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 <vlibmemory/api.h>
17 #include <vnet/lisp-cp/control.h>
18 #include <vnet/lisp-cp/packets.h>
19 #include <vnet/lisp-cp/lisp_msg_serdes.h>
20 #include <vnet/lisp-gpe/lisp_gpe_fwd_entry.h>
21 #include <vnet/lisp-gpe/lisp_gpe_tenant.h>
22 #include <vnet/lisp-gpe/lisp_gpe_tunnel.h>
23 #include <vnet/fib/fib_entry.h>
24 #include <vnet/fib/fib_table.h>
25 #include <vnet/ethernet/arp_packet.h>
26 #include <vnet/ethernet/packet.h>
28 #include <openssl/evp.h>
29 #include <openssl/hmac.h>
31 #define MAX_VALUE_U24 0xffffff
33 lisp_cp_main_t lisp_control_main;
35 u8 *format_lisp_cp_input_trace (u8 * s, va_list * args);
39 LISP_CP_INPUT_NEXT_DROP,
41 } lisp_cp_input_next_t;
52 vnet_lisp_get_map_request_mode (void)
54 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
55 return lcm->map_request_mode;
59 auth_data_len_by_key_id (lisp_key_type_t key_id)
64 return SHA1_AUTH_DATA_LEN;
65 case HMAC_SHA_256_128:
66 return SHA256_AUTH_DATA_LEN;
68 clib_warning ("unsupported key type: %d!", key_id);
75 get_encrypt_fcn (lisp_key_type_t key_id)
81 case HMAC_SHA_256_128:
84 clib_warning ("unsupported encryption key type: %d!", key_id);
91 queue_map_request (gid_address_t * seid, gid_address_t * deid,
92 u8 smr_invoked, u8 is_resend);
94 ip_interface_address_t *
95 ip_interface_get_first_interface_address (ip_lookup_main_t * lm,
96 u32 sw_if_index, u8 loop)
98 vnet_main_t *vnm = vnet_get_main ();
99 vnet_sw_interface_t *swif = vnet_get_sw_interface (vnm, sw_if_index);
100 if (loop && swif->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)
101 sw_if_index = swif->unnumbered_sw_if_index;
103 (vec_len ((lm)->if_address_pool_index_by_sw_if_index) > (sw_if_index)) ?
104 vec_elt ((lm)->if_address_pool_index_by_sw_if_index, (sw_if_index)) :
106 return pool_elt_at_index ((lm)->if_address_pool, ia);
110 ip_interface_get_first_address (ip_lookup_main_t * lm, u32 sw_if_index,
113 ip_interface_address_t *ia;
115 ia = ip_interface_get_first_interface_address (lm, sw_if_index, 1);
118 return ip_interface_address_get_address (lm, ia);
122 ip_interface_get_first_ip_address (lisp_cp_main_t * lcm, u32 sw_if_index,
123 u8 version, ip_address_t * result)
125 ip_lookup_main_t *lm;
128 lm = (version == IP4) ? &lcm->im4->lookup_main : &lcm->im6->lookup_main;
129 addr = ip_interface_get_first_address (lm, sw_if_index, version);
133 ip_address_set (result, addr, version);
138 * convert from a LISP address to a FIB prefix
141 ip_address_to_fib_prefix (const ip_address_t * addr, fib_prefix_t * prefix)
143 if (addr->version == IP4)
146 prefix->fp_proto = FIB_PROTOCOL_IP4;
147 memset (&prefix->fp_addr.pad, 0, sizeof (prefix->fp_addr.pad));
148 memcpy (&prefix->fp_addr.ip4, &addr->ip, sizeof (prefix->fp_addr.ip4));
152 prefix->fp_len = 128;
153 prefix->fp_proto = FIB_PROTOCOL_IP6;
154 memcpy (&prefix->fp_addr.ip6, &addr->ip, sizeof (prefix->fp_addr.ip6));
159 * convert from a LISP to a FIB prefix
162 ip_prefix_to_fib_prefix (const ip_prefix_t * ip_prefix,
163 fib_prefix_t * fib_prefix)
165 ip_address_to_fib_prefix (&ip_prefix->addr, fib_prefix);
166 fib_prefix->fp_len = ip_prefix->len;
170 * Find the sw_if_index of the interface that would be used to egress towards
174 ip_fib_get_egress_iface_for_dst (lisp_cp_main_t * lcm, ip_address_t * dst)
176 fib_node_index_t fei;
179 ip_address_to_fib_prefix (dst, &prefix);
181 fei = fib_table_lookup (0, &prefix);
183 return (fib_entry_get_resolving_interface (fei));
187 * Find first IP of the interface that would be used to egress towards dst.
188 * Returns 1 if the address is found 0 otherwise.
191 ip_fib_get_first_egress_ip_for_dst (lisp_cp_main_t * lcm, ip_address_t * dst,
192 ip_address_t * result)
195 ip_lookup_main_t *lm;
199 ASSERT (result != 0);
201 ipver = ip_addr_version (dst);
203 lm = (ipver == IP4) ? &lcm->im4->lookup_main : &lcm->im6->lookup_main;
204 si = ip_fib_get_egress_iface_for_dst (lcm, dst);
209 /* find the first ip address */
210 addr = ip_interface_get_first_address (lm, si, ipver);
214 ip_address_set (result, addr, ipver);
219 dp_add_del_iface (lisp_cp_main_t * lcm, u32 vni, u8 is_l2, u8 is_add)
225 dp_table = hash_get (lcm->table_id_by_vni, vni);
229 clib_warning ("vni %d not associated to a vrf!", vni);
230 return VNET_API_ERROR_INVALID_VALUE;
235 dp_table = hash_get (lcm->bd_id_by_vni, vni);
238 clib_warning ("vni %d not associated to a bridge domain!", vni);
239 return VNET_API_ERROR_INVALID_VALUE;
243 /* enable/disable data-plane interface */
247 lisp_gpe_tenant_l2_iface_add_or_lock (vni, dp_table[0]);
249 lisp_gpe_tenant_l3_iface_add_or_lock (vni, dp_table[0]);
254 lisp_gpe_tenant_l2_iface_unlock (vni);
256 lisp_gpe_tenant_l3_iface_unlock (vni);
263 dp_del_fwd_entry (lisp_cp_main_t * lcm, u32 src_map_index, u32 dst_map_index)
265 vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a;
268 memset (a, 0, sizeof (*a));
270 feip = hash_get (lcm->fwd_entry_by_mapping_index, dst_map_index);
274 fe = pool_elt_at_index (lcm->fwd_entry_pool, feip[0]);
276 /* delete dp fwd entry */
279 a->locator_pairs = fe->locator_pairs;
280 a->vni = gid_address_vni (&fe->reid);
281 gid_address_copy (&a->rmt_eid, &fe->reid);
283 gid_address_copy (&a->lcl_eid, &fe->leid);
285 vnet_lisp_gpe_del_fwd_counters (a, feip[0]);
286 vnet_lisp_gpe_add_del_fwd_entry (a, &sw_if_index);
288 /* delete entry in fwd table */
289 hash_unset (lcm->fwd_entry_by_mapping_index, dst_map_index);
290 vec_free (fe->locator_pairs);
291 pool_put (lcm->fwd_entry_pool, fe);
295 * Finds first remote locator with best (lowest) priority that has a local
296 * peer locator with an underlying route to it.
300 get_locator_pairs (lisp_cp_main_t * lcm, mapping_t * lcl_map,
301 mapping_t * rmt_map, locator_pair_t ** locator_pairs)
303 u32 i, limitp = 0, li, found = 0, esi;
304 locator_set_t *rmt_ls, *lcl_ls;
305 ip_address_t _lcl_addr, *lcl_addr = &_lcl_addr;
306 locator_t *lp, *rmt = 0;
311 pool_elt_at_index (lcm->locator_set_pool, rmt_map->locator_set_index);
313 pool_elt_at_index (lcm->locator_set_pool, lcl_map->locator_set_index);
315 if (!rmt_ls || vec_len (rmt_ls->locator_indices) == 0)
322 /* find unvisited remote locator with best priority */
323 for (i = 0; i < vec_len (rmt_ls->locator_indices); i++)
325 if (0 != hash_get (checked, i))
328 li = vec_elt (rmt_ls->locator_indices, i);
329 lp = pool_elt_at_index (lcm->locator_pool, li);
331 /* we don't support non-IP locators for now */
332 if (gid_address_type (&lp->address) != GID_ADDR_IP_PREFIX)
335 if ((found && lp->priority == limitp)
336 || (!found && lp->priority >= limitp))
340 /* don't search for locators with lower priority and don't
341 * check this locator again*/
342 limitp = lp->priority;
343 hash_set (checked, i, 1);
347 /* check if a local locator with a route to remote locator exists */
350 /* find egress sw_if_index for rmt locator */
352 ip_fib_get_egress_iface_for_dst (lcm,
353 &gid_address_ip (&rmt->address));
354 if ((u32) ~ 0 == esi)
357 for (i = 0; i < vec_len (lcl_ls->locator_indices); i++)
359 li = vec_elt (lcl_ls->locator_indices, i);
360 locator_t *sl = pool_elt_at_index (lcm->locator_pool, li);
362 /* found local locator with the needed sw_if_index */
363 if (sl->sw_if_index == esi)
365 /* and it has an address */
366 if (0 == ip_interface_get_first_ip_address (lcm,
368 gid_address_ip_version
373 memset (&pair, 0, sizeof (pair));
374 ip_address_copy (&pair.rmt_loc,
375 &gid_address_ip (&rmt->address));
376 ip_address_copy (&pair.lcl_loc, lcl_addr);
377 pair.weight = rmt->weight;
378 pair.priority = rmt->priority;
379 vec_add1 (locator_pairs[0], pair);
393 gid_address_sd_to_flat (gid_address_t * dst, gid_address_t * src,
396 ASSERT (GID_ADDR_SRC_DST == gid_address_type (src));
400 switch (fid_addr_type (fid))
402 case FID_ADDR_IP_PREF:
403 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
404 gid_address_ippref (dst) = fid_addr_ippref (fid);
407 gid_address_type (dst) = GID_ADDR_MAC;
408 mac_copy (gid_address_mac (dst), fid_addr_mac (fid));
411 clib_warning ("Unsupported fid type %d!", fid_addr_type (fid));
417 vnet_lisp_map_register_state_get (void)
419 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
420 return lcm->map_registering;
424 vnet_lisp_rloc_probe_state_get (void)
426 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
427 return lcm->rloc_probing;
431 dp_add_fwd_entry (lisp_cp_main_t * lcm, u32 src_map_index, u32 dst_map_index)
433 vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a;
434 gid_address_t *rmt_eid, *lcl_eid;
435 mapping_t *lcl_map, *rmt_map;
437 uword *feip = 0, *dpid;
439 u8 type, is_src_dst = 0;
442 memset (a, 0, sizeof (*a));
444 /* remove entry if it already exists */
445 feip = hash_get (lcm->fwd_entry_by_mapping_index, dst_map_index);
447 dp_del_fwd_entry (lcm, src_map_index, dst_map_index);
450 * Determine local mapping and eid
453 lcl_map = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
455 lcl_map = pool_elt_at_index (lcm->mapping_pool, src_map_index);
456 lcl_eid = &lcl_map->eid;
459 * Determine remote mapping and eid
461 rmt_map = pool_elt_at_index (lcm->mapping_pool, dst_map_index);
462 rmt_eid = &rmt_map->eid;
465 * Build and insert data plane forwarding entry
469 if (MR_MODE_SRC_DST == lcm->map_request_mode)
471 if (GID_ADDR_SRC_DST == gid_address_type (rmt_eid))
473 gid_address_sd_to_flat (&a->rmt_eid, rmt_eid,
474 &gid_address_sd_dst (rmt_eid));
475 gid_address_sd_to_flat (&a->lcl_eid, rmt_eid,
476 &gid_address_sd_src (rmt_eid));
480 gid_address_copy (&a->rmt_eid, rmt_eid);
481 gid_address_copy (&a->lcl_eid, lcl_eid);
486 gid_address_copy (&a->rmt_eid, rmt_eid);
488 a->vni = gid_address_vni (&a->rmt_eid);
489 a->is_src_dst = is_src_dst;
491 /* get vrf or bd_index associated to vni */
492 type = gid_address_type (&a->rmt_eid);
493 if (GID_ADDR_IP_PREFIX == type)
495 dpid = hash_get (lcm->table_id_by_vni, a->vni);
498 clib_warning ("vni %d not associated to a vrf!", a->vni);
501 a->table_id = dpid[0];
503 else if (GID_ADDR_MAC == type)
505 dpid = hash_get (lcm->bd_id_by_vni, a->vni);
508 clib_warning ("vni %d not associated to a bridge domain !", a->vni);
514 /* find best locator pair that 1) verifies LISP policy 2) are connected */
515 rv = get_locator_pairs (lcm, lcl_map, rmt_map, &a->locator_pairs);
517 /* Either rmt mapping is negative or we can't find underlay path.
518 * Try again with petr if configured */
519 if (rv == 0 && (lcm->flags & LISP_FLAG_USE_PETR))
521 rmt_map = lisp_get_petr_mapping (lcm);
522 rv = get_locator_pairs (lcm, lcl_map, rmt_map, &a->locator_pairs);
529 a->action = rmt_map->action;
532 rv = vnet_lisp_gpe_add_del_fwd_entry (a, &sw_if_index);
535 if (a->locator_pairs)
536 vec_free (a->locator_pairs);
540 /* add tunnel to fwd entry table */
541 pool_get (lcm->fwd_entry_pool, fe);
542 vnet_lisp_gpe_add_fwd_counters (a, fe - lcm->fwd_entry_pool);
544 fe->locator_pairs = a->locator_pairs;
545 gid_address_copy (&fe->reid, &a->rmt_eid);
548 gid_address_copy (&fe->leid, &a->lcl_eid);
550 gid_address_copy (&fe->leid, lcl_eid);
552 fe->is_src_dst = is_src_dst;
553 hash_set (lcm->fwd_entry_by_mapping_index, dst_map_index,
554 fe - lcm->fwd_entry_pool);
561 } fwd_entry_mt_arg_t;
564 dp_add_fwd_entry_thread_fn (void *arg)
566 fwd_entry_mt_arg_t *a = arg;
567 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
568 dp_add_fwd_entry (lcm, a->si, a->di);
573 dp_add_fwd_entry_from_mt (u32 si, u32 di)
575 fwd_entry_mt_arg_t a;
577 memset (&a, 0, sizeof (a));
581 vl_api_rpc_call_main_thread (dp_add_fwd_entry_thread_fn,
582 (u8 *) & a, sizeof (a));
587 * Returns vector of adjacencies.
589 * The caller must free the vector returned by this function.
591 * @param vni virtual network identifier
592 * @return vector of adjacencies
595 vnet_lisp_adjacencies_get_by_vni (u32 vni)
597 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
599 lisp_adjacency_t *adjs = 0, adj;
602 pool_foreach(fwd, lcm->fwd_entry_pool,
604 if (gid_address_vni (&fwd->reid) != vni)
607 gid_address_copy (&adj.reid, &fwd->reid);
608 gid_address_copy (&adj.leid, &fwd->leid);
609 vec_add1 (adjs, adj);
617 get_map_server (ip_address_t * a)
619 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
622 vec_foreach (m, lcm->map_servers)
624 if (!ip_address_cmp (&m->address, a))
633 get_map_resolver (ip_address_t * a)
635 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
638 vec_foreach (m, lcm->map_resolvers)
640 if (!ip_address_cmp (&m->address, a))
649 vnet_lisp_add_del_map_server (ip_address_t * addr, u8 is_add)
652 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
653 lisp_msmr_t _ms, *ms = &_ms;
655 if (vnet_lisp_enable_disable_status () == 0)
657 clib_warning ("LISP is disabled!");
658 return VNET_API_ERROR_LISP_DISABLED;
663 if (get_map_server (addr))
665 clib_warning ("map-server %U already exists!", format_ip_address,
670 memset (ms, 0, sizeof (*ms));
671 ip_address_copy (&ms->address, addr);
672 vec_add1 (lcm->map_servers, ms[0]);
674 if (vec_len (lcm->map_servers) == 1)
675 lcm->do_map_server_election = 1;
679 for (i = 0; i < vec_len (lcm->map_servers); i++)
681 ms = vec_elt_at_index (lcm->map_servers, i);
682 if (!ip_address_cmp (&ms->address, addr))
684 if (!ip_address_cmp (&ms->address, &lcm->active_map_server))
685 lcm->do_map_server_election = 1;
687 vec_del1 (lcm->map_servers, i);
697 * Add/remove mapping to/from map-cache. Overwriting not allowed.
700 vnet_lisp_map_cache_add_del (vnet_lisp_add_del_mapping_args_t * a,
701 u32 * map_index_result)
703 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
704 u32 mi, *map_indexp, map_index, i;
705 mapping_t *m, *old_map;
708 if (gid_address_type (&a->eid) == GID_ADDR_NSH)
710 if (gid_address_vni (&a->eid) != 0)
712 clib_warning ("Supported only default VNI for NSH!");
713 return VNET_API_ERROR_INVALID_ARGUMENT;
715 if (gid_address_nsh_spi (&a->eid) > MAX_VALUE_U24)
717 clib_warning ("SPI is greater than 24bit!");
718 return VNET_API_ERROR_INVALID_ARGUMENT;
722 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &a->eid);
723 old_map = mi != ~0 ? pool_elt_at_index (lcm->mapping_pool, mi) : 0;
726 /* TODO check if overwriting and take appropriate actions */
727 if (mi != GID_LOOKUP_MISS && !gid_address_cmp (&old_map->eid, &a->eid))
729 clib_warning ("eid %U found in the eid-table", format_gid_address,
731 return VNET_API_ERROR_VALUE_EXIST;
734 pool_get (lcm->mapping_pool, m);
735 gid_address_copy (&m->eid, &a->eid);
736 m->locator_set_index = a->locator_set_index;
738 m->action = a->action;
740 m->is_static = a->is_static;
741 m->key = vec_dup (a->key);
742 m->key_id = a->key_id;
744 map_index = m - lcm->mapping_pool;
745 gid_dictionary_add_del (&lcm->mapping_index_by_gid, &a->eid, map_index,
748 if (pool_is_free_index (lcm->locator_set_pool, a->locator_set_index))
750 clib_warning ("Locator set with index %d doesn't exist",
751 a->locator_set_index);
752 return VNET_API_ERROR_INVALID_VALUE;
755 /* add eid to list of eids supported by locator-set */
756 vec_validate (lcm->locator_set_to_eids, a->locator_set_index);
757 eid_indexes = vec_elt_at_index (lcm->locator_set_to_eids,
758 a->locator_set_index);
759 vec_add1 (eid_indexes[0], map_index);
764 vec_add1 (lcm->local_mappings_indexes, map_index);
766 map_index_result[0] = map_index;
770 if (mi == GID_LOOKUP_MISS)
772 clib_warning ("eid %U not found in the eid-table",
773 format_gid_address, &a->eid);
774 return VNET_API_ERROR_INVALID_VALUE;
777 /* clear locator-set to eids binding */
778 eid_indexes = vec_elt_at_index (lcm->locator_set_to_eids,
779 a->locator_set_index);
780 for (i = 0; i < vec_len (eid_indexes[0]); i++)
782 map_indexp = vec_elt_at_index (eid_indexes[0], i);
783 if (map_indexp[0] == mi)
786 vec_del1 (eid_indexes[0], i);
788 /* remove local mark if needed */
789 m = pool_elt_at_index (lcm->mapping_pool, mi);
793 for (k = 0; k < vec_len (lcm->local_mappings_indexes); k++)
795 lm_indexp = vec_elt_at_index (lcm->local_mappings_indexes, k);
796 if (lm_indexp[0] == mi)
799 vec_del1 (lcm->local_mappings_indexes, k);
802 /* remove mapping from dictionary */
803 gid_dictionary_add_del (&lcm->mapping_index_by_gid, &a->eid, 0, 0);
804 gid_address_free (&m->eid);
805 pool_put_index (lcm->mapping_pool, mi);
812 * Add/update/delete mapping to/in/from map-cache.
815 vnet_lisp_add_del_local_mapping (vnet_lisp_add_del_mapping_args_t * a,
816 u32 * map_index_result)
822 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
824 if (vnet_lisp_enable_disable_status () == 0)
826 clib_warning ("LISP is disabled!");
827 return VNET_API_ERROR_LISP_DISABLED;
830 vni = gid_address_vni (&a->eid);
831 type = gid_address_type (&a->eid);
832 if (GID_ADDR_IP_PREFIX == type)
833 dp_table = hash_get (lcm->table_id_by_vni, vni);
834 else if (GID_ADDR_MAC == type)
835 dp_table = hash_get (lcm->bd_id_by_vni, vni);
837 if (!dp_table && GID_ADDR_NSH != type)
839 clib_warning ("vni %d not associated to a %s!", vni,
840 GID_ADDR_IP_PREFIX == type ? "vrf" : "bd");
841 return VNET_API_ERROR_INVALID_VALUE;
844 /* store/remove mapping from map-cache */
845 return vnet_lisp_map_cache_add_del (a, map_index_result);
849 add_l2_arp_bd (BVT (clib_bihash_kv) * kvp, void *arg)
852 u32 bd = (u32) kvp->key[0];
853 hash_set (ht[0], bd, 0);
857 vnet_lisp_l2_arp_bds_get (void)
859 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
862 gid_dict_foreach_l2_arp_entry (&lcm->mapping_index_by_gid,
863 add_l2_arp_bd, &bds);
871 } lisp_add_l2_arp_args_t;
874 add_l2_arp_entry (BVT (clib_bihash_kv) * kvp, void *arg)
876 lisp_add_l2_arp_args_t *a = arg;
877 lisp_api_l2_arp_entry_t **vector = a->vector, e;
879 if ((u32) kvp->key[0] == a->bd)
881 mac_copy (e.mac, (void *) &kvp->value);
882 e.ip4 = (u32) kvp->key[1];
883 vec_add1 (vector[0], e);
887 lisp_api_l2_arp_entry_t *
888 vnet_lisp_l2_arp_entries_get_by_bd (u32 bd)
890 lisp_api_l2_arp_entry_t *entries = 0;
891 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
892 lisp_add_l2_arp_args_t a;
897 gid_dict_foreach_l2_arp_entry (&lcm->mapping_index_by_gid,
898 add_l2_arp_entry, &a);
903 vnet_lisp_add_del_l2_arp_entry (gid_address_t * key, u8 * mac, u8 is_add)
905 if (vnet_lisp_enable_disable_status () == 0)
907 clib_warning ("LISP is disabled!");
908 return VNET_API_ERROR_LISP_DISABLED;
911 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
914 u64 res = gid_dictionary_lookup (&lcm->mapping_index_by_gid, key);
917 if (res != GID_LOOKUP_MISS_L2)
919 clib_warning ("Entry %U exists in DB!", format_gid_address, key);
920 return VNET_API_ERROR_ENTRY_ALREADY_EXISTS;
922 u64 val = mac_to_u64 (mac);
923 gid_dictionary_add_del (&lcm->mapping_index_by_gid, key, val,
928 if (res == GID_LOOKUP_MISS_L2)
930 clib_warning ("ONE ARP entry %U not found - cannot delete!",
931 format_gid_address, key);
934 gid_dictionary_add_del (&lcm->mapping_index_by_gid, key, 0,
942 vnet_lisp_eid_table_map (u32 vni, u32 dp_id, u8 is_l2, u8 is_add)
944 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
945 uword *dp_idp, *vnip, **dp_table_by_vni, **vni_by_dp_table;
947 if (vnet_lisp_enable_disable_status () == 0)
949 clib_warning ("LISP is disabled!");
950 return VNET_API_ERROR_LISP_DISABLED;
953 dp_table_by_vni = is_l2 ? &lcm->bd_id_by_vni : &lcm->table_id_by_vni;
954 vni_by_dp_table = is_l2 ? &lcm->vni_by_bd_id : &lcm->vni_by_table_id;
956 if (!is_l2 && (vni == 0 || dp_id == 0))
958 clib_warning ("can't add/del default vni-vrf mapping!");
962 dp_idp = hash_get (dp_table_by_vni[0], vni);
963 vnip = hash_get (vni_by_dp_table[0], dp_id);
969 clib_warning ("vni %d or vrf %d already used in vrf/vni "
970 "mapping!", vni, dp_id);
973 hash_set (dp_table_by_vni[0], vni, dp_id);
974 hash_set (vni_by_dp_table[0], dp_id, vni);
976 /* create dp iface */
977 dp_add_del_iface (lcm, vni, is_l2, 1);
981 if (!dp_idp || !vnip)
983 clib_warning ("vni %d or vrf %d not used in any vrf/vni! "
984 "mapping!", vni, dp_id);
987 /* remove dp iface */
988 dp_add_del_iface (lcm, vni, is_l2, 0);
990 hash_unset (dp_table_by_vni[0], vni);
991 hash_unset (vni_by_dp_table[0], dp_id);
997 /* return 0 if the two locator sets are identical 1 otherwise */
999 compare_locators (lisp_cp_main_t * lcm, u32 * old_ls_indexes,
1000 locator_t * new_locators)
1003 locator_t *old_loc, *new_loc;
1005 if (vec_len (old_ls_indexes) != vec_len (new_locators))
1008 for (i = 0; i < vec_len (new_locators); i++)
1010 old_li = vec_elt (old_ls_indexes, i);
1011 old_loc = pool_elt_at_index (lcm->locator_pool, old_li);
1013 new_loc = vec_elt_at_index (new_locators, i);
1015 if (locator_cmp (old_loc, new_loc))
1025 gid_address_t *eids_to_be_deleted;
1026 } remove_mapping_args_t;
1029 * Callback invoked when a sub-prefix is found
1032 remove_mapping_if_needed (u32 mi, void *arg)
1035 remove_mapping_args_t *a = arg;
1036 lisp_cp_main_t *lcm = a->lcm;
1040 m = pool_elt_at_index (lcm->mapping_pool, mi);
1044 ls = pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
1048 if (0 != vec_len (ls->locator_indices))
1053 if (0 == vec_len (ls->locator_indices))
1058 vec_add1 (a->eids_to_be_deleted, m->eid);
1062 * This function searches map cache and looks for IP prefixes that are subset
1063 * of the provided one. If such prefix is found depending on 'is_negative'
1066 * 1) if is_negative is true and found prefix points to positive mapping,
1067 * then the mapping is removed
1068 * 2) if is_negative is false and found prefix points to negative mapping,
1069 * then the mapping is removed
1072 remove_overlapping_sub_prefixes (lisp_cp_main_t * lcm, gid_address_t * eid,
1076 remove_mapping_args_t a;
1078 memset (&a, 0, sizeof (a));
1080 /* do this only in src/dst mode ... */
1081 if (MR_MODE_SRC_DST != lcm->map_request_mode)
1084 /* ... and only for IP prefix */
1085 if (GID_ADDR_SRC_DST != gid_address_type (eid)
1086 || (FID_ADDR_IP_PREF != gid_address_sd_dst_type (eid)))
1089 a.is_negative = is_negative;
1092 gid_dict_foreach_subprefix (&lcm->mapping_index_by_gid, eid,
1093 remove_mapping_if_needed, &a);
1095 vec_foreach (e, a.eids_to_be_deleted)
1097 vnet_lisp_add_del_adjacency_args_t _adj_args, *adj_args = &_adj_args;
1099 memset (adj_args, 0, sizeof (adj_args[0]));
1100 gid_address_copy (&adj_args->reid, e);
1101 adj_args->is_add = 0;
1102 if (vnet_lisp_add_del_adjacency (adj_args))
1103 clib_warning ("failed to del adjacency!");
1105 vnet_lisp_add_del_mapping (e, 0, 0, 0, 0, 0 /* is add */ , 0, 0);
1108 vec_free (a.eids_to_be_deleted);
1112 mapping_delete_timer (lisp_cp_main_t * lcm, u32 mi)
1114 timing_wheel_delete (&lcm->wheel, mi);
1118 is_local_ip (lisp_cp_main_t * lcm, ip_address_t * addr)
1120 fib_node_index_t fei;
1121 fib_prefix_t prefix;
1122 fib_entry_flag_t flags;
1124 ip_address_to_fib_prefix (addr, &prefix);
1126 fei = fib_table_lookup (0, &prefix);
1127 flags = fib_entry_get_flags (fei);
1128 return (FIB_ENTRY_FLAG_LOCAL & flags);
1132 * Adds/removes/updates mapping. Does not program forwarding.
1134 * @param eid end-host identifier
1135 * @param rlocs vector of remote locators
1136 * @param action action for negative map-reply
1137 * @param is_add add mapping if non-zero, delete otherwise
1138 * @param res_map_index the map-index that was created/updated/removed. It is
1139 * set to ~0 if no action is taken.
1140 * @param is_static used for distinguishing between statically learned
1141 remote mappings and mappings obtained from MR
1142 * @return return code
1145 vnet_lisp_add_del_mapping (gid_address_t * eid, locator_t * rlocs, u8 action,
1146 u8 authoritative, u32 ttl, u8 is_add, u8 is_static,
1147 u32 * res_map_index)
1149 vnet_lisp_add_del_mapping_args_t _m_args, *m_args = &_m_args;
1150 vnet_lisp_add_del_locator_set_args_t _ls_args, *ls_args = &_ls_args;
1151 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1152 u32 mi, ls_index = 0, dst_map_index;
1156 if (vnet_lisp_enable_disable_status () == 0)
1158 clib_warning ("LISP is disabled!");
1159 return VNET_API_ERROR_LISP_DISABLED;
1163 res_map_index[0] = ~0;
1165 memset (m_args, 0, sizeof (m_args[0]));
1166 memset (ls_args, 0, sizeof (ls_args[0]));
1168 ls_args->locators = rlocs;
1170 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
1171 old_map = ((u32) ~ 0 != mi) ? pool_elt_at_index (lcm->mapping_pool, mi) : 0;
1175 /* check if none of the locators match localy configured address */
1176 vec_foreach (loc, rlocs)
1178 ip_prefix_t *p = &gid_address_ippref (&loc->address);
1179 if (is_local_ip (lcm, &ip_prefix_addr (p)))
1181 clib_warning ("RLOC %U matches a local address!",
1182 format_gid_address, &loc->address);
1183 return VNET_API_ERROR_LISP_RLOC_LOCAL;
1187 /* overwrite: if mapping already exists, decide if locators should be
1188 * updated and be done */
1189 if (old_map && gid_address_cmp (&old_map->eid, eid) == 0)
1191 if (!is_static && (old_map->is_static || old_map->local))
1193 /* do not overwrite local or static remote mappings */
1194 clib_warning ("mapping %U rejected due to collision with local "
1195 "or static remote mapping!", format_gid_address,
1200 locator_set_t *old_ls;
1202 /* update mapping attributes */
1203 old_map->action = action;
1204 old_map->authoritative = authoritative;
1207 old_ls = pool_elt_at_index (lcm->locator_set_pool,
1208 old_map->locator_set_index);
1209 if (compare_locators (lcm, old_ls->locator_indices,
1212 /* set locator-set index to overwrite */
1213 ls_args->is_add = 1;
1214 ls_args->index = old_map->locator_set_index;
1215 vnet_lisp_add_del_locator_set (ls_args, 0);
1217 res_map_index[0] = mi;
1223 remove_overlapping_sub_prefixes (lcm, eid, 0 == ls_args->locators);
1225 ls_args->is_add = 1;
1226 ls_args->index = ~0;
1228 vnet_lisp_add_del_locator_set (ls_args, &ls_index);
1231 gid_address_copy (&m_args->eid, eid);
1233 m_args->action = action;
1234 m_args->locator_set_index = ls_index;
1235 m_args->is_static = is_static;
1237 vnet_lisp_map_cache_add_del (m_args, &dst_map_index);
1240 res_map_index[0] = dst_map_index;
1245 if (old_map == 0 || gid_address_cmp (&old_map->eid, eid) != 0)
1247 clib_warning ("cannot delete mapping for eid %U",
1248 format_gid_address, eid);
1253 gid_address_copy (&m_args->eid, eid);
1254 m_args->locator_set_index = old_map->locator_set_index;
1256 /* delete mapping associated from map-cache */
1257 vnet_lisp_map_cache_add_del (m_args, 0);
1259 ls_args->is_add = 0;
1260 ls_args->index = old_map->locator_set_index;
1261 /* delete locator set */
1262 vnet_lisp_add_del_locator_set (ls_args, 0);
1264 /* delete timer associated to the mapping if any */
1265 if (old_map->timer_set)
1266 mapping_delete_timer (lcm, mi);
1268 /* return old mapping index */
1270 res_map_index[0] = mi;
1278 vnet_lisp_clear_all_remote_adjacencies (void)
1281 u32 mi, *map_indices = 0, *map_indexp;
1282 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1283 vnet_lisp_add_del_mapping_args_t _dm_args, *dm_args = &_dm_args;
1284 vnet_lisp_add_del_locator_set_args_t _ls, *ls = &_ls;
1287 pool_foreach_index (mi, lcm->mapping_pool,
1289 vec_add1 (map_indices, mi);
1293 vec_foreach (map_indexp, map_indices)
1295 mapping_t *map = pool_elt_at_index (lcm->mapping_pool, map_indexp[0]);
1298 dp_del_fwd_entry (lcm, 0, map_indexp[0]);
1300 dm_args->is_add = 0;
1301 gid_address_copy (&dm_args->eid, &map->eid);
1302 dm_args->locator_set_index = map->locator_set_index;
1304 /* delete mapping associated to fwd entry */
1305 vnet_lisp_map_cache_add_del (dm_args, 0);
1309 ls->index = map->locator_set_index;
1310 /* delete locator set */
1311 rv = vnet_lisp_add_del_locator_set (ls, 0);
1319 vec_free (map_indices);
1324 * Adds adjacency or removes forwarding entry associated to remote mapping.
1325 * Note that adjacencies are not stored, they only result in forwarding entries
1329 vnet_lisp_add_del_adjacency (vnet_lisp_add_del_adjacency_args_t * a)
1331 lisp_cp_main_t *lcm = &lisp_control_main;
1332 u32 local_mi, remote_mi = ~0;
1334 if (vnet_lisp_enable_disable_status () == 0)
1336 clib_warning ("LISP is disabled!");
1337 return VNET_API_ERROR_LISP_DISABLED;
1340 remote_mi = gid_dictionary_sd_lookup (&lcm->mapping_index_by_gid,
1341 &a->reid, &a->leid);
1342 if (GID_LOOKUP_MISS == remote_mi)
1344 clib_warning ("Remote eid %U not found. Cannot add adjacency!",
1345 format_gid_address, &a->reid);
1352 /* check if source eid has an associated mapping. If pitr mode is on,
1353 * just use the pitr's mapping */
1355 local_mi = lcm->pitr_map_index;
1358 if (gid_address_type (&a->reid) == GID_ADDR_NSH)
1360 if (lcm->nsh_map_index == ~0)
1361 local_mi = GID_LOOKUP_MISS;
1363 local_mi = lcm->nsh_map_index;
1367 local_mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid,
1372 if (GID_LOOKUP_MISS == local_mi)
1374 clib_warning ("Local eid %U not found. Cannot add adjacency!",
1375 format_gid_address, &a->leid);
1380 /* update forwarding */
1381 dp_add_fwd_entry (lcm, local_mi, remote_mi);
1384 dp_del_fwd_entry (lcm, 0, remote_mi);
1390 vnet_lisp_set_map_request_mode (u8 mode)
1392 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1394 if (vnet_lisp_enable_disable_status () == 0)
1396 clib_warning ("LISP is disabled!");
1397 return VNET_API_ERROR_LISP_DISABLED;
1400 if (mode >= _MR_MODE_MAX)
1402 clib_warning ("Invalid LISP map request mode %d!", mode);
1403 return VNET_API_ERROR_INVALID_ARGUMENT;
1406 lcm->map_request_mode = mode;
1411 vnet_lisp_nsh_set_locator_set (u8 * locator_set_name, u8 is_add)
1413 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1414 lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main ();
1415 u32 locator_set_index = ~0;
1419 if (vnet_lisp_enable_disable_status () == 0)
1421 clib_warning ("LISP is disabled!");
1422 return VNET_API_ERROR_LISP_DISABLED;
1427 if (lcm->nsh_map_index == (u32) ~ 0)
1429 p = hash_get_mem (lcm->locator_set_index_by_name, locator_set_name);
1432 clib_warning ("locator-set %v doesn't exist", locator_set_name);
1435 locator_set_index = p[0];
1437 pool_get (lcm->mapping_pool, m);
1438 memset (m, 0, sizeof *m);
1439 m->locator_set_index = locator_set_index;
1442 lcm->nsh_map_index = m - lcm->mapping_pool;
1444 if (~0 == vnet_lisp_gpe_add_nsh_iface (lgm))
1450 if (lcm->nsh_map_index != (u32) ~ 0)
1452 /* remove NSH mapping */
1453 pool_put_index (lcm->mapping_pool, lcm->nsh_map_index);
1454 lcm->nsh_map_index = ~0;
1455 vnet_lisp_gpe_del_nsh_iface (lgm);
1462 vnet_lisp_pitr_set_locator_set (u8 * locator_set_name, u8 is_add)
1464 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1465 u32 locator_set_index = ~0;
1469 if (vnet_lisp_enable_disable_status () == 0)
1471 clib_warning ("LISP is disabled!");
1472 return VNET_API_ERROR_LISP_DISABLED;
1475 p = hash_get_mem (lcm->locator_set_index_by_name, locator_set_name);
1478 clib_warning ("locator-set %v doesn't exist", locator_set_name);
1481 locator_set_index = p[0];
1485 pool_get (lcm->mapping_pool, m);
1486 m->locator_set_index = locator_set_index;
1489 lcm->pitr_map_index = m - lcm->mapping_pool;
1491 /* enable pitr mode */
1496 /* remove pitr mapping */
1497 pool_put_index (lcm->mapping_pool, lcm->pitr_map_index);
1499 /* disable pitr mode */
1506 vnet_lisp_map_register_fallback_threshold_set (u32 value)
1508 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1511 return VNET_API_ERROR_INVALID_ARGUMENT;
1514 lcm->max_expired_map_registers = value;
1519 vnet_lisp_map_register_fallback_threshold_get (void)
1521 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1522 return lcm->max_expired_map_registers;
1526 * Configure Proxy-ETR
1528 * @param ip PETR's IP address
1529 * @param is_add Flag that indicates if this is an addition or removal
1531 * return 0 on success
1534 vnet_lisp_use_petr (ip_address_t * ip, u8 is_add)
1536 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1539 vnet_lisp_add_del_locator_set_args_t _ls_args, *ls_args = &_ls_args;
1542 if (vnet_lisp_enable_disable_status () == 0)
1544 clib_warning ("LISP is disabled!");
1545 return VNET_API_ERROR_LISP_DISABLED;
1548 memset (ls_args, 0, sizeof (*ls_args));
1552 /* Create dummy petr locator-set */
1553 memset (&loc, 0, sizeof (loc));
1554 gid_address_from_ip (&loc.address, ip);
1556 loc.state = loc.weight = 1;
1559 ls_args->is_add = 1;
1560 ls_args->index = ~0;
1561 vec_add1 (ls_args->locators, loc);
1562 vnet_lisp_add_del_locator_set (ls_args, &ls_index);
1564 /* Add petr mapping */
1565 pool_get (lcm->mapping_pool, m);
1566 m->locator_set_index = ls_index;
1567 lcm->petr_map_index = m - lcm->mapping_pool;
1569 /* Enable use-petr */
1570 lcm->flags |= LISP_FLAG_USE_PETR;
1574 m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index);
1576 /* Remove petr locator */
1577 ls_args->is_add = 0;
1578 ls_args->index = m->locator_set_index;
1579 vnet_lisp_add_del_locator_set (ls_args, 0);
1581 /* Remove petr mapping */
1582 pool_put_index (lcm->mapping_pool, lcm->petr_map_index);
1584 /* Disable use-petr */
1585 lcm->flags &= ~LISP_FLAG_USE_PETR;
1590 /* cleans locator to locator-set data and removes locators not part of
1591 * any locator-set */
1593 clean_locator_to_locator_set (lisp_cp_main_t * lcm, u32 lsi)
1595 u32 i, j, *loc_indexp, *ls_indexp, **ls_indexes, *to_be_deleted = 0;
1596 locator_set_t *ls = pool_elt_at_index (lcm->locator_set_pool, lsi);
1597 for (i = 0; i < vec_len (ls->locator_indices); i++)
1599 loc_indexp = vec_elt_at_index (ls->locator_indices, i);
1600 ls_indexes = vec_elt_at_index (lcm->locator_to_locator_sets,
1602 for (j = 0; j < vec_len (ls_indexes[0]); j++)
1604 ls_indexp = vec_elt_at_index (ls_indexes[0], j);
1605 if (ls_indexp[0] == lsi)
1609 /* delete index for removed locator-set */
1610 vec_del1 (ls_indexes[0], j);
1612 /* delete locator if it's part of no locator-set */
1613 if (vec_len (ls_indexes[0]) == 0)
1615 pool_put_index (lcm->locator_pool, loc_indexp[0]);
1616 vec_add1 (to_be_deleted, i);
1622 for (i = 0; i < vec_len (to_be_deleted); i++)
1624 loc_indexp = vec_elt_at_index (to_be_deleted, i);
1625 vec_del1 (ls->locator_indices, loc_indexp[0]);
1627 vec_free (to_be_deleted);
1631 static inline uword *
1632 get_locator_set_index (vnet_lisp_add_del_locator_set_args_t * a, uword * p)
1634 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1639 /* find locator-set */
1642 p = hash_get_mem (lcm->locator_set_index_by_name, a->name);
1653 is_locator_in_locator_set (lisp_cp_main_t * lcm, locator_set_t * ls,
1659 ASSERT (ls != NULL);
1660 ASSERT (loc != NULL);
1662 vec_foreach (locit, ls->locator_indices)
1664 itloc = pool_elt_at_index (lcm->locator_pool, locit[0]);
1665 if ((ls->local && itloc->sw_if_index == loc->sw_if_index) ||
1666 (!ls->local && !gid_address_cmp (&itloc->address, &loc->address)))
1668 clib_warning ("Duplicate locator");
1669 return VNET_API_ERROR_VALUE_EXIST;
1677 update_adjacencies_by_map_index (lisp_cp_main_t * lcm, u8 is_local,
1678 u32 mapping_index, u8 remove_only)
1682 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
1684 map = pool_elt_at_index (lcm->mapping_pool, mapping_index);
1687 pool_foreach(fwd, lcm->fwd_entry_pool,
1689 if ((is_local && 0 == gid_address_cmp (&map->eid, &fwd->leid)) ||
1690 (!is_local && 0 == gid_address_cmp (&map->eid, &fwd->reid)))
1693 gid_address_copy (&a->leid, &fwd->leid);
1694 gid_address_copy (&a->reid, &fwd->reid);
1696 vnet_lisp_add_del_adjacency (a);
1701 vnet_lisp_add_del_adjacency (a);
1709 update_fwd_entries_by_locator_set (lisp_cp_main_t * lcm, u8 is_local,
1710 u32 ls_index, u8 remove_only)
1715 if (vec_len (lcm->locator_set_to_eids) <= ls_index)
1718 eid_indexes = vec_elt_at_index (lcm->locator_set_to_eids, ls_index);
1720 for (i = 0; i < vec_len (eid_indexes[0]); i++)
1722 map_indexp = vec_elt_at_index (eid_indexes[0], i);
1723 update_adjacencies_by_map_index (lcm, is_local, map_indexp[0],
1729 remove_locator_from_locator_set (locator_set_t * ls, u32 * locit,
1730 u32 ls_index, u32 loc_id)
1732 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1733 u32 **ls_indexes = NULL;
1735 ASSERT (ls != NULL);
1736 ASSERT (locit != NULL);
1738 ls_indexes = vec_elt_at_index (lcm->locator_to_locator_sets, locit[0]);
1739 pool_put_index (lcm->locator_pool, locit[0]);
1740 vec_del1 (ls->locator_indices, loc_id);
1741 vec_del1 (ls_indexes[0], ls_index);
1745 vnet_lisp_add_del_locator (vnet_lisp_add_del_locator_set_args_t * a,
1746 locator_set_t * ls, u32 * ls_result)
1748 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1749 locator_t *loc = NULL, *itloc = NULL;
1750 uword _p = (u32) ~ 0, *p = &_p;
1751 u32 loc_index = ~0, ls_index = ~0, *locit = NULL, **ls_indexes = NULL;
1757 if (vnet_lisp_enable_disable_status () == 0)
1759 clib_warning ("LISP is disabled!");
1760 return VNET_API_ERROR_LISP_DISABLED;
1763 p = get_locator_set_index (a, p);
1766 clib_warning ("locator-set %v doesn't exist", a->name);
1767 return VNET_API_ERROR_INVALID_ARGUMENT;
1772 ls = pool_elt_at_index (lcm->locator_set_pool, p[0]);
1775 clib_warning ("locator-set %d to be overwritten doesn't exist!",
1777 return VNET_API_ERROR_INVALID_ARGUMENT;
1784 ls_result[0] = p[0];
1786 /* allocate locators */
1787 vec_foreach (itloc, a->locators)
1789 ret = is_locator_in_locator_set (lcm, ls, itloc);
1795 pool_get (lcm->locator_pool, loc);
1797 loc_index = loc - lcm->locator_pool;
1799 vec_add1 (ls->locator_indices, loc_index);
1801 vec_validate (lcm->locator_to_locator_sets, loc_index);
1802 ls_indexes = vec_elt_at_index (lcm->locator_to_locator_sets,
1804 vec_add1 (ls_indexes[0], p[0]);
1812 vec_foreach (itloc, a->locators)
1816 vec_foreach (locit, ls->locator_indices)
1818 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
1820 if (loc->local && loc->sw_if_index == itloc->sw_if_index)
1823 remove_locator_from_locator_set (ls, locit, ls_index, loc_id);
1825 if (0 == loc->local &&
1826 !gid_address_cmp (&loc->address, &itloc->address))
1829 remove_locator_from_locator_set (ls, locit, ls_index, loc_id);
1834 /* update fwd entries using this locator in DP */
1835 update_fwd_entries_by_locator_set (lcm, loc->local, ls_index,
1836 vec_len (ls->locator_indices)
1849 vnet_lisp_add_del_locator_set (vnet_lisp_add_del_locator_set_args_t * a,
1852 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1854 uword _p = (u32) ~ 0, *p = &_p;
1859 if (vnet_lisp_enable_disable_status () == 0)
1861 clib_warning ("LISP is disabled!");
1862 return VNET_API_ERROR_LISP_DISABLED;
1867 p = get_locator_set_index (a, p);
1870 if (p && p[0] != (u32) ~ 0)
1872 ls = pool_elt_at_index (lcm->locator_set_pool, p[0]);
1875 clib_warning ("locator-set %d to be overwritten doesn't exist!",
1880 /* clean locator to locator-set vectors and remove locators if
1881 * they're not part of another locator-set */
1882 clean_locator_to_locator_set (lcm, p[0]);
1884 /* remove locator indices from locator set */
1885 vec_free (ls->locator_indices);
1890 ls_result[0] = p[0];
1892 /* new locator-set */
1895 pool_get (lcm->locator_set_pool, ls);
1896 memset (ls, 0, sizeof (*ls));
1897 ls_index = ls - lcm->locator_set_pool;
1901 ls->name = vec_dup (a->name);
1903 if (!lcm->locator_set_index_by_name)
1904 lcm->locator_set_index_by_name = hash_create_vec (
1912 hash_set_mem (lcm->locator_set_index_by_name, ls->name,
1915 /* mark as local locator-set */
1916 vec_add1 (lcm->local_locator_set_indexes, ls_index);
1918 ls->local = a->local;
1920 ls_result[0] = ls_index;
1923 ret = vnet_lisp_add_del_locator (a, ls, NULL);
1931 p = get_locator_set_index (a, p);
1934 clib_warning ("locator-set %v doesn't exists", a->name);
1938 ls = pool_elt_at_index (lcm->locator_set_pool, p[0]);
1941 clib_warning ("locator-set with index %d doesn't exists", p[0]);
1945 if (lcm->mreq_itr_rlocs == p[0])
1947 clib_warning ("Can't delete the locator-set used to constrain "
1948 "the itr-rlocs in map-requests!");
1952 if (vec_len (lcm->locator_set_to_eids) != 0)
1954 eid_indexes = vec_elt_at_index (lcm->locator_set_to_eids, p[0]);
1955 if (vec_len (eid_indexes[0]) != 0)
1958 ("Can't delete a locator that supports a mapping!");
1963 /* clean locator to locator-sets data */
1964 clean_locator_to_locator_set (lcm, p[0]);
1970 vec_foreach_index (it, lcm->local_locator_set_indexes)
1972 lsi = vec_elt (lcm->local_locator_set_indexes, it);
1975 vec_del1 (lcm->local_locator_set_indexes, it);
1979 hash_unset_mem (lcm->locator_set_index_by_name, ls->name);
1981 vec_free (ls->name);
1982 vec_free (ls->locator_indices);
1983 pool_put (lcm->locator_set_pool, ls);
1989 vnet_lisp_rloc_probe_enable_disable (u8 is_enable)
1991 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1993 lcm->rloc_probing = is_enable;
1998 vnet_lisp_map_register_enable_disable (u8 is_enable)
2000 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
2002 lcm->map_registering = is_enable;
2007 vnet_lisp_enable_disable (u8 is_enable)
2010 clib_error_t *error = 0;
2011 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
2012 vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a;
2014 a->is_en = is_enable;
2015 error = vnet_lisp_gpe_enable_disable (a);
2018 return clib_error_return (0, "failed to %s data-plane!",
2019 a->is_en ? "enable" : "disable");
2024 /* enable all l2 and l3 ifaces */
2027 hash_foreach(vni, dp_table, lcm->table_id_by_vni, ({
2028 dp_add_del_iface(lcm, vni, 0, 1);
2030 hash_foreach(vni, dp_table, lcm->bd_id_by_vni, ({
2031 dp_add_del_iface(lcm, vni, /* is_l2 */ 1, 1);
2037 /* clear interface table */
2038 hash_free (lcm->fwd_entry_by_mapping_index);
2039 pool_free (lcm->fwd_entry_pool);
2042 /* update global flag */
2043 lcm->is_enabled = is_enable;
2049 vnet_lisp_enable_disable_status (void)
2051 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
2052 return lcm->is_enabled;
2056 vnet_lisp_add_del_map_resolver (vnet_lisp_add_del_map_resolver_args_t * a)
2058 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
2060 lisp_msmr_t _mr, *mr = &_mr;
2062 if (vnet_lisp_enable_disable_status () == 0)
2064 clib_warning ("LISP is disabled!");
2065 return VNET_API_ERROR_LISP_DISABLED;
2071 if (get_map_resolver (&a->address))
2073 clib_warning ("map-resolver %U already exists!", format_ip_address,
2078 memset (mr, 0, sizeof (*mr));
2079 ip_address_copy (&mr->address, &a->address);
2080 vec_add1 (lcm->map_resolvers, *mr);
2082 if (vec_len (lcm->map_resolvers) == 1)
2083 lcm->do_map_resolver_election = 1;
2087 for (i = 0; i < vec_len (lcm->map_resolvers); i++)
2089 mr = vec_elt_at_index (lcm->map_resolvers, i);
2090 if (!ip_address_cmp (&mr->address, &a->address))
2092 if (!ip_address_cmp (&mr->address, &lcm->active_map_resolver))
2093 lcm->do_map_resolver_election = 1;
2095 vec_del1 (lcm->map_resolvers, i);
2104 vnet_lisp_map_register_set_ttl (u32 ttl)
2106 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
2107 lcm->map_register_ttl = ttl;
2112 vnet_lisp_map_register_get_ttl (void)
2114 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
2115 return lcm->map_register_ttl;
2119 vnet_lisp_add_del_mreq_itr_rlocs (vnet_lisp_add_del_mreq_itr_rloc_args_t * a)
2121 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
2124 if (vnet_lisp_enable_disable_status () == 0)
2126 clib_warning ("LISP is disabled!");
2127 return VNET_API_ERROR_LISP_DISABLED;
2132 p = hash_get_mem (lcm->locator_set_index_by_name, a->locator_set_name);
2135 clib_warning ("locator-set %v doesn't exist", a->locator_set_name);
2136 return VNET_API_ERROR_INVALID_ARGUMENT;
2139 lcm->mreq_itr_rlocs = p[0];
2143 lcm->mreq_itr_rlocs = ~0;
2149 /* Statistics (not really errors) */
2150 #define foreach_lisp_cp_lookup_error \
2152 _(MAP_REQUESTS_SENT, "map-request sent") \
2153 _(ARP_REPLY_TX, "ARP replies sent")
2155 static char *lisp_cp_lookup_error_strings[] = {
2156 #define _(sym,string) string,
2157 foreach_lisp_cp_lookup_error
2163 #define _(sym,str) LISP_CP_LOOKUP_ERROR_##sym,
2164 foreach_lisp_cp_lookup_error
2166 LISP_CP_LOOKUP_N_ERROR,
2167 } lisp_cp_lookup_error_t;
2171 LISP_CP_LOOKUP_NEXT_DROP,
2172 LISP_CP_LOOKUP_NEXT_ARP_REPLY_TX,
2173 LISP_CP_LOOKUP_N_NEXT,
2174 } lisp_cp_lookup_next_t;
2178 gid_address_t dst_eid;
2179 ip_address_t map_resolver_ip;
2180 } lisp_cp_lookup_trace_t;
2183 format_lisp_cp_lookup_trace (u8 * s, va_list * args)
2185 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
2186 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
2187 lisp_cp_lookup_trace_t *t = va_arg (*args, lisp_cp_lookup_trace_t *);
2189 s = format (s, "LISP-CP-LOOKUP: map-resolver: %U destination eid %U",
2190 format_ip_address, &t->map_resolver_ip, format_gid_address,
2196 get_mr_and_local_iface_ip (lisp_cp_main_t * lcm, ip_address_t * mr_ip,
2197 ip_address_t * sloc)
2202 if (vec_len (lcm->map_resolvers) == 0)
2204 clib_warning ("No map-resolver configured");
2208 /* find the first mr ip we have a route to and the ip of the
2209 * iface that has a route to it */
2210 vec_foreach (mrit, lcm->map_resolvers)
2213 if (0 != ip_fib_get_first_egress_ip_for_dst (lcm, a, sloc))
2215 ip_address_copy (mr_ip, a);
2217 /* also update globals */
2222 clib_warning ("Can't find map-resolver and local interface ip!");
2226 static gid_address_t *
2227 build_itr_rloc_list (lisp_cp_main_t * lcm, locator_set_t * loc_set)
2233 ip_interface_address_t *ia = 0;
2234 gid_address_t gid_data, *gid = &gid_data;
2235 gid_address_t *rlocs = 0;
2236 ip_prefix_t *ippref = &gid_address_ippref (gid);
2237 ip_address_t *rloc = &ip_prefix_addr (ippref);
2239 memset (gid, 0, sizeof (gid[0]));
2240 gid_address_type (gid) = GID_ADDR_IP_PREFIX;
2241 for (i = 0; i < vec_len (loc_set->locator_indices); i++)
2243 loc_indexp = vec_elt_at_index (loc_set->locator_indices, i);
2244 loc = pool_elt_at_index (lcm->locator_pool, loc_indexp[0]);
2246 /* Add ipv4 locators first TODO sort them */
2249 foreach_ip_interface_address (&lcm->im4->lookup_main, ia,
2250 loc->sw_if_index, 1 /* unnumbered */,
2252 addr = ip_interface_address_get_address (&lcm->im4->lookup_main, ia);
2253 ip_address_set (rloc, addr, IP4);
2254 ip_prefix_len (ippref) = 32;
2255 ip_prefix_normalize (ippref);
2256 vec_add1 (rlocs, gid[0]);
2259 /* Add ipv6 locators */
2260 foreach_ip_interface_address (&lcm->im6->lookup_main, ia,
2261 loc->sw_if_index, 1 /* unnumbered */,
2263 addr = ip_interface_address_get_address (&lcm->im6->lookup_main, ia);
2264 ip_address_set (rloc, addr, IP6);
2265 ip_prefix_len (ippref) = 128;
2266 ip_prefix_normalize (ippref);
2267 vec_add1 (rlocs, gid[0]);
2275 static vlib_buffer_t *
2276 build_map_request (lisp_cp_main_t * lcm, gid_address_t * deid,
2277 ip_address_t * sloc, ip_address_t * rloc,
2278 gid_address_t * itr_rlocs, u64 * nonce_res, u32 * bi_res)
2282 vlib_main_t *vm = lcm->vlib_main;
2284 if (vlib_buffer_alloc (vm, &bi, 1) != 1)
2286 clib_warning ("Can't allocate buffer for Map-Request!");
2290 b = vlib_get_buffer (vm, bi);
2292 /* leave some space for the encap headers */
2293 vlib_buffer_make_headroom (b, MAX_LISP_MSG_ENCAP_LEN);
2296 lisp_msg_put_mreq (lcm, b, NULL, deid, itr_rlocs, 0 /* smr invoked */ ,
2297 1 /* rloc probe */ , nonce_res);
2299 /* push outer ip header */
2300 pkt_push_udp_and_ip (vm, b, LISP_CONTROL_PORT, LISP_CONTROL_PORT, sloc,
2308 static vlib_buffer_t *
2309 build_encapsulated_map_request (lisp_cp_main_t * lcm,
2310 gid_address_t * seid, gid_address_t * deid,
2311 locator_set_t * loc_set, ip_address_t * mr_ip,
2312 ip_address_t * sloc, u8 is_smr_invoked,
2313 u64 * nonce_res, u32 * bi_res)
2317 gid_address_t *rlocs = 0;
2318 vlib_main_t *vm = lcm->vlib_main;
2320 if (vlib_buffer_alloc (vm, &bi, 1) != 1)
2322 clib_warning ("Can't allocate buffer for Map-Request!");
2326 b = vlib_get_buffer (vm, bi);
2329 /* leave some space for the encap headers */
2330 vlib_buffer_make_headroom (b, MAX_LISP_MSG_ENCAP_LEN);
2333 rlocs = build_itr_rloc_list (lcm, loc_set);
2335 if (MR_MODE_SRC_DST == lcm->map_request_mode
2336 && GID_ADDR_SRC_DST != gid_address_type (deid))
2339 memset (&sd, 0, sizeof (sd));
2340 build_src_dst (&sd, seid, deid);
2341 lisp_msg_put_mreq (lcm, b, seid, &sd, rlocs, is_smr_invoked,
2342 0 /* rloc probe */ , nonce_res);
2347 lisp_msg_put_mreq (lcm, b, seid, deid, rlocs, is_smr_invoked,
2348 0 /* rloc probe */ , nonce_res);
2351 /* push ecm: udp-ip-lisp */
2352 lisp_msg_push_ecm (vm, b, LISP_CONTROL_PORT, LISP_CONTROL_PORT, seid, deid);
2354 /* push outer ip header */
2355 pkt_push_udp_and_ip (vm, b, LISP_CONTROL_PORT, LISP_CONTROL_PORT, sloc,
2365 reset_pending_mr_counters (pending_map_request_t * r)
2367 r->time_to_expire = PENDING_MREQ_EXPIRATION_TIME;
2371 #define foreach_msmr \
2377 elect_map_ ## name (lisp_cp_main_t * lcm) \
2380 vec_foreach (mr, lcm->map_ ## name ## s) \
2384 ip_address_copy (&lcm->active_map_ ##name, &mr->address); \
2385 lcm->do_map_ ## name ## _election = 0; \
2394 free_map_register_records (mapping_t * maps)
2397 vec_foreach (map, maps) vec_free (map->locators);
2403 add_locators (lisp_cp_main_t * lcm, mapping_t * m, u32 locator_set_index,
2404 ip_address_t * probed_loc)
2407 locator_t *loc, new;
2408 ip_interface_address_t *ia = 0;
2410 ip_address_t *new_ip = &gid_address_ip (&new.address);
2413 locator_set_t *ls = pool_elt_at_index (lcm->locator_set_pool,
2415 vec_foreach (li, ls->locator_indices)
2417 loc = pool_elt_at_index (lcm->locator_pool, li[0]);
2422 foreach_ip_interface_address (&lcm->im4->lookup_main, ia,
2423 loc->sw_if_index, 1 /* unnumbered */,
2425 addr = ip_interface_address_get_address (&lcm->im4->lookup_main,
2427 ip_address_set (new_ip, addr, IP4);
2430 /* Add ipv6 locators */
2431 foreach_ip_interface_address (&lcm->im6->lookup_main, ia,
2432 loc->sw_if_index, 1 /* unnumbered */,
2434 addr = ip_interface_address_get_address (&lcm->im6->lookup_main,
2436 ip_address_set (new_ip, addr, IP6);
2440 if (probed_loc && ip_address_cmp (probed_loc, new_ip) == 0)
2443 vec_add1 (m->locators, new);
2448 build_map_register_record_list (lisp_cp_main_t * lcm)
2450 mapping_t *recs = 0, rec, *m;
2453 pool_foreach(m, lcm->mapping_pool,
2455 /* for now build only local mappings */
2460 add_locators (lcm, &rec, m->locator_set_index, NULL);
2461 vec_add1 (recs, rec);
2469 update_map_register_auth_data (map_register_hdr_t * map_reg_hdr,
2470 lisp_key_type_t key_id, u8 * key,
2471 u16 auth_data_len, u32 msg_len)
2473 MREG_KEY_ID (map_reg_hdr) = clib_host_to_net_u16 (key_id);
2474 MREG_AUTH_DATA_LEN (map_reg_hdr) = clib_host_to_net_u16 (auth_data_len);
2476 unsigned char *result = HMAC (get_encrypt_fcn (key_id), key, vec_len (key),
2477 (unsigned char *) map_reg_hdr, msg_len, NULL,
2479 clib_memcpy (MREG_DATA (map_reg_hdr), result, auth_data_len);
2484 static vlib_buffer_t *
2485 build_map_register (lisp_cp_main_t * lcm, ip_address_t * sloc,
2486 ip_address_t * ms_ip, u64 * nonce_res, u8 want_map_notif,
2487 mapping_t * records, lisp_key_type_t key_id, u8 * key,
2492 u32 bi, auth_data_len = 0, msg_len = 0;
2493 vlib_main_t *vm = lcm->vlib_main;
2495 if (vlib_buffer_alloc (vm, &bi, 1) != 1)
2497 clib_warning ("Can't allocate buffer for Map-Register!");
2501 b = vlib_get_buffer (vm, bi);
2503 /* leave some space for the encap headers */
2504 vlib_buffer_make_headroom (b, MAX_LISP_MSG_ENCAP_LEN);
2506 auth_data_len = auth_data_len_by_key_id (key_id);
2507 map_reg_hdr = lisp_msg_put_map_register (b, records, want_map_notif,
2508 auth_data_len, nonce_res,
2511 update_map_register_auth_data (map_reg_hdr, key_id, key, auth_data_len,
2514 /* push outer ip header */
2515 pkt_push_udp_and_ip (vm, b, LISP_CONTROL_PORT, LISP_CONTROL_PORT, sloc,
2524 get_egress_map_ ##name## _ip (lisp_cp_main_t * lcm, ip_address_t * ip) \
2527 while (lcm->do_map_ ## name ## _election \
2528 | (0 == ip_fib_get_first_egress_ip_for_dst \
2529 (lcm, &lcm->active_map_ ##name, ip))) \
2531 if (0 == elect_map_ ## name (lcm)) \
2532 /* all map resolvers/servers are down */ \
2534 /* restart MR/MS checking by marking all of them up */ \
2535 vec_foreach (mr, lcm->map_ ## name ## s) mr->is_down = 0; \
2544 /* CP output statistics */
2545 #define foreach_lisp_cp_output_error \
2546 _(MAP_REGISTERS_SENT, "map-registers sent") \
2547 _(RLOC_PROBES_SENT, "rloc-probes sent")
2548 static char *lisp_cp_output_error_strings[] = {
2549 #define _(sym,string) string,
2550 foreach_lisp_cp_output_error
2556 #define _(sym,str) LISP_CP_OUTPUT_ERROR_##sym,
2557 foreach_lisp_cp_output_error
2559 LISP_CP_OUTPUT_N_ERROR,
2560 } lisp_cp_output_error_t;
2563 lisp_cp_output (vlib_main_t * vm, vlib_node_runtime_t * node,
2564 vlib_frame_t * from_frame)
2569 /* dummy node used only for statistics */
2571 VLIB_REGISTER_NODE (lisp_cp_output_node) = {
2572 .function = lisp_cp_output,
2573 .name = "lisp-cp-output",
2574 .vector_size = sizeof (u32),
2575 .format_trace = format_lisp_cp_input_trace,
2576 .type = VLIB_NODE_TYPE_INTERNAL,
2578 .n_errors = LISP_CP_OUTPUT_N_ERROR,
2579 .error_strings = lisp_cp_output_error_strings,
2581 .n_next_nodes = LISP_CP_INPUT_N_NEXT,
2584 [LISP_CP_INPUT_NEXT_DROP] = "error-drop",
2590 send_rloc_probe (lisp_cp_main_t * lcm, gid_address_t * deid,
2591 u32 local_locator_set_index, ip_address_t * sloc,
2592 ip_address_t * rloc)
2599 u32 next_index, *to_next;
2600 gid_address_t *itr_rlocs;
2602 ls = pool_elt_at_index (lcm->locator_set_pool, local_locator_set_index);
2603 itr_rlocs = build_itr_rloc_list (lcm, ls);
2605 b = build_map_request (lcm, deid, sloc, rloc, itr_rlocs, &nonce, &bi);
2606 vec_free (itr_rlocs);
2610 vnet_buffer (b)->sw_if_index[VLIB_TX] = 0;
2612 next_index = (ip_addr_version (rloc) == IP4) ?
2613 ip4_lookup_node.index : ip6_lookup_node.index;
2615 f = vlib_get_frame_to_node (lcm->vlib_main, next_index);
2617 /* Enqueue the packet */
2618 to_next = vlib_frame_vector_args (f);
2621 vlib_put_frame_to_node (lcm->vlib_main, next_index, f);
2627 send_rloc_probes (lisp_cp_main_t * lcm)
2633 u32 si, rloc_probes_sent = 0;
2636 pool_foreach (e, lcm->fwd_entry_pool,
2638 if (vec_len (e->locator_pairs) == 0)
2641 si = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &e->leid);
2644 clib_warning ("internal error: cannot find local eid %U in "
2645 "map-cache!", format_gid_address, &e->leid);
2648 lm = pool_elt_at_index (lcm->mapping_pool, si);
2650 /* get the best (lowest) priority */
2651 lprio = e->locator_pairs[0].priority;
2653 /* send rloc-probe for pair(s) with the best remote locator priority */
2654 vec_foreach (lp, e->locator_pairs)
2656 if (lp->priority != lprio)
2659 /* get first remote locator */
2660 send_rloc_probe (lcm, &e->reid, lm->locator_set_index, &lp->lcl_loc,
2667 vlib_node_increment_counter (vlib_get_main (), lisp_cp_output_node.index,
2668 LISP_CP_OUTPUT_ERROR_RLOC_PROBES_SENT,
2674 send_map_register (lisp_cp_main_t * lcm, u8 want_map_notif)
2676 pending_map_register_t *pmr;
2677 u32 bi, map_registers_sent = 0;
2682 u32 next_index, *to_next;
2683 mapping_t *records, *r, *group, *k;
2685 if (get_egress_map_server_ip (lcm, &sloc) < 0)
2688 records = build_map_register_record_list (lcm);
2692 vec_foreach (r, records)
2695 u8 key_id = r->key_id;
2698 continue; /* no secret key -> map-register cannot be sent */
2701 vec_add1 (group, r[0]);
2703 /* group mappings that share common key */
2704 for (k = r + 1; k < vec_end (records); k++)
2706 if (k->key_id != r->key_id)
2709 if (vec_is_equal (k->key, r->key))
2711 vec_add1 (group, k[0]);
2712 k->key = 0; /* don't process this mapping again */
2716 b = build_map_register (lcm, &sloc, &lcm->active_map_server, &nonce,
2717 want_map_notif, group, key_id, key, &bi);
2722 vnet_buffer (b)->sw_if_index[VLIB_TX] = 0;
2724 next_index = (ip_addr_version (&lcm->active_map_server) == IP4) ?
2725 ip4_lookup_node.index : ip6_lookup_node.index;
2727 f = vlib_get_frame_to_node (lcm->vlib_main, next_index);
2729 /* Enqueue the packet */
2730 to_next = vlib_frame_vector_args (f);
2733 vlib_put_frame_to_node (lcm->vlib_main, next_index, f);
2734 map_registers_sent++;
2736 pool_get (lcm->pending_map_registers_pool, pmr);
2737 memset (pmr, 0, sizeof (*pmr));
2738 pmr->time_to_expire = PENDING_MREG_EXPIRATION_TIME;
2739 hash_set (lcm->map_register_messages_by_nonce, nonce,
2740 pmr - lcm->pending_map_registers_pool);
2742 free_map_register_records (records);
2744 vlib_node_increment_counter (vlib_get_main (), lisp_cp_output_node.index,
2745 LISP_CP_OUTPUT_ERROR_MAP_REGISTERS_SENT,
2746 map_registers_sent);
2751 #define send_encapsulated_map_request(lcm, seid, deid, smr) \
2752 _send_encapsulated_map_request(lcm, seid, deid, smr, 0)
2754 #define resend_encapsulated_map_request(lcm, seid, deid, smr) \
2755 _send_encapsulated_map_request(lcm, seid, deid, smr, 1)
2758 _send_encapsulated_map_request (lisp_cp_main_t * lcm,
2759 gid_address_t * seid, gid_address_t * deid,
2760 u8 is_smr_invoked, u8 is_resend)
2762 u32 next_index, bi = 0, *to_next, map_index;
2766 locator_set_t *loc_set;
2768 pending_map_request_t *pmr, *duplicate_pmr = 0;
2772 /* if there is already a pending request remember it */
2775 pool_foreach(pmr, lcm->pending_map_requests_pool,
2777 if (!gid_address_cmp (&pmr->src, seid)
2778 && !gid_address_cmp (&pmr->dst, deid))
2780 duplicate_pmr = pmr;
2786 if (!is_resend && duplicate_pmr)
2788 /* don't send the request if there is a pending map request already */
2792 /* get locator-set for seid */
2793 if (!lcm->lisp_pitr && gid_address_type (deid) != GID_ADDR_NSH)
2795 map_index = gid_dictionary_lookup (&lcm->mapping_index_by_gid, seid);
2796 if (map_index == ~0)
2798 clib_warning ("No local mapping found in eid-table for %U!",
2799 format_gid_address, seid);
2803 map = pool_elt_at_index (lcm->mapping_pool, map_index);
2808 ("Mapping found for src eid %U is not marked as local!",
2809 format_gid_address, seid);
2812 ls_index = map->locator_set_index;
2818 map = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
2819 ls_index = map->locator_set_index;
2823 if (lcm->nsh_map_index == (u32) ~ 0)
2825 clib_warning ("No locator-set defined for NSH!");
2830 map = pool_elt_at_index (lcm->mapping_pool, lcm->nsh_map_index);
2831 ls_index = map->locator_set_index;
2836 /* overwrite locator set if map-request itr-rlocs configured */
2837 if (~0 != lcm->mreq_itr_rlocs)
2839 ls_index = lcm->mreq_itr_rlocs;
2842 loc_set = pool_elt_at_index (lcm->locator_set_pool, ls_index);
2844 if (get_egress_map_resolver_ip (lcm, &sloc) < 0)
2847 duplicate_pmr->to_be_removed = 1;
2851 /* build the encapsulated map request */
2852 b = build_encapsulated_map_request (lcm, seid, deid, loc_set,
2853 &lcm->active_map_resolver,
2854 &sloc, is_smr_invoked, &nonce, &bi);
2859 /* set fib index to default and lookup node */
2860 vnet_buffer (b)->sw_if_index[VLIB_TX] = 0;
2861 next_index = (ip_addr_version (&lcm->active_map_resolver) == IP4) ?
2862 ip4_lookup_node.index : ip6_lookup_node.index;
2864 f = vlib_get_frame_to_node (lcm->vlib_main, next_index);
2866 /* Enqueue the packet */
2867 to_next = vlib_frame_vector_args (f);
2870 vlib_put_frame_to_node (lcm->vlib_main, next_index, f);
2873 /* if there is a pending request already update it */
2875 if (clib_fifo_elts (duplicate_pmr->nonces) >= PENDING_MREQ_QUEUE_LEN)
2877 /* remove the oldest nonce */
2878 u64 CLIB_UNUSED (tmp), *nonce_del;
2879 nonce_del = clib_fifo_head (duplicate_pmr->nonces);
2880 hash_unset (lcm->pending_map_requests_by_nonce, nonce_del[0]);
2881 clib_fifo_sub1 (duplicate_pmr->nonces, tmp);
2884 clib_fifo_add1 (duplicate_pmr->nonces, nonce);
2885 hash_set (lcm->pending_map_requests_by_nonce, nonce,
2886 duplicate_pmr - lcm->pending_map_requests_pool);
2890 /* add map-request to pending requests table */
2891 pool_get (lcm->pending_map_requests_pool, pmr);
2892 memset (pmr, 0, sizeof (*pmr));
2893 gid_address_copy (&pmr->src, seid);
2894 gid_address_copy (&pmr->dst, deid);
2895 clib_fifo_add1 (pmr->nonces, nonce);
2896 pmr->is_smr_invoked = is_smr_invoked;
2897 reset_pending_mr_counters (pmr);
2898 hash_set (lcm->pending_map_requests_by_nonce, nonce,
2899 pmr - lcm->pending_map_requests_pool);
2906 get_src_and_dst_ip (void *hdr, ip_address_t * src, ip_address_t * dst)
2908 ip4_header_t *ip4 = hdr;
2911 if ((ip4->ip_version_and_header_length & 0xF0) == 0x40)
2913 ip_address_set (src, &ip4->src_address, IP4);
2914 ip_address_set (dst, &ip4->dst_address, IP4);
2919 ip_address_set (src, &ip6->src_address, IP6);
2920 ip_address_set (dst, &ip6->dst_address, IP6);
2925 lisp_get_vni_from_buffer_ip (lisp_cp_main_t * lcm, vlib_buffer_t * b,
2929 u32 vni = ~0, table_id = ~0;
2931 table_id = fib_table_get_table_id_for_sw_if_index ((version ==
2932 IP4 ? FIB_PROTOCOL_IP4 :
2938 vnip = hash_get (lcm->vni_by_table_id, table_id);
2942 clib_warning ("vrf %d is not mapped to any vni!", table_id);
2948 lisp_get_bd_from_buffer_eth (vlib_buffer_t * b)
2952 l2input_main_t *l2im = &l2input_main;
2953 l2_input_config_t *config;
2954 l2_bridge_domain_t *bd_config;
2956 sw_if_index0 = vnet_buffer (b)->sw_if_index[VLIB_RX];
2957 config = vec_elt_at_index (l2im->configs, sw_if_index0);
2958 bd_config = vec_elt_at_index (l2im->bd_configs, config->bd_index);
2960 return bd_config->bd_id;
2964 lisp_get_vni_from_buffer_eth (lisp_cp_main_t * lcm, vlib_buffer_t * b)
2968 u32 bd = lisp_get_bd_from_buffer_eth (b);
2970 vnip = hash_get (lcm->vni_by_bd_id, bd);
2974 clib_warning ("bridge domain %d is not mapped to any vni!", bd);
2980 get_src_and_dst_eids_from_buffer (lisp_cp_main_t * lcm, vlib_buffer_t * b,
2981 gid_address_t * src, gid_address_t * dst,
2984 ethernet_header_t *eh;
2987 memset (src, 0, sizeof (*src));
2988 memset (dst, 0, sizeof (*dst));
2990 gid_address_type (dst) = GID_ADDR_NO_ADDRESS;
2991 gid_address_type (src) = GID_ADDR_NO_ADDRESS;
2993 if (LISP_AFI_IP == type || LISP_AFI_IP6 == type)
2996 u8 version, preflen;
2998 gid_address_type (src) = GID_ADDR_IP_PREFIX;
2999 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
3001 ip = vlib_buffer_get_current (b);
3002 get_src_and_dst_ip (ip, &gid_address_ip (src), &gid_address_ip (dst));
3004 version = gid_address_ip_version (src);
3005 preflen = ip_address_max_len (version);
3006 gid_address_ippref_len (src) = preflen;
3007 gid_address_ippref_len (dst) = preflen;
3009 vni = lisp_get_vni_from_buffer_ip (lcm, b, version);
3010 gid_address_vni (dst) = vni;
3011 gid_address_vni (src) = vni;
3013 else if (LISP_AFI_MAC == type)
3015 ethernet_arp_header_t *ah;
3017 eh = vlib_buffer_get_current (b);
3019 if (clib_net_to_host_u16 (eh->type) == ETHERNET_TYPE_ARP)
3021 ah = (ethernet_arp_header_t *) (((u8 *) eh) + sizeof (*eh));
3022 if (clib_net_to_host_u16 (ah->opcode)
3023 != ETHERNET_ARP_OPCODE_request)
3026 gid_address_type (dst) = GID_ADDR_ARP;
3027 gid_address_arp_bd (dst) = lisp_get_bd_from_buffer_eth (b);
3028 clib_memcpy (&gid_address_arp_ip4 (dst),
3029 &ah->ip4_over_ethernet[1].ip4, 4);
3033 gid_address_type (src) = GID_ADDR_MAC;
3034 gid_address_type (dst) = GID_ADDR_MAC;
3035 mac_copy (&gid_address_mac (src), eh->src_address);
3036 mac_copy (&gid_address_mac (dst), eh->dst_address);
3039 vni = lisp_get_vni_from_buffer_eth (lcm, b);
3041 gid_address_vni (dst) = vni;
3042 gid_address_vni (src) = vni;
3045 else if (LISP_AFI_LCAF == type)
3048 eh = vlib_buffer_get_current (b);
3050 if (clib_net_to_host_u16 (eh->type) == ETHERNET_TYPE_NSH)
3052 nh = (lisp_nsh_hdr_t *) (((u8 *) eh) + sizeof (*eh));
3053 u32 spi = clib_net_to_host_u32 (nh->spi_si << 8);
3054 u8 si = (u8) clib_net_to_host_u32 (nh->spi_si);
3055 gid_address_nsh_spi (dst) = spi;
3056 gid_address_nsh_si (dst) = si;
3058 gid_address_type (dst) = GID_ADDR_NSH;
3064 lisp_cp_lookup_inline (vlib_main_t * vm,
3065 vlib_node_runtime_t * node,
3066 vlib_frame_t * from_frame, int overlay)
3068 u32 *from, *to_next, di, si;
3069 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3070 u32 pkts_mapped = 0, next_index;
3071 uword n_left_from, n_left_to_next;
3072 vnet_main_t *vnm = vnet_get_main ();
3074 from = vlib_frame_vector_args (from_frame);
3075 n_left_from = from_frame->n_vectors;
3076 next_index = node->cached_next_index;
3078 while (n_left_from > 0)
3080 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
3082 while (n_left_from > 0 && n_left_to_next > 0)
3084 u32 pi0, sw_if_index0, next0;
3087 gid_address_t src, dst;
3088 ethernet_arp_header_t *arp0;
3089 ethernet_header_t *eth0;
3090 vnet_hw_interface_t *hw_if0;
3097 n_left_to_next -= 1;
3099 b0 = vlib_get_buffer (vm, pi0);
3101 /* src/dst eid pair */
3102 get_src_and_dst_eids_from_buffer (lcm, b0, &src, &dst, overlay);
3104 if (gid_address_type (&dst) == GID_ADDR_ARP)
3106 mac0 = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &dst);
3107 if (GID_LOOKUP_MISS_L2 != mac0)
3109 /* send ARP reply */
3111 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
3112 vnet_buffer (b0)->sw_if_index[VLIB_TX] = sw_if_index0;
3114 hw_if0 = vnet_get_sup_hw_interface (vnm, sw_if_index0);
3116 eth0 = vlib_buffer_get_current (b0);
3117 arp0 = (ethernet_arp_header_t *) (((u8 *) eth0)
3120 clib_host_to_net_u16 (ETHERNET_ARP_OPCODE_reply);
3121 arp0->ip4_over_ethernet[1] = arp0->ip4_over_ethernet[0];
3122 clib_memcpy (arp0->ip4_over_ethernet[0].ethernet,
3124 clib_memcpy (&arp0->ip4_over_ethernet[0].ip4,
3125 &gid_address_arp_ip4 (&dst), 4);
3127 /* Hardware must be ethernet-like. */
3128 ASSERT (vec_len (hw_if0->hw_address) == 6);
3130 clib_memcpy (eth0->dst_address, eth0->src_address, 6);
3131 clib_memcpy (eth0->src_address, hw_if0->hw_address, 6);
3133 b0->error = node->errors[LISP_CP_LOOKUP_ERROR_ARP_REPLY_TX];
3134 next0 = LISP_CP_LOOKUP_NEXT_ARP_REPLY_TX;
3135 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
3137 n_left_to_next, pi0,
3144 /* if we have remote mapping for destination already in map-chache
3145 add forwarding tunnel directly. If not send a map-request */
3146 di = gid_dictionary_sd_lookup (&lcm->mapping_index_by_gid, &dst,
3150 mapping_t *m = vec_elt_at_index (lcm->mapping_pool, di);
3151 /* send a map-request also in case of negative mapping entry
3152 with corresponding action */
3153 if (m->action == LISP_SEND_MAP_REQUEST)
3155 /* send map-request */
3156 queue_map_request (&src, &dst, 0 /* smr_invoked */ ,
3157 0 /* is_resend */ );
3162 if (GID_ADDR_NSH != gid_address_type (&dst))
3164 si = gid_dictionary_lookup (&lcm->mapping_index_by_gid,
3168 si = lcm->nsh_map_index;
3172 dp_add_fwd_entry_from_mt (si, di);
3178 /* send map-request */
3179 queue_map_request (&src, &dst, 0 /* smr_invoked */ ,
3180 0 /* is_resend */ );
3185 b0->error = node->errors[LISP_CP_LOOKUP_ERROR_DROP];
3186 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
3188 lisp_cp_lookup_trace_t *tr = vlib_add_trace (vm, node, b0,
3191 memset (tr, 0, sizeof (*tr));
3192 gid_address_copy (&tr->dst_eid, &dst);
3193 ip_address_copy (&tr->map_resolver_ip,
3194 &lcm->active_map_resolver);
3196 gid_address_free (&dst);
3197 gid_address_free (&src);
3198 next0 = LISP_CP_LOOKUP_NEXT_DROP;
3199 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
3201 n_left_to_next, pi0, next0);
3204 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
3206 vlib_node_increment_counter (vm, node->node_index,
3207 LISP_CP_LOOKUP_ERROR_MAP_REQUESTS_SENT,
3209 return from_frame->n_vectors;
3213 lisp_cp_lookup_ip4 (vlib_main_t * vm,
3214 vlib_node_runtime_t * node, vlib_frame_t * from_frame)
3216 return (lisp_cp_lookup_inline (vm, node, from_frame, LISP_AFI_IP));
3220 lisp_cp_lookup_ip6 (vlib_main_t * vm,
3221 vlib_node_runtime_t * node, vlib_frame_t * from_frame)
3223 return (lisp_cp_lookup_inline (vm, node, from_frame, LISP_AFI_IP6));
3227 lisp_cp_lookup_l2 (vlib_main_t * vm,
3228 vlib_node_runtime_t * node, vlib_frame_t * from_frame)
3230 return (lisp_cp_lookup_inline (vm, node, from_frame, LISP_AFI_MAC));
3234 lisp_cp_lookup_nsh (vlib_main_t * vm,
3235 vlib_node_runtime_t * node, vlib_frame_t * from_frame)
3237 /* TODO decide if NSH should be propagated as LCAF or not */
3238 return (lisp_cp_lookup_inline (vm, node, from_frame, LISP_AFI_LCAF));
3242 VLIB_REGISTER_NODE (lisp_cp_lookup_ip4_node) = {
3243 .function = lisp_cp_lookup_ip4,
3244 .name = "lisp-cp-lookup-ip4",
3245 .vector_size = sizeof (u32),
3246 .format_trace = format_lisp_cp_lookup_trace,
3247 .type = VLIB_NODE_TYPE_INTERNAL,
3249 .n_errors = LISP_CP_LOOKUP_N_ERROR,
3250 .error_strings = lisp_cp_lookup_error_strings,
3252 .n_next_nodes = LISP_CP_LOOKUP_N_NEXT,
3255 [LISP_CP_LOOKUP_NEXT_DROP] = "error-drop",
3256 [LISP_CP_LOOKUP_NEXT_ARP_REPLY_TX] = "interface-output",
3262 VLIB_REGISTER_NODE (lisp_cp_lookup_ip6_node) = {
3263 .function = lisp_cp_lookup_ip6,
3264 .name = "lisp-cp-lookup-ip6",
3265 .vector_size = sizeof (u32),
3266 .format_trace = format_lisp_cp_lookup_trace,
3267 .type = VLIB_NODE_TYPE_INTERNAL,
3269 .n_errors = LISP_CP_LOOKUP_N_ERROR,
3270 .error_strings = lisp_cp_lookup_error_strings,
3272 .n_next_nodes = LISP_CP_LOOKUP_N_NEXT,
3275 [LISP_CP_LOOKUP_NEXT_DROP] = "error-drop",
3276 [LISP_CP_LOOKUP_NEXT_ARP_REPLY_TX] = "interface-output",
3282 VLIB_REGISTER_NODE (lisp_cp_lookup_l2_node) = {
3283 .function = lisp_cp_lookup_l2,
3284 .name = "lisp-cp-lookup-l2",
3285 .vector_size = sizeof (u32),
3286 .format_trace = format_lisp_cp_lookup_trace,
3287 .type = VLIB_NODE_TYPE_INTERNAL,
3289 .n_errors = LISP_CP_LOOKUP_N_ERROR,
3290 .error_strings = lisp_cp_lookup_error_strings,
3292 .n_next_nodes = LISP_CP_LOOKUP_N_NEXT,
3295 [LISP_CP_LOOKUP_NEXT_DROP] = "error-drop",
3296 [LISP_CP_LOOKUP_NEXT_ARP_REPLY_TX] = "interface-output",
3302 VLIB_REGISTER_NODE (lisp_cp_lookup_nsh_node) = {
3303 .function = lisp_cp_lookup_nsh,
3304 .name = "lisp-cp-lookup-nsh",
3305 .vector_size = sizeof (u32),
3306 .format_trace = format_lisp_cp_lookup_trace,
3307 .type = VLIB_NODE_TYPE_INTERNAL,
3309 .n_errors = LISP_CP_LOOKUP_N_ERROR,
3310 .error_strings = lisp_cp_lookup_error_strings,
3312 .n_next_nodes = LISP_CP_LOOKUP_N_NEXT,
3315 [LISP_CP_LOOKUP_NEXT_DROP] = "error-drop",
3316 [LISP_CP_LOOKUP_NEXT_ARP_REPLY_TX] = "interface-output",
3321 /* lisp_cp_input statistics */
3322 #define foreach_lisp_cp_input_error \
3324 _(RLOC_PROBE_REQ_RECEIVED, "rloc-probe requests received") \
3325 _(RLOC_PROBE_REP_RECEIVED, "rloc-probe replies received") \
3326 _(MAP_NOTIFIES_RECEIVED, "map-notifies received") \
3327 _(MAP_REPLIES_RECEIVED, "map-replies received")
3329 static char *lisp_cp_input_error_strings[] = {
3330 #define _(sym,string) string,
3331 foreach_lisp_cp_input_error
3337 #define _(sym,str) LISP_CP_INPUT_ERROR_##sym,
3338 foreach_lisp_cp_input_error
3340 LISP_CP_INPUT_N_ERROR,
3341 } lisp_cp_input_error_t;
3345 gid_address_t dst_eid;
3346 ip4_address_t map_resolver_ip;
3347 } lisp_cp_input_trace_t;
3350 format_lisp_cp_input_trace (u8 * s, va_list * args)
3352 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
3353 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
3354 CLIB_UNUSED (lisp_cp_input_trace_t * t) =
3355 va_arg (*args, lisp_cp_input_trace_t *);
3357 s = format (s, "LISP-CP-INPUT: TODO");
3362 remove_expired_mapping (lisp_cp_main_t * lcm, u32 mi)
3365 vnet_lisp_add_del_adjacency_args_t _adj_args, *adj_args = &_adj_args;
3366 memset (adj_args, 0, sizeof (adj_args[0]));
3368 m = pool_elt_at_index (lcm->mapping_pool, mi);
3370 gid_address_copy (&adj_args->reid, &m->eid);
3371 adj_args->is_add = 0;
3372 if (vnet_lisp_add_del_adjacency (adj_args))
3373 clib_warning ("failed to del adjacency!");
3375 vnet_lisp_add_del_mapping (&m->eid, 0, 0, 0, ~0, 0 /* is_add */ ,
3376 0 /* is_static */ , 0);
3377 mapping_delete_timer (lcm, mi);
3381 mapping_start_expiration_timer (lisp_cp_main_t * lcm, u32 mi,
3382 f64 expiration_time)
3385 u64 now = clib_cpu_time_now ();
3386 u64 cpu_cps = lcm->vlib_main->clib_time.clocks_per_second;
3387 u64 exp_clock_time = now + expiration_time * cpu_cps;
3389 m = pool_elt_at_index (lcm->mapping_pool, mi);
3392 timing_wheel_insert (&lcm->wheel, exp_clock_time, mi);
3396 map_records_arg_free (map_records_arg_t * a)
3398 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3400 vec_foreach (m, a->mappings)
3402 vec_free (m->locators);
3403 gid_address_free (&m->eid);
3405 pool_put (lcm->map_records_args_pool[vlib_get_thread_index ()], a);
3409 process_map_reply (map_records_arg_t * a)
3412 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3413 u32 dst_map_index = 0;
3414 pending_map_request_t *pmr;
3418 if (a->is_rloc_probe)
3421 /* Check pending requests table and nonce */
3422 pmr_index = hash_get (lcm->pending_map_requests_by_nonce, a->nonce);
3425 clib_warning ("No pending map-request entry with nonce %lu!", a->nonce);
3428 pmr = pool_elt_at_index (lcm->pending_map_requests_pool, pmr_index[0]);
3430 vec_foreach (m, a->mappings)
3432 /* insert/update mappings cache */
3433 vnet_lisp_add_del_mapping (&m->eid, m->locators, m->action,
3434 m->authoritative, m->ttl,
3435 1, 0 /* is_static */ , &dst_map_index);
3437 if (dst_map_index == (u32) ~ 0)
3440 /* try to program forwarding only if mapping saved or updated */
3441 vnet_lisp_add_del_adjacency_args_t _adj_args, *adj_args = &_adj_args;
3442 memset (adj_args, 0, sizeof (adj_args[0]));
3444 gid_address_copy (&adj_args->leid, &pmr->src);
3445 gid_address_copy (&adj_args->reid, &m->eid);
3446 adj_args->is_add = 1;
3447 if (vnet_lisp_add_del_adjacency (adj_args))
3448 clib_warning ("failed to add adjacency!");
3450 if ((u32) ~ 0 != m->ttl)
3451 mapping_start_expiration_timer (lcm, dst_map_index, m->ttl * 60);
3454 /* remove pending map request entry */
3457 clib_fifo_foreach (noncep, pmr->nonces, ({
3458 hash_unset(lcm->pending_map_requests_by_nonce, noncep[0]);
3462 clib_fifo_free (pmr->nonces);
3463 pool_put (lcm->pending_map_requests_pool, pmr);
3471 is_auth_data_valid (map_notify_hdr_t * h, u32 msg_len,
3472 lisp_key_type_t key_id, u8 * key)
3478 auth_data_len = auth_data_len_by_key_id (key_id);
3479 if ((u16) ~ 0 == auth_data_len)
3481 clib_warning ("invalid length for key_id %d!", key_id);
3485 /* save auth data */
3486 vec_validate (auth_data, auth_data_len - 1);
3487 clib_memcpy (auth_data, MNOTIFY_DATA (h), auth_data_len);
3489 /* clear auth data */
3490 memset (MNOTIFY_DATA (h), 0, auth_data_len);
3492 /* get hash of the message */
3493 unsigned char *code = HMAC (get_encrypt_fcn (key_id), key, vec_len (key),
3494 (unsigned char *) h, msg_len, NULL, NULL);
3496 result = memcmp (code, auth_data, auth_data_len);
3498 vec_free (auth_data);
3504 process_map_notify (map_records_arg_t * a)
3506 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3509 pmr_index = hash_get (lcm->map_register_messages_by_nonce, a->nonce);
3512 clib_warning ("No pending map-register entry with nonce %lu!",
3518 pool_put_index (lcm->pending_map_registers_pool, pmr_index[0]);
3519 hash_unset (lcm->map_register_messages_by_nonce, a->nonce);
3521 /* reset map-notify counter */
3522 lcm->expired_map_registers = 0;
3526 get_mapping (lisp_cp_main_t * lcm, gid_address_t * e)
3530 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, e);
3533 clib_warning ("eid %U not found in map-cache!", unformat_gid_address,
3537 return pool_elt_at_index (lcm->mapping_pool, mi);
3541 * When map-notify is received it is necessary that all EIDs in the record
3542 * list share common key. The key is then used to verify authentication
3543 * data in map-notify message.
3546 map_record_integrity_check (lisp_cp_main_t * lcm, mapping_t * maps,
3547 u32 key_id, u8 ** key_out)
3549 u32 i, len = vec_len (maps);
3552 /* get key of the first mapping */
3553 m = get_mapping (lcm, &maps[0].eid);
3557 key_out[0] = m->key;
3559 for (i = 1; i < len; i++)
3561 m = get_mapping (lcm, &maps[i].eid);
3565 if (key_id != m->key_id || vec_cmp (m->key, key_out[0]))
3567 clib_warning ("keys does not match! %v, %v", key_out[0], m->key);
3575 parse_map_records (vlib_buffer_t * b, map_records_arg_t * a, u8 count)
3577 locator_t *locators = 0;
3583 memset (&m, 0, sizeof (m));
3585 /* parse record eid */
3586 for (i = 0; i < count; i++)
3589 len = lisp_msg_parse_mapping_record (b, &deid, &locators, NULL);
3592 clib_warning ("Failed to parse mapping record!");
3593 vec_foreach (loc, locators) locator_free (loc);
3594 vec_free (locators);
3598 m.locators = locators;
3599 gid_address_copy (&m.eid, &deid);
3600 vec_add1 (a->mappings, m);
3606 static map_records_arg_t *
3607 map_record_args_get ()
3609 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3610 map_records_arg_t *rec;
3614 pool_foreach (rec, lcm->map_records_args_pool[vlib_get_thread_index()], ({
3616 map_records_arg_free (rec);
3620 pool_get (lcm->map_records_args_pool[vlib_get_thread_index ()], rec);
3624 static map_records_arg_t *
3625 parse_map_notify (vlib_buffer_t * b)
3628 map_notify_hdr_t *mnotif_hdr;
3629 lisp_key_type_t key_id;
3630 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3633 u16 auth_data_len = 0;
3635 map_records_arg_t *a;
3637 a = map_record_args_get ();
3638 memset (a, 0, sizeof (*a));
3639 mnotif_hdr = vlib_buffer_get_current (b);
3640 vlib_buffer_pull (b, sizeof (*mnotif_hdr));
3641 memset (&deid, 0, sizeof (deid));
3643 a->nonce = MNOTIFY_NONCE (mnotif_hdr);
3644 key_id = clib_net_to_host_u16 (MNOTIFY_KEY_ID (mnotif_hdr));
3645 auth_data_len = auth_data_len_by_key_id (key_id);
3647 /* advance buffer by authentication data */
3648 vlib_buffer_pull (b, auth_data_len);
3650 record_count = MNOTIFY_REC_COUNT (mnotif_hdr);
3651 rc = parse_map_records (b, a, record_count);
3654 map_records_arg_free (a);
3658 rc = map_record_integrity_check (lcm, a->mappings, key_id, &key);
3661 map_records_arg_free (a);
3665 /* verify authentication data */
3666 if (!is_auth_data_valid (mnotif_hdr, vlib_buffer_get_tail (b)
3667 - (u8 *) mnotif_hdr, key_id, key))
3669 clib_warning ("Map-notify auth data verification failed for nonce "
3670 "0x%lx!", a->nonce);
3671 map_records_arg_free (a);
3677 static vlib_buffer_t *
3678 build_map_reply (lisp_cp_main_t * lcm, ip_address_t * sloc,
3679 ip_address_t * dst, u64 nonce, u8 probe_bit,
3680 mapping_t * records, u16 dst_port, u32 * bi_res)
3684 vlib_main_t *vm = lcm->vlib_main;
3686 if (vlib_buffer_alloc (vm, &bi, 1) != 1)
3688 clib_warning ("Can't allocate buffer for Map-Register!");
3692 b = vlib_get_buffer (vm, bi);
3694 /* leave some space for the encap headers */
3695 vlib_buffer_make_headroom (b, MAX_LISP_MSG_ENCAP_LEN);
3697 lisp_msg_put_map_reply (b, records, nonce, probe_bit);
3699 /* push outer ip header */
3700 pkt_push_udp_and_ip (vm, b, LISP_CONTROL_PORT, dst_port, sloc, dst, 1);
3707 send_map_reply (lisp_cp_main_t * lcm, u32 mi, ip_address_t * dst,
3708 u8 probe_bit, u64 nonce, u16 dst_port,
3709 ip_address_t * probed_loc)
3715 u32 next_index, *to_next;
3716 mapping_t *records = 0, *m;
3718 m = pool_elt_at_index (lcm->mapping_pool, mi);
3722 vec_add1 (records, m[0]);
3723 add_locators (lcm, &records[0], m->locator_set_index, probed_loc);
3724 memset (&src, 0, sizeof (src));
3726 if (!ip_fib_get_first_egress_ip_for_dst (lcm, dst, &src))
3728 clib_warning ("can't find inteface address for %U", format_ip_address,
3733 b = build_map_reply (lcm, &src, dst, nonce, probe_bit, records, dst_port,
3737 free_map_register_records (records);
3739 vnet_buffer (b)->sw_if_index[VLIB_TX] = 0;
3740 next_index = (ip_addr_version (&lcm->active_map_resolver) == IP4) ?
3741 ip4_lookup_node.index : ip6_lookup_node.index;
3743 f = vlib_get_frame_to_node (lcm->vlib_main, next_index);
3745 /* Enqueue the packet */
3746 to_next = vlib_frame_vector_args (f);
3749 vlib_put_frame_to_node (lcm->vlib_main, next_index, f);
3754 find_ip_header (vlib_buffer_t * b, u8 ** ip_hdr)
3756 const i32 start = vnet_buffer (b)->l3_hdr_offset;
3757 if (start < 0 && start < -sizeof (b->pre_data))
3763 *ip_hdr = b->data + start;
3764 if ((u8 *) * ip_hdr > (u8 *) vlib_buffer_get_current (b))
3769 process_map_request (vlib_main_t * vm, vlib_node_runtime_t * node,
3770 lisp_cp_main_t * lcm, vlib_buffer_t * b)
3773 ip_address_t *dst_loc = 0, probed_loc, src_loc;
3775 map_request_hdr_t *mreq_hdr;
3776 gid_address_t src, dst;
3778 u32 i, len = 0, rloc_probe_recv = 0;
3779 gid_address_t *itr_rlocs = 0;
3781 mreq_hdr = vlib_buffer_get_current (b);
3782 if (!MREQ_SMR (mreq_hdr) && !MREQ_RLOC_PROBE (mreq_hdr))
3785 ("Only SMR Map-Requests and RLOC probe supported for now!");
3789 vlib_buffer_pull (b, sizeof (*mreq_hdr));
3790 nonce = MREQ_NONCE (mreq_hdr);
3793 len = lisp_msg_parse_addr (b, &src);
3797 len = lisp_msg_parse_itr_rlocs (b, &itr_rlocs,
3798 MREQ_ITR_RLOC_COUNT (mreq_hdr) + 1);
3802 /* parse eid records and send SMR-invoked map-requests */
3803 for (i = 0; i < MREQ_REC_COUNT (mreq_hdr); i++)
3805 memset (&dst, 0, sizeof (dst));
3806 len = lisp_msg_parse_eid_rec (b, &dst);
3809 clib_warning ("Can't parse map-request EID-record");
3813 if (MREQ_SMR (mreq_hdr))
3815 /* send SMR-invoked map-requests */
3816 queue_map_request (&dst, &src, 1 /* invoked */ , 0 /* resend */ );
3818 else if (MREQ_RLOC_PROBE (mreq_hdr))
3820 find_ip_header (b, &ip_hdr);
3823 clib_warning ("Cannot find the IP header!");
3827 memset (&m, 0, sizeof (m));
3828 u32 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &dst);
3830 // TODO: select best locator; for now use the first one
3831 dst_loc = &gid_address_ip (&itr_rlocs[0]);
3833 /* get src/dst IP addresses */
3834 get_src_and_dst_ip (ip_hdr, &src_loc, &probed_loc);
3836 // TODO get source port from buffer
3837 u16 src_port = LISP_CONTROL_PORT;
3839 send_map_reply (lcm, mi, dst_loc, 1 /* probe-bit */ , nonce,
3840 src_port, &probed_loc);
3845 vlib_node_increment_counter (vm, node->node_index,
3846 LISP_CP_INPUT_ERROR_RLOC_PROBE_REQ_RECEIVED,
3848 vec_free (itr_rlocs);
3852 parse_map_reply (vlib_buffer_t * b)
3859 map_reply_hdr_t *mrep_hdr;
3860 map_records_arg_t *a;
3862 a = map_record_args_get ();
3863 memset (a, 0, sizeof (*a));
3865 locator_t *locators;
3867 mrep_hdr = vlib_buffer_get_current (b);
3868 a->nonce = MREP_NONCE (mrep_hdr);
3869 a->is_rloc_probe = MREP_RLOC_PROBE (mrep_hdr);
3870 if (!vlib_buffer_has_space (b, sizeof (*mrep_hdr)))
3875 vlib_buffer_pull (b, sizeof (*mrep_hdr));
3877 for (i = 0; i < MREP_REC_COUNT (mrep_hdr); i++)
3879 memset (&m, 0, sizeof (m));
3881 h = vlib_buffer_get_current (b);
3883 m.ttl = clib_net_to_host_u32 (MAP_REC_TTL (h));
3884 m.action = MAP_REC_ACTION (h);
3885 m.authoritative = MAP_REC_AUTH (h);
3887 len = lisp_msg_parse_mapping_record (b, &deid, &locators, &probed);
3890 clib_warning ("Failed to parse mapping record!");
3891 map_records_arg_free (a);
3895 m.locators = locators;
3896 gid_address_copy (&m.eid, &deid);
3897 vec_add1 (a->mappings, m);
3903 queue_map_reply_for_processing (map_records_arg_t * a)
3905 vl_api_rpc_call_main_thread (process_map_reply, (u8 *) a, sizeof (*a));
3909 queue_map_notify_for_processing (map_records_arg_t * a)
3911 vl_api_rpc_call_main_thread (process_map_notify, (u8 *) a, sizeof (a[0]));
3915 lisp_cp_input (vlib_main_t * vm, vlib_node_runtime_t * node,
3916 vlib_frame_t * from_frame)
3918 u32 n_left_from, *from, *to_next_drop, rloc_probe_rep_recv = 0,
3919 map_notifies_recv = 0;
3920 lisp_msg_type_e type;
3921 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3922 map_records_arg_t *a;
3924 from = vlib_frame_vector_args (from_frame);
3925 n_left_from = from_frame->n_vectors;
3928 while (n_left_from > 0)
3930 u32 n_left_to_next_drop;
3932 vlib_get_next_frame (vm, node, LISP_CP_INPUT_NEXT_DROP,
3933 to_next_drop, n_left_to_next_drop);
3934 while (n_left_from > 0 && n_left_to_next_drop > 0)
3942 to_next_drop[0] = bi0;
3944 n_left_to_next_drop -= 1;
3946 b0 = vlib_get_buffer (vm, bi0);
3948 type = lisp_msg_type (vlib_buffer_get_current (b0));
3951 case LISP_MAP_REPLY:
3952 a = parse_map_reply (b0);
3955 if (a->is_rloc_probe)
3956 rloc_probe_rep_recv++;
3957 queue_map_reply_for_processing (a);
3960 case LISP_MAP_REQUEST:
3961 process_map_request (vm, node, lcm, b0);
3963 case LISP_MAP_NOTIFY:
3964 a = parse_map_notify (b0);
3967 map_notifies_recv++;
3968 queue_map_notify_for_processing (a);
3972 clib_warning ("Unsupported LISP message type %d", type);
3976 b0->error = node->errors[LISP_CP_INPUT_ERROR_DROP];
3978 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
3984 vlib_put_next_frame (vm, node, LISP_CP_INPUT_NEXT_DROP,
3985 n_left_to_next_drop);
3987 vlib_node_increment_counter (vm, node->node_index,
3988 LISP_CP_INPUT_ERROR_RLOC_PROBE_REP_RECEIVED,
3989 rloc_probe_rep_recv);
3990 vlib_node_increment_counter (vm, node->node_index,
3991 LISP_CP_INPUT_ERROR_MAP_NOTIFIES_RECEIVED,
3993 return from_frame->n_vectors;
3997 VLIB_REGISTER_NODE (lisp_cp_input_node) = {
3998 .function = lisp_cp_input,
3999 .name = "lisp-cp-input",
4000 .vector_size = sizeof (u32),
4001 .format_trace = format_lisp_cp_input_trace,
4002 .type = VLIB_NODE_TYPE_INTERNAL,
4004 .n_errors = LISP_CP_INPUT_N_ERROR,
4005 .error_strings = lisp_cp_input_error_strings,
4007 .n_next_nodes = LISP_CP_INPUT_N_NEXT,
4010 [LISP_CP_INPUT_NEXT_DROP] = "error-drop",
4016 lisp_cp_init (vlib_main_t * vm)
4018 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4019 clib_error_t *error = 0;
4020 vlib_thread_main_t *vtm = vlib_get_thread_main ();
4023 if ((error = vlib_call_init_function (vm, lisp_gpe_init)))
4026 lcm->im4 = &ip4_main;
4027 lcm->im6 = &ip6_main;
4028 lcm->vlib_main = vm;
4029 lcm->vnet_main = vnet_get_main ();
4030 lcm->mreq_itr_rlocs = ~0;
4033 memset (&lcm->active_map_resolver, 0, sizeof (lcm->active_map_resolver));
4034 memset (&lcm->active_map_server, 0, sizeof (lcm->active_map_server));
4036 gid_dictionary_init (&lcm->mapping_index_by_gid);
4037 lcm->do_map_resolver_election = 1;
4038 lcm->do_map_server_election = 1;
4039 lcm->map_request_mode = MR_MODE_DST_ONLY;
4041 num_threads = 1 /* main thread */ + vtm->n_threads;
4042 vec_validate (lcm->map_records_args_pool, num_threads - 1);
4044 /* default vrf mapped to vni 0 */
4045 hash_set (lcm->table_id_by_vni, 0, 0);
4046 hash_set (lcm->vni_by_table_id, 0, 0);
4048 udp_register_dst_port (vm, UDP_DST_PORT_lisp_cp,
4049 lisp_cp_input_node.index, 1 /* is_ip4 */ );
4050 udp_register_dst_port (vm, UDP_DST_PORT_lisp_cp6,
4051 lisp_cp_input_node.index, 0 /* is_ip4 */ );
4053 u64 now = clib_cpu_time_now ();
4054 timing_wheel_init (&lcm->wheel, now, vm->clib_time.clocks_per_second);
4055 lcm->nsh_map_index = ~0;
4056 lcm->map_register_ttl = MAP_REGISTER_DEFAULT_TTL;
4057 lcm->max_expired_map_registers = MAX_EXPIRED_MAP_REGISTERS_DEFAULT;
4058 lcm->expired_map_registers = 0;
4063 lisp_stats_api_fill (lisp_cp_main_t * lcm, lisp_gpe_main_t * lgm,
4064 lisp_api_stats_t * stat, lisp_stats_key_t * key,
4068 vlib_combined_counter_main_t *cm = &lgm->counters;
4069 lisp_gpe_fwd_entry_key_t fwd_key;
4070 const lisp_gpe_tunnel_t *lgt;
4073 memset (stat, 0, sizeof (*stat));
4074 memset (&fwd_key, 0, sizeof (fwd_key));
4076 fe = pool_elt_at_index (lcm->fwd_entry_pool, key->fwd_entry_index);
4079 gid_to_dp_address (&fe->reid, &stat->deid);
4080 gid_to_dp_address (&fe->leid, &stat->seid);
4081 stat->vni = gid_address_vni (&fe->reid);
4083 lgt = lisp_gpe_tunnel_get (key->tunnel_index);
4084 stat->loc_rloc = lgt->key->lcl;
4085 stat->rmt_rloc = lgt->key->rmt;
4087 vlib_get_combined_counter (cm, stats_index, &v);
4093 vnet_lisp_get_stats (void)
4095 lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main ();
4096 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4097 lisp_api_stats_t *stats = 0, stat;
4098 lisp_stats_key_t *key;
4102 hash_foreach_mem (key, index, lgm->lisp_stats_index_by_key,
4104 if (lisp_stats_api_fill (lcm, lgm, &stat, key, index))
4105 vec_add1 (stats, stat);
4113 send_map_request_thread_fn (void *arg)
4115 map_request_args_t *a = arg;
4116 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4119 resend_encapsulated_map_request (lcm, &a->seid, &a->deid, a->smr_invoked);
4121 send_encapsulated_map_request (lcm, &a->seid, &a->deid, a->smr_invoked);
4127 queue_map_request (gid_address_t * seid, gid_address_t * deid,
4128 u8 smr_invoked, u8 is_resend)
4130 map_request_args_t a;
4132 a.is_resend = is_resend;
4133 gid_address_copy (&a.seid, seid);
4134 gid_address_copy (&a.deid, deid);
4135 a.smr_invoked = smr_invoked;
4137 vl_api_rpc_call_main_thread (send_map_request_thread_fn,
4138 (u8 *) & a, sizeof (a));
4143 * Take an action with a pending map request depending on expiration time
4144 * and re-try counters.
4147 update_pending_request (pending_map_request_t * r, f64 dt)
4149 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4152 if (r->time_to_expire - dt < 0)
4153 /* it's time to decide what to do with this pending request */
4155 if (r->retries_num >= NUMBER_OF_RETRIES)
4156 /* too many retries -> assume current map resolver is not available */
4158 mr = get_map_resolver (&lcm->active_map_resolver);
4161 clib_warning ("Map resolver %U not found - probably deleted "
4162 "by the user recently.", format_ip_address,
4163 &lcm->active_map_resolver);
4167 clib_warning ("map resolver %U is unreachable, ignoring",
4168 format_ip_address, &lcm->active_map_resolver);
4170 /* mark current map resolver unavailable so it won't be
4171 * selected next time */
4173 mr->last_update = vlib_time_now (lcm->vlib_main);
4176 reset_pending_mr_counters (r);
4177 elect_map_resolver (lcm);
4179 /* try to find a next eligible map resolver and re-send */
4180 queue_map_request (&r->src, &r->dst, r->is_smr_invoked,
4186 queue_map_request (&r->src, &r->dst, r->is_smr_invoked,
4189 r->time_to_expire = PENDING_MREQ_EXPIRATION_TIME;
4193 r->time_to_expire -= dt;
4197 remove_dead_pending_map_requests (lisp_cp_main_t * lcm)
4200 pending_map_request_t *pmr;
4201 u32 *to_be_removed = 0, *pmr_index;
4204 pool_foreach (pmr, lcm->pending_map_requests_pool,
4206 if (pmr->to_be_removed)
4208 clib_fifo_foreach (nonce, pmr->nonces, ({
4209 hash_unset (lcm->pending_map_requests_by_nonce, nonce[0]);
4212 vec_add1 (to_be_removed, pmr - lcm->pending_map_requests_pool);
4217 vec_foreach (pmr_index, to_be_removed)
4218 pool_put_index (lcm->pending_map_requests_pool, pmr_index[0]);
4220 vec_free (to_be_removed);
4224 update_rloc_probing (lisp_cp_main_t * lcm, f64 dt)
4226 static f64 time_left = RLOC_PROBING_INTERVAL;
4228 if (!lcm->is_enabled || !lcm->rloc_probing)
4234 time_left = RLOC_PROBING_INTERVAL;
4235 send_rloc_probes (lcm);
4240 update_pending_map_register (pending_map_register_t * r, f64 dt, u8 * del_all)
4242 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4246 r->time_to_expire -= dt;
4248 if (r->time_to_expire < 0)
4250 lcm->expired_map_registers++;
4252 if (lcm->expired_map_registers >= lcm->max_expired_map_registers)
4254 ms = get_map_server (&lcm->active_map_server);
4257 clib_warning ("Map server %U not found - probably deleted "
4258 "by the user recently.", format_ip_address,
4259 &lcm->active_map_server);
4263 clib_warning ("map server %U is unreachable, ignoring",
4264 format_ip_address, &lcm->active_map_server);
4266 /* mark current map server unavailable so it won't be
4267 * elected next time */
4269 ms->last_update = vlib_time_now (lcm->vlib_main);
4272 elect_map_server (lcm);
4274 /* indication for deleting all pending map registers */
4276 lcm->expired_map_registers = 0;
4281 /* delete pending map register */
4289 update_map_register (lisp_cp_main_t * lcm, f64 dt)
4291 u32 *to_be_removed = 0, *pmr_index;
4292 static f64 time_left = QUICK_MAP_REGISTER_INTERVAL;
4293 static u64 mreg_sent_counter = 0;
4295 pending_map_register_t *pmr;
4298 if (!lcm->is_enabled || !lcm->map_registering)
4302 pool_foreach (pmr, lcm->pending_map_registers_pool,
4304 if (!update_pending_map_register (pmr, dt, &del_all))
4308 vec_add1 (to_be_removed, pmr - lcm->pending_map_registers_pool);
4315 /* delete all pending map register messages so they won't
4316 * trigger another map server election.. */
4317 pool_free (lcm->pending_map_registers_pool);
4318 hash_free (lcm->map_register_messages_by_nonce);
4320 /* ..and trigger registration against next map server (if any) */
4325 vec_foreach (pmr_index, to_be_removed)
4326 pool_put_index (lcm->pending_map_registers_pool, pmr_index[0]);
4329 vec_free (to_be_removed);
4334 if (mreg_sent_counter >= QUICK_MAP_REGISTER_MSG_COUNT)
4335 time_left = MAP_REGISTER_INTERVAL;
4338 mreg_sent_counter++;
4339 time_left = QUICK_MAP_REGISTER_INTERVAL;
4341 send_map_register (lcm, 1 /* want map notify */ );
4346 send_map_resolver_service (vlib_main_t * vm,
4347 vlib_node_runtime_t * rt, vlib_frame_t * f)
4351 pending_map_request_t *pmr;
4352 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4356 vlib_process_wait_for_event_or_clock (vm, period);
4358 /* currently no signals are expected - just wait for clock */
4359 (void) vlib_process_get_events (vm, 0);
4362 pool_foreach (pmr, lcm->pending_map_requests_pool,
4364 if (!pmr->to_be_removed)
4365 update_pending_request (pmr, period);
4369 remove_dead_pending_map_requests (lcm);
4371 update_map_register (lcm, period);
4372 update_rloc_probing (lcm, period);
4374 u64 now = clib_cpu_time_now ();
4376 expired = timing_wheel_advance (&lcm->wheel, now, expired, 0);
4377 if (vec_len (expired) > 0)
4380 vec_foreach (mi, expired)
4382 remove_expired_mapping (lcm, mi[0]);
4384 _vec_len (expired) = 0;
4393 vnet_lisp_stats_enable_disable (u8 enable)
4395 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4397 if (vnet_lisp_enable_disable_status () == 0)
4398 return VNET_API_ERROR_LISP_DISABLED;
4401 lcm->flags |= LISP_FLAG_STATS_ENABLED;
4403 lcm->flags &= ~LISP_FLAG_STATS_ENABLED;
4409 vnet_lisp_stats_enable_disable_state (void)
4411 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
4413 if (vnet_lisp_enable_disable_status () == 0)
4414 return VNET_API_ERROR_LISP_DISABLED;
4416 return lcm->flags & LISP_FLAG_STATS_ENABLED;
4420 VLIB_REGISTER_NODE (lisp_retry_service_node,static) = {
4421 .function = send_map_resolver_service,
4422 .type = VLIB_NODE_TYPE_PROCESS,
4423 .name = "lisp-retry-service",
4424 .process_log2_n_stack_bytes = 16,
4428 VLIB_INIT_FUNCTION (lisp_cp_init);
4431 * fd.io coding-style-patch-verification: ON
4434 * eval: (c-set-style "gnu")