2 * Copyright (c) 2015 Ritesh Ranjan (r.ranjan789@gmail.com)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
29 /* \summary: - Locator/Identifier Separation Protocol (LISP) printer */
32 * specification: RFC 6830
35 * The Map-Register message format is:
38 * 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
39 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 * |Type=3 |P|S|I|R| Reserved |M| Record Count |
41 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46 * | Key ID | Authentication Data Length |
47 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
48 * ~ Authentication Data ~
49 * +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
51 * | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
52 * R | Locator Count | EID mask-len | ACT |A| Reserved |
53 * e +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
54 * c | Rsvd | Map-Version Number | EID-Prefix-AFI |
55 * o +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
57 * d +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
58 * | /| Priority | Weight | M Priority | M Weight |
59 * | L +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
60 * | o | Unused Flags |L|p|R| Loc-AFI |
61 * | c +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
63 * +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
66 * The Map-Notify message format is:
69 * 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
70 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
71 * |Type=4 |I|R| Reserved | Record Count |
72 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
74 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
76 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
77 * | Key ID | Authentication Data Length |
78 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
79 * ~ Authentication Data ~
80 * +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
82 * | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
83 * R | Locator Count | EID mask-len | ACT |A| Reserved |
84 * e +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
85 * c | Rsvd | Map-Version Number | EID-Prefix-AFI |
86 * o +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
88 * d +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
89 * | /| Priority | Weight | M Priority | M Weight |
90 * | L +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
91 * | o | Unused Flags |L|p|R| Loc-AFI |
92 * | c +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
94 * +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
101 #include "netdissect-stdinc.h"
102 #include "netdissect.h"
110 #include "addrtoname.h"
116 #define LISP_MAP_NOTIFY_IBIT_MASK 8
117 #define LISP_MAP_REGISTER_IBIT_MASK 2
120 LISP_MAP_REQUEST
= 1,
124 LISP_ENCAPSULATED_CONTROL_MESSAGE
= 8
133 static const struct tok lisp_type
[] = {
134 { 0, "LISP-Reserved" },
135 { 1, "LISP-Map-Request" },
136 { 2, "LISP-Map-Reply" },
137 { 3, "LISP-Map-Register" },
138 { 4, "LISP-Map-Notify" },
139 { 8, "LISP-Encapsulated-Contol-Message" },
144 * P-Bit : Request for Proxy Map-Reply from the MS/MR
145 * S-Bit : Security Enhancement. ETR is LISP-SEC enabled. draft-ietf-lisp-sec
146 * I-Bit : 128 bit xTR-ID and 64 bit Site-ID present.
147 * xTR-ID and Site-ID help in differentiation of xTRs in multi xTR
148 * and multi Site deployment scenarios.
149 * R-Bit : Built for a Reencapsulating-Tunnel-Router. Used in Traffic
150 * Engineering and Service Chaining
152 static const struct tok map_register_hdr_flag
[] = {
153 { 0x08000000, "P-Proxy-Map-Reply" },
154 { 0x04000000, "S-LISP-SEC-Capable" },
155 { 0x02000000, "I-xTR-ID-Present" },
156 { 0x01000000, "R-Build-For-RTR" },
157 { 0x00000100, "M-Want-Map-Notify" },
161 static const struct tok map_notify_hdr_flag
[] = {
162 { 0x08000000, "I-xTR-ID-Present" },
163 { 0x04000000, "R-Build-For-RTR" },
167 static const struct tok auth_type
[] = {
168 { LISP_AUTH_NONE
, "None" },
169 { LISP_AUTH_SHA1
, "SHA1" },
170 { LISP_AUTH_SHA256
, "SHA256" },
174 static const struct tok lisp_eid_action
[] = {
176 { 1, "Natively-Forward" },
177 { 2, "Send-Map-Request" },
182 static const struct tok lisp_loc_flag
[] = {
183 { 0x0004, "Local-Locator" },
184 { 0x0002, "RLoc-Probed" },
185 { 0x0001, "Reachable" },
189 typedef struct map_register_hdr
{
190 nd_uint8_t type_and_flag
;
192 nd_uint8_t reserved_and_flag2
;
193 nd_uint8_t record_count
;
196 nd_uint16_t auth_data_len
;
197 } lisp_map_register_hdr
;
199 #define MAP_REGISTER_HDR_LEN sizeof(lisp_map_register_hdr)
201 typedef struct map_register_eid
{
203 nd_uint8_t locator_count
;
204 nd_uint8_t eid_prefix_mask_length
;
205 nd_uint8_t act_auth_inc_res
;
207 nd_uint16_t reserved_and_version
;
208 nd_uint16_t eid_prefix_afi
;
209 } lisp_map_register_eid
;
211 #define MAP_REGISTER_EID_LEN sizeof(lisp_map_register_eid)
213 typedef struct map_register_loc
{
216 nd_uint8_t m_priority
;
218 nd_uint16_t unused_and_flag
;
219 nd_uint16_t locator_afi
;
220 } lisp_map_register_loc
;
222 #define MAP_REGISTER_LOC_LEN sizeof(lisp_map_register_loc)
224 static uint8_t extract_lisp_type(uint8_t);
225 static uint8_t is_xtr_data_present(uint8_t, uint8_t);
226 static void lisp_hdr_flag(netdissect_options
*, const lisp_map_register_hdr
*);
227 static void action_flag(netdissect_options
*, uint8_t);
228 static void loc_hdr_flag(netdissect_options
*, uint16_t);
231 lisp_print(netdissect_options
*ndo
, const u_char
*bp
, u_int length
)
233 uint8_t type_and_flag
;
238 uint8_t record_count
;
242 uint16_t map_version
;
243 uint16_t packet_offset
;
244 uint16_t auth_data_len
;
246 const u_char
*packet_iterator
;
247 const u_char
*loc_ip_pointer
;
248 const lisp_map_register_hdr
*lisp_hdr
;
249 const lisp_map_register_eid
*lisp_eid
;
250 const lisp_map_register_loc
*lisp_loc
;
252 ndo
->ndo_protocol
= "lisp";
253 /* Check if enough bytes for header are available */
254 ND_TCHECK_LEN(bp
, MAP_REGISTER_HDR_LEN
);
255 lisp_hdr
= (const lisp_map_register_hdr
*) bp
;
256 lisp_hdr_flag(ndo
, lisp_hdr
);
257 /* Supporting only MAP NOTIFY and MAP REGISTER LISP packets */
258 type_and_flag
= EXTRACT_U_1(lisp_hdr
->type_and_flag
);
259 type
= extract_lisp_type(type_and_flag
);
260 if ((type
!= LISP_MAP_REGISTER
) && (type
!= LISP_MAP_NOTIFY
))
263 /* Find if the packet contains xTR and Site-ID data */
264 xtr_present
= is_xtr_data_present(type
, type_and_flag
);
266 /* Extract the number of EID records present */
267 auth_data_len
= EXTRACT_BE_U_2(lisp_hdr
->auth_data_len
);
268 packet_iterator
= (const u_char
*)(lisp_hdr
);
269 packet_offset
= MAP_REGISTER_HDR_LEN
;
270 record_count
= EXTRACT_U_1(lisp_hdr
->record_count
);
272 if (ndo
->ndo_vflag
) {
273 key_id
= EXTRACT_BE_U_2(lisp_hdr
->key_id
);
274 ND_PRINT("\n %u record(s), ", record_count
);
275 ND_PRINT("Authentication %s,",
276 tok2str(auth_type
, "unknown-type", key_id
));
277 hex_print(ndo
, "\n Authentication-Data: ", packet_iterator
+
278 packet_offset
, auth_data_len
);
280 ND_PRINT(" %u record(s),", record_count
);
282 packet_offset
+= auth_data_len
;
284 if (record_count
== 0)
287 /* Print all the EID records */
288 while ((length
> packet_offset
) && (record_count
--)) {
290 ND_TCHECK_LEN(packet_iterator
+ packet_offset
,
291 MAP_REGISTER_EID_LEN
);
293 lisp_eid
= (const lisp_map_register_eid
*)
294 ((const u_char
*)lisp_hdr
+ packet_offset
);
295 packet_offset
+= MAP_REGISTER_EID_LEN
;
296 mask_len
= EXTRACT_U_1(lisp_eid
->eid_prefix_mask_length
);
297 eid_afi
= EXTRACT_BE_U_2(lisp_eid
->eid_prefix_afi
);
298 loc_count
= EXTRACT_U_1(lisp_eid
->locator_count
);
300 if (ndo
->ndo_vflag
) {
301 ttl
= EXTRACT_BE_U_4(lisp_eid
->ttl
);
302 ND_PRINT(" Record TTL %u,", ttl
);
303 action_flag(ndo
, EXTRACT_U_1(lisp_eid
->act_auth_inc_res
));
304 map_version
= EXTRACT_BE_U_2(lisp_eid
->reserved_and_version
) & 0x0FFF;
305 ND_PRINT(" Map Version: %u,", map_version
);
310 ND_TCHECK_4(packet_iterator
+ packet_offset
);
311 ND_PRINT(" EID %s/%u,", ipaddr_string(ndo
,
312 packet_iterator
+ packet_offset
), mask_len
);
316 ND_TCHECK_16(packet_iterator
+ packet_offset
);
317 ND_PRINT(" EID %s/%u,", ip6addr_string(ndo
,
318 packet_iterator
+ packet_offset
), mask_len
);
323 * No support for LCAF right now.
329 ND_PRINT(" %u locator(s)", loc_count
);
331 while (loc_count
--) {
332 ND_TCHECK_LEN(packet_iterator
+ packet_offset
,
333 MAP_REGISTER_LOC_LEN
);
334 lisp_loc
= (const lisp_map_register_loc
*) (packet_iterator
+ packet_offset
);
335 loc_ip_pointer
= (const u_char
*) (lisp_loc
+ 1);
336 packet_offset
+= MAP_REGISTER_LOC_LEN
;
337 loc_afi
= EXTRACT_BE_U_2(lisp_loc
->locator_afi
);
344 ND_TCHECK_4(packet_iterator
+ packet_offset
);
345 ND_PRINT(" LOC %s", ipaddr_string(ndo
, loc_ip_pointer
));
349 ND_TCHECK_16(packet_iterator
+ packet_offset
);
350 ND_PRINT(" LOC %s", ip6addr_string(ndo
, loc_ip_pointer
));
356 if (ndo
->ndo_vflag
) {
357 ND_PRINT("\n Priority/Weight %u/%u,"
358 " Multicast Priority/Weight %u/%u,",
359 EXTRACT_U_1(lisp_loc
->priority
),
360 EXTRACT_U_1(lisp_loc
->weight
),
361 EXTRACT_U_1(lisp_loc
->m_priority
),
362 EXTRACT_U_1(lisp_loc
->m_weight
));
364 EXTRACT_BE_U_2(lisp_loc
->unused_and_flag
));
370 * Print xTR and Site ID. Handle the fact that the packet could be invalid.
371 * If the xTR_ID_Present bit is not set, and we still have data to display,
372 * show it as hex data.
375 if (!ND_TTEST_LEN(packet_iterator
+ packet_offset
, 24))
377 hex_print_with_offset(ndo
, "\n xTR-ID: ", packet_iterator
+ packet_offset
, 16, 0);
378 ND_PRINT("\n SITE-ID: %" PRIu64
,
379 EXTRACT_BE_U_8(packet_iterator
+ packet_offset
+ 16));
381 /* Check if packet isn't over yet */
382 if (packet_iterator
+ packet_offset
< ndo
->ndo_snapend
) {
383 hex_print_with_offset(ndo
, "\n Data: ", packet_iterator
+ packet_offset
,
384 (ndo
->ndo_snapend
- (packet_iterator
+ packet_offset
)), 0);
392 ND_PRINT("%s", istr
);
397 extract_lisp_type(uint8_t lisp_hdr_flags
)
399 return (lisp_hdr_flags
) >> TYPE_INDEX
;
403 is_xtr_data_present(uint8_t type
, uint8_t lisp_hdr_flags
)
405 uint8_t xtr_present
= 0;
407 if (type
== LISP_MAP_REGISTER
)
408 xtr_present
= (lisp_hdr_flags
) & LISP_MAP_REGISTER_IBIT_MASK
;
409 else if (type
== LISP_MAP_NOTIFY
)
410 xtr_present
= (lisp_hdr_flags
) & LISP_MAP_NOTIFY_IBIT_MASK
;
415 static void lisp_hdr_flag(netdissect_options
*ndo
, const lisp_map_register_hdr
*lisp_hdr
)
417 uint8_t type
= extract_lisp_type(EXTRACT_U_1(lisp_hdr
->type_and_flag
));
419 if (!ndo
->ndo_vflag
) {
420 ND_PRINT("%s,", tok2str(lisp_type
, "unknown-type-%u", type
));
423 ND_PRINT("%s,", tok2str(lisp_type
, "unknown-type-%u", type
));
426 if (type
== LISP_MAP_REGISTER
) {
427 ND_PRINT(" flags [%s],", bittok2str(map_register_hdr_flag
,
428 "none", EXTRACT_BE_U_4(lisp_hdr
)));
429 } else if (type
== LISP_MAP_NOTIFY
) {
430 ND_PRINT(" flags [%s],", bittok2str(map_notify_hdr_flag
,
431 "none", EXTRACT_BE_U_4(lisp_hdr
)));
437 static void action_flag(netdissect_options
*ndo
, uint8_t act_auth_inc_res
)
440 uint8_t authoritative
;
442 authoritative
= ((act_auth_inc_res
>> 4) & 1);
445 ND_PRINT(" Authoritative,");
447 ND_PRINT(" Non-Authoritative,");
449 action
= act_auth_inc_res
>> 5;
450 ND_PRINT(" %s,", tok2str(lisp_eid_action
, "unknown", action
));
453 static void loc_hdr_flag(netdissect_options
*ndo
, uint16_t flag
)
455 ND_PRINT(" flags [%s],", bittok2str(lisp_loc_flag
, "none", flag
));