Migrated kernel_pfroute_net to INIT/METHOD macros
[strongswan.git] / src / libhydra / plugins / kernel_pfroute / kernel_pfroute_net.c
index 59fc915..c4c7757 100644 (file)
@@ -412,7 +412,8 @@ static void address_enumerator_destroy(address_enumerator_t *data)
 /**
  * filter for addresses
  */
-static bool filter_addresses(address_enumerator_t *data, addr_entry_t** in, host_t** out)
+static bool filter_addresses(address_enumerator_t *data,
+                                                        addr_entry_t** in, host_t** out)
 {
        host_t *ip;
        if (!data->include_virtual_ips && (*in)->virtual)
@@ -435,7 +436,8 @@ static bool filter_addresses(address_enumerator_t *data, addr_entry_t** in, host
 /**
  * enumerator constructor for interfaces
  */
-static enumerator_t *create_iface_enumerator(iface_entry_t *iface, address_enumerator_t *data)
+static enumerator_t *create_iface_enumerator(iface_entry_t *iface,
+                                                                                        address_enumerator_t *data)
 {
        return enumerator_create_filter(iface->addrs->create_enumerator(iface->addrs),
                                                                        (void*)filter_addresses, data, NULL);
@@ -444,7 +446,8 @@ static enumerator_t *create_iface_enumerator(iface_entry_t *iface, address_enume
 /**
  * filter for interfaces
  */
-static bool filter_interfaces(address_enumerator_t *data, iface_entry_t** in, iface_entry_t** out)
+static bool filter_interfaces(address_enumerator_t *data, iface_entry_t** in,
+                                                         iface_entry_t** out)
 {
        if (!data->include_down_ifaces && !((*in)->flags & IFF_UP))
        {   /* skip interfaces not up */
@@ -454,11 +457,9 @@ static bool filter_interfaces(address_enumerator_t *data, iface_entry_t** in, if
        return TRUE;
 }
 
-/**
- * implementation of kernel_net_t.create_address_enumerator
- */
-static enumerator_t *create_address_enumerator(private_kernel_pfroute_net_t *this,
-               bool include_down_ifaces, bool include_virtual_ips)
+METHOD(kernel_net_t, create_address_enumerator, enumerator_t*,
+       private_kernel_pfroute_net_t *this,
+       bool include_down_ifaces, bool include_virtual_ips)
 {
        address_enumerator_t *data = malloc_thing(address_enumerator_t);
        data->this = this;
@@ -467,15 +468,15 @@ static enumerator_t *create_address_enumerator(private_kernel_pfroute_net_t *thi
 
        this->mutex->lock(this->mutex);
        return enumerator_create_nested(
-                               enumerator_create_filter(this->ifaces->create_enumerator(this->ifaces),
-                                               (void*)filter_interfaces, data, NULL),
-                               (void*)create_iface_enumerator, data, (void*)address_enumerator_destroy);
+                               enumerator_create_filter(
+                                       this->ifaces->create_enumerator(this->ifaces),
+                                       (void*)filter_interfaces, data, NULL),
+                               (void*)create_iface_enumerator, data,
+                               (void*)address_enumerator_destroy);
 }
 
-/**
- * implementation of kernel_net_t.get_interface_name
- */
-static char *get_interface_name(private_kernel_pfroute_net_t *this, host_t* ip)
+METHOD(kernel_net_t, get_interface_name, char*,
+       private_kernel_pfroute_net_t *this, host_t* ip)
 {
        enumerator_t *ifaces, *addrs;
        iface_entry_t *iface;
@@ -517,54 +518,40 @@ static char *get_interface_name(private_kernel_pfroute_net_t *this, host_t* ip)
        return name;
 }
 
-/**
- * Implementation of kernel_net_t.get_source_addr.
- */
-static host_t* get_source_addr(private_kernel_pfroute_net_t *this,
-                                                          host_t *dest, host_t *src)
+METHOD(kernel_net_t, get_source_addr, host_t*,
+       private_kernel_pfroute_net_t *this, host_t *dest, host_t *src)
 {
        return NULL;
 }
 
-/**
- * Implementation of kernel_net_t.get_nexthop.
- */
-static host_t* get_nexthop(private_kernel_pfroute_net_t *this, host_t *dest)
+MEHTOD(kernel_net_t, get_nexthop, host_t*,
+       private_kernel_pfroute_net_t *this, host_t *dest)
 {
        return NULL;
 }
 
-/**
- * Implementation of kernel_net_t.add_ip.
- */
-static status_t add_ip(private_kernel_pfroute_net_t *this,
-                                               host_t *virtual_ip, host_t *iface_ip)
+METHOD(kernel_net_t, add_ip, status_t,
+       private_kernel_pfroute_net_t *this, host_t *virtual_ip, host_t *iface_ip)
 {
        return FAILED;
 }
 
-/**
- * Implementation of kernel_net_t.del_ip.
- */
-static status_t del_ip(private_kernel_pfroute_net_t *this, host_t *virtual_ip)
+METHOD(kernel_net_t, del_ip, status_t,
+       private_kernel_pfroute_net_t *this, host_t *virtual_ip)
 {
        return FAILED;
 }
 
-/**
- * Implementation of kernel_net_t.add_route.
- */
-static status_t add_route(private_kernel_pfroute_net_t *this, chunk_t dst_net,
-               u_int8_t prefixlen, host_t *gateway, host_t *src_ip, char *if_name)
+METHOD(kernel_net_t, add_route, status_t,
+       private_kernel_pfroute_net_t *this, chunk_t dst_net, u_int8_t prefixlen,
+       host_t *gateway, host_t *src_ip, char *if_name)
 {
        return FAILED;
 }
 
-/**
- * Implementation of kernel_net_t.del_route.
- */
-static status_t del_route(private_kernel_pfroute_net_t *this, chunk_t dst_net,
-               u_int8_t prefixlen, host_t *gateway, host_t *src_ip, char *if_name)
+METHOD(kernel_net_t, del_route, status_t,
+       private_kernel_pfroute_net_t *this, chunk_t dst_net, u_int8_t prefixlen,
+       host_t *gateway, host_t *src_ip, char *if_name)
 {
        return FAILED;
 }
@@ -658,10 +645,8 @@ static status_t init_address_list(private_kernel_pfroute_net_t *this)
        return SUCCESS;
 }
 
-/**
- * Implementation of kernel_netlink_net_t.destroy.
- */
-static void destroy(private_kernel_pfroute_net_t *this)
+METHOD(kernel__net_t, destroy, void,
+       private_kernel_pfroute_net_t *this)
 {
        if (this->job)
        {
@@ -686,28 +671,26 @@ static void destroy(private_kernel_pfroute_net_t *this)
  */
 kernel_pfroute_net_t *kernel_pfroute_net_create()
 {
-       private_kernel_pfroute_net_t *this = malloc_thing(private_kernel_pfroute_net_t);
-
-       /* public functions */
-       this->public.interface.get_interface = (char*(*)(kernel_net_t*,host_t*))get_interface_name;
-       this->public.interface.create_address_enumerator = (enumerator_t*(*)(kernel_net_t*,bool,bool))create_address_enumerator;
-       this->public.interface.get_source_addr = (host_t*(*)(kernel_net_t*, host_t *dest, host_t *src))get_source_addr;
-       this->public.interface.get_nexthop = (host_t*(*)(kernel_net_t*, host_t *dest))get_nexthop;
-       this->public.interface.add_ip = (status_t(*)(kernel_net_t*,host_t*,host_t*)) add_ip;
-       this->public.interface.del_ip = (status_t(*)(kernel_net_t*,host_t*)) del_ip;
-       this->public.interface.add_route = (status_t(*)(kernel_net_t*,chunk_t,u_int8_t,host_t*,host_t*,char*)) add_route;
-       this->public.interface.del_route = (status_t(*)(kernel_net_t*,chunk_t,u_int8_t,host_t*,host_t*,char*)) del_route;
-
-       this->public.interface.destroy = (void(*)(kernel_net_t*)) destroy;
-
-       /* private members */
-       this->ifaces = linked_list_create();
-       this->mutex = mutex_create(MUTEX_TYPE_DEFAULT);
-       this->mutex_pfroute = mutex_create(MUTEX_TYPE_DEFAULT);
-
-       this->seq = 0;
-       this->socket_events = 0;
-       this->job = NULL;
+       private_kernel_pfroute_net_t *this;
+
+       INIT(this,
+               .public = {
+                       .interface = {
+                               .get_interface = _get_interface_name,
+                               .create_address_enumerator = _create_address_enumerator,
+                               .get_source_addr = _get_source_addr,
+                               .get_nexthop = _get_nexthop,
+                               .add_ip = _add_ip,
+                               .del_ip = _del_ip,
+                               .add_route = _add_route,
+                               .del_route = _del_route,
+                               .destroy = _destroy,
+                       },
+               },
+               .ifaces = linked_list_create(),
+               .mutex = mutex_create(MUTEX_TYPE_DEFAULT),
+               .mutex_pfroute = mutex_create(MUTEX_TYPE_DEFAULT),
+       );
 
        /* create a PF_ROUTE socket to communicate with the kernel */
        this->socket = socket(PF_ROUTE, SOCK_RAW, AF_UNSPEC);