From patchwork Tue Jul 23 22:22:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13740421 X-Patchwork-Delegate: bpf@iogearbox.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D5CA91DDD6; Tue, 23 Jul 2024 22:23:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721773399; cv=none; b=MRpmFndEQn/xaDhfJhUXUSmECPPPOv+1z1RpDgEqfC6TROpDBqMHYzsqCGSQNt7Y4/CvnfdzdNLI6EkA5m1APN0PjiuZihSCgAkPZpg22t4mIIyY5EVS8oXzoN8WrL5RFo/Peimlt7L+JSgLweGVQ+/0oDtRJLfOY7P7ZSCxjOI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721773399; c=relaxed/simple; bh=4RgzlUO1ELpjhyL1Q4t07Sw3sMou1DtPvptQrfqDGKg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YNlFwWM720gi2PYRIdhBK4PXvgWo7biLZ6Ts/PgR97tp8lQucu07TVVYBSS2Cyz2Dspgdo3BJz+LjYarTjFbj1BsFLkh2jn1eeLSgV1kyNHkG2RGLp5cssbBiCYAt6UKXmye/40zuBAhtonXAmzBahY0YwgAqJ/Ln90MKuTtIAc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fNduFsIm; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fNduFsIm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1041CC4AF14; Tue, 23 Jul 2024 22:23:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721773399; bh=4RgzlUO1ELpjhyL1Q4t07Sw3sMou1DtPvptQrfqDGKg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fNduFsImGJp2OKknBzpaaEwfdYy2iTK1tt2thM9HPAGTp93XKDDNYo9RmbdMZr+aC dZiZ0WcRM1DIhG0c6E3MRlVue4K3racvkNn6VpKuIZZTs5F/qfZgwlDYMKJ0tAg0G4 PlaczmwZpOdU7QDVUJLLkwcgwRsr34BRAcV+MnmOggqCfEzMeOaju+1imLxIHvh4xY dZKxkOwMIHKC2ZV5TYfV6LVfaxbj2EdaKBXQO/AsranHW9nEjIwAvZVLvTcozBji76 dOODZXbuVsyWE8BPJAt0XTNYhNT1D6S3A0+ysIe7FeoI4ND5vGtYmXrbLju8G75/2W rdGNC/w0fcQrg== From: Geliang Tang To: Andrii Nakryiko , Eduard Zingerman , Mykola Lysenko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Hao Luo , Jiri Olsa , Shuah Khan Cc: Geliang Tang , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next 10/15] selftests/bpf: AF_VSOCK support for make_sockaddr Date: Wed, 24 Jul 2024 06:22:16 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Geliang Tang This patch adds AF_VSOCK support for make_sockaddr(), uses atoi() to convert the given addr_str string to an integer id and sets it to "svm_cid". Set "svm_port" as VMADDR_PORT_ANY if the value of port is zero. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index f140a76d3d7f..8b06b0bf66ae 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -18,6 +18,7 @@ #include #include #include +#include #include "bpf_util.h" #include "network_helpers.h" @@ -486,6 +487,16 @@ int make_sockaddr(int family, const char *addr_str, __u16 port, if (len) *len = sizeof(*salg); return 0; + } else if (family == AF_VSOCK) { + struct sockaddr_vm *svm = (void *)addr; + + memset(addr, 0, sizeof(*svm)); + svm->svm_family = family; + svm->svm_port = port ?: VMADDR_PORT_ANY; + svm->svm_cid = addr_str ? atoi(addr_str) : 0; + if (len) + *len = sizeof(*svm); + return 0; } return -1; }