aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/dumm/ext/dumm.c14
-rw-r--r--src/dumm/iface.c12
-rw-r--r--src/dumm/iface.h10
3 files changed, 21 insertions, 15 deletions
diff --git a/src/dumm/ext/dumm.c b/src/dumm/ext/dumm.c
index a9c7cb8bd..ca9b29388 100644
--- a/src/dumm/ext/dumm.c
+++ b/src/dumm/ext/dumm.c
@@ -594,21 +594,22 @@ static VALUE iface_add_addr(VALUE self, VALUE name)
{
iface_t *iface;
host_t *addr;
+ int bits;
- addr = host_create_from_string(StringValuePtr(name), 0);
+ addr = host_create_from_subnet(StringValuePtr(name), &bits);
if (!addr)
{
rb_raise(rb_eArgError, "invalid IP address");
}
Data_Get_Struct(self, iface_t, iface);
- if (!iface->add_address(iface, addr))
+ if (!iface->add_address(iface, addr, bits))
{
addr->destroy(addr);
rb_raise(rb_eRuntimeError, "adding address failed");
}
if (rb_block_given_p()) {
rb_yield(self);
- iface->delete_address(iface, addr);
+ iface->delete_address(iface, addr, bits);
}
addr->destroy(addr);
return self;
@@ -647,21 +648,22 @@ static VALUE iface_del_addr(VALUE self, VALUE vaddr)
{
iface_t *iface;
host_t *addr;
+ int bits;
- addr = host_create_from_string(StringValuePtr(vaddr), 0);
+ addr = host_create_from_subnet(StringValuePtr(vaddr), &bits);
if (!addr)
{
rb_raise(rb_eArgError, "invalid IP address");
}
Data_Get_Struct(self, iface_t, iface);
- if (!iface->delete_address(iface, addr))
+ if (!iface->delete_address(iface, addr, bits))
{
addr->destroy(addr);
rb_raise(rb_eRuntimeError, "address not found");
}
if (rb_block_given_p()) {
rb_yield(self);
- iface->add_address(iface, addr);
+ iface->add_address(iface, addr, bits);
}
addr->destroy(addr);
return self;
diff --git a/src/dumm/iface.c b/src/dumm/iface.c
index 1b5b7d717..483784f54 100644
--- a/src/dumm/iface.c
+++ b/src/dumm/iface.c
@@ -102,10 +102,10 @@ static char* get_hostif(private_iface_t *this)
/**
* Implementation of iface_t.add_address
*/
-static bool add_address(private_iface_t *this, host_t *addr)
+static bool add_address(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);
}
/**
@@ -146,10 +146,10 @@ static enumerator_t* create_address_enumerator(private_iface_t *this)
/**
* Implementation of iface_t.delete_address
*/
-static bool delete_address(private_iface_t *this, host_t *addr)
+static bool delete_address(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);
}
/**
@@ -277,9 +277,9 @@ iface_t *iface_create(char *name, guest_t *guest, mconsole_t *mconsole)
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.add_address = (bool(*)(iface_t*,host_t*,int))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.delete_address = (bool(*)(iface_t*,host_t*,int))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;
diff --git a/src/dumm/iface.h b/src/dumm/iface.h
index dabefaa17..e96ee508c 100644
--- a/src/dumm/iface.h
+++ b/src/dumm/iface.h
@@ -50,10 +50,11 @@ struct iface_t {
/**
* Add an address to the interface.
*
- * @param addr address to add to interface
+ * @param addr address to add to the interface
+ * @param bits network prefix length in bits
* @return TRUE if address added
*/
- bool (*add_address)(iface_t *this, host_t *addr);
+ bool (*add_address)(iface_t *this, host_t *addr, int bits);
/**
* Create an enumerator over all installed addresses.
@@ -65,10 +66,13 @@ struct iface_t {
/**
* Remove an address from an interface.
*
+ * @note The network prefix length has to be the same as used in add_address
+ *
* @param addr address to remove
+ * @param bits network prefix length in bits
* @return TRUE if address removed
*/
- bool (*delete_address)(iface_t *this, host_t *addr);
+ bool (*delete_address)(iface_t *this, host_t *addr, int bits);
/**
* Set the bridge this interface is attached to.