ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / net / ipv6 / netfilter / ip6table_raw.c
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
9 #define RAW_VALID_HOOKS ((1 << NF_IP6_PRE_ROUTING) | (1 << NF_IP6_LOCAL_OUT))
10
11 #if 0
12 #define DEBUGP(x, args...)      printk(KERN_DEBUG x, ## args)
13 #else
14 #define DEBUGP(x, args...)
15 #endif
16
17 /* Standard entry. */
18 struct ip6t_standard
19 {
20         struct ip6t_entry entry;
21         struct ip6t_standard_target target;
22 };
23
24 struct ip6t_error_target
25 {
26         struct ip6t_entry_target target;
27         char errorname[IP6T_FUNCTION_MAXNAMELEN];
28 };
29
30 struct ip6t_error
31 {
32         struct ip6t_entry entry;
33         struct ip6t_error_target target;
34 };
35
36 static struct
37 {
38         struct ip6t_replace repl;
39         struct ip6t_standard entries[2];
40         struct ip6t_error term;
41 } initial_table __initdata 
42 = { { "raw", RAW_VALID_HOOKS, 3,
43       sizeof(struct ip6t_standard) * 2 + sizeof(struct ip6t_error),
44       { [NF_IP6_PRE_ROUTING]    0,
45         [NF_IP6_LOCAL_OUT]      sizeof(struct ip6t_standard) },
46       { [NF_IP6_PRE_ROUTING]    0,
47         [NF_IP6_LOCAL_OUT]      sizeof(struct ip6t_standard) },
48       0, NULL, { } },
49     {
50             /* PRE_ROUTING */
51             { { { { { { 0 } } }, { { { 0 } } }, { { { 0 } } }, { { { 0 } } }, "", "", { 0 }, { 0 }, 0, 0, 0 },
52                 0,
53                 sizeof(struct ip6t_entry),
54                 sizeof(struct ip6t_standard),
55                 0, { 0, 0 }, { } },
56               { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
57                 -NF_ACCEPT - 1 } },
58             /* LOCAL_OUT */
59             { { { { { { 0 } } }, { { { 0 } } }, { { { 0 } } }, { { { 0 } } }, "", "", { 0 }, { 0 }, 0, 0, 0 },
60                 0,
61                 sizeof(struct ip6t_entry),
62                 sizeof(struct ip6t_standard),
63                 0, { 0, 0 }, { } },
64               { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
65                 -NF_ACCEPT - 1 } },
66     },
67     /* ERROR */
68     { { { { { { 0 } } }, { { { 0 } } }, { { { 0 } } }, { { { 0 } } }, "", "", { 0 }, { 0 }, 0, 0, 0 },
69         0,
70         sizeof(struct ip6t_entry),
71         sizeof(struct ip6t_error),
72         0, { 0, 0 }, { } },
73       { { { { IP6T_ALIGN(sizeof(struct ip6t_error_target)), IP6T_ERROR_TARGET } },
74           { } },
75         "ERROR"
76       }
77     }
78 };
79
80 static struct ip6t_table packet_raw = { 
81         .name = "raw", 
82         .table = &initial_table.repl,
83         .valid_hooks = RAW_VALID_HOOKS, 
84         .lock = RW_LOCK_UNLOCKED, 
85         .me = THIS_MODULE
86 };
87
88 /* The work comes in here from netfilter.c. */
89 static unsigned int
90 ip6t_hook(unsigned int hook,
91          struct sk_buff **pskb,
92          const struct net_device *in,
93          const struct net_device *out,
94          int (*okfn)(struct sk_buff *))
95 {
96         return ip6t_do_table(pskb, hook, in, out, &packet_raw, NULL);
97 }
98
99 static struct nf_hook_ops ip6t_ops[] = { 
100         {
101           .hook = ip6t_hook, 
102           .pf = PF_INET6,
103           .hooknum = NF_IP6_PRE_ROUTING,
104           .priority = NF_IP6_PRI_FIRST
105         },
106         {
107           .hook = ip6t_hook, 
108           .pf = PF_INET6, 
109           .hooknum = NF_IP6_LOCAL_OUT,
110           .priority = NF_IP6_PRI_FIRST
111         },
112 };
113
114 static int __init init(void)
115 {
116         int ret;
117
118         /* Register table */
119         ret = ip6t_register_table(&packet_raw);
120         if (ret < 0)
121                 return ret;
122
123         /* Register hooks */
124         ret = nf_register_hook(&ip6t_ops[0]);
125         if (ret < 0)
126                 goto cleanup_table;
127
128         ret = nf_register_hook(&ip6t_ops[1]);
129         if (ret < 0)
130                 goto cleanup_hook0;
131
132         return ret;
133
134  cleanup_hook0:
135         nf_unregister_hook(&ip6t_ops[0]);
136  cleanup_table:
137         ip6t_unregister_table(&packet_raw);
138
139         return ret;
140 }
141
142 static void __exit fini(void)
143 {
144         unsigned int i;
145
146         for (i = 0; i < sizeof(ip6t_ops)/sizeof(struct nf_hook_ops); i++)
147                 nf_unregister_hook(&ip6t_ops[i]);
148
149         ip6t_unregister_table(&packet_raw);
150 }
151
152 module_init(init);
153 module_exit(fini);
154 MODULE_LICENSE("GPL");