Support multiple virtual IPs on peer_cfg and ike_sa classes
This commit is contained in:
@@ -275,8 +275,8 @@ static job_requeue_t initiate(private_android_service_t *this)
|
||||
600, 600, /* jitter, over 10min */
|
||||
TRUE, FALSE, /* mobike, aggressive */
|
||||
0, 0, /* DPD delay, timeout */
|
||||
host_create_from_string("0.0.0.0", 0) /* virt */,
|
||||
NULL, FALSE, NULL, NULL); /* pool, mediation */
|
||||
peer_cfg->add_virtual_ip(peer_cfg, host_create_from_string("0.0.0.0", 0));
|
||||
|
||||
auth = auth_cfg_create();
|
||||
auth->add(auth, AUTH_RULE_AUTH_CLASS, AUTH_CLASS_EAP);
|
||||
|
||||
@@ -149,6 +149,7 @@ static bool send_message(private_eap_radius_accounting_t *this,
|
||||
*/
|
||||
static void add_ike_sa_parameters(radius_message_t *message, ike_sa_t *ike_sa)
|
||||
{
|
||||
enumerator_t *enumerator;
|
||||
host_t *vip;
|
||||
char buf[64];
|
||||
chunk_t data;
|
||||
@@ -157,17 +158,25 @@ static void add_ike_sa_parameters(radius_message_t *message, ike_sa_t *ike_sa)
|
||||
message->add(message, RAT_USER_NAME, chunk_create(buf, strlen(buf)));
|
||||
snprintf(buf, sizeof(buf), "%#H", ike_sa->get_other_host(ike_sa));
|
||||
message->add(message, RAT_CALLING_STATION_ID, chunk_create(buf, strlen(buf)));
|
||||
vip = ike_sa->get_virtual_ip(ike_sa, FALSE);
|
||||
if (vip && vip->get_family(vip) == AF_INET)
|
||||
|
||||
enumerator = ike_sa->create_virtual_ip_enumerator(ike_sa, FALSE);
|
||||
while (enumerator->enumerate(enumerator, &vip))
|
||||
{
|
||||
message->add(message, RAT_FRAMED_IP_ADDRESS, vip->get_address(vip));
|
||||
}
|
||||
if (vip && vip->get_family(vip) == AF_INET6)
|
||||
{
|
||||
/* we currently assign /128 prefixes, only (reserved, length) */
|
||||
data = chunk_from_chars(0, 128);
|
||||
data = chunk_cata("cc", data, vip->get_address(vip));
|
||||
message->add(message, RAT_FRAMED_IPV6_PREFIX, data);
|
||||
switch (vip->get_family(vip))
|
||||
{
|
||||
case AF_INET:
|
||||
message->add(message, RAT_FRAMED_IP_ADDRESS,
|
||||
vip->get_address(vip));
|
||||
break;
|
||||
case AF_INET6:
|
||||
/* we currently assign /128 prefixes, only (reserved, length) */
|
||||
data = chunk_from_chars(0, 128);
|
||||
data = chunk_cata("cc", data, vip->get_address(vip));
|
||||
message->add(message, RAT_FRAMED_IPV6_PREFIX, data);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -344,10 +344,10 @@ static void process_ike_update(private_ha_dispatcher_t *this,
|
||||
ike_sa->set_other_host(ike_sa, value.host->clone(value.host));
|
||||
break;
|
||||
case HA_LOCAL_VIP:
|
||||
ike_sa->set_virtual_ip(ike_sa, TRUE, value.host);
|
||||
ike_sa->add_virtual_ip(ike_sa, TRUE, value.host);
|
||||
break;
|
||||
case HA_REMOTE_VIP:
|
||||
ike_sa->set_virtual_ip(ike_sa, FALSE, value.host);
|
||||
ike_sa->add_virtual_ip(ike_sa, FALSE, value.host);
|
||||
received_vip = TRUE;
|
||||
break;
|
||||
case HA_PEER_ADDR:
|
||||
@@ -417,13 +417,18 @@ static void process_ike_update(private_ha_dispatcher_t *this,
|
||||
char *pool;
|
||||
|
||||
peer_cfg = ike_sa->get_peer_cfg(ike_sa);
|
||||
vip = ike_sa->get_virtual_ip(ike_sa, FALSE);
|
||||
if (peer_cfg && vip)
|
||||
if (peer_cfg)
|
||||
{
|
||||
pool = peer_cfg->get_pool(peer_cfg);
|
||||
if (pool)
|
||||
{
|
||||
this->attr->reserve(this->attr, pool, vip);
|
||||
enumerator = ike_sa->create_virtual_ip_enumerator(ike_sa,
|
||||
FALSE);
|
||||
while (enumerator->enumerate(enumerator, &vip))
|
||||
{
|
||||
this->attr->reserve(this->attr, pool, vip);
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,6 +241,34 @@ METHOD(listener_t, ike_state_change, bool,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a virtual IP sync message for remote VIPs
|
||||
*/
|
||||
static void sync_vips(private_ha_ike_t *this, ike_sa_t *ike_sa)
|
||||
{
|
||||
ha_message_t *m = NULL;
|
||||
enumerator_t *enumerator;
|
||||
host_t *vip;
|
||||
|
||||
enumerator = ike_sa->create_virtual_ip_enumerator(ike_sa, FALSE);
|
||||
while (enumerator->enumerate(enumerator, &vip))
|
||||
{
|
||||
if (!m)
|
||||
{
|
||||
m = ha_message_create(HA_IKE_UPDATE);
|
||||
m->add_attribute(m, HA_IKE_ID, ike_sa->get_id(ike_sa));
|
||||
}
|
||||
m->add_attribute(m, HA_REMOTE_VIP, vip);
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
|
||||
if (m)
|
||||
{
|
||||
this->socket->push(this->socket, m);
|
||||
this->cache->cache(this->cache, ike_sa, m);
|
||||
}
|
||||
}
|
||||
|
||||
METHOD(listener_t, message_hook, bool,
|
||||
private_ha_ike_t *this, ike_sa_t *ike_sa, message_t *message,
|
||||
bool incoming, bool plain)
|
||||
@@ -276,18 +304,7 @@ METHOD(listener_t, message_hook, bool,
|
||||
{ /* After IKE_SA has been established, sync peers virtual IP.
|
||||
* We cannot sync it in the state_change hook, it is installed later.
|
||||
* TODO: where to sync local VIP? */
|
||||
ha_message_t *m;
|
||||
host_t *vip;
|
||||
|
||||
vip = ike_sa->get_virtual_ip(ike_sa, FALSE);
|
||||
if (vip)
|
||||
{
|
||||
m = ha_message_create(HA_IKE_UPDATE);
|
||||
m->add_attribute(m, HA_IKE_ID, ike_sa->get_id(ike_sa));
|
||||
m->add_attribute(m, HA_REMOTE_VIP, vip);
|
||||
this->socket->push(this->socket, m);
|
||||
this->cache->cache(this->cache, ike_sa, m);
|
||||
}
|
||||
sync_vips(this, ike_sa);
|
||||
}
|
||||
}
|
||||
if (!plain && ike_sa->get_version(ike_sa) == IKEV1)
|
||||
@@ -296,7 +313,6 @@ METHOD(listener_t, message_hook, bool,
|
||||
keymat_v1_t *keymat;
|
||||
u_int32_t mid;
|
||||
chunk_t iv;
|
||||
host_t *vip;
|
||||
|
||||
mid = message->get_message_id(message);
|
||||
if (mid == 0)
|
||||
@@ -313,15 +329,7 @@ METHOD(listener_t, message_hook, bool,
|
||||
}
|
||||
if (!incoming && message->get_exchange_type(message) == TRANSACTION)
|
||||
{
|
||||
vip = ike_sa->get_virtual_ip(ike_sa, FALSE);
|
||||
if (vip)
|
||||
{
|
||||
m = ha_message_create(HA_IKE_UPDATE);
|
||||
m->add_attribute(m, HA_IKE_ID, ike_sa->get_id(ike_sa));
|
||||
m->add_attribute(m, HA_REMOTE_VIP, vip);
|
||||
this->socket->push(this->socket, m);
|
||||
this->cache->cache(this->cache, ike_sa, m);
|
||||
}
|
||||
sync_vips(this, ike_sa);
|
||||
}
|
||||
}
|
||||
if (plain && ike_sa->get_version(ike_sa) == IKEV1 &&
|
||||
|
||||
@@ -209,7 +209,7 @@ static void setup_tunnel(private_ha_tunnel_t *this,
|
||||
ike_cfg->add_proposal(ike_cfg, proposal_create_default(PROTO_IKE));
|
||||
peer_cfg = peer_cfg_create("ha", IKEV2, ike_cfg, CERT_NEVER_SEND,
|
||||
UNIQUE_KEEP, 0, 86400, 0, 7200, 3600, FALSE, FALSE, 30,
|
||||
0, NULL, NULL, FALSE, NULL, NULL);
|
||||
0, NULL, FALSE, NULL, NULL);
|
||||
|
||||
auth_cfg = auth_cfg_create();
|
||||
auth_cfg->add(auth_cfg, AUTH_RULE_AUTH_CLASS, AUTH_CLASS_PSK);
|
||||
|
||||
@@ -268,8 +268,11 @@ static peer_cfg_t* generate_config(private_load_tester_config_t *this, uint num)
|
||||
FALSE, FALSE, /* mobike, aggressive mode */
|
||||
this->dpd_delay, /* dpd_delay */
|
||||
this->dpd_timeout, /* dpd_timeout */
|
||||
this->vip ? this->vip->clone(this->vip) : NULL,
|
||||
this->pool, FALSE, NULL, NULL);
|
||||
if (this->vip)
|
||||
{
|
||||
peer_cfg->add_virtual_ip(peer_cfg, this->vip->clone(this->vip));
|
||||
}
|
||||
if (num)
|
||||
{ /* initiator */
|
||||
generate_auth_cfg(this, this->initiator_auth, peer_cfg, TRUE, num);
|
||||
|
||||
@@ -335,8 +335,8 @@ static gboolean initiate_connection(private_maemo_service_t *this,
|
||||
600, 600, /* jitter, over 10min */
|
||||
TRUE, FALSE, /* mobike, aggressive */
|
||||
0, 0, /* DPD delay, timeout */
|
||||
host_create_from_string("0.0.0.0", 0) /* virt */,
|
||||
NULL, FALSE, NULL, NULL); /* pool, mediation */
|
||||
peer_cfg->add_virtual_ip(peer_cfg, host_create_from_string("0.0.0.0", 0));
|
||||
|
||||
auth = auth_cfg_create();
|
||||
auth->add(auth, AUTH_RULE_AUTH_CLASS, AUTH_CLASS_EAP);
|
||||
|
||||
@@ -129,7 +129,7 @@ METHOD(backend_t, get_peer_cfg_by_name, peer_cfg_t*,
|
||||
this->rekey*5, this->rekey*3, /* jitter, overtime */
|
||||
TRUE, FALSE, /* mobike, aggressive */
|
||||
this->dpd, 0, /* DPD delay, timeout */
|
||||
NULL, NULL, /* vip, pool */
|
||||
NULL, /* pool */
|
||||
TRUE, NULL, NULL); /* mediation, med by, peer id */
|
||||
e->destroy(e);
|
||||
|
||||
@@ -167,7 +167,7 @@ METHOD(backend_t, get_peer_cfg_by_name, peer_cfg_t*,
|
||||
this->rekey*5, this->rekey*3, /* jitter, overtime */
|
||||
TRUE, FALSE, /* mobike, aggressive */
|
||||
this->dpd, 0, /* DPD delay, timeout */
|
||||
NULL, NULL, /* vip, pool */
|
||||
NULL, /* pool */
|
||||
FALSE, med_cfg, /* mediation, med by */
|
||||
identification_create_from_encoding(ID_KEY_ID, other));
|
||||
|
||||
@@ -243,7 +243,7 @@ METHOD(enumerator_t, peer_enumerator_enumerate, bool,
|
||||
this->rekey*5, this->rekey*3, /* jitter, overtime */
|
||||
TRUE, FALSE, /* mobike, aggressive */
|
||||
this->dpd, 0, /* DPD delay, timeout */
|
||||
NULL, NULL, /* vip, pool */
|
||||
NULL, /* pool */
|
||||
FALSE, NULL, NULL); /* mediation, med by, peer id */
|
||||
|
||||
auth = auth_cfg_create();
|
||||
|
||||
@@ -94,7 +94,7 @@ METHOD(backend_t, create_peer_cfg_enumerator, enumerator_t*,
|
||||
this->rekey*5, this->rekey*3, /* jitter, overtime */
|
||||
TRUE, FALSE, /* mobike, aggressiv */
|
||||
this->dpd, 0, /* DPD delay, timeout */
|
||||
NULL, NULL, /* vip, pool */
|
||||
NULL, /* pool */
|
||||
TRUE, NULL, NULL); /* mediation, med by, peer id */
|
||||
e->destroy(e);
|
||||
|
||||
|
||||
@@ -371,8 +371,12 @@ static peer_cfg_t *build_peer_cfg(private_sql_config_t *this, enumerator_t *e,
|
||||
peer_cfg = peer_cfg_create(
|
||||
name, IKEV2, ike, cert_policy, uniqueid,
|
||||
keyingtries, rekeytime, reauthtime, jitter, overtime,
|
||||
mobike, FALSE, dpd_delay, 0, vip, pool,
|
||||
mobike, FALSE, dpd_delay, 0, pool,
|
||||
mediation, mediated_cfg, peer_id);
|
||||
if (vip)
|
||||
{
|
||||
peer_cfg->add_virtual_ip(peer_cfg, vip);
|
||||
}
|
||||
auth = auth_cfg_create();
|
||||
auth->add(auth, AUTH_RULE_AUTH_CLASS, auth_method);
|
||||
auth->add(auth, AUTH_RULE_IDENTITY, local_id);
|
||||
|
||||
@@ -778,9 +778,13 @@ static peer_cfg_t *build_peer_cfg(private_stroke_config_t *this,
|
||||
msg->add_conn.rekey.tries, rekey, reauth, jitter, over,
|
||||
msg->add_conn.mobike, msg->add_conn.aggressive,
|
||||
msg->add_conn.dpd.delay, msg->add_conn.dpd.timeout,
|
||||
vip, msg->add_conn.other.sourceip_mask ?
|
||||
msg->add_conn.other.sourceip_mask ?
|
||||
msg->add_conn.name : msg->add_conn.other.sourceip,
|
||||
msg->add_conn.ikeme.mediation, mediated_by, peer_id);
|
||||
if (vip)
|
||||
{
|
||||
peer_cfg->add_virtual_ip(peer_cfg, vip);
|
||||
}
|
||||
|
||||
/* build leftauth= */
|
||||
auth_cfg = build_auth_cfg(this, msg, TRUE, TRUE);
|
||||
|
||||
@@ -407,10 +407,10 @@ METHOD(stroke_control_t, rekey, void,
|
||||
METHOD(stroke_control_t, terminate_srcip, void,
|
||||
private_stroke_control_t *this, stroke_msg_t *msg, FILE *out)
|
||||
{
|
||||
enumerator_t *enumerator;
|
||||
enumerator_t *enumerator, *vips;
|
||||
ike_sa_t *ike_sa;
|
||||
host_t *start = NULL, *end = NULL, *vip;
|
||||
chunk_t chunk_start, chunk_end = chunk_empty, chunk_vip;
|
||||
chunk_t chunk_start, chunk_end = chunk_empty, chunk;
|
||||
|
||||
if (msg->terminate_srcip.start)
|
||||
{
|
||||
@@ -438,33 +438,40 @@ METHOD(stroke_control_t, terminate_srcip, void,
|
||||
charon->controller, TRUE);
|
||||
while (enumerator->enumerate(enumerator, &ike_sa))
|
||||
{
|
||||
vip = ike_sa->get_virtual_ip(ike_sa, FALSE);
|
||||
if (!vip)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!end)
|
||||
{
|
||||
if (!vip->ip_equals(vip, start))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
chunk_vip = vip->get_address(vip);
|
||||
if (chunk_vip.len != chunk_start.len ||
|
||||
chunk_vip.len != chunk_end.len ||
|
||||
memcmp(chunk_vip.ptr, chunk_start.ptr, chunk_vip.len) < 0 ||
|
||||
memcmp(chunk_vip.ptr, chunk_end.ptr, chunk_vip.len) > 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
bool match = FALSE;
|
||||
|
||||
/* schedule delete asynchronously */
|
||||
lib->processor->queue_job(lib->processor, (job_t*)
|
||||
vips = ike_sa->create_virtual_ip_enumerator(ike_sa, FALSE);
|
||||
while (vips->enumerate(vips, &vip))
|
||||
{
|
||||
if (!end)
|
||||
{
|
||||
if (vip->ip_equals(vip, start))
|
||||
{
|
||||
match = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
chunk = vip->get_address(vip);
|
||||
if (chunk.len == chunk_start.len &&
|
||||
chunk.len == chunk_end.len &&
|
||||
memcmp(chunk.ptr, chunk_start.ptr, chunk.len) >= 0 &&
|
||||
memcmp(chunk.ptr, chunk_end.ptr, chunk.len) <= 0)
|
||||
{
|
||||
match = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
vips->destroy(vips);
|
||||
|
||||
if (match)
|
||||
{
|
||||
/* schedule delete asynchronously */
|
||||
lib->processor->queue_job(lib->processor, (job_t*)
|
||||
delete_ike_sa_job_create(ike_sa->get_id(ike_sa), TRUE));
|
||||
}
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
start->destroy(start);
|
||||
|
||||
@@ -178,7 +178,7 @@ METHOD(enumerator_t, peer_enumerator_enumerate, bool,
|
||||
1800, 900, /* jitter, overtime */
|
||||
TRUE, FALSE, /* mobike, aggressive */
|
||||
60, 0, /* DPD delay, timeout */
|
||||
NULL, NULL, /* vip, pool */
|
||||
NULL, /* pool */
|
||||
FALSE, NULL, NULL); /* mediation, med by, peer id */
|
||||
auth = auth_cfg_create();
|
||||
auth->add(auth, AUTH_RULE_AUTH_CLASS, AUTH_CLASS_PSK);
|
||||
|
||||
@@ -134,6 +134,46 @@ static char *make_dns_vars(private_updown_listener_t *this, ike_sa_t *ike_sa)
|
||||
return strdup(total);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create variables for local virtual IPs
|
||||
*/
|
||||
static char *make_vip_vars(private_updown_listener_t *this, ike_sa_t *ike_sa)
|
||||
{
|
||||
enumerator_t *enumerator;
|
||||
host_t *host;
|
||||
int v4 = 0, v6 = 0;
|
||||
char total[512] = "", current[64];
|
||||
bool first = TRUE;
|
||||
|
||||
enumerator = ike_sa->create_virtual_ip_enumerator(ike_sa, TRUE);
|
||||
while (enumerator->enumerate(enumerator, &host))
|
||||
{
|
||||
if (first)
|
||||
{ /* legacy variable for first VIP */
|
||||
snprintf(current, sizeof(current),
|
||||
"PLUTO_MY_SOURCEIP='%H' ", host);
|
||||
strncat(total, current, sizeof(total) - strlen(total) - 1);
|
||||
}
|
||||
switch (host->get_family(host))
|
||||
{
|
||||
case AF_INET:
|
||||
snprintf(current, sizeof(current),
|
||||
"PLUTO_MY_SOURCEIP4_%d='%H' ", ++v4, host);
|
||||
break;
|
||||
case AF_INET6:
|
||||
snprintf(current, sizeof(current),
|
||||
"PLUTO_MY_SOURCEIP6_%d='%H' ", ++v6, host);
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
strncat(total, current, sizeof(total) - strlen(total) - 1);
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
|
||||
return strdup(total);
|
||||
}
|
||||
|
||||
METHOD(listener_t, child_updown, bool,
|
||||
private_updown_listener_t *this, ike_sa_t *ike_sa, child_sa_t *child_sa,
|
||||
bool up)
|
||||
@@ -141,11 +181,10 @@ METHOD(listener_t, child_updown, bool,
|
||||
traffic_selector_t *my_ts, *other_ts;
|
||||
enumerator_t *enumerator;
|
||||
child_cfg_t *config;
|
||||
host_t *vip, *me, *other;
|
||||
host_t *me, *other;
|
||||
char *script;
|
||||
|
||||
config = child_sa->get_config(child_sa);
|
||||
vip = ike_sa->get_virtual_ip(ike_sa, TRUE);
|
||||
script = config->get_updown(config);
|
||||
me = ike_sa->get_my_host(ike_sa);
|
||||
other = ike_sa->get_other_host(ike_sa);
|
||||
@@ -169,20 +208,7 @@ METHOD(listener_t, child_updown, bool,
|
||||
my_ts->to_subnet(my_ts, &my_client, &my_client_mask);
|
||||
other_ts->to_subnet(other_ts, &other_client, &other_client_mask);
|
||||
|
||||
if (vip)
|
||||
{
|
||||
if (asprintf(&virtual_ip, "PLUTO_MY_SOURCEIP='%H' ", vip) < 0)
|
||||
{
|
||||
virtual_ip = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (asprintf(&virtual_ip, "") < 0)
|
||||
{
|
||||
virtual_ip = NULL;
|
||||
}
|
||||
}
|
||||
virtual_ip = make_vip_vars(this, ike_sa);
|
||||
|
||||
/* check for the presence of an inbound mark */
|
||||
mark = config->get_mark(config, TRUE);
|
||||
|
||||
Reference in New Issue
Block a user