Skip to content

Commit

Permalink
[RTNETLINK]: Send a single notification on device state changes.
Browse files Browse the repository at this point in the history
In do_setlink() a single notification is sent at the end of the
function if any modification occured. If the address has been changed,
another notification is sent.

Both of them is required because originally only the NETDEV_CHANGEADDR
notification was sent and although device state change implies address
change, some programs may expect the original notification. It remains
for compatibity.

If set_operstate() is called from do_setlink(), it doesn't send a
notification, only if it is called from rtnl_create_link() as earlier.

Signed-off-by: Laszlo Attila Toth <panther@balabit.hu>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Laszlo Attila Toth authored and David S. Miller committed Feb 13, 2008
1 parent 370125f commit 45b5035
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions net/core/rtnetlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ int rtnl_put_cacheinfo(struct sk_buff *skb, struct dst_entry *dst, u32 id,

EXPORT_SYMBOL_GPL(rtnl_put_cacheinfo);

static void set_operstate(struct net_device *dev, unsigned char transition)
static int set_operstate(struct net_device *dev, unsigned char transition, bool send_notification)
{
unsigned char operstate = dev->operstate;

Expand All @@ -527,8 +527,12 @@ static void set_operstate(struct net_device *dev, unsigned char transition)
write_lock_bh(&dev_base_lock);
dev->operstate = operstate;
write_unlock_bh(&dev_base_lock);
netdev_state_change(dev);
}

if (send_notification)
netdev_state_change(dev);
return 1;
} else
return 0;
}

static void copy_rtnl_link_stats(struct rtnl_link_stats *a,
Expand Down Expand Up @@ -822,6 +826,7 @@ static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm,
if (tb[IFLA_BROADCAST]) {
nla_memcpy(dev->broadcast, tb[IFLA_BROADCAST], dev->addr_len);
send_addr_notify = 1;
modified = 1;
}

if (ifm->ifi_flags || ifm->ifi_change) {
Expand All @@ -834,16 +839,23 @@ static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm,
dev_change_flags(dev, flags);
}

if (tb[IFLA_TXQLEN])
dev->tx_queue_len = nla_get_u32(tb[IFLA_TXQLEN]);
if (tb[IFLA_TXQLEN]) {
if (dev->tx_queue_len != nla_get_u32(tb[IFLA_TXQLEN])) {
dev->tx_queue_len = nla_get_u32(tb[IFLA_TXQLEN]);
modified = 1;
}
}

if (tb[IFLA_OPERSTATE])
set_operstate(dev, nla_get_u8(tb[IFLA_OPERSTATE]));
modified |= set_operstate(dev, nla_get_u8(tb[IFLA_OPERSTATE]), false);

if (tb[IFLA_LINKMODE]) {
write_lock_bh(&dev_base_lock);
dev->link_mode = nla_get_u8(tb[IFLA_LINKMODE]);
write_unlock_bh(&dev_base_lock);
if (dev->link_mode != nla_get_u8(tb[IFLA_LINKMODE])) {
write_lock_bh(&dev_base_lock);
dev->link_mode = nla_get_u8(tb[IFLA_LINKMODE]);
write_lock_bh(&dev_base_lock);
modified = 1;
}
}

err = 0;
Expand All @@ -857,6 +869,10 @@ static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm,

if (send_addr_notify)
call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);

if (modified)
netdev_state_change(dev);

return err;
}

Expand Down Expand Up @@ -974,7 +990,7 @@ struct net_device *rtnl_create_link(struct net *net, char *ifname,
if (tb[IFLA_TXQLEN])
dev->tx_queue_len = nla_get_u32(tb[IFLA_TXQLEN]);
if (tb[IFLA_OPERSTATE])
set_operstate(dev, nla_get_u8(tb[IFLA_OPERSTATE]));
set_operstate(dev, nla_get_u8(tb[IFLA_OPERSTATE]), true);
if (tb[IFLA_LINKMODE])
dev->link_mode = nla_get_u8(tb[IFLA_LINKMODE]);

Expand Down

0 comments on commit 45b5035

Please sign in to comment.