Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Tom Tucker | 792d193 | 2006-07-30 20:43:26 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Network event notifiers |
| 4 | * |
| 5 | * Authors: |
| 6 | * Tom Tucker <tom@opengridcomputing.com> |
| 7 | * Steve Wise <swise@opengridcomputing.com> |
| 8 | * |
Tom Tucker | 792d193 | 2006-07-30 20:43:26 -0700 | [diff] [blame] | 9 | * Fixes: |
| 10 | */ |
| 11 | |
| 12 | #include <linux/rtnetlink.h> |
| 13 | #include <linux/notifier.h> |
Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 14 | #include <linux/export.h> |
Adrian Bunk | 94b8341 | 2007-07-05 17:06:21 -0700 | [diff] [blame] | 15 | #include <net/netevent.h> |
Tom Tucker | 792d193 | 2006-07-30 20:43:26 -0700 | [diff] [blame] | 16 | |
| 17 | static ATOMIC_NOTIFIER_HEAD(netevent_notif_chain); |
| 18 | |
| 19 | /** |
| 20 | * register_netevent_notifier - register a netevent notifier block |
| 21 | * @nb: notifier |
| 22 | * |
| 23 | * Register a notifier to be called when a netevent occurs. |
| 24 | * The notifier passed is linked into the kernel structures and must |
| 25 | * not be reused until it has been unregistered. A negative errno code |
| 26 | * is returned on a failure. |
| 27 | */ |
| 28 | int register_netevent_notifier(struct notifier_block *nb) |
| 29 | { |
Wang Long | 282c320 | 2015-05-29 01:02:08 +0000 | [diff] [blame] | 30 | return atomic_notifier_chain_register(&netevent_notif_chain, nb); |
Tom Tucker | 792d193 | 2006-07-30 20:43:26 -0700 | [diff] [blame] | 31 | } |
Eric Dumazet | 9e34a5b | 2010-07-09 21:22:04 +0000 | [diff] [blame] | 32 | EXPORT_SYMBOL_GPL(register_netevent_notifier); |
Tom Tucker | 792d193 | 2006-07-30 20:43:26 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
Xiongfeng Wang | bb2882b | 2021-03-27 16:15:51 +0800 | [diff] [blame] | 35 | * unregister_netevent_notifier - unregister a netevent notifier block |
Tom Tucker | 792d193 | 2006-07-30 20:43:26 -0700 | [diff] [blame] | 36 | * @nb: notifier |
| 37 | * |
| 38 | * Unregister a notifier previously registered by |
| 39 | * register_neigh_notifier(). The notifier is unlinked into the |
| 40 | * kernel structures and may then be reused. A negative errno code |
| 41 | * is returned on a failure. |
| 42 | */ |
| 43 | |
| 44 | int unregister_netevent_notifier(struct notifier_block *nb) |
| 45 | { |
| 46 | return atomic_notifier_chain_unregister(&netevent_notif_chain, nb); |
| 47 | } |
Eric Dumazet | 9e34a5b | 2010-07-09 21:22:04 +0000 | [diff] [blame] | 48 | EXPORT_SYMBOL_GPL(unregister_netevent_notifier); |
Tom Tucker | 792d193 | 2006-07-30 20:43:26 -0700 | [diff] [blame] | 49 | |
| 50 | /** |
| 51 | * call_netevent_notifiers - call all netevent notifier blocks |
| 52 | * @val: value passed unmodified to notifier function |
| 53 | * @v: pointer passed unmodified to notifier function |
| 54 | * |
| 55 | * Call all neighbour notifier blocks. Parameters and return value |
| 56 | * are as for notifier_call_chain(). |
| 57 | */ |
| 58 | |
| 59 | int call_netevent_notifiers(unsigned long val, void *v) |
| 60 | { |
| 61 | return atomic_notifier_call_chain(&netevent_notif_chain, val, v); |
| 62 | } |
Tom Tucker | 792d193 | 2006-07-30 20:43:26 -0700 | [diff] [blame] | 63 | EXPORT_SYMBOL_GPL(call_netevent_notifiers); |