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