Merge of branches/team/network/new_stack - not yet complete as SVN does only support

replacing files when merging when you don't have deleted them manually (for some reason,
it only works as part of the merge operation, and we didn't copy the whole tree to
have "a fresh start" - next time we know better, at least if SVN still suffers from
that same limitation).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18456 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2006-08-08 12:33:33 +00:00
parent 70418bc5bf
commit 5adca30a18
406 changed files with 17948 additions and 26566 deletions
-110
View File
@@ -1,110 +0,0 @@
/* 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 get_max_hdr core->get_max_hdr
# define set_max_linkhdr core->set_max_linkhdr
# define get_max_linkhdr core->get_max_linkhdr
# define set_max_protohdr core->set_max_protohdr
# define get_max_protohdr core->get_max_protohdr
# 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 in_cksum core->in_cksum
# 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 sockbuf_append core->sockbuf_append
# define sockbuf_appendaddr core->sockbuf_appendaddr
# define sockbuf_drop core->sockbuf_drop
# define sockbuf_flush core->sockbuf_flush
# define sockbuf_reserve core->sockbuf_reserve
# define soreserve core->soreserve
# define sowakeup core->sowakeup
# define sonewconn core->sonewconn
# define socket_set_connected core->socket_set_connected
# define socket_set_connecting core->socket_set_connecting
# define socket_set_disconnected core->socket_set_disconnected
# define socket_set_disconnecting core->socket_set_disconnecting
# define socket_set_hasoutofband core->socket_set_hasoutofband
# define socket_set_cantsendmore core->socket_set_cantsendmore
# define socket_set_cantrcvmore core->socket_set_cantrcvmore
# 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 net_sysctl core->net_sysctl
#endif /* OBOS_CORE_FUNCS_H */
-167
View File
@@ -1,167 +0,0 @@
/* core_module.h
* definitions needed by the core networking module
*/
#ifndef OBOS_CORE_MODULE_H
#define OBOS_CORE_MODULE_H
#include <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);
status_t (*control_net_module)(const char *name, uint32 op, void *data,
size_t length);
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);
// functions for the 'max_xxx' values
int (*get_max_hdr)(void);
void (*set_max_linkhdr)(int maxLinkHdr);
int (*get_max_linkhdr)(void);
void (*set_max_protohdr)(int maxProtoHdr);
int (*get_max_protohdr)(void);
/* 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 (*sockbuf_reserve)(struct sockbuf *, uint32);
void (*sockbuf_append)(struct sockbuf *, struct mbuf *);
int (*sockbuf_appendaddr)(struct sockbuf *, struct sockaddr *,
struct mbuf *, struct mbuf *);
void (*sockbuf_drop)(struct sockbuf *, int);
void (*sockbuf_flush)(struct sockbuf *sb);
void (*sowakeup)(struct socket *, struct sockbuf *);
void (*socket_set_connected)(struct socket *so);
void (*socket_set_connecting)(struct socket *so);
void (*socket_set_disconnected)(struct socket *so);
void (*socket_set_disconnecting)(struct socket *so);
void (*socket_set_hasoutofband)(struct socket *so);
void (*socket_set_cantrcvmore)(struct socket *so);
void (*socket_set_cantsendmore)(struct socket *so);
/* 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);
uint16 (*in_cksum)(struct mbuf *m, int len, int off);
/* 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);
int (*net_sysctl)(int *, uint, void *, size_t *, void *, size_t);
/* socket functions - used by socket driver */
int (*socket_init) (struct socket **nso);
int (*socket_create) (struct socket *so, int dom, int type, int proto);
int (*socket_close) (struct socket *so);
int (*socket_bind) (struct socket *so, caddr_t, int);
int (*socket_listen) (struct socket *so, int backlog);
int (*socket_connect) (struct socket *so, caddr_t, int);
int (*socket_accept) (struct socket *so, struct socket **nso, void *, int *);
int (*socket_recv) (struct socket *so, struct msghdr *, caddr_t namelenp, int *retsize);
int (*socket_send) (struct socket *so, struct msghdr *, int flags, int *retsize);
int (*socket_ioctl) (struct socket *so, int, caddr_t);
int (*socket_writev) (struct socket *so, struct iovec *, int flags);
int (*socket_readv) (struct socket *so, struct iovec *, int *flags);
int (*socket_setsockopt) (struct socket *so, int, int, const void *, size_t);
int (*socket_getsockopt) (struct socket *so, int, int, void *, size_t *);
int (*socket_getpeername) (struct socket *so, struct sockaddr *, int *);
int (*socket_getsockname) (struct socket *so, struct sockaddr *, int *);
int (*socket_socketpair) (struct socket *so, struct socket **nso);
int (*socket_set_event_callback)(struct socket *so, socket_event_callback, void *, int);
int (*socket_shutdown) (struct socket *so, int how);
};
#define NET_CORE_MODULE_NAME NETWORK_MODULES_ROOT "core/v1"
#endif /* OBOS_CORE_MODULE_H */
-71
View File
@@ -1,71 +0,0 @@
/*
* ether_driver.h
*
* Ethernet driver: handles NE2000 and 3C503 cards
*/
/*
Copyright 1999, Be Incorporated. All Rights Reserved.
This file may be used under the terms of the Be Sample Code License.
*/
#ifndef _ETHER_DRIVER_H
#define _ETHER_DRIVER_H
#ifdef __cplusplus
extern "C" {
#endif
#include <Drivers.h>
/*
* ioctls: belongs in a public header file
* somewhere, so that the net_server and other ethernet drivers can use.
*/
enum {
ETHER_GETADDR = B_DEVICE_OP_CODES_END, /* get ethernet address */
ETHER_INIT, /* set irq and port */
ETHER_NONBLOCK, /* set/unset nonblocking mode */
ETHER_ADDMULTI, /* add multicast addr */
ETHER_REMMULTI, /* rem multicast addr */
ETHER_SETPROMISC, /* set promiscuous */
ETHER_GETFRAMESIZE, /* get frame size */
ETHER_ADDTIMESTAMP, /* (try to) add timestamps to packets (BONE ext) */
ETHER_HASIOVECS, /* does the driver implement writev ? (BONE ext) (bool *) */
ETHER_GETIFTYPE, /* get the IFT_ type of the interface (int *) */
ETHER_GETLINKSTATE /* get line speed, quality, duplex mode, etc. */
};
/*
* 48-bit ethernet address, passed back from ETHER_GETADDR
*/
typedef struct {
unsigned char ebyte[6];
} ether_address_t;
/*
* info passed to ETHER_INIT
*/
typedef struct ether_init_params {
short port;
short irq;
unsigned long mem;
} ether_init_params_t;
/*
* info returned from ETHER_GETLINKSTATE
*/
typedef struct ether_link_state {
float link_speed; /* In Mbits per second */
float link_quality; /* Set to zero if not connected */
char duplex_mode; /* Set to 1 for full duplex, 0 for half */
} ether_link_state_t;
#ifdef __cplusplus
}
#endif
#endif /* _ETHER_DRIVER_H */
-23
View File
@@ -1,23 +0,0 @@
/*
ethernet_module.h
*/
#ifndef ETHERNET_MODULE_H
#define ETHERNET_MODULE_H
#include "net_module.h"
#include <KernelExport.h>
#define NET_ETHERNET_MODULE_NAME NETWORK_MODULES_ROOT "interfaces/ethernet"
typedef void (*ethernet_receiver_func)(struct mbuf *buf);
struct ethernet_module_info {
struct kernel_net_module_info info;
void (*set_pppoe_receiver)(ethernet_receiver_func func);
void (*unset_pppoe_receiver)(void);
};
#endif /* ETHERNET_MODULE_H */
-38
View File
@@ -1,38 +0,0 @@
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1996,1999 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*
* This file is primarily maintained by <[email protected]> and <[email protected]>.
*/
/*
* $Id$
*/
#ifndef _HESIOD_H_INCLUDED
#define _HESIOD_H_INCLUDED
int hesiod_init __P((void **));
void hesiod_end __P((void *));
char * hesiod_to_bind __P((void *, const char *, const char *));
char ** hesiod_resolve __P((void *, const char *, const char *));
void hesiod_free_list __P((void *, char **));
struct __res_state * __hesiod_res_get __P((void *));
void __hesiod_res_set __P((void *, struct __res_state *,
void (*)(void *)));
#endif /*_HESIOD_H_INCLUDED*/
-19
View File
@@ -1,19 +0,0 @@
/* icmp_module.h
*/
#ifndef ICMP_MODULE_H
#define ICMP_MODULE_H
#include "net_module.h"
#include <KernelExport.h>
#define NET_ICMP_MODULE_NAME NETWORK_MODULES_ROOT "protocols/icmp"
struct icmp_module_info {
struct kernel_net_module_info info;
void (*error)(struct mbuf *, int, int, n_long, struct ifnet *);
};
#endif /* ICMP_MODULE_H */
-32
View File
@@ -1,32 +0,0 @@
/* ipv4_module.h
* definitions for ipv4 protocol
*/
#ifndef IPV4_MODULE_H
#define IPV4_MODULE_H
#include "net_module.h"
#include <KernelExport.h>
#define NET_IPV4_MODULE_NAME NETWORK_MODULES_ROOT "protocols/ipv4"
struct ipv4_module_info {
struct kernel_net_module_info info;
int (*output)(struct mbuf *,
struct mbuf *,
struct route *,
int, void *);
uint16 (*ip_id)(void);
int (*ctloutput)(int,
struct socket *,
int, int,
struct mbuf **);
struct mbuf *(*ip_srcroute)(void);
void (*ip_stripoptions)(struct mbuf *,
struct mbuf *);
struct mbuf *(*srcroute)(void);
};
#endif /* IPV4_MODULE_H */
-128
View File
@@ -1,128 +0,0 @@
#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, [email protected]
**
** 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_MODE
#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_MODE
#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 */
-311
View File
@@ -1,311 +0,0 @@
/* mbuf.h
* network buffer definitions
*
* Based on BSD's mbuf principal.
*/
#include "pools.h"
#ifndef OBOS_MBUF_H
#define OBOS_MBUF_H
/* MBuf's are all of a single size, MSIZE bytes. If we have more data
* than can be fitted we can add a single "MBuf cluster" which is of
* fixed size MCLBYTES.
* If the data to be written is larger than MCLMINBYTES bytes we won't use
* the storage provided within the MBuf, but rather all data will go
* directly into an added cluster.
*/
#define MSIZE 256 /* total size of structure */
#define MCLSHIFT 11
#define MCLBYTES (1 << MCLSHIFT)
#define MCLMAXBYTES 2048 /* they can't be bigger than 2k */
#define MLEN (MSIZE - sizeof(struct m_hdr)) /* data length w/o a pkt_hdr */
#define MHLEN (MLEN - sizeof(struct pkt_hdr)) /* data length w/pkt_hdr */
#define CLLEN (MCLBYTES - sizeof(struct cl_hdr))
#define MINCLSIZE (MHLEN + 1)
/* mbuf header structure
* This appears at teh start of every MBuf
*/
struct m_hdr {
struct mbuf *m_next; /* next mbuf in a chain */
struct mbuf *m_nxtpkt; /* next chain in a packet/queue */
char * m_data; /* pointer to data */
uint32 m_len; /* length data in this mbuf NB NOT total length */
uint16 m_type; /* what sort of data do we have ? */
uint16 m_flags; /* flags as defined below */
uint16 m_cksum; /* flags about the checksum on the packet */
};
/* pkt_hdr
* This is ONLY found in the first MBuf in a chain and is valid
* ONLY if we have the M_PKTHDR flag is set
*/
/* XXX - we also need to record things like the interface and also maintain
* a list of the packets associated with this message here.
*/
struct pkt_hdr {
struct ifnet *rcvif; /* interface we came it on */
int len; /* total length */
int csum; /* hardware cksum info... */
};
/* m_ext
* External storage, i.e. a cluster
*/
struct m_ext {
char *ext_buf; /* start of the buffer */
// void *(ext_free)(); /* free routine (if not standard) */
uint ext_size; /* how big is the buffer */
};
/* struct mbuf
* The actual buffer structure.
* This is defined as unions as the size is slightly variable
* depending on the options set.
*/
struct mbuf {
struct m_hdr m_hdr;
union {
struct {
struct pkt_hdr MH_pkthdr;
union {
struct m_ext MH_ext;
char MH_databuf[MHLEN];
} MH_dat;
} MH;
char m_databuf[MLEN];
} um_dat;
};
/* these are simply shortcuts... */
#define m_next m_hdr.m_next
#define m_len m_hdr.m_len
#define m_data m_hdr.m_data
#define m_type m_hdr.m_type
#define m_flags m_hdr.m_flags
#define m_cksum m_hdr.m_cksum
#define m_nextpkt m_hdr.m_nxtpkt
#define m_ext um_dat.MH.MH_dat.MH_ext
#define m_pktdat um_dat.MH.MH_dat.MH_databuf
#define m_pkthdr um_dat.MH.MH_pkthdr
#define m_dat um_dat.m_databuf
/* define a little macro that gives us the data pointer for an mbuf */
#define mtod(m, t) ((t)((m)->m_data))
#define dtom(x) ((struct mbuf *)((int)(x) & ~(MSIZE-1)))
/* mbuf flags */
enum {
M_EXT = 0x0001, /* has extenal storage attached */
M_PKTHDR = 0x0002, /* contains the packet header */
M_EOR = 0x0004, /* end of record (not used for tcp/udp) */
M_CLUSTER = 0x0008, /* external storage is a cluster */
/*
M_PROTO = 0x0010, * protocol specific *
*/
M_BCAST = 0x0100, /* rx/tx as a link-level broadcast */
M_MCAST = 0x0200, /* rx/tx as a link-level multicast */
M_CONF = 0x0400, /* packet was encrypted?? */
M_AUTH = 0x0800, /* packet was authenticated */
M_COMP = 0x1000, /* packet was compressed */
M_ANYCAST6 = 0x4000 /* it was an IPv6 anycast packet */
};
/* the M_COPYFLAGS lists the flags that can be copied when we copy
* an mbuf with the M_PKTHDR flag set */
#define M_COPYFLAGS (M_PKTHDR | M_EOR | M_BCAST | M_MCAST)
/* checksum flags */
enum {
M_IPV4_CSUM_OUT = 0x0001, /* ipv4 checksum required */
M_TCPV4_CSUM_OUT = 0x0002, /* TCP v4 checksum required */
M_UDPV4_CSUM_OUT = 0x0004,
M_IPV4_CSUM_IN_OK = 0x0008,
M_IPV4_CSUM_IN_OUT = 0x0010,
M_TCP_CSUM_IN_OK = 0x0020,
M_TCP_CSUM_IN_BAD = 0x0040,
M_UDP_CSUM_IN_OK = 0x0080,
M_UDP_CSUM_IN_BAD = 0x0100
};
/* MBuf types */
enum {
MT_FREE = 0, /* should be on free list */
MT_DATA = 1, /* dynamic data allocation */
MT_HEADER = 2, /* packet header */
MT_SONAME = 3,
MT_SOOPTS = 4,
MT_FTABLE = 5, /* fragment reassembly header */
MT_CONTROL = 6, /* extra-data protocol message */
MT_OOBDATA = 7 /* out-of-band data */
};
/* length to m_copy to copy all */
#define M_COPYALL 1000000000
/* now some macro's to make life easier... */
/* need to add the macro's here :) */
#define MRESETDATA(m) do { \
if ((m)->m_flags & M_EXT) \
(m)->m_data = (m)->m_ext.ext_buf; \
else if ((m)->m_flags & M_PKTHDR) \
(m)->m_data = (m)->m_pktdat; \
else \
(m)->m_data = (m)->dat; \
} while (0)
/* fill in an mbuf */
#define MGET(n, type) \
n = (struct mbuf*) pool_get(mbpool); \
if (n) { \
(n)->m_type = (type); \
(n)->m_next = NULL; \
(n)->m_nextpkt = NULL; \
(n)->m_data = (n)->m_dat; \
(n)->m_flags = 0; \
(n)->m_cksum = 0; \
}
#define MGETHDR(n, type) \
n = (struct mbuf*) pool_get(mbpool); \
if (n) { \
(n)->m_type = (type); \
(n)->m_next = NULL; \
(n)->m_nextpkt = NULL; \
(n)->m_data = (n)->m_pktdat; \
(n)->m_flags = M_PKTHDR; \
(n)->m_cksum = 0; \
}
#define _MEXTREMOVE(m) do { \
if ((m)->m_flags & M_CLUSTER) { \
pool_put(clpool, (m)->m_ext.ext_buf); \
} \
(m)->m_flags &= ~(M_CLUSTER|M_EXT); \
(m)->m_ext.ext_size = 0; \
} while (0)
#define MFREE(m, n) \
if ((m)->m_flags & M_EXT) { \
_MEXTREMOVE(m); \
} \
(n) = (m)->m_next; \
pool_put(mbpool, m);
/* set the data pointer to place an object of size len at the end
* of the mbuf, aligned to long word (16 bits)
*/
#define M_ALIGN(m, len) \
{ (m)->m_data += (MLEN - (len)) &~ (sizeof(int16) -1);}
#define MH_ALIGN(m, len) \
{ (m)->m_data += (MHLEN - (len)) &~ (sizeof(int16) -1);}
#define M_MOVE_HDR(to, from) { \
(to)->m_pkthdr = (from)->m_pkthdr; \
(from)->m_flags &= ~M_PKTHDR; \
}
#define M_MOVE_PKTHDR(to, from) { \
(to)->m_flags = (from)->m_flags & M_COPYFLAGS; \
M_MOVE_HDR((to), (from)); \
(to)->m_data = (to)->m_pktdat; \
}
#define MCLGET(m) do { \
(m)->m_ext.ext_buf = pool_get(clpool); \
if ((m)->m_ext.ext_buf != NULL) { \
(m)->m_data = (m)->m_ext.ext_buf; \
(m)->m_flags |= M_EXT|M_CLUSTER; \
(m)->m_ext.ext_size = MCLBYTES; \
} \
} while (0)
#define M_LEADINGSPACE(m) \
((m)->m_flags & M_EXT ? (m)->m_data - (m)->m_ext.ext_buf : \
(m)->m_flags & M_PKTHDR ? (m)->m_data - (m)->m_pktdat : \
(m)->m_data - (m)->m_dat)
#define M_PREPEND(m, plen) { \
if (M_LEADINGSPACE(m) >= (plen)) { \
(m)->m_data -= (plen); \
(m)->m_len += (plen); \
} else \
(m) = m_prepend((m), (plen)); \
if ((m) && (m)->m_flags & M_PKTHDR) \
(m)->m_pkthdr.len += (plen); \
}
/*
* Duplicate just m_pkthdr from from to to.
*/
#define M_DUP_HDR(to, from) { \
(to)->m_pkthdr = (from)->m_pkthdr; \
}
/*
* Duplicate mbuf pkthdr from from to to.
* from must have M_PKTHDR set, and to must be empty.
*/
#define M_DUP_PKTHDR(to, from) { \
(to)->m_flags = (from)->m_flags & M_COPYFLAGS; \
M_DUP_HDR((to), (from)); \
(to)->m_data = (to)->m_pktdat; \
}
#define M_TRAILINGSPACE(m) \
((m)->m_flags & M_EXT ? (m)->m_ext.ext_buf + (m)->m_ext.ext_size - \
((m)->m_data + (m)->m_len) : \
&(m)->m_dat[MLEN] - ((m)->m_data + (m)->m_len))
#define M_IS_CLUSTER(m) ((m)->m_flags & M_EXT)
#define M_DATASTART(m) \
(M_IS_CLUSTER(m) ? (m)->m_ext.ext_buf : \
(m)->m_flags & M_PKTHDR ? (m)->m_pktdat : (m)->m_dat)
#define M_DATASIZE(m) \
(M_IS_CLUSTER(m) ? (m)->m_ext.ext_size : \
(m)->m_flags & M_PKTHDR ? MHLEN: MLEN)
/* Functions! */
void mbinit(void);
struct mbuf *m_get(int type);
struct mbuf *m_gethdr(int type);
struct mbuf *m_getclr(int type);
struct mbuf *m_prepend(struct mbuf *m, int len);
struct mbuf *m_devget(char *buf, int totlen, int off0,
struct ifnet *ifp,
void (*copy)(const void *, void *, size_t));
struct mbuf *m_pullup(struct mbuf *, int len);
void m_copyback(struct mbuf *m0, int off, int len, caddr_t cp);
struct mbuf *m_free(struct mbuf *mfree);
void m_freem(struct mbuf *m);
void m_reserve(struct mbuf *mp, int len);
void m_cat(struct mbuf *m, struct mbuf *n);
void m_adj(struct mbuf *mp, int req_len);
void m_copydata(struct mbuf *m, int off, int len, caddr_t cp);
struct mbuf *m_copym(struct mbuf *m, int off0, int len);
/* debug functions */
void dump_freelist(void);
/* Stats structure */
/* XXX - add me! */
#endif /* OBOS_MBUF_H */
-37
View File
@@ -1,37 +0,0 @@
/* 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 */
-98
View File
@@ -1,98 +0,0 @@
/* net_misc.h
* Miscellaneous networking stuff that doesn't yet have a home.
*/
//#ifdef _NETWORK_STACK
#ifndef OBOS_NET_MISC_H
#define OBOS_NET_MISC_H
//#include <kernel/OS.h>
#include <Errors.h>
#include <mbuf.h>
#ifdef _KERNEL_MODE
#include <KernelExport.h>
#define printf dprintf
#endif
#ifndef __HAIKU__
/* Not really sure if this is safe... */
#define EHOSTDOWN (B_POSIX_ERROR_BASE + 45)
#endif
/* 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;
/* XXX - add some macro's for inserting various types of address
*/
void net_server_add_device(ifnet *ifn);
//XXX already in netinet/in.h
//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 */
-41
View File
@@ -1,41 +0,0 @@
/* net_module.h
* fundtions and staructures for all modules using the
* net_server
*/
#ifndef OBOS_NET_MODULE_H
#define OBOS_NET_MODULE_H
#include <kernel/OS.h>
#include <image.h>
#include "mbuf.h"
#include "net_misc.h"
#include "sys/socketvar.h"
#include "net/if.h"
#include "net/route.h"
#include <module.h>
#ifndef __HAIKU__
#define NETWORK_MODULES_ROOT "obos_network/"
#else
#define NETWORK_MODULES_ROOT "network/"
#endif
struct kernel_net_module_info {
module_info info;
int (*start)(void *);
int (*stop)(void);
status_t (*control)(uint32 op, void *data, size_t length);
};
struct net_module {
struct net_module *next;
char *name;
struct kernel_net_module_info *ptr;
int status;
};
#endif /* OBOS_NET_MODULE_H */
-79
View File
@@ -1,79 +0,0 @@
#ifndef _NET_SOCKET_H
#define _NET_SOCKET_H
#include <sys/socketvar.h>
#include <mbuf.h>
/* Function prototypes */
/* These functions are exported through the core module */
int socket_init (struct socket **nso);
int socket_create (struct socket *so, int dom, int type, int proto);
int socket_shutdown (struct socket *so, int how); // XXX this one is not used at all
int socket_close (struct socket *so);
int socket_bind (struct socket *so, char *, int);
int socket_listen (struct socket *so, int backlog);
int socket_connect (struct socket *so, char *, int);
int socket_accept (struct socket *so, struct socket **nso, void *, int *);
int socket_writev (struct socket *so, struct iovec *, int flags);
int socket_readv (struct socket *so, struct iovec *, int *flags);
int socket_send (struct socket *so, struct msghdr *, int flags, int *retsize);
int socket_recv (struct socket *so, struct msghdr *, caddr_t namelenp, int *retsize);
int socket_setsockopt (struct socket *so, int, int, const void *, size_t);
int socket_getsockopt (struct socket *so, int, int, void *, size_t *);
int socket_ioctl (struct socket *so, int cmd, caddr_t data);
int socket_getpeername (struct socket *so, struct sockaddr *, int *);
int socket_getsockname (struct socket *so, struct sockaddr *, int *);
int socket_socketpair (struct socket *so, struct socket **nso);
int socket_set_event_callback(struct socket *so, socket_event_callback, void *, int);
/* these are all private to the stack...although may be shared with
* other network modules.
*/
struct socket *sonewconn(struct socket *head, int connstatus);
int soreserve (struct socket *so, uint32 sndcc, uint32 rcvcc);
void sockbuf_release(struct sockbuf *sb);
int sockbuf_reserve(struct sockbuf *sb, uint32 cc);
void sockbuf_drop(struct sockbuf *sb, int len);
void sockbuf_droprecord(struct sockbuf *sb);
void sockbuf_flush(struct sockbuf *sb);
int sockbuf_wait(struct sockbuf *sb);
void sockbuf_append(struct sockbuf *sb, struct mbuf *m);
int sockbuf_appendaddr(struct sockbuf *sb, struct sockaddr *asa,
struct mbuf *m0, struct mbuf *control);
int sockbuf_appendcontrol(struct sockbuf *sb, struct mbuf *m0,
struct mbuf *control);
void sockbuf_appendrecord(struct sockbuf *sb, struct mbuf *m0);
void sockbuf_compress(struct sockbuf *sb, struct mbuf *m, struct mbuf *n);
void sockbuf_insertoob(struct sockbuf *, struct mbuf *);
void sowakeup(struct socket *so, struct sockbuf *sb);
int sodisconnect(struct socket *);
void socket_set_hasoutofband(struct socket *so);
void socket_set_cantsendmore(struct socket *so);
void socket_set_cantrcvmore(struct socket *so);
void socket_set_connected(struct socket *so);
void socket_set_connecting(struct socket *so);
void socket_set_disconnected(struct socket *so);
void socket_set_disconnecting(struct socket *so);
int sorflush(struct socket *so);
int sockbuf_lock(struct sockbuf *sb);
int nsleep(sem_id chan, char *msg, int timeo);
void wakeup(sem_id chan);
#endif
-169
View File
@@ -1,169 +0,0 @@
/* 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 <OS.h>
#include <sys/select.h>
#include <sys/socket.h>
// Forward declaration
struct sockaddr;
#define NET_STACK_DRIVER_DEV "net/stack"
#define NET_STACK_DRIVER_PATH "/dev/" NET_STACK_DRIVER_DEV
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 {
// ops not acting on an existing socket
NET_STACK_SOCKET = NET_STACK_IOCTL_BASE, // socket_args *
NET_STACK_GET_COOKIE, // void **
NET_STACK_CONTROL_NET_MODULE, // control_net_module_args *
NET_STACK_SYSCTL, // sysctl_args *
// ops acting on an existing socket
NET_STACK_BIND, // sockaddr_args *
NET_STACK_RECVFROM, // struct msghdr *
NET_STACK_RECV, // transfer_args *
NET_STACK_SENDTO, // struct msghdr *
NET_STACK_SEND, // transfer_args *
NET_STACK_LISTEN, // int_args * (value = backlog)
NET_STACK_ACCEPT, // sockaddr_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_SOCKETPAIR, // socketpair_args *
// TODO: remove R5 select() emulation
NET_STACK_SELECT, // select_args *
NET_STACK_DESELECT, // select_args *
NET_STACK_NOTIFY_SOCKET_EVENT, // notify_socket_event_args * (userland stack only)
NET_STACK_IOCTL_MAX
};
struct sockaddr_args { // used by NET_STACK_CONNECT/_BIND/_GETSOCKNAME/_GETPEERNAME
struct sockaddr *addr;
socklen_t addrlen;
};
struct sockopt_args { // used by NET_STACK_SETSOCKOPT/_GETSOCKOPT
int level;
int option;
void *optval;
int optlen;
};
struct transfer_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 socketpair_args { // used by NET_STACK_SOCKETPAIR
void *cookie;
};
struct accept_args { // used by NET_STACK_ACCEPT
void *cookie;
struct sockaddr *addr;
socklen_t addrlen;
};
struct sysctl_args { // used by NET_STACK_SYSCTL
int *name;
uint namelen;
void *oldp;
size_t *oldlenp;
void *newp;
size_t newlen;
};
struct control_net_module_args { // used by NET_STACK_CONTROL_NET_MODULE
const char *name;
uint32 op;
void *data;
size_t length;
};
/*
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_ERROR
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
};
struct stack_driver_args {
union {
int integer;
struct socket_args socket;
struct accept_args accept;
struct sockaddr_args sockaddr;
struct sockopt_args sockopt;
struct transfer_args transfer;
struct sysctl_args sysctl;
struct select_args select;
struct control_net_module_args control;
struct socketpair_args socketpair;
} u;
};
#endif /* NET_STACK_DRIVER_H */
-26
View File
@@ -1,26 +0,0 @@
#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, [email protected]
**
** 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 */
-81
View File
@@ -1,81 +0,0 @@
/*
Copyright 1999, Be Incorporated. All Rights Reserved.
This file may be used under the terms of the Be Sample Code License.
*/
/*
* netconfig.h
* Copyright (c) 1995 Be, Inc. All Rights Reserved
*
* Stuff for reading info out of the /boot/system/netconfig file
*/
#ifndef _NETCONFIG_H
#define _NETCONFIG_H
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#include <stdio.h>
#include <net_settings.h>
#define NC_MAXCLASSLEN 256
#define NC_MAXNAMELEN 256
#define NC_MAXVALLEN 256
static const char NETCONFIGFILE[] = "/network";
static const char NETCONFIGFILE_TMP[] = "/network.tmp";
typedef struct _netconfig {
FILE *ncfile;
char ncbuf[1020];
} NETCONFIG;
typedef char nc_data_t[NC_MAXVALLEN];
typedef struct nc_private {
nc_data_t key;
nc_data_t value;
} nc_private_t;
_IMPEXP_NET NETCONFIG *_netconfig_open(const char *heading);
_IMPEXP_NET char *_netconfig_find(const char *heading, const char *name, char *value,
int nbytes);
_IMPEXP_NET int _netconfig_set(const char *heading, const char *name, const char *value);
_IMPEXP_NET net_settings *_net_settings_open(const char *fname);
_IMPEXP_NET void _net_settings_makedefault(net_settings *ncw);
_IMPEXP_NET int _net_settings_save(net_settings *ncw);
_IMPEXP_NET int _net_settings_save_as(net_settings *ncw, const char *fname);
_IMPEXP_NET void _net_settings_close(net_settings *ncw);
_IMPEXP_NET int _netconfig_getnext(
NETCONFIG *netconfig,
char **name,
char **value
);
_IMPEXP_NET void _netconfig_close(NETCONFIG *netconfig);
#define net_settings_isdirty(ncw) (ncw)->_dirty
#define net_settings_makedirty(ncw, mkdirty) (ncw)->_dirty = mkdirty
#define net_settings_makedefault _net_settings_makedefault
#define netconfig_open _netconfig_open
#define net_settings_open _net_settings_open
#define netconfig_find _netconfig_find
#define netconfig_set _netconfig_set
#define net_settings_save _net_settings_save
#define net_settings_save_as _net_settings_save_as
#define net_settings_close _net_settings_close
#define netconfig_getnext _netconfig_getnext
#define netconfig_close _netconfig_close
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* _NETCONFIG_H */
-72
View File
@@ -1,72 +0,0 @@
/*
* netdebug.h
*
* Debugging message support. Nothing really network specific about
* it, but renamed from "debug.h" to distinguish it from other debug.h's
* that live around the system, and because the *&^%$#@! Metrowerks
* compiler can't deal with subdirs in include directives.
*/
/*
Copyright 1999, Be Incorporated. All Rights Reserved.
This file may be used under the terms of the Be Sample Code License.
*/
#ifndef _NETDEBUG_H
#define _NETDEBUG_H
#include <BeBuild.h>
#ifdef __cplusplus
#define EXTERNC extern "C"
#else
#define EXTERNC extern
#endif
/*
* Debug messages can go to a file, to the console, to both or to nowhere.
* Use debug_setflags() to set.
*/
#define DEBUG_CONSOLE 1
#define DEBUG_FILE 2
#define DEBUG_NOFLUSH 4
EXTERNC _IMPEXP_NET void _debug_setflags(unsigned flags);
EXTERNC _IMPEXP_NET unsigned _debug_getflags(void);
#define debug_setflags _debug_setflags
#define debug_getflags _debug_getflags
/*
* function -DDEBUG=? comment
* _____________________________________________________
* wprintf anything for warnings
* dprintf DEBUG > 0 for debugging messages
* ddprintf DEBUG > 1 for extra debugging messages
*/
EXTERNC _IMPEXP_NET int _wprintf(const char *format, ...);
EXTERNC _IMPEXP_NET int _dprintf(const char *format, ...);
/*
* Define null function "noprintf"
*/
#define noprintf (void)
#if DEBUG
#define wprintf _dprintf
#define dprintf _dprintf
#if DEBUG > 1
#define ddprintf _dprintf
#else /* DEBUG > 1 */
#define ddprintf noprintf
#endif /* DEBUG > 1 */
#else /* DEBUG */
#define wprintf _wprintf
#define dprintf noprintf
#define ddprintf noprintf
#endif /* DEBUG */
#endif /* _NETDEBUG_H */
-24
View File
@@ -1,24 +0,0 @@
#ifndef netgroup_h
#define netgroup_h
#ifndef __GLIBC__
/*
* The standard is crazy. These values "belong" to getnetgrent() and
* shouldn't be altered by the caller.
*/
int getnetgrent __P((/* const */ char **, /* const */ char **,
/* const */ char **));
int getnetgrent_r __P((char **, char **, char **, char *, int));
void endnetgrent __P((void));
#ifdef __osf__
int innetgr __P((char *, char *, char *, char *));
void setnetgrent __P((char *));
#else
void setnetgrent __P((const char *));
int innetgr __P((const char *, const char *, const char *, const char *));
#endif
#endif
#endif
-40
View File
@@ -1,40 +0,0 @@
/* 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 */
-55
View File
@@ -1,55 +0,0 @@
/* 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 */
-48
View File
@@ -1,48 +0,0 @@
/* protocols.h
* The various protocols we're likely to come across as
* they're identified in the type fields of packets...
*/
#include "netinet/in.h"
#ifndef OBOS_PROTOCOLS_H
#define OBOS_PROTOCOLS_H
/* define some protocol numbers unique to ethernet */
enum {
ETHER_IPV4 = 0x0800,
ETHER_ARP = 0x0806,
ETHER_RARP = 0x8035,
ETHER_ATALK = 0x809b, /* Appletalk */
ETHER_SNMP = 0x814c, /* SNMP */
ETHER_IPV6 = 0x86dd, /* IPv6 */
ETHER_PPPOE_DISC = 0x8863, /* PPPoE Discovery */
ETHER_PPPOE_SESS = 0x8864 /* PPPoE Session */
};
/* these are used when assigning slots in the protocol table, so they
* should tie in with IP numbers wherever possible, with other
* protocols fitting in.
* These are used in the module definitions.
*/
enum {
NS_IPV4 = IPPROTO_IP,
NS_ICMP = IPPROTO_ICMP,
NS_IGMP = IPPROTO_IGMP,
NS_TCP = IPPROTO_TCP,
NS_UDP = IPPROTO_UDP,
NS_ETHER=200,
NS_IPV6,
NS_ATALK,
NS_ARP,
NS_RARP,
NS_PPPOE,
NS_SERIAL,
NS_LOOP,
NS_SOCKET,
NS_ROUTE
};
#endif /* OBOS_PROTOCOLS_H */
-20
View File
@@ -1,20 +0,0 @@
/* raw_module.h
*/
#ifndef RAW_MODULE_H
#define RAW_MODULE_H
#include "net_module.h"
#include <KernelExport.h>
#define NET_RAW_MODULE_NAME NETWORK_MODULES_ROOT "protocols/raw"
struct raw_module_info {
struct kernel_net_module_info info;
void (*input)(struct mbuf *, int);
};
#endif /* RAW_MODULE_H */
-35
View File
@@ -1,35 +0,0 @@
/* domain.h */
/* A domain is just a container for like minded protocols! */
#ifndef _SYS_DOMAIN_H
#define _SYS_DOMAIN_H
#ifdef __cplusplus
extern "C" {
#endif
struct domain {
int dom_family; /* AF_INET and so on */
char *dom_name;
void (*dom_init)(void); /* initialise */
struct protosw *dom_protosw; /* the protocols we have */
struct domain *dom_next;
int (*dom_rtattach)(void **, int);
int dom_rtoffset;
int dom_maxrtkey;
};
extern struct domain *domains;
void add_domain (struct domain *dom, int fam);
void remove_domain (int fam);
#ifdef __cplusplus
}
#endif
#endif /* _SYS_DOMAIN_H */
-156
View File
@@ -1,156 +0,0 @@
/* protosw.h */
#ifndef _SYS_PROTOSW_H
#define _SYS_PROTOSW_H
#include <sys/socketvar.h> /* for struct socket */
#include <net/route.h>
#define PRCO_SETOPT 0
#define PRCO_GETOPT 1
/* every protocol module init's one of these and passes it into
* the add_protocol() function, defined below */
/* NB The pr_domain pointer will be filled in during the
* add_protocol() call
*/
struct protosw {
char *name;
char *mod_path;
uint16 pr_type; /* SOCK_xxx */
struct domain *pr_domain;
uint16 pr_protocol; /* protocol number */
uint16 pr_flags; /* flags, PR_xxx */
int layer; /* which layer are we? */
/* the functions! */
void (*pr_init)(void);
void (*pr_input)(struct mbuf*, int);
int (*pr_output)(struct mbuf *, struct mbuf *,
struct route *,
int, void *);
int (*pr_userreq)(struct socket *, int,
struct mbuf *,
struct mbuf *,
struct mbuf *);
int (*pr_sysctl)(int *, uint, void *, size_t *, void *, size_t);
void (*pr_ctlinput)(int, struct sockaddr *, void *);
int (*pr_ctloutput)(int, struct socket*, int, int, struct mbuf **);
struct protosw *pr_next; /* pointer to next proto structure */
struct protosw *dom_next; /* next protosw pointed by the domain */
};
/*
* Values for pr_flags.
* PR_ADDR requires PR_ATOMIC;
* PR_ADDR and PR_CONNREQUIRED are mutually exclusive.
*/
#define PR_ATOMIC 0x01 /* exchange atomic messages only */
#define PR_ADDR 0x02 /* addresses given with messages */
#define PR_CONNREQUIRED 0x04 /* connection required by protocol */
#define PR_WANTRCVD 0x08 /* want PRU_RCVD calls */
#define PR_RIGHTS 0x10 /* passes capabilities */
#define PR_ABRTACPTDIS 0x20 /* abort on accept(2) to disconnected
socket */
#define PR_SLOWHZ 2 /* 2 timeouts per second... */
#define PR_FASTHZ 5 /* 5 timeouts per second */
/*
* Defines for the userreq function req field are below.
*
* (*usrreq)(up, req, m, nam, opt);
*
* up is a (struct socket *)
* req is one of these requests,
* m is a optional mbuf chain containing a message,
* nam is an optional mbuf chain containing an address,
* opt is a pointer to a socketopt structure or nil.
*
* The protocol is responsible for disposal of the mbuf chain m,
* the caller is responsible for any space held by nam and opt.
* A non-zero return from usrreq gives an
* UNIX error number which should be passed to higher level software.
*/
#define PRU_ATTACH 0 /* attach protocol to up */
#define PRU_DETACH 1 /* detach protocol from up */
#define PRU_BIND 2 /* bind socket to address */
#define PRU_LISTEN 3 /* listen for connection */
#define PRU_CONNECT 4 /* establish connection to peer */
#define PRU_ACCEPT 5 /* accept connection from peer */
#define PRU_DISCONNECT 6 /* disconnect from peer */
#define PRU_SHUTDOWN 7 /* won't send any more data */
#define PRU_RCVD 8 /* have taken data; more room now */
#define PRU_SEND 9 /* send this data */
#define PRU_ABORT 10 /* abort (fast DISCONNECT, DETATCH) */
#define PRU_CONTROL 11 /* control operations on protocol */
#define PRU_SENSE 12 /* return status into m */
#define PRU_RCVOOB 13 /* retrieve out of band data */
#define PRU_SENDOOB 14 /* send out of band data */
#define PRU_SOCKADDR 15 /* fetch socket's address */
#define PRU_PEERADDR 16 /* fetch peer's address */
#define PRU_CONNECT2 17 /* connect two sockets */
/* begin for protocols internal use */
#define PRU_FASTTIMO 18 /* 200ms timeout */
#define PRU_SLOWTIMO 19 /* 500ms timeout */
#define PRU_PROTORCV 20 /* receive from below */
#define PRU_PROTOSEND 21 /* send to below */
#define PRU_PEEREID 22 /* get local peer eid */
#define PRU_NREQ 22
/*
* The arguments to the ctlinput routine are
* (*protosw[].pr_ctlinput)(cmd, sa, arg);
* where cmd is one of the commands below, sa is a pointer to a sockaddr,
* and arg is an optional caddr_t argument used within a protocol family.
*/
#define PRC_IFDOWN 0 /* interface transition */
#define PRC_ROUTEDEAD 1 /* select new route if possible ??? */
#define PRC_MTUINC 2 /* increase in mtu to host */
#define PRC_QUENCH2 3 /* DEC congestion bit says slow down */
#define PRC_QUENCH 4 /* some one said to slow down */
#define PRC_MSGSIZE 5 /* message size forced drop */
#define PRC_HOSTDEAD 6 /* host appears to be down */
#define PRC_HOSTUNREACH 7 /* deprecated (use PRC_UNREACH_HOST) */
#define PRC_UNREACH_NET 8 /* no route to network */
#define PRC_UNREACH_HOST 9 /* no route to host */
#define PRC_UNREACH_PROTOCOL 10 /* dst says bad protocol */
#define PRC_UNREACH_PORT 11 /* bad port # */
/* was PRC_UNREACH_NEEDFRAG 12 (use PRC_MSGSIZE) */
#define PRC_UNREACH_SRCFAIL 13 /* source route failed */
#define PRC_REDIRECT_NET 14 /* net routing redirect */
#define PRC_REDIRECT_HOST 15 /* host routing redirect */
#define PRC_REDIRECT_TOSNET 16 /* redirect for type of service & net */
#define PRC_REDIRECT_TOSHOST 17 /* redirect for tos & host */
#define PRC_TIMXCEED_INTRANS 18 /* packet lifetime expired in transit */
#define PRC_TIMXCEED_REASS 19 /* lifetime expired on reass q */
#define PRC_PARAMPROB 20 /* header incorrect */
#define PRC_NCMDS 21
#define PRC_IS_REDIRECT(cmd) \
((cmd) >= PRC_REDIRECT_NET && (cmd) <= PRC_REDIRECT_TOSHOST)
/* Network stack defines... */
// struct protosw *protocols;
enum {
NET_LAYER1 = 1,
NET_LAYER2,
NET_LAYER3,
NET_LAYER4
};
//XXX conflicts with src/add-ons/kernel/network/core/core.c:69
// void add_protosw (struct protosw *prt[], int);
void add_protocol (struct protosw *, int);
void remove_protocol (struct protosw *);
struct protosw *pffindproto(int domain, int protocol, int type);
struct protosw *pffindtype(int domain, int type);
#endif /* _SYS_PROTOSW_H */
-155
View File
@@ -1,155 +0,0 @@
/* socketvar.h */
#ifndef _SYS_SOCKETVAR_H
#define _SYS_SOCKETVAR_H
#include <OS.h>
#include <sys/uio.h>
#include <sys/socket.h>
struct mbuf;
struct sockbuf {
int32 sb_cc; /* actual chars in buffer */
int32 sb_hiwat; /* max actual char count (high water mark) */
int32 sb_mbcnt; /* chars of mbufs used */
int32 sb_mbmax; /* max chars of mbufs to use */
int32 sb_lowat; /* low water mark */
struct mbuf *sb_mb; /* the mbuf chain */
int16 sb_flags; /* flags, see below */
int32 sb_timeo; /* timeout for read/write */
sem_id sb_sleep; /* our sleep sem */
sem_id sb_pop; /* sem to wait on... */
};
#define SB_MAX (256*1024) /* default for max chars in sockbuf */
#define SB_LOCK 0x01 /* lock on data queue */
#define SB_WANT 0x02 /* someone is waiting to lock */
#define SB_WAIT 0x04 /* someone is waiting for data/space */
#define SB_SEL 0x08 /* someone is selecting */
#define SB_ASYNC 0x10 /* ASYNC I/O, need signals */
#define SB_NOINTR 0x40 /* operations not interruptible */
#define SB_KNOTE 0x80 /* kernel note attached */
#define SB_NOTIFY (SB_WAIT|SB_SEL|SB_ASYNC)
typedef void (*socket_event_callback)(void * socket, uint32 event, void * cookie);
struct socket {
uint16 so_type; /* type of socket */
uint16 so_options; /* socket options */
int16 so_linger; /* dreaded linger value */
int16 so_state; /* socket state */
char *so_pcb; /* pointer to the control block */
sem_id so_lock; /* socket lock */
sem_id so_timeo; /* our wait channel */
struct protosw *so_proto; /* pointer to protocol module */
struct socket *so_head;
struct socket *so_q0;
struct socket *so_q;
int16 so_q0len;
int16 so_qlen;
int16 so_qlimit;
int32 so_error;
// pid_t so_pgid;
uint32 so_oobmark;
/* our send/recv buffers */
struct sockbuf so_snd;
struct sockbuf so_rcv;
// event callback
socket_event_callback event_callback;
void * event_callback_cookie;
int sel_ev;
};
/* Select event bit mask */
#define SEL_READ 0x01
#define SEL_WRITE 0x02
#define SEL_EX 0x04
/*
* Socket state bits.
*/
#define SS_NOFDREF 0x001 /* no file table ref any more */
#define SS_ISCONNECTED 0x002 /* socket connected to a peer */
#define SS_ISCONNECTING 0x004 /* in process of connecting to peer */
#define SS_ISDISCONNECTING 0x008 /* in process of disconnecting */
#define SS_CANTSENDMORE 0x010 /* can't send more data to peer */
#define SS_CANTRCVMORE 0x020 /* can't receive more data from peer */
#define SS_RCVATMARK 0x040 /* at mark on input */
#define SS_ISDISCONNECTED 0x800 /* socket disconnected from peer */
#define SS_PRIV 0x080 /* privileged for broadcast, raw... */
#define SS_NBIO 0x100 /* non-blocking ops */
#define SS_ASYNC 0x200 /* async i/o notify */
#define SS_ISCONFIRMING 0x400 /* deciding to accept connection req */
#define SS_CONNECTOUT 0x1000 /* connect, not accept, at this end */
/* helpful defines... */
/* adjust counters in sb reflecting freeing of m */
#define sbfree(sb, m) { \
(sb)->sb_cc -= (m)->m_len; \
(sb)->sb_mbcnt -= MSIZE; \
if ((m)->m_flags & M_EXT) \
(sb)->sb_mbcnt -= (m)->m_ext.ext_size; \
}
#define sbspace(sb) \
(abs(min((int)((sb)->sb_hiwat - (sb)->sb_cc), \
(int)((sb)->sb_mbmax - (sb)->sb_mbcnt))))
/* do we have to send all at once on a socket? */
#define sosendallatonce(so) \
((so)->so_proto->pr_flags & PR_ATOMIC)
/* adjust counters in sb reflecting allocation of m */
#define sballoc(sb, m) { \
(sb)->sb_cc += (m)->m_len; \
(sb)->sb_mbcnt += MSIZE; \
if ((m)->m_flags & M_EXT) \
(sb)->sb_mbcnt += (m)->m_ext.ext_size; \
}
#define soreadable(so) \
((so)->so_rcv.sb_cc >= (so)->so_rcv.sb_lowat || \
((so)->so_state & SS_CANTRCVMORE) || \
(so)->so_qlen || (so)->so_error)
#define sowriteable(so) \
((sbspace(&(so)->so_snd) >= (so)->so_snd.sb_lowat) && \
(((so)->so_state & SS_ISCONNECTED) || \
(((so)->so_proto->pr_flags & PR_CONNREQUIRED) == 0) || \
((so)->so_state & SS_CANTSENDMORE) || (so)->so_error))
#define M_WAITOK 0x0000
#define M_NOWAIT 0x0001
/*
* Set lock on sockbuf sb; sleep if lock is already held.
* Unless SB_NOINTR is set on sockbuf, sleep is interruptible.
* Returns error without lock if sleep is interrupted.
*/
#define sblock(sb, wf) ((sb)->sb_flags & SB_LOCK ? \
(((wf) == M_WAITOK) ? sockbuf_lock(sb) : EWOULDBLOCK) : \
((sb)->sb_flags |= SB_LOCK), 0)
/* release lock on sockbuf sb */
#define sbunlock(sb) { \
(sb)->sb_flags &= ~SB_LOCK; \
if ((sb)->sb_flags & SB_WANT) { \
(sb)->sb_flags &= ~SB_WANT; \
wakeup((sb)->sb_sleep); \
} \
}
#define sorwakeup(so) sowakeup((so), &(so)->so_rcv)
/* we don't handle upcall for sockets */
#define sowwakeup(so) sowakeup((so), &(so)->so_snd)
#endif /* _SYS_SOCKETVAR_H */
-45
View File
@@ -1,45 +0,0 @@
#ifndef _SYS_SOCKIO_H
#define _SYS_SOCKIO_H
#include <sys/ioccom.h>
/* Socket ioctl's. */
#define SIOCSHIWAT _IOW('s', 0, int) /* set high watermark */
#define SIOCGHIWAT _IOR('s', 1, int) /* get high watermark */
#define SIOCSLOWAT _IOW('s', 2, int) /* set low watermark */
#define SIOCGLOWAT _IOR('s', 3, int) /* get low watermark */
#define SIOCATMARK _IOR('s', 7, int) /* at oob mark? */
#define SIOCADDRT _IOW('r', 10, struct ortentry) /* add route */
#define SIOCDELRT _IOW('r', 11, struct ortentry) /* delete route */
#define SIOCSIFADDR _IOW('i', 12, struct ifreq) /* set ifnet address */
#define OSIOCGIFADDR _IOWR('i', 13, struct ifreq) /* get ifnet address */
#define SIOCGIFADDR _IOWR('i', 33, struct ifreq) /* get ifnet address */
#define SIOCSIFDSTADDR _IOW('i', 14, struct ifreq) /* set p-p address */
#define OSIOCGIFDSTADDR _IOWR('i', 15, struct ifreq) /* get p-p address */
#define SIOCGIFDSTADDR _IOWR('i', 34, struct ifreq) /* get p-p address */
#define SIOCSIFFLAGS _IOW('i', 16, struct ifreq) /* set ifnet flags */
#define SIOCGIFFLAGS _IOWR('i', 17, struct ifreq) /* get ifnet flags */
#define OSIOCGIFBRDADDR _IOWR('i', 18, struct ifreq) /* get broadcast addr */
#define SIOCGIFBRDADDR _IOWR('i', 35, struct ifreq) /* get broadcast addr */
#define SIOCSIFBRDADDR _IOW('i', 19, struct ifreq) /* set broadcast addr */
#define OSIOCGIFCONF _IOWR('i', 20, struct ifconf) /* get ifnet list */
#define SIOCGIFCONF _IOWR('i', 36, struct ifconf) /* get ifnet list */
#define OSIOCGIFNETMASK _IOWR('i', 21, struct ifreq) /* get net addr mask */
#define SIOCGIFNETMASK _IOWR('i', 37, struct ifreq) /* get net addr mask */
#define SIOCSIFNETMASK _IOW('i', 22, struct ifreq) /* set net addr mask */
#define SIOCGIFMETRIC _IOWR('i', 23, struct ifreq) /* get IF metric */
#define SIOCSIFMETRIC _IOW('i', 24, struct ifreq) /* set IF metric */
#define SIOCDIFADDR _IOW('i', 25, struct ifreq) /* delete IF addr */
#define SIOCAIFADDR _IOW('i', 26, struct ifaliasreq)/* add/chg IF alias */
#define SIOCGIFDATA _IOWR('i', 27, struct ifreq) /* get if_data */
#define SIOCGIFMTU _IOWR('i', 126, struct ifreq) /* get ifnet MTU */
#define SIOCSIFMTU _IOW('i', 127, struct ifreq) /* set ifnet MTU */
#define SIOCADDMULTI _IOW('i', 49, struct ifreq) /* add m'cast addr */
#define SIOCDELMULTI _IOW('i', 50, struct ifreq) /* del m'cast addr */
#endif /* SYS_NET_IOCTL_H */
-65
View File
@@ -1,65 +0,0 @@
#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, [email protected]
** This file may be used under the terms of the OpenBeOS License.
*/
#include <OS.h>
#include <Drivers.h>
#include "net_stack_driver.h"
#ifdef __cplusplus
extern "C" {
#endif
#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 16
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;
thread_id socket_thread;
sem_id commandSemaphore; // command queue
uint32 numCommands,bufferSize;
} net_connection;
extern status_t init_userland_ipc(void);
extern void shutdown_userland_ipc(void);
#ifdef __cplusplus
} // end of extern "C"
#endif
#endif /* USERLAND_IPC_H */