From bd098dd9e6b69bd88545c4563be7a585ea1b84bc Mon Sep 17 00:00:00 2001 From: naddy Date: Fri, 20 Sep 2024 23:11:12 +0000 Subject: [PATCH] net/tcpflow: fix listening on a loopback interface From maintainer Kirill A. Korinsky --- net/tcpflow/Makefile | 2 +- net/tcpflow/patches/patch-src_datalink_cpp | 39 +++++++++++++++++++--- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/net/tcpflow/Makefile b/net/tcpflow/Makefile index 5b1dda9e0a5..edb217ace94 100644 --- a/net/tcpflow/Makefile +++ b/net/tcpflow/Makefile @@ -3,7 +3,7 @@ COMMENT= tool for capturing data from TCP connections V= 1.6.1 DISTNAME= tcpflow-${V} CATEGORIES= net -REVISION= 1 +REVISION= 2 SITES= https://github.com/simsong/tcpflow/releases/download/tcpflow-${V}/ diff --git a/net/tcpflow/patches/patch-src_datalink_cpp b/net/tcpflow/patches/patch-src_datalink_cpp index ba83ecee414..f030401e49e 100644 --- a/net/tcpflow/patches/patch-src_datalink_cpp +++ b/net/tcpflow/patches/patch-src_datalink_cpp @@ -1,9 +1,32 @@ Index: src/datalink.cpp --- src/datalink.cpp.orig +++ src/datalink.cpp -@@ -71,6 +71,29 @@ void dl_null(u_char *user, const struct pcap_pkthdr *h +@@ -70,7 +70,52 @@ void dl_null(u_char *user, const struct pcap_pkthdr *h + } #pragma GCC diagnostic warning "-Wcast-align" ++#define LOOP_HDRLEN 4 ++ ++void dl_loop(u_char *user, const struct pcap_pkthdr *h, const u_char *p) ++{ ++ u_int caplen = h->caplen; ++ u_int length = h->len; ++ ++ if (length != caplen) { ++ DEBUG(6) ("warning: only captured %d bytes of %d byte null frame", ++ caplen, length); ++ } ++ ++ if (caplen < LOOP_HDRLEN) { ++ DEBUG(6) ("warning: received incomplete null frame"); ++ return; ++ } ++ ++ struct timeval tv; ++ be13::packet_info pi(DLT_LOOP,h,p,tvshift(tv,h->ts),p+LOOP_HDRLEN,caplen - LOOP_HDRLEN); ++ be13::plugin::process_packet(pi); ++} ++ static uint64_t counter=0; + +#define PPP_ETHER_HDRLEN 8 @@ -31,11 +54,19 @@ Index: src/datalink.cpp /* DLT_RAW: just a raw IP packet, no encapsulation or link-layer * headers. Used for PPP connections under some OSs including Linux * and IRIX. */ -@@ -278,14 +301,18 @@ dlt_handler_t handlers[] = { - { dl_raw, 101 }, +@@ -269,7 +314,8 @@ void dl_linux_sll(u_char *user, const struct pcap_pkth + + /* List of callbacks for each data link type */ + dlt_handler_t handlers[] = { +- { dl_null, DLT_NULL }, ++ { dl_null, DLT_NULL }, ++ { dl_loop, DLT_LOOP }, + /* Some systems define DLT_RAW as 12, some as 14, and some as 101. + * So it is hard-coded here. + */ +@@ -279,13 +325,16 @@ dlt_handler_t handlers[] = { { dl_ethernet, DLT_EN10MB }, { dl_ethernet, DLT_IEEE802 }, -+ { dl_null, DLT_LOOP }, { dl_ppp, DLT_PPP }, + { dl_ppp_ether, DLT_PPP_ETHER }, #ifdef DLT_LINUX_SLL