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