Skip to content

Commit

Permalink
Merge branch 'netdev_modified'
Browse files Browse the repository at this point in the history
Nicolas Dichtel says:

====================
rtnl: send notification in do_setlink()

This series ensures to call the notifier chain and to send a netlink
message when a change is done by do_setlink().

The three first patches mainly prepare the last one, which do this change.
====================

Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
davem330 committed Sep 2, 2014
2 parents 219c536 + ba99890 commit 29fea20
Showing 1 changed file with 42 additions and 24 deletions.
66 changes: 42 additions & 24 deletions net/core/rtnetlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -1481,9 +1481,12 @@ static int do_set_master(struct net_device *dev, int ifindex)
return 0;
}

#define DO_SETLINK_MODIFIED 0x01
/* notify flag means notify + modified. */
#define DO_SETLINK_NOTIFY 0x03
static int do_setlink(const struct sk_buff *skb,
struct net_device *dev, struct ifinfomsg *ifm,
struct nlattr **tb, char *ifname, int modified)
struct nlattr **tb, char *ifname, int status)
{
const struct net_device_ops *ops = dev->netdev_ops;
int err;
Expand All @@ -1502,7 +1505,7 @@ static int do_setlink(const struct sk_buff *skb,
put_net(net);
if (err)
goto errout;
modified = 1;
status |= DO_SETLINK_MODIFIED;
}

if (tb[IFLA_MAP]) {
Expand Down Expand Up @@ -1531,7 +1534,7 @@ static int do_setlink(const struct sk_buff *skb,
if (err < 0)
goto errout;

modified = 1;
status |= DO_SETLINK_NOTIFY;
}

if (tb[IFLA_ADDRESS]) {
Expand All @@ -1551,19 +1554,19 @@ static int do_setlink(const struct sk_buff *skb,
kfree(sa);
if (err)
goto errout;
modified = 1;
status |= DO_SETLINK_MODIFIED;
}

if (tb[IFLA_MTU]) {
err = dev_set_mtu(dev, nla_get_u32(tb[IFLA_MTU]));
if (err < 0)
goto errout;
modified = 1;
status |= DO_SETLINK_MODIFIED;
}

if (tb[IFLA_GROUP]) {
dev_set_group(dev, nla_get_u32(tb[IFLA_GROUP]));
modified = 1;
status |= DO_SETLINK_NOTIFY;
}

/*
Expand All @@ -1575,15 +1578,15 @@ static int do_setlink(const struct sk_buff *skb,
err = dev_change_name(dev, ifname);
if (err < 0)
goto errout;
modified = 1;
status |= DO_SETLINK_MODIFIED;
}

if (tb[IFLA_IFALIAS]) {
err = dev_set_alias(dev, nla_data(tb[IFLA_IFALIAS]),
nla_len(tb[IFLA_IFALIAS]));
if (err < 0)
goto errout;
modified = 1;
status |= DO_SETLINK_NOTIFY;
}

if (tb[IFLA_BROADCAST]) {
Expand All @@ -1601,25 +1604,35 @@ static int do_setlink(const struct sk_buff *skb,
err = do_set_master(dev, nla_get_u32(tb[IFLA_MASTER]));
if (err)
goto errout;
modified = 1;
status |= DO_SETLINK_MODIFIED;
}

if (tb[IFLA_CARRIER]) {
err = dev_change_carrier(dev, nla_get_u8(tb[IFLA_CARRIER]));
if (err)
goto errout;
modified = 1;
status |= DO_SETLINK_MODIFIED;
}

if (tb[IFLA_TXQLEN])
dev->tx_queue_len = nla_get_u32(tb[IFLA_TXQLEN]);
if (tb[IFLA_TXQLEN]) {
unsigned long value = nla_get_u32(tb[IFLA_TXQLEN]);

if (dev->tx_queue_len ^ value)
status |= DO_SETLINK_NOTIFY;

dev->tx_queue_len = value;
}

if (tb[IFLA_OPERSTATE])
set_operstate(dev, nla_get_u8(tb[IFLA_OPERSTATE]));

if (tb[IFLA_LINKMODE]) {
unsigned char value = nla_get_u8(tb[IFLA_LINKMODE]);

write_lock_bh(&dev_base_lock);
dev->link_mode = nla_get_u8(tb[IFLA_LINKMODE]);
if (dev->link_mode ^ value)
status |= DO_SETLINK_NOTIFY;
dev->link_mode = value;
write_unlock_bh(&dev_base_lock);
}

Expand All @@ -1634,7 +1647,7 @@ static int do_setlink(const struct sk_buff *skb,
err = do_setvfinfo(dev, attr);
if (err < 0)
goto errout;
modified = 1;
status |= DO_SETLINK_NOTIFY;
}
}
err = 0;
Expand Down Expand Up @@ -1664,7 +1677,7 @@ static int do_setlink(const struct sk_buff *skb,
err = ops->ndo_set_vf_port(dev, vf, port);
if (err < 0)
goto errout;
modified = 1;
status |= DO_SETLINK_NOTIFY;
}
}
err = 0;
Expand All @@ -1682,7 +1695,7 @@ static int do_setlink(const struct sk_buff *skb,
err = ops->ndo_set_vf_port(dev, PORT_SELF_VF, port);
if (err < 0)
goto errout;
modified = 1;
status |= DO_SETLINK_NOTIFY;
}

if (tb[IFLA_AF_SPEC]) {
Expand All @@ -1699,15 +1712,20 @@ static int do_setlink(const struct sk_buff *skb,
if (err < 0)
goto errout;

modified = 1;
status |= DO_SETLINK_NOTIFY;
}
}
err = 0;

errout:
if (err < 0 && modified)
net_warn_ratelimited("A link change request failed with some changes committed already. Interface %s may have been left with an inconsistent configuration, please check.\n",
dev->name);
if (status & DO_SETLINK_MODIFIED) {
if (status & DO_SETLINK_NOTIFY)
netdev_state_change(dev);

if (err < 0)
net_warn_ratelimited("A link change request failed with some changes committed already. Interface %s may have been left with an inconsistent configuration, please check.\n",
dev->name);
}

return err;
}
Expand Down Expand Up @@ -1989,7 +2007,7 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh)
}

if (dev) {
int modified = 0;
int status = 0;

if (nlh->nlmsg_flags & NLM_F_EXCL)
return -EEXIST;
Expand All @@ -2004,7 +2022,7 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh)
err = ops->changelink(dev, tb, data);
if (err < 0)
return err;
modified = 1;
status |= DO_SETLINK_NOTIFY;
}

if (linkinfo[IFLA_INFO_SLAVE_DATA]) {
Expand All @@ -2015,10 +2033,10 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh)
tb, slave_data);
if (err < 0)
return err;
modified = 1;
status |= DO_SETLINK_NOTIFY;
}

return do_setlink(skb, dev, ifm, tb, ifname, modified);
return do_setlink(skb, dev, ifm, tb, ifname, status);
}

if (!(nlh->nlmsg_flags & NLM_F_CREATE)) {
Expand Down

0 comments on commit 29fea20

Please sign in to comment.