Пример #1
0
/* Dispose one event*/
void dispose_event(int fd)
{
    struct msg_server_s *msg;

    event_cnt++;
    if(fd == raw_sock){
        retrieve_raw_sockets(fd);
    }else{
        msg = msg_client_recv(fd);
        if(NULL == msg ){
            fprintf(stderr, "NULL msg :\n");
            log_info(LOG_ERR, "NULL msg from msg_client_recv");
            exit(EXIT_FAILURE);
        }   
        process((char*)msg, REMOTE);
    }   
#if (TCPCOPY_OFFLINE)
    if(!read_pcap_over){
        log_info(LOG_DEBUG, "send_packets_from_pcap");
        send_packets_from_pcap(0);
    }
#endif
    if((event_cnt%1000000) == 0){
        check_resource_usage();
    }
}
Пример #2
0
int
tc_offline_init(tc_event_loop_t *event_loop, char *pcap_file)
{
    int  fd;
    char ebuf[PCAP_ERRBUF_SIZE];

    /* init the raw socket to send */
    if ((fd = tc_raw_socket_out_init()) == TC_INVALID_SOCKET) {
        return TC_ERROR;
    } else {
        tc_raw_socket_out = fd;
    }

    if (pcap_file == NULL) {
        return TC_ERROR;
    }

    if ((clt_settings.pcap = pcap_open_offline(pcap_file, ebuf)) == NULL) {
        tc_log_info(LOG_ERR, 0, "open %s" , ebuf);
        fprintf(stderr, "open %s\n", ebuf);
        return TC_ERROR;
    }

    gettimeofday(&base_time, NULL);
    tc_log_info(LOG_NOTICE, 0, "open pcap success:%s", pcap_file);
    tc_log_info(LOG_NOTICE, 0, "send the first packets here");
    send_packets_from_pcap(1);

    /* register a timer for offline */
    tc_event_timer_add(event_loop, TIMER_INTERVAL, tc_process_offline_packet);

    return TC_OK;
}
Пример #3
0
static void
tc_process_offline_packet(tc_event_timer_t *evt)
{
    int diff = 0;  

    if (!read_pcap_over) {
        send_packets_from_pcap(0);
    } else {
        diff = tc_time() - read_pcap_over_time;
        if (diff > DEFAULT_SESSION_TIMEOUT) {
            tc_over = SIGRTMAX;
            tc_log_info(LOG_NOTICE, 0, "offline replay is complete");
        }
    }

    evt->msec = tc_current_time_msec;
}
Пример #4
0
/* Dispose one event*/
void dispose_event(int fd)
{
    event_cnt++;
    if (fd == raw_sock){
        retrieve_raw_sockets(fd);
    }else{
        log_info(LOG_WARN, "source from other");
    }   
#if (UDPCOPY_OFFLINE)
    if (!read_pcap_over){
        log_info(LOG_DEBUG, "send_packets_from_pcap");
        send_packets_from_pcap(0);
    }
#endif
    if ((event_cnt%1000000) == 0){
        check_resource_usage();
    }
}
Пример #5
0
/* Dispose one event*/
void
dispose_event(int fd)
{
    struct msg_server_s *msg;

    if (fd == raw_sock) {
        retrieve_raw_sockets(fd);
    } else {

        msg = msg_client_recv(fd);
        if (NULL == msg ) {
            fprintf(stderr, "NULL msg :\n");
            tc_log_info(LOG_ERR, 0, "NULL msg from msg_client_recv");
            exit(EXIT_FAILURE);
        }
        process((char*)msg, REMOTE);
    }
#if (TCPCOPY_OFFLINE)
    if (!read_pcap_over) {
        tc_log_debug0(LOG_DEBUG, 0, "send_packets_from_pcap");
        send_packets_from_pcap(0);
    }
#endif
}
Пример #6
0
static void
tc_process_offline_packet(tc_event_timer_t *evt)
{
    send_packets_from_pcap(0);
    evt->msec = tc_current_time_msec + TIMER_INTERVAL;
}
Пример #7
0
/* Initiate tcpcopy client */
int tcp_copy_init(cpy_event_loop_t *event_loop)
{
    int                    i;
#if (TCPCOPY_OFFLINE)
    char                  *pcap_file;
    char                   ebuf[PCAP_ERRBUF_SIZE];
#endif
    uint16_t               online_port, target_port;
    uint32_t               target_ip;
    ip_port_pair_mapping_t *pair;
    ip_port_pair_mapping_t **mappings;
    cpy_event_t            *raw_socket_event;

    /* keep it temporarily */
    select_server_set_callback(dispose_event);

    /* Init session table*/
    init_for_sessions();
    localhost = inet_addr("127.0.0.1"); 

    /* Init output raw socket info */
    send_init();
    /* Add connections to the tested server for exchanging info */
    mappings = clt_settings.transfer.mappings;
    for(i = 0; i < clt_settings.transfer.num; i++){
        pair = mappings[i];
        online_port = pair->online_port;
        target_ip   = pair->target_ip;
        target_port = pair->target_port;
        if(address_add_msg_conn(event_loop, online_port, target_ip, 
                clt_settings.srv_port))
        {
            return FAILURE;
        }
        log_info(LOG_NOTICE, "add a tunnel for exchanging info:%u",
                ntohs(target_port));
    }
    
#if (!TCPCOPY_OFFLINE)
    /* Init input raw socket info */
    raw_sock = init_input_raw_socket();
#endif
    if(raw_sock != -1){
        /* Add the input raw socket to select */
        raw_socket_event = cpy_event_create(raw_sock, dispose_event_wrapper,
                                           NULL);
        if (raw_socket_event == NULL) {
            return FAILURE;
        }

        if (cpy_event_add(event_loop, raw_socket_event, CPY_EVENT_READ)
                == CPY_EVENT_ERROR)
        {
            log_info(LOG_ERR, "add raw socket(%d) to event loop failed.",
                     raw_socket_event->fd);
            return FAILURE;
        }

        /* Init output raw socket info */
        send_init();
        /* Add connections to the tested server for exchanging info */
        mappings = clt_settings.transfer.mappings;
        for(i = 0; i < clt_settings.transfer.num; i++){
            pair = mappings[i];
            online_port = pair->online_port;
            target_ip   = pair->target_ip;
            target_port = pair->target_port;

            if (address_add_msg_conn(event_loop, online_port, target_ip, 
                                     clt_settings.srv_port) == -1)
            {
                return FAILURE;
            }

            log_info(LOG_NOTICE, "add a tunnel for exchanging info:%u",
                    ntohs(target_port));
        }
        return SUCCESS;
    }else{
#if (TCPCOPY_OFFLINE)
        select_offline_set_callback(send_packets_from_pcap);
        pcap_file = clt_settings.pcap_file;
        if(pcap_file != NULL){
            if ((pcap = pcap_open_offline(pcap_file, ebuf)) == NULL){
                log_info(LOG_ERR, "open %s" , ebuf);
                fprintf(stderr, "open %s\n", ebuf);
                return FAILURE;

            }else{
                gettimeofday(&base_time, NULL);
                log_info(LOG_NOTICE, "open pcap success:%s", pcap_file);
                log_info(LOG_NOTICE, "send the first packets here");
                send_packets_from_pcap(1);
            }
        }else{
            return FAILURE;
        }
#else
        return FAILURE;
#endif
    }

    return SUCCESS;
}
Пример #8
0
/* Initiate udpcopy client */
int udp_copy_init(tc_event_loop_t *event_loop)
{
#if (UDPCOPY_OFFLINE)
    char                   *pcap_file, ebuf[PCAP_ERRBUF_SIZE];
#endif
    tc_event_t             *raw_socket_event;

    /* keep it temporarily */
    select_server_set_callback(dispose_event);

    localhost = inet_addr("127.0.0.1"); 

    /* Init output raw socket info */
    send_init();

#if (!UDPCOPY_OFFLINE)
    /* Init input raw socket info */
    raw_sock = init_input_raw_socket();
#endif
    if (raw_sock != -1){
        /* Add the input raw socket to select */
        raw_socket_event = tc_event_create(raw_sock, dispose_event_wrapper,
                                           NULL);
        if (raw_socket_event == NULL) {
            return FAILURE;
        }

        if (tc_event_add(event_loop, raw_socket_event, TC_EVENT_READ)
                == TC_EVENT_ERROR)
        {
            log_info(LOG_ERR, "add raw socket(%d) to event loop failed.",
                     raw_socket_event->fd);
            return FAILURE;
        }

        /* Init output raw socket info */
        send_init();
        return SUCCESS;
    }else{
#if (UDPCOPY_OFFLINE)
        select_offline_set_callback(send_packets_from_pcap);
        pcap_file = clt_settings.pcap_file;
        if (pcap_file != NULL){
            if ((pcap = pcap_open_offline(pcap_file, ebuf)) == NULL){
                log_info(LOG_ERR, "open %s" , ebuf);
                fprintf(stderr, "open %s\n", ebuf);
                return FAILURE;

            }else{
                gettimeofday(&base_time, NULL);
                log_info(LOG_NOTICE, "open pcap success:%s", pcap_file);
                log_info(LOG_NOTICE, "send the first packets here");
                send_packets_from_pcap(1);
            }
        }else{
            return FAILURE;
        }
#else
        return FAILURE;
#endif
    }

    return SUCCESS;
}