From b65ea148d8f8edc4ef5774154b1aca25d884d500 Mon Sep 17 00:00:00 2001 From: Florian Westphal Date: Tue, 18 Jun 2019 20:43:58 +0200 Subject: src: statement: disable reject statement type omission for bridge add rule bridge test-bridge input reject with icmp type port-unreachable ... will be printed as 'reject', which is fine on ip family, but not on bridge -- 'with icmp type' adds an ipv4 dependency, but simple reject does not (it will use icmpx to also reject ipv6 packets with an icmpv6 error). Add a toggle to supress short-hand versions in this case. Signed-off-by: Florian Westphal Acked-by: Pablo Neira Ayuso --- src/json.c | 6 ++++-- src/netlink_delinearize.c | 6 ++++++ src/statement.c | 6 ++++-- 3 files changed, 14 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/json.c b/src/json.c index a503a975..e0127c57 100644 --- a/src/json.c +++ b/src/json.c @@ -1311,13 +1311,15 @@ json_t *reject_stmt_json(const struct stmt *stmt, struct output_ctx *octx) case NFT_REJECT_ICMP_UNREACH: switch (stmt->reject.family) { case NFPROTO_IPV4: - if (stmt->reject.icmp_code == ICMP_PORT_UNREACH) + if (!stmt->reject.verbose_print && + stmt->reject.icmp_code == ICMP_PORT_UNREACH) break; type = "icmp"; jexpr = expr_print_json(stmt->reject.expr, octx); break; case NFPROTO_IPV6: - if (stmt->reject.icmp_code == ICMP6_DST_UNREACH_NOPORT) + if (!stmt->reject.verbose_print && + stmt->reject.icmp_code == ICMP6_DST_UNREACH_NOPORT) break; type = "icmpv6"; jexpr = expr_print_json(stmt->reject.expr, octx); diff --git a/src/netlink_delinearize.c b/src/netlink_delinearize.c index 4d720d29..a4044f0c 100644 --- a/src/netlink_delinearize.c +++ b/src/netlink_delinearize.c @@ -2202,6 +2202,12 @@ static void stmt_reject_postprocess(struct rule_pp_ctx *rctx) datatype_set(stmt->reject.expr, &icmpx_code_type); break; } + + /* always print full icmp(6) name, simple 'reject' might be ambiguious + * because ipv4 vs. ipv6 info might be lost + */ + stmt->reject.verbose_print = 1; + base = rctx->pctx.protocol[PROTO_BASE_LL_HDR].desc; desc = rctx->pctx.protocol[PROTO_BASE_NETWORK_HDR].desc; protocol = proto_find_num(base, desc); diff --git a/src/statement.c b/src/statement.c index a9e8b3ae..c5594233 100644 --- a/src/statement.c +++ b/src/statement.c @@ -516,13 +516,15 @@ static void reject_stmt_print(const struct stmt *stmt, struct output_ctx *octx) case NFT_REJECT_ICMP_UNREACH: switch (stmt->reject.family) { case NFPROTO_IPV4: - if (stmt->reject.icmp_code == ICMP_PORT_UNREACH) + if (!stmt->reject.verbose_print && + stmt->reject.icmp_code == ICMP_PORT_UNREACH) break; nft_print(octx, " with icmp type "); expr_print(stmt->reject.expr, octx); break; case NFPROTO_IPV6: - if (stmt->reject.icmp_code == ICMP6_DST_UNREACH_NOPORT) + if (!stmt->reject.verbose_print && + stmt->reject.icmp_code == ICMP6_DST_UNREACH_NOPORT) break; nft_print(octx, " with icmpv6 type "); expr_print(stmt->reject.expr, octx); -- cgit v1.2.3