18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Network event notifiers 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Authors: 68c2ecf20Sopenharmony_ci * Tom Tucker <tom@opengridcomputing.com> 78c2ecf20Sopenharmony_ci * Steve Wise <swise@opengridcomputing.com> 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * Fixes: 108c2ecf20Sopenharmony_ci */ 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#include <linux/rtnetlink.h> 138c2ecf20Sopenharmony_ci#include <linux/notifier.h> 148c2ecf20Sopenharmony_ci#include <linux/export.h> 158c2ecf20Sopenharmony_ci#include <net/netevent.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_cistatic ATOMIC_NOTIFIER_HEAD(netevent_notif_chain); 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci/** 208c2ecf20Sopenharmony_ci * register_netevent_notifier - register a netevent notifier block 218c2ecf20Sopenharmony_ci * @nb: notifier 228c2ecf20Sopenharmony_ci * 238c2ecf20Sopenharmony_ci * Register a notifier to be called when a netevent occurs. 248c2ecf20Sopenharmony_ci * The notifier passed is linked into the kernel structures and must 258c2ecf20Sopenharmony_ci * not be reused until it has been unregistered. A negative errno code 268c2ecf20Sopenharmony_ci * is returned on a failure. 278c2ecf20Sopenharmony_ci */ 288c2ecf20Sopenharmony_ciint register_netevent_notifier(struct notifier_block *nb) 298c2ecf20Sopenharmony_ci{ 308c2ecf20Sopenharmony_ci return atomic_notifier_chain_register(&netevent_notif_chain, nb); 318c2ecf20Sopenharmony_ci} 328c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(register_netevent_notifier); 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci/** 358c2ecf20Sopenharmony_ci * netevent_unregister_notifier - unregister a netevent notifier block 368c2ecf20Sopenharmony_ci * @nb: notifier 378c2ecf20Sopenharmony_ci * 388c2ecf20Sopenharmony_ci * Unregister a notifier previously registered by 398c2ecf20Sopenharmony_ci * register_neigh_notifier(). The notifier is unlinked into the 408c2ecf20Sopenharmony_ci * kernel structures and may then be reused. A negative errno code 418c2ecf20Sopenharmony_ci * is returned on a failure. 428c2ecf20Sopenharmony_ci */ 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ciint unregister_netevent_notifier(struct notifier_block *nb) 458c2ecf20Sopenharmony_ci{ 468c2ecf20Sopenharmony_ci return atomic_notifier_chain_unregister(&netevent_notif_chain, nb); 478c2ecf20Sopenharmony_ci} 488c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(unregister_netevent_notifier); 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci/** 518c2ecf20Sopenharmony_ci * call_netevent_notifiers - call all netevent notifier blocks 528c2ecf20Sopenharmony_ci * @val: value passed unmodified to notifier function 538c2ecf20Sopenharmony_ci * @v: pointer passed unmodified to notifier function 548c2ecf20Sopenharmony_ci * 558c2ecf20Sopenharmony_ci * Call all neighbour notifier blocks. Parameters and return value 568c2ecf20Sopenharmony_ci * are as for notifier_call_chain(). 578c2ecf20Sopenharmony_ci */ 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ciint call_netevent_notifiers(unsigned long val, void *v) 608c2ecf20Sopenharmony_ci{ 618c2ecf20Sopenharmony_ci return atomic_notifier_call_chain(&netevent_notif_chain, val, v); 628c2ecf20Sopenharmony_ci} 638c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(call_netevent_notifiers); 64