diff options
| author | Phil Sutter <phil@nwl.cc> | 2024-10-02 16:44:49 +0200 |
|---|---|---|
| committer | Phil Sutter <phil@nwl.cc> | 2025-10-18 21:11:27 +0200 |
| commit | 5a54b99859fd52d8c7e866b57f6d8fac3e20a78f (patch) | |
| tree | 6f4638c243b241886fdd0bb8916f074bcd0d12ad /src/flowtable.c | |
| parent | 6f24a13a19b8690444564f50e1866fae5abf7687 (diff) | |
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.c | 24 |
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) |
