netfilter.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kerin Millar <kfm@plushkava.net>
To: Edward Dickson <edickson@hudson-trading.com>
Cc: netfilter@vger.kernel.org
Subject: Re: [nftables] Multiple reject withs in a single rule
Date: Thu, 1 Feb 2024 17:24:55 +0000	[thread overview]
Message-ID: <20240201172455.dbcd6ff0da8e545e06106e93@plushkava.net> (raw)
In-Reply-To: <CALqmkGz7HqTeAvyZwJDTcZsuSUVi6usAD8P6XwTnfMxzBSs=Fw@mail.gmail.com>

On Fri, 24 Nov 2023 14:57:09 +0000
Edward Dickson <edickson@hudson-trading.com> wrote:

> Hello,
> 
> I am running nftables v0.9.8 and am aiming to create a single
> rejection rule which specifies multiple rejection types for different
> protocols.
> 
> Something like: "reject with tcp reset with icmpx type admin-prohibited".
> 
> However when I've tried this, nftables throws an error:
> Error: syntax error, unexpected with, expecting end of file or newline
> or semicolon
> add rule inet filter output reject with tcp reset with icmpx type
> admin-prohibited
> 
>  ^^^^ (under the second with)
> 
> Error: Statement after terminal statement has no effect
> add rule inet filter output reject with tcp reset reject with icmpx
> type admin-prohibited
>                                       ~~~~~~ (under first reject)
> ^^^^^^ (under the second reject)
> 
> 
> I am currently using two rules which covers TCP, ICMP and anything
> else, but would be better as a single rule:
>     add rule inet filter output meta l4proto tcp reject with tcp reset
>     add rule inet filter output reject with icmpx type admin-prohibited
> 
> But this would be better as a single rule, as the duplicate similar
> rules create complexity and duplication.
> 
> Is there a way to specify multiple rejection types in a single nftables rule?

A chain would handle this perfectly adequately.

chain prohibit {
	meta l4proto tcp reject with tcp reset
	meta l4proto udp reject
	reject with icmpx type admin-prohibited
}

Then, simply employ "goto prohibit" as a target in your rules.

-- 
Kerin Millar

      parent reply	other threads:[~2024-02-01 17:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-24 14:57 [nftables] Multiple reject withs in a single rule Edward Dickson
2023-11-24 17:03 ` Reindl Harald
2024-02-01 17:24 ` Kerin Millar [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240201172455.dbcd6ff0da8e545e06106e93@plushkava.net \
    --to=kfm@plushkava.net \
    --cc=edickson@hudson-trading.com \
    --cc=netfilter@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).