From: Peter Powell Date: Mon, 28 Aug 2017 14:37:15 +0000 (+0100) Subject: Store the server endpoint as a sockaddrs in ListenSocket. X-Git-Url: https://git.netwichtig.de/gitweb/?a=commitdiff_plain;ds=inline;h=fb13dca410541f01db84287f2721d1e256eaf2b5;p=user%2Fhenk%2Fcode%2Finspircd.git Store the server endpoint as a sockaddrs in ListenSocket. --- diff --git a/include/socket.h b/include/socket.h index 9d6c56a18..375697ea1 100644 --- a/include/socket.h +++ b/include/socket.h @@ -128,10 +128,7 @@ class CoreExport ListenSocket : public EventHandler { public: reference 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 { diff --git a/src/coremods/core_stats.cpp b/src/coremods/core_stats.cpp index b91653908..9d1fdf3fe 100644 --- a/src/coremods/core_stats.cpp +++ b/src/coremods/core_stats.cpp @@ -99,18 +99,10 @@ void CommandStats::DoStats(Stats::Context& stats) for (std::vector::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; diff --git a/src/listensocket.cpp b/src/listensocket.cpp index b56e97025..4ec6c2b06 100644 --- a/src/listensocket.cpp +++ b/src/listensocket.cpp @@ -27,11 +27,8 @@ 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); } } diff --git a/src/modules/m_flashpolicyd.cpp b/src/modules/m_flashpolicyd.cpp index b44b72dbf..4e7af4b83 100644 --- a/src/modules/m_flashpolicyd.cpp +++ b/src/modules/m_flashpolicyd.cpp @@ -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()) diff --git a/src/socket.cpp b/src/socket.cpp index 0ba57a810..a5c1c679a 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -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::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