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