3 #include <sys/socket.h>
4 #include <sys/kern_control.h>
5 #include <sys/sys_domain.h>
7 #include <net/if_utun.h>
8 #include <net/if_ipsec.h>
10 #include <darwintest.h>
11 #include <darwintest_utils.h>
13 T_GLOBAL_META(T_META_NAMESPACE("xnu.net"));
15 T_DECL(PR_35136664_utun
,
16 "This bind a utun and close it without connecting")
19 struct ctl_info kernctl_info
;
20 struct sockaddr_ctl kernctl_addr
;
22 T_ASSERT_POSIX_SUCCESS(tunsock
= socket(PF_SYSTEM
, SOCK_DGRAM
, SYSPROTO_CONTROL
), NULL
);
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
);
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;
35 T_ASSERT_POSIX_ZERO(bind(tunsock
, (struct sockaddr
*)&kernctl_addr
, sizeof(kernctl_addr
)), NULL
);
37 T_ASSERT_POSIX_ZERO(close(tunsock
), NULL
);
40 T_DECL(PR_35136664_ipsec
,
41 "This bind a ipsec and close it without connecting")
44 struct ctl_info kernctl_info
;
45 struct sockaddr_ctl kernctl_addr
;
47 T_ASSERT_POSIX_SUCCESS(tunsock
= socket(PF_SYSTEM
, SOCK_DGRAM
, SYSPROTO_CONTROL
), NULL
);
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
);
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;
60 T_ASSERT_POSIX_ZERO(bind(tunsock
, (struct sockaddr
*)&kernctl_addr
, sizeof(kernctl_addr
)), NULL
);
62 T_ASSERT_POSIX_ZERO(close(tunsock
), NULL
);