ip: fix interface ip address del sw_if_index check
Type: fix Signed-off-by: Ye donggang <yedg@wangsu.com> Change-Id: Ia9f72ff2be455ecd4ff3d16e884c5a50f9df69fe (cherry picked from commit dbd366b239c0506b0d9984e7481967e038f10a23)
This commit is contained in:
@ -779,7 +779,10 @@ ip4_add_del_interface_address_internal (vlib_main_t * vm,
|
|||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
ip_interface_address_del (lm, if_address_index, addr_fib);
|
error = ip_interface_address_del (lm, vnm, if_address_index, addr_fib,
|
||||||
|
address_length, sw_if_index);
|
||||||
|
if (error)
|
||||||
|
goto done;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -428,7 +428,10 @@ ip6_add_del_interface_address (vlib_main_t * vm,
|
|||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
ip_interface_address_del (lm, if_address_index, addr_fib);
|
error = ip_interface_address_del (lm, vnm, if_address_index, addr_fib,
|
||||||
|
address_length, sw_if_index);
|
||||||
|
if (error)
|
||||||
|
goto done;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -90,14 +90,26 @@ ip_interface_address_add (ip_lookup_main_t * lm,
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
clib_error_t *
|
||||||
ip_interface_address_del (ip_lookup_main_t * lm,
|
ip_interface_address_del (ip_lookup_main_t * lm,
|
||||||
u32 address_index, void *addr_fib)
|
vnet_main_t * vnm,
|
||||||
|
u32 address_index, void *addr_fib,
|
||||||
|
u32 address_length, u32 sw_if_index)
|
||||||
{
|
{
|
||||||
ip_interface_address_t *a, *prev, *next;
|
ip_interface_address_t *a, *prev, *next;
|
||||||
|
|
||||||
a = pool_elt_at_index (lm->if_address_pool, address_index);
|
a = pool_elt_at_index (lm->if_address_pool, address_index);
|
||||||
|
|
||||||
|
if (a->sw_if_index != sw_if_index)
|
||||||
|
{
|
||||||
|
vnm->api_errno = VNET_API_ERROR_ADDRESS_NOT_FOUND_FOR_INTERFACE;
|
||||||
|
return clib_error_create ("%U not found for interface %U",
|
||||||
|
lm->format_address_and_length,
|
||||||
|
addr_fib, address_length,
|
||||||
|
format_vnet_sw_if_index_name,
|
||||||
|
vnet_get_main (), sw_if_index);
|
||||||
|
}
|
||||||
|
|
||||||
if (a->prev_this_sw_interface != ~0)
|
if (a->prev_this_sw_interface != ~0)
|
||||||
{
|
{
|
||||||
prev = pool_elt_at_index (lm->if_address_pool,
|
prev = pool_elt_at_index (lm->if_address_pool,
|
||||||
@ -121,6 +133,7 @@ ip_interface_address_del (ip_lookup_main_t * lm,
|
|||||||
mhash_unset (&lm->address_to_if_address_index, addr_fib,
|
mhash_unset (&lm->address_to_if_address_index, addr_fib,
|
||||||
/* old_value */ 0);
|
/* old_value */ 0);
|
||||||
pool_put (lm->if_address_pool, a);
|
pool_put (lm->if_address_pool, a);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
u8
|
u8
|
||||||
|
@ -28,8 +28,10 @@ clib_error_t *ip_interface_address_add (ip_lookup_main_t * lm,
|
|||||||
void *address,
|
void *address,
|
||||||
u32 address_length,
|
u32 address_length,
|
||||||
u32 * result_index);
|
u32 * result_index);
|
||||||
void ip_interface_address_del (ip_lookup_main_t * lm,
|
clib_error_t *ip_interface_address_del (ip_lookup_main_t * lm,
|
||||||
u32 addr_index, void *address);
|
vnet_main_t * vnm,
|
||||||
|
u32 addr_index, void *address,
|
||||||
|
u32 address_length, u32 sw_if_index);
|
||||||
void *ip_interface_get_first_ip (u32 sw_if_index, u8 is_ip4);
|
void *ip_interface_get_first_ip (u32 sw_if_index, u8 is_ip4);
|
||||||
void ip_interface_address_mark (void);
|
void ip_interface_address_mark (void);
|
||||||
void ip_interface_address_sweep (void);
|
void ip_interface_address_sweep (void);
|
||||||
|
@ -411,6 +411,24 @@ class TestIPv4IfAddrRoute(VppTestCase):
|
|||||||
fib4_dump = self.vapi.ip_route_dump(0)
|
fib4_dump = self.vapi.ip_route_dump(0)
|
||||||
self.assertTrue(lo_if.is_ip4_entry_in_fib_dump(fib4_dump))
|
self.assertTrue(lo_if.is_ip4_entry_in_fib_dump(fib4_dump))
|
||||||
|
|
||||||
|
def test_ipv4_ifaddr_del(self):
|
||||||
|
""" Delete an interface address that does not exist """
|
||||||
|
|
||||||
|
loopbacks = self.create_loopback_interfaces(1)
|
||||||
|
lo = self.lo_interfaces[0]
|
||||||
|
|
||||||
|
lo.config_ip4()
|
||||||
|
lo.admin_up()
|
||||||
|
|
||||||
|
#
|
||||||
|
# try and remove pg0's subnet from lo
|
||||||
|
#
|
||||||
|
with self.vapi.assert_negative_api_retval():
|
||||||
|
self.vapi.sw_interface_add_del_address(
|
||||||
|
sw_if_index=lo.sw_if_index,
|
||||||
|
prefix=self.pg0.local_ip4_prefix,
|
||||||
|
is_add=0)
|
||||||
|
|
||||||
|
|
||||||
class TestICMPEcho(VppTestCase):
|
class TestICMPEcho(VppTestCase):
|
||||||
""" ICMP Echo Test Case """
|
""" ICMP Echo Test Case """
|
||||||
|
@ -1125,6 +1125,24 @@ class TestIPv6IfAddrRoute(VppTestCase):
|
|||||||
self.assertFalse(find_route(self, addr1, 128))
|
self.assertFalse(find_route(self, addr1, 128))
|
||||||
self.assertFalse(find_route(self, addr2, 128))
|
self.assertFalse(find_route(self, addr2, 128))
|
||||||
|
|
||||||
|
def test_ipv6_ifaddr_del(self):
|
||||||
|
""" Delete an interface address that does not exist """
|
||||||
|
|
||||||
|
loopbacks = self.create_loopback_interfaces(1)
|
||||||
|
lo = self.lo_interfaces[0]
|
||||||
|
|
||||||
|
lo.config_ip6()
|
||||||
|
lo.admin_up()
|
||||||
|
|
||||||
|
#
|
||||||
|
# try and remove pg0's subnet from lo
|
||||||
|
#
|
||||||
|
with self.vapi.assert_negative_api_retval():
|
||||||
|
self.vapi.sw_interface_add_del_address(
|
||||||
|
sw_if_index=lo.sw_if_index,
|
||||||
|
prefix=self.pg0.local_ip6_prefix,
|
||||||
|
is_add=0)
|
||||||
|
|
||||||
|
|
||||||
class TestICMPv6Echo(VppTestCase):
|
class TestICMPv6Echo(VppTestCase):
|
||||||
""" ICMPv6 Echo Test Case """
|
""" ICMPv6 Echo Test Case """
|
||||||
|
Reference in New Issue
Block a user