summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src
diff options
context:
space:
mode:
authorRinku Kothiya <rkothiya@redhat.com>2019-01-01 21:06:05 +0530
committerAmar Tumballi <amarts@redhat.com>2019-01-18 17:13:13 +0000
commit0687b0beb5cc58d5aac9e203f0feebcd7e9eea03 (patch)
tree1816ba8a7868956702f4a6f7ecc338c4d66654b7 /libglusterfs/src
parentebaf09a2a329517936232510e117debc3795e80b (diff)
core: Feature added to accept CidrIp in auth.allow
Added functionality to gluster volume set auth.allow command to accept CIDR IP addresses. Modified few functions to isolate cidr feature so that it prevents other gluster commands such as peer probe to use cidr format ip. The functions are modified in such a way that they have an option to enable accepting of cidr format for other gluster commands if required in furture. updates: bz#1138841 Change-Id: Ie6734002a7078f1820e5df42d404411cce945e8b Credits: Mohit Agrawal Signed-off-by: Rinku Kothiya <rkothiya@redhat.com>
Diffstat (limited to 'libglusterfs/src')
-rw-r--r--libglusterfs/src/common-utils.c34
-rw-r--r--libglusterfs/src/glusterfs/common-utils.h3
-rw-r--r--libglusterfs/src/options.c6
3 files changed, 37 insertions, 6 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
index 6cefb2a439b..4104c576fd2 100644
--- a/libglusterfs/src/common-utils.c
+++ b/libglusterfs/src/common-utils.c
@@ -2090,7 +2090,7 @@ out:
* @ip_str : The IP to check
* @network: The network to check the IP against.
*
- * @return: success: 0
+ * @return: success: _gf_true
* failure: -EINVAL for bad args, retval of inet_pton otherwise
*/
gf_boolean_t
@@ -2457,6 +2457,31 @@ out:
return ret;
}
+char
+valid_cidr_address(char *cidr_address, gf_boolean_t wildcard_acc)
+{
+ unsigned int net_mask = 0, len = 0;
+ char *temp = NULL, *cidr_str = NULL, ret = 1;
+
+ cidr_str = strdupa(cidr_address);
+ temp = strstr(cidr_str, "/");
+ if (temp == NULL)
+ return 0; /* Since Invalid cidr ip address we return 0 */
+
+ *temp = '\0';
+ temp++;
+ net_mask = (unsigned int)atoi(temp);
+
+ if (net_mask > 32 || net_mask < 1)
+ return 0; /* Since Invalid cidr ip address we return 0*/
+
+ len = strlen(cidr_str);
+
+ ret = valid_ipv4_address(cidr_str, len, wildcard_acc);
+
+ return ret;
+}
+
/**
* valid_ipv4_subnetwork() takes the pattern and checks if it contains
* a valid ipv4 subnetwork pattern i.e. xx.xx.xx.xx/n. IPv4 address
@@ -2593,7 +2618,8 @@ out:
}
char
-valid_internet_address(char *address, gf_boolean_t wildcard_acc)
+valid_internet_address(char *address, gf_boolean_t wildcard_acc,
+ gf_boolean_t cidr)
{
char ret = 0;
int length = 0;
@@ -2608,6 +2634,10 @@ valid_internet_address(char *address, gf_boolean_t wildcard_acc)
if (length == 0)
goto out;
+ if (cidr && valid_cidr_address(address, wildcard_acc)) {
+ ret = 1;
+ }
+
if (valid_ipv4_address(address, length, wildcard_acc) ||
valid_ipv6_address(address, length, wildcard_acc) ||
valid_host_name(address, length))
diff --git a/libglusterfs/src/glusterfs/common-utils.h b/libglusterfs/src/glusterfs/common-utils.h
index 76d1e5feee5..b688981617d 100644
--- a/libglusterfs/src/glusterfs/common-utils.h
+++ b/libglusterfs/src/glusterfs/common-utils.h
@@ -875,7 +875,8 @@ 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);
char
-valid_internet_address(char *address, gf_boolean_t wildcard_acc);
+valid_internet_address(char *address, gf_boolean_t wildcard_acc,
+ gf_boolean_t cidr);
gf_boolean_t
valid_mount_auth_address(char *address);
gf_boolean_t
diff --git a/libglusterfs/src/options.c b/libglusterfs/src/options.c
index ccb8975b33b..da24122205e 100644
--- a/libglusterfs/src/options.c
+++ b/libglusterfs/src/options.c
@@ -551,7 +551,7 @@ xlator_option_validate_addr(xlator_t *xl, const char *key, const char *value,
int ret = -1;
char errstr[256];
- if (!valid_internet_address((char *)value, _gf_false)) {
+ if (!valid_internet_address((char *)value, _gf_false, _gf_false)) {
snprintf(errstr, 256, "option %s %s: Can not parse %s address", key,
value, value);
gf_msg(xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", errstr);
@@ -592,7 +592,7 @@ xlator_option_validate_addr_list(xlator_t *xl, const char *key,
/* Possible old format, handle it for back-ward compatibility */
addr_tok = strtok_r(dup_val, ",", &save_ptr);
while (addr_tok) {
- if (!valid_internet_address(addr_tok, _gf_true))
+ if (!valid_internet_address(addr_tok, _gf_true, _gf_true))
goto out;
addr_tok = strtok_r(NULL, ",", &save_ptr);
@@ -627,7 +627,7 @@ xlator_option_validate_addr_list(xlator_t *xl, const char *key,
if (addr_tok == NULL)
goto out;
while (addr_tok) {
- if (!valid_internet_address(addr_tok, _gf_true))
+ if (!valid_internet_address(addr_tok, _gf_true, _gf_true))
goto out;
addr_tok = strtok_r(NULL, "|", &save_ptr);