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 8E2985A027E for ; Thu, 29 Feb 2024 09:43:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1709196173; bh=WskEEpGebW78HFa+FjVA6yFIPynR56r7UguT+5iCvNU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MPIM53t/UvB6DAC3xeu1B0BVAn3VBU5TGWrXQdYIhJHVZC7PmcP70pCAN194hfth7 4u8Cme9vlf/1epGv2oSSuh+E0X6pPTWILRFKgx3Yja7g0pDfgmk7JmeFbZBb0M1TxT 8ANw7Y9/c33K6wtoqZYj6urHoXsEM587vyb1pPUld6QW8SMmTXC4t/+49fYF93pppt BvYsA0FHqvhGqjSll16IgTzJCGAX25FVpQk87ro1ttrnC/D5JLqbDa74q95GC7sViV 7E4nCES87DjLw9lwgX77xsfxoQx4wZM3VWL5Tjik1OnGuXjEexA4xDO/4tvz4RUJWM 6VZD6Ry4ZYWnA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4Tll992MVfz4wyq; Thu, 29 Feb 2024 19:42:53 +1100 (AEDT) From: David Gibson To: Stefano Brivio , Laurent Vivier , passt-dev@passt.top Subject: [PATCH 5/6] udp: Avoid unnecessary pointer in udp_update_hdr4() Date: Thu, 29 Feb 2024 19:42:49 +1100 Message-ID: <20240229084250.3202450-6-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240229084250.3202450-1-david@gibson.dropbear.id.au> References: <20240229084250.3202450-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: 6L5ZNUQC3AT3EEXDB37AIK2SF3G6X3X5 X-Message-ID-Hash: 6L5ZNUQC3AT3EEXDB37AIK2SF3G6X3X5 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 carry around the source address as a pointer to a constant struct in_addr. But it's silly to carry around a 4 or 8 byte pointer to a 4 byte IPv4 address. Just copy the IPv4 address around by value. Signed-off-by: David Gibson --- udp.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/udp.c b/udp.c index 0cca9531..a0080b1a 100644 --- a/udp.c +++ b/udp.c @@ -588,30 +588,30 @@ static size_t udp_update_hdr4(const struct ctx *c, struct udp4_l2_buf_t *b, const struct timespec *now) { size_t ip_len = datalen + sizeof(b->iph) + sizeof(b->uh); - const struct in_addr *src = &b->s_in.sin_addr; in_port_t srcport = ntohs(b->s_in.sin_port); + struct in_addr src = b->s_in.sin_addr; if (!IN4_IS_ADDR_UNSPECIFIED(&c->ip4.dns_match) && - IN4_ARE_ADDR_EQUAL(src, &c->ip4.dns_host) && srcport == 53) { - src = &c->ip4.dns_match; - } else if (IN4_IS_ADDR_LOOPBACK(src) || - IN4_ARE_ADDR_EQUAL(src, &c->ip4.addr_seen)) { + IN4_ARE_ADDR_EQUAL(&src, &c->ip4.dns_host) && srcport == 53) { + src = c->ip4.dns_match; + } else if (IN4_IS_ADDR_LOOPBACK(&src) || + IN4_ARE_ADDR_EQUAL(&src, &c->ip4.addr_seen)) { udp_tap_map[V4][srcport].ts = now->tv_sec; udp_tap_map[V4][srcport].flags |= PORT_LOCAL; - if (IN4_IS_ADDR_LOOPBACK(src)) + if (IN4_IS_ADDR_LOOPBACK(&src)) udp_tap_map[V4][srcport].flags |= PORT_LOOPBACK; else udp_tap_map[V4][srcport].flags &= ~PORT_LOOPBACK; bitmap_set(udp_act[V4][UDP_ACT_TAP], srcport); - src = &c->ip4.gw; + src = c->ip4.gw; } b->iph.tot_len = htons(ip_len); b->iph.daddr = c->ip4.addr_seen.s_addr; - b->iph.saddr = src->s_addr; + b->iph.saddr = src.s_addr; udp_update_check4(b); b->uh.source = htons(srcport); b->uh.dest = htons(dstport); -- 2.44.0