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> | |
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 | 13 | static 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. */ | |
22 | static unsigned int | |
737535c5 JE |
23 | iptable_raw_hook(unsigned int hook, struct sk_buff *skb, |
24 | const struct net_device *in, const struct net_device *out, | |
25 | int (*okfn)(struct sk_buff *)) | |
1da177e4 | 26 | { |
2b21e051 | 27 | const struct net *net; |
1da177e4 | 28 | |
2b21e051 JE |
29 | if (hook == NF_INET_LOCAL_OUT && |
30 | (skb->len < sizeof(struct iphdr) || | |
31 | ip_hdrlen(skb) < sizeof(struct iphdr))) | |
32 | /* root is playing with raw sockets. */ | |
802169a4 | 33 | return NF_ACCEPT; |
2b21e051 JE |
34 | |
35 | net = dev_net((in != NULL) ? in : out); | |
36 | return ipt_do_table(skb, hook, in, out, net->ipv4.iptable_raw); | |
802169a4 PM |
37 | } |
38 | ||
2b95efe7 | 39 | static struct nf_hook_ops *rawtable_ops __read_mostly; |
1da177e4 | 40 | |
9335f047 AD |
41 | static int __net_init iptable_raw_net_init(struct net *net) |
42 | { | |
e3eaa991 JE |
43 | struct ipt_replace *repl; |
44 | ||
45 | repl = ipt_alloc_initial_table(&packet_raw); | |
46 | if (repl == NULL) | |
47 | return -ENOMEM; | |
9335f047 | 48 | net->ipv4.iptable_raw = |
e3eaa991 JE |
49 | ipt_register_table(net, &packet_raw, repl); |
50 | kfree(repl); | |
9335f047 AD |
51 | if (IS_ERR(net->ipv4.iptable_raw)) |
52 | return PTR_ERR(net->ipv4.iptable_raw); | |
53 | return 0; | |
54 | } | |
55 | ||
56 | static void __net_exit iptable_raw_net_exit(struct net *net) | |
57 | { | |
f54e9367 | 58 | ipt_unregister_table(net, net->ipv4.iptable_raw); |
9335f047 AD |
59 | } |
60 | ||
61 | static struct pernet_operations iptable_raw_net_ops = { | |
62 | .init = iptable_raw_net_init, | |
63 | .exit = iptable_raw_net_exit, | |
64 | }; | |
65 | ||
65b4b4e8 | 66 | static int __init iptable_raw_init(void) |
1da177e4 LT |
67 | { |
68 | int ret; | |
69 | ||
9335f047 AD |
70 | ret = register_pernet_subsys(&iptable_raw_net_ops); |
71 | if (ret < 0) | |
72 | return ret; | |
1da177e4 LT |
73 | |
74 | /* Register hooks */ | |
2b95efe7 JE |
75 | rawtable_ops = xt_hook_link(&packet_raw, iptable_raw_hook); |
76 | if (IS_ERR(rawtable_ops)) { | |
77 | ret = PTR_ERR(rawtable_ops); | |
1da177e4 | 78 | goto cleanup_table; |
2b95efe7 | 79 | } |
1da177e4 | 80 | |
1da177e4 LT |
81 | return ret; |
82 | ||
1da177e4 | 83 | cleanup_table: |
9335f047 | 84 | unregister_pernet_subsys(&iptable_raw_net_ops); |
1da177e4 LT |
85 | return ret; |
86 | } | |
87 | ||
65b4b4e8 | 88 | static void __exit iptable_raw_fini(void) |
1da177e4 | 89 | { |
2b95efe7 | 90 | xt_hook_unlink(&packet_raw, rawtable_ops); |
9335f047 | 91 | unregister_pernet_subsys(&iptable_raw_net_ops); |
1da177e4 LT |
92 | } |
93 | ||
65b4b4e8 AM |
94 | module_init(iptable_raw_init); |
95 | module_exit(iptable_raw_fini); | |
1da177e4 | 96 | MODULE_LICENSE("GPL"); |