summaryrefslogtreecommitdiffstats
path: root/libglusterfs
diff options
context:
space:
mode:
Diffstat (limited to 'libglusterfs')
-rw-r--r--libglusterfs/src/common-utils.c19
-rw-r--r--libglusterfs/src/common-utils.h3
2 files changed, 21 insertions, 1 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
index 9fe1b6a4463..6ba5223da0b 100644
--- a/libglusterfs/src/common-utils.c
+++ b/libglusterfs/src/common-utils.c
@@ -1936,7 +1936,7 @@ valid_ipv4_subnetwork (const char *address)
prefixlen = strtol (slash + 1, &endptr, 10);
if ((errno != 0) || (*endptr != '\0') ||
- (prefixlen < 0) || (prefixlen > 32)) {
+ (prefixlen < 0) || (prefixlen > IPv4_ADDR_SIZE)) {
gf_log_callingfn (THIS->name, GF_LOG_WARNING,
"Invalid IPv4 subnetwork mask");
retv = _gf_false;
@@ -2132,6 +2132,23 @@ gf_sock_union_equal_addr (union gf_sock_union *a,
return _gf_false;
}
+/*
+ * Check if both have same network address.
+ * Extract the network address from the sockaddr(s) addr by applying the
+ * network mask. If they match, return boolean _gf_true, _gf_false otherwise.
+ *
+ * (x == y) <=> (x ^ y == 0)
+ * (x & y) ^ (x & z) <=> x & (y ^ z)
+ *
+ * ((ip1 & mask) == (ip2 & mask)) <=> ((mask & (ip1 ^ ip2)) == 0)
+ */
+gf_boolean_t
+mask_match(const uint32_t a, const uint32_t b, const uint32_t m)
+{
+ return (((a ^ b) & m) == 0);
+}
+
+
/*Thread safe conversion function*/
char *
uuid_utoa (uuid_t uuid)
diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h
index 61da39767a2..86848df452d 100644
--- a/libglusterfs/src/common-utils.h
+++ b/libglusterfs/src/common-utils.h
@@ -50,6 +50,8 @@ void trap (void);
#define roof(a,b) ((((a)+(b)-1)/((b)?(b):1))*(b))
#define floor(a,b) (((a)/((b)?(b):1))*(b))
+#define IPv4_ADDR_SIZE 32
+
#define GF_UNIT_KB 1024ULL
#define GF_UNIT_MB 1048576ULL
@@ -582,6 +584,7 @@ void skip_word (char **str);
/* returns a new string with nth word of given string. n>=1 */
char *get_nth_word (const char *str, int n);
+gf_boolean_t mask_match (const uint32_t a, const uint32_t b, const uint32_t m);
char valid_host_name (char *address, int length);
char valid_ipv4_address (char *address, int length, gf_boolean_t wildcard_acc);
char valid_ipv6_address (char *address, int length, gf_boolean_t wildcard_acc);