]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-rsvp.c
CI: Add warning exemptions for Sun C (suncc-5.15) on Solaris 10
[tcpdump] / print-rsvp.c
index ea6ccfd7cca434f24b2ecdee90e178b035548eb8..153070e83537339e596dadc0051491b60b543897 100644 (file)
 
 /* specification: RFC 2205 */
 
-#ifdef HAVE_CONFIG_H
 #include <config.h>
-#endif
 
 #include "netdissect-stdinc.h"
 
+#define ND_LONGJMP_FROM_TCHECK
 #include "netdissect.h"
 #include "extract.h"
 #include "addrtoname.h"
@@ -314,11 +313,11 @@ static const struct tok rsvp_ctype_values[] = {
  * out-of-band, or negotiated by other RSVP objects.
  */
 struct rsvp_obj_integrity_t {
-    uint8_t flags;
-    uint8_t res;
-    uint8_t key_id[6];
-    uint8_t sequence[8];
-    uint8_t digest[16];
+    nd_uint8_t flags;
+    nd_uint8_t res;
+    nd_byte    key_id[6];
+    nd_byte    sequence[8];
+    nd_byte    digest[16];
 };
 
 static const struct tok rsvp_obj_integrity_flag_values[] = {
@@ -327,21 +326,21 @@ static const struct tok rsvp_obj_integrity_flag_values[] = {
 };
 
 struct rsvp_obj_frr_t {
-    uint8_t setup_prio;
-    uint8_t hold_prio;
-    uint8_t hop_limit;
-    uint8_t flags;
-    uint8_t bandwidth[4];
-    uint8_t include_any[4];
-    uint8_t exclude_any[4];
-    uint8_t include_all[4];
+    nd_uint8_t  setup_prio;
+    nd_uint8_t  hold_prio;
+    nd_uint8_t  hop_limit;
+    nd_uint8_t  flags;
+    nd_float    bandwidth;
+    nd_uint32_t include_any;
+    nd_uint32_t exclude_any;
+    nd_uint32_t include_all;
 };
 
 
 #define RSVP_OBJ_XRO_MASK_SUBOBJ(x)   ((x)&0x7f)
 #define RSVP_OBJ_XRO_MASK_LOOSE(x)    ((x)&0x80)
 
-#define RSVP_OBJ_CAPABILITY_FLAGS_MASK  0x7
+#define RSVP_OBJ_CAPABILITY_FLAGS_MASK  0x7U
 
 #define        RSVP_OBJ_XRO_RES       0
 #define        RSVP_OBJ_XRO_IPV4      1
@@ -460,7 +459,7 @@ static const struct tok rsvp_obj_error_code_diffserv_te_values[] = {
     { 6,                      "CT/setup priority and CT/holding priority do not form a configured TE-Class" },
     { 7,                      "Inconsistency between signaled PSC and signaled CT" },
     { 8,                      "Inconsistency between signaled PHBs and signaled CT" },
-   { 0, NULL}
+    { 0, NULL}
 };
 
 /* rfc3473 / rfc 3471 */
@@ -513,16 +512,9 @@ rsvp_intserv_print(netdissect_options *ndo,
                    const u_char *tptr, u_int obj_tlen)
 {
     u_int parameter_id,parameter_length;
-    union {
-       float f;
-       uint32_t i;
-    } bw;
 
-    if (obj_tlen < 4)
-        return 0;
-    ND_TCHECK_1(tptr);
+    ND_ICHECK_U(obj_tlen, <, 4);
     parameter_id = GET_U_1(tptr);
-    ND_TCHECK_2(tptr + 2);
     parameter_length = GET_BE_U_2(tptr + 2)<<2; /* convert wordcount to bytecount */
 
     ND_PRINT("\n\t      Parameter ID: %s (%u), length: %u, Flags: [0x%02x]",
@@ -531,8 +523,7 @@ rsvp_intserv_print(netdissect_options *ndo,
            parameter_length,
            GET_U_1(tptr + 1));
 
-    if (obj_tlen < parameter_length+4)
-        return 0;
+    ND_ICHECK_U(obj_tlen, <, parameter_length + 4);
     switch(parameter_id) { /* parameter_id */
 
     case 4:
@@ -544,7 +535,6 @@ rsvp_intserv_print(netdissect_options *ndo,
         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         */
         if (parameter_length == 4) {
-           ND_TCHECK_4(tptr + 4);
             ND_PRINT("\n\t\tIS hop count: %u", GET_BE_U_4(tptr + 4));
         }
         break;
@@ -558,9 +548,8 @@ rsvp_intserv_print(netdissect_options *ndo,
         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         */
         if (parameter_length == 4) {
-           ND_TCHECK_4(tptr + 4);
-            bw.i = GET_BE_U_4(tptr + 4);
-            ND_PRINT("\n\t\tPath b/w estimate: %.10g Mbps", bw.f / 125000);
+            ND_PRINT("\n\t\tPath b/w estimate: %.10g Mbps",
+                     GET_BE_F_4(tptr + 4) / 125000);
         }
         break;
 
@@ -573,7 +562,6 @@ rsvp_intserv_print(netdissect_options *ndo,
         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         */
         if (parameter_length == 4) {
-           ND_TCHECK_4(tptr + 4);
             ND_PRINT("\n\t\tMinimum path latency: ");
             if (GET_BE_U_4(tptr + 4) == 0xffffffff)
                 ND_PRINT("don't care");
@@ -592,7 +580,6 @@ rsvp_intserv_print(netdissect_options *ndo,
         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         */
         if (parameter_length == 4) {
-           ND_TCHECK_4(tptr + 4);
             ND_PRINT("\n\t\tComposed MTU: %u bytes", GET_BE_U_4(tptr + 4));
         }
         break;
@@ -614,13 +601,12 @@ rsvp_intserv_print(netdissect_options *ndo,
         */
 
         if (parameter_length == 20) {
-           ND_TCHECK_LEN(tptr + 4, 20);
-            bw.i = GET_BE_U_4(tptr + 4);
-            ND_PRINT("\n\t\tToken Bucket Rate: %.10g Mbps", bw.f / 125000);
-            bw.i = GET_BE_U_4(tptr + 8);
-            ND_PRINT("\n\t\tToken Bucket Size: %.10g bytes", bw.f);
-            bw.i = GET_BE_U_4(tptr + 12);
-            ND_PRINT("\n\t\tPeak Data Rate: %.10g Mbps", bw.f / 125000);
+            ND_PRINT("\n\t\tToken Bucket Rate: %.10g Mbps",
+                     GET_BE_F_4(tptr + 4) / 125000);
+            ND_PRINT("\n\t\tToken Bucket Size: %.10g bytes",
+                     GET_BE_F_4(tptr + 8));
+            ND_PRINT("\n\t\tPeak Data Rate: %.10g Mbps",
+                     GET_BE_F_4(tptr + 12) / 125000);
             ND_PRINT("\n\t\tMinimum Policed Unit: %u bytes",
                      GET_BE_U_4(tptr + 16));
             ND_PRINT("\n\t\tMaximum Packet Size: %u bytes",
@@ -640,9 +626,7 @@ rsvp_intserv_print(netdissect_options *ndo,
         */
 
         if (parameter_length == 8) {
-           ND_TCHECK_8(tptr + 4);
-            bw.i = GET_BE_U_4(tptr + 4);
-            ND_PRINT("\n\t\tRate: %.10g Mbps", bw.f / 125000);
+            ND_PRINT("\n\t\tRate: %.10g Mbps", GET_BE_F_4(tptr + 4) / 125000);
             ND_PRINT("\n\t\tSlack Term: %u", GET_BE_U_4(tptr + 8));
         }
         break;
@@ -652,7 +636,6 @@ rsvp_intserv_print(netdissect_options *ndo,
     case 135:
     case 136:
         if (parameter_length == 4) {
-           ND_TCHECK_4(tptr + 4);
             ND_PRINT("\n\t\tValue: %u", GET_BE_U_4(tptr + 4));
         }
         break;
@@ -663,8 +646,8 @@ rsvp_intserv_print(netdissect_options *ndo,
     }
     return (parameter_length+4); /* header length 4 bytes */
 
-trunc:
-    nd_print_trunc(ndo);
+invalid:
+    nd_print_invalid(ndo);
     return 0;
 }
 
@@ -696,19 +679,12 @@ rsvp_obj_print(netdissect_options *ndo,
     u_short rsvp_obj_len,rsvp_obj_ctype,rsvp_obj_class_num;
     u_int obj_tlen,intserv_serv_tlen;
     int hexdump;
-    u_int processed,padbytes,error_code,error_value,i,sigcheck;
-    union {
-       float f;
-       uint32_t i;
-    } bw;
+    u_int processed,padbytes,error_code,error_value,sigcheck;
     u_int namelen;
 
     u_int action, subchannel;
 
     while(tlen>=sizeof(struct rsvp_object_header)) {
-        /* did we capture enough for fully decoding the object header ? */
-        ND_TCHECK_LEN(tptr, sizeof(struct rsvp_object_header));
-
         rsvp_obj_header = (const struct rsvp_object_header *)tptr;
         rsvp_obj_len=GET_BE_U_2(rsvp_obj_header->length);
         rsvp_obj_ctype=GET_U_1(rsvp_obj_header->ctype);
@@ -1140,7 +1116,6 @@ rsvp_obj_print(netdissect_options *ndo,
                                ND_PRINT(" ERROR: length != 8");
                                goto invalid;
                        }
-                       ND_TCHECK_8(obj_tptr);
                         ND_PRINT(", Flags: [%s] (%#x), Class-Type: %s (%u), %u",
                                bittok2str(rsvp_obj_rro_label_flag_values,
                                    "none",
@@ -1227,8 +1202,7 @@ rsvp_obj_print(netdissect_options *ndo,
                 if (obj_tlen < 4+namelen)
                     goto obj_tooshort;
                 ND_PRINT("%s  Session Name: ", indent);
-                for (i = 0; i < namelen; i++)
-                    fn_print_char(ndo, GET_U_1(obj_tptr + 4 + i));
+                nd_printjn(ndo, obj_tptr + 4, namelen);
                 ND_PRINT("%s  Setup Priority: %u, Holding Priority: %u, Flags: [%s] (%#x)",
                        indent,
                        GET_U_1(obj_tptr),
@@ -1256,7 +1230,7 @@ rsvp_obj_print(netdissect_options *ndo,
 
                /* read variable length subobjects */
                total_subobj_len = obj_tlen;
-                while(total_subobj_len > 0) {
+                while(total_subobj_len != 0) {
                     /* If RFC 3476 Section 3.1 defined that a sub-object of the
                      * GENERALIZED_UNI RSVP object must have the Length field as
                      * a multiple of 4, instead of the check below it would be
@@ -1266,8 +1240,7 @@ rsvp_obj_print(netdissect_options *ndo,
                      * each iteration subobj_len may happen to be a multiple of 1
                      * and test it and total_subobj_len respectively.
                      */
-                    if (total_subobj_len < 4)
-                        goto invalid;
+                    ND_ICHECK_U(total_subobj_len, <, 4);
                     subobj_len  = GET_BE_U_2(obj_tptr);
                     subobj_type = (GET_BE_U_2(obj_tptr + 2))>>8;
                     af = (GET_BE_U_2(obj_tptr + 2))&0x00FF;
@@ -1314,13 +1287,13 @@ rsvp_obj_print(netdissect_options *ndo,
                     case RSVP_GEN_UNI_SUBOBJ_DESTINATION_TNA_ADDRESS:
 
                         switch(af) {
-                        case AFNUM_INET:
+                        case AFNUM_IP:
                             if (subobj_len < 8)
                                 goto subobj_tooshort;
                             ND_PRINT("%s    UNI IPv4 TNA address: %s",
                                    indent, GET_IPADDR_STRING(obj_tptr + 4));
                             break;
-                        case AFNUM_INET6:
+                        case AFNUM_IP6:
                             if (subobj_len < 20)
                                 goto subobj_tooshort;
                             ND_PRINT("%s    UNI IPv6 TNA address: %s",
@@ -1562,13 +1535,12 @@ rsvp_obj_print(netdissect_options *ndo,
             case RSVP_CTYPE_1: /* new style */
                 if (obj_tlen < sizeof(struct rsvp_obj_frr_t))
                     goto obj_tooshort;
-                bw.i = GET_BE_U_4(obj_ptr.rsvp_obj_frr->bandwidth);
                 ND_PRINT("%s  Setup Priority: %u, Holding Priority: %u, Hop-limit: %u, Bandwidth: %.10g Mbps",
                        indent,
-                       obj_ptr.rsvp_obj_frr->setup_prio,
-                       obj_ptr.rsvp_obj_frr->hold_prio,
-                       obj_ptr.rsvp_obj_frr->hop_limit,
-                       bw.f * 8 / 1000000);
+                       GET_U_1(obj_ptr.rsvp_obj_frr->setup_prio),
+                       GET_U_1(obj_ptr.rsvp_obj_frr->hold_prio),
+                       GET_U_1(obj_ptr.rsvp_obj_frr->hop_limit),
+                       GET_BE_F_4(obj_ptr.rsvp_obj_frr->bandwidth) * 8 / 1000000);
                 ND_PRINT("%s  Include-any: 0x%08x, Exclude-any: 0x%08x, Include-all: 0x%08x",
                        indent,
                        GET_BE_U_4(obj_ptr.rsvp_obj_frr->include_any),
@@ -1581,13 +1553,12 @@ rsvp_obj_print(netdissect_options *ndo,
             case RSVP_CTYPE_TUNNEL_IPV4: /* old style */
                 if (obj_tlen < 16)
                     goto obj_tooshort;
-                bw.i = GET_BE_U_4(obj_ptr.rsvp_obj_frr->bandwidth);
                 ND_PRINT("%s  Setup Priority: %u, Holding Priority: %u, Hop-limit: %u, Bandwidth: %.10g Mbps",
                        indent,
-                       obj_ptr.rsvp_obj_frr->setup_prio,
-                       obj_ptr.rsvp_obj_frr->hold_prio,
-                       obj_ptr.rsvp_obj_frr->hop_limit,
-                       bw.f * 8 / 1000000);
+                       GET_U_1(obj_ptr.rsvp_obj_frr->setup_prio),
+                       GET_U_1(obj_ptr.rsvp_obj_frr->hold_prio),
+                       GET_U_1(obj_ptr.rsvp_obj_frr->hop_limit),
+                       GET_BE_F_4(obj_ptr.rsvp_obj_frr->bandwidth) * 8 / 1000000);
                 ND_PRINT("%s  Include Colors: 0x%08x, Exclude Colors: 0x%08x",
                        indent,
                        GET_BE_U_4(obj_ptr.rsvp_obj_frr->include_any),
@@ -1779,7 +1750,7 @@ rsvp_obj_print(netdissect_options *ndo,
                        GET_BE_U_4(obj_ptr.rsvp_obj_integrity->sequence + 4),
                        bittok2str(rsvp_obj_integrity_flag_values,
                                   "none",
-                                  obj_ptr.rsvp_obj_integrity->flags));
+                                  GET_U_1(obj_ptr.rsvp_obj_integrity->flags)));
                 ND_PRINT("%s  MD5-sum 0x%08x%08x%08x%08x ",
                        indent,
                        GET_BE_U_4(obj_ptr.rsvp_obj_integrity->digest),
@@ -1918,9 +1889,6 @@ obj_tooshort:
 invalid:
     nd_print_invalid(ndo);
     return -1;
-trunc:
-    nd_print_trunc(ndo);
-    return -1;
 }
 
 void
@@ -1989,7 +1957,7 @@ rsvp_print(netdissect_options *ndo,
          * Bundle messages may not contain bundle submessages, so we don't
          * need to handle bundle submessages specially.
          */
-        while(tlen > 0) {
+        while(tlen != 0) {
             const u_char *subpptr=tptr, *subtptr;
             u_short subplen, subtlen;
 
@@ -2069,8 +2037,4 @@ rsvp_print(netdissect_options *ndo,
         print_unknown_data(ndo, tptr, "\n\t    ", tlen);
         break;
     }
-
-    return;
-trunc:
-    nd_print_trunc(ndo);
 }