2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* This is the 1999 rewrite of IP Firewalling, aiming for kernel 2.3.x.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999 Paul `Rusty' Russell & Michael J. Neuling
|
|
|
|
* Copyright (C) 2000-2004 Netfilter Core Team <coreteam@netfilter.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/netfilter_ipv6/ip6_tables.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 02:04:11 -06:00
|
|
|
#include <linux/slab.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
|
|
|
|
MODULE_DESCRIPTION("ip6tables filter table");
|
|
|
|
|
2007-11-19 19:53:30 -07:00
|
|
|
#define FILTER_VALID_HOOKS ((1 << NF_INET_LOCAL_IN) | \
|
|
|
|
(1 << NF_INET_FORWARD) | \
|
|
|
|
(1 << NF_INET_LOCAL_OUT))
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2009-08-24 06:56:30 -06:00
|
|
|
static const struct xt_table packet_filter = {
|
2005-04-16 16:20:36 -06:00
|
|
|
.name = "filter",
|
|
|
|
.valid_hooks = FILTER_VALID_HOOKS,
|
|
|
|
.me = THIS_MODULE,
|
2009-06-12 22:25:44 -06:00
|
|
|
.af = NFPROTO_IPV6,
|
2009-06-17 05:57:48 -06:00
|
|
|
.priority = NF_IP6_PRI_FILTER,
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
/* The work comes in here from netfilter.c. */
|
|
|
|
static unsigned int
|
2013-10-10 01:21:55 -06:00
|
|
|
ip6table_filter_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
2009-06-12 22:46:36 -06:00
|
|
|
const struct net_device *in, const struct net_device *out,
|
|
|
|
int (*okfn)(struct sk_buff *))
|
2008-07-08 03:36:18 -06:00
|
|
|
{
|
2009-06-12 22:57:10 -06:00
|
|
|
const struct net *net = dev_net((in != NULL) ? in : out);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2013-10-10 01:21:55 -06:00
|
|
|
return ip6t_do_table(skb, ops->hooknum, in, out,
|
|
|
|
net->ipv6.ip6table_filter);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2009-06-17 05:57:48 -06:00
|
|
|
static struct nf_hook_ops *filter_ops __read_mostly;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* Default to forward because I got too much mail already. */
|
2012-03-22 06:27:06 -06:00
|
|
|
static bool forward = true;
|
2005-04-16 16:20:36 -06:00
|
|
|
module_param(forward, bool, 0000);
|
|
|
|
|
2008-01-31 05:04:13 -07:00
|
|
|
static int __net_init ip6table_filter_net_init(struct net *net)
|
|
|
|
{
|
2009-06-17 14:14:54 -06:00
|
|
|
struct ip6t_replace *repl;
|
|
|
|
|
|
|
|
repl = ip6t_alloc_initial_table(&packet_filter);
|
|
|
|
if (repl == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
/* Entry 1 is the FORWARD hook */
|
|
|
|
((struct ip6t_standard *)repl->entries)[1].target.verdict =
|
2012-03-22 06:27:06 -06:00
|
|
|
forward ? -NF_ACCEPT - 1 : -NF_DROP - 1;
|
2009-06-17 14:14:54 -06:00
|
|
|
|
2008-01-31 05:04:13 -07:00
|
|
|
net->ipv6.ip6table_filter =
|
2009-06-17 14:14:54 -06:00
|
|
|
ip6t_register_table(net, &packet_filter, repl);
|
|
|
|
kfree(repl);
|
2013-07-14 19:50:32 -06:00
|
|
|
return PTR_ERR_OR_ZERO(net->ipv6.ip6table_filter);
|
2008-01-31 05:04:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __net_exit ip6table_filter_net_exit(struct net *net)
|
|
|
|
{
|
2010-01-18 00:25:47 -07:00
|
|
|
ip6t_unregister_table(net, net->ipv6.ip6table_filter);
|
2008-01-31 05:04:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct pernet_operations ip6table_filter_net_ops = {
|
|
|
|
.init = ip6table_filter_net_init,
|
|
|
|
.exit = ip6table_filter_net_exit,
|
|
|
|
};
|
|
|
|
|
2006-03-28 17:37:06 -07:00
|
|
|
static int __init ip6table_filter_init(void)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2008-01-31 05:04:13 -07:00
|
|
|
ret = register_pernet_subsys(&ip6table_filter_net_ops);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* Register hooks */
|
2009-06-17 05:57:48 -06:00
|
|
|
filter_ops = xt_hook_link(&packet_filter, ip6table_filter_hook);
|
|
|
|
if (IS_ERR(filter_ops)) {
|
|
|
|
ret = PTR_ERR(filter_ops);
|
2005-04-16 16:20:36 -06:00
|
|
|
goto cleanup_table;
|
2009-06-17 05:57:48 -06:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
cleanup_table:
|
2008-01-31 05:04:13 -07:00
|
|
|
unregister_pernet_subsys(&ip6table_filter_net_ops);
|
2005-04-16 16:20:36 -06:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-03-28 17:37:06 -07:00
|
|
|
static void __exit ip6table_filter_fini(void)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2009-06-17 05:57:48 -06:00
|
|
|
xt_hook_unlink(&packet_filter, filter_ops);
|
2008-01-31 05:04:13 -07:00
|
|
|
unregister_pernet_subsys(&ip6table_filter_net_ops);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2006-03-28 17:37:06 -07:00
|
|
|
module_init(ip6table_filter_init);
|
|
|
|
module_exit(ip6table_filter_fini);
|