net: vrf: Add extack messages for newlink failures
authorDavid Ahern <dsahern@gmail.com>
Mon, 7 Aug 2017 17:08:10 +0000 (10:08 -0700)
committerDavid S. Miller <davem@davemloft.net>
Mon, 7 Aug 2017 22:16:33 +0000 (15:16 -0700)
Add extack error messages for failure paths creating vrf devices. Once
extack support is added to iproute2, we go from the unhelpful:
    $  ip li add foobar type vrf
    RTNETLINK answers: Invalid argument

to:
    $ ip li add foobar type vrf
    Error: VRF table id is missing

Signed-off-by: David Ahern <dsahern@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/vrf.c

index 8a1eaf3c302a6d68b7a03356bf418e90dca215e7..abd2010c48aecad957076da29dea1022216c1f54 100644 (file)
@@ -1371,10 +1371,14 @@ static int vrf_validate(struct nlattr *tb[], struct nlattr *data[],
                        struct netlink_ext_ack *extack)
 {
        if (tb[IFLA_ADDRESS]) {
-               if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN)
+               if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN) {
+                       NL_SET_ERR_MSG(extack, "Invalid hardware address");
                        return -EINVAL;
-               if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
+               }
+               if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS]))) {
+                       NL_SET_ERR_MSG(extack, "Invalid hardware address");
                        return -EADDRNOTAVAIL;
+               }
        }
        return 0;
 }
@@ -1399,12 +1403,17 @@ static int vrf_newlink(struct net *src_net, struct net_device *dev,
        struct net *net;
        int err;
 
-       if (!data || !data[IFLA_VRF_TABLE])
+       if (!data || !data[IFLA_VRF_TABLE]) {
+               NL_SET_ERR_MSG(extack, "VRF table id is missing");
                return -EINVAL;
+       }
 
        vrf->tb_id = nla_get_u32(data[IFLA_VRF_TABLE]);
-       if (vrf->tb_id == RT_TABLE_UNSPEC)
+       if (vrf->tb_id == RT_TABLE_UNSPEC) {
+               NL_SET_ERR_MSG_ATTR(extack, data[IFLA_VRF_TABLE],
+                                   "Invalid VRF table id");
                return -EINVAL;
+       }
 
        dev->priv_flags |= IFF_L3MDEV_MASTER;