Commit | Line | Data |
---|---|---|
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 | 12 | static const struct xt_table packet_raw = { |
e905a9ed YH |
13 | .name = "raw", |
14 | .valid_hooks = RAW_VALID_HOOKS, | |
2e4e6a17 | 15 | .me = THIS_MODULE, |
f88e6a8a | 16 | .af = NFPROTO_IPV4, |
2b95efe7 | 17 | .priority = NF_IP_PRI_RAW, |
1da177e4 LT |
18 | }; |
19 | ||
20 | /* The work comes in here from netfilter.c. */ | |
21 | static unsigned int | |
737535c5 JE |
22 | iptable_raw_hook(unsigned int hook, struct sk_buff *skb, |
23 | const struct net_device *in, const struct net_device *out, | |
24 | int (*okfn)(struct sk_buff *)) | |
1da177e4 | 25 | { |
2b21e051 | 26 | const struct net *net; |
1da177e4 | 27 | |
2b21e051 JE |
28 | if (hook == NF_INET_LOCAL_OUT && |
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 JE |
33 | |
34 | net = dev_net((in != NULL) ? in : out); | |
35 | return ipt_do_table(skb, hook, in, out, net->ipv4.iptable_raw); | |
802169a4 PM |
36 | } |
37 | ||
2b95efe7 | 38 | static struct nf_hook_ops *rawtable_ops __read_mostly; |
1da177e4 | 39 | |
9335f047 AD |
40 | static 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); | |
9335f047 AD |
50 | if (IS_ERR(net->ipv4.iptable_raw)) |
51 | return PTR_ERR(net->ipv4.iptable_raw); | |
52 | return 0; | |
53 | } | |
54 | ||
55 | static void __net_exit iptable_raw_net_exit(struct net *net) | |
56 | { | |
f54e9367 | 57 | ipt_unregister_table(net, net->ipv4.iptable_raw); |
9335f047 AD |
58 | } |
59 | ||
60 | static struct pernet_operations iptable_raw_net_ops = { | |
61 | .init = iptable_raw_net_init, | |
62 | .exit = iptable_raw_net_exit, | |
63 | }; | |
64 | ||
65b4b4e8 | 65 | static int __init iptable_raw_init(void) |
1da177e4 LT |
66 | { |
67 | int ret; | |
68 | ||
9335f047 AD |
69 | ret = register_pernet_subsys(&iptable_raw_net_ops); |
70 | if (ret < 0) | |
71 | return ret; | |
1da177e4 LT |
72 | |
73 | /* Register hooks */ | |
2b95efe7 JE |
74 | rawtable_ops = xt_hook_link(&packet_raw, iptable_raw_hook); |
75 | if (IS_ERR(rawtable_ops)) { | |
76 | ret = PTR_ERR(rawtable_ops); | |
1da177e4 | 77 | goto cleanup_table; |
2b95efe7 | 78 | } |
1da177e4 | 79 | |
1da177e4 LT |
80 | return ret; |
81 | ||
1da177e4 | 82 | cleanup_table: |
9335f047 | 83 | unregister_pernet_subsys(&iptable_raw_net_ops); |
1da177e4 LT |
84 | return ret; |
85 | } | |
86 | ||
65b4b4e8 | 87 | static void __exit iptable_raw_fini(void) |
1da177e4 | 88 | { |
2b95efe7 | 89 | xt_hook_unlink(&packet_raw, rawtable_ops); |
9335f047 | 90 | unregister_pernet_subsys(&iptable_raw_net_ops); |
1da177e4 LT |
91 | } |
92 | ||
65b4b4e8 AM |
93 | module_init(iptable_raw_init); |
94 | module_exit(iptable_raw_fini); | |
1da177e4 | 95 | MODULE_LICENSE("GPL"); |