xref: /netbsd-src/external/bsd/tcpdump/dist/print-lisp.c (revision 26ba0b503b498a5194a71ac319838b7f5497f3fe)
1784088dfSchristos /*
2784088dfSchristos  * Copyright (c) 2015 Ritesh Ranjan (r.ranjan789@gmail.com)
3784088dfSchristos  * All rights reserved.
4784088dfSchristos  *
5784088dfSchristos  * Redistribution and use in source and binary forms, with or without
6784088dfSchristos  * modification, are permitted provided that the following conditions
7784088dfSchristos  * are met:
8784088dfSchristos  * 1. Redistributions of source code must retain the above copyright
9784088dfSchristos  *    notice, this list of conditions and the following disclaimer.
10784088dfSchristos  * 2. Redistributions in binary form must reproduce the above copyright
11784088dfSchristos  *    notice, this list of conditions and the following disclaimer in the
12784088dfSchristos  *    documentation and/or other materials provided with the distribution.
13784088dfSchristos  * 3. The name of the author may not be used to endorse or promote products
14784088dfSchristos  *    derived from this software without specific prior written permission.
15784088dfSchristos  *
16784088dfSchristos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17784088dfSchristos  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18784088dfSchristos  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19784088dfSchristos  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20784088dfSchristos  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21784088dfSchristos  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22784088dfSchristos  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23784088dfSchristos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24784088dfSchristos  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25784088dfSchristos  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26784088dfSchristos  * POSSIBILITY OF SUCH DAMAGE.
27784088dfSchristos  */
28784088dfSchristos 
29dc860a36Sspz /* \summary: - Locator/Identifier Separation Protocol (LISP) printer */
30dc860a36Sspz 
31784088dfSchristos /*
32dc860a36Sspz  * specification: RFC 6830
33784088dfSchristos  *
34784088dfSchristos  *
35784088dfSchristos  * The Map-Register message format is:
36784088dfSchristos  *
37784088dfSchristos  *       0                   1                   2                   3
38784088dfSchristos  *       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
39784088dfSchristos  *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40784088dfSchristos  *      |Type=3 |P|S|I|R|      Reserved               |M| Record Count  |
41784088dfSchristos  *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42784088dfSchristos  *      |                         Nonce . . .                           |
43784088dfSchristos  *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44784088dfSchristos  *      |                         . . . Nonce                           |
45784088dfSchristos  *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46784088dfSchristos  *      |            Key ID             |  Authentication Data Length   |
47784088dfSchristos  *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
48784088dfSchristos  *      ~                     Authentication Data                       ~
49784088dfSchristos  *  +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
50784088dfSchristos  *  |   |                          Record TTL                           |
51784088dfSchristos  *  |   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
52784088dfSchristos  *  R   | Locator Count | EID mask-len  | ACT |A|      Reserved         |
53784088dfSchristos  *  e   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
54784088dfSchristos  *  c   | Rsvd  |  Map-Version Number   |        EID-Prefix-AFI         |
55784088dfSchristos  *  o   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
56784088dfSchristos  *  r   |                          EID-Prefix                           |
57784088dfSchristos  *  d   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
58784088dfSchristos  *  |  /|    Priority   |    Weight     |  M Priority   |   M Weight    |
59784088dfSchristos  *  | L +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
60784088dfSchristos  *  | o |        Unused Flags     |L|p|R|           Loc-AFI             |
61784088dfSchristos  *  | c +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
62784088dfSchristos  *  |  \|                             Locator                           |
63784088dfSchristos  *  +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
64784088dfSchristos  *
65784088dfSchristos  *
66784088dfSchristos  * The Map-Notify message format is:
67784088dfSchristos  *
68784088dfSchristos  *       0                   1                   2                   3
69784088dfSchristos  *       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
70784088dfSchristos  *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
71784088dfSchristos  *      |Type=4 |I|R|          Reserved                 | Record Count  |
72784088dfSchristos  *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
73784088dfSchristos  *      |                         Nonce . . .                           |
74784088dfSchristos  *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
75784088dfSchristos  *      |                         . . . Nonce                           |
76784088dfSchristos  *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
77784088dfSchristos  *      |            Key ID             |  Authentication Data Length   |
78784088dfSchristos  *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
79784088dfSchristos  *      ~                     Authentication Data                       ~
80784088dfSchristos  *  +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
81784088dfSchristos  *  |   |                          Record TTL                           |
82784088dfSchristos  *  |   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
83784088dfSchristos  *  R   | Locator Count | EID mask-len  | ACT |A|      Reserved         |
84784088dfSchristos  *  e   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
85784088dfSchristos  *  c   | Rsvd  |  Map-Version Number   |         EID-Prefix-AFI        |
86784088dfSchristos  *  o   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
87784088dfSchristos  *  r   |                          EID-Prefix                           |
88784088dfSchristos  *  d   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
89784088dfSchristos  *  |  /|    Priority   |    Weight     |  M Priority   |   M Weight    |
90784088dfSchristos  *  | L +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
91784088dfSchristos  *  | o |        Unused Flags     |L|p|R|           Loc-AFI             |
92784088dfSchristos  *  | c +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
93784088dfSchristos  *  |  \|                             Locator                           |
94784088dfSchristos  *  +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
95784088dfSchristos  */
96784088dfSchristos 
97fdccd7e4Schristos #include <sys/cdefs.h>
98fdccd7e4Schristos #ifndef lint
99*26ba0b50Schristos __RCSID("$NetBSD: print-lisp.c,v 1.5 2024/09/02 16:15:31 christos Exp $");
100fdccd7e4Schristos #endif
101fdccd7e4Schristos 
102c74ad251Schristos #include <config.h>
103784088dfSchristos 
104c74ad251Schristos #include "netdissect-stdinc.h"
105c74ad251Schristos #include "netdissect.h"
106784088dfSchristos 
107784088dfSchristos #include "ip.h"
108784088dfSchristos #include "ip6.h"
109784088dfSchristos 
110784088dfSchristos #include "extract.h"
111784088dfSchristos #include "addrtoname.h"
112784088dfSchristos 
113784088dfSchristos 
114784088dfSchristos #define IPv4_AFI			1
115784088dfSchristos #define IPv6_AFI			2
116784088dfSchristos #define TYPE_INDEX			4
117784088dfSchristos #define LISP_MAP_NOTIFY_IBIT_MASK	8
118784088dfSchristos #define LISP_MAP_REGISTER_IBIT_MASK	2
119784088dfSchristos 
120784088dfSchristos enum {
121784088dfSchristos 	LISP_MAP_REQUEST = 1,
122784088dfSchristos 	LISP_MAP_REPLY,
123784088dfSchristos 	LISP_MAP_REGISTER,
124784088dfSchristos 	LISP_MAP_NOTIFY,
125784088dfSchristos 	LISP_ENCAPSULATED_CONTROL_MESSAGE = 8
126784088dfSchristos };
127784088dfSchristos 
128784088dfSchristos enum {
129784088dfSchristos 	LISP_AUTH_NONE,
130784088dfSchristos 	LISP_AUTH_SHA1,
131784088dfSchristos 	LISP_AUTH_SHA256
132784088dfSchristos };
133784088dfSchristos 
134784088dfSchristos static const struct tok lisp_type [] = {
135784088dfSchristos 	{ 0, "LISP-Reserved"			 },
136784088dfSchristos 	{ 1, "LISP-Map-Request"			 },
137784088dfSchristos 	{ 2, "LISP-Map-Reply"			 },
138784088dfSchristos 	{ 3, "LISP-Map-Register"		 },
139784088dfSchristos 	{ 4, "LISP-Map-Notify"			 },
140*26ba0b50Schristos 	{ 8, "LISP-Encapsulated-Control-Message" },
141784088dfSchristos 	{ 0, NULL }
142784088dfSchristos };
143784088dfSchristos 
144784088dfSchristos /*
145784088dfSchristos  * P-Bit : Request for Proxy Map-Reply from the MS/MR
146784088dfSchristos  * S-Bit : Security Enhancement. ETR is LISP-SEC enabled. draft-ietf-lisp-sec
147784088dfSchristos  * I-Bit : 128 bit xTR-ID and 64 bit Site-ID present.
148784088dfSchristos  *	   xTR-ID and Site-ID help in differentiation of xTRs in multi xTR
149784088dfSchristos  *	   and multi Site deployment scenarios.
150784088dfSchristos  * R-Bit : Built for a Reencapsulating-Tunnel-Router. Used in Traffic
151784088dfSchristos  *	   Engineering and Service Chaining
152784088dfSchristos  */
153784088dfSchristos static const struct tok map_register_hdr_flag[] = {
154784088dfSchristos 	{ 0x08000000, "P-Proxy-Map-Reply"  },
155784088dfSchristos 	{ 0x04000000, "S-LISP-SEC-Capable" },
156784088dfSchristos 	{ 0x02000000, "I-xTR-ID-Present"   },
157784088dfSchristos 	{ 0x01000000, "R-Build-For-RTR"    },
158784088dfSchristos 	{ 0x00000100, "M-Want-Map-Notify"  },
159784088dfSchristos 	{ 0, NULL }
160784088dfSchristos };
161784088dfSchristos 
162784088dfSchristos static const struct tok map_notify_hdr_flag[] = {
163784088dfSchristos 	{ 0x08000000, "I-xTR-ID-Present"   },
164784088dfSchristos 	{ 0x04000000, "R-Build-For-RTR"    },
165784088dfSchristos 	{ 0, NULL }
166784088dfSchristos };
167784088dfSchristos 
168784088dfSchristos static const struct tok auth_type[] = {
169784088dfSchristos 	{ LISP_AUTH_NONE,   "None"   },
170784088dfSchristos 	{ LISP_AUTH_SHA1,   "SHA1"   },
171784088dfSchristos 	{ LISP_AUTH_SHA256, "SHA256" },
172784088dfSchristos 	{ 0, NULL}
173784088dfSchristos };
174784088dfSchristos 
175784088dfSchristos static const struct tok lisp_eid_action[] = {
176784088dfSchristos 	{ 0, "No-Action"	},
177784088dfSchristos 	{ 1, "Natively-Forward" },
178784088dfSchristos 	{ 2, "Send-Map-Request" },
179784088dfSchristos 	{ 3, "Drop"		},
180784088dfSchristos 	{ 0, NULL}
181784088dfSchristos };
182784088dfSchristos 
183784088dfSchristos static const struct tok lisp_loc_flag[] = {
184784088dfSchristos 	{ 0x0004, "Local-Locator" },
185784088dfSchristos 	{ 0x0002, "RLoc-Probed"	  },
186784088dfSchristos 	{ 0x0001, "Reachable"	  },
187784088dfSchristos 	{ 0, NULL }
188784088dfSchristos };
189784088dfSchristos 
190784088dfSchristos typedef struct map_register_hdr {
191784088dfSchristos 	nd_uint8_t type_and_flag;
192784088dfSchristos 	nd_uint8_t reserved;
193784088dfSchristos 	nd_uint8_t reserved_and_flag2;
194784088dfSchristos 	nd_uint8_t record_count;
195784088dfSchristos 	nd_uint64_t nonce;
196784088dfSchristos 	nd_uint16_t key_id;
197784088dfSchristos 	nd_uint16_t auth_data_len;
198784088dfSchristos } lisp_map_register_hdr;
199784088dfSchristos 
200784088dfSchristos #define MAP_REGISTER_HDR_LEN sizeof(lisp_map_register_hdr)
201784088dfSchristos 
202784088dfSchristos typedef struct map_register_eid {
203784088dfSchristos 	nd_uint32_t ttl;
204784088dfSchristos 	nd_uint8_t locator_count;
205784088dfSchristos 	nd_uint8_t eid_prefix_mask_length;
206784088dfSchristos 	nd_uint8_t act_auth_inc_res;
207784088dfSchristos 	nd_uint8_t reserved;
208c74ad251Schristos 	nd_uint16_t reserved_and_version;
209784088dfSchristos 	nd_uint16_t eid_prefix_afi;
210784088dfSchristos } lisp_map_register_eid;
211784088dfSchristos 
212784088dfSchristos #define MAP_REGISTER_EID_LEN sizeof(lisp_map_register_eid)
213784088dfSchristos 
214784088dfSchristos typedef struct map_register_loc {
215784088dfSchristos 	nd_uint8_t priority;
216784088dfSchristos 	nd_uint8_t weight;
217784088dfSchristos 	nd_uint8_t m_priority;
218784088dfSchristos 	nd_uint8_t m_weight;
219784088dfSchristos 	nd_uint16_t unused_and_flag;
220784088dfSchristos 	nd_uint16_t locator_afi;
221784088dfSchristos } lisp_map_register_loc;
222784088dfSchristos 
223784088dfSchristos #define MAP_REGISTER_LOC_LEN sizeof(lisp_map_register_loc)
224784088dfSchristos 
225c74ad251Schristos static uint8_t extract_lisp_type(uint8_t);
226c74ad251Schristos static uint8_t is_xtr_data_present(uint8_t, uint8_t);
227784088dfSchristos static void lisp_hdr_flag(netdissect_options *, const lisp_map_register_hdr *);
228784088dfSchristos static void action_flag(netdissect_options *, uint8_t);
229784088dfSchristos static void loc_hdr_flag(netdissect_options *, uint16_t);
230784088dfSchristos 
231c74ad251Schristos void
232c74ad251Schristos lisp_print(netdissect_options *ndo, const u_char *bp, u_int length)
233784088dfSchristos {
234c74ad251Schristos 	uint8_t type_and_flag;
235784088dfSchristos 	uint8_t type;
236784088dfSchristos 	uint8_t mask_len;
237784088dfSchristos 	uint8_t loc_count;
238784088dfSchristos 	uint8_t xtr_present;
239784088dfSchristos 	uint8_t record_count;
240784088dfSchristos 	uint16_t key_id;
241784088dfSchristos 	uint16_t eid_afi;
242784088dfSchristos 	uint16_t loc_afi;
243784088dfSchristos 	uint16_t map_version;
244784088dfSchristos 	uint16_t packet_offset;
245784088dfSchristos 	uint16_t auth_data_len;
246784088dfSchristos 	uint32_t ttl;
247784088dfSchristos 	const u_char *packet_iterator;
248784088dfSchristos 	const u_char *loc_ip_pointer;
249784088dfSchristos 	const lisp_map_register_hdr *lisp_hdr;
250784088dfSchristos 	const lisp_map_register_eid *lisp_eid;
251784088dfSchristos 	const lisp_map_register_loc *lisp_loc;
252784088dfSchristos 
253c74ad251Schristos 	ndo->ndo_protocol = "lisp";
254784088dfSchristos 	/* Check if enough bytes for header are available */
255c74ad251Schristos 	ND_TCHECK_LEN(bp, MAP_REGISTER_HDR_LEN);
256784088dfSchristos 	lisp_hdr = (const lisp_map_register_hdr *) bp;
257784088dfSchristos 	lisp_hdr_flag(ndo, lisp_hdr);
258784088dfSchristos 	/* Supporting only MAP NOTIFY and MAP REGISTER LISP packets */
259c74ad251Schristos 	type_and_flag = GET_U_1(lisp_hdr->type_and_flag);
260c74ad251Schristos 	type = extract_lisp_type(type_and_flag);
261784088dfSchristos 	if ((type != LISP_MAP_REGISTER) && (type != LISP_MAP_NOTIFY))
262784088dfSchristos 		return;
263784088dfSchristos 
264784088dfSchristos 	/* Find if the packet contains xTR and Site-ID data */
265c74ad251Schristos 	xtr_present = is_xtr_data_present(type, type_and_flag);
266784088dfSchristos 
267784088dfSchristos 	/* Extract the number of EID records present */
268c74ad251Schristos 	auth_data_len = GET_BE_U_2(lisp_hdr->auth_data_len);
269784088dfSchristos 	packet_iterator = (const u_char *)(lisp_hdr);
270784088dfSchristos 	packet_offset = MAP_REGISTER_HDR_LEN;
271c74ad251Schristos 	record_count = GET_U_1(lisp_hdr->record_count);
272784088dfSchristos 
273784088dfSchristos 	if (ndo->ndo_vflag) {
274c74ad251Schristos 		key_id = GET_BE_U_2(lisp_hdr->key_id);
275c74ad251Schristos 		ND_PRINT("\n    %u record(s), ", record_count);
276c74ad251Schristos 		ND_PRINT("Authentication %s,",
277c74ad251Schristos 			tok2str(auth_type, "unknown-type", key_id));
278784088dfSchristos 		hex_print(ndo, "\n    Authentication-Data: ", packet_iterator +
279784088dfSchristos 						packet_offset, auth_data_len);
280784088dfSchristos 	} else {
281c74ad251Schristos 		ND_PRINT(" %u record(s),", record_count);
282784088dfSchristos 	}
283784088dfSchristos 	packet_offset += auth_data_len;
284784088dfSchristos 
285784088dfSchristos 	if (record_count == 0)
286784088dfSchristos 		goto invalid;
287784088dfSchristos 
288784088dfSchristos 	/* Print all the EID records */
289c74ad251Schristos 	while ((length > packet_offset) && (record_count != 0)) {
290c74ad251Schristos 		record_count--;
291c74ad251Schristos 		ND_TCHECK_LEN(packet_iterator + packet_offset,
292c74ad251Schristos 			      MAP_REGISTER_EID_LEN);
293c74ad251Schristos 		ND_PRINT("\n");
294784088dfSchristos 		lisp_eid = (const lisp_map_register_eid *)
295784088dfSchristos 				((const u_char *)lisp_hdr + packet_offset);
296784088dfSchristos 		packet_offset += MAP_REGISTER_EID_LEN;
297c74ad251Schristos 		mask_len = GET_U_1(lisp_eid->eid_prefix_mask_length);
298c74ad251Schristos 		eid_afi = GET_BE_U_2(lisp_eid->eid_prefix_afi);
299c74ad251Schristos 		loc_count = GET_U_1(lisp_eid->locator_count);
300784088dfSchristos 
301784088dfSchristos 		if (ndo->ndo_vflag) {
302c74ad251Schristos 			ttl = GET_BE_U_4(lisp_eid->ttl);
303c74ad251Schristos 			ND_PRINT("      Record TTL %u,", ttl);
304c74ad251Schristos 			action_flag(ndo, GET_U_1(lisp_eid->act_auth_inc_res));
305c74ad251Schristos 			map_version = GET_BE_U_2(lisp_eid->reserved_and_version) & 0x0FFF;
306c74ad251Schristos 			ND_PRINT(" Map Version: %u,", map_version);
307784088dfSchristos 		}
308784088dfSchristos 
309784088dfSchristos 		switch (eid_afi) {
310784088dfSchristos 		case IPv4_AFI:
311c74ad251Schristos 			ND_PRINT(" EID %s/%u,",
312c74ad251Schristos 				GET_IPADDR_STRING(packet_iterator + packet_offset),
313c74ad251Schristos 				mask_len);
314784088dfSchristos 			packet_offset += 4;
315784088dfSchristos 			break;
316784088dfSchristos 		case IPv6_AFI:
317c74ad251Schristos 			ND_PRINT(" EID %s/%u,",
318c74ad251Schristos 				GET_IP6ADDR_STRING(packet_iterator + packet_offset),
319c74ad251Schristos 				mask_len);
320784088dfSchristos 			packet_offset += 16;
321784088dfSchristos 			break;
322784088dfSchristos 		default:
323784088dfSchristos 			/*
324784088dfSchristos 			 * No support for LCAF right now.
325784088dfSchristos 			 */
326784088dfSchristos 			return;
327784088dfSchristos 			break;
328784088dfSchristos 		}
329784088dfSchristos 
330c74ad251Schristos 		ND_PRINT(" %u locator(s)", loc_count);
331784088dfSchristos 
332c74ad251Schristos 		while (loc_count != 0) {
333c74ad251Schristos 			loc_count--;
334c74ad251Schristos 			ND_TCHECK_LEN(packet_iterator + packet_offset,
335c74ad251Schristos 				      MAP_REGISTER_LOC_LEN);
336784088dfSchristos 			lisp_loc = (const lisp_map_register_loc *) (packet_iterator + packet_offset);
337784088dfSchristos 			loc_ip_pointer = (const u_char *) (lisp_loc + 1);
338784088dfSchristos 			packet_offset += MAP_REGISTER_LOC_LEN;
339c74ad251Schristos 			loc_afi = GET_BE_U_2(lisp_loc->locator_afi);
340784088dfSchristos 
341784088dfSchristos 			if (ndo->ndo_vflag)
342c74ad251Schristos 				ND_PRINT("\n       ");
343784088dfSchristos 
344784088dfSchristos 			switch (loc_afi) {
345784088dfSchristos 			case IPv4_AFI:
346c74ad251Schristos 				ND_TCHECK_4(packet_iterator + packet_offset);
347c74ad251Schristos 				ND_PRINT(" LOC %s", GET_IPADDR_STRING(loc_ip_pointer));
348784088dfSchristos 				packet_offset += 4;
349784088dfSchristos 				break;
350784088dfSchristos 			case IPv6_AFI:
351c74ad251Schristos 				ND_TCHECK_16(packet_iterator + packet_offset);
352c74ad251Schristos 				ND_PRINT(" LOC %s", GET_IP6ADDR_STRING(loc_ip_pointer));
353784088dfSchristos 				packet_offset += 16;
354784088dfSchristos 				break;
355784088dfSchristos 			default:
356784088dfSchristos 				break;
357784088dfSchristos 			}
358784088dfSchristos 			if (ndo->ndo_vflag) {
359c74ad251Schristos 				ND_PRINT("\n          Priority/Weight %u/%u,"
360784088dfSchristos 						" Multicast Priority/Weight %u/%u,",
361c74ad251Schristos 						GET_U_1(lisp_loc->priority),
362c74ad251Schristos 						GET_U_1(lisp_loc->weight),
363c74ad251Schristos 						GET_U_1(lisp_loc->m_priority),
364c74ad251Schristos 						GET_U_1(lisp_loc->m_weight));
365c74ad251Schristos 				loc_hdr_flag(ndo,
366c74ad251Schristos 					     GET_BE_U_2(lisp_loc->unused_and_flag));
367784088dfSchristos 			}
368784088dfSchristos 		}
369784088dfSchristos 	}
370784088dfSchristos 
371784088dfSchristos 	/*
372784088dfSchristos 	 * Print xTR and Site ID. Handle the fact that the packet could be invalid.
373784088dfSchristos 	 * If the xTR_ID_Present bit is not set, and we still have data to display,
374784088dfSchristos 	 * show it as hex data.
375784088dfSchristos 	 */
376784088dfSchristos 	if (xtr_present) {
377c74ad251Schristos 		if (!ND_TTEST_LEN(packet_iterator + packet_offset, 24))
378784088dfSchristos 			goto invalid;
379c74ad251Schristos 		hex_print(ndo, "\n    xTR-ID: ", packet_iterator + packet_offset, 16);
380c74ad251Schristos 		ND_PRINT("\n    SITE-ID: %" PRIu64,
381c74ad251Schristos 			GET_BE_U_8(packet_iterator + packet_offset + 16));
382784088dfSchristos 	} else {
383784088dfSchristos 		/* Check if packet isn't over yet */
384784088dfSchristos 		if (packet_iterator + packet_offset < ndo->ndo_snapend) {
385c74ad251Schristos 			hex_print(ndo, "\n    Data: ", packet_iterator + packet_offset,
386c74ad251Schristos 				ND_BYTES_AVAILABLE_AFTER(packet_iterator + packet_offset));
387784088dfSchristos 		}
388784088dfSchristos 	}
389784088dfSchristos 	return;
390784088dfSchristos trunc:
391c74ad251Schristos 	nd_print_trunc(ndo);
392784088dfSchristos 	return;
393784088dfSchristos invalid:
394c74ad251Schristos 	nd_print_invalid(ndo);
395784088dfSchristos }
396784088dfSchristos 
397c74ad251Schristos static uint8_t
398c74ad251Schristos extract_lisp_type(uint8_t lisp_hdr_flags)
399784088dfSchristos {
400784088dfSchristos 	return (lisp_hdr_flags) >> TYPE_INDEX;
401784088dfSchristos }
402784088dfSchristos 
403c74ad251Schristos static uint8_t
404c74ad251Schristos is_xtr_data_present(uint8_t type, uint8_t lisp_hdr_flags)
405784088dfSchristos {
406784088dfSchristos 	uint8_t xtr_present = 0;
407784088dfSchristos 
408784088dfSchristos 	if (type == LISP_MAP_REGISTER)
409784088dfSchristos 		xtr_present = (lisp_hdr_flags) & LISP_MAP_REGISTER_IBIT_MASK;
410784088dfSchristos 	else if (type == LISP_MAP_NOTIFY)
411784088dfSchristos 		xtr_present = (lisp_hdr_flags) & LISP_MAP_NOTIFY_IBIT_MASK;
412784088dfSchristos 
413784088dfSchristos 	return xtr_present;
414784088dfSchristos }
415784088dfSchristos 
416784088dfSchristos static void lisp_hdr_flag(netdissect_options *ndo, const lisp_map_register_hdr *lisp_hdr)
417784088dfSchristos {
418c74ad251Schristos 	uint8_t type = extract_lisp_type(GET_U_1(lisp_hdr->type_and_flag));
419784088dfSchristos 
420784088dfSchristos 	if (!ndo->ndo_vflag) {
421c74ad251Schristos 		ND_PRINT("%s,", tok2str(lisp_type, "unknown-type-%u", type));
422784088dfSchristos 		return;
423784088dfSchristos 	} else {
424c74ad251Schristos 		ND_PRINT("%s,", tok2str(lisp_type, "unknown-type-%u", type));
425784088dfSchristos 	}
426784088dfSchristos 
427784088dfSchristos 	if (type == LISP_MAP_REGISTER) {
428c74ad251Schristos 		ND_PRINT(" flags [%s],", bittok2str(map_register_hdr_flag,
429c74ad251Schristos 			 "none", GET_BE_U_4(lisp_hdr)));
430784088dfSchristos 	} else if (type == LISP_MAP_NOTIFY) {
431c74ad251Schristos 		ND_PRINT(" flags [%s],", bittok2str(map_notify_hdr_flag,
432c74ad251Schristos 			 "none", GET_BE_U_4(lisp_hdr)));
433784088dfSchristos 	}
434784088dfSchristos }
435784088dfSchristos 
436784088dfSchristos static void action_flag(netdissect_options *ndo, uint8_t act_auth_inc_res)
437784088dfSchristos {
438784088dfSchristos 	uint8_t action;
439784088dfSchristos 	uint8_t authoritative;
440784088dfSchristos 
441784088dfSchristos 	authoritative  = ((act_auth_inc_res >> 4) & 1);
442784088dfSchristos 
443784088dfSchristos 	if (authoritative)
444c74ad251Schristos 		ND_PRINT(" Authoritative,");
445784088dfSchristos 	else
446c74ad251Schristos 		ND_PRINT(" Non-Authoritative,");
447784088dfSchristos 
448784088dfSchristos 	action = act_auth_inc_res >> 5;
449c74ad251Schristos 	ND_PRINT(" %s,", tok2str(lisp_eid_action, "unknown", action));
450784088dfSchristos }
451784088dfSchristos 
452784088dfSchristos static void loc_hdr_flag(netdissect_options *ndo, uint16_t flag)
453784088dfSchristos {
454c74ad251Schristos 	ND_PRINT(" flags [%s],", bittok2str(lisp_loc_flag, "none", flag));
455784088dfSchristos }
456784088dfSchristos 
457