From: Denis Ovsienko Date: Thu, 31 Oct 2013 14:58:42 +0000 (+0400) Subject: NFLOG: more minor improvements X-Git-Tag: tcpdump-4.5.0~5 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/fc133e2edba0fce13d34813308e7523596f869e1 NFLOG: more minor improvements Reduce pointer conversion and do version check before header decoding. --- diff --git a/print-nflog.c b/print-nflog.c index c2ea7b7b..adeecd39 100644 --- a/print-nflog.c +++ b/print-nflog.c @@ -50,11 +50,8 @@ static const struct tok nflog_values[] = { }; static inline void -nflog_hdr_print(struct netdissect_options *ndo, const u_char *bp, u_int length) +nflog_hdr_print(struct netdissect_options *ndo, const nflog_hdr_t *hdr, u_int length) { - const nflog_hdr_t *hdr; - hdr = (const nflog_hdr_t *)bp; - ND_PRINT((ndo, "version %d, resource ID %d", hdr->nflog_version, ntohs(hdr->nflog_rid))); if (!ndo->ndo_qflag) { @@ -76,7 +73,7 @@ u_int nflog_if_print(struct netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p) { - const nflog_hdr_t *hdr; + const nflog_hdr_t *hdr = (const nflog_hdr_t *)p; const nflog_tlv_t *tlv; u_int16_t size; u_int16_t h_size = sizeof(nflog_hdr_t); @@ -88,19 +85,18 @@ nflog_if_print(struct netdissect_options *ndo, return h_size; } + if (!(hdr->nflog_version) == 0) { + ND_PRINT((ndo, ", NFLOG version mismatch: %u", hdr->nflog_version)); + return h_size; + } + if (ndo->ndo_eflag) - nflog_hdr_print(ndo, p, length); + nflog_hdr_print(ndo, hdr, length); length -= sizeof(nflog_hdr_t); caplen -= sizeof(nflog_hdr_t); - hdr = (const nflog_hdr_t *)p; p += sizeof(nflog_hdr_t); - if (!(hdr->nflog_version) == 0) { - ND_PRINT((ndo, ", NFLOG version mismatch: %u", hdr->nflog_version)); - return h_size; - } - do { tlv = (const nflog_tlv_t *) p; size = tlv->tlv_length; @@ -140,7 +136,7 @@ nflog_if_print(struct netdissect_options *ndo, default: if (!ndo->ndo_eflag) - nflog_hdr_print(ndo, (u_char *)hdr, + nflog_hdr_print(ndo, hdr, length + sizeof(nflog_hdr_t)); if (!ndo->ndo_suppress_default_print)