Thomas Gleixner | 47505b8 | 2019-05-23 11:14:41 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Vlad Yasevich | 60c778b | 2008-01-11 09:57:09 -0500 | [diff] [blame] | 2 | /* SCTP kernel implementation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Copyright (c) 1999-2000 Cisco, Inc. |
| 4 | * Copyright (c) 1999-2001 Motorola, Inc. |
| 5 | * Copyright (c) 2001-2003 International Business Machines Corp. |
| 6 | * Copyright (c) 2001 Intel Corp. |
| 7 | * Copyright (c) 2001 La Monte H.P. Yarroll |
| 8 | * |
Vlad Yasevich | 60c778b | 2008-01-11 09:57:09 -0500 | [diff] [blame] | 9 | * This file is part of the SCTP kernel implementation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * |
Christophe JAILLET | 5112cf5 | 2020-11-22 19:07:04 +0100 | [diff] [blame] | 11 | * This module provides the abstraction for an SCTP transport representing |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | * a remote transport address. For local transport addresses, we just use |
| 13 | * union sctp_addr. |
| 14 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | * Please send any bug reports or fixes you make to the |
| 16 | * email address(es): |
Daniel Borkmann | 91705c6 | 2013-07-23 14:51:47 +0200 | [diff] [blame] | 17 | * lksctp developers <linux-sctp@vger.kernel.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | * Written or modified by: |
| 20 | * La Monte H.P. Yarroll <piggy@acm.org> |
| 21 | * Karl Knutson <karl@athena.chicago.il.us> |
| 22 | * Jon Grimm <jgrimm@us.ibm.com> |
| 23 | * Xingang Guo <xingang.guo@intel.com> |
| 24 | * Hui Huang <hui.huang@nokia.com> |
| 25 | * Sridhar Samudrala <sri@us.ibm.com> |
| 26 | * Ardelle Fan <ardelle.fan@intel.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | */ |
| 28 | |
Joe Perches | 145ce50 | 2010-08-24 13:21:08 +0000 | [diff] [blame] | 29 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 30 | |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 31 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <linux/types.h> |
Sridhar Samudrala | ad8fec1 | 2006-07-21 14:48:50 -0700 | [diff] [blame] | 33 | #include <linux/random.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <net/sctp/sctp.h> |
| 35 | #include <net/sctp/sm.h> |
| 36 | |
| 37 | /* 1st Level Abstractions. */ |
| 38 | |
| 39 | /* Initialize a new transport from provided memory. */ |
Eric W. Biederman | 89bf345 | 2012-08-07 07:26:14 +0000 | [diff] [blame] | 40 | static struct sctp_transport *sctp_transport_init(struct net *net, |
| 41 | struct sctp_transport *peer, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | const union sctp_addr *addr, |
Al Viro | dd0fc66 | 2005-10-07 07:46:04 +0100 | [diff] [blame] | 43 | gfp_t gfp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | { |
| 45 | /* Copy in the address. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | peer->af_specific = sctp_get_af_specific(addr->sa.sa_family); |
Xin Long | 4c31bc6 | 2019-07-30 20:38:19 +0800 | [diff] [blame] | 47 | memcpy(&peer->ipaddr, addr, peer->af_specific->sockaddr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | memset(&peer->saddr, 0, sizeof(union sctp_addr)); |
| 49 | |
Neil Horman | 4244854 | 2012-06-30 03:04:26 +0000 | [diff] [blame] | 50 | peer->sack_generation = 0; |
| 51 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | /* From 6.3.1 RTO Calculation: |
| 53 | * |
| 54 | * C1) Until an RTT measurement has been made for a packet sent to the |
| 55 | * given destination transport address, set RTO to the protocol |
| 56 | * parameter 'RTO.Initial'. |
| 57 | */ |
Eric W. Biederman | e1fc3b1 | 2012-08-07 07:29:57 +0000 | [diff] [blame] | 58 | peer->rto = msecs_to_jiffies(net->sctp.rto_initial); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
Thomas Gleixner | 8b0e195 | 2016-12-25 12:30:41 +0100 | [diff] [blame] | 60 | peer->last_time_heard = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | peer->last_time_ecne_reduced = jiffies; |
| 62 | |
Frank Filz | 52ccb8e | 2005-12-22 11:36:46 -0800 | [diff] [blame] | 63 | peer->param_flags = SPP_HB_DISABLE | |
| 64 | SPP_PMTUD_ENABLE | |
| 65 | SPP_SACKDELAY_ENABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
| 67 | /* Initialize the default path max_retrans. */ |
Eric W. Biederman | e1fc3b1 | 2012-08-07 07:29:57 +0000 | [diff] [blame] | 68 | peer->pathmaxrxt = net->sctp.max_retrans_path; |
| 69 | peer->pf_retrans = net->sctp.pf_retrans; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
| 71 | INIT_LIST_HEAD(&peer->transmitted); |
| 72 | INIT_LIST_HEAD(&peer->send_ready); |
| 73 | INIT_LIST_HEAD(&peer->transports); |
| 74 | |
Kees Cook | 9c3b575 | 2017-10-24 01:45:31 -0700 | [diff] [blame] | 75 | timer_setup(&peer->T3_rtx_timer, sctp_generate_t3_rtx_event, 0); |
| 76 | timer_setup(&peer->hb_timer, sctp_generate_heartbeat_event, 0); |
| 77 | timer_setup(&peer->reconf_timer, sctp_generate_reconf_event, 0); |
Xin Long | 92548ec | 2021-06-22 14:04:51 -0400 | [diff] [blame] | 78 | timer_setup(&peer->probe_timer, sctp_generate_probe_event, 0); |
Kees Cook | 9c3b575 | 2017-10-24 01:45:31 -0700 | [diff] [blame] | 79 | timer_setup(&peer->proto_unreach_timer, |
| 80 | sctp_generate_proto_unreach_event, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
Sridhar Samudrala | ad8fec1 | 2006-07-21 14:48:50 -0700 | [diff] [blame] | 82 | /* Initialize the 64-bit random nonce sent with heartbeat. */ |
| 83 | get_random_bytes(&peer->hb_nonce, sizeof(peer->hb_nonce)); |
| 84 | |
Reshetova, Elena | a4b2b58 | 2017-07-04 15:53:27 +0300 | [diff] [blame] | 85 | refcount_set(&peer->refcnt, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
| 87 | return peer; |
| 88 | } |
| 89 | |
| 90 | /* Allocate and initialize a new transport. */ |
Eric W. Biederman | 89bf345 | 2012-08-07 07:26:14 +0000 | [diff] [blame] | 91 | struct sctp_transport *sctp_transport_new(struct net *net, |
| 92 | const union sctp_addr *addr, |
Al Viro | dd0fc66 | 2005-10-07 07:46:04 +0100 | [diff] [blame] | 93 | gfp_t gfp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | { |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 95 | struct sctp_transport *transport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
Daniel Borkmann | 939cfa7 | 2013-06-17 11:40:04 +0200 | [diff] [blame] | 97 | transport = kzalloc(sizeof(*transport), gfp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | if (!transport) |
| 99 | goto fail; |
| 100 | |
Eric W. Biederman | 89bf345 | 2012-08-07 07:26:14 +0000 | [diff] [blame] | 101 | if (!sctp_transport_init(net, transport, addr, gfp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | goto fail_init; |
| 103 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | SCTP_DBG_OBJCNT_INC(transport); |
| 105 | |
| 106 | return transport; |
| 107 | |
| 108 | fail_init: |
| 109 | kfree(transport); |
| 110 | |
| 111 | fail: |
| 112 | return NULL; |
| 113 | } |
| 114 | |
| 115 | /* This transport is no longer needed. Free up if possible, or |
| 116 | * delay until it last reference count. |
| 117 | */ |
| 118 | void sctp_transport_free(struct sctp_transport *transport) |
| 119 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | /* Try to delete the heartbeat timer. */ |
| 121 | if (del_timer(&transport->hb_timer)) |
| 122 | sctp_transport_put(transport); |
| 123 | |
| 124 | /* Delete the T3_rtx timer if it's active. |
| 125 | * There is no point in not doing this now and letting |
| 126 | * structure hang around in memory since we know |
Christophe JAILLET | 5112cf5 | 2020-11-22 19:07:04 +0100 | [diff] [blame] | 127 | * the transport is going away. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | */ |
Ying Xue | 25cc4ae | 2013-02-03 20:32:57 +0000 | [diff] [blame] | 129 | if (del_timer(&transport->T3_rtx_timer)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | sctp_transport_put(transport); |
| 131 | |
Xin Long | 7b9438d | 2017-01-18 00:44:43 +0800 | [diff] [blame] | 132 | if (del_timer(&transport->reconf_timer)) |
| 133 | sctp_transport_put(transport); |
| 134 | |
Xin Long | 92548ec | 2021-06-22 14:04:51 -0400 | [diff] [blame] | 135 | if (del_timer(&transport->probe_timer)) |
| 136 | sctp_transport_put(transport); |
| 137 | |
Wei Yongjun | 55fa0cf | 2010-05-09 16:56:07 +0000 | [diff] [blame] | 138 | /* Delete the ICMP proto unreachable timer if it's active. */ |
Ying Xue | 25cc4ae | 2013-02-03 20:32:57 +0000 | [diff] [blame] | 139 | if (del_timer(&transport->proto_unreach_timer)) |
Xin Long | 057a10f | 2020-11-14 13:22:53 +0800 | [diff] [blame] | 140 | sctp_transport_put(transport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
| 142 | sctp_transport_put(transport); |
| 143 | } |
| 144 | |
Thomas Graf | 45122ca26 | 2012-12-06 09:25:05 +0000 | [diff] [blame] | 145 | static void sctp_transport_destroy_rcu(struct rcu_head *head) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | { |
Thomas Graf | 45122ca26 | 2012-12-06 09:25:05 +0000 | [diff] [blame] | 147 | struct sctp_transport *transport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
Thomas Graf | 45122ca26 | 2012-12-06 09:25:05 +0000 | [diff] [blame] | 149 | transport = container_of(head, struct sctp_transport, rcu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
| 151 | dst_release(transport->dst); |
| 152 | kfree(transport); |
| 153 | SCTP_DBG_OBJCNT_DEC(transport); |
| 154 | } |
| 155 | |
Thomas Graf | 45122ca26 | 2012-12-06 09:25:05 +0000 | [diff] [blame] | 156 | /* Destroy the transport data structure. |
| 157 | * Assumes there are no more users of this structure. |
| 158 | */ |
| 159 | static void sctp_transport_destroy(struct sctp_transport *transport) |
| 160 | { |
Reshetova, Elena | a4b2b58 | 2017-07-04 15:53:27 +0300 | [diff] [blame] | 161 | if (unlikely(refcount_read(&transport->refcnt))) { |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 162 | WARN(1, "Attempt to destroy undead transport %p!\n", transport); |
| 163 | return; |
| 164 | } |
Thomas Graf | 45122ca26 | 2012-12-06 09:25:05 +0000 | [diff] [blame] | 165 | |
Daniel Borkmann | 8c98653 | 2013-02-01 04:37:43 +0000 | [diff] [blame] | 166 | sctp_packet_free(&transport->packet); |
| 167 | |
| 168 | if (transport->asoc) |
| 169 | sctp_association_put(transport->asoc); |
Daniel Borkmann | 771085d | 2013-08-09 16:25:21 +0200 | [diff] [blame] | 170 | |
| 171 | call_rcu(&transport->rcu, sctp_transport_destroy_rcu); |
Thomas Graf | 45122ca26 | 2012-12-06 09:25:05 +0000 | [diff] [blame] | 172 | } |
| 173 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | /* Start T3_rtx timer if it is not already running and update the heartbeat |
| 175 | * timer. This routine is called every time a DATA chunk is sent. |
| 176 | */ |
Marcelo Ricardo Leitner | ba6f5e3 | 2016-04-06 15:15:19 -0300 | [diff] [blame] | 177 | void sctp_transport_reset_t3_rtx(struct sctp_transport *transport) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | { |
| 179 | /* RFC 2960 6.3.2 Retransmission Timer Rules |
| 180 | * |
| 181 | * R1) Every time a DATA chunk is sent to any address(including a |
| 182 | * retransmission), if the T3-rtx timer of that address is not running |
| 183 | * start it running so that it will expire after the RTO of that |
| 184 | * address. |
| 185 | */ |
| 186 | |
Vlad Yasevich | d9efc22 | 2010-04-30 22:41:09 -0400 | [diff] [blame] | 187 | if (!timer_pending(&transport->T3_rtx_timer)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | if (!mod_timer(&transport->T3_rtx_timer, |
| 189 | jiffies + transport->rto)) |
| 190 | sctp_transport_hold(transport); |
Marcelo Ricardo Leitner | ba6f5e3 | 2016-04-06 15:15:19 -0300 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | void sctp_transport_reset_hb_timer(struct sctp_transport *transport) |
| 194 | { |
| 195 | unsigned long expires; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | |
| 197 | /* When a data chunk is sent, reset the heartbeat interval. */ |
Marcelo Ricardo Leitner | ba6f5e3 | 2016-04-06 15:15:19 -0300 | [diff] [blame] | 198 | expires = jiffies + sctp_transport_timeout(transport); |
Maciej Kwiecien | d1f20c0 | 2019-02-22 09:45:26 +0100 | [diff] [blame] | 199 | if ((time_before(transport->hb_timer.expires, expires) || |
| 200 | !timer_pending(&transport->hb_timer)) && |
Marcelo Ricardo Leitner | ba6f5e3 | 2016-04-06 15:15:19 -0300 | [diff] [blame] | 201 | !mod_timer(&transport->hb_timer, |
| 202 | expires + prandom_u32_max(transport->rto))) |
| 203 | sctp_transport_hold(transport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | } |
| 205 | |
Xin Long | 7b9438d | 2017-01-18 00:44:43 +0800 | [diff] [blame] | 206 | void sctp_transport_reset_reconf_timer(struct sctp_transport *transport) |
| 207 | { |
| 208 | if (!timer_pending(&transport->reconf_timer)) |
| 209 | if (!mod_timer(&transport->reconf_timer, |
| 210 | jiffies + transport->rto)) |
| 211 | sctp_transport_hold(transport); |
| 212 | } |
| 213 | |
Xin Long | 92548ec | 2021-06-22 14:04:51 -0400 | [diff] [blame] | 214 | void sctp_transport_reset_probe_timer(struct sctp_transport *transport) |
| 215 | { |
| 216 | int scale = 1; |
| 217 | |
| 218 | if (timer_pending(&transport->probe_timer)) |
| 219 | return; |
| 220 | if (transport->pl.state == SCTP_PL_COMPLETE && |
| 221 | transport->pl.probe_count == 1) |
| 222 | scale = 30; /* works as PMTU_RAISE_TIMER */ |
| 223 | if (!mod_timer(&transport->probe_timer, |
| 224 | jiffies + transport->probe_interval * scale)) |
| 225 | sctp_transport_hold(transport); |
| 226 | } |
| 227 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | /* This transport has been assigned to an association. |
| 229 | * Initialize fields from the association or from the sock itself. |
| 230 | * Register the reference count in the association. |
| 231 | */ |
| 232 | void sctp_transport_set_owner(struct sctp_transport *transport, |
| 233 | struct sctp_association *asoc) |
| 234 | { |
| 235 | transport->asoc = asoc; |
| 236 | sctp_association_hold(asoc); |
| 237 | } |
| 238 | |
| 239 | /* Initialize the pmtu of a transport. */ |
Vlad Yasevich | 9914ae3 | 2011-04-26 21:51:31 +0000 | [diff] [blame] | 240 | void sctp_transport_pmtu(struct sctp_transport *transport, struct sock *sk) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | { |
Vlad Yasevich | da0420b | 2011-04-26 21:54:17 +0000 | [diff] [blame] | 242 | /* If we don't have a fresh route, look one up */ |
David S. Miller | f5b0a87 | 2012-07-19 12:31:33 -0700 | [diff] [blame] | 243 | if (!transport->dst || transport->dst->obsolete) { |
Julian Anastasov | c86a773 | 2017-02-06 23:14:13 +0200 | [diff] [blame] | 244 | sctp_transport_dst_release(transport); |
Vlad Yasevich | da0420b | 2011-04-26 21:54:17 +0000 | [diff] [blame] | 245 | transport->af_specific->get_dst(transport, &transport->saddr, |
David S. Miller | 8663c93 | 2011-05-06 16:32:47 -0700 | [diff] [blame] | 246 | &transport->fl, sk); |
Vlad Yasevich | da0420b | 2011-04-26 21:54:17 +0000 | [diff] [blame] | 247 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
Marcelo Ricardo Leitner | 6e91b57 | 2018-04-26 16:58:59 -0300 | [diff] [blame] | 249 | if (transport->param_flags & SPP_PMTUD_DISABLE) { |
| 250 | struct sctp_association *asoc = transport->asoc; |
| 251 | |
| 252 | if (!transport->pathmtu && asoc && asoc->pathmtu) |
| 253 | transport->pathmtu = asoc->pathmtu; |
| 254 | if (transport->pathmtu) |
| 255 | return; |
| 256 | } |
| 257 | |
Marcelo Ricardo Leitner | 6ff0f87 | 2018-04-26 16:58:57 -0300 | [diff] [blame] | 258 | if (transport->dst) |
| 259 | transport->pathmtu = sctp_dst_mtu(transport->dst); |
| 260 | else |
Frank Filz | 52ccb8e | 2005-12-22 11:36:46 -0800 | [diff] [blame] | 261 | transport->pathmtu = SCTP_DEFAULT_MAXSEGMENT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Xin Long | 1dc68c1 | 2021-06-22 14:04:53 -0400 | [diff] [blame^] | 264 | void sctp_transport_pl_send(struct sctp_transport *t) |
| 265 | { |
| 266 | pr_debug("%s: PLPMTUD: transport: %p, state: %d, pmtu: %d, size: %d, high: %d\n", |
| 267 | __func__, t, t->pl.state, t->pl.pmtu, t->pl.probe_size, t->pl.probe_high); |
| 268 | |
| 269 | if (t->pl.probe_count < SCTP_MAX_PROBES) { |
| 270 | t->pl.probe_count++; |
| 271 | return; |
| 272 | } |
| 273 | |
| 274 | if (t->pl.state == SCTP_PL_BASE) { |
| 275 | if (t->pl.probe_size == SCTP_BASE_PLPMTU) { /* BASE_PLPMTU Confirmation Failed */ |
| 276 | t->pl.state = SCTP_PL_ERROR; /* Base -> Error */ |
| 277 | |
| 278 | t->pl.pmtu = SCTP_MIN_PLPMTU; |
| 279 | t->pathmtu = t->pl.pmtu + sctp_transport_pl_hlen(t); |
| 280 | sctp_assoc_sync_pmtu(t->asoc); |
| 281 | } |
| 282 | } else if (t->pl.state == SCTP_PL_SEARCH) { |
| 283 | if (t->pl.pmtu == t->pl.probe_size) { /* Black Hole Detected */ |
| 284 | t->pl.state = SCTP_PL_BASE; /* Search -> Base */ |
| 285 | t->pl.probe_size = SCTP_BASE_PLPMTU; |
| 286 | t->pl.probe_high = 0; |
| 287 | |
| 288 | t->pl.pmtu = SCTP_BASE_PLPMTU; |
| 289 | t->pathmtu = t->pl.pmtu + sctp_transport_pl_hlen(t); |
| 290 | sctp_assoc_sync_pmtu(t->asoc); |
| 291 | } else { /* Normal probe failure. */ |
| 292 | t->pl.probe_high = t->pl.probe_size; |
| 293 | t->pl.probe_size = t->pl.pmtu; |
| 294 | } |
| 295 | } else if (t->pl.state == SCTP_PL_COMPLETE) { |
| 296 | if (t->pl.pmtu == t->pl.probe_size) { /* Black Hole Detected */ |
| 297 | t->pl.state = SCTP_PL_BASE; /* Search Complete -> Base */ |
| 298 | t->pl.probe_size = SCTP_BASE_PLPMTU; |
| 299 | |
| 300 | t->pl.pmtu = SCTP_BASE_PLPMTU; |
| 301 | t->pathmtu = t->pl.pmtu + sctp_transport_pl_hlen(t); |
| 302 | sctp_assoc_sync_pmtu(t->asoc); |
| 303 | } |
| 304 | } |
| 305 | t->pl.probe_count = 1; |
| 306 | } |
| 307 | |
Marcelo Ricardo Leitner | b6c5734 | 2018-01-05 11:17:18 -0200 | [diff] [blame] | 308 | bool sctp_transport_update_pmtu(struct sctp_transport *t, u32 pmtu) |
Vlad Yasevich | c910b47 | 2007-06-07 13:47:03 -0400 | [diff] [blame] | 309 | { |
Xin Long | 3ebfdf0 | 2017-04-04 13:39:55 +0800 | [diff] [blame] | 310 | struct dst_entry *dst = sctp_transport_dst_check(t); |
Xin Long | d7ab5cd | 2018-09-20 17:27:28 +0800 | [diff] [blame] | 311 | struct sock *sk = t->asoc->base.sk; |
Marcelo Ricardo Leitner | b6c5734 | 2018-01-05 11:17:18 -0200 | [diff] [blame] | 312 | bool change = true; |
Vlad Yasevich | c910b47 | 2007-06-07 13:47:03 -0400 | [diff] [blame] | 313 | |
| 314 | if (unlikely(pmtu < SCTP_DEFAULT_MINSEGMENT)) { |
Marcelo Ricardo Leitner | b6c5734 | 2018-01-05 11:17:18 -0200 | [diff] [blame] | 315 | pr_warn_ratelimited("%s: Reported pmtu %d too low, using default minimum of %d\n", |
| 316 | __func__, pmtu, SCTP_DEFAULT_MINSEGMENT); |
| 317 | /* Use default minimum segment instead */ |
| 318 | pmtu = SCTP_DEFAULT_MINSEGMENT; |
Vlad Yasevich | c910b47 | 2007-06-07 13:47:03 -0400 | [diff] [blame] | 319 | } |
Marcelo Ricardo Leitner | b6c5734 | 2018-01-05 11:17:18 -0200 | [diff] [blame] | 320 | pmtu = SCTP_TRUNC4(pmtu); |
Vlad Yasevich | c910b47 | 2007-06-07 13:47:03 -0400 | [diff] [blame] | 321 | |
David S. Miller | 02f3d4c | 2012-07-16 03:57:14 -0700 | [diff] [blame] | 322 | if (dst) { |
Xin Long | d7ab5cd | 2018-09-20 17:27:28 +0800 | [diff] [blame] | 323 | struct sctp_pf *pf = sctp_get_pf_specific(dst->ops->family); |
| 324 | union sctp_addr addr; |
| 325 | |
| 326 | pf->af->from_sk(&addr, sk); |
| 327 | pf->to_sk_daddr(&t->ipaddr, sk); |
Hangbin Liu | bd085ef | 2019-12-22 10:51:09 +0800 | [diff] [blame] | 328 | dst->ops->update_pmtu(dst, sk, NULL, pmtu, true); |
Xin Long | d7ab5cd | 2018-09-20 17:27:28 +0800 | [diff] [blame] | 329 | pf->to_sk_daddr(&addr, sk); |
| 330 | |
David S. Miller | 02f3d4c | 2012-07-16 03:57:14 -0700 | [diff] [blame] | 331 | dst = sctp_transport_dst_check(t); |
David S. Miller | 02f3d4c | 2012-07-16 03:57:14 -0700 | [diff] [blame] | 332 | } |
Xin Long | 3ebfdf0 | 2017-04-04 13:39:55 +0800 | [diff] [blame] | 333 | |
Marcelo Ricardo Leitner | b6c5734 | 2018-01-05 11:17:18 -0200 | [diff] [blame] | 334 | if (!dst) { |
Xin Long | d7ab5cd | 2018-09-20 17:27:28 +0800 | [diff] [blame] | 335 | t->af_specific->get_dst(t, &t->saddr, &t->fl, sk); |
Marcelo Ricardo Leitner | b6c5734 | 2018-01-05 11:17:18 -0200 | [diff] [blame] | 336 | dst = t->dst; |
| 337 | } |
| 338 | |
| 339 | if (dst) { |
| 340 | /* Re-fetch, as under layers may have a higher minimum size */ |
Xin Long | a659254 | 2018-07-03 16:30:47 +0800 | [diff] [blame] | 341 | pmtu = sctp_dst_mtu(dst); |
Marcelo Ricardo Leitner | b6c5734 | 2018-01-05 11:17:18 -0200 | [diff] [blame] | 342 | change = t->pathmtu != pmtu; |
| 343 | } |
| 344 | t->pathmtu = pmtu; |
| 345 | |
| 346 | return change; |
Vlad Yasevich | c910b47 | 2007-06-07 13:47:03 -0400 | [diff] [blame] | 347 | } |
| 348 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | /* Caches the dst entry and source address for a transport's destination |
| 350 | * address. |
| 351 | */ |
| 352 | void sctp_transport_route(struct sctp_transport *transport, |
| 353 | union sctp_addr *saddr, struct sctp_sock *opt) |
| 354 | { |
| 355 | struct sctp_association *asoc = transport->asoc; |
| 356 | struct sctp_af *af = transport->af_specific; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | |
Marcelo Ricardo Leitner | 6e91b57 | 2018-04-26 16:58:59 -0300 | [diff] [blame] | 358 | sctp_transport_dst_release(transport); |
David S. Miller | 8663c93 | 2011-05-06 16:32:47 -0700 | [diff] [blame] | 359 | af->get_dst(transport, saddr, &transport->fl, sctp_opt2sk(opt)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | |
| 361 | if (saddr) |
| 362 | memcpy(&transport->saddr, saddr, sizeof(union sctp_addr)); |
| 363 | else |
David S. Miller | 8663c93 | 2011-05-06 16:32:47 -0700 | [diff] [blame] | 364 | af->get_saddr(opt, transport, &transport->fl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | |
Marcelo Ricardo Leitner | 6e91b57 | 2018-04-26 16:58:59 -0300 | [diff] [blame] | 366 | sctp_transport_pmtu(transport, sctp_opt2sk(opt)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | |
Marcelo Ricardo Leitner | 6e91b57 | 2018-04-26 16:58:59 -0300 | [diff] [blame] | 368 | /* Initialize sk->sk_rcv_saddr, if the transport is the |
| 369 | * association's active path for getsockname(). |
| 370 | */ |
| 371 | if (transport->dst && asoc && |
| 372 | (!asoc->peer.primary_path || transport == asoc->peer.active_path)) |
| 373 | opt->pf->to_sk_saddr(&transport->saddr, asoc->base.sk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | /* Hold a reference to a transport. */ |
Xin Long | 1eed677 | 2016-01-22 01:49:07 +0800 | [diff] [blame] | 377 | int sctp_transport_hold(struct sctp_transport *transport) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | { |
Reshetova, Elena | a4b2b58 | 2017-07-04 15:53:27 +0300 | [diff] [blame] | 379 | return refcount_inc_not_zero(&transport->refcnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | /* Release a reference to a transport and clean up |
| 383 | * if there are no more references. |
| 384 | */ |
| 385 | void sctp_transport_put(struct sctp_transport *transport) |
| 386 | { |
Reshetova, Elena | a4b2b58 | 2017-07-04 15:53:27 +0300 | [diff] [blame] | 387 | if (refcount_dec_and_test(&transport->refcnt)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | sctp_transport_destroy(transport); |
| 389 | } |
| 390 | |
| 391 | /* Update transport's RTO based on the newly calculated RTT. */ |
| 392 | void sctp_transport_update_rto(struct sctp_transport *tp, __u32 rtt) |
| 393 | { |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 394 | if (unlikely(!tp->rto_pending)) |
| 395 | /* We should not be doing any RTO updates unless rto_pending is set. */ |
| 396 | pr_debug("%s: rto_pending not set on transport %p!\n", __func__, tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | |
| 398 | if (tp->rttvar || tp->srtt) { |
Xin Long | 4e7696d | 2019-12-09 13:45:18 +0800 | [diff] [blame] | 399 | struct net *net = tp->asoc->base.net; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | /* 6.3.1 C3) When a new RTT measurement R' is made, set |
| 401 | * RTTVAR <- (1 - RTO.Beta) * RTTVAR + RTO.Beta * |SRTT - R'| |
| 402 | * SRTT <- (1 - RTO.Alpha) * SRTT + RTO.Alpha * R' |
| 403 | */ |
| 404 | |
| 405 | /* Note: The above algorithm has been rewritten to |
| 406 | * express rto_beta and rto_alpha as inverse powers |
| 407 | * of two. |
| 408 | * For example, assuming the default value of RTO.Alpha of |
| 409 | * 1/8, rto_alpha would be expressed as 3. |
| 410 | */ |
Eric W. Biederman | e1fc3b1 | 2012-08-07 07:29:57 +0000 | [diff] [blame] | 411 | tp->rttvar = tp->rttvar - (tp->rttvar >> net->sctp.rto_beta) |
Andrew Morton | 79211c8 | 2015-11-09 14:58:13 -0800 | [diff] [blame] | 412 | + (((__u32)abs((__s64)tp->srtt - (__s64)rtt)) >> net->sctp.rto_beta); |
Eric W. Biederman | e1fc3b1 | 2012-08-07 07:29:57 +0000 | [diff] [blame] | 413 | tp->srtt = tp->srtt - (tp->srtt >> net->sctp.rto_alpha) |
| 414 | + (rtt >> net->sctp.rto_alpha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | } else { |
| 416 | /* 6.3.1 C2) When the first RTT measurement R is made, set |
| 417 | * SRTT <- R, RTTVAR <- R/2. |
| 418 | */ |
| 419 | tp->srtt = rtt; |
| 420 | tp->rttvar = rtt >> 1; |
| 421 | } |
| 422 | |
| 423 | /* 6.3.1 G1) Whenever RTTVAR is computed, if RTTVAR = 0, then |
| 424 | * adjust RTTVAR <- G, where G is the CLOCK GRANULARITY. |
| 425 | */ |
| 426 | if (tp->rttvar == 0) |
| 427 | tp->rttvar = SCTP_CLOCK_GRANULARITY; |
| 428 | |
| 429 | /* 6.3.1 C3) After the computation, update RTO <- SRTT + 4 * RTTVAR. */ |
| 430 | tp->rto = tp->srtt + (tp->rttvar << 2); |
| 431 | |
| 432 | /* 6.3.1 C6) Whenever RTO is computed, if it is less than RTO.Min |
| 433 | * seconds then it is rounded up to RTO.Min seconds. |
| 434 | */ |
| 435 | if (tp->rto < tp->asoc->rto_min) |
| 436 | tp->rto = tp->asoc->rto_min; |
| 437 | |
| 438 | /* 6.3.1 C7) A maximum value may be placed on RTO provided it is |
| 439 | * at least RTO.max seconds. |
| 440 | */ |
| 441 | if (tp->rto > tp->asoc->rto_max) |
| 442 | tp->rto = tp->asoc->rto_max; |
| 443 | |
Michele Baldessari | 196d675 | 2012-12-01 04:49:42 +0000 | [diff] [blame] | 444 | sctp_max_rto(tp->asoc, tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | tp->rtt = rtt; |
| 446 | |
| 447 | /* Reset rto_pending so that a new RTT measurement is started when a |
| 448 | * new data chunk is sent. |
| 449 | */ |
| 450 | tp->rto_pending = 0; |
| 451 | |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 452 | pr_debug("%s: transport:%p, rtt:%d, srtt:%d rttvar:%d, rto:%ld\n", |
| 453 | __func__, tp, rtt, tp->srtt, tp->rttvar, tp->rto); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | /* This routine updates the transport's cwnd and partial_bytes_acked |
| 457 | * parameters based on the bytes acked in the received SACK. |
| 458 | */ |
| 459 | void sctp_transport_raise_cwnd(struct sctp_transport *transport, |
| 460 | __u32 sack_ctsn, __u32 bytes_acked) |
| 461 | { |
Vlad Yasevich | cf9b481 | 2010-04-30 22:41:10 -0400 | [diff] [blame] | 462 | struct sctp_association *asoc = transport->asoc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | __u32 cwnd, ssthresh, flight_size, pba, pmtu; |
| 464 | |
| 465 | cwnd = transport->cwnd; |
| 466 | flight_size = transport->flight_size; |
| 467 | |
Vlad Yasevich | a646523 | 2008-06-04 12:38:43 -0700 | [diff] [blame] | 468 | /* See if we need to exit Fast Recovery first */ |
Vlad Yasevich | cf9b481 | 2010-04-30 22:41:10 -0400 | [diff] [blame] | 469 | if (asoc->fast_recovery && |
| 470 | TSN_lte(asoc->fast_recovery_exit, sack_ctsn)) |
| 471 | asoc->fast_recovery = 0; |
Vlad Yasevich | a646523 | 2008-06-04 12:38:43 -0700 | [diff] [blame] | 472 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | ssthresh = transport->ssthresh; |
| 474 | pba = transport->partial_bytes_acked; |
Frank Filz | 52ccb8e | 2005-12-22 11:36:46 -0800 | [diff] [blame] | 475 | pmtu = transport->asoc->pathmtu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | |
| 477 | if (cwnd <= ssthresh) { |
Vlad Yasevich | a646523 | 2008-06-04 12:38:43 -0700 | [diff] [blame] | 478 | /* RFC 4960 7.2.1 |
| 479 | * o When cwnd is less than or equal to ssthresh, an SCTP |
| 480 | * endpoint MUST use the slow-start algorithm to increase |
| 481 | * cwnd only if the current congestion window is being fully |
| 482 | * utilized, an incoming SACK advances the Cumulative TSN |
| 483 | * Ack Point, and the data sender is not in Fast Recovery. |
| 484 | * Only when these three conditions are met can the cwnd be |
| 485 | * increased; otherwise, the cwnd MUST not be increased. |
| 486 | * If these conditions are met, then cwnd MUST be increased |
| 487 | * by, at most, the lesser of 1) the total size of the |
| 488 | * previously outstanding DATA chunk(s) acknowledged, and |
| 489 | * 2) the destination's path MTU. This upper bound protects |
| 490 | * against the ACK-Splitting attack outlined in [SAVAGE99]. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | */ |
Vlad Yasevich | cf9b481 | 2010-04-30 22:41:10 -0400 | [diff] [blame] | 492 | if (asoc->fast_recovery) |
Vlad Yasevich | a646523 | 2008-06-04 12:38:43 -0700 | [diff] [blame] | 493 | return; |
| 494 | |
Marcelo Ricardo Leitner | 4ccbd0b | 2017-06-23 19:59:35 -0300 | [diff] [blame] | 495 | /* The appropriate cwnd increase algorithm is performed |
| 496 | * if, and only if the congestion window is being fully |
| 497 | * utilized. Note that RFC4960 Errata 3.22 removed the |
| 498 | * other condition on ctsn moving. |
| 499 | */ |
| 500 | if (flight_size < cwnd) |
| 501 | return; |
| 502 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | if (bytes_acked > pmtu) |
| 504 | cwnd += pmtu; |
| 505 | else |
| 506 | cwnd += bytes_acked; |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 507 | |
| 508 | pr_debug("%s: slow start: transport:%p, bytes_acked:%d, " |
| 509 | "cwnd:%d, ssthresh:%d, flight_size:%d, pba:%d\n", |
| 510 | __func__, transport, bytes_acked, cwnd, ssthresh, |
| 511 | flight_size, pba); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | } else { |
| 513 | /* RFC 2960 7.2.2 Whenever cwnd is greater than ssthresh, |
Marcelo Ricardo Leitner | e56f777a | 2017-06-23 19:59:34 -0300 | [diff] [blame] | 514 | * upon each SACK arrival, increase partial_bytes_acked |
| 515 | * by the total number of bytes of all new chunks |
| 516 | * acknowledged in that SACK including chunks |
| 517 | * acknowledged by the new Cumulative TSN Ack and by Gap |
| 518 | * Ack Blocks. (updated by RFC4960 Errata 3.22) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | * |
Marcelo Ricardo Leitner | 4ccbd0b | 2017-06-23 19:59:35 -0300 | [diff] [blame] | 520 | * When partial_bytes_acked is greater than cwnd and |
| 521 | * before the arrival of the SACK the sender had less |
| 522 | * bytes of data outstanding than cwnd (i.e., before |
| 523 | * arrival of the SACK, flightsize was less than cwnd), |
| 524 | * reset partial_bytes_acked to cwnd. (RFC 4960 Errata |
| 525 | * 3.26) |
| 526 | * |
Marcelo Ricardo Leitner | d0b53f4 | 2017-06-23 19:59:33 -0300 | [diff] [blame] | 527 | * When partial_bytes_acked is equal to or greater than |
| 528 | * cwnd and before the arrival of the SACK the sender |
| 529 | * had cwnd or more bytes of data outstanding (i.e., |
| 530 | * before arrival of the SACK, flightsize was greater |
| 531 | * than or equal to cwnd), partial_bytes_acked is reset |
| 532 | * to (partial_bytes_acked - cwnd). Next, cwnd is |
| 533 | * increased by MTU. (RFC 4960 Errata 3.12) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | */ |
| 535 | pba += bytes_acked; |
Marcelo Ricardo Leitner | 4ccbd0b | 2017-06-23 19:59:35 -0300 | [diff] [blame] | 536 | if (pba > cwnd && flight_size < cwnd) |
| 537 | pba = cwnd; |
| 538 | if (pba >= cwnd && flight_size >= cwnd) { |
Marcelo Ricardo Leitner | d0b53f4 | 2017-06-23 19:59:33 -0300 | [diff] [blame] | 539 | pba = pba - cwnd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | cwnd += pmtu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | } |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 542 | |
| 543 | pr_debug("%s: congestion avoidance: transport:%p, " |
| 544 | "bytes_acked:%d, cwnd:%d, ssthresh:%d, " |
| 545 | "flight_size:%d, pba:%d\n", __func__, |
| 546 | transport, bytes_acked, cwnd, ssthresh, |
| 547 | flight_size, pba); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | transport->cwnd = cwnd; |
| 551 | transport->partial_bytes_acked = pba; |
| 552 | } |
| 553 | |
| 554 | /* This routine is used to lower the transport's cwnd when congestion is |
| 555 | * detected. |
| 556 | */ |
| 557 | void sctp_transport_lower_cwnd(struct sctp_transport *transport, |
Xin Long | 233e793 | 2017-08-05 19:59:51 +0800 | [diff] [blame] | 558 | enum sctp_lower_cwnd reason) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | { |
Vlad Yasevich | cf9b481 | 2010-04-30 22:41:10 -0400 | [diff] [blame] | 560 | struct sctp_association *asoc = transport->asoc; |
| 561 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | switch (reason) { |
| 563 | case SCTP_LOWER_CWND_T3_RTX: |
| 564 | /* RFC 2960 Section 7.2.3, sctpimpguide |
| 565 | * When the T3-rtx timer expires on an address, SCTP should |
| 566 | * perform slow start by: |
| 567 | * ssthresh = max(cwnd/2, 4*MTU) |
| 568 | * cwnd = 1*MTU |
| 569 | * partial_bytes_acked = 0 |
| 570 | */ |
| 571 | transport->ssthresh = max(transport->cwnd/2, |
Vlad Yasevich | cf9b481 | 2010-04-30 22:41:10 -0400 | [diff] [blame] | 572 | 4*asoc->pathmtu); |
| 573 | transport->cwnd = asoc->pathmtu; |
Vlad Yasevich | 33ce828 | 2009-09-04 18:20:58 -0400 | [diff] [blame] | 574 | |
Vlad Yasevich | cf9b481 | 2010-04-30 22:41:10 -0400 | [diff] [blame] | 575 | /* T3-rtx also clears fast recovery */ |
| 576 | asoc->fast_recovery = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | break; |
| 578 | |
| 579 | case SCTP_LOWER_CWND_FAST_RTX: |
| 580 | /* RFC 2960 7.2.4 Adjust the ssthresh and cwnd of the |
| 581 | * destination address(es) to which the missing DATA chunks |
| 582 | * were last sent, according to the formula described in |
| 583 | * Section 7.2.3. |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 584 | * |
| 585 | * RFC 2960 7.2.3, sctpimpguide Upon detection of packet |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | * losses from SACK (see Section 7.2.4), An endpoint |
| 587 | * should do the following: |
| 588 | * ssthresh = max(cwnd/2, 4*MTU) |
| 589 | * cwnd = ssthresh |
| 590 | * partial_bytes_acked = 0 |
| 591 | */ |
Vlad Yasevich | cf9b481 | 2010-04-30 22:41:10 -0400 | [diff] [blame] | 592 | if (asoc->fast_recovery) |
Vlad Yasevich | a646523 | 2008-06-04 12:38:43 -0700 | [diff] [blame] | 593 | return; |
| 594 | |
| 595 | /* Mark Fast recovery */ |
Vlad Yasevich | cf9b481 | 2010-04-30 22:41:10 -0400 | [diff] [blame] | 596 | asoc->fast_recovery = 1; |
| 597 | asoc->fast_recovery_exit = asoc->next_tsn - 1; |
Vlad Yasevich | a646523 | 2008-06-04 12:38:43 -0700 | [diff] [blame] | 598 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | transport->ssthresh = max(transport->cwnd/2, |
Vlad Yasevich | cf9b481 | 2010-04-30 22:41:10 -0400 | [diff] [blame] | 600 | 4*asoc->pathmtu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | transport->cwnd = transport->ssthresh; |
| 602 | break; |
| 603 | |
| 604 | case SCTP_LOWER_CWND_ECNE: |
| 605 | /* RFC 2481 Section 6.1.2. |
| 606 | * If the sender receives an ECN-Echo ACK packet |
| 607 | * then the sender knows that congestion was encountered in the |
| 608 | * network on the path from the sender to the receiver. The |
| 609 | * indication of congestion should be treated just as a |
| 610 | * congestion loss in non-ECN Capable TCP. That is, the TCP |
| 611 | * source halves the congestion window "cwnd" and reduces the |
| 612 | * slow start threshold "ssthresh". |
| 613 | * A critical condition is that TCP does not react to |
| 614 | * congestion indications more than once every window of |
| 615 | * data (or more loosely more than once every round-trip time). |
| 616 | */ |
Wei Yongjun | f61f6f8 | 2009-03-02 09:46:13 +0000 | [diff] [blame] | 617 | if (time_after(jiffies, transport->last_time_ecne_reduced + |
| 618 | transport->rtt)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | transport->ssthresh = max(transport->cwnd/2, |
Vlad Yasevich | cf9b481 | 2010-04-30 22:41:10 -0400 | [diff] [blame] | 620 | 4*asoc->pathmtu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | transport->cwnd = transport->ssthresh; |
| 622 | transport->last_time_ecne_reduced = jiffies; |
| 623 | } |
| 624 | break; |
| 625 | |
| 626 | case SCTP_LOWER_CWND_INACTIVE: |
| 627 | /* RFC 2960 Section 7.2.1, sctpimpguide |
| 628 | * When the endpoint does not transmit data on a given |
| 629 | * transport address, the cwnd of the transport address |
| 630 | * should be adjusted to max(cwnd/2, 4*MTU) per RTO. |
| 631 | * NOTE: Although the draft recommends that this check needs |
| 632 | * to be done every RTO interval, we do it every hearbeat |
| 633 | * interval. |
| 634 | */ |
Vlad Yasevich | 245cba7 | 2009-11-23 15:53:58 -0500 | [diff] [blame] | 635 | transport->cwnd = max(transport->cwnd/2, |
Vlad Yasevich | cf9b481 | 2010-04-30 22:41:10 -0400 | [diff] [blame] | 636 | 4*asoc->pathmtu); |
Marcelo Ricardo Leitner | a02d036 | 2017-06-23 19:59:36 -0300 | [diff] [blame] | 637 | /* RFC 4960 Errata 3.27.2: also adjust sshthresh */ |
| 638 | transport->ssthresh = transport->cwnd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | break; |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 640 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | |
| 642 | transport->partial_bytes_acked = 0; |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 643 | |
| 644 | pr_debug("%s: transport:%p, reason:%d, cwnd:%d, ssthresh:%d\n", |
| 645 | __func__, transport, reason, transport->cwnd, |
| 646 | transport->ssthresh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | } |
| 648 | |
Vlad Yasevich | 46d5a80 | 2009-11-23 15:54:00 -0500 | [diff] [blame] | 649 | /* Apply Max.Burst limit to the congestion window: |
| 650 | * sctpimpguide-05 2.14.2 |
| 651 | * D) When the time comes for the sender to |
| 652 | * transmit new DATA chunks, the protocol parameter Max.Burst MUST |
| 653 | * first be applied to limit how many new DATA chunks may be sent. |
| 654 | * The limit is applied by adjusting cwnd as follows: |
| 655 | * if ((flightsize+ Max.Burst * MTU) < cwnd) |
| 656 | * cwnd = flightsize + Max.Burst * MTU |
| 657 | */ |
| 658 | |
| 659 | void sctp_transport_burst_limited(struct sctp_transport *t) |
| 660 | { |
| 661 | struct sctp_association *asoc = t->asoc; |
| 662 | u32 old_cwnd = t->cwnd; |
| 663 | u32 max_burst_bytes; |
| 664 | |
wangweidong | 78ac814 | 2013-12-04 17:32:39 +0800 | [diff] [blame] | 665 | if (t->burst_limited || asoc->max_burst == 0) |
Vlad Yasevich | 46d5a80 | 2009-11-23 15:54:00 -0500 | [diff] [blame] | 666 | return; |
| 667 | |
| 668 | max_burst_bytes = t->flight_size + (asoc->max_burst * asoc->pathmtu); |
| 669 | if (max_burst_bytes < old_cwnd) { |
| 670 | t->cwnd = max_burst_bytes; |
| 671 | t->burst_limited = old_cwnd; |
| 672 | } |
| 673 | } |
| 674 | |
| 675 | /* Restore the old cwnd congestion window, after the burst had it's |
| 676 | * desired effect. |
| 677 | */ |
| 678 | void sctp_transport_burst_reset(struct sctp_transport *t) |
| 679 | { |
| 680 | if (t->burst_limited) { |
| 681 | t->cwnd = t->burst_limited; |
| 682 | t->burst_limited = 0; |
| 683 | } |
| 684 | } |
| 685 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | /* What is the next timeout value for this transport? */ |
Daniel Borkmann | 8f61059 | 2014-06-30 13:52:08 +0200 | [diff] [blame] | 687 | unsigned long sctp_transport_timeout(struct sctp_transport *trans) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | { |
Daniel Borkmann | 8f61059 | 2014-06-30 13:52:08 +0200 | [diff] [blame] | 689 | /* RTO + timer slack +/- 50% of RTO */ |
Marcelo Ricardo Leitner | ba6f5e3 | 2016-04-06 15:15:19 -0300 | [diff] [blame] | 690 | unsigned long timeout = trans->rto >> 1; |
Daniel Borkmann | 8f61059 | 2014-06-30 13:52:08 +0200 | [diff] [blame] | 691 | |
| 692 | if (trans->state != SCTP_UNCONFIRMED && |
| 693 | trans->state != SCTP_PF) |
| 694 | timeout += trans->hbinterval; |
| 695 | |
Xin Long | 1d88ba1 | 2018-06-05 12:16:58 +0800 | [diff] [blame] | 696 | return max_t(unsigned long, timeout, HZ / 5); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | } |
Vlad Yasevich | 749bf92 | 2007-03-19 17:02:30 -0700 | [diff] [blame] | 698 | |
| 699 | /* Reset transport variables to their initial values */ |
| 700 | void sctp_transport_reset(struct sctp_transport *t) |
| 701 | { |
| 702 | struct sctp_association *asoc = t->asoc; |
| 703 | |
| 704 | /* RFC 2960 (bis), Section 5.2.4 |
| 705 | * All the congestion control parameters (e.g., cwnd, ssthresh) |
| 706 | * related to this peer MUST be reset to their initial values |
| 707 | * (see Section 6.2.1) |
| 708 | */ |
| 709 | t->cwnd = min(4*asoc->pathmtu, max_t(__u32, 2*asoc->pathmtu, 4380)); |
Vlad Yasevich | 46d5a80 | 2009-11-23 15:54:00 -0500 | [diff] [blame] | 710 | t->burst_limited = 0; |
Vlad Yasevich | 289f424 | 2007-03-22 12:26:25 -0700 | [diff] [blame] | 711 | t->ssthresh = asoc->peer.i.a_rwnd; |
Andrei Pelinescu-Onciul | 5fdd4ba | 2009-11-29 00:14:02 -0800 | [diff] [blame] | 712 | t->rto = asoc->rto_initial; |
Michele Baldessari | 196d675 | 2012-12-01 04:49:42 +0000 | [diff] [blame] | 713 | sctp_max_rto(asoc, t); |
Vlad Yasevich | 749bf92 | 2007-03-19 17:02:30 -0700 | [diff] [blame] | 714 | t->rtt = 0; |
| 715 | t->srtt = 0; |
| 716 | t->rttvar = 0; |
| 717 | |
Masahiro Yamada | b564d62 | 2017-02-27 14:29:06 -0800 | [diff] [blame] | 718 | /* Reset these additional variables so that we have a clean slate. */ |
Vlad Yasevich | 749bf92 | 2007-03-19 17:02:30 -0700 | [diff] [blame] | 719 | t->partial_bytes_acked = 0; |
| 720 | t->flight_size = 0; |
| 721 | t->error_count = 0; |
| 722 | t->rto_pending = 0; |
Vlad Yasevich | faee47c | 2009-02-13 08:33:43 +0000 | [diff] [blame] | 723 | t->hb_sent = 0; |
Vlad Yasevich | 749bf92 | 2007-03-19 17:02:30 -0700 | [diff] [blame] | 724 | |
| 725 | /* Initialize the state information for SFR-CACC */ |
| 726 | t->cacc.changeover_active = 0; |
| 727 | t->cacc.cycling_changeover = 0; |
| 728 | t->cacc.next_tsn_at_change = 0; |
| 729 | t->cacc.cacc_saw_newack = 0; |
| 730 | } |
Michio Honda | ddc4bbe | 2011-06-17 11:03:23 +0900 | [diff] [blame] | 731 | |
| 732 | /* Schedule retransmission on the given transport */ |
| 733 | void sctp_transport_immediate_rtx(struct sctp_transport *t) |
| 734 | { |
| 735 | /* Stop pending T3_rtx_timer */ |
Ying Xue | 25cc4ae | 2013-02-03 20:32:57 +0000 | [diff] [blame] | 736 | if (del_timer(&t->T3_rtx_timer)) |
Michio Honda | ddc4bbe | 2011-06-17 11:03:23 +0900 | [diff] [blame] | 737 | sctp_transport_put(t); |
Ying Xue | 25cc4ae | 2013-02-03 20:32:57 +0000 | [diff] [blame] | 738 | |
Michio Honda | ddc4bbe | 2011-06-17 11:03:23 +0900 | [diff] [blame] | 739 | sctp_retransmit(&t->asoc->outqueue, t, SCTP_RTXR_T3_RTX); |
| 740 | if (!timer_pending(&t->T3_rtx_timer)) { |
| 741 | if (!mod_timer(&t->T3_rtx_timer, jiffies + t->rto)) |
| 742 | sctp_transport_hold(t); |
| 743 | } |
Michio Honda | ddc4bbe | 2011-06-17 11:03:23 +0900 | [diff] [blame] | 744 | } |
Julian Anastasov | c86a773 | 2017-02-06 23:14:13 +0200 | [diff] [blame] | 745 | |
| 746 | /* Drop dst */ |
| 747 | void sctp_transport_dst_release(struct sctp_transport *t) |
| 748 | { |
| 749 | dst_release(t->dst); |
| 750 | t->dst = NULL; |
| 751 | t->dst_pending_confirm = 0; |
| 752 | } |
| 753 | |
| 754 | /* Schedule neighbour confirm */ |
| 755 | void sctp_transport_dst_confirm(struct sctp_transport *t) |
| 756 | { |
| 757 | t->dst_pending_confirm = 1; |
| 758 | } |