aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Poirier <bpoirier@nvidia.com>2023-12-11 09:07:32 -0500
committerStephen Hemminger <stephen@networkplumber.org>2023-12-22 09:58:16 -0800
commitd205b5cf387798f70d03bb51ad338794a9ffccad (patch)
tree68d9bafe1c260b298372c92ee5119cfe56e4f461
parent1d73bfc8ab290d60a23ea248ca85dacfd7cd0e2b (diff)
downloadiproute2-d205b5cf387798f70d03bb51ad338794a9ffccad.tar.gz
bridge: Provide rta_type()
Factor out the repeated code pattern rta_type = attr->rta_type & NLA_TYPE_MASK into a helper which is similar to the existing kernel function nla_type(). Reviewed-by: Petr Machata <petrm@nvidia.com> Tested-by: Petr Machata <petrm@nvidia.com> Signed-off-by: Benjamin Poirier <bpoirier@nvidia.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
-rw-r--r--bridge/vlan.c12
-rw-r--r--bridge/vni.c4
-rw-r--r--include/libnetlink.h4
3 files changed, 11 insertions, 9 deletions
diff --git a/bridge/vlan.c b/bridge/vlan.c
index 05e6a6206..5352eb24f 100644
--- a/bridge/vlan.c
+++ b/bridge/vlan.c
@@ -851,7 +851,7 @@ static void print_vlan_global_opts(struct rtattr *a, int ifindex)
struct rtattr *vtb[BRIDGE_VLANDB_GOPTS_MAX + 1], *vattr;
__u16 vid, vrange = 0;
- if ((a->rta_type & NLA_TYPE_MASK) != BRIDGE_VLANDB_GLOBAL_OPTIONS)
+ if (rta_type(a) != BRIDGE_VLANDB_GLOBAL_OPTIONS)
return;
parse_rtattr_flags(vtb, BRIDGE_VLANDB_GOPTS_MAX, RTA_DATA(a),
@@ -960,7 +960,7 @@ static void print_vlan_opts(struct rtattr *a, int ifindex)
__u16 vrange = 0;
__u8 state = 0;
- if ((a->rta_type & NLA_TYPE_MASK) != BRIDGE_VLANDB_ENTRY)
+ if (rta_type(a) != BRIDGE_VLANDB_ENTRY)
return;
parse_rtattr_flags(vtb, BRIDGE_VLANDB_ENTRY_MAX, RTA_DATA(a),
@@ -1086,14 +1086,14 @@ int print_vlan_rtm(struct nlmsghdr *n, void *arg, bool monitor, bool global_only
rem = len;
for (a = BRVLAN_RTA(bvm); RTA_OK(a, rem); a = RTA_NEXT(a, rem)) {
- unsigned short rta_type = a->rta_type & NLA_TYPE_MASK;
+ unsigned short attr_type = rta_type(a);
/* skip unknown attributes */
- if (rta_type > BRIDGE_VLANDB_MAX ||
- (global_only && rta_type != BRIDGE_VLANDB_GLOBAL_OPTIONS))
+ if (attr_type > BRIDGE_VLANDB_MAX ||
+ (global_only && attr_type != BRIDGE_VLANDB_GLOBAL_OPTIONS))
continue;
- switch (rta_type) {
+ switch (attr_type) {
case BRIDGE_VLANDB_ENTRY:
print_vlan_opts(a, bvm->ifindex);
break;
diff --git a/bridge/vni.c b/bridge/vni.c
index ffc3e1887..a7abe6de5 100644
--- a/bridge/vni.c
+++ b/bridge/vni.c
@@ -319,9 +319,7 @@ int print_vnifilter_rtm(struct nlmsghdr *n, void *arg)
rem = len;
for (t = TUNNEL_RTA(tmsg); RTA_OK(t, rem); t = RTA_NEXT(t, rem)) {
- unsigned short rta_type = t->rta_type & NLA_TYPE_MASK;
-
- if (rta_type != VXLAN_VNIFILTER_ENTRY)
+ if (rta_type(t) != VXLAN_VNIFILTER_ENTRY)
continue;
if (!opened) {
diff --git a/include/libnetlink.h b/include/libnetlink.h
index 39ed87a79..ad7e71272 100644
--- a/include/libnetlink.h
+++ b/include/libnetlink.h
@@ -275,6 +275,10 @@ static inline const char *rta_getattr_str(const struct rtattr *rta)
{
return (const char *)RTA_DATA(rta);
}
+static inline int rta_type(const struct rtattr *rta)
+{
+ return rta->rta_type & NLA_TYPE_MASK;
+}
int rtnl_listen_all_nsid(struct rtnl_handle *);
int rtnl_listen(struct rtnl_handle *, rtnl_listen_filter_t handler,