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 2A9AE5A0274 for ; Fri, 4 Nov 2022 04:10:47 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4N3QcG6twKz4xwt; Fri, 4 Nov 2022 14:10:38 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1667531438; bh=wiH7MLy7otb2RNo/ZsYvbNBrViFFejtFsS7yImKvOnw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KXd5DgZA9DsBVnCMnTUwW6pBqVsf2qBvwZ8MwNH02GAcJ0UIsueAIjh230ClgSOkA FuO88LXpUpokqsaqqhGDxW7+hokW/YYKwNVdcPvXtHmH36umFdJO+ZpoFDaPi4sfdQ tA4t/QgLLGMluqf0BksgY7McXV+9UpGTxS0wno7g= From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH v2 5/6] Use endian-safer typing in struct tap4_l4_t Date: Fri, 4 Nov 2022 14:10:36 +1100 Message-Id: <20221104031037.3866034-6-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221104031037.3866034-1-david@gibson.dropbear.id.au> References: <20221104031037.3866034-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: HYLZSZP4WT335N4URJR6SAK7K3Y5KYSP X-Message-ID-Hash: HYLZSZP4WT335N4URJR6SAK7K3Y5KYSP 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.3 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 recently converted to using struct in_addr rather than bare in_addr_t or uint32_t to represent IPv4 addresses in network order. This makes it harder forget to apply the correct endian conversions. We omitted the IPv4 addresses stored in struct tap4_l4_t, however. Convert those as well. Signed-off-by: David Gibson --- tap.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/tap.c b/tap.c index bb57568..e9cfab2 100644 --- a/tap.c +++ b/tap.c @@ -320,8 +320,8 @@ static struct tap4_l4_t { uint16_t source; uint16_t dest; - uint32_t saddr; - uint32_t daddr; + struct in_addr saddr; + struct in_addr daddr; struct pool_l4_t p; } tap4_l4[TAP_SEQS /* Arbitrary: TAP_MSGS in theory, so limit in users */]; @@ -367,14 +367,15 @@ static void tap_packet_debug(const struct iphdr *iph, uint8_t proto = 0; if (iph || seq4) { - inet_ntop(AF_INET, iph ? &iph->saddr : &seq4->saddr, - buf4s, sizeof(buf4s)); - inet_ntop(AF_INET, iph ? &iph->daddr : &seq4->daddr, - buf4d, sizeof(buf4d)); - if (iph) + if (iph) { + inet_ntop(AF_INET, &iph->saddr, buf4s, sizeof(buf4s)); + inet_ntop(AF_INET, &iph->daddr, buf4d, sizeof(buf4d)); proto = iph->protocol; - else if (seq4) + } else { + inet_ntop(AF_INET, &seq4->saddr, buf4s, sizeof(buf4s)); + inet_ntop(AF_INET, &seq4->daddr, buf4d, sizeof(buf4d)); proto = seq4->protocol; + } } else { inet_ntop(AF_INET6, ip6h ? &ip6h->saddr : &seq6->saddr, buf6s, sizeof(buf6s)); @@ -489,15 +490,15 @@ resume: #define L4_MATCH(iph, uh, seq) \ (seq->protocol == iph->protocol && \ seq->source == uh->source && seq->dest == uh->dest && \ - seq->saddr == iph->saddr && seq->daddr == iph->daddr) + seq->saddr.s_addr == iph->saddr && seq->daddr.s_addr == iph->daddr) #define L4_SET(iph, uh, seq) \ do { \ - seq->protocol = iph->protocol; \ - seq->source = uh->source; \ - seq->dest = uh->dest; \ - seq->saddr = iph->saddr; \ - seq->daddr = iph->daddr; \ + seq->protocol = iph->protocol; \ + seq->source = uh->source; \ + seq->dest = uh->dest; \ + seq->saddr.s_addr = iph->saddr; \ + seq->daddr.s_addr = iph->daddr; \ } while (0) if (seq && L4_MATCH(iph, uh, seq) && seq->p.count < TAP_SEQS) @@ -529,7 +530,7 @@ append: for (j = 0, seq = tap4_l4; j < seq_count; j++, seq++) { struct pool *p = (struct pool *)&seq->p; - uint32_t *da = &seq->daddr; + struct in_addr *da = &seq->daddr; size_t n = p->count; tap_packet_debug(NULL, NULL, seq, 0, NULL, n); -- 2.38.1