diff options
author | Arnaldo Carvalho de Melo <acme@mandriva.com> | 2005-08-27 22:18:26 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2005-08-29 19:12:25 -0400 |
commit | 4524b259541e1eea07020af825d8e7b0e4faaec5 (patch) | |
tree | a0aee23c08b3f98f0e96183309afb2d43ca12bd6 /net/dccp/ccids | |
parent | ae6706f0678b89de07ad3b456893cc883584f711 (diff) |
[DCCP]: Just move packet_history.[ch] to net/dccp/ccids/lib/
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/dccp/ccids')
-rw-r--r-- | net/dccp/ccids/Makefile | 2 | ||||
-rw-r--r-- | net/dccp/ccids/ccid3.c | 2 | ||||
-rw-r--r-- | net/dccp/ccids/lib/packet_history.c | 199 | ||||
-rw-r--r-- | net/dccp/ccids/lib/packet_history.h | 185 |
4 files changed, 386 insertions, 2 deletions
diff --git a/net/dccp/ccids/Makefile b/net/dccp/ccids/Makefile index 323b68f3b607..29eb1b61fdbd 100644 --- a/net/dccp/ccids/Makefile +++ b/net/dccp/ccids/Makefile | |||
@@ -1,3 +1,3 @@ | |||
1 | obj-$(CONFIG_IP_DCCP_CCID3) += dccp_ccid3.o | 1 | obj-$(CONFIG_IP_DCCP_CCID3) += dccp_ccid3.o |
2 | 2 | ||
3 | dccp_ccid3-y := ccid3.o lib/loss_interval.o | 3 | dccp_ccid3-y := ccid3.o lib/loss_interval.o lib/packet_history.o |
diff --git a/net/dccp/ccids/ccid3.c b/net/dccp/ccids/ccid3.c index 7468928b83c6..12548fbde86b 100644 --- a/net/dccp/ccids/ccid3.c +++ b/net/dccp/ccids/ccid3.c | |||
@@ -37,7 +37,7 @@ | |||
37 | #include <linux/config.h> | 37 | #include <linux/config.h> |
38 | #include "../ccid.h" | 38 | #include "../ccid.h" |
39 | #include "../dccp.h" | 39 | #include "../dccp.h" |
40 | #include "../packet_history.h" | 40 | #include "lib/packet_history.h" |
41 | #include "lib/loss_interval.h" | 41 | #include "lib/loss_interval.h" |
42 | #include "ccid3.h" | 42 | #include "ccid3.h" |
43 | 43 | ||
diff --git a/net/dccp/ccids/lib/packet_history.c b/net/dccp/ccids/lib/packet_history.c new file mode 100644 index 000000000000..2d9ef5ae0bf6 --- /dev/null +++ b/net/dccp/ccids/lib/packet_history.c | |||
@@ -0,0 +1,199 @@ | |||
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 | #include <linux/config.h> | ||
38 | #include <linux/string.h> | ||
39 | |||
40 | #include "packet_history.h" | ||
41 | |||
42 | struct dccp_rx_hist *dccp_rx_hist_new(const char *name) | ||
43 | { | ||
44 | struct dccp_rx_hist *hist = kmalloc(sizeof(*hist), GFP_ATOMIC); | ||
45 | static const char dccp_rx_hist_mask[] = "rx_hist_%s"; | ||
46 | char *slab_name; | ||
47 | |||
48 | if (hist == NULL) | ||
49 | goto out; | ||
50 | |||
51 | slab_name = kmalloc(strlen(name) + sizeof(dccp_rx_hist_mask) - 1, | ||
52 | GFP_ATOMIC); | ||
53 | if (slab_name == NULL) | ||
54 | goto out_free_hist; | ||
55 | |||
56 | sprintf(slab_name, dccp_rx_hist_mask, name); | ||
57 | hist->dccprxh_slab = kmem_cache_create(slab_name, | ||
58 | sizeof(struct dccp_rx_hist_entry), | ||
59 | 0, SLAB_HWCACHE_ALIGN, | ||
60 | NULL, NULL); | ||
61 | if (hist->dccprxh_slab == NULL) | ||
62 | goto out_free_slab_name; | ||
63 | out: | ||
64 | return hist; | ||
65 | out_free_slab_name: | ||
66 | kfree(slab_name); | ||
67 | out_free_hist: | ||
68 | kfree(hist); | ||
69 | hist = NULL; | ||
70 | goto out; | ||
71 | } | ||
72 | |||
73 | EXPORT_SYMBOL_GPL(dccp_rx_hist_new); | ||
74 | |||
75 | void dccp_rx_hist_delete(struct dccp_rx_hist *hist) | ||
76 | { | ||
77 | const char* name = kmem_cache_name(hist->dccprxh_slab); | ||
78 | |||
79 | kmem_cache_destroy(hist->dccprxh_slab); | ||
80 | kfree(name); | ||
81 | kfree(hist); | ||
82 | } | ||
83 | |||
84 | EXPORT_SYMBOL_GPL(dccp_rx_hist_delete); | ||
85 | |||
86 | void dccp_rx_hist_purge(struct dccp_rx_hist *hist, struct list_head *list) | ||
87 | { | ||
88 | struct dccp_rx_hist_entry *entry, *next; | ||
89 | |||
90 | list_for_each_entry_safe(entry, next, list, dccphrx_node) { | ||
91 | list_del_init(&entry->dccphrx_node); | ||
92 | kmem_cache_free(hist->dccprxh_slab, entry); | ||
93 | } | ||
94 | } | ||
95 | |||
96 | EXPORT_SYMBOL_GPL(dccp_rx_hist_purge); | ||
97 | |||
98 | struct dccp_rx_hist_entry * | ||
99 | dccp_rx_hist_find_data_packet(const struct list_head *list) | ||
100 | { | ||
101 | struct dccp_rx_hist_entry *entry, *packet = NULL; | ||
102 | |||
103 | list_for_each_entry(entry, list, dccphrx_node) | ||
104 | if (entry->dccphrx_type == DCCP_PKT_DATA || | ||
105 | entry->dccphrx_type == DCCP_PKT_DATAACK) { | ||
106 | packet = entry; | ||
107 | break; | ||
108 | } | ||
109 | |||
110 | return packet; | ||
111 | } | ||
112 | |||
113 | EXPORT_SYMBOL_GPL(dccp_rx_hist_find_data_packet); | ||
114 | |||
115 | struct dccp_tx_hist *dccp_tx_hist_new(const char *name) | ||
116 | { | ||
117 | struct dccp_tx_hist *hist = kmalloc(sizeof(*hist), GFP_ATOMIC); | ||
118 | static const char dccp_tx_hist_mask[] = "tx_hist_%s"; | ||
119 | char *slab_name; | ||
120 | |||
121 | if (hist == NULL) | ||
122 | goto out; | ||
123 | |||
124 | slab_name = kmalloc(strlen(name) + sizeof(dccp_tx_hist_mask) - 1, | ||
125 | GFP_ATOMIC); | ||
126 | if (slab_name == NULL) | ||
127 | goto out_free_hist; | ||
128 | |||
129 | sprintf(slab_name, dccp_tx_hist_mask, name); | ||
130 | hist->dccptxh_slab = kmem_cache_create(slab_name, | ||
131 | sizeof(struct dccp_tx_hist_entry), | ||
132 | 0, SLAB_HWCACHE_ALIGN, | ||
133 | NULL, NULL); | ||
134 | if (hist->dccptxh_slab == NULL) | ||
135 | goto out_free_slab_name; | ||
136 | out: | ||
137 | return hist; | ||
138 | out_free_slab_name: | ||
139 | kfree(slab_name); | ||
140 | out_free_hist: | ||
141 | kfree(hist); | ||
142 | hist = NULL; | ||
143 | goto out; | ||
144 | } | ||
145 | |||
146 | EXPORT_SYMBOL_GPL(dccp_tx_hist_new); | ||
147 | |||
148 | void dccp_tx_hist_delete(struct dccp_tx_hist *hist) | ||
149 | { | ||
150 | const char* name = kmem_cache_name(hist->dccptxh_slab); | ||
151 | |||
152 | kmem_cache_destroy(hist->dccptxh_slab); | ||
153 | kfree(name); | ||
154 | kfree(hist); | ||
155 | } | ||
156 | |||
157 | EXPORT_SYMBOL_GPL(dccp_tx_hist_delete); | ||
158 | |||
159 | struct dccp_tx_hist_entry * | ||
160 | dccp_tx_hist_find_entry(const struct list_head *list, const u64 seq) | ||
161 | { | ||
162 | struct dccp_tx_hist_entry *packet = NULL, *entry; | ||
163 | |||
164 | list_for_each_entry(entry, list, dccphtx_node) | ||
165 | if (entry->dccphtx_seqno == seq) { | ||
166 | packet = entry; | ||
167 | break; | ||
168 | } | ||
169 | |||
170 | return packet; | ||
171 | } | ||
172 | |||
173 | EXPORT_SYMBOL_GPL(dccp_tx_hist_find_entry); | ||
174 | |||
175 | void dccp_tx_hist_purge_older(struct dccp_tx_hist *hist, | ||
176 | struct list_head *list, | ||
177 | struct dccp_tx_hist_entry *packet) | ||
178 | { | ||
179 | struct dccp_tx_hist_entry *next; | ||
180 | |||
181 | list_for_each_entry_safe_continue(packet, next, list, dccphtx_node) { | ||
182 | list_del_init(&packet->dccphtx_node); | ||
183 | dccp_tx_hist_entry_delete(hist, packet); | ||
184 | } | ||
185 | } | ||
186 | |||
187 | EXPORT_SYMBOL_GPL(dccp_tx_hist_purge_older); | ||
188 | |||
189 | void dccp_tx_hist_purge(struct dccp_tx_hist *hist, struct list_head *list) | ||
190 | { | ||
191 | struct dccp_tx_hist_entry *entry, *next; | ||
192 | |||
193 | list_for_each_entry_safe(entry, next, list, dccphtx_node) { | ||
194 | list_del_init(&entry->dccphtx_node); | ||
195 | dccp_tx_hist_entry_delete(hist, entry); | ||
196 | } | ||
197 | } | ||
198 | |||
199 | EXPORT_SYMBOL_GPL(dccp_tx_hist_purge); | ||
diff --git a/net/dccp/ccids/lib/packet_history.h b/net/dccp/ccids/lib/packet_history.h new file mode 100644 index 000000000000..235828d822d9 --- /dev/null +++ b/net/dccp/ccids/lib/packet_history.h | |||
@@ -0,0 +1,185 @@ | |||
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_ccval:4, | ||
51 | dccphtx_sent:1; | ||
52 | u32 dccphtx_rtt; | ||
53 | struct timeval dccphtx_tstamp; | ||
54 | }; | ||
55 | |||
56 | struct dccp_rx_hist_entry { | ||
57 | struct list_head dccphrx_node; | ||
58 | u64 dccphrx_seqno:48, | ||
59 | dccphrx_ccval:4, | ||
60 | dccphrx_type:4; | ||
61 | u32 dccphrx_ndp; /* In fact it is from 8 to 24 bits */ | ||
62 | struct timeval dccphrx_tstamp; | ||
63 | }; | ||
64 | |||
65 | struct dccp_tx_hist { | ||
66 | kmem_cache_t *dccptxh_slab; | ||
67 | }; | ||
68 | |||
69 | extern struct dccp_tx_hist *dccp_tx_hist_new(const char *name); | ||
70 | extern void dccp_tx_hist_delete(struct dccp_tx_hist *hist); | ||
71 | |||
72 | struct dccp_rx_hist { | ||
73 | kmem_cache_t *dccprxh_slab; | ||
74 | }; | ||
75 | |||
76 | extern struct dccp_rx_hist *dccp_rx_hist_new(const char *name); | ||
77 | extern void dccp_rx_hist_delete(struct dccp_rx_hist *hist); | ||
78 | extern struct dccp_rx_hist_entry * | ||
79 | dccp_rx_hist_find_data_packet(const struct list_head *list); | ||
80 | |||
81 | static inline struct dccp_tx_hist_entry * | ||
82 | dccp_tx_hist_entry_new(struct dccp_tx_hist *hist, | ||
83 | const unsigned int __nocast prio) | ||
84 | { | ||
85 | struct dccp_tx_hist_entry *entry = kmem_cache_alloc(hist->dccptxh_slab, | ||
86 | prio); | ||
87 | |||
88 | if (entry != NULL) | ||
89 | entry->dccphtx_sent = 0; | ||
90 | |||
91 | return entry; | ||
92 | } | ||
93 | |||
94 | static inline void dccp_tx_hist_entry_delete(struct dccp_tx_hist *hist, | ||
95 | struct dccp_tx_hist_entry *entry) | ||
96 | { | ||
97 | if (entry != NULL) | ||
98 | kmem_cache_free(hist->dccptxh_slab, entry); | ||
99 | } | ||
100 | |||
101 | extern struct dccp_tx_hist_entry * | ||
102 | dccp_tx_hist_find_entry(const struct list_head *list, | ||
103 | const u64 seq); | ||
104 | |||
105 | static inline void dccp_tx_hist_add_entry(struct list_head *list, | ||
106 | struct dccp_tx_hist_entry *entry) | ||
107 | { | ||
108 | list_add(&entry->dccphtx_node, list); | ||
109 | } | ||
110 | |||
111 | extern void dccp_tx_hist_purge_older(struct dccp_tx_hist *hist, | ||
112 | struct list_head *list, | ||
113 | struct dccp_tx_hist_entry *next); | ||
114 | |||
115 | extern void dccp_tx_hist_purge(struct dccp_tx_hist *hist, | ||
116 | struct list_head *list); | ||
117 | |||
118 | static inline struct dccp_tx_hist_entry * | ||
119 | dccp_tx_hist_head(struct list_head *list) | ||
120 | { | ||
121 | struct dccp_tx_hist_entry *head = NULL; | ||
122 | |||
123 | if (!list_empty(list)) | ||
124 | head = list_entry(list->next, struct dccp_tx_hist_entry, | ||
125 | dccphtx_node); | ||
126 | return head; | ||
127 | } | ||
128 | |||
129 | static inline struct dccp_rx_hist_entry * | ||
130 | dccp_rx_hist_entry_new(struct dccp_rx_hist *hist, | ||
131 | const u32 ndp, | ||
132 | const struct sk_buff *skb, | ||
133 | const unsigned int __nocast prio) | ||
134 | { | ||
135 | struct dccp_rx_hist_entry *entry = kmem_cache_alloc(hist->dccprxh_slab, | ||
136 | prio); | ||
137 | |||
138 | if (entry != NULL) { | ||
139 | const struct dccp_hdr *dh = dccp_hdr(skb); | ||
140 | |||
141 | entry->dccphrx_seqno = DCCP_SKB_CB(skb)->dccpd_seq; | ||
142 | entry->dccphrx_ccval = dh->dccph_ccval; | ||
143 | entry->dccphrx_type = dh->dccph_type; | ||
144 | entry->dccphrx_ndp = ndp; | ||
145 | do_gettimeofday(&(entry->dccphrx_tstamp)); | ||
146 | } | ||
147 | |||
148 | return entry; | ||
149 | } | ||
150 | |||
151 | static inline void dccp_rx_hist_entry_delete(struct dccp_rx_hist *hist, | ||
152 | struct dccp_rx_hist_entry *entry) | ||
153 | { | ||
154 | if (entry != NULL) | ||
155 | kmem_cache_free(hist->dccprxh_slab, entry); | ||
156 | } | ||
157 | |||
158 | extern void dccp_rx_hist_purge(struct dccp_rx_hist *hist, | ||
159 | struct list_head *list); | ||
160 | |||
161 | static inline void dccp_rx_hist_add_entry(struct list_head *list, | ||
162 | struct dccp_rx_hist_entry *entry) | ||
163 | { | ||
164 | list_add(&entry->dccphrx_node, list); | ||
165 | } | ||
166 | |||
167 | static inline struct dccp_rx_hist_entry * | ||
168 | dccp_rx_hist_head(struct list_head *list) | ||
169 | { | ||
170 | struct dccp_rx_hist_entry *head = NULL; | ||
171 | |||
172 | if (!list_empty(list)) | ||
173 | head = list_entry(list->next, struct dccp_rx_hist_entry, | ||
174 | dccphrx_node); | ||
175 | return head; | ||
176 | } | ||
177 | |||
178 | static inline int | ||
179 | dccp_rx_hist_entry_data_packet(const struct dccp_rx_hist_entry *entry) | ||
180 | { | ||
181 | return entry->dccphrx_type == DCCP_PKT_DATA || | ||
182 | entry->dccphrx_type == DCCP_PKT_DATAACK; | ||
183 | } | ||
184 | |||
185 | #endif /* _DCCP_PKT_HIST_ */ | ||