[PATCH bpf-next 07/15] selftests/bpf: AF_ALG 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_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@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 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;
 }
-- 
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