]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Store the server endpoint as a sockaddrs in ListenSocket.
authorPeter Powell <petpow@saberuk.com>
Mon, 28 Aug 2017 14:37:15 +0000 (15:37 +0100)
committerPeter Powell <petpow@saberuk.com>
Tue, 12 Sep 2017 14:05:24 +0000 (15:05 +0100)
include/socket.h
src/coremods/core_stats.cpp
src/listensocket.cpp
src/modules/m_flashpolicyd.cpp
src/socket.cpp

index 9d6c56a182f9c05a426b8758c6067ef7f8113c31..375697ea17e654e5f70432524450b9a3480f19b6 100644 (file)
@@ -128,10 +128,7 @@ class CoreExport ListenSocket : public EventHandler
 {
  public:
        reference<ConfigTag> bind_tag;
-       std::string bind_addr;
-       int bind_port;
-       /** Human-readable bind description */
-       std::string bind_desc;
+       const irc::sockets::sockaddrs bind_sa;
 
        class IOHookProvRef : public dynamic_reference_nocheck<IOHookProvider>
        {
index b9165390872665dd33183b735087096dabf15bb1..9d1fdf3fe17a19f5513c6540c12f2572e0cdbf39 100644 (file)
@@ -99,18 +99,10 @@ void CommandStats::DoStats(Stats::Context& stats)
                        for (std::vector<ListenSocket*>::const_iterator i = ServerInstance->ports.begin(); i != ServerInstance->ports.end(); ++i)
                        {
                                ListenSocket* ls = *i;
-                               std::string ip = ls->bind_addr;
-                               if (ip.empty())
-                                       ip.assign("*");
-                               else if (ip.find_first_of(':') != std::string::npos)
-                               {
-                                       ip.insert(ip.begin(), '[');
-                                       ip.insert(ip.end(),  ']');
-                               }
                                std::string type = ls->bind_tag->getString("type", "clients");
                                std::string hook = ls->bind_tag->getString("ssl", "plaintext");
 
-                               stats.AddRow(249, ip + ":"+ConvToStr(ls->bind_port) + " (" + type + ", " + hook + ")");
+                               stats.AddRow(249, ls->bind_sa.str() + " (" + type + ", " + hook + ")");
                        }
                }
                break;
index b56e970253533a3de9b421bd6513b66c7601aaba..4ec6c2b0642453b7dfc31b9a563d7bec46e817d4 100644 (file)
 
 ListenSocket::ListenSocket(ConfigTag* tag, const irc::sockets::sockaddrs& bind_to)
        : bind_tag(tag)
+       , bind_sa(bind_to)
 {
-       bind_addr = bind_to.addr();
-       bind_port = bind_to.port();
-       bind_desc = bind_to.str();
-
        fd = socket(bind_to.sa.sa_family, SOCK_STREAM, 0);
 
        if (this->fd == -1)
@@ -119,12 +116,12 @@ ListenSocket::~ListenSocket()
 void ListenSocket::OnEventHandlerRead()
 {
        irc::sockets::sockaddrs client;
-       irc::sockets::sockaddrs server;
+       irc::sockets::sockaddrs server(bind_sa);
 
        socklen_t length = sizeof(client);
        int incomingSockfd = SocketEngine::Accept(this, &client.sa, &length);
 
-       ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "Accepting connection on socket %s fd %d", bind_desc.c_str(), incomingSockfd);
+       ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "Accepting connection on socket %s fd %d", bind_sa.str().c_str(), incomingSockfd);
        if (incomingSockfd < 0)
        {
                ServerInstance->stats.Refused++;
@@ -135,7 +132,6 @@ void ListenSocket::OnEventHandlerRead()
        if (getsockname(incomingSockfd, &server.sa, &sz))
        {
                ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "Can't get peername: %s", strerror(errno));
-               irc::sockets::aptosa(bind_addr, bind_port, server);
        }
 
        if (client.sa.sa_family == AF_INET6)
@@ -189,7 +185,7 @@ void ListenSocket::OnEventHandlerRead()
        {
                ServerInstance->stats.Refused++;
                ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "Refusing connection on %s - %s",
-                       bind_desc.c_str(), res == MOD_RES_DENY ? "Connection refused by module" : "Module for this port not found");
+                       bind_sa.str().c_str(), res == MOD_RES_DENY ? "Connection refused by module" : "Module for this port not found");
                SocketEngine::Close(incomingSockfd);
        }
 }
index b44b72dbfebfe56c8bb418c465a241d30bbdb0b0..4e7af4b836f7ad06fbab401f11c3bfd0bd47db8f 100644 (file)
@@ -126,7 +126,7 @@ class ModuleFlashPD : public Module
                                if (ls->bind_tag->getString("type", "clients") != "clients" || ls->bind_tag->getString("ssl", "plaintext") != "plaintext")
                                        continue;
 
-                               to_ports.append(ConvToStr(ls->bind_port)).push_back(',');
+                               to_ports.append(ConvToStr(ls->bind_sa.port())).push_back(',');
                }
 
                if (to_ports.empty())
index 0ba57a81009c3810745609a305a850f31dd85e2c..a5c1c679a8ef5822f151b5064ec3e28670e8b7ca 100644 (file)
@@ -45,12 +45,11 @@ int InspIRCd::BindPorts(FailedPortList &failed_ports)
                        irc::sockets::sockaddrs bindspec;
                        if (!irc::sockets::aptosa(Addr, portno, bindspec))
                                continue;
-                       std::string bind_readable = bindspec.str();
 
                        bool skip = false;
                        for (std::vector<ListenSocket*>::iterator n = old_ports.begin(); n != old_ports.end(); ++n)
                        {
-                               if ((**n).bind_desc == bind_readable)
+                               if ((**n).bind_sa == bindspec)
                                {
                                        (*n)->bind_tag = tag; // Replace tag, we know addr and port match, but other info (type, ssl) may not
                                        (*n)->ResetIOHookProvider();
@@ -71,7 +70,7 @@ int InspIRCd::BindPorts(FailedPortList &failed_ports)
                                }
                                else
                                {
-                                       failed_ports.push_back(std::make_pair(bind_readable, strerror(errno)));
+                                       failed_ports.push_back(std::make_pair(bindspec.str(), strerror(errno)));
                                        delete ll;
                                }
                        }
@@ -90,7 +89,7 @@ int InspIRCd::BindPorts(FailedPortList &failed_ports)
                }
 
                this->Logs->Log("SOCKET", LOG_DEFAULT, "Port binding %s was removed from the config file, closing.",
-                       (**n).bind_desc.c_str());
+                       (**n).bind_sa.str().c_str());
                delete *n;
 
                // this keeps the iterator valid, pointing to the next element