xref: /openbmc/linux/net/dccp/ccids/lib/packet_history.h (revision 96de0e252cedffad61b3cb5e05662c591898e69a)
1 /*
2  *  net/dccp/packet_history.h
3  *
4  *  Copyright (c) 2005-6 The University of Waikato, Hamilton, New Zealand.
5  *
6  *  An implementation of the DCCP protocol
7  *
8  *  This code has been developed by the University of Waikato WAND
9  *  research group. For further information please see http://www.wand.net.nz/
10  *  or e-mail Ian McDonald - ian.mcdonald@jandi.co.nz
11  *
12  *  This code also uses code from Lulea University, rereleased as GPL by its
13  *  authors:
14  *  Copyright (c) 2003 Nils-Erik Mattsson, Joacim Haggmark, Magnus Erixzon
15  *
16  *  Changes to meet Linux coding standards, to make it meet latest ccid3 draft
17  *  and to make it work as a loadable module in the DCCP stack written by
18  *  Arnaldo Carvalho de Melo <acme@conectiva.com.br>.
19  *
20  *  Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@conectiva.com.br>
21  *
22  *  This program is free software; you can redistribute it and/or modify
23  *  it under the terms of the GNU General Public License as published by
24  *  the Free Software Foundation; either version 2 of the License, or
25  *  (at your option) any later version.
26  *
27  *  This program is distributed in the hope that it will be useful,
28  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
29  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
30  *  GNU General Public License for more details.
31  *
32  *  You should have received a copy of the GNU General Public License
33  *  along with this program; if not, write to the Free Software
34  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35  */
36 
37 #ifndef _DCCP_PKT_HIST_
38 #define _DCCP_PKT_HIST_
39 
40 #include <linux/ktime.h>
41 #include <linux/list.h>
42 #include <linux/slab.h>
43 
44 #include "../../dccp.h"
45 
46 /* Number of later packets received before one is considered lost */
47 #define TFRC_RECV_NUM_LATE_LOSS	 3
48 
49 #define TFRC_WIN_COUNT_PER_RTT	 4
50 #define TFRC_WIN_COUNT_LIMIT	16
51 
52 /*
53  * 	Transmitter History data structures and declarations
54  */
55 struct dccp_tx_hist_entry {
56 	struct list_head dccphtx_node;
57 	u64		 dccphtx_seqno:48,
58 			 dccphtx_sent:1;
59 	u32		 dccphtx_rtt;
60 	ktime_t		 dccphtx_tstamp;
61 };
62 
63 struct dccp_tx_hist {
64 	struct kmem_cache *dccptxh_slab;
65 };
66 
67 extern struct dccp_tx_hist *dccp_tx_hist_new(const char *name);
68 extern void 		    dccp_tx_hist_delete(struct dccp_tx_hist *hist);
69 
70 static inline struct dccp_tx_hist_entry *
71 			dccp_tx_hist_entry_new(struct dccp_tx_hist *hist,
72 					       const gfp_t prio)
73 {
74 	struct dccp_tx_hist_entry *entry = kmem_cache_alloc(hist->dccptxh_slab,
75 							    prio);
76 
77 	if (entry != NULL)
78 		entry->dccphtx_sent = 0;
79 
80 	return entry;
81 }
82 
83 static inline struct dccp_tx_hist_entry *
84 			dccp_tx_hist_head(struct list_head *list)
85 {
86 	struct dccp_tx_hist_entry *head = NULL;
87 
88 	if (!list_empty(list))
89 		head = list_entry(list->next, struct dccp_tx_hist_entry,
90 				  dccphtx_node);
91 	return head;
92 }
93 
94 extern struct dccp_tx_hist_entry *
95 			dccp_tx_hist_find_entry(const struct list_head *list,
96 						const u64 seq);
97 
98 static inline void dccp_tx_hist_add_entry(struct list_head *list,
99 					  struct dccp_tx_hist_entry *entry)
100 {
101 	list_add(&entry->dccphtx_node, list);
102 }
103 
104 static inline void dccp_tx_hist_entry_delete(struct dccp_tx_hist *hist,
105 					     struct dccp_tx_hist_entry *entry)
106 {
107 	if (entry != NULL)
108 		kmem_cache_free(hist->dccptxh_slab, entry);
109 }
110 
111 extern void dccp_tx_hist_purge(struct dccp_tx_hist *hist,
112 			       struct list_head *list);
113 
114 extern void dccp_tx_hist_purge_older(struct dccp_tx_hist *hist,
115 				     struct list_head *list,
116 				     struct dccp_tx_hist_entry *next);
117 
118 /*
119  * 	Receiver History data structures and declarations
120  */
121 struct dccp_rx_hist_entry {
122 	struct list_head dccphrx_node;
123 	u64		 dccphrx_seqno:48,
124 			 dccphrx_ccval:4,
125 			 dccphrx_type:4;
126 	u32		 dccphrx_ndp; /* In fact it is from 8 to 24 bits */
127 	ktime_t		 dccphrx_tstamp;
128 };
129 
130 struct dccp_rx_hist {
131 	struct kmem_cache *dccprxh_slab;
132 };
133 
134 extern struct dccp_rx_hist *dccp_rx_hist_new(const char *name);
135 extern void 		dccp_rx_hist_delete(struct dccp_rx_hist *hist);
136 
137 static inline struct dccp_rx_hist_entry *
138 			dccp_rx_hist_entry_new(struct dccp_rx_hist *hist,
139 					       const u32 ndp,
140 					       const struct sk_buff *skb,
141 					       const gfp_t prio)
142 {
143 	struct dccp_rx_hist_entry *entry = kmem_cache_alloc(hist->dccprxh_slab,
144 							    prio);
145 
146 	if (entry != NULL) {
147 		const struct dccp_hdr *dh = dccp_hdr(skb);
148 
149 		entry->dccphrx_seqno = DCCP_SKB_CB(skb)->dccpd_seq;
150 		entry->dccphrx_ccval = dh->dccph_ccval;
151 		entry->dccphrx_type  = dh->dccph_type;
152 		entry->dccphrx_ndp   = ndp;
153 		entry->dccphrx_tstamp = ktime_get_real();
154 	}
155 
156 	return entry;
157 }
158 
159 static inline struct dccp_rx_hist_entry *
160 			dccp_rx_hist_head(struct list_head *list)
161 {
162 	struct dccp_rx_hist_entry *head = NULL;
163 
164 	if (!list_empty(list))
165 		head = list_entry(list->next, struct dccp_rx_hist_entry,
166 				  dccphrx_node);
167 	return head;
168 }
169 
170 extern int dccp_rx_hist_find_entry(const struct list_head *list, const u64 seq,
171 				   u8 *ccval);
172 extern struct dccp_rx_hist_entry *
173 		dccp_rx_hist_find_data_packet(const struct list_head *list);
174 
175 extern void dccp_rx_hist_add_packet(struct dccp_rx_hist *hist,
176 				    struct list_head *rx_list,
177 				    struct list_head *li_list,
178 				    struct dccp_rx_hist_entry *packet,
179 				    u64 nonloss_seqno);
180 
181 static inline void dccp_rx_hist_entry_delete(struct dccp_rx_hist *hist,
182 					     struct dccp_rx_hist_entry *entry)
183 {
184 	if (entry != NULL)
185 		kmem_cache_free(hist->dccprxh_slab, entry);
186 }
187 
188 extern void dccp_rx_hist_purge(struct dccp_rx_hist *hist,
189 			       struct list_head *list);
190 
191 static inline int
192 	dccp_rx_hist_entry_data_packet(const struct dccp_rx_hist_entry *entry)
193 {
194 	return entry->dccphrx_type == DCCP_PKT_DATA ||
195 	       entry->dccphrx_type == DCCP_PKT_DATAACK;
196 }
197 
198 extern u64 dccp_rx_hist_detect_loss(struct list_head *rx_list,
199 				    struct list_head *li_list, u8 *win_loss);
200 
201 #endif /* _DCCP_PKT_HIST_ */
202