コード例 #1
0
ファイル: xsocks_client.c プロジェクト: road0001/xsocks
static void
client_send_cb(uv_write_t *req, int status) {
    struct client_context *client = req->data;
    struct remote_context *remote = client->remote;

    if (status == 0) {
        if (client->stage == XSTAGE_REQUEST) {
            receive_from_client(client);

        } else if (client->stage == XSTAGE_FORWARD) {
            receive_from_remote(remote);

        } else if (client->stage == XSTAGE_TERMINATE) {
            close_client(client);
            close_remote(remote);
        }

    } else {
        char addrbuf[INET6_ADDRSTRLEN + 1] = {0};
        int port = ip_name(&client->addr, addrbuf, sizeof addrbuf);
        if (client->stage == XSTAGE_FORWARD) {
            logger_log(LOG_ERR, "%s:%d <- %s failed: %s", addrbuf, port, client->target_addr, uv_strerror(status));
        } else {
            logger_log(LOG_ERR, "forward to %s:%d failed: %s", addrbuf, port, uv_strerror(status));
        }
    }

    free(req);
}
コード例 #2
0
ファイル: main.c プロジェクト: kikutak/dpdk-ovs
static inline void
do_client_switching(void)
{
	static unsigned client = CLIENT1;
	static unsigned kni_vportid = KNI0;
	int rx_count = 0;
	int j = 0;
	struct rte_mbuf *bufs[PKT_BURST_SIZE] = {0};

	rx_count = receive_from_client(client, &bufs[0]);

	/* Prefetch first packets */
	for (j = 0; j < PREFETCH_OFFSET && j < rx_count; j++) {
		rte_prefetch0(rte_pktmbuf_mtod(bufs[j], void *));
	}

	/* Prefetch and forward already prefetched packets */
	for (j = 0; j < (rx_count - PREFETCH_OFFSET); j++) {
		rte_prefetch0(rte_pktmbuf_mtod(bufs[
					j + PREFETCH_OFFSET], void *));
		switch_packet(bufs[j], client);
	}

	/* Forward remaining prefetched packets */
	for (; j < rx_count; j++) {
		switch_packet(bufs[j], client);
	}

	/* move to next client and dont handle client 0*/
	if (++client == num_clients) {
		client = 1;
	}

	rx_count = receive_from_kni(kni_vportid, &bufs[0]);

	/* Prefetch first packets */
	for (j = 0; j < PREFETCH_OFFSET && j < rx_count; j++) {
		rte_prefetch0(rte_pktmbuf_mtod(bufs[j], void *));
	}

	/* Prefetch and forward already prefetched packets */
	for (j = 0; j < (rx_count - PREFETCH_OFFSET); j++) {
		rte_prefetch0(rte_pktmbuf_mtod(bufs[
					j + PREFETCH_OFFSET], void *));
		switch_packet(bufs[j], kni_vportid);
	}

	/* Forward remaining prefetched packets */
	for (; j < rx_count; j++) {
		switch_packet(bufs[j], kni_vportid);
	}

	/* move to next kni port */
	if (++kni_vportid == KNI0 + num_kni) {
		kni_vportid = KNI0;
	}

}
コード例 #3
0
ファイル: xsocks_remote.c プロジェクト: cdlz/xsocks
static void
remote_send_cb(uv_write_t *req, int status) {
    struct remote_context *remote = (struct remote_context *)req->data;
    struct client_context *client = remote->client;

    if (status == 0) {
        receive_from_client(client);
    } else {
        logger_log(LOG_ERR, "forward to remote failed: %s", uv_strerror(status));
    }
}
コード例 #4
0
ファイル: xtproxy_remote.c プロジェクト: cdlz/xsocks
static void
remote_send_cb(uv_write_t *req, int status) {
    struct remote_context *remote = (struct remote_context *)req->data;
    struct client_context *client = remote->client;

    if (status == 0) {
        reset_timer(remote);
        receive_from_client(client);

    } else {
        if (verbose) {
            logger_log(LOG_ERR, "send to server failed: %s", uv_strerror(status));
        }
    }
}
コード例 #5
0
ファイル: xsocksd_remote.c プロジェクト: nsdown/xsocks-1
static void
remote_send_cb(uv_write_t *req, int status) {
    struct remote_context *remote = (struct remote_context *)req->data;
    struct client_context *client = remote->client;

    if (status == 0) {
        receive_from_client(client);

    } else {
        char addrbuf[INET6_ADDRSTRLEN + 1] = {0};
        uint16_t port = ip_name(&client->addr, addrbuf, sizeof addrbuf);
        logger_log(LOG_ERR, "%s:%d -> failed: %s", addrbuf, port, client->target_addr, uv_strerror(status));
    }

    free(req);
}
コード例 #6
0
ファイル: xsocks_remote.c プロジェクト: cdlz/xsocks
static void
remote_connect_cb(uv_connect_t *req, int status) {
    struct remote_context *remote = (struct remote_context *)req->data;
    struct client_context *client = remote->client;


    if (status == 0) {
        remote->stage = XSTAGE_FORWARD;
        reset_timer(remote);
        receive_from_client(client);
        receive_from_remote(remote);

    } else {
        if (status != UV_ECANCELED) {
            logger_log(LOG_ERR, "connect to server failed: %s", uv_strerror(status));
            request_ack(client, S5_REP_HOST_UNREACHABLE);
        }
    }
}
コード例 #7
0
ファイル: xsocksd_remote.c プロジェクト: nsdown/xsocks-1
static void
remote_connect_cb(uv_connect_t *req, int status) {
    struct remote_context *remote = (struct remote_context *)req->data;
    struct client_context *client = remote->client;

    if (status == 0) {
        reset_timer(remote);

        client->stage = XSTAGE_FORWARD;
        remote->stage = XSTAGE_FORWARD;

        receive_from_client(client);
        receive_from_remote(remote);

    } else {
        if (status != UV_ECANCELED) {
            // TODO: handle RST
            logger_log(LOG_ERR, "connect to %s failed: %s", client->target_addr, uv_strerror(status));
            close_client(client);
            close_remote(remote);
        }
    }
}