]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - net/ipv4/netfilter/iptable_raw.c
Merge branches 'arm/omap', 'arm/msm', 'arm/smmu', 'arm/tegra', 'x86/vt-d', 'x86/amd...
[mirror_ubuntu-artful-kernel.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
35aad0ff 13static const struct xt_table packet_raw = {
e905a9ed
YH
14 .name = "raw",
15 .valid_hooks = RAW_VALID_HOOKS,
2e4e6a17 16 .me = THIS_MODULE,
f88e6a8a 17 .af = NFPROTO_IPV4,
2b95efe7 18 .priority = NF_IP_PRI_RAW,
1da177e4
LT
19};
20
21/* The work comes in here from netfilter.c. */
22static unsigned int
795aa6ef 23iptable_raw_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
238e54c9 24 const struct nf_hook_state *state)
1da177e4 25{
2b21e051 26 const struct net *net;
1da177e4 27
795aa6ef 28 if (ops->hooknum == NF_INET_LOCAL_OUT &&
2b21e051
JE
29 (skb->len < sizeof(struct iphdr) ||
30 ip_hdrlen(skb) < sizeof(struct iphdr)))
31 /* root is playing with raw sockets. */
802169a4 32 return NF_ACCEPT;
2b21e051 33
238e54c9 34 net = dev_net(state->in ? state->in : state->out);
1c491ba2 35 return ipt_do_table(skb, ops->hooknum, state, net->ipv4.iptable_raw);
802169a4
PM
36}
37
2b95efe7 38static struct nf_hook_ops *rawtable_ops __read_mostly;
1da177e4 39
9335f047
AD
40static int __net_init iptable_raw_net_init(struct net *net)
41{
e3eaa991
JE
42 struct ipt_replace *repl;
43
44 repl = ipt_alloc_initial_table(&packet_raw);
45 if (repl == NULL)
46 return -ENOMEM;
9335f047 47 net->ipv4.iptable_raw =
e3eaa991
JE
48 ipt_register_table(net, &packet_raw, repl);
49 kfree(repl);
8c6ffba0 50 return PTR_ERR_OR_ZERO(net->ipv4.iptable_raw);
9335f047
AD
51}
52
53static void __net_exit iptable_raw_net_exit(struct net *net)
54{
f54e9367 55 ipt_unregister_table(net, net->ipv4.iptable_raw);
9335f047
AD
56}
57
58static struct pernet_operations iptable_raw_net_ops = {
59 .init = iptable_raw_net_init,
60 .exit = iptable_raw_net_exit,
61};
62
65b4b4e8 63static int __init iptable_raw_init(void)
1da177e4
LT
64{
65 int ret;
66
9335f047
AD
67 ret = register_pernet_subsys(&iptable_raw_net_ops);
68 if (ret < 0)
69 return ret;
1da177e4
LT
70
71 /* Register hooks */
2b95efe7
JE
72 rawtable_ops = xt_hook_link(&packet_raw, iptable_raw_hook);
73 if (IS_ERR(rawtable_ops)) {
74 ret = PTR_ERR(rawtable_ops);
90efbed1 75 unregister_pernet_subsys(&iptable_raw_net_ops);
2b95efe7 76 }
1da177e4 77
1da177e4 78 return ret;
1da177e4
LT
79}
80
65b4b4e8 81static void __exit iptable_raw_fini(void)
1da177e4 82{
2b95efe7 83 xt_hook_unlink(&packet_raw, rawtable_ops);
9335f047 84 unregister_pernet_subsys(&iptable_raw_net_ops);
1da177e4
LT
85}
86
65b4b4e8
AM
87module_init(iptable_raw_init);
88module_exit(iptable_raw_fini);
1da177e4 89MODULE_LICENSE("GPL");