]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: allow beast frontend to listen on specific IP address 20000/head
authorYuan Zhou <yuan.zhou@intel.com>
Thu, 18 Jan 2018 06:21:42 +0000 (14:21 +0800)
committerYuan Zhou <yuan.zhou@intel.com>
Wed, 24 Jan 2018 00:30:32 +0000 (08:30 +0800)
This patch allows the beast frontend to listen on a specific
IP address rather than *. e.g., with below configuration:

rgw frontends = beast port=1.2.3.4:8080

rgw server will listen on 1.2.3.4 only.

Fixes: http://tracker.ceph.com/issues/22778
Signed-off-by: Yuan Zhou <yuan.zhou@intel.com>
src/rgw/rgw_asio_frontend.cc
src/rgw/rgw_asio_frontend.h
src/rgw/rgw_main.cc

index 61e011c7c4b5f91e08a2acefff89730692ffde42..cf4224a1f0e1362bf766400824025c377ff21ded 100644 (file)
@@ -194,6 +194,7 @@ class Connection {
 
 class AsioFrontend {
   RGWProcessEnv env;
+  RGWFrontendConfig* conf;
   boost::asio::io_service service;
 
   tcp::acceptor acceptor;
@@ -208,8 +209,8 @@ class AsioFrontend {
   void accept(boost::system::error_code ec);
 
  public:
-  AsioFrontend(const RGWProcessEnv& env)
-    : env(env), acceptor(service), peer_socket(service) {}
+  AsioFrontend(const RGWProcessEnv& env, RGWFrontendConfig* conf)
+    : env(env), conf(conf), acceptor(service), peer_socket(service) {}
 
   int init();
   int run();
@@ -221,10 +222,28 @@ class AsioFrontend {
 
 int AsioFrontend::init()
 {
-  auto ep = tcp::endpoint{tcp::v4(), static_cast<unsigned short>(env.port)};
-  ldout(ctx(), 4) << "frontend listening on " << ep << dendl;
+  std::string port_str;
+  conf->get_val("port", "80", &port_str);
 
+  unsigned short port;
+  boost::asio::ip::address addr; // default to 'any'
   boost::system::error_code ec;
+
+  auto colon = port_str.find(':');
+  if (colon != port_str.npos) {
+    addr = boost::asio::ip::make_address(port_str.substr(0, colon), ec);
+    if (ec) {
+      lderr(ctx()) << "failed to parse address '" << port_str << "': " << ec.message() << dendl;
+      return -ec.value();
+    }
+    port = std::stoul(port_str.substr(colon + 1), nullptr, 0);
+  } else {
+    port = std::stoul(port_str, nullptr, 0);
+  }
+
+  tcp::endpoint ep = {addr, port};
+  ldout(ctx(), 4) << "frontend listening on " << ep << dendl;
+
   acceptor.open(ep.protocol(), ec);
   if (ec) {
     lderr(ctx()) << "failed to open socket: " << ec.message() << dendl;
@@ -336,11 +355,12 @@ void AsioFrontend::unpause(RGWRados* const store,
 
 class RGWAsioFrontend::Impl : public AsioFrontend {
  public:
-  Impl(const RGWProcessEnv& env) : AsioFrontend(env) {}
+  Impl(const RGWProcessEnv& env, RGWFrontendConfig* conf) : AsioFrontend(env, conf) {}
 };
 
-RGWAsioFrontend::RGWAsioFrontend(const RGWProcessEnv& env)
-  : impl(new Impl(env))
+RGWAsioFrontend::RGWAsioFrontend(const RGWProcessEnv& env,
+                                 RGWFrontendConfig* conf)
+  : impl(new Impl(env, conf))
 {
 }
 
index 4c32cada640cbccd95c71e19ad05a801bab3440b..6e6a191065ba5e0e10ce8ff2a9cb55b6767efcd4 100644 (file)
@@ -11,7 +11,7 @@ class RGWAsioFrontend : public RGWFrontend {
   class Impl;
   std::unique_ptr<Impl> impl;
 public:
-  RGWAsioFrontend(const RGWProcessEnv& env);
+  RGWAsioFrontend(const RGWProcessEnv& env, RGWFrontendConfig* conf);
   ~RGWAsioFrontend() override;
 
   int init() override;
index aaa57ae0ef314fb07463fe3cf90989d57a129a7a..7456d8e7bb631e7d7436e349c5ab0670220eb7a8 100644 (file)
@@ -474,7 +474,7 @@ int main(int argc, const char **argv)
       std::string uri_prefix;
       config->get_val("prefix", "", &uri_prefix);
       RGWProcessEnv env{ store, &rest, olog, port, uri_prefix, auth_registry };
-      fe = new RGWAsioFrontend(env);
+      fe = new RGWAsioFrontend(env, config);
     }
 #endif /* WITH_RADOSGW_BEAST_FRONTEND */
 #if defined(WITH_RADOSGW_FCGI_FRONTEND)