From 10fcf53bea597833c58f8d1da70b19582328326e Mon Sep 17 00:00:00 2001 From: sonic Date: Fri, 5 Nov 2010 16:58:01 +0000 Subject: [PATCH] Untied tap.device from unixio.hidd git-svn-id: https://svn.aros.org/svn/aros/trunk/AROS@35151 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- arch/all-unix/devs/networks/tap/command.c | 14 +- arch/all-unix/devs/networks/tap/init.c | 188 +++++++++++++++++++++----- arch/all-unix/devs/networks/tap/iotask.c | 173 +++++++++++++----------- arch/all-unix/devs/networks/tap/mmakefile.src | 9 +- arch/all-unix/devs/networks/tap/tap.h | 61 ++++++--- 5 files changed, 301 insertions(+), 144 deletions(-) diff --git a/arch/all-unix/devs/networks/tap/command.c b/arch/all-unix/devs/networks/tap/command.c index 970dbcf040..74e15ea4fc 100644 --- a/arch/all-unix/devs/networks/tap/command.c +++ b/arch/all-unix/devs/networks/tap/command.c @@ -1,11 +1,15 @@ /* * tap - TUN/TAP network driver for AROS * Copyright (c) 2007 Robert Norris. All rights reserved. + * Copyright © 2010, The AROS Development Team. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the same terms as AROS itself. */ +#define DEBUG 0 +#define DWRITE(x) + #include "tap.h" static const UWORD tap_supported_commands[] = { @@ -123,7 +127,7 @@ static BOOL tap_read(struct IOSana2Req *req, struct tap_unit *unit) { static BOOL tap_write(struct IOSana2Req *req, struct tap_unit *unit) { if (!(unit->flags & tu_ONLINE)) { - D(bug("[tap] [%d] not online\n", unit->num)); + DWRITE(bug("[tap] [%d] not online\n", unit->num)); req->ios2_Req.io_Error = S2ERR_OUTOFSERVICE; req->ios2_WireError = S2WERR_UNIT_OFFLINE; @@ -132,13 +136,9 @@ static BOOL tap_write(struct IOSana2Req *req, struct tap_unit *unit) { } req->ios2_Req.io_Flags &= ~IOF_QUICK; - PutMsg(&(unit->write_queue), (struct Message *) req); - - D(bug("[tap] [%d] queued write request\n", unit->num)); + PutMsg(unit->write_queue, (struct Message *) req); - /* tell the iotask to write */ - /* XXX just use the write queue signal for this */ - Signal((struct Task *) unit->iotask, 1 << unit->write_signal); + DWRITE(bug("[tap] [%d] queued write request\n", unit->num)); return FALSE; } diff --git a/arch/all-unix/devs/networks/tap/init.c b/arch/all-unix/devs/networks/tap/init.c index 62caa5ab00..e3a38a4afc 100644 --- a/arch/all-unix/devs/networks/tap/init.c +++ b/arch/all-unix/devs/networks/tap/init.c @@ -1,43 +1,85 @@ /* * tap - TUN/TAP network driver for AROS * Copyright (c) 2007 Robert Norris. All rights reserved. + * Copyright © 2010, The AROS Development Team. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the same terms as AROS itself. */ +#include + #include "tap.h" #include +#include + +#include + +static const char *libc_symbols[] = { + "open", + "close", + "ioctl", + "fcntl", + "poll", + "read", + "write", + "getpid", +#ifdef HOST_OS_linux + "__errno_location", +#else + "__error", +#endif + NULL +}; -HIDD *unixio = NULL; - -static int GM_UNIQUENAME(init)(LIBBASETYPEPTR LIBBASE) { - int i; +static int GM_UNIQUENAME(init)(LIBBASETYPEPTR TAPBase) +{ + ULONG i; D(bug("[tap] in init\n")); - unixio = (HIDD *) OOP_NewObject(NULL, CLID_Hidd_UnixIO, NULL); - if (unixio == NULL) { - kprintf("[tap] couldn't create unixio object\n"); - return FALSE; - } + KernelBase = OpenResource("kernel.resource"); + if (!KernelBase) + return FALSE; + + HostLibBase = OpenResource("hostlib.resource"); + if (!HostLibBase) + return FALSE; + + TAPBase->LibCHandle = HostLib_Open(LIBC_NAME, NULL); + if (!TAPBase->LibCHandle) + return FALSE; + + TAPBase->TAPIFace = (struct LibCInterface *)HostLib_GetInterface(TAPBase->LibCHandle, libc_symbols, &i); + if ((!TAPBase->TAPIFace) || i) + return FALSE; + + InitSemaphore(&TAPBase->sem); + TAPBase->aros_pid = TAPBase->TAPIFace->getpid(); + TAPBase->errnoPtr = TAPBase->TAPIFace->__error(); for (i = 0; i < MAX_TAP_UNITS; i ++) - LIBBASE->unit[i].num = i; + { + TAPBase->unit[i].num = i; + } return TRUE; } -static int GM_UNIQUENAME(expunge)(LIBBASETYPEPTR LIBBASE) { +static int GM_UNIQUENAME(expunge)(LIBBASETYPEPTR TAPBase) { D(bug("[tap] in expunge\n")); + if (!HostLibBase) + return TRUE; + /* XXX kill the tasks and free memory, just in case */ - if (unixio != NULL) { - OOP_DisposeObject((OOP_Object *) unixio); - unixio = NULL; - } + if (TAPBase->TAPIFace) + HostLib_DropInterface ((APTR *)TAPBase->TAPIFace); + + if (TAPBase->LibCHandle) + HostLib_Close(TAPBase->LibCHandle, NULL); return TRUE; } @@ -53,9 +95,63 @@ static const ULONG tx_tags[] = { S2_CopyFromBuff32 }; -extern void tap_iotask(void); +struct newMemList +{ + struct Node nml_Node; + UWORD nml_NumEntries; + struct MemEntry nml_ME[2]; +}; -static int GM_UNIQUENAME(open)(LIBBASETYPEPTR LIBBASE, struct IOSana2Req *req, ULONG unitnum, ULONG flags) { +#define IOTASK_STACKSIZE 16384 + +static struct Task *CreateIOTask(struct tap_base *TAPBase, struct tap_unit *unit) +{ + struct Task * newtask; + struct newMemList nml = + { + { NULL, NULL}, + 2, + { + { { MEMF_CLEAR|MEMF_PUBLIC }, sizeof(struct Task) }, + { { MEMF_CLEAR }, IOTASK_STACKSIZE } + } + }; + struct MemList *ml; + + if (NewAllocEntry((struct MemList *)&nml, &ml, NULL)) + { + struct Task *t; + + newtask = ml->ml_ME[0].me_Addr; + + newtask->tc_Node.ln_Type = NT_TASK; + newtask->tc_Node.ln_Pri = 0; /* Priority */ + newtask->tc_Node.ln_Name = unit->iotask_name; + + newtask->tc_SPReg = (APTR)((IPTR)ml->ml_ME[1].me_Addr + IOTASK_STACKSIZE); + newtask->tc_SPLower = ml->ml_ME[1].me_Addr; + newtask->tc_SPUpper = newtask->tc_SPReg; + + D(bug("[tap] IOTask stack %p - %p, SP %p\n", newtask->tc_SPLower, newtask->tc_SPUpper, newtask->tc_SPReg)); + + NewList (&newtask->tc_MemEntry); + AddHead (&newtask->tc_MemEntry, (struct Node *)ml); + + t = NewAddTaskTags(newtask, tap_iotask, NULL, TASKTAG_ARG1, TAPBase, TASKTAG_ARG2, unit, TAG_DONE); + if (!t) + { + FreeEntry (ml); + newtask = NULL; + } + } + else + newtask=NULL; + + return newtask; +} /* CreateTask */ + +static int GM_UNIQUENAME(open)(LIBBASETYPEPTR TAPBase, struct IOSana2Req *req, ULONG unitnum, ULONG flags) +{ struct TagItem *tags; BYTE error = 0; struct tap_unit *unit; @@ -81,7 +177,7 @@ static int GM_UNIQUENAME(open)(LIBBASETYPEPTR LIBBASE, struct IOSana2Req *req, U kprintf("[tap] request for unit %d, which is out of range (0..%d)\n", unitnum, MAX_TAP_UNITS-1); error = IOERR_OPENFAIL; } - unit = &(LIBBASE->unit[unitnum]); + unit = &(TAPBase->unit[unitnum]); /* allocate storage for opener state */ if (error == 0) { @@ -96,7 +192,6 @@ static int GM_UNIQUENAME(open)(LIBBASETYPEPTR LIBBASE, struct IOSana2Req *req, U /* prepare the opener port and buffer management functions */ if (error == 0) { - int i; /* pending read requests get queued up in here */ NEWLIST(&(opener->read_pending.mp_MsgList)); @@ -119,7 +214,11 @@ static int GM_UNIQUENAME(open)(LIBBASETYPEPTR LIBBASE, struct IOSana2Req *req, U D(bug("[tap] [%d] refcount is 0, opening device\n", unit->num)); /* open the tun/tap device */ - fd = Hidd_UnixIO_OpenFile(unixio, TAP_DEV_NODE, O_RDWR, 0, &ioerr); + ObtainSemaphore(&TAPBase->sem); + fd = TAPBase->TAPIFace->open(TAP_DEV_NODE, O_RDWR, 0); + ioerr = *TAPBase->errnoPtr; + ReleaseSemaphore(&TAPBase->sem); + if (fd < 0) { kprintf("[tap] couldn't open '" TAP_DEV_NODE "' (%d)\n", ioerr); error = IOERR_OPENFAIL; @@ -133,14 +232,31 @@ static int GM_UNIQUENAME(open)(LIBBASETYPEPTR LIBBASE, struct IOSana2Req *req, U ifr.ifr_flags = IFF_TAP | IFF_NO_PI; strncpy(ifr.ifr_name, unit->name, IFNAMSIZ); - if ((Hidd_UnixIO_IOControlFile(unixio, fd, TUNSETIFF, &ifr, &ioerr)) < 0) { + ObtainSemaphore(&TAPBase->sem); + error = TAPBase->TAPIFace->ioctl(fd, TUNSETIFF, &ifr); + ioerr = *TAPBase->errnoPtr; + ReleaseSemaphore(&TAPBase->sem); + + if (error == -1) { kprintf("[tap] couldn't perform TUNSETIFF on TAP device (%d)\n", ioerr); error = IOERR_OPENFAIL; } - else { - unit->fd = fd; + else + { + /* + * Own the file descriptor and enable SIGIO. + * tap device has a quirk: this works only when it + * was permormed AFTER TUNSETIFF ioctl. + */ + ObtainSemaphore(&TAPBase->sem); + TAPBase->TAPIFace->fcntl(fd, F_SETOWN, TAPBase->aros_pid); + i = TAPBase->TAPIFace->fcntl(fd, F_GETFL); + i |= O_ASYNC; + TAPBase->TAPIFace->fcntl(fd, F_SETFL, i); + ReleaseSemaphore(&TAPBase->sem); + unit->fd = fd; kprintf("[tap] unit %d attached to %s\n", unit->num, unit->name); } } @@ -174,11 +290,6 @@ static int GM_UNIQUENAME(open)(LIBBASETYPEPTR LIBBASE, struct IOSana2Req *req, U /* and for the trackers */ NEWLIST(&(unit->trackers)); - /* prepare write queue */ - NEWLIST(&(unit->write_queue.mp_MsgList)); - unit->write_queue.mp_Node.ln_Type = NT_MSGPORT; - unit->write_queue.mp_Flags = PA_IGNORE; - /* a port to sync actions with the iotask */ unit->iosyncport = CreateMsgPort(); @@ -186,11 +297,7 @@ static int GM_UNIQUENAME(open)(LIBBASETYPEPTR LIBBASE, struct IOSana2Req *req, U __sprintf(unit->iotask_name, TAP_TASK_FORMAT, (int) unit->num); /* make it fly */ - unit->iotask = CreateNewProcTags(NP_Entry, (IPTR) tap_iotask, - NP_Name, unit->iotask_name, - NP_Priority, 50, - NP_UserData, (IPTR) unit, - TAG_DONE); + unit->iotask = CreateIOTask(TAPBase, unit); /* wait until its ready to go */ WaitPort(unit->iosyncport); @@ -235,7 +342,11 @@ static int GM_UNIQUENAME(open)(LIBBASETYPEPTR LIBBASE, struct IOSana2Req *req, U /* close the nic */ if (unit->fd > 0) - Hidd_UnixIO_CloseFile(unixio, unit->fd, NULL); + { + ObtainSemaphore(&TAPBase->sem); + TAPBase->TAPIFace->close(unit->fd); + ReleaseSemaphore(&TAPBase->sem); + } /* fastest way to kill it */ memset(unit, 0, sizeof(struct tap_unit)); @@ -253,7 +364,8 @@ static int GM_UNIQUENAME(open)(LIBBASETYPEPTR LIBBASE, struct IOSana2Req *req, U return (error == 0) ? TRUE : FALSE; } -static int GM_UNIQUENAME(close)(LIBBASETYPEPTR LIBBASE, struct IOSana2Req *req) { +static int GM_UNIQUENAME(close)(LIBBASETYPEPTR TAPBase, struct IOSana2Req *req) +{ struct tap_unit *unit = (struct tap_unit *) req->ios2_Req.io_Unit; struct tap_opener *opener = (struct tap_opener *) req->ios2_BufferManagement; struct tap_tracker *tracker, *tracker_next; @@ -280,7 +392,11 @@ static int GM_UNIQUENAME(close)(LIBBASETYPEPTR LIBBASE, struct IOSana2Req *req) /* close the nic */ if (unit->fd > 0) - Hidd_UnixIO_CloseFile(unixio, unit->fd, NULL); + { + ObtainSemaphore(&TAPBase->sem); + TAPBase->TAPIFace->close(unit->fd); + ReleaseSemaphore(&TAPBase->sem); + } /* XXX return outstanding requests? */ diff --git a/arch/all-unix/devs/networks/tap/iotask.c b/arch/all-unix/devs/networks/tap/iotask.c index eb3facef96..2d14641ab2 100644 --- a/arch/all-unix/devs/networks/tap/iotask.c +++ b/arch/all-unix/devs/networks/tap/iotask.c @@ -1,15 +1,21 @@ /* * tap - TUN/TAP network driver for AROS * Copyright (c) 2007 Robert Norris. All rights reserved. + * Copyright © 2010, The AROS Development Team. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the same terms as AROS itself. */ +#include + +#include + #include "tap.h" /* this fires whenever data is waiting to be read on the tap descriptor */ -static void tap_receive(struct tap_unit *unit) { +static void tap_receive(struct tap_base *TAPBase, struct tap_unit *unit) +{ unsigned char buf[ETH_FRAME_LEN], *packet; int nread, ioerr; struct ethhdr *eth; @@ -22,9 +28,14 @@ static void tap_receive(struct tap_unit *unit) { D(bug("[tap] [io:%d] got a packet\n", unit->num)); - /* read the packet */ - nread = Hidd_UnixIO_ReadFile(unixio, unit->fd, buf, ETH_FRAME_LEN, &ioerr); - if (ioerr != 0) { + /* Try to read the packet */ + ObtainSemaphore(&TAPBase->sem); + nread = TAPBase->TAPIFace->read(unit->fd, buf, ETH_FRAME_LEN); + ioerr = *TAPBase->errnoPtr; + ReleaseSemaphore(&TAPBase->sem); + + if (nread == -1) + { D(bug("[tap] [io:%d] read failed (%d)\n", unit->num, ioerr)); return; } @@ -164,7 +175,8 @@ static void tap_receive(struct tap_unit *unit) { } /* this fires whenever we can write to the tap descriptor */ -static void tap_send(struct tap_unit *unit) { +static void tap_send(struct tap_base *TAPBase, struct tap_unit *unit) +{ struct IOSana2Req *req; int packet_length; struct tap_opener *opener; @@ -173,8 +185,11 @@ static void tap_send(struct tap_unit *unit) { int ioerr, nwritten = 0; struct tap_tracker *tracker, *tracker_next; + if (!unit->write_queue->mp_MsgList.lh_Head->ln_Succ) + return; + /* grab the first pending request */ - req = (struct IOSana2Req *) unit->write_queue.mp_MsgList.lh_Head; + req = (struct IOSana2Req *) unit->write_queue->mp_MsgList.lh_Head; eth = (struct ethhdr *) buf; @@ -222,7 +237,11 @@ static void tap_send(struct tap_unit *unit) { D(bug("[tap] [io:%d] packet type: 0x%04x\n", unit->num, AROS_BE2WORD(eth->h_proto))); /* got a viable buffer, send it out */ - nwritten = Hidd_UnixIO_WriteFile(unixio, unit->fd, buf, packet_length, &ioerr); + ObtainSemaphore(&TAPBase->sem); + nwritten = TAPBase->TAPIFace->write(unit->fd, buf, packet_length); + ioerr = *TAPBase->errnoPtr; + ReleaseSemaphore(&TAPBase->sem); + if (nwritten < 0) { D(bug("[tap] [io:%d] write failed (%d)\n", unit->num, ioerr)); req->ios2_Req.io_Error = S2ERR_NO_RESOURCES; @@ -257,38 +276,42 @@ static void tap_send(struct tap_unit *unit) { ReplyMsg((APTR) req); }; -AROS_UFH3(void, tap_iotask, - AROS_UFHA(STRPTR, argPtr, A0), - AROS_UFHA(ULONG, argSize, D0), - AROS_UFHA(struct ExecBase *, SysBase, A6)) { - AROS_USERFUNC_INIT +static void SigIOHandler(struct tap_unit *unit, void *unused) +{ + D(bug("[tap] SIGIO received\n")); + Signal(unit->iotask, 1 << unit->io_signal); +} + - struct tap_unit *unit = FindTask(NULL)->tc_UserData; - struct MsgPort *ioport, *reply_port; +void tap_iotask(struct tap_base *TAPBase, struct tap_unit *unit) +{ + struct MsgPort *reply_port; struct Message *msg; - ULONG write_signal_mask, abort_signal_mask, signal_mask, signaled; - struct uioMessage *iomsg; - ULONG mode; - BOOL write_enabled = FALSE; + ULONG write_signal_mask, abort_signal_mask, io_signal_mask, signal_mask, signaled; + APTR irq; + short write_flag = 0; D(bug("[tap] [io:%d] iotask starting up\n", unit->num)); - /* create the port for unixio to talk to us through */ - ioport = CreateMsgPort(); + /* Prepare write queue */ + unit->write_queue = CreateMsgPort(); + D(bug("[tap] Write port %p\n", unit->write_queue)); - /* make some signals, one for them to ask for writes, and one for them to - * shut us down */ - unit->write_signal = AllocSignal(-1); + /* make some signals, one of them to shut us down, and one for I/O */ unit->abort_signal = AllocSignal(-1); - write_signal_mask = 1 << unit->write_signal; + unit->io_signal = AllocSignal(-1); + write_signal_mask = 1 << unit->write_queue->mp_SigBit; abort_signal_mask = 1 << unit->abort_signal; + io_signal_mask = 1 << unit->io_signal; /* bundle all the signals together */ - signal_mask = write_signal_mask | abort_signal_mask | (1 << ioport->mp_SigBit); + signal_mask = write_signal_mask | abort_signal_mask | io_signal_mask; + D(bug("[tap] signal mask 0x%08X\n", signal_mask)); /* start waiting for read events */ /* XXX check for failure */ - Hidd_UnixIO_AsyncIO(unixio, unit->fd, vHidd_UnixIO_Terminal, ioport, vHidd_UnixIO_Read, SysBase); + irq = KrnAddIRQHandler(SIGIO, SigIOHandler, unit, NULL); + D(bug("[tap] IRQ handle %p\n", irq)); reply_port = CreateMsgPort(); msg = (struct Message *) AllocVec(sizeof(struct Message), MEMF_PUBLIC | MEMF_CLEAR); @@ -302,81 +325,73 @@ AROS_UFH3(void, tap_iotask, D(bug("[tap] [io:%d] iotask entering loop\n", unit->num)); - while (1) { - D(bug("[tap] [io:%d] waiting for an event\n", unit->num)); - - if (IsListEmpty(&(ioport->mp_MsgList))) { - signaled = Wait(signal_mask); + while (1) + { + struct pollfd pfd; - if (signaled & write_signal_mask) { - D(bug("[tap] [io:%d] write requested, enabling\n", unit->num)); - if (! write_enabled) { - Hidd_UnixIO_AsyncIO(unixio, unit->fd, vHidd_UnixIO_Terminal, ioport, vHidd_UnixIO_Write, SysBase); - write_enabled = TRUE; - } + pfd.fd = unit->fd; - continue; - } - - if (signaled & abort_signal_mask) { - D(bug("[tap] [io:%d] iotask received abort signal\n", unit->num)); - break; - } - } + do + { + int res; - if (IsListEmpty(&(ioport->mp_MsgList))) - continue; + pfd.events = POLLIN|write_flag; + pfd.revents = 0; - iomsg = (struct uioMessage *) GetMsg(ioport); - mode = iomsg->mode; - FreeMem(iomsg, sizeof(struct uioMessage)); + ObtainSemaphore(&TAPBase->sem); + res = TAPBase->TAPIFace->poll(&pfd, 1, 0); + ReleaseSemaphore(&TAPBase->sem); - D(bug("[tap] [io:%d] iotask signaled\n", unit->num)); + if (res < 0) + continue; - if (mode & vHidd_UnixIO_Read) { - D(bug("[tap] [io:%d] ready for read\n", unit->num)); - tap_receive(unit); - } + if (pfd.revents & POLLIN) + { + D(bug("[tap] [io:%d] ready for read\n", unit->num)); + tap_receive(TAPBase, unit); + } - else if (mode & vHidd_UnixIO_Write) { - D(bug("[tap] [io:%d] ready for write\n", unit->num)); - tap_send(unit); + if (pfd.revents & POLLOUT) + { + D(bug("[tap] [io:%d] ready for write\n", unit->num)); + tap_send(TAPBase, unit); - if (IsMsgPortEmpty(&(unit->write_queue))) { - D(bug("[tap] [io:%d] all packets sent, will ignore future write events\n", unit->num)); - write_enabled = FALSE; + if (IsMsgPortEmpty(unit->write_queue)) { + D(bug("[tap] [io:%d] all packets sent, will ignore future write events\n", unit->num)); + write_flag = 0; + } } - } + } while (pfd.revents & (POLLIN|POLLOUT)); - else { - D(bug("[tap] [io:%d] unknown ioevent mode 0x%02x\n", unit->num, mode)); - } + D(bug("[tap] [io:%d] waiting for an event\n", unit->num)); - D(bug("[tap] [io:%d] resetting async events\n", unit->num)); + signaled = Wait(signal_mask); - /* reset unixio to make sure we get more events. this is horribly - * inefficient, but it'll do for now until unixio gets a little love */ - /* XXX check for failure */ - Hidd_UnixIO_AbortAsyncIO(unixio, unit->fd, SysBase); - Hidd_UnixIO_AsyncIO(unixio, unit->fd, vHidd_UnixIO_Terminal, ioport, vHidd_UnixIO_Read, SysBase); - if (write_enabled) - Hidd_UnixIO_AsyncIO(unixio, unit->fd, vHidd_UnixIO_Terminal, ioport, vHidd_UnixIO_Write, SysBase); + D(bug("[tap] [io:%d] iotask signaled\n", unit->num)); + if (signaled & write_signal_mask) + { + D(bug("[tap] [io:%d] write requested, enabling\n", unit->num)); + write_flag = POLLOUT; + } + + if (signaled & abort_signal_mask) { + D(bug("[tap] [io:%d] iotask received abort signal\n", unit->num)); + break; + } D(bug("[tap] [io:%d] event processed, replying and looping\n", unit->num)); } D(bug("[tap] [io:%d] iotask exiting\n", unit->num)); - Hidd_UnixIO_AbortAsyncIO(unixio, unit->fd, SysBase); - - DeleteMsgPort(ioport); + KrnRemIRQHandler(irq); FreeSignal(unit->abort_signal); - FreeSignal(unit->write_signal); + FreeSignal(unit->io_signal); + + DeleteMsgPort(unit->write_queue); msg = (struct Message *) AllocVec(sizeof(struct Message), MEMF_PUBLIC | MEMF_CLEAR); PutMsg(unit->iosyncport, msg); FreeVec(msg); - - AROS_USERFUNC_EXIT } diff --git a/arch/all-unix/devs/networks/tap/mmakefile.src b/arch/all-unix/devs/networks/tap/mmakefile.src index ff4bda6c9e..7681ab888e 100644 --- a/arch/all-unix/devs/networks/tap/mmakefile.src +++ b/arch/all-unix/devs/networks/tap/mmakefile.src @@ -1,15 +1,12 @@ include $(TOP)/config/make.cfg -#USER_INCLUDES = -I$(GENINCDIR) - -FLAGS := $(KERNEL_CFLAGS) -I$(GENINCDIR) +USER_CFLAGS := -DHOST_OS_$(ARCH) -DAROS_ARCHITECTURE="\"$(AROS_TARGET_ARCH)-$(AROS_TARGET_CPU)\"" \ + -isystem $(GENINCDIR) $(KERNEL_INCLUDES) -nostdinc %build_module mmake=workbench-devs-tap-unix \ modname=tap modtype=device \ moduledir=Devs/Networks \ files="init command iotask" \ - cflags=$(FLAGS) \ - uselibs="oop amiga rom m hiddstubs" \ - compiler=kernel + uselibs="oop amiga rom m hiddstubs" %common diff --git a/arch/all-unix/devs/networks/tap/tap.h b/arch/all-unix/devs/networks/tap/tap.h index 9ec8b625c0..a48eafc23c 100644 --- a/arch/all-unix/devs/networks/tap/tap.h +++ b/arch/all-unix/devs/networks/tap/tap.h @@ -1,6 +1,7 @@ /* * tap - TUN/TAP network driver for AROS * Copyright (c) 2007 Robert Norris. All rights reserved. + * Copyright © 2010, The AROS Development Team. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the same terms as AROS itself. @@ -9,7 +10,6 @@ #ifndef _TAP_DEVICE_H #define _TAP_DEVICE_H 1 -#define DEBUG 0 #include @@ -23,15 +23,10 @@ #include -#include - #include #include #include -#include - -#include #include #include #include @@ -52,6 +47,7 @@ #include #include +#include #include #undef timeval @@ -61,6 +57,17 @@ /* explicitly prototype rand() so we don't have pull in stdlib.h */ extern int rand(void); +#ifdef HOST_OS_linux +#define LIBC_NAME "libc.so.6" +#endif + +#ifdef HOST_OS_darwin +#define LIBC_NAME "libSystem.dylib" +#endif + +#ifndef LIBC_NAME +#define LIBC_NAME "libc.so" +#endif #define MAX_TAP_UNITS (4) @@ -69,9 +76,6 @@ extern int rand(void); #define TAP_IFACE_FORMAT "aros%ld" #define TAP_TASK_FORMAT "TAP IO: unit %d" - -extern HIDD *unixio; - struct tap_opener { struct MinNode node; @@ -90,7 +94,8 @@ struct tap_tracker { struct Sana2PacketTypeStats stats; }; -struct tap_unit { +struct tap_unit +{ ULONG num; ULONG refcount; @@ -111,20 +116,42 @@ struct tap_unit { char iotask_name[32]; struct MsgPort *iosyncport; - struct Process *iotask; + struct Task *iotask; - LONG write_signal; LONG abort_signal; + LONG io_signal; - struct MsgPort write_queue; + struct MsgPort *write_queue; }; -struct tap_base { - struct Device tap_device; +struct LibCInterface +{ + int (*open)(char *path, int oflag, ...); + int (*close)(int filedes); + int (*ioctl)(int d, int request, ...); + int (*fcntl)(int fd, int cmd, ...); + int (*poll)(struct pollfd *fds, nfds_t nfds, int timeout); + ssize_t (*read)(int fd, void *buf, size_t count); + ssize_t (*write)(int fildes, const void *buf, size_t nbyte); + pid_t (*getpid)(void); + int *(*__error)(void); +}; - struct tap_unit unit[MAX_TAP_UNITS]; +struct tap_base +{ + struct Device tap_device; + struct tap_unit unit[MAX_TAP_UNITS]; + APTR KernelBase; + APTR HostLibBase; + APTR LibCHandle; + struct LibCInterface *TAPIFace; + pid_t aros_pid; + int *errnoPtr; + struct SignalSemaphore sem; }; +#define HostLibBase TAPBase->HostLibBase +#define KernelBase TAPBase->KernelBase /* unit flags */ #define tu_CONFIGURED (1<<0) @@ -135,4 +162,6 @@ extern void tap_handle_request(struct IOSana2Req *req); extern void tap_hexdump(unsigned char *buf, int bufsz); +extern void tap_iotask(struct tap_base *TAPBase, struct tap_unit *unit); + #endif -- 2.11.4.GIT