From: guy Date: Mon, 18 Dec 2000 05:41:58 +0000 (+0000) Subject: Making "extracted_ethertype" static to "print-ether.c" broke other X-Git-Tag: tcpdump-3.5.1~34 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/7c4458eb6a0cd2a617adb9a3bbca44e9f59f3937 Making "extracted_ethertype" static to "print-ether.c" broke other dissectors that expected calls to "llc_print()" to set it. (Thanks and a tip of the hat to Olaf Kirch for noticing this.) Make "ether_encap_print()" and "llc_print()" take a pointer to an extracted-Ethertype variable as an argument, have "llc_print()" pass it to "ether_encap_print()", and have "ether_encap_print()" set what it points to rather than setting a static "extracted_ethertype" variable. Get rid of said static "extracted_ethertype" variable in favor of one local to "ether_if_print()", just as other link-layer dissectors have local "extracted_ethertype" variables. --- diff --git a/interface.h b/interface.h index c8462f44..8008fc51 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.146 2000-12-05 06:42:49 guy Exp $ (LBL) + * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.147 2000-12-18 05:41:58 guy Exp $ (LBL) */ #ifndef tcpdump_interface_h @@ -200,9 +200,9 @@ extern void ascii_print(const u_char *, u_int); extern void hex_print_with_offset(const u_char *, u_int, u_int); extern void telnet_print(const u_char *, u_int); extern void hex_print(const u_char *, u_int); -extern int ether_encap_print(u_short, const u_char *, u_int, u_int); +extern int ether_encap_print(u_short, const u_char *, u_int, u_int, u_short *); extern int llc_print(const u_char *, u_int, u_int, const u_char *, - const u_char *); + const u_char *, u_short *); extern void aarp_print(const u_char *, u_int); extern void arp_print(const u_char *, u_int, u_int); extern void atalk_print(const u_char *, u_int); diff --git a/print-cip.c b/print-cip.c index 248fb5e4..7a2de818 100644 --- a/print-cip.c +++ b/print-cip.c @@ -22,7 +22,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-cip.c,v 1.9 2000-09-29 04:58:35 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-cip.c,v 1.10 2000-12-18 05:41:58 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -132,7 +132,8 @@ cip_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) extracted_ethertype = 0; if (ether_type < ETHERMTU) { /* Try to print the LLC-layer header & higher layers */ - if (llc_print(p, length, caplen, NULL, NULL)==0) { + if (llc_print(p, length, caplen, NULL, NULL, + &extracted_ethertype)==0) { /* ether_type not known, print raw packet */ if (!eflag) cip_print((u_char *)bp, length); @@ -143,7 +144,8 @@ cip_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) if (!xflag && !qflag) default_print(p, caplen); } - } else if (ether_encap_print(ether_type, p, length, caplen) == 0) { + } else if (ether_encap_print(ether_type, p, length, caplen, + &extracted_ethertype) == 0) { /* ether_type not known, print raw packet */ if (!eflag) cip_print((u_char *)bp, length + RFC1483LLC_LEN); diff --git a/print-ether.c b/print-ether.c index 167c53e2..0711cca9 100644 --- a/print-ether.c +++ b/print-ether.c @@ -20,7 +20,7 @@ */ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-ether.c,v 1.59 2000-10-22 04:17:53 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-ether.c,v 1.60 2000-12-18 05:41:59 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -67,8 +67,6 @@ ether_print(register const u_char *bp, u_int length) length); } -static u_short extracted_ethertype; - /* * This is the top level routine of the printer. 'p' is the points * to the ether header of the packet, 'h->tv' is the timestamp, @@ -82,6 +80,7 @@ ether_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) u_int length = h->len; struct ether_header *ep; u_short ether_type; + u_short extracted_ethertype; ts_print(&h->ts); @@ -114,7 +113,8 @@ ether_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) extracted_ethertype = 0; if (ether_type <= ETHERMTU) { /* Try to print the LLC-layer header & higher layers */ - if (llc_print(p, length, caplen, ESRC(ep), EDST(ep)) == 0) { + if (llc_print(p, length, caplen, ESRC(ep), EDST(ep), + &extracted_ethertype) == 0) { /* ether_type not known, print raw packet */ if (!eflag) ether_print((u_char *)ep, length); @@ -125,7 +125,8 @@ ether_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) if (!xflag && !qflag) default_print(p, caplen); } - } else if (ether_encap_print(ether_type, p, length, caplen) == 0) { + } else if (ether_encap_print(ether_type, p, length, caplen, + &extracted_ethertype) == 0) { /* ether_type not known, print raw packet */ if (!eflag) ether_print((u_char *)ep, length + ETHER_HDRLEN); @@ -144,16 +145,18 @@ ether_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) * * Returns non-zero if it can do so, zero if the ethertype is unknown. * - * Stuffs the ether type into a global for the benefit of lower layers - * that might want to know what it is. + * The Ethernet type code is passed through a pointer; if it was + * ETHERTYPE_8021Q, it gets updated to be the Ethernet type of + * the 802.1Q payload, for the benefit of lower layers that might + * want to know what it is. */ int ether_encap_print(u_short ethertype, const u_char *p, - u_int length, u_int caplen) + u_int length, u_int caplen, u_short *extracted_ethertype) { recurse: - extracted_ethertype = ethertype; + *extracted_ethertype = ethertype; switch (ethertype) { @@ -202,15 +205,16 @@ ether_encap_print(u_short ethertype, const u_char *p, if (ethertype > ETHERMTU) goto recurse; - extracted_ethertype = 0; + *extracted_ethertype = 0; - if (llc_print(p, length, caplen, p - 18, p - 12) == 0) { + if (llc_print(p, length, caplen, p - 18, p - 12, + extracted_ethertype) == 0) { /* ether_type not known, print raw packet */ if (!eflag) ether_print(p - 18, length + 4); - if (extracted_ethertype) { + if (*extracted_ethertype) { printf("(LLC %s) ", - etherproto_string(htons(extracted_ethertype))); + etherproto_string(htons(*extracted_ethertype))); } if (!xflag && !qflag) default_print(p - 18, caplen + 4); diff --git a/print-fddi.c b/print-fddi.c index f1e0ecf8..6763ad4b 100644 --- a/print-fddi.c +++ b/print-fddi.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-fddi.c,v 1.47 2000-10-09 02:59:40 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-fddi.c,v 1.48 2000-12-18 05:41:59 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -298,8 +298,8 @@ fddi_if_print(u_char *pcap, const struct pcap_pkthdr *h, extracted_ethertype = 0; if ((fddip->fddi_fc & FDDIFC_CLFF) == FDDIFC_LLC_ASYNC) { /* Try to print the LLC-layer header & higher layers */ - if (llc_print(p, length, caplen, ESRC(&ehdr), EDST(&ehdr)) - == 0) { + if (llc_print(p, length, caplen, ESRC(&ehdr), EDST(&ehdr), + &extracted_ethertype) == 0) { /* * Some kinds of LLC packet we cannot * handle intelligently diff --git a/print-gre.c b/print-gre.c index 1076c7fd..1e801b91 100644 --- a/print-gre.c +++ b/print-gre.c @@ -24,7 +24,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-gre.c,v 1.8 2000-09-29 04:58:39 guy Exp $"; + "@(#) $Header: /tcpdump/master/tcpdump/print-gre.c,v 1.9 2000-12-18 05:41:59 guy Exp $"; #endif #ifdef HAVE_CONFIG_H @@ -86,7 +86,7 @@ gre_print(const u_char *bp, u_int length) { const u_char *cp = bp + 4; const struct gre *gre; - u_short flags, proto; + u_short flags, proto, extracted_ethertype; gre = (const struct gre *)bp; @@ -123,7 +123,8 @@ gre_print(const u_char *bp, u_int length) cp += 4; length -= cp - bp; - if (ether_encap_print(proto, cp, length, length) == 0) + if (ether_encap_print(proto, cp, length, length, + &extracted_ethertype) == 0) printf("gre-proto-0x%04X", proto); return; diff --git a/print-lane.c b/print-lane.c index 50103140..149a5aed 100644 --- a/print-lane.c +++ b/print-lane.c @@ -22,7 +22,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-lane.c,v 1.9 2000-09-29 04:58:43 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-lane.c,v 1.10 2000-12-18 05:42:00 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -112,7 +112,8 @@ lane_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) extracted_ethertype = 0; if (ether_type < ETHERMTU) { /* Try to print the LLC-layer header & higher layers */ - if (llc_print(p, length, caplen, ep->h_source,ep->h_dest)==0) { + if (llc_print(p, length, caplen, ep->h_source, ep->h_dest, + &extracted_ethertype) == 0) { /* ether_type not known, print raw packet */ if (!eflag) lane_print((u_char *)ep, length); @@ -123,7 +124,8 @@ lane_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) if (!xflag && !qflag) default_print(p, caplen); } - } else if (ether_encap_print(ether_type, p, length, caplen) == 0) { + } else if (ether_encap_print(ether_type, p, length, caplen, + &extracted_ethertype) == 0) { /* ether_type not known, print raw packet */ if (!eflag) lane_print((u_char *)ep, length + sizeof(*ep)); diff --git a/print-llc.c b/print-llc.c index 2763c0fc..6e757714 100644 --- a/print-llc.c +++ b/print-llc.c @@ -24,7 +24,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-llc.c,v 1.30 2000-12-05 06:42:48 guy Exp $"; + "@(#) $Header: /tcpdump/master/tcpdump/print-llc.c,v 1.31 2000-12-18 05:42:00 guy Exp $"; #endif #ifdef HAVE_CONFIG_H @@ -64,7 +64,7 @@ static struct tok cmd2str[] = { */ int llc_print(const u_char *p, u_int length, u_int caplen, - const u_char *esrc, const u_char *edst) + const u_char *esrc, const u_char *edst, u_short *extracted_ethertype) { struct llc llc; register u_short et; @@ -153,7 +153,8 @@ llc_print(const u_char *p, u_int length, u_int caplen, /* This is an encapsulated Ethernet packet */ et = EXTRACT_16BITS(&llc.ethertype[0]); - ret = ether_encap_print(et, p, length, caplen); + ret = ether_encap_print(et, p, length, caplen, + extracted_ethertype); if (ret) return (ret); } diff --git a/print-token.c b/print-token.c index 156c6109..9fa0b63b 100644 --- a/print-token.c +++ b/print-token.c @@ -25,7 +25,7 @@ */ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-token.c,v 1.8 2000-10-06 04:23:14 guy Exp $"; + "@(#) $Header: /tcpdump/master/tcpdump/print-token.c,v 1.9 2000-12-18 05:42:00 guy Exp $"; #endif #ifdef HAVE_CONFIG_H @@ -180,8 +180,8 @@ token_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) extracted_ethertype = 0; if (FRAME_TYPE(trp) == TOKEN_FC_LLC) { /* Try to print the LLC-layer header & higher layers */ - if (llc_print(p, length, caplen, ESRC(&ehdr), EDST(&ehdr)) - == 0) { + if (llc_print(p, length, caplen, ESRC(&ehdr), EDST(&ehdr), + &extracted_ethertype) == 0) { /* ether_type not known, print raw packet */ if (!eflag) token_print(trp, length,