lisp: Move to plugin
[vpp.git] / src / plugins / lisp / lisp-cp / lisp_cp_messages.h
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
22 #define MAX_IP_HDR_LEN 40       /* without options or IPv6 hdr extensions */
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
44 typedef struct _eid_prefix_record_hdr
45 {
46   u8 reserved;
47   u8 eid_prefix_length;
48 } __attribute__ ((__packed__)) eid_record_hdr_t;
49
50 void eid_rec_hdr_init (eid_record_hdr_t * ptr);
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
123 char *ecm_hdr_to_char (ecm_hdr_t * h);
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
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;
175 #else
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;
181 #endif
182 #if CLIB_ARCH_IS_LITTLE_ENDIAN
183   u8 reserved1:6;
184   u8 smr_invoked:1;
185   u8 pitr:1;
186 #else
187   u8 pitr:1;
188   u8 smr_invoked:1;
189   u8 reserved1:6;
190 #endif
191 #if CLIB_ARCH_IS_LITTLE_ENDIAN
192   u8 additional_itr_rloc_count:5;
193   u8 reserved2:3;
194 #else
195   u8 reserved2:3;
196   u8 additional_itr_rloc_count:5;
197 #endif
198   u8 record_count;
199   u64 nonce;
200 } __attribute__ ((__packed__)) map_request_hdr_t;
201
202 void map_request_hdr_init (void *ptr);
203 char *map_request_hdr_to_char (map_request_hdr_t * h);
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
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
254   u8 reserved1:1;
255   u8 security:1;
256   u8 echo_nonce:1;
257   u8 rloc_probe:1;
258   u8 type:4;
259 #else
260   u8 type:4;
261   u8 rloc_probe:1;
262   u8 echo_nonce:1;
263   u8 security:1;
264   u8 reserved1:1;
265 #endif
266   u8 reserved2;
267   u8 reserved3;
268   u8 record_count;
269   u64 nonce;
270 } __attribute__ ((__packed__)) map_reply_hdr_t;
271
272 void map_reply_hdr_init (void *ptr);
273 char *map_reply_hdr_to_char (map_reply_hdr_t * h);
274
275 #define MREP_TYPE(h_) MREP_HDR_CAST(h_)->type
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
283 lisp_msg_type (void *b)
284 {
285   ecm_hdr_t *hdr = b;
286   if (!hdr)
287     {
288       return (NOT_LISP_MSG);
289     }
290   return (hdr->type);
291 }
292
293 always_inline void
294 increment_record_count (void *b)
295 {
296   switch (lisp_msg_type (b))
297     {
298     case LISP_MAP_REQUEST:
299       MREQ_REC_COUNT (b) += 1;
300       break;
301     case LISP_MAP_REPLY:
302       MREP_REC_COUNT (b) += 1;
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  */
324 typedef struct _locator_hdr
325 {
326   u8 priority;
327   u8 weight;
328   u8 mpriority;
329   u8 mweight;
330   u8 unused1;
331 #ifdef CLIB_ARCH_IS_LITTLE_ENDIAN
332   u8 reachable:1;
333   u8 probed:1;
334   u8 local:1;
335   u8 unused2:5;
336 #else
337   u8 unused2:5;
338   u8 local:1;
339   u8 probed:1;
340   u8 reachable:1;
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
391   u8 action:3;
392   u8 authoritative:1;
393   u8 reserved1:4;
394 #endif
395   u8 reserved2;
396 #ifdef CLIB_ARCH_IS_LITTLE_ENDIAN
397   u8 version_hi:4;
398   u8 reserved3:4;
399 #else
400   u8 reserved3:4;
401   u8 version_hi:4;
402 #endif
403   u8 version_low;
404 } __attribute__ ((__packed__)) mapping_record_hdr_t;
405
406 void mapping_record_init_hdr (mapping_record_hdr_t * h);
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
416 typedef enum
417 {
418   LISP_NO_ACTION,
419   LISP_FORWARD_NATIVE,
420   LISP_SEND_MAP_REQUEST,
421   LISP_DROP
422 } lisp_action_e;
423
424 typedef enum lisp_authoritative
425 {
426   A_NO_AUTHORITATIVE = 0,
427   A_AUTHORITATIVE
428 } lisp_authoritative_e;
429
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
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
476 /*
477  * SPI LCAF
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  *   |              Service Path ID                  | Service index |
483  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
484  */
485 typedef struct _lcaf_spi_hdr_t
486 {
487   u32 spi_si;
488 } __attribute__ ((__packed__)) lcaf_spi_hdr_t;
489
490 #define LCAF_SPI_SI(_h) (_h)->spi_si
491
492 /*
493  * The Map-Register message format is:
494  *
495  *       0                   1                   2                   3
496  *       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
497  *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
498  *      |Type=3 |P|            Reserved               |M| Record Count  |
499  *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
500  *      |                         Nonce . . .                           |
501  *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
502  *      |                         . . . Nonce                           |
503  *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
504  *      |            Key ID             |  Authentication Data Length   |
505  *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
506  *      ~                     Authentication Data                       ~
507  *  +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
508  *  |   |                          Record TTL                           |
509  *  |   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
510  *  R   | Locator Count | EID mask-len  | ACT |A|      Reserved         |
511  *  e   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
512  *  c   | Rsvd  |  Map-Version Number   |        EID-Prefix-AFI         |
513  *  o   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
514  *  r   |                          EID-Prefix                           |
515  *  d   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
516  *  |  /|    Priority   |    Weight     |  M Priority   |   M Weight    |
517  *  | L +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
518  *  | o |        Unused Flags     |L|p|R|           Loc-AFI             |
519  *  | c +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
520  *  |  \|                             Locator                           |
521  *  +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
522  */
523 typedef struct
524 {
525 #if CLIB_ARCH_IS_LITTLE_ENDIAN
526   u8 res1:3;
527   u8 proxy_map_reply:1;
528   u8 type:4;
529 #else
530   u8 type:4;
531   u8 proxy_map_reply:1;
532   u8 res1:3;
533 #endif
534
535   u8 res2;
536
537 #if CLIB_ARCH_IS_LITTLE_ENDIAN
538   u8 want_map_notify:1;
539   u8 res3:7;
540 #else
541   u8 res3:7;
542   u8 want_map_notify:1;
543 #endif
544
545   u8 record_count;
546   u64 nonce;
547   u16 key_id;
548   u16 auth_data_len;
549   u8 data[0];
550 } __attribute__ ((__packed__)) map_register_hdr_t;
551
552 #define MREG_TYPE(h_) (h_)->type
553 #define MREG_HDR_CAST(h_) ((map_register_hdr_t *)(h_))
554 #define MREG_PROXY_MR(h_) (MREG_HDR_CAST(h_))->proxy_map_reply
555 #define MREG_WANT_MAP_NOTIFY(h_) (MREG_HDR_CAST(h_))->want_map_notify
556 #define MREG_REC_COUNT(h_) (MREG_HDR_CAST(h_))->record_count
557 #define MREG_NONCE(h_) (MREG_HDR_CAST(h_))->nonce
558 #define MREG_KEY_ID(h_) (MREG_HDR_CAST(h_))->key_id
559 #define MREG_AUTH_DATA_LEN(h_) (MREG_HDR_CAST(h_))->auth_data_len
560 #define MREG_DATA(h_) (MREG_HDR_CAST(h_))->data
561
562 /*
563  * The Map-Notify message format is:
564  *
565  *       0                   1                   2                   3
566  *       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
567  *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
568  *      |Type=4 |              Reserved                 | Record Count  |
569  *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
570  *      |                         Nonce . . .                           |
571  *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
572  *      |                         . . . Nonce                           |
573  *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
574  *      |            Key ID             |  Authentication Data Length   |
575  *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
576  *      ~                     Authentication Data                       ~
577  *  +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
578  *  |   |                          Record TTL                           |
579  *  |   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
580  *  R   | Locator Count | EID mask-len  | ACT |A|      Reserved         |
581  *  e   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
582  *  c   | Rsvd  |  Map-Version Number   |         EID-Prefix-AFI        |
583  *  o   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
584  *  r   |                          EID-Prefix                           |
585  *  d   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
586  *  |  /|    Priority   |    Weight     |  M Priority   |   M Weight    |
587  *  | L +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
588  *  | o |        Unused Flags     |L|p|R|           Loc-AFI             |
589  *  | c +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
590  *  |  \|                             Locator                           |
591  *  +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
592 */
593
594 typedef struct
595 {
596 #if CLIB_ARCH_IS_LITTLE_ENDIAN
597   u8 res1:4;
598   u8 type:4;
599 #else
600   u8 type:4;
601   u8 res1:4;
602 #endif
603
604   u16 res2;
605
606   u8 record_count;
607   u64 nonce;
608   u16 key_id;
609   u16 auth_data_len;
610   u8 data[0];
611 } __attribute__ ((__packed__)) map_notify_hdr_t;
612
613 #define MNOTIFY_TYPE(h_) (h_)->type
614 #define MNOTIFY_HDR_CAST(h_) ((map_register_hdr_t *)(h_))
615 #define MNOTIFY_REC_COUNT(h_) (MREG_HDR_CAST(h_))->record_count
616 #define MNOTIFY_NONCE(h_) (MREG_HDR_CAST(h_))->nonce
617 #define MNOTIFY_KEY_ID(h_) (MREG_HDR_CAST(h_))->key_id
618 #define MNOTIFY_AUTH_DATA_LEN(h_) (MREG_HDR_CAST(h_))->auth_data_len
619 #define MNOTIFY_DATA(h_) (MREG_HDR_CAST(h_))->data
620
621 /*
622  *   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
623  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
624  *  |Ver|O|C|R|R|R|R|R|R|   Length  |  MD type=0x1  | Next Protocol |
625  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
626  *  |          Service Path Identifer               | Service Index |
627  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
628  */
629
630 typedef struct
631 {
632   u32 header;
633   u32 spi_si;
634 } __attribute__ ((__packed__)) lisp_nsh_hdr_t;
635
636 #endif /* VNET_LISP_GPE_LISP_CP_MESSAGES_H_ */
637
638 /*
639  * fd.io coding-style-patch-verification: ON
640  *
641  * Local Variables:
642  * eval: (c-set-style "gnu")
643  * End:
644  */