]> git.proxmox.com Git - mirror_ubuntu-disco-kernel.git/blame - net/netfilter/xt_LOG.c
netfilter: log: split family specific code to nf_log_{ip,ip6,common}.c files
[mirror_ubuntu-disco-kernel.git] / net / netfilter / xt_LOG.c
CommitLineData
6939c33a
RW
1/*
2 * This is a module which is used for logging packets.
3 */
4
5/* (C) 1999-2001 Paul `Rusty' Russell
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 */
12
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>
18#include <linux/ip.h>
19#include <net/ipv6.h>
20#include <net/icmp.h>
21#include <net/udp.h>
22#include <net/tcp.h>
23#include <net/route.h>
24
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>
6939c33a 30
6939c33a
RW
31static unsigned int
32log_tg(struct sk_buff *skb, const struct xt_action_param *par)
33{
34 const struct xt_log_info *loginfo = par->targinfo;
35 struct nf_loginfo li;
8cdb46da 36 struct net *net = dev_net(par->in ? par->in : par->out);
6939c33a
RW
37
38 li.type = NF_LOG_TYPE_LOG;
39 li.u.log.level = loginfo->level;
40 li.u.log.logflags = loginfo->logflags;
41
42 if (par->family == NFPROTO_IPV4)
83e96d44
PNA
43 nf_log_ip_packet(net, NFPROTO_IPV4, par->hooknum, skb, par->in,
44 par->out, &li, loginfo->prefix);
a0f65a26 45#if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
6939c33a 46 else if (par->family == NFPROTO_IPV6)
83e96d44
PNA
47 nf_log_ip6_packet(net, NFPROTO_IPV6, par->hooknum, skb, par->in,
48 par->out, &li, loginfo->prefix);
6939c33a
RW
49#endif
50 else
51 WARN_ON_ONCE(1);
52
53 return XT_CONTINUE;
54}
55
56static int log_tg_check(const struct xt_tgchk_param *par)
57{
58 const struct xt_log_info *loginfo = par->targinfo;
59
60 if (par->family != NFPROTO_IPV4 && par->family != NFPROTO_IPV6)
61 return -EINVAL;
62
63 if (loginfo->level >= 8) {
64 pr_debug("level %u >= 8\n", loginfo->level);
65 return -EINVAL;
66 }
67
68 if (loginfo->prefix[sizeof(loginfo->prefix)-1] != '\0') {
69 pr_debug("prefix is not null-terminated\n");
70 return -EINVAL;
71 }
72
73 return 0;
74}
75
76static struct xt_target log_tg_regs[] __read_mostly = {
77 {
78 .name = "LOG",
79 .family = NFPROTO_IPV4,
80 .target = log_tg,
81 .targetsize = sizeof(struct xt_log_info),
82 .checkentry = log_tg_check,
83 .me = THIS_MODULE,
84 },
a0f65a26 85#if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
6939c33a
RW
86 {
87 .name = "LOG",
88 .family = NFPROTO_IPV6,
89 .target = log_tg,
90 .targetsize = sizeof(struct xt_log_info),
91 .checkentry = log_tg_check,
92 .me = THIS_MODULE,
93 },
94#endif
95};
96
6939c33a
RW
97static int __init log_tg_init(void)
98{
83e96d44 99 return xt_register_targets(log_tg_regs, ARRAY_SIZE(log_tg_regs));
6939c33a
RW
100}
101
102static void __exit log_tg_exit(void)
103{
6939c33a
RW
104 xt_unregister_targets(log_tg_regs, ARRAY_SIZE(log_tg_regs));
105}
106
107module_init(log_tg_init);
108module_exit(log_tg_exit);
109
110MODULE_LICENSE("GPL");
111MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
112MODULE_AUTHOR("Jan Rekorajski <baggins@pld.org.pl>");
113MODULE_DESCRIPTION("Xtables: IPv4/IPv6 packet logging");
114MODULE_ALIAS("ipt_LOG");
115MODULE_ALIAS("ip6t_LOG");