blob: 4fecd8de8cc24cb7d4bfa2cd31f77752ce05b470 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070011static struct
12{
13 struct ip6t_replace repl;
14 struct ip6t_standard entries[2];
15 struct ip6t_error term;
16} initial_table __initdata = {
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 McHardy6e23ae22007-11-19 18:53:30 -080023 [NF_INET_PRE_ROUTING] = 0,
24 [NF_INET_LOCAL_OUT] = sizeof(struct ip6t_standard)
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 },
26 .underflow = {
Patrick McHardy6e23ae22007-11-19 18:53:30 -080027 [NF_INET_PRE_ROUTING] = 0,
28 [NF_INET_LOCAL_OUT] = sizeof(struct ip6t_standard)
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 },
30 },
31 .entries = {
Patrick McHardy3c2ad462007-05-10 14:14:16 -070032 IP6T_STANDARD_INIT(NF_ACCEPT), /* PRE_ROUTING */
33 IP6T_STANDARD_INIT(NF_ACCEPT), /* LOCAL_OUT */
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 },
Patrick McHardy3c2ad462007-05-10 14:14:16 -070035 .term = IP6T_ERROR_INIT, /* ERROR */
Linus Torvalds1da177e2005-04-16 15:20:36 -070036};
37
YOSHIFUJI Hideaki1ab14572007-02-09 23:24:49 +090038static struct xt_table packet_raw = {
39 .name = "raw",
40 .valid_hooks = RAW_VALID_HOOKS,
41 .lock = RW_LOCK_UNLOCKED,
Harald Welte2e4e6a12006-01-12 13:30:04 -080042 .me = THIS_MODULE,
43 .af = AF_INET6,
Linus Torvalds1da177e2005-04-16 15:20:36 -070044};
45
46/* The work comes in here from netfilter.c. */
47static unsigned int
48ip6t_hook(unsigned int hook,
Herbert Xu3db05fe2007-10-15 00:53:15 -070049 struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 const struct net_device *in,
51 const struct net_device *out,
52 int (*okfn)(struct sk_buff *))
53{
Herbert Xu3db05fe2007-10-15 00:53:15 -070054 return ip6t_do_table(skb, hook, in, out, &packet_raw);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055}
56
YOSHIFUJI Hideaki1ab14572007-02-09 23:24:49 +090057static struct nf_hook_ops ip6t_ops[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 {
YOSHIFUJI Hideaki1ab14572007-02-09 23:24:49 +090059 .hook = ip6t_hook,
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 .pf = PF_INET6,
Patrick McHardy6e23ae22007-11-19 18:53:30 -080061 .hooknum = NF_INET_PRE_ROUTING,
Patrick McHardy97216c72005-06-21 14:03:01 -070062 .priority = NF_IP6_PRI_FIRST,
63 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 },
65 {
YOSHIFUJI Hideaki1ab14572007-02-09 23:24:49 +090066 .hook = ip6t_hook,
67 .pf = PF_INET6,
Patrick McHardy6e23ae22007-11-19 18:53:30 -080068 .hooknum = NF_INET_LOCAL_OUT,
Patrick McHardy97216c72005-06-21 14:03:01 -070069 .priority = NF_IP6_PRI_FIRST,
70 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 },
72};
73
Andrew Morton65b4b4e2006-03-28 16:37:06 -080074static int __init ip6table_raw_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
76 int ret;
77
78 /* Register table */
79 ret = ip6t_register_table(&packet_raw, &initial_table.repl);
80 if (ret < 0)
81 return ret;
82
83 /* Register hooks */
Patrick McHardy964ddaa2006-04-06 14:09:49 -070084 ret = nf_register_hooks(ip6t_ops, ARRAY_SIZE(ip6t_ops));
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 if (ret < 0)
86 goto cleanup_table;
87
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 return ret;
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 cleanup_table:
91 ip6t_unregister_table(&packet_raw);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 return ret;
93}
94
Andrew Morton65b4b4e2006-03-28 16:37:06 -080095static void __exit ip6table_raw_fini(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096{
Patrick McHardy964ddaa2006-04-06 14:09:49 -070097 nf_unregister_hooks(ip6t_ops, ARRAY_SIZE(ip6t_ops));
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 ip6t_unregister_table(&packet_raw);
99}
100
Andrew Morton65b4b4e2006-03-28 16:37:06 -0800101module_init(ip6table_raw_init);
102module_exit(ip6table_raw_fini);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103MODULE_LICENSE("GPL");