From dec3c184a6450ad62c184e1c5ccefb18264dce64 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Fri, 22 Mar 2019 17:19:51 +0100 Subject: [PATCH] ike-sa: Add property for interface ID --- src/libcharon/sa/ike_sa.c | 27 +++++++++++++++++++++++++-- src/libcharon/sa/ike_sa.h | 10 +++++++++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/libcharon/sa/ike_sa.c b/src/libcharon/sa/ike_sa.c index 3d576a0e89..e75aa755cd 100644 --- a/src/libcharon/sa/ike_sa.c +++ b/src/libcharon/sa/ike_sa.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2018 Tobias Brunner + * Copyright (C) 2006-2019 Tobias Brunner * Copyright (C) 2006 Daniel Roethlisberger * Copyright (C) 2005-2009 Martin Willi * Copyright (C) 2005 Jan Hutter @@ -296,6 +296,16 @@ struct private_ike_sa_t { * Timestamps of redirect attempts to handle loops */ array_t *redirected_at; + + /** + * Inbound interface ID + */ + uint32_t if_id_in; + + /** + * Outbound interface ID + */ + uint32_t if_id_out; }; /** @@ -419,11 +429,15 @@ METHOD(ike_sa_t, set_peer_cfg, void, DESTROY_IF(this->peer_cfg); this->peer_cfg = peer_cfg; - if (this->ike_cfg == NULL) + if (!this->ike_cfg) { this->ike_cfg = peer_cfg->get_ike_cfg(peer_cfg); this->ike_cfg->get_ref(this->ike_cfg); } + + this->if_id_in = peer_cfg->get_if_id(peer_cfg, TRUE); + this->if_id_out = peer_cfg->get_if_id(peer_cfg, FALSE); + allocate_unique_if_ids(&this->if_id_in, &this->if_id_out); } METHOD(ike_sa_t, get_auth_cfg, auth_cfg_t*, @@ -1656,6 +1670,12 @@ METHOD(ike_sa_t, set_other_id, void, this->other_id = other; } +METHOD(ike_sa_t, get_if_id, uint32_t, + private_ike_sa_t *this, bool inbound) +{ + return inbound ? this->if_id_in : this->if_id_out; +} + METHOD(ike_sa_t, add_child_sa, void, private_ike_sa_t *this, child_sa_t *child_sa) { @@ -2810,6 +2830,8 @@ METHOD(ike_sa_t, inherit_post, void, this->other_host = other->other_host->clone(other->other_host); this->my_id = other->my_id->clone(other->my_id); this->other_id = other->other_id->clone(other->other_id); + this->if_id_in = other->if_id_in; + this->if_id_out = other->if_id_out; /* apply assigned virtual IPs... */ while (array_remove(other->my_vips, ARRAY_HEAD, &vip)) @@ -3087,6 +3109,7 @@ ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id, bool initiator, .create_virtual_ip_enumerator = _create_virtual_ip_enumerator, .add_configuration_attribute = _add_configuration_attribute, .create_attribute_enumerator = _create_attribute_enumerator, + .get_if_id = _get_if_id, .set_kmaddress = _set_kmaddress, .create_task_enumerator = _create_task_enumerator, .remove_task = _remove_task, diff --git a/src/libcharon/sa/ike_sa.h b/src/libcharon/sa/ike_sa.h index be480eac86..c7ef1fe3c3 100644 --- a/src/libcharon/sa/ike_sa.h +++ b/src/libcharon/sa/ike_sa.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2018 Tobias Brunner + * Copyright (C) 2006-2019 Tobias Brunner * Copyright (C) 2006 Daniel Roethlisberger * Copyright (C) 2005-2009 Martin Willi * Copyright (C) 2005 Jan Hutter @@ -1068,6 +1068,14 @@ struct ike_sa_t { */ void (*clear_virtual_ips) (ike_sa_t *this, bool local); + /** + * Get interface ID to use as default for children of this IKE_SA. + * + * @param inbound TRUE for inbound interface ID + * @return interface ID + */ + uint32_t (*get_if_id)(ike_sa_t *this, bool inbound); + /** * Create an enumerator over virtual IPs. * -- 2.39.2