summaryrefslogtreecommitdiff
path: root/src/libstrongswan/ipsec
diff options
context:
space:
mode:
authorYves-Alexis Perez <corsac@debian.org>2013-11-01 13:32:07 +0100
committerYves-Alexis Perez <corsac@debian.org>2013-11-01 13:32:07 +0100
commit5313d2d78ca150515f7f5eb39801c100690b6b29 (patch)
treec78e420367283bb1b16f14210b12687cdfbd26eb /src/libstrongswan/ipsec
parent6b99c8d9cff7b3e8ae8f3204b99e7ea40f791349 (diff)
downloadvyos-strongswan-5313d2d78ca150515f7f5eb39801c100690b6b29.tar.gz
vyos-strongswan-5313d2d78ca150515f7f5eb39801c100690b6b29.zip
Imported Upstream version 5.1.1
Diffstat (limited to 'src/libstrongswan/ipsec')
-rw-r--r--src/libstrongswan/ipsec/ipsec_types.c37
-rw-r--r--src/libstrongswan/ipsec/ipsec_types.h11
2 files changed, 46 insertions, 2 deletions
diff --git a/src/libstrongswan/ipsec/ipsec_types.c b/src/libstrongswan/ipsec/ipsec_types.c
index e4e927313..4bbd918a0 100644
--- a/src/libstrongswan/ipsec/ipsec_types.c
+++ b/src/libstrongswan/ipsec/ipsec_types.c
@@ -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,38 @@ ENUM(ipcomp_transform_names, IPCOMP_NONE, IPCOMP_LZJH,
"IPCOMP_LZS",
"IPCOMP_LZJH"
);
+
+/*
+ * See header
+ */
+bool mark_from_string(const char *value, mark_t *mark)
+{
+ char *endptr;
+
+ if (!value)
+ {
+ return FALSE;
+ }
+ 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;
+}
diff --git a/src/libstrongswan/ipsec/ipsec_types.h b/src/libstrongswan/ipsec/ipsec_types.h
index 32e55bc50..6851f916a 100644
--- a/src/libstrongswan/ipsec/ipsec_types.h
+++ b/src/libstrongswan/ipsec/ipsec_types.h
@@ -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
@@ -169,4 +169,13 @@ struct mark_t {
*/
#define MARK_REQID (0xFFFFFFFF)
+/**
+ * Try to parse a mark_t from the given string of the form mark[/mask].
+ *
+ * @param value string to parse
+ * @param mark mark to fill
+ * @return TRUE if parsing was successful
+ */
+bool mark_from_string(const char *value, mark_t *mark);
+
#endif /** IPSEC_TYPES_H_ @}*/