summaryrefslogtreecommitdiff
path: root/src/common/socket.h
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2015-09-26 04:57:26 +0200
committerHaru <haru@dotalux.com>2015-10-11 00:24:22 +0200
commitec725a7c59ca35a254984439585ad2be74f33d83 (patch)
tree21bca35d3b553d8465f6d1f74a5e11c6bcefde51 /src/common/socket.h
parent657e7f9c07bc1445ce785cd11772664a1848ea5a (diff)
downloadhercules-ec725a7c59ca35a254984439585ad2be74f33d83.tar.gz
hercules-ec725a7c59ca35a254984439585ad2be74f33d83.tar.bz2
hercules-ec725a7c59ca35a254984439585ad2be74f33d83.tar.xz
hercules-ec725a7c59ca35a254984439585ad2be74f33d83.zip
Changed various s_subnet arrays to VECTORs
- sockt->lan_subnet was renamed to sockt->lan_subnets. - sockt->trusted_ip was renamed to sockt->trusted_ips. - sockt->allowed_ip was renamed to sockt->allowed_ips. - Convenience macros for checking IP ranges and subnets are provided (SUBNET_MATCH, APPLY_MASK). Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/common/socket.h')
-rw-r--r--src/common/socket.h20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/common/socket.h b/src/common/socket.h
index a2dea8b74..426f8e4bb 100644
--- a/src/common/socket.h
+++ b/src/common/socket.h
@@ -7,6 +7,7 @@
#include "common/hercules.h"
#include "common/conf.h"
+#include "common/db.h"
#ifdef WIN32
# include "common/winapi.h"
@@ -118,6 +119,9 @@ struct s_subnet {
uint32 mask;
};
+/// A vector of subnets/IP ranges.
+VECTOR_STRUCT_DECL(s_subnet_vector, struct s_subnet);
+
/// Use a shortlist of sockets instead of iterating all sessions for sockets
/// that have data to send or need eof handling.
/// Adapted to use a static array instead of a linked list.
@@ -129,6 +133,11 @@ struct s_subnet {
#define CONVIP(ip) ((ip)>>24)&0xFF,((ip)>>16)&0xFF,((ip)>>8)&0xFF,((ip)>>0)&0xFF
#define MAKEIP(a,b,c,d) ((uint32)( ( ( (a)&0xFF ) << 24 ) | ( ( (b)&0xFF ) << 16 ) | ( ( (c)&0xFF ) << 8 ) | ( ( (d)&0xFF ) << 0 ) ))
+/// Applies a subnet mask to an IP
+#define APPLY_MASK(ip, mask) ((ip)&(mask))
+/// Verifies the match between two IPs, with a subnet mask applied
+#define SUBNET_MATCH(ip1, ip2, mask) (APPLY_MASK((ip1), (mask)) == APPLY_MASK((ip2), (mask)))
+
/**
* Socket.c interface, mostly for reading however.
**/
@@ -143,12 +152,9 @@ struct socket_interface {
struct socket_data **session;
- struct s_subnet *lan_subnet; ///< LAN subnets array
- int lan_subnet_count; ///< LAN subnets count
- struct s_subnet *trusted_ip; ///< Trusted IP ranges array
- int trusted_ip_count; ///< Trusted IP ranges count
- struct s_subnet *allowed_ip; ///< Allowed server IP ranges array
- int allowed_ip_count; ///< Allowed server IP ranges count
+ struct s_subnet_vector lan_subnets; ///< LAN subnets.
+ struct s_subnet_vector trusted_ips; ///< Trusted IP ranges
+ struct s_subnet_vector allowed_ips; ///< Allowed server IP ranges
/* */
void (*init) (void);
@@ -187,7 +193,7 @@ struct socket_interface {
uint32 (*lan_subnet_check) (uint32 ip, struct s_subnet *info);
bool (*allowed_ip_check) (uint32 ip);
bool (*trusted_ip_check) (uint32 ip);
- int (*net_config_read_sub) (config_setting_t *t, struct s_subnet **list, int *count, const char *filename, const char *groupname);
+ int (*net_config_read_sub) (config_setting_t *t, struct s_subnet_vector *list, const char *filename, const char *groupname);
void (*net_config_read) (const char *filename);
};