X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/979fc38d033c43d68149954d64c93a273d358040..a8abce5c5e2dce2ba6dbccd5d3829da104b80f9c:/print-pflog.c diff --git a/print-pflog.c b/print-pflog.c index a2fba179..7cd96b2e 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)" }, @@ -87,59 +87,60 @@ static const struct tok pf_directions[] = { static void pflog_print(netdissect_options *ndo, const struct pfloghdr *hdr) { - u_int32_t rulenr, subrulenr; + uint32_t rulenr, subrulenr; - rulenr = EXTRACT_32BITS(&hdr->rulenr); - subrulenr = EXTRACT_32BITS(&hdr->subrulenr); - if (subrulenr == (u_int32_t)-1) - ND_PRINT((ndo, "rule %u/", rulenr)); + ndo->ndo_protocol = "pflog"; + rulenr = EXTRACT_BE_U_4(&hdr->rulenr); + subrulenr = EXTRACT_BE_U_4(&hdr->subrulenr); + if (subrulenr == (uint32_t)-1) + ND_PRINT("rule %u/", rulenr); else - ND_PRINT((ndo, "rule %u.%s.%u/", rulenr, hdr->ruleset, subrulenr)); + ND_PRINT("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("%s: %s %s on %s: ", + tok2str(pf_reasons, "unkn(%u)", EXTRACT_U_1(&hdr->reason)), + tok2str(pf_actions, "unkn(%u)", EXTRACT_U_1(&hdr->action)), + tok2str(pf_directions, "unkn(%u)", EXTRACT_U_1(&hdr->dir)), + hdr->ifname); } u_int 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; u_int caplen = h->caplen; const struct pfloghdr *hdr; - u_int8_t af; + uint8_t af; + ndo->ndo_protocol = "pflog_if"; /* check length */ - if (caplen < sizeof(u_int8_t)) { - ND_PRINT((ndo, "%s", tstr)); + if (caplen < sizeof(uint8_t)) { + nd_print_trunc(ndo); return (caplen); } #define MIN_PFLOG_HDRLEN 45 - hdr = (struct pfloghdr *)p; + hdr = (const struct pfloghdr *)p; if (hdr->length < MIN_PFLOG_HDRLEN) { - ND_PRINT((ndo, "[pflog: invalid header length!]")); + ND_PRINT("[pflog: invalid header length!]"); return (hdr->length); /* XXX: not really */ } hdrlen = BPF_WORDALIGN(hdr->length); if (caplen < hdrlen) { - ND_PRINT((ndo, "%s", tstr)); + nd_print_trunc(ndo); return (hdrlen); /* XXX: true? */ } /* 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 = EXTRACT_U_1(&hdr->af); length -= hdrlen; caplen -= hdrlen; p += hdrlen; @@ -152,14 +153,16 @@ pflog_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, ip_print(ndo, p, length); break; -#ifdef INET6 +#if defined(AF_INET6) || defined(OPENBSD_AF_INET6) +#ifdef AF_INET6 case AF_INET6: -#if OPENBSD_AF_INET6 != AF_INET6 +#endif /* AF_INET6 */ +#if !defined(AF_INET6) || OPENBSD_AF_INET6 != AF_INET6 case OPENBSD_AF_INET6: /* XXX: read pcap files */ -#endif +#endif /* !defined(AF_INET6) || OPENBSD_AF_INET6 != AF_INET6 */ ip6_print(ndo, p, length); break; -#endif +#endif /* defined(AF_INET6) || defined(OPENBSD_AF_INET6) */ default: /* address family not handled, print raw packet */ @@ -171,13 +174,6 @@ pflog_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, return (hdrlen); trunc: - ND_PRINT((ndo, "%s", tstr)); + nd_print_trunc(ndo); return (hdrlen); } - -/* - * Local Variables: - * c-style: whitesmith - * c-basic-offset: 8 - * End: - */