]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
meta: don't print meta keyword for unqualified meta stmts
authorPatrick McHardy <kaber@trash.net>
Mon, 12 Jan 2015 10:19:19 +0000 (10:19 +0000)
committerPatrick McHardy <kaber@trash.net>
Mon, 12 Jan 2015 13:18:44 +0000 (13:18 +0000)
Signed-off-by: Patrick McHardy <kaber@trash.net>
src/meta.c

index 6ff5fc87823b19d73e70e4814bb68c7a2712852c..6689eade249346666c1b3b5e1e0bcb56e1b6418b 100644 (file)
@@ -415,22 +415,28 @@ static const struct meta_template meta_templates[] = {
                                                BYTEORDER_HOST_ENDIAN),
 };
 
-static void meta_expr_print(const struct expr *expr)
+static bool meta_key_is_qualified(enum nft_meta_keys key)
 {
-       switch (expr->meta.key) {
+       switch (key) {
        case NFT_META_LEN:
        case NFT_META_NFPROTO:
        case NFT_META_L4PROTO:
        case NFT_META_PROTOCOL:
        case NFT_META_PRIORITY:
-               printf("meta %s", meta_templates[expr->meta.key].token);
-               break;
+               return true;
        default:
-               printf("%s", meta_templates[expr->meta.key].token);
-               break;
+               return false;
        }
 }
 
+static void meta_expr_print(const struct expr *expr)
+{
+       if (meta_key_is_qualified(expr->meta.key))
+               printf("meta %s", meta_templates[expr->meta.key].token);
+       else
+               printf("%s", meta_templates[expr->meta.key].token);
+}
+
 static bool meta_expr_cmp(const struct expr *e1, const struct expr *e2)
 {
        return e1->meta.key == e2->meta.key;
@@ -529,7 +535,11 @@ struct expr *meta_expr_alloc(const struct location *loc, enum nft_meta_keys key)
 
 static void meta_stmt_print(const struct stmt *stmt)
 {
-       printf("meta %s set ", meta_templates[stmt->meta.key].token);
+       if (meta_key_is_qualified(stmt->meta.key))
+               printf("meta %s set ", meta_templates[stmt->meta.key].token);
+       else
+               printf("%s set ", meta_templates[stmt->meta.key].token);
+
        expr_print(stmt->meta.expr);
 }