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))) { |
David S. Miller | 78fbfd8 | 2011-03-12 00:00:52 -0500 | [diff] [blame] | 101 | rt = ip_route_output(net, dest->addr.ip, 0, rtos, 0); |
David S. Miller | b23dd4f | 2011-03-02 14:31:35 -0800 | [diff] [blame] | 102 | if (IS_ERR(rt)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | spin_unlock(&dest->dst_lock); |
Harvey Harrison | 14d5e83 | 2008-10-31 00:54:29 -0700 | [diff] [blame] | 104 | IP_VS_DBG_RL("ip_route_output error, dest: %pI4\n", |
| 105 | &dest->addr.ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | return NULL; |
| 107 | } |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 108 | __ip_vs_dst_set(dest, rtos, dst_clone(&rt->dst), 0); |
Harvey Harrison | 14d5e83 | 2008-10-31 00:54:29 -0700 | [diff] [blame] | 109 | IP_VS_DBG(10, "new dst %pI4, refcnt=%d, rtos=%X\n", |
| 110 | &dest->addr.ip, |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 111 | atomic_read(&rt->dst.__refcnt), rtos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | } |
| 113 | spin_unlock(&dest->dst_lock); |
| 114 | } else { |
David S. Miller | 78fbfd8 | 2011-03-12 00:00:52 -0500 | [diff] [blame] | 115 | rt = ip_route_output(net, daddr, 0, rtos, 0); |
David S. Miller | b23dd4f | 2011-03-02 14:31:35 -0800 | [diff] [blame] | 116 | if (IS_ERR(rt)) { |
Harvey Harrison | 14d5e83 | 2008-10-31 00:54:29 -0700 | [diff] [blame] | 117 | IP_VS_DBG_RL("ip_route_output error, dest: %pI4\n", |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 118 | &daddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | return NULL; |
| 120 | } |
| 121 | } |
| 122 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 123 | local = rt->rt_flags & RTCF_LOCAL; |
Changli Gao | 17a8f8e | 2011-02-24 08:19:57 +0800 | [diff] [blame] | 124 | if (!((local ? IP_VS_RT_MODE_LOCAL : IP_VS_RT_MODE_NON_LOCAL) & |
| 125 | rt_mode)) { |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 126 | IP_VS_DBG_RL("Stopping traffic to %s address, dest: %pI4\n", |
| 127 | (rt->rt_flags & RTCF_LOCAL) ? |
| 128 | "local":"non-local", &rt->rt_dst); |
| 129 | ip_rt_put(rt); |
| 130 | return NULL; |
| 131 | } |
Changli Gao | 17a8f8e | 2011-02-24 08:19:57 +0800 | [diff] [blame] | 132 | if (local && !(rt_mode & IP_VS_RT_MODE_RDR) && |
| 133 | !((ort = skb_rtable(skb)) && ort->rt_flags & RTCF_LOCAL)) { |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 134 | IP_VS_DBG_RL("Redirect from non-local address %pI4 to local " |
| 135 | "requires NAT method, dest: %pI4\n", |
| 136 | &ip_hdr(skb)->daddr, &rt->rt_dst); |
| 137 | ip_rt_put(rt); |
| 138 | return NULL; |
| 139 | } |
| 140 | if (unlikely(!local && ipv4_is_loopback(ip_hdr(skb)->saddr))) { |
| 141 | IP_VS_DBG_RL("Stopping traffic from loopback address %pI4 " |
| 142 | "to non-local address, dest: %pI4\n", |
| 143 | &ip_hdr(skb)->saddr, &rt->rt_dst); |
| 144 | ip_rt_put(rt); |
| 145 | return NULL; |
| 146 | } |
| 147 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | return rt; |
| 149 | } |
| 150 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 151 | /* Reroute packet to local IPv4 stack after DNAT */ |
| 152 | static int |
| 153 | __ip_vs_reroute_locally(struct sk_buff *skb) |
| 154 | { |
| 155 | struct rtable *rt = skb_rtable(skb); |
| 156 | struct net_device *dev = rt->dst.dev; |
| 157 | struct net *net = dev_net(dev); |
| 158 | struct iphdr *iph = ip_hdr(skb); |
| 159 | |
David S. Miller | c753796 | 2010-11-11 17:07:48 -0800 | [diff] [blame] | 160 | if (rt_is_input_route(rt)) { |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 161 | unsigned long orefdst = skb->_skb_refdst; |
| 162 | |
| 163 | if (ip_route_input(skb, iph->daddr, iph->saddr, |
| 164 | iph->tos, skb->dev)) |
| 165 | return 0; |
| 166 | refdst_drop(orefdst); |
| 167 | } else { |
David S. Miller | 9d6ec93 | 2011-03-12 01:12:47 -0500 | [diff] [blame] | 168 | struct flowi4 fl4 = { |
| 169 | .daddr = iph->daddr, |
| 170 | .saddr = iph->saddr, |
| 171 | .flowi4_tos = RT_TOS(iph->tos), |
| 172 | .flowi4_mark = skb->mark, |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 173 | }; |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 174 | |
David S. Miller | 9d6ec93 | 2011-03-12 01:12:47 -0500 | [diff] [blame] | 175 | rt = ip_route_output_key(net, &fl4); |
David S. Miller | b23dd4f | 2011-03-02 14:31:35 -0800 | [diff] [blame] | 176 | if (IS_ERR(rt)) |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 177 | return 0; |
| 178 | if (!(rt->rt_flags & RTCF_LOCAL)) { |
| 179 | ip_rt_put(rt); |
| 180 | return 0; |
| 181 | } |
| 182 | /* Drop old route. */ |
| 183 | skb_dst_drop(skb); |
| 184 | skb_dst_set(skb, &rt->dst); |
| 185 | } |
| 186 | return 1; |
| 187 | } |
| 188 | |
Julius Volz | 38cdcc9 | 2008-09-02 15:55:44 +0200 | [diff] [blame] | 189 | #ifdef CONFIG_IP_VS_IPV6 |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 190 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 191 | static inline int __ip_vs_is_local_route6(struct rt6_info *rt) |
| 192 | { |
| 193 | return rt->rt6i_dev && rt->rt6i_dev->flags & IFF_LOOPBACK; |
| 194 | } |
| 195 | |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 196 | static struct dst_entry * |
| 197 | __ip_vs_route_output_v6(struct net *net, struct in6_addr *daddr, |
| 198 | struct in6_addr *ret_saddr, int do_xfrm) |
Julius Volz | 38cdcc9 | 2008-09-02 15:55:44 +0200 | [diff] [blame] | 199 | { |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 200 | struct dst_entry *dst; |
David S. Miller | 4c9483b | 2011-03-12 16:22:43 -0500 | [diff] [blame] | 201 | struct flowi6 fl6 = { |
| 202 | .daddr = *daddr, |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 203 | }; |
| 204 | |
David S. Miller | 4c9483b | 2011-03-12 16:22:43 -0500 | [diff] [blame] | 205 | dst = ip6_route_output(net, NULL, &fl6); |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 206 | if (dst->error) |
| 207 | goto out_err; |
| 208 | if (!ret_saddr) |
| 209 | return dst; |
David S. Miller | 4c9483b | 2011-03-12 16:22:43 -0500 | [diff] [blame] | 210 | if (ipv6_addr_any(&fl6.saddr) && |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 211 | ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev, |
David S. Miller | 4c9483b | 2011-03-12 16:22:43 -0500 | [diff] [blame] | 212 | &fl6.daddr, 0, &fl6.saddr) < 0) |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 213 | goto out_err; |
David S. Miller | 452edd5 | 2011-03-02 13:27:41 -0800 | [diff] [blame] | 214 | if (do_xfrm) { |
David S. Miller | 4c9483b | 2011-03-12 16:22:43 -0500 | [diff] [blame] | 215 | dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0); |
David S. Miller | 452edd5 | 2011-03-02 13:27:41 -0800 | [diff] [blame] | 216 | if (IS_ERR(dst)) { |
| 217 | dst = NULL; |
| 218 | goto out_err; |
| 219 | } |
| 220 | } |
David S. Miller | 4c9483b | 2011-03-12 16:22:43 -0500 | [diff] [blame] | 221 | ipv6_addr_copy(ret_saddr, &fl6.saddr); |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 222 | return dst; |
| 223 | |
| 224 | out_err: |
| 225 | dst_release(dst); |
| 226 | IP_VS_DBG_RL("ip6_route_output error, dest: %pI6\n", daddr); |
| 227 | return NULL; |
| 228 | } |
| 229 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 230 | /* |
| 231 | * Get route to destination or remote server |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 232 | */ |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 233 | static struct rt6_info * |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 234 | __ip_vs_get_out_rt_v6(struct sk_buff *skb, struct ip_vs_dest *dest, |
| 235 | struct in6_addr *daddr, struct in6_addr *ret_saddr, |
| 236 | int do_xfrm, int rt_mode) |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 237 | { |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 238 | struct net *net = dev_net(skb_dst(skb)->dev); |
Julius Volz | 38cdcc9 | 2008-09-02 15:55:44 +0200 | [diff] [blame] | 239 | struct rt6_info *rt; /* Route to the other host */ |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 240 | struct rt6_info *ort; /* Original route */ |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 241 | struct dst_entry *dst; |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 242 | int local; |
Julius Volz | 38cdcc9 | 2008-09-02 15:55:44 +0200 | [diff] [blame] | 243 | |
| 244 | if (dest) { |
| 245 | spin_lock(&dest->dst_lock); |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 246 | rt = (struct rt6_info *)__ip_vs_dst_check(dest, 0); |
Julius Volz | 38cdcc9 | 2008-09-02 15:55:44 +0200 | [diff] [blame] | 247 | if (!rt) { |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 248 | u32 cookie; |
Julius Volz | 38cdcc9 | 2008-09-02 15:55:44 +0200 | [diff] [blame] | 249 | |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 250 | dst = __ip_vs_route_output_v6(net, &dest->addr.in6, |
| 251 | &dest->dst_saddr, |
| 252 | do_xfrm); |
| 253 | if (!dst) { |
Julius Volz | 38cdcc9 | 2008-09-02 15:55:44 +0200 | [diff] [blame] | 254 | spin_unlock(&dest->dst_lock); |
Julius Volz | 38cdcc9 | 2008-09-02 15:55:44 +0200 | [diff] [blame] | 255 | return NULL; |
| 256 | } |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 257 | rt = (struct rt6_info *) dst; |
| 258 | cookie = rt->rt6i_node ? rt->rt6i_node->fn_sernum : 0; |
| 259 | __ip_vs_dst_set(dest, 0, dst_clone(&rt->dst), cookie); |
| 260 | IP_VS_DBG(10, "new dst %pI6, src %pI6, refcnt=%d\n", |
| 261 | &dest->addr.in6, &dest->dst_saddr, |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 262 | atomic_read(&rt->dst.__refcnt)); |
Julius Volz | 38cdcc9 | 2008-09-02 15:55:44 +0200 | [diff] [blame] | 263 | } |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 264 | if (ret_saddr) |
| 265 | ipv6_addr_copy(ret_saddr, &dest->dst_saddr); |
Julius Volz | 38cdcc9 | 2008-09-02 15:55:44 +0200 | [diff] [blame] | 266 | spin_unlock(&dest->dst_lock); |
| 267 | } else { |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 268 | dst = __ip_vs_route_output_v6(net, daddr, ret_saddr, do_xfrm); |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 269 | if (!dst) |
Julius Volz | 38cdcc9 | 2008-09-02 15:55:44 +0200 | [diff] [blame] | 270 | return NULL; |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 271 | rt = (struct rt6_info *) dst; |
Julius Volz | 38cdcc9 | 2008-09-02 15:55:44 +0200 | [diff] [blame] | 272 | } |
| 273 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 274 | local = __ip_vs_is_local_route6(rt); |
David S. Miller | e58b344 | 2011-05-12 18:22:34 -0400 | [diff] [blame^] | 275 | if (!((local ? IP_VS_RT_MODE_LOCAL : IP_VS_RT_MODE_NON_LOCAL) & |
| 276 | rt_mode)) { |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 277 | IP_VS_DBG_RL("Stopping traffic to %s address, dest: %pI6\n", |
| 278 | local ? "local":"non-local", daddr); |
| 279 | dst_release(&rt->dst); |
| 280 | return NULL; |
| 281 | } |
David S. Miller | e58b344 | 2011-05-12 18:22:34 -0400 | [diff] [blame^] | 282 | if (local && !(rt_mode & IP_VS_RT_MODE_RDR) && |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 283 | !((ort = (struct rt6_info *) skb_dst(skb)) && |
| 284 | __ip_vs_is_local_route6(ort))) { |
| 285 | IP_VS_DBG_RL("Redirect from non-local address %pI6 to local " |
| 286 | "requires NAT method, dest: %pI6\n", |
| 287 | &ipv6_hdr(skb)->daddr, daddr); |
| 288 | dst_release(&rt->dst); |
| 289 | return NULL; |
| 290 | } |
| 291 | if (unlikely(!local && (!skb->dev || skb->dev->flags & IFF_LOOPBACK) && |
| 292 | ipv6_addr_type(&ipv6_hdr(skb)->saddr) & |
| 293 | IPV6_ADDR_LOOPBACK)) { |
| 294 | IP_VS_DBG_RL("Stopping traffic from loopback address %pI6 " |
| 295 | "to non-local address, dest: %pI6\n", |
| 296 | &ipv6_hdr(skb)->saddr, daddr); |
| 297 | dst_release(&rt->dst); |
| 298 | return NULL; |
| 299 | } |
| 300 | |
Julius Volz | 38cdcc9 | 2008-09-02 15:55:44 +0200 | [diff] [blame] | 301 | return rt; |
| 302 | } |
| 303 | #endif |
| 304 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | |
| 306 | /* |
| 307 | * Release dest->dst_cache before a dest is removed |
| 308 | */ |
| 309 | void |
| 310 | ip_vs_dst_reset(struct ip_vs_dest *dest) |
| 311 | { |
| 312 | struct dst_entry *old_dst; |
| 313 | |
| 314 | old_dst = dest->dst_cache; |
| 315 | dest->dst_cache = NULL; |
| 316 | dst_release(old_dst); |
| 317 | } |
| 318 | |
Julian Anastasov | f4bc17c | 2010-09-21 17:35:41 +0200 | [diff] [blame] | 319 | #define IP_VS_XMIT_TUNNEL(skb, cp) \ |
| 320 | ({ \ |
| 321 | int __ret = NF_ACCEPT; \ |
| 322 | \ |
Julian Anastasov | cf356d6 | 2010-10-17 16:21:07 +0300 | [diff] [blame] | 323 | (skb)->ipvs_property = 1; \ |
Julian Anastasov | f4bc17c | 2010-09-21 17:35:41 +0200 | [diff] [blame] | 324 | if (unlikely((cp)->flags & IP_VS_CONN_F_NFCT)) \ |
| 325 | __ret = ip_vs_confirm_conntrack(skb, cp); \ |
| 326 | if (__ret == NF_ACCEPT) { \ |
| 327 | nf_reset(skb); \ |
Julian Anastasov | 4256f1a | 2010-10-17 16:29:40 +0300 | [diff] [blame] | 328 | skb_forward_csum(skb); \ |
Julian Anastasov | f4bc17c | 2010-09-21 17:35:41 +0200 | [diff] [blame] | 329 | } \ |
| 330 | __ret; \ |
| 331 | }) |
| 332 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 333 | #define IP_VS_XMIT_NAT(pf, skb, cp, local) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | do { \ |
Julian Anastasov | cf356d6 | 2010-10-17 16:21:07 +0300 | [diff] [blame] | 335 | (skb)->ipvs_property = 1; \ |
Julian Anastasov | f4bc17c | 2010-09-21 17:35:41 +0200 | [diff] [blame] | 336 | if (likely(!((cp)->flags & IP_VS_CONN_F_NFCT))) \ |
Julian Anastasov | cf356d6 | 2010-10-17 16:21:07 +0300 | [diff] [blame] | 337 | ip_vs_notrack(skb); \ |
Julian Anastasov | f4bc17c | 2010-09-21 17:35:41 +0200 | [diff] [blame] | 338 | else \ |
| 339 | ip_vs_update_conntrack(skb, cp, 1); \ |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 340 | if (local) \ |
| 341 | return NF_ACCEPT; \ |
Herbert Xu | ccc7911 | 2007-07-30 16:20:12 -0700 | [diff] [blame] | 342 | skb_forward_csum(skb); \ |
Julius Volz | 38cdcc9 | 2008-09-02 15:55:44 +0200 | [diff] [blame] | 343 | NF_HOOK(pf, NF_INET_LOCAL_OUT, (skb), NULL, \ |
Julian Anastasov | f4bc17c | 2010-09-21 17:35:41 +0200 | [diff] [blame] | 344 | skb_dst(skb)->dev, dst_output); \ |
| 345 | } while (0) |
| 346 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 347 | #define IP_VS_XMIT(pf, skb, cp, local) \ |
Julian Anastasov | f4bc17c | 2010-09-21 17:35:41 +0200 | [diff] [blame] | 348 | do { \ |
Julian Anastasov | cf356d6 | 2010-10-17 16:21:07 +0300 | [diff] [blame] | 349 | (skb)->ipvs_property = 1; \ |
Julian Anastasov | f4bc17c | 2010-09-21 17:35:41 +0200 | [diff] [blame] | 350 | if (likely(!((cp)->flags & IP_VS_CONN_F_NFCT))) \ |
Julian Anastasov | cf356d6 | 2010-10-17 16:21:07 +0300 | [diff] [blame] | 351 | ip_vs_notrack(skb); \ |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 352 | if (local) \ |
| 353 | return NF_ACCEPT; \ |
Julian Anastasov | f4bc17c | 2010-09-21 17:35:41 +0200 | [diff] [blame] | 354 | skb_forward_csum(skb); \ |
| 355 | NF_HOOK(pf, NF_INET_LOCAL_OUT, (skb), NULL, \ |
| 356 | skb_dst(skb)->dev, dst_output); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | } while (0) |
| 358 | |
| 359 | |
| 360 | /* |
| 361 | * NULL transmitter (do nothing except return NF_ACCEPT) |
| 362 | */ |
| 363 | int |
| 364 | ip_vs_null_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, |
| 365 | struct ip_vs_protocol *pp) |
| 366 | { |
| 367 | /* we do not touch skb and do not need pskb ptr */ |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 368 | IP_VS_XMIT(NFPROTO_IPV4, skb, cp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | |
| 372 | /* |
| 373 | * Bypass transmitter |
| 374 | * Let packets bypass the destination when the destination is not |
| 375 | * available, it may be only used in transparent cache cluster. |
| 376 | */ |
| 377 | int |
| 378 | ip_vs_bypass_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, |
| 379 | struct ip_vs_protocol *pp) |
| 380 | { |
| 381 | struct rtable *rt; /* Route to the other host */ |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 382 | struct iphdr *iph = ip_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | int mtu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | |
| 385 | EnterFunction(10); |
| 386 | |
Changli Gao | 17a8f8e | 2011-02-24 08:19:57 +0800 | [diff] [blame] | 387 | if (!(rt = __ip_vs_get_out_rt(skb, NULL, iph->daddr, RT_TOS(iph->tos), |
| 388 | IP_VS_RT_MODE_NON_LOCAL))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | goto tx_error_icmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
| 391 | /* MTU checking */ |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 392 | mtu = dst_mtu(&rt->dst); |
Simon Horman | 8f1b03a | 2010-11-09 10:08:49 +0900 | [diff] [blame] | 393 | if ((skb->len > mtu) && (iph->frag_off & htons(IP_DF)) && |
| 394 | !skb_is_gso(skb)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | ip_rt_put(rt); |
| 396 | icmp_send(skb, ICMP_DEST_UNREACH,ICMP_FRAG_NEEDED, htonl(mtu)); |
Hannes Eder | 1e3e238 | 2009-08-02 11:05:41 +0000 | [diff] [blame] | 397 | IP_VS_DBG_RL("%s(): frag needed\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | goto tx_error; |
| 399 | } |
| 400 | |
| 401 | /* |
| 402 | * Call ip_send_check because we are not sure it is called |
| 403 | * after ip_defrag. Is copy-on-write needed? |
| 404 | */ |
| 405 | if (unlikely((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL)) { |
| 406 | ip_rt_put(rt); |
| 407 | return NF_STOLEN; |
| 408 | } |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 409 | ip_send_check(ip_hdr(skb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | |
| 411 | /* drop old route */ |
Eric Dumazet | adf3090 | 2009-06-02 05:19:30 +0000 | [diff] [blame] | 412 | skb_dst_drop(skb); |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 413 | skb_dst_set(skb, &rt->dst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
| 415 | /* Another hack: avoid icmp_send in ip_fragment */ |
| 416 | skb->local_df = 1; |
| 417 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 418 | IP_VS_XMIT(NFPROTO_IPV4, skb, cp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | |
| 420 | LeaveFunction(10); |
| 421 | return NF_STOLEN; |
| 422 | |
| 423 | tx_error_icmp: |
| 424 | dst_link_failure(skb); |
| 425 | tx_error: |
| 426 | kfree_skb(skb); |
| 427 | LeaveFunction(10); |
| 428 | return NF_STOLEN; |
| 429 | } |
| 430 | |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 431 | #ifdef CONFIG_IP_VS_IPV6 |
| 432 | int |
| 433 | ip_vs_bypass_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, |
| 434 | struct ip_vs_protocol *pp) |
| 435 | { |
| 436 | struct rt6_info *rt; /* Route to the other host */ |
| 437 | struct ipv6hdr *iph = ipv6_hdr(skb); |
| 438 | int mtu; |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 439 | |
| 440 | EnterFunction(10); |
| 441 | |
David S. Miller | e58b344 | 2011-05-12 18:22:34 -0400 | [diff] [blame^] | 442 | if (!(rt = __ip_vs_get_out_rt_v6(skb, NULL, &iph->daddr, NULL, 0, |
| 443 | IP_VS_RT_MODE_NON_LOCAL))) |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 444 | goto tx_error_icmp; |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 445 | |
| 446 | /* MTU checking */ |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 447 | mtu = dst_mtu(&rt->dst); |
Simon Horman | 8f1b03a | 2010-11-09 10:08:49 +0900 | [diff] [blame] | 448 | if (skb->len > mtu && !skb_is_gso(skb)) { |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 449 | if (!skb->dev) { |
| 450 | struct net *net = dev_net(skb_dst(skb)->dev); |
| 451 | |
| 452 | skb->dev = net->loopback_dev; |
| 453 | } |
Alexey Dobriyan | 3ffe533 | 2010-02-18 08:25:24 +0000 | [diff] [blame] | 454 | icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu); |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 455 | dst_release(&rt->dst); |
Hannes Eder | 1e3e238 | 2009-08-02 11:05:41 +0000 | [diff] [blame] | 456 | IP_VS_DBG_RL("%s(): frag needed\n", __func__); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 457 | goto tx_error; |
| 458 | } |
| 459 | |
| 460 | /* |
| 461 | * Call ip_send_check because we are not sure it is called |
| 462 | * after ip_defrag. Is copy-on-write needed? |
| 463 | */ |
| 464 | skb = skb_share_check(skb, GFP_ATOMIC); |
| 465 | if (unlikely(skb == NULL)) { |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 466 | dst_release(&rt->dst); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 467 | return NF_STOLEN; |
| 468 | } |
| 469 | |
| 470 | /* drop old route */ |
Eric Dumazet | adf3090 | 2009-06-02 05:19:30 +0000 | [diff] [blame] | 471 | skb_dst_drop(skb); |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 472 | skb_dst_set(skb, &rt->dst); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 473 | |
| 474 | /* Another hack: avoid icmp_send in ip_fragment */ |
| 475 | skb->local_df = 1; |
| 476 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 477 | IP_VS_XMIT(NFPROTO_IPV6, skb, cp, 0); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 478 | |
| 479 | LeaveFunction(10); |
| 480 | return NF_STOLEN; |
| 481 | |
| 482 | tx_error_icmp: |
| 483 | dst_link_failure(skb); |
| 484 | tx_error: |
| 485 | kfree_skb(skb); |
| 486 | LeaveFunction(10); |
| 487 | return NF_STOLEN; |
| 488 | } |
| 489 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | |
| 491 | /* |
| 492 | * NAT transmitter (only for outside-to-inside nat forwarding) |
| 493 | * Not used for related ICMP |
| 494 | */ |
| 495 | int |
| 496 | ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, |
| 497 | struct ip_vs_protocol *pp) |
| 498 | { |
| 499 | struct rtable *rt; /* Route to the other host */ |
| 500 | int mtu; |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 501 | struct iphdr *iph = ip_hdr(skb); |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 502 | int local; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | |
| 504 | EnterFunction(10); |
| 505 | |
| 506 | /* check if it is a connection of no-client-port */ |
| 507 | if (unlikely(cp->flags & IP_VS_CONN_F_NO_CPORT)) { |
Al Viro | 014d730 | 2006-09-28 14:29:52 -0700 | [diff] [blame] | 508 | __be16 _pt, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | p = skb_header_pointer(skb, iph->ihl*4, sizeof(_pt), &_pt); |
| 510 | if (p == NULL) |
| 511 | goto tx_error; |
| 512 | ip_vs_conn_fill_cport(cp, *p); |
| 513 | IP_VS_DBG(10, "filled cport=%d\n", ntohs(*p)); |
| 514 | } |
| 515 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 516 | 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] | 517 | RT_TOS(iph->tos), |
| 518 | IP_VS_RT_MODE_LOCAL | |
| 519 | IP_VS_RT_MODE_NON_LOCAL | |
| 520 | IP_VS_RT_MODE_RDR))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | goto tx_error_icmp; |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 522 | local = rt->rt_flags & RTCF_LOCAL; |
| 523 | /* |
| 524 | * Avoid duplicate tuple in reply direction for NAT traffic |
| 525 | * to local address when connection is sync-ed |
| 526 | */ |
| 527 | #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) |
| 528 | if (cp->flags & IP_VS_CONN_F_SYNC && local) { |
| 529 | enum ip_conntrack_info ctinfo; |
| 530 | struct nf_conn *ct = ct = nf_ct_get(skb, &ctinfo); |
| 531 | |
| 532 | if (ct && !nf_ct_is_untracked(ct)) { |
Julian Anastasov | 0d79641 | 2010-10-17 16:46:17 +0300 | [diff] [blame] | 533 | IP_VS_DBG_RL_PKT(10, AF_INET, pp, skb, 0, |
| 534 | "ip_vs_nat_xmit(): " |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 535 | "stopping DNAT to local address"); |
| 536 | goto tx_error_put; |
| 537 | } |
| 538 | } |
| 539 | #endif |
| 540 | |
| 541 | /* From world but DNAT to loopback address? */ |
David S. Miller | c753796 | 2010-11-11 17:07:48 -0800 | [diff] [blame] | 542 | if (local && ipv4_is_loopback(rt->rt_dst) && |
| 543 | rt_is_input_route(skb_rtable(skb))) { |
Julian Anastasov | 0d79641 | 2010-10-17 16:46:17 +0300 | [diff] [blame] | 544 | 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] | 545 | "stopping DNAT to loopback address"); |
| 546 | goto tx_error_put; |
| 547 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | |
| 549 | /* MTU checking */ |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 550 | mtu = dst_mtu(&rt->dst); |
Simon Horman | 8f1b03a | 2010-11-09 10:08:49 +0900 | [diff] [blame] | 551 | if ((skb->len > mtu) && (iph->frag_off & htons(IP_DF)) && |
| 552 | !skb_is_gso(skb)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | icmp_send(skb, ICMP_DEST_UNREACH,ICMP_FRAG_NEEDED, htonl(mtu)); |
Julian Anastasov | 0d79641 | 2010-10-17 16:46:17 +0300 | [diff] [blame] | 554 | IP_VS_DBG_RL_PKT(0, AF_INET, pp, skb, 0, |
| 555 | "ip_vs_nat_xmit(): frag needed for"); |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 556 | goto tx_error_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | /* copy-on-write the packet before mangling it */ |
Herbert Xu | af1e1cf | 2007-10-14 00:39:33 -0700 | [diff] [blame] | 560 | if (!skb_make_writable(skb, sizeof(struct iphdr))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | goto tx_error_put; |
| 562 | |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 563 | if (skb_cow(skb, rt->dst.dev->hard_header_len)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | goto tx_error_put; |
| 565 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | /* mangle the packet */ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 567 | if (pp->dnat_handler && !pp->dnat_handler(skb, pp, cp)) |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 568 | goto tx_error_put; |
Julius Volz | e7ade46 | 2008-09-02 15:55:33 +0200 | [diff] [blame] | 569 | ip_hdr(skb)->daddr = cp->daddr.ip; |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 570 | ip_send_check(ip_hdr(skb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 572 | if (!local) { |
| 573 | /* drop old route */ |
| 574 | skb_dst_drop(skb); |
| 575 | skb_dst_set(skb, &rt->dst); |
| 576 | } else { |
| 577 | ip_rt_put(rt); |
| 578 | /* |
| 579 | * Some IPv4 replies get local address from routes, |
| 580 | * not from iph, so while we DNAT after routing |
| 581 | * we need this second input/output route. |
| 582 | */ |
| 583 | if (!__ip_vs_reroute_locally(skb)) |
| 584 | goto tx_error; |
| 585 | } |
| 586 | |
Julian Anastasov | 0d79641 | 2010-10-17 16:46:17 +0300 | [diff] [blame] | 587 | IP_VS_DBG_PKT(10, AF_INET, pp, skb, 0, "After DNAT"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | |
| 589 | /* FIXME: when application helper enlarges the packet and the length |
| 590 | is larger than the MTU of outgoing device, there will be still |
| 591 | MTU problem. */ |
| 592 | |
| 593 | /* Another hack: avoid icmp_send in ip_fragment */ |
| 594 | skb->local_df = 1; |
| 595 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 596 | IP_VS_XMIT_NAT(NFPROTO_IPV4, skb, cp, local); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | |
| 598 | LeaveFunction(10); |
| 599 | return NF_STOLEN; |
| 600 | |
| 601 | tx_error_icmp: |
| 602 | dst_link_failure(skb); |
| 603 | tx_error: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | kfree_skb(skb); |
Julian Anastasov | f4bc17c | 2010-09-21 17:35:41 +0200 | [diff] [blame] | 605 | LeaveFunction(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | return NF_STOLEN; |
| 607 | tx_error_put: |
| 608 | ip_rt_put(rt); |
| 609 | goto tx_error; |
| 610 | } |
| 611 | |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 612 | #ifdef CONFIG_IP_VS_IPV6 |
| 613 | int |
| 614 | ip_vs_nat_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, |
| 615 | struct ip_vs_protocol *pp) |
| 616 | { |
| 617 | struct rt6_info *rt; /* Route to the other host */ |
| 618 | int mtu; |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 619 | int local; |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 620 | |
| 621 | EnterFunction(10); |
| 622 | |
| 623 | /* check if it is a connection of no-client-port */ |
| 624 | if (unlikely(cp->flags & IP_VS_CONN_F_NO_CPORT)) { |
| 625 | __be16 _pt, *p; |
| 626 | p = skb_header_pointer(skb, sizeof(struct ipv6hdr), |
| 627 | sizeof(_pt), &_pt); |
| 628 | if (p == NULL) |
| 629 | goto tx_error; |
| 630 | ip_vs_conn_fill_cport(cp, *p); |
| 631 | IP_VS_DBG(10, "filled cport=%d\n", ntohs(*p)); |
| 632 | } |
| 633 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 634 | if (!(rt = __ip_vs_get_out_rt_v6(skb, cp->dest, &cp->daddr.in6, NULL, |
David S. Miller | e58b344 | 2011-05-12 18:22:34 -0400 | [diff] [blame^] | 635 | 0, (IP_VS_RT_MODE_LOCAL | |
| 636 | IP_VS_RT_MODE_NON_LOCAL | |
| 637 | IP_VS_RT_MODE_RDR)))) |
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, |
David S. Miller | e58b344 | 2011-05-12 18:22:34 -0400 | [diff] [blame^] | 880 | &saddr, 1, (IP_VS_RT_MODE_LOCAL | |
| 881 | IP_VS_RT_MODE_NON_LOCAL)))) |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 882 | goto tx_error_icmp; |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 883 | if (__ip_vs_is_local_route6(rt)) { |
| 884 | dst_release(&rt->dst); |
| 885 | IP_VS_XMIT(NFPROTO_IPV6, skb, cp, 1); |
| 886 | } |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 887 | |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 888 | tdev = rt->dst.dev; |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 889 | |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 890 | mtu = dst_mtu(&rt->dst) - sizeof(struct ipv6hdr); |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 891 | if (mtu < IPV6_MIN_MTU) { |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 892 | IP_VS_DBG_RL("%s(): mtu less than %d\n", __func__, |
| 893 | IPV6_MIN_MTU); |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 894 | goto tx_error_put; |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 895 | } |
Eric Dumazet | adf3090 | 2009-06-02 05:19:30 +0000 | [diff] [blame] | 896 | if (skb_dst(skb)) |
| 897 | skb_dst(skb)->ops->update_pmtu(skb_dst(skb), mtu); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 898 | |
Simon Horman | 8f1b03a | 2010-11-09 10:08:49 +0900 | [diff] [blame] | 899 | if (mtu < ntohs(old_iph->payload_len) + sizeof(struct ipv6hdr) && |
| 900 | !skb_is_gso(skb)) { |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 901 | if (!skb->dev) { |
| 902 | struct net *net = dev_net(skb_dst(skb)->dev); |
| 903 | |
| 904 | skb->dev = net->loopback_dev; |
| 905 | } |
Alexey Dobriyan | 3ffe533 | 2010-02-18 08:25:24 +0000 | [diff] [blame] | 906 | icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu); |
Hannes Eder | 1e3e238 | 2009-08-02 11:05:41 +0000 | [diff] [blame] | 907 | IP_VS_DBG_RL("%s(): frag needed\n", __func__); |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 908 | goto tx_error_put; |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | /* |
| 912 | * Okay, now see if we can stuff it in the buffer as-is. |
| 913 | */ |
| 914 | max_headroom = LL_RESERVED_SPACE(tdev) + sizeof(struct ipv6hdr); |
| 915 | |
| 916 | if (skb_headroom(skb) < max_headroom |
| 917 | || skb_cloned(skb) || skb_shared(skb)) { |
| 918 | struct sk_buff *new_skb = |
| 919 | skb_realloc_headroom(skb, max_headroom); |
| 920 | if (!new_skb) { |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 921 | dst_release(&rt->dst); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 922 | kfree_skb(skb); |
Hannes Eder | 1e3e238 | 2009-08-02 11:05:41 +0000 | [diff] [blame] | 923 | IP_VS_ERR_RL("%s(): no memory\n", __func__); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 924 | return NF_STOLEN; |
| 925 | } |
| 926 | kfree_skb(skb); |
| 927 | skb = new_skb; |
| 928 | old_iph = ipv6_hdr(skb); |
| 929 | } |
| 930 | |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 931 | skb->transport_header = skb->network_header; |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 932 | |
| 933 | skb_push(skb, sizeof(struct ipv6hdr)); |
| 934 | skb_reset_network_header(skb); |
| 935 | memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt)); |
| 936 | |
| 937 | /* drop old route */ |
Eric Dumazet | adf3090 | 2009-06-02 05:19:30 +0000 | [diff] [blame] | 938 | skb_dst_drop(skb); |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 939 | skb_dst_set(skb, &rt->dst); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 940 | |
| 941 | /* |
| 942 | * Push down and install the IPIP header. |
| 943 | */ |
| 944 | iph = ipv6_hdr(skb); |
| 945 | iph->version = 6; |
| 946 | iph->nexthdr = IPPROTO_IPV6; |
Harvey Harrison | b7b45f4 | 2008-11-10 16:46:06 -0800 | [diff] [blame] | 947 | iph->payload_len = old_iph->payload_len; |
| 948 | be16_add_cpu(&iph->payload_len, sizeof(*old_iph)); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 949 | iph->priority = old_iph->priority; |
| 950 | memset(&iph->flow_lbl, 0, sizeof(iph->flow_lbl)); |
Hans Schillstrom | 714f095 | 2010-10-19 10:38:48 +0200 | [diff] [blame] | 951 | ipv6_addr_copy(&iph->daddr, &cp->daddr.in6); |
| 952 | ipv6_addr_copy(&iph->saddr, &saddr); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 953 | iph->hop_limit = old_iph->hop_limit; |
| 954 | |
| 955 | /* Another hack: avoid icmp_send in ip_fragment */ |
| 956 | skb->local_df = 1; |
| 957 | |
Julian Anastasov | f4bc17c | 2010-09-21 17:35:41 +0200 | [diff] [blame] | 958 | ret = IP_VS_XMIT_TUNNEL(skb, cp); |
| 959 | if (ret == NF_ACCEPT) |
| 960 | ip6_local_out(skb); |
| 961 | else if (ret == NF_DROP) |
| 962 | kfree_skb(skb); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 963 | |
| 964 | LeaveFunction(10); |
| 965 | |
| 966 | return NF_STOLEN; |
| 967 | |
| 968 | tx_error_icmp: |
| 969 | dst_link_failure(skb); |
| 970 | tx_error: |
| 971 | kfree_skb(skb); |
| 972 | LeaveFunction(10); |
| 973 | return NF_STOLEN; |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 974 | tx_error_put: |
| 975 | dst_release(&rt->dst); |
| 976 | goto tx_error; |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 977 | } |
| 978 | #endif |
| 979 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | |
| 981 | /* |
| 982 | * Direct Routing transmitter |
| 983 | * Used for ANY protocol |
| 984 | */ |
| 985 | int |
| 986 | ip_vs_dr_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, |
| 987 | struct ip_vs_protocol *pp) |
| 988 | { |
| 989 | struct rtable *rt; /* Route to the other host */ |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 990 | struct iphdr *iph = ip_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | int mtu; |
| 992 | |
| 993 | EnterFunction(10); |
| 994 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 995 | 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] | 996 | RT_TOS(iph->tos), |
| 997 | IP_VS_RT_MODE_LOCAL | |
| 998 | IP_VS_RT_MODE_NON_LOCAL))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | goto tx_error_icmp; |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1000 | if (rt->rt_flags & RTCF_LOCAL) { |
| 1001 | ip_rt_put(rt); |
| 1002 | IP_VS_XMIT(NFPROTO_IPV4, skb, cp, 1); |
| 1003 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | |
| 1005 | /* MTU checking */ |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 1006 | mtu = dst_mtu(&rt->dst); |
Simon Horman | 8f1b03a | 2010-11-09 10:08:49 +0900 | [diff] [blame] | 1007 | if ((iph->frag_off & htons(IP_DF)) && skb->len > mtu && |
| 1008 | !skb_is_gso(skb)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | icmp_send(skb, ICMP_DEST_UNREACH,ICMP_FRAG_NEEDED, htonl(mtu)); |
| 1010 | ip_rt_put(rt); |
Hannes Eder | 1e3e238 | 2009-08-02 11:05:41 +0000 | [diff] [blame] | 1011 | IP_VS_DBG_RL("%s(): frag needed\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | goto tx_error; |
| 1013 | } |
| 1014 | |
| 1015 | /* |
| 1016 | * Call ip_send_check because we are not sure it is called |
| 1017 | * after ip_defrag. Is copy-on-write needed? |
| 1018 | */ |
| 1019 | if (unlikely((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL)) { |
| 1020 | ip_rt_put(rt); |
| 1021 | return NF_STOLEN; |
| 1022 | } |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 1023 | ip_send_check(ip_hdr(skb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | |
| 1025 | /* drop old route */ |
Eric Dumazet | adf3090 | 2009-06-02 05:19:30 +0000 | [diff] [blame] | 1026 | skb_dst_drop(skb); |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 1027 | skb_dst_set(skb, &rt->dst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | |
| 1029 | /* Another hack: avoid icmp_send in ip_fragment */ |
| 1030 | skb->local_df = 1; |
| 1031 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1032 | IP_VS_XMIT(NFPROTO_IPV4, skb, cp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | |
| 1034 | LeaveFunction(10); |
| 1035 | return NF_STOLEN; |
| 1036 | |
| 1037 | tx_error_icmp: |
| 1038 | dst_link_failure(skb); |
| 1039 | tx_error: |
| 1040 | kfree_skb(skb); |
| 1041 | LeaveFunction(10); |
| 1042 | return NF_STOLEN; |
| 1043 | } |
| 1044 | |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 1045 | #ifdef CONFIG_IP_VS_IPV6 |
| 1046 | int |
| 1047 | ip_vs_dr_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, |
| 1048 | struct ip_vs_protocol *pp) |
| 1049 | { |
| 1050 | struct rt6_info *rt; /* Route to the other host */ |
| 1051 | int mtu; |
| 1052 | |
| 1053 | EnterFunction(10); |
| 1054 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1055 | if (!(rt = __ip_vs_get_out_rt_v6(skb, cp->dest, &cp->daddr.in6, NULL, |
David S. Miller | e58b344 | 2011-05-12 18:22:34 -0400 | [diff] [blame^] | 1056 | 0, (IP_VS_RT_MODE_LOCAL | |
| 1057 | IP_VS_RT_MODE_NON_LOCAL)))) |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 1058 | goto tx_error_icmp; |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1059 | if (__ip_vs_is_local_route6(rt)) { |
| 1060 | dst_release(&rt->dst); |
| 1061 | IP_VS_XMIT(NFPROTO_IPV6, skb, cp, 1); |
| 1062 | } |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 1063 | |
| 1064 | /* MTU checking */ |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 1065 | mtu = dst_mtu(&rt->dst); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 1066 | if (skb->len > mtu) { |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 1067 | if (!skb->dev) { |
| 1068 | struct net *net = dev_net(skb_dst(skb)->dev); |
| 1069 | |
| 1070 | skb->dev = net->loopback_dev; |
| 1071 | } |
Alexey Dobriyan | 3ffe533 | 2010-02-18 08:25:24 +0000 | [diff] [blame] | 1072 | icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu); |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 1073 | dst_release(&rt->dst); |
Hannes Eder | 1e3e238 | 2009-08-02 11:05:41 +0000 | [diff] [blame] | 1074 | IP_VS_DBG_RL("%s(): frag needed\n", __func__); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 1075 | goto tx_error; |
| 1076 | } |
| 1077 | |
| 1078 | /* |
| 1079 | * Call ip_send_check because we are not sure it is called |
| 1080 | * after ip_defrag. Is copy-on-write needed? |
| 1081 | */ |
| 1082 | skb = skb_share_check(skb, GFP_ATOMIC); |
| 1083 | if (unlikely(skb == NULL)) { |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 1084 | dst_release(&rt->dst); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 1085 | return NF_STOLEN; |
| 1086 | } |
| 1087 | |
| 1088 | /* drop old route */ |
Eric Dumazet | adf3090 | 2009-06-02 05:19:30 +0000 | [diff] [blame] | 1089 | skb_dst_drop(skb); |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 1090 | skb_dst_set(skb, &rt->dst); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 1091 | |
| 1092 | /* Another hack: avoid icmp_send in ip_fragment */ |
| 1093 | skb->local_df = 1; |
| 1094 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1095 | IP_VS_XMIT(NFPROTO_IPV6, skb, cp, 0); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 1096 | |
| 1097 | LeaveFunction(10); |
| 1098 | return NF_STOLEN; |
| 1099 | |
| 1100 | tx_error_icmp: |
| 1101 | dst_link_failure(skb); |
| 1102 | tx_error: |
| 1103 | kfree_skb(skb); |
| 1104 | LeaveFunction(10); |
| 1105 | return NF_STOLEN; |
| 1106 | } |
| 1107 | #endif |
| 1108 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | |
| 1110 | /* |
| 1111 | * ICMP packet transmitter |
| 1112 | * called by the ip_vs_in_icmp |
| 1113 | */ |
| 1114 | int |
| 1115 | ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, |
| 1116 | struct ip_vs_protocol *pp, int offset) |
| 1117 | { |
| 1118 | struct rtable *rt; /* Route to the other host */ |
| 1119 | int mtu; |
| 1120 | int rc; |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1121 | int local; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | |
| 1123 | EnterFunction(10); |
| 1124 | |
| 1125 | /* The ICMP packet for VS/TUN, VS/DR and LOCALNODE will be |
| 1126 | forwarded directly here, because there is no need to |
| 1127 | translate address/port back */ |
| 1128 | if (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ) { |
| 1129 | if (cp->packet_xmit) |
| 1130 | rc = cp->packet_xmit(skb, cp, pp); |
| 1131 | else |
| 1132 | rc = NF_ACCEPT; |
| 1133 | /* do not touch skb anymore */ |
| 1134 | atomic_inc(&cp->in_pkts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | goto out; |
| 1136 | } |
| 1137 | |
| 1138 | /* |
| 1139 | * mangle and send the packet here (only for VS/NAT) |
| 1140 | */ |
| 1141 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1142 | 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] | 1143 | RT_TOS(ip_hdr(skb)->tos), |
| 1144 | IP_VS_RT_MODE_LOCAL | |
| 1145 | IP_VS_RT_MODE_NON_LOCAL | |
| 1146 | IP_VS_RT_MODE_RDR))) |
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); |
Simon Horman | 8f1b03a | 2010-11-09 10:08:49 +0900 | [diff] [blame] | 1179 | if ((skb->len > mtu) && (ip_hdr(skb)->frag_off & htons(IP_DF)) && |
| 1180 | !skb_is_gso(skb)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, htonl(mtu)); |
Hannes Eder | 1e3e238 | 2009-08-02 11:05:41 +0000 | [diff] [blame] | 1182 | IP_VS_DBG_RL("%s(): frag needed\n", __func__); |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1183 | goto tx_error_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | /* copy-on-write the packet before mangling it */ |
Herbert Xu | af1e1cf | 2007-10-14 00:39:33 -0700 | [diff] [blame] | 1187 | if (!skb_make_writable(skb, offset)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | goto tx_error_put; |
| 1189 | |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 1190 | if (skb_cow(skb, rt->dst.dev->hard_header_len)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | goto tx_error_put; |
| 1192 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | ip_vs_nat_icmp(skb, pp, cp, 0); |
| 1194 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1195 | if (!local) { |
| 1196 | /* drop the old route when skb is not shared */ |
| 1197 | skb_dst_drop(skb); |
| 1198 | skb_dst_set(skb, &rt->dst); |
| 1199 | } else { |
| 1200 | ip_rt_put(rt); |
| 1201 | /* |
| 1202 | * Some IPv4 replies get local address from routes, |
| 1203 | * not from iph, so while we DNAT after routing |
| 1204 | * we need this second input/output route. |
| 1205 | */ |
| 1206 | if (!__ip_vs_reroute_locally(skb)) |
| 1207 | goto tx_error; |
| 1208 | } |
| 1209 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | /* Another hack: avoid icmp_send in ip_fragment */ |
| 1211 | skb->local_df = 1; |
| 1212 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1213 | IP_VS_XMIT_NAT(NFPROTO_IPV4, skb, cp, local); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | |
| 1215 | rc = NF_STOLEN; |
| 1216 | goto out; |
| 1217 | |
| 1218 | tx_error_icmp: |
| 1219 | dst_link_failure(skb); |
| 1220 | tx_error: |
| 1221 | dev_kfree_skb(skb); |
| 1222 | rc = NF_STOLEN; |
| 1223 | out: |
| 1224 | LeaveFunction(10); |
| 1225 | return rc; |
| 1226 | tx_error_put: |
| 1227 | ip_rt_put(rt); |
| 1228 | goto tx_error; |
| 1229 | } |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 1230 | |
| 1231 | #ifdef CONFIG_IP_VS_IPV6 |
| 1232 | int |
| 1233 | ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, |
| 1234 | struct ip_vs_protocol *pp, int offset) |
| 1235 | { |
| 1236 | struct rt6_info *rt; /* Route to the other host */ |
| 1237 | int mtu; |
| 1238 | int rc; |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1239 | int local; |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 1240 | |
| 1241 | EnterFunction(10); |
| 1242 | |
| 1243 | /* The ICMP packet for VS/TUN, VS/DR and LOCALNODE will be |
| 1244 | forwarded directly here, because there is no need to |
| 1245 | translate address/port back */ |
| 1246 | if (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ) { |
| 1247 | if (cp->packet_xmit) |
| 1248 | rc = cp->packet_xmit(skb, cp, pp); |
| 1249 | else |
| 1250 | rc = NF_ACCEPT; |
| 1251 | /* do not touch skb anymore */ |
| 1252 | atomic_inc(&cp->in_pkts); |
| 1253 | goto out; |
| 1254 | } |
| 1255 | |
| 1256 | /* |
| 1257 | * mangle and send the packet here (only for VS/NAT) |
| 1258 | */ |
| 1259 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1260 | if (!(rt = __ip_vs_get_out_rt_v6(skb, cp->dest, &cp->daddr.in6, NULL, |
David S. Miller | e58b344 | 2011-05-12 18:22:34 -0400 | [diff] [blame^] | 1261 | 0, (IP_VS_RT_MODE_LOCAL | |
| 1262 | IP_VS_RT_MODE_NON_LOCAL | |
| 1263 | IP_VS_RT_MODE_RDR)))) |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 1264 | goto tx_error_icmp; |
| 1265 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1266 | local = __ip_vs_is_local_route6(rt); |
| 1267 | /* |
| 1268 | * Avoid duplicate tuple in reply direction for NAT traffic |
| 1269 | * to local address when connection is sync-ed |
| 1270 | */ |
| 1271 | #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) |
| 1272 | if (cp->flags & IP_VS_CONN_F_SYNC && local) { |
| 1273 | enum ip_conntrack_info ctinfo; |
| 1274 | struct nf_conn *ct = ct = nf_ct_get(skb, &ctinfo); |
| 1275 | |
| 1276 | if (ct && !nf_ct_is_untracked(ct)) { |
| 1277 | IP_VS_DBG(10, "%s(): " |
| 1278 | "stopping DNAT to local address %pI6\n", |
| 1279 | __func__, &cp->daddr.in6); |
| 1280 | goto tx_error_put; |
| 1281 | } |
| 1282 | } |
| 1283 | #endif |
| 1284 | |
| 1285 | /* From world but DNAT to loopback address? */ |
| 1286 | if (local && skb->dev && !(skb->dev->flags & IFF_LOOPBACK) && |
| 1287 | ipv6_addr_type(&rt->rt6i_dst.addr) & IPV6_ADDR_LOOPBACK) { |
| 1288 | IP_VS_DBG(1, "%s(): " |
| 1289 | "stopping DNAT to loopback %pI6\n", |
| 1290 | __func__, &cp->daddr.in6); |
| 1291 | goto tx_error_put; |
| 1292 | } |
| 1293 | |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 1294 | /* MTU checking */ |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 1295 | mtu = dst_mtu(&rt->dst); |
Simon Horman | 8f1b03a | 2010-11-09 10:08:49 +0900 | [diff] [blame] | 1296 | if (skb->len > mtu && !skb_is_gso(skb)) { |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 1297 | if (!skb->dev) { |
| 1298 | struct net *net = dev_net(skb_dst(skb)->dev); |
| 1299 | |
| 1300 | skb->dev = net->loopback_dev; |
| 1301 | } |
Alexey Dobriyan | 3ffe533 | 2010-02-18 08:25:24 +0000 | [diff] [blame] | 1302 | icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu); |
Hannes Eder | 1e3e238 | 2009-08-02 11:05:41 +0000 | [diff] [blame] | 1303 | IP_VS_DBG_RL("%s(): frag needed\n", __func__); |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1304 | goto tx_error_put; |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 1305 | } |
| 1306 | |
| 1307 | /* copy-on-write the packet before mangling it */ |
| 1308 | if (!skb_make_writable(skb, offset)) |
| 1309 | goto tx_error_put; |
| 1310 | |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 1311 | if (skb_cow(skb, rt->dst.dev->hard_header_len)) |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 1312 | goto tx_error_put; |
| 1313 | |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 1314 | ip_vs_nat_icmp_v6(skb, pp, cp, 0); |
| 1315 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1316 | if (!local || !skb->dev) { |
| 1317 | /* drop the old route when skb is not shared */ |
| 1318 | skb_dst_drop(skb); |
| 1319 | skb_dst_set(skb, &rt->dst); |
| 1320 | } else { |
| 1321 | /* destined to loopback, do we need to change route? */ |
| 1322 | dst_release(&rt->dst); |
| 1323 | } |
| 1324 | |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 1325 | /* Another hack: avoid icmp_send in ip_fragment */ |
| 1326 | skb->local_df = 1; |
| 1327 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1328 | IP_VS_XMIT_NAT(NFPROTO_IPV6, skb, cp, local); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 1329 | |
| 1330 | rc = NF_STOLEN; |
| 1331 | goto out; |
| 1332 | |
| 1333 | tx_error_icmp: |
| 1334 | dst_link_failure(skb); |
| 1335 | tx_error: |
| 1336 | dev_kfree_skb(skb); |
| 1337 | rc = NF_STOLEN; |
| 1338 | out: |
| 1339 | LeaveFunction(10); |
| 1340 | return rc; |
| 1341 | tx_error_put: |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 1342 | dst_release(&rt->dst); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 1343 | goto tx_error; |
| 1344 | } |
| 1345 | #endif |