net: introduce pre-up netdev notifier
authorJohannes Berg <johannes@sipsolutions.net>
Fri, 29 May 2009 23:39:53 +0000 (01:39 +0200)
committerJohn W. Linville <linville@tuxdriver.com>
Wed, 3 Jun 2009 18:05:12 +0000 (14:05 -0400)
NETDEV_UP is called after the device is set UP, but sometimes
it is useful to be able to veto the device UP. Introduce a
new NETDEV_PRE_UP notifier that can be used for exactly this.
The first use case will be cfg80211 denying interfaces to be
set UP if the device is known to be rfkill'ed.

Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Acked-by: David S. Miller <davem@davemloft.net>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
include/linux/notifier.h
net/core/dev.c

index b86fa2f..81bc252 100644 (file)
@@ -198,6 +198,7 @@ static inline int notifier_to_errno(int ret)
 #define NETDEV_CHANGENAME      0x000A
 #define NETDEV_FEAT_CHANGE     0x000B
 #define NETDEV_BONDING_FAILOVER 0x000C
+#define NETDEV_PRE_UP          0x000D
 
 #define SYS_DOWN       0x0001  /* Notify of system down */
 #define SYS_RESTART    SYS_DOWN
index 34b49a6..1f38401 100644 (file)
@@ -1048,7 +1048,7 @@ void dev_load(struct net *net, const char *name)
 int dev_open(struct net_device *dev)
 {
        const struct net_device_ops *ops = dev->netdev_ops;
-       int ret = 0;
+       int ret;
 
        ASSERT_RTNL();
 
@@ -1065,6 +1065,11 @@ int dev_open(struct net_device *dev)
        if (!netif_device_present(dev))
                return -ENODEV;
 
+       ret = call_netdevice_notifiers(NETDEV_PRE_UP, dev);
+       ret = notifier_to_errno(ret);
+       if (ret)
+               return ret;
+
        /*
         *      Call device private open method
         */