blob: a48239aba33b78b25c187b67f3df7a71564838a4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * ip_vs_xmit.c: various packet transmitters for IPVS
3 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * 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 *
Julian Anastasovcb591552010-10-17 16:40:51 +030014 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 */
25
Hannes Eder9aada7a2009-07-30 14:29:44 -070026#define KMSG_COMPONENT "IPVS"
27#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
28
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/kernel.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090030#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/tcp.h> /* for tcphdr */
Herbert Xuc439cb22008-01-11 19:14:00 -080032#include <net/ip.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#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 */
Julius Volz38cdcc92008-09-02 15:55:44 +020037#include <net/ipv6.h>
38#include <net/ip6_route.h>
Hans Schillstrom714f0952010-10-19 10:38:48 +020039#include <net/addrconf.h>
Julius Volz38cdcc92008-09-02 15:55:44 +020040#include <linux/icmpv6.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/netfilter.h>
42#include <linux/netfilter_ipv4.h>
43
44#include <net/ip_vs.h>
45
Changli Gao17a8f8e2011-02-24 08:19:57 +080046enum {
47 IP_VS_RT_MODE_LOCAL = 1, /* Allow local dest */
48 IP_VS_RT_MODE_NON_LOCAL = 2, /* Allow non-local dest */
49 IP_VS_RT_MODE_RDR = 4, /* Allow redirect from remote daddr to
50 * local
51 */
52};
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54/*
55 * Destination cache to speed up outgoing route lookup
56 */
57static inline void
Hans Schillstrom714f0952010-10-19 10:38:48 +020058__ip_vs_dst_set(struct ip_vs_dest *dest, u32 rtos, struct dst_entry *dst,
59 u32 dst_cookie)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
61 struct dst_entry *old_dst;
62
63 old_dst = dest->dst_cache;
64 dest->dst_cache = dst;
65 dest->dst_rtos = rtos;
Hans Schillstrom714f0952010-10-19 10:38:48 +020066 dest->dst_cookie = dst_cookie;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 dst_release(old_dst);
68}
69
70static inline struct dst_entry *
Hans Schillstrom714f0952010-10-19 10:38:48 +020071__ip_vs_dst_check(struct ip_vs_dest *dest, u32 rtos)
Linus Torvalds1da177e2005-04-16 15:20:36 -070072{
73 struct dst_entry *dst = dest->dst_cache;
74
75 if (!dst)
76 return NULL;
Hans Schillstrom714f0952010-10-19 10:38:48 +020077 if ((dst->obsolete || rtos != dest->dst_rtos) &&
78 dst->ops->check(dst, dest->dst_cookie) == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 dest->dst_cache = NULL;
80 dst_release(dst);
81 return NULL;
82 }
83 dst_hold(dst);
84 return dst;
85}
86
Changli Gao17a8f8e2011-02-24 08:19:57 +080087/* Get route to destination or remote server */
Ilpo Järvinenad1b30b2008-01-05 23:12:40 -080088static struct rtable *
Julian Anastasovfc604762010-10-17 16:38:15 +030089__ip_vs_get_out_rt(struct sk_buff *skb, struct ip_vs_dest *dest,
90 __be32 daddr, u32 rtos, int rt_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091{
Julian Anastasovfc604762010-10-17 16:38:15 +030092 struct net *net = dev_net(skb_dst(skb)->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 struct rtable *rt; /* Route to the other host */
Julian Anastasovfc604762010-10-17 16:38:15 +030094 struct rtable *ort; /* Original route */
95 int local;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
97 if (dest) {
98 spin_lock(&dest->dst_lock);
99 if (!(rt = (struct rtable *)
Hans Schillstrom714f0952010-10-19 10:38:48 +0200100 __ip_vs_dst_check(dest, rtos))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 struct flowi fl = {
Changli Gao58116622010-11-12 18:43:55 +0000102 .fl4_dst = dest->addr.ip,
103 .fl4_tos = rtos,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 };
105
Hans Schillstrom714f0952010-10-19 10:38:48 +0200106 if (ip_route_output_key(net, &rt, &fl)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 spin_unlock(&dest->dst_lock);
Harvey Harrison14d5e832008-10-31 00:54:29 -0700108 IP_VS_DBG_RL("ip_route_output error, dest: %pI4\n",
109 &dest->addr.ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 return NULL;
111 }
Hans Schillstrom714f0952010-10-19 10:38:48 +0200112 __ip_vs_dst_set(dest, rtos, dst_clone(&rt->dst), 0);
Harvey Harrison14d5e832008-10-31 00:54:29 -0700113 IP_VS_DBG(10, "new dst %pI4, refcnt=%d, rtos=%X\n",
114 &dest->addr.ip,
Changli Gaod8d1f302010-06-10 23:31:35 -0700115 atomic_read(&rt->dst.__refcnt), rtos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 }
117 spin_unlock(&dest->dst_lock);
118 } else {
119 struct flowi fl = {
Changli Gao58116622010-11-12 18:43:55 +0000120 .fl4_dst = daddr,
121 .fl4_tos = rtos,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 };
123
Hans Schillstrom714f0952010-10-19 10:38:48 +0200124 if (ip_route_output_key(net, &rt, &fl)) {
Harvey Harrison14d5e832008-10-31 00:54:29 -0700125 IP_VS_DBG_RL("ip_route_output error, dest: %pI4\n",
Julian Anastasovfc604762010-10-17 16:38:15 +0300126 &daddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 return NULL;
128 }
129 }
130
Julian Anastasovfc604762010-10-17 16:38:15 +0300131 local = rt->rt_flags & RTCF_LOCAL;
Changli Gao17a8f8e2011-02-24 08:19:57 +0800132 if (!((local ? IP_VS_RT_MODE_LOCAL : IP_VS_RT_MODE_NON_LOCAL) &
133 rt_mode)) {
Julian Anastasovfc604762010-10-17 16:38:15 +0300134 IP_VS_DBG_RL("Stopping traffic to %s address, dest: %pI4\n",
135 (rt->rt_flags & RTCF_LOCAL) ?
136 "local":"non-local", &rt->rt_dst);
137 ip_rt_put(rt);
138 return NULL;
139 }
Changli Gao17a8f8e2011-02-24 08:19:57 +0800140 if (local && !(rt_mode & IP_VS_RT_MODE_RDR) &&
141 !((ort = skb_rtable(skb)) && ort->rt_flags & RTCF_LOCAL)) {
Julian Anastasovfc604762010-10-17 16:38:15 +0300142 IP_VS_DBG_RL("Redirect from non-local address %pI4 to local "
143 "requires NAT method, dest: %pI4\n",
144 &ip_hdr(skb)->daddr, &rt->rt_dst);
145 ip_rt_put(rt);
146 return NULL;
147 }
148 if (unlikely(!local && ipv4_is_loopback(ip_hdr(skb)->saddr))) {
149 IP_VS_DBG_RL("Stopping traffic from loopback address %pI4 "
150 "to non-local address, dest: %pI4\n",
151 &ip_hdr(skb)->saddr, &rt->rt_dst);
152 ip_rt_put(rt);
153 return NULL;
154 }
155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 return rt;
157}
158
Julian Anastasovfc604762010-10-17 16:38:15 +0300159/* Reroute packet to local IPv4 stack after DNAT */
160static int
161__ip_vs_reroute_locally(struct sk_buff *skb)
162{
163 struct rtable *rt = skb_rtable(skb);
164 struct net_device *dev = rt->dst.dev;
165 struct net *net = dev_net(dev);
166 struct iphdr *iph = ip_hdr(skb);
167
David S. Millerc7537962010-11-11 17:07:48 -0800168 if (rt_is_input_route(rt)) {
Julian Anastasovfc604762010-10-17 16:38:15 +0300169 unsigned long orefdst = skb->_skb_refdst;
170
171 if (ip_route_input(skb, iph->daddr, iph->saddr,
172 iph->tos, skb->dev))
173 return 0;
174 refdst_drop(orefdst);
175 } else {
176 struct flowi fl = {
Changli Gao58116622010-11-12 18:43:55 +0000177 .fl4_dst = iph->daddr,
178 .fl4_src = iph->saddr,
179 .fl4_tos = RT_TOS(iph->tos),
Julian Anastasovfc604762010-10-17 16:38:15 +0300180 .mark = skb->mark,
181 };
Julian Anastasovfc604762010-10-17 16:38:15 +0300182
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
Julius Volz38cdcc92008-09-02 15:55:44 +0200196#ifdef CONFIG_IP_VS_IPV6
Hans Schillstrom714f0952010-10-19 10:38:48 +0200197
Julian Anastasovfc604762010-10-17 16:38:15 +0300198static 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
Hans Schillstrom714f0952010-10-19 10:38:48 +0200203static 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)
Julius Volz38cdcc92008-09-02 15:55:44 +0200206{
Hans Schillstrom714f0952010-10-19 10:38:48 +0200207 struct dst_entry *dst;
208 struct flowi fl = {
Changli Gao58116622010-11-12 18:43:55 +0000209 .fl6_dst = *daddr,
Hans Schillstrom714f0952010-10-19 10:38:48 +0200210 };
211
212 dst = ip6_route_output(net, NULL, &fl);
213 if (dst->error)
214 goto out_err;
215 if (!ret_saddr)
216 return dst;
217 if (ipv6_addr_any(&fl.fl6_src) &&
218 ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
219 &fl.fl6_dst, 0, &fl.fl6_src) < 0)
220 goto out_err;
221 if (do_xfrm && xfrm_lookup(net, &dst, &fl, NULL, 0) < 0)
222 goto out_err;
223 ipv6_addr_copy(ret_saddr, &fl.fl6_src);
224 return dst;
225
226out_err:
227 dst_release(dst);
228 IP_VS_DBG_RL("ip6_route_output error, dest: %pI6\n", daddr);
229 return NULL;
230}
231
Julian Anastasovfc604762010-10-17 16:38:15 +0300232/*
233 * Get route to destination or remote server
234 * rt_mode: flags, &1=Allow local dest, &2=Allow non-local dest,
235 * &4=Allow redirect from remote daddr to local
236 */
Hans Schillstrom714f0952010-10-19 10:38:48 +0200237static struct rt6_info *
Julian Anastasovfc604762010-10-17 16:38:15 +0300238__ip_vs_get_out_rt_v6(struct sk_buff *skb, struct ip_vs_dest *dest,
239 struct in6_addr *daddr, struct in6_addr *ret_saddr,
240 int do_xfrm, int rt_mode)
Hans Schillstrom714f0952010-10-19 10:38:48 +0200241{
Julian Anastasovfc604762010-10-17 16:38:15 +0300242 struct net *net = dev_net(skb_dst(skb)->dev);
Julius Volz38cdcc92008-09-02 15:55:44 +0200243 struct rt6_info *rt; /* Route to the other host */
Julian Anastasovfc604762010-10-17 16:38:15 +0300244 struct rt6_info *ort; /* Original route */
Hans Schillstrom714f0952010-10-19 10:38:48 +0200245 struct dst_entry *dst;
Julian Anastasovfc604762010-10-17 16:38:15 +0300246 int local;
Julius Volz38cdcc92008-09-02 15:55:44 +0200247
248 if (dest) {
249 spin_lock(&dest->dst_lock);
Hans Schillstrom714f0952010-10-19 10:38:48 +0200250 rt = (struct rt6_info *)__ip_vs_dst_check(dest, 0);
Julius Volz38cdcc92008-09-02 15:55:44 +0200251 if (!rt) {
Hans Schillstrom714f0952010-10-19 10:38:48 +0200252 u32 cookie;
Julius Volz38cdcc92008-09-02 15:55:44 +0200253
Hans Schillstrom714f0952010-10-19 10:38:48 +0200254 dst = __ip_vs_route_output_v6(net, &dest->addr.in6,
255 &dest->dst_saddr,
256 do_xfrm);
257 if (!dst) {
Julius Volz38cdcc92008-09-02 15:55:44 +0200258 spin_unlock(&dest->dst_lock);
Julius Volz38cdcc92008-09-02 15:55:44 +0200259 return NULL;
260 }
Hans Schillstrom714f0952010-10-19 10:38:48 +0200261 rt = (struct rt6_info *) dst;
262 cookie = rt->rt6i_node ? rt->rt6i_node->fn_sernum : 0;
263 __ip_vs_dst_set(dest, 0, dst_clone(&rt->dst), cookie);
264 IP_VS_DBG(10, "new dst %pI6, src %pI6, refcnt=%d\n",
265 &dest->addr.in6, &dest->dst_saddr,
Changli Gaod8d1f302010-06-10 23:31:35 -0700266 atomic_read(&rt->dst.__refcnt));
Julius Volz38cdcc92008-09-02 15:55:44 +0200267 }
Hans Schillstrom714f0952010-10-19 10:38:48 +0200268 if (ret_saddr)
269 ipv6_addr_copy(ret_saddr, &dest->dst_saddr);
Julius Volz38cdcc92008-09-02 15:55:44 +0200270 spin_unlock(&dest->dst_lock);
271 } else {
Julian Anastasovfc604762010-10-17 16:38:15 +0300272 dst = __ip_vs_route_output_v6(net, daddr, ret_saddr, do_xfrm);
Hans Schillstrom714f0952010-10-19 10:38:48 +0200273 if (!dst)
Julius Volz38cdcc92008-09-02 15:55:44 +0200274 return NULL;
Hans Schillstrom714f0952010-10-19 10:38:48 +0200275 rt = (struct rt6_info *) dst;
Julius Volz38cdcc92008-09-02 15:55:44 +0200276 }
277
Julian Anastasovfc604762010-10-17 16:38:15 +0300278 local = __ip_vs_is_local_route6(rt);
279 if (!((local ? 1 : 2) & rt_mode)) {
280 IP_VS_DBG_RL("Stopping traffic to %s address, dest: %pI6\n",
281 local ? "local":"non-local", daddr);
282 dst_release(&rt->dst);
283 return NULL;
284 }
285 if (local && !(rt_mode & 4) &&
286 !((ort = (struct rt6_info *) skb_dst(skb)) &&
287 __ip_vs_is_local_route6(ort))) {
288 IP_VS_DBG_RL("Redirect from non-local address %pI6 to local "
289 "requires NAT method, dest: %pI6\n",
290 &ipv6_hdr(skb)->daddr, daddr);
291 dst_release(&rt->dst);
292 return NULL;
293 }
294 if (unlikely(!local && (!skb->dev || skb->dev->flags & IFF_LOOPBACK) &&
295 ipv6_addr_type(&ipv6_hdr(skb)->saddr) &
296 IPV6_ADDR_LOOPBACK)) {
297 IP_VS_DBG_RL("Stopping traffic from loopback address %pI6 "
298 "to non-local address, dest: %pI6\n",
299 &ipv6_hdr(skb)->saddr, daddr);
300 dst_release(&rt->dst);
301 return NULL;
302 }
303
Julius Volz38cdcc92008-09-02 15:55:44 +0200304 return rt;
305}
306#endif
307
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
309/*
310 * Release dest->dst_cache before a dest is removed
311 */
312void
313ip_vs_dst_reset(struct ip_vs_dest *dest)
314{
315 struct dst_entry *old_dst;
316
317 old_dst = dest->dst_cache;
318 dest->dst_cache = NULL;
319 dst_release(old_dst);
320}
321
Julian Anastasovf4bc17c2010-09-21 17:35:41 +0200322#define IP_VS_XMIT_TUNNEL(skb, cp) \
323({ \
324 int __ret = NF_ACCEPT; \
325 \
Julian Anastasovcf356d62010-10-17 16:21:07 +0300326 (skb)->ipvs_property = 1; \
Julian Anastasovf4bc17c2010-09-21 17:35:41 +0200327 if (unlikely((cp)->flags & IP_VS_CONN_F_NFCT)) \
328 __ret = ip_vs_confirm_conntrack(skb, cp); \
329 if (__ret == NF_ACCEPT) { \
330 nf_reset(skb); \
Julian Anastasov4256f1a2010-10-17 16:29:40 +0300331 skb_forward_csum(skb); \
Julian Anastasovf4bc17c2010-09-21 17:35:41 +0200332 } \
333 __ret; \
334})
335
Julian Anastasovfc604762010-10-17 16:38:15 +0300336#define IP_VS_XMIT_NAT(pf, skb, cp, local) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337do { \
Julian Anastasovcf356d62010-10-17 16:21:07 +0300338 (skb)->ipvs_property = 1; \
Julian Anastasovf4bc17c2010-09-21 17:35:41 +0200339 if (likely(!((cp)->flags & IP_VS_CONN_F_NFCT))) \
Julian Anastasovcf356d62010-10-17 16:21:07 +0300340 ip_vs_notrack(skb); \
Julian Anastasovf4bc17c2010-09-21 17:35:41 +0200341 else \
342 ip_vs_update_conntrack(skb, cp, 1); \
Julian Anastasovfc604762010-10-17 16:38:15 +0300343 if (local) \
344 return NF_ACCEPT; \
Herbert Xuccc79112007-07-30 16:20:12 -0700345 skb_forward_csum(skb); \
Julius Volz38cdcc92008-09-02 15:55:44 +0200346 NF_HOOK(pf, NF_INET_LOCAL_OUT, (skb), NULL, \
Julian Anastasovf4bc17c2010-09-21 17:35:41 +0200347 skb_dst(skb)->dev, dst_output); \
348} while (0)
349
Julian Anastasovfc604762010-10-17 16:38:15 +0300350#define IP_VS_XMIT(pf, skb, cp, local) \
Julian Anastasovf4bc17c2010-09-21 17:35:41 +0200351do { \
Julian Anastasovcf356d62010-10-17 16:21:07 +0300352 (skb)->ipvs_property = 1; \
Julian Anastasovf4bc17c2010-09-21 17:35:41 +0200353 if (likely(!((cp)->flags & IP_VS_CONN_F_NFCT))) \
Julian Anastasovcf356d62010-10-17 16:21:07 +0300354 ip_vs_notrack(skb); \
Julian Anastasovfc604762010-10-17 16:38:15 +0300355 if (local) \
356 return NF_ACCEPT; \
Julian Anastasovf4bc17c2010-09-21 17:35:41 +0200357 skb_forward_csum(skb); \
358 NF_HOOK(pf, NF_INET_LOCAL_OUT, (skb), NULL, \
359 skb_dst(skb)->dev, dst_output); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360} while (0)
361
362
363/*
364 * NULL transmitter (do nothing except return NF_ACCEPT)
365 */
366int
367ip_vs_null_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
368 struct ip_vs_protocol *pp)
369{
370 /* we do not touch skb and do not need pskb ptr */
Julian Anastasovfc604762010-10-17 16:38:15 +0300371 IP_VS_XMIT(NFPROTO_IPV4, skb, cp, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372}
373
374
375/*
376 * Bypass transmitter
377 * Let packets bypass the destination when the destination is not
378 * available, it may be only used in transparent cache cluster.
379 */
380int
381ip_vs_bypass_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
382 struct ip_vs_protocol *pp)
383{
384 struct rtable *rt; /* Route to the other host */
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -0700385 struct iphdr *iph = ip_hdr(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 int mtu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
388 EnterFunction(10);
389
Changli Gao17a8f8e2011-02-24 08:19:57 +0800390 if (!(rt = __ip_vs_get_out_rt(skb, NULL, iph->daddr, RT_TOS(iph->tos),
391 IP_VS_RT_MODE_NON_LOCAL)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 goto tx_error_icmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
394 /* MTU checking */
Changli Gaod8d1f302010-06-10 23:31:35 -0700395 mtu = dst_mtu(&rt->dst);
Simon Horman8f1b03a2010-11-09 10:08:49 +0900396 if ((skb->len > mtu) && (iph->frag_off & htons(IP_DF)) &&
397 !skb_is_gso(skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 ip_rt_put(rt);
399 icmp_send(skb, ICMP_DEST_UNREACH,ICMP_FRAG_NEEDED, htonl(mtu));
Hannes Eder1e3e2382009-08-02 11:05:41 +0000400 IP_VS_DBG_RL("%s(): frag needed\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 goto tx_error;
402 }
403
404 /*
405 * Call ip_send_check because we are not sure it is called
406 * after ip_defrag. Is copy-on-write needed?
407 */
408 if (unlikely((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL)) {
409 ip_rt_put(rt);
410 return NF_STOLEN;
411 }
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -0700412 ip_send_check(ip_hdr(skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
414 /* drop old route */
Eric Dumazetadf30902009-06-02 05:19:30 +0000415 skb_dst_drop(skb);
Changli Gaod8d1f302010-06-10 23:31:35 -0700416 skb_dst_set(skb, &rt->dst);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
418 /* Another hack: avoid icmp_send in ip_fragment */
419 skb->local_df = 1;
420
Julian Anastasovfc604762010-10-17 16:38:15 +0300421 IP_VS_XMIT(NFPROTO_IPV4, skb, cp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
423 LeaveFunction(10);
424 return NF_STOLEN;
425
426 tx_error_icmp:
427 dst_link_failure(skb);
428 tx_error:
429 kfree_skb(skb);
430 LeaveFunction(10);
431 return NF_STOLEN;
432}
433
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200434#ifdef CONFIG_IP_VS_IPV6
435int
436ip_vs_bypass_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
437 struct ip_vs_protocol *pp)
438{
439 struct rt6_info *rt; /* Route to the other host */
440 struct ipv6hdr *iph = ipv6_hdr(skb);
441 int mtu;
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200442
443 EnterFunction(10);
444
Julian Anastasovfc604762010-10-17 16:38:15 +0300445 if (!(rt = __ip_vs_get_out_rt_v6(skb, NULL, &iph->daddr, NULL, 0, 2)))
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200446 goto tx_error_icmp;
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200447
448 /* MTU checking */
Changli Gaod8d1f302010-06-10 23:31:35 -0700449 mtu = dst_mtu(&rt->dst);
Simon Horman8f1b03a2010-11-09 10:08:49 +0900450 if (skb->len > mtu && !skb_is_gso(skb)) {
Julian Anastasovcb591552010-10-17 16:40:51 +0300451 if (!skb->dev) {
452 struct net *net = dev_net(skb_dst(skb)->dev);
453
454 skb->dev = net->loopback_dev;
455 }
Alexey Dobriyan3ffe5332010-02-18 08:25:24 +0000456 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
Julian Anastasovcb591552010-10-17 16:40:51 +0300457 dst_release(&rt->dst);
Hannes Eder1e3e2382009-08-02 11:05:41 +0000458 IP_VS_DBG_RL("%s(): frag needed\n", __func__);
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200459 goto tx_error;
460 }
461
462 /*
463 * Call ip_send_check because we are not sure it is called
464 * after ip_defrag. Is copy-on-write needed?
465 */
466 skb = skb_share_check(skb, GFP_ATOMIC);
467 if (unlikely(skb == NULL)) {
Changli Gaod8d1f302010-06-10 23:31:35 -0700468 dst_release(&rt->dst);
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200469 return NF_STOLEN;
470 }
471
472 /* drop old route */
Eric Dumazetadf30902009-06-02 05:19:30 +0000473 skb_dst_drop(skb);
Changli Gaod8d1f302010-06-10 23:31:35 -0700474 skb_dst_set(skb, &rt->dst);
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200475
476 /* Another hack: avoid icmp_send in ip_fragment */
477 skb->local_df = 1;
478
Julian Anastasovfc604762010-10-17 16:38:15 +0300479 IP_VS_XMIT(NFPROTO_IPV6, skb, cp, 0);
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200480
481 LeaveFunction(10);
482 return NF_STOLEN;
483
484 tx_error_icmp:
485 dst_link_failure(skb);
486 tx_error:
487 kfree_skb(skb);
488 LeaveFunction(10);
489 return NF_STOLEN;
490}
491#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
493/*
494 * NAT transmitter (only for outside-to-inside nat forwarding)
495 * Not used for related ICMP
496 */
497int
498ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
499 struct ip_vs_protocol *pp)
500{
501 struct rtable *rt; /* Route to the other host */
502 int mtu;
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -0700503 struct iphdr *iph = ip_hdr(skb);
Julian Anastasovfc604762010-10-17 16:38:15 +0300504 int local;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
506 EnterFunction(10);
507
508 /* check if it is a connection of no-client-port */
509 if (unlikely(cp->flags & IP_VS_CONN_F_NO_CPORT)) {
Al Viro014d7302006-09-28 14:29:52 -0700510 __be16 _pt, *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 p = skb_header_pointer(skb, iph->ihl*4, sizeof(_pt), &_pt);
512 if (p == NULL)
513 goto tx_error;
514 ip_vs_conn_fill_cport(cp, *p);
515 IP_VS_DBG(10, "filled cport=%d\n", ntohs(*p));
516 }
517
Julian Anastasovfc604762010-10-17 16:38:15 +0300518 if (!(rt = __ip_vs_get_out_rt(skb, cp->dest, cp->daddr.ip,
Changli Gao17a8f8e2011-02-24 08:19:57 +0800519 RT_TOS(iph->tos),
520 IP_VS_RT_MODE_LOCAL |
521 IP_VS_RT_MODE_NON_LOCAL |
522 IP_VS_RT_MODE_RDR)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 goto tx_error_icmp;
Julian Anastasovfc604762010-10-17 16:38:15 +0300524 local = rt->rt_flags & RTCF_LOCAL;
525 /*
526 * Avoid duplicate tuple in reply direction for NAT traffic
527 * to local address when connection is sync-ed
528 */
529#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
530 if (cp->flags & IP_VS_CONN_F_SYNC && local) {
531 enum ip_conntrack_info ctinfo;
532 struct nf_conn *ct = ct = nf_ct_get(skb, &ctinfo);
533
534 if (ct && !nf_ct_is_untracked(ct)) {
Julian Anastasov0d796412010-10-17 16:46:17 +0300535 IP_VS_DBG_RL_PKT(10, AF_INET, pp, skb, 0,
536 "ip_vs_nat_xmit(): "
Julian Anastasovfc604762010-10-17 16:38:15 +0300537 "stopping DNAT to local address");
538 goto tx_error_put;
539 }
540 }
541#endif
542
543 /* From world but DNAT to loopback address? */
David S. Millerc7537962010-11-11 17:07:48 -0800544 if (local && ipv4_is_loopback(rt->rt_dst) &&
545 rt_is_input_route(skb_rtable(skb))) {
Julian Anastasov0d796412010-10-17 16:46:17 +0300546 IP_VS_DBG_RL_PKT(1, AF_INET, pp, skb, 0, "ip_vs_nat_xmit(): "
Julian Anastasovfc604762010-10-17 16:38:15 +0300547 "stopping DNAT to loopback address");
548 goto tx_error_put;
549 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
551 /* MTU checking */
Changli Gaod8d1f302010-06-10 23:31:35 -0700552 mtu = dst_mtu(&rt->dst);
Simon Horman8f1b03a2010-11-09 10:08:49 +0900553 if ((skb->len > mtu) && (iph->frag_off & htons(IP_DF)) &&
554 !skb_is_gso(skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 icmp_send(skb, ICMP_DEST_UNREACH,ICMP_FRAG_NEEDED, htonl(mtu));
Julian Anastasov0d796412010-10-17 16:46:17 +0300556 IP_VS_DBG_RL_PKT(0, AF_INET, pp, skb, 0,
557 "ip_vs_nat_xmit(): frag needed for");
Julian Anastasovfc604762010-10-17 16:38:15 +0300558 goto tx_error_put;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 }
560
561 /* copy-on-write the packet before mangling it */
Herbert Xuaf1e1cf2007-10-14 00:39:33 -0700562 if (!skb_make_writable(skb, sizeof(struct iphdr)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 goto tx_error_put;
564
Changli Gaod8d1f302010-06-10 23:31:35 -0700565 if (skb_cow(skb, rt->dst.dev->hard_header_len))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 goto tx_error_put;
567
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 /* mangle the packet */
Herbert Xu3db05fe2007-10-15 00:53:15 -0700569 if (pp->dnat_handler && !pp->dnat_handler(skb, pp, cp))
Julian Anastasovfc604762010-10-17 16:38:15 +0300570 goto tx_error_put;
Julius Volze7ade462008-09-02 15:55:33 +0200571 ip_hdr(skb)->daddr = cp->daddr.ip;
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -0700572 ip_send_check(ip_hdr(skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573
Julian Anastasovfc604762010-10-17 16:38:15 +0300574 if (!local) {
575 /* drop old route */
576 skb_dst_drop(skb);
577 skb_dst_set(skb, &rt->dst);
578 } else {
579 ip_rt_put(rt);
580 /*
581 * Some IPv4 replies get local address from routes,
582 * not from iph, so while we DNAT after routing
583 * we need this second input/output route.
584 */
585 if (!__ip_vs_reroute_locally(skb))
586 goto tx_error;
587 }
588
Julian Anastasov0d796412010-10-17 16:46:17 +0300589 IP_VS_DBG_PKT(10, AF_INET, pp, skb, 0, "After DNAT");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
591 /* FIXME: when application helper enlarges the packet and the length
592 is larger than the MTU of outgoing device, there will be still
593 MTU problem. */
594
595 /* Another hack: avoid icmp_send in ip_fragment */
596 skb->local_df = 1;
597
Julian Anastasovfc604762010-10-17 16:38:15 +0300598 IP_VS_XMIT_NAT(NFPROTO_IPV4, skb, cp, local);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
600 LeaveFunction(10);
601 return NF_STOLEN;
602
603 tx_error_icmp:
604 dst_link_failure(skb);
605 tx_error:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 kfree_skb(skb);
Julian Anastasovf4bc17c2010-09-21 17:35:41 +0200607 LeaveFunction(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 return NF_STOLEN;
609 tx_error_put:
610 ip_rt_put(rt);
611 goto tx_error;
612}
613
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200614#ifdef CONFIG_IP_VS_IPV6
615int
616ip_vs_nat_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
617 struct ip_vs_protocol *pp)
618{
619 struct rt6_info *rt; /* Route to the other host */
620 int mtu;
Julian Anastasovfc604762010-10-17 16:38:15 +0300621 int local;
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200622
623 EnterFunction(10);
624
625 /* check if it is a connection of no-client-port */
626 if (unlikely(cp->flags & IP_VS_CONN_F_NO_CPORT)) {
627 __be16 _pt, *p;
628 p = skb_header_pointer(skb, sizeof(struct ipv6hdr),
629 sizeof(_pt), &_pt);
630 if (p == NULL)
631 goto tx_error;
632 ip_vs_conn_fill_cport(cp, *p);
633 IP_VS_DBG(10, "filled cport=%d\n", ntohs(*p));
634 }
635
Julian Anastasovfc604762010-10-17 16:38:15 +0300636 if (!(rt = __ip_vs_get_out_rt_v6(skb, cp->dest, &cp->daddr.in6, NULL,
637 0, 1|2|4)))
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200638 goto tx_error_icmp;
Julian Anastasovfc604762010-10-17 16:38:15 +0300639 local = __ip_vs_is_local_route6(rt);
640 /*
641 * Avoid duplicate tuple in reply direction for NAT traffic
642 * to local address when connection is sync-ed
643 */
644#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
645 if (cp->flags & IP_VS_CONN_F_SYNC && local) {
646 enum ip_conntrack_info ctinfo;
647 struct nf_conn *ct = ct = nf_ct_get(skb, &ctinfo);
648
649 if (ct && !nf_ct_is_untracked(ct)) {
Julian Anastasov0d796412010-10-17 16:46:17 +0300650 IP_VS_DBG_RL_PKT(10, AF_INET6, pp, skb, 0,
Julian Anastasovfc604762010-10-17 16:38:15 +0300651 "ip_vs_nat_xmit_v6(): "
652 "stopping DNAT to local address");
653 goto tx_error_put;
654 }
655 }
656#endif
657
658 /* From world but DNAT to loopback address? */
659 if (local && skb->dev && !(skb->dev->flags & IFF_LOOPBACK) &&
660 ipv6_addr_type(&rt->rt6i_dst.addr) & IPV6_ADDR_LOOPBACK) {
Julian Anastasov0d796412010-10-17 16:46:17 +0300661 IP_VS_DBG_RL_PKT(1, AF_INET6, pp, skb, 0,
Julian Anastasovfc604762010-10-17 16:38:15 +0300662 "ip_vs_nat_xmit_v6(): "
663 "stopping DNAT to loopback address");
664 goto tx_error_put;
665 }
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200666
667 /* MTU checking */
Changli Gaod8d1f302010-06-10 23:31:35 -0700668 mtu = dst_mtu(&rt->dst);
Simon Horman8f1b03a2010-11-09 10:08:49 +0900669 if (skb->len > mtu && !skb_is_gso(skb)) {
Julian Anastasovcb591552010-10-17 16:40:51 +0300670 if (!skb->dev) {
671 struct net *net = dev_net(skb_dst(skb)->dev);
672
673 skb->dev = net->loopback_dev;
674 }
Alexey Dobriyan3ffe5332010-02-18 08:25:24 +0000675 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
Julian Anastasov0d796412010-10-17 16:46:17 +0300676 IP_VS_DBG_RL_PKT(0, AF_INET6, pp, skb, 0,
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200677 "ip_vs_nat_xmit_v6(): frag needed for");
Julian Anastasovfc604762010-10-17 16:38:15 +0300678 goto tx_error_put;
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200679 }
680
681 /* copy-on-write the packet before mangling it */
682 if (!skb_make_writable(skb, sizeof(struct ipv6hdr)))
683 goto tx_error_put;
684
Changli Gaod8d1f302010-06-10 23:31:35 -0700685 if (skb_cow(skb, rt->dst.dev->hard_header_len))
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200686 goto tx_error_put;
687
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200688 /* mangle the packet */
689 if (pp->dnat_handler && !pp->dnat_handler(skb, pp, cp))
690 goto tx_error;
Julian Anastasovfc604762010-10-17 16:38:15 +0300691 ipv6_addr_copy(&ipv6_hdr(skb)->daddr, &cp->daddr.in6);
692
693 if (!local || !skb->dev) {
694 /* drop the old route when skb is not shared */
695 skb_dst_drop(skb);
696 skb_dst_set(skb, &rt->dst);
697 } else {
698 /* destined to loopback, do we need to change route? */
699 dst_release(&rt->dst);
700 }
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200701
Julian Anastasov0d796412010-10-17 16:46:17 +0300702 IP_VS_DBG_PKT(10, AF_INET6, pp, skb, 0, "After DNAT");
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200703
704 /* FIXME: when application helper enlarges the packet and the length
705 is larger than the MTU of outgoing device, there will be still
706 MTU problem. */
707
708 /* Another hack: avoid icmp_send in ip_fragment */
709 skb->local_df = 1;
710
Julian Anastasovfc604762010-10-17 16:38:15 +0300711 IP_VS_XMIT_NAT(NFPROTO_IPV6, skb, cp, local);
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200712
713 LeaveFunction(10);
714 return NF_STOLEN;
715
716tx_error_icmp:
717 dst_link_failure(skb);
718tx_error:
719 LeaveFunction(10);
720 kfree_skb(skb);
721 return NF_STOLEN;
722tx_error_put:
Changli Gaod8d1f302010-06-10 23:31:35 -0700723 dst_release(&rt->dst);
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200724 goto tx_error;
725}
726#endif
727
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728
729/*
730 * IP Tunneling transmitter
731 *
732 * This function encapsulates the packet in a new IP packet, its
733 * destination will be set to cp->daddr. Most code of this function
734 * is taken from ipip.c.
735 *
736 * It is used in VS/TUN cluster. The load balancer selects a real
737 * server from a cluster based on a scheduling algorithm,
738 * encapsulates the request packet and forwards it to the selected
739 * server. For example, all real servers are configured with
740 * "ifconfig tunl0 <Virtual IP Address> up". When the server receives
741 * the encapsulated packet, it will decapsulate the packet, processe
742 * the request and return the response packets directly to the client
743 * without passing the load balancer. This can greatly increase the
744 * scalability of virtual server.
745 *
746 * Used for ANY protocol
747 */
748int
749ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
750 struct ip_vs_protocol *pp)
751{
752 struct rtable *rt; /* Route to the other host */
753 struct net_device *tdev; /* Device to other host */
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -0700754 struct iphdr *old_iph = ip_hdr(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 u8 tos = old_iph->tos;
Alexey Dobriyan76ab6082006-01-06 13:24:29 -0800756 __be16 df = old_iph->frag_off;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 struct iphdr *iph; /* Our new IP header */
Chuck Leverc2636b42007-10-23 21:07:32 -0700758 unsigned int max_headroom; /* The extra header space needed */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 int mtu;
Julian Anastasovf4bc17c2010-09-21 17:35:41 +0200760 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
762 EnterFunction(10);
763
Julian Anastasovfc604762010-10-17 16:38:15 +0300764 if (!(rt = __ip_vs_get_out_rt(skb, cp->dest, cp->daddr.ip,
Changli Gao17a8f8e2011-02-24 08:19:57 +0800765 RT_TOS(tos), IP_VS_RT_MODE_LOCAL |
766 IP_VS_RT_MODE_NON_LOCAL)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 goto tx_error_icmp;
Julian Anastasovfc604762010-10-17 16:38:15 +0300768 if (rt->rt_flags & RTCF_LOCAL) {
769 ip_rt_put(rt);
770 IP_VS_XMIT(NFPROTO_IPV4, skb, cp, 1);
771 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772
Changli Gaod8d1f302010-06-10 23:31:35 -0700773 tdev = rt->dst.dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
Changli Gaod8d1f302010-06-10 23:31:35 -0700775 mtu = dst_mtu(&rt->dst) - sizeof(struct iphdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 if (mtu < 68) {
Hannes Eder1e3e2382009-08-02 11:05:41 +0000777 IP_VS_DBG_RL("%s(): mtu less than 68\n", __func__);
Julian Anastasovfc604762010-10-17 16:38:15 +0300778 goto tx_error_put;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 }
Eric Dumazetadf30902009-06-02 05:19:30 +0000780 if (skb_dst(skb))
781 skb_dst(skb)->ops->update_pmtu(skb_dst(skb), mtu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782
YOSHIFUJI Hideaki4412ec42007-03-07 14:19:10 +0900783 df |= (old_iph->frag_off & htons(IP_DF));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784
Simon Horman8f1b03a2010-11-09 10:08:49 +0900785 if ((old_iph->frag_off & htons(IP_DF) &&
786 mtu < ntohs(old_iph->tot_len) && !skb_is_gso(skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 icmp_send(skb, ICMP_DEST_UNREACH,ICMP_FRAG_NEEDED, htonl(mtu));
Hannes Eder1e3e2382009-08-02 11:05:41 +0000788 IP_VS_DBG_RL("%s(): frag needed\n", __func__);
Julian Anastasovfc604762010-10-17 16:38:15 +0300789 goto tx_error_put;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 }
791
792 /*
793 * Okay, now see if we can stuff it in the buffer as-is.
794 */
795 max_headroom = LL_RESERVED_SPACE(tdev) + sizeof(struct iphdr);
796
797 if (skb_headroom(skb) < max_headroom
798 || skb_cloned(skb) || skb_shared(skb)) {
799 struct sk_buff *new_skb =
800 skb_realloc_headroom(skb, max_headroom);
801 if (!new_skb) {
802 ip_rt_put(rt);
803 kfree_skb(skb);
Hannes Eder1e3e2382009-08-02 11:05:41 +0000804 IP_VS_ERR_RL("%s(): no memory\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 return NF_STOLEN;
806 }
807 kfree_skb(skb);
808 skb = new_skb;
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -0700809 old_iph = ip_hdr(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 }
811
Hans Schillstrom714f0952010-10-19 10:38:48 +0200812 skb->transport_header = skb->network_header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
814 /* fix old IP header checksum */
815 ip_send_check(old_iph);
816
Arnaldo Carvalho de Meloe2d1bca2007-04-10 20:46:21 -0700817 skb_push(skb, sizeof(struct iphdr));
818 skb_reset_network_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
820
821 /* drop old route */
Eric Dumazetadf30902009-06-02 05:19:30 +0000822 skb_dst_drop(skb);
Changli Gaod8d1f302010-06-10 23:31:35 -0700823 skb_dst_set(skb, &rt->dst);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824
825 /*
826 * Push down and install the IPIP header.
827 */
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -0700828 iph = ip_hdr(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 iph->version = 4;
830 iph->ihl = sizeof(struct iphdr)>>2;
831 iph->frag_off = df;
832 iph->protocol = IPPROTO_IPIP;
833 iph->tos = tos;
834 iph->daddr = rt->rt_dst;
835 iph->saddr = rt->rt_src;
836 iph->ttl = old_iph->ttl;
Changli Gaod8d1f302010-06-10 23:31:35 -0700837 ip_select_ident(iph, &rt->dst, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838
839 /* Another hack: avoid icmp_send in ip_fragment */
840 skb->local_df = 1;
841
Julian Anastasovf4bc17c2010-09-21 17:35:41 +0200842 ret = IP_VS_XMIT_TUNNEL(skb, cp);
843 if (ret == NF_ACCEPT)
844 ip_local_out(skb);
845 else if (ret == NF_DROP)
846 kfree_skb(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847
848 LeaveFunction(10);
849
850 return NF_STOLEN;
851
852 tx_error_icmp:
853 dst_link_failure(skb);
854 tx_error:
855 kfree_skb(skb);
856 LeaveFunction(10);
857 return NF_STOLEN;
Julian Anastasovfc604762010-10-17 16:38:15 +0300858tx_error_put:
859 ip_rt_put(rt);
860 goto tx_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861}
862
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200863#ifdef CONFIG_IP_VS_IPV6
864int
865ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
866 struct ip_vs_protocol *pp)
867{
868 struct rt6_info *rt; /* Route to the other host */
Hans Schillstrom714f0952010-10-19 10:38:48 +0200869 struct in6_addr saddr; /* Source for tunnel */
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200870 struct net_device *tdev; /* Device to other host */
871 struct ipv6hdr *old_iph = ipv6_hdr(skb);
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200872 struct ipv6hdr *iph; /* Our new IP header */
873 unsigned int max_headroom; /* The extra header space needed */
874 int mtu;
Julian Anastasovf4bc17c2010-09-21 17:35:41 +0200875 int ret;
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200876
877 EnterFunction(10);
878
Julian Anastasovfc604762010-10-17 16:38:15 +0300879 if (!(rt = __ip_vs_get_out_rt_v6(skb, cp->dest, &cp->daddr.in6,
880 &saddr, 1, 1|2)))
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200881 goto tx_error_icmp;
Julian Anastasovfc604762010-10-17 16:38:15 +0300882 if (__ip_vs_is_local_route6(rt)) {
883 dst_release(&rt->dst);
884 IP_VS_XMIT(NFPROTO_IPV6, skb, cp, 1);
885 }
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200886
Changli Gaod8d1f302010-06-10 23:31:35 -0700887 tdev = rt->dst.dev;
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200888
Changli Gaod8d1f302010-06-10 23:31:35 -0700889 mtu = dst_mtu(&rt->dst) - sizeof(struct ipv6hdr);
Hans Schillstrom714f0952010-10-19 10:38:48 +0200890 if (mtu < IPV6_MIN_MTU) {
Hans Schillstrom714f0952010-10-19 10:38:48 +0200891 IP_VS_DBG_RL("%s(): mtu less than %d\n", __func__,
892 IPV6_MIN_MTU);
Julian Anastasovfc604762010-10-17 16:38:15 +0300893 goto tx_error_put;
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200894 }
Eric Dumazetadf30902009-06-02 05:19:30 +0000895 if (skb_dst(skb))
896 skb_dst(skb)->ops->update_pmtu(skb_dst(skb), mtu);
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200897
Simon Horman8f1b03a2010-11-09 10:08:49 +0900898 if (mtu < ntohs(old_iph->payload_len) + sizeof(struct ipv6hdr) &&
899 !skb_is_gso(skb)) {
Julian Anastasovcb591552010-10-17 16:40:51 +0300900 if (!skb->dev) {
901 struct net *net = dev_net(skb_dst(skb)->dev);
902
903 skb->dev = net->loopback_dev;
904 }
Alexey Dobriyan3ffe5332010-02-18 08:25:24 +0000905 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
Hannes Eder1e3e2382009-08-02 11:05:41 +0000906 IP_VS_DBG_RL("%s(): frag needed\n", __func__);
Julian Anastasovfc604762010-10-17 16:38:15 +0300907 goto tx_error_put;
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200908 }
909
910 /*
911 * Okay, now see if we can stuff it in the buffer as-is.
912 */
913 max_headroom = LL_RESERVED_SPACE(tdev) + sizeof(struct ipv6hdr);
914
915 if (skb_headroom(skb) < max_headroom
916 || skb_cloned(skb) || skb_shared(skb)) {
917 struct sk_buff *new_skb =
918 skb_realloc_headroom(skb, max_headroom);
919 if (!new_skb) {
Changli Gaod8d1f302010-06-10 23:31:35 -0700920 dst_release(&rt->dst);
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200921 kfree_skb(skb);
Hannes Eder1e3e2382009-08-02 11:05:41 +0000922 IP_VS_ERR_RL("%s(): no memory\n", __func__);
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200923 return NF_STOLEN;
924 }
925 kfree_skb(skb);
926 skb = new_skb;
927 old_iph = ipv6_hdr(skb);
928 }
929
Hans Schillstrom714f0952010-10-19 10:38:48 +0200930 skb->transport_header = skb->network_header;
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200931
932 skb_push(skb, sizeof(struct ipv6hdr));
933 skb_reset_network_header(skb);
934 memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
935
936 /* drop old route */
Eric Dumazetadf30902009-06-02 05:19:30 +0000937 skb_dst_drop(skb);
Changli Gaod8d1f302010-06-10 23:31:35 -0700938 skb_dst_set(skb, &rt->dst);
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200939
940 /*
941 * Push down and install the IPIP header.
942 */
943 iph = ipv6_hdr(skb);
944 iph->version = 6;
945 iph->nexthdr = IPPROTO_IPV6;
Harvey Harrisonb7b45f42008-11-10 16:46:06 -0800946 iph->payload_len = old_iph->payload_len;
947 be16_add_cpu(&iph->payload_len, sizeof(*old_iph));
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200948 iph->priority = old_iph->priority;
949 memset(&iph->flow_lbl, 0, sizeof(iph->flow_lbl));
Hans Schillstrom714f0952010-10-19 10:38:48 +0200950 ipv6_addr_copy(&iph->daddr, &cp->daddr.in6);
951 ipv6_addr_copy(&iph->saddr, &saddr);
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200952 iph->hop_limit = old_iph->hop_limit;
953
954 /* Another hack: avoid icmp_send in ip_fragment */
955 skb->local_df = 1;
956
Julian Anastasovf4bc17c2010-09-21 17:35:41 +0200957 ret = IP_VS_XMIT_TUNNEL(skb, cp);
958 if (ret == NF_ACCEPT)
959 ip6_local_out(skb);
960 else if (ret == NF_DROP)
961 kfree_skb(skb);
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200962
963 LeaveFunction(10);
964
965 return NF_STOLEN;
966
967tx_error_icmp:
968 dst_link_failure(skb);
969tx_error:
970 kfree_skb(skb);
971 LeaveFunction(10);
972 return NF_STOLEN;
Julian Anastasovfc604762010-10-17 16:38:15 +0300973tx_error_put:
974 dst_release(&rt->dst);
975 goto tx_error;
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200976}
977#endif
978
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979
980/*
981 * Direct Routing transmitter
982 * Used for ANY protocol
983 */
984int
985ip_vs_dr_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
986 struct ip_vs_protocol *pp)
987{
988 struct rtable *rt; /* Route to the other host */
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -0700989 struct iphdr *iph = ip_hdr(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 int mtu;
991
992 EnterFunction(10);
993
Julian Anastasovfc604762010-10-17 16:38:15 +0300994 if (!(rt = __ip_vs_get_out_rt(skb, cp->dest, cp->daddr.ip,
Changli Gao17a8f8e2011-02-24 08:19:57 +0800995 RT_TOS(iph->tos),
996 IP_VS_RT_MODE_LOCAL |
997 IP_VS_RT_MODE_NON_LOCAL)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 goto tx_error_icmp;
Julian Anastasovfc604762010-10-17 16:38:15 +0300999 if (rt->rt_flags & RTCF_LOCAL) {
1000 ip_rt_put(rt);
1001 IP_VS_XMIT(NFPROTO_IPV4, skb, cp, 1);
1002 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003
1004 /* MTU checking */
Changli Gaod8d1f302010-06-10 23:31:35 -07001005 mtu = dst_mtu(&rt->dst);
Simon Horman8f1b03a2010-11-09 10:08:49 +09001006 if ((iph->frag_off & htons(IP_DF)) && skb->len > mtu &&
1007 !skb_is_gso(skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 icmp_send(skb, ICMP_DEST_UNREACH,ICMP_FRAG_NEEDED, htonl(mtu));
1009 ip_rt_put(rt);
Hannes Eder1e3e2382009-08-02 11:05:41 +00001010 IP_VS_DBG_RL("%s(): frag needed\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 goto tx_error;
1012 }
1013
1014 /*
1015 * Call ip_send_check because we are not sure it is called
1016 * after ip_defrag. Is copy-on-write needed?
1017 */
1018 if (unlikely((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL)) {
1019 ip_rt_put(rt);
1020 return NF_STOLEN;
1021 }
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001022 ip_send_check(ip_hdr(skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023
1024 /* drop old route */
Eric Dumazetadf30902009-06-02 05:19:30 +00001025 skb_dst_drop(skb);
Changli Gaod8d1f302010-06-10 23:31:35 -07001026 skb_dst_set(skb, &rt->dst);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027
1028 /* Another hack: avoid icmp_send in ip_fragment */
1029 skb->local_df = 1;
1030
Julian Anastasovfc604762010-10-17 16:38:15 +03001031 IP_VS_XMIT(NFPROTO_IPV4, skb, cp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032
1033 LeaveFunction(10);
1034 return NF_STOLEN;
1035
1036 tx_error_icmp:
1037 dst_link_failure(skb);
1038 tx_error:
1039 kfree_skb(skb);
1040 LeaveFunction(10);
1041 return NF_STOLEN;
1042}
1043
Julius Volzb3cdd2a72008-09-02 15:55:45 +02001044#ifdef CONFIG_IP_VS_IPV6
1045int
1046ip_vs_dr_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
1047 struct ip_vs_protocol *pp)
1048{
1049 struct rt6_info *rt; /* Route to the other host */
1050 int mtu;
1051
1052 EnterFunction(10);
1053
Julian Anastasovfc604762010-10-17 16:38:15 +03001054 if (!(rt = __ip_vs_get_out_rt_v6(skb, cp->dest, &cp->daddr.in6, NULL,
1055 0, 1|2)))
Julius Volzb3cdd2a72008-09-02 15:55:45 +02001056 goto tx_error_icmp;
Julian Anastasovfc604762010-10-17 16:38:15 +03001057 if (__ip_vs_is_local_route6(rt)) {
1058 dst_release(&rt->dst);
1059 IP_VS_XMIT(NFPROTO_IPV6, skb, cp, 1);
1060 }
Julius Volzb3cdd2a72008-09-02 15:55:45 +02001061
1062 /* MTU checking */
Changli Gaod8d1f302010-06-10 23:31:35 -07001063 mtu = dst_mtu(&rt->dst);
Julius Volzb3cdd2a72008-09-02 15:55:45 +02001064 if (skb->len > mtu) {
Julian Anastasovcb591552010-10-17 16:40:51 +03001065 if (!skb->dev) {
1066 struct net *net = dev_net(skb_dst(skb)->dev);
1067
1068 skb->dev = net->loopback_dev;
1069 }
Alexey Dobriyan3ffe5332010-02-18 08:25:24 +00001070 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
Changli Gaod8d1f302010-06-10 23:31:35 -07001071 dst_release(&rt->dst);
Hannes Eder1e3e2382009-08-02 11:05:41 +00001072 IP_VS_DBG_RL("%s(): frag needed\n", __func__);
Julius Volzb3cdd2a72008-09-02 15:55:45 +02001073 goto tx_error;
1074 }
1075
1076 /*
1077 * Call ip_send_check because we are not sure it is called
1078 * after ip_defrag. Is copy-on-write needed?
1079 */
1080 skb = skb_share_check(skb, GFP_ATOMIC);
1081 if (unlikely(skb == NULL)) {
Changli Gaod8d1f302010-06-10 23:31:35 -07001082 dst_release(&rt->dst);
Julius Volzb3cdd2a72008-09-02 15:55:45 +02001083 return NF_STOLEN;
1084 }
1085
1086 /* drop old route */
Eric Dumazetadf30902009-06-02 05:19:30 +00001087 skb_dst_drop(skb);
Changli Gaod8d1f302010-06-10 23:31:35 -07001088 skb_dst_set(skb, &rt->dst);
Julius Volzb3cdd2a72008-09-02 15:55:45 +02001089
1090 /* Another hack: avoid icmp_send in ip_fragment */
1091 skb->local_df = 1;
1092
Julian Anastasovfc604762010-10-17 16:38:15 +03001093 IP_VS_XMIT(NFPROTO_IPV6, skb, cp, 0);
Julius Volzb3cdd2a72008-09-02 15:55:45 +02001094
1095 LeaveFunction(10);
1096 return NF_STOLEN;
1097
1098tx_error_icmp:
1099 dst_link_failure(skb);
1100tx_error:
1101 kfree_skb(skb);
1102 LeaveFunction(10);
1103 return NF_STOLEN;
1104}
1105#endif
1106
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107
1108/*
1109 * ICMP packet transmitter
1110 * called by the ip_vs_in_icmp
1111 */
1112int
1113ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
1114 struct ip_vs_protocol *pp, int offset)
1115{
1116 struct rtable *rt; /* Route to the other host */
1117 int mtu;
1118 int rc;
Julian Anastasovfc604762010-10-17 16:38:15 +03001119 int local;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120
1121 EnterFunction(10);
1122
1123 /* The ICMP packet for VS/TUN, VS/DR and LOCALNODE will be
1124 forwarded directly here, because there is no need to
1125 translate address/port back */
1126 if (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ) {
1127 if (cp->packet_xmit)
1128 rc = cp->packet_xmit(skb, cp, pp);
1129 else
1130 rc = NF_ACCEPT;
1131 /* do not touch skb anymore */
1132 atomic_inc(&cp->in_pkts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 goto out;
1134 }
1135
1136 /*
1137 * mangle and send the packet here (only for VS/NAT)
1138 */
1139
Julian Anastasovfc604762010-10-17 16:38:15 +03001140 if (!(rt = __ip_vs_get_out_rt(skb, cp->dest, cp->daddr.ip,
Changli Gao17a8f8e2011-02-24 08:19:57 +08001141 RT_TOS(ip_hdr(skb)->tos),
1142 IP_VS_RT_MODE_LOCAL |
1143 IP_VS_RT_MODE_NON_LOCAL |
1144 IP_VS_RT_MODE_RDR)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 goto tx_error_icmp;
Julian Anastasovfc604762010-10-17 16:38:15 +03001146 local = rt->rt_flags & RTCF_LOCAL;
1147
1148 /*
1149 * Avoid duplicate tuple in reply direction for NAT traffic
1150 * to local address when connection is sync-ed
1151 */
1152#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
1153 if (cp->flags & IP_VS_CONN_F_SYNC && local) {
1154 enum ip_conntrack_info ctinfo;
1155 struct nf_conn *ct = ct = nf_ct_get(skb, &ctinfo);
1156
1157 if (ct && !nf_ct_is_untracked(ct)) {
1158 IP_VS_DBG(10, "%s(): "
1159 "stopping DNAT to local address %pI4\n",
1160 __func__, &cp->daddr.ip);
1161 goto tx_error_put;
1162 }
1163 }
1164#endif
1165
1166 /* From world but DNAT to loopback address? */
David S. Millerc7537962010-11-11 17:07:48 -08001167 if (local && ipv4_is_loopback(rt->rt_dst) &&
1168 rt_is_input_route(skb_rtable(skb))) {
Julian Anastasovfc604762010-10-17 16:38:15 +03001169 IP_VS_DBG(1, "%s(): "
1170 "stopping DNAT to loopback %pI4\n",
1171 __func__, &cp->daddr.ip);
1172 goto tx_error_put;
1173 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174
1175 /* MTU checking */
Changli Gaod8d1f302010-06-10 23:31:35 -07001176 mtu = dst_mtu(&rt->dst);
Simon Horman8f1b03a2010-11-09 10:08:49 +09001177 if ((skb->len > mtu) && (ip_hdr(skb)->frag_off & htons(IP_DF)) &&
1178 !skb_is_gso(skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, htonl(mtu));
Hannes Eder1e3e2382009-08-02 11:05:41 +00001180 IP_VS_DBG_RL("%s(): frag needed\n", __func__);
Julian Anastasovfc604762010-10-17 16:38:15 +03001181 goto tx_error_put;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 }
1183
1184 /* copy-on-write the packet before mangling it */
Herbert Xuaf1e1cf2007-10-14 00:39:33 -07001185 if (!skb_make_writable(skb, offset))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 goto tx_error_put;
1187
Changli Gaod8d1f302010-06-10 23:31:35 -07001188 if (skb_cow(skb, rt->dst.dev->hard_header_len))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 goto tx_error_put;
1190
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 ip_vs_nat_icmp(skb, pp, cp, 0);
1192
Julian Anastasovfc604762010-10-17 16:38:15 +03001193 if (!local) {
1194 /* drop the old route when skb is not shared */
1195 skb_dst_drop(skb);
1196 skb_dst_set(skb, &rt->dst);
1197 } else {
1198 ip_rt_put(rt);
1199 /*
1200 * Some IPv4 replies get local address from routes,
1201 * not from iph, so while we DNAT after routing
1202 * we need this second input/output route.
1203 */
1204 if (!__ip_vs_reroute_locally(skb))
1205 goto tx_error;
1206 }
1207
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 /* Another hack: avoid icmp_send in ip_fragment */
1209 skb->local_df = 1;
1210
Julian Anastasovfc604762010-10-17 16:38:15 +03001211 IP_VS_XMIT_NAT(NFPROTO_IPV4, skb, cp, local);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212
1213 rc = NF_STOLEN;
1214 goto out;
1215
1216 tx_error_icmp:
1217 dst_link_failure(skb);
1218 tx_error:
1219 dev_kfree_skb(skb);
1220 rc = NF_STOLEN;
1221 out:
1222 LeaveFunction(10);
1223 return rc;
1224 tx_error_put:
1225 ip_rt_put(rt);
1226 goto tx_error;
1227}
Julius Volzb3cdd2a72008-09-02 15:55:45 +02001228
1229#ifdef CONFIG_IP_VS_IPV6
1230int
1231ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
1232 struct ip_vs_protocol *pp, int offset)
1233{
1234 struct rt6_info *rt; /* Route to the other host */
1235 int mtu;
1236 int rc;
Julian Anastasovfc604762010-10-17 16:38:15 +03001237 int local;
Julius Volzb3cdd2a72008-09-02 15:55:45 +02001238
1239 EnterFunction(10);
1240
1241 /* The ICMP packet for VS/TUN, VS/DR and LOCALNODE will be
1242 forwarded directly here, because there is no need to
1243 translate address/port back */
1244 if (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ) {
1245 if (cp->packet_xmit)
1246 rc = cp->packet_xmit(skb, cp, pp);
1247 else
1248 rc = NF_ACCEPT;
1249 /* do not touch skb anymore */
1250 atomic_inc(&cp->in_pkts);
1251 goto out;
1252 }
1253
1254 /*
1255 * mangle and send the packet here (only for VS/NAT)
1256 */
1257
Julian Anastasovfc604762010-10-17 16:38:15 +03001258 if (!(rt = __ip_vs_get_out_rt_v6(skb, cp->dest, &cp->daddr.in6, NULL,
1259 0, 1|2|4)))
Julius Volzb3cdd2a72008-09-02 15:55:45 +02001260 goto tx_error_icmp;
1261
Julian Anastasovfc604762010-10-17 16:38:15 +03001262 local = __ip_vs_is_local_route6(rt);
1263 /*
1264 * Avoid duplicate tuple in reply direction for NAT traffic
1265 * to local address when connection is sync-ed
1266 */
1267#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
1268 if (cp->flags & IP_VS_CONN_F_SYNC && local) {
1269 enum ip_conntrack_info ctinfo;
1270 struct nf_conn *ct = ct = nf_ct_get(skb, &ctinfo);
1271
1272 if (ct && !nf_ct_is_untracked(ct)) {
1273 IP_VS_DBG(10, "%s(): "
1274 "stopping DNAT to local address %pI6\n",
1275 __func__, &cp->daddr.in6);
1276 goto tx_error_put;
1277 }
1278 }
1279#endif
1280
1281 /* From world but DNAT to loopback address? */
1282 if (local && skb->dev && !(skb->dev->flags & IFF_LOOPBACK) &&
1283 ipv6_addr_type(&rt->rt6i_dst.addr) & IPV6_ADDR_LOOPBACK) {
1284 IP_VS_DBG(1, "%s(): "
1285 "stopping DNAT to loopback %pI6\n",
1286 __func__, &cp->daddr.in6);
1287 goto tx_error_put;
1288 }
1289
Julius Volzb3cdd2a72008-09-02 15:55:45 +02001290 /* MTU checking */
Changli Gaod8d1f302010-06-10 23:31:35 -07001291 mtu = dst_mtu(&rt->dst);
Simon Horman8f1b03a2010-11-09 10:08:49 +09001292 if (skb->len > mtu && !skb_is_gso(skb)) {
Julian Anastasovcb591552010-10-17 16:40:51 +03001293 if (!skb->dev) {
1294 struct net *net = dev_net(skb_dst(skb)->dev);
1295
1296 skb->dev = net->loopback_dev;
1297 }
Alexey Dobriyan3ffe5332010-02-18 08:25:24 +00001298 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
Hannes Eder1e3e2382009-08-02 11:05:41 +00001299 IP_VS_DBG_RL("%s(): frag needed\n", __func__);
Julian Anastasovfc604762010-10-17 16:38:15 +03001300 goto tx_error_put;
Julius Volzb3cdd2a72008-09-02 15:55:45 +02001301 }
1302
1303 /* copy-on-write the packet before mangling it */
1304 if (!skb_make_writable(skb, offset))
1305 goto tx_error_put;
1306
Changli Gaod8d1f302010-06-10 23:31:35 -07001307 if (skb_cow(skb, rt->dst.dev->hard_header_len))
Julius Volzb3cdd2a72008-09-02 15:55:45 +02001308 goto tx_error_put;
1309
Julius Volzb3cdd2a72008-09-02 15:55:45 +02001310 ip_vs_nat_icmp_v6(skb, pp, cp, 0);
1311
Julian Anastasovfc604762010-10-17 16:38:15 +03001312 if (!local || !skb->dev) {
1313 /* drop the old route when skb is not shared */
1314 skb_dst_drop(skb);
1315 skb_dst_set(skb, &rt->dst);
1316 } else {
1317 /* destined to loopback, do we need to change route? */
1318 dst_release(&rt->dst);
1319 }
1320
Julius Volzb3cdd2a72008-09-02 15:55:45 +02001321 /* Another hack: avoid icmp_send in ip_fragment */
1322 skb->local_df = 1;
1323
Julian Anastasovfc604762010-10-17 16:38:15 +03001324 IP_VS_XMIT_NAT(NFPROTO_IPV6, skb, cp, local);
Julius Volzb3cdd2a72008-09-02 15:55:45 +02001325
1326 rc = NF_STOLEN;
1327 goto out;
1328
1329tx_error_icmp:
1330 dst_link_failure(skb);
1331tx_error:
1332 dev_kfree_skb(skb);
1333 rc = NF_STOLEN;
1334out:
1335 LeaveFunction(10);
1336 return rc;
1337tx_error_put:
Changli Gaod8d1f302010-06-10 23:31:35 -07001338 dst_release(&rt->dst);
Julius Volzb3cdd2a72008-09-02 15:55:45 +02001339 goto tx_error;
1340}
1341#endif