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 2384E5A0269 for ; Tue, 18 Oct 2022 10:40:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666082408; 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=rUJtPpv86WLDYgx4wQ8bb5o5jyYAdQHwul/bEAbTFws=; b=hUpSFCUiK7aOiuYlaQJ9oMZ6DlmGlue0Qbc5ALtDFEpuvgUT+6vt/l1tPxlg0Rs3uxiWdB mk3Xg+x2Nk7PKOwFeALc1/B/X2UZvhhBWExGdeIqQgIJcif2Q51jM82zP4UeTHZT/9D/F5 w1QPUkmxilXw0NP8OxulJLAViZNQRCY= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-156-jZ6CTOqjNuOuc6sX3njp4g-1; Tue, 18 Oct 2022 04:40:06 -0400 X-MC-Unique: jZ6CTOqjNuOuc6sX3njp4g-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4956E1C087AA; Tue, 18 Oct 2022 08:40:06 +0000 (UTC) Received: from maya.cloud.tilaa.com (ovpn-208-31.brq.redhat.com [10.40.208.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 20973C15BA4; Tue, 18 Oct 2022 08:40:06 +0000 (UTC) Date: Tue, 18 Oct 2022 05:04:41 +0200 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 06/14] Add helpers for normal inbound packet destination addresses Message-ID: <20221018050441.0d92c3d7@elisabeth> In-Reply-To: <20221017085807.473470-7-david@gibson.dropbear.id.au> References: <20221017085807.473470-1-david@gibson.dropbear.id.au> <20221017085807.473470-7-david@gibson.dropbear.id.au> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: 5GYCH3O2K63CLROK26V3K6FJSGGHIAZJ X-Message-ID-Hash: 5GYCH3O2K63CLROK26V3K6FJSGGHIAZJ 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.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: On Mon, 17 Oct 2022 19:57:59 +1100 David Gibson wrote: > tap_ip_send() doesn't take a destination address, because it's specifically > for inbound packets, and the IP addresses of the guest/namespace are > already known to us. Rather than open-coding this destination address > logic, make helper functions for it which will enable some later cleanups. > > Signed-off-by: David Gibson > --- > tap.c | 29 ++++++++++++++++++++++++----- > tap.h | 3 +++ > 2 files changed, 27 insertions(+), 5 deletions(-) > > diff --git a/tap.c b/tap.c > index de02c56..41e8ff2 100644 > --- a/tap.c > +++ b/tap.c > @@ -96,6 +96,28 @@ int tap_send(const struct ctx *c, const void *data, size_t len, int vnet_pre) > return write(c->fd_tap, (char *)data + (vnet_pre ? 4 : 0), len); > } > > +/** > + * tap_ip4_daddr() - Normal IPv4 destination address for inbound packets > + * @c: Execution context Given that the address is returned in network order, I think this would be relevant here: * Return: IPv4 address, network order > + */ > +in_addr_t tap_ip4_daddr(const struct ctx *c) > +{ > + return c->ip4.addr_seen; > +} > + > +/** > + * tap_ip6_daddr() - Normal IPv4 destination address for inbound packets > + * @c: Execution context > + * @src: Source address * Return: pointer to IPv6 address > + */ > +const struct in6_addr *tap_ip6_daddr(const struct ctx *c, > + const struct in6_addr *src) > +{ > + if (IN6_IS_ADDR_LINKLOCAL(src)) > + return &c->ip6.addr_ll_seen; > + return &c->ip6.addr_seen; > +} > + > /** > * tap_ip_send() - Send IP packet, with L2 headers, calculating L3/L4 checksums > * @c: Execution context > @@ -132,7 +154,7 @@ void tap_ip_send(const struct ctx *c, const struct in6_addr *src, uint8_t proto, > iph->frag_off = 0; > iph->ttl = 255; > iph->protocol = proto; > - iph->daddr = c->ip4.addr_seen; > + iph->daddr = tap_ip4_daddr(c); > memcpy(&iph->saddr, &src->s6_addr[12], 4); > > csum_ip4_header(iph); > @@ -163,10 +185,7 @@ void tap_ip_send(const struct ctx *c, const struct in6_addr *src, uint8_t proto, > ip6h->priority = 0; > > ip6h->saddr = *src; > - if (IN6_IS_ADDR_LINKLOCAL(src)) > - ip6h->daddr = c->ip6.addr_ll_seen; > - else > - ip6h->daddr = c->ip6.addr_seen; > + ip6h->daddr = *tap_ip6_daddr(c, src); > > memcpy(data, in, len); > > diff --git a/tap.h b/tap.h > index df3aec0..a6764b4 100644 > --- a/tap.h > +++ b/tap.h > @@ -6,6 +6,9 @@ > #ifndef TAP_H > #define TAP_H > > +in_addr_t tap_ip4_daddr(const struct ctx *c); > +const struct in6_addr *tap_ip6_daddr(const struct ctx *c, > + const struct in6_addr *src); > void tap_ip_send(const struct ctx *c, const struct in6_addr *src, uint8_t proto, > const char *in, size_t len, uint32_t flow); > int tap_send(const struct ctx *c, const void *data, size_t len, int vnet_pre); -- Stefano