{
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;
{
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;
/**
* 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);
}
/**
/**
* 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);
}
/**
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;
/**
* 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.
/**
* 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.