print-dccp.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. /*
  2. * Copyright (C) Arnaldo Carvalho de Melo 2004
  3. * Copyright (C) Ian McDonald 2005
  4. * Copyright (C) Yoshifumi Nishida 2005
  5. *
  6. * This software may be distributed either under the terms of the
  7. * BSD-style license that accompanies tcpdump or the GNU GPL version 2
  8. */
  9. /* \summary: Datagram Congestion Control Protocol (DCCP) printer */
  10. #ifdef HAVE_CONFIG_H
  11. #include "config.h"
  12. #endif
  13. #include <netdissect-stdinc.h>
  14. #include <stdio.h>
  15. #include <string.h>
  16. #include "netdissect.h"
  17. #include "addrtoname.h"
  18. #include "extract.h"
  19. #include "ip.h"
  20. #include "ip6.h"
  21. #include "ipproto.h"
  22. /* RFC4340: Datagram Congestion Control Protocol (DCCP) */
  23. /**
  24. * struct dccp_hdr - generic part of DCCP packet header, with a 24-bit
  25. * sequence number
  26. *
  27. * @dccph_sport - Relevant port on the endpoint that sent this packet
  28. * @dccph_dport - Relevant port on the other endpoint
  29. * @dccph_doff - Data Offset from the start of the DCCP header, in 32-bit words
  30. * @dccph_ccval - Used by the HC-Sender CCID
  31. * @dccph_cscov - Parts of the packet that are covered by the Checksum field
  32. * @dccph_checksum - Internet checksum, depends on dccph_cscov
  33. * @dccph_x - 0 = 24 bit sequence number, 1 = 48
  34. * @dccph_type - packet type, see DCCP_PKT_ prefixed macros
  35. * @dccph_seq - 24-bit sequence number
  36. */
  37. struct dccp_hdr {
  38. uint16_t dccph_sport,
  39. dccph_dport;
  40. uint8_t dccph_doff;
  41. uint8_t dccph_ccval_cscov;
  42. uint16_t dccph_checksum;
  43. uint8_t dccph_xtr;
  44. uint8_t dccph_seq[3];
  45. } UNALIGNED;
  46. /**
  47. * struct dccp_hdr_ext - generic part of DCCP packet header, with a 48-bit
  48. * sequence number
  49. *
  50. * @dccph_sport - Relevant port on the endpoint that sent this packet
  51. * @dccph_dport - Relevant port on the other endpoint
  52. * @dccph_doff - Data Offset from the start of the DCCP header, in 32-bit words
  53. * @dccph_ccval - Used by the HC-Sender CCID
  54. * @dccph_cscov - Parts of the packet that are covered by the Checksum field
  55. * @dccph_checksum - Internet checksum, depends on dccph_cscov
  56. * @dccph_x - 0 = 24 bit sequence number, 1 = 48
  57. * @dccph_type - packet type, see DCCP_PKT_ prefixed macros
  58. * @dccph_seq - 48-bit sequence number
  59. */
  60. struct dccp_hdr_ext {
  61. uint16_t dccph_sport,
  62. dccph_dport;
  63. uint8_t dccph_doff;
  64. uint8_t dccph_ccval_cscov;
  65. uint16_t dccph_checksum;
  66. uint8_t dccph_xtr;
  67. uint8_t reserved;
  68. uint8_t dccph_seq[6];
  69. } UNALIGNED;
  70. #define DCCPH_CCVAL(dh) (((dh)->dccph_ccval_cscov >> 4) & 0xF)
  71. #define DCCPH_CSCOV(dh) (((dh)->dccph_ccval_cscov) & 0xF)
  72. #define DCCPH_X(dh) ((dh)->dccph_xtr & 1)
  73. #define DCCPH_TYPE(dh) (((dh)->dccph_xtr >> 1) & 0xF)
  74. /**
  75. * struct dccp_hdr_request - Conection initiation request header
  76. *
  77. * @dccph_req_service - Service to which the client app wants to connect
  78. */
  79. struct dccp_hdr_request {
  80. uint32_t dccph_req_service;
  81. } UNALIGNED;
  82. /**
  83. * struct dccp_hdr_response - Conection initiation response header
  84. *
  85. * @dccph_resp_ack - 48 bit ack number, contains GSR
  86. * @dccph_resp_service - Echoes the Service Code on a received DCCP-Request
  87. */
  88. struct dccp_hdr_response {
  89. uint8_t dccph_resp_ack[8]; /* always 8 bytes */
  90. uint32_t dccph_resp_service;
  91. } UNALIGNED;
  92. /**
  93. * struct dccp_hdr_reset - Unconditionally shut down a connection
  94. *
  95. * @dccph_resp_ack - 48 bit ack number
  96. * @dccph_reset_service - Echoes the Service Code on a received DCCP-Request
  97. */
  98. struct dccp_hdr_reset {
  99. uint8_t dccph_reset_ack[8]; /* always 8 bytes */
  100. uint8_t dccph_reset_code,
  101. dccph_reset_data[3];
  102. } UNALIGNED;
  103. enum dccp_pkt_type {
  104. DCCP_PKT_REQUEST = 0,
  105. DCCP_PKT_RESPONSE,
  106. DCCP_PKT_DATA,
  107. DCCP_PKT_ACK,
  108. DCCP_PKT_DATAACK,
  109. DCCP_PKT_CLOSEREQ,
  110. DCCP_PKT_CLOSE,
  111. DCCP_PKT_RESET,
  112. DCCP_PKT_SYNC,
  113. DCCP_PKT_SYNCACK
  114. };
  115. static const struct tok dccp_pkt_type_str[] = {
  116. { DCCP_PKT_REQUEST, "DCCP-Request" },
  117. { DCCP_PKT_RESPONSE, "DCCP-Response" },
  118. { DCCP_PKT_DATA, "DCCP-Data" },
  119. { DCCP_PKT_ACK, "DCCP-Ack" },
  120. { DCCP_PKT_DATAACK, "DCCP-DataAck" },
  121. { DCCP_PKT_CLOSEREQ, "DCCP-CloseReq" },
  122. { DCCP_PKT_CLOSE, "DCCP-Close" },
  123. { DCCP_PKT_RESET, "DCCP-Reset" },
  124. { DCCP_PKT_SYNC, "DCCP-Sync" },
  125. { DCCP_PKT_SYNCACK, "DCCP-SyncAck" },
  126. { 0, NULL}
  127. };
  128. enum dccp_reset_codes {
  129. DCCP_RESET_CODE_UNSPECIFIED = 0,
  130. DCCP_RESET_CODE_CLOSED,
  131. DCCP_RESET_CODE_ABORTED,
  132. DCCP_RESET_CODE_NO_CONNECTION,
  133. DCCP_RESET_CODE_PACKET_ERROR,
  134. DCCP_RESET_CODE_OPTION_ERROR,
  135. DCCP_RESET_CODE_MANDATORY_ERROR,
  136. DCCP_RESET_CODE_CONNECTION_REFUSED,
  137. DCCP_RESET_CODE_BAD_SERVICE_CODE,
  138. DCCP_RESET_CODE_TOO_BUSY,
  139. DCCP_RESET_CODE_BAD_INIT_COOKIE,
  140. DCCP_RESET_CODE_AGGRESSION_PENALTY,
  141. __DCCP_RESET_CODE_LAST
  142. };
  143. static const char tstr[] = "[|dccp]";
  144. static const char *dccp_reset_codes[] = {
  145. "unspecified",
  146. "closed",
  147. "aborted",
  148. "no_connection",
  149. "packet_error",
  150. "option_error",
  151. "mandatory_error",
  152. "connection_refused",
  153. "bad_service_code",
  154. "too_busy",
  155. "bad_init_cookie",
  156. "aggression_penalty",
  157. };
  158. static const char *dccp_feature_nums[] = {
  159. "reserved",
  160. "ccid",
  161. "allow_short_seqno",
  162. "sequence_window",
  163. "ecn_incapable",
  164. "ack_ratio",
  165. "send_ack_vector",
  166. "send_ndp_count",
  167. "minimum checksum coverage",
  168. "check data checksum",
  169. };
  170. static inline u_int dccp_csum_coverage(const struct dccp_hdr* dh, u_int len)
  171. {
  172. u_int cov;
  173. if (DCCPH_CSCOV(dh) == 0)
  174. return len;
  175. cov = (dh->dccph_doff + DCCPH_CSCOV(dh) - 1) * sizeof(uint32_t);
  176. return (cov > len)? len : cov;
  177. }
  178. static int dccp_cksum(netdissect_options *ndo, const struct ip *ip,
  179. const struct dccp_hdr *dh, u_int len)
  180. {
  181. return nextproto4_cksum(ndo, ip, (const uint8_t *)(const void *)dh, len,
  182. dccp_csum_coverage(dh, len), IPPROTO_DCCP);
  183. }
  184. static int dccp6_cksum(netdissect_options *ndo, const struct ip6_hdr *ip6,
  185. const struct dccp_hdr *dh, u_int len)
  186. {
  187. return nextproto6_cksum(ndo, ip6, (const uint8_t *)(const void *)dh, len,
  188. dccp_csum_coverage(dh, len), IPPROTO_DCCP);
  189. }
  190. static const char *dccp_reset_code(uint8_t code)
  191. {
  192. if (code >= __DCCP_RESET_CODE_LAST)
  193. return "invalid";
  194. return dccp_reset_codes[code];
  195. }
  196. static uint64_t dccp_seqno(const u_char *bp)
  197. {
  198. const struct dccp_hdr *dh = (const struct dccp_hdr *)bp;
  199. uint64_t seqno;
  200. if (DCCPH_X(dh) != 0) {
  201. const struct dccp_hdr_ext *dhx = (const struct dccp_hdr_ext *)bp;
  202. seqno = EXTRACT_48BITS(dhx->dccph_seq);
  203. } else {
  204. seqno = EXTRACT_24BITS(dh->dccph_seq);
  205. }
  206. return seqno;
  207. }
  208. static inline unsigned int dccp_basic_hdr_len(const struct dccp_hdr *dh)
  209. {
  210. return DCCPH_X(dh) ? sizeof(struct dccp_hdr_ext) : sizeof(struct dccp_hdr);
  211. }
  212. static void dccp_print_ack_no(netdissect_options *ndo, const u_char *bp)
  213. {
  214. const struct dccp_hdr *dh = (const struct dccp_hdr *)bp;
  215. const u_char *ackp = bp + dccp_basic_hdr_len(dh);
  216. uint64_t ackno;
  217. if (DCCPH_X(dh) != 0) {
  218. ND_TCHECK2(*ackp, 8);
  219. ackno = EXTRACT_48BITS(ackp + 2);
  220. } else {
  221. ND_TCHECK2(*ackp, 4);
  222. ackno = EXTRACT_24BITS(ackp + 1);
  223. }
  224. ND_PRINT((ndo, "(ack=%" PRIu64 ") ", ackno));
  225. trunc:
  226. return;
  227. }
  228. static int dccp_print_option(netdissect_options *, const u_char *, u_int);
  229. /**
  230. * dccp_print - show dccp packet
  231. * @bp - beginning of dccp packet
  232. * @data2 - beginning of enclosing
  233. * @len - lenght of ip packet
  234. */
  235. void dccp_print(netdissect_options *ndo, const u_char *bp, const u_char *data2,
  236. u_int len)
  237. {
  238. const struct dccp_hdr *dh;
  239. const struct ip *ip;
  240. const struct ip6_hdr *ip6;
  241. const u_char *cp;
  242. u_short sport, dport;
  243. u_int hlen;
  244. u_int fixed_hdrlen;
  245. uint8_t dccph_type;
  246. dh = (const struct dccp_hdr *)bp;
  247. ip = (const struct ip *)data2;
  248. if (IP_V(ip) == 6)
  249. ip6 = (const struct ip6_hdr *)data2;
  250. else
  251. ip6 = NULL;
  252. /* make sure we have enough data to look at the X bit */
  253. cp = (const u_char *)(dh + 1);
  254. if (cp > ndo->ndo_snapend) {
  255. ND_PRINT((ndo, "[Invalid packet|dccp]"));
  256. return;
  257. }
  258. if (len < sizeof(struct dccp_hdr)) {
  259. ND_PRINT((ndo, "truncated-dccp - %u bytes missing!",
  260. len - (u_int)sizeof(struct dccp_hdr)));
  261. return;
  262. }
  263. /* get the length of the generic header */
  264. fixed_hdrlen = dccp_basic_hdr_len(dh);
  265. if (len < fixed_hdrlen) {
  266. ND_PRINT((ndo, "truncated-dccp - %u bytes missing!",
  267. len - fixed_hdrlen));
  268. return;
  269. }
  270. ND_TCHECK2(*dh, fixed_hdrlen);
  271. sport = EXTRACT_16BITS(&dh->dccph_sport);
  272. dport = EXTRACT_16BITS(&dh->dccph_dport);
  273. hlen = dh->dccph_doff * 4;
  274. if (ip6) {
  275. ND_PRINT((ndo, "%s.%d > %s.%d: ",
  276. ip6addr_string(ndo, &ip6->ip6_src), sport,
  277. ip6addr_string(ndo, &ip6->ip6_dst), dport));
  278. } else {
  279. ND_PRINT((ndo, "%s.%d > %s.%d: ",
  280. ipaddr_string(ndo, &ip->ip_src), sport,
  281. ipaddr_string(ndo, &ip->ip_dst), dport));
  282. }
  283. ND_PRINT((ndo, "DCCP"));
  284. if (ndo->ndo_qflag) {
  285. ND_PRINT((ndo, " %d", len - hlen));
  286. if (hlen > len) {
  287. ND_PRINT((ndo, " [bad hdr length %u - too long, > %u]",
  288. hlen, len));
  289. }
  290. return;
  291. }
  292. /* other variables in generic header */
  293. if (ndo->ndo_vflag) {
  294. ND_PRINT((ndo, " (CCVal %d, CsCov %d, ", DCCPH_CCVAL(dh), DCCPH_CSCOV(dh)));
  295. }
  296. /* checksum calculation */
  297. if (ndo->ndo_vflag && ND_TTEST2(bp[0], len)) {
  298. uint16_t sum = 0, dccp_sum;
  299. dccp_sum = EXTRACT_16BITS(&dh->dccph_checksum);
  300. ND_PRINT((ndo, "cksum 0x%04x ", dccp_sum));
  301. if (IP_V(ip) == 4)
  302. sum = dccp_cksum(ndo, ip, dh, len);
  303. else if (IP_V(ip) == 6)
  304. sum = dccp6_cksum(ndo, ip6, dh, len);
  305. if (sum != 0)
  306. ND_PRINT((ndo, "(incorrect -> 0x%04x)",in_cksum_shouldbe(dccp_sum, sum)));
  307. else
  308. ND_PRINT((ndo, "(correct)"));
  309. }
  310. if (ndo->ndo_vflag)
  311. ND_PRINT((ndo, ")"));
  312. ND_PRINT((ndo, " "));
  313. dccph_type = DCCPH_TYPE(dh);
  314. switch (dccph_type) {
  315. case DCCP_PKT_REQUEST: {
  316. const struct dccp_hdr_request *dhr =
  317. (const struct dccp_hdr_request *)(bp + fixed_hdrlen);
  318. fixed_hdrlen += 4;
  319. if (len < fixed_hdrlen) {
  320. ND_PRINT((ndo, "truncated-%s - %u bytes missing!",
  321. tok2str(dccp_pkt_type_str, "", dccph_type),
  322. len - fixed_hdrlen));
  323. return;
  324. }
  325. ND_TCHECK(*dhr);
  326. ND_PRINT((ndo, "%s (service=%d) ",
  327. tok2str(dccp_pkt_type_str, "", dccph_type),
  328. EXTRACT_32BITS(&dhr->dccph_req_service)));
  329. break;
  330. }
  331. case DCCP_PKT_RESPONSE: {
  332. const struct dccp_hdr_response *dhr =
  333. (const struct dccp_hdr_response *)(bp + fixed_hdrlen);
  334. fixed_hdrlen += 12;
  335. if (len < fixed_hdrlen) {
  336. ND_PRINT((ndo, "truncated-%s - %u bytes missing!",
  337. tok2str(dccp_pkt_type_str, "", dccph_type),
  338. len - fixed_hdrlen));
  339. return;
  340. }
  341. ND_TCHECK(*dhr);
  342. ND_PRINT((ndo, "%s (service=%d) ",
  343. tok2str(dccp_pkt_type_str, "", dccph_type),
  344. EXTRACT_32BITS(&dhr->dccph_resp_service)));
  345. break;
  346. }
  347. case DCCP_PKT_DATA:
  348. ND_PRINT((ndo, "%s ", tok2str(dccp_pkt_type_str, "", dccph_type)));
  349. break;
  350. case DCCP_PKT_ACK: {
  351. fixed_hdrlen += 8;
  352. if (len < fixed_hdrlen) {
  353. ND_PRINT((ndo, "truncated-%s - %u bytes missing!",
  354. tok2str(dccp_pkt_type_str, "", dccph_type),
  355. len - fixed_hdrlen));
  356. return;
  357. }
  358. ND_PRINT((ndo, "%s ", tok2str(dccp_pkt_type_str, "", dccph_type)));
  359. break;
  360. }
  361. case DCCP_PKT_DATAACK: {
  362. fixed_hdrlen += 8;
  363. if (len < fixed_hdrlen) {
  364. ND_PRINT((ndo, "truncated-%s - %u bytes missing!",
  365. tok2str(dccp_pkt_type_str, "", dccph_type),
  366. len - fixed_hdrlen));
  367. return;
  368. }
  369. ND_PRINT((ndo, "%s ", tok2str(dccp_pkt_type_str, "", dccph_type)));
  370. break;
  371. }
  372. case DCCP_PKT_CLOSEREQ:
  373. fixed_hdrlen += 8;
  374. if (len < fixed_hdrlen) {
  375. ND_PRINT((ndo, "truncated-%s - %u bytes missing!",
  376. tok2str(dccp_pkt_type_str, "", dccph_type),
  377. len - fixed_hdrlen));
  378. return;
  379. }
  380. ND_PRINT((ndo, "%s ", tok2str(dccp_pkt_type_str, "", dccph_type)));
  381. break;
  382. case DCCP_PKT_CLOSE:
  383. fixed_hdrlen += 8;
  384. if (len < fixed_hdrlen) {
  385. ND_PRINT((ndo, "truncated-%s - %u bytes missing!",
  386. tok2str(dccp_pkt_type_str, "", dccph_type),
  387. len - fixed_hdrlen));
  388. return;
  389. }
  390. ND_PRINT((ndo, "%s ", tok2str(dccp_pkt_type_str, "", dccph_type)));
  391. break;
  392. case DCCP_PKT_RESET: {
  393. const struct dccp_hdr_reset *dhr =
  394. (const struct dccp_hdr_reset *)(bp + fixed_hdrlen);
  395. fixed_hdrlen += 12;
  396. if (len < fixed_hdrlen) {
  397. ND_PRINT((ndo, "truncated-%s - %u bytes missing!",
  398. tok2str(dccp_pkt_type_str, "", dccph_type),
  399. len - fixed_hdrlen));
  400. return;
  401. }
  402. ND_TCHECK(*dhr);
  403. ND_PRINT((ndo, "%s (code=%s) ",
  404. tok2str(dccp_pkt_type_str, "", dccph_type),
  405. dccp_reset_code(dhr->dccph_reset_code)));
  406. break;
  407. }
  408. case DCCP_PKT_SYNC:
  409. fixed_hdrlen += 8;
  410. if (len < fixed_hdrlen) {
  411. ND_PRINT((ndo, "truncated-%s - %u bytes missing!",
  412. tok2str(dccp_pkt_type_str, "", dccph_type),
  413. len - fixed_hdrlen));
  414. return;
  415. }
  416. ND_PRINT((ndo, "%s ", tok2str(dccp_pkt_type_str, "", dccph_type)));
  417. break;
  418. case DCCP_PKT_SYNCACK:
  419. fixed_hdrlen += 8;
  420. if (len < fixed_hdrlen) {
  421. ND_PRINT((ndo, "truncated-%s - %u bytes missing!",
  422. tok2str(dccp_pkt_type_str, "", dccph_type),
  423. len - fixed_hdrlen));
  424. return;
  425. }
  426. ND_PRINT((ndo, "%s ", tok2str(dccp_pkt_type_str, "", dccph_type)));
  427. break;
  428. default:
  429. ND_PRINT((ndo, "%s ", tok2str(dccp_pkt_type_str, "unknown-type-%u", dccph_type)));
  430. break;
  431. }
  432. if ((DCCPH_TYPE(dh) != DCCP_PKT_DATA) &&
  433. (DCCPH_TYPE(dh) != DCCP_PKT_REQUEST))
  434. dccp_print_ack_no(ndo, bp);
  435. if (ndo->ndo_vflag < 2)
  436. return;
  437. ND_PRINT((ndo, "seq %" PRIu64, dccp_seqno(bp)));
  438. /* process options */
  439. if (hlen > fixed_hdrlen){
  440. u_int optlen;
  441. cp = bp + fixed_hdrlen;
  442. ND_PRINT((ndo, " <"));
  443. hlen -= fixed_hdrlen;
  444. while(1){
  445. optlen = dccp_print_option(ndo, cp, hlen);
  446. if (!optlen)
  447. break;
  448. if (hlen <= optlen)
  449. break;
  450. hlen -= optlen;
  451. cp += optlen;
  452. ND_PRINT((ndo, ", "));
  453. }
  454. ND_PRINT((ndo, ">"));
  455. }
  456. return;
  457. trunc:
  458. ND_PRINT((ndo, "%s", tstr));
  459. return;
  460. }
  461. static const struct tok dccp_option_values[] = {
  462. { 0, "nop" },
  463. { 1, "mandatory" },
  464. { 2, "slowreceiver" },
  465. { 32, "change_l" },
  466. { 33, "confirm_l" },
  467. { 34, "change_r" },
  468. { 35, "confirm_r" },
  469. { 36, "initcookie" },
  470. { 37, "ndp_count" },
  471. { 38, "ack_vector0" },
  472. { 39, "ack_vector1" },
  473. { 40, "data_dropped" },
  474. { 41, "timestamp" },
  475. { 42, "timestamp_echo" },
  476. { 43, "elapsed_time" },
  477. { 44, "data_checksum" },
  478. { 0, NULL }
  479. };
  480. static int dccp_print_option(netdissect_options *ndo, const u_char *option, u_int hlen)
  481. {
  482. uint8_t optlen, i;
  483. ND_TCHECK(*option);
  484. if (*option >= 32) {
  485. ND_TCHECK(*(option+1));
  486. optlen = *(option +1);
  487. if (optlen < 2) {
  488. if (*option >= 128)
  489. ND_PRINT((ndo, "CCID option %u optlen too short", *option));
  490. else
  491. ND_PRINT((ndo, "%s optlen too short",
  492. tok2str(dccp_option_values, "Option %u", *option)));
  493. return 0;
  494. }
  495. } else
  496. optlen = 1;
  497. if (hlen < optlen) {
  498. if (*option >= 128)
  499. ND_PRINT((ndo, "CCID option %u optlen goes past header length",
  500. *option));
  501. else
  502. ND_PRINT((ndo, "%s optlen goes past header length",
  503. tok2str(dccp_option_values, "Option %u", *option)));
  504. return 0;
  505. }
  506. ND_TCHECK2(*option, optlen);
  507. if (*option >= 128) {
  508. ND_PRINT((ndo, "CCID option %d", *option));
  509. switch (optlen) {
  510. case 4:
  511. ND_PRINT((ndo, " %u", EXTRACT_16BITS(option + 2)));
  512. break;
  513. case 6:
  514. ND_PRINT((ndo, " %u", EXTRACT_32BITS(option + 2)));
  515. break;
  516. default:
  517. break;
  518. }
  519. } else {
  520. ND_PRINT((ndo, "%s", tok2str(dccp_option_values, "Option %u", *option)));
  521. switch (*option) {
  522. case 32:
  523. case 33:
  524. case 34:
  525. case 35:
  526. if (optlen < 3) {
  527. ND_PRINT((ndo, " optlen too short"));
  528. return optlen;
  529. }
  530. if (*(option + 2) < 10){
  531. ND_PRINT((ndo, " %s", dccp_feature_nums[*(option + 2)]));
  532. for (i = 0; i < optlen - 3; i++)
  533. ND_PRINT((ndo, " %d", *(option + 3 + i)));
  534. }
  535. break;
  536. case 36:
  537. if (optlen > 2) {
  538. ND_PRINT((ndo, " 0x"));
  539. for (i = 0; i < optlen - 2; i++)
  540. ND_PRINT((ndo, "%02x", *(option + 2 + i)));
  541. }
  542. break;
  543. case 37:
  544. for (i = 0; i < optlen - 2; i++)
  545. ND_PRINT((ndo, " %d", *(option + 2 + i)));
  546. break;
  547. case 38:
  548. if (optlen > 2) {
  549. ND_PRINT((ndo, " 0x"));
  550. for (i = 0; i < optlen - 2; i++)
  551. ND_PRINT((ndo, "%02x", *(option + 2 + i)));
  552. }
  553. break;
  554. case 39:
  555. if (optlen > 2) {
  556. ND_PRINT((ndo, " 0x"));
  557. for (i = 0; i < optlen - 2; i++)
  558. ND_PRINT((ndo, "%02x", *(option + 2 + i)));
  559. }
  560. break;
  561. case 40:
  562. if (optlen > 2) {
  563. ND_PRINT((ndo, " 0x"));
  564. for (i = 0; i < optlen - 2; i++)
  565. ND_PRINT((ndo, "%02x", *(option + 2 + i)));
  566. }
  567. break;
  568. case 41:
  569. if (optlen == 4)
  570. ND_PRINT((ndo, " %u", EXTRACT_32BITS(option + 2)));
  571. else
  572. ND_PRINT((ndo, " optlen != 4"));
  573. break;
  574. case 42:
  575. if (optlen == 4)
  576. ND_PRINT((ndo, " %u", EXTRACT_32BITS(option + 2)));
  577. else
  578. ND_PRINT((ndo, " optlen != 4"));
  579. break;
  580. case 43:
  581. if (optlen == 6)
  582. ND_PRINT((ndo, " %u", EXTRACT_32BITS(option + 2)));
  583. else if (optlen == 4)
  584. ND_PRINT((ndo, " %u", EXTRACT_16BITS(option + 2)));
  585. else
  586. ND_PRINT((ndo, " optlen != 4 or 6"));
  587. break;
  588. case 44:
  589. if (optlen > 2) {
  590. ND_PRINT((ndo, " "));
  591. for (i = 0; i < optlen - 2; i++)
  592. ND_PRINT((ndo, "%02x", *(option + 2 + i)));
  593. }
  594. break;
  595. }
  596. }
  597. return optlen;
  598. trunc:
  599. ND_PRINT((ndo, "%s", tstr));
  600. return 0;
  601. }