mirror of
https://github.com/anope/anope.git
synced 2026-07-01 15:46:37 +02:00
Made session tracking ip based, not host based, and allow using CIDR to group multiple ips from one subnet to one session
This commit is contained in:
+31
-1
@@ -227,7 +227,7 @@ cidr::cidr(const Anope::string &ip, unsigned char len)
|
||||
|
||||
Anope::string cidr::mask() const
|
||||
{
|
||||
return this->cidr_ip + "/" + this->cidr_len;
|
||||
return Anope::printf("%s/%d", this->cidr_ip.c_str(), this->cidr_len);
|
||||
}
|
||||
|
||||
bool cidr::match(sockaddrs &other)
|
||||
@@ -265,6 +265,36 @@ bool cidr::match(sockaddrs &other)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cidr::operator<(const cidr &other) const
|
||||
{
|
||||
if (this->addr.sa.sa_family != other.addr.sa.sa_family)
|
||||
return this->addr.sa.sa_family < other.addr.sa.sa_family;
|
||||
|
||||
switch (this->addr.sa.sa_family)
|
||||
{
|
||||
case AF_INET:
|
||||
{
|
||||
unsigned int m = 0xFFFFFFFFU >> (32 - this->cidr_len);
|
||||
|
||||
return (this->addr.sa4.sin_addr.s_addr & m) < (other.addr.sa4.sin_addr.s_addr & m);
|
||||
}
|
||||
case AF_INET6:
|
||||
{
|
||||
int i = memcmp(&this->addr.sa6.sin6_addr.s6_addr, &other.addr.sa6.sin6_addr.s6_addr, this->cidr_len / 8);
|
||||
if (i || this->cidr_len >= 128)
|
||||
return i < 0;
|
||||
|
||||
// Now all thats left is to compare 'remainig' bits at offset this->cidr_len / 8
|
||||
int remaining = this->cidr_len % 8;
|
||||
unsigned char m = 0xFF << (8 - remaining);
|
||||
|
||||
return (this->addr.sa6.sin6_addr.s6_addr[this->cidr_len / 8] & m) < (other.addr.sa6.sin6_addr.s6_addr[this->cidr_len / 8] & m);
|
||||
}
|
||||
default:
|
||||
throw CoreException("Unknown AFTYPE for cidr");
|
||||
}
|
||||
}
|
||||
|
||||
/** Receive something from the buffer
|
||||
* @param s The socket
|
||||
* @param buf The buf to read to
|
||||
|
||||
Reference in New Issue
Block a user