It is accomplished ...

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
ejakowatz
2002-07-09 12:24:59 +00:00
commit 52a3801208
2025 changed files with 472889 additions and 0 deletions
+61
View File
@@ -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 */
+200
View File
@@ -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 */
+148
View File
@@ -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 */
+71
View File
@@ -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 */
+63
View File
@@ -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 */
+64
View File
@@ -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 */
+129
View File
@@ -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 */
+172
View File
@@ -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 */
+155
View File
@@ -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 */
+95
View File
@@ -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 */
+63
View File
@@ -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_ */
+86
View File
@@ -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_ */
+67
View File
@@ -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_ */
+136
View File
@@ -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 */
+280
View File
@@ -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 */
+66
View File
@@ -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 */
+48
View File
@@ -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 */
+51
View File
@@ -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