Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 1 | /* |
| 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: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 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. |
| 14 | */ |
| 15 | |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 16 | #include <vlibmemory/api.h> |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 17 | #include <vnet/lisp-cp/control.h> |
| 18 | #include <vnet/lisp-cp/packets.h> |
| 19 | #include <vnet/lisp-cp/lisp_msg_serdes.h> |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 20 | #include <vnet/lisp-gpe/lisp_gpe_fwd_entry.h> |
| 21 | #include <vnet/lisp-gpe/lisp_gpe_tenant.h> |
Filip Tehlar | 4868ff6 | 2017-03-09 16:48:39 +0100 | [diff] [blame] | 22 | #include <vnet/lisp-gpe/lisp_gpe_tunnel.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 23 | #include <vnet/fib/fib_entry.h> |
| 24 | #include <vnet/fib/fib_table.h> |
Filip Tehlar | d5a65db | 2017-05-17 17:21:10 +0200 | [diff] [blame] | 25 | #include <vnet/ethernet/arp_packet.h> |
| 26 | #include <vnet/ethernet/packet.h> |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 27 | |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 28 | #include <openssl/evp.h> |
| 29 | #include <openssl/hmac.h> |
| 30 | |
Filip Tehlar | ef2a5bf | 2017-05-30 07:14:46 +0200 | [diff] [blame] | 31 | #define MAX_VALUE_U24 0xffffff |
| 32 | |
Florin Coras | f3dc11a | 2017-01-24 03:13:43 -0800 | [diff] [blame] | 33 | lisp_cp_main_t lisp_control_main; |
| 34 | |
Filip Tehlar | cda7066 | 2017-01-16 10:30:03 +0100 | [diff] [blame] | 35 | u8 *format_lisp_cp_input_trace (u8 * s, va_list * args); |
| 36 | |
| 37 | typedef enum |
| 38 | { |
| 39 | LISP_CP_INPUT_NEXT_DROP, |
| 40 | LISP_CP_INPUT_N_NEXT, |
| 41 | } lisp_cp_input_next_t; |
| 42 | |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 43 | typedef struct |
| 44 | { |
| 45 | u8 is_resend; |
| 46 | gid_address_t seid; |
| 47 | gid_address_t deid; |
| 48 | u8 smr_invoked; |
| 49 | } map_request_args_t; |
| 50 | |
Florin Coras | dca8804 | 2016-09-14 16:01:38 +0200 | [diff] [blame] | 51 | u8 |
| 52 | vnet_lisp_get_map_request_mode (void) |
| 53 | { |
| 54 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 55 | return lcm->map_request_mode; |
| 56 | } |
| 57 | |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 58 | static u16 |
| 59 | auth_data_len_by_key_id (lisp_key_type_t key_id) |
| 60 | { |
| 61 | switch (key_id) |
| 62 | { |
| 63 | case HMAC_SHA_1_96: |
| 64 | return SHA1_AUTH_DATA_LEN; |
| 65 | case HMAC_SHA_256_128: |
| 66 | return SHA256_AUTH_DATA_LEN; |
| 67 | default: |
| 68 | clib_warning ("unsupported key type: %d!", key_id); |
| 69 | return (u16) ~ 0; |
| 70 | } |
| 71 | return (u16) ~ 0; |
| 72 | } |
| 73 | |
| 74 | static const EVP_MD * |
| 75 | get_encrypt_fcn (lisp_key_type_t key_id) |
| 76 | { |
| 77 | switch (key_id) |
| 78 | { |
| 79 | case HMAC_SHA_1_96: |
| 80 | return EVP_sha1 (); |
| 81 | case HMAC_SHA_256_128: |
| 82 | return EVP_sha256 (); |
| 83 | default: |
| 84 | clib_warning ("unsupported encryption key type: %d!", key_id); |
| 85 | break; |
| 86 | } |
| 87 | return 0; |
| 88 | } |
| 89 | |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 90 | static int |
| 91 | queue_map_request (gid_address_t * seid, gid_address_t * deid, |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 92 | u8 smr_invoked, u8 is_resend); |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 93 | |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 94 | ip_interface_address_t * |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 95 | ip_interface_get_first_interface_address (ip_lookup_main_t * lm, |
| 96 | u32 sw_if_index, u8 loop) |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 97 | { |
| 98 | vnet_main_t *vnm = vnet_get_main (); |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 99 | vnet_sw_interface_t *swif = vnet_get_sw_interface (vnm, sw_if_index); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 100 | if (loop && swif->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED) |
| 101 | sw_if_index = swif->unnumbered_sw_if_index; |
| 102 | u32 ia = |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 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)) : |
| 105 | (u32) ~ 0; |
| 106 | return pool_elt_at_index ((lm)->if_address_pool, ia); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 107 | } |
Filip Tehlar | 215104e | 2016-05-10 16:58:29 +0200 | [diff] [blame] | 108 | |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 109 | void * |
| 110 | ip_interface_get_first_address (ip_lookup_main_t * lm, u32 sw_if_index, |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 111 | u8 version) |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 112 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 113 | ip_interface_address_t *ia; |
Filip Tehlar | 195bcee | 2016-05-13 17:37:35 +0200 | [diff] [blame] | 114 | |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 115 | ia = ip_interface_get_first_interface_address (lm, sw_if_index, 1); |
| 116 | if (!ia) |
| 117 | return 0; |
| 118 | return ip_interface_address_get_address (lm, ia); |
| 119 | } |
Filip Tehlar | 195bcee | 2016-05-13 17:37:35 +0200 | [diff] [blame] | 120 | |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 121 | int |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 122 | ip_interface_get_first_ip_address (lisp_cp_main_t * lcm, u32 sw_if_index, |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 123 | u8 version, ip_address_t * result) |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 124 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 125 | ip_lookup_main_t *lm; |
| 126 | void *addr; |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 127 | |
| 128 | lm = (version == IP4) ? &lcm->im4->lookup_main : &lcm->im6->lookup_main; |
| 129 | addr = ip_interface_get_first_address (lm, sw_if_index, version); |
| 130 | if (!addr) |
| 131 | return 0; |
| 132 | |
| 133 | ip_address_set (result, addr, version); |
| 134 | return 1; |
| 135 | } |
| 136 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 137 | /** |
| 138 | * convert from a LISP address to a FIB prefix |
| 139 | */ |
| 140 | void |
| 141 | ip_address_to_fib_prefix (const ip_address_t * addr, fib_prefix_t * prefix) |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 142 | { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 143 | if (addr->version == IP4) |
| 144 | { |
| 145 | prefix->fp_len = 32; |
| 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)); |
| 149 | } |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 150 | else |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 151 | { |
| 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)); |
| 155 | } |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 156 | } |
| 157 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 158 | /** |
| 159 | * convert from a LISP to a FIB prefix |
| 160 | */ |
| 161 | void |
| 162 | ip_prefix_to_fib_prefix (const ip_prefix_t * ip_prefix, |
| 163 | fib_prefix_t * fib_prefix) |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 164 | { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 165 | ip_address_to_fib_prefix (&ip_prefix->addr, fib_prefix); |
| 166 | fib_prefix->fp_len = ip_prefix->len; |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | /** |
| 170 | * Find the sw_if_index of the interface that would be used to egress towards |
| 171 | * dst. |
| 172 | */ |
| 173 | u32 |
| 174 | ip_fib_get_egress_iface_for_dst (lisp_cp_main_t * lcm, ip_address_t * dst) |
| 175 | { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 176 | fib_node_index_t fei; |
| 177 | fib_prefix_t prefix; |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 178 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 179 | ip_address_to_fib_prefix (dst, &prefix); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 180 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 181 | fei = fib_table_lookup (0, &prefix); |
| 182 | |
| 183 | return (fib_entry_get_resolving_interface (fei)); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | /** |
| 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. |
| 189 | */ |
| 190 | int |
| 191 | ip_fib_get_first_egress_ip_for_dst (lisp_cp_main_t * lcm, ip_address_t * dst, |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 192 | ip_address_t * result) |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 193 | { |
| 194 | u32 si; |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 195 | ip_lookup_main_t *lm; |
| 196 | void *addr = 0; |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 197 | u8 ipver; |
| 198 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 199 | ASSERT (result != 0); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 200 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 201 | ipver = ip_addr_version (dst); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 202 | |
| 203 | lm = (ipver == IP4) ? &lcm->im4->lookup_main : &lcm->im6->lookup_main; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 204 | si = ip_fib_get_egress_iface_for_dst (lcm, dst); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 205 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 206 | if ((u32) ~ 0 == si) |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 207 | return 0; |
| 208 | |
| 209 | /* find the first ip address */ |
| 210 | addr = ip_interface_get_first_address (lm, si, ipver); |
| 211 | if (0 == addr) |
| 212 | return 0; |
| 213 | |
| 214 | ip_address_set (result, addr, ipver); |
| 215 | return 1; |
| 216 | } |
| 217 | |
| 218 | static int |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 219 | dp_add_del_iface (lisp_cp_main_t * lcm, u32 vni, u8 is_l2, u8 is_add) |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 220 | { |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 221 | uword *dp_table; |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 222 | |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 223 | if (!is_l2) |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 224 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 225 | dp_table = hash_get (lcm->table_id_by_vni, vni); |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 226 | |
| 227 | if (!dp_table) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 228 | { |
| 229 | clib_warning ("vni %d not associated to a vrf!", vni); |
| 230 | return VNET_API_ERROR_INVALID_VALUE; |
| 231 | } |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 232 | } |
| 233 | else |
| 234 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 235 | dp_table = hash_get (lcm->bd_id_by_vni, vni); |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 236 | if (!dp_table) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 237 | { |
| 238 | clib_warning ("vni %d not associated to a bridge domain!", vni); |
| 239 | return VNET_API_ERROR_INVALID_VALUE; |
| 240 | } |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 241 | } |
| 242 | |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 243 | /* enable/disable data-plane interface */ |
| 244 | if (is_add) |
| 245 | { |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 246 | if (is_l2) |
| 247 | lisp_gpe_tenant_l2_iface_add_or_lock (vni, dp_table[0]); |
| 248 | else |
| 249 | lisp_gpe_tenant_l3_iface_add_or_lock (vni, dp_table[0]); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 250 | } |
| 251 | else |
| 252 | { |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 253 | if (is_l2) |
| 254 | lisp_gpe_tenant_l2_iface_unlock (vni); |
| 255 | else |
| 256 | lisp_gpe_tenant_l3_iface_unlock (vni); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | return 0; |
| 260 | } |
| 261 | |
| 262 | static void |
| 263 | dp_del_fwd_entry (lisp_cp_main_t * lcm, u32 src_map_index, u32 dst_map_index) |
| 264 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 265 | vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a; |
| 266 | fwd_entry_t *fe = 0; |
| 267 | uword *feip = 0; |
| 268 | memset (a, 0, sizeof (*a)); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 269 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 270 | feip = hash_get (lcm->fwd_entry_by_mapping_index, dst_map_index); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 271 | if (!feip) |
| 272 | return; |
| 273 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 274 | fe = pool_elt_at_index (lcm->fwd_entry_pool, feip[0]); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 275 | |
| 276 | /* delete dp fwd entry */ |
| 277 | u32 sw_if_index; |
| 278 | a->is_add = 0; |
Florin Coras | bb5c22f | 2016-08-02 02:31:03 +0200 | [diff] [blame] | 279 | a->locator_pairs = fe->locator_pairs; |
Filip Tehlar | 2fdaece | 2016-09-28 14:27:59 +0200 | [diff] [blame] | 280 | a->vni = gid_address_vni (&fe->reid); |
| 281 | gid_address_copy (&a->rmt_eid, &fe->reid); |
Filip Tehlar | d5fcc46 | 2016-10-17 16:20:18 +0200 | [diff] [blame] | 282 | if (fe->is_src_dst) |
| 283 | gid_address_copy (&a->lcl_eid, &fe->leid); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 284 | |
Filip Tehlar | 2151191 | 2017-04-07 10:41:42 +0200 | [diff] [blame] | 285 | vnet_lisp_gpe_del_fwd_counters (a, feip[0]); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 286 | vnet_lisp_gpe_add_del_fwd_entry (a, &sw_if_index); |
| 287 | |
| 288 | /* delete entry in fwd table */ |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 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); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | /** |
| 295 | * Finds first remote locator with best (lowest) priority that has a local |
| 296 | * peer locator with an underlying route to it. |
| 297 | * |
| 298 | */ |
| 299 | static u32 |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 300 | get_locator_pairs (lisp_cp_main_t * lcm, mapping_t * lcl_map, |
| 301 | mapping_t * rmt_map, locator_pair_t ** locator_pairs) |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 302 | { |
Florin Coras | 3590ac5 | 2016-08-08 16:04:26 +0200 | [diff] [blame] | 303 | u32 i, limitp = 0, li, found = 0, esi; |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 304 | locator_set_t *rmt_ls, *lcl_ls; |
| 305 | ip_address_t _lcl_addr, *lcl_addr = &_lcl_addr; |
| 306 | locator_t *lp, *rmt = 0; |
| 307 | uword *checked = 0; |
Florin Coras | bb5c22f | 2016-08-02 02:31:03 +0200 | [diff] [blame] | 308 | locator_pair_t pair; |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 309 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 310 | rmt_ls = |
| 311 | pool_elt_at_index (lcm->locator_set_pool, rmt_map->locator_set_index); |
| 312 | lcl_ls = |
| 313 | pool_elt_at_index (lcm->locator_set_pool, lcl_map->locator_set_index); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 314 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 315 | if (!rmt_ls || vec_len (rmt_ls->locator_indices) == 0) |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 316 | return 0; |
| 317 | |
Florin Coras | 3590ac5 | 2016-08-08 16:04:26 +0200 | [diff] [blame] | 318 | while (1) |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 319 | { |
| 320 | rmt = 0; |
| 321 | |
| 322 | /* find unvisited remote locator with best priority */ |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 323 | for (i = 0; i < vec_len (rmt_ls->locator_indices); i++) |
| 324 | { |
| 325 | if (0 != hash_get (checked, i)) |
| 326 | continue; |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 327 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 328 | li = vec_elt (rmt_ls->locator_indices, i); |
| 329 | lp = pool_elt_at_index (lcm->locator_pool, li); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 330 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 331 | /* we don't support non-IP locators for now */ |
| 332 | if (gid_address_type (&lp->address) != GID_ADDR_IP_PREFIX) |
| 333 | continue; |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 334 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 335 | if ((found && lp->priority == limitp) |
| 336 | || (!found && lp->priority >= limitp)) |
| 337 | { |
| 338 | rmt = lp; |
Florin Coras | 3590ac5 | 2016-08-08 16:04:26 +0200 | [diff] [blame] | 339 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 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); |
| 344 | break; |
| 345 | } |
| 346 | } |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 347 | /* check if a local locator with a route to remote locator exists */ |
| 348 | if (rmt != 0) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 349 | { |
| 350 | /* find egress sw_if_index for rmt locator */ |
| 351 | esi = |
| 352 | ip_fib_get_egress_iface_for_dst (lcm, |
| 353 | &gid_address_ip (&rmt->address)); |
| 354 | if ((u32) ~ 0 == esi) |
| 355 | continue; |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 356 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 357 | for (i = 0; i < vec_len (lcl_ls->locator_indices); i++) |
| 358 | { |
| 359 | li = vec_elt (lcl_ls->locator_indices, i); |
| 360 | locator_t *sl = pool_elt_at_index (lcm->locator_pool, li); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 361 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 362 | /* found local locator with the needed sw_if_index */ |
| 363 | if (sl->sw_if_index == esi) |
| 364 | { |
| 365 | /* and it has an address */ |
| 366 | if (0 == ip_interface_get_first_ip_address (lcm, |
| 367 | sl->sw_if_index, |
| 368 | gid_address_ip_version |
| 369 | (&rmt->address), |
| 370 | lcl_addr)) |
| 371 | continue; |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 372 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 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; |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 378 | pair.priority = rmt->priority; |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 379 | vec_add1 (locator_pairs[0], pair); |
| 380 | found = 1; |
| 381 | } |
| 382 | } |
| 383 | } |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 384 | else |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 385 | break; |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 386 | } |
Florin Coras | 3590ac5 | 2016-08-08 16:04:26 +0200 | [diff] [blame] | 387 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 388 | hash_free (checked); |
Florin Coras | 3590ac5 | 2016-08-08 16:04:26 +0200 | [diff] [blame] | 389 | return found; |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | static void |
Florin Coras | dca8804 | 2016-09-14 16:01:38 +0200 | [diff] [blame] | 393 | gid_address_sd_to_flat (gid_address_t * dst, gid_address_t * src, |
| 394 | fid_address_t * fid) |
| 395 | { |
| 396 | ASSERT (GID_ADDR_SRC_DST == gid_address_type (src)); |
| 397 | |
| 398 | dst[0] = src[0]; |
| 399 | |
| 400 | switch (fid_addr_type (fid)) |
| 401 | { |
| 402 | case FID_ADDR_IP_PREF: |
| 403 | gid_address_type (dst) = GID_ADDR_IP_PREFIX; |
| 404 | gid_address_ippref (dst) = fid_addr_ippref (fid); |
| 405 | break; |
| 406 | case FID_ADDR_MAC: |
| 407 | gid_address_type (dst) = GID_ADDR_MAC; |
| 408 | mac_copy (gid_address_mac (dst), fid_addr_mac (fid)); |
| 409 | break; |
| 410 | default: |
| 411 | clib_warning ("Unsupported fid type %d!", fid_addr_type (fid)); |
| 412 | break; |
| 413 | } |
| 414 | } |
| 415 | |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 416 | u8 |
| 417 | vnet_lisp_map_register_state_get (void) |
| 418 | { |
| 419 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 420 | return lcm->map_registering; |
| 421 | } |
| 422 | |
| 423 | u8 |
| 424 | vnet_lisp_rloc_probe_state_get (void) |
| 425 | { |
| 426 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 427 | return lcm->rloc_probing; |
| 428 | } |
| 429 | |
Florin Coras | dca8804 | 2016-09-14 16:01:38 +0200 | [diff] [blame] | 430 | static void |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 431 | dp_add_fwd_entry (lisp_cp_main_t * lcm, u32 src_map_index, u32 dst_map_index) |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 432 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 433 | vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a; |
Florin Coras | ba888e4 | 2017-01-24 11:38:18 -0800 | [diff] [blame] | 434 | gid_address_t *rmt_eid, *lcl_eid; |
| 435 | mapping_t *lcl_map, *rmt_map; |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 436 | u32 sw_if_index; |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 437 | uword *feip = 0, *dpid; |
| 438 | fwd_entry_t *fe; |
Filip Tehlar | 69a9b76 | 2016-09-23 10:00:52 +0200 | [diff] [blame] | 439 | u8 type, is_src_dst = 0; |
Florin Coras | ba888e4 | 2017-01-24 11:38:18 -0800 | [diff] [blame] | 440 | int rv; |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 441 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 442 | memset (a, 0, sizeof (*a)); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 443 | |
| 444 | /* remove entry if it already exists */ |
| 445 | feip = hash_get (lcm->fwd_entry_by_mapping_index, dst_map_index); |
| 446 | if (feip) |
| 447 | dp_del_fwd_entry (lcm, src_map_index, dst_map_index); |
| 448 | |
Florin Coras | ba888e4 | 2017-01-24 11:38:18 -0800 | [diff] [blame] | 449 | /* |
| 450 | * Determine local mapping and eid |
| 451 | */ |
Filip Tehlar | f3e3fd3 | 2016-09-30 12:47:59 +0200 | [diff] [blame] | 452 | if (lcm->lisp_pitr) |
Florin Coras | ba888e4 | 2017-01-24 11:38:18 -0800 | [diff] [blame] | 453 | lcl_map = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index); |
Filip Tehlar | f3e3fd3 | 2016-09-30 12:47:59 +0200 | [diff] [blame] | 454 | else |
Florin Coras | ba888e4 | 2017-01-24 11:38:18 -0800 | [diff] [blame] | 455 | lcl_map = pool_elt_at_index (lcm->mapping_pool, src_map_index); |
| 456 | lcl_eid = &lcl_map->eid; |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 457 | |
Florin Coras | ba888e4 | 2017-01-24 11:38:18 -0800 | [diff] [blame] | 458 | /* |
| 459 | * Determine remote mapping and eid |
| 460 | */ |
| 461 | rmt_map = pool_elt_at_index (lcm->mapping_pool, dst_map_index); |
| 462 | rmt_eid = &rmt_map->eid; |
| 463 | |
| 464 | /* |
| 465 | * Build and insert data plane forwarding entry |
| 466 | */ |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 467 | a->is_add = 1; |
| 468 | |
Filip Tehlar | d5fcc46 | 2016-10-17 16:20:18 +0200 | [diff] [blame] | 469 | if (MR_MODE_SRC_DST == lcm->map_request_mode) |
Florin Coras | dca8804 | 2016-09-14 16:01:38 +0200 | [diff] [blame] | 470 | { |
Florin Coras | ba888e4 | 2017-01-24 11:38:18 -0800 | [diff] [blame] | 471 | if (GID_ADDR_SRC_DST == gid_address_type (rmt_eid)) |
Filip Tehlar | d5fcc46 | 2016-10-17 16:20:18 +0200 | [diff] [blame] | 472 | { |
Florin Coras | ba888e4 | 2017-01-24 11:38:18 -0800 | [diff] [blame] | 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)); |
Filip Tehlar | d5fcc46 | 2016-10-17 16:20:18 +0200 | [diff] [blame] | 477 | } |
| 478 | else |
| 479 | { |
Florin Coras | ba888e4 | 2017-01-24 11:38:18 -0800 | [diff] [blame] | 480 | gid_address_copy (&a->rmt_eid, rmt_eid); |
| 481 | gid_address_copy (&a->lcl_eid, lcl_eid); |
Filip Tehlar | d5fcc46 | 2016-10-17 16:20:18 +0200 | [diff] [blame] | 482 | } |
Filip Tehlar | 69a9b76 | 2016-09-23 10:00:52 +0200 | [diff] [blame] | 483 | is_src_dst = 1; |
Florin Coras | dca8804 | 2016-09-14 16:01:38 +0200 | [diff] [blame] | 484 | } |
| 485 | else |
Florin Coras | ba888e4 | 2017-01-24 11:38:18 -0800 | [diff] [blame] | 486 | gid_address_copy (&a->rmt_eid, rmt_eid); |
Florin Coras | dca8804 | 2016-09-14 16:01:38 +0200 | [diff] [blame] | 487 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 488 | a->vni = gid_address_vni (&a->rmt_eid); |
Filip Tehlar | ed6b52b | 2017-03-22 09:02:33 +0100 | [diff] [blame] | 489 | a->is_src_dst = is_src_dst; |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 490 | |
| 491 | /* get vrf or bd_index associated to vni */ |
Florin Coras | dca8804 | 2016-09-14 16:01:38 +0200 | [diff] [blame] | 492 | type = gid_address_type (&a->rmt_eid); |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 493 | if (GID_ADDR_IP_PREFIX == type) |
| 494 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 495 | dpid = hash_get (lcm->table_id_by_vni, a->vni); |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 496 | if (!dpid) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 497 | { |
| 498 | clib_warning ("vni %d not associated to a vrf!", a->vni); |
| 499 | return; |
| 500 | } |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 501 | a->table_id = dpid[0]; |
| 502 | } |
| 503 | else if (GID_ADDR_MAC == type) |
| 504 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 505 | dpid = hash_get (lcm->bd_id_by_vni, a->vni); |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 506 | if (!dpid) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 507 | { |
| 508 | clib_warning ("vni %d not associated to a bridge domain !", a->vni); |
| 509 | return; |
| 510 | } |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 511 | a->bd_id = dpid[0]; |
| 512 | } |
| 513 | |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 514 | /* find best locator pair that 1) verifies LISP policy 2) are connected */ |
Florin Coras | ba888e4 | 2017-01-24 11:38:18 -0800 | [diff] [blame] | 515 | rv = get_locator_pairs (lcm, lcl_map, rmt_map, &a->locator_pairs); |
| 516 | |
| 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)) |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 520 | { |
Florin Coras | ba888e4 | 2017-01-24 11:38:18 -0800 | [diff] [blame] | 521 | rmt_map = lisp_get_petr_mapping (lcm); |
| 522 | rv = get_locator_pairs (lcm, lcl_map, rmt_map, &a->locator_pairs); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 523 | } |
| 524 | |
Florin Coras | ba888e4 | 2017-01-24 11:38:18 -0800 | [diff] [blame] | 525 | /* negative entry */ |
| 526 | if (rv == 0) |
| 527 | { |
| 528 | a->is_negative = 1; |
| 529 | a->action = rmt_map->action; |
| 530 | } |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 531 | |
Filip Tehlar | 2151191 | 2017-04-07 10:41:42 +0200 | [diff] [blame] | 532 | rv = vnet_lisp_gpe_add_del_fwd_entry (a, &sw_if_index); |
| 533 | if (rv) |
| 534 | { |
| 535 | if (a->locator_pairs) |
| 536 | vec_free (a->locator_pairs); |
| 537 | return; |
| 538 | } |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 539 | |
Filip Tehlar | 2151191 | 2017-04-07 10:41:42 +0200 | [diff] [blame] | 540 | /* add tunnel to fwd entry table */ |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 541 | pool_get (lcm->fwd_entry_pool, fe); |
Filip Tehlar | 2151191 | 2017-04-07 10:41:42 +0200 | [diff] [blame] | 542 | vnet_lisp_gpe_add_fwd_counters (a, fe - lcm->fwd_entry_pool); |
| 543 | |
Florin Coras | bb5c22f | 2016-08-02 02:31:03 +0200 | [diff] [blame] | 544 | fe->locator_pairs = a->locator_pairs; |
Filip Tehlar | 2fdaece | 2016-09-28 14:27:59 +0200 | [diff] [blame] | 545 | gid_address_copy (&fe->reid, &a->rmt_eid); |
Filip Tehlar | b601f22 | 2017-01-02 10:22:56 +0100 | [diff] [blame] | 546 | |
| 547 | if (is_src_dst) |
| 548 | gid_address_copy (&fe->leid, &a->lcl_eid); |
| 549 | else |
Florin Coras | ba888e4 | 2017-01-24 11:38:18 -0800 | [diff] [blame] | 550 | gid_address_copy (&fe->leid, lcl_eid); |
Filip Tehlar | b601f22 | 2017-01-02 10:22:56 +0100 | [diff] [blame] | 551 | |
Filip Tehlar | 69a9b76 | 2016-09-23 10:00:52 +0200 | [diff] [blame] | 552 | fe->is_src_dst = is_src_dst; |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 553 | hash_set (lcm->fwd_entry_by_mapping_index, dst_map_index, |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 554 | fe - lcm->fwd_entry_pool); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 555 | } |
| 556 | |
Filip Tehlar | ce1aae4 | 2017-01-04 10:42:25 +0100 | [diff] [blame] | 557 | typedef struct |
| 558 | { |
| 559 | u32 si; |
| 560 | u32 di; |
| 561 | } fwd_entry_mt_arg_t; |
| 562 | |
| 563 | static void * |
| 564 | dp_add_fwd_entry_thread_fn (void *arg) |
| 565 | { |
| 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); |
| 569 | return 0; |
| 570 | } |
| 571 | |
| 572 | static int |
| 573 | dp_add_fwd_entry_from_mt (u32 si, u32 di) |
| 574 | { |
| 575 | fwd_entry_mt_arg_t a; |
| 576 | |
| 577 | memset (&a, 0, sizeof (a)); |
| 578 | a.si = si; |
| 579 | a.di = di; |
| 580 | |
| 581 | vl_api_rpc_call_main_thread (dp_add_fwd_entry_thread_fn, |
| 582 | (u8 *) & a, sizeof (a)); |
| 583 | return 0; |
| 584 | } |
| 585 | |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 586 | /** |
Filip Tehlar | 69a9b76 | 2016-09-23 10:00:52 +0200 | [diff] [blame] | 587 | * Returns vector of adjacencies. |
| 588 | * |
| 589 | * The caller must free the vector returned by this function. |
| 590 | * |
| 591 | * @param vni virtual network identifier |
| 592 | * @return vector of adjacencies |
| 593 | */ |
| 594 | lisp_adjacency_t * |
| 595 | vnet_lisp_adjacencies_get_by_vni (u32 vni) |
| 596 | { |
| 597 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 598 | fwd_entry_t *fwd; |
| 599 | lisp_adjacency_t *adjs = 0, adj; |
| 600 | |
| 601 | /* *INDENT-OFF* */ |
| 602 | pool_foreach(fwd, lcm->fwd_entry_pool, |
| 603 | ({ |
| 604 | if (gid_address_vni (&fwd->reid) != vni) |
| 605 | continue; |
| 606 | |
| 607 | gid_address_copy (&adj.reid, &fwd->reid); |
| 608 | gid_address_copy (&adj.leid, &fwd->leid); |
| 609 | vec_add1 (adjs, adj); |
| 610 | })); |
| 611 | /* *INDENT-ON* */ |
| 612 | |
| 613 | return adjs; |
| 614 | } |
| 615 | |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 616 | static lisp_msmr_t * |
| 617 | get_map_server (ip_address_t * a) |
| 618 | { |
| 619 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 620 | lisp_msmr_t *m; |
| 621 | |
| 622 | vec_foreach (m, lcm->map_servers) |
| 623 | { |
| 624 | if (!ip_address_cmp (&m->address, a)) |
| 625 | { |
| 626 | return m; |
| 627 | } |
| 628 | } |
| 629 | return 0; |
| 630 | } |
| 631 | |
| 632 | static lisp_msmr_t * |
| 633 | get_map_resolver (ip_address_t * a) |
| 634 | { |
| 635 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 636 | lisp_msmr_t *m; |
| 637 | |
| 638 | vec_foreach (m, lcm->map_resolvers) |
| 639 | { |
| 640 | if (!ip_address_cmp (&m->address, a)) |
| 641 | { |
| 642 | return m; |
| 643 | } |
| 644 | } |
| 645 | return 0; |
| 646 | } |
| 647 | |
| 648 | int |
| 649 | vnet_lisp_add_del_map_server (ip_address_t * addr, u8 is_add) |
| 650 | { |
| 651 | u32 i; |
| 652 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 653 | lisp_msmr_t _ms, *ms = &_ms; |
| 654 | |
| 655 | if (vnet_lisp_enable_disable_status () == 0) |
| 656 | { |
| 657 | clib_warning ("LISP is disabled!"); |
| 658 | return VNET_API_ERROR_LISP_DISABLED; |
| 659 | } |
| 660 | |
| 661 | if (is_add) |
| 662 | { |
| 663 | if (get_map_server (addr)) |
| 664 | { |
| 665 | clib_warning ("map-server %U already exists!", format_ip_address, |
| 666 | addr); |
| 667 | return -1; |
| 668 | } |
| 669 | |
| 670 | memset (ms, 0, sizeof (*ms)); |
| 671 | ip_address_copy (&ms->address, addr); |
| 672 | vec_add1 (lcm->map_servers, ms[0]); |
| 673 | } |
| 674 | else |
| 675 | { |
| 676 | for (i = 0; i < vec_len (lcm->map_servers); i++) |
| 677 | { |
| 678 | ms = vec_elt_at_index (lcm->map_servers, i); |
| 679 | if (!ip_address_cmp (&ms->address, addr)) |
| 680 | { |
| 681 | vec_del1 (lcm->map_servers, i); |
| 682 | break; |
| 683 | } |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | return 0; |
| 688 | } |
| 689 | |
Filip Tehlar | 69a9b76 | 2016-09-23 10:00:52 +0200 | [diff] [blame] | 690 | /** |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 691 | * Add/remove mapping to/from map-cache. Overwriting not allowed. |
| 692 | */ |
| 693 | int |
| 694 | vnet_lisp_map_cache_add_del (vnet_lisp_add_del_mapping_args_t * a, |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 695 | u32 * map_index_result) |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 696 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 697 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 698 | u32 mi, *map_indexp, map_index, i; |
| 699 | mapping_t *m, *old_map; |
| 700 | u32 **eid_indexes; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 701 | |
Filip Tehlar | ef2a5bf | 2017-05-30 07:14:46 +0200 | [diff] [blame] | 702 | if (gid_address_type (&a->eid) == GID_ADDR_NSH) |
| 703 | { |
| 704 | if (gid_address_vni (&a->eid) != 0) |
| 705 | { |
| 706 | clib_warning ("Supported only default VNI for NSH!"); |
| 707 | return VNET_API_ERROR_INVALID_ARGUMENT; |
| 708 | } |
| 709 | if (gid_address_nsh_spi (&a->eid) > MAX_VALUE_U24) |
| 710 | { |
| 711 | clib_warning ("SPI is greater than 24bit!"); |
| 712 | return VNET_API_ERROR_INVALID_ARGUMENT; |
| 713 | } |
| 714 | } |
| 715 | |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 716 | mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &a->eid); |
Filip Tehlar | 53f09e3 | 2016-05-19 14:25:44 +0200 | [diff] [blame] | 717 | old_map = mi != ~0 ? pool_elt_at_index (lcm->mapping_pool, mi) : 0; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 718 | if (a->is_add) |
| 719 | { |
| 720 | /* TODO check if overwriting and take appropriate actions */ |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 721 | if (mi != GID_LOOKUP_MISS && !gid_address_cmp (&old_map->eid, &a->eid)) |
| 722 | { |
| 723 | clib_warning ("eid %U found in the eid-table", format_gid_address, |
| 724 | &a->eid); |
| 725 | return VNET_API_ERROR_VALUE_EXIST; |
| 726 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 727 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 728 | pool_get (lcm->mapping_pool, m); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 729 | gid_address_copy (&m->eid, &a->eid); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 730 | m->locator_set_index = a->locator_set_index; |
| 731 | m->ttl = a->ttl; |
Filip Tehlar | 53f09e3 | 2016-05-19 14:25:44 +0200 | [diff] [blame] | 732 | m->action = a->action; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 733 | m->local = a->local; |
Filip Tehlar | 3cd9e73 | 2016-08-23 10:52:44 +0200 | [diff] [blame] | 734 | m->is_static = a->is_static; |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 735 | m->key = vec_dup (a->key); |
| 736 | m->key_id = a->key_id; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 737 | |
| 738 | map_index = m - lcm->mapping_pool; |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 739 | gid_dictionary_add_del (&lcm->mapping_index_by_gid, &a->eid, map_index, |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 740 | 1); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 741 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 742 | if (pool_is_free_index (lcm->locator_set_pool, a->locator_set_index)) |
| 743 | { |
| 744 | clib_warning ("Locator set with index %d doesn't exist", |
| 745 | a->locator_set_index); |
| 746 | return VNET_API_ERROR_INVALID_VALUE; |
| 747 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 748 | |
| 749 | /* add eid to list of eids supported by locator-set */ |
| 750 | vec_validate (lcm->locator_set_to_eids, a->locator_set_index); |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 751 | eid_indexes = vec_elt_at_index (lcm->locator_set_to_eids, |
| 752 | a->locator_set_index); |
| 753 | vec_add1 (eid_indexes[0], map_index); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 754 | |
| 755 | if (a->local) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 756 | { |
| 757 | /* mark as local */ |
| 758 | vec_add1 (lcm->local_mappings_indexes, map_index); |
| 759 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 760 | map_index_result[0] = map_index; |
| 761 | } |
| 762 | else |
| 763 | { |
Florin Coras | 577c355 | 2016-04-21 00:45:40 +0200 | [diff] [blame] | 764 | if (mi == GID_LOOKUP_MISS) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 765 | { |
| 766 | clib_warning ("eid %U not found in the eid-table", |
| 767 | format_gid_address, &a->eid); |
| 768 | return VNET_API_ERROR_INVALID_VALUE; |
| 769 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 770 | |
| 771 | /* clear locator-set to eids binding */ |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 772 | eid_indexes = vec_elt_at_index (lcm->locator_set_to_eids, |
| 773 | a->locator_set_index); |
| 774 | for (i = 0; i < vec_len (eid_indexes[0]); i++) |
| 775 | { |
| 776 | map_indexp = vec_elt_at_index (eid_indexes[0], i); |
| 777 | if (map_indexp[0] == mi) |
| 778 | break; |
| 779 | } |
| 780 | vec_del1 (eid_indexes[0], i); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 781 | |
| 782 | /* remove local mark if needed */ |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 783 | m = pool_elt_at_index (lcm->mapping_pool, mi); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 784 | if (m->local) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 785 | { |
| 786 | u32 k, *lm_indexp; |
| 787 | for (k = 0; k < vec_len (lcm->local_mappings_indexes); k++) |
| 788 | { |
| 789 | lm_indexp = vec_elt_at_index (lcm->local_mappings_indexes, k); |
| 790 | if (lm_indexp[0] == mi) |
| 791 | break; |
| 792 | } |
| 793 | vec_del1 (lcm->local_mappings_indexes, k); |
| 794 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 795 | |
| 796 | /* remove mapping from dictionary */ |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 797 | gid_dictionary_add_del (&lcm->mapping_index_by_gid, &a->eid, 0, 0); |
Filip Tehlar | 324112f | 2016-06-02 16:07:38 +0200 | [diff] [blame] | 798 | gid_address_free (&m->eid); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 799 | pool_put_index (lcm->mapping_pool, mi); |
| 800 | } |
| 801 | |
| 802 | return 0; |
| 803 | } |
| 804 | |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 805 | /** |
| 806 | * Add/update/delete mapping to/in/from map-cache. |
| 807 | */ |
Florin Coras | 577c355 | 2016-04-21 00:45:40 +0200 | [diff] [blame] | 808 | int |
| 809 | vnet_lisp_add_del_local_mapping (vnet_lisp_add_del_mapping_args_t * a, |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 810 | u32 * map_index_result) |
Florin Coras | 577c355 | 2016-04-21 00:45:40 +0200 | [diff] [blame] | 811 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 812 | uword *dp_table = 0; |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 813 | u32 vni; |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 814 | u8 type; |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 815 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 816 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
Florin Coras | 577c355 | 2016-04-21 00:45:40 +0200 | [diff] [blame] | 817 | |
Andrej Kozemcak | 8ebb2a1 | 2016-06-07 12:25:20 +0200 | [diff] [blame] | 818 | if (vnet_lisp_enable_disable_status () == 0) |
| 819 | { |
| 820 | clib_warning ("LISP is disabled!"); |
| 821 | return VNET_API_ERROR_LISP_DISABLED; |
| 822 | } |
| 823 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 824 | vni = gid_address_vni (&a->eid); |
| 825 | type = gid_address_type (&a->eid); |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 826 | if (GID_ADDR_IP_PREFIX == type) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 827 | dp_table = hash_get (lcm->table_id_by_vni, vni); |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 828 | else if (GID_ADDR_MAC == type) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 829 | dp_table = hash_get (lcm->bd_id_by_vni, vni); |
Florin Coras | 577c355 | 2016-04-21 00:45:40 +0200 | [diff] [blame] | 830 | |
Filip Tehlar | ef2a5bf | 2017-05-30 07:14:46 +0200 | [diff] [blame] | 831 | if (!dp_table && GID_ADDR_NSH != type) |
Florin Coras | 577c355 | 2016-04-21 00:45:40 +0200 | [diff] [blame] | 832 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 833 | clib_warning ("vni %d not associated to a %s!", vni, |
| 834 | GID_ADDR_IP_PREFIX == type ? "vrf" : "bd"); |
Florin Coras | 577c355 | 2016-04-21 00:45:40 +0200 | [diff] [blame] | 835 | return VNET_API_ERROR_INVALID_VALUE; |
| 836 | } |
| 837 | |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 838 | /* store/remove mapping from map-cache */ |
| 839 | return vnet_lisp_map_cache_add_del (a, map_index_result); |
Florin Coras | 577c355 | 2016-04-21 00:45:40 +0200 | [diff] [blame] | 840 | } |
| 841 | |
Filip Tehlar | d5a65db | 2017-05-17 17:21:10 +0200 | [diff] [blame] | 842 | static void |
| 843 | add_l2_arp_bd (BVT (clib_bihash_kv) * kvp, void *arg) |
| 844 | { |
| 845 | u32 **ht = arg; |
| 846 | u32 bd = (u32) kvp->key[0]; |
| 847 | hash_set (ht[0], bd, 0); |
| 848 | } |
| 849 | |
| 850 | u32 * |
| 851 | vnet_lisp_l2_arp_bds_get (void) |
| 852 | { |
| 853 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 854 | u32 *bds = 0; |
| 855 | |
| 856 | gid_dict_foreach_l2_arp_entry (&lcm->mapping_index_by_gid, |
| 857 | add_l2_arp_bd, &bds); |
| 858 | return bds; |
| 859 | } |
| 860 | |
| 861 | typedef struct |
| 862 | { |
| 863 | void *vector; |
| 864 | u32 bd; |
| 865 | } lisp_add_l2_arp_args_t; |
| 866 | |
| 867 | static void |
| 868 | add_l2_arp_entry (BVT (clib_bihash_kv) * kvp, void *arg) |
| 869 | { |
| 870 | lisp_add_l2_arp_args_t *a = arg; |
| 871 | lisp_api_l2_arp_entry_t **vector = a->vector, e; |
| 872 | |
| 873 | if ((u32) kvp->key[0] == a->bd) |
| 874 | { |
| 875 | mac_copy (e.mac, (void *) &kvp->value); |
| 876 | e.ip4 = (u32) kvp->key[1]; |
| 877 | vec_add1 (vector[0], e); |
| 878 | } |
| 879 | } |
| 880 | |
| 881 | lisp_api_l2_arp_entry_t * |
| 882 | vnet_lisp_l2_arp_entries_get_by_bd (u32 bd) |
| 883 | { |
| 884 | lisp_api_l2_arp_entry_t *entries = 0; |
| 885 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 886 | lisp_add_l2_arp_args_t a; |
| 887 | |
| 888 | a.vector = &entries; |
| 889 | a.bd = bd; |
| 890 | |
| 891 | gid_dict_foreach_l2_arp_entry (&lcm->mapping_index_by_gid, |
| 892 | add_l2_arp_entry, &a); |
| 893 | return entries; |
| 894 | } |
| 895 | |
| 896 | int |
| 897 | vnet_lisp_add_del_l2_arp_entry (gid_address_t * key, u8 * mac, u8 is_add) |
| 898 | { |
| 899 | if (vnet_lisp_enable_disable_status () == 0) |
| 900 | { |
| 901 | clib_warning ("LISP is disabled!"); |
| 902 | return VNET_API_ERROR_LISP_DISABLED; |
| 903 | } |
| 904 | |
| 905 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 906 | int rc = 0; |
| 907 | |
| 908 | u64 res = gid_dictionary_lookup (&lcm->mapping_index_by_gid, key); |
| 909 | if (is_add) |
| 910 | { |
| 911 | if (res != GID_LOOKUP_MISS_L2) |
| 912 | { |
| 913 | clib_warning ("Entry %U exists in DB!", format_gid_address, key); |
| 914 | return VNET_API_ERROR_ENTRY_ALREADY_EXISTS; |
| 915 | } |
| 916 | u64 val = mac_to_u64 (mac); |
| 917 | gid_dictionary_add_del (&lcm->mapping_index_by_gid, key, val, |
| 918 | 1 /* is_add */ ); |
| 919 | } |
| 920 | else |
| 921 | { |
| 922 | if (res == GID_LOOKUP_MISS_L2) |
| 923 | { |
| 924 | clib_warning ("ONE ARP entry %U not found - cannot delete!", |
| 925 | format_gid_address, key); |
| 926 | return -1; |
| 927 | } |
| 928 | gid_dictionary_add_del (&lcm->mapping_index_by_gid, key, 0, |
| 929 | 0 /* is_add */ ); |
| 930 | } |
| 931 | |
| 932 | return rc; |
| 933 | } |
| 934 | |
Filip Tehlar | 324112f | 2016-06-02 16:07:38 +0200 | [diff] [blame] | 935 | int |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 936 | vnet_lisp_eid_table_map (u32 vni, u32 dp_id, u8 is_l2, u8 is_add) |
Filip Tehlar | 324112f | 2016-06-02 16:07:38 +0200 | [diff] [blame] | 937 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 938 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 939 | uword *dp_idp, *vnip, **dp_table_by_vni, **vni_by_dp_table; |
Filip Tehlar | 324112f | 2016-06-02 16:07:38 +0200 | [diff] [blame] | 940 | |
| 941 | if (vnet_lisp_enable_disable_status () == 0) |
| 942 | { |
| 943 | clib_warning ("LISP is disabled!"); |
Filip Tehlar | d5a65db | 2017-05-17 17:21:10 +0200 | [diff] [blame] | 944 | return VNET_API_ERROR_LISP_DISABLED; |
Filip Tehlar | 324112f | 2016-06-02 16:07:38 +0200 | [diff] [blame] | 945 | } |
| 946 | |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 947 | dp_table_by_vni = is_l2 ? &lcm->bd_id_by_vni : &lcm->table_id_by_vni; |
| 948 | vni_by_dp_table = is_l2 ? &lcm->vni_by_bd_id : &lcm->vni_by_table_id; |
| 949 | |
| 950 | if (!is_l2 && (vni == 0 || dp_id == 0)) |
Filip Tehlar | 324112f | 2016-06-02 16:07:38 +0200 | [diff] [blame] | 951 | { |
| 952 | clib_warning ("can't add/del default vni-vrf mapping!"); |
| 953 | return -1; |
| 954 | } |
| 955 | |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 956 | dp_idp = hash_get (dp_table_by_vni[0], vni); |
| 957 | vnip = hash_get (vni_by_dp_table[0], dp_id); |
Filip Tehlar | 324112f | 2016-06-02 16:07:38 +0200 | [diff] [blame] | 958 | |
| 959 | if (is_add) |
| 960 | { |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 961 | if (dp_idp || vnip) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 962 | { |
| 963 | clib_warning ("vni %d or vrf %d already used in vrf/vni " |
| 964 | "mapping!", vni, dp_id); |
| 965 | return -1; |
| 966 | } |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 967 | hash_set (dp_table_by_vni[0], vni, dp_id); |
| 968 | hash_set (vni_by_dp_table[0], dp_id, vni); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 969 | |
| 970 | /* create dp iface */ |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 971 | dp_add_del_iface (lcm, vni, is_l2, 1); |
Filip Tehlar | 324112f | 2016-06-02 16:07:38 +0200 | [diff] [blame] | 972 | } |
| 973 | else |
| 974 | { |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 975 | if (!dp_idp || !vnip) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 976 | { |
| 977 | clib_warning ("vni %d or vrf %d not used in any vrf/vni! " |
| 978 | "mapping!", vni, dp_id); |
| 979 | return -1; |
| 980 | } |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 981 | /* remove dp iface */ |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 982 | dp_add_del_iface (lcm, vni, is_l2, 0); |
Filip Tehlar | fc56841 | 2017-04-05 10:06:03 +0200 | [diff] [blame] | 983 | |
| 984 | hash_unset (dp_table_by_vni[0], vni); |
| 985 | hash_unset (vni_by_dp_table[0], dp_id); |
Filip Tehlar | 324112f | 2016-06-02 16:07:38 +0200 | [diff] [blame] | 986 | } |
| 987 | return 0; |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 988 | |
Filip Tehlar | 324112f | 2016-06-02 16:07:38 +0200 | [diff] [blame] | 989 | } |
| 990 | |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 991 | /* return 0 if the two locator sets are identical 1 otherwise */ |
| 992 | static u8 |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 993 | compare_locators (lisp_cp_main_t * lcm, u32 * old_ls_indexes, |
| 994 | locator_t * new_locators) |
Filip Tehlar | 53f09e3 | 2016-05-19 14:25:44 +0200 | [diff] [blame] | 995 | { |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 996 | u32 i, old_li; |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 997 | locator_t *old_loc, *new_loc; |
Filip Tehlar | 53f09e3 | 2016-05-19 14:25:44 +0200 | [diff] [blame] | 998 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 999 | if (vec_len (old_ls_indexes) != vec_len (new_locators)) |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1000 | return 1; |
Filip Tehlar | 53f09e3 | 2016-05-19 14:25:44 +0200 | [diff] [blame] | 1001 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1002 | for (i = 0; i < vec_len (new_locators); i++) |
Filip Tehlar | 53f09e3 | 2016-05-19 14:25:44 +0200 | [diff] [blame] | 1003 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1004 | old_li = vec_elt (old_ls_indexes, i); |
| 1005 | old_loc = pool_elt_at_index (lcm->locator_pool, old_li); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1006 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1007 | new_loc = vec_elt_at_index (new_locators, i); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1008 | |
| 1009 | if (locator_cmp (old_loc, new_loc)) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1010 | return 1; |
Filip Tehlar | 53f09e3 | 2016-05-19 14:25:44 +0200 | [diff] [blame] | 1011 | } |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1012 | return 0; |
Filip Tehlar | 53f09e3 | 2016-05-19 14:25:44 +0200 | [diff] [blame] | 1013 | } |
| 1014 | |
Filip Tehlar | d5fcc46 | 2016-10-17 16:20:18 +0200 | [diff] [blame] | 1015 | typedef struct |
| 1016 | { |
| 1017 | u8 is_negative; |
| 1018 | void *lcm; |
| 1019 | gid_address_t *eids_to_be_deleted; |
| 1020 | } remove_mapping_args_t; |
| 1021 | |
| 1022 | /** |
| 1023 | * Callback invoked when a sub-prefix is found |
| 1024 | */ |
| 1025 | static void |
| 1026 | remove_mapping_if_needed (u32 mi, void *arg) |
| 1027 | { |
| 1028 | u8 delete = 0; |
| 1029 | remove_mapping_args_t *a = arg; |
| 1030 | lisp_cp_main_t *lcm = a->lcm; |
| 1031 | mapping_t *m; |
| 1032 | locator_set_t *ls; |
| 1033 | |
| 1034 | m = pool_elt_at_index (lcm->mapping_pool, mi); |
| 1035 | if (!m) |
| 1036 | return; |
| 1037 | |
| 1038 | ls = pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index); |
| 1039 | |
| 1040 | if (a->is_negative) |
| 1041 | { |
| 1042 | if (0 != vec_len (ls->locator_indices)) |
| 1043 | delete = 1; |
| 1044 | } |
| 1045 | else |
| 1046 | { |
| 1047 | if (0 == vec_len (ls->locator_indices)) |
| 1048 | delete = 1; |
| 1049 | } |
| 1050 | |
| 1051 | if (delete) |
| 1052 | vec_add1 (a->eids_to_be_deleted, m->eid); |
| 1053 | } |
| 1054 | |
| 1055 | /** |
| 1056 | * This function searches map cache and looks for IP prefixes that are subset |
| 1057 | * of the provided one. If such prefix is found depending on 'is_negative' |
| 1058 | * it does follows: |
| 1059 | * |
| 1060 | * 1) if is_negative is true and found prefix points to positive mapping, |
| 1061 | * then the mapping is removed |
| 1062 | * 2) if is_negative is false and found prefix points to negative mapping, |
| 1063 | * then the mapping is removed |
| 1064 | */ |
| 1065 | static void |
| 1066 | remove_overlapping_sub_prefixes (lisp_cp_main_t * lcm, gid_address_t * eid, |
| 1067 | u8 is_negative) |
| 1068 | { |
| 1069 | gid_address_t *e; |
| 1070 | remove_mapping_args_t a; |
Florin Coras | f3dc11a | 2017-01-24 03:13:43 -0800 | [diff] [blame] | 1071 | |
Filip Tehlar | d5fcc46 | 2016-10-17 16:20:18 +0200 | [diff] [blame] | 1072 | memset (&a, 0, sizeof (a)); |
| 1073 | |
| 1074 | /* do this only in src/dst mode ... */ |
| 1075 | if (MR_MODE_SRC_DST != lcm->map_request_mode) |
| 1076 | return; |
| 1077 | |
| 1078 | /* ... and only for IP prefix */ |
| 1079 | if (GID_ADDR_SRC_DST != gid_address_type (eid) |
| 1080 | || (FID_ADDR_IP_PREF != gid_address_sd_dst_type (eid))) |
| 1081 | return; |
| 1082 | |
| 1083 | a.is_negative = is_negative; |
| 1084 | a.lcm = lcm; |
| 1085 | |
| 1086 | gid_dict_foreach_subprefix (&lcm->mapping_index_by_gid, eid, |
| 1087 | remove_mapping_if_needed, &a); |
| 1088 | |
| 1089 | vec_foreach (e, a.eids_to_be_deleted) |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 1090 | { |
Florin Coras | f3dc11a | 2017-01-24 03:13:43 -0800 | [diff] [blame] | 1091 | vnet_lisp_add_del_adjacency_args_t _adj_args, *adj_args = &_adj_args; |
| 1092 | |
| 1093 | memset (adj_args, 0, sizeof (adj_args[0])); |
| 1094 | gid_address_copy (&adj_args->reid, e); |
| 1095 | adj_args->is_add = 0; |
| 1096 | if (vnet_lisp_add_del_adjacency (adj_args)) |
| 1097 | clib_warning ("failed to del adjacency!"); |
| 1098 | |
Filip Tehlar | d5fcc46 | 2016-10-17 16:20:18 +0200 | [diff] [blame] | 1099 | vnet_lisp_add_del_mapping (e, 0, 0, 0, 0, 0 /* is add */ , 0, 0); |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 1100 | } |
Filip Tehlar | d5fcc46 | 2016-10-17 16:20:18 +0200 | [diff] [blame] | 1101 | |
| 1102 | vec_free (a.eids_to_be_deleted); |
| 1103 | } |
| 1104 | |
Filip Tehlar | 9677a94 | 2016-11-28 10:23:31 +0100 | [diff] [blame] | 1105 | static void |
| 1106 | mapping_delete_timer (lisp_cp_main_t * lcm, u32 mi) |
| 1107 | { |
| 1108 | timing_wheel_delete (&lcm->wheel, mi); |
| 1109 | } |
| 1110 | |
Filip Tehlar | a6bce49 | 2017-02-03 10:17:49 +0100 | [diff] [blame] | 1111 | static int |
| 1112 | is_local_ip (lisp_cp_main_t * lcm, ip_address_t * addr) |
| 1113 | { |
| 1114 | fib_node_index_t fei; |
| 1115 | fib_prefix_t prefix; |
| 1116 | fib_entry_flag_t flags; |
| 1117 | |
| 1118 | ip_address_to_fib_prefix (addr, &prefix); |
| 1119 | |
| 1120 | fei = fib_table_lookup (0, &prefix); |
| 1121 | flags = fib_entry_get_flags (fei); |
| 1122 | return (FIB_ENTRY_FLAG_LOCAL & flags); |
| 1123 | } |
| 1124 | |
Filip Tehlar | 195bcee | 2016-05-13 17:37:35 +0200 | [diff] [blame] | 1125 | /** |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1126 | * Adds/removes/updates mapping. Does not program forwarding. |
Filip Tehlar | 195bcee | 2016-05-13 17:37:35 +0200 | [diff] [blame] | 1127 | * |
Florin Coras | 71893ac | 2016-07-10 20:09:32 +0200 | [diff] [blame] | 1128 | * @param eid end-host identifier |
Filip Tehlar | 195bcee | 2016-05-13 17:37:35 +0200 | [diff] [blame] | 1129 | * @param rlocs vector of remote locators |
| 1130 | * @param action action for negative map-reply |
| 1131 | * @param is_add add mapping if non-zero, delete otherwise |
Florin Coras | 71893ac | 2016-07-10 20:09:32 +0200 | [diff] [blame] | 1132 | * @param res_map_index the map-index that was created/updated/removed. It is |
| 1133 | * set to ~0 if no action is taken. |
Filip Tehlar | 3cd9e73 | 2016-08-23 10:52:44 +0200 | [diff] [blame] | 1134 | * @param is_static used for distinguishing between statically learned |
| 1135 | remote mappings and mappings obtained from MR |
Filip Tehlar | 195bcee | 2016-05-13 17:37:35 +0200 | [diff] [blame] | 1136 | * @return return code |
| 1137 | */ |
| 1138 | int |
Florin Coras | 71893ac | 2016-07-10 20:09:32 +0200 | [diff] [blame] | 1139 | vnet_lisp_add_del_mapping (gid_address_t * eid, locator_t * rlocs, u8 action, |
Filip Tehlar | 3cd9e73 | 2016-08-23 10:52:44 +0200 | [diff] [blame] | 1140 | u8 authoritative, u32 ttl, u8 is_add, u8 is_static, |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1141 | u32 * res_map_index) |
Filip Tehlar | 195bcee | 2016-05-13 17:37:35 +0200 | [diff] [blame] | 1142 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1143 | vnet_lisp_add_del_mapping_args_t _m_args, *m_args = &_m_args; |
| 1144 | vnet_lisp_add_del_locator_set_args_t _ls_args, *ls_args = &_ls_args; |
| 1145 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1146 | u32 mi, ls_index = 0, dst_map_index; |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1147 | mapping_t *old_map; |
Filip Tehlar | a6bce49 | 2017-02-03 10:17:49 +0100 | [diff] [blame] | 1148 | locator_t *loc; |
Filip Tehlar | 195bcee | 2016-05-13 17:37:35 +0200 | [diff] [blame] | 1149 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1150 | if (vnet_lisp_enable_disable_status () == 0) |
Andrej Kozemcak | 8ebb2a1 | 2016-06-07 12:25:20 +0200 | [diff] [blame] | 1151 | { |
| 1152 | clib_warning ("LISP is disabled!"); |
| 1153 | return VNET_API_ERROR_LISP_DISABLED; |
| 1154 | } |
| 1155 | |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1156 | if (res_map_index) |
| 1157 | res_map_index[0] = ~0; |
Filip Tehlar | 58f886a | 2016-05-30 15:57:40 +0200 | [diff] [blame] | 1158 | |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1159 | memset (m_args, 0, sizeof (m_args[0])); |
| 1160 | memset (ls_args, 0, sizeof (ls_args[0])); |
Filip Tehlar | 195bcee | 2016-05-13 17:37:35 +0200 | [diff] [blame] | 1161 | |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1162 | ls_args->locators = rlocs; |
Filip Tehlar | 195bcee | 2016-05-13 17:37:35 +0200 | [diff] [blame] | 1163 | |
Florin Coras | 71893ac | 2016-07-10 20:09:32 +0200 | [diff] [blame] | 1164 | mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid); |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1165 | old_map = ((u32) ~ 0 != mi) ? pool_elt_at_index (lcm->mapping_pool, mi) : 0; |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1166 | |
| 1167 | if (is_add) |
Filip Tehlar | 195bcee | 2016-05-13 17:37:35 +0200 | [diff] [blame] | 1168 | { |
Filip Tehlar | 272c69e | 2017-02-15 16:40:35 +0100 | [diff] [blame] | 1169 | /* check if none of the locators match localy configured address */ |
| 1170 | vec_foreach (loc, rlocs) |
| 1171 | { |
| 1172 | ip_prefix_t *p = &gid_address_ippref (&loc->address); |
| 1173 | if (is_local_ip (lcm, &ip_prefix_addr (p))) |
| 1174 | { |
| 1175 | clib_warning ("RLOC %U matches a local address!", |
| 1176 | format_gid_address, &loc->address); |
| 1177 | return VNET_API_ERROR_LISP_RLOC_LOCAL; |
| 1178 | } |
| 1179 | } |
| 1180 | |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1181 | /* overwrite: if mapping already exists, decide if locators should be |
| 1182 | * updated and be done */ |
Florin Coras | 71893ac | 2016-07-10 20:09:32 +0200 | [diff] [blame] | 1183 | if (old_map && gid_address_cmp (&old_map->eid, eid) == 0) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1184 | { |
Filip Tehlar | 3cd9e73 | 2016-08-23 10:52:44 +0200 | [diff] [blame] | 1185 | if (!is_static && (old_map->is_static || old_map->local)) |
| 1186 | { |
| 1187 | /* do not overwrite local or static remote mappings */ |
| 1188 | clib_warning ("mapping %U rejected due to collision with local " |
| 1189 | "or static remote mapping!", format_gid_address, |
Filip Tehlar | d5fcc46 | 2016-10-17 16:20:18 +0200 | [diff] [blame] | 1190 | eid); |
Filip Tehlar | 3cd9e73 | 2016-08-23 10:52:44 +0200 | [diff] [blame] | 1191 | return 0; |
| 1192 | } |
| 1193 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1194 | locator_set_t *old_ls; |
Filip Tehlar | 195bcee | 2016-05-13 17:37:35 +0200 | [diff] [blame] | 1195 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1196 | /* update mapping attributes */ |
| 1197 | old_map->action = action; |
| 1198 | old_map->authoritative = authoritative; |
| 1199 | old_map->ttl = ttl; |
Filip Tehlar | 195bcee | 2016-05-13 17:37:35 +0200 | [diff] [blame] | 1200 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1201 | old_ls = pool_elt_at_index (lcm->locator_set_pool, |
| 1202 | old_map->locator_set_index); |
| 1203 | if (compare_locators (lcm, old_ls->locator_indices, |
| 1204 | ls_args->locators)) |
| 1205 | { |
| 1206 | /* set locator-set index to overwrite */ |
| 1207 | ls_args->is_add = 1; |
| 1208 | ls_args->index = old_map->locator_set_index; |
| 1209 | vnet_lisp_add_del_locator_set (ls_args, 0); |
| 1210 | if (res_map_index) |
| 1211 | res_map_index[0] = mi; |
| 1212 | } |
| 1213 | } |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1214 | /* new mapping */ |
| 1215 | else |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1216 | { |
Filip Tehlar | d5fcc46 | 2016-10-17 16:20:18 +0200 | [diff] [blame] | 1217 | remove_overlapping_sub_prefixes (lcm, eid, 0 == ls_args->locators); |
| 1218 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1219 | ls_args->is_add = 1; |
| 1220 | ls_args->index = ~0; |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1221 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1222 | vnet_lisp_add_del_locator_set (ls_args, &ls_index); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1223 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1224 | /* add mapping */ |
| 1225 | gid_address_copy (&m_args->eid, eid); |
| 1226 | m_args->is_add = 1; |
| 1227 | m_args->action = action; |
| 1228 | m_args->locator_set_index = ls_index; |
Filip Tehlar | 3cd9e73 | 2016-08-23 10:52:44 +0200 | [diff] [blame] | 1229 | m_args->is_static = is_static; |
Filip Tehlar | 9677a94 | 2016-11-28 10:23:31 +0100 | [diff] [blame] | 1230 | m_args->ttl = ttl; |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1231 | vnet_lisp_map_cache_add_del (m_args, &dst_map_index); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1232 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1233 | if (res_map_index) |
| 1234 | res_map_index[0] = dst_map_index; |
| 1235 | } |
Filip Tehlar | 195bcee | 2016-05-13 17:37:35 +0200 | [diff] [blame] | 1236 | } |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1237 | else |
| 1238 | { |
Florin Coras | 71893ac | 2016-07-10 20:09:32 +0200 | [diff] [blame] | 1239 | if (old_map == 0 || gid_address_cmp (&old_map->eid, eid) != 0) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1240 | { |
| 1241 | clib_warning ("cannot delete mapping for eid %U", |
| 1242 | format_gid_address, eid); |
| 1243 | return -1; |
| 1244 | } |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1245 | |
| 1246 | m_args->is_add = 0; |
Florin Coras | 71893ac | 2016-07-10 20:09:32 +0200 | [diff] [blame] | 1247 | gid_address_copy (&m_args->eid, eid); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1248 | m_args->locator_set_index = old_map->locator_set_index; |
| 1249 | |
| 1250 | /* delete mapping associated from map-cache */ |
| 1251 | vnet_lisp_map_cache_add_del (m_args, 0); |
| 1252 | |
| 1253 | ls_args->is_add = 0; |
| 1254 | ls_args->index = old_map->locator_set_index; |
| 1255 | /* delete locator set */ |
| 1256 | vnet_lisp_add_del_locator_set (ls_args, 0); |
Filip Tehlar | b93222f | 2016-07-07 09:58:08 +0200 | [diff] [blame] | 1257 | |
Filip Tehlar | 9677a94 | 2016-11-28 10:23:31 +0100 | [diff] [blame] | 1258 | /* delete timer associated to the mapping if any */ |
| 1259 | if (old_map->timer_set) |
| 1260 | mapping_delete_timer (lcm, mi); |
| 1261 | |
Filip Tehlar | b93222f | 2016-07-07 09:58:08 +0200 | [diff] [blame] | 1262 | /* return old mapping index */ |
Andrej Kozemcak | 438109d | 2016-07-22 12:54:12 +0200 | [diff] [blame] | 1263 | if (res_map_index) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1264 | res_map_index[0] = mi; |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1265 | } |
| 1266 | |
Filip Tehlar | 195bcee | 2016-05-13 17:37:35 +0200 | [diff] [blame] | 1267 | /* success */ |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1268 | return 0; |
Filip Tehlar | 195bcee | 2016-05-13 17:37:35 +0200 | [diff] [blame] | 1269 | } |
| 1270 | |
Filip Tehlar | 58f886a | 2016-05-30 15:57:40 +0200 | [diff] [blame] | 1271 | int |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1272 | vnet_lisp_clear_all_remote_adjacencies (void) |
Filip Tehlar | 58f886a | 2016-05-30 15:57:40 +0200 | [diff] [blame] | 1273 | { |
| 1274 | int rv = 0; |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1275 | u32 mi, *map_indices = 0, *map_indexp; |
| 1276 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 1277 | vnet_lisp_add_del_mapping_args_t _dm_args, *dm_args = &_dm_args; |
| 1278 | vnet_lisp_add_del_locator_set_args_t _ls, *ls = &_ls; |
Filip Tehlar | 58f886a | 2016-05-30 15:57:40 +0200 | [diff] [blame] | 1279 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1280 | /* *INDENT-OFF* */ |
Filip Tehlar | 58f886a | 2016-05-30 15:57:40 +0200 | [diff] [blame] | 1281 | pool_foreach_index (mi, lcm->mapping_pool, |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1282 | ({ |
| 1283 | vec_add1 (map_indices, mi); |
| 1284 | })); |
| 1285 | /* *INDENT-ON* */ |
Filip Tehlar | 58f886a | 2016-05-30 15:57:40 +0200 | [diff] [blame] | 1286 | |
| 1287 | vec_foreach (map_indexp, map_indices) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1288 | { |
| 1289 | mapping_t *map = pool_elt_at_index (lcm->mapping_pool, map_indexp[0]); |
| 1290 | if (!map->local) |
| 1291 | { |
| 1292 | dp_del_fwd_entry (lcm, 0, map_indexp[0]); |
Filip Tehlar | 58f886a | 2016-05-30 15:57:40 +0200 | [diff] [blame] | 1293 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1294 | dm_args->is_add = 0; |
| 1295 | gid_address_copy (&dm_args->eid, &map->eid); |
| 1296 | dm_args->locator_set_index = map->locator_set_index; |
Filip Tehlar | 58f886a | 2016-05-30 15:57:40 +0200 | [diff] [blame] | 1297 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1298 | /* delete mapping associated to fwd entry */ |
| 1299 | vnet_lisp_map_cache_add_del (dm_args, 0); |
Filip Tehlar | 58f886a | 2016-05-30 15:57:40 +0200 | [diff] [blame] | 1300 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1301 | ls->is_add = 0; |
| 1302 | ls->local = 0; |
| 1303 | ls->index = map->locator_set_index; |
| 1304 | /* delete locator set */ |
| 1305 | rv = vnet_lisp_add_del_locator_set (ls, 0); |
| 1306 | if (rv != 0) |
| 1307 | goto cleanup; |
| 1308 | } |
| 1309 | } |
Filip Tehlar | 58f886a | 2016-05-30 15:57:40 +0200 | [diff] [blame] | 1310 | |
| 1311 | cleanup: |
| 1312 | if (map_indices) |
| 1313 | vec_free (map_indices); |
| 1314 | return rv; |
| 1315 | } |
| 1316 | |
Filip Tehlar | 195bcee | 2016-05-13 17:37:35 +0200 | [diff] [blame] | 1317 | /** |
Florin Coras | 71893ac | 2016-07-10 20:09:32 +0200 | [diff] [blame] | 1318 | * Adds adjacency or removes forwarding entry associated to remote mapping. |
| 1319 | * Note that adjacencies are not stored, they only result in forwarding entries |
| 1320 | * being created. |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1321 | */ |
Florin Coras | f3dc11a | 2017-01-24 03:13:43 -0800 | [diff] [blame] | 1322 | int |
| 1323 | vnet_lisp_add_del_adjacency (vnet_lisp_add_del_adjacency_args_t * a) |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1324 | { |
Florin Coras | f3dc11a | 2017-01-24 03:13:43 -0800 | [diff] [blame] | 1325 | lisp_cp_main_t *lcm = &lisp_control_main; |
Florin Coras | 71893ac | 2016-07-10 20:09:32 +0200 | [diff] [blame] | 1326 | u32 local_mi, remote_mi = ~0; |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1327 | |
| 1328 | if (vnet_lisp_enable_disable_status () == 0) |
| 1329 | { |
| 1330 | clib_warning ("LISP is disabled!"); |
| 1331 | return VNET_API_ERROR_LISP_DISABLED; |
| 1332 | } |
| 1333 | |
Filip Tehlar | 69a9b76 | 2016-09-23 10:00:52 +0200 | [diff] [blame] | 1334 | remote_mi = gid_dictionary_sd_lookup (&lcm->mapping_index_by_gid, |
Florin Coras | f3dc11a | 2017-01-24 03:13:43 -0800 | [diff] [blame] | 1335 | &a->reid, &a->leid); |
Florin Coras | 71893ac | 2016-07-10 20:09:32 +0200 | [diff] [blame] | 1336 | if (GID_LOOKUP_MISS == remote_mi) |
| 1337 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1338 | clib_warning ("Remote eid %U not found. Cannot add adjacency!", |
Florin Coras | f3dc11a | 2017-01-24 03:13:43 -0800 | [diff] [blame] | 1339 | format_gid_address, &a->reid); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1340 | |
Florin Coras | 71893ac | 2016-07-10 20:09:32 +0200 | [diff] [blame] | 1341 | return -1; |
| 1342 | } |
| 1343 | |
Florin Coras | f3dc11a | 2017-01-24 03:13:43 -0800 | [diff] [blame] | 1344 | if (a->is_add) |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1345 | { |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1346 | /* check if source eid has an associated mapping. If pitr mode is on, |
| 1347 | * just use the pitr's mapping */ |
Filip Tehlar | ef2a5bf | 2017-05-30 07:14:46 +0200 | [diff] [blame] | 1348 | if (lcm->lisp_pitr) |
| 1349 | local_mi = lcm->pitr_map_index; |
| 1350 | else |
| 1351 | { |
| 1352 | if (gid_address_type (&a->reid) == GID_ADDR_NSH) |
| 1353 | { |
| 1354 | if (lcm->nsh_map_index == ~0) |
| 1355 | local_mi = GID_LOOKUP_MISS; |
| 1356 | else |
| 1357 | local_mi = lcm->nsh_map_index; |
| 1358 | } |
| 1359 | else |
| 1360 | { |
| 1361 | local_mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, |
| 1362 | &a->leid); |
| 1363 | } |
| 1364 | } |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1365 | |
Florin Coras | 71893ac | 2016-07-10 20:09:32 +0200 | [diff] [blame] | 1366 | if (GID_LOOKUP_MISS == local_mi) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1367 | { |
| 1368 | clib_warning ("Local eid %U not found. Cannot add adjacency!", |
Florin Coras | f3dc11a | 2017-01-24 03:13:43 -0800 | [diff] [blame] | 1369 | format_gid_address, &a->leid); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1370 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1371 | return -1; |
| 1372 | } |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1373 | |
Florin Coras | 71893ac | 2016-07-10 20:09:32 +0200 | [diff] [blame] | 1374 | /* update forwarding */ |
| 1375 | dp_add_fwd_entry (lcm, local_mi, remote_mi); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1376 | } |
| 1377 | else |
Florin Coras | 71893ac | 2016-07-10 20:09:32 +0200 | [diff] [blame] | 1378 | dp_del_fwd_entry (lcm, 0, remote_mi); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1379 | |
| 1380 | return 0; |
| 1381 | } |
| 1382 | |
| 1383 | int |
Florin Coras | dca8804 | 2016-09-14 16:01:38 +0200 | [diff] [blame] | 1384 | vnet_lisp_set_map_request_mode (u8 mode) |
| 1385 | { |
| 1386 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 1387 | |
| 1388 | if (vnet_lisp_enable_disable_status () == 0) |
| 1389 | { |
| 1390 | clib_warning ("LISP is disabled!"); |
| 1391 | return VNET_API_ERROR_LISP_DISABLED; |
| 1392 | } |
| 1393 | |
| 1394 | if (mode >= _MR_MODE_MAX) |
| 1395 | { |
| 1396 | clib_warning ("Invalid LISP map request mode %d!", mode); |
| 1397 | return VNET_API_ERROR_INVALID_ARGUMENT; |
| 1398 | } |
| 1399 | |
| 1400 | lcm->map_request_mode = mode; |
| 1401 | return 0; |
| 1402 | } |
| 1403 | |
Filip Tehlar | 53f09e3 | 2016-05-19 14:25:44 +0200 | [diff] [blame] | 1404 | int |
Filip Tehlar | ef2a5bf | 2017-05-30 07:14:46 +0200 | [diff] [blame] | 1405 | vnet_lisp_nsh_set_locator_set (u8 * locator_set_name, u8 is_add) |
| 1406 | { |
| 1407 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 1408 | lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); |
| 1409 | u32 locator_set_index = ~0; |
| 1410 | mapping_t *m; |
| 1411 | uword *p; |
| 1412 | |
| 1413 | if (vnet_lisp_enable_disable_status () == 0) |
| 1414 | { |
| 1415 | clib_warning ("LISP is disabled!"); |
| 1416 | return VNET_API_ERROR_LISP_DISABLED; |
| 1417 | } |
| 1418 | |
| 1419 | if (is_add) |
| 1420 | { |
| 1421 | if (lcm->nsh_map_index == (u32) ~ 0) |
| 1422 | { |
| 1423 | p = hash_get_mem (lcm->locator_set_index_by_name, locator_set_name); |
| 1424 | if (!p) |
| 1425 | { |
| 1426 | clib_warning ("locator-set %v doesn't exist", locator_set_name); |
| 1427 | return -1; |
| 1428 | } |
| 1429 | locator_set_index = p[0]; |
| 1430 | |
| 1431 | pool_get (lcm->mapping_pool, m); |
| 1432 | memset (m, 0, sizeof *m); |
| 1433 | m->locator_set_index = locator_set_index; |
| 1434 | m->local = 1; |
| 1435 | m->nsh_set = 1; |
| 1436 | lcm->nsh_map_index = m - lcm->mapping_pool; |
| 1437 | |
| 1438 | if (~0 == vnet_lisp_gpe_add_nsh_iface (lgm)) |
| 1439 | return -1; |
| 1440 | } |
| 1441 | } |
| 1442 | else |
| 1443 | { |
| 1444 | if (lcm->nsh_map_index != (u32) ~ 0) |
| 1445 | { |
| 1446 | /* remove NSH mapping */ |
| 1447 | pool_put_index (lcm->mapping_pool, lcm->nsh_map_index); |
| 1448 | lcm->nsh_map_index = ~0; |
| 1449 | vnet_lisp_gpe_del_nsh_iface (lgm); |
| 1450 | } |
| 1451 | } |
| 1452 | return 0; |
| 1453 | } |
| 1454 | |
| 1455 | int |
Filip Tehlar | 53f09e3 | 2016-05-19 14:25:44 +0200 | [diff] [blame] | 1456 | vnet_lisp_pitr_set_locator_set (u8 * locator_set_name, u8 is_add) |
| 1457 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1458 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
Filip Tehlar | 53f09e3 | 2016-05-19 14:25:44 +0200 | [diff] [blame] | 1459 | u32 locator_set_index = ~0; |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1460 | mapping_t *m; |
| 1461 | uword *p; |
Filip Tehlar | 53f09e3 | 2016-05-19 14:25:44 +0200 | [diff] [blame] | 1462 | |
Andrej Kozemcak | 8ebb2a1 | 2016-06-07 12:25:20 +0200 | [diff] [blame] | 1463 | if (vnet_lisp_enable_disable_status () == 0) |
| 1464 | { |
| 1465 | clib_warning ("LISP is disabled!"); |
| 1466 | return VNET_API_ERROR_LISP_DISABLED; |
| 1467 | } |
| 1468 | |
Filip Tehlar | 53f09e3 | 2016-05-19 14:25:44 +0200 | [diff] [blame] | 1469 | p = hash_get_mem (lcm->locator_set_index_by_name, locator_set_name); |
| 1470 | if (!p) |
| 1471 | { |
| 1472 | clib_warning ("locator-set %v doesn't exist", locator_set_name); |
| 1473 | return -1; |
| 1474 | } |
| 1475 | locator_set_index = p[0]; |
| 1476 | |
| 1477 | if (is_add) |
| 1478 | { |
| 1479 | pool_get (lcm->mapping_pool, m); |
| 1480 | m->locator_set_index = locator_set_index; |
| 1481 | m->local = 1; |
Filip Tehlar | 38206ee | 2017-02-20 17:31:57 +0100 | [diff] [blame] | 1482 | m->pitr_set = 1; |
Filip Tehlar | 53f09e3 | 2016-05-19 14:25:44 +0200 | [diff] [blame] | 1483 | lcm->pitr_map_index = m - lcm->mapping_pool; |
| 1484 | |
| 1485 | /* enable pitr mode */ |
| 1486 | lcm->lisp_pitr = 1; |
| 1487 | } |
| 1488 | else |
| 1489 | { |
| 1490 | /* remove pitr mapping */ |
| 1491 | pool_put_index (lcm->mapping_pool, lcm->pitr_map_index); |
| 1492 | |
| 1493 | /* disable pitr mode */ |
| 1494 | lcm->lisp_pitr = 0; |
| 1495 | } |
| 1496 | return 0; |
| 1497 | } |
| 1498 | |
Florin Coras | ba888e4 | 2017-01-24 11:38:18 -0800 | [diff] [blame] | 1499 | /** |
| 1500 | * Configure Proxy-ETR |
| 1501 | * |
| 1502 | * @param ip PETR's IP address |
| 1503 | * @param is_add Flag that indicates if this is an addition or removal |
| 1504 | * |
| 1505 | * return 0 on success |
| 1506 | */ |
| 1507 | int |
| 1508 | vnet_lisp_use_petr (ip_address_t * ip, u8 is_add) |
| 1509 | { |
| 1510 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 1511 | u32 ls_index = ~0; |
| 1512 | mapping_t *m; |
| 1513 | vnet_lisp_add_del_locator_set_args_t _ls_args, *ls_args = &_ls_args; |
| 1514 | locator_t loc; |
| 1515 | |
| 1516 | if (vnet_lisp_enable_disable_status () == 0) |
| 1517 | { |
| 1518 | clib_warning ("LISP is disabled!"); |
| 1519 | return VNET_API_ERROR_LISP_DISABLED; |
| 1520 | } |
| 1521 | |
| 1522 | memset (ls_args, 0, sizeof (*ls_args)); |
| 1523 | |
| 1524 | if (is_add) |
| 1525 | { |
| 1526 | /* Create dummy petr locator-set */ |
Florin Coras | b69259a | 2017-03-09 14:39:54 -0800 | [diff] [blame] | 1527 | memset (&loc, 0, sizeof (loc)); |
Florin Coras | ba888e4 | 2017-01-24 11:38:18 -0800 | [diff] [blame] | 1528 | gid_address_from_ip (&loc.address, ip); |
| 1529 | loc.priority = 1; |
| 1530 | loc.state = loc.weight = 1; |
Florin Coras | 2743cc4 | 2017-01-29 16:42:20 -0800 | [diff] [blame] | 1531 | loc.local = 0; |
Florin Coras | ba888e4 | 2017-01-24 11:38:18 -0800 | [diff] [blame] | 1532 | |
| 1533 | ls_args->is_add = 1; |
| 1534 | ls_args->index = ~0; |
| 1535 | vec_add1 (ls_args->locators, loc); |
| 1536 | vnet_lisp_add_del_locator_set (ls_args, &ls_index); |
| 1537 | |
| 1538 | /* Add petr mapping */ |
| 1539 | pool_get (lcm->mapping_pool, m); |
| 1540 | m->locator_set_index = ls_index; |
| 1541 | lcm->petr_map_index = m - lcm->mapping_pool; |
| 1542 | |
| 1543 | /* Enable use-petr */ |
| 1544 | lcm->flags |= LISP_FLAG_USE_PETR; |
| 1545 | } |
| 1546 | else |
| 1547 | { |
| 1548 | m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index); |
| 1549 | |
| 1550 | /* Remove petr locator */ |
| 1551 | ls_args->is_add = 0; |
| 1552 | ls_args->index = m->locator_set_index; |
| 1553 | vnet_lisp_add_del_locator_set (ls_args, 0); |
| 1554 | |
| 1555 | /* Remove petr mapping */ |
| 1556 | pool_put_index (lcm->mapping_pool, lcm->petr_map_index); |
| 1557 | |
| 1558 | /* Disable use-petr */ |
| 1559 | lcm->flags &= ~LISP_FLAG_USE_PETR; |
| 1560 | } |
| 1561 | return 0; |
| 1562 | } |
| 1563 | |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 1564 | /* cleans locator to locator-set data and removes locators not part of |
| 1565 | * any locator-set */ |
| 1566 | static void |
| 1567 | clean_locator_to_locator_set (lisp_cp_main_t * lcm, u32 lsi) |
| 1568 | { |
Filip Tehlar | d1c5cc3 | 2016-05-30 10:39:20 +0200 | [diff] [blame] | 1569 | u32 i, j, *loc_indexp, *ls_indexp, **ls_indexes, *to_be_deleted = 0; |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1570 | locator_set_t *ls = pool_elt_at_index (lcm->locator_set_pool, lsi); |
| 1571 | for (i = 0; i < vec_len (ls->locator_indices); i++) |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 1572 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1573 | loc_indexp = vec_elt_at_index (ls->locator_indices, i); |
| 1574 | ls_indexes = vec_elt_at_index (lcm->locator_to_locator_sets, |
| 1575 | loc_indexp[0]); |
| 1576 | for (j = 0; j < vec_len (ls_indexes[0]); j++) |
| 1577 | { |
| 1578 | ls_indexp = vec_elt_at_index (ls_indexes[0], j); |
| 1579 | if (ls_indexp[0] == lsi) |
| 1580 | break; |
| 1581 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 1582 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1583 | /* delete index for removed locator-set */ |
| 1584 | vec_del1 (ls_indexes[0], j); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 1585 | |
| 1586 | /* delete locator if it's part of no locator-set */ |
| 1587 | if (vec_len (ls_indexes[0]) == 0) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1588 | { |
| 1589 | pool_put_index (lcm->locator_pool, loc_indexp[0]); |
| 1590 | vec_add1 (to_be_deleted, i); |
| 1591 | } |
Filip Tehlar | d1c5cc3 | 2016-05-30 10:39:20 +0200 | [diff] [blame] | 1592 | } |
| 1593 | |
| 1594 | if (to_be_deleted) |
| 1595 | { |
| 1596 | for (i = 0; i < vec_len (to_be_deleted); i++) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1597 | { |
| 1598 | loc_indexp = vec_elt_at_index (to_be_deleted, i); |
| 1599 | vec_del1 (ls->locator_indices, loc_indexp[0]); |
| 1600 | } |
Filip Tehlar | d1c5cc3 | 2016-05-30 10:39:20 +0200 | [diff] [blame] | 1601 | vec_free (to_be_deleted); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 1602 | } |
| 1603 | } |
Filip Tehlar | d1c5cc3 | 2016-05-30 10:39:20 +0200 | [diff] [blame] | 1604 | |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1605 | static inline uword * |
| 1606 | get_locator_set_index (vnet_lisp_add_del_locator_set_args_t * a, uword * p) |
Andrej Kozemcak | 6a2e439 | 2016-05-26 12:20:08 +0200 | [diff] [blame] | 1607 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1608 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
Andrej Kozemcak | 6a2e439 | 2016-05-26 12:20:08 +0200 | [diff] [blame] | 1609 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1610 | ASSERT (a != NULL); |
| 1611 | ASSERT (p != NULL); |
Andrej Kozemcak | 6a2e439 | 2016-05-26 12:20:08 +0200 | [diff] [blame] | 1612 | |
| 1613 | /* find locator-set */ |
| 1614 | if (a->local) |
| 1615 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1616 | p = hash_get_mem (lcm->locator_set_index_by_name, a->name); |
Andrej Kozemcak | 6a2e439 | 2016-05-26 12:20:08 +0200 | [diff] [blame] | 1617 | } |
| 1618 | else |
| 1619 | { |
| 1620 | *p = a->index; |
| 1621 | } |
| 1622 | |
| 1623 | return p; |
| 1624 | } |
| 1625 | |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1626 | static inline int |
| 1627 | is_locator_in_locator_set (lisp_cp_main_t * lcm, locator_set_t * ls, |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1628 | locator_t * loc) |
Andrej Kozemcak | 6a2e439 | 2016-05-26 12:20:08 +0200 | [diff] [blame] | 1629 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1630 | locator_t *itloc; |
| 1631 | u32 *locit; |
Andrej Kozemcak | 6a2e439 | 2016-05-26 12:20:08 +0200 | [diff] [blame] | 1632 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1633 | ASSERT (ls != NULL); |
| 1634 | ASSERT (loc != NULL); |
Andrej Kozemcak | 6a2e439 | 2016-05-26 12:20:08 +0200 | [diff] [blame] | 1635 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1636 | vec_foreach (locit, ls->locator_indices) |
| 1637 | { |
| 1638 | itloc = pool_elt_at_index (lcm->locator_pool, locit[0]); |
| 1639 | if ((ls->local && itloc->sw_if_index == loc->sw_if_index) || |
| 1640 | (!ls->local && !gid_address_cmp (&itloc->address, &loc->address))) |
| 1641 | { |
| 1642 | clib_warning ("Duplicate locator"); |
| 1643 | return VNET_API_ERROR_VALUE_EXIST; |
| 1644 | } |
| 1645 | } |
Andrej Kozemcak | 6a2e439 | 2016-05-26 12:20:08 +0200 | [diff] [blame] | 1646 | |
| 1647 | return 0; |
| 1648 | } |
| 1649 | |
Filip Tehlar | 68d2e24 | 2017-04-21 12:05:58 +0200 | [diff] [blame] | 1650 | static void |
| 1651 | update_adjacencies_by_map_index (lisp_cp_main_t * lcm, u8 is_local, |
| 1652 | u32 mapping_index, u8 remove_only) |
| 1653 | { |
| 1654 | fwd_entry_t *fwd; |
| 1655 | mapping_t *map; |
| 1656 | vnet_lisp_add_del_adjacency_args_t _a, *a = &_a; |
| 1657 | |
| 1658 | map = pool_elt_at_index (lcm->mapping_pool, mapping_index); |
| 1659 | |
| 1660 | /* *INDENT-OFF* */ |
| 1661 | pool_foreach(fwd, lcm->fwd_entry_pool, |
| 1662 | ({ |
| 1663 | if ((is_local && 0 == gid_address_cmp (&map->eid, &fwd->leid)) || |
| 1664 | (!is_local && 0 == gid_address_cmp (&map->eid, &fwd->reid))) |
| 1665 | { |
| 1666 | a->is_add = 0; |
| 1667 | gid_address_copy (&a->leid, &fwd->leid); |
| 1668 | gid_address_copy (&a->reid, &fwd->reid); |
| 1669 | |
| 1670 | vnet_lisp_add_del_adjacency (a); |
| 1671 | |
| 1672 | if (!remove_only) |
| 1673 | { |
| 1674 | a->is_add = 1; |
| 1675 | vnet_lisp_add_del_adjacency (a); |
| 1676 | } |
| 1677 | } |
| 1678 | })); |
| 1679 | /* *INDENT-ON* */ |
| 1680 | } |
| 1681 | |
| 1682 | static void |
| 1683 | update_fwd_entries_by_locator_set (lisp_cp_main_t * lcm, u8 is_local, |
| 1684 | u32 ls_index, u8 remove_only) |
| 1685 | { |
| 1686 | u32 i, *map_indexp; |
| 1687 | u32 **eid_indexes; |
Filip Tehlar | facee28 | 2017-04-27 14:29:27 +0200 | [diff] [blame] | 1688 | |
| 1689 | if (vec_len (lcm->locator_set_to_eids) <= ls_index) |
| 1690 | return; |
| 1691 | |
Filip Tehlar | 68d2e24 | 2017-04-21 12:05:58 +0200 | [diff] [blame] | 1692 | eid_indexes = vec_elt_at_index (lcm->locator_set_to_eids, ls_index); |
| 1693 | |
| 1694 | for (i = 0; i < vec_len (eid_indexes[0]); i++) |
| 1695 | { |
| 1696 | map_indexp = vec_elt_at_index (eid_indexes[0], i); |
| 1697 | update_adjacencies_by_map_index (lcm, is_local, map_indexp[0], |
| 1698 | remove_only); |
| 1699 | } |
| 1700 | } |
| 1701 | |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1702 | static inline void |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1703 | remove_locator_from_locator_set (locator_set_t * ls, u32 * locit, |
| 1704 | u32 ls_index, u32 loc_id) |
Andrej Kozemcak | 6a2e439 | 2016-05-26 12:20:08 +0200 | [diff] [blame] | 1705 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1706 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 1707 | u32 **ls_indexes = NULL; |
Andrej Kozemcak | 6a2e439 | 2016-05-26 12:20:08 +0200 | [diff] [blame] | 1708 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1709 | ASSERT (ls != NULL); |
| 1710 | ASSERT (locit != NULL); |
Andrej Kozemcak | 6a2e439 | 2016-05-26 12:20:08 +0200 | [diff] [blame] | 1711 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1712 | ls_indexes = vec_elt_at_index (lcm->locator_to_locator_sets, locit[0]); |
| 1713 | pool_put_index (lcm->locator_pool, locit[0]); |
| 1714 | vec_del1 (ls->locator_indices, loc_id); |
| 1715 | vec_del1 (ls_indexes[0], ls_index); |
Andrej Kozemcak | 6a2e439 | 2016-05-26 12:20:08 +0200 | [diff] [blame] | 1716 | } |
| 1717 | |
| 1718 | int |
| 1719 | vnet_lisp_add_del_locator (vnet_lisp_add_del_locator_set_args_t * a, |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1720 | locator_set_t * ls, u32 * ls_result) |
Andrej Kozemcak | 6a2e439 | 2016-05-26 12:20:08 +0200 | [diff] [blame] | 1721 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1722 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 1723 | locator_t *loc = NULL, *itloc = NULL; |
| 1724 | uword _p = (u32) ~ 0, *p = &_p; |
| 1725 | u32 loc_index = ~0, ls_index = ~0, *locit = NULL, **ls_indexes = NULL; |
Andrej Kozemcak | 6a2e439 | 2016-05-26 12:20:08 +0200 | [diff] [blame] | 1726 | u32 loc_id = ~0; |
| 1727 | int ret = 0; |
| 1728 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1729 | ASSERT (a != NULL); |
Andrej Kozemcak | 6a2e439 | 2016-05-26 12:20:08 +0200 | [diff] [blame] | 1730 | |
Andrej Kozemcak | 8ebb2a1 | 2016-06-07 12:25:20 +0200 | [diff] [blame] | 1731 | if (vnet_lisp_enable_disable_status () == 0) |
| 1732 | { |
| 1733 | clib_warning ("LISP is disabled!"); |
| 1734 | return VNET_API_ERROR_LISP_DISABLED; |
| 1735 | } |
| 1736 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1737 | p = get_locator_set_index (a, p); |
Andrej Kozemcak | 6a2e439 | 2016-05-26 12:20:08 +0200 | [diff] [blame] | 1738 | if (!p) |
| 1739 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1740 | clib_warning ("locator-set %v doesn't exist", a->name); |
Andrej Kozemcak | 6a2e439 | 2016-05-26 12:20:08 +0200 | [diff] [blame] | 1741 | return VNET_API_ERROR_INVALID_ARGUMENT; |
| 1742 | } |
| 1743 | |
| 1744 | if (ls == 0) |
| 1745 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1746 | ls = pool_elt_at_index (lcm->locator_set_pool, p[0]); |
Andrej Kozemcak | 6a2e439 | 2016-05-26 12:20:08 +0200 | [diff] [blame] | 1747 | if (!ls) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1748 | { |
| 1749 | clib_warning ("locator-set %d to be overwritten doesn't exist!", |
| 1750 | p[0]); |
| 1751 | return VNET_API_ERROR_INVALID_ARGUMENT; |
| 1752 | } |
Andrej Kozemcak | 6a2e439 | 2016-05-26 12:20:08 +0200 | [diff] [blame] | 1753 | } |
| 1754 | |
| 1755 | if (a->is_add) |
| 1756 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1757 | if (ls_result) |
| 1758 | ls_result[0] = p[0]; |
Andrej Kozemcak | 6a2e439 | 2016-05-26 12:20:08 +0200 | [diff] [blame] | 1759 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1760 | /* allocate locators */ |
| 1761 | vec_foreach (itloc, a->locators) |
Andrej Kozemcak | 6a2e439 | 2016-05-26 12:20:08 +0200 | [diff] [blame] | 1762 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1763 | ret = is_locator_in_locator_set (lcm, ls, itloc); |
| 1764 | if (0 != ret) |
| 1765 | { |
| 1766 | return ret; |
| 1767 | } |
Andrej Kozemcak | 6a2e439 | 2016-05-26 12:20:08 +0200 | [diff] [blame] | 1768 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1769 | pool_get (lcm->locator_pool, loc); |
| 1770 | loc[0] = itloc[0]; |
| 1771 | loc_index = loc - lcm->locator_pool; |
Andrej Kozemcak | 6a2e439 | 2016-05-26 12:20:08 +0200 | [diff] [blame] | 1772 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1773 | vec_add1 (ls->locator_indices, loc_index); |
Andrej Kozemcak | 6a2e439 | 2016-05-26 12:20:08 +0200 | [diff] [blame] | 1774 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1775 | vec_validate (lcm->locator_to_locator_sets, loc_index); |
| 1776 | ls_indexes = vec_elt_at_index (lcm->locator_to_locator_sets, |
| 1777 | loc_index); |
Filip Tehlar | c5bb0d6 | 2016-09-02 12:14:31 +0200 | [diff] [blame] | 1778 | vec_add1 (ls_indexes[0], p[0]); |
Andrej Kozemcak | 6a2e439 | 2016-05-26 12:20:08 +0200 | [diff] [blame] | 1779 | } |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1780 | } |
| 1781 | else |
| 1782 | { |
| 1783 | ls_index = p[0]; |
Filip Tehlar | 68d2e24 | 2017-04-21 12:05:58 +0200 | [diff] [blame] | 1784 | u8 removed; |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1785 | |
Filip Tehlar | 68d2e24 | 2017-04-21 12:05:58 +0200 | [diff] [blame] | 1786 | vec_foreach (itloc, a->locators) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1787 | { |
Filip Tehlar | 68d2e24 | 2017-04-21 12:05:58 +0200 | [diff] [blame] | 1788 | removed = 0; |
| 1789 | loc_id = 0; |
| 1790 | vec_foreach (locit, ls->locator_indices) |
| 1791 | { |
| 1792 | loc = pool_elt_at_index (lcm->locator_pool, locit[0]); |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1793 | |
Filip Tehlar | 68d2e24 | 2017-04-21 12:05:58 +0200 | [diff] [blame] | 1794 | if (loc->local && loc->sw_if_index == itloc->sw_if_index) |
| 1795 | { |
| 1796 | removed = 1; |
| 1797 | remove_locator_from_locator_set (ls, locit, ls_index, loc_id); |
| 1798 | } |
| 1799 | if (0 == loc->local && |
| 1800 | !gid_address_cmp (&loc->address, &itloc->address)) |
| 1801 | { |
| 1802 | removed = 1; |
| 1803 | remove_locator_from_locator_set (ls, locit, ls_index, loc_id); |
| 1804 | } |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1805 | |
Filip Tehlar | 68d2e24 | 2017-04-21 12:05:58 +0200 | [diff] [blame] | 1806 | if (removed) |
| 1807 | { |
| 1808 | /* update fwd entries using this locator in DP */ |
| 1809 | update_fwd_entries_by_locator_set (lcm, loc->local, ls_index, |
| 1810 | vec_len (ls->locator_indices) |
| 1811 | == 0); |
| 1812 | } |
| 1813 | |
| 1814 | loc_id++; |
| 1815 | } |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1816 | } |
| 1817 | } |
Andrej Kozemcak | 6a2e439 | 2016-05-26 12:20:08 +0200 | [diff] [blame] | 1818 | |
| 1819 | return 0; |
| 1820 | } |
| 1821 | |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 1822 | int |
| 1823 | vnet_lisp_add_del_locator_set (vnet_lisp_add_del_locator_set_args_t * a, |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1824 | u32 * ls_result) |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 1825 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1826 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 1827 | locator_set_t *ls; |
| 1828 | uword _p = (u32) ~ 0, *p = &_p; |
Andrej Kozemcak | 6a2e439 | 2016-05-26 12:20:08 +0200 | [diff] [blame] | 1829 | u32 ls_index; |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1830 | u32 **eid_indexes; |
Andrej Kozemcak | 6a2e439 | 2016-05-26 12:20:08 +0200 | [diff] [blame] | 1831 | int ret = 0; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 1832 | |
Andrej Kozemcak | 8ebb2a1 | 2016-06-07 12:25:20 +0200 | [diff] [blame] | 1833 | if (vnet_lisp_enable_disable_status () == 0) |
| 1834 | { |
| 1835 | clib_warning ("LISP is disabled!"); |
| 1836 | return VNET_API_ERROR_LISP_DISABLED; |
| 1837 | } |
| 1838 | |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 1839 | if (a->is_add) |
| 1840 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1841 | p = get_locator_set_index (a, p); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 1842 | |
| 1843 | /* overwrite */ |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1844 | if (p && p[0] != (u32) ~ 0) |
| 1845 | { |
| 1846 | ls = pool_elt_at_index (lcm->locator_set_pool, p[0]); |
| 1847 | if (!ls) |
| 1848 | { |
| 1849 | clib_warning ("locator-set %d to be overwritten doesn't exist!", |
| 1850 | p[0]); |
| 1851 | return -1; |
| 1852 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 1853 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1854 | /* clean locator to locator-set vectors and remove locators if |
| 1855 | * they're not part of another locator-set */ |
| 1856 | clean_locator_to_locator_set (lcm, p[0]); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 1857 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1858 | /* remove locator indices from locator set */ |
| 1859 | vec_free (ls->locator_indices); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 1860 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1861 | ls_index = p[0]; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 1862 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1863 | if (ls_result) |
| 1864 | ls_result[0] = p[0]; |
| 1865 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 1866 | /* new locator-set */ |
| 1867 | else |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1868 | { |
| 1869 | pool_get (lcm->locator_set_pool, ls); |
| 1870 | memset (ls, 0, sizeof (*ls)); |
| 1871 | ls_index = ls - lcm->locator_set_pool; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 1872 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1873 | if (a->local) |
| 1874 | { |
| 1875 | ls->name = vec_dup (a->name); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 1876 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1877 | if (!lcm->locator_set_index_by_name) |
| 1878 | lcm->locator_set_index_by_name = hash_create_vec ( |
| 1879 | /* size */ |
| 1880 | 0, |
| 1881 | sizeof |
| 1882 | (ls->name |
| 1883 | [0]), |
| 1884 | sizeof |
| 1885 | (uword)); |
| 1886 | hash_set_mem (lcm->locator_set_index_by_name, ls->name, |
| 1887 | ls_index); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 1888 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1889 | /* mark as local locator-set */ |
| 1890 | vec_add1 (lcm->local_locator_set_indexes, ls_index); |
| 1891 | } |
| 1892 | ls->local = a->local; |
| 1893 | if (ls_result) |
| 1894 | ls_result[0] = ls_index; |
| 1895 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 1896 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1897 | ret = vnet_lisp_add_del_locator (a, ls, NULL); |
Andrej Kozemcak | 6a2e439 | 2016-05-26 12:20:08 +0200 | [diff] [blame] | 1898 | if (0 != ret) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1899 | { |
| 1900 | return ret; |
| 1901 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 1902 | } |
| 1903 | else |
| 1904 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1905 | p = get_locator_set_index (a, p); |
Andrej Kozemcak | 6a2e439 | 2016-05-26 12:20:08 +0200 | [diff] [blame] | 1906 | if (!p) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1907 | { |
| 1908 | clib_warning ("locator-set %v doesn't exists", a->name); |
| 1909 | return -1; |
| 1910 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 1911 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1912 | ls = pool_elt_at_index (lcm->locator_set_pool, p[0]); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 1913 | if (!ls) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1914 | { |
| 1915 | clib_warning ("locator-set with index %d doesn't exists", p[0]); |
| 1916 | return -1; |
| 1917 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 1918 | |
Andrej Kozemcak | b6e4d39 | 2016-06-14 13:55:57 +0200 | [diff] [blame] | 1919 | if (lcm->mreq_itr_rlocs == p[0]) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1920 | { |
| 1921 | clib_warning ("Can't delete the locator-set used to constrain " |
| 1922 | "the itr-rlocs in map-requests!"); |
| 1923 | return -1; |
| 1924 | } |
Andrej Kozemcak | b6e4d39 | 2016-06-14 13:55:57 +0200 | [diff] [blame] | 1925 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1926 | if (vec_len (lcm->locator_set_to_eids) != 0) |
| 1927 | { |
| 1928 | eid_indexes = vec_elt_at_index (lcm->locator_set_to_eids, p[0]); |
| 1929 | if (vec_len (eid_indexes[0]) != 0) |
| 1930 | { |
| 1931 | clib_warning |
| 1932 | ("Can't delete a locator that supports a mapping!"); |
| 1933 | return -1; |
| 1934 | } |
| 1935 | } |
Andrej Kozemcak | b92feb6 | 2016-03-31 13:51:42 +0200 | [diff] [blame] | 1936 | |
| 1937 | /* clean locator to locator-sets data */ |
| 1938 | clean_locator_to_locator_set (lcm, p[0]); |
| 1939 | |
| 1940 | if (ls->local) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1941 | { |
| 1942 | u32 it, lsi; |
Andrej Kozemcak | b92feb6 | 2016-03-31 13:51:42 +0200 | [diff] [blame] | 1943 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1944 | vec_foreach_index (it, lcm->local_locator_set_indexes) |
| 1945 | { |
| 1946 | lsi = vec_elt (lcm->local_locator_set_indexes, it); |
| 1947 | if (lsi == p[0]) |
| 1948 | { |
| 1949 | vec_del1 (lcm->local_locator_set_indexes, it); |
| 1950 | break; |
| 1951 | } |
| 1952 | } |
| 1953 | hash_unset_mem (lcm->locator_set_index_by_name, ls->name); |
| 1954 | } |
| 1955 | vec_free (ls->name); |
| 1956 | vec_free (ls->locator_indices); |
| 1957 | pool_put (lcm->locator_set_pool, ls); |
Andrej Kozemcak | b92feb6 | 2016-03-31 13:51:42 +0200 | [diff] [blame] | 1958 | } |
| 1959 | return 0; |
| 1960 | } |
| 1961 | |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 1962 | int |
| 1963 | vnet_lisp_rloc_probe_enable_disable (u8 is_enable) |
| 1964 | { |
| 1965 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 1966 | |
| 1967 | lcm->rloc_probing = is_enable; |
| 1968 | return 0; |
| 1969 | } |
| 1970 | |
| 1971 | int |
| 1972 | vnet_lisp_map_register_enable_disable (u8 is_enable) |
| 1973 | { |
| 1974 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 1975 | |
| 1976 | lcm->map_registering = is_enable; |
| 1977 | return 0; |
| 1978 | } |
| 1979 | |
Filip Tehlar | 46d4e36 | 2016-05-09 09:39:26 +0200 | [diff] [blame] | 1980 | clib_error_t * |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1981 | vnet_lisp_enable_disable (u8 is_enable) |
Filip Tehlar | 46d4e36 | 2016-05-09 09:39:26 +0200 | [diff] [blame] | 1982 | { |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 1983 | u32 vni, dp_table; |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1984 | clib_error_t *error = 0; |
| 1985 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 1986 | vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a; |
Filip Tehlar | 46d4e36 | 2016-05-09 09:39:26 +0200 | [diff] [blame] | 1987 | |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1988 | a->is_en = is_enable; |
Filip Tehlar | 46d4e36 | 2016-05-09 09:39:26 +0200 | [diff] [blame] | 1989 | error = vnet_lisp_gpe_enable_disable (a); |
| 1990 | if (error) |
| 1991 | { |
| 1992 | return clib_error_return (0, "failed to %s data-plane!", |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1993 | a->is_en ? "enable" : "disable"); |
Filip Tehlar | 46d4e36 | 2016-05-09 09:39:26 +0200 | [diff] [blame] | 1994 | } |
| 1995 | |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 1996 | if (is_enable) |
Filip Tehlar | 46d4e36 | 2016-05-09 09:39:26 +0200 | [diff] [blame] | 1997 | { |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 1998 | /* enable all l2 and l3 ifaces */ |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 1999 | |
| 2000 | /* *INDENT-OFF* */ |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 2001 | hash_foreach(vni, dp_table, lcm->table_id_by_vni, ({ |
| 2002 | dp_add_del_iface(lcm, vni, 0, 1); |
| 2003 | })); |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 2004 | hash_foreach(vni, dp_table, lcm->bd_id_by_vni, ({ |
| 2005 | dp_add_del_iface(lcm, vni, /* is_l2 */ 1, 1); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 2006 | })); |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2007 | /* *INDENT-ON* */ |
Filip Tehlar | 46d4e36 | 2016-05-09 09:39:26 +0200 | [diff] [blame] | 2008 | } |
| 2009 | else |
| 2010 | { |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 2011 | /* clear interface table */ |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2012 | hash_free (lcm->fwd_entry_by_mapping_index); |
| 2013 | pool_free (lcm->fwd_entry_pool); |
Filip Tehlar | 46d4e36 | 2016-05-09 09:39:26 +0200 | [diff] [blame] | 2014 | } |
| 2015 | |
| 2016 | /* update global flag */ |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 2017 | lcm->is_enabled = is_enable; |
Filip Tehlar | 46d4e36 | 2016-05-09 09:39:26 +0200 | [diff] [blame] | 2018 | |
| 2019 | return 0; |
| 2020 | } |
| 2021 | |
Filip Tehlar | 46d4e36 | 2016-05-09 09:39:26 +0200 | [diff] [blame] | 2022 | u8 |
| 2023 | vnet_lisp_enable_disable_status (void) |
| 2024 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2025 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
Filip Tehlar | 46d4e36 | 2016-05-09 09:39:26 +0200 | [diff] [blame] | 2026 | return lcm->is_enabled; |
| 2027 | } |
| 2028 | |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2029 | int |
| 2030 | vnet_lisp_add_del_map_resolver (vnet_lisp_add_del_map_resolver_args_t * a) |
| 2031 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2032 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2033 | u32 i; |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 2034 | lisp_msmr_t _mr, *mr = &_mr; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2035 | |
Andrej Kozemcak | 8ebb2a1 | 2016-06-07 12:25:20 +0200 | [diff] [blame] | 2036 | if (vnet_lisp_enable_disable_status () == 0) |
| 2037 | { |
| 2038 | clib_warning ("LISP is disabled!"); |
| 2039 | return VNET_API_ERROR_LISP_DISABLED; |
| 2040 | } |
| 2041 | |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2042 | if (a->is_add) |
| 2043 | { |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 2044 | |
| 2045 | if (get_map_resolver (&a->address)) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2046 | { |
| 2047 | clib_warning ("map-resolver %U already exists!", format_ip_address, |
| 2048 | &a->address); |
| 2049 | return -1; |
| 2050 | } |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 2051 | |
| 2052 | memset (mr, 0, sizeof (*mr)); |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2053 | ip_address_copy (&mr->address, &a->address); |
| 2054 | vec_add1 (lcm->map_resolvers, *mr); |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 2055 | |
| 2056 | if (vec_len (lcm->map_resolvers) == 1) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2057 | lcm->do_map_resolver_election = 1; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2058 | } |
| 2059 | else |
| 2060 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2061 | for (i = 0; i < vec_len (lcm->map_resolvers); i++) |
| 2062 | { |
| 2063 | mr = vec_elt_at_index (lcm->map_resolvers, i); |
| 2064 | if (!ip_address_cmp (&mr->address, &a->address)) |
| 2065 | { |
| 2066 | if (!ip_address_cmp (&mr->address, &lcm->active_map_resolver)) |
| 2067 | lcm->do_map_resolver_election = 1; |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 2068 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2069 | vec_del1 (lcm->map_resolvers, i); |
| 2070 | break; |
| 2071 | } |
| 2072 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2073 | } |
| 2074 | return 0; |
| 2075 | } |
| 2076 | |
Andrej Kozemcak | b6e4d39 | 2016-06-14 13:55:57 +0200 | [diff] [blame] | 2077 | int |
| 2078 | vnet_lisp_add_del_mreq_itr_rlocs (vnet_lisp_add_del_mreq_itr_rloc_args_t * a) |
| 2079 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2080 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 2081 | uword *p = 0; |
Andrej Kozemcak | b6e4d39 | 2016-06-14 13:55:57 +0200 | [diff] [blame] | 2082 | |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 2083 | if (vnet_lisp_enable_disable_status () == 0) |
| 2084 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2085 | clib_warning ("LISP is disabled!"); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 2086 | return VNET_API_ERROR_LISP_DISABLED; |
| 2087 | } |
Andrej Kozemcak | b6e4d39 | 2016-06-14 13:55:57 +0200 | [diff] [blame] | 2088 | |
| 2089 | if (a->is_add) |
| 2090 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2091 | p = hash_get_mem (lcm->locator_set_index_by_name, a->locator_set_name); |
Andrej Kozemcak | b6e4d39 | 2016-06-14 13:55:57 +0200 | [diff] [blame] | 2092 | if (!p) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2093 | { |
| 2094 | clib_warning ("locator-set %v doesn't exist", a->locator_set_name); |
| 2095 | return VNET_API_ERROR_INVALID_ARGUMENT; |
| 2096 | } |
Andrej Kozemcak | b6e4d39 | 2016-06-14 13:55:57 +0200 | [diff] [blame] | 2097 | |
| 2098 | lcm->mreq_itr_rlocs = p[0]; |
| 2099 | } |
| 2100 | else |
| 2101 | { |
| 2102 | lcm->mreq_itr_rlocs = ~0; |
| 2103 | } |
| 2104 | |
| 2105 | return 0; |
| 2106 | } |
| 2107 | |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2108 | /* Statistics (not really errors) */ |
| 2109 | #define foreach_lisp_cp_lookup_error \ |
| 2110 | _(DROP, "drop") \ |
Filip Tehlar | d5a65db | 2017-05-17 17:21:10 +0200 | [diff] [blame] | 2111 | _(MAP_REQUESTS_SENT, "map-request sent") \ |
| 2112 | _(ARP_REPLY_TX, "ARP replies sent") |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2113 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2114 | static char *lisp_cp_lookup_error_strings[] = { |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2115 | #define _(sym,string) string, |
| 2116 | foreach_lisp_cp_lookup_error |
| 2117 | #undef _ |
| 2118 | }; |
| 2119 | |
| 2120 | typedef enum |
| 2121 | { |
| 2122 | #define _(sym,str) LISP_CP_LOOKUP_ERROR_##sym, |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2123 | foreach_lisp_cp_lookup_error |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2124 | #undef _ |
| 2125 | LISP_CP_LOOKUP_N_ERROR, |
| 2126 | } lisp_cp_lookup_error_t; |
| 2127 | |
| 2128 | typedef enum |
| 2129 | { |
| 2130 | LISP_CP_LOOKUP_NEXT_DROP, |
Filip Tehlar | d5a65db | 2017-05-17 17:21:10 +0200 | [diff] [blame] | 2131 | LISP_CP_LOOKUP_NEXT_ARP_REPLY_TX, |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2132 | LISP_CP_LOOKUP_N_NEXT, |
| 2133 | } lisp_cp_lookup_next_t; |
| 2134 | |
| 2135 | typedef struct |
| 2136 | { |
| 2137 | gid_address_t dst_eid; |
Andrej Kozemcak | 94e3476 | 2016-05-25 12:43:21 +0200 | [diff] [blame] | 2138 | ip_address_t map_resolver_ip; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2139 | } lisp_cp_lookup_trace_t; |
| 2140 | |
| 2141 | u8 * |
| 2142 | format_lisp_cp_lookup_trace (u8 * s, va_list * args) |
| 2143 | { |
| 2144 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 2145 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2146 | lisp_cp_lookup_trace_t *t = va_arg (*args, lisp_cp_lookup_trace_t *); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2147 | |
| 2148 | s = format (s, "LISP-CP-LOOKUP: map-resolver: %U destination eid %U", |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2149 | format_ip_address, &t->map_resolver_ip, format_gid_address, |
| 2150 | &t->dst_eid); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2151 | return s; |
| 2152 | } |
| 2153 | |
Florin Coras | 1c49484 | 2016-06-16 21:08:56 +0200 | [diff] [blame] | 2154 | int |
| 2155 | get_mr_and_local_iface_ip (lisp_cp_main_t * lcm, ip_address_t * mr_ip, |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2156 | ip_address_t * sloc) |
Florin Coras | c2c9008 | 2016-06-13 18:37:15 +0200 | [diff] [blame] | 2157 | { |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 2158 | lisp_msmr_t *mrit; |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2159 | ip_address_t *a; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2160 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2161 | if (vec_len (lcm->map_resolvers) == 0) |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2162 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2163 | clib_warning ("No map-resolver configured"); |
Florin Coras | 1c49484 | 2016-06-16 21:08:56 +0200 | [diff] [blame] | 2164 | return 0; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2165 | } |
| 2166 | |
Florin Coras | ddfafb8 | 2016-05-13 18:09:56 +0200 | [diff] [blame] | 2167 | /* find the first mr ip we have a route to and the ip of the |
| 2168 | * iface that has a route to it */ |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2169 | vec_foreach (mrit, lcm->map_resolvers) |
| 2170 | { |
| 2171 | a = &mrit->address; |
| 2172 | if (0 != ip_fib_get_first_egress_ip_for_dst (lcm, a, sloc)) |
| 2173 | { |
| 2174 | ip_address_copy (mr_ip, a); |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 2175 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2176 | /* also update globals */ |
| 2177 | return 1; |
| 2178 | } |
| 2179 | } |
Florin Coras | ddfafb8 | 2016-05-13 18:09:56 +0200 | [diff] [blame] | 2180 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2181 | clib_warning ("Can't find map-resolver and local interface ip!"); |
Florin Coras | 1c49484 | 2016-06-16 21:08:56 +0200 | [diff] [blame] | 2182 | return 0; |
Florin Coras | ddfafb8 | 2016-05-13 18:09:56 +0200 | [diff] [blame] | 2183 | } |
Filip Tehlar | 254b036 | 2016-04-07 10:04:34 +0200 | [diff] [blame] | 2184 | |
Filip Tehlar | beceab9 | 2016-04-20 17:21:55 +0200 | [diff] [blame] | 2185 | static gid_address_t * |
Filip Tehlar | 254b036 | 2016-04-07 10:04:34 +0200 | [diff] [blame] | 2186 | build_itr_rloc_list (lisp_cp_main_t * lcm, locator_set_t * loc_set) |
| 2187 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2188 | void *addr; |
Filip Tehlar | 254b036 | 2016-04-07 10:04:34 +0200 | [diff] [blame] | 2189 | u32 i; |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2190 | locator_t *loc; |
| 2191 | u32 *loc_indexp; |
| 2192 | ip_interface_address_t *ia = 0; |
| 2193 | gid_address_t gid_data, *gid = &gid_data; |
| 2194 | gid_address_t *rlocs = 0; |
| 2195 | ip_prefix_t *ippref = &gid_address_ippref (gid); |
| 2196 | ip_address_t *rloc = &ip_prefix_addr (ippref); |
Filip Tehlar | 254b036 | 2016-04-07 10:04:34 +0200 | [diff] [blame] | 2197 | |
Filip Tehlar | 324112f | 2016-06-02 16:07:38 +0200 | [diff] [blame] | 2198 | memset (gid, 0, sizeof (gid[0])); |
Filip Tehlar | beceab9 | 2016-04-20 17:21:55 +0200 | [diff] [blame] | 2199 | gid_address_type (gid) = GID_ADDR_IP_PREFIX; |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2200 | for (i = 0; i < vec_len (loc_set->locator_indices); i++) |
Filip Tehlar | 254b036 | 2016-04-07 10:04:34 +0200 | [diff] [blame] | 2201 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2202 | loc_indexp = vec_elt_at_index (loc_set->locator_indices, i); |
Filip Tehlar | 254b036 | 2016-04-07 10:04:34 +0200 | [diff] [blame] | 2203 | loc = pool_elt_at_index (lcm->locator_pool, loc_indexp[0]); |
| 2204 | |
Filip Tehlar | 254b036 | 2016-04-07 10:04:34 +0200 | [diff] [blame] | 2205 | /* Add ipv4 locators first TODO sort them */ |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2206 | |
| 2207 | /* *INDENT-OFF* */ |
Filip Tehlar | 254b036 | 2016-04-07 10:04:34 +0200 | [diff] [blame] | 2208 | foreach_ip_interface_address (&lcm->im4->lookup_main, ia, |
| 2209 | loc->sw_if_index, 1 /* unnumbered */, |
| 2210 | ({ |
Florin Coras | 1c49484 | 2016-06-16 21:08:56 +0200 | [diff] [blame] | 2211 | addr = ip_interface_address_get_address (&lcm->im4->lookup_main, ia); |
| 2212 | ip_address_set (rloc, addr, IP4); |
Florin Coras | ddfafb8 | 2016-05-13 18:09:56 +0200 | [diff] [blame] | 2213 | ip_prefix_len (ippref) = 32; |
Andrej Kozemcak | 438109d | 2016-07-22 12:54:12 +0200 | [diff] [blame] | 2214 | ip_prefix_normalize (ippref); |
Filip Tehlar | beceab9 | 2016-04-20 17:21:55 +0200 | [diff] [blame] | 2215 | vec_add1 (rlocs, gid[0]); |
Filip Tehlar | 254b036 | 2016-04-07 10:04:34 +0200 | [diff] [blame] | 2216 | })); |
| 2217 | |
Filip Tehlar | 254b036 | 2016-04-07 10:04:34 +0200 | [diff] [blame] | 2218 | /* Add ipv6 locators */ |
| 2219 | foreach_ip_interface_address (&lcm->im6->lookup_main, ia, |
| 2220 | loc->sw_if_index, 1 /* unnumbered */, |
| 2221 | ({ |
Florin Coras | 1c49484 | 2016-06-16 21:08:56 +0200 | [diff] [blame] | 2222 | addr = ip_interface_address_get_address (&lcm->im6->lookup_main, ia); |
| 2223 | ip_address_set (rloc, addr, IP6); |
Florin Coras | ddfafb8 | 2016-05-13 18:09:56 +0200 | [diff] [blame] | 2224 | ip_prefix_len (ippref) = 128; |
Andrej Kozemcak | 438109d | 2016-07-22 12:54:12 +0200 | [diff] [blame] | 2225 | ip_prefix_normalize (ippref); |
Filip Tehlar | beceab9 | 2016-04-20 17:21:55 +0200 | [diff] [blame] | 2226 | vec_add1 (rlocs, gid[0]); |
Filip Tehlar | 254b036 | 2016-04-07 10:04:34 +0200 | [diff] [blame] | 2227 | })); |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2228 | /* *INDENT-ON* */ |
| 2229 | |
Filip Tehlar | 254b036 | 2016-04-07 10:04:34 +0200 | [diff] [blame] | 2230 | } |
| 2231 | return rlocs; |
| 2232 | } |
| 2233 | |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2234 | static vlib_buffer_t * |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 2235 | build_map_request (lisp_cp_main_t * lcm, gid_address_t * deid, |
| 2236 | ip_address_t * sloc, ip_address_t * rloc, |
| 2237 | gid_address_t * itr_rlocs, u64 * nonce_res, u32 * bi_res) |
| 2238 | { |
| 2239 | vlib_buffer_t *b; |
| 2240 | u32 bi; |
| 2241 | vlib_main_t *vm = lcm->vlib_main; |
| 2242 | |
| 2243 | if (vlib_buffer_alloc (vm, &bi, 1) != 1) |
| 2244 | { |
| 2245 | clib_warning ("Can't allocate buffer for Map-Request!"); |
| 2246 | return 0; |
| 2247 | } |
| 2248 | |
| 2249 | b = vlib_get_buffer (vm, bi); |
| 2250 | |
| 2251 | /* leave some space for the encap headers */ |
| 2252 | vlib_buffer_make_headroom (b, MAX_LISP_MSG_ENCAP_LEN); |
| 2253 | |
| 2254 | /* put lisp msg */ |
| 2255 | lisp_msg_put_mreq (lcm, b, NULL, deid, itr_rlocs, 0 /* smr invoked */ , |
| 2256 | 1 /* rloc probe */ , nonce_res); |
| 2257 | |
| 2258 | /* push outer ip header */ |
| 2259 | pkt_push_udp_and_ip (vm, b, LISP_CONTROL_PORT, LISP_CONTROL_PORT, sloc, |
Florin Coras | fdbc382 | 2017-07-27 00:34:12 -0700 | [diff] [blame^] | 2260 | rloc, 1); |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 2261 | |
| 2262 | bi_res[0] = bi; |
| 2263 | |
| 2264 | return b; |
| 2265 | } |
| 2266 | |
| 2267 | static vlib_buffer_t * |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2268 | build_encapsulated_map_request (lisp_cp_main_t * lcm, |
| 2269 | gid_address_t * seid, gid_address_t * deid, |
| 2270 | locator_set_t * loc_set, ip_address_t * mr_ip, |
| 2271 | ip_address_t * sloc, u8 is_smr_invoked, |
| 2272 | u64 * nonce_res, u32 * bi_res) |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2273 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2274 | vlib_buffer_t *b; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2275 | u32 bi; |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2276 | gid_address_t *rlocs = 0; |
| 2277 | vlib_main_t *vm = lcm->vlib_main; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2278 | |
| 2279 | if (vlib_buffer_alloc (vm, &bi, 1) != 1) |
| 2280 | { |
| 2281 | clib_warning ("Can't allocate buffer for Map-Request!"); |
| 2282 | return 0; |
| 2283 | } |
| 2284 | |
| 2285 | b = vlib_get_buffer (vm, bi); |
Florin Coras | fdbc382 | 2017-07-27 00:34:12 -0700 | [diff] [blame^] | 2286 | b->flags = 0; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2287 | |
| 2288 | /* leave some space for the encap headers */ |
| 2289 | vlib_buffer_make_headroom (b, MAX_LISP_MSG_ENCAP_LEN); |
| 2290 | |
Filip Tehlar | 254b036 | 2016-04-07 10:04:34 +0200 | [diff] [blame] | 2291 | /* get rlocs */ |
| 2292 | rlocs = build_itr_rloc_list (lcm, loc_set); |
| 2293 | |
Filip Tehlar | d5fcc46 | 2016-10-17 16:20:18 +0200 | [diff] [blame] | 2294 | if (MR_MODE_SRC_DST == lcm->map_request_mode |
| 2295 | && GID_ADDR_SRC_DST != gid_address_type (deid)) |
Florin Coras | dca8804 | 2016-09-14 16:01:38 +0200 | [diff] [blame] | 2296 | { |
| 2297 | gid_address_t sd; |
| 2298 | memset (&sd, 0, sizeof (sd)); |
| 2299 | build_src_dst (&sd, seid, deid); |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 2300 | lisp_msg_put_mreq (lcm, b, seid, &sd, rlocs, is_smr_invoked, |
| 2301 | 0 /* rloc probe */ , nonce_res); |
Florin Coras | dca8804 | 2016-09-14 16:01:38 +0200 | [diff] [blame] | 2302 | } |
| 2303 | else |
| 2304 | { |
| 2305 | /* put lisp msg */ |
| 2306 | lisp_msg_put_mreq (lcm, b, seid, deid, rlocs, is_smr_invoked, |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 2307 | 0 /* rloc probe */ , nonce_res); |
Florin Coras | dca8804 | 2016-09-14 16:01:38 +0200 | [diff] [blame] | 2308 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2309 | |
| 2310 | /* push ecm: udp-ip-lisp */ |
| 2311 | lisp_msg_push_ecm (vm, b, LISP_CONTROL_PORT, LISP_CONTROL_PORT, seid, deid); |
| 2312 | |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2313 | /* push outer ip header */ |
Florin Coras | ddfafb8 | 2016-05-13 18:09:56 +0200 | [diff] [blame] | 2314 | pkt_push_udp_and_ip (vm, b, LISP_CONTROL_PORT, LISP_CONTROL_PORT, sloc, |
Florin Coras | fdbc382 | 2017-07-27 00:34:12 -0700 | [diff] [blame^] | 2315 | mr_ip, 1); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2316 | |
| 2317 | bi_res[0] = bi; |
Filip Tehlar | 254b036 | 2016-04-07 10:04:34 +0200 | [diff] [blame] | 2318 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2319 | vec_free (rlocs); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2320 | return b; |
| 2321 | } |
| 2322 | |
| 2323 | static void |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 2324 | reset_pending_mr_counters (pending_map_request_t * r) |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2325 | { |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 2326 | r->time_to_expire = PENDING_MREQ_EXPIRATION_TIME; |
| 2327 | r->retries_num = 0; |
| 2328 | } |
| 2329 | |
| 2330 | static int |
| 2331 | elect_map_resolver (lisp_cp_main_t * lcm) |
| 2332 | { |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 2333 | lisp_msmr_t *mr; |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 2334 | |
| 2335 | vec_foreach (mr, lcm->map_resolvers) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2336 | { |
| 2337 | if (!mr->is_down) |
| 2338 | { |
| 2339 | ip_address_copy (&lcm->active_map_resolver, &mr->address); |
| 2340 | lcm->do_map_resolver_election = 0; |
| 2341 | return 1; |
| 2342 | } |
| 2343 | } |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 2344 | return 0; |
| 2345 | } |
| 2346 | |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 2347 | static void |
| 2348 | free_map_register_records (mapping_t * maps) |
| 2349 | { |
| 2350 | mapping_t *map; |
| 2351 | vec_foreach (map, maps) vec_free (map->locators); |
| 2352 | |
| 2353 | vec_free (maps); |
| 2354 | } |
| 2355 | |
| 2356 | static void |
| 2357 | add_locators (lisp_cp_main_t * lcm, mapping_t * m, u32 locator_set_index, |
| 2358 | ip_address_t * probed_loc) |
| 2359 | { |
| 2360 | u32 *li; |
| 2361 | locator_t *loc, new; |
| 2362 | ip_interface_address_t *ia = 0; |
| 2363 | void *addr; |
| 2364 | ip_address_t *new_ip = &gid_address_ip (&new.address); |
| 2365 | |
| 2366 | m->locators = 0; |
| 2367 | locator_set_t *ls = pool_elt_at_index (lcm->locator_set_pool, |
| 2368 | locator_set_index); |
| 2369 | vec_foreach (li, ls->locator_indices) |
| 2370 | { |
| 2371 | loc = pool_elt_at_index (lcm->locator_pool, li[0]); |
| 2372 | new = loc[0]; |
| 2373 | if (loc->local) |
| 2374 | { |
| 2375 | /* *INDENT-OFF* */ |
| 2376 | foreach_ip_interface_address (&lcm->im4->lookup_main, ia, |
| 2377 | loc->sw_if_index, 1 /* unnumbered */, |
| 2378 | ({ |
| 2379 | addr = ip_interface_address_get_address (&lcm->im4->lookup_main, |
| 2380 | ia); |
| 2381 | ip_address_set (new_ip, addr, IP4); |
| 2382 | })); |
| 2383 | |
| 2384 | /* Add ipv6 locators */ |
| 2385 | foreach_ip_interface_address (&lcm->im6->lookup_main, ia, |
| 2386 | loc->sw_if_index, 1 /* unnumbered */, |
| 2387 | ({ |
| 2388 | addr = ip_interface_address_get_address (&lcm->im6->lookup_main, |
| 2389 | ia); |
| 2390 | ip_address_set (new_ip, addr, IP6); |
| 2391 | })); |
| 2392 | /* *INDENT-ON* */ |
| 2393 | |
| 2394 | if (probed_loc && ip_address_cmp (probed_loc, new_ip) == 0) |
| 2395 | new.probed = 1; |
| 2396 | } |
| 2397 | vec_add1 (m->locators, new); |
| 2398 | } |
| 2399 | } |
| 2400 | |
| 2401 | static mapping_t * |
| 2402 | build_map_register_record_list (lisp_cp_main_t * lcm) |
| 2403 | { |
| 2404 | mapping_t *recs = 0, rec, *m; |
| 2405 | |
| 2406 | /* *INDENT-OFF* */ |
| 2407 | pool_foreach(m, lcm->mapping_pool, |
| 2408 | { |
| 2409 | /* for now build only local mappings */ |
| 2410 | if (!m->local) |
| 2411 | continue; |
| 2412 | |
| 2413 | rec = m[0]; |
| 2414 | add_locators (lcm, &rec, m->locator_set_index, NULL); |
| 2415 | vec_add1 (recs, rec); |
| 2416 | }); |
| 2417 | /* *INDENT-ON* */ |
| 2418 | |
| 2419 | return recs; |
| 2420 | } |
| 2421 | |
| 2422 | static int |
| 2423 | update_map_register_auth_data (map_register_hdr_t * map_reg_hdr, |
| 2424 | lisp_key_type_t key_id, u8 * key, |
| 2425 | u16 auth_data_len, u32 msg_len) |
| 2426 | { |
| 2427 | MREG_KEY_ID (map_reg_hdr) = clib_host_to_net_u16 (key_id); |
| 2428 | MREG_AUTH_DATA_LEN (map_reg_hdr) = clib_host_to_net_u16 (auth_data_len); |
| 2429 | |
| 2430 | unsigned char *result = HMAC (get_encrypt_fcn (key_id), key, vec_len (key), |
| 2431 | (unsigned char *) map_reg_hdr, msg_len, NULL, |
| 2432 | NULL); |
| 2433 | clib_memcpy (MREG_DATA (map_reg_hdr), result, auth_data_len); |
| 2434 | |
| 2435 | return 0; |
| 2436 | } |
| 2437 | |
| 2438 | static vlib_buffer_t * |
| 2439 | build_map_register (lisp_cp_main_t * lcm, ip_address_t * sloc, |
| 2440 | ip_address_t * ms_ip, u64 * nonce_res, u8 want_map_notif, |
| 2441 | mapping_t * records, lisp_key_type_t key_id, u8 * key, |
| 2442 | u32 * bi_res) |
| 2443 | { |
| 2444 | void *map_reg_hdr; |
| 2445 | vlib_buffer_t *b; |
| 2446 | u32 bi, auth_data_len = 0, msg_len = 0; |
| 2447 | vlib_main_t *vm = lcm->vlib_main; |
| 2448 | |
| 2449 | if (vlib_buffer_alloc (vm, &bi, 1) != 1) |
| 2450 | { |
| 2451 | clib_warning ("Can't allocate buffer for Map-Register!"); |
| 2452 | return 0; |
| 2453 | } |
| 2454 | |
| 2455 | b = vlib_get_buffer (vm, bi); |
| 2456 | |
| 2457 | /* leave some space for the encap headers */ |
| 2458 | vlib_buffer_make_headroom (b, MAX_LISP_MSG_ENCAP_LEN); |
| 2459 | |
| 2460 | auth_data_len = auth_data_len_by_key_id (key_id); |
| 2461 | map_reg_hdr = lisp_msg_put_map_register (b, records, want_map_notif, |
| 2462 | auth_data_len, nonce_res, |
| 2463 | &msg_len); |
| 2464 | |
| 2465 | update_map_register_auth_data (map_reg_hdr, key_id, key, auth_data_len, |
| 2466 | msg_len); |
| 2467 | |
| 2468 | /* push outer ip header */ |
| 2469 | pkt_push_udp_and_ip (vm, b, LISP_CONTROL_PORT, LISP_CONTROL_PORT, sloc, |
Florin Coras | fdbc382 | 2017-07-27 00:34:12 -0700 | [diff] [blame^] | 2470 | ms_ip, 1); |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 2471 | |
| 2472 | bi_res[0] = bi; |
| 2473 | return b; |
| 2474 | } |
| 2475 | |
| 2476 | static int |
| 2477 | get_egress_map_resolver_ip (lisp_cp_main_t * lcm, ip_address_t * ip) |
| 2478 | { |
| 2479 | lisp_msmr_t *mr; |
| 2480 | while (lcm->do_map_resolver_election |
| 2481 | | (0 == ip_fib_get_first_egress_ip_for_dst (lcm, |
| 2482 | &lcm->active_map_resolver, |
| 2483 | ip))) |
| 2484 | { |
| 2485 | if (0 == elect_map_resolver (lcm)) |
| 2486 | /* all map resolvers are down */ |
| 2487 | { |
| 2488 | /* restart MR checking by marking all of them up */ |
| 2489 | vec_foreach (mr, lcm->map_resolvers) mr->is_down = 0; |
| 2490 | return -1; |
| 2491 | } |
| 2492 | } |
| 2493 | return 0; |
| 2494 | } |
| 2495 | |
Filip Tehlar | cda7066 | 2017-01-16 10:30:03 +0100 | [diff] [blame] | 2496 | /* CP output statistics */ |
| 2497 | #define foreach_lisp_cp_output_error \ |
| 2498 | _(MAP_REGISTERS_SENT, "map-registers sent") \ |
| 2499 | _(RLOC_PROBES_SENT, "rloc-probes sent") |
| 2500 | |
| 2501 | static char *lisp_cp_output_error_strings[] = { |
| 2502 | #define _(sym,string) string, |
| 2503 | foreach_lisp_cp_output_error |
| 2504 | #undef _ |
| 2505 | }; |
| 2506 | |
| 2507 | typedef enum |
| 2508 | { |
| 2509 | #define _(sym,str) LISP_CP_OUTPUT_ERROR_##sym, |
| 2510 | foreach_lisp_cp_output_error |
| 2511 | #undef _ |
| 2512 | LISP_CP_OUTPUT_N_ERROR, |
| 2513 | } lisp_cp_output_error_t; |
| 2514 | |
| 2515 | static uword |
| 2516 | lisp_cp_output (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 2517 | vlib_frame_t * from_frame) |
| 2518 | { |
| 2519 | return 0; |
| 2520 | } |
| 2521 | |
| 2522 | /* dummy node used only for statistics */ |
| 2523 | /* *INDENT-OFF* */ |
| 2524 | VLIB_REGISTER_NODE (lisp_cp_output_node) = { |
| 2525 | .function = lisp_cp_output, |
| 2526 | .name = "lisp-cp-output", |
| 2527 | .vector_size = sizeof (u32), |
| 2528 | .format_trace = format_lisp_cp_input_trace, |
| 2529 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 2530 | |
| 2531 | .n_errors = LISP_CP_OUTPUT_N_ERROR, |
| 2532 | .error_strings = lisp_cp_output_error_strings, |
| 2533 | |
| 2534 | .n_next_nodes = LISP_CP_INPUT_N_NEXT, |
| 2535 | |
| 2536 | .next_nodes = { |
| 2537 | [LISP_CP_INPUT_NEXT_DROP] = "error-drop", |
| 2538 | }, |
| 2539 | }; |
| 2540 | /* *INDENT-ON* */ |
| 2541 | |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 2542 | static int |
| 2543 | send_rloc_probe (lisp_cp_main_t * lcm, gid_address_t * deid, |
| 2544 | u32 local_locator_set_index, ip_address_t * sloc, |
| 2545 | ip_address_t * rloc) |
| 2546 | { |
| 2547 | locator_set_t *ls; |
| 2548 | u32 bi; |
| 2549 | vlib_buffer_t *b; |
| 2550 | vlib_frame_t *f; |
| 2551 | u64 nonce = 0; |
| 2552 | u32 next_index, *to_next; |
| 2553 | gid_address_t *itr_rlocs; |
| 2554 | |
| 2555 | ls = pool_elt_at_index (lcm->locator_set_pool, local_locator_set_index); |
| 2556 | itr_rlocs = build_itr_rloc_list (lcm, ls); |
| 2557 | |
| 2558 | b = build_map_request (lcm, deid, sloc, rloc, itr_rlocs, &nonce, &bi); |
| 2559 | vec_free (itr_rlocs); |
| 2560 | if (!b) |
| 2561 | return -1; |
| 2562 | |
| 2563 | vnet_buffer (b)->sw_if_index[VLIB_TX] = 0; |
| 2564 | |
Filip Tehlar | 272c69e | 2017-02-15 16:40:35 +0100 | [diff] [blame] | 2565 | next_index = (ip_addr_version (rloc) == IP4) ? |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 2566 | ip4_lookup_node.index : ip6_lookup_node.index; |
| 2567 | |
| 2568 | f = vlib_get_frame_to_node (lcm->vlib_main, next_index); |
| 2569 | |
| 2570 | /* Enqueue the packet */ |
| 2571 | to_next = vlib_frame_vector_args (f); |
| 2572 | to_next[0] = bi; |
| 2573 | f->n_vectors = 1; |
| 2574 | vlib_put_frame_to_node (lcm->vlib_main, next_index, f); |
| 2575 | |
| 2576 | hash_set (lcm->map_register_messages_by_nonce, nonce, 0); |
| 2577 | return 0; |
| 2578 | } |
| 2579 | |
| 2580 | static int |
| 2581 | send_rloc_probes (lisp_cp_main_t * lcm) |
| 2582 | { |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 2583 | u8 lprio = 0; |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 2584 | mapping_t *lm; |
| 2585 | fwd_entry_t *e; |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 2586 | locator_pair_t *lp; |
Filip Tehlar | cda7066 | 2017-01-16 10:30:03 +0100 | [diff] [blame] | 2587 | u32 si, rloc_probes_sent = 0; |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 2588 | |
| 2589 | /* *INDENT-OFF* */ |
| 2590 | pool_foreach (e, lcm->fwd_entry_pool, |
| 2591 | { |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 2592 | if (vec_len (e->locator_pairs) == 0) |
| 2593 | continue; |
| 2594 | |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 2595 | si = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &e->leid); |
| 2596 | if (~0 == si) |
| 2597 | { |
| 2598 | clib_warning ("internal error: cannot find local eid %U in " |
| 2599 | "map-cache!", format_gid_address, &e->leid); |
| 2600 | continue; |
| 2601 | } |
| 2602 | lm = pool_elt_at_index (lcm->mapping_pool, si); |
| 2603 | |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 2604 | /* get the best (lowest) priority */ |
| 2605 | lprio = e->locator_pairs[0].priority; |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 2606 | |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 2607 | /* send rloc-probe for pair(s) with the best remote locator priority */ |
| 2608 | vec_foreach (lp, e->locator_pairs) |
| 2609 | { |
| 2610 | if (lp->priority != lprio) |
| 2611 | break; |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 2612 | |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 2613 | /* get first remote locator */ |
| 2614 | send_rloc_probe (lcm, &e->reid, lm->locator_set_index, &lp->lcl_loc, |
| 2615 | &lp->rmt_loc); |
Filip Tehlar | cda7066 | 2017-01-16 10:30:03 +0100 | [diff] [blame] | 2616 | rloc_probes_sent++; |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 2617 | } |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 2618 | }); |
| 2619 | /* *INDENT-ON* */ |
| 2620 | |
Filip Tehlar | cda7066 | 2017-01-16 10:30:03 +0100 | [diff] [blame] | 2621 | vlib_node_increment_counter (vlib_get_main (), lisp_cp_output_node.index, |
| 2622 | LISP_CP_OUTPUT_ERROR_RLOC_PROBES_SENT, |
| 2623 | rloc_probes_sent); |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 2624 | return 0; |
| 2625 | } |
| 2626 | |
| 2627 | static int |
| 2628 | send_map_register (lisp_cp_main_t * lcm, u8 want_map_notif) |
| 2629 | { |
Filip Tehlar | cda7066 | 2017-01-16 10:30:03 +0100 | [diff] [blame] | 2630 | u32 bi, map_registers_sent = 0; |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 2631 | vlib_buffer_t *b; |
| 2632 | ip_address_t sloc; |
| 2633 | vlib_frame_t *f; |
| 2634 | u64 nonce = 0; |
| 2635 | u32 next_index, *to_next; |
| 2636 | ip_address_t *ms = 0; |
Filip Tehlar | cf121c8 | 2017-05-03 10:12:44 +0200 | [diff] [blame] | 2637 | mapping_t *records, *r, *group, *k; |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 2638 | |
| 2639 | // TODO: support multiple map servers and do election |
| 2640 | if (0 == vec_len (lcm->map_servers)) |
| 2641 | return -1; |
| 2642 | |
| 2643 | ms = &lcm->map_servers[0].address; |
| 2644 | |
| 2645 | if (0 == ip_fib_get_first_egress_ip_for_dst (lcm, ms, &sloc)) |
| 2646 | { |
| 2647 | clib_warning ("no eligible interface address found for %U!", |
| 2648 | format_ip_address, &lcm->map_servers[0]); |
| 2649 | return -1; |
| 2650 | } |
| 2651 | |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 2652 | records = build_map_register_record_list (lcm); |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 2653 | if (!records) |
| 2654 | return -1; |
| 2655 | |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 2656 | vec_foreach (r, records) |
| 2657 | { |
| 2658 | u8 *key = r->key; |
| 2659 | u8 key_id = r->key_id; |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 2660 | |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 2661 | if (!key) |
| 2662 | continue; /* no secret key -> map-register cannot be sent */ |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 2663 | |
Filip Tehlar | cf121c8 | 2017-05-03 10:12:44 +0200 | [diff] [blame] | 2664 | group = 0; |
| 2665 | vec_add1 (group, r[0]); |
| 2666 | |
| 2667 | /* group mappings that share common key */ |
| 2668 | for (k = r + 1; k < vec_end (records); k++) |
| 2669 | { |
| 2670 | if (k->key_id != r->key_id) |
| 2671 | continue; |
| 2672 | |
| 2673 | if (vec_is_equal (k->key, r->key)) |
| 2674 | { |
| 2675 | vec_add1 (group, k[0]); |
| 2676 | k->key = 0; /* don't process this mapping again */ |
| 2677 | } |
| 2678 | } |
| 2679 | |
| 2680 | b = build_map_register (lcm, &sloc, ms, &nonce, want_map_notif, group, |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 2681 | key_id, key, &bi); |
Filip Tehlar | cf121c8 | 2017-05-03 10:12:44 +0200 | [diff] [blame] | 2682 | vec_free (group); |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 2683 | if (!b) |
| 2684 | continue; |
| 2685 | |
| 2686 | vnet_buffer (b)->sw_if_index[VLIB_TX] = 0; |
| 2687 | |
| 2688 | next_index = (ip_addr_version (&lcm->active_map_resolver) == IP4) ? |
| 2689 | ip4_lookup_node.index : ip6_lookup_node.index; |
| 2690 | |
| 2691 | f = vlib_get_frame_to_node (lcm->vlib_main, next_index); |
| 2692 | |
| 2693 | /* Enqueue the packet */ |
| 2694 | to_next = vlib_frame_vector_args (f); |
| 2695 | to_next[0] = bi; |
| 2696 | f->n_vectors = 1; |
| 2697 | vlib_put_frame_to_node (lcm->vlib_main, next_index, f); |
Filip Tehlar | cda7066 | 2017-01-16 10:30:03 +0100 | [diff] [blame] | 2698 | map_registers_sent++; |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 2699 | |
| 2700 | hash_set (lcm->map_register_messages_by_nonce, nonce, 0); |
| 2701 | } |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 2702 | free_map_register_records (records); |
| 2703 | |
Filip Tehlar | cda7066 | 2017-01-16 10:30:03 +0100 | [diff] [blame] | 2704 | vlib_node_increment_counter (vlib_get_main (), lisp_cp_output_node.index, |
| 2705 | LISP_CP_OUTPUT_ERROR_MAP_REGISTERS_SENT, |
| 2706 | map_registers_sent); |
| 2707 | |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 2708 | return 0; |
| 2709 | } |
| 2710 | |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 2711 | #define send_encapsulated_map_request(lcm, seid, deid, smr) \ |
| 2712 | _send_encapsulated_map_request(lcm, seid, deid, smr, 0) |
| 2713 | |
| 2714 | #define resend_encapsulated_map_request(lcm, seid, deid, smr) \ |
| 2715 | _send_encapsulated_map_request(lcm, seid, deid, smr, 1) |
| 2716 | |
| 2717 | static int |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2718 | _send_encapsulated_map_request (lisp_cp_main_t * lcm, |
| 2719 | gid_address_t * seid, gid_address_t * deid, |
| 2720 | u8 is_smr_invoked, u8 is_resend) |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 2721 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2722 | u32 next_index, bi = 0, *to_next, map_index; |
| 2723 | vlib_buffer_t *b; |
| 2724 | vlib_frame_t *f; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2725 | u64 nonce = 0; |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2726 | locator_set_t *loc_set; |
| 2727 | mapping_t *map; |
| 2728 | pending_map_request_t *pmr, *duplicate_pmr = 0; |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 2729 | ip_address_t sloc; |
Andrej Kozemcak | b6e4d39 | 2016-06-14 13:55:57 +0200 | [diff] [blame] | 2730 | u32 ls_index; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2731 | |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 2732 | /* if there is already a pending request remember it */ |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2733 | |
| 2734 | /* *INDENT-OFF* */ |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 2735 | pool_foreach(pmr, lcm->pending_map_requests_pool, |
| 2736 | ({ |
| 2737 | if (!gid_address_cmp (&pmr->src, seid) |
| 2738 | && !gid_address_cmp (&pmr->dst, deid)) |
| 2739 | { |
| 2740 | duplicate_pmr = pmr; |
| 2741 | break; |
| 2742 | } |
| 2743 | })); |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2744 | /* *INDENT-ON* */ |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 2745 | |
| 2746 | if (!is_resend && duplicate_pmr) |
| 2747 | { |
| 2748 | /* don't send the request if there is a pending map request already */ |
| 2749 | return 0; |
| 2750 | } |
| 2751 | |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2752 | /* get locator-set for seid */ |
Filip Tehlar | ef2a5bf | 2017-05-30 07:14:46 +0200 | [diff] [blame] | 2753 | if (!lcm->lisp_pitr && gid_address_type (deid) != GID_ADDR_NSH) |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2754 | { |
Filip Tehlar | 53f09e3 | 2016-05-19 14:25:44 +0200 | [diff] [blame] | 2755 | map_index = gid_dictionary_lookup (&lcm->mapping_index_by_gid, seid); |
| 2756 | if (map_index == ~0) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2757 | { |
| 2758 | clib_warning ("No local mapping found in eid-table for %U!", |
| 2759 | format_gid_address, seid); |
| 2760 | return -1; |
| 2761 | } |
Filip Tehlar | 53f09e3 | 2016-05-19 14:25:44 +0200 | [diff] [blame] | 2762 | |
| 2763 | map = pool_elt_at_index (lcm->mapping_pool, map_index); |
| 2764 | |
| 2765 | if (!map->local) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2766 | { |
| 2767 | clib_warning |
| 2768 | ("Mapping found for src eid %U is not marked as local!", |
| 2769 | format_gid_address, seid); |
| 2770 | return -1; |
| 2771 | } |
Andrej Kozemcak | b6e4d39 | 2016-06-14 13:55:57 +0200 | [diff] [blame] | 2772 | ls_index = map->locator_set_index; |
Filip Tehlar | 53f09e3 | 2016-05-19 14:25:44 +0200 | [diff] [blame] | 2773 | } |
| 2774 | else |
| 2775 | { |
Filip Tehlar | ef2a5bf | 2017-05-30 07:14:46 +0200 | [diff] [blame] | 2776 | if (lcm->lisp_pitr) |
| 2777 | { |
| 2778 | map = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index); |
| 2779 | ls_index = map->locator_set_index; |
| 2780 | } |
| 2781 | else |
| 2782 | { |
| 2783 | if (lcm->nsh_map_index == (u32) ~ 0) |
| 2784 | { |
| 2785 | clib_warning ("No locator-set defined for NSH!"); |
| 2786 | return -1; |
| 2787 | } |
| 2788 | else |
| 2789 | { |
| 2790 | map = pool_elt_at_index (lcm->mapping_pool, lcm->nsh_map_index); |
| 2791 | ls_index = map->locator_set_index; |
| 2792 | } |
| 2793 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2794 | } |
| 2795 | |
Andrej Kozemcak | b6e4d39 | 2016-06-14 13:55:57 +0200 | [diff] [blame] | 2796 | /* overwrite locator set if map-request itr-rlocs configured */ |
| 2797 | if (~0 != lcm->mreq_itr_rlocs) |
| 2798 | { |
| 2799 | ls_index = lcm->mreq_itr_rlocs; |
| 2800 | } |
| 2801 | |
| 2802 | loc_set = pool_elt_at_index (lcm->locator_set_pool, ls_index); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2803 | |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 2804 | if (get_egress_map_resolver_ip (lcm, &sloc) < 0) |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 2805 | { |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 2806 | if (duplicate_pmr) |
| 2807 | duplicate_pmr->to_be_removed = 1; |
| 2808 | return -1; |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 2809 | } |
Florin Coras | ddfafb8 | 2016-05-13 18:09:56 +0200 | [diff] [blame] | 2810 | |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2811 | /* build the encapsulated map request */ |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 2812 | b = build_encapsulated_map_request (lcm, seid, deid, loc_set, |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2813 | &lcm->active_map_resolver, |
| 2814 | &sloc, is_smr_invoked, &nonce, &bi); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2815 | |
| 2816 | if (!b) |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 2817 | return -1; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2818 | |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 2819 | /* set fib index to default and lookup node */ |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2820 | vnet_buffer (b)->sw_if_index[VLIB_TX] = 0; |
| 2821 | next_index = (ip_addr_version (&lcm->active_map_resolver) == IP4) ? |
| 2822 | ip4_lookup_node.index : ip6_lookup_node.index; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2823 | |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 2824 | f = vlib_get_frame_to_node (lcm->vlib_main, next_index); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2825 | |
| 2826 | /* Enqueue the packet */ |
| 2827 | to_next = vlib_frame_vector_args (f); |
| 2828 | to_next[0] = bi; |
| 2829 | f->n_vectors = 1; |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 2830 | vlib_put_frame_to_node (lcm->vlib_main, next_index, f); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2831 | |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 2832 | if (duplicate_pmr) |
| 2833 | /* if there is a pending request already update it */ |
| 2834 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2835 | if (clib_fifo_elts (duplicate_pmr->nonces) >= PENDING_MREQ_QUEUE_LEN) |
| 2836 | { |
| 2837 | /* remove the oldest nonce */ |
| 2838 | u64 CLIB_UNUSED (tmp), *nonce_del; |
| 2839 | nonce_del = clib_fifo_head (duplicate_pmr->nonces); |
| 2840 | hash_unset (lcm->pending_map_requests_by_nonce, nonce_del[0]); |
| 2841 | clib_fifo_sub1 (duplicate_pmr->nonces, tmp); |
| 2842 | } |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 2843 | |
Florin Coras | f4691cd | 2016-08-15 19:16:32 +0200 | [diff] [blame] | 2844 | clib_fifo_add1 (duplicate_pmr->nonces, nonce); |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 2845 | hash_set (lcm->pending_map_requests_by_nonce, nonce, |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2846 | duplicate_pmr - lcm->pending_map_requests_pool); |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 2847 | } |
| 2848 | else |
| 2849 | { |
| 2850 | /* add map-request to pending requests table */ |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2851 | pool_get (lcm->pending_map_requests_pool, pmr); |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 2852 | memset (pmr, 0, sizeof (*pmr)); |
| 2853 | gid_address_copy (&pmr->src, seid); |
| 2854 | gid_address_copy (&pmr->dst, deid); |
Florin Coras | f4691cd | 2016-08-15 19:16:32 +0200 | [diff] [blame] | 2855 | clib_fifo_add1 (pmr->nonces, nonce); |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 2856 | pmr->is_smr_invoked = is_smr_invoked; |
| 2857 | reset_pending_mr_counters (pmr); |
| 2858 | hash_set (lcm->pending_map_requests_by_nonce, nonce, |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2859 | pmr - lcm->pending_map_requests_pool); |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 2860 | } |
| 2861 | |
| 2862 | return 0; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2863 | } |
| 2864 | |
| 2865 | static void |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2866 | get_src_and_dst_ip (void *hdr, ip_address_t * src, ip_address_t * dst) |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2867 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2868 | ip4_header_t *ip4 = hdr; |
| 2869 | ip6_header_t *ip6; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2870 | |
| 2871 | if ((ip4->ip_version_and_header_length & 0xF0) == 0x40) |
| 2872 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2873 | ip_address_set (src, &ip4->src_address, IP4); |
| 2874 | ip_address_set (dst, &ip4->dst_address, IP4); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2875 | } |
| 2876 | else |
| 2877 | { |
| 2878 | ip6 = hdr; |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2879 | ip_address_set (src, &ip6->src_address, IP6); |
| 2880 | ip_address_set (dst, &ip6->dst_address, IP6); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2881 | } |
| 2882 | } |
| 2883 | |
Filip Tehlar | 324112f | 2016-06-02 16:07:38 +0200 | [diff] [blame] | 2884 | static u32 |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 2885 | lisp_get_vni_from_buffer_ip (lisp_cp_main_t * lcm, vlib_buffer_t * b, |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2886 | u8 version) |
Filip Tehlar | 324112f | 2016-06-02 16:07:38 +0200 | [diff] [blame] | 2887 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2888 | uword *vnip; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2889 | u32 vni = ~0, table_id = ~0; |
Filip Tehlar | 324112f | 2016-06-02 16:07:38 +0200 | [diff] [blame] | 2890 | |
Florin Coras | 87e4069 | 2016-09-22 18:02:17 +0200 | [diff] [blame] | 2891 | table_id = fib_table_get_table_id_for_sw_if_index ((version == |
| 2892 | IP4 ? FIB_PROTOCOL_IP4 : |
| 2893 | FIB_PROTOCOL_IP6), |
| 2894 | vnet_buffer |
| 2895 | (b)->sw_if_index |
| 2896 | [VLIB_RX]); |
Filip Tehlar | 324112f | 2016-06-02 16:07:38 +0200 | [diff] [blame] | 2897 | |
| 2898 | vnip = hash_get (lcm->vni_by_table_id, table_id); |
| 2899 | if (vnip) |
| 2900 | vni = vnip[0]; |
| 2901 | else |
| 2902 | clib_warning ("vrf %d is not mapped to any vni!", table_id); |
| 2903 | |
| 2904 | return vni; |
| 2905 | } |
| 2906 | |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 2907 | always_inline u32 |
Filip Tehlar | d5a65db | 2017-05-17 17:21:10 +0200 | [diff] [blame] | 2908 | lisp_get_bd_from_buffer_eth (vlib_buffer_t * b) |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 2909 | { |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 2910 | u32 sw_if_index0; |
| 2911 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2912 | l2input_main_t *l2im = &l2input_main; |
| 2913 | l2_input_config_t *config; |
| 2914 | l2_bridge_domain_t *bd_config; |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 2915 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2916 | sw_if_index0 = vnet_buffer (b)->sw_if_index[VLIB_RX]; |
| 2917 | config = vec_elt_at_index (l2im->configs, sw_if_index0); |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 2918 | bd_config = vec_elt_at_index (l2im->bd_configs, config->bd_index); |
| 2919 | |
Filip Tehlar | d5a65db | 2017-05-17 17:21:10 +0200 | [diff] [blame] | 2920 | return bd_config->bd_id; |
| 2921 | } |
| 2922 | |
| 2923 | always_inline u32 |
| 2924 | lisp_get_vni_from_buffer_eth (lisp_cp_main_t * lcm, vlib_buffer_t * b) |
| 2925 | { |
| 2926 | uword *vnip; |
| 2927 | u32 vni = ~0; |
| 2928 | u32 bd = lisp_get_bd_from_buffer_eth (b); |
| 2929 | |
| 2930 | vnip = hash_get (lcm->vni_by_bd_id, bd); |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 2931 | if (vnip) |
| 2932 | vni = vnip[0]; |
| 2933 | else |
Filip Tehlar | d5a65db | 2017-05-17 17:21:10 +0200 | [diff] [blame] | 2934 | clib_warning ("bridge domain %d is not mapped to any vni!", bd); |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 2935 | |
| 2936 | return vni; |
| 2937 | } |
| 2938 | |
Filip Tehlar | 4868ff6 | 2017-03-09 16:48:39 +0100 | [diff] [blame] | 2939 | void |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2940 | get_src_and_dst_eids_from_buffer (lisp_cp_main_t * lcm, vlib_buffer_t * b, |
Filip Tehlar | 4868ff6 | 2017-03-09 16:48:39 +0100 | [diff] [blame] | 2941 | gid_address_t * src, gid_address_t * dst, |
| 2942 | u16 type) |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 2943 | { |
Filip Tehlar | ef2a5bf | 2017-05-30 07:14:46 +0200 | [diff] [blame] | 2944 | ethernet_header_t *eh; |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 2945 | u32 vni = 0; |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 2946 | |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 2947 | memset (src, 0, sizeof (*src)); |
| 2948 | memset (dst, 0, sizeof (*dst)); |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 2949 | |
Filip Tehlar | d5a65db | 2017-05-17 17:21:10 +0200 | [diff] [blame] | 2950 | gid_address_type (dst) = GID_ADDR_NO_ADDRESS; |
| 2951 | gid_address_type (src) = GID_ADDR_NO_ADDRESS; |
| 2952 | |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 2953 | if (LISP_AFI_IP == type || LISP_AFI_IP6 == type) |
| 2954 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2955 | ip4_header_t *ip; |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 2956 | u8 version, preflen; |
| 2957 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2958 | gid_address_type (src) = GID_ADDR_IP_PREFIX; |
| 2959 | gid_address_type (dst) = GID_ADDR_IP_PREFIX; |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 2960 | |
| 2961 | ip = vlib_buffer_get_current (b); |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2962 | get_src_and_dst_ip (ip, &gid_address_ip (src), &gid_address_ip (dst)); |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 2963 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2964 | version = gid_address_ip_version (src); |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 2965 | preflen = ip_address_max_len (version); |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 2966 | gid_address_ippref_len (src) = preflen; |
| 2967 | gid_address_ippref_len (dst) = preflen; |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 2968 | |
| 2969 | vni = lisp_get_vni_from_buffer_ip (lcm, b, version); |
| 2970 | gid_address_vni (dst) = vni; |
| 2971 | gid_address_vni (src) = vni; |
| 2972 | } |
| 2973 | else if (LISP_AFI_MAC == type) |
| 2974 | { |
Filip Tehlar | d5a65db | 2017-05-17 17:21:10 +0200 | [diff] [blame] | 2975 | ethernet_arp_header_t *ah; |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 2976 | |
| 2977 | eh = vlib_buffer_get_current (b); |
| 2978 | |
Filip Tehlar | d5a65db | 2017-05-17 17:21:10 +0200 | [diff] [blame] | 2979 | if (clib_net_to_host_u16 (eh->type) == ETHERNET_TYPE_ARP) |
| 2980 | { |
| 2981 | ah = (ethernet_arp_header_t *) (((u8 *) eh) + sizeof (*eh)); |
| 2982 | if (clib_net_to_host_u16 (ah->opcode) |
| 2983 | != ETHERNET_ARP_OPCODE_request) |
| 2984 | return; |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 2985 | |
Filip Tehlar | d5a65db | 2017-05-17 17:21:10 +0200 | [diff] [blame] | 2986 | gid_address_type (dst) = GID_ADDR_ARP; |
| 2987 | gid_address_arp_bd (dst) = lisp_get_bd_from_buffer_eth (b); |
| 2988 | clib_memcpy (&gid_address_arp_ip4 (dst), |
| 2989 | &ah->ip4_over_ethernet[1].ip4, 4); |
| 2990 | } |
| 2991 | else |
| 2992 | { |
| 2993 | gid_address_type (src) = GID_ADDR_MAC; |
| 2994 | gid_address_type (dst) = GID_ADDR_MAC; |
| 2995 | mac_copy (&gid_address_mac (src), eh->src_address); |
| 2996 | mac_copy (&gid_address_mac (dst), eh->dst_address); |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 2997 | |
Filip Tehlar | d5a65db | 2017-05-17 17:21:10 +0200 | [diff] [blame] | 2998 | /* get vni */ |
| 2999 | vni = lisp_get_vni_from_buffer_eth (lcm, b); |
| 3000 | |
| 3001 | gid_address_vni (dst) = vni; |
| 3002 | gid_address_vni (src) = vni; |
| 3003 | } |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 3004 | } |
Florin Coras | ce1b4c7 | 2017-01-26 14:25:34 -0800 | [diff] [blame] | 3005 | else if (LISP_AFI_LCAF == type) |
| 3006 | { |
Filip Tehlar | ef2a5bf | 2017-05-30 07:14:46 +0200 | [diff] [blame] | 3007 | lisp_nsh_hdr_t *nh; |
| 3008 | eh = vlib_buffer_get_current (b); |
| 3009 | |
| 3010 | if (clib_net_to_host_u16 (eh->type) == ETHERNET_TYPE_NSH) |
| 3011 | { |
| 3012 | nh = (lisp_nsh_hdr_t *) (((u8 *) eh) + sizeof (*eh)); |
| 3013 | u32 spi = clib_net_to_host_u32 (nh->spi_si << 8); |
| 3014 | u8 si = (u8) clib_net_to_host_u32 (nh->spi_si); |
| 3015 | gid_address_nsh_spi (dst) = spi; |
| 3016 | gid_address_nsh_si (dst) = si; |
| 3017 | |
| 3018 | gid_address_type (dst) = GID_ADDR_NSH; |
| 3019 | } |
Florin Coras | ce1b4c7 | 2017-01-26 14:25:34 -0800 | [diff] [blame] | 3020 | } |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 3021 | } |
| 3022 | |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3023 | static uword |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3024 | lisp_cp_lookup_inline (vlib_main_t * vm, |
| 3025 | vlib_node_runtime_t * node, |
| 3026 | vlib_frame_t * from_frame, int overlay) |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3027 | { |
Filip Tehlar | d5a65db | 2017-05-17 17:21:10 +0200 | [diff] [blame] | 3028 | u32 *from, *to_next, di, si; |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3029 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
Filip Tehlar | d5a65db | 2017-05-17 17:21:10 +0200 | [diff] [blame] | 3030 | u32 pkts_mapped = 0, next_index; |
| 3031 | uword n_left_from, n_left_to_next; |
| 3032 | vnet_main_t *vnm = vnet_get_main (); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3033 | |
| 3034 | from = vlib_frame_vector_args (from_frame); |
| 3035 | n_left_from = from_frame->n_vectors; |
Filip Tehlar | d5a65db | 2017-05-17 17:21:10 +0200 | [diff] [blame] | 3036 | next_index = node->cached_next_index; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3037 | |
| 3038 | while (n_left_from > 0) |
| 3039 | { |
Filip Tehlar | d5a65db | 2017-05-17 17:21:10 +0200 | [diff] [blame] | 3040 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3041 | |
Filip Tehlar | d5a65db | 2017-05-17 17:21:10 +0200 | [diff] [blame] | 3042 | while (n_left_from > 0 && n_left_to_next > 0) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3043 | { |
Filip Tehlar | d5a65db | 2017-05-17 17:21:10 +0200 | [diff] [blame] | 3044 | u32 pi0, sw_if_index0, next0; |
| 3045 | u64 mac0; |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3046 | vlib_buffer_t *b0; |
| 3047 | gid_address_t src, dst; |
Filip Tehlar | d5a65db | 2017-05-17 17:21:10 +0200 | [diff] [blame] | 3048 | ethernet_arp_header_t *arp0; |
| 3049 | ethernet_header_t *eth0; |
| 3050 | vnet_hw_interface_t *hw_if0; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3051 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3052 | pi0 = from[0]; |
| 3053 | from += 1; |
| 3054 | n_left_from -= 1; |
Filip Tehlar | d5a65db | 2017-05-17 17:21:10 +0200 | [diff] [blame] | 3055 | to_next[0] = pi0; |
| 3056 | to_next += 1; |
| 3057 | n_left_to_next -= 1; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3058 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3059 | b0 = vlib_get_buffer (vm, pi0); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3060 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3061 | /* src/dst eid pair */ |
Filip Tehlar | 4868ff6 | 2017-03-09 16:48:39 +0100 | [diff] [blame] | 3062 | get_src_and_dst_eids_from_buffer (lcm, b0, &src, &dst, overlay); |
Filip Tehlar | 324112f | 2016-06-02 16:07:38 +0200 | [diff] [blame] | 3063 | |
Filip Tehlar | d5a65db | 2017-05-17 17:21:10 +0200 | [diff] [blame] | 3064 | if (gid_address_type (&dst) == GID_ADDR_ARP) |
| 3065 | { |
| 3066 | mac0 = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &dst); |
| 3067 | if (GID_LOOKUP_MISS_L2 != mac0) |
| 3068 | { |
| 3069 | /* send ARP reply */ |
| 3070 | |
| 3071 | sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX]; |
| 3072 | vnet_buffer (b0)->sw_if_index[VLIB_TX] = sw_if_index0; |
| 3073 | |
| 3074 | hw_if0 = vnet_get_sup_hw_interface (vnm, sw_if_index0); |
| 3075 | |
| 3076 | eth0 = vlib_buffer_get_current (b0); |
| 3077 | arp0 = (ethernet_arp_header_t *) (((u8 *) eth0) |
| 3078 | + sizeof (*eth0)); |
| 3079 | arp0->opcode = |
| 3080 | clib_host_to_net_u16 (ETHERNET_ARP_OPCODE_reply); |
| 3081 | arp0->ip4_over_ethernet[1] = arp0->ip4_over_ethernet[0]; |
| 3082 | clib_memcpy (arp0->ip4_over_ethernet[0].ethernet, |
| 3083 | (u8 *) & mac0, 6); |
| 3084 | clib_memcpy (&arp0->ip4_over_ethernet[0].ip4, |
| 3085 | &gid_address_arp_ip4 (&dst), 4); |
| 3086 | |
| 3087 | /* Hardware must be ethernet-like. */ |
| 3088 | ASSERT (vec_len (hw_if0->hw_address) == 6); |
| 3089 | |
| 3090 | clib_memcpy (eth0->dst_address, eth0->src_address, 6); |
| 3091 | clib_memcpy (eth0->src_address, hw_if0->hw_address, 6); |
| 3092 | |
| 3093 | b0->error = node->errors[LISP_CP_LOOKUP_ERROR_ARP_REPLY_TX]; |
| 3094 | next0 = LISP_CP_LOOKUP_NEXT_ARP_REPLY_TX; |
| 3095 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 3096 | to_next, |
| 3097 | n_left_to_next, pi0, |
| 3098 | next0); |
| 3099 | } |
| 3100 | continue; |
| 3101 | } |
| 3102 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3103 | /* if we have remote mapping for destination already in map-chache |
| 3104 | add forwarding tunnel directly. If not send a map-request */ |
Florin Coras | dca8804 | 2016-09-14 16:01:38 +0200 | [diff] [blame] | 3105 | di = gid_dictionary_sd_lookup (&lcm->mapping_index_by_gid, &dst, |
| 3106 | &src); |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3107 | if (~0 != di) |
| 3108 | { |
| 3109 | mapping_t *m = vec_elt_at_index (lcm->mapping_pool, di); |
| 3110 | /* send a map-request also in case of negative mapping entry |
| 3111 | with corresponding action */ |
| 3112 | if (m->action == LISP_SEND_MAP_REQUEST) |
| 3113 | { |
| 3114 | /* send map-request */ |
| 3115 | queue_map_request (&src, &dst, 0 /* smr_invoked */ , |
| 3116 | 0 /* is_resend */ ); |
| 3117 | pkts_mapped++; |
| 3118 | } |
| 3119 | else |
| 3120 | { |
Filip Tehlar | ef2a5bf | 2017-05-30 07:14:46 +0200 | [diff] [blame] | 3121 | if (GID_ADDR_NSH != gid_address_type (&dst)) |
| 3122 | { |
| 3123 | si = gid_dictionary_lookup (&lcm->mapping_index_by_gid, |
| 3124 | &src); |
| 3125 | } |
| 3126 | else |
| 3127 | si = lcm->nsh_map_index; |
| 3128 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3129 | if (~0 != si) |
| 3130 | { |
Filip Tehlar | ce1aae4 | 2017-01-04 10:42:25 +0100 | [diff] [blame] | 3131 | dp_add_fwd_entry_from_mt (si, di); |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3132 | } |
| 3133 | } |
| 3134 | } |
| 3135 | else |
| 3136 | { |
| 3137 | /* send map-request */ |
| 3138 | queue_map_request (&src, &dst, 0 /* smr_invoked */ , |
| 3139 | 0 /* is_resend */ ); |
| 3140 | pkts_mapped++; |
| 3141 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3142 | |
Filip Tehlar | d5a65db | 2017-05-17 17:21:10 +0200 | [diff] [blame] | 3143 | b0->error = node->errors[LISP_CP_LOOKUP_ERROR_DROP]; |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3144 | if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 3145 | { |
| 3146 | lisp_cp_lookup_trace_t *tr = vlib_add_trace (vm, node, b0, |
| 3147 | sizeof (*tr)); |
Andrej Kozemcak | 94e3476 | 2016-05-25 12:43:21 +0200 | [diff] [blame] | 3148 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3149 | memset (tr, 0, sizeof (*tr)); |
| 3150 | gid_address_copy (&tr->dst_eid, &dst); |
Florin Coras | 5a1c11b | 2016-09-06 16:29:34 +0200 | [diff] [blame] | 3151 | ip_address_copy (&tr->map_resolver_ip, |
| 3152 | &lcm->active_map_resolver); |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3153 | } |
| 3154 | gid_address_free (&dst); |
| 3155 | gid_address_free (&src); |
Filip Tehlar | d5a65db | 2017-05-17 17:21:10 +0200 | [diff] [blame] | 3156 | next0 = LISP_CP_LOOKUP_NEXT_DROP; |
| 3157 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 3158 | to_next, |
| 3159 | n_left_to_next, pi0, next0); |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3160 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3161 | |
Filip Tehlar | d5a65db | 2017-05-17 17:21:10 +0200 | [diff] [blame] | 3162 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3163 | } |
| 3164 | vlib_node_increment_counter (vm, node->node_index, |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3165 | LISP_CP_LOOKUP_ERROR_MAP_REQUESTS_SENT, |
| 3166 | pkts_mapped); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3167 | return from_frame->n_vectors; |
| 3168 | } |
| 3169 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3170 | static uword |
| 3171 | lisp_cp_lookup_ip4 (vlib_main_t * vm, |
| 3172 | vlib_node_runtime_t * node, vlib_frame_t * from_frame) |
| 3173 | { |
| 3174 | return (lisp_cp_lookup_inline (vm, node, from_frame, LISP_AFI_IP)); |
| 3175 | } |
| 3176 | |
| 3177 | static uword |
| 3178 | lisp_cp_lookup_ip6 (vlib_main_t * vm, |
| 3179 | vlib_node_runtime_t * node, vlib_frame_t * from_frame) |
| 3180 | { |
| 3181 | return (lisp_cp_lookup_inline (vm, node, from_frame, LISP_AFI_IP6)); |
| 3182 | } |
| 3183 | |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 3184 | static uword |
| 3185 | lisp_cp_lookup_l2 (vlib_main_t * vm, |
| 3186 | vlib_node_runtime_t * node, vlib_frame_t * from_frame) |
| 3187 | { |
| 3188 | return (lisp_cp_lookup_inline (vm, node, from_frame, LISP_AFI_MAC)); |
| 3189 | } |
| 3190 | |
Florin Coras | ce1b4c7 | 2017-01-26 14:25:34 -0800 | [diff] [blame] | 3191 | static uword |
| 3192 | lisp_cp_lookup_nsh (vlib_main_t * vm, |
| 3193 | vlib_node_runtime_t * node, vlib_frame_t * from_frame) |
| 3194 | { |
| 3195 | /* TODO decide if NSH should be propagated as LCAF or not */ |
| 3196 | return (lisp_cp_lookup_inline (vm, node, from_frame, LISP_AFI_LCAF)); |
| 3197 | } |
| 3198 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3199 | /* *INDENT-OFF* */ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3200 | VLIB_REGISTER_NODE (lisp_cp_lookup_ip4_node) = { |
| 3201 | .function = lisp_cp_lookup_ip4, |
| 3202 | .name = "lisp-cp-lookup-ip4", |
| 3203 | .vector_size = sizeof (u32), |
| 3204 | .format_trace = format_lisp_cp_lookup_trace, |
| 3205 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 3206 | |
| 3207 | .n_errors = LISP_CP_LOOKUP_N_ERROR, |
| 3208 | .error_strings = lisp_cp_lookup_error_strings, |
| 3209 | |
| 3210 | .n_next_nodes = LISP_CP_LOOKUP_N_NEXT, |
| 3211 | |
| 3212 | .next_nodes = { |
| 3213 | [LISP_CP_LOOKUP_NEXT_DROP] = "error-drop", |
Filip Tehlar | d5a65db | 2017-05-17 17:21:10 +0200 | [diff] [blame] | 3214 | [LISP_CP_LOOKUP_NEXT_ARP_REPLY_TX] = "interface-output", |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3215 | }, |
| 3216 | }; |
| 3217 | /* *INDENT-ON* */ |
| 3218 | |
| 3219 | /* *INDENT-OFF* */ |
| 3220 | VLIB_REGISTER_NODE (lisp_cp_lookup_ip6_node) = { |
| 3221 | .function = lisp_cp_lookup_ip6, |
| 3222 | .name = "lisp-cp-lookup-ip6", |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3223 | .vector_size = sizeof (u32), |
| 3224 | .format_trace = format_lisp_cp_lookup_trace, |
| 3225 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 3226 | |
| 3227 | .n_errors = LISP_CP_LOOKUP_N_ERROR, |
| 3228 | .error_strings = lisp_cp_lookup_error_strings, |
| 3229 | |
| 3230 | .n_next_nodes = LISP_CP_LOOKUP_N_NEXT, |
| 3231 | |
| 3232 | .next_nodes = { |
| 3233 | [LISP_CP_LOOKUP_NEXT_DROP] = "error-drop", |
Filip Tehlar | d5a65db | 2017-05-17 17:21:10 +0200 | [diff] [blame] | 3234 | [LISP_CP_LOOKUP_NEXT_ARP_REPLY_TX] = "interface-output", |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 3235 | }, |
| 3236 | }; |
| 3237 | /* *INDENT-ON* */ |
| 3238 | |
| 3239 | /* *INDENT-OFF* */ |
| 3240 | VLIB_REGISTER_NODE (lisp_cp_lookup_l2_node) = { |
| 3241 | .function = lisp_cp_lookup_l2, |
| 3242 | .name = "lisp-cp-lookup-l2", |
| 3243 | .vector_size = sizeof (u32), |
| 3244 | .format_trace = format_lisp_cp_lookup_trace, |
| 3245 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 3246 | |
| 3247 | .n_errors = LISP_CP_LOOKUP_N_ERROR, |
| 3248 | .error_strings = lisp_cp_lookup_error_strings, |
| 3249 | |
| 3250 | .n_next_nodes = LISP_CP_LOOKUP_N_NEXT, |
| 3251 | |
| 3252 | .next_nodes = { |
| 3253 | [LISP_CP_LOOKUP_NEXT_DROP] = "error-drop", |
Filip Tehlar | d5a65db | 2017-05-17 17:21:10 +0200 | [diff] [blame] | 3254 | [LISP_CP_LOOKUP_NEXT_ARP_REPLY_TX] = "interface-output", |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3255 | }, |
| 3256 | }; |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3257 | /* *INDENT-ON* */ |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3258 | |
Florin Coras | ce1b4c7 | 2017-01-26 14:25:34 -0800 | [diff] [blame] | 3259 | /* *INDENT-OFF* */ |
| 3260 | VLIB_REGISTER_NODE (lisp_cp_lookup_nsh_node) = { |
| 3261 | .function = lisp_cp_lookup_nsh, |
| 3262 | .name = "lisp-cp-lookup-nsh", |
| 3263 | .vector_size = sizeof (u32), |
| 3264 | .format_trace = format_lisp_cp_lookup_trace, |
| 3265 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 3266 | |
| 3267 | .n_errors = LISP_CP_LOOKUP_N_ERROR, |
| 3268 | .error_strings = lisp_cp_lookup_error_strings, |
| 3269 | |
| 3270 | .n_next_nodes = LISP_CP_LOOKUP_N_NEXT, |
| 3271 | |
| 3272 | .next_nodes = { |
| 3273 | [LISP_CP_LOOKUP_NEXT_DROP] = "error-drop", |
Filip Tehlar | d5a65db | 2017-05-17 17:21:10 +0200 | [diff] [blame] | 3274 | [LISP_CP_LOOKUP_NEXT_ARP_REPLY_TX] = "interface-output", |
Florin Coras | ce1b4c7 | 2017-01-26 14:25:34 -0800 | [diff] [blame] | 3275 | }, |
| 3276 | }; |
| 3277 | /* *INDENT-ON* */ |
| 3278 | |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3279 | /* lisp_cp_input statistics */ |
Filip Tehlar | cda7066 | 2017-01-16 10:30:03 +0100 | [diff] [blame] | 3280 | #define foreach_lisp_cp_input_error \ |
| 3281 | _(DROP, "drop") \ |
| 3282 | _(RLOC_PROBE_REQ_RECEIVED, "rloc-probe requests received") \ |
| 3283 | _(RLOC_PROBE_REP_RECEIVED, "rloc-probe replies received") \ |
| 3284 | _(MAP_NOTIFIES_RECEIVED, "map-notifies received") \ |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3285 | _(MAP_REPLIES_RECEIVED, "map-replies received") |
| 3286 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3287 | static char *lisp_cp_input_error_strings[] = { |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3288 | #define _(sym,string) string, |
| 3289 | foreach_lisp_cp_input_error |
| 3290 | #undef _ |
| 3291 | }; |
| 3292 | |
| 3293 | typedef enum |
| 3294 | { |
| 3295 | #define _(sym,str) LISP_CP_INPUT_ERROR_##sym, |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3296 | foreach_lisp_cp_input_error |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3297 | #undef _ |
| 3298 | LISP_CP_INPUT_N_ERROR, |
| 3299 | } lisp_cp_input_error_t; |
| 3300 | |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3301 | typedef struct |
| 3302 | { |
| 3303 | gid_address_t dst_eid; |
| 3304 | ip4_address_t map_resolver_ip; |
| 3305 | } lisp_cp_input_trace_t; |
| 3306 | |
| 3307 | u8 * |
| 3308 | format_lisp_cp_input_trace (u8 * s, va_list * args) |
| 3309 | { |
| 3310 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 3311 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3312 | CLIB_UNUSED (lisp_cp_input_trace_t * t) = |
| 3313 | va_arg (*args, lisp_cp_input_trace_t *); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3314 | |
| 3315 | s = format (s, "LISP-CP-INPUT: TODO"); |
| 3316 | return s; |
| 3317 | } |
| 3318 | |
Filip Tehlar | 9677a94 | 2016-11-28 10:23:31 +0100 | [diff] [blame] | 3319 | static void |
| 3320 | remove_expired_mapping (lisp_cp_main_t * lcm, u32 mi) |
| 3321 | { |
| 3322 | mapping_t *m; |
Florin Coras | f3dc11a | 2017-01-24 03:13:43 -0800 | [diff] [blame] | 3323 | vnet_lisp_add_del_adjacency_args_t _adj_args, *adj_args = &_adj_args; |
| 3324 | memset (adj_args, 0, sizeof (adj_args[0])); |
Filip Tehlar | 9677a94 | 2016-11-28 10:23:31 +0100 | [diff] [blame] | 3325 | |
| 3326 | m = pool_elt_at_index (lcm->mapping_pool, mi); |
Florin Coras | f3dc11a | 2017-01-24 03:13:43 -0800 | [diff] [blame] | 3327 | |
| 3328 | gid_address_copy (&adj_args->reid, &m->eid); |
| 3329 | adj_args->is_add = 0; |
| 3330 | if (vnet_lisp_add_del_adjacency (adj_args)) |
| 3331 | clib_warning ("failed to del adjacency!"); |
| 3332 | |
Filip Tehlar | 9677a94 | 2016-11-28 10:23:31 +0100 | [diff] [blame] | 3333 | vnet_lisp_add_del_mapping (&m->eid, 0, 0, 0, ~0, 0 /* is_add */ , |
| 3334 | 0 /* is_static */ , 0); |
| 3335 | mapping_delete_timer (lcm, mi); |
| 3336 | } |
| 3337 | |
| 3338 | static void |
| 3339 | mapping_start_expiration_timer (lisp_cp_main_t * lcm, u32 mi, |
| 3340 | f64 expiration_time) |
| 3341 | { |
| 3342 | mapping_t *m; |
| 3343 | u64 now = clib_cpu_time_now (); |
| 3344 | u64 cpu_cps = lcm->vlib_main->clib_time.clocks_per_second; |
| 3345 | u64 exp_clock_time = now + expiration_time * cpu_cps; |
| 3346 | |
| 3347 | m = pool_elt_at_index (lcm->mapping_pool, mi); |
| 3348 | |
| 3349 | m->timer_set = 1; |
| 3350 | timing_wheel_insert (&lcm->wheel, exp_clock_time, mi); |
| 3351 | } |
| 3352 | |
Filip Tehlar | cdab4bd | 2016-12-06 10:31:57 +0100 | [diff] [blame] | 3353 | static void |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 3354 | map_records_arg_free (map_records_arg_t * a) |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3355 | { |
Florin Coras | acd4c63 | 2017-06-15 14:33:48 -0700 | [diff] [blame] | 3356 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
Filip Tehlar | cdab4bd | 2016-12-06 10:31:57 +0100 | [diff] [blame] | 3357 | mapping_t *m; |
| 3358 | vec_foreach (m, a->mappings) |
| 3359 | { |
Filip Tehlar | cdab4bd | 2016-12-06 10:31:57 +0100 | [diff] [blame] | 3360 | vec_free (m->locators); |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 3361 | gid_address_free (&m->eid); |
Filip Tehlar | cdab4bd | 2016-12-06 10:31:57 +0100 | [diff] [blame] | 3362 | } |
Florin Coras | acd4c63 | 2017-06-15 14:33:48 -0700 | [diff] [blame] | 3363 | pool_put (lcm->map_records_args_pool[vlib_get_thread_index ()], a); |
Filip Tehlar | cdab4bd | 2016-12-06 10:31:57 +0100 | [diff] [blame] | 3364 | } |
| 3365 | |
| 3366 | void * |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 3367 | process_map_reply (map_records_arg_t * a) |
Filip Tehlar | cdab4bd | 2016-12-06 10:31:57 +0100 | [diff] [blame] | 3368 | { |
Filip Tehlar | cdab4bd | 2016-12-06 10:31:57 +0100 | [diff] [blame] | 3369 | mapping_t *m; |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 3370 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 3371 | u32 dst_map_index = 0; |
| 3372 | pending_map_request_t *pmr; |
| 3373 | u64 *noncep; |
| 3374 | uword *pmr_index; |
| 3375 | |
| 3376 | if (a->is_rloc_probe) |
| 3377 | goto done; |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 3378 | |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3379 | /* Check pending requests table and nonce */ |
Filip Tehlar | cdab4bd | 2016-12-06 10:31:57 +0100 | [diff] [blame] | 3380 | pmr_index = hash_get (lcm->pending_map_requests_by_nonce, a->nonce); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3381 | if (!pmr_index) |
| 3382 | { |
Filip Tehlar | cdab4bd | 2016-12-06 10:31:57 +0100 | [diff] [blame] | 3383 | clib_warning ("No pending map-request entry with nonce %lu!", a->nonce); |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 3384 | goto done; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3385 | } |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3386 | pmr = pool_elt_at_index (lcm->pending_map_requests_pool, pmr_index[0]); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3387 | |
Filip Tehlar | cdab4bd | 2016-12-06 10:31:57 +0100 | [diff] [blame] | 3388 | vec_foreach (m, a->mappings) |
| 3389 | { |
| 3390 | /* insert/update mappings cache */ |
| 3391 | vnet_lisp_add_del_mapping (&m->eid, m->locators, m->action, |
| 3392 | m->authoritative, m->ttl, |
| 3393 | 1, 0 /* is_static */ , &dst_map_index); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3394 | |
Florin Coras | ba888e4 | 2017-01-24 11:38:18 -0800 | [diff] [blame] | 3395 | if (dst_map_index == (u32) ~ 0) |
| 3396 | continue; |
| 3397 | |
Filip Tehlar | cdab4bd | 2016-12-06 10:31:57 +0100 | [diff] [blame] | 3398 | /* try to program forwarding only if mapping saved or updated */ |
Florin Coras | ba888e4 | 2017-01-24 11:38:18 -0800 | [diff] [blame] | 3399 | vnet_lisp_add_del_adjacency_args_t _adj_args, *adj_args = &_adj_args; |
| 3400 | memset (adj_args, 0, sizeof (adj_args[0])); |
Florin Coras | f3dc11a | 2017-01-24 03:13:43 -0800 | [diff] [blame] | 3401 | |
Florin Coras | ba888e4 | 2017-01-24 11:38:18 -0800 | [diff] [blame] | 3402 | gid_address_copy (&adj_args->leid, &pmr->src); |
| 3403 | gid_address_copy (&adj_args->reid, &m->eid); |
| 3404 | adj_args->is_add = 1; |
| 3405 | if (vnet_lisp_add_del_adjacency (adj_args)) |
| 3406 | clib_warning ("failed to add adjacency!"); |
Florin Coras | f3dc11a | 2017-01-24 03:13:43 -0800 | [diff] [blame] | 3407 | |
Florin Coras | ba888e4 | 2017-01-24 11:38:18 -0800 | [diff] [blame] | 3408 | if ((u32) ~ 0 != m->ttl) |
| 3409 | mapping_start_expiration_timer (lcm, dst_map_index, m->ttl * 60); |
Filip Tehlar | cdab4bd | 2016-12-06 10:31:57 +0100 | [diff] [blame] | 3410 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3411 | |
| 3412 | /* remove pending map request entry */ |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3413 | |
| 3414 | /* *INDENT-OFF* */ |
Florin Coras | f4691cd | 2016-08-15 19:16:32 +0200 | [diff] [blame] | 3415 | clib_fifo_foreach (noncep, pmr->nonces, ({ |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 3416 | hash_unset(lcm->pending_map_requests_by_nonce, noncep[0]); |
Florin Coras | f4691cd | 2016-08-15 19:16:32 +0200 | [diff] [blame] | 3417 | })); |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3418 | /* *INDENT-ON* */ |
| 3419 | |
| 3420 | clib_fifo_free (pmr->nonces); |
| 3421 | pool_put (lcm->pending_map_requests_pool, pmr); |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 3422 | |
| 3423 | done: |
Florin Coras | acd4c63 | 2017-06-15 14:33:48 -0700 | [diff] [blame] | 3424 | a->is_free = 1; |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 3425 | return 0; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3426 | } |
| 3427 | |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 3428 | static int |
| 3429 | is_auth_data_valid (map_notify_hdr_t * h, u32 msg_len, |
| 3430 | lisp_key_type_t key_id, u8 * key) |
| 3431 | { |
| 3432 | u8 *auth_data = 0; |
| 3433 | u16 auth_data_len; |
| 3434 | int result; |
| 3435 | |
| 3436 | auth_data_len = auth_data_len_by_key_id (key_id); |
| 3437 | if ((u16) ~ 0 == auth_data_len) |
| 3438 | { |
| 3439 | clib_warning ("invalid length for key_id %d!", key_id); |
| 3440 | return 0; |
| 3441 | } |
| 3442 | |
| 3443 | /* save auth data */ |
| 3444 | vec_validate (auth_data, auth_data_len - 1); |
| 3445 | clib_memcpy (auth_data, MNOTIFY_DATA (h), auth_data_len); |
| 3446 | |
| 3447 | /* clear auth data */ |
| 3448 | memset (MNOTIFY_DATA (h), 0, auth_data_len); |
| 3449 | |
| 3450 | /* get hash of the message */ |
| 3451 | unsigned char *code = HMAC (get_encrypt_fcn (key_id), key, vec_len (key), |
| 3452 | (unsigned char *) h, msg_len, NULL, NULL); |
| 3453 | |
| 3454 | result = memcmp (code, auth_data, auth_data_len); |
| 3455 | |
| 3456 | vec_free (auth_data); |
| 3457 | |
| 3458 | return !result; |
| 3459 | } |
| 3460 | |
| 3461 | static void |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 3462 | process_map_notify (map_records_arg_t * a) |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 3463 | { |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 3464 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 3465 | uword *pmr_index; |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 3466 | |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 3467 | pmr_index = hash_get (lcm->map_register_messages_by_nonce, a->nonce); |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 3468 | if (!pmr_index) |
| 3469 | { |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 3470 | clib_warning ("No pending map-register entry with nonce %lu!", |
| 3471 | a->nonce); |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 3472 | return; |
| 3473 | } |
| 3474 | |
Florin Coras | acd4c63 | 2017-06-15 14:33:48 -0700 | [diff] [blame] | 3475 | a->is_free = 1; |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 3476 | hash_unset (lcm->map_register_messages_by_nonce, a->nonce); |
| 3477 | } |
| 3478 | |
| 3479 | static mapping_t * |
| 3480 | get_mapping (lisp_cp_main_t * lcm, gid_address_t * e) |
| 3481 | { |
| 3482 | u32 mi; |
| 3483 | |
| 3484 | mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, e); |
| 3485 | if (~0 == mi) |
| 3486 | { |
| 3487 | clib_warning ("eid %U not found in map-cache!", unformat_gid_address, |
| 3488 | e); |
| 3489 | return 0; |
| 3490 | } |
| 3491 | return pool_elt_at_index (lcm->mapping_pool, mi); |
| 3492 | } |
| 3493 | |
| 3494 | /** |
| 3495 | * When map-notify is received it is necessary that all EIDs in the record |
| 3496 | * list share common key. The key is then used to verify authentication |
| 3497 | * data in map-notify message. |
| 3498 | */ |
| 3499 | static int |
| 3500 | map_record_integrity_check (lisp_cp_main_t * lcm, mapping_t * maps, |
| 3501 | u32 key_id, u8 ** key_out) |
| 3502 | { |
| 3503 | u32 i, len = vec_len (maps); |
| 3504 | mapping_t *m; |
| 3505 | |
| 3506 | /* get key of the first mapping */ |
| 3507 | m = get_mapping (lcm, &maps[0].eid); |
| 3508 | if (!m || !m->key) |
| 3509 | return -1; |
| 3510 | |
| 3511 | key_out[0] = m->key; |
| 3512 | |
| 3513 | for (i = 1; i < len; i++) |
| 3514 | { |
| 3515 | m = get_mapping (lcm, &maps[i].eid); |
| 3516 | if (!m || !m->key) |
| 3517 | return -1; |
| 3518 | |
| 3519 | if (key_id != m->key_id || vec_cmp (m->key, key_out[0])) |
| 3520 | { |
| 3521 | clib_warning ("keys does not match! %v, %v", key_out[0], m->key); |
| 3522 | return -1; |
| 3523 | } |
| 3524 | } |
| 3525 | return 0; |
| 3526 | } |
| 3527 | |
| 3528 | static int |
| 3529 | parse_map_records (vlib_buffer_t * b, map_records_arg_t * a, u8 count) |
| 3530 | { |
| 3531 | locator_t *locators = 0; |
| 3532 | u32 i, len; |
| 3533 | gid_address_t deid; |
| 3534 | mapping_t m; |
| 3535 | locator_t *loc; |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 3536 | |
Filip Tehlar | 68c74fc | 2017-05-04 14:52:42 +0200 | [diff] [blame] | 3537 | memset (&m, 0, sizeof (m)); |
| 3538 | |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 3539 | /* parse record eid */ |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 3540 | for (i = 0; i < count; i++) |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 3541 | { |
Florin Coras | e68de8c | 2017-06-05 15:38:50 -0700 | [diff] [blame] | 3542 | locators = 0; |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 3543 | len = lisp_msg_parse_mapping_record (b, &deid, &locators, NULL); |
| 3544 | if (len == ~0) |
| 3545 | { |
| 3546 | clib_warning ("Failed to parse mapping record!"); |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 3547 | vec_foreach (loc, locators) locator_free (loc); |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 3548 | vec_free (locators); |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 3549 | return -1; |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 3550 | } |
| 3551 | |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 3552 | m.locators = locators; |
| 3553 | gid_address_copy (&m.eid, &deid); |
| 3554 | vec_add1 (a->mappings, m); |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 3555 | } |
| 3556 | |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 3557 | return 0; |
| 3558 | } |
| 3559 | |
| 3560 | static map_records_arg_t * |
Florin Coras | acd4c63 | 2017-06-15 14:33:48 -0700 | [diff] [blame] | 3561 | map_record_args_get () |
| 3562 | { |
| 3563 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 3564 | map_records_arg_t *rec; |
| 3565 | |
| 3566 | /* Cleanup first */ |
| 3567 | /* *INDENT-OFF* */ |
| 3568 | pool_foreach (rec, lcm->map_records_args_pool[vlib_get_thread_index()], ({ |
| 3569 | if (rec->is_free) |
| 3570 | map_records_arg_free (rec); |
| 3571 | })); |
| 3572 | /* *INDENT-ON* */ |
| 3573 | |
| 3574 | pool_get (lcm->map_records_args_pool[vlib_get_thread_index ()], rec); |
| 3575 | return rec; |
| 3576 | } |
| 3577 | |
| 3578 | static map_records_arg_t * |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 3579 | parse_map_notify (vlib_buffer_t * b) |
| 3580 | { |
| 3581 | int rc = 0; |
| 3582 | map_notify_hdr_t *mnotif_hdr; |
| 3583 | lisp_key_type_t key_id; |
| 3584 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 3585 | u8 *key = 0; |
| 3586 | gid_address_t deid; |
| 3587 | u16 auth_data_len = 0; |
| 3588 | u8 record_count; |
Florin Coras | acd4c63 | 2017-06-15 14:33:48 -0700 | [diff] [blame] | 3589 | map_records_arg_t *a; |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 3590 | |
Florin Coras | acd4c63 | 2017-06-15 14:33:48 -0700 | [diff] [blame] | 3591 | a = map_record_args_get (); |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 3592 | memset (a, 0, sizeof (*a)); |
| 3593 | mnotif_hdr = vlib_buffer_get_current (b); |
| 3594 | vlib_buffer_pull (b, sizeof (*mnotif_hdr)); |
| 3595 | memset (&deid, 0, sizeof (deid)); |
| 3596 | |
| 3597 | a->nonce = MNOTIFY_NONCE (mnotif_hdr); |
| 3598 | key_id = clib_net_to_host_u16 (MNOTIFY_KEY_ID (mnotif_hdr)); |
| 3599 | auth_data_len = auth_data_len_by_key_id (key_id); |
| 3600 | |
| 3601 | /* advance buffer by authentication data */ |
| 3602 | vlib_buffer_pull (b, auth_data_len); |
| 3603 | |
| 3604 | record_count = MNOTIFY_REC_COUNT (mnotif_hdr); |
| 3605 | rc = parse_map_records (b, a, record_count); |
| 3606 | if (rc != 0) |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 3607 | { |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 3608 | map_records_arg_free (a); |
| 3609 | return 0; |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 3610 | } |
| 3611 | |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 3612 | rc = map_record_integrity_check (lcm, a->mappings, key_id, &key); |
| 3613 | if (rc != 0) |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 3614 | { |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 3615 | map_records_arg_free (a); |
| 3616 | return 0; |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 3617 | } |
| 3618 | |
| 3619 | /* verify authentication data */ |
| 3620 | if (!is_auth_data_valid (mnotif_hdr, vlib_buffer_get_tail (b) |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 3621 | - (u8 *) mnotif_hdr, key_id, key)) |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 3622 | { |
| 3623 | clib_warning ("Map-notify auth data verification failed for nonce %lu!", |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 3624 | a->nonce); |
| 3625 | map_records_arg_free (a); |
| 3626 | return 0; |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 3627 | } |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 3628 | return a; |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 3629 | } |
| 3630 | |
| 3631 | static vlib_buffer_t * |
| 3632 | build_map_reply (lisp_cp_main_t * lcm, ip_address_t * sloc, |
| 3633 | ip_address_t * dst, u64 nonce, u8 probe_bit, |
| 3634 | mapping_t * records, u16 dst_port, u32 * bi_res) |
| 3635 | { |
| 3636 | vlib_buffer_t *b; |
| 3637 | u32 bi; |
| 3638 | vlib_main_t *vm = lcm->vlib_main; |
| 3639 | |
| 3640 | if (vlib_buffer_alloc (vm, &bi, 1) != 1) |
| 3641 | { |
| 3642 | clib_warning ("Can't allocate buffer for Map-Register!"); |
| 3643 | return 0; |
| 3644 | } |
| 3645 | |
| 3646 | b = vlib_get_buffer (vm, bi); |
| 3647 | |
| 3648 | /* leave some space for the encap headers */ |
| 3649 | vlib_buffer_make_headroom (b, MAX_LISP_MSG_ENCAP_LEN); |
| 3650 | |
| 3651 | lisp_msg_put_map_reply (b, records, nonce, probe_bit); |
| 3652 | |
| 3653 | /* push outer ip header */ |
Florin Coras | fdbc382 | 2017-07-27 00:34:12 -0700 | [diff] [blame^] | 3654 | pkt_push_udp_and_ip (vm, b, LISP_CONTROL_PORT, dst_port, sloc, dst, 1); |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 3655 | |
| 3656 | bi_res[0] = bi; |
| 3657 | return b; |
| 3658 | } |
| 3659 | |
| 3660 | static int |
| 3661 | send_map_reply (lisp_cp_main_t * lcm, u32 mi, ip_address_t * dst, |
| 3662 | u8 probe_bit, u64 nonce, u16 dst_port, |
| 3663 | ip_address_t * probed_loc) |
| 3664 | { |
| 3665 | ip_address_t src; |
| 3666 | u32 bi; |
| 3667 | vlib_buffer_t *b; |
| 3668 | vlib_frame_t *f; |
| 3669 | u32 next_index, *to_next; |
| 3670 | mapping_t *records = 0, *m; |
| 3671 | |
| 3672 | m = pool_elt_at_index (lcm->mapping_pool, mi); |
| 3673 | if (!m) |
| 3674 | return -1; |
| 3675 | |
| 3676 | vec_add1 (records, m[0]); |
| 3677 | add_locators (lcm, &records[0], m->locator_set_index, probed_loc); |
| 3678 | memset (&src, 0, sizeof (src)); |
| 3679 | |
| 3680 | if (!ip_fib_get_first_egress_ip_for_dst (lcm, dst, &src)) |
| 3681 | { |
| 3682 | clib_warning ("can't find inteface address for %U", format_ip_address, |
| 3683 | dst); |
| 3684 | return -1; |
| 3685 | } |
| 3686 | |
| 3687 | b = build_map_reply (lcm, &src, dst, nonce, probe_bit, records, dst_port, |
| 3688 | &bi); |
| 3689 | if (!b) |
| 3690 | return -1; |
| 3691 | free_map_register_records (records); |
| 3692 | |
| 3693 | vnet_buffer (b)->sw_if_index[VLIB_TX] = 0; |
| 3694 | next_index = (ip_addr_version (&lcm->active_map_resolver) == IP4) ? |
| 3695 | ip4_lookup_node.index : ip6_lookup_node.index; |
| 3696 | |
| 3697 | f = vlib_get_frame_to_node (lcm->vlib_main, next_index); |
| 3698 | |
| 3699 | /* Enqueue the packet */ |
| 3700 | to_next = vlib_frame_vector_args (f); |
| 3701 | to_next[0] = bi; |
| 3702 | f->n_vectors = 1; |
| 3703 | vlib_put_frame_to_node (lcm->vlib_main, next_index, f); |
| 3704 | return 0; |
| 3705 | } |
| 3706 | |
Filip Tehlar | b601f22 | 2017-01-02 10:22:56 +0100 | [diff] [blame] | 3707 | static void |
| 3708 | find_ip_header (vlib_buffer_t * b, u8 ** ip_hdr) |
| 3709 | { |
Damjan Marion | 072401e | 2017-07-13 18:53:27 +0200 | [diff] [blame] | 3710 | const i32 start = vnet_buffer (b)->l3_hdr_offset; |
Filip Tehlar | b601f22 | 2017-01-02 10:22:56 +0100 | [diff] [blame] | 3711 | if (start < 0 && start < -sizeof (b->pre_data)) |
| 3712 | { |
| 3713 | *ip_hdr = 0; |
| 3714 | return; |
| 3715 | } |
| 3716 | |
| 3717 | *ip_hdr = b->data + start; |
| 3718 | if ((u8 *) * ip_hdr > (u8 *) vlib_buffer_get_current (b)) |
| 3719 | *ip_hdr = 0; |
| 3720 | } |
| 3721 | |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3722 | void |
Filip Tehlar | cda7066 | 2017-01-16 10:30:03 +0100 | [diff] [blame] | 3723 | process_map_request (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 3724 | lisp_cp_main_t * lcm, vlib_buffer_t * b) |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3725 | { |
Filip Tehlar | b601f22 | 2017-01-02 10:22:56 +0100 | [diff] [blame] | 3726 | u8 *ip_hdr = 0; |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 3727 | ip_address_t *dst_loc = 0, probed_loc, src_loc; |
| 3728 | mapping_t m; |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3729 | map_request_hdr_t *mreq_hdr; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3730 | gid_address_t src, dst; |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 3731 | u64 nonce; |
Filip Tehlar | cda7066 | 2017-01-16 10:30:03 +0100 | [diff] [blame] | 3732 | u32 i, len = 0, rloc_probe_recv = 0; |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 3733 | gid_address_t *itr_rlocs = 0; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3734 | |
| 3735 | mreq_hdr = vlib_buffer_get_current (b); |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 3736 | if (!MREQ_SMR (mreq_hdr) && !MREQ_RLOC_PROBE (mreq_hdr)) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3737 | { |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 3738 | clib_warning |
| 3739 | ("Only SMR Map-Requests and RLOC probe supported for now!"); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3740 | return; |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3741 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3742 | |
Filip Tehlar | b601f22 | 2017-01-02 10:22:56 +0100 | [diff] [blame] | 3743 | vlib_buffer_pull (b, sizeof (*mreq_hdr)); |
| 3744 | nonce = MREQ_NONCE (mreq_hdr); |
| 3745 | |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3746 | /* parse src eid */ |
| 3747 | len = lisp_msg_parse_addr (b, &src); |
| 3748 | if (len == ~0) |
| 3749 | return; |
| 3750 | |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 3751 | len = lisp_msg_parse_itr_rlocs (b, &itr_rlocs, |
| 3752 | MREQ_ITR_RLOC_COUNT (mreq_hdr) + 1); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3753 | if (len == ~0) |
Filip Tehlar | cda7066 | 2017-01-16 10:30:03 +0100 | [diff] [blame] | 3754 | goto done; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3755 | |
| 3756 | /* parse eid records and send SMR-invoked map-requests */ |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3757 | for (i = 0; i < MREQ_REC_COUNT (mreq_hdr); i++) |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3758 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3759 | memset (&dst, 0, sizeof (dst)); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3760 | len = lisp_msg_parse_eid_rec (b, &dst); |
| 3761 | if (len == ~0) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3762 | { |
| 3763 | clib_warning ("Can't parse map-request EID-record"); |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 3764 | goto done; |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3765 | } |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 3766 | |
| 3767 | if (MREQ_SMR (mreq_hdr)) |
| 3768 | { |
| 3769 | /* send SMR-invoked map-requests */ |
| 3770 | queue_map_request (&dst, &src, 1 /* invoked */ , 0 /* resend */ ); |
| 3771 | } |
| 3772 | else if (MREQ_RLOC_PROBE (mreq_hdr)) |
| 3773 | { |
Filip Tehlar | b601f22 | 2017-01-02 10:22:56 +0100 | [diff] [blame] | 3774 | find_ip_header (b, &ip_hdr); |
| 3775 | if (!ip_hdr) |
| 3776 | { |
| 3777 | clib_warning ("Cannot find the IP header!"); |
Filip Tehlar | cda7066 | 2017-01-16 10:30:03 +0100 | [diff] [blame] | 3778 | goto done; |
Filip Tehlar | b601f22 | 2017-01-02 10:22:56 +0100 | [diff] [blame] | 3779 | } |
Filip Tehlar | cda7066 | 2017-01-16 10:30:03 +0100 | [diff] [blame] | 3780 | rloc_probe_recv++; |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 3781 | memset (&m, 0, sizeof (m)); |
| 3782 | u32 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &dst); |
| 3783 | |
| 3784 | // TODO: select best locator; for now use the first one |
| 3785 | dst_loc = &gid_address_ip (&itr_rlocs[0]); |
| 3786 | |
| 3787 | /* get src/dst IP addresses */ |
| 3788 | get_src_and_dst_ip (ip_hdr, &src_loc, &probed_loc); |
| 3789 | |
| 3790 | // TODO get source port from buffer |
| 3791 | u16 src_port = LISP_CONTROL_PORT; |
| 3792 | |
| 3793 | send_map_reply (lcm, mi, dst_loc, 1 /* probe-bit */ , nonce, |
| 3794 | src_port, &probed_loc); |
| 3795 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3796 | } |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 3797 | |
| 3798 | done: |
Filip Tehlar | cda7066 | 2017-01-16 10:30:03 +0100 | [diff] [blame] | 3799 | vlib_node_increment_counter (vm, node->node_index, |
| 3800 | LISP_CP_INPUT_ERROR_RLOC_PROBE_REQ_RECEIVED, |
| 3801 | rloc_probe_recv); |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 3802 | vec_free (itr_rlocs); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3803 | } |
| 3804 | |
Filip Tehlar | 816f437 | 2017-04-26 16:09:06 +0200 | [diff] [blame] | 3805 | map_records_arg_t * |
Filip Tehlar | cdab4bd | 2016-12-06 10:31:57 +0100 | [diff] [blame] | 3806 | parse_map_reply (vlib_buffer_t * b) |
| 3807 | { |
| 3808 | locator_t probed; |
| 3809 | gid_address_t deid; |
| 3810 | void *h; |
| 3811 | u32 i, len = 0; |
| 3812 | mapping_t m; |
| 3813 | map_reply_hdr_t *mrep_hdr; |
Florin Coras | acd4c63 | 2017-06-15 14:33:48 -0700 | [diff] [blame] | 3814 | map_records_arg_t *a; |
| 3815 | |
| 3816 | a = map_record_args_get (); |
Filip Tehlar | cdab4bd | 2016-12-06 10:31:57 +0100 | [diff] [blame] | 3817 | memset (a, 0, sizeof (*a)); |
Florin Coras | acd4c63 | 2017-06-15 14:33:48 -0700 | [diff] [blame] | 3818 | |
Filip Tehlar | cdab4bd | 2016-12-06 10:31:57 +0100 | [diff] [blame] | 3819 | locator_t *locators; |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 3820 | |
Filip Tehlar | cdab4bd | 2016-12-06 10:31:57 +0100 | [diff] [blame] | 3821 | mrep_hdr = vlib_buffer_get_current (b); |
| 3822 | a->nonce = MREP_NONCE (mrep_hdr); |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 3823 | a->is_rloc_probe = MREP_RLOC_PROBE (mrep_hdr); |
Filip Tehlar | 816f437 | 2017-04-26 16:09:06 +0200 | [diff] [blame] | 3824 | if (!vlib_buffer_has_space (b, sizeof (*mrep_hdr))) |
| 3825 | { |
| 3826 | clib_mem_free (a); |
| 3827 | return 0; |
| 3828 | } |
Filip Tehlar | cdab4bd | 2016-12-06 10:31:57 +0100 | [diff] [blame] | 3829 | vlib_buffer_pull (b, sizeof (*mrep_hdr)); |
| 3830 | |
| 3831 | for (i = 0; i < MREP_REC_COUNT (mrep_hdr); i++) |
| 3832 | { |
| 3833 | memset (&m, 0, sizeof (m)); |
| 3834 | locators = 0; |
| 3835 | h = vlib_buffer_get_current (b); |
| 3836 | |
| 3837 | m.ttl = clib_net_to_host_u32 (MAP_REC_TTL (h)); |
| 3838 | m.action = MAP_REC_ACTION (h); |
| 3839 | m.authoritative = MAP_REC_AUTH (h); |
| 3840 | |
| 3841 | len = lisp_msg_parse_mapping_record (b, &deid, &locators, &probed); |
| 3842 | if (len == ~0) |
| 3843 | { |
| 3844 | clib_warning ("Failed to parse mapping record!"); |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 3845 | map_records_arg_free (a); |
Filip Tehlar | cdab4bd | 2016-12-06 10:31:57 +0100 | [diff] [blame] | 3846 | return 0; |
| 3847 | } |
| 3848 | |
| 3849 | m.locators = locators; |
| 3850 | gid_address_copy (&m.eid, &deid); |
| 3851 | vec_add1 (a->mappings, m); |
| 3852 | } |
| 3853 | return a; |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 3854 | } |
| 3855 | |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 3856 | static void |
| 3857 | queue_map_reply_for_processing (map_records_arg_t * a) |
| 3858 | { |
Florin Coras | 655fcc4 | 2017-01-10 08:57:54 -0800 | [diff] [blame] | 3859 | vl_api_rpc_call_main_thread (process_map_reply, (u8 *) a, sizeof (*a)); |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 3860 | } |
| 3861 | |
| 3862 | static void |
| 3863 | queue_map_notify_for_processing (map_records_arg_t * a) |
| 3864 | { |
| 3865 | vl_api_rpc_call_main_thread (process_map_notify, (u8 *) a, sizeof (a[0])); |
| 3866 | } |
| 3867 | |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3868 | static uword |
| 3869 | lisp_cp_input (vlib_main_t * vm, vlib_node_runtime_t * node, |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3870 | vlib_frame_t * from_frame) |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3871 | { |
Filip Tehlar | cda7066 | 2017-01-16 10:30:03 +0100 | [diff] [blame] | 3872 | u32 n_left_from, *from, *to_next_drop, rloc_probe_rep_recv = 0, |
| 3873 | map_notifies_recv = 0; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3874 | lisp_msg_type_e type; |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3875 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 3876 | map_records_arg_t *a; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3877 | |
| 3878 | from = vlib_frame_vector_args (from_frame); |
| 3879 | n_left_from = from_frame->n_vectors; |
| 3880 | |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 3881 | |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3882 | while (n_left_from > 0) |
| 3883 | { |
| 3884 | u32 n_left_to_next_drop; |
| 3885 | |
| 3886 | vlib_get_next_frame (vm, node, LISP_CP_INPUT_NEXT_DROP, |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3887 | to_next_drop, n_left_to_next_drop); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3888 | while (n_left_from > 0 && n_left_to_next_drop > 0) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3889 | { |
| 3890 | u32 bi0; |
| 3891 | vlib_buffer_t *b0; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3892 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3893 | bi0 = from[0]; |
| 3894 | from += 1; |
| 3895 | n_left_from -= 1; |
| 3896 | to_next_drop[0] = bi0; |
| 3897 | to_next_drop += 1; |
| 3898 | n_left_to_next_drop -= 1; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3899 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3900 | b0 = vlib_get_buffer (vm, bi0); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3901 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3902 | type = lisp_msg_type (vlib_buffer_get_current (b0)); |
| 3903 | switch (type) |
| 3904 | { |
| 3905 | case LISP_MAP_REPLY: |
Filip Tehlar | cdab4bd | 2016-12-06 10:31:57 +0100 | [diff] [blame] | 3906 | a = parse_map_reply (b0); |
| 3907 | if (a) |
Filip Tehlar | cda7066 | 2017-01-16 10:30:03 +0100 | [diff] [blame] | 3908 | { |
| 3909 | if (a->is_rloc_probe) |
| 3910 | rloc_probe_rep_recv++; |
| 3911 | queue_map_reply_for_processing (a); |
| 3912 | } |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3913 | break; |
| 3914 | case LISP_MAP_REQUEST: |
Filip Tehlar | cda7066 | 2017-01-16 10:30:03 +0100 | [diff] [blame] | 3915 | process_map_request (vm, node, lcm, b0); |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3916 | break; |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 3917 | case LISP_MAP_NOTIFY: |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 3918 | a = parse_map_notify (b0); |
| 3919 | if (a) |
Filip Tehlar | cda7066 | 2017-01-16 10:30:03 +0100 | [diff] [blame] | 3920 | { |
| 3921 | map_notifies_recv++; |
| 3922 | queue_map_notify_for_processing (a); |
| 3923 | } |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 3924 | break; |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3925 | default: |
| 3926 | clib_warning ("Unsupported LISP message type %d", type); |
| 3927 | break; |
| 3928 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3929 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3930 | b0->error = node->errors[LISP_CP_INPUT_ERROR_DROP]; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3931 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3932 | if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 3933 | { |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3934 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3935 | } |
| 3936 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3937 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3938 | vlib_put_next_frame (vm, node, LISP_CP_INPUT_NEXT_DROP, |
| 3939 | n_left_to_next_drop); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3940 | } |
Filip Tehlar | cda7066 | 2017-01-16 10:30:03 +0100 | [diff] [blame] | 3941 | vlib_node_increment_counter (vm, node->node_index, |
| 3942 | LISP_CP_INPUT_ERROR_RLOC_PROBE_REP_RECEIVED, |
| 3943 | rloc_probe_rep_recv); |
| 3944 | vlib_node_increment_counter (vm, node->node_index, |
| 3945 | LISP_CP_INPUT_ERROR_MAP_NOTIFIES_RECEIVED, |
| 3946 | map_notifies_recv); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3947 | return from_frame->n_vectors; |
| 3948 | } |
| 3949 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3950 | /* *INDENT-OFF* */ |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3951 | VLIB_REGISTER_NODE (lisp_cp_input_node) = { |
| 3952 | .function = lisp_cp_input, |
| 3953 | .name = "lisp-cp-input", |
| 3954 | .vector_size = sizeof (u32), |
| 3955 | .format_trace = format_lisp_cp_input_trace, |
| 3956 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 3957 | |
| 3958 | .n_errors = LISP_CP_INPUT_N_ERROR, |
| 3959 | .error_strings = lisp_cp_input_error_strings, |
| 3960 | |
| 3961 | .n_next_nodes = LISP_CP_INPUT_N_NEXT, |
| 3962 | |
| 3963 | .next_nodes = { |
| 3964 | [LISP_CP_INPUT_NEXT_DROP] = "error-drop", |
| 3965 | }, |
| 3966 | }; |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3967 | /* *INDENT-ON* */ |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3968 | |
| 3969 | clib_error_t * |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3970 | lisp_cp_init (vlib_main_t * vm) |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3971 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3972 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 3973 | clib_error_t *error = 0; |
Florin Coras | acd4c63 | 2017-06-15 14:33:48 -0700 | [diff] [blame] | 3974 | vlib_thread_main_t *vtm = vlib_get_thread_main (); |
| 3975 | u32 num_threads; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3976 | |
| 3977 | if ((error = vlib_call_init_function (vm, lisp_gpe_init))) |
| 3978 | return error; |
| 3979 | |
| 3980 | lcm->im4 = &ip4_main; |
| 3981 | lcm->im6 = &ip6_main; |
| 3982 | lcm->vlib_main = vm; |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3983 | lcm->vnet_main = vnet_get_main (); |
Andrej Kozemcak | b6e4d39 | 2016-06-14 13:55:57 +0200 | [diff] [blame] | 3984 | lcm->mreq_itr_rlocs = ~0; |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 3985 | lcm->lisp_pitr = 0; |
Florin Coras | ba888e4 | 2017-01-24 11:38:18 -0800 | [diff] [blame] | 3986 | lcm->flags = 0; |
Florin Coras | 5a1c11b | 2016-09-06 16:29:34 +0200 | [diff] [blame] | 3987 | memset (&lcm->active_map_resolver, 0, sizeof (lcm->active_map_resolver)); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3988 | |
| 3989 | gid_dictionary_init (&lcm->mapping_index_by_gid); |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 3990 | lcm->do_map_resolver_election = 1; |
Florin Coras | dca8804 | 2016-09-14 16:01:38 +0200 | [diff] [blame] | 3991 | lcm->map_request_mode = MR_MODE_DST_ONLY; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 3992 | |
Florin Coras | acd4c63 | 2017-06-15 14:33:48 -0700 | [diff] [blame] | 3993 | num_threads = 1 /* main thread */ + vtm->n_threads; |
| 3994 | vec_validate (lcm->map_records_args_pool, num_threads - 1); |
| 3995 | |
Florin Coras | 577c355 | 2016-04-21 00:45:40 +0200 | [diff] [blame] | 3996 | /* default vrf mapped to vni 0 */ |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 3997 | hash_set (lcm->table_id_by_vni, 0, 0); |
| 3998 | hash_set (lcm->vni_by_table_id, 0, 0); |
Florin Coras | 577c355 | 2016-04-21 00:45:40 +0200 | [diff] [blame] | 3999 | |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 4000 | udp_register_dst_port (vm, UDP_DST_PORT_lisp_cp, |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 4001 | lisp_cp_input_node.index, 1 /* is_ip4 */ ); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 4002 | udp_register_dst_port (vm, UDP_DST_PORT_lisp_cp6, |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 4003 | lisp_cp_input_node.index, 0 /* is_ip4 */ ); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 4004 | |
Filip Tehlar | 9677a94 | 2016-11-28 10:23:31 +0100 | [diff] [blame] | 4005 | u64 now = clib_cpu_time_now (); |
| 4006 | timing_wheel_init (&lcm->wheel, now, vm->clib_time.clocks_per_second); |
Filip Tehlar | ef2a5bf | 2017-05-30 07:14:46 +0200 | [diff] [blame] | 4007 | lcm->nsh_map_index = ~0; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 4008 | return 0; |
| 4009 | } |
| 4010 | |
Filip Tehlar | 4868ff6 | 2017-03-09 16:48:39 +0100 | [diff] [blame] | 4011 | static int |
| 4012 | lisp_stats_api_fill (lisp_cp_main_t * lcm, lisp_gpe_main_t * lgm, |
| 4013 | lisp_api_stats_t * stat, lisp_stats_key_t * key, |
| 4014 | u32 stats_index) |
| 4015 | { |
Filip Tehlar | 2151191 | 2017-04-07 10:41:42 +0200 | [diff] [blame] | 4016 | vlib_counter_t v; |
| 4017 | vlib_combined_counter_main_t *cm = &lgm->counters; |
Filip Tehlar | 4868ff6 | 2017-03-09 16:48:39 +0100 | [diff] [blame] | 4018 | lisp_gpe_fwd_entry_key_t fwd_key; |
| 4019 | const lisp_gpe_tunnel_t *lgt; |
| 4020 | fwd_entry_t *fe; |
| 4021 | |
| 4022 | memset (stat, 0, sizeof (*stat)); |
| 4023 | memset (&fwd_key, 0, sizeof (fwd_key)); |
| 4024 | |
| 4025 | fe = pool_elt_at_index (lcm->fwd_entry_pool, key->fwd_entry_index); |
| 4026 | ASSERT (fe != 0); |
| 4027 | |
| 4028 | gid_to_dp_address (&fe->reid, &stat->deid); |
| 4029 | gid_to_dp_address (&fe->leid, &stat->seid); |
| 4030 | stat->vni = gid_address_vni (&fe->reid); |
| 4031 | |
| 4032 | lgt = lisp_gpe_tunnel_get (key->tunnel_index); |
| 4033 | stat->loc_rloc = lgt->key->lcl; |
| 4034 | stat->rmt_rloc = lgt->key->rmt; |
| 4035 | |
Filip Tehlar | 2151191 | 2017-04-07 10:41:42 +0200 | [diff] [blame] | 4036 | vlib_get_combined_counter (cm, stats_index, &v); |
| 4037 | stat->counters = v; |
Filip Tehlar | 4868ff6 | 2017-03-09 16:48:39 +0100 | [diff] [blame] | 4038 | return 1; |
| 4039 | } |
| 4040 | |
| 4041 | lisp_api_stats_t * |
| 4042 | vnet_lisp_get_stats (void) |
| 4043 | { |
| 4044 | lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); |
| 4045 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 4046 | lisp_api_stats_t *stats = 0, stat; |
| 4047 | lisp_stats_key_t *key; |
| 4048 | u32 index; |
| 4049 | |
| 4050 | /* *INDENT-OFF* */ |
| 4051 | hash_foreach_mem (key, index, lgm->lisp_stats_index_by_key, |
| 4052 | { |
| 4053 | if (lisp_stats_api_fill (lcm, lgm, &stat, key, index)) |
| 4054 | vec_add1 (stats, stat); |
| 4055 | }); |
| 4056 | /* *INDENT-ON* */ |
| 4057 | |
| 4058 | return stats; |
| 4059 | } |
| 4060 | |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 4061 | static void * |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 4062 | send_map_request_thread_fn (void *arg) |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 4063 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 4064 | map_request_args_t *a = arg; |
| 4065 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 4066 | |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 4067 | if (a->is_resend) |
| 4068 | resend_encapsulated_map_request (lcm, &a->seid, &a->deid, a->smr_invoked); |
| 4069 | else |
Filip Tehlar | cdab4bd | 2016-12-06 10:31:57 +0100 | [diff] [blame] | 4070 | send_encapsulated_map_request (lcm, &a->seid, &a->deid, a->smr_invoked); |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 4071 | |
| 4072 | return 0; |
| 4073 | } |
| 4074 | |
| 4075 | static int |
| 4076 | queue_map_request (gid_address_t * seid, gid_address_t * deid, |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 4077 | u8 smr_invoked, u8 is_resend) |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 4078 | { |
| 4079 | map_request_args_t a; |
| 4080 | |
| 4081 | a.is_resend = is_resend; |
| 4082 | gid_address_copy (&a.seid, seid); |
| 4083 | gid_address_copy (&a.deid, deid); |
| 4084 | a.smr_invoked = smr_invoked; |
| 4085 | |
| 4086 | vl_api_rpc_call_main_thread (send_map_request_thread_fn, |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 4087 | (u8 *) & a, sizeof (a)); |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 4088 | return 0; |
| 4089 | } |
| 4090 | |
| 4091 | /** |
| 4092 | * Take an action with a pending map request depending on expiration time |
| 4093 | * and re-try counters. |
| 4094 | */ |
| 4095 | static void |
| 4096 | update_pending_request (pending_map_request_t * r, f64 dt) |
| 4097 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 4098 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 4099 | lisp_msmr_t *mr; |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 4100 | |
| 4101 | if (r->time_to_expire - dt < 0) |
| 4102 | /* it's time to decide what to do with this pending request */ |
| 4103 | { |
| 4104 | if (r->retries_num >= NUMBER_OF_RETRIES) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 4105 | /* too many retries -> assume current map resolver is not available */ |
| 4106 | { |
| 4107 | mr = get_map_resolver (&lcm->active_map_resolver); |
| 4108 | if (!mr) |
| 4109 | { |
| 4110 | clib_warning ("Map resolver %U not found - probably deleted " |
| 4111 | "by the user recently.", format_ip_address, |
| 4112 | &lcm->active_map_resolver); |
| 4113 | } |
| 4114 | else |
| 4115 | { |
| 4116 | clib_warning ("map resolver %U is unreachable, ignoring", |
| 4117 | format_ip_address, &lcm->active_map_resolver); |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 4118 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 4119 | /* mark current map resolver unavailable so it won't be |
| 4120 | * selected next time */ |
| 4121 | mr->is_down = 1; |
| 4122 | mr->last_update = vlib_time_now (lcm->vlib_main); |
| 4123 | } |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 4124 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 4125 | reset_pending_mr_counters (r); |
| 4126 | elect_map_resolver (lcm); |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 4127 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 4128 | /* try to find a next eligible map resolver and re-send */ |
| 4129 | queue_map_request (&r->src, &r->dst, r->is_smr_invoked, |
| 4130 | 1 /* resend */ ); |
| 4131 | } |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 4132 | else |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 4133 | { |
| 4134 | /* try again */ |
| 4135 | queue_map_request (&r->src, &r->dst, r->is_smr_invoked, |
| 4136 | 1 /* resend */ ); |
| 4137 | r->retries_num++; |
| 4138 | r->time_to_expire = PENDING_MREQ_EXPIRATION_TIME; |
| 4139 | } |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 4140 | } |
| 4141 | else |
| 4142 | r->time_to_expire -= dt; |
| 4143 | } |
| 4144 | |
| 4145 | static void |
| 4146 | remove_dead_pending_map_requests (lisp_cp_main_t * lcm) |
| 4147 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 4148 | u64 *nonce; |
| 4149 | pending_map_request_t *pmr; |
| 4150 | u32 *to_be_removed = 0, *pmr_index; |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 4151 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 4152 | /* *INDENT-OFF* */ |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 4153 | pool_foreach (pmr, lcm->pending_map_requests_pool, |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 4154 | ({ |
| 4155 | if (pmr->to_be_removed) |
| 4156 | { |
| 4157 | clib_fifo_foreach (nonce, pmr->nonces, ({ |
| 4158 | hash_unset (lcm->pending_map_requests_by_nonce, nonce[0]); |
| 4159 | })); |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 4160 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 4161 | vec_add1 (to_be_removed, pmr - lcm->pending_map_requests_pool); |
| 4162 | } |
| 4163 | })); |
| 4164 | /* *INDENT-ON* */ |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 4165 | |
| 4166 | vec_foreach (pmr_index, to_be_removed) |
| 4167 | pool_put_index (lcm->pending_map_requests_by_nonce, pmr_index[0]); |
| 4168 | |
| 4169 | vec_free (to_be_removed); |
| 4170 | } |
| 4171 | |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 4172 | static void |
| 4173 | update_rloc_probing (lisp_cp_main_t * lcm, f64 dt) |
| 4174 | { |
| 4175 | static f64 time_left = RLOC_PROBING_INTERVAL; |
| 4176 | |
| 4177 | if (!lcm->is_enabled || !lcm->rloc_probing) |
| 4178 | return; |
| 4179 | |
| 4180 | time_left -= dt; |
| 4181 | if (time_left <= 0) |
| 4182 | { |
| 4183 | time_left = RLOC_PROBING_INTERVAL; |
| 4184 | send_rloc_probes (lcm); |
| 4185 | } |
| 4186 | } |
| 4187 | |
| 4188 | static void |
| 4189 | update_map_register (lisp_cp_main_t * lcm, f64 dt) |
| 4190 | { |
| 4191 | static f64 time_left = QUICK_MAP_REGISTER_INTERVAL; |
| 4192 | static u64 mreg_sent_counter = 0; |
| 4193 | |
| 4194 | if (!lcm->is_enabled || !lcm->map_registering) |
| 4195 | return; |
| 4196 | |
| 4197 | time_left -= dt; |
| 4198 | if (time_left <= 0) |
| 4199 | { |
| 4200 | if (mreg_sent_counter >= QUICK_MAP_REGISTER_MSG_COUNT) |
| 4201 | time_left = MAP_REGISTER_INTERVAL; |
| 4202 | else |
| 4203 | { |
| 4204 | mreg_sent_counter++; |
| 4205 | time_left = QUICK_MAP_REGISTER_INTERVAL; |
| 4206 | } |
| 4207 | send_map_register (lcm, 1 /* want map notify */ ); |
| 4208 | } |
| 4209 | } |
| 4210 | |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 4211 | static uword |
| 4212 | send_map_resolver_service (vlib_main_t * vm, |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 4213 | vlib_node_runtime_t * rt, vlib_frame_t * f) |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 4214 | { |
Filip Tehlar | 9677a94 | 2016-11-28 10:23:31 +0100 | [diff] [blame] | 4215 | u32 *expired = 0; |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 4216 | f64 period = 2.0; |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 4217 | pending_map_request_t *pmr; |
| 4218 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 4219 | |
| 4220 | while (1) |
| 4221 | { |
| 4222 | vlib_process_wait_for_event_or_clock (vm, period); |
| 4223 | |
| 4224 | /* currently no signals are expected - just wait for clock */ |
| 4225 | (void) vlib_process_get_events (vm, 0); |
| 4226 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 4227 | /* *INDENT-OFF* */ |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 4228 | pool_foreach (pmr, lcm->pending_map_requests_pool, |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 4229 | ({ |
| 4230 | if (!pmr->to_be_removed) |
| 4231 | update_pending_request (pmr, period); |
| 4232 | })); |
| 4233 | /* *INDENT-ON* */ |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 4234 | |
| 4235 | remove_dead_pending_map_requests (lcm); |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 4236 | |
| 4237 | update_map_register (lcm, period); |
| 4238 | update_rloc_probing (lcm, period); |
Filip Tehlar | 9677a94 | 2016-11-28 10:23:31 +0100 | [diff] [blame] | 4239 | |
| 4240 | u64 now = clib_cpu_time_now (); |
| 4241 | |
| 4242 | expired = timing_wheel_advance (&lcm->wheel, now, expired, 0); |
| 4243 | if (vec_len (expired) > 0) |
| 4244 | { |
| 4245 | u32 *mi = 0; |
| 4246 | vec_foreach (mi, expired) |
| 4247 | { |
| 4248 | remove_expired_mapping (lcm, mi[0]); |
| 4249 | } |
| 4250 | _vec_len (expired) = 0; |
| 4251 | } |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 4252 | } |
| 4253 | |
| 4254 | /* unreachable */ |
| 4255 | return 0; |
| 4256 | } |
| 4257 | |
Filip Tehlar | 7eaf0e5 | 2017-03-08 08:46:51 +0100 | [diff] [blame] | 4258 | vnet_api_error_t |
| 4259 | vnet_lisp_stats_enable_disable (u8 enable) |
| 4260 | { |
| 4261 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 4262 | |
| 4263 | if (vnet_lisp_enable_disable_status () == 0) |
| 4264 | return VNET_API_ERROR_LISP_DISABLED; |
| 4265 | |
Filip Tehlar | 4868ff6 | 2017-03-09 16:48:39 +0100 | [diff] [blame] | 4266 | if (enable) |
| 4267 | lcm->flags |= LISP_FLAG_STATS_ENABLED; |
| 4268 | else |
| 4269 | lcm->flags &= ~LISP_FLAG_STATS_ENABLED; |
| 4270 | |
Filip Tehlar | 7eaf0e5 | 2017-03-08 08:46:51 +0100 | [diff] [blame] | 4271 | return 0; |
| 4272 | } |
| 4273 | |
| 4274 | u8 |
| 4275 | vnet_lisp_stats_enable_disable_state (void) |
| 4276 | { |
| 4277 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 4278 | |
| 4279 | if (vnet_lisp_enable_disable_status () == 0) |
| 4280 | return VNET_API_ERROR_LISP_DISABLED; |
| 4281 | |
Filip Tehlar | 4868ff6 | 2017-03-09 16:48:39 +0100 | [diff] [blame] | 4282 | return lcm->flags & LISP_FLAG_STATS_ENABLED; |
Filip Tehlar | 7eaf0e5 | 2017-03-08 08:46:51 +0100 | [diff] [blame] | 4283 | } |
| 4284 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 4285 | /* *INDENT-OFF* */ |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 4286 | VLIB_REGISTER_NODE (lisp_retry_service_node,static) = { |
| 4287 | .function = send_map_resolver_service, |
| 4288 | .type = VLIB_NODE_TYPE_PROCESS, |
| 4289 | .name = "lisp-retry-service", |
| 4290 | .process_log2_n_stack_bytes = 16, |
| 4291 | }; |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 4292 | /* *INDENT-ON* */ |
Filip Tehlar | a5abdeb | 2016-07-18 17:35:40 +0200 | [diff] [blame] | 4293 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 4294 | VLIB_INIT_FUNCTION (lisp_cp_init); |
| 4295 | |
| 4296 | /* |
| 4297 | * fd.io coding-style-patch-verification: ON |
| 4298 | * |
| 4299 | * Local Variables: |
| 4300 | * eval: (c-set-style "gnu") |
| 4301 | * End: |
| 4302 | */ |