2 * Copyright (c) 2016 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #include <vnet/lisp-cp/control.h>
17 #include <vnet/lisp-cp/packets.h>
18 #include <vnet/lisp-cp/lisp_msg_serdes.h>
19 #include <vnet/lisp-gpe/lisp_gpe.h>
21 /* Stores mapping in map-cache. It does NOT program data plane forwarding for
22 * remote/learned mappings. */
24 vnet_lisp_add_del_mapping (vnet_lisp_add_del_mapping_args_t * a,
25 u32 * map_index_result)
27 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
28 u32 mi, * map_indexp, map_index, i;
32 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &a->deid);
35 /* TODO check if overwriting and take appropriate actions */
36 if (mi != GID_LOOKUP_MISS)
38 clib_warning("eid %U found in the eid-table", format_ip_address,
40 return VNET_API_ERROR_VALUE_EXIST;
43 pool_get(lcm->mapping_pool, m);
45 m->locator_set_index = a->locator_set_index;
49 map_index = m - lcm->mapping_pool;
50 gid_dictionary_add_del (&lcm->mapping_index_by_gid, &a->deid, map_index,
53 if (pool_is_free_index(lcm->locator_set_pool, a->locator_set_index))
55 clib_warning("Locator set with index %d doesn't exist",
56 a->locator_set_index);
57 return VNET_API_ERROR_INVALID_VALUE;
60 /* add eid to list of eids supported by locator-set */
61 vec_validate (lcm->locator_set_to_eids, a->locator_set_index);
62 eid_indexes = vec_elt_at_index(lcm->locator_set_to_eids,
63 a->locator_set_index);
64 vec_add1(eid_indexes[0], map_index);
69 vec_add1(lcm->local_mappings_indexes, map_index);
71 map_index_result[0] = map_index;
75 if (mi == GID_LOOKUP_MISS)
77 clib_warning("eid %U not found in the eid-table", format_ip_address,
79 return VNET_API_ERROR_INVALID_VALUE;
82 /* clear locator-set to eids binding */
83 eid_indexes = vec_elt_at_index(lcm->locator_set_to_eids,
84 a->locator_set_index);
85 for (i = 0; i < vec_len(eid_indexes[0]); i++)
87 map_indexp = vec_elt_at_index(eid_indexes[0], i);
88 if (map_indexp[0] == mi)
91 vec_del1(eid_indexes[0], i);
93 /* remove local mark if needed */
94 m = pool_elt_at_index(lcm->mapping_pool, mi);
98 for (k = 0; k < vec_len(lcm->local_mappings_indexes); k++)
100 lm_indexp = vec_elt_at_index(lcm->local_mappings_indexes, k);
101 if (lm_indexp[0] == mi)
104 vec_del1(lcm->local_mappings_indexes, k);
108 /* remove tunnel ??? */
111 /* remove mapping from dictionary */
112 gid_dictionary_add_del (&lcm->mapping_index_by_gid, &a->deid, 0, 0);
113 pool_put_index (lcm->mapping_pool, mi);
119 /* Stores mapping in map-cache and programs data plane for local mappings. */
121 vnet_lisp_add_del_local_mapping (vnet_lisp_add_del_mapping_args_t * a,
122 u32 * map_index_result)
124 uword * table_id, * refc;
126 vnet_lisp_gpe_add_del_iface_args_t _ai, *ai = &_ai;
127 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main ();
129 /* store/remove mapping from map-cache */
130 rv = vnet_lisp_add_del_mapping (a, map_index_result);
134 table_id = hash_get(lcm->table_id_by_vni, /* default for now */ 0);
138 clib_warning ("vni %d not associated to a vrf!", 0);
139 return VNET_API_ERROR_INVALID_VALUE;
142 refc = hash_get(lcm->dp_if_refcount_by_vni, 0);
144 /* enable/disable data-plane interface */
147 /* create interface or update refcount */
151 ai->vni = 0; /* default for now, pass vni as parameter */
152 ai->table_id = table_id[0];
153 vnet_lisp_gpe_add_del_iface (ai, 0);
155 hash_set(lcm->dp_if_refcount_by_vni, 0 /* table_id */, 1);
164 /* since this is a remove for an existing eid, the iface should exist */
168 /* remove iface if needed */
172 ai->vni = 0; /* default for now, pass vni as parameter */
173 ai->table_id = table_id[0];
174 vnet_lisp_gpe_add_del_iface (ai, 0);
181 static clib_error_t *
182 lisp_add_del_local_eid_command_fn (vlib_main_t * vm, unformat_input_t * input,
183 vlib_cli_command_t * cmd)
185 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
186 unformat_input_t _line_input, * line_input = &_line_input;
189 ip_prefix_t * prefp = &gid_address_ippref(&eid);
190 gid_address_t * eids = 0;
191 clib_error_t * error = 0;
192 u8 * locator_set_name;
193 u32 locator_set_index = 0, map_index = 0;
195 vnet_lisp_add_del_mapping_args_t _a, * a = &_a;
197 gid_address_type (&eid) = GID_ADDR_IP_PREFIX;
199 /* Get a line of input. */
200 if (! unformat_user (input, unformat_line_input, line_input))
203 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
205 if (unformat (line_input, "add"))
207 else if (unformat (line_input, "del"))
209 else if (unformat (line_input, "eid %U", unformat_ip_prefix, prefp))
213 else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name))
215 p = hash_get_mem(lcm->locator_set_index_by_name, locator_set_name);
218 error = clib_error_return(0, "locator-set %s doesn't exist",
222 locator_set_index = p[0];
226 error = unformat_parse_error(line_input);
231 /* XXX treat batch configuration */
234 a->locator_set_index = locator_set_index;
237 vnet_lisp_add_del_local_mapping (a, &map_index);
243 VLIB_CLI_COMMAND (lisp_add_del_local_eid_command) = {
244 .path = "lisp eid-table",
245 .short_help = "lisp eid-table add/del eid <eid> locator-set <locator-set>",
246 .function = lisp_add_del_local_eid_command_fn,
249 static clib_error_t *
250 lisp_show_local_eid_table_command_fn (vlib_main_t * vm,
251 unformat_input_t * input,
252 vlib_cli_command_t * cmd)
254 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
257 vlib_cli_output (vm, "%=20s%=16s", "EID", "Locator");
258 pool_foreach (mapit, lcm->mapping_pool,
261 locator_set_t * ls = pool_elt_at_index (lcm->locator_set_pool,
262 mapit->locator_set_index);
263 vlib_cli_output (vm, "%-16U%16v", format_gid_address, &mapit->eid,
271 VLIB_CLI_COMMAND (lisp_cp_show_local_eid_table_command) = {
272 .path = "show lisp eid-table",
273 .short_help = "Shows local EID table",
274 .function = lisp_show_local_eid_table_command_fn,
277 /* cleans locator to locator-set data and removes locators not part of
280 clean_locator_to_locator_set (lisp_cp_main_t * lcm, u32 lsi)
282 u32 i, j, *loc_indexp, *ls_indexp, **ls_indexes;
283 locator_set_t * ls = pool_elt_at_index(lcm->locator_set_pool, lsi);
284 for (i = 0; i < vec_len(ls->locator_indices); i++)
286 loc_indexp = vec_elt_at_index(ls->locator_indices, i);
287 ls_indexes = vec_elt_at_index(lcm->locator_to_locator_sets,
289 for (j = 0; j < vec_len(ls_indexes[0]); j++)
291 ls_indexp = vec_elt_at_index(ls_indexes[0], j);
292 if (ls_indexp[0] == lsi)
296 /* delete index for removed locator-set*/
297 vec_del1(ls_indexes[0], j);
299 /* delete locator if it's part of no locator-set */
300 if (vec_len (ls_indexes[0]) == 0)
301 pool_put_index(lcm->locator_pool, loc_indexp[0]);
305 vnet_lisp_add_del_locator_set (vnet_lisp_add_del_locator_set_args_t * a,
308 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
310 locator_t * loc, * itloc;
311 uword _p = (u32)~0, * p = &_p;
312 u32 loc_index, ls_index, ** ls_indexes;
317 /* check if overwrite */
319 p = hash_get_mem(lcm->locator_set_index_by_name, a->name);
324 if (p && p[0] != (u32)~0)
326 ls = pool_elt_at_index(lcm->locator_set_pool, p[0]);
329 clib_warning("locator-set %d to be overwritten doesn't exist!",
334 /* clean locator to locator-set vectors and remove locators if
335 * they're not part of another locator-set */
336 clean_locator_to_locator_set (lcm, p[0]);
338 /* remove locator indices from locator set */
339 vec_free(ls->locator_indices);
346 /* new locator-set */
349 pool_get(lcm->locator_set_pool, ls);
350 ls_index = ls - lcm->locator_set_pool;
354 ls->name = vec_dup(a->name);
356 if (!lcm->locator_set_index_by_name)
357 lcm->locator_set_index_by_name = hash_create_vec(
358 /* size */0, sizeof(ls->name[0]), sizeof(uword));
359 hash_set_mem(lcm->locator_set_index_by_name, ls->name, ls_index);
361 /* mark as local locator-set */
362 vec_add1(lcm->local_locator_set_indexes, ls_index);
364 ls->local = a->local;
366 ls_result[0] = ls_index;
369 /* allocate locators */
370 vec_foreach (itloc, a->locators)
372 pool_get(lcm->locator_pool, loc);
374 loc_index = loc - lcm->locator_pool;
376 vec_add1(ls->locator_indices, loc_index);
378 vec_validate (lcm->locator_to_locator_sets, loc_index);
379 ls_indexes = vec_elt_at_index(lcm->locator_to_locator_sets,
381 vec_add1(ls_indexes[0], ls_index);
386 /* find locator-set */
389 p = hash_get_mem(lcm->locator_set_index_by_name, a->name);
392 clib_warning("locator-set %v doesn't exists", a->name);
399 ls = pool_elt_at_index(lcm->locator_set_pool, p[0]);
402 clib_warning("locator-set with index %d doesn't exists", p[0]);
405 // /* XXX what happens when a mapping is configured to use the loc-set ? */
406 // if (vec_len (vec_elt_at_index(lcm->locator_set_to_eids, p[0])) != 0)
408 // clib_warning ("Can't delete a locator that supports a mapping!");
412 if (vec_len(lcm->locator_set_to_eids) != 0)
414 eid_indexes = vec_elt_at_index(lcm->locator_set_to_eids, p[0]);
415 if (vec_len(eid_indexes[0]) != 0)
417 clib_warning ("Can't delete a locator that supports a mapping!");
422 /* clean locator to locator-sets data */
423 clean_locator_to_locator_set (lcm, p[0]);
429 vec_foreach_index(it, lcm->local_locator_set_indexes)
431 lsi = vec_elt(lcm->local_locator_set_indexes, it);
434 vec_del1(lcm->local_locator_set_indexes, it);
438 hash_unset_mem(lcm->locator_set_index_by_name, ls->name);
441 pool_put(lcm->locator_set_pool, ls);
447 uword *vnet_lisp_get_locator(vnet_lisp_add_del_locator_set_args_t * a,
450 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
455 /* find locator-set */
458 p = hash_get_mem(lcm->locator_set_index_by_name, a->name);
469 vnet_lisp_add_del_locator_set_name (vnet_lisp_add_del_locator_set_args_t * a,
472 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
474 uword _p = (u32)~0, * p = &_p;
476 u32 **eid_indexes = NULL;
479 ASSERT(ls_result != NULL);
481 p = vnet_lisp_get_locator(a, p);
486 if (p && p[0] != (u32)~0)
488 ls = pool_elt_at_index(lcm->locator_set_pool, p[0]);
491 clib_warning("locator-set %d to be overwritten doesn't exist!",
493 return VNET_API_ERROR_UNSPECIFIED;
496 /* clean locator to locator-set vectors and remove locators if
497 * they're not part of another locator-set */
498 clean_locator_to_locator_set (lcm, p[0]);
500 /* remove locator indices from locator set */
501 vec_free(ls->locator_indices);
508 /* new locator-set */
511 pool_get(lcm->locator_set_pool, ls);
512 ls_index = ls - lcm->locator_set_pool;
516 ls->name = vec_dup(a->name);
518 if (!lcm->locator_set_index_by_name)
519 lcm->locator_set_index_by_name = hash_create_vec(
520 /* size */0, sizeof(ls->name[0]), sizeof(uword));
521 hash_set_mem(lcm->locator_set_index_by_name, ls->name, ls_index);
523 /* mark as local locator-set */
524 vec_add1(lcm->local_locator_set_indexes, ls_index);
526 ls->local = a->local;
527 ls->locator_indices = NULL;
529 ls_result[0] = ls_index;
536 clib_warning("locator-set %v doesn't exists", a->name);
537 return VNET_API_ERROR_INVALID_ARGUMENT;
540 ls = pool_elt_at_index(lcm->locator_set_pool, p[0]);
543 clib_warning("locator-set with index %d doesn't exists", p[0]);
544 return VNET_API_ERROR_INVALID_ARGUMENT;
547 if (vec_len(lcm->locator_set_to_eids) != 0)
549 eid_indexes = vec_elt_at_index(lcm->locator_set_to_eids, p[0]);
550 if (vec_len(eid_indexes[0]) != 0)
552 clib_warning ("Can't delete a locator that supports a mapping!");
557 /* clean locator to locator-sets data */
558 clean_locator_to_locator_set (lcm, p[0]);
564 vec_foreach_index(it, lcm->local_locator_set_indexes)
566 lsi = vec_elt(lcm->local_locator_set_indexes, it);
569 vec_del1(lcm->local_locator_set_indexes, it);
573 hash_unset_mem(lcm->locator_set_index_by_name, ls->name);
576 pool_put(lcm->locator_set_pool, ls);
582 vnet_lisp_add_del_locator (vnet_lisp_add_del_locator_set_args_t *a,
585 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
586 locator_set_t *ls = NULL;
587 locator_t *loc = NULL, *itloc = NULL;
588 uword _p = (u32)~0, * p = &_p;
589 u32 loc_index = ~0, ls_index = ~0, *locit = NULL, **ls_indexes = NULL;
593 ASSERT(ls_result != NULL);
595 p = vnet_lisp_get_locator(a, p);
597 clib_warning("locator-set %v doesn't exists", a->name);
598 return VNET_API_ERROR_INVALID_ARGUMENT;
605 ls = pool_elt_at_index(lcm->locator_set_pool, p[0]);
608 clib_warning("locator-set %d to be overwritten doesn't exist!",
610 return VNET_API_ERROR_INVALID_ARGUMENT;
616 /* allocate locators */
618 pool_get(lcm->locator_pool, loc);
620 loc_index = loc - lcm->locator_pool;
622 vec_add1(ls->locator_indices, loc_index);
624 vec_validate (lcm->locator_to_locator_sets, loc_index);
625 ls_indexes = vec_elt_at_index(lcm->locator_to_locator_sets,
627 vec_add1(ls_indexes[0], ls_index);
631 ls = pool_elt_at_index(lcm->locator_set_pool, p[0]);
634 clib_warning("locator-set with index %d doesn't exists", p[0]);
635 return VNET_API_ERROR_INVALID_ARGUMENT;
642 vec_foreach (locit, ls->locator_indices)
644 loc = pool_elt_at_index(lcm->locator_pool, locit[0]);
645 if (loc->local && loc->sw_if_index == itloc->sw_if_index)
647 ls_indexes = vec_elt_at_index(lcm->locator_to_locator_sets,
649 pool_put_index(lcm->locator_pool, locit[0]);
650 vec_del1(ls->locator_indices, i);
651 vec_del1(ls_indexes[0], ls_index);
660 static clib_error_t *
661 lisp_add_del_locator_set_command_fn (vlib_main_t * vm, unformat_input_t * input,
662 vlib_cli_command_t * cmd)
664 lisp_gpe_main_t * lgm = &lisp_gpe_main;
665 vnet_main_t * vnm = lgm->vnet_main;
666 unformat_input_t _line_input, * line_input = &_line_input;
668 clib_error_t * error = 0;
669 u8 * locator_set_name = 0;
670 locator_t locator, * locators = 0;
671 vnet_lisp_add_del_locator_set_args_t _a, * a = &_a;
674 memset(&locator, 0, sizeof(locator));
675 memset(a, 0, sizeof(a[0]));
677 /* Get a line of input. */
678 if (! unformat_user (input, unformat_line_input, line_input))
681 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
683 if (unformat (line_input, "add %_%v%_", &locator_set_name))
685 else if (unformat (line_input, "del %_%v%_", &locator_set_name))
687 else if (unformat (line_input, "iface %U p %d w %d",
688 unformat_vnet_sw_interface, vnm, &locator.sw_if_index,
689 &locator.priority, &locator.weight))
692 vec_add1(locators, locator);
696 error = unformat_parse_error(line_input);
701 a->name = locator_set_name;
702 a->locators = locators;
706 vnet_lisp_add_del_locator_set(a, &ls_index);
710 vec_free(locator_set_name);
714 VLIB_CLI_COMMAND (lisp_cp_add_del_locator_set_command) = {
715 .path = "lisp locator-set",
716 .short_help = "lisp locator-set add/del <name> iface <iface-name> "
717 "<priority> <weight>",
718 .function = lisp_add_del_locator_set_command_fn,
721 static clib_error_t *
722 lisp_cp_show_locator_sets_command_fn (vlib_main_t * vm,
723 unformat_input_t * input,
724 vlib_cli_command_t * cmd)
726 locator_set_t * lsit;
729 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
731 vlib_cli_output (vm, "%=20s%=16s%=16s%=16s", "Locator-set", "Locator",
732 "Priority", "Weight");
733 pool_foreach (lsit, lcm->locator_set_pool,
736 msg = format (msg, "%-16v", lsit->name);
737 vec_foreach (locit, lsit->locator_indices)
739 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
741 msg = format (msg, "%16d%16d%16d", loc->sw_if_index, loc->priority,
744 msg = format (msg, "%16U%16d%16d", format_gid_address, &loc->address,
745 loc->priority, loc->weight);
747 vlib_cli_output (vm, "%v", msg);
753 VLIB_CLI_COMMAND (lisp_cp_show_locator_sets_command) = {
754 .path = "show lisp locator-set",
755 .short_help = "Shows locator-sets",
756 .function = lisp_cp_show_locator_sets_command_fn,
760 vnet_lisp_add_del_map_resolver (vnet_lisp_add_del_map_resolver_args_t * a)
762 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
768 vec_foreach(addr, lcm->map_resolvers)
770 if (!ip_address_cmp (addr, &a->address))
772 clib_warning("map-resolver %U already exists!", format_ip_address,
777 vec_add1(lcm->map_resolvers, a->address);
781 for (i = 0; i < vec_len(lcm->map_resolvers); i++)
783 addr = vec_elt_at_index(lcm->map_resolvers, i);
784 if (!ip_address_cmp (addr, &a->address))
786 vec_delete(lcm->map_resolvers, 1, i);
794 static clib_error_t *
795 lisp_add_del_map_resolver_command_fn (vlib_main_t * vm,
796 unformat_input_t * input,
797 vlib_cli_command_t * cmd)
799 unformat_input_t _line_input, * line_input = &_line_input;
801 ip_address_t ip_addr;
802 clib_error_t * error = 0;
803 vnet_lisp_add_del_map_resolver_args_t _a, * a = &_a;
805 /* Get a line of input. */
806 if (! unformat_user (input, unformat_line_input, line_input))
809 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
811 if (unformat (line_input, "add"))
813 else if (unformat (line_input, "del"))
815 else if (unformat (line_input, "%U", unformat_ip_address, &ip_addr))
819 error = unformat_parse_error(line_input);
824 a->address = ip_addr;
825 vnet_lisp_add_del_map_resolver (a);
831 VLIB_CLI_COMMAND (lisp_add_del_map_resolver_command) = {
832 .path = "lisp map-resolver",
833 .short_help = "lisp map-resolver add/del <ip_address>",
834 .function = lisp_add_del_map_resolver_command_fn,
837 /* Statistics (not really errors) */
838 #define foreach_lisp_cp_lookup_error \
840 _(MAP_REQUESTS_SENT, "map-request sent")
842 static char * lisp_cp_lookup_error_strings[] = {
843 #define _(sym,string) string,
844 foreach_lisp_cp_lookup_error
850 #define _(sym,str) LISP_CP_LOOKUP_ERROR_##sym,
851 foreach_lisp_cp_lookup_error
853 LISP_CP_LOOKUP_N_ERROR,
854 } lisp_cp_lookup_error_t;
858 LISP_CP_LOOKUP_NEXT_DROP,
859 LISP_CP_LOOKUP_NEXT_IP4_LOOKUP,
860 LISP_CP_LOOKUP_NEXT_IP6_LOOKUP,
861 LISP_CP_LOOKUP_N_NEXT,
862 } lisp_cp_lookup_next_t;
866 gid_address_t dst_eid;
867 ip4_address_t map_resolver_ip;
868 } lisp_cp_lookup_trace_t;
871 format_lisp_cp_lookup_trace (u8 * s, va_list * args)
873 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
874 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
875 lisp_cp_lookup_trace_t * t = va_arg (*args, lisp_cp_lookup_trace_t *);
877 s = format (s, "LISP-CP-LOOKUP: map-resolver: %U destination eid %U",
878 format_ip_address, &t->map_resolver_ip, format_gid_address,
884 ip_fib_lookup_with_table (lisp_cp_main_t * lcm, u32 fib_index,
887 if (ip_addr_version (dst) == IP4)
888 return ip4_fib_lookup_with_table (lcm->im4, fib_index, &ip_addr_v4(dst),
891 return ip6_fib_lookup_with_table (lcm->im6, fib_index, &ip_addr_v6(dst));
895 get_local_iface_ip_for_dst (lisp_cp_main_t *lcm, ip_address_t * dst,
899 ip_adjacency_t * adj;
900 ip_interface_address_t * ia = 0;
901 ip_lookup_main_t * lm;
902 ip4_address_t * l4 = 0;
903 ip6_address_t * l6 = 0;
905 lm = ip_addr_version (dst) == IP4 ?
906 &lcm->im4->lookup_main : &lcm->im6->lookup_main;
908 adj_index = ip_fib_lookup_with_table (lcm, 0, dst);
909 adj = ip_get_adjacency (lm, adj_index);
911 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
913 ia = pool_elt_at_index(lm->if_address_pool, adj->if_address_index);
914 if (ip_addr_version(dst) == IP4)
916 l4 = ip_interface_address_get_address (lm, ia);
920 l6 = ip_interface_address_get_address (lm, ia);
923 else if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE)
925 /* find sw_if_index in rewrite header */
926 u32 sw_if_index = adj->rewrite_header.sw_if_index;
928 /* find suitable address */
929 if (ip_addr_version(dst) == IP4)
931 /* find the first ip address */
932 foreach_ip_interface_address (&lcm->im4->lookup_main, ia,
933 sw_if_index, 1 /* unnumbered */,
935 l4 = ip_interface_address_get_address (&lcm->im4->lookup_main, ia);
941 /* find the first ip address */
942 foreach_ip_interface_address (&lcm->im6->lookup_main, ia,
943 sw_if_index, 1 /* unnumbered */,
945 l6 = ip_interface_address_get_address (&lcm->im6->lookup_main, ia);
952 clib_warning("Can't find local local interface ip for dst %U",
953 format_ip_address, dst);
959 ip_addr_v4(sloc).as_u32 = l4->as_u32;
960 ip_addr_version(sloc) = IP4;
964 clib_memcpy (&ip_addr_v6(sloc), l6, sizeof(*l6));
965 ip_addr_version(sloc) = IP6;
969 clib_warning("Can't find local interface addr for dst %U",
970 format_ip_address, dst);
975 static gid_address_t *
976 build_itr_rloc_list (lisp_cp_main_t * lcm, locator_set_t * loc_set)
983 ip_interface_address_t * ia = 0;
984 gid_address_t gid_data, * gid = &gid_data;
985 gid_address_t * rlocs = 0;
986 ip_prefix_t * ippref = &gid_address_ippref (gid);
987 ip_address_t * rloc = &ip_prefix_addr (ippref);
989 gid_address_type (gid) = GID_ADDR_IP_PREFIX;
990 for (i = 0; i < vec_len(loc_set->locator_indices); i++)
992 loc_indexp = vec_elt_at_index(loc_set->locator_indices, i);
993 loc = pool_elt_at_index (lcm->locator_pool, loc_indexp[0]);
995 ip_addr_version(rloc) = IP4;
996 /* Add ipv4 locators first TODO sort them */
997 foreach_ip_interface_address (&lcm->im4->lookup_main, ia,
998 loc->sw_if_index, 1 /* unnumbered */,
1000 l4 = ip_interface_address_get_address (&lcm->im4->lookup_main, ia);
1001 ip_addr_v4 (rloc) = l4[0];
1002 vec_add1 (rlocs, gid[0]);
1005 ip_addr_version(rloc) = IP6;
1006 /* Add ipv6 locators */
1007 foreach_ip_interface_address (&lcm->im6->lookup_main, ia,
1008 loc->sw_if_index, 1 /* unnumbered */,
1010 l6 = ip_interface_address_get_address (&lcm->im6->lookup_main, ia);
1011 ip_addr_v6 (rloc) = l6[0];
1012 vec_add1 (rlocs, gid[0]);
1018 static vlib_buffer_t *
1019 build_encapsulated_map_request (vlib_main_t * vm, lisp_cp_main_t *lcm,
1020 gid_address_t * seid, gid_address_t * deid,
1021 locator_set_t * loc_set, u8 is_smr_invoked,
1022 u64 *nonce_res, u32 * bi_res)
1026 ip_address_t * mr_ip, sloc;
1027 gid_address_t * rlocs = 0;
1029 if (vlib_buffer_alloc (vm, &bi, 1) != 1)
1031 clib_warning ("Can't allocate buffer for Map-Request!");
1035 b = vlib_get_buffer (vm, bi);
1037 /* leave some space for the encap headers */
1038 vlib_buffer_make_headroom (b, MAX_LISP_MSG_ENCAP_LEN);
1041 rlocs = build_itr_rloc_list (lcm, loc_set);
1044 lisp_msg_put_mreq (lcm, b, seid, deid, rlocs, is_smr_invoked, nonce_res);
1046 /* push ecm: udp-ip-lisp */
1047 lisp_msg_push_ecm (vm, b, LISP_CONTROL_PORT, LISP_CONTROL_PORT, seid, deid);
1049 /* get map-resolver ip XXX use first*/
1050 mr_ip = vec_elt_at_index(lcm->map_resolvers, 0);
1052 /* get local iface ip to use in map-request XXX fib 0 for now*/
1053 get_local_iface_ip_for_dst (lcm, mr_ip, &sloc);
1055 /* push outer ip header */
1056 pkt_push_udp_and_ip (vm, b, LISP_CONTROL_PORT, LISP_CONTROL_PORT, &sloc,
1067 send_encapsulated_map_request (vlib_main_t * vm, lisp_cp_main_t *lcm,
1068 gid_address_t * seid, gid_address_t * deid,
1071 u32 next_index, bi = 0, * to_next, map_index;
1075 locator_set_t * loc_set;
1077 pending_map_request_t * pmr;
1079 /* get locator-set for seid */
1080 map_index = gid_dictionary_lookup (&lcm->mapping_index_by_gid, seid);
1081 if (map_index == ~0)
1083 clib_warning("No local mapping found in eid-table for %U!",
1084 format_gid_address, seid);
1088 map = pool_elt_at_index (lcm->mapping_pool, map_index);
1092 clib_warning("Mapping found for src eid %U is not marked as local!",
1093 format_gid_address, seid);
1096 loc_set = pool_elt_at_index (lcm->locator_set_pool, map->locator_set_index);
1098 /* build the encapsulated map request */
1099 b = build_encapsulated_map_request (vm, lcm, seid, deid, loc_set,
1100 is_smr_invoked, &nonce, &bi);
1105 vnet_buffer(b)->sw_if_index[VLIB_TX] = ~0;
1106 next_index = (ip_prefix_version(&gid_address_ippref(seid)) == IP4) ?
1107 ip4_lookup_node.index : ip6_lookup_node.index;
1109 f = vlib_get_frame_to_node (vm, next_index);
1111 /* Enqueue the packet */
1112 to_next = vlib_frame_vector_args (f);
1115 vlib_put_frame_to_node (vm, next_index, f);
1117 /* add map-request to pending requests table */
1118 pool_get(lcm->pending_map_requests_pool, pmr);
1119 gid_address_copy (&pmr->src, seid);
1120 gid_address_copy (&pmr->dst, deid);
1121 pmr->src_mapping_index = map_index;
1122 hash_set(lcm->pending_map_requests_by_nonce, nonce,
1123 pmr - lcm->pending_map_requests_pool);
1127 get_src_and_dst (void *hdr, ip_address_t * src, ip_address_t *dst)
1129 ip4_header_t * ip4 = hdr;
1132 if ((ip4->ip_version_and_header_length & 0xF0) == 0x40)
1134 ip_addr_v4(src).as_u32 = ip4->src_address.as_u32;
1135 ip_addr_version(src) = IP4;
1136 ip_addr_v4(dst).as_u32 = ip4->dst_address.as_u32;
1137 ip_addr_version(dst) = IP4;
1142 clib_memcpy (&ip_addr_v6(src), &ip6->src_address, sizeof(ip6->src_address));
1143 ip_addr_version(src) = IP6;
1144 clib_memcpy (&ip_addr_v6(dst), &ip6->dst_address, sizeof(ip6->dst_address));
1145 ip_addr_version(dst) = IP6;
1150 lisp_cp_lookup (vlib_main_t * vm, vlib_node_runtime_t * node,
1151 vlib_frame_t * from_frame)
1153 u32 * from, * to_next_drop;
1154 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main();
1155 u32 pkts_mapped = 0;
1156 uword n_left_from, n_left_to_next_drop;
1158 from = vlib_frame_vector_args (from_frame);
1159 n_left_from = from_frame->n_vectors;
1161 while (n_left_from > 0)
1163 vlib_get_next_frame (vm, node, LISP_CP_LOOKUP_NEXT_DROP,
1164 to_next_drop, n_left_to_next_drop);
1166 while (n_left_from > 0 && n_left_to_next_drop > 0)
1171 gid_address_t src, dst;
1172 ip_prefix_t * spref, * dpref;
1174 gid_address_type (&src) = GID_ADDR_IP_PREFIX;
1175 spref = &gid_address_ippref(&src);
1176 gid_address_type (&dst) = GID_ADDR_IP_PREFIX;
1177 dpref = &gid_address_ippref(&dst);
1182 to_next_drop[0] = pi0;
1184 n_left_to_next_drop -= 1;
1186 p0 = vlib_get_buffer (vm, pi0);
1187 p0->error = node->errors[LISP_CP_LOOKUP_ERROR_DROP];
1189 /* src/dst eid pair */
1190 ip0 = vlib_buffer_get_current (p0);
1191 get_src_and_dst (ip0, &ip_prefix_addr(spref), &ip_prefix_addr(dpref));
1192 ip_prefix_len(spref) = ip_address_max_len (ip_prefix_version(spref));
1193 ip_prefix_len(dpref) = ip_address_max_len (ip_prefix_version(dpref));
1195 /* send map-request */
1196 send_encapsulated_map_request (vm, lcm, &src, &dst, 0);
1200 if (PREDICT_FALSE(p0->flags & VLIB_BUFFER_IS_TRACED))
1202 lisp_cp_lookup_trace_t *tr = vlib_add_trace (vm, node, p0,
1204 gid_address_copy (&tr->dst_eid, &dst);
1205 clib_memcpy (&tr->map_resolver_ip,
1206 vec_elt_at_index(lcm->map_resolvers, 0),
1207 sizeof(ip_address_t));
1211 vlib_put_next_frame (vm, node, LISP_CP_LOOKUP_NEXT_DROP, n_left_to_next_drop);
1213 vlib_node_increment_counter (vm, node->node_index,
1214 LISP_CP_LOOKUP_ERROR_MAP_REQUESTS_SENT,
1216 return from_frame->n_vectors;
1219 VLIB_REGISTER_NODE (lisp_cp_lookup_node) = {
1220 .function = lisp_cp_lookup,
1221 .name = "lisp-cp-lookup",
1222 .vector_size = sizeof (u32),
1223 .format_trace = format_lisp_cp_lookup_trace,
1224 .type = VLIB_NODE_TYPE_INTERNAL,
1226 .n_errors = LISP_CP_LOOKUP_N_ERROR,
1227 .error_strings = lisp_cp_lookup_error_strings,
1229 .n_next_nodes = LISP_CP_LOOKUP_N_NEXT,
1232 [LISP_CP_LOOKUP_NEXT_DROP] = "error-drop",
1233 [LISP_CP_LOOKUP_NEXT_IP4_LOOKUP] = "ip4-lookup",
1234 [LISP_CP_LOOKUP_NEXT_IP6_LOOKUP] = "ip6-lookup",
1238 /* lisp_cp_input statistics */
1239 #define foreach_lisp_cp_input_error \
1241 _(MAP_REPLIES_RECEIVED, "map-replies received")
1243 static char * lisp_cp_input_error_strings[] = {
1244 #define _(sym,string) string,
1245 foreach_lisp_cp_input_error
1251 #define _(sym,str) LISP_CP_INPUT_ERROR_##sym,
1252 foreach_lisp_cp_input_error
1254 LISP_CP_INPUT_N_ERROR,
1255 } lisp_cp_input_error_t;
1259 LISP_CP_INPUT_NEXT_DROP,
1260 LISP_CP_INPUT_N_NEXT,
1261 } lisp_cp_input_next_t;
1265 gid_address_t dst_eid;
1266 ip4_address_t map_resolver_ip;
1267 } lisp_cp_input_trace_t;
1270 format_lisp_cp_input_trace (u8 * s, va_list * args)
1272 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1273 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1274 CLIB_UNUSED(lisp_cp_input_trace_t * t) = va_arg (*args, lisp_cp_input_trace_t *);
1276 s = format (s, "LISP-CP-INPUT: TODO");
1280 ip_interface_address_t *
1281 ip_interface_get_first_interface_address (ip_lookup_main_t *lm, u32 sw_if_index,
1284 vnet_main_t *vnm = vnet_get_main ();
1285 vnet_sw_interface_t * swif = vnet_get_sw_interface (vnm, sw_if_index);
1286 if (loop && swif->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)
1287 sw_if_index = swif->unnumbered_sw_if_index;
1289 (vec_len((lm)->if_address_pool_index_by_sw_if_index) > (sw_if_index)) ?
1290 vec_elt((lm)->if_address_pool_index_by_sw_if_index, (sw_if_index)) :
1292 return pool_elt_at_index((lm)->if_address_pool, ia);
1296 ip_interface_get_first_ip_addres (ip_lookup_main_t *lm, u32 sw_if_index,
1299 ip_interface_address_t * ia = ip_interface_get_first_interface_address (
1300 lm, sw_if_index, loop);
1301 return ip_interface_address_get_address (lm, ia);
1305 del_fwd_entry (lisp_cp_main_t * lcm, u32 src_map_index,
1308 vnet_lisp_gpe_add_del_fwd_entry_args_t _a, * a = &_a;
1309 fwd_entry_t * fe = 0;
1311 memset(a, 0, sizeof(*a));
1313 feip = hash_get(lcm->fwd_entry_by_mapping_index, dst_map_index);
1317 fe = pool_elt_at_index(lcm->fwd_entry_pool, feip[0]);
1319 /* delete dp fwd entry */
1322 a->dlocator = fe->dst_loc;
1323 a->slocator = fe->src_loc;
1324 a->vni = 0; // XXX should be part of mapping/eid
1325 gid_address_copy(&a->deid, &fe->deid);
1327 vnet_lisp_gpe_add_del_fwd_entry (a, &sw_if_index);
1329 /* delete entry in fwd table */
1330 hash_unset(lcm->fwd_entry_by_mapping_index, dst_map_index);
1331 pool_put(lcm->fwd_entry_pool, fe);
1335 add_fwd_entry (lisp_cp_main_t* lcm, u32 src_map_index, u32 dst_map_index)
1337 mapping_t * src_map, * dst_map;
1338 locator_set_t * dst_ls, * src_ls;
1341 uword * feip = 0, * tidp;
1343 vnet_lisp_gpe_add_del_fwd_entry_args_t _a, * a = &_a;
1345 memset (a, 0, sizeof(*a));
1347 /* remove entry if it already exists */
1348 feip = hash_get (lcm->fwd_entry_by_mapping_index, dst_map_index);
1350 del_fwd_entry (lcm, src_map_index, dst_map_index);
1352 src_map = pool_elt_at_index (lcm->mapping_pool, src_map_index);
1353 dst_map = pool_elt_at_index (lcm->mapping_pool, dst_map_index);
1355 /* XXX simple forwarding policy: first lowest (value) priority locator */
1356 dst_ls = pool_elt_at_index (lcm->locator_set_pool,
1357 dst_map->locator_set_index);
1358 for (i = 0; i < vec_len (dst_ls->locator_indices); i++)
1360 u32 li = vec_elt (dst_ls->locator_indices, i);
1361 locator_t * l = pool_elt_at_index (lcm->locator_pool, li);
1362 if (l->priority < minp && gid_address_type(&l->address)
1363 == GID_ADDR_IP_PREFIX)
1371 src_ls = pool_elt_at_index (lcm->locator_set_pool,
1372 src_map->locator_set_index);
1373 for (i = 0; i < vec_len (src_ls->locator_indices); i++)
1375 u32 li = vec_elt (src_ls->locator_indices, i);
1376 locator_t * sl = pool_elt_at_index (lcm->locator_pool, li);
1378 if (ip_addr_version(&gid_address_ip(&dl->address)) == IP4)
1381 l4 = ip_interface_get_first_ip_addres (&lcm->im4->lookup_main,
1383 1 /* unnumbered */);
1384 ip_addr_v4(&a->slocator) = *l4;
1385 ip_addr_version(&a->slocator) = IP4;
1390 l6 = ip_interface_get_first_ip_addres (&lcm->im6->lookup_main,
1392 1 /* unnumbered */);
1393 ip_addr_v6(&a->slocator) = *l6;
1394 ip_addr_version(&a->slocator) = IP6;
1398 /* insert data plane forwarding entry */
1402 a->dlocator = gid_address_ip(&dl->address);
1406 a->action = dst_map->action;
1409 gid_address_copy (&a->deid, &dst_map->eid);
1410 a->vni = 0; // XXX should be part of mapping/eid
1412 tidp = hash_get(lcm->table_id_by_vni, a->vni);
1415 clib_warning("vni %d not associated to a vrf!", a->vni);
1418 a->table_id = tidp[0];
1421 u8 ipver = ip_prefix_version(&gid_address_ippref(&a->deid));
1422 a->decap_next_index = (ipver == IP4) ?
1423 LISP_GPE_INPUT_NEXT_IP4_INPUT : LISP_GPE_INPUT_NEXT_IP6_INPUT;
1425 vnet_lisp_gpe_add_del_fwd_entry (a, &sw_if_index);
1427 /* add tunnel to fwd entry table XXX check return value from DP insertion */
1428 pool_get (lcm->fwd_entry_pool, fe);
1429 fe->dst_loc = a->dlocator;
1430 fe->src_loc = a->slocator;
1431 gid_address_copy (&fe->deid, &a->deid);
1432 hash_set (lcm->fwd_entry_by_mapping_index, dst_map_index,
1433 fe - lcm->fwd_entry_pool);
1436 /* return 0 if the two locator sets are identical 1 otherwise */
1438 compare_locators (lisp_cp_main_t *lcm, u32 * old_ls_indexes,
1439 locator_t * new_locators)
1442 locator_t * old_loc, * new_loc;
1444 if (vec_len (old_ls_indexes) != vec_len(new_locators))
1447 for (i = 0; i < vec_len(new_locators); i++)
1449 old_li = vec_elt(old_ls_indexes, i);
1450 old_loc = pool_elt_at_index(lcm->locator_pool, old_li);
1452 new_loc = vec_elt_at_index(new_locators, i);
1454 if (locator_cmp (old_loc, new_loc))
1461 process_map_reply (lisp_cp_main_t * lcm, vlib_buffer_t * b)
1464 u32 len = 0, i, ls_index = 0;
1466 vnet_lisp_add_del_locator_set_args_t _ls_arg, * ls_arg = &_ls_arg;
1467 vnet_lisp_add_del_mapping_args_t _m_args, * m_args = &_m_args;
1468 pending_map_request_t * pmr;
1470 map_reply_hdr_t * mrep_hdr;
1472 u32 dst_map_index, mi;
1475 mrep_hdr = vlib_buffer_get_current (b);
1477 /* Check pending requests table and nonce */
1478 nonce = MREP_NONCE(mrep_hdr);
1479 pmr_index = hash_get(lcm->pending_map_requests_by_nonce, nonce);
1482 clib_warning("No pending map-request entry with nonce %lu!", nonce);
1485 pmr = pool_elt_at_index(lcm->pending_map_requests_pool, pmr_index[0]);
1487 vlib_buffer_pull (b, sizeof(*mrep_hdr));
1489 for (i = 0; i < MREP_REC_COUNT(mrep_hdr); i++)
1491 memset (ls_arg, 0, sizeof(*ls_arg));
1492 memset (m_args, 0, sizeof(*m_args));
1494 h = vlib_buffer_get_current (b);
1495 m_args->ttl = clib_net_to_host_u32 (MAP_REC_TTL(h));
1496 m_args->action = MAP_REC_ACTION(h);
1497 m_args->authoritative = MAP_REC_AUTH(h);
1499 len = lisp_msg_parse_mapping_record (b, &m_args->deid, &ls_arg->locators,
1503 clib_warning ("Failed to parse mapping record!");
1504 vec_foreach (loc, ls_arg->locators)
1508 vec_free(ls_arg->locators);
1512 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &m_args->deid);
1514 /* if mapping already exists, decide if locators (and forwarding) should
1515 * be updated and be done */
1518 mapping_t * old_map;
1519 locator_set_t * old_ls;
1520 old_map = pool_elt_at_index(lcm->mapping_pool, mi);
1522 /* update mapping attributes */
1523 old_map->action = m_args->action;
1524 old_map->authoritative = m_args->authoritative;
1525 old_map->ttl = m_args->ttl;
1527 old_ls = pool_elt_at_index(lcm->locator_set_pool,
1528 old_map->locator_set_index);
1529 /* if the two locators are not equal, update them and forwarding
1530 * otherwise there's nothing to be done */
1531 if (compare_locators (lcm, old_ls->locator_indices, ls_arg->locators))
1533 /* set locator-set index to overwrite */
1535 ls_arg->index = old_map->locator_set_index;
1536 vnet_lisp_add_del_locator_set (ls_arg, 0);
1537 add_fwd_entry (lcm, pmr->src_mapping_index, mi);
1543 /* add locator-set */
1546 vnet_lisp_add_del_locator_set (ls_arg, &ls_index);
1550 m_args->locator_set_index = ls_index;
1551 vnet_lisp_add_del_mapping (m_args, &dst_map_index);
1553 /* add forwarding tunnel */
1554 add_fwd_entry (lcm, pmr->src_mapping_index, dst_map_index);
1556 vec_free(ls_arg->locators);
1559 /* remove pending map request entry */
1560 hash_unset(lcm->pending_map_requests_by_nonce, nonce);
1561 pool_put(lcm->pending_map_requests_pool, pmr);
1565 process_map_request (vlib_main_t * vm, lisp_cp_main_t * lcm, vlib_buffer_t * b)
1567 map_request_hdr_t * mreq_hdr;
1568 gid_address_t src, dst;
1571 gid_address_t * itr_rlocs = 0, * rloc;
1573 mreq_hdr = vlib_buffer_get_current (b);
1574 vlib_buffer_pull (b, sizeof(*mreq_hdr));
1576 // nonce = MREQ_NONCE(mreq_hdr);
1578 if (!MREQ_SMR(mreq_hdr)) {
1579 clib_warning("Only SMR Map-Requests supported for now!");
1584 len = lisp_msg_parse_addr (b, &src);
1588 /* for now we don't do anything with the itr's rlocs */
1589 len = lisp_msg_parse_itr_rlocs (b, &itr_rlocs, MREQ_ITR_RLOC_COUNT(mreq_hdr) + 1);
1593 /* TODO: RLOCs are currently unused, so free them for now */
1594 vec_foreach (rloc, itr_rlocs)
1596 gid_address_free (rloc);
1599 /* parse eid records and send SMR-invoked map-requests */
1600 for (i = 0; i < MREQ_REC_COUNT(mreq_hdr); i++)
1602 memset(&dst, 0, sizeof(dst));
1603 len = lisp_msg_parse_eid_rec (b, &dst);
1606 clib_warning("Can't parse map-request EID-record");
1609 /* send SMR-invoked map-requests */
1610 send_encapsulated_map_request (vm, lcm, &dst, &src, /* invoked */ 1);
1615 lisp_cp_input (vlib_main_t * vm, vlib_node_runtime_t * node,
1616 vlib_frame_t * from_frame)
1618 u32 n_left_from, * from, * to_next_drop;
1619 lisp_msg_type_e type;
1620 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
1622 from = vlib_frame_vector_args (from_frame);
1623 n_left_from = from_frame->n_vectors;
1626 while (n_left_from > 0)
1628 u32 n_left_to_next_drop;
1630 vlib_get_next_frame (vm, node, LISP_CP_INPUT_NEXT_DROP,
1631 to_next_drop, n_left_to_next_drop);
1632 while (n_left_from > 0 && n_left_to_next_drop > 0)
1640 to_next_drop[0] = bi0;
1642 n_left_to_next_drop -= 1;
1644 b0 = vlib_get_buffer (vm, bi0);
1646 type = lisp_msg_type(vlib_buffer_get_current (b0));
1649 case LISP_MAP_REPLY:
1650 process_map_reply (lcm, b0);
1652 case LISP_MAP_REQUEST:
1653 process_map_request(vm, lcm, b0);
1656 clib_warning("Unsupported LISP message type %d", type);
1660 b0->error = node->errors[LISP_CP_INPUT_ERROR_DROP];
1662 if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
1668 vlib_put_next_frame (vm, node, LISP_CP_INPUT_NEXT_DROP, n_left_to_next_drop);
1670 return from_frame->n_vectors;
1673 VLIB_REGISTER_NODE (lisp_cp_input_node) = {
1674 .function = lisp_cp_input,
1675 .name = "lisp-cp-input",
1676 .vector_size = sizeof (u32),
1677 .format_trace = format_lisp_cp_input_trace,
1678 .type = VLIB_NODE_TYPE_INTERNAL,
1680 .n_errors = LISP_CP_INPUT_N_ERROR,
1681 .error_strings = lisp_cp_input_error_strings,
1683 .n_next_nodes = LISP_CP_INPUT_N_NEXT,
1686 [LISP_CP_INPUT_NEXT_DROP] = "error-drop",
1691 lisp_cp_init (vlib_main_t *vm)
1693 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
1694 clib_error_t * error = 0;
1696 if ((error = vlib_call_init_function (vm, lisp_gpe_init)))
1699 lcm->im4 = &ip4_main;
1700 lcm->im6 = &ip6_main;
1701 lcm->vlib_main = vm;
1702 lcm->vnet_main = vnet_get_main();
1704 gid_dictionary_init (&lcm->mapping_index_by_gid);
1706 /* default vrf mapped to vni 0 */
1707 hash_set(lcm->table_id_by_vni, 0, 0);
1709 udp_register_dst_port (vm, UDP_DST_PORT_lisp_cp,
1710 lisp_cp_input_node.index, 1 /* is_ip4 */);
1711 udp_register_dst_port (vm, UDP_DST_PORT_lisp_cp6,
1712 lisp_cp_input_node.index, 0 /* is_ip4 */);
1717 VLIB_INIT_FUNCTION(lisp_cp_init);