@@ -65,9 +65,9 @@ extern struct expr *netlink_alloc_data(const struct location *loc,
const struct nft_data_delinearize *nld,
enum nft_registers dreg);
-extern int netlink_linearize_rule(struct netlink_ctx *ctx,
- struct nft_rule *nlr,
- const struct rule *rule);
+extern void netlink_linearize_rule(struct netlink_ctx *ctx,
+ struct nft_rule *nlr,
+ const struct rule *rule);
extern struct rule *netlink_delinearize_rule(struct netlink_ctx *ctx,
const struct nft_rule *r);
@@ -354,16 +354,14 @@ int netlink_add_rule_batch(struct netlink_ctx *ctx,
int err;
nlr = alloc_nft_rule(&rule->handle);
- err = netlink_linearize_rule(ctx, nlr, rule);
- if (err == 0) {
- err = mnl_nft_rule_batch_add(nlr, flags | NLM_F_EXCL,
- ctx->seqnum);
- if (err < 0)
- netlink_io_error(ctx, &rule->location,
- "Could not add rule to batch: %s",
- strerror(errno));
- }
+ netlink_linearize_rule(ctx, nlr, rule);
+ err = mnl_nft_rule_batch_add(nlr, flags | NLM_F_EXCL, ctx->seqnum);
nft_rule_free(nlr);
+ if (err < 0) {
+ netlink_io_error(ctx, &rule->location,
+ "Could not add rule to batch: %s",
+ strerror(errno));
+ }
return err;
}
@@ -746,8 +746,8 @@ static void netlink_gen_stmt(struct netlink_linearize_ctx *ctx,
}
}
-int netlink_linearize_rule(struct netlink_ctx *ctx, struct nft_rule *nlr,
- const struct rule *rule)
+void netlink_linearize_rule(struct netlink_ctx *ctx, struct nft_rule *nlr,
+ const struct rule *rule)
{
struct netlink_linearize_ctx lctx;
const struct stmt *stmt;
@@ -760,5 +760,4 @@ int netlink_linearize_rule(struct netlink_ctx *ctx, struct nft_rule *nlr,
netlink_gen_stmt(&lctx, stmt);
netlink_dump_rule(nlr);
- return 0;
}
This function converts the rule from the list of statements to the netlink message format. The only two possible errors that can make this function to fail are memory exhaustion and malformed statements which inmediately stop the execution of nft. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org> --- include/netlink.h | 6 +++--- src/netlink.c | 16 +++++++--------- src/netlink_linearize.c | 5 ++--- 3 files changed, 12 insertions(+), 15 deletions(-)