git: 0bb237770e36 - stable/13 - LinuxKPI: netdevice notifier callback argument

Bjoern A. Zeeb bz at FreeBSD.org
Sun Jul 18 00:36:03 UTC 2021


The branch stable/13 has been updated by bz:

URL: https://cgit.FreeBSD.org/src/commit/?id=0bb237770e36d93d7f23c22f61d3acb8e37dba43

commit 0bb237770e36d93d7f23c22f61d3acb8e37dba43
Author:     Bjoern A. Zeeb <bz at FreeBSD.org>
AuthorDate: 2021-03-21 21:18:34 +0000
Commit:     Bjoern A. Zeeb <bz at FreeBSD.org>
CommitDate: 2021-07-18 00:34:59 +0000

    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.
    
    Sponsored by:   The FreeBSD Foundation
    Reviewed by:    hselasky
    Differential Revision:  https://reviews.freebsd.org/D29365
    
    (cherry picked from commit fdcfe8a298e23bef9588cafad2672e0c5f48a327)
---
 .../linuxkpi/common/include/linux/netdevice.h      | 27 +++++++++++++---------
 sys/compat/linuxkpi/common/src/linux_compat.c      | 22 +++++++++++++-----
 2 files changed, 32 insertions(+), 17 deletions(-)

diff --git a/sys/compat/linuxkpi/common/include/linux/netdevice.h b/sys/compat/linuxkpi/common/include/linux/netdevice.h
index 336215b9f7c5..9ec76d9b90ef 100644
--- a/sys/compat/linuxkpi/common/include/linux/netdevice.h
+++ b/sys/compat/linuxkpi/common/include/linux/netdevice.h
@@ -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_ */
diff --git a/sys/compat/linuxkpi/common/src/linux_compat.c b/sys/compat/linuxkpi/common/src/linux_compat.c
index 9dfa5446e0cc..a8f090ed0bd5 100644
--- a/sys/compat/linuxkpi/common/src/linux_compat.c
+++ b/sys/compat/linuxkpi/common/src/linux_compat.c
@@ -2310,48 +2310,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


More information about the dev-commits-src-all mailing list