From 1dcd10aceabbc03bf571ea32b892c522cbe923de Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Fri, 3 Feb 2017 12:24:14 -0800 Subject: CVE-2017-12897/ISO CLNS: Use ND_TTEST() for the bounds checks in isoclns_print(). This fixes a buffer over-read discovered by Kamil Frankowicz. Don't pass the remaining caplen - that's too hard to get right, and we were getting it wrong in at least one case; just use ND_TTEST(). Add a test using the capture file supplied by the reporter(s). --- print-ether.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'print-ether.c') diff --git a/print-ether.c b/print-ether.c index 57c07ce9..33a135e0 100644 --- a/print-ether.c +++ b/print-ether.c @@ -367,7 +367,7 @@ ethertype_print(netdissect_options *ndo, ND_PRINT((ndo, " [|osi]")); return (1); } - isoclns_print(ndo, p + 1, length - 1, caplen - 1); + isoclns_print(ndo, p + 1, length - 1); return(1); case ETHERTYPE_PPPOED: -- cgit v1.2.1 From 577621026df8d4a33a34d4e125f9ec964fc0e53c Mon Sep 17 00:00:00 2001 From: Francois-Xavier Le Bail Date: Sat, 18 Nov 2017 11:52:52 +0100 Subject: Rename EXTRACT_nBITS() macros to EXTRACT_BE_nBITS() It indicates clearly that these macros are used to extract big-endian integral values. --- print-ether.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'print-ether.c') diff --git a/print-ether.c b/print-ether.c index 33a135e0..5ffbb273 100644 --- a/print-ether.c +++ b/print-ether.c @@ -102,7 +102,7 @@ ether_hdr_print(netdissect_options *ndo, etheraddr_string(ndo, ESRC(ep)), etheraddr_string(ndo, EDST(ep)))); - length_type = EXTRACT_16BITS(&ep->ether_length_type); + length_type = EXTRACT_BE_16BITS(&ep->ether_length_type); if (!ndo->ndo_qflag) { if (length_type <= ETHERMTU) { ND_PRINT((ndo, ", 802.3")); @@ -168,7 +168,7 @@ ether_print(netdissect_options *ndo, src.addr_string = etheraddr_string; dst.addr = EDST(ep); dst.addr_string = etheraddr_string; - length_type = EXTRACT_16BITS(&ep->ether_length_type); + length_type = EXTRACT_BE_16BITS(&ep->ether_length_type); recurse: /* @@ -201,12 +201,12 @@ recurse: return (hdrlen + length); } if (ndo->ndo_eflag) { - uint16_t tag = EXTRACT_16BITS(p); + uint16_t tag = EXTRACT_BE_16BITS(p); ND_PRINT((ndo, "%s, ", ieee8021q_tci_string(tag))); } - length_type = EXTRACT_16BITS(p + 2); + length_type = EXTRACT_BE_16BITS(p + 2); if (ndo->ndo_eflag && length_type > ETHERMTU) ND_PRINT((ndo, "ethertype %s, ", tok2str(ethertype_values,"0x%04x", length_type))); p += 4; -- cgit v1.2.1 From da20bc56d6100b5275d6f85c4a25bac1dab4e57e Mon Sep 17 00:00:00 2001 From: Francois-Xavier Le Bail Date: Wed, 22 Nov 2017 23:54:09 +0100 Subject: Rename EXTRACT_ macros Now all the macros have a name meaning a count in bytes. With _S_: signed, _U_: unsigned e.g.: EXTRACT_BE_32BITS -> EXTRACT_BE_U_4 EXTRACT_LE_32BITS -> EXTRACT_LE_U_4 ... EXTRACT_BE_INT32 -> EXTRACT_BE_S_4 and have: EXTRACT_8BITS -> EXTRACT_U_1 EXTRACT_INT8 -> EXTRACT_S_1 --- print-ether.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'print-ether.c') diff --git a/print-ether.c b/print-ether.c index 5ffbb273..8d8341ba 100644 --- a/print-ether.c +++ b/print-ether.c @@ -102,7 +102,7 @@ ether_hdr_print(netdissect_options *ndo, etheraddr_string(ndo, ESRC(ep)), etheraddr_string(ndo, EDST(ep)))); - length_type = EXTRACT_BE_16BITS(&ep->ether_length_type); + length_type = EXTRACT_BE_U_2(&ep->ether_length_type); if (!ndo->ndo_qflag) { if (length_type <= ETHERMTU) { ND_PRINT((ndo, ", 802.3")); @@ -168,7 +168,7 @@ ether_print(netdissect_options *ndo, src.addr_string = etheraddr_string; dst.addr = EDST(ep); dst.addr_string = etheraddr_string; - length_type = EXTRACT_BE_16BITS(&ep->ether_length_type); + length_type = EXTRACT_BE_U_2(&ep->ether_length_type); recurse: /* @@ -201,12 +201,12 @@ recurse: return (hdrlen + length); } if (ndo->ndo_eflag) { - uint16_t tag = EXTRACT_BE_16BITS(p); + uint16_t tag = EXTRACT_BE_U_2(p); ND_PRINT((ndo, "%s, ", ieee8021q_tci_string(tag))); } - length_type = EXTRACT_BE_16BITS(p + 2); + length_type = EXTRACT_BE_U_2(p + 2); if (ndo->ndo_eflag && length_type > ETHERMTU) ND_PRINT((ndo, "ethertype %s, ", tok2str(ethertype_values,"0x%04x", length_type))); p += 4; -- cgit v1.2.1 From 7068209574374db8934ceaaac8f92e5eb5c62880 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Tue, 12 Dec 2017 10:36:21 -0800 Subject: Use nd_ types in 802.x and FDDI headers. Use EXTRACT_U_1() as required by those changes. Remove no-longer-necessary & operators from other EXTRACT_ calls. While we're at it, add MAC_ADDR_LEN to netdissect.h, and use it instead of ETHER_ADDR_LEN; eliminate ETHER_ADDR_LEN. Move the maximum Ethernet length field value to ethertype.h, under the name MAX_ETHERNET_LENGTH_VAL. Move the Ethernet header structure, and the #define for the Ethernet header length, to print-ether.c; in non-Ethernet dissectors that were using the Ethernet header structure, just declare two nd_mac_addr variables for the source and destination MAC addresses and use them instead of the Ethernet header (we don't need the type field there). These changes leave nothing in ether.h, so eliminate it. --- print-ether.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'print-ether.c') diff --git a/print-ether.c b/print-ether.c index 8d8341ba..7e7216c4 100644 --- a/print-ether.c +++ b/print-ether.c @@ -31,7 +31,22 @@ #include "extract.h" #include "addrtoname.h" #include "ethertype.h" -#include "ether.h" + +/* + * Structure of an Ethernet header. + */ +struct ether_header { + nd_mac_addr ether_dhost; + nd_mac_addr ether_shost; + nd_uint16_t ether_length_type; +}; + +/* + * Length of an Ethernet header; note that some compilers may pad + * "struct ether_header" to a multiple of 4 bytes, for example, so + * "sizeof (struct ether_header)" may not give the right answer. + */ +#define ETHER_HDRLEN 14 const struct tok ethertype_values[] = { { ETHERTYPE_IP, "IPv4" }, @@ -102,9 +117,9 @@ ether_hdr_print(netdissect_options *ndo, etheraddr_string(ndo, ESRC(ep)), etheraddr_string(ndo, EDST(ep)))); - length_type = EXTRACT_BE_U_2(&ep->ether_length_type); + length_type = EXTRACT_BE_U_2(ep->ether_length_type); if (!ndo->ndo_qflag) { - if (length_type <= ETHERMTU) { + if (length_type <= MAX_ETHERNET_LENGTH_VAL) { ND_PRINT((ndo, ", 802.3")); length = length_type; } else @@ -112,7 +127,7 @@ ether_hdr_print(netdissect_options *ndo, tok2str(ethertype_values,"Unknown", length_type), length_type)); } else { - if (length_type <= ETHERMTU) { + if (length_type <= MAX_ETHERNET_LENGTH_VAL) { ND_PRINT((ndo, ", 802.3")); length = length_type; } else @@ -168,13 +183,13 @@ ether_print(netdissect_options *ndo, src.addr_string = etheraddr_string; dst.addr = EDST(ep); dst.addr_string = etheraddr_string; - length_type = EXTRACT_BE_U_2(&ep->ether_length_type); + length_type = EXTRACT_BE_U_2(ep->ether_length_type); recurse: /* * Is it (gag) an 802.3 encapsulation? */ - if (length_type <= ETHERMTU) { + if (length_type <= MAX_ETHERNET_LENGTH_VAL) { /* Try to print the LLC-layer header & higher layers */ llc_hdrlen = llc_print(ndo, p, length, caplen, &src, &dst); if (llc_hdrlen < 0) { @@ -207,7 +222,7 @@ recurse: } length_type = EXTRACT_BE_U_2(p + 2); - if (ndo->ndo_eflag && length_type > ETHERMTU) + if (ndo->ndo_eflag && length_type > MAX_ETHERNET_LENGTH_VAL) ND_PRINT((ndo, "ethertype %s, ", tok2str(ethertype_values,"0x%04x", length_type))); p += 4; length -= 4; -- cgit v1.2.1 From 5cea2703185c6af1616dc338c43c6cf67b0bec60 Mon Sep 17 00:00:00 2001 From: Francois-Xavier Le Bail Date: Wed, 13 Dec 2017 19:17:47 +0100 Subject: Remove all storage class specifier 'register' Let the compiler do the optimizations (or not) based on build options. Avoid 'value has been optimized out' messages in gdb using '-O0'. --- print-ether.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'print-ether.c') diff --git a/print-ether.c b/print-ether.c index 7e7216c4..ce96e62e 100644 --- a/print-ether.c +++ b/print-ether.c @@ -108,7 +108,7 @@ static inline void ether_hdr_print(netdissect_options *ndo, const u_char *bp, u_int length) { - register const struct ether_header *ep; + const struct ether_header *ep; uint16_t length_type; ep = (const struct ether_header *)bp; -- cgit v1.2.1 From 6a58ce3ad1f0fc8b1bfe3f74435649b4f72b6955 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Sat, 16 Dec 2017 19:57:14 -0800 Subject: Directly refer to ether_shost and ether_dhost; get rid of ESRC() and EDST(). They don't really add anything. --- print-ether.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'print-ether.c') diff --git a/print-ether.c b/print-ether.c index ce96e62e..7143830f 100644 --- a/print-ether.c +++ b/print-ether.c @@ -114,8 +114,8 @@ ether_hdr_print(netdissect_options *ndo, ep = (const struct ether_header *)bp; ND_PRINT((ndo, "%s > %s", - etheraddr_string(ndo, ESRC(ep)), - etheraddr_string(ndo, EDST(ep)))); + etheraddr_string(ndo, ep->ether_shost), + etheraddr_string(ndo, ep->ether_dhost))); length_type = EXTRACT_BE_U_2(ep->ether_length_type); if (!ndo->ndo_qflag) { @@ -179,9 +179,9 @@ ether_print(netdissect_options *ndo, p += ETHER_HDRLEN; hdrlen = ETHER_HDRLEN; - src.addr = ESRC(ep); + src.addr = ep->ether_shost; src.addr_string = etheraddr_string; - dst.addr = EDST(ep); + dst.addr = ep->ether_dhost; dst.addr_string = etheraddr_string; length_type = EXTRACT_BE_U_2(ep->ether_length_type); -- cgit v1.2.1 From e2982e7f6f0b624a773ec5a58885ee80fab46d34 Mon Sep 17 00:00:00 2001 From: Francois-Xavier Le Bail Date: Sun, 7 Jan 2018 11:47:30 +0100 Subject: Update ND_PRINT() as a variadic macro --- print-ether.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'print-ether.c') diff --git a/print-ether.c b/print-ether.c index 7143830f..c1f6fdba 100644 --- a/print-ether.c +++ b/print-ether.c @@ -113,28 +113,28 @@ ether_hdr_print(netdissect_options *ndo, ep = (const struct ether_header *)bp; - ND_PRINT((ndo, "%s > %s", + ND_PRINT("%s > %s", etheraddr_string(ndo, ep->ether_shost), - etheraddr_string(ndo, ep->ether_dhost))); + etheraddr_string(ndo, ep->ether_dhost)); length_type = EXTRACT_BE_U_2(ep->ether_length_type); if (!ndo->ndo_qflag) { if (length_type <= MAX_ETHERNET_LENGTH_VAL) { - ND_PRINT((ndo, ", 802.3")); + ND_PRINT(", 802.3"); length = length_type; } else - ND_PRINT((ndo, ", ethertype %s (0x%04x)", + ND_PRINT(", ethertype %s (0x%04x)", tok2str(ethertype_values,"Unknown", length_type), - length_type)); + length_type); } else { if (length_type <= MAX_ETHERNET_LENGTH_VAL) { - ND_PRINT((ndo, ", 802.3")); + ND_PRINT(", 802.3"); length = length_type; } else - ND_PRINT((ndo, ", %s", tok2str(ethertype_values,"Unknown Ethertype (0x%04x)", length_type))); + ND_PRINT(", %s", tok2str(ethertype_values,"Unknown Ethertype (0x%04x)", length_type)); } - ND_PRINT((ndo, ", length %u: ", length)); + ND_PRINT(", length %u: ", length); } /* @@ -158,11 +158,11 @@ ether_print(netdissect_options *ndo, struct lladdr_info src, dst; if (caplen < ETHER_HDRLEN) { - ND_PRINT((ndo, "[|ether]")); + ND_PRINT("[|ether]"); return (caplen); } if (length < ETHER_HDRLEN) { - ND_PRINT((ndo, "[|ether]")); + ND_PRINT("[|ether]"); return (length); } @@ -208,22 +208,22 @@ recurse: * the enclosed type field. */ if (caplen < 4) { - ND_PRINT((ndo, "[|vlan]")); + ND_PRINT("[|vlan]"); return (hdrlen + caplen); } if (length < 4) { - ND_PRINT((ndo, "[|vlan]")); + ND_PRINT("[|vlan]"); return (hdrlen + length); } if (ndo->ndo_eflag) { uint16_t tag = EXTRACT_BE_U_2(p); - ND_PRINT((ndo, "%s, ", ieee8021q_tci_string(tag))); + ND_PRINT("%s, ", ieee8021q_tci_string(tag)); } length_type = EXTRACT_BE_U_2(p + 2); if (ndo->ndo_eflag && length_type > MAX_ETHERNET_LENGTH_VAL) - ND_PRINT((ndo, "ethertype %s, ", tok2str(ethertype_values,"0x%04x", length_type))); + ND_PRINT("ethertype %s, ", tok2str(ethertype_values,"0x%04x", length_type)); p += 4; length -= 4; caplen -= 4; @@ -294,7 +294,7 @@ netanalyzer_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, * Fail if we don't have enough data for the Hilscher pseudo-header. */ if (h->len < 4 || h->caplen < 4) { - ND_PRINT((ndo, "[|netanalyzer]")); + ND_PRINT("[|netanalyzer]"); return (h->caplen); } @@ -322,7 +322,7 @@ netanalyzer_transparent_if_print(netdissect_options *ndo, * preamble, and SOF. */ if (h->len < 12 || h->caplen < 12) { - ND_PRINT((ndo, "[|netanalyzer-transparent]")); + ND_PRINT("[|netanalyzer-transparent]"); return (h->caplen); } @@ -364,7 +364,7 @@ ethertype_print(netdissect_options *ndo, case ETHERTYPE_ATALK: if (ndo->ndo_vflag) - ND_PRINT((ndo, "et1 ")); + ND_PRINT("et1 "); atalk_print(ndo, p, length); return (1); @@ -373,13 +373,13 @@ ethertype_print(netdissect_options *ndo, return (1); case ETHERTYPE_IPX: - ND_PRINT((ndo, "(NOV-ETHII) ")); + ND_PRINT("(NOV-ETHII) "); ipx_print(ndo, p, length); return (1); case ETHERTYPE_ISO: if (length == 0 || caplen == 0) { - ND_PRINT((ndo, " [|osi]")); + ND_PRINT(" [|osi]"); return (1); } isoclns_print(ndo, p + 1, length - 1); @@ -402,7 +402,7 @@ ethertype_print(netdissect_options *ndo, case ETHERTYPE_PPP: if (length) { - ND_PRINT((ndo, ": ")); + ND_PRINT(": "); ppp_print(ndo, p, length); } return (1); -- cgit v1.2.1 From 513f782ae18791f0c925b9235da749b38159b607 Mon Sep 17 00:00:00 2001 From: Francois-Xavier Le Bail Date: Sat, 20 Jan 2018 15:59:49 +0100 Subject: Use quoted include netdissect-stdinc.h instead of angle-bracketed one --- print-ether.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'print-ether.c') diff --git a/print-ether.c b/print-ether.c index c1f6fdba..31a6044b 100644 --- a/print-ether.c +++ b/print-ether.c @@ -25,7 +25,7 @@ #include "config.h" #endif -#include +#include "netdissect-stdinc.h" #include "netdissect.h" #include "extract.h" -- cgit v1.2.1 From fb2479d733dbe8a991d11909b319341f7db62ab1 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Sun, 21 Jan 2018 12:27:08 -0800 Subject: Always include rather than "config.h". This can prevent bizarre failures if, for example, you've done a configuration in the top-level source directory, leaving behind one config.h file, and then do an out-of-tree build in another directory, with different configuration options. This way, we always pick up the same config.h, in the build directory. --- print-ether.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'print-ether.c') diff --git a/print-ether.c b/print-ether.c index 31a6044b..73947a05 100644 --- a/print-ether.c +++ b/print-ether.c @@ -22,7 +22,7 @@ /* \summary: Ethernet printer */ #ifdef HAVE_CONFIG_H -#include "config.h" +#include #endif #include "netdissect-stdinc.h" -- cgit v1.2.1 From 944e93fa4c29c4e5cdecd858ead5a37430a418af Mon Sep 17 00:00:00 2001 From: Francois-Xavier Le Bail Date: Fri, 26 Jan 2018 15:15:58 +0100 Subject: Remove function specifier 'inline' in printers It was mostly used with large functions. Moreover: Put some function definition names at the beginning of line. Fix a space. --- print-ether.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'print-ether.c') diff --git a/print-ether.c b/print-ether.c index 73947a05..e09f2ac9 100644 --- a/print-ether.c +++ b/print-ether.c @@ -104,7 +104,7 @@ const struct tok ethertype_values[] = { { 0, NULL} }; -static inline void +static void ether_hdr_print(netdissect_options *ndo, const u_char *bp, u_int length) { -- cgit v1.2.1 From 57534b8c0a4699cd71415dbaf10a691a9ee5814c Mon Sep 17 00:00:00 2001 From: Francois-Xavier Le Bail Date: Thu, 1 Mar 2018 16:54:26 +0100 Subject: Ethernet: Rename a variable From 'ep', often used as 'pointer to the end of current packet' to 'ehp' as Ethernet header pointer. --- print-ether.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'print-ether.c') diff --git a/print-ether.c b/print-ether.c index e09f2ac9..0a331d18 100644 --- a/print-ether.c +++ b/print-ether.c @@ -108,16 +108,16 @@ static void ether_hdr_print(netdissect_options *ndo, const u_char *bp, u_int length) { - const struct ether_header *ep; + const struct ether_header *ehp; uint16_t length_type; - ep = (const struct ether_header *)bp; + ehp = (const struct ether_header *)bp; ND_PRINT("%s > %s", - etheraddr_string(ndo, ep->ether_shost), - etheraddr_string(ndo, ep->ether_dhost)); + etheraddr_string(ndo, ehp->ether_shost), + etheraddr_string(ndo, ehp->ether_dhost)); - length_type = EXTRACT_BE_U_2(ep->ether_length_type); + length_type = EXTRACT_BE_U_2(ehp->ether_length_type); if (!ndo->ndo_qflag) { if (length_type <= MAX_ETHERNET_LENGTH_VAL) { ND_PRINT(", 802.3"); @@ -150,7 +150,7 @@ ether_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen, void (*print_encap_header)(netdissect_options *ndo, const u_char *), const u_char *encap_header_arg) { - const struct ether_header *ep; + const struct ether_header *ehp; u_int orig_length; u_short length_type; u_int hdrlen; @@ -175,15 +175,15 @@ ether_print(netdissect_options *ndo, length -= ETHER_HDRLEN; caplen -= ETHER_HDRLEN; - ep = (const struct ether_header *)p; + ehp = (const struct ether_header *)p; p += ETHER_HDRLEN; hdrlen = ETHER_HDRLEN; - src.addr = ep->ether_shost; + src.addr = ehp->ether_shost; src.addr_string = etheraddr_string; - dst.addr = ep->ether_dhost; + dst.addr = ehp->ether_dhost; dst.addr_string = etheraddr_string; - length_type = EXTRACT_BE_U_2(ep->ether_length_type); + length_type = EXTRACT_BE_U_2(ehp->ether_length_type); recurse: /* @@ -254,7 +254,7 @@ recurse: if (!ndo->ndo_eflag) { if (print_encap_header != NULL) (*print_encap_header)(ndo, encap_header_arg); - ether_hdr_print(ndo, (const u_char *)ep, orig_length); + ether_hdr_print(ndo, (const u_char *)ehp, orig_length); } if (!ndo->ndo_suppress_default_print) -- cgit v1.2.1 From 546558eabd81cfc36a81a4df728fdfea0d83b41a Mon Sep 17 00:00:00 2001 From: Francois-Xavier Le Bail Date: Wed, 14 Mar 2018 16:54:17 +0100 Subject: Add the ndo_protocol field in the netdissect_options structure Update this field in printer entry functions. It will be used for some printings. --- print-ether.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'print-ether.c') diff --git a/print-ether.c b/print-ether.c index 0a331d18..112c6e81 100644 --- a/print-ether.c +++ b/print-ether.c @@ -157,6 +157,7 @@ ether_print(netdissect_options *ndo, int llc_hdrlen; struct lladdr_info src, dst; + ndo->ndo_protocol = "ether"; if (caplen < ETHER_HDRLEN) { ND_PRINT("[|ether]"); return (caplen); @@ -274,6 +275,7 @@ u_int ether_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p) { + ndo->ndo_protocol = "ether_if"; return (ether_print(ndo, p, h->len, h->caplen, NULL, NULL)); } @@ -293,6 +295,7 @@ netanalyzer_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, /* * Fail if we don't have enough data for the Hilscher pseudo-header. */ + ndo->ndo_protocol = "netanalyzer_if"; if (h->len < 4 || h->caplen < 4) { ND_PRINT("[|netanalyzer]"); return (h->caplen); @@ -321,6 +324,7 @@ netanalyzer_transparent_if_print(netdissect_options *ndo, * Fail if we don't have enough data for the Hilscher pseudo-header, * preamble, and SOF. */ + ndo->ndo_protocol = "netanalyzer_transparent_if"; if (h->len < 12 || h->caplen < 12) { ND_PRINT("[|netanalyzer-transparent]"); return (h->caplen); -- cgit v1.2.1 From 56e6581c34ceec5469b9f37c19b31a36b0256f3c Mon Sep 17 00:00:00 2001 From: Francois-Xavier Le Bail Date: Mon, 19 Mar 2018 14:25:35 +0100 Subject: Remove useless comments --- print-ether.c | 9 --------- 1 file changed, 9 deletions(-) (limited to 'print-ether.c') diff --git a/print-ether.c b/print-ether.c index 112c6e81..aed2bea8 100644 --- a/print-ether.c +++ b/print-ether.c @@ -476,12 +476,3 @@ ethertype_print(netdissect_options *ndo, return (0); } } - - -/* - * Local Variables: - * c-style: whitesmith - * c-basic-offset: 8 - * End: - */ - -- cgit v1.2.1 From 4dee61760d291060f08e68eed2e7a1b98ce7e4a4 Mon Sep 17 00:00:00 2001 From: Francois-Xavier Le Bail Date: Wed, 6 Jun 2018 15:00:10 +0200 Subject: Add more nd_print_trunc() calls Update the output of some tests accordingly. --- print-ether.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'print-ether.c') diff --git a/print-ether.c b/print-ether.c index aed2bea8..373103dc 100644 --- a/print-ether.c +++ b/print-ether.c @@ -159,11 +159,11 @@ ether_print(netdissect_options *ndo, ndo->ndo_protocol = "ether"; if (caplen < ETHER_HDRLEN) { - ND_PRINT("[|ether]"); + nd_print_trunc(ndo); return (caplen); } if (length < ETHER_HDRLEN) { - ND_PRINT("[|ether]"); + nd_print_trunc(ndo); return (length); } @@ -297,7 +297,7 @@ netanalyzer_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, */ ndo->ndo_protocol = "netanalyzer_if"; if (h->len < 4 || h->caplen < 4) { - ND_PRINT("[|netanalyzer]"); + nd_print_trunc(ndo); return (h->caplen); } @@ -326,7 +326,7 @@ netanalyzer_transparent_if_print(netdissect_options *ndo, */ ndo->ndo_protocol = "netanalyzer_transparent_if"; if (h->len < 12 || h->caplen < 12) { - ND_PRINT("[|netanalyzer-transparent]"); + nd_print_trunc(ndo); return (h->caplen); } -- cgit v1.2.1 From b7fff7058282c332ba1d8d236c9864ab21b16adf Mon Sep 17 00:00:00 2001 From: Francois-Xavier Le Bail Date: Wed, 12 Sep 2018 19:25:14 +0200 Subject: Ethernet: Remove two useless tests Because packet length (length) >= capture length (caplen), when caplen >= ETHER_HDRLEN, length >= caplen cannot be < ETHER_HDRLEN. Same for the other test (length < 4). (see the sanity checks in print.c, pretty_print_packet() function) Moreover: Clean up indentation. --- print-ether.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'print-ether.c') diff --git a/print-ether.c b/print-ether.c index 373103dc..d0eaf8cd 100644 --- a/print-ether.c +++ b/print-ether.c @@ -148,7 +148,8 @@ ether_hdr_print(netdissect_options *ndo, u_int ether_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen, - void (*print_encap_header)(netdissect_options *ndo, const u_char *), const u_char *encap_header_arg) + void (*print_encap_header)(netdissect_options *ndo, const u_char *), + const u_char *encap_header_arg) { const struct ether_header *ehp; u_int orig_length; @@ -162,10 +163,6 @@ ether_print(netdissect_options *ndo, nd_print_trunc(ndo); return (caplen); } - if (length < ETHER_HDRLEN) { - nd_print_trunc(ndo); - return (length); - } if (ndo->ndo_eflag) { if (print_encap_header != NULL) @@ -212,10 +209,6 @@ recurse: ND_PRINT("[|vlan]"); return (hdrlen + caplen); } - if (length < 4) { - ND_PRINT("[|vlan]"); - return (hdrlen + length); - } if (ndo->ndo_eflag) { uint16_t tag = EXTRACT_BE_U_2(p); -- cgit v1.2.1 From 8aa4617181138d2bd09ac37b164b39e99c5f3d3c Mon Sep 17 00:00:00 2001 From: Francois-Xavier Le Bail Date: Thu, 13 Sep 2018 14:24:23 +0200 Subject: Ethernet: Remove two useless tests Because packet length (len) >= capture length (caplen). (see the sanity checks in print.c, pretty_print_packet() function) --- print-ether.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'print-ether.c') diff --git a/print-ether.c b/print-ether.c index d0eaf8cd..1158b794 100644 --- a/print-ether.c +++ b/print-ether.c @@ -289,7 +289,7 @@ netanalyzer_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, * Fail if we don't have enough data for the Hilscher pseudo-header. */ ndo->ndo_protocol = "netanalyzer_if"; - if (h->len < 4 || h->caplen < 4) { + if (h->caplen < 4) { nd_print_trunc(ndo); return (h->caplen); } @@ -318,7 +318,7 @@ netanalyzer_transparent_if_print(netdissect_options *ndo, * preamble, and SOF. */ ndo->ndo_protocol = "netanalyzer_transparent_if"; - if (h->len < 12 || h->caplen < 12) { + if (h->caplen < 12) { nd_print_trunc(ndo); return (h->caplen); } -- cgit v1.2.1 From 818169971c0a572f4fc5763f91396169581e64c9 Mon Sep 17 00:00:00 2001 From: Francois-Xavier Le Bail Date: Thu, 13 Sep 2018 21:05:16 +0200 Subject: Add more nd_print_trunc() calls --- print-ether.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'print-ether.c') diff --git a/print-ether.c b/print-ether.c index 1158b794..887a8eee 100644 --- a/print-ether.c +++ b/print-ether.c @@ -206,7 +206,8 @@ recurse: * the enclosed type field. */ if (caplen < 4) { - ND_PRINT("[|vlan]"); + ndo->ndo_protocol = "vlan"; + nd_print_trunc(ndo); return (hdrlen + caplen); } if (ndo->ndo_eflag) { @@ -376,7 +377,8 @@ ethertype_print(netdissect_options *ndo, case ETHERTYPE_ISO: if (length == 0 || caplen == 0) { - ND_PRINT(" [|osi]"); + ndo->ndo_protocol = "isoclns"; + nd_print_trunc(ndo); return (1); } isoclns_print(ndo, p + 1, length - 1); -- cgit v1.2.1 From 01017da63c1c0d4b241ea29a43e5d5bd1a3a53dd Mon Sep 17 00:00:00 2001 From: Francois-Xavier Le Bail Date: Mon, 19 Nov 2018 16:02:40 +0100 Subject: Revert "Ethernet: Remove two useless tests" This reverts commit b7fff7058282c332ba1d8d236c9864ab21b16adf (partially) The sanity check in print.c/pretty_print_packet() function, packet length (length) >= capture length (caplen), apply when the ether_print() function is called by ether_if_print(), netanalyzer_if_print() or netanalyzer_transparent_if_print(). But the ether_print() function is called in some other cases, thus not sure length always >= caplen. --- print-ether.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'print-ether.c') diff --git a/print-ether.c b/print-ether.c index 887a8eee..d6dd9572 100644 --- a/print-ether.c +++ b/print-ether.c @@ -163,6 +163,10 @@ ether_print(netdissect_options *ndo, nd_print_trunc(ndo); return (caplen); } + if (length < ETHER_HDRLEN) { + nd_print_trunc(ndo); + return (length); + } if (ndo->ndo_eflag) { if (print_encap_header != NULL) @@ -210,6 +214,11 @@ recurse: nd_print_trunc(ndo); return (hdrlen + caplen); } + if (length < 4) { + ndo->ndo_protocol = "vlan"; + nd_print_trunc(ndo); + return (hdrlen + length); + } if (ndo->ndo_eflag) { uint16_t tag = EXTRACT_BE_U_2(p); -- cgit v1.2.1 From 48e290d807a535cdda391eef7e6992c3429c986a Mon Sep 17 00:00:00 2001 From: Florian Fainelli Date: Fri, 18 Jan 2019 15:19:38 -0800 Subject: Ethernet: Allow specifying non-standard Ethernet header length A fair number of proprietary Ethernet switch tagging protocols, such as Broadcom tags for instance, will place their tag between the MAC SA and the Type/Length field. Move the body of ether_print() into ether_print_hdr_len() and specify the Ethernet header length as an argument to that function. ether_print() calls ether_print_hdr_len() with a standard Ethernet header lenght of 14 bytes, while other callers could specify an arbitrary length. We still assume that the first Length/Type field to parse is located 2 bytes before the end of that Ethernet header length. This will be used in a subsequent commit to parse Broadcom tags. --- print-ether.c | 61 +++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 16 deletions(-) (limited to 'print-ether.c') diff --git a/print-ether.c b/print-ether.c index d6dd9572..ba488343 100644 --- a/print-ether.c +++ b/print-ether.c @@ -106,7 +106,8 @@ const struct tok ethertype_values[] = { static void ether_hdr_print(netdissect_options *ndo, - const u_char *bp, u_int length) + const u_char *bp, u_int length, + u_int hdrlen) { const struct ether_header *ehp; uint16_t length_type; @@ -117,7 +118,8 @@ ether_hdr_print(netdissect_options *ndo, etheraddr_string(ndo, ehp->ether_shost), etheraddr_string(ndo, ehp->ether_dhost)); - length_type = EXTRACT_BE_U_2(ehp->ether_length_type); + length_type = EXTRACT_BE_U_2(bp + + (hdrlen - sizeof(ehp->ether_length_type))); if (!ndo->ndo_qflag) { if (length_type <= MAX_ETHERNET_LENGTH_VAL) { ND_PRINT(", 802.3"); @@ -138,7 +140,8 @@ ether_hdr_print(netdissect_options *ndo, } /* - * Print an Ethernet frame. + * Print an Ethernet frame while specyfing a non-standard Ethernet header + * length. * This might be encapsulated within another frame; we might be passed * a pointer to a function that can print header information for that * frame's protocol, and an argument to pass to that function. @@ -146,46 +149,52 @@ ether_hdr_print(netdissect_options *ndo, * FIXME: caplen can and should be derived from ndo->ndo_snapend and p. */ u_int -ether_print(netdissect_options *ndo, +ether_print_hdr_len(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen, void (*print_encap_header)(netdissect_options *ndo, const u_char *), - const u_char *encap_header_arg) + const u_char *encap_header_arg, u_int hdrlen) { const struct ether_header *ehp; u_int orig_length; u_short length_type; - u_int hdrlen; int llc_hdrlen; struct lladdr_info src, dst; - ndo->ndo_protocol = "ether"; - if (caplen < ETHER_HDRLEN) { + /* Unless specified otherwise, assume a standard Ethernet header */ + if (hdrlen == ETHER_HDRLEN) + ndo->ndo_protocol = "ether"; + + if (caplen < hdrlen) { nd_print_trunc(ndo); return (caplen); } - if (length < ETHER_HDRLEN) { + if (length < hdrlen) { nd_print_trunc(ndo); return (length); } + /* If the offset is set, then the upper printer is responsible for + * printing the relevant part of the Ethernet header. + */ if (ndo->ndo_eflag) { if (print_encap_header != NULL) (*print_encap_header)(ndo, encap_header_arg); - ether_hdr_print(ndo, p, length); + ether_hdr_print(ndo, p, length, hdrlen); } + orig_length = length; - length -= ETHER_HDRLEN; - caplen -= ETHER_HDRLEN; + length -= hdrlen; + caplen -= hdrlen; ehp = (const struct ether_header *)p; - p += ETHER_HDRLEN; - hdrlen = ETHER_HDRLEN; + p += hdrlen; src.addr = ehp->ether_shost; src.addr_string = etheraddr_string; dst.addr = ehp->ether_dhost; dst.addr_string = etheraddr_string; - length_type = EXTRACT_BE_U_2(ehp->ether_length_type); + length_type = EXTRACT_BE_U_2((const u_char *)ehp + + (hdrlen - sizeof(ehp->ether_length_type))); recurse: /* @@ -258,7 +267,8 @@ recurse: if (!ndo->ndo_eflag) { if (print_encap_header != NULL) (*print_encap_header)(ndo, encap_header_arg); - ether_hdr_print(ndo, (const u_char *)ehp, orig_length); + ether_hdr_print(ndo, (const u_char *)ehp, orig_length, + hdrlen); } if (!ndo->ndo_suppress_default_print) @@ -268,6 +278,25 @@ recurse: return (hdrlen); } +/* + * Print an Ethernet frame. + * This might be encapsulated within another frame; we might be passed + * a pointer to a function that can print header information for that + * frame's protocol, and an argument to pass to that function. + * + * FIXME: caplen can and should be derived from ndo->ndo_snapend and p. + */ +u_int +ether_print(netdissect_options *ndo, + const u_char *p, u_int length, u_int caplen, + void (*print_encap_header)(netdissect_options *ndo, const u_char *), + const u_char *encap_header_arg) +{ + return (ether_print_hdr_len(ndo, p, length, caplen, + print_encap_header, encap_header_arg, + ETHER_HDRLEN)); +} + /* * This is the top level routine of the printer. 'p' points * to the ether header of the packet, 'h->len' is the length -- cgit v1.2.1 From ee68aa36460d7efeca48747f33b7f2adc0900bfb Mon Sep 17 00:00:00 2001 From: Francois-Xavier Le Bail Date: Sat, 16 Jun 2018 17:23:21 +0200 Subject: Use the new GET_ macros instead of the EXTRACT_ ones The exceptions are currently: Some EXTRACT_ in print-juniper.c, not used on packet buffer pointer. An EXTRACT_BE_U_3 in addrtoname.c, not always used on packet buffer pointer. --- print-ether.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'print-ether.c') diff --git a/print-ether.c b/print-ether.c index ba488343..8e07bb32 100644 --- a/print-ether.c +++ b/print-ether.c @@ -118,8 +118,7 @@ ether_hdr_print(netdissect_options *ndo, etheraddr_string(ndo, ehp->ether_shost), etheraddr_string(ndo, ehp->ether_dhost)); - length_type = EXTRACT_BE_U_2(bp + - (hdrlen - sizeof(ehp->ether_length_type))); + length_type = GET_BE_U_2(bp + (hdrlen - sizeof(ehp->ether_length_type))); if (!ndo->ndo_qflag) { if (length_type <= MAX_ETHERNET_LENGTH_VAL) { ND_PRINT(", 802.3"); @@ -193,8 +192,7 @@ ether_print_hdr_len(netdissect_options *ndo, src.addr_string = etheraddr_string; dst.addr = ehp->ether_dhost; dst.addr_string = etheraddr_string; - length_type = EXTRACT_BE_U_2((const u_char *)ehp + - (hdrlen - sizeof(ehp->ether_length_type))); + length_type = GET_BE_U_2((const u_char *)ehp + (hdrlen - sizeof(ehp->ether_length_type))); recurse: /* @@ -229,12 +227,12 @@ recurse: return (hdrlen + length); } if (ndo->ndo_eflag) { - uint16_t tag = EXTRACT_BE_U_2(p); + uint16_t tag = GET_BE_U_2(p); ND_PRINT("%s, ", ieee8021q_tci_string(tag)); } - length_type = EXTRACT_BE_U_2(p + 2); + length_type = GET_BE_U_2(p + 2); if (ndo->ndo_eflag && length_type > MAX_ETHERNET_LENGTH_VAL) ND_PRINT("ethertype %s, ", tok2str(ethertype_values,"0x%04x", length_type)); p += 4; -- cgit v1.2.1 From 968561fa1d5373681b29c99b1eaff82be17ca8d0 Mon Sep 17 00:00:00 2001 From: Francois-Xavier Le Bail Date: Wed, 3 Apr 2019 15:13:31 +0200 Subject: Clean up whitespaces/indentation --- print-ether.c | 100 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 50 insertions(+), 50 deletions(-) (limited to 'print-ether.c') diff --git a/print-ether.c b/print-ether.c index 8e07bb32..083d7ff7 100644 --- a/print-ether.c +++ b/print-ether.c @@ -106,7 +106,7 @@ const struct tok ethertype_values[] = { static void ether_hdr_print(netdissect_options *ndo, - const u_char *bp, u_int length, + const u_char *bp, u_int length, u_int hdrlen) { const struct ether_header *ehp; @@ -115,25 +115,25 @@ ether_hdr_print(netdissect_options *ndo, ehp = (const struct ether_header *)bp; ND_PRINT("%s > %s", - etheraddr_string(ndo, ehp->ether_shost), - etheraddr_string(ndo, ehp->ether_dhost)); + etheraddr_string(ndo, ehp->ether_shost), + etheraddr_string(ndo, ehp->ether_dhost)); length_type = GET_BE_U_2(bp + (hdrlen - sizeof(ehp->ether_length_type))); if (!ndo->ndo_qflag) { - if (length_type <= MAX_ETHERNET_LENGTH_VAL) { - ND_PRINT(", 802.3"); + if (length_type <= MAX_ETHERNET_LENGTH_VAL) { + ND_PRINT(", 802.3"); length = length_type; } else - ND_PRINT(", ethertype %s (0x%04x)", - tok2str(ethertype_values,"Unknown", length_type), - length_type); - } else { - if (length_type <= MAX_ETHERNET_LENGTH_VAL) { - ND_PRINT(", 802.3"); + ND_PRINT(", ethertype %s (0x%04x)", + tok2str(ethertype_values,"Unknown", length_type), + length_type); + } else { + if (length_type <= MAX_ETHERNET_LENGTH_VAL) { + ND_PRINT(", 802.3"); length = length_type; } else - ND_PRINT(", %s", tok2str(ethertype_values,"Unknown Ethertype (0x%04x)", length_type)); - } + ND_PRINT(", %s", tok2str(ethertype_values,"Unknown Ethertype (0x%04x)", length_type)); + } ND_PRINT(", length %u: ", length); } @@ -149,9 +149,9 @@ ether_hdr_print(netdissect_options *ndo, */ u_int ether_print_hdr_len(netdissect_options *ndo, - const u_char *p, u_int length, u_int caplen, - void (*print_encap_header)(netdissect_options *ndo, const u_char *), - const u_char *encap_header_arg, u_int hdrlen) + const u_char *p, u_int length, u_int caplen, + void (*print_encap_header)(netdissect_options *ndo, const u_char *), + const u_char *encap_header_arg, u_int hdrlen) { const struct ether_header *ehp; u_int orig_length; @@ -209,9 +209,9 @@ recurse: } hdrlen += llc_hdrlen; } else if (length_type == ETHERTYPE_8021Q || - length_type == ETHERTYPE_8021Q9100 || - length_type == ETHERTYPE_8021Q9200 || - length_type == ETHERTYPE_8021QinQ) { + length_type == ETHERTYPE_8021Q9100 || + length_type == ETHERTYPE_8021Q9200 || + length_type == ETHERTYPE_8021QinQ) { /* * Print VLAN information, and then go back and process * the enclosed type field. @@ -226,7 +226,7 @@ recurse: nd_print_trunc(ndo); return (hdrlen + length); } - if (ndo->ndo_eflag) { + if (ndo->ndo_eflag) { uint16_t tag = GET_BE_U_2(p); ND_PRINT("%s, ", ieee8021q_tci_string(tag)); @@ -286,13 +286,13 @@ recurse: */ u_int ether_print(netdissect_options *ndo, - const u_char *p, u_int length, u_int caplen, - void (*print_encap_header)(netdissect_options *ndo, const u_char *), - const u_char *encap_header_arg) + const u_char *p, u_int length, u_int caplen, + void (*print_encap_header)(netdissect_options *ndo, const u_char *), + const u_char *encap_header_arg) { return (ether_print_hdr_len(ndo, p, length, caplen, - print_encap_header, encap_header_arg, - ETHER_HDRLEN)); + print_encap_header, encap_header_arg, + ETHER_HDRLEN)); } /* @@ -303,7 +303,7 @@ ether_print(netdissect_options *ndo, */ u_int ether_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, - const u_char *p) + const u_char *p) { ndo->ndo_protocol = "ether_if"; return (ether_print(ndo, p, h->len, h->caplen, NULL, NULL)); @@ -320,7 +320,7 @@ ether_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, */ u_int netanalyzer_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, - const u_char *p) + const u_char *p) { /* * Fail if we don't have enough data for the Hilscher pseudo-header. @@ -347,8 +347,8 @@ netanalyzer_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, */ u_int netanalyzer_transparent_if_print(netdissect_options *ndo, - const struct pcap_pkthdr *h, - const u_char *p) + const struct pcap_pkthdr *h, + const u_char *p) { /* * Fail if we don't have enough data for the Hilscher pseudo-header, @@ -373,14 +373,14 @@ netanalyzer_transparent_if_print(netdissect_options *ndo, int ethertype_print(netdissect_options *ndo, - u_short ether_type, const u_char *p, - u_int length, u_int caplen, - const struct lladdr_info *src, const struct lladdr_info *dst) + u_short ether_type, const u_char *p, + u_int length, u_int caplen, + const struct lladdr_info *src, const struct lladdr_info *dst) { switch (ether_type) { case ETHERTYPE_IP: - ip_print(ndo, p, length); + ip_print(ndo, p, length); return (1); case ETHERTYPE_IPV6: @@ -389,7 +389,7 @@ ethertype_print(netdissect_options *ndo, case ETHERTYPE_ARP: case ETHERTYPE_REVARP: - arp_print(ndo, p, length, caplen); + arp_print(ndo, p, length, caplen); return (1); case ETHERTYPE_DN: @@ -428,11 +428,11 @@ ethertype_print(netdissect_options *ndo, return (1); case ETHERTYPE_EAPOL: - eap_print(ndo, p, length); + eap_print(ndo, p, length); return (1); case ETHERTYPE_RRCP: - rrcp_print(ndo, p, length, src, dst); + rrcp_print(ndo, p, length, src, dst); return (1); case ETHERTYPE_PPP: @@ -443,11 +443,11 @@ ethertype_print(netdissect_options *ndo, return (1); case ETHERTYPE_MPCP: - mpcp_print(ndo, p, length); + mpcp_print(ndo, p, length); return (1); case ETHERTYPE_SLOW: - slow_print(ndo, p, length); + slow_print(ndo, p, length); return (1); case ETHERTYPE_CFM: @@ -459,13 +459,13 @@ ethertype_print(netdissect_options *ndo, lldp_print(ndo, p, length); return (1); - case ETHERTYPE_NSH: - nsh_print(ndo, p, length); - return (1); + case ETHERTYPE_NSH: + nsh_print(ndo, p, length); + return (1); - case ETHERTYPE_LOOPBACK: + case ETHERTYPE_LOOPBACK: loopback_print(ndo, p, length); - return (1); + return (1); case ETHERTYPE_MPLS: case ETHERTYPE_MPLS_MULTI: @@ -480,14 +480,14 @@ ethertype_print(netdissect_options *ndo, msnlb_print(ndo, p); return (1); - case ETHERTYPE_GEONET_OLD: - case ETHERTYPE_GEONET: - geonet_print(ndo, p, length, src); - return (1); + case ETHERTYPE_GEONET_OLD: + case ETHERTYPE_GEONET: + geonet_print(ndo, p, length, src); + return (1); - case ETHERTYPE_CALM_FAST: - calm_fast_print(ndo, p, length, src); - return (1); + case ETHERTYPE_CALM_FAST: + calm_fast_print(ndo, p, length, src); + return (1); case ETHERTYPE_AOE: aoe_print(ndo, p, length); -- cgit v1.2.1 From cc82ffa44fabb75e4ea10033452699b389c57b8a Mon Sep 17 00:00:00 2001 From: Francois-Xavier Le Bail Date: Wed, 3 Apr 2019 20:59:41 +0200 Subject: Ethernet: Rename a printer Rename ether_print_hdr_len() to ether_hdr_len_print(), with _print suffix like in most similar cases. --- print-ether.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'print-ether.c') diff --git a/print-ether.c b/print-ether.c index 083d7ff7..8382e1ee 100644 --- a/print-ether.c +++ b/print-ether.c @@ -148,7 +148,7 @@ ether_hdr_print(netdissect_options *ndo, * FIXME: caplen can and should be derived from ndo->ndo_snapend and p. */ u_int -ether_print_hdr_len(netdissect_options *ndo, +ether_hdr_len_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen, void (*print_encap_header)(netdissect_options *ndo, const u_char *), const u_char *encap_header_arg, u_int hdrlen) @@ -290,7 +290,7 @@ ether_print(netdissect_options *ndo, void (*print_encap_header)(netdissect_options *ndo, const u_char *), const u_char *encap_header_arg) { - return (ether_print_hdr_len(ndo, p, length, caplen, + return (ether_hdr_len_print(ndo, p, length, caplen, print_encap_header, encap_header_arg, ETHER_HDRLEN)); } -- cgit v1.2.1 From d5c16b1668fef7011a239c216d07024136cc49e7 Mon Sep 17 00:00:00 2001 From: Vivien Didelot Date: Sat, 6 Apr 2019 16:49:10 -0400 Subject: Remove MEDSA ethertype printer MEDSA (which unofficially stands for Marvell EDSA) relies on the unregistered 0xDADA ethertype value that was randomly choosen and currently used by the kernel. But with EDSA this value is programmable, hence can be changed anytime. Now that a reliable DLT parser is implemented for both DSA and EDSA tagged master interfaces, let's get rid for the MEDSA ethertype parser. --- print-ether.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'print-ether.c') diff --git a/print-ether.c b/print-ether.c index 8382e1ee..5d6fded2 100644 --- a/print-ether.c +++ b/print-ether.c @@ -100,7 +100,6 @@ const struct tok ethertype_values[] = { { ETHERTYPE_GEONET, "GeoNet"}, { ETHERTYPE_CALM_FAST, "CALM FAST"}, { ETHERTYPE_AOE, "AoE" }, - { ETHERTYPE_MEDSA, "MEDSA" }, { 0, NULL} }; @@ -493,10 +492,6 @@ ethertype_print(netdissect_options *ndo, aoe_print(ndo, p, length); return (1); - case ETHERTYPE_MEDSA: - medsa_print(ndo, p, length, caplen, src, dst); - return (1); - case ETHERTYPE_LAT: case ETHERTYPE_SCA: case ETHERTYPE_MOPRC: -- cgit v1.2.1 From b7b72b7c6335fb22b712688b144a538be4ae96e9 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Mon, 22 Apr 2019 23:48:45 -0700 Subject: Treat the length field in an Ethernet header as such. If we have an Ethernet packet where the last 2 octets of the header are a length rather than an Ethernet type, and it's less than the remaining length of the packet, shorten the length and captured length, update the snapshot end. Turn the buffer stack into a "packet information" stack, so that, if we *do* update the snapshot end, we push the old end onto the stack, and pop it off as soon as we're done dissecting the Ethernet packet, in case there's more data in the packet after the Ethernet packet. Use the stack when we use the IPv4 and IPv6 length fields as well. --- print-ether.c | 52 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 15 deletions(-) (limited to 'print-ether.c') diff --git a/print-ether.c b/print-ether.c index 5d6fded2..02ab0665 100644 --- a/print-ether.c +++ b/print-ether.c @@ -118,23 +118,27 @@ ether_hdr_print(netdissect_options *ndo, etheraddr_string(ndo, ehp->ether_dhost)); length_type = GET_BE_U_2(bp + (hdrlen - sizeof(ehp->ether_length_type))); - if (!ndo->ndo_qflag) { - if (length_type <= MAX_ETHERNET_LENGTH_VAL) { - ND_PRINT(", 802.3"); - length = length_type; - } else - ND_PRINT(", ethertype %s (0x%04x)", - tok2str(ethertype_values,"Unknown", length_type), - length_type); + if (length_type <= MAX_ETHERNET_LENGTH_VAL) { + /* + * It's a length field. + */ + ND_PRINT(", 802.3, length %u", length_type); + if (length_type > length - hdrlen) + ND_PRINT(" (too large, > %u)", length - hdrlen); + ND_PRINT(": "); } else { - if (length_type <= MAX_ETHERNET_LENGTH_VAL) { - ND_PRINT(", 802.3"); - length = length_type; - } else - ND_PRINT(", %s", tok2str(ethertype_values,"Unknown Ethertype (0x%04x)", length_type)); + /* + * It's a type field. + */ + if (!ndo->ndo_qflag) + ND_PRINT(", ethertype %s (0x%04x), length %u: ", + tok2str(ethertype_values,"Unknown", length_type), + length_type, length); + else + ND_PRINT(", %s, length %u: ", + tok2str(ethertype_values,"Unknown Ethertype (0x%04x)", length_type), + length); } - - ND_PRINT(", length %u: ", length); } /* @@ -198,6 +202,22 @@ recurse: * Is it (gag) an 802.3 encapsulation? */ if (length_type <= MAX_ETHERNET_LENGTH_VAL) { + /* + * The length/type field contains the length of the + * remaining payload; use it as such, as long as + * it's not too large (bigger than the actual payload). + */ + if (length_type < length) { + length = length_type; + if (caplen > length) + caplen = length; + } + + /* + * Cut off the snapshot length to the end of the payload. + */ + nd_push_snapend(ndo, p + length); + /* Try to print the LLC-layer header & higher layers */ llc_hdrlen = llc_print(ndo, p, length, caplen, &src, &dst); if (llc_hdrlen < 0) { @@ -207,6 +227,8 @@ recurse: llc_hdrlen = -llc_hdrlen; } hdrlen += llc_hdrlen; + nd_pop_packet_info(ndo); + return (hdrlen); } else if (length_type == ETHERTYPE_8021Q || length_type == ETHERTYPE_8021Q9100 || length_type == ETHERTYPE_8021Q9200 || -- cgit v1.2.1 From d338a0a1a95d021e9654b4c80ee64fb4d3e40827 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Tue, 23 Apr 2019 13:47:33 -0700 Subject: Print the Ethertype the same way for Ethertypes in VLAN tags as for others. --- print-ether.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'print-ether.c') diff --git a/print-ether.c b/print-ether.c index 02ab0665..4e0d6f0f 100644 --- a/print-ether.c +++ b/print-ether.c @@ -254,8 +254,15 @@ recurse: } length_type = GET_BE_U_2(p + 2); - if (ndo->ndo_eflag && length_type > MAX_ETHERNET_LENGTH_VAL) - ND_PRINT("ethertype %s, ", tok2str(ethertype_values,"0x%04x", length_type)); + if (ndo->ndo_eflag && length_type > MAX_ETHERNET_LENGTH_VAL) { + if (!ndo->ndo_qflag) + ND_PRINT("ethertype %s (0x%04x), ", + tok2str(ethertype_values,"Unknown", length_type), + length_type); + else + ND_PRINT("%s, ", + tok2str(ethertype_values,"Unknown Ethertype (0x%04x)", length_type)); + } p += 4; length -= 4; caplen -= 4; -- cgit v1.2.1 From b258556bb81a53e61ad3a2ce642b50959e0ddc06 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Tue, 23 Apr 2019 15:26:02 -0700 Subject: Handle switch tags more cleanly. Have the switch tag dissectors handle *only* the switch tag, not anything else in the Ethernet header. Have a routine ether_print_switch_tag() that takes a pointer to a routine to dissect the switch tag, and a switch tag length, as an argument, and have a common Ethernet dissection routine called by ether_print_switch_tag() and by ether_print(), passing a null pointer for the switch tag dissector and 0 for the switch tag length. Dissect the switch tag after the MAC addresses, if there's a non-null switch tag routine dissector pointer. Clean up the processing logic in the common Ethernet dissection code - have a loop to process VLAN tags, if any, and, when it's done, handle frames with a length field, frames with a regular type field, and Alteon jumbo frames. --- print-ether.c | 269 ++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 159 insertions(+), 110 deletions(-) (limited to 'print-ether.c') diff --git a/print-ether.c b/print-ether.c index 4e0d6f0f..6202a699 100644 --- a/print-ether.c +++ b/print-ether.c @@ -104,136 +104,112 @@ const struct tok ethertype_values[] = { }; static void -ether_hdr_print(netdissect_options *ndo, - const u_char *bp, u_int length, - u_int hdrlen) +ether_addresses_print(netdissect_options *ndo, const u_char *src, + const u_char *dst) { - const struct ether_header *ehp; - uint16_t length_type; - - ehp = (const struct ether_header *)bp; - - ND_PRINT("%s > %s", - etheraddr_string(ndo, ehp->ether_shost), - etheraddr_string(ndo, ehp->ether_dhost)); + ND_PRINT("%s > %s, ", + etheraddr_string(ndo, src), etheraddr_string(ndo, dst)); +} - length_type = GET_BE_U_2(bp + (hdrlen - sizeof(ehp->ether_length_type))); - if (length_type <= MAX_ETHERNET_LENGTH_VAL) { - /* - * It's a length field. - */ - ND_PRINT(", 802.3, length %u", length_type); - if (length_type > length - hdrlen) - ND_PRINT(" (too large, > %u)", length - hdrlen); - ND_PRINT(": "); - } else { - /* - * It's a type field. - */ - if (!ndo->ndo_qflag) - ND_PRINT(", ethertype %s (0x%04x), length %u: ", - tok2str(ethertype_values,"Unknown", length_type), - length_type, length); - else - ND_PRINT(", %s, length %u: ", - tok2str(ethertype_values,"Unknown Ethertype (0x%04x)", length_type), - length); - } +static void +ether_type_print(netdissect_options *ndo, uint16_t type) +{ + if (!ndo->ndo_qflag) + ND_PRINT("ethertype %s (0x%04x)", + tok2str(ethertype_values, "Unknown", type), type); + else + ND_PRINT("%s", + tok2str(ethertype_values, "Unknown Ethertype (0x%04x)", type)); } /* - * Print an Ethernet frame while specyfing a non-standard Ethernet header - * length. - * This might be encapsulated within another frame; we might be passed - * a pointer to a function that can print header information for that - * frame's protocol, and an argument to pass to that function. + * Common code for printing Ethernet frames. * - * FIXME: caplen can and should be derived from ndo->ndo_snapend and p. + * It can handle Ethernet headers with extra tag information inserted + * after the destination and source addresses, as is inserted by some + * switch chips, and extra encapsulation header information before + * printing Ethernet header information (such as a LANE ID for ATM LANE). */ -u_int -ether_hdr_len_print(netdissect_options *ndo, - const u_char *p, u_int length, u_int caplen, - void (*print_encap_header)(netdissect_options *ndo, const u_char *), - const u_char *encap_header_arg, u_int hdrlen) +static u_int +ether_print_common(netdissect_options *ndo, const u_char *p, u_int length, + u_int caplen, + void (*print_switch_tag)(netdissect_options *ndo, const u_char *), + u_int switch_tag_len, + void (*print_encap_header)(netdissect_options *ndo, const u_char *), + const u_char *encap_header_arg) { const struct ether_header *ehp; u_int orig_length; + u_int hdrlen; u_short length_type; + int printed_length; int llc_hdrlen; struct lladdr_info src, dst; - /* Unless specified otherwise, assume a standard Ethernet header */ - if (hdrlen == ETHER_HDRLEN) - ndo->ndo_protocol = "ether"; - - if (caplen < hdrlen) { + if (caplen < ETHER_HDRLEN + switch_tag_len) { nd_print_trunc(ndo); return (caplen); } - if (length < hdrlen) { + if (length < ETHER_HDRLEN + switch_tag_len) { nd_print_trunc(ndo); return (length); } - /* If the offset is set, then the upper printer is responsible for - * printing the relevant part of the Ethernet header. - */ - if (ndo->ndo_eflag) { - if (print_encap_header != NULL) - (*print_encap_header)(ndo, encap_header_arg); - ether_hdr_print(ndo, p, length, hdrlen); - } + if (print_encap_header != NULL) + (*print_encap_header)(ndo, encap_header_arg); orig_length = length; - length -= hdrlen; - caplen -= hdrlen; + /* + * Get the source and destination addresses, skip past them, + * and print them if we're printing the link-layer header. + */ ehp = (const struct ether_header *)p; - p += hdrlen; - src.addr = ehp->ether_shost; src.addr_string = etheraddr_string; dst.addr = ehp->ether_dhost; dst.addr_string = etheraddr_string; - length_type = GET_BE_U_2((const u_char *)ehp + (hdrlen - sizeof(ehp->ether_length_type))); -recurse: + length -= 2*MAC_ADDR_LEN; + caplen -= 2*MAC_ADDR_LEN; + p += 2*MAC_ADDR_LEN; + hdrlen = 2*MAC_ADDR_LEN; + + if (ndo->ndo_eflag) + ether_addresses_print(ndo, src.addr, dst.addr); + /* - * Is it (gag) an 802.3 encapsulation? + * Print the switch tag, if we have one, and skip past it. */ - if (length_type <= MAX_ETHERNET_LENGTH_VAL) { - /* - * The length/type field contains the length of the - * remaining payload; use it as such, as long as - * it's not too large (bigger than the actual payload). - */ - if (length_type < length) { - length = length_type; - if (caplen > length) - caplen = length; - } + if (print_switch_tag != NULL) + (*print_switch_tag)(ndo, p); - /* - * Cut off the snapshot length to the end of the payload. - */ - nd_push_snapend(ndo, p + length); + length -= switch_tag_len; + caplen -= switch_tag_len; + p += switch_tag_len; + hdrlen += switch_tag_len; - /* Try to print the LLC-layer header & higher layers */ - llc_hdrlen = llc_print(ndo, p, length, caplen, &src, &dst); - if (llc_hdrlen < 0) { - /* packet type not known, print raw packet */ - if (!ndo->ndo_suppress_default_print) - ND_DEFAULTPRINT(p, caplen); - llc_hdrlen = -llc_hdrlen; - } - hdrlen += llc_hdrlen; - nd_pop_packet_info(ndo); - return (hdrlen); - } else if (length_type == ETHERTYPE_8021Q || + /* + * Get the length/type field, skip past it, and print it + * if we're printing the link-layer header. + */ + length_type = GET_BE_U_2(p); + + length -= 2; + caplen += 2; + p += 2; + hdrlen += 2; + + /* + * Process VLAN tag types. + */ + printed_length = 0; + while (length_type == ETHERTYPE_8021Q || length_type == ETHERTYPE_8021Q9100 || length_type == ETHERTYPE_8021Q9200 || length_type == ETHERTYPE_8021QinQ) { /* + * It has a VLAN tag. * Print VLAN information, and then go back and process * the enclosed type field. */ @@ -250,27 +226,65 @@ recurse: if (ndo->ndo_eflag) { uint16_t tag = GET_BE_U_2(p); + ether_type_print(ndo, length_type); + if (!printed_length) { + ND_PRINT(", length %u: ", orig_length); + printed_length = 1; + } else + ND_PRINT(", "); ND_PRINT("%s, ", ieee8021q_tci_string(tag)); } length_type = GET_BE_U_2(p + 2); - if (ndo->ndo_eflag && length_type > MAX_ETHERNET_LENGTH_VAL) { - if (!ndo->ndo_qflag) - ND_PRINT("ethertype %s (0x%04x), ", - tok2str(ethertype_values,"Unknown", length_type), - length_type); - else - ND_PRINT("%s, ", - tok2str(ethertype_values,"Unknown Ethertype (0x%04x)", length_type)); - } p += 4; length -= 4; caplen -= 4; hdrlen += 4; - goto recurse; + } + + /* + * We now have the final length/type field. + */ + if (length_type <= MAX_ETHERNET_LENGTH_VAL) { + /* + * It's a length field, containing the length of the + * remaining payload; use it as such, as long as + * it's not too large (bigger than the actual payload). + */ + if (length_type < length) { + length = length_type; + if (caplen > length) + caplen = length; + } + + /* + * Cut off the snapshot length to the end of the + * payload. + */ + nd_push_snapend(ndo, p + length); + + if (ndo->ndo_eflag) { + ND_PRINT("802.3"); + if (!printed_length) + ND_PRINT(", length %u: ", length); + } + + /* + * An LLC header follows the length. Print that and + * higher layers. + */ + llc_hdrlen = llc_print(ndo, p, length, caplen, &src, &dst); + if (llc_hdrlen < 0) { + /* packet type not known, print raw packet */ + if (!ndo->ndo_suppress_default_print) + ND_DEFAULTPRINT(p, caplen); + llc_hdrlen = -llc_hdrlen; + } + hdrlen += llc_hdrlen; + nd_pop_packet_info(ndo); } else if (length_type == ETHERTYPE_JUMBO) { /* - * Alteon jumbo frames. + * It's a type field, with the type for Alteon jumbo frames. * See * * http://tools.ietf.org/html/draft-ietf-isis-ext-eth-01 @@ -288,13 +302,29 @@ recurse: } hdrlen += llc_hdrlen; } else { + /* + * It's a type field with some other value. + */ + if (ndo->ndo_eflag) { + ether_type_print(ndo, length_type); + if (!printed_length) + ND_PRINT(", length %u: ", orig_length); + else + ND_PRINT(", "); + } if (ethertype_print(ndo, length_type, p, length, caplen, &src, &dst) == 0) { /* type not known, print raw packet */ if (!ndo->ndo_eflag) { - if (print_encap_header != NULL) - (*print_encap_header)(ndo, encap_header_arg); - ether_hdr_print(ndo, (const u_char *)ehp, orig_length, - hdrlen); + /* + * We didn't print the full link-layer + * header, as -e wasn't specified, so + * print only the source and destination + * MAC addresses and the final Ethernet + * type. + */ + ether_addresses_print(ndo, src.addr, dst.addr); + ether_type_print(ndo, length_type); + ND_PRINT(", length %u: ", orig_length); } if (!ndo->ndo_suppress_default_print) @@ -304,6 +334,25 @@ recurse: return (hdrlen); } +/* + * Print an Ethernet frame while specyfing a non-standard Ethernet header + * length. + * This might be encapsulated within another frame; we might be passed + * a pointer to a function that can print header information for that + * frame's protocol, and an argument to pass to that function. + * + * FIXME: caplen can and should be derived from ndo->ndo_snapend and p. + */ +u_int +ether_print_switch_tag(netdissect_options *ndo, const u_char *p, u_int length, + u_int caplen, + void (*print_switch_tag)(netdissect_options *, const u_char *), + u_int switch_tag_len) +{ + return (ether_print_common(ndo, p, length, caplen, print_switch_tag, + switch_tag_len, NULL, NULL)); +} + /* * Print an Ethernet frame. * This might be encapsulated within another frame; we might be passed @@ -318,9 +367,9 @@ ether_print(netdissect_options *ndo, void (*print_encap_header)(netdissect_options *ndo, const u_char *), const u_char *encap_header_arg) { - return (ether_hdr_len_print(ndo, p, length, caplen, - print_encap_header, encap_header_arg, - ETHER_HDRLEN)); + ndo->ndo_protocol = "ether"; + return (ether_print_common(ndo, p, length, caplen, NULL, 0, + print_encap_header, encap_header_arg)); } /* -- cgit v1.2.1 From 720616ddbde6f0fc136e14417bcbb3f2901f1232 Mon Sep 17 00:00:00 2001 From: Bill Fenner Date: Tue, 30 Apr 2019 07:29:10 -0700 Subject: Fix typo that increases, instead of decreases, caplen The refactoring in b258556b introduced this minor error. --- print-ether.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'print-ether.c') diff --git a/print-ether.c b/print-ether.c index 6202a699..e1d3b36d 100644 --- a/print-ether.c +++ b/print-ether.c @@ -196,7 +196,7 @@ ether_print_common(netdissect_options *ndo, const u_char *p, u_int length, length_type = GET_BE_U_2(p); length -= 2; - caplen += 2; + caplen -= 2; p += 2; hdrlen += 2; -- cgit v1.2.1 From e2f14ebc87586ecad6901c09a1cb7e371baf2ea1 Mon Sep 17 00:00:00 2001 From: niks3089 Date: Sat, 18 May 2019 06:18:30 -0700 Subject: New ethertype protocol for Arista Networks --- print-ether.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'print-ether.c') diff --git a/print-ether.c b/print-ether.c index e1d3b36d..d7bc1b40 100644 --- a/print-ether.c +++ b/print-ether.c @@ -100,6 +100,7 @@ const struct tok ethertype_values[] = { { ETHERTYPE_GEONET, "GeoNet"}, { ETHERTYPE_CALM_FAST, "CALM FAST"}, { ETHERTYPE_AOE, "AoE" }, + { ETHERTYPE_ARISTA, "Arista Vendor Specific Protocol" }, { 0, NULL} }; @@ -193,6 +194,7 @@ ether_print_common(netdissect_options *ndo, const u_char *p, u_int length, * Get the length/type field, skip past it, and print it * if we're printing the link-layer header. */ +recurse: length_type = GET_BE_U_2(p); length -= 2; @@ -301,6 +303,34 @@ ether_print_common(netdissect_options *ndo, const u_char *p, u_int length, llc_hdrlen = -llc_hdrlen; } hdrlen += llc_hdrlen; + } else if (length_type == ETHERTYPE_ARISTA) { + if (caplen < 2) { + ND_PRINT("[|arista]"); + return (hdrlen + caplen); + } + if (length < 2) { + ND_PRINT("[|arista]"); + return (hdrlen + length); + } + ether_type_print(ndo, length_type); + ND_PRINT(", length %u: ", orig_length); + int bytesConsumed = arista_print_ethertype(ndo, p, length); + if (bytesConsumed > 0) { + p += bytesConsumed; + length -= bytesConsumed; + caplen -= bytesConsumed; + hdrlen += bytesConsumed; + goto recurse; + } else { + /* subtype/version not known, print raw packet */ + if (!ndo->ndo_eflag && length_type > MAX_ETHERNET_LENGTH_VAL) { + ether_addresses_print(ndo, src.addr, dst.addr); + ether_type_print(ndo, length_type); + ND_PRINT(", length %u: ", orig_length); + } + if (!ndo->ndo_suppress_default_print) + ND_DEFAULTPRINT(p, caplen); + } } else { /* * It's a type field with some other value. -- cgit v1.2.1 From 350d645f0217a176595c48974b2523cef2681e46 Mon Sep 17 00:00:00 2001 From: Francois-Xavier Le Bail Date: Sat, 18 May 2019 16:54:44 +0200 Subject: Ethernet: Fix indentation --- print-ether.c | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'print-ether.c') diff --git a/print-ether.c b/print-ether.c index d7bc1b40..4f8caa97 100644 --- a/print-ether.c +++ b/print-ether.c @@ -303,34 +303,34 @@ recurse: llc_hdrlen = -llc_hdrlen; } hdrlen += llc_hdrlen; - } else if (length_type == ETHERTYPE_ARISTA) { - if (caplen < 2) { - ND_PRINT("[|arista]"); - return (hdrlen + caplen); - } - if (length < 2) { - ND_PRINT("[|arista]"); - return (hdrlen + length); - } - ether_type_print(ndo, length_type); - ND_PRINT(", length %u: ", orig_length); - int bytesConsumed = arista_print_ethertype(ndo, p, length); - if (bytesConsumed > 0) { - p += bytesConsumed; - length -= bytesConsumed; - caplen -= bytesConsumed; - hdrlen += bytesConsumed; - goto recurse; - } else { - /* subtype/version not known, print raw packet */ - if (!ndo->ndo_eflag && length_type > MAX_ETHERNET_LENGTH_VAL) { - ether_addresses_print(ndo, src.addr, dst.addr); - ether_type_print(ndo, length_type); - ND_PRINT(", length %u: ", orig_length); - } - if (!ndo->ndo_suppress_default_print) - ND_DEFAULTPRINT(p, caplen); + } else if (length_type == ETHERTYPE_ARISTA) { + if (caplen < 2) { + ND_PRINT("[|arista]"); + return (hdrlen + caplen); + } + if (length < 2) { + ND_PRINT("[|arista]"); + return (hdrlen + length); + } + ether_type_print(ndo, length_type); + ND_PRINT(", length %u: ", orig_length); + int bytesConsumed = arista_print_ethertype(ndo, p, length); + if (bytesConsumed > 0) { + p += bytesConsumed; + length -= bytesConsumed; + caplen -= bytesConsumed; + hdrlen += bytesConsumed; + goto recurse; + } else { + /* subtype/version not known, print raw packet */ + if (!ndo->ndo_eflag && length_type > MAX_ETHERNET_LENGTH_VAL) { + ether_addresses_print(ndo, src.addr, dst.addr); + ether_type_print(ndo, length_type); + ND_PRINT(", length %u: ", orig_length); } + if (!ndo->ndo_suppress_default_print) + ND_DEFAULTPRINT(p, caplen); + } } else { /* * It's a type field with some other value. -- cgit v1.2.1 From 0636ecf91357b749370170716e0c4cd494bcea84 Mon Sep 17 00:00:00 2001 From: Francois-Xavier Le Bail Date: Thu, 23 May 2019 11:20:16 +0200 Subject: Arista: Rename a printer Rename arista_print_ethertype() to arista_ethertype_print(), with _print suffix like in most similar cases. Moreover: Add a 'summary' comment with the protocol name. --- print-ether.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'print-ether.c') diff --git a/print-ether.c b/print-ether.c index 4f8caa97..8899469b 100644 --- a/print-ether.c +++ b/print-ether.c @@ -314,7 +314,7 @@ recurse: } ether_type_print(ndo, length_type); ND_PRINT(", length %u: ", orig_length); - int bytesConsumed = arista_print_ethertype(ndo, p, length); + int bytesConsumed = arista_ethertype_print(ndo, p, length); if (bytesConsumed > 0) { p += bytesConsumed; length -= bytesConsumed; -- cgit v1.2.1 From 8534f3b7bfbb81a76fc110a79bbbfedf35cc4f30 Mon Sep 17 00:00:00 2001 From: Francois-Xavier Le Bail Date: Mon, 5 Aug 2019 15:11:50 +0200 Subject: Use more HTTPS in URLs [skip ci] --- print-ether.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'print-ether.c') diff --git a/print-ether.c b/print-ether.c index 8899469b..0454c9a7 100644 --- a/print-ether.c +++ b/print-ether.c @@ -289,7 +289,7 @@ recurse: * It's a type field, with the type for Alteon jumbo frames. * See * - * http://tools.ietf.org/html/draft-ietf-isis-ext-eth-01 + * https://tools.ietf.org/html/draft-ietf-isis-ext-eth-01 * * which indicates that, following the type field, * there's an LLC header and payload. -- cgit v1.2.1 From 306c2a0384af923a73bf234f3c8bc186ceff0b58 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Sun, 19 Jan 2020 19:55:38 -0800 Subject: More bounds checking when fetching addresses and converting to strings. Replace more calls to ipaddr_string()/ip6addr_string() with calls to GET_IPADDR_STRING()/GET_IP6ADDR_STRING() macros performing bounds checking. Add similar bounds-checking inline functions and macros to wrap linkaddr_string(), etheraddr_string(), and isonsap_string() and convert calls to them to use the macros as well. Shuffle the inline functions in addrtoname.h around a bit, so that the inline functions, external declarations, and macros are all in the same order. --- print-ether.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'print-ether.c') diff --git a/print-ether.c b/print-ether.c index 0454c9a7..c9d27d44 100644 --- a/print-ether.c +++ b/print-ether.c @@ -109,7 +109,7 @@ ether_addresses_print(netdissect_options *ndo, const u_char *src, const u_char *dst) { ND_PRINT("%s > %s, ", - etheraddr_string(ndo, src), etheraddr_string(ndo, dst)); + GET_ETHERADDR_STRING(src), GET_ETHERADDR_STRING(dst)); } static void -- cgit v1.2.1 From 8380f5ff00dadc620426318ae75f2916738b6da0 Mon Sep 17 00:00:00 2001 From: Jeff Chan Date: Fri, 21 Feb 2020 04:32:48 -0800 Subject: Dispatch the PTP ethertype to ptp_print() This implements "IEEE 802.3/Ethernet" mode as described in annex F of the PTP standard. This uses the same format packets, but directly over Ethernet instead of encapsulated in UDP. --- print-ether.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'print-ether.c') diff --git a/print-ether.c b/print-ether.c index c9d27d44..74479ccf 100644 --- a/print-ether.c +++ b/print-ether.c @@ -100,6 +100,7 @@ const struct tok ethertype_values[] = { { ETHERTYPE_GEONET, "GeoNet"}, { ETHERTYPE_CALM_FAST, "CALM FAST"}, { ETHERTYPE_AOE, "AoE" }, + { ETHERTYPE_PTP, "PTP" }, { ETHERTYPE_ARISTA, "Arista Vendor Specific Protocol" }, { 0, NULL} }; @@ -600,6 +601,10 @@ ethertype_print(netdissect_options *ndo, aoe_print(ndo, p, length); return (1); + case ETHERTYPE_PTP: + ptp_print(ndo, p, length); + return (1); + case ETHERTYPE_LAT: case ETHERTYPE_SCA: case ETHERTYPE_MOPRC: -- cgit v1.2.1 From 19a7707e79c1b3191ada3725f69cfd6c640cfb5c Mon Sep 17 00:00:00 2001 From: Francois-Xavier Le Bail Date: Sun, 8 Mar 2020 12:36:46 +0100 Subject: Ethernet: Rename a printer Rename ether_print_switch_tag() to ether_switch_tag_print(), with _print suffix like in most similar cases. --- print-ether.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'print-ether.c') diff --git a/print-ether.c b/print-ether.c index 74479ccf..eed66ace 100644 --- a/print-ether.c +++ b/print-ether.c @@ -375,7 +375,7 @@ recurse: * FIXME: caplen can and should be derived from ndo->ndo_snapend and p. */ u_int -ether_print_switch_tag(netdissect_options *ndo, const u_char *p, u_int length, +ether_switch_tag_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen, void (*print_switch_tag)(netdissect_options *, const u_char *), u_int switch_tag_len) -- cgit v1.2.1 From 3ae0efa35ac7b56c8bbfcf8def208f1249b01e13 Mon Sep 17 00:00:00 2001 From: Francois-Xavier Le Bail Date: Tue, 28 Apr 2020 15:53:34 +0200 Subject: Ethernet: Rename a printer Rename ether_print_common() to ether_common_print(), with _print suffix like in most similar cases. Moreover: Fix indent. --- print-ether.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'print-ether.c') diff --git a/print-ether.c b/print-ether.c index eed66ace..299c2013 100644 --- a/print-ether.c +++ b/print-ether.c @@ -133,7 +133,7 @@ ether_type_print(netdissect_options *ndo, uint16_t type) * printing Ethernet header information (such as a LANE ID for ATM LANE). */ static u_int -ether_print_common(netdissect_options *ndo, const u_char *p, u_int length, +ether_common_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen, void (*print_switch_tag)(netdissect_options *ndo, const u_char *), u_int switch_tag_len, @@ -380,7 +380,7 @@ ether_switch_tag_print(netdissect_options *ndo, const u_char *p, u_int length, void (*print_switch_tag)(netdissect_options *, const u_char *), u_int switch_tag_len) { - return (ether_print_common(ndo, p, length, caplen, print_switch_tag, + return (ether_common_print(ndo, p, length, caplen, print_switch_tag, switch_tag_len, NULL, NULL)); } @@ -399,8 +399,8 @@ ether_print(netdissect_options *ndo, const u_char *encap_header_arg) { ndo->ndo_protocol = "ether"; - return (ether_print_common(ndo, p, length, caplen, NULL, 0, - print_encap_header, encap_header_arg)); + return (ether_common_print(ndo, p, length, caplen, NULL, 0, + print_encap_header, encap_header_arg)); } /* -- cgit v1.2.1