punt and drop features:
[vpp.git] / src / vnet / session / application_interface.c
index 566a52d..7e7449a 100644 (file)
@@ -92,9 +92,7 @@ vnet_bind_i (u32 app_index, session_type_t sst,
       return VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
     }
 
-  listener = stream_session_lookup_listener (&tep->ip,
-                                            clib_host_to_net_u16 (tep->port),
-                                            sst);
+  listener = stream_session_lookup_listener (&tep->ip, tep->port, sst);
   if (listener)
     return VNET_API_ERROR_ADDRESS_IN_USE;
 
@@ -131,9 +129,7 @@ vnet_connect_i (u32 app_index, u32 api_context, session_type_t sst,
   /*
    * Figure out if connecting to a local server
    */
-  listener = stream_session_lookup_listener (&tep->ip,
-                                            clib_host_to_net_u16 (tep->port),
-                                            sst);
+  listener = stream_session_lookup_listener (&tep->ip, tep->port, sst);
   if (listener)
     {
       server = application_get (listener->app_index);
@@ -181,6 +177,7 @@ unformat_vnet_uri (unformat_input_t * input, va_list * args)
                &tep->port))
     {
       *sst = SESSION_TYPE_IP4_TCP;
+      tep->port = clib_host_to_net_u16 (tep->port);
       tep->is_ip4 = 1;
       return 1;
     }
@@ -188,6 +185,7 @@ unformat_vnet_uri (unformat_input_t * input, va_list * args)
                &tep->port))
     {
       *sst = SESSION_TYPE_IP4_UDP;
+      tep->port = clib_host_to_net_u16 (tep->port);
       tep->is_ip4 = 1;
       return 1;
     }
@@ -195,23 +193,36 @@ unformat_vnet_uri (unformat_input_t * input, va_list * args)
                &tep->port))
     {
       *sst = SESSION_TYPE_IP6_UDP;
+      tep->port = clib_host_to_net_u16 (tep->port);
       return 1;
     }
   if (unformat (input, "tcp://%U/%d", unformat_ip6_address, &tep->ip.ip6,
                &tep->port))
     {
       *sst = SESSION_TYPE_IP6_TCP;
+      tep->port = clib_host_to_net_u16 (tep->port);
       return 1;
     }
 
   return 0;
 }
 
+static u8 *cache_uri;
+static session_type_t cache_sst;
+static transport_endpoint_t *cache_tep;
+
 int
 parse_uri (char *uri, session_type_t * sst, transport_endpoint_t * tep)
 {
   unformat_input_t _input, *input = &_input;
 
+  if (cache_uri && !strncmp (uri, (char *) cache_uri, vec_len (cache_uri)))
+    {
+      *sst = cache_sst;
+      *tep = *cache_tep;
+      return 0;
+    }
+
   /* Make sure */
   uri = (char *) format (0, "%s%c", uri, 0);
 
@@ -224,6 +235,14 @@ parse_uri (char *uri, session_type_t * sst, transport_endpoint_t * tep)
     }
   unformat_free (input);
 
+  vec_free (cache_uri);
+  cache_uri = (u8 *) uri;
+  cache_sst = *sst;
+  if (cache_tep)
+    clib_mem_free (cache_tep);
+  cache_tep = clib_mem_alloc (sizeof (*tep));
+  *cache_tep = *tep;
+
   return 0;
 }