xref: /freebsd/contrib/tcpdump/print-bootp.c (revision 0a7e5f1f02aad2ff5fff1c60f44c6975fd07e1d9)
14edb46e9SPaul Traina /*
2699fc314SBill Fenner  * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
34edb46e9SPaul Traina  *	The Regents of the University of California.  All rights reserved.
44edb46e9SPaul Traina  *
54edb46e9SPaul Traina  * Redistribution and use in source and binary forms, with or without
64edb46e9SPaul Traina  * modification, are permitted provided that: (1) source code distributions
74edb46e9SPaul Traina  * retain the above copyright notice and this paragraph in its entirety, (2)
84edb46e9SPaul Traina  * distributions including binary code include the above copyright notice and
94edb46e9SPaul Traina  * this paragraph in its entirety in the documentation or other materials
104edb46e9SPaul Traina  * provided with the distribution, and (3) all advertising materials mentioning
114edb46e9SPaul Traina  * features or use of this software display the following acknowledgement:
124edb46e9SPaul Traina  * ``This product includes software developed by the University of California,
134edb46e9SPaul Traina  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
144edb46e9SPaul Traina  * the University nor the names of its contributors may be used to endorse
154edb46e9SPaul Traina  * or promote products derived from this software without specific prior
164edb46e9SPaul Traina  * written permission.
174edb46e9SPaul Traina  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
184edb46e9SPaul Traina  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
194edb46e9SPaul Traina  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
204edb46e9SPaul Traina  */
21a88113a8SBill Fenner 
223340d773SGleb Smirnoff /* \summary: BOOTP and IPv4 DHCP printer */
233340d773SGleb Smirnoff 
24ee67461eSJoseph Mingrone #include <config.h>
254edb46e9SPaul Traina 
26ee67461eSJoseph Mingrone #include "netdissect-stdinc.h"
274edb46e9SPaul Traina 
284edb46e9SPaul Traina #include <string.h>
294edb46e9SPaul Traina 
303340d773SGleb Smirnoff #include "netdissect.h"
314edb46e9SPaul Traina #include "addrtoname.h"
32943ee2b1SBill Fenner #include "extract.h"
334edb46e9SPaul Traina 
344edb46e9SPaul Traina 
358bdc5a62SPatrick Kelsey /*
368bdc5a62SPatrick Kelsey  * Bootstrap Protocol (BOOTP).  RFC951 and RFC1048.
378bdc5a62SPatrick Kelsey  *
388bdc5a62SPatrick Kelsey  * This file specifies the "implementation-independent" BOOTP protocol
398bdc5a62SPatrick Kelsey  * information which is common to both client and server.
408bdc5a62SPatrick Kelsey  *
418bdc5a62SPatrick Kelsey  * Copyright 1988 by Carnegie Mellon.
428bdc5a62SPatrick Kelsey  *
438bdc5a62SPatrick Kelsey  * Permission to use, copy, modify, and distribute this program for any
448bdc5a62SPatrick Kelsey  * purpose and without fee is hereby granted, provided that this copyright
458bdc5a62SPatrick Kelsey  * and permission notice appear on all copies and supporting documentation,
468bdc5a62SPatrick Kelsey  * the name of Carnegie Mellon not be used in advertising or publicity
478bdc5a62SPatrick Kelsey  * pertaining to distribution of the program without specific prior
488bdc5a62SPatrick Kelsey  * permission, and notice be given in supporting documentation that copying
498bdc5a62SPatrick Kelsey  * and distribution is by permission of Carnegie Mellon and Stanford
508bdc5a62SPatrick Kelsey  * University.  Carnegie Mellon makes no representations about the
518bdc5a62SPatrick Kelsey  * suitability of this software for any purpose.  It is provided "as is"
528bdc5a62SPatrick Kelsey  * without express or implied warranty.
538bdc5a62SPatrick Kelsey  */
548bdc5a62SPatrick Kelsey 
558bdc5a62SPatrick Kelsey struct bootp {
56ee67461eSJoseph Mingrone 	nd_uint8_t	bp_op;		/* packet opcode type */
57ee67461eSJoseph Mingrone 	nd_uint8_t	bp_htype;	/* hardware addr type */
58ee67461eSJoseph Mingrone 	nd_uint8_t	bp_hlen;	/* hardware addr length */
59ee67461eSJoseph Mingrone 	nd_uint8_t	bp_hops;	/* gateway hops */
60ee67461eSJoseph Mingrone 	nd_uint32_t	bp_xid;		/* transaction ID */
61ee67461eSJoseph Mingrone 	nd_uint16_t	bp_secs;	/* seconds since boot began */
62ee67461eSJoseph Mingrone 	nd_uint16_t	bp_flags;	/* flags - see bootp_flag_values[]
638bdc5a62SPatrick Kelsey 					   in print-bootp.c */
64ee67461eSJoseph Mingrone 	nd_ipv4		bp_ciaddr;	/* client IP address */
65ee67461eSJoseph Mingrone 	nd_ipv4		bp_yiaddr;	/* 'your' IP address */
66ee67461eSJoseph Mingrone 	nd_ipv4		bp_siaddr;	/* server IP address */
67ee67461eSJoseph Mingrone 	nd_ipv4		bp_giaddr;	/* gateway IP address */
68ee67461eSJoseph Mingrone 	nd_byte		bp_chaddr[16];	/* client hardware address */
69ee67461eSJoseph Mingrone 	nd_byte		bp_sname[64];	/* server host name */
70ee67461eSJoseph Mingrone 	nd_byte		bp_file[128];	/* boot file name */
71ee67461eSJoseph Mingrone 	nd_byte		bp_vend[64];	/* vendor-specific area */
72ee67461eSJoseph Mingrone };
738bdc5a62SPatrick Kelsey 
748bdc5a62SPatrick Kelsey #define BOOTPREPLY	2
758bdc5a62SPatrick Kelsey #define BOOTPREQUEST	1
768bdc5a62SPatrick Kelsey 
778bdc5a62SPatrick Kelsey /*
788bdc5a62SPatrick Kelsey  * Vendor magic cookie (v_magic) for CMU
798bdc5a62SPatrick Kelsey  */
808bdc5a62SPatrick Kelsey #define VM_CMU		"CMU"
818bdc5a62SPatrick Kelsey 
828bdc5a62SPatrick Kelsey /*
838bdc5a62SPatrick Kelsey  * Vendor magic cookie (v_magic) for RFC1048
848bdc5a62SPatrick Kelsey  */
858bdc5a62SPatrick Kelsey #define VM_RFC1048	{ 99, 130, 83, 99 }
868bdc5a62SPatrick Kelsey 
878bdc5a62SPatrick Kelsey /*
888bdc5a62SPatrick Kelsey  * RFC1048 tag values used to specify what information is being supplied in
898bdc5a62SPatrick Kelsey  * the vendor field of the packet.
908bdc5a62SPatrick Kelsey  */
918bdc5a62SPatrick Kelsey 
928bdc5a62SPatrick Kelsey #define TAG_PAD			((uint8_t)   0)
938bdc5a62SPatrick Kelsey #define TAG_SUBNET_MASK		((uint8_t)   1)
948bdc5a62SPatrick Kelsey #define TAG_TIME_OFFSET		((uint8_t)   2)
958bdc5a62SPatrick Kelsey #define TAG_GATEWAY		((uint8_t)   3)
968bdc5a62SPatrick Kelsey #define TAG_TIME_SERVER		((uint8_t)   4)
978bdc5a62SPatrick Kelsey #define TAG_NAME_SERVER		((uint8_t)   5)
988bdc5a62SPatrick Kelsey #define TAG_DOMAIN_SERVER	((uint8_t)   6)
998bdc5a62SPatrick Kelsey #define TAG_LOG_SERVER		((uint8_t)   7)
1008bdc5a62SPatrick Kelsey #define TAG_COOKIE_SERVER	((uint8_t)   8)
1018bdc5a62SPatrick Kelsey #define TAG_LPR_SERVER		((uint8_t)   9)
1028bdc5a62SPatrick Kelsey #define TAG_IMPRESS_SERVER	((uint8_t)  10)
1038bdc5a62SPatrick Kelsey #define TAG_RLP_SERVER		((uint8_t)  11)
1048bdc5a62SPatrick Kelsey #define TAG_HOSTNAME		((uint8_t)  12)
1058bdc5a62SPatrick Kelsey #define TAG_BOOTSIZE		((uint8_t)  13)
1068bdc5a62SPatrick Kelsey #define TAG_END			((uint8_t) 255)
1078bdc5a62SPatrick Kelsey /* RFC1497 tags */
1088bdc5a62SPatrick Kelsey #define	TAG_DUMPPATH		((uint8_t)  14)
1098bdc5a62SPatrick Kelsey #define	TAG_DOMAINNAME		((uint8_t)  15)
1108bdc5a62SPatrick Kelsey #define	TAG_SWAP_SERVER		((uint8_t)  16)
1118bdc5a62SPatrick Kelsey #define	TAG_ROOTPATH		((uint8_t)  17)
1128bdc5a62SPatrick Kelsey #define	TAG_EXTPATH		((uint8_t)  18)
1138bdc5a62SPatrick Kelsey /* RFC2132 */
1148bdc5a62SPatrick Kelsey #define	TAG_IP_FORWARD		((uint8_t)  19)
1158bdc5a62SPatrick Kelsey #define	TAG_NL_SRCRT		((uint8_t)  20)
1168bdc5a62SPatrick Kelsey #define	TAG_PFILTERS		((uint8_t)  21)
1178bdc5a62SPatrick Kelsey #define	TAG_REASS_SIZE		((uint8_t)  22)
1188bdc5a62SPatrick Kelsey #define	TAG_DEF_TTL		((uint8_t)  23)
1198bdc5a62SPatrick Kelsey #define	TAG_MTU_TIMEOUT		((uint8_t)  24)
1208bdc5a62SPatrick Kelsey #define	TAG_MTU_TABLE		((uint8_t)  25)
1218bdc5a62SPatrick Kelsey #define	TAG_INT_MTU		((uint8_t)  26)
1228bdc5a62SPatrick Kelsey #define	TAG_LOCAL_SUBNETS	((uint8_t)  27)
1238bdc5a62SPatrick Kelsey #define	TAG_BROAD_ADDR		((uint8_t)  28)
1248bdc5a62SPatrick Kelsey #define	TAG_DO_MASK_DISC	((uint8_t)  29)
1258bdc5a62SPatrick Kelsey #define	TAG_SUPPLY_MASK		((uint8_t)  30)
1268bdc5a62SPatrick Kelsey #define	TAG_DO_RDISC		((uint8_t)  31)
1278bdc5a62SPatrick Kelsey #define	TAG_RTR_SOL_ADDR	((uint8_t)  32)
1288bdc5a62SPatrick Kelsey #define	TAG_STATIC_ROUTE	((uint8_t)  33)
1298bdc5a62SPatrick Kelsey #define	TAG_USE_TRAILERS	((uint8_t)  34)
1308bdc5a62SPatrick Kelsey #define	TAG_ARP_TIMEOUT		((uint8_t)  35)
1318bdc5a62SPatrick Kelsey #define	TAG_ETH_ENCAP		((uint8_t)  36)
1328bdc5a62SPatrick Kelsey #define	TAG_TCP_TTL		((uint8_t)  37)
1338bdc5a62SPatrick Kelsey #define	TAG_TCP_KEEPALIVE	((uint8_t)  38)
1348bdc5a62SPatrick Kelsey #define	TAG_KEEPALIVE_GO	((uint8_t)  39)
1358bdc5a62SPatrick Kelsey #define	TAG_NIS_DOMAIN		((uint8_t)  40)
1368bdc5a62SPatrick Kelsey #define	TAG_NIS_SERVERS		((uint8_t)  41)
1378bdc5a62SPatrick Kelsey #define	TAG_NTP_SERVERS		((uint8_t)  42)
1388bdc5a62SPatrick Kelsey #define	TAG_VENDOR_OPTS		((uint8_t)  43)
1398bdc5a62SPatrick Kelsey #define	TAG_NETBIOS_NS		((uint8_t)  44)
1408bdc5a62SPatrick Kelsey #define	TAG_NETBIOS_DDS		((uint8_t)  45)
1418bdc5a62SPatrick Kelsey #define	TAG_NETBIOS_NODE	((uint8_t)  46)
1428bdc5a62SPatrick Kelsey #define	TAG_NETBIOS_SCOPE	((uint8_t)  47)
1438bdc5a62SPatrick Kelsey #define	TAG_XWIN_FS		((uint8_t)  48)
1448bdc5a62SPatrick Kelsey #define	TAG_XWIN_DM		((uint8_t)  49)
1458bdc5a62SPatrick Kelsey #define	TAG_NIS_P_DOMAIN	((uint8_t)  64)
1468bdc5a62SPatrick Kelsey #define	TAG_NIS_P_SERVERS	((uint8_t)  65)
1478bdc5a62SPatrick Kelsey #define	TAG_MOBILE_HOME		((uint8_t)  68)
148*0a7e5f1fSJoseph Mingrone #define	TAG_SMTP_SERVER		((uint8_t)  69)
1498bdc5a62SPatrick Kelsey #define	TAG_POP3_SERVER		((uint8_t)  70)
1508bdc5a62SPatrick Kelsey #define	TAG_NNTP_SERVER		((uint8_t)  71)
1518bdc5a62SPatrick Kelsey #define	TAG_WWW_SERVER		((uint8_t)  72)
1528bdc5a62SPatrick Kelsey #define	TAG_FINGER_SERVER	((uint8_t)  73)
1538bdc5a62SPatrick Kelsey #define	TAG_IRC_SERVER		((uint8_t)  74)
1548bdc5a62SPatrick Kelsey #define	TAG_STREETTALK_SRVR	((uint8_t)  75)
1558bdc5a62SPatrick Kelsey #define	TAG_STREETTALK_STDA	((uint8_t)  76)
1568bdc5a62SPatrick Kelsey /* DHCP options */
1578bdc5a62SPatrick Kelsey #define	TAG_REQUESTED_IP	((uint8_t)  50)
1588bdc5a62SPatrick Kelsey #define	TAG_IP_LEASE		((uint8_t)  51)
1598bdc5a62SPatrick Kelsey #define	TAG_OPT_OVERLOAD	((uint8_t)  52)
1608bdc5a62SPatrick Kelsey #define	TAG_TFTP_SERVER		((uint8_t)  66)
1618bdc5a62SPatrick Kelsey #define	TAG_BOOTFILENAME	((uint8_t)  67)
1628bdc5a62SPatrick Kelsey #define	TAG_DHCP_MESSAGE	((uint8_t)  53)
1638bdc5a62SPatrick Kelsey #define	TAG_SERVER_ID		((uint8_t)  54)
1648bdc5a62SPatrick Kelsey #define	TAG_PARM_REQUEST	((uint8_t)  55)
1658bdc5a62SPatrick Kelsey #define	TAG_MESSAGE		((uint8_t)  56)
1668bdc5a62SPatrick Kelsey #define	TAG_MAX_MSG_SIZE	((uint8_t)  57)
1678bdc5a62SPatrick Kelsey #define	TAG_RENEWAL_TIME	((uint8_t)  58)
1688bdc5a62SPatrick Kelsey #define	TAG_REBIND_TIME		((uint8_t)  59)
1698bdc5a62SPatrick Kelsey #define	TAG_VENDOR_CLASS	((uint8_t)  60)
1708bdc5a62SPatrick Kelsey #define	TAG_CLIENT_ID		((uint8_t)  61)
1718bdc5a62SPatrick Kelsey /* RFC 2241 */
1728bdc5a62SPatrick Kelsey #define	TAG_NDS_SERVERS		((uint8_t)  85)
1738bdc5a62SPatrick Kelsey #define	TAG_NDS_TREE_NAME	((uint8_t)  86)
1748bdc5a62SPatrick Kelsey #define	TAG_NDS_CONTEXT		((uint8_t)  87)
1758bdc5a62SPatrick Kelsey /* RFC 2242 */
1768bdc5a62SPatrick Kelsey #define	TAG_NDS_IPDOMAIN	((uint8_t)  62)
1778bdc5a62SPatrick Kelsey #define	TAG_NDS_IPINFO		((uint8_t)  63)
1788bdc5a62SPatrick Kelsey /* RFC 2485 */
1798bdc5a62SPatrick Kelsey #define	TAG_OPEN_GROUP_UAP	((uint8_t)  98)
1808bdc5a62SPatrick Kelsey /* RFC 2563 */
1818bdc5a62SPatrick Kelsey #define	TAG_DISABLE_AUTOCONF	((uint8_t) 116)
1828bdc5a62SPatrick Kelsey /* RFC 2610 */
1838bdc5a62SPatrick Kelsey #define	TAG_SLP_DA		((uint8_t)  78)
1848bdc5a62SPatrick Kelsey #define	TAG_SLP_SCOPE		((uint8_t)  79)
1858bdc5a62SPatrick Kelsey /* RFC 2937 */
1868bdc5a62SPatrick Kelsey #define	TAG_NS_SEARCH		((uint8_t) 117)
1878bdc5a62SPatrick Kelsey /* RFC 3004 - The User Class Option for DHCP */
1888bdc5a62SPatrick Kelsey #define	TAG_USER_CLASS		((uint8_t)  77)
1898bdc5a62SPatrick Kelsey /* RFC 3011 */
1908bdc5a62SPatrick Kelsey #define	TAG_IP4_SUBNET_SELECT	((uint8_t) 118)
1918bdc5a62SPatrick Kelsey /* RFC 3442 */
1928bdc5a62SPatrick Kelsey #define TAG_CLASSLESS_STATIC_RT	((uint8_t) 121)
1938bdc5a62SPatrick Kelsey #define TAG_CLASSLESS_STA_RT_MS	((uint8_t) 249)
194*0a7e5f1fSJoseph Mingrone /* RFC8572 */
195*0a7e5f1fSJoseph Mingrone #define TAG_SZTP_REDIRECT	((uint8_t) 143)
1968bdc5a62SPatrick Kelsey /* RFC 5859 - TFTP Server Address Option for DHCPv4 */
1978bdc5a62SPatrick Kelsey #define	TAG_TFTP_SERVER_ADDRESS	((uint8_t) 150)
198ee67461eSJoseph Mingrone /* https://www.iana.org/assignments/bootp-dhcp-parameters/bootp-dhcp-parameters.xhtml */
1998bdc5a62SPatrick Kelsey #define	TAG_SLP_NAMING_AUTH	((uint8_t)  80)
2008bdc5a62SPatrick Kelsey #define	TAG_CLIENT_FQDN		((uint8_t)  81)
2018bdc5a62SPatrick Kelsey #define	TAG_AGENT_CIRCUIT	((uint8_t)  82)
2028bdc5a62SPatrick Kelsey #define	TAG_AGENT_REMOTE	((uint8_t)  83)
2038bdc5a62SPatrick Kelsey #define	TAG_TZ_STRING		((uint8_t)  88)
2048bdc5a62SPatrick Kelsey #define	TAG_FQDN_OPTION		((uint8_t)  89)
2058bdc5a62SPatrick Kelsey #define	TAG_AUTH		((uint8_t)  90)
206ee67461eSJoseph Mingrone #define	TAG_CLIENT_LAST_TRANSACTION_TIME	((uint8_t)  91)
207ee67461eSJoseph Mingrone #define	TAG_ASSOCIATED_IP			((uint8_t)  92)
2088bdc5a62SPatrick Kelsey #define	TAG_CLIENT_ARCH		((uint8_t)  93)
2098bdc5a62SPatrick Kelsey #define	TAG_CLIENT_NDI		((uint8_t)  94)
2108bdc5a62SPatrick Kelsey #define	TAG_CLIENT_GUID		((uint8_t)  97)
2118bdc5a62SPatrick Kelsey #define	TAG_LDAP_URL		((uint8_t)  95)
2123340d773SGleb Smirnoff /* RFC 4833, TZ codes */
2133340d773SGleb Smirnoff #define	TAG_TZ_PCODE		((uint8_t) 100)
2143340d773SGleb Smirnoff #define	TAG_TZ_TCODE		((uint8_t) 101)
2158bdc5a62SPatrick Kelsey #define	TAG_NETINFO_PARENT	((uint8_t) 112)
2168bdc5a62SPatrick Kelsey #define	TAG_NETINFO_PARENT_TAG	((uint8_t) 113)
2178bdc5a62SPatrick Kelsey #define	TAG_URL			((uint8_t) 114)
2183340d773SGleb Smirnoff #define TAG_MUDURL              ((uint8_t) 161)
2198bdc5a62SPatrick Kelsey 
2208bdc5a62SPatrick Kelsey /* DHCP Message types (values for TAG_DHCP_MESSAGE option) */
2218bdc5a62SPatrick Kelsey #define DHCPDISCOVER	1
2228bdc5a62SPatrick Kelsey #define DHCPOFFER	2
2238bdc5a62SPatrick Kelsey #define DHCPREQUEST	3
2248bdc5a62SPatrick Kelsey #define DHCPDECLINE	4
2258bdc5a62SPatrick Kelsey #define DHCPACK		5
2268bdc5a62SPatrick Kelsey #define DHCPNAK		6
2278bdc5a62SPatrick Kelsey #define DHCPRELEASE	7
2288bdc5a62SPatrick Kelsey #define DHCPINFORM	8
229ee67461eSJoseph Mingrone /* Defined in RFC4388 */
230ee67461eSJoseph Mingrone #define DHCPLEASEQUERY       10
231ee67461eSJoseph Mingrone #define DHCPLEASEUNASSIGNED  11
232ee67461eSJoseph Mingrone #define DHCPLEASEUNKNOWN     12
233ee67461eSJoseph Mingrone #define DHCPLEASEACTIVE      13
234ee67461eSJoseph Mingrone 
2358bdc5a62SPatrick Kelsey 
2368bdc5a62SPatrick Kelsey /*
2378bdc5a62SPatrick Kelsey  * "vendor" data permitted for CMU bootp clients.
2388bdc5a62SPatrick Kelsey  */
2398bdc5a62SPatrick Kelsey 
2408bdc5a62SPatrick Kelsey struct cmu_vend {
241ee67461eSJoseph Mingrone 	nd_byte		v_magic[4];	/* magic number */
242ee67461eSJoseph Mingrone 	nd_uint32_t	v_flags;	/* flags/opcodes, etc. */
243ee67461eSJoseph Mingrone 	nd_ipv4		v_smask;	/* Subnet mask */
244ee67461eSJoseph Mingrone 	nd_ipv4		v_dgate;	/* Default gateway */
245ee67461eSJoseph Mingrone 	nd_ipv4		v_dns1, v_dns2; /* Domain name servers */
246ee67461eSJoseph Mingrone 	nd_ipv4		v_ins1, v_ins2; /* IEN-116 name servers */
247ee67461eSJoseph Mingrone 	nd_ipv4		v_ts1, v_ts2;	/* Time servers */
248ee67461eSJoseph Mingrone 	nd_byte		v_unused[24];	/* currently unused */
249ee67461eSJoseph Mingrone };
2508bdc5a62SPatrick Kelsey 
2518bdc5a62SPatrick Kelsey 
2528bdc5a62SPatrick Kelsey /* v_flags values */
2538bdc5a62SPatrick Kelsey #define VF_SMASK	1	/* Subnet mask field contains valid data */
2548bdc5a62SPatrick Kelsey 
2558bdc5a62SPatrick Kelsey /* RFC 4702 DHCP Client FQDN Option */
2568bdc5a62SPatrick Kelsey 
2578bdc5a62SPatrick Kelsey #define CLIENT_FQDN_FLAGS_S	0x01
2588bdc5a62SPatrick Kelsey #define CLIENT_FQDN_FLAGS_O	0x02
2598bdc5a62SPatrick Kelsey #define CLIENT_FQDN_FLAGS_E	0x04
2608bdc5a62SPatrick Kelsey #define CLIENT_FQDN_FLAGS_N	0x08
2618bdc5a62SPatrick Kelsey /* end of original bootp.h */
2628bdc5a62SPatrick Kelsey 
2633c602fabSXin LI static void rfc1048_print(netdissect_options *, const u_char *);
2643c602fabSXin LI static void cmu_print(netdissect_options *, const u_char *);
2653c602fabSXin LI static char *client_fqdn_flags(u_int flags);
2664edb46e9SPaul Traina 
267cc391cceSBruce M Simpson static const struct tok bootp_flag_values[] = {
268cc391cceSBruce M Simpson 	{ 0x8000,	"Broadcast" },
269cc391cceSBruce M Simpson 	{ 0, NULL}
270cc391cceSBruce M Simpson };
271cc391cceSBruce M Simpson 
272cc391cceSBruce M Simpson static const struct tok bootp_op_values[] = {
273cc391cceSBruce M Simpson 	{ BOOTPREQUEST,	"Request" },
274cc391cceSBruce M Simpson 	{ BOOTPREPLY,	"Reply" },
275cc391cceSBruce M Simpson 	{ 0, NULL}
276cc391cceSBruce M Simpson };
277cc391cceSBruce M Simpson 
2784edb46e9SPaul Traina /*
2794edb46e9SPaul Traina  * Print bootp requests
2804edb46e9SPaul Traina  */
2814edb46e9SPaul Traina void
bootp_print(netdissect_options * ndo,const u_char * cp,u_int length)2823c602fabSXin LI bootp_print(netdissect_options *ndo,
283ee67461eSJoseph Mingrone 	    const u_char *cp, u_int length)
2844edb46e9SPaul Traina {
285ee67461eSJoseph Mingrone 	const struct bootp *bp;
286a1c2090eSBill Fenner 	static const u_char vm_cmu[4] = VM_CMU;
287a1c2090eSBill Fenner 	static const u_char vm_rfc1048[4] = VM_RFC1048;
288ee67461eSJoseph Mingrone 	uint8_t bp_op, bp_htype, bp_hlen;
2894edb46e9SPaul Traina 
290ee67461eSJoseph Mingrone 	ndo->ndo_protocol = "bootp";
291a1c2090eSBill Fenner 	bp = (const struct bootp *)cp;
292ee67461eSJoseph Mingrone 	bp_op = GET_U_1(bp->bp_op);
293ee67461eSJoseph Mingrone 	ND_PRINT("BOOTP/DHCP, %s",
294ee67461eSJoseph Mingrone 		  tok2str(bootp_op_values, "unknown (0x%02x)", bp_op));
2954edb46e9SPaul Traina 
296ee67461eSJoseph Mingrone 	bp_htype = GET_U_1(bp->bp_htype);
297ee67461eSJoseph Mingrone 	bp_hlen = GET_U_1(bp->bp_hlen);
298ee67461eSJoseph Mingrone 	if (bp_htype == 1 && bp_hlen == MAC_ADDR_LEN && bp_op == BOOTPREQUEST) {
299ee67461eSJoseph Mingrone 		ND_PRINT(" from %s", GET_ETHERADDR_STRING(bp->bp_chaddr));
3004edb46e9SPaul Traina 	}
3014edb46e9SPaul Traina 
302ee67461eSJoseph Mingrone 	ND_PRINT(", length %u", length);
303cc391cceSBruce M Simpson 
3043c602fabSXin LI 	if (!ndo->ndo_vflag)
305cc391cceSBruce M Simpson 		return;
306cc391cceSBruce M Simpson 
307ee67461eSJoseph Mingrone 	ND_TCHECK_2(bp->bp_secs);
3084edb46e9SPaul Traina 
3094edb46e9SPaul Traina 	/* The usual hardware address type is 1 (10Mb Ethernet) */
310ee67461eSJoseph Mingrone 	if (bp_htype != 1)
311ee67461eSJoseph Mingrone 		ND_PRINT(", htype %u", bp_htype);
3124edb46e9SPaul Traina 
3134edb46e9SPaul Traina 	/* The usual length for 10Mb Ethernet address is 6 bytes */
314ee67461eSJoseph Mingrone 	if (bp_htype != 1 || bp_hlen != MAC_ADDR_LEN)
315ee67461eSJoseph Mingrone 		ND_PRINT(", hlen %u", bp_hlen);
3164edb46e9SPaul Traina 
3174edb46e9SPaul Traina 	/* Only print interesting fields */
318ee67461eSJoseph Mingrone 	if (GET_U_1(bp->bp_hops))
319ee67461eSJoseph Mingrone 		ND_PRINT(", hops %u", GET_U_1(bp->bp_hops));
320ee67461eSJoseph Mingrone 	if (GET_BE_U_4(bp->bp_xid))
321ee67461eSJoseph Mingrone 		ND_PRINT(", xid 0x%x", GET_BE_U_4(bp->bp_xid));
322ee67461eSJoseph Mingrone 	if (GET_BE_U_2(bp->bp_secs))
323ee67461eSJoseph Mingrone 		ND_PRINT(", secs %u", GET_BE_U_2(bp->bp_secs));
324cc391cceSBruce M Simpson 
325ee67461eSJoseph Mingrone 	ND_PRINT(", Flags [%s]",
326ee67461eSJoseph Mingrone 		  bittok2str(bootp_flag_values, "none", GET_BE_U_2(bp->bp_flags)));
3273c602fabSXin LI 	if (ndo->ndo_vflag > 1)
328ee67461eSJoseph Mingrone 		ND_PRINT(" (0x%04x)", GET_BE_U_2(bp->bp_flags));
3294edb46e9SPaul Traina 
3304edb46e9SPaul Traina 	/* Client's ip address */
331ee67461eSJoseph Mingrone 	if (GET_IPV4_TO_NETWORK_ORDER(bp->bp_ciaddr))
332ee67461eSJoseph Mingrone 		ND_PRINT("\n\t  Client-IP %s", GET_IPADDR_STRING(bp->bp_ciaddr));
3334edb46e9SPaul Traina 
3344edb46e9SPaul Traina 	/* 'your' ip address (bootp client) */
335ee67461eSJoseph Mingrone 	if (GET_IPV4_TO_NETWORK_ORDER(bp->bp_yiaddr))
336ee67461eSJoseph Mingrone 		ND_PRINT("\n\t  Your-IP %s", GET_IPADDR_STRING(bp->bp_yiaddr));
3374edb46e9SPaul Traina 
3384edb46e9SPaul Traina 	/* Server's ip address */
339ee67461eSJoseph Mingrone 	if (GET_IPV4_TO_NETWORK_ORDER(bp->bp_siaddr))
340ee67461eSJoseph Mingrone 		ND_PRINT("\n\t  Server-IP %s", GET_IPADDR_STRING(bp->bp_siaddr));
3414edb46e9SPaul Traina 
3424edb46e9SPaul Traina 	/* Gateway's ip address */
343ee67461eSJoseph Mingrone 	if (GET_IPV4_TO_NETWORK_ORDER(bp->bp_giaddr))
344ee67461eSJoseph Mingrone 		ND_PRINT("\n\t  Gateway-IP %s", GET_IPADDR_STRING(bp->bp_giaddr));
3454edb46e9SPaul Traina 
3464edb46e9SPaul Traina 	/* Client's Ethernet address */
347ee67461eSJoseph Mingrone 	if (bp_htype == 1 && bp_hlen == MAC_ADDR_LEN) {
348ee67461eSJoseph Mingrone 		ND_PRINT("\n\t  Client-Ethernet-Address %s", GET_ETHERADDR_STRING(bp->bp_chaddr));
3494edb46e9SPaul Traina 	}
3504edb46e9SPaul Traina 
351ee67461eSJoseph Mingrone 	if (GET_U_1(bp->bp_sname)) {	/* get first char only */
352ee67461eSJoseph Mingrone 		ND_PRINT("\n\t  sname \"");
353ee67461eSJoseph Mingrone 		if (nd_printztn(ndo, bp->bp_sname, (u_int)sizeof(bp->bp_sname),
35439e421e8SCy Schubert 				ndo->ndo_snapend) == 0) {
355ee67461eSJoseph Mingrone 			ND_PRINT("\"");
356ee67461eSJoseph Mingrone 			nd_print_trunc(ndo);
3574edb46e9SPaul Traina 			return;
3584edb46e9SPaul Traina 		}
359ee67461eSJoseph Mingrone 		ND_PRINT("\"");
3604edb46e9SPaul Traina 	}
361ee67461eSJoseph Mingrone 	if (GET_U_1(bp->bp_file)) {	/* get first char only */
362ee67461eSJoseph Mingrone 		ND_PRINT("\n\t  file \"");
363ee67461eSJoseph Mingrone 		if (nd_printztn(ndo, bp->bp_file, (u_int)sizeof(bp->bp_file),
36439e421e8SCy Schubert 				ndo->ndo_snapend) == 0) {
365ee67461eSJoseph Mingrone 			ND_PRINT("\"");
366ee67461eSJoseph Mingrone 			nd_print_trunc(ndo);
3674edb46e9SPaul Traina 			return;
3684edb46e9SPaul Traina 		}
369ee67461eSJoseph Mingrone 		ND_PRINT("\"");
3704edb46e9SPaul Traina 	}
3714edb46e9SPaul Traina 
3724edb46e9SPaul Traina 	/* Decode the vendor buffer */
373ee67461eSJoseph Mingrone 	ND_TCHECK_4(bp->bp_vend);
374a1c2090eSBill Fenner 	if (memcmp((const char *)bp->bp_vend, vm_rfc1048,
3753c602fabSXin LI 		    sizeof(uint32_t)) == 0)
3763c602fabSXin LI 		rfc1048_print(ndo, bp->bp_vend);
377a1c2090eSBill Fenner 	else if (memcmp((const char *)bp->bp_vend, vm_cmu,
3783c602fabSXin LI 			sizeof(uint32_t)) == 0)
3793c602fabSXin LI 		cmu_print(ndo, bp->bp_vend);
3804edb46e9SPaul Traina 	else {
3813c602fabSXin LI 		uint32_t ul;
3824edb46e9SPaul Traina 
383ee67461eSJoseph Mingrone 		ul = GET_BE_U_4(bp->bp_vend);
3844edb46e9SPaul Traina 		if (ul != 0)
385ee67461eSJoseph Mingrone 			ND_PRINT("\n\t  Vendor-#0x%x", ul);
3864edb46e9SPaul Traina 	}
3874edb46e9SPaul Traina 
3884edb46e9SPaul Traina 	return;
3894edb46e9SPaul Traina trunc:
390ee67461eSJoseph Mingrone 	nd_print_trunc(ndo);
3914edb46e9SPaul Traina }
3924edb46e9SPaul Traina 
393a1c2090eSBill Fenner /*
394a1c2090eSBill Fenner  * The first character specifies the format to print:
395a1c2090eSBill Fenner  *     i - ip address (32 bits)
396a1c2090eSBill Fenner  *     p - ip address pairs (32 bits + 32 bits)
397a1c2090eSBill Fenner  *     l - long (32 bits)
398a1c2090eSBill Fenner  *     L - unsigned long (32 bits)
399a1c2090eSBill Fenner  *     s - short (16 bits)
400ee67461eSJoseph Mingrone  *     b - period-separated decimal bytes (variable length)
401ee67461eSJoseph Mingrone  *     x - colon-separated hex bytes (variable length)
402ee67461eSJoseph Mingrone  *     a - ASCII string (variable length)
403a1c2090eSBill Fenner  *     B - on/off (8 bits)
404a1c2090eSBill Fenner  *     $ - special (explicit code to handle)
405a1c2090eSBill Fenner  */
4063c602fabSXin LI static const struct tok tag2str[] = {
4074edb46e9SPaul Traina /* RFC1048 tags */
4084edb46e9SPaul Traina 	{ TAG_PAD,		" PAD" },
409abf25193SMax Laier 	{ TAG_SUBNET_MASK,	"iSubnet-Mask" },	/* subnet mask (RFC950) */
410abf25193SMax Laier 	{ TAG_TIME_OFFSET,	"LTime-Zone" },	/* seconds from UTC */
411abf25193SMax Laier 	{ TAG_GATEWAY,		"iDefault-Gateway" },	/* default gateway */
412abf25193SMax Laier 	{ TAG_TIME_SERVER,	"iTime-Server" },	/* time servers (RFC868) */
413abf25193SMax Laier 	{ TAG_NAME_SERVER,	"iIEN-Name-Server" },	/* IEN name servers (IEN116) */
414abf25193SMax Laier 	{ TAG_DOMAIN_SERVER,	"iDomain-Name-Server" },	/* domain name (RFC1035) */
4154edb46e9SPaul Traina 	{ TAG_LOG_SERVER,	"iLOG" },	/* MIT log servers */
4164edb46e9SPaul Traina 	{ TAG_COOKIE_SERVER,	"iCS" },	/* cookie servers (RFC865) */
417abf25193SMax Laier 	{ TAG_LPR_SERVER,	"iLPR-Server" },	/* lpr server (RFC1179) */
4184edb46e9SPaul Traina 	{ TAG_IMPRESS_SERVER,	"iIM" },	/* impress servers (Imagen) */
4194edb46e9SPaul Traina 	{ TAG_RLP_SERVER,	"iRL" },	/* resource location (RFC887) */
420ee67461eSJoseph Mingrone 	{ TAG_HOSTNAME,		"aHostname" },	/* ASCII hostname */
4214edb46e9SPaul Traina 	{ TAG_BOOTSIZE,		"sBS" },	/* 512 byte blocks */
4224edb46e9SPaul Traina 	{ TAG_END,		" END" },
4234edb46e9SPaul Traina /* RFC1497 tags */
4244edb46e9SPaul Traina 	{ TAG_DUMPPATH,		"aDP" },
425abf25193SMax Laier 	{ TAG_DOMAINNAME,	"aDomain-Name" },
4264edb46e9SPaul Traina 	{ TAG_SWAP_SERVER,	"iSS" },
4274edb46e9SPaul Traina 	{ TAG_ROOTPATH,		"aRP" },
4284edb46e9SPaul Traina 	{ TAG_EXTPATH,		"aEP" },
429a88113a8SBill Fenner /* RFC2132 tags */
430a88113a8SBill Fenner 	{ TAG_IP_FORWARD,	"BIPF" },
431a88113a8SBill Fenner 	{ TAG_NL_SRCRT,		"BSRT" },
432a88113a8SBill Fenner 	{ TAG_PFILTERS,		"pPF" },
433a88113a8SBill Fenner 	{ TAG_REASS_SIZE,	"sRSZ" },
434a88113a8SBill Fenner 	{ TAG_DEF_TTL,		"bTTL" },
435abf25193SMax Laier 	{ TAG_MTU_TIMEOUT,	"lMTU-Timeout" },
436abf25193SMax Laier 	{ TAG_MTU_TABLE,	"sMTU-Table" },
437a88113a8SBill Fenner 	{ TAG_INT_MTU,		"sMTU" },
438a88113a8SBill Fenner 	{ TAG_LOCAL_SUBNETS,	"BLSN" },
439a88113a8SBill Fenner 	{ TAG_BROAD_ADDR,	"iBR" },
440a88113a8SBill Fenner 	{ TAG_DO_MASK_DISC,	"BMD" },
441a88113a8SBill Fenner 	{ TAG_SUPPLY_MASK,	"BMS" },
442abf25193SMax Laier 	{ TAG_DO_RDISC,		"BRouter-Discovery" },
443a88113a8SBill Fenner 	{ TAG_RTR_SOL_ADDR,	"iRSA" },
444abf25193SMax Laier 	{ TAG_STATIC_ROUTE,	"pStatic-Route" },
445a88113a8SBill Fenner 	{ TAG_USE_TRAILERS,	"BUT" },
446a88113a8SBill Fenner 	{ TAG_ARP_TIMEOUT,	"lAT" },
447a88113a8SBill Fenner 	{ TAG_ETH_ENCAP,	"BIE" },
448a88113a8SBill Fenner 	{ TAG_TCP_TTL,		"bTT" },
449a88113a8SBill Fenner 	{ TAG_TCP_KEEPALIVE,	"lKI" },
450a88113a8SBill Fenner 	{ TAG_KEEPALIVE_GO,	"BKG" },
451a88113a8SBill Fenner 	{ TAG_NIS_DOMAIN,	"aYD" },
452a88113a8SBill Fenner 	{ TAG_NIS_SERVERS,	"iYS" },
453a88113a8SBill Fenner 	{ TAG_NTP_SERVERS,	"iNTP" },
454abf25193SMax Laier 	{ TAG_VENDOR_OPTS,	"bVendor-Option" },
455abf25193SMax Laier 	{ TAG_NETBIOS_NS,	"iNetbios-Name-Server" },
456a88113a8SBill Fenner 	{ TAG_NETBIOS_DDS,	"iWDD" },
457abf25193SMax Laier 	{ TAG_NETBIOS_NODE,	"$Netbios-Node" },
458abf25193SMax Laier 	{ TAG_NETBIOS_SCOPE,	"aNetbios-Scope" },
459a88113a8SBill Fenner 	{ TAG_XWIN_FS,		"iXFS" },
460a88113a8SBill Fenner 	{ TAG_XWIN_DM,		"iXDM" },
461a88113a8SBill Fenner 	{ TAG_NIS_P_DOMAIN,	"sN+D" },
462a88113a8SBill Fenner 	{ TAG_NIS_P_SERVERS,	"iN+S" },
463a88113a8SBill Fenner 	{ TAG_MOBILE_HOME,	"iMH" },
464*0a7e5f1fSJoseph Mingrone 	{ TAG_SMTP_SERVER,	"iSMTP" },
465a88113a8SBill Fenner 	{ TAG_POP3_SERVER,	"iPOP3" },
466a88113a8SBill Fenner 	{ TAG_NNTP_SERVER,	"iNNTP" },
467a88113a8SBill Fenner 	{ TAG_WWW_SERVER,	"iWWW" },
468a88113a8SBill Fenner 	{ TAG_FINGER_SERVER,	"iFG" },
469a88113a8SBill Fenner 	{ TAG_IRC_SERVER,	"iIRC" },
470a88113a8SBill Fenner 	{ TAG_STREETTALK_SRVR,	"iSTS" },
471a88113a8SBill Fenner 	{ TAG_STREETTALK_STDA,	"iSTDA" },
472abf25193SMax Laier 	{ TAG_REQUESTED_IP,	"iRequested-IP" },
473abf25193SMax Laier 	{ TAG_IP_LEASE,		"lLease-Time" },
474a1c2090eSBill Fenner 	{ TAG_OPT_OVERLOAD,	"$OO" },
475a88113a8SBill Fenner 	{ TAG_TFTP_SERVER,	"aTFTP" },
476a88113a8SBill Fenner 	{ TAG_BOOTFILENAME,	"aBF" },
477abf25193SMax Laier 	{ TAG_DHCP_MESSAGE,	" DHCP-Message" },
478abf25193SMax Laier 	{ TAG_SERVER_ID,	"iServer-ID" },
479abf25193SMax Laier 	{ TAG_PARM_REQUEST,	"bParameter-Request" },
480a88113a8SBill Fenner 	{ TAG_MESSAGE,		"aMSG" },
481a88113a8SBill Fenner 	{ TAG_MAX_MSG_SIZE,	"sMSZ" },
482a88113a8SBill Fenner 	{ TAG_RENEWAL_TIME,	"lRN" },
483a88113a8SBill Fenner 	{ TAG_REBIND_TIME,	"lRB" },
484abf25193SMax Laier 	{ TAG_VENDOR_CLASS,	"aVendor-Class" },
485abf25193SMax Laier 	{ TAG_CLIENT_ID,	"$Client-ID" },
486943ee2b1SBill Fenner /* RFC 2485 */
487943ee2b1SBill Fenner 	{ TAG_OPEN_GROUP_UAP,	"aUAP" },
488943ee2b1SBill Fenner /* RFC 2563 */
489943ee2b1SBill Fenner 	{ TAG_DISABLE_AUTOCONF,	"BNOAUTO" },
490943ee2b1SBill Fenner /* RFC 2610 */
491943ee2b1SBill Fenner 	{ TAG_SLP_DA,		"bSLP-DA" },	/*"b" is a little wrong */
492943ee2b1SBill Fenner 	{ TAG_SLP_SCOPE,	"bSLP-SCOPE" },	/*"b" is a little wrong */
493943ee2b1SBill Fenner /* RFC 2937 */
494943ee2b1SBill Fenner 	{ TAG_NS_SEARCH,	"sNSSEARCH" },	/* XXX 's' */
4958bdc5a62SPatrick Kelsey /* RFC 3004 - The User Class Option for DHCP */
4968bdc5a62SPatrick Kelsey 	{ TAG_USER_CLASS,	"$User-Class" },
497943ee2b1SBill Fenner /* RFC 3011 */
498943ee2b1SBill Fenner 	{ TAG_IP4_SUBNET_SELECT, "iSUBNET" },
499abf25193SMax Laier /* RFC 3442 */
500abf25193SMax Laier 	{ TAG_CLASSLESS_STATIC_RT, "$Classless-Static-Route" },
501abf25193SMax Laier 	{ TAG_CLASSLESS_STA_RT_MS, "$Classless-Static-Route-Microsoft" },
502*0a7e5f1fSJoseph Mingrone /* RFC 8572 */
503*0a7e5f1fSJoseph Mingrone 	{ TAG_SZTP_REDIRECT,	"$SZTP-Redirect" },
5048bdc5a62SPatrick Kelsey /* RFC 5859 - TFTP Server Address Option for DHCPv4 */
5058bdc5a62SPatrick Kelsey 	{ TAG_TFTP_SERVER_ADDRESS, "iTFTP-Server-Address" },
506ee67461eSJoseph Mingrone /* https://www.iana.org/assignments/bootp-dhcp-parameters/bootp-dhcp-parameters.xhtml#options */
507943ee2b1SBill Fenner 	{ TAG_SLP_NAMING_AUTH,	"aSLP-NA" },
508a1c2090eSBill Fenner 	{ TAG_CLIENT_FQDN,	"$FQDN" },
509abf25193SMax Laier 	{ TAG_AGENT_CIRCUIT,	"$Agent-Information" },
510943ee2b1SBill Fenner 	{ TAG_AGENT_REMOTE,	"bARMT" },
511943ee2b1SBill Fenner 	{ TAG_TZ_STRING,	"aTZSTR" },
512943ee2b1SBill Fenner 	{ TAG_FQDN_OPTION,	"bFQDNS" },	/* XXX 'b' */
513943ee2b1SBill Fenner 	{ TAG_AUTH,		"bAUTH" },	/* XXX 'b' */
514ee67461eSJoseph Mingrone 	{ TAG_CLIENT_LAST_TRANSACTION_TIME, "LLast-Transaction-Time" },
515ee67461eSJoseph Mingrone 	{ TAG_ASSOCIATED_IP,	"iAssociated-IP" },
516943ee2b1SBill Fenner 	{ TAG_CLIENT_ARCH,	"sARCH" },
517943ee2b1SBill Fenner 	{ TAG_CLIENT_NDI,	"bNDI" },	/* XXX 'b' */
518943ee2b1SBill Fenner 	{ TAG_CLIENT_GUID,	"bGUID" },	/* XXX 'b' */
519943ee2b1SBill Fenner 	{ TAG_LDAP_URL,		"aLDAP" },
5203340d773SGleb Smirnoff 	{ TAG_TZ_PCODE,		"aPOSIX-TZ" },
5213340d773SGleb Smirnoff 	{ TAG_TZ_TCODE,		"aTZ-Name" },
522943ee2b1SBill Fenner 	{ TAG_NETINFO_PARENT,	"iNI" },
523943ee2b1SBill Fenner 	{ TAG_NETINFO_PARENT_TAG, "aNITAG" },
524943ee2b1SBill Fenner 	{ TAG_URL,		"aURL" },
5253340d773SGleb Smirnoff 	{ TAG_MUDURL,           "aMUD-URL" },
526943ee2b1SBill Fenner 	{ 0, NULL }
527943ee2b1SBill Fenner };
5284edb46e9SPaul Traina 
529a1c2090eSBill Fenner /* DHCP "options overload" types */
5303c602fabSXin LI static const struct tok oo2str[] = {
531a1c2090eSBill Fenner 	{ 1,	"file" },
532a1c2090eSBill Fenner 	{ 2,	"sname" },
533a1c2090eSBill Fenner 	{ 3,	"file+sname" },
534a1c2090eSBill Fenner 	{ 0, NULL }
535a1c2090eSBill Fenner };
536a1c2090eSBill Fenner 
537a1c2090eSBill Fenner /* NETBIOS over TCP/IP node type options */
5383c602fabSXin LI static const struct tok nbo2str[] = {
539a1c2090eSBill Fenner 	{ 0x1,	"b-node" },
540a1c2090eSBill Fenner 	{ 0x2,	"p-node" },
541a1c2090eSBill Fenner 	{ 0x4,	"m-node" },
542a1c2090eSBill Fenner 	{ 0x8,	"h-node" },
543a1c2090eSBill Fenner 	{ 0, NULL }
544a1c2090eSBill Fenner };
545a1c2090eSBill Fenner 
546a1c2090eSBill Fenner /* ARP Hardware types, for Client-ID option */
5473c602fabSXin LI static const struct tok arp2str[] = {
548a1c2090eSBill Fenner 	{ 0x1,	"ether" },
549a1c2090eSBill Fenner 	{ 0x6,	"ieee802" },
550a1c2090eSBill Fenner 	{ 0x7,	"arcnet" },
551a1c2090eSBill Fenner 	{ 0xf,	"frelay" },
552a1c2090eSBill Fenner 	{ 0x17,	"strip" },
553a1c2090eSBill Fenner 	{ 0x18,	"ieee1394" },
554a1c2090eSBill Fenner 	{ 0, NULL }
555a1c2090eSBill Fenner };
556a1c2090eSBill Fenner 
5573c602fabSXin LI static const struct tok dhcp_msg_values[] = {
558abf25193SMax Laier 	{ DHCPDISCOVER,	       "Discover" },
559abf25193SMax Laier 	{ DHCPOFFER,	       "Offer" },
560abf25193SMax Laier 	{ DHCPREQUEST,	       "Request" },
561abf25193SMax Laier 	{ DHCPDECLINE,	       "Decline" },
562abf25193SMax Laier 	{ DHCPACK,	       "ACK" },
563abf25193SMax Laier 	{ DHCPNAK,	       "NACK" },
564abf25193SMax Laier 	{ DHCPRELEASE,	       "Release" },
565abf25193SMax Laier 	{ DHCPINFORM,	       "Inform" },
566ee67461eSJoseph Mingrone 	{ DHCPLEASEQUERY,      "LeaseQuery" },
567ee67461eSJoseph Mingrone 	{ DHCPLEASEUNASSIGNED, "LeaseUnassigned" },
568ee67461eSJoseph Mingrone 	{ DHCPLEASEUNKNOWN,    "LeaseUnknown" },
569ee67461eSJoseph Mingrone 	{ DHCPLEASEACTIVE,     "LeaseActive" },
570abf25193SMax Laier 	{ 0, NULL }
571abf25193SMax Laier };
572abf25193SMax Laier 
573a5779b6eSRui Paulo #define AGENT_SUBOPTION_CIRCUIT_ID	1	/* RFC 3046 */
574a5779b6eSRui Paulo #define AGENT_SUBOPTION_REMOTE_ID	2	/* RFC 3046 */
575a5779b6eSRui Paulo #define AGENT_SUBOPTION_SUBSCRIBER_ID	6	/* RFC 3993 */
5763c602fabSXin LI static const struct tok agent_suboption_values[] = {
577abf25193SMax Laier 	{ AGENT_SUBOPTION_CIRCUIT_ID,    "Circuit-ID" },
578a5779b6eSRui Paulo 	{ AGENT_SUBOPTION_REMOTE_ID,     "Remote-ID" },
579a5779b6eSRui Paulo 	{ AGENT_SUBOPTION_SUBSCRIBER_ID, "Subscriber-ID" },
580abf25193SMax Laier 	{ 0, NULL }
581abf25193SMax Laier };
582abf25193SMax Laier 
583abf25193SMax Laier 
5844edb46e9SPaul Traina static void
rfc1048_print(netdissect_options * ndo,const u_char * bp)5853c602fabSXin LI rfc1048_print(netdissect_options *ndo,
586ee67461eSJoseph Mingrone 	      const u_char *bp)
5874edb46e9SPaul Traina {
588ee67461eSJoseph Mingrone 	uint16_t tag;
589ee67461eSJoseph Mingrone 	u_int len;
590ee67461eSJoseph Mingrone 	const char *cp;
591ee67461eSJoseph Mingrone 	char c;
592abf25193SMax Laier 	int first, idx;
593ee67461eSJoseph Mingrone 	uint8_t subopt, suboptlen;
5944edb46e9SPaul Traina 
595ee67461eSJoseph Mingrone 	ND_PRINT("\n\t  Vendor-rfc1048 Extensions");
5964edb46e9SPaul Traina 
5974edb46e9SPaul Traina 	/* Step over magic cookie */
598ee67461eSJoseph Mingrone 	ND_PRINT("\n\t    Magic Cookie 0x%08x", GET_BE_U_4(bp));
5994edb46e9SPaul Traina 	bp += sizeof(int32_t);
6004edb46e9SPaul Traina 
6014edb46e9SPaul Traina 	/* Loop while we there is a tag left in the buffer */
602ee67461eSJoseph Mingrone 	while (ND_TTEST_1(bp)) {
603ee67461eSJoseph Mingrone 		tag = GET_U_1(bp);
604ee67461eSJoseph Mingrone 		bp++;
6053c602fabSXin LI 		if (tag == TAG_PAD && ndo->ndo_vflag < 3)
6064edb46e9SPaul Traina 			continue;
6073c602fabSXin LI 		if (tag == TAG_END && ndo->ndo_vflag < 3)
6084edb46e9SPaul Traina 			return;
609ee67461eSJoseph Mingrone 		cp = tok2str(tag2str, "?Unknown", tag);
6104edb46e9SPaul Traina 		c = *cp++;
6114edb46e9SPaul Traina 
612abf25193SMax Laier 		if (tag == TAG_PAD || tag == TAG_END)
613abf25193SMax Laier 			len = 0;
614abf25193SMax Laier 		else {
6154edb46e9SPaul Traina 			/* Get the length; check for truncation */
616ee67461eSJoseph Mingrone 			len = GET_U_1(bp);
617ee67461eSJoseph Mingrone 			bp++;
618abf25193SMax Laier 		}
619abf25193SMax Laier 
620ee67461eSJoseph Mingrone 		ND_PRINT("\n\t    %s (%u), length %u%s", cp, tag, len,
621ee67461eSJoseph Mingrone 			  len > 0 ? ": " : "");
622abf25193SMax Laier 
6233c602fabSXin LI 		if (tag == TAG_PAD && ndo->ndo_vflag > 2) {
624abf25193SMax Laier 			u_int ntag = 1;
625ee67461eSJoseph Mingrone 			while (ND_TTEST_1(bp) &&
626ee67461eSJoseph Mingrone 			       GET_U_1(bp) == TAG_PAD) {
627abf25193SMax Laier 				bp++;
628abf25193SMax Laier 				ntag++;
629abf25193SMax Laier 			}
630abf25193SMax Laier 			if (ntag > 1)
631ee67461eSJoseph Mingrone 				ND_PRINT(", occurs %u", ntag);
632abf25193SMax Laier 		}
633abf25193SMax Laier 
634ee67461eSJoseph Mingrone 		ND_TCHECK_LEN(bp, len);
6354edb46e9SPaul Traina 
636a88113a8SBill Fenner 		if (tag == TAG_DHCP_MESSAGE && len == 1) {
637ee67461eSJoseph Mingrone 			ND_PRINT("%s",
638ee67461eSJoseph Mingrone 				 tok2str(dhcp_msg_values, "Unknown (%u)", GET_U_1(bp)));
639ee67461eSJoseph Mingrone 			bp++;
640a88113a8SBill Fenner 			continue;
641a88113a8SBill Fenner 		}
642a88113a8SBill Fenner 
643a88113a8SBill Fenner 		if (tag == TAG_PARM_REQUEST) {
644abf25193SMax Laier 			idx = 0;
645ee67461eSJoseph Mingrone 			while (len > 0) {
646ee67461eSJoseph Mingrone 				uint8_t innertag = GET_U_1(bp);
647ee67461eSJoseph Mingrone 				bp++;
648ee67461eSJoseph Mingrone 				len--;
649ee67461eSJoseph Mingrone 				cp = tok2str(tag2str, "?Unknown", innertag);
650abf25193SMax Laier 				if (idx % 4 == 0)
651ee67461eSJoseph Mingrone 					ND_PRINT("\n\t      ");
652abf25193SMax Laier 				else
653ee67461eSJoseph Mingrone 					ND_PRINT(", ");
654ee67461eSJoseph Mingrone 				ND_PRINT("%s (%u)", cp + 1, innertag);
655abf25193SMax Laier 				idx++;
656943ee2b1SBill Fenner 			}
657943ee2b1SBill Fenner 			continue;
658943ee2b1SBill Fenner 		}
659abf25193SMax Laier 
6604edb46e9SPaul Traina 		/* Print data */
6614edb46e9SPaul Traina 		if (c == '?') {
6624edb46e9SPaul Traina 			/* Base default formats for unknown tags on data size */
663abf25193SMax Laier 			if (len & 1)
6644edb46e9SPaul Traina 				c = 'b';
665abf25193SMax Laier 			else if (len & 2)
6664edb46e9SPaul Traina 				c = 's';
6674edb46e9SPaul Traina 			else
6684edb46e9SPaul Traina 				c = 'l';
6694edb46e9SPaul Traina 		}
6704edb46e9SPaul Traina 		first = 1;
6714edb46e9SPaul Traina 		switch (c) {
6724edb46e9SPaul Traina 
6734edb46e9SPaul Traina 		case 'a':
674ee67461eSJoseph Mingrone 			/* ASCII strings */
675ee67461eSJoseph Mingrone 			ND_PRINT("\"");
676ee67461eSJoseph Mingrone 			if (nd_printn(ndo, bp, len, ndo->ndo_snapend)) {
677ee67461eSJoseph Mingrone 				ND_PRINT("\"");
67829292c17SSam Leffler 				goto trunc;
67929292c17SSam Leffler 			}
680ee67461eSJoseph Mingrone 			ND_PRINT("\"");
681abf25193SMax Laier 			bp += len;
682abf25193SMax Laier 			len = 0;
6834edb46e9SPaul Traina 			break;
6844edb46e9SPaul Traina 
6854edb46e9SPaul Traina 		case 'i':
6864edb46e9SPaul Traina 		case 'l':
687943ee2b1SBill Fenner 		case 'L':
6884edb46e9SPaul Traina 			/* ip addresses/32-bit words */
689ee67461eSJoseph Mingrone 			while (len >= 4) {
6904edb46e9SPaul Traina 				if (!first)
691ee67461eSJoseph Mingrone 					ND_PRINT(",");
692ee67461eSJoseph Mingrone 				if (c == 'i')
693ee67461eSJoseph Mingrone 					ND_PRINT("%s", GET_IPADDR_STRING(bp));
694ee67461eSJoseph Mingrone 				else if (c == 'L')
695ee67461eSJoseph Mingrone 					ND_PRINT("%d", GET_BE_S_4(bp));
6964edb46e9SPaul Traina 				else
697ee67461eSJoseph Mingrone 					ND_PRINT("%u", GET_BE_U_4(bp));
698ee67461eSJoseph Mingrone 				bp += 4;
699ee67461eSJoseph Mingrone 				len -= 4;
7004edb46e9SPaul Traina 				first = 0;
7014edb46e9SPaul Traina 			}
7024edb46e9SPaul Traina 			break;
7034edb46e9SPaul Traina 
704a88113a8SBill Fenner 		case 'p':
705a88113a8SBill Fenner 			/* IP address pairs */
706ee67461eSJoseph Mingrone 			while (len >= 2*4) {
707a88113a8SBill Fenner 				if (!first)
708ee67461eSJoseph Mingrone 					ND_PRINT(",");
709ee67461eSJoseph Mingrone 				ND_PRINT("(%s:", GET_IPADDR_STRING(bp));
710ee67461eSJoseph Mingrone 				bp += 4;
711ee67461eSJoseph Mingrone 				len -= 4;
712ee67461eSJoseph Mingrone 				ND_PRINT("%s)", GET_IPADDR_STRING(bp));
713ee67461eSJoseph Mingrone 				bp += 4;
714ee67461eSJoseph Mingrone 				len -= 4;
715a88113a8SBill Fenner 				first = 0;
716a88113a8SBill Fenner 			}
717a88113a8SBill Fenner 			break;
718a88113a8SBill Fenner 
7194edb46e9SPaul Traina 		case 's':
7204edb46e9SPaul Traina 			/* shorts */
721ee67461eSJoseph Mingrone 			while (len >= 2) {
7224edb46e9SPaul Traina 				if (!first)
723ee67461eSJoseph Mingrone 					ND_PRINT(",");
724ee67461eSJoseph Mingrone 				ND_PRINT("%u", GET_BE_U_2(bp));
725ee67461eSJoseph Mingrone 				bp += 2;
726ee67461eSJoseph Mingrone 				len -= 2;
7274edb46e9SPaul Traina 				first = 0;
7284edb46e9SPaul Traina 			}
7294edb46e9SPaul Traina 			break;
7304edb46e9SPaul Traina 
731a88113a8SBill Fenner 		case 'B':
732a88113a8SBill Fenner 			/* boolean */
733abf25193SMax Laier 			while (len > 0) {
734ee67461eSJoseph Mingrone 				uint8_t bool_value;
735a88113a8SBill Fenner 				if (!first)
736ee67461eSJoseph Mingrone 					ND_PRINT(",");
737ee67461eSJoseph Mingrone 				bool_value = GET_U_1(bp);
738ee67461eSJoseph Mingrone 				switch (bool_value) {
739a88113a8SBill Fenner 				case 0:
740ee67461eSJoseph Mingrone 					ND_PRINT("N");
741a88113a8SBill Fenner 					break;
742a88113a8SBill Fenner 				case 1:
743ee67461eSJoseph Mingrone 					ND_PRINT("Y");
744a88113a8SBill Fenner 					break;
745a88113a8SBill Fenner 				default:
746ee67461eSJoseph Mingrone 					ND_PRINT("%u?", bool_value);
747a88113a8SBill Fenner 					break;
748a88113a8SBill Fenner 				}
749a88113a8SBill Fenner 				++bp;
750abf25193SMax Laier 				--len;
751a88113a8SBill Fenner 				first = 0;
752a88113a8SBill Fenner 			}
753a88113a8SBill Fenner 			break;
754a88113a8SBill Fenner 
7554edb46e9SPaul Traina 		case 'b':
756943ee2b1SBill Fenner 		case 'x':
7574edb46e9SPaul Traina 		default:
7584edb46e9SPaul Traina 			/* Bytes */
759abf25193SMax Laier 			while (len > 0) {
760ee67461eSJoseph Mingrone 				uint8_t byte_value;
7614edb46e9SPaul Traina 				if (!first)
762ee67461eSJoseph Mingrone 					ND_PRINT(c == 'x' ? ":" : ".");
763ee67461eSJoseph Mingrone 				byte_value = GET_U_1(bp);
764a1c2090eSBill Fenner 				if (c == 'x')
765ee67461eSJoseph Mingrone 					ND_PRINT("%02x", byte_value);
766a1c2090eSBill Fenner 				else
767ee67461eSJoseph Mingrone 					ND_PRINT("%u", byte_value);
7684edb46e9SPaul Traina 				++bp;
769abf25193SMax Laier 				--len;
7704edb46e9SPaul Traina 				first = 0;
7714edb46e9SPaul Traina 			}
7724edb46e9SPaul Traina 			break;
773a1c2090eSBill Fenner 
774a1c2090eSBill Fenner 		case '$':
775a1c2090eSBill Fenner 			/* Guys we can't handle with one of the usual cases */
776a1c2090eSBill Fenner 			switch (tag) {
777a1c2090eSBill Fenner 
778a1c2090eSBill Fenner 			case TAG_NETBIOS_NODE:
779abf25193SMax Laier 				/* this option should be at least 1 byte long */
780abf25193SMax Laier 				if (len < 1) {
781ee67461eSJoseph Mingrone 					ND_PRINT("[ERROR: length < 1 bytes]");
782abf25193SMax Laier 					break;
783abf25193SMax Laier 				}
784ee67461eSJoseph Mingrone 				tag = GET_U_1(bp);
785ee67461eSJoseph Mingrone 				++bp;
786abf25193SMax Laier 				--len;
787ee67461eSJoseph Mingrone 				ND_PRINT("%s", tok2str(nbo2str, NULL, tag));
788a1c2090eSBill Fenner 				break;
789a1c2090eSBill Fenner 
790a1c2090eSBill Fenner 			case TAG_OPT_OVERLOAD:
791abf25193SMax Laier 				/* this option should be at least 1 byte long */
792abf25193SMax Laier 				if (len < 1) {
793ee67461eSJoseph Mingrone 					ND_PRINT("[ERROR: length < 1 bytes]");
794abf25193SMax Laier 					break;
795abf25193SMax Laier 				}
796ee67461eSJoseph Mingrone 				tag = GET_U_1(bp);
797ee67461eSJoseph Mingrone 				++bp;
798abf25193SMax Laier 				--len;
799ee67461eSJoseph Mingrone 				ND_PRINT("%s", tok2str(oo2str, NULL, tag));
800a1c2090eSBill Fenner 				break;
801a1c2090eSBill Fenner 
802a1c2090eSBill Fenner 			case TAG_CLIENT_FQDN:
803abf25193SMax Laier 				/* this option should be at least 3 bytes long */
804abf25193SMax Laier 				if (len < 3) {
805ee67461eSJoseph Mingrone 					ND_PRINT("[ERROR: length < 3 bytes]");
806abf25193SMax Laier 					bp += len;
807abf25193SMax Laier 					len = 0;
808cc391cceSBruce M Simpson 					break;
80929292c17SSam Leffler 				}
810ee67461eSJoseph Mingrone 				if (GET_U_1(bp) & 0xf0) {
811ee67461eSJoseph Mingrone 					ND_PRINT("[ERROR: MBZ nibble 0x%x != 0] ",
812ee67461eSJoseph Mingrone 						 (GET_U_1(bp) & 0xf0) >> 4);
813ee67461eSJoseph Mingrone 				}
814ee67461eSJoseph Mingrone 				if (GET_U_1(bp) & 0x0f)
815ee67461eSJoseph Mingrone 					ND_PRINT("[%s] ",
816ee67461eSJoseph Mingrone 						 client_fqdn_flags(GET_U_1(bp)));
817abf25193SMax Laier 				bp++;
818ee67461eSJoseph Mingrone 				if (GET_U_1(bp) || GET_U_1(bp + 1))
819ee67461eSJoseph Mingrone 					ND_PRINT("%u/%u ", GET_U_1(bp),
820ee67461eSJoseph Mingrone 						 GET_U_1(bp + 1));
821a1c2090eSBill Fenner 				bp += 2;
822ee67461eSJoseph Mingrone 				ND_PRINT("\"");
823ee67461eSJoseph Mingrone 				if (nd_printn(ndo, bp, len - 3, ndo->ndo_snapend)) {
824ee67461eSJoseph Mingrone 					ND_PRINT("\"");
82529292c17SSam Leffler 					goto trunc;
82629292c17SSam Leffler 				}
827ee67461eSJoseph Mingrone 				ND_PRINT("\"");
828abf25193SMax Laier 				bp += len - 3;
829abf25193SMax Laier 				len = 0;
830a1c2090eSBill Fenner 				break;
831a1c2090eSBill Fenner 
832a1c2090eSBill Fenner 			case TAG_CLIENT_ID:
8338bdc5a62SPatrick Kelsey 			    {
8348bdc5a62SPatrick Kelsey 				int type;
835abf25193SMax Laier 
836abf25193SMax Laier 				/* this option should be at least 1 byte long */
837abf25193SMax Laier 				if (len < 1) {
838ee67461eSJoseph Mingrone 					ND_PRINT("[ERROR: length < 1 bytes]");
839abf25193SMax Laier 					break;
840abf25193SMax Laier 				}
841ee67461eSJoseph Mingrone 				type = GET_U_1(bp);
842ee67461eSJoseph Mingrone 				bp++;
843abf25193SMax Laier 				len--;
844a1c2090eSBill Fenner 				if (type == 0) {
845ee67461eSJoseph Mingrone 					ND_PRINT("\"");
846ee67461eSJoseph Mingrone 					if (nd_printn(ndo, bp, len, ndo->ndo_snapend)) {
847ee67461eSJoseph Mingrone 						ND_PRINT("\"");
84829292c17SSam Leffler 						goto trunc;
84929292c17SSam Leffler 					}
850ee67461eSJoseph Mingrone 					ND_PRINT("\"");
851abf25193SMax Laier 					bp += len;
852abf25193SMax Laier 					len = 0;
853a1c2090eSBill Fenner 					break;
854a1c2090eSBill Fenner 				} else {
855ee67461eSJoseph Mingrone 					ND_PRINT("%s ", tok2str(arp2str, "hardware-type %u,", type));
856abf25193SMax Laier 					while (len > 0) {
857a1c2090eSBill Fenner 						if (!first)
858ee67461eSJoseph Mingrone 							ND_PRINT(":");
859ee67461eSJoseph Mingrone 						ND_PRINT("%02x", GET_U_1(bp));
860a1c2090eSBill Fenner 						++bp;
861abf25193SMax Laier 						--len;
862a1c2090eSBill Fenner 						first = 0;
863a1c2090eSBill Fenner 					}
864abf25193SMax Laier 				}
865a1c2090eSBill Fenner 				break;
866a1c2090eSBill Fenner 			    }
867a1c2090eSBill Fenner 
868abf25193SMax Laier 			case TAG_AGENT_CIRCUIT:
869abf25193SMax Laier 				while (len >= 2) {
870ee67461eSJoseph Mingrone 					subopt = GET_U_1(bp);
871ee67461eSJoseph Mingrone 					suboptlen = GET_U_1(bp + 1);
872ee67461eSJoseph Mingrone 					bp += 2;
873abf25193SMax Laier 					len -= 2;
874abf25193SMax Laier 					if (suboptlen > len) {
875ee67461eSJoseph Mingrone 						ND_PRINT("\n\t      %s SubOption %u, length %u: length goes past end of option",
876abf25193SMax Laier 							  tok2str(agent_suboption_values, "Unknown", subopt),
877abf25193SMax Laier 							  subopt,
878ee67461eSJoseph Mingrone 							  suboptlen);
879abf25193SMax Laier 						bp += len;
880abf25193SMax Laier 						len = 0;
881abf25193SMax Laier 						break;
882abf25193SMax Laier 					}
883ee67461eSJoseph Mingrone 					ND_PRINT("\n\t      %s SubOption %u, length %u: ",
884abf25193SMax Laier 						  tok2str(agent_suboption_values, "Unknown", subopt),
885abf25193SMax Laier 						  subopt,
886ee67461eSJoseph Mingrone 						  suboptlen);
887abf25193SMax Laier 					switch (subopt) {
888abf25193SMax Laier 
889a5779b6eSRui Paulo 					case AGENT_SUBOPTION_CIRCUIT_ID: /* fall through */
890a5779b6eSRui Paulo 					case AGENT_SUBOPTION_REMOTE_ID:
891a5779b6eSRui Paulo 					case AGENT_SUBOPTION_SUBSCRIBER_ID:
892ee67461eSJoseph Mingrone 						if (nd_printn(ndo, bp, suboptlen, ndo->ndo_snapend))
8938bdc5a62SPatrick Kelsey 							goto trunc;
894abf25193SMax Laier 						break;
895abf25193SMax Laier 
896abf25193SMax Laier 					default:
8973c602fabSXin LI 						print_unknown_data(ndo, bp, "\n\t\t", suboptlen);
898abf25193SMax Laier 					}
899abf25193SMax Laier 
900abf25193SMax Laier 					len -= suboptlen;
901abf25193SMax Laier 					bp += suboptlen;
902abf25193SMax Laier 				}
903abf25193SMax Laier 				break;
904abf25193SMax Laier 
905abf25193SMax Laier 			case TAG_CLASSLESS_STATIC_RT:
906abf25193SMax Laier 			case TAG_CLASSLESS_STA_RT_MS:
907abf25193SMax Laier 			    {
908abf25193SMax Laier 				u_int mask_width, significant_octets, i;
909abf25193SMax Laier 
910abf25193SMax Laier 				/* this option should be at least 5 bytes long */
911abf25193SMax Laier 				if (len < 5) {
912ee67461eSJoseph Mingrone 					ND_PRINT("[ERROR: length < 5 bytes]");
913abf25193SMax Laier 					bp += len;
914abf25193SMax Laier 					len = 0;
915abf25193SMax Laier 					break;
916abf25193SMax Laier 				}
917abf25193SMax Laier 				while (len > 0) {
918abf25193SMax Laier 					if (!first)
919ee67461eSJoseph Mingrone 						ND_PRINT(",");
920ee67461eSJoseph Mingrone 					mask_width = GET_U_1(bp);
921ee67461eSJoseph Mingrone 					bp++;
922abf25193SMax Laier 					len--;
923abf25193SMax Laier 					/* mask_width <= 32 */
924abf25193SMax Laier 					if (mask_width > 32) {
925ee67461eSJoseph Mingrone 						ND_PRINT("[ERROR: Mask width (%u) > 32]", mask_width);
926abf25193SMax Laier 						bp += len;
927abf25193SMax Laier 						len = 0;
928abf25193SMax Laier 						break;
929abf25193SMax Laier 					}
930abf25193SMax Laier 					significant_octets = (mask_width + 7) / 8;
931abf25193SMax Laier 					/* significant octets + router(4) */
932abf25193SMax Laier 					if (len < significant_octets + 4) {
933ee67461eSJoseph Mingrone 						ND_PRINT("[ERROR: Remaining length (%u) < %u bytes]", len, significant_octets + 4);
934abf25193SMax Laier 						bp += len;
935abf25193SMax Laier 						len = 0;
936abf25193SMax Laier 						break;
937abf25193SMax Laier 					}
938ee67461eSJoseph Mingrone 					ND_PRINT("(");
939abf25193SMax Laier 					if (mask_width == 0)
940ee67461eSJoseph Mingrone 						ND_PRINT("default");
941abf25193SMax Laier 					else {
942abf25193SMax Laier 						for (i = 0; i < significant_octets ; i++) {
943abf25193SMax Laier 							if (i > 0)
944ee67461eSJoseph Mingrone 								ND_PRINT(".");
945ee67461eSJoseph Mingrone 							ND_PRINT("%u",
946ee67461eSJoseph Mingrone 								 GET_U_1(bp));
947ee67461eSJoseph Mingrone 							bp++;
948abf25193SMax Laier 						}
949abf25193SMax Laier 						for (i = significant_octets ; i < 4 ; i++)
950ee67461eSJoseph Mingrone 							ND_PRINT(".0");
951ee67461eSJoseph Mingrone 						ND_PRINT("/%u", mask_width);
952abf25193SMax Laier 					}
953ee67461eSJoseph Mingrone 					ND_PRINT(":%s)", GET_IPADDR_STRING(bp));
954ee67461eSJoseph Mingrone 					bp += 4;
955abf25193SMax Laier 					len -= (significant_octets + 4);
956abf25193SMax Laier 					first = 0;
957abf25193SMax Laier 				}
9588bdc5a62SPatrick Kelsey 				break;
9598bdc5a62SPatrick Kelsey 			    }
9608bdc5a62SPatrick Kelsey 
9618bdc5a62SPatrick Kelsey 			case TAG_USER_CLASS:
9628bdc5a62SPatrick Kelsey 			    {
9638bdc5a62SPatrick Kelsey 				u_int suboptnumber = 1;
9648bdc5a62SPatrick Kelsey 
9658bdc5a62SPatrick Kelsey 				first = 1;
9668bdc5a62SPatrick Kelsey 				if (len < 2) {
967ee67461eSJoseph Mingrone 					ND_PRINT("[ERROR: length < 2 bytes]");
9688bdc5a62SPatrick Kelsey 					bp += len;
9698bdc5a62SPatrick Kelsey 					len = 0;
9708bdc5a62SPatrick Kelsey 					break;
9718bdc5a62SPatrick Kelsey 				}
9728bdc5a62SPatrick Kelsey 				while (len > 0) {
973ee67461eSJoseph Mingrone 					suboptlen = GET_U_1(bp);
974ee67461eSJoseph Mingrone 					bp++;
9758bdc5a62SPatrick Kelsey 					len--;
976ee67461eSJoseph Mingrone 					ND_PRINT("\n\t      ");
977ee67461eSJoseph Mingrone 					ND_PRINT("instance#%u: ", suboptnumber);
9788bdc5a62SPatrick Kelsey 					if (suboptlen == 0) {
979ee67461eSJoseph Mingrone 						ND_PRINT("[ERROR: suboption length must be non-zero]");
9808bdc5a62SPatrick Kelsey 						bp += len;
9818bdc5a62SPatrick Kelsey 						len = 0;
9828bdc5a62SPatrick Kelsey 						break;
9838bdc5a62SPatrick Kelsey 					}
9848bdc5a62SPatrick Kelsey 					if (len < suboptlen) {
985ee67461eSJoseph Mingrone 						ND_PRINT("[ERROR: invalid option]");
9868bdc5a62SPatrick Kelsey 						bp += len;
9878bdc5a62SPatrick Kelsey 						len = 0;
9888bdc5a62SPatrick Kelsey 						break;
9898bdc5a62SPatrick Kelsey 					}
990ee67461eSJoseph Mingrone 					ND_PRINT("\"");
991ee67461eSJoseph Mingrone 					if (nd_printn(ndo, bp, suboptlen, ndo->ndo_snapend)) {
992ee67461eSJoseph Mingrone 						ND_PRINT("\"");
9938bdc5a62SPatrick Kelsey 						goto trunc;
9948bdc5a62SPatrick Kelsey 					}
995ee67461eSJoseph Mingrone 					ND_PRINT("\"");
996ee67461eSJoseph Mingrone 					ND_PRINT(", length %u", suboptlen);
9978bdc5a62SPatrick Kelsey 					suboptnumber++;
9988bdc5a62SPatrick Kelsey 					len -= suboptlen;
9998bdc5a62SPatrick Kelsey 					bp += suboptlen;
1000abf25193SMax Laier 				}
1001abf25193SMax Laier 				break;
10028bdc5a62SPatrick Kelsey 			    }
1003abf25193SMax Laier 
1004*0a7e5f1fSJoseph Mingrone 
1005*0a7e5f1fSJoseph Mingrone 			case TAG_SZTP_REDIRECT:
1006*0a7e5f1fSJoseph Mingrone 				/* as per https://datatracker.ietf.org/doc/html/rfc8572#section-8.3
1007*0a7e5f1fSJoseph Mingrone 				 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-...-+-+-+-+-+-+-+
1008*0a7e5f1fSJoseph Mingrone 				 |        uri-length             |          URI                  |
1009*0a7e5f1fSJoseph Mingrone 				 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-...-+-+-+-+-+-+-+
1010*0a7e5f1fSJoseph Mingrone 
1011*0a7e5f1fSJoseph Mingrone 				 * uri-length: 2 octets long; specifies the length of the URI data.
1012*0a7e5f1fSJoseph Mingrone 				 * URI: URI of the SZTP bootstrap server.
1013*0a7e5f1fSJoseph Mingrone 				 */
1014*0a7e5f1fSJoseph Mingrone 				while (len >= 2) {
1015*0a7e5f1fSJoseph Mingrone 					suboptlen = GET_BE_U_2(bp);
1016*0a7e5f1fSJoseph Mingrone 					bp += 2;
1017*0a7e5f1fSJoseph Mingrone 					len -= 2;
1018*0a7e5f1fSJoseph Mingrone 					ND_PRINT("\n\t	    ");
1019*0a7e5f1fSJoseph Mingrone 					ND_PRINT("length %u: ", suboptlen);
1020*0a7e5f1fSJoseph Mingrone 					if (len < suboptlen) {
1021*0a7e5f1fSJoseph Mingrone 						ND_PRINT("length goes past end of option");
1022*0a7e5f1fSJoseph Mingrone 						bp += len;
1023*0a7e5f1fSJoseph Mingrone 						len = 0;
1024*0a7e5f1fSJoseph Mingrone 						break;
1025*0a7e5f1fSJoseph Mingrone 					}
1026*0a7e5f1fSJoseph Mingrone 					ND_PRINT("\"");
1027*0a7e5f1fSJoseph Mingrone 					nd_printjn(ndo, bp, suboptlen);
1028*0a7e5f1fSJoseph Mingrone 					ND_PRINT("\"");
1029*0a7e5f1fSJoseph Mingrone 					len -= suboptlen;
1030*0a7e5f1fSJoseph Mingrone 					bp += suboptlen;
1031*0a7e5f1fSJoseph Mingrone 				}
1032*0a7e5f1fSJoseph Mingrone 				if (len != 0) {
1033*0a7e5f1fSJoseph Mingrone 					ND_PRINT("[ERROR: length < 2 bytes]");
1034*0a7e5f1fSJoseph Mingrone 				}
1035*0a7e5f1fSJoseph Mingrone 				break;
1036*0a7e5f1fSJoseph Mingrone 
1037a1c2090eSBill Fenner 			default:
1038ee67461eSJoseph Mingrone 				ND_PRINT("[unknown special tag %u, size %u]",
1039ee67461eSJoseph Mingrone 					  tag, len);
1040abf25193SMax Laier 				bp += len;
1041abf25193SMax Laier 				len = 0;
1042a1c2090eSBill Fenner 				break;
1043a1c2090eSBill Fenner 			}
1044a1c2090eSBill Fenner 			break;
10454edb46e9SPaul Traina 		}
10464edb46e9SPaul Traina 		/* Data left over? */
1047abf25193SMax Laier 		if (len) {
1048ee67461eSJoseph Mingrone 			ND_PRINT("\n\t  trailing data length %u", len);
1049abf25193SMax Laier 			bp += len;
1050cc391cceSBruce M Simpson 		}
10514edb46e9SPaul Traina 	}
1052943ee2b1SBill Fenner 	return;
1053943ee2b1SBill Fenner trunc:
1054ee67461eSJoseph Mingrone 	nd_print_trunc(ndo);
10554edb46e9SPaul Traina }
10564edb46e9SPaul Traina 
1057ee67461eSJoseph Mingrone #define PRINTCMUADDR(m, s) { ND_TCHECK_4(cmu->m); \
1058ee67461eSJoseph Mingrone     if (GET_IPV4_TO_NETWORK_ORDER(cmu->m) != 0) \
1059ee67461eSJoseph Mingrone 	ND_PRINT(" %s:%s", s, GET_IPADDR_STRING(cmu->m)); }
1060ee67461eSJoseph Mingrone 
10614edb46e9SPaul Traina static void
cmu_print(netdissect_options * ndo,const u_char * bp)10623c602fabSXin LI cmu_print(netdissect_options *ndo,
1063ee67461eSJoseph Mingrone 	  const u_char *bp)
10644edb46e9SPaul Traina {
1065ee67461eSJoseph Mingrone 	const struct cmu_vend *cmu;
1066ee67461eSJoseph Mingrone 	uint8_t v_flags;
10674edb46e9SPaul Traina 
1068ee67461eSJoseph Mingrone 	ND_PRINT(" vend-cmu");
1069a1c2090eSBill Fenner 	cmu = (const struct cmu_vend *)bp;
10704edb46e9SPaul Traina 
10714edb46e9SPaul Traina 	/* Only print if there are unknown bits */
1072ee67461eSJoseph Mingrone 	ND_TCHECK_4(cmu->v_flags);
1073ee67461eSJoseph Mingrone 	v_flags = GET_U_1(cmu->v_flags);
1074ee67461eSJoseph Mingrone 	if ((v_flags & ~(VF_SMASK)) != 0)
1075ee67461eSJoseph Mingrone 		ND_PRINT(" F:0x%x", v_flags);
10764edb46e9SPaul Traina 	PRINTCMUADDR(v_dgate, "DG");
1077ee67461eSJoseph Mingrone 	PRINTCMUADDR(v_smask, v_flags & VF_SMASK ? "SM" : "SM*");
10784edb46e9SPaul Traina 	PRINTCMUADDR(v_dns1, "NS1");
10794edb46e9SPaul Traina 	PRINTCMUADDR(v_dns2, "NS2");
10804edb46e9SPaul Traina 	PRINTCMUADDR(v_ins1, "IEN1");
10814edb46e9SPaul Traina 	PRINTCMUADDR(v_ins2, "IEN2");
10824edb46e9SPaul Traina 	PRINTCMUADDR(v_ts1, "TS1");
10834edb46e9SPaul Traina 	PRINTCMUADDR(v_ts2, "TS2");
10844edb46e9SPaul Traina 	return;
10854edb46e9SPaul Traina 
10864edb46e9SPaul Traina trunc:
1087ee67461eSJoseph Mingrone 	nd_print_trunc(ndo);
10884edb46e9SPaul Traina }
1089abf25193SMax Laier 
1090ee67461eSJoseph Mingrone #undef PRINTCMUADDR
1091ee67461eSJoseph Mingrone 
1092abf25193SMax Laier static char *
client_fqdn_flags(u_int flags)1093abf25193SMax Laier client_fqdn_flags(u_int flags)
1094abf25193SMax Laier {
1095abf25193SMax Laier 	static char buf[8+1];
1096abf25193SMax Laier 	int i = 0;
1097abf25193SMax Laier 
1098abf25193SMax Laier 	if (flags & CLIENT_FQDN_FLAGS_S)
1099abf25193SMax Laier 		buf[i++] = 'S';
1100abf25193SMax Laier 	if (flags & CLIENT_FQDN_FLAGS_O)
1101abf25193SMax Laier 		buf[i++] = 'O';
1102abf25193SMax Laier 	if (flags & CLIENT_FQDN_FLAGS_E)
1103abf25193SMax Laier 		buf[i++] = 'E';
1104abf25193SMax Laier 	if (flags & CLIENT_FQDN_FLAGS_N)
1105abf25193SMax Laier 		buf[i++] = 'N';
1106abf25193SMax Laier 	buf[i] = '\0';
1107abf25193SMax Laier 
1108abf25193SMax Laier 	return buf;
1109abf25193SMax Laier }
1110