path: root/src/netlink_linearize.c
diff options
authorArturo Borrero <>2014-03-12 19:03:19 +0100
committerPablo Neira Ayuso <>2014-03-13 14:16:45 +0100
commitb573748a755f5f60449b53d85fb13093461530fb (patch)
treec8f4cba80408638478fd4e0760c139855fc78482 /src/netlink_linearize.c
parentd8118b445fa6ef44e839d9717b10dbf8d095feaa (diff)
ct: add support for setting ct mark
This patch adds the possibility to set ct keys using nft. Currently, the connection mark is supported. This functionality enables creating rules performing the same action as iptables -j CONNMARK --save-mark. For example: table ip filter { chain postrouting { type filter hook postrouting priority 0; ip protocol icmp ip daddr ct mark set meta mark } } My patch is based on the original by Kristian Evensen <>. I simply did a rebase and some testing. To test, I added rules like these: counter meta mark set 1 counter counter ct mark set mark counter counter ct mark 1 counter The last matching worked as expected, which means the second rule is also working as expected. Signed-off-by: Arturo Borrero Gonzalez <> Acked-by: Kristian Evensen <> Signed-off-by: Pablo Neira Ayuso <>
Diffstat (limited to 'src/netlink_linearize.c')
1 files changed, 18 insertions, 0 deletions
diff --git a/src/netlink_linearize.c b/src/netlink_linearize.c
index 9d59374c..e80646b6 100644
--- a/src/netlink_linearize.c
+++ b/src/netlink_linearize.c
@@ -662,6 +662,22 @@ static void netlink_gen_queue_stmt(struct netlink_linearize_ctx *ctx,
nft_rule_add_expr(ctx->nlr, nle);
+static void netlink_gen_ct_stmt(struct netlink_linearize_ctx *ctx,
+ const struct stmt *stmt)
+ struct nft_rule_expr *nle;
+ enum nft_registers sreg;
+ sreg = get_register(ctx);
+ netlink_gen_expr(ctx, stmt->ct.expr, sreg);
+ release_register(ctx);
+ nle = alloc_nft_expr("ct");
+ nft_rule_expr_set_u32(nle, NFT_EXPR_CT_SREG, sreg);
+ nft_rule_expr_set_u32(nle, NFT_EXPR_CT_KEY, stmt->ct.key);
+ nft_rule_add_expr(ctx->nlr, nle);
static void netlink_gen_stmt(struct netlink_linearize_ctx *ctx,
const struct stmt *stmt)
@@ -684,6 +700,8 @@ static void netlink_gen_stmt(struct netlink_linearize_ctx *ctx,
return netlink_gen_nat_stmt(ctx, stmt);
return netlink_gen_queue_stmt(ctx, stmt);
+ case STMT_CT:
+ return netlink_gen_ct_stmt(ctx, stmt);
BUG("unknown statement type %s\n", stmt->ops->name);