All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anton Rieger <rieger@jikken.de>
To: "netfilter@vger.kernel.org" <netfilter@vger.kernel.org>
Subject: Re: How can I block all traffic from an IP range, irrespective of origin, going to, or coming from, using nftables in Debian 10
Date: Fri, 4 Oct 2019 22:30:27 +0200	[thread overview]
Message-ID: <20191004203027.pgx7zvx2dogcp3lm@nisshoku> (raw)
In-Reply-To: <gqJSE9iGsixrV5lbpV2VVj_N-pdkB59YlfOJlH-VsKhUYHsgXJ2MlY62LPso375cRc0k2X4tXD7744rB6UYKqeJGA-KB6AmpqnBpvlvsmTE=@protonmail.com>

>Could someone please clarify RAW/MANGLE tables in regards to Nftables.

Short story short:
They doesn't exist anymore, but you can change priorities to simulate them.

Long answer:
A table in nftables is identified by:
    1) Their name
    2) Their addressees family is one of ip, ip6, inet, arp, bridge, netdev (inet is ip+ip6)
Currently only the ``dormant'' flag is supported meaning the table is not evaluated any more

A table is a container for chains.
A chain  is a container for rules.
There are two types of chains:
    1) base chain
    2) regular chain
A base chain must specify a ``type'', ``hook'' and ``priority''.
They need them, as these chains are entry points of packets from the network stack.
You can use these to reconstruct the predefined iptables chains by naming them the same.

Each type is bound to certain families hooks:
    filter) Standard type can be used everywhere.
    nat) Must be ip, ip6 or inet and provide prerouting, input, output, postrouting hooks
         Performs NAT based on conntrack entries.
         Only first packet of a connection traverses this chain.
         Specify conntrack details here.
    route) Must be ip or ip6 and only provides the output hook.
           If accepted and IP header changes a new route lookup is performed.
           Use this to e.g. implement policy routing selectors.

Quirks:
netdev needs filter and ingress hook and device parameter is mandatory.
arp only supports input/output hooks.

So you can see, that the most used type is filter.
To order with chain gets triggered in which order is determined by the priority parameter.
This can either be a signed integer (lower values have precedence) or standard priority names.
These standard priority names are labeled to match xtables default values:

raw      := -300 (ip,ip6,inet) all hooks
mangle   := -150 (ip,ip6,inet) all hooks
dstnat   := -100 (ip,ip6,inet) prerouting
filter   :=    0 (ip,ip6,inet,arp,netdev) all hooks
security :=   50 (ip,ip6,inet) all hooks
srcnat   :=  100 (ip,ip6,inet) postrouting

Please note, the ``bridge'' family has different values for dstnat,filter,out,scrnat
You can also use addition/subtraction in your definitions.
So their order is basically the same.
All this information is well documented in nft(8)

>Currently there are 5 different families of tables: ip, ip6, arp, bridge, inet
Should be updated to include the ``netdev'' family (for ingress handling)

>My question is, since Nftables doesn't have predefined tables, just by naming a table: 
>"table inet raw", does it becomes a RAW table or not?
It is NOT implicitly a raw table in the iptables sense. It's just a table matching ip or 
ip6 family packets.

> If not, what do I have to do?
You have to add at least one chain with the priority ``raw''.
So to match iptables:

```
table inet raw {
    chain PREROUTING {
        type filter hook prerouting priority raw; policy accepted;
    }

    chain OUTPUT {
        type filter hook output priority raw; policy accepted;
    }
}
```
Please note that ``policy accept'' is the default choice thus defining it here
is just for better understanding.

>For now I have added this to my nftables.conf
>
>xxxxx
>table inet raw {
>        chain prerouting {
>                type filter hook prerouting priority 0; policy accept;
>                ip saddr 123.0.0.0/8 counter drop
>          }
>        chain output {
>                type filter hook output priority 0; policy accept;
>                ip daddr 123.0.0.0/8 counter reject
>         }
>}
>xxxxx
Please note a priority of 0 is equal to ``filter''.

  reply	other threads:[~2019-10-04 20:30 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-01 23:22 How can I block all traffic from an IP range, irrespective of origin, going to, or coming from, using nftables in Debian 10 Jags
2019-10-03 19:00 ` zrm
2019-10-04  9:45   ` Jags
2019-10-04 10:18     ` Reindl Harald
2019-10-04 10:44       ` Jags
2019-10-04 11:05         ` Reindl Harald
2019-10-04 12:21           ` Jags
2019-10-04 13:06             ` Reindl Harald
2019-10-04 14:28               ` Jags
2019-10-04 15:10                 ` Reindl Harald
2019-10-04 15:47                   ` Neal P. Murphy
2019-10-04 16:25                   ` Jags
2019-10-04 20:30                     ` Anton Rieger [this message]
2019-10-04 21:27                       ` Jags
2019-10-06 17:26                         ` sean darcy
2019-10-06 23:00                           ` Jags

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=20191004203027.pgx7zvx2dogcp3lm@nisshoku \
    --to=rieger@jikken.de \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.