blob: d4bc56443dc17e02a6674b7a90f13b2057ef8558 [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09008#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
Patrick McHardy6e23ae22007-11-19 18:53:30 -080010#define RAW_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_OUT))
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
Florian Westphalb9e69e12016-02-25 10:08:36 +010012static int __net_init ip6table_raw_table_init(struct net *net);
13
Jan Engelhardt35aad0f2009-08-24 14:56:30 +020014static const struct xt_table packet_raw = {
YOSHIFUJI Hideaki1ab14572007-02-09 23:24:49 +090015 .name = "raw",
16 .valid_hooks = RAW_VALID_HOOKS,
Harald Welte2e4e6a12006-01-12 13:30:04 -080017 .me = THIS_MODULE,
Jan Engelhardtf88e6a82009-06-13 06:25:44 +020018 .af = NFPROTO_IPV6,
Jozsef Kadlecsik9c138862010-03-25 11:17:26 +010019 .priority = NF_IP6_PRI_RAW,
Florian Westphalb9e69e12016-02-25 10:08:36 +010020 .table_init = ip6table_raw_table_init,
Linus Torvalds1da177e2005-04-16 15:20:36 -070021};
22
23/* The work comes in here from netfilter.c. */
24static unsigned int
Eric W. Biederman06198b32015-09-18 14:33:06 -050025ip6table_raw_hook(void *priv, struct sk_buff *skb,
David S. Miller238e54c2015-04-03 20:32:56 -040026 const struct nf_hook_state *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070027{
Eric W. Biederman6cb8ff3f12015-09-18 14:32:55 -050028 return ip6t_do_table(skb, state, state->net->ipv6.ip6table_raw);
Linus Torvalds1da177e2005-04-16 15:20:36 -070029}
30
Jan Engelhardt2b95efe2009-06-17 13:57:48 +020031static struct nf_hook_ops *rawtable_ops __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Florian Westphalb9e69e12016-02-25 10:08:36 +010033static int __net_init ip6table_raw_table_init(struct net *net)
Alexey Dobriyan8280aa62008-01-31 04:04:13 -080034{
Jan Engelhardte3eaa992009-06-17 22:14:54 +020035 struct ip6t_replace *repl;
Florian Westphala67dd262016-02-25 10:08:35 +010036 int ret;
Jan Engelhardte3eaa992009-06-17 22:14:54 +020037
Florian Westphalb9e69e12016-02-25 10:08:36 +010038 if (net->ipv6.ip6table_raw)
39 return 0;
40
Jan Engelhardte3eaa992009-06-17 22:14:54 +020041 repl = ip6t_alloc_initial_table(&packet_raw);
42 if (repl == NULL)
43 return -ENOMEM;
Florian Westphala67dd262016-02-25 10:08:35 +010044 ret = ip6t_register_table(net, &packet_raw, repl, rawtable_ops,
45 &net->ipv6.ip6table_raw);
Jan Engelhardte3eaa992009-06-17 22:14:54 +020046 kfree(repl);
Florian Westphala67dd262016-02-25 10:08:35 +010047 return ret;
Alexey Dobriyan8280aa62008-01-31 04:04:13 -080048}
49
50static void __net_exit ip6table_raw_net_exit(struct net *net)
51{
Florian Westphalb9e69e12016-02-25 10:08:36 +010052 if (!net->ipv6.ip6table_raw)
53 return;
Florian Westphala67dd262016-02-25 10:08:35 +010054 ip6t_unregister_table(net, net->ipv6.ip6table_raw, rawtable_ops);
Florian Westphalb9e69e12016-02-25 10:08:36 +010055 net->ipv6.ip6table_raw = NULL;
Alexey Dobriyan8280aa62008-01-31 04:04:13 -080056}
57
58static struct pernet_operations ip6table_raw_net_ops = {
Alexey Dobriyan8280aa62008-01-31 04:04:13 -080059 .exit = ip6table_raw_net_exit,
60};
61
Andrew Morton65b4b4e2006-03-28 16:37:06 -080062static int __init ip6table_raw_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063{
64 int ret;
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 /* Register hooks */
Florian Westphalb9e69e12016-02-25 10:08:36 +010067 rawtable_ops = xt_hook_ops_alloc(&packet_raw, ip6table_raw_hook);
68 if (IS_ERR(rawtable_ops))
69 return PTR_ERR(rawtable_ops);
70
71 ret = register_pernet_subsys(&ip6table_raw_net_ops);
72 if (ret < 0) {
73 kfree(rawtable_ops);
74 return ret;
Jan Engelhardt2b95efe2009-06-17 13:57:48 +020075 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Florian Westphalb9e69e12016-02-25 10:08:36 +010077 ret = ip6table_raw_table_init(&init_net);
78 if (ret) {
79 unregister_pernet_subsys(&ip6table_raw_net_ops);
80 kfree(rawtable_ops);
81 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 return ret;
83}
84
Andrew Morton65b4b4e2006-03-28 16:37:06 -080085static void __exit ip6table_raw_fini(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086{
Alexey Dobriyan8280aa62008-01-31 04:04:13 -080087 unregister_pernet_subsys(&ip6table_raw_net_ops);
Florian Westphalb9e69e12016-02-25 10:08:36 +010088 kfree(rawtable_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089}
90
Andrew Morton65b4b4e2006-03-28 16:37:06 -080091module_init(ip6table_raw_init);
92module_exit(ip6table_raw_fini);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093MODULE_LICENSE("GPL");