[PATCH v9 0/5] Introduce multiple addresses
This series lets passt and pasta handle more than one IPv4 and IPv6 address per guest, building on the unified address array already upstream: - addr_fixed is replaced by the CONF_ADDR_USER flag - guest accessibility checks and ARP filtering consider all configured addresses, not only the first one of each family - -a/--address can be given multiple times; the first address of each family is still the one handed out via DHCP and DHCPv6/NDP - in pasta, all addresses of the template interface are read at startup, and copied to the namespace with --config-net Tested with pasta in a namespace without connectivity, both with multiple -a options and --config-net (all addresses and routes set up, echo requests from every address answered), and with the plain local mode defaults. ---- v2: -Using inany_addr instead of protocol specific addresses as entry address field. v3: -Merging into one array, directly in struct ctx -Changed prefix_len and flags fields in struct inany_addr_entry to uint8_t, since that makes the struct directly migratable v4: -Updated according to changes in previous commits -Updated according to feedback from David G. -Squashed IP4_MASK macro commit into this one v6: -Renamed and moved some definitions -Introduced fwd_set_addr() and fwd_get_addr() already in this commit -Eliminated first_v4/v6() functions, replaced with fwd_get_addr() -Some other changes as suggested by David G. -I kept the flag CONF_ADDR_LINKLOCAL, since it will be needed later in an address selection function. v7: -Introduced CONF_ADDR_GENERATED flag -Other fixes based on feedback from David and Stefano. -I changed signature of inany_prefix_len(), but I did not change its semantics, since the premise of David's comment is wrong: the caller does *not* explicitly know he is dealing with an IPv4 address. In fact, there are examples later in this series where it may be an IPv6 address, and the caller just trusts he gets the return value in the appropriate format. -Intoduced the inverse of inany_prefix_len(), called inany_prefix_len6() which always returns the prefix in IPv6 or mapped IPv4 format. The name of the function isn't great, but any alternative I came up with became too long to be practical. v8: -Added inany_prefix_v4() (David G.) to extract IPv4 address and prefix length simultaneously, replacing inany_prefix_len(). -Removed both inany_prefix_len() and inany_prefix_len6() auto-detecting functions. Prefix length attached to an inany is now always stored in IPv6 format (96-128 for IPv4-mapped). -fwd_set_addr() now requires prefix_len in IPv6 format; callers updated to pass prefix_len + 96 for IPv4 addresses. -Fixed -n option to store prefix_len in IPv6 format. -Fixed addr_seen regression: when address was set via -a, addr_seen was not initialised in conf_ip4(). -Replaced assert() with graceful no-op in dhcp.c and ndp.c when no address is configured (David G.). -Note: addr_seen is still initialised both at conf_ip*() time and at DHCP/DHCPv6 send time (David's concern). This inconsistency will be addressed in a follow-up. -Introduced a new CONF_ADDR_ANY macro tobe used for address selection, as suggested by Stefano. -Deferred introduction of an explicit scope field (replacing CONF_ADDR_LINKLOCAL flag) to a later commit or series. v9: -Posting without first commit in previous version, since that one has already been applied upstream. -Posted with only the next 5 commits in the previous version of the series, to make it more manageable. This was suggested by David Gibson. Jon Maloy (5): tap, conf: Replace addr_fixed with CONF_ADDR_USER flag check fwd: Unify guest accessibility checks with unified address array arp: Check all configured addresses in ARP filtering conf: Allow multiple -a/--address options per address family netlink, conf: Read all addresses from template interface at startup Jon Maloy (5): tap, conf: Replace addr_fixed with CONF_ADDR_USER flag check fwd: Unify guest accessibility checks with unified address array arp: Check all configured addresses in ARP filtering conf: Allow multiple -a/--address options per address family netlink, conf: Read all addresses from template interface at startup arp.c | 16 +++++----- conf.c | 63 +++++++++++++++++---------------------- fwd.c | 80 +++++++++++++------------------------------------- netlink.c | 88 ++++++++++++++++++++++++++++++++++++++++--------------- netlink.h | 3 +- passt.1 | 18 +++++------- passt.h | 6 ---- pasta.c | 27 +++++++++-------- tap.c | 6 ++-- 9 files changed, 145 insertions(+), 162 deletions(-) -- 2.56.1
Allow specifying multiple addresses per family with -a/--address.
The first address of each family is used for DHCP/DHCPv6 assignment.
Link: https://bugs.passt.top/show_bug.cgi?id=47
Cc: lemmi@nerd2nerd.org
Signed-off-by: Jon Maloy
We replace the fwd_guest_accessible4() and fwd_guest_accessible6()
functions with a unified fwd_guest_accessible() function that handles
both address families. With the unified address array, we can check
all configured addresses in a single pass using for_each_addr() with
family filter AF_UNSPEC.
Signed-off-by: Jon Maloy
As a preparation for handling multiple addresses, we update ignore_arp()
to check against all addresses in the unified addrs[] array using the
for_each_addr() macro.
Signed-off-by: Jon Maloy
Add nl_addr_get_all() to read all addresses from the template interface
into the c->addrs[] array, replacing nl_addr_get(), which only returned
a single address per family.
With pasta and --config-net, all addresses of the template interface
are already copied to the namespace, but so far, we only knew about one
of them. Recording all of them lets the address checks, ARP filtering
and the guest accessibility checks consider every address the guest
might use, and makes multi-address setups work in passt mode, too.
The first address of each family in c->addrs[] is the one we assign
via DHCP, DHCPv6 and NDP. To keep the behaviour introduced by commit
f091893c1ffe ("netlink: Fetch most specific (longest prefix) address
in nl_addr_get()"), add the address with the longest prefix first, and
the other ones after it, in the order reported by the kernel. Otherwise,
in nested setups, an L2 guest would pick the address the L1 guest
obtained via SLAAC rather than the one matching the host via DHCPv6.
For IPv6, the function also stores the link-local address with the
longest prefix into c->ip6.our_tap_ll, as nl_addr_get() did. IPv4
addresses with link scope are now skipped altogether.
Update conf_ip4() and conf_ip6() to use nl_addr_get_all() when no
user-provided addresses are present.
Signed-off-by: Jon Maloy
participants (1)
-
Jon Maloy