git: f2743786e9a7 - stable/13 - netlink: add u8/u64 attribute fetcher accessors to snl(3).

From: Alexander V. Chernikov <melifaro_at_FreeBSD.org>
Date: Sat, 08 Apr 2023 19:44:45 UTC
The branch stable/13 has been updated by melifaro:

URL: https://cgit.FreeBSD.org/src/commit/?id=f2743786e9a76d16a14e145eee72f77594e4d237

commit f2743786e9a76d16a14e145eee72f77594e4d237
Author:     Alexander V. Chernikov <melifaro@FreeBSD.org>
AuthorDate: 2023-03-03 14:05:40 +0000
Commit:     Alexander V. Chernikov <melifaro@FreeBSD.org>
CommitDate: 2023-04-08 19:03:23 +0000

    netlink: add u8/u64 attribute fetcher accessors to snl(3).
    
    MFC after:      2 weeks
    
    (cherry picked from commit 61507ae30b9096eaa0d44fec71211f3843d546eb)
---
 share/man/man3/snl.3      |  8 ++++++++
 sys/netlink/netlink_snl.h | 25 ++++++++++++++++++++++++-
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/share/man/man3/snl.3 b/share/man/man3/snl.3
index 78a6b67e88a9..2f328aadd023 100644
--- a/share/man/man3/snl.3
+++ b/share/man/man3/snl.3
@@ -75,10 +75,14 @@
 .Ft "bool"
 .Fn snl_attr_get_flag "struct snl_state *ss" "struct nlattr *nla" "void *target"
 .Ft "bool"
+.Fn snl_attr_get_uint8 "struct snl_state *ss" "struct nlattr *nla" "void *target"
+.Ft "bool"
 .Fn snl_attr_get_uint16 "struct snl_state *ss" "struct nlattr *nla" "void *target"
 .Ft "bool"
 .Fn snl_attr_get_uint32 "struct snl_state *ss" "struct nlattr *nla" "void *target"
 .Ft "bool"
+.Fn snl_attr_get_uint64 "struct snl_state *ss" "struct nlattr *nla" "void *target"
+.Ft "bool"
 .Fn snl_attr_get_string "struct snl_state *ss" "struct nlattr *nla" "void *target"
 .Ft "bool"
 .Fn snl_attr_get_stringn "struct snl_state *ss" "struct nlattr *nla" "void *target"
@@ -181,10 +185,14 @@ A number of predefined getters for the common data types exist.
 .Fn snl_attr_get_flag
 converts a flag-type attribute to an uint8_t value of 1 or 0, depending on the
 attribute presence.
+.Fn snl_attr_get_uint8
+stores a uint8_t type attribute into the uint8_t target field.
 .Fn snl_attr_get_uint16
 stores a uint16_t type attribute into the uint16_t target field.
 .Fn snl_attr_get_uint32
 stores a uint32_t type attribute into the uint32_t target field.
+.Fn snl_attr_get_uint64
+stores a uint64_t type attribute into the uint64_t target field.
 .Fn snl_attr_get_ip
 and
 .Fn snl_attr_get_ipvia
diff --git a/sys/netlink/netlink_snl.h b/sys/netlink/netlink_snl.h
index 6e2c4b89a7c4..d88808ea6d3b 100644
--- a/sys/netlink/netlink_snl.h
+++ b/sys/netlink/netlink_snl.h
@@ -355,6 +355,17 @@ snl_attr_get_flag(struct snl_state *ss __unused, struct nlattr *nla, void *targe
 	return (false);
 }
 
+static inline bool
+snl_attr_get_uint8(struct snl_state *ss __unused, struct nlattr *nla,
+    const void *arg __unused, void *target)
+{
+	if (NLA_DATA_LEN(nla) == sizeof(uint8_t)) {
+		*((uint8_t *)target) = *((const uint8_t *)NLA_DATA_CONST(nla));
+		return (true);
+	}
+	return (false);
+}
+
 static inline bool
 snl_attr_get_uint16(struct snl_state *ss __unused, struct nlattr *nla,
     const void *arg __unused, void *target)
@@ -377,6 +388,17 @@ snl_attr_get_uint32(struct snl_state *ss __unused, struct nlattr *nla,
 	return (false);
 }
 
+static inline bool
+snl_attr_get_uint64(struct snl_state *ss __unused, struct nlattr *nla,
+    const void *arg __unused, void *target)
+{
+	if (NLA_DATA_LEN(nla) == sizeof(uint64_t)) {
+		memcpy(target, NLA_DATA_CONST(nla), sizeof(uint64_t));
+		return (true);
+	}
+	return (false);
+}
+
 static inline bool
 snl_attr_get_string(struct snl_state *ss __unused, struct nlattr *nla,
     const void *arg __unused, void *target)
@@ -416,7 +438,8 @@ snl_attr_get_nested(struct snl_state *ss, struct nlattr *nla, const void *arg, v
 }
 
 static inline bool
-snl_attr_get_nla(struct snl_state *ss __unused, struct nlattr *nla, void *target)
+snl_attr_get_nla(struct snl_state *ss __unused, struct nlattr *nla,
+    const void *arg __unused, void *target)
 {
 	*((struct nlattr **)target) = nla;
 	return (true);