aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan
diff options
context:
space:
mode:
authorMartin Willi <martin@strongswan.org>2006-07-27 12:18:40 +0000
committerMartin Willi <martin@strongswan.org>2006-07-27 12:18:40 +0000
commitfe04e93a8b3306cf67ab726cd0ad06312a7ed3f6 (patch)
tree116cd00b78693c1ca5e95bb0ac5918e02fc2aa0e /src/libstrongswan
parent45f76a7dddd7924af6699264ccc946a1ec99c1c8 (diff)
downloadstrongswan-fe04e93a8b3306cf67ab726cd0ad06312a7ed3f6.tar.bz2
strongswan-fe04e93a8b3306cf67ab726cd0ad06312a7ed3f6.tar.xz
implemented IKE_SA rekeying
uses ikelifetime, rekeymargin and rekeyfuzz config settings no handling of simultaneus exchanges yet!
Diffstat (limited to 'src/libstrongswan')
-rw-r--r--src/libstrongswan/types.c49
-rw-r--r--src/libstrongswan/types.h7
2 files changed, 56 insertions, 0 deletions
diff --git a/src/libstrongswan/types.c b/src/libstrongswan/types.c
index c0b1a9d30..b60a604b8 100644
--- a/src/libstrongswan/types.c
+++ b/src/libstrongswan/types.c
@@ -24,6 +24,7 @@
#include <string.h>
#include <time.h>
#include <stdio.h>
+#include <stdarg.h>
#include "types.h"
@@ -69,6 +70,54 @@ chunk_t chunk_clone(chunk_t chunk)
}
/**
+ * Decribed in header.
+ */
+chunk_t chunk_cat(const char* mode, ...)
+{
+ chunk_t construct;
+ va_list chunks;
+ u_char *pos;
+ int i;
+ int count = strlen(mode);
+
+ /* sum up lengths of individual chunks */
+ va_start(chunks, mode);
+ construct.len = 0;
+ for (i = 0; i < count; i++)
+ {
+ chunk_t ch = va_arg(chunks, chunk_t);
+ construct.len += ch.len;
+ }
+ va_end(chunks);
+
+ /* allocate needed memory for construct */
+ construct.ptr = malloc(construct.len);
+ pos = construct.ptr;
+
+ /* copy or move the chunks */
+ va_start(chunks, mode);
+ for (i = 0; i < count; i++)
+ {
+ chunk_t ch = va_arg(chunks, chunk_t);
+ switch (*mode++)
+ {
+ case 'm':
+ memcpy(pos, ch.ptr, ch.len);
+ pos += ch.len;
+ free(ch.ptr);
+ break;
+ case 'c':
+ default:
+ memcpy(pos, ch.ptr, ch.len);
+ pos += ch.len;
+ }
+ }
+ va_end(chunks);
+
+ return construct;
+}
+
+/**
* Described in header.
*/
void chunk_free(chunk_t *chunk)
diff --git a/src/libstrongswan/types.h b/src/libstrongswan/types.h
index d859d8402..631e5025b 100644
--- a/src/libstrongswan/types.h
+++ b/src/libstrongswan/types.h
@@ -161,6 +161,13 @@ extern chunk_t CHUNK_INITIALIZER;
chunk_t chunk_clone(chunk_t chunk);
/**
+ * Allocate a chunk from concatenation of other chunks.
+ * mode is a string 'm' and 'c, 'm' means move chunk,
+ * 'c' means copy chunk.
+ */
+chunk_t chunk_cat(const char* mode, ...);
+
+/**
* Free contents of a chunk
*/
void chunk_free(chunk_t *chunk);