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