From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=IKK861kF; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTPS id ED17F5A0653 for ; Mon, 15 Dec 2025 23:05:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1765836347; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wlirHzqfyd/hW/s+ToMXUWS70rpbr5t9SzMIJ4ugEMc=; b=IKK861kFGPFcXKmCnL+Yn57dZ0ntZjrihfgQ9vNuFVStKTAUeZc87BJnDnLEY9QD80RTXL 0hSyKpd8U+bbXEsg5Bhb6bVq6Eavi54K89W3rorQhEFdGOG7OAEmW2cvPZ6qzyUwj4KxUl vh+E8LD/kxwjgEZqWmc7VKnfEiRJj1Q= Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-378-_JjZAuT4OxGq5wjmXmfOfw-1; Mon, 15 Dec 2025 17:05:45 -0500 X-MC-Unique: _JjZAuT4OxGq5wjmXmfOfw-1 X-Mimecast-MFC-AGG-ID: _JjZAuT4OxGq5wjmXmfOfw_1765836344 Received: by mail-pg1-f199.google.com with SMTP id 41be03b00d2f7-be8c77ecc63so6170695a12.2 for ; Mon, 15 Dec 2025 14:05:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765836344; x=1766441144; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=wlirHzqfyd/hW/s+ToMXUWS70rpbr5t9SzMIJ4ugEMc=; b=tXo5cS69RDZ7BUp8vP0NsB6FwnOsZ2BR0wkDI2bjYZUSPJrw7fi7vfqb90nFfcdR8I HlqHvSU4J4dPMsZhAtqTgj72C9s5oeRXxSZWWGbgqmO0xZHs463gVw97EYn0bDgDrbqa 8xVuWBrgzWXbOp2NgvmS/B3Ddw2JIXaJyaKHjI5oZYnj7aGEhIzCjGc5sIGUdKj53lGN 3gEFwqYvBMKpwBtEHxbvckuphYEOgncCwjrn5N0HKR57Ypbs4g2Sp8KWVSWpKL0GjBdh VPKuuA9UD8ScvVf6UD97P/LhW7ghsvczkMsEav6+n8fC2dFOl4Ej/CxnXcV+XSHOEeyS +I8w== X-Gm-Message-State: AOJu0Yyih4P61PlWgCcriU5uo09EuNRnDCZ3+1Fh1wb4txV2tUOOlmU6 /bJ0SrvZ8C3AZhezJRMYlNTzjk2N5BVy1X69si0NGKa1HAzYYmS5osYfl2djqngp+A4Zqwwnkv4 JnZ3rLmVB5+TfgvypR8TmedTqj22kbid/ttqmArOqRX3tkK1mlcEhOmWIMCu5B0i1OQEhej24+o 5p3zluOYBiSME8uGM7/0WE2Hm+Lqq/20TO1S0= X-Gm-Gg: AY/fxX5hOfuMUmZu5HM2YUfVg+mtFzVFNvSOMAEr3Sr0aeDHWllt4MJnJkvKwCPiC6k rXhTXBbf5Zvy+d3Jsd18juv2fijW8lZ2/4u8Soa4ZmUkBQLfycs4ydkE9kGOzzS++z9Xq39S3xk FtQ/ndVCmnSYFaehhc/E/E/J8UloUSNzJbZV71ycCL8VPjLeOO/f9lSS7tJTOWnkH6yTcbKhrne naPnf5J8A0d3bYBtvaKQhNu7m8Bpg1qJorPvBRmJWeg0dkLFiZSu2S6VmcBfHGGMhMe8BIJKKHl mZQ1ifIfV+EtkXIq5QMXmNcXE6EgtfDaceOH/LBOcAHaSmJvLEBh4iG9qzf24Q6iBjtq9OYFHol PmE3ZvE5TBcqcdL2UNHeGNC3rDoCeMKBDg6OXu0AaZmJnu9tPY4aCpMmDo5pEr8gWzhIXIiJ97N 2/Ekh3 X-Received: by 2002:a05:7300:d206:b0:2a4:3593:c7d0 with SMTP id 5a478bee46e88-2ac2f8b1017mr7013895eec.16.1765836343583; Mon, 15 Dec 2025 14:05:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IFYiCrvKCZvNEBY+0mJyTzGlH8LQkt96zR81VmiibiSHDPPWGgsGS8DxdnCvKMGQ6xjrwuMmw== X-Received: by 2002:a05:7300:d206:b0:2a4:3593:c7d0 with SMTP id 5a478bee46e88-2ac2f8b1017mr7013862eec.16.1765836342687; Mon, 15 Dec 2025 14:05:42 -0800 (PST) Received: from [192.168.2.15] (lnsm3-montreal02-142-116-222-198.internet.virginmobile.ca. [142.116.222.198]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2ac342eeaaasm21685401eec.6.2025.12.15.14.05.40 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 15 Dec 2025 14:05:42 -0800 (PST) Message-ID: Date: Mon, 15 Dec 2025 17:05:38 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC 01/12] ip: Introduce multi-address data structures for IPv4 and IPv6 To: passt-dev@passt.top References: <20251215015441.887736-1-jmaloy@redhat.com> <20251215015441.887736-2-jmaloy@redhat.com> From: Jon Maloy In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 06hzR6koqG0dQnbIt1k6crIydLEo3YJExGYhv22Y-Xg_1765836344 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID-Hash: V23QUZQHDSZN4JMCUBGPYVTDFFY27PL3 X-Message-ID-Hash: V23QUZQHDSZN4JMCUBGPYVTDFFY27PL3 X-MailFrom: jmaloy@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On 2025-12-15 04:40, David Gibson wrote: > On Sun, Dec 14, 2025 at 08:54:30PM -0500, Jon Maloy wrote: >> As preparation for supporting multiple addresses per interface, we >> replace the single addr/prefix_len fields with arrays. >> >> - We add an ip4_addr_entry and an ip6_addr_entry struct containing >> address and prefix length. >> >> - We set the array sizes to IP4_MAX_ADDRS=8 and IP6_MAX_ADDRS=16, >> respectively. >> >> The only functional change is that the IPv6 prefix length now is >> properly stored instead of being hardcoded to 64 even when set >> via the -a option. >> >> Signed-off-by: Jon Maloy >> --- >> arp.c | 4 +-- >> conf.c | 97 +++++++++++++++++++++++++++++++++----------------------- >> dhcp.c | 8 ++--- >> dhcpv6.c | 6 ++-- >> fwd.c | 12 +++---- >> ip.h | 26 +++++++++++++++ >> ndp.c | 6 ++-- >> passt.h | 16 ++++++---- >> pasta.c | 12 ++++--- >> tap.c | 4 +-- >> util.h | 1 + >> 11 files changed, 122 insertions(+), 70 deletions(-) >> >> diff --git a/arp.c b/arp.c >> index bb042e9..7eaf517 100644 >> --- a/arp.c >> +++ b/arp.c >> @@ -54,7 +54,7 @@ static bool ignore_arp(const struct ctx *c, >> return true; >> >> /* Don't resolve the guest's assigned address, either. */ >> - if (!memcmp(am->tip, &c->ip4.addr, sizeof(am->tip))) >> + if (!memcmp(am->tip, &c->ip4.addrs[0].addr, sizeof(am->tip))) >> return true; >> >> return false; >> @@ -145,7 +145,7 @@ void arp_send_init_req(const struct ctx *c) >> memcpy(req.am.sha, c->our_tap_mac, sizeof(req.am.sha)); >> memcpy(req.am.sip, &c->ip4.our_tap_addr, sizeof(req.am.sip)); >> memcpy(req.am.tha, MAC_BROADCAST, sizeof(req.am.tha)); >> - memcpy(req.am.tip, &c->ip4.addr, sizeof(req.am.tip)); >> + memcpy(req.am.tip, &c->ip4.addrs[0].addr, sizeof(req.am.tip)); >> >> debug("Sending initial ARP request for guest MAC address"); >> tap_send_single(c, &req, sizeof(req)); >> diff --git a/conf.c b/conf.c >> index fdc19e8..0e96f36 100644 >> --- a/conf.c >> +++ b/conf.c >> @@ -694,10 +694,12 @@ static int conf_ip4_prefix(const char *arg) >> * conf_ip4() - Verify or detect IPv4 support, get relevant addresses >> * @ifi: Host interface to attempt (0 to determine one) >> * @ip4: IPv4 context (will be written) >> + * @permanent: Mark configured addresses as permanent >> * >> * Return: interface index for IPv4, or 0 on failure. >> */ >> -static unsigned int conf_ip4(unsigned int ifi, struct ip4_ctx *ip4) >> +static unsigned int conf_ip4(unsigned int ifi, struct ip4_ctx *ip4, >> + bool permanent) >> { >> if (!ifi) >> ifi = nl_get_ext_if(nl_sock, AF_INET); >> @@ -717,33 +719,38 @@ static unsigned int conf_ip4(unsigned int ifi, struct ip4_ctx *ip4) >> } >> } >> >> - if (IN4_IS_ADDR_UNSPECIFIED(&ip4->addr)) { >> + if (!ip4->addr_count) { >> int rc = nl_addr_get(nl_sock, ifi, AF_INET, >> - &ip4->addr, &ip4->prefix_len, NULL); >> + &ip4->addrs[0].addr, >> + &ip4->addrs[0].prefix_len, NULL); >> if (rc < 0) { >> debug("Couldn't discover IPv4 address: %s", >> strerror_(-rc)); >> return 0; >> } >> + ip4->addrs[0].permanent = permanent; >> + ip4->addr_count = 1; >> } >> >> - if (!ip4->prefix_len) { >> - in_addr_t addr = ntohl(ip4->addr.s_addr); >> - if (IN_CLASSA(addr)) >> - ip4->prefix_len = (32 - IN_CLASSA_NSHIFT); >> - else if (IN_CLASSB(addr)) >> - ip4->prefix_len = (32 - IN_CLASSB_NSHIFT); >> - else if (IN_CLASSC(addr)) >> - ip4->prefix_len = (32 - IN_CLASSC_NSHIFT); >> + /* Apply default prefix_len to first address if not set */ >> + if (!ip4->addrs[0].prefix_len) { >> + in_addr_t a = ntohl(ip4->addrs[0].addr.s_addr); >> + >> + if (IN_CLASSA(a)) >> + ip4->addrs[0].prefix_len = 8; >> + else if (IN_CLASSB(a)) >> + ip4->addrs[0].prefix_len = 16; >> + else if (IN_CLASSC(a)) >> + ip4->addrs[0].prefix_len = 24; >> else >> - ip4->prefix_len = 32; >> + ip4->addrs[0].prefix_len = 32; >> } >> >> - ip4->addr_seen = ip4->addr; >> + ip4->addr_seen = ip4->addrs[0].addr; >> >> ip4->our_tap_addr = ip4->guest_gw; >> >> - if (IN4_IS_ADDR_UNSPECIFIED(&ip4->addr)) >> + if (IN4_IS_ADDR_UNSPECIFIED(&ip4->addrs[0].addr)) >> return 0; >> >> return ifi; >> @@ -755,9 +762,9 @@ static unsigned int conf_ip4(unsigned int ifi, struct ip4_ctx *ip4) >> */ >> static void conf_ip4_local(struct ip4_ctx *ip4) >> { >> - ip4->addr_seen = ip4->addr = IP4_LL_GUEST_ADDR; >> + ip4->addr_seen = ip4->addrs[0].addr = IP4_LL_GUEST_ADDR; >> ip4->our_tap_addr = ip4->guest_gw = IP4_LL_GUEST_GW; >> - ip4->prefix_len = IP4_LL_PREFIX_LEN; >> + ip4->addrs[0].prefix_len = IP4_LL_PREFIX_LEN; >> >> ip4->no_copy_addrs = ip4->no_copy_routes = true; >> } >> @@ -766,10 +773,12 @@ static void conf_ip4_local(struct ip4_ctx *ip4) >> * conf_ip6() - Verify or detect IPv6 support, get relevant addresses >> * @ifi: Host interface to attempt (0 to determine one) >> * @ip6: IPv6 context (will be written) >> + * @permanent: Mark discovered addresses as permanent >> * >> * Return: interface index for IPv6, or 0 on failure. >> */ >> -static unsigned int conf_ip6(unsigned int ifi, struct ip6_ctx *ip6) >> +static unsigned int conf_ip6(unsigned int ifi, struct ip6_ctx *ip6, >> + bool permanent) >> { >> int prefix_len = 0; >> int rc; >> @@ -792,19 +801,25 @@ static unsigned int conf_ip6(unsigned int ifi, struct ip6_ctx *ip6) >> } >> >> rc = nl_addr_get(nl_sock, ifi, AF_INET6, >> - IN6_IS_ADDR_UNSPECIFIED(&ip6->addr) ? &ip6->addr : NULL, >> + ip6->addr_count ? NULL : &ip6->addrs[0].addr, >> &prefix_len, &ip6->our_tap_ll); >> if (rc < 0) { >> debug("Couldn't discover IPv6 address: %s", strerror_(-rc)); >> return 0; >> } >> >> - ip6->addr_seen = ip6->addr; >> + if (!ip6->addr_count) { >> + ip6->addrs[0].prefix_len = prefix_len ? prefix_len : 64; >> + ip6->addrs[0].permanent = permanent; >> + ip6->addr_count = 1; >> + } >> + >> + ip6->addr_seen = ip6->addrs[0].addr; >> >> if (IN6_IS_ADDR_LINKLOCAL(&ip6->guest_gw)) >> ip6->our_tap_ll = ip6->guest_gw; >> >> - if (IN6_IS_ADDR_UNSPECIFIED(&ip6->addr) || >> + if (IN6_IS_ADDR_UNSPECIFIED(&ip6->addrs[0].addr) || >> IN6_IS_ADDR_UNSPECIFIED(&ip6->our_tap_ll)) >> return 0; >> >> @@ -1149,11 +1164,13 @@ static void conf_print(const struct ctx *c) >> if (!c->no_dhcp) { >> uint32_t mask; >> >> - mask = htonl(0xffffffff << (32 - c->ip4.prefix_len)); >> + mask = htonl(0xffffffff << >> + (32 - c->ip4.addrs[0].prefix_len)); >> >> info("DHCP:"); >> info(" assign: %s", >> - inet_ntop(AF_INET, &c->ip4.addr, buf4, sizeof(buf4))); >> + inet_ntop(AF_INET, &c->ip4.addrs[0].addr, >> + buf4, sizeof(buf4))); >> info(" mask: %s", >> inet_ntop(AF_INET, &mask, buf4, sizeof(buf4))); >> info(" router: %s", >> @@ -1191,7 +1208,8 @@ static void conf_print(const struct ctx *c) >> goto dns6; >> >> info(" assign: %s", >> - inet_ntop(AF_INET6, &c->ip6.addr, buf6, sizeof(buf6))); >> + inet_ntop(AF_INET6, &c->ip6.addrs[0].addr, >> + buf6, sizeof(buf6))); >> info(" router: %s", >> inet_ntop(AF_INET6, &c->ip6.guest_gw, buf6, sizeof(buf6))); >> info(" our link-local: %s", >> @@ -1812,22 +1830,23 @@ void conf(struct ctx *c, int argc, char **argv) >> break; >> } >> case 'a': >> - if (inet_pton(AF_INET6, optarg, &c->ip6.addr) && >> - !IN6_IS_ADDR_UNSPECIFIED(&c->ip6.addr) && >> - !IN6_IS_ADDR_LOOPBACK(&c->ip6.addr) && >> - !IN6_IS_ADDR_V4MAPPED(&c->ip6.addr) && >> - !IN6_IS_ADDR_V4COMPAT(&c->ip6.addr) && >> - !IN6_IS_ADDR_MULTICAST(&c->ip6.addr)) { >> + if (inet_pton(AF_INET6, optarg, >> + &c->ip6.addrs[0].addr) && >> + !IN6_IS_ADDR_UNSPECIFIED(&c->ip6.addrs[0].addr) && >> + !IN6_IS_ADDR_LOOPBACK(&c->ip6.addrs[0].addr) && >> + !IN6_IS_ADDR_V4MAPPED(&c->ip6.addrs[0].addr) && >> + !IN6_IS_ADDR_V4COMPAT(&c->ip6.addrs[0].addr) && >> + !IN6_IS_ADDR_MULTICAST(&c->ip6.addrs[0].addr)) { >> if (c->mode == MODE_PASTA) >> c->ip6.no_copy_addrs = true; >> break; >> } >> >> - if (inet_pton(AF_INET, optarg, &c->ip4.addr) && >> - !IN4_IS_ADDR_UNSPECIFIED(&c->ip4.addr) && >> - !IN4_IS_ADDR_BROADCAST(&c->ip4.addr) && >> - !IN4_IS_ADDR_LOOPBACK(&c->ip4.addr) && >> - !IN4_IS_ADDR_MULTICAST(&c->ip4.addr)) { >> + if (inet_pton(AF_INET, optarg, &c->ip4.addrs[0].addr) && >> + !IN4_IS_ADDR_UNSPECIFIED(&c->ip4.addrs[0].addr) && >> + !IN4_IS_ADDR_BROADCAST(&c->ip4.addrs[0].addr) && >> + !IN4_IS_ADDR_LOOPBACK(&c->ip4.addrs[0].addr) && >> + !IN4_IS_ADDR_MULTICAST(&c->ip4.addrs[0].addr)) { >> if (c->mode == MODE_PASTA) >> c->ip4.no_copy_addrs = true; >> break; >> @@ -1836,8 +1855,8 @@ void conf(struct ctx *c, int argc, char **argv) >> die("Invalid address: %s", optarg); >> break; >> case 'n': >> - c->ip4.prefix_len = conf_ip4_prefix(optarg); >> - if (c->ip4.prefix_len < 0) >> + c->ip4.addrs[0].prefix_len = conf_ip4_prefix(optarg); >> + if (c->ip4.addrs[0].prefix_len < 0) >> die("Invalid netmask: %s", optarg); >> >> break; >> @@ -1984,9 +2003,9 @@ void conf(struct ctx *c, int argc, char **argv) >> >> nl_sock_init(c, false); >> if (!v6_only) >> - c->ifi4 = conf_ip4(ifi4, &c->ip4); >> + c->ifi4 = conf_ip4(ifi4, &c->ip4, c->pasta_conf_ns); >> if (!v4_only) >> - c->ifi6 = conf_ip6(ifi6, &c->ip6); >> + c->ifi6 = conf_ip6(ifi6, &c->ip6, c->pasta_conf_ns); >> >> if (c->ifi4 && c->mtu < IPV4_MIN_MTU) { >> warn("MTU %"PRIu16" is too small for IPv4 (minimum %u)", >> @@ -2125,7 +2144,7 @@ void conf(struct ctx *c, int argc, char **argv) >> if (!c->ifi6) { >> c->no_ndp = 1; >> c->no_dhcpv6 = 1; >> - } else if (IN6_IS_ADDR_UNSPECIFIED(&c->ip6.addr)) { >> + } else if (IN6_IS_ADDR_UNSPECIFIED(&c->ip6.addrs[0].addr)) { >> c->no_dhcpv6 = 1; >> } >> >> diff --git a/dhcp.c b/dhcp.c >> index 6b9c2e3..46ef8e3 100644 >> --- a/dhcp.c >> +++ b/dhcp.c >> @@ -352,7 +352,7 @@ int dhcp(const struct ctx *c, struct iov_tail *data) >> reply.secs = 0; >> reply.flags = m->flags; >> reply.ciaddr = m->ciaddr; >> - reply.yiaddr = c->ip4.addr; >> + reply.yiaddr = c->ip4.addrs[0].addr; >> reply.siaddr = 0; >> reply.giaddr = m->giaddr; >> memcpy(&reply.chaddr, m->chaddr, sizeof(reply.chaddr)); >> @@ -404,7 +404,7 @@ int dhcp(const struct ctx *c, struct iov_tail *data) >> >> info(" from %s", eth_ntop(m->chaddr, macstr, sizeof(macstr))); >> >> - mask.s_addr = htonl(0xffffffff << (32 - c->ip4.prefix_len)); >> + mask.s_addr = htonl(0xffffffff << (32 - c->ip4.addrs[0].prefix_len)); >> memcpy(opts[1].s, &mask, sizeof(mask)); >> memcpy(opts[3].s, &c->ip4.guest_gw, sizeof(c->ip4.guest_gw)); >> memcpy(opts[54].s, &c->ip4.our_tap_addr, sizeof(c->ip4.our_tap_addr)); >> @@ -412,7 +412,7 @@ int dhcp(const struct ctx *c, struct iov_tail *data) >> /* If the gateway is not on the assigned subnet, send an option 121 >> * (Classless Static Routing) adding a dummy route to it. >> */ >> - if ((c->ip4.addr.s_addr & mask.s_addr) >> + if ((c->ip4.addrs[0].addr.s_addr & mask.s_addr) >> != (c->ip4.guest_gw.s_addr & mask.s_addr)) { >> /* a.b.c.d/32:0.0.0.0, 0:a.b.c.d */ >> opts[121].slen = 14; >> @@ -469,7 +469,7 @@ int dhcp(const struct ctx *c, struct iov_tail *data) >> if (m->flags & FLAG_BROADCAST) >> dst = in4addr_broadcast; >> else >> - dst = c->ip4.addr; >> + dst = c->ip4.addrs[0].addr; >> >> tap_udp4_send(c, c->ip4.our_tap_addr, 67, dst, 68, &reply, dlen); >> >> diff --git a/dhcpv6.c b/dhcpv6.c >> index e4df0db..7eae6a1 100644 >> --- a/dhcpv6.c >> +++ b/dhcpv6.c >> @@ -625,7 +625,7 @@ int dhcpv6(struct ctx *c, struct iov_tail *data, >> if (mh->type == TYPE_CONFIRM && server_id) >> return -1; >> >> - if (dhcpv6_ia_notonlink(data, &c->ip6.addr)) { >> + if (dhcpv6_ia_notonlink(data, &c->ip6.addrs[0].addr)) { >> >> dhcpv6_send_ia_notonlink(c, data, &client_id_base, >> ntohs(client_id->l), mh->xid); >> @@ -679,7 +679,7 @@ int dhcpv6(struct ctx *c, struct iov_tail *data, >> >> tap_udp6_send(c, src, 547, tap_ip6_daddr(c, src), 546, >> mh->xid, &resp, n); >> - c->ip6.addr_seen = c->ip6.addr; >> + c->ip6.addr_seen = c->ip6.addrs[0].addr; >> >> return 1; >> } >> @@ -703,5 +703,5 @@ void dhcpv6_init(const struct ctx *c) >> memcpy(resp_not_on_link.server_id.duid_lladdr, >> c->our_tap_mac, sizeof(c->our_tap_mac)); >> >> - resp.ia_addr.addr = c->ip6.addr; >> + resp.ia_addr.addr = c->ip6.addrs[0].addr; >> } >> diff --git a/fwd.c b/fwd.c >> index 44a0e10..408af30 100644 >> --- a/fwd.c >> +++ b/fwd.c >> @@ -516,7 +516,7 @@ static bool fwd_guest_accessible4(const struct ctx *c, >> /* For IPv4, addr_seen is initialised to addr, so is always a valid >> * address >> */ >> - if (IN4_ARE_ADDR_EQUAL(addr, &c->ip4.addr) || >> + if (IN4_ARE_ADDR_EQUAL(addr, &c->ip4.addrs[0].addr) || >> IN4_ARE_ADDR_EQUAL(addr, &c->ip4.addr_seen)) >> return false; >> >> @@ -537,7 +537,7 @@ static bool fwd_guest_accessible6(const struct ctx *c, >> if (IN6_IS_ADDR_LOOPBACK(addr)) >> return false; >> >> - if (IN6_ARE_ADDR_EQUAL(addr, &c->ip6.addr)) >> + if (IN6_ARE_ADDR_EQUAL(addr, &c->ip6.addrs[0].addr)) >> return false; >> >> /* For IPv6, addr_seen starts unspecified, because we don't know what LL >> @@ -587,9 +587,9 @@ static void nat_outbound(const struct ctx *c, const union inany_addr *addr, >> else if (inany_equals6(addr, &c->ip6.map_host_loopback)) >> *translated = inany_loopback6; >> else if (inany_equals4(addr, &c->ip4.map_guest_addr)) >> - *translated = inany_from_v4(c->ip4.addr); >> + *translated = inany_from_v4(c->ip4.addrs[0].addr); >> else if (inany_equals6(addr, &c->ip6.map_guest_addr)) >> - translated->a6 = c->ip6.addr; >> + translated->a6 = c->ip6.addrs[0].addr; >> else >> *translated = *addr; >> } >> @@ -710,10 +710,10 @@ bool nat_inbound(const struct ctx *c, const union inany_addr *addr, >> inany_equals6(addr, &in6addr_loopback)) { >> translated->a6 = c->ip6.map_host_loopback; >> } else if (!IN4_IS_ADDR_UNSPECIFIED(&c->ip4.map_guest_addr) && >> - inany_equals4(addr, &c->ip4.addr)) { >> + inany_equals4(addr, &c->ip4.addrs[0].addr)) { >> *translated = inany_from_v4(c->ip4.map_guest_addr); >> } else if (!IN6_IS_ADDR_UNSPECIFIED(&c->ip6.map_guest_addr) && >> - inany_equals6(addr, &c->ip6.addr)) { >> + inany_equals6(addr, &c->ip6.addrs[0].addr)) { >> translated->a6 = c->ip6.map_guest_addr; >> } else if (fwd_guest_accessible(c, addr)) { >> *translated = *addr; >> diff --git a/ip.h b/ip.h >> index 5830b92..748cb1f 100644 >> --- a/ip.h >> +++ b/ip.h >> @@ -135,4 +135,30 @@ static const struct in_addr in4addr_broadcast = { 0xffffffff }; >> #define IPV6_MIN_MTU 1280 >> #endif >> >> +/* Maximum number of addresses per address family */ >> +#define IP4_MAX_ADDRS 8 >> +#define IP6_MAX_ADDRS 16 >> + >> +/** >> + * struct ip4_addr_entry - IPv4 address with prefix length >> + * @addr: IPv4 address >> + * @prefix_len: Prefix length (netmask bits) >> + */ >> +struct ip4_addr_entry { >> + struct in_addr addr; >> + int prefix_len; >> + int permanent; > > Might as well make these uint8_t and bool, respectively. There will > be some padding, but the overall structure will still be smaller. > > Or, it might be worth considering replacing 'permanent' with a flags > mask, in case we have future uses for it. Agree with that. I'll make that change, and if we ver need more we can replace the boolean with a bitmask. /jon >