Commit 9e834259 authored by Nikolay Aleksandrov's avatar Nikolay Aleksandrov Committed by David S. Miller

net: rtnetlink: add NLM_F_BULK support to rtnl_fdb_del

When NLM_F_BULK is specified in a fdb del message we need to handle it
differently. First since this is a new call we can strictly validate the
passed attributes, at first only ifindex and vlan are allowed as these
will be the initially supported filter attributes, any other attribute
is rejected. The mac address is no longer mandatory, but we use it
to error out in older kernels because it cannot be specified with bulk
request (the attribute is not allowed) and then we have to dispatch
the call to ndo_fdb_del_bulk if the device supports it. The del bulk
callback can do further validation of the attributes if necessary.
Signed-off-by: default avatarNikolay Aleksandrov <razor@blackwall.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1306d536
...@@ -4169,22 +4169,34 @@ int ndo_dflt_fdb_del(struct ndmsg *ndm, ...@@ -4169,22 +4169,34 @@ int ndo_dflt_fdb_del(struct ndmsg *ndm,
} }
EXPORT_SYMBOL(ndo_dflt_fdb_del); EXPORT_SYMBOL(ndo_dflt_fdb_del);
static const struct nla_policy fdb_del_bulk_policy[NDA_MAX + 1] = {
[NDA_VLAN] = { .type = NLA_U16 },
[NDA_IFINDEX] = NLA_POLICY_MIN(NLA_S32, 1),
};
static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh, static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
bool del_bulk = !!(nlh->nlmsg_flags & NLM_F_BULK);
struct net *net = sock_net(skb->sk); struct net *net = sock_net(skb->sk);
const struct net_device_ops *ops;
struct ndmsg *ndm; struct ndmsg *ndm;
struct nlattr *tb[NDA_MAX+1]; struct nlattr *tb[NDA_MAX+1];
struct net_device *dev; struct net_device *dev;
__u8 *addr; __u8 *addr = NULL;
int err; int err;
u16 vid; u16 vid;
if (!netlink_capable(skb, CAP_NET_ADMIN)) if (!netlink_capable(skb, CAP_NET_ADMIN))
return -EPERM; return -EPERM;
err = nlmsg_parse_deprecated(nlh, sizeof(*ndm), tb, NDA_MAX, NULL, if (!del_bulk) {
extack); err = nlmsg_parse_deprecated(nlh, sizeof(*ndm), tb, NDA_MAX,
NULL, extack);
} else {
err = nlmsg_parse(nlh, sizeof(*ndm), tb, NDA_MAX,
fdb_del_bulk_policy, extack);
}
if (err < 0) if (err < 0)
return err; return err;
...@@ -4200,9 +4212,12 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -4200,9 +4212,12 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh,
return -ENODEV; return -ENODEV;
} }
if (!tb[NDA_LLADDR] || nla_len(tb[NDA_LLADDR]) != ETH_ALEN) { if (!del_bulk) {
NL_SET_ERR_MSG(extack, "invalid address"); if (!tb[NDA_LLADDR] || nla_len(tb[NDA_LLADDR]) != ETH_ALEN) {
return -EINVAL; NL_SET_ERR_MSG(extack, "invalid address");
return -EINVAL;
}
addr = nla_data(tb[NDA_LLADDR]);
} }
if (dev->type != ARPHRD_ETHER) { if (dev->type != ARPHRD_ETHER) {
...@@ -4210,8 +4225,6 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -4210,8 +4225,6 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh,
return -EINVAL; return -EINVAL;
} }
addr = nla_data(tb[NDA_LLADDR]);
err = fdb_vid_parse(tb[NDA_VLAN], &vid, extack); err = fdb_vid_parse(tb[NDA_VLAN], &vid, extack);
if (err) if (err)
return err; return err;
...@@ -4222,10 +4235,16 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -4222,10 +4235,16 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh,
if ((!ndm->ndm_flags || ndm->ndm_flags & NTF_MASTER) && if ((!ndm->ndm_flags || ndm->ndm_flags & NTF_MASTER) &&
netif_is_bridge_port(dev)) { netif_is_bridge_port(dev)) {
struct net_device *br_dev = netdev_master_upper_dev_get(dev); struct net_device *br_dev = netdev_master_upper_dev_get(dev);
const struct net_device_ops *ops = br_dev->netdev_ops;
if (ops->ndo_fdb_del) ops = br_dev->netdev_ops;
err = ops->ndo_fdb_del(ndm, tb, dev, addr, vid); if (!del_bulk) {
if (ops->ndo_fdb_del)
err = ops->ndo_fdb_del(ndm, tb, dev, addr, vid);
} else {
if (ops->ndo_fdb_del_bulk)
err = ops->ndo_fdb_del_bulk(ndm, tb, dev, vid,
extack);
}
if (err) if (err)
goto out; goto out;
...@@ -4235,15 +4254,24 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -4235,15 +4254,24 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh,
/* Embedded bridge, macvlan, and any other device support */ /* Embedded bridge, macvlan, and any other device support */
if (ndm->ndm_flags & NTF_SELF) { if (ndm->ndm_flags & NTF_SELF) {
if (dev->netdev_ops->ndo_fdb_del) ops = dev->netdev_ops;
err = dev->netdev_ops->ndo_fdb_del(ndm, tb, dev, addr, if (!del_bulk) {
vid); if (ops->ndo_fdb_del)
else err = ops->ndo_fdb_del(ndm, tb, dev, addr, vid);
err = ndo_dflt_fdb_del(ndm, tb, dev, addr, vid); else
err = ndo_dflt_fdb_del(ndm, tb, dev, addr, vid);
} else {
/* in case err was cleared by NTF_MASTER call */
err = -EOPNOTSUPP;
if (ops->ndo_fdb_del_bulk)
err = ops->ndo_fdb_del_bulk(ndm, tb, dev, vid,
extack);
}
if (!err) { if (!err) {
rtnl_fdb_notify(dev, addr, vid, RTM_DELNEIGH, if (!del_bulk)
ndm->ndm_state); rtnl_fdb_notify(dev, addr, vid, RTM_DELNEIGH,
ndm->ndm_state);
ndm->ndm_flags &= ~NTF_SELF; ndm->ndm_flags &= ~NTF_SELF;
} }
} }
...@@ -6145,7 +6173,8 @@ void __init rtnetlink_init(void) ...@@ -6145,7 +6173,8 @@ void __init rtnetlink_init(void)
rtnl_register(PF_UNSPEC, RTM_DELLINKPROP, rtnl_dellinkprop, NULL, 0); rtnl_register(PF_UNSPEC, RTM_DELLINKPROP, rtnl_dellinkprop, NULL, 0);
rtnl_register(PF_BRIDGE, RTM_NEWNEIGH, rtnl_fdb_add, NULL, 0); rtnl_register(PF_BRIDGE, RTM_NEWNEIGH, rtnl_fdb_add, NULL, 0);
rtnl_register(PF_BRIDGE, RTM_DELNEIGH, rtnl_fdb_del, NULL, 0); rtnl_register(PF_BRIDGE, RTM_DELNEIGH, rtnl_fdb_del, NULL,
RTNL_FLAG_BULK_DEL_SUPPORTED);
rtnl_register(PF_BRIDGE, RTM_GETNEIGH, rtnl_fdb_get, rtnl_fdb_dump, 0); rtnl_register(PF_BRIDGE, RTM_GETNEIGH, rtnl_fdb_get, rtnl_fdb_dump, 0);
rtnl_register(PF_BRIDGE, RTM_GETLINK, NULL, rtnl_bridge_getlink, 0); rtnl_register(PF_BRIDGE, RTM_GETLINK, NULL, rtnl_bridge_getlink, 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment