ipvs: IPv6 tunnel mode
Subsystems (4)
From: Julian Anastasov <[email protected]>
Tunnel mode for IPv6 doesn't work.
IPv6 encapsulation uses a bad source address for the tunnel. i.e. VIP will be used as local-addr and encap. dst addr. Decapsulation will not accept this.
Example
LVS (eth1 2003::2:0:1/96, VIP 2003::2:0:100)
(eth0 2003::1:0:1/96)
RS (ethX 2003::1:0:5/96)
tcpdump
2003::2:0:100 > 2003::1:0:5:
IP6 (hlim 63, next-header TCP (6) payload length: 40)
2003::3:0:10.50991 > 2003::2:0:100.http: Flags [S], cksum 0x7312
(correct), seq 3006460279, win 5760, options [mss 1440,sackOK,TS val 1904932 ecr 0,nop,wscale 3], length 0
In Linux IPv6 impl. you can't have a tunnel with an any cast address receiving packets (I have not tried to interpret RFC 2473) To have receive capabilities the tunnel must have:
- Local address set as multicast addr or an unicast addr
- Remote address set as an unicast addr.
- Loop back addres or Link local address are not allowed.
This causes us to setup a tunnel in the Real Server with the LVS as the remote address, here you can't use the VIP address since it's used inside the tunnel.
Solution
Use outgoing interface IPv6 address (match against the destination). i.e. use ip6_route_output() to look up the route cache and then use ipv6_dev_get_saddr(...) to set the source address of the encapsulated packet.
Additionally, cache the results in new destination
fields: dst_cookie and dst_saddr and properly check the returned dst from ip6_route_output. We now add xfrm_lookup call only for the tunneling method where the source address is a local one.
Original patch by Hans Schillstrom.
Check dst state and cache results for IPv6 by Julian Anastasov.
---
* v1
This is Julian's patch with a slightly edited version of the description from Hans's original patch.
* v2
Updated changelog as per commends from Julian
Is everyone ok with pushing this?
include/net/ip_vs.h renamed from linux/include/net/ip_vs.h +4 -0
@@ -509,6 +509,10 @@ struct ip_vs_dest {spinlock_t dst_lock;/* lock of dst_cache */ struct dst_entry *dst_cache;/* destination cache entry */ u32 dst_rtos;/* RT_TOS(tos) for dst */ +u32 dst_cookie; +#ifdef CONFIG_IP_VS_IPV6 +struct in6_addr dst_saddr; +#endif /* for virtual service */ struct ip_vs_service *svc;/* service it belongs to */
net/netfilter/ipvs/ip_vs_xmit.c renamed from linux/net/netfilter/ipvs/ip_vs_xmit.c +92 -79
363 lines not on this page · raw message
Julian Anastasov
maintainerHello,
Quoted 457 lines · Simon Horman
From: Julian Anastasov <[email protected]>
Tunnel mode for IPv6 doesn't work.
IPv6 encapsulation uses a bad source address for the tunnel. i.e. VIP will be used as local-addr and encap. dst addr. Decapsulation will not accept this.
Example
LVS (eth1 2003::2:0:1/96, VIP 2003::2:0:100)
(eth0 2003::1:0:1/96)
RS (ethX 2003::1:0:5/96)tcpdump
2003::2:0:100 > 2003::1:0:5:
IP6 (hlim 63, next-header TCP (6) payload length: 40) 2003::3:0:10.50991 > 2003::2:0:100.http: Flags [S], cksum0x7312(correct), seq 3006460279, win 5760, options [mss 1440,sackOK,TS val 1904932 ecr 0,nop,wscale 3], length 0In Linux IPv6 impl. you can't have a tunnel with an any cast address receiving packets (I have not tried to interpret RFC 2473) To have receive capabilities the tunnel must have:
- Local address set as multicast addr or an unicast addr
- Remote address set as an unicast addr.
- Loop back addres or Link local address are not allowed.This causes us to setup a tunnel in the Real Server with the LVS as the remote address, here you can't use the VIP address since it's used inside the tunnel.
Solution
Use outgoing interface IPv6 address (match against the destination). i.e. useip6_route_output()to look up the route cache and then useipv6_dev_get_saddr(...)to set the source address of the encapsulated packet.Additionally, cache the results in new destination
fields:dst_cookieanddst_saddrand properly check the returned dst fromip6_route_output. We now addxfrm_lookupcall only for the tunneling method where the source address is a local one.Original patch by Hans Schillstrom.
Check dst state and cache results for IPv6 by Julian Anastasov.Tested-by Hans Schillstrom <[email protected]>Signed-off-by Julian Anastasov <[email protected]>Signed-off-by Simon Horman <[email protected]>---
* v1
This is Julian's patch with a slightly edited version of the description from Hans's original patch.
* v2
Updated changelog as per commends from Julian
Is everyone ok with pushing this?
diff -urp
net-next-2.6-e548833-nfct_snat_reroute/linux/include/net/ip_vs.hlinux/include/net/ip_vs.hinclude/net/ip_vs.h renamed from linux/include/net/ip_vs.h +4
-0@@ -509,6 +509,10 @@ struct ip_vs_dest {spinlock_t dst_lock;/* lock of dst_cache */ struct dst_entry *dst_cache;/* destination cache entry */ u32 dst_rtos;/* RT_TOS(tos) for dst */ +u32 dst_cookie; +#ifdef CONFIG_IP_VS_IPV6 +struct in6_addr dst_saddr; +#endif /* for virtual service */ struct ip_vs_service *svc;/* service it belongs to */ diff -urp
net-next-2.6-e548833-nfct_snat_reroute/linux/net/netfilter/ipvs/ip_vs_xmit.clinux/net/netfilter/ipvs/ip_vs_xmit.cnet/netfilter/ipvs/ip_vs_xmit.c renamed from linux/net/netfilter/ipvs/ip_vs_xmit.c +1
-0@@ -26,6 +26,7 @@#include <net/route.h> /* for ip_route_output */ #include <net/ipv6.h> #include <net/ip6_route.h> +#include <net/addrconf.h> #include <linux/icmpv6.h> #include <linux/netfilter.h> #include <linux/netfilter_ipv4.h> @@ -37,26 +38,27 @@* Destination cache to speed up outgoing route lookup */ static inline void
net/netfilter/ipvs/ip_vs_xmit.c renamed from linux/net/netfilter/ipvs/ip_vs_xmit.c +2
-1-__ip_vs_dst_set(struct ip_vs_dest *dest, u32 rtos, struct dst_entry *dst) +__ip_vs_dst_set(struct ip_vs_dest *dest, u32 rtos, struct dst_entry *dst, + u32 dst_cookie){ struct dst_entry *old_dst; old_dst = dest->dst_cache; dest->dst_cache = dst; dest->dst_rtos = rtos;net/netfilter/ipvs/ip_vs_xmit.c renamed from linux/net/netfilter/ipvs/ip_vs_xmit.c +1
-0+ dest->dst_cookie = dst_cookie;dst_release(old_dst); }static inline struct
dst_entry*net/netfilter/ipvs/ip_vs_xmit.c renamed from linux/net/netfilter/ipvs/ip_vs_xmit.c +1
-1-__ip_vs_dst_check(struct ip_vs_dest *dest, u32 rtos, u32 cookie) +__ip_vs_dst_check(struct ip_vs_dest *dest, u32 rtos){ struct dst_entry *dst = dest->dst_cache; if (!dst) return NULL;net/netfilter/ipvs/ip_vs_xmit.c renamed from linux/net/netfilter/ipvs/ip_vs_xmit.c +2
-3-if ((dst->obsolete - || (dest->af ==AF_INET && rtos != dest->dst_rtos)) && - dst->ops->check (dst, cookie) ==NULL ) { +if ((dst->obsolete || rtos != dest->dst_rtos) && + dst->ops->check (dst, dest->dst_cookie) ==NULL ) {dest->dst_cache = NULL; dst_release(dst); return NULL;net/netfilter/ipvs/ip_vs_xmit.c renamed from linux/net/netfilter/ipvs/ip_vs_xmit.c +0
-0@@ -66,15 +68,16 @@ __ip_vs_dst_check(struct ip_vs_dest *des }static struct rtable *
net/netfilter/ipvs/ip_vs_xmit.c renamed from linux/net/netfilter/ipvs/ip_vs_xmit.c +1
-1-__ip_vs_get_out_rt(struct ip_vs_conn *cp, u32 rtos) +__ip_vs_get_out_rt(struct sk_buff *skb, struct ip_vs_conn *cp, u32 rtos){
net/netfilter/ipvs/ip_vs_xmit.c renamed from linux/net/netfilter/ipvs/ip_vs_xmit.c +1
-0+struct net *net =dev_net (skb->dev);struct rtable *rt; /* Route to the other host */ struct ip_vs_dest *dest = cp->dest; if (dest) { spin_lock(&dest->dst_lock); if (!(rt = (struct rtable *)net/netfilter/ipvs/ip_vs_xmit.c renamed from linux/net/netfilter/ipvs/ip_vs_xmit.c +1
-1- __ip_vs_dst_check(dest, rtos, 0))) { + __ip_vs_dst_check(dest, rtos))) {struct flowi fl = { .oif = 0, .nl_u = {net/netfilter/ipvs/ip_vs_xmit.c renamed from linux/net/netfilter/ipvs/ip_vs_xmit.c +38
-3@@ -84,13 +87,13 @@ __ip_vs_get_out_rt(struct ip_vs_conn *cp .tos = rtos, } }, }; -if (ip_route_output_key (&init_net, &rt, &fl)) { +if (ip_route_output_key (net, &rt, &fl)) {spin_unlock (&dest->dst_lock);IP_VS_DBG_RL ("ip_route_output error, dest: %pI4\n" , &dest->addr.ip);return NULL ; } -__ip_vs_dst_set (dest, rtos,dst_clone (&rt->dst)); +__ip_vs_dst_set (dest, rtos,dst_clone (&rt->dst),0 );IP_VS_DBG (10 ,"new dst %pI4, refcnt=%d, rtos=%X\n" , &dest->addr.ip,atomic_read (&rt->dst.__refcnt), rtos);@@ -106,7 +109,7 @@ __ip_vs_get_out_rt(struct ip_vs_conn *cp .tos = rtos, } }, }; -if (ip_route_output_key (&init_net, &rt, &fl)) { +if (ip_route_output_key (net, &rt, &fl)) {IP_VS_DBG_RL ("ip_route_output error, dest: %pI4\n" , &cp->daddr.ip);return NULL ;@@ -117,62 +120,79 @@ __ip_vs_get_out_rt(struct ip_vs_conn *cp }#ifdef CONFIG_IP_VS_IPV6 + +static struct dst_entry * +__ip_vs_route_output_v6 (struct net *net,struct in6_addr *daddr, +struct in6_addr *ret_saddr,int do_xfrm) +{ +struct dst_entry *dst; +struct flowi fl = { + .oif =0 , + .nl_u = { + .ip6_u = { + .daddr = *daddr, + }, + }, + }; + + dst =ip6_route_output (net,NULL , &fl); +if (dst->error) + goto out_err; +if (!ret_saddr) +return dst; +if (ipv6_addr_any (&fl.fl6_src) && +ipv6_dev_get_saddr (net,ip6_dst_idev (dst)->dev, + &fl.fl6_dst,0 , &fl.fl6_src) <0 ) + goto out_err; +if (do_xfrm &&xfrm_lookup (net, &dst, &fl,NULL ,0 ) <0 ) + goto out_err; +ipv6_addr_copy (ret_saddr, &fl.fl6_src); +return dst; + +out_err: +dst_release (dst); +IP_VS_DBG_RL ("ip6_route_output error, dest: %pI6\n" , daddr); +return NULL ; +} +static struct
rt6_info*net/netfilter/ipvs/ip_vs_xmit.c renamed from linux/net/netfilter/ipvs/ip_vs_xmit.c +2
-1-__ip_vs_get_out_rt_v6(struct ip_vs_conn *cp) +__ip_vs_get_out_rt_v6(struct sk_buff *skb, struct ip_vs_conn *cp, + struct in6_addr *ret_saddr, int do_xfrm){
net/netfilter/ipvs/ip_vs_xmit.c renamed from linux/net/netfilter/ipvs/ip_vs_xmit.c +1
-0+struct net *net =dev_net (skb->dev);struct rt6_info *rt; /* Route to the other host */ struct ip_vs_dest *dest = cp->dest;net/netfilter/ipvs/ip_vs_xmit.c renamed from linux/net/netfilter/ipvs/ip_vs_xmit.c +1
-0+struct dst_entry *dst;if (dest) { spin_lock(&dest->dst_lock);net/netfilter/ipvs/ip_vs_xmit.c renamed from linux/net/netfilter/ipvs/ip_vs_xmit.c +1
-1- rt = (struct rt6_info *)__ip_vs_dst_check (dest,0 ,0 ); + rt = (struct rt6_info *)__ip_vs_dst_check (dest,0 );if (!rt) {net/netfilter/ipvs/ip_vs_xmit.c renamed from linux/net/netfilter/ipvs/ip_vs_xmit.c +5
-15-struct flowi fl = { - .oif =0 , - .nl_u = { - .ip6_u = { - .daddr = dest->addr.in6, - .saddr = { - .s6_addr32 = - {0 ,0 ,0 ,0 }, - }, - }, - }, - }; +u32 cookie; - rt = (struct rt6_info *)ip6_route_output (&init_net, -NULL , &fl); -if (!rt) { + dst =__ip_vs_route_output_v6 (net, &dest->addr.in6, + &dest->dst_saddr, + do_xfrm); +if (!dst) {spin_unlock(&dest->dst_lock);net/netfilter/ipvs/ip_vs_xmit.c renamed from linux/net/netfilter/ipvs/ip_vs_xmit.c +0
-2-IP_VS_DBG_RL ("ip6_route_output error, dest: %pI6\n" , - &dest->addr.in6);return NULL; }net/netfilter/ipvs/ip_vs_xmit.c renamed from linux/net/netfilter/ipvs/ip_vs_xmit.c +5
-3-__ip_vs_dst_set (dest,0 ,dst_clone (&rt->dst)); - IP_VS_DBG(10, "new dst %pI6, refcnt=%d\n", - &dest->addr.in6, + rt = (struct rt6_info *) dst; + cookie = rt->rt6i_node ? rt->rt6i_node->fn_sernum :0 ; +__ip_vs_dst_set (dest,0 ,dst_clone (&rt->dst), cookie); + IP_VS_DBG(10, "new dst %pI6, src %pI6, refcnt=%d\n", + &dest->addr.in6, &dest->dst_saddr,atomic_read(&rt->dst.__refcnt)); }net/netfilter/ipvs/ip_vs_xmit.c renamed from linux/net/netfilter/ipvs/ip_vs_xmit.c +2
-0+if (ret_saddr) +ipv6_addr_copy (ret_saddr, &dest->dst_saddr);spin_unlock(&dest->dst_lock); } else {net/netfilter/ipvs/ip_vs_xmit.c renamed from linux/net/netfilter/ipvs/ip_vs_xmit.c +3
-16-struct flowi fl = { - .oif =0 , - .nl_u = { - .ip6_u = { - .daddr = cp->daddr.in6, - .saddr = { - .s6_addr32 = {0 ,0 ,0 ,0 }, - }, - }, - }, - }; - - rt = (struct rt6_info *)ip6_route_output (&init_net,NULL , &fl); -if (!rt) { -IP_VS_DBG_RL ("ip6_route_output error, dest: %pI6\n" , - &cp->daddr.in6); + dst =__ip_vs_route_output_v6 (net, &cp->daddr.in6, ret_saddr, + do_xfrm); +if (!dst)return NULL;net/netfilter/ipvs/ip_vs_xmit.c renamed from linux/net/netfilter/ipvs/ip_vs_xmit.c +1
-1- } + rt = (struct rt6_info *) dst;} return rt;net/netfilter/ipvs/ip_vs_xmit.c renamed from linux/net/netfilter/ipvs/ip_vs_xmit.c +22
-29@@ -248,6 +268,7 @@ int ip_vs_bypass_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp) { + struct net *net = dev_net(skb->dev);struct rtable *rt;/* Route to the other host */ struct iphdr *iph =ip_hdr (skb);u8 tos = iph->tos;@@ -263,7 +284,7 @@ ip_vs_bypass_xmit(struct sk_buff *skb, sEnterFunction (10 ); -if (ip_route_output_key (&init_net, &rt, &fl)) { +if (ip_route_output_key (net, &rt, &fl)) {IP_VS_DBG_RL ("%s(): ip_route_output error, dest: %pI4\n" , __func__, &iph->daddr); goto tx_error_icmp;@@ -313,25 +334,18 @@ int ip_vs_bypass_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp) { + struct net *net = dev_net(skb->dev); +struct dst_entry *dst;struct rt6_info *rt;/* Route to the other host */ struct ipv6hdr *iph =ipv6_hdr (skb);int mtu; -struct flowi fl = { - .oif =0 , - .nl_u = { - .ip6_u = { - .daddr = iph->daddr, - .saddr = { .s6_addr32 = {0 ,0 ,0 ,0 } }, } }, - };EnterFunction (10 ); - rt = (struct rt6_info *)ip6_route_output (&init_net,NULL , &fl); -if (!rt) { -IP_VS_DBG_RL ("%s(): ip6_route_output error, dest: %pI6\n" , - __func__, &iph->daddr); + dst =__ip_vs_route_output_v6 (net, &iph->daddr,NULL ,0 ); +if (!dst) goto tx_error_icmp; - } + rt = (struct rt6_info *) dst;/* MTU checking */ mtu =dst_mtu (&rt->dst);@@ -397,7 +411,7 @@ ip_vs_nat_xmit(struct sk_buff *skb, struIP_VS_DBG (10 ,"filled cport=%d\n" ,ntohs (*p)); } -if (!(rt =__ip_vs_get_out_rt (cp,RT_TOS (iph->tos)))) +if (!(rt =__ip_vs_get_out_rt (skb, cp,RT_TOS (iph->tos)))) goto tx_error_icmp;/* MTU checking */ @@ -472,7 +486,7 @@ ip_vs_nat_xmit_v6(struct sk_buff *skb, sIP_VS_DBG (10 ,"filled cport=%d\n" ,ntohs (*p)); } - rt =__ip_vs_get_out_rt_v6 (cp); + rt =__ip_vs_get_out_rt_v6 (skb, cp,NULL ,0 );if (!rt) goto tx_error_icmp;@@ -557,7 +571,6 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, sstruct iphdr *old_iph =ip_hdr (skb);u8 tos = old_iph->tos;__be16 df = old_iph->frag_off; -sk_buff_data_t old_transport_header = skb->transport_header;struct iphdr *iph;/* Our new IP header */ unsigned int max_headroom;/* The extra header space needed */ int mtu;@@ -572,7 +585,7 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, s goto tx_error; } -if (!(rt =__ip_vs_get_out_rt (cp,RT_TOS (tos)))) +if (!(rt =__ip_vs_get_out_rt (skb, cp,RT_TOS (tos)))) goto tx_error_icmp; tdev = rt->dst.dev;@@ -616,7 +629,7 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, s old_iph =ip_hdr (skb); } - skb->transport_header = old_transport_header; + skb->transport_header = skb->network_header;/* fix old IP header checksum */ ip_send_check (old_iph);@@ -670,9 +683,9 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb struct ip_vs_protocol *pp) {struct rt6_info *rt;/* Route to the other host */ +struct in6_addr saddr;/* Source for tunnel */ struct net_device *tdev;/* Device to other host */ struct ipv6hdr *old_iph =ipv6_hdr (skb); -sk_buff_data_t old_transport_header = skb->transport_header;struct ipv6hdr *iph;/* Our new IP header */ unsigned int max_headroom;/* The extra header space needed */ int mtu;@@ -687,17 +700,17 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb goto tx_error; } - rt =__ip_vs_get_out_rt_v6 (cp); + rt =__ip_vs_get_out_rt_v6 (skb, cp, &saddr,1 );if (!rt) goto tx_error_icmp; tdev = rt->dst.dev; mtu =dst_mtu (&rt->dst) -sizeof (struct ipv6hdr ); -/* TODO IPv6: do we need this check in IPv6? */ -if (mtu <1280 ) { +if (mtu <IPV6_MIN_MTU ) {dst_release (&rt->dst); -IP_VS_DBG_RL ("%s(): mtu less than 1280\n" , __func__); +IP_VS_DBG_RL ("%s(): mtu less than %d\n" , __func__, +IPV6_MIN_MTU ); goto tx_error; }if (skb_dst (skb))@@ -730,7 +743,7 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb old_iph =ipv6_hdr (skb); } - skb->transport_header = old_transport_header; + skb->transport_header = skb->network_header;skb_push (skb,sizeof (struct ipv6hdr ));skb_reset_network_header (skb);@@ -750,8 +763,8 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skbbe16_add_cpu (&iph->payload_len,sizeof (*old_iph)); iph->priority = old_iph->priority;memset (&iph->flow_lbl,0 ,sizeof (iph->flow_lbl)); - iph->daddr = rt->rt6i_dst.addr; - iph->saddr = cp->vaddr.in6;/* rt->rt6i_src.addr; */ +ipv6_addr_copy (&iph->daddr, &rt->rt6i_dst.addr); +ipv6_addr_copy (&iph->saddr, &saddr); iph->hop_limit = old_iph->hop_limit;/* Another hack: avoid icmp_send in ip_fragment */ @@ -791,7 +804,7 @@ ip_vs_dr_xmit(struct sk_buff *skb, strucEnterFunction (10 ); -if (!(rt =__ip_vs_get_out_rt (cp,RT_TOS (iph->tos)))) +if (!(rt =__ip_vs_get_out_rt (skb, cp,RT_TOS (iph->tos)))) goto tx_error_icmp;/* MTU checking */ @@ -843,7 +856,7 @@ ip_vs_dr_xmit_v6(struct sk_buff *skb, stEnterFunction (10 ); - rt =__ip_vs_get_out_rt_v6 (cp); + rt =__ip_vs_get_out_rt_v6 (skb, cp,NULL ,0 );if (!rt) goto tx_error_icmp;@@ -919,7 +932,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, str* mangle and send the packet here (only for VS/NAT) */ -if (!(rt =__ip_vs_get_out_rt (cp,RT_TOS (ip_hdr (skb)->tos)))) +if (!(rt =__ip_vs_get_out_rt (skb, cp,RT_TOS (ip_hdr (skb)->tos)))) goto tx_error_icmp;/* MTU checking */
net/netfilter/ipvs/ip_vs_xmit.c ip_vs_icmp_xmit_v6(struct sk_buff *skb, · line 1012
Quoted 8 lines
net/netfilter/ipvs/ip_vs_xmit.c renamed from linux/net/netfilter/ipvs/ip_vs_xmit.c +1
-1@@ -993,7 +1006,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb,* mangle and send the packet here (only for VS/NAT) */ - rt =__ip_vs_get_out_rt_v6 (cp); + rt =__ip_vs_get_out_rt_v6 (skb, cp,NULL ,0 );if (!rt) goto tx_error_icmp;
Looks good to me
Regards
--
Julian Anastasov <[email protected]>
Hello
I think this patch should be stopped since it doesn't work in some cases.
There is also a bug in the patch.ip6_route_output() returns a key as dest address
which can be a network and that's not a good dest address.
(It can be seen if the tunnel remote endpoint has to pass through an router/gateway)
@@ -750,8 +763,8 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb
...
...
- ipv6_addr_copy(&iph->daddr, &rt->rt6i_dst.addr);
+ ipv6_addr_copy(&iph->daddr, &cp->dest->addr.in6);
The principle for it is wrong, it's more or less impossible to get the expected address from ipv6_get_saddr_eval(), depending on your network topology.
Since there must be an address set on the remote/local pair for a IPv6 tunnel and you can't predict what source address you will get the function is more or less useless.
After spending a day single stepping through the IPv6 stack I'm more or less sure that:
- The only way to get IPv6 tunnels to work in a predictable way is to
add a "tunnel source address" to the ipvsadm commad.
What to do ?
- add a --tunsrc switch to ipvsadm -i command ?
or
- Disable the IPv6 tunnel mode ?
or
- Leave it as is ?
Regards
Hans Schillstrom <[email protected]>
Quoted 476 lines · Julian Anastasov
Hello,
Quoted 457 lines · Simon Horman
From: Julian Anastasov <[email protected]>
Tunnel mode for IPv6 doesn't work.
IPv6 encapsulation uses a bad source address for the tunnel. i.e. VIP will be used as local-addr and encap. dst addr. Decapsulation will not accept this.
Example
LVS (eth1 2003::2:0:1/96, VIP 2003::2:0:100)
(eth0 2003::1:0:1/96)
RS (ethX 2003::1:0:5/96)tcpdump
2003::2:0:100 > 2003::1:0:5:
IP6 (hlim 63, next-header TCP (6) payload length: 40) 2003::3:0:10.50991 > 2003::2:0:100.http: Flags [S], cksum0x7312(correct), seq 3006460279, win 5760, options [mss 1440,sackOK,TS val 1904932 ecr 0,nop,wscale 3], length 0In Linux IPv6 impl. you can't have a tunnel with an any cast address receiving packets (I have not tried to interpret RFC 2473) To have receive capabilities the tunnel must have:
- Local address set as multicast addr or an unicast addr
- Remote address set as an unicast addr.
- Loop back addres or Link local address are not allowed.This causes us to setup a tunnel in the Real Server with the LVS as the remote address, here you can't use the VIP address since it's used inside the tunnel.
Solution
Use outgoing interface IPv6 address (match against the destination). i.e. useip6_route_output()to look up the route cache and then useipv6_dev_get_saddr(...)to set the source address of the encapsulated packet.Additionally, cache the results in new destination
fields:dst_cookieanddst_saddrand properly check the returned dst fromip6_route_output. We now addxfrm_lookupcall only for the tunneling method where the source address is a local one.Original patch by Hans Schillstrom.
Check dst state and cache results for IPv6 by Julian Anastasov.Tested-by Hans Schillstrom <[email protected]>Signed-off-by Julian Anastasov <[email protected]>Signed-off-by Simon Horman <[email protected]>---
* v1
This is Julian's patch with a slightly edited version of the description from Hans's original patch.
* v2
Updated changelog as per commends from Julian
Is everyone ok with pushing this?
diff -urp
net-next-2.6-e548833-nfct_snat_reroute/linux/include/net/ip_vs.hlinux/include/net/ip_vs.hinclude/net/ip_vs.h 2010-09-22 10:50:18.548963467 +0300 renamed from linux/include/net/ip_vs.h 2010-09-16 09:03:48.000000000 +0300 +4
-0@@ -509,6 +509,10 @@ struct ip_vs_dest { spinlock_t dst_lock; /* lock of dst_cache */ struct dst_entry *dst_cache; /* destination cache entry */ u32 dst_rtos; /* RT_TOS(tos) for dst */ + u32 dst_cookie; +#ifdef CONFIG_IP_VS_IPV6 + struct in6_addr dst_saddr; +#endif /* for virtual service */ struct ip_vs_service *svc; /* service it belongs to */diff -urp
net-next-2.6-e548833-nfct_snat_reroute/linux/net/netfilter/ipvs/ip_vs_xmit.clinux/net/netfilter/ipvs/ip_vs_xmit.cnet/netfilter/ipvs/ip_vs_xmit.c 2010-09-22 16:29:43.271964521 +0300 renamed from linux/net/netfilter/ipvs/ip_vs_xmit.c 2010-09-16 09:02:25.000000000 +0300 +1
-0@@ -26,6 +26,7 @@ #include <net/route.h> /* for ip_route_output */ #include <net/ipv6.h> #include <net/ip6_route.h> +#include <net/addrconf.h> #include <linux/icmpv6.h> #include <linux/netfilter.h> #include <linux/netfilter_ipv4.h>@@ -37,26 +38,27 @@ * Destination cache to speed up outgoing route lookup */static inline void
net/netfilter/ipvs/ip_vs_xmit.c 2010-09-22 16:29:43.271964521 +0300 renamed from linux/net/netfilter/ipvs/ip_vs_xmit.c 2010-09-16 09:02:25.000000000 +0300 +2
-1-__ip_vs_dst_set(struct ip_vs_dest *dest, u32 rtos, struct dst_entry *dst) +__ip_vs_dst_set(struct ip_vs_dest *dest, u32 rtos, struct dst_entry *dst, + u32 dst_cookie){ struct dst_entry *old_dst; old_dst = dest->dst_cache; dest->dst_cache = dst; dest->dst_rtos = rtos; + dest->dst_cookie = dst_cookie; dst_release(old_dst); }static inline struct
dst_entry*net/netfilter/ipvs/ip_vs_xmit.c 2010-09-22 16:29:43.271964521 +0300 renamed from linux/net/netfilter/ipvs/ip_vs_xmit.c 2010-09-16 09:02:25.000000000 +0300 +1
-1-__ip_vs_dst_check(struct ip_vs_dest *dest, u32 rtos, u32 cookie) +__ip_vs_dst_check(struct ip_vs_dest *dest, u32 rtos){ struct dst_entry *dst = dest->dst_cache; if (!dst) return NULL;net/netfilter/ipvs/ip_vs_xmit.c 2010-09-22 16:29:43.271964521 +0300 renamed from linux/net/netfilter/ipvs/ip_vs_xmit.c 2010-09-16 09:02:25.000000000 +0300 +2
-3- if ((dst->obsolete - || (dest->af == AF_INET && rtos != dest->dst_rtos)) && - dst->ops->check(dst, cookie) == NULL) { + if ((dst->obsolete || rtos != dest->dst_rtos) && + dst->ops->check(dst, dest->dst_cookie) == NULL) { dest->dst_cache = NULL; dst_release(dst); return NULL;@@ -66,15 +68,16 @@ __ip_vs_dst_check(struct ip_vs_dest *des }static struct rtable *
net/netfilter/ipvs/ip_vs_xmit.c 2010-09-22 16:29:43.271964521 +0300 renamed from linux/net/netfilter/ipvs/ip_vs_xmit.c 2010-09-16 09:02:25.000000000 +0300 +1
-1-__ip_vs_get_out_rt(struct ip_vs_conn *cp, u32 rtos) +__ip_vs_get_out_rt(struct sk_buff *skb, struct ip_vs_conn *cp, u32 rtos){
net/netfilter/ipvs/ip_vs_xmit.c 2010-09-22 16:29:43.271964521 +0300 renamed from linux/net/netfilter/ipvs/ip_vs_xmit.c 2010-09-16 09:02:25.000000000 +0300 +40
-4+ struct net *net = dev_net(skb->dev); struct rtable *rt; /* Route to the other host */ struct ip_vs_dest *dest = cp->dest; if (dest) { spin_lock(&dest->dst_lock); if (!(rt = (struct rtable *) - __ip_vs_dst_check(dest, rtos, 0))) { + __ip_vs_dst_check(dest, rtos))) { struct flowi fl = { .oif = 0, .nl_u = {@@ -84,13 +87,13 @@ __ip_vs_get_out_rt(struct ip_vs_conn *cp .tos = rtos, } }, }; - if (ip_route_output_key(&init_net, &rt, &fl)) { + if (ip_route_output_key(net, &rt, &fl)) { spin_unlock(&dest->dst_lock); IP_VS_DBG_RL("ip_route_output error, dest: %pI4\n", &dest->addr.ip); return NULL; } - __ip_vs_dst_set(dest, rtos, dst_clone(&rt->dst)); + __ip_vs_dst_set(dest, rtos, dst_clone(&rt->dst), 0); IP_VS_DBG(10, "new dst %pI4, refcnt=%d, rtos=%X\n", &dest->addr.ip, atomic_read(&rt->dst.__refcnt), rtos);@@ -106,7 +109,7 @@ __ip_vs_get_out_rt(struct ip_vs_conn *cp .tos = rtos, } }, }; - if (ip_route_output_key(&init_net, &rt, &fl)) { + if (ip_route_output_key(net, &rt, &fl)) { IP_VS_DBG_RL("ip_route_output error, dest: %pI4\n", &cp->daddr.ip); return NULL;@@ -117,62 +120,79 @@ __ip_vs_get_out_rt(struct ip_vs_conn *cp } #ifdef CONFIG_IP_VS_IPV6 + +static struct dst_entry * +__ip_vs_route_output_v6(struct net *net, struct in6_addr *daddr, + struct in6_addr *ret_saddr, int do_xfrm) +{ + struct dst_entry *dst; + struct flowi fl = { + .oif = 0, + .nl_u = { + .ip6_u = { + .daddr = *daddr, + }, + }, + }; + + dst = ip6_route_output(net, NULL, &fl); + if (dst->error) + goto out_err; + if (!ret_saddr) + return dst; + if (ipv6_addr_any(&fl.fl6_src) && + ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev, + &fl.fl6_dst, 0, &fl.fl6_src) < 0) + goto out_err; + if (do_xfrm && xfrm_lookup(net, &dst, &fl, NULL, 0) < 0) + goto out_err; + ipv6_addr_copy(ret_saddr, &fl.fl6_src); + return dst; + +out_err: + dst_release(dst); + IP_VS_DBG_RL("ip6_route_output error, dest: %pI6\n", daddr); + return NULL; +} +static struct
rt6_info*net/netfilter/ipvs/ip_vs_xmit.c 2010-09-22 16:29:43.271964521 +0300 renamed from linux/net/netfilter/ipvs/ip_vs_xmit.c 2010-09-16 09:02:25.000000000 +0300 +2
-1-__ip_vs_get_out_rt_v6(struct ip_vs_conn *cp) +__ip_vs_get_out_rt_v6(struct sk_buff *skb, struct ip_vs_conn *cp, + struct in6_addr *ret_saddr, int do_xfrm){
net/netfilter/ipvs/ip_vs_xmit.c 2010-09-22 16:29:43.271964521 +0300 renamed from linux/net/netfilter/ipvs/ip_vs_xmit.c 2010-09-16 09:02:25.000000000 +0300 +41
-67+ struct net *net = dev_net(skb->dev); struct rt6_info *rt; /* Route to the other host */ struct ip_vs_dest *dest = cp->dest; + struct dst_entry *dst; if (dest) { spin_lock(&dest->dst_lock); - rt = (struct rt6_info *)__ip_vs_dst_check(dest, 0, 0); + rt = (struct rt6_info *)__ip_vs_dst_check(dest, 0); if (!rt) { - struct flowi fl = { - .oif = 0, - .nl_u = { - .ip6_u = { - .daddr = dest->addr.in6, - .saddr = { - .s6_addr32 = - { 0, 0, 0, 0 }, - }, - }, - }, - }; + u32 cookie; - rt = (struct rt6_info *)ip6_route_output(&init_net, - NULL, &fl); - if (!rt) { + dst = __ip_vs_route_output_v6(net, &dest->addr.in6, + &dest->dst_saddr, + do_xfrm); + if (!dst) { spin_unlock(&dest->dst_lock); - IP_VS_DBG_RL("ip6_route_output error, dest: %pI6\n", - &dest->addr.in6); return NULL; } - __ip_vs_dst_set(dest, 0, dst_clone(&rt->dst)); - IP_VS_DBG(10, "new dst %pI6, refcnt=%d\n", - &dest->addr.in6, + rt = (struct rt6_info *) dst; + cookie = rt->rt6i_node ? rt->rt6i_node->fn_sernum : 0; + __ip_vs_dst_set(dest, 0, dst_clone(&rt->dst), cookie); + IP_VS_DBG(10, "new dst %pI6, src %pI6, refcnt=%d\n", + &dest->addr.in6, &dest->dst_saddr, atomic_read(&rt->dst.__refcnt)); } + if (ret_saddr) + ipv6_addr_copy(ret_saddr, &dest->dst_saddr); spin_unlock(&dest->dst_lock); } else { - struct flowi fl = { - .oif = 0, - .nl_u = { - .ip6_u = { - .daddr = cp->daddr.in6, - .saddr = { - .s6_addr32 = { 0, 0, 0, 0 }, - }, - }, - }, - }; - - rt = (struct rt6_info *)ip6_route_output(&init_net, NULL, &fl); - if (!rt) { - IP_VS_DBG_RL("ip6_route_output error, dest: %pI6\n", - &cp->daddr.in6); + dst = __ip_vs_route_output_v6(net, &cp->daddr.in6, ret_saddr, + do_xfrm); + if (!dst) return NULL; - } + rt = (struct rt6_info *) dst; } return rt;@@ -248,6 +268,7 @@ int ip_vs_bypass_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp) { + struct net *net = dev_net(skb->dev); struct rtable *rt; /* Route to the other host */ struct iphdr *iph = ip_hdr(skb); u8 tos = iph->tos;@@ -263,7 +284,7 @@ ip_vs_bypass_xmit(struct sk_buff *skb, s EnterFunction(10); - if (ip_route_output_key(&init_net, &rt, &fl)) { + if (ip_route_output_key(net, &rt, &fl)) { IP_VS_DBG_RL("%s(): ip_route_output error, dest: %pI4\n", __func__, &iph->daddr); goto tx_error_icmp;@@ -313,25 +334,18 @@ int ip_vs_bypass_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp) { + struct net *net = dev_net(skb->dev); + struct dst_entry *dst; struct rt6_info *rt; /* Route to the other host */ struct ipv6hdr *iph = ipv6_hdr(skb); int mtu; - struct flowi fl = { - .oif = 0, - .nl_u = { - .ip6_u = { - .daddr = iph->daddr, - .saddr = { .s6_addr32 = {0, 0, 0, 0} }, } }, - }; EnterFunction(10); - rt = (struct rt6_info *)ip6_route_output(&init_net, NULL, &fl); - if (!rt) { - IP_VS_DBG_RL("%s(): ip6_route_output error, dest: %pI6\n", - __func__, &iph->daddr); + dst = __ip_vs_route_output_v6(net, &iph->daddr, NULL, 0); + if (!dst) goto tx_error_icmp; - } + rt = (struct rt6_info *) dst; /* MTU checking */ mtu = dst_mtu(&rt->dst);@@ -397,7 +411,7 @@ ip_vs_nat_xmit(struct sk_buff *skb, stru IP_VS_DBG(10, "filled cport=%d\n", ntohs(*p)); } - if (!(rt = __ip_vs_get_out_rt(cp, RT_TOS(iph->tos)))) + if (!(rt = __ip_vs_get_out_rt(skb, cp, RT_TOS(iph->tos)))) goto tx_error_icmp; /* MTU checking */@@ -472,7 +486,7 @@ ip_vs_nat_xmit_v6(struct sk_buff *skb, s IP_VS_DBG(10, "filled cport=%d\n", ntohs(*p)); } - rt = __ip_vs_get_out_rt_v6(cp); + rt = __ip_vs_get_out_rt_v6(skb, cp, NULL, 0); if (!rt) goto tx_error_icmp;@@ -557,7 +571,6 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, s struct iphdr *old_iph = ip_hdr(skb); u8 tos = old_iph->tos; __be16 df = old_iph->frag_off; - sk_buff_data_t old_transport_header = skb->transport_header; struct iphdr *iph; /* Our new IP header */ unsigned int max_headroom; /* The extra header space needed */ int mtu;@@ -572,7 +585,7 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, s goto tx_error; } - if (!(rt = __ip_vs_get_out_rt(cp, RT_TOS(tos)))) + if (!(rt = __ip_vs_get_out_rt(skb, cp, RT_TOS(tos)))) goto tx_error_icmp; tdev = rt->dst.dev;@@ -616,7 +629,7 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, s old_iph = ip_hdr(skb); } - skb->transport_header = old_transport_header; + skb->transport_header = skb->network_header; /* fix old IP header checksum */ ip_send_check(old_iph);@@ -670,9 +683,9 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb struct ip_vs_protocol *pp) { struct rt6_info *rt; /* Route to the other host */ + struct in6_addr saddr; /* Source for tunnel */ struct net_device *tdev; /* Device to other host */ struct ipv6hdr *old_iph = ipv6_hdr(skb); - sk_buff_data_t old_transport_header = skb->transport_header; struct ipv6hdr *iph; /* Our new IP header */ unsigned int max_headroom; /* The extra header space needed */ int mtu;@@ -687,17 +700,17 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb goto tx_error; } - rt = __ip_vs_get_out_rt_v6(cp); + rt = __ip_vs_get_out_rt_v6(skb, cp, &saddr, 1); if (!rt) goto tx_error_icmp; tdev = rt->dst.dev; mtu = dst_mtu(&rt->dst) - sizeof(struct ipv6hdr); - /* TODO IPv6: do we need this check in IPv6? */ - if (mtu < 1280) { + if (mtu < IPV6_MIN_MTU) { dst_release(&rt->dst); - IP_VS_DBG_RL("%s(): mtu less than 1280\n", __func__); + IP_VS_DBG_RL("%s(): mtu less than %d\n", __func__, + IPV6_MIN_MTU); goto tx_error; } if (skb_dst(skb))@@ -730,7 +743,7 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb old_iph = ipv6_hdr(skb); } - skb->transport_header = old_transport_header; + skb->transport_header = skb->network_header; skb_push(skb, sizeof(struct ipv6hdr)); skb_reset_network_header(skb);@@ -750,8 +763,8 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb be16_add_cpu(&iph->payload_len, sizeof(*old_iph)); iph->priority = old_iph->priority; memset(&iph->flow_lbl, 0, sizeof(iph->flow_lbl)); - iph->daddr = rt->rt6i_dst.addr; - iph->saddr = cp->vaddr.in6; /* rt->rt6i_src.addr; */ + ipv6_addr_copy(&iph->daddr, &rt->rt6i_dst.addr); + ipv6_addr_copy(&iph->saddr, &saddr); iph->hop_limit = old_iph->hop_limit; /* Another hack: avoid icmp_send in ip_fragment */@@ -791,7 +804,7 @@ ip_vs_dr_xmit(struct sk_buff *skb, struc EnterFunction(10); - if (!(rt = __ip_vs_get_out_rt(cp, RT_TOS(iph->tos)))) + if (!(rt = __ip_vs_get_out_rt(skb, cp, RT_TOS(iph->tos)))) goto tx_error_icmp; /* MTU checking */@@ -843,7 +856,7 @@ ip_vs_dr_xmit_v6(struct sk_buff *skb, st EnterFunction(10); - rt = __ip_vs_get_out_rt_v6(cp); + rt = __ip_vs_get_out_rt_v6(skb, cp, NULL, 0); if (!rt) goto tx_error_icmp;@@ -919,7 +932,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, str * mangle and send the packet here (only for VS/NAT) */ - if (!(rt = __ip_vs_get_out_rt(cp, RT_TOS(ip_hdr(skb)->tos)))) + if (!(rt = __ip_vs_get_out_rt(skb, cp, RT_TOS(ip_hdr(skb)->tos)))) goto tx_error_icmp; /* MTU checking */net/netfilter/ipvs/ip_vs_xmit.c 2010-09-22 16:29:43.271964521 +0300 ip_vs_icmp_xmit_v6(struct sk_buff *skb, · line 1012
Quoted 8 lines
net/netfilter/ipvs/ip_vs_xmit.c 2010-09-22 16:29:43.271964521 +0300 renamed from linux/net/netfilter/ipvs/ip_vs_xmit.c 2010-09-16 09:02:25.000000000 +0300 +1
-1@@ -993,7 +1006,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, * mangle and send the packet here (only for VS/NAT) */ - rt = __ip_vs_get_out_rt_v6(cp); + rt = __ip_vs_get_out_rt_v6(skb, cp, NULL, 0); if (!rt) goto tx_error_icmp;Looks good to me
Regards
--
Julian Anastasov <[email protected]>
Julian Anastasov
maintainerHello,
Quoted 3 lines · Hans Schillstrom
Hello
I think this patch should be stopped since it doesn't work in some cases.
I think, the patch is still correct. May be we
just need to create new patch to fix the remaining problems which are old (rt6i_dst use).
Quoted 5 lines
There is also a bug in the patch.
ip6_route_output()returns a key as dest address
which can be a network and that's not a good dest address. (It can be seen if the tunnel remote endpoint has to pass through an router/gateway)
You are referring to rt6i_dst?
Review ip_vs_tunnel_xmit_v6(struct sk_buff *skb
Quoted 5 lines
(quoted diff) +1
-1@@ -750,8 +763,8 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb - ipv6_addr_copy(&iph->daddr, &rt->rt6i_dst.addr); + ipv6_addr_copy(&iph->daddr, &cp->dest->addr.in6);
I prefer not to risk with cp->dest, see below.
May be ipv6_addr_copy(&iph->daddr, &cp->daddr.in6); is safer. But we still can add more checks for the daddr type one day when backup supports IPv6.
- both rt6_alloc_cow and rt6_alloc_clone copy our fl->fl6_dst into rt6i_dst. Only that CLONE_OFFLINK_ROUTE is not 1 and I'm not sure what happens with rt6i_dst in this case (ip6_pol_route). May be you see the route prefix there as set by ip6_route_add?
Quoted 7 lines
The principle for it is wrong, it's more or less impossible to get the expected address from
ipv6_get_saddr_eval(), depending on your network topology.Since there must be an address set on the remote/local pair for a IPv6 tunnel and you can't predict what source address you will get the function is more or less useless.
Yes, for IPv6 I don't see option in tunnel to accept
traffic from any remote address. This was not the case with IPv4. But the source address selection is rich enough. I don't know for any example settings for IPVS on IPv6 but routes in IPv6 can have source address if CONFIG_IPV6_SUBTREES is defined (ip6_route_add). Still, the routing should be able to return valid source address. I don't know what settings you are using but looking at code I think the options are:
- assign source address for route
- add VIPs as deprecated addresses (prefered_lft=0). By this way we don't risk they to be autoselected as source in output routes because they are ignored in ipv6_get_saddr_eval at step IPV6_SADDR_RULE_PREFERRED
As result, the source address should be properly
selected and our patch looks ok for the saddr part.
Quoted 4 lines
After spending a day single stepping through the IPv6 stack I'm more or less sure that:
- The only way to get IPv6 tunnels to work in a predictable way is to add a "tunnel source address" to the ipvsadm commad.
This is not possible for the case when cp->dest is
NULL, eg. when connection using fwmarks is moved to backup server. But this does not happen because IPv6 is not supported for sync. If one day we add support in new sync format I'm sure there will be also fwmark and cp->dest will be valid for the tunneling method.
Quoted 6 lines
What to do ?
- add a --tunsrc switch to ipvsadm -i command ?
or
- Disable the IPv6 tunnel mode ?
or
- Leave it as is ?
This 3th option is better for the moment. I think,
saddr is selected correctly, see ip6_dst_lookup() and ip6_dst_lookup_tail() in net/ipv6/ip6_output.c
But if you think using ipv6_addr_copy(&iph->daddr, &cp->daddr.in6); is working then feel free to post a patch on top of
the previous patch. Because other code in kernel uses resulting fl.fl6_dst, not rt6i_dst.
Regards
--
Julian Anastasov <[email protected]>
Hello
Quoted 12 lines · Julian Anastasov
Hello,
Quoted 3 lines · Hans Schillstrom
Hello
I think this patch should be stopped since it doesn't work in some cases.I think, the patch is still correct. May be we
just need to create new patch to fix the remaining problems which are old (rt6i_dstuse).
Quoted 7 lines
Quoted 5 lines
There is also a bug in the patch.
ip6_route_output()returns a key as dest address
which can be a network and that's not a good dest address. (It can be seen if the tunnel remote endpoint has to pass through an router/gateway)You are referring to
rt6i_dst?
Yes
Quoted 12 lines
Review ip_vs_tunnel_xmit_v6(struct sk_buff *skb
Quoted 6 lines
(quoted diff) +1
-1@@ -750,8 +763,8 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb - ipv6_addr_copy(&iph->daddr, &rt->rt6i_dst.addr); + ipv6_addr_copy(&iph->daddr, &cp->dest->addr.in6);I prefer not to risk with
cp->dest, see below.
May beipv6_addr_copy(&iph->daddr, &cp->daddr.in6); is safer. But we still can add more checks for the daddr type one day when backup supports IPv6.
Quoted 5 lines
- both
rt6_alloc_cowandrt6_alloc_clonecopy ourfl->fl6_dstintort6i_dst. Only thatCLONE_OFFLINK_ROUTEis not 1 and I'm not sure what happens withrt6i_dstin this case (ip6_pol_route). May be you see the route prefix there as set byip6_route_add?
Yes, the destination network
Quoted 21 lines
Quoted 8 lines
The principle for it is wrong, it's more or less impossible to get the expected address from
ipv6_get_saddr_eval(), depending on your network topology.Since there must be an address set on the remote/local pair for a IPv6 tunnel and you can't predict what source address you will get the function is more or less useless.
Yes, for IPv6 I don't see option in tunnel to accept
traffic from any remote address. This was not the case with IPv4. But the source address selection is rich enough. I don't know for any example settings for IPVS on IPv6 but routes in IPv6 can have source address ifCONFIG_IPV6_SUBTREESis defined (ip6_route_add). Still, the routing should be able to return valid source address. I don't know what settings you are using but looking at code I think the options are:- assign source address for route
Quoted 7 lines
- add VIPs as deprecated addresses (prefered_lft=0). By this way we don't risk they to be autoselected as source in output routes because they are ignored in
ipv6_get_saddr_evalat stepIPV6_SADDR_RULE_PREFERREDAs result, the source address should be properly
selected and our patch looks ok for the saddr part.
Yes you're right as usual :-)
With "prefered_lft=0" src selection works in most cases now. So this is not an issue any more.
Quoted 20 lines
Quoted 5 lines
After spending a day single stepping through the IPv6 stack I'm more or less sure that:
- The only way to get IPv6 tunnels to work in a predictable way is to add a "tunnel source address" to the ipvsadm commad.This is not possible for the case when
cp->destis
NULL, eg. when connection using fwmarks is moved to backup server. But this does not happen because IPv6 is not supported for sync. If one day we add support in new sync format I'm sure there will be also fwmark andcp->destwill be valid for the tunneling method.Quoted 6 lines
What to do ?
- add a --tunsrc switch to ipvsadm -i command ?
or
- Disable the IPv6 tunnel mode ?
or
- Leave it as is ?
Quoted 7 lines
This 3th option is better for the moment. I think,
saddr is selected correctly, seeip6_dst_lookup()andip6_dst_lookup_tail()innet/ipv6/ip6_output.c
But if you think usingipv6_addr_copy(&iph->daddr, &cp->daddr.in6); is working then feel free to post a patch on top of
the previous patch. Because other code in kernel uses resulting fl.fl6_dst, notrt6i_dst.
I prefer fl.fl6_dst right now since rt6i_dst gives a bad destination in many cases.
I will do some more testing before posting the patch.
Quoted 5 lines
Regards
--
Julian Anastasov <[email protected]>
Julian Anastasov
maintainerHello,
Quoted 10 lines · Hans Schillstrom
Quoted 9 lines
Quoted 1 line
- Leave it as is ?
This 3th option is better for the moment. I think,
saddr is selected correctly, seeip6_dst_lookup()andip6_dst_lookup_tail()innet/ipv6/ip6_output.c
But if you think usingipv6_addr_copy(&iph->daddr, &cp->daddr.in6); is working then feel free to post a patch on top of
the previous patch. Because other code in kernel uses resulting fl.fl6_dst, notrt6i_dst.
Quoted 4 lines
I prefer fl.fl6_dst right now since
rt6i_dstgives a bad destination in many cases.I will do some more testing before posting the patch.
ok, but note that now 'fl' is hidden in function
and not cached. I think fl.fl6_dst is read-only, so it should contain cp->daddr.in6 in all cases.
Regards
--
Julian Anastasov <[email protected]>
Slab corruption
Hi
Have you seen Slab corruption before ?
I got it when deleting a service when there is real-servers left
It's not related to IPv6 or fwmarks any "-D" causes it if there is rs attached for that service (and it's not bad RAM).
ex.
# ipvsadm -D -f 21 -6 Slab corruption: size-512 start=ffff880001760488, len=512 Redzone: 0x9f911029d74e35b/0x9f911029d74e35b. Last user: [<ffffffffa004aa3a>](__ip_vs_del_service+0xfa/0x108 [ip_vs]) 020: 6b 6b 6b 6b 6a 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b Single bit error detected. Probably bad RAM. Run memtest86+ or a similar memory test tool. Prev obj: start=ffff880001760270, len=512 Redzone: 0x9f911029d74e35b/0x9f911029d74e35b. Last user: [<ffffffff812b7a48>](skb_release_data+0xc1/0xc6) 000: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 010: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b Next obj: start=ffff8800017606a0, len=512 Redzone: 0xd84156c5635688c0/0xd84156c5635688c0. Last user: [<ffffffff812b3487>](sock_wmalloc+0x34/0x75) 000: 5a 5a 5a 5a 5a 5a 5a 5a 00 00 33 33 00 00 00 05 010: 00 00 02 01 01 01 86 dd 60 00 00 00 00 30 59 01
Signature · 2 lines
Regards Hans Schillstrom <[email protected]>
Julian Anastasov
maintainerRe: Slab corruption
Hello,
Quoted 5 lines · Hans Schillstrom
Hi
Have you seen Slab corruption before ?
I got it when deleting a service when there is real-servers left
It's not related to IPv6 or fwmarks any "-D" causes it if there is rs attached for that service (and it's not bad RAM).
Do you have this patch which is already in nf-next:
http://archive.linuxvirtualserver.org/html/lvs-devel/2010-09/threads.html#00039
static inline void ip_vs_service_put(struct ip_vs_service *svc)
{
atomic_dec(&svc->usecnt);
} There is one atomic_dec after free but I'm not sure
if it matches the dump below. If in doubt just add svc = NULL in ip_vs_genl_set_cmd after the call to ip_vs_del_service.
Quoted 10 lines
ex.
# ipvsadm -D -f 21 -6 Slab corruption: size-512 start=ffff880001760488, len=512 Redzone: 0x9f911029d74e35b/0x9f911029d74e35b. Last user: [<ffffffffa004aa3a>](__ip_vs_del_service+0xfa/0x108 [ip_vs]) 020: 6b 6b 6b 6b 6a 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b Single bit error detected. Probably bad RAM. Run memtest86+ or a similar memory test tool. Prev obj: start=ffff880001760270, len=512 Redzone: 0x9f911029d74e35b/0x9f911029d74e35b.
Quoted 8 lines
Last user: [<ffffffff812b7a48>](skb_release_data+0xc1/0xc6) 000: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 010: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b Next obj: start=ffff8800017606a0, len=512 Redzone: 0xd84156c5635688c0/0xd84156c5635688c0. Last user: [<ffffffff812b3487>](sock_wmalloc+0x34/0x75) 000: 5a 5a 5a 5a 5a 5a 5a 5a 00 00 33 33 00 00 00 05 010: 00 00 02 01 01 01 86 dd 60 00 00 00 00 30 59 01
Regards
--
Julian Anastasov <[email protected]>
Re: Slab corruption
Hello,
Quoted 5 lines · On Saturday 09 October 2010 13:23:29 Julian Anastasov wrote:
Hello,
On Thu, 7 Oct 2010, Hans Schillstrom wrote:
Quoted 7 lines
Quoted 5 lines
Hi
Have you seen Slab corruption before ?
I got it when deleting a service when there is real-servers left
It's not related to IPv6 or fwmarks any "-D" causes it if there is rs attached for that service (and it's not bad RAM).Do you have this patch which is already in nf-next:
Yes
Quoted 11 lines
http://archive.linuxvirtualserver.org/html/lvs-devel/2010-09/threads.html#00039
static inline void
ip_vs_service_put(struct ip_vs_service *svc){ atomic_dec(&svc->usecnt); }There is one
atomic_decafter free but I'm not sure
if it matches the dump below. If in doubt just add svc = NULL inip_vs_genl_set_cmdafter the call toip_vs_del_service.
added svc = NULL,
but it did not make any difference :-(
Quoted 25 lines
Quoted 11 lines
ex.
# ipvsadm -D -f 21 -6 Slab corruption: size-512 start=ffff880001760488, len=512 Redzone: 0x9f911029d74e35b/0x9f911029d74e35b. Last user: [<ffffffffa004aa3a>](__ip_vs_del_service+0xfa/0x108 [ip_vs]) 020: 6b 6b 6b 6b 6a 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b Single bit error detected. Probably bad RAM. Run memtest86+ or a similar memory test tool. Prev obj: start=ffff880001760270, len=512 Redzone: 0x9f911029d74e35b/0x9f911029d74e35b.Quoted 8 lines
Last user: [<ffffffff812b7a48>](skb_release_data+0xc1/0xc6) 000: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 010: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b Next obj: start=ffff8800017606a0, len=512 Redzone: 0xd84156c5635688c0/0xd84156c5635688c0. Last user: [<ffffffff812b3487>](sock_wmalloc+0x34/0x75) 000: 5a 5a 5a 5a 5a 5a 5a 5a 00 00 33 33 00 00 00 05 010: 00 00 02 01 01 01 86 dd 60 00 00 00 00 30 59 01Regards
--
Julian Anastasov <[email protected]>
Signature · 2 lines
Regards Hans Schillstrom <[email protected]>
Julian Anastasov
maintainerRe: Slab corruption
Hello,
Quoted 7 lines · Hans Schillstrom
Quoted 4 lines
There is one
atomic_decafter free but I'm not sure
if it matches the dump below. If in doubt just add svc = NULL inip_vs_genl_set_cmdafter the call toip_vs_del_service.added svc = NULL,
but it did not make any difference :-(
Do you see this message in debugs? Once or twice?
And with usecnt > 0?:
IP_VS_DBG_BUF(3, "Removing service %u/%s:%u usecnt=%d\n",
Also, do you have traffic or any connections
while removing the service? What is the result when there is no traffic?
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
ex.
# ipvsadm -D -f 21 -6 Slab corruption: size-512 start=ffff880001760488, len=512 Redzone: 0x9f911029d74e35b/0x9f911029d74e35b. Last user: [<ffffffffa004aa3a>](__ip_vs_del_service+0xfa/0x108 [ip_vs]) 020: 6b 6b 6b 6b 6a 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b
Is this offset 0x24? Can you determine which
field of struct ip_vs_service is on offset 0x24? It can be usecnt if platform is 64-bit.
Regards
--
Julian Anastasov <[email protected]>
Re: Slab corruption
Hello Julian,
Quoted 29 lines · On Monday 11 October 2010 22:36:47 Julian Anastasov wrote:
Hello,
Quoted 7 lines · Hans Schillstrom
Quoted 4 lines
There is one
atomic_decafter free but I'm not sure
if it matches the dump below. If in doubt just add svc = NULL inip_vs_genl_set_cmdafter the call toip_vs_del_service.added svc = NULL,
but it did not make any difference :-(Do you see this message in debugs? Once or twice?
And with usecnt > 0?:IP_VS_DBG_BUF(3, "Removing service %u/%s:%u usecnt=%d\n",
Also, do you have traffic or any connections
while removing the service? What is the result when there is no traffic?Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
ex.
# ipvsadm -D -f 21 -6 Slab corruption: size-512 start=ffff880001760488, len=512 Redzone: 0x9f911029d74e35b/0x9f911029d74e35b. Last user: [<ffffffffa004aa3a>](__ip_vs_del_service+0xfa/0x108 [ip_vs]) 020: 6b 6b 6b 6b 6a 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b
Quoted 4 lines
Is this offset
0x24? Can you determine which
field of structip_vs_serviceis on offset0x24? It can be usecnt if platform is 64-bit.
I am sorry, I made a mistake
I verified that the patch was in my nf-next-2.6 clone but I was running Dave Millers net-next-2.6...
I will switch to nf-next-2.6 and run my tests again
(with the patch included)
Anyway you was right, usecnt is at offset 0x24 on my 64 bit machine.
I will post the results today or to morrow.
Quoted 5 lines
Regards
--
Julian Anastasov <[email protected]>
Signature · 2 lines
Regards Hans Schillstrom <[email protected]>
Hello,
Quoted 457 lines · Simon Horman
From: Julian Anastasov <[email protected]>
Tunnel mode for IPv6 doesn't work.
IPv6 encapsulation uses a bad source address for the tunnel. i.e. VIP will be used as local-addr and encap. dst addr. Decapsulation will not accept this.
Example
LVS (eth1 2003::2:0:1/96, VIP 2003::2:0:100)
(eth0 2003::1:0:1/96)
RS (ethX 2003::1:0:5/96)tcpdump
2003::2:0:100 > 2003::1:0:5:
IP6 (hlim 63, next-header TCP (6) payload length: 40)
2003::3:0:10.50991 > 2003::2:0:100.http: Flags [S], cksum0x7312
(correct), seq 3006460279, win 5760, options [mss 1440,sackOK,TS val 1904932 ecr 0,nop,wscale 3], length 0In Linux IPv6 impl. you can't have a tunnel with an any cast address receiving packets (I have not tried to interpret RFC 2473) To have receive capabilities the tunnel must have:
- Local address set as multicast addr or an unicast addr
- Remote address set as an unicast addr.
- Loop back addres or Link local address are not allowed.This causes us to setup a tunnel in the Real Server with the LVS as the remote address, here you can't use the VIP address since it's used inside the tunnel.
Solution
Use outgoing interface IPv6 address (match against the destination). i.e. useip6_route_output()to look up the route cache and then useipv6_dev_get_saddr(...)to set the source address of the encapsulated packet.Additionally, cache the results in new destination
fields:dst_cookieanddst_saddrand properly check the returned dst fromip6_route_output. We now addxfrm_lookupcall only for the tunneling method where the source address is a local one.Original patch by Hans Schillstrom.
Check dst state and cache results for IPv6 by Julian Anastasov.Tested-by Hans Schillstrom <[email protected]>Signed-off-by Julian Anastasov <[email protected]>Signed-off-by Simon Horman <[email protected]>---
* v1
This is Julian's patch with a slightly edited version of the description from Hans's original patch.
* v2
Updated changelog as per commends from Julian
Is everyone ok with pushing this?
diff -urp
net-next-2.6-e548833-nfct_snat_reroute/linux/include/net/ip_vs.hlinux/include/net/ip_vs.hinclude/net/ip_vs.h 2010-09-22 10:50:18.548963467 +0300 renamed from linux/include/net/ip_vs.h 2010-09-16 09:03:48.000000000 +0300 +4
-0@@ -509,6 +509,10 @@ struct ip_vs_dest { spinlock_t dst_lock; /* lock of dst_cache */ struct dst_entry *dst_cache; /* destination cache entry */ u32 dst_rtos; /* RT_TOS(tos) for dst */ + u32 dst_cookie; +#ifdef CONFIG_IP_VS_IPV6 + struct in6_addr dst_saddr; +#endif /* for virtual service */ struct ip_vs_service *svc; /* service it belongs to */diff -urp
net-next-2.6-e548833-nfct_snat_reroute/linux/net/netfilter/ipvs/ip_vs_xmit.clinux/net/netfilter/ipvs/ip_vs_xmit.cnet/netfilter/ipvs/ip_vs_xmit.c 2010-09-22 16:29:43.271964521 +0300 renamed from linux/net/netfilter/ipvs/ip_vs_xmit.c 2010-09-16 09:02:25.000000000 +0300 +91
-78@@ -26,6 +26,7 @@ #include <net/route.h> /* for ip_route_output */ #include <net/ipv6.h> #include <net/ip6_route.h> +#include <net/addrconf.h> #include <linux/icmpv6.h> #include <linux/netfilter.h> #include <linux/netfilter_ipv4.h>@@ -37,26 +38,27 @@ * Destination cache to speed up outgoing route lookup */ static inline void -__ip_vs_dst_set(struct ip_vs_dest *dest, u32 rtos, struct dst_entry *dst) +__ip_vs_dst_set(struct ip_vs_dest *dest, u32 rtos, struct dst_entry *dst, + u32 dst_cookie) { struct dst_entry *old_dst; old_dst = dest->dst_cache; dest->dst_cache = dst; dest->dst_rtos = rtos; + dest->dst_cookie = dst_cookie; dst_release(old_dst); } static inline struct dst_entry * -__ip_vs_dst_check(struct ip_vs_dest *dest, u32 rtos, u32 cookie) +__ip_vs_dst_check(struct ip_vs_dest *dest, u32 rtos) { struct dst_entry *dst = dest->dst_cache; if (!dst) return NULL; - if ((dst->obsolete - || (dest->af == AF_INET && rtos != dest->dst_rtos)) && - dst->ops->check(dst, cookie) == NULL) { + if ((dst->obsolete || rtos != dest->dst_rtos) && + dst->ops->check(dst, dest->dst_cookie) == NULL) { dest->dst_cache = NULL; dst_release(dst); return NULL;@@ -66,15 +68,16 @@ __ip_vs_dst_check(struct ip_vs_dest *des } static struct rtable * -__ip_vs_get_out_rt(struct ip_vs_conn *cp, u32 rtos) +__ip_vs_get_out_rt(struct sk_buff *skb, struct ip_vs_conn *cp, u32 rtos) { + struct net *net = dev_net(skb->dev); struct rtable *rt; /* Route to the other host */ struct ip_vs_dest *dest = cp->dest; if (dest) { spin_lock(&dest->dst_lock); if (!(rt = (struct rtable *) - __ip_vs_dst_check(dest, rtos, 0))) { + __ip_vs_dst_check(dest, rtos))) { struct flowi fl = { .oif = 0, .nl_u = {@@ -84,13 +87,13 @@ __ip_vs_get_out_rt(struct ip_vs_conn *cp .tos = rtos, } }, }; - if (ip_route_output_key(&init_net, &rt, &fl)) { + if (ip_route_output_key(net, &rt, &fl)) { spin_unlock(&dest->dst_lock); IP_VS_DBG_RL("ip_route_output error, dest: %pI4\n", &dest->addr.ip); return NULL; } - __ip_vs_dst_set(dest, rtos, dst_clone(&rt->dst)); + __ip_vs_dst_set(dest, rtos, dst_clone(&rt->dst), 0); IP_VS_DBG(10, "new dst %pI4, refcnt=%d, rtos=%X\n", &dest->addr.ip, atomic_read(&rt->dst.__refcnt), rtos);@@ -106,7 +109,7 @@ __ip_vs_get_out_rt(struct ip_vs_conn *cp .tos = rtos, } }, }; - if (ip_route_output_key(&init_net, &rt, &fl)) { + if (ip_route_output_key(net, &rt, &fl)) { IP_VS_DBG_RL("ip_route_output error, dest: %pI4\n", &cp->daddr.ip); return NULL;@@ -117,62 +120,79 @@ __ip_vs_get_out_rt(struct ip_vs_conn *cp } #ifdef CONFIG_IP_VS_IPV6 + +static struct dst_entry * +__ip_vs_route_output_v6(struct net *net, struct in6_addr *daddr, + struct in6_addr *ret_saddr, int do_xfrm) +{ + struct dst_entry *dst; + struct flowi fl = { + .oif = 0, + .nl_u = { + .ip6_u = { + .daddr = *daddr, + }, + }, + }; + + dst = ip6_route_output(net, NULL, &fl); + if (dst->error) + goto out_err; + if (!ret_saddr) + return dst; + if (ipv6_addr_any(&fl.fl6_src) && + ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev, + &fl.fl6_dst, 0, &fl.fl6_src) < 0) + goto out_err; + if (do_xfrm && xfrm_lookup(net, &dst, &fl, NULL, 0) < 0) + goto out_err; + ipv6_addr_copy(ret_saddr, &fl.fl6_src); + return dst; + +out_err: + dst_release(dst); + IP_VS_DBG_RL("ip6_route_output error, dest: %pI6\n", daddr); + return NULL; +} + static struct rt6_info * -__ip_vs_get_out_rt_v6(struct ip_vs_conn *cp) +__ip_vs_get_out_rt_v6(struct sk_buff *skb, struct ip_vs_conn *cp, + struct in6_addr *ret_saddr, int do_xfrm) { + struct net *net = dev_net(skb->dev); struct rt6_info *rt; /* Route to the other host */ struct ip_vs_dest *dest = cp->dest; + struct dst_entry *dst; if (dest) { spin_lock(&dest->dst_lock); - rt = (struct rt6_info *)__ip_vs_dst_check(dest, 0, 0); + rt = (struct rt6_info *)__ip_vs_dst_check(dest, 0); if (!rt) { - struct flowi fl = { - .oif = 0, - .nl_u = { - .ip6_u = { - .daddr = dest->addr.in6, - .saddr = { - .s6_addr32 = - { 0, 0, 0, 0 }, - }, - }, - }, - }; + u32 cookie; - rt = (struct rt6_info *)ip6_route_output(&init_net, - NULL, &fl); - if (!rt) { + dst = __ip_vs_route_output_v6(net, &dest->addr.in6, + &dest->dst_saddr, + do_xfrm); + if (!dst) { spin_unlock(&dest->dst_lock); - IP_VS_DBG_RL("ip6_route_output error, dest: %pI6\n", - &dest->addr.in6); return NULL; } - __ip_vs_dst_set(dest, 0, dst_clone(&rt->dst)); - IP_VS_DBG(10, "new dst %pI6, refcnt=%d\n", - &dest->addr.in6, + rt = (struct rt6_info *) dst; + cookie = rt->rt6i_node ? rt->rt6i_node->fn_sernum : 0; + __ip_vs_dst_set(dest, 0, dst_clone(&rt->dst), cookie); + IP_VS_DBG(10, "new dst %pI6, src %pI6, refcnt=%d\n", + &dest->addr.in6, &dest->dst_saddr, atomic_read(&rt->dst.__refcnt)); } + if (ret_saddr) + ipv6_addr_copy(ret_saddr, &dest->dst_saddr); spin_unlock(&dest->dst_lock); } else { - struct flowi fl = { - .oif = 0, - .nl_u = { - .ip6_u = { - .daddr = cp->daddr.in6, - .saddr = { - .s6_addr32 = { 0, 0, 0, 0 }, - }, - }, - }, - }; - - rt = (struct rt6_info *)ip6_route_output(&init_net, NULL, &fl); - if (!rt) { - IP_VS_DBG_RL("ip6_route_output error, dest: %pI6\n", - &cp->daddr.in6); + dst = __ip_vs_route_output_v6(net, &cp->daddr.in6, ret_saddr, + do_xfrm); + if (!dst) return NULL; - } + rt = (struct rt6_info *) dst; } return rt;@@ -248,6 +268,7 @@ int ip_vs_bypass_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp) { + struct net *net = dev_net(skb->dev); struct rtable *rt; /* Route to the other host */ struct iphdr *iph = ip_hdr(skb); u8 tos = iph->tos;@@ -263,7 +284,7 @@ ip_vs_bypass_xmit(struct sk_buff *skb, s EnterFunction(10); - if (ip_route_output_key(&init_net, &rt, &fl)) { + if (ip_route_output_key(net, &rt, &fl)) { IP_VS_DBG_RL("%s(): ip_route_output error, dest: %pI4\n", __func__, &iph->daddr); goto tx_error_icmp;@@ -313,25 +334,18 @@ int ip_vs_bypass_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp) { + struct net *net = dev_net(skb->dev); + struct dst_entry *dst; struct rt6_info *rt; /* Route to the other host */ struct ipv6hdr *iph = ipv6_hdr(skb); int mtu; - struct flowi fl = { - .oif = 0, - .nl_u = { - .ip6_u = { - .daddr = iph->daddr, - .saddr = { .s6_addr32 = {0, 0, 0, 0} }, } }, - }; EnterFunction(10); - rt = (struct rt6_info *)ip6_route_output(&init_net, NULL, &fl); - if (!rt) { - IP_VS_DBG_RL("%s(): ip6_route_output error, dest: %pI6\n", - __func__, &iph->daddr); + dst = __ip_vs_route_output_v6(net, &iph->daddr, NULL, 0); + if (!dst) goto tx_error_icmp; - } + rt = (struct rt6_info *) dst; /* MTU checking */ mtu = dst_mtu(&rt->dst);@@ -397,7 +411,7 @@ ip_vs_nat_xmit(struct sk_buff *skb, stru IP_VS_DBG(10, "filled cport=%d\n", ntohs(*p)); } - if (!(rt = __ip_vs_get_out_rt(cp, RT_TOS(iph->tos)))) + if (!(rt = __ip_vs_get_out_rt(skb, cp, RT_TOS(iph->tos)))) goto tx_error_icmp; /* MTU checking */@@ -472,7 +486,7 @@ ip_vs_nat_xmit_v6(struct sk_buff *skb, s IP_VS_DBG(10, "filled cport=%d\n", ntohs(*p)); } - rt = __ip_vs_get_out_rt_v6(cp); + rt = __ip_vs_get_out_rt_v6(skb, cp, NULL, 0); if (!rt) goto tx_error_icmp;@@ -557,7 +571,6 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, s struct iphdr *old_iph = ip_hdr(skb); u8 tos = old_iph->tos; __be16 df = old_iph->frag_off; - sk_buff_data_t old_transport_header = skb->transport_header; struct iphdr *iph; /* Our new IP header */ unsigned int max_headroom; /* The extra header space needed */ int mtu;@@ -572,7 +585,7 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, s goto tx_error; } - if (!(rt = __ip_vs_get_out_rt(cp, RT_TOS(tos)))) + if (!(rt = __ip_vs_get_out_rt(skb, cp, RT_TOS(tos)))) goto tx_error_icmp; tdev = rt->dst.dev;@@ -616,7 +629,7 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, s old_iph = ip_hdr(skb); } - skb->transport_header = old_transport_header; + skb->transport_header = skb->network_header; /* fix old IP header checksum */ ip_send_check(old_iph);@@ -670,9 +683,9 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb struct ip_vs_protocol *pp) { struct rt6_info *rt; /* Route to the other host */ + struct in6_addr saddr; /* Source for tunnel */ struct net_device *tdev; /* Device to other host */ struct ipv6hdr *old_iph = ipv6_hdr(skb); - sk_buff_data_t old_transport_header = skb->transport_header; struct ipv6hdr *iph; /* Our new IP header */ unsigned int max_headroom; /* The extra header space needed */ int mtu;@@ -687,17 +700,17 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb goto tx_error; } - rt = __ip_vs_get_out_rt_v6(cp); + rt = __ip_vs_get_out_rt_v6(skb, cp, &saddr, 1); if (!rt) goto tx_error_icmp; tdev = rt->dst.dev; mtu = dst_mtu(&rt->dst) - sizeof(struct ipv6hdr); - /* TODO IPv6: do we need this check in IPv6? */ - if (mtu < 1280) { + if (mtu < IPV6_MIN_MTU) { dst_release(&rt->dst); - IP_VS_DBG_RL("%s(): mtu less than 1280\n", __func__); + IP_VS_DBG_RL("%s(): mtu less than %d\n", __func__, + IPV6_MIN_MTU); goto tx_error; } if (skb_dst(skb))@@ -730,7 +743,7 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb old_iph = ipv6_hdr(skb); } - skb->transport_header = old_transport_header; + skb->transport_header = skb->network_header; skb_push(skb, sizeof(struct ipv6hdr)); skb_reset_network_header(skb);@@ -750,8 +763,8 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb be16_add_cpu(&iph->payload_len, sizeof(*old_iph)); iph->priority = old_iph->priority; memset(&iph->flow_lbl, 0, sizeof(iph->flow_lbl)); - iph->daddr = rt->rt6i_dst.addr; - iph->saddr = cp->vaddr.in6; /* rt->rt6i_src.addr; */ + ipv6_addr_copy(&iph->daddr, &rt->rt6i_dst.addr); + ipv6_addr_copy(&iph->saddr, &saddr); iph->hop_limit = old_iph->hop_limit; /* Another hack: avoid icmp_send in ip_fragment */@@ -791,7 +804,7 @@ ip_vs_dr_xmit(struct sk_buff *skb, struc EnterFunction(10); - if (!(rt = __ip_vs_get_out_rt(cp, RT_TOS(iph->tos)))) + if (!(rt = __ip_vs_get_out_rt(skb, cp, RT_TOS(iph->tos)))) goto tx_error_icmp; /* MTU checking */@@ -843,7 +856,7 @@ ip_vs_dr_xmit_v6(struct sk_buff *skb, st EnterFunction(10); - rt = __ip_vs_get_out_rt_v6(cp); + rt = __ip_vs_get_out_rt_v6(skb, cp, NULL, 0); if (!rt) goto tx_error_icmp;@@ -919,7 +932,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, str * mangle and send the packet here (only for VS/NAT) */ - if (!(rt = __ip_vs_get_out_rt(cp, RT_TOS(ip_hdr(skb)->tos)))) + if (!(rt = __ip_vs_get_out_rt(skb, cp, RT_TOS(ip_hdr(skb)->tos)))) goto tx_error_icmp; /* MTU checking */
net/netfilter/ipvs/ip_vs_xmit.c 2010-09-22 16:29:43.271964521 +0300 ip_vs_icmp_xmit_v6(struct sk_buff *skb, · line 1012
Quoted 8 lines
net/netfilter/ipvs/ip_vs_xmit.c 2010-09-22 16:29:43.271964521 +0300 renamed from linux/net/netfilter/ipvs/ip_vs_xmit.c 2010-09-16 09:02:25.000000000 +0300 +1
-1@@ -993,7 +1006,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, * mangle and send the packet here (only for VS/NAT) */ - rt = __ip_vs_get_out_rt_v6(cp); + rt = __ip_vs_get_out_rt_v6(skb, cp, NULL, 0); if (!rt) goto tx_error_icmp;
Looks good, go ahead
--
Regards
Hans Schillstrom <[email protected]>