blob: 5b9926a011bd99faff714042746f161ee58a152a [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
Jan Engelhardt35aad0f2009-08-24 14:56:30 +020012static const struct xt_table packet_raw = {
YOSHIFUJI Hideaki1ab14572007-02-09 23:24:49 +090013 .name = "raw",
14 .valid_hooks = RAW_VALID_HOOKS,
Harald Welte2e4e6a12006-01-12 13:30:04 -080015 .me = THIS_MODULE,
Jan Engelhardtf88e6a82009-06-13 06:25:44 +020016 .af = NFPROTO_IPV6,
Jozsef Kadlecsik9c138862010-03-25 11:17:26 +010017 .priority = NF_IP6_PRI_RAW,
Linus Torvalds1da177e2005-04-16 15:20:36 -070018};
19
20/* The work comes in here from netfilter.c. */
21static unsigned int
Jan Engelhardt737535c2009-06-13 06:46:36 +020022ip6table_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 *))
Linus Torvalds1da177e2005-04-16 15:20:36 -070025{
Jan Engelhardt2b21e052009-06-13 06:57:10 +020026 const struct net *net = dev_net((in != NULL) ? in : out);
Alexey Dobriyan1339dd92008-10-08 11:35:01 +020027
Jan Engelhardt2b21e052009-06-13 06:57:10 +020028 return ip6t_do_table(skb, hook, in, out, 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
Alexey Dobriyan8280aa62008-01-31 04:04:13 -080033static int __net_init ip6table_raw_net_init(struct net *net)
34{
Jan Engelhardte3eaa992009-06-17 22:14:54 +020035 struct ip6t_replace *repl;
36
37 repl = ip6t_alloc_initial_table(&packet_raw);
38 if (repl == NULL)
39 return -ENOMEM;
Alexey Dobriyan8280aa62008-01-31 04:04:13 -080040 net->ipv6.ip6table_raw =
Jan Engelhardte3eaa992009-06-17 22:14:54 +020041 ip6t_register_table(net, &packet_raw, repl);
42 kfree(repl);
Alexey Dobriyan8280aa62008-01-31 04:04:13 -080043 if (IS_ERR(net->ipv6.ip6table_raw))
44 return PTR_ERR(net->ipv6.ip6table_raw);
45 return 0;
46}
47
48static void __net_exit ip6table_raw_net_exit(struct net *net)
49{
Alexey Dobriyanf54e9362010-01-18 08:25:47 +010050 ip6t_unregister_table(net, net->ipv6.ip6table_raw);
Alexey Dobriyan8280aa62008-01-31 04:04:13 -080051}
52
53static struct pernet_operations ip6table_raw_net_ops = {
54 .init = ip6table_raw_net_init,
55 .exit = ip6table_raw_net_exit,
56};
57
Andrew Morton65b4b4e2006-03-28 16:37:06 -080058static int __init ip6table_raw_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059{
60 int ret;
61
Alexey Dobriyan8280aa62008-01-31 04:04:13 -080062 ret = register_pernet_subsys(&ip6table_raw_net_ops);
63 if (ret < 0)
64 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66 /* Register hooks */
Jan Engelhardt2b95efe2009-06-17 13:57:48 +020067 rawtable_ops = xt_hook_link(&packet_raw, ip6table_raw_hook);
68 if (IS_ERR(rawtable_ops)) {
69 ret = PTR_ERR(rawtable_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 goto cleanup_table;
Jan Engelhardt2b95efe2009-06-17 13:57:48 +020071 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 return ret;
74
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 cleanup_table:
Alexey Dobriyan8280aa62008-01-31 04:04:13 -080076 unregister_pernet_subsys(&ip6table_raw_net_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 return ret;
78}
79
Andrew Morton65b4b4e2006-03-28 16:37:06 -080080static void __exit ip6table_raw_fini(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081{
Jan Engelhardt2b95efe2009-06-17 13:57:48 +020082 xt_hook_unlink(&packet_raw, rawtable_ops);
Alexey Dobriyan8280aa62008-01-31 04:04:13 -080083 unregister_pernet_subsys(&ip6table_raw_net_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084}
85
Andrew Morton65b4b4e2006-03-28 16:37:06 -080086module_init(ip6table_raw_init);
87module_exit(ip6table_raw_fini);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088MODULE_LICENSE("GPL");