From: Petr Vorel <petr.vo...@gmail.com> Implements: GH the-tcpdump-group/libpcap#127
Signed-off-by: Petr Vorel <petr.vo...@gmail.com> Signed-off-by: Petr Vorel <pvo...@suse.cz> --- INSTALL.md | 2 +- cmakeconfig.h.in | 3 +++ config.h.in | 4 ++++ configure | 20 ++++++++++++++++++++ configure.ac | 10 ++++++++++ gencode.c | 3 +++ pcap-common.c | 1 + pcap-linux.c | 12 ++++++++++++ pcap.c | 4 ++++ pcap/sll.h | 21 +++++++++++++++++++-- 10 files changed, 77 insertions(+), 3 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 96c87a2c..47daa52d 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -308,7 +308,7 @@ pcap/bluetooth.h - public definition of DLT_BLUETOOTH_HCI_H4_WITH_PHDR header pcap/bpf.h - BPF definitions pcap/namedb.h - public libpcap name database definitions pcap/pcap.h - public libpcap definitions -pcap/sll.h - public definition of DLT_LINUX_SLL header +pcap/sll.h - public definition of DLT_LINUX_SLL and DLT_LINUX_SLL2 headers pcap/usb.h - public definition of DLT_USB header pcap-bpf.c - BSD Packet Filter support pcap-bpf.h - header for backwards compatibility diff --git a/cmakeconfig.h.in b/cmakeconfig.h.in index 6760cec7..216ea92d 100644 --- a/cmakeconfig.h.in +++ b/cmakeconfig.h.in @@ -360,6 +360,9 @@ /* define on AIX to get certain functions */ #cmakedefine _SUN 1 +/* enable new LINKTYPE_LINUX_SLL2 capture support on Linux instead of legacy LINKTYPE_LINUX_SLL */ +#cmakedefine PCAP_SUPPORT_SLL_V2 1 + #if 0 /* on sinix */ #cmakedefine sinix 1 diff --git a/config.h.in b/config.h.in index b1a20a44..19dd284f 100644 --- a/config.h.in +++ b/config.h.in @@ -325,6 +325,10 @@ /* target host supports RDMA sniffing */ #undef PCAP_SUPPORT_RDMASNIFF +/* enable new LINKTYPE_LINUX_SLL2 capture support on Linux instead of legacy + LINKTYPE_LINUX_SLL */ +#undef PCAP_SUPPORT_SLL_V2 + /* target host supports USB sniffing */ #undef PCAP_SUPPORT_USB diff --git a/configure b/configure index 95e7f480..1fa60cde 100755 --- a/configure +++ b/configure @@ -623,6 +623,7 @@ ac_subst_vars='LTLIBOBJS INSTALL_DATA INSTALL_SCRIPT INSTALL_PROGRAM +PCAP_SUPPORT_SLL_V2 RDMA_SRC PCAP_SUPPORT_RDMASNIFF DBUS_SRC @@ -764,6 +765,7 @@ enable_netmap enable_bluetooth enable_dbus enable_rdma +enable_sll_v2 ' ac_precious_vars='build_alias host_alias @@ -1411,6 +1413,9 @@ Optional Features: support available] --enable-rdma enable RDMA capture support [default=yes, if support available] + --enable-sll-v2 enable new LINKTYPE_LINUX_SLL2 capture support on + Linux instead of legacy LINKTYPE_LINUX_SLL + [default=yes] Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] @@ -10647,6 +10652,21 @@ fi +fi + +# Check whether --enable-sll-v2 was given. +if test "${enable_sll_v2+set}" = set; then : + enableval=$enable_sll_v2; +else + enable_sll_v2=yes +fi + + +if test "x$enable_sll_v2" != "xno" ; then + +$as_echo "#define PCAP_SUPPORT_SLL_V2 1" >>confdefs.h + + fi # Find a good install program. We prefer a C program (faster), diff --git a/configure.ac b/configure.ac index eff6eb89..4f311a7b 100644 --- a/configure.ac +++ b/configure.ac @@ -2260,6 +2260,16 @@ if test "x$enable_rdmasniff" != "xno"; then AC_SUBST(RDMA_SRC) fi +AC_ARG_ENABLE([sll-v2], +[AC_HELP_STRING([--enable-sll-v2],[enable new LINKTYPE_LINUX_SLL2 capture support on Linux instead of legacy LINKTYPE_LINUX_SLL @<:@default=yes@:>@])], + [], + [enable_sll_v2=yes]) + +if test "x$enable_sll_v2" != "xno" ; then + AC_DEFINE(PCAP_SUPPORT_SLL_V2, 1, [enable new LINKTYPE_LINUX_SLL2 capture support on Linux instead of legacy LINKTYPE_LINUX_SLL]) + AC_SUBST(PCAP_SUPPORT_SLL_V2) +fi + AC_PROG_INSTALL AC_CONFIG_HEADER(config.h) diff --git a/gencode.c b/gencode.c index 959a56e6..cc4a64cf 100644 --- a/gencode.c +++ b/gencode.c @@ -1331,6 +1331,7 @@ init_linktype(compiler_state_t *cstate, pcap_t *p) break; case DLT_LINUX_SLL: /* fake header for Linux cooked socket */ + case DLT_LINUX_SLL2: cstate->off_linktype.constant_part = 14; cstate->off_linkpl.constant_part = 16; cstate->off_nl = 0; @@ -3136,6 +3137,7 @@ gen_linktype(compiler_state_t *cstate, int proto) break; case DLT_LINUX_SLL: + case DLT_LINUX_SLL2: return gen_linux_sll_linktype(cstate, proto); /*NOTREACHED*/ break; @@ -7725,6 +7727,7 @@ gen_inbound(compiler_state_t *cstate, int dir) break; case DLT_LINUX_SLL: + case DLT_LINUX_SLL2: /* match outgoing packets */ b0 = gen_cmp(cstate, OR_LINKHDR, 0, BPF_H, LINUX_SLL_OUTGOING); if (!dir) { diff --git a/pcap-common.c b/pcap-common.c index ca809996..c2149eb4 100644 --- a/pcap-common.c +++ b/pcap-common.c @@ -1525,6 +1525,7 @@ swap_pseudo_headers(int linktype, struct pcap_pkthdr *hdr, u_char *data) switch (linktype) { case DLT_LINUX_SLL: + case DLT_LINUX_SLL2: swap_linux_sll_header(hdr, data); break; diff --git a/pcap-linux.c b/pcap-linux.c index 49144b64..4123c72b 100644 --- a/pcap-linux.c +++ b/pcap-linux.c @@ -1910,6 +1910,9 @@ pcap_read_packet(pcap_t *handle, pcap_handler callback, u_char *userdata) hdrp = (struct sll_header *)bp; hdrp->sll_pkttype = map_packet_type_to_sll_type(from.sll_pkttype); +#ifdef PCAP_SUPPORT_SLL_V2 + hdrp->sll_ifindex = htons(from.sll_ifindex); +#endif hdrp->sll_hatype = htons(from.sll_hatype); hdrp->sll_halen = htons(from.sll_halen); memcpy(hdrp->sll_addr, from.sll_addr, @@ -3689,6 +3692,7 @@ activate_new(pcap_t *handle) map_arphrd_to_dlt(handle, sock_fd, arptype, device, 1); if (handle->linktype == -1 || handle->linktype == DLT_LINUX_SLL || + handle->linktype == DLT_LINUX_SLL2 || handle->linktype == DLT_LINUX_IRDA || handle->linktype == DLT_LINUX_LAPD || handle->linktype == DLT_NETLINK || @@ -3796,7 +3800,11 @@ activate_new(pcap_t *handle) * It uses cooked mode. */ handlep->cooked = 1; +#ifdef PCAP_SUPPORT_SLL_V2 + handle->linktype = DLT_LINUX_SLL2; +#else handle->linktype = DLT_LINUX_SLL; +#endif /* * We're not bound to a device. @@ -3892,6 +3900,7 @@ activate_new(pcap_t *handle) break; case DLT_LINUX_SLL: + case DLT_LINUX_SLL2: /* * The type field is in the last 2 bytes of the * DLT_LINUX_SLL header. @@ -4964,6 +4973,9 @@ static int pcap_handle_packet_mmap( hdrp = (struct sll_header *)bp; hdrp->sll_pkttype = map_packet_type_to_sll_type( sll->sll_pkttype); +#ifdef PCAP_SUPPORT_SLL_V2 + hdrp->sll_ifindex = sll->sll_ifindex; +#endif hdrp->sll_hatype = htons(sll->sll_hatype); hdrp->sll_halen = htons(sll->sll_halen); memcpy(hdrp->sll_addr, sll->sll_addr, SLL_ADDRLEN); diff --git a/pcap.c b/pcap.c index 3337bcb3..ecdd5aab 100644 --- a/pcap.c +++ b/pcap.c @@ -2841,7 +2841,11 @@ static struct dlt_choice dlt_choices[] = { DLT_CHOICE(FRELAY, "Frame Relay"), DLT_CHOICE(LOOP, "OpenBSD loopback"), DLT_CHOICE(ENC, "OpenBSD encapsulated IP"), +#ifdef PCAP_SUPPORT_SLL_V2 + DLT_CHOICE(LINUX_SLL2, "Linux cooked v2"), +#else DLT_CHOICE(LINUX_SLL, "Linux cooked"), +#endif DLT_CHOICE(LTALK, "Localtalk"), DLT_CHOICE(PFLOG, "OpenBSD pflog file"), DLT_CHOICE(PFSYNC, "Packet filter state syncing"), diff --git a/pcap/sll.h b/pcap/sll.h index c4d08862..82f009b2 100644 --- a/pcap/sll.h +++ b/pcap/sll.h @@ -75,19 +75,36 @@ #define lib_pcap_sll_h /* - * A DLT_LINUX_SLL fake link-layer header. + * DLT_LINUX_SLL and DLT_LINUX_SLL2 fake link-layer header. + * Uses PCAP_SUPPORT_SLL_V2 from config.h. */ -#define SLL_HDR_LEN 16 /* total header length */ +/* total header length */ +#ifdef PCAP_SUPPORT_SLL_V2 +#define SLL_HDR_LEN 24 +#else +#define SLL_HDR_LEN 16 +#endif + #define SLL_ADDRLEN 8 /* length of address field */ #include <pcap/pcap-inttypes.h> struct sll_header { +#ifdef PCAP_SUPPORT_SLL_V2 + uint16_t sll_protocol; /* protocol */ + uint16_t reserved; /* reserved */ + int32_t sll_ifindex; /* interface index, DLT_LINUX_SLL2 ONLY! */ + uint16_t sll_hatype; /* link-layer address type */ + uint16_t sll_pkttype; /* packet type */ + uint16_t sll_halen; /* link-layer address length */ + uint8_t sll_addr[SLL_ADDRLEN]; /* link-layer address */ +#else uint16_t sll_pkttype; /* packet type */ uint16_t sll_hatype; /* link-layer address type */ uint16_t sll_halen; /* link-layer address length */ uint8_t sll_addr[SLL_ADDRLEN]; /* link-layer address */ uint16_t sll_protocol; /* protocol */ +#endif }; /* -- 2.18.0 _______________________________________________ tcpdump-workers mailing list tcpdump-workers@lists.tcpdump.org https://lists.sandelman.ca/mailman/listinfo/tcpdump-workers