]> git.karo-electronics.de Git - mv-sheeva.git/blob - net/ipv6/netfilter/ip6table_filter.c
36b72cafc2276899d5a296236a9c9dba34f9fc08
[mv-sheeva.git] / net / ipv6 / netfilter / ip6table_filter.c
1 /*
2  * This is the 1999 rewrite of IP Firewalling, aiming for kernel 2.3.x.
3  *
4  * Copyright (C) 1999 Paul `Rusty' Russell & Michael J. Neuling
5  * Copyright (C) 2000-2004 Netfilter Core Team <coreteam@netfilter.org>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  */
11
12 #include <linux/module.h>
13 #include <linux/moduleparam.h>
14 #include <linux/netfilter_ipv6/ip6_tables.h>
15
16 MODULE_LICENSE("GPL");
17 MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
18 MODULE_DESCRIPTION("ip6tables filter table");
19
20 #define FILTER_VALID_HOOKS ((1 << NF_INET_LOCAL_IN) | \
21                             (1 << NF_INET_FORWARD) | \
22                             (1 << NF_INET_LOCAL_OUT))
23
24 static const struct xt_table packet_filter = {
25         .name           = "filter",
26         .valid_hooks    = FILTER_VALID_HOOKS,
27         .me             = THIS_MODULE,
28         .af             = NFPROTO_IPV6,
29         .priority       = NF_IP6_PRI_FILTER,
30 };
31
32 /* The work comes in here from netfilter.c. */
33 static unsigned int
34 ip6table_filter_hook(unsigned int hook, struct sk_buff *skb,
35                      const struct net_device *in, const struct net_device *out,
36                      int (*okfn)(struct sk_buff *))
37 {
38         const struct net *net = dev_net((in != NULL) ? in : out);
39
40         return ip6t_do_table(skb, hook, in, out, net->ipv6.ip6table_filter);
41 }
42
43 static struct nf_hook_ops *filter_ops __read_mostly;
44
45 /* Default to forward because I got too much mail already. */
46 static int forward = NF_ACCEPT;
47 module_param(forward, bool, 0000);
48
49 static int __net_init ip6table_filter_net_init(struct net *net)
50 {
51         struct ip6t_replace *repl;
52
53         repl = ip6t_alloc_initial_table(&packet_filter);
54         if (repl == NULL)
55                 return -ENOMEM;
56         /* Entry 1 is the FORWARD hook */
57         ((struct ip6t_standard *)repl->entries)[1].target.verdict =
58                 -forward - 1;
59
60         net->ipv6.ip6table_filter =
61                 ip6t_register_table(net, &packet_filter, repl);
62         kfree(repl);
63         if (IS_ERR(net->ipv6.ip6table_filter))
64                 return PTR_ERR(net->ipv6.ip6table_filter);
65         return 0;
66 }
67
68 static void __net_exit ip6table_filter_net_exit(struct net *net)
69 {
70         ip6t_unregister_table(net, net->ipv6.ip6table_filter);
71 }
72
73 static struct pernet_operations ip6table_filter_net_ops = {
74         .init = ip6table_filter_net_init,
75         .exit = ip6table_filter_net_exit,
76 };
77
78 static int __init ip6table_filter_init(void)
79 {
80         int ret;
81
82         if (forward < 0 || forward > NF_MAX_VERDICT) {
83                 printk("iptables forward must be 0 or 1\n");
84                 return -EINVAL;
85         }
86
87         ret = register_pernet_subsys(&ip6table_filter_net_ops);
88         if (ret < 0)
89                 return ret;
90
91         /* Register hooks */
92         filter_ops = xt_hook_link(&packet_filter, ip6table_filter_hook);
93         if (IS_ERR(filter_ops)) {
94                 ret = PTR_ERR(filter_ops);
95                 goto cleanup_table;
96         }
97
98         return ret;
99
100  cleanup_table:
101         unregister_pernet_subsys(&ip6table_filter_net_ops);
102         return ret;
103 }
104
105 static void __exit ip6table_filter_fini(void)
106 {
107         xt_hook_unlink(&packet_filter, filter_ops);
108         unregister_pernet_subsys(&ip6table_filter_net_ops);
109 }
110
111 module_init(ip6table_filter_init);
112 module_exit(ip6table_filter_fini);