/* *------------------------------------------------------------------ * lisp_gpe_api.c - lisp_gpe api * * Copyright (c) 2016 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *------------------------------------------------------------------ */ #include #include #include #include #include #include #include #include #include #include #include #define vl_api_gpe_locator_pair_t_endian vl_noop_handler #define vl_api_gpe_locator_pair_t_print vl_noop_handler #define vl_api_gpe_add_del_fwd_entry_t_endian vl_noop_handler #define vl_api_gpe_add_del_fwd_entry_t_print vl_noop_handler #define vl_typedefs /* define message structures */ #include #undef vl_typedefs #define vl_endianfun /* define message structures */ #include #undef vl_endianfun /* instantiate all the print functions we know about */ #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) #define vl_printfun #include #undef vl_printfun #include #define foreach_vpe_api_msg \ _(GPE_ADD_DEL_FWD_ENTRY, gpe_add_del_fwd_entry) \ _(GPE_FWD_ENTRIES_GET, gpe_fwd_entries_get) \ _(GPE_FWD_ENTRY_PATH_DUMP, gpe_fwd_entry_path_dump) \ _(GPE_ENABLE_DISABLE, gpe_enable_disable) \ _(GPE_ADD_DEL_IFACE, gpe_add_del_iface) \ _(GPE_FWD_ENTRY_VNIS_GET, gpe_fwd_entry_vnis_get) \ _(GPE_SET_ENCAP_MODE, gpe_set_encap_mode) \ _(GPE_GET_ENCAP_MODE, gpe_get_encap_mode) \ _(GPE_ADD_DEL_NATIVE_FWD_RPATH, gpe_add_del_native_fwd_rpath) \ _(GPE_NATIVE_FWD_RPATHS_GET, gpe_native_fwd_rpaths_get) static locator_pair_t * unformat_gpe_loc_pairs (void *locs, u32 rloc_num) { u32 i; locator_pair_t *pairs = 0, pair, *p; vl_api_gpe_locator_t *r; for (i = 0; i < rloc_num; i++) { /* local locator */ r = &((vl_api_gpe_locator_t *) locs)[i]; memset (&pair, 0, sizeof (pair)); ip_address_set (&pair.lcl_loc, &r->addr, r->is_ip4 ? IP4 : IP6); pair.weight = r->weight; vec_add1 (pairs, pair); } for (i = rloc_num; i < rloc_num * 2; i++) { /* remote locators */ r = &((vl_api_gpe_locator_t *) locs)[i]; p = &pairs[i - rloc_num]; ip_address_set (&p->rmt_loc, &r->addr, r->is_ip4 ? IP4 : IP6); } return pairs; } static int unformat_lisp_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src, u8 len) { switch (type) { case 0: /* ipv4 */ gid_address_type (dst) = GID_ADDR_IP_PREFIX; gid_address_ip_set (dst, src, IP4); gid_address_ippref_len (dst) = len; ip_prefix_normalize (&gid_address_ippref (dst)); break; case 1: /* ipv6 */ gid_address_type (dst) = GID_ADDR_IP_PREFIX; gid_address_ip_set (dst, src, IP6); gid_address_ippref_len (dst) = len; ip_prefix_normalize (&gid_address_ippref (dst)); break; case 2: /* l2 mac */ gid_address_type (dst) = GID_ADDR_MAC; clib_memcpy (&gid_address_mac (dst), src, 6); break; default: /* unknown type */ return VNET_API_ERROR_INVALID_VALUE; } gid_address_vni (dst) = vni; return 0; } static void gpe_fwd_entry_path_dump_t_net_to_host (vl_api_gpe_fwd_entry_path_dump_t * mp) { mp->fwd_entry_index = clib_net_to_host_u32 (mp->fwd_entry_index); } static void lisp_api_set_locator (vl_api_gpe_locator_t * loc, const ip_address_t * addr, u8 weight) { loc->weight = weight; if (IP4 == ip_addr_version (addr)) { loc->is_ip4 = 1; memcpy (loc->addr, addr, 4); } else { loc->is_ip4 = 0; memcpy (loc->addr, addr, 16); } } static void vl_api_gpe_fwd_entry_path_dump_t_handler (vl_api_gpe_fwd_entry_path_dump_t * mp) { lisp_fwd_path_t *path; vl_api_gpe_fwd_entry_path_details_t *rmp = NULL; lisp_gpe_main_t *lgm = &lisp_gpe_main; vl_api_registration_t *reg; lisp_gpe_fwd_entry_t *lfe; gpe_fwd_entry_path_dump_t_net_to_host (mp); reg = vl_api_client_index_to_registration (mp->client_index); if (!reg) return; if (pool_is_free_index (lgm->lisp_fwd_entry_pool, mp->fwd_entry_index)) return; lfe = pool_elt_at_index (lgm->lisp_fwd_entry_pool, mp->fwd_entry_index); if (LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE == lfe->type) return; vec_foreach (path, lfe->paths) { rmp = vl_msg_api_alloc (sizeof (*rmp)); memset (rmp, 0, sizeof (*rmp)); const lisp_gpe_tunnel_t *lgt; rmp->_vl_msg_id = clib_host_to_net_u16 (VL_API_GPE_FWD_ENTRY_PATH_DETAILS); const lisp_gpe_adjacency_t *ladj = lisp_gpe_adjacency_get (path->lisp_adj); lisp_api_set_locator (&rmp->rmt_loc, &ladj->remote_rloc, path->weight); lgt = lisp_gpe_tunnel_get (ladj->tunnel_index); lisp_api_set_locator (&rmp->lcl_loc, &lgt->key->lcl, path->weight); rmp->context = mp->context; vl_api_send_msg (reg, (u8 *) rmp); } } static void gpe_fwd_entries_copy (vl_api_gpe_fwd_entry_t * dst, lisp_api_gpe_fwd_entry_t * src) { lisp_api_gpe_fwd_entry_t *e; u32 i = 0; vec_foreach (e, src) { memset (&dst[i], 0, sizeof (*dst)); dst[i].dp_table = e->dp_table; dst[i].fwd_entry_index = e->fwd_entry_index; dst[i].vni = e->vni; dst[i].action = e->action; switch (fid_addr_type (&e->leid)) { case FID_ADDR_IP_PREF: if (IP4 == ip_prefix_version (&fid_addr_ippref (&e->leid))) { memcpy (&dst[i].leid, &fid_addr_ippref (&e->leid), 4); memcpy (&dst[i].reid, &fid_addr_ippref (&e->reid), 4); dst[i].eid_type = 0; } else { memcpy (&dst[i].leid, &fid_addr_ippref (&e->leid), 16); memcpy (&dst[i].reid, &fid_addr_ippref (&e->reid), 16); dst[i].eid_type = 1; } dst[i].leid_prefix_len = ip_prefix_len (&fid_addr_ippref (&e->leid)); dst[i].reid_prefix_len = ip_prefix_len (&fid_addr_ippref (&e->reid)); break; case FID_ADDR_MAC: memcpy (&dst[i].leid, fid_addr_mac (&e->leid), 6); memcpy (&dst[i].reid, fid_addr_mac (&e->reid), 6); dst[i].eid_type = 2; break; default: clib_warning ("unknown fid type %d!", fid_addr_type (&e->leid)); break; } i++; } } static void gpe_fwd_e
;;; plugin-api-skel.el - vpp engine plug-