octeontx2-pf: Fix error return code in otx2_probe()
[linux/fpc-iii.git] / net / netfilter / xt_LOG.c
bloba1e79b517c016b6c5b4be5891ee1e06c1718d116
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * This is a module which is used for logging packets.
4 */
6 /* (C) 1999-2001 Paul `Rusty' Russell
7 * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
8 */
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>
15 #include <linux/ip.h>
16 #include <net/ipv6.h>
17 #include <net/icmp.h>
18 #include <net/udp.h>
19 #include <net/tcp.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>
28 static unsigned int
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);
33 struct nf_loginfo li;
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);
41 return XT_CONTINUE;
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)
49 return -EINVAL;
51 if (loginfo->level >= 8) {
52 pr_debug("level %u >= 8\n", loginfo->level);
53 return -EINVAL;
56 if (loginfo->prefix[sizeof(loginfo->prefix)-1] != '\0') {
57 pr_debug("prefix is not null-terminated\n");
58 return -EINVAL;
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 = {
71 .name = "LOG",
72 .family = NFPROTO_IPV4,
73 .target = log_tg,
74 .targetsize = sizeof(struct xt_log_info),
75 .checkentry = log_tg_check,
76 .destroy = log_tg_destroy,
77 .me = THIS_MODULE,
79 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
81 .name = "LOG",
82 .family = NFPROTO_IPV6,
83 .target = log_tg,
84 .targetsize = sizeof(struct xt_log_info),
85 .checkentry = log_tg_check,
86 .destroy = log_tg_destroy,
87 .me = THIS_MODULE,
89 #endif
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");