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