X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/a0f9f103860d7635ac6c6ffb6ae68c8dc9343629..47fc89d711eec0a073d9b3b293a1af901b5bd791:/print-isakmp.c diff --git a/print-isakmp.c b/print-isakmp.c index a688c0d9..a4014364 100644 --- a/print-isakmp.c +++ b/print-isakmp.c @@ -55,10 +55,6 @@ #include "ip6.h" #endif -#ifndef HAVE_SOCKADDR_STORAGE -#define sockaddr_storage sockaddr -#endif - /* refer to RFC 2408 */ typedef u_char cookie_t[8]; @@ -802,21 +798,21 @@ cookie_record(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(struct in_addr)); + UNALIGNED_MEMCPY(&cookiecache[ninitiator].raddr.in4, &ip->ip_dst, sizeof(struct in_addr)); break; #ifdef INET6 case 6: ip6 = (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(struct in6_addr)); + UNALIGNED_MEMCPY(&cookiecache[ninitiator].raddr.in6, &ip6->ip6_dst, sizeof(struct in6_addr)); break; #endif default: return; } - unaligned_memcpy(&cookiecache[ninitiator].initiator, in, sizeof(*in)); + UNALIGNED_MEMCPY(&cookiecache[ninitiator].initiator, in, sizeof(*in)); ninitiator = (ninitiator + 1) % MAXINITIATORS; } @@ -836,10 +832,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(struct in_addr)) == 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(struct in_addr)) == 0) return 1; } break; @@ -849,10 +845,10 @@ cookie_sidecheck(int i, const u_char *bp2, int initiator) return 0; ip6 = (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(struct in6_addr)) == 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(struct in6_addr)) == 0) return 1; } break; @@ -1011,7 +1007,7 @@ ikev1_sa_print(netdissect_options *ndo, u_char tpay _U_, p = (struct ikev1_pl_sa *)ext; ND_TCHECK(*p); - unaligned_memcpy(&sa, ext, sizeof(sa)); + UNALIGNED_MEMCPY(&sa, ext, sizeof(sa)); doi = ntohl(sa.doi); sit = ntohl(sa.sit); if (doi != 1) { @@ -1037,7 +1033,7 @@ ikev1_sa_print(netdissect_options *ndo, u_char tpay _U_, np = (u_char *)ext + sizeof(sa); if (sit != 0x01) { ND_TCHECK2(*(ext + 1), sizeof(ident)); - unaligned_memcpy(&ident, ext + 1, sizeof(ident)); + UNALIGNED_MEMCPY(&ident, ext + 1, sizeof(ident)); ND_PRINT((ndo," ident=%u", (u_int32_t)ntohl(ident))); np += sizeof(ident); } @@ -1068,7 +1064,7 @@ ikev1_p_print(netdissect_options *ndo, u_char tpay _U_, p = (struct ikev1_pl_p *)ext; ND_TCHECK(*p); - unaligned_memcpy(&prop, ext, sizeof(prop)); + UNALIGNED_MEMCPY(&prop, ext, sizeof(prop)); ND_PRINT((ndo," #%d protoid=%s transform=%d", prop.p_no, PROTOIDSTR(prop.prot_id), prop.num_t)); if (prop.spi_size) { @@ -1235,7 +1231,7 @@ ikev1_t_print(netdissect_options *ndo, u_char tpay _U_, p = (struct ikev1_pl_t *)ext; ND_TCHECK(*p); - unaligned_memcpy(&t, ext, sizeof(t)); + UNALIGNED_MEMCPY(&t, ext, sizeof(t)); switch (proto) { case 1: @@ -1297,7 +1293,7 @@ ikev1_ke_print(netdissect_options *ndo, u_char tpay _U_, ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_KE))); ND_TCHECK(*ext); - unaligned_memcpy(&e, ext, sizeof(e)); + UNALIGNED_MEMCPY(&e, ext, sizeof(e)); ND_PRINT((ndo," key len=%d", ntohs(e.len) - 4)); if (2 < ndo->ndo_vflag && 4 < ntohs(e.len)) { ND_PRINT((ndo," ")); @@ -1334,7 +1330,7 @@ ikev1_id_print(netdissect_options *ndo, u_char tpay _U_, p = (struct ikev1_pl_id *)ext; ND_TCHECK(*p); - unaligned_memcpy(&id, ext, sizeof(id)); + UNALIGNED_MEMCPY(&id, ext, sizeof(id)); if (sizeof(*p) < item_len) { data = (u_char *)(p + 1); len = item_len - sizeof(*p); @@ -1367,7 +1363,7 @@ ikev1_id_print(netdissect_options *ndo, u_char tpay _U_, p = (struct ipsecdoi_id *)ext; ND_TCHECK(*p); - unaligned_memcpy(&id, ext, sizeof(id)); + UNALIGNED_MEMCPY(&id, ext, sizeof(id)); ND_PRINT((ndo," idtype=%s", STR_OR_ID(id.type, ipsecidtypestr))); if (id.proto_id) { #ifndef WIN32 @@ -1431,15 +1427,18 @@ ikev1_id_print(netdissect_options *ndo, u_char tpay _U_, break; case IPSECDOI_ID_IPV6_ADDR_SUBNET: { - const u_int32_t *mask; + const u_char *mask; if (len < 20) ND_PRINT((ndo," len=%d [bad: < 20]", len)); else { - mask = (u_int32_t *)(data + sizeof(struct in6_addr)); + mask = (u_char *)(data + sizeof(struct in6_addr)); /*XXX*/ - ND_PRINT((ndo," len=%d %s/0x%08x%08x%08x%08x", len, + ND_PRINT((ndo," len=%d %s/0x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", len, ip6addr_string(data), - mask[0], mask[1], mask[2], mask[3])); + mask[0], mask[1], mask[2], mask[3], + mask[4], mask[5], mask[6], mask[7], + mask[8], mask[9], mask[10], mask[11], + mask[12], mask[13], mask[14], mask[15])); } len = 0; break; @@ -1508,7 +1507,7 @@ ikev1_cert_print(netdissect_options *ndo, u_char tpay _U_, p = (struct ikev1_pl_cert *)ext; ND_TCHECK(*p); - unaligned_memcpy(&cert, ext, sizeof(cert)); + UNALIGNED_MEMCPY(&cert, ext, sizeof(cert)); ND_PRINT((ndo," len=%d", item_len - 4)); ND_PRINT((ndo," type=%s", STR_OR_ID((cert.encode), certstr))); if (2 < ndo->ndo_vflag && 4 < item_len) { @@ -1540,7 +1539,7 @@ ikev1_cr_print(netdissect_options *ndo, u_char tpay _U_, p = (struct ikev1_pl_cert *)ext; ND_TCHECK(*p); - unaligned_memcpy(&cert, ext, sizeof(cert)); + UNALIGNED_MEMCPY(&cert, ext, sizeof(cert)); ND_PRINT((ndo," len=%d", item_len - 4)); ND_PRINT((ndo," type=%s", STR_OR_ID((cert.encode), certstr))); if (2 < ndo->ndo_vflag && 4 < item_len) { @@ -1565,7 +1564,7 @@ ikev1_hash_print(netdissect_options *ndo, u_char tpay _U_, ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_HASH))); ND_TCHECK(*ext); - unaligned_memcpy(&e, ext, sizeof(e)); + UNALIGNED_MEMCPY(&e, ext, sizeof(e)); ND_PRINT((ndo," len=%d", ntohs(e.len) - 4)); if (2 < ndo->ndo_vflag && 4 < ntohs(e.len)) { ND_PRINT((ndo," ")); @@ -1589,7 +1588,7 @@ ikev1_sig_print(netdissect_options *ndo, u_char tpay _U_, ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_SIG))); ND_TCHECK(*ext); - unaligned_memcpy(&e, ext, sizeof(e)); + UNALIGNED_MEMCPY(&e, ext, sizeof(e)); ND_PRINT((ndo," len=%d", ntohs(e.len) - 4)); if (2 < ndo->ndo_vflag && 4 < ntohs(e.len)) { ND_PRINT((ndo," ")); @@ -1615,7 +1614,7 @@ ikev1_nonce_print(netdissect_options *ndo, u_char tpay _U_, ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_NONCE))); ND_TCHECK(*ext); - unaligned_memcpy(&e, ext, sizeof(e)); + UNALIGNED_MEMCPY(&e, ext, sizeof(e)); ND_PRINT((ndo," n len=%d", ntohs(e.len) - 4)); if (2 < ndo->ndo_vflag && 4 < ntohs(e.len)) { ND_PRINT((ndo," ")); @@ -1693,7 +1692,7 @@ ikev1_n_print(netdissect_options *ndo, u_char tpay _U_, p = (struct ikev1_pl_n *)ext; ND_TCHECK(*p); - unaligned_memcpy(&n, ext, sizeof(n)); + UNALIGNED_MEMCPY(&n, ext, sizeof(n)); doi = ntohl(n.doi); proto = n.prot_id; if (doi != 1) { @@ -1751,7 +1750,7 @@ ikev1_n_print(netdissect_options *ndo, u_char tpay _U_, } case IPSECDOI_NTYPE_REPLAY_STATUS: ND_PRINT((ndo,"replay detection %sabled", - (*(u_int32_t *)cp) ? "en" : "dis")); + EXTRACT_32BITS(cp) ? "en" : "dis")); break; case ISAKMP_NTYPE_NO_PROPOSAL_CHOSEN: if (ikev1_sub_print(ndo, ISAKMP_NPTYPE_SA, @@ -1790,7 +1789,7 @@ ikev1_d_print(netdissect_options *ndo, u_char tpay _U_, p = (struct ikev1_pl_d *)ext; ND_TCHECK(*p); - unaligned_memcpy(&d, ext, sizeof(d)); + UNALIGNED_MEMCPY(&d, ext, sizeof(d)); doi = ntohl(d.doi); proto = d.prot_id; if (doi != 1) { @@ -1829,7 +1828,7 @@ ikev1_vid_print(netdissect_options *ndo, u_char tpay _U_, ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_VID))); ND_TCHECK(*ext); - unaligned_memcpy(&e, ext, sizeof(e)); + UNALIGNED_MEMCPY(&e, ext, sizeof(e)); ND_PRINT((ndo," len=%d", ntohs(e.len) - 4)); if (2 < ndo->ndo_vflag && 4 < ntohs(e.len)) { ND_PRINT((ndo," ")); @@ -1861,7 +1860,7 @@ ikev2_gen_print(netdissect_options *ndo, u_char tpay, struct isakmp_gen e; ND_TCHECK(*ext); - unaligned_memcpy(&e, ext, sizeof(e)); + UNALIGNED_MEMCPY(&e, ext, sizeof(e)); ikev2_pay_print(ndo, NPSTR(tpay), e.critical); ND_PRINT((ndo," len=%d", ntohs(e.len) - 4)); @@ -1893,7 +1892,7 @@ ikev2_t_print(netdissect_options *ndo, u_char tpay _U_, int pcount, p = (struct ikev2_t *)ext; ND_TCHECK(*p); - unaligned_memcpy(&t, ext, sizeof(t)); + UNALIGNED_MEMCPY(&t, ext, sizeof(t)); ikev2_pay_print(ndo, NPSTR(ISAKMP_NPTYPE_T), t.h.critical); t_id = ntohs(t.t_id); @@ -1966,7 +1965,7 @@ ikev2_p_print(netdissect_options *ndo, u_char tpay _U_, int pcount _U_, p = (struct ikev2_p *)ext; ND_TCHECK(*p); - unaligned_memcpy(&prop, ext, sizeof(prop)); + UNALIGNED_MEMCPY(&prop, ext, sizeof(prop)); ikev2_pay_print(ndo, NPSTR(ISAKMP_NPTYPE_P), prop.h.critical); ND_PRINT((ndo," #%u protoid=%s transform=%d len=%u", @@ -2001,7 +2000,7 @@ ikev2_sa_print(netdissect_options *ndo, u_char tpay, int osa_length, sa_length; ND_TCHECK(*ext1); - unaligned_memcpy(&e, ext1, sizeof(e)); + UNALIGNED_MEMCPY(&e, ext1, sizeof(e)); ikev2_pay_print(ndo, "sa", e.critical); osa_length= ntohs(e.len); @@ -2030,7 +2029,7 @@ ikev2_ke_print(netdissect_options *ndo, u_char tpay, k = (struct ikev2_ke *)ext; ND_TCHECK(*ext); - unaligned_memcpy(&ke, ext, sizeof(ke)); + UNALIGNED_MEMCPY(&ke, ext, sizeof(ke)); ikev2_pay_print(ndo, NPSTR(tpay), ke.h.critical); ND_PRINT((ndo," len=%u group=%s", ntohs(ke.h.len) - 8, @@ -2060,7 +2059,7 @@ ikev2_ID_print(netdissect_options *ndo, u_char tpay, unsigned char *typedata; ND_TCHECK(*ext); - unaligned_memcpy(&id, ext, sizeof(id)); + UNALIGNED_MEMCPY(&id, ext, sizeof(id)); ikev2_pay_print(ndo, NPSTR(tpay), id.h.critical); id_len = ntohs(id.h.len); @@ -2163,7 +2162,7 @@ ikev2_auth_print(netdissect_options *ndo, u_char tpay, unsigned int len; ND_TCHECK(*ext); - unaligned_memcpy(&a, ext, sizeof(a)); + UNALIGNED_MEMCPY(&a, ext, sizeof(a)); ikev2_pay_print(ndo, NPSTR(tpay), a.h.critical); len = ntohs(a.h.len); @@ -2195,7 +2194,7 @@ ikev2_nonce_print(netdissect_options *ndo, u_char tpay, struct isakmp_gen e; ND_TCHECK(*ext); - unaligned_memcpy(&e, ext, sizeof(e)); + UNALIGNED_MEMCPY(&e, ext, sizeof(e)); ikev2_pay_print(ndo, "nonce", e.critical); ND_PRINT((ndo," len=%d", ntohs(e.len) - 4)); @@ -2230,7 +2229,7 @@ ikev2_n_print(netdissect_options *ndo, u_char tpay _U_, p = (struct ikev2_n *)ext; ND_TCHECK(*p); - unaligned_memcpy(&n, ext, sizeof(n)); + UNALIGNED_MEMCPY(&n, ext, sizeof(n)); ikev2_pay_print(ndo, NPSTR(ISAKMP_NPTYPE_N), n.h.critical); showspi = 1; @@ -2444,7 +2443,7 @@ ikev2_vid_print(netdissect_options *ndo, u_char tpay, int i, len; ND_TCHECK(*ext); - unaligned_memcpy(&e, ext, sizeof(e)); + UNALIGNED_MEMCPY(&e, ext, sizeof(e)); ikev2_pay_print(ndo, NPSTR(tpay), e.critical); ND_PRINT((ndo," len=%d vid=", ntohs(e.len) - 4)); @@ -2507,7 +2506,7 @@ ikev2_e_print(netdissect_options *ndo, volatile int dlen; ND_TCHECK(*ext); - unaligned_memcpy(&e, ext, sizeof(e)); + UNALIGNED_MEMCPY(&e, ext, sizeof(e)); ikev2_pay_print(ndo, NPSTR(tpay), e.critical); dlen = ntohs(e.len)-4; @@ -2579,7 +2578,7 @@ ike_sub0_print(netdissect_options *ndo, cp = (u_char *)ext; ND_TCHECK(*ext); - unaligned_memcpy(&e, ext, sizeof(e)); + UNALIGNED_MEMCPY(&e, ext, sizeof(e)); /* * Since we can't have a payload length of less than 4 bytes, @@ -2622,7 +2621,7 @@ ikev1_sub_print(netdissect_options *ndo, while (np) { ND_TCHECK(*ext); - unaligned_memcpy(&e, ext, sizeof(e)); + UNALIGNED_MEMCPY(&e, ext, sizeof(e)); ND_TCHECK2(*ext, ntohs(e.len)); @@ -2743,7 +2742,7 @@ ikev2_sub0_print(netdissect_options *ndo, struct isakmp *base, cp = (u_char *)ext; ND_TCHECK(*ext); - unaligned_memcpy(&e, ext, sizeof(e)); + UNALIGNED_MEMCPY(&e, ext, sizeof(e)); /* * Since we can't have a payload length of less than 4 bytes, @@ -2799,7 +2798,7 @@ ikev2_sub_print(netdissect_options *ndo, pcount++; ND_TCHECK(*ext); - unaligned_memcpy(&e, ext, sizeof(e)); + UNALIGNED_MEMCPY(&e, ext, sizeof(e)); ND_TCHECK2(*ext, ntohs(e.len)); @@ -2911,7 +2910,7 @@ isakmp_print(netdissect_options *ndo, return; } - unaligned_memcpy(&base, p, sizeof(base)); + UNALIGNED_MEMCPY(&base, p, sizeof(base)); ND_PRINT((ndo,"isakmp")); major = (base.vers & ISAKMP_VERS_MAJOR)