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 CEE905A027F for ; Wed, 17 May 2023 07:05:34 +0200 (CEST) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4QLgzH2NMpz4x4F; Wed, 17 May 2023 15:05:31 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1684299931; bh=f2lLAm/7PzzY+xONuQawHsB4g5RSgIiGGsLDQR8zzjs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iFNRJ5/VaMzjrexfmg646xPr1AZsz1QTHU/JVOH4U6YINk6TP3q8NhPI94zmjGTx2 O7KOmdvppU/mKapi2kIAtnciedNTHT9OFbITuQKBKyvvwR0KtZrlNR7Oxw9W9gXGhp ZbiRM+eyqkhZ6+9qQVIgcTQ2u6d+XlaP/pppkILY= From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH 2/5] udp: Small streamline to udp_update_hdr4() Date: Wed, 17 May 2023 15:05:26 +1000 Message-Id: <20230517050529.3505590-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230517050529.3505590-1-david@gibson.dropbear.id.au> References: <20230517050529.3505590-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: YH2RN7U2YUXCC6XSAZYW56JT6V5QYNRI X-Message-ID-Hash: YH2RN7U2YUXCC6XSAZYW56JT6V5QYNRI 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: Streamline the logic here slightly, by introducing a 'src' temporary for brevity. We also transform the logic for setting/clearing PORT_LOOPBACK. This makes udp_update_hdr4() more closely match the corresponding logic from udp_update_udp6(). Signed-off-by: David Gibson --- udp.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/udp.c b/udp.c index 78cb221..d7e1020 100644 --- a/udp.c +++ b/udp.c @@ -581,6 +581,7 @@ static size_t udp_update_hdr4(const struct ctx *c, int n, in_port_t dstport, const struct timespec *now) { struct udp4_l2_buf_t *b = &udp4_l2_buf[n]; + struct in_addr *src; in_port_t src_port; size_t ip_len; @@ -588,26 +589,26 @@ static size_t udp_update_hdr4(const struct ctx *c, int n, in_port_t dstport, b->iph.tot_len = htons(ip_len); + src = &b->s_in.sin_addr; src_port = ntohs(b->s_in.sin_port); if (!IN4_IS_ADDR_UNSPECIFIED(&c->ip4.dns_match) && - IN4_ARE_ADDR_EQUAL(&b->s_in.sin_addr, &c->ip4.dns_host) && - src_port == 53) { + IN4_ARE_ADDR_EQUAL(src, &c->ip4.dns_host) && src_port == 53) { b->iph.saddr = c->ip4.dns_match.s_addr; - } else if (IN4_IS_ADDR_LOOPBACK(&b->s_in.sin_addr) || - IN4_ARE_ADDR_EQUAL(&b->s_in.sin_addr, &c->ip4.addr_seen)) { + } else if (IN4_IS_ADDR_LOOPBACK(src) || + IN4_ARE_ADDR_EQUAL(src, &c->ip4.addr_seen)) { b->iph.saddr = c->ip4.gw.s_addr; udp_tap_map[V4][src_port].ts = now->tv_sec; udp_tap_map[V4][src_port].flags |= PORT_LOCAL; - if (IN4_ARE_ADDR_EQUAL(&b->s_in.sin_addr.s_addr, &c->ip4.addr_seen)) - udp_tap_map[V4][src_port].flags &= ~PORT_LOOPBACK; - else + if (IN4_IS_ADDR_LOOPBACK(src)) udp_tap_map[V4][src_port].flags |= PORT_LOOPBACK; + else + udp_tap_map[V4][src_port].flags &= ~PORT_LOOPBACK; bitmap_set(udp_act[V4][UDP_ACT_TAP], src_port); } else { - b->iph.saddr = b->s_in.sin_addr.s_addr; + b->iph.saddr = src->s_addr; } udp_update_check4(b); -- 2.40.1