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