transport.c 15.7 KB
Newer Older
Jon Grimm's avatar
Jon Grimm committed
1 2 3 4 5 6
/* SCTP kernel reference Implementation
 * Copyright (c) 1999-2000 Cisco, Inc.
 * Copyright (c) 1999-2001 Motorola, Inc.
 * Copyright (c) 2001 International Business Machines Corp.
 * Copyright (c) 2001 Intel Corp.
 * Copyright (c) 2001 La Monte H.P. Yarroll
Jon Grimm's avatar
Jon Grimm committed
7
 *
Jon Grimm's avatar
Jon Grimm committed
8
 * This file is part of the SCTP kernel reference Implementation
Jon Grimm's avatar
Jon Grimm committed
9
 *
Jon Grimm's avatar
Jon Grimm committed
10
 * This module provides the abstraction for an SCTP tranport representing
Jon Grimm's avatar
Jon Grimm committed
11
 * a remote transport address.  For local transport addresses, we just use
Jon Grimm's avatar
Jon Grimm committed
12
 * union sctp_addr.
Jon Grimm's avatar
Jon Grimm committed
13
 *
Jon Grimm's avatar
Jon Grimm committed
14 15
 * The SCTP reference implementation is free software;
 * you can redistribute it and/or modify it under the terms of
Jon Grimm's avatar
Jon Grimm committed
16 17 18
 * the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
Jon Grimm's avatar
Jon Grimm committed
19 20
 *
 * The SCTP reference implementation is distributed in the hope that it
Jon Grimm's avatar
Jon Grimm committed
21 22 23 24
 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
 *                 ************************
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
Jon Grimm's avatar
Jon Grimm committed
25
 *
Jon Grimm's avatar
Jon Grimm committed
26 27 28
 * You should have received a copy of the GNU General Public License
 * along with GNU CC; see the file COPYING.  If not, write to
 * the Free Software Foundation, 59 Temple Place - Suite 330,
Jon Grimm's avatar
Jon Grimm committed
29 30
 * Boston, MA 02111-1307, USA.
 *
Jon Grimm's avatar
Jon Grimm committed
31 32 33
 * Please send any bug reports or fixes you make to the
 * email address(es):
 *    lksctp developers <lksctp-developers@lists.sourceforge.net>
Jon Grimm's avatar
Jon Grimm committed
34
 *
Jon Grimm's avatar
Jon Grimm committed
35 36 37
 * Or submit a bug report through the following website:
 *    http://www.sf.net/projects/lksctp
 *
Jon Grimm's avatar
Jon Grimm committed
38
 * Written or modified by:
Jon Grimm's avatar
Jon Grimm committed
39 40 41 42 43 44
 *    La Monte H.P. Yarroll <piggy@acm.org>
 *    Karl Knutson          <karl@athena.chicago.il.us>
 *    Jon Grimm             <jgrimm@us.ibm.com>
 *    Xingang Guo           <xingang.guo@intel.com>
 *    Hui Huang             <hui.huang@nokia.com>
 *    Sridhar Samudrala	    <sri@us.ibm.com>
Jon Grimm's avatar
Jon Grimm committed
45
 *
Jon Grimm's avatar
Jon Grimm committed
46 47 48 49 50 51 52
 * Any bugs reported given to us we will try to fix... any fixes shared will
 * be incorporated into the next SCTP release.
 */

#include <linux/types.h>
#include <net/sctp/sctp.h>

53
/* 1st Level Abstractions.  */
Jon Grimm's avatar
Jon Grimm committed
54

55
/* Allocate and initialize a new transport.  */
Jon Grimm's avatar
Jon Grimm committed
56
sctp_transport_t *sctp_transport_new(const union sctp_addr *addr, int priority)
Jon Grimm's avatar
Jon Grimm committed
57 58 59 60
{
        sctp_transport_t *transport;

        transport = t_new(sctp_transport_t, priority);
61
	if (!transport)
Jon Grimm's avatar
Jon Grimm committed
62 63
		goto fail;

64
	if (!sctp_transport_init(transport, addr, priority))
Jon Grimm's avatar
Jon Grimm committed
65 66 67 68 69 70
		goto fail_init;

	transport->malloced = 1;
	SCTP_DBG_OBJCNT_INC(transport);

	return transport;
71

Jon Grimm's avatar
Jon Grimm committed
72 73
fail_init:
	kfree(transport);
74

Jon Grimm's avatar
Jon Grimm committed
75 76
fail:
	return NULL;
77
}
Jon Grimm's avatar
Jon Grimm committed
78

79 80
/* Intialize a new transport from provided memory.  */
sctp_transport_t *sctp_transport_init(sctp_transport_t *peer,
Jon Grimm's avatar
Jon Grimm committed
81
				      const union sctp_addr *addr,
82
				      int priority)
Jon Grimm's avatar
Jon Grimm committed
83
{
84
	sctp_protocol_t *proto = sctp_get_protocol();
Jon Grimm's avatar
Jon Grimm committed
85

86
	/* Copy in the address.  */
Jon Grimm's avatar
Jon Grimm committed
87
	peer->ipaddr = *addr;
Jon Grimm's avatar
Jon Grimm committed
88
	peer->af_specific = sctp_get_af_specific(addr->sa.sa_family);
89
	peer->asoc = NULL;
Jon Grimm's avatar
Jon Grimm committed
90

91 92
	/* From 6.3.1 RTO Calculation:
	 *
Jon Grimm's avatar
Jon Grimm committed
93 94 95
	 * C1) Until an RTT measurement has been made for a packet sent to the
	 * given destination transport address, set RTO to the protocol
	 * parameter 'RTO.Initial'.
96
	 */
Jon Grimm's avatar
Jon Grimm committed
97 98 99 100 101 102 103 104 105
	peer->rtt = 0;
	peer->rto = proto->rto_initial;
	peer->rttvar = 0;
	peer->srtt = 0;
	peer->rto_pending = 0;

	peer->last_time_heard = jiffies;
	peer->last_time_used = jiffies;
	peer->last_time_ecne_reduced = jiffies;
106

107 108
	peer->active = 1;
	peer->hb_allowed = 0;
109 110

	/* Initialize the default path max_retrans.  */
Jon Grimm's avatar
Jon Grimm committed
111 112
	peer->max_retrans = proto->max_retrans_path;
	peer->error_threshold = 0;
113 114 115
	peer->error_count = 0;

	peer->debug_name = "unnamedtransport";
Jon Grimm's avatar
Jon Grimm committed
116 117 118 119 120 121 122 123 124 125

	INIT_LIST_HEAD(&peer->transmitted);
	INIT_LIST_HEAD(&peer->send_ready);
	INIT_LIST_HEAD(&peer->transports);

	/* Set up the retransmission timer.  */
	init_timer(&peer->T3_rtx_timer);
	peer->T3_rtx_timer.function = sctp_generate_t3_rtx_event;
	peer->T3_rtx_timer.data = (unsigned long)peer;

126 127 128 129 130
	/* Set up the heartbeat timer. */
	init_timer(&peer->hb_timer);
	peer->hb_interval = SCTP_DEFAULT_TIMEOUT_HEARTBEAT;
	peer->hb_timer.function = sctp_generate_heartbeat_event;
	peer->hb_timer.data = (unsigned long)peer;
Jon Grimm's avatar
Jon Grimm committed
131

132
	atomic_set(&peer->refcnt, 1);
Jon Grimm's avatar
Jon Grimm committed
133 134 135
	peer->dead = 0;

	peer->malloced = 0;
136 137
	return peer;
}
Jon Grimm's avatar
Jon Grimm committed
138 139

/* This transport is no longer needed.  Free up if possible, or
140
 * delay until it last reference count.
Jon Grimm's avatar
Jon Grimm committed
141
 */
142
void sctp_transport_free(sctp_transport_t *transport)
Jon Grimm's avatar
Jon Grimm committed
143 144 145
{
	transport->dead = 1;

146 147
	/* Try to delete the heartbeat timer.  */
	if (del_timer(&transport->hb_timer))
Jon Grimm's avatar
Jon Grimm committed
148 149
		sctp_transport_put(transport);

150 151
	sctp_transport_put(transport);
}
Jon Grimm's avatar
Jon Grimm committed
152

153 154 155 156
/* Destroy the transport data structure.
 * Assumes there are no more users of this structure.
 */
void sctp_transport_destroy(sctp_transport_t *transport)
Jon Grimm's avatar
Jon Grimm committed
157 158 159
{
	SCTP_ASSERT(transport->dead, "Transport is not dead", return);

160
	if (transport->asoc)
Jon Grimm's avatar
Jon Grimm committed
161 162
		sctp_association_put(transport->asoc);

163
	dst_release(transport->dst);
Jon Grimm's avatar
Jon Grimm committed
164 165
	kfree(transport);
	SCTP_DBG_OBJCNT_DEC(transport);
166
}
Jon Grimm's avatar
Jon Grimm committed
167

168 169 170 171
/* Start T3_rtx timer if it is not already running and update the heartbeat
 * timer.  This routine is called everytime a DATA chunk is sent.
 */
void sctp_transport_reset_timers(sctp_transport_t *transport)
Jon Grimm's avatar
Jon Grimm committed
172 173 174
{
	/* RFC 2960 6.3.2 Retransmission Timer Rules
	 *
175 176
	 * R1) Every time a DATA chunk is sent to any address(including a
	 * retransmission), if the T3-rtx timer of that address is not running
Jon Grimm's avatar
Jon Grimm committed
177 178 179 180 181
	 * start it running so that it will expire after the RTO of that
	 * address.
	 */
	if (!timer_pending(&transport->T3_rtx_timer)) {
		if (!mod_timer(&transport->T3_rtx_timer,
182
			       jiffies + transport->rto))
Jon Grimm's avatar
Jon Grimm committed
183 184 185
			sctp_transport_hold(transport);
	}

186 187 188
	/* When a data chunk is sent, reset the heartbeat interval.  */
	if (!mod_timer(&transport->hb_timer,
		       transport->hb_interval + transport->rto + jiffies))
Jon Grimm's avatar
Jon Grimm committed
189
		sctp_transport_hold(transport);
190
}
Jon Grimm's avatar
Jon Grimm committed
191

192 193 194
/* This transport has been assigned to an association.
 * Initialize fields from the association or from the sock itself.
 * Register the reference count in the association.
Jon Grimm's avatar
Jon Grimm committed
195
 */
196
void sctp_transport_set_owner(sctp_transport_t *transport,
Jon Grimm's avatar
Jon Grimm committed
197 198 199 200
			      sctp_association_t *asoc)
{
	transport->asoc = asoc;
	sctp_association_hold(asoc);
201
}
Jon Grimm's avatar
Jon Grimm committed
202

203 204 205 206
/* Caches the dst entry for a transport's destination address and an optional
 * souce address.
 */ 
void sctp_transport_route(sctp_transport_t *transport,
Jon Grimm's avatar
Jon Grimm committed
207
			  union sctp_addr *saddr)
208 209 210
{
	sctp_association_t *asoc = transport->asoc;
	sctp_func_t *af = transport->af_specific;
Jon Grimm's avatar
Jon Grimm committed
211
	union sctp_addr *daddr = &transport->ipaddr;
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
	sctp_bind_addr_t *bp;
	rwlock_t *addr_lock;
	struct sockaddr_storage_list *laddr;
	struct list_head *pos;
	struct dst_entry *dst;

	dst = af->get_dst(daddr, saddr);

	/* If there is no association or if a source address is passed,
	 * no more validation is required.
	 */
	if (!asoc || saddr)
		goto out;

	if (SCTP_STATE_ESTABLISHED == asoc->state) {
		bp = &asoc->base.bind_addr;
		addr_lock = &asoc->base.addr_lock;
	} else {
		bp = &asoc->ep->base.bind_addr;
		addr_lock = &asoc->ep->base.addr_lock;
	}

	if (dst) {
		/* Walk through the bind address list and look for a bind
		 * address that matches the source address of the returned dst.
		 */
		sctp_read_lock(addr_lock);
		list_for_each(pos, &bp->address_list) {
			laddr = list_entry(pos, struct sockaddr_storage_list,
					   list);
			if (af->cmp_saddr(dst, &laddr->a))
				goto out_unlock;
		}
		sctp_read_unlock(addr_lock);
	
		/* None of the bound addresses match the source address of the
		 * dst. So release it.
		 */	
		dst_release(dst);
	}

	/* Walk through the bind address list and try to get a dst that
	 * matches a bind address as the source address.
	 */
	sctp_read_lock(addr_lock);
	list_for_each(pos, &bp->address_list) {
		laddr = list_entry(pos, struct sockaddr_storage_list, list);

		dst = af->get_dst(daddr, &laddr->a);
		if (dst)
			goto out_unlock;
	}

out_unlock:
	sctp_read_unlock(addr_lock);
out:
	transport->dst = dst;
	if (dst)
270
		transport->pmtu = dst_pmtu(dst);
271 272 273 274
	else
		transport->pmtu = SCTP_DEFAULT_MAXSEGMENT;
}

275
/* Hold a reference to a transport.  */
Jon Grimm's avatar
Jon Grimm committed
276 277 278
void sctp_transport_hold(sctp_transport_t *transport)
{
	atomic_inc(&transport->refcnt);
279
}
Jon Grimm's avatar
Jon Grimm committed
280 281

/* Release a reference to a transport and clean up
282
 * if there are no more references.
Jon Grimm's avatar
Jon Grimm committed
283 284 285
 */
void sctp_transport_put(sctp_transport_t *transport)
{
286
	if (atomic_dec_and_test(&transport->refcnt))
Jon Grimm's avatar
Jon Grimm committed
287
		sctp_transport_destroy(transport);
288
}
Jon Grimm's avatar
Jon Grimm committed
289

Jon Grimm's avatar
Jon Grimm committed
290
/* Update transport's RTO based on the newly calculated RTT. */
291
void sctp_transport_update_rto(sctp_transport_t *tp, __u32 rtt)
Jon Grimm's avatar
Jon Grimm committed
292 293 294
{
	sctp_protocol_t *proto = sctp_get_protocol();

295
	/* Check for valid transport.  */
Jon Grimm's avatar
Jon Grimm committed
296 297
	SCTP_ASSERT(tp, "NULL transport", return);

298
	/* We should not be doing any RTO updates unless rto_pending is set.  */
Jon Grimm's avatar
Jon Grimm committed
299 300 301 302
	SCTP_ASSERT(tp->rto_pending, "rto_pending not set", return);

	if (tp->rttvar || tp->srtt) {
		/* 6.3.1 C3) When a new RTT measurement R' is made, set
303
		 * RTTVAR <- (1 - RTO.Beta) * RTTVAR + RTO.Beta * |SRTT - R'|
Jon Grimm's avatar
Jon Grimm committed
304 305 306
		 * SRTT <- (1 - RTO.Alpha) * SRTT + RTO.Alpha * R'
		 */

307
		/* Note:  The above algorithm has been rewritten to
Jon Grimm's avatar
Jon Grimm committed
308
		 * express rto_beta and rto_alpha as inverse powers
309
		 * of two.
Jon Grimm's avatar
Jon Grimm committed
310
		 * For example, assuming the default value of RTO.Alpha of
311
		 * 1/8, rto_alpha would be expressed as 3.
Jon Grimm's avatar
Jon Grimm committed
312
		 */
313
		tp->rttvar = tp->rttvar - (tp->rttvar >> proto->rto_beta)
Jon Grimm's avatar
Jon Grimm committed
314
			+ ((abs(tp->srtt - rtt)) >> proto->rto_beta);
315
		tp->srtt = tp->srtt - (tp->srtt >> proto->rto_alpha)
Jon Grimm's avatar
Jon Grimm committed
316 317
			+ (rtt >> proto->rto_alpha);
	} else {
318
		/* 6.3.1 C2) When the first RTT measurement R is made, set
Jon Grimm's avatar
Jon Grimm committed
319 320 321 322 323 324
		 * SRTT <- R, RTTVAR <- R/2.
		 */
		tp->srtt = rtt;
		tp->rttvar = rtt >> 1;
	}

325
	/* 6.3.1 G1) Whenever RTTVAR is computed, if RTTVAR = 0, then
Jon Grimm's avatar
Jon Grimm committed
326 327
	 * adjust RTTVAR <- G, where G is the CLOCK GRANULARITY.
	 */
328
	if (tp->rttvar == 0)
Jon Grimm's avatar
Jon Grimm committed
329 330
		tp->rttvar = SCTP_CLOCK_GRANULARITY;

331
	/* 6.3.1 C3) After the computation, update RTO <- SRTT + 4 * RTTVAR.  */
Jon Grimm's avatar
Jon Grimm committed
332 333
	tp->rto = tp->srtt + (tp->rttvar << 2);

334 335
	/* 6.3.1 C6) Whenever RTO is computed, if it is less than RTO.Min
	 * seconds then it is rounded up to RTO.Min seconds.
Jon Grimm's avatar
Jon Grimm committed
336
	 */
337
	if (tp->rto < tp->asoc->rto_min)
Jon Grimm's avatar
Jon Grimm committed
338
		tp->rto = tp->asoc->rto_min;
Jon Grimm's avatar
Jon Grimm committed
339

340
	/* 6.3.1 C7) A maximum value may be placed on RTO provided it is
Jon Grimm's avatar
Jon Grimm committed
341 342
	 * at least RTO.max seconds.
	 */
343
	if (tp->rto > tp->asoc->rto_max)
Jon Grimm's avatar
Jon Grimm committed
344 345 346 347
		tp->rto = tp->asoc->rto_max;

	tp->rtt = rtt;

348
	/* Reset rto_pending so that a new RTT measurement is started when a
Jon Grimm's avatar
Jon Grimm committed
349 350 351 352
	 * new data chunk is sent.
	 */
	tp->rto_pending = 0;

353 354
	SCTP_DEBUG_PRINTK("%s: transport: %p, rtt: %d, srtt: %d "
			  "rttvar: %d, rto: %d\n", __FUNCTION__,
Jon Grimm's avatar
Jon Grimm committed
355
			  tp, rtt, tp->srtt, tp->rttvar, tp->rto);
356
}
Jon Grimm's avatar
Jon Grimm committed
357

358
/* This routine updates the transport's cwnd and partial_bytes_acked
Jon Grimm's avatar
Jon Grimm committed
359
 * parameters based on the bytes acked in the received SACK.
360 361 362
 */
void sctp_transport_raise_cwnd(sctp_transport_t *transport, __u32 sack_ctsn,
			       __u32 bytes_acked)
Jon Grimm's avatar
Jon Grimm committed
363
{
364
	__u32 cwnd, ssthresh, flight_size, pba, pmtu;
Jon Grimm's avatar
Jon Grimm committed
365 366 367 368

	cwnd = transport->cwnd;
	flight_size = transport->flight_size;

369 370 371
	/* The appropriate cwnd increase algorithm is performed if, and only
	 * if the cumulative TSN has advanced and the congestion window is
	 * being fully utilized.
Jon Grimm's avatar
Jon Grimm committed
372
	 */
373 374
	if ((transport->asoc->ctsn_ack_point >= sack_ctsn) ||
	    (flight_size < cwnd))
Jon Grimm's avatar
Jon Grimm committed
375 376 377 378 379 380 381
		return;

	ssthresh = transport->ssthresh;
	pba = transport->partial_bytes_acked;
	pmtu = transport->asoc->pmtu;

	if (cwnd <= ssthresh) {
382 383 384 385 386
		/* RFC 2960 7.2.1, sctpimpguide-05 2.14.2 When cwnd is less
		 * than or equal to ssthresh an SCTP endpoint MUST use the
		 * slow start algorithm to increase cwnd only if the current
		 * congestion window is being fully utilized and an incoming
		 * SACK advances the Cumulative TSN Ack Point. Only when these
Jon Grimm's avatar
Jon Grimm committed
387
		 * two conditions are met can the cwnd be increased otherwise
388 389 390 391
		 * the cwnd MUST not be increased. If these conditions are met
		 * then cwnd MUST be increased by at most the lesser of
		 * 1) the total size of the previously outstanding DATA chunk(s)
		 * acknowledged, and 2) the destination's path MTU.
Jon Grimm's avatar
Jon Grimm committed
392
		 */
393
		if (bytes_acked > pmtu)
Jon Grimm's avatar
Jon Grimm committed
394
			cwnd += pmtu;
395
		else
Jon Grimm's avatar
Jon Grimm committed
396
			cwnd += bytes_acked;
397
		SCTP_DEBUG_PRINTK("%s: SLOW START: transport: %p, "
398 399
				  "bytes_acked: %d, cwnd: %d, ssthresh: %d, "
				  "flight_size: %d, pba: %d\n",
400
				  __FUNCTION__,
401
				  transport, bytes_acked, cwnd,
Jon Grimm's avatar
Jon Grimm committed
402 403
				  ssthresh, flight_size, pba);
	} else {
404 405 406 407 408
		/* RFC 2960 7.2.2 Whenever cwnd is greater than ssthresh, upon
		 * each SACK arrival that advances the Cumulative TSN Ack Point,
		 * increase partial_bytes_acked by the total number of bytes of
		 * all new chunks acknowledged in that SACK including chunks
		 * acknowledged by the new Cumulative TSN Ack and by Gap Ack
Jon Grimm's avatar
Jon Grimm committed
409
		 * Blocks.
410
		 *
Jon Grimm's avatar
Jon Grimm committed
411
		 * When partial_bytes_acked is equal to or greater than cwnd and
412 413 414 415
		 * before the arrival of the SACK the sender had cwnd or more
		 * bytes of data outstanding (i.e., before arrival of the SACK,
		 * flightsize was greater than or equal to cwnd), increase cwnd
		 * by MTU, and reset partial_bytes_acked to
Jon Grimm's avatar
Jon Grimm committed
416 417 418 419 420 421 422
		 * (partial_bytes_acked - cwnd).
		 */
		pba += bytes_acked;
		if (pba >= cwnd) {
			cwnd += pmtu;
			pba = ((cwnd < pba) ? (pba - cwnd) : 0);
		}
423
		SCTP_DEBUG_PRINTK("%s: CONGESTION AVOIDANCE: "
Jon Grimm's avatar
Jon Grimm committed
424
				  "transport: %p, bytes_acked: %d, cwnd: %d, "
425
				  "ssthresh: %d, flight_size: %d, pba: %d\n",
426
				  __FUNCTION__,
427
				  transport, bytes_acked, cwnd,
Jon Grimm's avatar
Jon Grimm committed
428 429 430 431 432
				  ssthresh, flight_size, pba);
	}

	transport->cwnd = cwnd;
	transport->partial_bytes_acked = pba;
433
}
Jon Grimm's avatar
Jon Grimm committed
434

435 436
/* This routine is used to lower the transport's cwnd when congestion is
 * detected.
Jon Grimm's avatar
Jon Grimm committed
437
 */
438 439 440 441
void sctp_transport_lower_cwnd(sctp_transport_t *transport,
			       sctp_lower_cwnd_t reason)
{
	switch (reason) {
Jon Grimm's avatar
Jon Grimm committed
442
	case SCTP_LOWER_CWND_T3_RTX:
443 444
		/* RFC 2960 Section 7.2.3, sctpimpguide-05 Section 2.9.2
		 * When the T3-rtx timer expires on an address, SCTP should
Jon Grimm's avatar
Jon Grimm committed
445
		 * perform slow start by:
446 447 448 449 450
		 *      ssthresh = max(cwnd/2, 2*MTU)
		 *      cwnd = 1*MTU
		 *      partial_bytes_acked = 0
		 */
		transport->ssthresh = max(transport->cwnd/2,
Jon Grimm's avatar
Jon Grimm committed
451 452 453
					  2*transport->asoc->pmtu);
		transport->cwnd = transport->asoc->pmtu;
		break;
454

Jon Grimm's avatar
Jon Grimm committed
455
	case SCTP_LOWER_CWND_FAST_RTX:
Jon Grimm's avatar
Jon Grimm committed
456 457 458
		/* RFC 2960 7.2.4 Adjust the ssthresh and cwnd of the
		 * destination address(es) to which the missing DATA chunks
		 * were last sent, according to the formula described in
Jon Grimm's avatar
Jon Grimm committed
459 460
		 * Section 7.2.3.
	 	 *
Jon Grimm's avatar
Jon Grimm committed
461 462
	 	 * RFC 2960 7.2.3, sctpimpguide-05 2.9.2 Upon detection of
		 * packet losses from SACK (see Section 7.2.4), An endpoint
Jon Grimm's avatar
Jon Grimm committed
463
		 * should do the following:
464 465
		 *      ssthresh = max(cwnd/2, 2*MTU)
		 *      cwnd = ssthresh
Jon Grimm's avatar
Jon Grimm committed
466
		 *      partial_bytes_acked = 0
467 468
		 */
		transport->ssthresh = max(transport->cwnd/2,
Jon Grimm's avatar
Jon Grimm committed
469 470 471
					  2*transport->asoc->pmtu);
		transport->cwnd = transport->ssthresh;
		break;
472

Jon Grimm's avatar
Jon Grimm committed
473
	case SCTP_LOWER_CWND_ECNE:
474
		/* RFC 2481 Section 6.1.2.
Jon Grimm's avatar
Jon Grimm committed
475 476 477
		 * If the sender receives an ECN-Echo ACK packet
		 * then the sender knows that congestion was encountered in the
		 * network on the path from the sender to the receiver. The
478 479
		 * indication of congestion should be treated just as a
		 * congestion loss in non-ECN Capable TCP. That is, the TCP
Jon Grimm's avatar
Jon Grimm committed
480 481
		 * source halves the congestion window "cwnd" and reduces the
		 * slow start threshold "ssthresh".
482 483
		 * A critical condition is that TCP does not react to
		 * congestion indications more than once every window of
Jon Grimm's avatar
Jon Grimm committed
484 485
		 * data (or more loosely more than once every round-trip time).
		 */
486 487 488
		if ((jiffies - transport->last_time_ecne_reduced) >
		    transport->rtt) {
			transport->ssthresh = max(transport->cwnd/2,
Jon Grimm's avatar
Jon Grimm committed
489 490 491 492 493
					  	  2*transport->asoc->pmtu);
			transport->cwnd = transport->ssthresh;
			transport->last_time_ecne_reduced = jiffies;
		}
		break;
494

Jon Grimm's avatar
Jon Grimm committed
495
	case SCTP_LOWER_CWND_INACTIVE:
496 497 498 499 500 501 502
		/* RFC 2960 Section 7.2.1, sctpimpguide-05 Section 2.14.2
		 * When the association does not transmit data on a given
		 * transport address within an RTO, the cwnd of the transport
		 * address should be adjusted to 2*MTU.
		 * NOTE: Although the draft recommends that this check needs
		 * to be done every RTO interval, we do it every hearbeat
		 * interval.
Jon Grimm's avatar
Jon Grimm committed
503
		 */
504
		if ((jiffies - transport->last_time_used) > transport->rto)
Jon Grimm's avatar
Jon Grimm committed
505 506
			transport->cwnd = 2*transport->asoc->pmtu;
		break;
507
	};
Jon Grimm's avatar
Jon Grimm committed
508 509

	transport->partial_bytes_acked = 0;
510 511 512
	SCTP_DEBUG_PRINTK("%s: transport: %p reason: %d cwnd: "
			  "%d ssthresh: %d\n", __FUNCTION__,
			  transport, reason,
Jon Grimm's avatar
Jon Grimm committed
513
			  transport->cwnd, transport->ssthresh);
514
}