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