1 diff -Nur linux-2.6.21.1/include/linux/netfilter_ipv4/ipt_ROUTE.h linux-2.6.21.1-owrt/include/linux/netfilter_ipv4/ipt_ROUTE.h
2 --- linux-2.6.21.1/include/linux/netfilter_ipv4/ipt_ROUTE.h 1970-01-01 01:00:00.000000000 +0100
3 +++ linux-2.6.21.1-owrt/include/linux/netfilter_ipv4/ipt_ROUTE.h 2007-05-23 20:32:22.000000000 +0200
5 +/* Header file for iptables ipt_ROUTE target
7 + * (C) 2002 by Cédric de Launois <delaunois@info.ucl.ac.be>
9 + * This software is distributed under GNU GPL v2, 1991
11 +#ifndef _IPT_ROUTE_H_target
12 +#define _IPT_ROUTE_H_target
14 +#define IPT_ROUTE_IFNAMSIZ 16
16 +struct ipt_route_target_info {
17 + char oif[IPT_ROUTE_IFNAMSIZ]; /* Output Interface Name */
18 + char iif[IPT_ROUTE_IFNAMSIZ]; /* Input Interface Name */
19 + u_int32_t gw; /* IP address of gateway */
23 +/* Values for "flags" field */
24 +#define IPT_ROUTE_CONTINUE 0x01
25 +#define IPT_ROUTE_TEE 0x02
27 +#endif /*_IPT_ROUTE_H_target*/
28 diff -Nur linux-2.6.21.1/include/linux/netfilter_ipv6/ip6t_ROUTE.h linux-2.6.21.1-owrt/include/linux/netfilter_ipv6/ip6t_ROUTE.h
29 --- linux-2.6.21.1/include/linux/netfilter_ipv6/ip6t_ROUTE.h 1970-01-01 01:00:00.000000000 +0100
30 +++ linux-2.6.21.1-owrt/include/linux/netfilter_ipv6/ip6t_ROUTE.h 2007-05-23 20:32:22.000000000 +0200
32 +/* Header file for iptables ip6t_ROUTE target
34 + * (C) 2003 by Cédric de Launois <delaunois@info.ucl.ac.be>
36 + * This software is distributed under GNU GPL v2, 1991
38 +#ifndef _IPT_ROUTE_H_target
39 +#define _IPT_ROUTE_H_target
41 +#define IP6T_ROUTE_IFNAMSIZ 16
43 +struct ip6t_route_target_info {
44 + char oif[IP6T_ROUTE_IFNAMSIZ]; /* Output Interface Name */
45 + char iif[IP6T_ROUTE_IFNAMSIZ]; /* Input Interface Name */
46 + u_int32_t gw[4]; /* IPv6 address of gateway */
50 +/* Values for "flags" field */
51 +#define IP6T_ROUTE_CONTINUE 0x01
52 +#define IP6T_ROUTE_TEE 0x02
54 +#endif /*_IP6T_ROUTE_H_target*/
55 diff -Nur linux-2.6.21.1/net/ipv4/netfilter/ipt_ROUTE.c linux-2.6.21.1-owrt/net/ipv4/netfilter/ipt_ROUTE.c
56 --- linux-2.6.21.1/net/ipv4/netfilter/ipt_ROUTE.c 1970-01-01 01:00:00.000000000 +0100
57 +++ linux-2.6.21.1-owrt/net/ipv4/netfilter/ipt_ROUTE.c 2007-05-23 20:32:22.000000000 +0200
60 + * This implements the ROUTE target, which enables you to setup unusual
61 + * routes not supported by the standard kernel routing table.
63 + * Copyright (C) 2002 Cedric de Launois <delaunois@info.ucl.ac.be>
67 + * This software is distributed under GNU GPL v2, 1991
70 +#include <linux/module.h>
71 +#include <linux/skbuff.h>
72 +#include <linux/ip.h>
73 +#include <linux/netfilter_ipv4/ip_tables.h>
74 +#include <linux/netfilter_ipv4/ip_conntrack.h>
75 +#include <linux/netfilter_ipv4/ipt_ROUTE.h>
76 +#include <linux/netdevice.h>
77 +#include <linux/route.h>
78 +#include <linux/version.h>
79 +#include <linux/if_arp.h>
81 +#include <net/route.h>
82 +#include <net/icmp.h>
83 +#include <net/checksum.h>
86 +#define DEBUGP printk
88 +#define DEBUGP(format, args...)
91 +MODULE_LICENSE("GPL");
92 +MODULE_AUTHOR("Cedric de Launois <delaunois@info.ucl.ac.be>");
93 +MODULE_DESCRIPTION("iptables ROUTE target module");
95 +/* Try to route the packet according to the routing keys specified in
96 + * route_info. Keys are :
98 + * 0 if no oif preferred,
99 + * otherwise set to the index of the desired oif
100 + * - route_info->gw :
101 + * 0 if no gateway specified,
102 + * otherwise set to the next host to which the pkt must be routed
103 + * If success, skb->dev is the output device to which the packet must
104 + * be sent and skb->dst is not NULL
106 + * RETURN: -1 if an error occured
107 + * 1 if the packet was succesfully routed to the
108 + * destination desired
109 + * 0 if the kernel routing table could not route the packet
110 + * according to the keys specified
112 +static int route(struct sk_buff *skb,
113 + unsigned int ifindex,
114 + const struct ipt_route_target_info *route_info)
118 + struct iphdr *iph = skb->nh.iph;
119 + struct flowi fl = {
123 + .daddr = iph->daddr,
125 + .tos = RT_TOS(iph->tos),
126 + .scope = RT_SCOPE_UNIVERSE,
131 + /* The destination address may be overloaded by the target */
132 + if (route_info->gw)
133 + fl.fl4_dst = route_info->gw;
135 + /* Trying to route the packet using the standard routing table. */
136 + if ((err = ip_route_output_key(&rt, &fl))) {
137 + if (net_ratelimit())
138 + DEBUGP("ipt_ROUTE: couldn't route pkt (err: %i)",err);
142 + /* Drop old route. */
143 + dst_release(skb->dst);
146 + /* Success if no oif specified or if the oif correspond to the
148 + if (!ifindex || rt->u.dst.dev->ifindex == ifindex) {
149 + skb->dst = &rt->u.dst;
150 + skb->dev = skb->dst->dev;
151 + skb->protocol = htons(ETH_P_IP);
155 + /* The interface selected by the routing table is not the one
156 + * specified by the user. This may happen because the dst address
157 + * is one of our own addresses.
159 + if (net_ratelimit())
160 + DEBUGP("ipt_ROUTE: failed to route as desired gw=%u.%u.%u.%u oif=%i (got oif=%i)\n",
161 + NIPQUAD(route_info->gw), ifindex, rt->u.dst.dev->ifindex);
167 +/* Stolen from ip_finish_output2
168 + * PRE : skb->dev is set to the device we are leaving by
169 + * skb->dst is not NULL
170 + * POST: the packet is sent with the link layer header pushed
171 + * the packet is destroyed
173 +static void ip_direct_send(struct sk_buff *skb)
175 + struct dst_entry *dst = skb->dst;
176 + struct hh_cache *hh = dst->hh;
177 + struct net_device *dev = dst->dev;
178 + int hh_len = LL_RESERVED_SPACE(dev);
180 + /* Be paranoid, rather than too clever. */
181 + if (unlikely(skb_headroom(skb) < hh_len && dev->hard_header)) {
182 + struct sk_buff *skb2;
184 + skb2 = skb_realloc_headroom(skb, LL_RESERVED_SPACE(dev));
185 + if (skb2 == NULL) {
190 + skb_set_owner_w(skb2, skb->sk);
198 + read_lock_bh(&hh->hh_lock);
199 + hh_alen = HH_DATA_ALIGN(hh->hh_len);
200 + memcpy(skb->data - hh_alen, hh->hh_data, hh_alen);
201 + read_unlock_bh(&hh->hh_lock);
202 + skb_push(skb, hh->hh_len);
203 + hh->hh_output(skb);
204 + } else if (dst->neighbour)
205 + dst->neighbour->output(skb);
207 + if (net_ratelimit())
208 + DEBUGP(KERN_DEBUG "ipt_ROUTE: no hdr & no neighbour cache!\n");
214 +/* PRE : skb->dev is set to the device we are leaving by
215 + * POST: - the packet is directly sent to the skb->dev device, without
216 + * pushing the link layer header.
217 + * - the packet is destroyed
219 +static inline int dev_direct_send(struct sk_buff *skb)
221 + return dev_queue_xmit(skb);
225 +static unsigned int route_oif(const struct ipt_route_target_info *route_info,
226 + struct sk_buff *skb)
228 + unsigned int ifindex = 0;
229 + struct net_device *dev_out = NULL;
231 + /* The user set the interface name to use.
232 + * Getting the current interface index.
234 + if ((dev_out = dev_get_by_name(route_info->oif))) {
235 + ifindex = dev_out->ifindex;
237 + /* Unknown interface name : packet dropped */
238 + if (net_ratelimit())
239 + DEBUGP("ipt_ROUTE: oif interface %s not found\n", route_info->oif);
243 + /* Trying the standard way of routing packets */
244 + switch (route(skb, ifindex, route_info)) {
247 + if (route_info->flags & IPT_ROUTE_CONTINUE)
248 + return IPT_CONTINUE;
250 + ip_direct_send(skb);
254 + /* Failed to send to oif. Trying the hard way */
255 + if (route_info->flags & IPT_ROUTE_CONTINUE)
258 + if (net_ratelimit())
259 + DEBUGP("ipt_ROUTE: forcing the use of %i\n",
262 + /* We have to force the use of an interface.
263 + * This interface must be a tunnel interface since
264 + * otherwise we can't guess the hw address for
265 + * the packet. For a tunnel interface, no hw address
268 + if ((dev_out->type != ARPHRD_TUNNEL)
269 + && (dev_out->type != ARPHRD_IPGRE)) {
270 + if (net_ratelimit())
271 + DEBUGP("ipt_ROUTE: can't guess the hw addr !\n");
276 + /* Send the packet. This will also free skb
277 + * Do not go through the POST_ROUTING hook because
278 + * skb->dst is not set and because it will probably
279 + * get confused by the destination IP address.
281 + skb->dev = dev_out;
282 + dev_direct_send(skb);
287 + /* Unexpected error */
294 +static unsigned int route_iif(const struct ipt_route_target_info *route_info,
295 + struct sk_buff *skb)
297 + struct net_device *dev_in = NULL;
299 + /* Getting the current interface index. */
300 + if (!(dev_in = dev_get_by_name(route_info->iif))) {
301 + if (net_ratelimit())
302 + DEBUGP("ipt_ROUTE: iif interface %s not found\n", route_info->iif);
307 + dst_release(skb->dst);
316 +static unsigned int route_gw(const struct ipt_route_target_info *route_info,
317 + struct sk_buff *skb)
319 + if (route(skb, 0, route_info)!=1)
322 + if (route_info->flags & IPT_ROUTE_CONTINUE)
323 + return IPT_CONTINUE;
325 + ip_direct_send(skb);
330 +/* To detect and deter routed packet loopback when using the --tee option,
331 + * we take a page out of the raw.patch book: on the copied skb, we set up
332 + * a fake ->nfct entry, pointing to the local &route_tee_track. We skip
333 + * routing packets when we see they already have that ->nfct.
336 +static struct ip_conntrack route_tee_track;
338 +static unsigned int ipt_route_target(struct sk_buff **pskb,
339 + const struct net_device *in,
340 + const struct net_device *out,
341 + unsigned int hooknum,
342 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
343 + const struct xt_target *target,
345 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
346 + const void *targinfo,
349 + const void *targinfo)
352 + const struct ipt_route_target_info *route_info = targinfo;
353 + struct sk_buff *skb = *pskb;
356 + if (skb->nfct == &route_tee_track.ct_general) {
357 + /* Loopback - a packet we already routed, is to be
358 + * routed another time. Avoid that, now.
360 + if (net_ratelimit())
361 + DEBUGP(KERN_DEBUG "ipt_ROUTE: loopback - DROP!\n");
365 + /* If we are at PREROUTING or INPUT hook
366 + * the TTL isn't decreased by the IP stack
368 + if (hooknum == NF_IP_PRE_ROUTING ||
369 + hooknum == NF_IP_LOCAL_IN) {
371 + struct iphdr *iph = skb->nh.iph;
373 + if (iph->ttl <= 1) {
375 + struct flowi fl = {
379 + .daddr = iph->daddr,
380 + .saddr = iph->saddr,
381 + .tos = RT_TOS(iph->tos),
382 + .scope = ((iph->tos & RTO_ONLINK) ?
389 + if (ip_route_output_key(&rt, &fl)) {
393 + if (skb->dev == rt->u.dst.dev) {
394 + /* Drop old route. */
395 + dst_release(skb->dst);
396 + skb->dst = &rt->u.dst;
398 + /* this will traverse normal stack, and
399 + * thus call conntrack on the icmp packet */
400 + icmp_send(skb, ICMP_TIME_EXCEEDED,
408 + * If we are at INPUT the checksum must be recalculated since
409 + * the length could change as the result of a defragmentation.
411 + if(hooknum == NF_IP_LOCAL_IN) {
412 + iph->ttl = iph->ttl - 1;
414 + iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
416 + ip_decrease_ttl(iph);
420 + if ((route_info->flags & IPT_ROUTE_TEE)) {
422 + * Copy the *pskb, and route the copy. Will later return
423 + * IPT_CONTINUE for the original skb, which should continue
424 + * on its way as if nothing happened. The copy should be
425 + * independantly delivered to the ROUTE --gw.
427 + skb = skb_copy(*pskb, GFP_ATOMIC);
429 + if (net_ratelimit())
430 + DEBUGP(KERN_DEBUG "ipt_ROUTE: copy failed!\n");
431 + return IPT_CONTINUE;
435 + /* Tell conntrack to forget this packet since it may get confused
436 + * when a packet is leaving with dst address == our address.
437 + * Good idea ? Dunno. Need advice.
439 + * NEW: mark the skb with our &route_tee_track, so we avoid looping
440 + * on any already routed packet.
442 + if (!(route_info->flags & IPT_ROUTE_CONTINUE)) {
443 + nf_conntrack_put(skb->nfct);
444 + skb->nfct = &route_tee_track.ct_general;
445 + skb->nfctinfo = IP_CT_NEW;
446 + nf_conntrack_get(skb->nfct);
449 + if (route_info->oif[0] != '\0') {
450 + res = route_oif(route_info, skb);
451 + } else if (route_info->iif[0] != '\0') {
452 + res = route_iif(route_info, skb);
453 + } else if (route_info->gw) {
454 + res = route_gw(route_info, skb);
456 + if (net_ratelimit())
457 + DEBUGP(KERN_DEBUG "ipt_ROUTE: no parameter !\n");
458 + res = IPT_CONTINUE;
461 + if ((route_info->flags & IPT_ROUTE_TEE))
462 + res = IPT_CONTINUE;
468 +static int ipt_route_checkentry(const char *tablename,
469 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
472 + const struct ipt_ip *ip,
474 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
475 + const struct xt_target *target,
478 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
479 + unsigned int targinfosize,
481 + unsigned int hook_mask)
483 + if (strcmp(tablename, "mangle") != 0) {
484 + printk("ipt_ROUTE: bad table `%s', use the `mangle' table.\n",
489 + if (hook_mask & ~( (1 << NF_IP_PRE_ROUTING)
490 + | (1 << NF_IP_LOCAL_IN)
491 + | (1 << NF_IP_FORWARD)
492 + | (1 << NF_IP_LOCAL_OUT)
493 + | (1 << NF_IP_POST_ROUTING))) {
494 + printk("ipt_ROUTE: bad hook\n");
498 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
499 + if (targinfosize != IPT_ALIGN(sizeof(struct ipt_route_target_info))) {
500 + printk(KERN_WARNING "ipt_ROUTE: targinfosize %u != %Zu\n",
502 + IPT_ALIGN(sizeof(struct ipt_route_target_info)));
511 +static struct ipt_target ipt_route_reg = {
513 + .target = ipt_route_target,
514 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
515 + .targetsize = sizeof(struct ipt_route_target_info),
517 + .checkentry = ipt_route_checkentry,
521 +static int __init init(void)
523 + /* Set up fake conntrack (stolen from raw.patch):
524 + - to never be deleted, not in any hashes */
525 + atomic_set(&route_tee_track.ct_general.use, 1);
526 + /* - and look it like as a confirmed connection */
527 + set_bit(IPS_CONFIRMED_BIT, &route_tee_track.status);
528 + /* Initialize fake conntrack so that NAT will skip it */
529 + route_tee_track.status |= IPS_NAT_DONE_MASK;
531 + return xt_register_target(&ipt_route_reg);
535 +static void __exit fini(void)
537 + xt_unregister_target(&ipt_route_reg);
542 diff -Nur linux-2.6.21.1/net/ipv4/netfilter/Kconfig linux-2.6.21.1-owrt/net/ipv4/netfilter/Kconfig
543 --- linux-2.6.21.1/net/ipv4/netfilter/Kconfig 2007-04-27 23:49:26.000000000 +0200
544 +++ linux-2.6.21.1-owrt/net/ipv4/netfilter/Kconfig 2007-05-23 20:32:22.000000000 +0200
546 Allows altering the ARP packet payload: source and destination
547 hardware and network addresses.
549 +config IP_NF_TARGET_ROUTE
550 + tristate 'ROUTE target support'
551 + depends on IP_NF_MANGLE
553 + This option adds a `ROUTE' target, which enables you to setup unusual
554 + routes. For example, the ROUTE lets you route a received packet through
555 + an interface or towards a host, even if the regular destination of the
556 + packet is the router itself. The ROUTE target is also able to change the
557 + incoming interface of a packet.
559 + The target can be or not a final target. It has to be used inside the
562 + If you want to compile it as a module, say M here and read
563 + Documentation/modules.txt. The module will be called ipt_ROUTE.o.
564 + If unsure, say `N'.
568 diff -Nur linux-2.6.21.1/net/ipv4/netfilter/Makefile linux-2.6.21.1-owrt/net/ipv4/netfilter/Makefile
569 --- linux-2.6.21.1/net/ipv4/netfilter/Makefile 2007-04-27 23:49:26.000000000 +0200
570 +++ linux-2.6.21.1-owrt/net/ipv4/netfilter/Makefile 2007-05-23 20:32:22.000000000 +0200
572 obj-$(CONFIG_IP_NF_TARGET_ECN) += ipt_ECN.o
573 obj-$(CONFIG_IP_NF_TARGET_MASQUERADE) += ipt_MASQUERADE.o
574 obj-$(CONFIG_IP_NF_TARGET_REDIRECT) += ipt_REDIRECT.o
575 +obj-$(CONFIG_IP_NF_TARGET_ROUTE) += ipt_ROUTE.o
576 obj-$(CONFIG_IP_NF_TARGET_NETMAP) += ipt_NETMAP.o
577 obj-$(CONFIG_IP_NF_TARGET_SAME) += ipt_SAME.o
578 obj-$(CONFIG_IP_NF_NAT_SNMP_BASIC) += ip_nat_snmp_basic.o
579 diff -Nur linux-2.6.21.1/net/ipv6/ipv6_syms.c linux-2.6.21.1-owrt/net/ipv6/ipv6_syms.c
580 --- linux-2.6.21.1/net/ipv6/ipv6_syms.c 2007-04-27 23:49:26.000000000 +0200
581 +++ linux-2.6.21.1-owrt/net/ipv6/ipv6_syms.c 2007-05-23 20:32:22.000000000 +0200
583 EXPORT_SYMBOL(icmpv6_statistics);
584 EXPORT_SYMBOL(icmpv6_err_convert);
585 EXPORT_SYMBOL(ndisc_mc_map);
586 +EXPORT_SYMBOL(nd_tbl);
587 EXPORT_SYMBOL(register_inet6addr_notifier);
588 EXPORT_SYMBOL(unregister_inet6addr_notifier);
589 EXPORT_SYMBOL(ip6_route_output);
590 diff -Nur linux-2.6.21.1/net/ipv6/netfilter/ip6t_ROUTE.c linux-2.6.21.1-owrt/net/ipv6/netfilter/ip6t_ROUTE.c
591 --- linux-2.6.21.1/net/ipv6/netfilter/ip6t_ROUTE.c 1970-01-01 01:00:00.000000000 +0100
592 +++ linux-2.6.21.1-owrt/net/ipv6/netfilter/ip6t_ROUTE.c 2007-05-23 20:32:22.000000000 +0200
595 + * This implements the ROUTE v6 target, which enables you to setup unusual
596 + * routes not supported by the standard kernel routing table.
598 + * Copyright (C) 2003 Cedric de Launois <delaunois@info.ucl.ac.be>
602 + * This software is distributed under GNU GPL v2, 1991
605 +#include <linux/module.h>
606 +#include <linux/skbuff.h>
607 +#include <linux/ipv6.h>
608 +#include <linux/netfilter_ipv6/ip6_tables.h>
609 +#include <linux/netfilter_ipv6/ip6t_ROUTE.h>
610 +#include <linux/netdevice.h>
611 +#include <linux/version.h>
612 +#include <net/ipv6.h>
613 +#include <net/ndisc.h>
614 +#include <net/ip6_route.h>
615 +#include <linux/icmpv6.h>
618 +#define DEBUGP printk
620 +#define DEBUGP(format, args...)
623 +#define NIP6(addr) \
624 + ntohs((addr).s6_addr16[0]), \
625 + ntohs((addr).s6_addr16[1]), \
626 + ntohs((addr).s6_addr16[2]), \
627 + ntohs((addr).s6_addr16[3]), \
628 + ntohs((addr).s6_addr16[4]), \
629 + ntohs((addr).s6_addr16[5]), \
630 + ntohs((addr).s6_addr16[6]), \
631 + ntohs((addr).s6_addr16[7])
633 +/* Route the packet according to the routing keys specified in
634 + * route_info. Keys are :
636 + * 0 if no oif preferred,
637 + * otherwise set to the index of the desired oif
638 + * - route_info->gw :
639 + * 0 if no gateway specified,
640 + * otherwise set to the next host to which the pkt must be routed
641 + * If success, skb->dev is the output device to which the packet must
642 + * be sent and skb->dst is not NULL
644 + * RETURN: 1 if the packet was succesfully routed to the
645 + * destination desired
646 + * 0 if the kernel routing table could not route the packet
647 + * according to the keys specified
650 +route6(struct sk_buff *skb,
651 + unsigned int ifindex,
652 + const struct ip6t_route_target_info *route_info)
654 + struct rt6_info *rt = NULL;
655 + struct ipv6hdr *ipv6h = skb->nh.ipv6h;
656 + struct in6_addr *gw = (struct in6_addr*)&route_info->gw;
658 + DEBUGP("ip6t_ROUTE: called with: ");
659 + DEBUGP("DST=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ", NIP6(ipv6h->daddr));
660 + DEBUGP("GATEWAY=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ", NIP6(*gw));
661 + DEBUGP("OUT=%s\n", route_info->oif);
663 + if (ipv6_addr_any(gw))
664 + rt = rt6_lookup(&ipv6h->daddr, &ipv6h->saddr, ifindex, 1);
666 + rt = rt6_lookup(gw, &ipv6h->saddr, ifindex, 1);
671 + DEBUGP("ip6t_ROUTE: routing gives: ");
672 + DEBUGP("DST=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ", NIP6(rt->rt6i_dst.addr));
673 + DEBUGP("GATEWAY=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ", NIP6(rt->rt6i_gateway));
674 + DEBUGP("OUT=%s\n", rt->rt6i_dev->name);
676 + if (ifindex && rt->rt6i_dev->ifindex!=ifindex)
679 + if (!rt->rt6i_nexthop) {
680 + DEBUGP("ip6t_ROUTE: discovering neighbour\n");
681 + rt->rt6i_nexthop = ndisc_get_neigh(rt->rt6i_dev, &rt->rt6i_dst.addr);
684 + /* Drop old route. */
685 + dst_release(skb->dst);
686 + skb->dst = &rt->u.dst;
687 + skb->dev = rt->rt6i_dev;
691 + dst_release(&rt->u.dst);
693 + if (!net_ratelimit())
696 + printk("ip6t_ROUTE: no explicit route found ");
698 + printk("via interface %s ", route_info->oif);
699 + if (!ipv6_addr_any(gw))
700 + printk("via gateway %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x", NIP6(*gw));
706 +/* Stolen from ip6_output_finish
707 + * PRE : skb->dev is set to the device we are leaving by
708 + * skb->dst is not NULL
709 + * POST: the packet is sent with the link layer header pushed
710 + * the packet is destroyed
712 +static void ip_direct_send(struct sk_buff *skb)
714 + struct dst_entry *dst = skb->dst;
715 + struct hh_cache *hh = dst->hh;
718 + read_lock_bh(&hh->hh_lock);
719 + memcpy(skb->data - 16, hh->hh_data, 16);
720 + read_unlock_bh(&hh->hh_lock);
721 + skb_push(skb, hh->hh_len);
722 + hh->hh_output(skb);
723 + } else if (dst->neighbour)
724 + dst->neighbour->output(skb);
726 + if (net_ratelimit())
727 + DEBUGP(KERN_DEBUG "ip6t_ROUTE: no hdr & no neighbour cache!\n");
734 +route6_oif(const struct ip6t_route_target_info *route_info,
735 + struct sk_buff *skb)
737 + unsigned int ifindex = 0;
738 + struct net_device *dev_out = NULL;
740 + /* The user set the interface name to use.
741 + * Getting the current interface index.
743 + if ((dev_out = dev_get_by_name(route_info->oif))) {
744 + ifindex = dev_out->ifindex;
746 + /* Unknown interface name : packet dropped */
747 + if (net_ratelimit())
748 + DEBUGP("ip6t_ROUTE: oif interface %s not found\n", route_info->oif);
750 + if (route_info->flags & IP6T_ROUTE_CONTINUE)
751 + return IP6T_CONTINUE;
756 + /* Trying the standard way of routing packets */
757 + if (route6(skb, ifindex, route_info)) {
759 + if (route_info->flags & IP6T_ROUTE_CONTINUE)
760 + return IP6T_CONTINUE;
762 + ip_direct_send(skb);
770 +route6_gw(const struct ip6t_route_target_info *route_info,
771 + struct sk_buff *skb)
773 + if (route6(skb, 0, route_info)) {
774 + if (route_info->flags & IP6T_ROUTE_CONTINUE)
775 + return IP6T_CONTINUE;
777 + ip_direct_send(skb);
785 +ip6t_route_target(struct sk_buff **pskb,
786 + const struct net_device *in,
787 + const struct net_device *out,
788 + unsigned int hooknum,
789 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
790 + const struct xt_target *target,
792 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
793 + const void *targinfo,
796 + const void *targinfo)
799 + const struct ip6t_route_target_info *route_info = targinfo;
800 + struct sk_buff *skb = *pskb;
801 + struct in6_addr *gw = (struct in6_addr*)&route_info->gw;
804 + if (route_info->flags & IP6T_ROUTE_CONTINUE)
807 + /* If we are at PREROUTING or INPUT hook
808 + * the TTL isn't decreased by the IP stack
810 + if (hooknum == NF_IP6_PRE_ROUTING ||
811 + hooknum == NF_IP6_LOCAL_IN) {
813 + struct ipv6hdr *ipv6h = skb->nh.ipv6h;
815 + if (ipv6h->hop_limit <= 1) {
816 + /* Force OUTPUT device used as source address */
817 + skb->dev = skb->dst->dev;
819 + icmpv6_send(skb, ICMPV6_TIME_EXCEED,
820 + ICMPV6_EXC_HOPLIMIT, 0, skb->dev);
825 + ipv6h->hop_limit--;
828 + if ((route_info->flags & IP6T_ROUTE_TEE)) {
830 + * Copy the *pskb, and route the copy. Will later return
831 + * IP6T_CONTINUE for the original skb, which should continue
832 + * on its way as if nothing happened. The copy should be
833 + * independantly delivered to the ROUTE --gw.
835 + skb = skb_copy(*pskb, GFP_ATOMIC);
837 + if (net_ratelimit())
838 + DEBUGP(KERN_DEBUG "ip6t_ROUTE: copy failed!\n");
839 + return IP6T_CONTINUE;
844 + if (route_info->oif[0]) {
845 + res = route6_oif(route_info, skb);
846 + } else if (!ipv6_addr_any(gw)) {
847 + res = route6_gw(route_info, skb);
849 + if (net_ratelimit())
850 + DEBUGP(KERN_DEBUG "ip6t_ROUTE: no parameter !\n");
851 + res = IP6T_CONTINUE;
854 + if ((route_info->flags & IP6T_ROUTE_TEE))
855 + res = IP6T_CONTINUE;
862 +ip6t_route_checkentry(const char *tablename,
863 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
866 + const struct ip6t_entry *entry
868 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
869 + const struct xt_target *target,
872 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
873 + unsigned int targinfosize,
875 + unsigned int hook_mask)
877 + if (strcmp(tablename, "mangle") != 0) {
878 + printk("ip6t_ROUTE: can only be called from \"mangle\" table.\n");
882 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
883 + if (targinfosize != IP6T_ALIGN(sizeof(struct ip6t_route_target_info))) {
884 + printk(KERN_WARNING "ip6t_ROUTE: targinfosize %u != %Zu\n",
886 + IP6T_ALIGN(sizeof(struct ip6t_route_target_info)));
895 +static struct ip6t_target ip6t_route_reg = {
897 + .target = ip6t_route_target,
898 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
899 + .targetsize = sizeof(struct ip6t_route_target_info),
901 + .checkentry = ip6t_route_checkentry,
906 +static int __init init(void)
908 + printk(KERN_DEBUG "registering ipv6 ROUTE target\n");
909 + if (xt_register_target(&ip6t_route_reg))
916 +static void __exit fini(void)
918 + xt_unregister_target(&ip6t_route_reg);
923 +MODULE_LICENSE("GPL");
924 diff -Nur linux-2.6.21.1/net/ipv6/netfilter/Kconfig linux-2.6.21.1-owrt/net/ipv6/netfilter/Kconfig
925 --- linux-2.6.21.1/net/ipv6/netfilter/Kconfig 2007-04-27 23:49:26.000000000 +0200
926 +++ linux-2.6.21.1-owrt/net/ipv6/netfilter/Kconfig 2007-05-23 20:32:22.000000000 +0200
928 If you want to compile it as a module, say M here and read
929 <file:Documentation/modules.txt>. If unsure, say `N'.
931 +config IP6_NF_TARGET_ROUTE
932 + tristate 'ROUTE target support'
933 + depends on IP6_NF_MANGLE
935 + This option adds a `ROUTE' target, which enables you to setup unusual
936 + routes. The ROUTE target is also able to change the incoming interface
939 + The target can be or not a final target. It has to be used inside the
942 + Not working as a module.
946 diff -Nur linux-2.6.21.1/net/ipv6/netfilter/Makefile linux-2.6.21.1-owrt/net/ipv6/netfilter/Makefile
947 --- linux-2.6.21.1/net/ipv6/netfilter/Makefile 2007-04-27 23:49:26.000000000 +0200
948 +++ linux-2.6.21.1-owrt/net/ipv6/netfilter/Makefile 2007-05-23 20:32:22.000000000 +0200
950 obj-$(CONFIG_IP6_NF_RAW) += ip6table_raw.o
951 obj-$(CONFIG_IP6_NF_MATCH_HL) += ip6t_hl.o
952 obj-$(CONFIG_IP6_NF_TARGET_REJECT) += ip6t_REJECT.o
953 +obj-$(CONFIG_IP6_NF_TARGET_ROUTE) += ip6t_ROUTE.o
954 obj-$(CONFIG_IP6_NF_MATCH_MH) += ip6t_mh.o
956 # objects for l3 independent conntrack