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 287bde621bSKristof 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 377bde621bSKristof Provost #include <errno.h> 385458a63bSKristof Provost #include <fcntl.h> 395458a63bSKristof Provost #include <stdio.h> 407bde621bSKristof Provost #include <strings.h> 415458a63bSKristof Provost 425458a63bSKristof Provost #include <atf-c.h> 438ccf5032SOlivier Cochard #include "freebsd_test_suite/macros.h" 445458a63bSKristof Provost 455458a63bSKristof Provost ATF_TC(params); 465458a63bSKristof Provost ATF_TC_HEAD(params, tc) 475458a63bSKristof Provost { 485458a63bSKristof Provost atf_tc_set_md_var(tc, "require.user", "root"); 495458a63bSKristof Provost } 505458a63bSKristof Provost 515458a63bSKristof Provost ATF_TC_BODY(params, tc) 525458a63bSKristof Provost { 535458a63bSKristof Provost struct ifreq ifr; 545458a63bSKristof Provost int s; 555458a63bSKristof Provost 568ccf5032SOlivier Cochard kldload("if_epair"); 578ccf5032SOlivier Cochard ATF_REQUIRE_KERNEL_MODULE("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 67*942d05e3SGleb Smirnoff if (ioctl(s, SIOCIFCREATE2, &ifr) < 0) 68*942d05e3SGleb Smirnoff atf_tc_fail("Failed to create interface"); 69*942d05e3SGleb Smirnoff 70*942d05e3SGleb Smirnoff if (ioctl(s, SIOCIFDESTROY, &ifr) < 0) 71*942d05e3SGleb Smirnoff atf_tc_fail("Failed to destroy interface"); 725458a63bSKristof Provost } 735458a63bSKristof Provost 745458a63bSKristof Provost ATF_TP_ADD_TCS(tp) 755458a63bSKristof Provost { 765458a63bSKristof Provost ATF_TP_ADD_TC(tp, params); 775458a63bSKristof Provost 785458a63bSKristof Provost return (atf_no_error()); 795458a63bSKristof Provost } 80