From patchwork Tue Jul 23 22:22:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13740413 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 B86FB1487E9; Tue, 23 Jul 2024 22:22:45 +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=1721773365; cv=none; b=bH1VgPfmihd9u0L8q/gQIROiUM9WJKKBvPWef0fIK63l6+mblJcRlz8sjhk6eM5POXr5WcLuCrEkLR8A8vxH8Ekhp8cycRT9AfbJyWI7rvdUt1dHizcfqAul6rsuPRZBSRI2mKwC2YJlldeWHooLivoBuTxt76RnKPvlJIuYqQo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721773365; c=relaxed/simple; bh=12aAaZMootg+cvj+0ayt/8qu159GnEbnVlWc6KZT748=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mu6J/Uu5w9Lxj5N2y2ZnvQtVo4jZwDIVeKTJTAOlF1QmOeBw8kMUITpMX1ByTTn5fAZJwb1OhiBq5e0mSUpRGIWXh3LCNugODnwzYmZN6jpAAMhAbQVrROAm9BKY0TGe0iPRDrldnQJ2ASVLjAtM1aJd7JkXWUOZ6b3ie5x012o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GcNgF9j8; 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="GcNgF9j8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC283C4AF0F; Tue, 23 Jul 2024 22:22:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721773365; bh=12aAaZMootg+cvj+0ayt/8qu159GnEbnVlWc6KZT748=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GcNgF9j8fYFu0O8jZo1teuViXEcwm5ET1nCR4ZdoTXhkpDmsEd2gWimUte/Ge/0pY d2eMuUQPGqeRME6Mw0gs/MkIyE5dGVq3WijwFBrJR4g1Cc169OH+Bh6pH/PQm7tW5O uFw05Qm8gX+M7b7hSsZcqLU/jmvfnSi4kXB83DxscXADZkNC27Gcx07liHm+DhVFk0 pf0PTouQzG2QjnktC6hFId6ZRCOovNTbgVNiLvMvM8XLeuV7vOTZGTQvsEZ1fN9OTJ Ix1Z+VmviIDUvD0BUg9J7+4tjNYo3xF/X9x+Yz4JuMRkcTBN4PHsrpJrt4cv3dMNHu 4i7MjDv3Wq3Yg== 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 02/15] selftests/bpf: AF_PACKET support for make_sockaddr Date: Wed, 24 Jul 2024 06:22:08 +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_PACKET support for make_sockaddr(), uses sscanf() to parse the given addr_str string into sll_ifindex, sll_halen and sll_addr of sockaddr_ll. Other fields of struct sockaddr_ll are not used in BPF selftests right now. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index a3f0a49fb26f..2a142d713861 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -416,6 +416,21 @@ int make_sockaddr(int family, const char *addr_str, __u16 port, if (len) *len = offsetof(struct sockaddr_un, sun_path) + 1 + strlen(addr_str); return 0; + } else if (family == AF_PACKET) { + struct sockaddr_ll *sll = (void *)addr; + + memset(addr, 0, sizeof(*sll)); + sll->sll_family = family; + sll->sll_protocol = htons(ETH_P_ALL); + if (addr_str && + sscanf(addr_str, "%d %c %s", &sll->sll_ifindex, + &sll->sll_halen, sll->sll_addr) == -1) { + log_err("AF_PACKET sscanf(%s)", addr_str); + return -1; + } + if (len) + *len = sizeof(*sll); + return 0; } return -1; }