]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-bgp.c
Fix the pointer tests in the non-ndoified TTEST2() macro as well.
[tcpdump] / print-bgp.c
index eab6747d19c9eebdcc4c3e4990bbd486e16145c7..f5c02a1be985ae3c4d20e5ed5571db92a30a589a 100644 (file)
@@ -47,9 +47,9 @@
 #include "l2vpn.h"
 
 struct bgp {
-       u_int8_t bgp_marker[16];
-       u_int16_t bgp_len;
-       u_int8_t bgp_type;
+       uint8_t bgp_marker[16];
+       uint16_t bgp_len;
+       uint8_t bgp_type;
 };
 #define BGP_SIZE               19      /* unaligned */
 
@@ -69,42 +69,42 @@ static const struct tok bgp_msg_values[] = {
 };
 
 struct bgp_open {
-       u_int8_t bgpo_marker[16];
-       u_int16_t bgpo_len;
-       u_int8_t bgpo_type;
-       u_int8_t bgpo_version;
-       u_int16_t bgpo_myas;
-       u_int16_t bgpo_holdtime;
-       u_int32_t bgpo_id;
-       u_int8_t bgpo_optlen;
+       uint8_t bgpo_marker[16];
+       uint16_t bgpo_len;
+       uint8_t bgpo_type;
+       uint8_t bgpo_version;
+       uint16_t bgpo_myas;
+       uint16_t bgpo_holdtime;
+       uint32_t bgpo_id;
+       uint8_t bgpo_optlen;
        /* options should follow */
 };
 #define BGP_OPEN_SIZE          29      /* unaligned */
 
 struct bgp_opt {
-       u_int8_t bgpopt_type;
-       u_int8_t bgpopt_len;
+       uint8_t bgpopt_type;
+       uint8_t bgpopt_len;
        /* variable length */
 };
 #define BGP_OPT_SIZE           2       /* some compilers may pad to 4 bytes */
 #define BGP_CAP_HEADER_SIZE    2       /* some compilers may pad to 4 bytes */
 
 struct bgp_notification {
-       u_int8_t bgpn_marker[16];
-       u_int16_t bgpn_len;
-       u_int8_t bgpn_type;
-       u_int8_t bgpn_major;
-       u_int8_t bgpn_minor;
+       uint8_t bgpn_marker[16];
+       uint16_t bgpn_len;
+       uint8_t bgpn_type;
+       uint8_t bgpn_major;
+       uint8_t bgpn_minor;
 };
 #define BGP_NOTIFICATION_SIZE          21      /* unaligned */
 
 struct bgp_route_refresh {
-    u_int8_t  bgp_marker[16];
-    u_int16_t len;
-    u_int8_t  type;
-    u_int8_t  afi[2]; /* the compiler messes this structure up               */
-    u_int8_t  res;    /* when doing misaligned sequences of int8 and int16   */
-    u_int8_t  safi;   /* afi should be int16 - so we have to access it using */
+    uint8_t  bgp_marker[16];
+    uint16_t len;
+    uint8_t  type;
+    uint8_t  afi[2]; /* the compiler messes this structure up               */
+    uint8_t  res;    /* when doing misaligned sequences of int8 and int16   */
+    uint8_t  safi;   /* afi should be int16 - so we have to access it using */
 };                    /* EXTRACT_16BITS(&bgp_route_refresh->afi) (sigh)      */
 #define BGP_ROUTE_REFRESH_SIZE          23
 
@@ -503,7 +503,7 @@ decode_prefix4(netdissect_options *ndo,
                ((u_char *)&addr)[plenbytes - 1] &=
                        ((0xff00 >> (plen % 8)) & 0xff);
        }
-       snprintf(buf, buflen, "%s/%d", getname((u_char *)&addr), plen);
+       snprintf(buf, buflen, "%s/%d", getname(ndo, (u_char *)&addr), plen);
        return 1 + plenbytes;
 
 trunc:
@@ -553,7 +553,7 @@ decode_labeled_prefix4(netdissect_options *ndo,
        }
         /* the label may get offsetted by 4 bits so lets shift it right */
        snprintf(buf, buflen, "%s/%d, label:%u %s",
-                 getname((u_char *)&addr),
+                 getname(ndo, (u_char *)&addr),
                  plen,
                  EXTRACT_24BITS(pptr+1)>>4,
                  ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
@@ -583,12 +583,12 @@ bgp_vpn_ip_print(netdissect_options *ndo,
     switch(addr_length) {
     case (sizeof(struct in_addr) << 3): /* 32 */
         ND_TCHECK2(pptr[0], sizeof(struct in_addr));
-        snprintf(pos, sizeof(addr), "%s", ipaddr_string(pptr));
+        snprintf(pos, sizeof(addr), "%s", ipaddr_string(ndo, pptr));
         break;
 #ifdef INET6
     case (sizeof(struct in6_addr) << 3): /* 128 */
         ND_TCHECK2(pptr[0], sizeof(struct in6_addr));
-        snprintf(pos, sizeof(addr), "%s", ip6addr_string(pptr));
+        snprintf(pos, sizeof(addr), "%s", ip6addr_string(ndo, pptr));
         break;
 #endif
     default:
@@ -624,7 +624,7 @@ static int
 bgp_vpn_sg_print(netdissect_options *ndo,
                  const u_char *pptr, char *buf, u_int buflen) {
 
-    u_int8_t addr_length;
+    uint8_t addr_length;
     u_int total_length, offset;
 
     total_length = 0;
@@ -710,7 +710,7 @@ static int
 decode_rt_routing_info(netdissect_options *ndo,
                        const u_char *pptr, char *buf, u_int buflen)
 {
-       u_int8_t route_target[8];
+       uint8_t route_target[8];
        u_int plen;
 
        ND_TCHECK(pptr[0]);
@@ -772,7 +772,7 @@ decode_labeled_vpn_prefix4(netdissect_options *ndo,
         /* the label may get offsetted by 4 bits so lets shift it right */
        snprintf(buf, buflen, "RD: %s, %s/%d, label:%u %s",
                  bgp_vpn_rd_print(ndo, pptr+4),
-                 getname((u_char *)&addr),
+                 getname(ndo, (u_char *)&addr),
                  plen,
                  EXTRACT_24BITS(pptr+1)>>4,
                  ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
@@ -806,7 +806,7 @@ decode_mdt_vpn_nlri(netdissect_options *ndo,
     ND_TCHECK(pptr[0]);
 
     /* if the NLRI is not predefined length, quit.*/
-    if (*pptr != MDT_VPN_NLRI_LEN * NBBY)
+    if (*pptr != MDT_VPN_NLRI_LEN * 8)
        return -1;
     pptr++;
 
@@ -824,7 +824,7 @@ decode_mdt_vpn_nlri(netdissect_options *ndo,
     ND_TCHECK2(pptr[0], sizeof(struct in_addr));
 
     snprintf(buf, buflen, "RD: %s, VPN IP Address: %s, MC Group Address: %s",
-            bgp_vpn_rd_print(ndo, rd), ipaddr_string(vpn_ip), ipaddr_string(pptr));
+            bgp_vpn_rd_print(ndo, rd), ipaddr_string(ndo, vpn_ip), ipaddr_string(ndo, pptr));
 
     return MDT_VPN_NLRI_LEN + 1;
 
@@ -855,7 +855,7 @@ static int
 decode_multicast_vpn(netdissect_options *ndo,
                      const u_char *pptr, char *buf, u_int buflen)
 {
-        u_int8_t route_type, route_length, addr_length, sg_length;
+        uint8_t route_type, route_length, addr_length, sg_length;
         u_int offset;
 
        ND_TCHECK2(pptr[0], 2);
@@ -978,8 +978,8 @@ decode_labeled_vpn_l2(netdissect_options *ndo,
            buf[0]='\0';
            strlen=snprintf(buf, buflen, "RD: %s, BGPNH: %s",
                            bgp_vpn_rd_print(ndo, pptr),
-                           /* need something like getname() here */
-                           getname(pptr+8)
+                           /* need something like getname(ndo, ) here */
+                           getname(ndo, pptr+8)
                            );
            UPDATE_BUF_BUFLEN(buf, buflen, strlen);
            pptr+=12;
@@ -1075,7 +1075,7 @@ decode_prefix6(netdissect_options *ndo,
                addr.s6_addr[plenbytes - 1] &=
                        ((0xff00 >> (plen % 8)) & 0xff);
        }
-       snprintf(buf, buflen, "%s/%d", getname6((u_char *)&addr), plen);
+       snprintf(buf, buflen, "%s/%d", getname6(ndo, (u_char *)&addr), plen);
        return 1 + plenbytes;
 
 trunc:
@@ -1116,7 +1116,7 @@ decode_labeled_prefix6(netdissect_options *ndo,
        }
         /* the label may get offsetted by 4 bits so lets shift it right */
        snprintf(buf, buflen, "%s/%d, label:%u %s",
-                 getname6((u_char *)&addr),
+                 getname6(ndo, (u_char *)&addr),
                  plen,
                  EXTRACT_24BITS(pptr+1)>>4,
                  ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
@@ -1158,7 +1158,7 @@ decode_labeled_vpn_prefix6(netdissect_options *ndo,
         /* the label may get offsetted by 4 bits so lets shift it right */
        snprintf(buf, buflen, "RD: %s, %s/%d, label:%u %s",
                  bgp_vpn_rd_print(ndo, pptr+4),
-                 getname6((u_char *)&addr),
+                 getname6(ndo, (u_char *)&addr),
                  plen,
                  EXTRACT_24BITS(pptr+1)>>4,
                  ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
@@ -1174,7 +1174,7 @@ static int
 decode_clnp_prefix(netdissect_options *ndo,
                    const u_char *pptr, char *buf, u_int buflen)
 {
-        u_int8_t addr[19];
+        uint8_t addr[19];
        u_int plen;
 
        ND_TCHECK(pptr[0]);
@@ -1204,7 +1204,7 @@ static int
 decode_labeled_vpn_clnp_prefix(netdissect_options *ndo,
                                const u_char *pptr, char *buf, u_int buflen)
 {
-        u_int8_t addr[19];
+        uint8_t addr[19];
        u_int plen;
 
        ND_TCHECK(pptr[0]);
@@ -1248,7 +1248,7 @@ trunc:
  */
 static int
 bgp_attr_get_as_size(netdissect_options *ndo,
-                     u_int8_t bgpa_type, const u_char *pptr, int len)
+                     uint8_t bgpa_type, const u_char *pptr, int len)
 {
     const u_char *tptr = pptr;
 
@@ -1302,11 +1302,11 @@ bgp_attr_print(netdissect_options *ndo,
                u_int atype, const u_char *pptr, u_int len)
 {
        int i;
-       u_int16_t af;
-       u_int8_t safi, snpa, nhlen;
+       uint16_t af;
+       uint8_t safi, snpa, nhlen;
         union { /* copy buffer for bandwidth values */
             float f;
-            u_int32_t i;
+            uint32_t i;
         } bw;
        int advance;
        u_int tlen;
@@ -1382,7 +1382,7 @@ bgp_attr_print(netdissect_options *ndo,
                        ND_PRINT((ndo, "invalid len"));
                else {
                        ND_TCHECK2(tptr[0], 4);
-                       ND_PRINT((ndo, "%s", getname(tptr)));
+                       ND_PRINT((ndo, "%s", getname(ndo, tptr)));
                }
                break;
        case BGPTYPE_MULTI_EXIT_DISC:
@@ -1412,11 +1412,11 @@ bgp_attr_print(netdissect_options *ndo,
                 if (len == 6) {
                    ND_PRINT((ndo, " AS #%s, origin %s",
                        as_printf(ndo, astostr, sizeof(astostr), EXTRACT_16BITS(tptr)),
-                       getname(tptr + 2)));
+                       getname(ndo, tptr + 2)));
                 } else {
                    ND_PRINT((ndo, " AS #%s, origin %s",
                        as_printf(ndo, astostr, sizeof(astostr),
-                       EXTRACT_32BITS(tptr)), getname(tptr + 4)));
+                       EXTRACT_32BITS(tptr)), getname(ndo, tptr + 4)));
                 }
                 break;
        case BGPTYPE_AGGREGATOR4:
@@ -1427,7 +1427,7 @@ bgp_attr_print(netdissect_options *ndo,
                ND_TCHECK2(tptr[0], 8);
                ND_PRINT((ndo, " AS #%s, origin %s",
                    as_printf(ndo, astostr, sizeof(astostr), EXTRACT_32BITS(tptr)),
-                   getname(tptr + 4)));
+                   getname(ndo, tptr + 4)));
                break;
        case BGPTYPE_COMMUNITIES:
                if (len % 4) {
@@ -1435,7 +1435,7 @@ bgp_attr_print(netdissect_options *ndo,
                        break;
                }
                while (tlen>0) {
-                       u_int32_t comm;
+                       uint32_t comm;
                        ND_TCHECK2(tptr[0], 4);
                        comm = EXTRACT_32BITS(tptr);
                        switch (comm) {
@@ -1465,7 +1465,7 @@ bgp_attr_print(netdissect_options *ndo,
                        break;
                }
                ND_TCHECK2(tptr[0], 4);
-                ND_PRINT((ndo, "%s",getname(tptr)));
+                ND_PRINT((ndo, "%s",getname(ndo, tptr)));
                 break;
         case BGPTYPE_CLUSTER_LIST:
                if (len % 4) {
@@ -1475,7 +1475,7 @@ bgp_attr_print(netdissect_options *ndo,
                 while (tlen>0) {
                        ND_TCHECK2(tptr[0], 4);
                         ND_PRINT((ndo, "%s%s",
-                               getname(tptr),
+                               getname(ndo, tptr),
                                 (tlen>4) ? ", " : ""));
                         tlen -=4;
                         tptr +=4;
@@ -1562,7 +1562,7 @@ bgp_attr_print(netdissect_options *ndo,
                                 tlen = 0;
                             } else {
                                 ND_TCHECK2(tptr[0], sizeof(struct in_addr));
-                                ND_PRINT((ndo, "%s",getname(tptr)));
+                                ND_PRINT((ndo, "%s",getname(ndo, tptr)));
                                 tlen -= sizeof(struct in_addr);
                                 tptr += sizeof(struct in_addr);
                             }
@@ -1577,7 +1577,7 @@ bgp_attr_print(netdissect_options *ndo,
                                 ND_TCHECK2(tptr[0], sizeof(struct in_addr)+BGP_VPN_RD_LEN);
                                 ND_PRINT((ndo, "RD: %s, %s",
                                        bgp_vpn_rd_print(ndo, tptr),
-                                       getname(tptr+BGP_VPN_RD_LEN)));
+                                       getname(ndo, tptr+BGP_VPN_RD_LEN)));
                                 tlen -= (sizeof(struct in_addr)+BGP_VPN_RD_LEN);
                                 tptr += (sizeof(struct in_addr)+BGP_VPN_RD_LEN);
                             }
@@ -1592,7 +1592,7 @@ bgp_attr_print(netdissect_options *ndo,
                                 tlen = 0;
                             } else {
                                 ND_TCHECK2(tptr[0], sizeof(struct in6_addr));
-                                ND_PRINT((ndo, "%s", getname6(tptr)));
+                                ND_PRINT((ndo, "%s", getname6(ndo, tptr)));
                                 tlen -= sizeof(struct in6_addr);
                                 tptr += sizeof(struct in6_addr);
                             }
@@ -1607,7 +1607,7 @@ bgp_attr_print(netdissect_options *ndo,
                                 ND_TCHECK2(tptr[0], sizeof(struct in6_addr)+BGP_VPN_RD_LEN);
                                 ND_PRINT((ndo, "RD: %s, %s",
                                        bgp_vpn_rd_print(ndo, tptr),
-                                       getname6(tptr+BGP_VPN_RD_LEN)));
+                                       getname6(ndo, tptr+BGP_VPN_RD_LEN)));
                                 tlen -= (sizeof(struct in6_addr)+BGP_VPN_RD_LEN);
                                 tptr += (sizeof(struct in6_addr)+BGP_VPN_RD_LEN);
                             }
@@ -1622,7 +1622,7 @@ bgp_attr_print(netdissect_options *ndo,
                                 tlen = 0;
                             } else {
                                 ND_TCHECK2(tptr[0], sizeof(struct in_addr));
-                                ND_PRINT((ndo, "%s", getname(tptr)));
+                                ND_PRINT((ndo, "%s", getname(ndo, tptr)));
                                 tlen -= (sizeof(struct in_addr));
                                 tptr += (sizeof(struct in_addr));
                             }
@@ -1649,11 +1649,11 @@ bgp_attr_print(netdissect_options *ndo,
                                        isonsap_string(tptr+BGP_VPN_RD_LEN,tlen-BGP_VPN_RD_LEN)));
                                 /* rfc986 mapped IPv4 address ? */
                                 if (EXTRACT_32BITS(tptr+BGP_VPN_RD_LEN) ==  0x47000601)
-                                    ND_PRINT((ndo, " = %s", getname(tptr+BGP_VPN_RD_LEN+4)));
+                                    ND_PRINT((ndo, " = %s", getname(ndo, tptr+BGP_VPN_RD_LEN+4)));
 #ifdef INET6
                                 /* rfc1888 mapped IPv6 address ? */
                                 else if (EXTRACT_24BITS(tptr+BGP_VPN_RD_LEN) ==  0x350000)
-                                    ND_PRINT((ndo, " = %s", getname6(tptr+BGP_VPN_RD_LEN+3)));
+                                    ND_PRINT((ndo, " = %s", getname6(ndo, tptr+BGP_VPN_RD_LEN+3)));
 #endif
                                 tptr += tlen;
                                 tlen = 0;
@@ -2008,7 +2008,7 @@ bgp_attr_print(netdissect_options *ndo,
                        break;
                }
                 while (tlen>0) {
-                    u_int16_t extd_comm;
+                    uint16_t extd_comm;
 
                     ND_TCHECK2(tptr[0], 2);
                     extd_comm=EXTRACT_16BITS(tptr);
@@ -2028,14 +2028,14 @@ bgp_attr_print(netdissect_options *ndo,
                         ND_PRINT((ndo, ": %u:%u (= %s)",
                                EXTRACT_16BITS(tptr+2),
                                EXTRACT_32BITS(tptr+4),
-                               getname(tptr+4)));
+                               getname(ndo, tptr+4)));
                         break;
                     case BGP_EXT_COM_RT_1:
                     case BGP_EXT_COM_RO_1:
                     case BGP_EXT_COM_L2VPN_RT_1:
                     case BGP_EXT_COM_VRF_RT_IMP:
                         ND_PRINT((ndo, ": %s:%u",
-                               getname(tptr+2),
+                               getname(ndo, tptr+2),
                                EXTRACT_16BITS(tptr+6)));
                         break;
                     case BGP_EXT_COM_RT_2:
@@ -2055,12 +2055,12 @@ bgp_attr_print(netdissect_options *ndo,
                     case BGP_EXT_COM_VPN_ORIGIN4:
                     case BGP_EXT_COM_OSPF_RID:
                     case BGP_EXT_COM_OSPF_RID2:
-                        ND_PRINT((ndo, "%s", getname(tptr+2)));
+                        ND_PRINT((ndo, "%s", getname(ndo, tptr+2)));
                         break;
                     case BGP_EXT_COM_OSPF_RTYPE:
                     case BGP_EXT_COM_OSPF_RTYPE2:
                         ND_PRINT((ndo, ": area:%s, router-type:%s, metric-type:%s%s",
-                               getname(tptr+2),
+                               getname(ndo, tptr+2),
                                tok2strbuf(bgp_extd_comm_ospf_rtype_values,
                                          "unknown (0x%02x)",
                                          *(tptr+6),
@@ -2092,7 +2092,7 @@ bgp_attr_print(netdissect_options *ndo,
 
         case BGPTYPE_PMSI_TUNNEL:
         {
-                u_int8_t tunnel_type, flags;
+                uint8_t tunnel_type, flags;
 
                 tunnel_type = *(tptr+1);
                 flags = *tptr;
@@ -2113,32 +2113,32 @@ bgp_attr_print(netdissect_options *ndo,
                 case BGP_PMSI_TUNNEL_PIM_BIDIR:
                     ND_TCHECK2(tptr[0], 8);
                     ND_PRINT((ndo, "\n\t      Sender %s, P-Group %s",
-                           ipaddr_string(tptr),
-                           ipaddr_string(tptr+4)));
+                           ipaddr_string(ndo, tptr),
+                           ipaddr_string(ndo, tptr+4)));
                     break;
 
                 case BGP_PMSI_TUNNEL_PIM_SSM:
                     ND_TCHECK2(tptr[0], 8);
                     ND_PRINT((ndo, "\n\t      Root-Node %s, P-Group %s",
-                           ipaddr_string(tptr),
-                           ipaddr_string(tptr+4)));
+                           ipaddr_string(ndo, tptr),
+                           ipaddr_string(ndo, tptr+4)));
                     break;
                 case BGP_PMSI_TUNNEL_INGRESS:
                     ND_TCHECK2(tptr[0], 4);
                     ND_PRINT((ndo, "\n\t      Tunnel-Endpoint %s",
-                           ipaddr_string(tptr)));
+                           ipaddr_string(ndo, tptr)));
                     break;
                 case BGP_PMSI_TUNNEL_LDP_P2MP: /* fall through */
                 case BGP_PMSI_TUNNEL_LDP_MP2MP:
                     ND_TCHECK2(tptr[0], 8);
                     ND_PRINT((ndo, "\n\t      Root-Node %s, LSP-ID 0x%08x",
-                           ipaddr_string(tptr),
+                           ipaddr_string(ndo, tptr),
                            EXTRACT_32BITS(tptr+4)));
                     break;
                 case BGP_PMSI_TUNNEL_RSVP_P2MP:
                     ND_TCHECK2(tptr[0], 8);
                     ND_PRINT((ndo, "\n\t      Extended-Tunnel-ID %s, P2MP-ID 0x%08x",
-                           ipaddr_string(tptr),
+                           ipaddr_string(ndo, tptr),
                            EXTRACT_32BITS(tptr+4)));
                     break;
                 default:
@@ -2320,7 +2320,7 @@ bgp_open_print(netdissect_options *ndo,
        ND_PRINT((ndo, "my AS %s, ",
            as_printf(ndo, astostr, sizeof(astostr), ntohs(bgpo.bgpo_myas))));
        ND_PRINT((ndo, "Holdtime %us, ", ntohs(bgpo.bgpo_holdtime)));
-       ND_PRINT((ndo, "ID %s", getname((u_char *)&bgpo.bgpo_id)));
+       ND_PRINT((ndo, "ID %s", getname(ndo, (u_char *)&bgpo.bgpo_id)));
        ND_PRINT((ndo, "\n\t  Optional parameters, length: %u", bgpo.bgpo_optlen));
 
         /* some little sanity checking */
@@ -2708,7 +2708,7 @@ bgp_print(netdissect_options *ndo,
                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
        };
        struct bgp bgp;
-       u_int16_t hlen;
+       uint16_t hlen;
        char tokbuf[TOKBUFSIZE];
 
        ep = dat + length;