Moving the net kit private includes files to /current tree.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@897 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Philippe Houdoin 2002-08-27 07:59:57 +00:00
parent a225fd0942
commit 35682cc6b3
13 changed files with 909 additions and 14 deletions

View File

@ -0,0 +1,115 @@
/* core_funcs.h
* convenience macros to for calling core functions in the kernel
*/
#ifndef OBOS_CORE_FUNCS_H
#define OBOS_CORE_FUNCS_H
#include "core_module.h"
# define add_protosw core->add_protosw
# define add_domain core->add_domain
# define remove_domain core->remove_domain
# define add_protocol core->add_protocol
# define remove_protocol core->remove_protocol
# define start_rx_thread core->start_rx_thread
# define start_tx_thread core->start_tx_thread
# define net_add_timer core->net_add_timer
# define net_remove_timer core->net_remove_timer
# define start_ifq core->start_ifq
# define stop_ifq core->stop_ifq
# define pool_init core->pool_init
# define pool_get core->pool_get
# define pool_put core->pool_put
# define m_get core->m_get
# define m_gethdr core->m_gethdr
# define m_free core->m_free
# define m_freem core->m_freem
# define m_cat core->m_cat
# define m_adj core->m_adj
# define m_prepend core->m_prepend
# define m_pullup core->m_pullup
# define m_copydata core->m_copydata
# define m_copyback core->m_copyback
# define m_copym core->m_copym
# define m_reserve core->m_reserve
# define m_devget core->m_devget
# define if_attach core->if_attach
# define if_detach core->if_detach
# define in_pcballoc core->in_pcballoc
# define in_pcbconnect core->in_pcbconnect
# define in_pcbdisconnect core->in_pcbdisconnect
# define in_pcbbind core->in_pcbbind
# define in_pcblookup core->in_pcblookup
# define in_pcbdetach core->in_pcbdetach
# define in_pcbrtentry core->in_pcbrtentry
# define in_canforward core->in_canforward
# define in_localaddr core->in_localaddr
# define in_losing core->in_losing
# define in_broadcast core->in_broadcast
# define in_control core->in_control
# define in_setsockaddr core->in_setsockaddr
# define in_setpeeraddr core->in_setpeeraddr
# define in_pcbnotify core->in_pcbnotify
# define inetctlerrmap core->inetctlerrmap
# define ifa_ifwithdstaddr core->ifa_ifwithdstaddr
# define ifa_ifwithaddr core->ifa_ifwithaddr
# define ifa_ifwithnet core->ifa_ifwithnet
# define ifa_ifwithroute core->ifa_ifwithroute
# define ifaof_ifpforaddr core->ifaof_ifpforaddr
# define ifafree core->ifafree
# define sbappend core->sbappend
# define sbappendaddr core->sbappendaddr
# define sbdrop core->sbdrop
# define sbflush core->sbflush
# define sbreserve core->sbreserve
# define soreserve core->soreserve
# define sowakeup core->sowakeup
# define sonewconn core->sonewconn
# define soisconnected core->soisconnected
# define soisconnecting core->soisconnecting
# define soisdisconnected core->soisdisconnected
# define soisdisconnecting core->soisdisconnecting
# define sohasoutofband core->sohasoutofband
# define socantsendmore core->socantsendmore
# define socantrcvmore core->socantrcvmore
# define rtfree core->rtfree
# define rtalloc core->rtalloc
# define rtalloc1 core->rtalloc1
# define rtrequest core->rtrequest
# define rt_setgate core->rt_setgate
# define get_rt_tables core->get_rt_tables
# define rn_addmask core->rn_addmask
# define rn_head_search core->rn_head_search
# define get_interfaces core->get_interfaces
# define get_primary_addr core->get_primary_addr
# define initsocket core->initsocket
# define socreate core->socreate
# define soclose core->soclose
# define sobind core->sobind
# define soconnect core->soconnect
# define solisten core->solisten
# define soaccept core->soaccept
# define soo_ioctl core->soo_ioctl
# define net_sysctl core->net_sysctl
# define readit core->readit
# define writeit core->writeit
#endif /* OBOS_CORE_FUNCS_H */

View File

@ -0,0 +1,158 @@
/* core_module.h
* definitions needed by the core networking module
*/
#ifndef OBOS_CORE_MODULE_H
#define OBOS_CORE_MODULE_H
#include "sys/mbuf.h"
#include "sys/protosw.h"
#include "sys/socketvar.h"
#include "netinet/in_pcb.h"
#include "net/if.h"
#include "net_timer.h"
#include "net_module.h"
struct core_module_info {
module_info module;
int (*start)(void);
int (*stop)(void);
void (*add_domain)(struct domain *, int);
void (*remove_domain)(int);
void (*add_protocol)(struct protosw *, int);
void (*remove_protocol)(struct protosw *pr);
void (*add_protosw)(struct protosw *prt[], int layer);
void (*start_rx_thread)(struct ifnet *dev);
void (*start_tx_thread)(struct ifnet *dev);
/* timer functions */
net_timer_id (*net_add_timer)(net_timer_hook ,void *,
bigtime_t);
status_t (*net_remove_timer)(net_timer_id);
/* ifq functions */
struct ifq *(*start_ifq)(void);
void (*stop_ifq)(struct ifq *);
/* pool functions */
status_t (*pool_init)(pool_ctl **p, size_t sz);
char *(*pool_get)(pool_ctl *p);
void (*pool_put)(pool_ctl *p, void *ptr);
void (*pool_destroy)(pool_ctl *p);
/* socket functions - called "internally" */
struct socket *(*sonewconn)(struct socket *, int);
int (*soreserve)(struct socket *, uint32, uint32);
int (*sbreserve)(struct sockbuf *, uint32);
void (*sbappend)(struct sockbuf *, struct mbuf *);
int (*sbappendaddr)(struct sockbuf *, struct sockaddr *,
struct mbuf *, struct mbuf *);
void (*sbdrop)(struct sockbuf *, int);
void (*sbflush)(struct sockbuf *sb);
void (*sowakeup)(struct socket *, struct sockbuf *);
void (*soisconnected)(struct socket *);
void (*soisconnecting)(struct socket*);
void (*soisdisconnected)(struct socket *);
void (*soisdisconnecting)(struct socket *);
void (*sohasoutofband)(struct socket *so);
void (*socantrcvmore)(struct socket*);
void (*socantsendmore)(struct socket *);
/* pcb options */
int (*in_pcballoc)(struct socket *, struct inpcb *);
void (*in_pcbdetach)(struct inpcb *);
int (*in_pcbbind)(struct inpcb *, struct mbuf *);
int (*in_pcbconnect)(struct inpcb *, struct mbuf *);
int (*in_pcbdisconnect)(struct inpcb *);
struct inpcb * (*in_pcblookup)(struct inpcb *,
struct in_addr, uint16, struct in_addr, uint16, int);
int (*in_control)(struct socket *, int, caddr_t,
struct ifnet *);
void (*in_losing)(struct inpcb *);
int (*in_canforward)(struct in_addr);
int (*in_localaddr)(struct in_addr);
struct rtentry *(*in_pcbrtentry)(struct inpcb *);
void (*in_setsockaddr)(struct inpcb *, struct mbuf *);
void (*in_setpeeraddr)(struct inpcb *, struct mbuf *);
void (*in_pcbnotify)(struct inpcb *, struct sockaddr *,
uint16, struct in_addr, uint16,
int, void (*)(struct inpcb *, int));
int (*inetctlerrmap)(int);
/* mbuf routines... */
struct mbuf * (*m_gethdr)(int);
struct mbuf * (*m_get)(int);
void (*m_cat)(struct mbuf *, struct mbuf *);
void (*m_adj)(struct mbuf*, int);
struct mbuf * (*m_prepend)(struct mbuf*, int);
struct mbuf *(*m_pullup)(struct mbuf *, int);
void (*m_copyback)(struct mbuf *, int, int, caddr_t);
void (*m_copydata)(struct mbuf *, int, int, caddr_t);
struct mbuf *(*m_copym)(struct mbuf *, int, int);
struct mbuf * (*m_free)(struct mbuf *);
void (*m_freem)(struct mbuf *);
void (*m_reserve)(struct mbuf *, int);
struct mbuf *(*m_devget)(char *, int, int, struct ifnet *,
void (*copy)(const void *, void *, size_t));
/* module control routines... */
void (*add_device)(struct ifnet *);
struct ifnet *(*get_interfaces)(void);
int (*in_broadcast)(struct in_addr, struct ifnet *);
/* routing */
void (*rtalloc)(struct route *ro);
struct rtentry *(*rtalloc1)(struct sockaddr *, int);
void (*rtfree)(struct rtentry *);
int (*rtrequest)(int, struct sockaddr *,
struct sockaddr *, struct sockaddr *, int,
struct rtentry **);
struct radix_node *(*rn_addmask)(void *, int, int);
struct radix_node *(*rn_head_search)(void *argv_v);
struct radix_node_head **(*get_rt_tables)(void);
int (*rt_setgate)(struct rtentry *, struct sockaddr *,
struct sockaddr *);
/* ifnet functions */
struct ifaddr *(*ifa_ifwithdstaddr)(struct sockaddr *addr);
struct ifaddr *(*ifa_ifwithnet)(struct sockaddr *addr);
void (*if_attach)(struct ifnet *);
void (*if_detach)(struct ifnet *);
struct ifaddr *(*ifa_ifwithaddr)(struct sockaddr *);
struct ifaddr *(*ifa_ifwithroute)(int, struct sockaddr *,
struct sockaddr *);
struct ifaddr *(*ifaof_ifpforaddr)(struct sockaddr *, struct ifnet *);
void (*ifafree)(struct ifaddr *);
struct in_ifaddr *(*get_primary_addr)(void);
/* socket functions - used by socket driver */
int (*initsocket)(void **);
int (*socreate)(int, void *, int, int);
int (*soclose)(void *);
int (*sobind)(void *, caddr_t, int);
int (*solisten)(void *, int);
int (*soconnect)(void *, caddr_t, int);
int (*recvit)(void *, struct msghdr *, caddr_t, int *);
int (*sendit)(void *, struct msghdr *, int, int *);
int (*soo_ioctl)(void *, int, caddr_t);
int (*net_sysctl)(int *, uint, void *, size_t *, void *, size_t);
int (*writeit)(void *, struct iovec *, int);
int (*readit)(void*, struct iovec *, int *);
int (*sosetopt)(void *, int, int, const void *, size_t);
int (*sogetopt)(void *, int, int, void *, size_t *);
int (*set_socket_event_callback)(void *, socket_event_callback, void *, int);
int (*sogetpeername)(void *, struct sockaddr *, int *);
int (*sogetsockname)(void *, struct sockaddr *, int *);
int (*soaccept)(void *, void **, void *, int *);
};
#ifdef _KERNEL_MODE
#define CORE_MODULE_PATH "network/core"
#else
#define CORE_MODULE_PATH "modules/core"
#endif
#endif /* OBOS_CORE_MODULE_H */

View File

@ -4,12 +4,22 @@
#ifndef ICMP_MODULE_H
#define ICMP_MODULE_H
#include <net/net_module.h>
#include "net_module.h"
#ifdef _KERNEL_
#include <KernelExport.h>
#define ICMP_MODULE_PATH "network/protocol/icmp"
#else /* _KERNEL_ */
#define ICMP_MODULE_PATH "modules/protocol/icmp"
#endif /* _KERNEL_ */
struct icmp_module_info {
struct kernel_net_module_info info;
#ifndef _KERNEL_
void (*set_core)(struct core_module_info *);
#endif
void (*error)(struct mbuf *, int, int, n_long, struct ifnet *);
};

View File

@ -5,20 +5,26 @@
#ifndef IPV4_MODULE_H
#define IPV4_MODULE_H
#ifndef _KERNEL_MODE
#error "This is a kernel ONLY file"
#endif
#include "net/net_module.h"
#include "net_module.h"
#ifdef _KERNEL_
#include <KernelExport.h>
#define IPV4_MODULE_PATH "network/protocol/ipv4"
#else /* _KERNEL_ */
#define IPV4_MODULE_PATH "modules/protocol/ipv4"
#endif /* _KERNEL_ */
struct ipv4_module_info {
struct kernel_net_module_info info;
#ifndef _KERNEL_
void (*set_core)(struct core_module_info *);
#endif
int (*output)(struct mbuf *,
struct mbuf *,
struct route *,
int, void *);
uint16 (*ip_id)(void);
int (*ctloutput)(int,
struct socket *,
int, int,
@ -29,6 +35,4 @@ struct ipv4_module_info {
struct mbuf *(*srcroute)(void);
};
extern uint16 ip_id;
#endif /* IPV4_MODULE_H */

128
headers/private/net/lock.h Normal file
View File

@ -0,0 +1,128 @@
#ifndef LOCK_H
#define LOCK_H
/* lock.h - benaphore locking, "faster semaphores", read/write locks
** sorry for all those macros; I wish C would support C++-style
** inline functions.
**
** Initial version by Axel Dörfler, axeld@pinc-software.de
**
** This file may be used under the terms of the OpenBeOS License.
*/
#include <SupportDefs.h>
// for read/write locks
#define MAX_READERS 100000
struct benaphore {
sem_id sem;
int32 count;
};
typedef struct benaphore benaphore;
// it may make sense to add a status field to the rw_lock to
// be able to check if the semaphore could be locked
struct rw_lock {
sem_id sem;
int32 count;
benaphore writeLock;
};
typedef struct rw_lock rw_lock;
#ifndef _KERNEL_
#define INIT_BENAPHORE(lock,name) \
{ \
(lock).count = 1; \
(lock).sem = create_sem(0, name); \
}
#else
#define INIT_BENAPHORE(lock,name) \
{ \
(lock).count = 1; \
(lock).sem = create_sem(0, name); \
set_sem_owner((lock).sem, B_SYSTEM_TEAM); \
}
#endif
#define CHECK_BENAPHORE(lock) \
((lock).sem)
#define UNINIT_BENAPHORE(lock) \
delete_sem((lock).sem);
#define ACQUIRE_BENAPHORE(lock) \
(atomic_add(&((lock).count), -1) <= 0 ? \
acquire_sem_etc((lock).sem, 1, B_CAN_INTERRUPT, 0) \
: B_OK)
#define RELEASE_BENAPHORE(lock) \
{ \
if (atomic_add(&((lock).count), 1) < 0) \
release_sem((lock).sem); \
}
/* read/write lock */
#ifndef _KERNEL_
#define INIT_RW_LOCK(lock,name) \
{ \
(lock).sem = create_sem(0, name); \
(lock).count = MAX_READERS; \
INIT_BENAPHORE((lock).writeLock, "r/w write lock"); \
}
#else
#define INIT_RW_LOCK(lock,name) \
{ \
(lock).sem = create_sem(0, name); \
set_sem_owner((lock).sem, B_SYSTEM_TEAM); \
(lock).count = MAX_READERS; \
INIT_BENAPHORE((lock).writeLock, "r/w write lock"); \
}
#endif
#define CHECK_RW_LOCK(lock) \
((lock).sem)
#define UNINIT_RW_LOCK(lock) \
delete_sem((lock).sem); \
UNINIT_BENAPHORE((lock).writeLock)
#define ACQUIRE_READ_LOCK(lock) \
{ \
if (atomic_add(&(lock).count, -1) <= 0) \
acquire_sem((lock).sem); \
}
#define RELEASE_READ_LOCK(lock) \
{ \
if (atomic_add(&(lock).count, 1) < 0) \
release_sem((lock).sem); \
}
#define ACQUIRE_WRITE_LOCK(lock) \
{ \
int32 readers; \
ACQUIRE_BENAPHORE((lock).writeLock); \
readers = atomic_add(&(lock).count, -MAX_READERS); \
if (readers < MAX_READERS) \
acquire_sem_etc((lock).sem,readers <= 0 ? 1 : MAX_READERS - readers,0,0); \
RELEASE_BENAPHORE((lock).writeLock); \
}
#define RELEASE_WRITE_LOCK(lock) \
{ \
int32 readers = atomic_add(&(lock).count,MAX_READERS); \
if (readers < 0) \
release_sem_etc((lock).sem,readers <= -MAX_READERS ? 1 : -readers,B_CAN_INTERRUPT); \
}
#endif /* LOCK_H */

View File

@ -0,0 +1,37 @@
/* net_malloc.h
*
* Are we useing the system amlloc or our own...
*/
#ifndef NET_MALLOC_H
#define NET_MALLOC_H
#include <malloc.h>
#include "net_misc.h"
#if USE_DEBUG_MALLOC
/* We check the boundary of the malloc'd area at one end of the
* area allocated. If we are outside the area it'll stop, but we can
* check only one end of the boundary. So the following essentially
* allows us to choose which end.
*/
//#define OVERRUN
#ifdef OVERRUN
#define CHECK_OVERRUN 1
#else
#define CHECK_UNDERRUN 1
#endif
/* use the area malloc code from marcus Overhagen */
void *dbg_malloc(char *file, int line, size_t size);
void dbg_free (char *file, int line, void *ptr);
#define malloc(s) dbg_malloc(__FILE__, __LINE__, s)
#define free(s) do { dbg_free(__FILE__, __LINE__, s); s = NULL; } while (0)
#endif /* USE_DEBUG_MALLOC */
#endif /* NET_MALLOC_H */

View File

@ -0,0 +1,102 @@
/* net_misc.h
* Miscellaneous networking stuff that doesn't yet have a home.
*/
#ifdef _NETWORK_STACK
#include <kernel/OS.h>
#include <ByteOrder.h>
#include <Errors.h>
#include "sys/mbuf.h"
#ifndef OBOS_NET_MISC_H
#define OBOS_NET_MISC_H
#ifdef _KERNEL_
#include <KernelExport.h>
#define printf dprintf
#endif
/* Not really sure if this is safe... */
#define EHOSTDOWN (B_POSIX_ERROR_BASE + 45)
/* These are GCC only, so we'll need PPC version eventually... */
struct quehead {
struct quehead *qh_link;
struct quehead *qh_rlink;
};
static __inline void insque(void *a, void *b)
{
struct quehead *element = (struct quehead *)a,
*head = (struct quehead *)b;
element->qh_link = head->qh_link;
element->qh_rlink = head;
head->qh_link = element;
element->qh_link->qh_rlink = element;
}
static __inline void remque(void *a)
{
struct quehead *element = (struct quehead *)a;
element->qh_link->qh_rlink = element->qh_rlink;
element->qh_rlink->qh_link = element->qh_link;
element->qh_rlink = 0;
}
/* DEBUG Options!
*
* Having a single option is sort of lame so I'm going to start adding more here...
*
*/
#define SHOW_DEBUG 0 /* general debugging stuff (verbose!) */
#define SHOW_ROUTE 0 /* show routing information */
#define ARP_DEBUG 0 /* show ARP debug info */
#define USE_DEBUG_MALLOC 0 /* use the debug malloc code*/
typedef struct ifnet ifnet;
/* ARP lookup return codes... */
enum {
ARP_LOOKUP_OK = 1,
ARP_LOOKUP_QUEUED = 2,
ARP_LOOKUP_FAILED = 3
};
typedef uint32 ipv4_addr;
/* These should be in KernelExport.h */
#define B_SELECT_READ 1
#define B_SELECT_WRITE 2
#define B_SELECT_EXCEPTION 3
/* XXX - add some macro's for inserting various types of address
*/
void net_server_add_device(ifnet *ifn);
uint16 in_cksum(struct mbuf *m, int len, int off);
void local_init(void);
/* sockets and in_pcb init */
int sockets_init(void);
void sockets_shutdown(void);
int inpcb_init(void);
void start_tx_thread(ifnet *dev);
void start_rx_thread(ifnet *dev);
/* Useful debugging functions */
void dump_ipv4_addr(char *msg, void *ad);
void print_ipv4_addr(void *ad);
void dump_ether_addr(char *msg, void *ma);
void print_ether_addr(void *ea);
void dump_buffer(char *buffer, int len);
void dump_sockaddr(void *ptr);
#endif /* OBOS_NET_MISC_H */
#endif /* _NETWORK_STACK */

View File

@ -3,12 +3,31 @@
* net_server
*/
#ifndef _NET_NET_MODULE_H
#define _NET_NET_MODULE_H
#ifndef OBOS_NET_MODULE_H
#define OBOS_NET_MODULE_H
#include <OS.h>
#include <kernel/OS.h>
#include <image.h>
#include "sys/mbuf.h"
#include "net_misc.h"
#include "sys/socketvar.h"
#include "net/if.h"
#include "net/route.h"
#ifdef _KERNEL_MODE
#include <module.h>
#else
typedef struct module_info {
const char *name;
uint32 flags;
status_t (*std_ops)(int32, ...);
} module_info;
#define B_MODULE_INIT 1
#define B_MODULE_UNINIT 2
#define B_KEEP_LOADED 0x00000001
#endif
struct kernel_net_module_info {
module_info info;
@ -20,10 +39,18 @@ struct net_module {
struct net_module *next;
char *name;
struct kernel_net_module_info *ptr;
#ifndef _KERNEL_
image_id iid;
#endif
int status;
};
enum {
NET_LAYER1 = 1, /* link layer */
NET_LAYER2, /* network layer */
NET_LAYER3, /* transport layer */
NET_LAYER4 /* socket layer */
};
int inetctlerrmap(int);
#endif /* _NET_NET_MODULE_H */
#endif /* OBOS_NET_MODULE_H */

View File

@ -0,0 +1,140 @@
/* net_stack_driver.h
* structures and defines to deal with the network stack pseudo-driver...
*/
#ifndef NET_STACK_DRIVER_H
#define NET_STACK_DRIVER_H
#include <sys/select.h>
#define NET_STACK_DRIVER_PATH "net/stack"
enum {
// Paranoia mode: be far away of B_DEVICE_OP_CODES_END opcodes!!!
// You never know what another device driver ioctl() will do
// if think our NET_STACK_* is in fact his DO_RISKY_BUSINESS opcode, or whatever...
NET_IOCTL_BASE = 0xbe230000,
NET_STACK_IOCTL_BASE = NET_IOCTL_BASE + 0x200
};
enum {
NET_STACK_SOCKET = NET_STACK_IOCTL_BASE, // socket_args *
NET_STACK_BIND, // sockaddr_args *
NET_STACK_RECVFROM, // struct msghdr *
NET_STACK_RECV, // data_xfer_args *
NET_STACK_SENDTO, // struct msghdr *
NET_STACK_SEND, // data_xfer_args *
NET_STACK_LISTEN, // int_args * (value = backlog)
NET_STACK_ACCEPT, // accept_args *
NET_STACK_CONNECT, // sockaddr_args *
NET_STACK_SHUTDOWN, // int_args * (value = how)
NET_STACK_GETSOCKOPT, // sockopt_args *
NET_STACK_SETSOCKOPT, // sockopt_args *
NET_STACK_GETSOCKNAME, // sockaddr_args *
NET_STACK_GETPEERNAME, // sockaddr_args *
NET_STACK_SYSCTL, // sysctl_args *
NET_STACK_SELECT, // select_args *
NET_STACK_DESELECT, // select_args *
NET_STACK_GET_COOKIE, // void **
NET_STACK_STOP,
NET_STACK_NOTIFY_SOCKET_EVENT, // notify_socket_event_args * (userland stack only)
NET_STACK_IOCTL_MAX
};
struct int_args { // used by NET_STACK_LISTEN/_SHUTDOWN
int value;
};
struct sockaddr_args { // used by NET_STACK_CONNECT/_BIND/_GETSOCKNAME/_GETPEERNAME
struct sockaddr *addr;
int addrlen;
};
struct sockopt_args { // used by NET_STACK_SETSOCKOPT/_GETSOCKOPT
int level;
int option;
void *optval;
int optlen;
};
struct data_xfer_args { // used by NET_STACK_SEND/_RECV
void *data;
size_t datalen;
int flags;
struct sockaddr *addr; // unused in *_SEND and *_RECV cases
int addrlen; // unused in *_SEND and *_RECV cases
};
struct socket_args { // used by NET_STACK_SOCKET
int family;
int type;
int proto;
};
struct getcookie_args { // used by NET_STACK_GET_COOKIE
void **cookie;
};
struct accept_args { // used by NET_STACK_ACCEPT
void *cookie;
struct sockaddr *addr;
int addrlen;
};
struct sysctl_args { // used by NET_STACK_SYSCTL
int *name;
uint namelen;
void *oldp;
size_t *oldlenp;
void *newp;
size_t newlen;
};
/*
Userland stack driver on_socket_event() callback mecanism implementation:
the driver start a kernel thread waiting on a port for
a NET_STACK_SOCKET_EVENT_MSG message, which come with a socket_event_data block.
The on_socket_event() mechanism stay in driver (kernelland) because it's
only there we can call kernel's notify_select_event() on BONE systems.
For non-BONE systems, we use our own r5_notify_select_event()
implementation, that could be moved into the userland net_server code,
but it'll have split (again!) the /dev/net/stack driver code...
*/
struct notify_socket_event_args { // used by NET_STACK_NOTIFY_SOCKET_EVENT
port_id notify_port; // port waiting for notification, -1 = stop notify
void * cookie; // this cookie value will be pass back in the socket_event_args
};
#define NET_STACK_SOCKET_EVENT_NOTIFICATION 'sevn'
struct socket_event_data {
uint32 event; // B_SELECT_READ, B_SELECT_WRITE or B_SELECT_EXCEPTION
void * cookie; // The cookie as set in notify_socket_event_args for this socket
};
/*
R5.0.3 and before select() kernel support is too buggy to be used, so
here are the structures we used to support select() on sockets, and *only* on
sockets!
*/
struct select_args { // used by NET_STACK_SELECT and NET_STACK_DESELECT
struct selectsync * sync; // in fact, it's the area_id of a r5_selectsync struct!!!
uint32 ref;
};
struct r5_selectsync {
sem_id lock; // lock this r5_selectsync
sem_id wakeup; // sem to release to wakeup select()
struct fd_set rbits; // read event bits field
struct fd_set wbits; // write event bits field
struct fd_set ebits; // exception event bits field
};
#endif /* NET_STACK_DRIVER_H */

View File

@ -0,0 +1,26 @@
#ifndef NET_TIMER_H
#define NET_TIMER_H
/* net_timer.h - a small and more or less inaccurate timer for net modules.
** The registered hooks will be called in the thread of the timer.
**
** Initial version by Axel Dörfler, axeld@pinc-software.de
**
** This file may be used under the terms of the OpenBeOS License.
*/
#include <SupportDefs.h>
typedef void (*net_timer_hook)(void *);
typedef int32 net_timer_id;
extern status_t net_init_timer(void);
extern void net_shutdown_timer(void);
extern net_timer_id net_add_timer(net_timer_hook hook, void *data, bigtime_t interval);
extern status_t net_remove_timer(net_timer_id);
#endif /* NET_TIMER_H */

View File

@ -0,0 +1,40 @@
/* nhash.h
*/
#ifndef OBOS_NHASH_H
#define OBOS_NHASH_H
#include "pools.h"
typedef struct net_hash_entry net_hash_entry;
typedef struct net_hash net_hash;
typedef struct net_hash_index net_hash_index;
struct net_hash_entry {
net_hash_entry *next;
int hash;
const void *key;
ssize_t klen;
const void *val;
};
struct net_hash_index {
net_hash *nh;
net_hash_entry *this;
net_hash_entry *next;
int index;
};
struct net_hash {
net_hash_entry **array;
net_hash_index iterator;
int count;
int max;
struct pool_ctl *pool;
};
net_hash *nhash_make(void);
void *nhash_get(net_hash *, const void *key, ssize_t klen);
void nhash_set(net_hash *, const void *, ssize_t , const void *);
#endif /* OBOS_NHASH_H */

View File

@ -0,0 +1,55 @@
/* pools.h
* simple fixed size block allocator
*/
#ifndef OBOS_POOLS_H
#define OBOS_POOLS_H
#include <kernel/OS.h>
#include "lock.h"
typedef struct pool_ctl pool_ctl;
struct pool_mem {
struct pool_mem *next;
area_id aid;
char *base_addr;
size_t mem_size;
char *ptr;
size_t avail;
benaphore lock;
};
struct free_blk {
char *next;
};
#define POOL_USES_BENAPHORES 0
#define POOL_DEBUG_NAME_SZ 32
struct pool_ctl {
struct pool_mem *list;
char *freelist;
size_t alloc_size;
size_t block_size;
#if POOL_USES_BENAPHORES
benaphore lock;
#else
rw_lock lock;
#endif
int debug;
char name[POOL_DEBUG_NAME_SZ];
};
status_t pool_init(pool_ctl **p, size_t sz);
char *pool_get(pool_ctl *p);
void pool_put(pool_ctl *p, void *ptr);
void pool_destroy(pool_ctl *p);
void pool_debug(struct pool_ctl *p, char *name);
void pool_debug_walk(pool_ctl *p);
#endif /* OBOS_POOLS_H */

View File

@ -0,0 +1,53 @@
#ifndef USERLAND_IPC_H
#define USERLAND_IPC_H
/* userland_ipc - Communication between the network driver
** and the userland stack.
**
** Initial version by Axel Dörfler, axeld@pinc-software.de
** This file may be used under the terms of the OpenBeOS License.
*/
#include <OS.h>
#include "net_stack_driver.h"
#define NET_STACK_PORTNAME "net_server connection"
enum {
NET_STACK_OPEN = NET_STACK_IOCTL_MAX,
NET_STACK_CLOSE,
NET_STACK_NEW_CONNECTION,
};
#define MAX_NET_AREAS 5
typedef struct {
area_id id;
uint8 *offset;
} net_area_info;
typedef struct {
int32 op;
// int32 buffer;
uint8 *data;
int32 length;
int32 result;
net_area_info area[MAX_NET_AREAS];
} net_command;
#define CONNECTION_QUEUE_LENGTH 128
#define CONNECTION_COMMAND_SIZE 2048
typedef struct {
port_id port;
area_id area;
sem_id commandSemaphore; // command queue
uint32 numCommands,bufferSize;
} net_connection;
extern status_t init_userland_ipc(void);
extern void shutdown_userland_ipc(void);
#endif /* USERLAND_IPC_H */