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 5EB6B5A0278 for ; Sun, 18 Feb 2024 21:59:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708289983; 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=ntmI6kyizQ4DG+NN4dgnVHfy9BW+gb/pF8v0Kf1/ITI=; b=e7Tm+XTpbn8on0lbhKlB3h2ZidvywXdbQdtWVcYpK17BHICEtuw5gg0F9dxO3zeh9Oh3rS oPBQ9MUMI2iEgffwcj+b/KTBHxV9XUcrEryZxcnJ/1k118xNUFS/UZlzn9bx0AhfYxdmhF K37n2Fki7RdO6q0d+Z4TMBo0IMhcbas= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-614-4KgXCGCgOuyaIvNrVAQr5A-1; Sun, 18 Feb 2024 15:59:41 -0500 X-MC-Unique: 4KgXCGCgOuyaIvNrVAQr5A-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a3d24680e06so197258166b.3 for ; Sun, 18 Feb 2024 12:59:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708289979; x=1708894779; 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=ntmI6kyizQ4DG+NN4dgnVHfy9BW+gb/pF8v0Kf1/ITI=; b=txGSgZ1L7kWDj5FNIr2H+lDtY5mjHIffpx3Bl+CIl9SUx+4ktZusKGS3kbzy5bDD4V cZPXlz/i6dLNSOh4xUB6cE+5NKcGPg+4nN9lB8R5sDDtPfSK1cV7pcAsCfbg1p/kgvBa bh0zC3D3T21GRaH3TzjfPuxqZGVJ3m+ZxoouBOEo09cQYL9ySEgFp1bCEBFbfBL6rBYc GlNO8LTzB+9w1i2X9jmlsAy1u8mxAt5QzwCVTlW9KEJDdzO2bzSKEzRkYj6YroqB7Ui9 gfZHoSLi8yOPn34MRa/XGQfNvhjeoCRr0wyrmahK/prP3ODwsjWjzg92ZUncnH18hJrI RfXQ== X-Gm-Message-State: AOJu0Yz1GZpLjyoh3ON8WdiIyo7ce+foqBedKa/UR4YZxbE7HH7FAbyO DgecAgpbh9laOEqgLmiPB+ZbmExFTIAVSLv47fC2PQXFUt9SN8WuuIyuMOG/c+aHcpaYToelGgz xarl07FgtNTocbEZNROzPwkCxPrrM4PR5KQcpvvh+lNxdLIRLyxEwf868pj++ X-Received: by 2002:a17:906:d7bb:b0:a3d:d110:5c47 with SMTP id pk27-20020a170906d7bb00b00a3dd1105c47mr4967322ejb.68.1708289979745; Sun, 18 Feb 2024 12:59:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IGFnex4WU/xkYVotBveJW4C/AZJVCIMI8RrxgmykjsS2zxKR5MnNIZ8ohxFgOlvgoVhUuOgXQ== X-Received: by 2002:a17:906:d7bb:b0:a3d:d110:5c47 with SMTP id pk27-20020a170906d7bb00b00a3dd1105c47mr4967315ejb.68.1708289979411; Sun, 18 Feb 2024 12:59:39 -0800 (PST) Received: from maya.cloud.tilaa.com (maya.cloud.tilaa.com. [164.138.29.33]) by smtp.gmail.com with ESMTPSA id wb14-20020a170907d50e00b00a3d88bdf5aasm2246867ejc.103.2024.02.18.12.59.38 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 18 Feb 2024 12:59:38 -0800 (PST) Date: Sun, 18 Feb 2024 21:58:44 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH v2 02/22] inany: Helper to test for various address types Message-ID: <20240218215844.767562fc@elisabeth> In-Reply-To: <20240206011734.884138-3-david@gibson.dropbear.id.au> References: <20240206011734.884138-1-david@gibson.dropbear.id.au> <20240206011734.884138-3-david@gibson.dropbear.id.au> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.36; 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: RE3FR6GSXBYDA6JBITV4GTMWBDYS4R33 X-Message-ID-Hash: RE3FR6GSXBYDA6JBITV4GTMWBDYS4R33 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 Tue, 6 Feb 2024 12:17:14 +1100 David Gibson wrote: > Add helpers to determine if an inany is loopback, unspecified or multicast, > regardless of whether it's a "true" IPv6 address or an IPv4 address > represented as v4-mapped. > Sometimes we need to know if an inany is a loopback address, unspecified or > some other particular kind of address, but we don't really care if it is > IPv4. > > Use the loopback helper to simplify tcp_splice_conn_from_sock() slightly. > > Signed-off-by: David Gibson > --- > inany.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ > tcp_splice.c | 15 +++------------ > 2 files changed, 53 insertions(+), 12 deletions(-) > > diff --git a/inany.h b/inany.h > index fe652ff7..2058f145 100644 > --- a/inany.h > +++ b/inany.h > @@ -55,6 +55,56 @@ static inline bool inany_equals(const union inany_addr *a, > return IN6_ARE_ADDR_EQUAL(&a->a6, &b->a6); > } > > +/** inany_is_loopback - Check if address is loopback Nit: inany_is_loopback() (and four occurrences below). > + * @a: IPv[46] address > + * > + * Return: true if @a is either ::1 or in 127.0.0.1/8 > + */ > +static inline bool inany_is_loopback(const union inany_addr *a) > +{ > + const struct in_addr *v4 = inany_v4(a); > + > + return IN6_IS_ADDR_LOOPBACK(&a->a6) || (v4 && IN4_IS_ADDR_LOOPBACK(v4)); > +} > + > +/** inany_is_unspecified - Check if address is unspecified > + * @a: IPv[46] address > + * > + * Return: true if @a is either :: or 0.0.0.0 > + */ > +static inline bool inany_is_unspecified(const union inany_addr *a) > +{ > + const struct in_addr *v4 = inany_v4(a); > + > + return IN6_IS_ADDR_UNSPECIFIED(&a->a6) || > + (v4 && IN4_IS_ADDR_UNSPECIFIED(v4)); > +} > + > +/** inany_is_multicast - Check if address is multicast or broadcast > + * @a: IPv[46] address > + * > + * Return: true if @a is IPv6 multicast or IPv4 multicast or broadcast > + */ > +static inline bool inany_is_multicast(const union inany_addr *a) > +{ > + const struct in_addr *v4 = inany_v4(a); > + > + return IN6_IS_ADDR_MULTICAST(&a->a6) || > + (v4 && (IN4_IS_ADDR_MULTICAST(v4) || > + IN4_IS_ADDR_BROADCAST(v4))); > +} > + > +/** inany_is_unicast - Check if address is specified and unicast > + * @a: IPv[46] address > + * > + * Return: true if @a is specified and a unicast address > + */ > +/* cppcheck-suppress unusedFunction */ > +static inline bool inany_is_unicast(const union inany_addr *a) > +{ > + return !inany_is_unspecified(a) && !inany_is_multicast(a); > +} > + > /** inany_from_af - Set IPv[46] address from IPv4 or IPv6 address > * @aa: Pointer to store IPv[46] address > * @af: Address family of @addr > diff --git a/tcp_splice.c b/tcp_splice.c > index cc9745e8..4ecc178b 100644 > --- a/tcp_splice.c > +++ b/tcp_splice.c > @@ -440,29 +440,20 @@ bool tcp_splice_conn_from_sock(const struct ctx *c, > struct tcp_splice_conn *conn, int s, > const struct sockaddr *sa) > { > - const struct in_addr *a4; > union inany_addr aany; > in_port_t port; > > ASSERT(c->mode == MODE_PASTA); > > inany_from_sockaddr(&aany, &port, sa); > - a4 = inany_v4(&aany); > - > - if (a4) { > - if (!IN4_IS_ADDR_LOOPBACK(a4)) > - return false; > - conn->flags = 0; > - } else { > - if (!IN6_IS_ADDR_LOOPBACK(&aany.a6)) > - return false; > - conn->flags = SPLICE_V6; > - } > + if (!inany_is_loopback(&aany)) > + return false; > > if (setsockopt(s, SOL_TCP, TCP_QUICKACK, &((int){ 1 }), sizeof(int))) > flow_trace(conn, "failed to set TCP_QUICKACK on %i", s); > > conn->f.type = FLOW_TCP_SPLICE; > + conn->flags = inany_v4(&aany) ? 0 : SPLICE_V6; > conn->s[0] = s; > > if (tcp_splice_new(c, conn, ref.port, ref.pif))