tcpconn.c (ssldump-0.9b3) | : | tcpconn.c (ssldump-1.3) | ||
---|---|---|---|---|
skipping to change at line 44 | skipping to change at line 44 | |||
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY SUCH DAMA GE. | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY SUCH DAMA GE. | |||
$Id: tcpconn.c,v 1.7 2002/08/17 01:33:16 ekr Exp $ | $Id: tcpconn.c,v 1.7 2002/08/17 01:33:16 ekr Exp $ | |||
ekr@rtfm.com Tue Dec 29 15:13:03 1998 | ekr@rtfm.com Tue Dec 29 15:13:03 1998 | |||
*/ | */ | |||
static char *RCSSTRING="$Id: tcpconn.c,v 1.7 2002/08/17 01:33:16 ekr Exp $"; | ||||
#include "network.h" | #include "network.h" | |||
#include "tcpconn.h" | #include "tcpconn.h" | |||
typedef struct conn_struct_ { | typedef struct conn_struct_ { | |||
tcp_conn conn; | tcp_conn conn; | |||
struct conn_struct_ *next; | struct conn_struct_ *next; | |||
struct conn_struct_ *prev; | struct conn_struct_ *prev; | |||
} conn_struct; | } conn_struct; | |||
int conn_number=1; | int conn_number=1; | |||
static conn_struct *first_conn=0; | static conn_struct *first_conn=0; | |||
extern struct timeval last_packet_seen_time; | ||||
extern int conn_ttl; | ||||
static int zero_conn PROTO_LIST((tcp_conn *conn)); | static int zero_conn PROTO_LIST((tcp_conn *conn)); | |||
static int zero_conn(conn) | static int zero_conn(conn) | |||
tcp_conn *conn; | tcp_conn *conn; | |||
{ | { | |||
memset(conn,0,sizeof(tcp_conn)); | memset(conn,0,sizeof(tcp_conn)); | |||
return(0); | return(0); | |||
} | } | |||
int tcp_find_conn(connp,directionp,saddr,sport,daddr,dport) | int tcp_find_conn(tcp_conn **connp, int *directionp,struct in_addr *saddr, | |||
tcp_conn **connp; | u_short sport, struct in_addr *daddr, u_short dport) | |||
int *directionp; | ||||
struct in_addr *saddr; | ||||
u_short sport; | ||||
struct in_addr *daddr; | ||||
u_short dport; | ||||
{ | { | |||
conn_struct *conn; | conn_struct *conn; | |||
for(conn=first_conn;conn;conn=conn->next){ | for(conn=first_conn;conn;conn=conn->next){ | |||
if(sport == conn->conn.i_port && dport==conn->conn.r_port){ | if(sport == conn->conn.i_port && dport==conn->conn.r_port){ | |||
if(!memcmp(saddr,&conn->conn.i_addr,sizeof(struct in_addr)) | if(!memcmp(saddr,&conn->conn.i_addr,sizeof(struct in_addr)) | |||
&& !memcmp(daddr,&conn->conn.r_addr,sizeof(struct in_addr))) | && !memcmp(daddr,&conn->conn.r_addr,sizeof(struct in_addr))) | |||
{ | { | |||
*directionp=DIR_I2R; | *directionp=DIR_I2R; | |||
skipping to change at line 104 | skipping to change at line 100 | |||
*directionp=DIR_R2I; | *directionp=DIR_R2I; | |||
*connp=&(conn->conn); | *connp=&(conn->conn); | |||
return(0); | return(0); | |||
} | } | |||
} | } | |||
} | } | |||
return(R_NOT_FOUND); | return(R_NOT_FOUND); | |||
} | } | |||
int tcp_create_conn(connp,i_addr,i_port,r_addr,r_port) | int tcp_create_conn(tcp_conn **connp,struct in_addr *i_addr, | |||
tcp_conn **connp; | u_short i_port, struct in_addr *r_addr, u_short r_port) | |||
struct in_addr *i_addr; | ||||
u_short i_port; | ||||
struct in_addr *r_addr; | ||||
u_short r_port; | ||||
{ | { | |||
conn_struct *conn=0; | conn_struct *conn=0; | |||
if(!(conn=(conn_struct *)malloc(sizeof(conn_struct)))) | if(!(conn=(conn_struct *)malloc(sizeof(conn_struct)))) | |||
return(R_NO_MEMORY); | return(R_NO_MEMORY); | |||
conn->prev=0; | conn->prev=0; | |||
zero_conn(&conn->conn); | zero_conn(&conn->conn); | |||
conn->conn.backptr=conn; | conn->conn.backptr=conn; | |||
skipping to change at line 157 | skipping to change at line 149 | |||
c->prev->next=c->next; | c->prev->next=c->next; | |||
} | } | |||
else { | else { | |||
first_conn=c->next; | first_conn=c->next; | |||
} | } | |||
destroy_proto_handler(&conn->analyzer); | destroy_proto_handler(&conn->analyzer); | |||
free_tcp_segment_queue(conn->i2r.oo_queue); | free_tcp_segment_queue(conn->i2r.oo_queue); | |||
free_tcp_segment_queue(conn->r2i.oo_queue); | free_tcp_segment_queue(conn->r2i.oo_queue); | |||
zero_conn(conn); | zero_conn(conn); | |||
free(conn->backptr); | ||||
free(conn); | ||||
return(0); | return(0); | |||
} | } | |||
int clean_old_conn() { | ||||
conn_struct *conn; | ||||
tcp_conn *tcpconn; | ||||
struct timeval dt; | ||||
int i = 0; | ||||
if(!last_packet_seen_time.tv_sec) | ||||
return 0; // Still processing first block of packets | ||||
conn = first_conn; | ||||
while(conn) { | ||||
tcpconn = &conn->conn; | ||||
conn=conn->next; | ||||
if(timestamp_diff(&last_packet_seen_time, &tcpconn->last_seen_time, &dt) | ||||
) | ||||
continue; | ||||
if(dt.tv_sec > conn_ttl) { | ||||
i++; | ||||
tcp_destroy_conn(tcpconn); | ||||
} | ||||
} | ||||
return i; | ||||
} | ||||
int destroy_all_conn() { | ||||
int i = 0; | ||||
while(first_conn) { | ||||
i++; | ||||
tcp_destroy_conn(&first_conn->conn); | ||||
} | ||||
return i; | ||||
} | ||||
int free_tcp_segment_queue(seg) | int free_tcp_segment_queue(seg) | |||
segment *seg; | segment *seg; | |||
{ | { | |||
segment *tmp; | segment *tmp; | |||
while(seg){ | while(seg){ | |||
tmp=seg->next; | tmp=seg->next; | |||
packet_destroy(seg->p); | packet_destroy(seg->p); | |||
free(seg); | free(seg); | |||
seg=tmp; | seg=tmp; | |||
skipping to change at line 184 | skipping to change at line 210 | |||
} | } | |||
int copy_tcp_segment_queue(out,in) | int copy_tcp_segment_queue(out,in) | |||
segment **out; | segment **out; | |||
segment *in; | segment *in; | |||
{ | { | |||
int r,_status; | int r,_status; | |||
segment *base=0; | segment *base=0; | |||
for(;in;in=in->next){ | for(;in;in=in->next){ | |||
if(!(*out=(segment *)calloc(sizeof(segment),1))) | if(!(*out=(segment *)calloc(1,sizeof(segment)))) | |||
ABORT(R_NO_MEMORY); | ABORT(R_NO_MEMORY); | |||
if(!base) base=*out; | if(!base) base=*out; | |||
if(r=packet_copy(in->p,&(*out)->p)) | if((r=packet_copy(in->p,&(*out)->p))) | |||
ABORT(r); | ABORT(r); | |||
out=&(*out)->next; /* Move the pointer we're assigning to */ | out=&(*out)->next; /* Move the pointer we're assigning to */ | |||
} | } | |||
_status=0; | _status=0; | |||
abort: | abort: | |||
if(_status){ | if(_status){ | |||
free_tcp_segment_queue(base); | free_tcp_segment_queue(base); | |||
} | } | |||
return(_status); | return(_status); | |||
End of changes. 8 change blocks. | ||||
17 lines changed or deleted | 44 lines changed or added |