/* Initiate router table */ void router_init(size_t size) { #if (INTERCEPT_THREAD) pthread_mutex_init(&mutex, NULL); #endif delay_table_init(size); table = hash_create(size << 1); strcpy(table->name, "router-table"); tc_log_info(LOG_NOTICE, 0, "create %s, size:%u", table->name, table->size); }
/* Initiate for tcpcopy server */ void interception_init(uint16_t port) { delay_table_init(srv_settings.hash_size); router_init(srv_settings.hash_size << 1); select_server_set_callback(interception_process); msg_listen_sock = msg_server_init(srv_settings.binded_ip, port); log_info(LOG_NOTICE, "msg listen socket:%d", msg_listen_sock); select_server_add(msg_listen_sock); firewall_sock = nl_firewall_init(); log_info(LOG_NOTICE, "firewall socket:%d", firewall_sock); select_server_add(firewall_sock); }
/* initiate for tcpcopy server */ int interception_init(tc_event_loop_t *event_loop, char *ip, uint16_t port) { int fd; tc_event_t *ev; delay_table_init(srv_settings.hash_size); if (router_init() != TC_OK) { return TC_ERROR; } /* init the listening socket */ if ((fd = tc_socket_init()) == TC_INVALID_SOCKET) { return TC_ERROR; } else { if (tc_socket_listen(fd, ip, port) == TC_ERROR) { return TC_ERROR; } tc_log_info(LOG_NOTICE, 0, "msg listen socket:%d", fd); ev = tc_event_create(fd, tc_msg_event_accept, NULL); if (ev == NULL) { return TC_ERROR; } if (tc_event_add(event_loop, ev, TC_EVENT_READ) == TC_EVENT_ERROR) { return TC_ERROR; } } if (sniff_init(event_loop) != TC_OK) { return TC_ERROR; } return TC_OK; }
/* initiate for tcpcopy server */ int interception_init(tc_event_loop_t *event_loop, char *ip, uint16_t port) { int fd; tc_event_t *ev; #if (!TCPCOPY_SINGLE) delay_table_init(srv_settings.hash_size); if (router_init() != TC_OK) { return TC_ERROR; } #endif pid = getpid(); /* init the listening socket */ if ((fd = tc_socket_init()) == TC_INVALID_SOCKET) { return TC_ERROR; } else { if (tc_socket_listen(fd, ip, port) == TC_ERROR) { return TC_ERROR; } tc_log_info(LOG_NOTICE, 0, "msg listen socket:%d", fd); ev = tc_event_create(fd, tc_msg_event_accept, NULL); if (ev == NULL) { return TC_ERROR; } if (tc_event_add(event_loop, ev, TC_EVENT_READ) == TC_EVENT_ERROR) { return TC_ERROR; } } #if (INTERCEPT_NFQUEUE) /* init the nfq socket */ if ((fd = tc_nfq_socket_init(&srv_settings.nfq_handler, &srv_settings.nfq_q_handler, tc_nfq_process_packet)) == TC_INVALID_SOCKET) { return TC_ERROR; } else { tc_log_info(LOG_NOTICE, 0, "nfq socket:%d", fd); ev = tc_event_create(fd, tc_nfq_event_process, NULL); if (ev == NULL) { return TC_ERROR; } if (tc_event_add(event_loop, ev, TC_EVENT_READ) == TC_EVENT_ERROR) { return TC_ERROR; } } #else /* init the netlink socket */ if ((fd = tc_nl_socket_init()) == TC_INVALID_SOCKET) { return TC_ERROR; } else { tc_log_info(LOG_NOTICE, 0, "firewall socket:%d", fd); ev = tc_event_create(fd, tc_nl_event_process, NULL); if (ev == NULL) { return TC_ERROR; } if (tc_event_add(event_loop, ev, TC_EVENT_READ) == TC_EVENT_ERROR) { return TC_ERROR; } } #endif return TC_OK; }