2 * This is a module which is used for logging packets.
5 /* (C) 1999-2001 Paul `Rusty' Russell
6 * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
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.
13 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14 #include <linux/module.h>
15 #include <linux/spinlock.h>
16 #include <linux/skbuff.h>
17 #include <linux/if_arp.h>
23 #include <net/route.h>
25 #include <linux/netfilter.h>
26 #include <linux/netfilter/x_tables.h>
27 #include <linux/netfilter/xt_LOG.h>
28 #include <linux/netfilter_ipv6/ip6_tables.h>
29 #include <net/netfilter/nf_log.h>
30 #include <net/netfilter/xt_log.h>
32 static struct nf_loginfo default_loginfo = {
33 .type = NF_LOG_TYPE_LOG,
37 .logflags = NF_LOG_MASK,
42 static int dump_udp_header(struct sbuff *m, const struct sk_buff *skb,
43 u8 proto, int fragment, unsigned int offset)
46 const struct udphdr *uh;
48 if (proto == IPPROTO_UDP)
49 /* Max length: 10 "PROTO=UDP " */
50 sb_add(m, "PROTO=UDP ");
51 else /* Max length: 14 "PROTO=UDPLITE " */
52 sb_add(m, "PROTO=UDPLITE ");
57 /* Max length: 25 "INCOMPLETE [65535 bytes] " */
58 uh = skb_header_pointer(skb, offset, sizeof(_udph), &_udph);
60 sb_add(m, "INCOMPLETE [%u bytes] ", skb->len - offset);
65 /* Max length: 20 "SPT=65535 DPT=65535 " */
66 sb_add(m, "SPT=%u DPT=%u LEN=%u ", ntohs(uh->source), ntohs(uh->dest),
73 static int dump_tcp_header(struct sbuff *m, const struct sk_buff *skb,
74 u8 proto, int fragment, unsigned int offset,
75 unsigned int logflags)
78 const struct tcphdr *th;
80 /* Max length: 10 "PROTO=TCP " */
81 sb_add(m, "PROTO=TCP ");
86 /* Max length: 25 "INCOMPLETE [65535 bytes] " */
87 th = skb_header_pointer(skb, offset, sizeof(_tcph), &_tcph);
89 sb_add(m, "INCOMPLETE [%u bytes] ", skb->len - offset);
93 /* Max length: 20 "SPT=65535 DPT=65535 " */
94 sb_add(m, "SPT=%u DPT=%u ", ntohs(th->source), ntohs(th->dest));
95 /* Max length: 30 "SEQ=4294967295 ACK=4294967295 " */
96 if (logflags & XT_LOG_TCPSEQ)
97 sb_add(m, "SEQ=%u ACK=%u ", ntohl(th->seq), ntohl(th->ack_seq));
99 /* Max length: 13 "WINDOW=65535 " */
100 sb_add(m, "WINDOW=%u ", ntohs(th->window));
101 /* Max length: 9 "RES=0x3C " */
102 sb_add(m, "RES=0x%02x ", (u_int8_t)(ntohl(tcp_flag_word(th) &
103 TCP_RESERVED_BITS) >> 22));
104 /* Max length: 32 "CWR ECE URG ACK PSH RST SYN FIN " */
121 /* Max length: 11 "URGP=65535 " */
122 sb_add(m, "URGP=%u ", ntohs(th->urg_ptr));
124 if ((logflags & XT_LOG_TCPOPT) && th->doff*4 > sizeof(struct tcphdr)) {
125 u_int8_t _opt[60 - sizeof(struct tcphdr)];
128 unsigned int optsize = th->doff*4 - sizeof(struct tcphdr);
130 op = skb_header_pointer(skb, offset + sizeof(struct tcphdr),
133 sb_add(m, "OPT (TRUNCATED)");
137 /* Max length: 127 "OPT (" 15*4*2chars ") " */
139 for (i = 0; i < optsize; i++)
140 sb_add(m, "%02X", op[i]);
148 static void dump_sk_uid_gid(struct sbuff *m, struct sock *sk)
150 if (!sk || sk->sk_state == TCP_TIME_WAIT)
153 read_lock_bh(&sk->sk_callback_lock);
154 if (sk->sk_socket && sk->sk_socket->file) {
155 const struct cred *cred = sk->sk_socket->file->f_cred;
156 sb_add(m, "UID=%u GID=%u ",
157 from_kuid_munged(&init_user_ns, cred->fsuid),
158 from_kgid_munged(&init_user_ns, cred->fsgid));
160 read_unlock_bh(&sk->sk_callback_lock);
163 /* One level of recursion won't kill us */
164 static void dump_ipv4_packet(struct sbuff *m,
165 const struct nf_loginfo *info,
166 const struct sk_buff *skb,
170 const struct iphdr *ih;
171 unsigned int logflags;
173 if (info->type == NF_LOG_TYPE_LOG)
174 logflags = info->u.log.logflags;
176 logflags = NF_LOG_MASK;
178 ih = skb_header_pointer(skb, iphoff, sizeof(_iph), &_iph);
180 sb_add(m, "TRUNCATED");
185 * TOS, len, DF/MF, fragment offset, TTL, src, dst, options. */
186 /* Max length: 40 "SRC=255.255.255.255 DST=255.255.255.255 " */
187 sb_add(m, "SRC=%pI4 DST=%pI4 ",
188 &ih->saddr, &ih->daddr);
190 /* Max length: 46 "LEN=65535 TOS=0xFF PREC=0xFF TTL=255 ID=65535 " */
191 sb_add(m, "LEN=%u TOS=0x%02X PREC=0x%02X TTL=%u ID=%u ",
192 ntohs(ih->tot_len), ih->tos & IPTOS_TOS_MASK,
193 ih->tos & IPTOS_PREC_MASK, ih->ttl, ntohs(ih->id));
195 /* Max length: 6 "CE DF MF " */
196 if (ntohs(ih->frag_off) & IP_CE)
198 if (ntohs(ih->frag_off) & IP_DF)
200 if (ntohs(ih->frag_off) & IP_MF)
203 /* Max length: 11 "FRAG:65535 " */
204 if (ntohs(ih->frag_off) & IP_OFFSET)
205 sb_add(m, "FRAG:%u ", ntohs(ih->frag_off) & IP_OFFSET);
207 if ((logflags & XT_LOG_IPOPT) &&
208 ih->ihl * 4 > sizeof(struct iphdr)) {
209 const unsigned char *op;
210 unsigned char _opt[4 * 15 - sizeof(struct iphdr)];
211 unsigned int i, optsize;
213 optsize = ih->ihl * 4 - sizeof(struct iphdr);
214 op = skb_header_pointer(skb, iphoff+sizeof(_iph),
217 sb_add(m, "TRUNCATED");
221 /* Max length: 127 "OPT (" 15*4*2chars ") " */
223 for (i = 0; i < optsize; i++)
224 sb_add(m, "%02X", op[i]);
228 switch (ih->protocol) {
230 if (dump_tcp_header(m, skb, ih->protocol,
231 ntohs(ih->frag_off) & IP_OFFSET,
232 iphoff+ih->ihl*4, logflags))
236 case IPPROTO_UDPLITE:
237 if (dump_udp_header(m, skb, ih->protocol,
238 ntohs(ih->frag_off) & IP_OFFSET,
243 struct icmphdr _icmph;
244 const struct icmphdr *ich;
245 static const size_t required_len[NR_ICMP_TYPES+1]
246 = { [ICMP_ECHOREPLY] = 4,
248 = 8 + sizeof(struct iphdr),
250 = 8 + sizeof(struct iphdr),
252 = 8 + sizeof(struct iphdr),
255 = 8 + sizeof(struct iphdr),
257 = 8 + sizeof(struct iphdr),
258 [ICMP_TIMESTAMP] = 20,
259 [ICMP_TIMESTAMPREPLY] = 20,
261 [ICMP_ADDRESSREPLY] = 12 };
263 /* Max length: 11 "PROTO=ICMP " */
264 sb_add(m, "PROTO=ICMP ");
266 if (ntohs(ih->frag_off) & IP_OFFSET)
269 /* Max length: 25 "INCOMPLETE [65535 bytes] " */
270 ich = skb_header_pointer(skb, iphoff + ih->ihl * 4,
271 sizeof(_icmph), &_icmph);
273 sb_add(m, "INCOMPLETE [%u bytes] ",
274 skb->len - iphoff - ih->ihl*4);
278 /* Max length: 18 "TYPE=255 CODE=255 " */
279 sb_add(m, "TYPE=%u CODE=%u ", ich->type, ich->code);
281 /* Max length: 25 "INCOMPLETE [65535 bytes] " */
282 if (ich->type <= NR_ICMP_TYPES &&
283 required_len[ich->type] &&
284 skb->len-iphoff-ih->ihl*4 < required_len[ich->type]) {
285 sb_add(m, "INCOMPLETE [%u bytes] ",
286 skb->len - iphoff - ih->ihl*4);
293 /* Max length: 19 "ID=65535 SEQ=65535 " */
294 sb_add(m, "ID=%u SEQ=%u ",
295 ntohs(ich->un.echo.id),
296 ntohs(ich->un.echo.sequence));
299 case ICMP_PARAMETERPROB:
300 /* Max length: 14 "PARAMETER=255 " */
301 sb_add(m, "PARAMETER=%u ",
302 ntohl(ich->un.gateway) >> 24);
305 /* Max length: 24 "GATEWAY=255.255.255.255 " */
306 sb_add(m, "GATEWAY=%pI4 ", &ich->un.gateway);
308 case ICMP_DEST_UNREACH:
309 case ICMP_SOURCE_QUENCH:
310 case ICMP_TIME_EXCEEDED:
311 /* Max length: 3+maxlen */
312 if (!iphoff) { /* Only recurse once. */
314 dump_ipv4_packet(m, info, skb,
315 iphoff + ih->ihl*4+sizeof(_icmph));
319 /* Max length: 10 "MTU=65535 " */
320 if (ich->type == ICMP_DEST_UNREACH &&
321 ich->code == ICMP_FRAG_NEEDED)
322 sb_add(m, "MTU=%u ", ntohs(ich->un.frag.mtu));
328 struct ip_auth_hdr _ahdr;
329 const struct ip_auth_hdr *ah;
331 if (ntohs(ih->frag_off) & IP_OFFSET)
334 /* Max length: 9 "PROTO=AH " */
335 sb_add(m, "PROTO=AH ");
337 /* Max length: 25 "INCOMPLETE [65535 bytes] " */
338 ah = skb_header_pointer(skb, iphoff+ih->ihl*4,
339 sizeof(_ahdr), &_ahdr);
341 sb_add(m, "INCOMPLETE [%u bytes] ",
342 skb->len - iphoff - ih->ihl*4);
346 /* Length: 15 "SPI=0xF1234567 " */
347 sb_add(m, "SPI=0x%x ", ntohl(ah->spi));
351 struct ip_esp_hdr _esph;
352 const struct ip_esp_hdr *eh;
354 /* Max length: 10 "PROTO=ESP " */
355 sb_add(m, "PROTO=ESP ");
357 if (ntohs(ih->frag_off) & IP_OFFSET)
360 /* Max length: 25 "INCOMPLETE [65535 bytes] " */
361 eh = skb_header_pointer(skb, iphoff+ih->ihl*4,
362 sizeof(_esph), &_esph);
364 sb_add(m, "INCOMPLETE [%u bytes] ",
365 skb->len - iphoff - ih->ihl*4);
369 /* Length: 15 "SPI=0xF1234567 " */
370 sb_add(m, "SPI=0x%x ", ntohl(eh->spi));
373 /* Max length: 10 "PROTO 255 " */
375 sb_add(m, "PROTO=%u ", ih->protocol);
378 /* Max length: 15 "UID=4294967295 " */
379 if ((logflags & XT_LOG_UID) && !iphoff)
380 dump_sk_uid_gid(m, skb->sk);
382 /* Max length: 16 "MARK=0xFFFFFFFF " */
383 if (!iphoff && skb->mark)
384 sb_add(m, "MARK=0x%x ", skb->mark);
386 /* Proto Max log string length */
387 /* IP: 40+46+6+11+127 = 230 */
388 /* TCP: 10+max(25,20+30+13+9+32+11+127) = 252 */
389 /* UDP: 10+max(25,20) = 35 */
390 /* UDPLITE: 14+max(25,20) = 39 */
391 /* ICMP: 11+max(25, 18+25+max(19,14,24+3+n+10,3+n+10)) = 91+n */
392 /* ESP: 10+max(25)+15 = 50 */
393 /* AH: 9+max(25)+15 = 49 */
396 /* (ICMP allows recursion one level deep) */
397 /* maxlen = IP + ICMP + IP + max(TCP,UDP,ICMP,unknown) */
398 /* maxlen = 230+ 91 + 230 + 252 = 803 */
401 static void dump_ipv4_mac_header(struct sbuff *m,
402 const struct nf_loginfo *info,
403 const struct sk_buff *skb)
405 struct net_device *dev = skb->dev;
406 unsigned int logflags = 0;
408 if (info->type == NF_LOG_TYPE_LOG)
409 logflags = info->u.log.logflags;
411 if (!(logflags & XT_LOG_MACDECODE))
416 sb_add(m, "MACSRC=%pM MACDST=%pM MACPROTO=%04x ",
417 eth_hdr(skb)->h_source, eth_hdr(skb)->h_dest,
418 ntohs(eth_hdr(skb)->h_proto));
426 if (dev->hard_header_len &&
427 skb->mac_header != skb->network_header) {
428 const unsigned char *p = skb_mac_header(skb);
431 sb_add(m, "%02x", *p++);
432 for (i = 1; i < dev->hard_header_len; i++, p++)
433 sb_add(m, ":%02x", *p);
439 log_packet_common(struct sbuff *m,
441 unsigned int hooknum,
442 const struct sk_buff *skb,
443 const struct net_device *in,
444 const struct net_device *out,
445 const struct nf_loginfo *loginfo,
448 sb_add(m, KERN_SOH "%c%sIN=%s OUT=%s ",
449 '0' + loginfo->u.log.level, prefix,
451 out ? out->name : "");
452 #ifdef CONFIG_BRIDGE_NETFILTER
453 if (skb->nf_bridge) {
454 const struct net_device *physindev;
455 const struct net_device *physoutdev;
457 physindev = skb->nf_bridge->physindev;
458 if (physindev && in != physindev)
459 sb_add(m, "PHYSIN=%s ", physindev->name);
460 physoutdev = skb->nf_bridge->physoutdev;
461 if (physoutdev && out != physoutdev)
462 sb_add(m, "PHYSOUT=%s ", physoutdev->name);
469 ipt_log_packet(u_int8_t pf,
470 unsigned int hooknum,
471 const struct sk_buff *skb,
472 const struct net_device *in,
473 const struct net_device *out,
474 const struct nf_loginfo *loginfo,
477 struct sbuff *m = sb_open();
480 loginfo = &default_loginfo;
482 log_packet_common(m, pf, hooknum, skb, in, out, loginfo, prefix);
485 dump_ipv4_mac_header(m, loginfo, skb);
487 dump_ipv4_packet(m, loginfo, skb, 0);
492 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
493 /* One level of recursion won't kill us */
494 static void dump_ipv6_packet(struct sbuff *m,
495 const struct nf_loginfo *info,
496 const struct sk_buff *skb, unsigned int ip6hoff,
501 struct ipv6hdr _ip6h;
502 const struct ipv6hdr *ih;
504 unsigned int hdrlen = 0;
505 unsigned int logflags;
507 if (info->type == NF_LOG_TYPE_LOG)
508 logflags = info->u.log.logflags;
510 logflags = NF_LOG_MASK;
512 ih = skb_header_pointer(skb, ip6hoff, sizeof(_ip6h), &_ip6h);
514 sb_add(m, "TRUNCATED");
518 /* Max length: 88 "SRC=0000.0000.0000.0000.0000.0000.0000.0000 DST=0000.0000.0000.0000.0000.0000.0000.0000 " */
519 sb_add(m, "SRC=%pI6 DST=%pI6 ", &ih->saddr, &ih->daddr);
521 /* Max length: 44 "LEN=65535 TC=255 HOPLIMIT=255 FLOWLBL=FFFFF " */
522 sb_add(m, "LEN=%Zu TC=%u HOPLIMIT=%u FLOWLBL=%u ",
523 ntohs(ih->payload_len) + sizeof(struct ipv6hdr),
524 (ntohl(*(__be32 *)ih) & 0x0ff00000) >> 20,
526 (ntohl(*(__be32 *)ih) & 0x000fffff));
529 ptr = ip6hoff + sizeof(struct ipv6hdr);
530 currenthdr = ih->nexthdr;
531 while (currenthdr != NEXTHDR_NONE && ip6t_ext_hdr(currenthdr)) {
532 struct ipv6_opt_hdr _hdr;
533 const struct ipv6_opt_hdr *hp;
535 hp = skb_header_pointer(skb, ptr, sizeof(_hdr), &_hdr);
537 sb_add(m, "TRUNCATED");
541 /* Max length: 48 "OPT (...) " */
542 if (logflags & XT_LOG_IPOPT)
545 switch (currenthdr) {
546 case IPPROTO_FRAGMENT: {
547 struct frag_hdr _fhdr;
548 const struct frag_hdr *fh;
551 fh = skb_header_pointer(skb, ptr, sizeof(_fhdr),
554 sb_add(m, "TRUNCATED ");
558 /* Max length: 6 "65535 " */
559 sb_add(m, "%u ", ntohs(fh->frag_off) & 0xFFF8);
561 /* Max length: 11 "INCOMPLETE " */
562 if (fh->frag_off & htons(0x0001))
563 sb_add(m, "INCOMPLETE ");
565 sb_add(m, "ID:%08x ", ntohl(fh->identification));
567 if (ntohs(fh->frag_off) & 0xFFF8)
574 case IPPROTO_DSTOPTS:
575 case IPPROTO_ROUTING:
576 case IPPROTO_HOPOPTS:
578 if (logflags & XT_LOG_IPOPT)
582 hdrlen = ipv6_optlen(hp);
586 if (logflags & XT_LOG_IPOPT) {
587 struct ip_auth_hdr _ahdr;
588 const struct ip_auth_hdr *ah;
590 /* Max length: 3 "AH " */
598 ah = skb_header_pointer(skb, ptr, sizeof(_ahdr),
602 * Max length: 26 "INCOMPLETE [65535
605 sb_add(m, "INCOMPLETE [%u bytes] )",
610 /* Length: 15 "SPI=0xF1234567 */
611 sb_add(m, "SPI=0x%x ", ntohl(ah->spi));
615 hdrlen = (hp->hdrlen+2)<<2;
618 if (logflags & XT_LOG_IPOPT) {
619 struct ip_esp_hdr _esph;
620 const struct ip_esp_hdr *eh;
622 /* Max length: 4 "ESP " */
631 * Max length: 26 "INCOMPLETE [65535 bytes] )"
633 eh = skb_header_pointer(skb, ptr, sizeof(_esph),
636 sb_add(m, "INCOMPLETE [%u bytes] )",
641 /* Length: 16 "SPI=0xF1234567 )" */
642 sb_add(m, "SPI=0x%x )", ntohl(eh->spi));
647 /* Max length: 20 "Unknown Ext Hdr 255" */
648 sb_add(m, "Unknown Ext Hdr %u", currenthdr);
651 if (logflags & XT_LOG_IPOPT)
654 currenthdr = hp->nexthdr;
658 switch (currenthdr) {
660 if (dump_tcp_header(m, skb, currenthdr, fragment, ptr,
665 case IPPROTO_UDPLITE:
666 if (dump_udp_header(m, skb, currenthdr, fragment, ptr))
669 case IPPROTO_ICMPV6: {
670 struct icmp6hdr _icmp6h;
671 const struct icmp6hdr *ic;
673 /* Max length: 13 "PROTO=ICMPv6 " */
674 sb_add(m, "PROTO=ICMPv6 ");
679 /* Max length: 25 "INCOMPLETE [65535 bytes] " */
680 ic = skb_header_pointer(skb, ptr, sizeof(_icmp6h), &_icmp6h);
682 sb_add(m, "INCOMPLETE [%u bytes] ", skb->len - ptr);
686 /* Max length: 18 "TYPE=255 CODE=255 " */
687 sb_add(m, "TYPE=%u CODE=%u ", ic->icmp6_type, ic->icmp6_code);
689 switch (ic->icmp6_type) {
690 case ICMPV6_ECHO_REQUEST:
691 case ICMPV6_ECHO_REPLY:
692 /* Max length: 19 "ID=65535 SEQ=65535 " */
693 sb_add(m, "ID=%u SEQ=%u ",
694 ntohs(ic->icmp6_identifier),
695 ntohs(ic->icmp6_sequence));
697 case ICMPV6_MGM_QUERY:
698 case ICMPV6_MGM_REPORT:
699 case ICMPV6_MGM_REDUCTION:
702 case ICMPV6_PARAMPROB:
703 /* Max length: 17 "POINTER=ffffffff " */
704 sb_add(m, "POINTER=%08x ", ntohl(ic->icmp6_pointer));
706 case ICMPV6_DEST_UNREACH:
707 case ICMPV6_PKT_TOOBIG:
708 case ICMPV6_TIME_EXCEED:
709 /* Max length: 3+maxlen */
712 dump_ipv6_packet(m, info, skb,
713 ptr + sizeof(_icmp6h), 0);
717 /* Max length: 10 "MTU=65535 " */
718 if (ic->icmp6_type == ICMPV6_PKT_TOOBIG)
719 sb_add(m, "MTU=%u ", ntohl(ic->icmp6_mtu));
723 /* Max length: 10 "PROTO=255 " */
725 sb_add(m, "PROTO=%u ", currenthdr);
728 /* Max length: 15 "UID=4294967295 " */
729 if ((logflags & XT_LOG_UID) && recurse)
730 dump_sk_uid_gid(m, skb->sk);
732 /* Max length: 16 "MARK=0xFFFFFFFF " */
733 if (!recurse && skb->mark)
734 sb_add(m, "MARK=0x%x ", skb->mark);
737 static void dump_ipv6_mac_header(struct sbuff *m,
738 const struct nf_loginfo *info,
739 const struct sk_buff *skb)
741 struct net_device *dev = skb->dev;
742 unsigned int logflags = 0;
744 if (info->type == NF_LOG_TYPE_LOG)
745 logflags = info->u.log.logflags;
747 if (!(logflags & XT_LOG_MACDECODE))
752 sb_add(m, "MACSRC=%pM MACDST=%pM MACPROTO=%04x ",
753 eth_hdr(skb)->h_source, eth_hdr(skb)->h_dest,
754 ntohs(eth_hdr(skb)->h_proto));
762 if (dev->hard_header_len &&
763 skb->mac_header != skb->network_header) {
764 const unsigned char *p = skb_mac_header(skb);
765 unsigned int len = dev->hard_header_len;
768 if (dev->type == ARPHRD_SIT) {
776 sb_add(m, "%02x", *p++);
777 for (i = 1; i < len; i++)
778 sb_add(m, ":%02x", *p++);
782 if (dev->type == ARPHRD_SIT) {
783 const struct iphdr *iph =
784 (struct iphdr *)skb_mac_header(skb);
785 sb_add(m, "TUNNEL=%pI4->%pI4 ", &iph->saddr,
793 ip6t_log_packet(u_int8_t pf,
794 unsigned int hooknum,
795 const struct sk_buff *skb,
796 const struct net_device *in,
797 const struct net_device *out,
798 const struct nf_loginfo *loginfo,
801 struct sbuff *m = sb_open();
804 loginfo = &default_loginfo;
806 log_packet_common(m, pf, hooknum, skb, in, out, loginfo, prefix);
809 dump_ipv6_mac_header(m, loginfo, skb);
811 dump_ipv6_packet(m, loginfo, skb, skb_network_offset(skb), 1);
818 log_tg(struct sk_buff *skb, const struct xt_action_param *par)
820 const struct xt_log_info *loginfo = par->targinfo;
821 struct nf_loginfo li;
823 li.type = NF_LOG_TYPE_LOG;
824 li.u.log.level = loginfo->level;
825 li.u.log.logflags = loginfo->logflags;
827 if (par->family == NFPROTO_IPV4)
828 ipt_log_packet(NFPROTO_IPV4, par->hooknum, skb, par->in,
829 par->out, &li, loginfo->prefix);
830 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
831 else if (par->family == NFPROTO_IPV6)
832 ip6t_log_packet(NFPROTO_IPV6, par->hooknum, skb, par->in,
833 par->out, &li, loginfo->prefix);
841 static int log_tg_check(const struct xt_tgchk_param *par)
843 const struct xt_log_info *loginfo = par->targinfo;
845 if (par->family != NFPROTO_IPV4 && par->family != NFPROTO_IPV6)
848 if (loginfo->level >= 8) {
849 pr_debug("level %u >= 8\n", loginfo->level);
853 if (loginfo->prefix[sizeof(loginfo->prefix)-1] != '\0') {
854 pr_debug("prefix is not null-terminated\n");
861 static struct xt_target log_tg_regs[] __read_mostly = {
864 .family = NFPROTO_IPV4,
866 .targetsize = sizeof(struct xt_log_info),
867 .checkentry = log_tg_check,
870 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
873 .family = NFPROTO_IPV6,
875 .targetsize = sizeof(struct xt_log_info),
876 .checkentry = log_tg_check,
882 static struct nf_logger ipt_log_logger __read_mostly = {
884 .logfn = &ipt_log_packet,
888 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
889 static struct nf_logger ip6t_log_logger __read_mostly = {
891 .logfn = &ip6t_log_packet,
896 static int __init log_tg_init(void)
900 ret = xt_register_targets(log_tg_regs, ARRAY_SIZE(log_tg_regs));
904 nf_log_register(NFPROTO_IPV4, &ipt_log_logger);
905 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
906 nf_log_register(NFPROTO_IPV6, &ip6t_log_logger);
911 static void __exit log_tg_exit(void)
913 nf_log_unregister(&ipt_log_logger);
914 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
915 nf_log_unregister(&ip6t_log_logger);
917 xt_unregister_targets(log_tg_regs, ARRAY_SIZE(log_tg_regs));
920 module_init(log_tg_init);
921 module_exit(log_tg_exit);
923 MODULE_LICENSE("GPL");
924 MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
925 MODULE_AUTHOR("Jan Rekorajski <baggins@pld.org.pl>");
926 MODULE_DESCRIPTION("Xtables: IPv4/IPv6 packet logging");
927 MODULE_ALIAS("ipt_LOG");
928 MODULE_ALIAS("ip6t_LOG");