]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
rule: fix printing of rule comments
authorArturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Thu, 8 Oct 2015 09:27:24 +0000 (11:27 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Thu, 8 Oct 2015 16:16:44 +0000 (18:16 +0200)
Several fixes:
 * handles are printed last
 * simplify space games (an extra space was being printed)
 * comments are shown with `nft monitor' as well (missing before this patch)

Before this patch:

% nft list ruleset -a
[...]
chain test {
iifname eth0 # handle 1 comment "test"

}
[...]

% nft list ruleset
[...]
chain test {
iifname eth0  comment "test"
    ^^
}
[...]

% nft monitor &
% nft add rule test test iifname eth0 comment "test"
add rule test test iifname eth0

After this patch:

% nft list ruleset -a
chain test {
iifname eth0 comment "test" # handle 1
    ^
}

% nft monitor -a &
% nft add rule test test iifname eth0 comment "test"
add rule test test iifname eth0 comment "test" # handle 1

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/rule.c

index 92b83f08d026956a0fa37dfc511596cfb3d5feca..1bf0e03e44efef50ed273a300c23601ceb18a498 100644 (file)
@@ -383,6 +383,10 @@ void rule_print(const struct rule *rule)
                stmt->ops->print(stmt);
                printf(" ");
        }
+
+       if (rule->handle.comment)
+               printf("comment \"%s\" ", rule->handle.comment);
+
        if (handle_output > 0)
                printf("# handle %" PRIu64, rule->handle.handle);
 }
@@ -622,10 +626,7 @@ static void chain_print(const struct chain *chain)
        list_for_each_entry(rule, &chain->rules, list) {
                printf("\t\t");
                rule_print(rule);
-               if (rule->handle.comment)
-                       printf(" comment \"%s\"\n", rule->handle.comment);
-               else
-                       printf("\n");
+               printf("\n");
        }
        printf("\t}\n");
 }