From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-172.mta0.migadu.com (out-172.mta0.migadu.com [91.218.175.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6448E78C98 for ; Thu, 9 May 2024 20:52:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715287926; cv=none; b=l+ktohcSCaS0URIQg+71ZttXEotUVMQz/nDCbtu6QEsqQFtQvTSV5kOLBBDmHPNq+mBO7W9fMwoUP4p/eqdBh4iFO9KKk9FLLrkbGflne5h6XswErAIDqya6duUmdyEmTumW2aU4TYA1K2vhw+po37xekn0Vv0o5oR9kHEK3GKs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715287926; c=relaxed/simple; bh=8GKdlnhEh2sJ7tP4geEyRalZJQ9pIGkChfeP+/lJ+5I=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Iv1VMAYhY7BWvOwkdnqbzcXDUqs7ZllzoydCatd9oFfgfgCBEFFUXALMAyVuwzWl8pDjI2Y4rspymyj+bFStrpgprBi+7GsAnEHB5dc9m8kDplxoLBVB+DDVj7aBiKnah3ZxTWT4NWPrg7Mt4I2pwfrE3F42ncdxk1kYcSokexU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=sUGgyUTR; arc=none smtp.client-ip=91.218.175.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="sUGgyUTR" Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1715287921; 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=Xd5tz04LEJEZwJBrn5k92cQ8p5d0btGjHa23s560374=; b=sUGgyUTR4QmLr4e2wDwsg60mxpImCOFZULp5fq6hDXmNj98FMqrRkNVm9jonOF5YvoQikM heqoU0OScsfIAXQQDhoLt/s3r5GDenHLd2ZzGgpAv5beBVp7wfd18LhUW1zKKC/Mwlvuk7 wOXTbcg6dvBXwHxHuTfBK8y/gy5Zx9w= Date: Thu, 9 May 2024 13:51:54 -0700 Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH bpf-next 2/6] selftests/bpf: Use start_server_addr in sockopt_inherit To: Geliang Tang Cc: Andrii Nakryiko , Eduard Zingerman , Mykola Lysenko , Alexei Starovoitov , Daniel Borkmann , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan , Jakub Sitnicki , Geliang Tang , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org References: <687af66f743a0bf15cdba372c5f71fe64863219e.1714907662.git.tanggeliang@kylinos.cn> Content-Language: en-US X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Martin KaFai Lau In-Reply-To: <687af66f743a0bf15cdba372c5f71fe64863219e.1714907662.git.tanggeliang@kylinos.cn> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 5/5/24 4:35 AM, Geliang Tang wrote: > From: Geliang Tang > > Include network_helpers.h in prog_tests/sockopt_inherit.c, use public > helper start_server_addr() instead of the local defined function > start_server(). This can avoid duplicate code. > > Add a helper custom_cb() to set SOL_CUSTOM sockopt looply, set it to > post_socket_cb pointer of struct network_helper_opts, and pass it to > start_server_addr(). > > Signed-off-by: Geliang Tang > --- > .../bpf/prog_tests/sockopt_inherit.c | 32 +++++++------------ > 1 file changed, 12 insertions(+), 20 deletions(-) > > diff --git a/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c b/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c > index 917f486db826..ff0694ef5286 100644 > --- a/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c > +++ b/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c > @@ -1,6 +1,7 @@ > // SPDX-License-Identifier: GPL-2.0 > #include > #include "cgroup_helpers.h" > +#include "network_helpers.h" > > #include "sockopt_inherit.skel.h" > > @@ -98,23 +99,12 @@ static void *server_thread(void *arg) > return (void *)(long)err; > } > > -static int start_server(void) > +static int custom_cb(int fd, const struct post_socket_opts *opts) > { > - struct sockaddr_in addr = { > - .sin_family = AF_INET, > - .sin_addr.s_addr = htonl(INADDR_LOOPBACK), > - }; > char buf; > int err; > - int fd; > int i; > > - fd = socket(AF_INET, SOCK_STREAM, 0); > - if (fd < 0) { > - log_err("Failed to create server socket"); > - return -1; > - } > - > for (i = CUSTOM_INHERIT1; i <= CUSTOM_LISTENER; i++) { > buf = 0x01; > err = setsockopt(fd, SOL_CUSTOM, i, &buf, 1); There is a close(fd) on the error case a few lines below (not in this diff context). The caller (network_helpers.c) will also close it. I removed the close(fd) from the custom_cb() here. Thanks for the patches. Applied. > @@ -125,20 +115,21 @@ static int start_server(void) > } > } > > - if (bind(fd, (const struct sockaddr *)&addr, sizeof(addr)) < 0) { > - log_err("Failed to bind socket"); > - close(fd); > - return -1; > - } > - > - return fd; > + return 0; > } >