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 260015A027B for ; Thu, 3 Aug 2023 04:27:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1691029621; bh=uJVM3y9g8SUV4rE0uiFoDhnrfNid7wOITGtucyO9To0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=D2tIQ5h2I7d8XTDgVj851spUwNSS4+6LbBwnv347IRrJ+5WP1CyezSjVbue+SrhNT P9CjXej9ocBSmvJt05YOveMr2++dNhkqOaCPIviyZBFwyNmbbAXGJju44ZDKa0zp7F G16hzkV408lDWI+dj+fIWbFpR5TlXFKTBz8/I6q4= Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4RGXmP4lgcz4wxm; Thu, 3 Aug 2023 12:27:01 +1000 (AEST) Date: Thu, 3 Aug 2023 12:19:51 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 08/17] netlink: Treat send() or recv() errors as fatal Message-ID: References: <20230724060936.952659-1-david@gibson.dropbear.id.au> <20230724060936.952659-9-david@gibson.dropbear.id.au> <20230803004759.099a99a7@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="JEEWRsFLZdkIRRtf" Content-Disposition: inline In-Reply-To: <20230803004759.099a99a7@elisabeth> Message-ID-Hash: HFWBVWMMFUYIECEPGDQERQYAAQENRDWL X-Message-ID-Hash: HFWBVWMMFUYIECEPGDQERQYAAQENRDWL 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: 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: --JEEWRsFLZdkIRRtf Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Aug 03, 2023 at 12:47:59AM +0200, Stefano Brivio wrote: > On Mon, 24 Jul 2023 16:09:27 +1000 > David Gibson wrote: >=20 > > Errors on send() or recv() calls on a netlink socket don't indicate err= ors > > with the netlink operations we're attempting, but rather that something= 's > > gone wrong with the mechanics of netlink itself. We don't really expect > > this to ever happen, and if it does, it's not clear what we could to to > > recover. > >=20 > > So, treat errors from these calls as fatal, rather than returning the e= rror > > up the stack. This makes handling failures in the callers of nl_req() > > simpler. > >=20 > > Signed-off-by: David Gibson > > --- > > netlink.c | 36 +++++++++++++++++------------------- > > 1 file changed, 17 insertions(+), 19 deletions(-) > >=20 > > diff --git a/netlink.c b/netlink.c > > index 3620fd6..826c926 100644 > > --- a/netlink.c > > +++ b/netlink.c > > @@ -103,9 +103,9 @@ fail: > > * @req: Request with netlink header > > * @len: Request length > > * > > - * Return: received length on success, negative error code on failure > > + * Return: received length on success, terminates on error > > */ > > -static int nl_req(int s, char *buf, const void *req, ssize_t len) > > +static ssize_t nl_req(int s, char *buf, const void *req, ssize_t len) > > { > > char flush[NLBUFSIZ]; > > int done =3D 0; > > @@ -124,11 +124,17 @@ static int nl_req(int s, char *buf, const void *r= eq, ssize_t len) > > } > > } > > =20 > > - if ((send(s, req, len, 0) < len) || > > - (len =3D recv(s, buf, NLBUFSIZ, 0)) < 0) > > - return -errno; > > + n =3D send(s, req, len, 0); > > + if (n < 0) > > + die("netlink: Failed to send(): %s", strerror(errno)); > > + else if (n < len) > > + die("netlink: Short send"); >=20 > If you respin, probably worth doing: >=20 > die("netlink: Short send (%li out of %li bytes)", n, len); Done. --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --JEEWRsFLZdkIRRtf Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmTLDsEACgkQzQJF27ox 2GetcA//ZUVSDmAMKvaixBHC1geAiSkxKNFZgIcS8PcVbK/gIOeHbwnbbNUHLwvP 0IlBGq6zAEwbh/snAhFqRkiqeRoh5refaP7WOmL7bZEWquWGPFUYBjCFIJRHUoHT 3hQkgrm28T4OxwcOfu4fyFitmRfZ1n1z2ww6voHjbFstVqYlrj4xgCzECCZeIfEZ hN4hsSmHdAHJV91T6XmWmtU2gmnSZEbGUh5HCU3WTMEjCc4PBuzjzT4AXQb+kcAx xF0/T7zsVf7Wqt7aHzlTByY2ghln3tfVNdIdi18OyttO/qUqaLzUJES1SRYWanOP /WrERo/O74LvWFM7Tgv5/oj6lBhK1jEUVZuvfD9AgJY77HZwIDHZnvcQzmNlfiXP t/mP3My6SQc7BLmefHhklbOIWSFi19dtuyMAEpXWKuNebUVaxJRDPlZ9driNMJ9V TDCI5wQxMaLYzmH9qyjNVe/E2ZK/rxBKs18tT+BmdSbCyCD30zlnwdrFGh162z77 70IHz5nItKBkxQKPXaLYavAiTNJxRmvwJNuAD1kNJpDxeT65tbNlTovLf0+if6um A/J4/ZRHvPYzPrXIFSSjpBgjMrKddIRaEI1saCnpwPXruQo2jMhJvkIDZbf9PpPH bThBXtqRlf3NtiZ6Rexjz0rHNVtKJBAeNku54d+D4QnkjFZvrQI= =Xmk4 -----END PGP SIGNATURE----- --JEEWRsFLZdkIRRtf--