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
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
SubDir OBOS_TOP src add-ons kernel drivers net ;
|
||||
|
||||
#SubInclude OBOS_TOP src add-ons kernel drivers net stack ;
|
||||
|
||||
SubInclude OBOS_TOP src add-ons kernel drivers net stack ;
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
SubDir OBOS_TOP src add-ons kernel drivers net stack ;
|
||||
|
||||
UsePrivateHeaders net ;
|
||||
UsePublicHeaders drivers kernel ;
|
||||
UsePosixHeaders ;
|
||||
|
||||
# a) Userland stack version:
|
||||
|
||||
R5KernelAddon net_stack_driver : kernel drivers bin :
|
||||
net_userstack_driver.c
|
||||
;
|
||||
# R5KernelAddon net_stack_driver : kernel drivers bin :
|
||||
# net_userstack_driver.c
|
||||
# ;
|
||||
|
||||
# For OpenBeOS we should be building the driver objects this way.
|
||||
#KernelObjects
|
||||
@@ -19,9 +17,9 @@ R5KernelAddon net_stack_driver : kernel drivers bin :
|
||||
|
||||
# b) Kernelland stack version:
|
||||
#
|
||||
#R5KernelAddon net_stack_driver : kernel drivers bin :
|
||||
# net_stack_driver.c
|
||||
# ;
|
||||
R5KernelAddon net_stack_driver : kernel drivers bin :
|
||||
net_stack_driver.c
|
||||
;
|
||||
#
|
||||
# For OpenBeOS we should be building the kernel stack driver objects this way.
|
||||
#KernelObjects
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#include <string.h>
|
||||
|
||||
// Private includes
|
||||
#include <protosw.h>
|
||||
#include <sys/protosw.h>
|
||||
#include <core_module.h>
|
||||
|
||||
/* these are missing from KernelExport.h ... */
|
||||
@@ -60,6 +60,8 @@ extern void notify_select_event(selectsync * sync, uint32 ref);
|
||||
|
||||
typedef void (*notify_select_event_function)(selectsync * sync, uint32 ref);
|
||||
|
||||
struct socket; /* forward declaration */
|
||||
|
||||
// this struct will store one select() event to monitor per thread
|
||||
typedef struct selecter {
|
||||
struct selecter * next;
|
||||
@@ -71,10 +73,10 @@ typedef struct selecter {
|
||||
|
||||
// the cookie we attach to each file descriptor opened on our driver entry
|
||||
typedef struct {
|
||||
void * socket; // NULL before ioctl(fd, NET_STACK_SOCKET/_ACCEPT)
|
||||
uint32 open_flags; // the open() flags (mostly for storing O_NONBLOCK mode)
|
||||
sem_id selecters_lock; // protect the selecters linked-list
|
||||
selecter * selecters; // the select()'ers lists (thread-aware)
|
||||
struct socket * socket; // NULL before ioctl(fd, NET_STACK_SOCKET/_ACCEPT)
|
||||
uint32 open_flags; // the open() flags (mostly for storing O_NONBLOCK mode)
|
||||
sem_id selecters_lock; // protect the selecters linked-list
|
||||
selecter * selecters; // the select()'ers lists (thread-aware)
|
||||
} net_stack_cookie;
|
||||
|
||||
#if STAY_LOADED
|
||||
@@ -113,7 +115,7 @@ static status_t unload_driver();
|
||||
*/
|
||||
|
||||
const char * g_device_names_list[] = {
|
||||
NET_STACK_DRIVER_PATH,
|
||||
NET_STACK_DRIVER_DEV,
|
||||
NULL
|
||||
};
|
||||
|
||||
@@ -763,14 +765,14 @@ static status_t keep_driver_loaded()
|
||||
|
||||
/* force the driver to stay loaded by opening himself */
|
||||
#if SHOW_INSANE_DEBUGGING
|
||||
dprintf(LOGID "keep_driver_loaded: internaly opening /dev/" NET_STACK_DRIVER_PATH " to stay loaded in memory...\n");
|
||||
dprintf(LOGID "keep_driver_loaded: internaly opening " NET_STACK_DRIVER_PATH " to stay loaded in memory...\n");
|
||||
#endif
|
||||
|
||||
g_stay_loaded_fd = open("/dev/" NET_STACK_DRIVER_PATH, 0);
|
||||
g_stay_loaded_fd = open(NET_STACK_DRIVER_PATH, 0);
|
||||
|
||||
#if SHOW_INSANE_DEBUGGING
|
||||
if (g_stay_loaded_fd < 0)
|
||||
dprintf(LOGID ERR "keep_driver_loaded: couldn't open(/dev/" NET_STACK_DRIVER_PATH")!\n");
|
||||
dprintf(LOGID ERR "keep_driver_loaded: couldn't open(" NET_STACK_DRIVER_PATH ")!\n");
|
||||
#endif
|
||||
|
||||
return B_OK;
|
||||
|
||||
@@ -138,7 +138,7 @@ static status_t execute_command(net_stack_cookie *nsc, int32 op, void *data, uin
|
||||
*/
|
||||
|
||||
const char * g_device_names_list[] = {
|
||||
NET_STACK_DRIVER_PATH,
|
||||
NET_STACK_DRIVER_DEV,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
@@ -1,2 +1,21 @@
|
||||
SubDir OBOS_TOP src add-ons kernel network core ;
|
||||
|
||||
UsePrivateHeaders net ;
|
||||
|
||||
R5KernelAddon core : kernel network :
|
||||
cksum.c
|
||||
core.c
|
||||
if.c
|
||||
ifq.c
|
||||
in.c
|
||||
inpcb.c
|
||||
mbuf.c
|
||||
misc.c
|
||||
net_timer.c
|
||||
nhash.c
|
||||
pools.c
|
||||
radix.c
|
||||
route.c
|
||||
sockbuf.c
|
||||
socket.c
|
||||
;
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef _KERNEL_
|
||||
#include <KernelExport.h>
|
||||
#ifdef _KERNEL_MODE
|
||||
#include <KernelExport.h>
|
||||
#define printf dprintf
|
||||
#endif
|
||||
|
||||
#include "net_misc.h"
|
||||
#include <netinet/in.h>
|
||||
#include <mbuf.h>
|
||||
|
||||
/* This from Stevens Vol.2 */
|
||||
#define ADDCARRY(x) (x > 65535 ? x -= 65535 : x)
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef _KERNEL_
|
||||
#ifdef _KERNEL_MODE
|
||||
#include <Drivers.h>
|
||||
#include <module.h>
|
||||
#include <KernelExport.h>
|
||||
@@ -25,7 +25,7 @@
|
||||
#include "sys/socket.h"
|
||||
#include "sys/socketvar.h"
|
||||
#include "net/if.h" /* for ifnet definition */
|
||||
#include "net_server/net_server.h"
|
||||
//#include "net_server/net_server.h"
|
||||
#include "protocols.h"
|
||||
#include "net_module.h"
|
||||
#include "net_timer.h"
|
||||
@@ -39,6 +39,7 @@
|
||||
#include "net_malloc.h"
|
||||
#include "net/if_arp.h"
|
||||
#include "netinet/if_ether.h"
|
||||
#include <net_socket.h>
|
||||
|
||||
/* Defines we need */
|
||||
#define NETWORK_INTERFACES "network/interface"
|
||||
@@ -59,7 +60,7 @@ static int init_done = 0;
|
||||
|
||||
/* Forward prototypes... */
|
||||
/* Private for this file */
|
||||
#ifdef _KERNEL_
|
||||
#ifdef _KERNEL_MODE
|
||||
static status_t core_std_ops(int32 op, ...);
|
||||
#else
|
||||
#define core_std_ops NULL
|
||||
@@ -131,6 +132,7 @@ _EXPORT struct core_module_info core_info = {
|
||||
in_setpeeraddr,
|
||||
in_pcbnotify,
|
||||
inetctlerr,
|
||||
in_cksum,
|
||||
|
||||
m_gethdr,
|
||||
m_get,
|
||||
@@ -656,7 +658,7 @@ static void domain_init(void)
|
||||
* NB these don't have any additional functions so we just use the
|
||||
* system defined module_info structures
|
||||
*/
|
||||
#ifdef _KERNEL_
|
||||
#ifdef _KERNEL_MODE
|
||||
static void find_protocol_modules(void)
|
||||
{
|
||||
void *ml = open_module_list(NETWORK_PROTOCOLS);
|
||||
@@ -953,7 +955,7 @@ static int start_stack(void)
|
||||
if (dom_lock == -1)
|
||||
dom_lock = create_sem(1, "domain_lock");
|
||||
|
||||
#ifdef _KERNEL_
|
||||
#ifdef _KERNEL_MODE
|
||||
set_sem_owner(dev_lock, B_SYSTEM_TEAM);
|
||||
set_sem_owner(proto_lock, B_SYSTEM_TEAM);
|
||||
set_sem_owner(dom_lock, B_SYSTEM_TEAM);
|
||||
@@ -984,7 +986,7 @@ static int stop_stack(void)
|
||||
printf("trying to unload modules\n");
|
||||
nm = module_list;
|
||||
do {
|
||||
#ifdef _KERNEL_
|
||||
#ifdef _KERNEL_MODE
|
||||
put_module(nm->name);
|
||||
#else
|
||||
unload_add_on(nm->iid);
|
||||
@@ -1011,7 +1013,7 @@ static int stop_stack(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef _KERNEL_
|
||||
#ifdef _KERNEL_MODE
|
||||
static status_t core_std_ops(int32 op, ...)
|
||||
{
|
||||
switch(op) {
|
||||
|
||||
@@ -4,8 +4,9 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _KERNEL_
|
||||
# include <KernelExport.h>
|
||||
#ifdef _KERNEL_MODE
|
||||
#include <KernelExport.h>
|
||||
#define printf dprintf
|
||||
#endif
|
||||
|
||||
#include "netinet/in.h"
|
||||
@@ -52,7 +53,7 @@ if_init(void)
|
||||
|
||||
|
||||
int
|
||||
ifioctl(struct socket *so, int cmd, caddr_t data)
|
||||
ifioctl(struct socket *so, ulong cmd, caddr_t data)
|
||||
{
|
||||
struct ifnet *ifp;
|
||||
struct ifreq *ifr;
|
||||
@@ -102,7 +103,7 @@ ifioctl(struct socket *so, int cmd, caddr_t data)
|
||||
struct ifnet *
|
||||
ifunit(char *name)
|
||||
{
|
||||
ifnet *d = devices;
|
||||
struct ifnet *d = devices;
|
||||
|
||||
for (d=devices;d;d = d->if_next)
|
||||
if (strcmp(d->if_name, name) == 0)
|
||||
|
||||
@@ -3,11 +3,12 @@
|
||||
#include <stdio.h>
|
||||
#include <strings.h>
|
||||
|
||||
#ifdef _KERNEL_
|
||||
#ifdef _KERNEL_MODE
|
||||
#include <KernelExport.h>
|
||||
#endif
|
||||
|
||||
#include "net/if.h"
|
||||
#include <net/if.h>
|
||||
#include <mbuf.h>
|
||||
|
||||
struct ifq *start_ifq(void)
|
||||
{
|
||||
@@ -20,7 +21,7 @@ struct ifq *start_ifq(void)
|
||||
|
||||
nifq->lock = create_sem(1, "ifq_lock");
|
||||
nifq->pop = create_sem(0, "ifq_pop");
|
||||
#ifdef _KERNEL_
|
||||
#ifdef _KERNEL_MODE
|
||||
set_sem_owner(nifq->lock, B_SYSTEM_TEAM);
|
||||
set_sem_owner(nifq->pop, B_SYSTEM_TEAM);
|
||||
#endif
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
/* in.c */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_var.h>
|
||||
#include <sys/socketvar.h>
|
||||
#include <net/if.h>
|
||||
#include <sys/sockio.h>
|
||||
#include <net/route.h>
|
||||
|
||||
#ifdef _KERNEL_
|
||||
#include <KernelExport.h>
|
||||
#ifdef _KERNEL_MODE
|
||||
#include <KernelExport.h>
|
||||
#define printf dprintf
|
||||
#endif
|
||||
|
||||
#include "netinet/in.h"
|
||||
#include "netinet/in_var.h"
|
||||
#include "sys/socketvar.h"
|
||||
#include "net/if.h"
|
||||
#include "sys/sockio.h"
|
||||
#include "net/route.h"
|
||||
|
||||
extern struct ifnet **ifnet_addrs;
|
||||
|
||||
struct in_ifaddr *in_ifaddr = NULL; //XXX is this ever initialized correctly?
|
||||
|
||||
struct in_ifaddr *get_primary_addr(void)
|
||||
{
|
||||
return in_ifaddr;
|
||||
|
||||
@@ -5,8 +5,9 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef _KERNEL_
|
||||
#include <KernelExport.h>
|
||||
#ifdef _KERNEL_MODE
|
||||
#include <KernelExport.h>
|
||||
#define printf dprintf
|
||||
#endif
|
||||
|
||||
#include "pools.h"
|
||||
@@ -16,6 +17,9 @@
|
||||
#include "net/if.h"
|
||||
#include "netinet/in_var.h"
|
||||
#include "sys/protosw.h"
|
||||
#include <net_misc.h>
|
||||
|
||||
extern struct in_ifaddr *in_ifaddr;
|
||||
|
||||
static struct pool_ctl *pcbpool = NULL;
|
||||
static struct in_addr zeroin_addr;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* network buffer implementation
|
||||
*/
|
||||
|
||||
#ifndef _KERNEL_
|
||||
#ifndef _KERNEL_MODE
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "net_misc.h"
|
||||
#include "pools.h"
|
||||
|
||||
#ifdef _KERNEL_
|
||||
#ifdef _KERNEL_MODE
|
||||
#include <KernelExport.h>
|
||||
#endif
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <stdio.h>
|
||||
#include <strings.h>
|
||||
|
||||
#ifdef _KERNEL_
|
||||
#ifdef _KERNEL_MODE
|
||||
#include <KernelExport.h>
|
||||
#endif
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <OS.h>
|
||||
#include <malloc.h>
|
||||
|
||||
#ifdef _KERNEL_
|
||||
#ifdef _KERNEL_MODE
|
||||
#include <KernelExport.h>
|
||||
#endif
|
||||
|
||||
@@ -54,7 +54,7 @@ net_init_timer(void)
|
||||
if (gTimerInfo.ti_wait < B_OK)
|
||||
return B_ERROR;
|
||||
|
||||
#ifdef _KERNEL_
|
||||
#ifdef _KERNEL_MODE
|
||||
set_sem_owner(gTimerInfo.ti_lock, B_SYSTEM_TEAM);
|
||||
set_sem_owner(gTimerInfo.ti_wait, B_SYSTEM_TEAM);
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "net_misc.h"
|
||||
#include "net_malloc.h"
|
||||
|
||||
#ifdef _KERNEL_
|
||||
#ifdef _KERNEL_MODE
|
||||
#include <KernelExport.h>
|
||||
#define AREA_ADDR_FLAG B_ANY_KERNEL_ADDRESS
|
||||
#define AREA_FLAGS B_NO_LOCK
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
|
||||
#include "netinet/in.h"
|
||||
|
||||
#ifdef _KERNEL_
|
||||
#ifdef _KERNEL_MODE
|
||||
#include <KernelExport.h>
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/* route.c */
|
||||
|
||||
#ifndef _KERNEL_
|
||||
#ifndef _KERNEL_MODE
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
#include <kernel/OS.h>
|
||||
|
||||
#ifdef _KERNEL_
|
||||
#ifdef _KERNEL_MODE
|
||||
#include <KernelExport.h>
|
||||
#endif
|
||||
|
||||
|
||||
@@ -3,16 +3,16 @@
|
||||
#include <stdio.h>
|
||||
#include <kernel/OS.h>
|
||||
|
||||
#ifdef _KERNEL_
|
||||
#ifdef _KERNEL_MODE
|
||||
#include <KernelExport.h>
|
||||
#endif
|
||||
|
||||
#include "sys/socket.h"
|
||||
#include "sys/socketvar.h"
|
||||
#include "pools.h"
|
||||
#include "netinet/in_pcb.h"
|
||||
#include "net_misc.h"
|
||||
#include "protocols.h"
|
||||
#include <sys/socket.h>
|
||||
#include <net_socket.h>
|
||||
#include <pools.h>
|
||||
#include <netinet/in_pcb.h>
|
||||
#include <net_misc.h>
|
||||
#include <protocols.h>
|
||||
|
||||
uint32 sb_max = SB_MAX; /* hard value, recompile needed to alter :( */
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include <kernel/OS.h>
|
||||
#include <iovec.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "sys/socket.h"
|
||||
@@ -17,8 +16,10 @@
|
||||
#include "netinet/in_pcb.h"
|
||||
#include "net_misc.h"
|
||||
#include "protocols.h"
|
||||
#include "sys/net_uio.h"
|
||||
#ifdef _KERNEL_
|
||||
#include "sys/uio.h"
|
||||
#include <net_socket.h>
|
||||
|
||||
#ifdef _KERNEL_MODE
|
||||
#include <KernelExport.h>
|
||||
#include "core_module.h"
|
||||
#endif
|
||||
@@ -91,8 +92,8 @@ int uiomove(caddr_t cp, int n, struct uio *uio)
|
||||
else
|
||||
ptr = memcpy(cp, iov->iov_base, cnt);
|
||||
|
||||
if (!ptr)
|
||||
return (errno);
|
||||
// if (!ptr)
|
||||
// return (errno);
|
||||
break;
|
||||
}
|
||||
iov->iov_base = (caddr_t)iov->iov_base + cnt;
|
||||
@@ -105,7 +106,7 @@ int uiomove(caddr_t cp, int n, struct uio *uio)
|
||||
return (error);
|
||||
}
|
||||
|
||||
int initsocket(void **sp)
|
||||
int initsocket(struct socket **sp)
|
||||
{
|
||||
struct socket *so;
|
||||
|
||||
@@ -123,10 +124,10 @@ int initsocket(void **sp)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int socreate(int dom, void *sp, int type, int proto)
|
||||
int socreate(int dom, struct socket *sp, int type, int proto)
|
||||
{
|
||||
struct protosw *prm = NULL; /* protocol module */
|
||||
struct socket *so = (struct socket*)sp;
|
||||
struct socket *so = sp;
|
||||
int error;
|
||||
|
||||
if (so == NULL) {
|
||||
@@ -165,7 +166,7 @@ int socreate(int dom, void *sp, int type, int proto)
|
||||
so->so_timeo < 0)
|
||||
return ENOMEM;
|
||||
|
||||
#ifdef _KERNEL_
|
||||
#ifdef _KERNEL_MODE
|
||||
set_sem_owner(so->so_rcv.sb_pop, B_SYSTEM_TEAM);
|
||||
set_sem_owner(so->so_snd.sb_pop, B_SYSTEM_TEAM);
|
||||
set_sem_owner(so->so_timeo, B_SYSTEM_TEAM);
|
||||
@@ -316,7 +317,7 @@ struct socket *sonewconn(struct socket *head, int connstatus)
|
||||
|
||||
if (head->so_qlen + head->so_q0len > 3 * head->so_qlimit / 2)
|
||||
return NULL;
|
||||
if (initsocket((void**)&so) < 0)
|
||||
if (initsocket(&so) < 0)
|
||||
return NULL;
|
||||
|
||||
so->so_type = head->so_type;
|
||||
@@ -469,7 +470,7 @@ int sosend(struct socket *so, struct mbuf *addr, struct uio *uio, struct mbuf *t
|
||||
if (control)
|
||||
clen = control->m_len;
|
||||
|
||||
#define snderr(errno) { error = errno; /* unlock */ goto release; }
|
||||
#define snderr(err) { error = err; /* unlock */ goto release; }
|
||||
restart:
|
||||
if ((error = sblock(&so->so_snd, SBLOCKWAIT(flags))))
|
||||
goto out;
|
||||
@@ -1512,9 +1513,8 @@ int sogetpeername(void *sp, struct sockaddr *sa, int * alen)
|
||||
return error;
|
||||
}
|
||||
|
||||
int soaccept(void *sp, void **nsp, void *data, int *alen)
|
||||
int soaccept(struct socket *so, struct socket **nsp, void *data, int *alen)
|
||||
{
|
||||
struct socket * so = (struct socket *)sp;
|
||||
int len;
|
||||
int error;
|
||||
struct mbuf *nam;
|
||||
|
||||
@@ -1,2 +1,7 @@
|
||||
SubDir OBOS_TOP src add-ons kernel network interfaces ethernet ;
|
||||
|
||||
UsePrivateHeaders net ;
|
||||
|
||||
R5KernelAddon ethernet : kernel network interfaces :
|
||||
ethernet.c
|
||||
;
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#ifdef _KERNEL_MODE
|
||||
#include <KernelExport.h>
|
||||
#define spawn_thread spawn_kernel_thread
|
||||
#define printf dprintf
|
||||
|
||||
/* forward prototypes */
|
||||
int ether_dev_start(ifnet *dev);
|
||||
@@ -57,11 +58,12 @@ static int32 arp_allocated = 0; /* how many arp entries have we created? */
|
||||
int32 ether_input(void *data);
|
||||
int ether_output(struct ifnet *ifp, struct mbuf *buf, struct sockaddr *dst,
|
||||
struct rtentry *rt0);
|
||||
static int ether_ioctl(struct ifnet *ifp, int cmd, caddr_t data);
|
||||
static int ether_ioctl(struct ifnet *ifp, ulong cmd, caddr_t data);
|
||||
int ether_dev_attach(ifnet *dev);
|
||||
int ether_dev_stop(ifnet *dev);
|
||||
void arp_rtrequest(int req, struct rtentry *rt, struct sockaddr *sa);
|
||||
static void arpinput(struct mbuf *m);
|
||||
static void arpwhohas(struct arpcom *ac, struct in_addr *ia);
|
||||
|
||||
|
||||
#define DRIVER_DIRECTORY "/dev/net"
|
||||
@@ -595,7 +597,7 @@ static void arprequest(struct arpcom *ac, uint32 *sip, uint32 *tip, uint8 *enadd
|
||||
(*ac->ac_if.output)(&ac->ac_if, m, &sa, NULL);
|
||||
}
|
||||
|
||||
void arpwhohas(struct arpcom *ac, struct in_addr *ia)
|
||||
static void arpwhohas(struct arpcom *ac, struct in_addr *ia)
|
||||
{
|
||||
arprequest(ac, &ac->ac_ipaddr.s_addr, &ia->s_addr, ac->ac_enaddr);
|
||||
}
|
||||
@@ -787,7 +789,7 @@ void arp_init(void)
|
||||
|
||||
}
|
||||
|
||||
static int ether_ioctl(struct ifnet *ifp, int cmd, caddr_t data)
|
||||
static int ether_ioctl(struct ifnet *ifp, ulong cmd, caddr_t data)
|
||||
{
|
||||
struct arpcom *ac = (struct arpcom *)ifp;
|
||||
struct ifaddr *ifa = (struct ifaddr*)data;
|
||||
@@ -920,7 +922,7 @@ static int32 std_ops(int32 op, ...)
|
||||
get_module(CORE_MODULE_PATH, (module_info**)&core);
|
||||
if (!core)
|
||||
return B_ERROR;
|
||||
#ifdef _KERNEL_
|
||||
#ifdef _KERNEL_MODE
|
||||
load_driver_symbols("ethernet");
|
||||
#endif
|
||||
return B_OK;
|
||||
|
||||
@@ -1,2 +1,7 @@
|
||||
SubDir OBOS_TOP src add-ons kernel network interfaces loopback ;
|
||||
|
||||
UsePrivateHeaders net ;
|
||||
|
||||
R5KernelAddon loopback : kernel network interfaces :
|
||||
loopback.c
|
||||
;
|
||||
|
||||
@@ -19,8 +19,9 @@
|
||||
#include "net_module.h"
|
||||
#include "core_funcs.h"
|
||||
|
||||
#ifdef _KERNEL_
|
||||
#ifdef _KERNEL_MODE
|
||||
#include <KernelExport.h>
|
||||
#define printf dprintf
|
||||
#define LOOP_MODULE_PATH "network/interfaces/loopback"
|
||||
#else
|
||||
#define LOOP_MODULE_PATH "interfaces/loopback"
|
||||
@@ -84,7 +85,7 @@ static int loopback_dev_stop(struct ifnet *dev)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int loopback_ioctl(struct ifnet *ifp, int cmd, caddr_t data)
|
||||
static int loopback_ioctl(struct ifnet *ifp, ulong cmd, caddr_t data)
|
||||
{
|
||||
int error = 0;
|
||||
|
||||
|
||||
@@ -1,2 +1,7 @@
|
||||
SubDir OBOS_TOP src add-ons kernel network protocols icmp ;
|
||||
|
||||
UsePrivateHeaders net ;
|
||||
|
||||
R5KernelAddon icmp : kernel network protocols :
|
||||
icmp.c
|
||||
;
|
||||
|
||||
@@ -21,11 +21,11 @@
|
||||
#include "core_module.h"
|
||||
#include "net_module.h"
|
||||
#include "core_funcs.h"
|
||||
#include "raw/raw_module.h"
|
||||
#include "raw_module.h"
|
||||
#include "icmp_module.h"
|
||||
#include "../ipv4/ipv4_module.h"
|
||||
#include "ipv4_module.h"
|
||||
|
||||
#ifdef _KERNEL_
|
||||
#ifdef _KERNEL_MODE
|
||||
#include <KernelExport.h>
|
||||
static status_t icmp_ops(int32 op, ...);
|
||||
#else
|
||||
@@ -38,10 +38,12 @@ static struct raw_module_info *raw = NULL;
|
||||
static struct protosw* proto[IPPROTO_MAX];
|
||||
static struct in_ifaddr *ic_ifaddr = NULL;
|
||||
static struct ipv4_module_info *ipm = NULL;
|
||||
#ifndef _KERNEL_
|
||||
#ifndef _KERNEL_MODE
|
||||
static image_id ipid = -1;
|
||||
#endif
|
||||
|
||||
struct icmpstat icmpstat;
|
||||
|
||||
static struct route icmprt;
|
||||
|
||||
#if SHOW_DEBUG
|
||||
@@ -120,7 +122,7 @@ static void icmp_reflect(struct mbuf *m)
|
||||
ia = (struct in_ifaddr*)ifaof_ifpforaddr((struct sockaddr*)&icmpdst,
|
||||
m->m_pkthdr.rcvif);
|
||||
if (ia == NULL)
|
||||
ia = in_ifaddr;
|
||||
ia = get_primary_addr(); //XXX is this right?
|
||||
t = IA_SIN(ia)->sin_addr;
|
||||
ip->ip_src = t;
|
||||
ip->ip_ttl = MAXTTL;
|
||||
@@ -418,7 +420,7 @@ static int icmp_protocol_init(void *cpp)
|
||||
add_domain(NULL, AF_INET);
|
||||
add_protocol(&my_proto, AF_INET);
|
||||
|
||||
#ifndef _KERNEL_
|
||||
#ifndef _KERNEL_MODE
|
||||
if (!ipm) {
|
||||
char path[PATH_MAX];
|
||||
getcwd(path, PATH_MAX);
|
||||
@@ -453,7 +455,7 @@ static int icmp_protocol_stop(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef _KERNEL_
|
||||
#ifndef _KERNEL_MODE
|
||||
void set_core(struct core_module_info *cp)
|
||||
{
|
||||
core = cp;
|
||||
@@ -470,13 +472,13 @@ _EXPORT struct icmp_module_info protocol_info = {
|
||||
icmp_protocol_init,
|
||||
icmp_protocol_stop
|
||||
},
|
||||
#ifndef _KERNEL_
|
||||
#ifndef _KERNEL_MODE
|
||||
set_core,
|
||||
#endif
|
||||
icmp_error
|
||||
};
|
||||
|
||||
#ifdef _KERNEL_
|
||||
#ifdef _KERNEL_MODE
|
||||
static status_t icmp_ops(int32 op, ...)
|
||||
{
|
||||
switch(op) {
|
||||
|
||||
@@ -1,2 +1,7 @@
|
||||
SubDir OBOS_TOP src add-ons kernel network protocols ipv4 ;
|
||||
|
||||
UsePrivateHeaders net ;
|
||||
|
||||
R5KernelAddon ipv4 : kernel network protocols :
|
||||
ipv4.c
|
||||
;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* simple ipv4 implementation
|
||||
*/
|
||||
|
||||
#ifndef _KERNEL_
|
||||
#ifndef _KERNEL_MODE
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
@@ -25,14 +25,14 @@
|
||||
#include "core_funcs.h"
|
||||
#include "net_module.h"
|
||||
#include "ipv4_module.h"
|
||||
#include "../icmp/icmp_module.h"
|
||||
#include "icmp_module.h"
|
||||
|
||||
#ifdef _KERNEL_
|
||||
#ifdef _KERNEL_MODE
|
||||
#include <KernelExport.h>
|
||||
static status_t ipv4_ops(int32 op, ...);
|
||||
#else
|
||||
#define ipv4_ops NULL
|
||||
#endif /* _KERNEL_ */
|
||||
#endif /* _KERNEL_MODE */
|
||||
|
||||
#define INA struct in_ifaddr *
|
||||
#define SA struct sockaddr *
|
||||
@@ -46,17 +46,29 @@ static uint16 ip_id = 0;
|
||||
static sem_id id_lock = -1;
|
||||
static struct in_ifaddr *ip_ifaddr = NULL;
|
||||
static struct icmp_module_info *icmp = NULL;
|
||||
#ifndef _KERNEL_
|
||||
#ifndef _KERNEL_MODE
|
||||
static image_id icmpid = -1;
|
||||
#endif
|
||||
static struct ipq ipq;
|
||||
static net_timer_id timerid;
|
||||
|
||||
struct ipstat ipstat; //XXX might need to be shared
|
||||
|
||||
static void ipv4_input(struct mbuf *, int);
|
||||
static int ipv4_output(struct mbuf *, struct mbuf *, struct route *, int, void *);
|
||||
static int ipv4_ctloutput(int, struct socket *, int, int, struct mbuf **);
|
||||
|
||||
static int ip_dooptions(struct mbuf *);
|
||||
static void ip_stripoptions(struct mbuf *, struct mbuf *);
|
||||
static struct mbuf *ip_srcroute(void);
|
||||
|
||||
|
||||
|
||||
/* ??? - Globals we need to remove... TLS storage? */
|
||||
struct route ipforward_rt;
|
||||
|
||||
/* Forward prototypes */
|
||||
int ipv4_output(struct mbuf *, struct mbuf *, struct route *, int, void *);
|
||||
//int ipv4_output(struct mbuf *, struct mbuf *, struct route *, int, void *);
|
||||
|
||||
#if SHOW_DEBUG
|
||||
static void dump_ipv4_header(struct mbuf *buf)
|
||||
@@ -108,7 +120,7 @@ static struct ip_srcrt {
|
||||
* will be moved, and return value is their length.
|
||||
* XXX should be deleted; last arg currently ignored.
|
||||
*/
|
||||
void ip_stripoptions(struct mbuf *m, struct mbuf *mopt)
|
||||
static void ip_stripoptions(struct mbuf *m, struct mbuf *mopt)
|
||||
{
|
||||
int i;
|
||||
struct ip *ip = mtod(m, struct ip *);
|
||||
@@ -301,7 +313,7 @@ static void ip_forward(struct mbuf *m, int srcrt)
|
||||
icmp->error(mcopy, type, code, dest, destifp);
|
||||
}
|
||||
|
||||
int ip_dooptions(struct mbuf *m)
|
||||
static int ip_dooptions(struct mbuf *m)
|
||||
{
|
||||
struct ip *ip = mtod(m, struct ip*);
|
||||
uint8 *cp;
|
||||
@@ -445,7 +457,7 @@ bad:
|
||||
}
|
||||
|
||||
|
||||
struct mbuf * ip_srcroute(void)
|
||||
static struct mbuf * ip_srcroute(void)
|
||||
{
|
||||
struct in_addr *p, *q;
|
||||
struct mbuf *m;
|
||||
@@ -820,7 +832,7 @@ static int ip_optcopy(struct ip *ip, struct ip *jp)
|
||||
return (optlen);
|
||||
}
|
||||
|
||||
int ipv4_output(struct mbuf *m0, struct mbuf *opt, struct route *ro,
|
||||
static int ipv4_output(struct mbuf *m0, struct mbuf *opt, struct route *ro,
|
||||
int flags, void *optp)
|
||||
{
|
||||
struct mbuf *m = m0;
|
||||
@@ -1173,7 +1185,7 @@ static int ipv4_module_init(void *cpp)
|
||||
add_domain(NULL, AF_INET);
|
||||
add_protocol(&my_proto, AF_INET);
|
||||
|
||||
#ifndef _KERNEL_
|
||||
#ifndef _KERNEL_MODE
|
||||
if (!icmp) {
|
||||
char path[PATH_MAX];
|
||||
getcwd(path, PATH_MAX);
|
||||
@@ -1210,7 +1222,7 @@ static int ipv4_module_stop(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef _KERNEL_
|
||||
#ifndef _KERNEL_MODE
|
||||
void set_core(struct core_module_info *cp)
|
||||
{
|
||||
core = cp;
|
||||
@@ -1228,7 +1240,7 @@ _EXPORT struct ipv4_module_info protocol_info = {
|
||||
ipv4_module_stop
|
||||
},
|
||||
|
||||
#ifndef _KERNEL_
|
||||
#ifndef _KERNEL_MODE
|
||||
set_core,
|
||||
#endif
|
||||
|
||||
@@ -1240,7 +1252,7 @@ _EXPORT struct ipv4_module_info protocol_info = {
|
||||
ip_srcroute
|
||||
};
|
||||
|
||||
#ifdef _KERNEL_
|
||||
#ifdef _KERNEL_MODE
|
||||
static status_t ipv4_ops(int32 op, ...)
|
||||
{
|
||||
switch (op) {
|
||||
|
||||
@@ -1,2 +1,7 @@
|
||||
SubDir OBOS_TOP src add-ons kernel network protocols raw ;
|
||||
|
||||
UsePrivateHeaders net ;
|
||||
|
||||
R5KernelAddon raw : kernel network protocols :
|
||||
raw.c
|
||||
;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* raw.c */
|
||||
|
||||
#ifndef _KERNEL_
|
||||
#ifndef _KERNEL_MODE
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#endif
|
||||
@@ -16,13 +16,13 @@
|
||||
#include "core_module.h"
|
||||
#include "net_module.h"
|
||||
#include "core_funcs.h"
|
||||
#include "raw/raw_module.h"
|
||||
#include "ipv4/ipv4_module.h"
|
||||
#include "raw_module.h"
|
||||
#include "ipv4_module.h"
|
||||
|
||||
#ifdef _KERNEL_
|
||||
#ifdef _KERNEL_MODE
|
||||
#include <KernelExport.h>
|
||||
static status_t raw_ops(int32 op, ...);
|
||||
#else /* _KERNEL_ */
|
||||
#else /* _KERNEL_MODE */
|
||||
#define raw_ops NULL
|
||||
static image_id ipid;
|
||||
#endif
|
||||
@@ -35,6 +35,8 @@ static struct sockaddr_in ripsrc;
|
||||
static int rip_sendspace = 8192;
|
||||
static int rip_recvspace = 8192;
|
||||
|
||||
struct ipstat ipstat; //XXX might need to be shared
|
||||
|
||||
void rip_init(void)
|
||||
{
|
||||
rawinpcb.inp_next = rawinpcb.inp_prev = &rawinpcb;
|
||||
@@ -260,7 +262,7 @@ int rip_ctloutput(int op, struct socket *so, int level,
|
||||
break;
|
||||
/* XXX - Add other options here */
|
||||
}
|
||||
#ifdef _KERNEL_
|
||||
#ifdef _KERNEL_MODE
|
||||
return ipm->ctloutput(op, so, level, optnum, m);
|
||||
#else
|
||||
/* XXX - get this working for app...? */
|
||||
@@ -297,7 +299,7 @@ static int raw_module_init(void *cpp)
|
||||
add_domain(NULL, AF_INET);
|
||||
add_protocol(&my_protocol, AF_INET);
|
||||
|
||||
#ifndef _KERNEL_
|
||||
#ifndef _KERNEL_MODE
|
||||
if (!ipm) {
|
||||
char path[PATH_MAX];
|
||||
getcwd(path, PATH_MAX);
|
||||
@@ -328,7 +330,7 @@ static int raw_module_init(void *cpp)
|
||||
|
||||
static int raw_module_stop(void)
|
||||
{
|
||||
#ifndef _KERNEL_
|
||||
#ifndef _KERNEL_MODE
|
||||
unload_add_on(ipid);
|
||||
#else
|
||||
put_module(IPV4_MODULE_PATH);
|
||||
@@ -353,7 +355,7 @@ _EXPORT struct raw_module_info protocol_info = {
|
||||
&rip_input
|
||||
};
|
||||
|
||||
#ifdef _KERNEL_
|
||||
#ifdef _KERNEL_MODE
|
||||
static status_t raw_ops(int32 op, ...)
|
||||
{
|
||||
switch(op) {
|
||||
|
||||
@@ -1,2 +1,12 @@
|
||||
SubDir OBOS_TOP src add-ons kernel network protocols tcp ;
|
||||
|
||||
UsePrivateHeaders net ;
|
||||
|
||||
R5KernelAddon tcp : kernel network protocols :
|
||||
arc4random.c
|
||||
tcp.c
|
||||
tcp_debug.c
|
||||
tcp_input.c
|
||||
tcp_output.c
|
||||
tcp_timer.c
|
||||
;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* udp.c
|
||||
*/
|
||||
|
||||
#ifndef _KERNEL_
|
||||
#ifndef _KERNEL_MODE
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#endif
|
||||
@@ -26,14 +26,14 @@
|
||||
#include "core_module.h"
|
||||
#include "net_module.h"
|
||||
#include "core_funcs.h"
|
||||
#include "ipv4/ipv4_module.h"
|
||||
#include "ipv4_module.h"
|
||||
#include "net_timer.h"
|
||||
|
||||
#ifdef _KERNEL_
|
||||
#ifdef _KERNEL_MODE
|
||||
#include <KernelExport.h>
|
||||
#define TCP_MODULE_PATH "network/protocol/tcp"
|
||||
static status_t tcp_ops(int32 op, ...);
|
||||
#else /* _KERNEL_ */
|
||||
#else /* _KERNEL_MODE */
|
||||
#define tcp_ops NULL
|
||||
#define TCP_MODULE_PATH "modules/protocol/tcp"
|
||||
static image_id ipid = -1;
|
||||
@@ -59,6 +59,20 @@ struct inpcb *tcp_last_inpcb = NULL;
|
||||
static uint32 tcp_sendspace = 8192; /* size of send buffer */
|
||||
static uint32 tcp_recvspace = 8192; /* size of recieve buffer */
|
||||
|
||||
/* was in tcp_var.h */
|
||||
struct inpcb tcb;
|
||||
struct tcpstat tcpstat;
|
||||
int tcp_mssdflt;
|
||||
int tcp_do_rfc1323;
|
||||
unsigned long tcp_now;
|
||||
|
||||
/* was in tcp_seq.h */
|
||||
tcp_seq tcp_iss; /* tcp initial send seq # */
|
||||
|
||||
|
||||
// XXX shared? look into sockbuf.c
|
||||
uint32 sb_max = SB_MAX;
|
||||
|
||||
void tcp_init(void)
|
||||
{
|
||||
tcp_now = arc4random() / 2;
|
||||
@@ -520,7 +534,7 @@ static int tcp_module_init(void *cpp)
|
||||
add_domain(NULL, AF_INET);
|
||||
add_protocol(&my_proto, AF_INET);
|
||||
|
||||
#ifndef _KERNEL_
|
||||
#ifndef _KERNEL_MODE
|
||||
if (!ipm) {
|
||||
char path[PATH_MAX];
|
||||
getcwd(path, PATH_MAX);
|
||||
@@ -553,7 +567,7 @@ static int tcp_module_stop(void)
|
||||
net_remove_timer(slowtim);
|
||||
net_remove_timer(fasttim);
|
||||
|
||||
#ifndef _KERNEL_
|
||||
#ifndef _KERNEL_MODE
|
||||
unload_add_on(ipid);
|
||||
#else
|
||||
put_module(IPV4_MODULE_PATH);
|
||||
@@ -575,7 +589,7 @@ _EXPORT struct kernel_net_module_info protocol_info = {
|
||||
tcp_module_stop
|
||||
};
|
||||
|
||||
#ifdef _KERNEL_
|
||||
#ifdef _KERNEL_MODE
|
||||
static status_t tcp_ops(int32 op, ...)
|
||||
{
|
||||
switch(op) {
|
||||
|
||||
@@ -71,14 +71,15 @@
|
||||
|
||||
#ifdef TCPDEBUG
|
||||
/* load symbolic names */
|
||||
char *tanames[] = { "input", "output", "user", "respond", "drop" };
|
||||
|
||||
#define PRUREQUESTS
|
||||
#define TCPSTATES
|
||||
#define TCPTIMERS
|
||||
#define TANAMES
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <mbuf.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <net/route.h>
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
* Research Laboratory (NRL).
|
||||
*/
|
||||
|
||||
#ifndef _KERNEL_
|
||||
#ifndef _KERNEL_MODE
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
@@ -98,9 +98,9 @@
|
||||
|
||||
#include "core_module.h"
|
||||
#include "core_funcs.h"
|
||||
#include "ipv4/ipv4_module.h"
|
||||
#include "ipv4_module.h"
|
||||
|
||||
#ifdef _KERNEL_
|
||||
#ifdef _KERNEL_MODE
|
||||
#include <KernelExport.h>
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* tcp_output.c */
|
||||
|
||||
#ifndef _KERNEL_
|
||||
#ifndef _KERNEL_MODE
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
@@ -20,9 +20,9 @@
|
||||
|
||||
#include "core_module.h"
|
||||
#include "core_funcs.h"
|
||||
#include "ipv4/ipv4_module.h"
|
||||
#include "ipv4_module.h"
|
||||
|
||||
#ifdef _KERNEL_
|
||||
#ifdef _KERNEL_MODE
|
||||
#include <KernelExport.h>
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* tcp_timer.c */
|
||||
|
||||
#ifndef _KERNEL_
|
||||
#ifndef _KERNEL_MODE
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
@@ -15,12 +15,15 @@
|
||||
#include "core_module.h"
|
||||
#include "core_funcs.h"
|
||||
|
||||
#ifdef _KERNEL_
|
||||
#ifdef _KERNEL_MODE
|
||||
#include <KernelExport.h>
|
||||
#endif
|
||||
|
||||
extern struct core_module_info *core;
|
||||
|
||||
char *tcptimers[] =
|
||||
{ "REXMT", "PERSIST", "KEEP", "2MSL" };
|
||||
|
||||
int tcp_backoff[TCP_MAXRXTSHIFT + 1] =
|
||||
{ 1, 2, 4, 8, 16, 32, 64, 64, 64, 64, 64, 64, 64 };
|
||||
|
||||
|
||||
@@ -1,2 +1,7 @@
|
||||
SubDir OBOS_TOP src add-ons kernel network protocols udp ;
|
||||
|
||||
UsePrivateHeaders net ;
|
||||
|
||||
R5KernelAddon udp : kernel network protocols :
|
||||
udp.c
|
||||
;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* udp.c
|
||||
*/
|
||||
|
||||
#ifndef _KERNEL_
|
||||
#ifndef _KERNEL_MODE
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#endif
|
||||
@@ -22,9 +22,9 @@
|
||||
#include "core_module.h"
|
||||
#include "net_module.h"
|
||||
#include "core_funcs.h"
|
||||
#include "../icmp/icmp_module.h"
|
||||
#include "icmp_module.h"
|
||||
|
||||
#ifdef _KERNEL_
|
||||
#ifdef _KERNEL_MODE
|
||||
#include <KernelExport.h>
|
||||
static status_t udp_ops(int32 op, ...);
|
||||
#define UDP_MODULE_PATH "network/protocol/udp"
|
||||
@@ -42,7 +42,7 @@ static struct udpstat udpstat;
|
||||
static uint32 udp_sendspace; /* size of send buffer */
|
||||
static uint32 udp_recvspace; /* size of recieve buffer */
|
||||
static struct icmp_module_info *icmp = NULL;
|
||||
#ifndef _KERNEL_
|
||||
#ifndef _KERNEL_MODE
|
||||
static image_id icmpid = -1;
|
||||
#endif
|
||||
|
||||
@@ -380,7 +380,7 @@ static int udp_module_init(void *cpp)
|
||||
add_domain(NULL, AF_INET);
|
||||
add_protocol(&my_proto, AF_INET);
|
||||
|
||||
#ifndef _KERNEL_
|
||||
#ifndef _KERNEL_MODE
|
||||
if (!icmp) {
|
||||
char path[PATH_MAX];
|
||||
getcwd(path, PATH_MAX);
|
||||
@@ -425,7 +425,7 @@ _EXPORT struct kernel_net_module_info protocol_info = {
|
||||
udp_module_stop
|
||||
};
|
||||
|
||||
#ifdef _KERNEL_
|
||||
#ifdef _KERNEL_MODE
|
||||
static status_t udp_ops(int32 op, ...)
|
||||
{
|
||||
switch(op) {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "poll.h"
|
||||
|
||||
// -------------------------------
|
||||
int poll(struct pollfd * p, int nb, int timeout)
|
||||
int poll(struct pollfd *fds, nfds_t numfds, int timeout)
|
||||
{
|
||||
fd_set read_set;
|
||||
fd_set write_set;
|
||||
@@ -19,16 +19,16 @@ int poll(struct pollfd * p, int nb, int timeout)
|
||||
FD_ZERO(&exception_set);
|
||||
|
||||
n = -1;
|
||||
for(i = 0; i < nb; i++) {
|
||||
if (p[i].fd < 0)
|
||||
for(i = 0; i < numfds; i++) {
|
||||
if (fds[i].fd < 0)
|
||||
continue;
|
||||
|
||||
if (p[i].events & POLLIN) FD_SET(p[i].fd, &read_set);
|
||||
if (p[i].events & POLLOUT) FD_SET(p[i].fd, &write_set);
|
||||
if (p[i].events & POLLERR) FD_SET(p[i].fd, &exception_set);
|
||||
if (fds[i].events & POLLIN) FD_SET(fds[i].fd, &read_set);
|
||||
if (fds[i].events & POLLOUT) FD_SET(fds[i].fd, &write_set);
|
||||
if (fds[i].events & POLLERR) FD_SET(fds[i].fd, &exception_set);
|
||||
|
||||
if (p[i].fd > n)
|
||||
n = p[i].fd;
|
||||
if (fds[i].fd > n)
|
||||
n = fds[i].fd;
|
||||
};
|
||||
|
||||
if (n == -1)
|
||||
@@ -49,11 +49,11 @@ int poll(struct pollfd * p, int nb, int timeout)
|
||||
return rc;
|
||||
|
||||
for(i = 0; i < n; i++) {
|
||||
p[i].revents = 0;
|
||||
fds[i].revents = 0;
|
||||
|
||||
if (FD_ISSET(p[i].fd, &read_set)) p[i].revents |= POLLIN;
|
||||
if (FD_ISSET(p[i].fd, &write_set)) p[i].revents |= POLLOUT;
|
||||
if (FD_ISSET(p[i].fd, &exception_set)) p[i].revents |= POLLERR;
|
||||
if (FD_ISSET(fds[i].fd, &read_set)) fds[i].revents |= POLLIN;
|
||||
if (FD_ISSET(fds[i].fd, &write_set)) fds[i].revents |= POLLOUT;
|
||||
if (FD_ISSET(fds[i].fd, &exception_set)) fds[i].revents |= POLLERR;
|
||||
};
|
||||
|
||||
return rc;
|
||||
|
||||
@@ -49,11 +49,13 @@ _EXPORT int select(int nbits, struct fd_set * rbits,
|
||||
errno = area;
|
||||
return -1;
|
||||
};
|
||||
|
||||
|
||||
// The area is multi-thread protected by a semaphore locker
|
||||
rss->lock = create_sem(1, "r5_selectsync_lock");
|
||||
if (rss->lock < B_OK) {
|
||||
errno = rss->lock;
|
||||
rss->wakeup = 0;
|
||||
n = -1;
|
||||
goto error;
|
||||
};
|
||||
|
||||
@@ -61,6 +63,7 @@ _EXPORT int select(int nbits, struct fd_set * rbits,
|
||||
rss->wakeup = create_sem(0, "r5_selectsync_wakeup");
|
||||
if (rss->wakeup < B_OK) {
|
||||
errno = rss->wakeup;
|
||||
n = -1;
|
||||
goto error;
|
||||
};
|
||||
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
|
||||
#include "net_stack_driver.h"
|
||||
|
||||
const char *g_stack_driver_path = "/dev/" NET_STACK_DRIVER_PATH;
|
||||
|
||||
bool g_beos_r5_compatibility = false;
|
||||
static bool g_beos_r5_compatibility = false;
|
||||
|
||||
struct beosr5_sockaddr_in {
|
||||
uint16 sin_family;
|
||||
@@ -37,7 +35,7 @@ _EXPORT int socket(int family, int type, int protocol)
|
||||
int rv;
|
||||
struct socket_args args;
|
||||
|
||||
sock = open(g_stack_driver_path, O_RDWR);
|
||||
sock = open(NET_STACK_DRIVER_PATH, O_RDWR);
|
||||
if (sock < 0)
|
||||
return sock;
|
||||
|
||||
@@ -153,7 +151,7 @@ _EXPORT int accept(int sock, struct sockaddr *addr, int *addrlen)
|
||||
int new_sock;
|
||||
void *cookie;
|
||||
|
||||
new_sock = open(g_stack_driver_path, O_RDWR);
|
||||
new_sock = open(NET_STACK_DRIVER_PATH, O_RDWR);
|
||||
if (new_sock < 0)
|
||||
return new_sock;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user