[PATCH bpf-next 02/15] selftests/bpf: AF_PACKET support for make_sockaddr

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Geliang Tang <tanggeliang@xxxxxxxxxx>

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 <tanggeliang@xxxxxxxxxx>
---
 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;
 }
-- 
2.43.0





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux