Link the vpp application against libvnet.so, not libvnet.a 08/408/1
authorDave Barach <dave@barachs.net>
Wed, 24 Feb 2016 16:29:06 +0000 (11:29 -0500)
committerDave Barach <dave@barachs.net>
Wed, 24 Feb 2016 16:30:44 +0000 (11:30 -0500)
Turn of srp, mainly as an example of how to restructure a featurette
for selective disablement.

Change-Id: Id3364c58a8711b103939f4434adfa67177380f67
Signed-off-by: Dave Barach <dave@barachs.net>
vlib/vlib/init.h
vlib/vlib/unix/main.c
vnet/Makefile.am
vnet/vnet/ethernet/arp.c
vnet/vnet/ethernet/ethernet.h
vnet/vnet/ethernet/init.c
vnet/vnet/ethernet/node.c
vnet/vnet/srp/node.c
vnet/vnet/srp/srp.h
vpp/Makefile.am
vpp/vnet/main.c

index 9d940d0..c2a4014 100644 (file)
@@ -169,6 +169,14 @@ static void __vlib_add_config_function_##x (void)               \
     _error;                                                            \
   })
 
+/* Don't call given init function: used to suppress parts of the netstack */
+#define vlib_mark_init_function_complete(vm, x)                                \
+  ({                                                                   \
+    extern vlib_init_function_t * VLIB_INIT_FUNCTION_SYMBOL (x);       \
+    vlib_init_function_t * _f = VLIB_INIT_FUNCTION_SYMBOL (x);         \
+    hash_set1 (vm->init_functions_called, _f);                         \
+  })
+
 #define vlib_call_post_graph_init_function(vm, x)                      \
   ({                                                                   \
     extern vlib_init_function_t * VLIB_POST_GRAPH_INIT_FUNCTION_SYMBOL (x); \
index 6ff63f8..d6976b1 100644 (file)
@@ -431,7 +431,8 @@ int vlib_unix_main (int argc, char * argv[])
     return i;
   
   unformat_init_command_line (&input, (char **)vm->argv);
-  vm->init_functions_called = hash_create (0, /* value bytes */ 0);
+  if (vm->init_functions_called == 0)
+      vm->init_functions_called = hash_create (0, /* value bytes */ 0);
   e = vlib_call_all_config_functions (vm, &input, 1 /* early */);
   if (e != 0)
     {
index f44bb12..fc5a3ec 100644 (file)
@@ -16,7 +16,6 @@ AUTOMAKE_OPTIONS = foreign subdir-objects
 AM_CFLAGS = -Wall @DPDK@ @VIRL@ @IPSEC@ @VCGN@ @IPV6SR@
 
 libvnet_la_SOURCES =
-libvnetplugin_la_SOURCES =
 nobase_include_HEADERS =
 noinst_PROGRAMS =
 
@@ -42,6 +41,7 @@ nobase_include_HEADERS +=                     \
   vnet/interface_funcs.h                       \
   vnet/l3_types.h                              \
   vnet/pipeline.h                              \
+  vnet/plugin/plugin.h                         \
   vnet/replication.h                           \
   vnet/rewrite.h                               \
   vnet/vnet.h
@@ -620,17 +620,7 @@ nobase_include_HEADERS +=                  \
   vnet/unix/tuntap.h                           \
   vnet/unix/tapcli.h
 
-########################################
-# Plugin client library
-########################################
-
-libvnetplugin_la_SOURCES +=                    \
-  vnet/plugin/p1.c
-
-nobase_include_HEADERS +=                      \
-  vnet/plugin/plugin.h
-
-lib_LTLIBRARIES = libvnet.la libvnetplugin.la
+lib_LTLIBRARIES = libvnet.la 
 
 dpdk_libs = 
 
index 3548831..3eb6a11 100644 (file)
@@ -1246,6 +1246,10 @@ static clib_error_t * ethernet_arp_init (vlib_main_t * vm)
 {
   ethernet_arp_main_t * am = &ethernet_arp_main;
   pg_node_t * pn;
+  clib_error_t * error;
+
+  if ((error = vlib_call_init_function (vm, ethernet_init)))
+    return error;
 
   ethernet_register_input_type (vm, ETHERNET_TYPE_ARP, arp_input_node.index);
 
index 266e1d7..04e07b7 100644 (file)
@@ -218,6 +218,9 @@ typedef struct {
   /* Set to one to use AB.CD.EF instead of A:B:C:D:E:F as ethernet format. */
   int format_ethernet_address_16bit;
 
+  /* debug: make sure we don't wipe out an ethernet registration by mistake */
+  u8 next_by_ethertype_register_called;
+
 } ethernet_main_t;
 
 ethernet_main_t ethernet_main;
index 4ac14e2..42788f0 100644 (file)
@@ -66,6 +66,13 @@ static clib_error_t * ethernet_init (vlib_main_t * vm)
   ethernet_main_t * em = &ethernet_main;
   clib_error_t * error;
 
+  /* 
+   * Set up the L2 path now, or we'll wipe out the L2 ARP
+   * registration set up by ethernet_arp_init.
+   */
+  if ((error = vlib_call_init_function(vm, l2_init)))
+    return error;
+
   em->vlib_main = vm;
 
   em->type_info_by_name = hash_create_string (0, sizeof (uword));
index 9c94399..9aed302 100644 (file)
@@ -960,6 +960,16 @@ clib_error_t * next_by_ethertype_init (next_by_ethertype_t * l3_next)
   l3_next->sparse_index_by_input_next_index[ETHERNET_INPUT_NEXT_PUNT]
     = SPARSE_VEC_INVALID_INDEX;
  
+  /* 
+   * Make sure we don't wipe out an ethernet registration by mistake 
+   * Can happen if init function ordering constraints are missing.
+   */
+  if (CLIB_DEBUG > 0)
+    {
+      ethernet_main_t * em = &ethernet_main;
+      ASSERT(em->next_by_ethertype_register_called == 0);
+    }
+
   return 0;
 }
 
@@ -972,6 +982,12 @@ clib_error_t * next_by_ethertype_register (next_by_ethertype_t * l3_next,
   u16 * n;
   ethernet_main_t * em = &ethernet_main;
 
+  if (CLIB_DEBUG > 0)
+    {
+      ethernet_main_t * em = &ethernet_main;
+      em->next_by_ethertype_register_called = 1;
+    }
+
   /* Setup ethernet type -> next index sparse vector mapping. */
   n = sparse_vec_validate (l3_next->input_next_by_type, ethertype);
   n[0] = next_index;
index 42143ef..0b23258 100644 (file)
@@ -269,7 +269,7 @@ static char * srp_error_strings[] = {
 #undef _
 };
 
-VLIB_REGISTER_NODE (srp_input_node,static) = {
+vlib_node_registration_t srp_input_node = {
   .function = srp_input,
   .name = "srp-input",
   /* Takes a vector of packets. */
@@ -444,7 +444,7 @@ srp_control_input (vlib_main_t * vm,
   return from_frame->n_vectors;
 }
 
-VLIB_REGISTER_NODE (srp_control_input_node,static) = {
+static vlib_node_registration_t srp_control_input_node = {
   .function = srp_control_input,
   .name = "srp-control",
   /* Takes a vector of packets. */
@@ -908,7 +908,7 @@ srp_ips_process (vlib_main_t * vm,
   return 0;
 }
 
-VLIB_REGISTER_NODE (srp_ips_process_node) = {
+vlib_node_registration_t srp_ips_process_node = {
     .function = srp_ips_process,
     .type = VLIB_NODE_TYPE_PROCESS,
     .name = "srp-ips-process",
@@ -921,6 +921,9 @@ static clib_error_t * srp_init (vlib_main_t * vm)
 
   sm->default_data_ttl = 255;
   sm->vlib_main = vm;
+  vlib_register_node (vm, &srp_ips_process_node);
+  vlib_register_node (vm, &srp_input_node);
+  vlib_register_node (vm, &srp_control_input_node);
   srp_setup_node (vm, srp_input_node.index);
 
   return 0;
index 1b24171..48c447b 100644 (file)
@@ -150,6 +150,7 @@ void srp_interface_set_hw_wrap_function (u32 hw_if_index, srp_hw_wrap_function_t
 void srp_interface_set_hw_enable_function (u32 hw_if_index, srp_hw_enable_function_t * f);
 
 vlib_node_registration_t srp_ips_process_node;
+vlib_node_registration_t srp_input_node;
 
 /* Called when an IPS control packet is received on given interface. */
 void srp_ips_rx_packet (u32 sw_if_index, srp_ips_header_t * ips_packet);
index 0f2cf83..15f8d12 100644 (file)
@@ -64,12 +64,10 @@ app/version.h:
 
 vpp_LDADD = -lvlibapi -lvlibmemory  -lvlib_unix -lvlib
 
-vpp_LDADD += -l:libvnet.a
+vpp_LDADD += -lvnet
 
 vpp_LDADD += -lsvm -lsvmdb -lrt
 
-vpp_LDADD += -lvnetplugin
-
 if WITH_DPDK
 vpp_LDADD += -l:libdpdk.a
 endif
index bfd5ad5..08e8813 100644 (file)
  *
  */
 
-static clib_error_t *
+static void
 vpe_main_init (vlib_main_t * vm)
 {
-    clib_error_t * error = 0;
-    void vnet_library_plugin_reference(void);
-
     if (CLIB_DEBUG > 0)
         vlib_unix_cli_set_prompt ("DBGvpp# ");
     else
         vlib_unix_cli_set_prompt ("vpp# ");
 
-    vnet_library_plugin_reference();
-
-    if ((error = vlib_call_init_function (vm, pg_init)))
-       return error;
-    if ((error = vlib_call_init_function (vm, ip_main_init)))
-       return error;
-    if ((error = vlib_call_init_function (vm, osi_init)))
-       return error;
-    if ((error = vlib_call_init_function (vm, l2_init)))
-       return error;
-    if ((error = vlib_call_init_function (vm, ethernet_init)))
-       return error;
-    if ((error = vlib_call_init_function (vm, ethernet_arp_init)))
-       return error;
-    if ((error = vlib_call_init_function (vm, map_init)))
-       return error;
-    if ((error = vlib_call_init_function (vm, sixrd_init)))
-       return error;
-    if ((error = vlib_call_init_function (vm, llc_init)))
-       return error;
-    if ((error = vlib_call_init_function (vm, snap_init)))
-       return error;
-    if ((error = vlib_call_init_function (vm, cdp_init)))
-       return error;
-    if ((error = vlib_call_init_function (vm, nsh_gre_init)))
-       return error;
-    if ((error = vlib_call_init_function (vm, nsh_vxlan_gpe_init)))
-       return error;
-    if ((error = vlib_call_init_function (vm, lisp_gpe_init)))
-       return error;
-
-#if DPDK == 1
-    if ((error = vlib_call_init_function (vm, dpdk_init)))
-        return error;
-    if ((error = vlib_call_init_function (vm, dpdk_thread_init)))
-        return error;
-    if ((error = vlib_call_init_function (vm, vhost_user_init)))
-       return error;
-#if IPSEC > 0
-    if ((error = vlib_call_init_function (vm, ipsec_init)))
-        return error;
-#endif /* IPSEC */
-#endif    
-    if ((error = vlib_call_init_function (vm, vlibmemory_init)))
-       return error;
-    if ((error = vlib_call_init_function (vm, l2tp_init)))
-       return error;
-    if ((error = vlib_call_init_function (vm, gre_init)))
-        return error;
-    if ((error = vlib_call_init_function (vm, gre_interface_init)))
-        return error;
-    if ((error = vlib_call_init_function (vm, mpls_init)))
-        return error;
-    if ((error = vlib_call_init_function (vm, mpls_interface_init)))
-        return error;
-    if ((error = vlib_call_init_function (vm, dhcp_proxy_init)))
-        return error;
-    if ((error = vlib_call_init_function (vm, dhcpv6_proxy_init)))
-        return error;
-    if ((error = vlib_call_init_function (vm, tapcli_init)))
-        return error;
-    if ((error = vlib_call_init_function (vm, gdb_func_init)))
-        return error;
-    if ((error = unix_physmem_init
-        (vm, 0 /* fail_if_physical_memory_not_present */)))
-        return error;
-    if ((error = vlib_call_init_function (vm, tuntap_init)))
-       return error;
-#if IPV6SR > 0
-    if ((error = vlib_call_init_function (vm, sr_init)))
-        return error;
-#endif
-    if ((error = vlib_call_init_function (vm, l2_classify_init)))
-        return error;
-    if ((error = vlib_call_init_function (vm, policer_init)))
-        return error;
-    if ((error = vlib_call_init_function (vm, vxlan_init)))
-        return error;
-#if VCGN > 0
-    if ((error = vlib_call_init_function (vm, vcgn_init)))
-        return error;
-#endif
-    if ((error = vlib_call_init_function (vm, li_init)))
-        return error;
-    if ((error = vlib_call_init_function (vm, cop_init)))
-        return error;
-
-    return error;
+    /* Turn off network stack components which we don't want */
+    vlib_mark_init_function_complete (vm, srp_init);
 }
 
-VLIB_INIT_FUNCTION (vpe_main_init);
-
 /* 
  * Load plugins from /usr/lib/vpp_plugins by default
  */
@@ -147,6 +56,7 @@ void *vnet_get_handoff_structure (void)
 int main (int argc, char * argv[])
 {
     int i;
+    vlib_main_t * vm = &vlib_global_main;
     void vl_msg_api_set_first_available_msg_id (u16);
     uword main_heap_size = (1ULL << 30);
     u8 * sizep;
@@ -254,6 +164,8 @@ defaulted:
 
     /* Allocate main heap */
     if (clib_mem_init (0, main_heap_size)) {
+        vm->init_functions_called = hash_create (0, /* value bytes */ 0);
+        vpe_main_init(vm);
         vlib_set_get_handoff_structure_cb (&vnet_get_handoff_structure);
         return vlib_unix_main (argc, argv);
     } else {