git: 34aa6f2c2db5 - main - pflogd: Move struct definitions out of header file

From: Joseph Mingrone <jrm_at_FreeBSD.org>
Date: Fri, 04 Oct 2024 13:43:20 UTC
The branch main has been updated by jrm:

URL: https://cgit.FreeBSD.org/src/commit/?id=34aa6f2c2db5cc9655f201a1ef01adbb9fb484d5

commit 34aa6f2c2db5cc9655f201a1ef01adbb9fb484d5
Author:     Joseph Mingrone <jrm@FreeBSD.org>
AuthorDate: 2024-10-03 19:49:51 +0000
Commit:     Joseph Mingrone <jrm@FreeBSD.org>
CommitDate: 2024-10-04 13:41:53 +0000

    pflogd: Move struct definitions out of header file
    
    In libpcap 1.10.5, two structures that we relied on, pcap_timeval and
    pcap_sf_pkthdr, were made private.  As a workaround, we initially
    defined the structures in pflogd.h.  After further investigation, mostly
    by kp@, we concluded that it is reasonable to define these structures
    ourselves since they represent a file format and thus are unlikely to
    change from under us.  We will stick with this solution but move the
    definitions out of the header file to prevent others from using pflogd.h
    to access them.
    
    Another solution that was considered was using libpcap's pcap_dump()
    function to write packets, but there are blockers.  For example, pflogd
    writes to a memory buffer, and libpcap lacks support for this.
    
    Reviewed by:    kp
    MFC after:      3 days
    Event:          EuroBSDCon 2024
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D46894
---
 contrib/pf/pflogd/pflogd.c | 11 +++++++++++
 contrib/pf/pflogd/pflogd.h | 13 -------------
 2 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/contrib/pf/pflogd/pflogd.c b/contrib/pf/pflogd/pflogd.c
index 6df97f8b84f4..e24553dfc37b 100644
--- a/contrib/pf/pflogd/pflogd.c
+++ b/contrib/pf/pflogd/pflogd.c
@@ -74,6 +74,17 @@ char errbuf[PCAP_ERRBUF_SIZE];
 int log_debug = 0;
 unsigned int delay = FLUSH_DELAY;
 
+struct pcap_timeval {
+	bpf_u_int32 tv_sec;	/* seconds */
+	bpf_u_int32 tv_usec;	/* microseconds */
+};
+
+struct pcap_sf_pkthdr {
+	struct pcap_timeval ts;	/* time stamp */
+	bpf_u_int32 caplen;	/* length of portion present */
+	bpf_u_int32 len;	/* length of this packet (off wire) */
+};
+
 char *copy_argv(char * const *);
 void  dump_packet(u_char *, const struct pcap_pkthdr *, const u_char *);
 void  dump_packet_nobuf(u_char *, const struct pcap_pkthdr *, const u_char *);
diff --git a/contrib/pf/pflogd/pflogd.h b/contrib/pf/pflogd/pflogd.h
index 6e6b588d24bf..596e69692614 100644
--- a/contrib/pf/pflogd/pflogd.h
+++ b/contrib/pf/pflogd/pflogd.h
@@ -40,19 +40,6 @@ int	priv_open_log(void);
 int	priv_move_log(void);
 pcap_t *pcap_open_live_fd(int fd, int snaplen, char *ebuf);
 
-/* XXX TODO: Investigate a permanent solution, rather than defining these two
-   structures here. */
-struct pcap_timeval {
-	bpf_u_int32 tv_sec;	/* seconds */
-	bpf_u_int32 tv_usec;	/* microseconds */
-};
-
-struct pcap_sf_pkthdr {
-	struct pcap_timeval ts;	/* time stamp */
-	bpf_u_int32 caplen;	/* length of portion present */
-	bpf_u_int32 len;	/* length of this packet (off wire) */
-};
-
 void set_pcap_filter(void);
 /* File descriptor send/recv */
 void send_fd(int, int);