From c5ecdbf752ce0505a6696489d6df03b88cb56b0a Mon Sep 17 00:00:00 2001 From: Laura Garcia Liebana Date: Thu, 15 Mar 2018 09:23:21 +0100 Subject: src: support of dynamic map addition and update of elements The support of dynamic adds and updates are only available for sets and meters. This patch gives such abilities to maps as well. This patch is useful in cases where dynamic population of maps are required, for example, to maintain a persistence during some period of time. Example: table ip nftlb { map persistencia { type ipv4_addr : mark timeout 1h elements = { 192.168.1.132 expires 59m55s : 0x00000064, 192.168.56.101 expires 59m24s : 0x00000065 } } chain pre { type nat hook prerouting priority 0; policy accept; map update \ { @nh,96,32 : numgen inc mod 2 offset 100 } @persistencia } } An example of the netlink generated sequence: nft --debug=netlink add rule ip nftlb pre map add \ { ip saddr : numgen inc mod 2 offset 100 } @persistencia ip nftlb pre [ payload load 4b @ network header + 12 => reg 1 ] [ numgen reg 2 = inc mod 2 offset 100 ] [ dynset add reg_key 1 set persistencia sreg_data 2 ] Signed-off-by: Laura Garcia Liebana Signed-off-by: Pablo Neira Ayuso --- src/netlink_delinearize.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/netlink_delinearize.c') diff --git a/src/netlink_delinearize.c b/src/netlink_delinearize.c index d65aacf8..d225b3e4 100644 --- a/src/netlink_delinearize.c +++ b/src/netlink_delinearize.c @@ -1150,11 +1150,11 @@ static void netlink_parse_dynset(struct netlink_parse_ctx *ctx, const struct location *loc, const struct nftnl_expr *nle) { + struct expr *expr, *expr_data = NULL; + enum nft_registers sreg, sreg_data; const struct nftnl_expr *dnle; - struct expr *expr; struct stmt *stmt, *dstmt; struct set *set; - enum nft_registers sreg; const char *name; name = nftnl_expr_get_str(nle, NFTNL_EXPR_DYNSET_SET_NAME); @@ -1191,11 +1191,21 @@ static void netlink_parse_dynset(struct netlink_parse_ctx *ctx, dstmt = ctx->stmt; } + if (nftnl_expr_is_set(nle, NFTNL_EXPR_DYNSET_SREG_DATA)) { + sreg_data = netlink_parse_register(nle, NFTNL_EXPR_DYNSET_SREG_DATA); + expr_data = netlink_get_register(ctx, loc, sreg_data); + } + if (dstmt != NULL) { stmt = meter_stmt_alloc(loc); stmt->meter.set = set_ref_expr_alloc(loc, set); stmt->meter.key = expr; stmt->meter.stmt = dstmt; + } else if (expr_data != NULL) { + stmt = map_stmt_alloc(loc); + stmt->map.set = set_ref_expr_alloc(loc, set); + stmt->map.map = map_expr_alloc(loc, expr, expr_data); + stmt->map.op = nftnl_expr_get_u32(nle, NFTNL_EXPR_DYNSET_OP); } else { stmt = set_stmt_alloc(loc); stmt->set.set = set_ref_expr_alloc(loc, set); -- cgit v1.2.3