[UDP]: Make full use of proto.h.udp_hash innovation.
[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
LT
11
12static struct
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
9335f047 39static struct xt_table packet_raw = {
e905a9ed
YH
40 .name = "raw",
41 .valid_hooks = RAW_VALID_HOOKS,
42 .lock = RW_LOCK_UNLOCKED,
2e4e6a17
HW
43 .me = THIS_MODULE,
44 .af = AF_INET,
1da177e4
LT
45};
46
47/* The work comes in here from netfilter.c. */
48static unsigned int
49ipt_hook(unsigned int hook,
3db05fea 50 struct sk_buff *skb,
1da177e4
LT
51 const struct net_device *in,
52 const struct net_device *out,
53 int (*okfn)(struct sk_buff *))
54{
9335f047 55 return ipt_do_table(skb, hook, in, out, init_net.ipv4.iptable_raw);
1da177e4
LT
56}
57
802169a4
PM
58static unsigned int
59ipt_local_hook(unsigned int hook,
3db05fea 60 struct sk_buff *skb,
802169a4
PM
61 const struct net_device *in,
62 const struct net_device *out,
63 int (*okfn)(struct sk_buff *))
64{
65 /* root is playing with raw sockets. */
3db05fea
HX
66 if (skb->len < sizeof(struct iphdr) ||
67 ip_hdrlen(skb) < sizeof(struct iphdr)) {
802169a4 68 if (net_ratelimit())
464c4f18 69 printk("iptable_raw: ignoring short SOCK_RAW "
802169a4
PM
70 "packet.\n");
71 return NF_ACCEPT;
72 }
9335f047 73 return ipt_do_table(skb, hook, in, out, init_net.ipv4.iptable_raw);
802169a4
PM
74}
75
1da177e4 76/* 'raw' is the very first table. */
1999414a 77static struct nf_hook_ops ipt_ops[] __read_mostly = {
1da177e4 78 {
964ddaa1
PM
79 .hook = ipt_hook,
80 .pf = PF_INET,
6e23ae2a 81 .hooknum = NF_INET_PRE_ROUTING,
964ddaa1
PM
82 .priority = NF_IP_PRI_RAW,
83 .owner = THIS_MODULE,
1da177e4
LT
84 },
85 {
802169a4 86 .hook = ipt_local_hook,
964ddaa1 87 .pf = PF_INET,
6e23ae2a 88 .hooknum = NF_INET_LOCAL_OUT,
964ddaa1
PM
89 .priority = NF_IP_PRI_RAW,
90 .owner = THIS_MODULE,
1da177e4
LT
91 },
92};
93
9335f047
AD
94static int __net_init iptable_raw_net_init(struct net *net)
95{
96 /* Register table */
97 net->ipv4.iptable_raw =
98 ipt_register_table(net, &packet_raw, &initial_table.repl);
99 if (IS_ERR(net->ipv4.iptable_raw))
100 return PTR_ERR(net->ipv4.iptable_raw);
101 return 0;
102}
103
104static void __net_exit iptable_raw_net_exit(struct net *net)
105{
106 ipt_unregister_table(net->ipv4.iptable_raw);
107}
108
109static struct pernet_operations iptable_raw_net_ops = {
110 .init = iptable_raw_net_init,
111 .exit = iptable_raw_net_exit,
112};
113
65b4b4e8 114static int __init iptable_raw_init(void)
1da177e4
LT
115{
116 int ret;
117
9335f047
AD
118 ret = register_pernet_subsys(&iptable_raw_net_ops);
119 if (ret < 0)
120 return ret;
1da177e4
LT
121
122 /* Register hooks */
964ddaa1 123 ret = nf_register_hooks(ipt_ops, ARRAY_SIZE(ipt_ops));
1da177e4
LT
124 if (ret < 0)
125 goto cleanup_table;
126
1da177e4
LT
127 return ret;
128
1da177e4 129 cleanup_table:
9335f047 130 unregister_pernet_subsys(&iptable_raw_net_ops);
1da177e4
LT
131 return ret;
132}
133
65b4b4e8 134static void __exit iptable_raw_fini(void)
1da177e4 135{
964ddaa1 136 nf_unregister_hooks(ipt_ops, ARRAY_SIZE(ipt_ops));
9335f047 137 unregister_pernet_subsys(&iptable_raw_net_ops);
1da177e4
LT
138}
139
65b4b4e8
AM
140module_init(iptable_raw_init);
141module_exit(iptable_raw_fini);
1da177e4 142MODULE_LICENSE("GPL");
This page took 0.409017 seconds and 5 git commands to generate.