X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Flisp-cp%2Fcontrol.c;h=60d85619dc51c6f87224e48ce7427781a0f232aa;hb=6c25154e9544810afc1179ce8b0977a9786a8027;hp=c54ec577fb495897d11d71d1bef645fc4cf494fc;hpb=d37da9004f168c248ba8f4fdc1acd5e0344ae7f6;p=vpp.git diff --git a/src/vnet/lisp-cp/control.c b/src/vnet/lisp-cp/control.c index c54ec577fb4..60d85619dc5 100644 --- a/src/vnet/lisp-cp/control.c +++ b/src/vnet/lisp-cp/control.c @@ -114,7 +114,7 @@ ip_interface_get_first_ip_address (lisp_cp_main_t * lcm, u32 sw_if_index, ip_lookup_main_t *lm; void *addr; - lm = (version == IP4) ? &lcm->im4->lookup_main : &lcm->im6->lookup_main; + lm = (version == AF_IP4) ? &lcm->im4->lookup_main : &lcm->im6->lookup_main; addr = ip_interface_get_first_address (lm, sw_if_index, version); if (!addr) return 0; @@ -123,38 +123,6 @@ ip_interface_get_first_ip_address (lisp_cp_main_t * lcm, u32 sw_if_index, return 1; } -/** - * convert from a LISP address to a FIB prefix - */ -void -ip_address_to_fib_prefix (const ip_address_t * addr, fib_prefix_t * prefix) -{ - if (addr->version == IP4) - { - prefix->fp_len = 32; - prefix->fp_proto = FIB_PROTOCOL_IP4; - clib_memset (&prefix->fp_addr.pad, 0, sizeof (prefix->fp_addr.pad)); - memcpy (&prefix->fp_addr.ip4, &addr->ip, sizeof (prefix->fp_addr.ip4)); - } - else - { - prefix->fp_len = 128; - prefix->fp_proto = FIB_PROTOCOL_IP6; - memcpy (&prefix->fp_addr.ip6, &addr->ip, sizeof (prefix->fp_addr.ip6)); - } -} - -/** - * convert from a LISP to a FIB prefix - */ -void -ip_prefix_to_fib_prefix (const ip_prefix_t * ip_prefix, - fib_prefix_t * fib_prefix) -{ - ip_address_to_fib_prefix (&ip_prefix->addr, fib_prefix); - fib_prefix->fp_len = ip_prefix->len; -} - /** * Find the sw_if_index of the interface that would be used to egress towards * dst. @@ -189,7 +157,7 @@ ip_fib_get_first_egress_ip_for_dst (lisp_cp_main_t * lcm, ip_address_t * dst, ipver = ip_addr_version (dst); - lm = (ipver == IP4) ? &lcm->im4->lookup_main : &lcm->im6->lookup_main; + lm = (ipver == AF_IP4) ? &lcm->im4->lookup_main : &lcm->im6->lookup_main; si = ip_fib_get_egress_iface_for_dst (lcm, dst); if ((u32) ~ 0 == si) @@ -899,16 +867,17 @@ vnet_lisp_add_del_local_mapping (vnet_lisp_add_del_mapping_args_t * a, return vnet_lisp_map_cache_add_del (a, map_index_result); } -static void +static int add_l2_arp_bd (BVT (clib_bihash_kv) * kvp, void *arg) { u32 **ht = arg; u32 version = (u32) kvp->key[0]; - if (IP6 == version) - return; + if (AF_IP6 == version) + return (BIHASH_WALK_CONTINUE); u32 bd = (u32) (kvp->key[0] >> 32); hash_set (ht[0], bd, 0); + return (BIHASH_WALK_CONTINUE); } u32 * @@ -922,16 +891,17 @@ vnet_lisp_l2_arp_bds_get (void) return bds; } -static void +static int add_ndp_bd (BVT (clib_bihash_kv) * kvp, void *arg) { u32 **ht = arg; u32 version = (u32) kvp->key[0]; - if (IP4 == version) - return; + if (AF_IP4 == version) + return (BIHASH_WALK_CONTINUE); u32 bd = (u32) (kvp->key[0] >> 32); hash_set (ht[0], bd, 0); + return (BIHASH_WALK_CONTINUE); } u32 * @@ -951,15 +921,15 @@ typedef struct u32 bd; } lisp_add_l2_arp_ndp_args_t; -static void +static int add_l2_arp_entry (BVT (clib_bihash_kv) * kvp, void *arg) { lisp_add_l2_arp_ndp_args_t *a = arg; lisp_api_l2_arp_entry_t **vector = a->vector, e; u32 version = (u32) kvp->key[0]; - if (IP6 == version) - return; + if (AF_IP6 == version) + return (BIHASH_WALK_CONTINUE); u32 bd = (u32) (kvp->key[0] >> 32); @@ -969,6 +939,7 @@ add_l2_arp_entry (BVT (clib_bihash_kv) * kvp, void *arg) e.ip4 = (u32) kvp->key[1]; vec_add1 (vector[0], e); } + return (BIHASH_WALK_CONTINUE); } lisp_api_l2_arp_entry_t * @@ -986,15 +957,15 @@ vnet_lisp_l2_arp_entries_get_by_bd (u32 bd) return entries; } -static void +static int add_ndp_entry (BVT (clib_bihash_kv) * kvp, void *arg) { lisp_add_l2_arp_ndp_args_t *a = arg; lisp_api_ndp_entry_t **vector = a->vector, e; u32 version = (u32) kvp->key[0]; - if (IP4 == version) - return; + if (AF_IP4 == version) + return (BIHASH_WALK_CONTINUE); u32 bd = (u32) (kvp->key[0] >> 32); @@ -1004,6 +975,7 @@ add_ndp_entry (BVT (clib_bihash_kv) * kvp, void *arg) clib_memcpy (e.ip6, &kvp->key[1], 16); vec_add1 (vector[0], e); } + return (BIHASH_WALK_CONTINUE); } lisp_api_ndp_entry_t * @@ -1231,12 +1203,6 @@ remove_overlapping_sub_prefixes (lisp_cp_main_t * lcm, gid_address_t * eid, vec_free (a.eids_to_be_deleted); } -static void -mapping_delete_timer (lisp_cp_main_t * lcm, u32 mi) -{ - timing_wheel_delete (&lcm->wheel, mi); -} - static int is_local_ip (lisp_cp_main_t * lcm, ip_address_t * addr) { @@ -1397,18 +1363,18 @@ vnet_lisp_del_mapping (gid_address_t * eid, u32 * res_map_index) gid_address_copy (&m_args->eid, eid); m_args->locator_set_index = old_map->locator_set_index; - /* delete mapping associated from map-cache */ - vnet_lisp_map_cache_add_del (m_args, 0); - ls_args->is_add = 0; ls_args->index = old_map->locator_set_index; + /* delete timer associated to the mapping if any */ + if (old_map->timer_set) + TW (tw_timer_stop) (&lcm->wheel, old_map->timer_handle); + /* delete locator set */ vnet_lisp_add_del_locator_set (ls_args, 0); - /* delete timer associated to the mapping if any */ - if (old_map->timer_set) - mapping_delete_timer (lcm, mi); + /* delete mapping associated from map-cache */ + vnet_lisp_map_cache_add_del (m_args, 0); /* return old mapping index */ if (res_map_index) @@ -1698,7 +1664,7 @@ vnet_lisp_use_petr (ip_address_t * ip, u8 is_add) if (is_add) { - /* Create dummy petr locator-set */ + /* Create placeholder petr locator-set */ clib_memset (&loc, 0, sizeof (loc)); gid_address_from_ip (&loc.address, ip); loc.priority = 1; @@ -2003,8 +1969,8 @@ vnet_lisp_add_del_locator (vnet_lisp_add_del_locator_set_args_t * a, removed = 1; remove_locator_from_locator_set (ls, locit, ls_index, loc_id); } - if (0 == loc->local && - !gid_address_cmp (&loc->address, &itloc->address)) + else if (0 == loc->local && + !gid_address_cmp (&loc->address, &itloc->address)) { removed = 1; remove_locator_from_locator_set (ls, locit, ls_index, loc_id); @@ -2082,14 +2048,9 @@ vnet_lisp_add_del_locator_set (vnet_lisp_add_del_locator_set_args_t * a, ls->name = vec_dup (a->name); if (!lcm->locator_set_index_by_name) - lcm->locator_set_index_by_name = hash_create_vec ( - /* size */ - 0, - sizeof - (ls->name - [0]), - sizeof - (uword)); + lcm->locator_set_index_by_name = + hash_create_vec ( /* size */ 0, sizeof (ls->name[0]), + sizeof (uword)); hash_set_mem (lcm->locator_set_index_by_name, ls->name, ls_index); @@ -2513,7 +2474,7 @@ build_itr_rloc_list (lisp_cp_main_t * lcm, locator_set_t * loc_set) loc->sw_if_index, 1 /* unnumbered */, ({ addr = ip_interface_address_get_address (&lcm->im4->lookup_main, ia); - ip_address_set (rloc, addr, IP4); + ip_address_set (rloc, addr, AF_IP4); ip_prefix_len (ippref) = 32; ip_prefix_normalize (ippref); vec_add1 (rlocs, gid[0]); @@ -2524,7 +2485,7 @@ build_itr_rloc_list (lisp_cp_main_t * lcm, locator_set_t * loc_set) loc->sw_if_index, 1 /* unnumbered */, ({ addr = ip_interface_address_get_address (&lcm->im6->lookup_main, ia); - ip_address_set (rloc, addr, IP6); + ip_address_set (rloc, addr, AF_IP6); ip_prefix_len (ippref) = 128; ip_prefix_normalize (ippref); vec_add1 (rlocs, gid[0]); @@ -2687,7 +2648,7 @@ add_locators (lisp_cp_main_t * lcm, mapping_t * m, u32 locator_set_index, ({ addr = ip_interface_address_get_address (&lcm->im4->lookup_main, ia); - ip_address_set (new_ip, addr, IP4); + ip_address_set (new_ip, addr, AF_IP4); })); /* Add ipv6 locators */ @@ -2696,7 +2657,7 @@ add_locators (lisp_cp_main_t * lcm, mapping_t * m, u32 locator_set_index, ({ addr = ip_interface_address_get_address (&lcm->im6->lookup_main, ia); - ip_address_set (new_ip, addr, IP6); + ip_address_set (new_ip, addr, AF_IP6); })); /* *INDENT-ON* */ @@ -2876,7 +2837,7 @@ lisp_cp_output (vlib_main_t * vm, vlib_node_runtime_t * node, return 0; } -/* dummy node used only for statistics */ +/* placeholder node used only for statistics */ /* *INDENT-OFF* */ VLIB_REGISTER_NODE (lisp_cp_output_node) = { .function = lisp_cp_output, @@ -2919,7 +2880,7 @@ send_rloc_probe (lisp_cp_main_t * lcm, gid_address_t * deid, vnet_buffer (b)->sw_if_index[VLIB_TX] = 0; - next_index = (ip_addr_version (rloc) == IP4) ? + next_index = (ip_addr_version (rloc) == AF_IP4) ? ip4_lookup_node.index : ip6_lookup_node.index; f = vlib_get_frame_to_node (lcm->vlib_main, next_index); @@ -3031,7 +2992,7 @@ send_map_register (lisp_cp_main_t * lcm, u8 want_map_notif) vnet_buffer (b)->sw_if_index[VLIB_TX] = 0; - next_index = (ip_addr_version (&lcm->active_map_server) == IP4) ? + next_index = (ip_addr_version (&lcm->active_map_server) == AF_IP4) ? ip4_lookup_node.index : ip6_lookup_node.index; f = vlib_get_frame_to_node (lcm->vlib_main, next_index); @@ -3178,7 +3139,7 @@ _send_encapsulated_map_request (lisp_cp_main_t * lcm, /* set fib index to default and lookup node */ vnet_buffer (b)->sw_if_index[VLIB_TX] = 0; - next_index = (ip_addr_version (&lcm->active_map_resolver) == IP4) ? + next_index = (ip_addr_version (&lcm->active_map_resolver) == AF_IP4) ? ip4_lookup_node.index : ip6_lookup_node.index; f = vlib_get_frame_to_node (lcm->vlib_main, next_index); @@ -3233,14 +3194,14 @@ get_src_and_dst_ip (void *hdr, ip_address_t * src, ip_address_t * dst) if ((ip4->ip_version_and_header_length & 0xF0) == 0x40) { - ip_address_set (src, &ip4->src_address, IP4); - ip_address_set (dst, &ip4->dst_address, IP4); + ip_address_set (src, &ip4->src_address, AF_IP4); + ip_address_set (dst, &ip4->dst_address, AF_IP4); } else { ip6 = hdr; - ip_address_set (src, &ip6->src_address, IP6); - ip_address_set (dst, &ip6->dst_address, IP6); + ip_address_set (src, &ip6->src_address, AF_IP6); + ip_address_set (dst, &ip6->dst_address, AF_IP6); } } @@ -3252,7 +3213,8 @@ lisp_get_vni_from_buffer_ip (lisp_cp_main_t * lcm, vlib_buffer_t * b, u32 vni = ~0, table_id = ~0; table_id = fib_table_get_table_id_for_sw_if_index ((version == - IP4 ? FIB_PROTOCOL_IP4 : + AF_IP4 ? + FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6), vnet_buffer (b)->sw_if_index @@ -3350,7 +3312,7 @@ get_src_and_dst_eids_from_buffer (lisp_cp_main_t * lcm, vlib_buffer_t * b, { clib_memset (&gid_address_arp_ndp_ip (dst), 0, sizeof (ip_address_t)); - ip_addr_version (&gid_address_arp_ndp_ip (dst)) = IP4; + ip_addr_version (&gid_address_arp_ndp_ip (dst)) = AF_IP4; gid_address_arp_ndp_bd (dst) = ~0; return; } @@ -3383,7 +3345,7 @@ get_src_and_dst_eids_from_buffer (lisp_cp_main_t * lcm, vlib_buffer_t * b, clib_memset (&gid_address_arp_ndp_ip (dst), 0, sizeof (ip_address_t)); ip_addr_version (&gid_address_arp_ndp_ip (dst)) = - IP6; + AF_IP6; gid_address_arp_ndp_bd (dst) = ~0; gid_address_type (src) = GID_ADDR_NO_ADDRESS; return; @@ -3392,7 +3354,7 @@ get_src_and_dst_eids_from_buffer (lisp_cp_main_t * lcm, vlib_buffer_t * b, gid_address_ndp_bd (dst) = lisp_get_bd_from_buffer_eth (b); ip_address_set (&gid_address_arp_ndp_ip (dst), - &ndh->target_address, IP6); + &ndh->target_address, AF_IP6); return; } } @@ -3590,7 +3552,11 @@ lisp_cp_lookup_inline (vlib_main_t * vm, sizeof (*tr)); clib_memset (tr, 0, sizeof (*tr)); - gid_address_copy (&tr->dst_eid, &dst); + if ((gid_address_type (&dst) == GID_ADDR_NDP) || + (gid_address_type (&dst) == GID_ADDR_ARP)) + clib_memcpy (&tr->dst_eid, &dst, sizeof (gid_address_t)); + else + gid_address_copy (&tr->dst_eid, &dst); ip_address_copy (&tr->map_resolver_ip, &lcm->active_map_resolver); } @@ -3769,8 +3735,8 @@ remove_expired_mapping (lisp_cp_main_t * lcm, u32 mi) if (vnet_lisp_add_del_adjacency (adj_args)) clib_warning ("failed to del adjacency!"); + TW (tw_timer_stop) (&lcm->wheel, m->timer_handle); vnet_lisp_del_mapping (&m->eid, NULL); - mapping_delete_timer (lcm, mi); } static void @@ -3785,7 +3751,7 @@ mapping_start_expiration_timer (lisp_cp_main_t * lcm, u32 mi, m = pool_elt_at_index (lcm->mapping_pool, mi); m->timer_set = 1; - timing_wheel_insert (&lcm->wheel, exp_clock_time, mi); + m->timer_handle = TW (tw_timer_start) (&lcm->wheel, mi, 0, exp_clock_time); } static void @@ -4228,7 +4194,7 @@ send_map_reply (lisp_cp_main_t * lcm, u32 mi, ip_address_t * dst, free_map_register_records (records); vnet_buffer (b)->sw_if_index[VLIB_TX] = 0; - next_index = (ip_addr_version (&lcm->active_map_resolver) == IP4) ? + next_index = (ip_addr_version (&lcm->active_map_resolver) == AF_IP4) ? ip4_lookup_node.index : ip6_lookup_node.index; f = vlib_get_frame_to_node (lcm->vlib_main, next_index); @@ -4360,7 +4326,7 @@ parse_map_reply (vlib_buffer_t * b) a->is_rloc_probe = MREP_RLOC_PROBE (mrep_hdr); if (!vlib_buffer_has_space (b, sizeof (*mrep_hdr))) { - clib_mem_free (a); + map_records_arg_free (a); return 0; } vlib_buffer_pull (b, sizeof (*mrep_hdr)); @@ -4538,8 +4504,9 @@ lisp_cp_init (vlib_main_t * vm) hash_set (lcm->table_id_by_vni, 0, 0); hash_set (lcm->vni_by_table_id, 0, 0); - u64 now = clib_cpu_time_now (); - timing_wheel_init (&lcm->wheel, now, vm->clib_time.clocks_per_second); + TW (tw_timer_wheel_init) (&lcm->wheel, 0 /* no callback */ , + 1e-3 /* timer period 1ms */ , + ~0 /* max expirations per call */ ); lcm->nsh_map_index = ~0; lcm->map_register_ttl = MAP_REGISTER_DEFAULT_TTL; lcm->max_expired_map_registers = MAX_EXPIRED_MAP_REGISTERS_DEFAULT; @@ -4861,9 +4828,8 @@ send_map_resolver_service (vlib_main_t * vm, update_map_register (lcm, period); update_rloc_probing (lcm, period); - u64 now = clib_cpu_time_now (); - - expired = timing_wheel_advance (&lcm->wheel, now, expired, 0); + expired = TW (tw_timer_expire_timers_vec) (&lcm->wheel, + vlib_time_now (vm), expired); if (vec_len (expired) > 0) { u32 *mi = 0;