+ REPLY_MACRO (VL_API_CONNECT_SESSION_REPLY);
+}
+
+static void
+vl_api_app_namespace_add_del_t_handler (vl_api_app_namespace_add_del_t * mp)
+{
+ vl_api_app_namespace_add_del_reply_t *rmp;
+ clib_error_t *error = 0;
+ u32 appns_index = 0;
+ u8 *ns_id = 0;
+ int rv = 0;
+ if (!session_manager_is_enabled ())
+ {
+ rv = VNET_API_ERROR_FEATURE_DISABLED;
+ goto done;
+ }
+
+ if (mp->namespace_id_len > ARRAY_LEN (mp->namespace_id))
+ {
+ rv = VNET_API_ERROR_INVALID_VALUE;
+ goto done;
+ }
+
+ vec_validate (ns_id, mp->namespace_id_len - 1);
+ clib_memcpy (ns_id, mp->namespace_id, mp->namespace_id_len);
+ vnet_app_namespace_add_del_args_t args = {
+ .ns_id = ns_id,
+ .secret = clib_net_to_host_u64 (mp->secret),
+ .sw_if_index = clib_net_to_host_u32 (mp->sw_if_index),
+ .ip4_fib_id = clib_net_to_host_u32 (mp->ip4_fib_id),
+ .ip6_fib_id = clib_net_to_host_u32 (mp->ip6_fib_id),
+ .is_add = 1
+ };
+ error = vnet_app_namespace_add_del (&args);
+ if (error)
+ {
+ rv = clib_error_get_code (error);
+ clib_error_report (error);
+ }
+ else
+ {
+ appns_index = app_namespace_index_from_id (ns_id);
+ if (appns_index == APP_NAMESPACE_INVALID_INDEX)
+ {
+ clib_warning ("app ns lookup failed");
+ rv = VNET_API_ERROR_UNSPECIFIED;
+ }
+ }
+ vec_free (ns_id);
+
+ /* *INDENT-OFF* */
+done:
+ REPLY_MACRO2 (VL_API_APP_NAMESPACE_ADD_DEL_REPLY, ({
+ if (!rv)
+ rmp->appns_index = clib_host_to_net_u32 (appns_index);
+ }));
+ /* *INDENT-ON* */
+}
+
+static void
+vl_api_session_rule_add_del_t_handler (vl_api_session_rule_add_del_t * mp)
+{
+ vl_api_session_rule_add_del_reply_t *rmp;
+ session_rule_add_del_args_t args;
+ session_rule_table_add_del_args_t *table_args = &args.table_args;
+ clib_error_t *error;
+ u8 fib_proto;
+ int rv = 0;
+
+ memset (&args, 0, sizeof (args));
+ fib_proto = mp->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
+
+ table_args->lcl.fp_len = mp->lcl_plen;
+ table_args->lcl.fp_proto = fib_proto;
+ table_args->rmt.fp_len = mp->rmt_plen;
+ table_args->rmt.fp_proto = fib_proto;
+ table_args->lcl_port = mp->lcl_port;
+ table_args->rmt_port = mp->rmt_port;
+ table_args->action_index = clib_net_to_host_u32 (mp->action_index);
+ table_args->is_add = mp->is_add;
+ mp->tag[sizeof (mp->tag) - 1] = 0;
+ table_args->tag = format (0, "%s", mp->tag);
+ args.appns_index = clib_net_to_host_u32 (mp->appns_index);
+ args.scope = mp->scope;
+ args.transport_proto = mp->transport_proto;
+
+ memset (&table_args->lcl.fp_addr, 0, sizeof (table_args->lcl.fp_addr));
+ memset (&table_args->rmt.fp_addr, 0, sizeof (table_args->rmt.fp_addr));
+ ip_set (&table_args->lcl.fp_addr, mp->lcl_ip, mp->is_ip4);
+ ip_set (&table_args->rmt.fp_addr, mp->rmt_ip, mp->is_ip4);
+ error = vnet_session_rule_add_del (&args);
+ if (error)
+ {
+ rv = clib_error_get_code (error);
+ clib_error_report (error);
+ }
+ vec_free (table_args->tag);
+ REPLY_MACRO (VL_API_SESSION_RULE_ADD_DEL_REPLY);
+}
+
+static void
+send_session_rule_details4 (mma_rule_16_t * rule, u8 is_local,
+ u8 transport_proto, u32 appns_index, u8 * tag,
+ vl_api_registration_t * reg, u32 context)
+{
+ vl_api_session_rules_details_t *rmp = 0;
+ session_mask_or_match_4_t *match =
+ (session_mask_or_match_4_t *) & rule->match;
+ session_mask_or_match_4_t *mask =
+ (session_mask_or_match_4_t *) & rule->mask;
+
+ rmp = vl_msg_api_alloc (sizeof (*rmp));
+ memset (rmp, 0, sizeof (*rmp));
+ rmp->_vl_msg_id = ntohs (VL_API_SESSION_RULES_DETAILS);
+ rmp->context = context;
+
+ rmp->is_ip4 = 1;
+ clib_memcpy (rmp->lcl_ip, &match->lcl_ip, sizeof (match->lcl_ip));
+ clib_memcpy (rmp->rmt_ip, &match->rmt_ip, sizeof (match->rmt_ip));
+ rmp->lcl_plen = ip4_mask_to_preflen (&mask->lcl_ip);
+ rmp->rmt_plen = ip4_mask_to_preflen (&mask->rmt_ip);
+ rmp->lcl_port = match->lcl_port;
+ rmp->rmt_port = match->rmt_port;
+ rmp->action_index = clib_host_to_net_u32 (rule->action_index);
+ rmp->scope =
+ is_local ? SESSION_RULE_SCOPE_LOCAL : SESSION_RULE_SCOPE_GLOBAL;
+ rmp->transport_proto = transport_proto;
+ rmp->appns_index = clib_host_to_net_u32 (appns_index);
+ if (tag)
+ {
+ clib_memcpy (rmp->tag, tag, vec_len (tag));
+ rmp->tag[vec_len (tag)] = 0;
+ }
+
+ vl_api_send_msg (reg, (u8 *) rmp);
+}
+
+static void
+send_session_rule_details6 (mma_rule_40_t * rule, u8 is_local,
+ u8 transport_proto, u32 appns_index, u8 * tag,
+ vl_api_registration_t * reg, u32 context)
+{
+ vl_api_session_rules_details_t *rmp = 0;
+ session_mask_or_match_6_t *match =
+ (session_mask_or_match_6_t *) & rule->match;
+ session_mask_or_match_6_t *mask =
+ (session_mask_or_match_6_t *) & rule->mask;
+
+ rmp = vl_msg_api_alloc (sizeof (*rmp));
+ memset (rmp, 0, sizeof (*rmp));
+ rmp->_vl_msg_id = ntohs (VL_API_SESSION_RULES_DETAILS);
+ rmp->context = context;
+
+ rmp->is_ip4 = 0;
+ clib_memcpy (rmp->lcl_ip, &match->lcl_ip, sizeof (match->lcl_ip));
+ clib_memcpy (rmp->rmt_ip, &match->rmt_ip, sizeof (match->rmt_ip));
+ rmp->lcl_plen = ip6_mask_to_preflen (&mask->lcl_ip);
+ rmp->rmt_plen = ip6_mask_to_preflen (&mask->rmt_ip);
+ rmp->lcl_port = match->lcl_port;
+ rmp->rmt_port = match->rmt_port;
+ rmp->action_index = clib_host_to_net_u32 (rule->action_index);
+ rmp->scope =
+ is_local ? SESSION_RULE_SCOPE_LOCAL : SESSION_RULE_SCOPE_GLOBAL;
+ rmp->transport_proto = transport_proto;
+ rmp->appns_index = clib_host_to_net_u32 (appns_index);
+ if (tag)
+ {
+ clib_memcpy (rmp->tag, tag, vec_len (tag));
+ rmp->tag[vec_len (tag)] = 0;
+ }
+
+ vl_api_send_msg (reg, (u8 *) rmp);
+}
+
+static void
+send_session_rules_table_details (session_rules_table_t * srt, u8 fib_proto,
+ u8 tp, u8 is_local, u32 appns_index,
+ vl_api_registration_t * reg, u32 context)
+{
+ mma_rule_16_t *rule16;
+ mma_rule_40_t *rule40;
+ mma_rules_table_16_t *srt16;
+ mma_rules_table_40_t *srt40;
+ u32 ri;
+
+ if (is_local || fib_proto == FIB_PROTOCOL_IP4)
+ {
+ u8 *tag = 0;
+ /* *INDENT-OFF* */
+ srt16 = &srt->session_rules_tables_16;
+ 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)
+ {
+ u8 *tag = 0;
+ /* *INDENT-OFF* */
+ srt40 = &srt->session_rules_tables_40;
+ 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_registration_t *reg;
+ session_table_t *st;
+ u8 tp;
+
+ reg = vl_api_client_index_to_registration (mp->client_index);
+ if (!reg)
+ return;
+
+ /* *INDENT-OFF* */
+ session_table_foreach (st, ({
+ for (tp = 0; tp < TRANSPORT_N_PROTO; tp++)
+ {
+ send_session_rules_table_details (&st->session_rules[tp],
+ st->active_fib_proto, tp,
+ st->is_local, st->appns_index, reg,
+ mp->context);
+ }
+ }));
+ /* *INDENT-ON* */
+}
+
+static void
+vl_api_application_tls_cert_add_t_handler (vl_api_application_tls_cert_add_t *
+ mp)
+{
+ vl_api_app_namespace_add_del_reply_t *rmp;
+ vnet_app_add_tls_cert_args_t _a, *a = &_a;
+ clib_error_t *error;
+ application_t *app;
+ u32 cert_len;
+ int rv = 0;
+ if (!session_manager_is_enabled ())
+ {
+ rv = VNET_API_ERROR_FEATURE_DISABLED;
+ goto done;
+ }
+ if (!(app = application_lookup (mp->client_index)))
+ {
+ rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
+ goto done;
+ }
+ memset (a, 0, sizeof (*a));
+ a->app_index = app->index;
+ cert_len = clib_net_to_host_u16 (mp->cert_len);
+ if (cert_len > 10000)
+ {
+ rv = VNET_API_ERROR_INVALID_VALUE;
+ goto done;
+ }
+ vec_validate (a->cert, cert_len);
+ clib_memcpy (a->cert, mp->cert, cert_len);
+ if ((error = vnet_app_add_tls_cert (a)))
+ {
+ rv = clib_error_get_code (error);
+ clib_error_report (error);
+ }
+ vec_free (a->cert);
+done:
+ REPLY_MACRO (VL_API_APPLICATION_TLS_CERT_ADD_REPLY);
+}
+
+static void
+vl_api_application_tls_key_add_t_handler (vl_api_application_tls_key_add_t *
+ mp)
+{
+ vl_api_app_namespace_add_del_reply_t *rmp;
+ vnet_app_add_tls_key_args_t _a, *a = &_a;
+ clib_error_t *error;
+ application_t *app;
+ u32 key_len;
+ int rv = 0;
+ if (!session_manager_is_enabled ())
+ {
+ rv = VNET_API_ERROR_FEATURE_DISABLED;
+ goto done;
+ }
+ if (!(app = application_lookup (mp->client_index)))
+ {
+ rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
+ goto done;
+ }
+ memset (a, 0, sizeof (*a));
+ a->app_index = app->index;
+ key_len = clib_net_to_host_u16 (mp->key_len);
+ if (key_len > 10000)
+ {
+ rv = VNET_API_ERROR_INVALID_VALUE;
+ goto done;
+ }
+ vec_validate (a->key, key_len);
+ clib_memcpy (a->key, mp->key, key_len);
+ if ((error = vnet_app_add_tls_key (a)))
+ {
+ rv = clib_error_get_code (error);
+ clib_error_report (error);
+ }
+ vec_free (a->key);
+done:
+ REPLY_MACRO (VL_API_APPLICATION_TLS_KEY_ADD_REPLY);