From: Geliang Tang tanggeliang@kylinos.cn
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@kylinos.cn --- 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; }