vcl: add DSCP support in VCL
[vpp.git] / src / vcl / vppcom.c
index b91c3a3..107b109 100644 (file)
@@ -219,6 +219,7 @@ vcl_send_session_connect (vcl_worker_t * wrk, vcl_session_t * s)
   memset (mp, 0, sizeof (*mp));
   mp->client_index = wrk->api_client_handle;
   mp->context = s->session_index;
+  mp->dscp = s->dscp;
   mp->wrk_index = wrk->vpp_wrk_index;
   mp->is_ip4 = s->transport.is_ip4;
   mp->parent_handle = s->parent_handle;
@@ -508,10 +509,20 @@ vcl_session_connected_handler (vcl_worker_t * wrk,
 
   session_index = mp->context;
   session = vcl_session_get (wrk, session_index);
-  if (!session)
+  if (PREDICT_FALSE (!session))
     {
       VDBG (0, "ERROR: vpp handle 0x%llx has no session index (%u)!",
            mp->handle, session_index);
+      /* Should not happen but if it does, force vpp session cleanup */
+      vcl_session_t tmp_session = {
+       .vpp_handle = mp->handle,
+       .vpp_evt_q = 0,
+      };
+      vcl_segment_attach_session (
+       mp->segment_handle, mp->server_rx_fifo, mp->server_tx_fifo,
+       mp->vpp_event_queue_address, mp->mq_index, 0, session);
+      if (tmp_session.vpp_evt_q)
+       vcl_send_session_disconnect (wrk, &tmp_session);
       return VCL_INVALID_SESSION_INDEX;
     }
   if (mp->retval)
@@ -3089,8 +3100,22 @@ vcl_epoll_wait_handle_mq_event (vcl_worker_t * wrk, session_event_t * e,
       sid = s->session_index;
       session_events = s->vep.ev.events;
       add_event = 1;
-      events[*num_ev].events = EPOLLHUP | EPOLLRDHUP;
+      if (EPOLLRDHUP & session_events)
+       {
+         /* If app can distinguish between RDHUP and HUP,
+          * we make finer control */
+         events[*num_ev].events = EPOLLRDHUP;
+         if (s->flags & VCL_SESSION_F_WR_SHUTDOWN)
+           {
+             events[*num_ev].events |= EPOLLHUP;
+           }
+       }
+      else
+       {
+         events[*num_ev].events = EPOLLHUP;
+       }
       session_evt_data = s->vep.ev.data.u64;
+
       break;
     case SESSION_CTRL_EVT_RESET:
       if (!e->postponed)
@@ -3584,6 +3609,18 @@ vppcom_session_attr (uint32_t session_handle, uint32_t op,
        rv = VPPCOM_EINVAL;
       break;
 
+    case VPPCOM_ATTR_SET_DSCP:
+      if (buffer && buflen && (*buflen >= sizeof (u8)))
+       {
+         session->dscp = *(u8 *) buffer;
+
+         VDBG (2, "VPPCOM_ATTR_SET_DSCP: %u (0x%x), buflen %d,",
+               *(u8 *) buffer, *(u8 *) buffer, *buflen);
+       }
+      else
+       rv = VPPCOM_EINVAL;
+      break;
+
     case VPPCOM_ATTR_SET_TX_FIFO_LEN:
       if (buffer && buflen && (*buflen == sizeof (u32)))
        {