proto: add icmp and icmpv6 in inet protocols
PATCH 1/1 proto: add icmp and icmpv6 in inet protocols
If we try to add a rule with icmp or icmpv6 in a inet table like this:
nft add rule inet filter input icmp type echo-request counter or
nft add rule inet filter input icmpv6 type echo-request counter
we have this error:
<cmdline>:1:28-38: Error: conflicting protocols specified: inet-service vs. icmpv6 add rule inet filter input icmpv6 type echo-request counter accept
^^^^^^^^^^^
This patch solve it adding icmp and icmpv6 in the inet protocols that we can use. Also, I have added a statement meta for restricting that the rules for icmp is only for ipv4 traffic and the rules for icmpv6 is for ipv6 traffic.
---
I have tested this patch with the rules:
nft add rule inet filter input tcp dport 22 counter nft add rule inet filter input icmp type echo-request counter nft add rule inet filter input icmpv6 type echo-request counter
I have created traffic and I have seen that it works for me.
include/payload.h | 4 +-- include/statement.h | 1 + src/evaluate.c | 11 ++---- src/netlink_delinearize.c | 43 +++++++++++++++-------- src/payload.c | 84 ++++++++++++++++++++++++++++++++++----------- src/proto.c | 2 ++ 6 files changed, 100 insertions(+), 45 deletions(-)
include/payload.h +2 -2
@@ -11,8 +11,8 @@ extern void payload_init_raw(struct expr *expr, enum proto_bases base, unsigned int offset, unsigned int len);struct eval_ctx ; -extern int payload_gen_dependency (struct eval_ctx *ctx,const struct expr *expr, -struct expr **res); +extern int payload_gen_dependency (struct eval_ctx *ctx, +const struct expr *expr);extern bool payload_is_adjacent (const struct expr *e1,const struct expr *e2); extern struct expr *payload_expr_join(const struct expr *e1,
include/statement.h +1 -0
@@ -162,4 +162,5 @@ extern void stmt_free(struct stmt *stmt);extern void stmt_list_free (struct list_head *list);extern void stmt_print (const struct stmt *stmt); +int stmt_evaluate (struct eval_ctx *ctx,struct stmt *stmt);#endif /* NFTABLES_STATEMENT_H */
src/evaluate.c +2 -9
@@ -27,7 +27,6 @@#include <utils.h> static int expr_evaluate (struct eval_ctx *ctx,struct expr **expr); -static int stmt_evaluate (struct eval_ctx *ctx,struct stmt *stmt);static const char *byteorder_names[] = { [BYTEORDER_INVALID ] ="invalid" ,
@@ -271,16 +270,10 @@ static int expr_evaluate_payload(struct eval_ctx *ctx, struct expr **expr) {struct expr *payload = *expr;enum proto_bases base = payload->payload.base; -struct stmt *nstmt; -struct expr *nexpr;if (ctx->pctx.protocol[base].desc ==NULL ) { -if (payload_gen_dependency (ctx, payload, &nexpr) <0 ) +if (payload_gen_dependency (ctx, payload) <0 )return -1 ; - nstmt =expr_stmt_alloc (&nexpr->location, nexpr); -if (stmt_evaluate (ctx, nstmt) <0 ) -return -1 ; -list_add_tail (&nstmt->list, &ctx->stmt->list); }else if (ctx->pctx.protocol[base].desc != payload->payload.desc) return expr_error(ctx->msgs, payload, "conflicting protocols specified: %s vs. %s",
@@ -1196,7 +1189,7 @@ static int stmt_evaluate_ct(struct eval_ctx *ctx, struct stmt *stmt)return 0 ; } -static int stmt_evaluate (struct eval_ctx *ctx,struct stmt *stmt) +int stmt_evaluate (struct eval_ctx *ctx,struct stmt *stmt) {#ifdef DEBUG if (debug_level &DEBUG_EVALUATION ) {
src/netlink_delinearize.c +29 -14
79 lines not on this page · raw message
src/payload.c +64 -20
119 lines not on this page · raw message
src/proto.c +2 -0
@@ -644,6 +644,8 @@ const struct proto_desc proto_inet_service = {PROTO_LINK (IPPROTO_TCP , &proto_tcp),PROTO_LINK (IPPROTO_DCCP , &proto_dccp),PROTO_LINK (IPPROTO_SCTP , &proto_sctp), +PROTO_LINK (IPPROTO_ICMPV6 , &proto_icmp6), + PROTO_LINK(IPPROTO_ICMP, &proto_icmp), }, .templates = { [0] = PROTO_META_TEMPLATE("l4proto", &inet_protocol_type, NFT_META_L4PROTO, 8),
Signature · 1 line
1.7.10.4
Quoted 8 lines · Alvaro Neira Ayuso
If we try to add a rule with icmp or icmpv6 in a inet table like this:
nft add rule inet filter input icmp type echo-request counter or
nft add rule inet filter input icmpv6 type echo-request counterwe have this error:
Quoted 7 lines
<cmdline>:1:28-38: Error: conflicting protocols specified: inet-service vs. icmpv6 add rule inet filter input icmpv6 type echo-request counter accept
^^^^^^^^^^^This patch solve it adding icmp and icmpv6 in the inet protocols that we can use. Also, I have added a statement meta for restricting that the rules for icmp is only for ipv4 traffic and the rules for icmpv6 is for ipv6 traffic.
These a rather complex changes and I'd like to see the protocol context parts split and explained in more detail.
I'm also not convinced by the special handling for this case. The same problem affects f.i. the bridge family. Stated generically, the problem is finding dependency expressions when one or more element in the chain is missing. My feeling is that we should walk all possible paths to the base protocol and, if only a single path exists (for now), use that for dependencies.