summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2014-06-07 13:30:14 +0200
committerAttila Molnar <attilamolnar@hush.com>2014-06-07 13:30:14 +0200
commit30fec322809582f91be70cc1bb16c9678180db76 (patch)
tree464446f79af6259b4e280514eac25bea7777b014
parent4d7c590bb6a937c4c412241ae67b9fc74083b365 (diff)
Relax fd bounds checking
We can cope with fds greater than SocketEngine::GetMaxFds() since 3752b3f59d5216d7dc6221a361efc76b9ad2273d
-rw-r--r--src/listensocket.cpp19
-rw-r--r--src/socketengine.cpp2
-rw-r--r--src/socketengines/socketengine_epoll.cpp8
-rw-r--r--src/socketengines/socketengine_kqueue.cpp4
-rw-r--r--src/socketengines/socketengine_poll.cpp8
-rw-r--r--src/socketengines/socketengine_ports.cpp4
-rw-r--r--src/usermanager.cpp2
7 files changed, 14 insertions, 33 deletions
diff --git a/src/listensocket.cpp b/src/listensocket.cpp
index e73a8f4ce..cb4bfd2db 100644
--- a/src/listensocket.cpp
+++ b/src/listensocket.cpp
@@ -125,25 +125,6 @@ void ListenSocket::AcceptInternal()
irc::sockets::aptosa(bind_addr, bind_port, server);
}
- /*
- * XXX -
- * this is done as a safety check to keep the file descriptors within range of fd_ref_table.
- * its a pretty big but for the moment valid assumption:
- * file descriptors are handed out starting at 0, and are recycled as theyre freed.
- * therefore if there is ever an fd over 65535, 65536 clients must be connected to the
- * irc server at once (or the irc server otherwise initiating this many connections, files etc)
- * which for the time being is a physical impossibility (even the largest networks dont have more
- * than about 10,000 users on ONE server!)
- */
- if (incomingSockfd >= SocketEngine::GetMaxFds())
- {
- ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "Server is full");
- SocketEngine::Shutdown(incomingSockfd, 2);
- SocketEngine::Close(incomingSockfd);
- ServerInstance->stats->statsRefused++;
- return;
- }
-
if (client.sa.sa_family == AF_INET6)
{
/*
diff --git a/src/socketengine.cpp b/src/socketengine.cpp
index 86608f0a3..c6c520efc 100644
--- a/src/socketengine.cpp
+++ b/src/socketengine.cpp
@@ -136,7 +136,7 @@ bool SocketEngine::BoundsCheckFd(EventHandler* eh)
{
if (!eh)
return false;
- if ((eh->GetFd() < 0) || (eh->GetFd() > GetMaxFds()))
+ if (eh->GetFd() < 0)
return false;
return true;
}
diff --git a/src/socketengines/socketengine_epoll.cpp b/src/socketengines/socketengine_epoll.cpp
index 26dfc8f2f..a54907fca 100644
--- a/src/socketengines/socketengine_epoll.cpp
+++ b/src/socketengines/socketengine_epoll.cpp
@@ -102,9 +102,9 @@ static unsigned mask_to_epoll(int event_mask)
bool SocketEngine::AddFd(EventHandler* eh, int event_mask)
{
int fd = eh->GetFd();
- if ((fd < 0) || (fd > GetMaxFds() - 1))
+ if (fd < 0)
{
- ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "AddFd out of range: (fd: %d, max: %d)", fd, GetMaxFds());
+ ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "AddFd out of range: (fd: %d)", fd);
return false;
}
@@ -151,9 +151,9 @@ void SocketEngine::OnSetEvent(EventHandler* eh, int old_mask, int new_mask)
void SocketEngine::DelFd(EventHandler* eh)
{
int fd = eh->GetFd();
- if ((fd < 0) || (fd > GetMaxFds() - 1))
+ if (fd < 0)
{
- ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "DelFd out of range: (fd: %d, max: %d)", fd, GetMaxFds());
+ ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "DelFd out of range: (fd: %d)", fd);
return;
}
diff --git a/src/socketengines/socketengine_kqueue.cpp b/src/socketengines/socketengine_kqueue.cpp
index b7797a82f..68c1bda8c 100644
--- a/src/socketengines/socketengine_kqueue.cpp
+++ b/src/socketengines/socketengine_kqueue.cpp
@@ -105,7 +105,7 @@ bool SocketEngine::AddFd(EventHandler* eh, int event_mask)
{
int fd = eh->GetFd();
- if ((fd < 0) || (fd > GetMaxFds() - 1))
+ if (fd < 0)
return false;
if (!SocketEngine::AddFdRef(eh))
@@ -128,7 +128,7 @@ void SocketEngine::DelFd(EventHandler* eh)
{
int fd = eh->GetFd();
- if ((fd < 0) || (fd > GetMaxFds() - 1))
+ if (fd < 0)
{
ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "DelFd() on invalid fd: %d", fd);
return;
diff --git a/src/socketengines/socketengine_poll.cpp b/src/socketengines/socketengine_poll.cpp
index 8fa0a13c5..4eca494cf 100644
--- a/src/socketengines/socketengine_poll.cpp
+++ b/src/socketengines/socketengine_poll.cpp
@@ -80,9 +80,9 @@ static int mask_to_poll(int event_mask)
bool SocketEngine::AddFd(EventHandler* eh, int event_mask)
{
int fd = eh->GetFd();
- if ((fd < 0) || (fd > GetMaxFds() - 1))
+ if (fd < 0)
{
- ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "AddFd out of range: (fd: %d, max: %d)", fd, GetMaxFds());
+ ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "AddFd out of range: (fd: %d)", fd);
return false;
}
@@ -128,9 +128,9 @@ void SocketEngine::OnSetEvent(EventHandler* eh, int old_mask, int new_mask)
void SocketEngine::DelFd(EventHandler* eh)
{
int fd = eh->GetFd();
- if ((fd < 0) || (fd > MAX_DESCRIPTORS))
+ if (fd < 0)
{
- ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "DelFd out of range: (fd: %d, max: %d)", fd, GetMaxFds());
+ ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "DelFd out of range: (fd: %d)", fd);
return;
}
diff --git a/src/socketengines/socketengine_ports.cpp b/src/socketengines/socketengine_ports.cpp
index c30400107..deafd8fcb 100644
--- a/src/socketengines/socketengine_ports.cpp
+++ b/src/socketengines/socketengine_ports.cpp
@@ -95,7 +95,7 @@ static int mask_to_events(int event_mask)
bool SocketEngine::AddFd(EventHandler* eh, int event_mask)
{
int fd = eh->GetFd();
- if ((fd < 0) || (fd > GetMaxFds() - 1))
+ if (fd < 0)
return false;
if (!SocketEngine::AddFdRef(eh))
@@ -119,7 +119,7 @@ void SocketEngine::OnSetEvent(EventHandler* eh, int old_mask, int new_mask)
void SocketEngine::DelFd(EventHandler* eh)
{
int fd = eh->GetFd();
- if ((fd < 0) || (fd > GetMaxFds() - 1))
+ if (fd < 0)
return;
port_dissociate(EngineHandle, PORT_SOURCE_FD, fd);
diff --git a/src/usermanager.cpp b/src/usermanager.cpp
index 5dc410fff..3c234f13f 100644
--- a/src/usermanager.cpp
+++ b/src/usermanager.cpp
@@ -77,7 +77,7 @@ void UserManager::AddUser(int socket, ListenSocket* via, irc::sockets::sockaddrs
this->local_users.push_front(New);
- if ((this->local_users.size() > ServerInstance->Config->SoftLimit) || (this->local_users.size() >= (unsigned int)SocketEngine::GetMaxFds()))
+ if (this->local_users.size() > ServerInstance->Config->SoftLimit)
{
ServerInstance->SNO->WriteToSnoMask('a', "Warning: softlimit value has been reached: %d clients", ServerInstance->Config->SoftLimit);
this->QuitUser(New,"No more connections allowed");