child-rekey: Don't change state to INSTALLED if it was already REKEYING
[strongswan.git] / src / libstrongswan / ipsec / ipsec_types.c
index e4e9273..a52a1eb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 Tobias Brunner
+ * Copyright (C) 2012-2013 Tobias Brunner
  * Hochschule fuer Technik Rapperswil
  *
  * This program is free software; you can redistribute it and/or modify it
@@ -36,3 +36,62 @@ ENUM(ipcomp_transform_names, IPCOMP_NONE, IPCOMP_LZJH,
        "IPCOMP_LZS",
        "IPCOMP_LZJH"
 );
+
+/*
+ * See header
+ */
+bool ipsec_sa_cfg_equals(ipsec_sa_cfg_t *a, ipsec_sa_cfg_t *b)
+{
+       return a->mode == b->mode &&
+               a->reqid == b->reqid &&
+               a->policy_count == b->policy_count &&
+               a->esp.use == b->esp.use &&
+               a->esp.spi == b->esp.spi &&
+               a->ah.use == b->ah.use &&
+               a->ah.spi == b->ah.spi &&
+               a->ipcomp.transform == b->ipcomp.transform &&
+               a->ipcomp.cpi == b->ipcomp.cpi;
+}
+
+/*
+ * See header
+ */
+bool mark_from_string(const char *value, mark_t *mark)
+{
+       char *endptr;
+
+       if (!value)
+       {
+               return FALSE;
+       }
+       if (strcasepfx(value, "%unique"))
+       {
+               mark->value = MARK_UNIQUE;
+               endptr = (char*)value + strlen("%unique");
+       }
+       else
+       {
+               mark->value = strtoul(value, &endptr, 0);
+       }
+       if (*endptr)
+       {
+               if (*endptr != '/')
+               {
+                       DBG1(DBG_APP, "invalid mark value: %s", value);
+                       return FALSE;
+               }
+               mark->mask = strtoul(endptr+1, &endptr, 0);
+               if (*endptr)
+               {
+                       DBG1(DBG_LIB, "invalid mark mask: %s", endptr);
+                       return FALSE;
+               }
+       }
+       else
+       {
+               mark->mask = 0xffffffff;
+       }
+       /* apply the mask to ensure the value is in range */
+       mark->value &= mark->mask;
+       return TRUE;
+}