]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-isakmp.c
Add the ndo parameter to some functions
[tcpdump] / print-isakmp.c
index df9eaf92e94c553c6525f02fc0d3a727d6357736..3af263a817167bc87abc1f4f02e598d47c193f75 100644 (file)
@@ -741,9 +741,11 @@ static const char *etypestr[] = {
 static int
 iszero(const u_char *p, size_t l)
 {
-       while (l--) {
-               if (*p++)
+       while (l != 0) {
+               if (*p)
                        return 0;
+               p++;
+               l--;
        }
        return 1;
 }
@@ -764,7 +766,7 @@ cookie_find(const cookie_t *in)
 
 /* record initiator */
 static void
-cookie_record(const cookie_t *in, const u_char *bp2)
+cookie_record(netdissect_options *ndo, const cookie_t *in, const u_char *bp2)
 {
        int i;
        const struct ip *ip;
@@ -780,14 +782,18 @@ cookie_record(const cookie_t *in, const u_char *bp2)
        switch (IP_V(ip)) {
        case 4:
                cookiecache[ninitiator].version = 4;
-               UNALIGNED_MEMCPY(&cookiecache[ninitiator].iaddr.in4, &ip->ip_src, sizeof(struct in_addr));
-               UNALIGNED_MEMCPY(&cookiecache[ninitiator].raddr.in4, &ip->ip_dst, sizeof(struct in_addr));
+               UNALIGNED_MEMCPY(&cookiecache[ninitiator].iaddr.in4,
+                                ip->ip_src, sizeof(nd_ipv4));
+               UNALIGNED_MEMCPY(&cookiecache[ninitiator].raddr.in4,
+                                ip->ip_dst, sizeof(nd_ipv4));
                break;
        case 6:
                ip6 = (const struct ip6_hdr *)bp2;
                cookiecache[ninitiator].version = 6;
-               UNALIGNED_MEMCPY(&cookiecache[ninitiator].iaddr.in6, &ip6->ip6_src, sizeof(struct in6_addr));
-               UNALIGNED_MEMCPY(&cookiecache[ninitiator].raddr.in6, &ip6->ip6_dst, sizeof(struct in6_addr));
+               UNALIGNED_MEMCPY(&cookiecache[ninitiator].iaddr.in6,
+                                ip6->ip6_src, sizeof(nd_ipv6));
+               UNALIGNED_MEMCPY(&cookiecache[ninitiator].raddr.in6,
+                                ip6->ip6_dst, sizeof(nd_ipv6));
                break;
        default:
                return;
@@ -796,10 +802,10 @@ cookie_record(const cookie_t *in, const u_char *bp2)
        ninitiator = (ninitiator + 1) % MAXINITIATORS;
 }
 
-#define cookie_isinitiator(x, y)       cookie_sidecheck((x), (y), 1)
-#define cookie_isresponder(x, y)       cookie_sidecheck((x), (y), 0)
+#define cookie_isinitiator(ndo, x, y)  cookie_sidecheck(ndo, (x), (y), 1)
+#define cookie_isresponder(ndo, x, y)  cookie_sidecheck(ndo, (x), (y), 0)
 static int
-cookie_sidecheck(int i, const u_char *bp2, int initiator)
+cookie_sidecheck(netdissect_options *ndo, int i, const u_char *bp2, int initiator)
 {
        const struct ip *ip;
        const struct ip6_hdr *ip6;
@@ -810,10 +816,10 @@ cookie_sidecheck(int i, const u_char *bp2, int initiator)
                if (cookiecache[i].version != 4)
                        return 0;
                if (initiator) {
-                       if (UNALIGNED_MEMCMP(&ip->ip_src, &cookiecache[i].iaddr.in4, sizeof(struct in_addr)) == 0)
+                       if (UNALIGNED_MEMCMP(ip->ip_src, &cookiecache[i].iaddr.in4, sizeof(nd_ipv4)) == 0)
                                return 1;
                } else {
-                       if (UNALIGNED_MEMCMP(&ip->ip_src, &cookiecache[i].raddr.in4, sizeof(struct in_addr)) == 0)
+                       if (UNALIGNED_MEMCMP(ip->ip_src, &cookiecache[i].raddr.in4, sizeof(nd_ipv4)) == 0)
                                return 1;
                }
                break;
@@ -822,10 +828,10 @@ cookie_sidecheck(int i, const u_char *bp2, int initiator)
                        return 0;
                ip6 = (const struct ip6_hdr *)bp2;
                if (initiator) {
-                       if (UNALIGNED_MEMCMP(&ip6->ip6_src, &cookiecache[i].iaddr.in6, sizeof(struct in6_addr)) == 0)
+                       if (UNALIGNED_MEMCMP(ip6->ip6_src, &cookiecache[i].iaddr.in6, sizeof(nd_ipv6)) == 0)
                                return 1;
                } else {
-                       if (UNALIGNED_MEMCMP(&ip6->ip6_src, &cookiecache[i].raddr.in6, sizeof(struct in6_addr)) == 0)
+                       if (UNALIGNED_MEMCMP(ip6->ip6_src, &cookiecache[i].raddr.in6, sizeof(nd_ipv6)) == 0)
                                return 1;
                }
                break;
@@ -1169,7 +1175,7 @@ static const struct attrmap ipsec_t_map[] = {
 };
 
 static const struct attrmap encr_t_map[] = {
-       { NULL, 0, { NULL } },  { NULL, 0, { NULL } },  /* 0, 1 */
+       { NULL, 0, { NULL } },  { NULL, 0, { NULL } },  /* 0, 1 */
        { NULL, 0, { NULL } },  { NULL, 0, { NULL } },  /* 2, 3 */
        { NULL, 0, { NULL } },  { NULL, 0, { NULL } },  /* 4, 5 */
        { NULL, 0, { NULL } },  { NULL, 0, { NULL } },  /* 6, 7 */
@@ -1182,7 +1188,7 @@ static const struct attrmap encr_t_map[] = {
 static const struct attrmap oakley_t_map[] = {
        { NULL, 0, { NULL } },
        { "enc", 8,     { NULL, "1des", "idea", "blowfish", "rc5",
-                         "3des", "cast", "aes", }, },
+                         "3des", "cast", "aes", }, },
        { "hash", 7,    { NULL, "md5", "sha1", "tiger",
                          "sha2-256", "sha2-384", "sha2-512", }, },
        { "auth", 6,    { NULL, "preshared", "dss", "rsa sig", "rsa enc",
@@ -1392,7 +1398,7 @@ ikev1_id_print(netdissect_options *ndo, u_char tpay _U_,
                        u_int i;
                        ND_PRINT(" len=%u ", len);
                        for (i = 0; i < len; i++)
-                               safeputchar(ndo, EXTRACT_U_1(data + i));
+                               fn_print_char(ndo, EXTRACT_U_1(data + i));
                        len = 0;
                        break;
                    }
@@ -1402,7 +1408,7 @@ ikev1_id_print(netdissect_options *ndo, u_char tpay _U_,
                        if (len < 8)
                                ND_PRINT(" len=%u [bad: < 8]", len);
                        else {
-                               mask = data + sizeof(struct in_addr);
+                               mask = data + sizeof(nd_ipv4);
                                ND_PRINT(" len=%u %s/%u.%u.%u.%u", len,
                                          ipaddr_string(ndo, data),
                                          EXTRACT_U_1(mask), EXTRACT_U_1(mask + 1),
@@ -1424,7 +1430,7 @@ ikev1_id_print(netdissect_options *ndo, u_char tpay _U_,
                        if (len < 32)
                                ND_PRINT(" len=%u [bad: < 32]", len);
                        else {
-                               mask = (const u_char *)(data + sizeof(struct in6_addr));
+                               mask = (const u_char *)(data + sizeof(nd_ipv6));
                                /*XXX*/
                                ND_PRINT(" len=%u %s/0x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", len,
                                          ip6addr_string(ndo, data),
@@ -1442,7 +1448,7 @@ ikev1_id_print(netdissect_options *ndo, u_char tpay _U_,
                        else {
                                ND_PRINT(" len=%u %s-%s", len,
                                          ipaddr_string(ndo, data),
-                                         ipaddr_string(ndo, data + sizeof(struct in_addr)));
+                                         ipaddr_string(ndo, data + sizeof(nd_ipv4)));
                        }
                        len = 0;
                        break;
@@ -1452,7 +1458,7 @@ ikev1_id_print(netdissect_options *ndo, u_char tpay _U_,
                        else {
                                ND_PRINT(" len=%u %s-%s", len,
                                          ip6addr_string(ndo, data),
-                                         ip6addr_string(ndo, data + sizeof(struct in6_addr)));
+                                         ip6addr_string(ndo, data + sizeof(nd_ipv6)));
                        }
                        len = 0;
                        break;
@@ -2644,7 +2650,7 @@ ikev2_e_print(netdissect_options *ndo,
              int depth)
 {
        const u_char *dat;
-       volatile u_int dlen;
+       u_int dlen;
 #ifdef HAVE_LIBCRYPTO
        uint8_t np;
 #endif
@@ -2746,7 +2752,7 @@ ike_sub0_print(netdissect_options *ndo,
 
        return cp;
 trunc:
-       ND_PRINT(" [|isakmp]");
+       nd_print_trunc(ndo);
        return NULL;
 }
 
@@ -2794,7 +2800,7 @@ static char *
 numstr(u_int x)
 {
        static char buf[20];
-       snprintf(buf, sizeof(buf), "#%u", x);
+       nd_snprintf(buf, sizeof(buf), "#%u", x);
        return buf;
 }
 
@@ -2825,13 +2831,13 @@ ikev1_print(netdissect_options *ndo,
                        /* the first packet */
                        ND_PRINT(" I");
                        if (bp2)
-                               cookie_record(&base->i_ck, bp2);
+                               cookie_record(ndo, &base->i_ck, bp2);
                } else
                        ND_PRINT(" ?");
        } else {
-               if (bp2 && cookie_isinitiator(i, bp2))
+               if (bp2 && cookie_isinitiator(ndo, i, bp2))
                        ND_PRINT(" I");
-               else if (bp2 && cookie_isresponder(i, bp2))
+               else if (bp2 && cookie_isresponder(ndo, i, bp2))
                        ND_PRINT(" R");
                else
                        ND_PRINT(" ?");
@@ -2914,7 +2920,7 @@ ikev2_sub0_print(netdissect_options *ndo, const struct isakmp *base,
 
        return cp;
 trunc:
-       ND_PRINT(" [|isakmp]");
+       nd_print_trunc(ndo);
        return NULL;
 }
 
@@ -3026,6 +3032,7 @@ isakmp_print(netdissect_options *ndo,
        const u_char *ep;
        u_int major, minor;
 
+       ndo->ndo_protocol = "isakmp";
 #ifdef HAVE_LIBCRYPTO
        /* initialize SAs */
        if (ndo->ndo_sa_list_head == NULL) {
@@ -3038,7 +3045,7 @@ isakmp_print(netdissect_options *ndo,
        ep = ndo->ndo_snapend;
 
        if ((const struct isakmp *)ep < p + 1) {
-               ND_PRINT("[|isakmp]");
+               nd_print_trunc(ndo);
                return;
        }
 
@@ -3081,6 +3088,7 @@ isakmp_rfc3948_print(netdissect_options *ndo,
                     const u_char *bp, u_int length,
                     const u_char *bp2)
 {
+       ndo->ndo_protocol = "isakmp_rfc3948";
        ND_TCHECK_1(bp);
        if(length == 1 && EXTRACT_U_1(bp)==0xff) {
                ND_PRINT("isakmp-nat-keep-alive");
@@ -3095,8 +3103,7 @@ isakmp_rfc3948_print(netdissect_options *ndo,
        /*
         * see if this is an IKE packet
         */
-       if (EXTRACT_U_1(bp) == 0 && EXTRACT_U_1(bp + 1) == 0 &&
-           EXTRACT_U_1(bp + 2) == 0 && EXTRACT_U_1(bp + 3) == 0) {
+       if (EXTRACT_BE_U_4(bp) == 0) {
                ND_PRINT("NONESP-encap: ");
                isakmp_print(ndo, bp+4, length-4, bp2);
                return;
@@ -3117,18 +3124,11 @@ isakmp_rfc3948_print(netdissect_options *ndo,
                length -= advance + padlen;
                nh = enh & 0xff;
 
-               ip_print_inner(ndo, bp, length, nh, bp2);
+               ip_inner_print(ndo, bp, length, nh, bp2);
                return;
        }
 
 trunc:
-       ND_PRINT("[|isakmp]");
+       nd_print_trunc(ndo);
        return;
 }
-
-/*
- * Local Variables:
- * c-style: whitesmith
- * c-basic-offset: 8
- * End:
- */