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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | static struct |
| 12 | { |
| 13 | struct ip6t_replace repl; |
| 14 | struct ip6t_standard entries[2]; |
| 15 | struct ip6t_error term; |
Alexey Dobriyan | 8280aa6 | 2008-01-31 04:04:13 -0800 | [diff] [blame] | 16 | } initial_table __net_initdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | .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 McHardy | 6e23ae2 | 2007-11-19 18:53:30 -0800 | [diff] [blame] | 23 | [NF_INET_PRE_ROUTING] = 0, |
| 24 | [NF_INET_LOCAL_OUT] = sizeof(struct ip6t_standard) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | }, |
| 26 | .underflow = { |
Patrick McHardy | 6e23ae2 | 2007-11-19 18:53:30 -0800 | [diff] [blame] | 27 | [NF_INET_PRE_ROUTING] = 0, |
| 28 | [NF_INET_LOCAL_OUT] = sizeof(struct ip6t_standard) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | }, |
| 30 | }, |
| 31 | .entries = { |
Patrick McHardy | 3c2ad46 | 2007-05-10 14:14:16 -0700 | [diff] [blame] | 32 | IP6T_STANDARD_INIT(NF_ACCEPT), /* PRE_ROUTING */ |
| 33 | IP6T_STANDARD_INIT(NF_ACCEPT), /* LOCAL_OUT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | }, |
Patrick McHardy | 3c2ad46 | 2007-05-10 14:14:16 -0700 | [diff] [blame] | 35 | .term = IP6T_ERROR_INIT, /* ERROR */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | }; |
| 37 | |
Alexey Dobriyan | 8280aa6 | 2008-01-31 04:04:13 -0800 | [diff] [blame] | 38 | static struct xt_table packet_raw = { |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 39 | .name = "raw", |
| 40 | .valid_hooks = RAW_VALID_HOOKS, |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 41 | .me = THIS_MODULE, |
Jan Engelhardt | f88e6a8 | 2009-06-13 06:25:44 +0200 | [diff] [blame^] | 42 | .af = NFPROTO_IPV6, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | /* The work comes in here from netfilter.c. */ |
| 46 | static unsigned int |
Alexey Dobriyan | 1339dd9 | 2008-10-08 11:35:01 +0200 | [diff] [blame] | 47 | ip6t_pre_routing_hook(unsigned int hook, |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 48 | struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | const struct net_device *in, |
| 50 | const struct net_device *out, |
| 51 | int (*okfn)(struct sk_buff *)) |
| 52 | { |
Alexey Dobriyan | 1339dd9 | 2008-10-08 11:35:01 +0200 | [diff] [blame] | 53 | return ip6t_do_table(skb, hook, in, out, |
| 54 | dev_net(in)->ipv6.ip6table_raw); |
| 55 | } |
| 56 | |
| 57 | static unsigned int |
| 58 | ip6t_local_out_hook(unsigned int hook, |
| 59 | struct sk_buff *skb, |
| 60 | const struct net_device *in, |
| 61 | const struct net_device *out, |
| 62 | int (*okfn)(struct sk_buff *)) |
| 63 | { |
| 64 | return ip6t_do_table(skb, hook, in, out, |
| 65 | dev_net(out)->ipv6.ip6table_raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Patrick McHardy | 1999414 | 2007-12-05 01:23:00 -0800 | [diff] [blame] | 68 | static struct nf_hook_ops ip6t_ops[] __read_mostly = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | { |
Alexey Dobriyan | 1339dd9 | 2008-10-08 11:35:01 +0200 | [diff] [blame] | 70 | .hook = ip6t_pre_routing_hook, |
Jan Engelhardt | 24c232d | 2009-06-13 06:20:29 +0200 | [diff] [blame] | 71 | .pf = NFPROTO_IPV6, |
Patrick McHardy | 6e23ae2 | 2007-11-19 18:53:30 -0800 | [diff] [blame] | 72 | .hooknum = NF_INET_PRE_ROUTING, |
Patrick McHardy | 97216c7 | 2005-06-21 14:03:01 -0700 | [diff] [blame] | 73 | .priority = NF_IP6_PRI_FIRST, |
| 74 | .owner = THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | }, |
| 76 | { |
Alexey Dobriyan | 1339dd9 | 2008-10-08 11:35:01 +0200 | [diff] [blame] | 77 | .hook = ip6t_local_out_hook, |
Jan Engelhardt | 24c232d | 2009-06-13 06:20:29 +0200 | [diff] [blame] | 78 | .pf = NFPROTO_IPV6, |
Patrick McHardy | 6e23ae2 | 2007-11-19 18:53:30 -0800 | [diff] [blame] | 79 | .hooknum = NF_INET_LOCAL_OUT, |
Patrick McHardy | 97216c7 | 2005-06-21 14:03:01 -0700 | [diff] [blame] | 80 | .priority = NF_IP6_PRI_FIRST, |
| 81 | .owner = THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | }, |
| 83 | }; |
| 84 | |
Alexey Dobriyan | 8280aa6 | 2008-01-31 04:04:13 -0800 | [diff] [blame] | 85 | static int __net_init ip6table_raw_net_init(struct net *net) |
| 86 | { |
| 87 | /* Register table */ |
| 88 | net->ipv6.ip6table_raw = |
| 89 | ip6t_register_table(net, &packet_raw, &initial_table.repl); |
| 90 | if (IS_ERR(net->ipv6.ip6table_raw)) |
| 91 | return PTR_ERR(net->ipv6.ip6table_raw); |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | static void __net_exit ip6table_raw_net_exit(struct net *net) |
| 96 | { |
| 97 | ip6t_unregister_table(net->ipv6.ip6table_raw); |
| 98 | } |
| 99 | |
| 100 | static struct pernet_operations ip6table_raw_net_ops = { |
| 101 | .init = ip6table_raw_net_init, |
| 102 | .exit = ip6table_raw_net_exit, |
| 103 | }; |
| 104 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 105 | static int __init ip6table_raw_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | { |
| 107 | int ret; |
| 108 | |
Alexey Dobriyan | 8280aa6 | 2008-01-31 04:04:13 -0800 | [diff] [blame] | 109 | ret = register_pernet_subsys(&ip6table_raw_net_ops); |
| 110 | if (ret < 0) |
| 111 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
| 113 | /* Register hooks */ |
Patrick McHardy | 964ddaa | 2006-04-06 14:09:49 -0700 | [diff] [blame] | 114 | ret = nf_register_hooks(ip6t_ops, ARRAY_SIZE(ip6t_ops)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | if (ret < 0) |
| 116 | goto cleanup_table; |
| 117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | return ret; |
| 119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | cleanup_table: |
Alexey Dobriyan | 8280aa6 | 2008-01-31 04:04:13 -0800 | [diff] [blame] | 121 | unregister_pernet_subsys(&ip6table_raw_net_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | return ret; |
| 123 | } |
| 124 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 125 | static void __exit ip6table_raw_fini(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | { |
Patrick McHardy | 964ddaa | 2006-04-06 14:09:49 -0700 | [diff] [blame] | 127 | nf_unregister_hooks(ip6t_ops, ARRAY_SIZE(ip6t_ops)); |
Alexey Dobriyan | 8280aa6 | 2008-01-31 04:04:13 -0800 | [diff] [blame] | 128 | unregister_pernet_subsys(&ip6table_raw_net_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 131 | module_init(ip6table_raw_init); |
| 132 | module_exit(ip6table_raw_fini); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | MODULE_LICENSE("GPL"); |