]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
rule: fix object order via nft -f
authorPablo Neira Ayuso <pablo@netfilter.org>
Sat, 14 Feb 2015 20:41:23 +0000 (21:41 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Wed, 18 Feb 2015 14:51:29 +0000 (15:51 +0100)
The objects need to be loaded in the following order:

#1 tables
#2 chains
#3 sets
#4 rules

We have to make sure that chains are in place by when we add rules with
jumps/gotos. Similarly, we have to make sure that the sets are in place
by when rules reference them.

Without this patch, you may hit ENOENT errors depending on your ruleset
configuration.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/rule.c

index feafe26b6f7d8403fbecc0e60f99488dae726ebe..8d76fd05e2b8ef4c7d3cb267c5bc3af41df7c6a2 100644 (file)
@@ -658,14 +658,19 @@ static int do_add_table(struct netlink_ctx *ctx, const struct handle *h,
        if (netlink_add_table(ctx, h, loc, table, excl) < 0)
                return -1;
        if (table != NULL) {
+               list_for_each_entry(chain, &table->chains, list) {
+                       if (netlink_add_chain(ctx, &chain->handle,
+                                             &chain->location, chain,
+                                             excl) < 0)
+                               return -1;
+               }
                list_for_each_entry(set, &table->sets, list) {
                        handle_merge(&set->handle, &table->handle);
                        if (do_add_set(ctx, &set->handle, set) < 0)
                                return -1;
                }
                list_for_each_entry(chain, &table->chains, list) {
-                       if (do_add_chain(ctx, &chain->handle, &chain->location,
-                                        chain, excl) < 0)
+                       if (netlink_add_rule_list(ctx, h, &chain->rules) < 0)
                                return -1;
                }
        }