Merge tag 'linux-can-fixes-for-4.7-20160623' of git://git.kernel.org/pub/scm/linux...
[deliverable/linux.git] / net / ipv4 / netfilter / iptable_raw.c
CommitLineData
e905a9ed 1/*
1da177e4
LT
2 * 'raw' table, which is the very first hooked in at PRE_ROUTING and LOCAL_OUT .
3 *
4 * Copyright (C) 2003 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
5 */
6#include <linux/module.h>
7#include <linux/netfilter_ipv4/ip_tables.h>
5a0e3ad6 8#include <linux/slab.h>
802169a4 9#include <net/ip.h>
1da177e4 10
6e23ae2a 11#define RAW_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_OUT))
1da177e4 12
b9e69e12
FW
13static int __net_init iptable_raw_table_init(struct net *net);
14
35aad0ff 15static const struct xt_table packet_raw = {
e905a9ed
YH
16 .name = "raw",
17 .valid_hooks = RAW_VALID_HOOKS,
2e4e6a17 18 .me = THIS_MODULE,
f88e6a8a 19 .af = NFPROTO_IPV4,
2b95efe7 20 .priority = NF_IP_PRI_RAW,
b9e69e12 21 .table_init = iptable_raw_table_init,
1da177e4
LT
22};
23
24/* The work comes in here from netfilter.c. */
25static unsigned int
06198b34 26iptable_raw_hook(void *priv, struct sk_buff *skb,
238e54c9 27 const struct nf_hook_state *state)
1da177e4 28{
6cb8ff3f 29 if (state->hook == NF_INET_LOCAL_OUT &&
2b21e051
JE
30 (skb->len < sizeof(struct iphdr) ||
31 ip_hdrlen(skb) < sizeof(struct iphdr)))
32 /* root is playing with raw sockets. */
802169a4 33 return NF_ACCEPT;
2b21e051 34
6cb8ff3f 35 return ipt_do_table(skb, state, state->net->ipv4.iptable_raw);
802169a4
PM
36}
37
2b95efe7 38static struct nf_hook_ops *rawtable_ops __read_mostly;
1da177e4 39
b9e69e12 40static int __net_init iptable_raw_table_init(struct net *net)
9335f047 41{
e3eaa991 42 struct ipt_replace *repl;
a67dd266 43 int ret;
e3eaa991 44
b9e69e12
FW
45 if (net->ipv4.iptable_raw)
46 return 0;
47
e3eaa991
JE
48 repl = ipt_alloc_initial_table(&packet_raw);
49 if (repl == NULL)
50 return -ENOMEM;
a67dd266
FW
51 ret = ipt_register_table(net, &packet_raw, repl, rawtable_ops,
52 &net->ipv4.iptable_raw);
e3eaa991 53 kfree(repl);
a67dd266 54 return ret;
9335f047
AD
55}
56
57static void __net_exit iptable_raw_net_exit(struct net *net)
58{
b9e69e12
FW
59 if (!net->ipv4.iptable_raw)
60 return;
a67dd266 61 ipt_unregister_table(net, net->ipv4.iptable_raw, rawtable_ops);
b9e69e12 62 net->ipv4.iptable_raw = NULL;
9335f047
AD
63}
64
65static struct pernet_operations iptable_raw_net_ops = {
9335f047
AD
66 .exit = iptable_raw_net_exit,
67};
68
65b4b4e8 69static int __init iptable_raw_init(void)
1da177e4
LT
70{
71 int ret;
72
b9e69e12
FW
73 rawtable_ops = xt_hook_ops_alloc(&packet_raw, iptable_raw_hook);
74 if (IS_ERR(rawtable_ops))
75 return PTR_ERR(rawtable_ops);
76
9335f047 77 ret = register_pernet_subsys(&iptable_raw_net_ops);
b9e69e12
FW
78 if (ret < 0) {
79 kfree(rawtable_ops);
9335f047 80 return ret;
b9e69e12 81 }
1da177e4 82
b9e69e12
FW
83 ret = iptable_raw_table_init(&init_net);
84 if (ret) {
90efbed1 85 unregister_pernet_subsys(&iptable_raw_net_ops);
b9e69e12 86 kfree(rawtable_ops);
2b95efe7 87 }
1da177e4 88
1da177e4 89 return ret;
1da177e4
LT
90}
91
65b4b4e8 92static void __exit iptable_raw_fini(void)
1da177e4 93{
9335f047 94 unregister_pernet_subsys(&iptable_raw_net_ops);
b9e69e12 95 kfree(rawtable_ops);
1da177e4
LT
96}
97
65b4b4e8
AM
98module_init(iptable_raw_init);
99module_exit(iptable_raw_fini);
1da177e4 100MODULE_LICENSE("GPL");
This page took 1.004046 seconds and 5 git commands to generate.