summaryrefslogtreecommitdiff
path: root/src/dumm/iface.c
diff options
context:
space:
mode:
authorYves-Alexis Perez <corsac@corsac.net>2012-06-28 21:16:07 +0200
committerYves-Alexis Perez <corsac@corsac.net>2012-06-28 21:16:07 +0200
commitb34738ed08c2227300d554b139e2495ca5da97d6 (patch)
tree62f33b52820f2e49f0e53c0f8c636312037c8054 /src/dumm/iface.c
parent0a9d51a49042a68daa15b0c74a2b7f152f52606b (diff)
downloadvyos-strongswan-b34738ed08c2227300d554b139e2495ca5da97d6.tar.gz
vyos-strongswan-b34738ed08c2227300d554b139e2495ca5da97d6.zip
Imported Upstream version 4.6.4
Diffstat (limited to 'src/dumm/iface.c')
-rw-r--r--src/dumm/iface.c90
1 files changed, 37 insertions, 53 deletions
diff --git a/src/dumm/iface.c b/src/dumm/iface.c
index 1b5b7d717..214387e88 100644
--- a/src/dumm/iface.c
+++ b/src/dumm/iface.c
@@ -83,29 +83,23 @@ bool iface_control(char *name, bool up)
return good;
}
-/**
- * Implementation of iface_t.get_guestif.
- */
-static char* get_guestif(private_iface_t *this)
+METHOD(iface_t, get_guestif, char*,
+ private_iface_t *this)
{
return this->guestif;
}
-/**
- * Implementation of iface_t.get_hostif.
- */
-static char* get_hostif(private_iface_t *this)
+METHOD(iface_t, get_hostif, char*,
+ private_iface_t *this)
{
return this->hostif;
}
-/**
- * Implementation of iface_t.add_address
- */
-static bool add_address(private_iface_t *this, host_t *addr)
+METHOD(iface_t, add_address, bool,
+ private_iface_t *this, host_t *addr, int bits)
{
return (this->guest->exec(this->guest, NULL, NULL,
- "exec ip addr add %H dev %s", addr, this->guestif) == 0);
+ "exec ip addr add %H/%d dev %s", addr, bits, this->guestif) == 0);
}
/**
@@ -128,10 +122,8 @@ static void destroy_address_list(linked_list_t *list)
list->destroy_offset(list, offsetof(host_t, destroy));
}
-/**
- * Implementation of iface_t.create_address_enumerator
- */
-static enumerator_t* create_address_enumerator(private_iface_t *this)
+METHOD(iface_t, create_address_enumerator, enumerator_t*,
+ private_iface_t *this)
{
linked_list_t *addresses = linked_list_create();
this->guest->exec_str(this->guest, (void(*)(void*,char*))compile_address_list,
@@ -143,19 +135,15 @@ static enumerator_t* create_address_enumerator(private_iface_t *this)
(void(*)(void*))destroy_address_list, addresses);
}
-/**
- * Implementation of iface_t.delete_address
- */
-static bool delete_address(private_iface_t *this, host_t *addr)
+METHOD(iface_t, delete_address, bool,
+ private_iface_t *this, host_t *addr, int bits)
{
return (this->guest->exec(this->guest, NULL, NULL,
- "exec ip addr del %H dev %s", addr, this->guestif) == 0);
+ "exec ip addr del %H/%d dev %s", addr, bits, this->guestif) == 0);
}
-/**
- * Implementation of iface_t.set_bridge.
- */
-static void set_bridge(private_iface_t *this, bridge_t *bridge)
+METHOD(iface_t, set_bridge, void,
+ private_iface_t *this, bridge_t *bridge)
{
if (this->bridge == NULL && bridge)
{
@@ -170,18 +158,14 @@ static void set_bridge(private_iface_t *this, bridge_t *bridge)
this->bridge = bridge;
}
-/**
- * Implementation of iface_t.get_bridge
- */
-static bridge_t *get_bridge(private_iface_t *this)
+METHOD(iface_t, get_bridge, bridge_t*,
+ private_iface_t *this)
{
return this->bridge;
}
-/**
- * Implementation of iface_t.get_guest
- */
-static guest_t* get_guest(private_iface_t *this)
+METHOD(iface_t, get_guest, guest_t*,
+ private_iface_t *this)
{
return this->guest;
}
@@ -250,10 +234,8 @@ static char* create_tap(private_iface_t *this)
return strdup(ifr.ifr_name);
}
-/**
- * Implementation of iface_t.destroy.
- */
-static void destroy(private_iface_t *this)
+METHOD(iface_t, destroy, void,
+ private_iface_t *this)
{
if (this->bridge)
{
@@ -273,23 +255,25 @@ static void destroy(private_iface_t *this)
*/
iface_t *iface_create(char *name, guest_t *guest, mconsole_t *mconsole)
{
- private_iface_t *this = malloc_thing(private_iface_t);
-
- this->public.get_hostif = (char*(*)(iface_t*))get_hostif;
- this->public.get_guestif = (char*(*)(iface_t*))get_guestif;
- this->public.add_address = (bool(*)(iface_t*, host_t *addr))add_address;
- this->public.create_address_enumerator = (enumerator_t*(*)(iface_t*))create_address_enumerator;
- this->public.delete_address = (bool(*)(iface_t*, host_t *addr))delete_address;
- this->public.set_bridge = (void(*)(iface_t*, bridge_t*))set_bridge;
- this->public.get_bridge = (bridge_t*(*)(iface_t*))get_bridge;
- this->public.get_guest = (guest_t*(*)(iface_t*))get_guest;
- this->public.destroy = (void*)destroy;
+ private_iface_t *this;
- this->mconsole = mconsole;
- this->guestif = strdup(name);
- this->guest = guest;
+ INIT(this,
+ .public = {
+ .get_hostif = _get_hostif,
+ .get_guestif = _get_guestif,
+ .add_address = _add_address,
+ .create_address_enumerator = _create_address_enumerator,
+ .delete_address = _delete_address,
+ .set_bridge = _set_bridge,
+ .get_bridge = _get_bridge,
+ .get_guest = _get_guest,
+ .destroy = _destroy,
+ },
+ .mconsole = mconsole,
+ .guestif = strdup(name),
+ .guest = guest,
+ );
this->hostif = create_tap(this);
- this->bridge = NULL;
if (this->hostif == NULL)
{
destroy_tap(this);