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
217 /* Map Reply action codes */
218 #define LISP_ACTION_NO_ACTION 0
219 #define LISP_ACTION_FORWARD 1
220 #define LISP_ACTION_DROP 2
221 #define LISP_ACTION_SEND_MAP_REQUEST 3
224 * Map-Reply Message Format
227 * 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
228 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
229 * |Type=2 |P|E|S| Reserved | Record Count |
230 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
232 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
234 * +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
236 * | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
237 * R | Locator Count | EID mask-len | ACT |A| Reserved |
238 * e +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
239 * c | Rsvd | Map-Version Number | EID-AFI |
240 * o +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
242 * d +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
243 * | /| Priority | Weight | M Priority | M Weight |
244 * | L +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
245 * | o | Unused Flags |L|p|R| Loc-AFI |
246 * | c +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
248 * +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
249 * | Mapping Protocol Data |
250 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
254 * Fixed size portion of the map reply.
258 #if CLIB_ARCH_IS_LITTLE_ENDIAN
275 } __attribute__ ((__packed__)) map_reply_hdr_t;
277 void map_reply_hdr_init(void *ptr);
278 char *map_reply_hdr_to_char(map_reply_hdr_t *h);
280 #define MREP_HDR_CAST(h_) ((map_reply_hdr_t *)(h_))
281 #define MREP_REC_COUNT(h_) MREP_HDR_CAST(h_)->record_count
282 #define MREP_RLOC_PROBE(h_) MREP_HDR_CAST(h_)->rloc_probe
283 #define MREP_NONCE(h_) MREP_HDR_CAST(h_)->nonce
286 always_inline lisp_msg_type_e
287 lisp_msg_type (void * b)
292 return (NOT_LISP_MSG);
298 increment_record_count (void * b)
300 switch (lisp_msg_type (b))
302 case LISP_MAP_REQUEST:
303 MREQ_REC_COUNT(b) += 1;
306 MREP_REC_COUNT(b) += 1;
317 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
318 * /| Priority | Weight | M Priority | M Weight |
319 * L +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
320 * o | Unused Flags |L|p|R| Loc-AFI |
321 * c +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
323 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
325 * Fixed portion of the mapping record locator. Variable length
326 * locator address follows.
328 typedef struct _locator_hdr {
334 #ifdef CLIB_ARCH_IS_LITTLE_ENDIAN
345 } __attribute__ ((__packed__)) locator_hdr_t;
347 #define LOC_CAST(h_) ((locator_hdr_t *)(h_))
348 #define LOC_PROBED(h_) LOC_CAST(h_)->probed
349 #define LOC_PRIORITY(h_) LOC_CAST(h_)->priority
350 #define LOC_WEIGHT(h_) LOC_CAST(h_)->weight
351 #define LOC_MPRIORITY(h_) LOC_CAST(h_)->mpriority
352 #define LOC_MWEIGHT(h_) LOC_CAST(h_)->mweight
353 #define LOC_REACHABLE(h_) LOC_CAST(h_)->reachable
354 #define LOC_LOCAL(h_) LOC_CAST(h_)->local
355 #define LOC_ADDR(h_) ((u8 *)(h_) + sizeof(locator_hdr_t))
360 * Mapping record used in all LISP control messages.
362 * +---> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
364 * | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
365 * R | Locator Count | EID mask-len | ACT |A| Reserved |
366 * e +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
367 * c | Rsvd | Map-Version Number | EID-AFI |
368 * o +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
370 * d +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
371 * | /| Priority | Weight | M Priority | M Weight |
372 * | / +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
373 * | Loc | Unused Flags |L|p|R| Loc-AFI |
374 * | \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
376 * +---> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
380 * Fixed portion of the mapping record. EID prefix address and
384 typedef struct _mapping_record_hdr_t
388 u8 eid_prefix_length;
389 #ifdef CLIB_ARCH_IS_LITTLE_ENDIAN
399 #ifdef CLIB_ARCH_IS_LITTLE_ENDIAN
407 }__attribute__ ((__packed__)) mapping_record_hdr_t;
409 void mapping_record_init_hdr(mapping_record_hdr_t *h);
411 #define MAP_REC_EID_PLEN(h) ((mapping_record_hdr_t *)(h))->eid_prefix_length
412 #define MAP_REC_LOC_COUNT(h) ((mapping_record_hdr_t *)(h))->locator_count
413 #define MAP_REC_ACTION(h) ((mapping_record_hdr_t *)(h))->action
414 #define MAP_REC_AUTH(h) ((mapping_record_hdr_t *)(h))->authoritative
415 #define MAP_REC_TTL(h) ((mapping_record_hdr_t *)(h))->ttl
416 #define MAP_REC_EID(h) (u8 *)(h)+sizeof(mapping_record_hdr_t)
417 #define MAP_REC_VERSION(h) (h)->version_hi << 8 | (h)->version_low
419 typedef enum lisp_actions
427 typedef enum lisp_authoritative
429 A_NO_AUTHORITATIVE = 0,
431 } lisp_authoritative_e;
434 * LISP Canonical Address Format Encodings
437 * 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
438 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
439 * | AFI = 16387 | Rsvd1 | Flags |
440 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
441 * | Type | Rsvd2 | Length |
442 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
445 typedef struct _lcaf_hdr_t
452 } __attribute__ ((__packed__)) lcaf_hdr_t;
454 #define LCAF_TYPE(h) ((lcaf_hdr_t *)(h))->type
455 #define LCAF_LENGTH(h) ((lcaf_hdr_t *)(h))->len
456 #define LCAF_RES2(h) ((lcaf_hdr_t *)(h))->reserved2
457 #define LCAF_FLAGS(h) ((lcaf_hdr_t *)(h))->flags
458 #define LCAF_PAYLOAD(h) (u8 *)(h)+sizeof(lcaf_hdr_t)
460 #endif /* VNET_LISP_GPE_LISP_CP_MESSAGES_H_ */