blob: b9cf7cd6192316a265a9b670e558c3740514e0d8 [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 xt_table packet_raw = {
YOSHIFUJI Hideaki1ab14572007-02-09 23:24:49 +090012 .name = "raw",
13 .valid_hooks = RAW_VALID_HOOKS,
Harald Welte2e4e6a12006-01-12 13:30:04 -080014 .me = THIS_MODULE,
Jan Engelhardtf88e6a82009-06-13 06:25:44 +020015 .af = NFPROTO_IPV6,
Jozsef Kadlecsik9c138862010-03-25 11:17:26 +010016 .priority = NF_IP6_PRI_RAW,
Linus Torvalds1da177e2005-04-16 15:20:36 -070017};
18
19/* The work comes in here from netfilter.c. */
20static unsigned int
Jan Engelhardt737535c2009-06-13 06:46:36 +020021ip6table_raw_hook(unsigned int hook, struct sk_buff *skb,
22 const struct net_device *in, const struct net_device *out,
23 int (*okfn)(struct sk_buff *))
Linus Torvalds1da177e2005-04-16 15:20:36 -070024{
Jan Engelhardt2b21e052009-06-13 06:57:10 +020025 const struct net *net = dev_net((in != NULL) ? in : out);
Alexey Dobriyan1339dd92008-10-08 11:35:01 +020026
Jan Engelhardt2b21e052009-06-13 06:57:10 +020027 return ip6t_do_table(skb, hook, in, out, net->ipv6.ip6table_raw);
Linus Torvalds1da177e2005-04-16 15:20:36 -070028}
29
Jan Engelhardt2b95efe2009-06-17 13:57:48 +020030static struct nf_hook_ops *rawtable_ops __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Alexey Dobriyan8280aa62008-01-31 04:04:13 -080032static int __net_init ip6table_raw_net_init(struct net *net)
33{
Jan Engelhardte3eaa992009-06-17 22:14:54 +020034 struct ip6t_replace *repl;
35
36 repl = ip6t_alloc_initial_table(&packet_raw);
37 if (repl == NULL)
38 return -ENOMEM;
Alexey Dobriyan8280aa62008-01-31 04:04:13 -080039 net->ipv6.ip6table_raw =
Jan Engelhardte3eaa992009-06-17 22:14:54 +020040 ip6t_register_table(net, &packet_raw, repl);
41 kfree(repl);
Alexey Dobriyan8280aa62008-01-31 04:04:13 -080042 if (IS_ERR(net->ipv6.ip6table_raw))
43 return PTR_ERR(net->ipv6.ip6table_raw);
44 return 0;
45}
46
47static void __net_exit ip6table_raw_net_exit(struct net *net)
48{
Alexey Dobriyanf54e9362010-01-18 08:25:47 +010049 ip6t_unregister_table(net, net->ipv6.ip6table_raw);
Alexey Dobriyan8280aa62008-01-31 04:04:13 -080050}
51
52static struct pernet_operations ip6table_raw_net_ops = {
53 .init = ip6table_raw_net_init,
54 .exit = ip6table_raw_net_exit,
55};
56
Andrew Morton65b4b4e2006-03-28 16:37:06 -080057static int __init ip6table_raw_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058{
59 int ret;
60
Alexey Dobriyan8280aa62008-01-31 04:04:13 -080061 ret = register_pernet_subsys(&ip6table_raw_net_ops);
62 if (ret < 0)
63 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65 /* Register hooks */
Jan Engelhardt2b95efe2009-06-17 13:57:48 +020066 rawtable_ops = xt_hook_link(&packet_raw, ip6table_raw_hook);
67 if (IS_ERR(rawtable_ops)) {
68 ret = PTR_ERR(rawtable_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 goto cleanup_table;
Jan Engelhardt2b95efe2009-06-17 13:57:48 +020070 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 return ret;
73
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 cleanup_table:
Alexey Dobriyan8280aa62008-01-31 04:04:13 -080075 unregister_pernet_subsys(&ip6table_raw_net_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 return ret;
77}
78
Andrew Morton65b4b4e2006-03-28 16:37:06 -080079static void __exit ip6table_raw_fini(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080{
Jan Engelhardt2b95efe2009-06-17 13:57:48 +020081 xt_hook_unlink(&packet_raw, rawtable_ops);
Alexey Dobriyan8280aa62008-01-31 04:04:13 -080082 unregister_pernet_subsys(&ip6table_raw_net_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083}
84
Andrew Morton65b4b4e2006-03-28 16:37:06 -080085module_init(ip6table_raw_init);
86module_exit(ip6table_raw_fini);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087MODULE_LICENSE("GPL");