From: Denis Ovsienko Date: Tue, 4 Mar 2014 09:55:24 +0000 (+0400) Subject: NDOize HSRP, IGRP and UDLD decoders X-Git-Tag: tcpdump-4.6.0~201 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/121340f51409c65277b29b89d3ddbc8f1083d051 NDOize HSRP, IGRP and UDLD decoders --- diff --git a/interface.h b/interface.h index fd7b6f77..ffb25a62 100644 --- a/interface.h +++ b/interface.h @@ -217,7 +217,6 @@ extern u_int ieee802_11_radio_avs_if_print(const struct pcap_pkthdr *, 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 ipN_print(const u_char *, u_int); extern void ipx_print(const u_char *, u_int); extern void isoclns_print(const u_char *, u_int, u_int); @@ -289,7 +288,6 @@ extern u_int symantec_if_print(const struct pcap_pkthdr *, const u_char *); extern void tcp_print(const u_char *, u_int, const u_char *, int); extern void tftp_print(const u_char *, u_int); extern void timed_print(const u_char *); -extern void udld_print(const u_char *, u_int); extern void udp_print(const u_char *, u_int, const u_char *, int); extern void vtp_print(const u_char *, u_int); extern void wb_print(const void *, u_int); @@ -323,7 +321,6 @@ extern void mpls_lsp_ping_print(const u_char *, u_int); extern void zephyr_print(const u_char *, int); extern void zmtp1_print(const u_char *, u_int); extern void zmtp1_print_datagram(const u_char *, u_int); -extern void hsrp_print(const u_char *, u_int); extern void bfd_print(const u_char *, u_int, u_int); extern void sip_print(const u_char *, u_int); extern void syslog_print(const u_char *, u_int); diff --git a/netdissect.h b/netdissect.h index 54474157..adf8c2e4 100644 --- a/netdissect.h +++ b/netdissect.h @@ -374,6 +374,9 @@ extern void dtp_print(netdissect_options *, const u_char *, u_int); extern u_int cip_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern int ipcomp_print(netdissect_options *, register const u_char *, int *); extern u_int ipfc_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); +extern void udld_print(netdissect_options *, const u_char *, u_int); +extern void hsrp_print(netdissect_options *, const u_char *, u_int); +extern void igrp_print(netdissect_options *, const u_char *, u_int); /* stuff that has not yet been rototiled */ extern const u_char * ns_nprint (register const u_char *, register const u_char *); diff --git a/print-hsrp.c b/print-hsrp.c index fbcf5834..0059284f 100644 --- a/print-hsrp.c +++ b/print-hsrp.c @@ -35,8 +35,6 @@ #include -#include - #include "interface.h" #include "addrtoname.h" @@ -93,43 +91,43 @@ struct hsrp { }; void -hsrp_print(register const u_int8_t *bp, register u_int len) +hsrp_print(netdissect_options *ndo, register const u_int8_t *bp, register u_int len) { struct hsrp *hp = (struct hsrp *) bp; - TCHECK(hp->hsrp_version); - printf("HSRPv%d", hp->hsrp_version); + ND_TCHECK(hp->hsrp_version); + ND_PRINT((ndo, "HSRPv%d", hp->hsrp_version)); if (hp->hsrp_version != 0) return; - TCHECK(hp->hsrp_op_code); - printf("-"); - printf("%s ", tok2strary(op_code_str, "unknown (%d)", hp->hsrp_op_code)); - printf("%d: ", len); - TCHECK(hp->hsrp_state); - printf("state=%s ", tok2str(states, "Unknown (%d)", hp->hsrp_state)); - TCHECK(hp->hsrp_group); - printf("group=%d ", hp->hsrp_group); - TCHECK(hp->hsrp_reserved); + ND_TCHECK(hp->hsrp_op_code); + ND_PRINT((ndo, "-")); + ND_PRINT((ndo, "%s ", tok2strary(op_code_str, "unknown (%d)", hp->hsrp_op_code))); + ND_PRINT((ndo, "%d: ", len)); + ND_TCHECK(hp->hsrp_state); + ND_PRINT((ndo, "state=%s ", tok2str(states, "Unknown (%d)", hp->hsrp_state))); + ND_TCHECK(hp->hsrp_group); + ND_PRINT((ndo, "group=%d ", hp->hsrp_group)); + ND_TCHECK(hp->hsrp_reserved); if (hp->hsrp_reserved != 0) { - printf("[reserved=%d!] ", hp->hsrp_reserved); + ND_PRINT((ndo, "[reserved=%d!] ", hp->hsrp_reserved)); } - TCHECK(hp->hsrp_virtaddr); - printf("addr=%s", ipaddr_string(&hp->hsrp_virtaddr)); + ND_TCHECK(hp->hsrp_virtaddr); + ND_PRINT((ndo, "addr=%s", ipaddr_string(&hp->hsrp_virtaddr))); if (vflag) { - printf(" hellotime="); + ND_PRINT((ndo, " hellotime=")); relts_print(hp->hsrp_hellotime); - printf(" holdtime="); + ND_PRINT((ndo, " holdtime=")); relts_print(hp->hsrp_holdtime); - printf(" priority=%d", hp->hsrp_priority); - printf(" auth=\""); + ND_PRINT((ndo, " priority=%d", hp->hsrp_priority)); + ND_PRINT((ndo, " auth=\"")); if (fn_printn(hp->hsrp_authdata, sizeof(hp->hsrp_authdata), snapend)) { - printf("\""); + ND_PRINT((ndo, "\"")); goto trunc; } - printf("\""); + ND_PRINT((ndo, "\"")); } return; trunc: - printf("[|hsrp]"); + ND_PRINT((ndo, "[|hsrp]")); } diff --git a/print-igrp.c b/print-igrp.c index dfbc4025..8234a88d 100644 --- a/print-igrp.c +++ b/print-igrp.c @@ -27,10 +27,7 @@ #include -#include - -#include "interface.h" -#include "ip.h" +#include "netdissect.h" #include "extract.h" /* must come after interface.h */ /* Cisco IGRP definitions */ @@ -67,21 +64,21 @@ struct igrprte { #define IGRP_RTE_SIZE 14 /* don't believe sizeof ! */ static void -igrp_entry_print(register struct igrprte *igr, register int is_interior, - register int is_exterior) +igrp_entry_print(netdissect_options *ndo, register struct igrprte *igr, + register int is_interior, register int is_exterior) { register u_int delay, bandwidth; u_int metric, mtu; if (is_interior) - printf(" *.%d.%d.%d", igr->igr_net[0], - igr->igr_net[1], igr->igr_net[2]); + ND_PRINT((ndo, " *.%d.%d.%d", igr->igr_net[0], + igr->igr_net[1], igr->igr_net[2])); else if (is_exterior) - printf(" X%d.%d.%d.0", igr->igr_net[0], - igr->igr_net[1], igr->igr_net[2]); + ND_PRINT((ndo, " X%d.%d.%d.0", igr->igr_net[0], + igr->igr_net[1], igr->igr_net[2])); else - printf(" %d.%d.%d.0", igr->igr_net[0], - igr->igr_net[1], igr->igr_net[2]); + ND_PRINT((ndo, " %d.%d.%d.0", igr->igr_net[0], + igr->igr_net[1], igr->igr_net[2])); delay = EXTRACT_24BITS(igr->igr_dly); bandwidth = EXTRACT_24BITS(igr->igr_bw); @@ -90,10 +87,10 @@ igrp_entry_print(register struct igrprte *igr, register int is_interior, metric = 0xffffff; mtu = EXTRACT_16BITS(igr->igr_mtu); - printf(" d=%d b=%d r=%d l=%d M=%d mtu=%d in %d hops", + ND_PRINT((ndo, " d=%d b=%d r=%d l=%d M=%d mtu=%d in %d hops", 10 * delay, bandwidth == 0 ? 0 : 10000000 / bandwidth, igr->igr_rel, igr->igr_ld, metric, - mtu, igr->igr_hct); + mtu, igr->igr_hct)); } static const struct tok op2str[] = { @@ -103,7 +100,7 @@ static const struct tok op2str[] = { }; void -igrp_print(register const u_char *bp, u_int length, const u_char *bp2 _U_) +igrp_print(netdissect_options *ndo, register const u_char *bp, u_int length) { register struct igrphdr *hdr; register u_char *cp; @@ -111,39 +108,39 @@ igrp_print(register const u_char *bp, u_int length, const u_char *bp2 _U_) hdr = (struct igrphdr *)bp; cp = (u_char *)(hdr + 1); - (void)printf("igrp:"); + ND_PRINT((ndo, "igrp:")); /* Header */ - TCHECK(*hdr); + ND_TCHECK(*hdr); nint = EXTRACT_16BITS(&hdr->ig_ni); nsys = EXTRACT_16BITS(&hdr->ig_ns); next = EXTRACT_16BITS(&hdr->ig_nx); - (void)printf(" %s V%d edit=%d AS=%d (%d/%d/%d)", + ND_PRINT((ndo, " %s V%d edit=%d AS=%d (%d/%d/%d)", tok2str(op2str, "op-#%d", IGRP_OP(hdr->ig_vop)), IGRP_V(hdr->ig_vop), hdr->ig_ed, EXTRACT_16BITS(&hdr->ig_as), nint, nsys, - next); + next)); length -= sizeof(*hdr); while (length >= IGRP_RTE_SIZE) { if (nint > 0) { - TCHECK2(*cp, IGRP_RTE_SIZE); - igrp_entry_print((struct igrprte *)cp, 1, 0); + ND_TCHECK2(*cp, IGRP_RTE_SIZE); + igrp_entry_print(ndo, (struct igrprte *)cp, 1, 0); --nint; } else if (nsys > 0) { - TCHECK2(*cp, IGRP_RTE_SIZE); - igrp_entry_print((struct igrprte *)cp, 0, 0); + ND_TCHECK2(*cp, IGRP_RTE_SIZE); + igrp_entry_print(ndo, (struct igrprte *)cp, 0, 0); --nsys; } else if (next > 0) { - TCHECK2(*cp, IGRP_RTE_SIZE); - igrp_entry_print((struct igrprte *)cp, 0, 1); + ND_TCHECK2(*cp, IGRP_RTE_SIZE); + igrp_entry_print(ndo, (struct igrprte *)cp, 0, 1); --next; } else { - (void)printf(" [extra bytes %d]", length); + ND_PRINT((ndo, " [extra bytes %d]", length)); break; } cp += IGRP_RTE_SIZE; @@ -152,5 +149,5 @@ igrp_print(register const u_char *bp, u_int length, const u_char *bp2 _U_) if (nint == 0 && nsys == 0 && next == 0) return; trunc: - fputs(" [|igrp]", stdout); + ND_PRINT((ndo, " [|igrp]")); } diff --git a/print-ip.c b/print-ip.c index cdbd3080..e2001145 100644 --- a/print-ip.c +++ b/print-ip.c @@ -400,7 +400,7 @@ again: * match was the current protocol number * assignments say. */ - igrp_print(ipds->cp, ipds->len, (const u_char *)ipds->ip); + igrp_print(ndo, ipds->cp, ipds->len); break; case IPPROTO_EIGRP: diff --git a/print-llc.c b/print-llc.c index 5794365f..b21f5428 100644 --- a/print-llc.c +++ b/print-llc.c @@ -443,7 +443,7 @@ snap_print(const u_char *p, u_int length, u_int caplen, u_int bridge_pad) dtp_print(gndo, p, length); return (1); case PID_CISCO_UDLD: - udld_print(p, length); + udld_print(gndo, p, length); return (1); case PID_CISCO_VTP: vtp_print(p, length); diff --git a/print-udld.c b/print-udld.c index 4f26c6b2..7bc8acec 100644 --- a/print-udld.c +++ b/print-udld.c @@ -24,12 +24,8 @@ #include -#include -#include - -#include "interface.h" +#include "netdissect.h" #include "extract.h" -#include "nlpid.h" #define UDLD_HEADER_LEN 4 #define UDLD_DEVICE_ID_TLV 0x0001 @@ -82,7 +78,7 @@ static const struct tok udld_flags_values[] = { #define UDLD_EXTRACT_OPCODE(x) ((x)&0x1f) void -udld_print (const u_char *pptr, u_int length) +udld_print (netdissect_options *ndo, const u_char *pptr, u_int length) { int code, type, len; const u_char *tptr; @@ -92,33 +88,33 @@ udld_print (const u_char *pptr, u_int length) tptr = pptr; - if (!TTEST2(*tptr, UDLD_HEADER_LEN)) + if (!ND_TTEST2(*tptr, UDLD_HEADER_LEN)) goto trunc; code = UDLD_EXTRACT_OPCODE(*tptr); - printf("UDLDv%u, Code %s (%x), Flags [%s] (0x%02x), length %u", + ND_PRINT((ndo, "UDLDv%u, Code %s (%x), Flags [%s] (0x%02x), length %u", UDLD_EXTRACT_VERSION(*tptr), tok2str(udld_code_values, "Reserved", code), code, bittok2str(udld_flags_values, "none", *(tptr+1)), *(tptr+1), - length); + length)); /* * In non-verbose mode, just print version and opcode type */ - if (vflag < 1) { + if (ndo->ndo_vflag < 1) { return; } - printf("\n\tChecksum 0x%04x (unverified)", EXTRACT_16BITS(tptr+2)); + ND_PRINT((ndo, "\n\tChecksum 0x%04x (unverified)", EXTRACT_16BITS(tptr+2))); tptr += UDLD_HEADER_LEN; while (tptr < (pptr+length)) { - if (!TTEST2(*tptr, 4)) + if (!ND_TTEST2(*tptr, 4)) goto trunc; type = EXTRACT_16BITS(tptr); @@ -131,25 +127,25 @@ udld_print (const u_char *pptr, u_int length) return; } - printf("\n\t%s (0x%04x) TLV, length %u", + ND_PRINT((ndo, "\n\t%s (0x%04x) TLV, length %u", tok2str(udld_tlv_values, "Unknown", type), - type, len); + type, len)); switch (type) { case UDLD_DEVICE_ID_TLV: case UDLD_PORT_ID_TLV: case UDLD_ECHO_TLV: case UDLD_DEVICE_NAME_TLV: - printf(", %s", tptr); + ND_PRINT((ndo, ", %s", tptr)); break; case UDLD_MESSAGE_INTERVAL_TLV: case UDLD_TIMEOUT_INTERVAL_TLV: - printf(", %us", (*tptr)); + ND_PRINT((ndo, ", %us", (*tptr))); break; case UDLD_SEQ_NUMBER_TLV: - printf(", %u", EXTRACT_32BITS(tptr)); + ND_PRINT((ndo, ", %u", EXTRACT_32BITS(tptr))); break; default: @@ -161,7 +157,7 @@ udld_print (const u_char *pptr, u_int length) return; trunc: - printf("[|udld]"); + ND_PRINT((ndo, "[|udld]")); } /* diff --git a/print-udp.c b/print-udp.c index 1d68a39f..2bddae9c 100644 --- a/print-udp.c +++ b/print-udp.c @@ -644,7 +644,7 @@ udp_print(register const u_char *bp, u_int length, ISPORT(RADIUS_NEW_ACCOUNTING_PORT) ) radius_print((const u_char *)(up+1), length); else if (dport == HSRP_PORT) - hsrp_print((const u_char *)(up + 1), length); + hsrp_print(gndo, (const u_char *)(up + 1), length); else if (ISPORT(LWRES_PORT)) lwres_print((const u_char *)(up + 1), length); else if (ISPORT(LDP_PORT))