From: mcr Date: Wed, 6 Apr 2005 21:33:27 +0000 (+0000) Subject: added ESP-in-UDP printer from RFC3948. X-Git-Tag: tcpdump-3.9.1~168 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/ca59357767c4953d005812811f5241e4bbe0c0dd added ESP-in-UDP printer from RFC3948. --- diff --git a/interface.h b/interface.h index c67e6a6a..ae535f43 100644 --- a/interface.h +++ b/interface.h @@ -18,7 +18,7 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.243 2005-03-08 08:52:38 hannes Exp $ (LBL) + * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.244 2005-04-06 21:33:27 mcr Exp $ (LBL) */ #ifndef tcpdump_interface_h @@ -205,7 +205,6 @@ extern void gre_print(const u_char *, u_int); extern void icmp_print(const u_char *, u_int, const u_char *, int); extern void igmp_print(const u_char *, u_int); extern void igrp_print(const u_char *, u_int, const u_char *); -extern void ip_print(const u_char *, u_int); extern void ipN_print(const u_char *, u_int); extern u_int ipfc_if_print(const struct pcap_pkthdr *, const u_char *); extern void ipx_print(const u_char *, u_int); @@ -260,7 +259,6 @@ extern void timed_print(const u_char *); extern void udp_print(const u_char *, u_int, const u_char *, int); extern void wb_print(const void *, u_int); extern int ah_print(register const u_char *); -extern void isakmp_print(const u_char *, u_int, const u_char *); extern int ipcomp_print(register const u_char *, int *); extern void rx_print(register const u_char *, int, int, int, u_char *); extern void netbeui_print(u_short, const u_char *, int); diff --git a/netdissect.h b/netdissect.h index ab4dae61..43ad4291 100644 --- a/netdissect.h +++ b/netdissect.h @@ -21,7 +21,7 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) $Header: /tcpdump/master/tcpdump/netdissect.h,v 1.14 2004-12-30 03:36:51 guy Exp $ (LBL) + * @(#) $Header: /tcpdump/master/tcpdump/netdissect.h,v 1.15 2005-04-06 21:33:27 mcr Exp $ (LBL) */ #ifndef netdissect_h @@ -250,6 +250,11 @@ extern int esp_print(netdissect_options *, register const u_char *bp, int len, register const u_char *bp2, int *nhdr, int *padlen); extern void arp_print(netdissect_options *,const u_char *, u_int, u_int); +extern void isakmp_print(netdissect_options *,const u_char *, + u_int, const u_char *); +extern void isakmp_rfc3948_print(netdissect_options *,const u_char *, + u_int, const u_char *); +extern void ip_print(netdissect_options *,const u_char *, u_int); #if 0 extern void ascii_print_with_offset(netdissect_options *, const char *, @@ -301,7 +306,6 @@ extern void igmp_print(netdissect_options *, register const u_char *, u_int); extern void igrp_print(netdissect_options *,const u_char *, u_int, const u_char *); -extern void ip_print(netdissect_options *,const u_char *, u_int); extern void ipN_print(netdissect_options *,const u_char *, u_int); extern void ipx_print(netdissect_options *,const u_char *, u_int); extern void isoclns_print(netdissect_options *,const u_char *, @@ -374,8 +378,6 @@ extern void wb_print(netdissect_options *,const void *, u_int); extern int ah_print(netdissect_options *,register const u_char *, register const u_char *); extern void esp_print_decodesecret(netdissect_options *ndo); -extern void isakmp_print(netdissect_options *,const u_char *, - u_int, const u_char *); extern int ipcomp_print(netdissect_options *,register const u_char *, register const u_char *, int *); extern void rx_print(netdissect_options *,register const u_char *, diff --git a/print-isakmp.c b/print-isakmp.c index 6368cf56..a3cbbac0 100644 --- a/print-isakmp.c +++ b/print-isakmp.c @@ -30,7 +30,7 @@ #ifndef lint static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/tcpdump/print-isakmp.c,v 1.49 2004-11-04 07:49:14 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-isakmp.c,v 1.50 2005-04-06 21:33:27 mcr Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -1096,8 +1096,9 @@ isakmp_n_print(const struct isakmp_gen *ext, u_int item_len, break; default: /* NULL is dummy */ - isakmp_print(cp, item_len - sizeof(*p) - n.spi_size, - NULL); + isakmp_print(gndo, cp, + item_len - sizeof(*p) - n.spi_size, + NULL); } printf(")"); } @@ -1273,7 +1274,9 @@ safememcpy(void *p, const void *q, size_t l) } void -isakmp_print(const u_char *bp, u_int length, const u_char *bp2) +isakmp_print(netdissect_options *ndo, + const u_char *bp, u_int length, + const u_char *bp2) { const struct isakmp *p; struct isakmp base; @@ -1284,7 +1287,7 @@ isakmp_print(const u_char *bp, u_int length, const u_char *bp2) int major, minor; p = (const struct isakmp *)bp; - ep = snapend; + ep = ndo->ndo_snapend; if ((struct isakmp *)ep < p + 1) { printf("[|isakmp]"); @@ -1383,3 +1386,51 @@ done: } } } + +void +isakmp_rfc3948_print(netdissect_options *ndo, + const u_char *bp, u_int length, + const u_char *bp2) +{ + const u_char *ep; + ep = ndo->ndo_snapend; + + if(length == 1 && bp[0]==0xff) { + ND_PRINT((ndo, "isakmp-nat-keep-alive")); + return; + } + + ND_TCHECK2(bp, 4); + + /* + * see if this is an IKE packet + */ + if(bp[0]==0 && bp[1]==0 && bp[2]==0 && bp[3]==0) { + isakmp_print(ndo, bp+4, length-4, bp2); + return; + } + + /* must be an ESP packet */ + { + int nh, enh, padlen; + int advance; + + advance = esp_print(ndo, bp, length, bp2, &enh, &padlen); + if(advance <= 0) + return; + + bp += advance; + length -= advance + padlen; + nh = enh & 0xff; + + /* now need to jump into ip_print(). */ + return; + } + +trunc: + printf("[|isakmp]"); + return; +} + + + diff --git a/print-udp.c b/print-udp.c index 1cd16f60..867c2b6e 100644 --- a/print-udp.c +++ b/print-udp.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/tcpdump/print-udp.c,v 1.136 2004-12-27 01:13:44 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-udp.c,v 1.137 2005-04-06 21:33:28 mcr Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -615,11 +615,11 @@ udp_print(register const u_char *bp, u_int length, #else 0); #endif - else if (ISPORT(ISAKMP_PORT)) - isakmp_print((const u_char *)(up + 1), length, bp2); + else if (ISPORT(ISAKMP_PORT) || ISPORT(ISAKMP_PORT_NATT)) + isakmp_print(gndo, (const u_char *)(up + 1), length, bp2); #if 1 /*???*/ - else if (ISPORT(ISAKMP_PORT_USER1) || ISPORT(ISAKMP_PORT_USER2)) - isakmp_print((const u_char *)(up + 1), length, bp2); + else if (ISPORT(ISAKMP_PORT_USER1) || ISPORT(ISAKMP_PORT_USER2)) + isakmp_print(gndo, (const u_char *)(up + 1), length, bp2); #endif else if (ISPORT(SNMP_PORT) || ISPORT(SNMPTRAP_PORT)) snmp_print((const u_char *)(up + 1), length); @@ -690,3 +690,12 @@ udp_print(register const u_char *bp, u_int length, } else (void)printf("UDP, length %u", (u_int32_t)(ulen - sizeof(*up))); } + + +/* + * Local Variables: + * c-style: whitesmith + * c-basic-offset: 8 + * End: + */ + diff --git a/udp.h b/udp.h index 490645bb..7446c37b 100644 --- a/udp.h +++ b/udp.h @@ -1,4 +1,4 @@ -/* @(#) $Header: /tcpdump/master/tcpdump/udp.h,v 1.7 2004-07-27 17:04:21 hannes Exp $ (LBL) */ +/* @(#) $Header: /tcpdump/master/tcpdump/udp.h,v 1.8 2005-04-06 21:33:28 mcr Exp $ (LBL) */ /* * Copyright (c) 1982, 1986, 1993 * The Regents of the University of California. All rights reserved. @@ -60,6 +60,7 @@ struct udphdr { #define KERBEROS_SEC_PORT 750 /*XXX*/ #define L2TP_PORT 1701 /*XXX*/ #define SIP_PORT 5060 +#define ISAKMP_PORT_NATT 4500 /* rfc3948 */ #define ISAKMP_PORT_USER1 7500 /*XXX - nonstandard*/ #define ISAKMP_PORT_USER2 8500 /*XXX - nonstandard*/ #define RX_PORT_LOW 7000 /*XXX*/