blob: 3bfa6951164159a60183d99ba8f4f41753088f9e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Patrick McHardy6e23ae22007-11-19 18:53:30 -08009#define RAW_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_OUT))
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
Jan Engelhardt35aad0f2009-08-24 14:56:30 +020011static const struct
Linus Torvalds1da177e2005-04-16 15:20:36 -070012{
13 struct ip6t_replace repl;
14 struct ip6t_standard entries[2];
15 struct ip6t_error term;
Alexey Dobriyan8280aa62008-01-31 04:04:13 -080016} initial_table __net_initdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 .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 = {
Patrick McHardy6e23ae22007-11-19 18:53:30 -080023 [NF_INET_PRE_ROUTING] = 0,
24 [NF_INET_LOCAL_OUT] = sizeof(struct ip6t_standard)
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 },
26 .underflow = {
Patrick McHardy6e23ae22007-11-19 18:53:30 -080027 [NF_INET_PRE_ROUTING] = 0,
28 [NF_INET_LOCAL_OUT] = sizeof(struct ip6t_standard)
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 },
30 },
31 .entries = {
Patrick McHardy3c2ad462007-05-10 14:14:16 -070032 IP6T_STANDARD_INIT(NF_ACCEPT), /* PRE_ROUTING */
33 IP6T_STANDARD_INIT(NF_ACCEPT), /* LOCAL_OUT */
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 },
Patrick McHardy3c2ad462007-05-10 14:14:16 -070035 .term = IP6T_ERROR_INIT, /* ERROR */
Linus Torvalds1da177e2005-04-16 15:20:36 -070036};
37
Jan Engelhardt35aad0f2009-08-24 14:56:30 +020038static const struct xt_table packet_raw = {
YOSHIFUJI Hideaki1ab14572007-02-09 23:24:49 +090039 .name = "raw",
40 .valid_hooks = RAW_VALID_HOOKS,
Harald Welte2e4e6a12006-01-12 13:30:04 -080041 .me = THIS_MODULE,
Jan Engelhardtf88e6a82009-06-13 06:25:44 +020042 .af = NFPROTO_IPV6,
Jan Engelhardt2b95efe2009-06-17 13:57:48 +020043 .priority = NF_IP6_PRI_FIRST,
Linus Torvalds1da177e2005-04-16 15:20:36 -070044};
45
46/* The work comes in here from netfilter.c. */
47static unsigned int
Jan Engelhardt737535c2009-06-13 06:46:36 +020048ip6table_raw_hook(unsigned int hook, struct sk_buff *skb,
49 const struct net_device *in, const struct net_device *out,
50 int (*okfn)(struct sk_buff *))
Linus Torvalds1da177e2005-04-16 15:20:36 -070051{
Jan Engelhardt2b21e052009-06-13 06:57:10 +020052 const struct net *net = dev_net((in != NULL) ? in : out);
Alexey Dobriyan1339dd92008-10-08 11:35:01 +020053
Jan Engelhardt2b21e052009-06-13 06:57:10 +020054 return ip6t_do_table(skb, hook, in, out, net->ipv6.ip6table_raw);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055}
56
Jan Engelhardt2b95efe2009-06-17 13:57:48 +020057static struct nf_hook_ops *rawtable_ops __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Alexey Dobriyan8280aa62008-01-31 04:04:13 -080059static int __net_init ip6table_raw_net_init(struct net *net)
60{
61 /* Register table */
62 net->ipv6.ip6table_raw =
63 ip6t_register_table(net, &packet_raw, &initial_table.repl);
64 if (IS_ERR(net->ipv6.ip6table_raw))
65 return PTR_ERR(net->ipv6.ip6table_raw);
66 return 0;
67}
68
69static void __net_exit ip6table_raw_net_exit(struct net *net)
70{
Alexey Dobriyanf54e9362010-01-18 08:25:47 +010071 ip6t_unregister_table(net, net->ipv6.ip6table_raw);
Alexey Dobriyan8280aa62008-01-31 04:04:13 -080072}
73
74static struct pernet_operations ip6table_raw_net_ops = {
75 .init = ip6table_raw_net_init,
76 .exit = ip6table_raw_net_exit,
77};
78
Andrew Morton65b4b4e2006-03-28 16:37:06 -080079static int __init ip6table_raw_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080{
81 int ret;
82
Alexey Dobriyan8280aa62008-01-31 04:04:13 -080083 ret = register_pernet_subsys(&ip6table_raw_net_ops);
84 if (ret < 0)
85 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
87 /* Register hooks */
Jan Engelhardt2b95efe2009-06-17 13:57:48 +020088 rawtable_ops = xt_hook_link(&packet_raw, ip6table_raw_hook);
89 if (IS_ERR(rawtable_ops)) {
90 ret = PTR_ERR(rawtable_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 goto cleanup_table;
Jan Engelhardt2b95efe2009-06-17 13:57:48 +020092 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 return ret;
95
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 cleanup_table:
Alexey Dobriyan8280aa62008-01-31 04:04:13 -080097 unregister_pernet_subsys(&ip6table_raw_net_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 return ret;
99}
100
Andrew Morton65b4b4e2006-03-28 16:37:06 -0800101static void __exit ip6table_raw_fini(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102{
Jan Engelhardt2b95efe2009-06-17 13:57:48 +0200103 xt_hook_unlink(&packet_raw, rawtable_ops);
Alexey Dobriyan8280aa62008-01-31 04:04:13 -0800104 unregister_pernet_subsys(&ip6table_raw_net_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105}
106
Andrew Morton65b4b4e2006-03-28 16:37:06 -0800107module_init(ip6table_raw_init);
108module_exit(ip6table_raw_fini);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109MODULE_LICENSE("GPL");