Skip to content

Commit

Permalink
v1.0.104.3; changed behavior of accept/backlog to correct method (act…
Browse files Browse the repository at this point in the history
…ive opening on listen); removed start up of accept thread in TCP when get accept() from Daemon; changed conn_stub to a conn & merged conn_stub_list_sem into conn_list_sem; patched some memory leaks
  • Loading branch information
Jonathan Reed committed Aug 6, 2013
1 parent 6b1ba28 commit d8970a0
Show file tree
Hide file tree
Showing 14 changed files with 707 additions and 1,005 deletions.
2 changes: 2 additions & 0 deletions tests/speed_tcp_server.c
Expand Up @@ -147,6 +147,8 @@ int main(int argc, char *argv[]) {
printf("TCP Server waiting for client: port %d\n", ntohs(server_addr.sin_port));
fflush(stdout);

//fgetc(stdin); //wait until user enters

while (1) {
sock_client = accept(sock, (struct sockaddr *) &client_addr, (socklen_t *) &addr_len);
if (sock_client > 0) {
Expand Down
2 changes: 1 addition & 1 deletion trunk/libs/common/finsdebug.h
Expand Up @@ -12,7 +12,7 @@
#ifndef FINSDEBUG_H_
#define FINSDEBUG_H_

//#define DEBUG
#define DEBUG
#define INFO
#define WARN
#define IMPORTANT
Expand Down
10 changes: 10 additions & 0 deletions trunk/libs/common/finstypes.c
Expand Up @@ -1911,3 +1911,13 @@ struct route_record *route_clone(struct route_record *route) {
PRINT_DEBUG("Exited: route=%p, ret=%p", route, route_clone);
return route_clone;
}

/**
* @brief generate a random integer between min and max
* @param minimum value of the range, maximum value of the range
* @return the random integer value
*
*/
int randoming(int min, int max) {
return (min + (int) (max - min + 1) * (rand() / (RAND_MAX + 1.0)));
}
2 changes: 2 additions & 0 deletions trunk/libs/common/finstypes.h
Expand Up @@ -502,4 +502,6 @@ struct envi_record {
//struct linked_list *foward_list; //TODO add in forwarding table?
};

int randoming(int min, int max);

#endif /* FINSTYPES_H_ */
2 changes: 0 additions & 2 deletions trunk/modules/arp/arp.c
Expand Up @@ -175,8 +175,6 @@ void arp_cache_shutdown(struct arp_cache *cache) {
//stop threads
timer_stop(cache->to_data->tid);

//clear all threads using this conn_stub

//post to read/write/connect/etc threads
}

Expand Down
19 changes: 5 additions & 14 deletions trunk/modules/daemon/daemon.c
Expand Up @@ -162,8 +162,6 @@ void daemon_calls_shutdown(struct fins_module *module, int call_index) {
timer_delete(md->calls[call_index].to_data->tid);
free(md->calls[call_index].to_data);

//clear all threads using this conn_stub

PRINT_DEBUG("");
//post to read/write/connect/etc threads
//pthread_join(daemon_calls[call_index].to_thread, NULL);
Expand Down Expand Up @@ -306,17 +304,6 @@ int daemon_sockets_remove(struct fins_module *module, int sock_index) {
return 1;
}

/**
* @brief generate a random integer between min and max
* @param minimum value of the range, maximum value of the range
* @return the random integer value
*
*/

int daemon_randoming(int min, int max) {
return (min + (int) (max - min + 1) * (rand() / (RAND_MAX + 1.0)));
}

uint32_t daemon_fcf_to_switch(struct fins_module *module, uint32_t flow, metadata *meta, uint32_t serial_num, uint16_t opcode, uint32_t param_id) {
PRINT_DEBUG("Entered: module_id=%d, meta=%p, serial_num=%u, opcode=%u, param_id=%u", flow, meta, serial_num, opcode, param_id);

Expand Down Expand Up @@ -541,13 +528,15 @@ void daemon_alert(struct fins_module *module, struct finsFrame *ff) {
case IPPROTO_ICMP:
//daemon_in_poll_icmp(module, ff, ret_msg);
PRINT_WARN("todo");
freeFinsFrame(ff);
break;
case IPPROTO_TCP:
daemon_in_poll_tcp(module, ff, ret_msg);
break;
case IPPROTO_UDP:
//daemon_in_poll_udp(module, ff, ret_msg);
PRINT_WARN("todo");
freeFinsFrame(ff);
break;
default:
PRINT_ERROR("Unknown protocol, protocol=%u", protocol);
Expand All @@ -572,13 +561,15 @@ void daemon_alert(struct fins_module *module, struct finsFrame *ff) {
case IPPROTO_ICMP:
//daemon_in_shutdown_icmp(module, ff, ret_msg);
PRINT_WARN("todo");
freeFinsFrame(ff);
break;
case IPPROTO_TCP:
daemon_in_shutdown_tcp(module, ff, ret_msg);
break;
case IPPROTO_UDP:
//daemon_in_shutdown_udp(module, ff, ret_msg);
PRINT_WARN("todo");
freeFinsFrame(ff);
break;
default:
PRINT_ERROR("Unknown protocol, protocol=%u", protocol);
Expand Down Expand Up @@ -1070,7 +1061,7 @@ void *wedge_to_daemon(void *local) {
fds[0].fd = md->nl_sockfd;
fds[0].events = POLLIN | POLLRDNORM | POLLPRI | POLLRDBAND; //| POLLERR;
//fds[0].events = POLLIN | POLLPRI | POLLOUT | POLLERR | POLLHUP | POLLNVAL | POLLRDNORM | POLLRDBAND | POLLWRNORM | POLLWRBAND;
PRINT_DEBUG("fd: sock=%d, events=%x", md->nl_sockfd, fds[0].events);
PRINT_DEBUG("fd: sock=%d, events=0x%x", md->nl_sockfd, fds[0].events);
int time = 1000;

uint8_t *recv_buf = (uint8_t *) secure_malloc(RECV_BUFFER_SIZE + 16); //16 = NLMSGHDR size
Expand Down
2 changes: 0 additions & 2 deletions trunk/modules/daemon/daemon_internal.h
Expand Up @@ -340,8 +340,6 @@ int daemon_sockets_find(struct fins_module *module, uint64_t sock_id);
int daemon_sockets_check_addr6(struct fins_module *module, struct sockaddr_storage *addr, int protocol);
int daemon_sockets_remove(struct fins_module *module, int sock_index);

int daemon_randoming(int min, int max);

//TODO fix the usage of these
uint32_t daemon_fcf_to_switch(struct fins_module *module, uint32_t flow, metadata *meta, uint32_t serial_num, uint16_t opcode, uint32_t param_id);
uint32_t daemon_fdf_to_switch(struct fins_module *module, uint32_t flow, uint32_t data_len, uint8_t *data, metadata *meta);
Expand Down
14 changes: 12 additions & 2 deletions trunk/modules/daemon/tcpHandling.c
Expand Up @@ -276,7 +276,7 @@ void connect_out_tcp(struct fins_module *module, struct wedge_to_daemon_hdr *hdr
* /proc/sys/net/ipv4/ip_local_port_range default range in Ubuntu is 32768 - 61000
*/
while (1) {
host_port = (uint16_t) daemon_randoming(MIN_port, MAX_port);
host_port = (uint16_t) randoming(MIN_port, MAX_port);
if (match_host_addr4_tcp(module, host_ip, host_port) == -1) {
break;
}
Expand Down Expand Up @@ -709,7 +709,7 @@ void sendmsg_out_tcp(struct fins_module *module, struct wedge_to_daemon_hdr *hdr
* /proc/sys/net/ipv4/ip_local_port_range default range in Ubuntu is 32768 - 61000
*/
while (1) {
host_port = (uint16_t) daemon_randoming(MIN_port, MAX_port);
host_port = (uint16_t) randoming(MIN_port, MAX_port);
if (match_host_addr4_tcp(module, host_ip, (uint16_t) host_port) == -1) {
break;
}
Expand Down Expand Up @@ -1806,6 +1806,7 @@ void connect_in_tcp(struct fins_module *module, struct finsFrame *ff, struct dae
if (ff->ctrlFrame.param_id != DAEMON_EXEC_TCP_CONNECT) {
PRINT_ERROR("Exiting, param_id errors: ff=%p, param_id=%d, ret_val=%d", ff, ff->ctrlFrame.param_id, ff->ctrlFrame.ret_val);
nack_send(module, call->id, call->index, call->type, 1);
daemon_call_free(call);
freeFinsFrame(ff);
return;
}
Expand All @@ -1831,6 +1832,7 @@ void connect_in_tcp(struct fins_module *module, struct finsFrame *ff, struct dae
nack_send(module, call->id, call->index, call->type, ECONNREFUSED); //TODO change based off of timeout, refused etc
}

daemon_call_free(call);
freeFinsFrame(ff);
}

Expand All @@ -1842,6 +1844,7 @@ void accept_in_tcp(struct fins_module *module, struct finsFrame *ff, struct daem
if (ff->ctrlFrame.param_id != DAEMON_EXEC_TCP_ACCEPT) {
PRINT_ERROR("Exiting, param_id errors: ff=%p, param_id=%d, ret_val=%d", ff, ff->ctrlFrame.param_id, ff->ctrlFrame.ret_val);
nack_send(module, call->id, call->index, call->type, 1);
daemon_call_free(call);
freeFinsFrame(ff);
return;
}
Expand Down Expand Up @@ -1896,6 +1899,7 @@ void accept_in_tcp(struct fins_module *module, struct finsFrame *ff, struct daem
nack_send(module, call->id, call->index, call->type, ECONNREFUSED); //TODO change based off of timeout, refused etc
}

daemon_call_free(call);
freeFinsFrame(ff);
}

Expand All @@ -1906,6 +1910,7 @@ void sendmsg_in_tcp(struct fins_module *module, struct finsFrame *ff, struct dae
if (ff->ctrlFrame.param_id != DAEMON_EXEC_TCP_SEND) {
PRINT_ERROR("Exiting, param_id errors: ff=%p, param_id=%d, ret_val=%d", ff, ff->ctrlFrame.param_id, ff->ctrlFrame.ret_val);
nack_send(module, call->id, call->index, call->type, 1);
daemon_call_free(call);
freeFinsFrame(ff);
return;
}
Expand All @@ -1919,6 +1924,7 @@ void sendmsg_in_tcp(struct fins_module *module, struct finsFrame *ff, struct dae
nack_send(module, call->id, call->index, call->type, ret_msg);
}

daemon_call_free(call);
freeFinsFrame(ff);
}

Expand Down Expand Up @@ -2381,6 +2387,8 @@ void daemon_in_poll_tcp(struct fins_module *module, struct finsFrame *ff, uint32
PRINT_DEBUG("sock_id=%llu, sock_index=%d, state=%u, host=%u:%u, rem=%u:%u",
md->sockets[sock_index].sock_id, sock_index, md->sockets[sock_index].state, addr4_get_ip(&md->sockets[sock_index].host_addr), addr4_get_port(&md->sockets[sock_index].host_addr), addr4_get_ip(&md->sockets[sock_index].rem_addr), addr4_get_port(&md->sockets[sock_index].rem_addr));
list_for_each2(md->sockets[sock_index].call_list, poll_in_tcp_fdf, module, &ret_msg);

freeFinsFrame(ff);
}

void daemon_in_shutdown_tcp(struct fins_module *module, struct finsFrame *ff, uint32_t ret_msg) {
Expand Down Expand Up @@ -2448,6 +2456,8 @@ void daemon_in_shutdown_tcp(struct fins_module *module, struct finsFrame *ff, ui
}
}
}

freeFinsFrame(ff);
}

void connect_timeout_tcp(struct fins_module *module, struct daemon_call *call) {
Expand Down
4 changes: 2 additions & 2 deletions trunk/modules/daemon/udpHandling.c
Expand Up @@ -166,7 +166,7 @@ void connect_out_udp(struct fins_module *module, struct wedge_to_daemon_hdr *hdr
* /proc/sys/net/ipv4/ip_local_port_range default range in Ubuntu is 32768 - 61000
*/
while (1) {
host_port = (uint16_t) daemon_randoming(MIN_port, MAX_port);
host_port = (uint16_t) randoming(MIN_port, MAX_port);
if (match_host_addr4_udp(module, host_ip, host_port) == -1) {
break;
}
Expand Down Expand Up @@ -491,7 +491,7 @@ void sendmsg_out_udp(struct fins_module *module, struct wedge_to_daemon_hdr *hdr
* /proc/sys/net/ipv4/ip_local_port_range default range in Ubuntu is 32768 - 61000
*/
while (1) {
host_port = (uint16_t) daemon_randoming(MIN_port, MAX_port);
host_port = (uint16_t) randoming(MIN_port, MAX_port);
if (match_host_addr4_udp(module, host_ip, (uint16_t) host_port) == -1) {
break;
}
Expand Down
2 changes: 1 addition & 1 deletion trunk/modules/ipv4/IP4_next_hop.c
Expand Up @@ -14,7 +14,7 @@ struct ip4_next_hop_info IP4_next_hop(struct fins_module *module, uint32_t dst)
struct ip4_routing_table* current_table_entry = routing_table;
while (current_table_entry != NULL) {
//mask = (uint32_t)((0xffffffff << (8*IP4_ALEN - current_table_entry->mask)) & 0xffffffff);
PRINT_DEBUG("table->dst=%u, mask=%x, table=%x, dst=%x",
PRINT_DEBUG("table->dst=%u, mask=0x%x, table=0x%x, dst=0x%x",
current_table_entry->dst, current_table_entry->mask, current_table_entry->dst & current_table_entry->mask, dst & current_table_entry->mask);
if (((current_table_entry->dst & current_table_entry->mask) == (dst & current_table_entry->mask)) || (current_table_entry->dst == 0)) { //if dst=0, this is the default route, always match
if (current_table_entry->gw == 0) { //dst host in on our net, can be contacted directly
Expand Down

0 comments on commit d8970a0

Please sign in to comment.