netfilter: xtables: use xt_table for hook instantiation
[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>
802169a4 8#include <net/ip.h>
1da177e4 9
6e23ae2a 10#define RAW_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_OUT))
1da177e4 11
35aad0ff 12static const struct
1da177e4
LT
13{
14 struct ipt_replace repl;
15 struct ipt_standard entries[2];
16 struct ipt_error term;
9335f047 17} initial_table __net_initdata = {
1da177e4 18 .repl = {
e905a9ed
YH
19 .name = "raw",
20 .valid_hooks = RAW_VALID_HOOKS,
1da177e4
LT
21 .num_entries = 3,
22 .size = sizeof(struct ipt_standard) * 2 + sizeof(struct ipt_error),
e905a9ed 23 .hook_entry = {
6e23ae2a
PM
24 [NF_INET_PRE_ROUTING] = 0,
25 [NF_INET_LOCAL_OUT] = sizeof(struct ipt_standard)
3c2ad469 26 },
e905a9ed 27 .underflow = {
6e23ae2a
PM
28 [NF_INET_PRE_ROUTING] = 0,
29 [NF_INET_LOCAL_OUT] = sizeof(struct ipt_standard)
3c2ad469 30 },
1da177e4
LT
31 },
32 .entries = {
3c2ad469
PM
33 IPT_STANDARD_INIT(NF_ACCEPT), /* PRE_ROUTING */
34 IPT_STANDARD_INIT(NF_ACCEPT), /* LOCAL_OUT */
1da177e4 35 },
3c2ad469 36 .term = IPT_ERROR_INIT, /* ERROR */
1da177e4
LT
37};
38
35aad0ff 39static const struct xt_table packet_raw = {
e905a9ed
YH
40 .name = "raw",
41 .valid_hooks = RAW_VALID_HOOKS,
2e4e6a17 42 .me = THIS_MODULE,
f88e6a8a 43 .af = NFPROTO_IPV4,
2b95efe7 44 .priority = NF_IP_PRI_RAW,
1da177e4
LT
45};
46
47/* The work comes in here from netfilter.c. */
48static unsigned int
737535c5
JE
49iptable_raw_hook(unsigned int hook, struct sk_buff *skb,
50 const struct net_device *in, const struct net_device *out,
51 int (*okfn)(struct sk_buff *))
1da177e4 52{
2b21e051 53 const struct net *net;
1da177e4 54
2b21e051
JE
55 if (hook == NF_INET_LOCAL_OUT &&
56 (skb->len < sizeof(struct iphdr) ||
57 ip_hdrlen(skb) < sizeof(struct iphdr)))
58 /* root is playing with raw sockets. */
802169a4 59 return NF_ACCEPT;
2b21e051
JE
60
61 net = dev_net((in != NULL) ? in : out);
62 return ipt_do_table(skb, hook, in, out, net->ipv4.iptable_raw);
802169a4
PM
63}
64
2b95efe7 65static struct nf_hook_ops *rawtable_ops __read_mostly;
1da177e4 66
9335f047
AD
67static int __net_init iptable_raw_net_init(struct net *net)
68{
69 /* Register table */
70 net->ipv4.iptable_raw =
71 ipt_register_table(net, &packet_raw, &initial_table.repl);
72 if (IS_ERR(net->ipv4.iptable_raw))
73 return PTR_ERR(net->ipv4.iptable_raw);
74 return 0;
75}
76
77static void __net_exit iptable_raw_net_exit(struct net *net)
78{
f54e9367 79 ipt_unregister_table(net, net->ipv4.iptable_raw);
9335f047
AD
80}
81
82static struct pernet_operations iptable_raw_net_ops = {
83 .init = iptable_raw_net_init,
84 .exit = iptable_raw_net_exit,
85};
86
65b4b4e8 87static int __init iptable_raw_init(void)
1da177e4
LT
88{
89 int ret;
90
9335f047
AD
91 ret = register_pernet_subsys(&iptable_raw_net_ops);
92 if (ret < 0)
93 return ret;
1da177e4
LT
94
95 /* Register hooks */
2b95efe7
JE
96 rawtable_ops = xt_hook_link(&packet_raw, iptable_raw_hook);
97 if (IS_ERR(rawtable_ops)) {
98 ret = PTR_ERR(rawtable_ops);
1da177e4 99 goto cleanup_table;
2b95efe7 100 }
1da177e4 101
1da177e4
LT
102 return ret;
103
1da177e4 104 cleanup_table:
9335f047 105 unregister_pernet_subsys(&iptable_raw_net_ops);
1da177e4
LT
106 return ret;
107}
108
65b4b4e8 109static void __exit iptable_raw_fini(void)
1da177e4 110{
2b95efe7 111 xt_hook_unlink(&packet_raw, rawtable_ops);
9335f047 112 unregister_pernet_subsys(&iptable_raw_net_ops);
1da177e4
LT
113}
114
65b4b4e8
AM
115module_init(iptable_raw_init);
116module_exit(iptable_raw_fini);
1da177e4 117MODULE_LICENSE("GPL");
This page took 0.529897 seconds and 5 git commands to generate.