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.129.124]) by passt.top (Postfix) with ESMTP id 0731B5A026D for ; Thu, 3 Aug 2023 00:50:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691016602; 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=BOFChRnoMW/Y45oNLSvDk2QRcK6HPpNxVG6iqn3Ijf0=; b=LeTXzq+4+9/l/Rf6biacviMAJrs6OxFMtX4Smber+HBRXvMXtmjiEyuOmZEejff1G0a2fJ 6tMzYGxxISa8jf33JuKBHj8uP29VPFVBOlxg1n2aV3odp9I2NXArKRvWsyHNy9eOgBGmwW /nHf84jsK8f8s2VP0pjJWj985AzOgzw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-617-qv1-q-cFM1q0sX-qrOcHnA-1; Wed, 02 Aug 2023 18:48:23 -0400 X-MC-Unique: qv1-q-cFM1q0sX-qrOcHnA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D0428858F1E; Wed, 2 Aug 2023 22:48:22 +0000 (UTC) Received: from elisabeth (unknown [10.39.208.24]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2CDC640C2063; Wed, 2 Aug 2023 22:48:22 +0000 (UTC) Date: Thu, 3 Aug 2023 00:48:20 +0200 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 17/17] netlink: Propagate errors for "dup" operations Message-ID: <20230803004820.7b7967ac@elisabeth> In-Reply-To: <20230724060936.952659-18-david@gibson.dropbear.id.au> References: <20230724060936.952659-1-david@gibson.dropbear.id.au> <20230724060936.952659-18-david@gibson.dropbear.id.au> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: PN5XQWZFR7QIJ42KQ3GGQAORVNUZMMO4 X-Message-ID-Hash: PN5XQWZFR7QIJ42KQ3GGQAORVNUZMMO4 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 Mon, 24 Jul 2023 16:09:36 +1000 David Gibson wrote: > We now detect errors on netlink "set" operations while configuring the > pasta namespace with --config-net. However in many cases rather than > a simple "set" we use a more complex "dup" function to copy > configuration from the host to the namespace. We're not yet properly > detecting and reporting netlink errors for that case. > > Change the "dup" operations to propagate netlink errors to their > caller, pasta_ns_conf() and report them there. > > Link: https://bugs.passt.top/show_bug.cgi?id=60 > > Signed-off-by: David Gibson > --- > netlink.c | 40 ++++++++++++++++++++++++++++------------ > netlink.h | 8 ++++---- > pasta.c | 15 ++++++++------- > 3 files changed, 40 insertions(+), 23 deletions(-) > > diff --git a/netlink.c b/netlink.c > index 9e72b16..cdc18c0 100644 > --- a/netlink.c > +++ b/netlink.c > @@ -413,9 +413,11 @@ int nl_route_set_def(int s, unsigned int ifi, sa_family_t af, void *gw) > * @s_dst: Netlink socket in destination namespace > * @ifi_dst: Interface index in destination namespace > * @af: Address family > + * > + * Return: 0 on success, negative error code on failure > */ > -void nl_route_dup(int s_src, unsigned int ifi_src, > - int s_dst, unsigned int ifi_dst, sa_family_t af) > +int nl_route_dup(int s_src, unsigned int ifi_src, > + int s_dst, unsigned int ifi_dst, sa_family_t af) > { > struct req_t { > struct nlmsghdr nlh; > @@ -477,9 +479,11 @@ void nl_route_dup(int s_src, unsigned int ifi_src, > > if (extra) { > err("netlink: Too many routes to duplicate"); > - return; > + return -E2BIG; This is "Argument list too long", and... I don't have much better ideas. I would instinctively use ENOSPC or ENOMEM in this case, but both are slightly misleading in different ways, too. > } > } > + if (status < 0) > + return status; > > /* Routes might have dependencies between each other, and the > * kernel processes RTM_NEWROUTE messages sequentially. For n > @@ -494,15 +498,20 @@ void nl_route_dup(int s_src, unsigned int ifi_src, > NLMSG_OK(nh, status); > nh = NLMSG_NEXT(nh, status)) { > uint16_t flags = nh->nlmsg_flags; > + int rc; > > if (nh->nlmsg_type != RTM_NEWROUTE) > continue; > > - nl_do(s_dst, nh, RTM_NEWROUTE, > - (flags & ~NLM_F_DUMP_FILTERED) | NLM_F_CREATE, > - nh->nlmsg_len); > + rc = nl_do(s_dst, nh, RTM_NEWROUTE, > + (flags & ~NLM_F_DUMP_FILTERED) | NLM_F_CREATE, > + nh->nlmsg_len); > + if (rc < 0 && rc != -ENETUNREACH && rc != -EEXIST) > + return rc; > } > } > + > + return 0; > } > > /** > @@ -635,9 +644,11 @@ int nl_addr_set(int s, unsigned int ifi, sa_family_t af, > * @s_dst: Netlink socket in destination network namespace > * @ifi_dst: Interface index in destination namespace > * @af: Address family > + * > + * Return: 0 on success, negative error code on failure > */ > -void nl_addr_dup(int s_src, unsigned int ifi_src, > - int s_dst, unsigned int ifi_dst, sa_family_t af) > +int nl_addr_dup(int s_src, unsigned int ifi_src, > + int s_dst, unsigned int ifi_dst, sa_family_t af) > { > struct req_t { > struct nlmsghdr nlh; > @@ -651,6 +662,7 @@ void nl_addr_dup(int s_src, unsigned int ifi_src, > struct nlmsghdr *nh; > ssize_t status; > uint16_t seq; > + int rc= 0; Missing whitespace. -- Stefano