summaryrefslogtreecommitdiffstats
path: root/src/vnet/udp/udp_api.c
diff options
context:
space:
mode:
authorArthur de Kerhor <arthurdekerhor@gmail.com>2021-05-20 11:48:00 +0200
committerFlorin Coras <florin.coras@gmail.com>2021-05-29 18:13:01 +0000
commit8a6f5d394c69eba3bfaddfe36a93d1013cba3ce3 (patch)
tree4adb54d52b2f246fc7d2820fb959e63bbcae7de3 /src/vnet/udp/udp_api.c
parentb740fdc8ff7f58637524e999d5fe01b8b010810d (diff)
udp: add udp decapsulation
Possibility to register a port via CLI or API to decap incoming UDP packets: - For CLI, a user needs to specify the inner protocol (only MPLS supported for now) - For API, the protocol is specified by index Added unittests Type: feature Change-Id: Ifedd86d8db2e355b7618472554fd67d77a13a4aa Signed-off-by: Arthur de Kerhor <arthurdekerhor@gmail.com>
Diffstat (limited to 'src/vnet/udp/udp_api.c')
-rw-r--r--src/vnet/udp/udp_api.c57
1 files changed, 48 insertions, 9 deletions
diff --git a/src/vnet/udp/udp_api.c b/src/vnet/udp/udp_api.c
index 5b9d8945642..6ba92bbf207 100644
--- a/src/vnet/udp/udp_api.c
+++ b/src/vnet/udp/udp_api.c
@@ -16,6 +16,7 @@
#include <vnet/vnet.h>
#include <vlibmemory/api.h>
+#include <vnet/udp/udp_local.h>
#include <vnet/udp/udp_encap.h>
#include <vnet/fib/fib_table.h>
#include <vnet/ip/ip_types_api.h>
@@ -38,11 +39,11 @@
#include <vlibapi/api_helper_macros.h>
-
-#define foreach_udp_api_msg \
-_(UDP_ENCAP_DEL, udp_encap_del) \
-_(UDP_ENCAP_ADD, udp_encap_add) \
-_(UDP_ENCAP_DUMP, udp_encap_dump)
+#define foreach_udp_api_msg \
+ _ (UDP_ENCAP_DEL, udp_encap_del) \
+ _ (UDP_ENCAP_ADD, udp_encap_add) \
+ _ (UDP_ENCAP_DUMP, udp_encap_dump) \
+ _ (UDP_DECAP_ADD_DEL, udp_decap_add_del)
static void
send_udp_encap_details (const udp_encap_t * ue, vl_api_registration_t * reg,
@@ -92,8 +93,7 @@ send_udp_encap_details (const udp_encap_t * ue, vl_api_registration_t * reg,
}
static void
-vl_api_udp_encap_dump_t_handler (vl_api_udp_encap_dump_t * mp,
- vlib_main_t * vm)
+vl_api_udp_encap_dump_t_handler (vl_api_udp_encap_dump_t *mp)
{
vl_api_registration_t *reg;
udp_encap_t *ue;
@@ -111,7 +111,7 @@ vl_api_udp_encap_dump_t_handler (vl_api_udp_encap_dump_t * mp,
}
static void
-vl_api_udp_encap_add_t_handler (vl_api_udp_encap_add_t * mp, vlib_main_t * vm)
+vl_api_udp_encap_add_t_handler (vl_api_udp_encap_add_t *mp)
{
vl_api_udp_encap_add_reply_t *rmp;
ip46_address_t src_ip, dst_ip;
@@ -152,7 +152,7 @@ done:
}
static void
-vl_api_udp_encap_del_t_handler (vl_api_udp_encap_del_t * mp, vlib_main_t * vm)
+vl_api_udp_encap_del_t_handler (vl_api_udp_encap_del_t *mp)
{
vl_api_udp_encap_del_reply_t *rmp;
int rv = 0;
@@ -162,6 +162,45 @@ vl_api_udp_encap_del_t_handler (vl_api_udp_encap_del_t * mp, vlib_main_t * vm)
REPLY_MACRO (VL_API_UDP_ENCAP_DEL_REPLY);
}
+u32
+udp_api_decap_proto_to_index (vlib_main_t *vm,
+ vl_api_udp_decap_next_proto_t iproto)
+{
+ switch (iproto)
+ {
+ case UDP_API_DECAP_PROTO_IP4:
+ return vlib_get_node_by_name (vm, (u8 *) "ip4-input")->index;
+ case UDP_API_DECAP_PROTO_IP6:
+ return vlib_get_node_by_name (vm, (u8 *) "ip6-input")->index;
+ case UDP_API_DECAP_PROTO_MPLS:
+ return vlib_get_node_by_name (vm, (u8 *) "mpls-input")->index;
+ }
+ return ~0;
+}
+
+static void
+vl_api_udp_decap_add_del_t_handler (vl_api_udp_decap_add_del_t *mp)
+{
+ vl_api_udp_decap_add_del_reply_t *rmp;
+ vlib_main_t *vm = vlib_get_main ();
+ int rv = 0;
+
+ if (mp->is_add)
+ {
+ u32 node_index =
+ udp_api_decap_proto_to_index (vm, ntohl (mp->udp_decap.next_proto));
+ if (node_index == ~0)
+ rv = VNET_API_ERROR_INVALID_PROTOCOL;
+ else
+ udp_register_dst_port (vm, ntohs (mp->udp_decap.port), node_index,
+ mp->udp_decap.is_ip4);
+ }
+ else
+ udp_unregister_dst_port (vm, ntohs (mp->udp_decap.port),
+ mp->udp_decap.is_ip4);
+ REPLY_MACRO (VL_API_UDP_DECAP_ADD_DEL_REPLY);
+}
+
#define vl_msg_name_crc_list
#include <vnet/udp/udp.api.h>
#undef vl_msg_name_crc_list