enum nft_ct_keys key;
const struct ct_template *tmpl;
struct expr *expr;
+ int8_t direction;
};
extern struct stmt *ct_stmt_alloc(const struct location *loc,
enum nft_ct_keys key,
+ int8_t direction,
struct expr *expr);
struct dup_stmt {
struct expr *to;
static void ct_stmt_print(const struct stmt *stmt)
{
- printf("ct %s set ", ct_templates[stmt->ct.key].token);
+ ct_print(stmt->ct.key, stmt->ct.direction);
+ printf(" set ");
expr_print(stmt->ct.expr);
}
};
struct stmt *ct_stmt_alloc(const struct location *loc, enum nft_ct_keys key,
- struct expr *expr)
+ int8_t direction, struct expr *expr)
{
struct stmt *stmt;
stmt->ct.key = key;
stmt->ct.tmpl = &ct_templates[key];
stmt->ct.expr = expr;
+ stmt->ct.direction = direction;
+
return stmt;
}
uint32_t key;
struct stmt *stmt;
struct expr *expr;
+ int8_t dir = -1;
sreg = netlink_parse_register(nle, NFTNL_EXPR_CT_SREG);
expr = netlink_get_register(ctx, loc, sreg);
return netlink_error(ctx, loc,
"ct statement has no expression");
+ if (nftnl_expr_is_set(nle, NFTNL_EXPR_CT_DIR))
+ dir = nftnl_expr_get_u8(nle, NFTNL_EXPR_CT_DIR);
+
key = nftnl_expr_get_u32(nle, NFTNL_EXPR_CT_KEY);
- stmt = ct_stmt_alloc(loc, key, expr);
+ stmt = ct_stmt_alloc(loc, key, dir, expr);
expr_set_type(expr, stmt->ct.tmpl->dtype, stmt->ct.tmpl->byteorder);
ctx->stmt = stmt;
nle = alloc_nft_expr("ct");
netlink_put_register(nle, NFTNL_EXPR_CT_SREG, sreg);
nftnl_expr_set_u32(nle, NFTNL_EXPR_CT_KEY, stmt->ct.key);
+ if (stmt->ct.direction >= 0)
+ nftnl_expr_set_u8(nle, NFTNL_EXPR_CT_DIR,
+ stmt->ct.direction);
+
nftnl_rule_add_expr(ctx->nlr, nle);
}
ct_stmt : CT ct_key SET expr
{
- $$ = ct_stmt_alloc(&@$, $2, $4);
+ $$ = ct_stmt_alloc(&@$, $2, -1, $4);
}
| CT STRING SET expr
{
YYERROR;
}
- $$ = ct_stmt_alloc(&@$, key, $4);
+ $$ = ct_stmt_alloc(&@$, key, -1, $4);
+ }
+ | CT STRING ct_key_dir_optional SET expr
+ {
+ struct error_record *erec;
+ int8_t direction;
+
+ erec = ct_dir_parse(&@$, $2, &direction);
+ if (erec != NULL) {
+ erec_queue(erec, state->msgs);
+ YYERROR;
+ }
+
+ $$ = ct_stmt_alloc(&@$, $3, direction, $5);
}
;