Migrated iface_t to INIT/METHOD macros.
This commit is contained in:
+35
-51
@@ -83,26 +83,20 @@ bool iface_control(char *name, bool up)
|
|||||||
return good;
|
return good;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(iface_t, get_guestif, char*,
|
||||||
* Implementation of iface_t.get_guestif.
|
private_iface_t *this)
|
||||||
*/
|
|
||||||
static char* get_guestif(private_iface_t *this)
|
|
||||||
{
|
{
|
||||||
return this->guestif;
|
return this->guestif;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(iface_t, get_hostif, char*,
|
||||||
* Implementation of iface_t.get_hostif.
|
private_iface_t *this)
|
||||||
*/
|
|
||||||
static char* get_hostif(private_iface_t *this)
|
|
||||||
{
|
{
|
||||||
return this->hostif;
|
return this->hostif;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(iface_t, add_address, bool,
|
||||||
* Implementation of iface_t.add_address
|
private_iface_t *this, host_t *addr, int bits)
|
||||||
*/
|
|
||||||
static bool add_address(private_iface_t *this, host_t *addr, int bits)
|
|
||||||
{
|
{
|
||||||
return (this->guest->exec(this->guest, NULL, NULL,
|
return (this->guest->exec(this->guest, NULL, NULL,
|
||||||
"exec ip addr add %H/%d dev %s", addr, bits, 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));
|
list->destroy_offset(list, offsetof(host_t, destroy));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(iface_t, create_address_enumerator, enumerator_t*,
|
||||||
* Implementation of iface_t.create_address_enumerator
|
private_iface_t *this)
|
||||||
*/
|
|
||||||
static enumerator_t* create_address_enumerator(private_iface_t *this)
|
|
||||||
{
|
{
|
||||||
linked_list_t *addresses = linked_list_create();
|
linked_list_t *addresses = linked_list_create();
|
||||||
this->guest->exec_str(this->guest, (void(*)(void*,char*))compile_address_list,
|
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);
|
(void(*)(void*))destroy_address_list, addresses);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(iface_t, delete_address, bool,
|
||||||
* Implementation of iface_t.delete_address
|
private_iface_t *this, host_t *addr, int bits)
|
||||||
*/
|
|
||||||
static bool delete_address(private_iface_t *this, host_t *addr, int bits)
|
|
||||||
{
|
{
|
||||||
return (this->guest->exec(this->guest, NULL, NULL,
|
return (this->guest->exec(this->guest, NULL, NULL,
|
||||||
"exec ip addr del %H/%d dev %s", addr, bits, this->guestif) == 0);
|
"exec ip addr del %H/%d dev %s", addr, bits, this->guestif) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(iface_t, set_bridge, void,
|
||||||
* Implementation of iface_t.set_bridge.
|
private_iface_t *this, bridge_t *bridge)
|
||||||
*/
|
|
||||||
static void set_bridge(private_iface_t *this, bridge_t *bridge)
|
|
||||||
{
|
{
|
||||||
if (this->bridge == NULL && bridge)
|
if (this->bridge == NULL && bridge)
|
||||||
{
|
{
|
||||||
@@ -170,18 +158,14 @@ static void set_bridge(private_iface_t *this, bridge_t *bridge)
|
|||||||
this->bridge = bridge;
|
this->bridge = bridge;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(iface_t, get_bridge, bridge_t*,
|
||||||
* Implementation of iface_t.get_bridge
|
private_iface_t *this)
|
||||||
*/
|
|
||||||
static bridge_t *get_bridge(private_iface_t *this)
|
|
||||||
{
|
{
|
||||||
return this->bridge;
|
return this->bridge;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(iface_t, get_guest, guest_t*,
|
||||||
* Implementation of iface_t.get_guest
|
private_iface_t *this)
|
||||||
*/
|
|
||||||
static guest_t* get_guest(private_iface_t *this)
|
|
||||||
{
|
{
|
||||||
return this->guest;
|
return this->guest;
|
||||||
}
|
}
|
||||||
@@ -250,10 +234,8 @@ static char* create_tap(private_iface_t *this)
|
|||||||
return strdup(ifr.ifr_name);
|
return strdup(ifr.ifr_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(iface_t, destroy, void,
|
||||||
* Implementation of iface_t.destroy.
|
private_iface_t *this)
|
||||||
*/
|
|
||||||
static void destroy(private_iface_t *this)
|
|
||||||
{
|
{
|
||||||
if (this->bridge)
|
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)
|
iface_t *iface_create(char *name, guest_t *guest, mconsole_t *mconsole)
|
||||||
{
|
{
|
||||||
private_iface_t *this = malloc_thing(private_iface_t);
|
private_iface_t *this;
|
||||||
|
|
||||||
this->public.get_hostif = (char*(*)(iface_t*))get_hostif;
|
INIT(this,
|
||||||
this->public.get_guestif = (char*(*)(iface_t*))get_guestif;
|
.public = {
|
||||||
this->public.add_address = (bool(*)(iface_t*,host_t*,int))add_address;
|
.get_hostif = _get_hostif,
|
||||||
this->public.create_address_enumerator = (enumerator_t*(*)(iface_t*))create_address_enumerator;
|
.get_guestif = _get_guestif,
|
||||||
this->public.delete_address = (bool(*)(iface_t*,host_t*,int))delete_address;
|
.add_address = _add_address,
|
||||||
this->public.set_bridge = (void(*)(iface_t*, bridge_t*))set_bridge;
|
.create_address_enumerator = _create_address_enumerator,
|
||||||
this->public.get_bridge = (bridge_t*(*)(iface_t*))get_bridge;
|
.delete_address = _delete_address,
|
||||||
this->public.get_guest = (guest_t*(*)(iface_t*))get_guest;
|
.set_bridge = _set_bridge,
|
||||||
this->public.destroy = (void*)destroy;
|
.get_bridge = _get_bridge,
|
||||||
|
.get_guest = _get_guest,
|
||||||
this->mconsole = mconsole;
|
.destroy = _destroy,
|
||||||
this->guestif = strdup(name);
|
},
|
||||||
this->guest = guest;
|
.mconsole = mconsole,
|
||||||
|
.guestif = strdup(name),
|
||||||
|
.guest = guest,
|
||||||
|
);
|
||||||
this->hostif = create_tap(this);
|
this->hostif = create_tap(this);
|
||||||
this->bridge = NULL;
|
|
||||||
if (this->hostif == NULL)
|
if (this->hostif == NULL)
|
||||||
{
|
{
|
||||||
destroy_tap(this);
|
destroy_tap(this);
|
||||||
|
|||||||
Reference in New Issue
Block a user