Ejemplo n.º 1
0
static void interception_process(int fd)
{
    int                    diff, new_fd, i, pass_through_flag = 0;
    time_t                 now;
    unsigned long          packet_id;
    struct iphdr           *ip_header;
    struct msg_client_s    *c_msg;

    if(fd == msg_listen_sock){
        new_fd = accept(msg_listen_sock, NULL, NULL);   
        set_sock_no_delay(new_fd);
        if(new_fd != -1){
            select_server_add(new_fd);
        }
    }else if(fd == firewall_sock){
        packet_id = 0;
        ip_header = nl_firewall_recv(firewall_sock, &packet_id);
        if(ip_header != NULL){
            /* Check if it is the valid user to pass through firewall */
            for(i = 0; i < srv_settings.passed_ips.num; i++){
                if(srv_settings.passed_ips.ips[i] == ip_header->daddr){
                    pass_through_flag = 1;
                    break;
                }
            }
            if(pass_through_flag){
                /* Pass through the firewall */
                dispose_netlink_packet(NF_ACCEPT, packet_id);   
            }else{
                router_update(ip_header);
                now  = time(0);
                diff = now - last_clean_time;
                if(diff > CHECK_INTERVAL){
                    route_delete_obsolete(now);
                    delay_table_delete_obsolete(now);
                    last_clean_time = now;
                }
                 /* Drop the packet */
                dispose_netlink_packet(NF_DROP, packet_id);     
            }
        }
    }else{
        c_msg = msg_server_recv(fd);
        if(c_msg){
            if(c_msg->type == CLIENT_ADD){
                tc_log_debug1(LOG_NOTICE, "add client router:%u", 
                        ntohs(c_msg->client_port));
                router_add(c_msg->client_ip, c_msg->client_port, fd);
            }else if(c_msg->type == CLIENT_DEL){
                tc_log_debug1(LOG_NOTICE, "del client router:%u", 
                        ntohs(c_msg->client_port));
                router_del(c_msg->client_ip, c_msg->client_port);
            }
        }else{
            close(fd);
            select_server_del(fd);
            log_info(LOG_NOTICE, "close sock:%d", fd);
        }
    }
}
Ejemplo n.º 2
0
int
msg_client_init(uint32_t server_ip, uint16_t port)
{
    int sock  = tcp_sock_init();

    connect_to_server(sock, server_ip, port);
    set_sock_no_delay(sock);

    return sock;
}
Ejemplo n.º 3
0
Archivo: msg.c Proyecto: haolei/tcpcopy
int msg_copyer_init(uint32_t receiver_ip){
	int sock  = tcp_sock_init();
	connect_to_server(sock,receiver_ip);
	set_sock_no_delay(sock);
	return sock;
}