xref: /netbsd-src/sys/netinet/tcp_congctl.h (revision 4d4f2b7db1d0bfff95c4ce7c51a8ccff11d7eed5)
1*4d4f2b7dSkefren /*	$NetBSD: tcp_congctl.h,v 1.7 2013/11/12 09:02:05 kefren Exp $	*/
2f3330397Srpaulo 
3f3330397Srpaulo /*
4f3330397Srpaulo  * Copyright (c) 2006 The NetBSD Foundation, Inc.
5f3330397Srpaulo  * All rights reserved.
6f3330397Srpaulo  *
7f3330397Srpaulo  * This code is derived from software contributed to The NetBSD Foundation
8f3330397Srpaulo  * by Rui Paulo.
9f3330397Srpaulo  *
10f3330397Srpaulo  * Redistribution and use in source and binary forms, with or without
11f3330397Srpaulo  * modification, are permitted provided that the following conditions
12f3330397Srpaulo  * are met:
13f3330397Srpaulo  * 1. Redistributions of source code must retain the above copyright
14f3330397Srpaulo  *    notice, this list of conditions and the following disclaimer.
15f3330397Srpaulo  * 2. Redistributions in binary form must reproduce the above copyright
16f3330397Srpaulo  *    notice, this list of conditions and the following disclaimer in the
17f3330397Srpaulo  *    documentation and/or other materials provided with the distribution.
18f3330397Srpaulo  *
19f3330397Srpaulo  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20f3330397Srpaulo  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21f3330397Srpaulo  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22f3330397Srpaulo  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23f3330397Srpaulo  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24f3330397Srpaulo  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25f3330397Srpaulo  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26f3330397Srpaulo  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27f3330397Srpaulo  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28f3330397Srpaulo  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29f3330397Srpaulo  * POSSIBILITY OF SUCH DAMAGE.
30f3330397Srpaulo  */
31f3330397Srpaulo 
32f3330397Srpaulo #ifndef _NETINET_TCP_CONGCTL_H
33f3330397Srpaulo #define _NETINET_TCP_CONGCTL_H
34f3330397Srpaulo 
35a34217b8Smatt #define TCPCC_MAXLEN 12
36a34217b8Smatt 
37a34217b8Smatt struct tcp_congctlent {
38a34217b8Smatt 	TAILQ_ENTRY(tcp_congctlent) congctl_ent;
39a34217b8Smatt 	const struct tcp_congctl *congctl_ctl;
40a34217b8Smatt 	unsigned int congctl_refcnt;
41a34217b8Smatt 	char congctl_name[TCPCC_MAXLEN];
42a34217b8Smatt };
43f3330397Srpaulo /*
44f3330397Srpaulo  * Congestion control function table.
45f3330397Srpaulo  */
46f3330397Srpaulo struct tcp_congctl {
4741529ab2Syamt 	/*
4841529ab2Syamt 	 * fast_retransmit: called on tcprexmtthresh'th dup ACKs.
4941529ab2Syamt 	 * this actually retransmits packets by calling tcp_output()
5041529ab2Syamt 	 * if appropriate.
5141529ab2Syamt 	 * returns 0 if entering fast recovery.  otherwise returns non-0.
5241529ab2Syamt 	 */
537253aad9Syamt 	int  (*fast_retransmit)(struct tcpcb *, const struct tcphdr *);
5441529ab2Syamt 
5541529ab2Syamt 	/*
5641529ab2Syamt 	 * slow_retransmit: called on RTO to adjust parameters like cwnd.
5741529ab2Syamt 	 */
58f3330397Srpaulo 	void (*slow_retransmit)(struct tcpcb *);
5941529ab2Syamt 
6041529ab2Syamt 	/*
6141529ab2Syamt 	 * fast_retransmit_newack: called when new data is acked.
6241529ab2Syamt 	 * ie. when advancing SND.UNA
6341529ab2Syamt 	 * not called if TCP_SACK_ENABLED.
6441529ab2Syamt 	 */
657253aad9Syamt 	void (*fast_retransmit_newack)(struct tcpcb *, const struct tcphdr *);
6641529ab2Syamt 
6741529ab2Syamt 	/*
6841529ab2Syamt 	 * newack: called when new data is acked.  ie. when advancing SND.UNA
6941529ab2Syamt 	 * it's called before updating tp->snd_una.
7041529ab2Syamt 	 */
717253aad9Syamt 	void (*newack)(struct tcpcb *, const struct tcphdr *);
7241529ab2Syamt 
7341529ab2Syamt 	/*
7441529ab2Syamt 	 * cong_exp: called when congestion is detected.  eg. by ECN
7541529ab2Syamt 	 */
76a70594d3Srpaulo 	void (*cong_exp)(struct tcpcb *);
77f3330397Srpaulo };
78f3330397Srpaulo 
79a34217b8Smatt extern const struct tcp_congctl tcp_reno_ctl;
80a34217b8Smatt extern const struct tcp_congctl tcp_newreno_ctl;
81*4d4f2b7dSkefren extern const struct tcp_congctl tcp_cubic_ctl;
82f3330397Srpaulo 
83f3330397Srpaulo /* currently selected global congestion control */
84a34217b8Smatt extern char tcp_congctl_global_name[TCPCC_MAXLEN];
85f3330397Srpaulo 
86f3330397Srpaulo /* available global congestion control algorithms */
87a34217b8Smatt extern char tcp_congctl_avail[10 * TCPCC_MAXLEN];
88f3330397Srpaulo 
89f3330397Srpaulo void   tcp_congctl_init(void);
90a34217b8Smatt int    tcp_congctl_register(const char *, const struct tcp_congctl *);
91f3330397Srpaulo int    tcp_congctl_unregister(const char *);
92f3330397Srpaulo int    tcp_congctl_select(struct tcpcb *, const char *);
93a34217b8Smatt void   tcp_congctl_release(struct tcpcb *);
94f3330397Srpaulo const char *
95f3330397Srpaulo        tcp_congctl_bystruct(const struct tcp_congctl *);
96f3330397Srpaulo 
97f3330397Srpaulo #endif /* _NETINET_TCP_CONGCTL_H */
98