git: 70810dc8178c - main - netlink: add nlattr_get_uint8() function to pack u8 attributes.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 25 Apr 2023 11:15:30 UTC
The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=70810dc8178cdc473f31f10bdfaec5de533dd67e commit 70810dc8178cdc473f31f10bdfaec5de533dd67e Author: Alexander V. Chernikov <melifaro@FreeBSD.org> AuthorDate: 2023-04-25 10:56:42 +0000 Commit: Alexander V. Chernikov <melifaro@FreeBSD.org> CommitDate: 2023-04-25 10:56:42 +0000 netlink: add nlattr_get_uint8() function to pack u8 attributes. MFC after: 2 weeks --- sys/netlink/netlink_message_parser.c | 14 +++++++++++++- sys/netlink/netlink_message_parser.h | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/sys/netlink/netlink_message_parser.c b/sys/netlink/netlink_message_parser.c index d0aaf4301872..c6cd82260e5b 100644 --- a/sys/netlink/netlink_message_parser.c +++ b/sys/netlink/netlink_message_parser.c @@ -314,11 +314,23 @@ nlattr_get_ipvia(struct nlattr *nla, struct nl_pstate *npt, const void *arg, voi } +int +nlattr_get_uint8(struct nlattr *nla, struct nl_pstate *npt, const void *arg, void *target) +{ + if (__predict_false(NLA_DATA_LEN(nla) != sizeof(uint8_t))) { + NLMSG_REPORT_ERR_MSG(npt, "nla type %d size(%u) is not uint8", + nla->nla_type, NLA_DATA_LEN(nla)); + return (EINVAL); + } + *((uint16_t *)target) = *((const uint16_t *)NL_RTA_DATA_CONST(nla)); + return (0); +} + int nlattr_get_uint16(struct nlattr *nla, struct nl_pstate *npt, const void *arg, void *target) { if (__predict_false(NLA_DATA_LEN(nla) != sizeof(uint16_t))) { - NLMSG_REPORT_ERR_MSG(npt, "nla type %d size(%u) is not uint32", + NLMSG_REPORT_ERR_MSG(npt, "nla type %d size(%u) is not uint16", nla->nla_type, NLA_DATA_LEN(nla)); return (EINVAL); } diff --git a/sys/netlink/netlink_message_parser.h b/sys/netlink/netlink_message_parser.h index 067d25dae7d8..85d1c20557a2 100644 --- a/sys/netlink/netlink_message_parser.h +++ b/sys/netlink/netlink_message_parser.h @@ -169,6 +169,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_uint8(struct nlattr *nla, struct nl_pstate *npt, + const void *arg, void *target); int nlattr_get_uint16(struct nlattr *nla, struct nl_pstate *npt, const void *arg, void *target); int nlattr_get_uint32(struct nlattr *nla, struct nl_pstate *npt,