All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Kerin Millar" <kfm@plushkava.net>
To: "Marc Haber" <mh+netfilter@zugschlus.de>,
	"Netfilter list" <netfilter@vger.kernel.org>
Subject: Re: Combine ipv4 and ipv6 in a set
Date: Tue, 30 Jan 2024 15:17:32 +0000	[thread overview]
Message-ID: <cd7cbfc0-b7d4-4713-9e2d-f92596fb4844@app.fastmail.com> (raw)
In-Reply-To: <Zbj04V-90zpQwEzl@torres.zugschlus.de>

On Tue, 30 Jan 2024, at 1:08 PM, Marc Haber wrote:
> On Tue, Jan 30, 2024 at 10:39:57AM +0000, Kerin Millar wrote:
>> On Tue, 30 Jan 2024, at 10:17 AM, Daniel wrote:
>> > Hi,
>> >
>> > nft 1.06 Debian12. Is it possible in a set to combine ipv4 and ipv6 ? If 
>> > not, does it exist another method to do this ?
>> 
>> Combining is impossible.
>
> This is one of my pet peeves with nft, actually. For iptables, there was
> tooling like ferm which made it possible to write dual-stack rule sets
> very easily. This kind of tooling seems to be completely missing in the
> nftables world. Am I missing something here?

Quite possibly. Currently, nftables supports:

- mixed rulesets (using tables bearing the "inet" family)
- mixed rules (wherever it makes sense)
- first-class sets of any kind (irrespective of the type of table enclosing them)

Granted, one cannot create a set that is typed in such a way that an element can be either an IPv4 or IPv6 address/interval. Conversely, iptables does not natively support sets at all, though it can integrate with sets that are managed by ipset(8). Now, can an ipset contain addresses of mixed types? No, it cannot.

# ipset create myset hash:ip
# ipset add myset 127.0.0.1
# ipset add myset ::1
ipset v7.19: Syntax error: cannot parse ::1: resolving to IPv4 address failed

# ipset destroy myset
# ipset create myset hash:ip family inet6
# ipset add myset ::1
# ipset add myset 127.0.0.1
ipset v7.19: Syntax error: cannot parse 127.0.0.1: resolving to IPv6 address failed

As far as the present topic is concerned, the only tangible advantage that ipset has is the ability to create a set whose sole purpose is to act as a superset of other - potentially mixed - sets. This advantage is rather diminished by the fact that one also has to two manage two entirely separate rulesets with iptables and ip6tables, notwithstanding that wrappers such as fermi exist. At any rate, the follow nftables ruleset is valid.

table inet filter {
        set block4 {
                type ipv4_addr
        }
        set block6 {
                type ipv6_addr
        }
        chain INPUT {
                type filter hook input priority filter; policy accept
                ip saddr @block4 drop
                ip6 saddr @block6 drop
        }
}

>
>> However, the value of an ipv6_addr element is permitted to be an IPv4-mapped IPv6 address.
>
> Does nft have a function to convert an IPv4 address to an IPv4-mapped
> address? Will the rule set do the intended thing? Is an ipv6 rule with
> an IPv4 mapped address fully equivalent with a proper IPv4 rule?

I do not know, as I have not yet attempted to use them in an ipv6_addr set (it would waste memory). That said, my expectation would be that they have to be specified in the appropriate format and that they would only be applicable to dual-stack applications. In that case, they might sometimes prove helpful, particularly as Linux defaults to having the "net.ipv6.bindv6only" sysctl be set to "0".

-- 
Kerin Millar

  parent reply	other threads:[~2024-01-30 15:18 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-30 10:17 Combine ipv4 and ipv6 in a set Daniel
2024-01-30 10:39 ` Kerin Millar
2024-01-30 12:13   ` Daniel
2024-01-30 12:59     ` Daniel
2024-01-30 13:08   ` Marc Haber
2024-01-30 13:22     ` Kim B. Heino
2024-01-31 10:21       ` Marc Haber
2024-01-31 11:22         ` Kim B. Heino
2024-01-30 15:17     ` Kerin Millar [this message]
2024-01-30 17:00       ` Slavko
2024-01-30 17:57         ` Kerin Millar
2024-01-30 19:34           ` Slavko
2024-01-30 22:05             ` Kerin Millar
2024-02-01 12:13               ` Marc Haber
2024-01-31 11:27             ` Marc Haber
2024-01-31 11:13           ` Marc Haber
2024-01-31 11:00         ` Marc Haber
2024-01-31 10:54       ` Marc Haber
2024-01-31 11:55         ` Daniel
2024-02-01 11:39           ` Marc Haber
2024-01-31 13:02         ` Kerin Millar
2024-01-31 20:23           ` Slavko
2024-01-31 22:10             ` Kerin Millar
2024-02-01  6:06               ` Kevin P. Fleming
2024-02-01 17:09                 ` Kerin Millar
2024-02-01 10:50               ` Slavko
2024-02-01 12:48                 ` Kerin Millar
2024-02-01 13:42                   ` Slavko
2024-02-01 14:03                     ` Kerin Millar
2024-01-31 22:36             ` Pablo Neira Ayuso
2024-02-01  8:22               ` Slavko
2024-02-02  1:38               ` Eric
2024-02-02  9:23                 ` Pablo Neira Ayuso
2024-02-03  9:24                   ` Slavko
2024-02-03 15:49                   ` Eric
2024-02-05  9:47                     ` Pablo Neira Ayuso
2024-02-05 17:02                       ` Eric
2024-02-05 17:08                         ` Pablo Neira Ayuso
2024-02-05 17:16                           ` Eric
2024-02-01 11:33           ` Marc Haber

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=cd7cbfc0-b7d4-4713-9e2d-f92596fb4844@app.fastmail.com \
    --to=kfm@plushkava.net \
    --cc=mh+netfilter@zugschlus.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.