diff options
author | Max Laier <mlaier@FreeBSD.org> | 2004-08-31 18:04:34 +0000 |
---|---|---|
committer | Max Laier <mlaier@FreeBSD.org> | 2004-08-31 18:04:34 +0000 |
commit | 6964e37de4dc650b45630a2d25341dc8e137d4ef (patch) | |
tree | 09854ab609be109e5f5705762061bce633ab4fd1 /contrib/pf/pflogd | |
parent | 4d1183c13e1e982ea963c32d9179f03ef5287fdc (diff) | |
download | src-6964e37de4dc650b45630a2d25341dc8e137d4ef.tar.gz src-6964e37de4dc650b45630a2d25341dc8e137d4ef.zip |
Make pflogd(8) store pcap_sf_pkthdr instead of MD timeval contaminated
pcap_pkthdr. This makes /var/log/pflog standart compliant on 64bit archs.
OpenBSD has fixed this by changing the bpf timeval to 32bit in the kernel,
so no need to report this over (again).
PR: bin/71096 (w/ changes)
Submitted by: Ville-Pertti Keinonen
Tested by: amd64(submitter), sparc64(yongari), i386(myself)
MFC after: 3 days
Notes
Notes:
svn path=/head/; revision=134578
Diffstat (limited to 'contrib/pf/pflogd')
-rw-r--r-- | contrib/pf/pflogd/pflogd.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/contrib/pf/pflogd/pflogd.c b/contrib/pf/pflogd/pflogd.c index 54a2572d8924..cb2719764f32 100644 --- a/contrib/pf/pflogd/pflogd.c +++ b/contrib/pf/pflogd/pflogd.c @@ -325,7 +325,11 @@ int scan_dump(FILE *fp, off_t size) { struct pcap_file_header hdr; +#ifdef __FreeBSD__ + struct pcap_sf_pkthdr ph; +#else struct pcap_pkthdr ph; +#endif off_t pos; /* @@ -395,17 +399,34 @@ void dump_packet_nobuf(u_char *user, const struct pcap_pkthdr *h, const u_char *sp) { FILE *f = (FILE *)user; +#ifdef __FreeBSD__ + struct pcap_sf_pkthdr sh; +#endif if (suspended) { packets_dropped++; return; } +#ifdef __FreeBSD__ + sh.ts.tv_sec = (bpf_int32)h->ts.tv_sec; + sh.ts.tv_usec = (bpf_int32)h->ts.tv_usec; + sh.caplen = h->caplen; + sh.len = h->len; + + if (fwrite((char *)&sh, sizeof(sh), 1, f) != 1) { +#else if (fwrite((char *)h, sizeof(*h), 1, f) != 1) { +#endif /* try to undo header to prevent corruption */ off_t pos = ftello(f); +#ifdef __FreeBSD__ + if (pos < sizeof(sh) || + ftruncate(fileno(f), pos - sizeof(sh))) { +#else if (pos < sizeof(*h) || ftruncate(fileno(f), pos - sizeof(*h))) { +#endif logmsg(LOG_ERR, "Write failed, corrupted logfile!"); set_suspended(1); gotsig_close = 1; @@ -474,7 +495,12 @@ void dump_packet(u_char *user, const struct pcap_pkthdr *h, const u_char *sp) { FILE *f = (FILE *)user; +#ifdef __FreeBSD__ + struct pcap_sf_pkthdr sh; + size_t len = sizeof(sh) + h->caplen; +#else size_t len = sizeof(*h) + h->caplen; +#endif if (len < sizeof(*h) || h->caplen > (size_t)cur_snaplen) { logmsg(LOG_NOTICE, "invalid size %u (%u/%u), packet dropped", @@ -502,8 +528,18 @@ dump_packet(u_char *user, const struct pcap_pkthdr *h, const u_char *sp) } append: +#ifdef __FreeBSD__ + sh.ts.tv_sec = (bpf_int32)h->ts.tv_sec; + sh.ts.tv_usec = (bpf_int32)h->ts.tv_usec; + sh.caplen = h->caplen; + sh.len = h->len; + + memcpy(bufpos, &sh, sizeof(sh)); + memcpy(bufpos + sizeof(sh), sp, h->caplen); +#else memcpy(bufpos, h, sizeof(*h)); memcpy(bufpos + sizeof(*h), sp, h->caplen); +#endif bufpos += len; bufleft -= len; |