]> git.saurik.com Git - apple/xnu.git/blob - tests/net_tun_pr_35136664.c
xnu-7195.50.7.100.1.tar.gz
[apple/xnu.git] / tests / net_tun_pr_35136664.c
1 #include <sys/ioctl.h>
2 #include <sys/socket.h>
3 #include <sys/kern_control.h>
4 #include <sys/sys_domain.h>
5
6 #include <net/if_utun.h>
7 #include <net/if_ipsec.h>
8
9 #include <darwintest.h>
10 #include <darwintest_utils.h>
11
12 T_GLOBAL_META(T_META_NAMESPACE("xnu.net"),
13 T_META_RUN_CONCURRENTLY(true),
14 T_META_ASROOT(true));
15
16 T_DECL(PR_35136664_utun,
17 "This bind a utun and close it without connecting")
18 {
19 int tunsock;
20 struct ctl_info kernctl_info;
21 struct sockaddr_ctl kernctl_addr;
22
23 T_ASSERT_POSIX_SUCCESS(tunsock = socket(PF_SYSTEM, SOCK_DGRAM, SYSPROTO_CONTROL), NULL);
24
25 memset(&kernctl_info, 0, sizeof(kernctl_info));
26 strlcpy(kernctl_info.ctl_name, UTUN_CONTROL_NAME, sizeof(kernctl_info.ctl_name));
27 T_ASSERT_POSIX_ZERO(ioctl(tunsock, CTLIOCGINFO, &kernctl_info), NULL);
28
29 memset(&kernctl_addr, 0, sizeof(kernctl_addr));
30 kernctl_addr.sc_len = sizeof(kernctl_addr);
31 kernctl_addr.sc_family = AF_SYSTEM;
32 kernctl_addr.ss_sysaddr = AF_SYS_CONTROL;
33 kernctl_addr.sc_id = kernctl_info.ctl_id;
34 kernctl_addr.sc_unit = 0;
35
36 T_ASSERT_POSIX_ZERO(bind(tunsock, (struct sockaddr *)&kernctl_addr, sizeof(kernctl_addr)), NULL);
37
38 T_ASSERT_POSIX_ZERO(close(tunsock), NULL);
39 }
40
41 T_DECL(PR_35136664_ipsec,
42 "This bind a ipsec and close it without connecting")
43 {
44 int tunsock;
45 struct ctl_info kernctl_info;
46 struct sockaddr_ctl kernctl_addr;
47
48 T_ASSERT_POSIX_SUCCESS(tunsock = socket(PF_SYSTEM, SOCK_DGRAM, SYSPROTO_CONTROL), NULL);
49
50 memset(&kernctl_info, 0, sizeof(kernctl_info));
51 strlcpy(kernctl_info.ctl_name, IPSEC_CONTROL_NAME, sizeof(kernctl_info.ctl_name));
52 T_ASSERT_POSIX_ZERO(ioctl(tunsock, CTLIOCGINFO, &kernctl_info), NULL);
53
54 memset(&kernctl_addr, 0, sizeof(kernctl_addr));
55 kernctl_addr.sc_len = sizeof(kernctl_addr);
56 kernctl_addr.sc_family = AF_SYSTEM;
57 kernctl_addr.ss_sysaddr = AF_SYS_CONTROL;
58 kernctl_addr.sc_id = kernctl_info.ctl_id;
59 kernctl_addr.sc_unit = 0;
60
61 T_ASSERT_POSIX_ZERO(bind(tunsock, (struct sockaddr *)&kernctl_addr, sizeof(kernctl_addr)), NULL);
62
63 T_ASSERT_POSIX_ZERO(close(tunsock), NULL);
64 }