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