VCL: application proxy configuration
[vpp.git] / src / vcl / vppcom.c
index 0f30c60..9501b7e 100644 (file)
@@ -109,7 +109,8 @@ typedef struct
   u32 vrf;
   vppcom_ip46_t lcl_addr;
   vppcom_ip46_t peer_addr;
-  u16 port;
+  u16 lcl_port;                        // network order
+  u16 peer_port;               // network order
   u8 proto;
   u64 client_queue_address;
   u64 options[16];
@@ -126,6 +127,12 @@ typedef struct vppcom_cfg_t_
   u32 tx_fifo_size;
   u32 event_queue_size;
   u32 listen_queue_size;
+  u8 app_proxy_transport_tcp;
+  u8 app_proxy_transport_udp;
+  u8 app_scope_local;
+  u8 app_scope_global;
+  u8 *namespace_id;
+  u64 namespace_secret;
   f64 app_timeout;
   f64 session_timeout;
   f64 accept_timeout;
@@ -454,6 +461,10 @@ vppcom_app_send_attach (void)
 {
   vppcom_main_t *vcm = &vppcom_main;
   vl_api_application_attach_t *bmp;
+  u8 nsid_len = vec_len (vcm->cfg.namespace_id);
+  u8 app_is_proxy = (vcm->cfg.app_proxy_transport_tcp ||
+                    vcm->cfg.app_proxy_transport_udp);
+
   bmp = vl_msg_api_alloc (sizeof (*bmp));
   memset (bmp, 0, sizeof (*bmp));
 
@@ -462,11 +473,22 @@ vppcom_app_send_attach (void)
   bmp->context = htonl (0xfeedface);
   bmp->options[APP_OPTIONS_FLAGS] =
     APP_OPTIONS_FLAGS_ACCEPT_REDIRECT | APP_OPTIONS_FLAGS_ADD_SEGMENT |
-    APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE | APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
+    (vcm->cfg.app_scope_local ? APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE : 0) |
+    (vcm->cfg.app_scope_global ? APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE : 0) |
+    (app_is_proxy ? APP_OPTIONS_FLAGS_IS_PROXY : 0);
+  bmp->options[APP_OPTIONS_PROXY_TRANSPORT] =
+    (vcm->cfg.app_proxy_transport_tcp ? 1 << TRANSPORT_PROTO_TCP : 0) |
+    (vcm->cfg.app_proxy_transport_udp ? 1 << TRANSPORT_PROTO_UDP : 0);
   bmp->options[SESSION_OPTIONS_SEGMENT_SIZE] = vcm->cfg.segment_size;
   bmp->options[SESSION_OPTIONS_ADD_SEGMENT_SIZE] = vcm->cfg.add_segment_size;
   bmp->options[SESSION_OPTIONS_RX_FIFO_SIZE] = vcm->cfg.rx_fifo_size;
   bmp->options[SESSION_OPTIONS_TX_FIFO_SIZE] = vcm->cfg.tx_fifo_size;
+  if (nsid_len)
+    {
+      bmp->namespace_id_len = nsid_len;
+      clib_memcpy (bmp->namespace_id, vcm->cfg.namespace_id, nsid_len);
+      bmp->options[APP_OPTIONS_NAMESPACE_SECRET] = vcm->cfg.namespace_secret;
+    }
   vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & bmp);
 }
 
@@ -806,39 +828,25 @@ vppcom_send_connect_sock (session_t * session, u32 session_index)
   cmp->vrf = session->vrf;
   cmp->is_ip4 = session->peer_addr.is_ip4;
   clib_memcpy (cmp->ip, &session->peer_addr.ip46, sizeof (cmp->ip));
-  cmp->port = session->port;
+  cmp->port = session->peer_port;
   cmp->proto = session->proto;
   clib_memcpy (cmp->options, session->options, sizeof (cmp->options));
   vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & cmp);
 }
 
-static int
-vppcom_send_disconnect (u32 session_index)
+static inline void
+vppcom_send_disconnect (session_t * session)
 {
   vppcom_main_t *vcm = &vppcom_main;
   vl_api_disconnect_session_t *dmp;
-  session_t *session = 0;
-  int rv;
-
-  clib_spinlock_lock (&vcm->sessions_lockp);
-  rv = vppcom_session_at_index (session_index, &session);
-  if (PREDICT_FALSE (rv))
-    {
-      clib_spinlock_unlock (&vcm->sessions_lockp);
-      if (VPPCOM_DEBUG > 1)
-       clib_warning ("[%d] invalid session, sid (%u) has been closed!",
-                     vcm->my_pid, session_index);
-      return rv;
-    }
 
+  /* Assumes caller as acquired the spinlock: vcm->sessions_lockp */
   dmp = vl_msg_api_alloc (sizeof (*dmp));
   memset (dmp, 0, sizeof (*dmp));
   dmp->_vl_msg_id = ntohs (VL_API_DISCONNECT_SESSION);
   dmp->client_index = vcm->my_client_index;
   dmp->handle = session->vpp_session_handle;
-  clib_spinlock_unlock (&vcm->sessions_lockp);
   vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & dmp);
-  return VPPCOM_OK;
 }
 
 static void
@@ -1014,7 +1022,7 @@ vl_api_accept_session_t_handler (vl_api_accept_session_t * mp)
   session->state = STATE_ACCEPT;
   session->is_cut_thru = 0;
   session->is_server = 1;
-  session->port = mp->port;
+  session->peer_port = mp->port;
   session->peer_addr.is_ip4 = mp->is_ip4;
   clib_memcpy (&session->peer_addr.ip46, mp->ip,
               sizeof (session->peer_addr.ip46));
@@ -1132,7 +1140,7 @@ vl_api_connect_sock_t_handler (vl_api_connect_sock_t * mp)
   session->client_queue_address = mp->client_queue_address;
   session->is_cut_thru = 1;
   session->is_server = 1;
-  session->port = mp->port;
+  session->peer_port = mp->port;
   session->peer_addr.is_ip4 = mp->is_ip4;
   clib_memcpy (&session->peer_addr.ip46, mp->ip,
               sizeof (session->peer_addr.ip46));
@@ -1198,7 +1206,7 @@ vppcom_send_bind_sock (session_t * session)
   bmp->vrf = session->vrf;
   bmp->is_ip4 = session->lcl_addr.is_ip4;
   clib_memcpy (bmp->ip, &session->lcl_addr.ip46, sizeof (bmp->ip));
-  bmp->port = session->port;
+  bmp->port = session->lcl_port;
   bmp->proto = session->proto;
   clib_memcpy (bmp->options, session->options, sizeof (bmp->options));
   vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & bmp);
@@ -1282,25 +1290,38 @@ vppcom_session_unbind (u32 session_index)
   return VPPCOM_OK;
 }
 
-static int
+static inline int
 vppcom_session_disconnect (u32 session_index)
 {
   vppcom_main_t *vcm = &vppcom_main;
   int rv;
+  session_t *session;
 
-  rv = vppcom_send_disconnect (session_index);
-  if (PREDICT_FALSE (rv))
-    return rv;
-
-  rv = vppcom_wait_for_session_state_change (session_index, STATE_DISCONNECT,
-                                            vcm->cfg.session_timeout);
+  clib_spinlock_lock (&vcm->sessions_lockp);
+  rv = vppcom_session_at_index (session_index, &session);
   if (PREDICT_FALSE (rv))
     {
-      if (VPPCOM_DEBUG > 0)
-       clib_warning ("[%d] client disconnect timed out, rv = %s (%d)",
-                     vcm->my_pid, vppcom_retval_str (rv), rv);
+      clib_spinlock_unlock (&vcm->sessions_lockp);
+      if (VPPCOM_DEBUG > 1)
+       clib_warning ("[%d] invalid session, sid (%u) has been closed!",
+                     vcm->my_pid, session_index);
       return rv;
     }
+
+  if (!session->is_cut_thru)
+    {
+      vppcom_send_disconnect (session);
+      clib_spinlock_unlock (&vcm->sessions_lockp);
+
+      rv = vppcom_wait_for_session_state_change (session_index,
+                                                STATE_DISCONNECT, 1.0);
+      if ((VPPCOM_DEBUG > 0) && (rv < 0))
+       clib_warning ("[%d] disconnect (session %d) failed, rv = %s (%d)",
+                     vcm->my_pid, session_index, vppcom_retval_str (rv), rv);
+    }
+  else
+    clib_spinlock_unlock (&vcm->sessions_lockp);
+
   return VPPCOM_OK;
 }
 
@@ -1508,7 +1529,7 @@ vppcom_cfg_read (char *conf_fname)
       (void) unformat_user (input, unformat_line_input, line_input);
       unformat_skip_white_space (line_input);
 
-      if (unformat (line_input, "vppcom {"))
+      if (unformat (line_input, "vcl {"))
        {
          vc_cfg_input = 1;
          continue;
@@ -1547,11 +1568,11 @@ vppcom_cfg_read (char *conf_fname)
              if (VPPCOM_DEBUG > 0)
                clib_warning ("[%d] configured gid %d", vcm->my_pid, gid);
            }
-         else if (unformat (line_input, "segment-baseva 0x%llx",
+         else if (unformat (line_input, "segment-baseva 0x%lx",
                             &vcl_cfg->segment_baseva))
            {
              if (VPPCOM_DEBUG > 0)
-               clib_warning ("[%d] configured segment_baseva 0x%llx",
+               clib_warning ("[%d] configured segment_baseva 0x%lx",
                              vcm->my_pid, vcl_cfg->segment_baseva);
            }
          else if (unformat (line_input, "segment-size 0x%lx",
@@ -1682,6 +1703,62 @@ vppcom_cfg_read (char *conf_fname)
                clib_warning ("[%d] configured accept_timeout %f",
                              vcm->my_pid, vcl_cfg->accept_timeout);
            }
+         else if (unformat (line_input, "app-proxy-transport-tcp"))
+           {
+             vcl_cfg->app_proxy_transport_tcp = 1;
+             if (VPPCOM_DEBUG > 0)
+               clib_warning ("[%d] configured app_proxy_transport_tcp (%d)",
+                             vcm->my_pid, vcl_cfg->app_proxy_transport_tcp);
+           }
+         else if (unformat (line_input, "app-proxy-transport-udp"))
+           {
+             vcl_cfg->app_proxy_transport_udp = 1;
+             if (VPPCOM_DEBUG > 0)
+               clib_warning ("[%d] configured app_proxy_transport_udp (%d)",
+                             vcm->my_pid, vcl_cfg->app_proxy_transport_udp);
+           }
+         else if (unformat (line_input, "app-scope-local"))
+           {
+             vcl_cfg->app_scope_local = 1;
+             if (VPPCOM_DEBUG > 0)
+               clib_warning ("[%d] configured app_scope_local (%d)",
+                             vcm->my_pid, vcl_cfg->app_scope_local);
+           }
+         else if (unformat (line_input, "app-scope-global"))
+           {
+             vcl_cfg->app_scope_global = 1;
+             if (VPPCOM_DEBUG > 0)
+               clib_warning ("[%d] configured app_scope_global (%d)",
+                             vcm->my_pid, vcl_cfg->app_scope_global);
+           }
+         else if (unformat (line_input, "namespace-secret %lu",
+                            &vcl_cfg->namespace_secret))
+           {
+             if (VPPCOM_DEBUG > 0)
+               clib_warning
+                 ("[%d] configured namespace_secret %lu (0x%lx)",
+                  vcm->my_pid, vcl_cfg->namespace_secret,
+                  vcl_cfg->namespace_secret);
+           }
+         else if (unformat (line_input, "namespace-id %v",
+                            &vcl_cfg->namespace_id))
+           {
+             vl_api_application_attach_t *mp;
+             u32 max_nsid_vec_len = sizeof (mp->namespace_id) - 1;
+             u32 nsid_vec_len = vec_len (vcl_cfg->namespace_id);
+             if (nsid_vec_len > max_nsid_vec_len)
+               {
+                 _vec_len (vcl_cfg->namespace_id) = max_nsid_vec_len;
+                 if (VPPCOM_DEBUG > 0)
+                   clib_warning ("[%d] configured namespace_id is too long,"
+                                 " truncated to %d characters!", vcm->my_pid,
+                                 max_nsid_vec_len);
+               }
+
+             if (VPPCOM_DEBUG > 0)
+               clib_warning ("[%d] configured namespace_id %v",
+                             vcm->my_pid, vcl_cfg->namespace_id);
+           }
          else if (unformat (line_input, "}"))
            {
              vc_cfg_input = 0;
@@ -1725,22 +1802,88 @@ vppcom_app_create (char *app_name)
   if (!vcm->init)
     {
       char *conf_fname;
+      char *env_var_str;
 
       vcm->init = 1;
       vcm->my_pid = getpid ();
       clib_fifo_validate (vcm->client_session_index_fifo,
                          vcm->cfg.listen_queue_size);
       vppcom_cfg_init (vcl_cfg);
-      conf_fname = getenv (VPPCOM_CONF_ENV);
+      conf_fname = getenv (VPPCOM_ENV_CONF);
       if (!conf_fname)
        {
          conf_fname = VPPCOM_CONF_DEFAULT;
          if (VPPCOM_DEBUG > 0)
            clib_warning ("[%d] getenv '%s' failed!", vcm->my_pid,
-                         VPPCOM_CONF_ENV);
+                         VPPCOM_ENV_CONF);
        }
       vppcom_cfg_heapsize (conf_fname);
       vppcom_cfg_read (conf_fname);
+      env_var_str = getenv (VPPCOM_ENV_APP_NAMESPACE_ID);
+      if (env_var_str)
+       {
+         u32 ns_id_vec_len = strlen (env_var_str);
+
+         vec_reset_length (vcm->cfg.namespace_id);
+         vec_validate (vcm->cfg.namespace_id, ns_id_vec_len - 1);
+         clib_memcpy (vcm->cfg.namespace_id, env_var_str, ns_id_vec_len);
+
+         if (VPPCOM_DEBUG > 0)
+           clib_warning ("[%d] configured namespace_id (%v) from "
+                         VPPCOM_ENV_APP_NAMESPACE_ID "!", vcm->my_pid,
+                         vcm->cfg.namespace_id);
+       }
+      env_var_str = getenv (VPPCOM_ENV_APP_NAMESPACE_SECRET);
+      if (env_var_str)
+       {
+         u64 tmp;
+         if (sscanf (env_var_str, "%lu", &tmp) != 1)
+           clib_warning ("[%d] Invalid namespace secret specified in "
+                         "the environment variable "
+                         VPPCOM_ENV_APP_NAMESPACE_SECRET
+                         " (%s)!\n", vcm->my_pid, env_var_str);
+         else
+           {
+             vcm->cfg.namespace_secret = tmp;
+             if (VPPCOM_DEBUG > 0)
+               clib_warning ("[%d] configured namespace secret (%lu) from "
+                             VPPCOM_ENV_APP_NAMESPACE_ID "!", vcm->my_pid,
+                             vcm->cfg.namespace_secret);
+           }
+       }
+      if (getenv (VPPCOM_ENV_APP_PROXY_TRANSPORT_TCP))
+       {
+         vcm->cfg.app_proxy_transport_tcp = 1;
+         if (VPPCOM_DEBUG > 0)
+           clib_warning ("[%d] configured app_proxy_transport_tcp (%u) from "
+                         VPPCOM_ENV_APP_PROXY_TRANSPORT_TCP "!", vcm->my_pid,
+                         vcm->cfg.app_proxy_transport_tcp);
+       }
+      if (getenv (VPPCOM_ENV_APP_PROXY_TRANSPORT_UDP))
+       {
+         vcm->cfg.app_proxy_transport_udp = 1;
+         if (VPPCOM_DEBUG > 0)
+           clib_warning ("[%d] configured app_proxy_transport_udp (%u) from "
+                         VPPCOM_ENV_APP_PROXY_TRANSPORT_UDP "!", vcm->my_pid,
+                         vcm->cfg.app_proxy_transport_udp);
+       }
+      if (getenv (VPPCOM_ENV_APP_SCOPE_LOCAL))
+       {
+         vcm->cfg.app_scope_local = 1;
+         if (VPPCOM_DEBUG > 0)
+           clib_warning ("[%d] configured app_scope_local (%u) from "
+                         VPPCOM_ENV_APP_SCOPE_LOCAL "!", vcm->my_pid,
+                         vcm->cfg.app_scope_local);
+       }
+      if (getenv (VPPCOM_ENV_APP_SCOPE_GLOBAL))
+       {
+         vcm->cfg.app_scope_global = 1;
+         if (VPPCOM_DEBUG > 0)
+           clib_warning ("[%d] configured app_scope_global (%u) from "
+                         VPPCOM_ENV_APP_SCOPE_GLOBAL "!", vcm->my_pid,
+                         vcm->cfg.app_scope_global);
+       }
+
       vcm->bind_session_index = ~0;
       vcm->main_cpu = os_get_thread_index ();
       heap = clib_mem_get_per_cpu_heap ();
@@ -1789,12 +1932,12 @@ vppcom_app_create (char *app_name)
          clib_warning ("[%d] vppcom_app_attach() failed!", vcm->my_pid);
          return rv;
        }
-    }
 
-  if (VPPCOM_DEBUG > 0)
-    clib_warning ("[%d] app_name '%s', my_client_index %d (0x%x)",
-                 vcm->my_pid, app_name, vcm->my_client_index,
-                 vcm->my_client_index);
+      if (VPPCOM_DEBUG > 0)
+       clib_warning ("[%d] app_name '%s', my_client_index %d (0x%x)",
+                     vcm->my_pid, app_name, vcm->my_client_index,
+                     vcm->my_client_index);
+    }
 
   return VPPCOM_OK;
 }
@@ -1855,6 +1998,14 @@ vppcom_session_close (uint32_t session_index)
   vppcom_main_t *vcm = &vppcom_main;
   session_t *session = 0;
   int rv;
+  u8 is_server;
+  u8 is_listen;
+  u8 is_cut_thru;
+  u8 is_vep;
+  u8 is_vep_session;
+  u32 next_sid;
+  u32 vep_idx;
+  session_state_t state;
 
   clib_spinlock_lock (&vcm->sessions_lockp);
   rv = vppcom_session_at_index (session_index, &session);
@@ -1866,22 +2017,27 @@ vppcom_session_close (uint32_t session_index)
       clib_spinlock_unlock (&vcm->sessions_lockp);
       goto done;
     }
+  is_server = session->is_server;
+  is_listen = session->is_listen;
+  is_cut_thru = session->is_cut_thru;
+  is_vep = session->is_vep;
+  is_vep_session = session->is_vep_session;
+  next_sid = session->vep.next_sid;
+  vep_idx = session->vep.vep_idx;
+  state = session->state;
   clib_spinlock_unlock (&vcm->sessions_lockp);
 
   if (VPPCOM_DEBUG > 0)
     clib_warning ("[%d] sid %d", vcm->my_pid, session_index);
 
-  if (session->is_vep)
+  if (is_vep)
     {
-      u32 next_sid;
-      for (next_sid = session->vep.next_sid; next_sid != ~0;
-          next_sid = session->vep.next_sid)
+      while (next_sid != ~0)
        {
          rv = vppcom_epoll_ctl (session_index, EPOLL_CTL_DEL, next_sid, 0);
          if ((VPPCOM_DEBUG > 0) && (rv < 0))
            clib_warning ("[%d] EPOLL_CTL_DEL vep_idx %u, sid %u failed, "
-                         "rv = %s (%d)", session_index, next_sid,
-                         vcm->my_pid, session_index,
+                         "rv = %s (%d)", vcm->my_pid, vep_idx, next_sid,
                          vppcom_retval_str (rv), rv);
 
          clib_spinlock_lock (&vcm->sessions_lockp);
@@ -1895,37 +2051,22 @@ vppcom_session_close (uint32_t session_index)
              clib_spinlock_unlock (&vcm->sessions_lockp);
              goto done;
            }
+         next_sid = session->vep.next_sid;
          clib_spinlock_unlock (&vcm->sessions_lockp);
        }
     }
   else
     {
-      if (session->is_vep_session)
+      if (is_vep_session)
        {
-         u32 vep_idx = session->vep.vep_idx;
          rv = vppcom_epoll_ctl (vep_idx, EPOLL_CTL_DEL, session_index, 0);
          if ((VPPCOM_DEBUG > 0) && (rv < 0))
            clib_warning ("[%d] EPOLL_CTL_DEL vep_idx %u, sid %u failed, "
-                         "rv = %s (%d)", vep_idx, session_index,
-                         vcm->my_pid, session_index,
+                         "rv = %s (%d)", vcm->my_pid, vep_idx, session_index,
                          vppcom_retval_str (rv), rv);
-
-         clib_spinlock_lock (&vcm->sessions_lockp);
-         rv = vppcom_session_at_index (session_index, &session);
-         if (PREDICT_FALSE (rv))
-           {
-             if (VPPCOM_DEBUG > 0)
-               clib_warning
-                 ("[%d] invalid session, sid (%u) has been closed!",
-                  vcm->my_pid, session_index);
-             clib_spinlock_unlock (&vcm->sessions_lockp);
-             goto done;
-           }
-         clib_spinlock_unlock (&vcm->sessions_lockp);
        }
 
-      if (session->is_cut_thru && session->is_server &&
-         (session->state == STATE_ACCEPT))
+      if (is_cut_thru && is_server && (state == STATE_ACCEPT))
        {
          rv = vppcom_session_unbind_cut_thru (session);
          if ((VPPCOM_DEBUG > 0) && (rv < 0))
@@ -1934,7 +2075,7 @@ vppcom_session_close (uint32_t session_index)
                          vcm->my_pid, session_index,
                          vppcom_retval_str (rv), rv);
        }
-      else if (session->is_server && session->is_listen)
+      else if (is_server && is_listen)
        {
          rv = vppcom_session_unbind (session_index);
          if ((VPPCOM_DEBUG > 0) && (rv < 0))
@@ -1942,16 +2083,13 @@ vppcom_session_close (uint32_t session_index)
                          vcm->my_pid, session_index,
                          vppcom_retval_str (rv), rv);
        }
-      else if (session->state == STATE_CONNECT)
-       {
-         rv = vppcom_session_disconnect (session_index);
-         if ((VPPCOM_DEBUG > 0) && (rv < 0))
-           clib_warning ("[%d] disconnect (session %d) failed, rv = %s (%d)",
-                         vcm->my_pid, session_index,
-                         vppcom_retval_str (rv), rv);
-       }
+      else if (state == STATE_CONNECT)
+       if (vppcom_session_disconnect (session_index))
+         goto done;
     }
+  clib_spinlock_lock (&vcm->sessions_lockp);
   pool_put_index (vcm->sessions, session_index);
+  clib_spinlock_unlock (&vcm->sessions_lockp);
 done:
   return rv;
 }
@@ -1986,13 +2124,16 @@ vppcom_session_bind (uint32_t session_index, vppcom_endpt_t * ep)
       return VPPCOM_EBADFD;
     }
 
-  if (VPPCOM_DEBUG > 0)
-    clib_warning ("[%d] sid %d", vcm->my_pid, session_index);
-
   session->vrf = ep->vrf;
   session->lcl_addr.is_ip4 = ep->is_ip4;
   session->lcl_addr.ip46 = to_ip46 (!ep->is_ip4, ep->ip);
-  session->port = ep->port;
+  session->lcl_port = ep->port;
+
+  if (VPPCOM_DEBUG > 0)
+    clib_warning ("[%d] sid %d, bound to lcl address %U lcl port %u",
+                 vcm->my_pid, session_index, format_ip46_address,
+                 &session->lcl_addr.ip46, session->lcl_addr.is_ip4,
+                 clib_net_to_host_u16 (session->lcl_port));
 
   clib_spinlock_unlock (&vcm->sessions_lockp);
   return VPPCOM_OK;
@@ -2138,16 +2279,26 @@ vppcom_session_accept (uint32_t listen_session_index, vppcom_endpt_t * ep,
     clib_warning ("[%d] Got a request: client sid %d", vcm->my_pid,
                  client_session_index);
 
+  // Copy the lcl information from the listening session to the client session
+  //  client_session->lcl_port = listen_session->lcl_port;
+  //  client_session->lcl_addr = listen_session->lcl_addr;
+
   ep->vrf = client_session->vrf;
   ep->is_cut_thru = client_session->is_cut_thru;
   ep->is_ip4 = client_session->peer_addr.is_ip4;
-  ep->port = client_session->port;
+  ep->port = client_session->peer_port;
   if (client_session->peer_addr.is_ip4)
     clib_memcpy (ep->ip, &client_session->peer_addr.ip46.ip4,
                 sizeof (ip4_address_t));
   else
     clib_memcpy (ep->ip, &client_session->peer_addr.ip46.ip6,
                 sizeof (ip6_address_t));
+  if (VPPCOM_DEBUG > 0)
+    clib_warning ("[%d] sid %d, accepted peer address %U peer port %u",
+                 vcm->my_pid, client_session_index, format_ip46_address,
+                 &client_session->peer_addr.ip46,
+                 client_session->peer_addr.is_ip4,
+                 clib_net_to_host_u16 (client_session->peer_port));
   clib_spinlock_unlock (&vcm->sessions_lockp);
   return (int) client_session_index;
 }
@@ -2191,7 +2342,7 @@ vppcom_session_connect (uint32_t session_index, vppcom_endpt_t * server_ep)
   session->vrf = server_ep->vrf;
   session->peer_addr.is_ip4 = server_ep->is_ip4;
   session->peer_addr.ip46 = to_ip46 (!server_ep->is_ip4, server_ep->ip);
-  session->port = server_ep->port;
+  session->peer_port = server_ep->port;
 
   if (VPPCOM_DEBUG > 0)
     {
@@ -2200,7 +2351,7 @@ vppcom_session_connect (uint32_t session_index, vppcom_endpt_t * server_ep)
                           session->peer_addr.is_ip4);
       clib_warning ("[%d] connect sid %d to %s server port %d proto %s",
                    vcm->my_pid, session_index, ip_str,
-                   clib_net_to_host_u16 (session->port),
+                   clib_net_to_host_u16 (session->peer_port),
                    session->proto ? "UDP" : "TCP");
       vec_free (ip_str);
     }
@@ -2222,8 +2373,9 @@ vppcom_session_connect (uint32_t session_index, vppcom_endpt_t * server_ep)
   return VPPCOM_OK;
 }
 
-int
-vppcom_session_read (uint32_t session_index, void *buf, int n)
+static inline int
+vppcom_session_read_internal (uint32_t session_index, void *buf, int n,
+                             u8 peek)
 {
   vppcom_main_t *vcm = &vppcom_main;
   session_t *session = 0;
@@ -2273,7 +2425,10 @@ vppcom_session_read (uint32_t session_index, void *buf, int n)
 
   do
     {
-      n_read = svm_fifo_dequeue_nowait (rx_fifo, n, buf);
+      if (peek)
+       n_read = svm_fifo_peek (rx_fifo, 0, n, buf);
+      else
+       n_read = svm_fifo_dequeue_nowait (rx_fifo, n, buf);
     }
   while (!session->is_nonblocking && (n_read <= 0));
 
@@ -2291,6 +2446,18 @@ vppcom_session_read (uint32_t session_index, void *buf, int n)
   return (n_read <= 0) ? VPPCOM_EAGAIN : n_read;
 }
 
+int
+vppcom_session_read (uint32_t session_index, void *buf, int n)
+{
+  return (vppcom_session_read_internal (session_index, buf, n, 0));
+}
+
+static int
+vppcom_session_peek (uint32_t session_index, void *buf, int n)
+{
+  return (vppcom_session_read_internal (session_index, buf, n, 1));
+}
+
 static inline int
 vppcom_session_read_ready (session_t * session, u32 session_index)
 {
@@ -2618,6 +2785,7 @@ select_done:
 static inline void
 vep_verify_epoll_chain (u32 vep_idx)
 {
+  vppcom_main_t *vcm = &vppcom_main;
   session_t *session;
   vppcom_epoll_t *vep;
   int rv;
@@ -2630,21 +2798,23 @@ vep_verify_epoll_chain (u32 vep_idx)
   rv = vppcom_session_at_index (vep_idx, &session);
   if (PREDICT_FALSE (rv))
     {
-      clib_warning ("ERROR: Invalid vep_idx (%u)!", vep_idx);
+      clib_warning ("[%d] ERROR: Invalid vep_idx (%u)!", vcm->my_pid,
+                   vep_idx);
       goto done;
     }
   if (PREDICT_FALSE (!session->is_vep))
     {
-      clib_warning ("ERROR: vep_idx (%u) is not a vep!", vep_idx);
+      clib_warning ("[%d] ERROR: vep_idx (%u) is not a vep!", vcm->my_pid,
+                   vep_idx);
       goto done;
     }
   if (VPPCOM_DEBUG > 1)
-    clib_warning ("vep_idx (%u): Dumping epoll chain\n"
+    clib_warning ("[%d] vep_idx (%u): Dumping epoll chain\n"
                  "{\n"
                  "   is_vep         = %u\n"
                  "   is_vep_session = %u\n"
                  "   wait_cont_idx  = 0x%x (%u)\n"
-                 "}\n",
+                 "}\n", vcm->my_pid,
                  vep_idx, session->is_vep, session->is_vep_session,
                  session->wait_cont_idx, session->wait_cont_idx);
   do
@@ -2674,19 +2844,22 @@ vep_verify_epoll_chain (u32 vep_idx)
          rv = vppcom_session_at_index (sid, &session);
          if (PREDICT_FALSE (rv))
            {
-             clib_warning ("ERROR: Invalid sid (%u)!", sid);
+             clib_warning ("[%d] ERROR: Invalid sid (%u)!",
+                           vcm->my_pid, sid);
              goto done;
            }
          if (PREDICT_FALSE (session->is_vep))
-           clib_warning ("ERROR: sid (%u) is a vep!", vep_idx);
+           clib_warning ("[%d] ERROR: sid (%u) is a vep!",
+                         vcm->my_pid, vep_idx);
          else if (PREDICT_FALSE (!session->is_vep_session))
            {
-             clib_warning ("ERROR: session (%u) is not a vep session!", sid);
+             clib_warning ("[%d] ERROR: session (%u) is not a vep session!",
+                           vcm->my_pid, sid);
              goto done;
            }
          if (PREDICT_FALSE (session->vep.vep_idx != vep_idx))
-           clib_warning ("ERROR: session (%u) vep_idx (%u) != "
-                         "vep_idx (%u)!",
+           clib_warning ("[%d] ERROR: session (%u) vep_idx (%u) != "
+                         "vep_idx (%u)!", vcm->my_pid,
                          sid, session->vep.vep_idx, vep_idx);
        }
     }
@@ -2694,7 +2867,7 @@ vep_verify_epoll_chain (u32 vep_idx)
 
 done:
   if (VPPCOM_DEBUG > 1)
-    clib_warning ("vep_idx (%u): Dump complete!", vep_idx);
+    clib_warning ("[%d] vep_idx (%u): Dump complete!", vcm->my_pid, vep_idx);
 }
 
 int
@@ -2717,7 +2890,7 @@ vppcom_epoll_create (void)
   clib_spinlock_unlock (&vcm->sessions_lockp);
 
   if (VPPCOM_DEBUG > 0)
-    clib_warning ("Created vep_idx %u!", vep_idx);
+    clib_warning ("[%d] Created vep_idx %u!", vcm->my_pid, vep_idx);
 
   return (vep_idx);
 }
@@ -2734,7 +2907,8 @@ vppcom_epoll_ctl (uint32_t vep_idx, int op, uint32_t session_index,
   if (vep_idx == session_index)
     {
       if (VPPCOM_DEBUG > 0)
-       clib_warning ("ERROR: vep_idx == session_index (%u)!", vep_idx);
+       clib_warning ("[%d] ERROR: vep_idx == session_index (%u)!",
+                     vcm->my_pid, vep_idx);
       return VPPCOM_EINVAL;
     }
 
@@ -2743,13 +2917,14 @@ vppcom_epoll_ctl (uint32_t vep_idx, int op, uint32_t session_index,
   if (PREDICT_FALSE (rv))
     {
       if (VPPCOM_DEBUG > 0)
-       clib_warning ("ERROR: Invalid vep_idx (%u)!", vep_idx);
+       clib_warning ("[%d] ERROR: Invalid vep_idx (%u)!", vep_idx);
       goto done;
     }
   if (PREDICT_FALSE (!vep_session->is_vep))
     {
       if (VPPCOM_DEBUG > 0)
-       clib_warning ("ERROR: vep_idx (%u) is not a vep!", vep_idx);
+       clib_warning ("[%d] ERROR: vep_idx (%u) is not a vep!",
+                     vcm->my_pid, vep_idx);
       rv = VPPCOM_EINVAL;
       goto done;
     }
@@ -2761,7 +2936,8 @@ vppcom_epoll_ctl (uint32_t vep_idx, int op, uint32_t session_index,
   if (PREDICT_FALSE (rv))
     {
       if (VPPCOM_DEBUG > 0)
-       clib_warning ("ERROR: Invalid session_index (%u)!", session_index);
+       clib_warning ("[%d] ERROR: Invalid session_index (%u)!",
+                     vcm->my_pid, session_index);
       goto done;
     }
   if (PREDICT_FALSE (session->is_vep))
@@ -2777,7 +2953,8 @@ vppcom_epoll_ctl (uint32_t vep_idx, int op, uint32_t session_index,
     case EPOLL_CTL_ADD:
       if (PREDICT_FALSE (!event))
        {
-         clib_warning ("NULL pointer to epoll_event structure!");
+         clib_warning ("[%d] ERROR: EPOLL_CTL_ADD: NULL pointer to "
+                       "epoll_event structure!", vcm->my_pid);
          rv = VPPCOM_EINVAL;
          goto done;
        }
@@ -2789,8 +2966,9 @@ vppcom_epoll_ctl (uint32_t vep_idx, int op, uint32_t session_index,
          if (PREDICT_FALSE (rv))
            {
              if (VPPCOM_DEBUG > 0)
-               clib_warning ("EPOLL_CTL_ADD: Invalid vep.next_sid (%u) on"
-                             " vep_idx (%u)!", vep_session->vep.next_sid,
+               clib_warning ("[%d] ERROR: EPOLL_CTL_ADD: Invalid "
+                             "vep.next_sid (%u) on vep_idx (%u)!",
+                             vcm->my_pid, vep_session->vep.next_sid,
                              vep_idx);
              goto done;
            }
@@ -2805,15 +2983,16 @@ vppcom_epoll_ctl (uint32_t vep_idx, int op, uint32_t session_index,
       session->is_vep_session = 1;
       vep_session->vep.next_sid = session_index;
       if (VPPCOM_DEBUG > 1)
-       clib_warning ("EPOLL_CTL_ADD: vep_idx %u, sid %u, events 0x%x,"
-                     " data 0x%llx!", vep_idx, session_index,
+       clib_warning ("[%d] EPOLL_CTL_ADD: vep_idx %u, sid %u, events 0x%x,"
+                     " data 0x%llx!", vcm->my_pid, vep_idx, session_index,
                      event->events, event->data.u64);
       break;
 
     case EPOLL_CTL_MOD:
       if (PREDICT_FALSE (!event))
        {
-         clib_warning ("NULL pointer to epoll_event structure!");
+         clib_warning ("[%d] ERROR: EPOLL_CTL_MOD: NULL pointer to "
+                       "epoll_event structure!", vcm->my_pid);
          rv = VPPCOM_EINVAL;
          goto done;
        }
@@ -2823,11 +3002,13 @@ vppcom_epoll_ctl (uint32_t vep_idx, int op, uint32_t session_index,
          if (VPPCOM_DEBUG > 0)
            {
              if (!session->is_vep_session)
-               clib_warning ("EPOLL_CTL_MOD: session (%u) is not "
-                             "a vep session!", session_index);
+               clib_warning ("[%d] ERROR: EPOLL_CTL_MOD: session (%u) "
+                             "is not a vep session!",
+                             vcm->my_pid, session_index);
              else
-               clib_warning ("EPOLL_CTL_MOD: session (%u) vep_idx (%u) != "
-                             "vep_idx (%u)!", session_index,
+               clib_warning ("[%d] ERROR: EPOLL_CTL_MOD: session (%u) "
+                             "vep_idx (%u) != vep_idx (%u)!",
+                             vcm->my_pid, session_index,
                              session->vep.vep_idx, vep_idx);
            }
          rv = VPPCOM_EINVAL;
@@ -2836,8 +3017,8 @@ vppcom_epoll_ctl (uint32_t vep_idx, int op, uint32_t session_index,
       session->vep.et_mask = VEP_DEFAULT_ET_MASK;
       session->vep.ev = *event;
       if (VPPCOM_DEBUG > 1)
-       clib_warning ("EPOLL_CTL_MOD: vep_idx %u, sid %u, events 0x%x,"
-                     " data 0x%llx!", vep_idx, session_index,
+       clib_warning ("[%d] EPOLL_CTL_MOD: vep_idx %u, sid %u, events 0x%x,"
+                     " data 0x%llx!", vcm->my_pid, vep_idx, session_index,
                      event->events, event->data.u64);
       break;
 
@@ -2848,11 +3029,13 @@ vppcom_epoll_ctl (uint32_t vep_idx, int op, uint32_t session_index,
          if (VPPCOM_DEBUG > 0)
            {
              if (!session->is_vep_session)
-               clib_warning ("EPOLL_CTL_DEL: session (%u) is not "
-                             "a vep session!", session_index);
+               clib_warning ("[%d] ERROR: EPOLL_CTL_DEL: session (%u) "
+                             "is not a vep session!",
+                             vcm->my_pid, session_index);
              else
-               clib_warning ("EPOLL_CTL_DEL: session (%u) vep_idx (%u) != "
-                             "vep_idx (%u)!", session_index,
+               clib_warning ("[%d] ERROR: EPOLL_CTL_DEL: session (%u) "
+                             "vep_idx (%u) != vep_idx (%u)!",
+                             vcm->my_pid, session_index,
                              session->vep.vep_idx, vep_idx);
            }
          rv = VPPCOM_EINVAL;
@@ -2872,8 +3055,9 @@ vppcom_epoll_ctl (uint32_t vep_idx, int op, uint32_t session_index,
          if (PREDICT_FALSE (rv))
            {
              if (VPPCOM_DEBUG > 0)
-               clib_warning ("EPOLL_CTL_DEL: Invalid vep.prev_sid (%u) on"
-                             " sid (%u)!", session->vep.prev_sid,
+               clib_warning ("[%d] ERROR: EPOLL_CTL_DEL: Invalid "
+                             "vep.prev_sid (%u) on sid (%u)!",
+                             vcm->my_pid, session->vep.prev_sid,
                              session_index);
              goto done;
            }
@@ -2887,8 +3071,9 @@ vppcom_epoll_ctl (uint32_t vep_idx, int op, uint32_t session_index,
          if (PREDICT_FALSE (rv))
            {
              if (VPPCOM_DEBUG > 0)
-               clib_warning ("EPOLL_CTL_DEL: Invalid vep.next_sid (%u) on"
-                             " sid (%u)!", session->vep.next_sid,
+               clib_warning ("[%d] ERROR: EPOLL_CTL_DEL: Invalid "
+                             "vep.next_sid (%u) on sid (%u)!",
+                             vcm->my_pid, session->vep.next_sid,
                              session_index);
              goto done;
            }
@@ -2902,12 +3087,12 @@ vppcom_epoll_ctl (uint32_t vep_idx, int op, uint32_t session_index,
       session->vep.vep_idx = ~0;
       session->is_vep_session = 0;
       if (VPPCOM_DEBUG > 1)
-       clib_warning ("EPOLL_CTL_DEL: vep_idx %u, sid %u!", vep_idx,
-                     session_index);
+       clib_warning ("[%d] EPOLL_CTL_DEL: vep_idx %u, sid %u!",
+                     vcm->my_pid, vep_idx, session_index);
       break;
 
     default:
-      clib_warning ("Invalid operation (%d)!", op);
+      clib_warning ("[%d] ERROR: Invalid operation (%d)!", vcm->my_pid, op);
       rv = VPPCOM_EINVAL;
     }
 
@@ -2929,7 +3114,8 @@ do {                                                    \
       clib_spinlock_unlock (&vcm->sessions_lockp);      \
                                                         \
       if (VPPCOM_DEBUG > 0)                             \
-        clib_warning ("ERROR: Invalid ##I (%u)!", I);   \
+        clib_warning ("[%s] ERROR: Invalid ##I (%u)!",  \
+                      vcm->my_pid, I);                  \
                                                         \
       goto done;                                        \
     }                                                   \
@@ -2950,13 +3136,15 @@ vppcom_epoll_wait (uint32_t vep_idx, struct epoll_event *events,
   if (PREDICT_FALSE (maxevents <= 0))
     {
       if (VPPCOM_DEBUG > 0)
-       clib_warning ("ERROR: Invalid maxevents (%d)!", maxevents);
+       clib_warning ("[%d] ERROR: Invalid maxevents (%d)!",
+                     vcm->my_pid, maxevents);
       return VPPCOM_EINVAL;
     }
   if (PREDICT_FALSE (wait_for_time < 0))
     {
       if (VPPCOM_DEBUG > 0)
-       clib_warning ("ERROR: Invalid wait_for_time (%f)!", wait_for_time);
+       clib_warning ("[%d] ERROR: Invalid wait_for_time (%f)!",
+                     vcm->my_pid, wait_for_time);
       return VPPCOM_EINVAL;
     }
   memset (events, 0, sizeof (*events) * maxevents);
@@ -2970,13 +3158,15 @@ vppcom_epoll_wait (uint32_t vep_idx, struct epoll_event *events,
   if (PREDICT_FALSE (!is_vep))
     {
       if (VPPCOM_DEBUG > 0)
-       clib_warning ("ERROR: vep_idx (%u) is not a vep!", vep_idx);
+       clib_warning ("[%d] ERROR: vep_idx (%u) is not a vep!",
+                     vcm->my_pid, vep_idx);
       rv = VPPCOM_EINVAL;
       goto done;
     }
   if ((VPPCOM_DEBUG > 0) && (PREDICT_FALSE (vep_next_sid == ~0)))
     {
-      clib_warning ("WARNING: vep_idx (%u) is empty!", vep_idx);
+      clib_warning ("[%d] WARNING: vep_idx (%u) is empty!",
+                   vcm->my_pid, vep_idx);
       goto done;
     }
 
@@ -3007,23 +3197,24 @@ vppcom_epoll_wait (uint32_t vep_idx, struct epoll_event *events,
          if (PREDICT_FALSE (is_vep))
            {
              if (VPPCOM_DEBUG > 0)
-               clib_warning ("ERROR: sid (%u) is a vep!", vep_idx);
+               clib_warning ("[%d] ERROR: sid (%u) is a vep!",
+                             vcm->my_pid, vep_idx);
              rv = VPPCOM_EINVAL;
              goto done;
            }
          if (PREDICT_FALSE (!is_vep_session))
            {
              if (VPPCOM_DEBUG > 0)
-               clib_warning ("EPOLL_CTL_MOD: session (%u) is not "
-                             "a vep session!", sid);
+               clib_warning ("[%d] ERROR: session (%u) is not "
+                             "a vep session!", vcm->my_pid, sid);
              rv = VPPCOM_EINVAL;
              goto done;
            }
          if (PREDICT_FALSE (session_vep_idx != vep_idx))
            {
-             clib_warning ("EPOLL_CTL_MOD: session (%u) "
+             clib_warning ("[%d] ERROR: session (%u) "
                            "vep_idx (%u) != vep_idx (%u)!",
-                           sid, session->vep.vep_idx, vep_idx);
+                           vcm->my_pid, sid, session->vep.vep_idx, vep_idx);
              rv = VPPCOM_EINVAL;
              goto done;
            }
@@ -3140,8 +3331,9 @@ vppcom_session_attr (uint32_t session_index, uint32_t op,
     {
     case VPPCOM_ATTR_GET_NREAD:
       rv = vppcom_session_read_ready (session, session_index);
-      if (VPPCOM_DEBUG > 0)
-       clib_warning ("VPPCOM_ATTR_GET_NREAD: nread = %d", rv);
+      if (VPPCOM_DEBUG > 1)
+       clib_warning ("[%d] VPPCOM_ATTR_GET_NREAD: nread = %d",
+                     vcm->my_pid, rv);
 
       break;
 
@@ -3154,9 +3346,9 @@ vppcom_session_attr (uint32_t session_index, uint32_t op,
        {
          *flags = O_RDWR | ((session->is_nonblocking) ? O_NONBLOCK : 0);
          *buflen = sizeof (*flags);
-         if (VPPCOM_DEBUG > 0)
-           clib_warning ("VPPCOM_ATTR_GET_FLAGS: flags = 0x%08x, "
-                         "is_nonblocking = %u", *flags,
+         if (VPPCOM_DEBUG > 1)
+           clib_warning ("[%d] VPPCOM_ATTR_GET_FLAGS: flags = 0x%08x, "
+                         "is_nonblocking = %u", vcm->my_pid, *flags,
                          session->is_nonblocking);
        }
       else
@@ -3167,9 +3359,9 @@ vppcom_session_attr (uint32_t session_index, uint32_t op,
       if (buffer && buflen && (*buflen >= sizeof (*flags)))
        {
          session->is_nonblocking = (*flags & O_NONBLOCK) ? 1 : 0;
-         if (VPPCOM_DEBUG > 0)
-           clib_warning ("VPPCOM_ATTR_SET_FLAGS: flags = 0x%08x, "
-                         "is_nonblocking = %u", *flags,
+         if (VPPCOM_DEBUG > 1)
+           clib_warning ("[%d] VPPCOM_ATTR_SET_FLAGS: flags = 0x%08x, "
+                         "is_nonblocking = %u", vcm->my_pid, *flags,
                          session->is_nonblocking);
        }
       else
@@ -3181,7 +3373,7 @@ vppcom_session_attr (uint32_t session_index, uint32_t op,
        {
          ep->vrf = session->vrf;
          ep->is_ip4 = session->peer_addr.is_ip4;
-         ep->port = session->port;
+         ep->port = session->peer_port;
          if (session->peer_addr.is_ip4)
            clib_memcpy (ep->ip, &session->peer_addr.ip46.ip4,
                         sizeof (ip4_address_t));
@@ -3189,10 +3381,12 @@ vppcom_session_attr (uint32_t session_index, uint32_t op,
            clib_memcpy (ep->ip, &session->peer_addr.ip46.ip6,
                         sizeof (ip6_address_t));
          *buflen = sizeof (*ep);
-         if (VPPCOM_DEBUG > 0)
-           clib_warning ("VPPCOM_ATTR_GET_PEER_ADDR: is_ip4 = %u, "
-                         "addr = %U", ep->is_ip4, format_ip46_address,
-                         &session->peer_addr.ip46, ep->is_ip4);
+         if (VPPCOM_DEBUG > 1)
+           clib_warning ("[%d] VPPCOM_ATTR_GET_PEER_ADDR: sid %u is_ip4 = "
+                         "%u, addr = %U, port %u", vcm->my_pid,
+                         session_index, ep->is_ip4, format_ip46_address,
+                         &session->peer_addr.ip46, ep->is_ip4,
+                         clib_net_to_host_u16 (ep->port));
        }
       else
        rv = VPPCOM_EINVAL;
@@ -3203,7 +3397,7 @@ vppcom_session_attr (uint32_t session_index, uint32_t op,
        {
          ep->vrf = session->vrf;
          ep->is_ip4 = session->lcl_addr.is_ip4;
-         ep->port = session->port;
+         ep->port = session->lcl_port;
          if (session->lcl_addr.is_ip4)
            clib_memcpy (ep->ip, &session->lcl_addr.ip46.ip4,
                         sizeof (ip4_address_t));
@@ -3211,11 +3405,12 @@ vppcom_session_attr (uint32_t session_index, uint32_t op,
            clib_memcpy (ep->ip, &session->lcl_addr.ip46.ip6,
                         sizeof (ip6_address_t));
          *buflen = sizeof (*ep);
-         if (VPPCOM_DEBUG > 0)
-           if (VPPCOM_DEBUG > 0)
-             clib_warning ("VPPCOM_ATTR_GET_LCL_ADDR: is_ip4 = %u, "
-                           "addr = %U", ep->is_ip4, format_ip46_address,
-                           &session->lcl_addr.ip46, ep->is_ip4);
+         if (VPPCOM_DEBUG > 1)
+           clib_warning ("[%d] VPPCOM_ATTR_GET_LCL_ADDR: sid %u is_ip4 = "
+                         "%u, addr = %U port %d", vcm->my_pid,
+                         session_index, ep->is_ip4, format_ip46_address,
+                         &session->lcl_addr.ip46, ep->is_ip4,
+                         clib_net_to_host_u16 (ep->port));
        }
       else
        rv = VPPCOM_EINVAL;
@@ -3249,6 +3444,81 @@ done:
   return rv;
 }
 
+int
+vppcom_session_recvfrom (uint32_t session_index, void *buffer,
+                        uint32_t buflen, int flags, vppcom_endpt_t * ep)
+{
+  vppcom_main_t *vcm = &vppcom_main;
+  int rv = VPPCOM_OK;
+  session_t *session = 0;
+
+  if (ep)
+    {
+      clib_spinlock_lock (&vcm->sessions_lockp);
+      rv = vppcom_session_at_index (session_index, &session);
+      if (PREDICT_FALSE (rv))
+       {
+         clib_spinlock_unlock (&vcm->sessions_lockp);
+         if (VPPCOM_DEBUG > 0)
+           clib_warning ("[%d] invalid session, sid (%u) has been closed!",
+                         vcm->my_pid, session_index);
+         rv = VPPCOM_EBADFD;
+         clib_spinlock_unlock (&vcm->sessions_lockp);
+         goto done;
+       }
+      ep->vrf = session->vrf;
+      ep->is_ip4 = session->peer_addr.is_ip4;
+      ep->port = session->peer_port;
+      if (session->peer_addr.is_ip4)
+       clib_memcpy (ep->ip, &session->peer_addr.ip46.ip4,
+                    sizeof (ip4_address_t));
+      else
+       clib_memcpy (ep->ip, &session->peer_addr.ip46.ip6,
+                    sizeof (ip6_address_t));
+      clib_spinlock_unlock (&vcm->sessions_lockp);
+    }
+
+  if (flags == 0)
+    rv = vppcom_session_read (session_index, buffer, buflen);
+  else if (flags & MSG_PEEK)
+    rv = vppcom_session_peek (session_index, buffer, buflen);
+  else
+    {
+      clib_warning ("[%d] Unsupport flags for recvfrom %d",
+                   vcm->my_pid, flags);
+      rv = VPPCOM_EAFNOSUPPORT;
+    }
+
+done:
+  return rv;
+}
+
+int
+vppcom_session_sendto (uint32_t session_index, void *buffer,
+                      uint32_t buflen, int flags, vppcom_endpt_t * ep)
+{
+  vppcom_main_t *vcm = &vppcom_main;
+
+  if (!buffer)
+    return VPPCOM_EINVAL;
+
+  if (ep)
+    {
+      // TBD
+      return VPPCOM_EINVAL;
+    }
+
+  if (flags)
+    {
+      // TBD check the flags and do the right thing
+      if (VPPCOM_DEBUG > 2)
+       clib_warning ("[%d] handling flags 0x%u (%d) not implemented yet.",
+                     vcm->my_pid, flags, flags);
+    }
+
+  return (vppcom_session_write (session_index, buffer, buflen));
+}
+
 /*
  * fd.io coding-style-patch-verification: ON
  *