Example #1
0
static int
tc_msg_event_accept(tc_event_t *rev)
{
    int         fd;
    tc_event_t *ev;

    if ((fd = tc_socket_accept(rev->fd)) == TC_INVALID_SOCKET) {
        tc_log_info(LOG_ERR, 0, "msg accept failed, from listen:%d", rev->fd);
        return TC_ERROR;
    }

    if (tc_socket_set_nodelay(fd) == TC_ERROR) {
        tc_log_info(LOG_ERR, 0, "Set no delay to socket(%d) failed.", rev->fd);
        return TC_ERROR;
    }

    ev = tc_event_create(fd, tc_msg_event_process, NULL);
    if (ev == NULL) {
        tc_log_info(LOG_ERR, 0, "Msg event create failed.");
        return TC_ERROR;
    }

    if (tc_event_add(rev->loop, ev, TC_EVENT_READ) == TC_EVENT_ERROR) {
        return TC_ERROR;
    }

    return TC_OK;
}
Example #2
0
static int
tc_msg_event_accept(tc_event_t *rev)
{
    int         fd;
    tc_event_t *ev;

    if ((fd = tc_socket_accept(rev->fd)) == TC_INVALID_SOCKET) {
        tc_log_info(LOG_ERR, 0, "msg accept failed, from listen:%d", rev->fd);
        return TC_ERROR;
    }

    if (tc_socket_set_nodelay(fd) == TC_ERROR) {
        tc_log_info(LOG_ERR, 0, "Set no delay to socket(%d) failed.", rev->fd);
        return TC_ERROR;
    }

    ev = tc_event_create(fd, tc_msg_event_process, NULL);
    if (ev == NULL) {
        tc_log_info(LOG_ERR, 0, "msg event create failed.");
        return TC_ERROR;
    }

    if (tc_event_add(rev->loop, ev, TC_EVENT_READ) == TC_EVENT_ERROR) {
        return TC_ERROR;
    }
#if (TCPCOPY_SINGLE)  
    if (srv_settings.router_fd > 0) {
        tc_log_info(LOG_WARN, 0, "it does not support distributed tcpcopy");
    }
    srv_settings.router_fd = fd;
#endif

    return TC_OK;
}
Example #3
0
static int
tc_msg_event_accept(tc_event_t *rev)
{
    tc_event_t     *ev;
    register int    fd;
    tunnel_basic_t *tunnel;

    if ((fd = tc_socket_accept(rev->fd)) == TC_INVALID_SOCK) {
        tc_log_info(LOG_ERR, 0, "msg accept failed, from listen:%d", rev->fd);
        return TC_ERR;
    }
    
    tc_log_info(LOG_NOTICE, 0, "it adds fd:%d", fd);

    if (tc_socket_set_nodelay(fd) == TC_ERR) {
        tc_log_info(LOG_ERR, 0, "Set no delay to socket(%d) failed.", rev->fd);
        tc_log_info(LOG_NOTICE, 0, "it close socket:%d", fd);
        tc_socket_close(fd);
        return TC_ERR;
    }

#if (TC_SINGLE)  
    if (!tc_intercept_check_tunnel_for_single(fd)) {
        tc_log_info(LOG_WARN, 0, "sth tries to connect to server.");
        tc_log_info(LOG_NOTICE, 0, "it close socket:%d", fd);
        tc_socket_close(fd);
        return TC_ERR;
    }
#endif   

    ev = tc_event_create(rev->loop->pool, fd, tc_msg_event_proc, NULL);
    if (ev == NULL) {
        tc_log_info(LOG_ERR, 0, "Msg event create failed.");
        return TC_ERR;
    }

    if (tc_event_add(rev->loop, ev, TC_EVENT_READ) == TC_EVENT_ERROR) {
        return TC_ERR;
    }

    tunnel = srv_settings.tunnel;
    tunnel[fd].ev = ev;
    tunnel[fd].first_in = 1;
    tunnel[fd].fd_valid = 1;

    return TC_OK;
}
Example #4
0
int
tc_message_init(tc_event_loop_t *event_loop, uint32_t ip, uint16_t port)
{
    int            fd;
    tc_event_t    *ev;

#if (TCPCOPY_DR)
    socklen_t      len;
    struct timeval timeout = {3,0}; 
#endif

    if ((fd = tc_socket_init()) == TC_INVALID_SOCKET) {
        return TC_INVALID_SOCKET;
    }

    if (tc_socket_connect(fd, ip, port) == TC_ERROR) {
        return TC_INVALID_SOCKET;
    }

    if (tc_socket_set_nodelay(fd) == TC_ERROR) {
        return TC_INVALID_SOCKET;
    }
#if (TCPCOPY_COMBINED)
    if (tc_socket_set_nonblocking(fd) == TC_ERROR) {
        return TC_INVALID_SOCKET;
    }
#endif

#if (TCPCOPY_DR)
    len = (socklen_t) sizeof(struct timeval);
    setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, len);
#endif

    ev = tc_event_create(fd, tc_process_server_msg, NULL);
    if (ev == NULL) {
        return TC_INVALID_SOCKET;
    }

    if (tc_event_add(event_loop, ev, TC_EVENT_READ) == TC_EVENT_ERROR) {
        return TC_INVALID_SOCKET;
    }

    return fd;
}
Example #5
0
/* This is for copying multiple ports */
int
address_add_msg_conn(tc_event_loop_t *event_loop, uint16_t local_port,
        uint32_t dst_ip, uint16_t dst_port)
{
    int          fd;
    tc_event_t  *msg_socket_event;

    if ((fd = tc_socket_init()) == TC_INVALID_SOCKET) {
        return TC_ERROR;
    }

    if (tc_socket_connect(fd, dst_ip, dst_port) == TC_ERROR) {
        return TC_ERROR;
    }

    if (tc_socket_set_nodelay(fd) == TC_ERROR) {
        return TC_ERROR;
    }

    msg_socket_event = tc_event_create(fd, dispose_event_wrapper, NULL);
    if (msg_socket_event == NULL) {
        return TC_ERROR;
    }

    if (tc_event_add(event_loop, msg_socket_event, TC_EVENT_READ)
            == TC_EVENT_ERROR)
    {
        return TC_ERROR;
    }

    addr[local_port].ip = dst_ip;
    addr[local_port].port = dst_port;
    addr[local_port].sock = fd;

    return TC_OK;
}