xref: /linux/net/dccp/ackvec.h (revision 14b42963f64b98ab61fa9723c03d71aa5ef4f862)
1 #ifndef _ACKVEC_H
2 #define _ACKVEC_H
3 /*
4  *  net/dccp/ackvec.h
5  *
6  *  An implementation of the DCCP protocol
7  *  Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@mandriva.com>
8  *
9  *	This program is free software; you can redistribute it and/or modify it
10  *	under the terms of the GNU General Public License version 2 as
11  *	published by the Free Software Foundation.
12  */
13 
14 #include <linux/compiler.h>
15 #include <linux/list.h>
16 #include <linux/time.h>
17 #include <linux/types.h>
18 
19 /* Read about the ECN nonce to see why it is 253 */
20 #define DCCP_MAX_ACKVEC_LEN 253
21 
22 #define DCCP_ACKVEC_STATE_RECEIVED	0
23 #define DCCP_ACKVEC_STATE_ECN_MARKED	(1 << 6)
24 #define DCCP_ACKVEC_STATE_NOT_RECEIVED	(3 << 6)
25 
26 #define DCCP_ACKVEC_STATE_MASK		0xC0 /* 11000000 */
27 #define DCCP_ACKVEC_LEN_MASK		0x3F /* 00111111 */
28 
29 /** struct dccp_ackvec - ack vector
30  *
31  * This data structure is the one defined in the DCCP draft
32  * Appendix A.
33  *
34  * @dccpav_buf_head - circular buffer head
35  * @dccpav_buf_tail - circular buffer tail
36  * @dccpav_buf_ackno - ack # of the most recent packet acknowledgeable in the
37  * 		       buffer (i.e. %dccpav_buf_head)
38  * @dccpav_buf_nonce - the one-bit sum of the ECN Nonces on all packets acked
39  * 		       by the buffer with State 0
40  *
41  * Additionally, the HC-Receiver must keep some information about the
42  * Ack Vectors it has recently sent. For each packet sent carrying an
43  * Ack Vector, it remembers four variables:
44  *
45  * @dccpav_ack_ptr - the value of buf_head at the time of acknowledgement.
46  * @dccpav_records - list of dccp_ackvec_record
47  * @dccpav_ack_nonce - the one-bit sum of the ECN Nonces for all State 0.
48  *
49  * @dccpav_time		- the time in usecs
50  * @dccpav_buf - circular buffer of acknowledgeable packets
51  */
52 struct dccp_ackvec {
53 	u64		dccpav_buf_ackno;
54 	struct list_head dccpav_records;
55 	struct timeval	dccpav_time;
56 	u8		dccpav_buf_head;
57 	u8		dccpav_buf_tail;
58 	u8		dccpav_ack_ptr;
59 	u8		dccpav_sent_len;
60 	u8		dccpav_vec_len;
61 	u8		dccpav_buf_nonce;
62 	u8		dccpav_ack_nonce;
63 	u8		dccpav_buf[DCCP_MAX_ACKVEC_LEN];
64 };
65 
66 /** struct dccp_ackvec_record - ack vector record
67  *
68  * ACK vector record as defined in Appendix A of spec.
69  *
70  * The list is sorted by dccpavr_ack_seqno
71  *
72  * @dccpavr_node - node in dccpav_records
73  * @dccpavr_ack_seqno - sequence number of the packet this record was sent on
74  * @dccpavr_ack_ackno - sequence number being acknowledged
75  * @dccpavr_ack_ptr - pointer into dccpav_buf where this record starts
76  * @dccpavr_ack_nonce - dccpav_ack_nonce at the time this record was sent
77  * @dccpavr_sent_len - lenght of the record in dccpav_buf
78  */
79 struct dccp_ackvec_record {
80 	struct list_head dccpavr_node;
81 	u64		 dccpavr_ack_seqno;
82 	u64		 dccpavr_ack_ackno;
83 	u8		 dccpavr_ack_ptr;
84 	u8		 dccpavr_ack_nonce;
85 	u8		 dccpavr_sent_len;
86 };
87 
88 struct sock;
89 struct sk_buff;
90 
91 #ifdef CONFIG_IP_DCCP_ACKVEC
92 extern int dccp_ackvec_init(void);
93 extern void dccp_ackvec_exit(void);
94 
95 extern struct dccp_ackvec *dccp_ackvec_alloc(const gfp_t priority);
96 extern void dccp_ackvec_free(struct dccp_ackvec *av);
97 
98 extern int dccp_ackvec_add(struct dccp_ackvec *av, const struct sock *sk,
99 			   const u64 ackno, const u8 state);
100 
101 extern void dccp_ackvec_check_rcv_ackno(struct dccp_ackvec *av,
102 					struct sock *sk, const u64 ackno);
103 extern int dccp_ackvec_parse(struct sock *sk, const struct sk_buff *skb,
104 			     const u8 opt, const u8 *value, const u8 len);
105 
106 extern int dccp_insert_option_ackvec(struct sock *sk, struct sk_buff *skb);
107 
108 static inline int dccp_ackvec_pending(const struct dccp_ackvec *av)
109 {
110 	return av->dccpav_sent_len != av->dccpav_vec_len;
111 }
112 #else /* CONFIG_IP_DCCP_ACKVEC */
113 static inline int dccp_ackvec_init(void)
114 {
115 	return 0;
116 }
117 
118 static inline void dccp_ackvec_exit(void)
119 {
120 }
121 
122 static inline struct dccp_ackvec *dccp_ackvec_alloc(const gfp_t priority)
123 {
124 	return NULL;
125 }
126 
127 static inline void dccp_ackvec_free(struct dccp_ackvec *av)
128 {
129 }
130 
131 static inline int dccp_ackvec_add(struct dccp_ackvec *av, const struct sock *sk,
132 				  const u64 ackno, const u8 state)
133 {
134 	return -1;
135 }
136 
137 static inline void dccp_ackvec_check_rcv_ackno(struct dccp_ackvec *av,
138 					       struct sock *sk, const u64 ackno)
139 {
140 }
141 
142 static inline int dccp_ackvec_parse(struct sock *sk, const struct sk_buff *skb,
143 				    const u8 opt, const u8 *value, const u8 len)
144 {
145 	return -1;
146 }
147 
148 static inline int dccp_insert_option_ackvec(const struct sock *sk,
149 					    const struct sk_buff *skb)
150 {
151 	return -1;
152 }
153 
154 static inline int dccp_ackvec_pending(const struct dccp_ackvec *av)
155 {
156 	return 0;
157 }
158 #endif /* CONFIG_IP_DCCP_ACKVEC */
159 #endif /* _ACKVEC_H */
160