aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/vnet/interface.c45
-rw-r--r--src/vnet/interface_api.c39
-rw-r--r--src/vnet/interface_cli.c54
-rw-r--r--src/vnet/interface_funcs.h4
-rw-r--r--src/vnet/ip/ip4_forward.c3
-rw-r--r--src/vnet/ip/ip6_forward.c3
-rw-r--r--test/test_p2p_ethernet.py51
-rw-r--r--test/vpp_sub_interface.py2
8 files changed, 101 insertions, 100 deletions
diff --git a/src/vnet/interface.c b/src/vnet/interface.c
index b197aa1e073..122ae065ad0 100644
--- a/src/vnet/interface.c
+++ b/src/vnet/interface.c
@@ -1414,6 +1414,51 @@ vnet_hw_interface_change_mac_address (vnet_main_t * vnm, u32 hw_if_index,
(vnm, hw_if_index, mac_address);
}
+/* update the unnumbered state of an interface*/
+void
+vnet_sw_interface_update_unnumbered (u32 unnumbered_sw_if_index,
+ u32 ip_sw_if_index, u8 enable)
+{
+ vnet_main_t *vnm = vnet_get_main ();
+ vnet_sw_interface_t *si;
+ u32 was_unnum;
+
+ si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
+ was_unnum = (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED);
+
+ if (enable)
+ {
+ si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
+ si->unnumbered_sw_if_index = ip_sw_if_index;
+
+ ip4_main.lookup_main.if_address_pool_index_by_sw_if_index
+ [unnumbered_sw_if_index] =
+ ip4_main.
+ lookup_main.if_address_pool_index_by_sw_if_index[ip_sw_if_index];
+ ip6_main.
+ lookup_main.if_address_pool_index_by_sw_if_index
+ [unnumbered_sw_if_index] =
+ ip6_main.
+ lookup_main.if_address_pool_index_by_sw_if_index[ip_sw_if_index];
+ }
+ else
+ {
+ si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
+ si->unnumbered_sw_if_index = (u32) ~ 0;
+
+ ip4_main.lookup_main.if_address_pool_index_by_sw_if_index
+ [unnumbered_sw_if_index] = ~0;
+ ip6_main.lookup_main.if_address_pool_index_by_sw_if_index
+ [unnumbered_sw_if_index] = ~0;
+ }
+
+ if (was_unnum != (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
+ {
+ ip4_sw_interface_enable_disable (unnumbered_sw_if_index, enable);
+ ip6_sw_interface_enable_disable (unnumbered_sw_if_index, enable);
+ }
+}
+
vnet_l3_packet_type_t
vnet_link_to_l3_proto (vnet_link_t link)
{
diff --git a/src/vnet/interface_api.c b/src/vnet/interface_api.c
index fc7af1be463..b22cadd871e 100644
--- a/src/vnet/interface_api.c
+++ b/src/vnet/interface_api.c
@@ -582,7 +582,6 @@ static void vl_api_sw_interface_set_unnumbered_t_handler
vnet_main_t *vnm = vnet_get_main ();
u32 sw_if_index = ntohl (mp->sw_if_index);
u32 unnumbered_sw_if_index = ntohl (mp->unnumbered_sw_if_index);
- u32 was_unnum;
/*
* The API message field names are backwards from
@@ -602,42 +601,8 @@ static void vl_api_sw_interface_set_unnumbered_t_handler
goto done;
}
- vnet_sw_interface_t *si =
- vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
- was_unnum = (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED);
-
- if (mp->is_add)
- {
- si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
- si->unnumbered_sw_if_index = sw_if_index;
-
- ip4_main.lookup_main.if_address_pool_index_by_sw_if_index
- [unnumbered_sw_if_index] =
- ip4_main.
- lookup_main.if_address_pool_index_by_sw_if_index[sw_if_index];
- ip6_main.
- lookup_main.if_address_pool_index_by_sw_if_index
- [unnumbered_sw_if_index] =
- ip6_main.
- lookup_main.if_address_pool_index_by_sw_if_index[sw_if_index];
- }
- else
- {
- si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
- si->unnumbered_sw_if_index = (u32) ~ 0;
-
- ip4_main.lookup_main.if_address_pool_index_by_sw_if_index
- [unnumbered_sw_if_index] = ~0;
- ip6_main.lookup_main.if_address_pool_index_by_sw_if_index
- [unnumbered_sw_if_index] = ~0;
- }
-
- if (was_unnum != (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
- {
- ip4_sw_interface_enable_disable (unnumbered_sw_if_index, mp->is_add);
- ip6_sw_interface_enable_disable (unnumbered_sw_if_index, mp->is_add);
- }
-
+ vnet_sw_interface_update_unnumbered (unnumbered_sw_if_index,
+ sw_if_index, mp->is_add);
done:
REPLY_MACRO (VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
}
diff --git a/src/vnet/interface_cli.c b/src/vnet/interface_cli.c
index 8880d9749b8..d151335aa1f 100644
--- a/src/vnet/interface_cli.c
+++ b/src/vnet/interface_cli.c
@@ -934,60 +934,32 @@ set_unnumbered (vlib_main_t * vm,
unformat_input_t * input, vlib_cli_command_t * cmd)
{
vnet_main_t *vnm = vnet_get_main ();
- u32 unnumbered_sw_if_index;
- u32 inherit_from_sw_if_index;
- vnet_sw_interface_t *si;
- int is_set = 0;
- int is_del = 0;
- u32 was_unnum;
+ u32 unnumbered_sw_if_index = ~0;
+ u32 inherit_from_sw_if_index = ~0;
+ int enable = 1;
if (unformat (input, "%U use %U",
unformat_vnet_sw_interface, vnm, &unnumbered_sw_if_index,
unformat_vnet_sw_interface, vnm, &inherit_from_sw_if_index))
- is_set = 1;
+ enable = 1;
else if (unformat (input, "del %U",
unformat_vnet_sw_interface, vnm,
&unnumbered_sw_if_index))
- is_del = 1;
+ enable = 0;
else
return clib_error_return (0, "parse error '%U'",
format_unformat_error, input);
- si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
- was_unnum = (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED);
+ if (~0 == unnumbered_sw_if_index)
+ return clib_error_return (0, "Specify the unnumbered interface");
+ if (enable && ~0 == inherit_from_sw_if_index)
+ return clib_error_return (0, "When enabling unnumberered specify the"
+ " IP enabled interface that it uses");
- if (is_del)
- {
- si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
- si->unnumbered_sw_if_index = (u32) ~ 0;
-
- ip4_main.lookup_main.if_address_pool_index_by_sw_if_index
- [unnumbered_sw_if_index] = ~0;
- ip6_main.lookup_main.if_address_pool_index_by_sw_if_index
- [unnumbered_sw_if_index] = ~0;
- }
- else if (is_set)
- {
- si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
- si->unnumbered_sw_if_index = inherit_from_sw_if_index;
-
- ip4_main.lookup_main.if_address_pool_index_by_sw_if_index
- [unnumbered_sw_if_index] =
- ip4_main.lookup_main.if_address_pool_index_by_sw_if_index
- [inherit_from_sw_if_index];
- ip6_main.lookup_main.if_address_pool_index_by_sw_if_index
- [unnumbered_sw_if_index] =
- ip6_main.lookup_main.if_address_pool_index_by_sw_if_index
- [inherit_from_sw_if_index];
- }
+ vnet_sw_interface_update_unnumbered (unnumbered_sw_if_index,
+ inherit_from_sw_if_index, enable);
- if (was_unnum != (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
- {
- ip4_sw_interface_enable_disable (unnumbered_sw_if_index, !is_del);
- ip6_sw_interface_enable_disable (unnumbered_sw_if_index, !is_del);
- }
-
- return 0;
+ return (NULL);
}
/* *INDENT-OFF* */
diff --git a/src/vnet/interface_funcs.h b/src/vnet/interface_funcs.h
index 9c96027b705..3d045f84d2b 100644
--- a/src/vnet/interface_funcs.h
+++ b/src/vnet/interface_funcs.h
@@ -295,6 +295,10 @@ clib_error_t *set_hw_interface_change_rx_mode (vnet_main_t * vnm,
/* Set the MTU on the HW interface */
void vnet_hw_interface_set_mtu (vnet_main_t * vnm, u32 hw_if_index, u32 mtu);
+/* update the unnumbered state of an interface */
+void vnet_sw_interface_update_unnumbered (u32 sw_if_index,
+ u32 ip_sw_if_index, u8 enable);
+
/* Formats sw/hw interface. */
format_function_t format_vnet_hw_interface;
format_function_t format_vnet_hw_interface_rx_mode;
diff --git a/src/vnet/ip/ip4_forward.c b/src/vnet/ip/ip4_forward.c
index 6b7eb9c0f30..19babced33f 100644
--- a/src/vnet/ip/ip4_forward.c
+++ b/src/vnet/ip/ip4_forward.c
@@ -793,8 +793,9 @@ ip4_sw_interface_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_add)
ip4_address_t *address;
vlib_main_t *vm = vlib_get_main ();
+ vnet_sw_interface_update_unnumbered (sw_if_index, ~0, 0);
/* *INDENT-OFF* */
- foreach_ip_interface_address (lm4, ia, sw_if_index, 1 /* honor unnumbered */,
+ foreach_ip_interface_address (lm4, ia, sw_if_index, 0,
({
address = ip_interface_address_get_address (lm4, ia);
ip4_add_del_interface_address(vm, sw_if_index, address, ia->address_length, 1);
diff --git a/src/vnet/ip/ip6_forward.c b/src/vnet/ip/ip6_forward.c
index eb7667b0148..3eb84e8b9ef 100644
--- a/src/vnet/ip/ip6_forward.c
+++ b/src/vnet/ip/ip6_forward.c
@@ -432,8 +432,9 @@ ip6_sw_interface_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_add)
vlib_main_t *vm = vlib_get_main ();
ip6_neighbor_sw_interface_add_del (vnm, sw_if_index, 0 /* is_add */ );
+ vnet_sw_interface_update_unnumbered (sw_if_index, ~0, 0);
/* *INDENT-OFF* */
- foreach_ip_interface_address (lm6, ia, sw_if_index, 1 /* honor unnumbered */,
+ foreach_ip_interface_address (lm6, ia, sw_if_index, 0,
({
address = ip_interface_address_get_address (lm6, ia);
ip6_add_del_interface_address(vm, sw_if_index, address, ia->address_length, 1);
diff --git a/test/test_p2p_ethernet.py b/test/test_p2p_ethernet.py
index 5295d1c0c6e..d6d5c5071c4 100644
--- a/test/test_p2p_ethernet.py
+++ b/test/test_p2p_ethernet.py
@@ -126,15 +126,19 @@ class P2PEthernetIPV6(VppTestCase):
super(P2PEthernetIPV6, self).setUp()
for p in self.packets:
self.packets.remove(p)
- self.create_p2p_ethernet(self.pg0, 1, self.pg0._remote_hosts[0].mac)
- self.create_p2p_ethernet(self.pg0, 2, self.pg0._remote_hosts[1].mac)
- self.p2p_sub_ifs[0].config_ip6()
- self.p2p_sub_ifs[1].config_ip6()
+ self.p2p_sub_ifs.append(
+ self.create_p2p_ethernet(self.pg0, 1,
+ self.pg0._remote_hosts[0].mac))
+ self.p2p_sub_ifs.append(
+ self.create_p2p_ethernet(self.pg0, 2,
+ self.pg0._remote_hosts[1].mac))
self.vapi.cli("trace add p2p-ethernet-input 50")
def tearDown(self):
- self.delete_p2p_ethernet(self.pg0, self.pg0._remote_hosts[0].mac)
- self.delete_p2p_ethernet(self.pg0, self.pg0._remote_hosts[1].mac)
+ while len(self.p2p_sub_ifs):
+ p2p = self.p2p_sub_ifs.pop()
+ self.delete_p2p_ethernet(p2p)
+
super(P2PEthernetIPV6, self).tearDown()
def create_p2p_ethernet(self, parent_if, sub_id, remote_mac):
@@ -142,11 +146,13 @@ class P2PEthernetIPV6(VppTestCase):
p2p.admin_up()
p2p.config_ip6()
p2p.disable_ipv6_ra()
- self.p2p_sub_ifs.append(p2p)
+ return p2p
- def delete_p2p_ethernet(self, parent_if, remote_mac):
- self.vapi.delete_p2pethernet_subif(parent_if.sw_if_index,
- mactobinary(remote_mac))
+ def delete_p2p_ethernet(self, p2p):
+ p2p.unconfig_ip6()
+ p2p.admin_down()
+ self.vapi.delete_p2pethernet_subif(p2p.parent.sw_if_index,
+ p2p.p2p_remote_mac)
def create_stream(self, src_mac=None, dst_mac=None,
src_ip=None, dst_ip=None, size=None):
@@ -355,15 +361,18 @@ class P2PEthernetIPV4(VppTestCase):
super(P2PEthernetIPV4, self).setUp()
for p in self.packets:
self.packets.remove(p)
- self.create_p2p_ethernet(self.pg0, 1, self.pg0._remote_hosts[0].mac)
- self.create_p2p_ethernet(self.pg0, 2, self.pg0._remote_hosts[1].mac)
- self.p2p_sub_ifs[0].config_ip4()
- self.p2p_sub_ifs[1].config_ip4()
+ self.p2p_sub_ifs.append(
+ self.create_p2p_ethernet(self.pg0, 1,
+ self.pg0._remote_hosts[0].mac))
+ self.p2p_sub_ifs.append(
+ self.create_p2p_ethernet(self.pg0, 2,
+ self.pg0._remote_hosts[1].mac))
self.vapi.cli("trace add p2p-ethernet-input 50")
def tearDown(self):
- self.delete_p2p_ethernet(self.pg0, self.pg0._remote_hosts[0].mac)
- self.delete_p2p_ethernet(self.pg0, self.pg0._remote_hosts[1].mac)
+ while len(self.p2p_sub_ifs):
+ p2p = self.p2p_sub_ifs.pop()
+ self.delete_p2p_ethernet(p2p)
super(P2PEthernetIPV4, self).tearDown()
def create_stream(self, src_mac=None, dst_mac=None,
@@ -401,11 +410,13 @@ class P2PEthernetIPV4(VppTestCase):
p2p = VppP2PSubint(self, parent_if, sub_id, mactobinary(remote_mac))
p2p.admin_up()
p2p.config_ip4()
- self.p2p_sub_ifs.append(p2p)
+ return p2p
- def delete_p2p_ethernet(self, parent_if, remote_mac):
- self.vapi.delete_p2pethernet_subif(parent_if.sw_if_index,
- mactobinary(remote_mac))
+ def delete_p2p_ethernet(self, p2p):
+ p2p.unconfig_ip4()
+ p2p.admin_down()
+ self.vapi.delete_p2pethernet_subif(p2p.parent.sw_if_index,
+ p2p.p2p_remote_mac)
def test_ip4_rx_p2p_subif(self):
"""receive ipv4 packet via p2p subinterface"""
diff --git a/test/vpp_sub_interface.py b/test/vpp_sub_interface.py
index cabee88deb6..38d24041e81 100644
--- a/test/vpp_sub_interface.py
+++ b/test/vpp_sub_interface.py
@@ -196,6 +196,8 @@ class VppP2PSubint(VppSubInterface):
r = test.vapi.create_p2pethernet_subif(parent.sw_if_index,
remote_mac, sub_id)
self._sw_if_index = r.sw_if_index
+ self.parent_sw_if_index = parent.sw_if_index
+ self.p2p_remote_mac = remote_mac
super(VppP2PSubint, self).__init__(test, parent, sub_id)
def add_dot1_layer(self, packet):