Browse code

ipops: proper return code for ip_is_in_subnet()

- returning 0 stopos the config execution, do -1 instead
- reported by A Messina, GH #1018

Daniel-Constantin Mierla authored on 05/03/2017 08:45:37
Showing 1 changed files
... ...
@@ -77,7 +77,8 @@ MODULE_VERSION
77 77
 int _compare_ips(char*, size_t, enum enum_ip_type, char*, size_t, enum enum_ip_type);
78 78
 int _compare_ips_v4(struct in_addr *ip, char*, size_t);
79 79
 int _compare_ips_v6(struct in6_addr *ip, char*, size_t);
80
-int _ip_is_in_subnet(char *ip1, size_t len1, enum enum_ip_type ip1_type, char *ip2, size_t len2, enum enum_ip_type ip2_type, int netmask);
80
+int _ip_is_in_subnet(char *ip1, size_t len1, enum enum_ip_type ip1_type,
81
+		char *ip2, size_t len2, enum enum_ip_type ip2_type, int netmask);
81 82
 int _ip_is_in_subnet_v4(struct in_addr *ip, char *net, size_t netlen, int netmask);
82 83
 int _ip_is_in_subnet_v6(struct in6_addr *ip, char *net, size_t netlen, int netmask);
83 84
 int _ip_is_in_subnet_str(void *ip, enum enum_ip_type type, char *s, int slen);
... ...
@@ -304,8 +305,10 @@ int _compare_ips_v6(struct in6_addr *ip, char* ip2, size_t len2)
304 305
 	return 0;
305 306
 }
306 307
 
307
-/*! \brief Return 1 if IP1 is in the subnet given by IP2 and the netmask, 0 otherwise. */
308
-int _ip_is_in_subnet(char *ip1, size_t len1, enum enum_ip_type ip1_type, char *ip2, size_t len2, enum enum_ip_type ip2_type, int netmask)
308
+/*! \brief Return 1 if IP1 is in the subnet given by IP2 and the netmask,
309
+ * 0 otherwise. */
310
+int _ip_is_in_subnet(char *ip1, size_t len1, enum enum_ip_type ip1_type,
311
+		char *ip2, size_t len2, enum enum_ip_type ip2_type, int netmask)
309 312
 {
310 313
 	struct in_addr in_addr1, in_addr2;
311 314
 	struct in6_addr in6_addr1, in6_addr2;
... ...
@@ -875,7 +878,9 @@ static int w_ip_is_in_subnet(struct sip_msg* _msg, char* _s1, char* _s2)
875 878
 		if((ret = _ip_is_in_subnet_str_trimmed(ip,ip1_type,b,e))>0) return ret;
876 879
 	}
877 880
 	e = string2.s+string2.len;
878
-	return _ip_is_in_subnet_str_trimmed(ip,ip1_type,b,e);
881
+	ret = _ip_is_in_subnet_str_trimmed(ip,ip1_type,b,e);
882
+	if(ret==0) return -1;
883
+	return ret;
879 884
 }
880 885
 
881 886