Skip to content

Commit 346122a

Browse files
committed
pflog: handle OpenBSD's "rewriten" flag and addresses.
Derived from the OpenBSD tcpdump.
1 parent 979037f commit 346122a

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

print-pflog.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "netdissect.h"
3232
#include "extract.h"
3333
#include "af.h"
34+
#include "addrtostr.h"
3435

3536
/*
3637
* pflog headers, at least as they exist now.
@@ -337,6 +338,34 @@ static const struct tok pf_directions_other[] = {
337338
{ 0, NULL }
338339
};
339340

341+
static void
342+
print_pf_addr(netdissect_options *ndo, const char *tag, u_int naf,
343+
const struct pf_addr *addr, const nd_uint16_t port)
344+
{
345+
char buf[INET6_ADDRSTRLEN];
346+
uint16_t portnum;
347+
348+
ND_PRINT("%s ", tag);
349+
ND_TCHECK_SIZE(addr);
350+
switch (naf) {
351+
352+
case BSD_AF_INET:
353+
addrtostr(addr->v4, buf, sizeof(buf));
354+
break;
355+
356+
case BSD_AF_INET6_BSD:
357+
addrtostr6(addr->v6, buf, sizeof(buf));
358+
break;
359+
360+
default:
361+
strlcpy(buf, "?", sizeof(buf));
362+
break;
363+
}
364+
ND_PRINT("%s:", buf);
365+
portnum = GET_BE_U_2(port);
366+
ND_PRINT("%u", portnum);
367+
}
368+
340369
static void
341370
pflog_print(netdissect_options *ndo, const struct pfloghdr *hdr)
342371
{
@@ -427,6 +456,20 @@ pflog_print(netdissect_options *ndo, const struct pfloghdr *hdr)
427456
}
428457
nd_printjnp(ndo, (const u_char*)hdr->ifname, PFLOG_IFNAMSIZ);
429458
ND_PRINT(": ");
459+
if (length == PFLOG_HEADER_LEN_OPENBSD) {
460+
if (ndo->ndo_vflag && GET_U_1(hdr->u.openbsd.rewritten)) {
461+
uint8_t naf;
462+
463+
ND_PRINT("[rewritten: ");
464+
naf = GET_U_1(hdr->u.openbsd.naf);
465+
print_pf_addr(ndo, "src", naf, &hdr->u.openbsd.saddr,
466+
hdr->u.openbsd.sport);
467+
ND_PRINT(", ");
468+
print_pf_addr(ndo, "src", naf, &hdr->u.openbsd.daddr,
469+
hdr->u.openbsd.dport);
470+
ND_PRINT("; ");
471+
}
472+
}
430473
}
431474

432475
void

0 commit comments

Comments
 (0)