home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / internet / tcpipsrc / h / if / syslog / TCP next >
Encoding:
Text File  |  1995-01-28  |  7.9 KB  |  207 lines

  1. /* TCP implementation. Follows RFC 793 as closely as possible */
  2.  
  3. #define DEF_WND  2048   /* Default receiver window */
  4. #define NTCB     19     /* # TCB hash table headers */
  5. #define DEF_MSS  512    /* Default maximum segment size */
  6. #define DEF_RTT  5000   /* Initial guess at round trip time (5 sec) */
  7. #define DEF_MRTT 30000  /* Maximum allowed re-transmittion interval (30 sec) */
  8. #define MSL2     30     /* Guess at two maximum-segment lifetimes */
  9. /* Round trip timing parameters */
  10. #define AGAIN    8      /* Average RTT gain = 1/8 */
  11. #define DGAIN    4      /* Mean deviation gain = 1/4 */
  12.  
  13. /* TCP segment header -- internal representation
  14.  * Note that this structure is NOT the actual header as it appears on the
  15.  * network (in particular, the offset and checksum fields are missing).
  16.  * All that knowledge is in the functions ntohtcp() and htontcp() in tcpsubr.c
  17.  */
  18. struct tcp {
  19.         int16 source;   /* Source port */
  20.         int16 dest;     /* Destination port */
  21.         int32 seq;      /* Sequence number */
  22.         int32 ack;      /* Acknowledgment number */
  23.         char flags;     /* Flags, data offset */
  24. #define URG     0x20    /* URGent flag */
  25. #define ACK     0x10    /* ACKnowledgment flag */
  26. #define PSH     0x08    /* PuSH flag */
  27. #define RST     0x04    /* ReSeT flag */
  28. #define SYN     0x02    /* SYNchronize flag */
  29. #define FIN     0x01    /* FINal flag */
  30.         int16 wnd;      /* Receiver flow control window */
  31.         int16 up;       /* Urgent pointer */
  32.         int16 mss;      /* Optional max seg size */
  33. };
  34. /* TCP options */
  35. #define EOL_KIND        0
  36. #define NOOP_KIND       1
  37. #define MSS_KIND        2
  38.  
  39. #define TCPLEN          20
  40. #define MSS_LENGTH      4
  41. /* Resequencing queue entry */
  42. struct reseq {
  43.         struct reseq *next;     /* Linked-list pointer */
  44.         char tos;               /* Type of service */
  45.         struct tcp seg;         /* TCP header */
  46.         struct mbuf *bp;        /* data */
  47.         int16 length;           /* data length */
  48. };
  49. #define NULLRESEQ       (struct reseq *)0
  50.  
  51. /* TCP connection control block */
  52. struct tcb {
  53.         struct tcb *prev;       /* Linked list pointers for hash table */
  54.         struct tcb *next;
  55.  
  56.         struct connection conn;
  57.  
  58.         char state;     /* Connection state */
  59. #define CLOSED          0       /* Must be 0 */
  60. #define LISTEN          1
  61. #define SYN_SENT        2
  62. #define SYN_RECEIVED    3
  63. #define ESTABLISHED     4
  64. #define FINWAIT1        5
  65. #define FINWAIT2        6
  66. #define CLOSE_WAIT      7
  67. #define CLOSING         8
  68. #define LAST_ACK        9
  69. #define TIME_WAIT       10
  70.  
  71.         char reason;            /* Reason for closing */
  72. #define NORMAL          0       /* Normal close */
  73. #define RESET           1       /* Reset by other end */
  74. #define TIMEOUT         2       /* Excessive retransmissions */
  75. #define NETWORK         3       /* Network problem (ICMP message) */
  76.  
  77. /* If reason == NETWORK, the ICMP type and code values are stored here */
  78.         char type;
  79.         char code;
  80.  
  81.         /* Send sequence variables */
  82.         struct {
  83.                 int32 una;      /* First unacknowledged sequence number */
  84.                 int32 nxt;      /* Next sequence num to be sent for the first time */
  85.                 int32 ptr;      /* Working transmission pointer */
  86.                 int16 wnd;      /* Other end's offered receive window */
  87.                 int16 up;       /* Send urgent pointer */
  88.                 int32 wl1;      /* Sequence number used for last window update */
  89.                 int32 wl2;      /* Ack number used for last window update */
  90.         } snd;
  91.         int32 iss;              /* Initial send sequence number */
  92.         int16 cwind;            /* Congestion window */
  93.         int16 ssthresh;         /* Slow-start threshold */
  94.         int32 resent;           /* Count of bytes retransmitted */
  95.  
  96.         /* Receive sequence variables */
  97.         struct {
  98.                 int32 nxt;      /* Incoming sequence number expected next */
  99.                 int16 wnd;      /* Our offered receive window */
  100.                 int16 up;       /* Receive urgent pointer */
  101.         } rcv;
  102.         int32 irs;              /* Initial receive sequence number */
  103.         int16 mss;              /* Maximum segment size */
  104.         int32 rerecv;           /* Count of duplicate bytes received */
  105.  
  106.         int16 window;           /* Receiver window and send queue limit */
  107.  
  108.         char backoff;           /* Backoff interval */
  109.         void (*r_upcall)();     /* Call when "significant" amount of data arrives */
  110.         void (*t_upcall)();     /* Call when ok to send more data */
  111.         void (*s_upcall)();     /* Call when connection state changes */
  112.         char flags;             /* Control flags */
  113. #define FORCE   1               /* We owe the other end an ACK or window update */
  114. #define CLONE   2               /* Server-type TCB, cloned on incoming SYN */
  115. #define RETRAN  4               /* A retransmission has occurred */
  116. #define ACTIVE  8               /* TCB created with an active open */
  117. #define SYNACK  16              /* Our SYN has been acked */
  118.         char tos;               /* Type of service (for IP) */
  119.  
  120.         struct mbuf *rcvq;      /* Receive queue */
  121.         int16 rcvcnt;
  122.  
  123.         struct mbuf *sndq;      /* Send queue */
  124.         int16 sndcnt;           /* Number of unacknowledged sequence numbers on
  125.                                  * send queue. NB: includes SYN and FIN, which don't
  126.                                  * actually appear on sndq!
  127.                                  */
  128.  
  129.  
  130.         struct reseq *reseq;    /* Out-of-order segment queue */
  131.         struct timer timer;     /* Retransmission timer */
  132.         struct timer rtt_timer; /* Round trip timer */
  133.         int32 rttseq;           /* Sequence number being timed */
  134.         int32 srtt;             /* Smoothed round trip time, milliseconds */
  135.         int32 mdev;             /* Mean deviation, milliseconds */
  136.  
  137.         char *user;             /* User parameter (e.g., for mapping to an
  138.                                  * application control block
  139.                                  */
  140. };
  141. #define NULLTCB (struct tcb *)0
  142. /* TCP statistics counters */
  143. struct tcp_stat {
  144.         int16 runt;             /* Smaller than minimum size */
  145.         int16 checksum;         /* TCP header checksum errors */
  146.         int16 conout;           /* Outgoing connection attempts */
  147.         int16 conin;            /* Incoming connection attempts */
  148.         int16 resets;           /* Resets generated */
  149.         int16 bdcsts;           /* Bogus broadcast packets */
  150. };
  151. extern struct tcp_stat tcp_stat;
  152.  
  153. extern struct tcb *tcbs[];
  154.  
  155. /* In TCPCMD */
  156. int dotcp(int, char **);
  157. int rem_kick(void);
  158.  
  159. /* In TCPDUMP */
  160. void tcp_dump(struct mbuf **, int32, int32, int);
  161.  
  162. /* In TCPIN */
  163. void tcp_input(struct mbuf *, char, int32, int32, char, int16, char);
  164. void tcp_icmp(int32, int32, char, char, struct mbuf **);
  165. void send_syn(struct tcb *);
  166.  
  167. /* In TCPOUT */
  168. void tcp_output(struct tcb *);
  169.  
  170. /* In TCPSUBR */
  171. struct tcb *lookup_tcb(struct connection *);
  172. struct tcb *create_tcb(struct connection *);
  173. void close_self(struct tcb *, char);
  174. int32 iss(void);
  175. int seq_within(int32, int32, int32);
  176. int seq_lt(int32, int32);
  177. int seq_le(int32, int32);
  178. int seq_gt(int32, int32);
  179. int seq_ge(int32, int32);
  180. void link_tcb(struct tcb *);
  181. void unlink_tcb(struct tcb *);
  182. void setstate(struct tcb *, char);
  183. struct mbuf *htontcp(struct tcp *, struct mbuf *, struct pseudo_header *);
  184. int ntohtcp(struct tcp *, struct mbuf **);
  185.  
  186. /* In TCPTIMER*/
  187. void tcp_timeout(char *);
  188. int  backoff(int);
  189.  
  190. /* In TCPUSER */
  191. struct tcb *open_tcp(struct socket *, struct socket *, int, int16,
  192.                      void (*)(), void (*)(), void (*)(), char, char *);
  193. int send_tcp(struct tcb *, struct mbuf *);
  194. int recv_tcp(struct tcb *, struct mbuf **, int16);
  195. int close_tcp(struct tcb *);
  196. int del_tcp(struct tcb *);
  197. int tprintf(struct tcb *, char *, ...);
  198. int tcpval(struct tcb *);
  199. int kick_tcp(struct tcb *);
  200. void reset_tcp(struct tcb *);
  201. char *tcp_port(int16);
  202.  
  203. extern int16 tcp_mss;
  204. extern int16 tcp_window;
  205. extern int32 tcp_irtt;
  206. extern int32 tcp_mrtt;
  207.