misc: move to new pool_foreach macros
[vpp.git] / src / vnet / session / session_api.c
index 988d3e2..d080ae4 100644 (file)
@@ -180,7 +180,7 @@ mq_send_session_accepted_cb (session_t * s)
       mp->rmt.is_ip4 = session_type_is_ip4 (listener->session_type);
       mp->rmt.port = ct->c_rmt_port;
       mp->handle = session_handle (s);
-      vpp_queue = session_main_get_vpp_event_queue (0);
+      vpp_queue = session_main_get_vpp_event_queue (s->thread_index);
       mp->vpp_event_queue_address = pointer_to_uword (vpp_queue);
     }
   svm_msg_q_add_and_unlock (app_mq, msg);
@@ -318,7 +318,7 @@ mq_send_session_connected_cb (u32 app_wrk_index, u32 api_context,
       mp->handle = session_handle (s);
       mp->lcl.port = cct->c_lcl_port;
       mp->lcl.is_ip4 = cct->c_is_ip4;
-      vpp_mq = session_main_get_vpp_event_queue (0);
+      vpp_mq = session_main_get_vpp_event_queue (s->thread_index);
       mp->vpp_event_queue_address = pointer_to_uword (vpp_mq);
       mp->server_rx_fifo = pointer_to_uword (s->rx_fifo);
       mp->server_tx_fifo = pointer_to_uword (s->tx_fifo);
@@ -614,6 +614,12 @@ vl_api_app_attach_t_handler (vl_api_app_attach_t * mp)
       rv = VNET_API_ERROR_FEATURE_DISABLED;
       goto done;
     }
+  /* Only support binary api with socket transport */
+  if (vl_api_registration_file_index (reg) == VL_API_INVALID_FI)
+    {
+      rv = VNET_API_ERROR_APP_UNSUPPORTED_CFG;
+      goto done;
+    }
 
   STATIC_ASSERT (sizeof (u64) * APP_OPTIONS_N_OPTIONS <=
                 sizeof (mp->options),
@@ -623,7 +629,6 @@ vl_api_app_attach_t_handler (vl_api_app_attach_t * mp)
   a->api_client_index = mp->client_index;
   a->options = mp->options;
   a->session_cb_vft = &session_mq_cb_vft;
-
   a->namespace_id = vl_api_from_api_to_new_vec (mp, &mp->namespace_id);
 
   if ((rv = vnet_application_attach (a)))
@@ -964,12 +969,12 @@ send_session_rules_table_details (session_rules_table_t * srt, u8 fib_proto,
       u8 *tag = 0;
       /* *INDENT-OFF* */
       srt16 = &srt->session_rules_tables_16;
-      pool_foreach (rule16, srt16->rules, ({
+      pool_foreach (rule16, srt16->rules)  {
        ri = mma_rules_table_rule_index_16 (srt16, rule16);
        tag = session_rules_table_rule_tag (srt, ri, 1);
         send_session_rule_details4 (rule16, is_local, tp, appns_index, tag,
                                     reg, context);
-      }));
+      }
       /* *INDENT-ON* */
     }
   if (is_local || fib_proto == FIB_PROTOCOL_IP6)
@@ -977,18 +982,18 @@ send_session_rules_table_details (session_rules_table_t * srt, u8 fib_proto,
       u8 *tag = 0;
       /* *INDENT-OFF* */
       srt40 = &srt->session_rules_tables_40;
-      pool_foreach (rule40, srt40->rules, ({
+      pool_foreach (rule40, srt40->rules)  {
        ri = mma_rules_table_rule_index_40 (srt40, rule40);
        tag = session_rules_table_rule_tag (srt, ri, 1);
         send_session_rule_details6 (rule40, is_local, tp, appns_index, tag,
                                     reg, context);
-      }));
+      }
       /* *INDENT-ON* */
     }
 }
 
 static void
-vl_api_session_rules_dump_t_handler (vl_api_one_map_server_dump_t * mp)
+vl_api_session_rules_dump_t_handler (vl_api_session_rules_dump_t * mp)
 {
   vl_api_registration_t *reg;
   session_table_t *st;
@@ -1225,6 +1230,8 @@ sapi_send_fds (app_worker_t * app_wrk, int *fds, int n_fds)
   app_ns = app_namespace_get (app->ns_index);
   cs_index = appns_sapi_handle_sock_index (app_wrk->api_client_index);
   cs = appns_sapi_get_socket (app_ns, cs_index);
+  if (PREDICT_FALSE (!cs))
+    return;
 
   /* There's no payload for the message only the type */
   smsg.type = APP_SAPI_MSG_TYPE_SEND_FDS;
@@ -1434,8 +1441,8 @@ sapi_add_del_worker_handler (app_namespace_t * app_ns,
   app_ns_api_handle_t *handle;
   app_sapi_msg_t msg = { 0 };
   app_worker_t *app_wrk;
+  u32 sapi_handle = -1;
   application_t *app;
-  u32 sapi_handle;
   u8 fd_flags = 0;
 
   app = application_get_if_valid (mp->app_index);
@@ -1486,6 +1493,7 @@ done:
   rmp = &msg.worker_add_del_reply;
   rmp->retval = rv;
   rmp->is_add = mp->is_add;
+  rmp->api_client_handle = sapi_handle;
   rmp->wrk_index = args.wrk_map_index;
   rmp->segment_handle = args.segment_handle;
   if (!rv && mp->is_add)
@@ -1533,6 +1541,7 @@ static clib_error_t *
 sapi_sock_read_ready (clib_file_t * cf)
 {
   app_ns_api_handle_t *handle = (app_ns_api_handle_t *) & cf->private_data;
+  vlib_main_t *vm = vlib_get_main ();
   app_sapi_msg_t msg = { 0 };
   app_namespace_t *app_ns;
   clib_error_t *err = 0;
@@ -1553,6 +1562,8 @@ sapi_sock_read_ready (clib_file_t * cf)
 
   handle = (app_ns_api_handle_t *) & cs->private_data;
 
+  vlib_worker_thread_barrier_sync (vm);
+
   switch (msg.type)
     {
     case APP_SAPI_MSG_TYPE_ATTACH:
@@ -1567,6 +1578,8 @@ sapi_sock_read_ready (clib_file_t * cf)
       break;
     }
 
+  vlib_worker_thread_barrier_release (vm);
+
 error:
   return 0;
 }
@@ -1630,14 +1643,14 @@ sapi_sock_accept_ready (clib_file_t * scf)
   cf.file_descriptor = ccs->fd;
   /* File points to app namespace and socket */
   handle.aah_sock_index = appns_sapi_socket_index (app_ns, ccs);
-  cf.private_data = handle.as_uword;
+  cf.private_data = handle.as_u64;
   cf.description = format (0, "app sock conn fd: %d", ccs->fd);
 
   /* Poll until we get an attach message. Socket points to file and
    * application that owns the socket */
   handle.aah_app_wrk_index = APP_INVALID_INDEX;
   handle.aah_file_index = clib_file_add (&file_main, &cf);
-  ccs->private_data = handle.as_uword;
+  ccs->private_data = handle.as_u64;
 
   return err;