It is accomplished ...

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
ejakowatz
2002-07-09 12:24:59 +00:00
commit 52a3801208
2025 changed files with 472889 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
/* domain.h */
/* A domain is just a container for like minded protocols! */
#ifndef DOMAIN_H
#define DOMAIN_H
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;
};
struct domain *domains;
void add_domain(struct domain *dom, int fam);
void remove_domain(int fam);
#endif /* DOMAIN_H */
+318
View File
@@ -0,0 +1,318 @@
/* 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! */
struct pool_ctl *mbpool;
struct pool_ctl *clpool;
int max_hdr; /* largest link+protocol header */
int max_linkhdr; /* largest link level header */
int max_protohdr; /* largest protocol header */
#endif /* OBOS_MBUF_H */
+26
View File
@@ -0,0 +1,26 @@
/* uio.h */
#ifndef NET_SYS_UIO_H
#define NET_SYS_UIO_H
enum uio_rw { UIO_READ, UIO_WRITE };
/* Segment flag values. */
enum uio_seg {
UIO_USERSPACE, /* from user data space */
UIO_SYSSPACE /* from system space */
};
struct uio {
struct iovec *uio_iov; /* pointer to array of iovecs */
int uio_iovcnt; /* number of iovecs in array */
off_t uio_offset; /* offset into file this uio corresponds to */
size_t uio_resid; /* residual i/o count */
enum uio_seg uio_segflg; /* see above */
enum uio_rw uio_rw; /* see above */
// struct proc *uio_procp; /* process if UIO_USERSPACE */
};
int uiomove(caddr_t cp, int n, struct uio *uio);
#endif /* NET_SYS_UIO_H */
+147
View File
@@ -0,0 +1,147 @@
/* protosw.h */
#ifndef PROTOSW_H
#define 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... */
#ifdef _NETWORK_STACK
struct protosw *protocols;
void add_protocol(struct protosw *pr, int fam);
void remove_protocol(struct protosw *pr);
#endif
struct protosw *pffindproto(int domain, int protocol, int type);
struct protosw *pffindtype(int domain, int type);
#endif /* PROTOSW_H */
+50
View File
@@ -0,0 +1,50 @@
/* select.h */
#ifndef _SYS_SELECT_H
#define _SYS_SELECT_H
#include <sys/time.h> /* for struct timeval */
/*
* You can define your own FDSETSIZE if you want more bits
*/
#ifndef FD_SETSIZE
#define FD_SETSIZE 1024
#endif /* FD_SETSIZE */
/* compatability with BSD */
#define NBBY 8 /* number of bits in a byte */
typedef unsigned long fd_mask;
#ifndef howmany
#define howmany(x, y) (((x) + ((y) - 1)) / (y))
#endif
/*
* Compatibily only: use FD_SETSIZE instead
*/
#ifndef FDSETSIZE
#define FDSETSIZE FD_SETSIZE
#endif /* FDSETSIZE */
#define NFDBITS 32
typedef struct fd_set {
unsigned mask[FDSETSIZE / NFDBITS];
} fd_set;
#define _FDMSKNO(fd) ((fd) / NFDBITS)
#define _FDBITNO(fd) ((fd) % NFDBITS)
#define FD_ZERO(setp) memset((setp)->mask, 0, sizeof((setp)->mask))
#define FD_SET(fd, setp) ((setp)->mask[_FDMSKNO(fd)] |= (1 << (_FDBITNO(fd))))
#define FD_CLR(fd, setp) ((setp)->mask[_FDMSKNO(fd)] &= ~(1 << (_FDBITNO(fd))))
#define FD_ISSET(fd, setp) ((setp)->mask[_FDMSKNO(fd)] & (1 << (_FDBITNO(fd))))
int select(int nbits, struct fd_set *rbits,
struct fd_set *wbits,
struct fd_set *ebits,
struct timeval *timeout);
#endif /* _SYS_SELECT_H */
+216
View File
@@ -0,0 +1,216 @@
/* sys/socket.h */
#ifndef OBOS_SYS_SOCKET_H
#define OBOS_SYS_SOCKET_H
#include <kernel/OS.h>
/* shoudl bt in types.h */
typedef uint32 socklen_t;
/* These are the address/protocol families we'll be using... */
/* NB these should be added to as required... */
/* If we want to have Binary compatability we may need to alter these
* to agree with the Be versions...
*/
#define AF_UNSPEC 0
#define AF_LOCAL 1
#define AF_UNIX AF_LOCAL /* for compatability */
#define AF_INET 2
#define AF_ROUTE 3
#define AF_IMPLINK 4
#define AF_LINK 18
#define AF_IPX 23
#define AF_INET6 24
#define AF_MAX 24
#define PF_UNSPEC AF_UNSPEC
#define PF_INET AF_INET
#define PF_ROUTE AF_ROUTE
#define PF_LINK AF_LINK
#define PF_INET6 AF_INET6
#define PF_IPX AF_IPX
#define PF_IMPLINK AF_IMPLINK
/* Types of socket we can create (eventually) */
#define SOCK_DGRAM 10
#define SOCK_STREAM 11
#define SOCK_RAW 12
#define SOCK_MISC 255
/*
* Option flags per-socket.
*/
#define SO_DEBUG 0x0001 /* turn on debugging info recording */
#define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
#define SO_REUSEADDR 0x0004 /* allow local address reuse */
#define SO_KEEPALIVE 0x0008 /* keep connections alive */
#define SO_DONTROUTE 0x0010 /* just use interface addresses */
#define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */
#define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
#define SO_LINGER 0x0080 /* linger on close if data present */
#define SO_OOBINLINE 0x0100 /* leave received OOB data in line */
#define SO_REUSEPORT 0x0200 /* allow local address & port reuse */
#define SOL_SOCKET 0xffff
/*
* Additional options, not kept in so_options.
*/
#define SO_SNDBUF 0x1001 /* send buffer size */
#define SO_RCVBUF 0x1002 /* receive buffer size */
#define SO_SNDLOWAT 0x1003 /* send low-water mark */
#define SO_RCVLOWAT 0x1004 /* receive low-water mark */
#define SO_SNDTIMEO 0x1005 /* send timeout */
#define SO_RCVTIMEO 0x1006 /* receive timeout */
#define SO_ERROR 0x1007 /* get error status and clear */
#define SO_TYPE 0x1008 /* get socket type */
#define SO_NETPROC 0x1020 /* multiplex; network processing */
/*
* These are the valid values for the "how" field used by shutdown(2).
*/
#define SHUT_RD 1
#define SHUT_WR 2
#define SHUT_RDWR 3
struct linger {
int l_onoff;
int l_linger;
};
struct sockaddr {
uint8 sa_len;
uint8 sa_family;
uint8 sa_data[30];
};
/* this can hold ANY sockaddr we care to throw at it! */
struct sockaddr_storage {
uint8 ss_len; /* total length */
uint8 ss_family; /* address family */
uint8 __ss_pad1[6]; /* align to quad */
uint64 __ss_pad2; /* force alignment for stupid compilers */
uint8 __ss_pad3[240]; /* pad to a total of 256 bytes */
};
struct sockproto {
uint16 sp_family;
uint16 sp_protocol;
};
#define CTL_NET 4
#define CTL_NET_NAMES { \
{ 0, 0 }, \
{ "unix", CTLTYPE_NODE }, \
{ "inet", CTLTYPE_NODE }, \
{ "implink", CTLTYPE_NODE }, \
{ "pup", CTLTYPE_NODE }, \
{ "chaos", CTLTYPE_NODE }, \
{ "xerox_ns", CTLTYPE_NODE }, \
{ "iso", CTLTYPE_NODE }, \
{ "emca", CTLTYPE_NODE }, \
{ "datakit", CTLTYPE_NODE }, \
{ "ccitt", CTLTYPE_NODE }, \
{ "ibm_sna", CTLTYPE_NODE }, \
{ "decnet", CTLTYPE_NODE }, \
{ "dec_dli", CTLTYPE_NODE }, \
{ "lat", CTLTYPE_NODE }, \
{ "hylink", CTLTYPE_NODE }, \
{ "appletalk", CTLTYPE_NODE }, \
{ "route", CTLTYPE_NODE }, \
{ "link_layer", CTLTYPE_NODE }, \
{ "xtp", CTLTYPE_NODE }, \
{ "coip", CTLTYPE_NODE }, \
{ "cnt", CTLTYPE_NODE }, \
{ "rtip", CTLTYPE_NODE }, \
{ "ipx", CTLTYPE_NODE }, \
{ "inet6", CTLTYPE_NODE }, \
{ "pip", CTLTYPE_NODE }, \
{ "isdn", CTLTYPE_NODE }, \
{ "natm", CTLTYPE_NODE }, \
{ "encap", CTLTYPE_NODE }, \
{ "sip", CTLTYPE_NODE }, \
{ "key", CTLTYPE_NODE }, \
}
/*
* PF_ROUTE - Routing table
*
* Three additional levels are defined:
* Fourth: address family, 0 is wildcard
* Fifth: type of info, defined below
* Sixth: flag(s) to mask with for NET_RT_FLAGS
*/
#define NET_RT_DUMP 1 /* dump; may limit to a.f. */
#define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */
#define NET_RT_IFLIST 3 /* survey interface list */
#define NET_RT_MAXID 4
#define CTL_NET_RT_NAMES { \
{ 0, 0 }, \
{ "dump", CTLTYPE_STRUCT }, \
{ "flags", CTLTYPE_STRUCT }, \
{ "iflist", CTLTYPE_STRUCT }, \
}
/* Max listen queue for a socket */
#define SOMAXCONN 5 /* defined as 128 in OpenBSD */
struct msghdr {
caddr_t msg_name; /* address we're using (optional) */
uint msg_namelen; /* length of address */
struct iovec *msg_iov; /* scatter/gather array we'll use */
uint msg_iovlen; /* # elements in msg_iov */
caddr_t msg_control; /* extra data */
uint msg_controllen; /* length of extra data */
int msg_flags; /* flags */
};
/* Defines used in msghdr structure. */
#define MSG_OOB 0x1 /* process out-of-band data */
#define MSG_PEEK 0x2 /* peek at incoming message */
#define MSG_DONTROUTE 0x4 /* send without using routing tables */
#define MSG_EOR 0x8 /* data completes record */
#define MSG_TRUNC 0x10 /* data discarded before delivery */
#define MSG_CTRUNC 0x20 /* control data lost before delivery */
#define MSG_WAITALL 0x40 /* wait for full request or error */
#define MSG_DONTWAIT 0x80 /* this message should be nonblocking */
#define MSG_BCAST 0x100 /* this message rec'd as broadcast */
#define MSG_MCAST 0x200 /* this message rec'd as multicast */
struct cmsghdr {
uint cmsg_len;
int cmsg_level;
int cmsg_type;
/* there now follows uchar[] cmsg_data */
};
/* Function declarations */
int socket (int, int, int);
int bind(int, const struct sockaddr *, int);
int connect(int, const struct sockaddr *, int);
int listen(int, int);
int accept(int, struct sockaddr *, int *);
int closesocket(int);
int shutdown(int sock, int how);
ssize_t send(int, const void *, size_t, int);
ssize_t recv(int, void *, size_t, int);
ssize_t sendto(int, const void *, size_t, int, const struct sockaddr *, size_t);
ssize_t recvfrom(int, void *, size_t, int, struct sockaddr *, size_t *);
int setsockopt(int, int, int, const void *, size_t);
int getsockopt(int, int, int, void *, size_t *);
int getpeername(int, struct sockaddr *, int *);
int getsockname(int, struct sockaddr *, int *);
/* is it really part of sockets BSD API?*/
int sysctl (int *, uint, void *, size_t *, void *, size_t);
#endif /* OBOS_SYS_SOCKET_H */
+236
View File
@@ -0,0 +1,236 @@
/* socketvar.h */
#ifndef SYS_SOCKETVAR_H
#define SYS_SOCKETVAR_H
#include <kernel/OS.h>
#include "sys/mbuf.h"
#include "sys/net_uio.h"
#include "sys/socket.h"
struct sockbuf {
uint32 sb_cc; /* actual chars in buffer */
uint32 sb_hiwat; /* max actual char count (high water mark) */
uint32 sb_mbcnt; /* chars of mbufs used */
uint32 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 */
caddr_t 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) \
((uint32) 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) ? sb_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)
#ifdef _NETWORK_STACK
uint32 sb_max;
/* Function prototypes */
/* These are the ones we export to libnet.so */
int initsocket(void **);
int socreate (int, void *, int, int);
int soshutdown(void *, int);
int soclose (void *);
int sobind (void *, caddr_t, int);
int solisten (void *, int);
int soconnect (void *, caddr_t, int);
int soaccept (void *, void **, void *, int *);
int writeit (void *, struct iovec *, int);
int readit (void *, struct iovec *, int *);
int sendit (void *, struct msghdr *, int, int *);
int recvit (void *, struct msghdr *, caddr_t, int *);
int soo_ioctl (void *, int, caddr_t);
int sosysctl (int *, uint, void *, size_t *, void *, size_t);
int sosetopt (void *, int, int, const void *, size_t);
int sogetopt (void *, int, int, void *, size_t *);
int sogetpeername(void *, struct sockaddr *, int *);
int sogetsockname(void *, struct sockaddr *, int *);
/* these are all private to the stack...although may be shared with
* other network modules.
*/
int sosend(struct socket *so, struct mbuf *addr, struct uio *uio,
struct mbuf *top, struct mbuf *control, int flags);
struct socket *sonewconn(struct socket *head, int connstatus);
int set_socket_event_callback(void *, socket_event_callback, void *, int);
int soreserve (struct socket *so, uint32 sndcc, uint32 rcvcc);
void sbrelease (struct sockbuf *sb);
int sbreserve (struct sockbuf *sb, uint32 cc);
void sbdrop (struct sockbuf *sb, int len);
void sbdroprecord (struct sockbuf *sb);
void sbflush (struct sockbuf *sb);
int sbwait (struct sockbuf *sb);
void sbappend (struct sockbuf *sb, struct mbuf *m);
int sbappendaddr (struct sockbuf *sb, struct sockaddr *asa,
struct mbuf *m0, struct mbuf *control);
int sbappendcontrol (struct sockbuf *sb, struct mbuf *m0,
struct mbuf *control);
void sbappendrecord (struct sockbuf *sb, struct mbuf *m0);
void sbcheck (struct sockbuf *sb);
void sbcompress (struct sockbuf *sb, struct mbuf *m, struct mbuf *n);
int soreceive (struct socket *so, struct mbuf **paddr, struct uio *uio,
struct mbuf **mp0, struct mbuf **controlp, int *flagsp);
void sowakeup(struct socket *so, struct sockbuf *sb);
int sbwait(struct sockbuf *sb);
int sodisconnect(struct socket *);
void sofree(struct socket *);
void sohasoutofband(struct socket *so);
void socantsendmore(struct socket *so);
void socantrcvmore(struct socket *so);
void soisconnected (struct socket *so);
void soisconnecting (struct socket *so);
void soisdisconnected (struct socket *so);
void soisdisconnecting (struct socket *so);
void soqinsque (struct socket *head, struct socket *so, int q);
int soqremque (struct socket *so, int q);
int sorflush(struct socket *so);
int sb_lock(struct sockbuf *sb);
int nsleep(sem_id chan, char *msg, int timeo);
void wakeup(sem_id chan);
#endif /* _NETWORK_STACK */
#endif /* SYS_SOCKETVAR_H */
+65
View File
@@ -0,0 +1,65 @@
/* net_ioctl.h */
#ifndef SYS_NET_IOCTL_H
#define SYS_NET_IOCTL_H
#define IOCPARM_MASK 0x1fff /* parameter length, at most 13 bits */
#define IOC_OUT (unsigned long)0x40000000
/* copy parameters in */
#define IOC_IN (unsigned long)0x80000000
/* copy paramters in and out */
#define IOC_INOUT (IOC_IN|IOC_OUT)
/* mask for IN/OUT/VOID */
#define _IOC(inout,group,num,len) \
(inout | ((len & IOCPARM_MASK) << 16) | ((group) << 8) | (num))
#define IOCGROUP(x) (((x) >> 8) & 0xff)
#define _IOR(g,n,t) _IOC(IOC_OUT, (g), (n), sizeof(t))
#define _IOW(g,n,t) _IOC(IOC_IN, (g), (n), sizeof(t))
#define _IOWR(g,n,t) _IOC(IOC_INOUT, (g), (n), sizeof(t))
#define FIONBIO _IOW('f', 126, int) /* set/clear non-blocking i/o */
#define FIONREAD _IOR('f', 127, int) /* get # bytes to read */
#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 */