From 5a54b99859fd52d8c7e866b57f6d8fac3e20a78f Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Wed, 2 Oct 2024 16:44:49 +0200 Subject: utils: Introduce nftnl_parse_str_attr() Wrap the common parsing of string attributes in a function. Apart from slightly reducing code size, this unifies callers in conditional freeing of the field in case it was set before (missing in twelve spots) and error checking for failing strdup()-calls (missing in four spots). Signed-off-by: Phil Sutter Acked-by: Florian Westphal --- include/utils.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include') diff --git a/include/utils.h b/include/utils.h index 5a3379f..1049289 100644 --- a/include/utils.h +++ b/include/utils.h @@ -88,4 +88,7 @@ struct nlattr; void nftnl_attr_put_ifname(struct nlmsghdr *nlh, const char *ifname); char *nftnl_attr_get_ifname(const struct nlattr *attr); +int nftnl_parse_str_attr(const struct nlattr *tb, int attr, + const char **field, uint32_t *flags); + #endif -- cgit v1.2.3