linux-cp: add callbacks for pair management
[vpp.git] / src / plugins / linux-cp / lcp_interface.c
index 0dcac48..5c4cd49 100644 (file)
@@ -60,6 +60,17 @@ static uword *lip_db_by_vif;
 index_t *lip_db_by_phy;
 u32 *lip_db_by_host;
 
+/**
+ * vector of virtual function table
+ */
+static lcp_itf_pair_vft_t *lcp_itf_vfts = NULL;
+
+void
+lcp_itf_pair_register_vft (lcp_itf_pair_vft_t *lcp_itf_vft)
+{
+  vec_add1 (lcp_itf_vfts, *lcp_itf_vft);
+}
+
 #define LCP_ITF_PAIR_DBG(...)                                                 \
   vlib_log_notice (lcp_itf_pair_logger, __VA_ARGS__);
 
@@ -216,12 +227,6 @@ lcp_itf_set_adjs (lcp_itf_pair_t *lip)
   lip->lip_rewrite_len = adj->rewrite_header.data_bytes;
 }
 
-int __clib_weak
-lcp_nl_drain_messages (void)
-{
-  return 0;
-}
-
 int
 lcp_itf_pair_add (u32 host_sw_if_index, u32 phy_sw_if_index, u8 *host_name,
                  u32 host_index, lip_host_type_t host_type, u8 *ns)
@@ -240,14 +245,6 @@ lcp_itf_pair_add (u32 host_sw_if_index, u32 phy_sw_if_index, u8 *host_name,
   if (lipi != INDEX_INVALID)
     return VNET_API_ERROR_VALUE_EXIST;
 
-  /*
-   * Drain netlink messages before adding the new pair.
-   * This avoids unnecessarily applying messages that were generated by
-   * the creation of the tap/tun interface. By processing them before we
-   * store the pair data, we will ensure that they are ignored.
-   */
-  lcp_nl_drain_messages ();
-
   /*
    * Create a new pair.
    */
@@ -267,7 +264,6 @@ lcp_itf_pair_add (u32 host_sw_if_index, u32 phy_sw_if_index, u8 *host_name,
   lip->lip_host_type = host_type;
   lip->lip_vif_index = host_index;
   lip->lip_namespace = vec_dup (ns);
-  lip->lip_create_ts = vlib_time_now (vlib_get_main ());
 
   if (lip->lip_host_sw_if_index == ~0)
     return 0;
@@ -323,6 +319,18 @@ lcp_itf_pair_add (u32 host_sw_if_index, u32 phy_sw_if_index, u8 *host_name,
                                   0);
     }
 
+  /* invoke registered callbacks for pair addition */
+  lcp_itf_pair_vft_t *vft;
+
+  vec_foreach (vft, lcp_itf_vfts)
+    {
+      if (vft->pair_add_fn)
+       vft->pair_add_fn (lip);
+    }
+
+  /* set timestamp when pair entered service */
+  lip->lip_create_ts = vlib_time_now (vlib_get_main ());
+
   return 0;
 }
 
@@ -382,6 +390,7 @@ lcp_itf_pair_del (u32 phy_sw_if_index)
   ip_address_family_t af;
   lcp_itf_pair_t *lip;
   u32 lipi;
+  lcp_itf_pair_vft_t *vft;
 
   lipi = lcp_itf_pair_find_by_phy (phy_sw_if_index);
 
@@ -395,6 +404,13 @@ lcp_itf_pair_del (u32 phy_sw_if_index)
                     format_vnet_sw_if_index_name, vnet_get_main (),
                     lip->lip_host_sw_if_index, lip->lip_host_name);
 
+  /* invoke registered callbacks for pair deletion */
+  vec_foreach (vft, lcp_itf_vfts)
+    {
+      if (vft->pair_del_fn)
+       vft->pair_del_fn (lip);
+    }
+
   FOR_EACH_IP_ADDRESS_FAMILY (af)
   ip_feature_enable_disable (af, N_SAFI, IP_FEATURE_INPUT,
                             lcp_itf_l3_feat_names[lip->lip_host_type][af],
@@ -640,7 +656,8 @@ lcp_itf_set_vif_link_state (u32 vif_index, u8 up, u8 *ns)
 
 int
 lcp_itf_pair_create (u32 phy_sw_if_index, u8 *host_if_name,
-                    lip_host_type_t host_if_type, u8 *ns)
+                    lip_host_type_t host_if_type, u8 *ns,
+                    u32 *host_sw_if_indexp)
 {
   vlib_main_t *vm;
   vnet_main_t *vnm;
@@ -823,6 +840,9 @@ lcp_itf_pair_create (u32 phy_sw_if_index, u8 *host_if_name,
                     format_vnet_sw_if_index_name, vnet_get_main (),
                     host_sw_if_index, host_if_name);
 
+  if (host_sw_if_indexp)
+    *host_sw_if_indexp = host_sw_if_index;
+
   return 0;
 }
 
@@ -902,7 +922,7 @@ lcp_itf_pair_process (vlib_main_t *vm, vlib_node_runtime_t *rt,
          lipn = &lipn_names[*lipn_index];
          lcp_itf_pair_create (lipn->lipn_phy_sw_if_index,
                               lipn->lipn_host_name, LCP_ITF_HOST_TAP,
-                              lipn->lipn_namespace);
+                              lipn->lipn_namespace, NULL);
        }
 
       vec_reset_length (event_data);