]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-radius.c
Put "{" at end of line with "if" to keep a consistent style
[tcpdump] / print-radius.c
index 5c27710a2836a6a272f04c78dbfe322428901b2c..825724bae05aad04f4b89125009b52e4f509faf6 100644 (file)
 #define PRINT_HEX(bytes_len, ptr_data)                               \
            while(bytes_len)                                          \
            {                                                         \
-              ND_PRINT("%02X", *ptr_data );                   \
+              ND_PRINT("%02X", GET_U_1(ptr_data));                   \
               ptr_data++;                                            \
               bytes_len--;                                           \
            }
@@ -214,7 +214,7 @@ static void print_attr_location_information(netdissect_options *, const u_char *
 static void print_attr_location_data(netdissect_options *, const u_char *, u_int, u_short);
 static void print_basic_location_policy_rules(netdissect_options *, const u_char *, u_int, u_short);
 static void print_attr_time(netdissect_options *, const u_char *, u_int, u_short);
-static void print_attr_vector64(netdissect_options *, register const u_char *, u_int, u_short);
+static void print_attr_vector64(netdissect_options *, const u_char *, u_int, u_short);
 static void print_attr_strange(netdissect_options *, const u_char *, u_int, u_short);
 
 
@@ -794,8 +794,7 @@ print_attr_string(netdissect_options *ndo,
       case TUNNEL_ASSIGN_ID:
       case TUNNEL_CLIENT_AUTH:
       case TUNNEL_SERVER_AUTH:
-           if (GET_U_1(data) <= 0x1F)
-           {
+           if (GET_U_1(data) <= 0x1F) {
               if (length < 1)
                  goto trunc;
               if (GET_U_1(data))
@@ -854,20 +853,16 @@ print_vendor_attr(netdissect_options *ndo,
            vendor_id);
 
     while (length >= 2) {
-       ND_TCHECK_2(data);
-
         vendor_type = GET_U_1(data);
         vendor_length = GET_U_1(data + 1);
 
-        if (vendor_length < 2)
-        {
+        if (vendor_length < 2) {
             ND_PRINT("\n\t    Vendor Attribute: %u, Length: %u (bogus, must be >= 2)",
                    vendor_type,
                    vendor_length);
             return;
         }
-        if (vendor_length > length)
-        {
+        if (vendor_length > length) {
             ND_PRINT("\n\t    Vendor Attribute: %u, Length: %u (bogus, goes past end of vendor-specific attribute)",
                    vendor_type,
                    vendor_length);
@@ -904,22 +899,18 @@ print_attr_num(netdissect_options *ndo,
 {
    uint32_t timeout;
 
-   if (length != 4)
-   {
+   if (length != 4) {
        ND_PRINT("ERROR: length %u != 4", length);
        return;
    }
 
-   ND_TCHECK_4(data);
                           /* This attribute has standard values */
-   if (attr_type[attr_code].siz_subtypes)
-   {
+   if (attr_type[attr_code].siz_subtypes) {
       static const char **table;
       uint32_t data_value;
       table = attr_type[attr_code].subtypes;
 
-      if ( (attr_code == TUNNEL_TYPE) || (attr_code == TUNNEL_MEDIUM) )
-      {
+      if ( (attr_code == TUNNEL_TYPE) || (attr_code == TUNNEL_MEDIUM) ) {
          if (!GET_U_1(data))
             ND_PRINT("Tag[Unused] ");
          else
@@ -1007,11 +998,6 @@ print_attr_num(netdissect_options *ndo,
       } /* switch */
 
    } /* if-else */
-
-   return;
-
-   trunc:
-     nd_print_trunc(ndo);
 }
 
 /*****************************/
@@ -1025,14 +1011,11 @@ static void
 print_attr_address(netdissect_options *ndo,
                    const u_char *data, u_int length, u_short attr_code)
 {
-   if (length != 4)
-   {
+   if (length != 4) {
        ND_PRINT("ERROR: length %u != 4", length);
        return;
    }
 
-   ND_TCHECK_4(data);
-
    switch(attr_code)
    {
       case FRM_IPADDR:
@@ -1050,11 +1033,6 @@ print_attr_address(netdissect_options *ndo,
           ND_PRINT("%s", GET_IPADDR_STRING(data));
       break;
    }
-
-   return;
-
-   trunc:
-     nd_print_trunc(ndo);
 }
 
 /*****************************/
@@ -1068,20 +1046,12 @@ static void
 print_attr_address6(netdissect_options *ndo,
                    const u_char *data, u_int length, u_short attr_code _U_)
 {
-   if (length != 16)
-   {
+   if (length != 16) {
        ND_PRINT("ERROR: length %u != 16", length);
        return;
    }
 
-   ND_TCHECK_16(data);
-
    ND_PRINT("%s", GET_IP6ADDR_STRING(data));
-
-   return;
-
-   trunc:
-     nd_print_trunc(ndo);
 }
 
 static void
@@ -1090,14 +1060,12 @@ print_attr_netmask6(netdissect_options *ndo,
 {
    u_char data2[16];
 
-   if (length < 2 || length > 18)
-   {
+   if (length < 2 || length > 18) {
        ND_PRINT("ERROR: length %u not in range (2..18)", length);
        return;
    }
    ND_TCHECK_LEN(data, length);
-   if (GET_U_1(data + 1) > 128)
-   {
+   if (GET_U_1(data + 1) > 128) {
       ND_PRINT("ERROR: netmask %u not in range (0..128)", GET_U_1(data + 1));
       return;
    }
@@ -1106,7 +1074,7 @@ print_attr_netmask6(netdissect_options *ndo,
    if (length > 2)
       memcpy(data2, data+2, length-2);
 
-   ND_PRINT("%s/%u", ip6addr_string(ndo, data2), GET_U_1(data + 1));
+   ND_PRINT("%s/%u", ip6addr_string(ndo, data2), GET_U_1(data + 1)); /* local buffer, not packet data; don't use GET_IP6ADDR_STRING() */
 
    if (GET_U_1(data + 1) > 8 * (length - 2))
       ND_PRINT(" (inconsistent prefix length)");
@@ -1121,14 +1089,12 @@ static void
 print_attr_mip6_home_link_prefix(netdissect_options *ndo,
                     const u_char *data, u_int length, u_short attr_code _U_)
 {
-   if (length != 17)
-   {
+   if (length != 17) {
       ND_PRINT("ERROR: length %u != 17", length);
       return;
    }
    ND_TCHECK_LEN(data, length);
-   if (GET_U_1(data) > 128)
-   {
+   if (GET_U_1(data) > 128) {
       ND_PRINT("ERROR: netmask %u not in range (0..128)", GET_U_1(data));
       return;
    }
@@ -1148,8 +1114,7 @@ print_attr_operator_name(netdissect_options *ndo,
    u_int namespace_value;
 
    ND_TCHECK_LEN(data, length);
-   if (length < 2)
-   {
+   if (length < 2) {
       ND_PRINT("ERROR: length %u < 2", length);
       return;
    }
@@ -1157,7 +1122,7 @@ print_attr_operator_name(netdissect_options *ndo,
    data++;
    ND_PRINT("[%s] ", tok2str(operator_name_vector, "unknown namespace %u", namespace_value));
 
-   nd_printn(ndo, data, length - 1, NULL);
+   nd_printjn(ndo, data, length - 1);
 
    return;
 
@@ -1173,8 +1138,7 @@ print_attr_location_information(netdissect_options *ndo,
    uint8_t code, entity;
 
    ND_TCHECK_LEN(data, length);
-   if (length < 21)
-   {
+   if (length < 21) {
      ND_PRINT("ERROR: length %u < 21", length);
       return;
    }
@@ -1205,7 +1169,7 @@ print_attr_location_information(netdissect_options *ndo,
    data += 8;
 
    ND_PRINT("method \"");
-   nd_printn(ndo, data, length - 20, NULL);
+   nd_printjn(ndo, data, length - 20);
    ND_PRINT("\"");
 
    return;
@@ -1221,8 +1185,7 @@ print_attr_location_data(netdissect_options *ndo,
    uint16_t index;
 
    ND_TCHECK_LEN(data, length);
-   if (length < 3)
-   {
+   if (length < 3) {
      ND_PRINT("ERROR: length %u < 3", length);
       return;
    }
@@ -1253,8 +1216,7 @@ print_basic_location_policy_rules(netdissect_options *ndo,
    uint16_t flags;
 
    ND_TCHECK_LEN(data, length);
-   if (length < 10)
-   {
+   if (length < 10) {
      ND_PRINT("ERROR: length %u < 10", length);
       return;
    }
@@ -1269,7 +1231,7 @@ print_basic_location_policy_rules(netdissect_options *ndo,
 
    if (length > 10) {
       ND_PRINT(", note well \"");
-      nd_printn(ndo, data, length - 10, NULL);
+      nd_printjn(ndo, data, length - 10);
       ND_PRINT("\"");
    }
 
@@ -1295,8 +1257,7 @@ print_attr_time(netdissect_options *ndo,
    time_t attr_time;
    char string[26];
 
-   if (length != 4)
-   {
+   if (length != 4) {
        ND_PRINT("ERROR: length %u != 4", length);
        return;
    }
@@ -1310,13 +1271,12 @@ print_attr_time(netdissect_options *ndo,
 
 static void
 print_attr_vector64(netdissect_options *ndo,
-                 register const u_char *data, u_int length, u_short attr_code _U_)
+                   const u_char *data, u_int length, u_short attr_code _U_)
 {
    uint64_t data_value, i;
    const char *sep = "";
 
-   if (length != 8)
-   {
+   if (length != 8) {
        ND_PRINT("ERROR: length %u != 8", length);
        return;
    }
@@ -1336,8 +1296,6 @@ print_attr_vector64(netdissect_options *ndo,
    }
 
    ND_PRINT("]");
-
-   return;
 }
 
 /***********************************/
@@ -1357,25 +1315,21 @@ print_attr_strange(netdissect_options *ndo,
    switch(attr_code)
    {
       case ARAP_PASS:
-           if (length != 16)
-           {
+           if (length != 16) {
                ND_PRINT("ERROR: length %u != 16", length);
                return;
            }
            ND_PRINT("User_challenge (");
-           ND_TCHECK_8(data);
            len_data = 8;
            PRINT_HEX(len_data, data);
            ND_PRINT(") User_resp(");
-           ND_TCHECK_8(data);
            len_data = 8;
            PRINT_HEX(len_data, data);
            ND_PRINT(")");
         break;
 
       case ARAP_FEATURES:
-           if (length != 14)
-           {
+           if (length != 14) {
                ND_PRINT("ERROR: length %u != 14", length);
                return;
            }
@@ -1387,33 +1341,27 @@ print_attr_strange(netdissect_options *ndo,
            ND_PRINT(", Min password length: %u", GET_U_1(data));
            data++;
            ND_PRINT(", created at: ");
-           ND_TCHECK_4(data);
            len_data = 4;
            PRINT_HEX(len_data, data);
            ND_PRINT(", expires in: ");
-           ND_TCHECK_4(data);
            len_data = 4;
            PRINT_HEX(len_data, data);
            ND_PRINT(", Current Time: ");
-           ND_TCHECK_4(data);
            len_data = 4;
            PRINT_HEX(len_data, data);
         break;
 
       case ARAP_CHALLENGE_RESP:
-           if (length < 8)
-           {
+           if (length < 8) {
                ND_PRINT("ERROR: length %u != 8", length);
                return;
            }
-           ND_TCHECK_8(data);
            len_data = 8;
            PRINT_HEX(len_data, data);
         break;
 
       case ERROR_CAUSE:
-           if (length != 4)
-           {
+           if (length != 4) {
                ND_PRINT("Error: length %u != 4", length);
                return;
            }
@@ -1423,9 +1371,6 @@ print_attr_strange(netdissect_options *ndo,
         break;
    }
    return;
-
-   trunc:
-     nd_print_trunc(ndo);
 }
 
 static void
@@ -1436,8 +1381,7 @@ radius_attrs_print(netdissect_options *ndo,
    const char *attr_string;
    uint8_t type, len;
 
-   while (length > 0)
-   {
+   while (length > 0) {
      if (length < 2)
         goto trunc;
      ND_TCHECK_SIZE(rad_attr);
@@ -1453,22 +1397,18 @@ radius_attrs_print(netdissect_options *ndo,
                attr_string,
                type,
                len);
-     if (len < 2)
-     {
+     if (len < 2) {
        ND_PRINT(" (bogus, must be >= 2)");
        return;
      }
-     if (len > length)
-     {
+     if (len > length) {
         ND_PRINT(" (bogus, goes past end of packet)");
         return;
      }
      ND_PRINT(", Value: ");
 
-     if (type < TAM_SIZE(attr_type))
-     {
-         if (len > 2)
-         {
+     if (type < TAM_SIZE(attr_type)) {
+         if (len > 2) {
              if ( attr_type[type].print_func )
                  (*attr_type[type].print_func)(
                      ndo, ((const u_char *)(rad_attr+1)),
@@ -1500,8 +1440,7 @@ radius_print(netdissect_options *ndo,
    rad = (const struct radius_hdr *)dat;
    len = GET_BE_U_2(rad->len);
 
-   if (len < MIN_RADIUS_LEN)
-   {
+   if (len < MIN_RADIUS_LEN) {
          nd_print_trunc(ndo);
          return;
    }