git: dfed87b5ce9c - main - netlink: add bool type support
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 28 Feb 2024 22:27:13 UTC
The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=dfed87b5ce9c4e82b0227c14a3ed0cafeb814b16 commit dfed87b5ce9c4e82b0227c14a3ed0cafeb814b16 Author: Kristof Provost <kp@FreeBSD.org> AuthorDate: 2024-02-26 10:19:28 +0000 Commit: Kristof Provost <kp@FreeBSD.org> CommitDate: 2024-02-28 22:26:18 +0000 netlink: add bool type support Reviewed by: melifaro Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D44089 --- sys/netlink/netlink_message_parser.c | 11 +++++++++++ sys/netlink/netlink_message_parser.h | 2 ++ sys/netlink/netlink_snl.h | 6 ++++++ 3 files changed, 19 insertions(+) diff --git a/sys/netlink/netlink_message_parser.c b/sys/netlink/netlink_message_parser.c index 8caa13fbf3ce..eafc2d83cbfb 100644 --- a/sys/netlink/netlink_message_parser.c +++ b/sys/netlink/netlink_message_parser.c @@ -312,6 +312,17 @@ nlattr_get_ipvia(struct nlattr *nla, struct nl_pstate *npt, const void *arg, voi return (error); } +int +nlattr_get_bool(struct nlattr *nla, struct nl_pstate *npt, const void *arg, void *target) +{ + if (__predict_false(NLA_DATA_LEN(nla) != sizeof(bool))) { + NLMSG_REPORT_ERR_MSG(npt, "nla type %d size(%u) is not bool", + nla->nla_type, NLA_DATA_LEN(nla)); + return (EINVAL); + } + *((bool *)target) = *((const bool *)NL_RTA_DATA_CONST(nla)); + return (0); +} int nlattr_get_uint8(struct nlattr *nla, struct nl_pstate *npt, const void *arg, void *target) diff --git a/sys/netlink/netlink_message_parser.h b/sys/netlink/netlink_message_parser.h index 7a417c00fc46..49bec646b29e 100644 --- a/sys/netlink/netlink_message_parser.h +++ b/sys/netlink/netlink_message_parser.h @@ -173,6 +173,8 @@ int nlattr_get_flag(struct nlattr *nla, struct nl_pstate *npt, const void *arg, void *target); int nlattr_get_ip(struct nlattr *nla, struct nl_pstate *npt, const void *arg, void *target); +int nlattr_get_bool(struct nlattr *nla, struct nl_pstate *npt, + const void *arg, void *target); int nlattr_get_uint8(struct nlattr *nla, struct nl_pstate *npt, const void *arg, void *target); int nlattr_get_uint16(struct nlattr *nla, struct nl_pstate *npt, diff --git a/sys/netlink/netlink_snl.h b/sys/netlink/netlink_snl.h index 89ba5b5aef5d..6553a391a8f5 100644 --- a/sys/netlink/netlink_snl.h +++ b/sys/netlink/netlink_snl.h @@ -1147,6 +1147,12 @@ snl_add_msg_attr_raw(struct snl_writer *nw, const struct nlattr *nla_src) return (snl_add_msg_attr(nw, nla_src->nla_type, attr_len, (const void *)(nla_src + 1))); } +static inline bool +snl_add_msg_attr_bool(struct snl_writer *nw, int attrtype, bool value) +{ + return (snl_add_msg_attr(nw, attrtype, sizeof(bool), &value)); +} + static inline bool snl_add_msg_attr_u8(struct snl_writer *nw, int attrtype, uint8_t value) {