print-udp.c 21 KB

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