Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 1 | #include <linux/kernel.h> |
| 2 | #include <linux/ip.h> |
| 3 | #include <linux/sctp.h> |
| 4 | #include <net/ip.h> |
| 5 | #include <net/ip6_checksum.h> |
| 6 | #include <linux/netfilter.h> |
| 7 | #include <linux/netfilter_ipv4.h> |
| 8 | #include <net/sctp/checksum.h> |
| 9 | #include <net/ip_vs.h> |
| 10 | |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 11 | static int |
Eric W. Biederman | d8f44c3 | 2015-09-21 13:02:43 -0500 | [diff] [blame] | 12 | sctp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb, |
| 13 | struct ip_vs_proto_data *pd, |
Jesper Dangaard Brouer | d4383f0 | 2012-09-26 14:07:17 +0200 | [diff] [blame] | 14 | int *verdict, struct ip_vs_conn **cpp, |
| 15 | struct ip_vs_iphdr *iph) |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 16 | { |
| 17 | struct ip_vs_service *svc; |
| 18 | sctp_chunkhdr_t _schunkh, *sch; |
| 19 | sctp_sctphdr_t *sh, _sctph; |
Alex Gartrell | 5e26b1b | 2015-08-26 09:40:41 -0700 | [diff] [blame] | 20 | __be16 _ports[2], *ports = NULL; |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 21 | |
Alex Gartrell | 5e26b1b | 2015-08-26 09:40:41 -0700 | [diff] [blame] | 22 | if (likely(!ip_vs_iph_icmp(iph))) { |
| 23 | sh = skb_header_pointer(skb, iph->len, sizeof(_sctph), &_sctph); |
| 24 | if (sh) { |
| 25 | sch = skb_header_pointer( |
| 26 | skb, iph->len + sizeof(sctp_sctphdr_t), |
| 27 | sizeof(_schunkh), &_schunkh); |
| 28 | if (sch && (sch->type == SCTP_CID_INIT || |
| 29 | sysctl_sloppy_sctp(ipvs))) |
| 30 | ports = &sh->source; |
| 31 | } |
| 32 | } else { |
| 33 | ports = skb_header_pointer( |
| 34 | skb, iph->len, sizeof(_ports), &_ports); |
Alex Gartrell | 6044eef | 2015-08-26 09:40:37 -0700 | [diff] [blame] | 35 | } |
| 36 | |
Alex Gartrell | 5e26b1b | 2015-08-26 09:40:41 -0700 | [diff] [blame] | 37 | if (!ports) { |
Daniel Borkmann | 6e7cd27 | 2013-10-25 11:05:04 +0200 | [diff] [blame] | 38 | *verdict = NF_DROP; |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 39 | return 0; |
Daniel Borkmann | 6e7cd27 | 2013-10-25 11:05:04 +0200 | [diff] [blame] | 40 | } |
| 41 | |
Julian Anastasov | ceec4c3 | 2013-03-22 11:46:53 +0200 | [diff] [blame] | 42 | rcu_read_lock(); |
Alex Gartrell | 5e26b1b | 2015-08-26 09:40:41 -0700 | [diff] [blame] | 43 | if (likely(!ip_vs_iph_inverse(iph))) |
Eric W. Biederman | 0a4fd6c | 2015-09-21 13:01:49 -0500 | [diff] [blame] | 44 | svc = ip_vs_service_find(ipvs, af, skb->mark, iph->protocol, |
Alex Gartrell | 5e26b1b | 2015-08-26 09:40:41 -0700 | [diff] [blame] | 45 | &iph->daddr, ports[1]); |
| 46 | else |
Eric W. Biederman | 0a4fd6c | 2015-09-21 13:01:49 -0500 | [diff] [blame] | 47 | svc = ip_vs_service_find(ipvs, af, skb->mark, iph->protocol, |
Alex Gartrell | 5e26b1b | 2015-08-26 09:40:41 -0700 | [diff] [blame] | 48 | &iph->saddr, ports[0]); |
| 49 | if (svc) { |
Julian Anastasov | 190ecd2 | 2010-10-17 16:24:37 +0300 | [diff] [blame] | 50 | int ignored; |
| 51 | |
Alexander Frolkin | c6c96c1 | 2013-06-13 08:56:15 +0100 | [diff] [blame] | 52 | if (ip_vs_todrop(ipvs)) { |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 53 | /* |
| 54 | * It seems that we are very loaded. |
| 55 | * We have to drop this packet :( |
| 56 | */ |
Julian Anastasov | ceec4c3 | 2013-03-22 11:46:53 +0200 | [diff] [blame] | 57 | rcu_read_unlock(); |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 58 | *verdict = NF_DROP; |
| 59 | return 0; |
| 60 | } |
| 61 | /* |
| 62 | * Let the virtual server select a real server for the |
| 63 | * incoming connection, and create a connection entry. |
| 64 | */ |
Jesper Dangaard Brouer | d4383f0 | 2012-09-26 14:07:17 +0200 | [diff] [blame] | 65 | *cpp = ip_vs_schedule(svc, skb, pd, &ignored, iph); |
Hans Schillstrom | a5959d5 | 2010-11-19 14:25:10 +0100 | [diff] [blame] | 66 | if (!*cpp && ignored <= 0) { |
| 67 | if (!ignored) |
Jesper Dangaard Brouer | d4383f0 | 2012-09-26 14:07:17 +0200 | [diff] [blame] | 68 | *verdict = ip_vs_leave(svc, skb, pd, iph); |
Julian Anastasov | ceec4c3 | 2013-03-22 11:46:53 +0200 | [diff] [blame] | 69 | else |
Hans Schillstrom | a5959d5 | 2010-11-19 14:25:10 +0100 | [diff] [blame] | 70 | *verdict = NF_DROP; |
Julian Anastasov | ceec4c3 | 2013-03-22 11:46:53 +0200 | [diff] [blame] | 71 | rcu_read_unlock(); |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 72 | return 0; |
| 73 | } |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 74 | } |
Julian Anastasov | ceec4c3 | 2013-03-22 11:46:53 +0200 | [diff] [blame] | 75 | rcu_read_unlock(); |
Hans Schillstrom | a5959d5 | 2010-11-19 14:25:10 +0100 | [diff] [blame] | 76 | /* NF_ACCEPT */ |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 77 | return 1; |
| 78 | } |
| 79 | |
Daniel Borkmann | 4b47bc9 | 2013-02-05 17:21:31 +0100 | [diff] [blame] | 80 | static void sctp_nat_csum(struct sk_buff *skb, sctp_sctphdr_t *sctph, |
| 81 | unsigned int sctphoff) |
| 82 | { |
Joe Stringer | 024ec3d | 2013-07-25 10:52:05 +0900 | [diff] [blame] | 83 | sctph->checksum = sctp_compute_cksum(skb, sctphoff); |
Daniel Borkmann | 4b47bc9 | 2013-02-05 17:21:31 +0100 | [diff] [blame] | 84 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 85 | } |
| 86 | |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 87 | static int |
Jesper Dangaard Brouer | d4383f0 | 2012-09-26 14:07:17 +0200 | [diff] [blame] | 88 | sctp_snat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp, |
| 89 | struct ip_vs_conn *cp, struct ip_vs_iphdr *iph) |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 90 | { |
| 91 | sctp_sctphdr_t *sctph; |
Jesper Dangaard Brouer | d4383f0 | 2012-09-26 14:07:17 +0200 | [diff] [blame] | 92 | unsigned int sctphoff = iph->len; |
Daniel Borkmann | 97203ab | 2013-10-28 10:56:20 +0100 | [diff] [blame] | 93 | bool payload_csum = false; |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 94 | |
| 95 | #ifdef CONFIG_IP_VS_IPV6 |
Jesper Dangaard Brouer | d4383f0 | 2012-09-26 14:07:17 +0200 | [diff] [blame] | 96 | if (cp->af == AF_INET6 && iph->fragoffs) |
Jesper Dangaard Brouer | 63dca2c | 2012-09-26 14:06:41 +0200 | [diff] [blame] | 97 | return 1; |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 98 | #endif |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 99 | |
| 100 | /* csum_check requires unshared skb */ |
| 101 | if (!skb_make_writable(skb, sctphoff + sizeof(*sctph))) |
| 102 | return 0; |
| 103 | |
| 104 | if (unlikely(cp->app != NULL)) { |
Daniel Borkmann | 97203ab | 2013-10-28 10:56:20 +0100 | [diff] [blame] | 105 | int ret; |
| 106 | |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 107 | /* Some checks before mangling */ |
| 108 | if (pp->csum_check && !pp->csum_check(cp->af, skb, pp)) |
| 109 | return 0; |
| 110 | |
| 111 | /* Call application helper if needed */ |
Daniel Borkmann | 97203ab | 2013-10-28 10:56:20 +0100 | [diff] [blame] | 112 | ret = ip_vs_app_pkt_out(cp, skb); |
| 113 | if (ret == 0) |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 114 | return 0; |
Daniel Borkmann | 97203ab | 2013-10-28 10:56:20 +0100 | [diff] [blame] | 115 | /* ret=2: csum update is needed after payload mangling */ |
| 116 | if (ret == 2) |
| 117 | payload_csum = true; |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | sctph = (void *) skb_network_header(skb) + sctphoff; |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 121 | |
Daniel Borkmann | 97203ab | 2013-10-28 10:56:20 +0100 | [diff] [blame] | 122 | /* Only update csum if we really have to */ |
| 123 | if (sctph->source != cp->vport || payload_csum || |
| 124 | skb->ip_summed == CHECKSUM_PARTIAL) { |
| 125 | sctph->source = cp->vport; |
| 126 | sctp_nat_csum(skb, sctph, sctphoff); |
| 127 | } else { |
| 128 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 129 | } |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 130 | |
| 131 | return 1; |
| 132 | } |
| 133 | |
| 134 | static int |
Jesper Dangaard Brouer | d4383f0 | 2012-09-26 14:07:17 +0200 | [diff] [blame] | 135 | sctp_dnat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp, |
| 136 | struct ip_vs_conn *cp, struct ip_vs_iphdr *iph) |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 137 | { |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 138 | sctp_sctphdr_t *sctph; |
Jesper Dangaard Brouer | d4383f0 | 2012-09-26 14:07:17 +0200 | [diff] [blame] | 139 | unsigned int sctphoff = iph->len; |
Daniel Borkmann | 97203ab | 2013-10-28 10:56:20 +0100 | [diff] [blame] | 140 | bool payload_csum = false; |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 141 | |
| 142 | #ifdef CONFIG_IP_VS_IPV6 |
Jesper Dangaard Brouer | d4383f0 | 2012-09-26 14:07:17 +0200 | [diff] [blame] | 143 | if (cp->af == AF_INET6 && iph->fragoffs) |
Jesper Dangaard Brouer | 63dca2c | 2012-09-26 14:06:41 +0200 | [diff] [blame] | 144 | return 1; |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 145 | #endif |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 146 | |
| 147 | /* csum_check requires unshared skb */ |
| 148 | if (!skb_make_writable(skb, sctphoff + sizeof(*sctph))) |
| 149 | return 0; |
| 150 | |
| 151 | if (unlikely(cp->app != NULL)) { |
Daniel Borkmann | 97203ab | 2013-10-28 10:56:20 +0100 | [diff] [blame] | 152 | int ret; |
| 153 | |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 154 | /* Some checks before mangling */ |
| 155 | if (pp->csum_check && !pp->csum_check(cp->af, skb, pp)) |
| 156 | return 0; |
| 157 | |
| 158 | /* Call application helper if needed */ |
Daniel Borkmann | 97203ab | 2013-10-28 10:56:20 +0100 | [diff] [blame] | 159 | ret = ip_vs_app_pkt_in(cp, skb); |
| 160 | if (ret == 0) |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 161 | return 0; |
Daniel Borkmann | 97203ab | 2013-10-28 10:56:20 +0100 | [diff] [blame] | 162 | /* ret=2: csum update is needed after payload mangling */ |
| 163 | if (ret == 2) |
| 164 | payload_csum = true; |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | sctph = (void *) skb_network_header(skb) + sctphoff; |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 168 | |
Daniel Borkmann | 97203ab | 2013-10-28 10:56:20 +0100 | [diff] [blame] | 169 | /* Only update csum if we really have to */ |
| 170 | if (sctph->dest != cp->dport || payload_csum || |
| 171 | (skb->ip_summed == CHECKSUM_PARTIAL && |
Tom Herbert | 53692b1 | 2015-12-14 11:19:41 -0800 | [diff] [blame] | 172 | !(skb_dst(skb)->dev->features & NETIF_F_SCTP_CRC))) { |
Daniel Borkmann | 97203ab | 2013-10-28 10:56:20 +0100 | [diff] [blame] | 173 | sctph->dest = cp->dport; |
| 174 | sctp_nat_csum(skb, sctph, sctphoff); |
| 175 | } else if (skb->ip_summed != CHECKSUM_PARTIAL) { |
| 176 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 177 | } |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 178 | |
| 179 | return 1; |
| 180 | } |
| 181 | |
| 182 | static int |
| 183 | sctp_csum_check(int af, struct sk_buff *skb, struct ip_vs_protocol *pp) |
| 184 | { |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 185 | unsigned int sctphoff; |
| 186 | struct sctphdr *sh, _sctph; |
Joe Stringer | 024ec3d | 2013-07-25 10:52:05 +0900 | [diff] [blame] | 187 | __le32 cmp, val; |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 188 | |
| 189 | #ifdef CONFIG_IP_VS_IPV6 |
| 190 | if (af == AF_INET6) |
| 191 | sctphoff = sizeof(struct ipv6hdr); |
| 192 | else |
| 193 | #endif |
| 194 | sctphoff = ip_hdrlen(skb); |
| 195 | |
| 196 | sh = skb_header_pointer(skb, sctphoff, sizeof(_sctph), &_sctph); |
| 197 | if (sh == NULL) |
| 198 | return 0; |
| 199 | |
| 200 | cmp = sh->checksum; |
Joe Stringer | 024ec3d | 2013-07-25 10:52:05 +0900 | [diff] [blame] | 201 | val = sctp_compute_cksum(skb, sctphoff); |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 202 | |
| 203 | if (val != cmp) { |
| 204 | /* CRC failure, dump it. */ |
Julian Anastasov | 0d79641 | 2010-10-17 16:46:17 +0300 | [diff] [blame] | 205 | IP_VS_DBG_RL_PKT(0, af, pp, skb, 0, |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 206 | "Failed checksum for"); |
| 207 | return 0; |
| 208 | } |
| 209 | return 1; |
| 210 | } |
| 211 | |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 212 | enum ipvs_sctp_event_t { |
Julian Anastasov | 61e7c42 | 2013-06-18 10:08:07 +0300 | [diff] [blame] | 213 | IP_VS_SCTP_DATA = 0, /* DATA, SACK, HEARTBEATs */ |
| 214 | IP_VS_SCTP_INIT, |
| 215 | IP_VS_SCTP_INIT_ACK, |
| 216 | IP_VS_SCTP_COOKIE_ECHO, |
| 217 | IP_VS_SCTP_COOKIE_ACK, |
| 218 | IP_VS_SCTP_SHUTDOWN, |
| 219 | IP_VS_SCTP_SHUTDOWN_ACK, |
| 220 | IP_VS_SCTP_SHUTDOWN_COMPLETE, |
| 221 | IP_VS_SCTP_ERROR, |
| 222 | IP_VS_SCTP_ABORT, |
| 223 | IP_VS_SCTP_EVENT_LAST |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 224 | }; |
| 225 | |
Julian Anastasov | 61e7c42 | 2013-06-18 10:08:07 +0300 | [diff] [blame] | 226 | /* RFC 2960, 3.2 Chunk Field Descriptions */ |
| 227 | static __u8 sctp_events[] = { |
| 228 | [SCTP_CID_DATA] = IP_VS_SCTP_DATA, |
| 229 | [SCTP_CID_INIT] = IP_VS_SCTP_INIT, |
| 230 | [SCTP_CID_INIT_ACK] = IP_VS_SCTP_INIT_ACK, |
| 231 | [SCTP_CID_SACK] = IP_VS_SCTP_DATA, |
| 232 | [SCTP_CID_HEARTBEAT] = IP_VS_SCTP_DATA, |
| 233 | [SCTP_CID_HEARTBEAT_ACK] = IP_VS_SCTP_DATA, |
| 234 | [SCTP_CID_ABORT] = IP_VS_SCTP_ABORT, |
| 235 | [SCTP_CID_SHUTDOWN] = IP_VS_SCTP_SHUTDOWN, |
| 236 | [SCTP_CID_SHUTDOWN_ACK] = IP_VS_SCTP_SHUTDOWN_ACK, |
| 237 | [SCTP_CID_ERROR] = IP_VS_SCTP_ERROR, |
| 238 | [SCTP_CID_COOKIE_ECHO] = IP_VS_SCTP_COOKIE_ECHO, |
| 239 | [SCTP_CID_COOKIE_ACK] = IP_VS_SCTP_COOKIE_ACK, |
| 240 | [SCTP_CID_ECN_ECNE] = IP_VS_SCTP_DATA, |
| 241 | [SCTP_CID_ECN_CWR] = IP_VS_SCTP_DATA, |
| 242 | [SCTP_CID_SHUTDOWN_COMPLETE] = IP_VS_SCTP_SHUTDOWN_COMPLETE, |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 243 | }; |
| 244 | |
Julian Anastasov | 61e7c42 | 2013-06-18 10:08:07 +0300 | [diff] [blame] | 245 | /* SCTP States: |
| 246 | * See RFC 2960, 4. SCTP Association State Diagram |
| 247 | * |
| 248 | * New states (not in diagram): |
| 249 | * - INIT1 state: use shorter timeout for dropped INIT packets |
| 250 | * - REJECTED state: use shorter timeout if INIT is rejected with ABORT |
| 251 | * - INIT, COOKIE_SENT, COOKIE_REPLIED, COOKIE states: for better debugging |
| 252 | * |
| 253 | * The states are as seen in real server. In the diagram, INIT1, INIT, |
| 254 | * COOKIE_SENT and COOKIE_REPLIED processing happens in CLOSED state. |
| 255 | * |
| 256 | * States as per packets from client (C) and server (S): |
| 257 | * |
| 258 | * Setup of client connection: |
| 259 | * IP_VS_SCTP_S_INIT1: First C:INIT sent, wait for S:INIT-ACK |
| 260 | * IP_VS_SCTP_S_INIT: Next C:INIT sent, wait for S:INIT-ACK |
| 261 | * IP_VS_SCTP_S_COOKIE_SENT: S:INIT-ACK sent, wait for C:COOKIE-ECHO |
| 262 | * IP_VS_SCTP_S_COOKIE_REPLIED: C:COOKIE-ECHO sent, wait for S:COOKIE-ACK |
| 263 | * |
| 264 | * Setup of server connection: |
| 265 | * IP_VS_SCTP_S_COOKIE_WAIT: S:INIT sent, wait for C:INIT-ACK |
| 266 | * IP_VS_SCTP_S_COOKIE: C:INIT-ACK sent, wait for S:COOKIE-ECHO |
| 267 | * IP_VS_SCTP_S_COOKIE_ECHOED: S:COOKIE-ECHO sent, wait for C:COOKIE-ACK |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 268 | */ |
Julian Anastasov | 61e7c42 | 2013-06-18 10:08:07 +0300 | [diff] [blame] | 269 | |
| 270 | #define sNO IP_VS_SCTP_S_NONE |
| 271 | #define sI1 IP_VS_SCTP_S_INIT1 |
| 272 | #define sIN IP_VS_SCTP_S_INIT |
| 273 | #define sCS IP_VS_SCTP_S_COOKIE_SENT |
| 274 | #define sCR IP_VS_SCTP_S_COOKIE_REPLIED |
| 275 | #define sCW IP_VS_SCTP_S_COOKIE_WAIT |
| 276 | #define sCO IP_VS_SCTP_S_COOKIE |
| 277 | #define sCE IP_VS_SCTP_S_COOKIE_ECHOED |
| 278 | #define sES IP_VS_SCTP_S_ESTABLISHED |
| 279 | #define sSS IP_VS_SCTP_S_SHUTDOWN_SENT |
| 280 | #define sSR IP_VS_SCTP_S_SHUTDOWN_RECEIVED |
| 281 | #define sSA IP_VS_SCTP_S_SHUTDOWN_ACK_SENT |
| 282 | #define sRJ IP_VS_SCTP_S_REJECTED |
| 283 | #define sCL IP_VS_SCTP_S_CLOSED |
| 284 | |
| 285 | static const __u8 sctp_states |
| 286 | [IP_VS_DIR_LAST][IP_VS_SCTP_EVENT_LAST][IP_VS_SCTP_S_LAST] = { |
| 287 | { /* INPUT */ |
| 288 | /* sNO, sI1, sIN, sCS, sCR, sCW, sCO, sCE, sES, sSS, sSR, sSA, sRJ, sCL*/ |
| 289 | /* d */{sES, sI1, sIN, sCS, sCR, sCW, sCO, sCE, sES, sSS, sSR, sSA, sRJ, sCL}, |
| 290 | /* i */{sI1, sIN, sIN, sCS, sCR, sCW, sCO, sCE, sES, sSS, sSR, sSA, sIN, sIN}, |
| 291 | /* i_a */{sCW, sCW, sCW, sCS, sCR, sCO, sCO, sCE, sES, sSS, sSR, sSA, sRJ, sCL}, |
| 292 | /* c_e */{sCR, sIN, sIN, sCR, sCR, sCW, sCO, sCE, sES, sSS, sSR, sSA, sRJ, sCL}, |
| 293 | /* c_a */{sES, sI1, sIN, sCS, sCR, sCW, sCO, sES, sES, sSS, sSR, sSA, sRJ, sCL}, |
| 294 | /* s */{sSR, sI1, sIN, sCS, sCR, sCW, sCO, sCE, sSR, sSS, sSR, sSA, sRJ, sCL}, |
| 295 | /* s_a */{sCL, sIN, sIN, sCS, sCR, sCW, sCO, sCE, sES, sCL, sSR, sCL, sRJ, sCL}, |
| 296 | /* s_c */{sCL, sCL, sCL, sCS, sCR, sCW, sCO, sCE, sES, sSS, sSR, sCL, sRJ, sCL}, |
| 297 | /* err */{sCL, sI1, sIN, sCS, sCR, sCW, sCO, sCL, sES, sSS, sSR, sSA, sRJ, sCL}, |
| 298 | /* ab */{sCL, sCL, sCL, sCL, sCL, sRJ, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL}, |
| 299 | }, |
| 300 | { /* OUTPUT */ |
| 301 | /* sNO, sI1, sIN, sCS, sCR, sCW, sCO, sCE, sES, sSS, sSR, sSA, sRJ, sCL*/ |
| 302 | /* d */{sES, sI1, sIN, sCS, sCR, sCW, sCO, sCE, sES, sSS, sSR, sSA, sRJ, sCL}, |
| 303 | /* i */{sCW, sCW, sCW, sCW, sCW, sCW, sCW, sCW, sES, sCW, sCW, sCW, sCW, sCW}, |
| 304 | /* i_a */{sCS, sCS, sCS, sCS, sCR, sCW, sCO, sCE, sES, sSS, sSR, sSA, sRJ, sCL}, |
| 305 | /* c_e */{sCE, sCE, sCE, sCE, sCE, sCE, sCE, sCE, sES, sSS, sSR, sSA, sRJ, sCL}, |
| 306 | /* c_a */{sES, sES, sES, sES, sES, sES, sES, sES, sES, sSS, sSR, sSA, sRJ, sCL}, |
| 307 | /* s */{sSS, sSS, sSS, sSS, sSS, sSS, sSS, sSS, sSS, sSS, sSR, sSA, sRJ, sCL}, |
| 308 | /* s_a */{sSA, sSA, sSA, sSA, sSA, sCW, sCO, sCE, sES, sSA, sSA, sSA, sRJ, sCL}, |
| 309 | /* s_c */{sCL, sI1, sIN, sCS, sCR, sCW, sCO, sCE, sES, sSS, sSR, sSA, sRJ, sCL}, |
| 310 | /* err */{sCL, sCL, sCL, sCL, sCL, sCW, sCO, sCE, sES, sSS, sSR, sSA, sRJ, sCL}, |
| 311 | /* ab */{sCL, sRJ, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL}, |
| 312 | }, |
| 313 | { /* INPUT-ONLY */ |
| 314 | /* sNO, sI1, sIN, sCS, sCR, sCW, sCO, sCE, sES, sSS, sSR, sSA, sRJ, sCL*/ |
| 315 | /* d */{sES, sI1, sIN, sCS, sCR, sES, sCO, sCE, sES, sSS, sSR, sSA, sRJ, sCL}, |
| 316 | /* i */{sI1, sIN, sIN, sIN, sIN, sIN, sCO, sCE, sES, sSS, sSR, sSA, sIN, sIN}, |
| 317 | /* i_a */{sCE, sCE, sCE, sCE, sCE, sCE, sCO, sCE, sES, sSS, sSR, sSA, sRJ, sCL}, |
| 318 | /* c_e */{sES, sES, sES, sES, sES, sES, sCO, sCE, sES, sSS, sSR, sSA, sRJ, sCL}, |
| 319 | /* c_a */{sES, sI1, sIN, sES, sES, sCW, sES, sES, sES, sSS, sSR, sSA, sRJ, sCL}, |
| 320 | /* s */{sSR, sI1, sIN, sCS, sCR, sCW, sCO, sCE, sSR, sSS, sSR, sSA, sRJ, sCL}, |
| 321 | /* s_a */{sCL, sIN, sIN, sCS, sCR, sCW, sCO, sCE, sCL, sCL, sSR, sCL, sRJ, sCL}, |
| 322 | /* s_c */{sCL, sCL, sCL, sCL, sCL, sCW, sCO, sCE, sES, sSS, sCL, sCL, sRJ, sCL}, |
| 323 | /* err */{sCL, sI1, sIN, sCS, sCR, sCW, sCO, sCE, sES, sSS, sSR, sSA, sRJ, sCL}, |
| 324 | /* ab */{sCL, sCL, sCL, sCL, sCL, sRJ, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL}, |
| 325 | }, |
| 326 | }; |
| 327 | |
| 328 | #define IP_VS_SCTP_MAX_RTO ((60 + 1) * HZ) |
| 329 | |
| 330 | /* Timeout table[state] */ |
Hans Schillstrom | 9d93487 | 2011-01-03 14:44:49 +0100 | [diff] [blame] | 331 | static const int sctp_timeouts[IP_VS_SCTP_S_LAST + 1] = { |
Julian Anastasov | 61e7c42 | 2013-06-18 10:08:07 +0300 | [diff] [blame] | 332 | [IP_VS_SCTP_S_NONE] = 2 * HZ, |
| 333 | [IP_VS_SCTP_S_INIT1] = (0 + 3 + 1) * HZ, |
| 334 | [IP_VS_SCTP_S_INIT] = IP_VS_SCTP_MAX_RTO, |
| 335 | [IP_VS_SCTP_S_COOKIE_SENT] = IP_VS_SCTP_MAX_RTO, |
| 336 | [IP_VS_SCTP_S_COOKIE_REPLIED] = IP_VS_SCTP_MAX_RTO, |
| 337 | [IP_VS_SCTP_S_COOKIE_WAIT] = IP_VS_SCTP_MAX_RTO, |
| 338 | [IP_VS_SCTP_S_COOKIE] = IP_VS_SCTP_MAX_RTO, |
| 339 | [IP_VS_SCTP_S_COOKIE_ECHOED] = IP_VS_SCTP_MAX_RTO, |
| 340 | [IP_VS_SCTP_S_ESTABLISHED] = 15 * 60 * HZ, |
| 341 | [IP_VS_SCTP_S_SHUTDOWN_SENT] = IP_VS_SCTP_MAX_RTO, |
| 342 | [IP_VS_SCTP_S_SHUTDOWN_RECEIVED] = IP_VS_SCTP_MAX_RTO, |
| 343 | [IP_VS_SCTP_S_SHUTDOWN_ACK_SENT] = IP_VS_SCTP_MAX_RTO, |
| 344 | [IP_VS_SCTP_S_REJECTED] = (0 + 3 + 1) * HZ, |
| 345 | [IP_VS_SCTP_S_CLOSED] = IP_VS_SCTP_MAX_RTO, |
| 346 | [IP_VS_SCTP_S_LAST] = 2 * HZ, |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 347 | }; |
| 348 | |
| 349 | static const char *sctp_state_name_table[IP_VS_SCTP_S_LAST + 1] = { |
Julian Anastasov | 61e7c42 | 2013-06-18 10:08:07 +0300 | [diff] [blame] | 350 | [IP_VS_SCTP_S_NONE] = "NONE", |
| 351 | [IP_VS_SCTP_S_INIT1] = "INIT1", |
| 352 | [IP_VS_SCTP_S_INIT] = "INIT", |
| 353 | [IP_VS_SCTP_S_COOKIE_SENT] = "C-SENT", |
| 354 | [IP_VS_SCTP_S_COOKIE_REPLIED] = "C-REPLIED", |
| 355 | [IP_VS_SCTP_S_COOKIE_WAIT] = "C-WAIT", |
| 356 | [IP_VS_SCTP_S_COOKIE] = "COOKIE", |
| 357 | [IP_VS_SCTP_S_COOKIE_ECHOED] = "C-ECHOED", |
| 358 | [IP_VS_SCTP_S_ESTABLISHED] = "ESTABLISHED", |
| 359 | [IP_VS_SCTP_S_SHUTDOWN_SENT] = "S-SENT", |
| 360 | [IP_VS_SCTP_S_SHUTDOWN_RECEIVED] = "S-RECEIVED", |
| 361 | [IP_VS_SCTP_S_SHUTDOWN_ACK_SENT] = "S-ACK-SENT", |
| 362 | [IP_VS_SCTP_S_REJECTED] = "REJECTED", |
| 363 | [IP_VS_SCTP_S_CLOSED] = "CLOSED", |
| 364 | [IP_VS_SCTP_S_LAST] = "BUG!", |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 365 | }; |
| 366 | |
| 367 | |
| 368 | static const char *sctp_state_name(int state) |
| 369 | { |
| 370 | if (state >= IP_VS_SCTP_S_LAST) |
| 371 | return "ERR!"; |
| 372 | if (sctp_state_name_table[state]) |
| 373 | return sctp_state_name_table[state]; |
| 374 | return "?"; |
| 375 | } |
| 376 | |
Simon Horman | 4a516f1 | 2011-09-16 14:11:49 +0900 | [diff] [blame] | 377 | static inline void |
Hans Schillstrom | 9330419 | 2011-01-03 14:44:51 +0100 | [diff] [blame] | 378 | set_sctp_state(struct ip_vs_proto_data *pd, struct ip_vs_conn *cp, |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 379 | int direction, const struct sk_buff *skb) |
| 380 | { |
| 381 | sctp_chunkhdr_t _sctpch, *sch; |
| 382 | unsigned char chunk_type; |
| 383 | int event, next_state; |
Julian Anastasov | cf2e394 | 2013-03-09 23:25:06 +0200 | [diff] [blame] | 384 | int ihl, cofs; |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 385 | |
| 386 | #ifdef CONFIG_IP_VS_IPV6 |
| 387 | ihl = cp->af == AF_INET ? ip_hdrlen(skb) : sizeof(struct ipv6hdr); |
| 388 | #else |
| 389 | ihl = ip_hdrlen(skb); |
| 390 | #endif |
| 391 | |
Julian Anastasov | cf2e394 | 2013-03-09 23:25:06 +0200 | [diff] [blame] | 392 | cofs = ihl + sizeof(sctp_sctphdr_t); |
| 393 | sch = skb_header_pointer(skb, cofs, sizeof(_sctpch), &_sctpch); |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 394 | if (sch == NULL) |
Simon Horman | 4a516f1 | 2011-09-16 14:11:49 +0900 | [diff] [blame] | 395 | return; |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 396 | |
| 397 | chunk_type = sch->type; |
| 398 | /* |
| 399 | * Section 3: Multiple chunks can be bundled into one SCTP packet |
| 400 | * up to the MTU size, except for the INIT, INIT ACK, and |
| 401 | * SHUTDOWN COMPLETE chunks. These chunks MUST NOT be bundled with |
| 402 | * any other chunk in a packet. |
| 403 | * |
| 404 | * Section 3.3.7: DATA chunks MUST NOT be bundled with ABORT. Control |
| 405 | * chunks (except for INIT, INIT ACK, and SHUTDOWN COMPLETE) MAY be |
| 406 | * bundled with an ABORT, but they MUST be placed before the ABORT |
| 407 | * in the SCTP packet or they will be ignored by the receiver. |
| 408 | */ |
| 409 | if ((sch->type == SCTP_CID_COOKIE_ECHO) || |
| 410 | (sch->type == SCTP_CID_COOKIE_ACK)) { |
Julian Anastasov | cf2e394 | 2013-03-09 23:25:06 +0200 | [diff] [blame] | 411 | int clen = ntohs(sch->length); |
| 412 | |
| 413 | if (clen >= sizeof(sctp_chunkhdr_t)) { |
| 414 | sch = skb_header_pointer(skb, cofs + ALIGN(clen, 4), |
| 415 | sizeof(_sctpch), &_sctpch); |
| 416 | if (sch && sch->type == SCTP_CID_ABORT) |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 417 | chunk_type = sch->type; |
| 418 | } |
| 419 | } |
| 420 | |
Julian Anastasov | 61e7c42 | 2013-06-18 10:08:07 +0300 | [diff] [blame] | 421 | event = (chunk_type < sizeof(sctp_events)) ? |
| 422 | sctp_events[chunk_type] : IP_VS_SCTP_DATA; |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 423 | |
Julian Anastasov | 61e7c42 | 2013-06-18 10:08:07 +0300 | [diff] [blame] | 424 | /* Update direction to INPUT_ONLY if necessary |
| 425 | * or delete NO_OUTPUT flag if output packet detected |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 426 | */ |
Julian Anastasov | 61e7c42 | 2013-06-18 10:08:07 +0300 | [diff] [blame] | 427 | if (cp->flags & IP_VS_CONN_F_NOOUTPUT) { |
| 428 | if (direction == IP_VS_DIR_OUTPUT) |
| 429 | cp->flags &= ~IP_VS_CONN_F_NOOUTPUT; |
| 430 | else |
| 431 | direction = IP_VS_DIR_INPUT_ONLY; |
| 432 | } |
| 433 | |
| 434 | next_state = sctp_states[direction][event][cp->state]; |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 435 | |
| 436 | if (next_state != cp->state) { |
| 437 | struct ip_vs_dest *dest = cp->dest; |
| 438 | |
| 439 | IP_VS_DBG_BUF(8, "%s %s %s:%d->" |
| 440 | "%s:%d state: %s->%s conn->refcnt:%d\n", |
Hans Schillstrom | 9330419 | 2011-01-03 14:44:51 +0100 | [diff] [blame] | 441 | pd->pp->name, |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 442 | ((direction == IP_VS_DIR_OUTPUT) ? |
| 443 | "output " : "input "), |
Julian Anastasov | f18ae72 | 2014-09-09 16:40:38 -0700 | [diff] [blame] | 444 | IP_VS_DBG_ADDR(cp->daf, &cp->daddr), |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 445 | ntohs(cp->dport), |
| 446 | IP_VS_DBG_ADDR(cp->af, &cp->caddr), |
| 447 | ntohs(cp->cport), |
| 448 | sctp_state_name(cp->state), |
| 449 | sctp_state_name(next_state), |
| 450 | atomic_read(&cp->refcnt)); |
| 451 | if (dest) { |
| 452 | if (!(cp->flags & IP_VS_CONN_F_INACTIVE) && |
| 453 | (next_state != IP_VS_SCTP_S_ESTABLISHED)) { |
| 454 | atomic_dec(&dest->activeconns); |
| 455 | atomic_inc(&dest->inactconns); |
| 456 | cp->flags |= IP_VS_CONN_F_INACTIVE; |
| 457 | } else if ((cp->flags & IP_VS_CONN_F_INACTIVE) && |
| 458 | (next_state == IP_VS_SCTP_S_ESTABLISHED)) { |
| 459 | atomic_inc(&dest->activeconns); |
| 460 | atomic_dec(&dest->inactconns); |
| 461 | cp->flags &= ~IP_VS_CONN_F_INACTIVE; |
| 462 | } |
| 463 | } |
| 464 | } |
Hans Schillstrom | 9d93487 | 2011-01-03 14:44:49 +0100 | [diff] [blame] | 465 | if (likely(pd)) |
| 466 | cp->timeout = pd->timeout_table[cp->state = next_state]; |
| 467 | else /* What to do ? */ |
| 468 | cp->timeout = sctp_timeouts[cp->state = next_state]; |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 469 | } |
| 470 | |
Simon Horman | 4a516f1 | 2011-09-16 14:11:49 +0900 | [diff] [blame] | 471 | static void |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 472 | sctp_state_transition(struct ip_vs_conn *cp, int direction, |
Hans Schillstrom | 9330419 | 2011-01-03 14:44:51 +0100 | [diff] [blame] | 473 | const struct sk_buff *skb, struct ip_vs_proto_data *pd) |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 474 | { |
Julian Anastasov | ac69269 | 2013-03-22 11:46:54 +0200 | [diff] [blame] | 475 | spin_lock_bh(&cp->lock); |
Simon Horman | 4a516f1 | 2011-09-16 14:11:49 +0900 | [diff] [blame] | 476 | set_sctp_state(pd, cp, direction, skb); |
Julian Anastasov | ac69269 | 2013-03-22 11:46:54 +0200 | [diff] [blame] | 477 | spin_unlock_bh(&cp->lock); |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 478 | } |
| 479 | |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 480 | static inline __u16 sctp_app_hashkey(__be16 port) |
| 481 | { |
| 482 | return (((__force u16)port >> SCTP_APP_TAB_BITS) ^ (__force u16)port) |
| 483 | & SCTP_APP_TAB_MASK; |
| 484 | } |
| 485 | |
Eric W. Biederman | 1964891 | 2015-09-21 13:02:29 -0500 | [diff] [blame] | 486 | static int sctp_register_app(struct netns_ipvs *ipvs, struct ip_vs_app *inc) |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 487 | { |
| 488 | struct ip_vs_app *i; |
| 489 | __u16 hash; |
| 490 | __be16 port = inc->port; |
| 491 | int ret = 0; |
Eric W. Biederman | 18d6ade | 2015-09-21 13:02:01 -0500 | [diff] [blame] | 492 | struct ip_vs_proto_data *pd = ip_vs_proto_data_get(ipvs, IPPROTO_SCTP); |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 493 | |
| 494 | hash = sctp_app_hashkey(port); |
| 495 | |
Hans Schillstrom | 9d93487 | 2011-01-03 14:44:49 +0100 | [diff] [blame] | 496 | list_for_each_entry(i, &ipvs->sctp_apps[hash], p_list) { |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 497 | if (i->port == port) { |
| 498 | ret = -EEXIST; |
| 499 | goto out; |
| 500 | } |
| 501 | } |
Julian Anastasov | 363c97d | 2013-03-21 11:58:07 +0200 | [diff] [blame] | 502 | list_add_rcu(&inc->p_list, &ipvs->sctp_apps[hash]); |
Hans Schillstrom | 9bbac6a | 2011-01-03 14:44:52 +0100 | [diff] [blame] | 503 | atomic_inc(&pd->appcnt); |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 504 | out: |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 505 | |
| 506 | return ret; |
| 507 | } |
| 508 | |
Eric W. Biederman | 1964891 | 2015-09-21 13:02:29 -0500 | [diff] [blame] | 509 | static void sctp_unregister_app(struct netns_ipvs *ipvs, struct ip_vs_app *inc) |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 510 | { |
Eric W. Biederman | 1964891 | 2015-09-21 13:02:29 -0500 | [diff] [blame] | 511 | struct ip_vs_proto_data *pd = ip_vs_proto_data_get(ipvs, IPPROTO_SCTP); |
Hans Schillstrom | 9d93487 | 2011-01-03 14:44:49 +0100 | [diff] [blame] | 512 | |
Hans Schillstrom | 9bbac6a | 2011-01-03 14:44:52 +0100 | [diff] [blame] | 513 | atomic_dec(&pd->appcnt); |
Julian Anastasov | 363c97d | 2013-03-21 11:58:07 +0200 | [diff] [blame] | 514 | list_del_rcu(&inc->p_list); |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | static int sctp_app_conn_bind(struct ip_vs_conn *cp) |
| 518 | { |
Eric W. Biederman | 58dbc6f | 2015-09-21 13:01:41 -0500 | [diff] [blame] | 519 | struct netns_ipvs *ipvs = cp->ipvs; |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 520 | int hash; |
| 521 | struct ip_vs_app *inc; |
| 522 | int result = 0; |
| 523 | |
| 524 | /* Default binding: bind app only for NAT */ |
| 525 | if (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ) |
| 526 | return 0; |
| 527 | /* Lookup application incarnations and bind the right one */ |
| 528 | hash = sctp_app_hashkey(cp->vport); |
| 529 | |
Julian Anastasov | 363c97d | 2013-03-21 11:58:07 +0200 | [diff] [blame] | 530 | rcu_read_lock(); |
| 531 | list_for_each_entry_rcu(inc, &ipvs->sctp_apps[hash], p_list) { |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 532 | if (inc->port == cp->vport) { |
| 533 | if (unlikely(!ip_vs_app_inc_get(inc))) |
| 534 | break; |
Julian Anastasov | 363c97d | 2013-03-21 11:58:07 +0200 | [diff] [blame] | 535 | rcu_read_unlock(); |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 536 | |
| 537 | IP_VS_DBG_BUF(9, "%s: Binding conn %s:%u->" |
| 538 | "%s:%u to app %s on port %u\n", |
| 539 | __func__, |
| 540 | IP_VS_DBG_ADDR(cp->af, &cp->caddr), |
| 541 | ntohs(cp->cport), |
| 542 | IP_VS_DBG_ADDR(cp->af, &cp->vaddr), |
| 543 | ntohs(cp->vport), |
| 544 | inc->name, ntohs(inc->port)); |
| 545 | cp->app = inc; |
| 546 | if (inc->init_conn) |
| 547 | result = inc->init_conn(inc, cp); |
| 548 | goto out; |
| 549 | } |
| 550 | } |
Julian Anastasov | 363c97d | 2013-03-21 11:58:07 +0200 | [diff] [blame] | 551 | rcu_read_unlock(); |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 552 | out: |
| 553 | return result; |
| 554 | } |
| 555 | |
Hans Schillstrom | 9d93487 | 2011-01-03 14:44:49 +0100 | [diff] [blame] | 556 | /* --------------------------------------------- |
| 557 | * timeouts is netns related now. |
| 558 | * --------------------------------------------- |
| 559 | */ |
Eric W. Biederman | 1281a9c2 | 2015-09-21 13:02:36 -0500 | [diff] [blame] | 560 | static int __ip_vs_sctp_init(struct netns_ipvs *ipvs, struct ip_vs_proto_data *pd) |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 561 | { |
Hans Schillstrom | 9d93487 | 2011-01-03 14:44:49 +0100 | [diff] [blame] | 562 | ip_vs_init_hash_table(ipvs->sctp_apps, SCTP_APP_TAB_SIZE); |
Hans Schillstrom | 9d93487 | 2011-01-03 14:44:49 +0100 | [diff] [blame] | 563 | pd->timeout_table = ip_vs_create_timeout_table((int *)sctp_timeouts, |
| 564 | sizeof(sctp_timeouts)); |
Hans Schillstrom | 582b8e3 | 2012-04-26 09:45:35 +0200 | [diff] [blame] | 565 | if (!pd->timeout_table) |
| 566 | return -ENOMEM; |
| 567 | return 0; |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 568 | } |
| 569 | |
Eric W. Biederman | 1281a9c2 | 2015-09-21 13:02:36 -0500 | [diff] [blame] | 570 | static void __ip_vs_sctp_exit(struct netns_ipvs *ipvs, struct ip_vs_proto_data *pd) |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 571 | { |
Hans Schillstrom | 9d93487 | 2011-01-03 14:44:49 +0100 | [diff] [blame] | 572 | kfree(pd->timeout_table); |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | struct ip_vs_protocol ip_vs_protocol_sctp = { |
Hans Schillstrom | 9d93487 | 2011-01-03 14:44:49 +0100 | [diff] [blame] | 576 | .name = "SCTP", |
| 577 | .protocol = IPPROTO_SCTP, |
| 578 | .num_states = IP_VS_SCTP_S_LAST, |
| 579 | .dont_defrag = 0, |
| 580 | .init = NULL, |
| 581 | .exit = NULL, |
| 582 | .init_netns = __ip_vs_sctp_init, |
| 583 | .exit_netns = __ip_vs_sctp_exit, |
| 584 | .register_app = sctp_register_app, |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 585 | .unregister_app = sctp_unregister_app, |
Hans Schillstrom | 9d93487 | 2011-01-03 14:44:49 +0100 | [diff] [blame] | 586 | .conn_schedule = sctp_conn_schedule, |
| 587 | .conn_in_get = ip_vs_conn_in_get_proto, |
| 588 | .conn_out_get = ip_vs_conn_out_get_proto, |
| 589 | .snat_handler = sctp_snat_handler, |
| 590 | .dnat_handler = sctp_dnat_handler, |
| 591 | .csum_check = sctp_csum_check, |
| 592 | .state_name = sctp_state_name, |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 593 | .state_transition = sctp_state_transition, |
Hans Schillstrom | 9d93487 | 2011-01-03 14:44:49 +0100 | [diff] [blame] | 594 | .app_conn_bind = sctp_app_conn_bind, |
| 595 | .debug_packet = ip_vs_tcpudp_debug_packet, |
| 596 | .timeout_change = NULL, |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 597 | }; |