From 20b9d6ab026620cdcc773725169ac745bcea6802 Mon Sep 17 00:00:00 2001 From: winlin Date: Fri, 21 Feb 2020 23:51:40 +0800 Subject: [PATCH] For #1598, support SLB health checking by TCP. 3.0.123 --- README.md | 2 ++ trunk/conf/full.conf | 4 ++++ trunk/src/app/srs_app_caster_flv.cpp | 6 +++++- trunk/src/app/srs_app_config.cpp | 14 +++++++++++++- trunk/src/app/srs_app_config.hpp | 2 ++ trunk/src/app/srs_app_rtsp.cpp | 3 +++ trunk/src/app/srs_app_server.cpp | 4 ++++ trunk/src/core/srs_core_version3.hpp | 2 +- 8 files changed, 34 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4f4ee7545..e72c4e14f 100755 --- a/README.md +++ b/README.md @@ -146,6 +146,7 @@ For previous versions, please read: ## V3 changes +* v3.0, 2020-02-21, For [#1598][bug #1598], support SLB health checking by TCP. 3.0.123 * v3.0, 2020-02-21, Fix bug for librtmp client ipv4/ipv6 socket. 3.0.122 * v3.0, 2020-02-18, For [#1579][bug #1579], support start/final wait for gracefully quit. 3.0.121 * v3.0, 2020-02-18, For [#1579][bug #1579], support force gracefully quit. 3.0.120 @@ -1656,6 +1657,7 @@ Winlin [bug #1595]: https://github.com/ossrs/srs/issues/1595 [bug #1601]: https://github.com/ossrs/srs/issues/1601 [bug #1579]: https://github.com/ossrs/srs/issues/1579 +[bug #1598]: https://github.com/ossrs/srs/issues/1598 [bug #xxxxxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxxxxx [exo #828]: https://github.com/google/ExoPlayer/pull/828 diff --git a/trunk/conf/full.conf b/trunk/conf/full.conf index 65d5ddb48..b56f27fbc 100644 --- a/trunk/conf/full.conf +++ b/trunk/conf/full.conf @@ -72,6 +72,10 @@ work_dir ./; # @reamrk do not support reload. # default: off asprocess off; +# Whether client empty IP is ok, for example, health checking by SLB. +# If ok(on), we will ignore this connection without warnings or errors. +# default: on +empty_ip_ok on; # For gracefully quit, wait for a while then close listeners, # because K8S notify SRS with SIGQUIT and update Service simultaneously, diff --git a/trunk/src/app/srs_app_caster_flv.cpp b/trunk/src/app/srs_app_caster_flv.cpp index 7526921cc..d6f3150f7 100644 --- a/trunk/src/app/srs_app_caster_flv.cpp +++ b/trunk/src/app/srs_app_caster_flv.cpp @@ -76,8 +76,12 @@ srs_error_t SrsAppCasterFlv::initialize() srs_error_t SrsAppCasterFlv::on_tcp_client(srs_netfd_t stfd) { srs_error_t err = srs_success; - + string ip = srs_get_peer_ip(srs_netfd_fileno(stfd)); + if (ip.empty() && !_srs_config->empty_ip_ok()) { + srs_warn("empty ip for fd=%d", srs_netfd_fileno(stfd)); + } + SrsHttpConn* conn = new SrsDynamicHttpConn(this, stfd, http_mux, ip); conns.push_back(conn); diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 3c0af54de..3eb7483a5 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -3488,7 +3488,7 @@ srs_error_t SrsConfig::check_normal_config() && n != "http_server" && n != "stream_caster" && n != "utc_time" && n != "work_dir" && n != "asprocess" && n != "ff_log_level" && n != "grace_final_wait" && n != "force_grace_quit" - && n != "grace_start_wait" + && n != "grace_start_wait" && n != "empty_ip_ok" ) { return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal directive %s", n.c_str()); } @@ -4051,6 +4051,18 @@ bool SrsConfig::get_asprocess() return SRS_CONF_PERFER_FALSE(conf->arg0()); } +bool SrsConfig::empty_ip_ok() +{ + static bool DEFAULT = true; + + SrsConfDirective* conf = root->get("empty_ip_ok"); + if (!conf || conf->arg0().empty()) { + return DEFAULT; + } + + return SRS_CONF_PERFER_TRUE(conf->arg0()); +} + srs_utime_t SrsConfig::get_grace_start_wait() { static srs_utime_t DEFAULT = 2300 * SRS_UTIME_MILLISECONDS; diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index 2bd2882b3..0b94470da 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -468,6 +468,8 @@ public: virtual std::string get_work_dir(); // Whether use asprocess mode. virtual bool get_asprocess(); + // Whether empty client IP is ok. + virtual bool empty_ip_ok(); // Get the start wait in ms for gracefully quit. virtual srs_utime_t get_grace_start_wait(); // Get the final wait in ms for gracefully quit. diff --git a/trunk/src/app/srs_app_rtsp.cpp b/trunk/src/app/srs_app_rtsp.cpp index 051071b49..62ebfdcd1 100644 --- a/trunk/src/app/srs_app_rtsp.cpp +++ b/trunk/src/app/srs_app_rtsp.cpp @@ -243,6 +243,9 @@ srs_error_t SrsRtspConn::do_cycle() // retrieve ip of client. std::string ip = srs_get_peer_ip(srs_netfd_fileno(stfd)); + if (ip.empty() && !_srs_config->empty_ip_ok()) { + srs_warn("empty ip for fd=%d", srs_netfd_fileno(stfd)); + } srs_trace("rtsp: serve %s", ip.c_str()); // consume all rtsp messages. diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index b82cb9197..632ff9fc5 100644 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -1237,6 +1237,10 @@ srs_error_t SrsServer::accept_client(SrsListenerType type, srs_netfd_t stfd) SrsConnection* conn = NULL; if ((err = fd2conn(type, stfd, &conn)) != srs_success) { + if (srs_error_code(err) == ERROR_SOCKET_GET_PEER_IP && _srs_config->empty_ip_ok()) { + srs_close_stfd(stfd); srs_error_reset(err); + return srs_success; + } return srs_error_wrap(err, "fd2conn"); } srs_assert(conn); diff --git a/trunk/src/core/srs_core_version3.hpp b/trunk/src/core/srs_core_version3.hpp index 801fd91fe..c871670b0 100644 --- a/trunk/src/core/srs_core_version3.hpp +++ b/trunk/src/core/srs_core_version3.hpp @@ -24,6 +24,6 @@ #ifndef SRS_CORE_VERSION3_HPP #define SRS_CORE_VERSION3_HPP -#define SRS_VERSION3_REVISION 122 +#define SRS_VERSION3_REVISION 123 #endif