summaryrefslogtreecommitdiffstats
path: root/src/flowtable.c
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2024-10-02 16:44:49 +0200
committerPhil Sutter <phil@nwl.cc>2025-10-18 21:11:27 +0200
commit5a54b99859fd52d8c7e866b57f6d8fac3e20a78f (patch)
tree6f4638c243b241886fdd0bb8916f074bcd0d12ad /src/flowtable.c
parent6f24a13a19b8690444564f50e1866fae5abf7687 (diff)
utils: Introduce nftnl_parse_str_attr()HEADmaster
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 <phil@nwl.cc> Acked-by: Florian Westphal <fw@strlen.de>
Diffstat (limited to 'src/flowtable.c')
-rw-r--r--src/flowtable.c24
1 files changed, 8 insertions, 16 deletions
diff --git a/src/flowtable.c b/src/flowtable.c
index 59991d6..27af51c 100644
--- a/src/flowtable.c
+++ b/src/flowtable.c
@@ -408,22 +408,14 @@ int nftnl_flowtable_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_flowtab
if (mnl_attr_parse(nlh, sizeof(*nfg), nftnl_flowtable_parse_attr_cb, tb) < 0)
return -1;
- if (tb[NFTA_FLOWTABLE_NAME]) {
- if (c->flags & (1 << NFTNL_FLOWTABLE_NAME))
- xfree(c->name);
- c->name = strdup(mnl_attr_get_str(tb[NFTA_FLOWTABLE_NAME]));
- if (!c->name)
- return -1;
- c->flags |= (1 << NFTNL_FLOWTABLE_NAME);
- }
- if (tb[NFTA_FLOWTABLE_TABLE]) {
- if (c->flags & (1 << NFTNL_FLOWTABLE_TABLE))
- xfree(c->table);
- c->table = strdup(mnl_attr_get_str(tb[NFTA_FLOWTABLE_TABLE]));
- if (!c->table)
- return -1;
- c->flags |= (1 << NFTNL_FLOWTABLE_TABLE);
- }
+ if (nftnl_parse_str_attr(tb[NFTA_FLOWTABLE_NAME],
+ NFTNL_FLOWTABLE_NAME,
+ &c->name, &c->flags) < 0)
+ return -1;
+ if (nftnl_parse_str_attr(tb[NFTA_FLOWTABLE_TABLE],
+ NFTNL_FLOWTABLE_TABLE,
+ &c->table, &c->flags) < 0)
+ return -1;
if (tb[NFTA_FLOWTABLE_HOOK]) {
ret = nftnl_flowtable_parse_hook(tb[NFTA_FLOWTABLE_HOOK], c);
if (ret < 0)