]> The Tcpdump Group git mirrors - tcpdump/commitdiff
NFLOG: more minor improvements
authorDenis Ovsienko <[email protected]>
Thu, 31 Oct 2013 14:58:42 +0000 (18:58 +0400)
committerDenis Ovsienko <[email protected]>
Thu, 31 Oct 2013 15:01:56 +0000 (19:01 +0400)
Reduce pointer conversion and do version check before header decoding.

print-nflog.c

index c2ea7b7be792e972fef1a8e849b1b730d52cd729..adeecd39ba443739c045f7625e7cec5babf52158 100644 (file)
@@ -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)