hrev53076 adds 3 changesets to branch 'master'
old head: b5d233733084bfcd8e61199915d98069eed86d5b
new head: 64948daae87758e6c54bff5ce8ff7f7305fef6e0
overview:
https://git.haiku-os.org/haiku/log/?qt=range&q=64948daae877+%5Eb5d233733084
----------------------------------------------------------------------------
b110fce124c8: Add sources for my original BeOS BONE tun/tap config driver
as a starting point.
Change-Id: I9c3b1027a7fda4ab1eaced486eb2455a19571fee
[ François Revol <revol@xxxxxxx> ]
23901a75de8d: Stub out a tun/tap module from the loopback code
Not functional yet.
Change-Id: I6f7427c5fa176595927d73dd3b11b04945f66d84
[ François Revol <revol@xxxxxxx> ]
64948daae877: tun/tap: Build fixes for tun add-on
[ Alexander von Gluck IV <kallisti5@xxxxxxxxxxx> ]
----------------------------------------------------------------------------
8 files changed, 652 insertions(+)
headers/posix/net/if_tun.h | 64 ++++
headers/posix/net/if_types.h | 2 +
headers/private/net/net_tun.h | 33 ++
src/add-ons/kernel/drivers/network/tun/Jamfile | 12 +
src/add-ons/kernel/drivers/network/tun/driver.c | 335 ++++++++++++++++++++
src/add-ons/kernel/network/devices/Jamfile | 1 +
src/add-ons/kernel/network/devices/tun/Jamfile | 9 +
src/add-ons/kernel/network/devices/tun/tun.cpp | 196 ++++++++++++
############################################################################
Commit: b110fce124c8603201228da1b67119b56e41cf7e
URL: https://git.haiku-os.org/haiku/commit/?id=b110fce124c8
Author: François Revol <revol@xxxxxxx>
Date: Wed Apr 3 16:36:30 2019 UTC
Committer: Alexander von Gluck IV <kallisti5@xxxxxxxxxxx>
Commit-Date: Wed Apr 17 14:12:59 2019 UTC
Add sources for my original BeOS BONE tun/tap config driver
as a starting point.
Change-Id: I9c3b1027a7fda4ab1eaced486eb2455a19571fee
----------------------------------------------------------------------------
diff --git a/headers/posix/net/if_tun.h b/headers/posix/net/if_tun.h
new file mode 100644
index 0000000000..624ac48bba
--- /dev/null
+++ b/headers/posix/net/if_tun.h
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2003-2018 Haiku, Inc. All Rights Reserved.
+ * Distributed under the terms of the MIT License.
+ */
+
+#ifndef _NET_IF_TUN_H
+#define _NET_IF_TUN_H
+
+#include <sys/sockio.h>
+
+/*
+ * public API for tun/tap device.
+ * This API is compatible with the Linux tun/tap driver from
+ * http://vtun.sourceforge.net/tun/index.html
+ */
+
+
+/* max of each type */
+#define TUN_MAX_DEV 10
+/*255*/
+
+/* TX queue size */
+#define TUN_TXQ_SIZE 10
+
+/* Max frame size */
+#define TUN_MAX_FRAME 4096
+
+/* TUN device flags */
+#define TUN_TUN_DEV 0x0001
+#define TUN_TAP_DEV 0x0002
+#define TUN_TYPE_MASK 0x000f
+
+/* not yet*//*#define TUN_FASYNC 0x0010*/
+#define TUN_NOCHECKSUM 0x0020
+#define TUN_NO_PI 0x0040
+
+#define TUN_IFF_SET 0x1000
+
+/* Ioctl defines */
+/* XXX: NOT OFFICIAL */
+#define TUNSETNOCSUM (B_DEVICE_OP_CODES_END+0x90)
+#define TUNSETDEBUG (B_DEVICE_OP_CODES_END+0x91)
+#define TUNSETIFF (B_DEVICE_OP_CODES_END+0x92)
+
+/* get/set MAC address */
+//#define SIOCGIFHWADDR (BONE_SOCKIO_IOCTL_BASE+0x95)
+//#define SIOCSIFHWADDR (BONE_SOCKIO_IOCTL_BASE+0x96)
+
+/* TUNSETIFF ifr flags */
+#define IFF_TUN 0x0001
+#define IFF_TAP 0x0002
+#define IFF_NO_PI 0x1000
+/* XXX: fix the confusion about which *NO_PI go where ! */
+
+struct tun_pi {
+ unsigned short flags;
+ unsigned short proto;
+};
+/* tun_pi::flags */
+#define TUN_PKT_STRIP 0x0001
+
+#define TUN_DEVICE "/dev/config/tun"
+
+#endif /* __IF_TUN_H */
diff --git a/src/add-ons/kernel/drivers/network/tun/Jamfile
b/src/add-ons/kernel/drivers/network/tun/Jamfile
new file mode 100644
index 0000000000..99fb0ebad3
--- /dev/null
+++ b/src/add-ons/kernel/drivers/network/tun/Jamfile
@@ -0,0 +1,12 @@
+SubDir HAIKU_TOP src add-ons kernel drivers network tun ;
+
+UsePrivateSystemHeaders ;
+# For net_tun.h
+UsePrivateHeaders net ;
+
+KernelAddon tun_config :
+ driver.c
+ ;
+
+
+
diff --git a/src/add-ons/kernel/drivers/network/tun/driver.c
b/src/add-ons/kernel/drivers/network/tun/driver.c
new file mode 100644
index 0000000000..5eb56269ab
--- /dev/null
+++ b/src/add-ons/kernel/drivers/network/tun/driver.c
@@ -0,0 +1,335 @@
+#include <Drivers.h>
+#include <KernelExport.h>
+#include <OS.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <fsproto.h>
+#include "bone_tun.h"
+
+/*
+ * /dev/config/tun network tunnel driver for BeOS
+ * (c) 2003, mmu_man, revol@xxxxxxx
+ * licenced under MIT licence.
+ */
+
+
+const char * device_names[]={TUN_DRIVER_NAME, NULL};
+extern device_hooks tun_hooks;
+
+int32 api_version = B_CUR_DRIVER_API_VERSION;
+
+vint32 if_mod_ref_count = 0;
+bone_tun_interface_info_t *gIfaceModule = NULL;
+bone_util_info_t *gUtil = NULL;
+
+status_t init_hardware(void) {
+ dprintf("tun:init_hardware()\n");
+ return B_OK;
+}
+
+status_t init_driver(void) {
+ dprintf("tun:init_driver()\n");
+ return B_OK;
+}
+
+void uninit_driver(void) {
+ dprintf("tun:uninit_driver()\n");
+}
+
+const char **publish_devices() {
+ return device_names;
+}
+
+device_hooks *find_device(const char *name) {
+ (void)name;
+ return &tun_hooks;
+}
+
+status_t tun_open(const char *name, uint32 flags, cookie_t **cookie) {
+ status_t err = B_OK;
+ (void)name; (void)flags;
+ /* XXX: add O_NONBLOCK + FIONBIO */
+#if DEBUG > 1
+ dprintf("tun:open(%s, 0x%08lx,)\n", name, flags);
+#endif
+ err = get_module(BONE_UTIL_MOD_NAME, (struct module_info **)&gUtil);
+ if (err < B_OK)
+ return err;
+ err = get_module(TUN_INTERFACE_MODULE, (struct module_info
**)&gIfaceModule);
+ if (err < B_OK) {
+ put_module(BONE_UTIL_MOD_NAME);
+ return err;
+ }
+
+ /* XXX: FIXME, still not ok (rescan) */
+ if (atomic_add(&if_mod_ref_count, 1) < 1) /* force one more open to
keep loaded */
+ get_module(TUN_INTERFACE_MODULE, (struct module_info
**)&gIfaceModule);
+
+ *cookie = (void*)malloc(sizeof(cookie_t));
+ if (*cookie == NULL) {
+ dprintf("tun_open : error allocating cookie\n");
+ goto err0;
+ }
+ memset(*cookie, 0, sizeof(cookie_t));
+ (*cookie)->blocking_io = true;
+ return B_OK;
+
+err1:
+ dprintf("tun_open : cleanup : will free cookie\n");
+ free(*cookie);
+ *cookie = NULL;
+ put_module(TUN_INTERFACE_MODULE);
+ put_module(BONE_UTIL_MOD_NAME);
+err0:
+ return B_ERROR;
+}
+
+status_t tun_close(void *cookie) {
+ (void)cookie;
+ return B_OK;
+}
+
+status_t tun_free(cookie_t *cookie) {
+ status_t err = B_OK;
+#if DEBUG > 1
+ dprintf("tun_close()\n");
+#endif
+ if (cookie->iface)
+ err = gIfaceModule->tun_detach_driver(cookie->iface, true);
+ free(cookie);
+ atomic_add(&if_mod_ref_count, -1);
+ put_module(TUN_INTERFACE_MODULE);
+ put_module(BONE_UTIL_MOD_NAME);
+ return err;
+}
+
+status_t tun_ioctl(cookie_t *cookie, uint32 op, void *data, size_t len) {
+ ifreq_t *ifr;
+ bone_tun_if_interface_t *iface;
+ (void)cookie; (void)op; (void)data; (void)len;
+ iface = cookie->iface;
+#if DEBUG > 1
+ dprintf("tun_ioctl(%d(0x%08lx), , %d)\n", op, op, len);
+#endif
+
+ switch (op) {
+ case B_SET_NONBLOCKING_IO:
+ cookie->blocking_io = false;
+ return B_OK;
+ case B_SET_BLOCKING_IO:
+ cookie->blocking_io = true;
+ return B_OK;
+ case TUNSETNOCSUM:
+ return B_OK;//EOPNOTSUPP;
+ case TUNSETDEBUG:
+ return B_OK;//EOPNOTSUPP;
+ case TUNSETIFF:
+ if (data == NULL)
+ return EINVAL;
+ ifr = (ifreq_t *)data;
+
+ iface = gIfaceModule->tun_reuse_or_create(ifr, cookie);
+ if (iface != NULL) {
+ dprintf("tun: new tunnel created: %s, flags:
0x%08lx\n", ifr->ifr_name, iface->flags);
+ return B_OK;
+ } else
+ dprintf("tun: can't allocate a new tunnel!\n");
+ break;
+
+ case SIOCGIFHWADDR:
+ if (data == NULL)
+ return EINVAL;
+ ifr = (ifreq_t *)data;
+ if (iface == NULL)
+ return EINVAL;
+ if (strncmp(ifr->ifr_name, iface->ifn->if_name, IFNAMSIZ) != 0)
+ return EINVAL;
+ memcpy(ifr->ifr_hwaddr, iface->fakemac.octet, 6);
+ return B_OK;
+ case SIOCSIFHWADDR:
+ if (data == NULL)
+ return EINVAL;
+ ifr = (ifreq_t *)data;
+ if (iface == NULL)
+ return EINVAL;
+ if (strncmp(ifr->ifr_name, iface->ifn->if_name, IFNAMSIZ) != 0)
+ return EINVAL;
+ memcpy(iface->fakemac.octet, ifr->ifr_hwaddr, 6);
+ return B_OK;
+
+ }
+ return B_ERROR;
+}
+
+status_t tun_read(cookie_t *cookie, off_t position, void *data, size_t
*numbytes) {
+ bone_data_t *bdata;
+ uint32 got;
+ ssize_t pktsize;
+ if (cookie->iface == NULL)
+ return EBUSY;
+
+ //if ((pktsize = gUtil->dequeue_fifo_data(cookie->iface->wfifo, &bdata,
B_INFINITE_TIMEOUT, false)) < 0)
+ pktsize = gUtil->dequeue_fifo_data(cookie->iface->wfifo, &bdata,
cookie->blocking_io?B_INFINITE_TIMEOUT:0LL, false);
+
+ if (pktsize < 0) {
+ *numbytes = 0;
+ return pktsize;
+ }
+#if DEBUG > 2
+ dprintf("tun: dequeue = %ld, datalen = %ld, \n", pktsize,
bdata?bdata->datalen:0);
+#endif
+ pktsize = (ssize_t)bdata->datalen;
+
+ got = gUtil->copy_from_data(bdata, 0L, data, MIN((bdata->datalen),
(*numbytes)));
+ //got = MIN((*numbytes), bdata->datalen);
+ if ((pktsize > *numbytes) && !(cookie->iface->flags & TUN_NO_PI))
+ ((struct tun_pi *)data)->flags |= TUN_PKT_STRIP;
+ gUtil->delete_data(bdata);
+#if DEBUG > 2
+ dprintf("tun: read() got %ld bytes, buf is %ld\n", got, *numbytes);
+ dump_data(bdata);
+ iovec_dump_data(bdata);
+#endif
+ *numbytes = got;
+ return B_OK;
+ERROR_EOF:
+ *numbytes = 0;
+ return B_OK;
+}
+
+status_t tun_write(cookie_t *cookie, off_t position, const void *data, size_t
*numbytes) {
+ bone_data_t *bdata = NULL;
+ void *buf;
+ status_t err = B_NO_MEMORY;
+ (void)position;
+
+ /* XXX: max for *numbytes ? */
+
+ if (cookie->iface == NULL)
+ return EBUSY;
+ bdata = gUtil->new_data();
+ if (bdata == NULL)
+ return B_NO_MEMORY;
+ buf = gUtil->falloc(*numbytes);
+ if (buf == NULL)
+ goto ERROR_1;
+ memcpy(buf, data, *numbytes);
+
+ if (gUtil->prepend_data(bdata, buf, *numbytes, gUtil->free) < 0) {
+ gUtil->free(buf);
+ goto ERROR_1;
+ }
+ if ((err = gUtil->enqueue_fifo_data(cookie->iface->rfifo, bdata)) <
B_OK)
+ goto ERROR_1;
+ return B_OK;
+
+ERROR_1:
+ if (bdata)
+ gUtil->delete_data(bdata);
+ return err;
+}
+
+status_t tun_select(cookie_t *cookie, uint8 event, uint32 ref, selectsync
*sync)
+{
+ status_t err = B_OK;
+#if DEBUG > 1
+ dprintf("tun: select(, %d, %ld, )\n", event, ref);
+#endif
+ if (cookie->iface == NULL)
+ return B_NO_INIT;
+ if (event > B_SELECT_EXCEPTION || !event)
+ return EINVAL;
+ err = gUtil->lock_benaphore(&cookie->iface->lock);
+ if (err < B_OK)
+ return err;
+ /* iface LOCKED */
+ if (cookie->iface->sel[event].sync)
+ err = EALREADY;
+ else {
+ bone_fifo_t *fifo = NULL;
+ switch (event) {
+ case B_SELECT_READ:
+ fifo = cookie->iface->wfifo;
+ break;
+ case B_SELECT_WRITE:
+ fifo = cookie->iface->rfifo;
+ break;
+ }
+ if (fifo) {
+ /* XXX: is it safe ??? shouldn't we dequeue(peek=true)
? */
+ err = gUtil->lock_benaphore(&fifo->lock);
+ if (err >= B_OK) {
+ bool avail;
+ switch (event) {
+ case B_SELECT_READ:
+ avail = (fifo->current_bytes > 1);
+ break;
+ case B_SELECT_WRITE:
+ avail = ((fifo->max_bytes -
fifo->current_bytes) > cookie->iface->ifn->if_mtu);
+ break;
+ }
+ /* check if we don't already have the event */
+ if (avail) {
+ notify_select_event(sync, ref);
+ }
+ else {
+ cookie->iface->sel[event].sync = sync;
+ cookie->iface->sel[event].ref = ref;
+ }
+ gUtil->unlock_benaphore(&fifo->lock);
+ }
+ } else {
+ cookie->iface->sel[event].sync = sync;
+ cookie->iface->sel[event].ref = ref;
+ }
+ }
+ gUtil->unlock_benaphore(&cookie->iface->lock);
+ /* iface UNLOCKED */
+ return err;
+}
+status_t tun_deselect(cookie_t *cookie, uint8 event, selectsync *sync)
+{
+ status_t err = B_OK;
+#if DEBUG > 1
+ dprintf("tun: deselect(, %d, )\n", event);
+#endif
+ if (cookie->iface == NULL)
+ return B_NO_INIT;
+ if (event > B_SELECT_EXCEPTION || !event)
+ return EINVAL;
+ err = gUtil->lock_benaphore(&cookie->iface->lock);
+ if (err < B_OK)
+ return err;
+ cookie->iface->sel[event].sync = NULL;
+ cookie->iface->sel[event].ref = 0;
+ gUtil->unlock_benaphore(&cookie->iface->lock);
+ /* iface LOCKED */
+ return B_OK;
+}
+status_t tun_readv(cookie_t *cookie, off_t position, const iovec *vec, size_t
count, size_t *numBytes)
+{
+ dprintf("tun: readv(, %Ld, , %ld)\n", position, count);
+ return EOPNOTSUPP;
+}
+status_t tun_writev(cookie_t *cookie, off_t position, const iovec *vec, size_t
count, size_t *numBytes)
+{
+ dprintf("tun: writev(, %Ld, , %ld)\n", position, count);
+ return EOPNOTSUPP;
+}
+
+device_hooks tun_hooks={
+ (device_open_hook)tun_open,
+ tun_close,
+ (device_free_hook)tun_free,
+ (device_control_hook)tun_ioctl,
+ (device_read_hook)tun_read,
+ (device_write_hook)tun_write,
+ (device_select_hook)tun_select,
+ (device_deselect_hook)tun_deselect,
+ (device_readv_hook)tun_readv,
+ (device_writev_hook)tun_writev
+};
############################################################################
Commit: 23901a75de8d0f2b1b32333ee037d36665545870
URL: https://git.haiku-os.org/haiku/commit/?id=23901a75de8d
Author: François Revol <revol@xxxxxxx>
Date: Wed Apr 3 16:37:30 2019 UTC
Committer: Alexander von Gluck IV <kallisti5@xxxxxxxxxxx>
Commit-Date: Wed Apr 17 14:12:59 2019 UTC
Stub out a tun/tap module from the loopback code
Not functional yet.
Change-Id: I6f7427c5fa176595927d73dd3b11b04945f66d84
----------------------------------------------------------------------------
diff --git a/headers/private/net/net_tun.h b/headers/private/net/net_tun.h
new file mode 100644
index 0000000000..11385aa4a2
--- /dev/null
+++ b/headers/private/net/net_tun.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2008, Haiku, Inc. All Rights Reserved.
+ * This file may be used under the terms of the MIT License.
+ */
+#ifndef NET_TUN_H
+#define NET_TUN_H
+
+
+#include <sys/socket.h>
+#include <net_device.h>
+
+
+// name of the kernel tun interface
+#define NET_TUN_MODULE_NAME "network/devices/tun/v1"
+
+
+struct tun_device : net_device {
+ //queue
+ /*
+ int fd;
+ uint32 frame_size;*/
+};
+
+
+
+struct tun_module_info {
+ struct net_device_module_info;
+
+ status_t (*tun_read)(net_device* device, net_buffer* buffer);
+ status_t (*tun_write)(net_device* device, net_buffer** _buffer);
+};
+
+#endif // NET_TUN_H
diff --git a/src/add-ons/kernel/network/devices/tun/Jamfile
b/src/add-ons/kernel/network/devices/tun/Jamfile
new file mode 100644
index 0000000000..87976f35ea
--- /dev/null
+++ b/src/add-ons/kernel/network/devices/tun/Jamfile
@@ -0,0 +1,9 @@
+SubDir HAIKU_TOP src add-ons kernel network devices tun ;
+
+UsePrivateKernelHeaders ;
+UsePrivateHeaders net ;
+
+KernelAddon tun :
+ tun.cpp
+;
+
diff --git a/src/add-ons/kernel/network/devices/tun/tun.cpp
b/src/add-ons/kernel/network/devices/tun/tun.cpp
new file mode 100644
index 0000000000..298fb14196
--- /dev/null
+++ b/src/add-ons/kernel/network/devices/tun/tun.cpp
@@ -0,0 +1,196 @@
+/*
+ * Copyright 2006-2007, Haiku, Inc. All Rights Reserved.
+ * Distributed under the terms of the MIT License.
+ *
+ * Authors:
+ * Axel Dörfler, axeld@xxxxxxxxxxxxxxxx
+ */
+
+
+#include <net_buffer.h>
+#include <net_device.h>
+#include <net_stack.h>
+
+#include <KernelExport.h>
+
+#include <net/if.h>
+#include <net/if_types.h>
+#include <net/if_media.h>
+#include <new>
+#include <stdlib.h>
+#include <string.h>
+
+
+
+struct net_buffer_module_info *gBufferModule;
+static struct net_stack_module_info *sStackModule;
+
+//static mutex sListLock;
+//static DoublyLinkedList<ethernet_device> sCheckList;
+
+
+// #pragma mark -
+
+
+status_t
+tun_init(const char *name, net_device **_device)
+{
+ tun_device *device;
+ status_t status;
+
+ if (strncmp(name, "tun", 3)
+ && strncmp(name, "tap", 3)
+ && strncmp(name, "dns", 3)) /* iodine uses that */
+ return B_BAD_VALUE;
+
+ device = new (std::nothrow) tun_device;
+ if (device == NULL) {
+ return B_NO_MEMORY;
+ }
+
+ memset(device, 0, sizeof(tun_device));
+
+ strcpy(device->name, name);
+ device->flags = IFF_LINK;
+ device->type = strncmp(name, "tap", 3) ? IFT_TUN : IFT_ETHER;
+ device->mtu = 16384;
+ device->media = IFM_ACTIVE;
+
+ *_device = device;
+ return B_OK;
+}
+
+
+status_t
+tun_uninit(net_device *_device)
+{
+ tun_device *device = (tun_device *)_device;
+
+ put_module(NET_STACK_MODULE_NAME);
+ put_module(NET_BUFFER_MODULE_NAME);
+ delete device;
+
+ return B_OK;
+}
+
+
+status_t
+tun_up(net_device *device)
+{
+ return B_OK;
+}
+
+
+void
+tun_down(net_device *device)
+{
+}
+
+
+status_t
+tun_control(net_device *device, int32 op, void *argument,
+ size_t length)
+{
+ return B_BAD_VALUE;
+}
+
+
+status_t
+tun_send_data(net_device *device, net_buffer *buffer)
+{
+ return sStackModule->device_enqueue_buffer(device, buffer);
+}
+
+
+status_t
+tun_set_mtu(net_device *device, size_t mtu)
+{
+ if (mtu > 65536 || mtu < 16)
+ return B_BAD_VALUE;
+
+ device->mtu = mtu;
+ return B_OK;
+}
+
+
+status_t
+tun_set_promiscuous(net_device *device, bool promiscuous)
+{
+ return EOPNOTSUPP;
+}
+
+
+status_t
+tun_set_media(net_device *device, uint32 media)
+{
+ return EOPNOTSUPP;
+}
+
+
+status_t
+tun_add_multicast(net_device *device, const sockaddr *address)
+{
+ return B_OK;
+}
+
+
+status_t
+tun_remove_multicast(net_device *device, const sockaddr *address)
+{
+ return B_OK;
+}
+
+
+static status_t
+tun_std_ops(int32 op, ...)
+{
+ switch (op) {
+ case B_MODULE_INIT:
+ status_t status = get_module(NET_STACK_MODULE_NAME,
+ (module_info **)&sStackModule);
+ if (status < B_OK)
+ return status;
+
+ status = get_module(NET_BUFFER_MODULE_NAME,
+ (module_info **)&gBufferModule);
+ if (status < B_OK) {
+ put_module(NET_STACK_MODULE_NAME);
+ return status;
+ }
+
+ case B_MODULE_UNINIT:
+ put_module(NET_BUFFER_MODULE_NAME);
+ put_module(NET_STACK_MODULE_NAME);
+ return B_OK;
+
+ default:
+ return B_ERROR;
+ }
+}
+
+
+net_device_module_info sLoopbackModule = {
+ {
+ "network/devices/tun/v1",
+ 0,
+ tun_std_ops
+ },
+ tun_init,
+ tun_uninit,
+ tun_up,
+ tun_down,
+ tun_control,
+ tun_send_data,
+ NULL, // receive_data
+ tun_set_mtu,
+ tun_set_promiscuous,
+ tun_set_media,
+ tun_add_multicast,
+ tun_remove_multicast,
+
+};
+
+module_info *modules[] = {
+ (module_info *)&sLoopbackModule,
+ NULL
+};
############################################################################
Revision: hrev53076
Commit: 64948daae87758e6c54bff5ce8ff7f7305fef6e0
URL: https://git.haiku-os.org/haiku/commit/?id=64948daae877
Author: Alexander von Gluck IV <kallisti5@xxxxxxxxxxx>
Date: Wed Apr 17 14:07:44 2019 UTC
tun/tap: Build fixes for tun add-on
----------------------------------------------------------------------------
diff --git a/headers/posix/net/if_types.h b/headers/posix/net/if_types.h
index fda4534f03..f95dd24379 100644
--- a/headers/posix/net/if_types.h
+++ b/headers/posix/net/if_types.h
@@ -12,5 +12,7 @@
#define IFT_LOOP 0x18
#define IFT_SLIP 0x1c
#define IFT_MODEM 0x30
+#define IFT_TUN 0x40
+
#endif /* _NET_IF_TYPES_H */
diff --git a/src/add-ons/kernel/network/devices/Jamfile
b/src/add-ons/kernel/network/devices/Jamfile
index 78eb1fde15..a7147d8944 100644
--- a/src/add-ons/kernel/network/devices/Jamfile
+++ b/src/add-ons/kernel/network/devices/Jamfile
@@ -3,4 +3,5 @@ SubDir HAIKU_TOP src add-ons kernel network devices ;
SubInclude HAIKU_TOP src add-ons kernel network devices dialup ;
SubInclude HAIKU_TOP src add-ons kernel network devices ethernet ;
SubInclude HAIKU_TOP src add-ons kernel network devices loopback ;
+SubInclude HAIKU_TOP src add-ons kernel network devices tun ;
diff --git a/src/add-ons/kernel/network/devices/tun/tun.cpp
b/src/add-ons/kernel/network/devices/tun/tun.cpp
index 298fb14196..4fa665a919 100644
--- a/src/add-ons/kernel/network/devices/tun/tun.cpp
+++ b/src/add-ons/kernel/network/devices/tun/tun.cpp
@@ -6,6 +6,7 @@
* Axel Dörfler, axeld@xxxxxxxxxxxxxxxx
*/
+#include <net_tun.h>
#include <net_buffer.h>
#include <net_device.h>
@@ -36,7 +37,6 @@ status_t
tun_init(const char *name, net_device **_device)
{
tun_device *device;
- status_t status;
if (strncmp(name, "tun", 3)
&& strncmp(name, "tap", 3)
@@ -146,23 +146,23 @@ tun_std_ops(int32 op, ...)
{
switch (op) {
case B_MODULE_INIT:
+ {
status_t status = get_module(NET_STACK_MODULE_NAME,
(module_info **)&sStackModule);
if (status < B_OK)
return status;
-
status = get_module(NET_BUFFER_MODULE_NAME,
(module_info **)&gBufferModule);
if (status < B_OK) {
put_module(NET_STACK_MODULE_NAME);
return status;
}
-
+ return B_OK;
+ }
case B_MODULE_UNINIT:
put_module(NET_BUFFER_MODULE_NAME);
put_module(NET_STACK_MODULE_NAME);
return B_OK;
-
default:
return B_ERROR;
}