增加TCP Passthrough功能实现,调通明文转发流程。
This commit is contained in:
@@ -40,7 +40,7 @@ struct kni_tlv_info
|
||||
char value;
|
||||
};
|
||||
|
||||
struct kni_acceptor_ctx
|
||||
struct kni_acceptor
|
||||
{
|
||||
/* INPUT */
|
||||
struct tfe_proxy * proxy;
|
||||
@@ -63,7 +63,7 @@ struct kni_acceptor_ctx
|
||||
pid_t pid_kni_conn;
|
||||
};
|
||||
|
||||
void __kni_conn_close(struct kni_acceptor_ctx * ctx)
|
||||
void __kni_conn_close(struct kni_acceptor * ctx)
|
||||
{
|
||||
if (ctx->fd_kni_conn != 0) close(ctx->fd_kni_conn);
|
||||
if (ctx->ev_kni_conn != NULL) event_free(ctx->ev_kni_conn);
|
||||
@@ -72,7 +72,7 @@ void __kni_conn_close(struct kni_acceptor_ctx * ctx)
|
||||
|
||||
void __kni_event_cb(evutil_socket_t fd, short what, void * user)
|
||||
{
|
||||
struct kni_acceptor_ctx * __ctx = (struct kni_acceptor_ctx *)user;
|
||||
struct kni_acceptor * __ctx = (struct kni_acceptor *)user;
|
||||
struct cmsghdr * __cmsghdr;
|
||||
struct tfe_proxy_accept_para __accept_para;
|
||||
int * __fds = NULL;
|
||||
@@ -112,12 +112,12 @@ void __kni_event_cb(evutil_socket_t fd, short what, void * user)
|
||||
}
|
||||
else if (rd < 0)
|
||||
{
|
||||
TFE_LOG_ERROR(__ctx->logger, "Failed at recving fds from KNI connection: %s", strerror(errno));
|
||||
TFE_LOG_ERROR(__ctx->logger, "Failed at recving fds from KNI connection: %s. ", strerror(errno));
|
||||
goto __close_kni_connection;
|
||||
}
|
||||
else if (rd == 0)
|
||||
{
|
||||
TFE_LOG_INFO(__ctx->logger, "KNI connected from process %u", __ctx->pid_kni_conn);
|
||||
TFE_LOG_INFO(__ctx->logger, "KNI connected from process %u. ", __ctx->pid_kni_conn);
|
||||
goto __close_kni_connection;
|
||||
}
|
||||
|
||||
@@ -163,12 +163,14 @@ __drop_recieved_fds:
|
||||
void __kni_listener_accept_cb(struct evconnlistener * listener, evutil_socket_t fd,
|
||||
struct sockaddr * sk_addr, int sk_len, void * user)
|
||||
{
|
||||
struct kni_acceptor_ctx * __ctx = (struct kni_acceptor_ctx *)user;
|
||||
struct kni_acceptor * __ctx = (struct kni_acceptor *)user;
|
||||
struct event * __event = NULL;
|
||||
|
||||
struct ucred __cr{};
|
||||
socklen_t __cr_len = sizeof(struct ucred);
|
||||
|
||||
int ret = 0;
|
||||
|
||||
/* There is only one KNI process can connect to TFE.
|
||||
* If ev_kni_conn is not NULL, there's already a KNI connected to TFE.
|
||||
* We need to refuse this connection
|
||||
@@ -195,6 +197,13 @@ void __kni_listener_accept_cb(struct evconnlistener * listener, evutil_socket_t
|
||||
goto __close_this_connection;
|
||||
}
|
||||
|
||||
ret = event_add(__event, NULL);
|
||||
if (unlikely(ret < 0))
|
||||
{
|
||||
TFE_LOG_ERROR(__ctx->logger, "Failed at adding event to evbase, close this connection. ");
|
||||
goto __close_this_connection;
|
||||
}
|
||||
|
||||
__ctx->fd_kni_conn = fd;
|
||||
__ctx->ev_kni_conn = __event;
|
||||
__ctx->pid_kni_conn = __cr.pid;
|
||||
@@ -208,7 +217,7 @@ __close_this_connection:
|
||||
|
||||
void * __kni_listener_thread_entry(void * args)
|
||||
{
|
||||
struct kni_acceptor_ctx * __ctx = (struct kni_acceptor_ctx *)args;
|
||||
struct kni_acceptor * __ctx = (struct kni_acceptor *)args;
|
||||
assert(__ctx != NULL && __ctx->thread == pthread_self());
|
||||
|
||||
TFE_LOG_DEBUG(__ctx->logger, "Starting KNI listener thread...");
|
||||
@@ -217,7 +226,7 @@ void * __kni_listener_thread_entry(void * args)
|
||||
return (void *)NULL;
|
||||
}
|
||||
|
||||
void kni_acceptor_deinit(struct kni_acceptor_ctx *ctx)
|
||||
void kni_acceptor_deinit(struct kni_acceptor *ctx)
|
||||
{
|
||||
if (ctx != NULL && ctx->ev_listener != NULL)
|
||||
{
|
||||
@@ -242,12 +251,13 @@ void kni_acceptor_deinit(struct kni_acceptor_ctx *ctx)
|
||||
return;
|
||||
}
|
||||
|
||||
struct kni_acceptor_ctx * kni_acceptor_init(struct tfe_proxy *proxy, const char *profile, void *logger)
|
||||
struct kni_acceptor * kni_acceptor_init(struct tfe_proxy *proxy, const char *profile, void *logger)
|
||||
{
|
||||
struct kni_acceptor_ctx * __ctx = ALLOC(struct kni_acceptor_ctx, 1);
|
||||
struct kni_acceptor * __ctx = ALLOC(struct kni_acceptor, 1);
|
||||
struct sockaddr_un __sockaddr_un;
|
||||
int ret = 0;
|
||||
|
||||
__ctx->proxy = proxy;
|
||||
__ctx->profile = profile;
|
||||
__ctx->logger = logger;
|
||||
|
||||
@@ -290,9 +300,7 @@ struct kni_acceptor_ctx * kni_acceptor_init(struct tfe_proxy *proxy, const char
|
||||
goto __errout;
|
||||
}
|
||||
|
||||
TFE_LOG_INFO(__ctx->logger, "KNI UNIXDOMAIN FILE: %s", __ctx->str_unixdomain_file);
|
||||
TFE_LOG_INFO(__ctx->logger, "KNI LISTENER FD: %d", __ctx->fd_unixdomain);
|
||||
|
||||
TFE_LOG_INFO(__ctx->logger, "KNI acceptor unixdomain file: %s", __ctx->str_unixdomain_file);
|
||||
return __ctx;
|
||||
|
||||
__errout:
|
||||
|
||||
Reference in New Issue
Block a user