[INET_DIAG]: Move the tcp_diag interface to the proper place
[safe/jmp/linux-2.6] / net / dccp / packet_history.h
1 /*
2  *  net/dccp/packet_history.h
3  *
4  *  Copyright (c) 2005 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 - iam4@cs.waikato.ac.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/config.h>
41 #include <linux/list.h>
42 #include <linux/slab.h>
43 #include <linux/time.h>
44
45 #include "dccp.h"
46
47 struct dccp_tx_hist_entry {
48         struct list_head dccphtx_node;
49         u64              dccphtx_seqno:48,
50                          dccphtx_win_count:8,
51                          dccphtx_sent:1;
52         struct timeval   dccphtx_tstamp;
53 };
54
55 struct dccp_rx_hist_entry {
56         struct list_head dccphrx_node;
57         u64              dccphrx_seqno:48,
58                          dccphrx_win_count:4,
59                          dccphrx_type:4;
60         u32              dccphrx_ndp; /* In fact it is from 8 to 24 bits */
61         struct timeval   dccphrx_tstamp;
62 };
63
64 struct dccp_tx_hist {
65         kmem_cache_t *dccptxh_slab;
66 };
67
68 extern struct dccp_tx_hist *dccp_tx_hist_new(const char *name);
69 extern void dccp_tx_hist_delete(struct dccp_tx_hist *hist);
70
71 struct dccp_rx_hist {
72         kmem_cache_t *dccprxh_slab;
73 };
74
75 extern struct dccp_rx_hist *dccp_rx_hist_new(const char *name);
76 extern void dccp_rx_hist_delete(struct dccp_rx_hist *hist);
77 extern struct dccp_rx_hist_entry *
78                 dccp_rx_hist_find_data_packet(const struct list_head *list);
79
80 static inline struct dccp_tx_hist_entry *
81                         dccp_tx_hist_entry_new(struct dccp_tx_hist *hist,
82                                                const int prio)
83 {
84         struct dccp_tx_hist_entry *entry = kmem_cache_alloc(hist->dccptxh_slab,
85                                                             prio);
86
87         if (entry != NULL)
88                 entry->dccphtx_sent = 0;
89
90         return entry;
91 }
92
93 static inline void dccp_tx_hist_entry_delete(struct dccp_tx_hist *hist,
94                                              struct dccp_tx_hist_entry *entry)
95 {
96         if (entry != NULL)
97                 kmem_cache_free(hist->dccptxh_slab, entry);
98 }
99
100 extern struct dccp_tx_hist_entry *
101                         dccp_tx_hist_find_entry(const struct list_head *list,
102                                                 const u64 seq);
103
104 static inline void dccp_tx_hist_add_entry(struct list_head *list,
105                                           struct dccp_tx_hist_entry *entry)
106 {
107         list_add(&entry->dccphtx_node, list);
108 }
109
110 extern void dccp_tx_hist_purge_older(struct dccp_tx_hist *hist,
111                                      struct list_head *list,
112                                      struct dccp_tx_hist_entry *next);
113
114 extern void dccp_tx_hist_purge(struct dccp_tx_hist *hist,
115                                struct list_head *list);
116
117 static inline struct dccp_tx_hist_entry *dccp_tx_hist_head(struct list_head *list)
118 {
119         struct dccp_tx_hist_entry *head = NULL;
120
121         if (!list_empty(list))
122                 head = list_entry(list->next, struct dccp_tx_hist_entry,
123                                   dccphtx_node);
124         return head;
125 }
126
127 static inline struct dccp_rx_hist_entry *
128                              dccp_rx_hist_entry_new(struct dccp_rx_hist *hist,
129                                                     const u32 ndp, 
130                                                     const struct sk_buff *skb,
131                                                     const int prio)
132 {
133         struct dccp_rx_hist_entry *entry = kmem_cache_alloc(hist->dccprxh_slab,
134                                                             prio);
135
136         if (entry != NULL) {
137                 const struct dccp_hdr *dh = dccp_hdr(skb);
138
139                 entry->dccphrx_seqno     = DCCP_SKB_CB(skb)->dccpd_seq;
140                 entry->dccphrx_win_count = dh->dccph_ccval;
141                 entry->dccphrx_type      = dh->dccph_type;
142                 entry->dccphrx_ndp       = ndp;
143                 do_gettimeofday(&(entry->dccphrx_tstamp));
144         }
145
146         return entry;
147 }
148
149 static inline void dccp_rx_hist_entry_delete(struct dccp_rx_hist *hist,
150                                              struct dccp_rx_hist_entry *entry)
151 {
152         if (entry != NULL)
153                 kmem_cache_free(hist->dccprxh_slab, entry);
154 }
155
156 extern void dccp_rx_hist_purge(struct dccp_rx_hist *hist,
157                                struct list_head *list);
158
159 static inline void dccp_rx_hist_add_entry(struct list_head *list,
160                                           struct dccp_rx_hist_entry *entry)
161 {
162         list_add(&entry->dccphrx_node, list);
163 }
164
165 static inline struct dccp_rx_hist_entry *dccp_rx_hist_head(struct list_head *list)
166 {
167         struct dccp_rx_hist_entry *head = NULL;
168
169         if (!list_empty(list))
170                 head = list_entry(list->next, struct dccp_rx_hist_entry,
171                                   dccphrx_node);
172         return head;
173 }
174
175 static inline int
176         dccp_rx_hist_entry_data_packet(const struct dccp_rx_hist_entry *entry)
177 {
178         return entry->dccphrx_type == DCCP_PKT_DATA ||
179                entry->dccphrx_type == DCCP_PKT_DATAACK;
180 }
181
182 #endif /* _DCCP_PKT_HIST_ */