1 // SPDX-License-Identifier: GPL-2.0-only
3 * This is a module which is used for logging packets.
6 /* (C) 1999-2001 Paul `Rusty' Russell
7 * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
10 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
11 #include <linux/module.h>
12 #include <linux/spinlock.h>
13 #include <linux/skbuff.h>
14 #include <linux/if_arp.h>
20 #include <net/route.h>
22 #include <linux/netfilter.h>
23 #include <linux/netfilter/x_tables.h>
24 #include <linux/netfilter/xt_LOG.h>
25 #include <linux/netfilter_ipv6/ip6_tables.h>
26 #include <net/netfilter/nf_log.h>
29 log_tg(struct sk_buff
*skb
, const struct xt_action_param
*par
)
31 const struct xt_log_info
*loginfo
= par
->targinfo
;
32 struct net
*net
= xt_net(par
);
35 li
.type
= NF_LOG_TYPE_LOG
;
36 li
.u
.log
.level
= loginfo
->level
;
37 li
.u
.log
.logflags
= loginfo
->logflags
;
39 nf_log_packet(net
, xt_family(par
), xt_hooknum(par
), skb
, xt_in(par
),
40 xt_out(par
), &li
, "%s", loginfo
->prefix
);
44 static int log_tg_check(const struct xt_tgchk_param
*par
)
46 const struct xt_log_info
*loginfo
= par
->targinfo
;
48 if (par
->family
!= NFPROTO_IPV4
&& par
->family
!= NFPROTO_IPV6
)
51 if (loginfo
->level
>= 8) {
52 pr_debug("level %u >= 8\n", loginfo
->level
);
56 if (loginfo
->prefix
[sizeof(loginfo
->prefix
)-1] != '\0') {
57 pr_debug("prefix is not null-terminated\n");
61 return nf_logger_find_get(par
->family
, NF_LOG_TYPE_LOG
);
64 static void log_tg_destroy(const struct xt_tgdtor_param
*par
)
66 nf_logger_put(par
->family
, NF_LOG_TYPE_LOG
);
69 static struct xt_target log_tg_regs
[] __read_mostly
= {
72 .family
= NFPROTO_IPV4
,
74 .targetsize
= sizeof(struct xt_log_info
),
75 .checkentry
= log_tg_check
,
76 .destroy
= log_tg_destroy
,
79 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
82 .family
= NFPROTO_IPV6
,
84 .targetsize
= sizeof(struct xt_log_info
),
85 .checkentry
= log_tg_check
,
86 .destroy
= log_tg_destroy
,
92 static int __init
log_tg_init(void)
94 return xt_register_targets(log_tg_regs
, ARRAY_SIZE(log_tg_regs
));
97 static void __exit
log_tg_exit(void)
99 xt_unregister_targets(log_tg_regs
, ARRAY_SIZE(log_tg_regs
));
102 module_init(log_tg_init
);
103 module_exit(log_tg_exit
);
105 MODULE_LICENSE("GPL");
106 MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
107 MODULE_AUTHOR("Jan Rekorajski <baggins@pld.org.pl>");
108 MODULE_DESCRIPTION("Xtables: IPv4/IPv6 packet logging");
109 MODULE_ALIAS("ipt_LOG");
110 MODULE_ALIAS("ip6t_LOG");