Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ip_vs_xmit.c: various packet transmitters for IPVS |
| 3 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | * |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 14 | * Description of forwarding methods: |
| 15 | * - all transmitters are called from LOCAL_IN (remote clients) and |
| 16 | * LOCAL_OUT (local clients) but for ICMP can be called from FORWARD |
| 17 | * - not all connections have destination server, for example, |
| 18 | * connections in backup server when fwmark is used |
| 19 | * - bypass connections use daddr from packet |
| 20 | * LOCAL_OUT rules: |
| 21 | * - skb->dev is NULL, skb->protocol is not set (both are set in POST_ROUTING) |
| 22 | * - skb->pkt_type is not set yet |
| 23 | * - the only place where we can see skb->sk != NULL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | */ |
| 25 | |
Hannes Eder | 9aada7a | 2009-07-30 14:29:44 -0700 | [diff] [blame] | 26 | #define KMSG_COMPONENT "IPVS" |
| 27 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/kernel.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 30 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <linux/tcp.h> /* for tcphdr */ |
Herbert Xu | c439cb2 | 2008-01-11 19:14:00 -0800 | [diff] [blame] | 32 | #include <net/ip.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <net/tcp.h> /* for csum_tcpudp_magic */ |
| 34 | #include <net/udp.h> |
| 35 | #include <net/icmp.h> /* for icmp_send */ |
| 36 | #include <net/route.h> /* for ip_route_output */ |
Julius Volz | 38cdcc9 | 2008-09-02 15:55:44 +0200 | [diff] [blame] | 37 | #include <net/ipv6.h> |
| 38 | #include <net/ip6_route.h> |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 39 | #include <net/addrconf.h> |
Julius Volz | 38cdcc9 | 2008-09-02 15:55:44 +0200 | [diff] [blame] | 40 | #include <linux/icmpv6.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include <linux/netfilter.h> |
| 42 | #include <linux/netfilter_ipv4.h> |
| 43 | |
| 44 | #include <net/ip_vs.h> |
| 45 | |
Changli Gao | 17a8f8e | 2011-02-24 08:19:57 +0800 | [diff] [blame^] | 46 | enum { |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
| 54 | /* |
| 55 | * Destination cache to speed up outgoing route lookup |
| 56 | */ |
| 57 | static inline void |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 58 | __ip_vs_dst_set(struct ip_vs_dest *dest, u32 rtos, struct dst_entry *dst, |
| 59 | u32 dst_cookie) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | { |
| 61 | struct dst_entry *old_dst; |
| 62 | |
| 63 | old_dst = dest->dst_cache; |
| 64 | dest->dst_cache = dst; |
| 65 | dest->dst_rtos = rtos; |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 66 | dest->dst_cookie = dst_cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | dst_release(old_dst); |
| 68 | } |
| 69 | |
| 70 | static inline struct dst_entry * |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 71 | __ip_vs_dst_check(struct ip_vs_dest *dest, u32 rtos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | { |
| 73 | struct dst_entry *dst = dest->dst_cache; |
| 74 | |
| 75 | if (!dst) |
| 76 | return NULL; |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 77 | if ((dst->obsolete || rtos != dest->dst_rtos) && |
| 78 | dst->ops->check(dst, dest->dst_cookie) == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | dest->dst_cache = NULL; |
| 80 | dst_release(dst); |
| 81 | return NULL; |
| 82 | } |
| 83 | dst_hold(dst); |
| 84 | return dst; |
| 85 | } |
| 86 | |
Changli Gao | 17a8f8e | 2011-02-24 08:19:57 +0800 | [diff] [blame^] | 87 | /* Get route to destination or remote server */ |
Ilpo Järvinen | ad1b30b | 2008-01-05 23:12:40 -0800 | [diff] [blame] | 88 | static struct rtable * |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 89 | __ip_vs_get_out_rt(struct sk_buff *skb, struct ip_vs_dest *dest, |
| 90 | __be32 daddr, u32 rtos, int rt_mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | { |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 92 | struct net *net = dev_net(skb_dst(skb)->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | struct rtable *rt; /* Route to the other host */ |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 94 | struct rtable *ort; /* Original route */ |
| 95 | int local; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
| 97 | if (dest) { |
| 98 | spin_lock(&dest->dst_lock); |
| 99 | if (!(rt = (struct rtable *) |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 100 | __ip_vs_dst_check(dest, rtos))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | struct flowi fl = { |
Changli Gao | 5811662 | 2010-11-12 18:43:55 +0000 | [diff] [blame] | 102 | .fl4_dst = dest->addr.ip, |
| 103 | .fl4_tos = rtos, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | }; |
| 105 | |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 106 | if (ip_route_output_key(net, &rt, &fl)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | spin_unlock(&dest->dst_lock); |
Harvey Harrison | 14d5e83 | 2008-10-31 00:54:29 -0700 | [diff] [blame] | 108 | IP_VS_DBG_RL("ip_route_output error, dest: %pI4\n", |
| 109 | &dest->addr.ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | return NULL; |
| 111 | } |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 112 | __ip_vs_dst_set(dest, rtos, dst_clone(&rt->dst), 0); |
Harvey Harrison | 14d5e83 | 2008-10-31 00:54:29 -0700 | [diff] [blame] | 113 | IP_VS_DBG(10, "new dst %pI4, refcnt=%d, rtos=%X\n", |
| 114 | &dest->addr.ip, |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 115 | atomic_read(&rt->dst.__refcnt), rtos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | } |
| 117 | spin_unlock(&dest->dst_lock); |
| 118 | } else { |
| 119 | struct flowi fl = { |
Changli Gao | 5811662 | 2010-11-12 18:43:55 +0000 | [diff] [blame] | 120 | .fl4_dst = daddr, |
| 121 | .fl4_tos = rtos, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | }; |
| 123 | |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 124 | if (ip_route_output_key(net, &rt, &fl)) { |
Harvey Harrison | 14d5e83 | 2008-10-31 00:54:29 -0700 | [diff] [blame] | 125 | IP_VS_DBG_RL("ip_route_output error, dest: %pI4\n", |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 126 | &daddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | return NULL; |
| 128 | } |
| 129 | } |
| 130 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 131 | local = rt->rt_flags & RTCF_LOCAL; |
Changli Gao | 17a8f8e | 2011-02-24 08:19:57 +0800 | [diff] [blame^] | 132 | if (!((local ? IP_VS_RT_MODE_LOCAL : IP_VS_RT_MODE_NON_LOCAL) & |
| 133 | rt_mode)) { |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 134 | 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 Gao | 17a8f8e | 2011-02-24 08:19:57 +0800 | [diff] [blame^] | 140 | if (local && !(rt_mode & IP_VS_RT_MODE_RDR) && |
| 141 | !((ort = skb_rtable(skb)) && ort->rt_flags & RTCF_LOCAL)) { |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 142 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | return rt; |
| 157 | } |
| 158 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 159 | /* Reroute packet to local IPv4 stack after DNAT */ |
| 160 | static 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. Miller | c753796 | 2010-11-11 17:07:48 -0800 | [diff] [blame] | 168 | if (rt_is_input_route(rt)) { |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 169 | 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 Gao | 5811662 | 2010-11-12 18:43:55 +0000 | [diff] [blame] | 177 | .fl4_dst = iph->daddr, |
| 178 | .fl4_src = iph->saddr, |
| 179 | .fl4_tos = RT_TOS(iph->tos), |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 180 | .mark = skb->mark, |
| 181 | }; |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 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 | |
Julius Volz | 38cdcc9 | 2008-09-02 15:55:44 +0200 | [diff] [blame] | 196 | #ifdef CONFIG_IP_VS_IPV6 |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 197 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 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 | |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 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) |
Julius Volz | 38cdcc9 | 2008-09-02 15:55:44 +0200 | [diff] [blame] | 206 | { |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 207 | struct dst_entry *dst; |
| 208 | struct flowi fl = { |
Changli Gao | 5811662 | 2010-11-12 18:43:55 +0000 | [diff] [blame] | 209 | .fl6_dst = *daddr, |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 210 | }; |
| 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 | |
| 226 | out_err: |
| 227 | dst_release(dst); |
| 228 | IP_VS_DBG_RL("ip6_route_output error, dest: %pI6\n", daddr); |
| 229 | return NULL; |
| 230 | } |
| 231 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 232 | /* |
| 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 Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 237 | static struct rt6_info * |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 238 | __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 Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 241 | { |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 242 | struct net *net = dev_net(skb_dst(skb)->dev); |
Julius Volz | 38cdcc9 | 2008-09-02 15:55:44 +0200 | [diff] [blame] | 243 | struct rt6_info *rt; /* Route to the other host */ |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 244 | struct rt6_info *ort; /* Original route */ |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 245 | struct dst_entry *dst; |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 246 | int local; |
Julius Volz | 38cdcc9 | 2008-09-02 15:55:44 +0200 | [diff] [blame] | 247 | |
| 248 | if (dest) { |
| 249 | spin_lock(&dest->dst_lock); |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 250 | rt = (struct rt6_info *)__ip_vs_dst_check(dest, 0); |
Julius Volz | 38cdcc9 | 2008-09-02 15:55:44 +0200 | [diff] [blame] | 251 | if (!rt) { |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 252 | u32 cookie; |
Julius Volz | 38cdcc9 | 2008-09-02 15:55:44 +0200 | [diff] [blame] | 253 | |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 254 | dst = __ip_vs_route_output_v6(net, &dest->addr.in6, |
| 255 | &dest->dst_saddr, |
| 256 | do_xfrm); |
| 257 | if (!dst) { |
Julius Volz | 38cdcc9 | 2008-09-02 15:55:44 +0200 | [diff] [blame] | 258 | spin_unlock(&dest->dst_lock); |
Julius Volz | 38cdcc9 | 2008-09-02 15:55:44 +0200 | [diff] [blame] | 259 | return NULL; |
| 260 | } |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 261 | 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 Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 266 | atomic_read(&rt->dst.__refcnt)); |
Julius Volz | 38cdcc9 | 2008-09-02 15:55:44 +0200 | [diff] [blame] | 267 | } |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 268 | if (ret_saddr) |
| 269 | ipv6_addr_copy(ret_saddr, &dest->dst_saddr); |
Julius Volz | 38cdcc9 | 2008-09-02 15:55:44 +0200 | [diff] [blame] | 270 | spin_unlock(&dest->dst_lock); |
| 271 | } else { |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 272 | dst = __ip_vs_route_output_v6(net, daddr, ret_saddr, do_xfrm); |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 273 | if (!dst) |
Julius Volz | 38cdcc9 | 2008-09-02 15:55:44 +0200 | [diff] [blame] | 274 | return NULL; |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 275 | rt = (struct rt6_info *) dst; |
Julius Volz | 38cdcc9 | 2008-09-02 15:55:44 +0200 | [diff] [blame] | 276 | } |
| 277 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 278 | 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 Volz | 38cdcc9 | 2008-09-02 15:55:44 +0200 | [diff] [blame] | 304 | return rt; |
| 305 | } |
| 306 | #endif |
| 307 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
| 309 | /* |
| 310 | * Release dest->dst_cache before a dest is removed |
| 311 | */ |
| 312 | void |
| 313 | ip_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 Anastasov | f4bc17c | 2010-09-21 17:35:41 +0200 | [diff] [blame] | 322 | #define IP_VS_XMIT_TUNNEL(skb, cp) \ |
| 323 | ({ \ |
| 324 | int __ret = NF_ACCEPT; \ |
| 325 | \ |
Julian Anastasov | cf356d6 | 2010-10-17 16:21:07 +0300 | [diff] [blame] | 326 | (skb)->ipvs_property = 1; \ |
Julian Anastasov | f4bc17c | 2010-09-21 17:35:41 +0200 | [diff] [blame] | 327 | 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 Anastasov | 4256f1a | 2010-10-17 16:29:40 +0300 | [diff] [blame] | 331 | skb_forward_csum(skb); \ |
Julian Anastasov | f4bc17c | 2010-09-21 17:35:41 +0200 | [diff] [blame] | 332 | } \ |
| 333 | __ret; \ |
| 334 | }) |
| 335 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 336 | #define IP_VS_XMIT_NAT(pf, skb, cp, local) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | do { \ |
Julian Anastasov | cf356d6 | 2010-10-17 16:21:07 +0300 | [diff] [blame] | 338 | (skb)->ipvs_property = 1; \ |
Julian Anastasov | f4bc17c | 2010-09-21 17:35:41 +0200 | [diff] [blame] | 339 | if (likely(!((cp)->flags & IP_VS_CONN_F_NFCT))) \ |
Julian Anastasov | cf356d6 | 2010-10-17 16:21:07 +0300 | [diff] [blame] | 340 | ip_vs_notrack(skb); \ |
Julian Anastasov | f4bc17c | 2010-09-21 17:35:41 +0200 | [diff] [blame] | 341 | else \ |
| 342 | ip_vs_update_conntrack(skb, cp, 1); \ |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 343 | if (local) \ |
| 344 | return NF_ACCEPT; \ |
Herbert Xu | ccc7911 | 2007-07-30 16:20:12 -0700 | [diff] [blame] | 345 | skb_forward_csum(skb); \ |
Julius Volz | 38cdcc9 | 2008-09-02 15:55:44 +0200 | [diff] [blame] | 346 | NF_HOOK(pf, NF_INET_LOCAL_OUT, (skb), NULL, \ |
Julian Anastasov | f4bc17c | 2010-09-21 17:35:41 +0200 | [diff] [blame] | 347 | skb_dst(skb)->dev, dst_output); \ |
| 348 | } while (0) |
| 349 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 350 | #define IP_VS_XMIT(pf, skb, cp, local) \ |
Julian Anastasov | f4bc17c | 2010-09-21 17:35:41 +0200 | [diff] [blame] | 351 | do { \ |
Julian Anastasov | cf356d6 | 2010-10-17 16:21:07 +0300 | [diff] [blame] | 352 | (skb)->ipvs_property = 1; \ |
Julian Anastasov | f4bc17c | 2010-09-21 17:35:41 +0200 | [diff] [blame] | 353 | if (likely(!((cp)->flags & IP_VS_CONN_F_NFCT))) \ |
Julian Anastasov | cf356d6 | 2010-10-17 16:21:07 +0300 | [diff] [blame] | 354 | ip_vs_notrack(skb); \ |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 355 | if (local) \ |
| 356 | return NF_ACCEPT; \ |
Julian Anastasov | f4bc17c | 2010-09-21 17:35:41 +0200 | [diff] [blame] | 357 | skb_forward_csum(skb); \ |
| 358 | NF_HOOK(pf, NF_INET_LOCAL_OUT, (skb), NULL, \ |
| 359 | skb_dst(skb)->dev, dst_output); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | } while (0) |
| 361 | |
| 362 | |
| 363 | /* |
| 364 | * NULL transmitter (do nothing except return NF_ACCEPT) |
| 365 | */ |
| 366 | int |
| 367 | ip_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 Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 371 | IP_VS_XMIT(NFPROTO_IPV4, skb, cp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | } |
| 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 | */ |
| 380 | int |
| 381 | ip_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 Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 385 | struct iphdr *iph = ip_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | int mtu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | |
| 388 | EnterFunction(10); |
| 389 | |
Changli Gao | 17a8f8e | 2011-02-24 08:19:57 +0800 | [diff] [blame^] | 390 | if (!(rt = __ip_vs_get_out_rt(skb, NULL, iph->daddr, RT_TOS(iph->tos), |
| 391 | IP_VS_RT_MODE_NON_LOCAL))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | goto tx_error_icmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | |
| 394 | /* MTU checking */ |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 395 | mtu = dst_mtu(&rt->dst); |
Simon Horman | 8f1b03a | 2010-11-09 10:08:49 +0900 | [diff] [blame] | 396 | if ((skb->len > mtu) && (iph->frag_off & htons(IP_DF)) && |
| 397 | !skb_is_gso(skb)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | ip_rt_put(rt); |
| 399 | icmp_send(skb, ICMP_DEST_UNREACH,ICMP_FRAG_NEEDED, htonl(mtu)); |
Hannes Eder | 1e3e238 | 2009-08-02 11:05:41 +0000 | [diff] [blame] | 400 | IP_VS_DBG_RL("%s(): frag needed\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | 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 Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 412 | ip_send_check(ip_hdr(skb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | |
| 414 | /* drop old route */ |
Eric Dumazet | adf3090 | 2009-06-02 05:19:30 +0000 | [diff] [blame] | 415 | skb_dst_drop(skb); |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 416 | skb_dst_set(skb, &rt->dst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | |
| 418 | /* Another hack: avoid icmp_send in ip_fragment */ |
| 419 | skb->local_df = 1; |
| 420 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 421 | IP_VS_XMIT(NFPROTO_IPV4, skb, cp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | |
| 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 Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 434 | #ifdef CONFIG_IP_VS_IPV6 |
| 435 | int |
| 436 | ip_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 Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 442 | |
| 443 | EnterFunction(10); |
| 444 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 445 | if (!(rt = __ip_vs_get_out_rt_v6(skb, NULL, &iph->daddr, NULL, 0, 2))) |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 446 | goto tx_error_icmp; |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 447 | |
| 448 | /* MTU checking */ |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 449 | mtu = dst_mtu(&rt->dst); |
Simon Horman | 8f1b03a | 2010-11-09 10:08:49 +0900 | [diff] [blame] | 450 | if (skb->len > mtu && !skb_is_gso(skb)) { |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 451 | if (!skb->dev) { |
| 452 | struct net *net = dev_net(skb_dst(skb)->dev); |
| 453 | |
| 454 | skb->dev = net->loopback_dev; |
| 455 | } |
Alexey Dobriyan | 3ffe533 | 2010-02-18 08:25:24 +0000 | [diff] [blame] | 456 | icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu); |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 457 | dst_release(&rt->dst); |
Hannes Eder | 1e3e238 | 2009-08-02 11:05:41 +0000 | [diff] [blame] | 458 | IP_VS_DBG_RL("%s(): frag needed\n", __func__); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 459 | 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 Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 468 | dst_release(&rt->dst); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 469 | return NF_STOLEN; |
| 470 | } |
| 471 | |
| 472 | /* drop old route */ |
Eric Dumazet | adf3090 | 2009-06-02 05:19:30 +0000 | [diff] [blame] | 473 | skb_dst_drop(skb); |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 474 | skb_dst_set(skb, &rt->dst); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 475 | |
| 476 | /* Another hack: avoid icmp_send in ip_fragment */ |
| 477 | skb->local_df = 1; |
| 478 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 479 | IP_VS_XMIT(NFPROTO_IPV6, skb, cp, 0); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 480 | |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | |
| 493 | /* |
| 494 | * NAT transmitter (only for outside-to-inside nat forwarding) |
| 495 | * Not used for related ICMP |
| 496 | */ |
| 497 | int |
| 498 | ip_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 Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 503 | struct iphdr *iph = ip_hdr(skb); |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 504 | int local; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | |
| 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 Viro | 014d730 | 2006-09-28 14:29:52 -0700 | [diff] [blame] | 510 | __be16 _pt, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | 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 Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 518 | if (!(rt = __ip_vs_get_out_rt(skb, cp->dest, cp->daddr.ip, |
Changli Gao | 17a8f8e | 2011-02-24 08:19:57 +0800 | [diff] [blame^] | 519 | RT_TOS(iph->tos), |
| 520 | IP_VS_RT_MODE_LOCAL | |
| 521 | IP_VS_RT_MODE_NON_LOCAL | |
| 522 | IP_VS_RT_MODE_RDR))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | goto tx_error_icmp; |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 524 | 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 Anastasov | 0d79641 | 2010-10-17 16:46:17 +0300 | [diff] [blame] | 535 | IP_VS_DBG_RL_PKT(10, AF_INET, pp, skb, 0, |
| 536 | "ip_vs_nat_xmit(): " |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 537 | "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. Miller | c753796 | 2010-11-11 17:07:48 -0800 | [diff] [blame] | 544 | if (local && ipv4_is_loopback(rt->rt_dst) && |
| 545 | rt_is_input_route(skb_rtable(skb))) { |
Julian Anastasov | 0d79641 | 2010-10-17 16:46:17 +0300 | [diff] [blame] | 546 | IP_VS_DBG_RL_PKT(1, AF_INET, pp, skb, 0, "ip_vs_nat_xmit(): " |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 547 | "stopping DNAT to loopback address"); |
| 548 | goto tx_error_put; |
| 549 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | |
| 551 | /* MTU checking */ |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 552 | mtu = dst_mtu(&rt->dst); |
Simon Horman | 8f1b03a | 2010-11-09 10:08:49 +0900 | [diff] [blame] | 553 | if ((skb->len > mtu) && (iph->frag_off & htons(IP_DF)) && |
| 554 | !skb_is_gso(skb)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | icmp_send(skb, ICMP_DEST_UNREACH,ICMP_FRAG_NEEDED, htonl(mtu)); |
Julian Anastasov | 0d79641 | 2010-10-17 16:46:17 +0300 | [diff] [blame] | 556 | IP_VS_DBG_RL_PKT(0, AF_INET, pp, skb, 0, |
| 557 | "ip_vs_nat_xmit(): frag needed for"); |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 558 | goto tx_error_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | /* copy-on-write the packet before mangling it */ |
Herbert Xu | af1e1cf | 2007-10-14 00:39:33 -0700 | [diff] [blame] | 562 | if (!skb_make_writable(skb, sizeof(struct iphdr))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | goto tx_error_put; |
| 564 | |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 565 | if (skb_cow(skb, rt->dst.dev->hard_header_len)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | goto tx_error_put; |
| 567 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | /* mangle the packet */ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 569 | if (pp->dnat_handler && !pp->dnat_handler(skb, pp, cp)) |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 570 | goto tx_error_put; |
Julius Volz | e7ade46 | 2008-09-02 15:55:33 +0200 | [diff] [blame] | 571 | ip_hdr(skb)->daddr = cp->daddr.ip; |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 572 | ip_send_check(ip_hdr(skb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 574 | 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 Anastasov | 0d79641 | 2010-10-17 16:46:17 +0300 | [diff] [blame] | 589 | IP_VS_DBG_PKT(10, AF_INET, pp, skb, 0, "After DNAT"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | |
| 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 Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 598 | IP_VS_XMIT_NAT(NFPROTO_IPV4, skb, cp, local); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | |
| 600 | LeaveFunction(10); |
| 601 | return NF_STOLEN; |
| 602 | |
| 603 | tx_error_icmp: |
| 604 | dst_link_failure(skb); |
| 605 | tx_error: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | kfree_skb(skb); |
Julian Anastasov | f4bc17c | 2010-09-21 17:35:41 +0200 | [diff] [blame] | 607 | LeaveFunction(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | return NF_STOLEN; |
| 609 | tx_error_put: |
| 610 | ip_rt_put(rt); |
| 611 | goto tx_error; |
| 612 | } |
| 613 | |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 614 | #ifdef CONFIG_IP_VS_IPV6 |
| 615 | int |
| 616 | ip_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 Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 621 | int local; |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 622 | |
| 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 Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 636 | if (!(rt = __ip_vs_get_out_rt_v6(skb, cp->dest, &cp->daddr.in6, NULL, |
| 637 | 0, 1|2|4))) |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 638 | goto tx_error_icmp; |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 639 | 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 Anastasov | 0d79641 | 2010-10-17 16:46:17 +0300 | [diff] [blame] | 650 | IP_VS_DBG_RL_PKT(10, AF_INET6, pp, skb, 0, |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 651 | "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 Anastasov | 0d79641 | 2010-10-17 16:46:17 +0300 | [diff] [blame] | 661 | IP_VS_DBG_RL_PKT(1, AF_INET6, pp, skb, 0, |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 662 | "ip_vs_nat_xmit_v6(): " |
| 663 | "stopping DNAT to loopback address"); |
| 664 | goto tx_error_put; |
| 665 | } |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 666 | |
| 667 | /* MTU checking */ |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 668 | mtu = dst_mtu(&rt->dst); |
Simon Horman | 8f1b03a | 2010-11-09 10:08:49 +0900 | [diff] [blame] | 669 | if (skb->len > mtu && !skb_is_gso(skb)) { |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 670 | if (!skb->dev) { |
| 671 | struct net *net = dev_net(skb_dst(skb)->dev); |
| 672 | |
| 673 | skb->dev = net->loopback_dev; |
| 674 | } |
Alexey Dobriyan | 3ffe533 | 2010-02-18 08:25:24 +0000 | [diff] [blame] | 675 | icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu); |
Julian Anastasov | 0d79641 | 2010-10-17 16:46:17 +0300 | [diff] [blame] | 676 | IP_VS_DBG_RL_PKT(0, AF_INET6, pp, skb, 0, |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 677 | "ip_vs_nat_xmit_v6(): frag needed for"); |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 678 | goto tx_error_put; |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 679 | } |
| 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 Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 685 | if (skb_cow(skb, rt->dst.dev->hard_header_len)) |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 686 | goto tx_error_put; |
| 687 | |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 688 | /* mangle the packet */ |
| 689 | if (pp->dnat_handler && !pp->dnat_handler(skb, pp, cp)) |
| 690 | goto tx_error; |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 691 | 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 Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 701 | |
Julian Anastasov | 0d79641 | 2010-10-17 16:46:17 +0300 | [diff] [blame] | 702 | IP_VS_DBG_PKT(10, AF_INET6, pp, skb, 0, "After DNAT"); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 703 | |
| 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 Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 711 | IP_VS_XMIT_NAT(NFPROTO_IPV6, skb, cp, local); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 712 | |
| 713 | LeaveFunction(10); |
| 714 | return NF_STOLEN; |
| 715 | |
| 716 | tx_error_icmp: |
| 717 | dst_link_failure(skb); |
| 718 | tx_error: |
| 719 | LeaveFunction(10); |
| 720 | kfree_skb(skb); |
| 721 | return NF_STOLEN; |
| 722 | tx_error_put: |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 723 | dst_release(&rt->dst); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 724 | goto tx_error; |
| 725 | } |
| 726 | #endif |
| 727 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | |
| 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 | */ |
| 748 | int |
| 749 | ip_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 Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 754 | struct iphdr *old_iph = ip_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | u8 tos = old_iph->tos; |
Alexey Dobriyan | 76ab608 | 2006-01-06 13:24:29 -0800 | [diff] [blame] | 756 | __be16 df = old_iph->frag_off; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | struct iphdr *iph; /* Our new IP header */ |
Chuck Lever | c2636b4 | 2007-10-23 21:07:32 -0700 | [diff] [blame] | 758 | unsigned int max_headroom; /* The extra header space needed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | int mtu; |
Julian Anastasov | f4bc17c | 2010-09-21 17:35:41 +0200 | [diff] [blame] | 760 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | |
| 762 | EnterFunction(10); |
| 763 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 764 | if (!(rt = __ip_vs_get_out_rt(skb, cp->dest, cp->daddr.ip, |
Changli Gao | 17a8f8e | 2011-02-24 08:19:57 +0800 | [diff] [blame^] | 765 | RT_TOS(tos), IP_VS_RT_MODE_LOCAL | |
| 766 | IP_VS_RT_MODE_NON_LOCAL))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | goto tx_error_icmp; |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 768 | if (rt->rt_flags & RTCF_LOCAL) { |
| 769 | ip_rt_put(rt); |
| 770 | IP_VS_XMIT(NFPROTO_IPV4, skb, cp, 1); |
| 771 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 773 | tdev = rt->dst.dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 775 | mtu = dst_mtu(&rt->dst) - sizeof(struct iphdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | if (mtu < 68) { |
Hannes Eder | 1e3e238 | 2009-08-02 11:05:41 +0000 | [diff] [blame] | 777 | IP_VS_DBG_RL("%s(): mtu less than 68\n", __func__); |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 778 | goto tx_error_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | } |
Eric Dumazet | adf3090 | 2009-06-02 05:19:30 +0000 | [diff] [blame] | 780 | if (skb_dst(skb)) |
| 781 | skb_dst(skb)->ops->update_pmtu(skb_dst(skb), mtu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | |
YOSHIFUJI Hideaki | 4412ec4 | 2007-03-07 14:19:10 +0900 | [diff] [blame] | 783 | df |= (old_iph->frag_off & htons(IP_DF)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | |
Simon Horman | 8f1b03a | 2010-11-09 10:08:49 +0900 | [diff] [blame] | 785 | if ((old_iph->frag_off & htons(IP_DF) && |
| 786 | mtu < ntohs(old_iph->tot_len) && !skb_is_gso(skb))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | icmp_send(skb, ICMP_DEST_UNREACH,ICMP_FRAG_NEEDED, htonl(mtu)); |
Hannes Eder | 1e3e238 | 2009-08-02 11:05:41 +0000 | [diff] [blame] | 788 | IP_VS_DBG_RL("%s(): frag needed\n", __func__); |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 789 | goto tx_error_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | } |
| 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 Eder | 1e3e238 | 2009-08-02 11:05:41 +0000 | [diff] [blame] | 804 | IP_VS_ERR_RL("%s(): no memory\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | return NF_STOLEN; |
| 806 | } |
| 807 | kfree_skb(skb); |
| 808 | skb = new_skb; |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 809 | old_iph = ip_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | } |
| 811 | |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 812 | skb->transport_header = skb->network_header; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | |
| 814 | /* fix old IP header checksum */ |
| 815 | ip_send_check(old_iph); |
| 816 | |
Arnaldo Carvalho de Melo | e2d1bca | 2007-04-10 20:46:21 -0700 | [diff] [blame] | 817 | skb_push(skb, sizeof(struct iphdr)); |
| 818 | skb_reset_network_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt)); |
| 820 | |
| 821 | /* drop old route */ |
Eric Dumazet | adf3090 | 2009-06-02 05:19:30 +0000 | [diff] [blame] | 822 | skb_dst_drop(skb); |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 823 | skb_dst_set(skb, &rt->dst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | |
| 825 | /* |
| 826 | * Push down and install the IPIP header. |
| 827 | */ |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 828 | iph = ip_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | 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 Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 837 | ip_select_ident(iph, &rt->dst, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | |
| 839 | /* Another hack: avoid icmp_send in ip_fragment */ |
| 840 | skb->local_df = 1; |
| 841 | |
Julian Anastasov | f4bc17c | 2010-09-21 17:35:41 +0200 | [diff] [blame] | 842 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | |
| 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 Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 858 | tx_error_put: |
| 859 | ip_rt_put(rt); |
| 860 | goto tx_error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | } |
| 862 | |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 863 | #ifdef CONFIG_IP_VS_IPV6 |
| 864 | int |
| 865 | ip_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 Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 869 | struct in6_addr saddr; /* Source for tunnel */ |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 870 | struct net_device *tdev; /* Device to other host */ |
| 871 | struct ipv6hdr *old_iph = ipv6_hdr(skb); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 872 | struct ipv6hdr *iph; /* Our new IP header */ |
| 873 | unsigned int max_headroom; /* The extra header space needed */ |
| 874 | int mtu; |
Julian Anastasov | f4bc17c | 2010-09-21 17:35:41 +0200 | [diff] [blame] | 875 | int ret; |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 876 | |
| 877 | EnterFunction(10); |
| 878 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 879 | if (!(rt = __ip_vs_get_out_rt_v6(skb, cp->dest, &cp->daddr.in6, |
| 880 | &saddr, 1, 1|2))) |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 881 | goto tx_error_icmp; |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 882 | if (__ip_vs_is_local_route6(rt)) { |
| 883 | dst_release(&rt->dst); |
| 884 | IP_VS_XMIT(NFPROTO_IPV6, skb, cp, 1); |
| 885 | } |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 886 | |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 887 | tdev = rt->dst.dev; |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 888 | |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 889 | mtu = dst_mtu(&rt->dst) - sizeof(struct ipv6hdr); |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 890 | if (mtu < IPV6_MIN_MTU) { |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 891 | IP_VS_DBG_RL("%s(): mtu less than %d\n", __func__, |
| 892 | IPV6_MIN_MTU); |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 893 | goto tx_error_put; |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 894 | } |
Eric Dumazet | adf3090 | 2009-06-02 05:19:30 +0000 | [diff] [blame] | 895 | if (skb_dst(skb)) |
| 896 | skb_dst(skb)->ops->update_pmtu(skb_dst(skb), mtu); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 897 | |
Simon Horman | 8f1b03a | 2010-11-09 10:08:49 +0900 | [diff] [blame] | 898 | if (mtu < ntohs(old_iph->payload_len) + sizeof(struct ipv6hdr) && |
| 899 | !skb_is_gso(skb)) { |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 900 | if (!skb->dev) { |
| 901 | struct net *net = dev_net(skb_dst(skb)->dev); |
| 902 | |
| 903 | skb->dev = net->loopback_dev; |
| 904 | } |
Alexey Dobriyan | 3ffe533 | 2010-02-18 08:25:24 +0000 | [diff] [blame] | 905 | icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu); |
Hannes Eder | 1e3e238 | 2009-08-02 11:05:41 +0000 | [diff] [blame] | 906 | IP_VS_DBG_RL("%s(): frag needed\n", __func__); |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 907 | goto tx_error_put; |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 908 | } |
| 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 Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 920 | dst_release(&rt->dst); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 921 | kfree_skb(skb); |
Hannes Eder | 1e3e238 | 2009-08-02 11:05:41 +0000 | [diff] [blame] | 922 | IP_VS_ERR_RL("%s(): no memory\n", __func__); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 923 | return NF_STOLEN; |
| 924 | } |
| 925 | kfree_skb(skb); |
| 926 | skb = new_skb; |
| 927 | old_iph = ipv6_hdr(skb); |
| 928 | } |
| 929 | |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 930 | skb->transport_header = skb->network_header; |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 931 | |
| 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 Dumazet | adf3090 | 2009-06-02 05:19:30 +0000 | [diff] [blame] | 937 | skb_dst_drop(skb); |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 938 | skb_dst_set(skb, &rt->dst); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 939 | |
| 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 Harrison | b7b45f4 | 2008-11-10 16:46:06 -0800 | [diff] [blame] | 946 | iph->payload_len = old_iph->payload_len; |
| 947 | be16_add_cpu(&iph->payload_len, sizeof(*old_iph)); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 948 | iph->priority = old_iph->priority; |
| 949 | memset(&iph->flow_lbl, 0, sizeof(iph->flow_lbl)); |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 950 | ipv6_addr_copy(&iph->daddr, &cp->daddr.in6); |
| 951 | ipv6_addr_copy(&iph->saddr, &saddr); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 952 | iph->hop_limit = old_iph->hop_limit; |
| 953 | |
| 954 | /* Another hack: avoid icmp_send in ip_fragment */ |
| 955 | skb->local_df = 1; |
| 956 | |
Julian Anastasov | f4bc17c | 2010-09-21 17:35:41 +0200 | [diff] [blame] | 957 | 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 Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 962 | |
| 963 | LeaveFunction(10); |
| 964 | |
| 965 | return NF_STOLEN; |
| 966 | |
| 967 | tx_error_icmp: |
| 968 | dst_link_failure(skb); |
| 969 | tx_error: |
| 970 | kfree_skb(skb); |
| 971 | LeaveFunction(10); |
| 972 | return NF_STOLEN; |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 973 | tx_error_put: |
| 974 | dst_release(&rt->dst); |
| 975 | goto tx_error; |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 976 | } |
| 977 | #endif |
| 978 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | |
| 980 | /* |
| 981 | * Direct Routing transmitter |
| 982 | * Used for ANY protocol |
| 983 | */ |
| 984 | int |
| 985 | ip_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 Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 989 | struct iphdr *iph = ip_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | int mtu; |
| 991 | |
| 992 | EnterFunction(10); |
| 993 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 994 | if (!(rt = __ip_vs_get_out_rt(skb, cp->dest, cp->daddr.ip, |
Changli Gao | 17a8f8e | 2011-02-24 08:19:57 +0800 | [diff] [blame^] | 995 | RT_TOS(iph->tos), |
| 996 | IP_VS_RT_MODE_LOCAL | |
| 997 | IP_VS_RT_MODE_NON_LOCAL))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | goto tx_error_icmp; |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 999 | if (rt->rt_flags & RTCF_LOCAL) { |
| 1000 | ip_rt_put(rt); |
| 1001 | IP_VS_XMIT(NFPROTO_IPV4, skb, cp, 1); |
| 1002 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | |
| 1004 | /* MTU checking */ |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 1005 | mtu = dst_mtu(&rt->dst); |
Simon Horman | 8f1b03a | 2010-11-09 10:08:49 +0900 | [diff] [blame] | 1006 | if ((iph->frag_off & htons(IP_DF)) && skb->len > mtu && |
| 1007 | !skb_is_gso(skb)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | icmp_send(skb, ICMP_DEST_UNREACH,ICMP_FRAG_NEEDED, htonl(mtu)); |
| 1009 | ip_rt_put(rt); |
Hannes Eder | 1e3e238 | 2009-08-02 11:05:41 +0000 | [diff] [blame] | 1010 | IP_VS_DBG_RL("%s(): frag needed\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | 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 Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 1022 | ip_send_check(ip_hdr(skb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | |
| 1024 | /* drop old route */ |
Eric Dumazet | adf3090 | 2009-06-02 05:19:30 +0000 | [diff] [blame] | 1025 | skb_dst_drop(skb); |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 1026 | skb_dst_set(skb, &rt->dst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | |
| 1028 | /* Another hack: avoid icmp_send in ip_fragment */ |
| 1029 | skb->local_df = 1; |
| 1030 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1031 | IP_VS_XMIT(NFPROTO_IPV4, skb, cp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | |
| 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 Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 1044 | #ifdef CONFIG_IP_VS_IPV6 |
| 1045 | int |
| 1046 | ip_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 Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1054 | if (!(rt = __ip_vs_get_out_rt_v6(skb, cp->dest, &cp->daddr.in6, NULL, |
| 1055 | 0, 1|2))) |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 1056 | goto tx_error_icmp; |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1057 | if (__ip_vs_is_local_route6(rt)) { |
| 1058 | dst_release(&rt->dst); |
| 1059 | IP_VS_XMIT(NFPROTO_IPV6, skb, cp, 1); |
| 1060 | } |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 1061 | |
| 1062 | /* MTU checking */ |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 1063 | mtu = dst_mtu(&rt->dst); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 1064 | if (skb->len > mtu) { |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 1065 | if (!skb->dev) { |
| 1066 | struct net *net = dev_net(skb_dst(skb)->dev); |
| 1067 | |
| 1068 | skb->dev = net->loopback_dev; |
| 1069 | } |
Alexey Dobriyan | 3ffe533 | 2010-02-18 08:25:24 +0000 | [diff] [blame] | 1070 | icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu); |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 1071 | dst_release(&rt->dst); |
Hannes Eder | 1e3e238 | 2009-08-02 11:05:41 +0000 | [diff] [blame] | 1072 | IP_VS_DBG_RL("%s(): frag needed\n", __func__); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 1073 | 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 Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 1082 | dst_release(&rt->dst); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 1083 | return NF_STOLEN; |
| 1084 | } |
| 1085 | |
| 1086 | /* drop old route */ |
Eric Dumazet | adf3090 | 2009-06-02 05:19:30 +0000 | [diff] [blame] | 1087 | skb_dst_drop(skb); |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 1088 | skb_dst_set(skb, &rt->dst); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 1089 | |
| 1090 | /* Another hack: avoid icmp_send in ip_fragment */ |
| 1091 | skb->local_df = 1; |
| 1092 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1093 | IP_VS_XMIT(NFPROTO_IPV6, skb, cp, 0); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 1094 | |
| 1095 | LeaveFunction(10); |
| 1096 | return NF_STOLEN; |
| 1097 | |
| 1098 | tx_error_icmp: |
| 1099 | dst_link_failure(skb); |
| 1100 | tx_error: |
| 1101 | kfree_skb(skb); |
| 1102 | LeaveFunction(10); |
| 1103 | return NF_STOLEN; |
| 1104 | } |
| 1105 | #endif |
| 1106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | |
| 1108 | /* |
| 1109 | * ICMP packet transmitter |
| 1110 | * called by the ip_vs_in_icmp |
| 1111 | */ |
| 1112 | int |
| 1113 | ip_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 Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1119 | int local; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | goto out; |
| 1134 | } |
| 1135 | |
| 1136 | /* |
| 1137 | * mangle and send the packet here (only for VS/NAT) |
| 1138 | */ |
| 1139 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1140 | if (!(rt = __ip_vs_get_out_rt(skb, cp->dest, cp->daddr.ip, |
Changli Gao | 17a8f8e | 2011-02-24 08:19:57 +0800 | [diff] [blame^] | 1141 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | goto tx_error_icmp; |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1146 | 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. Miller | c753796 | 2010-11-11 17:07:48 -0800 | [diff] [blame] | 1167 | if (local && ipv4_is_loopback(rt->rt_dst) && |
| 1168 | rt_is_input_route(skb_rtable(skb))) { |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1169 | IP_VS_DBG(1, "%s(): " |
| 1170 | "stopping DNAT to loopback %pI4\n", |
| 1171 | __func__, &cp->daddr.ip); |
| 1172 | goto tx_error_put; |
| 1173 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | |
| 1175 | /* MTU checking */ |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 1176 | mtu = dst_mtu(&rt->dst); |
Simon Horman | 8f1b03a | 2010-11-09 10:08:49 +0900 | [diff] [blame] | 1177 | if ((skb->len > mtu) && (ip_hdr(skb)->frag_off & htons(IP_DF)) && |
| 1178 | !skb_is_gso(skb)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, htonl(mtu)); |
Hannes Eder | 1e3e238 | 2009-08-02 11:05:41 +0000 | [diff] [blame] | 1180 | IP_VS_DBG_RL("%s(): frag needed\n", __func__); |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1181 | goto tx_error_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | /* copy-on-write the packet before mangling it */ |
Herbert Xu | af1e1cf | 2007-10-14 00:39:33 -0700 | [diff] [blame] | 1185 | if (!skb_make_writable(skb, offset)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | goto tx_error_put; |
| 1187 | |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 1188 | if (skb_cow(skb, rt->dst.dev->hard_header_len)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | goto tx_error_put; |
| 1190 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | ip_vs_nat_icmp(skb, pp, cp, 0); |
| 1192 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1193 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | /* Another hack: avoid icmp_send in ip_fragment */ |
| 1209 | skb->local_df = 1; |
| 1210 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1211 | IP_VS_XMIT_NAT(NFPROTO_IPV4, skb, cp, local); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | |
| 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 Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 1228 | |
| 1229 | #ifdef CONFIG_IP_VS_IPV6 |
| 1230 | int |
| 1231 | ip_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 Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1237 | int local; |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 1238 | |
| 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 Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1258 | if (!(rt = __ip_vs_get_out_rt_v6(skb, cp->dest, &cp->daddr.in6, NULL, |
| 1259 | 0, 1|2|4))) |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 1260 | goto tx_error_icmp; |
| 1261 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1262 | 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 Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 1290 | /* MTU checking */ |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 1291 | mtu = dst_mtu(&rt->dst); |
Simon Horman | 8f1b03a | 2010-11-09 10:08:49 +0900 | [diff] [blame] | 1292 | if (skb->len > mtu && !skb_is_gso(skb)) { |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 1293 | if (!skb->dev) { |
| 1294 | struct net *net = dev_net(skb_dst(skb)->dev); |
| 1295 | |
| 1296 | skb->dev = net->loopback_dev; |
| 1297 | } |
Alexey Dobriyan | 3ffe533 | 2010-02-18 08:25:24 +0000 | [diff] [blame] | 1298 | icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu); |
Hannes Eder | 1e3e238 | 2009-08-02 11:05:41 +0000 | [diff] [blame] | 1299 | IP_VS_DBG_RL("%s(): frag needed\n", __func__); |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1300 | goto tx_error_put; |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 1301 | } |
| 1302 | |
| 1303 | /* copy-on-write the packet before mangling it */ |
| 1304 | if (!skb_make_writable(skb, offset)) |
| 1305 | goto tx_error_put; |
| 1306 | |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 1307 | if (skb_cow(skb, rt->dst.dev->hard_header_len)) |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 1308 | goto tx_error_put; |
| 1309 | |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 1310 | ip_vs_nat_icmp_v6(skb, pp, cp, 0); |
| 1311 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1312 | 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 Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 1321 | /* Another hack: avoid icmp_send in ip_fragment */ |
| 1322 | skb->local_df = 1; |
| 1323 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1324 | IP_VS_XMIT_NAT(NFPROTO_IPV6, skb, cp, local); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 1325 | |
| 1326 | rc = NF_STOLEN; |
| 1327 | goto out; |
| 1328 | |
| 1329 | tx_error_icmp: |
| 1330 | dst_link_failure(skb); |
| 1331 | tx_error: |
| 1332 | dev_kfree_skb(skb); |
| 1333 | rc = NF_STOLEN; |
| 1334 | out: |
| 1335 | LeaveFunction(10); |
| 1336 | return rc; |
| 1337 | tx_error_put: |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 1338 | dst_release(&rt->dst); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 1339 | goto tx_error; |
| 1340 | } |
| 1341 | #endif |