00001
00002
00003
00004
00005
00006
00007 #ifndef TCP_INT_H
00008 #define TCP_INT_H
00009
00010 #define IP_TCP_MIN_HDR_SIZE (IP_MIN_HDR_SIZE+TCP_MIN_HDR_SIZE)
00011
00012 #define TCP_CONN_HASH_SHIFT 4
00013 #define TCP_CONN_HASH_NR (1 << TCP_CONN_HASH_SHIFT)
00014
00015 typedef struct tcp_port
00016 {
00017 int tp_ipdev;
00018 int tp_flags;
00019 int tp_state;
00020 int tp_ipfd;
00021 acc_t *tp_pack;
00022 ipaddr_t tp_ipaddr;
00023 ipaddr_t tp_subnetmask;
00024 u16_t tp_mtu;
00025 struct tcp_conn *tp_snd_head;
00026 struct tcp_conn *tp_snd_tail;
00027 event_t tp_snd_event;
00028 struct tcp_conn *tp_conn_hash[TCP_CONN_HASH_NR][4];
00029 } tcp_port_t;
00030
00031 #define TPF_EMPTY 0x0
00032 #define TPF_SUSPEND 0x1
00033 #define TPF_READ_IP 0x2
00034 #define TPF_READ_SP 0x4
00035 #define TPF_WRITE_IP 0x8
00036 #define TPF_WRITE_SP 0x10
00037 #define TPF_DELAY_TCP 0x40
00038
00039 #define TPS_EMPTY 0
00040 #define TPS_SETPROTO 1
00041 #define TPS_GETCONF 2
00042 #define TPS_MAIN 3
00043 #define TPS_ERROR 4
00044
00045 #define TFL_LISTEN_MAX 5
00046
00047 typedef struct tcp_fd
00048 {
00049 unsigned long tf_flags;
00050 tcp_port_t *tf_port;
00051 int tf_srfd;
00052 ioreq_t tf_ioreq;
00053 nwio_tcpconf_t tf_tcpconf;
00054 nwio_tcpopt_t tf_tcpopt;
00055 get_userdata_t tf_get_userdata;
00056 put_userdata_t tf_put_userdata;
00057 select_res_t tf_select_res;
00058 struct tcp_conn *tf_conn;
00059 struct tcp_conn *tf_listenq[TFL_LISTEN_MAX];
00060 size_t tf_write_offset;
00061 size_t tf_write_count;
00062 size_t tf_read_offset;
00063 size_t tf_read_count;
00064 int tf_error;
00065 tcp_cookie_t tf_cookie;
00066 } tcp_fd_t;
00067
00068 #define TFF_EMPTY 0x0
00069 #define TFF_INUSE 0x1
00070 #define TFF_READ_IP 0x2
00071 #define TFF_WRITE_IP 0x4
00072 #define TFF_IOCTL_IP 0x8
00073 #define TFF_CONF_SET 0x10
00074 #define TFF_IOC_INIT_SP 0x20
00075 #define TFF_LISTENQ 0x40
00076 #define TFF_CONNECTING 0x80
00077 #define TFF_CONNECTED 0x100
00078 #define TFF_WR_URG 0x200
00079 #define TFF_PUSH_DATA 0x400
00080 #define TFF_RECV_URG 0x800
00081 #define TFF_SEL_READ 0x1000
00082 #define TFF_SEL_WRITE 0x2000
00083 #define TFF_SEL_EXCEPT 0x4000
00084 #define TFF_DEL_RST 0x8000
00085 #define TFF_COOKIE 0x10000
00086
00087 typedef struct tcp_conn
00088 {
00089 int tc_flags;
00090 int tc_state;
00091 int tc_busy;
00092
00093
00094 tcp_port_t *tc_port;
00095 tcp_fd_t *tc_fd;
00096
00097 tcpport_t tc_locport;
00098 ipaddr_t tc_locaddr;
00099 tcpport_t tc_remport;
00100 ipaddr_t tc_remaddr;
00101
00102 int tc_connInprogress;
00103 int tc_orglisten;
00104 clock_t tc_senddis;
00105
00106
00107 u32_t tc_ISS;
00108 u32_t tc_SND_UNA;
00109 u32_t tc_SND_TRM;
00110 u32_t tc_SND_NXT;
00111 u32_t tc_SND_UP;
00112
00113 u32_t tc_SND_PSH;
00114
00115
00116 u32_t tc_snd_cwnd;
00117 u32_t tc_snd_cthresh;
00118 u32_t tc_snd_cinc;
00119 u16_t tc_snd_wnd;
00120 u16_t tc_snd_dack;
00121
00122
00123 clock_t tc_rt_time;
00124 u32_t tc_rt_seq;
00125 u32_t tc_rt_threshold;
00126 clock_t tc_artt;
00127 clock_t tc_drtt;
00128 clock_t tc_rtt;
00129
00130 acc_t *tc_send_data;
00131 acc_t *tc_frag2send;
00132 struct tcp_conn *tc_send_link;
00133
00134
00135 u32_t tc_IRS;
00136 u32_t tc_RCV_LO;
00137 u32_t tc_RCV_NXT;
00138 u32_t tc_RCV_HI;
00139 u32_t tc_RCV_UP;
00140
00141 u16_t tc_rcv_wnd;
00142 acc_t *tc_rcvd_data;
00143 acc_t *tc_adv_data;
00144 u32_t tc_adv_seq;
00145
00146
00147
00148
00149
00150
00151 u32_t tc_ka_snd;
00152 u32_t tc_ka_rcv;
00153 clock_t tc_ka_time;
00154
00155 acc_t *tc_remipopt;
00156 acc_t *tc_tcpopt;
00157 u8_t tc_tos;
00158 u8_t tc_ttl;
00159 u16_t tc_max_mtu;
00160 u16_t tc_mtu;
00161 clock_t tc_mtutim;
00162
00163 struct timer tc_transmit_timer;
00164 u32_t tc_transmit_seq;
00165 clock_t tc_0wnd_to;
00166 clock_t tc_stt;
00167 clock_t tc_rt_dead;
00168
00169 int tc_error;
00170 int tc_inconsistent;
00171 } tcp_conn_t;
00172
00173 #define TCF_EMPTY 0x0
00174 #define TCF_INUSE 0x1
00175 #define TCF_FIN_RECV 0x2
00176 #define TCF_RCV_PUSH 0x4
00177 #define TCF_MORE2WRITE 0x8
00178 #define TCF_SEND_ACK 0x10
00179 #define TCF_FIN_SENT 0x20
00180 #define TCF_BSD_URG 0x40
00181 #define TCF_NO_PUSH 0x80
00182 #define TCF_PUSH_NOW 0x100
00183 #define TCF_PMTU 0x200
00184
00185 #if DEBUG & 0x200
00186 #define TCF_DEBUG 0x1000
00187 #endif
00188
00189 #define TCS_CLOSED 0
00190 #define TCS_LISTEN 1
00191 #define TCS_SYN_RECEIVED 2
00192 #define TCS_SYN_SENT 3
00193 #define TCS_ESTABLISHED 4
00194 #define TCS_CLOSING 5
00195
00196
00197 void tcp_frag2conn ARGS(( tcp_conn_t *tcp_conn, ip_hdr_t *ip_hdr,
00198 tcp_hdr_t *tcp_hdr, acc_t *tcp_data, size_t data_len ));
00199 void tcp_fd_read ARGS(( tcp_conn_t *tcp_conn, int enq ));
00200 unsigned tcp_sel_read ARGS(( tcp_conn_t *tcp_conn ));
00201 void tcp_rsel_read ARGS(( tcp_conn_t *tcp_conn ));
00202 void tcp_bytesavailable ARGS(( tcp_fd_t *tcp_fd, int *bytesp ));
00203
00204
00205 void tcp_conn_write ARGS(( tcp_conn_t *tcp_conn, int enq ));
00206 void tcp_release_retrans ARGS(( tcp_conn_t *tcp_conn, u32_t seg_ack,
00207 U16_t new_win ));
00208 void tcp_fast_retrans ARGS(( tcp_conn_t *tcp_conn ));
00209 void tcp_set_send_timer ARGS(( tcp_conn_t *tcp_conn ));
00210 void tcp_fd_write ARGS(( tcp_conn_t *tcp_conn ));
00211 unsigned tcp_sel_write ARGS(( tcp_conn_t *tcp_conn ));
00212 void tcp_rsel_write ARGS(( tcp_conn_t *tcp_conn ));
00213 void tcp_close_connection ARGS(( tcp_conn_t *tcp_conn,
00214 int error ));
00215 void tcp_port_write ARGS(( tcp_port_t *tcp_port ));
00216 void tcp_shutdown ARGS(( tcp_conn_t *tcp_conn ));
00217
00218
00219 void tcp_extract_ipopt ARGS(( tcp_conn_t *tcp_conn,
00220 ip_hdr_t *ip_hdr ));
00221 void tcp_extract_tcpopt ARGS(( tcp_conn_t *tcp_conn,
00222 tcp_hdr_t *tcp_hdr, size_t *mssp ));
00223 void tcp_get_ipopt ARGS(( tcp_conn_t *tcp_conn, ip_hdropt_t
00224 *ip_hdropt ));
00225 void tcp_get_tcpopt ARGS(( tcp_conn_t *tcp_conn, tcp_hdropt_t
00226 *tcp_hdropt ));
00227 acc_t *tcp_make_header ARGS(( tcp_conn_t *tcp_conn,
00228 ip_hdr_t **ref_ip_hdr, tcp_hdr_t **ref_tcp_hdr, acc_t *data ));
00229 u16_t tcp_pack_oneCsum ARGS(( ip_hdr_t *ip_hdr, acc_t *tcp_pack ));
00230 int tcp_check_conn ARGS(( tcp_conn_t *tcp_conn ));
00231 void tcp_print_pack ARGS(( ip_hdr_t *ip_hdr, tcp_hdr_t *tcp_hdr ));
00232 void tcp_print_state ARGS(( tcp_conn_t *tcp_conn ));
00233 void tcp_print_conn ARGS(( tcp_conn_t *tcp_conn ));
00234 int tcp_LEmod4G ARGS(( u32_t n1, u32_t n2 ));
00235 int tcp_Lmod4G ARGS(( u32_t n1, u32_t n2 ));
00236 int tcp_GEmod4G ARGS(( u32_t n1, u32_t n2 ));
00237 int tcp_Gmod4G ARGS(( u32_t n1, u32_t n2 ));
00238
00239
00240 void tcp_restart_connect ARGS(( tcp_conn_t *tcp_conn ));
00241 int tcp_su4listen ARGS(( tcp_fd_t *tcp_fd, tcp_conn_t *tcp_conn,
00242 int do_listenq ));
00243 void tcp_reply_ioctl ARGS(( tcp_fd_t *tcp_fd, int reply ));
00244 void tcp_reply_write ARGS(( tcp_fd_t *tcp_fd, size_t reply ));
00245 void tcp_reply_read ARGS(( tcp_fd_t *tcp_fd, size_t reply ));
00246 void tcp_notreach ARGS(( tcp_conn_t *tcp_conn, int error ));
00247 void tcp_mtu_exceeded ARGS(( tcp_conn_t *tcp_conn ));
00248 void tcp_mtu_incr ARGS(( tcp_conn_t *tcp_conn ));
00249
00250 #define TCP_FD_NR (10*IP_PORT_MAX)
00251 #define TCP_CONN_NR (2*TCP_FD_NR)
00252
00253 EXTERN tcp_port_t *tcp_port_table;
00254 EXTERN tcp_conn_t tcp_conn_table[TCP_CONN_NR];
00255 EXTERN tcp_fd_t tcp_fd_table[TCP_FD_NR];
00256
00257 #define tcp_Lmod4G(n1,n2) (!!(((n1)-(n2)) & 0x80000000L))
00258 #define tcp_GEmod4G(n1,n2) (!(((n1)-(n2)) & 0x80000000L))
00259 #define tcp_Gmod4G(n1,n2) (!!(((n2)-(n1)) & 0x80000000L))
00260 #define tcp_LEmod4G(n1,n2) (!(((n2)-(n1)) & 0x80000000L))
00261
00262 #endif
00263
00264
00265
00266