| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: if_virt.c,v 1.9 2009/05/26 19:03:05 pooka Exp $ */ | | 1 | /* $NetBSD: if_virt.c,v 1.10 2009/05/27 23:41:20 pooka Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2008 Antti Kantee. All Rights Reserved. | | 4 | * Copyright (c) 2008 Antti Kantee. All Rights Reserved. |
5 | * | | 5 | * |
6 | * Redistribution and use in source and binary forms, with or without | | 6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions | | 7 | * modification, are permitted provided that the following conditions |
8 | * are met: | | 8 | * are met: |
9 | * 1. Redistributions of source code must retain the above copyright | | 9 | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. | | 10 | * notice, this list of conditions and the following disclaimer. |
11 | * 2. Redistributions in binary form must reproduce the above copyright | | 11 | * 2. Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the | | 12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. | | 13 | * documentation and/or other materials provided with the distribution. |
14 | * | | 14 | * |
| @@ -16,48 +16,49 @@ | | | @@ -16,48 +16,49 @@ |
16 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | | 16 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | | 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
18 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | | 18 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | | 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
25 | * SUCH DAMAGE. | | 25 | * SUCH DAMAGE. |
26 | */ | | 26 | */ |
27 | | | 27 | |
28 | #include <sys/cdefs.h> | | 28 | #include <sys/cdefs.h> |
29 | __KERNEL_RCSID(0, "$NetBSD: if_virt.c,v 1.9 2009/05/26 19:03:05 pooka Exp $"); | | 29 | __KERNEL_RCSID(0, "$NetBSD: if_virt.c,v 1.10 2009/05/27 23:41:20 pooka Exp $"); |
30 | | | 30 | |
31 | #include <sys/param.h> | | 31 | #include <sys/param.h> |
32 | #include <sys/condvar.h> | | 32 | #include <sys/condvar.h> |
33 | #include <sys/fcntl.h> | | 33 | #include <sys/fcntl.h> |
34 | #include <sys/kmem.h> | | 34 | #include <sys/kmem.h> |
35 | #include <sys/kthread.h> | | 35 | #include <sys/kthread.h> |
36 | #include <sys/mutex.h> | | 36 | #include <sys/mutex.h> |
37 | #include <sys/sockio.h> | | 37 | #include <sys/sockio.h> |
38 | #include <sys/socketvar.h> | | 38 | #include <sys/socketvar.h> |
39 | | | 39 | |
40 | #include <net/if.h> | | 40 | #include <net/if.h> |
41 | #include <net/if_ether.h> | | 41 | #include <net/if_ether.h> |
42 | #include <net/if_tap.h> | | 42 | #include <net/if_tap.h> |
43 | | | 43 | |
44 | #include <netinet/in.h> | | 44 | #include <netinet/in.h> |
45 | #include <netinet/in_var.h> | | 45 | #include <netinet/in_var.h> |
46 | | | 46 | |
47 | #include <rump/rump.h> | | 47 | #include <rump/rump.h> |
48 | #include <rump/rumpuser.h> | | 48 | #include <rump/rumpuser.h> |
49 | | | 49 | |
50 | #include "rump_private.h" | | 50 | #include "rump_private.h" |
| | | 51 | #include "rump_net_private.h" |
51 | | | 52 | |
52 | /* | | 53 | /* |
53 | * Virtual interface for userspace purposes. Uses tap(4) to | | 54 | * Virtual interface for userspace purposes. Uses tap(4) to |
54 | * interface with the kernel and just simply shovels data | | 55 | * interface with the kernel and just simply shovels data |
55 | * to/from /dev/tap. | | 56 | * to/from /dev/tap. |
56 | */ | | 57 | */ |
57 | | | 58 | |
58 | #define VIRTIF_BASE "virt" | | 59 | #define VIRTIF_BASE "virt" |
59 | | | 60 | |
60 | static int virtif_init(struct ifnet *); | | 61 | static int virtif_init(struct ifnet *); |
61 | static int virtif_ioctl(struct ifnet *, u_long, void *); | | 62 | static int virtif_ioctl(struct ifnet *, u_long, void *); |
62 | static void virtif_start(struct ifnet *); | | 63 | static void virtif_start(struct ifnet *); |
63 | static void virtif_stop(struct ifnet *, int); | | 64 | static void virtif_stop(struct ifnet *, int); |
| @@ -243,13 +244,59 @@ virtif_sender(void *arg) | | | @@ -243,13 +244,59 @@ virtif_sender(void *arg) |
243 | io[i].iov_base = mtod(m, void *); | | 244 | io[i].iov_base = mtod(m, void *); |
244 | io[i].iov_len = m->m_len; | | 245 | io[i].iov_len = m->m_len; |
245 | m = m->m_next; | | 246 | m = m->m_next; |
246 | } | | 247 | } |
247 | if (i == 16) | | 248 | if (i == 16) |
248 | panic("lazy bum"); | | 249 | panic("lazy bum"); |
249 | rumpuser_writev(sc->sc_tapfd, io, i, &error); | | 250 | rumpuser_writev(sc->sc_tapfd, io, i, &error); |
250 | m_freem(m0); | | 251 | m_freem(m0); |
251 | mutex_enter(&sc->sc_sendmtx); | | 252 | mutex_enter(&sc->sc_sendmtx); |
252 | } | | 253 | } |
253 | | | 254 | |
254 | mutex_exit(softnet_lock); | | 255 | mutex_exit(softnet_lock); |
255 | } | | 256 | } |
| | | 257 | |
| | | 258 | /* |
| | | 259 | * dummyif is a nada-interface. |
| | | 260 | * As it requires nothing external, it can be used for testing |
| | | 261 | * interface configuration. |
| | | 262 | */ |
| | | 263 | static int dummyif_init(struct ifnet *); |
| | | 264 | static void dummyif_start(struct ifnet *); |
| | | 265 | |
| | | 266 | void |
| | | 267 | rump_dummyif_create() |
| | | 268 | { |
| | | 269 | struct ifnet *ifp; |
| | | 270 | struct ethercom *ec; |
| | | 271 | uint8_t enaddr[ETHER_ADDR_LEN] = { 0xb2, 0x0a, 0x00, 0x0b, 0x0e, 0x01 }; |
| | | 272 | |
| | | 273 | enaddr[2] = arc4random() & 0xff; |
| | | 274 | enaddr[5] = arc4random() & 0xff; |
| | | 275 | |
| | | 276 | ec = kmem_zalloc(sizeof(*ec), KM_SLEEP); |
| | | 277 | |
| | | 278 | ifp = &ec->ec_if; |
| | | 279 | strlcpy(ifp->if_xname, "dummy0", sizeof(ifp->if_xname)); |
| | | 280 | ifp->if_softc = ifp; |
| | | 281 | ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; |
| | | 282 | ifp->if_init = dummyif_init; |
| | | 283 | ifp->if_ioctl = virtif_ioctl; |
| | | 284 | ifp->if_start = dummyif_start; |
| | | 285 | |
| | | 286 | if_attach(ifp); |
| | | 287 | ether_ifattach(ifp, enaddr); |
| | | 288 | } |
| | | 289 | |
| | | 290 | static int |
| | | 291 | dummyif_init(struct ifnet *ifp) |
| | | 292 | { |
| | | 293 | |
| | | 294 | ifp->if_flags |= IFF_RUNNING; |
| | | 295 | return 0; |
| | | 296 | } |
| | | 297 | |
| | | 298 | static void |
| | | 299 | dummyif_start(struct ifnet *ifp) |
| | | 300 | { |
| | | 301 | |
| | | 302 | } |