-static void
-vl_api_session_rules_details_t_handler (vl_api_session_rules_details_t * mp)
-{
- vat_main_t *vam = &vat_main;
- fib_prefix_t lcl, rmt;
-
- ip_prefix_decode (&mp->lcl, &lcl);
- ip_prefix_decode (&mp->rmt, &rmt);
-
- if (lcl.fp_proto == FIB_PROTOCOL_IP4)
- {
- print (vam->ofp,
- "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
- clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
- mp->scope, format_ip4_address, &lcl.fp_addr.ip4, lcl.fp_len,
- clib_net_to_host_u16 (mp->lcl_port), format_ip4_address,
- &rmt.fp_addr.ip4, rmt.fp_len,
- clib_net_to_host_u16 (mp->rmt_port),
- clib_net_to_host_u32 (mp->action_index), mp->tag);
- }
- else
- {
- print (vam->ofp,
- "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
- clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
- mp->scope, format_ip6_address, &lcl.fp_addr.ip6, lcl.fp_len,
- clib_net_to_host_u16 (mp->lcl_port), format_ip6_address,
- &rmt.fp_addr.ip6, rmt.fp_len,
- clib_net_to_host_u16 (mp->rmt_port),
- clib_net_to_host_u32 (mp->action_index), mp->tag);
- }
-}
-
-static void
-vl_api_session_rules_details_t_handler_json (vl_api_session_rules_details_t *
- mp)
-{
- vat_main_t *vam = &vat_main;
- vat_json_node_t *node = NULL;
- struct in6_addr ip6;
- struct in_addr ip4;
-
- fib_prefix_t lcl, rmt;
-
- ip_prefix_decode (&mp->lcl, &lcl);
- ip_prefix_decode (&mp->rmt, &rmt);
-
- if (VAT_JSON_ARRAY != vam->json_tree.type)
- {
- ASSERT (VAT_JSON_NONE == vam->json_tree.type);
- vat_json_init_array (&vam->json_tree);
- }
- node = vat_json_array_add (&vam->json_tree);
- vat_json_init_object (node);
-
- vat_json_object_add_uint (node, "appns_index",
- clib_net_to_host_u32 (mp->appns_index));
- vat_json_object_add_uint (node, "transport_proto", mp->transport_proto);
- vat_json_object_add_uint (node, "scope", mp->scope);
- vat_json_object_add_uint (node, "action_index",
- clib_net_to_host_u32 (mp->action_index));
- vat_json_object_add_uint (node, "lcl_port",
- clib_net_to_host_u16 (mp->lcl_port));
- vat_json_object_add_uint (node, "rmt_port",
- clib_net_to_host_u16 (mp->rmt_port));
- vat_json_object_add_uint (node, "lcl_plen", lcl.fp_len);
- vat_json_object_add_uint (node, "rmt_plen", rmt.fp_len);
- vat_json_object_add_string_copy (node, "tag", mp->tag);
- if (lcl.fp_proto == FIB_PROTOCOL_IP4)
- {
- clib_memcpy (&ip4, &lcl.fp_addr.ip4, sizeof (ip4));
- vat_json_object_add_ip4 (node, "lcl_ip", ip4);
- clib_memcpy (&ip4, &rmt.fp_addr.ip4, sizeof (ip4));
- vat_json_object_add_ip4 (node, "rmt_ip", ip4);
- }
- else
- {
- clib_memcpy (&ip6, &lcl.fp_addr.ip6, sizeof (ip6));
- vat_json_object_add_ip6 (node, "lcl_ip", ip6);
- clib_memcpy (&ip6, &rmt.fp_addr.ip6, sizeof (ip6));
- vat_json_object_add_ip6 (node, "rmt_ip", ip6);
- }
-}
-
-static int
-api_session_rule_add_del (vat_main_t * vam)
-{
- vl_api_session_rule_add_del_t *mp;
- unformat_input_t *i = vam->input;
- u32 proto = ~0, lcl_port, rmt_port, action = 0, lcl_plen, rmt_plen;
- u32 appns_index = 0, scope = 0;
- ip4_address_t lcl_ip4, rmt_ip4;
- ip6_address_t lcl_ip6, rmt_ip6;
- u8 is_ip4 = 1, conn_set = 0;
- u8 is_add = 1, *tag = 0;
- int ret;
- fib_prefix_t lcl, rmt;
-
- while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (i, "del"))
- is_add = 0;
- else if (unformat (i, "add"))
- ;
- else if (unformat (i, "proto tcp"))
- proto = 0;
- else if (unformat (i, "proto udp"))
- proto = 1;
- else if (unformat (i, "appns %d", &appns_index))
- ;
- else if (unformat (i, "scope %d", &scope))
- ;
- else if (unformat (i, "tag %_%v%_", &tag))
- ;
- else
- if (unformat
- (i, "%U/%d %d %U/%d %d", unformat_ip4_address, &lcl_ip4,
- &lcl_plen, &lcl_port, unformat_ip4_address, &rmt_ip4, &rmt_plen,
- &rmt_port))
- {
- is_ip4 = 1;
- conn_set = 1;
- }
- else
- if (unformat
- (i, "%U/%d %d %U/%d %d", unformat_ip6_address, &lcl_ip6,
- &lcl_plen, &lcl_port, unformat_ip6_address, &rmt_ip6, &rmt_plen,
- &rmt_port))
- {
- is_ip4 = 0;
- conn_set = 1;
- }
- else if (unformat (i, "action %d", &action))
- ;
- else
- break;
- }
- if (proto == ~0 || !conn_set || action == ~0)
- {
- errmsg ("transport proto, connection and action must be set");
- return -99;
- }
-
- if (scope > 3)
- {
- errmsg ("scope should be 0-3");
- return -99;
- }
-
- M (SESSION_RULE_ADD_DEL, mp);
-
- clib_memset (&lcl, 0, sizeof (lcl));
- clib_memset (&rmt, 0, sizeof (rmt));
- if (is_ip4)
- {
- ip_set (&lcl.fp_addr, &lcl_ip4, 1);
- ip_set (&rmt.fp_addr, &rmt_ip4, 1);
- lcl.fp_len = lcl_plen;
- rmt.fp_len = rmt_plen;
- }
- else
- {
- ip_set (&lcl.fp_addr, &lcl_ip6, 0);
- ip_set (&rmt.fp_addr, &rmt_ip6, 0);
- lcl.fp_len = lcl_plen;
- rmt.fp_len = rmt_plen;
- }
-
-
- ip_prefix_encode (&lcl, &mp->lcl);
- ip_prefix_encode (&rmt, &mp->rmt);
- mp->lcl_port = clib_host_to_net_u16 ((u16) lcl_port);
- mp->rmt_port = clib_host_to_net_u16 ((u16) rmt_port);
- mp->transport_proto =
- proto ? TRANSPORT_PROTO_API_UDP : TRANSPORT_PROTO_API_TCP;
- mp->action_index = clib_host_to_net_u32 (action);
- mp->appns_index = clib_host_to_net_u32 (appns_index);
- mp->scope = scope;
- mp->is_add = is_add;
- if (tag)
- {
- clib_memcpy (mp->tag, tag, vec_len (tag));
- vec_free (tag);
- }
-
- S (mp);
- W (ret);
- return ret;
-}
-
-static int
-api_session_rules_dump (vat_main_t * vam)
-{
- vl_api_session_rules_dump_t *mp;
- vl_api_control_ping_t *mp_ping;
- int ret;
-
- if (!vam->json_output)
- {
- print (vam->ofp, "%=20s", "Session Rules");
- }
-
- M (SESSION_RULES_DUMP, mp);
- /* send it... */
- S (mp);
-
- /* Use a control ping for synchronization */
- MPING (CONTROL_PING, mp_ping);
- S (mp_ping);
-
- /* Wait for a reply... */
- W (ret);
- return ret;
-}
-