Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Patrick McHardy | 6e23ae2 | 2007-11-19 18:53:30 -0800 | [diff] [blame] | 9 | #define RAW_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_OUT)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | |
Jan Engelhardt | 35aad0f | 2009-08-24 14:56:30 +0200 | [diff] [blame] | 11 | static const struct xt_table packet_raw = { |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 12 | .name = "raw", |
| 13 | .valid_hooks = RAW_VALID_HOOKS, |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 14 | .me = THIS_MODULE, |
Jan Engelhardt | f88e6a8 | 2009-06-13 06:25:44 +0200 | [diff] [blame] | 15 | .af = NFPROTO_IPV6, |
Jozsef Kadlecsik | 9c13886 | 2010-03-25 11:17:26 +0100 | [diff] [blame] | 16 | .priority = NF_IP6_PRI_RAW, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | }; |
| 18 | |
| 19 | /* The work comes in here from netfilter.c. */ |
| 20 | static unsigned int |
Jan Engelhardt | 737535c | 2009-06-13 06:46:36 +0200 | [diff] [blame] | 21 | ip6table_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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | { |
Jan Engelhardt | 2b21e05 | 2009-06-13 06:57:10 +0200 | [diff] [blame] | 25 | const struct net *net = dev_net((in != NULL) ? in : out); |
Alexey Dobriyan | 1339dd9 | 2008-10-08 11:35:01 +0200 | [diff] [blame] | 26 | |
Jan Engelhardt | 2b21e05 | 2009-06-13 06:57:10 +0200 | [diff] [blame] | 27 | return ip6t_do_table(skb, hook, in, out, net->ipv6.ip6table_raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | } |
| 29 | |
Jan Engelhardt | 2b95efe | 2009-06-17 13:57:48 +0200 | [diff] [blame] | 30 | static struct nf_hook_ops *rawtable_ops __read_mostly; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
Alexey Dobriyan | 8280aa6 | 2008-01-31 04:04:13 -0800 | [diff] [blame] | 32 | static int __net_init ip6table_raw_net_init(struct net *net) |
| 33 | { |
Jan Engelhardt | e3eaa99 | 2009-06-17 22:14:54 +0200 | [diff] [blame] | 34 | struct ip6t_replace *repl; |
| 35 | |
| 36 | repl = ip6t_alloc_initial_table(&packet_raw); |
| 37 | if (repl == NULL) |
| 38 | return -ENOMEM; |
Alexey Dobriyan | 8280aa6 | 2008-01-31 04:04:13 -0800 | [diff] [blame] | 39 | net->ipv6.ip6table_raw = |
Jan Engelhardt | e3eaa99 | 2009-06-17 22:14:54 +0200 | [diff] [blame] | 40 | ip6t_register_table(net, &packet_raw, repl); |
| 41 | kfree(repl); |
Alexey Dobriyan | 8280aa6 | 2008-01-31 04:04:13 -0800 | [diff] [blame] | 42 | if (IS_ERR(net->ipv6.ip6table_raw)) |
| 43 | return PTR_ERR(net->ipv6.ip6table_raw); |
| 44 | return 0; |
| 45 | } |
| 46 | |
| 47 | static void __net_exit ip6table_raw_net_exit(struct net *net) |
| 48 | { |
Alexey Dobriyan | f54e936 | 2010-01-18 08:25:47 +0100 | [diff] [blame] | 49 | ip6t_unregister_table(net, net->ipv6.ip6table_raw); |
Alexey Dobriyan | 8280aa6 | 2008-01-31 04:04:13 -0800 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | static struct pernet_operations ip6table_raw_net_ops = { |
| 53 | .init = ip6table_raw_net_init, |
| 54 | .exit = ip6table_raw_net_exit, |
| 55 | }; |
| 56 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 57 | static int __init ip6table_raw_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | { |
| 59 | int ret; |
| 60 | |
Alexey Dobriyan | 8280aa6 | 2008-01-31 04:04:13 -0800 | [diff] [blame] | 61 | ret = register_pernet_subsys(&ip6table_raw_net_ops); |
| 62 | if (ret < 0) |
| 63 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
| 65 | /* Register hooks */ |
Jan Engelhardt | 2b95efe | 2009-06-17 13:57:48 +0200 | [diff] [blame] | 66 | rawtable_ops = xt_hook_link(&packet_raw, ip6table_raw_hook); |
| 67 | if (IS_ERR(rawtable_ops)) { |
| 68 | ret = PTR_ERR(rawtable_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | goto cleanup_table; |
Jan Engelhardt | 2b95efe | 2009-06-17 13:57:48 +0200 | [diff] [blame] | 70 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | return ret; |
| 73 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | cleanup_table: |
Alexey Dobriyan | 8280aa6 | 2008-01-31 04:04:13 -0800 | [diff] [blame] | 75 | unregister_pernet_subsys(&ip6table_raw_net_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | return ret; |
| 77 | } |
| 78 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 79 | static void __exit ip6table_raw_fini(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | { |
Jan Engelhardt | 2b95efe | 2009-06-17 13:57:48 +0200 | [diff] [blame] | 81 | xt_hook_unlink(&packet_raw, rawtable_ops); |
Alexey Dobriyan | 8280aa6 | 2008-01-31 04:04:13 -0800 | [diff] [blame] | 82 | unregister_pernet_subsys(&ip6table_raw_net_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 85 | module_init(ip6table_raw_init); |
| 86 | module_exit(ip6table_raw_fini); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | MODULE_LICENSE("GPL"); |