From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=LZnjl+nL; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id 92E735A0271 for ; Sun, 11 Jan 2026 00:33:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768088024; 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=DEnKECB7rNlB8Nh0agmen7141l0YmnHiLYiIn2C02iw=; b=LZnjl+nL99CykqFyc4xzrGgTbYSKjFj/C5wSRpln3cBMpS8TKvFIoDu2LmBlKuT5lxLTco MC/jdGoYbYbjAnVYm423aTGFhl4aMWwPXwEvWQJjdlD5kbHmaP0KGd+i7PeNklTOuYevvV mcjrGUaTlA772tT/3BM9m2ZDmcJq5MA= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-211-HOlhJ45NONiBxZQFEyD5eQ-1; Sat, 10 Jan 2026 18:33:43 -0500 X-MC-Unique: HOlhJ45NONiBxZQFEyD5eQ-1 X-Mimecast-MFC-AGG-ID: HOlhJ45NONiBxZQFEyD5eQ_1768088022 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-4325aa61c6bso3286368f8f.0 for ; Sat, 10 Jan 2026 15:33:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768088021; x=1768692821; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DEnKECB7rNlB8Nh0agmen7141l0YmnHiLYiIn2C02iw=; b=FoC+NN59Mu9fOrnOI1zGQduNDfQs6wYTQO12XSoPBu9V/+52OhsKJmqtZEhiYnNeBo 0nDmSUAEH+PKQNhEwPc9VmuvqJDReVDL44LkLxaHkWfkVNRoDtLnCb+FIELF2oLK5S64 N6gj51NWXoPFpgr2KoZ+ddMkUGLYWPFJfAfM8s0+se0ONQ/7e0CRz7YbsnfinztUb5AE eVwsBlmQkfC23s/QwR2Y4Sh3jWGbv6U2LA0Hdh7SxYZBmElpi/P7au3uC2IcLCa6WmLp E/zdVbcxPvO0RE08draSdewnMxsOMaNCClcrdl7dE+3WSO+W6uJ6KO7flY4F1PYvnrn9 Q50A== X-Gm-Message-State: AOJu0YxinUIk96Eoy54fvG8PK/AQar+p4xk2gRULUWHN9E6YQIXduEq4 lHb8EcMoQ1t/+9sKXDoI/EeojeFoACsF5CCBfBnSQHpHZQ/cmHLTLT32nEq2Dgc17bo4+MuTfNV fG6/BT9rcAAYraLhFer4tcmYyuuSRBzDWCTy8M+j8HDEOHwXnLjvIFn5/+D3QiA== X-Gm-Gg: AY/fxX7IeJClLFYipez/0nAJjwZu+uB6SyaMc1fUhPYUd7OA06V+Blym1cJkHKAvpRu 5jhagXu/ABR8Af2tZERV+CnpOiKXU7qALOGqvc6MLrJy7X0mb2R7sarmZjOXoLfSkN9nri51DsR dCgf7Vx7uLTVMNVXhzOiT+zb90IeGjPR0jBDS1C1ORSBnEq0ixRkuA9AzKNcu6d5bNfNufexmTA aMFa9SbYXNZHbeRoWsJWRtlSvsLz5jfqIeyBOAaVZblpW+xy27HAlgaTcfwpcXYD8SyZmNrCc21 RKwlQZii5HZZpi8kueMrI7hz9UcVyYdXvIYwXk97ANpP0f0At/9uORxgo5QNOBD4QkLeTdfO+vO 8AoTUhjEBqVj/QaEB2KWHUw9jAnPGjde2Drw58w== X-Received: by 2002:a5d:588f:0:b0:431:8f8:7f1a with SMTP id ffacd0b85a97d-432c3750285mr15437822f8f.31.1768088021327; Sat, 10 Jan 2026 15:33:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IFccgkkyUo2MEaPP1fx2T+Wwfw7F5c2WCYqf42zfaj+FFUH+6r+sm+39aXUm4jECMgaZsPu8Q== X-Received: by 2002:a5d:588f:0:b0:431:8f8:7f1a with SMTP id ffacd0b85a97d-432c3750285mr15437808f8f.31.1768088020829; Sat, 10 Jan 2026 15:33:40 -0800 (PST) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-432bd5dfa07sm29930817f8f.25.2026.01.10.15.33.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jan 2026 15:33:40 -0800 (PST) Date: Sun, 11 Jan 2026 00:33:39 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 3/3] tcp, udp: Make {tcp,udp}_listen() return socket fds Message-ID: <20260111003339.5c2c979c@elisabeth> In-Reply-To: <20260105082850.1985300-4-david@gibson.dropbear.id.au> References: <20260105082850.1985300-1-david@gibson.dropbear.id.au> <20260105082850.1985300-4-david@gibson.dropbear.id.au> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.49; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: s-8z1y4TFyIdQ8p6Lt0Z7c4rpdBjY-lbw0Mfu3Uyk4E_1768088022 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: G5ZMHNMFFK4QHA56VBUL52YHM6EJZXEQ X-Message-ID-Hash: G5ZMHNMFFK4QHA56VBUL52YHM6EJZXEQ 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, 5 Jan 2026 19:28:50 +1100 David Gibson wrote: > {tcp,udp}_listen() currently return 0 on success, rather than the socket > fd they created. Historically, that was because these functions could > sometimes create multiple sockets. We've now refactored things to avoid > that, so it makes more sense for them to return the socket on success. > > Signed-off-by: David Gibson > --- > conf.c | 14 +++++++------- > tcp.c | 7 ++----- > udp.c | 4 ++-- > 3 files changed, 11 insertions(+), 14 deletions(-) > > diff --git a/conf.c b/conf.c > index cc3c20a9..5db49653 100644 > --- a/conf.c > +++ b/conf.c > @@ -149,7 +149,7 @@ static void conf_ports_range_except(const struct ctx *c, char optname, > { > bool bound_one = false; > unsigned i; > - int ret; > + int fd; > > if (first == 0) { > die("Can't forward port 0 for option '-%c %s'", > @@ -185,23 +185,23 @@ static void conf_ports_range_except(const struct ctx *c, char optname, > fwd->delta[i] = to - first; > > if (optname == 't') > - ret = tcp_listen(c, PIF_HOST, addr, ifname, i); > + fd = tcp_listen(c, PIF_HOST, addr, ifname, i); > else if (optname == 'u') > - ret = udp_listen(c, PIF_HOST, addr, ifname, i); > + fd = udp_listen(c, PIF_HOST, addr, ifname, i); > else > /* No way to check in advance for -T and -U */ > - ret = 0; > + fd = 0; > > - if (ret == -ENFILE || ret == -EMFILE) { > + if (fd == -ENFILE || fd == -EMFILE) { > die("Can't open enough sockets for port specifier: %s", > optarg); > } > > - if (!ret) { > + if (fd >= 0) { > bound_one = true; > } else if (!weak) { > die("Failed to bind port %u (%s) for option '-%c %s'", > - i, strerror_(-ret), optname, optarg); > + i, strerror_(-fd), optname, optarg); > } > } > > diff --git a/tcp.c b/tcp.c > index 67007c05..80b47f3c 100644 > --- a/tcp.c > +++ b/tcp.c > @@ -2680,7 +2680,7 @@ void tcp_sock_handler(const struct ctx *c, union epoll_ref ref, > * @ifname: Name of interface to bind to, NULL for any > * @port: Port, host order > * > - * Return: 0 on success, negative error code on failure > + * Return: Socket fd on success, negative error code on failure Nit, here and on udp_listen(): "socket". See also 9e0423e13541 ("style: Fix 'Return' comment style"). > */ > int tcp_listen(const struct ctx *c, uint8_t pif, > const union inany_addr *addr, const char *ifname, in_port_t port) > @@ -2729,10 +2729,7 @@ int tcp_listen(const struct ctx *c, uint8_t pif, > socks[port][V6] = s < 0 ? -1 : s; > } > > - if (s < 0) > - return s; > - > - return 0; > + return s; > } > > /** > diff --git a/udp.c b/udp.c > index 8cfa1e1f..63dc7c25 100644 > --- a/udp.c > +++ b/udp.c > @@ -1136,7 +1136,7 @@ int udp_tap_handler(const struct ctx *c, uint8_t pif, > * @ifname: Name of interface to bind to, NULL if not configured > * @port: Port, host order > * > - * Return: 0 on success, negative error code on failure > + * Return: Socket fd on success, negative error code on failure > */ > int udp_listen(const struct ctx *c, uint8_t pif, > const union inany_addr *addr, const char *ifname, in_port_t port) > @@ -1180,7 +1180,7 @@ int udp_listen(const struct ctx *c, uint8_t pif, > if (!addr || !inany_v4(addr)) > socks[V6][port] = s < 0 ? -1 : s; > > - return s < 0 ? s : 0; > + return s; > } > > /** -- Stefano