[NETFILTER]: Convert DEBUGP to pr_debug
[deliverable/linux.git] / net / ipv6 / netfilter / ip6table_mangle.c
CommitLineData
1da177e4
LT
1/*
2 * IPv6 packet mangling table, a port of the IPv4 mangle table to IPv6
3 *
4 * Copyright (C) 2000-2001 by Harald Welte <laforge@gnumonks.org>
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.
1da177e4
LT
10 */
11#include <linux/module.h>
12#include <linux/netfilter_ipv6/ip6_tables.h>
13
14MODULE_LICENSE("GPL");
15MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
16MODULE_DESCRIPTION("ip6tables mangle table");
17
18#define MANGLE_VALID_HOOKS ((1 << NF_IP6_PRE_ROUTING) | \
19 (1 << NF_IP6_LOCAL_IN) | \
20 (1 << NF_IP6_FORWARD) | \
21 (1 << NF_IP6_LOCAL_OUT) | \
22 (1 << NF_IP6_POST_ROUTING))
23
1da177e4
LT
24static struct
25{
26 struct ip6t_replace repl;
27 struct ip6t_standard entries[5];
28 struct ip6t_error term;
3c2ad469
PM
29} initial_table __initdata = {
30 .repl = {
31 .name = "mangle",
32 .valid_hooks = MANGLE_VALID_HOOKS,
33 .num_entries = 6,
34 .size = sizeof(struct ip6t_standard) * 5 + sizeof(struct ip6t_error),
35 .hook_entry = {
36 [NF_IP6_PRE_ROUTING] = 0,
37 [NF_IP6_LOCAL_IN] = sizeof(struct ip6t_standard),
38 [NF_IP6_FORWARD] = sizeof(struct ip6t_standard) * 2,
39 [NF_IP6_LOCAL_OUT] = sizeof(struct ip6t_standard) * 3,
40 [NF_IP6_POST_ROUTING] = sizeof(struct ip6t_standard) * 4,
41 },
42 .underflow = {
43 [NF_IP6_PRE_ROUTING] = 0,
44 [NF_IP6_LOCAL_IN] = sizeof(struct ip6t_standard),
45 [NF_IP6_FORWARD] = sizeof(struct ip6t_standard) * 2,
46 [NF_IP6_LOCAL_OUT] = sizeof(struct ip6t_standard) * 3,
47 [NF_IP6_POST_ROUTING] = sizeof(struct ip6t_standard) * 4,
48 },
49 },
50 .entries = {
51 IP6T_STANDARD_INIT(NF_ACCEPT), /* PRE_ROUTING */
52 IP6T_STANDARD_INIT(NF_ACCEPT), /* LOCAL_IN */
53 IP6T_STANDARD_INIT(NF_ACCEPT), /* FORWARD */
54 IP6T_STANDARD_INIT(NF_ACCEPT), /* LOCAL_OUT */
55 IP6T_STANDARD_INIT(NF_ACCEPT), /* POST_ROUTING */
56 },
57 .term = IP6T_ERROR_INIT, /* ERROR */
1da177e4
LT
58};
59
e60a13e0 60static struct xt_table packet_mangler = {
1da177e4
LT
61 .name = "mangle",
62 .valid_hooks = MANGLE_VALID_HOOKS,
63 .lock = RW_LOCK_UNLOCKED,
64 .me = THIS_MODULE,
2e4e6a17 65 .af = AF_INET6,
1da177e4
LT
66};
67
68/* The work comes in here from netfilter.c. */
69static unsigned int
70ip6t_route_hook(unsigned int hook,
71 struct sk_buff **pskb,
72 const struct net_device *in,
73 const struct net_device *out,
74 int (*okfn)(struct sk_buff *))
75{
fe1cb108 76 return ip6t_do_table(pskb, hook, in, out, &packet_mangler);
1da177e4
LT
77}
78
79static unsigned int
80ip6t_local_hook(unsigned int hook,
81 struct sk_buff **pskb,
82 const struct net_device *in,
83 const struct net_device *out,
84 int (*okfn)(struct sk_buff *))
85{
86
1da177e4
LT
87 unsigned int ret;
88 struct in6_addr saddr, daddr;
89 u_int8_t hop_limit;
82e91ffe 90 u_int32_t flowlabel, mark;
1da177e4
LT
91
92#if 0
93 /* root is playing with raw sockets. */
94 if ((*pskb)->len < sizeof(struct iphdr)
c9bdd4b5 95 || ip_hdrlen(*pskb) < sizeof(struct iphdr)) {
1da177e4
LT
96 if (net_ratelimit())
97 printk("ip6t_hook: happy cracking.\n");
98 return NF_ACCEPT;
99 }
100#endif
101
82e91ffe 102 /* save source/dest address, mark, hoplimit, flowlabel, priority, */
0660e03f
ACM
103 memcpy(&saddr, &ipv6_hdr(*pskb)->saddr, sizeof(saddr));
104 memcpy(&daddr, &ipv6_hdr(*pskb)->daddr, sizeof(daddr));
82e91ffe 105 mark = (*pskb)->mark;
0660e03f 106 hop_limit = ipv6_hdr(*pskb)->hop_limit;
1da177e4
LT
107
108 /* flowlabel and prio (includes version, which shouldn't change either */
0660e03f 109 flowlabel = *((u_int32_t *)ipv6_hdr(*pskb));
1da177e4 110
fe1cb108 111 ret = ip6t_do_table(pskb, hook, in, out, &packet_mangler);
1da177e4 112
1ab1457c 113 if (ret != NF_DROP && ret != NF_STOLEN
0660e03f
ACM
114 && (memcmp(&ipv6_hdr(*pskb)->saddr, &saddr, sizeof(saddr))
115 || memcmp(&ipv6_hdr(*pskb)->daddr, &daddr, sizeof(daddr))
82e91ffe 116 || (*pskb)->mark != mark
0660e03f 117 || ipv6_hdr(*pskb)->hop_limit != hop_limit))
9123de2c 118 return ip6_route_me_harder(*pskb) == 0 ? ret : NF_DROP;
1da177e4
LT
119
120 return ret;
121}
122
123static struct nf_hook_ops ip6t_ops[] = {
124 {
125 .hook = ip6t_route_hook,
126 .owner = THIS_MODULE,
127 .pf = PF_INET6,
128 .hooknum = NF_IP6_PRE_ROUTING,
129 .priority = NF_IP6_PRI_MANGLE,
130 },
131 {
132 .hook = ip6t_local_hook,
133 .owner = THIS_MODULE,
134 .pf = PF_INET6,
135 .hooknum = NF_IP6_LOCAL_IN,
136 .priority = NF_IP6_PRI_MANGLE,
137 },
138 {
139 .hook = ip6t_route_hook,
140 .owner = THIS_MODULE,
141 .pf = PF_INET6,
142 .hooknum = NF_IP6_FORWARD,
143 .priority = NF_IP6_PRI_MANGLE,
144 },
145 {
146 .hook = ip6t_local_hook,
147 .owner = THIS_MODULE,
148 .pf = PF_INET6,
149 .hooknum = NF_IP6_LOCAL_OUT,
150 .priority = NF_IP6_PRI_MANGLE,
151 },
152 {
153 .hook = ip6t_route_hook,
154 .owner = THIS_MODULE,
155 .pf = PF_INET6,
156 .hooknum = NF_IP6_POST_ROUTING,
157 .priority = NF_IP6_PRI_MANGLE,
158 },
159};
160
65b4b4e8 161static int __init ip6table_mangle_init(void)
1da177e4
LT
162{
163 int ret;
164
165 /* Register table */
166 ret = ip6t_register_table(&packet_mangler, &initial_table.repl);
167 if (ret < 0)
168 return ret;
169
170 /* Register hooks */
964ddaa1 171 ret = nf_register_hooks(ip6t_ops, ARRAY_SIZE(ip6t_ops));
1da177e4
LT
172 if (ret < 0)
173 goto cleanup_table;
174
1da177e4
LT
175 return ret;
176
1da177e4
LT
177 cleanup_table:
178 ip6t_unregister_table(&packet_mangler);
1da177e4
LT
179 return ret;
180}
181
65b4b4e8 182static void __exit ip6table_mangle_fini(void)
1da177e4 183{
964ddaa1 184 nf_unregister_hooks(ip6t_ops, ARRAY_SIZE(ip6t_ops));
1da177e4
LT
185 ip6t_unregister_table(&packet_mangler);
186}
187
65b4b4e8
AM
188module_init(ip6table_mangle_init);
189module_exit(ip6table_mangle_fini);
This page took 0.242514 seconds and 5 git commands to generate.