xref: /netbsd-src/sys/rump/net/lib/libtun/tun_component.c (revision 6dc1297521c9a83bdfc2a2df0eaaafd967fbd3aa)
1*6dc12975Sozaki-r /*	$NetBSD: tun_component.c,v 1.1 2016/09/05 02:25:38 ozaki-r Exp $	*/
2*6dc12975Sozaki-r 
3*6dc12975Sozaki-r /*
4*6dc12975Sozaki-r  * Copyright (c) 2016 Internet Initiative Japan Inc.
5*6dc12975Sozaki-r  * All Rights Reserved.
6*6dc12975Sozaki-r  *
7*6dc12975Sozaki-r  * Redistribution and use in source and binary forms, with or without
8*6dc12975Sozaki-r  * modification, are permitted provided that the following conditions
9*6dc12975Sozaki-r  * are met:
10*6dc12975Sozaki-r  * 1. Redistributions of source code must retain the above copyright
11*6dc12975Sozaki-r  *    notice, this list of conditions and the following disclaimer.
12*6dc12975Sozaki-r  * 2. Redistributions in binary form must reproduce the above copyright
13*6dc12975Sozaki-r  *    notice, this list of conditions and the following disclaimer in the
14*6dc12975Sozaki-r  *    documentation and/or other materials provided with the distribution.
15*6dc12975Sozaki-r  *
16*6dc12975Sozaki-r  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
17*6dc12975Sozaki-r  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18*6dc12975Sozaki-r  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19*6dc12975Sozaki-r  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20*6dc12975Sozaki-r  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21*6dc12975Sozaki-r  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22*6dc12975Sozaki-r  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23*6dc12975Sozaki-r  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24*6dc12975Sozaki-r  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25*6dc12975Sozaki-r  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26*6dc12975Sozaki-r  * SUCH DAMAGE.
27*6dc12975Sozaki-r  */
28*6dc12975Sozaki-r 
29*6dc12975Sozaki-r #include <sys/cdefs.h>
30*6dc12975Sozaki-r __KERNEL_RCSID(0, "$NetBSD: tun_component.c,v 1.1 2016/09/05 02:25:38 ozaki-r Exp $");
31*6dc12975Sozaki-r 
32*6dc12975Sozaki-r #include <sys/param.h>
33*6dc12975Sozaki-r #include <sys/device.h>
34*6dc12975Sozaki-r #include <sys/stat.h>
35*6dc12975Sozaki-r 
36*6dc12975Sozaki-r #include <rump-sys/kern.h>
37*6dc12975Sozaki-r #include <rump-sys/vfs.h>
38*6dc12975Sozaki-r 
39*6dc12975Sozaki-r #include "ioconf.h"
40*6dc12975Sozaki-r 
RUMP_COMPONENT(RUMP_COMPONENT_NET_IF)41*6dc12975Sozaki-r RUMP_COMPONENT(RUMP_COMPONENT_NET_IF)
42*6dc12975Sozaki-r {
43*6dc12975Sozaki-r 	extern const struct cdevsw tun_cdevsw;
44*6dc12975Sozaki-r 	extern devmajor_t tun_bmajor, tun_cmajor;
45*6dc12975Sozaki-r 	int error;
46*6dc12975Sozaki-r 
47*6dc12975Sozaki-r 	error = devsw_attach("tun", NULL, &tun_bmajor,
48*6dc12975Sozaki-r 	    &tun_cdevsw, &tun_cmajor);
49*6dc12975Sozaki-r 	if (error != 0)
50*6dc12975Sozaki-r 		panic("tun devsw attach failed: %d", error);
51*6dc12975Sozaki-r 
52*6dc12975Sozaki-r 	error = rump_vfs_makeonedevnode(S_IFCHR, "/dev/tun", tun_cmajor,
53*6dc12975Sozaki-r 	    0xfffff);
54*6dc12975Sozaki-r 	if (error != 0)
55*6dc12975Sozaki-r 		panic("cannot create tun device node: %d", error);
56*6dc12975Sozaki-r 
57*6dc12975Sozaki-r 	error = rump_vfs_makedevnodes(S_IFCHR, "/dev/tun", '0', tun_cmajor,
58*6dc12975Sozaki-r 	    0, 4);
59*6dc12975Sozaki-r 	if (error != 0)
60*6dc12975Sozaki-r 		panic("cannot create tun[0-4] device node: %d", error);
61*6dc12975Sozaki-r 
62*6dc12975Sozaki-r 	devsw_detach(NULL, &tun_cdevsw);
63*6dc12975Sozaki-r }
64