xref: /openbmc/linux/net/dccp/ackvec.h (revision f17a37c9b8c4b32c01e501a84fa6f30e344c6110)
1ae31c339SArnaldo Carvalho de Melo #ifndef _ACKVEC_H
2ae31c339SArnaldo Carvalho de Melo #define _ACKVEC_H
3ae31c339SArnaldo Carvalho de Melo /*
4ae31c339SArnaldo Carvalho de Melo  *  net/dccp/ackvec.h
5ae31c339SArnaldo Carvalho de Melo  *
6*f17a37c9SGerrit Renker  *  An implementation of Ack Vectors for the DCCP protocol
7*f17a37c9SGerrit Renker  *  Copyright (c) 2007 University of Aberdeen, Scotland, UK
8ae31c339SArnaldo Carvalho de Melo  *  Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@mandriva.com>
9ae31c339SArnaldo Carvalho de Melo  *	This program is free software; you can redistribute it and/or modify it
10ae31c339SArnaldo Carvalho de Melo  *	under the terms of the GNU General Public License version 2 as
11ae31c339SArnaldo Carvalho de Melo  *	published by the Free Software Foundation.
12ae31c339SArnaldo Carvalho de Melo  */
13ae31c339SArnaldo Carvalho de Melo 
14b20a9c24SGerrit Renker #include <linux/dccp.h>
15ae31c339SArnaldo Carvalho de Melo #include <linux/compiler.h>
1602bcf28cSAndrea Bittau #include <linux/list.h>
17ae31c339SArnaldo Carvalho de Melo #include <linux/types.h>
18ae31c339SArnaldo Carvalho de Melo 
19*f17a37c9SGerrit Renker /*
20*f17a37c9SGerrit Renker  * Ack Vector buffer space is static, in multiples of %DCCP_SINGLE_OPT_MAXLEN,
21*f17a37c9SGerrit Renker  * the maximum size of a single Ack Vector. Setting %DCCPAV_NUM_ACKVECS to 1
22*f17a37c9SGerrit Renker  * will be sufficient for most cases of low Ack Ratios, using a value of 2 gives
23*f17a37c9SGerrit Renker  * more headroom if Ack Ratio is higher or when the sender acknowledges slowly.
24*f17a37c9SGerrit Renker  */
25*f17a37c9SGerrit Renker #define DCCPAV_NUM_ACKVECS	2
26*f17a37c9SGerrit Renker #define DCCPAV_MAX_ACKVEC_LEN	(DCCP_SINGLE_OPT_MAXLEN * DCCPAV_NUM_ACKVECS)
27ae31c339SArnaldo Carvalho de Melo 
28361a5c1dSGerrit Renker /* Estimated minimum average Ack Vector length - used for updating MPS */
29361a5c1dSGerrit Renker #define DCCPAV_MIN_OPTLEN	16
30361a5c1dSGerrit Renker 
31*f17a37c9SGerrit Renker enum dccp_ackvec_states {
32*f17a37c9SGerrit Renker 	DCCPAV_RECEIVED =	0x00,
33*f17a37c9SGerrit Renker 	DCCPAV_ECN_MARKED =	0x40,
34*f17a37c9SGerrit Renker 	DCCPAV_RESERVED =	0x80,
35*f17a37c9SGerrit Renker 	DCCPAV_NOT_RECEIVED =	0xC0
36*f17a37c9SGerrit Renker };
37*f17a37c9SGerrit Renker #define DCCPAV_MAX_RUNLEN	0x3F
38ae31c339SArnaldo Carvalho de Melo 
39*f17a37c9SGerrit Renker static inline u8 dccp_ackvec_runlen(const u8 *cell)
40*f17a37c9SGerrit Renker {
41*f17a37c9SGerrit Renker 	return *cell & DCCPAV_MAX_RUNLEN;
42*f17a37c9SGerrit Renker }
43ae31c339SArnaldo Carvalho de Melo 
44*f17a37c9SGerrit Renker static inline u8 dccp_ackvec_state(const u8 *cell)
45*f17a37c9SGerrit Renker {
46*f17a37c9SGerrit Renker 	return *cell & ~DCCPAV_MAX_RUNLEN;
47*f17a37c9SGerrit Renker }
48*f17a37c9SGerrit Renker 
49*f17a37c9SGerrit Renker /** struct dccp_ackvec - Ack Vector main data structure
50ae31c339SArnaldo Carvalho de Melo  *
51*f17a37c9SGerrit Renker  * This implements a fixed-size circular buffer within an array and is largely
52*f17a37c9SGerrit Renker  * based on Appendix A of RFC 4340.
53ae31c339SArnaldo Carvalho de Melo  *
54*f17a37c9SGerrit Renker  * @av_buf:	   circular buffer storage area
55*f17a37c9SGerrit Renker  * @av_buf_head:   head index; begin of live portion in @av_buf
56*f17a37c9SGerrit Renker  * @av_buf_tail:   tail index; first index _after_ the live portion in @av_buf
57*f17a37c9SGerrit Renker  * @av_buf_ackno:  highest seqno of acknowledgeable packet recorded in @av_buf
58*f17a37c9SGerrit Renker  * @av_buf_nonce:  ECN nonce sums, each covering subsequent segments of up to
59*f17a37c9SGerrit Renker  *		   %DCCP_SINGLE_OPT_MAXLEN cells in the live portion of @av_buf
60*f17a37c9SGerrit Renker  * @av_records:	   list of %dccp_ackvec_record (Ack Vectors sent previously)
61*f17a37c9SGerrit Renker  * @av_veclen:	   length of the live portion of @av_buf
62ae31c339SArnaldo Carvalho de Melo  */
63ae31c339SArnaldo Carvalho de Melo struct dccp_ackvec {
64*f17a37c9SGerrit Renker 	u8			av_buf[DCCPAV_MAX_ACKVEC_LEN];
65a47c5104SGerrit Renker 	u16			av_buf_head;
66*f17a37c9SGerrit Renker 	u16			av_buf_tail;
67*f17a37c9SGerrit Renker 	u64			av_buf_ackno:48;
68*f17a37c9SGerrit Renker 	bool			av_buf_nonce[DCCPAV_NUM_ACKVECS];
69*f17a37c9SGerrit Renker 	struct list_head	av_records;
70a47c5104SGerrit Renker 	u16			av_vec_len;
71ae31c339SArnaldo Carvalho de Melo };
72ae31c339SArnaldo Carvalho de Melo 
73*f17a37c9SGerrit Renker /** struct dccp_ackvec_record - Records information about sent Ack Vectors
7402bcf28cSAndrea Bittau  *
75*f17a37c9SGerrit Renker  * These list entries define the additional information which the HC-Receiver
76*f17a37c9SGerrit Renker  * keeps about recently-sent Ack Vectors; again refer to RFC 4340, Appendix A.
7702bcf28cSAndrea Bittau  *
78*f17a37c9SGerrit Renker  * @avr_node:	    the list node in @av_records
79*f17a37c9SGerrit Renker  * @avr_ack_seqno:  sequence number of the packet the Ack Vector was sent on
80*f17a37c9SGerrit Renker  * @avr_ack_ackno:  the Ack number that this record/Ack Vector refers to
81*f17a37c9SGerrit Renker  * @avr_ack_ptr:    pointer into @av_buf where this record starts
82*f17a37c9SGerrit Renker  * @avr_ack_runlen: run length of @avr_ack_ptr at the time of sending
83*f17a37c9SGerrit Renker  * @avr_ack_nonce:  the sum of @av_buf_nonce's at the time this record was sent
8402bcf28cSAndrea Bittau  *
85*f17a37c9SGerrit Renker  * The list as a whole is sorted in descending order by @avr_ack_seqno.
8602bcf28cSAndrea Bittau  */
8702bcf28cSAndrea Bittau struct dccp_ackvec_record {
88a47c5104SGerrit Renker 	struct list_head avr_node;
89*f17a37c9SGerrit Renker 	u64		 avr_ack_seqno:48;
90*f17a37c9SGerrit Renker 	u64		 avr_ack_ackno:48;
91a47c5104SGerrit Renker 	u16		 avr_ack_ptr;
92*f17a37c9SGerrit Renker 	u8		 avr_ack_runlen;
93*f17a37c9SGerrit Renker 	u8		 avr_ack_nonce:1;
9402bcf28cSAndrea Bittau };
9502bcf28cSAndrea Bittau 
96ae31c339SArnaldo Carvalho de Melo struct sock;
97ae31c339SArnaldo Carvalho de Melo struct sk_buff;
98ae31c339SArnaldo Carvalho de Melo 
999b07ef5dSArnaldo Carvalho de Melo extern int dccp_ackvec_init(void);
1009b07ef5dSArnaldo Carvalho de Melo extern void dccp_ackvec_exit(void);
1019b07ef5dSArnaldo Carvalho de Melo 
1027400d781SArnaldo Carvalho de Melo extern struct dccp_ackvec *dccp_ackvec_alloc(const gfp_t priority);
103ae31c339SArnaldo Carvalho de Melo extern void dccp_ackvec_free(struct dccp_ackvec *av);
104ae31c339SArnaldo Carvalho de Melo 
105ae31c339SArnaldo Carvalho de Melo extern int dccp_ackvec_add(struct dccp_ackvec *av, const struct sock *sk,
106ae31c339SArnaldo Carvalho de Melo 			   const u64 ackno, const u8 state);
107ae31c339SArnaldo Carvalho de Melo 
108ae31c339SArnaldo Carvalho de Melo extern void dccp_ackvec_check_rcv_ackno(struct dccp_ackvec *av,
109ae31c339SArnaldo Carvalho de Melo 					struct sock *sk, const u64 ackno);
110ae31c339SArnaldo Carvalho de Melo extern int dccp_ackvec_parse(struct sock *sk, const struct sk_buff *skb,
111bdf13d20SAndrea Bittau 			     u64 *ackno, const u8 opt,
112bdf13d20SAndrea Bittau 			     const u8 *value, const u8 len);
113ae31c339SArnaldo Carvalho de Melo 
114ae31c339SArnaldo Carvalho de Melo extern int dccp_insert_option_ackvec(struct sock *sk, struct sk_buff *skb);
115ae31c339SArnaldo Carvalho de Melo 
116ae31c339SArnaldo Carvalho de Melo static inline int dccp_ackvec_pending(const struct dccp_ackvec *av)
117ae31c339SArnaldo Carvalho de Melo {
118a47c5104SGerrit Renker 	return av->av_vec_len;
119ae31c339SArnaldo Carvalho de Melo }
120ae31c339SArnaldo Carvalho de Melo #endif /* _ACKVEC_H */
121