aboutsummaryrefslogtreecommitdiffstats
path: root/src/libimcv/seg
diff options
context:
space:
mode:
authorAndreas Steffen <andreas.steffen@strongswan.org>2014-10-11 14:49:23 +0200
committerAndreas Steffen <andreas.steffen@strongswan.org>2014-10-11 14:50:08 +0200
commit8b812065f04171944b8fc1e86775b6c9df8d23ff (patch)
tree504780aed658d8fdb21495fa0da3cf50f1f2bc98 /src/libimcv/seg
parentab999396281b2c15b53626d79fb5c5742f9cdca1 (diff)
downloadstrongswan-8b812065f04171944b8fc1e86775b6c9df8d23ff.tar.bz2
strongswan-8b812065f04171944b8fc1e86775b6c9df8d23ff.tar.xz
Support of multiple directed segmentation contracts
Diffstat (limited to 'src/libimcv/seg')
-rw-r--r--src/libimcv/seg/seg_contract.c57
-rw-r--r--src/libimcv/seg/seg_contract.h28
-rw-r--r--src/libimcv/seg/seg_contract_manager.c7
-rw-r--r--src/libimcv/seg/seg_contract_manager.h4
4 files changed, 88 insertions, 8 deletions
diff --git a/src/libimcv/seg/seg_contract.c b/src/libimcv/seg/seg_contract.c
index df25e64e9..7db702a08 100644
--- a/src/libimcv/seg/seg_contract.c
+++ b/src/libimcv/seg/seg_contract.c
@@ -72,11 +72,16 @@ struct private_seg_contract_t {
bool is_issuer;
/**
- * Issuer ID (either IMV ID or IMC ID)
+ * Issuer ID (either IMV or IMC ID)
*/
TNC_UInt32 issuer_id;
/**
+ * Responder ID (either IMC or IMV ID)
+ */
+ TNC_UInt32 responder_id;
+
+ /**
* IMC/IMV role
*/
bool is_imc;
@@ -290,6 +295,36 @@ METHOD(seg_contract_t, is_null, bool,
return this->is_null;
}
+METHOD(seg_contract_t, set_responder, void,
+ private_seg_contract_t *this, TNC_UInt32 responder_id)
+{
+ this->responder_id = responder_id;
+}
+
+METHOD(seg_contract_t, get_responder, TNC_UInt32,
+ private_seg_contract_t *this)
+{
+ return this->responder_id;
+}
+
+METHOD(seg_contract_t, get_issuer, TNC_UInt32,
+ private_seg_contract_t *this)
+{
+ return this->issuer_id;
+}
+
+METHOD(seg_contract_t, clone_, seg_contract_t*,
+ private_seg_contract_t *this)
+{
+ private_seg_contract_t *clone;
+
+ clone = malloc_thing(private_seg_contract_t);
+ memcpy(clone, this, sizeof(private_seg_contract_t));
+ clone->seg_envs = linked_list_create();
+
+ return &clone->public;
+}
+
METHOD(seg_contract_t, get_info_string, void,
private_seg_contract_t *this, char *buf, size_t len, bool request)
{
@@ -308,7 +343,10 @@ METHOD(seg_contract_t, get_info_string, void,
}
else
{
- written = snprintf(pos, len, "received");
+ written = snprintf(pos, len, "%s %d received",
+ this->is_imc ? "IMC" : "IMV",
+ this->is_issuer ? this->issuer_id :
+ this->responder_id);
}
if (written < 0 || written > len)
{
@@ -318,7 +356,8 @@ METHOD(seg_contract_t, get_info_string, void,
len -= written;
written = snprintf(pos, len, " a %ssegmentation contract%s ",
- this->is_null ? "null" : "", request ? "" : " response");
+ this->is_null ? "null" : "", request ?
+ (this->is_issuer ? "" : " request") : " response");
if (written < 0 || written > len)
{
return;
@@ -326,10 +365,13 @@ METHOD(seg_contract_t, get_info_string, void,
pos += written;
len -= written;
- if (!this->is_issuer && this->issuer_id != TNC_IMVID_ANY)
+ if ((!this->is_issuer && this->issuer_id != TNC_IMVID_ANY) ||
+ ( this->is_issuer && this->responder_id != TNC_IMVID_ANY))
{
written = snprintf(pos, len, "from %s %d ",
- this->is_imc ? "IMV" : "IMC", this->issuer_id);
+ this->is_imc ? "IMV" : "IMC",
+ this->is_issuer ? this->responder_id :
+ this->issuer_id);
if (written < 0 || written > len)
{
return;
@@ -413,6 +455,10 @@ seg_contract_t *seg_contract_create(pen_type_t msg_type,
.add_segment = _add_segment,
.is_issuer = _is_issuer,
.is_null = _is_null,
+ .set_responder = _set_responder,
+ .get_responder = _get_responder,
+ .get_issuer = _get_issuer,
+ .clone = _clone_,
.get_info_string = _get_info_string,
.destroy = _destroy,
},
@@ -422,6 +468,7 @@ seg_contract_t *seg_contract_create(pen_type_t msg_type,
.seg_envs = linked_list_create(),
.is_issuer = is_issuer,
.issuer_id = issuer_id,
+ .responder_id = is_imc ? TNC_IMVID_ANY : TNC_IMCID_ANY,
.is_imc = is_imc,
.is_null = max_attr_size == SEG_CONTRACT_MAX_SIZE_VALUE &&
max_seg_size == SEG_CONTRACT_MAX_SIZE_VALUE,
diff --git a/src/libimcv/seg/seg_contract.h b/src/libimcv/seg/seg_contract.h
index 48828c472..2a2666f42 100644
--- a/src/libimcv/seg/seg_contract.h
+++ b/src/libimcv/seg/seg_contract.h
@@ -118,6 +118,34 @@ struct seg_contract_t {
bool (*is_null)(seg_contract_t *this);
/**
+ * Set the responder ID
+ *
+ * @param responder IMC or IMV ID of responder
+ */
+ void (*set_responder)(seg_contract_t *this, TNC_UInt32 responder);
+
+ /**
+ * Get the responder ID
+ *
+ * @return IMC or IMV ID of responder
+ */
+ TNC_UInt32 (*get_responder)(seg_contract_t *this);
+
+ /**
+ * Get the issuer ID
+ *
+ * @return IMC or IMV ID of issuer
+ */
+ TNC_UInt32 (*get_issuer)(seg_contract_t *this);
+
+ /**
+ * Clone a contract
+ *
+ * @return Cloned contract
+ */
+ seg_contract_t* (*clone)(seg_contract_t *this);
+
+ /**
* Get an info string about the contract
*
* @param buf String buffer of at least size len
diff --git a/src/libimcv/seg/seg_contract_manager.c b/src/libimcv/seg/seg_contract_manager.c
index d099436fc..604c51134 100644
--- a/src/libimcv/seg/seg_contract_manager.c
+++ b/src/libimcv/seg/seg_contract_manager.c
@@ -42,7 +42,8 @@ METHOD(seg_contract_manager_t, add_contract, void,
}
METHOD(seg_contract_manager_t, get_contract, seg_contract_t*,
- private_seg_contract_manager_t *this, pen_type_t msg_type, bool is_issuer)
+ private_seg_contract_manager_t *this, pen_type_t msg_type, bool is_issuer,
+ TNC_UInt32 id)
{
enumerator_t *enumerator;
seg_contract_t *contract, *found = NULL;
@@ -51,7 +52,9 @@ METHOD(seg_contract_manager_t, get_contract, seg_contract_t*,
while (enumerator->enumerate(enumerator, &contract))
{
if (contract->is_issuer(contract) == is_issuer &&
- pen_type_equals(contract->get_msg_type(contract), msg_type))
+ pen_type_equals(contract->get_msg_type(contract), msg_type) &&
+ id == (is_issuer ? contract->get_responder(contract) :
+ contract->get_issuer(contract)))
{
found = contract;
break;
diff --git a/src/libimcv/seg/seg_contract_manager.h b/src/libimcv/seg/seg_contract_manager.h
index 355822d99..2757eca9e 100644
--- a/src/libimcv/seg/seg_contract_manager.h
+++ b/src/libimcv/seg/seg_contract_manager.h
@@ -43,9 +43,11 @@ struct seg_contract_manager_t {
*
* @param msg_type PA-TNC message type governed by contract
* @param is_issuer If TRUE get only issuer contracts
+ * @param id Match either issuer or responder ID
*/
seg_contract_t* (*get_contract)(seg_contract_manager_t *this,
- pen_type_t msg_type, bool is_issuer);
+ pen_type_t msg_type, bool is_issuer,
+ TNC_UInt32 id);
/**
* Destroys a seg_contract_manager_t object.