]> The Tcpdump Group git mirrors - tcpdump/commitdiff
NDOize Babel decoder
authorDenis Ovsienko <[email protected]>
Thu, 3 Apr 2014 08:33:53 +0000 (12:33 +0400)
committerDenis Ovsienko <[email protected]>
Thu, 3 Apr 2014 08:33:53 +0000 (12:33 +0400)
interface.h
netdissect.h
print-babel.c
print-udp.c

index 6f5e10638ba4320885311e7aabaf08dd7dff7749..25fe79ee7d7cdbe31044341916f2d2e9de234e7b 100644 (file)
@@ -167,7 +167,6 @@ extern char *smb_errstr(int, int);
 extern const char *nt_errstr(u_int32_t);
 
 #ifdef INET6
 extern const char *nt_errstr(u_int32_t);
 
 #ifdef INET6
-extern void babel_print(const u_char *, u_int);
 extern int mask62plen(const u_char *);
 #endif /*INET6*/
 
 extern int mask62plen(const u_char *);
 #endif /*INET6*/
 
index 947f296dabb8ce78b279a0fc0f7b8ebda4b3cf59..09b28ff5ae7f1b85e1852329ce04deaebaa15c89 100644 (file)
@@ -563,6 +563,7 @@ extern void ripng_print(netdissect_options *, const u_char *, unsigned int);
 extern int mobility_print(netdissect_options *, const u_char *, const u_char *);
 extern void dhcp6_print(netdissect_options *, const u_char *, u_int);
 extern void ospf6_print(netdissect_options *, const u_char *, u_int);
 extern int mobility_print(netdissect_options *, const u_char *, const u_char *);
 extern void dhcp6_print(netdissect_options *, const u_char *, u_int);
 extern void ospf6_print(netdissect_options *, const u_char *, u_int);
+extern void babel_print(netdissect_options *, const u_char *, u_int);
 #endif /*INET6*/
 
 #if 0
 #endif /*INET6*/
 
 #if 0
index bf8f29e84fbdb98fe4ffd8cafa7140ab7283fe90..6b03732816d24ae9481a76f3f1acd86d08512af8 100644 (file)
@@ -26,6 +26,7 @@
  * SUCH DAMAGE.
  */
 
  * SUCH DAMAGE.
  */
 
+#define NETDISSECT_REWORKED
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
 static const char tstr[] = "[|babel]";
 
 
 static const char tstr[] = "[|babel]";
 
-static void babel_print_v2(const u_char *cp, u_int length);
+static void babel_print_v2(netdissect_options *, const u_char *cp, u_int length);
 
 void
 
 void
-babel_print(const u_char *cp, u_int length) {
-    printf("babel");
+babel_print(netdissect_options *ndo,
+            const u_char *cp, u_int length) {
+    ND_PRINT((ndo, "babel"));
 
 
-    TCHECK2(*cp, 4);
+    ND_TCHECK2(*cp, 4);
 
     if(cp[0] != 42) {
 
     if(cp[0] != 42) {
-        printf(" malformed header");
+        ND_PRINT((ndo, " malformed header"));
         return;
     } else {
         return;
     } else {
-        printf(" %d", cp[1]);
+        ND_PRINT((ndo, " %d", cp[1]));
     }
 
     switch(cp[1]) {
     case 2:
     }
 
     switch(cp[1]) {
     case 2:
-        babel_print_v2(cp,length);
+        babel_print_v2(ndo, cp, length);
         break;
     default:
         break;
     default:
-        printf(" unknown version");
+        ND_PRINT((ndo, " unknown version"));
         break;
     }
 
     return;
 
  trunc:
         break;
     }
 
     return;
 
  trunc:
-    printf(" %s", tstr);
+    ND_PRINT((ndo, " %s", tstr));
     return;
 }
 
     return;
 }
 
@@ -251,14 +253,15 @@ network_address(int ae, const unsigned char *a, unsigned int len,
  * The former would mean a lack of any claims about the interference, and the
  * latter would state that interference is definitely absent. */
 static void
  * The former would mean a lack of any claims about the interference, and the
  * latter would state that interference is definitely absent. */
 static void
-subtlvs_print(const u_char *cp, const u_char *ep, const uint8_t tlv_type) {
+subtlvs_print(netdissect_options *ndo,
+              const u_char *cp, const u_char *ep, const uint8_t tlv_type) {
     uint8_t subtype, sublen;
     const char *sep;
 
     while (cp < ep) {
         subtype = *cp++;
         if(subtype == MESSAGE_SUB_PAD1) {
     uint8_t subtype, sublen;
     const char *sep;
 
     while (cp < ep) {
         subtype = *cp++;
         if(subtype == MESSAGE_SUB_PAD1) {
-            printf(" sub-pad1");
+            ND_PRINT((ndo, " sub-pad1"));
             continue;
         }
         if(cp == ep)
             continue;
         }
         if(cp == ep)
@@ -269,50 +272,51 @@ subtlvs_print(const u_char *cp, const u_char *ep, const uint8_t tlv_type) {
 
         switch(subtype) {
         case MESSAGE_SUB_PADN:
 
         switch(subtype) {
         case MESSAGE_SUB_PADN:
-            printf(" sub-padn");
+            ND_PRINT((ndo, " sub-padn"));
             cp += sublen;
             break;
         case MESSAGE_SUB_DIVERSITY:
             cp += sublen;
             break;
         case MESSAGE_SUB_DIVERSITY:
-            printf(" sub-diversity");
+            ND_PRINT((ndo, " sub-diversity"));
             if (sublen == 0) {
             if (sublen == 0) {
-                printf(" empty");
+                ND_PRINT((ndo, " empty"));
                 break;
             }
             sep = " ";
             while(sublen--) {
                 break;
             }
             sep = " ";
             while(sublen--) {
-                printf("%s%s", sep, tok2str(diversity_str, "%u", *cp++));
+                ND_PRINT((ndo, "%s%s", sep, tok2str(diversity_str, "%u", *cp++)));
                 sep = "-";
             }
             if(tlv_type != MESSAGE_UPDATE)
                 sep = "-";
             }
             if(tlv_type != MESSAGE_UPDATE)
-                printf(" (bogus)");
+                ND_PRINT((ndo, " (bogus)"));
             break;
         default:
             break;
         default:
-            printf(" sub-unknown-0x%02x", subtype);
+            ND_PRINT((ndo, " sub-unknown-0x%02x", subtype));
             cp += sublen;
         } /* switch */
     } /* while */
     return;
 
  corrupt:
             cp += sublen;
         } /* switch */
     } /* while */
     return;
 
  corrupt:
-    printf(" (corrupt)");
+    ND_PRINT((ndo, " (corrupt)"));
 }
 
 #define ICHECK(i, l) \
        if ((i) + (l) > bodylen || (i) + (l) > length) goto corrupt;
 
 static void
 }
 
 #define ICHECK(i, l) \
        if ((i) + (l) > bodylen || (i) + (l) > length) goto corrupt;
 
 static void
-babel_print_v2(const u_char *cp, u_int length) {
+babel_print_v2(netdissect_options *ndo,
+               const u_char *cp, u_int length) {
     u_int i;
     u_short bodylen;
     u_char v4_prefix[16] =
         {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, 0, 0, 0, 0 };
     u_char v6_prefix[16] = {0};
 
     u_int i;
     u_short bodylen;
     u_char v4_prefix[16] =
         {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, 0, 0, 0, 0 };
     u_char v6_prefix[16] = {0};
 
-    TCHECK2(*cp, 4);
+    ND_TCHECK2(*cp, 4);
     if (length < 4)
         goto corrupt;
     bodylen = EXTRACT_16BITS(cp + 2);
     if (length < 4)
         goto corrupt;
     bodylen = EXTRACT_16BITS(cp + 2);
-    printf(" (%u)", bodylen);
+    ND_PRINT((ndo, " (%u)", bodylen));
 
     /* Process the TLVs in the body */
     i = 0;
 
     /* Process the TLVs in the body */
     i = 0;
@@ -322,131 +326,131 @@ babel_print_v2(const u_char *cp, u_int length) {
 
         message = cp + 4 + i;
 
 
         message = cp + 4 + i;
 
-        TCHECK2(*message, 1);
+        ND_TCHECK2(*message, 1);
         if((type = message[0]) == MESSAGE_PAD1) {
         if((type = message[0]) == MESSAGE_PAD1) {
-            printf(vflag ? "\n\tPad 1" : " pad1");
+            ND_PRINT((ndo, ndo->ndo_vflag ? "\n\tPad 1" : " pad1"));
             i += 1;
             continue;
         }
 
             i += 1;
             continue;
         }
 
-        TCHECK2(*message, 2);
+        ND_TCHECK2(*message, 2);
         ICHECK(i, 2);
         len = message[1];
 
         ICHECK(i, 2);
         len = message[1];
 
-        TCHECK2(*message, 2 + len);
+        ND_TCHECK2(*message, 2 + len);
         ICHECK(i, 2 + len);
 
         switch(type) {
         case MESSAGE_PADN: {
         ICHECK(i, 2 + len);
 
         switch(type) {
         case MESSAGE_PADN: {
-            if(!vflag)
-                printf(" padN");
+            if (!ndo->ndo_vflag)
+                ND_PRINT((ndo, " padN"));
             else
             else
-                printf("\n\tPad %d", len + 2);
+                ND_PRINT((ndo, "\n\tPad %d", len + 2));
         }
             break;
 
         case MESSAGE_ACK_REQ: {
             u_short nonce, interval;
         }
             break;
 
         case MESSAGE_ACK_REQ: {
             u_short nonce, interval;
-            if(!vflag)
-                printf(" ack-req");
+            if (!ndo->ndo_vflag)
+                ND_PRINT((ndo, " ack-req"));
             else {
             else {
-                printf("\n\tAcknowledgment Request ");
+                ND_PRINT((ndo, "\n\tAcknowledgment Request "));
                 if(len < 6) goto corrupt;
                 nonce = EXTRACT_16BITS(message + 4);
                 interval = EXTRACT_16BITS(message + 6);
                 if(len < 6) goto corrupt;
                 nonce = EXTRACT_16BITS(message + 4);
                 interval = EXTRACT_16BITS(message + 6);
-                printf("%04x %s", nonce, format_interval(interval));
+                ND_PRINT((ndo, "%04x %s", nonce, format_interval(interval)));
             }
         }
             break;
 
         case MESSAGE_ACK: {
             u_short nonce;
             }
         }
             break;
 
         case MESSAGE_ACK: {
             u_short nonce;
-            if(!vflag)
-                printf(" ack");
+            if (!ndo->ndo_vflag)
+                ND_PRINT((ndo, " ack"));
             else {
             else {
-                printf("\n\tAcknowledgment ");
+                ND_PRINT((ndo, "\n\tAcknowledgment "));
                 if(len < 2) goto corrupt;
                 nonce = EXTRACT_16BITS(message + 2);
                 if(len < 2) goto corrupt;
                 nonce = EXTRACT_16BITS(message + 2);
-                printf("%04x", nonce);
+                ND_PRINT((ndo, "%04x", nonce));
             }
         }
             break;
 
         case MESSAGE_HELLO:  {
             u_short seqno, interval;
             }
         }
             break;
 
         case MESSAGE_HELLO:  {
             u_short seqno, interval;
-            if(!vflag)
-                printf(" hello");
+            if (!ndo->ndo_vflag)
+                ND_PRINT((ndo, " hello"));
             else {
             else {
-                printf("\n\tHello ");
+                ND_PRINT((ndo, "\n\tHello "));
                 if(len < 6) goto corrupt;
                 seqno = EXTRACT_16BITS(message + 4);
                 interval = EXTRACT_16BITS(message + 6);
                 if(len < 6) goto corrupt;
                 seqno = EXTRACT_16BITS(message + 4);
                 interval = EXTRACT_16BITS(message + 6);
-                printf("seqno %u interval %s", seqno, format_interval(interval));
+                ND_PRINT((ndo, "seqno %u interval %s", seqno, format_interval(interval)));
             }
         }
             break;
 
         case MESSAGE_IHU: {
             unsigned short txcost, interval;
             }
         }
             break;
 
         case MESSAGE_IHU: {
             unsigned short txcost, interval;
-            if(!vflag)
-                printf(" ihu");
+            if (!ndo->ndo_vflag)
+                ND_PRINT((ndo, " ihu"));
             else {
                 u_char address[16];
                 int rc;
             else {
                 u_char address[16];
                 int rc;
-                printf("\n\tIHU ");
+                ND_PRINT((ndo, "\n\tIHU "));
                 if(len < 6) goto corrupt;
                 txcost = EXTRACT_16BITS(message + 4);
                 interval = EXTRACT_16BITS(message + 6);
                 rc = network_address(message[2], message + 8, len - 6, address);
                 if(len < 6) goto corrupt;
                 txcost = EXTRACT_16BITS(message + 4);
                 interval = EXTRACT_16BITS(message + 6);
                 rc = network_address(message[2], message + 8, len - 6, address);
-                if(rc < 0) { printf("%s", tstr); break; }
-                printf("%s txcost %u interval %s",
-                       format_address(address), txcost, format_interval(interval));
+                if(rc < 0) { ND_PRINT((ndo, "%s", tstr)); break; }
+                ND_PRINT((ndo, "%s txcost %u interval %s",
+                       format_address(address), txcost, format_interval(interval)));
             }
         }
             break;
 
         case MESSAGE_ROUTER_ID: {
             }
         }
             break;
 
         case MESSAGE_ROUTER_ID: {
-            if(!vflag)
-                printf(" router-id");
+            if (!ndo->ndo_vflag)
+                ND_PRINT((ndo, " router-id"));
             else {
             else {
-                printf("\n\tRouter Id");
+                ND_PRINT((ndo, "\n\tRouter Id"));
                 if(len < 10) goto corrupt;
                 if(len < 10) goto corrupt;
-                printf(" %s", format_id(message + 4));
+                ND_PRINT((ndo, " %s", format_id(message + 4)));
             }
         }
             break;
 
         case MESSAGE_NH: {
             }
         }
             break;
 
         case MESSAGE_NH: {
-            if(!vflag)
-                printf(" nh");
+            if (!ndo->ndo_vflag)
+                ND_PRINT((ndo, " nh"));
             else {
                 int rc;
                 u_char nh[16];
             else {
                 int rc;
                 u_char nh[16];
-                printf("\n\tNext Hop");
+                ND_PRINT((ndo, "\n\tNext Hop"));
                 if(len < 2) goto corrupt;
                 rc = network_address(message[2], message + 4, len - 2, nh);
                 if(rc < 0) goto corrupt;
                 if(len < 2) goto corrupt;
                 rc = network_address(message[2], message + 4, len - 2, nh);
                 if(rc < 0) goto corrupt;
-                printf(" %s", format_address(nh));
+                ND_PRINT((ndo, " %s", format_address(nh)));
             }
         }
             break;
 
         case MESSAGE_UPDATE: {
             }
         }
             break;
 
         case MESSAGE_UPDATE: {
-            if(!vflag) {
-                printf(" update");
+            if (!ndo->ndo_vflag) {
+                ND_PRINT((ndo, " update"));
                 if(len < 1)
                 if(len < 1)
-                    printf("/truncated");
+                    ND_PRINT((ndo, "/truncated"));
                 else
                 else
-                    printf("%s%s%s",
+                    ND_PRINT((ndo, "%s%s%s",
                            (message[3] & 0x80) ? "/prefix": "",
                            (message[3] & 0x40) ? "/id" : "",
                            (message[3] & 0x80) ? "/prefix": "",
                            (message[3] & 0x40) ? "/id" : "",
-                           (message[3] & 0x3f) ? "/unknown" : "");
+                           (message[3] & 0x3f) ? "/unknown" : ""));
             } else {
                 u_short interval, seqno, metric;
                 u_char plen;
                 int rc;
                 u_char prefix[16];
             } else {
                 u_short interval, seqno, metric;
                 u_char plen;
                 int rc;
                 u_char prefix[16];
-                printf("\n\tUpdate");
+                ND_PRINT((ndo, "\n\tUpdate"));
                 if(len < 10) goto corrupt;
                 plen = message[4] + (message[2] == 1 ? 96 : 0);
                 rc = network_prefix(message[2], message[4], message[5],
                 if(len < 10) goto corrupt;
                 plen = message[4] + (message[2] == 1 ? 96 : 0);
                 rc = network_prefix(message[2], message[4], message[5],
@@ -457,12 +461,12 @@ babel_print_v2(const u_char *cp, u_int length) {
                 interval = EXTRACT_16BITS(message + 6);
                 seqno = EXTRACT_16BITS(message + 8);
                 metric = EXTRACT_16BITS(message + 10);
                 interval = EXTRACT_16BITS(message + 6);
                 seqno = EXTRACT_16BITS(message + 8);
                 metric = EXTRACT_16BITS(message + 10);
-                printf("%s%s%s %s metric %u seqno %u interval %s",
+                ND_PRINT((ndo, "%s%s%s %s metric %u seqno %u interval %s",
                        (message[3] & 0x80) ? "/prefix": "",
                        (message[3] & 0x40) ? "/id" : "",
                        (message[3] & 0x3f) ? "/unknown" : "",
                        format_prefix(prefix, plen),
                        (message[3] & 0x80) ? "/prefix": "",
                        (message[3] & 0x40) ? "/id" : "",
                        (message[3] & 0x3f) ? "/unknown" : "",
                        format_prefix(prefix, plen),
-                       metric, seqno, format_interval_update(interval));
+                       metric, seqno, format_interval_update(interval)));
                 if(message[3] & 0x80) {
                     if(message[2] == 1)
                         memcpy(v4_prefix, prefix, 16);
                 if(message[3] & 0x80) {
                     if(message[2] == 1)
                         memcpy(v4_prefix, prefix, 16);
@@ -471,87 +475,87 @@ babel_print_v2(const u_char *cp, u_int length) {
                 }
                 /* extra data? */
                 if((u_int)rc < len - 10)
                 }
                 /* extra data? */
                 if((u_int)rc < len - 10)
-                    subtlvs_print(message + 12 + rc, message + 2 + len, type);
+                    subtlvs_print(ndo, message + 12 + rc, message + 2 + len, type);
             }
         }
             break;
 
         case MESSAGE_REQUEST: {
             }
         }
             break;
 
         case MESSAGE_REQUEST: {
-            if(!vflag)
-                printf(" request");
+            if (!ndo->ndo_vflag)
+                ND_PRINT((ndo, " request"));
             else {
                 int rc;
                 u_char prefix[16], plen;
             else {
                 int rc;
                 u_char prefix[16], plen;
-                printf("\n\tRequest ");
+                ND_PRINT((ndo, "\n\tRequest "));
                 if(len < 2) goto corrupt;
                 plen = message[3] + (message[2] == 1 ? 96 : 0);
                 rc = network_prefix(message[2], message[3], 0,
                                     message + 4, NULL, len - 2, prefix);
                 if(rc < 0) goto corrupt;
                 if(len < 2) goto corrupt;
                 plen = message[3] + (message[2] == 1 ? 96 : 0);
                 rc = network_prefix(message[2], message[3], 0,
                                     message + 4, NULL, len - 2, prefix);
                 if(rc < 0) goto corrupt;
-                printf("for %s",
-                       message[2] == 0 ? "any" : format_prefix(prefix, plen));
+                ND_PRINT((ndo, "for %s",
+                       message[2] == 0 ? "any" : format_prefix(prefix, plen)));
             }
         }
             break;
 
         case MESSAGE_MH_REQUEST : {
             }
         }
             break;
 
         case MESSAGE_MH_REQUEST : {
-            if(!vflag)
-                printf(" mh-request");
+            if (!ndo->ndo_vflag)
+                ND_PRINT((ndo, " mh-request"));
             else {
                 int rc;
                 u_short seqno;
                 u_char prefix[16], plen;
             else {
                 int rc;
                 u_short seqno;
                 u_char prefix[16], plen;
-                printf("\n\tMH-Request ");
+                ND_PRINT((ndo, "\n\tMH-Request "));
                 if(len < 14) goto corrupt;
                 seqno = EXTRACT_16BITS(message + 4);
                 rc = network_prefix(message[2], message[3], 0,
                                     message + 16, NULL, len - 14, prefix);
                 if(rc < 0) goto corrupt;
                 plen = message[3] + (message[2] == 1 ? 96 : 0);
                 if(len < 14) goto corrupt;
                 seqno = EXTRACT_16BITS(message + 4);
                 rc = network_prefix(message[2], message[3], 0,
                                     message + 16, NULL, len - 14, prefix);
                 if(rc < 0) goto corrupt;
                 plen = message[3] + (message[2] == 1 ? 96 : 0);
-                printf("(%u hops) for %s seqno %u id %s",
+                ND_PRINT((ndo, "(%u hops) for %s seqno %u id %s",
                        message[6], format_prefix(prefix, plen),
                        message[6], format_prefix(prefix, plen),
-                       seqno, format_id(message + 8));
+                       seqno, format_id(message + 8)));
             }
         }
             break;
         case MESSAGE_TSPC :
             }
         }
             break;
         case MESSAGE_TSPC :
-            if(!vflag)
-                printf(" tspc");
+            if (!ndo->ndo_vflag)
+                ND_PRINT((ndo, " tspc"));
             else {
             else {
-                printf("\n\tTS/PC ");
+                ND_PRINT((ndo, "\n\tTS/PC "));
                 if(len < 6) goto corrupt;
                 if(len < 6) goto corrupt;
-                printf("timestamp %u packetcounter %u", EXTRACT_32BITS (message + 4),
-                       EXTRACT_16BITS(message + 2));
+                ND_PRINT((ndo, "timestamp %u packetcounter %u", EXTRACT_32BITS (message + 4),
+                       EXTRACT_16BITS(message + 2)));
             }
             break;
         case MESSAGE_HMAC : {
             }
             break;
         case MESSAGE_HMAC : {
-            if(!vflag)
-                printf(" hmac");
+            if (!ndo->ndo_vflag)
+                ND_PRINT((ndo, " hmac"));
             else {
                 unsigned j;
             else {
                 unsigned j;
-                printf("\n\tHMAC ");
+                ND_PRINT((ndo, "\n\tHMAC "));
                 if(len < 18) goto corrupt;
                 if(len < 18) goto corrupt;
-                printf("key-id %u digest-%u ", EXTRACT_16BITS(message + 2), len - 2);
+                ND_PRINT((ndo, "key-id %u digest-%u ", EXTRACT_16BITS(message + 2), len - 2));
                 for (j = 0; j < len - 2; j++)
                 for (j = 0; j < len - 2; j++)
-                    printf ("%02X", message[4 + j]);
+                    ND_PRINT((ndo, "%02X", message[4 + j]));
             }
         }
             break;
         default:
             }
         }
             break;
         default:
-            if(!vflag)
-                printf(" unknown");
+            if (!ndo->ndo_vflag)
+                ND_PRINT((ndo, " unknown"));
             else
             else
-                printf("\n\tUnknown message type %d", type);
+                ND_PRINT((ndo, "\n\tUnknown message type %d", type));
         }
         i += len + 2;
     }
     return;
 
  trunc:
         }
         i += len + 2;
     }
     return;
 
  trunc:
-    printf(" %s", tstr);
+    ND_PRINT((ndo, " %s", tstr));
     return;
 
  corrupt:
     return;
 
  corrupt:
-    printf(" (corrupt)");
+    ND_PRINT((ndo, " (corrupt)"));
     return;
 }
     return;
 }
index f3c1235f55334b5232a608517bfa87ee0fe8cb6f..d059603967a9193b05eb5d14157b6305d05cfe19 100644 (file)
@@ -624,7 +624,7 @@ udp_print(netdissect_options *ndo, register const u_char *bp, u_int length,
                else if (ISPORT(AHCP_PORT))
                        ahcp_print(ndo, (const u_char *)(up + 1), length);
                else if (ISPORT(BABEL_PORT) || ISPORT(BABEL_PORT_OLD))
                else if (ISPORT(AHCP_PORT))
                        ahcp_print(ndo, (const u_char *)(up + 1), length);
                else if (ISPORT(BABEL_PORT) || ISPORT(BABEL_PORT_OLD))
-                       babel_print((const u_char *)(up + 1), length);
+                       babel_print(ndo, (const u_char *)(up + 1), length);
 #endif /*INET6*/
                /*
                 * Kludge in test for whiteboard packets.
 #endif /*INET6*/
                /*
                 * Kludge in test for whiteboard packets.