[PATCH bpf-next 10/15] selftests/bpf: AF_VSOCK 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_VSOCK support for make_sockaddr(), uses atoi()
to convert the given addr_str string to an integer id and sets it to
"svm_cid". Set "svm_port" as VMADDR_PORT_ANY if the value of port is
zero.

Signed-off-by: Geliang Tang <tanggeliang@xxxxxxxxxx>
---
 tools/testing/selftests/bpf/network_helpers.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c
index f140a76d3d7f..8b06b0bf66ae 100644
--- a/tools/testing/selftests/bpf/network_helpers.c
+++ b/tools/testing/selftests/bpf/network_helpers.c
@@ -18,6 +18,7 @@
 #include <linux/in6.h>
 #include <linux/limits.h>
 #include <linux/if_alg.h>
+#include <linux/vm_sockets.h>
 
 #include "bpf_util.h"
 #include "network_helpers.h"
@@ -486,6 +487,16 @@ int make_sockaddr(int family, const char *addr_str, __u16 port,
 		if (len)
 			*len = sizeof(*salg);
 		return 0;
+	} else if (family == AF_VSOCK) {
+		struct sockaddr_vm *svm = (void *)addr;
+
+		memset(addr, 0, sizeof(*svm));
+		svm->svm_family = family;
+		svm->svm_port = port ?: VMADDR_PORT_ANY;
+		svm->svm_cid = addr_str ? atoi(addr_str) : 0;
+		if (len)
+			*len = sizeof(*svm);
+		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