Main Page | Class List | File List | Class Members | File Members

tcp.c File Reference

#include <stdio.h>
#include <string.h>
#include <netinet/in.h>
#include <linux/ip.h>
#include <linux/tcp.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <pthread.h>
#include <assert.h>
#include "misc.h"
#include "tcpproxy.h"
#include "scheduler.h"
#include "tcptimer.h"
#include "tcp.h"

Go to the source code of this file.

Functions

void init_tcp ()
void cleanup_tcp ()
int seq_cmp (unsigned a, unsigned b)
int allow_conn (Tpacket_data *pd)
unsigned get_queue_weight (Ttcp_cid *cid)
Ttcp_cballoc_tcp_cb (Tpacket_data *pd, Ttcp_cid *cid)
int dealloc_tcp_cb (Ttcp_cb *cb)
int valid_ack (Ttcp_cb *cb, Tpacket_data *pd)
unsigned short tcp_chksum (struct iphdr *ip)
int send_tcp_rst (Tpacket_data *pd)
int clamp_tcp_win (Tpacket_data *pd)
int tcp_data_size (Tpacket_data *pd)
int tcps_err (Ttcp_cb *cb, Tpacket_data *pd)
int tcps_new (Ttcp_cb *cb, Tpacket_data *pd)
int tcps_syn_sent (Ttcp_cb *cb, Tpacket_data *pd)
int tcps_syn_recv (Ttcp_cb *cb, Tpacket_data *pd)
int tcps_established (Ttcp_cb *cb, Tpacket_data *pd)
int tcps_fin_wait1 (Ttcp_cb *cb, Tpacket_data *pd)
int tcps_fin_wait2 (Ttcp_cb *cb, Tpacket_data *pd)
int tcps_time_wait (Ttcp_cb *cb, Tpacket_data *pd)
int tcps_closed (Ttcp_cb *cb, Tpacket_data *pd)
int tcps_close_wait (Ttcp_cb *cb, Tpacket_data *pd)
int tcps_last_ack (Ttcp_cb *cb, Tpacket_data *pd)
int tcps_closing (Ttcp_cb *cb, Tpacket_data *pd)
void tcp_timeout (void *ptr)
int handle_tcp (Tpacket_data *pd)

Variables

static unsigned win_clamp_size = TCP_WIN_CLAMP_SIZE
static Ttcp_cb tcp_tab [TCP_MAX_CONN]
static pthread_mutex_t tcp_tab_mut
int(* tcp_switch [TCPS_MAX_STATES])()


Function Documentation

Ttcp_cb* alloc_tcp_cb Tpacket_data pd,
Ttcp_cid cid
 

Definition at line 103 of file tcp.c.

References alloc_tcp_queue(), tcp_cb::cid, DPRINT, get_queue_weight(), tcp_cb::init, tcp_cb::out_queue, tcp_cb::state, TCP_MAX_CONN, TCPS_FREE, and TCPS_NEW.

Referenced by handle_tcp().

int allow_conn Tpacket_data pd  )  [inline]
 

Definition at line 76 of file tcp.c.

Referenced by handle_tcp().

int clamp_tcp_win Tpacket_data pd  ) 
 

Definition at line 283 of file tcp.c.

References packet_data::ip, tcp_chksum(), packet_data::trans, and win_clamp_size.

Referenced by handle_tcp().

void cleanup_tcp  ) 
 

Definition at line 52 of file tcp.c.

Referenced by main().

int dealloc_tcp_cb Ttcp_cb cb  ) 
 

Definition at line 141 of file tcp.c.

References close_tcp_queue(), DPRINT, tcp_cb::out_queue, tcp_cb::state, and TCPS_FREE.

Referenced by handle_tcp(), and tcp_timeout().

unsigned get_queue_weight Ttcp_cid cid  ) 
 

Definition at line 88 of file tcp.c.

References QUEUE_WEIGHT_HIGH, QUEUE_WEIGHT_NORMAL, and tcp_cid::sport.

Referenced by alloc_tcp_cb().

int handle_tcp Tpacket_data pd  ) 
 

Definition at line 668 of file tcp.c.

References alloc_tcp_cb(), allow_conn(), tcp_cb::cid, clamp_tcp_win(), clear_timer(), tcp_cid::daddr, dealloc_packet_data(), dealloc_tcp_cb(), packet_data::dir, tcp_cid::dport, DPRINT, tcp_cb::fh_ack, tcp_cb::fh_seq, tcp_cb::init, packet_data::ip, packet_data::ipq_pm, tcp_cb::mh_ack, mh_ack_rcvd(), tcp_cb::mh_seq, tcp_cb::mut, mutex_lock(), mutex_unlock(), tcp_cb::out_queue, PACKET_DIR_IN, queue_hipri(), queue_tcp(), reset_tcp_queue(), tcp_cid::saddr, send_tcp_rst(), seq_cmp(), tcp_cid::sport, tcp_cb::state, tcp_chksum(), tcp_data_size(), TCP_INIT_FH_ACK, TCP_INIT_FH_SEQ, TCP_INIT_MH_ACK, TCP_INIT_MH_SEQ, TCP_MAX_CONN, tcp_switch, tcp_tab_mut, tcp_timeout(), TCPS_CLOSED, TCPS_FREE, and packet_data::trans.

Referenced by handle_packet().

void init_tcp  ) 
 

Definition at line 34 of file tcp.c.

References tcp_cb::out_queue, tcp_cb::state, TCP_MAX_CONN, tcp_tab_mut, and TCPS_FREE.

Referenced by main().

int send_tcp_rst Tpacket_data pd  ) 
 

Definition at line 210 of file tcp.c.

References DPRINT, IP_START_TTL, IP_VERSION, PACKET_DIR_IN, PACKET_DIR_OUT, queue_hipri(), tcp_chksum(), TCP_PROTO, xfree(), and xmalloc().

Referenced by handle_tcp().

int seq_cmp unsigned  a,
unsigned  b
[inline]
 

Definition at line 66 of file tcp.c.

Referenced by add_tcp_sent(), handle_tcp(), and mh_ack_rcvd().

unsigned short tcp_chksum struct iphdr *  ip  ) 
 

Definition at line 163 of file tcp.c.

References TCP_PROTO.

Referenced by clamp_tcp_win(), handle_tcp(), and send_tcp_rst().

int tcp_data_size Tpacket_data pd  )  [inline]
 

Definition at line 305 of file tcp.c.

References packet_data::ip, packet_data::ipq_pm, and packet_data::trans.

Referenced by handle_tcp(), and scheduler().

void tcp_timeout void *  ptr  ) 
 

Definition at line 634 of file tcp.c.

References dealloc_tcp_cb(), DPRINT, EPRINT, tcp_cb::mut, mutex_lock(), mutex_unlock(), tcp_cb::state, TCPS_CLOSED, TCPS_LAST_ACK, TCPS_SYN_SENT, and TCPS_TIME_WAIT.

Referenced by clear_tcp_timers(), handle_tcp(), tcps_close_wait(), tcps_closing(), tcps_fin_wait1(), tcps_fin_wait2(), tcps_new(), and tcps_syn_sent().

int tcps_close_wait Ttcp_cb cb,
Tpacket_data pd
 

Definition at line 532 of file tcp.c.

References add_timer(), packet_data::dir, DPRINT, PACKET_DIR_IN, tcp_cb::state, tcp_timeout(), TCP_TWO_MSL, TCPS_CLOSING, TCPS_LAST_ACK, packet_data::trans, and valid_ack().

int tcps_closed Ttcp_cb cb,
Tpacket_data pd
 

Definition at line 516 of file tcp.c.

References packet_data::dir, EPRINT, PACKET_DIR_IN, and UNREACHABLE.

int tcps_closing Ttcp_cb cb,
Tpacket_data pd
 

Definition at line 591 of file tcp.c.

References add_timer(), packet_data::dir, DPRINT, PACKET_DIR_IN, tcp_cb::state, tcp_timeout(), TCP_TWO_MSL, TCPS_TIME_WAIT, packet_data::trans, and valid_ack().

int tcps_err Ttcp_cb cb,
Tpacket_data pd
 

Definition at line 321 of file tcp.c.

References EPRINT, and UNREACHABLE.

int tcps_established Ttcp_cb cb,
Tpacket_data pd
 

Definition at line 412 of file tcp.c.

References packet_data::dir, DPRINT, PACKET_DIR_IN, tcp_cb::state, TCPS_CLOSE_WAIT, TCPS_FIN_WAIT1, and packet_data::trans.

int tcps_fin_wait1 Ttcp_cb cb,
Tpacket_data pd
 

Definition at line 438 of file tcp.c.

References add_timer(), packet_data::dir, DPRINT, PACKET_DIR_IN, tcp_cb::state, tcp_timeout(), TCP_TWO_MSL, TCPS_CLOSING, TCPS_FIN_WAIT2, TCPS_TIME_WAIT, packet_data::trans, and valid_ack().

int tcps_fin_wait2 Ttcp_cb cb,
Tpacket_data pd
 

Definition at line 478 of file tcp.c.

References add_timer(), packet_data::dir, DPRINT, PACKET_DIR_IN, tcp_cb::state, tcp_timeout(), TCP_TWO_MSL, TCPS_TIME_WAIT, and packet_data::trans.

int tcps_last_ack Ttcp_cb cb,
Tpacket_data pd
 

Definition at line 565 of file tcp.c.

References packet_data::dir, DPRINT, PACKET_DIR_IN, tcp_cb::state, TCPS_CLOSED, packet_data::trans, and valid_ack().

int tcps_new Ttcp_cb cb,
Tpacket_data pd
 

Definition at line 331 of file tcp.c.

References add_timer(), packet_data::dir, DPRINT, PACKET_DIR_IN, tcp_cb::state, tcp_timeout(), TCP_TWO_MSL, TCPS_SYN_RECV, and TCPS_SYN_SENT.

int tcps_syn_recv Ttcp_cb cb,
Tpacket_data pd
 

Definition at line 381 of file tcp.c.

References packet_data::dir, DPRINT, PACKET_DIR_IN, tcp_cb::state, TCPS_ESTABLISHED, TCPS_FIN_WAIT1, packet_data::trans, and valid_ack().

int tcps_syn_sent Ttcp_cb cb,
Tpacket_data pd
 

Definition at line 349 of file tcp.c.

References clear_timer(), packet_data::dir, DPRINT, PACKET_DIR_IN, tcp_cb::state, tcp_timeout(), TCPS_ESTABLISHED, TCPS_SYN_RECV, packet_data::trans, and valid_ack().

int tcps_time_wait Ttcp_cb cb,
Tpacket_data pd
 

Definition at line 501 of file tcp.c.

References packet_data::dir, DPRINT, and PACKET_DIR_IN.

int valid_ack Ttcp_cb cb,
Tpacket_data pd
[inline]
 

Definition at line 149 of file tcp.c.

References packet_data::dir, tcp_cb::fh_seq, tcp_cb::mh_seq, PACKET_DIR_IN, and packet_data::trans.

Referenced by tcps_close_wait(), tcps_closing(), tcps_fin_wait1(), tcps_last_ack(), tcps_syn_recv(), and tcps_syn_sent().


Variable Documentation

int(* tcp_switch[TCPS_MAX_STATES])()
 

Initial value:

Definition at line 615 of file tcp.c.

Referenced by handle_tcp().

Ttcp_cb tcp_tab[TCP_MAX_CONN] [static]
 

Definition at line 27 of file tcp.c.

pthread_mutex_t tcp_tab_mut [static]
 

Definition at line 28 of file tcp.c.

Referenced by handle_tcp(), and init_tcp().

unsigned win_clamp_size = TCP_WIN_CLAMP_SIZE [static]
 

Definition at line 26 of file tcp.c.

Referenced by clamp_tcp_win().


Generated on Sun May 14 13:36:53 2006 by  doxygen 1.4.2