]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
evaluate: reject: check the context in reject without reason for bridge and inet...
authorAlvaro Neira <alvaroneay@gmail.com>
Thu, 23 Oct 2014 17:36:56 +0000 (19:36 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Fri, 24 Oct 2014 10:00:57 +0000 (12:00 +0200)
In rules like:

  nft add rule inet filter input reject
or
  nft add rule bridge filter input reject

we use icmpx to reject it. But if we have network context, we also use type of
reject. With this patch, we check the network context. If we don't have context,
we still use icmpx. However, if we have rules with network context like:

  nft add rule inet meta nfproto ipv4 reject
or
  nft add rule bridge ether type ipv6 reject

We are going to use icmp or icmpv6 to reject it taking into account the network
context.

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/evaluate.c
tests/regression/bridge/reject.t
tests/regression/inet/reject.t

index 63ba82e30ba33d75b49d3b2803bc68d8ef4c5cad..2dd49fa61d395492ef797e1c4e4d1e6e8de137ed 100644 (file)
@@ -1357,6 +1357,9 @@ static int stmt_evaluate_reject_family(struct eval_ctx *ctx, struct stmt *stmt,
 static int stmt_evaluate_reject_default(struct eval_ctx *ctx,
                                          struct stmt *stmt)
 {
+       int protocol;
+       const struct proto_desc *desc, *base;
+
        switch (ctx->pctx.family) {
        case NFPROTO_IPV4:
        case NFPROTO_IPV6:
@@ -1368,9 +1371,46 @@ static int stmt_evaluate_reject_default(struct eval_ctx *ctx,
                        stmt->reject.icmp_code = ICMP6_DST_UNREACH_NOPORT;
                break;
        case NFPROTO_INET:
+               desc = ctx->pctx.protocol[PROTO_BASE_NETWORK_HDR].desc;
+               if (desc == NULL) {
+                       stmt->reject.type = NFT_REJECT_ICMPX_UNREACH;
+                       stmt->reject.icmp_code = NFT_REJECT_ICMPX_PORT_UNREACH;
+                       break;
+               }
+               stmt->reject.type = NFT_REJECT_ICMP_UNREACH;
+               base = ctx->pctx.protocol[PROTO_BASE_LL_HDR].desc;
+               protocol = proto_find_num(base, desc);
+               switch (protocol) {
+               case NFPROTO_IPV4:
+                       stmt->reject.family = NFPROTO_IPV4;
+                       stmt->reject.icmp_code = ICMP_PORT_UNREACH;
+                       break;
+               case NFPROTO_IPV6:
+                       stmt->reject.family = NFPROTO_IPV6;
+                       stmt->reject.icmp_code = ICMP6_DST_UNREACH_NOPORT;
+                       break;
+               }
+               break;
        case NFPROTO_BRIDGE:
-               stmt->reject.type = NFT_REJECT_ICMPX_UNREACH;
-               stmt->reject.icmp_code = NFT_REJECT_ICMPX_PORT_UNREACH;
+               desc = ctx->pctx.protocol[PROTO_BASE_NETWORK_HDR].desc;
+               if (desc == NULL) {
+                       stmt->reject.type = NFT_REJECT_ICMPX_UNREACH;
+                       stmt->reject.icmp_code = NFT_REJECT_ICMPX_PORT_UNREACH;
+                       break;
+               }
+               stmt->reject.type = NFT_REJECT_ICMP_UNREACH;
+               base = ctx->pctx.protocol[PROTO_BASE_LL_HDR].desc;
+               protocol = proto_find_num(base, desc);
+               switch (protocol) {
+               case __constant_htons(ETH_P_IP):
+                       stmt->reject.family = NFPROTO_IPV4;
+                       stmt->reject.icmp_code = ICMP_PORT_UNREACH;
+                       break;
+               case __constant_htons(ETH_P_IPV6):
+                       stmt->reject.family = NFPROTO_IPV6;
+                       stmt->reject.icmp_code = ICMP6_DST_UNREACH_NOPORT;
+                       break;
+               }
                break;
        }
        return 0;
index 11a0f1c59c9209c82d7d9480738d9484b46b763d..43e54611fcfcbd93bf9fac01bdb1c8e71f23ccda 100644 (file)
@@ -18,6 +18,9 @@ reject with icmpv6 type port-unreachable;ok;ether type ip6 reject
 ip protocol tcp reject with tcp reset;ok;ip protocol 6 reject with tcp reset
 
 reject;ok
+ether type ip reject;ok
+ether type ip6 reject;ok
+
 reject with icmpx type host-unreachable;ok
 reject with icmpx type no-route;ok
 reject with icmpx type admin-prohibited;ok
index 2f5aef3a176dcd2872c539f72f3290fecac74fbe..52e7b28b53779e2d736b2abe175d0260d23038b7 100644 (file)
@@ -18,6 +18,9 @@ reject with icmpv6 type port-unreachable;ok;meta nfproto ipv6 reject
 reject with tcp reset;ok;meta l4proto 6 reject with tcp reset
 
 reject;ok
+meta nfproto ipv4 reject;ok
+meta nfproto ipv6 reject;ok
+
 reject with icmpx type host-unreachable;ok
 reject with icmpx type no-route;ok
 reject with icmpx type admin-prohibited;ok