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.
30 * netdissect printer for LISP - Locator/Identifier Separation Protocol
34 * The Map-Register message format is:
37 * 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
38 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 * |Type=3 |P|S|I|R| Reserved |M| Record Count |
40 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45 * | Key ID | Authentication Data Length |
46 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
47 * ~ Authentication Data ~
48 * +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
50 * | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
51 * R | Locator Count | EID mask-len | ACT |A| Reserved |
52 * e +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
53 * c | Rsvd | Map-Version Number | EID-Prefix-AFI |
54 * o +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
56 * d +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
57 * | /| Priority | Weight | M Priority | M Weight |
58 * | L +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
59 * | o | Unused Flags |L|p|R| Loc-AFI |
60 * | c +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
62 * +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
65 * The Map-Notify message format is:
68 * 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
69 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
70 * |Type=4 |I|R| Reserved | Record Count |
71 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
73 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
75 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
76 * | Key ID | Authentication Data Length |
77 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
78 * ~ Authentication Data ~
79 * +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
81 * | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
82 * R | Locator Count | EID mask-len | ACT |A| Reserved |
83 * e +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
84 * c | Rsvd | Map-Version Number | EID-Prefix-AFI |
85 * o +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
87 * d +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
88 * | /| Priority | Weight | M Priority | M Weight |
89 * | L +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
90 * | o | Unused Flags |L|p|R| Loc-AFI |
91 * | c +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
93 * +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
100 #include <netdissect-stdinc.h>
101 #include <netdissect.h>
109 #include "addrtoname.h"
111 static const char tstr
[] = " [|LISP]";
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_uint8_t reserved_version_hi
;
208 nd_uint8_t version_low
;
209 nd_uint16_t eid_prefix_afi
;
210 } lisp_map_register_eid
;
212 #define MAP_REGISTER_EID_LEN sizeof(lisp_map_register_eid)
214 typedef struct map_register_loc
{
217 nd_uint8_t m_priority
;
219 nd_uint16_t unused_and_flag
;
220 nd_uint16_t locator_afi
;
221 } lisp_map_register_loc
;
223 #define MAP_REGISTER_LOC_LEN sizeof(lisp_map_register_loc)
225 static inline uint8_t extract_lisp_type(uint8_t);
226 static inline uint8_t is_xtr_data_present(uint8_t , uint8_t);
227 static void lisp_hdr_flag(netdissect_options
*, const lisp_map_register_hdr
*);
228 static void action_flag(netdissect_options
*, uint8_t);
229 static void loc_hdr_flag(netdissect_options
*, uint16_t);
231 void lisp_print(netdissect_options
*ndo
, const u_char
*bp
, u_int length
)
237 uint8_t record_count
;
241 uint16_t map_version
;
242 uint16_t packet_offset
;
243 uint16_t auth_data_len
;
245 const u_char
*packet_iterator
;
246 const u_char
*loc_ip_pointer
;
247 const lisp_map_register_hdr
*lisp_hdr
;
248 const lisp_map_register_eid
*lisp_eid
;
249 const lisp_map_register_loc
*lisp_loc
;
251 /* Check if enough bytes for header are available */
252 ND_TCHECK2(*bp
, MAP_REGISTER_HDR_LEN
);
253 lisp_hdr
= (const lisp_map_register_hdr
*) bp
;
254 lisp_hdr_flag(ndo
, lisp_hdr
);
255 /* Supporting only MAP NOTIFY and MAP REGISTER LISP packets */
256 type
= extract_lisp_type(lisp_hdr
->type_and_flag
);
257 if ((type
!= LISP_MAP_REGISTER
) && (type
!= LISP_MAP_NOTIFY
))
260 /* Find if the packet contains xTR and Site-ID data */
261 xtr_present
= is_xtr_data_present(type
, lisp_hdr
->type_and_flag
);
263 /* Extract the number of EID records present */
264 auth_data_len
= EXTRACT_16BITS(&lisp_hdr
->auth_data_len
);
265 packet_iterator
= (const u_char
*)(lisp_hdr
);
266 packet_offset
= MAP_REGISTER_HDR_LEN
;
267 record_count
= lisp_hdr
->record_count
;
269 if (ndo
->ndo_vflag
) {
270 key_id
= EXTRACT_16BITS(&lisp_hdr
->key_id
);
271 ND_PRINT((ndo
, "\n %u record(s), ", record_count
));
272 ND_PRINT((ndo
, "Authentication %s,",
273 tok2str(auth_type
, "unknown-type", key_id
)));
274 hex_print(ndo
, "\n Authentication-Data: ", packet_iterator
+
275 packet_offset
, auth_data_len
);
277 ND_PRINT((ndo
, " %u record(s),", record_count
));
279 packet_offset
+= auth_data_len
;
281 if (record_count
== 0)
284 /* Print all the EID records */
285 while ((length
> packet_offset
) && (record_count
--)) {
287 ND_TCHECK2(*(packet_iterator
+ packet_offset
), MAP_REGISTER_EID_LEN
);
288 ND_PRINT((ndo
, "\n"));
289 lisp_eid
= (const lisp_map_register_eid
*)
290 ((const u_char
*)lisp_hdr
+ packet_offset
);
291 packet_offset
+= MAP_REGISTER_EID_LEN
;
292 mask_len
= lisp_eid
->eid_prefix_mask_length
;
293 eid_afi
= EXTRACT_16BITS(&lisp_eid
->eid_prefix_afi
);
294 loc_count
= lisp_eid
->locator_count
;
296 if (ndo
->ndo_vflag
) {
297 ttl
= EXTRACT_32BITS(&lisp_eid
->ttl
);
298 ND_PRINT((ndo
, " Record TTL %u,", ttl
));
299 action_flag(ndo
, lisp_eid
->act_auth_inc_res
);
300 map_version
= (((lisp_eid
->reserved_version_hi
) & 15 ) * 255) +
301 lisp_eid
->version_low
;
302 ND_PRINT((ndo
, " Map Version: %u,", map_version
));
307 ND_TCHECK2(*(packet_iterator
+ packet_offset
), 4);
308 ND_PRINT((ndo
, " EID %s/%u,", ipaddr_string(ndo
,
309 packet_iterator
+ packet_offset
), mask_len
));
313 ND_TCHECK2(*(packet_iterator
+ packet_offset
), 16);
314 ND_PRINT((ndo
, " EID %s/%u,", ip6addr_string(ndo
,
315 packet_iterator
+ packet_offset
), mask_len
));
320 * No support for LCAF right now.
326 ND_PRINT((ndo
, " %u locator(s)", loc_count
));
328 while (loc_count
--) {
329 ND_TCHECK2(*(packet_iterator
+ packet_offset
), MAP_REGISTER_LOC_LEN
);
330 lisp_loc
= (const lisp_map_register_loc
*) (packet_iterator
+ packet_offset
);
331 loc_ip_pointer
= (const u_char
*) (lisp_loc
+ 1);
332 packet_offset
+= MAP_REGISTER_LOC_LEN
;
333 loc_afi
= EXTRACT_16BITS(&lisp_loc
->locator_afi
);
336 ND_PRINT((ndo
, "\n "));
340 ND_TCHECK2(*(packet_iterator
+ packet_offset
), 4);
341 ND_PRINT((ndo
, " LOC %s", ipaddr_string(ndo
, loc_ip_pointer
)));
345 ND_TCHECK2(*(packet_iterator
+ packet_offset
), 16);
346 ND_PRINT((ndo
, " LOC %s", ip6addr_string(ndo
, loc_ip_pointer
)));
352 if (ndo
->ndo_vflag
) {
353 ND_PRINT((ndo
, "\n Priority/Weight %u/%u,"
354 " Multicast Priority/Weight %u/%u,",
355 lisp_loc
->priority
, lisp_loc
->weight
,
356 lisp_loc
->m_priority
, lisp_loc
->m_weight
));
357 loc_hdr_flag(ndo
, EXTRACT_16BITS(&lisp_loc
->unused_and_flag
));
363 * Print xTR and Site ID. Handle the fact that the packet could be invalid.
364 * If the xTR_ID_Present bit is not set, and we still have data to display,
365 * show it as hex data.
368 if (!ND_TTEST2(*(packet_iterator
+ packet_offset
), 24))
370 hex_print_with_offset(ndo
, "\n xTR-ID: ", packet_iterator
+ packet_offset
, 16, 0);
371 ND_PRINT((ndo
, "\n SITE-ID: %" PRIu64
,
372 EXTRACT_64BITS(packet_iterator
+ packet_offset
+ 16)));
374 /* Check if packet isn't over yet */
375 if (packet_iterator
+ packet_offset
< ndo
->ndo_snapend
) {
376 hex_print_with_offset(ndo
, "\n Data: ", packet_iterator
+ packet_offset
,
377 (ndo
->ndo_snapend
- (packet_iterator
+ packet_offset
)), 0);
382 ND_PRINT((ndo
, "\n %s", tstr
));
385 ND_PRINT((ndo
, "\n %s", istr
));
389 static inline uint8_t extract_lisp_type(uint8_t lisp_hdr_flags
)
391 return (lisp_hdr_flags
) >> TYPE_INDEX
;
394 static inline uint8_t is_xtr_data_present(uint8_t type
, uint8_t lisp_hdr_flags
)
396 uint8_t xtr_present
= 0;
398 if (type
== LISP_MAP_REGISTER
)
399 xtr_present
= (lisp_hdr_flags
) & LISP_MAP_REGISTER_IBIT_MASK
;
400 else if (type
== LISP_MAP_NOTIFY
)
401 xtr_present
= (lisp_hdr_flags
) & LISP_MAP_NOTIFY_IBIT_MASK
;
406 static void lisp_hdr_flag(netdissect_options
*ndo
, const lisp_map_register_hdr
*lisp_hdr
)
408 uint8_t type
= extract_lisp_type(lisp_hdr
->type_and_flag
);
410 if (!ndo
->ndo_vflag
) {
411 ND_PRINT((ndo
, "%s,", tok2str(lisp_type
, "unknown-type-%u", type
)));
414 ND_PRINT((ndo
, "%s,", tok2str(lisp_type
, "unknown-type-%u", type
)));
417 if (type
== LISP_MAP_REGISTER
) {
418 ND_PRINT((ndo
, " flags [%s],", bittok2str(map_register_hdr_flag
,
419 "none", EXTRACT_32BITS(lisp_hdr
))));
420 } else if (type
== LISP_MAP_NOTIFY
) {
421 ND_PRINT((ndo
, " flags [%s],", bittok2str(map_notify_hdr_flag
,
422 "none", EXTRACT_32BITS(lisp_hdr
))));
428 static void action_flag(netdissect_options
*ndo
, uint8_t act_auth_inc_res
)
431 uint8_t authoritative
;
433 authoritative
= ((act_auth_inc_res
>> 4) & 1);
436 ND_PRINT((ndo
, " Authoritative,"));
438 ND_PRINT((ndo
, " Non-Authoritative,"));
440 action
= act_auth_inc_res
>> 5;
441 ND_PRINT((ndo
, " %s,", tok2str(lisp_eid_action
, "unknown", action
)));
444 static void loc_hdr_flag(netdissect_options
*ndo
, uint16_t flag
)
446 ND_PRINT((ndo
, " flags [%s],", bittok2str(lisp_loc_flag
, "none", flag
)));