From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id D4C945A027F for ; Mon, 29 Jan 2024 05:36:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1706502960; bh=u2d2q+3cfArRmwDK1Stbmd0zJtxEycW3qtguAcleFB8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c8kDJAJUCuxaQenj5Wn7BdFPqeEWyVkXhlPpQaqKuVf4OwwNBJula4vhPUPKioZOf 1SA7Pmu3PbbV0hyaZ4TaUAaO9cm7xmahi+4ZbTA5kx+AnBk7Z3u/ib+9Vc9QuTLZPj 5/4We6nyBDAmCx16EUby9SsHk4ckdugV3O4EDTtLavHCEIw6F6EHcOWdbbc07Z2FhY cI1pHw3FYTEZRDpLu0KjiDWKDs8iiiA9oQTikvitrQE53KjtANLO4MSbmsFmWHFH+K BoOF7ybl22LaaLQ6oKMiv/BTWibL3v9XYUzQgbvy6rufDPZ8uGdtj46vG2TNnOIr5+ 8vAkD/Nj4g5EA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4TNb8c00pvz4x5r; Mon, 29 Jan 2024 15:35:59 +1100 (AEDT) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH 16/16] inany: Extend inany_from_af to easily set unspecified addresses Date: Mon, 29 Jan 2024 15:35:57 +1100 Message-ID: <20240129043557.823451-17-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240129043557.823451-1-david@gibson.dropbear.id.au> References: <20240129043557.823451-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: LMFCKNBQVZIUQIRKOJUI5FDFS3WOH5NS X-Message-ID-Hash: LMFCKNBQVZIUQIRKOJUI5FDFS3WOH5NS X-MailFrom: dgibson@gandalf.ozlabs.org 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 CC: David Gibson 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: inany_from_af() can be used to initialise a union inany_addr from either an IPv4 or IPv6 address. If we want to set it to the unspecified IPv4 or IPv6 address we can do that, but need to explicitly pass the correct address version. Make this easier by allowing it to interpret a NULL address as the unspecified address of the appropriate family. We only have one trivial use for this at present, but it will have more uses in future. Signed-off-by: David Gibson --- inany.h | 10 ++++++++-- tcp.c | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/inany.h b/inany.h index 063545b7..70237821 100644 --- a/inany.h +++ b/inany.h @@ -92,11 +92,17 @@ static inline void inany_from_af(union inany_addr *aa, sa_family_t af, const void *addr) { if (af == AF_INET6) { - aa->a6 = *((struct in6_addr *)addr); + if (addr) + aa->a6 = *((struct in6_addr *)addr); + else + aa->a6 = in6addr_any; } else if (af == AF_INET) { memset(&aa->v4mapped.zero, 0, sizeof(aa->v4mapped.zero)); memset(&aa->v4mapped.one, 0xff, sizeof(aa->v4mapped.one)); - aa->v4mapped.a4 = *((struct in_addr *)addr); + if (addr) + aa->v4mapped.a4 = *((struct in_addr *)addr); + else + aa->v4mapped.a4 = in4addr_any; } else { /* Not valid to call with other address families */ ASSERT(0); diff --git a/tcp.c b/tcp.c index 6c9edbe1..1326584e 100644 --- a/tcp.c +++ b/tcp.c @@ -883,7 +883,7 @@ static void tcp_rtt_dst_check(const struct tcp_tap_conn *conn, low_rtt_dst[hole++] = conn->faddr; if (hole == LOW_RTT_TABLE_SIZE) hole = 0; - inany_from_af(low_rtt_dst + hole, AF_INET6, &in6addr_any); + inany_from_af(low_rtt_dst + hole, AF_INET6, NULL); #else (void)conn; (void)tinfo; -- 2.43.0