-
Notifications
You must be signed in to change notification settings - Fork 6
/
udp.h
876 lines (789 loc) · 26.8 KB
/
udp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
#ifndef __HAVE_UDP_H
#define __HAVE_UDP_H
#define LISP_AFI_IP 1
#define LISP_AFI_IPV6 2
#define BUFLEN 512
#define PKBUFLEN 65527
#define LISP_TYPE_RESERVED 0x0
#define LISP_TYPE_MAP_REQUEST 0x1
#define LISP_TYPE_MAP_REPLY 0x2
#define LISP_TYPE_MAP_REGISTER 0x3
#define LISP_TYPE_MAP_NOTIFY 0x4
#define LISP_TYPE_MAP_REFERRAL 0x6
#define LISP_TYPE_ENCAPSULATED_CONTROL_MESSAGE 0x8
#define LISP_TYPE_INFO_MSG 0x7
#define LCAF_AFI 16387
#define LCAF_NATT 7
#define LCAF_TE 10
/*
* CO --
*
* Calculate Offset
*
* Try not to make dumb mistakes with
* pointer arithmetic
*
*/
/* <AFI, Address> tuple IPv4 */
struct afi_address {
uint16_t afi;
struct in_addr address;
} __attribute__ ((__packed__));
/* <AFI, Address> tuple IPv6 */
struct afi_address6 {
uint16_t afi;
struct in6_addr address;
} __attribute__ ((__packed__));
/* <AFI, Address> tuple IPv4 and IPv6*/
union afi_address_generic {
struct afi_address ip;
struct afi_address6 ip6;
};
/*
0 1 2 3
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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Type=6 | Reserved | Record Count |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Nonce . . . |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| . . . Nonce |
+-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | Record TTL |
| +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
R | Referral Count| EID mask-len | ACT |A|I| Reserved |
e +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
c |SigCnt | Map Version Number | EID-AFI |
o +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
r | EID-prefix ... |
d +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| /| Priority | Weight | M Priority | M Weight |
| L +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| o | Unused Flags |R| Loc/LCAF-AFI |
| c +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| \| Locator ... |
+-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
0 1 2 3
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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| AFI = 16387 | Rsvd1 | Flags |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type = 2 | IID mask-len | 4 + n |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Instance ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| AFI = x | Address ... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
struct map_referral_lcaf_afi {
uint16_t afi;
uint8_t rsvd1;
uint8_t flags;
uint8_t type;
uint8_t iid_masklen;
uint16_t length;
uint32_t iid;
};
struct map_referral_hdr {
#ifdef LITTLE_ENDIAN
uint8_t rsvd:4;
uint8_t lisp_type:4;
#else
uint8_t lisp_type:4;
uint8_t rsvd:4;
#endif
uint16_t reserved;
uint8_t record_count;
uint64_t nonce;
} __attribute__ ((__packed__));
struct map_referral_record {
uint32_t ttl;
uint8_t referral_count;
uint8_t eid_mask_len;
#ifdef LITTLE_ENDIAN
uint8_t reserved:3;
uint8_t i:1;
uint8_t a:1;
uint8_t act:3;
#else
uint8_t act:3;
uint8_t a:1;
uint8_t i:1;
uint8_t reserved:3;
#endif
uint8_t reserved1;
#ifdef LITTLE_ENDIAN
uint16_t version:12;
uint16_t sig_cnt:4;
#else
uint16_t sigcnt:4;
uint16_t version:12;
#endif
struct map_referral_lcaf_afi lcaf;
uint16_t eid_prefix_afi;
struct in_addr eid_prefix;
} __attribute__ ((__packed__));
struct map_referral_record6 {
uint32_t ttl;
uint8_t referral_count;
uint8_t eid_mask_len;
#ifdef LITTLE_ENDIAN
uint8_t reserved:3;
uint8_t i:1;
uint8_t a:1;
uint8_t act:3;
#else
uint8_t act:3;
uint8_t a:1;
uint8_t i:1;
uint8_t reserved:3;
#endif
uint8_t reserved1;
#ifdef LITTLE_ENDIAN
uint16_t version:12;
uint16_t sig_cnt:4;
#else
uint16_t sigcnt:4;
uint16_t version:12;
#endif
struct map_referral_lcaf_afi lcaf;
uint16_t eid_prefix_afi;
struct in6_addr eid_prefix;
} __attribute__ ((__packed__));
union map_referral_record_generic {
struct map_referral_record record;
struct map_referral_record6 record6;
};
struct map_referral_locator {
uint8_t priority;
uint8_t weight;
uint8_t m_priority;
uint8_t m_weight;
uint8_t unused_flags;
#ifdef LITTLE_ENDIAN
uint8_t R:1;
uint8_t unused_flags1:7;
#else
uint8_t unused_flags1:7;
uint8_t R:1;
#endif
uint16_t rloc_afi;
struct in_addr rloc;
} __attribute__ ((__packed__));
struct map_referral_locator6 {
uint8_t priority;
uint8_t weight;
uint8_t m_priority;
uint8_t m_weight;
uint8_t unused_flags;
#ifdef LITTLE_ENDIAN
uint8_t R:1;
uint8_t unused_flags1:7;
#else
uint8_t unused_flags1:7;
uint8_t R:1;
#endif
uint16_t rloc_afi;
struct in6_addr rloc;
} __attribute__ ((__packed__));
union map_referral_locator_generic {
struct map_referral_locator rloc;
struct map_referral_locator6 rloc6;
};
/*
0 1 2 3
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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Type=2 |P|E|S| Reserved | Record Count |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Nonce . . . |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| . . . Nonce |
+-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | Record TTL |
| +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
R | Locator Count | EID mask-len | ACT |A| Reserved |
e +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
c | Rsvd | Map-Version Number | EID-AFI |
o +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
r | EID-prefix |
d +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| /| Priority | Weight | M Priority | M Weight |
| L +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| o | Unused Flags |L|p|R| Loc-AFI |
| c +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| \| Locator |
+-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
struct map_reply_hdr {
#ifdef LITTLE_ENDIAN
uint8_t rsvd:1;
uint8_t security_bit:1;
uint8_t echo_nonce_capable:1;
uint8_t rloc_probe:1;
uint8_t lisp_type:4;
#else
uint8_t lisp_type:4;
uint8_t rloc_probe:1;
uint8_t echo_nonce_capable:1;
uint8_t security_bit:1;
uint8_t rsvd:1;
#endif
uint16_t reserved;
uint8_t record_count;
uint64_t nonce;
} __attribute__ ((__packed__));
struct map_reply_record {
uint32_t ttl;
uint8_t locator_count;
uint8_t eid_mask_len;
#ifdef LITTLE_ENDIAN
uint8_t reserved:4;
uint8_t a:1;
uint8_t act:3;
#else
uint8_t act:3;
uint8_t a:1;
uint8_t reserved:4;
#endif
uint8_t reserved1;
#ifdef LITTLE_ENDIAN
uint16_t version:12;
uint16_t rsvd:4;
#else
uint16_t rsvd:4;
uint16_t version:12;
#endif
uint16_t eid_prefix_afi;
struct in_addr eid_prefix;
} __attribute__ ((__packed__));
struct map_reply_record6 {
uint32_t ttl;
uint8_t locator_count;
uint8_t eid_mask_len;
#ifdef LITTLE_ENDIAN
uint8_t reserved:4;
uint8_t a:1;
uint8_t act:3;
#else
uint8_t act:3;
uint8_t a:1;
uint8_t reserved:4;
#endif
uint8_t reserved1;
#ifdef LITTLE_ENDIAN
uint16_t version:12;
uint16_t rsvd:4;
#else
uint16_t rsvd:4;
uint16_t version:12;
#endif
uint16_t eid_prefix_afi;
struct in6_addr eid_prefix;
} __attribute__ ((__packed__));
union map_reply_record_generic {
struct map_reply_record record;
struct map_reply_record6 record6;
};
struct map_reply_locator {
uint8_t priority;
uint8_t weight;
uint8_t m_priority;
uint8_t m_weight;
uint8_t unused_flags;
#ifdef LITTLE_ENDIAN
uint8_t R:1;
uint8_t p:1;
uint8_t L:1;
uint8_t unused_flags1:5;
#else
uint8_t unused_flags1:5;
uint8_t L:1;
uint8_t p:1;
uint8_t R:1;
#endif
uint16_t rloc_afi;
struct in_addr rloc;
} __attribute__ ((__packed__));
struct map_reply_locator6 {
uint8_t priority;
uint8_t weight;
uint8_t m_priority;
uint8_t m_weight;
uint8_t unused_flags;
#ifdef LITTLE_ENDIAN
uint8_t R:1;
uint8_t p:1;
uint8_t L:1;
uint8_t unused_flags1:5;
#else
uint8_t unused_flags1:5;
uint8_t L:1;
uint8_t p:1;
uint8_t R:1;
#endif
uint16_t rloc_afi;
struct in6_addr rloc;
} __attribute__ ((__packed__));
union map_reply_locator_generic {
struct map_reply_locator rloc;
struct map_reply_locator6 rloc6;
};
struct lcaf_hdr{
uint16_t afi;
uint8_t reserved;
uint8_t flags;
uint8_t type;
uint8_t reserved2;
uint16_t payload_len;
};
struct rloc_te{
#ifdef LITTLE_ENDIAN
uint16_t reserved:13;
uint8_t L:1;
uint8_t P:1;
uint8_t S:1;
#else
uint8_t L:3;
uint8_t P:1;
uint8_t S:1;
uint8_t reserved:13;
#endif
uint16_t afi;
struct in_addr hop_addr;
};
struct rloc6_te{
#ifdef LITTLE_ENDIAN
uint16_t reserved:13;
uint8_t L:1;
uint8_t P:1;
uint8_t S:1;
#else
uint8_t L:3;
uint8_t P:1;
uint8_t S:1;
uint8_t reserved:13;
#endif
uint16_t afi;
struct in6_addr hop_addr;
};
union rloc_te_generic {
struct rloc_te rloc;
struct rloc6_te rloc6;
};
struct map_reply_locator_te {
uint8_t priority;
uint8_t weight;
uint8_t m_priority;
uint8_t m_weight;
uint8_t unused_flags;
#ifdef LITTLE_ENDIAN
uint8_t R:1;
uint8_t p:1;
uint8_t L:1;
uint8_t unused_flags1:5;
#else
uint8_t unused_flags1:5;
uint8_t L:1;
uint8_t p:1;
uint8_t R:1;
#endif
struct lcaf_hdr lcaf;
} __attribute__ ((__packed__));
/* Map-Referral handling code */
void * udp_map_referral_init(void *data);
int udp_map_referral_add_record(void *data, uint32_t iid, struct prefix *p,
uint32_t ttl, uint8_t lcount, uint32_t version,
uint8_t A, uint8_t act, uint8_t i, uint8_t sigcnt);
int udp_map_referral_add_locator(void *data, struct map_entry *e);
int udp_map_referral_error(void *data);
int udp_map_referral_terminate(void *data);
/* ! Map-Referral handling code */
/* Map-Reply handling code */
void *udp_map_reply_init(void *data);
int udp_map_reply_add_record(void *data, struct prefix *p,
uint32_t ttl, uint8_t lcount,
uint32_t version, uint8_t A, uint8_t act);
int udp_map_reply_add_locator(void *data, struct map_entry *e);
int udp_map_reply_terminate(void *data);
/* ! Map-Reply handling code */
/* Map-Request handling code */
struct map_request{
char *eid;
uint64_t nonce;
};
int udp_request_terminate(void *data);
int udp_request_get_eid(void *data, struct prefix *p);
uint64_t udp_request_get_nonce(void *data);
int udp_request_is_ddt(void *data);
int udp_request_get_itr(void *data, union sockunion *itr, int afi);
int udp_request_get_port(void *data, uint16_t *port);
void *udp_request_add(void *data, uint8_t security, uint8_t ddt,\
uint8_t A, uint8_t M, uint8_t P, uint8_t S,\
uint8_t p, uint8_t s, uint64_t nonce,\
const union sockunion *src, \
const union sockunion *dst, \
const struct prefix *eid );
uint32_t _forward_to_etr(void *data, struct db_node *rn);
int _send_negative_map_reply(void *data, struct communication_fct *fct, \
struct db_node *rn, struct prefix *pf, uint32_t ttl, uint8_t A, uint8_t act, uint8_t version );
/* ! Map-Request handling code */
/* Communication handling code */
void *udp_start_communication(void *context);
void *udp_stop_communication(void *context);
/* Map Serveur specifique fonctions */
void *_ms_recal_hashing(const void *packet, int pk_len, void *key, void *rt, int no_nonce);
int ms_process_info_req(struct pk_req_entry *pke);
int addrcmp(union sockunion *src, union sockunion *dst);
uint8_t *build_encap_pkt(uint8_t *pkt, size_t pkt_len, void *lisp_oh,
size_t lisp_oh_len, const union sockunion *src,
const union sockunion *dst, size_t *buf_len);
size_t _get_reply_record_size(const union map_reply_record_generic *rec);
/* RTR specifique fonctions */
int rtr_process_map_register(struct pk_req_entry *pke);
int rtr_process_map_notify(struct pk_req_entry *pke);
/*
* Map-Request draft-ietf-lisp-22 structures definition
* Map encapsulated control message draft-fuller-lisp-ddt-00
*
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
LH |Type=8 |S|D|R|N| Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ | IPv4 or IPv6 Header |
IH | (uses RLOC or EID addresses) |
\ | |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ | Source Port = xxxx | Dest Port = yyyy |
UDP +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
\ | UDP Length | UDP Checksum |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
LCM |Type=1 |A|M|P|S|p|s| Reserved | IRC | Record Count |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Nonce . . . |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| . . . Nonce |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Source-EID-AFI | Source EID Address ... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ITR-RLOC-AFI 1 | ITR-RLOC Address 1 ... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ITR-RLOC-AFI n | ITR-RLOC Address n ... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ | Reserved | EID mask-len | EID-prefix-AFI |
Rec +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
\ | EID-prefix ... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Map-Reply Record ... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
struct lisp_control_hdr {
#ifdef LITTLE_ENDIAN
uint8_t N:1;
uint8_t R:1;
uint8_t ddt_originated:1;
uint8_t security_bit:1;
uint8_t type:4;
#else
uint8_t type:4;
uint8_t security_bit:1;
uint8_t ddt_originated:1;
uint8_t R:1;
uint8_t N:1;
#endif
uint8_t reserved[3];
} __attribute__ ((__packed__));
struct map_request_hdr {
#ifdef LITTLE_ENDIAN
uint8_t smr_bit:1;
uint8_t rloc_probe:1;
uint8_t map_data_present:1;
uint8_t auth_bit:1;
uint8_t lisp_type:4;
#else
uint8_t lisp_type:4;
uint8_t auth_bit:1;
uint8_t map_data_present:1;
uint8_t rloc_probe:1;
uint8_t smr_bit:1;
#endif
#ifdef LITTLE_ENDIAN
uint8_t reserved1:6;
uint8_t smr_invoke_bit:1;
uint8_t pitr_bit:1;
#else
uint8_t pitr_bit:1;
uint8_t smr_invoke_bit:1;
uint8_t reserved1:6;
#endif
#ifdef LITTLE_ENDIAN
uint8_t irc:5;
uint8_t reserved2:3;
#else
uint8_t reserved2:3;
uint8_t irc:5;
#endif
uint8_t record_count;
uint64_t nonce;
} __attribute__ ((__packed__));
/* Map-Request record tuple IPv4 */
struct map_request_record {
uint8_t reserved;
uint8_t eid_mask_len;
uint16_t eid_prefix_afi;
struct in_addr eid_prefix;
} __attribute__ ((__packed__));
/* Map-Request record tuple IPv6 */
struct map_request_record6 {
uint8_t reserved;
uint8_t eid_mask_len;
uint16_t eid_prefix_afi;
struct in6_addr eid_prefix;
} __attribute__ ((__packed__));
/* Map-Request record tuple IPv4 and IPv6 */
union map_request_record_generic {
struct map_request_record record;
struct map_request_record6 record6;
};
/*
0 1 2 3
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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| AFI = 16387 | Rsvd1 | Flags |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type = 2 | IID mask-len | 4 + n |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Instance ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| AFI = x | Address ... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
struct map_request_record_lcaf {
uint8_t reserved;
uint8_t eid_mask_len;
uint16_t afi;
uint8_t rsvd1;
uint8_t flags;
uint8_t type;
uint8_t iid_masklen;
uint16_t length;
uint32_t iid;
uint16_t eid_prefix_afi;
struct in_addr eid_prefix;
} __attribute__ ((__packed__));
struct map_request_record6_lcaf {
uint8_t reserved;
uint8_t eid_mask_len;
uint16_t afi;
uint8_t rsvd1;
uint8_t flags;
uint8_t type;
uint8_t iid_masklen;
uint16_t length;
uint32_t iid;
uint16_t eid_prefix_afi;
struct in6_addr eid_prefix;
} __attribute__ ((__packed__));
union map_request_record_generic_lcaf {
struct map_request_record_lcaf record;
struct map_request_record6_lcaf record6;
};
/* =========================================================== */
/*
0 1 2 3
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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Type=3 |P| |I| Reserved |M| Record Count |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Nonce . . . |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| . . . Nonce |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Key ID | Authentication Data Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
~ Authentication Data ~
+-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | Record TTL |
| +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
R | Locator Count | EID mask-len | ACT |A| Reserved |
e +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
c | Rsvd | Map-Version Number | EID-AFI |
o +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
r | EID-prefix |
d +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| /| Priority | Weight | M Priority | M Weight |
| L +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| o | Unused Flags |L|p|R| Loc-AFI |
| c +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| \| Locator |
+-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
struct map_register_hdr {
#ifdef LITTLE_ENDIAN
uint8_t R:1; /* TODO: no longer RFC compliante */
uint8_t I:1;
uint8_t rsvd:1;
uint8_t proxy_map_reply:1;
uint8_t lisp_type:4;
#else
uint8_t lisp_type:4;
uint8_t proxy_map_reply:1;
uint8_t rsvd:1;
uint8_t I:1;
uint8_t R:1; /* TODO: no longer RFC compliante */
#endif
uint8_t reserved1;
#ifdef LITTLE_ENDIAN
uint8_t want_map_notify:1;
uint8_t reserved2:7;
#else
uint8_t reserved2:7;
uint8_t want_map_notify:1;
#endif
uint8_t record_count;
uint64_t nonce;
uint16_t key_id;
uint16_t auth_data_length;
uint8_t auth_data[0];
} __attribute__ ((__packed__));
#define map_register_record_generic map_reply_record_generic
#define map_register_locator map_reply_locator
#define map_register_locator6 map_reply_locator6
#define map_register_locator_generic map_reply_locator_generic
/*
0 1 2 3
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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Type=4 |I| Reserved | Record Count |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Nonce . . . |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| . . . Nonce |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Key ID | Authentication Data Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
~ Authentication Data ~
+-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | Record TTL |
| +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
R | Locator Count | EID mask-len | ACT |A| Reserved |
e +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
c | Rsvd | Map-Version Number | EID-AFI |
o +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
r | EID-prefix |
d +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| /| Priority | Weight | M Priority | M Weight |
| L +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| o | Unused Flags |L|p|R| Loc-AFI |
| c +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| \| Locator |
+-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
struct map_notify_hdr {
#ifdef LITTLE_ENDIAN
uint8_t rsvd:3;
uint8_t I:1;
uint8_t lisp_type:4;
#else
uint8_t lisp_type:4;
uint8_t I:1;
uint8_t rsvd:3;
#endif
uint8_t reserved[2];
uint8_t record_count;
uint64_t nonce;
uint16_t key_id;
uint16_t auth_data_length;
uint8_t auth_data[0];
} __attribute__ ((__packed__));
#define map_notify_record_generic map_reply_record_generic
#define map_notify_locator map_reply_locator
#define map_notify_locator6 map_reply_locator6
#define map_notify_locator_generic map_reply_locator_generic
/*
0 1 2 3
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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Type=7 |R| Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Nonce . . . |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| . . . Nonce |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Key ID | Authentication Data Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
~ Authentication Data ~
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| TTL |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Reserved | EID mask-len | EID-prefix-AFI |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| EID-prefix |
+->+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | AFI = 16387 | Rsvd1 | Flags |
| +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | Type = 7 | Rsvd2 | 4 + n |
| +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
N | MS UDP Port Number | ETR UDP Port Number |
A +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
T | AFI = x | Global ETR RLOC Address ... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
L | AFI = x | MS RLOC Address ... |
C +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
A | AFI = x | Private ETR RLOC Address ... |
F +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | AFI = x | RTR RLOC Address 1 ... |
| +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | AFI = x | RTR RLOC Address n ... |
+->+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
struct info_msg_hdr {
#ifdef LITTLE_ENDIAN
uint8_t rsvd:3;
uint8_t R:1;
uint8_t lisp_type:4;
#else
uint8_t lisp_type:4;
uint8_t R:1;
uint8_t rsvd:3;
#endif
uint8_t reserved[3];
uint64_t nonce;
uint16_t key_id;
uint16_t auth_data_length;
uint8_t auth_data[0];
} __attribute__ ((__packed__));
#define info_msg_ttl_t uint32_t
#define info_msg_eid map_request_record_generic
/*
0 1 2 3
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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|N|L|E|V|I|flags| Nonce/Map-Version |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Instance ID/Locator-Status-Bits |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
struct lisp_data_hdr {
#ifdef LITTLE_ENDIAN
uint8_t flags:3;
uint8_t I:1;
uint8_t V:1;
uint8_t E:1;
uint8_t L:1;
uint8_t N:1;
#else
uint8_t N:1;
uint8_t L:1;
uint8_t E:1;
uint8_t V:1;
uint8_t I:1;
uint8_t flags:3;
#endif
uint8_t nonce[3];
uint8_t instance_id[3];
uint8_t lsbs;
} __attribute__ ((__packed__));
#define DATA_MAP_NOTIFY_INSTANCE_ID 0xFFFFFF
#endif