]> git.baikalelectronics.ru Git - kernel.git/commitdiff
selftests: net: rename cmsg_so_mark
authorJakub Kicinski <kuba@kernel.org>
Thu, 10 Feb 2022 00:36:42 +0000 (16:36 -0800)
committerDavid S. Miller <davem@davemloft.net>
Thu, 10 Feb 2022 15:04:51 +0000 (15:04 +0000)
Rename the file in prep for generalization.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
tools/testing/selftests/net/.gitignore
tools/testing/selftests/net/Makefile
tools/testing/selftests/net/cmsg_sender.c [new file with mode: 0644]
tools/testing/selftests/net/cmsg_so_mark.c [deleted file]
tools/testing/selftests/net/cmsg_so_mark.sh

index 7581a7348e1bcca4898d9c4391d50053804a5f4c..21a411b0489005caba4c89657d25e6c5cff33940 100644 (file)
@@ -35,4 +35,4 @@ test_unix_oob
 gro
 ioam6_parser
 toeplitz
-cmsg_so_mark
+cmsg_sender
index 9897fa9ab95373f292bff1bffaf989fa5271eafc..8f4c1f16655f3dc2b6b21d7a48ba8cda841390cf 100644 (file)
@@ -52,7 +52,7 @@ TEST_GEN_FILES += gro
 TEST_GEN_PROGS = reuseport_bpf reuseport_bpf_cpu reuseport_bpf_numa
 TEST_GEN_PROGS += reuseport_dualstack reuseaddr_conflict tls
 TEST_GEN_FILES += toeplitz
-TEST_GEN_FILES += cmsg_so_mark
+TEST_GEN_FILES += cmsg_sender
 
 TEST_FILES := settings
 
diff --git a/tools/testing/selftests/net/cmsg_sender.c b/tools/testing/selftests/net/cmsg_sender.c
new file mode 100644 (file)
index 0000000..27f2804
--- /dev/null
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+#include <errno.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <linux/types.h>
+#include <sys/socket.h>
+
+int main(int argc, const char **argv)
+{
+       char cbuf[CMSG_SPACE(sizeof(__u32))];
+       struct addrinfo hints, *ai;
+       struct cmsghdr *cmsg;
+       struct iovec iov[1];
+       struct msghdr msg;
+       int mark;
+       int err;
+       int fd;
+
+       if (argc != 4) {
+               fprintf(stderr, "Usage: %s <dst_ip> <port> <mark>\n", argv[0]);
+               return 1;
+       }
+       mark = atoi(argv[3]);
+
+       memset(&hints, 0, sizeof(hints));
+       hints.ai_family = AF_UNSPEC;
+       hints.ai_socktype = SOCK_DGRAM;
+
+       ai = NULL;
+       err = getaddrinfo(argv[1], argv[2], &hints, &ai);
+       if (err) {
+               fprintf(stderr, "Can't resolve address: %s\n", strerror(errno));
+               return 1;
+       }
+
+       fd = socket(ai->ai_family, SOCK_DGRAM, IPPROTO_UDP);
+       if (fd < 0) {
+               fprintf(stderr, "Can't open socket: %s\n", strerror(errno));
+               freeaddrinfo(ai);
+               return 1;
+       }
+
+       iov[0].iov_base = "bla";
+       iov[0].iov_len = 4;
+
+       msg.msg_name = ai->ai_addr;
+       msg.msg_namelen = ai->ai_addrlen;
+       msg.msg_iov = iov;
+       msg.msg_iovlen = 1;
+       msg.msg_control = cbuf;
+       msg.msg_controllen = sizeof(cbuf);
+
+       cmsg = CMSG_FIRSTHDR(&msg);
+       cmsg->cmsg_level = SOL_SOCKET;
+       cmsg->cmsg_type = SO_MARK;
+       cmsg->cmsg_len = CMSG_LEN(sizeof(__u32));
+       *(__u32 *)CMSG_DATA(cmsg) = mark;
+
+       err = sendmsg(fd, &msg, 0);
+
+       close(fd);
+       freeaddrinfo(ai);
+       return err != 4;
+}
diff --git a/tools/testing/selftests/net/cmsg_so_mark.c b/tools/testing/selftests/net/cmsg_so_mark.c
deleted file mode 100644 (file)
index 27f2804..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-#include <errno.h>
-#include <netdb.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <linux/types.h>
-#include <sys/socket.h>
-
-int main(int argc, const char **argv)
-{
-       char cbuf[CMSG_SPACE(sizeof(__u32))];
-       struct addrinfo hints, *ai;
-       struct cmsghdr *cmsg;
-       struct iovec iov[1];
-       struct msghdr msg;
-       int mark;
-       int err;
-       int fd;
-
-       if (argc != 4) {
-               fprintf(stderr, "Usage: %s <dst_ip> <port> <mark>\n", argv[0]);
-               return 1;
-       }
-       mark = atoi(argv[3]);
-
-       memset(&hints, 0, sizeof(hints));
-       hints.ai_family = AF_UNSPEC;
-       hints.ai_socktype = SOCK_DGRAM;
-
-       ai = NULL;
-       err = getaddrinfo(argv[1], argv[2], &hints, &ai);
-       if (err) {
-               fprintf(stderr, "Can't resolve address: %s\n", strerror(errno));
-               return 1;
-       }
-
-       fd = socket(ai->ai_family, SOCK_DGRAM, IPPROTO_UDP);
-       if (fd < 0) {
-               fprintf(stderr, "Can't open socket: %s\n", strerror(errno));
-               freeaddrinfo(ai);
-               return 1;
-       }
-
-       iov[0].iov_base = "bla";
-       iov[0].iov_len = 4;
-
-       msg.msg_name = ai->ai_addr;
-       msg.msg_namelen = ai->ai_addrlen;
-       msg.msg_iov = iov;
-       msg.msg_iovlen = 1;
-       msg.msg_control = cbuf;
-       msg.msg_controllen = sizeof(cbuf);
-
-       cmsg = CMSG_FIRSTHDR(&msg);
-       cmsg->cmsg_level = SOL_SOCKET;
-       cmsg->cmsg_type = SO_MARK;
-       cmsg->cmsg_len = CMSG_LEN(sizeof(__u32));
-       *(__u32 *)CMSG_DATA(cmsg) = mark;
-
-       err = sendmsg(fd, &msg, 0);
-
-       close(fd);
-       freeaddrinfo(ai);
-       return err != 4;
-}
index 19c6aab8d0e94d0f8aef86b95ebbad8d308940c0..29a623aac74bf6f7cc2fc36b96c070896b01a608 100755 (executable)
@@ -41,14 +41,14 @@ check_result() {
     fi
 }
 
-ip netns exec $NS ./cmsg_so_mark $TGT4 1234 $((MARK + 1))
+ip netns exec $NS ./cmsg_sender $TGT4 1234 $((MARK + 1))
 check_result $? 0 "IPv4 pass"
-ip netns exec $NS ./cmsg_so_mark $TGT6 1234 $((MARK + 1))
+ip netns exec $NS ./cmsg_sender $TGT6 1234 $((MARK + 1))
 check_result $? 0 "IPv6 pass"
 
-ip netns exec $NS ./cmsg_so_mark $TGT4 1234 $MARK
+ip netns exec $NS ./cmsg_sender $TGT4 1234 $MARK
 check_result $? 1 "IPv4 rejection"
-ip netns exec $NS ./cmsg_so_mark $TGT6 1234 $MARK
+ip netns exec $NS ./cmsg_sender $TGT6 1234 $MARK
 check_result $? 1 "IPv6 rejection"
 
 # Summary