Pavel Kotucek | abea966 | 2016-12-21 15:50:08 +0100 | [diff] [blame] | 1 | /* |
| 2 | *------------------------------------------------------------------ |
| 3 | * lisp_gpe_api.c - lisp_gpe api |
| 4 | * |
| 5 | * Copyright (c) 2016 Cisco and/or its affiliates. |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at: |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | *------------------------------------------------------------------ |
| 18 | */ |
| 19 | |
| 20 | #include <vnet/vnet.h> |
| 21 | #include <vlibmemory/api.h> |
| 22 | |
| 23 | #include <vnet/interface.h> |
| 24 | #include <vnet/api_errno.h> |
| 25 | #include <vnet/lisp-gpe/lisp_gpe.h> |
Filip Tehlar | 5fae99c | 2017-01-18 12:57:37 +0100 | [diff] [blame] | 26 | #include <vnet/lisp-gpe/lisp_gpe_adjacency.h> |
| 27 | #include <vnet/lisp-gpe/lisp_gpe_tunnel.h> |
Pavel Kotucek | abea966 | 2016-12-21 15:50:08 +0100 | [diff] [blame] | 28 | #include <vnet/lisp-gpe/lisp_gpe_fwd_entry.h> |
| 29 | #include <vnet/lisp-gpe/lisp_gpe_tenant.h> |
| 30 | |
| 31 | #include <vnet/vnet_msg_enum.h> |
| 32 | |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 33 | #define vl_api_gpe_locator_pair_t_endian vl_noop_handler |
| 34 | #define vl_api_gpe_locator_pair_t_print vl_noop_handler |
| 35 | #define vl_api_gpe_add_del_fwd_entry_t_endian vl_noop_handler |
| 36 | #define vl_api_gpe_add_del_fwd_entry_t_print vl_noop_handler |
Filip Tehlar | c3af7bf | 2017-01-13 14:13:09 +0100 | [diff] [blame] | 37 | |
Pavel Kotucek | abea966 | 2016-12-21 15:50:08 +0100 | [diff] [blame] | 38 | #define vl_typedefs /* define message structures */ |
| 39 | #include <vnet/vnet_all_api_h.h> |
| 40 | #undef vl_typedefs |
| 41 | |
| 42 | #define vl_endianfun /* define message structures */ |
| 43 | #include <vnet/vnet_all_api_h.h> |
| 44 | #undef vl_endianfun |
| 45 | |
| 46 | /* instantiate all the print functions we know about */ |
| 47 | #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) |
| 48 | #define vl_printfun |
| 49 | #include <vnet/vnet_all_api_h.h> |
| 50 | #undef vl_printfun |
| 51 | |
| 52 | #include <vlibapi/api_helper_macros.h> |
| 53 | |
| 54 | #define foreach_vpe_api_msg \ |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 55 | _(GPE_ADD_DEL_FWD_ENTRY, gpe_add_del_fwd_entry) \ |
| 56 | _(GPE_FWD_ENTRIES_GET, gpe_fwd_entries_get) \ |
| 57 | _(GPE_FWD_ENTRY_PATH_DUMP, gpe_fwd_entry_path_dump) \ |
| 58 | _(GPE_ENABLE_DISABLE, gpe_enable_disable) \ |
Filip Tehlar | 3e7b5693 | 2017-02-21 18:28:34 +0100 | [diff] [blame] | 59 | _(GPE_ADD_DEL_IFACE, gpe_add_del_iface) \ |
Filip Tehlar | 0eb874e | 2017-05-18 14:23:32 +0200 | [diff] [blame] | 60 | _(GPE_FWD_ENTRY_VNIS_GET, gpe_fwd_entry_vnis_get) \ |
Filip Tehlar | 3e7b5693 | 2017-02-21 18:28:34 +0100 | [diff] [blame] | 61 | _(GPE_SET_ENCAP_MODE, gpe_set_encap_mode) \ |
| 62 | _(GPE_GET_ENCAP_MODE, gpe_get_encap_mode) |
Pavel Kotucek | abea966 | 2016-12-21 15:50:08 +0100 | [diff] [blame] | 63 | |
| 64 | static locator_pair_t * |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 65 | unformat_gpe_loc_pairs (void *locs, u32 rloc_num) |
Pavel Kotucek | abea966 | 2016-12-21 15:50:08 +0100 | [diff] [blame] | 66 | { |
| 67 | u32 i; |
Filip Tehlar | c3af7bf | 2017-01-13 14:13:09 +0100 | [diff] [blame] | 68 | locator_pair_t *pairs = 0, pair, *p; |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 69 | vl_api_gpe_locator_t *r; |
Pavel Kotucek | abea966 | 2016-12-21 15:50:08 +0100 | [diff] [blame] | 70 | |
| 71 | for (i = 0; i < rloc_num; i++) |
| 72 | { |
| 73 | /* local locator */ |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 74 | r = &((vl_api_gpe_locator_t *) locs)[i]; |
Filip Tehlar | c3af7bf | 2017-01-13 14:13:09 +0100 | [diff] [blame] | 75 | memset (&pair, 0, sizeof (pair)); |
Pavel Kotucek | abea966 | 2016-12-21 15:50:08 +0100 | [diff] [blame] | 76 | ip_address_set (&pair.lcl_loc, &r->addr, r->is_ip4 ? IP4 : IP6); |
| 77 | |
Pavel Kotucek | abea966 | 2016-12-21 15:50:08 +0100 | [diff] [blame] | 78 | pair.weight = r->weight; |
Pavel Kotucek | abea966 | 2016-12-21 15:50:08 +0100 | [diff] [blame] | 79 | vec_add1 (pairs, pair); |
| 80 | } |
Filip Tehlar | c3af7bf | 2017-01-13 14:13:09 +0100 | [diff] [blame] | 81 | |
| 82 | for (i = rloc_num; i < rloc_num * 2; i++) |
| 83 | { |
| 84 | /* remote locators */ |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 85 | r = &((vl_api_gpe_locator_t *) locs)[i]; |
Filip Tehlar | c3af7bf | 2017-01-13 14:13:09 +0100 | [diff] [blame] | 86 | p = &pairs[i - rloc_num]; |
| 87 | ip_address_set (&p->rmt_loc, &r->addr, r->is_ip4 ? IP4 : IP6); |
| 88 | } |
Pavel Kotucek | abea966 | 2016-12-21 15:50:08 +0100 | [diff] [blame] | 89 | return pairs; |
| 90 | } |
| 91 | |
| 92 | static int |
| 93 | unformat_lisp_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src, |
| 94 | u8 len) |
| 95 | { |
| 96 | switch (type) |
| 97 | { |
| 98 | case 0: /* ipv4 */ |
| 99 | gid_address_type (dst) = GID_ADDR_IP_PREFIX; |
| 100 | gid_address_ip_set (dst, src, IP4); |
| 101 | gid_address_ippref_len (dst) = len; |
| 102 | ip_prefix_normalize (&gid_address_ippref (dst)); |
| 103 | break; |
| 104 | case 1: /* ipv6 */ |
| 105 | gid_address_type (dst) = GID_ADDR_IP_PREFIX; |
| 106 | gid_address_ip_set (dst, src, IP6); |
| 107 | gid_address_ippref_len (dst) = len; |
| 108 | ip_prefix_normalize (&gid_address_ippref (dst)); |
| 109 | break; |
| 110 | case 2: /* l2 mac */ |
| 111 | gid_address_type (dst) = GID_ADDR_MAC; |
| 112 | clib_memcpy (&gid_address_mac (dst), src, 6); |
| 113 | break; |
| 114 | default: |
| 115 | /* unknown type */ |
| 116 | return VNET_API_ERROR_INVALID_VALUE; |
| 117 | } |
| 118 | |
| 119 | gid_address_vni (dst) = vni; |
| 120 | |
| 121 | return 0; |
| 122 | } |
| 123 | |
| 124 | static void |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 125 | gpe_fwd_entry_path_dump_t_net_to_host |
| 126 | (vl_api_gpe_fwd_entry_path_dump_t * mp) |
Filip Tehlar | 5fae99c | 2017-01-18 12:57:37 +0100 | [diff] [blame] | 127 | { |
| 128 | mp->fwd_entry_index = clib_net_to_host_u32 (mp->fwd_entry_index); |
| 129 | } |
| 130 | |
| 131 | static void |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 132 | lisp_api_set_locator (vl_api_gpe_locator_t * loc, |
Filip Tehlar | 5fae99c | 2017-01-18 12:57:37 +0100 | [diff] [blame] | 133 | const ip_address_t * addr, u8 weight) |
| 134 | { |
| 135 | loc->weight = weight; |
| 136 | if (IP4 == ip_addr_version (addr)) |
| 137 | { |
| 138 | loc->is_ip4 = 1; |
| 139 | memcpy (loc->addr, addr, 4); |
| 140 | } |
| 141 | else |
| 142 | { |
| 143 | loc->is_ip4 = 0; |
| 144 | memcpy (loc->addr, addr, 16); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | static void |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 149 | vl_api_gpe_fwd_entry_path_dump_t_handler |
| 150 | (vl_api_gpe_fwd_entry_path_dump_t * mp) |
Filip Tehlar | 5fae99c | 2017-01-18 12:57:37 +0100 | [diff] [blame] | 151 | { |
| 152 | lisp_fwd_path_t *path; |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 153 | vl_api_gpe_fwd_entry_path_details_t *rmp = NULL; |
Filip Tehlar | 5fae99c | 2017-01-18 12:57:37 +0100 | [diff] [blame] | 154 | lisp_gpe_main_t *lgm = &lisp_gpe_main; |
| 155 | unix_shared_memory_queue_t *q = NULL; |
| 156 | lisp_gpe_fwd_entry_t *lfe; |
| 157 | |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 158 | gpe_fwd_entry_path_dump_t_net_to_host (mp); |
Filip Tehlar | 5fae99c | 2017-01-18 12:57:37 +0100 | [diff] [blame] | 159 | |
| 160 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 161 | if (q == 0) |
| 162 | return; |
| 163 | |
| 164 | if (pool_is_free_index (lgm->lisp_fwd_entry_pool, mp->fwd_entry_index)) |
| 165 | return; |
| 166 | |
| 167 | lfe = pool_elt_at_index (lgm->lisp_fwd_entry_pool, mp->fwd_entry_index); |
| 168 | |
| 169 | if (LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE == lfe->type) |
| 170 | return; |
| 171 | |
| 172 | vec_foreach (path, lfe->paths) |
| 173 | { |
| 174 | rmp = vl_msg_api_alloc (sizeof (*rmp)); |
| 175 | memset (rmp, 0, sizeof (*rmp)); |
| 176 | const lisp_gpe_tunnel_t *lgt; |
| 177 | |
| 178 | rmp->_vl_msg_id = |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 179 | clib_host_to_net_u16 (VL_API_GPE_FWD_ENTRY_PATH_DETAILS); |
Filip Tehlar | 5fae99c | 2017-01-18 12:57:37 +0100 | [diff] [blame] | 180 | |
| 181 | const lisp_gpe_adjacency_t *ladj = |
| 182 | lisp_gpe_adjacency_get (path->lisp_adj); |
| 183 | lisp_api_set_locator (&rmp->rmt_loc, &ladj->remote_rloc, path->weight); |
| 184 | lgt = lisp_gpe_tunnel_get (ladj->tunnel_index); |
| 185 | lisp_api_set_locator (&rmp->lcl_loc, &lgt->key->lcl, path->weight); |
| 186 | |
| 187 | rmp->context = mp->context; |
| 188 | vl_msg_api_send_shmem (q, (u8 *) & rmp); |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | static void |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 193 | gpe_fwd_entries_copy (vl_api_gpe_fwd_entry_t * dst, |
| 194 | lisp_api_gpe_fwd_entry_t * src) |
Filip Tehlar | 5fae99c | 2017-01-18 12:57:37 +0100 | [diff] [blame] | 195 | { |
| 196 | lisp_api_gpe_fwd_entry_t *e; |
| 197 | u32 i = 0; |
| 198 | |
| 199 | vec_foreach (e, src) |
| 200 | { |
| 201 | memset (dst, 0, sizeof (*dst)); |
| 202 | dst[i].dp_table = src->dp_table; |
| 203 | dst[i].fwd_entry_index = src->fwd_entry_index; |
Filip Tehlar | 0eb874e | 2017-05-18 14:23:32 +0200 | [diff] [blame] | 204 | dst[i].vni = src->vni; |
| 205 | dst[i].action = src->action; |
Filip Tehlar | 5fae99c | 2017-01-18 12:57:37 +0100 | [diff] [blame] | 206 | switch (fid_addr_type (&e->leid)) |
| 207 | { |
| 208 | case FID_ADDR_IP_PREF: |
| 209 | if (IP4 == ip_prefix_version (&fid_addr_ippref (&e->leid))) |
| 210 | { |
| 211 | memcpy (&dst[i].leid, &fid_addr_ippref (&e->leid), 4); |
| 212 | memcpy (&dst[i].reid, &fid_addr_ippref (&e->reid), 4); |
| 213 | dst[i].eid_type = 0; |
| 214 | } |
| 215 | else |
| 216 | { |
| 217 | memcpy (&dst[i].leid, &fid_addr_ippref (&e->leid), 16); |
| 218 | memcpy (&dst[i].reid, &fid_addr_ippref (&e->reid), 16); |
| 219 | dst[i].eid_type = 1; |
| 220 | } |
| 221 | dst[i].leid_prefix_len = ip_prefix_len (&fid_addr_ippref (&e->leid)); |
| 222 | dst[i].reid_prefix_len = ip_prefix_len (&fid_addr_ippref (&e->reid)); |
| 223 | break; |
| 224 | case FID_ADDR_MAC: |
| 225 | memcpy (&dst[i].leid, fid_addr_mac (&e->leid), 6); |
| 226 | memcpy (&dst[i].reid, fid_addr_mac (&e->reid), 6); |
| 227 | dst[i].eid_type = 2; |
| 228 | break; |
| 229 | default: |
| 230 | clib_warning ("unknown fid type %d!", fid_addr_type (&e->leid)); |
| 231 | break; |
| 232 | } |
| 233 | i++; |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | static void |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 238 | gpe_fwd_entries_get_t_net_to_host (vl_api_gpe_fwd_entries_get_t * mp) |
Filip Tehlar | 5fae99c | 2017-01-18 12:57:37 +0100 | [diff] [blame] | 239 | { |
| 240 | mp->vni = clib_net_to_host_u32 (mp->vni); |
| 241 | } |
| 242 | |
| 243 | static void |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 244 | gpe_entry_t_host_to_net (vl_api_gpe_fwd_entry_t * e) |
Filip Tehlar | 5fae99c | 2017-01-18 12:57:37 +0100 | [diff] [blame] | 245 | { |
| 246 | e->fwd_entry_index = clib_host_to_net_u32 (e->fwd_entry_index); |
| 247 | e->dp_table = clib_host_to_net_u32 (e->dp_table); |
Filip Tehlar | 0eb874e | 2017-05-18 14:23:32 +0200 | [diff] [blame] | 248 | e->vni = clib_host_to_net_u32 (e->vni); |
Filip Tehlar | 5fae99c | 2017-01-18 12:57:37 +0100 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | static void |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 252 | gpe_fwd_entries_get_reply_t_host_to_net |
| 253 | (vl_api_gpe_fwd_entries_get_reply_t * mp) |
Filip Tehlar | 5fae99c | 2017-01-18 12:57:37 +0100 | [diff] [blame] | 254 | { |
| 255 | u32 i; |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 256 | vl_api_gpe_fwd_entry_t *e; |
Filip Tehlar | 5fae99c | 2017-01-18 12:57:37 +0100 | [diff] [blame] | 257 | |
| 258 | for (i = 0; i < mp->count; i++) |
| 259 | { |
| 260 | e = &mp->entries[i]; |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 261 | gpe_entry_t_host_to_net (e); |
Filip Tehlar | 5fae99c | 2017-01-18 12:57:37 +0100 | [diff] [blame] | 262 | } |
| 263 | mp->count = clib_host_to_net_u32 (mp->count); |
| 264 | } |
| 265 | |
| 266 | static void |
Filip Tehlar | 0eb874e | 2017-05-18 14:23:32 +0200 | [diff] [blame] | 267 | vl_api_gpe_fwd_entry_vnis_get_t_handler (vl_api_gpe_fwd_entry_vnis_get_t * mp) |
| 268 | { |
| 269 | vl_api_gpe_fwd_entry_vnis_get_reply_t *rmp = 0; |
| 270 | hash_pair_t *p; |
| 271 | u32 i = 0; |
| 272 | int rv = 0; |
| 273 | |
| 274 | u32 *vnis = vnet_lisp_gpe_get_fwd_entry_vnis (); |
| 275 | u32 size = hash_elts (vnis) * sizeof (u32); |
| 276 | |
| 277 | /* *INDENT-OFF* */ |
| 278 | REPLY_MACRO4 (VL_API_GPE_FWD_ENTRY_VNIS_GET_REPLY, size, |
| 279 | { |
| 280 | rmp->count = clib_host_to_net_u32 (hash_elts (vnis)); |
| 281 | hash_foreach_pair (p, vnis, |
| 282 | ({ |
| 283 | rmp->vnis[i++] = clib_host_to_net_u32 (p->key); |
| 284 | })); |
| 285 | }); |
| 286 | /* *INDENT-ON* */ |
| 287 | |
| 288 | hash_free (vnis); |
| 289 | } |
| 290 | |
| 291 | static void |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 292 | vl_api_gpe_fwd_entries_get_t_handler (vl_api_gpe_fwd_entries_get_t * mp) |
Filip Tehlar | 5fae99c | 2017-01-18 12:57:37 +0100 | [diff] [blame] | 293 | { |
| 294 | lisp_api_gpe_fwd_entry_t *e; |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 295 | vl_api_gpe_fwd_entries_get_reply_t *rmp = 0; |
Filip Tehlar | 5fae99c | 2017-01-18 12:57:37 +0100 | [diff] [blame] | 296 | u32 size = 0; |
| 297 | int rv = 0; |
| 298 | |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 299 | gpe_fwd_entries_get_t_net_to_host (mp); |
Filip Tehlar | 5fae99c | 2017-01-18 12:57:37 +0100 | [diff] [blame] | 300 | |
| 301 | e = vnet_lisp_gpe_fwd_entries_get_by_vni (mp->vni); |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 302 | size = vec_len (e) * sizeof (vl_api_gpe_fwd_entry_t); |
Filip Tehlar | 5fae99c | 2017-01-18 12:57:37 +0100 | [diff] [blame] | 303 | |
| 304 | /* *INDENT-OFF* */ |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 305 | REPLY_MACRO4 (VL_API_GPE_FWD_ENTRIES_GET_REPLY, size, |
Filip Tehlar | 5fae99c | 2017-01-18 12:57:37 +0100 | [diff] [blame] | 306 | { |
| 307 | rmp->count = vec_len (e); |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 308 | gpe_fwd_entries_copy (rmp->entries, e); |
| 309 | gpe_fwd_entries_get_reply_t_host_to_net (rmp); |
Filip Tehlar | 5fae99c | 2017-01-18 12:57:37 +0100 | [diff] [blame] | 310 | }); |
| 311 | /* *INDENT-ON* */ |
| 312 | |
| 313 | vec_free (e); |
| 314 | } |
| 315 | |
| 316 | static void |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 317 | gpe_add_del_fwd_entry_t_net_to_host (vl_api_gpe_add_del_fwd_entry_t * mp) |
Filip Tehlar | c3af7bf | 2017-01-13 14:13:09 +0100 | [diff] [blame] | 318 | { |
| 319 | mp->vni = clib_net_to_host_u32 (mp->vni); |
| 320 | mp->dp_table = clib_net_to_host_u32 (mp->dp_table); |
| 321 | mp->loc_num = clib_net_to_host_u32 (mp->loc_num); |
| 322 | } |
| 323 | |
| 324 | static void |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 325 | vl_api_gpe_add_del_fwd_entry_t_handler (vl_api_gpe_add_del_fwd_entry_t * mp) |
Pavel Kotucek | abea966 | 2016-12-21 15:50:08 +0100 | [diff] [blame] | 326 | { |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 327 | vl_api_gpe_add_del_fwd_entry_reply_t *rmp; |
Pavel Kotucek | abea966 | 2016-12-21 15:50:08 +0100 | [diff] [blame] | 328 | vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a; |
| 329 | locator_pair_t *pairs = 0; |
| 330 | int rv = 0; |
| 331 | |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 332 | gpe_add_del_fwd_entry_t_net_to_host (mp); |
Pavel Kotucek | abea966 | 2016-12-21 15:50:08 +0100 | [diff] [blame] | 333 | memset (a, 0, sizeof (a[0])); |
| 334 | |
| 335 | rv = unformat_lisp_eid_api (&a->rmt_eid, mp->vni, mp->eid_type, |
| 336 | mp->rmt_eid, mp->rmt_len); |
| 337 | rv |= unformat_lisp_eid_api (&a->lcl_eid, mp->vni, mp->eid_type, |
| 338 | mp->lcl_eid, mp->lcl_len); |
| 339 | |
Filip Tehlar | c3af7bf | 2017-01-13 14:13:09 +0100 | [diff] [blame] | 340 | if (mp->loc_num % 2 != 0) |
| 341 | { |
| 342 | rv = -1; |
| 343 | goto send_reply; |
| 344 | } |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 345 | pairs = unformat_gpe_loc_pairs (mp->locs, mp->loc_num / 2); |
Pavel Kotucek | abea966 | 2016-12-21 15:50:08 +0100 | [diff] [blame] | 346 | |
Filip Tehlar | 0eb874e | 2017-05-18 14:23:32 +0200 | [diff] [blame] | 347 | if (rv) |
Pavel Kotucek | abea966 | 2016-12-21 15:50:08 +0100 | [diff] [blame] | 348 | goto send_reply; |
| 349 | |
| 350 | a->is_add = mp->is_add; |
| 351 | a->locator_pairs = pairs; |
| 352 | a->dp_table = mp->dp_table; |
| 353 | a->vni = mp->vni; |
| 354 | a->action = mp->action; |
Filip Tehlar | 0eb874e | 2017-05-18 14:23:32 +0200 | [diff] [blame] | 355 | if (mp->loc_num == 0) |
| 356 | a->is_negative = 1; |
Pavel Kotucek | abea966 | 2016-12-21 15:50:08 +0100 | [diff] [blame] | 357 | |
| 358 | rv = vnet_lisp_gpe_add_del_fwd_entry (a, 0); |
| 359 | vec_free (pairs); |
| 360 | send_reply: |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 361 | REPLY_MACRO (VL_API_GPE_ADD_DEL_FWD_ENTRY_REPLY); |
Pavel Kotucek | abea966 | 2016-12-21 15:50:08 +0100 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | static void |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 365 | vl_api_gpe_enable_disable_t_handler (vl_api_gpe_enable_disable_t * mp) |
Pavel Kotucek | abea966 | 2016-12-21 15:50:08 +0100 | [diff] [blame] | 366 | { |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 367 | vl_api_gpe_enable_disable_reply_t *rmp; |
Pavel Kotucek | abea966 | 2016-12-21 15:50:08 +0100 | [diff] [blame] | 368 | int rv = 0; |
| 369 | vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a; |
| 370 | |
| 371 | a->is_en = mp->is_en; |
| 372 | vnet_lisp_gpe_enable_disable (a); |
| 373 | |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 374 | REPLY_MACRO (VL_API_GPE_ENABLE_DISABLE_REPLY); |
Pavel Kotucek | abea966 | 2016-12-21 15:50:08 +0100 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | static void |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 378 | vl_api_gpe_add_del_iface_t_handler (vl_api_gpe_add_del_iface_t * mp) |
Pavel Kotucek | abea966 | 2016-12-21 15:50:08 +0100 | [diff] [blame] | 379 | { |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 380 | vl_api_gpe_add_del_iface_reply_t *rmp; |
Pavel Kotucek | abea966 | 2016-12-21 15:50:08 +0100 | [diff] [blame] | 381 | int rv = 0; |
| 382 | |
| 383 | if (mp->is_l2) |
| 384 | { |
| 385 | if (mp->is_add) |
| 386 | { |
| 387 | if (~0 == |
| 388 | lisp_gpe_tenant_l2_iface_add_or_lock (mp->vni, mp->dp_table)) |
| 389 | rv = 1; |
| 390 | } |
| 391 | else |
| 392 | lisp_gpe_tenant_l2_iface_unlock (mp->vni); |
| 393 | } |
| 394 | else |
| 395 | { |
| 396 | if (mp->is_add) |
| 397 | { |
| 398 | if (~0 == |
| 399 | lisp_gpe_tenant_l3_iface_add_or_lock (mp->vni, mp->dp_table)) |
| 400 | rv = 1; |
| 401 | } |
| 402 | else |
| 403 | lisp_gpe_tenant_l3_iface_unlock (mp->vni); |
| 404 | } |
| 405 | |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 406 | REPLY_MACRO (VL_API_GPE_ADD_DEL_IFACE_REPLY); |
Pavel Kotucek | abea966 | 2016-12-21 15:50:08 +0100 | [diff] [blame] | 407 | } |
| 408 | |
Filip Tehlar | 3e7b5693 | 2017-02-21 18:28:34 +0100 | [diff] [blame] | 409 | static void |
| 410 | vl_api_gpe_set_encap_mode_t_handler (vl_api_gpe_set_encap_mode_t * mp) |
| 411 | { |
| 412 | vl_api_gpe_set_encap_mode_reply_t *rmp; |
| 413 | int rv = 0; |
| 414 | |
| 415 | rv = vnet_gpe_set_encap_mode (mp->mode); |
| 416 | REPLY_MACRO (VL_API_GPE_SET_ENCAP_MODE_REPLY); |
| 417 | } |
| 418 | |
| 419 | static void |
| 420 | vl_api_gpe_get_encap_mode_t_handler (vl_api_gpe_get_encap_mode_t * mp) |
| 421 | { |
| 422 | vl_api_gpe_get_encap_mode_reply_t *rmp; |
| 423 | int rv = 0; |
| 424 | |
| 425 | /* *INDENT-OFF* */ |
| 426 | REPLY_MACRO2 (VL_API_GPE_GET_ENCAP_MODE_REPLY, |
| 427 | ({ |
| 428 | rmp->encap_mode = vnet_gpe_get_encap_mode (); |
| 429 | })); |
| 430 | /* *INDENT-ON* */ |
| 431 | } |
| 432 | |
Pavel Kotucek | abea966 | 2016-12-21 15:50:08 +0100 | [diff] [blame] | 433 | /* |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 434 | * gpe_api_hookup |
Pavel Kotucek | abea966 | 2016-12-21 15:50:08 +0100 | [diff] [blame] | 435 | * Add vpe's API message handlers to the table. |
| 436 | * vlib has alread mapped shared memory and |
| 437 | * added the client registration handlers. |
| 438 | * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process() |
| 439 | */ |
| 440 | #define vl_msg_name_crc_list |
| 441 | #include <vnet/vnet_all_api_h.h> |
| 442 | #undef vl_msg_name_crc_list |
| 443 | |
| 444 | static void |
| 445 | setup_message_id_table (api_main_t * am) |
| 446 | { |
| 447 | #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id); |
| 448 | foreach_vl_msg_name_crc_lisp_gpe; |
| 449 | #undef _ |
| 450 | } |
| 451 | |
| 452 | static clib_error_t * |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 453 | gpe_api_hookup (vlib_main_t * vm) |
Pavel Kotucek | abea966 | 2016-12-21 15:50:08 +0100 | [diff] [blame] | 454 | { |
| 455 | api_main_t *am = &api_main; |
| 456 | |
| 457 | #define _(N,n) \ |
| 458 | vl_msg_api_set_handlers(VL_API_##N, #n, \ |
| 459 | vl_api_##n##_t_handler, \ |
| 460 | vl_noop_handler, \ |
| 461 | vl_api_##n##_t_endian, \ |
| 462 | vl_api_##n##_t_print, \ |
| 463 | sizeof(vl_api_##n##_t), 1); |
| 464 | foreach_vpe_api_msg; |
| 465 | #undef _ |
| 466 | |
| 467 | /* |
| 468 | * Set up the (msg_name, crc, message-id) table |
| 469 | */ |
| 470 | setup_message_id_table (am); |
| 471 | |
| 472 | return 0; |
| 473 | } |
| 474 | |
Filip Tehlar | 82786c4 | 2017-02-20 15:20:37 +0100 | [diff] [blame] | 475 | VLIB_API_INIT_FUNCTION (gpe_api_hookup); |
Pavel Kotucek | abea966 | 2016-12-21 15:50:08 +0100 | [diff] [blame] | 476 | |
| 477 | /* |
| 478 | * fd.io coding-style-patch-verification: ON |
| 479 | * |
| 480 | * Local Variables: |
| 481 | * eval: (c-set-style "gnu") |
| 482 | * End: |
| 483 | */ |