6rd: Move to plugin 04/1604/3
authorOle Troan <ot@cisco.com>
Wed, 15 Jun 2016 12:29:08 +0000 (14:29 +0200)
committerOle Troan <ot@cisco.com>
Wed, 15 Jun 2016 14:10:08 +0000 (16:10 +0200)
- Change toplevel plugins make target. Now builds all plugins under
  plugins/. (Apart from sample-plugin).
- Move sixrd code to plugins directory and make necessary changes to
  make it a plugin
- Remove 6rd hooks from IP lookup code

Change-Id: I447e92e3bee240cd8de01d0abac2e1708e8c27d1
Signed-off-by: Ole Troan <ot@cisco.com>
12 files changed:
Makefile
build-data/packages/plugins.mk [new file with mode: 0644]
plugins/Makefile.am [new file with mode: 0644]
plugins/configure.ac [new file with mode: 0644]
plugins/plugins/sixrd/ip4_sixrd.c [moved from vnet/vnet/map/ip4_sixrd.c with 100% similarity]
plugins/plugins/sixrd/ip6_sixrd.c [moved from vnet/vnet/map/ip6_sixrd.c with 100% similarity]
plugins/plugins/sixrd/sixrd.c [moved from vnet/vnet/map/sixrd.c with 87% similarity]
plugins/plugins/sixrd/sixrd.h [moved from vnet/vnet/map/sixrd.h with 98% similarity]
vlib/vlib/unix/plugin.c
vnet/Makefile.am
vnet/vnet/ip/lookup.c
vnet/vnet/ip/lookup.h

index 2d6429c..c3380e7 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -53,7 +53,7 @@ endif
 
 .PHONY: help bootstrap wipe wipe-release build build-release rebuild rebuild-release
 .PHONY: run run-release debug debug-release build-vat run-vat pkg-deb pkg-rpm
-.PHONY: ctags cscope doxygen wipe-doxygen
+.PHONY: ctags cscope doxygen wipe-doxygen plugins plugins-release
 
 help:
        @echo "Make Targets:"
@@ -163,10 +163,10 @@ wipe-release: $(BR)/.bootstrap.ok
 rebuild-release: wipe-release build-release
 
 plugins: $(BR)/.bootstrap.ok
-       $(call make,$(PLATFORM)_debug,sample-plugin-install)
+       $(call make,$(PLATFORM)_debug,plugins-install)
 
 plugins-release: $(BR)/.bootstrap.ok
-       $(call make,$(PLATFORM),sample-plugin-install)
+       $(call make,$(PLATFORM),plugins-install)
 
 STARTUP_DIR ?= $(PWD)
 ifeq ("$(wildcard $(STARTUP_CONF))","")
diff --git a/build-data/packages/plugins.mk b/build-data/packages/plugins.mk
new file mode 100644 (file)
index 0000000..f069862
--- /dev/null
@@ -0,0 +1,38 @@
+plugins_configure_depend =                     \
+    vppinfra-install                           \
+    vlib-api-install                           \
+    vlib-install 
+
+plugins_CPPFLAGS = $(call installed_includes_fn,       \
+    vppinfra                                   \
+    vlib                                       \
+    vlib-api)
+
+plugins_LDFLAGS = $(call installed_libs_fn,    \
+    vppinfra                                   \
+    vlib                                       \
+    vlib-api)
+
+ifeq ($($(PLATFORM)_enable_tests),yes)
+plugins_configure_args += --enable-tests
+endif
+
+# Platform dependent configure flags
+plugins_configure_args += $(plugins_configure_args_$(PLATFORM))
+
+# include & link with openssl only if needed
+ifneq ($($(PLATFORM)_uses_openssl),no)
+plugins_CPPFLAGS += $(call installed_includes_fn, openssl)
+plugins_LDFLAGS += $(call installed_libs_fn, openssl)
+endif
+
+ifneq ($($(PLATFORM)_uses_dpdk),no)
+ifeq ($($(PLATFORM)_uses_external_dpdk),yes)
+plugins_CPPFLAGS += -I$($(PLATFORM)_dpdk_inc_dir)
+plugins_LDFLAGS += -L$($(PLATFORM)_dpdk_lib_dir)
+else
+plugins_configure_depend += dpdk-install
+plugins_CPPFLAGS += $(call installed_includes_fn, dpdk)
+plugins_LDFLAGS += $(call installed_libs_fn, dpdk)
+endif
+endif
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
new file mode 100644 (file)
index 0000000..e72b863
--- /dev/null
@@ -0,0 +1,35 @@
+# Copyright (c) 2016 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.
+
+AUTOMAKE_OPTIONS = foreign subdir-objects
+
+AM_CFLAGS = -Wall -I@TOOLKIT_INCLUDE@
+
+
+########################################
+# SIXRD (RFC5969)
+########################################
+libsixrd_plugin_la_SOURCES = plugins/sixrd/sixrd.c plugins/sixrd/ip4_sixrd.c plugins/sixrd/ip6_sixrd.c
+nobase_include_HEADERS = plugins/sixrd/sixrd.h
+
+libsixrd_plugin_la_LDFLAGS = -module
+BUILT_SOURCES =
+
+lib_LTLIBRARIES = libsixrd_plugin.la
+
+if WITH_PLUGIN_TOOLKIT
+install-data-hook:
+       mkdir /usr/lib/vpp_plugins || true
+       mkdir /usr/lib/vpp_api_test_plugins || true
+       cp $(prefix)/lib/sixrd_plugin.so.*.*.* /usr/lib/vpp_plugins
+endif
diff --git a/plugins/configure.ac b/plugins/configure.ac
new file mode 100644 (file)
index 0000000..bf01aac
--- /dev/null
@@ -0,0 +1,23 @@
+AC_INIT(core_plugins, 1.0)
+LT_INIT
+AM_INIT_AUTOMAKE
+
+AM_PROG_AS
+AC_PROG_CC
+AM_PROG_CC_C_O
+
+AC_ARG_ENABLE(tests,
+              AC_HELP_STRING([--enable-tests], [Build unit tests]),
+              [enable_tests=1],
+              [enable_tests=0])
+
+AC_ARG_WITH(plugin-toolkit,
+            AC_HELP_STRING([--with-plugin-toolkit],
+            [build using the vpp toolkit]),
+            [with_plugin_toolkit=${prefix}/include],
+            [with_plugin_toolkit=.])
+
+AC_SUBST(TOOLKIT_INCLUDE,[${with_plugin_toolkit}])
+AM_CONDITIONAL(WITH_PLUGIN_TOOLKIT, test "$with_plugin_toolkit" != ".")
+AM_CONDITIONAL(ENABLE_TESTS, test "$enable_tests" = "1")
+AC_OUTPUT([Makefile])
similarity index 87%
rename from vnet/vnet/map/sixrd.c
rename to plugins/plugins/sixrd/sixrd.c
index 26b4eea..8ebdb32 100644 (file)
@@ -14,6 +14,7 @@
  */
 
 #include "sixrd.h"
+#include <vnet/plugin/plugin.h>
 
 /*
  * This code supports the following sixrd modes:
@@ -63,7 +64,6 @@ sixrd_create_domain (ip6_address_t *ip6_prefix,
   /* Init IP adjacency */
   memset(&adj, 0, sizeof(adj));
   adj.explicit_fib_index = ~0;
-  adj.lookup_next_index = IP_LOOKUP_NEXT_SIXRD;
   p = (u32 *)&adj.rewrite_data[0];
   *p = (u32) (*sixrd_domain_index);
 
@@ -77,6 +77,7 @@ sixrd_create_domain (ip6_address_t *ip6_prefix,
   args6.adj_index = ~0;
   args6.add_adj = &adj;
   args6.n_add_adj = 1;
+  adj.lookup_next_index = mm->ip6_lookup_next_index;
   ip6_add_del_route(im6, &args6);
 
   /* Multiple SIXRD domains may share same source IPv4 TEP */
@@ -85,7 +86,7 @@ sixrd_create_domain (ip6_address_t *ip6_prefix,
     u32 ai = q[0];
     ip_lookup_main_t *lm4 = &ip4_main.lookup_main;
     ip_adjacency_t *adj4 = ip_get_adjacency(lm4, ai);
-    if (adj4->lookup_next_index != IP_LOOKUP_NEXT_SIXRD) {
+    if (adj4->lookup_next_index != mm->ip4_lookup_next_index) {
       clib_warning("BR source address already assigned: %U", format_ip4_address, ip4_src);
       pool_put(mm->domains, d);
       return -1;
@@ -106,6 +107,7 @@ sixrd_create_domain (ip6_address_t *ip6_prefix,
     args4.adj_index = ~0;
     args4.add_adj = &adj;
     args4.n_add_adj = 1;
+    adj.lookup_next_index = mm->ip4_lookup_next_index;
     ip4_add_del_route(im4, &args4);
   }
 
@@ -135,7 +137,6 @@ sixrd_delete_domain (u32 sixrd_domain_index)
 
   memset(&adj, 0, sizeof(adj));
   adj.explicit_fib_index = ~0;
-  adj.lookup_next_index = IP_LOOKUP_NEXT_SIXRD;
 
   /* Delete ip6 adjacency */
   memset(&args6, 0, sizeof (args6));
@@ -339,17 +340,40 @@ VLIB_CLI_COMMAND(show_sixrd_stats_command, static) = {
   .function = show_sixrd_stats_command_fn,
 };
 
-/*
- * sixrd_init
+/* 
+ * This routine exists to convince the vlib plugin framework that
+ * we haven't accidentally copied a random .dll into the plugin directory.
+ *
+ * Also collects global variable pointers passed from the vpp engine
  */
-clib_error_t *sixrd_init (vlib_main_t *vm)
+clib_error_t * 
+vlib_plugin_register (vlib_main_t * vm, vnet_plugin_handoff_t * h,
+                      int from_early_init)
 {
+  clib_error_t * error = 0;
   sixrd_main_t *mm = &sixrd_main;
 
   mm->vnet_main = vnet_get_main();
   mm->vlib_main = vm;
 
-  return 0;
+  return error;
+}
+
+static clib_error_t * sixrd_init (vlib_main_t * vm)
+{
+  clib_error_t * error = 0;
+  sixrd_main_t *mm = &sixrd_main;
+
+  vlib_node_t * ip6_lookup_node = vlib_get_node_by_name(vm, (u8 *)"ip6-lookup");
+  vlib_node_t * ip4_lookup_node = vlib_get_node_by_name(vm, (u8 *)"ip4-lookup");
+  vlib_node_t * ip6_sixrd_node = vlib_get_node_by_name(vm, (u8 *)"ip6-sixrd");
+  vlib_node_t * ip4_sixrd_node = vlib_get_node_by_name(vm, (u8 *)"ip4-sixrd");
+  ASSERT(ip6_lookup_node && ip4_lookup_node && ip6_sixrd_node && ip4_sixrd_node);
+
+  mm->ip6_lookup_next_index = vlib_node_add_next(vm, ip6_lookup_node->index, ip6_sixrd_node->index);
+  mm->ip4_lookup_next_index = vlib_node_add_next(vm, ip4_lookup_node->index, ip4_sixrd_node->index);
+
+  return error;
 }
 
-VLIB_INIT_FUNCTION(sixrd_init);
+VLIB_INIT_FUNCTION (sixrd_init);
similarity index 98%
rename from vnet/vnet/map/sixrd.h
rename to plugins/plugins/sixrd/sixrd.h
index 388ba4d..1581649 100644 (file)
@@ -44,6 +44,9 @@ typedef struct {
   /* convenience */
   vlib_main_t *vlib_main;
   vnet_main_t *vnet_main;
+
+  u32 ip4_lookup_next_index;
+  u32 ip6_lookup_next_index;
 } sixrd_main_t;
 
 #define foreach_sixrd_error                            \
index 3411ef3..93bfbb7 100644 (file)
@@ -61,11 +61,13 @@ load_one_plugin (plugin_main_t *pm, plugin_info_t *pi, int from_early_init)
   
   pi->handle = handle;
 
+
   register_handle = dlsym (pi->handle, "vlib_plugin_register");
   if (register_handle == 0)
     {
       dlclose (handle);
-      return 0;
+      clib_warning("Plugin missing vlib_plugin_register: %s\n", (char *)pi->name);
+      return 1;
     }
 
   fp = register_handle;
@@ -148,9 +150,12 @@ int vlib_load_new_plugins (plugin_main_t *pm, int from_early_init)
 
           plugin_name = format (0, "%s/%s%c", plugin_path[i],
                                 entry->d_name, 0);
-          
+
+         /* Only accept .so */
+         char * ext = strrchr((const char *)plugin_name, '.');
           /* unreadable */
-          if (stat ((char *)plugin_name, &statb) < 0)
+         if(!ext || (strcmp(ext, ".so") != 0) ||
+            stat ((char *)plugin_name, &statb) < 0)
             {
             ignore:
               vec_free (plugin_name);
index 3d9e07d..b758c7f 100644 (file)
@@ -346,15 +346,11 @@ libvnet_la_SOURCES +=                           \
  vnet/map/map.c                                 \
  vnet/map/ip4_map.c                             \
  vnet/map/ip6_map.c                             \
- vnet/map/sixrd.c                               \
- vnet/map/ip4_sixrd.c                           \
- vnet/map/ip6_sixrd.c                           \
  vnet/map/ip4_map_t.c                           \
  vnet/map/ip6_map_t.c
 
 nobase_include_HEADERS +=                       \
- vnet/map/map.h                                 \
- vnet/map/sixrd.h
+ vnet/map/map.h
 
 ########################################
 # Tunnel protocol: gre
index 5a56870..2d9e01f 100644 (file)
@@ -947,7 +947,6 @@ u8 * format_ip_lookup_next (u8 * s, va_list * args)
     case IP_LOOKUP_NEXT_CLASSIFY: t = "classify"; break;
     case IP_LOOKUP_NEXT_MAP: t = "map"; break;
     case IP_LOOKUP_NEXT_MAP_T: t = "map-t"; break;
-    case IP_LOOKUP_NEXT_SIXRD: t = "sixrd"; break;
     case IP_LOOKUP_NEXT_INDIRECT: t="indirect"; break;
     case IP_LOOKUP_NEXT_REWRITE:
       break;
index a7aef9f..35c19a7 100644 (file)
@@ -76,9 +76,6 @@ typedef enum {
   /* This packet needs to go to MAP with Translation - RFC7599 */
   IP_LOOKUP_NEXT_MAP_T,
 
-  /* This packets needs to go to 6RD (RFC5969) */
-  IP_LOOKUP_NEXT_SIXRD,
-
   /* This packets needs to go to indirect next hop */
   IP_LOOKUP_NEXT_INDIRECT,
 
@@ -109,7 +106,6 @@ typedef enum {
     [IP_LOOKUP_NEXT_CLASSIFY] = "ip4-classify",                        \
     [IP_LOOKUP_NEXT_MAP] = "ip4-map",                          \
     [IP_LOOKUP_NEXT_MAP_T] = "ip4-map-t",                      \
-    [IP_LOOKUP_NEXT_SIXRD] = "ip4-sixrd",                      \
     [IP_LOOKUP_NEXT_INDIRECT] = "ip4-indirect",                        \
     [IP_LOOKUP_NEXT_ICMP_ERROR] = "ip4-icmp-error",            \
 }
@@ -124,7 +120,6 @@ typedef enum {
     [IP_LOOKUP_NEXT_CLASSIFY] = "ip6-classify",                        \
     [IP_LOOKUP_NEXT_MAP] = "ip6-map",                          \
     [IP_LOOKUP_NEXT_MAP_T] = "ip6-map-t",                      \
-    [IP_LOOKUP_NEXT_SIXRD] = "ip6-sixrd",                      \
     [IP_LOOKUP_NEXT_INDIRECT] = "ip6-indirect",                        \
     [IP_LOOKUP_NEXT_ICMP_ERROR] = "ip6-icmp-error",            \
     [IP6_LOOKUP_NEXT_HOP_BY_HOP] = "ip6-hop-by-hop",           \