Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * IPv6 raw table, a port of the IPv4 raw table to IPv6 | |
3 | * | |
4 | * Copyright (C) 2003 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu> | |
5 | */ | |
6 | #include <linux/module.h> | |
7 | #include <linux/netfilter_ipv6/ip6_tables.h> | |
8 | ||
6e23ae2a | 9 | #define RAW_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_OUT)) |
1da177e4 | 10 | |
35aad0ff | 11 | static const struct |
1da177e4 LT |
12 | { |
13 | struct ip6t_replace repl; | |
14 | struct ip6t_standard entries[2]; | |
15 | struct ip6t_error term; | |
8280aa61 | 16 | } initial_table __net_initdata = { |
1da177e4 LT |
17 | .repl = { |
18 | .name = "raw", | |
19 | .valid_hooks = RAW_VALID_HOOKS, | |
20 | .num_entries = 3, | |
21 | .size = sizeof(struct ip6t_standard) * 2 + sizeof(struct ip6t_error), | |
22 | .hook_entry = { | |
6e23ae2a PM |
23 | [NF_INET_PRE_ROUTING] = 0, |
24 | [NF_INET_LOCAL_OUT] = sizeof(struct ip6t_standard) | |
1da177e4 LT |
25 | }, |
26 | .underflow = { | |
6e23ae2a PM |
27 | [NF_INET_PRE_ROUTING] = 0, |
28 | [NF_INET_LOCAL_OUT] = sizeof(struct ip6t_standard) | |
1da177e4 LT |
29 | }, |
30 | }, | |
31 | .entries = { | |
3c2ad469 PM |
32 | IP6T_STANDARD_INIT(NF_ACCEPT), /* PRE_ROUTING */ |
33 | IP6T_STANDARD_INIT(NF_ACCEPT), /* LOCAL_OUT */ | |
1da177e4 | 34 | }, |
3c2ad469 | 35 | .term = IP6T_ERROR_INIT, /* ERROR */ |
1da177e4 LT |
36 | }; |
37 | ||
35aad0ff | 38 | static const struct xt_table packet_raw = { |
1ab1457c YH |
39 | .name = "raw", |
40 | .valid_hooks = RAW_VALID_HOOKS, | |
2e4e6a17 | 41 | .me = THIS_MODULE, |
f88e6a8a | 42 | .af = NFPROTO_IPV6, |
1da177e4 LT |
43 | }; |
44 | ||
45 | /* The work comes in here from netfilter.c. */ | |
46 | static unsigned int | |
737535c5 JE |
47 | ip6table_raw_hook(unsigned int hook, struct sk_buff *skb, |
48 | const struct net_device *in, const struct net_device *out, | |
49 | int (*okfn)(struct sk_buff *)) | |
1da177e4 | 50 | { |
2b21e051 | 51 | const struct net *net = dev_net((in != NULL) ? in : out); |
1339dd91 | 52 | |
2b21e051 | 53 | return ip6t_do_table(skb, hook, in, out, net->ipv6.ip6table_raw); |
1da177e4 LT |
54 | } |
55 | ||
1999414a | 56 | static struct nf_hook_ops ip6t_ops[] __read_mostly = { |
1da177e4 | 57 | { |
737535c5 | 58 | .hook = ip6table_raw_hook, |
24c232d8 | 59 | .pf = NFPROTO_IPV6, |
6e23ae2a | 60 | .hooknum = NF_INET_PRE_ROUTING, |
97216c79 PM |
61 | .priority = NF_IP6_PRI_FIRST, |
62 | .owner = THIS_MODULE, | |
1da177e4 LT |
63 | }, |
64 | { | |
737535c5 | 65 | .hook = ip6table_raw_hook, |
24c232d8 | 66 | .pf = NFPROTO_IPV6, |
6e23ae2a | 67 | .hooknum = NF_INET_LOCAL_OUT, |
97216c79 PM |
68 | .priority = NF_IP6_PRI_FIRST, |
69 | .owner = THIS_MODULE, | |
1da177e4 LT |
70 | }, |
71 | }; | |
72 | ||
8280aa61 AD |
73 | static int __net_init ip6table_raw_net_init(struct net *net) |
74 | { | |
75 | /* Register table */ | |
76 | net->ipv6.ip6table_raw = | |
77 | ip6t_register_table(net, &packet_raw, &initial_table.repl); | |
78 | if (IS_ERR(net->ipv6.ip6table_raw)) | |
79 | return PTR_ERR(net->ipv6.ip6table_raw); | |
80 | return 0; | |
81 | } | |
82 | ||
83 | static void __net_exit ip6table_raw_net_exit(struct net *net) | |
84 | { | |
f54e9367 | 85 | ip6t_unregister_table(net, net->ipv6.ip6table_raw); |
8280aa61 AD |
86 | } |
87 | ||
88 | static struct pernet_operations ip6table_raw_net_ops = { | |
89 | .init = ip6table_raw_net_init, | |
90 | .exit = ip6table_raw_net_exit, | |
91 | }; | |
92 | ||
65b4b4e8 | 93 | static int __init ip6table_raw_init(void) |
1da177e4 LT |
94 | { |
95 | int ret; | |
96 | ||
8280aa61 AD |
97 | ret = register_pernet_subsys(&ip6table_raw_net_ops); |
98 | if (ret < 0) | |
99 | return ret; | |
1da177e4 LT |
100 | |
101 | /* Register hooks */ | |
964ddaa1 | 102 | ret = nf_register_hooks(ip6t_ops, ARRAY_SIZE(ip6t_ops)); |
1da177e4 LT |
103 | if (ret < 0) |
104 | goto cleanup_table; | |
105 | ||
1da177e4 LT |
106 | return ret; |
107 | ||
1da177e4 | 108 | cleanup_table: |
8280aa61 | 109 | unregister_pernet_subsys(&ip6table_raw_net_ops); |
1da177e4 LT |
110 | return ret; |
111 | } | |
112 | ||
65b4b4e8 | 113 | static void __exit ip6table_raw_fini(void) |
1da177e4 | 114 | { |
964ddaa1 | 115 | nf_unregister_hooks(ip6t_ops, ARRAY_SIZE(ip6t_ops)); |
8280aa61 | 116 | unregister_pernet_subsys(&ip6table_raw_net_ops); |
1da177e4 LT |
117 | } |
118 | ||
65b4b4e8 AM |
119 | module_init(ip6table_raw_init); |
120 | module_exit(ip6table_raw_fini); | |
1da177e4 | 121 | MODULE_LICENSE("GPL"); |