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
48 } __attribute__ ((__packed__)) eid_record_hdr_t;
50 void eid_rec_hdr_init (eid_record_hdr_t * ptr);
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)
65 LISP_ENCAP_CONTROL_TYPE = 8,
70 * ENCAPSULATED CONTROL MESSAGE
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) |
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) |
90 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
91 * / | Source Port = xxxx | Dest Port = yyyy |
92 * UDP +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
93 * \ | UDP Length | UDP Checksum |
94 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
95 * LCM | LISP Control Message |
96 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
101 * Encapsulated control message header. This is followed by the IP
102 * header of the encapsulated LISP control message.
104 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
105 * |Type=8 |S| Reserved |
106 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
111 #if CLIB_ARCH_IS_LITTLE_ENDIAN
123 char *ecm_hdr_to_char (ecm_hdr_t * h);
125 #define ECM_TYPE(h_) ((ecm_hdr_t *)(h_))->type
128 * MAP-REQUEST MESSAGE
132 * Map-Request Message Format
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 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
140 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
142 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
143 * | Source-EID-AFI | Source EID Address ... |
144 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
145 * | ITR-RLOC-AFI 1 | ITR-RLOC Address 1 ... |
146 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
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 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
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.
169 #if CLIB_ARCH_IS_LITTLE_ENDIAN
170 u8 solicit_map_request:1;
172 u8 map_data_present:1;
178 u8 map_data_present:1;
180 u8 solicit_map_request:1;
182 #if CLIB_ARCH_IS_LITTLE_ENDIAN
191 #if CLIB_ARCH_IS_LITTLE_ENDIAN
192 u8 additional_itr_rloc_count:5;
196 u8 additional_itr_rloc_count:5;
200 } __attribute__ ((__packed__)) map_request_hdr_t;
202 void map_request_hdr_init (void *ptr);
203 char *map_request_hdr_to_char (map_request_hdr_t * h);
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
219 * Map-Reply Message Format
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 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
227 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
229 * +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
231 * | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
232 * R | Locator Count | EID mask-len | ACT |A| Reserved |
233 * e +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
234 * c | Rsvd | Map-Version Number | EID-AFI |
235 * o +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
237 * d +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
238 * | /| Priority | Weight | M Priority | M Weight |
239 * | L +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
240 * | o | Unused Flags |L|p|R| Loc-AFI |
241 * | c +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
243 * +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
244 * | Mapping Protocol Data |
245 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
249 * Fixed size portion of the map reply.
253 #if CLIB_ARCH_IS_LITTLE_ENDIAN
270 } __attribute__ ((__packed__)) map_reply_hdr_t;
272 void map_reply_hdr_init (void *ptr);
273 char *map_reply_hdr_to_char (map_reply_hdr_t * h);
275 #define MREP_HDR_CAST(h_) ((map_reply_hdr_t *)(h_))
276 #define MREP_REC_COUNT(h_) MREP_HDR_CAST(h_)->record_count
277 #define MREP_RLOC_PROBE(h_) MREP_HDR_CAST(h_)->rloc_probe
278 #define MREP_NONCE(h_) MREP_HDR_CAST(h_)->nonce
281 always_inline lisp_msg_type_e
282 lisp_msg_type (void *b)
287 return (NOT_LISP_MSG);
293 increment_record_count (void *b)
295 switch (lisp_msg_type (b))
297 case LISP_MAP_REQUEST:
298 MREQ_REC_COUNT (b) += 1;
301 MREP_REC_COUNT (b) += 1;
312 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
313 * /| Priority | Weight | M Priority | M Weight |
314 * L +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
315 * o | Unused Flags |L|p|R| Loc-AFI |
316 * c +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
318 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
320 * Fixed portion of the mapping record locator. Variable length
321 * locator address follows.
323 typedef struct _locator_hdr
330 #ifdef CLIB_ARCH_IS_LITTLE_ENDIAN
341 } __attribute__ ((__packed__)) locator_hdr_t;
343 #define LOC_CAST(h_) ((locator_hdr_t *)(h_))
344 #define LOC_PROBED(h_) LOC_CAST(h_)->probed
345 #define LOC_PRIORITY(h_) LOC_CAST(h_)->priority
346 #define LOC_WEIGHT(h_) LOC_CAST(h_)->weight
347 #define LOC_MPRIORITY(h_) LOC_CAST(h_)->mpriority
348 #define LOC_MWEIGHT(h_) LOC_CAST(h_)->mweight
349 #define LOC_REACHABLE(h_) LOC_CAST(h_)->reachable
350 #define LOC_LOCAL(h_) LOC_CAST(h_)->local
351 #define LOC_ADDR(h_) ((u8 *)(h_) + sizeof(locator_hdr_t))
356 * Mapping record used in all LISP control messages.
358 * +---> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
360 * | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
361 * R | Locator Count | EID mask-len | ACT |A| Reserved |
362 * e +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
363 * c | Rsvd | Map-Version Number | EID-AFI |
364 * o +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
366 * d +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
367 * | /| Priority | Weight | M Priority | M Weight |
368 * | / +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
369 * | Loc | Unused Flags |L|p|R| Loc-AFI |
370 * | \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
372 * +---> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
376 * Fixed portion of the mapping record. EID prefix address and
380 typedef struct _mapping_record_hdr_t
384 u8 eid_prefix_length;
385 #ifdef CLIB_ARCH_IS_LITTLE_ENDIAN
395 #ifdef CLIB_ARCH_IS_LITTLE_ENDIAN
403 } __attribute__ ((__packed__)) mapping_record_hdr_t;
405 void mapping_record_init_hdr (mapping_record_hdr_t * h);
407 #define MAP_REC_EID_PLEN(h) ((mapping_record_hdr_t *)(h))->eid_prefix_length
408 #define MAP_REC_LOC_COUNT(h) ((mapping_record_hdr_t *)(h))->locator_count
409 #define MAP_REC_ACTION(h) ((mapping_record_hdr_t *)(h))->action
410 #define MAP_REC_AUTH(h) ((mapping_record_hdr_t *)(h))->authoritative
411 #define MAP_REC_TTL(h) ((mapping_record_hdr_t *)(h))->ttl
412 #define MAP_REC_EID(h) (u8 *)(h)+sizeof(mapping_record_hdr_t)
413 #define MAP_REC_VERSION(h) (h)->version_hi << 8 | (h)->version_low
419 LISP_SEND_MAP_REQUEST,
423 typedef enum lisp_authoritative
425 A_NO_AUTHORITATIVE = 0,
427 } lisp_authoritative_e;
430 * LISP Canonical Address Format Encodings
433 * 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
434 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
435 * | AFI = 16387 | Rsvd1 | Flags |
436 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
437 * | Type | Rsvd2 | Length |
438 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
441 typedef struct _lcaf_hdr_t
448 } __attribute__ ((__packed__)) lcaf_hdr_t;
450 #define LCAF_TYPE(h) ((lcaf_hdr_t *)(h))->type
451 #define LCAF_LENGTH(h) ((lcaf_hdr_t *)(h))->len
452 #define LCAF_RES2(h) ((lcaf_hdr_t *)(h))->reserved2
453 #define LCAF_FLAGS(h) ((lcaf_hdr_t *)(h))->flags
454 #define LCAF_PAYLOAD(h) (u8 *)(h)+sizeof(lcaf_hdr_t)
457 * Source/Dest Key Canonical Address Format:
460 * 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
461 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
462 * | Reserved | Source-ML | Dest-ML |
463 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
465 typedef struct _lcaf_src_dst_hdr_t
470 } __attribute__ ((__packed__)) lcaf_src_dst_hdr_t;
472 #define LCAF_SD_SRC_ML(_h) (_h)->src_mask_len
473 #define LCAF_SD_DST_ML(_h) (_h)->dst_mask_len
475 #endif /* VNET_LISP_GPE_LISP_CP_MESSAGES_H_ */
478 * fd.io coding-style-patch-verification: ON
481 * eval: (c-set-style "gnu")