summaryrefslogtreecommitdiffstats
path: root/src/payload.c
diff options
context:
space:
mode:
authorFlorian Westphal <fw@strlen.de>2021-06-15 18:01:50 +0200
committerFlorian Westphal <fw@strlen.de>2021-06-17 01:12:46 +0200
commite69019ec7aa6bd40ab23659e4b97cdb094ab7a79 (patch)
treeb0342e8bfd12907a06a956c8f9ea8fced61dda07 /src/payload.c
parent9a5574e2d4e9c9cb5d6382be03a7eccfa8663a15 (diff)
payload: do not remove icmp echo dependency
"icmp type echo-request icmp id 2" and "icmp id 2" are not the same, the latter gains an implicit dependency on both echo-request and echo-reply. Change payload dependency tracking to not store dependency in case the value type is ICMP(6)_ECHO(REPLY). Signed-off-by: Florian Westphal <fw@strlen.de>
Diffstat (limited to 'src/payload.c')
-rw-r--r--src/payload.c61
1 files changed, 37 insertions, 24 deletions
diff --git a/src/payload.c b/src/payload.c
index cfa95224..97b60713 100644
--- a/src/payload.c
+++ b/src/payload.c
@@ -98,12 +98,16 @@ static void payload_expr_pctx_update(struct proto_ctx *ctx,
desc = proto_find_upper(base, proto);
if (!desc) {
- if (base == &proto_icmp || base == &proto_icmp6) {
+ if (base == &proto_icmp) {
/* proto 0 is ECHOREPLY, just pretend its ECHO.
* Not doing this would need an additional marker
* bit to tell when icmp.type was set.
*/
ctx->th_dep.icmp.type = proto ? proto : ICMP_ECHO;
+ } else if (base == &proto_icmp6) {
+ if (proto == ICMP6_ECHO_REPLY)
+ proto = ICMP6_ECHO_REQUEST;
+ ctx->th_dep.icmp.type = proto;
}
return;
}
@@ -554,33 +558,39 @@ void payload_dependency_reset(struct payload_dep_ctx *ctx)
memset(ctx, 0, sizeof(*ctx));
}
-static uint8_t icmp_get_type(const struct proto_desc *desc, uint8_t value)
+static bool payload_dependency_store_icmp_type(struct payload_dep_ctx *ctx,
+ const struct stmt *stmt)
{
- if (desc == &proto_icmp && value == 0)
- return ICMP_ECHO;
+ struct expr *dep = stmt->expr;
+ const struct proto_desc *desc;
+ const struct expr *right;
+ uint8_t type;
- return value;
-}
+ if (dep->left->etype != EXPR_PAYLOAD)
+ return false;
-static uint8_t icmp_get_dep_type(const struct proto_desc *desc, struct expr *right)
-{
- if (right->etype == EXPR_VALUE && right->len == BITS_PER_BYTE)
- return icmp_get_type(desc, mpz_get_uint8(right->value));
+ right = dep->right;
+ if (right->etype != EXPR_VALUE || right->len != BITS_PER_BYTE)
+ return false;
- return 0;
-}
+ desc = dep->left->payload.desc;
+ if (desc == &proto_icmp) {
+ type = mpz_get_uint8(right->value);
-static void payload_dependency_store_icmp_type(struct payload_dep_ctx *ctx)
-{
- struct expr *dep = ctx->pdep->expr;
- const struct proto_desc *desc;
+ if (type == ICMP_ECHOREPLY)
+ type = ICMP_ECHO;
- if (dep->left->etype != EXPR_PAYLOAD)
- return;
+ ctx->icmp_type = type;
- desc = dep->left->payload.desc;
- if (desc == &proto_icmp || desc == &proto_icmp6)
- ctx->icmp_type = icmp_get_dep_type(dep->left->payload.desc, dep->right);
+ return type == ICMP_ECHO;
+ } else if (desc == &proto_icmp6) {
+ type = mpz_get_uint8(right->value);
+
+ ctx->icmp_type = type;
+ return type == ICMP6_ECHO_REQUEST || type == ICMP6_ECHO_REPLY;
+ }
+
+ return false;
}
/**
@@ -593,10 +603,13 @@ static void payload_dependency_store_icmp_type(struct payload_dep_ctx *ctx)
void payload_dependency_store(struct payload_dep_ctx *ctx,
struct stmt *stmt, enum proto_bases base)
{
- ctx->pbase = base + 1;
- ctx->pdep = stmt;
+ bool ignore_dep = payload_dependency_store_icmp_type(ctx, stmt);
+
+ if (ignore_dep)
+ return;
- payload_dependency_store_icmp_type(ctx);
+ ctx->pdep = stmt;
+ ctx->pbase = base + 1;
}
/**