xref: /freebsd-src/contrib/tcpdump/print-lisp.c (revision 0a7e5f1f02aad2ff5fff1c60f44c6975fd07e1d9)
13340d773SGleb Smirnoff /*
23340d773SGleb Smirnoff  * Copyright (c) 2015 Ritesh Ranjan (r.ranjan789@gmail.com)
33340d773SGleb Smirnoff  * All rights reserved.
43340d773SGleb Smirnoff  *
53340d773SGleb Smirnoff  * Redistribution and use in source and binary forms, with or without
63340d773SGleb Smirnoff  * modification, are permitted provided that the following conditions
73340d773SGleb Smirnoff  * are met:
83340d773SGleb Smirnoff  * 1. Redistributions of source code must retain the above copyright
93340d773SGleb Smirnoff  *    notice, this list of conditions and the following disclaimer.
103340d773SGleb Smirnoff  * 2. Redistributions in binary form must reproduce the above copyright
113340d773SGleb Smirnoff  *    notice, this list of conditions and the following disclaimer in the
123340d773SGleb Smirnoff  *    documentation and/or other materials provided with the distribution.
133340d773SGleb Smirnoff  * 3. The name of the author may not be used to endorse or promote products
143340d773SGleb Smirnoff  *    derived from this software without specific prior written permission.
153340d773SGleb Smirnoff  *
163340d773SGleb Smirnoff  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
173340d773SGleb Smirnoff  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
183340d773SGleb Smirnoff  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
193340d773SGleb Smirnoff  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
203340d773SGleb Smirnoff  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
213340d773SGleb Smirnoff  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
223340d773SGleb Smirnoff  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
233340d773SGleb Smirnoff  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
243340d773SGleb Smirnoff  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
253340d773SGleb Smirnoff  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
263340d773SGleb Smirnoff  * POSSIBILITY OF SUCH DAMAGE.
273340d773SGleb Smirnoff  */
283340d773SGleb Smirnoff 
293340d773SGleb Smirnoff /* \summary: - Locator/Identifier Separation Protocol (LISP) printer */
303340d773SGleb Smirnoff 
313340d773SGleb Smirnoff /*
323340d773SGleb Smirnoff  * specification: RFC 6830
333340d773SGleb Smirnoff  *
343340d773SGleb Smirnoff  *
353340d773SGleb Smirnoff  * The Map-Register message format is:
363340d773SGleb Smirnoff  *
373340d773SGleb Smirnoff  *       0                   1                   2                   3
383340d773SGleb Smirnoff  *       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
393340d773SGleb Smirnoff  *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
403340d773SGleb Smirnoff  *      |Type=3 |P|S|I|R|      Reserved               |M| Record Count  |
413340d773SGleb Smirnoff  *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
423340d773SGleb Smirnoff  *      |                         Nonce . . .                           |
433340d773SGleb Smirnoff  *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
443340d773SGleb Smirnoff  *      |                         . . . Nonce                           |
453340d773SGleb Smirnoff  *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
463340d773SGleb Smirnoff  *      |            Key ID             |  Authentication Data Length   |
473340d773SGleb Smirnoff  *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
483340d773SGleb Smirnoff  *      ~                     Authentication Data                       ~
493340d773SGleb Smirnoff  *  +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
503340d773SGleb Smirnoff  *  |   |                          Record TTL                           |
513340d773SGleb Smirnoff  *  |   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
523340d773SGleb Smirnoff  *  R   | Locator Count | EID mask-len  | ACT |A|      Reserved         |
533340d773SGleb Smirnoff  *  e   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
543340d773SGleb Smirnoff  *  c   | Rsvd  |  Map-Version Number   |        EID-Prefix-AFI         |
553340d773SGleb Smirnoff  *  o   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
563340d773SGleb Smirnoff  *  r   |                          EID-Prefix                           |
573340d773SGleb Smirnoff  *  d   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
583340d773SGleb Smirnoff  *  |  /|    Priority   |    Weight     |  M Priority   |   M Weight    |
593340d773SGleb Smirnoff  *  | L +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
603340d773SGleb Smirnoff  *  | o |        Unused Flags     |L|p|R|           Loc-AFI             |
613340d773SGleb Smirnoff  *  | c +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
623340d773SGleb Smirnoff  *  |  \|                             Locator                           |
633340d773SGleb Smirnoff  *  +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
643340d773SGleb Smirnoff  *
653340d773SGleb Smirnoff  *
663340d773SGleb Smirnoff  * The Map-Notify message format is:
673340d773SGleb Smirnoff  *
683340d773SGleb Smirnoff  *       0                   1                   2                   3
693340d773SGleb Smirnoff  *       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
703340d773SGleb Smirnoff  *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
713340d773SGleb Smirnoff  *      |Type=4 |I|R|          Reserved                 | Record Count  |
723340d773SGleb Smirnoff  *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
733340d773SGleb Smirnoff  *      |                         Nonce . . .                           |
743340d773SGleb Smirnoff  *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
753340d773SGleb Smirnoff  *      |                         . . . Nonce                           |
763340d773SGleb Smirnoff  *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
773340d773SGleb Smirnoff  *      |            Key ID             |  Authentication Data Length   |
783340d773SGleb Smirnoff  *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
793340d773SGleb Smirnoff  *      ~                     Authentication Data                       ~
803340d773SGleb Smirnoff  *  +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
813340d773SGleb Smirnoff  *  |   |                          Record TTL                           |
823340d773SGleb Smirnoff  *  |   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
833340d773SGleb Smirnoff  *  R   | Locator Count | EID mask-len  | ACT |A|      Reserved         |
843340d773SGleb Smirnoff  *  e   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
853340d773SGleb Smirnoff  *  c   | Rsvd  |  Map-Version Number   |         EID-Prefix-AFI        |
863340d773SGleb Smirnoff  *  o   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
873340d773SGleb Smirnoff  *  r   |                          EID-Prefix                           |
883340d773SGleb Smirnoff  *  d   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
893340d773SGleb Smirnoff  *  |  /|    Priority   |    Weight     |  M Priority   |   M Weight    |
903340d773SGleb Smirnoff  *  | L +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
913340d773SGleb Smirnoff  *  | o |        Unused Flags     |L|p|R|           Loc-AFI             |
923340d773SGleb Smirnoff  *  | c +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
933340d773SGleb Smirnoff  *  |  \|                             Locator                           |
943340d773SGleb Smirnoff  *  +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
953340d773SGleb Smirnoff  */
963340d773SGleb Smirnoff 
97ee67461eSJoseph Mingrone #include <config.h>
983340d773SGleb Smirnoff 
99ee67461eSJoseph Mingrone #include "netdissect-stdinc.h"
100ee67461eSJoseph Mingrone #include "netdissect.h"
1013340d773SGleb Smirnoff 
1023340d773SGleb Smirnoff #include "ip.h"
1033340d773SGleb Smirnoff #include "ip6.h"
1043340d773SGleb Smirnoff 
1053340d773SGleb Smirnoff #include "extract.h"
1063340d773SGleb Smirnoff #include "addrtoname.h"
1073340d773SGleb Smirnoff 
1083340d773SGleb Smirnoff 
1093340d773SGleb Smirnoff #define IPv4_AFI			1
1103340d773SGleb Smirnoff #define IPv6_AFI			2
1113340d773SGleb Smirnoff #define TYPE_INDEX			4
1123340d773SGleb Smirnoff #define LISP_MAP_NOTIFY_IBIT_MASK	8
1133340d773SGleb Smirnoff #define LISP_MAP_REGISTER_IBIT_MASK	2
1143340d773SGleb Smirnoff 
1153340d773SGleb Smirnoff enum {
1163340d773SGleb Smirnoff 	LISP_MAP_REQUEST = 1,
1173340d773SGleb Smirnoff 	LISP_MAP_REPLY,
1183340d773SGleb Smirnoff 	LISP_MAP_REGISTER,
1193340d773SGleb Smirnoff 	LISP_MAP_NOTIFY,
1203340d773SGleb Smirnoff 	LISP_ENCAPSULATED_CONTROL_MESSAGE = 8
1213340d773SGleb Smirnoff };
1223340d773SGleb Smirnoff 
1233340d773SGleb Smirnoff enum {
1243340d773SGleb Smirnoff 	LISP_AUTH_NONE,
1253340d773SGleb Smirnoff 	LISP_AUTH_SHA1,
1263340d773SGleb Smirnoff 	LISP_AUTH_SHA256
1273340d773SGleb Smirnoff };
1283340d773SGleb Smirnoff 
1293340d773SGleb Smirnoff static const struct tok lisp_type [] = {
1303340d773SGleb Smirnoff 	{ 0, "LISP-Reserved"			 },
1313340d773SGleb Smirnoff 	{ 1, "LISP-Map-Request"			 },
1323340d773SGleb Smirnoff 	{ 2, "LISP-Map-Reply"			 },
1333340d773SGleb Smirnoff 	{ 3, "LISP-Map-Register"		 },
1343340d773SGleb Smirnoff 	{ 4, "LISP-Map-Notify"			 },
135*0a7e5f1fSJoseph Mingrone 	{ 8, "LISP-Encapsulated-Control-Message" },
1363340d773SGleb Smirnoff 	{ 0, NULL }
1373340d773SGleb Smirnoff };
1383340d773SGleb Smirnoff 
1393340d773SGleb Smirnoff /*
1403340d773SGleb Smirnoff  * P-Bit : Request for Proxy Map-Reply from the MS/MR
1413340d773SGleb Smirnoff  * S-Bit : Security Enhancement. ETR is LISP-SEC enabled. draft-ietf-lisp-sec
1423340d773SGleb Smirnoff  * I-Bit : 128 bit xTR-ID and 64 bit Site-ID present.
1433340d773SGleb Smirnoff  *	   xTR-ID and Site-ID help in differentiation of xTRs in multi xTR
1443340d773SGleb Smirnoff  *	   and multi Site deployment scenarios.
1453340d773SGleb Smirnoff  * R-Bit : Built for a Reencapsulating-Tunnel-Router. Used in Traffic
1463340d773SGleb Smirnoff  *	   Engineering and Service Chaining
1473340d773SGleb Smirnoff  */
1483340d773SGleb Smirnoff static const struct tok map_register_hdr_flag[] = {
1493340d773SGleb Smirnoff 	{ 0x08000000, "P-Proxy-Map-Reply"  },
1503340d773SGleb Smirnoff 	{ 0x04000000, "S-LISP-SEC-Capable" },
1513340d773SGleb Smirnoff 	{ 0x02000000, "I-xTR-ID-Present"   },
1523340d773SGleb Smirnoff 	{ 0x01000000, "R-Build-For-RTR"    },
1533340d773SGleb Smirnoff 	{ 0x00000100, "M-Want-Map-Notify"  },
1543340d773SGleb Smirnoff 	{ 0, NULL }
1553340d773SGleb Smirnoff };
1563340d773SGleb Smirnoff 
1573340d773SGleb Smirnoff static const struct tok map_notify_hdr_flag[] = {
1583340d773SGleb Smirnoff 	{ 0x08000000, "I-xTR-ID-Present"   },
1593340d773SGleb Smirnoff 	{ 0x04000000, "R-Build-For-RTR"    },
1603340d773SGleb Smirnoff 	{ 0, NULL }
1613340d773SGleb Smirnoff };
1623340d773SGleb Smirnoff 
1633340d773SGleb Smirnoff static const struct tok auth_type[] = {
1643340d773SGleb Smirnoff 	{ LISP_AUTH_NONE,   "None"   },
1653340d773SGleb Smirnoff 	{ LISP_AUTH_SHA1,   "SHA1"   },
1663340d773SGleb Smirnoff 	{ LISP_AUTH_SHA256, "SHA256" },
1673340d773SGleb Smirnoff 	{ 0, NULL}
1683340d773SGleb Smirnoff };
1693340d773SGleb Smirnoff 
1703340d773SGleb Smirnoff static const struct tok lisp_eid_action[] = {
1713340d773SGleb Smirnoff 	{ 0, "No-Action"	},
1723340d773SGleb Smirnoff 	{ 1, "Natively-Forward" },
1733340d773SGleb Smirnoff 	{ 2, "Send-Map-Request" },
1743340d773SGleb Smirnoff 	{ 3, "Drop"		},
1753340d773SGleb Smirnoff 	{ 0, NULL}
1763340d773SGleb Smirnoff };
1773340d773SGleb Smirnoff 
1783340d773SGleb Smirnoff static const struct tok lisp_loc_flag[] = {
1793340d773SGleb Smirnoff 	{ 0x0004, "Local-Locator" },
1803340d773SGleb Smirnoff 	{ 0x0002, "RLoc-Probed"	  },
1813340d773SGleb Smirnoff 	{ 0x0001, "Reachable"	  },
1823340d773SGleb Smirnoff 	{ 0, NULL }
1833340d773SGleb Smirnoff };
1843340d773SGleb Smirnoff 
1853340d773SGleb Smirnoff typedef struct map_register_hdr {
1863340d773SGleb Smirnoff 	nd_uint8_t type_and_flag;
1873340d773SGleb Smirnoff 	nd_uint8_t reserved;
1883340d773SGleb Smirnoff 	nd_uint8_t reserved_and_flag2;
1893340d773SGleb Smirnoff 	nd_uint8_t record_count;
1903340d773SGleb Smirnoff 	nd_uint64_t nonce;
1913340d773SGleb Smirnoff 	nd_uint16_t key_id;
1923340d773SGleb Smirnoff 	nd_uint16_t auth_data_len;
1933340d773SGleb Smirnoff } lisp_map_register_hdr;
1943340d773SGleb Smirnoff 
1953340d773SGleb Smirnoff #define MAP_REGISTER_HDR_LEN sizeof(lisp_map_register_hdr)
1963340d773SGleb Smirnoff 
1973340d773SGleb Smirnoff typedef struct map_register_eid {
1983340d773SGleb Smirnoff 	nd_uint32_t ttl;
1993340d773SGleb Smirnoff 	nd_uint8_t locator_count;
2003340d773SGleb Smirnoff 	nd_uint8_t eid_prefix_mask_length;
2013340d773SGleb Smirnoff 	nd_uint8_t act_auth_inc_res;
2023340d773SGleb Smirnoff 	nd_uint8_t reserved;
203ee67461eSJoseph Mingrone 	nd_uint16_t reserved_and_version;
2043340d773SGleb Smirnoff 	nd_uint16_t eid_prefix_afi;
2053340d773SGleb Smirnoff } lisp_map_register_eid;
2063340d773SGleb Smirnoff 
2073340d773SGleb Smirnoff #define MAP_REGISTER_EID_LEN sizeof(lisp_map_register_eid)
2083340d773SGleb Smirnoff 
2093340d773SGleb Smirnoff typedef struct map_register_loc {
2103340d773SGleb Smirnoff 	nd_uint8_t priority;
2113340d773SGleb Smirnoff 	nd_uint8_t weight;
2123340d773SGleb Smirnoff 	nd_uint8_t m_priority;
2133340d773SGleb Smirnoff 	nd_uint8_t m_weight;
2143340d773SGleb Smirnoff 	nd_uint16_t unused_and_flag;
2153340d773SGleb Smirnoff 	nd_uint16_t locator_afi;
2163340d773SGleb Smirnoff } lisp_map_register_loc;
2173340d773SGleb Smirnoff 
2183340d773SGleb Smirnoff #define MAP_REGISTER_LOC_LEN sizeof(lisp_map_register_loc)
2193340d773SGleb Smirnoff 
220ee67461eSJoseph Mingrone static uint8_t extract_lisp_type(uint8_t);
221ee67461eSJoseph Mingrone static uint8_t is_xtr_data_present(uint8_t, uint8_t);
2223340d773SGleb Smirnoff static void lisp_hdr_flag(netdissect_options *, const lisp_map_register_hdr *);
2233340d773SGleb Smirnoff static void action_flag(netdissect_options *, uint8_t);
2243340d773SGleb Smirnoff static void loc_hdr_flag(netdissect_options *, uint16_t);
2253340d773SGleb Smirnoff 
226ee67461eSJoseph Mingrone void
227ee67461eSJoseph Mingrone lisp_print(netdissect_options *ndo, const u_char *bp, u_int length)
2283340d773SGleb Smirnoff {
229ee67461eSJoseph Mingrone 	uint8_t type_and_flag;
2303340d773SGleb Smirnoff 	uint8_t type;
2313340d773SGleb Smirnoff 	uint8_t mask_len;
2323340d773SGleb Smirnoff 	uint8_t loc_count;
2333340d773SGleb Smirnoff 	uint8_t xtr_present;
2343340d773SGleb Smirnoff 	uint8_t record_count;
2353340d773SGleb Smirnoff 	uint16_t key_id;
2363340d773SGleb Smirnoff 	uint16_t eid_afi;
2373340d773SGleb Smirnoff 	uint16_t loc_afi;
2383340d773SGleb Smirnoff 	uint16_t map_version;
2393340d773SGleb Smirnoff 	uint16_t packet_offset;
2403340d773SGleb Smirnoff 	uint16_t auth_data_len;
2413340d773SGleb Smirnoff 	uint32_t ttl;
2423340d773SGleb Smirnoff 	const u_char *packet_iterator;
2433340d773SGleb Smirnoff 	const u_char *loc_ip_pointer;
2443340d773SGleb Smirnoff 	const lisp_map_register_hdr *lisp_hdr;
2453340d773SGleb Smirnoff 	const lisp_map_register_eid *lisp_eid;
2463340d773SGleb Smirnoff 	const lisp_map_register_loc *lisp_loc;
2473340d773SGleb Smirnoff 
248ee67461eSJoseph Mingrone 	ndo->ndo_protocol = "lisp";
2493340d773SGleb Smirnoff 	/* Check if enough bytes for header are available */
250ee67461eSJoseph Mingrone 	ND_TCHECK_LEN(bp, MAP_REGISTER_HDR_LEN);
2513340d773SGleb Smirnoff 	lisp_hdr = (const lisp_map_register_hdr *) bp;
2523340d773SGleb Smirnoff 	lisp_hdr_flag(ndo, lisp_hdr);
2533340d773SGleb Smirnoff 	/* Supporting only MAP NOTIFY and MAP REGISTER LISP packets */
254ee67461eSJoseph Mingrone 	type_and_flag = GET_U_1(lisp_hdr->type_and_flag);
255ee67461eSJoseph Mingrone 	type = extract_lisp_type(type_and_flag);
2563340d773SGleb Smirnoff 	if ((type != LISP_MAP_REGISTER) && (type != LISP_MAP_NOTIFY))
2573340d773SGleb Smirnoff 		return;
2583340d773SGleb Smirnoff 
2593340d773SGleb Smirnoff 	/* Find if the packet contains xTR and Site-ID data */
260ee67461eSJoseph Mingrone 	xtr_present = is_xtr_data_present(type, type_and_flag);
2613340d773SGleb Smirnoff 
2623340d773SGleb Smirnoff 	/* Extract the number of EID records present */
263ee67461eSJoseph Mingrone 	auth_data_len = GET_BE_U_2(lisp_hdr->auth_data_len);
2643340d773SGleb Smirnoff 	packet_iterator = (const u_char *)(lisp_hdr);
2653340d773SGleb Smirnoff 	packet_offset = MAP_REGISTER_HDR_LEN;
266ee67461eSJoseph Mingrone 	record_count = GET_U_1(lisp_hdr->record_count);
2673340d773SGleb Smirnoff 
2683340d773SGleb Smirnoff 	if (ndo->ndo_vflag) {
269ee67461eSJoseph Mingrone 		key_id = GET_BE_U_2(lisp_hdr->key_id);
270ee67461eSJoseph Mingrone 		ND_PRINT("\n    %u record(s), ", record_count);
271ee67461eSJoseph Mingrone 		ND_PRINT("Authentication %s,",
272ee67461eSJoseph Mingrone 			tok2str(auth_type, "unknown-type", key_id));
2733340d773SGleb Smirnoff 		hex_print(ndo, "\n    Authentication-Data: ", packet_iterator +
2743340d773SGleb Smirnoff 						packet_offset, auth_data_len);
2753340d773SGleb Smirnoff 	} else {
276ee67461eSJoseph Mingrone 		ND_PRINT(" %u record(s),", record_count);
2773340d773SGleb Smirnoff 	}
2783340d773SGleb Smirnoff 	packet_offset += auth_data_len;
2793340d773SGleb Smirnoff 
2803340d773SGleb Smirnoff 	if (record_count == 0)
2813340d773SGleb Smirnoff 		goto invalid;
2823340d773SGleb Smirnoff 
2833340d773SGleb Smirnoff 	/* Print all the EID records */
284ee67461eSJoseph Mingrone 	while ((length > packet_offset) && (record_count != 0)) {
285ee67461eSJoseph Mingrone 		record_count--;
286ee67461eSJoseph Mingrone 		ND_TCHECK_LEN(packet_iterator + packet_offset,
287ee67461eSJoseph Mingrone 			      MAP_REGISTER_EID_LEN);
288ee67461eSJoseph Mingrone 		ND_PRINT("\n");
2893340d773SGleb Smirnoff 		lisp_eid = (const lisp_map_register_eid *)
2903340d773SGleb Smirnoff 				((const u_char *)lisp_hdr + packet_offset);
2913340d773SGleb Smirnoff 		packet_offset += MAP_REGISTER_EID_LEN;
292ee67461eSJoseph Mingrone 		mask_len = GET_U_1(lisp_eid->eid_prefix_mask_length);
293ee67461eSJoseph Mingrone 		eid_afi = GET_BE_U_2(lisp_eid->eid_prefix_afi);
294ee67461eSJoseph Mingrone 		loc_count = GET_U_1(lisp_eid->locator_count);
2953340d773SGleb Smirnoff 
2963340d773SGleb Smirnoff 		if (ndo->ndo_vflag) {
297ee67461eSJoseph Mingrone 			ttl = GET_BE_U_4(lisp_eid->ttl);
298ee67461eSJoseph Mingrone 			ND_PRINT("      Record TTL %u,", ttl);
299ee67461eSJoseph Mingrone 			action_flag(ndo, GET_U_1(lisp_eid->act_auth_inc_res));
300ee67461eSJoseph Mingrone 			map_version = GET_BE_U_2(lisp_eid->reserved_and_version) & 0x0FFF;
301ee67461eSJoseph Mingrone 			ND_PRINT(" Map Version: %u,", map_version);
3023340d773SGleb Smirnoff 		}
3033340d773SGleb Smirnoff 
3043340d773SGleb Smirnoff 		switch (eid_afi) {
3053340d773SGleb Smirnoff 		case IPv4_AFI:
306ee67461eSJoseph Mingrone 			ND_PRINT(" EID %s/%u,",
307ee67461eSJoseph Mingrone 				GET_IPADDR_STRING(packet_iterator + packet_offset),
308ee67461eSJoseph Mingrone 				mask_len);
3093340d773SGleb Smirnoff 			packet_offset += 4;
3103340d773SGleb Smirnoff 			break;
3113340d773SGleb Smirnoff 		case IPv6_AFI:
312ee67461eSJoseph Mingrone 			ND_PRINT(" EID %s/%u,",
313ee67461eSJoseph Mingrone 				GET_IP6ADDR_STRING(packet_iterator + packet_offset),
314ee67461eSJoseph Mingrone 				mask_len);
3153340d773SGleb Smirnoff 			packet_offset += 16;
3163340d773SGleb Smirnoff 			break;
3173340d773SGleb Smirnoff 		default:
3183340d773SGleb Smirnoff 			/*
3193340d773SGleb Smirnoff 			 * No support for LCAF right now.
3203340d773SGleb Smirnoff 			 */
3213340d773SGleb Smirnoff 			return;
3223340d773SGleb Smirnoff 			break;
3233340d773SGleb Smirnoff 		}
3243340d773SGleb Smirnoff 
325ee67461eSJoseph Mingrone 		ND_PRINT(" %u locator(s)", loc_count);
3263340d773SGleb Smirnoff 
327ee67461eSJoseph Mingrone 		while (loc_count != 0) {
328ee67461eSJoseph Mingrone 			loc_count--;
329ee67461eSJoseph Mingrone 			ND_TCHECK_LEN(packet_iterator + packet_offset,
330ee67461eSJoseph Mingrone 				      MAP_REGISTER_LOC_LEN);
3313340d773SGleb Smirnoff 			lisp_loc = (const lisp_map_register_loc *) (packet_iterator + packet_offset);
3323340d773SGleb Smirnoff 			loc_ip_pointer = (const u_char *) (lisp_loc + 1);
3333340d773SGleb Smirnoff 			packet_offset += MAP_REGISTER_LOC_LEN;
334ee67461eSJoseph Mingrone 			loc_afi = GET_BE_U_2(lisp_loc->locator_afi);
3353340d773SGleb Smirnoff 
3363340d773SGleb Smirnoff 			if (ndo->ndo_vflag)
337ee67461eSJoseph Mingrone 				ND_PRINT("\n       ");
3383340d773SGleb Smirnoff 
3393340d773SGleb Smirnoff 			switch (loc_afi) {
3403340d773SGleb Smirnoff 			case IPv4_AFI:
341ee67461eSJoseph Mingrone 				ND_TCHECK_4(packet_iterator + packet_offset);
342ee67461eSJoseph Mingrone 				ND_PRINT(" LOC %s", GET_IPADDR_STRING(loc_ip_pointer));
3433340d773SGleb Smirnoff 				packet_offset += 4;
3443340d773SGleb Smirnoff 				break;
3453340d773SGleb Smirnoff 			case IPv6_AFI:
346ee67461eSJoseph Mingrone 				ND_TCHECK_16(packet_iterator + packet_offset);
347ee67461eSJoseph Mingrone 				ND_PRINT(" LOC %s", GET_IP6ADDR_STRING(loc_ip_pointer));
3483340d773SGleb Smirnoff 				packet_offset += 16;
3493340d773SGleb Smirnoff 				break;
3503340d773SGleb Smirnoff 			default:
3513340d773SGleb Smirnoff 				break;
3523340d773SGleb Smirnoff 			}
3533340d773SGleb Smirnoff 			if (ndo->ndo_vflag) {
354ee67461eSJoseph Mingrone 				ND_PRINT("\n          Priority/Weight %u/%u,"
3553340d773SGleb Smirnoff 						" Multicast Priority/Weight %u/%u,",
356ee67461eSJoseph Mingrone 						GET_U_1(lisp_loc->priority),
357ee67461eSJoseph Mingrone 						GET_U_1(lisp_loc->weight),
358ee67461eSJoseph Mingrone 						GET_U_1(lisp_loc->m_priority),
359ee67461eSJoseph Mingrone 						GET_U_1(lisp_loc->m_weight));
360ee67461eSJoseph Mingrone 				loc_hdr_flag(ndo,
361ee67461eSJoseph Mingrone 					     GET_BE_U_2(lisp_loc->unused_and_flag));
3623340d773SGleb Smirnoff 			}
3633340d773SGleb Smirnoff 		}
3643340d773SGleb Smirnoff 	}
3653340d773SGleb Smirnoff 
3663340d773SGleb Smirnoff 	/*
3673340d773SGleb Smirnoff 	 * Print xTR and Site ID. Handle the fact that the packet could be invalid.
3683340d773SGleb Smirnoff 	 * If the xTR_ID_Present bit is not set, and we still have data to display,
3693340d773SGleb Smirnoff 	 * show it as hex data.
3703340d773SGleb Smirnoff 	 */
3713340d773SGleb Smirnoff 	if (xtr_present) {
372ee67461eSJoseph Mingrone 		if (!ND_TTEST_LEN(packet_iterator + packet_offset, 24))
3733340d773SGleb Smirnoff 			goto invalid;
374ee67461eSJoseph Mingrone 		hex_print(ndo, "\n    xTR-ID: ", packet_iterator + packet_offset, 16);
375ee67461eSJoseph Mingrone 		ND_PRINT("\n    SITE-ID: %" PRIu64,
376ee67461eSJoseph Mingrone 			GET_BE_U_8(packet_iterator + packet_offset + 16));
3773340d773SGleb Smirnoff 	} else {
3783340d773SGleb Smirnoff 		/* Check if packet isn't over yet */
3793340d773SGleb Smirnoff 		if (packet_iterator + packet_offset < ndo->ndo_snapend) {
380ee67461eSJoseph Mingrone 			hex_print(ndo, "\n    Data: ", packet_iterator + packet_offset,
381ee67461eSJoseph Mingrone 				ND_BYTES_AVAILABLE_AFTER(packet_iterator + packet_offset));
3823340d773SGleb Smirnoff 		}
3833340d773SGleb Smirnoff 	}
3843340d773SGleb Smirnoff 	return;
3853340d773SGleb Smirnoff trunc:
386ee67461eSJoseph Mingrone 	nd_print_trunc(ndo);
3873340d773SGleb Smirnoff 	return;
3883340d773SGleb Smirnoff invalid:
389ee67461eSJoseph Mingrone 	nd_print_invalid(ndo);
3903340d773SGleb Smirnoff }
3913340d773SGleb Smirnoff 
392ee67461eSJoseph Mingrone static uint8_t
393ee67461eSJoseph Mingrone extract_lisp_type(uint8_t lisp_hdr_flags)
3943340d773SGleb Smirnoff {
3953340d773SGleb Smirnoff 	return (lisp_hdr_flags) >> TYPE_INDEX;
3963340d773SGleb Smirnoff }
3973340d773SGleb Smirnoff 
398ee67461eSJoseph Mingrone static uint8_t
399ee67461eSJoseph Mingrone is_xtr_data_present(uint8_t type, uint8_t lisp_hdr_flags)
4003340d773SGleb Smirnoff {
4013340d773SGleb Smirnoff 	uint8_t xtr_present = 0;
4023340d773SGleb Smirnoff 
4033340d773SGleb Smirnoff 	if (type == LISP_MAP_REGISTER)
4043340d773SGleb Smirnoff 		xtr_present = (lisp_hdr_flags) & LISP_MAP_REGISTER_IBIT_MASK;
4053340d773SGleb Smirnoff 	else if (type == LISP_MAP_NOTIFY)
4063340d773SGleb Smirnoff 		xtr_present = (lisp_hdr_flags) & LISP_MAP_NOTIFY_IBIT_MASK;
4073340d773SGleb Smirnoff 
4083340d773SGleb Smirnoff 	return xtr_present;
4093340d773SGleb Smirnoff }
4103340d773SGleb Smirnoff 
4113340d773SGleb Smirnoff static void lisp_hdr_flag(netdissect_options *ndo, const lisp_map_register_hdr *lisp_hdr)
4123340d773SGleb Smirnoff {
413ee67461eSJoseph Mingrone 	uint8_t type = extract_lisp_type(GET_U_1(lisp_hdr->type_and_flag));
4143340d773SGleb Smirnoff 
4153340d773SGleb Smirnoff 	if (!ndo->ndo_vflag) {
416ee67461eSJoseph Mingrone 		ND_PRINT("%s,", tok2str(lisp_type, "unknown-type-%u", type));
4173340d773SGleb Smirnoff 		return;
4183340d773SGleb Smirnoff 	} else {
419ee67461eSJoseph Mingrone 		ND_PRINT("%s,", tok2str(lisp_type, "unknown-type-%u", type));
4203340d773SGleb Smirnoff 	}
4213340d773SGleb Smirnoff 
4223340d773SGleb Smirnoff 	if (type == LISP_MAP_REGISTER) {
423ee67461eSJoseph Mingrone 		ND_PRINT(" flags [%s],", bittok2str(map_register_hdr_flag,
424ee67461eSJoseph Mingrone 			 "none", GET_BE_U_4(lisp_hdr)));
4253340d773SGleb Smirnoff 	} else if (type == LISP_MAP_NOTIFY) {
426ee67461eSJoseph Mingrone 		ND_PRINT(" flags [%s],", bittok2str(map_notify_hdr_flag,
427ee67461eSJoseph Mingrone 			 "none", GET_BE_U_4(lisp_hdr)));
4283340d773SGleb Smirnoff 	}
4293340d773SGleb Smirnoff }
4303340d773SGleb Smirnoff 
4313340d773SGleb Smirnoff static void action_flag(netdissect_options *ndo, uint8_t act_auth_inc_res)
4323340d773SGleb Smirnoff {
4333340d773SGleb Smirnoff 	uint8_t action;
4343340d773SGleb Smirnoff 	uint8_t authoritative;
4353340d773SGleb Smirnoff 
4363340d773SGleb Smirnoff 	authoritative  = ((act_auth_inc_res >> 4) & 1);
4373340d773SGleb Smirnoff 
4383340d773SGleb Smirnoff 	if (authoritative)
439ee67461eSJoseph Mingrone 		ND_PRINT(" Authoritative,");
4403340d773SGleb Smirnoff 	else
441ee67461eSJoseph Mingrone 		ND_PRINT(" Non-Authoritative,");
4423340d773SGleb Smirnoff 
4433340d773SGleb Smirnoff 	action = act_auth_inc_res >> 5;
444ee67461eSJoseph Mingrone 	ND_PRINT(" %s,", tok2str(lisp_eid_action, "unknown", action));
4453340d773SGleb Smirnoff }
4463340d773SGleb Smirnoff 
4473340d773SGleb Smirnoff static void loc_hdr_flag(netdissect_options *ndo, uint16_t flag)
4483340d773SGleb Smirnoff {
449ee67461eSJoseph Mingrone 	ND_PRINT(" flags [%s],", bittok2str(lisp_loc_flag, "none", flag));
4503340d773SGleb Smirnoff }
4513340d773SGleb Smirnoff 
452