child-sa: Replace reqid based marks by "unique" marks
As we now use the same reqid for multiple CHILD_SAs with the same selectors, having marks based on the reqid makes not that much sense anymore. Instead we use unique marks that use a custom identifier. This identifier is reused during rekeying, keeping the marks constant for any rule relying on it (for example installed by updown). This also simplifies handling of reqid allocation, as we do not have to query the marks that is not yet assigned for an unknown reqid.
This commit is contained in:
@@ -159,6 +159,16 @@ struct private_child_create_t {
|
||||
*/
|
||||
u_int32_t reqid;
|
||||
|
||||
/**
|
||||
* Explicit inbound mark value
|
||||
*/
|
||||
u_int mark_in;
|
||||
|
||||
/**
|
||||
* Explicit outbound mark value
|
||||
*/
|
||||
u_int mark_out;
|
||||
|
||||
/**
|
||||
* CHILD_SA which gets established
|
||||
*/
|
||||
@@ -996,7 +1006,8 @@ METHOD(task_t, build_i, status_t,
|
||||
|
||||
this->child_sa = child_sa_create(this->ike_sa->get_my_host(this->ike_sa),
|
||||
this->ike_sa->get_other_host(this->ike_sa), this->config, this->reqid,
|
||||
this->ike_sa->has_condition(this->ike_sa, COND_NAT_ANY));
|
||||
this->ike_sa->has_condition(this->ike_sa, COND_NAT_ANY),
|
||||
this->mark_in, this->mark_out);
|
||||
|
||||
if (!allocate_spi(this))
|
||||
{
|
||||
@@ -1241,7 +1252,8 @@ METHOD(task_t, build_r, status_t,
|
||||
|
||||
this->child_sa = child_sa_create(this->ike_sa->get_my_host(this->ike_sa),
|
||||
this->ike_sa->get_other_host(this->ike_sa), this->config, this->reqid,
|
||||
this->ike_sa->has_condition(this->ike_sa, COND_NAT_ANY));
|
||||
this->ike_sa->has_condition(this->ike_sa, COND_NAT_ANY),
|
||||
this->mark_in, this->mark_out);
|
||||
|
||||
if (this->ipcomp_received != IPCOMP_NONE)
|
||||
{
|
||||
@@ -1478,6 +1490,13 @@ METHOD(child_create_t, use_reqid, void,
|
||||
this->reqid = reqid;
|
||||
}
|
||||
|
||||
METHOD(child_create_t, use_marks, void,
|
||||
private_child_create_t *this, u_int in, u_int out)
|
||||
{
|
||||
this->mark_in = in;
|
||||
this->mark_out = out;
|
||||
}
|
||||
|
||||
METHOD(child_create_t, get_child, child_sa_t*,
|
||||
private_child_create_t *this)
|
||||
{
|
||||
@@ -1545,6 +1564,8 @@ METHOD(task_t, migrate, void,
|
||||
this->ipcomp_received = IPCOMP_NONE;
|
||||
this->other_cpi = 0;
|
||||
this->reqid = 0;
|
||||
this->mark_in = 0;
|
||||
this->mark_out = 0;
|
||||
this->established = FALSE;
|
||||
}
|
||||
|
||||
@@ -1593,6 +1614,7 @@ child_create_t *child_create_create(ike_sa_t *ike_sa,
|
||||
.set_config = _set_config,
|
||||
.get_lower_nonce = _get_lower_nonce,
|
||||
.use_reqid = _use_reqid,
|
||||
.use_marks = _use_marks,
|
||||
.task = {
|
||||
.get_type = _get_type,
|
||||
.migrate = _migrate,
|
||||
|
||||
@@ -51,6 +51,14 @@ struct child_create_t {
|
||||
*/
|
||||
void (*use_reqid) (child_create_t *this, u_int32_t reqid);
|
||||
|
||||
/**
|
||||
* Use specific mark values to override configuration.
|
||||
*
|
||||
* @param in inbound mark value
|
||||
* @param out outbound mark value
|
||||
*/
|
||||
void (*use_marks)(child_create_t *this, u_int in, u_int out);
|
||||
|
||||
/**
|
||||
* Get the lower of the two nonces, used for rekey collisions.
|
||||
*
|
||||
|
||||
@@ -184,6 +184,9 @@ METHOD(task_t, build_i, status_t,
|
||||
}
|
||||
reqid = this->child_sa->get_reqid(this->child_sa);
|
||||
this->child_create->use_reqid(this->child_create, reqid);
|
||||
this->child_create->use_marks(this->child_create,
|
||||
this->child_sa->get_mark(this->child_sa, TRUE).value,
|
||||
this->child_sa->get_mark(this->child_sa, FALSE).value);
|
||||
|
||||
if (this->child_create->task.build(&this->child_create->task,
|
||||
message) != NEED_MORE)
|
||||
@@ -224,6 +227,9 @@ METHOD(task_t, build_r, status_t,
|
||||
/* let the CHILD_CREATE task build the response */
|
||||
reqid = this->child_sa->get_reqid(this->child_sa);
|
||||
this->child_create->use_reqid(this->child_create, reqid);
|
||||
this->child_create->use_marks(this->child_create,
|
||||
this->child_sa->get_mark(this->child_sa, TRUE).value,
|
||||
this->child_sa->get_mark(this->child_sa, FALSE).value);
|
||||
config = this->child_sa->get_config(this->child_sa);
|
||||
this->child_create->set_config(this->child_create, config->get_ref(config));
|
||||
this->child_create->task.build(&this->child_create->task, message);
|
||||
|
||||
Reference in New Issue
Block a user