diff --git a/netlink/Makefile.am b/netlink/Makefile.am index f760b86..e0fe913 100644 --- a/netlink/Makefile.am +++ b/netlink/Makefile.am @@ -18,7 +18,7 @@ if DEBUG AM_CFLAGS += -O0 -DCLIB_DEBUG vpp_build = vpp_debug-native else -AM_CFLAGS += -O2 +AM_CFLAGS += -O2 -DCLIB_VEC64=0 vpp_build = vpp-native endif diff --git a/netlink/librtnl/mapper.c b/netlink/librtnl/mapper.c index 207013c..ba9f767 100644 --- a/netlink/librtnl/mapper.c +++ b/netlink/librtnl/mapper.c @@ -13,8 +13,8 @@ * limitations under the License. */ -#include -#include +#include "mapper.h" +#include "netns.h" #include #include @@ -42,7 +42,7 @@ static mapper_main_t mapper_main; mapper_map_t *mapper_get_by_ifindex(mapper_ns_t *ns, int ifindex) { mapper_map_t *map; - pool_foreach(map, ns->mappings, { + pool_foreach_old(map, ns->mappings, { if (ifindex == map->linux_ifindex) return map; }); @@ -127,7 +127,7 @@ mapper_delmap(mapper_ns_t*ns, mapper_map_t *map) { ns_route_t *route; netns_t *netns = netns_getns(ns->netns_handle); - pool_foreach(route, netns->routes, { + pool_foreach_old(route, netns->routes, { if (route->oif == map->linux_ifindex) mapper_add_del_route(ns, route, 1); }); @@ -139,7 +139,7 @@ mapper_getmap(mapper_ns_t*ns, u32 sw_if_index, int linux_ifindex, int create) { mapper_map_t *map; - pool_foreach(map, ns->mappings, { + pool_foreach_old(map, ns->mappings, { if (linux_ifindex == map->linux_ifindex) { if (sw_if_index != map->sw_if_index) return NULL; //Cannot have multiple mapping with the same ifindex @@ -160,7 +160,7 @@ mapper_getmap(mapper_ns_t*ns, u32 sw_if_index, //Load available routes ns_route_t *route; netns_t *netns = netns_getns(ns->netns_handle); - pool_foreach(route, netns->routes, { + pool_foreach_old(route, netns->routes, { if (route->oif == map->linux_ifindex) mapper_add_del_route(ns, route, 0); }); @@ -172,7 +172,7 @@ mapper_get_ns(char *nsname) { mapper_main_t *mm = &mapper_main; mapper_ns_t *ns; - pool_foreach(ns, mm->namespaces, { + pool_foreach_old(ns, mm->namespaces, { if (!strcmp(nsname, ns->nsname)) return ns - mm->namespaces; }); @@ -246,7 +246,7 @@ mapper_del_ns(u32 nsindex) //Remove all existing mappings int i, *indexes = 0; - pool_foreach_index(i, ns->mappings, { + pool_foreach_index_old(i, ns->mappings, { vec_add1(indexes, i); }); vec_foreach_index(i, indexes) { diff --git a/netlink/librtnl/mapper.h b/netlink/librtnl/mapper.h index 1811096..5cf1d02 100644 --- a/netlink/librtnl/mapper.h +++ b/netlink/librtnl/mapper.h @@ -16,7 +16,7 @@ #ifndef MAPPER_H_ #define MAPPER_H_ -#include +#include "netns.h" /* * Automatically map linux network routes to VPP. diff --git a/netlink/librtnl/netns.c b/netlink/librtnl/netns.c index 1b40227..23cee31 100644 --- a/netlink/librtnl/netns.c +++ b/netlink/librtnl/netns.c @@ -13,7 +13,7 @@ * limitations under the License. */ -#include +#include "netns.h" #include #include @@ -315,7 +315,7 @@ netns_notify(netns_p *ns, void *obj, netns_type_t type, u32 flags) { netns_main_t *nm = &netns_main; netns_handle_t *h; - pool_foreach(h, nm->handles, { + pool_foreach_old(h, nm->handles, { if (h->netns_index == (ns - nm->netnss) && h->notify) h->notify(obj, type, flags, h->opaque); }); @@ -338,7 +338,7 @@ static ns_link_t * ns_get_link(netns_p *ns, struct ifinfomsg *ifi, struct rtattr *rtas[]) { ns_link_t *link; - pool_foreach(link, ns->netns.links, { + pool_foreach_old(link, ns->netns.links, { if(ifi->ifi_index == link->ifi.ifi_index) return link; }); @@ -404,7 +404,7 @@ ns_get_route(netns_p *ns, struct rtmsg *rtm, struct rtattr *rtas[]) .rtm_type = 0xff }; - pool_foreach(route, ns->netns.routes, { + pool_foreach_old(route, ns->netns.routes, { if(mask_match(&route->rtm, rtm, &msg, sizeof(struct rtmsg)) && rtnl_entry_match(route, rtas, ns_routemap)) return route; @@ -467,7 +467,7 @@ ns_get_addr(netns_p *ns, struct ifaddrmsg *ifaddr, struct rtattr *rtas[]) .ifa_prefixlen = 0xff, }; - pool_foreach(addr, ns->netns.addresses, { + pool_foreach_old(addr, ns->netns.addresses, { if(mask_match(&addr->ifaddr, ifaddr, &msg, sizeof(struct ifaddrmsg)) && rtnl_entry_match(addr, rtas, ns_addrmap)) return addr; @@ -530,7 +530,7 @@ ns_get_neigh(netns_p *ns, struct ndmsg *nd, struct rtattr *rtas[]) .ndm_ifindex = 0xff, }; - pool_foreach(neigh, ns->netns.neighbors, { + pool_foreach_old(neigh, ns->netns.neighbors, { if(mask_match(&neigh->nd, nd, &msg, sizeof(&msg)) && rtnl_entry_match(neigh, rtas, ns_neighmap)) return neigh; @@ -597,7 +597,7 @@ ns_recv_error(rtnl_error_t err, uword o) u32 *i = 0; #define _(pool, type) \ - pool_foreach_index(*i, ns->netns.pool, { \ + pool_foreach_index_old(*i, ns->netns.pool, { \ vec_add1(indexes, *i); \ }) \ vec_foreach(i, indexes) { \ @@ -656,7 +656,7 @@ netns_get(char *name) { netns_main_t *nm = &netns_main; netns_p *ns; - pool_foreach(ns, nm->netnss, { + pool_foreach_old(ns, nm->netnss, { if (!strcmp(name, ns->netns.name)) return ns; }); @@ -733,7 +733,7 @@ void netns_callme(u32 handle, char del) return; #define _(pool, type) \ - pool_foreach_index(i, ns->netns.pool, { \ + pool_foreach_index_old(i, ns->netns.pool, { \ h->notify(&ns->netns.pool[i], type, \ del?NETNS_F_DEL:NETNS_F_ADD, h->opaque); \ }); diff --git a/netlink/librtnl/netns.h b/netlink/librtnl/netns.h index 23f2dc2..d3725c7 100644 --- a/netlink/librtnl/netns.h +++ b/netlink/librtnl/netns.h @@ -23,7 +23,7 @@ #include #include -#include +#include "rtnl.h" /*include it for 'struct mpls_label'*/ #include diff --git a/netlink/librtnl/rtnl.c b/netlink/librtnl/rtnl.c index a849dc6..fc3d335 100644 --- a/netlink/librtnl/rtnl.c +++ b/netlink/librtnl/rtnl.c @@ -16,8 +16,8 @@ #define _GNU_SOURCE #include -#include -#include +#include "rtnl.h" +#include "netns.h" #include #include @@ -266,7 +266,7 @@ static int rtnl_socket_open(rtnl_ns_t *ns) .nl_groups = grpmask(RTNLGRP_LINK)| grpmask(RTNLGRP_IPV6_IFADDR) | grpmask(RTNLGRP_IPV4_IFADDR) | grpmask(RTNLGRP_IPV4_ROUTE) | grpmask(RTNLGRP_IPV6_ROUTE) | grpmask(RTNLGRP_NEIGH) | - grpmask(RTNLGRP_NOTIFY) | grpmask(RTNLGRP_MPLS_ROUTE), + grpmask(RTNLGRP_NOTIFY), }; if (bind(ns->rtnl_socket, (struct sockaddr*) &addr, sizeof(addr))) { @@ -516,7 +516,7 @@ rtnl_process (vlib_main_t * vm, rm->now = vlib_time_now(vm); if (event_type == ~0) { //Clock event or no event - pool_foreach(ns, rm->streams, { + pool_foreach_old(ns, rm->streams, { if (ns->timeout < rm->now) { ns->timeout = DBL_MAX; rtnl_process_timeout(ns); @@ -545,7 +545,7 @@ rtnl_process (vlib_main_t * vm, vec_reset_length (event_data); timeout = DBL_MAX; - pool_foreach(ns, rm->streams, { + pool_foreach_old(ns, rm->streams, { if (ns->timeout < timeout) timeout = ns->timeout; }); diff --git a/router/CMakeLists.txt b/router/CMakeLists.txt new file mode 100644 index 0000000..632ae0a --- /dev/null +++ b/router/CMakeLists.txt @@ -0,0 +1,30 @@ +# Copyright (c) 2018 Cisco and/or its affiliates. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +add_vpp_plugin(router + SOURCES + librtnl/mapper.c + librtnl/netns.c + librtnl/rtnl.c + router/tap_inject.c + router/tap_inject_netlink.c + router/tap_inject_node.c + router/tap_inject_tap.c + + INSTALL_HEADERS + librtnl/mapper.h + librtnl/netns.h + librtnl/rtnl.h + router/tap_inject.h + +) diff --git a/router/Makefile.am b/router/Makefile.am index a4387dd..06606c2 100644 --- a/router/Makefile.am +++ b/router/Makefile.am @@ -1,6 +1,6 @@ AUTOMAKE_OPTIONS = foreign subdir-objects -AM_CFLAGS = -Wall -I@TOOLKIT_INCLUDE@ +AM_CFLAGS = -Wall -I@TOOLKIT_INCLUDE@ -DCLIB_DEBUG -DCLIB_VEC64=0 -I../../vpp/build-root/build-vpp-native/vpp -I../../vpp/src -I../netlink lib_LTLIBRARIES = router.la router_la_SOURCES = \ @@ -13,7 +13,7 @@ nobase_include_HEADERS = \ router/tap_inject.h router_la_LDFLAGS = -module -router_la_LIBADD = -lrtnl +router_la_LIBADD = -L../../vpp/build-root/build-vpp-native/vpp/lib/ -lrtnl if WITH_PLUGIN_TOOLKIT install-data-hook: diff --git a/router/router/tap_inject.c b/router/router/tap_inject.c index 01aecc7..59916b4 100644 --- a/router/router/tap_inject.c +++ b/router/router/tap_inject.c @@ -258,7 +258,7 @@ tap_inject_enable_disable_all_interfaces (int enable) /* Collect all the interface indices. */ interfaces = vnet_main->interface_main.hw_interfaces; indices = enable ? &im->interfaces_to_enable : &im->interfaces_to_disable; - pool_foreach (hw, interfaces, vec_add1 (*indices, hw - interfaces)); + pool_foreach_old (hw, interfaces, vec_add1 (*indices, hw - interfaces)); if (tap_inject_iface_isr (vlib_get_main (), 0, 0)) return clib_error_return (0, "tap-inject interface add del isr failed"); diff --git a/router/router/tap_inject_netlink.c b/router/router/tap_inject_netlink.c index 8b00f05..e845982 100644 --- a/router/router/tap_inject_netlink.c +++ b/router/router/tap_inject_netlink.c @@ -14,12 +14,12 @@ * limitations under the License. */ -#include +#include #include -#include +#include #include #include -#include +#include #include #include #include @@ -95,6 +95,7 @@ add_del_link (ns_link_t * l, int is_del) static void add_del_neigh (ns_neigh_t * n, int is_del) { +#if TBD vnet_main_t * vnet_main = vnet_get_main (); vlib_main_t * vm = vlib_get_main (); u32 sw_if_index; @@ -111,10 +112,9 @@ add_del_neigh (ns_neigh_t * n, int is_del) memset (&a, 0, sizeof (a)); - clib_memcpy (&a.ethernet, n->lladdr, ETHER_ADDR_LEN); + 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, @@ -126,6 +126,7 @@ add_del_neigh (ns_neigh_t * n, int is_del) { vnet_arp_unset_ip4_over_ethernet (vnet_main, sw_if_index, &a); } + } else if (n->nd.ndm_family == AF_INET6) { @@ -140,6 +141,7 @@ add_del_neigh (ns_neigh_t * n, int is_del) vnet_unset_ip6_ethernet_neighbor (vm, sw_if_index, (ip6_address_t *) n->dst); } +#endif } @@ -225,6 +227,7 @@ add_del_route (ns_route_t * r, int is_del) 0 /* weight */, NULL, FIB_ROUTE_PATH_FLAG_NONE); } +#if 0 else if (r->rtm.rtm_family == AF_MPLS) { u32 dst_label; @@ -250,6 +253,7 @@ add_del_route (ns_route_t * r, int is_del) FIB_ENTRY_FLAG_NONE, rpaths); } +#endif } diff --git a/router/router/tap_inject_node.c b/router/router/tap_inject_node.c index 8282c4c..65cb76a 100644 --- a/router/router/tap_inject_node.c +++ b/router/router/tap_inject_node.c @@ -18,6 +18,7 @@ #include #include +#include /* writev */ vlib_node_registration_t tap_inject_rx_node; vlib_node_registration_t tap_inject_tx_node; @@ -178,7 +179,7 @@ VLIB_REGISTER_NODE (tap_inject_neighbor_node) = { #define MTU 1500 -#define MTU_BUFFERS ((MTU + VLIB_BUFFER_DATA_SIZE - 1) / VLIB_BUFFER_DATA_SIZE) +#define MTU_BUFFERS ((MTU + VLIB_BUFFER_DEFAULT_DATA_SIZE - 1) / VLIB_BUFFER_DEFAULT_DATA_SIZE) #define NUM_BUFFERS_TO_ALLOC 32 static inline uword @@ -202,9 +203,15 @@ tap_rx (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * f, int fd) { u32 len = vec_len (im->rx_buffers); - len = vlib_buffer_alloc_from_free_list (vm, - &im->rx_buffers[len], NUM_BUFFERS_TO_ALLOC, - VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX); +#if TBD + len = vlib_buffer_alloc_from_free_list (vm, + &im->rx_buffers[len], NUM_BUFFERS_TO_ALLOC, + VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX); +#else + len = vlib_buffer_alloc_on_numa (vm, + &im->rx_buffers[len], NUM_BUFFERS_TO_ALLOC, + vm->numa_node); +#endif _vec_len (im->rx_buffers) += len; @@ -225,7 +232,7 @@ tap_rx (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * f, int fd) b = vlib_get_buffer (vm, bi[i]); iov[i].iov_base = b->data; - iov[i].iov_len = VLIB_BUFFER_DATA_SIZE; + iov[i].iov_len = VLIB_BUFFER_DEFAULT_DATA_SIZE; } n_bytes = readv (fd, iov, MTU_BUFFERS); @@ -240,7 +247,7 @@ tap_rx (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * f, int fd) vnet_buffer (b)->sw_if_index[VLIB_RX] = sw_if_index; vnet_buffer (b)->sw_if_index[VLIB_TX] = sw_if_index; - n_bytes_left = n_bytes - VLIB_BUFFER_DATA_SIZE; + n_bytes_left = n_bytes - VLIB_BUFFER_DEFAULT_DATA_SIZE; if (n_bytes_left > 0) { @@ -251,10 +258,10 @@ tap_rx (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * f, int fd) b->current_length = n_bytes; /* If necessary, configure any remaining buffers in the chain. */ - for (i = 1; n_bytes_left > 0; ++i, n_bytes_left -= VLIB_BUFFER_DATA_SIZE) + for (i = 1; n_bytes_left > 0; ++i, n_bytes_left -= VLIB_BUFFER_DEFAULT_DATA_SIZE) { b = vlib_get_buffer (vm, bi[i - 1]); - b->current_length = VLIB_BUFFER_DATA_SIZE; + b->current_length = VLIB_BUFFER_DEFAULT_DATA_SIZE; b->flags |= VLIB_BUFFER_NEXT_PRESENT; b->next_buffer = bi[i]; diff --git a/router/router/tap_inject_tap.c b/router/router/tap_inject_tap.c index a3ec9ff..6b4d159 100644 --- a/router/router/tap_inject_tap.c +++ b/router/router/tap_inject_tap.c @@ -119,6 +119,7 @@ tap_inject_tap_connect (vnet_hw_interface_t * hw) /* Get notified when the tap needs to be read. */ template.read_function = tap_inject_tap_read; template.file_descriptor = tap_fd; + template.description = name; clib_file_add (&file_main, &template); diff --git a/vpp_21.06_help b/vpp_21.06_help new file mode 100644 index 0000000..290ac2a --- /dev/null +++ b/vpp_21.06_help @@ -0,0 +1,5 @@ + + + +ln -sf ../netlink/librtnl router/librtnl +ln -sf ../../../vppsb/router vpp/src/plugins/router