提交 b88d12e4 编写于 作者: F Florian Westphal 提交者: David S. Miller

rtnetlink: bridge: use ext_ack instead of printk

We can now piggyback error strings to userspace via extended acks
rather than using printk.

Before:
bridge fdb add 01:02:03:04:05:06 dev br0 vlan 4095
RTNETLINK answers: Invalid argument

After:
bridge fdb add 01:02:03:04:05:06 dev br0 vlan 4095
Error: invalid vlan id.

v3: drop 'RTM_' prefixes, suggested by David Ahern, they
are not useful, the add/del in bridge command line is enough.

Also reword error in response to malformed/bad vlan id attribute
size.

Cc: David Ahern <dsahern@gmail.com>
Signed-off-by: NFlorian Westphal <fw@strlen.de>
Reviewed-by: NDavid Ahern <dsahern@gmail.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 8f88f74a
...@@ -3066,21 +3066,21 @@ int ndo_dflt_fdb_add(struct ndmsg *ndm, ...@@ -3066,21 +3066,21 @@ int ndo_dflt_fdb_add(struct ndmsg *ndm,
} }
EXPORT_SYMBOL(ndo_dflt_fdb_add); EXPORT_SYMBOL(ndo_dflt_fdb_add);
static int fdb_vid_parse(struct nlattr *vlan_attr, u16 *p_vid) static int fdb_vid_parse(struct nlattr *vlan_attr, u16 *p_vid,
struct netlink_ext_ack *extack)
{ {
u16 vid = 0; u16 vid = 0;
if (vlan_attr) { if (vlan_attr) {
if (nla_len(vlan_attr) != sizeof(u16)) { if (nla_len(vlan_attr) != sizeof(u16)) {
pr_info("PF_BRIDGE: RTM_NEWNEIGH with invalid vlan\n"); NL_SET_ERR_MSG(extack, "invalid vlan attribute size");
return -EINVAL; return -EINVAL;
} }
vid = nla_get_u16(vlan_attr); vid = nla_get_u16(vlan_attr);
if (!vid || vid >= VLAN_VID_MASK) { if (!vid || vid >= VLAN_VID_MASK) {
pr_info("PF_BRIDGE: RTM_NEWNEIGH with invalid vlan id %d\n", NL_SET_ERR_MSG(extack, "invalid vlan id");
vid);
return -EINVAL; return -EINVAL;
} }
} }
...@@ -3105,24 +3105,24 @@ static int rtnl_fdb_add(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -3105,24 +3105,24 @@ static int rtnl_fdb_add(struct sk_buff *skb, struct nlmsghdr *nlh,
ndm = nlmsg_data(nlh); ndm = nlmsg_data(nlh);
if (ndm->ndm_ifindex == 0) { if (ndm->ndm_ifindex == 0) {
pr_info("PF_BRIDGE: RTM_NEWNEIGH with invalid ifindex\n"); NL_SET_ERR_MSG(extack, "invalid ifindex");
return -EINVAL; return -EINVAL;
} }
dev = __dev_get_by_index(net, ndm->ndm_ifindex); dev = __dev_get_by_index(net, ndm->ndm_ifindex);
if (dev == NULL) { if (dev == NULL) {
pr_info("PF_BRIDGE: RTM_NEWNEIGH with unknown ifindex\n"); NL_SET_ERR_MSG(extack, "unknown ifindex");
return -ENODEV; return -ENODEV;
} }
if (!tb[NDA_LLADDR] || nla_len(tb[NDA_LLADDR]) != ETH_ALEN) { if (!tb[NDA_LLADDR] || nla_len(tb[NDA_LLADDR]) != ETH_ALEN) {
pr_info("PF_BRIDGE: RTM_NEWNEIGH with invalid address\n"); NL_SET_ERR_MSG(extack, "invalid address");
return -EINVAL; return -EINVAL;
} }
addr = nla_data(tb[NDA_LLADDR]); addr = nla_data(tb[NDA_LLADDR]);
err = fdb_vid_parse(tb[NDA_VLAN], &vid); err = fdb_vid_parse(tb[NDA_VLAN], &vid, extack);
if (err) if (err)
return err; return err;
...@@ -3209,24 +3209,24 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -3209,24 +3209,24 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh,
ndm = nlmsg_data(nlh); ndm = nlmsg_data(nlh);
if (ndm->ndm_ifindex == 0) { if (ndm->ndm_ifindex == 0) {
pr_info("PF_BRIDGE: RTM_DELNEIGH with invalid ifindex\n"); NL_SET_ERR_MSG(extack, "invalid ifindex");
return -EINVAL; return -EINVAL;
} }
dev = __dev_get_by_index(net, ndm->ndm_ifindex); dev = __dev_get_by_index(net, ndm->ndm_ifindex);
if (dev == NULL) { if (dev == NULL) {
pr_info("PF_BRIDGE: RTM_DELNEIGH with unknown ifindex\n"); NL_SET_ERR_MSG(extack, "unknown ifindex");
return -ENODEV; return -ENODEV;
} }
if (!tb[NDA_LLADDR] || nla_len(tb[NDA_LLADDR]) != ETH_ALEN) { if (!tb[NDA_LLADDR] || nla_len(tb[NDA_LLADDR]) != ETH_ALEN) {
pr_info("PF_BRIDGE: RTM_DELNEIGH with invalid address\n"); NL_SET_ERR_MSG(extack, "invalid address");
return -EINVAL; return -EINVAL;
} }
addr = nla_data(tb[NDA_LLADDR]); addr = nla_data(tb[NDA_LLADDR]);
err = fdb_vid_parse(tb[NDA_VLAN], &vid); err = fdb_vid_parse(tb[NDA_VLAN], &vid, extack);
if (err) if (err)
return err; return err;
...@@ -3666,7 +3666,7 @@ static int rtnl_bridge_setlink(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -3666,7 +3666,7 @@ static int rtnl_bridge_setlink(struct sk_buff *skb, struct nlmsghdr *nlh,
dev = __dev_get_by_index(net, ifm->ifi_index); dev = __dev_get_by_index(net, ifm->ifi_index);
if (!dev) { if (!dev) {
pr_info("PF_BRIDGE: RTM_SETLINK with unknown ifindex\n"); NL_SET_ERR_MSG(extack, "unknown ifindex");
return -ENODEV; return -ENODEV;
} }
...@@ -3741,7 +3741,7 @@ static int rtnl_bridge_dellink(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -3741,7 +3741,7 @@ static int rtnl_bridge_dellink(struct sk_buff *skb, struct nlmsghdr *nlh,
dev = __dev_get_by_index(net, ifm->ifi_index); dev = __dev_get_by_index(net, ifm->ifi_index);
if (!dev) { if (!dev) {
pr_info("PF_BRIDGE: RTM_SETLINK with unknown ifindex\n"); NL_SET_ERR_MSG(extack, "unknown ifindex");
return -ENODEV; return -ENODEV;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册