net: rtnetlink: add helper to extract msg type's kind
authorNikolay Aleksandrov <razor@blackwall.org>
Wed, 13 Apr 2022 10:51:52 +0000 (13:51 +0300)
committerDavid S. Miller <davem@davemloft.net>
Wed, 13 Apr 2022 11:46:25 +0000 (12:46 +0100)
Add a helper which extracts the msg type's kind using the kind mask (0x3).

Signed-off-by: Nikolay Aleksandrov <razor@blackwall.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/rtnetlink.h
net/core/rtnetlink.c

index 78712b51f3dad57c8b2711af8d14ab0992af0f4f..c51c5ff7f7e2a7d7b84fccc0d7b0ea905a03d6a2 100644 (file)
@@ -19,6 +19,12 @@ enum rtnl_kinds {
        RTNL_KIND_GET,
        RTNL_KIND_SET
 };
+#define RTNL_KIND_MASK 0x3
+
+static inline enum rtnl_kinds rtnl_msgtype_kind(int msgtype)
+{
+       return msgtype & RTNL_KIND_MASK;
+}
 
 void rtnl_register(int protocol, int msgtype,
                   rtnl_doit_func, rtnl_dumpit_func, unsigned int flags);
index 2c36c9dc9b6279dd366303d4d46b2c3bb7645a4e..beda4a7da06253bf0a5fa786549f95755d95616c 100644 (file)
@@ -5947,7 +5947,7 @@ static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh,
                return 0;
 
        family = ((struct rtgenmsg *)nlmsg_data(nlh))->rtgen_family;
-       kind = type&3;
+       kind = rtnl_msgtype_kind(type);
 
        if (kind != RTNL_KIND_GET && !netlink_net_capable(skb, CAP_NET_ADMIN))
                return -EPERM;