📄 tcp_ipp.h
字号:
/***********************************************************************//* *//* Module: tcp_ip/tcp_ipp.h *//* Release: 2001.3 *//* Version: 2001.0 *//* Purpose: TCP/IP Private Include File *//* *//*---------------------------------------------------------------------*//* *//* Copyright 2001, Blunk Microsystems *//* ALL RIGHTS RESERVED *//* *//* Licensees have the non-exclusive right to use, modify, or extract *//* this computer program for software development at a single site. *//* This program may be resold or disseminated in executable format *//* only. The source code may not be redistributed or resold. *//* *//* *//***********************************************************************/#ifndef _TCP_IPP_H /* Don't include this file more than once */#define _TCP_IPP_H#include <targetos.h>#include "kernel.h"#include "sys.h"#include <sockets.h>#include <tcp_ip.h>#include <stddef.h>#include <errno.h>/***********************************************************************//* Configuration *//***********************************************************************/#define HI_PORT_NUM 5000 /* maximum ephemeral port number */#define LO_PORT_NUM 1025 /* minimum ephemeral port number */#define GATEWAY FALSE /* enables router behavior */#if FALSE /* TRUE for TargetTCP testing, FALSE for production */void AssertError(int line, char *file);#define TcpAssert(c) if (c) \ {} \ else \ AssertError(__LINE__, __FILE__)#else#define TcpAssert(c)#endif/***********************************************************************//* Symbol Definitions *//***********************************************************************/#define UDP_HLEN 8 /* UDP header length in bytes */#define IPMHLEN 20 /* minimum IP header length in bytes */#define TICKS_PER_SEC 10 /* TCP/IP timer ticks per second *//*** Message Definitions*/#define PUTP 1#define DATA_IND 2#define ATTN_REQ 3#define FREE_BUF 4/*** Socket Flags**** First are definitions for flag field in TCP header*/#define TCPF_FIN 0x01 /* sender is finished sending */#define TCPF_SYN 0x02 /* synchronize sequence numbers */#define TCPF_RST 0x04 /* reset the connection */#define TCPF_PSH 0x08 /* this segment requests a push */#define TCPF_ACK 0x10 /* acknowledgment field is valid */#define TCPF_URG 0x20 /* urgent pointer is valid *//*** Other control socket API options or state machine behavior*/#define SF_SENDFLG 0x00000100 /* need to output */#define SF_OOOFIN 0x00000200 /* received out of order FIN */#define SF_GOTFIN 0x00000400 /* received FIN */#define SF_SNDFIN 0x00000800 /* need to send FIN */#define SF_RUPOK 0x00001000 /* valid receive urgent pointer */#define SF_SUPOK 0x00002000 /* send urgent pointer is valid */#define SF_CONNECTED 0x00004000 /* socket has been connected */#define SF_OOB_DATA 0x00008000 /* TRUE iff OOB data available */#define SF_BROADCAST 0x00010000 /* datagram broadcast enable */#define SF_RCV_SHUT 0x00020000 /* socket shutdown for receiving */#define SF_SND_SHUT 0x00040000 /* socket shutdown for sending */#define SF_NODELAY 0x00080000 /* disable Nagle algorithm */#define SF_INLINE 0x00100000 /* leave OOB data in line */#define SF_LINGER 0x00200000 /* linger on close */#define SF_FORCEFUL 0x00400000 /* forceful close */#define SF_NONBLKNG 0x00800000 /* TRUE iff no blocking allowed */#define SF_DONTROUTE 0x01000000 /* omit routing */#define SF_REUSEADDR 0x02000000 /* allow local address reuse */#define SF_KEEPALIVE 0x04000000 /* enable KEEPALIVE timer */#define SF_INHERITED (SF_NODELAY | SF_INLINE | SF_LINGER | \ SF_FORCEFUL | SF_NONBLKNG | SF_DONTROUTE | \ SF_REUSEADDR | SF_KEEPALIVE)#define SF_TW_RESTART 0x08000000 /* TIME_WAIT restart occurred */#define SF_TIMING_RTT 0x10000000 /* measuring round trip time */#define SF_NOCHECKSUM 0x20000000 /* measuring round trip time *//*** Socket States*/#define SS_FREE 0#define SS_CLOSED 1#define SS_LISTEN 2#define SS_SYNSENT 3#define SS_SYNRCVD 4#define SS_ESTABLISHED 5#define SS_FINWAIT1 6#define SS_FINWAIT2 7#define SS_CLOSEWAIT 8#define SS_LASTACK 9#define SS_CLOSING 10#define SS_TIMEWAIT 11/***********************************************************************//* Macro Definitions *//***********************************************************************/#define InvalidHandle(s) ((s == 0) || \ ((uint)(s) > MAX_NUM_SOCKETS) || \ (Socks[s - 1].state == SS_FREE) || \ (Socks[s - 1].api_access == 0))#define INIT_TMR(tmr) (tmr.link.next_fwd = tmr.link.next_bck = &tmr.link)/***********************************************************************//* Type Definitions *//***********************************************************************//*** TCP Sequence Number*/typedef ui32 tcpseq;/*** Socket Address Structure*/typedef struct sockaddr_in SockAddr;/*** Circular Linked List Node (used for timer lists)*/typedef struct circ_list{ struct circ_list *next_fwd; struct circ_list *next_bck;} CircLink;/*** Timer Control Block*/typedef struct tcp_tmr{ CircLink link; /* offset fixed at 0 */ ui32 time_due; void (*action)(void *object); void *object; int running;} TcpTmr;/*** Socket Structure*/typedef struct socket *SOCKET;typedef const struct socket *CSOCKET;struct socket{ /* ** Fields common between TCP and UDP sockets. */ CircLink link; /* offset fixed at 0 */ struct route *route; /* route to connection endpoint */ NetBuf *rq_head; /* buffer queue head */ NetBuf *rq_tail; /* buffer queue tail */ SockAddr remote; /* peer's address */ SockAddr local; /* socket's address */ ui32 flags; /* option and state flags */ ui32 connect_timeo; /* send() timeout */ ui32 send_timeo; /* send() timeout */ ui32 recv_timeo; /* recv() timeout */ ui32 events; /* for posting/pending events */ SEM api_access; /* for application mutual exclusion */ TASK taskid; /* handle for waking tasks */ ui16 type; /* SOCK_STREAM or SOCK_DGRAM */ short q_count; /* datagram/listen queue count */ int reserve_cnt; /* number of socket reservations */ int error; /* application error code */ int soft_error; /* reported only if timeout occurs */ /* ** Fields specific to TCP sockets. */ ui32 sel_evnts; /* for posting/pending select() events */ TASK sel_id; /* handle for waking select() task */ SOCKET lq_next; /* listen queue next pointer */ SOCKET lq_head; /* listen queue head pointer */ SOCKET lq_tail; /* listen queue tail pointer */ SOCKET psock; /* pointer to parent socket, for accept() */ tcpseq snt_una; /* lowest unacknowledged sequence number */ tcpseq snd_nxt; /* next sequence number to send */ tcpseq max_snt; /* maximum sequence number sent */ tcpseq rtt_seq; /* sequence whose RTT is being measured */ tcpseq fin_seq; /* sequence of FIN, if SF_SNDFIN set */ tcpseq lw_seq; /* sequence of last window update */ tcpseq surg_seq; /* sequence number of urgent send data */ tcpseq rurg_seq; /* sequence number of urgent receive data */ tcpseq rcv_nxt; /* next sequence number to receive */ tcpseq rd_nxt; /* next sequence number to read */ tcpseq ooo_fin; /* FIN sequence number if SF_OOOFIN set */ struct srec *oosq; /* out-of-order segment record queue */ ui8 *sbuf; /* pointer to circular send buffer */ ui8 *rbuf; /* pointer to circular receive buffer */ TcpTmr state_tmr; /* timer for SYN_RCVD, FIN wait, and 2MSL */ TcpTmr out_tmr; /* timer for retransmit and persist timing */ TcpTmr ack_tmr; /* timer for delayed acks */ void (*report)(int sock, ui32 events); /* optional callback function */ ui32 rb_start; /* start of valid data */ ui32 rb_count; /* data character count */ ui32 rb_size; /* receive buffer size (bytes) */ ui32 snd_window; /* send window size (bytes) */ i32 rcv_win; /* offered receive window */ ui16 snd_cwnd; /* congestion window size (bytes) */ ui16 ssthresh; /* slow start threshold (bytes) */ ui16 snd_mss; /* max send segment size (bytes) */ ui16 srtt; /* smoothed round trip time */ ui16 rttvar; /* round trip deviation estimator */ ui16 retrans_timeo; /* retransmit timeout value */ ui16 persist_timeo; /* persist timeout value */ ui16 sb_start; /* start of send buffer unacknowledged data */ ui16 sb_count; /* send buffer valid byte count */ ui16 sb_size; /* send buffer size (bytes) */ ui16 rcv_mss; /* max receive segment size (bytes) */ ui8 dup_acks; /* number of duplicate acknowledgments */ ui8 retrans_count; /* number of retransmissions sent */ ui8 state; /* TCP state */ ui8 out_state; /* output state */ ui8 lis_backlog; /* listen queue max size */ ui8 ip_tos; /* type of service */};/*** UDP Packet Format*/typedef struct udp{ ui16 src_port; /* source UDP port number */ ui16 dst_port; /* destination UDP port number */ ui16 length; /* length of UDP data */ ui16 checksum; /* UDP checksum (0 => none) */ ui8 data[1]; /* data in UDP message */} Udp;/*** Statistics*/typedef struct{ int IpPartialPkt; int IpFragFails; int IpReasmFails; int IpOutDiscards; int IpFragCreates; int IpReasmReqds; int IpInHdrErrors; int IpInAddrErrors; int IpOutNoRoutes; int IpForwDatagrams; int IgmpInSegs; int UdpInErrors; int UdpInDatagrams; int UdpNoPorts; int UdpOutDatagrams; int RouteCacheHits; int TcpInSegs; int TcpActiveOpens; int TcpPassiveOpens; int TcpEstabResets; int TcpAttemptFails; int TcpOutSegs; int TcpRetransSegs; int TcpCurrEstab; int GetBufFails; int IcmpDestUr;} StatType;/*** Route Structure*/typedef struct route Route;/***********************************************************************//* Global Variable Declarations *//***********************************************************************//*** TCP/IP Global Variables*/extern struct tcp_globals{ int IsGateway; tcpseq ISN; Ni Local; int Initialized; SEM IntSem; SEM DnsSem; int SockCount; int SockMin; int PutFailed; int QHighWater; int TryOut; struct ip *Ip; /* pointer to packet's IP data */ struct tcp *Tcp; /* pointer to packet's TCP segment */ ui16 IpAckId;} Net;extern StatType Stats;extern struct socket Socks[MAX_NUM_SOCKETS];extern void (*TcpSwitch[])(void);extern CircLink TcpLruList;extern CircLink UdpLruList;extern CircLink NetSockList;extern NetBuf *RxBuf;extern int NetProbeFlag;extern ui32 NetTickCount;/***********************************************************************//* Global Function Prototypes *//***********************************************************************/void NetPendEvent(SOCKET sock, ui32 events, ui32 timeout);void NetPostEvent(SOCKET sock, ui32 events);int NetPostMsg(void (*func)(void *ptr), void *ptr, ui32 msg);void NetProbe(const NetBuf *buf);void NetBufInit(void);void NetQueryArp(void);void NetQueryBuf(void);SOCKET SockAlloc(int type);void SockRelease(SOCKET sock);void NetRstBuf(NetBuf *ptr);void tcpRetRcvBuf(NetBuf *buf);void NetError(SOCKET sock, int err_code);void ArpInit(void);void ArpIn(void);void IpIn(void);void RarpIn(void);void IcmpIn(void);void TcpIn(void);void TcpOut(void *object);ui16 TcpNextPort(void);void TcpFlush(NetBuf *buf);void TcpTrimBeg(NetBuf *buf, int overlap);ui16 DataChecksum(ui32 partial, const NetBuf *buf);void NetTimerInit(void);void NetTimerStart(TcpTmr *timer, uint timeout);void NetTimerStop(TcpTmr *timer);void NetTimerTick(void);void UdpInit(void);void UdpIn(void);int UdpConnect(SOCKET sock);ui16 UdpNextPort(void);void UdpSend(CSOCKET sock, const SockAddr *dst, NetBuf *buf, int len, Route *r);void UdpQuerySock(void);void IcmpDestUR(int code, NetBuf *buf, ui32 src, ui32 dst);void IcmpTimeEx(int code, NetBuf *buf, ui32 src, ui32 dst);void IcmpRedirect(int code, ui32 gw, ui32 src, ui32 dst);void IcmpDecode(const NetBuf *buf);void DhcpInit(void);int DhcpAdd(Ni *ni);int DhcpDel(const Ni *ni);void DhcpArpReq(Ni *ni, ui32 ip_addr);int DhcpArpCached(ui32 addr);void DhcpArpReply(Ni *ni);int RarpAdd(Ni *ni);void NiWrite(NetBuf *buf);int NiRtAdd(Ni *ni);void NiBufFree(Ni *ni);ui32 NiBorrowAddr(void);#endif /* _TCP_IPP_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -