diff options
| author | luqiuwen <[email protected]> | 2019-06-01 17:00:36 +0800 |
|---|---|---|
| committer | luqiuwen <[email protected]> | 2019-06-02 16:30:59 +0800 |
| commit | 77aa3063f73aa36028062acaa7a0d0fe4c223fe4 (patch) | |
| tree | 2ae7766ba1aa3209d0eb1eaa33f7d593b84b5385 /platform/src/proxy.cpp | |
| parent | 1b872c246dec1c4a8b8d79b5eca303a18c849e72 (diff) | |
使用cmsg公共库解析cmsg信息,对业务层提供获取cmsg句柄的接口
Diffstat (limited to 'platform/src/proxy.cpp')
| -rw-r--r-- | platform/src/proxy.cpp | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/platform/src/proxy.cpp b/platform/src/proxy.cpp index cb3030b..69c7ac4 100644 --- a/platform/src/proxy.cpp +++ b/platform/src/proxy.cpp @@ -30,6 +30,8 @@ #include <tfe_future.h> #include <tfe_stream.h> #include <tfe_proxy.h> +#include <tfe_plugin.h> +#include <tfe_cmsg.h> #include <platform.h> #include <proxy.h> @@ -37,7 +39,6 @@ #include <tcp_stream.h> #include <MESA/MESA_prof_load.h> #include <MESA/field_stat2.h> -#include <tfe_plugin.h> extern struct ssl_policy_enforcer* ssl_policy_enforcer_create(void* logger); extern enum ssl_stream_action ssl_policy_enforce(struct ssl_stream *upstream, void* u_para); @@ -99,16 +100,28 @@ void tfe_proxy_thread_ctx_release(struct tfe_thread_ctx * thread_ctx) ATOMIC_DEC(&thread_ctx->load); } -int tfe_proxy_fds_accept(struct tfe_proxy * ctx, const struct tfe_proxy_accept_para * para) +int tfe_proxy_fds_accept(struct tfe_proxy * ctx, int fd_downstream, int fd_upstream, struct tfe_cmsg * cmsg) { - tfe_thread_ctx * worker_thread_ctx = tfe_proxy_thread_ctx_acquire(ctx); - + struct tfe_thread_ctx * worker_thread_ctx = tfe_proxy_thread_ctx_acquire(ctx); struct tfe_stream * stream = tfe_stream_create(ctx, worker_thread_ctx); - tfe_stream_option_set(stream, TFE_STREAM_OPT_SESSION_TYPE, ¶->session_type, sizeof(para->session_type)); - tfe_stream_option_set(stream, TFE_STREAM_OPT_KEYRING_ID, ¶->keyring_id, sizeof(para->keyring_id)); + + enum tfe_stream_proto stream_protocol; + uint16_t __size; + + int result = tfe_cmsg_get_value(cmsg, TFE_CMSG_TCP_RESTORE_PROTOCOL, (char *)&stream_protocol, + sizeof(stream_protocol), &__size); + + if (unlikely(result < 0)) + { + TFE_LOG_ERROR(ctx->logger, "failed at fetch connection's protocol from cmsg: %s", strerror(-result)); + goto __errout; + } + + tfe_stream_option_set(stream, TFE_STREAM_OPT_SESSION_TYPE, &stream_protocol, sizeof(stream_protocol)); + tfe_stream_cmsg_setup(stream, cmsg); /* FOR DEBUG */ - if (para->passthrough || ctx->tcp_all_passthrough) + if (unlikely(ctx->tcp_all_passthrough)) { bool __true = true; enum tfe_stream_proto __session_type = STREAM_PROTO_PLAIN; @@ -117,17 +130,16 @@ int tfe_proxy_fds_accept(struct tfe_proxy * ctx, const struct tfe_proxy_accept_p tfe_stream_option_set(stream, TFE_STREAM_OPT_SESSION_TYPE, &__session_type, sizeof(__session_type)); } - int ret = tfe_stream_init_by_fds(stream, para->downstream_fd, para->upstream_fd); - if (ret < 0) + result = tfe_stream_init_by_fds(stream, fd_downstream, fd_upstream); + if (result < 0) { TFE_LOG_ERROR(ctx->logger, "%p, Fds(downstream = %d, upstream = %d, type = %d) accept failed.", - stream, para->downstream_fd, para->upstream_fd, para->session_type); - goto __errout; + stream, fd_downstream, fd_upstream, stream_protocol); goto __errout; } else { TFE_LOG_DEBUG(ctx->logger, "%p, Fds(downstream = %d, upstream = %d, type = %d) accepted.", - stream, para->downstream_fd, para->upstream_fd, para->session_type); + stream, fd_downstream, fd_upstream, stream_protocol); } return 0; |
