From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id 349945A004F for ; Wed, 24 Jul 2024 08:39:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721803177; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2z0zk4AquAs74I8xmnlCfW/9SteDyaSXabtijqwA6L8=; b=MwJTZ8EFM2ldA8Coqe7Us0r8Dywa/ZwMYL7wmJJFof7yow/KSr5AMymsnHH6w/TV8v/WN2 RiTWcaxR/Cik+t7sx3ap4JZxNtINlvglgi0+hxuDEqKgNELOVsvzx1yGA1tejyVEkJU2z3 AKhrh8nIwrNHSmE3fMqpu+B4MVFCr/o= Received: from mail-yw1-f197.google.com (mail-yw1-f197.google.com [209.85.128.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-448-_i2X1UCaOk63Gq_brP5zMw-1; Wed, 24 Jul 2024 02:39:36 -0400 X-MC-Unique: _i2X1UCaOk63Gq_brP5zMw-1 Received: by mail-yw1-f197.google.com with SMTP id 00721157ae682-664ccf0659cso180759097b3.1 for ; Tue, 23 Jul 2024 23:39:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721803175; x=1722407975; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=2z0zk4AquAs74I8xmnlCfW/9SteDyaSXabtijqwA6L8=; b=A+SAegaxfBipThRL1JzxO5CAWScuQixdxw5RhQF9EDuQzBEN5l7kjUxPrxTLKGC02U hg0Qln6z+QacojMv4Ydp5tcuUBfO3ydii5rz3at3IEsFX3ymuFQg37umsmCZe8CnhOZ+ +R4e5HKPy2qpW6qHflDawQnUzFQMF1RUHVkJ+YwMVfiuYxUwXElreGqsU4lQm26/DqBS OnctM/hhSvbz+jZvpxtHICpaNuOEmuj2XcrTDEBY67OPdYgAl8djTyGIKKdDHMTpRqE4 Y0leyLYkSGvuZ3fzXC/H6pRw/Sbau8z9+iAxd/R9psnEXtRy1c/Sb2vVsAH1SHxvI9VF Zbbw== X-Gm-Message-State: AOJu0YywquBK5jYYx03dZfiMOE6EPeJGKeyK49DVVe4vaOzkEmeKsOXM XFL+4q3TuOf0ZmRT0iaBKakNKteN9KNG7S8wd5JSAk0V3Mhr2VJCMP8JZRuQPxLUJ2UZaKSgJjn Q4JtA+vz0TWWH72caShLV89iuD2bHzhjTlbfike2TxNE47f7GyY9HCYPmskQx X-Received: by 2002:a05:690c:a88:b0:64a:5493:e0bd with SMTP id 00721157ae682-66a6ab013f2mr164245597b3.40.1721803174995; Tue, 23 Jul 2024 23:39:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG4q5vmKxWnMTZHExJ94FLlDGLG7SmchU6Z/gVrEBy4ZTnZObG35bIEvJbsri54sePXoHR0cg== X-Received: by 2002:a05:690c:a88:b0:64a:5493:e0bd with SMTP id 00721157ae682-66a6ab013f2mr164245487b3.40.1721803174630; Tue, 23 Jul 2024 23:39:34 -0700 (PDT) Received: from maya.cloud.tilaa.com (maya.cloud.tilaa.com. [164.138.29.33]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b96740cbdasm38040606d6.109.2024.07.23.23.39.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Jul 2024 23:39:34 -0700 (PDT) Date: Wed, 24 Jul 2024 08:38:59 +0200 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 1/2] fwd: Refactor tests in fwd_nat_from_tap() for clarity Message-ID: <20240724083859.2a97e66c@elisabeth> In-Reply-To: <20240724062058.1259033-2-david@gibson.dropbear.id.au> References: <20240724062058.1259033-1-david@gibson.dropbear.id.au> <20240724062058.1259033-2-david@gibson.dropbear.id.au> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: 53R4NUPBD37233V7FDDKMOEKLJ2ZIRID X-Message-ID-Hash: 53R4NUPBD37233V7FDDKMOEKLJ2ZIRID X-MailFrom: sbrivio@redhat.com 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: passt-dev@passt.top 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: On Wed, 24 Jul 2024 16:20:57 +1000 David Gibson wrote: > Currently, we start by handling the common case, where we don't translate > the destination address, then we modify the tgt side for the special cases. > In the process we do comparisons on the tentatively set fields in tgt, > which obscures the fact that tgt should be an essentially pure function of > ini, and risks people examining fields of tgt that are not yet initialized. > > To make this clearer, do all our tests on 'ini', constructing tgt from > scratch on that basis. > > Signed-off-by: David Gibson > --- > fwd.c | 22 +++++++++++----------- > 1 file changed, 11 insertions(+), 11 deletions(-) > > diff --git a/fwd.c b/fwd.c > index 8c1f3d91..bd16ac42 100644 > --- a/fwd.c > +++ b/fwd.c > @@ -169,22 +169,22 @@ void fwd_scan_ports_init(struct ctx *c) > uint8_t fwd_nat_from_tap(const struct ctx *c, uint8_t proto, > const struct flowside *ini, struct flowside *tgt) > { > - tgt->eaddr = ini->faddr; > - tgt->eport = ini->fport; > - > - if (proto == IPPROTO_UDP && tgt->eport == 53 && > - inany_equals4(&tgt->eaddr, &c->ip4.dns_match)) { These blocks are all one-liners now and curly brackets could go away, I guess? > + if (proto == IPPROTO_UDP && ini->fport == 53 && > + inany_equals4(&ini->faddr, &c->ip4.dns_match)) { > tgt->eaddr = inany_from_v4(c->ip4.dns_host); > - } else if (proto == IPPROTO_UDP && tgt->eport == 53 && > - inany_equals6(&tgt->eaddr, &c->ip6.dns_match)) { > + } else if (proto == IPPROTO_UDP && ini->fport == 53 && > + inany_equals6(&ini->faddr, &c->ip6.dns_match)) { > tgt->eaddr.a6 = c->ip6.dns_host; > - } else if (!c->no_map_gw) { > - if (inany_equals4(&tgt->eaddr, &c->ip4.gw)) > - tgt->eaddr = inany_loopback4; > - else if (inany_equals6(&tgt->eaddr, &c->ip6.gw)) > + } else if (!c->no_map_gw && inany_equals4(&ini->faddr, &c->ip4.gw)) { > + tgt->eaddr = inany_loopback4; > + } else if (!c->no_map_gw && inany_equals6(&ini->faddr, &c->ip6.gw)) { > tgt->eaddr = inany_loopback6; Resulting excess tab here. > + } else { > + tgt->eaddr = ini->faddr; > } > > + tgt->eport = ini->fport; > + > /* The relevant addr_out controls the host side source address. This > * may be unspecified, which allows the kernel to pick an address. > */ -- Stefano