Skip to content

Commit

Permalink
ctdb-system: Return window size and RST bit when reading TCP packets
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Schwenke <[email protected]>
Reviewed-by: Amitay Isaacs <[email protected]>
  • Loading branch information
martin-schwenke authored and Amitay Isaacs committed Apr 1, 2016
1 parent d7fa4b7 commit bba3115
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 20 deletions.
5 changes: 3 additions & 2 deletions ctdb/common/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ int ctdb_sys_send_tcp(const ctdb_sock_addr *dest,
int ctdb_sys_open_capture_socket(const char *iface, void **private_data);
int ctdb_sys_close_capture_socket(void *private_data);
int ctdb_sys_read_tcp_packet(int s, void *private_data,
ctdb_sock_addr *src, ctdb_sock_addr *dst,
uint32_t *ack_seq, uint32_t *seq);
ctdb_sock_addr *src, ctdb_sock_addr *dst,
uint32_t *ack_seq, uint32_t *seq,
int *rst, uint16_t *window);
bool ctdb_sys_check_iface_exists(const char *iface);
int ctdb_get_peer_pid(const int fd, pid_t *peer_pid);

Expand Down
20 changes: 16 additions & 4 deletions ctdb/common/system_aix.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,10 @@ static int aix_get_mac_addr(const char *device_name, uint8_t mac[6])
return -1;
}

int ctdb_sys_read_tcp_packet(int s, void *private_data,
ctdb_sock_addr *src, ctdb_sock_addr *dst,
uint32_t *ack_seq, uint32_t *seq)
int ctdb_sys_read_tcp_packet(int s, void *private_data,
ctdb_sock_addr *src, ctdb_sock_addr *dst,
uint32_t *ack_seq, uint32_t *seq,
int *rst, uint16_t *window)
{
int ret;
struct ether_header *eth;
Expand Down Expand Up @@ -326,7 +327,12 @@ int ctdb_sys_read_tcp_packet(int s, void *private_data,
dst->ip.sin_port = tcp->th_dport;
*ack_seq = tcp->th_ack;
*seq = tcp->th_seq;

if (window != NULL) {
*window = tcp->th_win;
}
if (rst != NULL) {
*rst = tcp->th_flags & TH_RST;
}

return 0;
#ifndef ETHERTYPE_IP6
Expand Down Expand Up @@ -355,6 +361,12 @@ int ctdb_sys_read_tcp_packet(int s, void *private_data,

*ack_seq = tcp->th_ack;
*seq = tcp->th_seq;
if (window != NULL) {
*window = tcp->th_win;
}
if (rst != NULL) {
*rst = tcp->th_flags & TH_RST;
}

return 0;
}
Expand Down
17 changes: 15 additions & 2 deletions ctdb/common/system_freebsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,9 @@ int ctdb_sys_close_capture_socket(void *private_data)
called when the raw socket becomes readable
*/
int ctdb_sys_read_tcp_packet(int s, void *private_data,
ctdb_sock_addr *src, ctdb_sock_addr *dst,
uint32_t *ack_seq, uint32_t *seq)
ctdb_sock_addr *src, ctdb_sock_addr *dst,
uint32_t *ack_seq, uint32_t *seq,
int *rst, uint16_t *window)
{
int ret;
#define RCVPKTSIZE 100
Expand Down Expand Up @@ -332,6 +333,12 @@ int ctdb_sys_read_tcp_packet(int s, void *private_data,
dst->ip.sin_port = tcp->th_dport;
*ack_seq = tcp->th_ack;
*seq = tcp->th_seq;
if (window != NULL) {
*window = tcp->th_win;
}
if (rst != NULL) {
*rst = tcp->th_flags & TH_RST;
}

return 0;
} else if (ntohs(eth->ether_type) == ETHERTYPE_IP6) {
Expand All @@ -357,6 +364,12 @@ int ctdb_sys_read_tcp_packet(int s, void *private_data,

*ack_seq = tcp->th_ack;
*seq = tcp->th_seq;
if (window != NULL) {
*window = tcp->th_win;
}
if (rst != NULL) {
*rst = tcp->th_flags & TH_RST;
}

return 0;
}
Expand Down
19 changes: 16 additions & 3 deletions ctdb/common/system_gnu.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,10 @@ int ctdb_sys_close_capture_socket(void *private_data)
/*
called when the raw socket becomes readable
*/
int ctdb_sys_read_tcp_packet(int s, void *private_data,
ctdb_sock_addr *src, ctdb_sock_addr *dst,
uint32_t *ack_seq, uint32_t *seq)
int ctdb_sys_read_tcp_packet(int s, void *private_data,
ctdb_sock_addr *src, ctdb_sock_addr *dst,
uint32_t *ack_seq, uint32_t *seq,
int *rst, uint16_t *window)
{
int ret;
#define RCVPKTSIZE 100
Expand Down Expand Up @@ -325,6 +326,12 @@ int ctdb_sys_read_tcp_packet(int s, void *private_data,
dst->ip.sin_port = tcp->dest;
*ack_seq = tcp->ack_seq;
*seq = tcp->seq;
if (window != NULL) {
*window = tcp->window;
}
if (rst != NULL) {
*rst = tcp->rst;
}

return 0;
} else if (ntohs(eth->ether_type) == ETHERTYPE_IP6) {
Expand All @@ -350,6 +357,12 @@ int ctdb_sys_read_tcp_packet(int s, void *private_data,

*ack_seq = tcp->ack_seq;
*seq = tcp->seq;
if (window != NULL) {
*window = tcp->window;
}
if (rst != NULL) {
*rst = tcp->rst;
}

return 0;
}
Expand Down
19 changes: 16 additions & 3 deletions ctdb/common/system_kfreebsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,10 @@ int ctdb_sys_close_capture_socket(void *private_data)
/*
called when the raw socket becomes readable
*/
int ctdb_sys_read_tcp_packet(int s, void *private_data,
ctdb_sock_addr *src, ctdb_sock_addr *dst,
uint32_t *ack_seq, uint32_t *seq)
int ctdb_sys_read_tcp_packet(int s, void *private_data,
ctdb_sock_addr *src, ctdb_sock_addr *dst,
uint32_t *ack_seq, uint32_t *seq,
int *rst, uint16_t *window)
{
int ret;
#define RCVPKTSIZE 100
Expand Down Expand Up @@ -325,6 +326,12 @@ int ctdb_sys_read_tcp_packet(int s, void *private_data,
dst->ip.sin_port = tcp->dest;
*ack_seq = tcp->ack_seq;
*seq = tcp->seq;
if (window != NULL) {
*window = tcp->window;
}
if (rst != NULL) {
*rst = tcp->rst;
}

return 0;
} else if (ntohs(eth->ether_type) == ETHERTYPE_IP6) {
Expand All @@ -350,6 +357,12 @@ int ctdb_sys_read_tcp_packet(int s, void *private_data,

*ack_seq = tcp->ack_seq;
*seq = tcp->seq;
if (window != NULL) {
*window = tcp->window;
}
if (rst != NULL) {
*rst = tcp->rst;
}

return 0;
}
Expand Down
19 changes: 16 additions & 3 deletions ctdb/common/system_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,10 @@ int ctdb_sys_close_capture_socket(void *private_data)
/*
called when the raw socket becomes readable
*/
int ctdb_sys_read_tcp_packet(int s, void *private_data,
ctdb_sock_addr *src, ctdb_sock_addr *dst,
uint32_t *ack_seq, uint32_t *seq)
int ctdb_sys_read_tcp_packet(int s, void *private_data,
ctdb_sock_addr *src, ctdb_sock_addr *dst,
uint32_t *ack_seq, uint32_t *seq,
int *rst, uint16_t *window)
{
int ret;
#define RCVPKTSIZE 100
Expand Down Expand Up @@ -543,6 +544,12 @@ int ctdb_sys_read_tcp_packet(int s, void *private_data,
dst->ip.sin_port = tcp->dest;
*ack_seq = tcp->ack_seq;
*seq = tcp->seq;
if (window != NULL) {
*window = tcp->window;
}
if (rst != NULL) {
*rst = tcp->rst;
}

return 0;
} else if (ntohs(eth->ether_type) == ETHERTYPE_IP6) {
Expand All @@ -568,6 +575,12 @@ int ctdb_sys_read_tcp_packet(int s, void *private_data,

*ack_seq = tcp->ack_seq;
*seq = tcp->seq;
if (window != NULL) {
*window = tcp->window;
}
if (rst != NULL) {
*rst = tcp->rst;
}

return 0;
}
Expand Down
8 changes: 5 additions & 3 deletions ctdb/tools/ctdb_killtcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,13 @@ static void capture_tcp_handler(struct tevent_context *ev,
struct ctdb_killtcp_con *con;
ctdb_sock_addr src, dst;
uint32_t ack_seq, seq;
int rst;
uint16_t window;

if (ctdb_sys_read_tcp_packet(killtcp->capture_fd,
killtcp->private_data,
&src, &dst,
&ack_seq, &seq) != 0) {
killtcp->private_data,
&src, &dst,
&ack_seq, &seq, &rst, &window) != 0) {
/* probably a non-tcp ACK packet */
return;
}
Expand Down

0 comments on commit bba3115

Please sign in to comment.