It is accomplished ...
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
/* arpa/inet.h */
|
||||
|
||||
/* public definitions of inet functions... */
|
||||
|
||||
#ifndef _INET_H_
|
||||
#define _INET_H_
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
in_addr_t inet_addr (const char *);
|
||||
int inet_aton (const char *, struct in_addr *);
|
||||
in_addr_t inet_lnaof (struct in_addr);
|
||||
struct in_addr inet_makeaddr (in_addr_t , in_addr_t);
|
||||
char * inet_neta (in_addr_t, char *, size_t);
|
||||
in_addr_t inet_netof (struct in_addr);
|
||||
in_addr_t inet_network (const char *);
|
||||
char *inet_net_ntop (int, const void *, int, char *, size_t);
|
||||
int inet_net_pton (int, const char *, void *, size_t);
|
||||
char *inet_ntoa (struct in_addr);
|
||||
int inet_pton (int, const char *, void *);
|
||||
const char *inet_ntop (int, const void *, char *, size_t);
|
||||
u_int inet_nsap_addr (const char *, u_char *, int);
|
||||
char *inet_nsap_ntoa (int, const u_char *, char *);
|
||||
|
||||
#endif /* _INET_H */
|
||||
@@ -0,0 +1,395 @@
|
||||
/* $OpenBSD: nameser.h,v 1.6 2001/07/31 22:02:18 jakob Exp $ */
|
||||
|
||||
/*
|
||||
* ++Copyright++ 1983, 1989, 1993
|
||||
* -
|
||||
* Copyright (c) 1983, 1989, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* -
|
||||
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies, and that
|
||||
* the name of Digital Equipment Corporation not be used in advertising or
|
||||
* publicity pertaining to distribution of the document or software without
|
||||
* specific, written prior permission.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
|
||||
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
|
||||
* CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||
* SOFTWARE.
|
||||
* -
|
||||
* Portions Copyright (c) 1995 by International Business Machines, Inc.
|
||||
*
|
||||
* International Business Machines, Inc. (hereinafter called IBM) grants
|
||||
* permission under its copyrights to use, copy, modify, and distribute this
|
||||
* Software with or without fee, provided that the above copyright notice and
|
||||
* all paragraphs of this notice appear in all copies, and that the name of IBM
|
||||
* not be used in connection with the marketing of any product incorporating
|
||||
* the Software or modifications thereof, without specific, written prior
|
||||
* permission.
|
||||
*
|
||||
* To the extent it has a right to do so, IBM grants an immunity from suit
|
||||
* under its patents, if any, for the use, sale or manufacture of products to
|
||||
* the extent that such products are used for performing Domain Name System
|
||||
* dynamic updates in TCP/IP networks by means of the Software. No immunity is
|
||||
* granted for any product per se or for any other function of any product.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
|
||||
* DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
|
||||
* IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* --Copyright--
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)nameser.h 8.1 (Berkeley) 6/2/93
|
||||
* $From: nameser.h,v 8.11 1996/10/08 04:51:02 vixie Exp $
|
||||
*/
|
||||
|
||||
#ifndef _NAMESER_H_
|
||||
#define _NAMESER_H_
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef _AUX_SOURCE
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* revision information. this is the release date in YYYYMMDD format.
|
||||
* it can change every day so the right thing to do with it is use it
|
||||
* in preprocessor commands such as "#if (__BIND > 19931104)". do not
|
||||
* compare for equality; rather, use it to determine whether your resolver
|
||||
* is new enough to contain a certain feature.
|
||||
*/
|
||||
|
||||
#define __BIND 19960801 /* interface version stamp */
|
||||
|
||||
/*
|
||||
* Define constants based on rfc883
|
||||
*/
|
||||
#define PACKETSZ 512 /* maximum packet size */
|
||||
#define MAXDNAME 1025 /* maximum presentation domain name */
|
||||
#define MAXCDNAME 255 /* maximum compressed domain name */
|
||||
#define MAXLABEL 63 /* maximum length of domain label */
|
||||
#define HFIXEDSZ 12 /* #/bytes of fixed data in header */
|
||||
#define QFIXEDSZ 4 /* #/bytes of fixed data in query */
|
||||
#define RRFIXEDSZ 10 /* #/bytes of fixed data in r record */
|
||||
#define INT32SZ 4 /* for systems without 32-bit ints */
|
||||
#define INT16SZ 2 /* for systems without 16-bit ints */
|
||||
#define INADDRSZ 4 /* IPv4 T_A */
|
||||
#define IN6ADDRSZ 16 /* IPv6 T_AAAA */
|
||||
|
||||
/*
|
||||
* Internet nameserver port number
|
||||
*/
|
||||
#define NAMESERVER_PORT 53
|
||||
|
||||
/*
|
||||
* Currently defined opcodes
|
||||
*/
|
||||
#define QUERY 0x0 /* standard query */
|
||||
#define IQUERY 0x1 /* inverse query */
|
||||
#define STATUS 0x2 /* nameserver status query */
|
||||
/*#define xxx 0x3*/ /* 0x3 reserved */
|
||||
#define NS_NOTIFY_OP 0x4 /* notify secondary of SOA change */
|
||||
/*
|
||||
* Currently defined response codes
|
||||
*/
|
||||
#define NOERROR 0 /* no error */
|
||||
#define FORMERR 1 /* format error */
|
||||
#define SERVFAIL 2 /* server failure */
|
||||
#define NXDOMAIN 3 /* non existent domain */
|
||||
#define NOTIMP 4 /* not implemented */
|
||||
#define REFUSED 5 /* query refused */
|
||||
|
||||
/*
|
||||
* Type values for resources and queries
|
||||
*/
|
||||
#define T_A 1 /* host address */
|
||||
#define T_NS 2 /* authoritative server */
|
||||
#define T_MD 3 /* mail destination */
|
||||
#define T_MF 4 /* mail forwarder */
|
||||
#define T_CNAME 5 /* canonical name */
|
||||
#define T_SOA 6 /* start of authority zone */
|
||||
#define T_MB 7 /* mailbox domain name */
|
||||
#define T_MG 8 /* mail group member */
|
||||
#define T_MR 9 /* mail rename name */
|
||||
#define T_NULL 10 /* null resource record */
|
||||
#define T_WKS 11 /* well known service */
|
||||
#define T_PTR 12 /* domain name pointer */
|
||||
#define T_HINFO 13 /* host information */
|
||||
#define T_MINFO 14 /* mailbox information */
|
||||
#define T_MX 15 /* mail routing information */
|
||||
#define T_TXT 16 /* text strings */
|
||||
#define T_RP 17 /* responsible person */
|
||||
#define T_AFSDB 18 /* AFS cell database */
|
||||
#define T_X25 19 /* X_25 calling address */
|
||||
#define T_ISDN 20 /* ISDN calling address */
|
||||
#define T_RT 21 /* router */
|
||||
#define T_NSAP 22 /* NSAP address */
|
||||
#define T_NSAP_PTR 23 /* reverse NSAP lookup (deprecated) */
|
||||
#define T_SIG 24 /* security signature */
|
||||
#define T_KEY 25 /* security key */
|
||||
#define T_PX 26 /* X.400 mail mapping */
|
||||
#define T_GPOS 27 /* geographical position (withdrawn) */
|
||||
#define T_AAAA 28 /* IP6 Address */
|
||||
#define T_LOC 29 /* Location Information */
|
||||
#define T_NXT 30 /* Next Valid Name in Zone */
|
||||
#define T_EID 31 /* Endpoint identifier */
|
||||
#define T_NIMLOC 32 /* Nimrod locator */
|
||||
#define T_SRV 33 /* Server selection */
|
||||
#define T_ATMA 34 /* ATM Address */
|
||||
#define T_NAPTR 35 /* Naming Authority PoinTeR */
|
||||
#define T_OPT 41 /* OPT pseudo-RR, RFC2671 */
|
||||
/* non standard */
|
||||
#define T_UINFO 100 /* user (finger) information */
|
||||
#define T_UID 101 /* user ID */
|
||||
#define T_GID 102 /* group ID */
|
||||
#define T_UNSPEC 103 /* Unspecified format (binary data) */
|
||||
/* Query type values which do not appear in resource records */
|
||||
#define T_IXFR 251 /* incremental zone transfer */
|
||||
#define T_AXFR 252 /* transfer zone of authority */
|
||||
#define T_MAILB 253 /* transfer mailbox records */
|
||||
#define T_MAILA 254 /* transfer mail agent records */
|
||||
#define T_ANY 255 /* wildcard match */
|
||||
|
||||
/*
|
||||
* Values for class field
|
||||
*/
|
||||
|
||||
#define C_IN 1 /* the arpa internet */
|
||||
#define C_CHAOS 3 /* for chaos net (MIT) */
|
||||
#define C_HS 4 /* for Hesiod name server (MIT) (XXX) */
|
||||
/* Query class values which do not appear in resource records */
|
||||
#define C_ANY 255 /* wildcard match */
|
||||
|
||||
/*
|
||||
* Flags field of the KEY RR rdata
|
||||
*/
|
||||
#define KEYFLAG_TYPEMASK 0xC000 /* Mask for "type" bits */
|
||||
#define KEYFLAG_TYPE_AUTH_CONF 0x0000 /* Key usable for both */
|
||||
#define KEYFLAG_TYPE_CONF_ONLY 0x8000 /* Key usable for confidentiality */
|
||||
#define KEYFLAG_TYPE_AUTH_ONLY 0x4000 /* Key usable for authentication */
|
||||
#define KEYFLAG_TYPE_NO_KEY 0xC000 /* No key usable for either; no key */
|
||||
/* The type bits can also be interpreted independently, as single bits: */
|
||||
#define KEYFLAG_NO_AUTH 0x8000 /* Key not usable for authentication */
|
||||
#define KEYFLAG_NO_CONF 0x4000 /* Key not usable for confidentiality */
|
||||
|
||||
#define KEYFLAG_EXPERIMENTAL 0x2000 /* Security is *mandatory* if bit=0 */
|
||||
#define KEYFLAG_RESERVED3 0x1000 /* reserved - must be zero */
|
||||
#define KEYFLAG_RESERVED4 0x0800 /* reserved - must be zero */
|
||||
#define KEYFLAG_USERACCOUNT 0x0400 /* key is assoc. with a user acct */
|
||||
#define KEYFLAG_ENTITY 0x0200 /* key is assoc. with entity eg host */
|
||||
#define KEYFLAG_ZONEKEY 0x0100 /* key is zone key for the zone named */
|
||||
#define KEYFLAG_IPSEC 0x0080 /* key is for IPSEC use (host or user)*/
|
||||
#define KEYFLAG_EMAIL 0x0040 /* key is for email (MIME security) */
|
||||
#define KEYFLAG_RESERVED10 0x0020 /* reserved - must be zero */
|
||||
#define KEYFLAG_RESERVED11 0x0010 /* reserved - must be zero */
|
||||
#define KEYFLAG_SIGNATORYMASK 0x000F /* key can sign DNS RR's of same name */
|
||||
|
||||
#define KEYFLAG_RESERVED_BITMASK ( KEYFLAG_RESERVED3 | \
|
||||
KEYFLAG_RESERVED4 | \
|
||||
KEYFLAG_RESERVED10| KEYFLAG_RESERVED11)
|
||||
|
||||
/* The Algorithm field of the KEY and SIG RR's is an integer, {1..254} */
|
||||
#define ALGORITHM_MD5RSA 1 /* MD5 with RSA */
|
||||
#define ALGORITHM_EXPIRE_ONLY 253 /* No alg, no security */
|
||||
#define ALGORITHM_PRIVATE_OID 254 /* Key begins with OID indicating alg */
|
||||
|
||||
/* Signatures */
|
||||
/* Size of a mod or exp in bits */
|
||||
#define MIN_MD5RSA_KEY_PART_BITS 512
|
||||
#define MAX_MD5RSA_KEY_PART_BITS 2552
|
||||
/* Total of binary mod and exp, bytes */
|
||||
#define MAX_MD5RSA_KEY_BYTES ((MAX_MD5RSA_KEY_PART_BITS+7/8)*2+3)
|
||||
/* Max length of text sig block */
|
||||
#define MAX_KEY_BASE64 (((MAX_MD5RSA_KEY_BYTES+2)/3)*4)
|
||||
|
||||
/*
|
||||
* EDNS0 Z-field extended flags
|
||||
*/
|
||||
#define DNS_MESSAGEEXTFLAG_DO 0x8000U
|
||||
|
||||
/*
|
||||
* Status return codes for T_UNSPEC conversion routines
|
||||
*/
|
||||
#define CONV_SUCCESS 0
|
||||
#define CONV_OVERFLOW (-1)
|
||||
#define CONV_BADFMT (-2)
|
||||
#define CONV_BADCKSUM (-3)
|
||||
#define CONV_BADBUFLEN (-4)
|
||||
|
||||
#ifndef BYTE_ORDER
|
||||
#if (BSD >= 199103)
|
||||
# include <machine/endian.h>
|
||||
#else
|
||||
#ifdef linux
|
||||
# include <endian.h>
|
||||
#else
|
||||
#define LITTLE_ENDIAN 1234 /* least-significant byte first (vax, pc) */
|
||||
#define BIG_ENDIAN 4321 /* most-significant byte first (IBM, net) */
|
||||
#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long (pdp)*/
|
||||
|
||||
#if defined(vax) || defined(ns32000) || defined(sun386) || defined(i386) || \
|
||||
defined(MIPSEL) || defined(_MIPSEL) || defined(BIT_ZERO_ON_RIGHT) || \
|
||||
defined(__alpha__) || defined(__alpha)
|
||||
#define BYTE_ORDER LITTLE_ENDIAN
|
||||
#endif
|
||||
|
||||
#if defined(sel) || defined(pyr) || defined(mc68000) || defined(sparc) || \
|
||||
defined(is68k) || defined(tahoe) || defined(ibm032) || defined(ibm370) || \
|
||||
defined(MIPSEB) || defined(_MIPSEB) || defined(_IBMR2) || defined(DGUX) ||\
|
||||
defined(apollo) || defined(__convex__) || defined(_CRAY) || \
|
||||
defined(__hppa) || defined(__hp9000) || \
|
||||
defined(__hp9000s300) || defined(__hp9000s700) || \
|
||||
defined (BIT_ZERO_ON_LEFT) || defined(m68k)
|
||||
#define BYTE_ORDER BIG_ENDIAN
|
||||
#endif
|
||||
#endif /* linux */
|
||||
#endif /* BSD */
|
||||
#endif /* BYTE_ORDER */
|
||||
|
||||
#if !defined(BYTE_ORDER) || \
|
||||
(BYTE_ORDER != BIG_ENDIAN && BYTE_ORDER != LITTLE_ENDIAN && \
|
||||
BYTE_ORDER != PDP_ENDIAN)
|
||||
/* you must determine what the correct bit order is for
|
||||
* your compiler - the next line is an intentional error
|
||||
* which will force your compiles to bomb until you fix
|
||||
* the above macros.
|
||||
*/
|
||||
error "Undefined or invalid BYTE_ORDER";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Structure for query header. The order of the fields is machine- and
|
||||
* compiler-dependent, depending on the byte/bit order and the layout
|
||||
* of bit fields. We use bit fields only in int variables, as this
|
||||
* is all ANSI requires. This requires a somewhat confusing rearrangement.
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
unsigned id :16; /* query identification number */
|
||||
#if BYTE_ORDER == BIG_ENDIAN
|
||||
/* fields in third byte */
|
||||
unsigned qr: 1; /* response flag */
|
||||
unsigned opcode: 4; /* purpose of message */
|
||||
unsigned aa: 1; /* authoritive answer */
|
||||
unsigned tc: 1; /* truncated message */
|
||||
unsigned rd: 1; /* recursion desired */
|
||||
/* fields in fourth byte */
|
||||
unsigned ra: 1; /* recursion available */
|
||||
unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */
|
||||
unsigned ad: 1; /* authentic data from named */
|
||||
unsigned cd: 1; /* checking disabled by resolver */
|
||||
unsigned rcode :4; /* response code */
|
||||
#endif
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN
|
||||
/* fields in third byte */
|
||||
unsigned rd :1; /* recursion desired */
|
||||
unsigned tc :1; /* truncated message */
|
||||
unsigned aa :1; /* authoritive answer */
|
||||
unsigned opcode :4; /* purpose of message */
|
||||
unsigned qr :1; /* response flag */
|
||||
/* fields in fourth byte */
|
||||
unsigned rcode :4; /* response code */
|
||||
unsigned cd: 1; /* checking disabled by resolver */
|
||||
unsigned ad: 1; /* authentic data from named */
|
||||
unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */
|
||||
unsigned ra :1; /* recursion available */
|
||||
#endif
|
||||
/* remaining bytes */
|
||||
unsigned qdcount :16; /* number of question entries */
|
||||
unsigned ancount :16; /* number of answer entries */
|
||||
unsigned nscount :16; /* number of authority entries */
|
||||
unsigned arcount :16; /* number of resource entries */
|
||||
} HEADER;
|
||||
|
||||
/*
|
||||
* Defines for handling compressed domain names
|
||||
*/
|
||||
#define INDIR_MASK 0xc0
|
||||
|
||||
extern uint16 _getshort (const u_char *);
|
||||
extern uint32 _getlong (const u_char *);
|
||||
|
||||
/*
|
||||
* Inline versions of get/put short/long. Pointer is advanced.
|
||||
*
|
||||
* These macros demonstrate the property of C whereby it can be
|
||||
* portable or it can be elegant but rarely both.
|
||||
*/
|
||||
#define GETSHORT(s, cp) { \
|
||||
register u_char *t_cp = (u_char *)(cp); \
|
||||
(s) = ((uint16)t_cp[0] << 8) \
|
||||
| ((uint16)t_cp[1]) \
|
||||
; \
|
||||
(cp) += INT16SZ; \
|
||||
}
|
||||
|
||||
#define GETLONG(l, cp) { \
|
||||
register u_char *t_cp = (u_char *)(cp); \
|
||||
(l) = ((uint32)t_cp[0] << 24) \
|
||||
| ((uint32)t_cp[1] << 16) \
|
||||
| ((uint32)t_cp[2] << 8) \
|
||||
| ((uint32)t_cp[3]) \
|
||||
; \
|
||||
(cp) += INT32SZ; \
|
||||
}
|
||||
|
||||
#define PUTSHORT(s, cp) { \
|
||||
register uint16 t_s = (uint16)(s); \
|
||||
register u_char *t_cp = (u_char *)(cp); \
|
||||
*t_cp++ = t_s >> 8; \
|
||||
*t_cp = t_s; \
|
||||
(cp) += INT16SZ; \
|
||||
}
|
||||
|
||||
#define PUTLONG(l, cp) { \
|
||||
register uint32 t_l = (uint32)(l); \
|
||||
register u_char *t_cp = (u_char *)(cp); \
|
||||
*t_cp++ = t_l >> 24; \
|
||||
*t_cp++ = t_l >> 16; \
|
||||
*t_cp++ = t_l >> 8; \
|
||||
*t_cp = t_l; \
|
||||
(cp) += INT32SZ; \
|
||||
}
|
||||
|
||||
#endif /* !_NAMESER_H_ */
|
||||
@@ -0,0 +1,115 @@
|
||||
/* core_funcs.h
|
||||
* convenience macros to for calling core functions in the kernel
|
||||
*/
|
||||
|
||||
#ifndef OBOS_CORE_FUNCS_H
|
||||
#define OBOS_CORE_FUNCS_H
|
||||
|
||||
#include "core_module.h"
|
||||
|
||||
# define add_protosw core->add_protosw
|
||||
# define add_domain core->add_domain
|
||||
# define remove_domain core->remove_domain
|
||||
# define add_protocol core->add_protocol
|
||||
# define remove_protocol core->remove_protocol
|
||||
# define start_rx_thread core->start_rx_thread
|
||||
# define start_tx_thread core->start_tx_thread
|
||||
|
||||
# define net_add_timer core->net_add_timer
|
||||
# define net_remove_timer core->net_remove_timer
|
||||
|
||||
# define start_ifq core->start_ifq
|
||||
# define stop_ifq core->stop_ifq
|
||||
|
||||
# define pool_init core->pool_init
|
||||
# define pool_get core->pool_get
|
||||
# define pool_put core->pool_put
|
||||
|
||||
# define m_get core->m_get
|
||||
# define m_gethdr core->m_gethdr
|
||||
# define m_free core->m_free
|
||||
# define m_freem core->m_freem
|
||||
# define m_cat core->m_cat
|
||||
# define m_adj core->m_adj
|
||||
# define m_prepend core->m_prepend
|
||||
# define m_pullup core->m_pullup
|
||||
# define m_copydata core->m_copydata
|
||||
# define m_copyback core->m_copyback
|
||||
# define m_copym core->m_copym
|
||||
# define m_reserve core->m_reserve
|
||||
# define m_devget core->m_devget
|
||||
|
||||
# define if_attach core->if_attach
|
||||
# define if_detach core->if_detach
|
||||
|
||||
# define in_pcballoc core->in_pcballoc
|
||||
# define in_pcbconnect core->in_pcbconnect
|
||||
# define in_pcbdisconnect core->in_pcbdisconnect
|
||||
# define in_pcbbind core->in_pcbbind
|
||||
# define in_pcblookup core->in_pcblookup
|
||||
# define in_pcbdetach core->in_pcbdetach
|
||||
# define in_pcbrtentry core->in_pcbrtentry
|
||||
# define in_canforward core->in_canforward
|
||||
# define in_localaddr core->in_localaddr
|
||||
# define in_losing core->in_losing
|
||||
# define in_broadcast core->in_broadcast
|
||||
# define in_control core->in_control
|
||||
# define in_setsockaddr core->in_setsockaddr
|
||||
# define in_setpeeraddr core->in_setpeeraddr
|
||||
# define in_pcbnotify core->in_pcbnotify
|
||||
# define inetctlerrmap core->inetctlerrmap
|
||||
|
||||
# define ifa_ifwithdstaddr core->ifa_ifwithdstaddr
|
||||
# define ifa_ifwithaddr core->ifa_ifwithaddr
|
||||
# define ifa_ifwithnet core->ifa_ifwithnet
|
||||
# define ifa_ifwithroute core->ifa_ifwithroute
|
||||
# define ifaof_ifpforaddr core->ifaof_ifpforaddr
|
||||
# define ifafree core->ifafree
|
||||
|
||||
# define sbappend core->sbappend
|
||||
# define sbappendaddr core->sbappendaddr
|
||||
# define sbdrop core->sbdrop
|
||||
# define sbflush core->sbflush
|
||||
# define sbreserve core->sbreserve
|
||||
|
||||
# define soreserve core->soreserve
|
||||
# define sowakeup core->sowakeup
|
||||
# define sonewconn core->sonewconn
|
||||
# define soisconnected core->soisconnected
|
||||
# define soisconnecting core->soisconnecting
|
||||
# define soisdisconnected core->soisdisconnected
|
||||
# define soisdisconnecting core->soisdisconnecting
|
||||
# define sohasoutofband core->sohasoutofband
|
||||
# define socantsendmore core->socantsendmore
|
||||
# define socantrcvmore core->socantrcvmore
|
||||
|
||||
# define rtfree core->rtfree
|
||||
# define rtalloc core->rtalloc
|
||||
# define rtalloc1 core->rtalloc1
|
||||
# define rtrequest core->rtrequest
|
||||
|
||||
# define rt_setgate core->rt_setgate
|
||||
# define get_rt_tables core->get_rt_tables
|
||||
|
||||
# define rn_addmask core->rn_addmask
|
||||
# define rn_head_search core->rn_head_search
|
||||
|
||||
# define get_interfaces core->get_interfaces
|
||||
# define get_primary_addr core->get_primary_addr
|
||||
|
||||
# define initsocket core->initsocket
|
||||
# define socreate core->socreate
|
||||
# define soclose core->soclose
|
||||
|
||||
# define sobind core->sobind
|
||||
# define soconnect core->soconnect
|
||||
# define solisten core->solisten
|
||||
# define soaccept core->soaccept
|
||||
|
||||
# define soo_ioctl core->soo_ioctl
|
||||
# define net_sysctl core->net_sysctl
|
||||
|
||||
# define readit core->readit
|
||||
# define writeit core->writeit
|
||||
|
||||
#endif /* OBOS_CORE_FUNCS_H */
|
||||
@@ -0,0 +1,158 @@
|
||||
/* core_module.h
|
||||
* definitions needed by the core networking module
|
||||
*/
|
||||
|
||||
#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"
|
||||
|
||||
struct core_module_info {
|
||||
module_info module;
|
||||
|
||||
int (*start)(void);
|
||||
int (*stop)(void);
|
||||
void (*add_domain)(struct domain *, int);
|
||||
void (*remove_domain)(int);
|
||||
void (*add_protocol)(struct protosw *, int);
|
||||
void (*remove_protocol)(struct protosw *pr);
|
||||
void (*add_protosw)(struct protosw *prt[], int layer);
|
||||
void (*start_rx_thread)(struct ifnet *dev);
|
||||
void (*start_tx_thread)(struct ifnet *dev);
|
||||
|
||||
/* timer functions */
|
||||
net_timer_id (*net_add_timer)(net_timer_hook ,void *,
|
||||
bigtime_t);
|
||||
status_t (*net_remove_timer)(net_timer_id);
|
||||
|
||||
/* ifq functions */
|
||||
struct ifq *(*start_ifq)(void);
|
||||
void (*stop_ifq)(struct ifq *);
|
||||
|
||||
/* pool functions */
|
||||
status_t (*pool_init)(pool_ctl **p, size_t sz);
|
||||
char *(*pool_get)(pool_ctl *p);
|
||||
void (*pool_put)(pool_ctl *p, void *ptr);
|
||||
void (*pool_destroy)(pool_ctl *p);
|
||||
|
||||
/* socket functions - called "internally" */
|
||||
struct socket *(*sonewconn)(struct socket *, int);
|
||||
int (*soreserve)(struct socket *, uint32, uint32);
|
||||
int (*sbreserve)(struct sockbuf *, uint32);
|
||||
void (*sbappend)(struct sockbuf *, struct mbuf *);
|
||||
int (*sbappendaddr)(struct sockbuf *, struct sockaddr *,
|
||||
struct mbuf *, struct mbuf *);
|
||||
void (*sbdrop)(struct sockbuf *, int);
|
||||
void (*sbflush)(struct sockbuf *sb);
|
||||
void (*sowakeup)(struct socket *, struct sockbuf *);
|
||||
void (*soisconnected)(struct socket *);
|
||||
void (*soisconnecting)(struct socket*);
|
||||
void (*soisdisconnected)(struct socket *);
|
||||
void (*soisdisconnecting)(struct socket *);
|
||||
void (*sohasoutofband)(struct socket *so);
|
||||
void (*socantrcvmore)(struct socket*);
|
||||
void (*socantsendmore)(struct socket *);
|
||||
|
||||
/* pcb options */
|
||||
int (*in_pcballoc)(struct socket *, struct inpcb *);
|
||||
void (*in_pcbdetach)(struct inpcb *);
|
||||
int (*in_pcbbind)(struct inpcb *, struct mbuf *);
|
||||
int (*in_pcbconnect)(struct inpcb *, struct mbuf *);
|
||||
int (*in_pcbdisconnect)(struct inpcb *);
|
||||
struct inpcb * (*in_pcblookup)(struct inpcb *,
|
||||
struct in_addr, uint16, struct in_addr, uint16, int);
|
||||
int (*in_control)(struct socket *, int, caddr_t,
|
||||
struct ifnet *);
|
||||
void (*in_losing)(struct inpcb *);
|
||||
int (*in_canforward)(struct in_addr);
|
||||
int (*in_localaddr)(struct in_addr);
|
||||
struct rtentry *(*in_pcbrtentry)(struct inpcb *);
|
||||
void (*in_setsockaddr)(struct inpcb *, struct mbuf *);
|
||||
void (*in_setpeeraddr)(struct inpcb *, struct mbuf *);
|
||||
void (*in_pcbnotify)(struct inpcb *, struct sockaddr *,
|
||||
uint16, struct in_addr, uint16,
|
||||
int, void (*)(struct inpcb *, int));
|
||||
int (*inetctlerrmap)(int);
|
||||
|
||||
/* mbuf routines... */
|
||||
struct mbuf * (*m_gethdr)(int);
|
||||
struct mbuf * (*m_get)(int);
|
||||
void (*m_cat)(struct mbuf *, struct mbuf *);
|
||||
void (*m_adj)(struct mbuf*, int);
|
||||
struct mbuf * (*m_prepend)(struct mbuf*, int);
|
||||
struct mbuf *(*m_pullup)(struct mbuf *, int);
|
||||
void (*m_copyback)(struct mbuf *, int, int, caddr_t);
|
||||
void (*m_copydata)(struct mbuf *, int, int, caddr_t);
|
||||
struct mbuf *(*m_copym)(struct mbuf *, int, int);
|
||||
struct mbuf * (*m_free)(struct mbuf *);
|
||||
void (*m_freem)(struct mbuf *);
|
||||
void (*m_reserve)(struct mbuf *, int);
|
||||
struct mbuf *(*m_devget)(char *, int, int, struct ifnet *,
|
||||
void (*copy)(const void *, void *, size_t));
|
||||
|
||||
/* module control routines... */
|
||||
void (*add_device)(struct ifnet *);
|
||||
struct ifnet *(*get_interfaces)(void);
|
||||
int (*in_broadcast)(struct in_addr, struct ifnet *);
|
||||
|
||||
/* routing */
|
||||
void (*rtalloc)(struct route *ro);
|
||||
struct rtentry *(*rtalloc1)(struct sockaddr *, int);
|
||||
void (*rtfree)(struct rtentry *);
|
||||
int (*rtrequest)(int, struct sockaddr *,
|
||||
struct sockaddr *, struct sockaddr *, int,
|
||||
struct rtentry **);
|
||||
struct radix_node *(*rn_addmask)(void *, int, int);
|
||||
struct radix_node *(*rn_head_search)(void *argv_v);
|
||||
struct radix_node_head **(*get_rt_tables)(void);
|
||||
int (*rt_setgate)(struct rtentry *, struct sockaddr *,
|
||||
struct sockaddr *);
|
||||
|
||||
/* ifnet functions */
|
||||
struct ifaddr *(*ifa_ifwithdstaddr)(struct sockaddr *addr);
|
||||
struct ifaddr *(*ifa_ifwithnet)(struct sockaddr *addr);
|
||||
void (*if_attach)(struct ifnet *);
|
||||
void (*if_detach)(struct ifnet *);
|
||||
struct ifaddr *(*ifa_ifwithaddr)(struct sockaddr *);
|
||||
struct ifaddr *(*ifa_ifwithroute)(int, struct sockaddr *,
|
||||
struct sockaddr *);
|
||||
struct ifaddr *(*ifaof_ifpforaddr)(struct sockaddr *, struct ifnet *);
|
||||
void (*ifafree)(struct ifaddr *);
|
||||
|
||||
struct in_ifaddr *(*get_primary_addr)(void);
|
||||
|
||||
/* socket functions - used by socket driver */
|
||||
int (*initsocket)(void **);
|
||||
int (*socreate)(int, void *, int, int);
|
||||
int (*soclose)(void *);
|
||||
int (*sobind)(void *, caddr_t, int);
|
||||
int (*solisten)(void *, int);
|
||||
int (*soconnect)(void *, caddr_t, int);
|
||||
int (*recvit)(void *, struct msghdr *, caddr_t, int *);
|
||||
int (*sendit)(void *, struct msghdr *, int, int *);
|
||||
int (*soo_ioctl)(void *, int, caddr_t);
|
||||
int (*net_sysctl)(int *, uint, void *, size_t *, void *, size_t);
|
||||
int (*writeit)(void *, struct iovec *, int);
|
||||
int (*readit)(void*, struct iovec *, int *);
|
||||
int (*sosetopt)(void *, int, int, const void *, size_t);
|
||||
int (*sogetopt)(void *, int, int, void *, size_t *);
|
||||
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 *);
|
||||
};
|
||||
|
||||
#ifdef _KERNEL_
|
||||
#define CORE_MODULE_PATH "network/core"
|
||||
#else
|
||||
#define CORE_MODULE_PATH "modules/core"
|
||||
#endif
|
||||
|
||||
#endif /* OBOS_CORE_MODULE_H */
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
#ifndef LOCK_H
|
||||
#define LOCK_H
|
||||
/* lock.h - benaphore locking, "faster semaphores", read/write locks
|
||||
** sorry for all those macros; I wish C would support C++-style
|
||||
** inline functions.
|
||||
**
|
||||
** Initial version by Axel Dörfler, [email protected]
|
||||
**
|
||||
** This file may be used under the terms of the OpenBeOS License.
|
||||
*/
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
// for read/write locks
|
||||
#define MAX_READERS 100000
|
||||
|
||||
|
||||
struct benaphore {
|
||||
sem_id sem;
|
||||
int32 count;
|
||||
};
|
||||
|
||||
typedef struct benaphore benaphore;
|
||||
|
||||
// it may make sense to add a status field to the rw_lock to
|
||||
// be able to check if the semaphore could be locked
|
||||
|
||||
struct rw_lock {
|
||||
sem_id sem;
|
||||
int32 count;
|
||||
benaphore writeLock;
|
||||
};
|
||||
|
||||
typedef struct rw_lock rw_lock;
|
||||
|
||||
#ifndef _KERNEL_
|
||||
#define INIT_BENAPHORE(lock,name) \
|
||||
{ \
|
||||
(lock).count = 1; \
|
||||
(lock).sem = create_sem(0, name); \
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#define INIT_BENAPHORE(lock,name) \
|
||||
{ \
|
||||
(lock).count = 1; \
|
||||
(lock).sem = create_sem(0, name); \
|
||||
set_sem_owner((lock).sem, B_SYSTEM_TEAM); \
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#define CHECK_BENAPHORE(lock) \
|
||||
((lock).sem)
|
||||
|
||||
#define UNINIT_BENAPHORE(lock) \
|
||||
delete_sem((lock).sem);
|
||||
|
||||
#define ACQUIRE_BENAPHORE(lock) \
|
||||
(atomic_add(&((lock).count), -1) <= 0 ? \
|
||||
acquire_sem_etc((lock).sem, 1, B_CAN_INTERRUPT, 0) \
|
||||
: B_OK)
|
||||
|
||||
#define RELEASE_BENAPHORE(lock) \
|
||||
{ \
|
||||
if (atomic_add(&((lock).count), 1) < 0) \
|
||||
release_sem((lock).sem); \
|
||||
}
|
||||
|
||||
/* read/write lock */
|
||||
#ifndef _KERNEL_
|
||||
#define INIT_RW_LOCK(lock,name) \
|
||||
{ \
|
||||
(lock).sem = create_sem(0, name); \
|
||||
(lock).count = MAX_READERS; \
|
||||
INIT_BENAPHORE((lock).writeLock, "r/w write lock"); \
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#define INIT_RW_LOCK(lock,name) \
|
||||
{ \
|
||||
(lock).sem = create_sem(0, name); \
|
||||
set_sem_owner((lock).sem, B_SYSTEM_TEAM); \
|
||||
(lock).count = MAX_READERS; \
|
||||
INIT_BENAPHORE((lock).writeLock, "r/w write lock"); \
|
||||
}
|
||||
|
||||
#endif
|
||||
#define CHECK_RW_LOCK(lock) \
|
||||
((lock).sem)
|
||||
|
||||
#define UNINIT_RW_LOCK(lock) \
|
||||
delete_sem((lock).sem); \
|
||||
UNINIT_BENAPHORE((lock).writeLock)
|
||||
|
||||
#define ACQUIRE_READ_LOCK(lock) \
|
||||
{ \
|
||||
if (atomic_add(&(lock).count, -1) <= 0) \
|
||||
acquire_sem((lock).sem); \
|
||||
}
|
||||
|
||||
#define RELEASE_READ_LOCK(lock) \
|
||||
{ \
|
||||
if (atomic_add(&(lock).count, 1) < 0) \
|
||||
release_sem((lock).sem); \
|
||||
}
|
||||
|
||||
#define ACQUIRE_WRITE_LOCK(lock) \
|
||||
{ \
|
||||
int32 readers; \
|
||||
ACQUIRE_BENAPHORE((lock).writeLock); \
|
||||
readers = atomic_add(&(lock).count, -MAX_READERS); \
|
||||
if (readers < MAX_READERS) \
|
||||
acquire_sem_etc((lock).sem,readers <= 0 ? 1 : MAX_READERS - readers,0,0); \
|
||||
RELEASE_BENAPHORE((lock).writeLock); \
|
||||
}
|
||||
|
||||
#define RELEASE_WRITE_LOCK(lock) \
|
||||
{ \
|
||||
int32 readers = atomic_add(&(lock).count,MAX_READERS); \
|
||||
if (readers < 0) \
|
||||
release_sem_etc((lock).sem,readers <= -MAX_READERS ? 1 : -readers,B_CAN_INTERRUPT); \
|
||||
}
|
||||
|
||||
#endif /* LOCK_H */
|
||||
@@ -0,0 +1,275 @@
|
||||
/* if.h
|
||||
* Interface definitions for beos
|
||||
*/
|
||||
|
||||
#ifndef OBOS_IF_H
|
||||
#define OBOS_IF_H
|
||||
|
||||
#include <kernel/OS.h>
|
||||
#include <Drivers.h>
|
||||
#include "sys/socketvar.h"
|
||||
#include "net/if_types.h"
|
||||
#include "netinet/in.h"
|
||||
#include "net/route.h"
|
||||
|
||||
enum {
|
||||
IF_GETADDR = B_DEVICE_OP_CODES_END,
|
||||
IF_INIT,
|
||||
IF_NONBLOCK,
|
||||
IF_ADDMULTI,
|
||||
IF_REMMULTI,
|
||||
IF_SETPROMISC,
|
||||
IF_GETFRAMESIZE
|
||||
};
|
||||
|
||||
/* Media types are now listed in net/if_types.h */
|
||||
|
||||
/* Interface flags */
|
||||
enum {
|
||||
IFF_UP = 0x0001,
|
||||
IFF_DOWN = 0x0002,
|
||||
IFF_PROMISC = 0x0004,
|
||||
IFF_RUNNING = 0x0008,
|
||||
IFF_MULTICAST = 0x0010,
|
||||
IFF_BROADCAST = 0x0020,
|
||||
IFF_POINTOPOINT = 0x0040,
|
||||
IFF_NOARP = 0x0080,
|
||||
IFF_LOOPBACK = 0x0100,
|
||||
IFF_DEBUG = 0x0200,
|
||||
IFF_LINK0 = 0x0400,
|
||||
IFF_LINK1 = 0x0800,
|
||||
IFF_LINK2 = 0x1000,
|
||||
IFF_SIMPLEX = 0x2000
|
||||
};
|
||||
|
||||
struct ifq {
|
||||
struct mbuf *head;
|
||||
struct mbuf *tail;
|
||||
int maxlen;
|
||||
int len;
|
||||
sem_id lock;
|
||||
sem_id pop;
|
||||
};
|
||||
|
||||
#define IFQ_FULL(ifq) (ifq->len >= ifq->maxlen)
|
||||
|
||||
#define IFQ_ENQUEUE(ifq, m) { \
|
||||
acquire_sem((ifq)->lock); \
|
||||
(m)->m_nextpkt = 0; \
|
||||
if ((ifq)->tail == 0) \
|
||||
(ifq)->head = m; \
|
||||
else \
|
||||
(ifq)->tail->m_nextpkt = m; \
|
||||
(ifq)->tail = m; \
|
||||
(ifq)->len++; \
|
||||
release_sem((ifq)->lock); \
|
||||
release_sem((ifq)->pop); \
|
||||
}
|
||||
|
||||
#define IFQ_DEQUEUE(ifq, m) { \
|
||||
acquire_sem((ifq)->lock); \
|
||||
(m) = (ifq)->head; \
|
||||
if (m) { \
|
||||
if (((ifq)->head = (m)->m_nextpkt) == 0) \
|
||||
(ifq)->tail = 0; \
|
||||
(m)->m_nextpkt = 0; \
|
||||
(ifq)->len--; \
|
||||
} \
|
||||
release_sem((ifq)->lock); \
|
||||
}
|
||||
|
||||
struct ifaddr {
|
||||
struct ifaddr *ifa_next; /* the next address for the interface */
|
||||
struct ifnet *ifa_ifp; /* pointer to the interface structure */
|
||||
|
||||
struct sockaddr *ifa_addr; /* the address - cast to be a suitable type, so we
|
||||
* use this structure to store any type of address that
|
||||
* we have a struct sockaddr_? for. e.g.
|
||||
* link level address via sockaddr_dl and
|
||||
* ipv4 via sockeddr_in
|
||||
* same for next 2 pointers as well
|
||||
*/
|
||||
struct sockaddr *ifa_dstaddr; /* if we're on a point-to-point link this
|
||||
* is the other end */
|
||||
struct sockaddr *ifa_netmask; /* The netmask we're using */
|
||||
|
||||
/* check or clean routes... */
|
||||
void (*ifa_rtrequest)(int, struct rtentry *, struct sockaddr *);
|
||||
uint8 ifa_flags; /* flags (mainly routing */
|
||||
uint16 ifa_refcnt; /* how many references are there to
|
||||
* this structure? */
|
||||
int ifa_metric; /* the metirc for this interface/address */
|
||||
};
|
||||
#define ifa_broadaddr ifa_dstaddr
|
||||
|
||||
struct if_data {
|
||||
uint8 ifi_type; /* type of media */
|
||||
uint8 ifi_addrlen; /* length of media address length */
|
||||
uint8 ifi_hdrlen; /* size of media header */
|
||||
uint32 ifi_mtu; /* mtu */
|
||||
uint32 ifi_metric; /* routing metric */
|
||||
uint32 ifi_baudrate; /* baudrate of line */
|
||||
/* statistics!! */
|
||||
int32 ifi_ipackets; /* packets received on interface */
|
||||
int32 ifi_ierrors; /* input errors on interface */
|
||||
int32 ifi_opackets; /* packets sent on interface */
|
||||
int32 ifi_oerrors; /* output errors on interface */
|
||||
int32 ifi_collisions; /* collisions on csma interfaces */
|
||||
int32 ifi_ibytes; /* total number of octets received */
|
||||
int32 ifi_obytes; /* total number of octets sent */
|
||||
int32 ifi_imcasts; /* packets received via multicast */
|
||||
int32 ifi_omcasts; /* packets sent via multicast */
|
||||
int32 ifi_iqdrops; /* dropped on input, this interface */
|
||||
int32 ifi_noproto; /* destined for unsupported protocol */
|
||||
};
|
||||
|
||||
struct ifnet {
|
||||
struct ifnet *if_next; /* next device */
|
||||
struct ifaddr *if_addrlist; /* linked list of addresses */
|
||||
int devid; /* our device id if we have one... */
|
||||
int id; /* id within the stack's device list */
|
||||
char *name; /* name of driver e.g. tulip */
|
||||
int if_unit; /* number of unit e.g 0 */
|
||||
char *if_name; /* full name, e.g. tulip0 */
|
||||
struct if_data ifd; /* if_data structure, shortcuts below */
|
||||
int if_flags; /* if flags */
|
||||
int if_index; /* our index in ifnet_addrs and interfaces */
|
||||
|
||||
struct ifq *rxq;
|
||||
thread_id rx_thread;
|
||||
struct ifq *txq;
|
||||
thread_id tx_thread;
|
||||
struct ifq *devq;
|
||||
|
||||
int (*start) (struct ifnet *);
|
||||
int (*stop) (struct ifnet *);
|
||||
void (*input) (struct mbuf*);
|
||||
int (*output)(struct ifnet *, struct mbuf*,
|
||||
struct sockaddr*, struct rtentry *);
|
||||
int (*ioctl) (struct ifnet *, int, caddr_t);
|
||||
};
|
||||
#define if_mtu ifd.ifi_mtu
|
||||
#define if_type ifd.ifi_type
|
||||
#define if_addrlen ifd.ifi_addrlen
|
||||
#define if_hdrlen ifd.ifi_hdrlen
|
||||
#define if_metric ifd.ifi_metric
|
||||
#define if_baudrate ifd.ifi_baurdate
|
||||
#define if_ipackets ifd.ifi_ipackets
|
||||
#define if_ierrors ifd.ifi_ierrors
|
||||
#define if_opackets ifd.ifi_opackets
|
||||
#define if_oerrors ifd.ifi_oerrors
|
||||
#define if_collisions ifd.ifi_collisions
|
||||
#define if_ibytes ifd.ifi_ibytes
|
||||
#define if_obytes ifd.ifi_obytes
|
||||
#define if_imcasts ifd.ifi_imcasts
|
||||
#define if_omcasts ifd.ifi_omcasts
|
||||
#define if_iqdrops ifd.ifi_iqdrops
|
||||
#define if_noproto ifd.ifi_noproto
|
||||
|
||||
#define IFNAMSIZ 16
|
||||
|
||||
/* This structure is used for passing interface requests via ioctl */
|
||||
struct ifreq {
|
||||
char ifr_name[IFNAMSIZ]; /* name of interface */
|
||||
union {
|
||||
struct sockaddr ifru_addr;
|
||||
struct sockaddr ifru_dstaddr;
|
||||
struct sockaddr ifru_broadaddr;
|
||||
uint16 ifru_flags;
|
||||
int ifru_metric;
|
||||
caddr_t ifru_data;
|
||||
} ifr_ifru;
|
||||
};
|
||||
#define ifr_addr ifr_ifru.ifru_addr
|
||||
#define ifr_dstaddr ifr_ifru.ifru_dstaddr
|
||||
#define ifr_broadaddr ifr_ifru.ifru_broadaddr
|
||||
#define ifr_flags ifr_ifru.ifru_flags
|
||||
#define ifr_metric ifr_ifru.ifru_metric
|
||||
#define ifr_mtu ifr_ifru.ifru_metric /* sneaky overload :) */
|
||||
#define ifr_data ifr_ifru.ifru_data
|
||||
|
||||
struct ifconf {
|
||||
int ifc_len; /* length of associated buffer */
|
||||
union {
|
||||
caddr_t ifcu_buf;
|
||||
struct ifreq *ifcu_req;
|
||||
} ifc_ifcu;
|
||||
};
|
||||
#define ifc_buf ifc_ifcu.ifcu_buf
|
||||
#define ifc_req ifc_ifcu.ifcu_req
|
||||
|
||||
|
||||
#define IFAFREE(ifa) \
|
||||
do { \
|
||||
if ((ifa)->ifa_refcnt <= 0) \
|
||||
ifafree(ifa); \
|
||||
else \
|
||||
(ifa)->ifa_refcnt--; \
|
||||
} while (0)
|
||||
|
||||
/* used to pass in additional information, such as aliases */
|
||||
struct ifaliasreq {
|
||||
char ifa_name[IFNAMSIZ];
|
||||
struct sockaddr ifra_addr;
|
||||
struct sockaddr ifra_broadaddr;
|
||||
#define ifra_dstaddr ifra_broadaddr
|
||||
struct sockaddr ifra_mask;
|
||||
};
|
||||
|
||||
#define IFA_ROUTE RTF_UP
|
||||
|
||||
/*
|
||||
* Message format for use in obtaining information about interfaces
|
||||
* from sysctl and the routing socket.
|
||||
*/
|
||||
struct if_msghdr {
|
||||
u_short ifm_msglen; /* to skip over non-understood messages */
|
||||
u_char ifm_version; /* future binary compatability */
|
||||
u_char ifm_type; /* message type */
|
||||
int ifm_addrs; /* like rtm_addrs */
|
||||
int ifm_flags; /* value of if_flags */
|
||||
u_short ifm_index; /* index for associated ifp */
|
||||
struct if_data ifm_data;/* statistics and other data about if */
|
||||
};
|
||||
|
||||
/*
|
||||
* Message format for use in obtaining information about interface addresses
|
||||
* from sysctl and the routing socket.
|
||||
*/
|
||||
struct ifa_msghdr {
|
||||
u_short ifam_msglen; /* to skip over non-understood messages */
|
||||
u_char ifam_version; /* future binary compatability */
|
||||
u_char ifam_type; /* message type */
|
||||
int ifam_addrs; /* like rtm_addrs */
|
||||
int ifam_flags; /* value of ifa_flags */
|
||||
u_short ifam_index; /* index for associated ifp */
|
||||
int ifam_metric; /* value of ifa_metric */
|
||||
};
|
||||
|
||||
#ifdef _NETWORK_STACK
|
||||
|
||||
/* function declaration */
|
||||
struct ifq *start_ifq(void);
|
||||
void stop_ifq(struct ifq *);
|
||||
struct ifnet *get_interfaces(void);
|
||||
struct ifnet *ifunit(char *name);
|
||||
struct ifaddr *ifa_ifwithaddr(struct sockaddr *);
|
||||
struct ifaddr *ifa_ifwithaf(int);
|
||||
struct ifaddr *ifa_ifwithdstaddr(struct sockaddr *);
|
||||
struct ifaddr *ifa_ifwithnet(struct sockaddr *);
|
||||
struct ifaddr *ifa_ifwithroute(int, struct sockaddr *,
|
||||
struct sockaddr *);
|
||||
struct ifaddr *ifaof_ifpforaddr(struct sockaddr *, struct ifnet *);
|
||||
void ifafree(struct ifaddr *);
|
||||
|
||||
void if_attach(struct ifnet *ifp);
|
||||
void if_detach(struct ifnet *ifp);
|
||||
|
||||
int ifioctl(struct socket *so, int cmd, caddr_t data);
|
||||
int ifconf(int cmd, caddr_t data);
|
||||
void if_init(void);
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* OBOS_IF_H */
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) 1986, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)if_arp.h 8.1 (Berkeley) 6/10/93
|
||||
*/
|
||||
|
||||
#ifndef NET_IF_ARP_H
|
||||
#define NET_IF_ARP_H
|
||||
/*
|
||||
* Address Resolution Protocol.
|
||||
*
|
||||
* See RFC 826 for protocol description. ARP packets are variable
|
||||
* in size; the arphdr structure defines the fixed-length portion.
|
||||
* Protocol type values are the same as those for 10 Mb/s Ethernet.
|
||||
* It is followed by the variable-sized fields ar_sha, arp_spa,
|
||||
* arp_tha and arp_tpa in that order, according to the lengths
|
||||
* specified. Field names used correspond to RFC 826.
|
||||
*/
|
||||
struct arphdr {
|
||||
uint16 ar_hrd; /* format of hardware address */
|
||||
uint16 ar_pro; /* format of protocol address */
|
||||
uint8 ar_hln; /* length of hardware address */
|
||||
uint8 ar_pln; /* length of protocol address */
|
||||
uint16 ar_op; /* one of: */
|
||||
/*
|
||||
* The remaining fields are variable in size,
|
||||
* according to the sizes above.
|
||||
*/
|
||||
#ifdef COMMENT_ONLY
|
||||
uint8 ar_sha[]; /* sender hardware address */
|
||||
uint8 ar_spa[]; /* sender protocol address */
|
||||
uint8 ar_tha[]; /* target hardware address */
|
||||
uint8 ar_tpa[]; /* target protocol address */
|
||||
#endif
|
||||
};
|
||||
|
||||
#define ARPHRD_ETHER 1 /* ethernet hardware format */
|
||||
#define ARPHRD_IEEE802 6 /* IEEE 802 hardware format */
|
||||
#define ARPHRD_FRELAY 15 /* frame relay hardware format */
|
||||
|
||||
#define ARPOP_REQUEST 1 /* request to resolve address */
|
||||
#define ARPOP_REPLY 2 /* response to previous request */
|
||||
#define ARPOP_REVREQUEST 3 /* request protocol address given hardware */
|
||||
#define ARPOP_REVREPLY 4 /* response giving protocol address */
|
||||
#define ARPOP_INVREQUEST 8 /* request to identify peer */
|
||||
#define ARPOP_INVREPLY 9 /* response identifying peer */
|
||||
|
||||
/*
|
||||
* ARP ioctl request
|
||||
*/
|
||||
struct arpreq {
|
||||
struct sockaddr arp_pa; /* protocol address */
|
||||
struct sockaddr arp_ha; /* hardware address */
|
||||
int arp_flags; /* flags */
|
||||
};
|
||||
/* arp_flags and at_flags field values */
|
||||
#define ATF_INUSE 0x01 /* entry in use */
|
||||
#define ATF_COM 0x02 /* completed entry (enaddr valid) */
|
||||
#define ATF_PERM 0x04 /* permanent entry */
|
||||
#define ATF_PUBL 0x08 /* publish entry (respond for other host) */
|
||||
#define ATF_USETRAILERS 0x10 /* has requested trailers */
|
||||
|
||||
#endif /* NET_IF_ARP_H */
|
||||
@@ -0,0 +1,30 @@
|
||||
/* if.h
|
||||
* Interface definitions for beos
|
||||
*/
|
||||
|
||||
#ifndef OBOS_IF_DL_H
|
||||
#define OBOS_IF_DL_H
|
||||
|
||||
#include "net/if.h"
|
||||
|
||||
/* link level sockaddr structure */
|
||||
struct sockaddr_dl {
|
||||
uint8 sdl_len; /* Total length of sockaddr */
|
||||
uint8 sdl_family; /* AF_LINK */
|
||||
uint16 sdl_index; /* if != 0, system given index for interface */
|
||||
uint8 sdl_type; /* interface type */
|
||||
uint8 sdl_nlen; /* interface name length, no trailing 0 reqd. */
|
||||
uint8 sdl_alen; /* link level address length */
|
||||
uint8 sdl_slen; /* link layer selector length */
|
||||
char sdl_data[12]; /* minimum work area, can be larger;
|
||||
contains both if name and ll address */
|
||||
};
|
||||
|
||||
/* Macro to get a pointer to the link level address */
|
||||
#define LLADDR(s) ((caddr_t)((s)->sdl_data + (s)->sdl_nlen))
|
||||
|
||||
void link_addr (const char *, struct sockaddr_dl *);
|
||||
char *link_ntoa (const struct sockaddr_dl *);
|
||||
|
||||
#endif /* OBOS_IF_DL_H */
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
/* $OpenBSD: if_ppp.h,v 1.6 2001/06/09 06:16:38 angelos Exp $ */
|
||||
/* $NetBSD: if_ppp.h,v 1.11 1996/03/15 02:28:05 paulus Exp $ */
|
||||
|
||||
/*
|
||||
* if_ppp.h - Point-to-Point Protocol definitions.
|
||||
*
|
||||
* Copyright (c) 1989 Carnegie Mellon University.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by Carnegie Mellon University. The name of the
|
||||
* University may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
#ifndef _NET_IF_PPP_H_
|
||||
#define _NET_IF_PPP_H_
|
||||
|
||||
/*
|
||||
* Bit definitions for flags.
|
||||
*/
|
||||
#define SC_COMP_PROT 0x00000001 /* protocol compression (output) */
|
||||
#define SC_COMP_AC 0x00000002 /* header compression (output) */
|
||||
#define SC_COMP_TCP 0x00000004 /* TCP (VJ) compression (output) */
|
||||
#define SC_NO_TCP_CCID 0x00000008 /* disable VJ connection-id comp. */
|
||||
#define SC_REJ_COMP_AC 0x00000010 /* reject adrs/ctrl comp. on input */
|
||||
#define SC_REJ_COMP_TCP 0x00000020 /* reject TCP (VJ) comp. on input */
|
||||
#define SC_CCP_OPEN 0x00000040 /* Look at CCP packets */
|
||||
#define SC_CCP_UP 0x00000080 /* May send/recv compressed packets */
|
||||
#define SC_DEBUG 0x00010000 /* enable debug messages */
|
||||
#define SC_LOG_INPKT 0x00020000 /* log contents of good pkts recvd */
|
||||
#define SC_LOG_OUTPKT 0x00040000 /* log contents of pkts sent */
|
||||
#define SC_LOG_RAWIN 0x00080000 /* log all chars received */
|
||||
#define SC_LOG_FLUSH 0x00100000 /* log all chars flushed */
|
||||
#define SC_RCV_B7_0 0x01000000 /* have rcvd char with bit 7 = 0 */
|
||||
#define SC_RCV_B7_1 0x02000000 /* have rcvd char with bit 7 = 1 */
|
||||
#define SC_RCV_EVNP 0x04000000 /* have rcvd char with even parity */
|
||||
#define SC_RCV_ODDP 0x08000000 /* have rcvd char with odd parity */
|
||||
#define SC_MASK 0x0fff00ff /* bits that user can change */
|
||||
|
||||
/*
|
||||
* State bits in sc_flags, not changeable by user.
|
||||
*/
|
||||
#define SC_TIMEOUT 0x00000400 /* timeout is currently pending */
|
||||
#define SC_VJ_RESET 0x00000800 /* need to reset VJ decomp */
|
||||
#define SC_COMP_RUN 0x00001000 /* compressor has been inited */
|
||||
#define SC_DECOMP_RUN 0x00002000 /* decompressor has been inited */
|
||||
#define SC_DC_ERROR 0x00004000 /* non-fatal decomp error detected */
|
||||
#define SC_DC_FERROR 0x00008000 /* fatal decomp error detected */
|
||||
#define SC_TBUSY 0x10000000 /* xmitter doesn't need a packet yet */
|
||||
#define SC_PKTLOST 0x20000000 /* have lost or dropped a packet */
|
||||
#define SC_FLUSH 0x40000000 /* flush input until next PPP_FLAG */
|
||||
#define SC_ESCAPED 0x80000000 /* saw a PPP_ESCAPE */
|
||||
|
||||
/*
|
||||
* Ioctl definitions.
|
||||
*/
|
||||
|
||||
struct npioctl {
|
||||
int protocol; /* PPP procotol, e.g. PPP_IP */
|
||||
int on;
|
||||
};
|
||||
|
||||
/* Structure describing a CCP configuration option, for PPPIOCSCOMPRESS */
|
||||
struct ppp_option_data {
|
||||
u_char *ptr;
|
||||
u_int length;
|
||||
int transmit;
|
||||
};
|
||||
|
||||
struct ifpppstatsreq {
|
||||
char ifr_name[IFNAMSIZ];
|
||||
struct ppp_stats stats;
|
||||
};
|
||||
|
||||
struct ifpppcstatsreq {
|
||||
char ifr_name[IFNAMSIZ];
|
||||
struct ppp_comp_stats stats;
|
||||
};
|
||||
|
||||
/*
|
||||
* Ioctl definitions.
|
||||
*/
|
||||
|
||||
#define PPPIOCGFLAGS _IOR('t', 90, int) /* get configuration flags */
|
||||
#define PPPIOCSFLAGS _IOW('t', 89, int) /* set configuration flags */
|
||||
#define PPPIOCGASYNCMAP _IOR('t', 88, int) /* get async map */
|
||||
#define PPPIOCSASYNCMAP _IOW('t', 87, int) /* set async map */
|
||||
#define PPPIOCGUNIT _IOR('t', 86, int) /* get ppp unit number */
|
||||
#define PPPIOCGRASYNCMAP _IOR('t', 85, int) /* get receive async map */
|
||||
#define PPPIOCSRASYNCMAP _IOW('t', 84, int) /* set receive async map */
|
||||
#define PPPIOCGMRU _IOR('t', 83, int) /* get max receive unit */
|
||||
#define PPPIOCSMRU _IOW('t', 82, int) /* set max receive unit */
|
||||
#define PPPIOCSMAXCID _IOW('t', 81, int) /* set VJ max slot ID */
|
||||
#define PPPIOCGXASYNCMAP _IOR('t', 80, ext_accm) /* get extended ACCM */
|
||||
#define PPPIOCSXASYNCMAP _IOW('t', 79, ext_accm) /* set extended ACCM */
|
||||
#define PPPIOCXFERUNIT _IO('t', 78) /* transfer PPP unit */
|
||||
#define PPPIOCSCOMPRESS _IOW('t', 77, struct ppp_option_data)
|
||||
#define PPPIOCGNPMODE _IOWR('t', 76, struct npioctl) /* get NP mode */
|
||||
#define PPPIOCSNPMODE _IOW('t', 75, struct npioctl) /* set NP mode */
|
||||
#define PPPIOCGIDLE _IOR('t', 74, struct ppp_idle) /* get idle time */
|
||||
#define PPPIOCSPASS _IOW('t', 71, struct bpf_program) /* set pass filter */
|
||||
#define PPPIOCSACTIVE _IOW('t', 70, struct bpf_program) /* set active filt */
|
||||
|
||||
/* PPPIOC[GS]MTU are alternatives to SIOC[GS]IFMTU, used under Ultrix */
|
||||
#define PPPIOCGMTU _IOR('t', 73, int) /* get interface MTU */
|
||||
#define PPPIOCSMTU _IOW('t', 72, int) /* set interface MTU */
|
||||
|
||||
/*
|
||||
* These two are interface ioctls so that pppstats can do them on
|
||||
* a socket without having to open the serial device.
|
||||
*/
|
||||
#define SIOCGPPPSTATS _IOWR('i', 123, struct ifpppstatsreq)
|
||||
#define SIOCGPPPCSTATS _IOWR('i', 122, struct ifpppcstatsreq)
|
||||
|
||||
#ifdef _KERNEL_
|
||||
int pppoutput (struct ifnet *, struct mbuf *, struct sockaddr *,
|
||||
struct rtentry *);
|
||||
void pppinput (struct mbuf *);
|
||||
#endif
|
||||
|
||||
#endif /* _NET_IF_PPP_H_ */
|
||||
@@ -0,0 +1,23 @@
|
||||
/* if_types.h
|
||||
*
|
||||
* <URL:http://www.iana.org/assignments/ianaiftype-mib>
|
||||
*/
|
||||
|
||||
#ifndef NET_IF_TYPES_H
|
||||
#define NET_IF_TYPES_H
|
||||
|
||||
/* We just list the ones here we actually use... */
|
||||
|
||||
#define IFT_ETHER 0x06
|
||||
#define IFT_PPP 0x17
|
||||
#define IFT_LOOP 0x18
|
||||
#define IFT_SLIP 0x1c
|
||||
#define IFT_RS232 0x21
|
||||
#define IFT_PARA 0x22 /* Parallel port! ?? */
|
||||
#define IFT_ATM 0x25
|
||||
#define IFT_MODEM 0x31 /* Just a simple generic modem */
|
||||
#define IFT_FASTETHER 0x32 /* 100BaseT ethernet */
|
||||
#define IFT_ISDN 0x3f /* ISDN / X.25 */
|
||||
|
||||
#endif /* NET_IF_TYPES_H */
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* ppp_ctrl.h
|
||||
*
|
||||
* Definitions required to control PPP from userland
|
||||
*/
|
||||
|
||||
#ifndef _NET_PPP_CTRL_H_
|
||||
#define _NET_PPP_CTRL_H_
|
||||
|
||||
#define PPPCTRL_THREADNAME "PPP_Control_Thread"
|
||||
#define PPPCTRL_MAXSIZE 100 /* biggest lump of data we accept */
|
||||
|
||||
enum {
|
||||
PPPCTRL_OK = 0, /* Operation completed OK */
|
||||
PPPCTRL_FAIL, /* Operation failed */
|
||||
PPPCTRL_CREATE, /* create a new PPP device */
|
||||
PPPCTRL_DELETE, /* delete a PPP device */
|
||||
PPPCTRL_UP, /* start a ppp connection */
|
||||
PPPCTRL_OPEN, /* Open a device */
|
||||
PPPCTRL_DOWN, /* stop a ppp connection */
|
||||
|
||||
};
|
||||
|
||||
#endif /* _NET_PPP_CTRL_H_ */
|
||||
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* ppp_defs.h - PPP definitions.
|
||||
*
|
||||
* Copyright (c) 1994 The Australian National University.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, provided that the above copyright
|
||||
* notice appears in all copies. This software is provided without any
|
||||
* warranty, express or implied. The Australian National University
|
||||
* makes no representations about the suitability of this software for
|
||||
* any purpose.
|
||||
*
|
||||
* IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
|
||||
* PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
||||
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
|
||||
* THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
||||
* ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
|
||||
* OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
|
||||
* OR MODIFICATIONS.
|
||||
*/
|
||||
|
||||
#ifndef _PPP_DEFS_H_
|
||||
#define _PPP_DEFS_H_
|
||||
|
||||
/*
|
||||
* The basic PPP frame.
|
||||
*/
|
||||
|
||||
/* pppoe header = 6 bytes
|
||||
* hdlc frame header is 3 bytes
|
||||
* PPP protocol is 2 bytes,
|
||||
* so PPP_HDRLEN set to 8 to try and get us enough storage
|
||||
* for any of these. If we have to allocate a new mbuf then so be it.
|
||||
*/
|
||||
#define PPP_HDRLEN 8 /* octets for standard ppp header */
|
||||
#define PPP_PROTHDRLEN 2
|
||||
#define PPP_PROTOFF PPP_HDRLEN - PPP_PROTHDRLEN
|
||||
|
||||
#define PPP_FCSLEN 2 /* octets for FCS */
|
||||
#define PPP_MRU 1500 /* default MRU = max length of info field */
|
||||
|
||||
#define PPP_PROTOCOL(p) ((((u_char *)(p))[0] << 8) + ((u_char *)(p))[1])
|
||||
|
||||
/*
|
||||
* Significant octet values.
|
||||
*/
|
||||
#define PPP_ALLSTATIONS 0xff /* All-Stations broadcast address */
|
||||
#define PPP_UI 0x03 /* Unnumbered Information */
|
||||
#define PPP_FLAG 0x7e /* Flag Sequence */
|
||||
#define PPP_ESCAPE 0x7d /* Asynchronous Control Escape */
|
||||
#define PPP_TRANS 0x20 /* Asynchronous transparency modifier */
|
||||
|
||||
/*
|
||||
* Protocol field values.
|
||||
*/
|
||||
#define PPP_IP 0x21 /* Internet Protocol */
|
||||
#define PPP_XNS 0x25 /* Xerox NS */
|
||||
#define PPP_AT 0x29 /* AppleTalk Protocol */
|
||||
#define PPP_IPX 0x2b /* Internetwork Packet Exchange */
|
||||
#define PPP_VJC_COMP 0x2d /* VJ compressed TCP */
|
||||
#define PPP_VJC_UNCOMP 0x2f /* VJ uncompressed TCP */
|
||||
#define PPP_IPV6 0x57 /* Internet Protocol Version 6 */
|
||||
#define PPP_COMP 0xfd /* compressed packet */
|
||||
#define PPP_IPCP 0x8021 /* IP Control Protocol */
|
||||
#define PPP_ATCP 0x8029 /* AppleTalk Control Protocol */
|
||||
#define PPP_IPXCP 0x802b /* IPX Control Protocol */
|
||||
#define PPP_IPV6CP 0x8057 /* IPv6 Control Protocol */
|
||||
#define PPP_CCP 0x80fd /* Compression Control Protocol */
|
||||
#define PPP_LCP 0xc021 /* Link Control Protocol */
|
||||
#define PPP_PAP 0xc023 /* Password Authentication Protocol */
|
||||
#define PPP_LQR 0xc025 /* Link Quality Report protocol */
|
||||
#define PPP_CHAP 0xc223 /* Cryptographic Handshake Auth. Protocol */
|
||||
#define PPP_CBCP 0xc029 /* Callback Control Protocol */
|
||||
|
||||
/*
|
||||
* Values for FCS calculations.
|
||||
*/
|
||||
#define PPP_INITFCS 0xffff /* Initial FCS value */
|
||||
#define PPP_GOODFCS 0xf0b8 /* Good final FCS value */
|
||||
|
||||
/*
|
||||
* Extended asyncmap - allows any character to be escaped.
|
||||
*/
|
||||
typedef uint32 ext_accm[8];
|
||||
|
||||
/*
|
||||
* What to do with network protocol (NP) packets.
|
||||
*/
|
||||
enum NPmode {
|
||||
NPMODE_PASS, /* pass the packet through */
|
||||
NPMODE_DROP, /* silently drop the packet */
|
||||
NPMODE_ERROR, /* return an error */
|
||||
NPMODE_QUEUE /* save it up for later. */
|
||||
};
|
||||
|
||||
/*
|
||||
* Statistics.
|
||||
*/
|
||||
struct pppstat {
|
||||
uint ppp_ibytes; /* bytes received */
|
||||
uint ppp_ipackets; /* packets received */
|
||||
uint ppp_ierrors; /* receive errors */
|
||||
uint ppp_obytes; /* bytes sent */
|
||||
uint ppp_opackets; /* packets sent */
|
||||
uint ppp_oerrors; /* transmit errors */
|
||||
};
|
||||
|
||||
struct vjstat {
|
||||
uint vjs_packets; /* outbound packets */
|
||||
uint vjs_compressed; /* outbound compressed packets */
|
||||
uint vjs_searches; /* searches for connection state */
|
||||
uint vjs_misses; /* times couldn't find conn. state */
|
||||
uint vjs_uncompressedin; /* inbound uncompressed packets */
|
||||
uint vjs_compressedin; /* inbound compressed packets */
|
||||
uint vjs_errorin; /* inbound unknown type packets */
|
||||
uint vjs_tossed; /* inbound packets tossed because of error */
|
||||
};
|
||||
|
||||
struct ppp_stats {
|
||||
struct pppstat p; /* basic PPP statistics */
|
||||
struct vjstat vj; /* VJ header compression statistics */
|
||||
};
|
||||
|
||||
struct compstat {
|
||||
uint unc_bytes; /* total uncompressed bytes */
|
||||
uint unc_packets; /* total uncompressed packets */
|
||||
uint comp_bytes; /* compressed bytes */
|
||||
uint comp_packets; /* compressed packets */
|
||||
uint inc_bytes; /* incompressible bytes */
|
||||
uint inc_packets; /* incompressible packets */
|
||||
uint ratio; /* recent compression ratio << 8 */
|
||||
};
|
||||
|
||||
struct ppp_comp_stats {
|
||||
struct compstat c; /* packet compression statistics */
|
||||
struct compstat d; /* packet decompression statistics */
|
||||
};
|
||||
|
||||
/*
|
||||
* The following structure records the time in seconds since
|
||||
* the last NP packet was sent or received.
|
||||
*/
|
||||
struct ppp_idle {
|
||||
time_t xmit_idle; /* time since last NP packet sent */
|
||||
time_t recv_idle; /* time since last NP packet received */
|
||||
};
|
||||
|
||||
#ifdef _NETWORK_STACK
|
||||
uint16 pppfcs16(uint16 fcs, u_char *cp, int len);
|
||||
#endif
|
||||
|
||||
#endif /* _PPP_DEFS_H_ */
|
||||
@@ -0,0 +1,47 @@
|
||||
#ifndef _PPP_STATS_H_
|
||||
#define _PPP_STATS_H_
|
||||
|
||||
/*
|
||||
* Statistics.
|
||||
*/
|
||||
struct pppstat {
|
||||
uint ppp_ibytes; /* bytes received */
|
||||
uint ppp_ipackets; /* packets received */
|
||||
uint ppp_ierrors; /* receive errors */
|
||||
uint ppp_obytes; /* bytes sent */
|
||||
uint ppp_opackets; /* packets sent */
|
||||
uint ppp_oerrors; /* transmit errors */
|
||||
};
|
||||
|
||||
struct vjstat {
|
||||
uint vjs_packets; /* outbound packets */
|
||||
uint vjs_compressed; /* outbound compressed packets */
|
||||
uint vjs_searches; /* searches for connection state */
|
||||
uint vjs_misses; /* times couldn't find conn. state */
|
||||
uint vjs_uncompressedin; /* inbound uncompressed packets */
|
||||
uint vjs_compressedin; /* inbound compressed packets */
|
||||
uint vjs_errorin; /* inbound unknown type packets */
|
||||
uint vjs_tossed; /* inbound packets tossed because of error */
|
||||
};
|
||||
|
||||
struct ppp_stats {
|
||||
struct pppstat p; /* basic PPP statistics */
|
||||
struct vjstat vj; /* VJ header compression statistics */
|
||||
};
|
||||
|
||||
struct compstat {
|
||||
uint unc_bytes; /* total uncompressed bytes */
|
||||
uint unc_packets; /* total uncompressed packets */
|
||||
uint comp_bytes; /* compressed bytes */
|
||||
uint comp_packets; /* compressed packets */
|
||||
uint inc_bytes; /* incompressible bytes */
|
||||
uint inc_packets; /* incompressible packets */
|
||||
uint ratio; /* recent compression ratio << 8 */
|
||||
};
|
||||
|
||||
struct ppp_comp_stats {
|
||||
struct compstat c; /* packet compression statistics */
|
||||
struct compstat d; /* packet decompression statistics */
|
||||
};
|
||||
|
||||
#endif /* _PPP_STATS_H_ */
|
||||
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)radix.h 8.2 (Berkeley) 10/31/94
|
||||
* $FreeBSD: src/sys/net/radix.h,v 1.16.2.1 2000/05/03 19:17:11 wollman Exp $
|
||||
*/
|
||||
|
||||
#ifndef _RADIX_H_
|
||||
#define _RADIX_H_
|
||||
|
||||
#include <malloc.h>
|
||||
|
||||
/*
|
||||
* Radix search tree node layout.
|
||||
*/
|
||||
|
||||
struct radix_node {
|
||||
struct radix_mask *rn_mklist; /* list of masks contained in subtree */
|
||||
struct radix_node *rn_parent; /* parent */
|
||||
short rn_bit; /* bit offset; -1-index(netmask) */
|
||||
char rn_bmask; /* node: mask for bit test*/
|
||||
u_char rn_flags; /* enumerated next */
|
||||
#define RNF_NORMAL 1 /* leaf contains normal route */
|
||||
#define RNF_ROOT 2 /* leaf is root leaf for tree */
|
||||
#define RNF_ACTIVE 4 /* This node is alive (for rtfree) */
|
||||
union {
|
||||
struct { /* leaf only data: */
|
||||
caddr_t rn_Key; /* object of search */
|
||||
caddr_t rn_Mask; /* netmask, if present */
|
||||
struct radix_node *rn_Dupedkey;
|
||||
} rn_leaf;
|
||||
struct { /* node only data: */
|
||||
int rn_Off; /* where to start compare */
|
||||
struct radix_node *rn_L;/* progeny */
|
||||
struct radix_node *rn_R;/* progeny */
|
||||
} rn_node;
|
||||
} rn_u;
|
||||
#ifdef RN_DEBUG
|
||||
int rn_info;
|
||||
struct radix_node *rn_twin;
|
||||
struct radix_node *rn_ybro;
|
||||
#endif
|
||||
};
|
||||
|
||||
#define rn_dupedkey rn_u.rn_leaf.rn_Dupedkey
|
||||
#define rn_key rn_u.rn_leaf.rn_Key
|
||||
#define rn_mask rn_u.rn_leaf.rn_Mask
|
||||
#define rn_offset rn_u.rn_node.rn_Off
|
||||
#define rn_left rn_u.rn_node.rn_L
|
||||
#define rn_right rn_u.rn_node.rn_R
|
||||
|
||||
/*
|
||||
* Annotations to tree concerning potential routes applying to subtrees.
|
||||
*/
|
||||
|
||||
struct radix_mask {
|
||||
short rm_bit; /* bit offset; -1-index(netmask) */
|
||||
char rm_unused; /* cf. rn_bmask */
|
||||
u_char rm_flags; /* cf. rn_flags */
|
||||
struct radix_mask *rm_mklist; /* more masks to try */
|
||||
union {
|
||||
caddr_t rmu_mask; /* the mask */
|
||||
struct radix_node *rmu_leaf; /* for normal routes */
|
||||
} rm_rmu;
|
||||
int rm_refs; /* # of references to this struct */
|
||||
};
|
||||
|
||||
#define rm_mask rm_rmu.rmu_mask
|
||||
#define rm_leaf rm_rmu.rmu_leaf /* extra field would make 32 bytes */
|
||||
|
||||
#define MKGet(m) {\
|
||||
if (rn_mkfreelist) {\
|
||||
m = rn_mkfreelist; \
|
||||
rn_mkfreelist = (m)->rm_mklist; \
|
||||
} else \
|
||||
R_Malloc(m, struct radix_mask *, sizeof (*(m))); }\
|
||||
|
||||
#define MKFree(m) { (m)->rm_mklist = rn_mkfreelist; rn_mkfreelist = (m);}
|
||||
|
||||
typedef int walktree_f_t (struct radix_node *, void *);
|
||||
|
||||
struct radix_node_head {
|
||||
struct radix_node *rnh_treetop;
|
||||
int rnh_addrsize; /* permit, but not require fixed keys */
|
||||
int rnh_pktsize; /* permit, but not require fixed keys */
|
||||
struct radix_node *(*rnh_addaddr) /* add based on sockaddr */
|
||||
(void *v, void *mask,
|
||||
struct radix_node_head *head, struct radix_node nodes[]);
|
||||
struct radix_node *(*rnh_addpkt) /* add based on packet hdr */
|
||||
(void *v, void *mask,
|
||||
struct radix_node_head *head, struct radix_node nodes[]);
|
||||
struct radix_node *(*rnh_deladdr) /* remove based on sockaddr */
|
||||
(void *v, void *mask, struct radix_node_head *head);
|
||||
struct radix_node *(*rnh_delpkt) /* remove based on packet hdr */
|
||||
(void *v, void *mask, struct radix_node_head *head);
|
||||
struct radix_node *(*rnh_matchaddr) /* locate based on sockaddr */
|
||||
(void *v, struct radix_node_head *head);
|
||||
struct radix_node *(*rnh_lookup) /* locate based on sockaddr */
|
||||
(void *v, void *mask, struct radix_node_head *head);
|
||||
struct radix_node *(*rnh_matchpkt) /* locate based on packet hdr */
|
||||
(void *v, struct radix_node_head *head);
|
||||
int (*rnh_walktree) /* traverse tree */
|
||||
(struct radix_node_head *head, walktree_f_t *f, void *w);
|
||||
int (*rnh_walktree_from) /* traverse tree below a */
|
||||
(struct radix_node_head *head, void *a, void *m,
|
||||
walktree_f_t *f, void *w);
|
||||
void (*rnh_close) /* do something when the last ref drops */
|
||||
(struct radix_node *rn, struct radix_node_head *head);
|
||||
struct radix_node rnh_nodes[3]; /* empty tree for common case */
|
||||
};
|
||||
|
||||
#define Bcmp(a, b, n) memcmp(((char *)(a)), ((char *)(b)), (n))
|
||||
#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) malloc((unsigned int)(n))); \
|
||||
memset(p, 0, sizeof(*p)); \
|
||||
} while (0)
|
||||
#define Free(p) free((char *)p);
|
||||
|
||||
void rn_init (void);
|
||||
int rn_inithead (void **, int);
|
||||
int rn_refines (void *, void *);
|
||||
struct radix_node
|
||||
*rn_addmask (void *, int, int),
|
||||
*rn_addroute (void *, void *, struct radix_node_head *,
|
||||
struct radix_node [2]),
|
||||
*rn_delete (void *, void *, struct radix_node_head *),
|
||||
*rn_lookup (void *v_arg, void *m_arg,
|
||||
struct radix_node_head *head),
|
||||
*rn_match (void *, struct radix_node_head *);
|
||||
|
||||
/* extra fucntion so we don't have to export the mask_rnhead */
|
||||
struct radix_node *rn_head_search(void *argv_v);
|
||||
|
||||
#endif /* _RADIX_H_ */
|
||||
@@ -0,0 +1,17 @@
|
||||
/* raw_cb.h */
|
||||
|
||||
#ifndef NET_RAW_CB_H
|
||||
#define NET_RAW_CB_H
|
||||
|
||||
struct rawcb {
|
||||
struct rawcb *rcb_next;
|
||||
struct rawcb *rcb_prev;
|
||||
struct socket *rcb_socket;
|
||||
struct sockaddr *rcb_faddr;
|
||||
struct sockaddr *rcb_laddr;
|
||||
struct sockproto rcb_proto;
|
||||
};
|
||||
|
||||
#define sotorawcb(so) ((struct rawcb*)(so)->so_pcb)
|
||||
|
||||
#endif /* NET_RAW_CB_H */
|
||||
@@ -0,0 +1,208 @@
|
||||
/* route.h */
|
||||
|
||||
#ifndef NET_ROUTE_H
|
||||
#define NET_ROUTE_H
|
||||
|
||||
#include "net/radix.h"
|
||||
#include "sys/socket.h" /* for AF_MAX */
|
||||
/*
|
||||
* A route consists of a destination address and a reference
|
||||
* to a routing entry. These are often held by protocols
|
||||
* in their control blocks, e.g. inpcb.
|
||||
*/
|
||||
struct route {
|
||||
struct rtentry *ro_rt;
|
||||
struct sockaddr ro_dst;
|
||||
};
|
||||
|
||||
/*
|
||||
* These numbers are used by reliable protocols for determining
|
||||
* retransmission behavior and are included in the routing structure.
|
||||
*/
|
||||
struct rt_metrics {
|
||||
uint32 rmx_locks; /* Kernel must leave these values alone */
|
||||
uint32 rmx_mtu; /* MTU for this path */
|
||||
uint32 rmx_hopcount; /* max hops expected */
|
||||
uint32 rmx_expire; /* lifetime for route, e.g. redirect */
|
||||
u_long rmx_recvpipe; /* inbound delay-bandwith product */
|
||||
u_long rmx_sendpipe; /* outbound delay-bandwith product */
|
||||
u_long rmx_ssthresh; /* outbound gateway buffer limit */
|
||||
u_long rmx_rtt; /* estimated round trip time */
|
||||
u_long rmx_rttvar; /* estimated rtt variance */
|
||||
u_long rmx_pksent; /* packets sent using this route */
|
||||
};
|
||||
|
||||
/*
|
||||
* rmx_rtt and rmx_rttvar are stored as microseconds;
|
||||
* RTTTOPRHZ(rtt) converts to a value suitable for use
|
||||
* by a protocol slowtimo counter.
|
||||
*/
|
||||
#define RTM_RTTUNIT 1000000 /* units for rtt, rttvar, as units per sec */
|
||||
#define RTTTOPRHZ(r) ((r) / (RTM_RTTUNIT / PR_SLOWHZ))
|
||||
|
||||
struct rtentry {
|
||||
struct radix_node rt_nodes[2]; /* tree glue, and other values */
|
||||
struct sockaddr *rt_gateway; /* value */
|
||||
uint rt_flags; /* up/down?, host/net */
|
||||
int rt_refcnt; /* # held references */
|
||||
uint32 rt_use; /* raw # packets forwarded */
|
||||
struct ifnet *rt_ifp; /* the answer: interface to use */
|
||||
struct ifaddr *rt_ifa; /* the answer: interface to use */
|
||||
struct sockaddr *rt_genmask; /* for generation of cloned routes */
|
||||
caddr_t rt_llinfo; /* pointer to link level info cache */
|
||||
struct rt_metrics rt_rmx; /* metrics used by rx'ing protocols */
|
||||
struct rtentry *rt_gwroute; /* implied entry for gatewayed routes */
|
||||
struct rtentry *rt_parent; /* If cloned, parent of this route. */
|
||||
/* XXX - add this! */
|
||||
// rt_timer; * queue of timeouts for misc funcs *
|
||||
};
|
||||
#define rt_use rt_rmx.rmx_pksent
|
||||
#define rt_key(r) ((struct sockaddr *)((r)->rt_nodes->rn_key))
|
||||
#define rt_mask(r) ((struct sockaddr *)((r)->rt_nodes->rn_mask))
|
||||
|
||||
#define RTF_UP 0x1 /* route usable */
|
||||
#define RTF_GATEWAY 0x2 /* destination is a gateway */
|
||||
#define RTF_HOST 0x4 /* host entry (net otherwise) */
|
||||
#define RTF_REJECT 0x8 /* host or net unreachable */
|
||||
#define RTF_DYNAMIC 0x10 /* created dynamically (by redirect) */
|
||||
#define RTF_MODIFIED 0x20 /* modified dynamically (by redirect) */
|
||||
#define RTF_DONE 0x40 /* message confirmed */
|
||||
#define RTF_MASK 0x80 /* subnet mask present */
|
||||
#define RTF_CLONING 0x100 /* generate new routes on use */
|
||||
#define RTF_XRESOLVE 0x200 /* external daemon resolves name */
|
||||
#define RTF_LLINFO 0x400 /* generated by ARP or ESIS */
|
||||
#define RTF_STATIC 0x800 /* manually added */
|
||||
#define RTF_BLACKHOLE 0x1000 /* just discard pkts (during updates) */
|
||||
#define RTF_PROTO3 0x2000 /* protocol specific routing flag */
|
||||
#define RTF_PROTO2 0x4000 /* protocol specific routing flag */
|
||||
#define RTF_PROTO1 0x8000 /* protocol specific routing flag */
|
||||
|
||||
#define RTM_VERSION 3 /* Up the ante and ignore older versions */
|
||||
|
||||
#define RTM_ADD 0x1 /* Add Route */
|
||||
#define RTM_DELETE 0x2 /* Delete Route */
|
||||
#define RTM_CHANGE 0x3 /* Change Metrics or flags */
|
||||
#define RTM_GET 0x4 /* Report Metrics */
|
||||
#define RTM_LOSING 0x5 /* Kernel Suspects Partitioning */
|
||||
#define RTM_REDIRECT 0x6 /* Told to use different route */
|
||||
#define RTM_MISS 0x7 /* Lookup failed on this address */
|
||||
#define RTM_LOCK 0x8 /* fix specified metrics */
|
||||
#define RTM_OLDADD 0x9 /* caused by SIOCADDRT */
|
||||
#define RTM_OLDDEL 0xa /* caused by SIOCDELRT */
|
||||
#define RTM_RESOLVE 0xb /* req to resolve dst to LL addr */
|
||||
#define RTM_NEWADDR 0xc /* address being added to iface */
|
||||
#define RTM_DELADDR 0xd /* address being removed from iface */
|
||||
#define RTM_IFINFO 0xe /* iface going up/down etc. */
|
||||
|
||||
#define RTV_MTU 0x1 /* init or lock _mtu */
|
||||
#define RTV_HOPCOUNT 0x2 /* init or lock _hopcount */
|
||||
#define RTV_EXPIRE 0x4 /* init or lock _hopcount */
|
||||
#define RTV_RPIPE 0x8 /* init or lock _recvpipe */
|
||||
#define RTV_SPIPE 0x10 /* init or lock _sendpipe */
|
||||
#define RTV_SSTHRESH 0x20 /* init or lock _ssthresh */
|
||||
#define RTV_RTT 0x40 /* init or lock _rtt */
|
||||
#define RTV_RTTVAR 0x80 /* init or lock _rttvar */
|
||||
|
||||
/*
|
||||
* Bitmask values for rtm_addr.
|
||||
*/
|
||||
#define RTA_DST 0x1 /* destination sockaddr present */
|
||||
#define RTA_GATEWAY 0x2 /* gateway sockaddr present */
|
||||
#define RTA_NETMASK 0x4 /* netmask sockaddr present */
|
||||
#define RTA_GENMASK 0x8 /* cloning mask sockaddr present */
|
||||
#define RTA_IFP 0x10 /* interface name sockaddr present */
|
||||
#define RTA_IFA 0x20 /* interface addr sockaddr present */
|
||||
#define RTA_AUTHOR 0x40 /* sockaddr for author of redirect */
|
||||
#define RTA_BRD 0x80 /* for NEWADDR, broadcast or p-p dest addr */
|
||||
|
||||
/*
|
||||
* Index offsets for sockaddr array for alternate internal encoding.
|
||||
*/
|
||||
#define RTAX_DST 0 /* destination sockaddr present */
|
||||
#define RTAX_GATEWAY 1 /* gateway sockaddr present */
|
||||
#define RTAX_NETMASK 2 /* netmask sockaddr present */
|
||||
#define RTAX_GENMASK 3 /* cloning mask sockaddr present */
|
||||
#define RTAX_IFP 4 /* interface name sockaddr present */
|
||||
#define RTAX_IFA 5 /* interface addr sockaddr present */
|
||||
#define RTAX_AUTHOR 6 /* sockaddr for author of redirect */
|
||||
#define RTAX_BRD 7 /* for NEWADDR, broadcast or p-p dest addr */
|
||||
#define RTAX_MAX 8 /* size of array to allocate */
|
||||
|
||||
struct rt_msghdr {
|
||||
uint16 rtm_msglen;
|
||||
uint8 rtm_version;
|
||||
uint8 rtm_type;
|
||||
|
||||
uint16 rtm_index;
|
||||
int rtm_flags;
|
||||
int rtm_addrs;
|
||||
int rtm_seq;
|
||||
int rtm_errno;
|
||||
int rtm_use;
|
||||
uint32 rtm_inits;
|
||||
struct rt_metrics rtm_rmx;
|
||||
};
|
||||
|
||||
struct rt_addrinfo {
|
||||
int rti_addrs;
|
||||
struct sockaddr *rti_info[RTAX_MAX];
|
||||
int rti_flags;
|
||||
struct ifaddr *rti_ifa;
|
||||
struct ifnet *rti_ifp;
|
||||
struct rt_msghdr *rti_rtm;
|
||||
};
|
||||
|
||||
struct route_cb {
|
||||
int32 ip_count; /* how many AF_INET structures we have */
|
||||
int32 any_count; /* total of all above... */
|
||||
};
|
||||
|
||||
struct walkarg {
|
||||
int w_op;
|
||||
int w_arg;
|
||||
int w_given;
|
||||
int w_needed;
|
||||
int w_tmemsize;
|
||||
caddr_t w_where;
|
||||
caddr_t w_tmem;
|
||||
};
|
||||
|
||||
/*
|
||||
* Routing statistics.
|
||||
*/
|
||||
struct rtstat {
|
||||
int32 rts_badredirect; /* bogus redirect calls */
|
||||
int32 rts_dynamic; /* routes created by redirects */
|
||||
int32 rts_newgateway; /* routes modified by redirects */
|
||||
int32 rts_unreach; /* lookups which failed */
|
||||
int32 rts_wildcard; /* lookups satisfied by a wildcard */
|
||||
};
|
||||
|
||||
#define RTFREE(rt) do { \
|
||||
if ((rt)->rt_refcnt <= 1) \
|
||||
rtfree(rt); \
|
||||
else \
|
||||
(rt)->rt_refcnt--; \
|
||||
} while (0)
|
||||
|
||||
struct rtstat rtstat;
|
||||
struct radix_node_head *rt_tables[AF_MAX+1];
|
||||
|
||||
void route_init(void);
|
||||
|
||||
int rtinit (struct ifaddr *, int, int);
|
||||
void rtalloc (struct route *);
|
||||
struct rtentry *rtalloc1 (struct sockaddr *, int);
|
||||
void rtfree (struct rtentry *);
|
||||
int rtrequest (int, struct sockaddr *,
|
||||
struct sockaddr *, struct sockaddr *, int,
|
||||
struct rtentry **);
|
||||
void rt_maskedcopy(struct sockaddr *src,
|
||||
struct sockaddr *dst,
|
||||
struct sockaddr *netmask);
|
||||
int rt_setgate (struct rtentry *, struct sockaddr *,
|
||||
struct sockaddr *);
|
||||
|
||||
struct radix_node_head ** get_rt_tables(void);
|
||||
|
||||
#endif /* NET_ROUTE_H */
|
||||
@@ -0,0 +1,37 @@
|
||||
/* net_malloc.h
|
||||
*
|
||||
* Are we useing the system amlloc or our own...
|
||||
*/
|
||||
|
||||
#ifndef NET_MALLOC_H
|
||||
#define NET_MALLOC_H
|
||||
|
||||
#include <malloc.h>
|
||||
#include "net_misc.h"
|
||||
|
||||
#if USE_DEBUG_MALLOC
|
||||
|
||||
|
||||
|
||||
/* We check the boundary of the malloc'd area at one end of the
|
||||
* area allocated. If we are outside the area it'll stop, but we can
|
||||
* check only one end of the boundary. So the following essentially
|
||||
* allows us to choose which end.
|
||||
*/
|
||||
//#define OVERRUN
|
||||
#ifdef OVERRUN
|
||||
#define CHECK_OVERRUN 1
|
||||
#else
|
||||
#define CHECK_UNDERRUN 1
|
||||
#endif
|
||||
|
||||
/* use the area malloc code from marcus Overhagen */
|
||||
void *dbg_malloc(char *file, int line, size_t size);
|
||||
void dbg_free (char *file, int line, void *ptr);
|
||||
|
||||
#define malloc(s) dbg_malloc(__FILE__, __LINE__, s)
|
||||
#define free(s) do { dbg_free(__FILE__, __LINE__, s); s = NULL; } while (0)
|
||||
#endif /* USE_DEBUG_MALLOC */
|
||||
|
||||
#endif /* NET_MALLOC_H */
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
/* net_misc.h
|
||||
* 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"
|
||||
|
||||
#ifndef OBOS_NET_MISC_H
|
||||
#define OBOS_NET_MISC_H
|
||||
|
||||
#ifdef _KERNEL_
|
||||
#include <KernelExport.h>
|
||||
#define printf dprintf
|
||||
#endif
|
||||
|
||||
/* Not really sure if this is safe... */
|
||||
#define EHOSTDOWN (B_POSIX_ERROR_BASE + 45)
|
||||
|
||||
/* These are GCC only, so we'll need PPC version eventually... */
|
||||
struct quehead {
|
||||
struct quehead *qh_link;
|
||||
struct quehead *qh_rlink;
|
||||
};
|
||||
|
||||
static __inline void insque(void *a, void *b)
|
||||
{
|
||||
struct quehead *element = (struct quehead *)a,
|
||||
*head = (struct quehead *)b;
|
||||
|
||||
element->qh_link = head->qh_link;
|
||||
element->qh_rlink = head;
|
||||
head->qh_link = element;
|
||||
element->qh_link->qh_rlink = element;
|
||||
}
|
||||
|
||||
static __inline void remque(void *a)
|
||||
{
|
||||
struct quehead *element = (struct quehead *)a;
|
||||
|
||||
element->qh_link->qh_rlink = element->qh_rlink;
|
||||
element->qh_rlink->qh_link = element->qh_link;
|
||||
element->qh_rlink = 0;
|
||||
}
|
||||
|
||||
/* DEBUG Options!
|
||||
*
|
||||
* Having a single option is sort of lame so I'm going to start adding more here...
|
||||
*
|
||||
*/
|
||||
#define SHOW_DEBUG 0 /* general debugging stuff (verbose!) */
|
||||
#define SHOW_ROUTE 0 /* show routing information */
|
||||
#define ARP_DEBUG 0 /* show ARP debug info */
|
||||
#define USE_DEBUG_MALLOC 0 /* use the debug malloc code*/
|
||||
|
||||
typedef struct ifnet ifnet;
|
||||
|
||||
/* ARP lookup return codes... */
|
||||
enum {
|
||||
ARP_LOOKUP_OK = 1,
|
||||
ARP_LOOKUP_QUEUED = 2,
|
||||
ARP_LOOKUP_FAILED = 3
|
||||
};
|
||||
|
||||
typedef uint32 ipv4_addr;
|
||||
|
||||
/* These should be in KernelExport.h */
|
||||
#define B_SELECT_READ 1
|
||||
#define B_SELECT_WRITE 2
|
||||
#define B_SELECT_EXCEPTION 3
|
||||
|
||||
/* XXX - add some macro's for inserting various types of address
|
||||
*/
|
||||
|
||||
void net_server_add_device(ifnet *ifn);
|
||||
uint16 in_cksum(struct mbuf *m, int len, int off);
|
||||
void local_init(void);
|
||||
|
||||
/* sockets and in_pcb init */
|
||||
int sockets_init(void);
|
||||
void sockets_shutdown(void);
|
||||
int inpcb_init(void);
|
||||
|
||||
void start_tx_thread(ifnet *dev);
|
||||
void start_rx_thread(ifnet *dev);
|
||||
|
||||
/* Useful debugging functions */
|
||||
void dump_ipv4_addr(char *msg, void *ad);
|
||||
void print_ipv4_addr(void *ad);
|
||||
void dump_ether_addr(char *msg, void *ma);
|
||||
void print_ether_addr(void *ea);
|
||||
void dump_buffer(char *buffer, int len);
|
||||
void dump_sockaddr(void *ptr);
|
||||
|
||||
#endif /* OBOS_NET_MISC_H */
|
||||
|
||||
#endif /* _NETWORK_STACK */
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/* net_module.h
|
||||
* fundtions and staructures for all modules using the
|
||||
* net_server
|
||||
*/
|
||||
|
||||
#ifndef OBOS_NET_MODULE_H
|
||||
#define OBOS_NET_MODULE_H
|
||||
|
||||
#include <kernel/OS.h>
|
||||
#include <image.h>
|
||||
|
||||
#include "sys/mbuf.h"
|
||||
#include "net_misc.h"
|
||||
#include "sys/socketvar.h"
|
||||
#include "net/if.h"
|
||||
#include "net/route.h"
|
||||
|
||||
#ifdef _KERNEL_
|
||||
#include <module.h>
|
||||
#else
|
||||
typedef struct module_info {
|
||||
const char *name;
|
||||
uint32 flags;
|
||||
status_t (*std_ops)(int32, ...);
|
||||
} module_info;
|
||||
|
||||
#define B_MODULE_INIT 1
|
||||
#define B_MODULE_UNINIT 2
|
||||
#define B_KEEP_LOADED 0x00000001
|
||||
#endif
|
||||
|
||||
struct kernel_net_module_info {
|
||||
module_info info;
|
||||
int (*start)(void *);
|
||||
int (*stop)(void);
|
||||
};
|
||||
|
||||
struct net_module {
|
||||
struct net_module *next;
|
||||
char *name;
|
||||
struct kernel_net_module_info *ptr;
|
||||
#ifndef _KERNEL_
|
||||
image_id iid;
|
||||
#endif
|
||||
int status;
|
||||
};
|
||||
|
||||
enum {
|
||||
NET_LAYER1 = 1, /* link layer */
|
||||
NET_LAYER2, /* network layer */
|
||||
NET_LAYER3, /* transport layer */
|
||||
NET_LAYER4 /* socket layer */
|
||||
};
|
||||
|
||||
#endif /* OBOS_NET_MODULE_H */
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef NET_TIMER_H
|
||||
#define NET_TIMER_H
|
||||
/* net_timer.h - a small and more or less inaccurate timer for net modules.
|
||||
** The registered hooks will be called in the thread of the timer.
|
||||
**
|
||||
** Initial version by Axel Dörfler, [email protected]
|
||||
**
|
||||
** This file may be used under the terms of the OpenBeOS License.
|
||||
*/
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
typedef void (*net_timer_hook)(void *);
|
||||
typedef int32 net_timer_id;
|
||||
|
||||
|
||||
extern status_t net_init_timer(void);
|
||||
extern void net_shutdown_timer(void);
|
||||
|
||||
extern net_timer_id net_add_timer(net_timer_hook hook, void *data, bigtime_t interval);
|
||||
extern status_t net_remove_timer(net_timer_id);
|
||||
|
||||
|
||||
#endif /* NET_TIMER_H */
|
||||
@@ -0,0 +1,177 @@
|
||||
/* netdb.h */
|
||||
|
||||
#ifndef NETDB_H
|
||||
#define NETDB_H
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#ifndef MAXHOSTNAMELEN
|
||||
#define MAXHOSTNAMELEN 64
|
||||
#endif
|
||||
|
||||
#define HOST_NOT_FOUND 1
|
||||
#define TRY_AGAIN 2
|
||||
#define NO_RECOVERY 3
|
||||
#define NO_DATA 4
|
||||
|
||||
#ifndef h_errno
|
||||
extern int h_errno;
|
||||
extern int *_h_errnop(void);
|
||||
#define h_errno (*_h_errnop())
|
||||
#endif /* h_errno */
|
||||
|
||||
struct hostent {
|
||||
char *h_name;
|
||||
char **h_aliases;
|
||||
int h_addrtype;
|
||||
int h_length;
|
||||
char **h_addr_list;
|
||||
};
|
||||
#define h_addr h_addr_list[0]
|
||||
|
||||
struct servent {
|
||||
char *s_name;
|
||||
char **s_aliases;
|
||||
int s_port;
|
||||
char *s_proto;
|
||||
};
|
||||
|
||||
/*
|
||||
* Assumption here is that a network number
|
||||
* fits in an in_addr_t -- probably a poor one.
|
||||
*/
|
||||
struct netent {
|
||||
char *n_name; /* official name of net */
|
||||
char **n_aliases; /* alias list */
|
||||
int n_addrtype; /* net address type */
|
||||
in_addr_t n_net; /* network # */
|
||||
};
|
||||
|
||||
struct protoent {
|
||||
char *p_name; /* official protocol name */
|
||||
char **p_aliases; /* alias list */
|
||||
int p_proto; /* protocol # */
|
||||
};
|
||||
|
||||
struct addrinfo {
|
||||
int ai_flags; /* input flags */
|
||||
int ai_family; /* protocol family for socket */
|
||||
int ai_socktype; /* socket type */
|
||||
int ai_protocol; /* protocol for socket */
|
||||
socklen_t ai_addrlen; /* length of socket-address */
|
||||
struct sockaddr *ai_addr; /* socket-address for socket */
|
||||
char *ai_canonname; /* canonical name for service location (iff req) */
|
||||
struct addrinfo *ai_next; /* pointer to next in list */
|
||||
};
|
||||
|
||||
|
||||
struct hostent *gethostbyname(const char *hostname);
|
||||
struct hostent *gethostbyaddr(const char *hostname, int len, int type);
|
||||
struct servent *getservbyname(const char *name, const char *proto);
|
||||
void herror(const char *);
|
||||
unsigned long inet_addr(const char *a_addr);
|
||||
char *inet_ntoa(struct in_addr addr);
|
||||
|
||||
int gethostname(char *hostname, size_t hostlen);
|
||||
|
||||
/* BE specific, because of lack of UNIX passwd functions */
|
||||
int getusername(char *username, size_t userlen);
|
||||
int getpassword(char *password, size_t passlen);
|
||||
|
||||
|
||||
/* These are new! */
|
||||
struct netent *getnetbyaddr (in_addr_t, int);
|
||||
struct netent *getnetbyname (const char *);
|
||||
struct netent *getnetent (void);
|
||||
struct protoent *getprotoent (void);
|
||||
struct protoent *getprotobyname (const char *);
|
||||
struct protoent *getprotobynumber (int);
|
||||
struct hostent *gethostbyname2 (const char *, int);
|
||||
struct servent *getservbyport (int, const char *);
|
||||
|
||||
int getaddrinfo (const char *, const char *,
|
||||
const struct addrinfo *,
|
||||
struct addrinfo **);
|
||||
void freeaddrinfo (struct addrinfo *);
|
||||
int getnameinfo (const struct sockaddr *, socklen_t,
|
||||
char *, size_t, char *, size_t,
|
||||
int);
|
||||
|
||||
void sethostent (int);
|
||||
void setnetent (int);
|
||||
void setprotoent (int);
|
||||
void setservent (int);
|
||||
|
||||
void endhostent (void);
|
||||
void endnetent (void);
|
||||
void endprotoent (void);
|
||||
void endservent (void);
|
||||
|
||||
#define _PATH_HEQUIV "/etc/hosts.equiv"
|
||||
#define _PATH_HOSTS "/etc/hosts"
|
||||
#define _PATH_NETWORKS "/etc/networks"
|
||||
#define _PATH_PROTOCOLS "/etc/protocols"
|
||||
#define _PATH_SERVICES "/etc/services"
|
||||
|
||||
/*
|
||||
* Error return codes from gethostbyname() and gethostbyaddr()
|
||||
* (left in extern int h_errno).
|
||||
*/
|
||||
|
||||
#define NETDB_INTERNAL -1 /* see errno */
|
||||
#define NETDB_SUCCESS 0 /* no problem */
|
||||
#define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */
|
||||
#define TRY_AGAIN 2 /* Non-Authoritive Host not found, or SERVERFAIL */
|
||||
#define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
|
||||
#define NO_DATA 4 /* Valid name, no data record of requested type */
|
||||
#define NO_ADDRESS NO_DATA /* no address, look for MX record */
|
||||
|
||||
/* Values for getaddrinfo() and getnameinfo() */
|
||||
#define AI_PASSIVE 1 /* socket address is intended for bind() */
|
||||
#define AI_CANONNAME 2 /* request for canonical name */
|
||||
#define AI_NUMERICHOST 4 /* don't ever try nameservice */
|
||||
#define AI_EXT 8 /* enable non-portable extensions */
|
||||
/* valid flags for addrinfo */
|
||||
#define AI_MASK (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST)
|
||||
|
||||
#define NI_NUMERICHOST 1 /* return the host address, not the name */
|
||||
#define NI_NUMERICSERV 2 /* return the service address, not the name */
|
||||
#define NI_NOFQDN 4 /* return a short name if in the local domain */
|
||||
#define NI_NAMEREQD 8 /* fail if either host or service name is unknown */
|
||||
#define NI_DGRAM 16 /* look up datagram service instead of stream */
|
||||
#define NI_WITHSCOPEID 32 /* KAME hack: attach scopeid to host portion */
|
||||
|
||||
#define NI_MAXHOST MAXHOSTNAMELEN /* max host name returned by getnameinfo */
|
||||
#define NI_MAXSERV 32 /* max serv. name length returned by getnameinfo */
|
||||
|
||||
/*
|
||||
* Scope delimit character (KAME hack)
|
||||
*/
|
||||
#define SCOPE_DELIMITER '%'
|
||||
|
||||
#define EAI_BADFLAGS -1 /* invalid value for ai_flags */
|
||||
#define EAI_NONAME -2 /* name or service is not known */
|
||||
#define EAI_AGAIN -3 /* temporary failure in name resolution */
|
||||
#define EAI_FAIL -4 /* non-recoverable failure in name resolution */
|
||||
#define EAI_NODATA -5 /* no address associated with name */
|
||||
#define EAI_FAMILY -6 /* ai_family not supported */
|
||||
#define EAI_SOCKTYPE -7 /* ai_socktype not supported */
|
||||
#define EAI_SERVICE -8 /* service not supported for ai_socktype */
|
||||
#define EAI_ADDRFAMILY -9 /* address family for name not supported */
|
||||
#define EAI_MEMORY -10 /* memory allocation failure */
|
||||
#define EAI_SYSTEM -11 /* system error (code indicated in errno) */
|
||||
#define EAI_BADHINTS -12 /* invalid value for hints */
|
||||
#define EAI_PROTOCOL -13 /* resolved protocol is unknown */
|
||||
|
||||
|
||||
/*
|
||||
* Flags for getrrsetbyname()
|
||||
*/
|
||||
#define RRSET_VALIDATED 1
|
||||
|
||||
/*
|
||||
* Return codes for getrrsetbyname()
|
||||
*/
|
||||
#define ERRSET_SUCCESS 0
|
||||
|
||||
#endif /* NETDB_H */
|
||||
@@ -0,0 +1,61 @@
|
||||
/* Parts of this file are covered under the following copyright */
|
||||
/*
|
||||
* Copyright (c) 1982, 1986, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)icmp_var.h 8.1 (Berkeley) 6/10/93
|
||||
*/
|
||||
|
||||
#ifndef NETINET_ICMP_VAR_H
|
||||
#define NETINET_ICMP_VAR_H
|
||||
|
||||
#include <ByteOrder.h>
|
||||
|
||||
#include "netinet/ip_icmp.h"
|
||||
|
||||
struct icmpstat {
|
||||
int32 icps_oldicmp;
|
||||
int32 icps_oldshort;
|
||||
int32 icps_badcode;
|
||||
int32 icps_badlen;
|
||||
int32 icps_checksum;
|
||||
int32 icps_tooshort;
|
||||
int32 icps_error;
|
||||
int32 icps_reflect;
|
||||
int32 icps_outhist[ICMP_MAXTYPE + 1];
|
||||
int32 icps_inhist[ICMP_MAXTYPE + 1];
|
||||
};
|
||||
|
||||
#ifdef _NETWORK_STACK
|
||||
struct icmpstat icmpstat;
|
||||
#endif
|
||||
|
||||
#endif /* NETINET_ICMP_VAR_H */
|
||||
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
* Copyright (c) 1982, 1986, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)if_ether.h 8.1 (Berkeley) 6/10/93
|
||||
*/
|
||||
|
||||
#ifndef NETINET_IF_ETHER_H
|
||||
#define NETINET_IF_ETHER_H
|
||||
|
||||
#include <kernel/OS.h>
|
||||
|
||||
#include "net/if_arp.h"
|
||||
|
||||
/*
|
||||
* Ethernet address - 6 octets
|
||||
* this is only used by the ethers(3) functions.
|
||||
*/
|
||||
struct ether_addr {
|
||||
uint8 ether_addr_octet[6];
|
||||
};
|
||||
|
||||
/*
|
||||
* Some Ethernet constants.
|
||||
*/
|
||||
#define ETHER_ADDR_LEN 6 /* Ethernet address length */
|
||||
#define ETHER_TYPE_LEN 2 /* Ethernet type field length */
|
||||
#define ETHER_CRC_LEN 4 /* Ethernet CRC lenght */
|
||||
#define ETHER_HDR_LEN ((ETHER_ADDR_LEN * 2) + ETHER_TYPE_LEN)
|
||||
#define ETHER_MIN_LEN 64 /* Minimum frame length, CRC included */
|
||||
#define ETHER_MAX_LEN 1518 /* Maximum frame length, CRC included */
|
||||
|
||||
struct ether_header {
|
||||
uint8 ether_dhost[ETHER_ADDR_LEN];
|
||||
uint8 ether_shost[ETHER_ADDR_LEN];
|
||||
uint16 ether_type;
|
||||
};
|
||||
|
||||
#define ETHERTYPE_PUP 0x0200 /* PUP protocol */
|
||||
#define ETHERTYPE_IP 0x0800 /* IP protocol */
|
||||
#define ETHERTYPE_ARP 0x0806 /* address resolution protocol */
|
||||
#define ETHERTYPE_REVARP 0x8035 /* reverse addr resolution protocol */
|
||||
#define ETHERTYPE_8021Q 0x8100 /* IEEE 802.1Q VLAN tagging */
|
||||
#define ETHERTYPE_IPV6 0x86DD /* IPv6 protocol */
|
||||
#define ETHERTYPE_PPPOEDISC 0x8863 /* PPP Over Ethernet Discovery Stage */
|
||||
#define ETHERTYPE_PPPOE 0x8864 /* PPP Over Ethernet Session Stage */
|
||||
#define ETHERTYPE_LOOPBACK 0x9000 /* used to test interfaces */
|
||||
|
||||
#define ETHER_IS_MULTICAST(addr) (*(addr) & 0x01) /* is address mcast/bcast? */
|
||||
|
||||
#define ETHERMTU (ETHER_MAX_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)
|
||||
#define ETHERMIN (ETHER_MIN_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)
|
||||
|
||||
|
||||
#ifdef _NETWORK_STACK
|
||||
|
||||
/*
|
||||
* Macro to map an IP multicast address to an Ethernet multicast address.
|
||||
* The high-order 25 bits of the Ethernet address are statically assigned,
|
||||
* and the low-order 23 bits are taken from the low end of the IP address.
|
||||
*/
|
||||
#define ETHER_MAP_IP_MULTICAST(ipaddr, enaddr) \
|
||||
/* struct in_addr *ipaddr; */ \
|
||||
/* u_int8_t enaddr[ETHER_ADDR_LEN]; */ \
|
||||
{ \
|
||||
(enaddr)[0] = 0x01; \
|
||||
(enaddr)[1] = 0x00; \
|
||||
(enaddr)[2] = 0x5e; \
|
||||
(enaddr)[3] = ((uint8 *)ipaddr)[1] & 0x7f; \
|
||||
(enaddr)[4] = ((uint8 *)ipaddr)[2]; \
|
||||
(enaddr)[5] = ((uint8 *)ipaddr)[3]; \
|
||||
}
|
||||
|
||||
/*
|
||||
* Macro to map an IPv6 multicast address to an Ethernet multicast address.
|
||||
* The high-order 16 bits of the Ethernet address are statically assigned,
|
||||
* and the low-order 32 bits are taken from the low end of the IPv6 address.
|
||||
*/
|
||||
#define ETHER_MAP_IPV6_MULTICAST(ip6addr, enaddr) \
|
||||
/* struct in6_addr *ip6addr; */ \
|
||||
/* u_int8_t enaddr[ETHER_ADDR_LEN]; */ \
|
||||
{ \
|
||||
(enaddr)[0] = 0x33; \
|
||||
(enaddr)[1] = 0x33; \
|
||||
(enaddr)[2] = ((u_int8_t *)ip6addr)[12]; \
|
||||
(enaddr)[3] = ((u_int8_t *)ip6addr)[13]; \
|
||||
(enaddr)[4] = ((u_int8_t *)ip6addr)[14]; \
|
||||
(enaddr)[5] = ((u_int8_t *)ip6addr)[15]; \
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Structure shared between the ethernet driver modules and
|
||||
* the address resolution code. For example, each ec_softc or il_softc
|
||||
* begins with this structure.
|
||||
*/
|
||||
struct arpcom {
|
||||
struct ifnet ac_if; /* network-visible interface */
|
||||
uint8 ac_enaddr[ETHER_ADDR_LEN]; /* ethernet hardware address */
|
||||
struct in_addr ac_ipaddr;
|
||||
char ac__pad[2]; /* pad for some machines */
|
||||
// struct ether_multi *ac_multiaddrs; /* list of ether multicast addrs */
|
||||
int ac_multicnt; /* length of ac_multiaddrs list */
|
||||
};
|
||||
|
||||
struct ether_device {
|
||||
struct arpcom sc_ac;
|
||||
struct ether_device *next; /* next ether_device */
|
||||
};
|
||||
#define sc_if sc_ac.ac_if
|
||||
#define sc_addr sc_ac.ac_enaddr
|
||||
|
||||
struct ether_arp {
|
||||
struct arphdr ea_hdr;
|
||||
u_char arp_sha[6];
|
||||
u_char arp_spa[4];
|
||||
u_char arp_tha[6];
|
||||
u_char arp_tpa[4];
|
||||
};
|
||||
#define arp_hrd ea_hdr.ar_hrd
|
||||
#define arp_pro ea_hdr.ar_pro
|
||||
#define arp_hln ea_hdr.ar_hln
|
||||
#define arp_pln ea_hdr.ar_pln
|
||||
#define arp_op ea_hdr.ar_op
|
||||
|
||||
struct llinfo_arp {
|
||||
struct llinfo_arp *la_next;
|
||||
struct llinfo_arp *la_prev;
|
||||
struct rtentry *la_rt;
|
||||
struct mbuf *la_hold;
|
||||
int32 la_asked;
|
||||
};
|
||||
|
||||
#define la_timer la_rt->rt_rmx.rmx_expire
|
||||
|
||||
struct sockaddr_inarp {
|
||||
uint8 sin_len;
|
||||
uint8 sin_family;
|
||||
uint16 sin_port;
|
||||
struct in_addr sin_addr;
|
||||
struct in_addr sin_srcaddr;
|
||||
uint16 sin_tos;
|
||||
uint16 sin_other;
|
||||
};
|
||||
#define SIN_PROXY 1
|
||||
|
||||
/*
|
||||
* IP and ethernet specific routing flags
|
||||
*/
|
||||
#define RTF_USETRAILERS RTF_PROTO1 /* use trailers */
|
||||
#define RTF_ANNOUNCE RTF_PROTO2 /* announce new arp entry */
|
||||
#define RTF_PERMANENT_ARP RTF_PROTO3 /* only manual overwrite of entry */
|
||||
|
||||
#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);
|
||||
|
||||
|
||||
#else
|
||||
|
||||
char *ether_ntoa (struct ether_addr *);
|
||||
struct ether_addr *ether_aton (char *);
|
||||
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 /* NETINET_IF_ETHER_H */
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
/* in.h */
|
||||
#ifndef _NETINET_IN_H_
|
||||
#define _NETINET_IN_H_
|
||||
|
||||
#include <ByteOrder.h> /* for htonl */
|
||||
|
||||
#ifdef _NETWORK_STACK
|
||||
#include "net_misc.h"
|
||||
#endif
|
||||
#include "net/if.h"
|
||||
|
||||
/* XXX - This really doesn't belong in here... */
|
||||
/* XXX - move these to sys/param.h */
|
||||
typedef uint32 in_addr_t;
|
||||
typedef uint16 in_port_t;
|
||||
|
||||
/* Protocol definitions - add to as required... */
|
||||
|
||||
enum {
|
||||
IPPROTO_IP = 0, /* 0, IPv4 */
|
||||
IPPROTO_ICMP = 1, /* 1, ICMP (v4) */
|
||||
IPPROTO_IGMP = 2, /* 2, IGMP (group management) */
|
||||
IPPROTO_TCP = 6, /* 6, tcp */
|
||||
IPPROTO_UDP = 17, /* 17, UDP */
|
||||
IPPROTO_IPV6 = 41, /* 41, IPv6 in IPv6 */
|
||||
IPPROTO_ROUTING = 43, /* 43, Routing */
|
||||
IPPROTO_ICMPV6 = 58, /* 58, IPv6 ICMP */
|
||||
IPPROTO_ETHERIP = 97, /* 97, Ethernet in IPv4 */
|
||||
IPPROTO_RAW = 255 /* 255 */
|
||||
};
|
||||
|
||||
#define IPPROTO_MAX 256
|
||||
|
||||
/* Port numbers...
|
||||
* < IPPORT_RESERVED are privileged and should be
|
||||
* accessible only by root
|
||||
* > IPPORT_USERRESERVED are reserved for servers, though
|
||||
* not requiring privileged status
|
||||
*/
|
||||
|
||||
#define IPPORT_RESERVED 1024
|
||||
#define IPPORT_USERRESERVED 49151
|
||||
|
||||
/* This is an IPv4 address structure. Why is it a structure?
|
||||
* Historical reasons.
|
||||
*/
|
||||
struct in_addr {
|
||||
in_addr_t s_addr;
|
||||
};
|
||||
|
||||
/*
|
||||
* IP Version 4 socket address.
|
||||
*/
|
||||
struct sockaddr_in {
|
||||
uint8 sin_len;
|
||||
uint8 sin_family;
|
||||
uint16 sin_port;
|
||||
struct in_addr sin_addr;
|
||||
int8 sin_zero[8];
|
||||
};
|
||||
/* the address is therefore at sin_addr.s_addr */
|
||||
|
||||
/*
|
||||
* Options for use with [gs]etsockopt at the IP level.
|
||||
* First word of comment is data type; bool is stored in int.
|
||||
*/
|
||||
#define IP_OPTIONS 1 /* buf/ip_opts; set/get IP options */
|
||||
#define IP_HDRINCL 2 /* int; header is included with data */
|
||||
#define IP_TOS 3 /* int; IP type of service and preced. */
|
||||
#define IP_TTL 4 /* int; IP time to live */
|
||||
#define IP_RECVOPTS 5 /* bool; receive all IP opts w/dgram */
|
||||
#define IP_RECVRETOPTS 6 /* bool; receive IP opts for response */
|
||||
#define IP_RECVDSTADDR 7 /* bool; receive IP dst addr w/dgram */
|
||||
#define IP_RETOPTS 8 /* ip_opts; set/get IP options */
|
||||
#define IP_MULTICAST_IF 9 /* in_addr; set/get IP multicast i/f */
|
||||
#define IP_MULTICAST_TTL 10 /* u_char; set/get IP multicast ttl */
|
||||
#define IP_MULTICAST_LOOP 11 /* u_char; set/get IP multicast loopback */
|
||||
#define IP_ADD_MEMBERSHIP 12 /* ip_mreq; add an IP group membership */
|
||||
#define IP_DROP_MEMBERSHIP 13 /* ip_mreq; drop an IP group membership */
|
||||
|
||||
#ifdef _NETWORK_STACK
|
||||
#define __IPADDR(x) ((uint32) htonl((uint32)(x)))
|
||||
#else
|
||||
#define __IPADDR(x) ((uint32)(x))
|
||||
#endif
|
||||
|
||||
#define INADDR_ANY __IPADDR(0x00000000)
|
||||
#define INADDR_LOOPBACK __IPADDR(0x7f000001)
|
||||
#define INADDR_BROADCAST __IPADDR(0xffffffff) /* must be masked */
|
||||
|
||||
#define INADDR_UNSPEC_GROUP __IPADDR(0xe0000000) /* 224.0.0.0 */
|
||||
#define INADDR_ALLHOSTS_GROUP __IPADDR(0xe0000001) /* 224.0.0.1 */
|
||||
#define INADDR_ALLROUTERS_GROUP __IPADDR(0xe0000002) /* 224.0.0.2 */
|
||||
#define INADDR_MAX_LOCAL_GROUP __IPADDR(0xe00000ff) /* 224.0.0.255 */
|
||||
|
||||
#define IN_LOOPBACKNET 127 /* official! */
|
||||
|
||||
#ifndef _NETWORK_STACK
|
||||
#define INADDR_NONE __IPADDR(0xffffffff)
|
||||
#endif
|
||||
|
||||
#define IN_CLASSA(i) (((uint32)(i) & __IPADDR(0x80000000)) == \
|
||||
__IPADDR(0x00000000))
|
||||
#define IN_CLASSA_NET __IPADDR(0xff000000)
|
||||
#define IN_CLASSA_NSHIFT 24
|
||||
#define IN_CLASSA_HOST __IPADDR(0x00ffffff)
|
||||
#define IN_CLASSA_MAX 128
|
||||
|
||||
#define IN_CLASSB(i) (((uint32)(i) & __IPADDR(0xc0000000)) == \
|
||||
__IPADDR(0x80000000))
|
||||
#define IN_CLASSB_NET __IPADDR(0xffff0000)
|
||||
#define IN_CLASSB_NSHIFT 16
|
||||
#define IN_CLASSB_HOST __IPADDR(0x0000ffff)
|
||||
#define IN_CLASSB_MAX 65536
|
||||
|
||||
#define IN_CLASSC(i) (((uint32)(i) & __IPADDR(0xe0000000)) == \
|
||||
__IPADDR(0xc0000000))
|
||||
#define IN_CLASSC_NET __IPADDR(0xffffff00)
|
||||
#define IN_CLASSC_NSHIFT 8
|
||||
#define IN_CLASSC_HOST __IPADDR(0x000000ff)
|
||||
|
||||
#define IN_CLASSD(i) (((uint32)(i) & __IPADDR(0xf0000000)) == \
|
||||
__IPADDR(0xe0000000))
|
||||
/* These ones aren't really net and host fields, but routing needn't know. */
|
||||
#define IN_CLASSD_NET __IPADDR(0xf0000000)
|
||||
#define IN_CLASSD_NSHIFT 28
|
||||
#define IN_CLASSD_HOST __IPADDR(0x0fffffff)
|
||||
|
||||
#define IN_MULTICAST(i) IN_CLASSD(i)
|
||||
|
||||
#define IN_EXPERIMENTAL(i) (((uint32)(i) & 0xf0000000) == 0xf0000000)
|
||||
#define IN_BADCLASS(i) (((uint32)(i) & 0xf0000000) == 0xf0000000)
|
||||
|
||||
#define IP_MAX_MEMBERSHIPS 20
|
||||
|
||||
/* some helpful macro's :) */
|
||||
#define in_hosteq(s,t) ((s).s_addr == (t).s_addr)
|
||||
#define in_nullhost(x) ((x).s_addr == INADDR_ANY)
|
||||
#define satosin(sa) ((struct sockaddr_in *)(sa))
|
||||
#define sintosa(sin) ((struct sockaddr *)(sin))
|
||||
|
||||
/* 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*);
|
||||
|
||||
#endif /* NETINET_IN_H */
|
||||
@@ -0,0 +1,71 @@
|
||||
/* in_pcb.h
|
||||
* internet protcol control blocks
|
||||
*/
|
||||
|
||||
#include "sys/socketvar.h"
|
||||
#include "sys/socket.h"
|
||||
#include "net_misc.h"
|
||||
#include "pools.h"
|
||||
#include "netinet/ip.h"
|
||||
#include "netinet/in.h"
|
||||
#include "net/route.h"
|
||||
|
||||
#ifndef IN_PCB_H
|
||||
#define IN_PCB_H
|
||||
|
||||
enum {
|
||||
INP_HDRINCL = 0x01,
|
||||
INP_RECVOPTS = 0x02,
|
||||
INP_RECVRETOPTS = 0x04,
|
||||
INP_RECVDSTADDR = 0x08 /* receive IP destination as control inf. */
|
||||
};
|
||||
#define INP_CONTROLOPT (INP_RECVOPTS | INP_RECVRETOPTS | INP_RECVDSTADDR)
|
||||
|
||||
/* Constants for in_pcblookup */
|
||||
enum {
|
||||
INPLOOKUP_WILDCARD = 1,
|
||||
INPLOOKUP_SETLOCAL = 2,
|
||||
INPLOOKUP_IPV6 = 4
|
||||
};
|
||||
|
||||
struct inpcb {
|
||||
struct inpcb *inp_next;
|
||||
struct inpcb *inp_prev;
|
||||
struct inpcb *inp_head;
|
||||
|
||||
struct in_addr faddr; /* foreign address */
|
||||
uint16 fport; /* foreign port # */
|
||||
struct in_addr laddr; /* local address */
|
||||
uint16 lport; /* local port # */
|
||||
|
||||
struct socket *inp_socket;
|
||||
caddr_t inp_ppcb; /* pointer to a per protocol pcb*/
|
||||
struct ip inp_ip; /* header prototype */
|
||||
int inp_flags; /* flags */
|
||||
struct mbuf *inp_options; /* IP options */
|
||||
/* more will be required */
|
||||
struct route inp_route; /* the route to host */
|
||||
};
|
||||
|
||||
int in_pcballoc (struct socket *, struct inpcb *);
|
||||
int in_pcbbind (struct inpcb *, struct mbuf *);
|
||||
int in_pcbconnect (struct inpcb *, struct mbuf *);
|
||||
void in_pcbdetach (struct inpcb *);
|
||||
int in_pcbdisconnect (struct inpcb *);
|
||||
void in_losing (struct inpcb *);
|
||||
void in_setpeeraddr (struct inpcb *, struct mbuf *);
|
||||
void in_setsockaddr (struct inpcb *, struct mbuf *);
|
||||
|
||||
struct inpcb *in_pcblookup(struct inpcb *head, struct in_addr faddr,
|
||||
uint16 fport_a, struct in_addr laddr,
|
||||
uint16 lport_a, int flags);
|
||||
struct rtentry *in_pcbrtentry (struct inpcb *);
|
||||
void in_pcbnotify (struct inpcb *, struct sockaddr *,
|
||||
uint16, struct in_addr, uint16,
|
||||
int, void (*)(struct inpcb *, int));
|
||||
|
||||
/* helpful macro's */
|
||||
#define sotoinpcb(so) ((struct inpcb *)(so)->so_pcb)
|
||||
|
||||
#endif /* IN_PCB_H */
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 1982, 1986, 1993
|
||||
*The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
*This product includes software developed by the University of
|
||||
*California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*@(#)in_systm.h 8.1 (Berkeley) 6/10/93
|
||||
*/
|
||||
|
||||
#ifndef NETINET_IN_SYSTM_H
|
||||
#define NETINET_IN_SYSTM_H
|
||||
|
||||
/*
|
||||
* Miscellaneous internetwork
|
||||
* definitions for kernel.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Network types.
|
||||
*
|
||||
* Internally the system keeps counters in the headers with the bytes
|
||||
* swapped so that VAX instructions will work on them. It reverses
|
||||
* the bytes before transmission at each protocol level. The n_ types
|
||||
* represent the types with the bytes in ``high-ender'' order.
|
||||
*/
|
||||
typedef uint16 n_short; /* short as received from the net */
|
||||
typedef uint32 n_long; /* long as received from the net */
|
||||
|
||||
typedef uint32 n_time; /* ms since 00:00 GMT, byte rev */
|
||||
|
||||
#ifdef _NETWORK_STACK
|
||||
#define iptime() (htonl((uint32)real_time_clock_usecs()))
|
||||
#endif /* _NETWORK_STACK */
|
||||
|
||||
#endif /* NETINET_IN_SYSTM_H */
|
||||
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/* in_var.h */
|
||||
#ifndef NETINET_IN_VAR_H
|
||||
#define NETINET_IN_VAR_H
|
||||
|
||||
#include "netinet/in.h"
|
||||
#include "net/if.h"
|
||||
|
||||
struct in_ifaddr {
|
||||
struct ifaddr ia_ifa;
|
||||
struct in_ifaddr *ia_next;
|
||||
|
||||
uint32 ia_net;
|
||||
uint32 ia_netmask;
|
||||
uint32 ia_subnet;
|
||||
uint32 ia_subnetmask;
|
||||
struct in_addr ia_netbroadcast;
|
||||
struct sockaddr_in ia_addr;
|
||||
struct sockaddr_in ia_dstaddr; /* broadcast address */
|
||||
struct sockaddr_in ia_sockmask;
|
||||
/*XXX - milticast address list */
|
||||
};
|
||||
#define ia_ifp ia_ifa.ifa_ifp
|
||||
#define ia_flags ia_ifa.ifa_flags
|
||||
#define ia_broadaddr ia_dstaddr
|
||||
|
||||
#define ifatoia(ifa) ((struct in_ifaddr *)(ifa))
|
||||
#define sintosa(sin) ((struct sockaddr *)(sin))
|
||||
|
||||
/* used to pass in additional information, such as aliases */
|
||||
struct in_aliasreq {
|
||||
char ifa_name[IFNAMSIZ];
|
||||
struct sockaddr_in ifra_addr;
|
||||
struct sockaddr_in ifra_broadaddr;
|
||||
#define ifra_dstaddr ifra_broadaddr
|
||||
struct sockaddr_in ifra_mask;
|
||||
};
|
||||
|
||||
|
||||
struct in_multi {
|
||||
struct in_addr inm_addr;
|
||||
struct ifnet *inm_ifp;
|
||||
struct in_ifaddr *inm_ia;
|
||||
uint inm_refcount;
|
||||
uint inm_timer;
|
||||
struct in_multi *next;
|
||||
struct in_multi **prev;
|
||||
uint inm_state;
|
||||
};
|
||||
|
||||
/*
|
||||
* Given a pointer to an in_ifaddr (ifaddr),
|
||||
* return a pointer to the addr as a sockaddr_in.
|
||||
*/
|
||||
#define IA_SIN(ia) (&(((struct in_ifaddr *)(ia))->ia_addr))
|
||||
|
||||
struct in_ifaddr *in_ifaddr;
|
||||
|
||||
int in_control(struct socket *so, int cmd, caddr_t data, struct ifnet *ifp);
|
||||
int in_ifinit(struct ifnet *dev, struct in_ifaddr *ia, struct sockaddr_in *sin,
|
||||
int scrub);
|
||||
int inetctlerr(int cmd);
|
||||
struct in_ifaddr *get_primary_addr(void);
|
||||
|
||||
#endif /* NETINET_IN_VAR_H */
|
||||
@@ -0,0 +1,129 @@
|
||||
/* netinet/ip.h
|
||||
* definitions for ipv4 protocol
|
||||
*/
|
||||
|
||||
#ifndef NETINET_IP_H
|
||||
#define NETINET_IP_H
|
||||
|
||||
#include <ByteOrder.h>
|
||||
|
||||
#include "sys/mbuf.h"
|
||||
#include "net_misc.h"
|
||||
#include "netinet/in_systm.h"
|
||||
#include "netinet/in.h"
|
||||
|
||||
/* Based on RFC 791 */
|
||||
|
||||
#define IPVERSION 4
|
||||
|
||||
struct ip {
|
||||
#if B_HOST_IS_BENDIAN
|
||||
uint8 ip_v:4;
|
||||
uint8 ip_hl:4;
|
||||
#else
|
||||
uint8 ip_hl:4;
|
||||
uint8 ip_v:4;
|
||||
#endif
|
||||
uint8 ip_tos;
|
||||
uint16 ip_len;
|
||||
uint16 ip_id;
|
||||
int16 ip_off;
|
||||
uint8 ip_ttl;
|
||||
uint8 ip_p;
|
||||
uint16 ip_sum;
|
||||
struct in_addr ip_src;
|
||||
struct in_addr ip_dst;
|
||||
} _PACKED;
|
||||
|
||||
#define IP_MAXPACKET 65535/* Maximum packet size */
|
||||
|
||||
/* IP Type of Service */
|
||||
#define IPTOS_RELIABILITY 0x04
|
||||
#define IPTOS_THROUGHPUT 0x08
|
||||
#define IPTOS_LOWDELAY 0x10
|
||||
|
||||
/*
|
||||
* Definitions for options.
|
||||
*/
|
||||
#define IPOPT_COPIED(o)((o)&0x80)
|
||||
#define IPOPT_CLASS(o)((o)&0x60)
|
||||
#define IPOPT_NUMBER(o)((o)&0x1f)
|
||||
|
||||
#define IPOPT_CONTROL 0x00
|
||||
#define IPOPT_RESERVED1 0x20
|
||||
#define IPOPT_DEBMEAS 0x40
|
||||
#define IPOPT_RESERVED2 0x60
|
||||
|
||||
#define IPOPT_EOL 0/* end of option list */
|
||||
#define IPOPT_NOP 1/* no operation */
|
||||
|
||||
#define IPOPT_RR 7/* record packet route */
|
||||
#define IPOPT_TS 68/* timestamp */
|
||||
#define IPOPT_SECURITY 130/* provide s,c,h,tcc */
|
||||
#define IPOPT_LSRR 131/* loose source route */
|
||||
#define IPOPT_SATID 136/* satnet id */
|
||||
#define IPOPT_SSRR 137/* strict source route */
|
||||
|
||||
/*
|
||||
* Offsets to fields in options other than EOL and NOP.
|
||||
*/
|
||||
#define IPOPT_OPTVAL 0/* option ID */
|
||||
#define IPOPT_OLEN 1/* option length */
|
||||
#define IPOPT_OFFSET 2/* offset within option */
|
||||
#define IPOPT_MINOFF 4/* min value of above */
|
||||
|
||||
struct ip_timestamp {
|
||||
uint8 ipt_code;/* IPOPT_TS */
|
||||
uint8 ipt_len;/* size of structure (variable) */
|
||||
uint8 ipt_ptr;/* index of current entry */
|
||||
#if B_HOST_IS_BENDIAN
|
||||
uint8 ipt_oflw:4,
|
||||
ipt_flg:4;
|
||||
#else
|
||||
uint8 ipt_flg:4,
|
||||
ipt_oflw:4;
|
||||
#endif
|
||||
union ipt_timestamp {
|
||||
n_time ipt_time[1];
|
||||
struct ipt_ta {
|
||||
struct in_addr ipt_addr;
|
||||
n_time ipt_time;
|
||||
} ipt_ta;
|
||||
} ipt_timestamp;
|
||||
};
|
||||
|
||||
/* flag bits for ipt_flg */
|
||||
#define IPOPT_TS_TSONLY 0/* timestamps only */
|
||||
#define IPOPT_TS_TSANDADDR 1/* timestamps and addresses */
|
||||
#define IPOPT_TS_PRESPEC 3/* specified modules only */
|
||||
|
||||
/* bits for security (not byte swapped) */
|
||||
#define IPOPT_SECUR_UNCLASS 0x0000
|
||||
#define IPOPT_SECUR_CONFID 0xf135
|
||||
#define IPOPT_SECUR_EFTO 0x789a
|
||||
#define IPOPT_SECUR_MMMM 0xbc4d
|
||||
#define IPOPT_SECUR_RESTR 0xaf13
|
||||
#define IPOPT_SECUR_SECRET 0xd788
|
||||
#define IPOPT_SECUR_TOPSECRET 0x6bc5
|
||||
|
||||
#define MAXTTL 255/* maximum time to live (seconds) */
|
||||
#define IPDEFTTL 64/* default ttl, from RFC 1340 */
|
||||
#define IPFRAGTTL 60/* time to live for frags, slowhz */
|
||||
#define IPTTLDEC 1/* subtracted when forwarding */
|
||||
|
||||
#define IP_MSS 576/* default maximum segment size */
|
||||
|
||||
struct ippseudo {
|
||||
struct in_addr ippseudo_src; /* source internet address */
|
||||
struct in_addr ippseudo_dst; /* destination internet address */
|
||||
uint8 ippseudo_pad;/* pad, must be zero */
|
||||
uint8 ippseudo_p;/* protocol */
|
||||
uint16 ippseudo_len;/* protocol length */
|
||||
};
|
||||
|
||||
/* Fragment flags */
|
||||
#define IP_DF 0x4000 /* don't fragment */
|
||||
#define IP_MF 0x2000 /* more fragments */
|
||||
#define IP_OFFMASK 0x1fff
|
||||
|
||||
#endif /* NETINET_IP_H */
|
||||
@@ -0,0 +1,172 @@
|
||||
/* Parts of this file are covered under the following copyright */
|
||||
/*
|
||||
* Copyright (c) 1982, 1986, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)ip_icmp.h 8.1 (Berkeley) 6/10/93
|
||||
*/
|
||||
|
||||
#ifndef NETINET_IP_ICMP_H
|
||||
#define NETINET_IP_ICMP_H
|
||||
|
||||
#include <ByteOrder.h>
|
||||
|
||||
#include "net_misc.h"
|
||||
#include "netinet/in.h"
|
||||
|
||||
struct icmp {
|
||||
uint8 icmp_type;
|
||||
uint8 icmp_code;
|
||||
uint16 icmp_cksum;
|
||||
union {
|
||||
uint8 ih_pptr;
|
||||
struct in_addr ih_gwaddr;
|
||||
struct ih_idseq {
|
||||
n_short icd_id;
|
||||
n_short icd_seq;
|
||||
} ih_idseq;
|
||||
int32 ih_void;
|
||||
|
||||
/* ICMP_UNREACH_NEEDFRAG (RFC 1191) */
|
||||
struct ih_pmtu {
|
||||
n_short ipm_void;
|
||||
n_short ipm_nextmtu;
|
||||
} ih_pmtu;
|
||||
} icmp_hun;
|
||||
union {
|
||||
struct id_ts {
|
||||
n_time its_otime;
|
||||
n_time its_rtime;
|
||||
n_time its_ttime;
|
||||
} id_ts;
|
||||
struct id_ip {
|
||||
struct ip idi_ip;
|
||||
} id_ip;
|
||||
uint32 id_mask;
|
||||
char id_data[1];
|
||||
} icmp_dun;
|
||||
};
|
||||
|
||||
#define icmp_pptr icmp_hun.ih_pptr
|
||||
#define icmp_gwaddr icmp_hun.ih_gwaddr
|
||||
#define icmp_id icmp_hun.ih_idseq.icd_id
|
||||
#define icmp_seq icmp_hun.ih_idseq.icd_seq
|
||||
#define icmp_void icmp_hun.ih_void
|
||||
#define icmp_pmvoid icmp_hun.ih_pmtu.ipm_void
|
||||
#define icmp_nextmtu icmp_hun.ih_pmtu.ipm_nextmtu
|
||||
|
||||
#define icmp_otime icmp_dun.id_ts.its_otime
|
||||
#define icmp_rtime icmp_dun.id_ts.its_rtime
|
||||
#define icmp_ttime icmp_dun.id_ts.its_ttime
|
||||
#define icmp_ip icmp_dun.id_ip.idi_ip
|
||||
#define icmp_mask icmp_dun.id_mask
|
||||
#define icmp_data icmp_dun.id_data
|
||||
|
||||
#define ICMP_MINLEN 8 /* absolute minimum length */
|
||||
#define ICMP_ADVLENMIN (8 + sizeof(struct ip) + 8)
|
||||
#define ICMP_ADVLEN(p) (8 + ((p)->icmp_ip.ip_hl << 2) + 8)
|
||||
|
||||
/* Definition of type and code field values.
|
||||
*http://www.iana.org/assignments/icmp-parameters
|
||||
*/
|
||||
#define ICMP_ECHOREPLY 0/* echo reply */
|
||||
#define ICMP_UNREACH 3/* dest unreachable, codes: */
|
||||
#define ICMP_SOURCEQUENCH 4/* packet lost, slow down */
|
||||
#define ICMP_REDIRECT 5/* shorter route, codes: */
|
||||
#define ICMP_ALTHOSTADDR 6/* alternate host address */
|
||||
#define ICMP_ECHO 8/* echo service */
|
||||
#define ICMP_ROUTERADVERT 9/* router advertisement */
|
||||
#define ICMP_ROUTERSOLICIT 10/* router solicitation */
|
||||
#define ICMP_TIMXCEED 11/* time exceeded, code: */
|
||||
#define ICMP_PARAMPROB 12/* ip header bad */
|
||||
#define ICMP_TSTAMP 13/* timestamp request */
|
||||
#define ICMP_TSTAMPREPLY 14/* timestamp reply */
|
||||
#define ICMP_IREQ 15/* information request */
|
||||
#define ICMP_IREQREPLY 16/* information reply */
|
||||
#define ICMP_MASKREQ 17/* address mask request */
|
||||
#define ICMP_MASKREPLY 18/* address mask reply */
|
||||
#define ICMP_TRACEROUTE 30/* traceroute */
|
||||
#define ICMP_DATACONVERR 31/* data conversion error */
|
||||
#define ICMP_MOBILE_REDIRECT 32/* mobile host redirect */
|
||||
#define ICMP_IPV6_WHEREAREYOU 33/* IPv6 where-are-you */
|
||||
#define ICMP_IPV6_IAMHERE 34/* IPv6 i-am-here */
|
||||
#define ICMP_MOBILE_REGREQUEST 35/* mobile registration req */
|
||||
#define ICMP_MOBILE_REGREPLY 36/* mobile registration reply */
|
||||
#define ICMP_SKIP 39/* SKIP */
|
||||
#define ICMP_PHOTURIS 40/* Photuris */
|
||||
|
||||
#define ICMP_MAXTYPE 40
|
||||
|
||||
#define ICMP_UNREACH_NET 0/* bad net */
|
||||
#define ICMP_UNREACH_HOST 1/* bad host */
|
||||
#define ICMP_UNREACH_PROTOCOL 2/* bad protocol */
|
||||
#define ICMP_UNREACH_PORT 3/* bad port */
|
||||
#define ICMP_UNREACH_NEEDFRAG 4/* IP_DF caused drop */
|
||||
#define ICMP_UNREACH_SRCFAIL 5/* src route failed */
|
||||
#define ICMP_UNREACH_NET_UNKNOWN 6/* unknown net */
|
||||
#define ICMP_UNREACH_HOST_UNKNOWN 7/* unknown host */
|
||||
#define ICMP_UNREACH_ISOLATED 8/* src host isolated */
|
||||
#define ICMP_UNREACH_NET_PROHIB 9/* for crypto devs */
|
||||
#define ICMP_UNREACH_HOST_PROHIB 10/* ditto */
|
||||
#define ICMP_UNREACH_TOSNET 11/* bad tos for net */
|
||||
#define ICMP_UNREACH_TOSHOST 12/* bad tos for host */
|
||||
#define ICMP_UNREACH_FILTER_PROHIB 13/* prohibited access */
|
||||
#define ICMP_UNREACH_HOST_PRECEDENCE 14/* precedence violat'n*/
|
||||
#define ICMP_UNREACH_PRECEDENCE_CUTOFF 15/* precedence cutoff */
|
||||
|
||||
#define ICMP_REDIRECT_NET 0/* for network */
|
||||
#define ICMP_REDIRECT_HOST 1/* for host */
|
||||
#define ICMP_REDIRECT_TOSNET 2/* for tos and net */
|
||||
#define ICMP_REDIRECT_TOSHOST 3/* for tos and host */
|
||||
|
||||
#define ICMP_ROUTERADVERT_NORMAL 0/* normal advertisement */
|
||||
#define ICMP_ROUTERADVERT_NOROUTE_COMMON16/* selective routing */
|
||||
|
||||
#define ICMP_TIMXCEED_INTRANS 0/* ttl==0 in transit */
|
||||
#define ICMP_TIMXCEED_REASS 1/* ttl==0 in reass */
|
||||
|
||||
#define ICMP_PARAMPROB_ERRATPTR 0/* req. opt. absent */
|
||||
#define ICMP_PARAMPROB_OPTABSENT 1/* req. opt. absent */
|
||||
#define ICMP_PARAMPROB_LENGTH 2/* bad length */
|
||||
|
||||
#define ICMP_PHOTURIS_UNKNOWN_INDEX 1/* unknown sec index */
|
||||
#define ICMP_PHOTURIS_AUTH_FAILED 2/* auth failed */
|
||||
#define ICMP_PHOTURIS_DECRYPT_FAILED 3/* decrypt failed */
|
||||
|
||||
|
||||
#define ICMP_INFOTYPE(type) \
|
||||
((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || \
|
||||
(type) == ICMP_ROUTERADVERT || (type) == ICMP_ROUTERSOLICIT || \
|
||||
(type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY || \
|
||||
(type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || \
|
||||
(type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY)
|
||||
|
||||
#endif /* NETINET_IP_ICMP_H */
|
||||
@@ -0,0 +1,155 @@
|
||||
/* Parts of this file are covered under the following copyright */
|
||||
/*
|
||||
* Copyright (c) 1982, 1986, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)ip_var.h 8.1 (Berkeley) 6/10/93
|
||||
*/
|
||||
|
||||
#ifndef NETINET_IP_VAR_H
|
||||
#define NETINET_IP_VAR_H
|
||||
|
||||
#include "sys/socket.h"
|
||||
|
||||
/*
|
||||
* Overlay for ip header used by other protocols (tcp, udp).
|
||||
*/
|
||||
struct ipovly {
|
||||
caddr_t ih_next;
|
||||
caddr_t ih_prev;
|
||||
uint8 ih_x1; /* (unused) */
|
||||
uint8 ih_pr; /* protocol */
|
||||
uint16 ih_len; /* protocol length */
|
||||
struct in_addr ih_src; /* source internet address */
|
||||
struct in_addr ih_dst; /* destination internet address */
|
||||
};
|
||||
|
||||
/*
|
||||
* Structure stored in mbuf in inpcb.ip_options
|
||||
* and passed to ip_output when ip options are in use.
|
||||
* The actual length of the options (including ipopt_dst)
|
||||
* is in m_len.
|
||||
*/
|
||||
#define MAX_IPOPTLEN 40
|
||||
|
||||
struct ipoption {
|
||||
struct in_addr ipopt_dst; /* first-hop dst if source routed */
|
||||
int8 ipopt_list[MAX_IPOPTLEN]; /* options proper */
|
||||
};
|
||||
|
||||
/*
|
||||
* Structure attached to inpcb.ip_moptions and
|
||||
* passed to ip_output when IP multicast options are in use.
|
||||
*/
|
||||
struct ip_moptions {
|
||||
struct ifnet *imo_multicast_ifp; /* ifp for outgoing multicasts */
|
||||
uint8 imo_multicast_ttl; /* TTL for outgoing multicasts */
|
||||
uint8 imo_multicast_loop; /* 1 => here sends if a member */
|
||||
uint16 imo_num_memberships; /* no. memberships this socket */
|
||||
struct in_multi *imo_membership[IP_MAX_MEMBERSHIPS];
|
||||
};
|
||||
|
||||
struct ipasfrag {
|
||||
#if B_HOST_IS_BENDIAN
|
||||
uint8 ip_v:4;
|
||||
uint8 ip_hl:4;
|
||||
#else
|
||||
uint8 ip_hl:4;
|
||||
uint8 ip_v:4;
|
||||
#endif
|
||||
uint8 ipf_mff;
|
||||
int16 ip_len;
|
||||
uint16 ip_id;
|
||||
int16 ip_off;
|
||||
uint8 ip_ttl;
|
||||
uint8 ip_p;
|
||||
struct ipasfrag *ipf_next;
|
||||
struct ipasfrag *ipf_prev;
|
||||
};
|
||||
|
||||
struct ipq {
|
||||
struct ipq *next, *prev;
|
||||
uint8 ipq_ttl;
|
||||
uint8 ipq_p;
|
||||
uint16 ipq_id;
|
||||
struct ipasfrag *ipq_next, *ipq_prev;
|
||||
struct in_addr ipq_src, ipq_dst;
|
||||
};
|
||||
|
||||
struct ipstat {
|
||||
int32 ips_total; /* total packets received */
|
||||
int32 ips_badsum; /* checksum bad */
|
||||
int32 ips_tooshort; /* packet too short */
|
||||
int32 ips_toosmall; /* not enough data */
|
||||
int32 ips_badhlen; /* ip header length < data size */
|
||||
int32 ips_badlen; /* ip length < ip header length */
|
||||
int32 ips_fragments; /* fragments received */
|
||||
int32 ips_fragdropped; /* frags dropped (dups, out of space) */
|
||||
int32 ips_fragtimeout; /* fragments timed out */
|
||||
int32 ips_forward; /* packets forwarded */
|
||||
int32 ips_cantforward; /* packets rcvd for unreachable dest */
|
||||
int32 ips_redirectsent; /* packets forwarded on same net */
|
||||
int32 ips_noproto; /* unknown or unsupported protocol */
|
||||
int32 ips_delivered; /* datagrams delivered to upper level*/
|
||||
int32 ips_localout; /* total ip packets generated here */
|
||||
int32 ips_odropped; /* lost packets due to nobufs, etc. */
|
||||
int32 ips_reassembled; /* total packets reassembled ok */
|
||||
int32 ips_fragmented; /* datagrams sucessfully fragmented */
|
||||
int32 ips_ofragments; /* output fragments created */
|
||||
int32 ips_cantfrag; /* don't fragment flag was set, etc. */
|
||||
int32 ips_badoptions; /* error in option processing */
|
||||
int32 ips_noroute; /* packets discarded due to no route */
|
||||
int32 ips_badvers; /* ip version != 4 */
|
||||
int32 ips_rawout; /* total raw ip packets generated */
|
||||
int32 ips_badfrags; /* malformed fragments (bad length) */
|
||||
int32 ips_rcvmemdrop; /* frags dropped for lack of memory */
|
||||
int32 ips_toolong; /* ip length > max ip packet size */
|
||||
int32 ips_nogif; /* no match gif found */
|
||||
int32 ips_badaddr; /* invalid address on header */
|
||||
int32 ips_inhwcsum; /* hardware checksummed on input */
|
||||
int32 ips_outhwcsum; /* hardware checksummed on output */
|
||||
};
|
||||
|
||||
#ifdef _NETWORK_STACK
|
||||
|
||||
#define IP_FORWARDING 0x1 /* most of ip header exists */
|
||||
#define IP_RAWOUTPUT 0x2 /* raw ip header exists */
|
||||
#define IP_ROUTETOIF SO_DONTROUTE /* bypass routing tables */
|
||||
#define IP_ALLOWBROADCAST SO_BROADCAST /* can send broadcast packets */
|
||||
#define IP_MTUDISC 0x0400 /* pmtu discovery, set DF */
|
||||
|
||||
struct ipstat ipstat;
|
||||
|
||||
void ip_stripoptions (struct mbuf *, struct mbuf *);
|
||||
|
||||
#endif /* _NETWORK_STACK */
|
||||
|
||||
#endif /* NETINET_IP_VAR_H */
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (c) 1982, 1986, 1993
|
||||
*The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
*
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
*
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef NETINET_TCP_H
|
||||
#define NETINET_TCP_H
|
||||
|
||||
typedef uint32 tcp_seq;
|
||||
|
||||
struct tcphdr {
|
||||
uint16 th_sport; /* src port */
|
||||
uint16 th_dport; /* dest. port */
|
||||
tcp_seq th_seq; /* seq number */
|
||||
tcp_seq th_ack; /* ack number */
|
||||
|
||||
#if B_HOST_IS_BENDIAN
|
||||
uint8 th_off:4,
|
||||
th_x2:4;
|
||||
#else
|
||||
uint8 th_x2:4, /* unused */
|
||||
th_off:4; /* data offset */
|
||||
#endif
|
||||
uint8 th_flags; /* ACK, FIN, PUSH, RST, SYN, URG */
|
||||
uint16 th_win; /* advertised window */
|
||||
uint16 th_sum; /* checksum */
|
||||
uint16 th_urp; /* urgent offset */
|
||||
} _PACKED;
|
||||
|
||||
#define TH_FIN 0x01
|
||||
#define TH_SYN 0x02
|
||||
#define TH_RST 0x04
|
||||
#define TH_PUSH 0x08
|
||||
#define TH_ACK 0x10
|
||||
#define TH_URG 0x20
|
||||
|
||||
#define TCPOPT_EOL 0
|
||||
#define TCPOPT_NOP 1
|
||||
#define TCPOPT_MAXSEG 2
|
||||
#define TCPOPT_WINDOW 3
|
||||
#define TCPOPT_SACK_PERMITTED 4 /* Experimental */
|
||||
#define TCPOPT_SACK 5 /* Experimental */
|
||||
#define TCPOPT_TIMESTAMP 8
|
||||
#define TCPOPT_SIGNATURE 19
|
||||
|
||||
#define MAX_TCPOPTLEN 40 /* Absolute maximum TCP options len */
|
||||
|
||||
#define TCPOLEN_MAXSEG 4
|
||||
#define TCPOLEN_WINDOW 3
|
||||
#define TCPOLEN_SACK 8 /* 2*sizeof(tcp_seq) */
|
||||
#define TCPOLEN_SACK_PERMITTED 2
|
||||
#define TCPOLEN_TIMESTAMP 10
|
||||
#define TCPOLEN_TSTAMP_APPA (TCPOLEN_TIMESTAMP+2) /* appendix A */
|
||||
#define TCPOLEN_SIGNATURE 18
|
||||
|
||||
#define TCPOPT_TSTAMP_HDR \
|
||||
(TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_TIMESTAMP<<8|TCPOLEN_TIMESTAMP)
|
||||
|
||||
#define TCP_MSS 512
|
||||
#define TCP_MAXWIN 65535
|
||||
#define TCP_MAX_WINSHIFT 14
|
||||
|
||||
|
||||
#endif /* NETINET_TCP_H */
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 1982, 1986, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)tcp_debug.h 8.1 (Berkeley) 6/10/93
|
||||
*/
|
||||
|
||||
#ifndef NETINET_TCP_DEBUG_H_
|
||||
#define NETINET_TCP_DEBUG_H_
|
||||
|
||||
struct tcp_debug {
|
||||
n_time td_time;
|
||||
short td_act;
|
||||
short td_ostate;
|
||||
caddr_t td_tcb;
|
||||
struct tcpiphdr td_ti;
|
||||
short td_req;
|
||||
struct tcpcb td_cb;
|
||||
};
|
||||
|
||||
#define TA_INPUT 0
|
||||
#define TA_OUTPUT 1
|
||||
#define TA_USER 2
|
||||
#define TA_RESPOND 3
|
||||
#define TA_DROP 4
|
||||
|
||||
#ifdef TANAMES
|
||||
char *tanames[] =
|
||||
{ "input", "output", "user", "respond", "drop" };
|
||||
#endif /* TANAMES */
|
||||
|
||||
#define TCP_NDEBUG 100
|
||||
struct tcp_debug tcp_debug[TCP_NDEBUG];
|
||||
int tcp_debx;
|
||||
#endif /* _NETINET_TCP_DEBUG_H_ */
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (c) 1982, 1986, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)tcp_fsm.h 8.1 (Berkeley) 6/10/93
|
||||
*/
|
||||
|
||||
#ifndef _NETINET_TCP_FSM_H_
|
||||
#define _NETINET_TCP_FSM_H_
|
||||
|
||||
/*
|
||||
* TCP FSM state definitions.
|
||||
* Per RFC793, September, 1981.
|
||||
*/
|
||||
|
||||
#define TCP_NSTATES 11
|
||||
|
||||
#define TCPS_CLOSED 0 /* closed */
|
||||
#define TCPS_LISTEN 1 /* listening for connection */
|
||||
#define TCPS_SYN_SENT 2 /* active, have sent syn */
|
||||
#define TCPS_SYN_RECEIVED 3 /* have sent and received syn */
|
||||
/* states < TCPS_ESTABLISHED are those where connections not established */
|
||||
#define TCPS_ESTABLISHED 4 /* established */
|
||||
#define TCPS_CLOSE_WAIT 5 /* rcvd fin, waiting for close */
|
||||
/* states > TCPS_CLOSE_WAIT are those where user has closed */
|
||||
#define TCPS_FIN_WAIT_1 6 /* have closed, sent fin */
|
||||
#define TCPS_CLOSING 7 /* closed xchd FIN; await ACK */
|
||||
#define TCPS_LAST_ACK 8 /* had fin and close; await FIN ACK */
|
||||
/* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */
|
||||
#define TCPS_FIN_WAIT_2 9 /* have closed, fin is acked */
|
||||
#define TCPS_TIME_WAIT 10 /* in 2*msl quiet wait after close */
|
||||
|
||||
#define TCPS_HAVERCVDSYN(s) ((s) >= TCPS_SYN_RECEIVED)
|
||||
#define TCPS_HAVEESTABLISHED(s) ((s) >= TCPS_ESTABLISHED)
|
||||
#define TCPS_HAVERCVDFIN(s) ((s) >= TCPS_TIME_WAIT)
|
||||
|
||||
#ifdef TCPOUTFLAGS
|
||||
/*
|
||||
* Flags used when sending segments in tcp_output.
|
||||
* Basic flags (TH_RST,TH_ACK,TH_SYN,TH_FIN) are totally
|
||||
* determined by state, with the proviso that TH_FIN is sent only
|
||||
* if all data queued for output is included in the segment.
|
||||
*/
|
||||
u_char tcp_outflags[TCP_NSTATES] = {
|
||||
TH_RST|TH_ACK, 0, TH_SYN, TH_SYN|TH_ACK,
|
||||
TH_ACK, TH_ACK,
|
||||
TH_FIN|TH_ACK, TH_ACK, TH_FIN|TH_ACK, TH_ACK, TH_ACK,
|
||||
};
|
||||
#endif /* TCPOUTFLAGS */
|
||||
|
||||
#ifdef TCPSTATES
|
||||
char *tcpstates[] = {
|
||||
"CLOSED", "LISTEN", "SYN_SENT", "SYN_RCVD",
|
||||
"ESTABLISHED", "CLOSE_WAIT", "FIN_WAIT_1", "CLOSING",
|
||||
"LAST_ACK", "FIN_WAIT_2", "TIME_WAIT",
|
||||
};
|
||||
#endif /* TCPSTATES */
|
||||
#endif /* _NETINET_TCP_FSM_H_ */
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 1982, 1986, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)tcp_seq.h 8.1 (Berkeley) 6/10/93
|
||||
*/
|
||||
|
||||
#ifndef _NETINET_TCP_SEQ_H_
|
||||
#define _NETINET_TCP_SEQ_H_
|
||||
|
||||
/*
|
||||
* TCP sequence numbers are 32 bit integers operated
|
||||
* on with modular arithmetic. These macros can be
|
||||
* used to compare such integers.
|
||||
*/
|
||||
#define SEQ_LT(a,b) ((int)((a)-(b)) < 0)
|
||||
#define SEQ_LEQ(a,b) ((int)((a)-(b)) <= 0)
|
||||
#define SEQ_GT(a,b) ((int)((a)-(b)) > 0)
|
||||
#define SEQ_GEQ(a,b) ((int)((a)-(b)) >= 0)
|
||||
|
||||
/*
|
||||
* Macros to initialize tcp sequence numbers for
|
||||
* send and receive from initial send and receive
|
||||
* sequence numbers.
|
||||
*/
|
||||
#define tcp_rcvseqinit(tp) \
|
||||
(tp)->rcv_adv = (tp)->rcv_nxt = (tp)->irs + 1
|
||||
|
||||
#define tcp_sendseqinit(tp) \
|
||||
(tp)->snd_una = (tp)->snd_nxt = (tp)->snd_max = (tp)->snd_up = \
|
||||
(tp)->iss
|
||||
|
||||
#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 */
|
||||
|
||||
#endif /* _NETINET_TCP_SEQ_H_ */
|
||||
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* Copyright (c) 1982, 1986, 1993
|
||||
*The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
*
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
*
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef NETINET_TCP_TIMERS_H
|
||||
#define NETINET_TCP_TIMERS_H
|
||||
|
||||
/*
|
||||
* Definitions of the TCP timers. These timers are counted
|
||||
* down PR_SLOWHZ times a second.
|
||||
*/
|
||||
#define TCPT_NTIMERS 4
|
||||
|
||||
#define TCPT_REXMT 0 /* retransmission timer */
|
||||
#define TCPT_PERSIST 1 /* presist timer */
|
||||
#define TCPT_KEEP 2 /* keeplaive timer or conn est timer */
|
||||
#define TCPT_2MSL 3 /* 2MSL timer or FIN_WAIT_2 timer */
|
||||
|
||||
/*
|
||||
* The TCPT_REXMT timer is used to force retransmissions.
|
||||
* The TCP has the TCPT_REXMT timer set whenever segments
|
||||
* have been sent for which ACKs are expected but not yet
|
||||
* received. If an ACK is received which advances tp->snd_una,
|
||||
* then the retransmit timer is cleared (if there are no more
|
||||
* outstanding segments) or reset to the base value (if there
|
||||
* are more ACKs expected). Whenever the retransmit timer goes off,
|
||||
* we retransmit one unacknowledged segment, and do a backoff
|
||||
* on the retransmit timer.
|
||||
*
|
||||
* The TCPT_PERSIST timer is used to keep window size information
|
||||
* flowing even if the window goes shut. If all previous transmissions
|
||||
* have been acknowledged (so that there are no retransmissions in progress),
|
||||
* and the window is too small to bother sending anything, then we start
|
||||
* the TCPT_PERSIST timer. When it expires, if the window is nonzero,
|
||||
* we go to transmit state. Otherwise, at intervals send a single byte
|
||||
* into the peer's window to force him to update our window information.
|
||||
* We do this at most as often as TCPT_PERSMIN time intervals,
|
||||
* but no more frequently than the current estimate of round-trip
|
||||
* packet time. The TCPT_PERSIST timer is cleared whenever we receive
|
||||
* a window update from the peer.
|
||||
*
|
||||
* The TCPT_KEEP timer is used to keep connections alive. If an
|
||||
* connection is idle (no segments received) for TCPTV_KEEP_INIT amount of time,
|
||||
* but not yet established, then we drop the connection. Once the connection
|
||||
* is established, if the connection is idle for TCPTV_KEEP_IDLE time
|
||||
* (and keepalives have been enabled on the socket), we begin to probe
|
||||
* the connection. We force the peer to send us a segment by sending:
|
||||
* <SEQ=SND.UNA-1><ACK=RCV.NXT><CTL=ACK>
|
||||
* This segment is (deliberately) outside the window, and should elicit
|
||||
* an ack segment in response from the peer. If, despite the TCPT_KEEP
|
||||
* initiated segments we cannot elicit a response from a peer in TCPT_MAXIDLE
|
||||
* amount of time probing, then we drop the connection.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Time constants.
|
||||
*/
|
||||
#define TCPTV_MSL ( 30*PR_SLOWHZ ) /* max seg lifetime (hah!) */
|
||||
#define TCPTV_SRTTBASE 0 /* base roundtrip time;
|
||||
* if 0, no idea yet */
|
||||
#define TCPTV_SRTTDFLT ( 3*PR_SLOWHZ ) /* assumed RTT if no info */
|
||||
|
||||
#define TCPTV_PERSMIN ( 5*PR_SLOWHZ ) /* retransmit persistance */
|
||||
#define TCPTV_PERSMAX ( 60*PR_SLOWHZ ) /* maximum persist interval */
|
||||
|
||||
#define TCPTV_KEEP_INIT ( 75*PR_SLOWHZ ) /* initial connect keep alive */
|
||||
#define TCPTV_KEEP_IDLE (120*60*PR_SLOWHZ) /* dflt time before probing */
|
||||
#define TCPTV_KEEPINTVL ( 75*PR_SLOWHZ ) /* default probe interval */
|
||||
#define TCPTV_KEEPCNT 8 /* max probes before drop */
|
||||
|
||||
#define TCPTV_MIN ( 1*PR_SLOWHZ ) /* minimum allowable value */
|
||||
#define TCPTV_REXMTMAX ( 64*PR_SLOWHZ ) /* max allowable REXMT value */
|
||||
|
||||
#define TCP_LINGERTIME 120 /* at most 2 minutes... */
|
||||
#define TCP_MAXRXTSHIFT 12 /* maximum retransmits */
|
||||
|
||||
#ifdef TCPTIMERS
|
||||
char *tcptimers[] =
|
||||
{ "REXMT", "PERSIST", "KEEP", "2MSL" };
|
||||
#endif /* TCPTIMERS */
|
||||
|
||||
/*
|
||||
* Force a time value to be in a certain range.
|
||||
*/
|
||||
#define TCPT_RANGESET(tv, value, tvmin, tvmax) { \
|
||||
(tv) = (value); \
|
||||
if ((tv) < (tvmin)) \
|
||||
(tv) = (tvmin); \
|
||||
else if ((tv) > (tvmax)) \
|
||||
(tv) = (tvmax); \
|
||||
}
|
||||
|
||||
#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 */
|
||||
extern int tcp_maxidle; /* time to drop after starting probes */
|
||||
extern int tcp_ttl; /* time to live for TCP segs */
|
||||
extern int tcp_backoff[];
|
||||
|
||||
|
||||
#endif /* _NETWORK_STACK */
|
||||
|
||||
#endif /* NETINET_TCP_TIMERS_H */
|
||||
@@ -0,0 +1,280 @@
|
||||
/*
|
||||
* Copyright (c) 1982, 1986, 1993
|
||||
*The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
*
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
*
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef NETINET_TCP_VAR_H
|
||||
#define NETINET_TCP_VAR_H
|
||||
|
||||
/*
|
||||
* Tcp control block, one per tcp connection
|
||||
*/
|
||||
struct tcpcb {
|
||||
struct tcpiphdr *seg_next;
|
||||
struct tcpiphdr *seg_prev;
|
||||
int16 t_state; /* state of this connection */
|
||||
int16 t_timer[TCPT_NTIMERS]; /* tcp timers */
|
||||
int16 t_rxtshift; /* log(2) of rexmt exp. backoff */
|
||||
int16 t_rxtcur; /* current retransmit value */
|
||||
int16 t_dupacks; /* consecutive dup acks recd */
|
||||
uint16 t_maxseg; /* maximum segment size */
|
||||
int8 t_force; /* 1 if forcing out a byte */
|
||||
uint16 t_flags;
|
||||
|
||||
struct tcpiphdr *t_template; /* skeletal packet for transmit */
|
||||
struct inpcb *t_inpcb; /* back pointer to internet pcb */
|
||||
/*
|
||||
* The following fields are used as in the protocol specification.
|
||||
* See RFC783, Dec. 1981, page 21.
|
||||
*/
|
||||
/* send sequence variables */
|
||||
tcp_seq snd_una; /* send unacknowledged */
|
||||
tcp_seq snd_nxt; /* send next */
|
||||
tcp_seq snd_up; /* send urgent pointer */
|
||||
tcp_seq snd_wl1; /* window update seg seq number */
|
||||
tcp_seq snd_wl2; /* window update seg ack number */
|
||||
tcp_seq iss; /* initial send sequence number */
|
||||
unsigned long snd_wnd; /* send window */
|
||||
|
||||
/* receive sequence variables */
|
||||
unsigned long rcv_wnd; /* receive window */
|
||||
tcp_seq rcv_nxt; /* receive next */
|
||||
tcp_seq rcv_up; /* receive urgent pointer */
|
||||
tcp_seq irs; /* initial receive sequence number */
|
||||
|
||||
/*
|
||||
* Additional variables for this implementation.
|
||||
*/
|
||||
/* receive variables */
|
||||
tcp_seq rcv_adv; /* advertised window */
|
||||
/* retransmit variables */
|
||||
tcp_seq snd_max; /* highest sequence number sent;
|
||||
* used to recognize retransmits
|
||||
*/
|
||||
/* congestion control (for slow start, source quench, retransmit after loss) */
|
||||
unsigned long snd_cwnd; /* congestion-controlled window */
|
||||
unsigned long snd_ssthresh; /* snd_cwnd size threshhold for
|
||||
* for slow start exponential to
|
||||
* linear switch
|
||||
*/
|
||||
uint16 t_maxopd; /* mss plus options */
|
||||
uint16 t_peermss; /* peer's maximum segment size */
|
||||
|
||||
/*
|
||||
* transmit timing stuff. See below for scale of srtt and rttvar.
|
||||
* "Variance" is actually smoothed difference.
|
||||
*/
|
||||
int16 t_idle; /* inactivity time */
|
||||
int16 t_rtt; /* round trip time */
|
||||
tcp_seq t_rtseq; /* sequence number being timed */
|
||||
uint16 t_srtt; /* smoothed round-trip time */
|
||||
uint16 t_rttvar; /* variance in round-trip time */
|
||||
uint16 t_rttmin; /* minimum rtt allowed */
|
||||
uint32 max_sndwnd; /* largest window peer has offered */
|
||||
|
||||
/* out-of-band data */
|
||||
int8 t_oobflags; /* have some */
|
||||
int8 t_iobc; /* input character */
|
||||
int16 t_softerror; /* possible error, not yet reported... */
|
||||
/* RFC 1323 variables */
|
||||
uint8 snd_scale; /* window scaling for send window */
|
||||
uint8 rcv_scale; /* window scaling for recv window */
|
||||
uint8 request_r_scale; /* pending window scaling */
|
||||
uint8 requested_s_scale;
|
||||
uint32 ts_recent; /* timestamp echo data */
|
||||
uint32 ts_recent_age; /* when last updated */
|
||||
tcp_seq last_ack_sent;
|
||||
};
|
||||
|
||||
#define intotcpcb(ip) ((struct tcpcb*)(ip)->inp_ppcb)
|
||||
#define sototcpcb(so) (intotcpcb(sotoinpcb(so)))
|
||||
|
||||
#define TF_ACKNOW 0x0001 /* send ACK immeadiately */
|
||||
#define TF_DELACK 0x0002 /* send ACK, but try to delay it */
|
||||
#define TF_NODELAY 0x0004 /* don't delay packets to coalesce */
|
||||
#define TF_NOOPT 0x0008 /* don't use tcp options */
|
||||
#define TF_SENTFIN 0x0010 /* have sent FIN */
|
||||
#define TF_REQ_SCALE 0x0020 /* have/will request window scaling */
|
||||
#define TF_RCVD_SCALE 0x0040 /* other side has requested scaling */
|
||||
#define TF_REQ_TSTMP 0x0080 /* have/will request timestamps */
|
||||
#define TF_RCVD_TSTMP 0x0100 /* a timestamp was received in SYN */
|
||||
#define TF_SACK_PERMIT 0x0200 /* other side said I could SACK */
|
||||
#define TF_SIGNATURE 0x0400 /* require TCP MD5 signature */
|
||||
|
||||
#define TCPOOB_HAVEDATA 0x01 /* we have TCP OOB data */
|
||||
#define TCPOOB_HADDATA 0x02 /* we've had some TCP OOB data */
|
||||
|
||||
/*
|
||||
* The smoothed round-trip time and estimated variance
|
||||
* are stored as fixed point numbers scaled by the values below.
|
||||
* For convenience, these scales are also used in smoothing the average
|
||||
* (smoothed = (1/scale)sample + ((scale-1)/scale)smoothed).
|
||||
* With these scales, srtt has 3 bits to the right of the binary point,
|
||||
* and thus an "ALPHA" of 0.875. rttvar has 2 bits to the right of the
|
||||
* binary point, and is smoothed with an ALPHA of 0.75.
|
||||
*/
|
||||
#define TCP_RTT_SCALE 8 /* multiplier for srtt; 3 bits frac. */
|
||||
#define TCP_RTT_SHIFT 3 /* shift for srtt; 3 bits frac. */
|
||||
#define TCP_RTTVAR_SCALE 4 /* multiplier for rttvar; 2 bits */
|
||||
#define TCP_RTTVAR_SHIFT 2 /* multiplier for rttvar; 2 bits */
|
||||
|
||||
#define TCP_REXMTVAL(tp) \
|
||||
((((tp)->t_srtt >> TCP_RTT_SHIFT) + (tp)->t_rttvar) >> 2)
|
||||
/*
|
||||
* TCP statistics.
|
||||
* Many of these should be kept per connection,
|
||||
* but that's inconvenient at the moment.
|
||||
*/
|
||||
struct tcpstat {
|
||||
uint32 tcps_connattempt; /* connections initiated */
|
||||
uint32 tcps_accepts; /* connections accepted */
|
||||
uint32 tcps_connects; /* connections established */
|
||||
uint32 tcps_drops; /* connections dropped */
|
||||
uint32 tcps_conndrops; /* embryonic connections dropped */
|
||||
uint32 tcps_closed; /* conn. closed (includes drops) */
|
||||
uint32 tcps_segstimed; /* segs where we tried to get rtt */
|
||||
uint32 tcps_rttupdated; /* times we succeeded */
|
||||
uint32 tcps_delack; /* delayed acks sent */
|
||||
uint32 tcps_timeoutdrop; /* conn. dropped in rxmt timeout */
|
||||
uint32 tcps_rexmttimeo; /* retransmit timeouts */
|
||||
uint32 tcps_persisttimeo; /* persist timeouts */
|
||||
uint32 tcps_persistdrop; /* connections dropped in persist */
|
||||
uint32 tcps_keeptimeo; /* keepalive timeouts */
|
||||
uint32 tcps_keepprobe; /* keepalive probes sent */
|
||||
uint32 tcps_keepdrops; /* connections dropped in keepalive */
|
||||
|
||||
uint32 tcps_sndtotal; /* total packets sent */
|
||||
uint32 tcps_sndpack; /* data packets sent */
|
||||
uint64 tcps_sndbyte; /* data bytes sent */
|
||||
uint32 tcps_sndrexmitpack; /* data packets retransmitted */
|
||||
uint64 tcps_sndrexmitbyte; /* data bytes retransmitted */
|
||||
uint64 tcps_sndrexmitfast; /* Fast retransmits */
|
||||
uint32 tcps_sndacks; /* ack-only packets sent */
|
||||
uint32 tcps_sndprobe; /* window probes sent */
|
||||
uint32 tcps_sndurg; /* packets sent with URG only */
|
||||
uint32 tcps_sndwinup; /* window update-only packets sent */
|
||||
uint32 tcps_sndctrl; /* control (SYN|FIN|RST) packets sent */
|
||||
|
||||
uint32 tcps_rcvtotal; /* total packets received */
|
||||
uint32 tcps_rcvpack; /* packets received in sequence */
|
||||
uint64 tcps_rcvbyte; /* bytes received in sequence */
|
||||
uint32 tcps_rcvbadsum; /* packets received with ccksum errs */
|
||||
uint32 tcps_rcvbadoff; /* packets received with bad offset */
|
||||
uint32 tcps_rcvmemdrop; /* packets dropped for lack of memory */
|
||||
uint32 tcps_rcvnosec; /* packets dropped for lack of ipsec */
|
||||
uint32 tcps_rcvshort; /* packets received too short */
|
||||
uint32 tcps_rcvduppack; /* duplicate-only packets received */
|
||||
uint64 tcps_rcvdupbyte; /* duplicate-only bytes received */
|
||||
uint32 tcps_rcvpartduppack; /* packets with some duplicate data */
|
||||
uint64 tcps_rcvpartdupbyte; /* dup. bytes in part-dup. packets */
|
||||
uint32 tcps_rcvoopack; /* out-of-order packets received */
|
||||
uint64 tcps_rcvoobyte; /* out-of-order bytes received */
|
||||
uint32 tcps_rcvpackafterwin; /* packets with data after window */
|
||||
uint64 tcps_rcvbyteafterwin; /* bytes rcvd after window */
|
||||
uint32 tcps_rcvafterclose; /* packets rcvd after "close" */
|
||||
uint32 tcps_rcvwinprobe; /* rcvd window probe packets */
|
||||
uint32 tcps_rcvdupack; /* rcvd duplicate acks */
|
||||
uint32 tcps_rcvacktoomuch; /* rcvd acks for unsent data */
|
||||
uint32 tcps_rcvackpack; /* rcvd ack packets */
|
||||
uint64 tcps_rcvackbyte; /* bytes acked by rcvd acks */
|
||||
uint32 tcps_rcvwinupd; /* rcvd window update packets */
|
||||
uint32 tcps_pawsdrop; /* segments dropped due to PAWS */
|
||||
uint32 tcps_predack; /* times hdr predict ok for acks */
|
||||
uint32 tcps_preddat; /* times hdr predict ok for data pkts */
|
||||
|
||||
uint32 tcps_pcbhashmiss; /* input packets missing pcb hash */
|
||||
uint32 tcps_noport; /* no socket on port */
|
||||
uint32 tcps_badsyn; /* SYN packet with src==dst rcv'ed */
|
||||
|
||||
uint32 tcps_rcvbadsig; /* rcvd bad/missing TCP signatures */
|
||||
uint64 tcps_rcvgoodsig; /* rcvd good TCP signatures */
|
||||
uint32 tcps_inhwcsum; /* input hardware-checksummed packets */
|
||||
uint32 tcps_outhwcsum; /* output hardware-checksummed packets */
|
||||
};
|
||||
|
||||
/*
|
||||
* Names for TCP sysctl objects.
|
||||
*/
|
||||
|
||||
#define TCPCTL_RFC1323 1 /* enable/disable RFC1323 timestamps/scaling */
|
||||
#define TCPCTL_KEEPINITTIME 2 /* TCPT_KEEP value */
|
||||
#define TCPCTL_KEEPIDLE 3 /* allow tcp_keepidle to be changed */
|
||||
#define TCPCTL_KEEPINTVL 4 /* allow tcp_keepintvl to be changed */
|
||||
#define TCPCTL_SLOWHZ 5 /* return kernel idea of PR_SLOWHZ */
|
||||
#define TCPCTL_BADDYNAMIC 6 /* return bad dynamic port bitmap */
|
||||
#define TCPCTL_RECVSPACE 7 /* receive buffer space */
|
||||
#define TCPCTL_SENDSPACE 8 /* send buffer space */
|
||||
#define TCPCTL_IDENT 9 /* get connection owner */
|
||||
#define TCPCTL_SACK 10 /* selective acknowledgement, rfc 2018 */
|
||||
#define TCPCTL_MSSDFLT 11 /* Default maximum segment size */
|
||||
#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;
|
||||
|
||||
void tcp_input(struct mbuf *, int);
|
||||
int tcp_output(struct tcpcb*);
|
||||
int tcp_mss(struct tcpcb *, uint);
|
||||
void tcp_mss_update(struct tcpcb *);
|
||||
void tcp_quench(struct inpcb *, int);
|
||||
int tcp_userreq(struct socket *, int, struct mbuf *, struct mbuf *,
|
||||
struct mbuf *);
|
||||
struct tcpcb * tcp_timers(struct tcpcb *, int);
|
||||
struct tcpcb *tcp_close(struct tcpcb *);
|
||||
void tcp_setpersist(struct tcpcb *);
|
||||
struct tcpcb *tcp_drop(struct tcpcb *, int);
|
||||
void tcp_respond(struct tcpcb *, struct tcpiphdr *, struct mbuf *,
|
||||
tcp_seq, tcp_seq, int);
|
||||
void tcp_xmit_timer(struct tcpcb *, int16);
|
||||
void tcp_dooptions(struct tcpcb *, u_char *, int, struct tcpiphdr *,
|
||||
int *, uint32 *, uint32 *);
|
||||
struct tcpiphdr *tcp_template(struct tcpcb *);
|
||||
void tcp_pulloutofband(struct socket *, struct tcpiphdr *, struct mbuf *);
|
||||
|
||||
void tcp_canceltimers(struct tcpcb *);
|
||||
void tcp_trace(int16, int16, struct tcpcb *, void *, int, int);
|
||||
|
||||
void tcp_slowtimer(void *data);
|
||||
void tcp_fasttimer(void *data);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* NETINET_TCP_VAR_H */
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 1982, 1986, 1993
|
||||
*The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
*
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
*
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef NETINET_TCPIP_H
|
||||
#define NETINET_TCPIP_H
|
||||
|
||||
/* The TCP + IPv4 header (NB no options) */
|
||||
struct tcpiphdr {
|
||||
struct ipovly ti_i;
|
||||
struct tcphdr ti_t;
|
||||
};
|
||||
|
||||
#define ti_next ti_i.ih_next
|
||||
#define ti_prev ti_i.ih_prev
|
||||
#define ti_x1 ti_i.ih_x1
|
||||
#define ti_pr ti_i.ih_pr
|
||||
#define ti_len ti_i.ih_len
|
||||
#define ti_src ti_i.ih_src
|
||||
#define ti_dst ti_i.ih_dst
|
||||
#define ti_sport ti_t.th_sport
|
||||
#define ti_dport ti_t.th_dport
|
||||
#define ti_seq ti_t.th_seq
|
||||
#define ti_ack ti_t.th_ack
|
||||
#define ti_x2 ti_t.th_x2
|
||||
#define ti_off ti_t.th_off
|
||||
#define ti_flags ti_t.th_flags
|
||||
#define ti_win ti_t.th_win
|
||||
#define ti_sum ti_t.th_sum
|
||||
#define ti_urp ti_t.th_urp
|
||||
|
||||
#define REASS_MBUF(ti) (*(struct mbuf **)&((ti)->ti_t))
|
||||
|
||||
#endif /* NETINET_TCPIP_H */
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 1982, 1986, 1993
|
||||
*The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
*
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
*
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*@(#)udp.h8.1 (Berkeley) 6/10/93
|
||||
*/
|
||||
|
||||
#ifndef NETINET_UDP_H
|
||||
#define NETINET_UDP_H
|
||||
|
||||
struct udphdr {
|
||||
uint16 uh_sport;
|
||||
uint16 uh_dport;
|
||||
uint16 uh_ulen;
|
||||
uint16 uh_sum;
|
||||
};
|
||||
|
||||
#endif /* NETINET_UDP_H */
|
||||
@@ -0,0 +1,51 @@
|
||||
/* udp_var.h */
|
||||
|
||||
#ifndef UDP_VAR_H
|
||||
#define UDP_VAR_H
|
||||
|
||||
#include "netinet/ip_var.h"
|
||||
|
||||
struct udpiphdr {
|
||||
struct ipovly ui_i;
|
||||
struct udphdr ui_u;
|
||||
};
|
||||
#define ui_next ui_i.ih_next
|
||||
#define ui_prev ui_i.ih_prev
|
||||
#define ui_x1 ui_i.ih_x1 /* NB _x1 (one) */
|
||||
#define ui_pr ui_i.ih_pr
|
||||
#define ui_len ui_i.ih_len
|
||||
#define ui_src ui_i.ih_src
|
||||
#define ui_dst ui_i.ih_dst
|
||||
#define ui_sport ui_u.uh_sport
|
||||
#define ui_dport ui_u.uh_dport
|
||||
#define ui_ulen ui_u.uh_ulen
|
||||
#define ui_sum ui_u.uh_sum
|
||||
|
||||
struct udpstat {
|
||||
/* input statistics: */
|
||||
uint32 udps_ipackets; /* total input packets */
|
||||
uint32 udps_hdrops; /* packet shorter than header */
|
||||
uint32 udps_badsum; /* checksum error */
|
||||
uint32 udps_nosum; /* no checksum */
|
||||
uint32 udps_badlen; /* data length larger than packet */
|
||||
uint32 udps_noport; /* no socket on port */
|
||||
uint32 udps_noportbcast; /* of above, arrived as broadcast */
|
||||
uint32 udps_nosec; /* dropped for lack of ipsec */
|
||||
uint32 udps_fullsock; /* not delivered, input socket full */
|
||||
uint32 udps_pcbhashmiss; /* input packets missing pcb hash */
|
||||
uint32 udps_inhwcsum; /* input hardware-csummed packets */
|
||||
/* output statistics: */
|
||||
uint32 udps_opackets; /* total output packets */
|
||||
uint32 udps_outhwcsum; /* output hardware-csummed packets */
|
||||
};
|
||||
|
||||
/*
|
||||
* Names for UDP sysctl objects
|
||||
*/
|
||||
#define UDPCTL_CHECKSUM 1 /* checksum UDP packets */
|
||||
#define UDPCTL_BADDYNAMIC 2 /* return bad dynamic port bitmap */
|
||||
#define UDPCTL_RECVSPACE 3 /* receive buffer space */
|
||||
#define UDPCTL_SENDSPACE 4 /* send buffer space */
|
||||
#define UDPCTL_MAXID 5
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,40 @@
|
||||
/* 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 */
|
||||
@@ -0,0 +1,24 @@
|
||||
/* poll.h
|
||||
*
|
||||
* poll is an alternative way to deal with system notification
|
||||
* of events on sockets
|
||||
*/
|
||||
|
||||
#ifndef __POLL_H
|
||||
#define __POLL_H
|
||||
|
||||
#define POLLIN 0x0001
|
||||
#define POLLPRI 0x0002 /* not used */
|
||||
#define POLLOUT 0x0004
|
||||
#define POLLERR 0x0008
|
||||
|
||||
struct pollfd {
|
||||
int fd;
|
||||
int events; /* events to look for */
|
||||
int revents; /* events that occured */
|
||||
};
|
||||
|
||||
extern int poll(struct pollfd * p, int nb, int timeout);
|
||||
|
||||
#endif /* __POLL_H */
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/* pools.h
|
||||
* simple fixed size block allocator
|
||||
*/
|
||||
|
||||
#ifndef OBOS_POOLS_H
|
||||
#define OBOS_POOLS_H
|
||||
|
||||
|
||||
#include <kernel/OS.h>
|
||||
|
||||
#include "lock.h"
|
||||
|
||||
|
||||
typedef struct pool_ctl pool_ctl;
|
||||
|
||||
struct pool_mem {
|
||||
struct pool_mem *next;
|
||||
area_id aid;
|
||||
char *base_addr;
|
||||
size_t mem_size;
|
||||
char *ptr;
|
||||
size_t avail;
|
||||
benaphore lock;
|
||||
};
|
||||
|
||||
struct free_blk {
|
||||
char *next;
|
||||
};
|
||||
|
||||
#define POOL_USES_BENAPHORES 0
|
||||
#define POOL_DEBUG_NAME_SZ 32
|
||||
|
||||
struct pool_ctl {
|
||||
struct pool_mem *list;
|
||||
char *freelist;
|
||||
size_t alloc_size;
|
||||
size_t block_size;
|
||||
#if POOL_USES_BENAPHORES
|
||||
benaphore lock;
|
||||
#else
|
||||
rw_lock lock;
|
||||
#endif
|
||||
int debug;
|
||||
char name[POOL_DEBUG_NAME_SZ];
|
||||
};
|
||||
|
||||
status_t pool_init(pool_ctl **p, size_t sz);
|
||||
char *pool_get(pool_ctl *p);
|
||||
void pool_put(pool_ctl *p, void *ptr);
|
||||
void pool_destroy(pool_ctl *p);
|
||||
void pool_debug(struct pool_ctl *p, char *name);
|
||||
|
||||
void pool_debug_walk(pool_ctl *p);
|
||||
|
||||
#endif /* OBOS_POOLS_H */
|
||||
@@ -0,0 +1,48 @@
|
||||
/* protocols.h
|
||||
* The various protocols we're likely to come across as
|
||||
* they're identified in the type fields of packets...
|
||||
*/
|
||||
|
||||
#include "netinet/in.h"
|
||||
|
||||
#ifndef OBOS_PROTOCOLS_H
|
||||
#define OBOS_PROTOCOLS_H
|
||||
|
||||
/* define some protocol numbers unique to ethernet */
|
||||
enum {
|
||||
ETHER_IPV4 = 0x0800,
|
||||
ETHER_ARP = 0x0806,
|
||||
ETHER_RARP = 0x8035,
|
||||
ETHER_ATALK = 0x809b, /* Appletalk */
|
||||
ETHER_SNMP = 0x814c, /* SNMP */
|
||||
ETHER_IPV6 = 0x86dd, /* IPv6 */
|
||||
ETHER_PPPOE_DISC = 0x8863, /* PPPoE Discovery */
|
||||
ETHER_PPPOE_SESS = 0x8864 /* PPPoE Session */
|
||||
};
|
||||
|
||||
/* these are used when assigning slots in the protocol table, so they
|
||||
* should tie in with IP numbers wherever possible, with other
|
||||
* protocols fitting in.
|
||||
* These are used in the module definitions.
|
||||
*/
|
||||
enum {
|
||||
NS_IPV4 = IPPROTO_IP,
|
||||
NS_ICMP = IPPROTO_ICMP,
|
||||
NS_IGMP = IPPROTO_IGMP,
|
||||
NS_TCP = IPPROTO_TCP,
|
||||
NS_UDP = IPPROTO_UDP,
|
||||
NS_ETHER=200,
|
||||
NS_IPV6,
|
||||
NS_ATALK,
|
||||
NS_ARP,
|
||||
NS_RARP,
|
||||
NS_PPPOE,
|
||||
NS_SERIAL,
|
||||
NS_LOOP,
|
||||
NS_SOCKET,
|
||||
NS_ROUTE
|
||||
};
|
||||
|
||||
|
||||
#endif /* OBOS_PROTOCOLS_H */
|
||||
|
||||
@@ -0,0 +1,349 @@
|
||||
/* $OpenBSD: resolv.h,v 1.7 2001/07/31 22:02:18 jakob Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* ++Copyright++ 1983, 1987, 1989, 1993
|
||||
* -
|
||||
* Copyright (c) 1983, 1987, 1989, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* -
|
||||
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies, and that
|
||||
* the name of Digital Equipment Corporation not be used in advertising or
|
||||
* publicity pertaining to distribution of the document or software without
|
||||
* specific, written prior permission.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
|
||||
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
|
||||
* CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||
* SOFTWARE.
|
||||
* -
|
||||
* --Copyright--
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)resolv.h 8.1 (Berkeley) 6/2/93
|
||||
* $From: resolv.h,v 8.17 1996/11/26 10:11:20 vixie Exp $
|
||||
*/
|
||||
|
||||
#ifndef _RESOLV_H_
|
||||
#define _RESOLV_H_
|
||||
|
||||
#include <kernel/OS.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include "sys/socket.h"
|
||||
#include <stdio.h>
|
||||
|
||||
/*
|
||||
* Revision information. This is the release date in YYYYMMDD format.
|
||||
* It can change every day so the right thing to do with it is use it
|
||||
* in preprocessor commands such as "#if (__RES > 19931104)". Do not
|
||||
* compare for equality; rather, use it to determine whether your resolver
|
||||
* is new enough to contain a certain feature.
|
||||
*/
|
||||
|
||||
#define __RES 19960801
|
||||
|
||||
/*
|
||||
* Resolver configuration file.
|
||||
* Normally not present, but may contain the address of the
|
||||
* initial name server(s) to query and the domain search list.
|
||||
*/
|
||||
|
||||
#ifndef _PATH_RESCONF
|
||||
#define _PATH_RESCONF "/etc/resolv.conf"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Global defines and variables for resolver stub.
|
||||
*/
|
||||
#define MAXNS 3 /* max # name servers we'll track */
|
||||
#define MAXDFLSRCH 3 /* # default domain levels to try */
|
||||
#define MAXDNSRCH 6 /* max # domains in search path */
|
||||
#define LOCALDOMAINPARTS 2 /* min levels in name that is "local" */
|
||||
#define MAXDNSLUS 4 /* max # of host lookup types */
|
||||
|
||||
#define RES_TIMEOUT 5 /* min. seconds between retries */
|
||||
#define MAXRESOLVSORT 10 /* number of net to sort on */
|
||||
#define RES_MAXNDOTS 15 /* should reflect bit field size */
|
||||
|
||||
struct __res_state {
|
||||
int retrans; /* retransmition time interval */
|
||||
int retry; /* number of times to retransmit */
|
||||
u_long options; /* option flags - see below. */
|
||||
int nscount; /* number of name servers */
|
||||
struct sockaddr_in
|
||||
nsaddr_list[MAXNS]; /* address of name server */
|
||||
#define nsaddr nsaddr_list[0] /* for backward compatibility */
|
||||
u_short id; /* current message id */
|
||||
char *dnsrch[MAXDNSRCH+1]; /* components of domain to search */
|
||||
char defdname[256]; /* default domain (deprecated) */
|
||||
u_long pfcode; /* RES_PRF_ flags - see below. */
|
||||
unsigned ndots:4; /* threshold for initial abs. query */
|
||||
unsigned nsort:4; /* number of elements in sort_list[] */
|
||||
char unused[3];
|
||||
struct {
|
||||
struct in_addr addr;
|
||||
uint32 mask;
|
||||
} sort_list[MAXRESOLVSORT];
|
||||
char lookups[MAXDNSLUS];
|
||||
char pad[68]; /* on an i386 this means 512b total */
|
||||
};
|
||||
|
||||
#ifdef INET6
|
||||
/*
|
||||
* replacement of __res_state, separated to keep binary compatibility.
|
||||
*/
|
||||
struct __res_state_ext {
|
||||
struct sockaddr_storage nsaddr_list[MAXNS];
|
||||
struct {
|
||||
int af; /* address family for addr, mask */
|
||||
union {
|
||||
struct in_addr ina;
|
||||
struct in6_addr in6a;
|
||||
} addr, mask;
|
||||
} sort_list[MAXRESOLVSORT];
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Resolver options (keep these in synch with res_debug.c, please)
|
||||
*/
|
||||
#define RES_INIT 0x00000001 /* address initialized */
|
||||
#define RES_DEBUG 0x00000002 /* print debug messages */
|
||||
#define RES_AAONLY 0x00000004 /* authoritative answers only (!IMPL)*/
|
||||
#define RES_USEVC 0x00000008 /* use virtual circuit */
|
||||
#define RES_PRIMARY 0x00000010 /* query primary server only (!IMPL) */
|
||||
#define RES_IGNTC 0x00000020 /* ignore trucation errors */
|
||||
#define RES_RECURSE 0x00000040 /* recursion desired */
|
||||
#define RES_DEFNAMES 0x00000080 /* use default domain name */
|
||||
#define RES_STAYOPEN 0x00000100 /* Keep TCP socket open */
|
||||
#define RES_DNSRCH 0x00000200 /* search up local domain tree */
|
||||
#define RES_INSECURE1 0x00000400 /* type 1 security disabled */
|
||||
#define RES_INSECURE2 0x00000800 /* type 2 security disabled */
|
||||
#define RES_NOALIASES 0x00001000 /* shuts off HOSTALIASES feature */
|
||||
#define RES_USE_INET6 0x00002000 /* use/map IPv6 in gethostbyname() */
|
||||
/* KAME extensions: use higher bit to avoid conflict with ISC use */
|
||||
#define RES_USE_EDNS0 0x40000000 /* use EDNS0 */
|
||||
/* DNSSEC extensions: use higher bit to avoid conflict with ISC use */
|
||||
#define RES_USE_DNSSEC 0x20000000 /* use DNSSEC using OK bit in OPT */
|
||||
|
||||
#define RES_DEFAULT (RES_RECURSE | RES_DEFNAMES | RES_DNSRCH)
|
||||
|
||||
/*
|
||||
* Resolver "pfcode" values. Used by dig.
|
||||
*/
|
||||
#define RES_PRF_STATS 0x00000001
|
||||
/* 0x00000002 */
|
||||
#define RES_PRF_CLASS 0x00000004
|
||||
#define RES_PRF_CMD 0x00000008
|
||||
#define RES_PRF_QUES 0x00000010
|
||||
#define RES_PRF_ANS 0x00000020
|
||||
#define RES_PRF_AUTH 0x00000040
|
||||
#define RES_PRF_ADD 0x00000080
|
||||
#define RES_PRF_HEAD1 0x00000100
|
||||
#define RES_PRF_HEAD2 0x00000200
|
||||
#define RES_PRF_TTLID 0x00000400
|
||||
#define RES_PRF_HEADX 0x00000800
|
||||
#define RES_PRF_QUERY 0x00001000
|
||||
#define RES_PRF_REPLY 0x00002000
|
||||
#define RES_PRF_INIT 0x00004000
|
||||
/* 0x00008000 */
|
||||
|
||||
/* hooks are still experimental as of 4.9.2 */
|
||||
typedef enum { res_goahead, res_nextns, res_modified, res_done, res_error }
|
||||
res_sendhookact;
|
||||
|
||||
typedef res_sendhookact (*res_send_qhook)(struct sockaddr_in * const *ns,
|
||||
const uchar **query,
|
||||
int *querylen,
|
||||
uchar *ans,
|
||||
int anssiz,
|
||||
int *resplen);
|
||||
|
||||
typedef res_sendhookact (*res_send_rhook)(const struct sockaddr_in *ns,
|
||||
const uchar *query,
|
||||
int querylen,
|
||||
uchar *ans,
|
||||
int anssiz,
|
||||
int *resplen);
|
||||
|
||||
struct res_sym {
|
||||
int number; /* Identifying number, like T_MX */
|
||||
char * name; /* Its symbolic name, like "MX" */
|
||||
char * humanname; /* Its fun name, like "mail exchanger" */
|
||||
};
|
||||
|
||||
extern struct __res_state _res;
|
||||
#ifdef INET6
|
||||
extern struct __res_state_ext _res_ext;
|
||||
#endif
|
||||
extern const struct res_sym __p_class_syms[];
|
||||
extern const struct res_sym __p_type_syms[];
|
||||
|
||||
/* Private routines shared between libc/net, named, nslookup and others. */
|
||||
#define res_hnok __res_hnok
|
||||
#define res_ownok __res_ownok
|
||||
#define res_mailok __res_mailok
|
||||
#define res_dnok __res_dnok
|
||||
#define sym_ston __sym_ston
|
||||
#define sym_ntos __sym_ntos
|
||||
#define sym_ntop __sym_ntop
|
||||
#define b64_ntop __b64_ntop
|
||||
#define b64_pton __b64_pton
|
||||
#define loc_ntoa __loc_ntoa
|
||||
#define loc_aton __loc_aton
|
||||
#define dn_skipname __dn_skipname
|
||||
#define fp_resstat __fp_resstat
|
||||
#define fp_query __fp_query
|
||||
#define fp_nquery __fp_nquery
|
||||
#define hostalias __hostalias
|
||||
#define putlong __putlong
|
||||
#define putshort __putshort
|
||||
#define p_class __p_class
|
||||
#define p_time __p_time
|
||||
#define p_type __p_type
|
||||
#define p_query __p_query
|
||||
#define p_cdnname __p_cdnname
|
||||
#define p_cdname __p_cdname
|
||||
#define p_fqnname __p_fqnname
|
||||
#define p_fqname __p_fqname
|
||||
#define p_rr __p_rr
|
||||
#define p_option __p_option
|
||||
#define p_secstodate __p_secstodate
|
||||
#define dn_count_labels __dn_count_labels
|
||||
#define dn_comp __dn_comp
|
||||
#define res_randomid __res_randomid
|
||||
#define res_send __res_send
|
||||
#define res_isourserver __res_isourserver
|
||||
#define res_nameinquery __res_nameinquery
|
||||
#define res_queriesmatch __res_queriesmatch
|
||||
#define res_close __res_close
|
||||
#define res_opt __res_opt
|
||||
|
||||
#ifdef BIND_RES_POSIX3
|
||||
#define dn_expand __dn_expand
|
||||
#define res_init __res_init
|
||||
#define res_query __res_query
|
||||
#define res_search __res_search
|
||||
#define res_querydomain __res_querydomain
|
||||
#define res_mkquery __res_mkquery
|
||||
#endif
|
||||
|
||||
int res_hnok (const char *);
|
||||
int res_ownok (const char *);
|
||||
int res_mailok (const char *);
|
||||
int res_dnok (const char *);
|
||||
int sym_ston (const struct res_sym *, char *, int *);
|
||||
const char * sym_ntos (const struct res_sym *, int, int *);
|
||||
const char * sym_ntop (const struct res_sym *, int, int *);
|
||||
int b64_ntop (uchar const *, size_t, char *, size_t);
|
||||
int b64_pton (char const *, uchar *, size_t);
|
||||
int loc_aton (const char *, uchar *);
|
||||
const char * loc_ntoa (const uchar *, char *);
|
||||
int dn_skipname (const uchar *, const uchar *);
|
||||
void fp_resstat (struct __res_state *, FILE *);
|
||||
void fp_query (const uchar *, FILE *);
|
||||
void fp_nquery (const uchar *, int, FILE *);
|
||||
const char * hostalias (const char *);
|
||||
void putlong (uint32, uchar *);
|
||||
void putshort (uint16, uchar *);
|
||||
const char * p_class (int);
|
||||
const char * p_time (uint32);
|
||||
const char * p_type (int);
|
||||
void p_query (const uchar *);
|
||||
const uchar * p_cdnname (const uchar *, const uchar *, int, FILE *);
|
||||
const uchar * p_cdname (const uchar *, const uchar *, FILE *);
|
||||
const uchar * p_fqnname (const uchar *cp, const uchar *msg,
|
||||
int, char *, int);
|
||||
const uchar * p_fqname (const uchar *, const uchar *, FILE *);
|
||||
const uchar * p_rr (const uchar *, const uchar *, FILE *);
|
||||
const char * p_option (u_long option);
|
||||
char * p_secstodate (u_long);
|
||||
int dn_count_labels (char *);
|
||||
int dn_comp (const char *, uchar *, int,
|
||||
uchar **, uchar **);
|
||||
int dn_expand (const uchar *, const uchar *, const uchar *,
|
||||
char *, int);
|
||||
int res_init (void);
|
||||
uint res_randomid (void);
|
||||
int res_query (const char *, int, int, uchar *, int);
|
||||
int res_search (const char *, int, int, uchar *, int);
|
||||
int res_querydomain (const char *, const char *, int, int,
|
||||
uchar *, int);
|
||||
int res_mkquery (int, const char *, int, int, const uchar *, int,
|
||||
const uchar *, uchar *, int);
|
||||
int res_send (const uchar *, int, uchar *, int);
|
||||
int res_isourserver (const struct sockaddr_in *);
|
||||
int res_nameinquery (const char *, int, int,
|
||||
const uchar *, const uchar *);
|
||||
int res_queriesmatch (const uchar *, const uchar *,
|
||||
const uchar *, const uchar *);
|
||||
void res_close (void);
|
||||
|
||||
#endif /* !_RESOLV_H_ */
|
||||
@@ -0,0 +1,26 @@
|
||||
/* domain.h */
|
||||
|
||||
/* A domain is just a container for like minded protocols! */
|
||||
|
||||
#ifndef DOMAIN_H
|
||||
#define DOMAIN_H
|
||||
|
||||
struct domain {
|
||||
int dom_family; /* AF_INET and so on */
|
||||
char *dom_name;
|
||||
|
||||
void (*dom_init)(void); /* initialise */
|
||||
|
||||
struct protosw *dom_protosw; /* the protocols we have */
|
||||
struct domain *dom_next;
|
||||
|
||||
int (*dom_rtattach)(void **, int);
|
||||
int dom_rtoffset;
|
||||
int dom_maxrtkey;
|
||||
};
|
||||
|
||||
struct domain *domains;
|
||||
void add_domain(struct domain *dom, int fam);
|
||||
void remove_domain(int fam);
|
||||
|
||||
#endif /* DOMAIN_H */
|
||||
@@ -0,0 +1,318 @@
|
||||
/* mbuf.h
|
||||
* network buffer definitions
|
||||
*
|
||||
* Based on BSD's mbuf principal.
|
||||
*/
|
||||
|
||||
#include "pools.h"
|
||||
|
||||
#ifndef OBOS_MBUF_H
|
||||
#define OBOS_MBUF_H
|
||||
|
||||
/* MBuf's are all of a single size, MSIZE bytes. If we have more data
|
||||
* than can be fitted we can add a single "MBuf cluster" which is of
|
||||
* fixed size MCLBYTES.
|
||||
* If the data to be written is larger than MCLMINBYTES bytes we won't use
|
||||
* the storage provided within the MBuf, but rather all data will go
|
||||
* directly into an added cluster.
|
||||
*/
|
||||
|
||||
#define MSIZE 256 /* total size of structure */
|
||||
#define MCLSHIFT 11
|
||||
#define MCLBYTES (1 << MCLSHIFT)
|
||||
|
||||
#define MCLMAXBYTES 2048 /* they can't be bigger than 2k */
|
||||
#define MLEN (MSIZE - sizeof(struct m_hdr)) /* data length w/o a pkt_hdr */
|
||||
#define MHLEN (MLEN - sizeof(struct pkt_hdr)) /* data length w/pkt_hdr */
|
||||
#define CLLEN (MCLBYTES - sizeof(struct cl_hdr))
|
||||
|
||||
#define MINCLSIZE (MHLEN + 1)
|
||||
|
||||
/* mbuf header structure
|
||||
* This appears at teh start of every MBuf
|
||||
*/
|
||||
struct m_hdr {
|
||||
struct mbuf *m_next; /* next mbuf in a chain */
|
||||
struct mbuf *m_nxtpkt; /* next chain in a packet/queue */
|
||||
char * m_data; /* pointer to data */
|
||||
uint32 m_len; /* length data in this mbuf NB NOT total length */
|
||||
uint16 m_type; /* what sort of data do we have ? */
|
||||
uint16 m_flags; /* flags as defined below */
|
||||
uint16 m_cksum; /* flags about the checksum on the packet */
|
||||
};
|
||||
|
||||
/* pkt_hdr
|
||||
* This is ONLY found in the first MBuf in a chain and is valid
|
||||
* ONLY if we have the M_PKTHDR flag is set
|
||||
*/
|
||||
/* XXX - we also need to record things like the interface and also maintain
|
||||
* a list of the packets associated with this message here.
|
||||
*/
|
||||
struct pkt_hdr {
|
||||
struct ifnet *rcvif; /* interface we came it on */
|
||||
int len; /* total length */
|
||||
int csum; /* hardware cksum info... */
|
||||
};
|
||||
|
||||
/* m_ext
|
||||
* External storage, i.e. a cluster
|
||||
*/
|
||||
struct m_ext {
|
||||
char *ext_buf; /* start of the buffer */
|
||||
// void *(ext_free)(); /* free routine (if not standard) */
|
||||
uint ext_size; /* how big is the buffer */
|
||||
};
|
||||
|
||||
/* struct mbuf
|
||||
* The actual buffer structure.
|
||||
* This is defined as unions as the size is slightly variable
|
||||
* depending on the options set.
|
||||
*/
|
||||
|
||||
struct mbuf {
|
||||
struct m_hdr m_hdr;
|
||||
union {
|
||||
struct {
|
||||
struct pkt_hdr MH_pkthdr;
|
||||
union {
|
||||
struct m_ext MH_ext;
|
||||
char MH_databuf[MHLEN];
|
||||
} MH_dat;
|
||||
} MH;
|
||||
char m_databuf[MLEN];
|
||||
} um_dat;
|
||||
};
|
||||
|
||||
/* these are simply shortcuts... */
|
||||
#define m_next m_hdr.m_next
|
||||
#define m_len m_hdr.m_len
|
||||
#define m_data m_hdr.m_data
|
||||
#define m_type m_hdr.m_type
|
||||
#define m_flags m_hdr.m_flags
|
||||
#define m_cksum m_hdr.m_cksum
|
||||
#define m_nextpkt m_hdr.m_nxtpkt
|
||||
#define m_ext um_dat.MH.MH_dat.MH_ext
|
||||
#define m_pktdat um_dat.MH.MH_dat.MH_databuf
|
||||
#define m_pkthdr um_dat.MH.MH_pkthdr
|
||||
#define m_dat um_dat.m_databuf
|
||||
|
||||
/* define a little macro that gives us the data pointer for an mbuf */
|
||||
#define mtod(m, t) ((t)((m)->m_data))
|
||||
#define dtom(x) ((struct mbuf *)((int)(x) & ~(MSIZE-1)))
|
||||
|
||||
/* mbuf flags */
|
||||
enum {
|
||||
M_EXT = 0x0001, /* has extenal storage attached */
|
||||
M_PKTHDR = 0x0002, /* contains the packet header */
|
||||
M_EOR = 0x0004, /* end of record (not used for tcp/udp) */
|
||||
M_CLUSTER = 0x0008, /* external storage is a cluster */
|
||||
/*
|
||||
M_PROTO = 0x0010, * protocol specific *
|
||||
*/
|
||||
M_BCAST = 0x0100, /* rx/tx as a link-level broadcast */
|
||||
M_MCAST = 0x0200, /* rx/tx as a link-level multicast */
|
||||
M_CONF = 0x0400, /* packet was encrypted?? */
|
||||
M_AUTH = 0x0800, /* packet was authenticated */
|
||||
M_COMP = 0x1000, /* packet was compressed */
|
||||
M_ANYCAST6 = 0x4000 /* it was an IPv6 anycast packet */
|
||||
};
|
||||
/* the M_COPYFLAGS lists the flags that can be copied when we copy
|
||||
* an mbuf with the M_PKTHDR flag set */
|
||||
#define M_COPYFLAGS (M_PKTHDR | M_EOR | M_BCAST | M_MCAST)
|
||||
|
||||
/* checksum flags */
|
||||
enum {
|
||||
M_IPV4_CSUM_OUT = 0x0001, /* ipv4 checksum required */
|
||||
M_TCPV4_CSUM_OUT = 0x0002, /* TCP v4 checksum required */
|
||||
M_UDPV4_CSUM_OUT = 0x0004,
|
||||
|
||||
M_IPV4_CSUM_IN_OK = 0x0008,
|
||||
M_IPV4_CSUM_IN_OUT = 0x0010,
|
||||
|
||||
M_TCP_CSUM_IN_OK = 0x0020,
|
||||
M_TCP_CSUM_IN_BAD = 0x0040,
|
||||
|
||||
M_UDP_CSUM_IN_OK = 0x0080,
|
||||
M_UDP_CSUM_IN_BAD = 0x0100
|
||||
};
|
||||
|
||||
/* MBuf types */
|
||||
enum {
|
||||
MT_FREE = 0, /* should be on free list */
|
||||
MT_DATA = 1, /* dynamic data allocation */
|
||||
MT_HEADER = 2, /* packet header */
|
||||
MT_SONAME = 3,
|
||||
MT_SOOPTS = 4,
|
||||
MT_FTABLE = 5, /* fragment reassembly header */
|
||||
MT_CONTROL = 6, /* extra-data protocol message */
|
||||
MT_OOBDATA = 7 /* out-of-band data */
|
||||
};
|
||||
|
||||
/* length to m_copy to copy all */
|
||||
#define M_COPYALL 1000000000
|
||||
|
||||
/* now some macro's to make life easier... */
|
||||
|
||||
/* need to add the macro's here :) */
|
||||
|
||||
#define MRESETDATA(m) do { \
|
||||
if ((m)->m_flags & M_EXT) \
|
||||
(m)->m_data = (m)->m_ext.ext_buf; \
|
||||
else if ((m)->m_flags & M_PKTHDR) \
|
||||
(m)->m_data = (m)->m_pktdat; \
|
||||
else \
|
||||
(m)->m_data = (m)->dat; \
|
||||
} while (0)
|
||||
|
||||
/* fill in an mbuf */
|
||||
#define MGET(n, type) \
|
||||
n = (struct mbuf*) pool_get(mbpool); \
|
||||
if (n) { \
|
||||
(n)->m_type = (type); \
|
||||
(n)->m_next = NULL; \
|
||||
(n)->m_nextpkt = NULL; \
|
||||
(n)->m_data = (n)->m_dat; \
|
||||
(n)->m_flags = 0; \
|
||||
(n)->m_cksum = 0; \
|
||||
}
|
||||
|
||||
#define MGETHDR(n, type) \
|
||||
n = (struct mbuf*) pool_get(mbpool); \
|
||||
if (n) { \
|
||||
(n)->m_type = (type); \
|
||||
(n)->m_next = NULL; \
|
||||
(n)->m_nextpkt = NULL; \
|
||||
(n)->m_data = (n)->m_pktdat; \
|
||||
(n)->m_flags = M_PKTHDR; \
|
||||
(n)->m_cksum = 0; \
|
||||
}
|
||||
|
||||
#define _MEXTREMOVE(m) do { \
|
||||
if ((m)->m_flags & M_CLUSTER) { \
|
||||
pool_put(clpool, (m)->m_ext.ext_buf); \
|
||||
} \
|
||||
(m)->m_flags &= ~(M_CLUSTER|M_EXT); \
|
||||
(m)->m_ext.ext_size = 0; \
|
||||
} while (0)
|
||||
|
||||
#define MFREE(m, n) \
|
||||
if ((m)->m_flags & M_EXT) { \
|
||||
_MEXTREMOVE(m); \
|
||||
} \
|
||||
(n) = (m)->m_next; \
|
||||
pool_put(mbpool, m);
|
||||
|
||||
/* set the data pointer to place an object of size len at the end
|
||||
* of the mbuf, aligned to long word (16 bits)
|
||||
*/
|
||||
#define M_ALIGN(m, len) \
|
||||
{ (m)->m_data += (MLEN - (len)) &~ (sizeof(int16) -1);}
|
||||
|
||||
#define MH_ALIGN(m, len) \
|
||||
{ (m)->m_data += (MHLEN - (len)) &~ (sizeof(int16) -1);}
|
||||
|
||||
#define M_MOVE_HDR(to, from) { \
|
||||
(to)->m_pkthdr = (from)->m_pkthdr; \
|
||||
(from)->m_flags &= ~M_PKTHDR; \
|
||||
}
|
||||
|
||||
#define M_MOVE_PKTHDR(to, from) { \
|
||||
(to)->m_flags = (from)->m_flags & M_COPYFLAGS; \
|
||||
M_MOVE_HDR((to), (from)); \
|
||||
(to)->m_data = (to)->m_pktdat; \
|
||||
}
|
||||
|
||||
#define MCLGET(m) do { \
|
||||
(m)->m_ext.ext_buf = pool_get(clpool); \
|
||||
if ((m)->m_ext.ext_buf != NULL) { \
|
||||
(m)->m_data = (m)->m_ext.ext_buf; \
|
||||
(m)->m_flags |= M_EXT|M_CLUSTER; \
|
||||
(m)->m_ext.ext_size = MCLBYTES; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define M_LEADINGSPACE(m) \
|
||||
((m)->m_flags & M_EXT ? (m)->m_data - (m)->m_ext.ext_buf : \
|
||||
(m)->m_flags & M_PKTHDR ? (m)->m_data - (m)->m_pktdat : \
|
||||
(m)->m_data - (m)->m_dat)
|
||||
|
||||
#define M_PREPEND(m, plen) { \
|
||||
if (M_LEADINGSPACE(m) >= (plen)) { \
|
||||
(m)->m_data -= (plen); \
|
||||
(m)->m_len += (plen); \
|
||||
} else \
|
||||
(m) = m_prepend((m), (plen)); \
|
||||
if ((m) && (m)->m_flags & M_PKTHDR) \
|
||||
(m)->m_pkthdr.len += (plen); \
|
||||
}
|
||||
|
||||
/*
|
||||
* Duplicate just m_pkthdr from from to to.
|
||||
*/
|
||||
#define M_DUP_HDR(to, from) { \
|
||||
(to)->m_pkthdr = (from)->m_pkthdr; \
|
||||
}
|
||||
|
||||
/*
|
||||
* Duplicate mbuf pkthdr from from to to.
|
||||
* from must have M_PKTHDR set, and to must be empty.
|
||||
*/
|
||||
#define M_DUP_PKTHDR(to, from) { \
|
||||
(to)->m_flags = (from)->m_flags & M_COPYFLAGS; \
|
||||
M_DUP_HDR((to), (from)); \
|
||||
(to)->m_data = (to)->m_pktdat; \
|
||||
}
|
||||
|
||||
#define M_TRAILINGSPACE(m) \
|
||||
((m)->m_flags & M_EXT ? (m)->m_ext.ext_buf + (m)->m_ext.ext_size - \
|
||||
((m)->m_data + (m)->m_len) : \
|
||||
&(m)->m_dat[MLEN] - ((m)->m_data + (m)->m_len))
|
||||
|
||||
#define M_IS_CLUSTER(m) ((m)->m_flags & M_EXT)
|
||||
|
||||
#define M_DATASTART(m) \
|
||||
(M_IS_CLUSTER(m) ? (m)->m_ext.ext_buf : \
|
||||
(m)->m_flags & M_PKTHDR ? (m)->m_pktdat : (m)->m_dat)
|
||||
|
||||
#define M_DATASIZE(m) \
|
||||
(M_IS_CLUSTER(m) ? (m)->m_ext.ext_size : \
|
||||
(m)->m_flags & M_PKTHDR ? MHLEN: MLEN)
|
||||
|
||||
/* Functions! */
|
||||
void mbinit(void);
|
||||
struct mbuf *m_get(int type);
|
||||
|
||||
struct mbuf *m_gethdr(int type);
|
||||
struct mbuf *m_getclr(int type);
|
||||
|
||||
struct mbuf *m_prepend(struct mbuf *m, int len);
|
||||
struct mbuf *m_devget(char *buf, int totlen, int off0,
|
||||
struct ifnet *ifp,
|
||||
void (*copy)(const void *, void *, size_t));
|
||||
struct mbuf *m_pullup(struct mbuf *, int len);
|
||||
void m_copyback(struct mbuf *m0, int off, int len, caddr_t cp);
|
||||
|
||||
struct mbuf *m_free(struct mbuf *mfree);
|
||||
void m_freem(struct mbuf *m);
|
||||
|
||||
void m_reserve(struct mbuf *mp, int len);
|
||||
void m_cat(struct mbuf *m, struct mbuf *n);
|
||||
void m_adj(struct mbuf *mp, int req_len);
|
||||
void m_copydata(struct mbuf *m, int off, int len, caddr_t cp);
|
||||
struct mbuf *m_copym(struct mbuf *m, int off0, int len);
|
||||
|
||||
/* debug functions */
|
||||
void dump_freelist(void);
|
||||
|
||||
/* Stats structure */
|
||||
/* XXX - add me! */
|
||||
|
||||
|
||||
struct pool_ctl *mbpool;
|
||||
struct pool_ctl *clpool;
|
||||
|
||||
int max_hdr; /* largest link+protocol header */
|
||||
int max_linkhdr; /* largest link level header */
|
||||
int max_protohdr; /* largest protocol header */
|
||||
|
||||
#endif /* OBOS_MBUF_H */
|
||||
@@ -0,0 +1,26 @@
|
||||
/* uio.h */
|
||||
|
||||
#ifndef NET_SYS_UIO_H
|
||||
#define NET_SYS_UIO_H
|
||||
|
||||
enum uio_rw { UIO_READ, UIO_WRITE };
|
||||
|
||||
/* Segment flag values. */
|
||||
enum uio_seg {
|
||||
UIO_USERSPACE, /* from user data space */
|
||||
UIO_SYSSPACE /* from system space */
|
||||
};
|
||||
|
||||
struct uio {
|
||||
struct iovec *uio_iov; /* pointer to array of iovecs */
|
||||
int uio_iovcnt; /* number of iovecs in array */
|
||||
off_t uio_offset; /* offset into file this uio corresponds to */
|
||||
size_t uio_resid; /* residual i/o count */
|
||||
enum uio_seg uio_segflg; /* see above */
|
||||
enum uio_rw uio_rw; /* see above */
|
||||
// struct proc *uio_procp; /* process if UIO_USERSPACE */
|
||||
};
|
||||
|
||||
int uiomove(caddr_t cp, int n, struct uio *uio);
|
||||
|
||||
#endif /* NET_SYS_UIO_H */
|
||||
@@ -0,0 +1,147 @@
|
||||
/* protosw.h */
|
||||
|
||||
#ifndef PROTOSW_H
|
||||
#define PROTOSW_H
|
||||
|
||||
#include "sys/socketvar.h" /* for struct socket */
|
||||
#include "net/route.h"
|
||||
|
||||
#define PRCO_SETOPT 0
|
||||
#define PRCO_GETOPT 1
|
||||
|
||||
/* every protocol module init's one of these and passes it into
|
||||
* the add_protocol() function, defined below */
|
||||
/* NB The pr_domain pointer will be filled in during the
|
||||
* add_protocol() call
|
||||
*/
|
||||
struct protosw {
|
||||
char *name;
|
||||
char *mod_path;
|
||||
uint16 pr_type; /* SOCK_xxx */
|
||||
struct domain *pr_domain;
|
||||
uint16 pr_protocol; /* protocol number */
|
||||
uint16 pr_flags; /* flags, PR_xxx */
|
||||
int layer; /* which layer are we? */
|
||||
|
||||
/* the functions! */
|
||||
void (*pr_init)(void);
|
||||
void (*pr_input)(struct mbuf*, int);
|
||||
int (*pr_output)(struct mbuf *, struct mbuf *,
|
||||
struct route *,
|
||||
int, void *);
|
||||
|
||||
int (*pr_userreq)(struct socket *, int,
|
||||
struct mbuf *,
|
||||
struct mbuf *,
|
||||
struct mbuf *);
|
||||
int (*pr_sysctl)(int *, uint, void *, size_t *, void *, size_t);
|
||||
void (*pr_ctlinput)(int, struct sockaddr *, void *);
|
||||
int (*pr_ctloutput)(int, struct socket*, int, int, struct mbuf **);
|
||||
|
||||
struct protosw *pr_next; /* pointer to next proto structure */
|
||||
struct protosw *dom_next; /* next protosw pointed by the domain */
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Values for pr_flags.
|
||||
* PR_ADDR requires PR_ATOMIC;
|
||||
* PR_ADDR and PR_CONNREQUIRED are mutually exclusive.
|
||||
*/
|
||||
#define PR_ATOMIC 0x01 /* exchange atomic messages only */
|
||||
#define PR_ADDR 0x02 /* addresses given with messages */
|
||||
#define PR_CONNREQUIRED 0x04 /* connection required by protocol */
|
||||
#define PR_WANTRCVD 0x08 /* want PRU_RCVD calls */
|
||||
#define PR_RIGHTS 0x10 /* passes capabilities */
|
||||
#define PR_ABRTACPTDIS 0x20 /* abort on accept(2) to disconnected
|
||||
socket */
|
||||
|
||||
#define PR_SLOWHZ 2 /* 2 timeouts per second... */
|
||||
#define PR_FASTHZ 5 /* 5 timeouts per second */
|
||||
/*
|
||||
* Defines for the userreq function req field are below.
|
||||
*
|
||||
* (*usrreq)(up, req, m, nam, opt);
|
||||
*
|
||||
* up is a (struct socket *)
|
||||
* req is one of these requests,
|
||||
* m is a optional mbuf chain containing a message,
|
||||
* nam is an optional mbuf chain containing an address,
|
||||
* opt is a pointer to a socketopt structure or nil.
|
||||
*
|
||||
* The protocol is responsible for disposal of the mbuf chain m,
|
||||
* the caller is responsible for any space held by nam and opt.
|
||||
* A non-zero return from usrreq gives an
|
||||
* UNIX error number which should be passed to higher level software.
|
||||
*/
|
||||
#define PRU_ATTACH 0 /* attach protocol to up */
|
||||
#define PRU_DETACH 1 /* detach protocol from up */
|
||||
#define PRU_BIND 2 /* bind socket to address */
|
||||
#define PRU_LISTEN 3 /* listen for connection */
|
||||
#define PRU_CONNECT 4 /* establish connection to peer */
|
||||
#define PRU_ACCEPT 5 /* accept connection from peer */
|
||||
#define PRU_DISCONNECT 6 /* disconnect from peer */
|
||||
#define PRU_SHUTDOWN 7 /* won't send any more data */
|
||||
#define PRU_RCVD 8 /* have taken data; more room now */
|
||||
#define PRU_SEND 9 /* send this data */
|
||||
#define PRU_ABORT 10 /* abort (fast DISCONNECT, DETATCH) */
|
||||
#define PRU_CONTROL 11 /* control operations on protocol */
|
||||
#define PRU_SENSE 12 /* return status into m */
|
||||
#define PRU_RCVOOB 13 /* retrieve out of band data */
|
||||
#define PRU_SENDOOB 14 /* send out of band data */
|
||||
#define PRU_SOCKADDR 15 /* fetch socket's address */
|
||||
#define PRU_PEERADDR 16 /* fetch peer's address */
|
||||
#define PRU_CONNECT2 17 /* connect two sockets */
|
||||
/* begin for protocols internal use */
|
||||
#define PRU_FASTTIMO 18 /* 200ms timeout */
|
||||
#define PRU_SLOWTIMO 19 /* 500ms timeout */
|
||||
#define PRU_PROTORCV 20 /* receive from below */
|
||||
#define PRU_PROTOSEND 21 /* send to below */
|
||||
#define PRU_PEEREID 22 /* get local peer eid */
|
||||
|
||||
#define PRU_NREQ 22
|
||||
|
||||
/*
|
||||
* The arguments to the ctlinput routine are
|
||||
* (*protosw[].pr_ctlinput)(cmd, sa, arg);
|
||||
* where cmd is one of the commands below, sa is a pointer to a sockaddr,
|
||||
* and arg is an optional caddr_t argument used within a protocol family.
|
||||
*/
|
||||
#define PRC_IFDOWN 0 /* interface transition */
|
||||
#define PRC_ROUTEDEAD 1 /* select new route if possible ??? */
|
||||
#define PRC_MTUINC 2 /* increase in mtu to host */
|
||||
#define PRC_QUENCH2 3 /* DEC congestion bit says slow down */
|
||||
#define PRC_QUENCH 4 /* some one said to slow down */
|
||||
#define PRC_MSGSIZE 5 /* message size forced drop */
|
||||
#define PRC_HOSTDEAD 6 /* host appears to be down */
|
||||
#define PRC_HOSTUNREACH 7 /* deprecated (use PRC_UNREACH_HOST) */
|
||||
#define PRC_UNREACH_NET 8 /* no route to network */
|
||||
#define PRC_UNREACH_HOST 9 /* no route to host */
|
||||
#define PRC_UNREACH_PROTOCOL 10 /* dst says bad protocol */
|
||||
#define PRC_UNREACH_PORT 11 /* bad port # */
|
||||
/* was PRC_UNREACH_NEEDFRAG 12 (use PRC_MSGSIZE) */
|
||||
#define PRC_UNREACH_SRCFAIL 13 /* source route failed */
|
||||
#define PRC_REDIRECT_NET 14 /* net routing redirect */
|
||||
#define PRC_REDIRECT_HOST 15 /* host routing redirect */
|
||||
#define PRC_REDIRECT_TOSNET 16 /* redirect for type of service & net */
|
||||
#define PRC_REDIRECT_TOSHOST 17 /* redirect for tos & host */
|
||||
#define PRC_TIMXCEED_INTRANS 18 /* packet lifetime expired in transit */
|
||||
#define PRC_TIMXCEED_REASS 19 /* lifetime expired on reass q */
|
||||
#define PRC_PARAMPROB 20 /* header incorrect */
|
||||
|
||||
#define PRC_NCMDS 21
|
||||
|
||||
#define PRC_IS_REDIRECT(cmd) \
|
||||
((cmd) >= PRC_REDIRECT_NET && (cmd) <= PRC_REDIRECT_TOSHOST)
|
||||
|
||||
|
||||
/* Network stack defines... */
|
||||
#ifdef _NETWORK_STACK
|
||||
struct protosw *protocols;
|
||||
void add_protocol(struct protosw *pr, int fam);
|
||||
void remove_protocol(struct protosw *pr);
|
||||
#endif
|
||||
struct protosw *pffindproto(int domain, int protocol, int type);
|
||||
struct protosw *pffindtype(int domain, int type);
|
||||
|
||||
#endif /* PROTOSW_H */
|
||||
@@ -0,0 +1,50 @@
|
||||
/* select.h */
|
||||
|
||||
#ifndef _SYS_SELECT_H
|
||||
#define _SYS_SELECT_H
|
||||
|
||||
#include <sys/time.h> /* for struct timeval */
|
||||
/*
|
||||
* You can define your own FDSETSIZE if you want more bits
|
||||
*/
|
||||
|
||||
#ifndef FD_SETSIZE
|
||||
#define FD_SETSIZE 1024
|
||||
#endif /* FD_SETSIZE */
|
||||
|
||||
/* compatability with BSD */
|
||||
#define NBBY 8 /* number of bits in a byte */
|
||||
|
||||
typedef unsigned long fd_mask;
|
||||
|
||||
#ifndef howmany
|
||||
#define howmany(x, y) (((x) + ((y) - 1)) / (y))
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Compatibily only: use FD_SETSIZE instead
|
||||
*/
|
||||
#ifndef FDSETSIZE
|
||||
#define FDSETSIZE FD_SETSIZE
|
||||
#endif /* FDSETSIZE */
|
||||
|
||||
#define NFDBITS 32
|
||||
|
||||
typedef struct fd_set {
|
||||
unsigned mask[FDSETSIZE / NFDBITS];
|
||||
} fd_set;
|
||||
|
||||
#define _FDMSKNO(fd) ((fd) / NFDBITS)
|
||||
#define _FDBITNO(fd) ((fd) % NFDBITS)
|
||||
|
||||
#define FD_ZERO(setp) memset((setp)->mask, 0, sizeof((setp)->mask))
|
||||
#define FD_SET(fd, setp) ((setp)->mask[_FDMSKNO(fd)] |= (1 << (_FDBITNO(fd))))
|
||||
#define FD_CLR(fd, setp) ((setp)->mask[_FDMSKNO(fd)] &= ~(1 << (_FDBITNO(fd))))
|
||||
#define FD_ISSET(fd, setp) ((setp)->mask[_FDMSKNO(fd)] & (1 << (_FDBITNO(fd))))
|
||||
|
||||
int select(int nbits, struct fd_set *rbits,
|
||||
struct fd_set *wbits,
|
||||
struct fd_set *ebits,
|
||||
struct timeval *timeout);
|
||||
|
||||
#endif /* _SYS_SELECT_H */
|
||||
@@ -0,0 +1,216 @@
|
||||
/* sys/socket.h */
|
||||
|
||||
#ifndef OBOS_SYS_SOCKET_H
|
||||
#define OBOS_SYS_SOCKET_H
|
||||
|
||||
#include <kernel/OS.h>
|
||||
|
||||
/* shoudl bt in types.h */
|
||||
typedef uint32 socklen_t;
|
||||
|
||||
/* These are the address/protocol families we'll be using... */
|
||||
/* NB these should be added to as required... */
|
||||
|
||||
/* If we want to have Binary compatability we may need to alter these
|
||||
* to agree with the Be versions...
|
||||
*/
|
||||
#define AF_UNSPEC 0
|
||||
#define AF_LOCAL 1
|
||||
#define AF_UNIX AF_LOCAL /* for compatability */
|
||||
#define AF_INET 2
|
||||
#define AF_ROUTE 3
|
||||
#define AF_IMPLINK 4
|
||||
#define AF_LINK 18
|
||||
#define AF_IPX 23
|
||||
#define AF_INET6 24
|
||||
|
||||
#define AF_MAX 24
|
||||
|
||||
#define PF_UNSPEC AF_UNSPEC
|
||||
#define PF_INET AF_INET
|
||||
#define PF_ROUTE AF_ROUTE
|
||||
#define PF_LINK AF_LINK
|
||||
#define PF_INET6 AF_INET6
|
||||
#define PF_IPX AF_IPX
|
||||
#define PF_IMPLINK AF_IMPLINK
|
||||
|
||||
/* Types of socket we can create (eventually) */
|
||||
#define SOCK_DGRAM 10
|
||||
#define SOCK_STREAM 11
|
||||
#define SOCK_RAW 12
|
||||
#define SOCK_MISC 255
|
||||
|
||||
/*
|
||||
* Option flags per-socket.
|
||||
*/
|
||||
#define SO_DEBUG 0x0001 /* turn on debugging info recording */
|
||||
#define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
|
||||
#define SO_REUSEADDR 0x0004 /* allow local address reuse */
|
||||
#define SO_KEEPALIVE 0x0008 /* keep connections alive */
|
||||
#define SO_DONTROUTE 0x0010 /* just use interface addresses */
|
||||
#define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */
|
||||
#define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
|
||||
#define SO_LINGER 0x0080 /* linger on close if data present */
|
||||
#define SO_OOBINLINE 0x0100 /* leave received OOB data in line */
|
||||
#define SO_REUSEPORT 0x0200 /* allow local address & port reuse */
|
||||
|
||||
#define SOL_SOCKET 0xffff
|
||||
|
||||
/*
|
||||
* Additional options, not kept in so_options.
|
||||
*/
|
||||
#define SO_SNDBUF 0x1001 /* send buffer size */
|
||||
#define SO_RCVBUF 0x1002 /* receive buffer size */
|
||||
#define SO_SNDLOWAT 0x1003 /* send low-water mark */
|
||||
#define SO_RCVLOWAT 0x1004 /* receive low-water mark */
|
||||
#define SO_SNDTIMEO 0x1005 /* send timeout */
|
||||
#define SO_RCVTIMEO 0x1006 /* receive timeout */
|
||||
#define SO_ERROR 0x1007 /* get error status and clear */
|
||||
#define SO_TYPE 0x1008 /* get socket type */
|
||||
#define SO_NETPROC 0x1020 /* multiplex; network processing */
|
||||
|
||||
/*
|
||||
* These are the valid values for the "how" field used by shutdown(2).
|
||||
*/
|
||||
#define SHUT_RD 1
|
||||
#define SHUT_WR 2
|
||||
#define SHUT_RDWR 3
|
||||
|
||||
struct linger {
|
||||
int l_onoff;
|
||||
int l_linger;
|
||||
};
|
||||
|
||||
struct sockaddr {
|
||||
uint8 sa_len;
|
||||
uint8 sa_family;
|
||||
uint8 sa_data[30];
|
||||
};
|
||||
|
||||
/* this can hold ANY sockaddr we care to throw at it! */
|
||||
struct sockaddr_storage {
|
||||
uint8 ss_len; /* total length */
|
||||
uint8 ss_family; /* address family */
|
||||
uint8 __ss_pad1[6]; /* align to quad */
|
||||
uint64 __ss_pad2; /* force alignment for stupid compilers */
|
||||
uint8 __ss_pad3[240]; /* pad to a total of 256 bytes */
|
||||
};
|
||||
|
||||
struct sockproto {
|
||||
uint16 sp_family;
|
||||
uint16 sp_protocol;
|
||||
};
|
||||
|
||||
#define CTL_NET 4
|
||||
|
||||
#define CTL_NET_NAMES { \
|
||||
{ 0, 0 }, \
|
||||
{ "unix", CTLTYPE_NODE }, \
|
||||
{ "inet", CTLTYPE_NODE }, \
|
||||
{ "implink", CTLTYPE_NODE }, \
|
||||
{ "pup", CTLTYPE_NODE }, \
|
||||
{ "chaos", CTLTYPE_NODE }, \
|
||||
{ "xerox_ns", CTLTYPE_NODE }, \
|
||||
{ "iso", CTLTYPE_NODE }, \
|
||||
{ "emca", CTLTYPE_NODE }, \
|
||||
{ "datakit", CTLTYPE_NODE }, \
|
||||
{ "ccitt", CTLTYPE_NODE }, \
|
||||
{ "ibm_sna", CTLTYPE_NODE }, \
|
||||
{ "decnet", CTLTYPE_NODE }, \
|
||||
{ "dec_dli", CTLTYPE_NODE }, \
|
||||
{ "lat", CTLTYPE_NODE }, \
|
||||
{ "hylink", CTLTYPE_NODE }, \
|
||||
{ "appletalk", CTLTYPE_NODE }, \
|
||||
{ "route", CTLTYPE_NODE }, \
|
||||
{ "link_layer", CTLTYPE_NODE }, \
|
||||
{ "xtp", CTLTYPE_NODE }, \
|
||||
{ "coip", CTLTYPE_NODE }, \
|
||||
{ "cnt", CTLTYPE_NODE }, \
|
||||
{ "rtip", CTLTYPE_NODE }, \
|
||||
{ "ipx", CTLTYPE_NODE }, \
|
||||
{ "inet6", CTLTYPE_NODE }, \
|
||||
{ "pip", CTLTYPE_NODE }, \
|
||||
{ "isdn", CTLTYPE_NODE }, \
|
||||
{ "natm", CTLTYPE_NODE }, \
|
||||
{ "encap", CTLTYPE_NODE }, \
|
||||
{ "sip", CTLTYPE_NODE }, \
|
||||
{ "key", CTLTYPE_NODE }, \
|
||||
}
|
||||
|
||||
/*
|
||||
* PF_ROUTE - Routing table
|
||||
*
|
||||
* Three additional levels are defined:
|
||||
* Fourth: address family, 0 is wildcard
|
||||
* Fifth: type of info, defined below
|
||||
* Sixth: flag(s) to mask with for NET_RT_FLAGS
|
||||
*/
|
||||
#define NET_RT_DUMP 1 /* dump; may limit to a.f. */
|
||||
#define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */
|
||||
#define NET_RT_IFLIST 3 /* survey interface list */
|
||||
#define NET_RT_MAXID 4
|
||||
|
||||
#define CTL_NET_RT_NAMES { \
|
||||
{ 0, 0 }, \
|
||||
{ "dump", CTLTYPE_STRUCT }, \
|
||||
{ "flags", CTLTYPE_STRUCT }, \
|
||||
{ "iflist", CTLTYPE_STRUCT }, \
|
||||
}
|
||||
|
||||
/* Max listen queue for a socket */
|
||||
#define SOMAXCONN 5 /* defined as 128 in OpenBSD */
|
||||
|
||||
struct msghdr {
|
||||
caddr_t msg_name; /* address we're using (optional) */
|
||||
uint msg_namelen; /* length of address */
|
||||
struct iovec *msg_iov; /* scatter/gather array we'll use */
|
||||
uint msg_iovlen; /* # elements in msg_iov */
|
||||
caddr_t msg_control; /* extra data */
|
||||
uint msg_controllen; /* length of extra data */
|
||||
int msg_flags; /* flags */
|
||||
};
|
||||
|
||||
/* Defines used in msghdr structure. */
|
||||
#define MSG_OOB 0x1 /* process out-of-band data */
|
||||
#define MSG_PEEK 0x2 /* peek at incoming message */
|
||||
#define MSG_DONTROUTE 0x4 /* send without using routing tables */
|
||||
#define MSG_EOR 0x8 /* data completes record */
|
||||
#define MSG_TRUNC 0x10 /* data discarded before delivery */
|
||||
#define MSG_CTRUNC 0x20 /* control data lost before delivery */
|
||||
#define MSG_WAITALL 0x40 /* wait for full request or error */
|
||||
#define MSG_DONTWAIT 0x80 /* this message should be nonblocking */
|
||||
#define MSG_BCAST 0x100 /* this message rec'd as broadcast */
|
||||
#define MSG_MCAST 0x200 /* this message rec'd as multicast */
|
||||
|
||||
struct cmsghdr {
|
||||
uint cmsg_len;
|
||||
int cmsg_level;
|
||||
int cmsg_type;
|
||||
/* there now follows uchar[] cmsg_data */
|
||||
};
|
||||
|
||||
|
||||
/* Function declarations */
|
||||
int socket (int, int, int);
|
||||
int bind(int, const struct sockaddr *, int);
|
||||
int connect(int, const struct sockaddr *, int);
|
||||
int listen(int, int);
|
||||
int accept(int, struct sockaddr *, int *);
|
||||
int closesocket(int);
|
||||
int shutdown(int sock, int how);
|
||||
|
||||
ssize_t send(int, const void *, size_t, int);
|
||||
ssize_t recv(int, void *, size_t, int);
|
||||
ssize_t sendto(int, const void *, size_t, int, const struct sockaddr *, size_t);
|
||||
ssize_t recvfrom(int, void *, size_t, int, struct sockaddr *, size_t *);
|
||||
|
||||
int setsockopt(int, int, int, const void *, size_t);
|
||||
int getsockopt(int, int, int, void *, size_t *);
|
||||
int getpeername(int, struct sockaddr *, int *);
|
||||
int getsockname(int, struct sockaddr *, int *);
|
||||
|
||||
/* is it really part of sockets BSD API?*/
|
||||
int sysctl (int *, uint, void *, size_t *, void *, size_t);
|
||||
|
||||
#endif /* OBOS_SYS_SOCKET_H */
|
||||
|
||||
@@ -0,0 +1,236 @@
|
||||
/* socketvar.h */
|
||||
|
||||
|
||||
#ifndef SYS_SOCKETVAR_H
|
||||
#define SYS_SOCKETVAR_H
|
||||
|
||||
#include <kernel/OS.h>
|
||||
#include "sys/mbuf.h"
|
||||
#include "sys/net_uio.h"
|
||||
#include "sys/socket.h"
|
||||
|
||||
struct sockbuf {
|
||||
uint32 sb_cc; /* actual chars in buffer */
|
||||
uint32 sb_hiwat; /* max actual char count (high water mark) */
|
||||
uint32 sb_mbcnt; /* chars of mbufs used */
|
||||
uint32 sb_mbmax; /* max chars of mbufs to use */
|
||||
int32 sb_lowat; /* low water mark */
|
||||
struct mbuf *sb_mb; /* the mbuf chain */
|
||||
int16 sb_flags; /* flags, see below */
|
||||
int32 sb_timeo; /* timeout for read/write */
|
||||
sem_id sb_sleep; /* our sleep sem */
|
||||
sem_id sb_pop; /* sem to wait on... */
|
||||
};
|
||||
|
||||
#define SB_MAX (256*1024) /* default for max chars in sockbuf */
|
||||
#define SB_LOCK 0x01 /* lock on data queue */
|
||||
#define SB_WANT 0x02 /* someone is waiting to lock */
|
||||
#define SB_WAIT 0x04 /* someone is waiting for data/space */
|
||||
#define SB_SEL 0x08 /* someone is selecting */
|
||||
#define SB_ASYNC 0x10 /* ASYNC I/O, need signals */
|
||||
#define SB_NOINTR 0x40 /* operations not interruptible */
|
||||
#define SB_KNOTE 0x80 /* kernel note attached */
|
||||
#define SB_NOTIFY (SB_WAIT|SB_SEL|SB_ASYNC)
|
||||
|
||||
typedef void (*socket_event_callback)(void * socket, uint32 event, void * cookie);
|
||||
|
||||
struct socket {
|
||||
uint16 so_type; /* type of socket */
|
||||
uint16 so_options; /* socket options */
|
||||
int16 so_linger; /* dreaded linger value */
|
||||
int16 so_state; /* socket state */
|
||||
caddr_t so_pcb; /* pointer to the control block */
|
||||
sem_id so_lock; /* socket lock */
|
||||
sem_id so_timeo; /* our wait channel */
|
||||
|
||||
struct protosw *so_proto; /* pointer to protocol module */
|
||||
|
||||
struct socket *so_head;
|
||||
struct socket *so_q0;
|
||||
struct socket *so_q;
|
||||
|
||||
int16 so_q0len;
|
||||
int16 so_qlen;
|
||||
int16 so_qlimit;
|
||||
int32 so_error;
|
||||
// pid_t so_pgid;
|
||||
uint32 so_oobmark;
|
||||
|
||||
/* our send/recv buffers */
|
||||
struct sockbuf so_snd;
|
||||
struct sockbuf so_rcv;
|
||||
|
||||
// event callback
|
||||
socket_event_callback event_callback;
|
||||
void * event_callback_cookie;
|
||||
int sel_ev;
|
||||
};
|
||||
|
||||
/* Select event bit mask */
|
||||
#define SEL_READ 0x01
|
||||
#define SEL_WRITE 0x02
|
||||
#define SEL_EX 0x04
|
||||
|
||||
/*
|
||||
* Socket state bits.
|
||||
*/
|
||||
#define SS_NOFDREF 0x001 /* no file table ref any more */
|
||||
#define SS_ISCONNECTED 0x002 /* socket connected to a peer */
|
||||
#define SS_ISCONNECTING 0x004 /* in process of connecting to peer */
|
||||
#define SS_ISDISCONNECTING 0x008 /* in process of disconnecting */
|
||||
#define SS_CANTSENDMORE 0x010 /* can't send more data to peer */
|
||||
#define SS_CANTRCVMORE 0x020 /* can't receive more data from peer */
|
||||
#define SS_RCVATMARK 0x040 /* at mark on input */
|
||||
#define SS_ISDISCONNECTED 0x800 /* socket disconnected from peer */
|
||||
|
||||
#define SS_PRIV 0x080 /* privileged for broadcast, raw... */
|
||||
#define SS_NBIO 0x100 /* non-blocking ops */
|
||||
#define SS_ASYNC 0x200 /* async i/o notify */
|
||||
#define SS_ISCONFIRMING 0x400 /* deciding to accept connection req */
|
||||
#define SS_CONNECTOUT 0x1000 /* connect, not accept, at this end */
|
||||
|
||||
/* helpful defines... */
|
||||
|
||||
/* adjust counters in sb reflecting freeing of m */
|
||||
#define sbfree(sb, m) { \
|
||||
(sb)->sb_cc -= (m)->m_len; \
|
||||
(sb)->sb_mbcnt -= MSIZE; \
|
||||
if ((m)->m_flags & M_EXT) \
|
||||
(sb)->sb_mbcnt -= (m)->m_ext.ext_size; \
|
||||
}
|
||||
|
||||
#define sbspace(sb) \
|
||||
((uint32) min((int)((sb)->sb_hiwat - (sb)->sb_cc), \
|
||||
(int)((sb)->sb_mbmax - (sb)->sb_mbcnt)))
|
||||
|
||||
/* do we have to send all at once on a socket? */
|
||||
#define sosendallatonce(so) \
|
||||
((so)->so_proto->pr_flags & PR_ATOMIC)
|
||||
|
||||
/* adjust counters in sb reflecting allocation of m */
|
||||
#define sballoc(sb, m) { \
|
||||
(sb)->sb_cc += (m)->m_len; \
|
||||
(sb)->sb_mbcnt += MSIZE; \
|
||||
if ((m)->m_flags & M_EXT) \
|
||||
(sb)->sb_mbcnt += (m)->m_ext.ext_size; \
|
||||
}
|
||||
|
||||
#define soreadable(so) \
|
||||
((so)->so_rcv.sb_cc >= (so)->so_rcv.sb_lowat || \
|
||||
((so)->so_state & SS_CANTRCVMORE) || \
|
||||
(so)->so_qlen || (so)->so_error)
|
||||
|
||||
#define sowriteable(so) \
|
||||
((sbspace(&(so)->so_snd) >= (so)->so_snd.sb_lowat) && \
|
||||
(((so)->so_state & SS_ISCONNECTED) || \
|
||||
(((so)->so_proto->pr_flags & PR_CONNREQUIRED) == 0) || \
|
||||
((so)->so_state & SS_CANTSENDMORE) || (so)->so_error))
|
||||
|
||||
#define M_WAITOK 0x0000
|
||||
#define M_NOWAIT 0x0001
|
||||
|
||||
/*
|
||||
* Set lock on sockbuf sb; sleep if lock is already held.
|
||||
* Unless SB_NOINTR is set on sockbuf, sleep is interruptible.
|
||||
* Returns error without lock if sleep is interrupted.
|
||||
*/
|
||||
#define sblock(sb, wf) ((sb)->sb_flags & SB_LOCK ? \
|
||||
(((wf) == M_WAITOK) ? sb_lock(sb) : EWOULDBLOCK) : \
|
||||
((sb)->sb_flags |= SB_LOCK), 0)
|
||||
|
||||
/* release lock on sockbuf sb */
|
||||
#define sbunlock(sb) { \
|
||||
(sb)->sb_flags &= ~SB_LOCK; \
|
||||
if ((sb)->sb_flags & SB_WANT) { \
|
||||
(sb)->sb_flags &= ~SB_WANT; \
|
||||
wakeup((sb)->sb_sleep); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define sorwakeup(so) sowakeup((so), &(so)->so_rcv)
|
||||
/* we don't handle upcall for sockets */
|
||||
#define sowwakeup(so) sowakeup((so), &(so)->so_snd)
|
||||
|
||||
#ifdef _NETWORK_STACK
|
||||
|
||||
uint32 sb_max;
|
||||
|
||||
/* Function prototypes */
|
||||
|
||||
/* These are the ones we export to libnet.so */
|
||||
|
||||
int initsocket(void **);
|
||||
int socreate (int, void *, int, int);
|
||||
int soshutdown(void *, int);
|
||||
int soclose (void *);
|
||||
|
||||
int sobind (void *, caddr_t, int);
|
||||
int solisten (void *, int);
|
||||
int soconnect (void *, caddr_t, int);
|
||||
int soaccept (void *, void **, void *, int *);
|
||||
|
||||
int writeit (void *, struct iovec *, int);
|
||||
int readit (void *, struct iovec *, int *);
|
||||
int sendit (void *, struct msghdr *, int, int *);
|
||||
int recvit (void *, struct msghdr *, caddr_t, int *);
|
||||
|
||||
int soo_ioctl (void *, int, caddr_t);
|
||||
int sosysctl (int *, uint, void *, size_t *, void *, size_t);
|
||||
int sosetopt (void *, int, int, const void *, size_t);
|
||||
int sogetopt (void *, int, int, void *, size_t *);
|
||||
|
||||
int sogetpeername(void *, struct sockaddr *, int *);
|
||||
int sogetsockname(void *, struct sockaddr *, int *);
|
||||
|
||||
|
||||
/* these are all private to the stack...although may be shared with
|
||||
* other network modules.
|
||||
*/
|
||||
|
||||
int sosend(struct socket *so, struct mbuf *addr, struct uio *uio,
|
||||
struct mbuf *top, struct mbuf *control, int flags);
|
||||
|
||||
struct socket *sonewconn(struct socket *head, int connstatus);
|
||||
int set_socket_event_callback(void *, socket_event_callback, void *, int);
|
||||
int soreserve (struct socket *so, uint32 sndcc, uint32 rcvcc);
|
||||
|
||||
void sbrelease (struct sockbuf *sb);
|
||||
int sbreserve (struct sockbuf *sb, uint32 cc);
|
||||
void sbdrop (struct sockbuf *sb, int len);
|
||||
void sbdroprecord (struct sockbuf *sb);
|
||||
void sbflush (struct sockbuf *sb);
|
||||
int sbwait (struct sockbuf *sb);
|
||||
void sbappend (struct sockbuf *sb, struct mbuf *m);
|
||||
int sbappendaddr (struct sockbuf *sb, struct sockaddr *asa,
|
||||
struct mbuf *m0, struct mbuf *control);
|
||||
int sbappendcontrol (struct sockbuf *sb, struct mbuf *m0,
|
||||
struct mbuf *control);
|
||||
void sbappendrecord (struct sockbuf *sb, struct mbuf *m0);
|
||||
void sbcheck (struct sockbuf *sb);
|
||||
void sbcompress (struct sockbuf *sb, struct mbuf *m, struct mbuf *n);
|
||||
int soreceive (struct socket *so, struct mbuf **paddr, struct uio *uio,
|
||||
struct mbuf **mp0, struct mbuf **controlp, int *flagsp);
|
||||
void sowakeup(struct socket *so, struct sockbuf *sb);
|
||||
int sbwait(struct sockbuf *sb);
|
||||
|
||||
int sodisconnect(struct socket *);
|
||||
void sofree(struct socket *);
|
||||
|
||||
void sohasoutofband(struct socket *so);
|
||||
void socantsendmore(struct socket *so);
|
||||
void socantrcvmore(struct socket *so);
|
||||
void soisconnected (struct socket *so);
|
||||
void soisconnecting (struct socket *so);
|
||||
void soisdisconnected (struct socket *so);
|
||||
void soisdisconnecting (struct socket *so);
|
||||
void soqinsque (struct socket *head, struct socket *so, int q);
|
||||
int soqremque (struct socket *so, int q);
|
||||
int sorflush(struct socket *so);
|
||||
|
||||
int sb_lock(struct sockbuf *sb);
|
||||
int nsleep(sem_id chan, char *msg, int timeo);
|
||||
void wakeup(sem_id chan);
|
||||
|
||||
#endif /* _NETWORK_STACK */
|
||||
|
||||
#endif /* SYS_SOCKETVAR_H */
|
||||
@@ -0,0 +1,65 @@
|
||||
/* net_ioctl.h */
|
||||
|
||||
#ifndef SYS_NET_IOCTL_H
|
||||
#define SYS_NET_IOCTL_H
|
||||
|
||||
#define IOCPARM_MASK 0x1fff /* parameter length, at most 13 bits */
|
||||
|
||||
#define IOC_OUT (unsigned long)0x40000000
|
||||
/* copy parameters in */
|
||||
#define IOC_IN (unsigned long)0x80000000
|
||||
/* copy paramters in and out */
|
||||
#define IOC_INOUT (IOC_IN|IOC_OUT)
|
||||
/* mask for IN/OUT/VOID */
|
||||
|
||||
#define _IOC(inout,group,num,len) \
|
||||
(inout | ((len & IOCPARM_MASK) << 16) | ((group) << 8) | (num))
|
||||
|
||||
#define IOCGROUP(x) (((x) >> 8) & 0xff)
|
||||
|
||||
#define _IOR(g,n,t) _IOC(IOC_OUT, (g), (n), sizeof(t))
|
||||
#define _IOW(g,n,t) _IOC(IOC_IN, (g), (n), sizeof(t))
|
||||
#define _IOWR(g,n,t) _IOC(IOC_INOUT, (g), (n), sizeof(t))
|
||||
|
||||
#define FIONBIO _IOW('f', 126, int) /* set/clear non-blocking i/o */
|
||||
#define FIONREAD _IOR('f', 127, int) /* get # bytes to read */
|
||||
|
||||
#define SIOCSHIWAT _IOW('s', 0, int) /* set high watermark */
|
||||
#define SIOCGHIWAT _IOR('s', 1, int) /* get high watermark */
|
||||
#define SIOCSLOWAT _IOW('s', 2, int) /* set low watermark */
|
||||
#define SIOCGLOWAT _IOR('s', 3, int) /* get low watermark */
|
||||
#define SIOCATMARK _IOR('s', 7, int) /* at oob mark? */
|
||||
|
||||
#define SIOCADDRT _IOW('r', 10, struct ortentry) /* add route */
|
||||
#define SIOCDELRT _IOW('r', 11, struct ortentry) /* delete route */
|
||||
|
||||
#define SIOCSIFADDR _IOW('i', 12, struct ifreq) /* set ifnet address */
|
||||
#define OSIOCGIFADDR _IOWR('i', 13, struct ifreq) /* get ifnet address */
|
||||
#define SIOCGIFADDR _IOWR('i', 33, struct ifreq) /* get ifnet address */
|
||||
#define SIOCSIFDSTADDR _IOW('i', 14, struct ifreq) /* set p-p address */
|
||||
#define OSIOCGIFDSTADDR _IOWR('i', 15, struct ifreq) /* get p-p address */
|
||||
#define SIOCGIFDSTADDR _IOWR('i', 34, struct ifreq) /* get p-p address */
|
||||
#define SIOCSIFFLAGS _IOW('i', 16, struct ifreq) /* set ifnet flags */
|
||||
#define SIOCGIFFLAGS _IOWR('i', 17, struct ifreq) /* get ifnet flags */
|
||||
#define OSIOCGIFBRDADDR _IOWR('i', 18, struct ifreq) /* get broadcast addr */
|
||||
#define SIOCGIFBRDADDR _IOWR('i', 35, struct ifreq) /* get broadcast addr */
|
||||
#define SIOCSIFBRDADDR _IOW('i', 19, struct ifreq) /* set broadcast addr */
|
||||
#define OSIOCGIFCONF _IOWR('i', 20, struct ifconf) /* get ifnet list */
|
||||
#define SIOCGIFCONF _IOWR('i', 36, struct ifconf) /* get ifnet list */
|
||||
#define OSIOCGIFNETMASK _IOWR('i', 21, struct ifreq) /* get net addr mask */
|
||||
#define SIOCGIFNETMASK _IOWR('i', 37, struct ifreq) /* get net addr mask */
|
||||
#define SIOCSIFNETMASK _IOW('i', 22, struct ifreq) /* set net addr mask */
|
||||
#define SIOCGIFMETRIC _IOWR('i', 23, struct ifreq) /* get IF metric */
|
||||
#define SIOCSIFMETRIC _IOW('i', 24, struct ifreq) /* set IF metric */
|
||||
#define SIOCDIFADDR _IOW('i', 25, struct ifreq) /* delete IF addr */
|
||||
#define SIOCAIFADDR _IOW('i', 26, struct ifaliasreq)/* add/chg IF alias */
|
||||
#define SIOCGIFDATA _IOWR('i', 27, struct ifreq) /* get if_data */
|
||||
|
||||
#define SIOCGIFMTU _IOWR('i', 126, struct ifreq) /* get ifnet MTU */
|
||||
#define SIOCSIFMTU _IOW('i', 127, struct ifreq) /* set ifnet MTU */
|
||||
|
||||
#define SIOCADDMULTI _IOW('i', 49, struct ifreq) /* add m'cast addr */
|
||||
#define SIOCDELMULTI _IOW('i', 50, struct ifreq) /* del m'cast addr */
|
||||
|
||||
#endif /* SYS_NET_IOCTL_H */
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
#ifndef USERLAND_IPC_H
|
||||
#define USERLAND_IPC_H
|
||||
/* userland_ipc - Communication between the network driver
|
||||
** and the userland stack.
|
||||
**
|
||||
** Initial version by Axel Dörfler, [email protected]
|
||||
** This file may be used under the terms of the OpenBeOS License.
|
||||
*/
|
||||
|
||||
|
||||
#include <OS.h>
|
||||
#include "net_stack_driver.h"
|
||||
|
||||
|
||||
#define NET_STACK_PORTNAME "net_server connection"
|
||||
|
||||
enum {
|
||||
NET_STACK_OPEN = NET_STACK_IOCTL_MAX,
|
||||
NET_STACK_CLOSE,
|
||||
NET_STACK_NEW_CONNECTION,
|
||||
};
|
||||
|
||||
#define MAX_NET_AREAS 5
|
||||
|
||||
typedef struct {
|
||||
area_id id;
|
||||
uint8 *offset;
|
||||
} net_area_info;
|
||||
|
||||
typedef struct {
|
||||
int32 op;
|
||||
// int32 buffer;
|
||||
uint8 *data;
|
||||
int32 length;
|
||||
int32 result;
|
||||
net_area_info area[MAX_NET_AREAS];
|
||||
} net_command;
|
||||
|
||||
#define CONNECTION_QUEUE_LENGTH 128
|
||||
#define CONNECTION_COMMAND_SIZE 2048
|
||||
|
||||
typedef struct {
|
||||
port_id port;
|
||||
area_id area;
|
||||
|
||||
sem_id commandSemaphore; // command queue
|
||||
uint32 numCommands,bufferSize;
|
||||
} net_connection;
|
||||
|
||||
extern status_t init_userland_ipc(void);
|
||||
extern void shutdown_userland_ipc(void);
|
||||
|
||||
#endif /* USERLAND_IPC_H */
|
||||
Reference in New Issue
Block a user