Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * IPVS An implementation of the IP virtual server support for the |
| 3 | * LINUX operating system. IPVS is now implemented as a module |
| 4 | * over the Netfilter framework. IPVS can be used to build a |
| 5 | * high-performance and highly available server based on a |
| 6 | * cluster of servers. |
| 7 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * Authors: Wensong Zhang <wensong@linuxvirtualserver.org> |
| 9 | * Peter Kese <peter.kese@ijs.si> |
| 10 | * Julian Anastasov <ja@ssi.bg> |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License |
| 14 | * as published by the Free Software Foundation; either version |
| 15 | * 2 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * The IPVS code for kernel 2.2 was done by Wensong Zhang and Peter Kese, |
| 18 | * with changes/fixes from Julian Anastasov, Lars Marowsky-Bree, Horms |
| 19 | * and others. |
| 20 | * |
| 21 | * Changes: |
| 22 | * Paul `Rusty' Russell properly handle non-linear skbs |
Harald Welte | 6869c4d | 2005-08-09 19:24:19 -0700 | [diff] [blame] | 23 | * Harald Welte don't use nfcache |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | * |
| 25 | */ |
| 26 | |
Hannes Eder | 9aada7a | 2009-07-30 14:29:44 -0700 | [diff] [blame] | 27 | #define KMSG_COMPONENT "IPVS" |
| 28 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 29 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/module.h> |
| 31 | #include <linux/kernel.h> |
| 32 | #include <linux/ip.h> |
| 33 | #include <linux/tcp.h> |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 34 | #include <linux/sctp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <linux/icmp.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 36 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 38 | #include <net/ip.h> |
| 39 | #include <net/tcp.h> |
| 40 | #include <net/udp.h> |
| 41 | #include <net/icmp.h> /* for icmp_send */ |
| 42 | #include <net/route.h> |
Stephen Rothwell | 2c70b51 | 2010-08-29 17:04:53 +0000 | [diff] [blame] | 43 | #include <net/ip6_checksum.h> |
Hans Schillstrom | 61b1ab4 | 2011-01-03 14:44:42 +0100 | [diff] [blame] | 44 | #include <net/netns/generic.h> /* net_generic() */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
| 46 | #include <linux/netfilter.h> |
| 47 | #include <linux/netfilter_ipv4.h> |
| 48 | |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 49 | #ifdef CONFIG_IP_VS_IPV6 |
| 50 | #include <net/ipv6.h> |
| 51 | #include <linux/netfilter_ipv6.h> |
Julian Anastasov | 489fded | 2010-10-17 16:27:31 +0300 | [diff] [blame] | 52 | #include <net/ip6_route.h> |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 53 | #endif |
| 54 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | #include <net/ip_vs.h> |
| 56 | |
| 57 | |
| 58 | EXPORT_SYMBOL(register_ip_vs_scheduler); |
| 59 | EXPORT_SYMBOL(unregister_ip_vs_scheduler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | EXPORT_SYMBOL(ip_vs_proto_name); |
| 61 | EXPORT_SYMBOL(ip_vs_conn_new); |
| 62 | EXPORT_SYMBOL(ip_vs_conn_in_get); |
| 63 | EXPORT_SYMBOL(ip_vs_conn_out_get); |
| 64 | #ifdef CONFIG_IP_VS_PROTO_TCP |
| 65 | EXPORT_SYMBOL(ip_vs_tcp_conn_listen); |
| 66 | #endif |
| 67 | EXPORT_SYMBOL(ip_vs_conn_put); |
| 68 | #ifdef CONFIG_IP_VS_DEBUG |
| 69 | EXPORT_SYMBOL(ip_vs_get_debug_level); |
| 70 | #endif |
Marco Angaroni | 39b9722 | 2016-04-05 18:26:29 +0200 | [diff] [blame] | 71 | EXPORT_SYMBOL(ip_vs_new_conn_out); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
Julian Anastasov | b962abd | 2013-03-09 23:25:08 +0200 | [diff] [blame] | 73 | static int ip_vs_net_id __read_mostly; |
Hans Schillstrom | 61b1ab4 | 2011-01-03 14:44:42 +0100 | [diff] [blame] | 74 | /* netns cnt used for uniqueness */ |
| 75 | static atomic_t ipvs_netns_cnt = ATOMIC_INIT(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
| 77 | /* ID used in ICMP lookups */ |
| 78 | #define icmp_id(icmph) (((icmph)->un).echo.id) |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 79 | #define icmpv6_id(icmph) (icmph->icmp6_dataun.u_echo.identifier) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 81 | const char *ip_vs_proto_name(unsigned int proto) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | { |
| 83 | static char buf[20]; |
| 84 | |
| 85 | switch (proto) { |
| 86 | case IPPROTO_IP: |
| 87 | return "IP"; |
| 88 | case IPPROTO_UDP: |
| 89 | return "UDP"; |
| 90 | case IPPROTO_TCP: |
| 91 | return "TCP"; |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 92 | case IPPROTO_SCTP: |
| 93 | return "SCTP"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | case IPPROTO_ICMP: |
| 95 | return "ICMP"; |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 96 | #ifdef CONFIG_IP_VS_IPV6 |
| 97 | case IPPROTO_ICMPV6: |
| 98 | return "ICMPv6"; |
| 99 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | default: |
Masanari Iida | 1404c3a | 2014-04-21 09:16:47 +0900 | [diff] [blame] | 101 | sprintf(buf, "IP_%u", proto); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | return buf; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | void ip_vs_init_hash_table(struct list_head *table, int rows) |
| 107 | { |
| 108 | while (--rows >= 0) |
| 109 | INIT_LIST_HEAD(&table[rows]); |
| 110 | } |
| 111 | |
| 112 | static inline void |
| 113 | ip_vs_in_stats(struct ip_vs_conn *cp, struct sk_buff *skb) |
| 114 | { |
| 115 | struct ip_vs_dest *dest = cp->dest; |
Eric W. Biederman | 7c08d78 | 2015-09-21 13:02:48 -0500 | [diff] [blame] | 116 | struct netns_ipvs *ipvs = cp->ipvs; |
Hans Schillstrom | b17fc99 | 2011-01-03 14:44:56 +0100 | [diff] [blame] | 117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | if (dest && (dest->flags & IP_VS_DEST_F_AVAILABLE)) { |
Hans Schillstrom | b17fc99 | 2011-01-03 14:44:56 +0100 | [diff] [blame] | 119 | struct ip_vs_cpu_stats *s; |
Julian Anastasov | bcbde4c | 2013-09-12 11:21:07 +0300 | [diff] [blame] | 120 | struct ip_vs_service *svc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
Hans Schillstrom | b17fc99 | 2011-01-03 14:44:56 +0100 | [diff] [blame] | 122 | s = this_cpu_ptr(dest->stats.cpustats); |
Hans Schillstrom | b17fc99 | 2011-01-03 14:44:56 +0100 | [diff] [blame] | 123 | u64_stats_update_begin(&s->syncp); |
Julian Anastasov | cd67cd5 | 2015-02-06 09:44:44 +0200 | [diff] [blame] | 124 | s->cnt.inpkts++; |
| 125 | s->cnt.inbytes += skb->len; |
Hans Schillstrom | b17fc99 | 2011-01-03 14:44:56 +0100 | [diff] [blame] | 126 | u64_stats_update_end(&s->syncp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | |
Julian Anastasov | bcbde4c | 2013-09-12 11:21:07 +0300 | [diff] [blame] | 128 | rcu_read_lock(); |
| 129 | svc = rcu_dereference(dest->svc); |
| 130 | s = this_cpu_ptr(svc->stats.cpustats); |
Hans Schillstrom | b17fc99 | 2011-01-03 14:44:56 +0100 | [diff] [blame] | 131 | u64_stats_update_begin(&s->syncp); |
Julian Anastasov | cd67cd5 | 2015-02-06 09:44:44 +0200 | [diff] [blame] | 132 | s->cnt.inpkts++; |
| 133 | s->cnt.inbytes += skb->len; |
Hans Schillstrom | b17fc99 | 2011-01-03 14:44:56 +0100 | [diff] [blame] | 134 | u64_stats_update_end(&s->syncp); |
Julian Anastasov | bcbde4c | 2013-09-12 11:21:07 +0300 | [diff] [blame] | 135 | rcu_read_unlock(); |
Hans Schillstrom | b17fc99 | 2011-01-03 14:44:56 +0100 | [diff] [blame] | 136 | |
Julian Anastasov | 2a0751a | 2011-03-04 12:20:35 +0200 | [diff] [blame] | 137 | s = this_cpu_ptr(ipvs->tot_stats.cpustats); |
Hans Schillstrom | b17fc99 | 2011-01-03 14:44:56 +0100 | [diff] [blame] | 138 | u64_stats_update_begin(&s->syncp); |
Julian Anastasov | cd67cd5 | 2015-02-06 09:44:44 +0200 | [diff] [blame] | 139 | s->cnt.inpkts++; |
| 140 | s->cnt.inbytes += skb->len; |
Hans Schillstrom | b17fc99 | 2011-01-03 14:44:56 +0100 | [diff] [blame] | 141 | u64_stats_update_end(&s->syncp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | } |
| 143 | } |
| 144 | |
| 145 | |
| 146 | static inline void |
| 147 | ip_vs_out_stats(struct ip_vs_conn *cp, struct sk_buff *skb) |
| 148 | { |
| 149 | struct ip_vs_dest *dest = cp->dest; |
Eric W. Biederman | 7c08d78 | 2015-09-21 13:02:48 -0500 | [diff] [blame] | 150 | struct netns_ipvs *ipvs = cp->ipvs; |
Hans Schillstrom | b17fc99 | 2011-01-03 14:44:56 +0100 | [diff] [blame] | 151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | if (dest && (dest->flags & IP_VS_DEST_F_AVAILABLE)) { |
Hans Schillstrom | b17fc99 | 2011-01-03 14:44:56 +0100 | [diff] [blame] | 153 | struct ip_vs_cpu_stats *s; |
Julian Anastasov | bcbde4c | 2013-09-12 11:21:07 +0300 | [diff] [blame] | 154 | struct ip_vs_service *svc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
Hans Schillstrom | b17fc99 | 2011-01-03 14:44:56 +0100 | [diff] [blame] | 156 | s = this_cpu_ptr(dest->stats.cpustats); |
Hans Schillstrom | b17fc99 | 2011-01-03 14:44:56 +0100 | [diff] [blame] | 157 | u64_stats_update_begin(&s->syncp); |
Julian Anastasov | cd67cd5 | 2015-02-06 09:44:44 +0200 | [diff] [blame] | 158 | s->cnt.outpkts++; |
| 159 | s->cnt.outbytes += skb->len; |
Hans Schillstrom | b17fc99 | 2011-01-03 14:44:56 +0100 | [diff] [blame] | 160 | u64_stats_update_end(&s->syncp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
Julian Anastasov | bcbde4c | 2013-09-12 11:21:07 +0300 | [diff] [blame] | 162 | rcu_read_lock(); |
| 163 | svc = rcu_dereference(dest->svc); |
| 164 | s = this_cpu_ptr(svc->stats.cpustats); |
Hans Schillstrom | b17fc99 | 2011-01-03 14:44:56 +0100 | [diff] [blame] | 165 | u64_stats_update_begin(&s->syncp); |
Julian Anastasov | cd67cd5 | 2015-02-06 09:44:44 +0200 | [diff] [blame] | 166 | s->cnt.outpkts++; |
| 167 | s->cnt.outbytes += skb->len; |
Hans Schillstrom | b17fc99 | 2011-01-03 14:44:56 +0100 | [diff] [blame] | 168 | u64_stats_update_end(&s->syncp); |
Julian Anastasov | bcbde4c | 2013-09-12 11:21:07 +0300 | [diff] [blame] | 169 | rcu_read_unlock(); |
Hans Schillstrom | b17fc99 | 2011-01-03 14:44:56 +0100 | [diff] [blame] | 170 | |
Julian Anastasov | 2a0751a | 2011-03-04 12:20:35 +0200 | [diff] [blame] | 171 | s = this_cpu_ptr(ipvs->tot_stats.cpustats); |
Hans Schillstrom | b17fc99 | 2011-01-03 14:44:56 +0100 | [diff] [blame] | 172 | u64_stats_update_begin(&s->syncp); |
Julian Anastasov | cd67cd5 | 2015-02-06 09:44:44 +0200 | [diff] [blame] | 173 | s->cnt.outpkts++; |
| 174 | s->cnt.outbytes += skb->len; |
Hans Schillstrom | b17fc99 | 2011-01-03 14:44:56 +0100 | [diff] [blame] | 175 | u64_stats_update_end(&s->syncp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | } |
| 177 | } |
| 178 | |
| 179 | |
| 180 | static inline void |
| 181 | ip_vs_conn_stats(struct ip_vs_conn *cp, struct ip_vs_service *svc) |
| 182 | { |
Eric W. Biederman | 3109d2f | 2015-09-21 13:01:44 -0500 | [diff] [blame] | 183 | struct netns_ipvs *ipvs = svc->ipvs; |
Hans Schillstrom | b17fc99 | 2011-01-03 14:44:56 +0100 | [diff] [blame] | 184 | struct ip_vs_cpu_stats *s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | |
Hans Schillstrom | b17fc99 | 2011-01-03 14:44:56 +0100 | [diff] [blame] | 186 | s = this_cpu_ptr(cp->dest->stats.cpustats); |
Julian Anastasov | cd67cd5 | 2015-02-06 09:44:44 +0200 | [diff] [blame] | 187 | u64_stats_update_begin(&s->syncp); |
| 188 | s->cnt.conns++; |
| 189 | u64_stats_update_end(&s->syncp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
Hans Schillstrom | b17fc99 | 2011-01-03 14:44:56 +0100 | [diff] [blame] | 191 | s = this_cpu_ptr(svc->stats.cpustats); |
Julian Anastasov | cd67cd5 | 2015-02-06 09:44:44 +0200 | [diff] [blame] | 192 | u64_stats_update_begin(&s->syncp); |
| 193 | s->cnt.conns++; |
| 194 | u64_stats_update_end(&s->syncp); |
Hans Schillstrom | b17fc99 | 2011-01-03 14:44:56 +0100 | [diff] [blame] | 195 | |
Julian Anastasov | 2a0751a | 2011-03-04 12:20:35 +0200 | [diff] [blame] | 196 | s = this_cpu_ptr(ipvs->tot_stats.cpustats); |
Julian Anastasov | cd67cd5 | 2015-02-06 09:44:44 +0200 | [diff] [blame] | 197 | u64_stats_update_begin(&s->syncp); |
| 198 | s->cnt.conns++; |
| 199 | u64_stats_update_end(&s->syncp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | |
Simon Horman | 4a516f1 | 2011-09-16 14:11:49 +0900 | [diff] [blame] | 203 | static inline void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | ip_vs_set_state(struct ip_vs_conn *cp, int direction, |
| 205 | const struct sk_buff *skb, |
Hans Schillstrom | 9330419 | 2011-01-03 14:44:51 +0100 | [diff] [blame] | 206 | struct ip_vs_proto_data *pd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | { |
Simon Horman | 4a516f1 | 2011-09-16 14:11:49 +0900 | [diff] [blame] | 208 | if (likely(pd->pp->state_transition)) |
| 209 | pd->pp->state_transition(cp, direction, skb, pd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Hans Schillstrom | a5959d5 | 2010-11-19 14:25:10 +0100 | [diff] [blame] | 212 | static inline int |
Simon Horman | 8599928 | 2010-08-22 21:37:53 +0900 | [diff] [blame] | 213 | ip_vs_conn_fill_param_persist(const struct ip_vs_service *svc, |
| 214 | struct sk_buff *skb, int protocol, |
| 215 | const union nf_inet_addr *caddr, __be16 cport, |
| 216 | const union nf_inet_addr *vaddr, __be16 vport, |
| 217 | struct ip_vs_conn_param *p) |
| 218 | { |
Eric W. Biederman | 3109d2f | 2015-09-21 13:01:44 -0500 | [diff] [blame] | 219 | ip_vs_conn_fill_param(svc->ipvs, svc->af, protocol, caddr, cport, vaddr, |
Hans Schillstrom | 6e67e58 | 2011-01-03 14:44:57 +0100 | [diff] [blame] | 220 | vport, p); |
Julian Anastasov | ceec4c3 | 2013-03-22 11:46:53 +0200 | [diff] [blame] | 221 | p->pe = rcu_dereference(svc->pe); |
Simon Horman | 8599928 | 2010-08-22 21:37:53 +0900 | [diff] [blame] | 222 | if (p->pe && p->pe->fill_param) |
Hans Schillstrom | a5959d5 | 2010-11-19 14:25:10 +0100 | [diff] [blame] | 223 | return p->pe->fill_param(p, skb); |
| 224 | |
| 225 | return 0; |
Simon Horman | 8599928 | 2010-08-22 21:37:53 +0900 | [diff] [blame] | 226 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | /* |
| 229 | * IPVS persistent scheduling function |
| 230 | * It creates a connection entry according to its template if exists, |
| 231 | * or selects a server and creates a connection entry plus a template. |
| 232 | * Locking: we are svc user (svc->refcnt), so we hold all dests too |
| 233 | * Protocols supported: TCP, UDP |
| 234 | */ |
| 235 | static struct ip_vs_conn * |
| 236 | ip_vs_sched_persist(struct ip_vs_service *svc, |
Jesper Dangaard Brouer | d4383f0 | 2012-09-26 14:07:17 +0200 | [diff] [blame] | 237 | struct sk_buff *skb, __be16 src_port, __be16 dst_port, |
| 238 | int *ignored, struct ip_vs_iphdr *iph) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | { |
| 240 | struct ip_vs_conn *cp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | struct ip_vs_dest *dest; |
| 242 | struct ip_vs_conn *ct; |
Simon Horman | 5b57a98 | 2010-08-22 21:37:51 +0900 | [diff] [blame] | 243 | __be16 dport = 0; /* destination port to forward */ |
Julian Anastasov | 3575792 | 2010-09-17 14:18:16 +0200 | [diff] [blame] | 244 | unsigned int flags; |
Simon Horman | f11017e | 2010-08-22 21:37:52 +0900 | [diff] [blame] | 245 | struct ip_vs_conn_param param; |
Simon Horman | e0aac52 | 2012-01-27 10:45:27 +0900 | [diff] [blame] | 246 | const union nf_inet_addr fwmark = { .ip = htonl(svc->fwmark) }; |
Julius Volz | 28364a5 | 2008-09-02 15:55:43 +0200 | [diff] [blame] | 247 | union nf_inet_addr snet; /* source network of the client, |
| 248 | after masking */ |
Alex Gartrell | ee78378f | 2015-08-26 09:40:33 -0700 | [diff] [blame] | 249 | const union nf_inet_addr *src_addr, *dst_addr; |
| 250 | |
| 251 | if (likely(!ip_vs_iph_inverse(iph))) { |
| 252 | src_addr = &iph->saddr; |
| 253 | dst_addr = &iph->daddr; |
| 254 | } else { |
| 255 | src_addr = &iph->daddr; |
| 256 | dst_addr = &iph->saddr; |
| 257 | } |
| 258 | |
Julius Volz | cd17f9e | 2008-09-02 15:55:46 +0200 | [diff] [blame] | 259 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | /* Mask saddr with the netmask to adjust template granularity */ |
Julius Volz | cd17f9e | 2008-09-02 15:55:46 +0200 | [diff] [blame] | 261 | #ifdef CONFIG_IP_VS_IPV6 |
| 262 | if (svc->af == AF_INET6) |
Alex Gartrell | ee78378f | 2015-08-26 09:40:33 -0700 | [diff] [blame] | 263 | ipv6_addr_prefix(&snet.in6, &src_addr->in6, |
Julian Anastasov | 0a92586 | 2013-04-17 23:50:49 +0300 | [diff] [blame] | 264 | (__force __u32) svc->netmask); |
Julius Volz | cd17f9e | 2008-09-02 15:55:46 +0200 | [diff] [blame] | 265 | else |
| 266 | #endif |
Alex Gartrell | ee78378f | 2015-08-26 09:40:33 -0700 | [diff] [blame] | 267 | snet.ip = src_addr->ip & svc->netmask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | |
Julius Volz | cd17f9e | 2008-09-02 15:55:46 +0200 | [diff] [blame] | 269 | IP_VS_DBG_BUF(6, "p-schedule: src %s:%u dest %s:%u " |
| 270 | "mnet %s\n", |
Alex Gartrell | ee78378f | 2015-08-26 09:40:33 -0700 | [diff] [blame] | 271 | IP_VS_DBG_ADDR(svc->af, src_addr), ntohs(src_port), |
| 272 | IP_VS_DBG_ADDR(svc->af, dst_addr), ntohs(dst_port), |
Julius Volz | cd17f9e | 2008-09-02 15:55:46 +0200 | [diff] [blame] | 273 | IP_VS_DBG_ADDR(svc->af, &snet)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | |
| 275 | /* |
| 276 | * As far as we know, FTP is a very complicated network protocol, and |
| 277 | * it uses control connection and data connections. For active FTP, |
| 278 | * FTP server initialize data connection to the client, its source port |
| 279 | * is often 20. For passive FTP, FTP server tells the clients the port |
| 280 | * that it passively listens to, and the client issues the data |
| 281 | * connection. In the tunneling or direct routing mode, the load |
| 282 | * balancer is on the client-to-server half of connection, the port |
| 283 | * number is unknown to the load balancer. So, a conn template like |
| 284 | * <caddr, 0, vaddr, 0, daddr, 0> is created for persistent FTP |
| 285 | * service, and a template like <caddr, 0, vaddr, vport, daddr, dport> |
| 286 | * is created for other persistent services. |
| 287 | */ |
Simon Horman | 5b57a98 | 2010-08-22 21:37:51 +0900 | [diff] [blame] | 288 | { |
Jesper Dangaard Brouer | d4383f0 | 2012-09-26 14:07:17 +0200 | [diff] [blame] | 289 | int protocol = iph->protocol; |
Alex Gartrell | ee78378f | 2015-08-26 09:40:33 -0700 | [diff] [blame] | 290 | const union nf_inet_addr *vaddr = dst_addr; |
Simon Horman | f11017e | 2010-08-22 21:37:52 +0900 | [diff] [blame] | 291 | __be16 vport = 0; |
| 292 | |
Hans Schillstrom | ce144f2 | 2010-11-19 14:25:08 +0100 | [diff] [blame] | 293 | if (dst_port == svc->port) { |
Simon Horman | 5b57a98 | 2010-08-22 21:37:51 +0900 | [diff] [blame] | 294 | /* non-FTP template: |
| 295 | * <protocol, caddr, 0, vaddr, vport, daddr, dport> |
| 296 | * FTP template: |
| 297 | * <protocol, caddr, 0, vaddr, 0, daddr, 0> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | */ |
| 299 | if (svc->port != FTPPORT) |
Hans Schillstrom | ce144f2 | 2010-11-19 14:25:08 +0100 | [diff] [blame] | 300 | vport = dst_port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | } else { |
Simon Horman | 5b57a98 | 2010-08-22 21:37:51 +0900 | [diff] [blame] | 302 | /* Note: persistent fwmark-based services and |
| 303 | * persistent port zero service are handled here. |
| 304 | * fwmark template: |
| 305 | * <IPPROTO_IP,caddr,0,fwmark,0,daddr,0> |
| 306 | * port zero template: |
| 307 | * <protocol,caddr,0,vaddr,0,daddr,0> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | */ |
Julius Volz | 28364a5 | 2008-09-02 15:55:43 +0200 | [diff] [blame] | 309 | if (svc->fwmark) { |
Simon Horman | 5b57a98 | 2010-08-22 21:37:51 +0900 | [diff] [blame] | 310 | protocol = IPPROTO_IP; |
| 311 | vaddr = &fwmark; |
| 312 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | } |
Hans Schillstrom | a5959d5 | 2010-11-19 14:25:10 +0100 | [diff] [blame] | 314 | /* return *ignored = -1 so NF_DROP can be used */ |
| 315 | if (ip_vs_conn_fill_param_persist(svc, skb, protocol, &snet, 0, |
| 316 | vaddr, vport, ¶m) < 0) { |
| 317 | *ignored = -1; |
| 318 | return NULL; |
| 319 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | } |
| 321 | |
Simon Horman | 5b57a98 | 2010-08-22 21:37:51 +0900 | [diff] [blame] | 322 | /* Check if a template already exists */ |
Simon Horman | f11017e | 2010-08-22 21:37:52 +0900 | [diff] [blame] | 323 | ct = ip_vs_ct_in_get(¶m); |
Marco Angaroni | 3ec10d3 | 2016-05-16 19:18:09 +0200 | [diff] [blame] | 324 | if (!ct || !ip_vs_check_template(ct, NULL)) { |
Julian Anastasov | ceec4c3 | 2013-03-22 11:46:53 +0200 | [diff] [blame] | 325 | struct ip_vs_scheduler *sched; |
| 326 | |
Hans Schillstrom | a5959d5 | 2010-11-19 14:25:10 +0100 | [diff] [blame] | 327 | /* |
| 328 | * No template found or the dest of the connection |
Simon Horman | 5b57a98 | 2010-08-22 21:37:51 +0900 | [diff] [blame] | 329 | * template is not available. |
Hans Schillstrom | a5959d5 | 2010-11-19 14:25:10 +0100 | [diff] [blame] | 330 | * return *ignored=0 i.e. ICMP and NF_DROP |
Simon Horman | 5b57a98 | 2010-08-22 21:37:51 +0900 | [diff] [blame] | 331 | */ |
Julian Anastasov | ceec4c3 | 2013-03-22 11:46:53 +0200 | [diff] [blame] | 332 | sched = rcu_dereference(svc->scheduler); |
Julian Anastasov | 05f0050 | 2015-06-29 21:51:40 +0300 | [diff] [blame] | 333 | if (sched) { |
| 334 | /* read svc->sched_data after svc->scheduler */ |
| 335 | smp_rmb(); |
| 336 | dest = sched->schedule(svc, skb, iph); |
| 337 | } else { |
| 338 | dest = NULL; |
| 339 | } |
Simon Horman | 5b57a98 | 2010-08-22 21:37:51 +0900 | [diff] [blame] | 340 | if (!dest) { |
| 341 | IP_VS_DBG(1, "p-schedule: no dest found.\n"); |
Simon Horman | 8599928 | 2010-08-22 21:37:53 +0900 | [diff] [blame] | 342 | kfree(param.pe_data); |
Hans Schillstrom | a5959d5 | 2010-11-19 14:25:10 +0100 | [diff] [blame] | 343 | *ignored = 0; |
Simon Horman | 5b57a98 | 2010-08-22 21:37:51 +0900 | [diff] [blame] | 344 | return NULL; |
| 345 | } |
| 346 | |
Hans Schillstrom | ce144f2 | 2010-11-19 14:25:08 +0100 | [diff] [blame] | 347 | if (dst_port == svc->port && svc->port != FTPPORT) |
Simon Horman | 5b57a98 | 2010-08-22 21:37:51 +0900 | [diff] [blame] | 348 | dport = dest->port; |
| 349 | |
Simon Horman | 8599928 | 2010-08-22 21:37:53 +0900 | [diff] [blame] | 350 | /* Create a template |
| 351 | * This adds param.pe_data to the template, |
| 352 | * and thus param.pe_data will be destroyed |
| 353 | * when the template expires */ |
Alex Gartrell | ba38528 | 2014-09-09 16:40:23 -0700 | [diff] [blame] | 354 | ct = ip_vs_conn_new(¶m, dest->af, &dest->addr, dport, |
Hans Schillstrom | 0e051e6 | 2010-11-19 14:25:07 +0100 | [diff] [blame] | 355 | IP_VS_CONN_F_TEMPLATE, dest, skb->mark); |
Simon Horman | 8599928 | 2010-08-22 21:37:53 +0900 | [diff] [blame] | 356 | if (ct == NULL) { |
| 357 | kfree(param.pe_data); |
Hans Schillstrom | a5959d5 | 2010-11-19 14:25:10 +0100 | [diff] [blame] | 358 | *ignored = -1; |
Simon Horman | 5b57a98 | 2010-08-22 21:37:51 +0900 | [diff] [blame] | 359 | return NULL; |
Simon Horman | 8599928 | 2010-08-22 21:37:53 +0900 | [diff] [blame] | 360 | } |
Simon Horman | 5b57a98 | 2010-08-22 21:37:51 +0900 | [diff] [blame] | 361 | |
| 362 | ct->timeout = svc->timeout; |
Simon Horman | 8599928 | 2010-08-22 21:37:53 +0900 | [diff] [blame] | 363 | } else { |
Simon Horman | 5b57a98 | 2010-08-22 21:37:51 +0900 | [diff] [blame] | 364 | /* set destination with the found template */ |
| 365 | dest = ct->dest; |
Simon Horman | 8599928 | 2010-08-22 21:37:53 +0900 | [diff] [blame] | 366 | kfree(param.pe_data); |
| 367 | } |
Simon Horman | 5b57a98 | 2010-08-22 21:37:51 +0900 | [diff] [blame] | 368 | |
Hans Schillstrom | ce144f2 | 2010-11-19 14:25:08 +0100 | [diff] [blame] | 369 | dport = dst_port; |
Simon Horman | 5b57a98 | 2010-08-22 21:37:51 +0900 | [diff] [blame] | 370 | if (dport == svc->port && dest->port) |
| 371 | dport = dest->port; |
| 372 | |
Nick Chalk | 26ec037 | 2010-06-22 08:07:01 +0200 | [diff] [blame] | 373 | flags = (svc->flags & IP_VS_SVC_F_ONEPACKET |
Jesper Dangaard Brouer | d4383f0 | 2012-09-26 14:07:17 +0200 | [diff] [blame] | 374 | && iph->protocol == IPPROTO_UDP) ? |
Nick Chalk | 26ec037 | 2010-06-22 08:07:01 +0200 | [diff] [blame] | 375 | IP_VS_CONN_F_ONE_PACKET : 0; |
| 376 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | /* |
| 378 | * Create a new connection according to the template |
| 379 | */ |
Eric W. Biederman | 3109d2f | 2015-09-21 13:01:44 -0500 | [diff] [blame] | 380 | ip_vs_conn_fill_param(svc->ipvs, svc->af, iph->protocol, src_addr, |
Alex Gartrell | ee78378f | 2015-08-26 09:40:33 -0700 | [diff] [blame] | 381 | src_port, dst_addr, dst_port, ¶m); |
Hans Schillstrom | ce144f2 | 2010-11-19 14:25:08 +0100 | [diff] [blame] | 382 | |
Alex Gartrell | ba38528 | 2014-09-09 16:40:23 -0700 | [diff] [blame] | 383 | cp = ip_vs_conn_new(¶m, dest->af, &dest->addr, dport, flags, dest, |
| 384 | skb->mark); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | if (cp == NULL) { |
| 386 | ip_vs_conn_put(ct); |
Hans Schillstrom | a5959d5 | 2010-11-19 14:25:10 +0100 | [diff] [blame] | 387 | *ignored = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | return NULL; |
| 389 | } |
| 390 | |
| 391 | /* |
| 392 | * Add its control |
| 393 | */ |
| 394 | ip_vs_control_add(cp, ct); |
| 395 | ip_vs_conn_put(ct); |
| 396 | |
| 397 | ip_vs_conn_stats(cp, svc); |
| 398 | return cp; |
| 399 | } |
| 400 | |
| 401 | |
| 402 | /* |
| 403 | * IPVS main scheduling function |
| 404 | * It selects a server according to the virtual service, and |
| 405 | * creates a connection entry. |
| 406 | * Protocols supported: TCP, UDP |
Hans Schillstrom | a5959d5 | 2010-11-19 14:25:10 +0100 | [diff] [blame] | 407 | * |
| 408 | * Usage of *ignored |
| 409 | * |
| 410 | * 1 : protocol tried to schedule (eg. on SYN), found svc but the |
| 411 | * svc/scheduler decides that this packet should be accepted with |
| 412 | * NF_ACCEPT because it must not be scheduled. |
| 413 | * |
| 414 | * 0 : scheduler can not find destination, so try bypass or |
| 415 | * return ICMP and then NF_DROP (ip_vs_leave). |
| 416 | * |
| 417 | * -1 : scheduler tried to schedule but fatal error occurred, eg. |
| 418 | * ip_vs_conn_new failure (ENOMEM) or ip_vs_sip_fill_param |
| 419 | * failure such as missing Call-ID, ENOMEM on skb_linearize |
| 420 | * or pe_data. In this case we should return NF_DROP without |
| 421 | * any attempts to send ICMP with ip_vs_leave. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | */ |
| 423 | struct ip_vs_conn * |
Julian Anastasov | 190ecd2 | 2010-10-17 16:24:37 +0300 | [diff] [blame] | 424 | ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb, |
Jesper Dangaard Brouer | d4383f0 | 2012-09-26 14:07:17 +0200 | [diff] [blame] | 425 | struct ip_vs_proto_data *pd, int *ignored, |
| 426 | struct ip_vs_iphdr *iph) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | { |
Hans Schillstrom | 9330419 | 2011-01-03 14:44:51 +0100 | [diff] [blame] | 428 | struct ip_vs_protocol *pp = pd->pp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | struct ip_vs_conn *cp = NULL; |
Julian Anastasov | ceec4c3 | 2013-03-22 11:46:53 +0200 | [diff] [blame] | 430 | struct ip_vs_scheduler *sched; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | struct ip_vs_dest *dest; |
Alex Gartrell | ee78378f | 2015-08-26 09:40:33 -0700 | [diff] [blame] | 432 | __be16 _ports[2], *pptr, cport, vport; |
| 433 | const void *caddr, *vaddr; |
Julian Anastasov | 3575792 | 2010-09-17 14:18:16 +0200 | [diff] [blame] | 434 | unsigned int flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | |
Julian Anastasov | 190ecd2 | 2010-10-17 16:24:37 +0300 | [diff] [blame] | 436 | *ignored = 1; |
Jesper Dangaard Brouer | 2f74713 | 2012-09-26 14:06:59 +0200 | [diff] [blame] | 437 | /* |
| 438 | * IPv6 frags, only the first hit here. |
| 439 | */ |
Jesper Dangaard Brouer | d4383f0 | 2012-09-26 14:07:17 +0200 | [diff] [blame] | 440 | pptr = frag_safe_skb_hp(skb, iph->len, sizeof(_ports), _ports, iph); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | if (pptr == NULL) |
| 442 | return NULL; |
| 443 | |
Alex Gartrell | ee78378f | 2015-08-26 09:40:33 -0700 | [diff] [blame] | 444 | if (likely(!ip_vs_iph_inverse(iph))) { |
| 445 | cport = pptr[0]; |
| 446 | caddr = &iph->saddr; |
| 447 | vport = pptr[1]; |
| 448 | vaddr = &iph->daddr; |
| 449 | } else { |
| 450 | cport = pptr[1]; |
| 451 | caddr = &iph->daddr; |
| 452 | vport = pptr[0]; |
| 453 | vaddr = &iph->saddr; |
| 454 | } |
| 455 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | /* |
Julian Anastasov | 190ecd2 | 2010-10-17 16:24:37 +0300 | [diff] [blame] | 457 | * FTPDATA needs this check when using local real server. |
| 458 | * Never schedule Active FTPDATA connections from real server. |
| 459 | * For LVS-NAT they must be already created. For other methods |
| 460 | * with persistence the connection is created on SYN+ACK. |
| 461 | */ |
Alex Gartrell | ee78378f | 2015-08-26 09:40:33 -0700 | [diff] [blame] | 462 | if (cport == FTPDATA) { |
Alex Gartrell | b0e010c | 2015-08-26 09:40:28 -0700 | [diff] [blame] | 463 | IP_VS_DBG_PKT(12, svc->af, pp, skb, iph->off, |
Julian Anastasov | 0d79641 | 2010-10-17 16:46:17 +0300 | [diff] [blame] | 464 | "Not scheduling FTPDATA"); |
Julian Anastasov | 190ecd2 | 2010-10-17 16:24:37 +0300 | [diff] [blame] | 465 | return NULL; |
| 466 | } |
| 467 | |
| 468 | /* |
Hans Schillstrom | a5959d5 | 2010-11-19 14:25:10 +0100 | [diff] [blame] | 469 | * Do not schedule replies from local real server. |
Julian Anastasov | 190ecd2 | 2010-10-17 16:24:37 +0300 | [diff] [blame] | 470 | */ |
Alex Gartrell | 802c41a | 2015-08-26 09:40:32 -0700 | [diff] [blame] | 471 | if ((!skb->dev || skb->dev->flags & IFF_LOOPBACK)) { |
| 472 | iph->hdr_flags ^= IP_VS_HDR_INVERSE; |
Eric W. Biederman | ab16197 | 2015-09-21 13:02:38 -0500 | [diff] [blame] | 473 | cp = pp->conn_in_get(svc->ipvs, svc->af, skb, iph); |
Alex Gartrell | 802c41a | 2015-08-26 09:40:32 -0700 | [diff] [blame] | 474 | iph->hdr_flags ^= IP_VS_HDR_INVERSE; |
| 475 | |
| 476 | if (cp) { |
| 477 | IP_VS_DBG_PKT(12, svc->af, pp, skb, iph->off, |
| 478 | "Not scheduling reply for existing" |
| 479 | " connection"); |
| 480 | __ip_vs_conn_put(cp); |
| 481 | return NULL; |
| 482 | } |
Julian Anastasov | 190ecd2 | 2010-10-17 16:24:37 +0300 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | * Persistent service |
| 487 | */ |
Hans Schillstrom | a5959d5 | 2010-11-19 14:25:10 +0100 | [diff] [blame] | 488 | if (svc->flags & IP_VS_SVC_F_PERSISTENT) |
Alex Gartrell | ee78378f | 2015-08-26 09:40:33 -0700 | [diff] [blame] | 489 | return ip_vs_sched_persist(svc, skb, cport, vport, ignored, |
Jesper Dangaard Brouer | d4383f0 | 2012-09-26 14:07:17 +0200 | [diff] [blame] | 490 | iph); |
Hans Schillstrom | a5959d5 | 2010-11-19 14:25:10 +0100 | [diff] [blame] | 491 | |
| 492 | *ignored = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | |
| 494 | /* |
| 495 | * Non-persistent service |
| 496 | */ |
Alex Gartrell | ee78378f | 2015-08-26 09:40:33 -0700 | [diff] [blame] | 497 | if (!svc->fwmark && vport != svc->port) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | if (!svc->port) |
Hannes Eder | 1e3e238 | 2009-08-02 11:05:41 +0000 | [diff] [blame] | 499 | pr_err("Schedule: port zero only supported " |
| 500 | "in persistent services, " |
| 501 | "check your ipvs configuration\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | return NULL; |
| 503 | } |
| 504 | |
Julian Anastasov | ceec4c3 | 2013-03-22 11:46:53 +0200 | [diff] [blame] | 505 | sched = rcu_dereference(svc->scheduler); |
Julian Anastasov | 05f0050 | 2015-06-29 21:51:40 +0300 | [diff] [blame] | 506 | if (sched) { |
| 507 | /* read svc->sched_data after svc->scheduler */ |
| 508 | smp_rmb(); |
| 509 | dest = sched->schedule(svc, skb, iph); |
| 510 | } else { |
| 511 | dest = NULL; |
| 512 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | if (dest == NULL) { |
| 514 | IP_VS_DBG(1, "Schedule: no dest found.\n"); |
| 515 | return NULL; |
| 516 | } |
| 517 | |
Nick Chalk | 26ec037 | 2010-06-22 08:07:01 +0200 | [diff] [blame] | 518 | flags = (svc->flags & IP_VS_SVC_F_ONEPACKET |
Jesper Dangaard Brouer | d4383f0 | 2012-09-26 14:07:17 +0200 | [diff] [blame] | 519 | && iph->protocol == IPPROTO_UDP) ? |
Nick Chalk | 26ec037 | 2010-06-22 08:07:01 +0200 | [diff] [blame] | 520 | IP_VS_CONN_F_ONE_PACKET : 0; |
| 521 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | /* |
| 523 | * Create a connection entry. |
| 524 | */ |
Simon Horman | f11017e | 2010-08-22 21:37:52 +0900 | [diff] [blame] | 525 | { |
| 526 | struct ip_vs_conn_param p; |
Hans Schillstrom | 6e67e58 | 2011-01-03 14:44:57 +0100 | [diff] [blame] | 527 | |
Eric W. Biederman | 3109d2f | 2015-09-21 13:01:44 -0500 | [diff] [blame] | 528 | ip_vs_conn_fill_param(svc->ipvs, svc->af, iph->protocol, |
Alex Gartrell | ee78378f | 2015-08-26 09:40:33 -0700 | [diff] [blame] | 529 | caddr, cport, vaddr, vport, &p); |
Alex Gartrell | ba38528 | 2014-09-09 16:40:23 -0700 | [diff] [blame] | 530 | cp = ip_vs_conn_new(&p, dest->af, &dest->addr, |
Alex Gartrell | ee78378f | 2015-08-26 09:40:33 -0700 | [diff] [blame] | 531 | dest->port ? dest->port : vport, |
Hans Schillstrom | 0e051e6 | 2010-11-19 14:25:07 +0100 | [diff] [blame] | 532 | flags, dest, skb->mark); |
Hans Schillstrom | a5959d5 | 2010-11-19 14:25:10 +0100 | [diff] [blame] | 533 | if (!cp) { |
| 534 | *ignored = -1; |
Simon Horman | f11017e | 2010-08-22 21:37:52 +0900 | [diff] [blame] | 535 | return NULL; |
Hans Schillstrom | a5959d5 | 2010-11-19 14:25:10 +0100 | [diff] [blame] | 536 | } |
Simon Horman | f11017e | 2010-08-22 21:37:52 +0900 | [diff] [blame] | 537 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | |
Julius Volz | cd17f9e | 2008-09-02 15:55:46 +0200 | [diff] [blame] | 539 | IP_VS_DBG_BUF(6, "Schedule fwd:%c c:%s:%u v:%s:%u " |
| 540 | "d:%s:%u conn->flags:%X conn->refcnt:%d\n", |
| 541 | ip_vs_fwd_tag(cp), |
Julian Anastasov | f18ae72 | 2014-09-09 16:40:38 -0700 | [diff] [blame] | 542 | IP_VS_DBG_ADDR(cp->af, &cp->caddr), ntohs(cp->cport), |
| 543 | IP_VS_DBG_ADDR(cp->af, &cp->vaddr), ntohs(cp->vport), |
| 544 | IP_VS_DBG_ADDR(cp->daf, &cp->daddr), ntohs(cp->dport), |
Julius Volz | cd17f9e | 2008-09-02 15:55:46 +0200 | [diff] [blame] | 545 | cp->flags, atomic_read(&cp->refcnt)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | |
| 547 | ip_vs_conn_stats(cp, svc); |
| 548 | return cp; |
| 549 | } |
| 550 | |
Alex Gartrell | 0b72902 | 2015-08-26 09:40:30 -0700 | [diff] [blame] | 551 | static inline int ip_vs_addr_is_unicast(struct net *net, int af, |
| 552 | union nf_inet_addr *addr) |
| 553 | { |
| 554 | #ifdef CONFIG_IP_VS_IPV6 |
| 555 | if (af == AF_INET6) |
| 556 | return ipv6_addr_type(&addr->in6) & IPV6_ADDR_UNICAST; |
| 557 | #endif |
| 558 | return (inet_addr_type(net, addr->ip) == RTN_UNICAST); |
| 559 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | |
| 561 | /* |
| 562 | * Pass or drop the packet. |
| 563 | * Called by ip_vs_in, when the virtual service is available but |
| 564 | * no destination is available for a new connection. |
| 565 | */ |
| 566 | int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb, |
Jesper Dangaard Brouer | d4383f0 | 2012-09-26 14:07:17 +0200 | [diff] [blame] | 567 | struct ip_vs_proto_data *pd, struct ip_vs_iphdr *iph) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | { |
Alex Gartrell | 0b72902 | 2015-08-26 09:40:30 -0700 | [diff] [blame] | 569 | __be16 _ports[2], *pptr, dport; |
Eric W. Biederman | 51efbcb | 2015-09-21 13:02:50 -0500 | [diff] [blame] | 570 | struct netns_ipvs *ipvs = svc->ipvs; |
| 571 | struct net *net = ipvs->net; |
Hans Schillstrom | 9330419 | 2011-01-03 14:44:51 +0100 | [diff] [blame] | 572 | |
Jesper Dangaard Brouer | d4383f0 | 2012-09-26 14:07:17 +0200 | [diff] [blame] | 573 | pptr = frag_safe_skb_hp(skb, iph->len, sizeof(_ports), _ports, iph); |
Alex Gartrell | 0b72902 | 2015-08-26 09:40:30 -0700 | [diff] [blame] | 574 | if (!pptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | return NF_DROP; |
Alex Gartrell | 0b72902 | 2015-08-26 09:40:30 -0700 | [diff] [blame] | 576 | dport = likely(!ip_vs_iph_inverse(iph)) ? pptr[1] : pptr[0]; |
Simon Horman | a7a86b8 | 2011-02-04 18:33:02 +0900 | [diff] [blame] | 577 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | /* if it is fwmark-based service, the cache_bypass sysctl is up |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 579 | and the destination is a non-local unicast, then create |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | a cache_bypass connection entry */ |
Eric W. Biederman | 5703294 | 2015-09-21 13:02:49 -0500 | [diff] [blame] | 581 | if (sysctl_cache_bypass(ipvs) && svc->fwmark && |
Alex Gartrell | 0b72902 | 2015-08-26 09:40:30 -0700 | [diff] [blame] | 582 | !(iph->hdr_flags & (IP_VS_HDR_INVERSE | IP_VS_HDR_ICMP)) && |
| 583 | ip_vs_addr_is_unicast(net, svc->af, &iph->daddr)) { |
Krzysztof Wilczynski | ad542ced | 2011-10-18 20:59:49 +0100 | [diff] [blame] | 584 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | struct ip_vs_conn *cp; |
Julian Anastasov | 3575792 | 2010-09-17 14:18:16 +0200 | [diff] [blame] | 586 | unsigned int flags = (svc->flags & IP_VS_SVC_F_ONEPACKET && |
Jesper Dangaard Brouer | d4383f0 | 2012-09-26 14:07:17 +0200 | [diff] [blame] | 587 | iph->protocol == IPPROTO_UDP) ? |
Julian Anastasov | 3575792 | 2010-09-17 14:18:16 +0200 | [diff] [blame] | 588 | IP_VS_CONN_F_ONE_PACKET : 0; |
Simon Horman | dff630d | 2008-09-17 10:10:42 +1000 | [diff] [blame] | 589 | union nf_inet_addr daddr = { .all = { 0, 0, 0, 0 } }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | /* create a new connection entry */ |
Hannes Eder | 1e3e238 | 2009-08-02 11:05:41 +0000 | [diff] [blame] | 592 | IP_VS_DBG(6, "%s(): create a cache_bypass entry\n", __func__); |
Simon Horman | f11017e | 2010-08-22 21:37:52 +0900 | [diff] [blame] | 593 | { |
| 594 | struct ip_vs_conn_param p; |
Eric W. Biederman | 3109d2f | 2015-09-21 13:01:44 -0500 | [diff] [blame] | 595 | ip_vs_conn_fill_param(svc->ipvs, svc->af, iph->protocol, |
Jesper Dangaard Brouer | d4383f0 | 2012-09-26 14:07:17 +0200 | [diff] [blame] | 596 | &iph->saddr, pptr[0], |
| 597 | &iph->daddr, pptr[1], &p); |
Alex Gartrell | ba38528 | 2014-09-09 16:40:23 -0700 | [diff] [blame] | 598 | cp = ip_vs_conn_new(&p, svc->af, &daddr, 0, |
Simon Horman | f11017e | 2010-08-22 21:37:52 +0900 | [diff] [blame] | 599 | IP_VS_CONN_F_BYPASS | flags, |
Hans Schillstrom | 0e051e6 | 2010-11-19 14:25:07 +0100 | [diff] [blame] | 600 | NULL, skb->mark); |
Simon Horman | f11017e | 2010-08-22 21:37:52 +0900 | [diff] [blame] | 601 | if (!cp) |
| 602 | return NF_DROP; |
| 603 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | |
| 605 | /* statistics */ |
| 606 | ip_vs_in_stats(cp, skb); |
| 607 | |
| 608 | /* set state */ |
Simon Horman | 4a516f1 | 2011-09-16 14:11:49 +0900 | [diff] [blame] | 609 | ip_vs_set_state(cp, IP_VS_DIR_INPUT, skb, pd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | |
| 611 | /* transmit the first SYN packet */ |
Jesper Dangaard Brouer | d4383f0 | 2012-09-26 14:07:17 +0200 | [diff] [blame] | 612 | ret = cp->packet_xmit(skb, cp, pd->pp, iph); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | /* do not touch skb anymore */ |
| 614 | |
Marco Angaroni | 698e2a8 | 2016-04-26 21:20:22 +0200 | [diff] [blame] | 615 | if ((cp->flags & IP_VS_CONN_F_ONE_PACKET) && cp->control) |
| 616 | atomic_inc(&cp->control->in_pkts); |
| 617 | else |
| 618 | atomic_inc(&cp->in_pkts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | ip_vs_conn_put(cp); |
| 620 | return ret; |
| 621 | } |
| 622 | |
| 623 | /* |
| 624 | * When the virtual ftp service is presented, packets destined |
| 625 | * for other services on the VIP may get here (except services |
| 626 | * listed in the ipvs table), pass the packets, because it is |
| 627 | * not ipvs job to decide to drop the packets. |
| 628 | */ |
Alex Gartrell | 0b72902 | 2015-08-26 09:40:30 -0700 | [diff] [blame] | 629 | if (svc->port == FTPPORT && dport != FTPPORT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | return NF_ACCEPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | |
Alex Gartrell | 0b72902 | 2015-08-26 09:40:30 -0700 | [diff] [blame] | 632 | if (unlikely(ip_vs_iph_icmp(iph))) |
| 633 | return NF_DROP; |
| 634 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | /* |
| 636 | * Notify the client that the destination is unreachable, and |
| 637 | * release the socket buffer. |
| 638 | * Since it is in IP layer, the TCP socket is not actually |
| 639 | * created, the TCP RST packet cannot be sent, instead that |
| 640 | * ICMP_PORT_UNREACH is sent here no matter it is TCP/UDP. --WZ |
| 641 | */ |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 642 | #ifdef CONFIG_IP_VS_IPV6 |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 643 | if (svc->af == AF_INET6) { |
Eric W. Biederman | 5703294 | 2015-09-21 13:02:49 -0500 | [diff] [blame] | 644 | if (!skb->dev) |
| 645 | skb->dev = net->loopback_dev; |
Alexey Dobriyan | 3ffe533 | 2010-02-18 08:25:24 +0000 | [diff] [blame] | 646 | icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0); |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 647 | } else |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 648 | #endif |
| 649 | icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0); |
| 650 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | return NF_DROP; |
| 652 | } |
| 653 | |
Simon Horman | 84b3cee | 2011-02-04 18:33:01 +0900 | [diff] [blame] | 654 | #ifdef CONFIG_SYSCTL |
| 655 | |
Eric W. Biederman | a43d1a6 | 2015-09-21 13:02:56 -0500 | [diff] [blame] | 656 | static int sysctl_snat_reroute(struct netns_ipvs *ipvs) |
Simon Horman | 84b3cee | 2011-02-04 18:33:01 +0900 | [diff] [blame] | 657 | { |
Simon Horman | 84b3cee | 2011-02-04 18:33:01 +0900 | [diff] [blame] | 658 | return ipvs->sysctl_snat_reroute; |
| 659 | } |
| 660 | |
Eric W. Biederman | 2300f04 | 2015-09-21 13:02:51 -0500 | [diff] [blame] | 661 | static int sysctl_nat_icmp_send(struct netns_ipvs *ipvs) |
Simon Horman | 0cfa558 | 2011-02-04 18:33:01 +0900 | [diff] [blame] | 662 | { |
Simon Horman | 0cfa558 | 2011-02-04 18:33:01 +0900 | [diff] [blame] | 663 | return ipvs->sysctl_nat_icmp_send; |
| 664 | } |
| 665 | |
Simon Horman | 71a8ab6 | 2011-02-04 18:33:01 +0900 | [diff] [blame] | 666 | static int sysctl_expire_nodest_conn(struct netns_ipvs *ipvs) |
| 667 | { |
| 668 | return ipvs->sysctl_expire_nodest_conn; |
| 669 | } |
| 670 | |
Simon Horman | 84b3cee | 2011-02-04 18:33:01 +0900 | [diff] [blame] | 671 | #else |
| 672 | |
Eric W. Biederman | a43d1a6 | 2015-09-21 13:02:56 -0500 | [diff] [blame] | 673 | static int sysctl_snat_reroute(struct netns_ipvs *ipvs) { return 0; } |
Eric W. Biederman | 2300f04 | 2015-09-21 13:02:51 -0500 | [diff] [blame] | 674 | static int sysctl_nat_icmp_send(struct netns_ipvs *ipvs) { return 0; } |
Simon Horman | 71a8ab6 | 2011-02-04 18:33:01 +0900 | [diff] [blame] | 675 | static int sysctl_expire_nodest_conn(struct netns_ipvs *ipvs) { return 0; } |
Simon Horman | 84b3cee | 2011-02-04 18:33:01 +0900 | [diff] [blame] | 676 | |
| 677 | #endif |
| 678 | |
Al Viro | b1550f2 | 2006-11-14 21:37:50 -0800 | [diff] [blame] | 679 | __sum16 ip_vs_checksum_complete(struct sk_buff *skb, int offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | { |
Al Viro | d3bc23e | 2006-11-14 21:24:49 -0800 | [diff] [blame] | 681 | return csum_fold(skb_checksum(skb, offset, skb->len - offset, 0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | } |
| 683 | |
Julian Anastasov | 1ca5bb5 | 2010-10-17 16:32:29 +0300 | [diff] [blame] | 684 | static inline enum ip_defrag_users ip_vs_defrag_user(unsigned int hooknum) |
| 685 | { |
| 686 | if (NF_INET_LOCAL_IN == hooknum) |
| 687 | return IP_DEFRAG_VS_IN; |
| 688 | if (NF_INET_FORWARD == hooknum) |
| 689 | return IP_DEFRAG_VS_FWD; |
| 690 | return IP_DEFRAG_VS_OUT; |
| 691 | } |
| 692 | |
Eric W. Biederman | 57781c1 | 2015-09-21 13:03:01 -0500 | [diff] [blame] | 693 | static inline int ip_vs_gather_frags(struct netns_ipvs *ipvs, |
| 694 | struct sk_buff *skb, u_int32_t user) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | { |
Julian Anastasov | ac69269 | 2013-03-22 11:46:54 +0200 | [diff] [blame] | 696 | int err; |
Herbert Xu | 776c729 | 2007-10-14 00:38:32 -0700 | [diff] [blame] | 697 | |
Julian Anastasov | ac69269 | 2013-03-22 11:46:54 +0200 | [diff] [blame] | 698 | local_bh_disable(); |
Eric W. Biederman | 19bcf9f | 2015-10-09 13:44:54 -0500 | [diff] [blame] | 699 | err = ip_defrag(ipvs->net, skb, user); |
Julian Anastasov | ac69269 | 2013-03-22 11:46:54 +0200 | [diff] [blame] | 700 | local_bh_enable(); |
Herbert Xu | 776c729 | 2007-10-14 00:38:32 -0700 | [diff] [blame] | 701 | if (!err) |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 702 | ip_send_check(ip_hdr(skb)); |
Herbert Xu | 776c729 | 2007-10-14 00:38:32 -0700 | [diff] [blame] | 703 | |
| 704 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | } |
| 706 | |
Eric W. Biederman | a43d1a6 | 2015-09-21 13:02:56 -0500 | [diff] [blame] | 707 | static int ip_vs_route_me_harder(struct netns_ipvs *ipvs, int af, |
| 708 | struct sk_buff *skb, unsigned int hooknum) |
Simon Horman | ba4fd7e | 2011-02-04 18:33:01 +0900 | [diff] [blame] | 709 | { |
Eric W. Biederman | a43d1a6 | 2015-09-21 13:02:56 -0500 | [diff] [blame] | 710 | if (!sysctl_snat_reroute(ipvs)) |
Julian Anastasov | 579eb62 | 2014-12-18 22:41:23 +0200 | [diff] [blame] | 711 | return 0; |
| 712 | /* Reroute replies only to remote clients (FORWARD and LOCAL_OUT) */ |
| 713 | if (NF_INET_LOCAL_IN == hooknum) |
| 714 | return 0; |
Simon Horman | ba4fd7e | 2011-02-04 18:33:01 +0900 | [diff] [blame] | 715 | #ifdef CONFIG_IP_VS_IPV6 |
| 716 | if (af == AF_INET6) { |
Julian Anastasov | 579eb62 | 2014-12-18 22:41:23 +0200 | [diff] [blame] | 717 | struct dst_entry *dst = skb_dst(skb); |
| 718 | |
| 719 | if (dst->dev && !(dst->dev->flags & IFF_LOOPBACK) && |
Eric W. Biederman | 5f5d74d | 2015-09-25 15:07:31 -0500 | [diff] [blame] | 720 | ip6_route_me_harder(ipvs->net, skb) != 0) |
Simon Horman | ba4fd7e | 2011-02-04 18:33:01 +0900 | [diff] [blame] | 721 | return 1; |
| 722 | } else |
| 723 | #endif |
Julian Anastasov | 579eb62 | 2014-12-18 22:41:23 +0200 | [diff] [blame] | 724 | if (!(skb_rtable(skb)->rt_flags & RTCF_LOCAL) && |
Eric W. Biederman | e45f506 | 2015-09-25 15:07:30 -0500 | [diff] [blame] | 725 | ip_route_me_harder(ipvs->net, skb, RTN_LOCAL) != 0) |
Simon Horman | ba4fd7e | 2011-02-04 18:33:01 +0900 | [diff] [blame] | 726 | return 1; |
| 727 | |
| 728 | return 0; |
| 729 | } |
| 730 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | /* |
| 732 | * Packet has been made sufficiently writable in caller |
| 733 | * - inout: 1=in->out, 0=out->in |
| 734 | */ |
| 735 | void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp, |
| 736 | struct ip_vs_conn *cp, int inout) |
| 737 | { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 738 | struct iphdr *iph = ip_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | unsigned int icmp_offset = iph->ihl*4; |
Arnaldo Carvalho de Melo | d56f90a | 2007-04-10 20:50:43 -0700 | [diff] [blame] | 740 | struct icmphdr *icmph = (struct icmphdr *)(skb_network_header(skb) + |
| 741 | icmp_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | struct iphdr *ciph = (struct iphdr *)(icmph + 1); |
| 743 | |
| 744 | if (inout) { |
Julius Volz | e7ade46 | 2008-09-02 15:55:33 +0200 | [diff] [blame] | 745 | iph->saddr = cp->vaddr.ip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | ip_send_check(iph); |
Julius Volz | e7ade46 | 2008-09-02 15:55:33 +0200 | [diff] [blame] | 747 | ciph->daddr = cp->vaddr.ip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | ip_send_check(ciph); |
| 749 | } else { |
Julius Volz | e7ade46 | 2008-09-02 15:55:33 +0200 | [diff] [blame] | 750 | iph->daddr = cp->daddr.ip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | ip_send_check(iph); |
Julius Volz | e7ade46 | 2008-09-02 15:55:33 +0200 | [diff] [blame] | 752 | ciph->saddr = cp->daddr.ip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | ip_send_check(ciph); |
| 754 | } |
| 755 | |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 756 | /* the TCP/UDP/SCTP port */ |
| 757 | if (IPPROTO_TCP == ciph->protocol || IPPROTO_UDP == ciph->protocol || |
| 758 | IPPROTO_SCTP == ciph->protocol) { |
Al Viro | 014d730 | 2006-09-28 14:29:52 -0700 | [diff] [blame] | 759 | __be16 *ports = (void *)ciph + ciph->ihl*4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | |
| 761 | if (inout) |
| 762 | ports[1] = cp->vport; |
| 763 | else |
| 764 | ports[0] = cp->dport; |
| 765 | } |
| 766 | |
| 767 | /* And finally the ICMP checksum */ |
| 768 | icmph->checksum = 0; |
| 769 | icmph->checksum = ip_vs_checksum_complete(skb, icmp_offset); |
| 770 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 771 | |
| 772 | if (inout) |
Julian Anastasov | 0d79641 | 2010-10-17 16:46:17 +0300 | [diff] [blame] | 773 | IP_VS_DBG_PKT(11, AF_INET, pp, skb, (void *)ciph - (void *)iph, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | "Forwarding altered outgoing ICMP"); |
| 775 | else |
Julian Anastasov | 0d79641 | 2010-10-17 16:46:17 +0300 | [diff] [blame] | 776 | IP_VS_DBG_PKT(11, AF_INET, pp, skb, (void *)ciph - (void *)iph, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | "Forwarding altered incoming ICMP"); |
| 778 | } |
| 779 | |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 780 | #ifdef CONFIG_IP_VS_IPV6 |
| 781 | void ip_vs_nat_icmp_v6(struct sk_buff *skb, struct ip_vs_protocol *pp, |
| 782 | struct ip_vs_conn *cp, int inout) |
| 783 | { |
| 784 | struct ipv6hdr *iph = ipv6_hdr(skb); |
Jesper Dangaard Brouer | 63dca2c | 2012-09-26 14:06:41 +0200 | [diff] [blame] | 785 | unsigned int icmp_offset = 0; |
| 786 | unsigned int offs = 0; /* header offset*/ |
| 787 | int protocol; |
| 788 | struct icmp6hdr *icmph; |
| 789 | struct ipv6hdr *ciph; |
| 790 | unsigned short fragoffs; |
| 791 | |
| 792 | ipv6_find_hdr(skb, &icmp_offset, IPPROTO_ICMPV6, &fragoffs, NULL); |
| 793 | icmph = (struct icmp6hdr *)(skb_network_header(skb) + icmp_offset); |
| 794 | offs = icmp_offset + sizeof(struct icmp6hdr); |
| 795 | ciph = (struct ipv6hdr *)(skb_network_header(skb) + offs); |
| 796 | |
| 797 | protocol = ipv6_find_hdr(skb, &offs, -1, &fragoffs, NULL); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 798 | |
| 799 | if (inout) { |
| 800 | iph->saddr = cp->vaddr.in6; |
| 801 | ciph->daddr = cp->vaddr.in6; |
| 802 | } else { |
| 803 | iph->daddr = cp->daddr.in6; |
| 804 | ciph->saddr = cp->daddr.in6; |
| 805 | } |
| 806 | |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 807 | /* the TCP/UDP/SCTP port */ |
Jesper Dangaard Brouer | 63dca2c | 2012-09-26 14:06:41 +0200 | [diff] [blame] | 808 | if (!fragoffs && (IPPROTO_TCP == protocol || IPPROTO_UDP == protocol || |
| 809 | IPPROTO_SCTP == protocol)) { |
| 810 | __be16 *ports = (void *)(skb_network_header(skb) + offs); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 811 | |
Jesper Dangaard Brouer | 63dca2c | 2012-09-26 14:06:41 +0200 | [diff] [blame] | 812 | IP_VS_DBG(11, "%s() changed port %d to %d\n", __func__, |
| 813 | ntohs(inout ? ports[1] : ports[0]), |
| 814 | ntohs(inout ? cp->vport : cp->dport)); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 815 | if (inout) |
| 816 | ports[1] = cp->vport; |
| 817 | else |
| 818 | ports[0] = cp->dport; |
| 819 | } |
| 820 | |
| 821 | /* And finally the ICMP checksum */ |
Simon Horman | 8870f84 | 2010-08-26 13:21:26 -0700 | [diff] [blame] | 822 | icmph->icmp6_cksum = ~csum_ipv6_magic(&iph->saddr, &iph->daddr, |
| 823 | skb->len - icmp_offset, |
| 824 | IPPROTO_ICMPV6, 0); |
| 825 | skb->csum_start = skb_network_header(skb) - skb->head + icmp_offset; |
| 826 | skb->csum_offset = offsetof(struct icmp6hdr, icmp6_cksum); |
| 827 | skb->ip_summed = CHECKSUM_PARTIAL; |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 828 | |
| 829 | if (inout) |
Julian Anastasov | 0d79641 | 2010-10-17 16:46:17 +0300 | [diff] [blame] | 830 | IP_VS_DBG_PKT(11, AF_INET6, pp, skb, |
| 831 | (void *)ciph - (void *)iph, |
| 832 | "Forwarding altered outgoing ICMPv6"); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 833 | else |
Julian Anastasov | 0d79641 | 2010-10-17 16:46:17 +0300 | [diff] [blame] | 834 | IP_VS_DBG_PKT(11, AF_INET6, pp, skb, |
| 835 | (void *)ciph - (void *)iph, |
| 836 | "Forwarding altered incoming ICMPv6"); |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 837 | } |
| 838 | #endif |
| 839 | |
Malcolm Turnbull | 4856c84 | 2008-09-05 11:17:13 +1000 | [diff] [blame] | 840 | /* Handle relevant response ICMP messages - forward to the right |
Julian Anastasov | 6cb90db | 2011-02-09 02:26:38 +0200 | [diff] [blame] | 841 | * destination host. |
Malcolm Turnbull | 4856c84 | 2008-09-05 11:17:13 +1000 | [diff] [blame] | 842 | */ |
Simon Horman | f2428ed | 2008-09-05 11:17:14 +1000 | [diff] [blame] | 843 | static int handle_response_icmp(int af, struct sk_buff *skb, |
| 844 | union nf_inet_addr *snet, |
| 845 | __u8 protocol, struct ip_vs_conn *cp, |
Malcolm Turnbull | 4856c84 | 2008-09-05 11:17:13 +1000 | [diff] [blame] | 846 | struct ip_vs_protocol *pp, |
Julian Anastasov | 579eb62 | 2014-12-18 22:41:23 +0200 | [diff] [blame] | 847 | unsigned int offset, unsigned int ihl, |
| 848 | unsigned int hooknum) |
Malcolm Turnbull | 4856c84 | 2008-09-05 11:17:13 +1000 | [diff] [blame] | 849 | { |
| 850 | unsigned int verdict = NF_DROP; |
| 851 | |
| 852 | if (IP_VS_FWD_METHOD(cp) != 0) { |
Hannes Eder | 1e3e238 | 2009-08-02 11:05:41 +0000 | [diff] [blame] | 853 | pr_err("shouldn't reach here, because the box is on the " |
| 854 | "half connection in the tun/dr module.\n"); |
Malcolm Turnbull | 4856c84 | 2008-09-05 11:17:13 +1000 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | /* Ensure the checksum is correct */ |
| 858 | if (!skb_csum_unnecessary(skb) && ip_vs_checksum_complete(skb, ihl)) { |
| 859 | /* Failed checksum! */ |
Simon Horman | f2428ed | 2008-09-05 11:17:14 +1000 | [diff] [blame] | 860 | IP_VS_DBG_BUF(1, "Forward ICMP: failed checksum from %s!\n", |
| 861 | IP_VS_DBG_ADDR(af, snet)); |
Malcolm Turnbull | 4856c84 | 2008-09-05 11:17:13 +1000 | [diff] [blame] | 862 | goto out; |
| 863 | } |
| 864 | |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 865 | if (IPPROTO_TCP == protocol || IPPROTO_UDP == protocol || |
| 866 | IPPROTO_SCTP == protocol) |
Malcolm Turnbull | 4856c84 | 2008-09-05 11:17:13 +1000 | [diff] [blame] | 867 | offset += 2 * sizeof(__u16); |
| 868 | if (!skb_make_writable(skb, offset)) |
| 869 | goto out; |
| 870 | |
Simon Horman | f2428ed | 2008-09-05 11:17:14 +1000 | [diff] [blame] | 871 | #ifdef CONFIG_IP_VS_IPV6 |
| 872 | if (af == AF_INET6) |
| 873 | ip_vs_nat_icmp_v6(skb, pp, cp, 1); |
| 874 | else |
| 875 | #endif |
| 876 | ip_vs_nat_icmp(skb, pp, cp, 1); |
Malcolm Turnbull | 4856c84 | 2008-09-05 11:17:13 +1000 | [diff] [blame] | 877 | |
Eric W. Biederman | a43d1a6 | 2015-09-21 13:02:56 -0500 | [diff] [blame] | 878 | if (ip_vs_route_me_harder(cp->ipvs, af, skb, hooknum)) |
Simon Horman | ba4fd7e | 2011-02-04 18:33:01 +0900 | [diff] [blame] | 879 | goto out; |
Julian Anastasov | f5a4184 | 2010-10-17 16:35:46 +0300 | [diff] [blame] | 880 | |
Malcolm Turnbull | 4856c84 | 2008-09-05 11:17:13 +1000 | [diff] [blame] | 881 | /* do the statistics and put it back */ |
| 882 | ip_vs_out_stats(cp, skb); |
| 883 | |
Julian Anastasov | cf356d6 | 2010-10-17 16:21:07 +0300 | [diff] [blame] | 884 | skb->ipvs_property = 1; |
Julian Anastasov | f4bc17c | 2010-09-21 17:35:41 +0200 | [diff] [blame] | 885 | if (!(cp->flags & IP_VS_CONN_F_NFCT)) |
Julian Anastasov | cf356d6 | 2010-10-17 16:21:07 +0300 | [diff] [blame] | 886 | ip_vs_notrack(skb); |
Julian Anastasov | f4bc17c | 2010-09-21 17:35:41 +0200 | [diff] [blame] | 887 | else |
| 888 | ip_vs_update_conntrack(skb, cp, 0); |
Malcolm Turnbull | 4856c84 | 2008-09-05 11:17:13 +1000 | [diff] [blame] | 889 | verdict = NF_ACCEPT; |
| 890 | |
| 891 | out: |
| 892 | __ip_vs_conn_put(cp); |
| 893 | |
| 894 | return verdict; |
| 895 | } |
| 896 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | /* |
| 898 | * Handle ICMP messages in the inside-to-outside direction (outgoing). |
Malcolm Turnbull | 4856c84 | 2008-09-05 11:17:13 +1000 | [diff] [blame] | 899 | * Find any that might be relevant, check against existing connections. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | * Currently handles error types - unreachable, quench, ttl exceeded. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | */ |
Eric W. Biederman | 7b5f689 | 2015-09-21 13:02:55 -0500 | [diff] [blame] | 902 | static int ip_vs_out_icmp(struct netns_ipvs *ipvs, struct sk_buff *skb, |
| 903 | int *related, unsigned int hooknum) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | struct iphdr *iph; |
| 906 | struct icmphdr _icmph, *ic; |
| 907 | struct iphdr _ciph, *cih; /* The ip header contained within the ICMP */ |
Julius Volz | 51ef348 | 2008-09-02 15:55:40 +0200 | [diff] [blame] | 908 | struct ip_vs_iphdr ciph; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | struct ip_vs_conn *cp; |
| 910 | struct ip_vs_protocol *pp; |
Malcolm Turnbull | 4856c84 | 2008-09-05 11:17:13 +1000 | [diff] [blame] | 911 | unsigned int offset, ihl; |
Simon Horman | f2428ed | 2008-09-05 11:17:14 +1000 | [diff] [blame] | 912 | union nf_inet_addr snet; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | |
| 914 | *related = 1; |
| 915 | |
| 916 | /* reassemble IP fragments */ |
Paul Gortmaker | 56f8a75 | 2011-06-21 20:33:34 -0700 | [diff] [blame] | 917 | if (ip_is_fragment(ip_hdr(skb))) { |
Eric W. Biederman | 57781c1 | 2015-09-21 13:03:01 -0500 | [diff] [blame] | 918 | if (ip_vs_gather_frags(ipvs, skb, ip_vs_defrag_user(hooknum))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | return NF_STOLEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | } |
| 921 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 922 | iph = ip_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | offset = ihl = iph->ihl * 4; |
| 924 | ic = skb_header_pointer(skb, offset, sizeof(_icmph), &_icmph); |
| 925 | if (ic == NULL) |
| 926 | return NF_DROP; |
| 927 | |
Harvey Harrison | 14d5e83 | 2008-10-31 00:54:29 -0700 | [diff] [blame] | 928 | IP_VS_DBG(12, "Outgoing ICMP (%d,%d) %pI4->%pI4\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | ic->type, ntohs(icmp_id(ic)), |
Harvey Harrison | 14d5e83 | 2008-10-31 00:54:29 -0700 | [diff] [blame] | 930 | &iph->saddr, &iph->daddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | |
| 932 | /* |
| 933 | * Work through seeing if this is for us. |
| 934 | * These checks are supposed to be in an order that means easy |
| 935 | * things are checked first to speed up processing.... however |
| 936 | * this means that some packets will manage to get a long way |
| 937 | * down this stack and then be rejected, but that's life. |
| 938 | */ |
| 939 | if ((ic->type != ICMP_DEST_UNREACH) && |
| 940 | (ic->type != ICMP_SOURCE_QUENCH) && |
| 941 | (ic->type != ICMP_TIME_EXCEEDED)) { |
| 942 | *related = 0; |
| 943 | return NF_ACCEPT; |
| 944 | } |
| 945 | |
| 946 | /* Now find the contained IP header */ |
| 947 | offset += sizeof(_icmph); |
| 948 | cih = skb_header_pointer(skb, offset, sizeof(_ciph), &_ciph); |
| 949 | if (cih == NULL) |
| 950 | return NF_ACCEPT; /* The packet looks wrong, ignore */ |
| 951 | |
| 952 | pp = ip_vs_proto_get(cih->protocol); |
| 953 | if (!pp) |
| 954 | return NF_ACCEPT; |
| 955 | |
| 956 | /* Is the embedded protocol header present? */ |
YOSHIFUJI Hideaki | 4412ec4 | 2007-03-07 14:19:10 +0900 | [diff] [blame] | 957 | if (unlikely(cih->frag_off & htons(IP_OFFSET) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | pp->dont_defrag)) |
| 959 | return NF_ACCEPT; |
| 960 | |
Julian Anastasov | 0d79641 | 2010-10-17 16:46:17 +0300 | [diff] [blame] | 961 | IP_VS_DBG_PKT(11, AF_INET, pp, skb, offset, |
| 962 | "Checking outgoing ICMP for"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | |
Alex Gartrell | 4fd9bee | 2015-08-26 09:40:29 -0700 | [diff] [blame] | 964 | ip_vs_fill_iph_skb_icmp(AF_INET, skb, offset, true, &ciph); |
Alex Gartrell | b0e010c | 2015-08-26 09:40:28 -0700 | [diff] [blame] | 965 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | /* The embedded headers contain source and dest in reverse order */ |
Eric W. Biederman | 0cf705c8c | 2015-09-21 13:02:39 -0500 | [diff] [blame] | 967 | cp = pp->conn_out_get(ipvs, AF_INET, skb, &ciph); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | if (!cp) |
| 969 | return NF_ACCEPT; |
| 970 | |
Simon Horman | f2428ed | 2008-09-05 11:17:14 +1000 | [diff] [blame] | 971 | snet.ip = iph->saddr; |
| 972 | return handle_response_icmp(AF_INET, skb, &snet, cih->protocol, cp, |
Julian Anastasov | 579eb62 | 2014-12-18 22:41:23 +0200 | [diff] [blame] | 973 | pp, ciph.len, ihl, hooknum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | } |
| 975 | |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 976 | #ifdef CONFIG_IP_VS_IPV6 |
Eric W. Biederman | 7b5f689 | 2015-09-21 13:02:55 -0500 | [diff] [blame] | 977 | static int ip_vs_out_icmp_v6(struct netns_ipvs *ipvs, struct sk_buff *skb, |
| 978 | int *related, unsigned int hooknum, |
| 979 | struct ip_vs_iphdr *ipvsh) |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 980 | { |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 981 | struct icmp6hdr _icmph, *ic; |
Jesper Dangaard Brouer | 63dca2c | 2012-09-26 14:06:41 +0200 | [diff] [blame] | 982 | struct ip_vs_iphdr ciph = {.flags = 0, .fragoffs = 0};/*Contained IP */ |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 983 | struct ip_vs_conn *cp; |
| 984 | struct ip_vs_protocol *pp; |
Simon Horman | f2428ed | 2008-09-05 11:17:14 +1000 | [diff] [blame] | 985 | union nf_inet_addr snet; |
Alex Gartrell | b0e010c | 2015-08-26 09:40:28 -0700 | [diff] [blame] | 986 | unsigned int offset; |
Jesper Dangaard Brouer | 63dca2c | 2012-09-26 14:06:41 +0200 | [diff] [blame] | 987 | |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 988 | *related = 1; |
Jesper Dangaard Brouer | 2f74713 | 2012-09-26 14:06:59 +0200 | [diff] [blame] | 989 | ic = frag_safe_skb_hp(skb, ipvsh->len, sizeof(_icmph), &_icmph, ipvsh); |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 990 | if (ic == NULL) |
| 991 | return NF_DROP; |
| 992 | |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 993 | /* |
| 994 | * Work through seeing if this is for us. |
| 995 | * These checks are supposed to be in an order that means easy |
| 996 | * things are checked first to speed up processing.... however |
| 997 | * this means that some packets will manage to get a long way |
| 998 | * down this stack and then be rejected, but that's life. |
| 999 | */ |
Jesper Dangaard Brouer | 2fab891 | 2012-09-26 14:06:11 +0200 | [diff] [blame] | 1000 | if (ic->icmp6_type & ICMPV6_INFOMSG_MASK) { |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1001 | *related = 0; |
| 1002 | return NF_ACCEPT; |
| 1003 | } |
Jesper Dangaard Brouer | 2f74713 | 2012-09-26 14:06:59 +0200 | [diff] [blame] | 1004 | /* Fragment header that is before ICMP header tells us that: |
| 1005 | * it's not an error message since they can't be fragmented. |
| 1006 | */ |
David S. Miller | e716503 | 2012-11-30 12:01:30 -0500 | [diff] [blame] | 1007 | if (ipvsh->flags & IP6_FH_F_FRAG) |
Jesper Dangaard Brouer | 2f74713 | 2012-09-26 14:06:59 +0200 | [diff] [blame] | 1008 | return NF_DROP; |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1009 | |
Jesper Dangaard Brouer | 63dca2c | 2012-09-26 14:06:41 +0200 | [diff] [blame] | 1010 | IP_VS_DBG(8, "Outgoing ICMPv6 (%d,%d) %pI6c->%pI6c\n", |
| 1011 | ic->icmp6_type, ntohs(icmpv6_id(ic)), |
| 1012 | &ipvsh->saddr, &ipvsh->daddr); |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1013 | |
Alex Gartrell | 4fd9bee | 2015-08-26 09:40:29 -0700 | [diff] [blame] | 1014 | if (!ip_vs_fill_iph_skb_icmp(AF_INET6, skb, ipvsh->len + sizeof(_icmph), |
| 1015 | true, &ciph)) |
Jesper Dangaard Brouer | 63dca2c | 2012-09-26 14:06:41 +0200 | [diff] [blame] | 1016 | return NF_ACCEPT; /* The packet looks wrong, ignore */ |
Jesper Dangaard Brouer | 63dca2c | 2012-09-26 14:06:41 +0200 | [diff] [blame] | 1017 | |
| 1018 | pp = ip_vs_proto_get(ciph.protocol); |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1019 | if (!pp) |
| 1020 | return NF_ACCEPT; |
| 1021 | |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1022 | /* The embedded headers contain source and dest in reverse order */ |
Eric W. Biederman | 0cf705c8c | 2015-09-21 13:02:39 -0500 | [diff] [blame] | 1023 | cp = pp->conn_out_get(ipvs, AF_INET6, skb, &ciph); |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1024 | if (!cp) |
| 1025 | return NF_ACCEPT; |
| 1026 | |
Jesper Dangaard Brouer | 63dca2c | 2012-09-26 14:06:41 +0200 | [diff] [blame] | 1027 | snet.in6 = ciph.saddr.in6; |
Alex Gartrell | b0e010c | 2015-08-26 09:40:28 -0700 | [diff] [blame] | 1028 | offset = ciph.len; |
Jesper Dangaard Brouer | 63dca2c | 2012-09-26 14:06:41 +0200 | [diff] [blame] | 1029 | return handle_response_icmp(AF_INET6, skb, &snet, ciph.protocol, cp, |
Alex Gartrell | b0e010c | 2015-08-26 09:40:28 -0700 | [diff] [blame] | 1030 | pp, offset, sizeof(struct ipv6hdr), |
Julian Anastasov | 579eb62 | 2014-12-18 22:41:23 +0200 | [diff] [blame] | 1031 | hooknum); |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1032 | } |
| 1033 | #endif |
| 1034 | |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 1035 | /* |
| 1036 | * Check if sctp chunc is ABORT chunk |
| 1037 | */ |
| 1038 | static inline int is_sctp_abort(const struct sk_buff *skb, int nh_len) |
| 1039 | { |
| 1040 | sctp_chunkhdr_t *sch, schunk; |
| 1041 | sch = skb_header_pointer(skb, nh_len + sizeof(sctp_sctphdr_t), |
| 1042 | sizeof(schunk), &schunk); |
| 1043 | if (sch == NULL) |
| 1044 | return 0; |
| 1045 | if (sch->type == SCTP_CID_ABORT) |
| 1046 | return 1; |
| 1047 | return 0; |
| 1048 | } |
| 1049 | |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1050 | static inline int is_tcp_reset(const struct sk_buff *skb, int nh_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | { |
| 1052 | struct tcphdr _tcph, *th; |
| 1053 | |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1054 | th = skb_header_pointer(skb, nh_len, sizeof(_tcph), &_tcph); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | if (th == NULL) |
| 1056 | return 0; |
| 1057 | return th->rst; |
| 1058 | } |
| 1059 | |
Grzegorz Lyczba | dc7b3eb | 2013-05-13 23:56:24 +0200 | [diff] [blame] | 1060 | static inline bool is_new_conn(const struct sk_buff *skb, |
| 1061 | struct ip_vs_iphdr *iph) |
| 1062 | { |
| 1063 | switch (iph->protocol) { |
| 1064 | case IPPROTO_TCP: { |
| 1065 | struct tcphdr _tcph, *th; |
| 1066 | |
| 1067 | th = skb_header_pointer(skb, iph->len, sizeof(_tcph), &_tcph); |
| 1068 | if (th == NULL) |
| 1069 | return false; |
| 1070 | return th->syn; |
| 1071 | } |
| 1072 | case IPPROTO_SCTP: { |
| 1073 | sctp_chunkhdr_t *sch, schunk; |
| 1074 | |
| 1075 | sch = skb_header_pointer(skb, iph->len + sizeof(sctp_sctphdr_t), |
| 1076 | sizeof(schunk), &schunk); |
| 1077 | if (sch == NULL) |
| 1078 | return false; |
| 1079 | return sch->type == SCTP_CID_INIT; |
| 1080 | } |
| 1081 | default: |
| 1082 | return false; |
| 1083 | } |
| 1084 | } |
| 1085 | |
Marcelo Ricardo Leitner | d752c36 | 2015-02-23 15:02:34 -0300 | [diff] [blame] | 1086 | static inline bool is_new_conn_expected(const struct ip_vs_conn *cp, |
| 1087 | int conn_reuse_mode) |
| 1088 | { |
| 1089 | /* Controlled (FTP DATA or persistence)? */ |
| 1090 | if (cp->control) |
| 1091 | return false; |
| 1092 | |
| 1093 | switch (cp->protocol) { |
| 1094 | case IPPROTO_TCP: |
| 1095 | return (cp->state == IP_VS_TCP_S_TIME_WAIT) || |
Julian Anastasov | f911b67 | 2016-03-05 15:03:23 +0200 | [diff] [blame] | 1096 | (cp->state == IP_VS_TCP_S_CLOSE) || |
Marcelo Ricardo Leitner | d752c36 | 2015-02-23 15:02:34 -0300 | [diff] [blame] | 1097 | ((conn_reuse_mode & 2) && |
| 1098 | (cp->state == IP_VS_TCP_S_FIN_WAIT) && |
| 1099 | (cp->flags & IP_VS_CONN_F_NOOUTPUT)); |
| 1100 | case IPPROTO_SCTP: |
| 1101 | return cp->state == IP_VS_SCTP_S_CLOSED; |
| 1102 | default: |
| 1103 | return false; |
| 1104 | } |
| 1105 | } |
| 1106 | |
Marco Angaroni | 39b9722 | 2016-04-05 18:26:29 +0200 | [diff] [blame] | 1107 | /* Generic function to create new connections for outgoing RS packets |
| 1108 | * |
| 1109 | * Pre-requisites for successful connection creation: |
| 1110 | * 1) Virtual Service is NOT fwmark based: |
| 1111 | * In fwmark-VS actual vaddr and vport are unknown to IPVS |
| 1112 | * 2) Real Server and Virtual Service were NOT configured without port: |
| 1113 | * This is to allow match of different VS to the same RS ip-addr |
| 1114 | */ |
| 1115 | struct ip_vs_conn *ip_vs_new_conn_out(struct ip_vs_service *svc, |
| 1116 | struct ip_vs_dest *dest, |
| 1117 | struct sk_buff *skb, |
| 1118 | const struct ip_vs_iphdr *iph, |
| 1119 | __be16 dport, |
| 1120 | __be16 cport) |
| 1121 | { |
| 1122 | struct ip_vs_conn_param param; |
| 1123 | struct ip_vs_conn *ct = NULL, *cp = NULL; |
| 1124 | const union nf_inet_addr *vaddr, *daddr, *caddr; |
| 1125 | union nf_inet_addr snet; |
| 1126 | __be16 vport; |
| 1127 | unsigned int flags; |
| 1128 | |
| 1129 | EnterFunction(12); |
| 1130 | vaddr = &svc->addr; |
| 1131 | vport = svc->port; |
| 1132 | daddr = &iph->saddr; |
| 1133 | caddr = &iph->daddr; |
| 1134 | |
| 1135 | /* check pre-requisites are satisfied */ |
| 1136 | if (svc->fwmark) |
| 1137 | return NULL; |
| 1138 | if (!vport || !dport) |
| 1139 | return NULL; |
| 1140 | |
| 1141 | /* for persistent service first create connection template */ |
| 1142 | if (svc->flags & IP_VS_SVC_F_PERSISTENT) { |
| 1143 | /* apply netmask the same way ingress-side does */ |
| 1144 | #ifdef CONFIG_IP_VS_IPV6 |
| 1145 | if (svc->af == AF_INET6) |
| 1146 | ipv6_addr_prefix(&snet.in6, &caddr->in6, |
| 1147 | (__force __u32)svc->netmask); |
| 1148 | else |
| 1149 | #endif |
| 1150 | snet.ip = caddr->ip & svc->netmask; |
| 1151 | /* fill params and create template if not existent */ |
| 1152 | if (ip_vs_conn_fill_param_persist(svc, skb, iph->protocol, |
| 1153 | &snet, 0, vaddr, |
| 1154 | vport, ¶m) < 0) |
| 1155 | return NULL; |
| 1156 | ct = ip_vs_ct_in_get(¶m); |
Marco Angaroni | 3ec10d3 | 2016-05-16 19:18:09 +0200 | [diff] [blame] | 1157 | /* check if template exists and points to the same dest */ |
| 1158 | if (!ct || !ip_vs_check_template(ct, dest)) { |
Marco Angaroni | 39b9722 | 2016-04-05 18:26:29 +0200 | [diff] [blame] | 1159 | ct = ip_vs_conn_new(¶m, dest->af, daddr, dport, |
| 1160 | IP_VS_CONN_F_TEMPLATE, dest, 0); |
| 1161 | if (!ct) { |
| 1162 | kfree(param.pe_data); |
| 1163 | return NULL; |
| 1164 | } |
| 1165 | ct->timeout = svc->timeout; |
| 1166 | } else { |
| 1167 | kfree(param.pe_data); |
| 1168 | } |
| 1169 | } |
| 1170 | |
| 1171 | /* connection flags */ |
| 1172 | flags = ((svc->flags & IP_VS_SVC_F_ONEPACKET) && |
| 1173 | iph->protocol == IPPROTO_UDP) ? IP_VS_CONN_F_ONE_PACKET : 0; |
| 1174 | /* create connection */ |
| 1175 | ip_vs_conn_fill_param(svc->ipvs, svc->af, iph->protocol, |
| 1176 | caddr, cport, vaddr, vport, ¶m); |
| 1177 | cp = ip_vs_conn_new(¶m, dest->af, daddr, dport, flags, dest, 0); |
| 1178 | if (!cp) { |
| 1179 | if (ct) |
| 1180 | ip_vs_conn_put(ct); |
| 1181 | return NULL; |
| 1182 | } |
| 1183 | if (ct) { |
| 1184 | ip_vs_control_add(cp, ct); |
| 1185 | ip_vs_conn_put(ct); |
| 1186 | } |
| 1187 | ip_vs_conn_stats(cp, svc); |
| 1188 | |
| 1189 | /* return connection (will be used to handle outgoing packet) */ |
| 1190 | IP_VS_DBG_BUF(6, "New connection RS-initiated:%c c:%s:%u v:%s:%u " |
| 1191 | "d:%s:%u conn->flags:%X conn->refcnt:%d\n", |
| 1192 | ip_vs_fwd_tag(cp), |
| 1193 | IP_VS_DBG_ADDR(cp->af, &cp->caddr), ntohs(cp->cport), |
| 1194 | IP_VS_DBG_ADDR(cp->af, &cp->vaddr), ntohs(cp->vport), |
| 1195 | IP_VS_DBG_ADDR(cp->af, &cp->daddr), ntohs(cp->dport), |
| 1196 | cp->flags, atomic_read(&cp->refcnt)); |
| 1197 | LeaveFunction(12); |
| 1198 | return cp; |
| 1199 | } |
| 1200 | |
| 1201 | /* Handle outgoing packets which are considered requests initiated by |
| 1202 | * real servers, so that subsequent responses from external client can be |
| 1203 | * routed to the right real server. |
| 1204 | * Used also for outgoing responses in OPS mode. |
| 1205 | * |
| 1206 | * Connection management is handled by persistent-engine specific callback. |
| 1207 | */ |
| 1208 | static struct ip_vs_conn *__ip_vs_rs_conn_out(unsigned int hooknum, |
| 1209 | struct netns_ipvs *ipvs, |
| 1210 | int af, struct sk_buff *skb, |
| 1211 | const struct ip_vs_iphdr *iph) |
| 1212 | { |
| 1213 | struct ip_vs_dest *dest; |
| 1214 | struct ip_vs_conn *cp = NULL; |
| 1215 | __be16 _ports[2], *pptr; |
| 1216 | |
| 1217 | if (hooknum == NF_INET_LOCAL_IN) |
| 1218 | return NULL; |
| 1219 | |
| 1220 | pptr = frag_safe_skb_hp(skb, iph->len, |
| 1221 | sizeof(_ports), _ports, iph); |
| 1222 | if (!pptr) |
| 1223 | return NULL; |
| 1224 | |
| 1225 | rcu_read_lock(); |
| 1226 | dest = ip_vs_find_real_service(ipvs, af, iph->protocol, |
| 1227 | &iph->saddr, pptr[0]); |
| 1228 | if (dest) { |
| 1229 | struct ip_vs_service *svc; |
| 1230 | struct ip_vs_pe *pe; |
| 1231 | |
| 1232 | svc = rcu_dereference(dest->svc); |
| 1233 | if (svc) { |
| 1234 | pe = rcu_dereference(svc->pe); |
| 1235 | if (pe && pe->conn_out) |
| 1236 | cp = pe->conn_out(svc, dest, skb, iph, |
| 1237 | pptr[0], pptr[1]); |
| 1238 | } |
| 1239 | } |
| 1240 | rcu_read_unlock(); |
| 1241 | |
| 1242 | return cp; |
| 1243 | } |
| 1244 | |
Malcolm Turnbull | 4856c84 | 2008-09-05 11:17:13 +1000 | [diff] [blame] | 1245 | /* Handle response packets: rewrite addresses and send away... |
Malcolm Turnbull | 4856c84 | 2008-09-05 11:17:13 +1000 | [diff] [blame] | 1246 | */ |
| 1247 | static unsigned int |
Hans Schillstrom | 9330419 | 2011-01-03 14:44:51 +0100 | [diff] [blame] | 1248 | handle_response(int af, struct sk_buff *skb, struct ip_vs_proto_data *pd, |
Julian Anastasov | 579eb62 | 2014-12-18 22:41:23 +0200 | [diff] [blame] | 1249 | struct ip_vs_conn *cp, struct ip_vs_iphdr *iph, |
| 1250 | unsigned int hooknum) |
Malcolm Turnbull | 4856c84 | 2008-09-05 11:17:13 +1000 | [diff] [blame] | 1251 | { |
Hans Schillstrom | 9330419 | 2011-01-03 14:44:51 +0100 | [diff] [blame] | 1252 | struct ip_vs_protocol *pp = pd->pp; |
| 1253 | |
Alex Gartrell | b0e010c | 2015-08-26 09:40:28 -0700 | [diff] [blame] | 1254 | IP_VS_DBG_PKT(11, af, pp, skb, iph->off, "Outgoing packet"); |
Malcolm Turnbull | 4856c84 | 2008-09-05 11:17:13 +1000 | [diff] [blame] | 1255 | |
Jesper Dangaard Brouer | d4383f0 | 2012-09-26 14:07:17 +0200 | [diff] [blame] | 1256 | if (!skb_make_writable(skb, iph->len)) |
Malcolm Turnbull | 4856c84 | 2008-09-05 11:17:13 +1000 | [diff] [blame] | 1257 | goto drop; |
| 1258 | |
| 1259 | /* mangle the packet */ |
Jesper Dangaard Brouer | d4383f0 | 2012-09-26 14:07:17 +0200 | [diff] [blame] | 1260 | if (pp->snat_handler && !pp->snat_handler(skb, pp, cp, iph)) |
Malcolm Turnbull | 4856c84 | 2008-09-05 11:17:13 +1000 | [diff] [blame] | 1261 | goto drop; |
| 1262 | |
| 1263 | #ifdef CONFIG_IP_VS_IPV6 |
| 1264 | if (af == AF_INET6) |
| 1265 | ipv6_hdr(skb)->saddr = cp->vaddr.in6; |
| 1266 | else |
| 1267 | #endif |
| 1268 | { |
| 1269 | ip_hdr(skb)->saddr = cp->vaddr.ip; |
| 1270 | ip_send_check(ip_hdr(skb)); |
| 1271 | } |
| 1272 | |
Julian Anastasov | 8a80304 | 2010-09-21 17:38:57 +0200 | [diff] [blame] | 1273 | /* |
| 1274 | * nf_iterate does not expect change in the skb->dst->dev. |
| 1275 | * It looks like it is not fatal to enable this code for hooks |
| 1276 | * where our handlers are at the end of the chain list and |
| 1277 | * when all next handlers use skb->dst->dev and not outdev. |
| 1278 | * It will definitely route properly the inout NAT traffic |
| 1279 | * when multiple paths are used. |
| 1280 | */ |
| 1281 | |
Malcolm Turnbull | 4856c84 | 2008-09-05 11:17:13 +1000 | [diff] [blame] | 1282 | /* For policy routing, packets originating from this |
| 1283 | * machine itself may be routed differently to packets |
| 1284 | * passing through. We want this packet to be routed as |
| 1285 | * if it came from this machine itself. So re-compute |
| 1286 | * the routing information. |
| 1287 | */ |
Eric W. Biederman | a43d1a6 | 2015-09-21 13:02:56 -0500 | [diff] [blame] | 1288 | if (ip_vs_route_me_harder(cp->ipvs, af, skb, hooknum)) |
Simon Horman | ba4fd7e | 2011-02-04 18:33:01 +0900 | [diff] [blame] | 1289 | goto drop; |
Malcolm Turnbull | 4856c84 | 2008-09-05 11:17:13 +1000 | [diff] [blame] | 1290 | |
Alex Gartrell | b0e010c | 2015-08-26 09:40:28 -0700 | [diff] [blame] | 1291 | IP_VS_DBG_PKT(10, af, pp, skb, iph->off, "After SNAT"); |
Malcolm Turnbull | 4856c84 | 2008-09-05 11:17:13 +1000 | [diff] [blame] | 1292 | |
| 1293 | ip_vs_out_stats(cp, skb); |
Hans Schillstrom | 9330419 | 2011-01-03 14:44:51 +0100 | [diff] [blame] | 1294 | ip_vs_set_state(cp, IP_VS_DIR_OUTPUT, skb, pd); |
Julian Anastasov | cf356d6 | 2010-10-17 16:21:07 +0300 | [diff] [blame] | 1295 | skb->ipvs_property = 1; |
Julian Anastasov | f4bc17c | 2010-09-21 17:35:41 +0200 | [diff] [blame] | 1296 | if (!(cp->flags & IP_VS_CONN_F_NFCT)) |
Julian Anastasov | cf356d6 | 2010-10-17 16:21:07 +0300 | [diff] [blame] | 1297 | ip_vs_notrack(skb); |
Julian Anastasov | f4bc17c | 2010-09-21 17:35:41 +0200 | [diff] [blame] | 1298 | else |
| 1299 | ip_vs_update_conntrack(skb, cp, 0); |
Malcolm Turnbull | 4856c84 | 2008-09-05 11:17:13 +1000 | [diff] [blame] | 1300 | ip_vs_conn_put(cp); |
| 1301 | |
Malcolm Turnbull | 4856c84 | 2008-09-05 11:17:13 +1000 | [diff] [blame] | 1302 | LeaveFunction(11); |
| 1303 | return NF_ACCEPT; |
| 1304 | |
| 1305 | drop: |
| 1306 | ip_vs_conn_put(cp); |
| 1307 | kfree_skb(skb); |
Julian Anastasov | f4bc17c | 2010-09-21 17:35:41 +0200 | [diff] [blame] | 1308 | LeaveFunction(11); |
Malcolm Turnbull | 4856c84 | 2008-09-05 11:17:13 +1000 | [diff] [blame] | 1309 | return NF_STOLEN; |
| 1310 | } |
| 1311 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | /* |
Malcolm Turnbull | 4856c84 | 2008-09-05 11:17:13 +1000 | [diff] [blame] | 1313 | * Check if outgoing packet belongs to the established ip_vs_conn. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | */ |
| 1315 | static unsigned int |
Eric W. Biederman | 1b75097 | 2015-09-21 13:02:52 -0500 | [diff] [blame] | 1316 | ip_vs_out(struct netns_ipvs *ipvs, unsigned int hooknum, struct sk_buff *skb, int af) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | { |
Julius Volz | 51ef348 | 2008-09-02 15:55:40 +0200 | [diff] [blame] | 1318 | struct ip_vs_iphdr iph; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | struct ip_vs_protocol *pp; |
Hans Schillstrom | 9330419 | 2011-01-03 14:44:51 +0100 | [diff] [blame] | 1320 | struct ip_vs_proto_data *pd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | struct ip_vs_conn *cp; |
Eric Dumazet | 340c78e | 2015-11-12 09:14:12 -0800 | [diff] [blame] | 1322 | struct sock *sk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 | |
| 1324 | EnterFunction(11); |
| 1325 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1326 | /* Already marked as IPVS request or reply? */ |
Harald Welte | 6869c4d | 2005-08-09 19:24:19 -0700 | [diff] [blame] | 1327 | if (skb->ipvs_property) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | return NF_ACCEPT; |
| 1329 | |
Eric Dumazet | 340c78e | 2015-11-12 09:14:12 -0800 | [diff] [blame] | 1330 | sk = skb_to_full_sk(skb); |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1331 | /* Bad... Do not break raw sockets */ |
Eric Dumazet | 340c78e | 2015-11-12 09:14:12 -0800 | [diff] [blame] | 1332 | if (unlikely(sk && hooknum == NF_INET_LOCAL_OUT && |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1333 | af == AF_INET)) { |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1334 | |
Eric Dumazet | 340c78e | 2015-11-12 09:14:12 -0800 | [diff] [blame] | 1335 | if (sk->sk_family == PF_INET && inet_sk(sk)->nodefrag) |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1336 | return NF_ACCEPT; |
| 1337 | } |
| 1338 | |
| 1339 | if (unlikely(!skb_dst(skb))) |
| 1340 | return NF_ACCEPT; |
| 1341 | |
Eric W. Biederman | 48aed1b | 2015-09-21 13:01:50 -0500 | [diff] [blame] | 1342 | if (!ipvs->enable) |
Hans Schillstrom | 7a4f076 | 2011-05-03 22:09:31 +0200 | [diff] [blame] | 1343 | return NF_ACCEPT; |
| 1344 | |
Alex Gartrell | 4fd9bee | 2015-08-26 09:40:29 -0700 | [diff] [blame] | 1345 | ip_vs_fill_iph_skb(af, skb, false, &iph); |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1346 | #ifdef CONFIG_IP_VS_IPV6 |
| 1347 | if (af == AF_INET6) { |
| 1348 | if (unlikely(iph.protocol == IPPROTO_ICMPV6)) { |
Julian Anastasov | 1ca5bb5 | 2010-10-17 16:32:29 +0300 | [diff] [blame] | 1349 | int related; |
Eric W. Biederman | 7b5f689 | 2015-09-21 13:02:55 -0500 | [diff] [blame] | 1350 | int verdict = ip_vs_out_icmp_v6(ipvs, skb, &related, |
Jesper Dangaard Brouer | d4383f0 | 2012-09-26 14:07:17 +0200 | [diff] [blame] | 1351 | hooknum, &iph); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | |
Julian Anastasov | f5a4184 | 2010-10-17 16:35:46 +0300 | [diff] [blame] | 1353 | if (related) |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1354 | return verdict; |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1355 | } |
| 1356 | } else |
| 1357 | #endif |
| 1358 | if (unlikely(iph.protocol == IPPROTO_ICMP)) { |
Julian Anastasov | 1ca5bb5 | 2010-10-17 16:32:29 +0300 | [diff] [blame] | 1359 | int related; |
Eric W. Biederman | 7b5f689 | 2015-09-21 13:02:55 -0500 | [diff] [blame] | 1360 | int verdict = ip_vs_out_icmp(ipvs, skb, &related, hooknum); |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1361 | |
Julian Anastasov | f5a4184 | 2010-10-17 16:35:46 +0300 | [diff] [blame] | 1362 | if (related) |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1363 | return verdict; |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1364 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | |
Eric W. Biederman | 18d6ade | 2015-09-21 13:02:01 -0500 | [diff] [blame] | 1366 | pd = ip_vs_proto_data_get(ipvs, iph.protocol); |
Hans Schillstrom | 9330419 | 2011-01-03 14:44:51 +0100 | [diff] [blame] | 1367 | if (unlikely(!pd)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | return NF_ACCEPT; |
Hans Schillstrom | 9330419 | 2011-01-03 14:44:51 +0100 | [diff] [blame] | 1369 | pp = pd->pp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | |
| 1371 | /* reassemble IP fragments */ |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1372 | #ifdef CONFIG_IP_VS_IPV6 |
Jesper Dangaard Brouer | 63dca2c | 2012-09-26 14:06:41 +0200 | [diff] [blame] | 1373 | if (af == AF_INET) |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1374 | #endif |
Paul Gortmaker | 56f8a75 | 2011-06-21 20:33:34 -0700 | [diff] [blame] | 1375 | if (unlikely(ip_is_fragment(ip_hdr(skb)) && !pp->dont_defrag)) { |
Eric W. Biederman | 57781c1 | 2015-09-21 13:03:01 -0500 | [diff] [blame] | 1376 | if (ip_vs_gather_frags(ipvs, skb, |
Julian Anastasov | 1ca5bb5 | 2010-10-17 16:32:29 +0300 | [diff] [blame] | 1377 | ip_vs_defrag_user(hooknum))) |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1378 | return NF_STOLEN; |
| 1379 | |
Alex Gartrell | 4fd9bee | 2015-08-26 09:40:29 -0700 | [diff] [blame] | 1380 | ip_vs_fill_iph_skb(AF_INET, skb, false, &iph); |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1381 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | |
| 1383 | /* |
| 1384 | * Check if the packet belongs to an existing entry |
| 1385 | */ |
Eric W. Biederman | 0cf705c8c | 2015-09-21 13:02:39 -0500 | [diff] [blame] | 1386 | cp = pp->conn_out_get(ipvs, af, skb, &iph); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 1388 | if (likely(cp)) |
Julian Anastasov | 579eb62 | 2014-12-18 22:41:23 +0200 | [diff] [blame] | 1389 | return handle_response(af, skb, pd, cp, &iph, hooknum); |
Marco Angaroni | 39b9722 | 2016-04-05 18:26:29 +0200 | [diff] [blame] | 1390 | |
| 1391 | /* Check for real-server-started requests */ |
| 1392 | if (atomic_read(&ipvs->conn_out_counter)) { |
| 1393 | /* Currently only for UDP: |
| 1394 | * connection oriented protocols typically use |
| 1395 | * ephemeral ports for outgoing connections, so |
| 1396 | * related incoming responses would not match any VS |
| 1397 | */ |
| 1398 | if (pp->protocol == IPPROTO_UDP) { |
| 1399 | cp = __ip_vs_rs_conn_out(hooknum, ipvs, af, skb, &iph); |
| 1400 | if (likely(cp)) |
| 1401 | return handle_response(af, skb, pd, cp, &iph, |
| 1402 | hooknum); |
| 1403 | } |
| 1404 | } |
| 1405 | |
Eric W. Biederman | 2300f04 | 2015-09-21 13:02:51 -0500 | [diff] [blame] | 1406 | if (sysctl_nat_icmp_send(ipvs) && |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 1407 | (pp->protocol == IPPROTO_TCP || |
| 1408 | pp->protocol == IPPROTO_UDP || |
| 1409 | pp->protocol == IPPROTO_SCTP)) { |
| 1410 | __be16 _ports[2], *pptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1411 | |
Jesper Dangaard Brouer | 2f74713 | 2012-09-26 14:06:59 +0200 | [diff] [blame] | 1412 | pptr = frag_safe_skb_hp(skb, iph.len, |
| 1413 | sizeof(_ports), _ports, &iph); |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 1414 | if (pptr == NULL) |
| 1415 | return NF_ACCEPT; /* Not for me */ |
Eric W. Biederman | 48aed1b | 2015-09-21 13:01:50 -0500 | [diff] [blame] | 1416 | if (ip_vs_has_real_service(ipvs, af, iph.protocol, &iph.saddr, |
Julian Anastasov | 276472e | 2013-03-21 11:58:08 +0200 | [diff] [blame] | 1417 | pptr[0])) { |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 1418 | /* |
| 1419 | * Notify the real server: there is no |
| 1420 | * existing entry if it is not RST |
| 1421 | * packet or not TCP packet. |
| 1422 | */ |
| 1423 | if ((iph.protocol != IPPROTO_TCP && |
| 1424 | iph.protocol != IPPROTO_SCTP) |
| 1425 | || ((iph.protocol == IPPROTO_TCP |
| 1426 | && !is_tcp_reset(skb, iph.len)) |
| 1427 | || (iph.protocol == IPPROTO_SCTP |
| 1428 | && !is_sctp_abort(skb, |
| 1429 | iph.len)))) { |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1430 | #ifdef CONFIG_IP_VS_IPV6 |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 1431 | if (af == AF_INET6) { |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 1432 | if (!skb->dev) |
David Ahern | ed1c9f0 | 2015-10-01 08:49:04 -0700 | [diff] [blame] | 1433 | skb->dev = ipvs->net->loopback_dev; |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 1434 | icmpv6_send(skb, |
| 1435 | ICMPV6_DEST_UNREACH, |
| 1436 | ICMPV6_PORT_UNREACH, |
| 1437 | 0); |
| 1438 | } else |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1439 | #endif |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 1440 | icmp_send(skb, |
| 1441 | ICMP_DEST_UNREACH, |
| 1442 | ICMP_PORT_UNREACH, 0); |
| 1443 | return NF_DROP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | } |
| 1445 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | } |
Alex Gartrell | b0e010c | 2015-08-26 09:40:28 -0700 | [diff] [blame] | 1447 | IP_VS_DBG_PKT(12, af, pp, skb, iph.off, |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 1448 | "ip_vs_out: packet continues traversal as normal"); |
| 1449 | return NF_ACCEPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1450 | } |
| 1451 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1452 | /* |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 1453 | * It is hooked at the NF_INET_FORWARD and NF_INET_LOCAL_IN chain, |
| 1454 | * used only for VS/NAT. |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1455 | * Check if packet is reply for established ip_vs_conn. |
| 1456 | */ |
| 1457 | static unsigned int |
Eric W. Biederman | 06198b3 | 2015-09-18 14:33:06 -0500 | [diff] [blame] | 1458 | ip_vs_reply4(void *priv, struct sk_buff *skb, |
David S. Miller | 238e54c | 2015-04-03 20:32:56 -0400 | [diff] [blame] | 1459 | const struct nf_hook_state *state) |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1460 | { |
Eric W. Biederman | 1b75097 | 2015-09-21 13:02:52 -0500 | [diff] [blame] | 1461 | return ip_vs_out(net_ipvs(state->net), state->hook, skb, AF_INET); |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1462 | } |
| 1463 | |
| 1464 | /* |
| 1465 | * It is hooked at the NF_INET_LOCAL_OUT chain, used only for VS/NAT. |
| 1466 | * Check if packet is reply for established ip_vs_conn. |
| 1467 | */ |
| 1468 | static unsigned int |
Eric W. Biederman | 06198b3 | 2015-09-18 14:33:06 -0500 | [diff] [blame] | 1469 | ip_vs_local_reply4(void *priv, struct sk_buff *skb, |
David S. Miller | 238e54c | 2015-04-03 20:32:56 -0400 | [diff] [blame] | 1470 | const struct nf_hook_state *state) |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1471 | { |
Eric W. Biederman | 1b75097 | 2015-09-21 13:02:52 -0500 | [diff] [blame] | 1472 | return ip_vs_out(net_ipvs(state->net), state->hook, skb, AF_INET); |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1473 | } |
| 1474 | |
| 1475 | #ifdef CONFIG_IP_VS_IPV6 |
| 1476 | |
| 1477 | /* |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 1478 | * It is hooked at the NF_INET_FORWARD and NF_INET_LOCAL_IN chain, |
| 1479 | * used only for VS/NAT. |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1480 | * Check if packet is reply for established ip_vs_conn. |
| 1481 | */ |
| 1482 | static unsigned int |
Eric W. Biederman | 06198b3 | 2015-09-18 14:33:06 -0500 | [diff] [blame] | 1483 | ip_vs_reply6(void *priv, struct sk_buff *skb, |
David S. Miller | 238e54c | 2015-04-03 20:32:56 -0400 | [diff] [blame] | 1484 | const struct nf_hook_state *state) |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1485 | { |
Eric W. Biederman | 1b75097 | 2015-09-21 13:02:52 -0500 | [diff] [blame] | 1486 | return ip_vs_out(net_ipvs(state->net), state->hook, skb, AF_INET6); |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | /* |
| 1490 | * It is hooked at the NF_INET_LOCAL_OUT chain, used only for VS/NAT. |
| 1491 | * Check if packet is reply for established ip_vs_conn. |
| 1492 | */ |
| 1493 | static unsigned int |
Eric W. Biederman | 06198b3 | 2015-09-18 14:33:06 -0500 | [diff] [blame] | 1494 | ip_vs_local_reply6(void *priv, struct sk_buff *skb, |
David S. Miller | 238e54c | 2015-04-03 20:32:56 -0400 | [diff] [blame] | 1495 | const struct nf_hook_state *state) |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1496 | { |
Eric W. Biederman | 1b75097 | 2015-09-21 13:02:52 -0500 | [diff] [blame] | 1497 | return ip_vs_out(net_ipvs(state->net), state->hook, skb, AF_INET6); |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1498 | } |
| 1499 | |
| 1500 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | |
Alex Gartrell | 3b5ca61 | 2015-08-26 09:40:31 -0700 | [diff] [blame] | 1502 | static unsigned int |
Eric W. Biederman | d8f44c3 | 2015-09-21 13:02:43 -0500 | [diff] [blame] | 1503 | ip_vs_try_to_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb, |
| 1504 | struct ip_vs_proto_data *pd, |
Alex Gartrell | 3b5ca61 | 2015-08-26 09:40:31 -0700 | [diff] [blame] | 1505 | int *verdict, struct ip_vs_conn **cpp, |
| 1506 | struct ip_vs_iphdr *iph) |
| 1507 | { |
| 1508 | struct ip_vs_protocol *pp = pd->pp; |
| 1509 | |
| 1510 | if (!iph->fragoffs) { |
| 1511 | /* No (second) fragments need to enter here, as nf_defrag_ipv6 |
| 1512 | * replayed fragment zero will already have created the cp |
| 1513 | */ |
| 1514 | |
| 1515 | /* Schedule and create new connection entry into cpp */ |
Eric W. Biederman | d8f44c3 | 2015-09-21 13:02:43 -0500 | [diff] [blame] | 1516 | if (!pp->conn_schedule(ipvs, af, skb, pd, verdict, cpp, iph)) |
Alex Gartrell | 3b5ca61 | 2015-08-26 09:40:31 -0700 | [diff] [blame] | 1517 | return 0; |
| 1518 | } |
| 1519 | |
| 1520 | if (unlikely(!*cpp)) { |
| 1521 | /* sorry, all this trouble for a no-hit :) */ |
| 1522 | IP_VS_DBG_PKT(12, af, pp, skb, iph->off, |
| 1523 | "ip_vs_in: packet continues traversal as normal"); |
| 1524 | if (iph->fragoffs) { |
| 1525 | /* Fragment that couldn't be mapped to a conn entry |
| 1526 | * is missing module nf_defrag_ipv6 |
| 1527 | */ |
| 1528 | IP_VS_DBG_RL("Unhandled frag, load nf_defrag_ipv6\n"); |
| 1529 | IP_VS_DBG_PKT(7, af, pp, skb, iph->off, |
| 1530 | "unhandled fragment"); |
| 1531 | } |
| 1532 | *verdict = NF_ACCEPT; |
| 1533 | return 0; |
| 1534 | } |
| 1535 | |
| 1536 | return 1; |
| 1537 | } |
| 1538 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1539 | /* |
| 1540 | * Handle ICMP messages in the outside-to-inside direction (incoming). |
| 1541 | * Find any that might be relevant, check against existing connections, |
| 1542 | * forward to the right destination host if relevant. |
| 1543 | * Currently handles error types - unreachable, quench, ttl exceeded. |
| 1544 | */ |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 1545 | static int |
Eric W. Biederman | 6f2bcea | 2015-09-21 13:02:54 -0500 | [diff] [blame] | 1546 | ip_vs_in_icmp(struct netns_ipvs *ipvs, struct sk_buff *skb, int *related, |
| 1547 | unsigned int hooknum) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1548 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1549 | struct iphdr *iph; |
| 1550 | struct icmphdr _icmph, *ic; |
| 1551 | struct iphdr _ciph, *cih; /* The ip header contained within the ICMP */ |
Julius Volz | 51ef348 | 2008-09-02 15:55:40 +0200 | [diff] [blame] | 1552 | struct ip_vs_iphdr ciph; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1553 | struct ip_vs_conn *cp; |
| 1554 | struct ip_vs_protocol *pp; |
Hans Schillstrom | 9330419 | 2011-01-03 14:44:51 +0100 | [diff] [blame] | 1555 | struct ip_vs_proto_data *pd; |
Julian Anastasov | f2edb9f | 2012-07-20 11:59:52 +0300 | [diff] [blame] | 1556 | unsigned int offset, offset2, ihl, verdict; |
Alex Gartrell | 6044eef | 2015-08-26 09:40:37 -0700 | [diff] [blame] | 1557 | bool ipip, new_cp = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | |
| 1559 | *related = 1; |
| 1560 | |
| 1561 | /* reassemble IP fragments */ |
Paul Gortmaker | 56f8a75 | 2011-06-21 20:33:34 -0700 | [diff] [blame] | 1562 | if (ip_is_fragment(ip_hdr(skb))) { |
Eric W. Biederman | 57781c1 | 2015-09-21 13:03:01 -0500 | [diff] [blame] | 1563 | if (ip_vs_gather_frags(ipvs, skb, ip_vs_defrag_user(hooknum))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | return NF_STOLEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1565 | } |
| 1566 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 1567 | iph = ip_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1568 | offset = ihl = iph->ihl * 4; |
| 1569 | ic = skb_header_pointer(skb, offset, sizeof(_icmph), &_icmph); |
| 1570 | if (ic == NULL) |
| 1571 | return NF_DROP; |
| 1572 | |
Harvey Harrison | 14d5e83 | 2008-10-31 00:54:29 -0700 | [diff] [blame] | 1573 | IP_VS_DBG(12, "Incoming ICMP (%d,%d) %pI4->%pI4\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1574 | ic->type, ntohs(icmp_id(ic)), |
Harvey Harrison | 14d5e83 | 2008-10-31 00:54:29 -0700 | [diff] [blame] | 1575 | &iph->saddr, &iph->daddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1576 | |
| 1577 | /* |
| 1578 | * Work through seeing if this is for us. |
| 1579 | * These checks are supposed to be in an order that means easy |
| 1580 | * things are checked first to speed up processing.... however |
| 1581 | * this means that some packets will manage to get a long way |
| 1582 | * down this stack and then be rejected, but that's life. |
| 1583 | */ |
| 1584 | if ((ic->type != ICMP_DEST_UNREACH) && |
| 1585 | (ic->type != ICMP_SOURCE_QUENCH) && |
| 1586 | (ic->type != ICMP_TIME_EXCEEDED)) { |
| 1587 | *related = 0; |
| 1588 | return NF_ACCEPT; |
| 1589 | } |
| 1590 | |
| 1591 | /* Now find the contained IP header */ |
| 1592 | offset += sizeof(_icmph); |
| 1593 | cih = skb_header_pointer(skb, offset, sizeof(_ciph), &_ciph); |
| 1594 | if (cih == NULL) |
| 1595 | return NF_ACCEPT; /* The packet looks wrong, ignore */ |
| 1596 | |
Julian Anastasov | f2edb9f | 2012-07-20 11:59:52 +0300 | [diff] [blame] | 1597 | /* Special case for errors for IPIP packets */ |
| 1598 | ipip = false; |
| 1599 | if (cih->protocol == IPPROTO_IPIP) { |
| 1600 | if (unlikely(cih->frag_off & htons(IP_OFFSET))) |
| 1601 | return NF_ACCEPT; |
| 1602 | /* Error for our IPIP must arrive at LOCAL_IN */ |
| 1603 | if (!(skb_rtable(skb)->rt_flags & RTCF_LOCAL)) |
| 1604 | return NF_ACCEPT; |
| 1605 | offset += cih->ihl * 4; |
| 1606 | cih = skb_header_pointer(skb, offset, sizeof(_ciph), &_ciph); |
| 1607 | if (cih == NULL) |
| 1608 | return NF_ACCEPT; /* The packet looks wrong, ignore */ |
| 1609 | ipip = true; |
| 1610 | } |
| 1611 | |
Eric W. Biederman | 18d6ade | 2015-09-21 13:02:01 -0500 | [diff] [blame] | 1612 | pd = ip_vs_proto_data_get(ipvs, cih->protocol); |
Hans Schillstrom | 9330419 | 2011-01-03 14:44:51 +0100 | [diff] [blame] | 1613 | if (!pd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1614 | return NF_ACCEPT; |
Hans Schillstrom | 9330419 | 2011-01-03 14:44:51 +0100 | [diff] [blame] | 1615 | pp = pd->pp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1616 | |
| 1617 | /* Is the embedded protocol header present? */ |
YOSHIFUJI Hideaki | 4412ec4 | 2007-03-07 14:19:10 +0900 | [diff] [blame] | 1618 | if (unlikely(cih->frag_off & htons(IP_OFFSET) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1619 | pp->dont_defrag)) |
| 1620 | return NF_ACCEPT; |
| 1621 | |
Julian Anastasov | 0d79641 | 2010-10-17 16:46:17 +0300 | [diff] [blame] | 1622 | IP_VS_DBG_PKT(11, AF_INET, pp, skb, offset, |
| 1623 | "Checking incoming ICMP for"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1624 | |
Julian Anastasov | f2edb9f | 2012-07-20 11:59:52 +0300 | [diff] [blame] | 1625 | offset2 = offset; |
Alex Gartrell | 4fd9bee | 2015-08-26 09:40:29 -0700 | [diff] [blame] | 1626 | ip_vs_fill_iph_skb_icmp(AF_INET, skb, offset, !ipip, &ciph); |
Jesper Dangaard Brouer | 63dca2c | 2012-09-26 14:06:41 +0200 | [diff] [blame] | 1627 | offset = ciph.len; |
Alex Gartrell | b0e010c | 2015-08-26 09:40:28 -0700 | [diff] [blame] | 1628 | |
Julian Anastasov | f2edb9f | 2012-07-20 11:59:52 +0300 | [diff] [blame] | 1629 | /* The embedded headers contain source and dest in reverse order. |
| 1630 | * For IPIP this is error for request, not for reply. |
| 1631 | */ |
Eric W. Biederman | ab16197 | 2015-09-21 13:02:38 -0500 | [diff] [blame] | 1632 | cp = pp->conn_in_get(ipvs, AF_INET, skb, &ciph); |
Alex Gartrell | 6044eef | 2015-08-26 09:40:37 -0700 | [diff] [blame] | 1633 | |
| 1634 | if (!cp) { |
| 1635 | int v; |
| 1636 | |
Eric W. Biederman | a47b430 | 2015-09-21 13:02:00 -0500 | [diff] [blame] | 1637 | if (!sysctl_schedule_icmp(ipvs)) |
Alex Gartrell | 6044eef | 2015-08-26 09:40:37 -0700 | [diff] [blame] | 1638 | return NF_ACCEPT; |
| 1639 | |
Eric W. Biederman | d8f44c3 | 2015-09-21 13:02:43 -0500 | [diff] [blame] | 1640 | if (!ip_vs_try_to_schedule(ipvs, AF_INET, skb, pd, &v, &cp, &ciph)) |
Alex Gartrell | 6044eef | 2015-08-26 09:40:37 -0700 | [diff] [blame] | 1641 | return v; |
| 1642 | new_cp = true; |
| 1643 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1644 | |
| 1645 | verdict = NF_DROP; |
| 1646 | |
| 1647 | /* Ensure the checksum is correct */ |
Herbert Xu | 6047637 | 2007-04-09 11:59:39 -0700 | [diff] [blame] | 1648 | if (!skb_csum_unnecessary(skb) && ip_vs_checksum_complete(skb, ihl)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1649 | /* Failed checksum! */ |
Harvey Harrison | 14d5e83 | 2008-10-31 00:54:29 -0700 | [diff] [blame] | 1650 | IP_VS_DBG(1, "Incoming ICMP: failed checksum from %pI4!\n", |
| 1651 | &iph->saddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1652 | goto out; |
| 1653 | } |
| 1654 | |
Julian Anastasov | f2edb9f | 2012-07-20 11:59:52 +0300 | [diff] [blame] | 1655 | if (ipip) { |
| 1656 | __be32 info = ic->un.gateway; |
Peter Christensen | f44a5f4 | 2014-05-24 21:40:12 +0200 | [diff] [blame] | 1657 | __u8 type = ic->type; |
| 1658 | __u8 code = ic->code; |
Julian Anastasov | f2edb9f | 2012-07-20 11:59:52 +0300 | [diff] [blame] | 1659 | |
| 1660 | /* Update the MTU */ |
| 1661 | if (ic->type == ICMP_DEST_UNREACH && |
| 1662 | ic->code == ICMP_FRAG_NEEDED) { |
| 1663 | struct ip_vs_dest *dest = cp->dest; |
| 1664 | u32 mtu = ntohs(ic->un.frag.mtu); |
Peter Christensen | f44a5f4 | 2014-05-24 21:40:12 +0200 | [diff] [blame] | 1665 | __be16 frag_off = cih->frag_off; |
Julian Anastasov | f2edb9f | 2012-07-20 11:59:52 +0300 | [diff] [blame] | 1666 | |
| 1667 | /* Strip outer IP and ICMP, go to IPIP header */ |
Peter Christensen | f44a5f4 | 2014-05-24 21:40:12 +0200 | [diff] [blame] | 1668 | if (pskb_pull(skb, ihl + sizeof(_icmph)) == NULL) |
| 1669 | goto ignore_ipip; |
Julian Anastasov | f2edb9f | 2012-07-20 11:59:52 +0300 | [diff] [blame] | 1670 | offset2 -= ihl + sizeof(_icmph); |
| 1671 | skb_reset_network_header(skb); |
| 1672 | IP_VS_DBG(12, "ICMP for IPIP %pI4->%pI4: mtu=%u\n", |
| 1673 | &ip_hdr(skb)->saddr, &ip_hdr(skb)->daddr, mtu); |
Eric W. Biederman | 6f2bcea | 2015-09-21 13:02:54 -0500 | [diff] [blame] | 1674 | ipv4_update_pmtu(skb, ipvs->net, |
Julian Anastasov | f2edb9f | 2012-07-20 11:59:52 +0300 | [diff] [blame] | 1675 | mtu, 0, 0, 0, 0); |
Julian Anastasov | f2edb9f | 2012-07-20 11:59:52 +0300 | [diff] [blame] | 1676 | /* Client uses PMTUD? */ |
Peter Christensen | f44a5f4 | 2014-05-24 21:40:12 +0200 | [diff] [blame] | 1677 | if (!(frag_off & htons(IP_DF))) |
Julian Anastasov | f2edb9f | 2012-07-20 11:59:52 +0300 | [diff] [blame] | 1678 | goto ignore_ipip; |
| 1679 | /* Prefer the resulting PMTU */ |
| 1680 | if (dest) { |
Julian Anastasov | 026ace0 | 2013-03-21 11:58:06 +0200 | [diff] [blame] | 1681 | struct ip_vs_dest_dst *dest_dst; |
| 1682 | |
| 1683 | rcu_read_lock(); |
| 1684 | dest_dst = rcu_dereference(dest->dest_dst); |
| 1685 | if (dest_dst) |
| 1686 | mtu = dst_mtu(dest_dst->dst_cache); |
| 1687 | rcu_read_unlock(); |
Julian Anastasov | f2edb9f | 2012-07-20 11:59:52 +0300 | [diff] [blame] | 1688 | } |
| 1689 | if (mtu > 68 + sizeof(struct iphdr)) |
| 1690 | mtu -= sizeof(struct iphdr); |
| 1691 | info = htonl(mtu); |
| 1692 | } |
| 1693 | /* Strip outer IP, ICMP and IPIP, go to IP header of |
| 1694 | * original request. |
| 1695 | */ |
Peter Christensen | f44a5f4 | 2014-05-24 21:40:12 +0200 | [diff] [blame] | 1696 | if (pskb_pull(skb, offset2) == NULL) |
| 1697 | goto ignore_ipip; |
Julian Anastasov | f2edb9f | 2012-07-20 11:59:52 +0300 | [diff] [blame] | 1698 | skb_reset_network_header(skb); |
| 1699 | IP_VS_DBG(12, "Sending ICMP for %pI4->%pI4: t=%u, c=%u, i=%u\n", |
| 1700 | &ip_hdr(skb)->saddr, &ip_hdr(skb)->daddr, |
Peter Christensen | f44a5f4 | 2014-05-24 21:40:12 +0200 | [diff] [blame] | 1701 | type, code, ntohl(info)); |
| 1702 | icmp_send(skb, type, code, info); |
Julian Anastasov | f2edb9f | 2012-07-20 11:59:52 +0300 | [diff] [blame] | 1703 | /* ICMP can be shorter but anyways, account it */ |
| 1704 | ip_vs_out_stats(cp, skb); |
| 1705 | |
| 1706 | ignore_ipip: |
| 1707 | consume_skb(skb); |
| 1708 | verdict = NF_STOLEN; |
| 1709 | goto out; |
| 1710 | } |
| 1711 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1712 | /* do the statistics and put it back */ |
| 1713 | ip_vs_in_stats(cp, skb); |
Julian Anastasov | 06f3d7f | 2013-06-18 10:08:06 +0300 | [diff] [blame] | 1714 | if (IPPROTO_TCP == cih->protocol || IPPROTO_UDP == cih->protocol || |
| 1715 | IPPROTO_SCTP == cih->protocol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1716 | offset += 2 * sizeof(__u16); |
Jesper Dangaard Brouer | d4383f0 | 2012-09-26 14:07:17 +0200 | [diff] [blame] | 1717 | verdict = ip_vs_icmp_xmit(skb, cp, pp, offset, hooknum, &ciph); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1718 | |
Hans Schillstrom | 552ad65 | 2011-06-13 12:19:26 +0200 | [diff] [blame] | 1719 | out: |
Alex Gartrell | 6044eef | 2015-08-26 09:40:37 -0700 | [diff] [blame] | 1720 | if (likely(!new_cp)) |
| 1721 | __ip_vs_conn_put(cp); |
| 1722 | else |
| 1723 | ip_vs_conn_put(cp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1724 | |
| 1725 | return verdict; |
| 1726 | } |
| 1727 | |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1728 | #ifdef CONFIG_IP_VS_IPV6 |
Eric W. Biederman | 6f2bcea | 2015-09-21 13:02:54 -0500 | [diff] [blame] | 1729 | static int ip_vs_in_icmp_v6(struct netns_ipvs *ipvs, struct sk_buff *skb, |
| 1730 | int *related, unsigned int hooknum, |
| 1731 | struct ip_vs_iphdr *iph) |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1732 | { |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1733 | struct icmp6hdr _icmph, *ic; |
Jesper Dangaard Brouer | 63dca2c | 2012-09-26 14:06:41 +0200 | [diff] [blame] | 1734 | struct ip_vs_iphdr ciph = {.flags = 0, .fragoffs = 0};/*Contained IP */ |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1735 | struct ip_vs_conn *cp; |
| 1736 | struct ip_vs_protocol *pp; |
Hans Schillstrom | 9330419 | 2011-01-03 14:44:51 +0100 | [diff] [blame] | 1737 | struct ip_vs_proto_data *pd; |
Alex Gartrell | b0e010c | 2015-08-26 09:40:28 -0700 | [diff] [blame] | 1738 | unsigned int offset, verdict; |
Alex Gartrell | 6044eef | 2015-08-26 09:40:37 -0700 | [diff] [blame] | 1739 | bool new_cp = false; |
Jesper Dangaard Brouer | 63dca2c | 2012-09-26 14:06:41 +0200 | [diff] [blame] | 1740 | |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1741 | *related = 1; |
| 1742 | |
Jesper Dangaard Brouer | 2f74713 | 2012-09-26 14:06:59 +0200 | [diff] [blame] | 1743 | ic = frag_safe_skb_hp(skb, iph->len, sizeof(_icmph), &_icmph, iph); |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1744 | if (ic == NULL) |
| 1745 | return NF_DROP; |
| 1746 | |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1747 | /* |
| 1748 | * Work through seeing if this is for us. |
| 1749 | * These checks are supposed to be in an order that means easy |
| 1750 | * things are checked first to speed up processing.... however |
| 1751 | * this means that some packets will manage to get a long way |
| 1752 | * down this stack and then be rejected, but that's life. |
| 1753 | */ |
Jesper Dangaard Brouer | 2fab891 | 2012-09-26 14:06:11 +0200 | [diff] [blame] | 1754 | if (ic->icmp6_type & ICMPV6_INFOMSG_MASK) { |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1755 | *related = 0; |
| 1756 | return NF_ACCEPT; |
| 1757 | } |
Jesper Dangaard Brouer | 2f74713 | 2012-09-26 14:06:59 +0200 | [diff] [blame] | 1758 | /* Fragment header that is before ICMP header tells us that: |
| 1759 | * it's not an error message since they can't be fragmented. |
| 1760 | */ |
David S. Miller | e716503 | 2012-11-30 12:01:30 -0500 | [diff] [blame] | 1761 | if (iph->flags & IP6_FH_F_FRAG) |
Jesper Dangaard Brouer | 2f74713 | 2012-09-26 14:06:59 +0200 | [diff] [blame] | 1762 | return NF_DROP; |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1763 | |
Jesper Dangaard Brouer | 63dca2c | 2012-09-26 14:06:41 +0200 | [diff] [blame] | 1764 | IP_VS_DBG(8, "Incoming ICMPv6 (%d,%d) %pI6c->%pI6c\n", |
| 1765 | ic->icmp6_type, ntohs(icmpv6_id(ic)), |
| 1766 | &iph->saddr, &iph->daddr); |
| 1767 | |
Alex Gartrell | b0e010c | 2015-08-26 09:40:28 -0700 | [diff] [blame] | 1768 | offset = iph->len + sizeof(_icmph); |
Alex Gartrell | 4fd9bee | 2015-08-26 09:40:29 -0700 | [diff] [blame] | 1769 | if (!ip_vs_fill_iph_skb_icmp(AF_INET6, skb, offset, true, &ciph)) |
Alex Gartrell | b0e010c | 2015-08-26 09:40:28 -0700 | [diff] [blame] | 1770 | return NF_ACCEPT; |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1771 | |
Eric W. Biederman | 18d6ade | 2015-09-21 13:02:01 -0500 | [diff] [blame] | 1772 | pd = ip_vs_proto_data_get(ipvs, ciph.protocol); |
Hans Schillstrom | 9330419 | 2011-01-03 14:44:51 +0100 | [diff] [blame] | 1773 | if (!pd) |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1774 | return NF_ACCEPT; |
Hans Schillstrom | 9330419 | 2011-01-03 14:44:51 +0100 | [diff] [blame] | 1775 | pp = pd->pp; |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1776 | |
Jesper Dangaard Brouer | 63dca2c | 2012-09-26 14:06:41 +0200 | [diff] [blame] | 1777 | /* Cannot handle fragmented embedded protocol */ |
| 1778 | if (ciph.fragoffs) |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1779 | return NF_ACCEPT; |
| 1780 | |
Alex Gartrell | b0e010c | 2015-08-26 09:40:28 -0700 | [diff] [blame] | 1781 | IP_VS_DBG_PKT(11, AF_INET6, pp, skb, offset, |
Julian Anastasov | 0d79641 | 2010-10-17 16:46:17 +0300 | [diff] [blame] | 1782 | "Checking incoming ICMPv6 for"); |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1783 | |
Jesper Dangaard Brouer | 2f74713 | 2012-09-26 14:06:59 +0200 | [diff] [blame] | 1784 | /* The embedded headers contain source and dest in reverse order |
| 1785 | * if not from localhost |
| 1786 | */ |
Eric W. Biederman | ab16197 | 2015-09-21 13:02:38 -0500 | [diff] [blame] | 1787 | cp = pp->conn_in_get(ipvs, AF_INET6, skb, &ciph); |
Jesper Dangaard Brouer | 2f74713 | 2012-09-26 14:06:59 +0200 | [diff] [blame] | 1788 | |
Alex Gartrell | 6044eef | 2015-08-26 09:40:37 -0700 | [diff] [blame] | 1789 | if (!cp) { |
| 1790 | int v; |
| 1791 | |
Eric W. Biederman | a47b430 | 2015-09-21 13:02:00 -0500 | [diff] [blame] | 1792 | if (!sysctl_schedule_icmp(ipvs)) |
Alex Gartrell | 6044eef | 2015-08-26 09:40:37 -0700 | [diff] [blame] | 1793 | return NF_ACCEPT; |
| 1794 | |
Eric W. Biederman | d8f44c3 | 2015-09-21 13:02:43 -0500 | [diff] [blame] | 1795 | if (!ip_vs_try_to_schedule(ipvs, AF_INET6, skb, pd, &v, &cp, &ciph)) |
Alex Gartrell | 6044eef | 2015-08-26 09:40:37 -0700 | [diff] [blame] | 1796 | return v; |
| 1797 | |
| 1798 | new_cp = true; |
| 1799 | } |
| 1800 | |
Jesper Dangaard Brouer | 2f74713 | 2012-09-26 14:06:59 +0200 | [diff] [blame] | 1801 | /* VS/TUN, VS/DR and LOCALNODE just let it go */ |
| 1802 | if ((hooknum == NF_INET_LOCAL_OUT) && |
| 1803 | (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ)) { |
Alex Gartrell | 6044eef | 2015-08-26 09:40:37 -0700 | [diff] [blame] | 1804 | verdict = NF_ACCEPT; |
| 1805 | goto out; |
Jesper Dangaard Brouer | 2f74713 | 2012-09-26 14:06:59 +0200 | [diff] [blame] | 1806 | } |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1807 | |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1808 | /* do the statistics and put it back */ |
| 1809 | ip_vs_in_stats(cp, skb); |
Jesper Dangaard Brouer | 63dca2c | 2012-09-26 14:06:41 +0200 | [diff] [blame] | 1810 | |
| 1811 | /* Need to mangle contained IPv6 header in ICMPv6 packet */ |
Alex Gartrell | b0e010c | 2015-08-26 09:40:28 -0700 | [diff] [blame] | 1812 | offset = ciph.len; |
Jesper Dangaard Brouer | 63dca2c | 2012-09-26 14:06:41 +0200 | [diff] [blame] | 1813 | if (IPPROTO_TCP == ciph.protocol || IPPROTO_UDP == ciph.protocol || |
| 1814 | IPPROTO_SCTP == ciph.protocol) |
Alex Gartrell | b0e010c | 2015-08-26 09:40:28 -0700 | [diff] [blame] | 1815 | offset += 2 * sizeof(__u16); /* Also mangle ports */ |
Jesper Dangaard Brouer | 63dca2c | 2012-09-26 14:06:41 +0200 | [diff] [blame] | 1816 | |
Alex Gartrell | b0e010c | 2015-08-26 09:40:28 -0700 | [diff] [blame] | 1817 | verdict = ip_vs_icmp_xmit_v6(skb, cp, pp, offset, hooknum, &ciph); |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1818 | |
Alex Gartrell | 6044eef | 2015-08-26 09:40:37 -0700 | [diff] [blame] | 1819 | out: |
| 1820 | if (likely(!new_cp)) |
| 1821 | __ip_vs_conn_put(cp); |
| 1822 | else |
| 1823 | ip_vs_conn_put(cp); |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 1824 | |
| 1825 | return verdict; |
| 1826 | } |
| 1827 | #endif |
| 1828 | |
| 1829 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1830 | /* |
| 1831 | * Check if it's for virtual services, look it up, |
| 1832 | * and send it on its way... |
| 1833 | */ |
| 1834 | static unsigned int |
Eric W. Biederman | 6e385bb | 2015-09-21 13:02:53 -0500 | [diff] [blame] | 1835 | ip_vs_in(struct netns_ipvs *ipvs, unsigned int hooknum, struct sk_buff *skb, int af) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | { |
Julius Volz | 51ef348 | 2008-09-02 15:55:40 +0200 | [diff] [blame] | 1837 | struct ip_vs_iphdr iph; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1838 | struct ip_vs_protocol *pp; |
Hans Schillstrom | 9330419 | 2011-01-03 14:44:51 +0100 | [diff] [blame] | 1839 | struct ip_vs_proto_data *pd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | struct ip_vs_conn *cp; |
Simon Horman | 4a516f1 | 2011-09-16 14:11:49 +0900 | [diff] [blame] | 1841 | int ret, pkts; |
Marcelo Ricardo Leitner | d752c36 | 2015-02-23 15:02:34 -0300 | [diff] [blame] | 1842 | int conn_reuse_mode; |
Eric Dumazet | 340c78e | 2015-11-12 09:14:12 -0800 | [diff] [blame] | 1843 | struct sock *sk; |
Julius Volz | 51ef348 | 2008-09-02 15:55:40 +0200 | [diff] [blame] | 1844 | |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 1845 | /* Already marked as IPVS request or reply? */ |
| 1846 | if (skb->ipvs_property) |
| 1847 | return NF_ACCEPT; |
| 1848 | |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 1849 | /* |
| 1850 | * Big tappo: |
| 1851 | * - remote client: only PACKET_HOST |
| 1852 | * - route: used for struct net when skb->dev is unset |
| 1853 | */ |
| 1854 | if (unlikely((skb->pkt_type != PACKET_HOST && |
| 1855 | hooknum != NF_INET_LOCAL_OUT) || |
| 1856 | !skb_dst(skb))) { |
Alex Gartrell | 4fd9bee | 2015-08-26 09:40:29 -0700 | [diff] [blame] | 1857 | ip_vs_fill_iph_skb(af, skb, false, &iph); |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 1858 | IP_VS_DBG_BUF(12, "packet type=%d proto=%d daddr=%s" |
| 1859 | " ignored in hook %u\n", |
| 1860 | skb->pkt_type, iph.protocol, |
| 1861 | IP_VS_DBG_ADDR(af, &iph.daddr), hooknum); |
| 1862 | return NF_ACCEPT; |
| 1863 | } |
Hans Schillstrom | 7a4f076 | 2011-05-03 22:09:31 +0200 | [diff] [blame] | 1864 | /* ipvs enabled in this netns ? */ |
Julian Anastasov | 0c12582 | 2013-03-09 23:25:04 +0200 | [diff] [blame] | 1865 | if (unlikely(sysctl_backup_only(ipvs) || !ipvs->enable)) |
Hans Schillstrom | 7a4f076 | 2011-05-03 22:09:31 +0200 | [diff] [blame] | 1866 | return NF_ACCEPT; |
| 1867 | |
Alex Gartrell | 4fd9bee | 2015-08-26 09:40:29 -0700 | [diff] [blame] | 1868 | ip_vs_fill_iph_skb(af, skb, false, &iph); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1869 | |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 1870 | /* Bad... Do not break raw sockets */ |
Eric Dumazet | 340c78e | 2015-11-12 09:14:12 -0800 | [diff] [blame] | 1871 | sk = skb_to_full_sk(skb); |
| 1872 | if (unlikely(sk && hooknum == NF_INET_LOCAL_OUT && |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 1873 | af == AF_INET)) { |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 1874 | |
Eric Dumazet | 340c78e | 2015-11-12 09:14:12 -0800 | [diff] [blame] | 1875 | if (sk->sk_family == PF_INET && inet_sk(sk)->nodefrag) |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 1876 | return NF_ACCEPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1877 | } |
| 1878 | |
Julius Volz | 94b2655 | 2009-08-31 16:22:23 +0200 | [diff] [blame] | 1879 | #ifdef CONFIG_IP_VS_IPV6 |
| 1880 | if (af == AF_INET6) { |
| 1881 | if (unlikely(iph.protocol == IPPROTO_ICMPV6)) { |
Julian Anastasov | 1ca5bb5 | 2010-10-17 16:32:29 +0300 | [diff] [blame] | 1882 | int related; |
Eric W. Biederman | 6f2bcea | 2015-09-21 13:02:54 -0500 | [diff] [blame] | 1883 | int verdict = ip_vs_in_icmp_v6(ipvs, skb, &related, |
| 1884 | hooknum, &iph); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1885 | |
Julius Volz | 94b2655 | 2009-08-31 16:22:23 +0200 | [diff] [blame] | 1886 | if (related) |
| 1887 | return verdict; |
Julius Volz | 94b2655 | 2009-08-31 16:22:23 +0200 | [diff] [blame] | 1888 | } |
| 1889 | } else |
| 1890 | #endif |
| 1891 | if (unlikely(iph.protocol == IPPROTO_ICMP)) { |
Julian Anastasov | 1ca5bb5 | 2010-10-17 16:32:29 +0300 | [diff] [blame] | 1892 | int related; |
Eric W. Biederman | 6f2bcea | 2015-09-21 13:02:54 -0500 | [diff] [blame] | 1893 | int verdict = ip_vs_in_icmp(ipvs, skb, &related, |
| 1894 | hooknum); |
Julius Volz | 94b2655 | 2009-08-31 16:22:23 +0200 | [diff] [blame] | 1895 | |
| 1896 | if (related) |
| 1897 | return verdict; |
Julius Volz | 94b2655 | 2009-08-31 16:22:23 +0200 | [diff] [blame] | 1898 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | |
| 1900 | /* Protocol supported? */ |
Eric W. Biederman | 18d6ade | 2015-09-21 13:02:01 -0500 | [diff] [blame] | 1901 | pd = ip_vs_proto_data_get(ipvs, iph.protocol); |
Alex Gartrell | 4e47809 | 2015-09-14 23:23:05 -0700 | [diff] [blame] | 1902 | if (unlikely(!pd)) { |
| 1903 | /* The only way we'll see this packet again is if it's |
| 1904 | * encapsulated, so mark it with ipvs_property=1 so we |
| 1905 | * skip it if we're ignoring tunneled packets |
| 1906 | */ |
| 1907 | if (sysctl_ignore_tunneled(ipvs)) |
| 1908 | skb->ipvs_property = 1; |
| 1909 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | return NF_ACCEPT; |
Alex Gartrell | 4e47809 | 2015-09-14 23:23:05 -0700 | [diff] [blame] | 1911 | } |
Hans Schillstrom | 9330419 | 2011-01-03 14:44:51 +0100 | [diff] [blame] | 1912 | pp = pd->pp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | /* |
| 1914 | * Check if the packet belongs to an existing connection entry |
| 1915 | */ |
Eric W. Biederman | ab16197 | 2015-09-21 13:02:38 -0500 | [diff] [blame] | 1916 | cp = pp->conn_in_get(ipvs, af, skb, &iph); |
Grzegorz Lyczba | dc7b3eb | 2013-05-13 23:56:24 +0200 | [diff] [blame] | 1917 | |
Marcelo Ricardo Leitner | d752c36 | 2015-02-23 15:02:34 -0300 | [diff] [blame] | 1918 | conn_reuse_mode = sysctl_conn_reuse_mode(ipvs); |
Julian Anastasov | f719e37 | 2016-03-05 15:03:22 +0200 | [diff] [blame] | 1919 | if (conn_reuse_mode && !iph.fragoffs && is_new_conn(skb, &iph) && cp) { |
| 1920 | bool uses_ct = false, resched = false; |
| 1921 | |
| 1922 | if (unlikely(sysctl_expire_nodest_conn(ipvs)) && cp->dest && |
| 1923 | unlikely(!atomic_read(&cp->dest->weight))) { |
| 1924 | resched = true; |
| 1925 | uses_ct = ip_vs_conn_uses_conntrack(cp, skb); |
| 1926 | } else if (is_new_conn_expected(cp, conn_reuse_mode)) { |
| 1927 | uses_ct = ip_vs_conn_uses_conntrack(cp, skb); |
| 1928 | if (!atomic_read(&cp->n_control)) { |
| 1929 | resched = true; |
| 1930 | } else { |
| 1931 | /* Do not reschedule controlling connection |
| 1932 | * that uses conntrack while it is still |
| 1933 | * referenced by controlled connection(s). |
| 1934 | */ |
| 1935 | resched = !uses_ct; |
| 1936 | } |
| 1937 | } |
| 1938 | |
| 1939 | if (resched) { |
| 1940 | if (!atomic_read(&cp->n_control)) |
| 1941 | ip_vs_conn_expire_now(cp); |
| 1942 | __ip_vs_conn_put(cp); |
| 1943 | if (uses_ct) |
| 1944 | return NF_DROP; |
| 1945 | cp = NULL; |
| 1946 | } |
Grzegorz Lyczba | dc7b3eb | 2013-05-13 23:56:24 +0200 | [diff] [blame] | 1947 | } |
| 1948 | |
Alex Gartrell | 3b5ca61 | 2015-08-26 09:40:31 -0700 | [diff] [blame] | 1949 | if (unlikely(!cp)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1950 | int v; |
| 1951 | |
Eric W. Biederman | d8f44c3 | 2015-09-21 13:02:43 -0500 | [diff] [blame] | 1952 | if (!ip_vs_try_to_schedule(ipvs, af, skb, pd, &v, &cp, &iph)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1953 | return v; |
| 1954 | } |
| 1955 | |
Alex Gartrell | b0e010c | 2015-08-26 09:40:28 -0700 | [diff] [blame] | 1956 | IP_VS_DBG_PKT(11, af, pp, skb, iph.off, "Incoming packet"); |
Alex Gartrell | 3b5ca61 | 2015-08-26 09:40:31 -0700 | [diff] [blame] | 1957 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1958 | /* Check the server status */ |
| 1959 | if (cp->dest && !(cp->dest->flags & IP_VS_DEST_F_AVAILABLE)) { |
| 1960 | /* the destination server is not available */ |
| 1961 | |
Simon Horman | 71a8ab6 | 2011-02-04 18:33:01 +0900 | [diff] [blame] | 1962 | if (sysctl_expire_nodest_conn(ipvs)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | /* try to expire the connection immediately */ |
| 1964 | ip_vs_conn_expire_now(cp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1965 | } |
Julian Anastasov | dc8103f | 2005-11-08 09:40:05 -0800 | [diff] [blame] | 1966 | /* don't restart its timer, and silently |
| 1967 | drop the packet. */ |
| 1968 | __ip_vs_conn_put(cp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1969 | return NF_DROP; |
| 1970 | } |
| 1971 | |
| 1972 | ip_vs_in_stats(cp, skb); |
Simon Horman | 4a516f1 | 2011-09-16 14:11:49 +0900 | [diff] [blame] | 1973 | ip_vs_set_state(cp, IP_VS_DIR_INPUT, skb, pd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1974 | if (cp->packet_xmit) |
Jesper Dangaard Brouer | d4383f0 | 2012-09-26 14:07:17 +0200 | [diff] [blame] | 1975 | ret = cp->packet_xmit(skb, cp, pp, &iph); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1976 | /* do not touch skb anymore */ |
| 1977 | else { |
| 1978 | IP_VS_DBG_RL("warning: packet_xmit is null"); |
| 1979 | ret = NF_ACCEPT; |
| 1980 | } |
| 1981 | |
Rumen G. Bogdanovski | efac527 | 2007-11-07 02:36:55 -0800 | [diff] [blame] | 1982 | /* Increase its packet counter and check if it is needed |
| 1983 | * to be synchronized |
| 1984 | * |
| 1985 | * Sync connection if it is about to close to |
| 1986 | * encorage the standby servers to update the connections timeout |
Hans Schillstrom | 986a075 | 2010-11-19 14:25:13 +0100 | [diff] [blame] | 1987 | * |
| 1988 | * For ONE_PKT let ip_vs_sync_conn() do the filter work. |
Rumen G. Bogdanovski | efac527 | 2007-11-07 02:36:55 -0800 | [diff] [blame] | 1989 | */ |
Hans Schillstrom | f131315 | 2011-01-03 14:44:55 +0100 | [diff] [blame] | 1990 | |
Hans Schillstrom | 986a075 | 2010-11-19 14:25:13 +0100 | [diff] [blame] | 1991 | if (cp->flags & IP_VS_CONN_F_ONE_PACKET) |
Simon Horman | 59e0350 | 2011-02-04 18:33:01 +0900 | [diff] [blame] | 1992 | pkts = sysctl_sync_threshold(ipvs); |
Hans Schillstrom | 986a075 | 2010-11-19 14:25:13 +0100 | [diff] [blame] | 1993 | else |
| 1994 | pkts = atomic_add_return(1, &cp->in_pkts); |
| 1995 | |
Julian Anastasov | 749c42b | 2012-04-24 23:46:40 +0300 | [diff] [blame] | 1996 | if (ipvs->sync_state & IP_VS_STATE_MASTER) |
Eric W. Biederman | b61a8c1 | 2015-09-21 13:02:17 -0500 | [diff] [blame] | 1997 | ip_vs_sync_conn(ipvs, cp, pkts); |
Marco Angaroni | 698e2a8 | 2016-04-26 21:20:22 +0200 | [diff] [blame] | 1998 | else if ((cp->flags & IP_VS_CONN_F_ONE_PACKET) && cp->control) |
| 1999 | /* increment is done inside ip_vs_sync_conn too */ |
| 2000 | atomic_inc(&cp->control->in_pkts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2001 | |
| 2002 | ip_vs_conn_put(cp); |
| 2003 | return ret; |
| 2004 | } |
| 2005 | |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 2006 | /* |
| 2007 | * AF_INET handler in NF_INET_LOCAL_IN chain |
| 2008 | * Schedule and forward packets from remote clients |
| 2009 | */ |
| 2010 | static unsigned int |
Eric W. Biederman | 06198b3 | 2015-09-18 14:33:06 -0500 | [diff] [blame] | 2011 | ip_vs_remote_request4(void *priv, struct sk_buff *skb, |
David S. Miller | 238e54c | 2015-04-03 20:32:56 -0400 | [diff] [blame] | 2012 | const struct nf_hook_state *state) |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 2013 | { |
Eric W. Biederman | 6e385bb | 2015-09-21 13:02:53 -0500 | [diff] [blame] | 2014 | return ip_vs_in(net_ipvs(state->net), state->hook, skb, AF_INET); |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 2015 | } |
| 2016 | |
| 2017 | /* |
| 2018 | * AF_INET handler in NF_INET_LOCAL_OUT chain |
| 2019 | * Schedule and forward packets from local clients |
| 2020 | */ |
| 2021 | static unsigned int |
Eric W. Biederman | 06198b3 | 2015-09-18 14:33:06 -0500 | [diff] [blame] | 2022 | ip_vs_local_request4(void *priv, struct sk_buff *skb, |
David S. Miller | 238e54c | 2015-04-03 20:32:56 -0400 | [diff] [blame] | 2023 | const struct nf_hook_state *state) |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 2024 | { |
Eric W. Biederman | 6e385bb | 2015-09-21 13:02:53 -0500 | [diff] [blame] | 2025 | return ip_vs_in(net_ipvs(state->net), state->hook, skb, AF_INET); |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 2026 | } |
| 2027 | |
| 2028 | #ifdef CONFIG_IP_VS_IPV6 |
| 2029 | |
| 2030 | /* |
| 2031 | * AF_INET6 handler in NF_INET_LOCAL_IN chain |
| 2032 | * Schedule and forward packets from remote clients |
| 2033 | */ |
| 2034 | static unsigned int |
Eric W. Biederman | 06198b3 | 2015-09-18 14:33:06 -0500 | [diff] [blame] | 2035 | ip_vs_remote_request6(void *priv, struct sk_buff *skb, |
David S. Miller | 238e54c | 2015-04-03 20:32:56 -0400 | [diff] [blame] | 2036 | const struct nf_hook_state *state) |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 2037 | { |
Eric W. Biederman | 6e385bb | 2015-09-21 13:02:53 -0500 | [diff] [blame] | 2038 | return ip_vs_in(net_ipvs(state->net), state->hook, skb, AF_INET6); |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 2039 | } |
| 2040 | |
| 2041 | /* |
| 2042 | * AF_INET6 handler in NF_INET_LOCAL_OUT chain |
| 2043 | * Schedule and forward packets from local clients |
| 2044 | */ |
| 2045 | static unsigned int |
Eric W. Biederman | 06198b3 | 2015-09-18 14:33:06 -0500 | [diff] [blame] | 2046 | ip_vs_local_request6(void *priv, struct sk_buff *skb, |
David S. Miller | 238e54c | 2015-04-03 20:32:56 -0400 | [diff] [blame] | 2047 | const struct nf_hook_state *state) |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 2048 | { |
Eric W. Biederman | 6e385bb | 2015-09-21 13:02:53 -0500 | [diff] [blame] | 2049 | return ip_vs_in(net_ipvs(state->net), state->hook, skb, AF_INET6); |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 2050 | } |
| 2051 | |
| 2052 | #endif |
| 2053 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2054 | |
| 2055 | /* |
Patrick McHardy | 6e23ae2 | 2007-11-19 18:53:30 -0800 | [diff] [blame] | 2056 | * It is hooked at the NF_INET_FORWARD chain, in order to catch ICMP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2057 | * related packets destined for 0.0.0.0/0. |
| 2058 | * When fwmark-based virtual service is used, such as transparent |
| 2059 | * cache cluster, TCP packets can be marked and routed to ip_vs_in, |
| 2060 | * but ICMP destined for 0.0.0.0/0 cannot not be easily marked and |
Patrick McHardy | 6e23ae2 | 2007-11-19 18:53:30 -0800 | [diff] [blame] | 2061 | * sent to ip_vs_in_icmp. So, catch them at the NF_INET_FORWARD chain |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2062 | * and send them to ip_vs_in_icmp. |
| 2063 | */ |
| 2064 | static unsigned int |
Eric W. Biederman | 06198b3 | 2015-09-18 14:33:06 -0500 | [diff] [blame] | 2065 | ip_vs_forward_icmp(void *priv, struct sk_buff *skb, |
David S. Miller | 238e54c | 2015-04-03 20:32:56 -0400 | [diff] [blame] | 2066 | const struct nf_hook_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2067 | { |
| 2068 | int r; |
Eric W. Biederman | 6f2bcea | 2015-09-21 13:02:54 -0500 | [diff] [blame] | 2069 | struct netns_ipvs *ipvs = net_ipvs(state->net); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2070 | |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 2071 | if (ip_hdr(skb)->protocol != IPPROTO_ICMP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2072 | return NF_ACCEPT; |
| 2073 | |
Hans Schillstrom | 7a4f076 | 2011-05-03 22:09:31 +0200 | [diff] [blame] | 2074 | /* ipvs enabled in this netns ? */ |
Julian Anastasov | 0c12582 | 2013-03-09 23:25:04 +0200 | [diff] [blame] | 2075 | if (unlikely(sysctl_backup_only(ipvs) || !ipvs->enable)) |
Hans Schillstrom | 7a4f076 | 2011-05-03 22:09:31 +0200 | [diff] [blame] | 2076 | return NF_ACCEPT; |
| 2077 | |
Eric W. Biederman | 6f2bcea | 2015-09-21 13:02:54 -0500 | [diff] [blame] | 2078 | return ip_vs_in_icmp(ipvs, skb, &r, state->hook); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2079 | } |
| 2080 | |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 2081 | #ifdef CONFIG_IP_VS_IPV6 |
| 2082 | static unsigned int |
Eric W. Biederman | 06198b3 | 2015-09-18 14:33:06 -0500 | [diff] [blame] | 2083 | ip_vs_forward_icmp_v6(void *priv, struct sk_buff *skb, |
David S. Miller | 238e54c | 2015-04-03 20:32:56 -0400 | [diff] [blame] | 2084 | const struct nf_hook_state *state) |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 2085 | { |
| 2086 | int r; |
Eric W. Biederman | 6f2bcea | 2015-09-21 13:02:54 -0500 | [diff] [blame] | 2087 | struct netns_ipvs *ipvs = net_ipvs(state->net); |
Jesper Dangaard Brouer | 63dca2c | 2012-09-26 14:06:41 +0200 | [diff] [blame] | 2088 | struct ip_vs_iphdr iphdr; |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 2089 | |
Alex Gartrell | 4fd9bee | 2015-08-26 09:40:29 -0700 | [diff] [blame] | 2090 | ip_vs_fill_iph_skb(AF_INET6, skb, false, &iphdr); |
Jesper Dangaard Brouer | 63dca2c | 2012-09-26 14:06:41 +0200 | [diff] [blame] | 2091 | if (iphdr.protocol != IPPROTO_ICMPV6) |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 2092 | return NF_ACCEPT; |
| 2093 | |
Hans Schillstrom | 7a4f076 | 2011-05-03 22:09:31 +0200 | [diff] [blame] | 2094 | /* ipvs enabled in this netns ? */ |
Julian Anastasov | 0c12582 | 2013-03-09 23:25:04 +0200 | [diff] [blame] | 2095 | if (unlikely(sysctl_backup_only(ipvs) || !ipvs->enable)) |
Hans Schillstrom | 7a4f076 | 2011-05-03 22:09:31 +0200 | [diff] [blame] | 2096 | return NF_ACCEPT; |
| 2097 | |
Eric W. Biederman | 6f2bcea | 2015-09-21 13:02:54 -0500 | [diff] [blame] | 2098 | return ip_vs_in_icmp_v6(ipvs, skb, &r, state->hook, &iphdr); |
Julius Volz | 2a3b791 | 2008-09-02 15:55:47 +0200 | [diff] [blame] | 2099 | } |
| 2100 | #endif |
| 2101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2102 | |
Patrick McHardy | 1999414 | 2007-12-05 01:23:00 -0800 | [diff] [blame] | 2103 | static struct nf_hook_ops ip_vs_ops[] __read_mostly = { |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 2104 | /* After packet filtering, change source only for VS/NAT */ |
| 2105 | { |
| 2106 | .hook = ip_vs_reply4, |
Alban Crequy | 4c809d6 | 2012-05-14 03:56:38 +0000 | [diff] [blame] | 2107 | .pf = NFPROTO_IPV4, |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 2108 | .hooknum = NF_INET_LOCAL_IN, |
Julian Anastasov | afb523c | 2011-06-02 09:09:54 +0900 | [diff] [blame] | 2109 | .priority = NF_IP_PRI_NAT_SRC - 2, |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 2110 | }, |
Patrick McHardy | 41c5b31 | 2007-12-05 01:22:43 -0800 | [diff] [blame] | 2111 | /* After packet filtering, forward packet through VS/DR, VS/TUN, |
| 2112 | * or VS/NAT(change destination), so that filtering rules can be |
| 2113 | * applied to IPVS. */ |
| 2114 | { |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 2115 | .hook = ip_vs_remote_request4, |
Alban Crequy | 4c809d6 | 2012-05-14 03:56:38 +0000 | [diff] [blame] | 2116 | .pf = NFPROTO_IPV4, |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 2117 | .hooknum = NF_INET_LOCAL_IN, |
Julian Anastasov | afb523c | 2011-06-02 09:09:54 +0900 | [diff] [blame] | 2118 | .priority = NF_IP_PRI_NAT_SRC - 1, |
Patrick McHardy | 41c5b31 | 2007-12-05 01:22:43 -0800 | [diff] [blame] | 2119 | }, |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 2120 | /* Before ip_vs_in, change source only for VS/NAT */ |
Patrick McHardy | 41c5b31 | 2007-12-05 01:22:43 -0800 | [diff] [blame] | 2121 | { |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 2122 | .hook = ip_vs_local_reply4, |
Alban Crequy | 4c809d6 | 2012-05-14 03:56:38 +0000 | [diff] [blame] | 2123 | .pf = NFPROTO_IPV4, |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 2124 | .hooknum = NF_INET_LOCAL_OUT, |
Julian Anastasov | afb523c | 2011-06-02 09:09:54 +0900 | [diff] [blame] | 2125 | .priority = NF_IP_PRI_NAT_DST + 1, |
Patrick McHardy | 41c5b31 | 2007-12-05 01:22:43 -0800 | [diff] [blame] | 2126 | }, |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 2127 | /* After mangle, schedule and forward local requests */ |
| 2128 | { |
| 2129 | .hook = ip_vs_local_request4, |
Alban Crequy | 4c809d6 | 2012-05-14 03:56:38 +0000 | [diff] [blame] | 2130 | .pf = NFPROTO_IPV4, |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 2131 | .hooknum = NF_INET_LOCAL_OUT, |
Julian Anastasov | afb523c | 2011-06-02 09:09:54 +0900 | [diff] [blame] | 2132 | .priority = NF_IP_PRI_NAT_DST + 2, |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 2133 | }, |
Patrick McHardy | 41c5b31 | 2007-12-05 01:22:43 -0800 | [diff] [blame] | 2134 | /* After packet filtering (but before ip_vs_out_icmp), catch icmp |
| 2135 | * destined for 0.0.0.0/0, which is for incoming IPVS connections */ |
| 2136 | { |
| 2137 | .hook = ip_vs_forward_icmp, |
Alban Crequy | 4c809d6 | 2012-05-14 03:56:38 +0000 | [diff] [blame] | 2138 | .pf = NFPROTO_IPV4, |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 2139 | .hooknum = NF_INET_FORWARD, |
| 2140 | .priority = 99, |
Patrick McHardy | 41c5b31 | 2007-12-05 01:22:43 -0800 | [diff] [blame] | 2141 | }, |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 2142 | /* After packet filtering, change source only for VS/NAT */ |
| 2143 | { |
| 2144 | .hook = ip_vs_reply4, |
Alban Crequy | 4c809d6 | 2012-05-14 03:56:38 +0000 | [diff] [blame] | 2145 | .pf = NFPROTO_IPV4, |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 2146 | .hooknum = NF_INET_FORWARD, |
| 2147 | .priority = 100, |
| 2148 | }, |
Julius Volz | 473b23d | 2008-09-02 15:55:54 +0200 | [diff] [blame] | 2149 | #ifdef CONFIG_IP_VS_IPV6 |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 2150 | /* After packet filtering, change source only for VS/NAT */ |
| 2151 | { |
| 2152 | .hook = ip_vs_reply6, |
Alban Crequy | 4c809d6 | 2012-05-14 03:56:38 +0000 | [diff] [blame] | 2153 | .pf = NFPROTO_IPV6, |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 2154 | .hooknum = NF_INET_LOCAL_IN, |
Julian Anastasov | afb523c | 2011-06-02 09:09:54 +0900 | [diff] [blame] | 2155 | .priority = NF_IP6_PRI_NAT_SRC - 2, |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 2156 | }, |
Julius Volz | 473b23d | 2008-09-02 15:55:54 +0200 | [diff] [blame] | 2157 | /* After packet filtering, forward packet through VS/DR, VS/TUN, |
| 2158 | * or VS/NAT(change destination), so that filtering rules can be |
| 2159 | * applied to IPVS. */ |
| 2160 | { |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 2161 | .hook = ip_vs_remote_request6, |
Alban Crequy | 4c809d6 | 2012-05-14 03:56:38 +0000 | [diff] [blame] | 2162 | .pf = NFPROTO_IPV6, |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 2163 | .hooknum = NF_INET_LOCAL_IN, |
Julian Anastasov | afb523c | 2011-06-02 09:09:54 +0900 | [diff] [blame] | 2164 | .priority = NF_IP6_PRI_NAT_SRC - 1, |
Julius Volz | 473b23d | 2008-09-02 15:55:54 +0200 | [diff] [blame] | 2165 | }, |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 2166 | /* Before ip_vs_in, change source only for VS/NAT */ |
Julius Volz | 473b23d | 2008-09-02 15:55:54 +0200 | [diff] [blame] | 2167 | { |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 2168 | .hook = ip_vs_local_reply6, |
Julian Anastasov | eb90b0c | 2014-08-22 17:53:41 +0300 | [diff] [blame] | 2169 | .pf = NFPROTO_IPV6, |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 2170 | .hooknum = NF_INET_LOCAL_OUT, |
Julian Anastasov | afb523c | 2011-06-02 09:09:54 +0900 | [diff] [blame] | 2171 | .priority = NF_IP6_PRI_NAT_DST + 1, |
Julius Volz | 473b23d | 2008-09-02 15:55:54 +0200 | [diff] [blame] | 2172 | }, |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 2173 | /* After mangle, schedule and forward local requests */ |
| 2174 | { |
| 2175 | .hook = ip_vs_local_request6, |
Alban Crequy | 4c809d6 | 2012-05-14 03:56:38 +0000 | [diff] [blame] | 2176 | .pf = NFPROTO_IPV6, |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 2177 | .hooknum = NF_INET_LOCAL_OUT, |
Julian Anastasov | afb523c | 2011-06-02 09:09:54 +0900 | [diff] [blame] | 2178 | .priority = NF_IP6_PRI_NAT_DST + 2, |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 2179 | }, |
Julius Volz | 473b23d | 2008-09-02 15:55:54 +0200 | [diff] [blame] | 2180 | /* After packet filtering (but before ip_vs_out_icmp), catch icmp |
| 2181 | * destined for 0.0.0.0/0, which is for incoming IPVS connections */ |
| 2182 | { |
| 2183 | .hook = ip_vs_forward_icmp_v6, |
Alban Crequy | 4c809d6 | 2012-05-14 03:56:38 +0000 | [diff] [blame] | 2184 | .pf = NFPROTO_IPV6, |
Julian Anastasov | cb59155 | 2010-10-17 16:40:51 +0300 | [diff] [blame] | 2185 | .hooknum = NF_INET_FORWARD, |
| 2186 | .priority = 99, |
Julius Volz | 473b23d | 2008-09-02 15:55:54 +0200 | [diff] [blame] | 2187 | }, |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 2188 | /* After packet filtering, change source only for VS/NAT */ |
| 2189 | { |
| 2190 | .hook = ip_vs_reply6, |
Alban Crequy | 4c809d6 | 2012-05-14 03:56:38 +0000 | [diff] [blame] | 2191 | .pf = NFPROTO_IPV6, |
Julian Anastasov | fc60476 | 2010-10-17 16:38:15 +0300 | [diff] [blame] | 2192 | .hooknum = NF_INET_FORWARD, |
| 2193 | .priority = 100, |
| 2194 | }, |
Julius Volz | 473b23d | 2008-09-02 15:55:54 +0200 | [diff] [blame] | 2195 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2196 | }; |
Hans Schillstrom | 61b1ab4 | 2011-01-03 14:44:42 +0100 | [diff] [blame] | 2197 | /* |
| 2198 | * Initialize IP Virtual Server netns mem. |
| 2199 | */ |
| 2200 | static int __net_init __ip_vs_init(struct net *net) |
| 2201 | { |
| 2202 | struct netns_ipvs *ipvs; |
| 2203 | |
Hans Schillstrom | 61b1ab4 | 2011-01-03 14:44:42 +0100 | [diff] [blame] | 2204 | ipvs = net_generic(net, ip_vs_net_id); |
Joe Perches | 0a9ee81 | 2011-08-29 14:17:25 -0700 | [diff] [blame] | 2205 | if (ipvs == NULL) |
Hans Schillstrom | 61b1ab4 | 2011-01-03 14:44:42 +0100 | [diff] [blame] | 2206 | return -ENOMEM; |
Joe Perches | 0a9ee81 | 2011-08-29 14:17:25 -0700 | [diff] [blame] | 2207 | |
Hans Schillstrom | 7a4f076 | 2011-05-03 22:09:31 +0200 | [diff] [blame] | 2208 | /* Hold the beast until a service is registerd */ |
| 2209 | ipvs->enable = 0; |
Hans Schillstrom | f6340ee | 2011-01-03 14:44:59 +0100 | [diff] [blame] | 2210 | ipvs->net = net; |
Hans Schillstrom | 61b1ab4 | 2011-01-03 14:44:42 +0100 | [diff] [blame] | 2211 | /* Counters used for creating unique names */ |
| 2212 | ipvs->gen = atomic_read(&ipvs_netns_cnt); |
| 2213 | atomic_inc(&ipvs_netns_cnt); |
| 2214 | net->ipvs = ipvs; |
Hans Schillstrom | 7a4f076 | 2011-05-03 22:09:31 +0200 | [diff] [blame] | 2215 | |
Eric W. Biederman | a4dd036 | 2015-09-21 13:02:28 -0500 | [diff] [blame] | 2216 | if (ip_vs_estimator_net_init(ipvs) < 0) |
Hans Schillstrom | 7a4f076 | 2011-05-03 22:09:31 +0200 | [diff] [blame] | 2217 | goto estimator_fail; |
| 2218 | |
Eric W. Biederman | 3d99376 | 2015-09-21 13:02:26 -0500 | [diff] [blame] | 2219 | if (ip_vs_control_net_init(ipvs) < 0) |
Hans Schillstrom | 7a4f076 | 2011-05-03 22:09:31 +0200 | [diff] [blame] | 2220 | goto control_fail; |
| 2221 | |
Eric W. Biederman | 7d1f88e | 2015-09-21 13:02:58 -0500 | [diff] [blame] | 2222 | if (ip_vs_protocol_net_init(ipvs) < 0) |
Hans Schillstrom | 7a4f076 | 2011-05-03 22:09:31 +0200 | [diff] [blame] | 2223 | goto protocol_fail; |
| 2224 | |
Eric W. Biederman | b5dd212 | 2015-09-21 13:02:34 -0500 | [diff] [blame] | 2225 | if (ip_vs_app_net_init(ipvs) < 0) |
Hans Schillstrom | 7a4f076 | 2011-05-03 22:09:31 +0200 | [diff] [blame] | 2226 | goto app_fail; |
| 2227 | |
Eric W. Biederman | 2f3edc6a | 2015-09-21 13:02:42 -0500 | [diff] [blame] | 2228 | if (ip_vs_conn_net_init(ipvs) < 0) |
Hans Schillstrom | 7a4f076 | 2011-05-03 22:09:31 +0200 | [diff] [blame] | 2229 | goto conn_fail; |
| 2230 | |
Eric W. Biederman | 802cb43 | 2015-09-21 13:02:20 -0500 | [diff] [blame] | 2231 | if (ip_vs_sync_net_init(ipvs) < 0) |
Hans Schillstrom | 7a4f076 | 2011-05-03 22:09:31 +0200 | [diff] [blame] | 2232 | goto sync_fail; |
| 2233 | |
Simon Horman | a870c8c | 2011-02-01 18:21:53 +0100 | [diff] [blame] | 2234 | printk(KERN_INFO "IPVS: Creating netns size=%zu id=%d\n", |
Hans Schillstrom | 61b1ab4 | 2011-01-03 14:44:42 +0100 | [diff] [blame] | 2235 | sizeof(struct netns_ipvs), ipvs->gen); |
| 2236 | return 0; |
Hans Schillstrom | 7a4f076 | 2011-05-03 22:09:31 +0200 | [diff] [blame] | 2237 | /* |
| 2238 | * Error handling |
| 2239 | */ |
| 2240 | |
| 2241 | sync_fail: |
Eric W. Biederman | 2f3edc6a | 2015-09-21 13:02:42 -0500 | [diff] [blame] | 2242 | ip_vs_conn_net_cleanup(ipvs); |
Hans Schillstrom | 7a4f076 | 2011-05-03 22:09:31 +0200 | [diff] [blame] | 2243 | conn_fail: |
Eric W. Biederman | b5dd212 | 2015-09-21 13:02:34 -0500 | [diff] [blame] | 2244 | ip_vs_app_net_cleanup(ipvs); |
Hans Schillstrom | 7a4f076 | 2011-05-03 22:09:31 +0200 | [diff] [blame] | 2245 | app_fail: |
Eric W. Biederman | 7d1f88e | 2015-09-21 13:02:58 -0500 | [diff] [blame] | 2246 | ip_vs_protocol_net_cleanup(ipvs); |
Hans Schillstrom | 7a4f076 | 2011-05-03 22:09:31 +0200 | [diff] [blame] | 2247 | protocol_fail: |
Eric W. Biederman | 3d99376 | 2015-09-21 13:02:26 -0500 | [diff] [blame] | 2248 | ip_vs_control_net_cleanup(ipvs); |
Hans Schillstrom | 7a4f076 | 2011-05-03 22:09:31 +0200 | [diff] [blame] | 2249 | control_fail: |
Eric W. Biederman | a4dd036 | 2015-09-21 13:02:28 -0500 | [diff] [blame] | 2250 | ip_vs_estimator_net_cleanup(ipvs); |
Hans Schillstrom | 7a4f076 | 2011-05-03 22:09:31 +0200 | [diff] [blame] | 2251 | estimator_fail: |
Julian Anastasov | 39f618b | 2012-04-25 00:29:58 +0300 | [diff] [blame] | 2252 | net->ipvs = NULL; |
Hans Schillstrom | 7a4f076 | 2011-05-03 22:09:31 +0200 | [diff] [blame] | 2253 | return -ENOMEM; |
Hans Schillstrom | 61b1ab4 | 2011-01-03 14:44:42 +0100 | [diff] [blame] | 2254 | } |
| 2255 | |
| 2256 | static void __net_exit __ip_vs_cleanup(struct net *net) |
| 2257 | { |
Eric W. Biederman | 56d2169 | 2015-09-21 13:01:58 -0500 | [diff] [blame] | 2258 | struct netns_ipvs *ipvs = net_ipvs(net); |
| 2259 | |
| 2260 | ip_vs_service_net_cleanup(ipvs); /* ip_vs_flush() with locks */ |
Eric W. Biederman | 2f3edc6a | 2015-09-21 13:02:42 -0500 | [diff] [blame] | 2261 | ip_vs_conn_net_cleanup(ipvs); |
Eric W. Biederman | b5dd212 | 2015-09-21 13:02:34 -0500 | [diff] [blame] | 2262 | ip_vs_app_net_cleanup(ipvs); |
Eric W. Biederman | 7d1f88e | 2015-09-21 13:02:58 -0500 | [diff] [blame] | 2263 | ip_vs_protocol_net_cleanup(ipvs); |
Eric W. Biederman | 3d99376 | 2015-09-21 13:02:26 -0500 | [diff] [blame] | 2264 | ip_vs_control_net_cleanup(ipvs); |
Eric W. Biederman | a4dd036 | 2015-09-21 13:02:28 -0500 | [diff] [blame] | 2265 | ip_vs_estimator_net_cleanup(ipvs); |
Eric W. Biederman | 56d2169 | 2015-09-21 13:01:58 -0500 | [diff] [blame] | 2266 | IP_VS_DBG(2, "ipvs netns %d released\n", ipvs->gen); |
Julian Anastasov | 39f618b | 2012-04-25 00:29:58 +0300 | [diff] [blame] | 2267 | net->ipvs = NULL; |
Hans Schillstrom | 61b1ab4 | 2011-01-03 14:44:42 +0100 | [diff] [blame] | 2268 | } |
| 2269 | |
Hans Schillstrom | 7a4f076 | 2011-05-03 22:09:31 +0200 | [diff] [blame] | 2270 | static void __net_exit __ip_vs_dev_cleanup(struct net *net) |
| 2271 | { |
Eric W. Biederman | ebea1f7 | 2015-09-21 13:02:21 -0500 | [diff] [blame] | 2272 | struct netns_ipvs *ipvs = net_ipvs(net); |
Hans Schillstrom | 7a4f076 | 2011-05-03 22:09:31 +0200 | [diff] [blame] | 2273 | EnterFunction(2); |
Eric W. Biederman | ebea1f7 | 2015-09-21 13:02:21 -0500 | [diff] [blame] | 2274 | ipvs->enable = 0; /* Disable packet reception */ |
Hans Schillstrom | 8f4e0a1 | 2011-06-13 09:06:57 +0200 | [diff] [blame] | 2275 | smp_wmb(); |
Eric W. Biederman | ebea1f7 | 2015-09-21 13:02:21 -0500 | [diff] [blame] | 2276 | ip_vs_sync_net_cleanup(ipvs); |
Hans Schillstrom | 7a4f076 | 2011-05-03 22:09:31 +0200 | [diff] [blame] | 2277 | LeaveFunction(2); |
| 2278 | } |
| 2279 | |
Hans Schillstrom | 61b1ab4 | 2011-01-03 14:44:42 +0100 | [diff] [blame] | 2280 | static struct pernet_operations ipvs_core_ops = { |
| 2281 | .init = __ip_vs_init, |
| 2282 | .exit = __ip_vs_cleanup, |
| 2283 | .id = &ip_vs_net_id, |
| 2284 | .size = sizeof(struct netns_ipvs), |
| 2285 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | |
Hans Schillstrom | 7a4f076 | 2011-05-03 22:09:31 +0200 | [diff] [blame] | 2287 | static struct pernet_operations ipvs_core_dev_ops = { |
| 2288 | .exit = __ip_vs_dev_cleanup, |
| 2289 | }; |
| 2290 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2291 | /* |
| 2292 | * Initialize IP Virtual Server |
| 2293 | */ |
| 2294 | static int __init ip_vs_init(void) |
| 2295 | { |
| 2296 | int ret; |
| 2297 | |
| 2298 | ret = ip_vs_control_init(); |
| 2299 | if (ret < 0) { |
Hannes Eder | 1e3e238 | 2009-08-02 11:05:41 +0000 | [diff] [blame] | 2300 | pr_err("can't setup control.\n"); |
Hans Schillstrom | 6c8f794 | 2011-06-13 12:19:27 +0200 | [diff] [blame] | 2301 | goto exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2302 | } |
| 2303 | |
| 2304 | ip_vs_protocol_init(); |
| 2305 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2306 | ret = ip_vs_conn_init(); |
| 2307 | if (ret < 0) { |
Hannes Eder | 1e3e238 | 2009-08-02 11:05:41 +0000 | [diff] [blame] | 2308 | pr_err("can't setup connection table.\n"); |
Hans Schillstrom | 6c8f794 | 2011-06-13 12:19:27 +0200 | [diff] [blame] | 2309 | goto cleanup_protocol; |
Hans Schillstrom | 61b1ab4 | 2011-01-03 14:44:42 +0100 | [diff] [blame] | 2310 | } |
| 2311 | |
Hans Schillstrom | 7a4f076 | 2011-05-03 22:09:31 +0200 | [diff] [blame] | 2312 | ret = register_pernet_subsys(&ipvs_core_ops); /* Alloc ip_vs struct */ |
| 2313 | if (ret < 0) |
Hans Schillstrom | 6c8f794 | 2011-06-13 12:19:27 +0200 | [diff] [blame] | 2314 | goto cleanup_conn; |
Hans Schillstrom | 7a4f076 | 2011-05-03 22:09:31 +0200 | [diff] [blame] | 2315 | |
| 2316 | ret = register_pernet_device(&ipvs_core_dev_ops); |
| 2317 | if (ret < 0) |
| 2318 | goto cleanup_sub; |
| 2319 | |
Patrick McHardy | 41c5b31 | 2007-12-05 01:22:43 -0800 | [diff] [blame] | 2320 | ret = nf_register_hooks(ip_vs_ops, ARRAY_SIZE(ip_vs_ops)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2321 | if (ret < 0) { |
Hannes Eder | 1e3e238 | 2009-08-02 11:05:41 +0000 | [diff] [blame] | 2322 | pr_err("can't register hooks.\n"); |
Hans Schillstrom | 7a4f076 | 2011-05-03 22:09:31 +0200 | [diff] [blame] | 2323 | goto cleanup_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2324 | } |
| 2325 | |
Hans Schillstrom | 8537de8 | 2012-04-26 07:47:44 +0200 | [diff] [blame] | 2326 | ret = ip_vs_register_nl_ioctl(); |
| 2327 | if (ret < 0) { |
| 2328 | pr_err("can't register netlink/ioctl.\n"); |
| 2329 | goto cleanup_hooks; |
| 2330 | } |
| 2331 | |
Hannes Eder | 1e3e238 | 2009-08-02 11:05:41 +0000 | [diff] [blame] | 2332 | pr_info("ipvs loaded.\n"); |
Hans Schillstrom | 7a4f076 | 2011-05-03 22:09:31 +0200 | [diff] [blame] | 2333 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2334 | return ret; |
| 2335 | |
Hans Schillstrom | 8537de8 | 2012-04-26 07:47:44 +0200 | [diff] [blame] | 2336 | cleanup_hooks: |
| 2337 | nf_unregister_hooks(ip_vs_ops, ARRAY_SIZE(ip_vs_ops)); |
Hans Schillstrom | 7a4f076 | 2011-05-03 22:09:31 +0200 | [diff] [blame] | 2338 | cleanup_dev: |
| 2339 | unregister_pernet_device(&ipvs_core_dev_ops); |
| 2340 | cleanup_sub: |
| 2341 | unregister_pernet_subsys(&ipvs_core_ops); |
Hans Schillstrom | 552ad65 | 2011-06-13 12:19:26 +0200 | [diff] [blame] | 2342 | cleanup_conn: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2343 | ip_vs_conn_cleanup(); |
Hans Schillstrom | 552ad65 | 2011-06-13 12:19:26 +0200 | [diff] [blame] | 2344 | cleanup_protocol: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2345 | ip_vs_protocol_cleanup(); |
| 2346 | ip_vs_control_cleanup(); |
Hans Schillstrom | 6c8f794 | 2011-06-13 12:19:27 +0200 | [diff] [blame] | 2347 | exit: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2348 | return ret; |
| 2349 | } |
| 2350 | |
| 2351 | static void __exit ip_vs_cleanup(void) |
| 2352 | { |
Hans Schillstrom | 8537de8 | 2012-04-26 07:47:44 +0200 | [diff] [blame] | 2353 | ip_vs_unregister_nl_ioctl(); |
Patrick McHardy | 41c5b31 | 2007-12-05 01:22:43 -0800 | [diff] [blame] | 2354 | nf_unregister_hooks(ip_vs_ops, ARRAY_SIZE(ip_vs_ops)); |
Hans Schillstrom | 7a4f076 | 2011-05-03 22:09:31 +0200 | [diff] [blame] | 2355 | unregister_pernet_device(&ipvs_core_dev_ops); |
| 2356 | unregister_pernet_subsys(&ipvs_core_ops); /* free ip_vs struct */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2357 | ip_vs_conn_cleanup(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2358 | ip_vs_protocol_cleanup(); |
| 2359 | ip_vs_control_cleanup(); |
Hannes Eder | 1e3e238 | 2009-08-02 11:05:41 +0000 | [diff] [blame] | 2360 | pr_info("ipvs unloaded.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2361 | } |
| 2362 | |
| 2363 | module_init(ip_vs_init); |
| 2364 | module_exit(ip_vs_cleanup); |
| 2365 | MODULE_LICENSE("GPL"); |