+METHOD(ike_sa_t, handle_redirect, bool,
+ private_ike_sa_t *this, identification_t *gateway)
+{
+ char gw[BUF_LEN];
+ host_t *other;
+
+ DBG1(DBG_IKE, "redirected to %Y", gateway);
+
+ snprintf(gw, sizeof(gw), "%Y", gateway);
+ gw[sizeof(gw)-1] = '\0';
+ other = host_create_from_dns(gw, AF_UNSPEC, IKEV2_UDP_PORT);
+ if (!other)
+ {
+ DBG1(DBG_IKE, "unable to resolve gateway ID '%Y', redirect failed",
+ gateway);
+ return FALSE;
+ }
+ switch (this->state)
+ {
+ case IKE_CONNECTING:
+ reset(this);
+ set_other_host(this, other);
+ return TRUE;
+ default:
+ DBG1(DBG_IKE, "unable to handle redirect for IKE_SA in state %N",
+ ike_sa_state_names, this->state);
+ other->destroy(other);
+ return FALSE;
+ }
+}
+