ctdb-common: Add packet type detection to pcap-based capture
commit3bf20300ac5962e71069be3998ef7f0502045d24
authorMartin Schwenke <martin@meltin.net>
Sun, 14 Aug 2022 23:43:58 +0000 (15 09:43 +1000)
committerAmitay Isaacs <amitay@samba.org>
Tue, 20 Sep 2022 10:43:37 +0000 (20 10:43 +0000)
tree50d025cdb7889c9646c40a1fd78f84d855067fcc
parent5dd964aa0297b6e9ab8e1d0ff9fa0565c97ea43e
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>
ctdb/common/system_socket.c