ctdb-common: Add packet type detection to pcap-based capture
commit0f3864d7c596d766cd223529f817d9232ce49908
authorMartin Schwenke <martin@meltin.net>
Sun, 14 Aug 2022 23:43:58 +0000 (15 09:43 +1000)
committerJule Anger <janger@samba.org>
Tue, 29 Aug 2023 09:35:11 +0000 (29 09:35 +0000)
tree34d41f96993b91026655023d8626ad4733920363
parentf01d53d8848ccd6e6a743ea42d5dd7846840d7a2
ctdb-common: Add packet type detection to pcap-based capture

The current code will almost certainly generate ENOMSG for
non-ethernet packets, even for ethernet packets when the "any"
interface is used.

pcap_datalink(3PCAP) says:

  Do NOT assume that the packets for a given capture or ``savefile``
  will have any given link-layer header type, such as DLT_EN10MB for
  Ethernet.  For example, the "any" device on Linux will have a
  link-layer header type of DLT_LINUX_SLL or DLT_LINUX_SLL2 even if
  all devices on the sys‐ tem at the time the "any" device is opened
  have some other data link type, such as DLT_EN10MB for Ethernet.

So, pcap_datalink() must be used.

Detect pcap packet types that are supported (currently only ethernet)
in the open code. There is no use continuing if the read code can't
parse packets.  The pattern of using switch statements supports future
addition of other packet types.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
(cherry picked from commit 3bf20300ac5962e71069be3998ef7f0502045d24)
ctdb/common/system_socket.c