From e39f2ee64e7df2eda4b3cd63652507580c279f09 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 17 Oct 2023 12:39:24 -0400 Subject: [PATCH] MT#57371 split up rtpe_target function ... so that the core functionality can be re-used Change-Id: Ie567110dc3c407ee38dcf6710d090828206db619 --- daemon/nftables.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/daemon/nftables.c b/daemon/nftables.c index 5122c1386e..fe5eec085b 100644 --- a/daemon/nftables.c +++ b/daemon/nftables.c @@ -402,10 +402,8 @@ static const char *input_immediate(struct nftnl_rule *r, int family, struct add_ } -static const char *rtpe_target(struct nftnl_rule *r, int family, struct add_rule_callbacks *callbacks) { - nftnl_rule_set_str(r, NFTNL_RULE_CHAIN, callbacks->chain); - - AUTO_CLEANUP(struct nftnl_expr *e, expr_free) = nftnl_expr_alloc("target"); +static const char *rtpe_target_base(struct nftnl_rule *r, struct add_rule_callbacks *callbacks) { + struct nftnl_expr *e = nftnl_expr_alloc("target"); if (!e) return "failed to allocate target expr for RTPENGINE"; @@ -417,13 +415,22 @@ static const char *rtpe_target(struct nftnl_rule *r, int family, struct add_rule nftnl_expr_set(e, NFTNL_EXPR_TG_INFO, &callbacks->rtpe_target_info, sizeof(callbacks->rtpe_target_info)); nftnl_rule_add_expr(r, e); - e = NULL; - e = nftnl_expr_alloc("counter"); + return NULL; +} + + +static const char *rtpe_target(struct nftnl_rule *r, int family, struct add_rule_callbacks *callbacks) { + nftnl_rule_set_str(r, NFTNL_RULE_CHAIN, callbacks->chain); + + const char *err = rtpe_target_base(r, callbacks); + if (err) + return err; + + struct nftnl_expr *e = nftnl_expr_alloc("counter"); if (!e) return "failed to allocate counter expr for RTPENGINE"; nftnl_rule_add_expr(r, e); - e = NULL; return NULL; }