A release of the nftables packet filter 1.0.6 has been published, unifying the packet filtering interfaces for IPv4, IPv6, ARP, and network bridges (aimed at replacing iptables, ip6tables, arptables, and ebtables). The nftables package includes user-space components of the packet filter, while the nf_tables subsystem, which is part of the Linux kernel since version 3.13, handles operations at the kernel level. A generic interface is provided at the kernel level, independent of specific protocols, offering basic functions for data extraction from packets, data manipulation, and flow management.
The filtering rules themselves and protocol-specific handlers are compiled into bytecode in user space, after which this bytecode is loaded into the kernel via the Netlink interface and executed in the kernel in a special environment resembling BPF (Berkeley Packet Filters). This approach significantly reduces the size of the filtering code running at the kernel level and offloads all functions related to rule parsing and protocol logic into user space. virtual machineFull support for lightweight tunnel templates, such as vxlan, geneve, and erspan, has been provided: table netdev global { tunnel t1 { id 10 ip saddr 192.168.2.10 ip daddr 192.168.2.11 sport 1025 dport 20020 ttl 1 erspan { version 1 index 2 } } tunnel t2 { id 10 ip saddr 192.168.3.10 ip daddr 192.168.3.11 sport 1025 dport 21021 ttl 1 erspan { version 1 index 2 } } chain in { type filter hook ingress device veth0 priority 0; tunnel name ip saddr map { 10.141.10.12 : "t1", 10.141.10.13 : "t2" } fwd to erspan1 } } Before loading the rules, a network interface erspan1 must be created: ip link add dev erspan1 type erspan external
Key Changes:
- In the rule optimizer, invoked with the option '-o/--optimize', automatic packing of rules is established through their merging and conversion into map and set lists. For example, the rules in # cat ruleset.nft: table ip x { chain y { type filter hook input priority filter; policy drop; meta iifname eth1 ip saddr 1.1.1.1 ip daddr 2.2.2.3 accept meta iifname eth1 ip saddr 1.1.1.2 ip daddr 2.2.2.4 accept meta iifname eth1 ip saddr 1.1.1.2 ip daddr 2.2.3.0/24 accept meta iifname eth1 ip saddr 1.1.1.2 ip daddr 2.2.4.0-2.2.4.10 accept meta iifname eth2 ip saddr 1.1.1.3 ip daddr 2.2.2.5 accept } } after running 'nft -o -c -f ruleset.nft' will be transformed as follows: ruleset.nft:4:17-74: meta iifname eth1 ip saddr 1.1.1.1 ip daddr 2.2.2.3 accept ruleset.nft:5:17-74: meta iifname eth1 ip saddr 1.1.1.2 ip daddr 2.2.2.4 accept ruleset.nft:6:17-77: meta iifname eth1 ip saddr 1.1.1.2 ip daddr 2.2.3.0/24 accept ruleset.nft:7:17-83: meta iifname eth1 ip saddr 1.1.1.2 ip daddr 2.2.4.0-2.2.4.10 accept ruleset.nft:8:17-74: meta iifname eth2 ip saddr 1.1.1.3 ip daddr 2.2.2.5 accept into: iifname . ip saddr . ip daddr { eth1 . 1.1.1.1 . 2.2.2.3, eth1 . 1.1.1.2 . 2.2.2.4, eth1 . 1.1.1.2 . 2.2.3.0/24, eth1 . 1.1.1.2 . 2.2.4.0-2.2.4.10, eth2 . 1.1.1.3 . 2.2.2.5 } accept
- The optimizer can also transform into a more compact form the rules that already use simple set lists, such as the rules: # cat ruleset.nft table ip filter { chain input { type filter hook input priority filter; policy drop; iifname "lo" accept ct state established,related accept comment "In traffic we originate, we trust" iifname "enp0s31f6" ip saddr { 209.115.181.102, 216.197.228.230 } ip daddr 10.0.0.149 udp sport 123 udp dport 32768-65535 accept iifname "enp0s31f6" ip saddr { 64.59.144.17, 64.59.150.133 } ip daddr 10.0.0.149 udp sport 53 udp dport 32768-65535 accept } } after executing "nft -o -c -f ruleset.nft" they will be packed as follows: ruleset.nft:6:22-149: iifname "enp0s31f6" ip saddr { 209.115.181.102, 216.197.228.230 } ip daddr 10.0.0.149 udp sport 123 udp dport 32768-65535 accept ruleset.nft:7:22-143: iifname "enp0s31f6" ip saddr { 64.59.144.17, 64.59.150.133 } ip daddr 10.0.0.149 udp sport 53 udp dport 32768-65535 accept into: iifname . ip saddr . ip daddr . udp sport . udp dport { enp0s31f6 . 209.115.181.102 . 10.0.0.149 . 123 . 32768-65535, enp0s31f6 . 216.197.228.230 . 10.0.0.149 . 123 . 32768-65535, enp0s31f6 . 64.59.144.17 . 10.0.0.149 . 53 . 32768-65535, enp0s31f6 . 64.59.150.133 . 10.0.0.149 . 53 . 32768-65535 } accept
- The issue with generating bytecode for the merging of intervals that use types with different byte orders, such as IPv4 (network byte order) and meta mark (system byte order), has been resolved. table ip x { map w { typeof ip saddr . meta mark : verdict flags interval counter elements = { 127.0.0.1-127.0.0.4 . 0x123434-0xb00122 : accept, 192.168.0.10-192.168.1.20 . 0x0000aa00-0x0000aaff : accept, } } chain k { type filter hook input priority filter; policy drop; ip saddr . meta mark vmap @w } }
- Established matching for rare protocols when using raw expressions, for example: meta l4proto 91 @th,400,16 0x0 accept
- Resolved issues with inserting rules with intervals: insert rule x y tcp sport { 3478-3497, 16384-16387 } counter accept
- Improved JSON API, which now includes support for expressions in set and map lists.
- In the extensions to the Python library nftables, loading rule sets for processing in check mode ("-c") has been allowed and support for external variable definitions has been added.
- Adding comments has been permitted in set list elements.
- In byte ratelimit, specifying a zero value has been allowed.
Source: opennet.ru
