15458a63bSKristof Provost /*- 25458a63bSKristof Provost * Copyright (c) 2020 Kristof Provost <kp@FreeBSD.org> 35458a63bSKristof Provost * 45458a63bSKristof Provost * Redistribution and use in source and binary forms, with or without 55458a63bSKristof Provost * modification, are permitted provided that the following conditions 65458a63bSKristof Provost * are met: 75458a63bSKristof Provost * 1. Redistributions of source code must retain the above copyright 85458a63bSKristof Provost * notice, this list of conditions and the following disclaimer. 95458a63bSKristof Provost * 2. Redistributions in binary form must reproduce the above copyright 105458a63bSKristof Provost * notice, this list of conditions and the following disclaimer in the 115458a63bSKristof Provost * documentation and/or other materials provided with the distribution. 125458a63bSKristof Provost * 135458a63bSKristof Provost * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 145458a63bSKristof Provost * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 155458a63bSKristof Provost * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 165458a63bSKristof Provost * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 175458a63bSKristof Provost * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 185458a63bSKristof Provost * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 195458a63bSKristof Provost * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 205458a63bSKristof Provost * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 215458a63bSKristof Provost * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 225458a63bSKristof Provost * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 235458a63bSKristof Provost * SUCH DAMAGE. 245458a63bSKristof Provost * 255458a63bSKristof Provost * $FreeBSD$ 265458a63bSKristof Provost */ 275458a63bSKristof Provost 28*7bde621bSKristof Provost #include <sys/param.h> 295458a63bSKristof Provost #include <sys/ioctl.h> 305458a63bSKristof Provost #include <sys/linker.h> 315458a63bSKristof Provost #include <sys/module.h> 325458a63bSKristof Provost #include <sys/socket.h> 335458a63bSKristof Provost #include <sys/types.h> 345458a63bSKristof Provost 355458a63bSKristof Provost #include <net/if.h> 365458a63bSKristof Provost 37*7bde621bSKristof Provost #include <errno.h> 385458a63bSKristof Provost #include <fcntl.h> 395458a63bSKristof Provost #include <stdio.h> 40*7bde621bSKristof Provost #include <strings.h> 415458a63bSKristof Provost 425458a63bSKristof Provost #include <atf-c.h> 435458a63bSKristof Provost 445458a63bSKristof Provost ATF_TC(params); 455458a63bSKristof Provost ATF_TC_HEAD(params, tc) 465458a63bSKristof Provost { 475458a63bSKristof Provost atf_tc_set_md_var(tc, "require.user", "root"); 485458a63bSKristof Provost } 495458a63bSKristof Provost 505458a63bSKristof Provost ATF_TC_BODY(params, tc) 515458a63bSKristof Provost { 525458a63bSKristof Provost struct ifreq ifr; 535458a63bSKristof Provost int s; 545458a63bSKristof Provost 555458a63bSKristof Provost s = kldload("if_epair"); 56*7bde621bSKristof Provost if (s != 0 && errno != EEXIST) 575458a63bSKristof Provost atf_tc_fail("Failed to load if_epair"); 585458a63bSKristof Provost 595458a63bSKristof Provost s = socket(AF_INET, SOCK_DGRAM, 0); 605458a63bSKristof Provost if (s < 0) 615458a63bSKristof Provost atf_tc_fail("Failed to create socket"); 625458a63bSKristof Provost 635458a63bSKristof Provost bzero(&ifr, sizeof(ifr)); 645458a63bSKristof Provost ifr.ifr_data = (caddr_t)-1; 655458a63bSKristof Provost (void) strlcpy(ifr.ifr_name, "epair", sizeof(ifr.ifr_name)); 665458a63bSKristof Provost 675458a63bSKristof Provost ioctl(s, SIOCIFCREATE2, &ifr); 685458a63bSKristof Provost } 695458a63bSKristof Provost 705458a63bSKristof Provost ATF_TP_ADD_TCS(tp) 715458a63bSKristof Provost { 725458a63bSKristof Provost ATF_TP_ADD_TC(tp, params); 735458a63bSKristof Provost 745458a63bSKristof Provost return (atf_no_error()); 755458a63bSKristof Provost } 76