]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * This is a module which is used for logging packets. | |
3 | */ | |
4 | ||
5 | /* (C) 2001 Jan Rekorajski <baggins@pld.org.pl> | |
6 | * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org> | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License version 2 as | |
10 | * published by the Free Software Foundation. | |
11 | */ | |
ff67e4e4 | 12 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
1da177e4 | 13 | #include <linux/module.h> |
1da177e4 | 14 | #include <linux/skbuff.h> |
14c85021 | 15 | #include <linux/if_arp.h> |
1da177e4 LT |
16 | #include <linux/ip.h> |
17 | #include <linux/spinlock.h> | |
18 | #include <linux/icmpv6.h> | |
19 | #include <net/udp.h> | |
20 | #include <net/tcp.h> | |
21 | #include <net/ipv6.h> | |
22 | #include <linux/netfilter.h> | |
6709dbbb | 23 | #include <linux/netfilter/x_tables.h> |
1da177e4 | 24 | #include <linux/netfilter_ipv6/ip6_tables.h> |
f01ffbd6 | 25 | #include <net/netfilter/nf_log.h> |
a8defca0 | 26 | #include <net/netfilter/xt_log.h> |
1da177e4 LT |
27 | |
28 | MODULE_AUTHOR("Jan Rekorajski <baggins@pld.org.pl>"); | |
2ae15b64 | 29 | MODULE_DESCRIPTION("Xtables: IPv6 packet logging to syslog"); |
1da177e4 LT |
30 | MODULE_LICENSE("GPL"); |
31 | ||
1da177e4 LT |
32 | struct in_device; |
33 | #include <net/route.h> | |
34 | #include <linux/netfilter_ipv6/ip6t_LOG.h> | |
35 | ||
1da177e4 | 36 | /* One level of recursion won't kill us */ |
a8defca0 ED |
37 | static void dump_packet(struct sbuff *m, |
38 | const struct nf_loginfo *info, | |
1da177e4 LT |
39 | const struct sk_buff *skb, unsigned int ip6hoff, |
40 | int recurse) | |
41 | { | |
42 | u_int8_t currenthdr; | |
43 | int fragment; | |
a47362a2 JE |
44 | struct ipv6hdr _ip6h; |
45 | const struct ipv6hdr *ih; | |
1da177e4 LT |
46 | unsigned int ptr; |
47 | unsigned int hdrlen = 0; | |
608c8e4f HW |
48 | unsigned int logflags; |
49 | ||
50 | if (info->type == NF_LOG_TYPE_LOG) | |
51 | logflags = info->u.log.logflags; | |
52 | else | |
53 | logflags = NF_LOG_MASK; | |
1da177e4 LT |
54 | |
55 | ih = skb_header_pointer(skb, ip6hoff, sizeof(_ip6h), &_ip6h); | |
56 | if (ih == NULL) { | |
a8defca0 | 57 | sb_add(m, "TRUNCATED"); |
1da177e4 LT |
58 | return; |
59 | } | |
60 | ||
46b86a2d | 61 | /* Max length: 88 "SRC=0000.0000.0000.0000.0000.0000.0000.0000 DST=0000.0000.0000.0000.0000.0000.0000.0000 " */ |
a8defca0 | 62 | sb_add(m, "SRC=%pI6 DST=%pI6 ", &ih->saddr, &ih->daddr); |
1da177e4 LT |
63 | |
64 | /* Max length: 44 "LEN=65535 TC=255 HOPLIMIT=255 FLOWLBL=FFFFF " */ | |
a8defca0 | 65 | sb_add(m, "LEN=%Zu TC=%u HOPLIMIT=%u FLOWLBL=%u ", |
1da177e4 | 66 | ntohs(ih->payload_len) + sizeof(struct ipv6hdr), |
e69a4adc | 67 | (ntohl(*(__be32 *)ih) & 0x0ff00000) >> 20, |
1da177e4 | 68 | ih->hop_limit, |
e69a4adc | 69 | (ntohl(*(__be32 *)ih) & 0x000fffff)); |
1da177e4 LT |
70 | |
71 | fragment = 0; | |
72 | ptr = ip6hoff + sizeof(struct ipv6hdr); | |
73 | currenthdr = ih->nexthdr; | |
74 | while (currenthdr != NEXTHDR_NONE && ip6t_ext_hdr(currenthdr)) { | |
a47362a2 JE |
75 | struct ipv6_opt_hdr _hdr; |
76 | const struct ipv6_opt_hdr *hp; | |
1da177e4 LT |
77 | |
78 | hp = skb_header_pointer(skb, ptr, sizeof(_hdr), &_hdr); | |
79 | if (hp == NULL) { | |
a8defca0 | 80 | sb_add(m, "TRUNCATED"); |
1da177e4 LT |
81 | return; |
82 | } | |
83 | ||
84 | /* Max length: 48 "OPT (...) " */ | |
608c8e4f | 85 | if (logflags & IP6T_LOG_IPOPT) |
a8defca0 | 86 | sb_add(m, "OPT ( "); |
1da177e4 LT |
87 | |
88 | switch (currenthdr) { | |
89 | case IPPROTO_FRAGMENT: { | |
a47362a2 JE |
90 | struct frag_hdr _fhdr; |
91 | const struct frag_hdr *fh; | |
1da177e4 | 92 | |
a8defca0 | 93 | sb_add(m, "FRAG:"); |
1da177e4 LT |
94 | fh = skb_header_pointer(skb, ptr, sizeof(_fhdr), |
95 | &_fhdr); | |
96 | if (fh == NULL) { | |
a8defca0 | 97 | sb_add(m, "TRUNCATED "); |
1da177e4 LT |
98 | return; |
99 | } | |
100 | ||
101 | /* Max length: 6 "65535 " */ | |
a8defca0 | 102 | sb_add(m, "%u ", ntohs(fh->frag_off) & 0xFFF8); |
1da177e4 LT |
103 | |
104 | /* Max length: 11 "INCOMPLETE " */ | |
105 | if (fh->frag_off & htons(0x0001)) | |
a8defca0 | 106 | sb_add(m, "INCOMPLETE "); |
1da177e4 | 107 | |
a8defca0 | 108 | sb_add(m, "ID:%08x ", ntohl(fh->identification)); |
1da177e4 LT |
109 | |
110 | if (ntohs(fh->frag_off) & 0xFFF8) | |
111 | fragment = 1; | |
112 | ||
113 | hdrlen = 8; | |
114 | ||
115 | break; | |
116 | } | |
117 | case IPPROTO_DSTOPTS: | |
118 | case IPPROTO_ROUTING: | |
119 | case IPPROTO_HOPOPTS: | |
120 | if (fragment) { | |
608c8e4f | 121 | if (logflags & IP6T_LOG_IPOPT) |
a8defca0 | 122 | sb_add(m, ")"); |
1da177e4 LT |
123 | return; |
124 | } | |
125 | hdrlen = ipv6_optlen(hp); | |
126 | break; | |
127 | /* Max Length */ | |
128 | case IPPROTO_AH: | |
608c8e4f | 129 | if (logflags & IP6T_LOG_IPOPT) { |
a47362a2 JE |
130 | struct ip_auth_hdr _ahdr; |
131 | const struct ip_auth_hdr *ah; | |
1da177e4 LT |
132 | |
133 | /* Max length: 3 "AH " */ | |
a8defca0 | 134 | sb_add(m, "AH "); |
1da177e4 LT |
135 | |
136 | if (fragment) { | |
a8defca0 | 137 | sb_add(m, ")"); |
1da177e4 LT |
138 | return; |
139 | } | |
140 | ||
141 | ah = skb_header_pointer(skb, ptr, sizeof(_ahdr), | |
142 | &_ahdr); | |
143 | if (ah == NULL) { | |
144 | /* | |
1ab1457c | 145 | * Max length: 26 "INCOMPLETE [65535 |
1da177e4 LT |
146 | * bytes] )" |
147 | */ | |
a8defca0 | 148 | sb_add(m, "INCOMPLETE [%u bytes] )", |
1da177e4 LT |
149 | skb->len - ptr); |
150 | return; | |
151 | } | |
152 | ||
153 | /* Length: 15 "SPI=0xF1234567 */ | |
a8defca0 | 154 | sb_add(m, "SPI=0x%x ", ntohl(ah->spi)); |
1da177e4 LT |
155 | |
156 | } | |
157 | ||
158 | hdrlen = (hp->hdrlen+2)<<2; | |
159 | break; | |
160 | case IPPROTO_ESP: | |
608c8e4f | 161 | if (logflags & IP6T_LOG_IPOPT) { |
a47362a2 JE |
162 | struct ip_esp_hdr _esph; |
163 | const struct ip_esp_hdr *eh; | |
1da177e4 LT |
164 | |
165 | /* Max length: 4 "ESP " */ | |
a8defca0 | 166 | sb_add(m, "ESP "); |
1da177e4 LT |
167 | |
168 | if (fragment) { | |
a8defca0 | 169 | sb_add(m, ")"); |
1da177e4 LT |
170 | return; |
171 | } | |
172 | ||
173 | /* | |
174 | * Max length: 26 "INCOMPLETE [65535 bytes] )" | |
175 | */ | |
176 | eh = skb_header_pointer(skb, ptr, sizeof(_esph), | |
177 | &_esph); | |
178 | if (eh == NULL) { | |
a8defca0 | 179 | sb_add(m, "INCOMPLETE [%u bytes] )", |
1da177e4 LT |
180 | skb->len - ptr); |
181 | return; | |
182 | } | |
183 | ||
184 | /* Length: 16 "SPI=0xF1234567 )" */ | |
a8defca0 | 185 | sb_add(m, "SPI=0x%x )", ntohl(eh->spi) ); |
1da177e4 LT |
186 | |
187 | } | |
188 | return; | |
189 | default: | |
190 | /* Max length: 20 "Unknown Ext Hdr 255" */ | |
a8defca0 | 191 | sb_add(m, "Unknown Ext Hdr %u", currenthdr); |
1da177e4 LT |
192 | return; |
193 | } | |
608c8e4f | 194 | if (logflags & IP6T_LOG_IPOPT) |
a8defca0 | 195 | sb_add(m, ") "); |
1da177e4 LT |
196 | |
197 | currenthdr = hp->nexthdr; | |
198 | ptr += hdrlen; | |
199 | } | |
200 | ||
201 | switch (currenthdr) { | |
202 | case IPPROTO_TCP: { | |
a47362a2 JE |
203 | struct tcphdr _tcph; |
204 | const struct tcphdr *th; | |
1da177e4 LT |
205 | |
206 | /* Max length: 10 "PROTO=TCP " */ | |
a8defca0 | 207 | sb_add(m, "PROTO=TCP "); |
1da177e4 LT |
208 | |
209 | if (fragment) | |
210 | break; | |
211 | ||
212 | /* Max length: 25 "INCOMPLETE [65535 bytes] " */ | |
213 | th = skb_header_pointer(skb, ptr, sizeof(_tcph), &_tcph); | |
214 | if (th == NULL) { | |
a8defca0 | 215 | sb_add(m, "INCOMPLETE [%u bytes] ", skb->len - ptr); |
1da177e4 LT |
216 | return; |
217 | } | |
218 | ||
219 | /* Max length: 20 "SPT=65535 DPT=65535 " */ | |
a8defca0 | 220 | sb_add(m, "SPT=%u DPT=%u ", |
1da177e4 LT |
221 | ntohs(th->source), ntohs(th->dest)); |
222 | /* Max length: 30 "SEQ=4294967295 ACK=4294967295 " */ | |
608c8e4f | 223 | if (logflags & IP6T_LOG_TCPSEQ) |
a8defca0 | 224 | sb_add(m, "SEQ=%u ACK=%u ", |
1da177e4 LT |
225 | ntohl(th->seq), ntohl(th->ack_seq)); |
226 | /* Max length: 13 "WINDOW=65535 " */ | |
a8defca0 | 227 | sb_add(m, "WINDOW=%u ", ntohs(th->window)); |
1da177e4 | 228 | /* Max length: 9 "RES=0x3C " */ |
a8defca0 | 229 | sb_add(m, "RES=0x%02x ", (u_int8_t)(ntohl(tcp_flag_word(th) & TCP_RESERVED_BITS) >> 22)); |
1da177e4 LT |
230 | /* Max length: 32 "CWR ECE URG ACK PSH RST SYN FIN " */ |
231 | if (th->cwr) | |
a8defca0 | 232 | sb_add(m, "CWR "); |
1da177e4 | 233 | if (th->ece) |
a8defca0 | 234 | sb_add(m, "ECE "); |
1da177e4 | 235 | if (th->urg) |
a8defca0 | 236 | sb_add(m, "URG "); |
1da177e4 | 237 | if (th->ack) |
a8defca0 | 238 | sb_add(m, "ACK "); |
1da177e4 | 239 | if (th->psh) |
a8defca0 | 240 | sb_add(m, "PSH "); |
1da177e4 | 241 | if (th->rst) |
a8defca0 | 242 | sb_add(m, "RST "); |
1da177e4 | 243 | if (th->syn) |
a8defca0 | 244 | sb_add(m, "SYN "); |
1da177e4 | 245 | if (th->fin) |
a8defca0 | 246 | sb_add(m, "FIN "); |
1da177e4 | 247 | /* Max length: 11 "URGP=65535 " */ |
a8defca0 | 248 | sb_add(m, "URGP=%u ", ntohs(th->urg_ptr)); |
1da177e4 | 249 | |
3666ed1c JP |
250 | if ((logflags & IP6T_LOG_TCPOPT) && |
251 | th->doff * 4 > sizeof(struct tcphdr)) { | |
a47362a2 JE |
252 | u_int8_t _opt[60 - sizeof(struct tcphdr)]; |
253 | const u_int8_t *op; | |
1da177e4 LT |
254 | unsigned int i; |
255 | unsigned int optsize = th->doff * 4 | |
256 | - sizeof(struct tcphdr); | |
257 | ||
258 | op = skb_header_pointer(skb, | |
259 | ptr + sizeof(struct tcphdr), | |
260 | optsize, _opt); | |
261 | if (op == NULL) { | |
a8defca0 | 262 | sb_add(m, "OPT (TRUNCATED)"); |
1da177e4 LT |
263 | return; |
264 | } | |
265 | ||
266 | /* Max length: 127 "OPT (" 15*4*2chars ") " */ | |
a8defca0 | 267 | sb_add(m, "OPT ("); |
1da177e4 | 268 | for (i =0; i < optsize; i++) |
a8defca0 ED |
269 | sb_add(m, "%02X", op[i]); |
270 | sb_add(m, ") "); | |
1da177e4 LT |
271 | } |
272 | break; | |
273 | } | |
ba4e58ec GR |
274 | case IPPROTO_UDP: |
275 | case IPPROTO_UDPLITE: { | |
a47362a2 JE |
276 | struct udphdr _udph; |
277 | const struct udphdr *uh; | |
1da177e4 | 278 | |
ba4e58ec GR |
279 | if (currenthdr == IPPROTO_UDP) |
280 | /* Max length: 10 "PROTO=UDP " */ | |
a8defca0 | 281 | sb_add(m, "PROTO=UDP " ); |
ba4e58ec | 282 | else /* Max length: 14 "PROTO=UDPLITE " */ |
a8defca0 | 283 | sb_add(m, "PROTO=UDPLITE "); |
1da177e4 LT |
284 | |
285 | if (fragment) | |
286 | break; | |
287 | ||
288 | /* Max length: 25 "INCOMPLETE [65535 bytes] " */ | |
289 | uh = skb_header_pointer(skb, ptr, sizeof(_udph), &_udph); | |
290 | if (uh == NULL) { | |
a8defca0 | 291 | sb_add(m, "INCOMPLETE [%u bytes] ", skb->len - ptr); |
1da177e4 LT |
292 | return; |
293 | } | |
294 | ||
295 | /* Max length: 20 "SPT=65535 DPT=65535 " */ | |
a8defca0 | 296 | sb_add(m, "SPT=%u DPT=%u LEN=%u ", |
1da177e4 LT |
297 | ntohs(uh->source), ntohs(uh->dest), |
298 | ntohs(uh->len)); | |
299 | break; | |
300 | } | |
301 | case IPPROTO_ICMPV6: { | |
a47362a2 JE |
302 | struct icmp6hdr _icmp6h; |
303 | const struct icmp6hdr *ic; | |
1da177e4 LT |
304 | |
305 | /* Max length: 13 "PROTO=ICMPv6 " */ | |
a8defca0 | 306 | sb_add(m, "PROTO=ICMPv6 "); |
1da177e4 LT |
307 | |
308 | if (fragment) | |
309 | break; | |
310 | ||
311 | /* Max length: 25 "INCOMPLETE [65535 bytes] " */ | |
312 | ic = skb_header_pointer(skb, ptr, sizeof(_icmp6h), &_icmp6h); | |
313 | if (ic == NULL) { | |
a8defca0 | 314 | sb_add(m, "INCOMPLETE [%u bytes] ", skb->len - ptr); |
1da177e4 LT |
315 | return; |
316 | } | |
317 | ||
318 | /* Max length: 18 "TYPE=255 CODE=255 " */ | |
a8defca0 | 319 | sb_add(m, "TYPE=%u CODE=%u ", ic->icmp6_type, ic->icmp6_code); |
1da177e4 LT |
320 | |
321 | switch (ic->icmp6_type) { | |
322 | case ICMPV6_ECHO_REQUEST: | |
323 | case ICMPV6_ECHO_REPLY: | |
324 | /* Max length: 19 "ID=65535 SEQ=65535 " */ | |
a8defca0 | 325 | sb_add(m, "ID=%u SEQ=%u ", |
1da177e4 LT |
326 | ntohs(ic->icmp6_identifier), |
327 | ntohs(ic->icmp6_sequence)); | |
328 | break; | |
329 | case ICMPV6_MGM_QUERY: | |
330 | case ICMPV6_MGM_REPORT: | |
331 | case ICMPV6_MGM_REDUCTION: | |
332 | break; | |
333 | ||
334 | case ICMPV6_PARAMPROB: | |
335 | /* Max length: 17 "POINTER=ffffffff " */ | |
a8defca0 | 336 | sb_add(m, "POINTER=%08x ", ntohl(ic->icmp6_pointer)); |
1da177e4 LT |
337 | /* Fall through */ |
338 | case ICMPV6_DEST_UNREACH: | |
339 | case ICMPV6_PKT_TOOBIG: | |
340 | case ICMPV6_TIME_EXCEED: | |
341 | /* Max length: 3+maxlen */ | |
342 | if (recurse) { | |
a8defca0 ED |
343 | sb_add(m, "["); |
344 | dump_packet(m, info, skb, | |
345 | ptr + sizeof(_icmp6h), 0); | |
346 | sb_add(m, "] "); | |
1da177e4 LT |
347 | } |
348 | ||
349 | /* Max length: 10 "MTU=65535 " */ | |
350 | if (ic->icmp6_type == ICMPV6_PKT_TOOBIG) | |
a8defca0 | 351 | sb_add(m, "MTU=%u ", ntohl(ic->icmp6_mtu)); |
1da177e4 LT |
352 | } |
353 | break; | |
354 | } | |
355 | /* Max length: 10 "PROTO=255 " */ | |
356 | default: | |
a8defca0 | 357 | sb_add(m, "PROTO=%u ", currenthdr); |
1da177e4 LT |
358 | } |
359 | ||
360 | /* Max length: 15 "UID=4294967295 " */ | |
608c8e4f | 361 | if ((logflags & IP6T_LOG_UID) && recurse && skb->sk) { |
1da177e4 LT |
362 | read_lock_bh(&skb->sk->sk_callback_lock); |
363 | if (skb->sk->sk_socket && skb->sk->sk_socket->file) | |
a8defca0 | 364 | sb_add(m, "UID=%u GID=%u ", |
d76b0d9b DH |
365 | skb->sk->sk_socket->file->f_cred->fsuid, |
366 | skb->sk->sk_socket->file->f_cred->fsgid); | |
1da177e4 LT |
367 | read_unlock_bh(&skb->sk->sk_callback_lock); |
368 | } | |
36e2a1b0 PM |
369 | |
370 | /* Max length: 16 "MARK=0xFFFFFFFF " */ | |
371 | if (!recurse && skb->mark) | |
a8defca0 | 372 | sb_add(m, "MARK=0x%x ", skb->mark); |
1da177e4 LT |
373 | } |
374 | ||
a8defca0 ED |
375 | static void dump_mac_header(struct sbuff *m, |
376 | const struct nf_loginfo *info, | |
7eb9282c PM |
377 | const struct sk_buff *skb) |
378 | { | |
379 | struct net_device *dev = skb->dev; | |
380 | unsigned int logflags = 0; | |
381 | ||
382 | if (info->type == NF_LOG_TYPE_LOG) | |
383 | logflags = info->u.log.logflags; | |
384 | ||
385 | if (!(logflags & IP6T_LOG_MACDECODE)) | |
386 | goto fallback; | |
387 | ||
388 | switch (dev->type) { | |
389 | case ARPHRD_ETHER: | |
a8defca0 | 390 | sb_add(m, "MACSRC=%pM MACDST=%pM MACPROTO=%04x ", |
7eb9282c PM |
391 | eth_hdr(skb)->h_source, eth_hdr(skb)->h_dest, |
392 | ntohs(eth_hdr(skb)->h_proto)); | |
393 | return; | |
394 | default: | |
395 | break; | |
396 | } | |
397 | ||
398 | fallback: | |
a8defca0 | 399 | sb_add(m, "MAC="); |
7eb9282c PM |
400 | if (dev->hard_header_len && |
401 | skb->mac_header != skb->network_header) { | |
402 | const unsigned char *p = skb_mac_header(skb); | |
403 | unsigned int len = dev->hard_header_len; | |
404 | unsigned int i; | |
405 | ||
406 | if (dev->type == ARPHRD_SIT && | |
407 | (p -= ETH_HLEN) < skb->head) | |
408 | p = NULL; | |
409 | ||
410 | if (p != NULL) { | |
a8defca0 | 411 | sb_add(m, "%02x", *p++); |
7eb9282c | 412 | for (i = 1; i < len; i++) |
a8defca0 | 413 | sb_add(m, ":%02x", p[i]); |
7eb9282c | 414 | } |
a8defca0 | 415 | sb_add(m, " "); |
7eb9282c PM |
416 | |
417 | if (dev->type == ARPHRD_SIT) { | |
418 | const struct iphdr *iph = | |
419 | (struct iphdr *)skb_mac_header(skb); | |
a8defca0 | 420 | sb_add(m, "TUNNEL=%pI4->%pI4 ", &iph->saddr, &iph->daddr); |
7eb9282c PM |
421 | } |
422 | } else | |
a8defca0 | 423 | sb_add(m, " "); |
7eb9282c PM |
424 | } |
425 | ||
608c8e4f HW |
426 | static struct nf_loginfo default_loginfo = { |
427 | .type = NF_LOG_TYPE_LOG, | |
428 | .u = { | |
429 | .log = { | |
f0d57a54 | 430 | .level = 5, |
608c8e4f HW |
431 | .logflags = NF_LOG_MASK, |
432 | }, | |
433 | }, | |
434 | }; | |
435 | ||
1da177e4 | 436 | static void |
76108cea | 437 | ip6t_log_packet(u_int8_t pf, |
608c8e4f | 438 | unsigned int hooknum, |
1da177e4 LT |
439 | const struct sk_buff *skb, |
440 | const struct net_device *in, | |
441 | const struct net_device *out, | |
608c8e4f | 442 | const struct nf_loginfo *loginfo, |
1da177e4 LT |
443 | const char *prefix) |
444 | { | |
a8defca0 ED |
445 | struct sbuff *m = sb_open(); |
446 | ||
608c8e4f HW |
447 | if (!loginfo) |
448 | loginfo = &default_loginfo; | |
449 | ||
a8defca0 ED |
450 | sb_add(m, "<%d>%sIN=%s OUT=%s ", loginfo->u.log.level, |
451 | prefix, | |
452 | in ? in->name : "", | |
453 | out ? out->name : ""); | |
047601bf | 454 | |
7eb9282c PM |
455 | /* MAC logging for input path only. */ |
456 | if (in && !out) | |
a8defca0 ED |
457 | dump_mac_header(m, loginfo, skb); |
458 | ||
459 | dump_packet(m, loginfo, skb, skb_network_offset(skb), 1); | |
1da177e4 | 460 | |
a8defca0 | 461 | sb_close(m); |
1da177e4 LT |
462 | } |
463 | ||
464 | static unsigned int | |
4b560b44 | 465 | log_tg6(struct sk_buff *skb, const struct xt_action_param *par) |
1da177e4 | 466 | { |
7eb35586 | 467 | const struct ip6t_log_info *loginfo = par->targinfo; |
608c8e4f HW |
468 | struct nf_loginfo li; |
469 | ||
470 | li.type = NF_LOG_TYPE_LOG; | |
471 | li.u.log.level = loginfo->level; | |
472 | li.u.log.logflags = loginfo->logflags; | |
1da177e4 | 473 | |
7eb35586 | 474 | ip6t_log_packet(NFPROTO_IPV6, par->hooknum, skb, par->in, par->out, |
ee999d8b | 475 | &li, loginfo->prefix); |
6709dbbb | 476 | return XT_CONTINUE; |
1da177e4 LT |
477 | } |
478 | ||
1da177e4 | 479 | |
135367b8 | 480 | static int log_tg6_check(const struct xt_tgchk_param *par) |
1da177e4 | 481 | { |
af5d6dc2 | 482 | const struct ip6t_log_info *loginfo = par->targinfo; |
1da177e4 | 483 | |
1da177e4 | 484 | if (loginfo->level >= 8) { |
ff67e4e4 | 485 | pr_debug("level %u >= 8\n", loginfo->level); |
d6b00a53 | 486 | return -EINVAL; |
1da177e4 | 487 | } |
1da177e4 | 488 | if (loginfo->prefix[sizeof(loginfo->prefix)-1] != '\0') { |
ff67e4e4 | 489 | pr_debug("prefix not null-terminated\n"); |
d6b00a53 | 490 | return -EINVAL; |
1da177e4 | 491 | } |
d6b00a53 | 492 | return 0; |
1da177e4 LT |
493 | } |
494 | ||
d3c5ee6d | 495 | static struct xt_target log_tg6_reg __read_mostly = { |
1da177e4 | 496 | .name = "LOG", |
ee999d8b | 497 | .family = NFPROTO_IPV6, |
d3c5ee6d | 498 | .target = log_tg6, |
7f939713 | 499 | .targetsize = sizeof(struct ip6t_log_info), |
d3c5ee6d | 500 | .checkentry = log_tg6_check, |
1da177e4 LT |
501 | .me = THIS_MODULE, |
502 | }; | |
503 | ||
ca735b3a | 504 | static struct nf_logger ip6t_logger __read_mostly = { |
608c8e4f HW |
505 | .name = "ip6t_LOG", |
506 | .logfn = &ip6t_log_packet, | |
507 | .me = THIS_MODULE, | |
508 | }; | |
509 | ||
d3c5ee6d | 510 | static int __init log_tg6_init(void) |
1da177e4 | 511 | { |
e1fd0586 JE |
512 | int ret; |
513 | ||
d3c5ee6d | 514 | ret = xt_register_target(&log_tg6_reg); |
e1fd0586 JE |
515 | if (ret < 0) |
516 | return ret; | |
ee999d8b | 517 | nf_log_register(NFPROTO_IPV6, &ip6t_logger); |
7e2acc7e | 518 | return 0; |
1da177e4 LT |
519 | } |
520 | ||
d3c5ee6d | 521 | static void __exit log_tg6_exit(void) |
1da177e4 | 522 | { |
e92ad99c | 523 | nf_log_unregister(&ip6t_logger); |
d3c5ee6d | 524 | xt_unregister_target(&log_tg6_reg); |
1da177e4 LT |
525 | } |
526 | ||
d3c5ee6d JE |
527 | module_init(log_tg6_init); |
528 | module_exit(log_tg6_exit); |