changeset 428:ce1903f4bdb7 release-2.1

Fix #637: check for domain and family options The decision was not clear between the two option names, the documentation stated to use family but the code checked for family. Accept both for compatibility purposes and unify the documentation using the family name. Task: #637 Errata: 20170218
author David Demelier <markand@malikania.fr>
date Sat, 18 Feb 2017 09:08:51 +0100
parents e1373abccacb
children e85366a81ab4
files irccdctl/main.cpp libirccd/irccd/config.cpp libirccd/irccd/transport.cpp
diffstat 3 files changed, 15 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/irccdctl/main.cpp	Thu Feb 16 18:53:30 2017 +0100
+++ b/irccdctl/main.cpp	Sat Feb 18 09:08:51 2017 +0100
@@ -132,13 +132,13 @@
 
     int domain = AF_INET;
 
-    if ((it = sc.find("domain")) != sc.end()) {
+    if ((it = sc.find("domain")) != sc.end() || (it = sc.find("family")) != sc.end()) {
         if (it->value() == "ipv6") {
             domain = AF_INET6;
         } else if (it->value() == "ipv4") {
             domain = AF_INET;
         } else {
-            throw std::invalid_argument("invalid domain: " + it->value());
+            throw std::invalid_argument("invalid family: " + it->value());
         }
     }
 
--- a/libirccd/irccd/config.cpp	Thu Feb 16 18:53:30 2017 +0100
+++ b/libirccd/irccd/config.cpp	Sat Feb 18 09:08:51 2017 +0100
@@ -157,10 +157,16 @@
     if ((it = sc.find("address")) != sc.end())
         address = it->value();
 
-    // Domain
     std::uint8_t mode = TransportServerIp::v4;
 
-    if ((it = sc.find("domain")) != sc.end()) {
+    /*
+     * Documentation stated family but code checked for 'domain' option.
+     *
+     * As irccdctl uses domain, accept both and unify the option name to 'family'.
+     *
+     * See #637
+     */
+    if ((it = sc.find("domain")) != sc.end() || (it = sc.find("family")) != sc.end()) {
         mode = 0;
 
         for (const auto &v : *it) {
@@ -188,7 +194,7 @@
     }
 
     if (mode == 0)
-        throw std::invalid_argument("transport: domain must at least have ipv4 or ipv6");
+        throw std::invalid_argument("transport: family must at least have ipv4 or ipv6");
 
     if (pkey.empty())
         return std::make_shared<TransportServerIp>(address, port, mode);
--- a/libirccd/irccd/transport.cpp	Thu Feb 16 18:53:30 2017 +0100
+++ b/libirccd/irccd/transport.cpp	Sat Feb 18 09:08:51 2017 +0100
@@ -376,14 +376,14 @@
     m_socket.set(net::option::SockReuseAddress(true));
 
     if (mode & v6) {
+        // Disable or enable IPv4 when using IPv6.
+        if (!(mode & v4))
+            m_socket.set(net::option::Ipv6Only(true));
+
         if (address == "*")
             m_socket.bind(net::ipv6::any(port));
         else
             m_socket.bind(net::ipv6::pton(address, port));
-
-        // Disable or enable IPv4 when using IPv6.
-        if (!(mode & v4))
-            m_socket.set(net::option::Ipv6Only(true));
     } else {
         if (address == "*")
             m_socket.bind(net::ipv4::any(port));