2 * IPv6 packet mangling table, a port of the IPv4 mangle table to IPv6
4 * Copyright (C) 2000-2001 by Harald Welte <laforge@gnumonks.org>
5 * Copyright (C) 2000-2004 Netfilter Core Team <coreteam@netfilter.org>
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.
11 #include <linux/module.h>
12 #include <linux/netfilter_ipv6/ip6_tables.h>
14 MODULE_LICENSE("GPL");
15 MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
16 MODULE_DESCRIPTION("ip6tables mangle table");
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))
25 #define DEBUGP(x, args...) printk(KERN_DEBUG x, ## args)
27 #define DEBUGP(x, args...)
32 struct ip6t_replace repl
;
33 struct ip6t_standard entries
[5];
34 struct ip6t_error term
;
35 } initial_table __initdata
= {
38 .valid_hooks
= MANGLE_VALID_HOOKS
,
40 .size
= sizeof(struct ip6t_standard
) * 5 + sizeof(struct ip6t_error
),
42 [NF_IP6_PRE_ROUTING
] = 0,
43 [NF_IP6_LOCAL_IN
] = sizeof(struct ip6t_standard
),
44 [NF_IP6_FORWARD
] = sizeof(struct ip6t_standard
) * 2,
45 [NF_IP6_LOCAL_OUT
] = sizeof(struct ip6t_standard
) * 3,
46 [NF_IP6_POST_ROUTING
] = sizeof(struct ip6t_standard
) * 4,
49 [NF_IP6_PRE_ROUTING
] = 0,
50 [NF_IP6_LOCAL_IN
] = sizeof(struct ip6t_standard
),
51 [NF_IP6_FORWARD
] = sizeof(struct ip6t_standard
) * 2,
52 [NF_IP6_LOCAL_OUT
] = sizeof(struct ip6t_standard
) * 3,
53 [NF_IP6_POST_ROUTING
] = sizeof(struct ip6t_standard
) * 4,
57 IP6T_STANDARD_INIT(NF_ACCEPT
), /* PRE_ROUTING */
58 IP6T_STANDARD_INIT(NF_ACCEPT
), /* LOCAL_IN */
59 IP6T_STANDARD_INIT(NF_ACCEPT
), /* FORWARD */
60 IP6T_STANDARD_INIT(NF_ACCEPT
), /* LOCAL_OUT */
61 IP6T_STANDARD_INIT(NF_ACCEPT
), /* POST_ROUTING */
63 .term
= IP6T_ERROR_INIT
, /* ERROR */
66 static struct xt_table packet_mangler
= {
68 .valid_hooks
= MANGLE_VALID_HOOKS
,
69 .lock
= RW_LOCK_UNLOCKED
,
74 /* The work comes in here from netfilter.c. */
76 ip6t_route_hook(unsigned int hook
,
77 struct sk_buff
**pskb
,
78 const struct net_device
*in
,
79 const struct net_device
*out
,
80 int (*okfn
)(struct sk_buff
*))
82 return ip6t_do_table(pskb
, hook
, in
, out
, &packet_mangler
);
86 ip6t_local_hook(unsigned int hook
,
87 struct sk_buff
**pskb
,
88 const struct net_device
*in
,
89 const struct net_device
*out
,
90 int (*okfn
)(struct sk_buff
*))
94 struct in6_addr saddr
, daddr
;
96 u_int32_t flowlabel
, mark
;
99 /* root is playing with raw sockets. */
100 if ((*pskb
)->len
< sizeof(struct iphdr
)
101 || ip_hdrlen(*pskb
) < sizeof(struct iphdr
)) {
103 printk("ip6t_hook: happy cracking.\n");
108 /* save source/dest address, mark, hoplimit, flowlabel, priority, */
109 memcpy(&saddr
, &ipv6_hdr(*pskb
)->saddr
, sizeof(saddr
));
110 memcpy(&daddr
, &ipv6_hdr(*pskb
)->daddr
, sizeof(daddr
));
111 mark
= (*pskb
)->mark
;
112 hop_limit
= ipv6_hdr(*pskb
)->hop_limit
;
114 /* flowlabel and prio (includes version, which shouldn't change either */
115 flowlabel
= *((u_int32_t
*)ipv6_hdr(*pskb
));
117 ret
= ip6t_do_table(pskb
, hook
, in
, out
, &packet_mangler
);
119 if (ret
!= NF_DROP
&& ret
!= NF_STOLEN
120 && (memcmp(&ipv6_hdr(*pskb
)->saddr
, &saddr
, sizeof(saddr
))
121 || memcmp(&ipv6_hdr(*pskb
)->daddr
, &daddr
, sizeof(daddr
))
122 || (*pskb
)->mark
!= mark
123 || ipv6_hdr(*pskb
)->hop_limit
!= hop_limit
))
124 return ip6_route_me_harder(*pskb
) == 0 ? ret
: NF_DROP
;
129 static struct nf_hook_ops ip6t_ops
[] = {
131 .hook
= ip6t_route_hook
,
132 .owner
= THIS_MODULE
,
134 .hooknum
= NF_IP6_PRE_ROUTING
,
135 .priority
= NF_IP6_PRI_MANGLE
,
138 .hook
= ip6t_local_hook
,
139 .owner
= THIS_MODULE
,
141 .hooknum
= NF_IP6_LOCAL_IN
,
142 .priority
= NF_IP6_PRI_MANGLE
,
145 .hook
= ip6t_route_hook
,
146 .owner
= THIS_MODULE
,
148 .hooknum
= NF_IP6_FORWARD
,
149 .priority
= NF_IP6_PRI_MANGLE
,
152 .hook
= ip6t_local_hook
,
153 .owner
= THIS_MODULE
,
155 .hooknum
= NF_IP6_LOCAL_OUT
,
156 .priority
= NF_IP6_PRI_MANGLE
,
159 .hook
= ip6t_route_hook
,
160 .owner
= THIS_MODULE
,
162 .hooknum
= NF_IP6_POST_ROUTING
,
163 .priority
= NF_IP6_PRI_MANGLE
,
167 static int __init
ip6table_mangle_init(void)
172 ret
= ip6t_register_table(&packet_mangler
, &initial_table
.repl
);
177 ret
= nf_register_hooks(ip6t_ops
, ARRAY_SIZE(ip6t_ops
));
184 ip6t_unregister_table(&packet_mangler
);
188 static void __exit
ip6table_mangle_fini(void)
190 nf_unregister_hooks(ip6t_ops
, ARRAY_SIZE(ip6t_ops
));
191 ip6t_unregister_table(&packet_mangler
);
194 module_init(ip6table_mangle_init
);
195 module_exit(ip6table_mangle_fini
);
This page took 0.059848 seconds and 6 git commands to generate.