diff mbox series

[net-next,v2,5/8] net: rtnetlink: add common flush attributes

Message ID 20220411172934.1813604-6-razor@blackwall.org (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series net: bridge: add flush filtering support | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next, async
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 4794 this patch: 4794
netdev/cc_maintainers warning 4 maintainers not CCed: idosch@nvidia.com daniel@iogearbox.net petrm@nvidia.com pabeni@redhat.com
netdev/build_clang success Errors and warnings before: 1073 this patch: 1073
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 4940 this patch: 4940
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 55 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Nikolay Aleksandrov April 11, 2022, 5:29 p.m. UTC
Add common fdb flush attributes - ifindex, vlan id, ndm flags/state masks.
All of these are used by the bridge and vxlan drivers. Also minimal attr
policy validation is added, it is up to ndo_fdb_flush implementers to
further validate them.

Signed-off-by: Nikolay Aleksandrov <razor@blackwall.org>
---
 include/uapi/linux/neighbour.h |  4 ++++
 net/core/rtnetlink.c           | 16 +++++++++++++---
 2 files changed, 17 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/include/uapi/linux/neighbour.h b/include/uapi/linux/neighbour.h
index 60e728319a50..5ab4e9b5edc8 100644
--- a/include/uapi/linux/neighbour.h
+++ b/include/uapi/linux/neighbour.h
@@ -214,6 +214,10 @@  enum {
 
 enum {
 	NDFA_UNSPEC,
+	NDFA_IFINDEX,
+	NDFA_VLAN,
+	NDFA_NDM_STATE_MASK,
+	NDFA_NDM_FLAGS_MASK,
 	__NDFA_MAX
 };
 #define NDFA_MAX (__NDFA_MAX - 1)
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 7325b60d1aa2..379b6a066fbd 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -4660,7 +4660,11 @@  static int rtnl_fdb_get(struct sk_buff *in_skb, struct nlmsghdr *nlh,
 }
 
 static const struct nla_policy fdb_flush_policy[NDFA_MAX + 1] = {
-	[NDFA_UNSPEC] = { .type = NLA_REJECT },
+	[NDFA_UNSPEC]	= { .type = NLA_REJECT },
+	[NDFA_IFINDEX]	= NLA_POLICY_MIN(NLA_S32, 1),
+	[NDFA_VLAN]	= { .type = NLA_U16 },
+	[NDFA_NDM_STATE_MASK]	= { .type = NLA_U16 },
+	[NDFA_NDM_FLAGS_MASK]	= { .type = NLA_U8 },
 };
 
 static int rtnl_fdb_flush(struct sk_buff *skb, struct nlmsghdr *nlh,
@@ -4670,6 +4674,7 @@  static int rtnl_fdb_flush(struct sk_buff *skb, struct nlmsghdr *nlh,
 	struct nlattr *tb[NDFA_MAX + 1];
 	struct net_device *dev;
 	struct ndmsg *ndm;
+	u16 vid;
 	int err;
 
 	err = nlmsg_parse(nlh, sizeof(*ndm), tb, NDFA_MAX, fdb_flush_policy,
@@ -4689,19 +4694,24 @@  static int rtnl_fdb_flush(struct sk_buff *skb, struct nlmsghdr *nlh,
 		return -ENODEV;
 	}
 
+	err = fdb_vid_parse(tb[NDFA_VLAN], &vid, extack);
+	if (err)
+		return err;
+
 	err = -EOPNOTSUPP;
 	if ((!ndm->ndm_flags || ndm->ndm_flags & NTF_MASTER) &&
 	    netif_is_bridge_port(dev)) {
 		struct net_device *br_dev = netdev_master_upper_dev_get(dev);
 
-		err = br_dev->netdev_ops->ndo_fdb_flush(ndm, tb, dev, 0, extack);
+		err = br_dev->netdev_ops->ndo_fdb_flush(ndm, tb, dev, vid,
+							extack);
 		if (err)
 			goto out;
 		else
 			ndm->ndm_flags &= ~NTF_MASTER;
 	}
 	if ((ndm->ndm_flags & NTF_SELF) && dev->netdev_ops->ndo_fdb_flush) {
-		err = dev->netdev_ops->ndo_fdb_flush(ndm, tb, dev, 0, extack);
+		err = dev->netdev_ops->ndo_fdb_flush(ndm, tb, dev, vid, extack);
 		if (!err)
 			ndm->ndm_flags &= ~NTF_SELF;
 	}