- if (vam->async_mode)
- {
- vam->async_errors += (retval < 0);
- }
- else
- {
- vam->retval = retval;
- vam->result_ready = 1;
- }
-}
-
-static void vl_api_map_add_domain_reply_t_handler_json
- (vl_api_map_add_domain_reply_t * mp)
-{
- vat_main_t *vam = &vat_main;
- vat_json_node_t node;
-
- vat_json_init_object (&node);
- vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
- vat_json_object_add_uint (&node, "index", ntohl (mp->index));
-
- vat_json_print (vam->ofp, &node);
- vat_json_free (&node);
-
- vam->retval = ntohl (mp->retval);
- vam->result_ready = 1;
-}
-
-static int
-api_get_first_msg_id (vat_main_t * vam)
-{
- vl_api_get_first_msg_id_t *mp;
- unformat_input_t *i = vam->input;
- u8 *name;
- u8 name_set = 0;
- int ret;
-
- while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (i, "client %s", &name))
- name_set = 1;
- else
- break;
- }
-
- if (name_set == 0)
- {
- errmsg ("missing client name");
- return -99;
- }
- vec_add1 (name, 0);
-
- if (vec_len (name) > 63)
- {
- errmsg ("client name too long");
- return -99;
- }
-
- M (GET_FIRST_MSG_ID, mp);
- clib_memcpy (mp->name, name, vec_len (name));
- S (mp);
- W (ret);
- return ret;
-}
-
-static int
-api_cop_interface_enable_disable (vat_main_t * vam)
-{
- unformat_input_t *line_input = vam->input;
- vl_api_cop_interface_enable_disable_t *mp;
- u32 sw_if_index = ~0;
- u8 enable_disable = 1;
- int ret;
-
- while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (line_input, "disable"))
- enable_disable = 0;
- if (unformat (line_input, "enable"))
- enable_disable = 1;
- else if (unformat (line_input, "%U", api_unformat_sw_if_index,
- vam, &sw_if_index))
- ;
- else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
- ;
- else
- break;
- }
-
- if (sw_if_index == ~0)
- {
- errmsg ("missing interface name or sw_if_index");
- return -99;
- }
-
- /* Construct the API message */
- M (COP_INTERFACE_ENABLE_DISABLE, mp);
- mp->sw_if_index = ntohl (sw_if_index);
- mp->enable_disable = enable_disable;
-
- /* send it... */
- S (mp);
- /* Wait for the reply */
- W (ret);
- return ret;
-}
-
-static int
-api_cop_whitelist_enable_disable (vat_main_t * vam)
-{
- unformat_input_t *line_input = vam->input;
- vl_api_cop_whitelist_enable_disable_t *mp;
- u32 sw_if_index = ~0;
- u8 ip4 = 0, ip6 = 0, default_cop = 0;
- u32 fib_id = 0;
- int ret;
-
- while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (line_input, "ip4"))
- ip4 = 1;
- else if (unformat (line_input, "ip6"))
- ip6 = 1;
- else if (unformat (line_input, "default"))
- default_cop = 1;
- else if (unformat (line_input, "%U", api_unformat_sw_if_index,
- vam, &sw_if_index))
- ;
- else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
- ;
- else if (unformat (line_input, "fib-id %d", &fib_id))
- ;
- else
- break;
- }
-
- if (sw_if_index == ~0)
- {
- errmsg ("missing interface name or sw_if_index");
- return -99;
- }
-
- /* Construct the API message */
- M (COP_WHITELIST_ENABLE_DISABLE, mp);
- mp->sw_if_index = ntohl (sw_if_index);
- mp->fib_id = ntohl (fib_id);
- mp->ip4 = ip4;
- mp->ip6 = ip6;
- mp->default_cop = default_cop;
-
- /* send it... */
- S (mp);
- /* Wait for the reply */
- W (ret);
- return ret;
-}
-
-static int
-api_get_node_graph (vat_main_t * vam)
-{
- vl_api_get_node_graph_t *mp;
- int ret;
-
- M (GET_NODE_GRAPH, mp);
-
- /* send it... */
- S (mp);
- /* Wait for the reply */
- W (ret);
- return ret;
-}
-
-/* *INDENT-OFF* */
-/** Used for parsing LISP eids */
-typedef CLIB_PACKED(struct{
- u8 addr[16]; /**< eid address */
- u32 len; /**< prefix length if IP */
- u8 type; /**< type of eid */
-}) lisp_eid_vat_t;
-/* *INDENT-ON* */
-
-static uword
-unformat_lisp_eid_vat (unformat_input_t * input, va_list * args)
-{
- lisp_eid_vat_t *a = va_arg (*args, lisp_eid_vat_t *);
-
- memset (a, 0, sizeof (a[0]));
-
- if (unformat (input, "%U/%d", unformat_ip4_address, a->addr, &a->len))
- {
- a->type = 0; /* ipv4 type */
- }
- else if (unformat (input, "%U/%d", unformat_ip6_address, a->addr, &a->len))
- {
- a->type = 1; /* ipv6 type */
- }
- else if (unformat (input, "%U", unformat_ethernet_address, a->addr))
- {
- a->type = 2; /* mac type */
- }
- else
- {
- return 0;
- }
-
- if ((a->type == 0 && a->len > 32) || (a->type == 1 && a->len > 128))
- {
- return 0;
- }
-
- return 1;
-}
-
-static int
-lisp_eid_size_vat (u8 type)
-{
- switch (type)
- {
- case 0:
- return 4;
- case 1:
- return 16;
- case 2:
- return 6;
- }
- return 0;
-}
-
-static void
-lisp_eid_put_vat (u8 * dst, u8 eid[16], u8 type)
-{
- clib_memcpy (dst, eid, lisp_eid_size_vat (type));
-}
-
-static int
-api_one_add_del_locator_set (vat_main_t * vam)
-{
- unformat_input_t *input = vam->input;
- vl_api_one_add_del_locator_set_t *mp;
- u8 is_add = 1;
- u8 *locator_set_name = NULL;
- u8 locator_set_name_set = 0;
- vl_api_local_locator_t locator, *locators = 0;
- u32 sw_if_index, priority, weight;
- u32 data_len = 0;
-
- int ret;
- /* Parse args required to build the message */
- while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (input, "del"))
- {
- is_add = 0;
- }
- else if (unformat (input, "locator-set %s", &locator_set_name))
- {
- locator_set_name_set = 1;
- }
- else if (unformat (input, "sw_if_index %u p %u w %u",
- &sw_if_index, &priority, &weight))
- {
- locator.sw_if_index = htonl (sw_if_index);
- locator.priority = priority;
- locator.weight = weight;
- vec_add1 (locators, locator);
- }
- else
- if (unformat
- (input, "iface %U p %u w %u", api_unformat_sw_if_index, vam,
- &sw_if_index, &priority, &weight))
- {
- locator.sw_if_index = htonl (sw_if_index);
- locator.priority = priority;
- locator.weight = weight;
- vec_add1 (locators, locator);
- }
- else
- break;
- }
-
- if (locator_set_name_set == 0)
- {
- errmsg ("missing locator-set name");
- vec_free (locators);
- return -99;
- }
-
- if (vec_len (locator_set_name) > 64)
- {
- errmsg ("locator-set name too long");
- vec_free (locator_set_name);
- vec_free (locators);
- return -99;
- }
- vec_add1 (locator_set_name, 0);
-
- data_len = sizeof (vl_api_local_locator_t) * vec_len (locators);
-
- /* Construct the API message */
- M2 (ONE_ADD_DEL_LOCATOR_SET, mp, data_len);
-
- mp->is_add = is_add;
- clib_memcpy (mp->locator_set_name, locator_set_name,
- vec_len (locator_set_name));
- vec_free (locator_set_name);
-
- mp->locator_num = clib_host_to_net_u32 (vec_len (locators));
- if (locators)
- clib_memcpy (mp->locators, locators, data_len);
- vec_free (locators);
-
- /* send it... */
- S (mp);
-
- /* Wait for a reply... */
- W (ret);
- return ret;
-}
-
-#define api_lisp_add_del_locator_set api_one_add_del_locator_set
-
-static int
-api_one_add_del_locator (vat_main_t * vam)
-{
- unformat_input_t *input = vam->input;
- vl_api_one_add_del_locator_t *mp;
- u32 tmp_if_index = ~0;
- u32 sw_if_index = ~0;
- u8 sw_if_index_set = 0;
- u8 sw_if_index_if_name_set = 0;
- u32 priority = ~0;
- u8 priority_set = 0;
- u32 weight = ~0;
- u8 weight_set = 0;
- u8 is_add = 1;
- u8 *locator_set_name = NULL;
- u8 locator_set_name_set = 0;
- int ret;
-
- /* Parse args required to build the message */
- while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (input, "del"))
- {
- is_add = 0;
- }
- else if (unformat (input, "locator-set %s", &locator_set_name))
- {
- locator_set_name_set = 1;
- }
- else if (unformat (input, "iface %U", api_unformat_sw_if_index, vam,
- &tmp_if_index))
- {
- sw_if_index_if_name_set = 1;
- sw_if_index = tmp_if_index;
- }
- else if (unformat (input, "sw_if_index %d", &tmp_if_index))
- {
- sw_if_index_set = 1;
- sw_if_index = tmp_if_index;
- }
- else if (unformat (input, "p %d", &priority))
- {
- priority_set = 1;
- }
- else if (unformat (input, "w %d", &weight))
- {
- weight_set = 1;
- }
- else
- break;
- }
-
- if (locator_set_name_set == 0)
- {
- errmsg ("missing locator-set name");
- return -99;
- }
-
- if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0)
- {
- errmsg ("missing sw_if_index");
- vec_free (locator_set_name);
- return -99;
- }
-
- if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0)
- {
- errmsg ("cannot use both params interface name and sw_if_index");
- vec_free (locator_set_name);
- return -99;
- }
-
- if (priority_set == 0)
- {
- errmsg ("missing locator-set priority");
- vec_free (locator_set_name);
- return -99;
- }
-
- if (weight_set == 0)
- {
- errmsg ("missing locator-set weight");
- vec_free (locator_set_name);
- return -99;
- }
-
- if (vec_len (locator_set_name) > 64)
- {
- errmsg ("locator-set name too long");
- vec_free (locator_set_name);
- return -99;
- }
- vec_add1 (locator_set_name, 0);
-
- /* Construct the API message */
- M (ONE_ADD_DEL_LOCATOR, mp);
-
- mp->is_add = is_add;
- mp->sw_if_index = ntohl (sw_if_index);
- mp->priority = priority;
- mp->weight = weight;
- clib_memcpy (mp->locator_set_name, locator_set_name,
- vec_len (locator_set_name));
- vec_free (locator_set_name);
-
- /* send it... */
- S (mp);
-
- /* Wait for a reply... */
- W (ret);
- return ret;
-}
-
-#define api_lisp_add_del_locator api_one_add_del_locator
-
-uword
-unformat_hmac_key_id (unformat_input_t * input, va_list * args)
-{
- u32 *key_id = va_arg (*args, u32 *);
- u8 *s = 0;
-
- if (unformat (input, "%s", &s))
- {
- if (!strcmp ((char *) s, "sha1"))
- key_id[0] = HMAC_SHA_1_96;
- else if (!strcmp ((char *) s, "sha256"))
- key_id[0] = HMAC_SHA_256_128;
- else
- {
- clib_warning ("invalid key_id: '%s'", s);
- key_id[0] = HMAC_NO_KEY;
- }
- }
- else
- return 0;
-
- vec_free (s);
- return 1;
-}
-
-static int
-api_one_add_del_local_eid (vat_main_t * vam)
-{
- unformat_input_t *input = vam->input;
- vl_api_one_add_del_local_eid_t *mp;
- u8 is_add = 1;
- u8 eid_set = 0;
- lisp_eid_vat_t _eid, *eid = &_eid;
- u8 *locator_set_name = 0;
- u8 locator_set_name_set = 0;
- u32 vni = 0;
- u16 key_id = 0;
- u8 *key = 0;
- int ret;
-
- /* Parse args required to build the message */
- while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (input, "del"))
- {
- is_add = 0;
- }
- else if (unformat (input, "vni %d", &vni))
- {
- ;
- }
- else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
- {
- eid_set = 1;
- }
- else if (unformat (input, "locator-set %s", &locator_set_name))
- {
- locator_set_name_set = 1;
- }
- else if (unformat (input, "key-id %U", unformat_hmac_key_id, &key_id))
- ;
- else if (unformat (input, "secret-key %_%v%_", &key))
- ;
- else
- break;
- }
-
- if (locator_set_name_set == 0)
- {
- errmsg ("missing locator-set name");
- return -99;
- }
-
- if (0 == eid_set)
- {
- errmsg ("EID address not set!");
- vec_free (locator_set_name);
- return -99;
- }
-
- if (key && (0 == key_id))
- {
- errmsg ("invalid key_id!");
- return -99;
- }
-
- if (vec_len (key) > 64)
- {
- errmsg ("key too long");
- vec_free (key);
- return -99;
- }
-
- if (vec_len (locator_set_name) > 64)
- {
- errmsg ("locator-set name too long");
- vec_free (locator_set_name);
- return -99;
- }
- vec_add1 (locator_set_name, 0);
-
- /* Construct the API message */
- M (ONE_ADD_DEL_LOCAL_EID, mp);
-
- mp->is_add = is_add;
- lisp_eid_put_vat (mp->eid, eid->addr, eid->type);
- mp->eid_type = eid->type;
- mp->prefix_len = eid->len;
- mp->vni = clib_host_to_net_u32 (vni);
- mp->key_id = clib_host_to_net_u16 (key_id);
- clib_memcpy (mp->locator_set_name, locator_set_name,
- vec_len (locator_set_name));
- clib_memcpy (mp->key, key, vec_len (key));
-
- vec_free (locator_set_name);
- vec_free (key);
-
- /* send it... */
- S (mp);
-
- /* Wait for a reply... */
- W (ret);
- return ret;
-}
-
-#define api_lisp_add_del_local_eid api_one_add_del_local_eid
-
-static int
-api_lisp_gpe_add_del_fwd_entry (vat_main_t * vam)
-{
- u32 dp_table = 0, vni = 0;;
- unformat_input_t *input = vam->input;
- vl_api_gpe_add_del_fwd_entry_t *mp;
- u8 is_add = 1;
- lisp_eid_vat_t _rmt_eid, *rmt_eid = &_rmt_eid;
- lisp_eid_vat_t _lcl_eid, *lcl_eid = &_lcl_eid;
- u8 rmt_eid_set = 0, lcl_eid_set = 0;
- u32 action = ~0, w;
- ip4_address_t rmt_rloc4, lcl_rloc4;
- ip6_address_t rmt_rloc6, lcl_rloc6;
- vl_api_gpe_locator_t *rmt_locs = 0, *lcl_locs = 0, rloc, *curr_rloc = 0;
- int ret;
-
- memset (&rloc, 0, sizeof (rloc));
-
- /* Parse args required to build the message */
- while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)