aboutsummaryrefslogtreecommitdiffstats
path: root/net/dccp/ccid.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/dccp/ccid.c')
-rw-r--r--net/dccp/ccid.c101
1 files changed, 24 insertions, 77 deletions
diff --git a/net/dccp/ccid.c b/net/dccp/ccid.c
index e3fb52b4f5c6..4809753d12ae 100644
--- a/net/dccp/ccid.c
+++ b/net/dccp/ccid.c
@@ -13,13 +13,6 @@
13 13
14#include "ccid.h" 14#include "ccid.h"
15 15
16static u8 builtin_ccids[] = {
17 DCCPC_CCID2, /* CCID2 is supported by default */
18#if defined(CONFIG_IP_DCCP_CCID3) || defined(CONFIG_IP_DCCP_CCID3_MODULE)
19 DCCPC_CCID3,
20#endif
21};
22
23static struct ccid_operations *ccids[CCID_MAX]; 16static struct ccid_operations *ccids[CCID_MAX];
24#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT) 17#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT)
25static atomic_t ccids_lockct = ATOMIC_INIT(0); 18static atomic_t ccids_lockct = ATOMIC_INIT(0);
@@ -93,47 +86,6 @@ static void ccid_kmem_cache_destroy(struct kmem_cache *slab)
93 } 86 }
94} 87}
95 88
96/* check that up to @array_len members in @ccid_array are supported */
97bool ccid_support_check(u8 const *ccid_array, u8 array_len)
98{
99 u8 i, j, found;
100
101 for (i = 0, found = 0; i < array_len; i++, found = 0) {
102 for (j = 0; !found && j < ARRAY_SIZE(builtin_ccids); j++)
103 found = (ccid_array[i] == builtin_ccids[j]);
104 if (!found)
105 return false;
106 }
107 return true;
108}
109
110/**
111 * ccid_get_builtin_ccids - Provide copy of `builtin' CCID array
112 * @ccid_array: pointer to copy into
113 * @array_len: value to return length into
114 * This function allocates memory - caller must see that it is freed after use.
115 */
116int ccid_get_builtin_ccids(u8 **ccid_array, u8 *array_len)
117{
118 *ccid_array = kmemdup(builtin_ccids, sizeof(builtin_ccids), gfp_any());
119 if (*ccid_array == NULL)
120 return -ENOBUFS;
121 *array_len = ARRAY_SIZE(builtin_ccids);
122 return 0;
123}
124
125int ccid_getsockopt_builtin_ccids(struct sock *sk, int len,
126 char __user *optval, int __user *optlen)
127{
128 if (len < sizeof(builtin_ccids))
129 return -EINVAL;
130
131 if (put_user(sizeof(builtin_ccids), optlen) ||
132 copy_to_user(optval, builtin_ccids, sizeof(builtin_ccids)))
133 return -EFAULT;
134 return 0;
135}
136
137int ccid_register(struct ccid_operations *ccid_ops) 89int ccid_register(struct ccid_operations *ccid_ops)
138{ 90{
139 int err = -ENOBUFS; 91 int err = -ENOBUFS;
@@ -196,41 +148,22 @@ int ccid_unregister(struct ccid_operations *ccid_ops)
196 148
197EXPORT_SYMBOL_GPL(ccid_unregister); 149EXPORT_SYMBOL_GPL(ccid_unregister);
198 150
199/**
200 * ccid_request_module - Pre-load CCID module for later use
201 * This should be called only from process context (e.g. during connection
202 * setup) and is necessary for later calls to ccid_new (typically in software
203 * interrupt), so that it has the modules available when they are needed.
204 */
205static int ccid_request_module(u8 id)
206{
207 if (!in_atomic()) {
208 ccids_read_lock();
209 if (ccids[id] == NULL) {
210 ccids_read_unlock();
211 return request_module("net-dccp-ccid-%d", id);
212 }
213 ccids_read_unlock();
214 }
215 return 0;
216}
217
218int ccid_request_modules(u8 const *ccid_array, u8 array_len)
219{
220#ifdef CONFIG_KMOD
221 while (array_len--)
222 if (ccid_request_module(ccid_array[array_len]))
223 return -1;
224#endif
225 return 0;
226}
227
228struct ccid *ccid_new(unsigned char id, struct sock *sk, int rx, gfp_t gfp) 151struct ccid *ccid_new(unsigned char id, struct sock *sk, int rx, gfp_t gfp)
229{ 152{
230 struct ccid_operations *ccid_ops; 153 struct ccid_operations *ccid_ops;
231 struct ccid *ccid = NULL; 154 struct ccid *ccid = NULL;
232 155
233 ccids_read_lock(); 156 ccids_read_lock();
157#ifdef CONFIG_KMOD
158 if (ccids[id] == NULL) {
159 /* We only try to load if in process context */
160 ccids_read_unlock();
161 if (gfp & GFP_ATOMIC)
162 goto out;
163 request_module("net-dccp-ccid-%d", id);
164 ccids_read_lock();
165 }
166#endif
234 ccid_ops = ccids[id]; 167 ccid_ops = ccids[id];
235 if (ccid_ops == NULL) 168 if (ccid_ops == NULL)
236 goto out_unlock; 169 goto out_unlock;
@@ -272,6 +205,20 @@ out_module_put:
272 205
273EXPORT_SYMBOL_GPL(ccid_new); 206EXPORT_SYMBOL_GPL(ccid_new);
274 207
208struct ccid *ccid_hc_rx_new(unsigned char id, struct sock *sk, gfp_t gfp)
209{
210 return ccid_new(id, sk, 1, gfp);
211}
212
213EXPORT_SYMBOL_GPL(ccid_hc_rx_new);
214
215struct ccid *ccid_hc_tx_new(unsigned char id,struct sock *sk, gfp_t gfp)
216{
217 return ccid_new(id, sk, 0, gfp);
218}
219
220EXPORT_SYMBOL_GPL(ccid_hc_tx_new);
221
275static void ccid_delete(struct ccid *ccid, struct sock *sk, int rx) 222static void ccid_delete(struct ccid *ccid, struct sock *sk, int rx)
276{ 223{
277 struct ccid_operations *ccid_ops; 224 struct ccid_operations *ccid_ops;