]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: beast frontend parses ipv6 addrs 25079/head
authorCasey Bodley <cbodley@redhat.com>
Thu, 1 Nov 2018 20:17:11 +0000 (16:17 -0400)
committerJonathan Brielmaier <jbrielmaier@suse.de>
Tue, 13 Nov 2018 15:28:24 +0000 (16:28 +0100)
Fixes: http://tracker.ceph.com/issues/36662
Signed-off-by: Casey Bodley <cbodley@redhat.com>
(cherry picked from commit a3b4124fd258887ff4cb3f65967f593658a41f4f)
Signed-off-by: Jonathan Brielmaier <jbrielmaier@suse.de>
doc/radosgw/frontends.rst
src/rgw/rgw_asio_frontend.cc

index 768e1d777950c607e7567dd451437fa5d1386e9d..a33a42392f3627a60aaca659349a40212d28b38c 100644 (file)
@@ -31,10 +31,10 @@ Options
 
 :Description: Sets the listening address in the form ``address[:port]``,
               where the address is an IPv4 address string in dotted decimal
-              form, or an IPv6 address in hexadecimal notation. The
-              optional port defaults to 80 for ``endpoint`` and 443 for
-              ``ssl_endpoint``. Can be specified multiple times as in
-              ``endpoint=::1 endpoint=192.168.0.100:8000``.
+              form, or an IPv6 address in hexadecimal notation surrounded
+              by square brackets. The optional port defaults to 80 for
+              ``endpoint`` and 443 for ``ssl_endpoint``. Can be specified
+              multiple times as in ``endpoint=[::1] endpoint=192.168.0.100:8000``.
 
 :Type: Integer
 :Default: None
index 42efc13c7c562910c7685a9664d2a637206a7bbd..3c6ae446990eed00b52469ea6d3e1f457c44508e 100644 (file)
@@ -262,16 +262,41 @@ tcp::endpoint parse_endpoint(boost::asio::string_view input,
 {
   tcp::endpoint endpoint;
 
-  auto colon = input.find(':');
-  if (colon != input.npos) {
-    auto port_str = input.substr(colon + 1);
-    endpoint.port(parse_port(port_str.data(), ec));
-  } else {
-    endpoint.port(default_port);
+  if (input.empty()) {
+    ec = boost::asio::error::invalid_argument;
+    return endpoint;
   }
-  if (!ec) {
+
+  if (input[0] == '[') { // ipv6
+    const size_t addr_begin = 1;
+    const size_t addr_end = input.find(']');
+    if (addr_end == input.npos) { // no matching ]
+      ec = boost::asio::error::invalid_argument;
+      return endpoint;
+    }
+    if (addr_end + 1 < input.size()) {
+      // :port must must follow [ipv6]
+      if (input[addr_end + 1] != ':') {
+        ec = boost::asio::error::invalid_argument;
+        return endpoint;
+      } else {
+        auto port_str = input.substr(addr_end + 2);
+        endpoint.port(parse_port(port_str.data(), ec));
+      }
+    }
+    auto addr = input.substr(addr_begin, addr_end - addr_begin);
+    endpoint.address(boost::asio::ip::make_address_v6(addr, ec));
+  } else { // ipv4
+    auto colon = input.find(':');
+    if (colon != input.npos) {
+      auto port_str = input.substr(colon + 1);
+      endpoint.port(parse_port(port_str.data(), ec));
+      if (ec) {
+        return endpoint;
+      }
+    }
     auto addr = input.substr(0, colon);
-    endpoint.address(boost::asio::ip::make_address(addr, ec));
+    endpoint.address(boost::asio::ip::make_address_v4(addr, ec));
   }
   return endpoint;
 }