summaryrefslogtreecommitdiff
path: root/print-ether.c
Commit message (Collapse)AuthorAgeFilesLines
* Fail if nd_push_buffer() or nd_push_snaplen() fails.Guy Harris2022-04-011-1/+4
| | | | | | | | Always call ndo->ndo_error with a memory-allocation error if they fail. Add WARN_UNUSED_RESULT for compilers that support it, and use it for those routines, so that any future code that doesn't check for failure gets a warning.
* Have routines that set the snapend take a buffer pointer and length as args.Guy Harris2022-03-311-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | Have nd_push_buffer() take a snapshot length, not a snapshot end, as its last argument. Replace nd_push_snapend() and nd_change_snapend() with nd_push_snaplen() and nd_change_snaplen(), both of which take a pointer into the packet buffer and snapshot length relative to that pointer as arguments. Have those routines check the snapshot length to make sure it's not bigger than the number of bytes in the packet past the pointer, and silently ignore the requst if it is. Using a length rather than a pointer avoids the possibility of the calculation of the snapshot end overflowing and resulting in a snapshot end *before* the point in the buffer. Add a test for this, with a capture file containing an IPv6 packet with an extremely large "jumbo" packet size. Revert the "Make sure we don't set the snapend before the beginning of the packet." changes, as they no longer apply with this change (which also makes sure we don't set the snapend before the beginning of the packet).
* Support more Realtek protocols than RRCP.Guy Harris2022-01-231-3/+3
| | | | | | | The Ethertype 0x8899 is used by Realtek for several over-the-wire protocols, as well as for supplying tag information to a host CPU from a Realtek chip. Add code to handle protocols other than RRCP, although we don't fully dissect all of them.
* Update the ND_LCHECK*() macros to ND_ICHECK*() macrosFrancois-Xavier Le Bail2021-12-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | ICHECK like Invalid-Check. Reminder: If the checked expression is true an error message is printed and a 'goto invalid' is executed. This change adds the parameter 'operator'. Before this change, '<' comparison was hard coded. We can do now: ND_ICHECK_U(length, <, HEADER_LEN); ND_ICHECK_U(length, ==, 24); ND_ICHECK_U(length, !=, 8); ND_ICHECK_ZU(length, <, sizeof(struct my_struct)); ND_ICHECKMSG_U("message length", msg_tlen, <, 4); ... (Any comparison operator) Remark: The change of names from ND_LCHECK*() to ND_ICHECK*() is because something else than a length(L) can be checked. Moreover: Place the 'message' parameter at the beginning of ND_ICHECKMSG_U() and ND_ICHECKMSG_ZU() paramaters lists.
* Ethernet: Add a length checkFrancois-Xavier Le Bail2021-11-211-1/+3
| | | | | | | | | | | | | | This fix some undefined behaviors at runtime. The errors were like: print-ether.c:241:11: runtime error: unsigned integer overflow: 1 - 2 cannot be represented in type 'unsigned int' print-ether.c:242:11: runtime error: unsigned integer overflow: 1 - 2 cannot be represented in type 'unsigned int' Moreover: Fix indentation.
* Ethernet: Rework the length checksFrancois-Xavier Le Bail2021-11-211-4/+5
| | | | | | | | | | | Add a sanity check: packet length need to be >= capture length (Like a sanity check in print.c, pretty_print_packet() function) Remove a now useless test: Because packet length (length) >= capture length (caplen), when caplen >= ETHER_HDRLEN + switch_tag_len, length cannot be < ETHER_HDRLEN + switch_tag_len.
* Use more the ND_TCHECK_1() macroFrancois-Xavier Le Bail2021-08-151-1/+1
| | | | This is a follow-up to 7b7b84716e604abd8bd92cee75e6385cab6ce3dc.
* Ethernet: Add a bounds checkFrancois-Xavier Le Bail2021-05-061-0/+3
| | | | | | | | Avoid to have p (current pointer on packet data) > ndo->ndo_snapend in isoclns_print() in some cases. Moreover: Add a "FIXME" comment.
* NetAnalyzer: Use ND_TCHECK_LEN() for bounds checksFrancois-Xavier Le Bail2020-11-161-10/+3
| | | | | | Moreover: Define ND_LONGJMP_FROM_TCHECK. Remove 2 ndo_ll_hdr_len increments in truncation cases.
* Rework "Update more link-layer dissectors to void functions"Francois-Xavier Le Bail2020-08-061-44/+27
| | | | | | | | | | It's a follow-up to commit 81dbf4a0b05092760d0ff0cdd48c692e4769ba99. There is no need to update ether_print(), ether_common_print() and ether_switch_tag_print() to void functions: back to u_int functions. There is also no need to add a flag parameter to ether_print(), ether_common_print() and ether_switch_tag_print(): Remove it.
* Support for EAP Dump in RADIUS MessagesAravind Prasad S2020-07-221-1/+1
| | | | (pull request #864)
* Update more link-layer dissectors to void functionsFrancois-Xavier Le Bail2020-07-151-30/+54
| | | | | | | | | | | | | | | | | | | | | | brcm_tag_if_print() brcm_tag_prepend_if_print() dsa_if_print() edsa_if_print() ether_if_print() netanalyzer_if_print() netanalyzer_transparent_if_print() Update ether_print(), ether_common_print() and ether_switch_tag_print() to void functions. Add a flag parameter to ether_print(), ether_common_print() and ether_switch_tag_print() to increment the link-layer header length field of the netdissect_options when needed. The calls use TRUE when the return value of the funtions was used. The calls with FALSE avoid increments when the calls are nested. Moreover: Remove trailing "_if" from some protocol names.
* macsec, ether: clean up printing of encrypted and changed packets.Guy Harris2020-05-281-5/+2
| | | | | | | If the packet is encrypted or changed, so that we just print the payload as raw data, and we're not running with -e, print the MAC addresses (if any) and an indication that it's an 802.11AE packet, followed by the MACsec header.
* ether: for MACsec packets, print the MACsec ethertype if E or C set.Guy Harris2020-05-281-0/+4
| | | | | | If -e isn't specified, and a MACsec packet is encrypted or changed, so that we don't print the payload, at least report that it's a MACsec packet.
* ether: clean up MACsec processing.Guy Harris2020-05-281-4/+20
| | | | | | | | | | | | | Print the length early if we're printing the link-layer header. If the payload is encrypted or otherwise modified, print it out as raw data. If the payload is not encrypted or otherwise modified, and we didn't have a problem printing the header, fetch the type/length field following the MACsec header, skip past it, and continue, rather than looping back - there shouldn't be multiple MACsec headers, as far as I know. (If that's not the case, go back to looping.)
* macsec: more cleanups.Guy Harris2020-05-271-1/+6
| | | | | | Get rid of code that knows about Ethernet; this is 802.1AE, not 802.3AE. Get rid o some unused variables.
* Remove unused label.Guy Harris2020-05-271-1/+0
|
* Properly handle the return value of macsec_print().Guy Harris2020-05-271-4/+7
|
* Merge branch 'master' into macsecGuy Harris2020-05-271-147/+297
|\
| * Ethernet: Rename a printerFrancois-Xavier Le Bail2020-04-291-4/+4
| | | | | | | | | | | | | | | | Rename ether_print_common() to ether_common_print(), with _print suffix like in most similar cases. Moreover: Fix indent.
| * Ethernet: Rename a printerFrancois-Xavier Le Bail2020-03-081-1/+1
| | | | | | | | | | Rename ether_print_switch_tag() to ether_switch_tag_print(), with _print suffix like in most similar cases.
| * Dispatch the PTP ethertype to ptp_print()Jeff Chan2020-02-291-0/+5
| | | | | | | | | | | | 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.
| * More bounds checking when fetching addresses and converting to strings.Guy Harris2020-01-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
| * Use more HTTPS in URLsFrancois-Xavier Le Bail2019-08-191-1/+1
| | | | | | | | [skip ci]
| * Arista: Rename a printerFrancois-Xavier Le Bail2019-05-231-1/+1
| | | | | | | | | | | | | | | | 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.
| * Ethernet: Fix indentationFrancois-Xavier Le Bail2019-05-231-27/+27
| |
| * New ethertype protocol for Arista Networksniks30892019-05-231-0/+30
| |
| * Fix typo that increases, instead of decreases, caplenBill Fenner2019-04-301-1/+1
| | | | | | | | The refactoring in b258556b introduced this minor error.
| * Handle switch tags more cleanly.Guy Harris2019-04-231-110/+159
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 the Ethertype the same way for Ethertypes in VLAN tags as for others.Guy Harris2019-04-231-2/+9
| |
| * Treat the length field in an Ethernet header as such.Guy Harris2019-04-221-15/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
| * Remove MEDSA ethertype printerVivien Didelot2019-04-161-5/+0
| | | | | | | | | | | | | | | | | | | | 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.
| * Ethernet: Rename a printerFrancois-Xavier Le Bail2019-04-031-2/+2
| | | | | | | | | | Rename ether_print_hdr_len() to ether_hdr_len_print(), with _print suffix like in most similar cases.
| * Clean up whitespaces/indentationFrancois-Xavier Le Bail2019-04-031-50/+50
| |
| * Use the new GET_ macros instead of the EXTRACT_ onesFrancois-Xavier Le Bail2019-03-261-6/+4
| | | | | | | | | | | | | | 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.
| * Ethernet: Allow specifying non-standard Ethernet header lengthFlorian Fainelli2019-01-251-16/+45
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
| * Revert "Ethernet: Remove two useless tests"Francois-Xavier Le Bail2018-11-191-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | 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.
| * Add more nd_print_trunc() callsFrancois-Xavier Le Bail2018-09-131-2/+4
| |
| * Ethernet: Remove two useless testsFrancois-Xavier Le Bail2018-09-131-2/+2
| | | | | | | | | | | | Because packet length (len) >= capture length (caplen). (see the sanity checks in print.c, pretty_print_packet() function)
| * Ethernet: Remove two useless testsFrancois-Xavier Le Bail2018-09-121-9/+2
| | | | | | | | | | | | | | | | | | | | | | | | 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.
| * Add more nd_print_trunc() callsFrancois-Xavier Le Bail2018-06-061-4/+4
| | | | | | | | Update the output of some tests accordingly.
| * Remove useless commentsFrancois-Xavier Le Bail2018-03-191-9/+0
| |
| * Add the ndo_protocol field in the netdissect_options structureFrancois-Xavier Le Bail2018-03-161-0/+4
| | | | | | | | | | Update this field in printer entry functions. It will be used for some printings.
| * Ethernet: Rename a variableFrancois-Xavier Le Bail2018-03-011-11/+11
| | | | | | | | | | From 'ep', often used as 'pointer to the end of current packet' to 'ehp' as Ethernet header pointer.
| * Remove function specifier 'inline' in printersFrancois-Xavier Le Bail2018-01-261-1/+1
| | | | | | | | | | | | | | | | It was mostly used with large functions. Moreover: Put some function definition names at the beginning of line. Fix a space.
| * Always include <config.h> rather than "config.h".Guy Harris2018-01-211-1/+1
| | | | | | | | | | | | | | | | 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.
| * Use quoted include netdissect-stdinc.h instead of angle-bracketed oneFrancois-Xavier Le Bail2018-01-211-1/+1
| |
| * Update ND_PRINT() as a variadic macroFrancois-Xavier Le Bail2018-01-071-20/+20
| |
| * Directly refer to ether_shost and ether_dhost; get rid of ESRC() and EDST().Guy Harris2017-12-161-4/+4
| | | | | | | | They don't really add anything.
| * Remove all storage class specifier 'register'Francois-Xavier Le Bail2017-12-131-1/+1
| | | | | | | | | | | | Let the compiler do the optimizations (or not) based on build options. Avoid 'value has been optimized out' messages in gdb using '-O0'.