]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
ike-cfg: Add helper function to determine if a given IP address was configured
authorTobias Brunner <tobias@strongswan.org>
Wed, 1 Feb 2017 17:00:57 +0000 (18:00 +0100)
committerMartin Willi <martin@strongswan.org>
Fri, 17 Feb 2017 09:52:21 +0000 (10:52 +0100)
src/libcharon/config/ike_cfg.c
src/libcharon/config/ike_cfg.h

index 8375680af85c9e52a1778267bc796a2378929b92..480dd3720ee1407ee5fdec62f795b68b0e5b017a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2016 Tobias Brunner
+ * Copyright (C) 2012-2017 Tobias Brunner
  * Copyright (C) 2005-2007 Martin Willi
  * Copyright (C) 2005 Jan Hutter
  * Hochschule fuer Technik Rapperswil
@@ -556,6 +556,39 @@ int ike_cfg_get_family(ike_cfg_t *cfg, bool local)
        return family;
 }
 
+/**
+ * Described in header.
+ */
+bool ike_cfg_has_address(ike_cfg_t *cfg, host_t *addr, bool local)
+{
+       private_ike_cfg_t *this = (private_ike_cfg_t*)cfg;
+       enumerator_t *enumerator;
+       host_t *host;
+       char *str;
+       bool found = FALSE;
+
+       if (local)
+       {
+               enumerator = this->my_hosts->create_enumerator(this->my_hosts);
+       }
+       else
+       {
+               enumerator = this->other_hosts->create_enumerator(this->other_hosts);
+       }
+       while (enumerator->enumerate(enumerator, &str))
+       {
+               host = host_create_from_string(str, 0);
+               if (host && addr->ip_equals(addr, host))
+               {
+                       found = TRUE;
+                       break;
+               }
+               DESTROY_IF(host);
+       }
+       enumerator->destroy(enumerator);
+       return found;
+}
+
 /**
  * Described in header.
  */
index afcb772fec1d19aa630cf1abb485e950e21ba26f..4d37264f60fab0b1b2d3cb0a0e06c1df3b09a360 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2016 Tobias Brunner
+ * Copyright (C) 2012-2017 Tobias Brunner
  * Copyright (C) 2005-2007 Martin Willi
  * Copyright (C) 2005 Jan Hutter
  * Hochschule fuer Technik Rapperswil
@@ -266,4 +266,15 @@ ike_cfg_t *ike_cfg_create(ike_version_t version, bool certreq, bool force_encap,
  */
 int ike_cfg_get_family(ike_cfg_t *this, bool local);
 
+/**
+ * Determine if the given address was explicitly configured as local or remote
+ * address.
+ *
+ * @param this                         ike config to check
+ * @param addr                         address to check
+ * @param local                                TRUE to check local addresses, FALSE for remote
+ * @return                                     TRUE if address was configured
+ */
+bool ike_cfg_has_address(ike_cfg_t *this, host_t *addr, bool local);
+
 #endif /** IKE_CFG_H_ @}*/