xref: /linux/net/dccp/ackvec.h (revision 75bf465f0bc33e9b776a46d6a1b9b990f5fb7c37)
1*d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2ae31c339SArnaldo Carvalho de Melo #ifndef _ACKVEC_H
3ae31c339SArnaldo Carvalho de Melo #define _ACKVEC_H
4ae31c339SArnaldo Carvalho de Melo /*
5ae31c339SArnaldo Carvalho de Melo  *  net/dccp/ackvec.h
6ae31c339SArnaldo Carvalho de Melo  *
7f17a37c9SGerrit Renker  *  An implementation of Ack Vectors for the DCCP protocol
8f17a37c9SGerrit Renker  *  Copyright (c) 2007 University of Aberdeen, Scotland, UK
9ae31c339SArnaldo Carvalho de Melo  *  Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@mandriva.com>
10ae31c339SArnaldo Carvalho de Melo  */
11ae31c339SArnaldo Carvalho de Melo 
12b20a9c24SGerrit Renker #include <linux/dccp.h>
13ae31c339SArnaldo Carvalho de Melo #include <linux/compiler.h>
1402bcf28cSAndrea Bittau #include <linux/list.h>
15ae31c339SArnaldo Carvalho de Melo #include <linux/types.h>
16ae31c339SArnaldo Carvalho de Melo 
17f17a37c9SGerrit Renker /*
18f17a37c9SGerrit Renker  * Ack Vector buffer space is static, in multiples of %DCCP_SINGLE_OPT_MAXLEN,
19f17a37c9SGerrit Renker  * the maximum size of a single Ack Vector. Setting %DCCPAV_NUM_ACKVECS to 1
20f17a37c9SGerrit Renker  * will be sufficient for most cases of low Ack Ratios, using a value of 2 gives
21f17a37c9SGerrit Renker  * more headroom if Ack Ratio is higher or when the sender acknowledges slowly.
22b3d14bffSGerrit Renker  * The maximum value is bounded by the u16 types for indices and functions.
23f17a37c9SGerrit Renker  */
24f17a37c9SGerrit Renker #define DCCPAV_NUM_ACKVECS	2
25f17a37c9SGerrit Renker #define DCCPAV_MAX_ACKVEC_LEN	(DCCP_SINGLE_OPT_MAXLEN * DCCPAV_NUM_ACKVECS)
26ae31c339SArnaldo Carvalho de Melo 
27361a5c1dSGerrit Renker /* Estimated minimum average Ack Vector length - used for updating MPS */
28361a5c1dSGerrit Renker #define DCCPAV_MIN_OPTLEN	16
29361a5c1dSGerrit Renker 
3038024086SGerrit Renker /* Threshold for coping with large bursts of losses */
3138024086SGerrit Renker #define DCCPAV_BURST_THRESH	(DCCPAV_MAX_ACKVEC_LEN / 8)
3238024086SGerrit Renker 
33f17a37c9SGerrit Renker enum dccp_ackvec_states {
34f17a37c9SGerrit Renker 	DCCPAV_RECEIVED =	0x00,
35f17a37c9SGerrit Renker 	DCCPAV_ECN_MARKED =	0x40,
36f17a37c9SGerrit Renker 	DCCPAV_RESERVED =	0x80,
37f17a37c9SGerrit Renker 	DCCPAV_NOT_RECEIVED =	0xC0
38f17a37c9SGerrit Renker };
39f17a37c9SGerrit Renker #define DCCPAV_MAX_RUNLEN	0x3F
40ae31c339SArnaldo Carvalho de Melo 
dccp_ackvec_runlen(const u8 * cell)41f17a37c9SGerrit Renker static inline u8 dccp_ackvec_runlen(const u8 *cell)
42f17a37c9SGerrit Renker {
43f17a37c9SGerrit Renker 	return *cell & DCCPAV_MAX_RUNLEN;
44f17a37c9SGerrit Renker }
45ae31c339SArnaldo Carvalho de Melo 
dccp_ackvec_state(const u8 * cell)46f17a37c9SGerrit Renker static inline u8 dccp_ackvec_state(const u8 *cell)
47f17a37c9SGerrit Renker {
48f17a37c9SGerrit Renker 	return *cell & ~DCCPAV_MAX_RUNLEN;
49f17a37c9SGerrit Renker }
50f17a37c9SGerrit Renker 
512c53040fSBen Hutchings /**
522c53040fSBen Hutchings  * struct dccp_ackvec - Ack Vector main data structure
53ae31c339SArnaldo Carvalho de Melo  *
54f17a37c9SGerrit Renker  * This implements a fixed-size circular buffer within an array and is largely
55f17a37c9SGerrit Renker  * based on Appendix A of RFC 4340.
56ae31c339SArnaldo Carvalho de Melo  *
57f17a37c9SGerrit Renker  * @av_buf:	   circular buffer storage area
58f17a37c9SGerrit Renker  * @av_buf_head:   head index; begin of live portion in @av_buf
59f17a37c9SGerrit Renker  * @av_buf_tail:   tail index; first index _after_ the live portion in @av_buf
60f17a37c9SGerrit Renker  * @av_buf_ackno:  highest seqno of acknowledgeable packet recorded in @av_buf
61b3d14bffSGerrit Renker  * @av_tail_ackno: lowest  seqno of acknowledgeable packet recorded in @av_buf
62f17a37c9SGerrit Renker  * @av_buf_nonce:  ECN nonce sums, each covering subsequent segments of up to
63f17a37c9SGerrit Renker  *		   %DCCP_SINGLE_OPT_MAXLEN cells in the live portion of @av_buf
64b3d14bffSGerrit Renker  * @av_overflow:   if 1 then buf_head == buf_tail indicates buffer wraparound
65f17a37c9SGerrit Renker  * @av_records:	   list of %dccp_ackvec_record (Ack Vectors sent previously)
66ae31c339SArnaldo Carvalho de Melo  */
67ae31c339SArnaldo Carvalho de Melo struct dccp_ackvec {
68f17a37c9SGerrit Renker 	u8			av_buf[DCCPAV_MAX_ACKVEC_LEN];
69a47c5104SGerrit Renker 	u16			av_buf_head;
70f17a37c9SGerrit Renker 	u16			av_buf_tail;
71f17a37c9SGerrit Renker 	u64			av_buf_ackno:48;
72b3d14bffSGerrit Renker 	u64			av_tail_ackno:48;
73f17a37c9SGerrit Renker 	bool			av_buf_nonce[DCCPAV_NUM_ACKVECS];
74b3d14bffSGerrit Renker 	u8			av_overflow:1;
75f17a37c9SGerrit Renker 	struct list_head	av_records;
76ae31c339SArnaldo Carvalho de Melo };
77ae31c339SArnaldo Carvalho de Melo 
782c53040fSBen Hutchings /**
792c53040fSBen Hutchings  * struct dccp_ackvec_record - Records information about sent Ack Vectors
8002bcf28cSAndrea Bittau  *
81f17a37c9SGerrit Renker  * These list entries define the additional information which the HC-Receiver
82f17a37c9SGerrit Renker  * keeps about recently-sent Ack Vectors; again refer to RFC 4340, Appendix A.
8302bcf28cSAndrea Bittau  *
84f17a37c9SGerrit Renker  * @avr_node:	    the list node in @av_records
85f17a37c9SGerrit Renker  * @avr_ack_seqno:  sequence number of the packet the Ack Vector was sent on
86f17a37c9SGerrit Renker  * @avr_ack_ackno:  the Ack number that this record/Ack Vector refers to
87f17a37c9SGerrit Renker  * @avr_ack_ptr:    pointer into @av_buf where this record starts
88f17a37c9SGerrit Renker  * @avr_ack_runlen: run length of @avr_ack_ptr at the time of sending
89f17a37c9SGerrit Renker  * @avr_ack_nonce:  the sum of @av_buf_nonce's at the time this record was sent
9002bcf28cSAndrea Bittau  *
91f17a37c9SGerrit Renker  * The list as a whole is sorted in descending order by @avr_ack_seqno.
9202bcf28cSAndrea Bittau  */
9302bcf28cSAndrea Bittau struct dccp_ackvec_record {
94a47c5104SGerrit Renker 	struct list_head avr_node;
95f17a37c9SGerrit Renker 	u64		 avr_ack_seqno:48;
96f17a37c9SGerrit Renker 	u64		 avr_ack_ackno:48;
97a47c5104SGerrit Renker 	u16		 avr_ack_ptr;
98f17a37c9SGerrit Renker 	u8		 avr_ack_runlen;
99f17a37c9SGerrit Renker 	u8		 avr_ack_nonce:1;
10002bcf28cSAndrea Bittau };
10102bcf28cSAndrea Bittau 
102a402a5aaSJoe Perches int dccp_ackvec_init(void);
103a402a5aaSJoe Perches void dccp_ackvec_exit(void);
1049b07ef5dSArnaldo Carvalho de Melo 
105a402a5aaSJoe Perches struct dccp_ackvec *dccp_ackvec_alloc(const gfp_t priority);
106a402a5aaSJoe Perches void dccp_ackvec_free(struct dccp_ackvec *av);
107ae31c339SArnaldo Carvalho de Melo 
108a402a5aaSJoe Perches void dccp_ackvec_input(struct dccp_ackvec *av, struct sk_buff *skb);
109a402a5aaSJoe Perches int dccp_ackvec_update_records(struct dccp_ackvec *av, u64 seq, u8 sum);
110a402a5aaSJoe Perches void dccp_ackvec_clear_state(struct dccp_ackvec *av, const u64 ackno);
111a402a5aaSJoe Perches u16 dccp_ackvec_buflen(const struct dccp_ackvec *av);
112ae31c339SArnaldo Carvalho de Melo 
dccp_ackvec_is_empty(const struct dccp_ackvec * av)113b3d14bffSGerrit Renker static inline bool dccp_ackvec_is_empty(const struct dccp_ackvec *av)
114ae31c339SArnaldo Carvalho de Melo {
115b3d14bffSGerrit Renker 	return av->av_overflow == 0 && av->av_buf_head == av->av_buf_tail;
116ae31c339SArnaldo Carvalho de Melo }
1177e87fe84SGerrit Renker 
1187e87fe84SGerrit Renker /**
1197e87fe84SGerrit Renker  * struct dccp_ackvec_parsed  -  Record offsets of Ack Vectors in skb
1207e87fe84SGerrit Renker  * @vec:	start of vector (offset into skb)
1217e87fe84SGerrit Renker  * @len:	length of @vec
1227e87fe84SGerrit Renker  * @nonce:	whether @vec had an ECN nonce of 0 or 1
1237e87fe84SGerrit Renker  * @node:	FIFO - arranged in descending order of ack_ackno
1242c53040fSBen Hutchings  *
1257e87fe84SGerrit Renker  * This structure is used by CCIDs to access Ack Vectors in a received skb.
1267e87fe84SGerrit Renker  */
1277e87fe84SGerrit Renker struct dccp_ackvec_parsed {
1287e87fe84SGerrit Renker 	u8		 *vec,
1297e87fe84SGerrit Renker 			 len,
1307e87fe84SGerrit Renker 			 nonce:1;
1317e87fe84SGerrit Renker 	struct list_head node;
1327e87fe84SGerrit Renker };
1337e87fe84SGerrit Renker 
134a402a5aaSJoe Perches int dccp_ackvec_parsed_add(struct list_head *head, u8 *vec, u8 len, u8 nonce);
135a402a5aaSJoe Perches void dccp_ackvec_parsed_cleanup(struct list_head *parsed_chunks);
136ae31c339SArnaldo Carvalho de Melo #endif /* _ACKVEC_H */
137