Migrated ike_config to INIT/METHOD macros
[strongswan.git] / src / libcharon / sa / tasks / ike_config.c
index 58bcf07..4ef9c56 100644 (file)
@@ -174,6 +174,11 @@ static void process_attribute(private_ike_config_t *this,
                        }
                        break;
                }
+               case INTERNAL_IP4_SERVER:
+               case INTERNAL_IP6_SERVER:
+                       /* assume it's a Windows client if we see proprietary attributes */
+                       this->ike_sa->enable_extension(this->ike_sa, EXT_MS_WINDOWS);
+                       /* fall */
                default:
                {
                        if (this->initiator)
@@ -225,10 +230,8 @@ static void process_payloads(private_ike_config_t *this, message_t *message)
        enumerator->destroy(enumerator);
 }
 
-/**
- * Implementation of task_t.process for initiator
- */
-static status_t build_i(private_ike_config_t *this, message_t *message)
+METHOD(task_t, build_i, status_t,
+       private_ike_config_t *this, message_t *message)
 {
        if (message->get_message_id(message) == 1)
        {       /* in first IKE_AUTH only */
@@ -287,10 +290,8 @@ static status_t build_i(private_ike_config_t *this, message_t *message)
        return NEED_MORE;
 }
 
-/**
- * Implementation of task_t.process for responder
- */
-static status_t process_r(private_ike_config_t *this, message_t *message)
+METHOD(task_t, process_r, status_t,
+       private_ike_config_t *this, message_t *message)
 {
        if (message->get_message_id(message) == 1)
        {       /* in first IKE_AUTH only */
@@ -299,10 +300,8 @@ static status_t process_r(private_ike_config_t *this, message_t *message)
        return NEED_MORE;
 }
 
-/**
- * Implementation of task_t.build for responder
- */
-static status_t build_r(private_ike_config_t *this, message_t *message)
+METHOD(task_t, build_r, status_t,
+       private_ike_config_t *this, message_t *message)
 {
        if (this->ike_sa->get_state(this->ike_sa) == IKE_ESTABLISHED)
        {       /* in last IKE_AUTH exchange */
@@ -317,7 +316,7 @@ static status_t build_r(private_ike_config_t *this, message_t *message)
                id = this->ike_sa->get_other_eap_id(this->ike_sa);
 
                config = this->ike_sa->get_peer_cfg(this->ike_sa);
-               if (config && this->virtual_ip)
+               if (this->virtual_ip)
                {
                        DBG1(DBG_IKE, "peer requested virtual IP %H", this->virtual_ip);
                        if (config->get_pool(config))
@@ -333,7 +332,7 @@ static status_t build_r(private_ike_config_t *this, message_t *message)
                                                                        chunk_empty);
                                return SUCCESS;
                        }
-                       DBG1(DBG_IKE, "assigning virtual IP %H to peer", vip);
+                       DBG1(DBG_IKE, "assigning virtual IP %H to peer '%Y'", vip, id);
                        this->ike_sa->set_virtual_ip(this->ike_sa, FALSE, vip);
 
                        cp = cp_payload_create_type(CFG_REPLY);
@@ -342,7 +341,7 @@ static status_t build_r(private_ike_config_t *this, message_t *message)
 
                /* query registered providers for additional attributes to include */
                enumerator = hydra->attributes->create_responder_enumerator(
-                                                                                                       hydra->attributes, id, vip);
+                                               hydra->attributes, config->get_pool(config), id, vip);
                while (enumerator->enumerate(enumerator, &type, &value))
                {
                        if (!cp)
@@ -366,10 +365,8 @@ static status_t build_r(private_ike_config_t *this, message_t *message)
        return NEED_MORE;
 }
 
-/**
- * Implementation of task_t.process for initiator
- */
-static status_t process_i(private_ike_config_t *this, message_t *message)
+METHOD(task_t, process_i, status_t,
+       private_ike_config_t *this, message_t *message)
 {
        if (this->ike_sa->get_state(this->ike_sa) == IKE_ESTABLISHED)
        {       /* in last IKE_AUTH exchange */
@@ -385,18 +382,14 @@ static status_t process_i(private_ike_config_t *this, message_t *message)
        return NEED_MORE;
 }
 
-/**
- * Implementation of task_t.get_type
- */
-static task_type_t get_type(private_ike_config_t *this)
+METHOD(task_t, get_type, task_type_t,
+       private_ike_config_t *this)
 {
        return IKE_CONFIG;
 }
 
-/**
- * Implementation of task_t.migrate
- */
-static void migrate(private_ike_config_t *this, ike_sa_t *ike_sa)
+METHOD(task_t, migrate, void,
+       private_ike_config_t *this, ike_sa_t *ike_sa)
 {
        DESTROY_IF(this->virtual_ip);
 
@@ -406,10 +399,8 @@ static void migrate(private_ike_config_t *this, ike_sa_t *ike_sa)
        this->requested = linked_list_create();
 }
 
-/**
- * Implementation of task_t.destroy
- */
-static void destroy(private_ike_config_t *this)
+METHOD(task_t, destroy, void,
+       private_ike_config_t *this)
 {
        DESTROY_IF(this->virtual_ip);
        this->requested->destroy_function(this->requested, free);
@@ -421,26 +412,30 @@ static void destroy(private_ike_config_t *this)
  */
 ike_config_t *ike_config_create(ike_sa_t *ike_sa, bool initiator)
 {
-       private_ike_config_t *this = malloc_thing(private_ike_config_t);
-
-       this->public.task.get_type = (task_type_t(*)(task_t*))get_type;
-       this->public.task.migrate = (void(*)(task_t*,ike_sa_t*))migrate;
-       this->public.task.destroy = (void(*)(task_t*))destroy;
-
-       this->initiator = initiator;
-       this->ike_sa = ike_sa;
-       this->virtual_ip = NULL;
-       this->requested = linked_list_create();
+       private_ike_config_t *this;
+
+       INIT(this,
+               .public = {
+                       .task = {
+                               .get_type = _get_type,
+                               .migrate = _migrate,
+                               .destroy = _destroy,
+                       },
+               },
+               .initiator = initiator,
+               .ike_sa = ike_sa,
+               .requested = linked_list_create(),
+       );
 
        if (initiator)
        {
-               this->public.task.build = (status_t(*)(task_t*,message_t*))build_i;
-               this->public.task.process = (status_t(*)(task_t*,message_t*))process_i;
+               this->public.task.build = _build_i;
+               this->public.task.process = _process_i;
        }
        else
        {
-               this->public.task.build = (status_t(*)(task_t*,message_t*))build_r;
-               this->public.task.process = (status_t(*)(task_t*,message_t*))process_r;
+               this->public.task.build = _build_r;
+               this->public.task.process = _process_r;
        }
 
        return &this->public;