@@ -87,7 +87,7 @@ __ip_vs_dst_check(struct ip_vs_dest *dest, u32 rtos)
8787/* Get route to destination or remote server */
8888static struct rtable *
8989__ip_vs_get_out_rt (struct sk_buff * skb , struct ip_vs_dest * dest ,
90- __be32 daddr , u32 rtos , int rt_mode )
90+ __be32 daddr , u32 rtos , int rt_mode , __be32 * ret_saddr )
9191{
9292 struct net * net = dev_net (skb_dst (skb )-> dev );
9393 struct rtable * rt ; /* Route to the other host */
@@ -98,27 +98,43 @@ __ip_vs_get_out_rt(struct sk_buff *skb, struct ip_vs_dest *dest,
9898 spin_lock (& dest -> dst_lock );
9999 if (!(rt = (struct rtable * )
100100 __ip_vs_dst_check (dest , rtos ))) {
101- rt = ip_route_output (net , dest -> addr .ip , 0 , rtos , 0 );
101+ struct flowi4 fl4 ;
102+
103+ memset (& fl4 , 0 , sizeof (fl4 ));
104+ fl4 .daddr = dest -> addr .ip ;
105+ fl4 .flowi4_tos = rtos ;
106+ rt = ip_route_output_key (net , & fl4 );
102107 if (IS_ERR (rt )) {
103108 spin_unlock (& dest -> dst_lock );
104109 IP_VS_DBG_RL ("ip_route_output error, dest: %pI4\n" ,
105110 & dest -> addr .ip );
106111 return NULL ;
107112 }
108113 __ip_vs_dst_set (dest , rtos , dst_clone (& rt -> dst ), 0 );
109- IP_VS_DBG (10 , "new dst %pI4, refcnt=%d, rtos=%X\n" ,
110- & dest -> addr .ip ,
114+ dest -> dst_saddr .ip = fl4 .saddr ;
115+ IP_VS_DBG (10 , "new dst %pI4, src %pI4, refcnt=%d, "
116+ "rtos=%X\n" ,
117+ & dest -> addr .ip , & dest -> dst_saddr .ip ,
111118 atomic_read (& rt -> dst .__refcnt ), rtos );
112119 }
113120 daddr = dest -> addr .ip ;
121+ if (ret_saddr )
122+ * ret_saddr = dest -> dst_saddr .ip ;
114123 spin_unlock (& dest -> dst_lock );
115124 } else {
116- rt = ip_route_output (net , daddr , 0 , rtos , 0 );
125+ struct flowi4 fl4 ;
126+
127+ memset (& fl4 , 0 , sizeof (fl4 ));
128+ fl4 .daddr = daddr ;
129+ fl4 .flowi4_tos = rtos ;
130+ rt = ip_route_output_key (net , & fl4 );
117131 if (IS_ERR (rt )) {
118132 IP_VS_DBG_RL ("ip_route_output error, dest: %pI4\n" ,
119133 & daddr );
120134 return NULL ;
121135 }
136+ if (ret_saddr )
137+ * ret_saddr = fl4 .saddr ;
122138 }
123139
124140 local = rt -> rt_flags & RTCF_LOCAL ;
@@ -249,7 +265,7 @@ __ip_vs_get_out_rt_v6(struct sk_buff *skb, struct ip_vs_dest *dest,
249265 u32 cookie ;
250266
251267 dst = __ip_vs_route_output_v6 (net , & dest -> addr .in6 ,
252- & dest -> dst_saddr ,
268+ & dest -> dst_saddr . in6 ,
253269 do_xfrm );
254270 if (!dst ) {
255271 spin_unlock (& dest -> dst_lock );
@@ -259,11 +275,11 @@ __ip_vs_get_out_rt_v6(struct sk_buff *skb, struct ip_vs_dest *dest,
259275 cookie = rt -> rt6i_node ? rt -> rt6i_node -> fn_sernum : 0 ;
260276 __ip_vs_dst_set (dest , 0 , dst_clone (& rt -> dst ), cookie );
261277 IP_VS_DBG (10 , "new dst %pI6, src %pI6, refcnt=%d\n" ,
262- & dest -> addr .in6 , & dest -> dst_saddr ,
278+ & dest -> addr .in6 , & dest -> dst_saddr . in6 ,
263279 atomic_read (& rt -> dst .__refcnt ));
264280 }
265281 if (ret_saddr )
266- ipv6_addr_copy (ret_saddr , & dest -> dst_saddr );
282+ ipv6_addr_copy (ret_saddr , & dest -> dst_saddr . in6 );
267283 spin_unlock (& dest -> dst_lock );
268284 } else {
269285 dst = __ip_vs_route_output_v6 (net , daddr , ret_saddr , do_xfrm );
@@ -386,7 +402,7 @@ ip_vs_bypass_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
386402 EnterFunction (10 );
387403
388404 if (!(rt = __ip_vs_get_out_rt (skb , NULL , iph -> daddr , RT_TOS (iph -> tos ),
389- IP_VS_RT_MODE_NON_LOCAL )))
405+ IP_VS_RT_MODE_NON_LOCAL , NULL )))
390406 goto tx_error_icmp ;
391407
392408 /* MTU checking */
@@ -518,7 +534,7 @@ ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
518534 RT_TOS (iph -> tos ),
519535 IP_VS_RT_MODE_LOCAL |
520536 IP_VS_RT_MODE_NON_LOCAL |
521- IP_VS_RT_MODE_RDR )))
537+ IP_VS_RT_MODE_RDR , NULL )))
522538 goto tx_error_icmp ;
523539 local = rt -> rt_flags & RTCF_LOCAL ;
524540 /*
@@ -540,7 +556,7 @@ ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
540556#endif
541557
542558 /* From world but DNAT to loopback address? */
543- if (local && ipv4_is_loopback (rt -> rt_dst ) &&
559+ if (local && ipv4_is_loopback (cp -> daddr . ip ) &&
544560 rt_is_input_route (skb_rtable (skb ))) {
545561 IP_VS_DBG_RL_PKT (1 , AF_INET , pp , skb , 0 , "ip_vs_nat_xmit(): "
546562 "stopping DNAT to loopback address" );
@@ -751,6 +767,7 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
751767 struct ip_vs_protocol * pp )
752768{
753769 struct rtable * rt ; /* Route to the other host */
770+ __be32 saddr ; /* Source for tunnel */
754771 struct net_device * tdev ; /* Device to other host */
755772 struct iphdr * old_iph = ip_hdr (skb );
756773 u8 tos = old_iph -> tos ;
@@ -764,7 +781,8 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
764781
765782 if (!(rt = __ip_vs_get_out_rt (skb , cp -> dest , cp -> daddr .ip ,
766783 RT_TOS (tos ), IP_VS_RT_MODE_LOCAL |
767- IP_VS_RT_MODE_NON_LOCAL )))
784+ IP_VS_RT_MODE_NON_LOCAL ,
785+ & saddr )))
768786 goto tx_error_icmp ;
769787 if (rt -> rt_flags & RTCF_LOCAL ) {
770788 ip_rt_put (rt );
@@ -832,8 +850,8 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
832850 iph -> frag_off = df ;
833851 iph -> protocol = IPPROTO_IPIP ;
834852 iph -> tos = tos ;
835- iph -> daddr = rt -> rt_dst ;
836- iph -> saddr = rt -> rt_src ;
853+ iph -> daddr = cp -> daddr . ip ;
854+ iph -> saddr = saddr ;
837855 iph -> ttl = old_iph -> ttl ;
838856 ip_select_ident (iph , & rt -> dst , NULL );
839857
@@ -996,7 +1014,7 @@ ip_vs_dr_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
9961014 if (!(rt = __ip_vs_get_out_rt (skb , cp -> dest , cp -> daddr .ip ,
9971015 RT_TOS (iph -> tos ),
9981016 IP_VS_RT_MODE_LOCAL |
999- IP_VS_RT_MODE_NON_LOCAL )))
1017+ IP_VS_RT_MODE_NON_LOCAL , NULL )))
10001018 goto tx_error_icmp ;
10011019 if (rt -> rt_flags & RTCF_LOCAL ) {
10021020 ip_rt_put (rt );
@@ -1114,12 +1132,13 @@ ip_vs_dr_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
11141132 */
11151133int
11161134ip_vs_icmp_xmit (struct sk_buff * skb , struct ip_vs_conn * cp ,
1117- struct ip_vs_protocol * pp , int offset )
1135+ struct ip_vs_protocol * pp , int offset , unsigned int hooknum )
11181136{
11191137 struct rtable * rt ; /* Route to the other host */
11201138 int mtu ;
11211139 int rc ;
11221140 int local ;
1141+ int rt_mode ;
11231142
11241143 EnterFunction (10 );
11251144
@@ -1140,11 +1159,13 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
11401159 * mangle and send the packet here (only for VS/NAT)
11411160 */
11421161
1162+ /* LOCALNODE from FORWARD hook is not supported */
1163+ rt_mode = (hooknum != NF_INET_FORWARD ) ?
1164+ IP_VS_RT_MODE_LOCAL | IP_VS_RT_MODE_NON_LOCAL |
1165+ IP_VS_RT_MODE_RDR : IP_VS_RT_MODE_NON_LOCAL ;
11431166 if (!(rt = __ip_vs_get_out_rt (skb , cp -> dest , cp -> daddr .ip ,
11441167 RT_TOS (ip_hdr (skb )-> tos ),
1145- IP_VS_RT_MODE_LOCAL |
1146- IP_VS_RT_MODE_NON_LOCAL |
1147- IP_VS_RT_MODE_RDR )))
1168+ rt_mode , NULL )))
11481169 goto tx_error_icmp ;
11491170 local = rt -> rt_flags & RTCF_LOCAL ;
11501171
@@ -1167,7 +1188,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
11671188#endif
11681189
11691190 /* From world but DNAT to loopback address? */
1170- if (local && ipv4_is_loopback (rt -> rt_dst ) &&
1191+ if (local && ipv4_is_loopback (cp -> daddr . ip ) &&
11711192 rt_is_input_route (skb_rtable (skb ))) {
11721193 IP_VS_DBG (1 , "%s(): "
11731194 "stopping DNAT to loopback %pI4\n" ,
@@ -1232,12 +1253,13 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
12321253#ifdef CONFIG_IP_VS_IPV6
12331254int
12341255ip_vs_icmp_xmit_v6 (struct sk_buff * skb , struct ip_vs_conn * cp ,
1235- struct ip_vs_protocol * pp , int offset )
1256+ struct ip_vs_protocol * pp , int offset , unsigned int hooknum )
12361257{
12371258 struct rt6_info * rt ; /* Route to the other host */
12381259 int mtu ;
12391260 int rc ;
12401261 int local ;
1262+ int rt_mode ;
12411263
12421264 EnterFunction (10 );
12431265
@@ -1258,10 +1280,12 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
12581280 * mangle and send the packet here (only for VS/NAT)
12591281 */
12601282
1283+ /* LOCALNODE from FORWARD hook is not supported */
1284+ rt_mode = (hooknum != NF_INET_FORWARD ) ?
1285+ IP_VS_RT_MODE_LOCAL | IP_VS_RT_MODE_NON_LOCAL |
1286+ IP_VS_RT_MODE_RDR : IP_VS_RT_MODE_NON_LOCAL ;
12611287 if (!(rt = __ip_vs_get_out_rt_v6 (skb , cp -> dest , & cp -> daddr .in6 , NULL ,
1262- 0 , (IP_VS_RT_MODE_LOCAL |
1263- IP_VS_RT_MODE_NON_LOCAL |
1264- IP_VS_RT_MODE_RDR ))))
1288+ 0 , rt_mode )))
12651289 goto tx_error_icmp ;
12661290
12671291 local = __ip_vs_is_local_route6 (rt );
0 commit comments