int router_has_router(router_list_t *list, uint16_t vlan_id, struct in6_addr lla, struct ether_addr eth) { if (router_get(list, vlan_id, lla, eth)==NULL) { return 0; } return 1; }
void router_update(int old, int main_router_fd, tc_ip_header_t *ip_header) { #if (!TCPCOPY_SINGLE) int fd; uint32_t key; #endif uint32_t size_ip, size_tcp, tot_len; msg_server_t msg; tc_tcp_header_t *tcp_header; #if (TCPCOPY_MYSQL_ADVANCED) uint32_t cont_len; unsigned char *payload, *p; #endif #if (TCPCOPY_SINGLE) if (main_router_fd == 0) { return; } #endif if (ip_header->protocol != IPPROTO_TCP) { tc_log_info(LOG_INFO, 0, "this is not a tcp packet"); return; } size_ip = ip_header->ihl << 2; tcp_header = (tc_tcp_header_t *) ((char *) ip_header + size_ip); size_tcp = tcp_header->doff << 2; tot_len = ntohs(ip_header->tot_len); memset(&msg, 0, sizeof(struct msg_server_s)); memcpy((void *) &(msg.ip_header), ip_header, sizeof(tc_ip_header_t)); memcpy((void *) &(msg.tcp_header), tcp_header, size_tcp); #if (TCPCOPY_MYSQL_ADVANCED) cont_len = tot_len - size_ip - size_tcp; if (cont_len > 0) { payload = (unsigned char *) ((char *) tcp_header + size_tcp); if (cont_len <= MAX_PAYLOAD_LEN) { p = ((unsigned char *) &(msg.tcp_header)) + size_tcp; memcpy((void *) p, payload, cont_len); } } #endif #if (!TCPCOPY_SINGLE) key = get_route_key(old, ip_header->daddr, tcp_header->dest, ip_header->saddr, tcp_header->source); fd = router_get(key); if (fd <= 0) { if (tcp_header->syn || tcp_header->rst) { if (tcp_header->rst) { tc_log_info(LOG_NOTICE, 0, "reset from tcp"); } tc_log_debug0(LOG_DEBUG, 0, "fd is null"); delay_table_add(key, &msg); return ; } else { tc_log_info(LOG_NOTICE, 0, "fd is null after session is created"); tc_log_trace(LOG_NOTICE, 0, BACKEND_FLAG, ip_header, tcp_header); return; } } #endif tc_log_debug_trace(LOG_NOTICE, 0, BACKEND_FLAG, ip_header, tcp_header); #if (INTERCEPT_COMBINED) #if (!TCPCOPY_SINGLE) buffer_and_send(main_router_fd, (int) (long) fd, &msg); #else buffer_and_send(main_router_fd, main_router_fd, &msg); #endif #else #if (!TCPCOPY_SINGLE) tc_socket_send((int) (long) fd, (char *) &msg, MSG_SERVER_SIZE); #else tc_socket_send(main_router_fd, (char *) &msg, MSG_SERVER_SIZE); #endif #endif }