X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/a6f81d534ddc1026442664d21a2122d64ab571a9..c39d40a767a1ae36171e5bcbf6f157ff3e80fb6c:/print-pflog.c diff --git a/print-pflog.c b/print-pflog.c index 72ae2763..eb1b1766 100644 --- a/print-pflog.c +++ b/print-pflog.c @@ -19,9 +19,10 @@ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ -#define NETDISSECT_REWORKED +/* \summary: OpenBSD packet filter log file printer */ + #ifdef HAVE_CONFIG_H -#include "config.h" +#include #endif #ifndef HAVE_NET_PFVAR_H @@ -33,12 +34,11 @@ #include #include -#include +#include "netdissect-stdinc.h" -#include "interface.h" +#include "netdissect.h" #include "extract.h" -static const char tstr[] = "[|pflog]"; static const struct tok pf_reasons[] = { { 0, "0(match)" }, @@ -89,23 +89,28 @@ pflog_print(netdissect_options *ndo, const struct pfloghdr *hdr) { uint32_t rulenr, subrulenr; - rulenr = EXTRACT_32BITS(&hdr->rulenr); - subrulenr = EXTRACT_32BITS(&hdr->subrulenr); + ndo->ndo_protocol = "pflog"; + rulenr = GET_BE_U_4(&hdr->rulenr); + subrulenr = GET_BE_U_4(&hdr->subrulenr); if (subrulenr == (uint32_t)-1) - ND_PRINT((ndo, "rule %u/", rulenr)); - else - ND_PRINT((ndo, "rule %u.%s.%u/", rulenr, hdr->ruleset, subrulenr)); - - ND_PRINT((ndo, "%s: %s %s on %s: ", - tok2str(pf_reasons, "unkn(%u)", hdr->reason), - tok2str(pf_actions, "unkn(%u)", hdr->action), - tok2str(pf_directions, "unkn(%u)", hdr->dir), - hdr->ifname)); + ND_PRINT("rule %u/", rulenr); + else { + ND_PRINT("rule %u.", rulenr); + nd_printjnp(ndo, (const u_char*)hdr->ruleset, PFLOG_RULESET_NAME_SIZE); + ND_PRINT(".%u/", subrulenr); + } + + ND_PRINT("%s: %s %s on ", + tok2str(pf_reasons, "unkn(%u)", GET_U_1(&hdr->reason)), + tok2str(pf_actions, "unkn(%u)", GET_U_1(&hdr->action)), + tok2str(pf_directions, "unkn(%u)", GET_U_1(&hdr->dir))); + nd_printjnp(ndo, (const u_char*)hdr->ifname, IFNAMSIZ); + ND_PRINT(": "); } -u_int +void pflog_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, - register const u_char *p) + const u_char *p) { u_int length = h->len; u_int hdrlen; @@ -113,33 +118,36 @@ pflog_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const struct pfloghdr *hdr; uint8_t af; + ndo->ndo_protocol = "pflog"; /* check length */ if (caplen < sizeof(uint8_t)) { - ND_PRINT((ndo, "%s", tstr)); - return (caplen); + nd_print_trunc(ndo); + ndo->ndo_ll_hdr_len += h->caplen; + return; } #define MIN_PFLOG_HDRLEN 45 - hdr = (struct pfloghdr *)p; - if (hdr->length < MIN_PFLOG_HDRLEN) { - ND_PRINT((ndo, "[pflog: invalid header length!]")); - return (hdr->length); /* XXX: not really */ + hdr = (const struct pfloghdr *)p; + if (GET_U_1(&hdr->length) < MIN_PFLOG_HDRLEN) { + ND_PRINT("[pflog: invalid header length!]"); + ndo->ndo_ll_hdr_len += GET_U_1(&hdr->length); /* XXX: not really */ + return; } hdrlen = BPF_WORDALIGN(hdr->length); if (caplen < hdrlen) { - ND_PRINT((ndo, "%s", tstr)); - return (hdrlen); /* XXX: true? */ + nd_print_trunc(ndo); + ndo->ndo_ll_hdr_len += hdrlen; /* XXX: true? */ + return; } /* print what we know */ - hdr = (struct pfloghdr *)p; - ND_TCHECK(*hdr); + ND_TCHECK_SIZE(hdr); if (ndo->ndo_eflag) pflog_print(ndo, hdr); /* skip to the real packet */ - af = hdr->af; + af = GET_U_1(&hdr->af); length -= hdrlen; caplen -= hdrlen; p += hdrlen; @@ -171,15 +179,9 @@ pflog_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, ND_DEFAULTPRINT(p, caplen); } - return (hdrlen); + ndo->ndo_ll_hdr_len += hdrlen; + return; trunc: - ND_PRINT((ndo, "%s", tstr)); - return (hdrlen); + nd_print_trunc(ndo); + ndo->ndo_ll_hdr_len += hdrlen; } - -/* - * Local Variables: - * c-style: whitesmith - * c-basic-offset: 8 - * End: - */