Merge git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-unstable
[linux-2.6/mini2440.git] / net / ipv4 / netfilter / iptable_raw.c
blobe5356da1fb543093d943a07ef92181a5ad0311b5
1 /*
2 * 'raw' table, which is the very first hooked in at PRE_ROUTING and LOCAL_OUT .
4 * Copyright (C) 2003 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
5 */
6 #include <linux/module.h>
7 #include <linux/netfilter_ipv4/ip_tables.h>
8 #include <net/ip.h>
10 #define RAW_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_OUT))
12 static struct
14 struct ipt_replace repl;
15 struct ipt_standard entries[2];
16 struct ipt_error term;
17 } initial_table __net_initdata = {
18 .repl = {
19 .name = "raw",
20 .valid_hooks = RAW_VALID_HOOKS,
21 .num_entries = 3,
22 .size = sizeof(struct ipt_standard) * 2 + sizeof(struct ipt_error),
23 .hook_entry = {
24 [NF_INET_PRE_ROUTING] = 0,
25 [NF_INET_LOCAL_OUT] = sizeof(struct ipt_standard)
27 .underflow = {
28 [NF_INET_PRE_ROUTING] = 0,
29 [NF_INET_LOCAL_OUT] = sizeof(struct ipt_standard)
32 .entries = {
33 IPT_STANDARD_INIT(NF_ACCEPT), /* PRE_ROUTING */
34 IPT_STANDARD_INIT(NF_ACCEPT), /* LOCAL_OUT */
36 .term = IPT_ERROR_INIT, /* ERROR */
39 static struct xt_table packet_raw = {
40 .name = "raw",
41 .valid_hooks = RAW_VALID_HOOKS,
42 .me = THIS_MODULE,
43 .af = AF_INET,
46 /* The work comes in here from netfilter.c. */
47 static unsigned int
48 ipt_hook(unsigned int hook,
49 struct sk_buff *skb,
50 const struct net_device *in,
51 const struct net_device *out,
52 int (*okfn)(struct sk_buff *))
54 return ipt_do_table(skb, hook, in, out,
55 dev_net(in)->ipv4.iptable_raw);
58 static unsigned int
59 ipt_local_hook(unsigned int hook,
60 struct sk_buff *skb,
61 const struct net_device *in,
62 const struct net_device *out,
63 int (*okfn)(struct sk_buff *))
65 /* root is playing with raw sockets. */
66 if (skb->len < sizeof(struct iphdr) ||
67 ip_hdrlen(skb) < sizeof(struct iphdr))
68 return NF_ACCEPT;
69 return ipt_do_table(skb, hook, in, out,
70 dev_net(out)->ipv4.iptable_raw);
73 /* 'raw' is the very first table. */
74 static struct nf_hook_ops ipt_ops[] __read_mostly = {
76 .hook = ipt_hook,
77 .pf = PF_INET,
78 .hooknum = NF_INET_PRE_ROUTING,
79 .priority = NF_IP_PRI_RAW,
80 .owner = THIS_MODULE,
83 .hook = ipt_local_hook,
84 .pf = PF_INET,
85 .hooknum = NF_INET_LOCAL_OUT,
86 .priority = NF_IP_PRI_RAW,
87 .owner = THIS_MODULE,
91 static int __net_init iptable_raw_net_init(struct net *net)
93 /* Register table */
94 net->ipv4.iptable_raw =
95 ipt_register_table(net, &packet_raw, &initial_table.repl);
96 if (IS_ERR(net->ipv4.iptable_raw))
97 return PTR_ERR(net->ipv4.iptable_raw);
98 return 0;
101 static void __net_exit iptable_raw_net_exit(struct net *net)
103 ipt_unregister_table(net->ipv4.iptable_raw);
106 static struct pernet_operations iptable_raw_net_ops = {
107 .init = iptable_raw_net_init,
108 .exit = iptable_raw_net_exit,
111 static int __init iptable_raw_init(void)
113 int ret;
115 ret = register_pernet_subsys(&iptable_raw_net_ops);
116 if (ret < 0)
117 return ret;
119 /* Register hooks */
120 ret = nf_register_hooks(ipt_ops, ARRAY_SIZE(ipt_ops));
121 if (ret < 0)
122 goto cleanup_table;
124 return ret;
126 cleanup_table:
127 unregister_pernet_subsys(&iptable_raw_net_ops);
128 return ret;
131 static void __exit iptable_raw_fini(void)
133 nf_unregister_hooks(ipt_ops, ARRAY_SIZE(ipt_ops));
134 unregister_pernet_subsys(&iptable_raw_net_ops);
137 module_init(iptable_raw_init);
138 module_exit(iptable_raw_fini);
139 MODULE_LICENSE("GPL");