LinuxKPI: netdevice notifier callback argument

Introduce struct netdev_notifier_info as a container to pass
net_device to the callback functions.
Adjust netdev_notifier_info_to_dev() to return the net_device field.

Add explicit casts from ifp to ni->dev even though currently
struct net_device is defined to struct ifnet.  This is needed in
preparation for untangling this and improving the net_device compat
code.

Obtained-from:	bz_iwlwifi
Sponsored-by:	The FreeBSD Foundation
MFC-after:	2 weeks
Reviewed-by:	hselasky
Differential Revision:	https://reviews.freebsd.org/D29365
This commit is contained in:
Bjoern A. Zeeb 2021-03-21 21:18:34 +00:00
parent bc042266b2
commit fdcfe8a298
2 changed files with 32 additions and 17 deletions

View File

@ -88,17 +88,6 @@ netdev_priv(const struct net_device *dev)
return (dev->if_softc);
}
static inline struct net_device *
netdev_notifier_info_to_dev(void *ifp)
{
return (ifp);
}
int register_netdevice_notifier(struct notifier_block *);
int register_inetaddr_notifier(struct notifier_block *);
int unregister_netdevice_notifier(struct notifier_block *);
int unregister_inetaddr_notifier(struct notifier_block *);
#define rtnl_lock()
#define rtnl_unlock()
@ -140,4 +129,20 @@ dev_mc_add(struct net_device *dev, void *addr, int alen, int newonly)
return -if_addmulti(dev, (struct sockaddr *)&sdl, NULL);
}
/* According to linux::ipoib_main.c. */
struct netdev_notifier_info {
struct net_device *dev;
};
static inline struct net_device *
netdev_notifier_info_to_dev(struct netdev_notifier_info *ni)
{
return (ni->dev);
}
int register_netdevice_notifier(struct notifier_block *);
int register_inetaddr_notifier(struct notifier_block *);
int unregister_netdevice_notifier(struct notifier_block *);
int unregister_inetaddr_notifier(struct notifier_block *);
#endif /* _LINUX_NETDEVICE_H_ */

View File

@ -2256,48 +2256,58 @@ static void
linux_handle_ifnet_link_event(void *arg, struct ifnet *ifp, int linkstate)
{
struct notifier_block *nb;
struct netdev_notifier_info ni;
nb = arg;
ni.dev = (struct net_device *)ifp;
if (linkstate == LINK_STATE_UP)
nb->notifier_call(nb, NETDEV_UP, ifp);
nb->notifier_call(nb, NETDEV_UP, &ni);
else
nb->notifier_call(nb, NETDEV_DOWN, ifp);
nb->notifier_call(nb, NETDEV_DOWN, &ni);
}
static void
linux_handle_ifnet_arrival_event(void *arg, struct ifnet *ifp)
{
struct notifier_block *nb;
struct netdev_notifier_info ni;
nb = arg;
nb->notifier_call(nb, NETDEV_REGISTER, ifp);
ni.dev = (struct net_device *)ifp;
nb->notifier_call(nb, NETDEV_REGISTER, &ni);
}
static void
linux_handle_ifnet_departure_event(void *arg, struct ifnet *ifp)
{
struct notifier_block *nb;
struct netdev_notifier_info ni;
nb = arg;
nb->notifier_call(nb, NETDEV_UNREGISTER, ifp);
ni.dev = (struct net_device *)ifp;
nb->notifier_call(nb, NETDEV_UNREGISTER, &ni);
}
static void
linux_handle_iflladdr_event(void *arg, struct ifnet *ifp)
{
struct notifier_block *nb;
struct netdev_notifier_info ni;
nb = arg;
nb->notifier_call(nb, NETDEV_CHANGEADDR, ifp);
ni.dev = (struct net_device *)ifp;
nb->notifier_call(nb, NETDEV_CHANGEADDR, &ni);
}
static void
linux_handle_ifaddr_event(void *arg, struct ifnet *ifp)
{
struct notifier_block *nb;
struct netdev_notifier_info ni;
nb = arg;
nb->notifier_call(nb, NETDEV_CHANGEIFADDR, ifp);
ni.dev = (struct net_device *)ifp;
nb->notifier_call(nb, NETDEV_CHANGEIFADDR, &ni);
}
int