xref: /freebsd/sys/netinet/cc/cc.h (revision adc56f5a383771f594829b7db9c263b6f0dcf1bd)
14644fda3SGleb Smirnoff /*-
24644fda3SGleb Smirnoff  * Copyright (c) 2007-2008
34644fda3SGleb Smirnoff  * 	Swinburne University of Technology, Melbourne, Australia.
44644fda3SGleb Smirnoff  * Copyright (c) 2009-2010 Lawrence Stewart <lstewart@freebsd.org>
54644fda3SGleb Smirnoff  * Copyright (c) 2010 The FreeBSD Foundation
64644fda3SGleb Smirnoff  * All rights reserved.
74644fda3SGleb Smirnoff  *
84644fda3SGleb Smirnoff  * This software was developed at the Centre for Advanced Internet
94644fda3SGleb Smirnoff  * Architectures, Swinburne University of Technology, by Lawrence Stewart and
104644fda3SGleb Smirnoff  * James Healy, made possible in part by a grant from the Cisco University
114644fda3SGleb Smirnoff  * Research Program Fund at Community Foundation Silicon Valley.
124644fda3SGleb Smirnoff  *
134644fda3SGleb Smirnoff  * Portions of this software were developed at the Centre for Advanced
144644fda3SGleb Smirnoff  * Internet Architectures, Swinburne University of Technology, Melbourne,
154644fda3SGleb Smirnoff  * Australia by David Hayes under sponsorship from the FreeBSD Foundation.
164644fda3SGleb Smirnoff  *
174644fda3SGleb Smirnoff  * Redistribution and use in source and binary forms, with or without
184644fda3SGleb Smirnoff  * modification, are permitted provided that the following conditions
194644fda3SGleb Smirnoff  * are met:
204644fda3SGleb Smirnoff  * 1. Redistributions of source code must retain the above copyright
214644fda3SGleb Smirnoff  *    notice, this list of conditions and the following disclaimer.
224644fda3SGleb Smirnoff  * 2. Redistributions in binary form must reproduce the above copyright
234644fda3SGleb Smirnoff  *    notice, this list of conditions and the following disclaimer in the
244644fda3SGleb Smirnoff  *    documentation and/or other materials provided with the distribution.
254644fda3SGleb Smirnoff  *
264644fda3SGleb Smirnoff  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
274644fda3SGleb Smirnoff  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
284644fda3SGleb Smirnoff  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
294644fda3SGleb Smirnoff  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
304644fda3SGleb Smirnoff  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
314644fda3SGleb Smirnoff  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
324644fda3SGleb Smirnoff  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
334644fda3SGleb Smirnoff  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
344644fda3SGleb Smirnoff  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
354644fda3SGleb Smirnoff  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
364644fda3SGleb Smirnoff  * SUCH DAMAGE.
374644fda3SGleb Smirnoff  *
384644fda3SGleb Smirnoff  * $FreeBSD$
394644fda3SGleb Smirnoff  */
404644fda3SGleb Smirnoff 
414644fda3SGleb Smirnoff /*
424644fda3SGleb Smirnoff  * This software was first released in 2007 by James Healy and Lawrence Stewart
434644fda3SGleb Smirnoff  * whilst working on the NewTCP research project at Swinburne University of
444644fda3SGleb Smirnoff  * Technology's Centre for Advanced Internet Architectures, Melbourne,
454644fda3SGleb Smirnoff  * Australia, which was made possible in part by a grant from the Cisco
464644fda3SGleb Smirnoff  * University Research Program Fund at Community Foundation Silicon Valley.
474644fda3SGleb Smirnoff  * More details are available at:
484644fda3SGleb Smirnoff  *   http://caia.swin.edu.au/urp/newtcp/
494644fda3SGleb Smirnoff  */
504644fda3SGleb Smirnoff 
514644fda3SGleb Smirnoff #ifndef _NETINET_CC_CC_H_
524644fda3SGleb Smirnoff #define _NETINET_CC_CC_H_
534644fda3SGleb Smirnoff 
54*adc56f5aSEdward Tomasz Napierala #ifdef _KERNEL
554644fda3SGleb Smirnoff 
564644fda3SGleb Smirnoff /* Global CC vars. */
574644fda3SGleb Smirnoff extern STAILQ_HEAD(cc_head, cc_algo) cc_list;
584644fda3SGleb Smirnoff extern const int tcprexmtthresh;
594644fda3SGleb Smirnoff extern struct cc_algo newreno_cc_algo;
604644fda3SGleb Smirnoff 
614644fda3SGleb Smirnoff /* Per-netstack bits. */
624644fda3SGleb Smirnoff VNET_DECLARE(struct cc_algo *, default_cc_ptr);
634644fda3SGleb Smirnoff #define	V_default_cc_ptr VNET(default_cc_ptr)
644644fda3SGleb Smirnoff 
65370efe5aSLawrence Stewart VNET_DECLARE(int, cc_do_abe);
66370efe5aSLawrence Stewart #define	V_cc_do_abe			VNET(cc_do_abe)
67370efe5aSLawrence Stewart 
68370efe5aSLawrence Stewart VNET_DECLARE(int, cc_abe_frlossreduce);
69370efe5aSLawrence Stewart #define	V_cc_abe_frlossreduce		VNET(cc_abe_frlossreduce)
70370efe5aSLawrence Stewart 
714644fda3SGleb Smirnoff /* Define the new net.inet.tcp.cc sysctl tree. */
724644fda3SGleb Smirnoff SYSCTL_DECL(_net_inet_tcp_cc);
734644fda3SGleb Smirnoff 
744644fda3SGleb Smirnoff /* CC housekeeping functions. */
754644fda3SGleb Smirnoff int	cc_register_algo(struct cc_algo *add_cc);
764644fda3SGleb Smirnoff int	cc_deregister_algo(struct cc_algo *remove_cc);
774644fda3SGleb Smirnoff 
784644fda3SGleb Smirnoff /*
794644fda3SGleb Smirnoff  * Wrapper around transport structs that contain same-named congestion
804644fda3SGleb Smirnoff  * control variables. Allows algos to be shared amongst multiple CC aware
814644fda3SGleb Smirnoff  * transprots.
824644fda3SGleb Smirnoff  */
834644fda3SGleb Smirnoff struct cc_var {
844644fda3SGleb Smirnoff 	void		*cc_data; /* Per-connection private CC algorithm data. */
854644fda3SGleb Smirnoff 	int		bytes_this_ack; /* # bytes acked by the current ACK. */
864644fda3SGleb Smirnoff 	tcp_seq		curack; /* Most recent ACK. */
874644fda3SGleb Smirnoff 	uint32_t	flags; /* Flags for cc_var (see below) */
884644fda3SGleb Smirnoff 	int		type; /* Indicates which ptr is valid in ccvc. */
894644fda3SGleb Smirnoff 	union ccv_container {
904644fda3SGleb Smirnoff 		struct tcpcb		*tcp;
914644fda3SGleb Smirnoff 		struct sctp_nets	*sctp;
924644fda3SGleb Smirnoff 	} ccvc;
934b7b743cSLawrence Stewart 	uint16_t	nsegs; /* # segments coalesced into current chain. */
944644fda3SGleb Smirnoff };
954644fda3SGleb Smirnoff 
964644fda3SGleb Smirnoff /* cc_var flags. */
974644fda3SGleb Smirnoff #define	CCF_ABC_SENTAWND	0x0001	/* ABC counted cwnd worth of bytes? */
984644fda3SGleb Smirnoff #define	CCF_CWND_LIMITED	0x0002	/* Are we currently cwnd limited? */
994644fda3SGleb Smirnoff #define	CCF_DELACK		0x0004	/* Is this ack delayed? */
1004644fda3SGleb Smirnoff #define	CCF_ACKNOW		0x0008	/* Will this ack be sent now? */
1014644fda3SGleb Smirnoff #define	CCF_IPHDR_CE		0x0010	/* Does this packet set CE bit? */
1024644fda3SGleb Smirnoff #define	CCF_TCPHDR_CWR		0x0020	/* Does this packet set CWR bit? */
1034644fda3SGleb Smirnoff 
1044644fda3SGleb Smirnoff /* ACK types passed to the ack_received() hook. */
1054644fda3SGleb Smirnoff #define	CC_ACK		0x0001	/* Regular in sequence ACK. */
1064644fda3SGleb Smirnoff #define	CC_DUPACK	0x0002	/* Duplicate ACK. */
1074644fda3SGleb Smirnoff #define	CC_PARTIALACK	0x0004	/* Not yet. */
1084644fda3SGleb Smirnoff #define	CC_SACK		0x0008	/* Not yet. */
109*adc56f5aSEdward Tomasz Napierala #endif /* _KERNEL */
1104644fda3SGleb Smirnoff 
1114644fda3SGleb Smirnoff /*
1124644fda3SGleb Smirnoff  * Congestion signal types passed to the cong_signal() hook. The highest order 8
1134644fda3SGleb Smirnoff  * bits (0x01000000 - 0x80000000) are reserved for CC algos to declare their own
1144644fda3SGleb Smirnoff  * congestion signal types.
1154644fda3SGleb Smirnoff  */
1164644fda3SGleb Smirnoff #define	CC_ECN		0x00000001	/* ECN marked packet received. */
1174644fda3SGleb Smirnoff #define	CC_RTO		0x00000002	/* RTO fired. */
1184644fda3SGleb Smirnoff #define	CC_RTO_ERR	0x00000004	/* RTO fired in error. */
1194644fda3SGleb Smirnoff #define	CC_NDUPACK	0x00000008	/* Threshold of dupack's reached. */
1204644fda3SGleb Smirnoff 
1214644fda3SGleb Smirnoff #define	CC_SIGPRIVMASK	0xFF000000	/* Mask to check if sig is private. */
1224644fda3SGleb Smirnoff 
123*adc56f5aSEdward Tomasz Napierala #ifdef _KERNEL
1244644fda3SGleb Smirnoff /*
1254644fda3SGleb Smirnoff  * Structure to hold data and function pointers that together represent a
1264644fda3SGleb Smirnoff  * congestion control algorithm.
1274644fda3SGleb Smirnoff  */
1284644fda3SGleb Smirnoff struct cc_algo {
1294644fda3SGleb Smirnoff 	char	name[TCP_CA_NAME_MAX];
1304644fda3SGleb Smirnoff 
1314644fda3SGleb Smirnoff 	/* Init global module state on kldload. */
1324644fda3SGleb Smirnoff 	int	(*mod_init)(void);
1334644fda3SGleb Smirnoff 
1344644fda3SGleb Smirnoff 	/* Cleanup global module state on kldunload. */
1354644fda3SGleb Smirnoff 	int	(*mod_destroy)(void);
1364644fda3SGleb Smirnoff 
1374644fda3SGleb Smirnoff 	/* Init CC state for a new control block. */
1384644fda3SGleb Smirnoff 	int	(*cb_init)(struct cc_var *ccv);
1394644fda3SGleb Smirnoff 
1404644fda3SGleb Smirnoff 	/* Cleanup CC state for a terminating control block. */
1414644fda3SGleb Smirnoff 	void	(*cb_destroy)(struct cc_var *ccv);
1424644fda3SGleb Smirnoff 
1434644fda3SGleb Smirnoff 	/* Init variables for a newly established connection. */
1444644fda3SGleb Smirnoff 	void	(*conn_init)(struct cc_var *ccv);
1454644fda3SGleb Smirnoff 
1464644fda3SGleb Smirnoff 	/* Called on receipt of an ack. */
1474644fda3SGleb Smirnoff 	void	(*ack_received)(struct cc_var *ccv, uint16_t type);
1484644fda3SGleb Smirnoff 
1494644fda3SGleb Smirnoff 	/* Called on detection of a congestion signal. */
1504644fda3SGleb Smirnoff 	void	(*cong_signal)(struct cc_var *ccv, uint32_t type);
1514644fda3SGleb Smirnoff 
1524644fda3SGleb Smirnoff 	/* Called after exiting congestion recovery. */
1534644fda3SGleb Smirnoff 	void	(*post_recovery)(struct cc_var *ccv);
1544644fda3SGleb Smirnoff 
1554644fda3SGleb Smirnoff 	/* Called when data transfer resumes after an idle period. */
1564644fda3SGleb Smirnoff 	void	(*after_idle)(struct cc_var *ccv);
1574644fda3SGleb Smirnoff 
1584644fda3SGleb Smirnoff 	/* Called for an additional ECN processing apart from RFC3168. */
1594644fda3SGleb Smirnoff 	void	(*ecnpkt_handler)(struct cc_var *ccv);
1604644fda3SGleb Smirnoff 
1614644fda3SGleb Smirnoff 	/* Called for {get|set}sockopt() on a TCP socket with TCP_CCALGOOPT. */
1624644fda3SGleb Smirnoff 	int     (*ctl_output)(struct cc_var *, struct sockopt *, void *);
1634644fda3SGleb Smirnoff 
1644644fda3SGleb Smirnoff 	STAILQ_ENTRY (cc_algo) entries;
1654644fda3SGleb Smirnoff };
1664644fda3SGleb Smirnoff 
1674644fda3SGleb Smirnoff /* Macro to obtain the CC algo's struct ptr. */
1684644fda3SGleb Smirnoff #define	CC_ALGO(tp)	((tp)->cc_algo)
1694644fda3SGleb Smirnoff 
1704644fda3SGleb Smirnoff /* Macro to obtain the CC algo's data ptr. */
1714644fda3SGleb Smirnoff #define	CC_DATA(tp)	((tp)->ccv->cc_data)
1724644fda3SGleb Smirnoff 
1734644fda3SGleb Smirnoff /* Macro to obtain the system default CC algo's struct ptr. */
1744644fda3SGleb Smirnoff #define	CC_DEFAULT()	V_default_cc_ptr
1754644fda3SGleb Smirnoff 
1764644fda3SGleb Smirnoff extern struct rwlock cc_list_lock;
1774644fda3SGleb Smirnoff #define	CC_LIST_LOCK_INIT()	rw_init(&cc_list_lock, "cc_list")
1784644fda3SGleb Smirnoff #define	CC_LIST_LOCK_DESTROY()	rw_destroy(&cc_list_lock)
1794644fda3SGleb Smirnoff #define	CC_LIST_RLOCK()		rw_rlock(&cc_list_lock)
1804644fda3SGleb Smirnoff #define	CC_LIST_RUNLOCK()	rw_runlock(&cc_list_lock)
1814644fda3SGleb Smirnoff #define	CC_LIST_WLOCK()		rw_wlock(&cc_list_lock)
1824644fda3SGleb Smirnoff #define	CC_LIST_WUNLOCK()	rw_wunlock(&cc_list_lock)
1834644fda3SGleb Smirnoff #define	CC_LIST_LOCK_ASSERT()	rw_assert(&cc_list_lock, RA_LOCKED)
1844644fda3SGleb Smirnoff 
185c8b53cedSMichael Tuexen #define CC_ALGOOPT_LIMIT	2048
186c8b53cedSMichael Tuexen 
187*adc56f5aSEdward Tomasz Napierala #endif /* _KERNEL */
1884644fda3SGleb Smirnoff #endif /* _NETINET_CC_CC_H_ */
189