tcp.h

Go to the documentation of this file.
00001 /*
00002 ** tcp.h for  in /home/anoman/work/lse/lseos/lseos-net/inet
00003 ** 
00004 ** Copyright (c)2004 Arthur Kopatsy
00005 ** Login   <kopats_a@epita.fr>
00006 ** 
00007 ** Started on  Tue Nov  9 10:57:11 2004 Arthur Kopatsy
00008 ** Last update Tue Dec 14 09:58:55 2004 Arthur Kopatsy
00009 */
00010 
00011 #ifndef TCP_H_
00012 #define TCP_H_
00013 
00014 #define TCP_FL_FIN      0x01
00015 #define TCP_FL_SYN      0x02
00016 #define TCP_FL_RST      0x04
00017 #define TCP_FL_PSH      0x08
00018 #define TCP_FL_ACK      0x10
00019 #define TCP_FL_URG      0x20
00020 
00021 struct s_tcp_hdr
00022 {
00023   u_int16_t             tcp_sp;
00024   u_int16_t             tcp_dp;
00025   u_int32_t             tcp_seq;
00026   u_int32_t             tcp_ack;
00027 #if 1                   /* Little indian */
00028   u_int8_t              tcp_u : 4;
00029   u_int8_t              tcp_hl : 4;
00030   u_int8_t              tcp_flg;
00031 #else
00032   u_int8_t              tcp_flg;
00033   u_int8_t              tcp_hl : 4;
00034   u_int8_t              tcp_u : 4;
00035 #endif
00036   u_int16_t             tcp_win;
00037   u_int16_t             tcp_sum;
00038   u_int16_t             tcp_urp;
00039 } __attribute__ ((packed));
00040 
00041 #define TCP_HEADER_LEN  sizeof (struct s_tcp_hdr)
00042 
00043 #ifdef __INET__
00044 
00045 #define TCP_WINDOW_SIZE         5840
00046 #define TCP_DEFAULT_MSS         1460
00047 
00048 /*
00049 ** TCP options
00050 */
00051 
00052 #define TCPOPT_EOL              0x00
00053 #define TCPOPT_NOP              0x01
00054 #define TCPOPT_MSS              0x02
00055 # define TCPOPT_LEN_MSS         0x04
00056 #define TCPOPT_WSCALE           0x03
00057 # define TCPOPT_LEN_WSCALE      0x03
00058 #define TCPOPT_SACKOK           0x04
00059 # define TCPOPT_LEN_SACKOK      0x02
00060 #define TCPOPT_SACK             0x05
00061 #define TCPOPT_TIMESTAMP        0x08
00062 # define TCPOPT_LEN_TIMESTAMP   0x0a
00063 
00064 struct s_tcp_option
00065 {
00066   int8_t        opt;
00067   int8_t        optlen;
00068 };
00069 
00070 enum e_tcp_state
00071   {
00072     STATE_CLOSED, STATE_LISTEN, STATE_SYN_SENT, STATE_SYN_RCVD, STATE_ESTABLISHED,
00073     STATE_FIN_WAIT_1, STATE_FIN_WAIT_2, STATE_TIME_WAIT, STATE_CLOSE_WAIT,
00074     STATE_LAST_ACK
00075   };
00076 
00077 struct s_tcp_segment
00078 {
00079   TAILQ_ENTRY(s_tcp_segment)            seg_next;
00080 
00081   struct s_tcp_pcb                      *seg_pcb;
00082 
00083   u_int32_t                             seg_seq;
00084   struct s_data_buf                     *seg_data;
00085   size_t                                seg_size;
00086 
00087   int                                   seg_try;        /* Retry number */
00088   int                                   seg_timer_id;   /* Retransmission timer */
00089   int64_t                               seg_timeout;    /* Current timeout associated with timer*/
00090   int64_t                               seg_ar;         /* Async report associated with this emission */
00091 };
00092 
00093 TAILQ_HEAD(s_tcp_segment_tailq, s_tcp_segment);
00094 
00095 struct s_tcp_pcb;
00096 LIST_HEAD(s_tcp_pcb_list, s_tcp_pcb);
00097 
00098 struct s_tcp_pcb
00099 {
00100   LIST_ENTRY(s_tcp_pcb)         tcp_next;
00101   LIST_ENTRY(s_tcp_pcb)         tcp_next_con;
00102   int                           tcp_lock;
00103   enum e_tcp_state              tcp_state;
00104 
00105   /* Send */
00106   u_int32_t                     tcp_snd_iss;            /* Initial segment sequence */
00107   u_int32_t                     tcp_snd_una;            /* First not aknowleged segment sequence */
00108   u_int32_t                     tcp_snd_nxt;            /* Next segment sequence to send */
00109   u_int16_t                     tcp_snd_win;
00110   struct s_tcp_segment_tailq    tcp_sndq_una;
00111 
00112   /* Recv */
00113   u_int32_t                     tcp_rcv_iss;
00114   u_int16_t                     tcp_rcv_win;
00115   u_int32_t                     tcp_rcv_una;
00116   struct s_tcp_segment_tailq    tcp_rcvq_una;           /* Unaknowledged segment queue */
00117   struct s_tcp_segment_tailq    tcp_rcvq;               /* Aknowledged segment queue */
00118 
00119   struct s_tcp_pcb_list         tcp_con;                /* Connections established or not */
00120 
00121   struct s_in_pcb               *tcp_in_pcb;
00122   int64_t                       tcp_holders;
00123 
00124   struct s_entry                *tcp_entry;
00125 };
00126 
00127 typedef void (*t_tcp_state_fun)(struct s_tcp_pcb        *pcb,
00128                                 struct s_pkbuf          *pk);
00129 
00130 struct s_tcp_state
00131 {
00132   enum e_tcp_state      state;
00133   t_tcp_state_fun       state_fun;
00134 };
00135 
00136 extern struct s_tcp_state tcp_states[];
00137 
00138 struct s_tcp_proto_info
00139 {
00140   struct s_tcp_pcb_list tcp_pcb;
00141   struct s_in_pcb_list  in_pcb;
00142   struct s_entry        *tcp_entry;
00143 };
00144 
00145 extern struct s_tcp_proto_info  tcp_proto_info;
00146 
00147 #endif
00148 
00149 /* PROTO tcp.c tcp_socket.c */
00150 #ifdef __INET__
00151 /* tcp.c */
00152 void tcp_dump(struct s_pkbuf *pk);
00153 void tcp_proto_init(void);
00154 u_int32_t tcp_alloc_sequence(void);
00155 int aa_tcp_input(struct s_pkbuf *pk);
00156 int tcp_output(struct s_pkbuf *pk, struct s_tcp_pcb *pcb, int tcp_flags, u_int32_t tcp_seq);
00157 void tcp_syn_sent_timeout(struct s_tcp_segment *segment);
00158 int aa_tcp_connect(struct s_tcp_segment *segment);
00159 void tcp_syn_sent_recv(struct s_tcp_pcb *pcb, struct s_pkbuf *pk);
00160 void tcp_send_timeout(struct s_tcp_segment *segment);
00161 int aa_tcp_send(struct s_tcp_segment *segment);
00162 int aa_tcp_ack(struct s_tcp_pcb *pcb);
00163 int aa_tcp_close(struct s_tcp_pcb *pcb);
00164 void tcp_established_recv(struct s_tcp_pcb *pcb, struct s_pkbuf *pk);
00165 void tcp_listen_recv(struct s_tcp_pcb *pcb, struct s_pkbuf *pk);
00166 int aa_tcp_accept(struct s_tcp_pcb *pcb);
00167 void tcp_syn_rcvd_recv(struct s_tcp_pcb *pcb, struct s_pkbuf *pk);
00168 void tcp_last_ack_recv(struct s_tcp_pcb *pcb, struct s_pkbuf *pk);
00169 void tcp_fin_wait_1_recv(struct s_tcp_pcb *pcb, struct s_pkbuf *pk);
00170 void tcp_fin_wait_2_recv(struct s_tcp_pcb *pcb, struct s_pkbuf *pk);
00171 /* tcp_socket.c */
00172 int tcp_poll(struct s_socket *so, t_pollrec *pollrec);
00173 int tcp_attach(struct s_socket *so);
00174 int tcp_detach(struct s_socket *so);
00175 int tcp_bind(struct s_socket *so, struct sockaddr *sa, socklen_t salen);
00176 int tcp_getpeername(struct s_socket *so, struct sockaddr *sa, socklen_t *salen);
00177 int tcp_getsockname(struct s_socket *so, struct sockaddr *sa, socklen_t *salen);
00178 int tcp_connect(struct s_socket *so, struct sockaddr *sa, socklen_t salen);
00179 size_t tcp_recv(struct s_socket *so, pid_t pid, struct sockaddr *sa, socklen_t *salen, vaddr_t uaddr, size_t usize);
00180 int tcp_accept(struct s_socket *so, struct sockaddr *sa, socklen_t *salen, void **ret_pcb);
00181 int tcp_listen(struct s_socket *so, int backlog);
00182 int tcp_send(struct s_socket *so, struct s_data_buf *data, size_t data_size, struct sockaddr *sa, socklen_t salen);
00183 int tcp_inetfs_read(pid_t pid, struct s_of *of, char *ubuf, size_t usize);
00184 #endif /* __INET__ */
00185 #endif

Generated on Wed May 24 23:05:52 2006 for LSE/OS by  doxygen 1.4.6