aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--extras/vom/vom/ip_punt_redirect_cmds.cpp15
-rw-r--r--src/vnet/ip/ip.api41
-rw-r--r--src/vnet/ip/ip4_punt_drop.c36
-rw-r--r--src/vnet/ip/ip6_punt_drop.c40
-rw-r--r--src/vnet/ip/ip_api.c111
-rw-r--r--src/vnet/ip/ip_punt_drop.h15
-rw-r--r--test/test_ip4.py41
-rw-r--r--test/test_ip6.py54
-rw-r--r--test/vpp_papi_provider.py17
9 files changed, 310 insertions, 60 deletions
diff --git a/extras/vom/vom/ip_punt_redirect_cmds.cpp b/extras/vom/vom/ip_punt_redirect_cmds.cpp
index 8ab6005eddb..eda6929e2d1 100644
--- a/extras/vom/vom/ip_punt_redirect_cmds.cpp
+++ b/extras/vom/vom/ip_punt_redirect_cmds.cpp
@@ -14,6 +14,7 @@
*/
#include "vom/ip_punt_redirect_cmds.hpp"
+#include <vom/api_types.hpp>
namespace VOM {
namespace ip_punt_redirect_cmds {
@@ -44,10 +45,9 @@ config_cmd::issue(connection& con)
auto& payload = req.get_request().get_payload();
payload.is_add = 1;
- payload.rx_sw_if_index = m_rx_itf.value();
- payload.tx_sw_if_index = m_tx_itf.value();
-
- to_bytes(m_addr, &payload.is_ip6, payload.nh);
+ payload.punt.rx_sw_if_index = m_rx_itf.value();
+ payload.punt.tx_sw_if_index = m_tx_itf.value();
+ payload.punt.nh = to_api(m_addr);
VAPI_CALL(req.execute());
@@ -91,10 +91,9 @@ unconfig_cmd::issue(connection& con)
auto& payload = req.get_request().get_payload();
payload.is_add = 0;
- payload.rx_sw_if_index = m_rx_itf.value();
- payload.tx_sw_if_index = m_tx_itf.value();
-
- to_bytes(m_addr, &payload.is_ip6, payload.nh);
+ payload.punt.rx_sw_if_index = m_rx_itf.value();
+ payload.punt.tx_sw_if_index = m_tx_itf.value();
+ payload.punt.nh = to_api(m_addr);
VAPI_CALL(req.execute());
diff --git a/src/vnet/ip/ip.api b/src/vnet/ip/ip.api
index 6ae0e023d5f..ca0088f962f 100644
--- a/src/vnet/ip/ip.api
+++ b/src/vnet/ip/ip.api
@@ -630,26 +630,47 @@ autoreply define ip_punt_police
u8 is_ip6;
};
-/** \brief IP punt redirect
- @param client_index - opaque cookie to identify the sender
- @param context - sender context, to match reply w/ request
- @param is_add - 1 to add neighbor, 0 to delete
- @param is_ipv6 - 1 for IPv6 neighbor, 0 for IPv4
+/** \brief Punt redirect type
@param rx_sw_if_index - specify the original RX interface of traffic
that should be redirected. ~0 means any interface.
@param tx_sw_if_index - the TX interface to which traffic shoulde be
redirected.
- @param nh - The next-hop to redirect the traffic to.
+ @param nh - the next-hop to redirect the traffic to.
+ @param is_ipv6 - 1 for IPv6 neighbor, 0 for IPv4
+*/
+typeonly define punt_redirect
+{
+ u32 rx_sw_if_index;
+ u32 tx_sw_if_index;
+ vl_api_address_t nh;
+};
+
+/** \brief IP punt redirect
+ @param client_index - opaque cookie to identify the sender
+ @param context - sender context, to match reply w/ request
+ @param punt - punt definition
+ @param is_add - 1 to add neighbor, 0 to delete
*/
autoreply define ip_punt_redirect
{
u32 client_index;
u32 context;
- u32 rx_sw_if_index;
- u32 tx_sw_if_index;
+ vl_api_punt_redirect_t punt;
u8 is_add;
- u8 is_ip6;
- u8 nh[16];
+};
+
+define ip_punt_redirect_dump
+{
+ u32 client_index;
+ u32 context;
+ u32 sw_if_index;
+ u8 is_ipv6;
+};
+
+define ip_punt_redirect_details
+{
+ u32 context;
+ vl_api_punt_redirect_t punt;
};
autoreply define ip_container_proxy_add_del
diff --git a/src/vnet/ip/ip4_punt_drop.c b/src/vnet/ip/ip4_punt_drop.c
index cec2c5aed9b..e36980ce9ed 100644
--- a/src/vnet/ip/ip4_punt_drop.c
+++ b/src/vnet/ip/ip4_punt_drop.c
@@ -521,6 +521,42 @@ format_ip_punt_redirect (u8 * s, va_list * args)
return (s);
}
+ip_punt_redirect_detail_t *
+ip4_punt_redirect_entries (u32 sw_if_index)
+{
+ ip_punt_redirect_rx_t *pr;
+ ip_punt_redirect_detail_t *prs = 0;
+ u32 rx_sw_if_index;
+
+ vec_foreach_index (rx_sw_if_index,
+ ip4_punt_redirect_cfg.redirect_by_rx_sw_if_index)
+ {
+ if (sw_if_index == ~0 || sw_if_index == rx_sw_if_index)
+ {
+ pr =
+ &ip4_punt_redirect_cfg.redirect_by_rx_sw_if_index[rx_sw_if_index];
+ if (~0 != pr->tx_sw_if_index)
+ {
+ ip_punt_redirect_detail_t detail = {.rx_sw_if_index =
+ rx_sw_if_index,
+ .punt_redirect = *pr
+ };
+ vec_add1 (prs, detail);
+ }
+ }
+ }
+ if (~0 != ip4_punt_redirect_cfg.any_rx_sw_if_index.tx_sw_if_index)
+ {
+ pr = &ip4_punt_redirect_cfg.any_rx_sw_if_index;
+ ip_punt_redirect_detail_t detail = {.rx_sw_if_index = ~0,
+ .punt_redirect = *pr
+ };
+ vec_add1 (prs, detail);
+ }
+
+ return prs;
+}
+
static clib_error_t *
ip4_punt_redirect_show_cmd (vlib_main_t * vm,
unformat_input_t * main_input,
diff --git a/src/vnet/ip/ip6_punt_drop.c b/src/vnet/ip/ip6_punt_drop.c
index ea8477f81a5..3c839ffdd74 100644
--- a/src/vnet/ip/ip6_punt_drop.c
+++ b/src/vnet/ip/ip6_punt_drop.c
@@ -399,6 +399,46 @@ VLIB_CLI_COMMAND (ip6_punt_redirect_command, static) =
};
/* *INDENT-ON* */
+ip_punt_redirect_detail_t *
+ip6_punt_redirect_entries (u32 sw_if_index)
+{
+ ip_punt_redirect_rx_t *pr;
+ ip_punt_redirect_detail_t *prs = 0;
+ u32 rx_sw_if_index;
+
+ vec_foreach_index (rx_sw_if_index,
+ ip6_punt_redirect_cfg.redirect_by_rx_sw_if_index)
+ {
+ if (sw_if_index == ~0 || sw_if_index == rx_sw_if_index)
+ {
+ pr =
+ &ip6_punt_redirect_cfg.redirect_by_rx_sw_if_index[rx_sw_if_index];
+ if (NULL != pr && ~0 != pr->tx_sw_if_index)
+ {
+ ip_punt_redirect_detail_t detail = {.rx_sw_if_index =
+ rx_sw_if_index,
+ .punt_redirect = *pr
+ };
+ vec_add1 (prs, detail);
+ }
+ }
+ }
+ if (~0 != ip6_punt_redirect_cfg.any_rx_sw_if_index.tx_sw_if_index)
+ {
+ pr = &ip6_punt_redirect_cfg.any_rx_sw_if_index;
+ if (NULL != pr)
+ {
+ ip_punt_redirect_detail_t detail = {.rx_sw_if_index =
+ rx_sw_if_index,
+ .punt_redirect = *pr
+ };
+ vec_add1 (prs, detail);
+ }
+ }
+
+ return prs;
+}
+
static clib_error_t *
ip6_punt_redirect_show_cmd (vlib_main_t * vm,
unformat_input_t * main_input,
diff --git a/src/vnet/ip/ip_api.c b/src/vnet/ip/ip_api.c
index 1a31b5abf73..2f476a330ee 100644
--- a/src/vnet/ip/ip_api.c
+++ b/src/vnet/ip/ip_api.c
@@ -26,6 +26,7 @@
#include <vnet/ip/ip.h>
#include <vnet/ip/ip_neighbor.h>
#include <vnet/ip/ip6_neighbor.h>
+#include <vnet/ip/ip_punt_drop.h>
#include <vnet/fib/fib_table.h>
#include <vnet/fib/fib_api.h>
#include <vnet/dpo/drop_dpo.h>
@@ -110,7 +111,9 @@ _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \
ip_source_and_port_range_check_interface_add_del) \
_(IP_REASSEMBLY_SET, ip_reassembly_set) \
_(IP_REASSEMBLY_GET, ip_reassembly_get) \
-_(IP_REASSEMBLY_ENABLE_DISABLE, ip_reassembly_enable_disable)
+_(IP_REASSEMBLY_ENABLE_DISABLE, ip_reassembly_enable_disable) \
+_(IP_PUNT_REDIRECT_DUMP, ip_punt_redirect_dump)
+
extern void stats_dslock_with_hint (int hint, int tag);
extern void stats_dsunlock (void);
@@ -615,40 +618,40 @@ vl_api_ip_punt_redirect_t_handler (vl_api_ip_punt_redirect_t * mp,
{
vl_api_ip_punt_redirect_reply_t *rmp;
int rv = 0;
+ ip46_type_t ipv;
+ ip46_address_t nh;
+ if (!vnet_sw_if_index_is_api_valid (ntohl (mp->punt.tx_sw_if_index)))
+ goto bad_sw_if_index;
+
+ ipv = ip_address_decode (&mp->punt.nh, &nh);
if (mp->is_add)
{
- ip46_address_t nh;
-
- clib_memset (&nh, 0, sizeof (nh));
-
- if (mp->is_ip6)
+ if (ipv == IP46_TYPE_IP6)
{
- memcpy (&nh.ip6, mp->nh, sizeof (nh.ip6));
-
- ip6_punt_redirect_add (ntohl (mp->rx_sw_if_index),
- ntohl (mp->tx_sw_if_index), &nh);
+ ip6_punt_redirect_add (ntohl (mp->punt.rx_sw_if_index),
+ ntohl (mp->punt.tx_sw_if_index), &nh);
}
- else
+ else if (ipv == IP46_TYPE_IP4)
{
- memcpy (&nh.ip4, mp->nh, sizeof (nh.ip4));
-
- ip4_punt_redirect_add (ntohl (mp->rx_sw_if_index),
- ntohl (mp->tx_sw_if_index), &nh);
+ ip4_punt_redirect_add (ntohl (mp->punt.rx_sw_if_index),
+ ntohl (mp->punt.tx_sw_if_index), &nh);
}
}
else
{
- if (mp->is_ip6)
+ if (ipv == IP46_TYPE_IP6)
{
- ip6_punt_redirect_del (ntohl (mp->rx_sw_if_index));
+ ip6_punt_redirect_del (ntohl (mp->punt.rx_sw_if_index));
}
- else
+ else if (ipv == IP46_TYPE_IP4)
{
- ip4_punt_redirect_del (ntohl (mp->rx_sw_if_index));
+ ip4_punt_redirect_del (ntohl (mp->punt.rx_sw_if_index));
}
}
+ BAD_SW_IF_INDEX_LABEL;
+
REPLY_MACRO (VL_API_IP_PUNT_REDIRECT_REPLY);
}
@@ -3309,6 +3312,76 @@ void
REPLY_MACRO (VL_API_IP_REASSEMBLY_SET_REPLY);
}
+void
+send_ip_punt_redirect_details (vl_api_registration_t * reg,
+ u32 context, u32 sw_if_index,
+ ip_punt_redirect_rx_t * pr, u8 is_ipv6)
+{
+ vl_api_ip_punt_redirect_details_t *mp;
+
+ mp = vl_msg_api_alloc (sizeof (*mp));
+ if (!mp)
+ return;
+
+ clib_memset (mp, 0, sizeof (*mp));
+ mp->_vl_msg_id = ntohs (VL_API_IP_PUNT_REDIRECT_DETAILS);
+ mp->context = context;
+ mp->punt.rx_sw_if_index = htonl (sw_if_index);
+ mp->punt.tx_sw_if_index = htonl (pr->tx_sw_if_index);
+ if (is_ipv6)
+ {
+ ip_address_encode (&pr->nh, IP46_TYPE_IP6, &mp->punt.nh);
+ }
+ else
+ {
+ ip_address_encode (&pr->nh, IP46_TYPE_IP4, &mp->punt.nh);
+ }
+
+ vl_api_send_msg (reg, (u8 *) mp);
+}
+
+static void
+vl_api_ip_punt_redirect_dump_t_handler (vl_api_ip_punt_redirect_dump_t * mp)
+{
+ vl_api_registration_t *reg;
+ u32 sw_if_index;
+ int rv __attribute__ ((unused)) = 0;
+
+ sw_if_index = ntohl (mp->sw_if_index);
+ reg = vl_api_client_index_to_registration (mp->client_index);
+ if (!reg)
+ return;
+
+ if (~0 != sw_if_index)
+ VALIDATE_SW_IF_INDEX (mp);
+
+ ip_punt_redirect_detail_t *pr, *prs;
+ if (mp->is_ipv6)
+ {
+ prs = ip6_punt_redirect_entries (sw_if_index);
+ /* *INDENT-OFF* */
+ vec_foreach (pr, prs)
+ {
+ send_ip_punt_redirect_details (reg, mp->context, pr->rx_sw_if_index, &pr->punt_redirect, 1);
+ }
+ /* *INDENT-ON* */
+ vec_free (prs);
+ }
+ else
+ {
+ prs = ip4_punt_redirect_entries (sw_if_index);
+ /* *INDENT-OFF* */
+ vec_foreach (pr, prs)
+ {
+ send_ip_punt_redirect_details (reg, mp->context, pr->rx_sw_if_index, &pr->punt_redirect, 0);
+ }
+ /* *INDENT-ON* */
+ vec_free (prs);
+ }
+
+ BAD_SW_IF_INDEX_LABEL;
+}
+
#define vl_msg_name_crc_list
#include <vnet/ip/ip.api.h>
#undef vl_msg_name_crc_list
diff --git a/src/vnet/ip/ip_punt_drop.h b/src/vnet/ip/ip_punt_drop.h
index 7ba65e1a6e4..ccf88e593cf 100644
--- a/src/vnet/ip/ip_punt_drop.h
+++ b/src/vnet/ip/ip_punt_drop.h
@@ -245,6 +245,18 @@ typedef struct ip4_punt_redirect_trace_t_
u32 next;
} ip_punt_redirect_trace_t;
+typedef struct ip_punt_redirect_detail_t_
+{
+ /**
+ * the RX interface
+ */
+ u32 rx_sw_if_index;
+ /**
+ * IP punt redirect configuration
+ */
+ ip_punt_redirect_rx_t punt_redirect;
+} ip_punt_redirect_detail_t;
+
/**
* Add a punt redirect entry
*/
@@ -258,6 +270,9 @@ extern u8 *format_ip_punt_redirect (u8 * s, va_list * args);
extern u8 *format_ip_punt_redirect_trace (u8 * s, va_list * args);
+extern ip_punt_redirect_detail_t *ip4_punt_redirect_entries (u32 sw_if_index);
+extern ip_punt_redirect_detail_t *ip6_punt_redirect_entries (u32 sw_if_index);
+
always_inline u32
ip_punt_redirect_tx_via_adj (vlib_buffer_t * b0, adj_index_t ai)
{
diff --git a/test/test_ip4.py b/test/test_ip4.py
index 9f2c925ec4d..9ec7f4e8129 100644
--- a/test/test_ip4.py
+++ b/test/test_ip4.py
@@ -8,7 +8,7 @@ from framework import VppTestCase, VppTestRunner
from vpp_sub_interface import VppSubInterface, VppDot1QSubint, VppDot1ADSubint
from vpp_ip_route import VppIpRoute, VppRoutePath, VppIpMRoute, \
VppMRoutePath, MRouteItfFlags, MRouteEntryFlags, VppMplsIpBind, \
- VppMplsTable, VppIpTable
+ VppMplsTable, VppIpTable, VppIpAddress
from scapy.packet import Raw
from scapy.layers.l2 import Ether, Dot1Q, ARP
@@ -1094,7 +1094,7 @@ class TestIPPunt(VppTestCase):
def setUp(self):
super(TestIPPunt, self).setUp()
- self.create_pg_interfaces(range(2))
+ self.create_pg_interfaces(range(4))
for i in self.pg_interfaces:
i.admin_up()
@@ -1121,8 +1121,7 @@ class TestIPPunt(VppTestCase):
#
# Configure a punt redirect via pg1.
#
- nh_addr = socket.inet_pton(socket.AF_INET,
- self.pg1.remote_ip4)
+ nh_addr = VppIpAddress(self.pg1.remote_ip4).encode()
self.vapi.ip_punt_redirect(self.pg0.sw_if_index,
self.pg1.sw_if_index,
nh_addr)
@@ -1180,6 +1179,40 @@ class TestIPPunt(VppTestCase):
nh_addr,
is_add=0)
+ def test_ip_punt_dump(self):
+ """ IP4 punt redirect dump"""
+
+ #
+ # Configure a punt redirects
+ #
+ nh_address = VppIpAddress(self.pg3.remote_ip4).encode()
+ self.vapi.ip_punt_redirect(self.pg0.sw_if_index,
+ self.pg3.sw_if_index,
+ nh_address)
+ self.vapi.ip_punt_redirect(self.pg1.sw_if_index,
+ self.pg3.sw_if_index,
+ nh_address)
+ self.vapi.ip_punt_redirect(self.pg2.sw_if_index,
+ self.pg3.sw_if_index,
+ VppIpAddress('0.0.0.0').encode())
+
+ #
+ # Dump pg0 punt redirects
+ #
+ punts = self.vapi.ip_punt_redirect_dump(self.pg0.sw_if_index)
+ for p in punts:
+ self.assertEqual(p.punt.rx_sw_if_index, self.pg0.sw_if_index)
+
+ #
+ # Dump punt redirects for all interfaces
+ #
+ punts = self.vapi.ip_punt_redirect_dump(0xffffffff)
+ self.assertEqual(len(punts), 3)
+ for p in punts:
+ self.assertEqual(p.punt.tx_sw_if_index, self.pg3.sw_if_index)
+ self.assertNotEqual(punts[1].punt.nh.un.ip4, self.pg3.remote_ip4)
+ self.assertEqual(punts[2].punt.nh.un.ip4.address, '\x00'*4)
+
class TestIPDeag(VppTestCase):
""" IPv4 Deaggregate Routes """
diff --git a/test/test_ip6.py b/test/test_ip6.py
index 33194ebc5b2..1d7fa766d14 100644
--- a/test/test_ip6.py
+++ b/test/test_ip6.py
@@ -10,7 +10,7 @@ from vpp_pg_interface import is_ipv6_misc
from vpp_ip import DpoProto
from vpp_ip_route import VppIpRoute, VppRoutePath, find_route, VppIpMRoute, \
VppMRoutePath, MRouteItfFlags, MRouteEntryFlags, VppMplsIpBind, \
- VppMplsRoute, VppMplsTable, VppIpTable
+ VppMplsRoute, VppMplsTable, VppIpTable, VppIpAddress
from vpp_neighbor import find_nbr, VppNeighbor
from scapy.packet import Raw
@@ -1867,7 +1867,7 @@ class TestIP6Punt(VppTestCase):
def setUp(self):
super(TestIP6Punt, self).setUp()
- self.create_pg_interfaces(range(2))
+ self.create_pg_interfaces(range(4))
for i in self.pg_interfaces:
i.admin_up()
@@ -1894,12 +1894,10 @@ class TestIP6Punt(VppTestCase):
#
# Configure a punt redirect via pg1.
#
- nh_addr = inet_pton(AF_INET6,
- self.pg1.remote_ip6)
+ nh_addr = VppIpAddress(self.pg1.remote_ip6).encode()
self.vapi.ip_punt_redirect(self.pg0.sw_if_index,
self.pg1.sw_if_index,
- nh_addr,
- is_ip6=1)
+ nh_addr)
self.send_and_expect(self.pg0, pkts, self.pg1)
@@ -1937,8 +1935,7 @@ class TestIP6Punt(VppTestCase):
self.vapi.ip_punt_redirect(self.pg0.sw_if_index,
self.pg1.sw_if_index,
nh_addr,
- is_add=0,
- is_ip6=1)
+ is_add=0)
self.send_and_assert_no_replies(self.pg0, pkts,
"IP no punt config")
@@ -1947,15 +1944,48 @@ class TestIP6Punt(VppTestCase):
#
self.vapi.ip_punt_redirect(0xffffffff,
self.pg1.sw_if_index,
- nh_addr,
- is_ip6=1)
+ nh_addr)
self.send_and_expect(self.pg0, pkts, self.pg1)
self.vapi.ip_punt_redirect(0xffffffff,
self.pg1.sw_if_index,
nh_addr,
- is_add=0,
- is_ip6=1)
+ is_add=0)
+
+ def test_ip_punt_dump(self):
+ """ IP6 punt redirect dump"""
+
+ #
+ # Configure a punt redirects
+ #
+ nh_addr = VppIpAddress(self.pg3.remote_ip6).encode()
+ self.vapi.ip_punt_redirect(self.pg0.sw_if_index,
+ self.pg3.sw_if_index,
+ nh_addr)
+ self.vapi.ip_punt_redirect(self.pg1.sw_if_index,
+ self.pg3.sw_if_index,
+ nh_addr)
+ self.vapi.ip_punt_redirect(self.pg2.sw_if_index,
+ self.pg3.sw_if_index,
+ VppIpAddress('0::0').encode())
+
+ #
+ # Dump pg0 punt redirects
+ #
+ punts = self.vapi.ip_punt_redirect_dump(self.pg0.sw_if_index,
+ is_ipv6=1)
+ for p in punts:
+ self.assertEqual(p.punt.rx_sw_if_index, self.pg0.sw_if_index)
+
+ #
+ # Dump punt redirects for all interfaces
+ #
+ punts = self.vapi.ip_punt_redirect_dump(0xffffffff, is_ipv6=1)
+ self.assertEqual(len(punts), 3)
+ for p in punts:
+ self.assertEqual(p.punt.tx_sw_if_index, self.pg3.sw_if_index)
+ self.assertNotEqual(punts[1].punt.nh.un.ip6, self.pg3.remote_ip6)
+ self.assertEqual(punts[2].punt.nh.un.ip6.address, '\x00'*16)
class TestIPDeag(VppTestCase):
diff --git a/test/vpp_papi_provider.py b/test/vpp_papi_provider.py
index 966d9198fa0..662732ffb30 100644
--- a/test/vpp_papi_provider.py
+++ b/test/vpp_papi_provider.py
@@ -3168,15 +3168,18 @@ class VppPapiProvider(object):
def ip_punt_redirect(self,
rx_sw_if_index,
tx_sw_if_index,
- nh,
- is_ip6=0,
+ address,
is_add=1):
return self.api(self.papi.ip_punt_redirect,
- {'rx_sw_if_index': rx_sw_if_index,
- 'tx_sw_if_index': tx_sw_if_index,
- 'nh': nh,
- 'is_add': is_add,
- 'is_ip6': is_ip6})
+ {'punt': {'rx_sw_if_index': rx_sw_if_index,
+ 'tx_sw_if_index': tx_sw_if_index,
+ 'nh': address},
+ 'is_add': is_add})
+
+ def ip_punt_redirect_dump(self, sw_if_index, is_ipv6=0):
+ return self.api(self.papi.ip_punt_redirect_dump,
+ {'sw_if_index': sw_if_index,
+ 'is_ipv6': is_ipv6})
def bier_table_add_del(self,
bti,