aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Sadie Powell2022-12-18 01:01:43 +0000
committerGravatar Sadie Powell2022-12-18 01:13:47 +0000
commitcf3466963b0c2f1013d8b78f0a37bbea7b6725fb (patch)
treed90e05aedd7f6a6bb9524d377acf376ce4c9f0c2
parentUse SOCKET_ADDRESS instead of u_short. (diff)
Add is_local to the sockaddrs union.
-rw-r--r--include/socket.h3
-rw-r--r--src/modules/m_spanningtree/server.cpp2
-rw-r--r--src/socket.cpp19
3 files changed, 23 insertions, 1 deletions
diff --git a/include/socket.h b/include/socket.h
index fa6ca779c..691cb196a 100644
--- a/include/socket.h
+++ b/include/socket.h
@@ -91,6 +91,9 @@ namespace irc
*/
bool from_unix(const std::string& path);
+ /** Determines whether this socket address is a local endpoint. */
+ bool is_local() const;
+
/** Returns the TCP port number of the socket address or 0 if not relevant to this family. */
int port() const;
diff --git a/src/modules/m_spanningtree/server.cpp b/src/modules/m_spanningtree/server.cpp
index 34bfadc88..79acfe744 100644
--- a/src/modules/m_spanningtree/server.cpp
+++ b/src/modules/m_spanningtree/server.cpp
@@ -138,7 +138,7 @@ std::shared_ptr<Link> TreeSocket::AuthRemote(const CommandBase::Params& params)
ssliohook->GetCiphersuite(ciphersuite);
ServerInstance->SNO.WriteToSnoMask('l', "Negotiated ciphersuite %s on link %s", ciphersuite.c_str(), x->Name.c_str());
}
- else if (capab->remotesa.family() != AF_UNIX && !irc::sockets::cidr_mask("127.0.0.0/8").match(capab->remotesa) && !irc::sockets::cidr_mask("::1/128").match(capab->remotesa))
+ else if (!capab->remotesa.is_local())
{
this->SendError("Non-local server connections MUST be linked with SSL!");
return nullptr;
diff --git a/src/socket.cpp b/src/socket.cpp
index bb2fb6b17..0f2905cfd 100644
--- a/src/socket.cpp
+++ b/src/socket.cpp
@@ -218,6 +218,25 @@ sa_family_t irc::sockets::sockaddrs::family() const
return sa.sa_family;
}
+bool irc::sockets::sockaddrs::is_local() const
+{
+ switch (family())
+ {
+ case AF_INET:
+ return irc::sockets::cidr_mask("127.0.0.0/8").match(*this);
+
+ case AF_INET6:
+ return irc::sockets::cidr_mask("::1/128").match(*this);
+
+ case AF_UNIX:
+ return true;
+ }
+
+ // If we have reached this point then we have encountered a bug.
+ ServerInstance->Logs.Debug("SOCKET", "BUG: irc::sockets::sockaddrs::is_local(): socket type %hu is unknown!", family());
+ return false;
+}
+
int irc::sockets::sockaddrs::port() const
{
switch (family())