xref: /netbsd-src/external/bsd/tcpdump/dist/print-udp.c (revision 801f73adf8029e41ec107911c58034bb925796a2)
1 /*
2  * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that: (1) source code distributions
7  * retain the above copyright notice and this paragraph in its entirety, (2)
8  * distributions including binary code include the above copyright notice and
9  * this paragraph in its entirety in the documentation or other materials
10  * provided with the distribution, and (3) all advertising materials mentioning
11  * features or use of this software display the following acknowledgement:
12  * ``This product includes software developed by the University of California,
13  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14  * the University nor the names of its contributors may be used to endorse
15  * or promote products derived from this software without specific prior
16  * written permission.
17  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20  */
21 
22 #include <sys/cdefs.h>
23 #ifndef lint
24 __RCSID("$NetBSD: print-udp.c,v 1.10 2023/08/17 20:19:40 christos Exp $");
25 #endif
26 
27 /* \summary: UDP printer */
28 
29 #ifdef HAVE_CONFIG_H
30 #include <config.h>
31 #endif
32 
33 #include "netdissect-stdinc.h"
34 
35 #include "netdissect.h"
36 #include "addrtoname.h"
37 #include "extract.h"
38 #include "appletalk.h"
39 
40 #include "udp.h"
41 
42 #include "ip.h"
43 #include "ip6.h"
44 #include "ipproto.h"
45 #include "rpc_auth.h"
46 #include "rpc_msg.h"
47 
48 #include "nfs.h"
49 
50 
51 struct rtcphdr {
52 	nd_uint16_t rh_flags;	/* T:2 P:1 CNT:5 PT:8 */
53 	nd_uint16_t rh_len;	/* length of message (in words) */
54 	nd_uint32_t rh_ssrc;	/* synchronization src id */
55 };
56 
57 typedef struct {
58 	nd_uint32_t upper;	/* more significant 32 bits */
59 	nd_uint32_t lower;	/* less significant 32 bits */
60 } ntp64;
61 
62 /*
63  * Sender report.
64  */
65 struct rtcp_sr {
66 	ntp64       sr_ntp;	/* 64-bit ntp timestamp */
67 	nd_uint32_t sr_ts;	/* reference media timestamp */
68 	nd_uint32_t sr_np;	/* no. packets sent */
69 	nd_uint32_t sr_nb;	/* no. bytes sent */
70 };
71 
72 /*
73  * Receiver report.
74  * Time stamps are middle 32-bits of ntp timestamp.
75  */
76 struct rtcp_rr {
77 	nd_uint32_t rr_srcid;	/* sender being reported */
78 	nd_uint32_t rr_nl;	/* no. packets lost */
79 	nd_uint32_t rr_ls;	/* extended last seq number received */
80 	nd_uint32_t rr_dv;	/* jitter (delay variance) */
81 	nd_uint32_t rr_lsr;	/* orig. ts from last rr from this src  */
82 	nd_uint32_t rr_dlsr;	/* time from recpt of last rr to xmit time */
83 };
84 
85 /*XXX*/
86 #define RTCP_PT_SR	200
87 #define RTCP_PT_RR	201
88 #define RTCP_PT_SDES	202
89 #define    RTCP_SDES_CNAME	1
90 #define    RTCP_SDES_NAME	2
91 #define    RTCP_SDES_EMAIL	3
92 #define    RTCP_SDES_PHONE	4
93 #define    RTCP_SDES_LOC	5
94 #define    RTCP_SDES_TOOL	6
95 #define    RTCP_SDES_NOTE	7
96 #define    RTCP_SDES_PRIV	8
97 #define RTCP_PT_BYE	203
98 #define RTCP_PT_APP	204
99 
100 static void
101 vat_print(netdissect_options *ndo, const u_char *hdr, u_int length)
102 {
103 	/* vat/vt audio */
104 	u_int ts;
105 
106 	ndo->ndo_protocol = "vat";
107 	if (length < 2) {
108 		ND_PRINT("udp/va/vat, length %u < 2", length);
109 		return;
110 	}
111 	ts = GET_BE_U_2(hdr);
112 	if ((ts & 0xf060) != 0) {
113 		/* probably vt */
114 		ND_PRINT("udp/vt %u %u / %u",
115 			     length,
116 			     ts & 0x3ff, ts >> 10);
117 	} else {
118 		/* probably vat */
119 		uint32_t i0, i1;
120 
121 		if (length < 8) {
122 			ND_PRINT("udp/vat, length %u < 8", length);
123 			return;
124 		}
125 		i0 = GET_BE_U_4(&((const u_int *)hdr)[0]);
126 		i1 = GET_BE_U_4(&((const u_int *)hdr)[1]);
127 		ND_PRINT("udp/vat %u c%u %u%s",
128 			length - 8,
129 			i0 & 0xffff,
130 			i1, i0 & 0x800000? "*" : "");
131 		/* audio format */
132 		if (i0 & 0x1f0000)
133 			ND_PRINT(" f%u", (i0 >> 16) & 0x1f);
134 		if (i0 & 0x3f000000)
135 			ND_PRINT(" s%u", (i0 >> 24) & 0x3f);
136 	}
137 }
138 
139 static void
140 rtp_print(netdissect_options *ndo, const u_char *hdr, u_int len)
141 {
142 	/* rtp v1 or v2 */
143 	const u_int *ip = (const u_int *)hdr;
144 	u_int hasopt, hasext, contype, hasmarker, dlen;
145 	uint32_t i0, i1;
146 	const char * ptype;
147 
148 	ndo->ndo_protocol = "rtp";
149 	if (len < 8) {
150 		ND_PRINT("udp/rtp, length %u < 8", len);
151 		return;
152 	}
153 	i0 = GET_BE_U_4(&((const u_int *)hdr)[0]);
154 	i1 = GET_BE_U_4(&((const u_int *)hdr)[1]);
155 	dlen = len - 8;
156 	ip += 2;
157 	len >>= 2;
158 	len -= 2;
159 	hasopt = 0;
160 	hasext = 0;
161 	if ((i0 >> 30) == 1) {
162 		/* rtp v1 - draft-ietf-avt-rtp-04 */
163 		hasopt = i0 & 0x800000;
164 		contype = (i0 >> 16) & 0x3f;
165 		hasmarker = i0 & 0x400000;
166 		ptype = "rtpv1";
167 	} else {
168 		/* rtp v2 - RFC 3550 */
169 		if (dlen < 4) {
170 			ND_PRINT("udp/rtp, length %u < 12", dlen + 8);
171 			return;
172 		}
173 		hasext = i0 & 0x10000000;
174 		contype = (i0 >> 16) & 0x7f;
175 		hasmarker = i0 & 0x800000;
176 		dlen -= 4;
177 		ptype = "rtp";
178 		ip += 1;
179 		len -= 1;
180 	}
181 	ND_PRINT("udp/%s %u c%u %s%s %u %u",
182 		ptype,
183 		dlen,
184 		contype,
185 		(hasopt || hasext)? "+" : "",
186 		hasmarker? "*" : "",
187 		i0 & 0xffff,
188 		i1);
189 	if (ndo->ndo_vflag) {
190 		ND_PRINT(" %u", GET_BE_U_4(&((const u_int *)hdr)[2]));
191 		if (hasopt) {
192 			u_int i2, optlen;
193 			do {
194 				i2 = GET_BE_U_4(ip);
195 				optlen = (i2 >> 16) & 0xff;
196 				if (optlen == 0 || optlen > len) {
197 					ND_PRINT(" !opt");
198 					return;
199 				}
200 				ip += optlen;
201 				len -= optlen;
202 			} while ((int)i2 >= 0);
203 		}
204 		if (hasext) {
205 			u_int i2, extlen;
206 			i2 = GET_BE_U_4(ip);
207 			extlen = (i2 & 0xffff) + 1;
208 			if (extlen > len) {
209 				ND_PRINT(" !ext");
210 				return;
211 			}
212 			ip += extlen;
213 		}
214 		if (contype == 0x1f) /*XXX H.261 */
215 			ND_PRINT(" 0x%04x", GET_BE_U_4(ip) >> 16);
216 	}
217 }
218 
219 static const u_char *
220 rtcp_print(netdissect_options *ndo, const u_char *hdr, const u_char *ep)
221 {
222 	/* rtp v2 control (rtcp) */
223 	const struct rtcp_rr *rr = 0;
224 	const struct rtcp_sr *sr;
225 	const struct rtcphdr *rh = (const struct rtcphdr *)hdr;
226 	u_int len;
227 	uint16_t flags;
228 	u_int cnt;
229 	double ts, dts;
230 
231 	ndo->ndo_protocol = "rtcp";
232 	if ((const u_char *)(rh + 1) > ep)
233 		goto trunc;
234 	ND_TCHECK_SIZE(rh);
235 	len = (GET_BE_U_2(rh->rh_len) + 1) * 4;
236 	flags = GET_BE_U_2(rh->rh_flags);
237 	cnt = (flags >> 8) & 0x1f;
238 	switch (flags & 0xff) {
239 	case RTCP_PT_SR:
240 		sr = (const struct rtcp_sr *)(rh + 1);
241 		ND_PRINT(" sr");
242 		if (len != cnt * sizeof(*rr) + sizeof(*sr) + sizeof(*rh))
243 			ND_PRINT(" [%u]", len);
244 		if (ndo->ndo_vflag)
245 			ND_PRINT(" %u", GET_BE_U_4(rh->rh_ssrc));
246 		if ((const u_char *)(sr + 1) > ep)
247 			goto trunc;
248 		ND_TCHECK_SIZE(sr);
249 		ts = (double)(GET_BE_U_4(sr->sr_ntp.upper)) +
250 		    ((double)(GET_BE_U_4(sr->sr_ntp.lower)) /
251 		     FMAXINT);
252 		ND_PRINT(" @%.2f %u %up %ub", ts, GET_BE_U_4(sr->sr_ts),
253 			  GET_BE_U_4(sr->sr_np), GET_BE_U_4(sr->sr_nb));
254 		rr = (const struct rtcp_rr *)(sr + 1);
255 		break;
256 	case RTCP_PT_RR:
257 		ND_PRINT(" rr");
258 		if (len != cnt * sizeof(*rr) + sizeof(*rh))
259 			ND_PRINT(" [%u]", len);
260 		rr = (const struct rtcp_rr *)(rh + 1);
261 		if (ndo->ndo_vflag)
262 			ND_PRINT(" %u", GET_BE_U_4(rh->rh_ssrc));
263 		break;
264 	case RTCP_PT_SDES:
265 		ND_PRINT(" sdes %u", len);
266 		if (ndo->ndo_vflag)
267 			ND_PRINT(" %u", GET_BE_U_4(rh->rh_ssrc));
268 		cnt = 0;
269 		break;
270 	case RTCP_PT_BYE:
271 		ND_PRINT(" bye %u", len);
272 		if (ndo->ndo_vflag)
273 			ND_PRINT(" %u", GET_BE_U_4(rh->rh_ssrc));
274 		cnt = 0;
275 		break;
276 	default:
277 		ND_PRINT(" type-0x%x %u", flags & 0xff, len);
278 		cnt = 0;
279 		break;
280 	}
281 	if (cnt > 1)
282 		ND_PRINT(" c%u", cnt);
283 	while (cnt != 0) {
284 		if ((const u_char *)(rr + 1) > ep)
285 			goto trunc;
286 		ND_TCHECK_SIZE(rr);
287 		if (ndo->ndo_vflag)
288 			ND_PRINT(" %u", GET_BE_U_4(rr->rr_srcid));
289 		ts = (double)(GET_BE_U_4(rr->rr_lsr)) / 65536.;
290 		dts = (double)(GET_BE_U_4(rr->rr_dlsr)) / 65536.;
291 		ND_PRINT(" %ul %us %uj @%.2f+%.2f",
292 		    GET_BE_U_4(rr->rr_nl) & 0x00ffffff,
293 		    GET_BE_U_4(rr->rr_ls),
294 		    GET_BE_U_4(rr->rr_dv), ts, dts);
295 		cnt--;
296 	}
297 	return (hdr + len);
298 
299 trunc:
300 	nd_print_trunc(ndo);
301 	return ep;
302 }
303 
304 static uint16_t udp_cksum(netdissect_options *ndo, const struct ip *ip,
305 		     const struct udphdr *up,
306 		     u_int len)
307 {
308 	return nextproto4_cksum(ndo, ip, (const uint8_t *)(const void *)up, len, len,
309 				IPPROTO_UDP);
310 }
311 
312 static uint16_t udp6_cksum(netdissect_options *ndo, const struct ip6_hdr *ip6,
313 		      const struct udphdr *up, u_int len)
314 {
315 	return nextproto6_cksum(ndo, ip6, (const uint8_t *)(const void *)up, len, len,
316 				IPPROTO_UDP);
317 }
318 
319 static void
320 udpipaddr_print(netdissect_options *ndo, const struct ip *ip, int sport, int dport)
321 {
322 	const struct ip6_hdr *ip6;
323 
324 	if (IP_V(ip) == 6)
325 		ip6 = (const struct ip6_hdr *)ip;
326 	else
327 		ip6 = NULL;
328 
329 	if (ip6) {
330 		if (GET_U_1(ip6->ip6_nxt) == IPPROTO_UDP) {
331 			if (sport == -1) {
332 				ND_PRINT("%s > %s: ",
333 					GET_IP6ADDR_STRING(ip6->ip6_src),
334 					GET_IP6ADDR_STRING(ip6->ip6_dst));
335 			} else {
336 				ND_PRINT("%s.%s > %s.%s: ",
337 					GET_IP6ADDR_STRING(ip6->ip6_src),
338 					udpport_string(ndo, (uint16_t)sport),
339 					GET_IP6ADDR_STRING(ip6->ip6_dst),
340 					udpport_string(ndo, (uint16_t)dport));
341 			}
342 		} else {
343 			if (sport != -1) {
344 				ND_PRINT("%s > %s: ",
345 					udpport_string(ndo, (uint16_t)sport),
346 					udpport_string(ndo, (uint16_t)dport));
347 			}
348 		}
349 	} else {
350 		if (GET_U_1(ip->ip_p) == IPPROTO_UDP) {
351 			if (sport == -1) {
352 				ND_PRINT("%s > %s: ",
353 					GET_IPADDR_STRING(ip->ip_src),
354 					GET_IPADDR_STRING(ip->ip_dst));
355 			} else {
356 				ND_PRINT("%s.%s > %s.%s: ",
357 					GET_IPADDR_STRING(ip->ip_src),
358 					udpport_string(ndo, (uint16_t)sport),
359 					GET_IPADDR_STRING(ip->ip_dst),
360 					udpport_string(ndo, (uint16_t)dport));
361 			}
362 		} else {
363 			if (sport != -1) {
364 				ND_PRINT("%s > %s: ",
365 					udpport_string(ndo, (uint16_t)sport),
366 					udpport_string(ndo, (uint16_t)dport));
367 			}
368 		}
369 	}
370 }
371 
372 UNALIGNED_OK
373 void
374 udp_print(netdissect_options *ndo, const u_char *bp, u_int length,
375 	  const u_char *bp2, int fragmented, u_int ttl_hl)
376 {
377 	const struct udphdr *up;
378 	const struct ip *ip;
379 	const u_char *cp;
380 	const u_char *ep = ndo->ndo_snapend;
381 	uint16_t sport, dport;
382 	u_int ulen;
383 	const struct ip6_hdr *ip6;
384 
385 	ndo->ndo_protocol = "udp";
386 	up = (const struct udphdr *)bp;
387 	ip = (const struct ip *)bp2;
388 	if (IP_V(ip) == 6)
389 		ip6 = (const struct ip6_hdr *)bp2;
390 	else
391 		ip6 = NULL;
392 	if (!ND_TTEST_2(up->uh_dport)) {
393 		udpipaddr_print(ndo, ip, -1, -1);
394 		goto trunc;
395 	}
396 
397 	sport = GET_BE_U_2(up->uh_sport);
398 	dport = GET_BE_U_2(up->uh_dport);
399 
400 	if (length < sizeof(struct udphdr)) {
401 		udpipaddr_print(ndo, ip, sport, dport);
402 		ND_PRINT("truncated-udp %u", length);
403 		return;
404 	}
405 	if (!ND_TTEST_2(up->uh_ulen)) {
406 		udpipaddr_print(ndo, ip, sport, dport);
407 		goto trunc;
408 	}
409 	ulen = GET_BE_U_2(up->uh_ulen);
410 	/*
411 	 * IPv6 Jumbo Datagrams; see RFC 2675.
412 	 * If the length is zero, and the length provided to us is
413 	 * > 65535, use the provided length as the length.
414 	 */
415 	if (ulen == 0 && length > 65535)
416 		ulen = length;
417 	if (ulen < sizeof(struct udphdr)) {
418 		udpipaddr_print(ndo, ip, sport, dport);
419 		ND_PRINT("truncated-udplength %u", ulen);
420 		return;
421 	}
422 	ulen -= sizeof(struct udphdr);
423 	length -= sizeof(struct udphdr);
424 	if (ulen < length)
425 		length = ulen;
426 
427 	cp = (const u_char *)(up + 1);
428 	if (cp > ndo->ndo_snapend) {
429 		udpipaddr_print(ndo, ip, sport, dport);
430 		goto trunc;
431 	}
432 
433 	if (ndo->ndo_packettype) {
434 		const struct sunrpc_msg *rp;
435 		enum sunrpc_msg_type direction;
436 
437 		switch (ndo->ndo_packettype) {
438 
439 		case PT_VAT:
440 			udpipaddr_print(ndo, ip, sport, dport);
441 			vat_print(ndo, cp, length);
442 			break;
443 
444 		case PT_WB:
445 			udpipaddr_print(ndo, ip, sport, dport);
446 			wb_print(ndo, cp, length);
447 			break;
448 
449 		case PT_RPC:
450 			rp = (const struct sunrpc_msg *)cp;
451 			direction = (enum sunrpc_msg_type) GET_BE_U_4(rp->rm_direction);
452 			if (direction == SUNRPC_CALL)
453 				sunrpc_print(ndo, (const u_char *)rp, length,
454 				    (const u_char *)ip);
455 			else
456 				nfsreply_print(ndo, (const u_char *)rp, length,
457 				    (const u_char *)ip);			/*XXX*/
458 			break;
459 
460 		case PT_RTP:
461 			udpipaddr_print(ndo, ip, sport, dport);
462 			rtp_print(ndo, cp, length);
463 			break;
464 
465 		case PT_RTCP:
466 			udpipaddr_print(ndo, ip, sport, dport);
467 			while (cp < ep)
468 				cp = rtcp_print(ndo, cp, ep);
469 			break;
470 
471 		case PT_SNMP:
472 			udpipaddr_print(ndo, ip, sport, dport);
473 			snmp_print(ndo, cp, length);
474 			break;
475 
476 		case PT_CNFP:
477 			udpipaddr_print(ndo, ip, sport, dport);
478 			cnfp_print(ndo, cp);
479 			break;
480 
481 		case PT_TFTP:
482 			udpipaddr_print(ndo, ip, sport, dport);
483 			tftp_print(ndo, cp, length);
484 			break;
485 
486 		case PT_AODV:
487 			udpipaddr_print(ndo, ip, sport, dport);
488 			aodv_print(ndo, cp, length,
489 			    ip6 != NULL);
490 			break;
491 
492 		case PT_RADIUS:
493 			udpipaddr_print(ndo, ip, sport, dport);
494 			radius_print(ndo, cp, length);
495 			break;
496 
497 		case PT_VXLAN:
498 			udpipaddr_print(ndo, ip, sport, dport);
499 			vxlan_print(ndo, cp, length);
500 			break;
501 
502 		case PT_PGM:
503 		case PT_PGM_ZMTP1:
504 			udpipaddr_print(ndo, ip, sport, dport);
505 			pgm_print(ndo, cp, length, bp2);
506 			break;
507 		case PT_LMP:
508 			udpipaddr_print(ndo, ip, sport, dport);
509 			lmp_print(ndo, cp, length);
510 			break;
511 		case PT_PTP:
512 			udpipaddr_print(ndo, ip, sport, dport);
513 			ptp_print(ndo, cp, length);
514 			break;
515 		case PT_SOMEIP:
516 			udpipaddr_print(ndo, ip, sport, dport);
517 			someip_print(ndo, cp, length);
518 			break;
519 		case PT_DOMAIN:
520 			udpipaddr_print(ndo, ip, sport, dport);
521 			/* over_tcp: FALSE, is_mdns: FALSE */
522 			domain_print(ndo, cp, length, FALSE, FALSE);
523 			break;
524 		}
525 		return;
526 	}
527 
528 	udpipaddr_print(ndo, ip, sport, dport);
529 	if (!ndo->ndo_qflag) {
530 		const struct sunrpc_msg *rp;
531 		enum sunrpc_msg_type direction;
532 
533 		rp = (const struct sunrpc_msg *)cp;
534 		if (ND_TTEST_4(rp->rm_direction)) {
535 			direction = (enum sunrpc_msg_type) GET_BE_U_4(rp->rm_direction);
536 			if (dport == NFS_PORT && direction == SUNRPC_CALL) {
537 				ND_PRINT("NFS request xid %u ",
538 					 GET_BE_U_4(rp->rm_xid));
539 				nfsreq_noaddr_print(ndo, (const u_char *)rp, length,
540 				    (const u_char *)ip);
541 				return;
542 			}
543 			if (sport == NFS_PORT && direction == SUNRPC_REPLY) {
544 				ND_PRINT("NFS reply xid %u ",
545 					 GET_BE_U_4(rp->rm_xid));
546 				nfsreply_noaddr_print(ndo, (const u_char *)rp, length,
547 				    (const u_char *)ip);
548 				return;
549 			}
550 #ifdef notdef
551 			if (dport == SUNRPC_PORT && direction == SUNRPC_CALL) {
552 				sunrpc_print((const u_char *)rp, length, (const u_char *)ip);
553 				return;
554 			}
555 #endif
556 		}
557 	}
558 
559 	if (ndo->ndo_vflag && !ndo->ndo_Kflag && !fragmented) {
560 		/* Check the checksum, if possible. */
561 		uint16_t sum, udp_sum;
562 
563 		/*
564 		 * XXX - do this even if vflag == 1?
565 		 * TCP does, and we do so for UDP-over-IPv6.
566 		 */
567 		if (IP_V(ip) == 4 && (ndo->ndo_vflag > 1)) {
568 			udp_sum = GET_BE_U_2(up->uh_sum);
569 			if (udp_sum == 0) {
570 				ND_PRINT("[no cksum] ");
571 			} else if (ND_TTEST_LEN(cp, length)) {
572 				sum = udp_cksum(ndo, ip, up, length + sizeof(struct udphdr));
573 
574 				if (sum != 0) {
575 					ND_PRINT("[bad udp cksum 0x%04x -> 0x%04x!] ",
576 					    udp_sum,
577 					    in_cksum_shouldbe(udp_sum, sum));
578 				} else
579 					ND_PRINT("[udp sum ok] ");
580 			}
581 		}
582 		else if (IP_V(ip) == 6) {
583 			/* for IPv6, UDP checksum is mandatory */
584 			if (ND_TTEST_LEN(cp, length)) {
585 				sum = udp6_cksum(ndo, ip6, up, length + sizeof(struct udphdr));
586 				udp_sum = GET_BE_U_2(up->uh_sum);
587 
588 				if (sum != 0) {
589 					ND_PRINT("[bad udp cksum 0x%04x -> 0x%04x!] ",
590 					    udp_sum,
591 					    in_cksum_shouldbe(udp_sum, sum));
592 				} else
593 					ND_PRINT("[udp sum ok] ");
594 			}
595 		}
596 	}
597 
598 	if (!ndo->ndo_qflag) {
599 		if (IS_SRC_OR_DST_PORT(NAMESERVER_PORT))
600 			/* over_tcp: FALSE, is_mdns: FALSE */
601 			domain_print(ndo, cp, length, FALSE, FALSE);
602 		else if (IS_SRC_OR_DST_PORT(MULTICASTDNS_PORT))
603 			/* over_tcp: FALSE, is_mdns: TRUE */
604 			domain_print(ndo, cp, length, FALSE, TRUE);
605 		else if (IS_SRC_OR_DST_PORT(TIMED_PORT))
606 			timed_print(ndo, (const u_char *)cp);
607 		else if (IS_SRC_OR_DST_PORT(TFTP_PORT))
608 			tftp_print(ndo, cp, length);
609 		else if (IS_SRC_OR_DST_PORT(BOOTPC_PORT) || IS_SRC_OR_DST_PORT(BOOTPS_PORT))
610 			bootp_print(ndo, cp, length);
611 		else if (IS_SRC_OR_DST_PORT(RIP_PORT))
612 			rip_print(ndo, cp, length);
613 		else if (IS_SRC_OR_DST_PORT(AODV_PORT))
614 			aodv_print(ndo, cp, length,
615 			    ip6 != NULL);
616 		else if (IS_SRC_OR_DST_PORT(ISAKMP_PORT))
617 			 isakmp_print(ndo, cp, length, bp2);
618 		else if (IS_SRC_OR_DST_PORT(ISAKMP_PORT_NATT))
619 			 isakmp_rfc3948_print(ndo, cp, length, bp2, IP_V(ip), fragmented, ttl_hl);
620 		else if (IS_SRC_OR_DST_PORT(ISAKMP_PORT_USER1) || IS_SRC_OR_DST_PORT(ISAKMP_PORT_USER2))
621 			isakmp_print(ndo, cp, length, bp2);
622 		else if (IS_SRC_OR_DST_PORT(SNMP_PORT) || IS_SRC_OR_DST_PORT(SNMPTRAP_PORT))
623 			snmp_print(ndo, cp, length);
624 		else if (IS_SRC_OR_DST_PORT(NTP_PORT))
625 			ntp_print(ndo, cp, length);
626 		else if (IS_SRC_OR_DST_PORT(KERBEROS_PORT) || IS_SRC_OR_DST_PORT(KERBEROS_SEC_PORT))
627 			krb_print(ndo, (const u_char *)cp);
628 		else if (IS_SRC_OR_DST_PORT(L2TP_PORT))
629 			l2tp_print(ndo, cp, length);
630 #ifdef ENABLE_SMB
631 		else if (IS_SRC_OR_DST_PORT(NETBIOS_NS_PORT))
632 			nbt_udp137_print(ndo, cp, length);
633 		else if (IS_SRC_OR_DST_PORT(NETBIOS_DGRAM_PORT))
634 			nbt_udp138_print(ndo, cp, length);
635 #endif
636 		else if (dport == VAT_PORT)
637 			vat_print(ndo, cp, length);
638 		else if (IS_SRC_OR_DST_PORT(ZEPHYR_SRV_PORT) || IS_SRC_OR_DST_PORT(ZEPHYR_CLT_PORT))
639 			zephyr_print(ndo, cp, length);
640 		/*
641 		 * Since there are 10 possible ports to check, I think
642 		 * a <> test would be more efficient
643 		 */
644 		else if ((sport >= RX_PORT_LOW && sport <= RX_PORT_HIGH) ||
645 			 (dport >= RX_PORT_LOW && dport <= RX_PORT_HIGH))
646 			rx_print(ndo, cp, length, sport, dport,
647 				 (const u_char *) ip);
648 		else if (IS_SRC_OR_DST_PORT(RIPNG_PORT))
649 			ripng_print(ndo, cp, length);
650 		else if (IS_SRC_OR_DST_PORT(DHCP6_SERV_PORT) || IS_SRC_OR_DST_PORT(DHCP6_CLI_PORT))
651 			dhcp6_print(ndo, cp, length);
652 		else if (IS_SRC_OR_DST_PORT(AHCP_PORT))
653 			ahcp_print(ndo, cp, length);
654 		else if (IS_SRC_OR_DST_PORT(BABEL_PORT) || IS_SRC_OR_DST_PORT(BABEL_PORT_OLD))
655 			babel_print(ndo, cp, length);
656 		else if (IS_SRC_OR_DST_PORT(HNCP_PORT))
657 			hncp_print(ndo, cp, length);
658 		/*
659 		 * Kludge in test for whiteboard packets.
660 		 */
661 		else if (dport == WB_PORT)
662 			wb_print(ndo, cp, length);
663 		else if (IS_SRC_OR_DST_PORT(CISCO_AUTORP_PORT))
664 			cisco_autorp_print(ndo, cp, length);
665 		else if (IS_SRC_OR_DST_PORT(RADIUS_PORT) ||
666 			 IS_SRC_OR_DST_PORT(RADIUS_NEW_PORT) ||
667 			 IS_SRC_OR_DST_PORT(RADIUS_ACCOUNTING_PORT) ||
668 			 IS_SRC_OR_DST_PORT(RADIUS_NEW_ACCOUNTING_PORT) ||
669 			 IS_SRC_OR_DST_PORT(RADIUS_CISCO_COA_PORT) ||
670 			 IS_SRC_OR_DST_PORT(RADIUS_COA_PORT) )
671 			radius_print(ndo, cp, length);
672 		else if (dport == HSRP_PORT)
673 			hsrp_print(ndo, cp, length);
674 		else if (IS_SRC_OR_DST_PORT(LWRES_PORT))
675 			lwres_print(ndo, cp, length);
676 		else if (IS_SRC_OR_DST_PORT(LDP_PORT))
677 			ldp_print(ndo, cp, length);
678 		else if (IS_SRC_OR_DST_PORT(OLSR_PORT))
679 			olsr_print(ndo, cp, length,
680 					(IP_V(ip) == 6) ? 1 : 0);
681 		else if (IS_SRC_OR_DST_PORT(MPLS_LSP_PING_PORT))
682 			lspping_print(ndo, cp, length);
683 		else if (sport == BCM_LI_PORT)
684 			bcm_li_print(ndo, cp, length);
685 		else if (dport == BFD_CONTROL_PORT ||
686 			 dport == BFD_MULTIHOP_PORT ||
687 			 dport == BFD_LAG_PORT ||
688 			 dport == BFD_ECHO_PORT )
689 			bfd_print(ndo, cp, length, dport);
690 		else if (IS_SRC_OR_DST_PORT(LMP_PORT))
691 			lmp_print(ndo, cp, length);
692 		else if (IS_SRC_OR_DST_PORT(VQP_PORT))
693 			vqp_print(ndo, cp, length);
694 		else if (IS_SRC_OR_DST_PORT(SFLOW_PORT))
695 			sflow_print(ndo, cp, length);
696 		else if (dport == LWAPP_CONTROL_PORT)
697 			lwapp_control_print(ndo, cp, length, 1);
698 		else if (sport == LWAPP_CONTROL_PORT)
699 			lwapp_control_print(ndo, cp, length, 0);
700 		else if (IS_SRC_OR_DST_PORT(LWAPP_DATA_PORT))
701 			lwapp_data_print(ndo, cp, length);
702 		else if (IS_SRC_OR_DST_PORT(SIP_PORT))
703 			sip_print(ndo, cp, length);
704 		else if (IS_SRC_OR_DST_PORT(SYSLOG_PORT))
705 			syslog_print(ndo, cp, length);
706 		else if (IS_SRC_OR_DST_PORT(OTV_PORT))
707 			otv_print(ndo, cp, length);
708 		else if (IS_SRC_OR_DST_PORT(VXLAN_PORT))
709 			vxlan_print(ndo, cp, length);
710 		else if (dport == GENEVE_PORT)
711 			geneve_print(ndo, cp, length);
712 		else if (IS_SRC_OR_DST_PORT(LISP_CONTROL_PORT))
713 			lisp_print(ndo, cp, length);
714 		else if (IS_SRC_OR_DST_PORT(VXLAN_GPE_PORT))
715 			vxlan_gpe_print(ndo, cp, length);
716 		else if (IS_SRC_OR_DST_PORT(ZEP_PORT))
717 			zep_print(ndo, cp, length);
718 		else if (IS_SRC_OR_DST_PORT(MPLS_PORT))
719 			mpls_print(ndo, cp, length);
720 		else if (ND_TTEST_1(((const struct LAP *)cp)->type) &&
721 			 GET_U_1(((const struct LAP *)cp)->type) == lapDDP &&
722 			 (atalk_port(sport) || atalk_port(dport))) {
723 			if (ndo->ndo_vflag)
724 				ND_PRINT("kip ");
725 			llap_print(ndo, cp, length);
726 		} else if (IS_SRC_OR_DST_PORT(PTP_EVENT_PORT) ||
727 			IS_SRC_OR_DST_PORT(PTP_GENERAL_PORT)) {
728 			ptp_print(ndo, cp, length);
729 		} else if (IS_SRC_OR_DST_PORT(SOMEIP_PORT))
730 			someip_print(ndo, cp, length);
731 		else {
732 			if (ulen > length && !fragmented)
733 				ND_PRINT("UDP, bad length %u > %u",
734 				    ulen, length);
735 			else
736 				ND_PRINT("UDP, length %u", ulen);
737 		}
738 	} else {
739 		if (ulen > length && !fragmented)
740 			ND_PRINT("UDP, bad length %u > %u",
741 			    ulen, length);
742 		else
743 			ND_PRINT("UDP, length %u", ulen);
744 	}
745 	return;
746 
747 trunc:
748 	nd_print_trunc(ndo);
749 }
750