xref: /freebsd/tests/sys/net/if_epair.c (revision b3e7694832e81d7a904a10f525f8797b753bf0d3)
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 
267bde621bSKristof Provost #include <sys/param.h>
275458a63bSKristof Provost #include <sys/ioctl.h>
285458a63bSKristof Provost #include <sys/linker.h>
295458a63bSKristof Provost #include <sys/module.h>
305458a63bSKristof Provost #include <sys/socket.h>
315458a63bSKristof Provost #include <sys/types.h>
325458a63bSKristof Provost 
335458a63bSKristof Provost #include <net/if.h>
345458a63bSKristof Provost 
357bde621bSKristof Provost #include <errno.h>
365458a63bSKristof Provost #include <fcntl.h>
375458a63bSKristof Provost #include <stdio.h>
387bde621bSKristof Provost #include <strings.h>
395458a63bSKristof Provost 
405458a63bSKristof Provost #include <atf-c.h>
418ccf5032SOlivier Cochard #include "freebsd_test_suite/macros.h"
425458a63bSKristof Provost 
435458a63bSKristof Provost ATF_TC(params);
ATF_TC_HEAD(params,tc)445458a63bSKristof Provost ATF_TC_HEAD(params, tc)
455458a63bSKristof Provost {
465458a63bSKristof Provost         atf_tc_set_md_var(tc, "require.user", "root");
475458a63bSKristof Provost }
485458a63bSKristof Provost 
ATF_TC_BODY(params,tc)495458a63bSKristof Provost ATF_TC_BODY(params, tc)
505458a63bSKristof Provost {
515458a63bSKristof Provost 	struct ifreq ifr;
525458a63bSKristof Provost 	int s;
535458a63bSKristof Provost 
548ccf5032SOlivier Cochard 	kldload("if_epair");
558ccf5032SOlivier Cochard 	ATF_REQUIRE_KERNEL_MODULE("if_epair");
565458a63bSKristof Provost 
575458a63bSKristof Provost 	s = socket(AF_INET, SOCK_DGRAM, 0);
585458a63bSKristof Provost 	if (s < 0)
595458a63bSKristof Provost 		atf_tc_fail("Failed to create socket");
605458a63bSKristof Provost 
615458a63bSKristof Provost         bzero(&ifr, sizeof(ifr));
625458a63bSKristof Provost 	ifr.ifr_data = (caddr_t)-1;
635458a63bSKristof Provost         (void) strlcpy(ifr.ifr_name, "epair", sizeof(ifr.ifr_name));
645458a63bSKristof Provost 
65*942d05e3SGleb Smirnoff 	if (ioctl(s, SIOCIFCREATE2, &ifr) < 0)
66*942d05e3SGleb Smirnoff 		atf_tc_fail("Failed to create interface");
67*942d05e3SGleb Smirnoff 
68*942d05e3SGleb Smirnoff 	if (ioctl(s, SIOCIFDESTROY, &ifr) < 0)
69*942d05e3SGleb Smirnoff 		atf_tc_fail("Failed to destroy interface");
705458a63bSKristof Provost }
715458a63bSKristof Provost 
ATF_TP_ADD_TCS(tp)725458a63bSKristof Provost ATF_TP_ADD_TCS(tp)
735458a63bSKristof Provost {
745458a63bSKristof Provost         ATF_TP_ADD_TC(tp, params);
755458a63bSKristof Provost 
765458a63bSKristof Provost 	return (atf_no_error());
775458a63bSKristof Provost }
78