From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id BB5715A027B for ; Thu, 7 Dec 2023 15:31:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1701959502; bh=pS59YzDbPtu34nvUN370J8+CPpiO5l9kgMGBns6sDSM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qjKeathMZKwZzJeqDT6XQA1dJXQrs2ourtZqtFwfiRiWXRX3UrhbuorHEmLFz7AEz yoTaTPDklws5XkHzUNmk+YiakSB00mObpliPoe3T8uJigGMn/K5zrj3Cu+1C1bPa5f vzgH8tpaGmIzMPQYZpX7TVm0uEfElyDIjDHLDIfY8thVpsoLW8CL0nPNxMmf02Efcm 0xiGJwSmW0zYXSK0GmMiqVgYvlOYe2cm3lwBm7lkhSx9eGIX5sNPlEU4ZHIuQEFmEP xrcpB0YU+K1q5TyB/VGDpK0zGZDfSAzkkzXjr2cFy4Va7tpAY2LSeNYu1MUl2jM+0y nyFe08FBU5VlA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4SmGtQ1xhxz4xPY; Fri, 8 Dec 2023 01:31:42 +1100 (AEDT) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH 6/8] icmp: Avoid unnecessary handling of unspecified bind address Date: Fri, 8 Dec 2023 01:31:38 +1100 Message-ID: <20231207143140.1851378-7-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231207143140.1851378-1-david@gibson.dropbear.id.au> References: <20231207143140.1851378-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: RVHEWABMFQZZMS6EZOKLDJUPMGA5ZVZ6 X-Message-ID-Hash: RVHEWABMFQZZMS6EZOKLDJUPMGA5ZVZ6 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: We go to some trouble, if the configured output address is unspecified, to pass NULL to sock_l4(). But while passing NULL is one way to get sock_l4() not to specify a bind address, passing the "any" address explicitly works too. Use this to simplify icmp_tap_handler(). Signed-off-by: David Gibson --- icmp.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/icmp.c b/icmp.c index 2a15d25..d982fda 100644 --- a/icmp.c +++ b/icmp.c @@ -187,16 +187,12 @@ int icmp_tap_handler(const struct ctx *c, uint8_t pif, int af, iref.id = id = ntohs(ih->un.echo.id); if ((s = icmp_id_map[V4][id].sock) <= 0) { - const struct in_addr *bind_addr = NULL; const char *bind_if; bind_if = *c->ip4.ifname_out ? c->ip4.ifname_out : NULL; - if (!IN4_IS_ADDR_UNSPECIFIED(&c->ip4.addr_out)) - bind_addr = &c->ip4.addr_out; - - s = sock_l4(c, AF_INET, IPPROTO_ICMP, bind_addr, - bind_if, id, iref.u32); + s = sock_l4(c, AF_INET, IPPROTO_ICMP, + &c->ip4.addr_out, bind_if, id, iref.u32); if (s < 0) goto fail_sock; if (s > FD_REF_MAX) { @@ -241,16 +237,12 @@ int icmp_tap_handler(const struct ctx *c, uint8_t pif, int af, iref.id = id = ntohs(ih->icmp6_identifier); if ((s = icmp_id_map[V6][id].sock) <= 0) { - const struct in6_addr *bind_addr = NULL; const char *bind_if; bind_if = *c->ip6.ifname_out ? c->ip6.ifname_out : NULL; - if (!IN6_IS_ADDR_UNSPECIFIED(&c->ip6.addr_out)) - bind_addr = &c->ip6.addr_out; - - s = sock_l4(c, AF_INET6, IPPROTO_ICMPV6, bind_addr, - bind_if, id, iref.u32); + s = sock_l4(c, AF_INET6, IPPROTO_ICMPV6, + &c->ip6.addr_out, bind_if, id, iref.u32); if (s < 0) goto fail_sock; if (s > FD_REF_MAX) { -- 2.43.0