Migrated kernel_klips_ipsec to METHOD/INIT macros
authorMartin Willi <martin@revosec.ch>
Tue, 23 Feb 2010 16:10:29 +0000 (16:10 +0000)
committerMartin Willi <martin@revosec.ch>
Fri, 26 Feb 2010 10:44:33 +0000 (11:44 +0100)
src/charon/plugins/kernel_klips/kernel_klips_ipsec.c

index fea1b83..21f6b2a 100644 (file)
@@ -1532,13 +1532,9 @@ static void schedule_expire(private_kernel_klips_ipsec_t *this,
        charon->scheduler->schedule_job(charon->scheduler, (job_t*)job, time);
 }
 
-/**
- * Implementation of kernel_interface_t.get_spi.
- */
-static status_t get_spi(private_kernel_klips_ipsec_t *this,
-                                               host_t *src, host_t *dst,
-                                               protocol_id_t protocol, u_int32_t reqid,
-                                               u_int32_t *spi)
+METHOD(kernel_ipsec_t, get_spi, status_t,
+       private_kernel_klips_ipsec_t *this, host_t *src, host_t *dst,
+       protocol_id_t protocol, u_int32_t reqid, u_int32_t *spi)
 {
        /* we cannot use SADB_GETSPI because KLIPS does not allow us to set the
         * NAT-T type in an SADB_UPDATE which we would have to use to update the
@@ -1573,12 +1569,9 @@ static status_t get_spi(private_kernel_klips_ipsec_t *this,
        return SUCCESS;
 }
 
-/**
- * Implementation of kernel_interface_t.get_cpi.
- */
-static status_t get_cpi(private_kernel_klips_ipsec_t *this,
-                                               host_t *src, host_t *dst,
-                                               u_int32_t reqid, u_int16_t *cpi)
+METHOD(kernel_ipsec_t, get_cpi, status_t,
+       private_kernel_klips_ipsec_t *this, host_t *src, host_t *dst,
+       u_int32_t reqid, u_int16_t *cpi)
 {
        return FAILED;
 }
@@ -1695,18 +1688,12 @@ static status_t group_ipip_sa(private_kernel_klips_ipsec_t *this,
        return SUCCESS;
 }
 
-/**
- * Implementation of kernel_interface_t.add_sa.
- */
-static status_t add_sa(private_kernel_klips_ipsec_t *this,
-                                          host_t *src, host_t *dst, u_int32_t spi,
-                                          protocol_id_t protocol, u_int32_t reqid,
-                                          lifetime_cfg_t *lifetime,
-                                          u_int16_t enc_alg, chunk_t enc_key,
-                                          u_int16_t int_alg, chunk_t int_key,
-                                          ipsec_mode_t mode, u_int16_t ipcomp, u_int16_t cpi,
-                                          bool encap, bool inbound, traffic_selector_t *src_ts,
-                                          traffic_selector_t *dst_ts)
+METHOD(kernel_ipsec_t, add_sa, status_t,
+       private_kernel_klips_ipsec_t *this, host_t *src, host_t *dst, u_int32_t spi,
+       protocol_id_t protocol, u_int32_t reqid, lifetime_cfg_t *lifetime,
+       u_int16_t enc_alg, chunk_t enc_key, u_int16_t int_alg, chunk_t int_key,
+       ipsec_mode_t mode, u_int16_t ipcomp, u_int16_t cpi, bool encap,
+       bool inbound, traffic_selector_t *src_ts, traffic_selector_t *dst_ts)
 {
        unsigned char request[PFKEY_BUFFER_SIZE];
        struct sadb_msg *msg, *out;
@@ -1859,14 +1846,10 @@ static status_t add_sa(private_kernel_klips_ipsec_t *this,
        return SUCCESS;
 }
 
-/**
- * Implementation of kernel_interface_t.update_sa.
- */
-static status_t update_sa(private_kernel_klips_ipsec_t *this,
-                                                 u_int32_t spi, protocol_id_t protocol, u_int16_t cpi,
-                                                 host_t *src, host_t *dst,
-                                                 host_t *new_src, host_t *new_dst,
-                                                 bool encap, bool new_encap)
+METHOD(kernel_ipsec_t, update_sa, status_t,
+       private_kernel_klips_ipsec_t *this, u_int32_t spi, protocol_id_t protocol,
+       u_int16_t cpi, host_t *src, host_t *dst, host_t *new_src, host_t *new_dst,
+       bool encap, bool new_encap)
 {
        unsigned char request[PFKEY_BUFFER_SIZE];
        struct sadb_msg *msg, *out;
@@ -1935,22 +1918,16 @@ static status_t update_sa(private_kernel_klips_ipsec_t *this,
        return SUCCESS;
 }
 
-/**
- * Implementation of kernel_interface_t.query_sa.
- */
-static status_t query_sa(private_kernel_klips_ipsec_t *this, host_t *src,
-                                                host_t *dst, u_int32_t spi, protocol_id_t protocol,
-                                                u_int64_t *bytes)
+METHOD(kernel_ipsec_t, query_sa, status_t,
+       private_kernel_klips_ipsec_t *this, host_t *src, host_t *dst,
+       u_int32_t spi, protocol_id_t protocol, u_int64_t *bytes)
 {
        return NOT_SUPPORTED;  /* TODO */
 }
 
-/**
- * Implementation of kernel_interface_t.del_sa.
- */
-static status_t del_sa(private_kernel_klips_ipsec_t *this, host_t *src,
-                                          host_t *dst, u_int32_t spi, protocol_id_t protocol,
-                                          u_int16_t cpi)
+METHOD(kernel_ipsec_t, del_sa, status_t,
+       private_kernel_klips_ipsec_t *this, host_t *src, host_t *dst,
+       u_int32_t spi, protocol_id_t protocol, u_int16_t cpi)
 {
        unsigned char request[PFKEY_BUFFER_SIZE];
        struct sadb_msg *msg, *out;
@@ -2011,17 +1988,12 @@ static status_t del_sa(private_kernel_klips_ipsec_t *this, host_t *src,
        return SUCCESS;
 }
 
-/**
- * Implementation of kernel_interface_t.add_policy.
- */
-static status_t add_policy(private_kernel_klips_ipsec_t *this,
-                                                  host_t *src, host_t *dst,
-                                                  traffic_selector_t *src_ts,
-                                                  traffic_selector_t *dst_ts,
-                                                  policy_dir_t direction, u_int32_t spi,
-                                                  protocol_id_t protocol, u_int32_t reqid,
-                                                  ipsec_mode_t mode, u_int16_t ipcomp, u_int16_t cpi,
-                                                  bool routed)
+METHOD(kernel_ipsec_t, add_policy, status_t,
+       private_kernel_klips_ipsec_t *this, host_t *src, host_t *dst,
+       traffic_selector_t *src_ts, traffic_selector_t *dst_ts,
+       policy_dir_t direction, u_int32_t spi, protocol_id_t protocol,
+       u_int32_t reqid, ipsec_mode_t mode, u_int16_t ipcomp, u_int16_t cpi,
+       bool routed)
 {
        unsigned char request[PFKEY_BUFFER_SIZE];
        struct sadb_msg *msg, *out;
@@ -2236,13 +2208,9 @@ static status_t add_policy(private_kernel_klips_ipsec_t *this,
        return SUCCESS;
 }
 
-/**
- * Implementation of kernel_interface_t.query_policy.
- */
-static status_t query_policy(private_kernel_klips_ipsec_t *this,
-                                                        traffic_selector_t *src_ts,
-                                                        traffic_selector_t *dst_ts,
-                                                        policy_dir_t direction, u_int32_t *use_time)
+METHOD(kernel_ipsec_t, query_policy, status_t,
+       private_kernel_klips_ipsec_t *this, traffic_selector_t *src_ts,
+       traffic_selector_t *dst_ts, policy_dir_t direction, u_int32_t *use_time)
 {
        #define IDLE_PREFIX "idle="
        static const char *path_eroute = "/proc/net/ipsec_eroute";
@@ -2395,13 +2363,9 @@ static status_t query_policy(private_kernel_klips_ipsec_t *this,
        return status;
 }
 
-/**
- * Implementation of kernel_interface_t.del_policy.
- */
-static status_t del_policy(private_kernel_klips_ipsec_t *this,
-                                                  traffic_selector_t *src_ts,
-                                                  traffic_selector_t *dst_ts,
-                                                  policy_dir_t direction, bool unrouted)
+METHOD(kernel_ipsec_t, del_policy, status_t,
+       private_kernel_klips_ipsec_t *this, traffic_selector_t *src_ts,
+       traffic_selector_t *dst_ts, policy_dir_t direction, bool unrouted)
 {
        unsigned char request[PFKEY_BUFFER_SIZE];
        struct sadb_msg *msg = (struct sadb_msg*)request, *out;
@@ -2592,10 +2556,8 @@ static status_t register_pfkey_socket(private_kernel_klips_ipsec_t *this, u_int8
        return SUCCESS;
 }
 
-/**
- * Implementation of kernel_interface_t.destroy.
- */
-static void destroy(private_kernel_klips_ipsec_t *this)
+METHOD(kernel_ipsec_t, destroy, void,
+       private_kernel_klips_ipsec_t *this)
 {
        this->job->cancel(this->job);
        close(this->socket);
@@ -2614,30 +2576,30 @@ static void destroy(private_kernel_klips_ipsec_t *this)
  */
 kernel_klips_ipsec_t *kernel_klips_ipsec_create()
 {
-       private_kernel_klips_ipsec_t *this = malloc_thing(private_kernel_klips_ipsec_t);
-
-       /* public functions */
-       this->public.interface.get_spi = (status_t(*)(kernel_ipsec_t*,host_t*,host_t*,protocol_id_t,u_int32_t,u_int32_t*))get_spi;
-       this->public.interface.get_cpi = (status_t(*)(kernel_ipsec_t*,host_t*,host_t*,u_int32_t,u_int16_t*))get_cpi;
-       this->public.interface.add_sa  = (status_t(*)(kernel_ipsec_t *,host_t*,host_t*,u_int32_t,protocol_id_t,u_int32_t,lifetime_cfg_t*,u_int16_t,chunk_t,u_int16_t,chunk_t,ipsec_mode_t,u_int16_t,u_int16_t,bool,bool,traffic_selector_t*,traffic_selector_t*))add_sa;
-       this->public.interface.update_sa = (status_t(*)(kernel_ipsec_t*,u_int32_t,protocol_id_t,u_int16_t,host_t*,host_t*,host_t*,host_t*,bool,bool))update_sa;
-       this->public.interface.query_sa = (status_t(*)(kernel_ipsec_t*,host_t*,host_t*,u_int32_t,protocol_id_t,u_int64_t*))query_sa;
-       this->public.interface.del_sa = (status_t(*)(kernel_ipsec_t*,host_t*,host_t*,u_int32_t,protocol_id_t,u_int16_t))del_sa;
-       this->public.interface.add_policy = (status_t(*)(kernel_ipsec_t*,host_t*,host_t*,traffic_selector_t*,traffic_selector_t*,policy_dir_t,u_int32_t,protocol_id_t,u_int32_t,ipsec_mode_t,u_int16_t,u_int16_t,bool))add_policy;
-       this->public.interface.query_policy = (status_t(*)(kernel_ipsec_t*,traffic_selector_t*,traffic_selector_t*,policy_dir_t,u_int32_t*))query_policy;
-       this->public.interface.del_policy = (status_t(*)(kernel_ipsec_t*,traffic_selector_t*,traffic_selector_t*,policy_dir_t,bool))del_policy;
-
-       this->public.interface.destroy = (void(*)(kernel_ipsec_t*)) destroy;
-
-       /* private members */
-       this->policies = linked_list_create();
-       this->allocated_spis = linked_list_create();
-       this->installed_sas = linked_list_create();
-       this->ipsec_devices = linked_list_create();
-       this->mutex = mutex_create(MUTEX_TYPE_DEFAULT);
-       this->mutex_pfkey = mutex_create(MUTEX_TYPE_DEFAULT);
-       this->install_routes = lib->settings->get_bool(lib->settings, "charon.install_routes", TRUE);
-       this->seq = 0;
+       private_kernel_klips_ipsec_t *this;
+
+       INIT(this,
+               .public.interface = {
+                       .get_spi = _get_spi,
+                       .get_cpi = _get_cpi,
+                       .add_sa  = _add_sa,
+                       .update_sa = _update_sa,
+                       .query_sa = _query_sa,
+                       .del_sa = _del_sa,
+                       .add_policy = _add_policy,
+                       .query_policy = _query_policy,
+                       .del_policy = _del_policy,
+                       .destroy = _destroy,
+               },
+               .policies = linked_list_create(),
+               .allocated_spis = linked_list_create(),
+               .installed_sas = linked_list_create(),
+               .ipsec_devices = linked_list_create(),
+               .mutex = mutex_create(MUTEX_TYPE_DEFAULT),
+               .mutex_pfkey = mutex_create(MUTEX_TYPE_DEFAULT),
+               .install_routes = lib->settings->get_bool(lib->settings,
+                                                                                               "charon.install_routes", TRUE),
+       );
 
        /* initialize ipsec devices */
        init_ipsec_devices(this);