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 | |
| 16 | #include <vnet/lisp-cp/lisp_msg_serdes.h> |
| 17 | #include <vnet/lisp-cp/packets.h> |
| 18 | #include <vppinfra/time.h> |
| 19 | |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 20 | void *lisp_msg_put_gid (vlib_buffer_t * b, gid_address_t * gid); |
| 21 | |
| 22 | static void |
| 23 | lisp_msg_put_locators (vlib_buffer_t * b, locator_t * locators) |
| 24 | { |
| 25 | locator_t *loc; |
| 26 | |
| 27 | vec_foreach (loc, locators) |
| 28 | { |
| 29 | u8 *p = vlib_buffer_put_uninit (b, sizeof (locator_hdr_t)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 30 | clib_memset (p, 0, sizeof (locator_hdr_t)); |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 31 | LOC_PRIORITY (p) = loc->priority; |
| 32 | LOC_MPRIORITY (p) = loc->mpriority; |
| 33 | LOC_WEIGHT (p) = loc->weight; |
| 34 | LOC_MWEIGHT (p) = loc->mweight; |
| 35 | LOC_LOCAL (p) = loc->local; |
| 36 | LOC_PROBED (p) = loc->probed ? 1 : 0; |
| 37 | lisp_msg_put_gid (b, &loc->address); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | static void |
| 42 | lisp_msg_put_mapping_record (vlib_buffer_t * b, mapping_t * record) |
| 43 | { |
| 44 | mapping_record_hdr_t *p = |
| 45 | vlib_buffer_put_uninit (b, sizeof (mapping_record_hdr_t)); |
| 46 | gid_address_t *eid = &record->eid; |
| 47 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 48 | clib_memset (p, 0, sizeof (*p)); |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 49 | MAP_REC_EID_PLEN (p) = gid_address_len (eid); |
Filip Tehlar | fb9931f | 2016-12-09 13:52:38 +0100 | [diff] [blame] | 50 | MAP_REC_TTL (p) = clib_host_to_net_u32 (MAP_REGISTER_DEFAULT_TTL); |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 51 | MAP_REC_AUTH (p) = record->authoritative ? 1 : 0; |
| 52 | MAP_REC_LOC_COUNT (p) = vec_len (record->locators); |
| 53 | |
| 54 | lisp_msg_put_gid (b, eid); |
| 55 | lisp_msg_put_locators (b, record->locators); |
| 56 | } |
| 57 | |
| 58 | static void |
| 59 | lisp_msg_put_mreg_records (vlib_buffer_t * b, mapping_t * records) |
| 60 | { |
| 61 | u32 i; |
| 62 | for (i = 0; i < vec_len (records); i++) |
| 63 | lisp_msg_put_mapping_record (b, &records[i]); |
| 64 | } |
| 65 | |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 66 | void * |
| 67 | lisp_msg_put_gid (vlib_buffer_t * b, gid_address_t * gid) |
| 68 | { |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 69 | u8 *p = 0; |
| 70 | if (!gid) |
| 71 | { |
| 72 | /* insert only src-eid-afi field set to 0 */ |
| 73 | p = vlib_buffer_put_uninit (b, sizeof (u16)); |
| 74 | *(u16 *) p = 0; |
| 75 | } |
| 76 | else |
| 77 | { |
| 78 | p = vlib_buffer_put_uninit (b, gid_address_size_to_put (gid)); |
| 79 | gid_address_put (p, gid); |
| 80 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 81 | return p; |
| 82 | } |
| 83 | |
Filip Tehlar | beceab9 | 2016-04-20 17:21:55 +0200 | [diff] [blame] | 84 | static void * |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 85 | lisp_msg_put_itr_rlocs (lisp_cp_main_t * lcm, vlib_buffer_t * b, |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 86 | gid_address_t * rlocs, u8 * locs_put) |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 87 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 88 | u8 *bp, count = 0; |
Filip Tehlar | 254b036 | 2016-04-07 10:04:34 +0200 | [diff] [blame] | 89 | u32 i; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 90 | |
Filip Tehlar | beceab9 | 2016-04-20 17:21:55 +0200 | [diff] [blame] | 91 | bp = vlib_buffer_get_current (b); |
| 92 | for (i = 0; i < vec_len (rlocs); i++) |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 93 | { |
Filip Tehlar | beceab9 | 2016-04-20 17:21:55 +0200 | [diff] [blame] | 94 | lisp_msg_put_gid (b, &rlocs[i]); |
Filip Tehlar | 254b036 | 2016-04-07 10:04:34 +0200 | [diff] [blame] | 95 | count++; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 96 | } |
Filip Tehlar | 254b036 | 2016-04-07 10:04:34 +0200 | [diff] [blame] | 97 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 98 | *locs_put = count - 1; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 99 | return bp; |
| 100 | } |
| 101 | |
| 102 | void * |
| 103 | lisp_msg_put_eid_rec (vlib_buffer_t * b, gid_address_t * eid) |
| 104 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 105 | eid_record_hdr_t *h = vlib_buffer_put_uninit (b, sizeof (*h)); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 106 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 107 | clib_memset (h, 0, sizeof (*h)); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 108 | EID_REC_MLEN (h) = gid_address_len (eid); |
| 109 | lisp_msg_put_gid (b, eid); |
| 110 | return h; |
| 111 | } |
| 112 | |
| 113 | u64 |
| 114 | nonce_build (u32 seed) |
| 115 | { |
| 116 | u64 nonce; |
| 117 | u32 nonce_lower; |
| 118 | u32 nonce_upper; |
| 119 | struct timespec ts; |
| 120 | |
| 121 | /* Put nanosecond clock in lower 32-bits and put an XOR of the nanosecond |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 122 | * clock with the second clock in the upper 32-bits. */ |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 123 | syscall (SYS_clock_gettime, CLOCK_REALTIME, &ts); |
| 124 | nonce_lower = ts.tv_nsec; |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 125 | nonce_upper = ts.tv_sec ^ clib_host_to_net_u32 (nonce_lower); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 126 | |
| 127 | /* OR in a caller provided seed to the low-order 32-bits. */ |
| 128 | nonce_lower |= seed; |
| 129 | |
| 130 | /* Return 64-bit nonce. */ |
| 131 | nonce = nonce_upper; |
| 132 | nonce = (nonce << 32) | nonce_lower; |
| 133 | return nonce; |
| 134 | } |
| 135 | |
| 136 | void * |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 137 | lisp_msg_put_map_reply (vlib_buffer_t * b, mapping_t * records, u64 nonce, |
| 138 | u8 probe_bit) |
| 139 | { |
| 140 | map_reply_hdr_t *h = vlib_buffer_put_uninit (b, sizeof (h[0])); |
| 141 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 142 | clib_memset (h, 0, sizeof (h[0])); |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 143 | MREP_TYPE (h) = LISP_MAP_REPLY; |
| 144 | MREP_NONCE (h) = nonce; |
| 145 | MREP_REC_COUNT (h) = 1; |
| 146 | MREP_RLOC_PROBE (h) = probe_bit; |
| 147 | |
| 148 | lisp_msg_put_mreg_records (b, records); |
| 149 | return h; |
| 150 | } |
| 151 | |
| 152 | void * |
| 153 | lisp_msg_put_map_register (vlib_buffer_t * b, mapping_t * records, |
| 154 | u8 want_map_notify, u16 auth_data_len, u64 * nonce, |
| 155 | u32 * msg_len) |
| 156 | { |
| 157 | u8 *auth_data = 0; |
| 158 | |
| 159 | /* Basic header init */ |
| 160 | map_register_hdr_t *h = vlib_buffer_put_uninit (b, sizeof (h[0])); |
| 161 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 162 | clib_memset (h, 0, sizeof (h[0])); |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 163 | MREG_TYPE (h) = LISP_MAP_REGISTER; |
| 164 | MREG_NONCE (h) = nonce_build (0); |
| 165 | MREG_WANT_MAP_NOTIFY (h) = want_map_notify ? 1 : 0; |
| 166 | MREG_REC_COUNT (h) = vec_len (records); |
| 167 | |
| 168 | auth_data = vlib_buffer_put_uninit (b, auth_data_len); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 169 | clib_memset (auth_data, 0, auth_data_len); |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 170 | |
| 171 | /* Put map register records */ |
| 172 | lisp_msg_put_mreg_records (b, records); |
| 173 | |
| 174 | nonce[0] = MREG_NONCE (h); |
| 175 | msg_len[0] = vlib_buffer_get_tail (b) - (u8 *) h; |
| 176 | return h; |
| 177 | } |
| 178 | |
| 179 | void * |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 180 | lisp_msg_put_mreq (lisp_cp_main_t * lcm, vlib_buffer_t * b, |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 181 | gid_address_t * seid, gid_address_t * deid, |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 182 | gid_address_t * rlocs, u8 is_smr_invoked, |
| 183 | u8 rloc_probe_set, u64 * nonce) |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 184 | { |
| 185 | u8 loc_count = 0; |
| 186 | |
| 187 | /* Basic header init */ |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 188 | map_request_hdr_t *h = vlib_buffer_put_uninit (b, sizeof (h[0])); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 189 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 190 | clib_memset (h, 0, sizeof (h[0])); |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 191 | MREQ_TYPE (h) = LISP_MAP_REQUEST; |
| 192 | MREQ_NONCE (h) = nonce_build (0); |
| 193 | MREQ_SMR_INVOKED (h) = is_smr_invoked ? 1 : 0; |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 194 | MREQ_RLOC_PROBE (h) = rloc_probe_set ? 1 : 0; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 195 | |
| 196 | /* We're adding one eid record */ |
| 197 | increment_record_count (h); |
| 198 | |
| 199 | /* Fill source eid */ |
| 200 | lisp_msg_put_gid (b, seid); |
| 201 | |
| 202 | /* Put itr rlocs */ |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 203 | lisp_msg_put_itr_rlocs (lcm, b, rlocs, &loc_count); |
| 204 | MREQ_ITR_RLOC_COUNT (h) = loc_count; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 205 | |
| 206 | /* Put eid record */ |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 207 | lisp_msg_put_eid_rec (b, deid); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 208 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 209 | nonce[0] = MREQ_NONCE (h); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 210 | return h; |
| 211 | } |
| 212 | |
| 213 | void * |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 214 | lisp_msg_push_ecm (vlib_main_t * vm, vlib_buffer_t * b, int lp, int rp, |
| 215 | gid_address_t * la, gid_address_t * ra) |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 216 | { |
| 217 | ecm_hdr_t *h; |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 218 | ip_address_t _src_ip, *src_ip = &_src_ip, _dst_ip, *dst_ip = &_dst_ip; |
| 219 | if (gid_address_type (la) != GID_ADDR_IP_PREFIX) |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 220 | { |
| 221 | /* empty ip4 */ |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 222 | clib_memset (src_ip, 0, sizeof (src_ip[0])); |
| 223 | clib_memset (dst_ip, 0, sizeof (dst_ip[0])); |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 224 | } |
| 225 | else |
| 226 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 227 | src_ip = &gid_address_ip (la); |
| 228 | dst_ip = &gid_address_ip (ra); |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 229 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 230 | |
| 231 | /* Push inner ip and udp */ |
Florin Coras | fdbc382 | 2017-07-27 00:34:12 -0700 | [diff] [blame] | 232 | pkt_push_udp_and_ip (vm, b, lp, rp, src_ip, dst_ip, 0); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 233 | |
| 234 | /* Push lisp ecm hdr */ |
| 235 | h = pkt_push_ecm_hdr (b); |
| 236 | |
| 237 | return h; |
| 238 | } |
| 239 | |
| 240 | static u32 |
| 241 | msg_type_to_hdr_len (lisp_msg_type_e type) |
| 242 | { |
| 243 | switch (type) |
| 244 | { |
| 245 | case LISP_MAP_REQUEST: |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 246 | return (sizeof (map_request_hdr_t)); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 247 | case LISP_MAP_REPLY: |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 248 | return (sizeof (map_reply_hdr_t)); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 249 | default: |
| 250 | return (0); |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | void * |
| 255 | lisp_msg_pull_hdr (vlib_buffer_t * b, lisp_msg_type_e type) |
| 256 | { |
| 257 | return vlib_buffer_pull (b, msg_type_to_hdr_len (type)); |
| 258 | } |
| 259 | |
| 260 | u32 |
| 261 | lisp_msg_parse_addr (vlib_buffer_t * b, gid_address_t * eid) |
| 262 | { |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 263 | u32 len; |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 264 | clib_memset (eid, 0, sizeof (*eid)); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 265 | len = gid_address_parse (vlib_buffer_get_current (b), eid); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 266 | if (len != ~0) |
| 267 | vlib_buffer_pull (b, len); |
| 268 | return len; |
| 269 | } |
| 270 | |
| 271 | u32 |
| 272 | lisp_msg_parse_eid_rec (vlib_buffer_t * b, gid_address_t * eid) |
| 273 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 274 | eid_record_hdr_t *h = vlib_buffer_get_current (b); |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 275 | u32 len; |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 276 | clib_memset (eid, 0, sizeof (*eid)); |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 277 | len = gid_address_parse (EID_REC_ADDR (h), eid); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 278 | if (len == ~0) |
| 279 | return len; |
| 280 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 281 | gid_address_ippref_len (eid) = EID_REC_MLEN (h); |
| 282 | vlib_buffer_pull (b, len + sizeof (eid_record_hdr_t)); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 283 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 284 | return len + sizeof (eid_record_hdr_t); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | u32 |
| 288 | lisp_msg_parse_itr_rlocs (vlib_buffer_t * b, gid_address_t ** rlocs, |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 289 | u8 rloc_count) |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 290 | { |
| 291 | gid_address_t tloc; |
| 292 | u32 i, len = 0, tlen = 0; |
| 293 | |
| 294 | //MREQ_ITR_RLOC_COUNT(mreq_hdr) + 1 |
| 295 | for (i = 0; i < rloc_count; i++) |
| 296 | { |
| 297 | len = lisp_msg_parse_addr (b, &tloc); |
| 298 | if (len == ~0) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 299 | return len; |
| 300 | vec_add1 (*rlocs, tloc); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 301 | tlen += len; |
| 302 | } |
| 303 | return tlen; |
| 304 | } |
| 305 | |
| 306 | u32 |
| 307 | lisp_msg_parse_loc (vlib_buffer_t * b, locator_t * loc) |
| 308 | { |
| 309 | int len; |
| 310 | |
| 311 | len = locator_parse (vlib_buffer_get_current (b), loc); |
| 312 | if (len == ~0) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 313 | return ~0; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 314 | |
Filip Tehlar | 816f437 | 2017-04-26 16:09:06 +0200 | [diff] [blame] | 315 | if (!vlib_buffer_has_space (b, sizeof (len))) |
| 316 | return ~0; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 317 | vlib_buffer_pull (b, len); |
| 318 | |
| 319 | return len; |
| 320 | } |
| 321 | |
| 322 | u32 |
| 323 | lisp_msg_parse_mapping_record (vlib_buffer_t * b, gid_address_t * eid, |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 324 | locator_t ** locs, locator_t * probed_) |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 325 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 326 | void *h = 0, *loc_hdr = 0; |
| 327 | locator_t loc, *probed = 0; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 328 | int i = 0, len = 0, llen = 0; |
| 329 | |
| 330 | h = vlib_buffer_get_current (b); |
Filip Tehlar | 816f437 | 2017-04-26 16:09:06 +0200 | [diff] [blame] | 331 | if (!vlib_buffer_has_space (b, sizeof (mapping_record_hdr_t))) |
| 332 | return ~0; |
| 333 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 334 | vlib_buffer_pull (b, sizeof (mapping_record_hdr_t)); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 335 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 336 | clib_memset (eid, 0, sizeof (*eid)); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 337 | len = gid_address_parse (vlib_buffer_get_current (b), eid); |
| 338 | if (len == ~0) |
| 339 | return len; |
| 340 | |
Filip Tehlar | 816f437 | 2017-04-26 16:09:06 +0200 | [diff] [blame] | 341 | if (!vlib_buffer_has_space (b, sizeof (len))) |
| 342 | return ~0; |
| 343 | |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 344 | vlib_buffer_pull (b, len); |
Florin Coras | dca8804 | 2016-09-14 16:01:38 +0200 | [diff] [blame] | 345 | if (GID_ADDR_IP_PREFIX == gid_address_type (eid)) |
| 346 | gid_address_ippref_len (eid) = MAP_REC_EID_PLEN (h); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 347 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 348 | for (i = 0; i < MAP_REC_LOC_COUNT (h); i++) |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 349 | { |
| 350 | loc_hdr = vlib_buffer_get_current (b); |
| 351 | |
| 352 | llen = lisp_msg_parse_loc (b, &loc); |
| 353 | if (llen == ~0) |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 354 | return llen; |
| 355 | vec_add1 (*locs, loc); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 356 | len += llen; |
| 357 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 358 | if (LOC_PROBED (loc_hdr)) |
| 359 | { |
| 360 | if (probed != 0) |
| 361 | clib_warning |
| 362 | ("Multiple locators probed! Probing only the first!"); |
| 363 | else |
| 364 | probed = &loc; |
| 365 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 366 | } |
| 367 | /* XXX */ |
| 368 | if (probed_ != 0 && probed) |
| 369 | *probed_ = *probed; |
| 370 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 371 | return len + sizeof (map_reply_hdr_t); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 372 | } |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 373 | |
| 374 | /* |
| 375 | * fd.io coding-style-patch-verification: ON |
| 376 | * |
| 377 | * Local Variables: |
| 378 | * eval: (c-set-style "gnu") |
| 379 | * End: |
| 380 | */ |