tests: add icmp/6 test where dependency should be left alone
Florian Westphal
maintainerPATCH 1/2 tests: add icmp/6 test where dependency should be left alone
These tests fail: nft should leave the type as-is.
--- tests/py/ip/icmp.t | 2 ++ tests/py/ip/icmp.t.json | 28 ++++++++++++++++++++++++++++ tests/py/ip/icmp.t.payload.ip | 6 ++++++ tests/py/ip6/icmpv6.t | 2 ++ tests/py/ip6/icmpv6.t.json | 28 ++++++++++++++++++++++++++++ tests/py/ip6/icmpv6.t.payload.ip6 | 7 +++++++ 6 files changed, 73 insertions(+)
tests/py/ip/icmp.t +2 -0
@@ -86,3 +86,5 @@ icmp gateway != { 33-55};ok icmp gateway != 34;ok icmp gateway != { 333, 334};ok +icmp code 1 icmp type 2;ok;icmp type 2 icmp code host-unreachable +icmp code != 1 icmp type 2 icmp mtu 5;fail
tests/py/ip/icmp.t.json +28 -0
@@ -1843,3 +1843,31 @@ } } ] + +# icmp code 1 icmp type 2 +[ + { + "match": { + "left": { + "payload": { + "field": "type", + "protocol": "icmp" + } + }, + "op": "==", + "right": 2 + } + }, + { + "match": { + "left": { + "payload": { + "field": "code", + "protocol": "icmp" + } + }, + "op": "==", + "right": "host-unreachable" + } + } +]
tests/py/ip/icmp.t.payload.ip +6 -0
@@ -787,3 +787,9 @@ ip test-ip4 input [ lookup reg 1 set __set%d ] [ immediate reg 0 accept ] +# icmp code 1 icmp type 2 +ip + [ meta load l4proto => reg 1 ] + [ cmp eq reg 1 0x00000001 ] + [ payload load 2b @ transport header + 0 => reg 1 ] + [ cmp eq reg 1 0x00000102 ]
tests/py/ip6/icmpv6.t +2 -0
@@ -92,3 +92,5 @@ icmpv6 max-delay {33, 55, 67, 88};ok icmpv6 max-delay != {33, 55, 67, 88};ok icmpv6 max-delay {33-55};ok icmpv6 max-delay != {33-55};ok + +icmpv6 type parameter-problem icmpv6 code no-route;ok
tests/py/ip6/icmpv6.t.json +28 -0
@@ -1315,3 +1315,31 @@ } } ] + +# icmpv6 type parameter-problem icmpv6 code no-route +[ + { + "match": { + "left": { + "payload": { + "field": "type", + "protocol": "icmpv6" + } + }, + "op": "==", + "right": "parameter-problem" + } + }, + { + "match": { + "left": { + "payload": { + "field": "code", + "protocol": "icmpv6" + } + }, + "op": "==", + "right": "no-route" + } + } +]
tests/py/ip6/icmpv6.t.payload.ip6 +7 -0
@@ -682,3 +682,10 @@ ip6 test-ip6 input [ payload load 2b @ transport header + 4 => reg 1 ] [ lookup reg 1 set __set%d 0x1 ] +# icmpv6 type parameter-problem icmpv6 code no-route +ip6 + [ meta load l4proto => reg 1 ] + [ cmp eq reg 1 0x0000003a ] + [ payload load 2b @ transport header + 0 => reg 1 ] + [ cmp eq reg 1 0x00000004 ] +
Signature · 1 line
2.26.2
Florian Westphal
maintainerPATCH 2/2 payload: check icmp dependency before removing previous icmp expression
nft is too greedy when removing icmp dependencies. 'icmp code 1 type 2' did remove the type when printing.
Be more careful and check that the icmp type dependency of the candidate expression (earlier icmp payload expression) has the same type dependency as the new expression.
--- src/payload.c | 63 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 21 deletions(-)
src/payload.c +42 -21
@@ -627,6 +627,40 @@ void payload_dependency_release(struct payload_dep_ctx *ctx) ctx->pdep =NULL ; } +static uint8_t icmp_dep_to_type (enum icmp_hdr_field_type t) +{ +switch (t) { +case PROTO_ICMP_ANY : +BUG ("Invalid map for simple dependency" ); +case PROTO_ICMP_ECHO :return ICMP_ECHO ; +case PROTO_ICMP6_ECHO :return ICMP6_ECHO_REQUEST ; +case PROTO_ICMP_MTU :return ICMP_DEST_UNREACH ; +case PROTO_ICMP_ADDRESS :return ICMP_REDIRECT ; +case PROTO_ICMP6_MTU :return ICMP6_PACKET_TOO_BIG ; +case PROTO_ICMP6_MGMQ :return MLD_LISTENER_QUERY ; +case PROTO_ICMP6_PPTR :return ICMP6_PARAM_PROB ; + } + +BUG ("Missing icmp type mapping" ); +} + +static bool payload_may_dependency_kill_icmp (struct payload_dep_ctx *ctx,struct expr *expr) +{ +const struct expr *dep = ctx->pdep->expr; +uint8_t icmp_type; + + icmp_type = expr->payload.tmpl->icmp_dep; +if (icmp_type ==PROTO_ICMP_ANY ) +return false; + +if (dep->left->payload.desc != expr->payload.desc) +return false; + + icmp_type =icmp_dep_to_type (expr->payload.tmpl->icmp_dep); + +return ctx->icmp_type == icmp_type; +} +static bool payload_may_dependency_kill (struct payload_dep_ctx *ctx,unsigned int family,struct expr *expr) {
@@ -661,6 +695,14 @@ static bool payload_may_dependency_kill(struct payload_dep_ctx *ctx,break ; } +if (expr->payload.base ==PROTO_BASE_TRANSPORT_HDR && + dep->left->payload.base ==PROTO_BASE_TRANSPORT_HDR ) { +if (dep->left->payload.desc == &proto_icmp) +return payload_may_dependency_kill_icmp (ctx, expr); +if (dep->left->payload.desc == &proto_icmp6) +return payload_may_dependency_kill_icmp (ctx, expr); + } +return true; }
@@ -680,10 +722,6 @@ void payload_dependency_kill(struct payload_dep_ctx *ctx, struct expr *expr,if (payload_dependency_exists (ctx, expr->payload.base) &&payload_may_dependency_kill (ctx, family, expr))payload_dependency_release (ctx); -else if (ctx->icmp_type && ctx->pdep) { -fprintf (stderr,"Did not kill \n" ); -payload_dependency_release (ctx); - } } void exthdr_dependency_kill(struct payload_dep_ctx *ctx, struct expr *expr,
@@ -707,23 +745,6 @@ void exthdr_dependency_kill(struct payload_dep_ctx *ctx, struct expr *expr, } } -static uint8_t icmp_dep_to_type (enum icmp_hdr_field_type t) -{ -switch (t) { -case PROTO_ICMP_ANY : -BUG ("Invalid map for simple dependency" ); -case PROTO_ICMP_ECHO :return ICMP_ECHO ; -case PROTO_ICMP6_ECHO :return ICMP6_ECHO_REQUEST ; -case PROTO_ICMP_MTU :return ICMP_DEST_UNREACH ; -case PROTO_ICMP_ADDRESS :return ICMP_REDIRECT ; -case PROTO_ICMP6_MTU :return ICMP6_PACKET_TOO_BIG ; -case PROTO_ICMP6_MGMQ :return MLD_LISTENER_QUERY ; -case PROTO_ICMP6_PPTR :return ICMP6_PARAM_PROB ; - } - -BUG ("Missing icmp type mapping" ); -} -/** * payload_expr_complete - fill in type information of a raw payload expr *
Signature · 1 line
2.26.2
Re: [PATCH nft 2/2] payload: check icmp dependency before removing previous icmp expression
Quoted 7 lines · Florian Westphal
nft is too greedy when removing icmp dependencies. 'icmp code 1 type 2' did remove the type when printing.
Be more careful and check that the icmp type dependency of the candidate expression (earlier icmp payload expression) has the same type dependency as the new expression.
Quoted 5 lines
Reported-by Eric Garver <[email protected]>Reported-by Michael Biebl <[email protected]>Fixes d0f3b9eaab8d77e ("payload: auto-remove simple icmp/icmpv6 dependency expressions")Signed-off-by Florian Westphal <[email protected]>---
Thanks Florian. This fixes the issue [1] reported against firewalld.
[1]: https://github.com/firewalld/firewalld/issues/752
--->8---
tmp/autopkgtest.PRXtPH/build.yiS/src/src/tests/testsuite.dir/at-groups/97/stdout renamed from - +1 -1
@@ -1,6 +1,6 @@ table inet firewalld { chain filter_IN_public_deny { -icmp type destination-unreachable icmp code host-prohibited reject with icmpx type admin-prohibited +icmp code host-prohibited reject with icmpx type admin-prohibited } }
Re: [PATCH nft 2/2] payload: check icmp dependency before removing previous icmp expression
Am 02.02.21 um 14:21 schrieb Eric Garver:
Quoted 14 lines · Florian Westphal
Quoted 7 lines
nft is too greedy when removing icmp dependencies. 'icmp code 1 type 2' did remove the type when printing.
Be more careful and check that the icmp type dependency of the candidate expression (earlier icmp payload expression) has the same type dependency as the new expression.
Quoted 5 lines
Reported-by Eric Garver <[email protected]>Reported-by Michael Biebl <[email protected]>Fixes d0f3b9eaab8d77e ("payload: auto-remove simple icmp/icmpv6 dependency expressions")Signed-off-by Florian Westphal <[email protected]>---
Quoted 5 lines
Tested-by Eric Garver <[email protected]>Thanks Florian. This fixes the issue [1] reported against firewalld.
I can confirm that as well.
Regards,
Michael