2 #include <sys/socket.h>
3 #include <sys/kern_control.h>
4 #include <sys/sys_domain.h>
6 #include <net/if_utun.h>
7 #include <net/if_ipsec.h>
9 #include <darwintest.h>
10 #include <darwintest_utils.h>
12 T_GLOBAL_META(T_META_NAMESPACE("xnu.net"),
13 T_META_RUN_CONCURRENTLY(true),
16 T_DECL(PR_35136664_utun
,
17 "This bind a utun and close it without connecting")
20 struct ctl_info kernctl_info
;
21 struct sockaddr_ctl kernctl_addr
;
23 T_ASSERT_POSIX_SUCCESS(tunsock
= socket(PF_SYSTEM
, SOCK_DGRAM
, SYSPROTO_CONTROL
), NULL
);
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
);
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;
36 T_ASSERT_POSIX_ZERO(bind(tunsock
, (struct sockaddr
*)&kernctl_addr
, sizeof(kernctl_addr
)), NULL
);
38 T_ASSERT_POSIX_ZERO(close(tunsock
), NULL
);
41 T_DECL(PR_35136664_ipsec
,
42 "This bind a ipsec and close it without connecting")
45 struct ctl_info kernctl_info
;
46 struct sockaddr_ctl kernctl_addr
;
48 T_ASSERT_POSIX_SUCCESS(tunsock
= socket(PF_SYSTEM
, SOCK_DGRAM
, SYSPROTO_CONTROL
), NULL
);
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
);
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;
61 T_ASSERT_POSIX_ZERO(bind(tunsock
, (struct sockaddr
*)&kernctl_addr
, sizeof(kernctl_addr
)), NULL
);
63 T_ASSERT_POSIX_ZERO(close(tunsock
), NULL
);