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