ip6table_raw.c 2.8 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8
/*
 * IPv6 raw table, a port of the IPv4 raw table to IPv6
 *
 * Copyright (C) 2003 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
 */
#include <linux/module.h>
#include <linux/netfilter_ipv6/ip6_tables.h>

9
#define RAW_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_OUT))
L
Linus Torvalds 已提交
10

11
static const struct
L
Linus Torvalds 已提交
12 13 14 15
{
	struct ip6t_replace repl;
	struct ip6t_standard entries[2];
	struct ip6t_error term;
16
} initial_table __net_initdata = {
L
Linus Torvalds 已提交
17 18 19 20 21 22
	.repl = {
		.name = "raw",
		.valid_hooks = RAW_VALID_HOOKS,
		.num_entries = 3,
		.size = sizeof(struct ip6t_standard) * 2 + sizeof(struct ip6t_error),
		.hook_entry = {
23 24
			[NF_INET_PRE_ROUTING] = 0,
			[NF_INET_LOCAL_OUT] = sizeof(struct ip6t_standard)
L
Linus Torvalds 已提交
25 26
		},
		.underflow = {
27 28
			[NF_INET_PRE_ROUTING] = 0,
			[NF_INET_LOCAL_OUT] = sizeof(struct ip6t_standard)
L
Linus Torvalds 已提交
29 30 31
		},
	},
	.entries = {
32 33
		IP6T_STANDARD_INIT(NF_ACCEPT),	/* PRE_ROUTING */
		IP6T_STANDARD_INIT(NF_ACCEPT),	/* LOCAL_OUT */
L
Linus Torvalds 已提交
34
	},
35
	.term = IP6T_ERROR_INIT,		/* ERROR */
L
Linus Torvalds 已提交
36 37
};

38
static const struct xt_table packet_raw = {
39 40
	.name = "raw",
	.valid_hooks = RAW_VALID_HOOKS,
41
	.me = THIS_MODULE,
42
	.af = NFPROTO_IPV6,
L
Linus Torvalds 已提交
43 44 45 46
};

/* The work comes in here from netfilter.c. */
static unsigned int
47 48 49
ip6table_raw_hook(unsigned int hook, struct sk_buff *skb,
		  const struct net_device *in, const struct net_device *out,
		  int (*okfn)(struct sk_buff *))
L
Linus Torvalds 已提交
50
{
51
	const struct net *net = dev_net((in != NULL) ? in : out);
52

53
	return ip6t_do_table(skb, hook, in, out, net->ipv6.ip6table_raw);
L
Linus Torvalds 已提交
54 55
}

56
static struct nf_hook_ops ip6t_ops[] __read_mostly = {
L
Linus Torvalds 已提交
57
	{
58
	  .hook = ip6table_raw_hook,
59
	  .pf = NFPROTO_IPV6,
60
	  .hooknum = NF_INET_PRE_ROUTING,
61 62
	  .priority = NF_IP6_PRI_FIRST,
	  .owner = THIS_MODULE,
L
Linus Torvalds 已提交
63 64
	},
	{
65
	  .hook = ip6table_raw_hook,
66
	  .pf = NFPROTO_IPV6,
67
	  .hooknum = NF_INET_LOCAL_OUT,
68 69
	  .priority = NF_IP6_PRI_FIRST,
	  .owner = THIS_MODULE,
L
Linus Torvalds 已提交
70 71 72
	},
};

73 74 75 76 77 78 79 80 81 82 83 84
static int __net_init ip6table_raw_net_init(struct net *net)
{
	/* Register table */
	net->ipv6.ip6table_raw =
		ip6t_register_table(net, &packet_raw, &initial_table.repl);
	if (IS_ERR(net->ipv6.ip6table_raw))
		return PTR_ERR(net->ipv6.ip6table_raw);
	return 0;
}

static void __net_exit ip6table_raw_net_exit(struct net *net)
{
85
	ip6t_unregister_table(net, net->ipv6.ip6table_raw);
86 87 88 89 90 91 92
}

static struct pernet_operations ip6table_raw_net_ops = {
	.init = ip6table_raw_net_init,
	.exit = ip6table_raw_net_exit,
};

93
static int __init ip6table_raw_init(void)
L
Linus Torvalds 已提交
94 95 96
{
	int ret;

97 98 99
	ret = register_pernet_subsys(&ip6table_raw_net_ops);
	if (ret < 0)
		return ret;
L
Linus Torvalds 已提交
100 101

	/* Register hooks */
102
	ret = nf_register_hooks(ip6t_ops, ARRAY_SIZE(ip6t_ops));
L
Linus Torvalds 已提交
103 104 105 106 107 108
	if (ret < 0)
		goto cleanup_table;

	return ret;

 cleanup_table:
109
	unregister_pernet_subsys(&ip6table_raw_net_ops);
L
Linus Torvalds 已提交
110 111 112
	return ret;
}

113
static void __exit ip6table_raw_fini(void)
L
Linus Torvalds 已提交
114
{
115
	nf_unregister_hooks(ip6t_ops, ARRAY_SIZE(ip6t_ops));
116
	unregister_pernet_subsys(&ip6table_raw_net_ops);
L
Linus Torvalds 已提交
117 118
}

119 120
module_init(ip6table_raw_init);
module_exit(ip6table_raw_fini);
L
Linus Torvalds 已提交
121
MODULE_LICENSE("GPL");