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 | #ifndef VNET_LISP_GPE_LISP_CP_MESSAGES_H_ |
| 17 | #define VNET_LISP_GPE_LISP_CP_MESSAGES_H_ |
| 18 | |
| 19 | #include <vnet/vnet.h> |
| 20 | |
| 21 | #define MAX_IP_PKT_LEN 4096 |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 22 | #define MAX_IP_HDR_LEN 40 /* without options or IPv6 hdr extensions */ |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 23 | #define UDP_HDR_LEN 8 |
| 24 | #define LISP_DATA_HDR_LEN 8 |
| 25 | #define LISP_ECM_HDR_LEN 4 |
| 26 | #define MAX_LISP_MSG_ENCAP_LEN 2*(MAX_IP_HDR_LEN + UDP_HDR_LEN)+ LISP_ECM_HDR_LEN |
| 27 | #define MAX_LISP_PKT_ENCAP_LEN MAX_IP_HDR_LEN + UDP_HDR_LEN + LISP_DATA_HDR_LEN |
| 28 | |
| 29 | #define LISP_CONTROL_PORT 4342 |
| 30 | |
| 31 | /* |
| 32 | * EID RECORD FIELD |
| 33 | */ |
| 34 | |
| 35 | /* |
| 36 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 37 | * / | Reserved | EID mask-len | EID-prefix-AFI | |
| 38 | * Rec +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 39 | * \ | EID-prefix ... | |
| 40 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 41 | */ |
| 42 | |
| 43 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 44 | typedef struct _eid_prefix_record_hdr |
| 45 | { |
| 46 | u8 reserved; |
| 47 | u8 eid_prefix_length; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 48 | } __attribute__ ((__packed__)) eid_record_hdr_t; |
| 49 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 50 | void eid_rec_hdr_init (eid_record_hdr_t * ptr); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 51 | |
| 52 | #define EID_REC_CAST(h_) ((eid_record_hdr_t *)(h_)) |
| 53 | #define EID_REC_MLEN(h_) EID_REC_CAST((h_))->eid_prefix_length |
| 54 | #define EID_REC_ADDR(h) (u8 *)(h) + sizeof(eid_record_hdr_t) |
| 55 | |
| 56 | /* LISP Types */ |
| 57 | typedef enum |
| 58 | { |
| 59 | NOT_LISP_MSG, |
| 60 | LISP_MAP_REQUEST = 1, |
| 61 | LISP_MAP_REPLY, |
| 62 | LISP_MAP_REGISTER, |
| 63 | LISP_MAP_NOTIFY, |
| 64 | LISP_INFO_NAT = 7, |
| 65 | LISP_ENCAP_CONTROL_TYPE = 8, |
| 66 | LISP_MSG_TYPES |
| 67 | } lisp_msg_type_e; |
| 68 | |
| 69 | /* |
| 70 | * ENCAPSULATED CONTROL MESSAGE |
| 71 | */ |
| 72 | |
| 73 | /* |
| 74 | * 0 1 2 3 |
| 75 | * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
| 76 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 77 | * / | IPv4 or IPv6 Header | |
| 78 | * OH | (uses RLOC addresses) | |
| 79 | * \ | | |
| 80 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 81 | * / | Source Port = xxxx | Dest Port = 4342 | |
| 82 | * UDP +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 83 | * \ | UDP Length | UDP Checksum | |
| 84 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 85 | * LH |Type=8 |S| Reserved | |
| 86 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 87 | * / | IPv4 or IPv6 Header | |
| 88 | * IH | (uses RLOC or EID addresses) | |
| 89 | * \ | | |
| 90 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 91 | * / | Source Port = xxxx | Dest Port = yyyy | |
| 92 | * UDP +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 93 | * \ | UDP Length | UDP Checksum | |
| 94 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 95 | * LCM | LISP Control Message | |
| 96 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 97 | */ |
| 98 | |
| 99 | |
| 100 | /* |
| 101 | * Encapsulated control message header. This is followed by the IP |
| 102 | * header of the encapsulated LISP control message. |
| 103 | * |
| 104 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 105 | * |Type=8 |S| Reserved | |
| 106 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 107 | */ |
| 108 | |
| 109 | typedef struct |
| 110 | { |
| 111 | #if CLIB_ARCH_IS_LITTLE_ENDIAN |
| 112 | u8 reserved:3; |
| 113 | u8 s_bit:1; |
| 114 | u8 type:4; |
| 115 | #else |
| 116 | u8 type:4; |
| 117 | u8 s_bit:1; |
| 118 | u8 reserved:3; |
| 119 | #endif |
| 120 | u8 reserved2[3]; |
| 121 | } ecm_hdr_t; |
| 122 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 123 | char *ecm_hdr_to_char (ecm_hdr_t * h); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 124 | |
| 125 | #define ECM_TYPE(h_) ((ecm_hdr_t *)(h_))->type |
| 126 | |
| 127 | /* |
| 128 | * MAP-REQUEST MESSAGE |
| 129 | */ |
| 130 | |
| 131 | /* |
| 132 | * Map-Request Message Format |
| 133 | * |
| 134 | * 0 1 2 3 |
| 135 | * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
| 136 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 137 | * |Type=1 |A|M|P|S|p|s| Reserved | IRC | Record Count | |
| 138 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 139 | * | Nonce . . . | |
| 140 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 141 | * | . . . Nonce | |
| 142 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 143 | * | Source-EID-AFI | Source EID Address ... | |
| 144 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 145 | * | ITR-RLOC-AFI 1 | ITR-RLOC Address 1 ... | |
| 146 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 147 | * | ... | |
| 148 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 149 | * | ITR-RLOC-AFI n | ITR-RLOC Address n ... | |
| 150 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 151 | * / | Reserved | EID mask-len | EID-prefix-AFI | |
| 152 | * Rec +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 153 | * \ | EID-prefix ... | |
| 154 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 155 | * | Map-Reply Record ... | |
| 156 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 157 | * | Mapping Protocol Data | |
| 158 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 159 | */ |
| 160 | |
| 161 | |
| 162 | /* |
| 163 | * Fixed size portion of the map request. Variable size source EID |
| 164 | * address, originating ITR RLOC AFIs and addresses and then map |
| 165 | * request records follow. |
| 166 | */ |
| 167 | typedef struct |
| 168 | { |
| 169 | #if CLIB_ARCH_IS_LITTLE_ENDIAN |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 170 | u8 solicit_map_request:1; |
| 171 | u8 rloc_probe:1; |
| 172 | u8 map_data_present:1; |
| 173 | u8 authoritative:1; |
| 174 | u8 type:4; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 175 | #else |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 176 | u8 type:4; |
| 177 | u8 authoritative:1; |
| 178 | u8 map_data_present:1; |
| 179 | u8 rloc_probe:1; |
| 180 | u8 solicit_map_request:1; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 181 | #endif |
| 182 | #if CLIB_ARCH_IS_LITTLE_ENDIAN |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 183 | u8 reserved1:6; |
| 184 | u8 smr_invoked:1; |
| 185 | u8 pitr:1; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 186 | #else |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 187 | u8 pitr:1; |
| 188 | u8 smr_invoked:1; |
| 189 | u8 reserved1:6; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 190 | #endif |
| 191 | #if CLIB_ARCH_IS_LITTLE_ENDIAN |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 192 | u8 additional_itr_rloc_count:5; |
| 193 | u8 reserved2:3; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 194 | #else |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 195 | u8 reserved2:3; |
| 196 | u8 additional_itr_rloc_count:5; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 197 | #endif |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 198 | u8 record_count; |
| 199 | u64 nonce; |
| 200 | } __attribute__ ((__packed__)) map_request_hdr_t; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 201 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 202 | void map_request_hdr_init (void *ptr); |
| 203 | char *map_request_hdr_to_char (map_request_hdr_t * h); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 204 | |
| 205 | #define MREQ_TYPE(h_) (h_)->type |
| 206 | #define MREQ_HDR_CAST(h_) ((map_request_hdr_t *)(h_)) |
| 207 | #define MREQ_REC_COUNT(h_) (MREQ_HDR_CAST(h_))->record_count |
| 208 | #define MREQ_RLOC_PROBE(h_) (MREQ_HDR_CAST(h_))->rloc_probe |
| 209 | #define MREQ_ITR_RLOC_COUNT(h_) (MREQ_HDR_CAST(h_))->additional_itr_rloc_count |
| 210 | #define MREQ_NONCE(h_) (MREQ_HDR_CAST(h_))->nonce |
| 211 | #define MREQ_SMR(h_) (MREQ_HDR_CAST(h_))->solicit_map_request |
| 212 | #define MREQ_SMR_INVOKED(h_) (MREQ_HDR_CAST(h_))->smr_invoked |
| 213 | |
| 214 | /* |
| 215 | * MAP-REPLY MESSAGE |
| 216 | */ |
| 217 | |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 218 | /* |
| 219 | * Map-Reply Message Format |
| 220 | * |
| 221 | * 0 1 2 3 |
| 222 | * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
| 223 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 224 | * |Type=2 |P|E|S| Reserved | Record Count | |
| 225 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 226 | * | Nonce . . . | |
| 227 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 228 | * | . . . Nonce | |
| 229 | * +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 230 | * | | Record TTL | |
| 231 | * | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 232 | * R | Locator Count | EID mask-len | ACT |A| Reserved | |
| 233 | * e +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 234 | * c | Rsvd | Map-Version Number | EID-AFI | |
| 235 | * o +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 236 | * r | EID-prefix | |
| 237 | * d +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 238 | * | /| Priority | Weight | M Priority | M Weight | |
| 239 | * | L +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 240 | * | o | Unused Flags |L|p|R| Loc-AFI | |
| 241 | * | c +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 242 | * | \| Locator | |
| 243 | * +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 244 | * | Mapping Protocol Data | |
| 245 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 246 | */ |
| 247 | |
| 248 | /* |
| 249 | * Fixed size portion of the map reply. |
| 250 | */ |
| 251 | typedef struct |
| 252 | { |
| 253 | #if CLIB_ARCH_IS_LITTLE_ENDIAN |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 254 | u8 reserved1:1; |
| 255 | u8 security:1; |
| 256 | u8 echo_nonce:1; |
| 257 | u8 rloc_probe:1; |
| 258 | u8 type:4; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 259 | #else |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 260 | u8 type:4; |
| 261 | u8 rloc_probe:1; |
| 262 | u8 echo_nonce:1; |
| 263 | u8 security:1; |
| 264 | u8 reserved1:1; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 265 | #endif |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 266 | u8 reserved2; |
| 267 | u8 reserved3; |
| 268 | u8 record_count; |
| 269 | u64 nonce; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 270 | } __attribute__ ((__packed__)) map_reply_hdr_t; |
| 271 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 272 | void map_reply_hdr_init (void *ptr); |
| 273 | char *map_reply_hdr_to_char (map_reply_hdr_t * h); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 274 | |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 275 | #define MREP_TYPE(h_) MREP_HDR_CAST(h_)->type |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 276 | #define MREP_HDR_CAST(h_) ((map_reply_hdr_t *)(h_)) |
| 277 | #define MREP_REC_COUNT(h_) MREP_HDR_CAST(h_)->record_count |
| 278 | #define MREP_RLOC_PROBE(h_) MREP_HDR_CAST(h_)->rloc_probe |
| 279 | #define MREP_NONCE(h_) MREP_HDR_CAST(h_)->nonce |
| 280 | |
| 281 | |
| 282 | always_inline lisp_msg_type_e |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 283 | lisp_msg_type (void *b) |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 284 | { |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 285 | ecm_hdr_t *hdr = b; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 286 | if (!hdr) |
| 287 | { |
| 288 | return (NOT_LISP_MSG); |
| 289 | } |
| 290 | return (hdr->type); |
| 291 | } |
| 292 | |
| 293 | always_inline void |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 294 | increment_record_count (void *b) |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 295 | { |
| 296 | switch (lisp_msg_type (b)) |
| 297 | { |
| 298 | case LISP_MAP_REQUEST: |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 299 | MREQ_REC_COUNT (b) += 1; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 300 | break; |
| 301 | case LISP_MAP_REPLY: |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 302 | MREP_REC_COUNT (b) += 1; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 303 | break; |
| 304 | default: |
| 305 | return; |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | |
| 310 | /* |
| 311 | * LOCATOR FIELD |
| 312 | * |
| 313 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 314 | * /| Priority | Weight | M Priority | M Weight | |
| 315 | * L +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 316 | * o | Unused Flags |L|p|R| Loc-AFI | |
| 317 | * c +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 318 | * \| Locator | |
| 319 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 320 | * |
| 321 | * Fixed portion of the mapping record locator. Variable length |
| 322 | * locator address follows. |
| 323 | */ |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 324 | typedef struct _locator_hdr |
| 325 | { |
| 326 | u8 priority; |
| 327 | u8 weight; |
| 328 | u8 mpriority; |
| 329 | u8 mweight; |
| 330 | u8 unused1; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 331 | #ifdef CLIB_ARCH_IS_LITTLE_ENDIAN |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 332 | u8 reachable:1; |
| 333 | u8 probed:1; |
| 334 | u8 local:1; |
| 335 | u8 unused2:5; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 336 | #else |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 337 | u8 unused2:5; |
| 338 | u8 local:1; |
| 339 | u8 probed:1; |
| 340 | u8 reachable:1; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 341 | #endif |
| 342 | } __attribute__ ((__packed__)) locator_hdr_t; |
| 343 | |
| 344 | #define LOC_CAST(h_) ((locator_hdr_t *)(h_)) |
| 345 | #define LOC_PROBED(h_) LOC_CAST(h_)->probed |
| 346 | #define LOC_PRIORITY(h_) LOC_CAST(h_)->priority |
| 347 | #define LOC_WEIGHT(h_) LOC_CAST(h_)->weight |
| 348 | #define LOC_MPRIORITY(h_) LOC_CAST(h_)->mpriority |
| 349 | #define LOC_MWEIGHT(h_) LOC_CAST(h_)->mweight |
| 350 | #define LOC_REACHABLE(h_) LOC_CAST(h_)->reachable |
| 351 | #define LOC_LOCAL(h_) LOC_CAST(h_)->local |
| 352 | #define LOC_ADDR(h_) ((u8 *)(h_) + sizeof(locator_hdr_t)) |
| 353 | |
| 354 | /* |
| 355 | * MAPPING RECORD |
| 356 | * |
| 357 | * Mapping record used in all LISP control messages. |
| 358 | * |
| 359 | * +---> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 360 | * | | Record TTL | |
| 361 | * | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 362 | * R | Locator Count | EID mask-len | ACT |A| Reserved | |
| 363 | * e +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 364 | * c | Rsvd | Map-Version Number | EID-AFI | |
| 365 | * o +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 366 | * r | EID-prefix | |
| 367 | * d +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 368 | * | /| Priority | Weight | M Priority | M Weight | |
| 369 | * | / +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 370 | * | Loc | Unused Flags |L|p|R| Loc-AFI | |
| 371 | * | \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 372 | * | \| Locator | |
| 373 | * +---> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 374 | */ |
| 375 | |
| 376 | /* |
| 377 | * Fixed portion of the mapping record. EID prefix address and |
| 378 | * locators follow. |
| 379 | */ |
| 380 | |
| 381 | typedef struct _mapping_record_hdr_t |
| 382 | { |
| 383 | u32 ttl; |
| 384 | u8 locator_count; |
| 385 | u8 eid_prefix_length; |
| 386 | #ifdef CLIB_ARCH_IS_LITTLE_ENDIAN |
| 387 | u8 reserved1:4; |
| 388 | u8 authoritative:1; |
| 389 | u8 action:3; |
| 390 | #else |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 391 | u8 action:3; |
| 392 | u8 authoritative:1; |
| 393 | u8 reserved1:4; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 394 | #endif |
| 395 | u8 reserved2; |
| 396 | #ifdef CLIB_ARCH_IS_LITTLE_ENDIAN |
| 397 | u8 version_hi:4; |
| 398 | u8 reserved3:4; |
| 399 | #else |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 400 | u8 reserved3:4; |
| 401 | u8 version_hi:4; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 402 | #endif |
| 403 | u8 version_low; |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 404 | } __attribute__ ((__packed__)) mapping_record_hdr_t; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 405 | |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 406 | void mapping_record_init_hdr (mapping_record_hdr_t * h); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 407 | |
| 408 | #define MAP_REC_EID_PLEN(h) ((mapping_record_hdr_t *)(h))->eid_prefix_length |
| 409 | #define MAP_REC_LOC_COUNT(h) ((mapping_record_hdr_t *)(h))->locator_count |
| 410 | #define MAP_REC_ACTION(h) ((mapping_record_hdr_t *)(h))->action |
| 411 | #define MAP_REC_AUTH(h) ((mapping_record_hdr_t *)(h))->authoritative |
| 412 | #define MAP_REC_TTL(h) ((mapping_record_hdr_t *)(h))->ttl |
| 413 | #define MAP_REC_EID(h) (u8 *)(h)+sizeof(mapping_record_hdr_t) |
| 414 | #define MAP_REC_VERSION(h) (h)->version_hi << 8 | (h)->version_low |
| 415 | |
Filip Tehlar | 53f09e3 | 2016-05-19 14:25:44 +0200 | [diff] [blame] | 416 | typedef enum |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 417 | { |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 418 | LISP_NO_ACTION, |
| 419 | LISP_FORWARD_NATIVE, |
| 420 | LISP_SEND_MAP_REQUEST, |
| 421 | LISP_DROP |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 422 | } lisp_action_e; |
| 423 | |
| 424 | typedef enum lisp_authoritative |
| 425 | { |
| 426 | A_NO_AUTHORITATIVE = 0, |
| 427 | A_AUTHORITATIVE |
| 428 | } lisp_authoritative_e; |
| 429 | |
Filip Tehlar | beceab9 | 2016-04-20 17:21:55 +0200 | [diff] [blame] | 430 | /* |
| 431 | * LISP Canonical Address Format Encodings |
| 432 | * |
| 433 | * 0 1 2 3 |
| 434 | * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
| 435 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 436 | * | AFI = 16387 | Rsvd1 | Flags | |
| 437 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 438 | * | Type | Rsvd2 | Length | |
| 439 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 440 | */ |
| 441 | |
| 442 | typedef struct _lcaf_hdr_t |
| 443 | { |
| 444 | u8 reserved1; |
| 445 | u8 flags; |
| 446 | u8 type; |
| 447 | u8 reserved2; |
| 448 | u16 len; |
| 449 | } __attribute__ ((__packed__)) lcaf_hdr_t; |
| 450 | |
| 451 | #define LCAF_TYPE(h) ((lcaf_hdr_t *)(h))->type |
| 452 | #define LCAF_LENGTH(h) ((lcaf_hdr_t *)(h))->len |
| 453 | #define LCAF_RES2(h) ((lcaf_hdr_t *)(h))->reserved2 |
| 454 | #define LCAF_FLAGS(h) ((lcaf_hdr_t *)(h))->flags |
| 455 | #define LCAF_PAYLOAD(h) (u8 *)(h)+sizeof(lcaf_hdr_t) |
| 456 | |
Filip Tehlar | 91c7d38 | 2016-08-02 19:37:26 +0200 | [diff] [blame] | 457 | /* |
| 458 | * Source/Dest Key Canonical Address Format: |
| 459 | * |
| 460 | * 0 1 2 3 |
| 461 | * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
| 462 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 463 | * | Reserved | Source-ML | Dest-ML | |
| 464 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 465 | */ |
| 466 | typedef struct _lcaf_src_dst_hdr_t |
| 467 | { |
| 468 | u16 reserved; |
| 469 | u8 src_mask_len; |
| 470 | u8 dst_mask_len; |
| 471 | } __attribute__ ((__packed__)) lcaf_src_dst_hdr_t; |
| 472 | |
| 473 | #define LCAF_SD_SRC_ML(_h) (_h)->src_mask_len |
| 474 | #define LCAF_SD_DST_ML(_h) (_h)->dst_mask_len |
| 475 | |
Filip Tehlar | 397fd7d | 2016-10-26 14:31:24 +0200 | [diff] [blame] | 476 | /* |
| 477 | * The Map-Register message format is: |
| 478 | * |
| 479 | * 0 1 2 3 |
| 480 | * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
| 481 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 482 | * |Type=3 |P| Reserved |M| Record Count | |
| 483 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 484 | * | Nonce . . . | |
| 485 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 486 | * | . . . Nonce | |
| 487 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 488 | * | Key ID | Authentication Data Length | |
| 489 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 490 | * ~ Authentication Data ~ |
| 491 | * +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 492 | * | | Record TTL | |
| 493 | * | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 494 | * R | Locator Count | EID mask-len | ACT |A| Reserved | |
| 495 | * e +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 496 | * c | Rsvd | Map-Version Number | EID-Prefix-AFI | |
| 497 | * o +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 498 | * r | EID-Prefix | |
| 499 | * d +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 500 | * | /| Priority | Weight | M Priority | M Weight | |
| 501 | * | L +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 502 | * | o | Unused Flags |L|p|R| Loc-AFI | |
| 503 | * | c +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 504 | * | \| Locator | |
| 505 | * +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 506 | */ |
| 507 | typedef struct |
| 508 | { |
| 509 | #if CLIB_ARCH_IS_LITTLE_ENDIAN |
| 510 | u8 res1:3; |
| 511 | u8 proxy_map_reply:1; |
| 512 | u8 type:4; |
| 513 | #else |
| 514 | u8 type:4; |
| 515 | u8 proxy_map_reply:1; |
| 516 | u8 res1:3; |
| 517 | #endif |
| 518 | |
| 519 | u8 res2; |
| 520 | |
| 521 | #if CLIB_ARCH_IS_LITTLE_ENDIAN |
| 522 | u8 want_map_notify:1; |
| 523 | u8 res3:7; |
| 524 | #else |
| 525 | u8 res3:7; |
| 526 | u8 want_map_notify:1; |
| 527 | #endif |
| 528 | |
| 529 | u8 record_count; |
| 530 | u64 nonce; |
| 531 | u16 key_id; |
| 532 | u16 auth_data_len; |
| 533 | u8 data[0]; |
| 534 | } __attribute__ ((__packed__)) map_register_hdr_t; |
| 535 | |
| 536 | #define MREG_TYPE(h_) (h_)->type |
| 537 | #define MREG_HDR_CAST(h_) ((map_register_hdr_t *)(h_)) |
| 538 | #define MREG_PROXY_MR(h_) (MREG_HDR_CAST(h_))->proxy_map_reply |
| 539 | #define MREG_WANT_MAP_NOTIFY(h_) (MREG_HDR_CAST(h_))->want_map_notify |
| 540 | #define MREG_REC_COUNT(h_) (MREG_HDR_CAST(h_))->record_count |
| 541 | #define MREG_NONCE(h_) (MREG_HDR_CAST(h_))->nonce |
| 542 | #define MREG_KEY_ID(h_) (MREG_HDR_CAST(h_))->key_id |
| 543 | #define MREG_AUTH_DATA_LEN(h_) (MREG_HDR_CAST(h_))->auth_data_len |
| 544 | #define MREG_DATA(h_) (MREG_HDR_CAST(h_))->data |
| 545 | |
| 546 | /* |
| 547 | * The Map-Notify message format is: |
| 548 | * |
| 549 | * 0 1 2 3 |
| 550 | * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
| 551 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 552 | * |Type=4 | Reserved | Record Count | |
| 553 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 554 | * | Nonce . . . | |
| 555 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 556 | * | . . . Nonce | |
| 557 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 558 | * | Key ID | Authentication Data Length | |
| 559 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 560 | * ~ Authentication Data ~ |
| 561 | * +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 562 | * | | Record TTL | |
| 563 | * | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 564 | * R | Locator Count | EID mask-len | ACT |A| Reserved | |
| 565 | * e +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 566 | * c | Rsvd | Map-Version Number | EID-Prefix-AFI | |
| 567 | * o +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 568 | * r | EID-Prefix | |
| 569 | * d +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 570 | * | /| Priority | Weight | M Priority | M Weight | |
| 571 | * | L +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 572 | * | o | Unused Flags |L|p|R| Loc-AFI | |
| 573 | * | c +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 574 | * | \| Locator | |
| 575 | * +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 576 | */ |
| 577 | |
| 578 | typedef struct |
| 579 | { |
| 580 | #if CLIB_ARCH_IS_LITTLE_ENDIAN |
| 581 | u8 res1:4; |
| 582 | u8 type:4; |
| 583 | #else |
| 584 | u8 type:4; |
| 585 | u8 res1:4; |
| 586 | #endif |
| 587 | |
| 588 | u16 res2; |
| 589 | |
| 590 | u8 record_count; |
| 591 | u64 nonce; |
| 592 | u16 key_id; |
| 593 | u16 auth_data_len; |
| 594 | u8 data[0]; |
| 595 | } __attribute__ ((__packed__)) map_notify_hdr_t; |
| 596 | |
| 597 | #define MNOTIFY_TYPE(h_) (h_)->type |
| 598 | #define MNOTIFY_HDR_CAST(h_) ((map_register_hdr_t *)(h_)) |
| 599 | #define MNOTIFY_REC_COUNT(h_) (MREG_HDR_CAST(h_))->record_count |
| 600 | #define MNOTIFY_NONCE(h_) (MREG_HDR_CAST(h_))->nonce |
| 601 | #define MNOTIFY_KEY_ID(h_) (MREG_HDR_CAST(h_))->key_id |
| 602 | #define MNOTIFY_AUTH_DATA_LEN(h_) (MREG_HDR_CAST(h_))->auth_data_len |
| 603 | #define MNOTIFY_DATA(h_) (MREG_HDR_CAST(h_))->data |
| 604 | |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 605 | #endif /* VNET_LISP_GPE_LISP_CP_MESSAGES_H_ */ |
Florin Coras | a2157cf | 2016-08-16 21:09:14 +0200 | [diff] [blame] | 606 | |
| 607 | /* |
| 608 | * fd.io coding-style-patch-verification: ON |
| 609 | * |
| 610 | * Local Variables: |
| 611 | * eval: (c-set-style "gnu") |
| 612 | * End: |
| 613 | */ |