the list of addresses on the interface of a guest is not cached anymore, but queried directly from the interface
This commit is contained in:
+30
-31
@@ -44,8 +44,6 @@ struct private_iface_t {
|
|||||||
guest_t *guest;
|
guest_t *guest;
|
||||||
/** mconsole for guest */
|
/** mconsole for guest */
|
||||||
mconsole_t *mconsole;
|
mconsole_t *mconsole;
|
||||||
/** list of interface addresses */
|
|
||||||
linked_list_t *addresses;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -105,14 +103,28 @@ static char* get_hostif(private_iface_t *this)
|
|||||||
*/
|
*/
|
||||||
static bool add_address(private_iface_t *this, host_t *addr)
|
static bool add_address(private_iface_t *this, host_t *addr)
|
||||||
{
|
{
|
||||||
if (this->guest->exec(this->guest, NULL, NULL, "ip addr add %H dev %s",
|
return (this->guest->exec(this->guest, NULL, NULL, "ip addr add %H dev %s",
|
||||||
addr, this->guestif) == 0)
|
addr, this->guestif) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* compile a list of the addresses of an interface
|
||||||
|
*/
|
||||||
|
static void compile_address_list(linked_list_t *list, char *address)
|
||||||
|
{
|
||||||
|
host_t *host = host_create_from_string(address, 0);
|
||||||
|
if (host)
|
||||||
{
|
{
|
||||||
this->addresses->insert_last(this->addresses, addr);
|
list->insert_last(list, host);
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
addr->destroy(addr);
|
}
|
||||||
return FALSE;
|
|
||||||
|
/**
|
||||||
|
* delete the list of addresses
|
||||||
|
*/
|
||||||
|
static void destroy_address_list(linked_list_t *list)
|
||||||
|
{
|
||||||
|
list->destroy_offset(list, offsetof(host_t, destroy));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -120,7 +132,14 @@ static bool add_address(private_iface_t *this, host_t *addr)
|
|||||||
*/
|
*/
|
||||||
static enumerator_t* create_address_enumerator(private_iface_t *this)
|
static enumerator_t* create_address_enumerator(private_iface_t *this)
|
||||||
{
|
{
|
||||||
return this->addresses->create_enumerator(this->addresses);
|
linked_list_t *addresses = linked_list_create();
|
||||||
|
this->guest->exec_str(this->guest, (void(*)(void*,char*))compile_address_list,
|
||||||
|
TRUE, addresses,
|
||||||
|
"ip addr list dev %s scope global | "
|
||||||
|
"grep '^ \\+\\(inet6\\? \\)' | "
|
||||||
|
"awk -F '( +|/)' '{ print $3 }'", this->guestif);
|
||||||
|
return enumerator_create_cleaner(addresses->create_enumerator(addresses),
|
||||||
|
(void(*)(void*))destroy_address_list, addresses);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -128,26 +147,8 @@ static enumerator_t* create_address_enumerator(private_iface_t *this)
|
|||||||
*/
|
*/
|
||||||
static bool delete_address(private_iface_t *this, host_t *addr)
|
static bool delete_address(private_iface_t *this, host_t *addr)
|
||||||
{
|
{
|
||||||
enumerator_t *enumerator;
|
return (this->guest->exec(this->guest, NULL, NULL,
|
||||||
bool success = FALSE;
|
"ip addr del %H dev %s", addr, this->guestif) == 0);
|
||||||
host_t *current;
|
|
||||||
|
|
||||||
enumerator = create_address_enumerator(this);
|
|
||||||
while (enumerator->enumerate(enumerator, ¤t))
|
|
||||||
{
|
|
||||||
if (current->ip_equals(current, addr))
|
|
||||||
{
|
|
||||||
if (this->guest->exec(this->guest, NULL, NULL,
|
|
||||||
"ip addr del %H dev %s", current, this->guestif) == 0)
|
|
||||||
{
|
|
||||||
this->addresses->remove_at(this->addresses, enumerator);
|
|
||||||
success = TRUE;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
enumerator->destroy(enumerator);
|
|
||||||
return success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -263,7 +264,6 @@ static void destroy(private_iface_t *this)
|
|||||||
destroy_tap(this);
|
destroy_tap(this);
|
||||||
free(this->guestif);
|
free(this->guestif);
|
||||||
free(this->hostif);
|
free(this->hostif);
|
||||||
this->addresses->destroy(this->addresses);
|
|
||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -309,7 +309,6 @@ iface_t *iface_create(char *name, guest_t *guest, mconsole_t *mconsole)
|
|||||||
{
|
{
|
||||||
DBG1("bringing iface '%s' up failed: %m", this->hostif);
|
DBG1("bringing iface '%s' up failed: %m", this->hostif);
|
||||||
}
|
}
|
||||||
this->addresses = linked_list_create();
|
|
||||||
return &this->public;
|
return &this->public;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-1
@@ -443,13 +443,14 @@ static VALUE iface_add_addr(VALUE self, VALUE name)
|
|||||||
addr = host_create_from_string(StringValuePtr(name), 0);
|
addr = host_create_from_string(StringValuePtr(name), 0);
|
||||||
if (!addr)
|
if (!addr)
|
||||||
{
|
{
|
||||||
rb_raise(rb_eRuntimeError, "invalid IP address");
|
rb_raise(rb_eArgError, "invalid IP address");
|
||||||
}
|
}
|
||||||
Data_Get_Struct(self, iface_t, iface);
|
Data_Get_Struct(self, iface_t, iface);
|
||||||
if (!iface->add_address(iface, addr))
|
if (!iface->add_address(iface, addr))
|
||||||
{
|
{
|
||||||
rb_raise(rb_eRuntimeError, "adding address failed");
|
rb_raise(rb_eRuntimeError, "adding address failed");
|
||||||
}
|
}
|
||||||
|
addr->destroy(addr);
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -481,6 +482,10 @@ static VALUE iface_del_addr(VALUE self, VALUE vaddr)
|
|||||||
host_t *addr;
|
host_t *addr;
|
||||||
|
|
||||||
addr = host_create_from_string(StringValuePtr(vaddr), 0);
|
addr = host_create_from_string(StringValuePtr(vaddr), 0);
|
||||||
|
if (!addr)
|
||||||
|
{
|
||||||
|
rb_raise(rb_eArgError, "invalid IP address");
|
||||||
|
}
|
||||||
Data_Get_Struct(self, iface_t, iface);
|
Data_Get_Struct(self, iface_t, iface);
|
||||||
if (!iface->delete_address(iface, addr))
|
if (!iface->delete_address(iface, addr))
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user