1*5458a63bSKristof Provost /*- 2*5458a63bSKristof Provost * Copyright (c) 2020 Kristof Provost <kp@FreeBSD.org> 3*5458a63bSKristof Provost * 4*5458a63bSKristof Provost * Redistribution and use in source and binary forms, with or without 5*5458a63bSKristof Provost * modification, are permitted provided that the following conditions 6*5458a63bSKristof Provost * are met: 7*5458a63bSKristof Provost * 1. Redistributions of source code must retain the above copyright 8*5458a63bSKristof Provost * notice, this list of conditions and the following disclaimer. 9*5458a63bSKristof Provost * 2. Redistributions in binary form must reproduce the above copyright 10*5458a63bSKristof Provost * notice, this list of conditions and the following disclaimer in the 11*5458a63bSKristof Provost * documentation and/or other materials provided with the distribution. 12*5458a63bSKristof Provost * 13*5458a63bSKristof Provost * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14*5458a63bSKristof Provost * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15*5458a63bSKristof Provost * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16*5458a63bSKristof Provost * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17*5458a63bSKristof Provost * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18*5458a63bSKristof Provost * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19*5458a63bSKristof Provost * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20*5458a63bSKristof Provost * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21*5458a63bSKristof Provost * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22*5458a63bSKristof Provost * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23*5458a63bSKristof Provost * SUCH DAMAGE. 24*5458a63bSKristof Provost * 25*5458a63bSKristof Provost * $FreeBSD$ 26*5458a63bSKristof Provost */ 27*5458a63bSKristof Provost 28*5458a63bSKristof Provost #include <sys/ioctl.h> 29*5458a63bSKristof Provost #include <sys/linker.h> 30*5458a63bSKristof Provost #include <sys/module.h> 31*5458a63bSKristof Provost #include <sys/param.h> 32*5458a63bSKristof Provost #include <sys/socket.h> 33*5458a63bSKristof Provost #include <sys/types.h> 34*5458a63bSKristof Provost 35*5458a63bSKristof Provost #include <net/if.h> 36*5458a63bSKristof Provost 37*5458a63bSKristof Provost #include <fcntl.h> 38*5458a63bSKristof Provost #include <stdio.h> 39*5458a63bSKristof Provost 40*5458a63bSKristof Provost #include <atf-c.h> 41*5458a63bSKristof Provost 42*5458a63bSKristof Provost ATF_TC(params); 43*5458a63bSKristof Provost ATF_TC_HEAD(params, tc) 44*5458a63bSKristof Provost { 45*5458a63bSKristof Provost atf_tc_set_md_var(tc, "require.user", "root"); 46*5458a63bSKristof Provost } 47*5458a63bSKristof Provost 48*5458a63bSKristof Provost ATF_TC_BODY(params, tc) 49*5458a63bSKristof Provost { 50*5458a63bSKristof Provost struct ifreq ifr; 51*5458a63bSKristof Provost int s; 52*5458a63bSKristof Provost 53*5458a63bSKristof Provost s = kldload("if_epair"); 54*5458a63bSKristof Provost if (s != 0) 55*5458a63bSKristof Provost atf_tc_fail("Failed to load if_epair"); 56*5458a63bSKristof Provost 57*5458a63bSKristof Provost s = socket(AF_INET, SOCK_DGRAM, 0); 58*5458a63bSKristof Provost if (s < 0) 59*5458a63bSKristof Provost atf_tc_fail("Failed to create socket"); 60*5458a63bSKristof Provost 61*5458a63bSKristof Provost bzero(&ifr, sizeof(ifr)); 62*5458a63bSKristof Provost ifr.ifr_data = (caddr_t)-1; 63*5458a63bSKristof Provost (void) strlcpy(ifr.ifr_name, "epair", sizeof(ifr.ifr_name)); 64*5458a63bSKristof Provost 65*5458a63bSKristof Provost ioctl(s, SIOCIFCREATE2, &ifr); 66*5458a63bSKristof Provost } 67*5458a63bSKristof Provost 68*5458a63bSKristof Provost ATF_TP_ADD_TCS(tp) 69*5458a63bSKristof Provost { 70*5458a63bSKristof Provost ATF_TP_ADD_TC(tp, params); 71*5458a63bSKristof Provost 72*5458a63bSKristof Provost return (atf_no_error()); 73*5458a63bSKristof Provost } 74