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