From: Geliang Tang tanggeliang@kylinos.cn
This patch adds AF_ALG support for make_sockaddr(), uses sscanf() to parse the given addr_str string to "salg_type" and "salg_name" of struct sockaddr_alg.
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 a6c158718267..8f39adbc2c16 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -17,6 +17,7 @@ #include <linux/in.h> #include <linux/in6.h> #include <linux/limits.h> +#include <linux/if_alg.h>
#include "bpf_util.h" #include "network_helpers.h" @@ -468,6 +469,20 @@ int make_sockaddr(int family, const char *addr_str, __u16 port, if (len) *len = sizeof(*sll); return 0; + } else if (family == AF_ALG) { + struct sockaddr_alg *salg = (void *)addr; + + memset(addr, 0, sizeof(*salg)); + salg->salg_family = family; + if (addr_str && + sscanf(addr_str, "%s %s", + salg->salg_type, salg->salg_name) == -1) { + log_err("AF_ALG sscanf(%s)", addr_str); + return -1; + } + if (len) + *len = sizeof(*salg); + return 0; } return -1; }