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