summaryrefslogtreecommitdiffstats
path: root/extras/router-plugin/rtinject/tap_inject_netlink.c
diff options
context:
space:
mode:
authorLuca Muscariello <lumuscar@cisco.com>2022-03-30 22:29:28 +0200
committerMauro Sardara <msardara@cisco.com>2022-03-31 19:51:47 +0200
commitc46e5df56b67bb8ea7a068d39324c640084ead2b (patch)
treeeddeb17785938e09bc42eec98ee09b8a28846de6 /extras/router-plugin/rtinject/tap_inject_netlink.c
parent18fa668f25d3cc5463417ce7df6637e31578e898 (diff)
feat: boostrap hicn 22.02
The current patch provides several new features, improvements, bug fixes and also complete rewrite of entire components. - lib The hicn packet parser has been improved with a new packet format fully based on UDP. The TCP header is still temporarily supported but the UDP header will replace completely the new hicn packet format. Improvements have been made to make sure every packet parsing operation is made via this library. The current new header can be used as header between the payload and the UDP header or as trailer in the UDP surplus area to be tested when UDP options will start to be used. - hicn-light The portable packet forwarder has been completely rewritten from scratch with the twofold objective to improve performance and code size but also to drop dependencies such as libparc which is now removed by the current implementation. - hicn control the control library is the agent that is used to program the packet forwarders via their binary API. This component has benefited from significant improvements in terms of interaction model which is now event driven and more robust to failures. - VPP plugin has been updated to support VPP 22.02 - transport Major improvement have been made to the RTC protocol, to the support of IO modules and to the security sub system. Signed manifests are the default data authenticity and integrity framework. Confidentiality can be enabled by sharing the encryption key to the prod/cons layer. The library has been tested with group key based applications such as broadcast/multicast and real-time on-line meetings with trusted server keys or MLS. - testing Unit testing has been introduced using GoogleTest. One third of the code base is covered by unit testing with priority on critical features. Functional testing has also been introduce using Docker, linux bridging and Robot Framework to define test with Less Code techniques to facilitate the extension of the coverage. Co-authored-by: Mauro Sardara <msardara@cisco.com> Co-authored-by: Jordan Augé <jordan.auge+fdio@cisco.com> Co-authored-by: Michele Papalini <micpapal@cisco.com> Co-authored-by: Angelo Mantellini <manangel@cisco.com> Co-authored-by: Jacques Samain <jsamain@cisco.com> Co-authored-by: Olivier Roques <oroques+fdio@cisco.com> Co-authored-by: Enrico Loparco <eloparco@cisco.com> Co-authored-by: Giulio Grassi <gigrassi@cisco.com> Change-Id: I75d0ef70f86d921e3ef503c99271216ff583c215 Signed-off-by: Luca Muscariello <muscariello@ieee.org> Signed-off-by: Mauro Sardara <msardara@cisco.com>
Diffstat (limited to 'extras/router-plugin/rtinject/tap_inject_netlink.c')
-rw-r--r--extras/router-plugin/rtinject/tap_inject_netlink.c227
1 files changed, 107 insertions, 120 deletions
diff --git a/extras/router-plugin/rtinject/tap_inject_netlink.c b/extras/router-plugin/rtinject/tap_inject_netlink.c
index a221e8eaa..92ffdc6e5 100644
--- a/extras/router-plugin/rtinject/tap_inject_netlink.c
+++ b/extras/router-plugin/rtinject/tap_inject_netlink.c
@@ -15,25 +15,25 @@
*/
#include "../devices/rtnetlink/netns.h"
+#include <arpa/inet.h>
+#include <linux/mpls.h>
#include <vlibmemory/api.h>
+#include <vnet/ethernet/arp.h>
+#include <vnet/fib/fib.h>
#include <vnet/ip/ip6_neighbor.h>
#include <vnet/ip/lookup.h>
-#include <vnet/fib/fib.h>
-#include <vnet/ethernet/arp.h>
-#include <arpa/inet.h>
-#include <linux/mpls.h>
#include <vnet/mpls/packet.h>
#include "tap_inject.h"
static void
-add_del_addr (ns_addr_t * a, int is_del)
+add_del_addr (ns_addr_t *a, int is_del)
{
- vlib_main_t * vm = vlib_get_main ();
+ vlib_main_t *vm = vlib_get_main ();
u32 sw_if_index;
- sw_if_index = tap_inject_lookup_sw_if_index_from_tap_if_index (
- a->ifaddr.ifa_index);
+ sw_if_index =
+ tap_inject_lookup_sw_if_index_from_tap_if_index (a->ifaddr.ifa_index);
if (sw_if_index == ~0)
return;
@@ -41,37 +41,39 @@ add_del_addr (ns_addr_t * a, int is_del)
if (a->ifaddr.ifa_family == AF_INET)
{
ip4_add_del_interface_address (vm, sw_if_index,
- (ip4_address_t *) a->local, a->ifaddr.ifa_prefixlen, is_del);
+ (ip4_address_t *) a->local,
+ a->ifaddr.ifa_prefixlen, is_del);
}
else if (a->ifaddr.ifa_family == AF_INET6)
{
ip6_add_del_interface_address (vm, sw_if_index,
- (ip6_address_t *) a->addr, a->ifaddr.ifa_prefixlen, is_del);
+ (ip6_address_t *) a->addr,
+ a->ifaddr.ifa_prefixlen, is_del);
}
}
-
-struct set_flags_args {
+struct set_flags_args
+{
u32 index;
u8 flags;
};
static void
-set_flags_cb (struct set_flags_args * a)
+set_flags_cb (struct set_flags_args *a)
{
vnet_sw_interface_set_flags (vnet_get_main (), a->index, a->flags);
}
static void
-add_del_link (ns_link_t * l, int is_del)
+add_del_link (ns_link_t *l, int is_del)
{
struct set_flags_args args = { ~0, 0 };
- vnet_sw_interface_t * sw;
+ vnet_sw_interface_t *sw;
u8 flags = 0;
u32 sw_if_index;
- sw_if_index = tap_inject_lookup_sw_if_index_from_tap_if_index (
- l->ifi.ifi_index);
+ sw_if_index =
+ tap_inject_lookup_sw_if_index_from_tap_if_index (l->ifi.ifi_index);
if (sw_if_index == ~0)
return;
@@ -88,19 +90,18 @@ add_del_link (ns_link_t * l, int is_del)
args.index = sw_if_index;
args.flags = flags;
- vl_api_rpc_call_main_thread (set_flags_cb, (u8 *)&args, sizeof (args));
+ vl_api_rpc_call_main_thread (set_flags_cb, (u8 *) &args, sizeof (args));
}
-
static void
-add_del_neigh (ns_neigh_t * n, int is_del)
+add_del_neigh (ns_neigh_t *n, int is_del)
{
- vnet_main_t * vnet_main = vnet_get_main ();
- vlib_main_t * vm = vlib_get_main ();
+ vnet_main_t *vnet_main = vnet_get_main ();
+ vlib_main_t *vm = vlib_get_main ();
u32 sw_if_index;
- sw_if_index = tap_inject_lookup_sw_if_index_from_tap_if_index (
- n->nd.ndm_ifindex);
+ sw_if_index =
+ tap_inject_lookup_sw_if_index_from_tap_if_index (n->nd.ndm_ifindex);
if (sw_if_index == ~0)
return;
@@ -114,57 +115,54 @@ add_del_neigh (ns_neigh_t * n, int is_del)
clib_memcpy (&a.mac, n->lladdr, ETHER_ADDR_LEN);
clib_memcpy (&a.ip4, n->dst, sizeof (a.ip4));
-
if (n->nd.ndm_state & NUD_REACHABLE)
- {
- vnet_arp_set_ip4_over_ethernet (vnet_main, sw_if_index,
- &a,
- IP_NEIGHBOR_FLAG_NO_FIB_ENTRY);
-
- }
+ {
+ vnet_arp_set_ip4_over_ethernet (vnet_main, sw_if_index, &a,
+ IP_NEIGHBOR_FLAG_NO_FIB_ENTRY);
+ }
else if (n->nd.ndm_state & NUD_FAILED)
- {
- vnet_arp_unset_ip4_over_ethernet (vnet_main, sw_if_index, &a);
- }
+ {
+ vnet_arp_unset_ip4_over_ethernet (vnet_main, sw_if_index, &a);
+ }
}
else if (n->nd.ndm_family == AF_INET6)
{
if (n->nd.ndm_state & NUD_REACHABLE)
- {
-
- mac_address_t * mac1;
- mac1=malloc(sizeof(mac_address_t));
- memcpy (mac1, n->lladdr, ETHER_ADDR_LEN);
- vnet_set_ip6_ethernet_neighbor (vm, sw_if_index,
- (ip6_address_t *) n->dst, (mac_address_t *) mac1,
- IP_NEIGHBOR_FLAG_NONE);
- }
+ {
+
+ mac_address_t *mac1;
+ mac1 = malloc (sizeof (mac_address_t));
+ memcpy (mac1, n->lladdr, ETHER_ADDR_LEN);
+ vnet_set_ip6_ethernet_neighbor (
+ vm, sw_if_index, (ip6_address_t *) n->dst, (mac_address_t *) mac1,
+ IP_NEIGHBOR_FLAG_NONE);
+ }
else
- vnet_unset_ip6_ethernet_neighbor (vm, sw_if_index,
- (ip6_address_t *) n->dst);
+ vnet_unset_ip6_ethernet_neighbor (vm, sw_if_index,
+ (ip6_address_t *) n->dst);
}
}
-
#define TAP_INJECT_HOST_ROUTE_TABLE_MAIN 254
static void
-get_mpls_label_stack(struct mpls_label *addr, u32* l)
+get_mpls_label_stack (struct mpls_label *addr, u32 *l)
{
- u32 entry = ntohl(addr[0].entry);
+ u32 entry = ntohl (addr[0].entry);
u32 label = (entry & MPLS_LS_LABEL_MASK) >> MPLS_LS_LABEL_SHIFT;
- for(int i = 1; label != 0; i++) {
- *l++ = label;
- if(entry & MPLS_LS_S_MASK)
- return;
- entry = ntohl(addr[i].entry);
- label = (entry & MPLS_LS_LABEL_MASK) >> MPLS_LS_LABEL_SHIFT;
- }
+ for (int i = 1; label != 0; i++)
+ {
+ *l++ = label;
+ if (entry & MPLS_LS_S_MASK)
+ return;
+ entry = ntohl (addr[i].entry);
+ label = (entry & MPLS_LS_LABEL_MASK) >> MPLS_LS_LABEL_SHIFT;
+ }
}
static void
-add_del_route (ns_route_t * r, int is_del)
+add_del_route (ns_route_t *r, int is_del)
{
u32 sw_if_index;
@@ -175,101 +173,90 @@ add_del_route (ns_route_t * r, int is_del)
if (r->rtm.rtm_family == AF_INET)
{
- u32 stack[MPLS_STACK_DEPTH] = {0};
+ u32 stack[MPLS_STACK_DEPTH] = { 0 };
fib_prefix_t prefix;
- ip46_address_t nh;
+ ip_address_t nh;
memset (&prefix, 0, sizeof (prefix));
prefix.fp_len = r->rtm.rtm_dst_len;
prefix.fp_proto = FIB_PROTOCOL_IP4;
clib_memcpy (&prefix.fp_addr.ip4, r->dst, sizeof (prefix.fp_addr.ip4));
- get_mpls_label_stack(r->encap, stack);
+ get_mpls_label_stack (r->encap, stack);
memset (&nh, 0, sizeof (nh));
clib_memcpy (&nh.ip4, r->gateway, sizeof (nh.ip4));
- if(*stack == 0)
- fib_table_entry_path_add (0, &prefix, FIB_SOURCE_API,
- FIB_ENTRY_FLAG_NONE, prefix.fp_proto,
- &nh, sw_if_index, 0,
- 0 /* weight */, NULL,
- FIB_ROUTE_PATH_FLAG_NONE);
- else {
- fib_route_path_t *rpaths = NULL, rpath;
- memset(&rpath, 0, sizeof(rpath));
- rpath.frp_weight = 1;
- rpath.frp_proto = DPO_PROTO_IP4;
- clib_memcpy(&rpath.frp_addr.ip4, r->gateway, sizeof(rpath.frp_addr.ip4));
- rpath.frp_sw_if_index = sw_if_index;
- for(int i = 0; i < MPLS_STACK_DEPTH && stack[i] != 0; i++) {
- fib_mpls_label_t fib_label = {stack[i],0,0,0};
- vec_add1(rpath.frp_label_stack, fib_label);
- }
- vec_add1(rpaths, rpath);
- fib_table_entry_path_add2(0,
- &prefix,
- FIB_SOURCE_API,
- FIB_ENTRY_FLAG_NONE,
- rpaths);
- }
+ if (*stack == 0)
+ fib_table_entry_path_add (
+ 0, &prefix, FIB_SOURCE_API, FIB_ENTRY_FLAG_NONE, prefix.fp_proto,
+ &nh, sw_if_index, 0, 0 /* weight */, NULL, FIB_ROUTE_PATH_FLAG_NONE);
+ else
+ {
+ fib_route_path_t *rpaths = NULL, rpath;
+ memset (&rpath, 0, sizeof (rpath));
+ rpath.frp_weight = 1;
+ rpath.frp_proto = DPO_PROTO_IP4;
+ clib_memcpy (&rpath.frp_addr.ip4, r->gateway,
+ sizeof (rpath.frp_addr.ip4));
+ rpath.frp_sw_if_index = sw_if_index;
+ for (int i = 0; i < MPLS_STACK_DEPTH && stack[i] != 0; i++)
+ {
+ fib_mpls_label_t fib_label = { stack[i], 0, 0, 0 };
+ vec_add1 (rpath.frp_label_stack, fib_label);
+ }
+ vec_add1 (rpaths, rpath);
+ fib_table_entry_path_add2 (0, &prefix, FIB_SOURCE_API,
+ FIB_ENTRY_FLAG_NONE, rpaths);
+ }
}
else if (r->rtm.rtm_family == AF_INET6)
{
fib_prefix_t prefix;
- ip46_address_t nh;
+ ip_address_t nh;
memset (&prefix, 0, sizeof (prefix));
prefix.fp_len = r->rtm.rtm_dst_len;
prefix.fp_proto = FIB_PROTOCOL_IP6;
clib_memcpy (&prefix.fp_addr.ip6, r->dst, sizeof (prefix.fp_addr.ip6));
memset (&nh, 0, sizeof (nh));
clib_memcpy (&nh.ip6, r->gateway, sizeof (nh.ip6));
- fib_table_entry_path_add (0, &prefix, FIB_SOURCE_API,
- FIB_ENTRY_FLAG_NONE, prefix.fp_proto,
- &nh, sw_if_index, 0,
- 0 /* weight */, NULL,
- FIB_ROUTE_PATH_FLAG_NONE);
+ fib_table_entry_path_add (
+ 0, &prefix, FIB_SOURCE_API, FIB_ENTRY_FLAG_NONE, prefix.fp_proto, &nh,
+ sw_if_index, 0, 0 /* weight */, NULL, FIB_ROUTE_PATH_FLAG_NONE);
}
-/* else if (r->rtm.rtm_family == AF_MPLS)
- {
- u32 dst_label;
- get_mpls_label_stack((struct mpls_label*) r->dst, &dst_label);
- struct rtvia *via = (struct rtvia*) r->via;
- fib_prefix_t prefix;
- fib_route_path_t *rpaths = NULL, rpath;
- memset (&prefix, 0, sizeof (prefix));
- prefix.fp_len = 21;
- prefix.fp_label = dst_label;
- prefix.fp_proto = FIB_PROTOCOL_MPLS;
- prefix.fp_payload_proto = DPO_PROTO_IP4;
- memset(&rpath, 0, sizeof(rpath));
- clib_memcpy (&rpath.frp_addr.ip4, via->rtvia_addr, sizeof (rpath.frp_addr.ip4));
- rpath.frp_weight = 1;
- rpath.frp_proto = DPO_PROTO_IP4;
- rpath.frp_fib_index = 0;
- rpath.frp_sw_if_index = sw_if_index;
- vec_add1(rpaths, rpath);
- fib_table_entry_path_add2(0,
- &prefix,
- FIB_SOURCE_API,
- FIB_ENTRY_FLAG_NONE,
- rpaths);
- }*/
+ /* else if (r->rtm.rtm_family == AF_MPLS)
+ {
+ u32 dst_label;
+ get_mpls_label_stack((struct mpls_label*) r->dst, &dst_label);
+ struct rtvia *via = (struct rtvia*) r->via;
+ fib_prefix_t prefix;
+ fib_route_path_t *rpaths = NULL, rpath;
+ memset (&prefix, 0, sizeof (prefix));
+ prefix.fp_len = 21;
+ prefix.fp_label = dst_label;
+ prefix.fp_proto = FIB_PROTOCOL_MPLS;
+ prefix.fp_payload_proto = DPO_PROTO_IP4;
+ memset(&rpath, 0, sizeof(rpath));
+ clib_memcpy (&rpath.frp_addr.ip4, via->rtvia_addr, sizeof
+ (rpath.frp_addr.ip4)); rpath.frp_weight = 1; rpath.frp_proto =
+ DPO_PROTO_IP4; rpath.frp_fib_index = 0; rpath.frp_sw_if_index =
+ sw_if_index; vec_add1(rpaths, rpath); fib_table_entry_path_add2(0,
+ &prefix, FIB_SOURCE_API, FIB_ENTRY_FLAG_NONE, rpaths);
+ }*/
}
-
static void
-netns_notify_cb (void * obj, netns_type_t type, u32 flags, uword opaque)
+netns_notify_cb (void *obj, netns_type_t type, u32 flags, uword opaque)
{
if (type == NETNS_TYPE_ADDR)
- add_del_addr ((ns_addr_t *)obj, flags & NETNS_F_DEL);
+ add_del_addr ((ns_addr_t *) obj, flags & NETNS_F_DEL);
else if (type == NETNS_TYPE_LINK)
- add_del_link ((ns_link_t *)obj, flags & NETNS_F_DEL);
+ add_del_link ((ns_link_t *) obj, flags & NETNS_F_DEL);
else if (type == NETNS_TYPE_NEIGH)
- add_del_neigh ((ns_neigh_t *)obj, flags & NETNS_F_DEL);
+ add_del_neigh ((ns_neigh_t *) obj, flags & NETNS_F_DEL);
else if (type == NETNS_TYPE_ROUTE)
- add_del_route ((ns_route_t *)obj, flags & NETNS_F_DEL);
+ add_del_route ((ns_route_t *) obj, flags & NETNS_F_DEL);
}
void