This repository has been archived by the owner on Sep 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpacket-lisp.c
2013 lines (1747 loc) · 76 KB
/
packet-lisp.c
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
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* packet-lisp.c
* Routines for Locator/ID Separation Protocol (LISP) Control Message dissection
* Copyright 2011, Lorand Jakab <lj@lispmon.net>
*
* $Id: packet-lisp.c 48836 2013-04-13 14:56:19Z pascal $
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*/
#include "config.h"
#include <epan/packet.h>
#include <epan/afn.h>
#include <epan/ipv6-utils.h>
#include <epan/expert.h>
#define INET_ADDRLEN 4
#define INET6_ADDRLEN 16
/*
* See RFC 6830 "Locator/ID Separation Protocol (LISP)",
* draft-ietf-lisp-lcaf-02 "LISP Canonical Address Format (LCAF)",
* draft-ietf-lisp-sec-04 "LISP-Security (LISP-SEC)", and
* draft-ermagan-lisp-nat-traversal-03 "NAT traversal for LISP" for packet
* format and protocol information.
*/
#define LCAF_DRAFT_VERSION 10
#define LISP_CONTROL_PORT 4342
/* LISP Control Message types */
#define LISP_MAP_REQUEST 1
#define LISP_MAP_REPLY 2
#define LISP_MAP_REGISTER 3
#define LISP_MAP_NOTIFY 4
#define LISP_MAP_REFERRAL 6
#define LISP_INFO 7
#define LISP_ECM 8
#define LISP_ACT_NONE 0
#define LISP_ACT_FWD_NATIVE 1
#define LISP_ACT_MREQ 2
#define LISP_ACT_DROP 3
#define DDT_NODE_REF 0
#define DDT_MS_REF 1
#define DDT_MS_ACK 2
#define DDT_MS_NREG 3
#define DDT_DLGT_HOLE 4
#define DDT_NAUTH 5
#define LCAF_NULL 0
#define LCAF_AFI_LIST 1
#define LCAF_IID 2
#define LCAF_ASN 3
#define LCAF_APP_DATA 4
#define LCAF_GEO 5
#define LCAF_OKEY 6
#define LCAF_NATT 7
#define LCAF_NONCE_LOC 8
#define LCAF_MCAST_INFO 9
#define LCAF_ELP 10
#define LCAF_SEC_KEY 11
#define LCAF_SRC_DST_KEY 12
#define LCAF_HEADER_LEN 6
#define LISP_ECM_HEADER_LEN 4
#define LISP_XTRID_LEN 16
#define LISP_SITEID_LEN 8
#define LISP_MAP_ACT 0xE000
#define LISP_MAP_AUTH 0x1000
#define REFERRAL_INCOMPLETE 0x0800
#define LOCAL_BIT_MASK 0x0004
#define PROBE_BIT_MASK 0x0002
#define REACH_BIT_MASK 0x0001
#define MAP_REQ_FLAG_A 0x080000
#define MAP_REQ_FLAG_M 0x040000
#define MAP_REQ_FLAG_P 0x020000
#define MAP_REQ_FLAG_S 0x010000
#define MAP_REQ_FLAG_p 0x008000
#define MAP_REQ_FLAG_s 0x004000
#define MAP_REQ_RESERVED 0x003FE0
#define MAP_REP_FLAG_P 0x080000
#define MAP_REP_FLAG_E 0x040000
#define MAP_REP_FLAG_S 0x020000
#define MAP_REP_RESERVED 0x01FFFF
#define MAP_REG_FLAG_P 0x080000
#define MAP_REG_FLAG_S 0x040000
#define MAP_REG_FLAG_I 0x020000
#define MAP_REG_FLAG_R 0x010000
#define MAP_REG_RESERVED 0x00FFFE
#define MAP_REG_FLAG_M 0x000001
#define MAP_NOT_FLAG_I 0x080000
#define MAP_NOT_FLAG_R 0x040000
#define MAP_NOT_RESERVED 0x03FFFF
#define MAP_REF_RESERVED 0x0FFFFF
#define INFO_FLAG_R 0x080000
#define INFO_RESERVED 0x07FFFFFF
#define ECM_FLAG_S 0x08000000
#define ECM_FLAG_D 0x04000000
/* Initialize the protocol and registered fields */
static int proto_lisp = -1;
static int hf_lisp_type = -1;
static int hf_lisp_irc = -1;
static int hf_lisp_records = -1;
static int hf_lisp_nonce = -1;
static int hf_lisp_keyid = -1;
static int hf_lisp_authlen = -1;
static int hf_lisp_auth = -1;
static int hf_lisp_msrtr_keyid = -1;
static int hf_lisp_msrtr_authlen = -1;
static int hf_lisp_msrtr_auth = -1;
static int hf_lisp_xtrid = -1;
static int hf_lisp_siteid = -1;
/* Map-Request fields */
static int hf_lisp_mreq_flags_auth = -1;
static int hf_lisp_mreq_flags_mrp = -1;
static int hf_lisp_mreq_flags_probe = -1;
static int hf_lisp_mreq_flags_smr = -1;
static int hf_lisp_mreq_flags_pitr = -1;
static int hf_lisp_mreq_flags_smri = -1;
static int hf_lisp_mreq_res = -1;
static int hf_lisp_mreq_srceid_afi = -1;
static int hf_lisp_mreq_srceid = -1;
static int hf_lisp_mreq_srceidv6 = -1;
static int hf_lisp_mreq_srcitr = -1;
static int hf_lisp_mreq_srcitrv6 = -1;
/* Map-Reply fields */
static int hf_lisp_mrep_flags_probe = -1;
static int hf_lisp_mrep_flags_enlr = -1;
static int hf_lisp_mrep_flags_sec = -1;
static int hf_lisp_mrep_res = -1;
/* Map-Register fields */
static int hf_lisp_mreg_flags_pmr = -1;
static int hf_lisp_mreg_flags_sec = -1;
static int hf_lisp_mreg_flags_xtrid = -1;
static int hf_lisp_mreg_flags_rtr = -1;
static int hf_lisp_mreg_flags_wmn = -1;
static int hf_lisp_mreg_res = -1;
/* Map-Notify fields */
static int hf_lisp_mnot_flags_xtrid = -1;
static int hf_lisp_mnot_flags_rtr = -1;
static int hf_lisp_mnot_res = -1;
/* Map-Referral fields */
static int hf_lisp_mref_res = -1;
static int hf_lisp_referral_sigcnt = -1;
static int hf_lisp_referral_incomplete = -1;
/* Info fields */
static int hf_lisp_info_r = -1;
static int hf_lisp_info_res1 = -1;
static int hf_lisp_info_ttl = -1;
static int hf_lisp_info_res2 = -1;
static int hf_lisp_info_afi = -1;
/* Mapping record fields */
static int hf_lisp_mapping_ttl = -1;
static int hf_lisp_mapping_loccnt = -1;
static int hf_lisp_mapping_eid_masklen = -1;
static int hf_lisp_mapping_act = -1;
static int hf_lisp_mapping_auth = -1;
static int hf_lisp_mapping_res1 = -1;
static int hf_lisp_mapping_res2 = -1;
static int hf_lisp_mapping_ver = -1;
static int hf_lisp_mapping_eid_afi = -1;
static int hf_lisp_mapping_eid = -1;
/* LCAF fields */
static int hf_lisp_lcaf_res1 = -1;
static int hf_lisp_lcaf_flags = -1;
static int hf_lisp_lcaf_type = -1;
static int hf_lisp_lcaf_res2 = -1;
static int hf_lisp_lcaf_length = -1;
/* LCAF IID fields */
static int hf_lisp_lcaf_iid = -1;
/* LCAF NATT fields */
static int hf_lisp_lcaf_natt_msport = -1;
static int hf_lisp_lcaf_natt_etrport = -1;
/* Encapsulated Control Message fields */
static int hf_lisp_ecm_flags_sec = -1;
static int hf_lisp_ecm_flags_ddt = -1;
static int hf_lisp_ecm_res = -1;
/* Initialize the subtree pointers */
static gint ett_lisp = -1;
static gint ett_lisp_mr = -1;
static gint ett_lisp_mapping = -1;
static gint ett_lisp_itr = -1;
static gint ett_lisp_record = -1;
static gint ett_lisp_lcaf = -1;
static gint ett_lisp_elp = -1;
static dissector_handle_t ipv4_handle;
static dissector_handle_t ipv6_handle;
static dissector_handle_t data_handle;
static gboolean encapsulated = FALSE;
static gboolean ddt_originated = FALSE;
const value_string lisp_typevals[] = {
{ LISP_MAP_REQUEST, "Map-Request" },
{ LISP_MAP_REPLY, "Map-Reply" },
{ LISP_MAP_REGISTER, "Map-Register" },
{ LISP_MAP_NOTIFY, "Map-Notify" },
{ LISP_MAP_REFERRAL, "Map-Referral" },
{ LISP_INFO, "Info" },
{ LISP_ECM, "Encapsulated Control Message" },
{ 0, NULL}
};
const value_string mapping_actions[] = {
{ LISP_ACT_NONE, "No-Action" },
{ LISP_ACT_FWD_NATIVE, "Natively-Forward" },
{ LISP_ACT_MREQ, "Send-Map-Request" },
{ LISP_ACT_DROP, "Drop" },
{ 0, NULL}
};
const value_string referral_actions[] = {
{ DDT_NODE_REF, "Node Referral" },
{ DDT_MS_REF, "Map-Server Referral" },
{ DDT_MS_ACK, "Map-Server ACK" },
{ DDT_MS_NREG, "Map-Server Not Registered" },
{ DDT_DLGT_HOLE, "Delegation Hole" },
{ DDT_NAUTH, "Not Authoritative" },
{ 0, NULL}
};
const value_string lcaf_typevals[] = {
{ LCAF_NULL, "Null Body" },
{ LCAF_AFI_LIST, "AFI List" },
{ LCAF_IID, "Instance ID" },
{ LCAF_ASN, "AS Number" },
{ LCAF_APP_DATA, "Application Data" },
{ LCAF_GEO, "Geo Coordinates" },
{ LCAF_OKEY, "Opaque Key" },
{ LCAF_NATT, "NAT Traversal" },
{ LCAF_NONCE_LOC, "Nonce Locator" },
{ LCAF_MCAST_INFO, "Multicast Info" },
{ LCAF_ELP, "Explicit Locator Path" },
{ LCAF_SEC_KEY, "Security Key" },
{ LCAF_SRC_DST_KEY, "Source/Dest Key" },
{ 0, NULL}
};
static int
dissect_lcaf(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset);
static int
get_lcaf_data(tvbuff_t *tvb, gint offset, guint8 *lcaf_type, guint16 *len)
{
/* Jump over Rsvd1 and Flags (16 bits) */
offset += 2;
/* Type (8 bits) */
if (lcaf_type)
*lcaf_type = tvb_get_guint8(tvb, offset);
offset += 1;
/* Jump over Rsvd2 bits (8 bits) */
offset += 1;
/* Length (16 bits) */
if (len)
/* Adding the size of the LCAF header as well */
*len = tvb_get_ntohs(tvb, offset) + LCAF_HEADER_LEN;
offset += 2;
return offset;
}
static const gchar *
get_addr_str(tvbuff_t *tvb, gint offset, guint16 afi, guint16 *addr_len)
{
const gchar *notset_str = "not set";
const gchar *addr_str;
guint32 locator_v4;
struct e_in6_addr locator_v6;
guint8 lcaf_type;
guint32 iid;
guint16 cur_len;
switch (afi) {
case AFNUM_RESERVED:
*addr_len = 0;
return notset_str;
case AFNUM_INET:
locator_v4 = tvb_get_ipv4(tvb, offset);
*addr_len = INET_ADDRLEN;
addr_str = ip_to_str((guint8 *)&locator_v4);
return addr_str;
case AFNUM_INET6:
tvb_get_ipv6(tvb, offset, &locator_v6);
*addr_len = INET6_ADDRLEN;
addr_str = ip6_to_str(&locator_v6);
return addr_str;
case AFNUM_LCAF:
get_lcaf_data(tvb, offset, &lcaf_type, addr_len);
addr_str = val_to_str(lcaf_type, lcaf_typevals, "Unknown LCAF Type (%d)");
if (lcaf_type == LCAF_IID) {
iid = tvb_get_ntohl(tvb, offset + LCAF_HEADER_LEN);
afi = tvb_get_ntohs(tvb, offset + LCAF_HEADER_LEN + 4);
addr_str = get_addr_str(tvb, offset + LCAF_HEADER_LEN + 6, afi, &cur_len);
return ep_strdup_printf("[%d] %s", iid, addr_str);
}
return addr_str;
default:
return NULL;
}
}
static int
dissect_lcaf_natt_rloc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
gint offset, const gchar *str, int idx)
{
guint16 addr_len = 0;
guint16 rloc_afi;
const gchar *rloc_str;
rloc_afi = tvb_get_ntohs(tvb, offset); offset += 2;
rloc_str = get_addr_str(tvb, offset, rloc_afi, &addr_len);
if (rloc_str == NULL) {
expert_add_info_format(pinfo, tree, PI_PROTOCOL, PI_ERROR,
"Unexpected RLOC AFI (%d), cannot decode", rloc_afi);
return offset;
}
if (idx) {
proto_tree_add_text(tree, tvb, offset - 2, 2 + addr_len, str, idx, rloc_str);
} else {
proto_tree_add_text(tree, tvb, offset - 2, 2 + addr_len, str, rloc_str);
}
return addr_len + 2;
}
static int
dissect_lcaf_elp_hop(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
gint offset, int idx)
{
guint16 addr_len = 0;
guint16 hop_afi;
guint16 hop_flags;
const gchar *hop_str;
proto_item *ti;
hop_afi = tvb_get_ntohs(tvb, offset); offset += 2;
hop_flags = tvb_get_ntohs(tvb, offset); offset += 2;
hop_str = get_addr_str(tvb, offset, hop_afi, &addr_len);
if (hop_str == NULL) {
expert_add_info_format(pinfo, tree, PI_PROTOCOL, PI_ERROR,
"Unexpected reencap hop AFI (%d), cannot decode", hop_afi);
return offset;
}
if (idx) {
ti = proto_tree_add_text(tree, tvb, offset - 4, addr_len + 4, "Reencap hop %d: %s", idx, hop_str);
} else {
ti = proto_tree_add_text(tree, tvb, offset - 4, addr_len + 4, "Reencap hop: %s", hop_str);
}
if (hop_flags & 0x04)
proto_item_append_text(ti, ", Lookup");
if (hop_flags & 0x02)
proto_item_append_text(ti, ", RLOC-Probe");
if (hop_flags & 0x01)
proto_item_append_text(ti, ", Strict");
return addr_len + 4;
}
/*
* Dissector code for AFI List
*
*/
static int
dissect_lcaf_afi_list(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
gint offset, guint16 length)
{
gint old_offset;
gint remaining = length;
gint i = 1;
guint16 addr_len = 0;
guint16 afi;
guint32 ipv4;
struct e_in6_addr ipv6;
const gchar *lcaf_str;
proto_item *tir;
proto_tree *lisp_elp_tree;
while (remaining > 0) {
afi = tvb_get_ntohs(tvb, offset); offset += 2; remaining -= 2;
switch (afi) {
case AFNUM_INET:
ipv4 = tvb_get_ipv4(tvb, offset);
proto_tree_add_text(tree, tvb, offset - 2, 2 + INET_ADDRLEN,
"%d. IPv4 Addess: %s", i, ip_to_str((guint8 *)&ipv4));
offset += INET_ADDRLEN;
remaining -= INET_ADDRLEN;
break;
case AFNUM_INET6:
tvb_get_ipv6(tvb, offset, &ipv6);
proto_tree_add_text(tree, tvb, offset - 2, 2 + INET6_ADDRLEN,
"%d. IPv6 Addess: %s", i, ip6_to_str(&ipv6));
offset += INET6_ADDRLEN;
remaining -= INET6_ADDRLEN;
break;
case AFNUM_LCAF:
old_offset = offset;
lcaf_str = get_addr_str(tvb, offset, afi, &addr_len);
tir = proto_tree_add_text(tree, tvb, offset - 2, 2 + addr_len,
"%d. %s", i, lcaf_str);
/* XXX need to check LCAF type */
lisp_elp_tree = proto_item_add_subtree(tir, ett_lisp_elp);
offset = dissect_lcaf(tvb, pinfo, lisp_elp_tree, offset);
remaining -= (offset - old_offset);
break;
default:
expert_add_info_format(pinfo, tree, PI_PROTOCOL, PI_ERROR,
"Unexpected AFI (%d), cannot decode", afi);
return -1;
}
i++;
}
return offset;
}
/*
* Dissector code for Instance ID
*
* 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 | Rsvd2 | 4 + n |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Instance ID |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | AFI = x | Address ... |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*/
static int
dissect_lcaf_iid(tvbuff_t *tvb, proto_tree *tree, gint offset)
{
/* For now, we don't print reserved and length fields */
offset += 3;
proto_tree_add_item(tree, hf_lisp_lcaf_iid, tvb, offset, 4, ENC_BIG_ENDIAN);
offset += 4;
return offset;
}
/*
* Dissector code for NAT-Traversal
*
* 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 = 7 | Rsvd2 | 4 + n |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | MS UDP Port Number | ETR UDP Port Number |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | AFI = x | Global ETR RLOC Address ... |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | AFI = x | MS RLOC Address ... |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | AFI = x | Private ETR RLOC Address ... |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | AFI = x | RTR RLOC Address 1 ... |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | AFI = x | RTR RLOC Address n ... |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*/
static int
dissect_lcaf_natt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
gint offset, guint16 length)
{
gint i;
gint len;
gint remaining = length;
const gchar *global_etr = "Global ETR RLOC: %s";
const gchar *ms = "MS RLOC: %s";
const gchar *private_etr = "Private ETR RLOC: %s";
const gchar *rtr = "RTR RLOC %d: %s";
remaining -= 4;
proto_tree_add_item(tree, hf_lisp_lcaf_natt_msport, tvb, offset, 2, ENC_BIG_ENDIAN);
offset += 2;
remaining -= 2;
proto_tree_add_item(tree, hf_lisp_lcaf_natt_etrport, tvb, offset, 2, ENC_BIG_ENDIAN);
offset += 2;
remaining -= 2;
len = dissect_lcaf_natt_rloc(tvb, pinfo, tree, offset, global_etr, 0);
offset += len;
remaining -= len;
len = dissect_lcaf_natt_rloc(tvb, pinfo, tree, offset, ms, 0);
offset += len;
remaining -= len;
len = dissect_lcaf_natt_rloc(tvb, pinfo, tree, offset, private_etr, 0);
offset += len;
remaining -= len;
i = 1;
while (remaining > 0) {
len = dissect_lcaf_natt_rloc(tvb, pinfo, tree, offset, rtr, i);
offset += len;
remaining -= len;
i++;
}
return offset;
}
/*
* Dissector code for Explicit Locator Path
*
* 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 = 10 | Rsvd2 | n |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | AFI = x | Rsvd3 |L|P|S|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Reencap Hop 1 ... |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | AFI = x | Rsvd3 |L|P|S|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Reencap Hop k ... |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*/
static int
dissect_lcaf_elp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
gint offset, guint16 length)
{
gint len;
gint remaining = length;
gint i = 1;
while (remaining > 0) {
len = dissect_lcaf_elp_hop(tvb, pinfo, tree, offset, i);
offset += len;
remaining -= len;
i++;
}
return offset;
}
/*
* Dissector code for LISP Canonical Address Format (LCAF)
*
* 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 | Rsvd2 | Length |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
* Type 0: Null Body Type
* Type 1: AFI List Type
* Type 2: Instance ID Type
* Type 3: AS Number Type
* Type 4: Application Data Type
* Type 5: Geo Coordinates Type
* Type 6: Opaque Key Type
* Type 7: NAT-Traversal Type
* Type 8: Nonce Locator Type
* Type 9: Multicast Info Type
* Type 10: Explicit Locator Path Type
* Type 11: Security Key Type
* Type 12: Source/Dest Key Type
*
*/
static int
dissect_lcaf(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset)
{
guint8 lcaf_type;
guint16 len;
proto_item *tir;
proto_tree *lcaf_tree;
lcaf_type = tvb_get_guint8(tvb, offset + 2);
len = tvb_get_ntohs(tvb, offset + 4);
tir = proto_tree_add_text(tree, tvb, offset, 6,
"LCAF Header (Type: %s, Length: %d bytes)",
val_to_str(lcaf_type, lcaf_typevals, "Unknown (%d)"),
len);
lcaf_tree = proto_item_add_subtree(tir, ett_lisp_lcaf);
/* Reserved bits (8 bits) */
proto_tree_add_item(lcaf_tree, hf_lisp_lcaf_res1, tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
/* Flags (8 bits) */
proto_tree_add_item(lcaf_tree, hf_lisp_lcaf_flags, tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
/* Type (8 bits) */
proto_tree_add_item(lcaf_tree, hf_lisp_lcaf_type, tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
/* Reserved bits (8 bits) */
proto_tree_add_item(lcaf_tree, hf_lisp_lcaf_res2, tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
/* Length (16 bits) */
proto_tree_add_item(lcaf_tree, hf_lisp_lcaf_length, tvb, offset, 2, ENC_BIG_ENDIAN);
offset += 2;
switch (lcaf_type) {
case LCAF_NULL:
break;
case LCAF_AFI_LIST:
offset = dissect_lcaf_afi_list(tvb, pinfo, tree, offset, len);
break;
case LCAF_IID:
offset = dissect_lcaf_iid(tvb, tree, offset);
break;
case LCAF_NATT:
offset = dissect_lcaf_natt(tvb, pinfo, tree, offset, len);
break;
case LCAF_ELP:
offset = dissect_lcaf_elp(tvb, pinfo, tree, offset, len);
break;
default:
if (lcaf_type < 13)
expert_add_undecoded_item(tvb, pinfo, tree, offset,
len, PI_WARN);
else
expert_add_info_format(pinfo, tree, PI_PROTOCOL, PI_ERROR,
"LCAF type %d is not defined in draft-farinacci-lisp-lcaf-%d",
lcaf_type, LCAF_DRAFT_VERSION);
return offset + len;
}
return offset;
}
/*
* Dissector code for locator records within control packets
*
* 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
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Priority | Weight | M Priority | M Weight |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Unused Flags |L|p|R| Loc-AFI |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Locator |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*/
static int
dissect_lisp_locator(tvbuff_t *tvb, packet_info *pinfo, proto_tree *lisp_mapping_tree)
{
gint offset = 0;
guint16 addr_len = 0;
guint8 prio;
guint8 weight;
guint8 m_prio;
guint8 m_weight;
guint16 flags;
guint16 loc_afi;
const gchar *locator;
proto_item *tir;
proto_tree *lisp_elp_tree;
prio = tvb_get_guint8(tvb, offset); offset += 1;
weight = tvb_get_guint8(tvb, offset); offset += 1;
m_prio = tvb_get_guint8(tvb, offset); offset += 1;
m_weight = tvb_get_guint8(tvb, offset); offset += 1;
flags = tvb_get_ntohs(tvb, offset); offset += 2;
loc_afi = tvb_get_ntohs(tvb, offset); offset += 2;
locator = get_addr_str(tvb, offset, loc_afi, &addr_len);
if (locator == NULL) {
expert_add_info_format(pinfo, lisp_mapping_tree, PI_PROTOCOL, PI_ERROR,
"Unexpected locator AFI (%d), cannot decode", loc_afi);
return offset;
}
tir = proto_tree_add_text(lisp_mapping_tree, tvb, 0, 8 + addr_len,
"%sRLOC: %s%s, %s, Priority/Weight: %d/%d, Multicast Priority/Weight: %d/%d",
(flags&LOCAL_BIT_MASK) ? "Local " : "",
locator,
(flags&PROBE_BIT_MASK) ? " (probed)" : "",
(flags&REACH_BIT_MASK) ? "Reachable" : "Unreachable",
prio, weight, m_prio, m_weight);
if (loc_afi == AFNUM_LCAF) {
/* Create a sub-tree for the mapping */
lisp_elp_tree = proto_item_add_subtree(tir, ett_lisp_elp);
offset = dissect_lcaf(tvb, pinfo, lisp_elp_tree, offset);
} else {
offset += addr_len;
}
return offset;
}
/*
* Dissector code for mapping records within control packets
*
* 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
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Record TTL |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Locator Count | EID mask-len | ACT |A| Reserved |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Rsvd | Map-Version Number | EID-AFI |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | EID-prefix |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*/
static int
dissect_lisp_mapping(tvbuff_t *tvb, packet_info *pinfo, proto_tree *lisp_tree,
guint8 rec_cnt, gboolean referral)
{
int i;
gint offset = 0;
gint offset_rec = 0;
guint32 ttl;
guint16 addr_len = 0;
guint8 loc_cnt;
guint8 prefix_mask;
guint16 flags;
guint16 act;
guint16 prefix_afi;
const gchar *prefix;
proto_item *tir;
proto_tree *lisp_mapping_tree;
ttl = tvb_get_ntohl(tvb, offset); offset += 4;
loc_cnt = tvb_get_guint8(tvb, offset); offset += 1;
prefix_mask = tvb_get_guint8(tvb, offset); offset += 1;
flags = tvb_get_ntohs(tvb, offset); offset += 4;
prefix_afi = tvb_get_ntohs(tvb, offset); offset += 2;
act = flags & LISP_MAP_ACT;
act >>= 13;
prefix = get_addr_str(tvb, offset, prefix_afi, &addr_len);
if (prefix == NULL) {
expert_add_info_format(pinfo, lisp_tree, PI_PROTOCOL, PI_ERROR,
"Unexpected EID prefix AFI (%d), cannot decode", prefix_afi);
return offset;
}
tir = proto_tree_add_text(lisp_tree, tvb, 0, 12 + addr_len,
"EID prefix: %s/%d, TTL: %s, %sAuthoritative, %s%s",
prefix, prefix_mask,
(ttl == 0xFFFFFFFF) ? "Unlimited" : ep_strdup_printf("%d", ttl),
(flags&LISP_MAP_AUTH) ? "" : "Not ",
val_to_str(act, (referral) ? referral_actions : mapping_actions, "Invalid action code (%d)"),
(referral&&(flags&REFERRAL_INCOMPLETE)) ? " (Incomplete)" : "");
offset += addr_len;
/* Update the INFO column if there is only one record */
if (rec_cnt == 1)
col_append_fstr(pinfo->cinfo, COL_INFO, " for %s/%d",
prefix, prefix_mask);
/* Create a sub-tree for the mapping */
lisp_mapping_tree = proto_item_add_subtree(tir, ett_lisp_mapping);
/* TTL (32 bits) */
proto_tree_add_item(lisp_mapping_tree, hf_lisp_mapping_ttl, tvb, offset_rec, 4, ENC_BIG_ENDIAN);
offset_rec += 4;
/* Locator count (8 bits) */
proto_tree_add_item(lisp_mapping_tree, hf_lisp_mapping_loccnt, tvb, offset_rec, 1, ENC_BIG_ENDIAN);
offset_rec += 1;
/* EID mask length (8 bits) */
proto_tree_add_item(lisp_mapping_tree, hf_lisp_mapping_eid_masklen, tvb, offset_rec, 1, ENC_BIG_ENDIAN);
offset_rec += 1;
/* Action (3 bits) */
proto_tree_add_item(lisp_mapping_tree, hf_lisp_mapping_act, tvb, offset_rec, 2, ENC_BIG_ENDIAN);
/* Authoritative bit */
proto_tree_add_item(lisp_mapping_tree, hf_lisp_mapping_auth, tvb, offset_rec, 2, ENC_BIG_ENDIAN);
/* Incomplete bit in Map-Referrals */
if (referral)
proto_tree_add_item(lisp_mapping_tree, hf_lisp_referral_incomplete, tvb, offset_rec, 2, ENC_BIG_ENDIAN);
/* Reserved (11 bits) */
proto_tree_add_item(lisp_mapping_tree, hf_lisp_mapping_res1, tvb, offset_rec, 2, ENC_BIG_ENDIAN);
offset_rec += 2;
if (referral) {
/* SigCnt (4 bits) */
proto_tree_add_item(lisp_mapping_tree, hf_lisp_referral_sigcnt, tvb, offset_rec, 2, ENC_BIG_ENDIAN);
} else {
/* Reserved (4 bits) */
proto_tree_add_item(lisp_mapping_tree, hf_lisp_mapping_res2, tvb, offset_rec, 2, ENC_BIG_ENDIAN);
}
/* Map-Version Number (12 bits) */
proto_tree_add_item(lisp_mapping_tree, hf_lisp_mapping_ver, tvb, offset_rec, 2, ENC_BIG_ENDIAN);
offset_rec += 2;
/* EID prefix AFI (16 bits) */
proto_tree_add_item(lisp_mapping_tree, hf_lisp_mapping_eid_afi, tvb, offset_rec, 2, ENC_BIG_ENDIAN);
offset_rec += 2;
/* EID */
proto_tree_add_string(lisp_mapping_tree, hf_lisp_mapping_eid, tvb, offset_rec, offset - offset_rec, prefix);
/* Locators */
for(i=0; i < loc_cnt; i++) {
tvbuff_t *loc_tvb;
int len = 0;
loc_tvb = tvb_new_subset_remaining(tvb, offset);
len = dissect_lisp_locator(loc_tvb, pinfo, lisp_mapping_tree);
offset += len;
}
return offset;
}
/*
* Dissector code for Map-Request type control packets
*
* 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=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 ... |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*/
static void
dissect_lisp_map_request(tvbuff_t *tvb, packet_info *pinfo, proto_tree *lisp_tree)
{
int i;
guint16 addr_len = 0;
gint offset = 0;
guint16 flags;
gboolean mrep = FALSE;
gboolean smr = FALSE;
gboolean probe = FALSE;
gboolean pitr = FALSE;
gboolean smr_invoked = FALSE;
guint8 itr_rec_cnt = 0;
guint8 rec_cnt = 0;
guint16 src_eid_afi;
const gchar *src_eid;
struct e_in6_addr e_in6_addr;
tvbuff_t *next_tvb;
/* Flags (6 bits)*/
flags = tvb_get_ntohs(tvb, offset);
mrep = flags & (MAP_REQ_FLAG_M >> 8);
smr = flags & (MAP_REQ_FLAG_S >> 8);
probe = flags & (MAP_REQ_FLAG_P >> 8);
pitr = flags & (MAP_REQ_FLAG_p >> 8);
smr_invoked = flags & (MAP_REQ_FLAG_s >> 8);
proto_tree_add_item(lisp_tree, hf_lisp_mreq_flags_auth, tvb, offset, 3, ENC_BIG_ENDIAN);
proto_tree_add_item(lisp_tree, hf_lisp_mreq_flags_mrp, tvb, offset, 3, ENC_BIG_ENDIAN);
proto_tree_add_item(lisp_tree, hf_lisp_mreq_flags_probe, tvb, offset, 3, ENC_BIG_ENDIAN);
proto_tree_add_item(lisp_tree, hf_lisp_mreq_flags_smr, tvb, offset, 3, ENC_BIG_ENDIAN);
proto_tree_add_item(lisp_tree, hf_lisp_mreq_flags_pitr, tvb, offset, 3, ENC_BIG_ENDIAN);
proto_tree_add_item(lisp_tree, hf_lisp_mreq_flags_smri, tvb, offset, 3, ENC_BIG_ENDIAN);
if (pitr)
col_append_str(pinfo->cinfo, COL_INFO, " by P-ITR");
if (smr)
col_append_str(pinfo->cinfo, COL_INFO, " (SMR)");
if (probe)
col_append_str(pinfo->cinfo, COL_INFO, " (RLOC-probe)");
if (smr_invoked)
col_append_str(pinfo->cinfo, COL_INFO, " (SMR-invoked)");
/* Reserved bits (9 bits) */
proto_tree_add_item(lisp_tree, hf_lisp_mreq_res, tvb, offset, 3, ENC_BIG_ENDIAN);
/* ITR record count (5 bits) */
itr_rec_cnt = tvb_get_guint8(tvb, offset + 2) & 0x1F;
proto_tree_add_item(lisp_tree, hf_lisp_irc, tvb, offset, 3, ENC_BIG_ENDIAN);
offset += 3;
/* Record count (8 bits) */
rec_cnt = tvb_get_guint8(tvb, offset);
proto_tree_add_item(lisp_tree, hf_lisp_records, tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
/* Nonce (64 bits) */
proto_tree_add_item(lisp_tree, hf_lisp_nonce, tvb, offset, 8, ENC_BIG_ENDIAN);
offset += 8;
/* Source EID AFI (16 bits) */
src_eid_afi = tvb_get_ntohs(tvb, offset);
proto_tree_add_item(lisp_tree, hf_lisp_mreq_srceid_afi, tvb, offset, 2, ENC_BIG_ENDIAN);
offset += 2;
/* Source EID */
switch (src_eid_afi) {
case AFNUM_RESERVED:
proto_tree_add_text(lisp_tree, tvb, offset, 0, "Source EID: not set");
break;
case AFNUM_INET:
proto_tree_add_ipv4(lisp_tree,
hf_lisp_mreq_srceid, tvb, offset, INET_ADDRLEN, tvb_get_ipv4(tvb, offset));
offset += INET_ADDRLEN;