aboutsummaryrefslogtreecommitdiffstats
path: root/net/core/utils.c
diff options
context:
space:
mode:
authorHannes Frederic Sowa <hannes@stressinduktion.org>2015-10-07 19:20:35 -0400
committerDavid S. Miller <davem@davemloft.net>2015-10-08 08:26:35 -0400
commit46234253b9363894a254844a6550b4cc5f3edfe8 (patch)
treeab3b795f7ff1765d2f7dbb318b5fae08945a0bdf /net/core/utils.c
parent28335a7445202a3d118145a07d9138e9881ebe18 (diff)
net: move net_get_random_once to lib
There's no good reason why users outside of networking should not be using this facility, f.e. for initializing their seeds. Therefore, make it accessible from there as get_random_once(). Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core/utils.c')
-rw-r--r--net/core/utils.c49
1 files changed, 0 insertions, 49 deletions
diff --git a/net/core/utils.c b/net/core/utils.c
index 3dffce953c39..3d17ca8b4744 100644
--- a/net/core/utils.c
+++ b/net/core/utils.c
@@ -348,52 +348,3 @@ void inet_proto_csum_replace_by_diff(__sum16 *sum, struct sk_buff *skb,
348 } 348 }
349} 349}
350EXPORT_SYMBOL(inet_proto_csum_replace_by_diff); 350EXPORT_SYMBOL(inet_proto_csum_replace_by_diff);
351
352struct __net_random_once_work {
353 struct work_struct work;
354 struct static_key *key;
355};
356
357static void __net_random_once_deferred(struct work_struct *w)
358{
359 struct __net_random_once_work *work =
360 container_of(w, struct __net_random_once_work, work);
361 BUG_ON(!static_key_enabled(work->key));
362 static_key_slow_dec(work->key);
363 kfree(work);
364}
365
366static void __net_random_once_disable_jump(struct static_key *key)
367{
368 struct __net_random_once_work *w;
369
370 w = kmalloc(sizeof(*w), GFP_ATOMIC);
371 if (!w)
372 return;
373
374 INIT_WORK(&w->work, __net_random_once_deferred);
375 w->key = key;
376 schedule_work(&w->work);
377}
378
379bool __net_get_random_once(void *buf, int nbytes, bool *done,
380 struct static_key *once_key)
381{
382 static DEFINE_SPINLOCK(lock);
383 unsigned long flags;
384
385 spin_lock_irqsave(&lock, flags);
386 if (*done) {
387 spin_unlock_irqrestore(&lock, flags);
388 return false;
389 }
390
391 get_random_bytes(buf, nbytes);
392 *done = true;
393 spin_unlock_irqrestore(&lock, flags);
394
395 __net_random_once_disable_jump(once_key);
396
397 return true;
398}
399EXPORT_SYMBOL(__net_get_random_once);