]> The Tcpdump Group git mirrors - tcpdump/commitdiff
NFLOG: Use correct AF code points on all OSes.
authorDenis Ovsienko <[email protected]>
Sat, 11 Feb 2023 19:01:01 +0000 (19:01 +0000)
committerDenis Ovsienko <[email protected]>
Sat, 11 Feb 2023 19:07:11 +0000 (19:07 +0000)
On Haiku R1/beta4 "make check" failed the "nglog-e" test case because
the printer did not recognize address family 2 as IPv4:

-    1  18:31:59.615994 version 0, resource ID 20, family IPv4 (2),
+    1  18:31:59.615994 version 0, resource ID 20, family Unknown (2),

Fix print-nflog.c to use the wire encoding AF code points rather than
the OS libc AF constants.  This fixes "make check" on Haiku and likely
fixes IPv6 NFLOG decoding on a few non-Linux OSes.

CHANGES
print-nflog.c

diff --git a/CHANGES b/CHANGES
index d9cf414a29a7eeb2635f21e6447f9579548f7db0..0383cbdced533d3845208766f28c008458bd242d 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -24,6 +24,7 @@ DayOfTheWeek, Month DD, YYYY / The Tcpdump Group
       BGP: Add Origin Validation State extended community
       BGP: Add support for BGP Role capability and OTC attribute
       Arista: Use the test .pcap file from pull request #955 (HwInfo).
+      NFLOG: Use correct AF code points on all OSes.
     User interface:
       Add optional unit suffix on -C file size.
       Add --print-sampling to print every Nth packet instead of all.
index 1e75561b967dc01b60e62e3af432f246ae5696b4..bbe4ccfcc761b847d7e6043dc14e95dfc455cd94 100644 (file)
@@ -103,9 +103,19 @@ typedef struct nflog_timestamp {
 #define NFULA_HWHEADER                 16      /* skbuff's MAC-layer header */
 #define NFULA_HWLEN                    17      /* length of skbuff's MAC-layer header */
 
+/*
+ * Define two constants specifically for the two AF code points from the
+ * LINKTYPE_NFLOG specification above and use these constants instead of
+ * AF_INET and AF_INET6.  This is the only way to dissect the "wire" encoding
+ * correctly because some BSD systems define AF_INET6 differently from Linux
+ * (see af.h) and Haiku defines both AF_INET and AF_INET6 differently from
+ * Linux.
+ */
+#define NFLOG_AF_INET   2
+#define NFLOG_AF_INET6 10
 static const struct tok nflog_values[] = {
-       { AF_INET,              "IPv4" },
-       { AF_INET6,             "IPv6" },
+       { NFLOG_AF_INET,        "IPv4" },
+       { NFLOG_AF_INET6,       "IPv6" },
        { 0,                    NULL }
 };
 
@@ -203,11 +213,11 @@ nflog_if_print(netdissect_options *ndo,
 
        switch (GET_U_1(hdr->nflog_family)) {
 
-       case AF_INET:
+       case NFLOG_AF_INET:
                ip_print(ndo, p, length);
                break;
 
-       case AF_INET6:
+       case NFLOG_AF_INET6:
                ip6_print(ndo, p, length);
                break;