diff options
author | Patrick McHardy <kaber@trash.net> | 2015-01-12 12:09:17 +0000 |
---|---|---|
committer | Patrick McHardy <kaber@trash.net> | 2015-01-12 13:21:38 +0000 |
commit | 5424f775729a1bc9b72111eb9dfa2b1ffe201e30 (patch) | |
tree | a6bd9fc8518c7053a727b37c169be352a6647ac6 /src | |
parent | 08bc04a81ecd9cfdae1022bfe4b5f9507d3cd882 (diff) |
evaluate: check that map expressions' datatype matches mappings
Catch type errors in map expressions using named maps:
# nft add map filter test { type ipv4_addr : inet_service; }
# nft filter output mark set tcp dport map @test
<cmdline>:1:38-42: Error: datatype mismatch, map expects IPv4 address, mapping expression has type internet network service
filter output mark set tcp dport map @test
~~~~~~~~~ ^^^^^
Signed-off-by: Patrick McHardy <kaber@trash.net>
Diffstat (limited to 'src')
-rw-r--r-- | src/evaluate.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/evaluate.c b/src/evaluate.c index 2067a011..90c87d09 100644 --- a/src/evaluate.c +++ b/src/evaluate.c @@ -748,6 +748,13 @@ static int expr_evaluate_map(struct eval_ctx *ctx, struct expr **expr) map->mappings->ops->name); } + if (!datatype_equal(map->map->dtype, map->mappings->set->keytype)) + return expr_binary_error(ctx->msgs, map->mappings, map->map, + "datatype mismatch, map expects %s, " + "mapping expression has type %s", + map->mappings->set->keytype->desc, + map->map->dtype->desc); + map->dtype = map->mappings->set->datatype; map->flags |= EXPR_F_CONSTANT; |