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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef VNET_LISP_GPE_LISP_CP_MESSAGES_H_
17 #define VNET_LISP_GPE_LISP_CP_MESSAGES_H_
19 #include <vnet/vnet.h>
21 #define MAX_IP_PKT_LEN 4096
22 #define MAX_IP_HDR_LEN 40 /* without options or IPv6 hdr extensions */
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
29 #define LISP_CONTROL_PORT 4342
36 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37 * / | Reserved | EID mask-len | EID-prefix-AFI |
38 * Rec +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 * \ | EID-prefix ... |
40 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44 typedef struct _eid_prefix_record_hdr {
47 } __attribute__ ((__packed__)) eid_record_hdr_t;
49 void eid_rec_hdr_init(eid_record_hdr_t *ptr);
51 #define EID_REC_CAST(h_) ((eid_record_hdr_t *)(h_))
52 #define EID_REC_MLEN(h_) EID_REC_CAST((h_))->eid_prefix_length
53 #define EID_REC_ADDR(h) (u8 *)(h) + sizeof(eid_record_hdr_t)
64 LISP_ENCAP_CONTROL_TYPE = 8,
69 * ENCAPSULATED CONTROL MESSAGE
74 * 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
75 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
76 * / | IPv4 or IPv6 Header |
77 * OH | (uses RLOC addresses) |
79 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
80 * / | Source Port = xxxx | Dest Port = 4342 |
81 * UDP +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
82 * \ | UDP Length | UDP Checksum |
83 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
84 * LH |Type=8 |S| Reserved |
85 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
86 * / | IPv4 or IPv6 Header |
87 * IH | (uses RLOC or EID addresses) |
89 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
90 * / | Source Port = xxxx | Dest Port = yyyy |
91 * UDP +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
92 * \ | UDP Length | UDP Checksum |
93 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
94 * LCM | LISP Control Message |
95 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
100 * Encapsulated control message header. This is followed by the IP
101 * header of the encapsulated LISP control message.
103 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
104 * |Type=8 |S| Reserved |
105 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
110 #if CLIB_ARCH_IS_LITTLE_ENDIAN
122 char *ecm_hdr_to_char(ecm_hdr_t *h);
124 #define ECM_TYPE(h_) ((ecm_hdr_t *)(h_))->type
127 * MAP-REQUEST MESSAGE
131 * Map-Request Message Format
134 * 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
135 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
136 * |Type=1 |A|M|P|S|p|s| Reserved | IRC | Record Count |
137 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
139 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
141 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
142 * | Source-EID-AFI | Source EID Address ... |
143 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
144 * | ITR-RLOC-AFI 1 | ITR-RLOC Address 1 ... |
145 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
147 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
148 * | ITR-RLOC-AFI n | ITR-RLOC Address n ... |
149 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
150 * / | Reserved | EID mask-len | EID-prefix-AFI |
151 * Rec +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
152 * \ | EID-prefix ... |
153 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
154 * | Map-Reply Record ... |
155 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
156 * | Mapping Protocol Data |
157 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
162 * Fixed size portion of the map request. Variable size source EID
163 * address, originating ITR RLOC AFIs and addresses and then map
164 * request records follow.
168 #if CLIB_ARCH_IS_LITTLE_ENDIAN
169 u8 solicit_map_request:1;
171 u8 map_data_present:1;
177 u8 map_data_present:1;
179 u8 solicit_map_request:1;
181 #if CLIB_ARCH_IS_LITTLE_ENDIAN
190 #if CLIB_ARCH_IS_LITTLE_ENDIAN
191 u8 additional_itr_rloc_count:5;
195 u8 additional_itr_rloc_count:5;
199 }__attribute__ ((__packed__)) map_request_hdr_t;
201 void map_request_hdr_init(void *ptr);
202 char *map_request_hdr_to_char(map_request_hdr_t *h);
204 #define MREQ_TYPE(h_) (h_)->type
205 #define MREQ_HDR_CAST(h_) ((map_request_hdr_t *)(h_))
206 #define MREQ_REC_COUNT(h_) (MREQ_HDR_CAST(h_))->record_count
207 #define MREQ_RLOC_PROBE(h_) (MREQ_HDR_CAST(h_))->rloc_probe
208 #define MREQ_ITR_RLOC_COUNT(h_) (MREQ_HDR_CAST(h_))->additional_itr_rloc_count
209 #define MREQ_NONCE(h_) (MREQ_HDR_CAST(h_))->nonce
210 #define MREQ_SMR(h_) (MREQ_HDR_CAST(h_))->solicit_map_request
211 #define MREQ_SMR_INVOKED(h_) (MREQ_HDR_CAST(h_))->smr_invoked
218 * Map-Reply Message Format
221 * 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
222 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
223 * |Type=2 |P|E|S| Reserved | Record Count |
224 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
226 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
228 * +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
230 * | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
231 * R | Locator Count | EID mask-len | ACT |A| Reserved |
232 * e +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
233 * c | Rsvd | Map-Version Number | EID-AFI |
234 * o +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
236 * d +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
237 * | /| Priority | Weight | M Priority | M Weight |
238 * | L +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
239 * | o | Unused Flags |L|p|R| Loc-AFI |
240 * | c +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
242 * +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
243 * | Mapping Protocol Data |
244 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
248 * Fixed size portion of the map reply.
252 #if CLIB_ARCH_IS_LITTLE_ENDIAN
269 } __attribute__ ((__packed__)) map_reply_hdr_t;
271 void map_reply_hdr_init(void *ptr);
272 char *map_reply_hdr_to_char(map_reply_hdr_t *h);
274 #define MREP_HDR_CAST(h_) ((map_reply_hdr_t *)(h_))
275 #define MREP_REC_COUNT(h_) MREP_HDR_CAST(h_)->record_count
276 #define MREP_RLOC_PROBE(h_) MREP_HDR_CAST(h_)->rloc_probe
277 #define MREP_NONCE(h_) MREP_HDR_CAST(h_)->nonce
280 always_inline lisp_msg_type_e
281 lisp_msg_type (void * b)
286 return (NOT_LISP_MSG);
292 increment_record_count (void * b)
294 switch (lisp_msg_type (b))
296 case LISP_MAP_REQUEST:
297 MREQ_REC_COUNT(b) += 1;
300 MREP_REC_COUNT(b) += 1;
311 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
312 * /| Priority | Weight | M Priority | M Weight |
313 * L +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
314 * o | Unused Flags |L|p|R| Loc-AFI |
315 * c +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
317 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
319 * Fixed portion of the mapping record locator. Variable length
320 * locator address follows.
322 typedef struct _locator_hdr {
328 #ifdef CLIB_ARCH_IS_LITTLE_ENDIAN
339 } __attribute__ ((__packed__)) locator_hdr_t;
341 #define LOC_CAST(h_) ((locator_hdr_t *)(h_))
342 #define LOC_PROBED(h_) LOC_CAST(h_)->probed
343 #define LOC_PRIORITY(h_) LOC_CAST(h_)->priority
344 #define LOC_WEIGHT(h_) LOC_CAST(h_)->weight
345 #define LOC_MPRIORITY(h_) LOC_CAST(h_)->mpriority
346 #define LOC_MWEIGHT(h_) LOC_CAST(h_)->mweight
347 #define LOC_REACHABLE(h_) LOC_CAST(h_)->reachable
348 #define LOC_LOCAL(h_) LOC_CAST(h_)->local
349 #define LOC_ADDR(h_) ((u8 *)(h_) + sizeof(locator_hdr_t))
354 * Mapping record used in all LISP control messages.
356 * +---> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
358 * | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
359 * R | Locator Count | EID mask-len | ACT |A| Reserved |
360 * e +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
361 * c | Rsvd | Map-Version Number | EID-AFI |
362 * o +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
364 * d +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
365 * | /| Priority | Weight | M Priority | M Weight |
366 * | / +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
367 * | Loc | Unused Flags |L|p|R| Loc-AFI |
368 * | \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
370 * +---> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
374 * Fixed portion of the mapping record. EID prefix address and
378 typedef struct _mapping_record_hdr_t
382 u8 eid_prefix_length;
383 #ifdef CLIB_ARCH_IS_LITTLE_ENDIAN
393 #ifdef CLIB_ARCH_IS_LITTLE_ENDIAN
401 }__attribute__ ((__packed__)) mapping_record_hdr_t;
403 void mapping_record_init_hdr(mapping_record_hdr_t *h);
405 #define MAP_REC_EID_PLEN(h) ((mapping_record_hdr_t *)(h))->eid_prefix_length
406 #define MAP_REC_LOC_COUNT(h) ((mapping_record_hdr_t *)(h))->locator_count
407 #define MAP_REC_ACTION(h) ((mapping_record_hdr_t *)(h))->action
408 #define MAP_REC_AUTH(h) ((mapping_record_hdr_t *)(h))->authoritative
409 #define MAP_REC_TTL(h) ((mapping_record_hdr_t *)(h))->ttl
410 #define MAP_REC_EID(h) (u8 *)(h)+sizeof(mapping_record_hdr_t)
411 #define MAP_REC_VERSION(h) (h)->version_hi << 8 | (h)->version_low
417 LISP_SEND_MAP_REQUEST,
421 typedef enum lisp_authoritative
423 A_NO_AUTHORITATIVE = 0,
425 } lisp_authoritative_e;
428 * LISP Canonical Address Format Encodings
431 * 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
432 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
433 * | AFI = 16387 | Rsvd1 | Flags |
434 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
435 * | Type | Rsvd2 | Length |
436 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
439 typedef struct _lcaf_hdr_t
446 } __attribute__ ((__packed__)) lcaf_hdr_t;
448 #define LCAF_TYPE(h) ((lcaf_hdr_t *)(h))->type
449 #define LCAF_LENGTH(h) ((lcaf_hdr_t *)(h))->len
450 #define LCAF_RES2(h) ((lcaf_hdr_t *)(h))->reserved2
451 #define LCAF_FLAGS(h) ((lcaf_hdr_t *)(h))->flags
452 #define LCAF_PAYLOAD(h) (u8 *)(h)+sizeof(lcaf_hdr_t)
454 #endif /* VNET_LISP_GPE_LISP_CP_MESSAGES_H_ */