after many changes, the network stack can now be build
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1776 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -8,7 +8,6 @@
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h>
|
||||
#include <ByteOrder.h> /* htonl, htons, ntohl, ntohs */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -150,7 +150,7 @@ struct ifnet {
|
||||
void (*input) (struct mbuf*);
|
||||
int (*output)(struct ifnet *, struct mbuf*,
|
||||
struct sockaddr*, struct rtentry *);
|
||||
int (*ioctl) (struct ifnet *, ulong, char *);
|
||||
int (*ioctl) (struct ifnet *, ulong, caddr_t);
|
||||
};
|
||||
#define if_mtu ifd.ifi_mtu
|
||||
#define if_type ifd.ifi_type
|
||||
@@ -268,7 +268,7 @@ struct ifa_msghdr {
|
||||
void if_attach(struct ifnet *ifp);
|
||||
void if_detach(struct ifnet *ifp);
|
||||
|
||||
int ifioctl(struct socket *so, ulong cmd, char *data);
|
||||
int ifioctl(struct socket *so, ulong cmd, caddr_t data);
|
||||
int ifconf(int cmd, char *data);
|
||||
void if_init(void);
|
||||
#endif
|
||||
|
||||
@@ -142,10 +142,10 @@ struct radix_node_head {
|
||||
#define Bcopy(a, b, n) memcpy(((char *)(b)), ((char *)(a)), (unsigned)(n))
|
||||
#define Bzero(p, n) memset((char *)(p),0, (int)(n));
|
||||
#define R_Malloc(p, t, n) do { \
|
||||
(p = (t) kmalloc((unsigned int)(n))); \
|
||||
(p = (t) malloc((unsigned int)(n))); \
|
||||
memset(p, 0, sizeof(*p)); \
|
||||
} while (0)
|
||||
#define Free(p) kfree((char *)p);
|
||||
#define Free(p) free((char *)p);
|
||||
|
||||
void rn_init (void);
|
||||
int rn_inithead (void **, int);
|
||||
|
||||
@@ -37,8 +37,6 @@
|
||||
#ifndef NETINET_ICMP_VAR_H
|
||||
#define NETINET_ICMP_VAR_H
|
||||
|
||||
#include <ByteOrder.h>
|
||||
|
||||
#include "netinet/ip_icmp.h"
|
||||
|
||||
struct icmpstat {
|
||||
@@ -54,8 +52,8 @@ struct icmpstat {
|
||||
int32 icps_inhist[ICMP_MAXTYPE + 1];
|
||||
};
|
||||
|
||||
#ifdef _KERNEL_MODE
|
||||
struct icmpstat icmpstat;
|
||||
#endif
|
||||
//#ifdef _KERNEL_MODE
|
||||
//struct icmpstat icmpstat;
|
||||
//#endif
|
||||
|
||||
#endif /* NETINET_ICMP_VAR_H */
|
||||
|
||||
@@ -80,7 +80,7 @@ struct ether_header {
|
||||
#define ETHERMIN (ETHER_MIN_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)
|
||||
|
||||
|
||||
#ifdef _NETWORK_STACK
|
||||
//#ifdef _NETWORK_STACK
|
||||
|
||||
/*
|
||||
* Macro to map an IP multicast address to an Ethernet multicast address.
|
||||
@@ -115,7 +115,7 @@ struct ether_header {
|
||||
(enaddr)[4] = ((u_int8_t *)ip6addr)[14]; \
|
||||
(enaddr)[5] = ((u_int8_t *)ip6addr)[15]; \
|
||||
}
|
||||
#endif
|
||||
//#endif
|
||||
|
||||
/*
|
||||
* Structure shared between the ethernet driver modules and
|
||||
@@ -179,14 +179,14 @@ struct sockaddr_inarp {
|
||||
#define RTF_ANNOUNCE RTF_PROTO2 /* announce new arp entry */
|
||||
#define RTF_PERMANENT_ARP RTF_PROTO3 /* only manual overwrite of entry */
|
||||
|
||||
#ifdef _NETWORK_STACK
|
||||
//#ifdef _NETWORK_STACK
|
||||
|
||||
int arpresolve(struct arpcom *ac, struct rtentry *rt, struct mbuf *m,
|
||||
struct sockaddr *dst, uint8 *desten);
|
||||
void arpwhohas(struct arpcom *ac, struct in_addr *ia);
|
||||
//void arpwhohas(struct arpcom *ac, struct in_addr *ia);
|
||||
|
||||
|
||||
#else
|
||||
//#else
|
||||
|
||||
char *ether_ntoa (struct ether_addr *);
|
||||
struct ether_addr *ether_aton (char *);
|
||||
@@ -194,7 +194,7 @@ int ether_ntohost (char *, struct ether_addr *);
|
||||
int ether_hostton (char *, struct ether_addr *);
|
||||
int ether_line(char *line, struct ether_addr *e, char *hostname);
|
||||
|
||||
#endif
|
||||
//#endif
|
||||
|
||||
#endif /* NETINET_IF_ETHER_H */
|
||||
|
||||
|
||||
@@ -3,16 +3,36 @@
|
||||
#ifndef _NETINET_IN_H_
|
||||
#define _NETINET_IN_H_
|
||||
|
||||
//#include <ByteOrder.h> /* for htonl */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <net/if.h>
|
||||
#include <endian.h>
|
||||
|
||||
typedef unsigned short in_port_t;
|
||||
typedef unsigned long in_addr_t;
|
||||
|
||||
/* We can't include <ByteOrder.h> since we are a posix file,
|
||||
* and we are not allowed to import all the BeOS types here.
|
||||
*/
|
||||
#ifndef htonl
|
||||
extern unsigned long __swap_int32(unsigned long); /* private */
|
||||
extern unsigned short __swap_int16(unsigned short); /* private */
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
#define htonl(x) __swap_int32(x)
|
||||
#define ntohl(x) __swap_int32(x)
|
||||
#define htons(x) __swap_int16(x)
|
||||
#define ntohs(x) __swap_int16(x)
|
||||
#elif BYTE_ORDER == BIG_ENDIAN
|
||||
#define htonl(x) (x)
|
||||
#define ntohl(x) (x)
|
||||
#define htons(x) (x)
|
||||
#define ntohs(x) (x)
|
||||
#else
|
||||
#error Unknown byte order.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef uint16 in_port_t;
|
||||
typedef uint32 in_addr_t;
|
||||
|
||||
/* Protocol definitions - add to as required... */
|
||||
|
||||
enum {
|
||||
IPPROTO_IP = 0, /* 0, IPv4 */
|
||||
IPPROTO_ICMP = 1, /* 1, ICMP (v4) */
|
||||
@@ -137,12 +157,15 @@ struct sockaddr_in {
|
||||
#define satosin(sa) ((struct sockaddr_in *)(sa))
|
||||
#define sintosa(sin) ((struct sockaddr *)(sin))
|
||||
|
||||
struct ifnet; // forward declaration
|
||||
|
||||
/* Prototypes... */
|
||||
int in_broadcast (struct in_addr, struct ifnet *);
|
||||
int in_canforward (struct in_addr);
|
||||
int in_localaddr (struct in_addr);
|
||||
void in_socktrim (struct sockaddr_in*);
|
||||
uint16 in_cksum (struct mbuf *, int);
|
||||
/* uint16 in_cksum (struct mbuf *, int); */
|
||||
uint16 in_cksum(struct mbuf *m, int len, int off);
|
||||
|
||||
#endif /* _KERNEL_MODE */
|
||||
#endif /* NETINET_IN_H */
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* internet protcol control blocks
|
||||
*/
|
||||
|
||||
#include <sys/socketvar.h>
|
||||
//#include <sys/socketvar.h>
|
||||
#include <sys/socket.h>
|
||||
#include <pools.h>
|
||||
#include <netinet/ip.h>
|
||||
|
||||
@@ -56,7 +56,7 @@ struct in_multi {
|
||||
|
||||
#define IA_SIN(ia) (&(((struct in_ifaddr *)(ia))->ia_addr))
|
||||
|
||||
extern struct in_ifaddr *in_ifaddr;
|
||||
// extern struct in_ifaddr *in_ifaddr;
|
||||
|
||||
int in_control(struct socket *so, int cmd, char *data, struct ifnet *ifp);
|
||||
int in_ifinit(struct ifnet *dev, struct in_ifaddr *ia, struct sockaddr_in *sin,
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
#ifndef _NETINET_IP_H
|
||||
#define _NETINET_IP_H
|
||||
|
||||
//#include <ByteOrder.h>
|
||||
|
||||
#include <mbuf.h>
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
@@ -138,7 +138,7 @@ struct ipstat {
|
||||
int32 ips_outhwcsum; /* hardware checksummed on output */
|
||||
};
|
||||
|
||||
#ifdef _KERNEL_MODE
|
||||
//#ifdef _KERNEL_MODE
|
||||
|
||||
#define IP_FORWARDING 0x1 /* most of ip header exists */
|
||||
#define IP_RAWOUTPUT 0x2 /* raw ip header exists */
|
||||
@@ -146,7 +146,8 @@ struct ipstat {
|
||||
#define IP_ALLOWBROADCAST SO_BROADCAST /* can send broadcast packets */
|
||||
#define IP_MTUDISC 0x0400 /* pmtu discovery, set DF */
|
||||
|
||||
struct ipstat ipstat;
|
||||
#if 0
|
||||
//struct ipstat ipstat;
|
||||
|
||||
void ipv4_input(struct mbuf *, int);
|
||||
int ipv4_output(struct mbuf *, struct mbuf *, struct route *, int, void *);
|
||||
|
||||
@@ -52,10 +52,10 @@ struct tcp_debug {
|
||||
#define TA_RESPOND 3
|
||||
#define TA_DROP 4
|
||||
|
||||
#ifdef TANAMES
|
||||
char *tanames[] =
|
||||
{ "input", "output", "user", "respond", "drop" };
|
||||
#endif /* TANAMES */
|
||||
//#ifdef TANAMES
|
||||
//char *tanames[] =
|
||||
// { "input", "output", "user", "respond", "drop" };
|
||||
//#endif /* TANAMES */
|
||||
|
||||
#define TCP_NDEBUG 100
|
||||
struct tcp_debug tcp_debug[TCP_NDEBUG];
|
||||
|
||||
@@ -60,8 +60,8 @@
|
||||
|
||||
#define TCP_ISSINCR (125*1024) /* increment for tcp_iss each second */
|
||||
|
||||
#ifdef _NETWORK_STACK
|
||||
tcp_seq tcp_iss; /* tcp initial send seq # */
|
||||
#endif /* _NETWORK_STACK */
|
||||
//#ifdef _NETWORK_STACK
|
||||
extern tcp_seq tcp_iss; /* tcp initial send seq # */
|
||||
//#endif /* _NETWORK_STACK */
|
||||
|
||||
#endif /* _NETINET_TCP_SEQ_H_ */
|
||||
|
||||
@@ -106,10 +106,11 @@
|
||||
#define TCP_LINGERTIME 120 /* at most 2 minutes... */
|
||||
#define TCP_MAXRXTSHIFT 12 /* maximum retransmits */
|
||||
|
||||
#ifdef TCPTIMERS
|
||||
char *tcptimers[] =
|
||||
{ "REXMT", "PERSIST", "KEEP", "2MSL" };
|
||||
#endif /* TCPTIMERS */
|
||||
//#ifdef TCPTIMERS
|
||||
//char *tcptimers[] =
|
||||
// { "REXMT", "PERSIST", "KEEP", "2MSL" };
|
||||
//#endif /* TCPTIMERS */
|
||||
extern char *tcptimers[];
|
||||
|
||||
/*
|
||||
* Force a time value to be in a certain range.
|
||||
@@ -122,7 +123,7 @@ char *tcptimers[] =
|
||||
(tv) = (tvmax); \
|
||||
}
|
||||
|
||||
#ifdef _NETWORK_STACK
|
||||
//#ifdef _NETWORK_STACK
|
||||
extern int tcptv_keep_init;
|
||||
extern int tcp_keepidle; /* time before keepalive probes begin */
|
||||
extern int tcp_keepintvl; /* time between keepalive probes */
|
||||
@@ -131,6 +132,6 @@ extern int tcp_ttl; /* time to live for TCP segs */
|
||||
extern int tcp_backoff[];
|
||||
|
||||
|
||||
#endif /* _NETWORK_STACK */
|
||||
//#endif /* _NETWORK_STACK */
|
||||
|
||||
#endif /* NETINET_TCP_TIMERS_H */
|
||||
|
||||
@@ -241,12 +241,14 @@ struct tcpstat {
|
||||
#define TCPCTL_RSTPPSLIMIT 12 /* RST pps limit */
|
||||
#define TCPCTL_MAXID 13
|
||||
|
||||
#ifdef _NETWORK_STACK
|
||||
struct inpcb tcb;
|
||||
struct tcpstat tcpstat;
|
||||
int tcp_mssdflt;
|
||||
int tcp_do_rfc1323;
|
||||
unsigned long tcp_now;
|
||||
//#ifdef _NETWORK_STACK
|
||||
|
||||
extern struct inpcb tcb;
|
||||
extern struct tcpstat tcpstat;
|
||||
extern int tcp_mssdflt;
|
||||
extern int tcp_do_rfc1323;
|
||||
extern unsigned long tcp_now;
|
||||
|
||||
|
||||
void tcp_input(struct mbuf *, int);
|
||||
int tcp_output(struct tcpcb*);
|
||||
@@ -275,6 +277,6 @@ void tcp_fasttimer(void *data);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
//#endif
|
||||
|
||||
#endif /* NETINET_TCP_VAR_H */
|
||||
|
||||
@@ -145,8 +145,9 @@ struct protosw {
|
||||
NET_LAYER3,
|
||||
NET_LAYER4
|
||||
};
|
||||
|
||||
void add_protosw (struct protosw *prt[], int);
|
||||
|
||||
//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 *);
|
||||
#endif
|
||||
|
||||
@@ -5,10 +5,11 @@
|
||||
#define _SYS_SOCKETVAR_H
|
||||
|
||||
#include <OS.h>
|
||||
#include <sys/mbuf.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) */
|
||||
|
||||
@@ -1,319 +0,0 @@
|
||||
/* mbuf.h
|
||||
* network buffer definitions
|
||||
*
|
||||
* Based on BSD's mbuf principal.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef OBOS_MBUF_H
|
||||
#define OBOS_MBUF_H
|
||||
|
||||
#include <pools.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, char * 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, char * 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 */
|
||||
@@ -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 */
|
||||
@@ -58,6 +58,7 @@
|
||||
# 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
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
#ifndef OBOS_CORE_MODULE_H
|
||||
#define OBOS_CORE_MODULE_H
|
||||
|
||||
#include "sys/mbuf.h"
|
||||
#include "sys/protosw.h"
|
||||
#include "sys/socketvar.h"
|
||||
#include "netinet/in_pcb.h"
|
||||
#include "net/if.h"
|
||||
#include "net_timer.h"
|
||||
#include "net_module.h"
|
||||
#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;
|
||||
@@ -79,6 +79,8 @@ struct core_module_info {
|
||||
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);
|
||||
@@ -128,8 +130,8 @@ struct core_module_info {
|
||||
struct in_ifaddr *(*get_primary_addr)(void);
|
||||
|
||||
/* socket functions - used by socket driver */
|
||||
int (*initsocket)(void **);
|
||||
int (*socreate)(int, void *, int, int);
|
||||
int (*initsocket)(struct socket **);
|
||||
int (*socreate)(int, struct socket *, int, int);
|
||||
int (*soclose)(void *);
|
||||
int (*sobind)(void *, caddr_t, int);
|
||||
int (*solisten)(void *, int);
|
||||
@@ -145,7 +147,7 @@ struct core_module_info {
|
||||
int (*set_socket_event_callback)(void *, socket_event_callback, void *, int);
|
||||
int (*sogetpeername)(void *, struct sockaddr *, int *);
|
||||
int (*sogetsockname)(void *, struct sockaddr *, int *);
|
||||
int (*soaccept)(void *, void **, void *, int *);
|
||||
int (*soaccept)(struct socket *s, struct socket **news, void *, int *);
|
||||
};
|
||||
|
||||
#ifdef _KERNEL_MODE
|
||||
|
||||
@@ -6,17 +6,17 @@
|
||||
|
||||
#include "net_module.h"
|
||||
|
||||
#ifdef _KERNEL_
|
||||
#ifdef _KERNEL_MODE
|
||||
#include <KernelExport.h>
|
||||
#define ICMP_MODULE_PATH "network/protocol/icmp"
|
||||
#else /* _KERNEL_ */
|
||||
#else /* _KERNEL_MODE */
|
||||
#define ICMP_MODULE_PATH "modules/protocol/icmp"
|
||||
#endif /* _KERNEL_ */
|
||||
#endif /* _KERNEL_MODE */
|
||||
|
||||
struct icmp_module_info {
|
||||
struct kernel_net_module_info info;
|
||||
|
||||
#ifndef _KERNEL_
|
||||
#ifndef _KERNEL_MODE
|
||||
void (*set_core)(struct core_module_info *);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -7,16 +7,16 @@
|
||||
|
||||
#include "net_module.h"
|
||||
|
||||
#ifdef _KERNEL_
|
||||
#ifdef _KERNEL_MODE
|
||||
#include <KernelExport.h>
|
||||
#define IPV4_MODULE_PATH "network/protocol/ipv4"
|
||||
#else /* _KERNEL_ */
|
||||
#else /* _KERNEL_MODE */
|
||||
#define IPV4_MODULE_PATH "modules/protocol/ipv4"
|
||||
#endif /* _KERNEL_ */
|
||||
#endif /* _KERNEL_MODE */
|
||||
|
||||
struct ipv4_module_info {
|
||||
struct kernel_net_module_info info;
|
||||
#ifndef _KERNEL_
|
||||
#ifndef _KERNEL_MODE
|
||||
void (*set_core)(struct core_module_info *);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ struct rw_lock {
|
||||
|
||||
typedef struct rw_lock rw_lock;
|
||||
|
||||
#ifndef _KERNEL_
|
||||
#ifndef _KERNEL_MODE
|
||||
#define INIT_BENAPHORE(lock,name) \
|
||||
{ \
|
||||
(lock).count = 1; \
|
||||
@@ -70,7 +70,7 @@ typedef struct rw_lock rw_lock;
|
||||
}
|
||||
|
||||
/* read/write lock */
|
||||
#ifndef _KERNEL_
|
||||
#ifndef _KERNEL_MODE
|
||||
#define INIT_RW_LOCK(lock,name) \
|
||||
{ \
|
||||
(lock).sem = create_sem(0, name); \
|
||||
|
||||
@@ -2,18 +2,16 @@
|
||||
* Miscellaneous networking stuff that doesn't yet have a home.
|
||||
*/
|
||||
|
||||
#ifdef _NETWORK_STACK
|
||||
|
||||
#include <kernel/OS.h>
|
||||
#include <ByteOrder.h>
|
||||
#include <Errors.h>
|
||||
|
||||
#include "sys/mbuf.h"
|
||||
//#ifdef _NETWORK_STACK
|
||||
|
||||
#ifndef OBOS_NET_MISC_H
|
||||
#define OBOS_NET_MISC_H
|
||||
|
||||
#ifdef _KERNEL_
|
||||
//#include <kernel/OS.h>
|
||||
#include <Errors.h>
|
||||
#include <mbuf.h>
|
||||
|
||||
#ifdef _KERNEL_MODE
|
||||
#include <KernelExport.h>
|
||||
#define printf dprintf
|
||||
#endif
|
||||
@@ -77,7 +75,8 @@ typedef uint32 ipv4_addr;
|
||||
*/
|
||||
|
||||
void net_server_add_device(ifnet *ifn);
|
||||
uint16 in_cksum(struct mbuf *m, int len, int off);
|
||||
//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 */
|
||||
@@ -98,5 +97,5 @@ void dump_sockaddr(void *ptr);
|
||||
|
||||
#endif /* OBOS_NET_MISC_H */
|
||||
|
||||
#endif /* _NETWORK_STACK */
|
||||
//#endif /* _NETWORK_STACK */
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <kernel/OS.h>
|
||||
#include <image.h>
|
||||
|
||||
#include "sys/mbuf.h"
|
||||
#include "mbuf.h"
|
||||
#include "net_misc.h"
|
||||
#include "sys/socketvar.h"
|
||||
#include "net/if.h"
|
||||
@@ -39,18 +39,19 @@ struct net_module {
|
||||
struct net_module *next;
|
||||
char *name;
|
||||
struct kernel_net_module_info *ptr;
|
||||
#ifndef _KERNEL_
|
||||
#ifndef _KERNEL_MODE
|
||||
image_id iid;
|
||||
#endif
|
||||
int status;
|
||||
};
|
||||
|
||||
enum {
|
||||
NET_LAYER1 = 1, /* link layer */
|
||||
NET_LAYER2, /* network layer */
|
||||
NET_LAYER3, /* transport layer */
|
||||
NET_LAYER4 /* socket layer */
|
||||
};
|
||||
|
||||
//XXX already in posix/sys/protosw.h
|
||||
//enum {
|
||||
// NET_LAYER1 = 1, /* link layer */
|
||||
// NET_LAYER2, /* network layer */
|
||||
// NET_LAYER3, /* transport layer */
|
||||
// NET_LAYER4 /* socket layer */
|
||||
//};
|
||||
|
||||
#endif /* OBOS_NET_MODULE_H */
|
||||
|
||||
|
||||
@@ -2,22 +2,23 @@
|
||||
#define _NET_SOCKET_H
|
||||
|
||||
#include <sys/socketvar.h>
|
||||
#include <mbuf.h>
|
||||
|
||||
uint32 sb_max;
|
||||
//uint32 sb_max;
|
||||
|
||||
/* Function prototypes */
|
||||
|
||||
/* These are the ones we export to libnet.so */
|
||||
|
||||
int initsocket(void **);
|
||||
int socreate (int, struct socket **, int, int);
|
||||
int initsocket(struct socket **);
|
||||
int socreate (int, struct socket *, int, int);//XXX
|
||||
int soshutdown(void *, int);
|
||||
int soclose (void *);
|
||||
|
||||
int sobind (void *, char *, int);
|
||||
int solisten (void *, int);
|
||||
int soconnect (void *, char *, int);
|
||||
int soaccept (void *, void **, void *, int *);
|
||||
int soaccept (struct socket *, struct socket **, void *, int *);
|
||||
|
||||
int writeit (void *, struct iovec *, int);
|
||||
int readit (void *, struct iovec *, int *);
|
||||
@@ -28,6 +29,7 @@ int recvit (void *, struct msghdr *, char *, int *);
|
||||
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 soo_ioctl(void *sp, int cmd, caddr_t data);
|
||||
|
||||
int sogetpeername(void *, struct sockaddr *, int *);
|
||||
int sogetsockname(void *, struct sockaddr *, int *);
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
|
||||
#include <sys/select.h>
|
||||
|
||||
#define NET_STACK_DRIVER_PATH "net/stack"
|
||||
#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!!!
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include "net_module.h"
|
||||
|
||||
#ifdef _KERNEL_
|
||||
#ifdef _KERNEL_MODE
|
||||
#include <KernelExport.h>
|
||||
#define RAW_MODULE_PATH "network/protocol/raw"
|
||||
#else
|
||||
|
||||
Reference in New Issue
Block a user