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=ZzWfXSjO; 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 1FB135A0262 for ; Fri, 15 May 2026 02:47:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778806045; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3W49t6z/z6YNWAh89FsjAKDc2cYhPjAkOgROhSJ6ljw=; b=ZzWfXSjOhkduhpJLa2nhmsqXsFiQHDRUh1ur204h8dZ6Rt51jc3dAAErlpgspQa+ckwjIx CfxpLj58hCViub/EYnoLKGwUHC/9VhlIheMZI5jkOxAQIoQ4Dj6GaOZn7AzxJwKv+fJPFN gjlLWzIe/pLaqR367gHCGFQDhl5zHXI= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-589-Ha62CmDxPxKsYHCx-KL4oA-1; Thu, 14 May 2026 20:47:23 -0400 X-MC-Unique: Ha62CmDxPxKsYHCx-KL4oA-1 X-Mimecast-MFC-AGG-ID: Ha62CmDxPxKsYHCx-KL4oA_1778806043 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-910b2b92741so98100085a.0 for ; Thu, 14 May 2026 17:47:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778806043; x=1779410843; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3W49t6z/z6YNWAh89FsjAKDc2cYhPjAkOgROhSJ6ljw=; b=roP+3AxhfdTM82xe0BrcXytOwfwA1bA0LeJLOkFultkSeLyN95afC1XRDbRFUN30nE hHTofQ2GXDvIuOvmEEEqIn7phMYCQrdyCclEt7JJwP4BjNvdWptIY2Plq40te9yD4ohj ykFfPuGQQpQWbEC+ZTZwjLzNGqX0WV+BGBTrEpOpAhDAgdh4DNTDqJzC+WxumaW1lLck MjQz/Jhd48UkN/S5CrimOhRAiy5KqKNv8KTCO1eScHyXxO0TdrLIKPBtkDj6Hg2TOpME 6y5s7Yoh7qxxdse6hbk90IR5gmwmIIPVUqOdzG7L2ZWXtBWuMWlFnq/JMF6Gs0XQwM5R h5vQ== X-Forwarded-Encrypted: i=1; AFNElJ88eV+VfRlNkHXHMnB8ObnkF+whwUyUnkuSufRJTApfNCl+OA6kY/FKPxCExwGKwArLGyKqde/Mb3M=@passt.top X-Gm-Message-State: AOJu0YyEIE3pvoOfRfPK9UCB+86k7pb4y+veu0c670izoHyO3FWMFlIQ W6uPWiWcPjWeVAWNPTfu8+MccW33YbrOKzW+ZPL9z3xM64Awoe4x96UK5pRLgc+KC059yiYePgy 7ZPQtSLwozBKIcDLcLbuH6t7EftHAYTYaaiwLT/GzRLVznDGW32u+lg== X-Gm-Gg: Acq92OFS2PyD5X7v8jzVbgDAoLHCc1J8kW1XeQvRt6/JJxX+7Nyyurj4FRZyWU1H/US oEsw+FZcqsEgWGgR6bBvWkMZDHeHKy7NSYK0IR13Pavt9VWR7tAm0kJJE8QG8MDKGmEUnHK2V/m MiVwbSgXyUnKQ+dxoHQXCzgCoss99P5G3oe/0rJ48s6N4bs+4sQvlntrdKJRvygRV/Itxok0i9C 4UdZhr5nPmYg9ZAProlp/Jh/7eyHLY2MAvNUSsFC1NLS7oxWUChHLdZus6GnQFjpM6xrACKsjhs FJkf5nQ2Qbe7VM1+snizp7P9afZKyL5N/SBVd/kh0Iv6TRYzlPf8lP2mSi4FxWsfpv0SU4CqbbA /190QV1Y3yv/hFvtKXt7H1omRKB9Ao0r22TZxZKPCPoHANMtKqh3YhiG21lnI9gA4tXBF/Y37F9 MLNd6Q10qxZvLuTNgD6+uGPbw= X-Received: by 2002:a05:620a:a019:b0:911:e17d:1d78 with SMTP id af79cd13be357-911e17d1e4dmr218175485a.21.1778806042814; Thu, 14 May 2026 17:47:22 -0700 (PDT) X-Received: by 2002:a05:620a:a019:b0:911:e17d:1d78 with SMTP id af79cd13be357-911e17d1e4dmr218172885a.21.1778806042336; Thu, 14 May 2026 17:47:22 -0700 (PDT) Received: from [192.168.2.15] (lnsm4-toronto63-142-116-28-118.internet.virginmobile.ca. [142.116.28.118]) by smtp.gmail.com with ESMTPSA id af79cd13be357-910bd6243b3sm391262985a.44.2026.05.14.17.47.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 May 2026 17:47:21 -0700 (PDT) Message-ID: <567be31e-7769-4d49-b15b-15ea2ace7f51@redhat.com> Date: Thu, 14 May 2026 20:47:21 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/2] tcp, tcp_splice: Make helper for setting SO_LINGER socket option To: David Gibson , passt-dev@passt.top, Stefano Brivio References: <20260513071821.3137329-1-david@gibson.dropbear.id.au> <20260513071821.3137329-2-david@gibson.dropbear.id.au> From: Jon Maloy In-Reply-To: <20260513071821.3137329-2-david@gibson.dropbear.id.au> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: yVzH-ZrG8HpMDS4NnWMRkPJ9ioXwRThdhyR9Lc_cGxg_1778806043 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID-Hash: QLCRRMSZFFPI44AYOVJSPHKX3MJOTSFN X-Message-ID-Hash: QLCRRMSZFFPI44AYOVJSPHKX3MJOTSFN X-MailFrom: jmaloy@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 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 2026-05-13 03:18, David Gibson wrote: > Both spliced and non-spliced TCP in some cases set the SO_LINGER socket > option in order to to force a TCP RST on a socket side connection. In eachs/to to/to> case we open code the setsockopt() logic. We're shortly going to add > another place that needs this, so move the setsockopt() and error handling > logic into a shared helper. > > Signed-off-by: David Gibson Reviewed-by: Jon Maloy On 2026-05-13 03:18, David Gibson wrote: > Both spliced and non-spliced TCP in some cases set the SO_LINGER socket > option in order to to force a TCP RST on a socket side connection. In each s/to to/to/ > case we open code the setsockopt() logic. We're shortly going to add > another place that needs this, so move the setsockopt() and error handling > logic into a shared helper. > > Signed-off-by: David Gibson Reviewed-by: Jon Maloy > tcp.c | 33 ++++++++++++++++++++------------- > tcp_conn.h | 3 +++ > tcp_splice.c | 20 +++----------------- > 3 files changed, 26 insertions(+), 30 deletions(-) > > diff --git a/tcp.c b/tcp.c > index d6a9ba28..1078bdc3 100644 > --- a/tcp.c > +++ b/tcp.c > @@ -1395,29 +1395,36 @@ static int tcp_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, > } > > /** > - * tcp_sock_rst() - Close TCP connection forcing RST on socket side > - * @c: Execution context > - * @conn: Connection pointer > + * tcp_linger0_() - Set SO_LINGER with 0 timeout on socket > + * @f: Flow header (only for debug logging) > + * @s: Socket to modify > */ > -static void tcp_sock_rst(const struct ctx *c, struct tcp_tap_conn *conn) > +void tcp_linger0_(const struct flow_common *f, int s) > { > const struct linger linger0 = { > .l_onoff = 1, > .l_linger = 0, > }; > > - /* Force RST on socket to inform the peer > - * > - * We do this by setting SO_LINGER with 0 timeout, which means that > - * close() will send an RST (unless the connection is already closed in > - * both directions). > + /* Setting SO_LINGER with 0 timeout, means that close() will send an RST > + * (unless the connection is already closed in both directions). > */ > - if (setsockopt(conn->sock, SOL_SOCKET, > - SO_LINGER, &linger0, sizeof(linger0)) < 0) { > - flow_dbg_perror(conn, > - "SO_LINGER failed, may not send RST to peer"); > + if (setsockopt(s, SOL_SOCKET, SO_LINGER, > + &linger0, sizeof(linger0)) < 0) { > + flow_log_perror_(f, LOG_DEBUG, > + "SO_LINGER failed, may not send RST to peer"); > } > +} > > +/** > + * tcp_sock_rst() - Close TCP connection forcing RST on socket side > + * @c: Execution context > + * @conn: Connection pointer > + */ > +static void tcp_sock_rst(const struct ctx *c, struct tcp_tap_conn *conn) > +{ > + /* Force RST on socket to inform the peer */ > + tcp_linger0(conn, conn->sock); > conn_event(c, conn, CLOSED); > } > > diff --git a/tcp_conn.h b/tcp_conn.h > index 9f5bee03..5f7af240 100644 > --- a/tcp_conn.h > +++ b/tcp_conn.h > @@ -241,6 +241,9 @@ struct tcp_splice_conn { > extern int init_sock_pool4 [TCP_SOCK_POOL_SIZE]; > extern int init_sock_pool6 [TCP_SOCK_POOL_SIZE]; > > +void tcp_linger0_(const struct flow_common *f, int s); > +#define tcp_linger0(flow_, s_) tcp_linger0_(&(flow_)->f, (s_)) > + > bool tcp_flow_defer(const struct tcp_tap_conn *conn); > > int tcp_flow_repair_on(struct ctx *c, const struct tcp_tap_conn *conn); > diff --git a/tcp_splice.c b/tcp_splice.c > index 42ee8abc..4c18f0c4 100644 > --- a/tcp_splice.c > +++ b/tcp_splice.c > @@ -240,28 +240,14 @@ static void conn_event_do(struct tcp_splice_conn *conn, unsigned long event) > */ > static void tcp_splice_rst(struct tcp_splice_conn *conn) > { > - const struct linger linger0 = { > - .l_onoff = 1, > - .l_linger = 0, > - }; > unsigned sidei; > > if (conn->flags & CLOSING) > return; /* Nothing to do */ > > - /* Force RST on sockets to inform the peer > - * > - * We do this by setting SO_LINGER with 0 timeout, which means that > - * close() will send an RST (unless the connection is already closed in > - * both directions). > - */ > - flow_foreach_sidei(sidei) { > - if (setsockopt(conn->s[sidei], SOL_SOCKET, > - SO_LINGER, &linger0, sizeof(linger0)) < 0) { > - flow_dbg_perror(conn, > -"SO_LINGER failed, may not send RST to peer"); > - } > - } > + /* Force RST on sockets to inform the peer */ > + flow_foreach_sidei(sidei) > + tcp_linger0(conn, conn->s[sidei]); > > conn_flag(conn, CLOSING); > }