* [PATCH nft,v2 0/9] netmap support for nftables
@ 2020-04-27 23:12 Pablo Neira Ayuso
2020-04-27 23:12 ` [PATCH nft,v2 1/9] src: NAT support for intervals in maps Pablo Neira Ayuso
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: Pablo Neira Ayuso @ 2020-04-27 23:12 UTC (permalink / raw)
To: netfilter-devel
Hi,
This is v2 of the netmap support for nftables, this round includes:
* Fix anonymous sets with more than one single element.
* Add tests/py and tests/shell.
Not directly related, but also included in this patch:
* Fix a crash in simple nat concatenation (no map).
* Restore --debug=netlink with sets.
* Remove bogus tests/py with service name range.
Pablo Neira Ayuso (9):
src: NAT support for intervals in maps
include: resync nf_nat.h kernel header
src: add netmap support
src: add STMT_NAT_F_CONCAT flag and use it
evaluate: fix crash when handling concatenation without map
tests: py: concatenation, netmap and nat mappings
mnl: restore --debug=netlink output with sets
tests: py: remove range test with service names
tests: shell: add NAT mappings tests
include/expression.h | 2 +
include/linux/netfilter/nf_nat.h | 15 ++++-
include/statement.h | 8 ++-
src/evaluate.c | 50 +++++++++++++-
src/mnl.c | 10 ++-
src/netlink.c | 66 ++++++++++++++++++-
src/netlink_delinearize. | 0
src/netlink_delinearize.c | 45 ++++++++++++-
src/netlink_linearize.c | 14 +++-
src/parser_bison.y | 53 ++++++++++++++-
src/rule.c | 3 +
src/statement.c | 6 +-
tests/py/inet/dccp.t | 1 -
tests/py/ip/snat.t | 4 ++
tests/py/ip/snat.t.payload | 27 ++++++++
tests/shell/testcases/sets/0046netmap_0 | 14 ++++
tests/shell/testcases/sets/0047nat_0 | 20 ++++++
.../testcases/sets/dumps/0046netmap_0.nft | 6 ++
.../shell/testcases/sets/dumps/0047nat_0.nft | 13 ++++
19 files changed, 343 insertions(+), 14 deletions(-)
create mode 100644 src/netlink_delinearize.
create mode 100755 tests/shell/testcases/sets/0046netmap_0
create mode 100755 tests/shell/testcases/sets/0047nat_0
create mode 100644 tests/shell/testcases/sets/dumps/0046netmap_0.nft
create mode 100644 tests/shell/testcases/sets/dumps/0047nat_0.nft
--
2.20.1
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH nft,v2 1/9] src: NAT support for intervals in maps
2020-04-27 23:12 [PATCH nft,v2 0/9] netmap support for nftables Pablo Neira Ayuso
@ 2020-04-27 23:12 ` Pablo Neira Ayuso
2020-04-27 23:12 ` [PATCH nft,v2 2/9] include: resync nf_nat.h kernel header Pablo Neira Ayuso
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Pablo Neira Ayuso @ 2020-04-27 23:12 UTC (permalink / raw)
To: netfilter-devel
This patch allows you to specify an interval of IP address in maps.
table ip x {
chain y {
type nat hook postrouting priority srcnat; policy accept;
snat ip interval to ip saddr map { 10.141.11.4 : 192.168.2.2-192.168.2.4 }
}
}
The example above performs SNAT to packets that comes from 10.141.11.4
to an interval of IP addresses from 192.168.2.2 to 192.168.2.4 (both
included).
You can also combine this with dynamic maps:
table ip x {
map y {
type ipv4_addr : interval ipv4_addr
flags interval
elements = { 10.141.10.0/24 : 192.168.2.2-192.168.2.4 }
}
chain y {
type nat hook postrouting priority srcnat; policy accept;
snat ip interval to ip saddr map @y
}
}
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
include/expression.h | 2 ++
include/statement.h | 5 +++
src/evaluate.c | 45 ++++++++++++++++++++++++--
src/mnl.c | 5 ++-
src/netlink.c | 66 ++++++++++++++++++++++++++++++++++++++-
src/netlink_delinearize.c | 39 +++++++++++++++++++++++
src/netlink_linearize.c | 8 +++++
src/parser_bison.y | 34 ++++++++++++++++++++
src/rule.c | 3 ++
src/statement.c | 2 ++
10 files changed, 205 insertions(+), 4 deletions(-)
diff --git a/include/expression.h b/include/expression.h
index 87c39e5de08a..359348275a04 100644
--- a/include/expression.h
+++ b/include/expression.h
@@ -184,6 +184,7 @@ const struct expr_ops *expr_ops_by_type(enum expr_types etype);
* @EXPR_F_PROTOCOL: expressions describes upper layer protocol
* @EXPR_F_INTERVAL_END: set member ends an open interval
* @EXPR_F_BOOLEAN: expression is boolean (set by relational expr on LHS)
+ * @EXPR_F_INTERVAL: expression describes a interval
*/
enum expr_flags {
EXPR_F_CONSTANT = 0x1,
@@ -191,6 +192,7 @@ enum expr_flags {
EXPR_F_PROTOCOL = 0x4,
EXPR_F_INTERVAL_END = 0x8,
EXPR_F_BOOLEAN = 0x10,
+ EXPR_F_INTERVAL = 0x20,
};
#include <payload.h>
diff --git a/include/statement.h b/include/statement.h
index 8fb459ca1cd4..8427f47e4071 100644
--- a/include/statement.h
+++ b/include/statement.h
@@ -119,6 +119,10 @@ enum nft_nat_etypes {
extern const char *nat_etype2str(enum nft_nat_etypes type);
+enum {
+ STMT_NAT_F_INTERVAL = (1 << 0),
+};
+
struct nat_stmt {
enum nft_nat_etypes type;
struct expr *addr;
@@ -126,6 +130,7 @@ struct nat_stmt {
uint32_t flags;
uint8_t family;
bool ipportmap;
+ uint32_t type_flags;
};
extern struct stmt *nat_stmt_alloc(const struct location *loc,
diff --git a/src/evaluate.c b/src/evaluate.c
index 759b17366f68..a116f7b66e07 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -1446,6 +1446,9 @@ static int expr_evaluate_map(struct eval_ctx *ctx, struct expr **expr)
if (binop_transfer(ctx, expr) < 0)
return -1;
+ if (ctx->set->data->flags & EXPR_F_INTERVAL)
+ ctx->set->data->len *= 2;
+
ctx->set->key->len = ctx->ectx.len;
ctx->set = NULL;
map = *expr;
@@ -1486,6 +1489,7 @@ static int expr_evaluate_mapping(struct eval_ctx *ctx, struct expr **expr)
{
struct expr *mapping = *expr;
struct set *set = ctx->set;
+ uint32_t datalen;
if (set == NULL)
return expr_error(ctx->msgs, mapping,
@@ -1502,7 +1506,13 @@ static int expr_evaluate_mapping(struct eval_ctx *ctx, struct expr **expr)
mapping->flags |= mapping->left->flags & EXPR_F_SINGLETON;
if (set->data) {
- expr_set_context(&ctx->ectx, set->data->dtype, set->data->len);
+ if (!set_is_anonymous(set->flags) &&
+ set->data->flags & EXPR_F_INTERVAL)
+ datalen = set->data->len / 2;
+ else
+ datalen = set->data->len;
+
+ expr_set_context(&ctx->ectx, set->data->dtype, datalen);
} else {
assert((set->flags & NFT_SET_MAP) == 0);
}
@@ -1512,7 +1522,14 @@ static int expr_evaluate_mapping(struct eval_ctx *ctx, struct expr **expr)
if (!expr_is_constant(mapping->right))
return expr_error(ctx->msgs, mapping->right,
"Value must be a constant");
- if (!expr_is_singleton(mapping->right))
+
+ if (set_is_anonymous(set->flags) &&
+ (mapping->right->etype == EXPR_RANGE ||
+ mapping->right->etype == EXPR_PREFIX))
+ set->data->flags |= EXPR_F_INTERVAL;
+
+ if (!(set->data->flags & EXPR_F_INTERVAL) &&
+ !expr_is_singleton(mapping->right))
return expr_error(ctx->msgs, mapping->right,
"Value must be a singleton");
@@ -2970,6 +2987,27 @@ static int stmt_evaluate_nat(struct eval_ctx *ctx, struct stmt *stmt)
if (err < 0)
return err;
}
+
+ if (stmt->nat.type_flags & STMT_NAT_F_INTERVAL) {
+ switch (stmt->nat.addr->etype) {
+ case EXPR_MAP:
+ if (!(stmt->nat.addr->mappings->set->data->flags & EXPR_F_INTERVAL))
+ return expr_error(ctx->msgs, stmt->nat.addr,
+ "map is not defined as interval");
+ break;
+ case EXPR_RANGE:
+ case EXPR_PREFIX:
+ break;
+ default:
+ return expr_error(ctx->msgs, stmt->nat.addr,
+ "neither prefix, range nor map expression");
+ }
+
+ stmt->flags |= STMT_F_TERMINAL;
+
+ return 0;
+ }
+
if (stmt->nat.proto != NULL) {
err = nat_evaluate_transport(ctx, stmt, &stmt->nat.proto);
if (err < 0)
@@ -3477,6 +3515,9 @@ static int set_evaluate(struct eval_ctx *ctx, struct set *set)
return set_error(ctx, set, "map definition does not "
"specify mapping data type");
+ if (set->data->flags & EXPR_F_INTERVAL)
+ set->data->len *= 2;
+
if (set->data->etype == EXPR_CONCAT &&
expr_evaluate_concat(ctx, &set->data, false) < 0)
return -1;
diff --git a/src/mnl.c b/src/mnl.c
index 3c009fab6dcf..fb34ecb3dece 100644
--- a/src/mnl.c
+++ b/src/mnl.c
@@ -1012,8 +1012,11 @@ int mnl_nft_set_add(struct netlink_ctx *ctx, struct cmd *cmd,
memory_allocation_error();
set_key_expression(ctx, set->key, set->flags, udbuf, NFTNL_UDATA_SET_KEY_TYPEOF);
- if (set->data)
+ if (set->data) {
set_key_expression(ctx, set->data, set->flags, udbuf, NFTNL_UDATA_SET_DATA_TYPEOF);
+ nftnl_udata_put_u32(udbuf, NFTNL_UDATA_SET_DATA_INTERVAL,
+ !!(set->data->flags & EXPR_F_INTERVAL));
+ }
if (set->desc.field_len[0]) {
nftnl_set_set_data(nls, NFTNL_SET_DESC_CONCAT,
diff --git a/src/netlink.c b/src/netlink.c
index 7b7ef39e7807..d83a79bce6ca 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -176,6 +176,8 @@ static struct nftnl_set_elem *alloc_nftnl_setelem(const struct expr *set,
assert(nld.len > 0);
/* fallthrough */
case EXPR_VALUE:
+ case EXPR_RANGE:
+ case EXPR_PREFIX:
nftnl_set_elem_set(nlse, NFTNL_SET_ELEM_DATA,
nld.value, nld.len);
break;
@@ -296,6 +298,38 @@ static void netlink_gen_verdict(const struct expr *expr,
}
}
+static void netlink_gen_range(const struct expr *expr,
+ struct nft_data_linearize *nld)
+{
+ unsigned int len = div_round_up(expr->left->len, BITS_PER_BYTE) * 2;
+ unsigned char data[len];
+ unsigned int offset = 0;
+
+ memset(data, 0, len);
+ offset = netlink_export_pad(data, expr->left->value, expr->left);
+ netlink_export_pad(data + offset, expr->right->value, expr->right);
+ memcpy(nld->value, data, len);
+ nld->len = len;
+}
+
+static void netlink_gen_prefix(const struct expr *expr,
+ struct nft_data_linearize *nld)
+{
+ unsigned int len = div_round_up(expr->len, BITS_PER_BYTE) * 2;
+ unsigned char data[len];
+ int offset;
+ mpz_t v;
+
+ offset = netlink_export_pad(data, expr->prefix->value, expr);
+ mpz_init_bitmask(v, expr->len - expr->prefix_len);
+ mpz_add(v, expr->prefix->value, v);
+ netlink_export_pad(data + offset, v, expr->prefix);
+ mpz_clear(v);
+
+ memcpy(nld->value, data, len);
+ nld->len = len;
+}
+
void netlink_gen_data(const struct expr *expr, struct nft_data_linearize *data)
{
switch (expr->etype) {
@@ -305,6 +339,10 @@ void netlink_gen_data(const struct expr *expr, struct nft_data_linearize *data)
return netlink_gen_concat_data(expr, data);
case EXPR_VERDICT:
return netlink_gen_verdict(expr, data);
+ case EXPR_RANGE:
+ return netlink_gen_range(expr, data);
+ case EXPR_PREFIX:
+ return netlink_gen_prefix(expr, data);
default:
BUG("invalid data expression type %s\n", expr_name(expr));
}
@@ -618,6 +656,7 @@ static int set_parse_udata_cb(const struct nftnl_udata *attr, void *data)
case NFTNL_UDATA_SET_KEYBYTEORDER:
case NFTNL_UDATA_SET_DATABYTEORDER:
case NFTNL_UDATA_SET_MERGE_ELEMENTS:
+ case NFTNL_UDATA_SET_DATA_INTERVAL:
if (len != sizeof(uint32_t))
return -1;
break;
@@ -701,6 +740,7 @@ struct set *netlink_delinearize_set(struct netlink_ctx *ctx,
struct expr *typeof_expr_key, *typeof_expr_data;
uint32_t flags, key, objtype = 0;
const struct datatype *dtype;
+ uint32_t data_interval = 0;
bool automerge = false;
const char *udata;
struct set *set;
@@ -724,6 +764,7 @@ struct set *netlink_delinearize_set(struct netlink_ctx *ctx,
GET_U32_UDATA(keybyteorder, NFTNL_UDATA_SET_KEYBYTEORDER);
GET_U32_UDATA(databyteorder, NFTNL_UDATA_SET_DATABYTEORDER);
GET_U32_UDATA(automerge, NFTNL_UDATA_SET_MERGE_ELEMENTS);
+ GET_U32_UDATA(data_interval, NFTNL_UDATA_SET_DATA_INTERVAL);
#undef GET_U32_UDATA
typeof_expr_key = set_make_key(ud[NFTNL_UDATA_SET_KEY_TYPEOF]);
@@ -792,6 +833,9 @@ struct set *netlink_delinearize_set(struct netlink_ctx *ctx,
typeof_expr_key = NULL;
}
+ if (data_interval)
+ set->data->flags |= EXPR_F_INTERVAL;
+
if (dtype != datatype)
datatype_free(datatype);
}
@@ -885,6 +929,24 @@ void alloc_setelem_cache(const struct expr *set, struct nftnl_set *nls)
}
}
+static struct expr *netlink_parse_interval_elem(const struct datatype *dtype,
+ struct expr *expr)
+{
+ unsigned int len = div_round_up(expr->len, BITS_PER_BYTE);
+ struct expr *left, *right;
+ char data[len];
+
+ mpz_export_data(data, expr->value, dtype->byteorder, len);
+ left = constant_expr_alloc(&internal_location, dtype,
+ dtype->byteorder,
+ (len / 2) * BITS_PER_BYTE, &data[0]);
+ right = constant_expr_alloc(&internal_location, dtype,
+ dtype->byteorder,
+ (len / 2) * BITS_PER_BYTE, &data[len / 2]);
+
+ return range_expr_alloc(&expr->location, left, right);
+}
+
static struct expr *netlink_parse_concat_elem(const struct datatype *dtype,
struct expr *data)
{
@@ -1021,7 +1083,9 @@ key_end:
datatype_set(data, set->data->dtype);
data->byteorder = set->data->byteorder;
- if (set->data->dtype->subtypes)
+ if (set->data->flags & EXPR_F_INTERVAL)
+ data = netlink_parse_interval_elem(set->data->dtype, data);
+ else if (set->data->dtype->subtypes)
data = netlink_parse_concat_elem(set->data->dtype, data);
if (data->byteorder == BYTEORDER_HOST_ENDIAN)
diff --git a/src/netlink_delinearize.c b/src/netlink_delinearize.c
index 79efda123c14..f41223a8e24a 100644
--- a/src/netlink_delinearize.c
+++ b/src/netlink_delinearize.c
@@ -979,6 +979,38 @@ static void netlink_parse_reject(struct netlink_parse_ctx *ctx,
ctx->stmt = stmt;
}
+static bool is_nat_addr_map(const struct expr *addr, uint8_t family)
+{
+ const struct expr *mappings, *data;
+ const struct set *set;
+
+ if (!addr ||
+ expr_ops(addr)->type != EXPR_MAP)
+ return false;
+
+ mappings = addr->right;
+ if (expr_ops(mappings)->type != EXPR_SET_REF)
+ return false;
+
+ set = mappings->set;
+ data = set->data;
+
+ if (!(data->flags & EXPR_F_INTERVAL))
+ return false;
+
+ /* if we're dealing with an address:address map,
+ * the length will be bit_sizeof(addr) + 32 (one register).
+ */
+ switch (family) {
+ case NFPROTO_IPV4:
+ return data->len == 32 + 32;
+ case NFPROTO_IPV6:
+ return data->len == 128 + 128;
+ }
+
+ return false;
+}
+
static bool is_nat_proto_map(const struct expr *addr, uint8_t family)
{
const struct expr *mappings, *data;
@@ -1046,6 +1078,13 @@ static void netlink_parse_nat(struct netlink_parse_ctx *ctx,
stmt->nat.addr = addr;
}
+ if (is_nat_addr_map(addr, family)) {
+ stmt->nat.family = family;
+ stmt->nat.type_flags |= STMT_NAT_F_INTERVAL;
+ ctx->stmt = stmt;
+ return;
+ }
+
reg2 = netlink_parse_register(nle, NFTNL_EXPR_NAT_REG_ADDR_MAX);
if (reg2 && reg2 != reg1) {
addr = netlink_get_register(ctx, loc, reg2);
diff --git a/src/netlink_linearize.c b/src/netlink_linearize.c
index e70e63b336cd..944fcdae4ee9 100644
--- a/src/netlink_linearize.c
+++ b/src/netlink_linearize.c
@@ -1117,6 +1117,14 @@ static void netlink_gen_nat_stmt(struct netlink_linearize_ctx *ctx,
netlink_gen_expr(ctx, stmt->nat.addr, amin_reg);
netlink_put_register(nle, NFTNL_EXPR_NAT_REG_ADDR_MIN,
amin_reg);
+ if (stmt->nat.addr->etype == EXPR_MAP &&
+ stmt->nat.addr->mappings->set->data->flags & EXPR_F_INTERVAL) {
+ amax_reg = get_register(ctx, NULL);
+ registers++;
+ amin_reg += netlink_register_space(nat_addrlen(family));
+ netlink_put_register(nle, NFTNL_EXPR_NAT_REG_ADDR_MAX,
+ amin_reg);
+ }
}
if (stmt->nat.ipportmap) {
diff --git a/src/parser_bison.y b/src/parser_bison.y
index 0e04a0e4fcf0..731a5b3ecdf4 100644
--- a/src/parser_bison.y
+++ b/src/parser_bison.y
@@ -1792,6 +1792,17 @@ map_block : /* empty */ { $$ = $<set>-1; }
$1->flags |= NFT_SET_MAP;
$$ = $1;
}
+ | map_block TYPE
+ data_type_expr COLON INTERVAL data_type_expr
+ stmt_separator
+ {
+ $1->key = $3;
+ $1->data = $6;
+ $1->data->flags |= EXPR_F_INTERVAL;
+
+ $1->flags |= NFT_SET_MAP;
+ $$ = $1;
+ }
| map_block TYPEOF
typeof_expr COLON typeof_expr
stmt_separator
@@ -1803,6 +1814,18 @@ map_block : /* empty */ { $$ = $<set>-1; }
$1->flags |= NFT_SET_MAP;
$$ = $1;
}
+ | map_block TYPEOF
+ typeof_expr COLON INTERVAL typeof_expr
+ stmt_separator
+ {
+ $1->key = $3;
+ datatype_set($1->key, $3->dtype);
+ $1->data = $6;
+ $1->data->flags |= EXPR_F_INTERVAL;
+
+ $1->flags |= NFT_SET_MAP;
+ $$ = $1;
+ }
| map_block TYPE
data_type_expr COLON COUNTER
stmt_separator
@@ -3171,6 +3194,17 @@ nat_stmt_args : stmt_expr
$<stmt>0->nat.addr = $6;
$<stmt>0->nat.ipportmap = true;
}
+ | nf_key_proto INTERVAL TO stmt_expr
+ {
+ $<stmt>0->nat.family = $1;
+ $<stmt>0->nat.addr = $4;
+ $<stmt>0->nat.type_flags = STMT_NAT_F_INTERVAL;
+ }
+ | INTERVAL TO stmt_expr
+ {
+ $<stmt>0->nat.addr = $3;
+ $<stmt>0->nat.type_flags = STMT_NAT_F_INTERVAL;
+ }
;
masq_stmt : masq_stmt_alloc masq_stmt_args
diff --git a/src/rule.c b/src/rule.c
index a312693f4edc..633ca13639ad 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -462,6 +462,9 @@ static void set_print_key_and_data(const struct set *set, struct output_ctx *oct
if (set_is_datamap(set->flags)) {
nft_print(octx, " : ");
+ if (set->data->flags & EXPR_F_INTERVAL)
+ nft_print(octx, "interval ");
+
if (use_typeof)
expr_print(set->data, octx);
else
diff --git a/src/statement.c b/src/statement.c
index 182edac8f2ec..5bbc054055bc 100644
--- a/src/statement.c
+++ b/src/statement.c
@@ -609,6 +609,8 @@ static void nat_stmt_print(const struct stmt *stmt, struct output_ctx *octx)
if (stmt->nat.ipportmap)
nft_print(octx, " addr . port");
+ else if (stmt->nat.type_flags & STMT_NAT_F_INTERVAL)
+ nft_print(octx, " interval");
nft_print(octx, " to");
}
--
2.20.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH nft,v2 2/9] include: resync nf_nat.h kernel header
2020-04-27 23:12 [PATCH nft,v2 0/9] netmap support for nftables Pablo Neira Ayuso
2020-04-27 23:12 ` [PATCH nft,v2 1/9] src: NAT support for intervals in maps Pablo Neira Ayuso
@ 2020-04-27 23:12 ` Pablo Neira Ayuso
2020-04-27 23:12 ` [PATCH nft,v2 3/9] src: add netmap support Pablo Neira Ayuso
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Pablo Neira Ayuso @ 2020-04-27 23:12 UTC (permalink / raw)
To: netfilter-devel
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
include/linux/netfilter/nf_nat.h | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/include/linux/netfilter/nf_nat.h b/include/linux/netfilter/nf_nat.h
index 0880781ad7b6..4a95c0db14d4 100644
--- a/include/linux/netfilter/nf_nat.h
+++ b/include/linux/netfilter/nf_nat.h
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
#ifndef _NETFILTER_NF_NAT_H
#define _NETFILTER_NF_NAT_H
@@ -9,6 +10,7 @@
#define NF_NAT_RANGE_PROTO_RANDOM (1 << 2)
#define NF_NAT_RANGE_PERSISTENT (1 << 3)
#define NF_NAT_RANGE_PROTO_RANDOM_FULLY (1 << 4)
+#define NF_NAT_RANGE_PROTO_OFFSET (1 << 5)
#define NF_NAT_RANGE_PROTO_RANDOM_ALL \
(NF_NAT_RANGE_PROTO_RANDOM | NF_NAT_RANGE_PROTO_RANDOM_FULLY)
@@ -16,7 +18,7 @@
#define NF_NAT_RANGE_MASK \
(NF_NAT_RANGE_MAP_IPS | NF_NAT_RANGE_PROTO_SPECIFIED | \
NF_NAT_RANGE_PROTO_RANDOM | NF_NAT_RANGE_PERSISTENT | \
- NF_NAT_RANGE_PROTO_RANDOM_FULLY)
+ NF_NAT_RANGE_PROTO_RANDOM_FULLY | NF_NAT_RANGE_PROTO_OFFSET)
struct nf_nat_ipv4_range {
unsigned int flags;
@@ -39,4 +41,13 @@ struct nf_nat_range {
union nf_conntrack_man_proto max_proto;
};
+struct nf_nat_range2 {
+ unsigned int flags;
+ union nf_inet_addr min_addr;
+ union nf_inet_addr max_addr;
+ union nf_conntrack_man_proto min_proto;
+ union nf_conntrack_man_proto max_proto;
+ union nf_conntrack_man_proto base_proto;
+};
+
#endif /* _NETFILTER_NF_NAT_H */
--
2.20.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH nft,v2 3/9] src: add netmap support
2020-04-27 23:12 [PATCH nft,v2 0/9] netmap support for nftables Pablo Neira Ayuso
2020-04-27 23:12 ` [PATCH nft,v2 1/9] src: NAT support for intervals in maps Pablo Neira Ayuso
2020-04-27 23:12 ` [PATCH nft,v2 2/9] include: resync nf_nat.h kernel header Pablo Neira Ayuso
@ 2020-04-27 23:12 ` Pablo Neira Ayuso
2020-04-27 23:12 ` [PATCH nft,v2 4/9] src: add STMT_NAT_F_CONCAT flag and use it Pablo Neira Ayuso
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Pablo Neira Ayuso @ 2020-04-27 23:12 UTC (permalink / raw)
To: netfilter-devel
This patch allows you to specify an interval of IP address in maps.
table ip x {
chain y {
type nat hook postrouting priority srcnat; policy accept;
snat ip prefix to ip saddr map { 10.141.11.0/24 : 192.168.2.0/24 }
}
}
The example above performs SNAT to packets that comes from
10.141.11.0/24 using the prefix 192.168.2.0/24, e.g. 10.141.11.4 is
mangled to 192.168.2.4.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
include/linux/netfilter/nf_nat.h | 4 +++-
include/statement.h | 1 +
src/netlink_delinearize.c | 4 ++++
src/parser_bison.y | 17 +++++++++++++++++
src/statement.c | 2 ++
5 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/include/linux/netfilter/nf_nat.h b/include/linux/netfilter/nf_nat.h
index 4a95c0db14d4..a64586e77b24 100644
--- a/include/linux/netfilter/nf_nat.h
+++ b/include/linux/netfilter/nf_nat.h
@@ -11,6 +11,7 @@
#define NF_NAT_RANGE_PERSISTENT (1 << 3)
#define NF_NAT_RANGE_PROTO_RANDOM_FULLY (1 << 4)
#define NF_NAT_RANGE_PROTO_OFFSET (1 << 5)
+#define NF_NAT_RANGE_NETMAP (1 << 6)
#define NF_NAT_RANGE_PROTO_RANDOM_ALL \
(NF_NAT_RANGE_PROTO_RANDOM | NF_NAT_RANGE_PROTO_RANDOM_FULLY)
@@ -18,7 +19,8 @@
#define NF_NAT_RANGE_MASK \
(NF_NAT_RANGE_MAP_IPS | NF_NAT_RANGE_PROTO_SPECIFIED | \
NF_NAT_RANGE_PROTO_RANDOM | NF_NAT_RANGE_PERSISTENT | \
- NF_NAT_RANGE_PROTO_RANDOM_FULLY | NF_NAT_RANGE_PROTO_OFFSET)
+ NF_NAT_RANGE_PROTO_RANDOM_FULLY | NF_NAT_RANGE_PROTO_OFFSET | \
+ NF_NAT_RANGE_NETMAP)
struct nf_nat_ipv4_range {
unsigned int flags;
diff --git a/include/statement.h b/include/statement.h
index 8427f47e4071..01fe416c415a 100644
--- a/include/statement.h
+++ b/include/statement.h
@@ -121,6 +121,7 @@ extern const char *nat_etype2str(enum nft_nat_etypes type);
enum {
STMT_NAT_F_INTERVAL = (1 << 0),
+ STMT_NAT_F_PREFIX = (1 << 1),
};
struct nat_stmt {
diff --git a/src/netlink_delinearize.c b/src/netlink_delinearize.c
index f41223a8e24a..b039a1e3c7ac 100644
--- a/src/netlink_delinearize.c
+++ b/src/netlink_delinearize.c
@@ -15,6 +15,7 @@
#include <limits.h>
#include <linux/netfilter/nf_tables.h>
#include <arpa/inet.h>
+#include <linux/netfilter/nf_nat.h>
#include <linux/netfilter.h>
#include <net/ethernet.h>
#include <netlink.h>
@@ -1060,6 +1061,9 @@ static void netlink_parse_nat(struct netlink_parse_ctx *ctx,
if (nftnl_expr_is_set(nle, NFTNL_EXPR_NAT_FLAGS))
stmt->nat.flags = nftnl_expr_get_u32(nle, NFTNL_EXPR_NAT_FLAGS);
+ if (stmt->nat.flags & NF_NAT_RANGE_NETMAP)
+ stmt->nat.type_flags |= STMT_NAT_F_PREFIX;
+
addr = NULL;
reg1 = netlink_parse_register(nle, NFTNL_EXPR_NAT_REG_ADDR_MIN);
if (reg1) {
diff --git a/src/parser_bison.y b/src/parser_bison.y
index 731a5b3ecdf4..3b470cc63235 100644
--- a/src/parser_bison.y
+++ b/src/parser_bison.y
@@ -3205,6 +3205,23 @@ nat_stmt_args : stmt_expr
$<stmt>0->nat.addr = $3;
$<stmt>0->nat.type_flags = STMT_NAT_F_INTERVAL;
}
+ | nf_key_proto PREFIX TO stmt_expr
+ {
+ $<stmt>0->nat.family = $1;
+ $<stmt>0->nat.addr = $4;
+ $<stmt>0->nat.type_flags =
+ STMT_NAT_F_PREFIX |
+ STMT_NAT_F_INTERVAL;
+ $<stmt>0->nat.flags |= NF_NAT_RANGE_NETMAP;
+ }
+ | PREFIX TO stmt_expr
+ {
+ $<stmt>0->nat.addr = $3;
+ $<stmt>0->nat.type_flags =
+ STMT_NAT_F_PREFIX |
+ STMT_NAT_F_INTERVAL;
+ $<stmt>0->nat.flags |= NF_NAT_RANGE_NETMAP;
+ }
;
masq_stmt : masq_stmt_alloc masq_stmt_args
diff --git a/src/statement.c b/src/statement.c
index 5bbc054055bc..8a1cd6e04f61 100644
--- a/src/statement.c
+++ b/src/statement.c
@@ -609,6 +609,8 @@ static void nat_stmt_print(const struct stmt *stmt, struct output_ctx *octx)
if (stmt->nat.ipportmap)
nft_print(octx, " addr . port");
+ else if (stmt->nat.type_flags & STMT_NAT_F_PREFIX)
+ nft_print(octx, " prefix");
else if (stmt->nat.type_flags & STMT_NAT_F_INTERVAL)
nft_print(octx, " interval");
--
2.20.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH nft,v2 4/9] src: add STMT_NAT_F_CONCAT flag and use it
2020-04-27 23:12 [PATCH nft,v2 0/9] netmap support for nftables Pablo Neira Ayuso
` (2 preceding siblings ...)
2020-04-27 23:12 ` [PATCH nft,v2 3/9] src: add netmap support Pablo Neira Ayuso
@ 2020-04-27 23:12 ` Pablo Neira Ayuso
2020-04-27 23:12 ` [PATCH nft,v2 5/9] evaluate: fix crash when handling concatenation without map Pablo Neira Ayuso
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Pablo Neira Ayuso @ 2020-04-27 23:12 UTC (permalink / raw)
To: netfilter-devel
Replace ipportmap boolean field by flags.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
include/statement.h | 2 +-
src/evaluate.c | 2 +-
src/netlink_delinearize. | 0
src/netlink_delinearize.c | 2 +-
src/netlink_linearize.c | 6 +++---
src/parser_bison.y | 2 +-
src/statement.c | 2 +-
7 files changed, 8 insertions(+), 8 deletions(-)
create mode 100644 src/netlink_delinearize.
diff --git a/include/statement.h b/include/statement.h
index 01fe416c415a..7d96b3947dfc 100644
--- a/include/statement.h
+++ b/include/statement.h
@@ -122,6 +122,7 @@ extern const char *nat_etype2str(enum nft_nat_etypes type);
enum {
STMT_NAT_F_INTERVAL = (1 << 0),
STMT_NAT_F_PREFIX = (1 << 1),
+ STMT_NAT_F_CONCAT = (1 << 2),
};
struct nat_stmt {
@@ -130,7 +131,6 @@ struct nat_stmt {
struct expr *proto;
uint32_t flags;
uint8_t family;
- bool ipportmap;
uint32_t type_flags;
};
diff --git a/src/evaluate.c b/src/evaluate.c
index a116f7b66e07..cad65cfb7343 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -2973,7 +2973,7 @@ static int stmt_evaluate_nat(struct eval_ctx *ctx, struct stmt *stmt)
if (err < 0)
return err;
- if (stmt->nat.ipportmap) {
+ if (stmt->nat.type_flags & STMT_NAT_F_CONCAT) {
err = stmt_evaluate_nat_map(ctx, stmt);
if (err < 0)
return err;
diff --git a/src/netlink_delinearize. b/src/netlink_delinearize.
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/src/netlink_delinearize.c b/src/netlink_delinearize.c
index b039a1e3c7ac..772559c838f5 100644
--- a/src/netlink_delinearize.c
+++ b/src/netlink_delinearize.c
@@ -1110,7 +1110,7 @@ static void netlink_parse_nat(struct netlink_parse_ctx *ctx,
if (is_nat_proto_map(addr, family)) {
stmt->nat.family = family;
- stmt->nat.ipportmap = true;
+ stmt->nat.type_flags |= STMT_NAT_F_CONCAT;
ctx->stmt = stmt;
return;
}
diff --git a/src/netlink_linearize.c b/src/netlink_linearize.c
index 944fcdae4ee9..08f7f89f1066 100644
--- a/src/netlink_linearize.c
+++ b/src/netlink_linearize.c
@@ -1127,15 +1127,15 @@ static void netlink_gen_nat_stmt(struct netlink_linearize_ctx *ctx,
}
}
- if (stmt->nat.ipportmap) {
+ if (stmt->nat.type_flags & STMT_NAT_F_CONCAT) {
/* nat_stmt evaluation step doesn't allow
- * stmt->nat.ipportmap && stmt->nat.proto.
+ * STMT_NAT_F_CONCAT && stmt->nat.proto.
*/
assert(stmt->nat.proto == NULL);
pmin_reg = amin_reg;
- /* if ipportmap is set, the mapped type is a
+ /* if STMT_NAT_F_CONCAT is set, the mapped type is a
* concatenation of 'addr . inet_service'.
* The map lookup will then return the
* concatenated value, so we need to skip
diff --git a/src/parser_bison.y b/src/parser_bison.y
index 3b470cc63235..b1e869d568a1 100644
--- a/src/parser_bison.y
+++ b/src/parser_bison.y
@@ -3192,7 +3192,7 @@ nat_stmt_args : stmt_expr
{
$<stmt>0->nat.family = $1;
$<stmt>0->nat.addr = $6;
- $<stmt>0->nat.ipportmap = true;
+ $<stmt>0->nat.type_flags = STMT_NAT_F_CONCAT;
}
| nf_key_proto INTERVAL TO stmt_expr
{
diff --git a/src/statement.c b/src/statement.c
index 8a1cd6e04f61..21a1bc8d40dd 100644
--- a/src/statement.c
+++ b/src/statement.c
@@ -607,7 +607,7 @@ static void nat_stmt_print(const struct stmt *stmt, struct output_ctx *octx)
break;
}
- if (stmt->nat.ipportmap)
+ if (stmt->nat.type_flags & STMT_NAT_F_CONCAT)
nft_print(octx, " addr . port");
else if (stmt->nat.type_flags & STMT_NAT_F_PREFIX)
nft_print(octx, " prefix");
--
2.20.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH nft,v2 5/9] evaluate: fix crash when handling concatenation without map
2020-04-27 23:12 [PATCH nft,v2 0/9] netmap support for nftables Pablo Neira Ayuso
` (3 preceding siblings ...)
2020-04-27 23:12 ` [PATCH nft,v2 4/9] src: add STMT_NAT_F_CONCAT flag and use it Pablo Neira Ayuso
@ 2020-04-27 23:12 ` Pablo Neira Ayuso
2020-04-27 23:12 ` [PATCH nft,v2 6/9] tests: py: concatenation, netmap and nat mappings Pablo Neira Ayuso
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Pablo Neira Ayuso @ 2020-04-27 23:12 UTC (permalink / raw)
To: netfilter-devel
Fix a crash when map is not specified, e.g.
nft add rule x y snat ip addr . port to 1.1.1.1 . 22
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
src/evaluate.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/evaluate.c b/src/evaluate.c
index cad65cfb7343..8c227eb11402 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -2924,6 +2924,9 @@ static int stmt_evaluate_nat_map(struct eval_ctx *ctx, struct stmt *stmt)
if (expr_evaluate(ctx, &stmt->nat.addr))
return -1;
+ if (stmt->nat.addr->etype != EXPR_MAP)
+ return 0;
+
data = stmt->nat.addr->mappings->set->data;
datatype_set(data, dtype);
--
2.20.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH nft,v2 6/9] tests: py: concatenation, netmap and nat mappings
2020-04-27 23:12 [PATCH nft,v2 0/9] netmap support for nftables Pablo Neira Ayuso
` (4 preceding siblings ...)
2020-04-27 23:12 ` [PATCH nft,v2 5/9] evaluate: fix crash when handling concatenation without map Pablo Neira Ayuso
@ 2020-04-27 23:12 ` Pablo Neira Ayuso
2020-04-27 23:12 ` [PATCH nft,v2 7/9] mnl: restore --debug=netlink output with sets Pablo Neira Ayuso
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Pablo Neira Ayuso @ 2020-04-27 23:12 UTC (permalink / raw)
To: netfilter-devel
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
tests/py/ip/snat.t | 4 ++++
tests/py/ip/snat.t.payload | 27 +++++++++++++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/tests/py/ip/snat.t b/tests/py/ip/snat.t
index 7281bf5fa7e0..c6e8a8e68f9d 100644
--- a/tests/py/ip/snat.t
+++ b/tests/py/ip/snat.t
@@ -8,3 +8,7 @@ iifname "eth0" tcp dport {80, 90, 23} snat to 192.168.3.2;ok
iifname "eth0" tcp dport != {80, 90, 23} snat to 192.168.3.2;ok
iifname "eth0" tcp dport != 23-34 snat to 192.168.3.2;ok
+
+snat ip addr . port to ip saddr map { 10.141.11.4 : 192.168.2.3 . 80 };ok
+snat ip interval to ip saddr map { 10.141.11.4 : 192.168.2.2-192.168.2.4 };ok
+snat ip prefix to ip saddr map { 10.141.11.0/24 : 192.168.2.0/24 };ok
diff --git a/tests/py/ip/snat.t.payload b/tests/py/ip/snat.t.payload
index 789933ffd650..22befe155dde 100644
--- a/tests/py/ip/snat.t.payload
+++ b/tests/py/ip/snat.t.payload
@@ -60,3 +60,30 @@ ip test-ip4 postrouting
[ immediate reg 1 0x0203a8c0 ]
[ nat snat ip addr_min reg 1 addr_max reg 0 ]
+# snat ip addr . port to ip saddr map { 10.141.11.4 : 192.168.2.3 . 80 }
+__map%d test-ip4 b size 1
+__map%d test-ip4 0
+ element 040b8d0a : 0302a8c0 00005000 0 [end]
+ip
+ [ payload load 4b @ network header + 12 => reg 1 ]
+ [ lookup reg 1 set __map%d dreg 1 ]
+ [ nat snat ip addr_min reg 1 addr_max reg 0 proto_min reg 9 proto_max reg 0 ]
+
+# snat ip interval to ip saddr map { 10.141.11.4 : 192.168.2.2-192.168.2.4 }
+__map%d test-ip4 b size 1
+__map%d test-ip4 0
+ element 040b8d0a : 0202a8c0 0402a8c0 0 [end]
+ip
+ [ payload load 4b @ network header + 12 => reg 1 ]
+ [ lookup reg 1 set __map%d dreg 1 ]
+ [ nat snat ip addr_min reg 1 addr_max reg 9 ]
+
+# snat ip prefix to ip saddr map { 10.141.11.0/24 : 192.168.2.0/24 }
+__map%d test-ip4 f size 3
+__map%d test-ip4 0
+ element 00000000 : 1 [end] element 000b8d0a : 0002a8c0 ff02a8c0 0 [end] element 000c8d0a : 1 [end]
+ip
+ [ payload load 4b @ network header + 12 => reg 1 ]
+ [ lookup reg 1 set __map%d dreg 1 ]
+ [ nat snat ip addr_min reg 1 addr_max reg 9 flags 0x40 ]
+
--
2.20.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH nft,v2 7/9] mnl: restore --debug=netlink output with sets
2020-04-27 23:12 [PATCH nft,v2 0/9] netmap support for nftables Pablo Neira Ayuso
` (5 preceding siblings ...)
2020-04-27 23:12 ` [PATCH nft,v2 6/9] tests: py: concatenation, netmap and nat mappings Pablo Neira Ayuso
@ 2020-04-27 23:12 ` Pablo Neira Ayuso
2020-04-27 23:12 ` [PATCH nft,v2 8/9] tests: py: remove range test with service names Pablo Neira Ayuso
2020-04-27 23:12 ` [PATCH nft,v2 9/9] tests: shell: add NAT mappings tests Pablo Neira Ayuso
8 siblings, 0 replies; 10+ messages in thread
From: Pablo Neira Ayuso @ 2020-04-27 23:12 UTC (permalink / raw)
To: netfilter-devel
(null) (null) b size 1
The debugging output displays table and set names as (null). This patch
sets the table and name before displaying the netlink debugging, then
unset them to not break the extended error support.
Fixes: 086ec6f30c96 ("mnl: extended error support for create command")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
src/mnl.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/src/mnl.c b/src/mnl.c
index fb34ecb3dece..94e80261afb7 100644
--- a/src/mnl.c
+++ b/src/mnl.c
@@ -960,6 +960,8 @@ int mnl_nft_set_add(struct netlink_ctx *ctx, struct cmd *cmd,
memory_allocation_error();
nftnl_set_set_u32(nls, NFTNL_SET_FAMILY, h->family);
+ nftnl_set_set_str(nls, NFTNL_SET_TABLE, h->table.name);
+ nftnl_set_set_str(nls, NFTNL_SET_NAME, h->set.name);
nftnl_set_set_u32(nls, NFTNL_SET_ID, h->set_id);
nftnl_set_set_u32(nls, NFTNL_SET_FLAGS, set->flags);
@@ -1036,6 +1038,9 @@ int mnl_nft_set_add(struct netlink_ctx *ctx, struct cmd *cmd,
netlink_dump_set(nls, ctx);
+ nftnl_set_unset(nls, NFTNL_SET_TABLE);
+ nftnl_set_unset(nls, NFTNL_SET_NAME);
+
nlh = nftnl_nlmsg_build_hdr(nftnl_batch_buffer(ctx->batch),
NFT_MSG_NEWSET,
h->family,
--
2.20.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH nft,v2 8/9] tests: py: remove range test with service names
2020-04-27 23:12 [PATCH nft,v2 0/9] netmap support for nftables Pablo Neira Ayuso
` (6 preceding siblings ...)
2020-04-27 23:12 ` [PATCH nft,v2 7/9] mnl: restore --debug=netlink output with sets Pablo Neira Ayuso
@ 2020-04-27 23:12 ` Pablo Neira Ayuso
2020-04-27 23:12 ` [PATCH nft,v2 9/9] tests: shell: add NAT mappings tests Pablo Neira Ayuso
8 siblings, 0 replies; 10+ messages in thread
From: Pablo Neira Ayuso @ 2020-04-27 23:12 UTC (permalink / raw)
To: netfilter-devel
Service names printing are not default these days, using service names
with ranges is misleading.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
tests/py/inet/dccp.t | 1 -
1 file changed, 1 deletion(-)
diff --git a/tests/py/inet/dccp.t b/tests/py/inet/dccp.t
index f0dd788b8b36..9a81bb2e60f3 100644
--- a/tests/py/inet/dccp.t
+++ b/tests/py/inet/dccp.t
@@ -12,7 +12,6 @@ dccp sport {23, 24, 25};ok
dccp sport != {23, 24, 25};ok
dccp sport { 20-50 };ok
-dccp sport ftp-data - re-mail-ck;ok;dccp sport 20-50
dccp sport 20-50;ok
dccp sport { 20-50};ok
dccp sport != { 20-50};ok
--
2.20.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH nft,v2 9/9] tests: shell: add NAT mappings tests
2020-04-27 23:12 [PATCH nft,v2 0/9] netmap support for nftables Pablo Neira Ayuso
` (7 preceding siblings ...)
2020-04-27 23:12 ` [PATCH nft,v2 8/9] tests: py: remove range test with service names Pablo Neira Ayuso
@ 2020-04-27 23:12 ` Pablo Neira Ayuso
8 siblings, 0 replies; 10+ messages in thread
From: Pablo Neira Ayuso @ 2020-04-27 23:12 UTC (permalink / raw)
To: netfilter-devel
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
tests/shell/testcases/sets/0046netmap_0 | 14 +++++++++++++
tests/shell/testcases/sets/0047nat_0 | 20 +++++++++++++++++++
.../testcases/sets/dumps/0046netmap_0.nft | 6 ++++++
.../shell/testcases/sets/dumps/0047nat_0.nft | 13 ++++++++++++
4 files changed, 53 insertions(+)
create mode 100755 tests/shell/testcases/sets/0046netmap_0
create mode 100755 tests/shell/testcases/sets/0047nat_0
create mode 100644 tests/shell/testcases/sets/dumps/0046netmap_0.nft
create mode 100644 tests/shell/testcases/sets/dumps/0047nat_0.nft
diff --git a/tests/shell/testcases/sets/0046netmap_0 b/tests/shell/testcases/sets/0046netmap_0
new file mode 100755
index 000000000000..2804a4a27ede
--- /dev/null
+++ b/tests/shell/testcases/sets/0046netmap_0
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+EXPECTED="table ip x {
+ chain y {
+ type nat hook postrouting priority srcnat; policy accept;
+ snat ip prefix to ip saddr map { 10.141.11.0/24 : 192.168.2.0/24,
+ 10.141.12.0/24 : 192.168.3.0/24,
+ 10.141.13.0/24 : 192.168.4.0/24 }
+ }
+ }
+"
+
+set -e
+$NFT -f - <<< $EXPECTED
diff --git a/tests/shell/testcases/sets/0047nat_0 b/tests/shell/testcases/sets/0047nat_0
new file mode 100755
index 000000000000..746a6b6d3450
--- /dev/null
+++ b/tests/shell/testcases/sets/0047nat_0
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+EXPECTED="table ip x {
+ map y {
+ type ipv4_addr : interval ipv4_addr
+ flags interval
+ elements = { 10.141.10.0/24 : 192.168.2.2-192.168.2.4,
+ 10.141.11.0/24 : 192.168.4.2-192.168.4.3 }
+ }
+
+ chain y {
+ type nat hook postrouting priority srcnat; policy accept;
+ snat ip interval to ip saddr map @y
+ }
+ }
+"
+
+set -e
+$NFT -f - <<< $EXPECTED
+$NFT add element x y { 10.141.12.0/24 : 192.168.5.10-192.168.5.20 }
diff --git a/tests/shell/testcases/sets/dumps/0046netmap_0.nft b/tests/shell/testcases/sets/dumps/0046netmap_0.nft
new file mode 100644
index 000000000000..7b66e644c05a
--- /dev/null
+++ b/tests/shell/testcases/sets/dumps/0046netmap_0.nft
@@ -0,0 +1,6 @@
+table ip x {
+ chain y {
+ type nat hook postrouting priority srcnat; policy accept;
+ snat ip prefix to ip saddr map { 10.141.11.0/24 : 192.168.2.0-192.168.2.255, 10.141.12.0/24 : 192.168.3.0-192.168.3.255, 10.141.13.0/24 : 192.168.4.0-192.168.4.255 }
+ }
+}
diff --git a/tests/shell/testcases/sets/dumps/0047nat_0.nft b/tests/shell/testcases/sets/dumps/0047nat_0.nft
new file mode 100644
index 000000000000..ebfb174199e1
--- /dev/null
+++ b/tests/shell/testcases/sets/dumps/0047nat_0.nft
@@ -0,0 +1,13 @@
+table ip x {
+ map y {
+ type ipv4_addr : interval ipv4_addr
+ flags interval
+ elements = { 10.141.10.0/24 : 192.168.2.2-192.168.2.4, 10.141.11.0/24 : 192.168.4.2-192.168.4.3,
+ 10.141.12.0/24 : 192.168.5.10-192.168.5.20 }
+ }
+
+ chain y {
+ type nat hook postrouting priority srcnat; policy accept;
+ snat ip interval to ip saddr map @y
+ }
+}
--
2.20.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
end of thread, other threads:[~2020-04-27 23:12 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-27 23:12 [PATCH nft,v2 0/9] netmap support for nftables Pablo Neira Ayuso
2020-04-27 23:12 ` [PATCH nft,v2 1/9] src: NAT support for intervals in maps Pablo Neira Ayuso
2020-04-27 23:12 ` [PATCH nft,v2 2/9] include: resync nf_nat.h kernel header Pablo Neira Ayuso
2020-04-27 23:12 ` [PATCH nft,v2 3/9] src: add netmap support Pablo Neira Ayuso
2020-04-27 23:12 ` [PATCH nft,v2 4/9] src: add STMT_NAT_F_CONCAT flag and use it Pablo Neira Ayuso
2020-04-27 23:12 ` [PATCH nft,v2 5/9] evaluate: fix crash when handling concatenation without map Pablo Neira Ayuso
2020-04-27 23:12 ` [PATCH nft,v2 6/9] tests: py: concatenation, netmap and nat mappings Pablo Neira Ayuso
2020-04-27 23:12 ` [PATCH nft,v2 7/9] mnl: restore --debug=netlink output with sets Pablo Neira Ayuso
2020-04-27 23:12 ` [PATCH nft,v2 8/9] tests: py: remove range test with service names Pablo Neira Ayuso
2020-04-27 23:12 ` [PATCH nft,v2 9/9] tests: shell: add NAT mappings tests Pablo Neira Ayuso
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.