]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Declare the NFLOG pseudo-header ourselves.
authorGuy Harris <[email protected]>
Wed, 23 May 2018 21:43:47 +0000 (14:43 -0700)
committerGuy Harris <[email protected]>
Wed, 23 May 2018 21:43:47 +0000 (14:43 -0700)
It's not specified by a libpcap header that might have a different
layout in different pcap releases, it's specified on the list of
link-layer header types and must remain the same forever (except for
getting additional bits defined), so we don't need to pick it up from
libpcap.

This means we get to use tcpdump's nd_ types; do so.

CMakeLists.txt
config.h.in
configure
configure.ac
print-nflog.c

index ab359f44d9d48dddb2560b0d12d2574a0d7c7040..7fb381e5056d3adf1b51328d565104acc7db7d23 100644 (file)
@@ -538,17 +538,6 @@ set(CMAKE_REQUIRED_INCLUDES ${PCAP_INCLUDE_DIRS})
 #
 check_include_file(pcap/pcap-inttypes.h HAVE_PCAP_PCAP_INTTYPES_H)
 
-#
-# Check for some headers introduced in later versions of libpcap
-# and used by some printers.
-#
-# Those headers might use the {u_}intN_t types, so we must include
-# netdissect-stdinc.h first.
-#
-set(CMAKE_EXTRA_INCLUDE_FILES netdissect-stdinc.h)
-check_include_file(pcap/nflog.h HAVE_PCAP_NFLOG_H)
-cmake_pop_check_state()
-
 #
 # Check for various functions in libpcap/WinPcap.
 #
index fafdae2b43732e3f94bc4769d3585c81ce201a19..4fcbba77efe1ada2b6250dc76f8304b3bb63e348 100644 (file)
 /* define if libpcap has pcap_list_datalinks() */
 #undef HAVE_PCAP_LIST_DATALINKS
 
-/* Define to 1 if you have the <pcap/nflog.h> header file. */
-#undef HAVE_PCAP_NFLOG_H
-
 /* Define to 1 if you have the `pcap_open' function. */
 #undef HAVE_PCAP_OPEN
 
index 63372c10399e9825bb74ecc778354c9fd76a734d..7c79206b89a89d4f2758b772ef5410f84cbfb12c 100755 (executable)
--- a/configure
+++ b/configure
@@ -6514,30 +6514,6 @@ $as_echo "#define u_int64_t uint64_t" >>confdefs.h
 fi
 
 
-#
-# Check for some headers introduced in later versions of libpcap
-# and used by some printers.
-#
-# Those headers might use the {u_}intN_t types, so we must do this
-# after we check for what's needed to get them defined.
-#
-savedcppflags="$CPPFLAGS"
-CPPFLAGS="$CPPFLAGS $V_INCLS"
-for ac_header in pcap/nflog.h
-do :
-  ac_fn_c_check_header_compile "$LINENO" "pcap/nflog.h" "ac_cv_header_pcap_nflog_h" "#include \"netdissect-stdinc.h\"
-"
-if test "x$ac_cv_header_pcap_nflog_h" = xyes; then :
-  cat >>confdefs.h <<_ACEOF
-#define HAVE_PCAP_NFLOG_H 1
-_ACEOF
-
-fi
-
-done
-
-CPPFLAGS="$savedcppflags"
-
 if test -n "$ac_tool_prefix"; then
   # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args.
 set dummy ${ac_tool_prefix}ranlib; ac_word=$2
index d6546ff39dfcdf6d9ce026a6c9e6b371f6b239a1..32f48b606b3e7cc4cfec1e42077102ff233c7893 100644 (file)
@@ -888,18 +888,6 @@ AC_CHECK_TYPE([u_int64_t], ,
 #include <sys/types.h>
 ])
 
-#
-# Check for some headers introduced in later versions of libpcap
-# and used by some printers.
-#
-# Those headers might use the {u_}intN_t types, so we must do this
-# after we check for what's needed to get them defined.
-#
-savedcppflags="$CPPFLAGS"
-CPPFLAGS="$CPPFLAGS $V_INCLS"
-AC_CHECK_HEADERS(pcap/nflog.h,,,[#include "netdissect-stdinc.h"])
-CPPFLAGS="$savedcppflags"
-
 AC_PROG_RANLIB
 AC_CHECK_TOOL([AR], [ar])
 
index b295adefb04cdc0efbd0bb5c9c55642c632aca9a..63cdbc9a07219b4807ef8ef586f2a119fd02fd69 100644 (file)
 #include "netdissect-stdinc.h"
 
 #include "netdissect.h"
+#include "extract.h"
 
-#if defined(DLT_NFLOG) && defined(HAVE_PCAP_NFLOG_H)
+#ifdef DLT_NFLOG
 
-#include <pcap/nflog.h>
+/*
+ * Structure of an NFLOG header and TLV parts, as described at
+ * http://www.tcpdump.org/linktypes/LINKTYPE_NFLOG.html
+ *
+ * The NFLOG header is big-endian.
+ *
+ * The TLV length and type are in host byte order.  The value is either
+ * big-endian or is an array of bytes in some externally-specified byte
+ * order (text string, link-layer address, link-layer header, packet
+ * data, etc.).
+ */
+typedef struct nflog_hdr {
+       nd_uint8_t      nflog_family;           /* address family */
+       nd_uint8_t      nflog_version;          /* version */
+       nd_uint16_t     nflog_rid;              /* resource ID */
+} nflog_hdr_t;
+
+typedef struct nflog_tlv {
+       nd_uint16_t     tlv_length;             /* tlv length */
+       nd_uint16_t     tlv_type;               /* tlv type */
+       /* value follows this */
+} nflog_tlv_t;
+
+typedef struct nflog_packet_hdr {
+       nd_uint16_t     hw_protocol;    /* hw protocol */
+       nd_uint8_t      hook;           /* netfilter hook */
+       nd_byte         pad[1];         /* padding to 32 bits */
+} nflog_packet_hdr_t;
+
+typedef struct nflog_hwaddr {
+       nd_uint16_t     hw_addrlen;     /* address length */
+       nd_byte         pad[2];         /* padding to 32-bit boundary */
+       nd_byte         hw_addr[8];     /* address, up to 8 bytes */
+} nflog_hwaddr_t;
+
+typedef struct nflog_timestamp {
+       nd_uint64_t     sec;
+       nd_uint64_t     usec;
+} nflog_timestamp_t;
 
+/*
+ * TLV types.
+ */
+#define NFULA_PACKET_HDR               1       /* nflog_packet_hdr_t */
+#define NFULA_MARK                     2       /* packet mark from skbuff */
+#define NFULA_TIMESTAMP                        3       /* nflog_timestamp_t for skbuff's time stamp */
+#define NFULA_IFINDEX_INDEV            4       /* ifindex of device on which packet received (possibly bridge group) */
+#define NFULA_IFINDEX_OUTDEV           5       /* ifindex of device on which packet transmitted (possibly bridge group) */
+#define NFULA_IFINDEX_PHYSINDEV                6       /* ifindex of physical device on which packet received (not bridge group) */
+#define NFULA_IFINDEX_PHYSOUTDEV       7       /* ifindex of physical device on which packet transmitted (not bridge group) */
+#define NFULA_HWADDR                   8       /* nflog_hwaddr_t for hardware address */
+#define NFULA_PAYLOAD                  9       /* packet payload */
+#define NFULA_PREFIX                   10      /* text string - null-terminated, count includes NUL */
+#define NFULA_UID                      11      /* UID owning socket on which packet was sent/received */
+#define NFULA_SEQ                      12      /* sequence number of packets on this NFLOG socket */
+#define NFULA_SEQ_GLOBAL               13      /* sequence number of pakets on all NFLOG sockets */
+#define NFULA_GID                      14      /* GID owning socket on which packet was sent/received */
+#define NFULA_HWTYPE                   15      /* ARPHRD_ type of skbuff's device */
+#define NFULA_HWHEADER                 16      /* skbuff's MAC-layer header */
+#define NFULA_HWLEN                    17      /* length of skbuff's MAC-layer header */
 
 static const struct tok nflog_values[] = {
        { AF_INET,              "IPv4" },
@@ -51,18 +110,19 @@ static const struct tok nflog_values[] = {
 static void
 nflog_hdr_print(netdissect_options *ndo, const nflog_hdr_t *hdr, u_int length)
 {
-       ND_PRINT("version %d, resource ID %d", hdr->nflog_version, ntohs(hdr->nflog_rid));
+       ND_PRINT("version %u, resource ID %u",
+           EXTRACT_U_1(hdr->nflog_version), EXTRACT_BE_U_2(hdr->nflog_rid));
 
        if (!ndo->ndo_qflag) {
-               ND_PRINT(", family %s (%d)",
+               ND_PRINT(", family %s (%u)",
                         tok2str(nflog_values, "Unknown",
-                                hdr->nflog_family),
-                        hdr->nflog_family);
+                                EXTRACT_U_1(hdr->nflog_family)),
+                        EXTRACT_U_1(hdr->nflog_family));
                } else {
                ND_PRINT(", %s",
                         tok2str(nflog_values,
                                 "Unknown NFLOG (0x%02x)",
-                        hdr->nflog_family));
+                        EXTRACT_U_1(hdr->nflog_family)));
                }
 
        ND_PRINT(", length %u: ", length);
@@ -83,8 +143,8 @@ nflog_if_print(netdissect_options *ndo,
                goto trunc;
 
        ND_TCHECK_SIZE(hdr);
-       if (hdr->nflog_version != 0) {
-               ND_PRINT("version %u (unknown)", hdr->nflog_version);
+       if (EXTRACT_U_1(hdr->nflog_version) != 0) {
+               ND_PRINT("version %u (unknown)", EXTRACT_U_1(hdr->nflog_version));
                return h_size;
        }
 
@@ -104,7 +164,7 @@ nflog_if_print(netdissect_options *ndo,
 
                tlv = (const nflog_tlv_t *) p;
                ND_TCHECK_SIZE(tlv);
-               size = tlv->tlv_length;
+               size = EXTRACT_HE_U_2(tlv->tlv_length);
                if (size % 4 != 0)
                        size += 4 - size % 4;
 
@@ -116,7 +176,7 @@ nflog_if_print(netdissect_options *ndo,
                if (caplen < size || length < size)
                        goto trunc;     /* No. */
 
-               if (tlv->tlv_type == NFULA_PAYLOAD) {
+               if (EXTRACT_HE_U_2(tlv->tlv_type) == NFULA_PAYLOAD) {
                        /*
                         * This TLV's data is the packet payload.
                         * Skip past the TLV header, and break out
@@ -135,7 +195,7 @@ nflog_if_print(netdissect_options *ndo,
                caplen -= size;
        }
 
-       switch (hdr->nflog_family) {
+       switch (EXTRACT_U_1(hdr->nflog_family)) {
 
        case AF_INET:
                ip_print(ndo, p, length);