1e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes/*
2e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * Copyright (c) 2015 Ritesh Ranjan (r.ranjan789@gmail.com)
3e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * All rights reserved.
4e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *
5e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * Redistribution and use in source and binary forms, with or without
6e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * modification, are permitted provided that the following conditions
7e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * are met:
8e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * 1. Redistributions of source code must retain the above copyright
9e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *    notice, this list of conditions and the following disclaimer.
10e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * 2. Redistributions in binary form must reproduce the above copyright
11e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *    notice, this list of conditions and the following disclaimer in the
12e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *    documentation and/or other materials provided with the distribution.
13e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * 3. The name of the author may not be used to endorse or promote products
14e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *    derived from this software without specific prior written permission.
15e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *
16e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * POSSIBILITY OF SUCH DAMAGE.
27e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes */
28e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
29e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes/* \summary: - Locator/Identifier Separation Protocol (LISP) printer */
30e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
31e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes/*
32e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * specification: RFC 6830
33e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *
34e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *
35e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * The Map-Register message format is:
36e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *
37e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *       0                   1                   2                   3
38e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *       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
39e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *      |Type=3 |P|S|I|R|      Reserved               |M| Record Count  |
41e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *      |                         Nonce . . .                           |
43e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *      |                         . . . Nonce                           |
45e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *      |            Key ID             |  Authentication Data Length   |
47e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
48e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *      ~                     Authentication Data                       ~
49e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *  +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
50e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *  |   |                          Record TTL                           |
51e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *  |   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
52e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *  R   | Locator Count | EID mask-len  | ACT |A|      Reserved         |
53e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *  e   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
54e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *  c   | Rsvd  |  Map-Version Number   |        EID-Prefix-AFI         |
55e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *  o   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
56e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *  r   |                          EID-Prefix                           |
57e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *  d   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
58e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *  |  /|    Priority   |    Weight     |  M Priority   |   M Weight    |
59e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *  | L +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
60e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *  | o |        Unused Flags     |L|p|R|           Loc-AFI             |
61e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *  | c +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
62e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *  |  \|                             Locator                           |
63e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *  +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
64e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *
65e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *
66e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * The Map-Notify message format is:
67e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *
68e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *       0                   1                   2                   3
69e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *       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
70e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
71e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *      |Type=4 |I|R|          Reserved                 | Record Count  |
72e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
73e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *      |                         Nonce . . .                           |
74e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
75e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *      |                         . . . Nonce                           |
76e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
77e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *      |            Key ID             |  Authentication Data Length   |
78e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
79e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *      ~                     Authentication Data                       ~
80e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *  +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
81e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *  |   |                          Record TTL                           |
82e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *  |   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
83e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *  R   | Locator Count | EID mask-len  | ACT |A|      Reserved         |
84e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *  e   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
85e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *  c   | Rsvd  |  Map-Version Number   |         EID-Prefix-AFI        |
86e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *  o   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
87e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *  r   |                          EID-Prefix                           |
88e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *  d   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
89e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *  |  /|    Priority   |    Weight     |  M Priority   |   M Weight    |
90e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *  | L +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
91e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *  | o |        Unused Flags     |L|p|R|           Loc-AFI             |
92e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *  | c +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
93e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *  |  \|                             Locator                           |
94e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *  +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
95e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes */
96e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
97e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef HAVE_CONFIG_H
98e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#include "config.h"
99e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
100e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
101e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#include <netdissect-stdinc.h>
102e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#include <netdissect.h>
103e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#include <string.h>
104e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#include <stdlib.h>
105e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
106e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#include "ip.h"
107e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#include "ip6.h"
108e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
109e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#include "extract.h"
110e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#include "addrtoname.h"
111e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
112e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesstatic const char tstr[] = " [|LISP]";
113e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
114e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#define IPv4_AFI			1
115e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#define IPv6_AFI			2
116e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#define TYPE_INDEX			4
117e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#define LISP_MAP_NOTIFY_IBIT_MASK	8
118e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#define LISP_MAP_REGISTER_IBIT_MASK	2
119e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
120e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesenum {
121e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	LISP_MAP_REQUEST = 1,
122e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	LISP_MAP_REPLY,
123e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	LISP_MAP_REGISTER,
124e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	LISP_MAP_NOTIFY,
125e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	LISP_ENCAPSULATED_CONTROL_MESSAGE = 8
126e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes};
127e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
128e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesenum {
129e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	LISP_AUTH_NONE,
130e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	LISP_AUTH_SHA1,
131e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	LISP_AUTH_SHA256
132e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes};
133e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
134e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesstatic const struct tok lisp_type [] = {
135e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ 0, "LISP-Reserved"			},
136e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ 1, "LISP-Map-Request"			},
137e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ 2, "LISP-Map-Reply"			},
138e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ 3, "LISP-Map-Register"		},
139e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ 4, "LISP-Map-Notify"			},
140e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ 8, "LISP-Encapsulated-Contol-Message" },
141e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ 0, NULL }
142e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes};
143e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
144e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes/*
145e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * P-Bit : Request for Proxy Map-Reply from the MS/MR
146e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * S-Bit : Security Enhancement. ETR is LISP-SEC enabled. draft-ietf-lisp-sec
147e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * I-Bit : 128 bit xTR-ID and 64 bit Site-ID present.
148e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *	   xTR-ID and Site-ID help in differentiation of xTRs in multi xTR
149e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *	   and multi Site deployment scenarios.
150e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * R-Bit : Built for a Reencapsulating-Tunnel-Router. Used in Traffic
151e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *	   Engineering and Service Chaining
152e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes */
153e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesstatic const struct tok map_register_hdr_flag[] = {
154e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ 0x08000000, "P-Proxy-Map-Reply"  },
155e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ 0x04000000, "S-LISP-SEC-Capable" },
156e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ 0x02000000, "I-xTR-ID-Present"   },
157e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ 0x01000000, "R-Build-For-RTR"    },
158e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ 0x00000100, "M-Want-Map-Notify"  },
159e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ 0, NULL }
160e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes};
161e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
162e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesstatic const struct tok map_notify_hdr_flag[] = {
163e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ 0x08000000, "I-xTR-ID-Present"   },
164e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ 0x04000000, "R-Build-For-RTR"    },
165e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ 0, NULL }
166e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes};
167e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
168e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesstatic const struct tok auth_type[] = {
169e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ LISP_AUTH_NONE,   "None"   },
170e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ LISP_AUTH_SHA1,   "SHA1"   },
171e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ LISP_AUTH_SHA256, "SHA256" },
172e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ 0, NULL}
173e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes};
174e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
175e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesstatic const struct tok lisp_eid_action[] = {
176e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ 0, "No-Action"	},
177e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ 1, "Natively-Forward" },
178e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ 2, "Send-Map-Request" },
179e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ 3, "Drop"		},
180e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ 0, NULL}
181e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes};
182e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
183e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesstatic const struct tok lisp_loc_flag[] = {
184e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ 0x0004, "Local-Locator" },
185e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ 0x0002, "RLoc-Probed"	  },
186e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ 0x0001, "Reachable"	  },
187e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ 0, NULL }
188e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes};
189e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
190e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughestypedef struct map_register_hdr {
191e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	nd_uint8_t type_and_flag;
192e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	nd_uint8_t reserved;
193e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	nd_uint8_t reserved_and_flag2;
194e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	nd_uint8_t record_count;
195e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	nd_uint64_t nonce;
196e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	nd_uint16_t key_id;
197e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	nd_uint16_t auth_data_len;
198e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes} lisp_map_register_hdr;
199e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
200e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#define MAP_REGISTER_HDR_LEN sizeof(lisp_map_register_hdr)
201e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
202e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughestypedef struct map_register_eid {
203e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	nd_uint32_t ttl;
204e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	nd_uint8_t locator_count;
205e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	nd_uint8_t eid_prefix_mask_length;
206e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	nd_uint8_t act_auth_inc_res;
207e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	nd_uint8_t reserved;
208e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	nd_uint8_t reserved_version_hi;
209e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	nd_uint8_t version_low;
210e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	nd_uint16_t eid_prefix_afi;
211e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes} lisp_map_register_eid;
212e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
213e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#define MAP_REGISTER_EID_LEN sizeof(lisp_map_register_eid)
214e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
215e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughestypedef struct map_register_loc {
216e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	nd_uint8_t priority;
217e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	nd_uint8_t weight;
218e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	nd_uint8_t m_priority;
219e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	nd_uint8_t m_weight;
220e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	nd_uint16_t unused_and_flag;
221e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	nd_uint16_t locator_afi;
222e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes} lisp_map_register_loc;
223e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
224e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#define MAP_REGISTER_LOC_LEN sizeof(lisp_map_register_loc)
225e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
226e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesstatic inline uint8_t extract_lisp_type(uint8_t);
227e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesstatic inline uint8_t is_xtr_data_present(uint8_t , uint8_t);
228e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesstatic void lisp_hdr_flag(netdissect_options *, const lisp_map_register_hdr *);
229e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesstatic void action_flag(netdissect_options *, uint8_t);
230e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesstatic void loc_hdr_flag(netdissect_options *, uint16_t);
231e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
232e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesvoid lisp_print(netdissect_options *ndo, const u_char *bp, u_int length)
233e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes{
234e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	uint8_t type;
235e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	uint8_t mask_len;
236e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	uint8_t loc_count;
237e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	uint8_t xtr_present;
238e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	uint8_t record_count;
239e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	uint16_t key_id;
240e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	uint16_t eid_afi;
241e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	uint16_t loc_afi;
242e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	uint16_t map_version;
243e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	uint16_t packet_offset;
244e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	uint16_t auth_data_len;
245e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	uint32_t ttl;
246e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	const u_char *packet_iterator;
247e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	const u_char *loc_ip_pointer;
248e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	const lisp_map_register_hdr *lisp_hdr;
249e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	const lisp_map_register_eid *lisp_eid;
250e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	const lisp_map_register_loc *lisp_loc;
251e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
252e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	/* Check if enough bytes for header are available */
253e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	ND_TCHECK2(*bp, MAP_REGISTER_HDR_LEN);
254e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	lisp_hdr = (const lisp_map_register_hdr *) bp;
255e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	lisp_hdr_flag(ndo, lisp_hdr);
256e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	/* Supporting only MAP NOTIFY and MAP REGISTER LISP packets */
257e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	type = extract_lisp_type(lisp_hdr->type_and_flag);
258e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	if ((type != LISP_MAP_REGISTER) && (type != LISP_MAP_NOTIFY))
259e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		return;
260e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
261e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	/* Find if the packet contains xTR and Site-ID data */
262e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	xtr_present = is_xtr_data_present(type, lisp_hdr->type_and_flag);
263e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
264e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	/* Extract the number of EID records present */
265e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	auth_data_len = EXTRACT_16BITS(&lisp_hdr->auth_data_len);
266e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	packet_iterator = (const u_char *)(lisp_hdr);
267e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	packet_offset = MAP_REGISTER_HDR_LEN;
268e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	record_count = lisp_hdr->record_count;
269e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
270e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	if (ndo->ndo_vflag) {
271e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		key_id = EXTRACT_16BITS(&lisp_hdr->key_id);
272e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		ND_PRINT((ndo, "\n    %u record(s), ", record_count));
273e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		ND_PRINT((ndo, "Authentication %s,",
274e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			tok2str(auth_type, "unknown-type", key_id)));
275e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		hex_print(ndo, "\n    Authentication-Data: ", packet_iterator +
276e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes						packet_offset, auth_data_len);
277e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	} else {
278e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		ND_PRINT((ndo, " %u record(s),", record_count));
279e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	}
280e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	packet_offset += auth_data_len;
281e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
282e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	if (record_count == 0)
283e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		goto invalid;
284e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
285e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	/* Print all the EID records */
286e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	while ((length > packet_offset) && (record_count--)) {
287e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
288e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		ND_TCHECK2(*(packet_iterator + packet_offset), MAP_REGISTER_EID_LEN);
289e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		ND_PRINT((ndo, "\n"));
290e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		lisp_eid = (const lisp_map_register_eid *)
291e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes				((const u_char *)lisp_hdr + packet_offset);
292e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		packet_offset += MAP_REGISTER_EID_LEN;
293e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		mask_len = lisp_eid->eid_prefix_mask_length;
294e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		eid_afi = EXTRACT_16BITS(&lisp_eid->eid_prefix_afi);
295e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		loc_count = lisp_eid->locator_count;
296e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
297e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		if (ndo->ndo_vflag) {
298e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			ttl = EXTRACT_32BITS(&lisp_eid->ttl);
299e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			ND_PRINT((ndo, "      Record TTL %u,", ttl));
300e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			action_flag(ndo, lisp_eid->act_auth_inc_res);
301e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			map_version = (((lisp_eid->reserved_version_hi) & 15 ) * 255) +
302e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes					lisp_eid->version_low;
303e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			ND_PRINT((ndo, " Map Version: %u,", map_version));
304e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		}
305e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
306e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		switch (eid_afi) {
307e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		case IPv4_AFI:
308e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			ND_TCHECK2(*(packet_iterator + packet_offset), 4);
309e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			ND_PRINT((ndo, " EID %s/%u,", ipaddr_string(ndo,
310e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes				packet_iterator + packet_offset), mask_len));
311e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			packet_offset += 4;
312e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			break;
313e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		case IPv6_AFI:
314e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			ND_TCHECK2(*(packet_iterator + packet_offset), 16);
315e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			ND_PRINT((ndo, " EID %s/%u,", ip6addr_string(ndo,
316e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes				packet_iterator + packet_offset), mask_len));
317e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			packet_offset += 16;
318e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			break;
319e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		default:
320e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			/*
321e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			 * No support for LCAF right now.
322e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			 */
323e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			return;
324e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			break;
325e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		}
326e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
327e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		ND_PRINT((ndo, " %u locator(s)", loc_count));
328e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
329e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		while (loc_count--) {
330e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			ND_TCHECK2(*(packet_iterator + packet_offset), MAP_REGISTER_LOC_LEN);
331e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			lisp_loc = (const lisp_map_register_loc *) (packet_iterator + packet_offset);
332e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			loc_ip_pointer = (const u_char *) (lisp_loc + 1);
333e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			packet_offset += MAP_REGISTER_LOC_LEN;
334e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			loc_afi = EXTRACT_16BITS(&lisp_loc->locator_afi);
335e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
336e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			if (ndo->ndo_vflag)
337e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes				ND_PRINT((ndo, "\n       "));
338e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
339e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			switch (loc_afi) {
340e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			case IPv4_AFI:
341e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes				ND_TCHECK2(*(packet_iterator + packet_offset), 4);
342e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes				ND_PRINT((ndo, " LOC %s", ipaddr_string(ndo, loc_ip_pointer)));
343e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes				packet_offset += 4;
344e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes				break;
345e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			case IPv6_AFI:
346e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes				ND_TCHECK2(*(packet_iterator + packet_offset), 16);
347e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes				ND_PRINT((ndo, " LOC %s", ip6addr_string(ndo, loc_ip_pointer)));
348e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes				packet_offset += 16;
349e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes				break;
350e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			default:
351e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes				break;
352e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			}
353e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			if (ndo->ndo_vflag) {
354e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes				ND_PRINT((ndo, "\n          Priority/Weight %u/%u,"
355e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes						" Multicast Priority/Weight %u/%u,",
356e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes						lisp_loc->priority, lisp_loc->weight,
357e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes						lisp_loc->m_priority, lisp_loc->m_weight));
358e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes				loc_hdr_flag(ndo, EXTRACT_16BITS(&lisp_loc->unused_and_flag));
359e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			}
360e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		}
361e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	}
362e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
363e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	/*
364e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	 * Print xTR and Site ID. Handle the fact that the packet could be invalid.
365e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	 * If the xTR_ID_Present bit is not set, and we still have data to display,
366e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	 * show it as hex data.
367e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	 */
368e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	if (xtr_present) {
369e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		if (!ND_TTEST2(*(packet_iterator + packet_offset), 24))
370e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			goto invalid;
371e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		hex_print_with_offset(ndo, "\n    xTR-ID: ", packet_iterator + packet_offset, 16, 0);
372e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		ND_PRINT((ndo, "\n    SITE-ID: %" PRIu64,
373e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			EXTRACT_64BITS(packet_iterator + packet_offset + 16)));
374e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	} else {
375e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		/* Check if packet isn't over yet */
376e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		if (packet_iterator + packet_offset < ndo->ndo_snapend) {
377e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			hex_print_with_offset(ndo, "\n    Data: ", packet_iterator + packet_offset,
378e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes				(ndo->ndo_snapend - (packet_iterator + packet_offset)), 0);
379e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		}
380e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	}
381e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	return;
382e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughestrunc:
383e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	ND_PRINT((ndo, "\n   %s", tstr));
384e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	return;
385e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesinvalid:
386e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	ND_PRINT((ndo, "\n   %s", istr));
387e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	return;
388e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes}
389e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
390e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesstatic inline uint8_t extract_lisp_type(uint8_t lisp_hdr_flags)
391e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes{
392e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	return (lisp_hdr_flags) >> TYPE_INDEX;
393e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes}
394e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
395e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesstatic inline uint8_t is_xtr_data_present(uint8_t type, uint8_t lisp_hdr_flags)
396e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes{
397e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	uint8_t xtr_present = 0;
398e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
399e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	if (type == LISP_MAP_REGISTER)
400e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		xtr_present = (lisp_hdr_flags) & LISP_MAP_REGISTER_IBIT_MASK;
401e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	else if (type == LISP_MAP_NOTIFY)
402e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		xtr_present = (lisp_hdr_flags) & LISP_MAP_NOTIFY_IBIT_MASK;
403e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
404e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	return xtr_present;
405e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes}
406e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
407e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesstatic void lisp_hdr_flag(netdissect_options *ndo, const lisp_map_register_hdr *lisp_hdr)
408e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes{
409e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	uint8_t type = extract_lisp_type(lisp_hdr->type_and_flag);
410e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
411e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	if (!ndo->ndo_vflag) {
412e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		ND_PRINT((ndo, "%s,", tok2str(lisp_type, "unknown-type-%u", type)));
413e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		return;
414e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	} else {
415e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		ND_PRINT((ndo, "%s,", tok2str(lisp_type, "unknown-type-%u", type)));
416e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	}
417e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
418e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	if (type == LISP_MAP_REGISTER) {
419e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		ND_PRINT((ndo, " flags [%s],", bittok2str(map_register_hdr_flag,
420e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			 "none", EXTRACT_32BITS(lisp_hdr))));
421e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	} else if (type == LISP_MAP_NOTIFY) {
422e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		ND_PRINT((ndo, " flags [%s],", bittok2str(map_notify_hdr_flag,
423e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			 "none", EXTRACT_32BITS(lisp_hdr))));
424e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	}
425e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
426e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	return;
427e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes}
428e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
429e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesstatic void action_flag(netdissect_options *ndo, uint8_t act_auth_inc_res)
430e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes{
431e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	uint8_t action;
432e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	uint8_t authoritative;
433e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
434e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	authoritative  = ((act_auth_inc_res >> 4) & 1);
435e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
436e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	if (authoritative)
437e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		ND_PRINT((ndo, " Authoritative,"));
438e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	else
439e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		ND_PRINT((ndo, " Non-Authoritative,"));
440e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
441e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	action = act_auth_inc_res >> 5;
442e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	ND_PRINT((ndo, " %s,", tok2str(lisp_eid_action, "unknown", action)));
443e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes}
444e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
445e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesstatic void loc_hdr_flag(netdissect_options *ndo, uint16_t flag)
446e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes{
447e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	ND_PRINT((ndo, " flags [%s],", bittok2str(lisp_loc_flag, "none", flag)));
448e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes}
449e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
450