2 * Copyright (c) 2013, Petar Alilovic,
3 * Faculty of Electrical Engineering and Computing, University of Zagreb
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
9 * * Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
32 #include <tcpdump-stdinc.h>
37 #include "netdissect.h"
38 #include "interface.h"
44 #define NFULA_PAYLOAD 9
47 const struct tok nflog_values
[] = {
54 nflog_hdr_print(struct netdissect_options
*ndo
, const u_char
*bp
, u_int length
)
56 const nflog_hdr_t
*hdr
;
57 hdr
= (const nflog_hdr_t
*)bp
;
59 ND_PRINT((ndo
, "version %d, resource ID %d", hdr
->nflog_version
, ntohs(hdr
->nflog_rid
)));
61 if (!ndo
->ndo_qflag
) {
62 ND_PRINT((ndo
,", family %s (%d)",
63 tok2str(nflog_values
, "Unknown",
69 "Unknown NFLOG (0x%02x)",
73 ND_PRINT((ndo
, ", length %u: ", length
));
77 nflog_print(struct netdissect_options
*ndo
, const u_char
*p
, u_int length
, u_int caplen
)
79 const nflog_hdr_t
*hdr
;
80 const nflog_tlv_t
*tlv
;
83 if (caplen
< (int) sizeof(nflog_hdr_t
)) {
84 ND_PRINT((ndo
, "[|nflog]"));
89 nflog_hdr_print(ndo
, p
, length
);
91 length
-= sizeof(nflog_hdr_t
);
92 caplen
-= sizeof(nflog_hdr_t
);
93 hdr
= (const nflog_hdr_t
*)p
;
94 p
+= sizeof(nflog_hdr_t
);
97 tlv
= (const nflog_tlv_t
*) p
;
98 size
= tlv
->tlv_length
;
100 /* wrong size of the packet */
105 if (tlv
->tlv_type
> NFULA_MAX
)
109 size
+= 4 - size
% 4;
112 length
= length
- size
;
113 caplen
= caplen
- size
;
115 } while (tlv
->tlv_type
!= NFULA_PAYLOAD
);
117 /* dont skip payload just tlv length and type */
122 switch (hdr
->nflog_family
) {
125 ip_print(ndo
, p
, length
);
130 ip6_print(ndo
, p
, length
);
136 nflog_hdr_print(ndo
, (u_char
*)hdr
,
137 length
+ sizeof(nflog_hdr_t
));
139 if (!ndo
->ndo_suppress_default_print
)
140 ndo
->ndo_default_print(ndo
, p
, caplen
);
146 nflog_if_print(struct netdissect_options
*ndo
,
147 const struct pcap_pkthdr
*h
, const u_char
*p
)
150 nflog_print(ndo
, p
, h
->len
, h
->caplen
);
151 return (sizeof(nflog_hdr_t
));
154 #endif /* DLT_NFLOG */