xref: /linux/net/core/netevent.c (revision 8be98d2f2a0a262f8bf8a0bc1fdf522b3c7aab17)
12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2792d1932STom Tucker /*
3792d1932STom Tucker  *	Network event notifiers
4792d1932STom Tucker  *
5792d1932STom Tucker  *	Authors:
6792d1932STom Tucker  *      Tom Tucker             <tom@opengridcomputing.com>
7792d1932STom Tucker  *      Steve Wise             <swise@opengridcomputing.com>
8792d1932STom Tucker  *
9792d1932STom Tucker  *	Fixes:
10792d1932STom Tucker  */
11792d1932STom Tucker 
12792d1932STom Tucker #include <linux/rtnetlink.h>
13792d1932STom Tucker #include <linux/notifier.h>
14bc3b2d7fSPaul Gortmaker #include <linux/export.h>
1594b83419SAdrian Bunk #include <net/netevent.h>
16792d1932STom Tucker 
17792d1932STom Tucker static ATOMIC_NOTIFIER_HEAD(netevent_notif_chain);
18792d1932STom Tucker 
19792d1932STom Tucker /**
20792d1932STom Tucker  *	register_netevent_notifier - register a netevent notifier block
21792d1932STom Tucker  *	@nb: notifier
22792d1932STom Tucker  *
23792d1932STom Tucker  *	Register a notifier to be called when a netevent occurs.
24792d1932STom Tucker  *	The notifier passed is linked into the kernel structures and must
25792d1932STom Tucker  *	not be reused until it has been unregistered. A negative errno code
26792d1932STom Tucker  *	is returned on a failure.
27792d1932STom Tucker  */
register_netevent_notifier(struct notifier_block * nb)28792d1932STom Tucker int register_netevent_notifier(struct notifier_block *nb)
29792d1932STom Tucker {
30282c320dSWang Long 	return atomic_notifier_chain_register(&netevent_notif_chain, nb);
31792d1932STom Tucker }
329e34a5b5SEric Dumazet EXPORT_SYMBOL_GPL(register_netevent_notifier);
33792d1932STom Tucker 
34792d1932STom Tucker /**
35*bb2882bcSXiongfeng Wang  *	unregister_netevent_notifier - unregister a netevent notifier block
36792d1932STom Tucker  *	@nb: notifier
37792d1932STom Tucker  *
38792d1932STom Tucker  *	Unregister a notifier previously registered by
39792d1932STom Tucker  *	register_neigh_notifier(). The notifier is unlinked into the
40792d1932STom Tucker  *	kernel structures and may then be reused. A negative errno code
41792d1932STom Tucker  *	is returned on a failure.
42792d1932STom Tucker  */
43792d1932STom Tucker 
unregister_netevent_notifier(struct notifier_block * nb)44792d1932STom Tucker int unregister_netevent_notifier(struct notifier_block *nb)
45792d1932STom Tucker {
46792d1932STom Tucker 	return atomic_notifier_chain_unregister(&netevent_notif_chain, nb);
47792d1932STom Tucker }
489e34a5b5SEric Dumazet EXPORT_SYMBOL_GPL(unregister_netevent_notifier);
49792d1932STom Tucker 
50792d1932STom Tucker /**
51792d1932STom Tucker  *	call_netevent_notifiers - call all netevent notifier blocks
52792d1932STom Tucker  *      @val: value passed unmodified to notifier function
53792d1932STom Tucker  *      @v:   pointer passed unmodified to notifier function
54792d1932STom Tucker  *
55792d1932STom Tucker  *	Call all neighbour notifier blocks.  Parameters and return value
56792d1932STom Tucker  *	are as for notifier_call_chain().
57792d1932STom Tucker  */
58792d1932STom Tucker 
call_netevent_notifiers(unsigned long val,void * v)59792d1932STom Tucker int call_netevent_notifiers(unsigned long val, void *v)
60792d1932STom Tucker {
61792d1932STom Tucker 	return atomic_notifier_call_chain(&netevent_notif_chain, val, v);
62792d1932STom Tucker }
63792d1932STom Tucker EXPORT_SYMBOL_GPL(call_netevent_notifiers);
64