Jelajahi Sumber

modules/ipops: Corrected is_in_subnet() exported function and added is_ip to module C API

- Fixes and enhancements by Hugh Waite @ Crocodile RCS
Peter Dunkley 13 tahun lalu
induk
melakukan
8ab4daa7f1
3 mengubah file dengan 16 tambahan dan 1 penghapusan
  1. 12 0
      modules/ipops/api.c
  2. 3 0
      modules/ipops/api.h
  3. 1 1
      modules/ipops/ipops_mod.c

+ 12 - 0
modules/ipops/api.c

@@ -117,6 +117,17 @@ int ipopsapi_ip_is_in_subnet(const str *const ip1, const str *const ip2)
     return -1;
 }
 
+/**
+ *
+ */
+int ipopsapi_is_ip(const str * const ip)
+{
+  if (ip_parser_execute(ip->s, ip->len) != ip_type_error)
+    return 1;
+  else
+    return -1;
+}
+
 /**
  *
  */
@@ -128,6 +139,7 @@ int bind_ipops(ipops_api_t* api)
 	}
 	api->compare_ips     = ipopsapi_compare_ips;
 	api->ip_is_in_subnet = ipopsapi_ip_is_in_subnet;
+	api->is_ip           = ipopsapi_is_ip;
 
 	return 0;
 }

+ 3 - 0
modules/ipops/api.h

@@ -36,12 +36,15 @@ int ipopsapi_compare_ips(const str *const ip1, const str *const ip2);
 typedef int (*ip_is_in_subnet_f)(const str *const, const str *const);
 int ipopsapi_ip_is_in_subnet(const str *const ip1, const str *const ip2);
 
+typedef int (*is_ip_f)(const str * const ip);
+int ipopsapi_is_ip(const str * const ip);
 /**
  * @brief IPOPS API structure
  */
 typedef struct ipops_api {
 	compare_ips_f       compare_ips;
 	ip_is_in_subnet_f   ip_is_in_subnet;
+	is_ip_f   is_ip;
 } ipops_api_t;
 
 typedef int (*bind_ipops_f)(ipops_api_t* api);

+ 1 - 1
modules/ipops/ipops_mod.c

@@ -108,7 +108,7 @@ static cmd_export_t cmds[] =
   REQUEST_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE },
   { "is_ip_rfc1918", (cmd_function)w_is_ip_rfc1918, 1, fixup_spve_null, 0,
   REQUEST_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE },
-  { "is_in_subnet", (cmd_function)w_ip_is_in_subnet, 2, fixup_spve_null, 0,
+  { "is_in_subnet", (cmd_function)w_ip_is_in_subnet, 2, fixup_spve_spve, 0,
   REQUEST_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE },
   { "bind_ipops", (cmd_function)bind_ipops, 0, 0, 0, 0},
   { 0, 0, 0, 0, 0, 0 }