Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
[sfrench/cifs-2.6.git] / net / netfilter / ipvs / ip_vs_xmit.c
1 /*
2  * ip_vs_xmit.c: various packet transmitters for IPVS
3  *
4  * Authors:     Wensong Zhang <wensong@linuxvirtualserver.org>
5  *              Julian Anastasov <ja@ssi.bg>
6  *
7  *              This program is free software; you can redistribute it and/or
8  *              modify it under the terms of the GNU General Public License
9  *              as published by the Free Software Foundation; either version
10  *              2 of the License, or (at your option) any later version.
11  *
12  * Changes:
13  *
14  * Description of forwarding methods:
15  * - all transmitters are called from LOCAL_IN (remote clients) and
16  * LOCAL_OUT (local clients) but for ICMP can be called from FORWARD
17  * - not all connections have destination server, for example,
18  * connections in backup server when fwmark is used
19  * - bypass connections use daddr from packet
20  * - we can use dst without ref while sending in RCU section, we use
21  * ref when returning NF_ACCEPT for NAT-ed packet via loopback
22  * LOCAL_OUT rules:
23  * - skb->dev is NULL, skb->protocol is not set (both are set in POST_ROUTING)
24  * - skb->pkt_type is not set yet
25  * - the only place where we can see skb->sk != NULL
26  */
27
28 #define KMSG_COMPONENT "IPVS"
29 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
30
31 #include <linux/kernel.h>
32 #include <linux/slab.h>
33 #include <linux/tcp.h>                  /* for tcphdr */
34 #include <net/ip.h>
35 #include <net/tcp.h>                    /* for csum_tcpudp_magic */
36 #include <net/udp.h>
37 #include <net/icmp.h>                   /* for icmp_send */
38 #include <net/route.h>                  /* for ip_route_output */
39 #include <net/ipv6.h>
40 #include <net/ip6_route.h>
41 #include <net/ip_tunnels.h>
42 #include <net/addrconf.h>
43 #include <linux/icmpv6.h>
44 #include <linux/netfilter.h>
45 #include <linux/netfilter_ipv4.h>
46
47 #include <net/ip_vs.h>
48
49 enum {
50         IP_VS_RT_MODE_LOCAL     = 1, /* Allow local dest */
51         IP_VS_RT_MODE_NON_LOCAL = 2, /* Allow non-local dest */
52         IP_VS_RT_MODE_RDR       = 4, /* Allow redirect from remote daddr to
53                                       * local
54                                       */
55         IP_VS_RT_MODE_CONNECT   = 8, /* Always bind route to saddr */
56         IP_VS_RT_MODE_KNOWN_NH  = 16,/* Route via remote addr */
57         IP_VS_RT_MODE_TUNNEL    = 32,/* Tunnel mode */
58 };
59
60 static inline struct ip_vs_dest_dst *ip_vs_dest_dst_alloc(void)
61 {
62         return kmalloc(sizeof(struct ip_vs_dest_dst), GFP_ATOMIC);
63 }
64
65 static inline void ip_vs_dest_dst_free(struct ip_vs_dest_dst *dest_dst)
66 {
67         kfree(dest_dst);
68 }
69
70 /*
71  *      Destination cache to speed up outgoing route lookup
72  */
73 static inline void
74 __ip_vs_dst_set(struct ip_vs_dest *dest, struct ip_vs_dest_dst *dest_dst,
75                 struct dst_entry *dst, u32 dst_cookie)
76 {
77         struct ip_vs_dest_dst *old;
78
79         old = rcu_dereference_protected(dest->dest_dst,
80                                         lockdep_is_held(&dest->dst_lock));
81
82         if (dest_dst) {
83                 dest_dst->dst_cache = dst;
84                 dest_dst->dst_cookie = dst_cookie;
85         }
86         rcu_assign_pointer(dest->dest_dst, dest_dst);
87
88         if (old)
89                 call_rcu(&old->rcu_head, ip_vs_dest_dst_rcu_free);
90 }
91
92 static inline struct ip_vs_dest_dst *
93 __ip_vs_dst_check(struct ip_vs_dest *dest)
94 {
95         struct ip_vs_dest_dst *dest_dst = rcu_dereference(dest->dest_dst);
96         struct dst_entry *dst;
97
98         if (!dest_dst)
99                 return NULL;
100         dst = dest_dst->dst_cache;
101         if (dst->obsolete &&
102             dst->ops->check(dst, dest_dst->dst_cookie) == NULL)
103                 return NULL;
104         return dest_dst;
105 }
106
107 static inline bool
108 __mtu_check_toobig_v6(const struct sk_buff *skb, u32 mtu)
109 {
110         if (IP6CB(skb)->frag_max_size) {
111                 /* frag_max_size tell us that, this packet have been
112                  * defragmented by netfilter IPv6 conntrack module.
113                  */
114                 if (IP6CB(skb)->frag_max_size > mtu)
115                         return true; /* largest fragment violate MTU */
116         }
117         else if (skb->len > mtu && !skb_is_gso(skb)) {
118                 return true; /* Packet size violate MTU size */
119         }
120         return false;
121 }
122
123 /* Get route to daddr, update *saddr, optionally bind route to saddr */
124 static struct rtable *do_output_route4(struct net *net, __be32 daddr,
125                                        int rt_mode, __be32 *saddr)
126 {
127         struct flowi4 fl4;
128         struct rtable *rt;
129         int loop = 0;
130
131         memset(&fl4, 0, sizeof(fl4));
132         fl4.daddr = daddr;
133         fl4.saddr = (rt_mode & IP_VS_RT_MODE_CONNECT) ? *saddr : 0;
134         fl4.flowi4_flags = (rt_mode & IP_VS_RT_MODE_KNOWN_NH) ?
135                            FLOWI_FLAG_KNOWN_NH : 0;
136
137 retry:
138         rt = ip_route_output_key(net, &fl4);
139         if (IS_ERR(rt)) {
140                 /* Invalid saddr ? */
141                 if (PTR_ERR(rt) == -EINVAL && *saddr &&
142                     rt_mode & IP_VS_RT_MODE_CONNECT && !loop) {
143                         *saddr = 0;
144                         flowi4_update_output(&fl4, 0, 0, daddr, 0);
145                         goto retry;
146                 }
147                 IP_VS_DBG_RL("ip_route_output error, dest: %pI4\n", &daddr);
148                 return NULL;
149         } else if (!*saddr && rt_mode & IP_VS_RT_MODE_CONNECT && fl4.saddr) {
150                 ip_rt_put(rt);
151                 *saddr = fl4.saddr;
152                 flowi4_update_output(&fl4, 0, 0, daddr, fl4.saddr);
153                 loop++;
154                 goto retry;
155         }
156         *saddr = fl4.saddr;
157         return rt;
158 }
159
160 /* Get route to destination or remote server */
161 static int
162 __ip_vs_get_out_rt(struct sk_buff *skb, struct ip_vs_dest *dest,
163                    __be32 daddr, int rt_mode, __be32 *ret_saddr)
164 {
165         struct net *net = dev_net(skb_dst(skb)->dev);
166         struct netns_ipvs *ipvs = net_ipvs(net);
167         struct ip_vs_dest_dst *dest_dst;
168         struct rtable *rt;                      /* Route to the other host */
169         struct rtable *ort;                     /* Original route */
170         struct iphdr *iph;
171         __be16 df;
172         int mtu;
173         int local, noref = 1;
174
175         if (dest) {
176                 dest_dst = __ip_vs_dst_check(dest);
177                 if (likely(dest_dst))
178                         rt = (struct rtable *) dest_dst->dst_cache;
179                 else {
180                         dest_dst = ip_vs_dest_dst_alloc();
181                         spin_lock_bh(&dest->dst_lock);
182                         if (!dest_dst) {
183                                 __ip_vs_dst_set(dest, NULL, NULL, 0);
184                                 spin_unlock_bh(&dest->dst_lock);
185                                 goto err_unreach;
186                         }
187                         rt = do_output_route4(net, dest->addr.ip, rt_mode,
188                                               &dest_dst->dst_saddr.ip);
189                         if (!rt) {
190                                 __ip_vs_dst_set(dest, NULL, NULL, 0);
191                                 spin_unlock_bh(&dest->dst_lock);
192                                 ip_vs_dest_dst_free(dest_dst);
193                                 goto err_unreach;
194                         }
195                         __ip_vs_dst_set(dest, dest_dst, &rt->dst, 0);
196                         spin_unlock_bh(&dest->dst_lock);
197                         IP_VS_DBG(10, "new dst %pI4, src %pI4, refcnt=%d\n",
198                                   &dest->addr.ip, &dest_dst->dst_saddr.ip,
199                                   atomic_read(&rt->dst.__refcnt));
200                 }
201                 daddr = dest->addr.ip;
202                 if (ret_saddr)
203                         *ret_saddr = dest_dst->dst_saddr.ip;
204         } else {
205                 __be32 saddr = htonl(INADDR_ANY);
206
207                 noref = 0;
208
209                 /* For such unconfigured boxes avoid many route lookups
210                  * for performance reasons because we do not remember saddr
211                  */
212                 rt_mode &= ~IP_VS_RT_MODE_CONNECT;
213                 rt = do_output_route4(net, daddr, rt_mode, &saddr);
214                 if (!rt)
215                         goto err_unreach;
216                 if (ret_saddr)
217                         *ret_saddr = saddr;
218         }
219
220         local = (rt->rt_flags & RTCF_LOCAL) ? 1 : 0;
221         if (!((local ? IP_VS_RT_MODE_LOCAL : IP_VS_RT_MODE_NON_LOCAL) &
222               rt_mode)) {
223                 IP_VS_DBG_RL("Stopping traffic to %s address, dest: %pI4\n",
224                              (rt->rt_flags & RTCF_LOCAL) ?
225                              "local":"non-local", &daddr);
226                 goto err_put;
227         }
228         iph = ip_hdr(skb);
229         if (likely(!local)) {
230                 if (unlikely(ipv4_is_loopback(iph->saddr))) {
231                         IP_VS_DBG_RL("Stopping traffic from loopback address "
232                                      "%pI4 to non-local address, dest: %pI4\n",
233                                      &iph->saddr, &daddr);
234                         goto err_put;
235                 }
236         } else {
237                 ort = skb_rtable(skb);
238                 if (!(rt_mode & IP_VS_RT_MODE_RDR) &&
239                     !(ort->rt_flags & RTCF_LOCAL)) {
240                         IP_VS_DBG_RL("Redirect from non-local address %pI4 to "
241                                      "local requires NAT method, dest: %pI4\n",
242                                      &iph->daddr, &daddr);
243                         goto err_put;
244                 }
245                 /* skb to local stack, preserve old route */
246                 if (!noref)
247                         ip_rt_put(rt);
248                 return local;
249         }
250
251         if (likely(!(rt_mode & IP_VS_RT_MODE_TUNNEL))) {
252                 mtu = dst_mtu(&rt->dst);
253                 df = iph->frag_off & htons(IP_DF);
254         } else {
255                 struct sock *sk = skb->sk;
256
257                 mtu = dst_mtu(&rt->dst) - sizeof(struct iphdr);
258                 if (mtu < 68) {
259                         IP_VS_DBG_RL("%s(): mtu less than 68\n", __func__);
260                         goto err_put;
261                 }
262                 ort = skb_rtable(skb);
263                 if (!skb->dev && sk && sk->sk_state != TCP_TIME_WAIT)
264                         ort->dst.ops->update_pmtu(&ort->dst, sk, NULL, mtu);
265                 /* MTU check allowed? */
266                 df = sysctl_pmtu_disc(ipvs) ? iph->frag_off & htons(IP_DF) : 0;
267         }
268
269         /* MTU checking */
270         if (unlikely(df && skb->len > mtu && !skb_is_gso(skb))) {
271                 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, htonl(mtu));
272                 IP_VS_DBG(1, "frag needed for %pI4\n", &iph->saddr);
273                 goto err_put;
274         }
275
276         skb_dst_drop(skb);
277         if (noref) {
278                 if (!local)
279                         skb_dst_set_noref_force(skb, &rt->dst);
280                 else
281                         skb_dst_set(skb, dst_clone(&rt->dst));
282         } else
283                 skb_dst_set(skb, &rt->dst);
284
285         return local;
286
287 err_put:
288         if (!noref)
289                 ip_rt_put(rt);
290         return -1;
291
292 err_unreach:
293         dst_link_failure(skb);
294         return -1;
295 }
296
297 #ifdef CONFIG_IP_VS_IPV6
298
299 static inline int __ip_vs_is_local_route6(struct rt6_info *rt)
300 {
301         return rt->dst.dev && rt->dst.dev->flags & IFF_LOOPBACK;
302 }
303
304 static struct dst_entry *
305 __ip_vs_route_output_v6(struct net *net, struct in6_addr *daddr,
306                         struct in6_addr *ret_saddr, int do_xfrm)
307 {
308         struct dst_entry *dst;
309         struct flowi6 fl6 = {
310                 .daddr = *daddr,
311         };
312
313         dst = ip6_route_output(net, NULL, &fl6);
314         if (dst->error)
315                 goto out_err;
316         if (!ret_saddr)
317                 return dst;
318         if (ipv6_addr_any(&fl6.saddr) &&
319             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
320                                &fl6.daddr, 0, &fl6.saddr) < 0)
321                 goto out_err;
322         if (do_xfrm) {
323                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
324                 if (IS_ERR(dst)) {
325                         dst = NULL;
326                         goto out_err;
327                 }
328         }
329         *ret_saddr = fl6.saddr;
330         return dst;
331
332 out_err:
333         dst_release(dst);
334         IP_VS_DBG_RL("ip6_route_output error, dest: %pI6\n", daddr);
335         return NULL;
336 }
337
338 /*
339  * Get route to destination or remote server
340  */
341 static int
342 __ip_vs_get_out_rt_v6(struct sk_buff *skb, struct ip_vs_dest *dest,
343                       struct in6_addr *daddr, struct in6_addr *ret_saddr,
344                       struct ip_vs_iphdr *ipvsh, int do_xfrm, int rt_mode)
345 {
346         struct net *net = dev_net(skb_dst(skb)->dev);
347         struct ip_vs_dest_dst *dest_dst;
348         struct rt6_info *rt;                    /* Route to the other host */
349         struct rt6_info *ort;                   /* Original route */
350         struct dst_entry *dst;
351         int mtu;
352         int local, noref = 1;
353
354         if (dest) {
355                 dest_dst = __ip_vs_dst_check(dest);
356                 if (likely(dest_dst))
357                         rt = (struct rt6_info *) dest_dst->dst_cache;
358                 else {
359                         u32 cookie;
360
361                         dest_dst = ip_vs_dest_dst_alloc();
362                         spin_lock_bh(&dest->dst_lock);
363                         if (!dest_dst) {
364                                 __ip_vs_dst_set(dest, NULL, NULL, 0);
365                                 spin_unlock_bh(&dest->dst_lock);
366                                 goto err_unreach;
367                         }
368                         dst = __ip_vs_route_output_v6(net, &dest->addr.in6,
369                                                       &dest_dst->dst_saddr.in6,
370                                                       do_xfrm);
371                         if (!dst) {
372                                 __ip_vs_dst_set(dest, NULL, NULL, 0);
373                                 spin_unlock_bh(&dest->dst_lock);
374                                 ip_vs_dest_dst_free(dest_dst);
375                                 goto err_unreach;
376                         }
377                         rt = (struct rt6_info *) dst;
378                         cookie = rt->rt6i_node ? rt->rt6i_node->fn_sernum : 0;
379                         __ip_vs_dst_set(dest, dest_dst, &rt->dst, cookie);
380                         spin_unlock_bh(&dest->dst_lock);
381                         IP_VS_DBG(10, "new dst %pI6, src %pI6, refcnt=%d\n",
382                                   &dest->addr.in6, &dest_dst->dst_saddr.in6,
383                                   atomic_read(&rt->dst.__refcnt));
384                 }
385                 if (ret_saddr)
386                         *ret_saddr = dest_dst->dst_saddr.in6;
387         } else {
388                 noref = 0;
389                 dst = __ip_vs_route_output_v6(net, daddr, ret_saddr, do_xfrm);
390                 if (!dst)
391                         goto err_unreach;
392                 rt = (struct rt6_info *) dst;
393         }
394
395         local = __ip_vs_is_local_route6(rt);
396         if (!((local ? IP_VS_RT_MODE_LOCAL : IP_VS_RT_MODE_NON_LOCAL) &
397               rt_mode)) {
398                 IP_VS_DBG_RL("Stopping traffic to %s address, dest: %pI6c\n",
399                              local ? "local":"non-local", daddr);
400                 goto err_put;
401         }
402         if (likely(!local)) {
403                 if (unlikely((!skb->dev || skb->dev->flags & IFF_LOOPBACK) &&
404                              ipv6_addr_type(&ipv6_hdr(skb)->saddr) &
405                                             IPV6_ADDR_LOOPBACK)) {
406                         IP_VS_DBG_RL("Stopping traffic from loopback address "
407                                      "%pI6c to non-local address, "
408                                      "dest: %pI6c\n",
409                                      &ipv6_hdr(skb)->saddr, daddr);
410                         goto err_put;
411                 }
412         } else {
413                 ort = (struct rt6_info *) skb_dst(skb);
414                 if (!(rt_mode & IP_VS_RT_MODE_RDR) &&
415                     !__ip_vs_is_local_route6(ort)) {
416                         IP_VS_DBG_RL("Redirect from non-local address %pI6c "
417                                      "to local requires NAT method, "
418                                      "dest: %pI6c\n",
419                                      &ipv6_hdr(skb)->daddr, daddr);
420                         goto err_put;
421                 }
422                 /* skb to local stack, preserve old route */
423                 if (!noref)
424                         dst_release(&rt->dst);
425                 return local;
426         }
427
428         /* MTU checking */
429         if (likely(!(rt_mode & IP_VS_RT_MODE_TUNNEL)))
430                 mtu = dst_mtu(&rt->dst);
431         else {
432                 struct sock *sk = skb->sk;
433
434                 mtu = dst_mtu(&rt->dst) - sizeof(struct ipv6hdr);
435                 if (mtu < IPV6_MIN_MTU) {
436                         IP_VS_DBG_RL("%s(): mtu less than %d\n", __func__,
437                                      IPV6_MIN_MTU);
438                         goto err_put;
439                 }
440                 ort = (struct rt6_info *) skb_dst(skb);
441                 if (!skb->dev && sk && sk->sk_state != TCP_TIME_WAIT)
442                         ort->dst.ops->update_pmtu(&ort->dst, sk, NULL, mtu);
443         }
444
445         if (unlikely(__mtu_check_toobig_v6(skb, mtu))) {
446                 if (!skb->dev)
447                         skb->dev = net->loopback_dev;
448                 /* only send ICMP too big on first fragment */
449                 if (!ipvsh->fragoffs)
450                         icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
451                 IP_VS_DBG(1, "frag needed for %pI6c\n", &ipv6_hdr(skb)->saddr);
452                 goto err_put;
453         }
454
455         skb_dst_drop(skb);
456         if (noref) {
457                 if (!local)
458                         skb_dst_set_noref_force(skb, &rt->dst);
459                 else
460                         skb_dst_set(skb, dst_clone(&rt->dst));
461         } else
462                 skb_dst_set(skb, &rt->dst);
463
464         return local;
465
466 err_put:
467         if (!noref)
468                 dst_release(&rt->dst);
469         return -1;
470
471 err_unreach:
472         dst_link_failure(skb);
473         return -1;
474 }
475 #endif
476
477
478 /* return NF_ACCEPT to allow forwarding or other NF_xxx on error */
479 static inline int ip_vs_tunnel_xmit_prepare(struct sk_buff *skb,
480                                             struct ip_vs_conn *cp)
481 {
482         int ret = NF_ACCEPT;
483
484         skb->ipvs_property = 1;
485         if (unlikely(cp->flags & IP_VS_CONN_F_NFCT))
486                 ret = ip_vs_confirm_conntrack(skb);
487         if (ret == NF_ACCEPT) {
488                 nf_reset(skb);
489                 skb_forward_csum(skb);
490         }
491         return ret;
492 }
493
494 /* return NF_STOLEN (sent) or NF_ACCEPT if local=1 (not sent) */
495 static inline int ip_vs_nat_send_or_cont(int pf, struct sk_buff *skb,
496                                          struct ip_vs_conn *cp, int local)
497 {
498         int ret = NF_STOLEN;
499
500         skb->ipvs_property = 1;
501         if (likely(!(cp->flags & IP_VS_CONN_F_NFCT)))
502                 ip_vs_notrack(skb);
503         else
504                 ip_vs_update_conntrack(skb, cp, 1);
505         if (!local) {
506                 skb_forward_csum(skb);
507                 NF_HOOK(pf, NF_INET_LOCAL_OUT, skb, NULL, skb_dst(skb)->dev,
508                         dst_output);
509         } else
510                 ret = NF_ACCEPT;
511         return ret;
512 }
513
514 /* return NF_STOLEN (sent) or NF_ACCEPT if local=1 (not sent) */
515 static inline int ip_vs_send_or_cont(int pf, struct sk_buff *skb,
516                                      struct ip_vs_conn *cp, int local)
517 {
518         int ret = NF_STOLEN;
519
520         skb->ipvs_property = 1;
521         if (likely(!(cp->flags & IP_VS_CONN_F_NFCT)))
522                 ip_vs_notrack(skb);
523         if (!local) {
524                 skb_forward_csum(skb);
525                 NF_HOOK(pf, NF_INET_LOCAL_OUT, skb, NULL, skb_dst(skb)->dev,
526                         dst_output);
527         } else
528                 ret = NF_ACCEPT;
529         return ret;
530 }
531
532
533 /*
534  *      NULL transmitter (do nothing except return NF_ACCEPT)
535  */
536 int
537 ip_vs_null_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
538                 struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)
539 {
540         /* we do not touch skb and do not need pskb ptr */
541         return ip_vs_send_or_cont(NFPROTO_IPV4, skb, cp, 1);
542 }
543
544
545 /*
546  *      Bypass transmitter
547  *      Let packets bypass the destination when the destination is not
548  *      available, it may be only used in transparent cache cluster.
549  */
550 int
551 ip_vs_bypass_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
552                   struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)
553 {
554         struct iphdr  *iph = ip_hdr(skb);
555
556         EnterFunction(10);
557
558         rcu_read_lock();
559         if (__ip_vs_get_out_rt(skb, NULL, iph->daddr, IP_VS_RT_MODE_NON_LOCAL,
560                                NULL) < 0)
561                 goto tx_error;
562
563         ip_send_check(iph);
564
565         /* Another hack: avoid icmp_send in ip_fragment */
566         skb->ignore_df = 1;
567
568         ip_vs_send_or_cont(NFPROTO_IPV4, skb, cp, 0);
569         rcu_read_unlock();
570
571         LeaveFunction(10);
572         return NF_STOLEN;
573
574  tx_error:
575         kfree_skb(skb);
576         rcu_read_unlock();
577         LeaveFunction(10);
578         return NF_STOLEN;
579 }
580
581 #ifdef CONFIG_IP_VS_IPV6
582 int
583 ip_vs_bypass_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
584                      struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)
585 {
586         EnterFunction(10);
587
588         rcu_read_lock();
589         if (__ip_vs_get_out_rt_v6(skb, NULL, &ipvsh->daddr.in6, NULL,
590                                   ipvsh, 0, IP_VS_RT_MODE_NON_LOCAL) < 0)
591                 goto tx_error;
592
593         /* Another hack: avoid icmp_send in ip_fragment */
594         skb->ignore_df = 1;
595
596         ip_vs_send_or_cont(NFPROTO_IPV6, skb, cp, 0);
597         rcu_read_unlock();
598
599         LeaveFunction(10);
600         return NF_STOLEN;
601
602  tx_error:
603         kfree_skb(skb);
604         rcu_read_unlock();
605         LeaveFunction(10);
606         return NF_STOLEN;
607 }
608 #endif
609
610 /*
611  *      NAT transmitter (only for outside-to-inside nat forwarding)
612  *      Not used for related ICMP
613  */
614 int
615 ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
616                struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)
617 {
618         struct rtable *rt;              /* Route to the other host */
619         int local, rc, was_input;
620
621         EnterFunction(10);
622
623         rcu_read_lock();
624         /* check if it is a connection of no-client-port */
625         if (unlikely(cp->flags & IP_VS_CONN_F_NO_CPORT)) {
626                 __be16 _pt, *p;
627
628                 p = skb_header_pointer(skb, ipvsh->len, sizeof(_pt), &_pt);
629                 if (p == NULL)
630                         goto tx_error;
631                 ip_vs_conn_fill_cport(cp, *p);
632                 IP_VS_DBG(10, "filled cport=%d\n", ntohs(*p));
633         }
634
635         was_input = rt_is_input_route(skb_rtable(skb));
636         local = __ip_vs_get_out_rt(skb, cp->dest, cp->daddr.ip,
637                                    IP_VS_RT_MODE_LOCAL |
638                                    IP_VS_RT_MODE_NON_LOCAL |
639                                    IP_VS_RT_MODE_RDR, NULL);
640         if (local < 0)
641                 goto tx_error;
642         rt = skb_rtable(skb);
643         /*
644          * Avoid duplicate tuple in reply direction for NAT traffic
645          * to local address when connection is sync-ed
646          */
647 #if IS_ENABLED(CONFIG_NF_CONNTRACK)
648         if (cp->flags & IP_VS_CONN_F_SYNC && local) {
649                 enum ip_conntrack_info ctinfo;
650                 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
651
652                 if (ct && !nf_ct_is_untracked(ct)) {
653                         IP_VS_DBG_RL_PKT(10, AF_INET, pp, skb, 0,
654                                          "ip_vs_nat_xmit(): "
655                                          "stopping DNAT to local address");
656                         goto tx_error;
657                 }
658         }
659 #endif
660
661         /* From world but DNAT to loopback address? */
662         if (local && ipv4_is_loopback(cp->daddr.ip) && was_input) {
663                 IP_VS_DBG_RL_PKT(1, AF_INET, pp, skb, 0, "ip_vs_nat_xmit(): "
664                                  "stopping DNAT to loopback address");
665                 goto tx_error;
666         }
667
668         /* copy-on-write the packet before mangling it */
669         if (!skb_make_writable(skb, sizeof(struct iphdr)))
670                 goto tx_error;
671
672         if (skb_cow(skb, rt->dst.dev->hard_header_len))
673                 goto tx_error;
674
675         /* mangle the packet */
676         if (pp->dnat_handler && !pp->dnat_handler(skb, pp, cp, ipvsh))
677                 goto tx_error;
678         ip_hdr(skb)->daddr = cp->daddr.ip;
679         ip_send_check(ip_hdr(skb));
680
681         IP_VS_DBG_PKT(10, AF_INET, pp, skb, 0, "After DNAT");
682
683         /* FIXME: when application helper enlarges the packet and the length
684            is larger than the MTU of outgoing device, there will be still
685            MTU problem. */
686
687         /* Another hack: avoid icmp_send in ip_fragment */
688         skb->ignore_df = 1;
689
690         rc = ip_vs_nat_send_or_cont(NFPROTO_IPV4, skb, cp, local);
691         rcu_read_unlock();
692
693         LeaveFunction(10);
694         return rc;
695
696   tx_error:
697         kfree_skb(skb);
698         rcu_read_unlock();
699         LeaveFunction(10);
700         return NF_STOLEN;
701 }
702
703 #ifdef CONFIG_IP_VS_IPV6
704 int
705 ip_vs_nat_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
706                   struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)
707 {
708         struct rt6_info *rt;            /* Route to the other host */
709         int local, rc;
710
711         EnterFunction(10);
712
713         rcu_read_lock();
714         /* check if it is a connection of no-client-port */
715         if (unlikely(cp->flags & IP_VS_CONN_F_NO_CPORT && !ipvsh->fragoffs)) {
716                 __be16 _pt, *p;
717                 p = skb_header_pointer(skb, ipvsh->len, sizeof(_pt), &_pt);
718                 if (p == NULL)
719                         goto tx_error;
720                 ip_vs_conn_fill_cport(cp, *p);
721                 IP_VS_DBG(10, "filled cport=%d\n", ntohs(*p));
722         }
723
724         local = __ip_vs_get_out_rt_v6(skb, cp->dest, &cp->daddr.in6, NULL,
725                                       ipvsh, 0,
726                                       IP_VS_RT_MODE_LOCAL |
727                                       IP_VS_RT_MODE_NON_LOCAL |
728                                       IP_VS_RT_MODE_RDR);
729         if (local < 0)
730                 goto tx_error;
731         rt = (struct rt6_info *) skb_dst(skb);
732         /*
733          * Avoid duplicate tuple in reply direction for NAT traffic
734          * to local address when connection is sync-ed
735          */
736 #if IS_ENABLED(CONFIG_NF_CONNTRACK)
737         if (cp->flags & IP_VS_CONN_F_SYNC && local) {
738                 enum ip_conntrack_info ctinfo;
739                 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
740
741                 if (ct && !nf_ct_is_untracked(ct)) {
742                         IP_VS_DBG_RL_PKT(10, AF_INET6, pp, skb, 0,
743                                          "ip_vs_nat_xmit_v6(): "
744                                          "stopping DNAT to local address");
745                         goto tx_error;
746                 }
747         }
748 #endif
749
750         /* From world but DNAT to loopback address? */
751         if (local && skb->dev && !(skb->dev->flags & IFF_LOOPBACK) &&
752             ipv6_addr_type(&rt->rt6i_dst.addr) & IPV6_ADDR_LOOPBACK) {
753                 IP_VS_DBG_RL_PKT(1, AF_INET6, pp, skb, 0,
754                                  "ip_vs_nat_xmit_v6(): "
755                                  "stopping DNAT to loopback address");
756                 goto tx_error;
757         }
758
759         /* copy-on-write the packet before mangling it */
760         if (!skb_make_writable(skb, sizeof(struct ipv6hdr)))
761                 goto tx_error;
762
763         if (skb_cow(skb, rt->dst.dev->hard_header_len))
764                 goto tx_error;
765
766         /* mangle the packet */
767         if (pp->dnat_handler && !pp->dnat_handler(skb, pp, cp, ipvsh))
768                 goto tx_error;
769         ipv6_hdr(skb)->daddr = cp->daddr.in6;
770
771         IP_VS_DBG_PKT(10, AF_INET6, pp, skb, 0, "After DNAT");
772
773         /* FIXME: when application helper enlarges the packet and the length
774            is larger than the MTU of outgoing device, there will be still
775            MTU problem. */
776
777         /* Another hack: avoid icmp_send in ip_fragment */
778         skb->ignore_df = 1;
779
780         rc = ip_vs_nat_send_or_cont(NFPROTO_IPV6, skb, cp, local);
781         rcu_read_unlock();
782
783         LeaveFunction(10);
784         return rc;
785
786 tx_error:
787         LeaveFunction(10);
788         kfree_skb(skb);
789         rcu_read_unlock();
790         return NF_STOLEN;
791 }
792 #endif
793
794
795 /*
796  *   IP Tunneling transmitter
797  *
798  *   This function encapsulates the packet in a new IP packet, its
799  *   destination will be set to cp->daddr. Most code of this function
800  *   is taken from ipip.c.
801  *
802  *   It is used in VS/TUN cluster. The load balancer selects a real
803  *   server from a cluster based on a scheduling algorithm,
804  *   encapsulates the request packet and forwards it to the selected
805  *   server. For example, all real servers are configured with
806  *   "ifconfig tunl0 <Virtual IP Address> up". When the server receives
807  *   the encapsulated packet, it will decapsulate the packet, processe
808  *   the request and return the response packets directly to the client
809  *   without passing the load balancer. This can greatly increase the
810  *   scalability of virtual server.
811  *
812  *   Used for ANY protocol
813  */
814 int
815 ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
816                   struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)
817 {
818         struct netns_ipvs *ipvs = net_ipvs(skb_net(skb));
819         struct rtable *rt;                      /* Route to the other host */
820         __be32 saddr;                           /* Source for tunnel */
821         struct net_device *tdev;                /* Device to other host */
822         struct iphdr  *old_iph = ip_hdr(skb);
823         u8     tos = old_iph->tos;
824         __be16 df;
825         struct iphdr  *iph;                     /* Our new IP header */
826         unsigned int max_headroom;              /* The extra header space needed */
827         int ret, local;
828
829         EnterFunction(10);
830
831         rcu_read_lock();
832         local = __ip_vs_get_out_rt(skb, cp->dest, cp->daddr.ip,
833                                    IP_VS_RT_MODE_LOCAL |
834                                    IP_VS_RT_MODE_NON_LOCAL |
835                                    IP_VS_RT_MODE_CONNECT |
836                                    IP_VS_RT_MODE_TUNNEL, &saddr);
837         if (local < 0)
838                 goto tx_error;
839         if (local) {
840                 rcu_read_unlock();
841                 return ip_vs_send_or_cont(NFPROTO_IPV4, skb, cp, 1);
842         }
843
844         rt = skb_rtable(skb);
845         tdev = rt->dst.dev;
846
847         /* Copy DF, reset fragment offset and MF */
848         df = sysctl_pmtu_disc(ipvs) ? old_iph->frag_off & htons(IP_DF) : 0;
849
850         /*
851          * Okay, now see if we can stuff it in the buffer as-is.
852          */
853         max_headroom = LL_RESERVED_SPACE(tdev) + sizeof(struct iphdr);
854
855         if (skb_headroom(skb) < max_headroom || skb_cloned(skb)) {
856                 struct sk_buff *new_skb =
857                         skb_realloc_headroom(skb, max_headroom);
858
859                 if (!new_skb)
860                         goto tx_error;
861                 consume_skb(skb);
862                 skb = new_skb;
863                 old_iph = ip_hdr(skb);
864         }
865
866         /* fix old IP header checksum */
867         ip_send_check(old_iph);
868
869         skb = iptunnel_handle_offloads(skb, false, SKB_GSO_IPIP);
870         if (IS_ERR(skb))
871                 goto tx_error;
872
873         skb->transport_header = skb->network_header;
874
875         skb_push(skb, sizeof(struct iphdr));
876         skb_reset_network_header(skb);
877         memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
878
879         /*
880          *      Push down and install the IPIP header.
881          */
882         iph                     =       ip_hdr(skb);
883         iph->version            =       4;
884         iph->ihl                =       sizeof(struct iphdr)>>2;
885         iph->frag_off           =       df;
886         iph->protocol           =       IPPROTO_IPIP;
887         iph->tos                =       tos;
888         iph->daddr              =       cp->daddr.ip;
889         iph->saddr              =       saddr;
890         iph->ttl                =       old_iph->ttl;
891         ip_select_ident(skb, NULL);
892
893         /* Another hack: avoid icmp_send in ip_fragment */
894         skb->ignore_df = 1;
895
896         ret = ip_vs_tunnel_xmit_prepare(skb, cp);
897         if (ret == NF_ACCEPT)
898                 ip_local_out(skb);
899         else if (ret == NF_DROP)
900                 kfree_skb(skb);
901         rcu_read_unlock();
902
903         LeaveFunction(10);
904
905         return NF_STOLEN;
906
907   tx_error:
908         if (!IS_ERR(skb))
909                 kfree_skb(skb);
910         rcu_read_unlock();
911         LeaveFunction(10);
912         return NF_STOLEN;
913 }
914
915 #ifdef CONFIG_IP_VS_IPV6
916 int
917 ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
918                      struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)
919 {
920         struct rt6_info *rt;            /* Route to the other host */
921         struct in6_addr saddr;          /* Source for tunnel */
922         struct net_device *tdev;        /* Device to other host */
923         struct ipv6hdr  *old_iph = ipv6_hdr(skb);
924         struct ipv6hdr  *iph;           /* Our new IP header */
925         unsigned int max_headroom;      /* The extra header space needed */
926         int ret, local;
927
928         EnterFunction(10);
929
930         rcu_read_lock();
931         local = __ip_vs_get_out_rt_v6(skb, cp->dest, &cp->daddr.in6,
932                                       &saddr, ipvsh, 1,
933                                       IP_VS_RT_MODE_LOCAL |
934                                       IP_VS_RT_MODE_NON_LOCAL |
935                                       IP_VS_RT_MODE_TUNNEL);
936         if (local < 0)
937                 goto tx_error;
938         if (local) {
939                 rcu_read_unlock();
940                 return ip_vs_send_or_cont(NFPROTO_IPV6, skb, cp, 1);
941         }
942
943         rt = (struct rt6_info *) skb_dst(skb);
944         tdev = rt->dst.dev;
945
946         /*
947          * Okay, now see if we can stuff it in the buffer as-is.
948          */
949         max_headroom = LL_RESERVED_SPACE(tdev) + sizeof(struct ipv6hdr);
950
951         if (skb_headroom(skb) < max_headroom || skb_cloned(skb)) {
952                 struct sk_buff *new_skb =
953                         skb_realloc_headroom(skb, max_headroom);
954
955                 if (!new_skb)
956                         goto tx_error;
957                 consume_skb(skb);
958                 skb = new_skb;
959                 old_iph = ipv6_hdr(skb);
960         }
961
962         /* GSO: we need to provide proper SKB_GSO_ value for IPv6 */
963         skb = iptunnel_handle_offloads(skb, false, 0); /* SKB_GSO_SIT/IPV6 */
964         if (IS_ERR(skb))
965                 goto tx_error;
966
967         skb->transport_header = skb->network_header;
968
969         skb_push(skb, sizeof(struct ipv6hdr));
970         skb_reset_network_header(skb);
971         memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
972
973         /*
974          *      Push down and install the IPIP header.
975          */
976         iph                     =       ipv6_hdr(skb);
977         iph->version            =       6;
978         iph->nexthdr            =       IPPROTO_IPV6;
979         iph->payload_len        =       old_iph->payload_len;
980         be16_add_cpu(&iph->payload_len, sizeof(*old_iph));
981         memset(&iph->flow_lbl, 0, sizeof(iph->flow_lbl));
982         ipv6_change_dsfield(iph, 0, ipv6_get_dsfield(old_iph));
983         iph->daddr = cp->daddr.in6;
984         iph->saddr = saddr;
985         iph->hop_limit          =       old_iph->hop_limit;
986
987         /* Another hack: avoid icmp_send in ip_fragment */
988         skb->ignore_df = 1;
989
990         ret = ip_vs_tunnel_xmit_prepare(skb, cp);
991         if (ret == NF_ACCEPT)
992                 ip6_local_out(skb);
993         else if (ret == NF_DROP)
994                 kfree_skb(skb);
995         rcu_read_unlock();
996
997         LeaveFunction(10);
998
999         return NF_STOLEN;
1000
1001 tx_error:
1002         if (!IS_ERR(skb))
1003                 kfree_skb(skb);
1004         rcu_read_unlock();
1005         LeaveFunction(10);
1006         return NF_STOLEN;
1007 }
1008 #endif
1009
1010
1011 /*
1012  *      Direct Routing transmitter
1013  *      Used for ANY protocol
1014  */
1015 int
1016 ip_vs_dr_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
1017               struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)
1018 {
1019         int local;
1020
1021         EnterFunction(10);
1022
1023         rcu_read_lock();
1024         local = __ip_vs_get_out_rt(skb, cp->dest, cp->daddr.ip,
1025                                    IP_VS_RT_MODE_LOCAL |
1026                                    IP_VS_RT_MODE_NON_LOCAL |
1027                                    IP_VS_RT_MODE_KNOWN_NH, NULL);
1028         if (local < 0)
1029                 goto tx_error;
1030         if (local) {
1031                 rcu_read_unlock();
1032                 return ip_vs_send_or_cont(NFPROTO_IPV4, skb, cp, 1);
1033         }
1034
1035         ip_send_check(ip_hdr(skb));
1036
1037         /* Another hack: avoid icmp_send in ip_fragment */
1038         skb->ignore_df = 1;
1039
1040         ip_vs_send_or_cont(NFPROTO_IPV4, skb, cp, 0);
1041         rcu_read_unlock();
1042
1043         LeaveFunction(10);
1044         return NF_STOLEN;
1045
1046   tx_error:
1047         kfree_skb(skb);
1048         rcu_read_unlock();
1049         LeaveFunction(10);
1050         return NF_STOLEN;
1051 }
1052
1053 #ifdef CONFIG_IP_VS_IPV6
1054 int
1055 ip_vs_dr_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
1056                  struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)
1057 {
1058         int local;
1059
1060         EnterFunction(10);
1061
1062         rcu_read_lock();
1063         local = __ip_vs_get_out_rt_v6(skb, cp->dest, &cp->daddr.in6, NULL,
1064                                       ipvsh, 0,
1065                                       IP_VS_RT_MODE_LOCAL |
1066                                       IP_VS_RT_MODE_NON_LOCAL);
1067         if (local < 0)
1068                 goto tx_error;
1069         if (local) {
1070                 rcu_read_unlock();
1071                 return ip_vs_send_or_cont(NFPROTO_IPV6, skb, cp, 1);
1072         }
1073
1074         /* Another hack: avoid icmp_send in ip_fragment */
1075         skb->ignore_df = 1;
1076
1077         ip_vs_send_or_cont(NFPROTO_IPV6, skb, cp, 0);
1078         rcu_read_unlock();
1079
1080         LeaveFunction(10);
1081         return NF_STOLEN;
1082
1083 tx_error:
1084         kfree_skb(skb);
1085         rcu_read_unlock();
1086         LeaveFunction(10);
1087         return NF_STOLEN;
1088 }
1089 #endif
1090
1091
1092 /*
1093  *      ICMP packet transmitter
1094  *      called by the ip_vs_in_icmp
1095  */
1096 int
1097 ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
1098                 struct ip_vs_protocol *pp, int offset, unsigned int hooknum,
1099                 struct ip_vs_iphdr *iph)
1100 {
1101         struct rtable   *rt;    /* Route to the other host */
1102         int rc;
1103         int local;
1104         int rt_mode, was_input;
1105
1106         EnterFunction(10);
1107
1108         /* The ICMP packet for VS/TUN, VS/DR and LOCALNODE will be
1109            forwarded directly here, because there is no need to
1110            translate address/port back */
1111         if (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ) {
1112                 if (cp->packet_xmit)
1113                         rc = cp->packet_xmit(skb, cp, pp, iph);
1114                 else
1115                         rc = NF_ACCEPT;
1116                 /* do not touch skb anymore */
1117                 atomic_inc(&cp->in_pkts);
1118                 goto out;
1119         }
1120
1121         /*
1122          * mangle and send the packet here (only for VS/NAT)
1123          */
1124         was_input = rt_is_input_route(skb_rtable(skb));
1125
1126         /* LOCALNODE from FORWARD hook is not supported */
1127         rt_mode = (hooknum != NF_INET_FORWARD) ?
1128                   IP_VS_RT_MODE_LOCAL | IP_VS_RT_MODE_NON_LOCAL |
1129                   IP_VS_RT_MODE_RDR : IP_VS_RT_MODE_NON_LOCAL;
1130         rcu_read_lock();
1131         local = __ip_vs_get_out_rt(skb, cp->dest, cp->daddr.ip, rt_mode, NULL);
1132         if (local < 0)
1133                 goto tx_error;
1134         rt = skb_rtable(skb);
1135
1136         /*
1137          * Avoid duplicate tuple in reply direction for NAT traffic
1138          * to local address when connection is sync-ed
1139          */
1140 #if IS_ENABLED(CONFIG_NF_CONNTRACK)
1141         if (cp->flags & IP_VS_CONN_F_SYNC && local) {
1142                 enum ip_conntrack_info ctinfo;
1143                 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
1144
1145                 if (ct && !nf_ct_is_untracked(ct)) {
1146                         IP_VS_DBG(10, "%s(): "
1147                                   "stopping DNAT to local address %pI4\n",
1148                                   __func__, &cp->daddr.ip);
1149                         goto tx_error;
1150                 }
1151         }
1152 #endif
1153
1154         /* From world but DNAT to loopback address? */
1155         if (local && ipv4_is_loopback(cp->daddr.ip) && was_input) {
1156                 IP_VS_DBG(1, "%s(): "
1157                           "stopping DNAT to loopback %pI4\n",
1158                           __func__, &cp->daddr.ip);
1159                 goto tx_error;
1160         }
1161
1162         /* copy-on-write the packet before mangling it */
1163         if (!skb_make_writable(skb, offset))
1164                 goto tx_error;
1165
1166         if (skb_cow(skb, rt->dst.dev->hard_header_len))
1167                 goto tx_error;
1168
1169         ip_vs_nat_icmp(skb, pp, cp, 0);
1170
1171         /* Another hack: avoid icmp_send in ip_fragment */
1172         skb->ignore_df = 1;
1173
1174         rc = ip_vs_nat_send_or_cont(NFPROTO_IPV4, skb, cp, local);
1175         rcu_read_unlock();
1176         goto out;
1177
1178   tx_error:
1179         kfree_skb(skb);
1180         rcu_read_unlock();
1181         rc = NF_STOLEN;
1182   out:
1183         LeaveFunction(10);
1184         return rc;
1185 }
1186
1187 #ifdef CONFIG_IP_VS_IPV6
1188 int
1189 ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
1190                 struct ip_vs_protocol *pp, int offset, unsigned int hooknum,
1191                 struct ip_vs_iphdr *ipvsh)
1192 {
1193         struct rt6_info *rt;    /* Route to the other host */
1194         int rc;
1195         int local;
1196         int rt_mode;
1197
1198         EnterFunction(10);
1199
1200         /* The ICMP packet for VS/TUN, VS/DR and LOCALNODE will be
1201            forwarded directly here, because there is no need to
1202            translate address/port back */
1203         if (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ) {
1204                 if (cp->packet_xmit)
1205                         rc = cp->packet_xmit(skb, cp, pp, ipvsh);
1206                 else
1207                         rc = NF_ACCEPT;
1208                 /* do not touch skb anymore */
1209                 atomic_inc(&cp->in_pkts);
1210                 goto out;
1211         }
1212
1213         /*
1214          * mangle and send the packet here (only for VS/NAT)
1215          */
1216
1217         /* LOCALNODE from FORWARD hook is not supported */
1218         rt_mode = (hooknum != NF_INET_FORWARD) ?
1219                   IP_VS_RT_MODE_LOCAL | IP_VS_RT_MODE_NON_LOCAL |
1220                   IP_VS_RT_MODE_RDR : IP_VS_RT_MODE_NON_LOCAL;
1221         rcu_read_lock();
1222         local = __ip_vs_get_out_rt_v6(skb, cp->dest, &cp->daddr.in6, NULL,
1223                                       ipvsh, 0, rt_mode);
1224         if (local < 0)
1225                 goto tx_error;
1226         rt = (struct rt6_info *) skb_dst(skb);
1227         /*
1228          * Avoid duplicate tuple in reply direction for NAT traffic
1229          * to local address when connection is sync-ed
1230          */
1231 #if IS_ENABLED(CONFIG_NF_CONNTRACK)
1232         if (cp->flags & IP_VS_CONN_F_SYNC && local) {
1233                 enum ip_conntrack_info ctinfo;
1234                 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
1235
1236                 if (ct && !nf_ct_is_untracked(ct)) {
1237                         IP_VS_DBG(10, "%s(): "
1238                                   "stopping DNAT to local address %pI6\n",
1239                                   __func__, &cp->daddr.in6);
1240                         goto tx_error;
1241                 }
1242         }
1243 #endif
1244
1245         /* From world but DNAT to loopback address? */
1246         if (local && skb->dev && !(skb->dev->flags & IFF_LOOPBACK) &&
1247             ipv6_addr_type(&rt->rt6i_dst.addr) & IPV6_ADDR_LOOPBACK) {
1248                 IP_VS_DBG(1, "%s(): "
1249                           "stopping DNAT to loopback %pI6\n",
1250                           __func__, &cp->daddr.in6);
1251                 goto tx_error;
1252         }
1253
1254         /* copy-on-write the packet before mangling it */
1255         if (!skb_make_writable(skb, offset))
1256                 goto tx_error;
1257
1258         if (skb_cow(skb, rt->dst.dev->hard_header_len))
1259                 goto tx_error;
1260
1261         ip_vs_nat_icmp_v6(skb, pp, cp, 0);
1262
1263         /* Another hack: avoid icmp_send in ip_fragment */
1264         skb->ignore_df = 1;
1265
1266         rc = ip_vs_nat_send_or_cont(NFPROTO_IPV6, skb, cp, local);
1267         rcu_read_unlock();
1268         goto out;
1269
1270 tx_error:
1271         kfree_skb(skb);
1272         rcu_read_unlock();
1273         rc = NF_STOLEN;
1274 out:
1275         LeaveFunction(10);
1276         return rc;
1277 }
1278 #endif