Moved back from headers/posix/sys from here, where they belong.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4274 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Philippe Houdoin 2003-08-11 22:50:27 +00:00
parent 549b25ed0a
commit e8d1b6e166
4 changed files with 391 additions and 0 deletions

View File

@ -0,0 +1,35 @@
/* 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 */

View File

@ -0,0 +1,156 @@
/* 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 */

View File

@ -0,0 +1,155 @@
/* 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 {
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 */
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) \
((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) ? 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 */

View File

@ -0,0 +1,45 @@
#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 */