From 4a60f1f9297ddf4f90855e6ed54671568bda2540 Mon Sep 17 00:00:00 2001 From: Denis Ovsienko Date: Sun, 1 Dec 2024 22:16:50 +0000 Subject: [PATCH] Linux: Refine connection status reporting. [skip appveyor] Add CAN and a few tunnel interface varieties to the list of ARP hardware types that do not have a connections status, and instead of skipping these types set PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE. For other types that fail SIOCETHTOOL with specific error codes set PCAP_IF_CONNECTION_STATUS_UNKNOWN. --- CHANGES | 2 ++ pcap-linux.c | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/CHANGES b/CHANGES index 1f09384cdb..9595edfdbb 100644 --- a/CHANGES +++ b/CHANGES @@ -77,6 +77,8 @@ DayOfTheWeek, Month DD, YYYY / The Tcpdump Group Fix a few device activation bugs. Count and timestamp packets better. Add kernel filtering, fix userland filtering. + Linux: + Refine connection status reporting. DAG: Always set PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE. In dag_findalldevs() handle known errors better. diff --git a/pcap-linux.c b/pcap-linux.c index acfdd33a1e..bdae7c5ffd 100644 --- a/pcap-linux.c +++ b/pcap-linux.c @@ -103,6 +103,10 @@ // Linux before 3.5 #define ARPHRD_IEEE802154_MONITOR 805 #endif +#ifndef ARPHRD_IP6GRE + // Linux before 3.7 + #define ARPHRD_IP6GRE 823 +#endif #ifndef ARPHRD_NETLINK // Linux before 3.11 #define ARPHRD_NETLINK 824 @@ -1828,17 +1832,22 @@ get_if_flags(const char *name, bpf_u_int32 *flags, char *errbuf) switch (arptype) { case ARPHRD_LOOPBACK: + case ARPHRD_CAN: + case ARPHRD_TUNNEL: + case ARPHRD_TUNNEL6: + case ARPHRD_SIT: + case ARPHRD_IPGRE: + case ARPHRD_IP6GRE: /* * These are types to which * "connected" and "disconnected" * don't apply, so don't bother * asking about it. - * - * XXX - add other types? */ close(sock); fclose(fh); free(pathstr); + *flags |= PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE; return 0; case ARPHRD_IRDA: @@ -1886,13 +1895,8 @@ get_if_flags(const char *name, bpf_u_int32 *flags, char *errbuf) /* * OK, this OS version or driver doesn't support * asking for this information. - * XXX - distinguish between "this doesn't - * support ethtool at all because it's not - * that type of device" vs. "this doesn't - * support ethtool even though it's that - * type of device", and return "unknown". */ - *flags |= PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE; + *flags |= PCAP_IF_CONNECTION_STATUS_UNKNOWN; close(sock); return 0;