diff options
author | Andrej Kozemcak <akozemca@cisco.com> | 2016-06-14 13:55:57 +0200 |
---|---|---|
committer | Florin Coras <florin.coras@gmail.com> | 2016-06-17 09:17:31 +0000 |
commit | b6e4d3990ed694fd0aeaa2e4a75c1b4602cf0379 (patch) | |
tree | 35770420009384b0d99d426029246e299f7a605d | |
parent | a29f20068841a05ee5813c1601ba2f07d9398afa (diff) |
New LISP API map-request itr-rloc
API to constrain source locator when sending map-requests.
lisp map-request itr-rloc <locator-set name>
Change-Id: I19f3a1aa8a387ca8662ccf3a4ad774ea7d655f80
Signed-off-by: Andrej Kozemcak <akozemca@cisco.com>
-rw-r--r-- | vnet/vnet/lisp-cp/control.c | 130 | ||||
-rw-r--r-- | vnet/vnet/lisp-cp/control.h | 12 | ||||
-rw-r--r-- | vpp-api-test/vat/api_format.c | 126 | ||||
-rw-r--r-- | vpp/api/api.c | 58 | ||||
-rw-r--r-- | vpp/api/vpe.api | 40 |
5 files changed, 364 insertions, 2 deletions
diff --git a/vnet/vnet/lisp-cp/control.c b/vnet/vnet/lisp-cp/control.c index c96ff71c348..537a3340dfd 100644 --- a/vnet/vnet/lisp-cp/control.c +++ b/vnet/vnet/lisp-cp/control.c @@ -1075,6 +1075,13 @@ vnet_lisp_add_del_locator_set (vnet_lisp_add_del_locator_set_args_t * a, return -1; } + if (lcm->mreq_itr_rlocs == p[0]) + { + clib_warning ("Can't delete the locator-set used to constrain " + "the itr-rlocs in map-requests!"); + return -1; + } + if (vec_len(lcm->locator_set_to_eids) != 0) { eid_indexes = vec_elt_at_index(lcm->locator_set_to_eids, p[0]); @@ -1422,6 +1429,117 @@ VLIB_CLI_COMMAND (lisp_add_del_map_resolver_command) = { .function = lisp_add_del_map_resolver_command_fn, }; +int +vnet_lisp_add_del_mreq_itr_rlocs (vnet_lisp_add_del_mreq_itr_rloc_args_t * a) +{ + lisp_cp_main_t * lcm = vnet_lisp_cp_get_main(); + uword * p = 0; + + //TODO: Wait for merge https://gerrit.fd.io/r/#/c/1427/ +// if (vnet_lisp_enable_disable_status () == 0) +// { +// clib_warning ("LISP is disabled!"); +// return VNET_API_ERROR_LISP_DISABLED; +// } + + if (a->is_add) + { + p = hash_get_mem(lcm->locator_set_index_by_name, a->locator_set_name); + if (!p) + { + clib_warning("locator-set %v doesn't exist", a->locator_set_name); + return VNET_API_ERROR_INVALID_ARGUMENT; + } + + lcm->mreq_itr_rlocs = p[0]; + } + else + { + lcm->mreq_itr_rlocs = ~0; + } + + return 0; +} + +static clib_error_t * +lisp_add_del_mreq_itr_rlocs_command_fn(vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + unformat_input_t _line_input, * line_input = &_line_input; + u8 is_add = 1; + u8 * locator_set_name = 0; + clib_error_t * error = 0; + int rv = 0; + vnet_lisp_add_del_mreq_itr_rloc_args_t _a, * a = &_a; + + /* Get a line of input. */ + if (! unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "del")) + is_add = 0; + else if (unformat (line_input, "add %s", &locator_set_name)) + is_add = 1; + else + { + error = unformat_parse_error(line_input); + goto done; + } + } + + a->is_add = is_add; + a->locator_set_name = locator_set_name; + rv = vnet_lisp_add_del_mreq_itr_rlocs (a); + if (0 != rv) + { + error = clib_error_return(0, "failed to %s map-request itr-rlocs!", + is_add ? "add" : "delete"); + } + + vec_free(locator_set_name); + + done: + return error; + +} + +VLIB_CLI_COMMAND (lisp_add_del_map_request_command) = { + .path = "lisp map-request itr-rlocs", + .short_help = "lisp map-request itr-rlocs add/del <locator_set_name>", + .function = lisp_add_del_mreq_itr_rlocs_command_fn, +}; + +static clib_error_t * +lisp_show_mreq_itr_rlocs_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + lisp_cp_main_t * lcm = vnet_lisp_cp_get_main(); + locator_set_t * loc_set; + + vlib_cli_output (vm, "%=20s", "itr-rlocs"); + + if (~0 == lcm->mreq_itr_rlocs) + { + return 0; + } + + loc_set = pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs); + + vlib_cli_output (vm, "%=20s", loc_set->name); + + return 0; +} + +VLIB_CLI_COMMAND (lisp_show_map_request_command) = { + .path = "show lisp map-request itr-rlocs", + .short_help = "Shows map-request itr-rlocs", + .function = lisp_show_mreq_itr_rlocs_command_fn, +}; + /* Statistics (not really errors) */ #define foreach_lisp_cp_lookup_error \ _(DROP, "drop") \ @@ -1713,6 +1831,7 @@ send_encapsulated_map_request (vlib_main_t * vm, lisp_cp_main_t *lcm, mapping_t * map; pending_map_request_t * pmr; ip_address_t mr_ip, sloc; + u32 ls_index; /* get locator-set for seid */ if (!lcm->lisp_pitr) @@ -1733,14 +1852,22 @@ send_encapsulated_map_request (vlib_main_t * vm, lisp_cp_main_t *lcm, format_gid_address, seid); return; } + ls_index = map->locator_set_index; } else { map_index = lcm->pitr_map_index; map = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index); + ls_index = map->locator_set_index; + } + + /* overwrite locator set if map-request itr-rlocs configured */ + if (~0 != lcm->mreq_itr_rlocs) + { + ls_index = lcm->mreq_itr_rlocs; } - loc_set = pool_elt_at_index (lcm->locator_set_pool, map->locator_set_index); + loc_set = pool_elt_at_index (lcm->locator_set_pool, ls_index); /* get local iface ip to use in map-request */ if (0 == get_mr_and_local_iface_ip (lcm, &mr_ip, &sloc)) @@ -2391,6 +2518,7 @@ lisp_cp_init (vlib_main_t *vm) lcm->im6 = &ip6_main; lcm->vlib_main = vm; lcm->vnet_main = vnet_get_main(); + lcm->mreq_itr_rlocs = ~0; gid_dictionary_init (&lcm->mapping_index_by_gid); diff --git a/vnet/vnet/lisp-cp/control.h b/vnet/vnet/lisp-cp/control.h index a81dd2846b4..53c14dd1e01 100644 --- a/vnet/vnet/lisp-cp/control.h +++ b/vnet/vnet/lisp-cp/control.h @@ -94,6 +94,9 @@ typedef struct /* vector of map-resolver addresses */ ip_address_t * map_resolvers; + /* map-request locator set index */ + u32 mreq_itr_rlocs; + /* Lookup vrf by vni */ uword * table_id_by_vni; @@ -186,6 +189,15 @@ vnet_lisp_add_del_remote_mapping (gid_address_t * deid, gid_address_t * seid, int vnet_lisp_pitr_set_locator_set (u8 * locator_set_name, u8 is_add); +typedef struct +{ + u8 is_add; + u8 * locator_set_name; +} vnet_lisp_add_del_mreq_itr_rloc_args_t; + +int +vnet_lisp_add_del_mreq_itr_rlocs (vnet_lisp_add_del_mreq_itr_rloc_args_t * a); + int vnet_lisp_clear_all_remote_mappings (void); #endif /* VNET_CONTROL_H_ */ diff --git a/vpp-api-test/vat/api_format.c b/vpp-api-test/vat/api_format.c index d4e53929bff..bfafc5bcac1 100644 --- a/vpp-api-test/vat/api_format.c +++ b/vpp-api-test/vat/api_format.c @@ -2194,6 +2194,45 @@ vl_api_lisp_enable_disable_status_details_t_handler_json vec_free (feature_status); } +static void +vl_api_lisp_get_map_request_itr_rlocs_reply_t_handler ( + vl_api_lisp_get_map_request_itr_rlocs_reply_t * mp) +{ + vat_main_t * vam = &vat_main; + i32 retval = ntohl(mp->retval); + + if (retval >= 0) { + fformat(vam->ofp, "%=20s\n", + mp->locator_set_name); + } + + vam->retval = retval; + vam->result_ready = 1; +} + +static void +vl_api_lisp_get_map_request_itr_rlocs_reply_t_handler_json ( + vl_api_lisp_get_map_request_itr_rlocs_reply_t * mp) +{ + vat_main_t * vam = &vat_main; + vat_json_node_t * node = NULL; + + 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_string_copy(node, "itr-rlocs", mp->locator_set_name); + + vat_json_print(vam->ofp, node); + vat_json_free(node); + + vam->retval = ntohl(mp->retval); + vam->result_ready = 1; +} + static u8 * format_policer_type (u8 * s, va_list * va) { u32 i = va_arg (*va, u32); @@ -2409,6 +2448,7 @@ _(lisp_gpe_enable_disable_reply) \ _(lisp_gpe_add_del_iface_reply) \ _(lisp_enable_disable_reply) \ _(lisp_pitr_set_locator_set_reply) \ +_(lisp_add_del_map_request_itr_rlocs_reply) \ _(vxlan_gpe_add_del_tunnel_reply) \ _(af_packet_delete_reply) \ _(policer_add_del_reply) \ @@ -2594,6 +2634,10 @@ _(LISP_GPE_TUNNEL_DETAILS, lisp_gpe_tunnel_details) \ _(LISP_MAP_RESOLVER_DETAILS, lisp_map_resolver_details) \ _(LISP_ENABLE_DISABLE_STATUS_DETAILS, \ lisp_enable_disable_status_details) \ +_(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY, \ + lisp_add_del_map_request_itr_rlocs_reply) \ +_(LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY, \ + lisp_get_map_request_itr_rlocs_reply) \ _(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \ _(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \ _(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \ @@ -10424,6 +10468,65 @@ api_lisp_gpe_add_del_iface(vat_main_t * vam) return 0; } +/** + * Add/del map request itr rlocs from LISP control plane and updates + * + * @param vam vpp API test context + * @return return code + */ +static int +api_lisp_add_del_map_request_itr_rlocs(vat_main_t * vam) +{ + unformat_input_t * input = vam->input; + vl_api_lisp_add_del_map_request_itr_rlocs_t *mp; + f64 timeout = ~0; + u8 *locator_set_name = 0; + u8 locator_set_name_set = 0; + u8 is_add = 1; + + /* 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, "%_%v%_", &locator_set_name)) { + locator_set_name_set = 1; + } else { + clib_warning ("parse error '%U'", format_unformat_error, input); + return -99; + } + } + + if (is_add && !locator_set_name_set) { + errmsg ("itr-rloc is not set!"); + return -99; + } + + if (is_add && vec_len(locator_set_name) > 64) { + errmsg ("itr-rloc locator-set name too long\n"); + vec_free(locator_set_name); + return -99; + } + + M(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, lisp_add_del_map_request_itr_rlocs); + mp->is_add = is_add; + if (is_add) { + clib_memcpy (mp->locator_set_name , locator_set_name, + vec_len(locator_set_name)); + } else { + memset(mp->locator_set_name, 0, sizeof(mp->locator_set_name)); + } + vec_free (locator_set_name); + + /* send it... */ + S; + + /* Wait for a reply... */ + W; + + /* NOTREACHED */ + return 0; +} + static int api_lisp_locator_set_dump(vat_main_t *vam) { @@ -10569,6 +10672,27 @@ api_lisp_enable_disable_status_dump(vat_main_t *vam) } static int +api_lisp_get_map_request_itr_rlocs(vat_main_t *vam) +{ + vl_api_lisp_get_map_request_itr_rlocs_t *mp; + f64 timeout = ~0; + + if (!vam->json_output) { + fformat(vam->ofp, "%=20s\n", + "itr-rlocs:"); + } + + M(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs); + /* send it... */ + S; + /* Wait for a reply... */ + W; + + /* NOTREACHED */ + return 0; +} + +static int api_af_packet_create (vat_main_t * vam) { unformat_input_t * i = vam->input; @@ -11322,11 +11446,13 @@ _(lisp_add_del_remote_mapping, "add|del vni <vni> table-id <id> " \ " <src-eid> rloc <locator> " \ "[rloc <loc> ... ]") \ _(lisp_pitr_set_locator_set, "locator-set <loc-set-name> | del") \ +_(lisp_add_del_map_request_itr_rlocs, "<loc-set-name> [del]") \ _(lisp_locator_set_dump, "") \ _(lisp_local_eid_table_dump, "") \ _(lisp_gpe_tunnel_dump, "") \ _(lisp_map_resolver_dump, "") \ _(lisp_enable_disable_status_dump, "") \ +_(lisp_get_map_request_itr_rlocs, "") \ _(af_packet_create, "name <host interface name> [hw_addr <mac>]") \ _(af_packet_delete, "name <host interface name>") \ _(policer_add_del, "name <policer name> <params> [del]") \ diff --git a/vpp/api/api.c b/vpp/api/api.c index 77635a9d1ff..f99d9ce28e3 100644 --- a/vpp/api/api.c +++ b/vpp/api/api.c @@ -340,6 +340,9 @@ _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump) \ _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \ _(LISP_ENABLE_DISABLE_STATUS_DUMP, \ lisp_enable_disable_status_dump) \ +_(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \ + lisp_add_del_map_request_itr_rlocs) \ +_(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs) \ _(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del) \ _(AF_PACKET_CREATE, af_packet_create) \ _(AF_PACKET_DELETE, af_packet_delete) \ @@ -4934,6 +4937,27 @@ vl_api_lisp_pitr_set_locator_set_t_handler( REPLY_MACRO(VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY); } +static void +vl_api_lisp_add_del_map_request_itr_rlocs_t_handler +(vl_api_lisp_add_del_map_request_itr_rlocs_t *mp) +{ + vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp; + int rv = 0; + u8 * locator_set_name = NULL; + vnet_lisp_add_del_mreq_itr_rloc_args_t _a, * a = &_a; + + locator_set_name = format (0, "%s", mp->locator_set_name); + + a->is_add = mp->is_add; + a->locator_set_name = locator_set_name; + + rv = vnet_lisp_add_del_mreq_itr_rlocs(a); + + vec_free(locator_set_name); + + REPLY_MACRO(VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY); +} + /** Used for transferring locators via VPP API */ typedef CLIB_PACKED(struct { @@ -5240,7 +5264,7 @@ send_lisp_map_resolver_details (ip_address_t *ip, static void vl_api_lisp_map_resolver_dump_t_handler ( - vl_api_lisp_local_eid_table_dump_t *mp) + vl_api_lisp_map_resolver_dump_t *mp) { unix_shared_memory_queue_t * q = NULL; lisp_cp_main_t * lcm = vnet_lisp_cp_get_main(); @@ -5289,6 +5313,38 @@ vl_api_lisp_enable_disable_status_dump_t_handler } static void +vl_api_lisp_get_map_request_itr_rlocs_t_handler ( + vl_api_lisp_get_map_request_itr_rlocs_t *mp) +{ + unix_shared_memory_queue_t * q = NULL; + vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL; + lisp_cp_main_t * lcm = vnet_lisp_cp_get_main(); + locator_set_t * loc_set = 0; + u8 * tmp_str = 0; + int rv = 0; + + q = vl_api_client_index_to_input_queue (mp->client_index); + if (q == 0) { + return; + } + + if (~0 == lcm->mreq_itr_rlocs) { + tmp_str = format(0, " "); + } else { + loc_set = pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs); + tmp_str = format(0, "%s", loc_set->name); + } + + REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY, + ({ + strncpy((char *) rmp->locator_set_name, (char *) tmp_str, + ARRAY_LEN(rmp->locator_set_name) - 1); + })); + + vec_free(tmp_str); +} + +static void vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *mp) { vl_api_interface_name_renumber_reply_t * rmp; diff --git a/vpp/api/vpe.api b/vpp/api/vpe.api index 71783a463b3..14664fdbb45 100644 --- a/vpp/api/vpe.api +++ b/vpp/api/vpe.api @@ -2404,6 +2404,29 @@ define lisp_add_del_remote_mapping_reply { i32 retval; }; +/** \brief add or delete map request itr rlocs + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param is_add - add address if non-zero, else delete + @param locator_set_name - locator set name +*/ +define lisp_add_del_map_request_itr_rlocs { + u32 client_index; + u32 context; + u8 is_add; + u8 locator_set_name[64]; +}; + +/** \brief Reply for lisp_add_del_map_request_itr_rlocs + @param context - returned sender context, to match reply w/ request + @param retval - return code +*/ + +define lisp_add_del_map_request_itr_rlocs_reply { + u32 context; + i32 retval; +}; + /** \brief LISP locator_set status @param locator_set_name - name of the locator_set @param sw_if_index - sw_if_index of the locator @@ -2519,6 +2542,23 @@ define lisp_enable_disable_status_dump { u32 context; }; +/** \brief Get LISP map request itr rlocs status + @param context - sender context, to match reply w/ request + @param locator_set_name - name of the locator_set + */ +define lisp_get_map_request_itr_rlocs { + u32 client_index; + u32 context; +}; + +/** \brief Request for map request itr rlocs summary status + */ +define lisp_get_map_request_itr_rlocs_reply { + u32 context; + i32 retval; + u8 locator_set_name[64]; +}; + /* Gross kludge, DGMS */ define interface_name_renumber { u32 client_index; |