]> The Tcpdump Group git mirrors - tcpdump/blob - print-dccp.c
6ad4027292f65f0ecf84fc5cbf1bb1cffb603b4d
[tcpdump] / print-dccp.c
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
10 /* \summary: Datagram Congestion Control Protocol (DCCP) printer */
11
12 /* specification: RFC 4340 */
13
14 #ifdef HAVE_CONFIG_H
15 #include <config.h>
16 #endif
17
18 #include "netdissect-stdinc.h"
19
20 #include "netdissect.h"
21 #include "addrtoname.h"
22 #include "extract.h"
23 #include "ip.h"
24 #include "ip6.h"
25 #include "ipproto.h"
26
27 /* RFC4340: Datagram Congestion Control Protocol (DCCP) */
28
29 /**
30 * struct dccp_hdr - generic part of DCCP packet header, with a 24-bit
31 * sequence number
32 *
33 * @dccph_sport - Relevant port on the endpoint that sent this packet
34 * @dccph_dport - Relevant port on the other endpoint
35 * @dccph_doff - Data Offset from the start of the DCCP header, in 32-bit words
36 * @dccph_ccval - Used by the HC-Sender CCID
37 * @dccph_cscov - Parts of the packet that are covered by the Checksum field
38 * @dccph_checksum - Internet checksum, depends on dccph_cscov
39 * @dccph_x - 0 = 24 bit sequence number, 1 = 48
40 * @dccph_type - packet type, see DCCP_PKT_ prefixed macros
41 * @dccph_seq - 24-bit sequence number
42 */
43 struct dccp_hdr {
44 nd_uint16_t dccph_sport,
45 dccph_dport;
46 nd_uint8_t dccph_doff;
47 nd_uint8_t dccph_ccval_cscov;
48 nd_uint16_t dccph_checksum;
49 nd_uint8_t dccph_xtr;
50 nd_uint24_t dccph_seq;
51 };
52
53 /**
54 * struct dccp_hdr_ext - generic part of DCCP packet header, with a 48-bit
55 * sequence number
56 *
57 * @dccph_sport - Relevant port on the endpoint that sent this packet
58 * @dccph_dport - Relevant port on the other endpoint
59 * @dccph_doff - Data Offset from the start of the DCCP header, in 32-bit words
60 * @dccph_ccval - Used by the HC-Sender CCID
61 * @dccph_cscov - Parts of the packet that are covered by the Checksum field
62 * @dccph_checksum - Internet checksum, depends on dccph_cscov
63 * @dccph_x - 0 = 24 bit sequence number, 1 = 48
64 * @dccph_type - packet type, see DCCP_PKT_ prefixed macros
65 * @dccph_seq - 48-bit sequence number
66 */
67 struct dccp_hdr_ext {
68 nd_uint16_t dccph_sport,
69 dccph_dport;
70 nd_uint8_t dccph_doff;
71 nd_uint8_t dccph_ccval_cscov;
72 nd_uint16_t dccph_checksum;
73 nd_uint8_t dccph_xtr;
74 nd_uint8_t reserved;
75 nd_uint48_t dccph_seq;
76 };
77
78 #define DCCPH_CCVAL(dh) ((GET_U_1((dh)->dccph_ccval_cscov) >> 4) & 0xF)
79 #define DCCPH_CSCOV(dh) (GET_U_1((dh)->dccph_ccval_cscov) & 0xF)
80
81 #define DCCPH_X(dh) (GET_U_1((dh)->dccph_xtr) & 1)
82 #define DCCPH_TYPE(dh) ((GET_U_1((dh)->dccph_xtr) >> 1) & 0xF)
83
84 /**
85 * struct dccp_hdr_request - Connection initiation request header
86 *
87 * @dccph_req_service - Service to which the client app wants to connect
88 */
89 struct dccp_hdr_request {
90 nd_uint32_t dccph_req_service;
91 };
92
93 /**
94 * struct dccp_hdr_response - Connection initiation response header
95 *
96 * @dccph_resp_ack - 48 bit ack number, contains GSR
97 * @dccph_resp_service - Echoes the Service Code on a received DCCP-Request
98 */
99 struct dccp_hdr_response {
100 nd_uint64_t dccph_resp_ack; /* always 8 bytes, first 2 reserved */
101 nd_uint32_t dccph_resp_service;
102 };
103
104 /**
105 * struct dccp_hdr_reset - Unconditionally shut down a connection
106 *
107 * @dccph_resp_ack - 48 bit ack number
108 * @dccph_reset_service - Echoes the Service Code on a received DCCP-Request
109 */
110 struct dccp_hdr_reset {
111 nd_uint64_t dccph_reset_ack; /* always 8 bytes, first 2 reserved */
112 nd_uint8_t dccph_reset_code;
113 nd_uint8_t dccph_reset_data1;
114 nd_uint8_t dccph_reset_data2;
115 nd_uint8_t dccph_reset_data3;
116 };
117
118 enum dccp_pkt_type {
119 DCCP_PKT_REQUEST = 0,
120 DCCP_PKT_RESPONSE,
121 DCCP_PKT_DATA,
122 DCCP_PKT_ACK,
123 DCCP_PKT_DATAACK,
124 DCCP_PKT_CLOSEREQ,
125 DCCP_PKT_CLOSE,
126 DCCP_PKT_RESET,
127 DCCP_PKT_SYNC,
128 DCCP_PKT_SYNCACK
129 };
130
131 static const struct tok dccp_pkt_type_str[] = {
132 { DCCP_PKT_REQUEST, "DCCP-Request" },
133 { DCCP_PKT_RESPONSE, "DCCP-Response" },
134 { DCCP_PKT_DATA, "DCCP-Data" },
135 { DCCP_PKT_ACK, "DCCP-Ack" },
136 { DCCP_PKT_DATAACK, "DCCP-DataAck" },
137 { DCCP_PKT_CLOSEREQ, "DCCP-CloseReq" },
138 { DCCP_PKT_CLOSE, "DCCP-Close" },
139 { DCCP_PKT_RESET, "DCCP-Reset" },
140 { DCCP_PKT_SYNC, "DCCP-Sync" },
141 { DCCP_PKT_SYNCACK, "DCCP-SyncAck" },
142 { 0, NULL}
143 };
144
145 enum dccp_reset_codes {
146 DCCP_RESET_CODE_UNSPECIFIED = 0,
147 DCCP_RESET_CODE_CLOSED,
148 DCCP_RESET_CODE_ABORTED,
149 DCCP_RESET_CODE_NO_CONNECTION,
150 DCCP_RESET_CODE_PACKET_ERROR,
151 DCCP_RESET_CODE_OPTION_ERROR,
152 DCCP_RESET_CODE_MANDATORY_ERROR,
153 DCCP_RESET_CODE_CONNECTION_REFUSED,
154 DCCP_RESET_CODE_BAD_SERVICE_CODE,
155 DCCP_RESET_CODE_TOO_BUSY,
156 DCCP_RESET_CODE_BAD_INIT_COOKIE,
157 DCCP_RESET_CODE_AGGRESSION_PENALTY,
158 };
159
160 static const struct tok dccp_reset_code_str[] = {
161 { DCCP_RESET_CODE_UNSPECIFIED, "unspecified" },
162 { DCCP_RESET_CODE_CLOSED, "closed" },
163 { DCCP_RESET_CODE_ABORTED, "aborted" },
164 { DCCP_RESET_CODE_NO_CONNECTION, "no_connection" },
165 { DCCP_RESET_CODE_PACKET_ERROR, "packet_error" },
166 { DCCP_RESET_CODE_OPTION_ERROR, "option_error" },
167 { DCCP_RESET_CODE_MANDATORY_ERROR, "mandatory_error" },
168 { DCCP_RESET_CODE_CONNECTION_REFUSED, "connection_refused" },
169 { DCCP_RESET_CODE_BAD_SERVICE_CODE, "bad_service_code" },
170 { DCCP_RESET_CODE_TOO_BUSY, "too_busy" },
171 { DCCP_RESET_CODE_BAD_INIT_COOKIE, "bad_init_cookie" },
172 { DCCP_RESET_CODE_AGGRESSION_PENALTY, "aggression_penalty" },
173 { 0, NULL }
174 };
175
176 static const struct tok dccp_feature_num_str[] = {
177 { 0, "reserved" },
178 { 1, "ccid" },
179 { 2, "allow_short_seqno" },
180 { 3, "sequence_window" },
181 { 4, "ecn_incapable" },
182 { 5, "ack_ratio" },
183 { 6, "send_ack_vector" },
184 { 7, "send_ndp_count" },
185 { 8, "minimum checksum coverage" },
186 { 9, "check data checksum" },
187 { 0, NULL }
188 };
189
190 static u_int
191 dccp_csum_coverage(netdissect_options *ndo,
192 const struct dccp_hdr *dh, u_int len)
193 {
194 u_int cov;
195
196 if (DCCPH_CSCOV(dh) == 0)
197 return len;
198 cov = (GET_U_1(dh->dccph_doff) + DCCPH_CSCOV(dh) - 1) * sizeof(uint32_t);
199 return (cov > len)? len : cov;
200 }
201
202 static uint16_t dccp_cksum(netdissect_options *ndo, const struct ip *ip,
203 const struct dccp_hdr *dh, u_int len)
204 {
205 return nextproto4_cksum(ndo, ip, (const uint8_t *)(const void *)dh, len,
206 dccp_csum_coverage(ndo, dh, len), IPPROTO_DCCP);
207 }
208
209 static uint16_t dccp6_cksum(netdissect_options *ndo, const struct ip6_hdr *ip6,
210 const struct dccp_hdr *dh, u_int len)
211 {
212 return nextproto6_cksum(ndo, ip6, (const uint8_t *)(const void *)dh, len,
213 dccp_csum_coverage(ndo, dh, len), IPPROTO_DCCP);
214 }
215
216 static uint64_t
217 dccp_seqno(netdissect_options *ndo, const u_char *bp)
218 {
219 const struct dccp_hdr *dh = (const struct dccp_hdr *)bp;
220 uint64_t seqno;
221
222 if (DCCPH_X(dh) != 0) {
223 const struct dccp_hdr_ext *dhx = (const struct dccp_hdr_ext *)bp;
224 seqno = GET_BE_U_6(dhx->dccph_seq);
225 } else {
226 seqno = GET_BE_U_3(dh->dccph_seq);
227 }
228
229 return seqno;
230 }
231
232 static unsigned int
233 dccp_basic_hdr_len(netdissect_options *ndo, const struct dccp_hdr *dh)
234 {
235 return DCCPH_X(dh) ? sizeof(struct dccp_hdr_ext) : sizeof(struct dccp_hdr);
236 }
237
238 static void dccp_print_ack_no(netdissect_options *ndo, const u_char *bp)
239 {
240 const struct dccp_hdr *dh = (const struct dccp_hdr *)bp;
241 const u_char *ackp = bp + dccp_basic_hdr_len(ndo, dh);
242 uint64_t ackno;
243
244 if (DCCPH_X(dh) != 0) {
245 ackno = GET_BE_U_6(ackp + 2);
246 } else {
247 ackno = GET_BE_U_3(ackp + 1);
248 }
249
250 ND_PRINT("(ack=%" PRIu64 ") ", ackno);
251 }
252
253 static u_int dccp_print_option(netdissect_options *, const u_char *, u_int);
254
255 /**
256 * dccp_print - show dccp packet
257 * @bp - beginning of dccp packet
258 * @data2 - beginning of enclosing
259 * @len - length of ip packet
260 */
261 void
262 dccp_print(netdissect_options *ndo, const u_char *bp, const u_char *data2,
263 u_int len)
264 {
265 const struct dccp_hdr *dh;
266 const struct ip *ip;
267 const struct ip6_hdr *ip6;
268 const u_char *cp;
269 u_short sport, dport;
270 u_int hlen;
271 u_int fixed_hdrlen;
272 uint8_t dccph_type;
273
274 ndo->ndo_protocol = "dccp";
275 dh = (const struct dccp_hdr *)bp;
276
277 ip = (const struct ip *)data2;
278 if (IP_V(ip) == 6)
279 ip6 = (const struct ip6_hdr *)data2;
280 else
281 ip6 = NULL;
282
283 /* make sure we have enough data to look at the X bit */
284 cp = (const u_char *)(dh + 1);
285 if (cp > ndo->ndo_snapend)
286 goto trunc;
287 if (len < sizeof(struct dccp_hdr)) {
288 ND_PRINT("truncated-dccp - %zu bytes missing!",
289 sizeof(struct dccp_hdr) - len);
290 return;
291 }
292
293 /* get the length of the generic header */
294 fixed_hdrlen = dccp_basic_hdr_len(ndo, dh);
295 if (len < fixed_hdrlen) {
296 ND_PRINT("truncated-dccp - %u bytes missing!",
297 fixed_hdrlen - len);
298 return;
299 }
300 ND_TCHECK_LEN(dh, fixed_hdrlen);
301
302 sport = GET_BE_U_2(dh->dccph_sport);
303 dport = GET_BE_U_2(dh->dccph_dport);
304 hlen = GET_U_1(dh->dccph_doff) * 4;
305
306 if (ip6) {
307 ND_PRINT("%s.%u > %s.%u: ",
308 GET_IP6ADDR_STRING(ip6->ip6_src), sport,
309 GET_IP6ADDR_STRING(ip6->ip6_dst), dport);
310 } else {
311 ND_PRINT("%s.%u > %s.%u: ",
312 GET_IPADDR_STRING(ip->ip_src), sport,
313 GET_IPADDR_STRING(ip->ip_dst), dport);
314 }
315
316 nd_print_protocol_caps(ndo);
317
318 if (ndo->ndo_qflag) {
319 ND_PRINT(" %u", len - hlen);
320 if (hlen > len) {
321 ND_PRINT(" [bad hdr length %u - too long, > %u]",
322 hlen, len);
323 }
324 return;
325 }
326
327 /* other variables in generic header */
328 if (ndo->ndo_vflag) {
329 ND_PRINT(" (CCVal %u, CsCov %u", DCCPH_CCVAL(dh), DCCPH_CSCOV(dh));
330
331 /* checksum calculation */
332 if (ND_TTEST_LEN(bp, len)) {
333 uint16_t sum = 0, dccp_sum;
334
335 dccp_sum = GET_BE_U_2(dh->dccph_checksum);
336 ND_PRINT(", cksum 0x%04x ", dccp_sum);
337 if (IP_V(ip) == 4)
338 sum = dccp_cksum(ndo, ip, dh, len);
339 else if (IP_V(ip) == 6)
340 sum = dccp6_cksum(ndo, ip6, dh, len);
341 if (sum != 0)
342 ND_PRINT("(incorrect -> 0x%04x)",in_cksum_shouldbe(dccp_sum, sum));
343 else
344 ND_PRINT("(correct)");
345 }
346 ND_PRINT(")");
347 }
348 ND_PRINT(" ");
349
350 dccph_type = DCCPH_TYPE(dh);
351 switch (dccph_type) {
352 case DCCP_PKT_REQUEST: {
353 const struct dccp_hdr_request *dhr =
354 (const struct dccp_hdr_request *)(bp + fixed_hdrlen);
355 fixed_hdrlen += 4;
356 if (len < fixed_hdrlen) {
357 ND_PRINT("truncated-%s - %u bytes missing!",
358 tok2str(dccp_pkt_type_str, "", dccph_type),
359 fixed_hdrlen - len);
360 return;
361 }
362 ND_TCHECK_SIZE(dhr);
363 ND_PRINT("%s (service=%u) ",
364 tok2str(dccp_pkt_type_str, "", dccph_type),
365 GET_BE_U_4(dhr->dccph_req_service));
366 break;
367 }
368 case DCCP_PKT_RESPONSE: {
369 const struct dccp_hdr_response *dhr =
370 (const struct dccp_hdr_response *)(bp + fixed_hdrlen);
371 fixed_hdrlen += 12;
372 if (len < fixed_hdrlen) {
373 ND_PRINT("truncated-%s - %u bytes missing!",
374 tok2str(dccp_pkt_type_str, "", dccph_type),
375 fixed_hdrlen - len);
376 return;
377 }
378 ND_TCHECK_SIZE(dhr);
379 ND_PRINT("%s (service=%u) ",
380 tok2str(dccp_pkt_type_str, "", dccph_type),
381 GET_BE_U_4(dhr->dccph_resp_service));
382 break;
383 }
384 case DCCP_PKT_DATA:
385 ND_PRINT("%s ", tok2str(dccp_pkt_type_str, "", dccph_type));
386 break;
387 case DCCP_PKT_ACK: {
388 fixed_hdrlen += 8;
389 if (len < fixed_hdrlen) {
390 ND_PRINT("truncated-%s - %u bytes missing!",
391 tok2str(dccp_pkt_type_str, "", dccph_type),
392 fixed_hdrlen - len);
393 return;
394 }
395 ND_PRINT("%s ", tok2str(dccp_pkt_type_str, "", dccph_type));
396 break;
397 }
398 case DCCP_PKT_DATAACK: {
399 fixed_hdrlen += 8;
400 if (len < fixed_hdrlen) {
401 ND_PRINT("truncated-%s - %u bytes missing!",
402 tok2str(dccp_pkt_type_str, "", dccph_type),
403 fixed_hdrlen - len);
404 return;
405 }
406 ND_PRINT("%s ", tok2str(dccp_pkt_type_str, "", dccph_type));
407 break;
408 }
409 case DCCP_PKT_CLOSEREQ:
410 fixed_hdrlen += 8;
411 if (len < fixed_hdrlen) {
412 ND_PRINT("truncated-%s - %u bytes missing!",
413 tok2str(dccp_pkt_type_str, "", dccph_type),
414 fixed_hdrlen - len);
415 return;
416 }
417 ND_PRINT("%s ", tok2str(dccp_pkt_type_str, "", dccph_type));
418 break;
419 case DCCP_PKT_CLOSE:
420 fixed_hdrlen += 8;
421 if (len < fixed_hdrlen) {
422 ND_PRINT("truncated-%s - %u bytes missing!",
423 tok2str(dccp_pkt_type_str, "", dccph_type),
424 fixed_hdrlen - len);
425 return;
426 }
427 ND_PRINT("%s ", tok2str(dccp_pkt_type_str, "", dccph_type));
428 break;
429 case DCCP_PKT_RESET: {
430 const struct dccp_hdr_reset *dhr =
431 (const struct dccp_hdr_reset *)(bp + fixed_hdrlen);
432 fixed_hdrlen += 12;
433 if (len < fixed_hdrlen) {
434 ND_PRINT("truncated-%s - %u bytes missing!",
435 tok2str(dccp_pkt_type_str, "", dccph_type),
436 fixed_hdrlen - len);
437 return;
438 }
439 ND_TCHECK_SIZE(dhr);
440 ND_PRINT("%s (code=%s) ",
441 tok2str(dccp_pkt_type_str, "", dccph_type),
442 tok2str(dccp_reset_code_str, "invalid", GET_U_1(dhr->dccph_reset_code)));
443 break;
444 }
445 case DCCP_PKT_SYNC:
446 fixed_hdrlen += 8;
447 if (len < fixed_hdrlen) {
448 ND_PRINT("truncated-%s - %u bytes missing!",
449 tok2str(dccp_pkt_type_str, "", dccph_type),
450 fixed_hdrlen - len);
451 return;
452 }
453 ND_PRINT("%s ", tok2str(dccp_pkt_type_str, "", dccph_type));
454 break;
455 case DCCP_PKT_SYNCACK:
456 fixed_hdrlen += 8;
457 if (len < fixed_hdrlen) {
458 ND_PRINT("truncated-%s - %u bytes missing!",
459 tok2str(dccp_pkt_type_str, "", dccph_type),
460 fixed_hdrlen - len);
461 return;
462 }
463 ND_PRINT("%s ", tok2str(dccp_pkt_type_str, "", dccph_type));
464 break;
465 default:
466 ND_PRINT("%s ", tok2str(dccp_pkt_type_str, "unknown-type-%u", dccph_type));
467 break;
468 }
469
470 if ((DCCPH_TYPE(dh) != DCCP_PKT_DATA) &&
471 (DCCPH_TYPE(dh) != DCCP_PKT_REQUEST))
472 dccp_print_ack_no(ndo, bp);
473
474 if (ndo->ndo_vflag < 2)
475 return;
476
477 ND_PRINT("seq %" PRIu64, dccp_seqno(ndo, bp));
478
479 /* process options */
480 if (hlen > fixed_hdrlen){
481 u_int optlen;
482 cp = bp + fixed_hdrlen;
483 ND_PRINT(" <");
484
485 hlen -= fixed_hdrlen;
486 while(1){
487 optlen = dccp_print_option(ndo, cp, hlen);
488 if (!optlen)
489 break;
490 if (hlen <= optlen)
491 break;
492 hlen -= optlen;
493 cp += optlen;
494 ND_PRINT(", ");
495 }
496 ND_PRINT(">");
497 }
498 return;
499 trunc:
500 nd_print_trunc(ndo);
501 }
502
503 enum dccp_option_type {
504 DCCP_OPTION_PADDING = 0,
505 DCCP_OPTION_MANDATORY = 1,
506 DCCP_OPTION_SLOW_RECEIVER = 2,
507 DCCP_OPTION_CHANGE_L = 32,
508 DCCP_OPTION_CONFIRM_L = 33,
509 DCCP_OPTION_CHANGE_R = 34,
510 DCCP_OPTION_CONFIRM_R = 35,
511 DCCP_OPTION_INIT_COOKIE = 36,
512 DCCP_OPTION_NDP_COUNT = 37,
513 DCCP_OPTION_ACK_VECTOR_NONCE_0 = 38,
514 DCCP_OPTION_ACK_VECTOR_NONCE_1 = 39,
515 DCCP_OPTION_DATA_DROPPED = 40,
516 DCCP_OPTION_TIMESTAMP = 41,
517 DCCP_OPTION_TIMESTAMP_ECHO = 42,
518 DCCP_OPTION_ELAPSED_TIME = 43,
519 DCCP_OPTION_DATA_CHECKSUM = 44
520 };
521
522 static const struct tok dccp_option_values[] = {
523 { DCCP_OPTION_PADDING, "nop" },
524 { DCCP_OPTION_MANDATORY, "mandatory" },
525 { DCCP_OPTION_SLOW_RECEIVER, "slowreceiver" },
526 { DCCP_OPTION_CHANGE_L, "change_l" },
527 { DCCP_OPTION_CONFIRM_L, "confirm_l" },
528 { DCCP_OPTION_CHANGE_R, "change_r" },
529 { DCCP_OPTION_CONFIRM_R, "confirm_r" },
530 { DCCP_OPTION_INIT_COOKIE, "initcookie" },
531 { DCCP_OPTION_NDP_COUNT, "ndp_count" },
532 { DCCP_OPTION_ACK_VECTOR_NONCE_0, "ack_vector0" },
533 { DCCP_OPTION_ACK_VECTOR_NONCE_1, "ack_vector1" },
534 { DCCP_OPTION_DATA_DROPPED, "data_dropped" },
535 { DCCP_OPTION_TIMESTAMP, "timestamp" },
536 { DCCP_OPTION_TIMESTAMP_ECHO, "timestamp_echo" },
537 { DCCP_OPTION_ELAPSED_TIME, "elapsed_time" },
538 { DCCP_OPTION_DATA_CHECKSUM, "data_checksum" },
539 { 0, NULL }
540 };
541
542 static u_int
543 dccp_print_option(netdissect_options *ndo, const u_char *bp, u_int hlen)
544 {
545 uint8_t option, optlen, i;
546
547 option = GET_U_1(bp);
548 if (option >= 32) {
549 optlen = GET_U_1(bp + 1);
550 if (optlen < 2) {
551 if (option >= 128)
552 ND_PRINT("CCID option %u optlen too short",
553 option);
554 else
555 ND_PRINT("%s optlen too short",
556 tok2str(dccp_option_values,
557 "Option %u", option));
558 return 0;
559 }
560 } else
561 optlen = 1;
562
563 if (hlen < optlen) {
564 if (option >= 128)
565 ND_PRINT("CCID option %u optlen goes past header length",
566 option);
567 else
568 ND_PRINT("%s optlen goes past header length",
569 tok2str(dccp_option_values, "Option %u",
570 option));
571 return 0;
572 }
573 ND_TCHECK_LEN(bp, optlen);
574
575 if (option >= 128) {
576 ND_PRINT("CCID option %u", option);
577 switch (optlen) {
578 case 4:
579 ND_PRINT(" %u", GET_BE_U_2(bp + 2));
580 break;
581 case 6:
582 ND_PRINT(" %u", GET_BE_U_4(bp + 2));
583 break;
584 default:
585 break;
586 }
587 } else {
588 ND_PRINT("%s",
589 tok2str(dccp_option_values, "Option %u", option));
590 switch (option) {
591 case DCCP_OPTION_CHANGE_L:
592 case DCCP_OPTION_CONFIRM_L:
593 case DCCP_OPTION_CHANGE_R:
594 case DCCP_OPTION_CONFIRM_R:
595 if (optlen < 3) {
596 ND_PRINT(" optlen too short");
597 return optlen;
598 }
599 ND_PRINT(" %s", tok2str(dccp_feature_num_str,
600 "invalid (%u)", GET_U_1(bp + 2)));
601 for (i = 0; i < optlen - 3; i++)
602 ND_PRINT(" %u", GET_U_1(bp + 3 + i));
603 break;
604 case DCCP_OPTION_INIT_COOKIE:
605 if (optlen > 2) {
606 ND_PRINT(" 0x");
607 for (i = 0; i < optlen - 2; i++)
608 ND_PRINT("%02x",
609 GET_U_1(bp + 2 + i));
610 }
611 break;
612 case DCCP_OPTION_NDP_COUNT:
613 for (i = 0; i < optlen - 2; i++)
614 ND_PRINT(" %u", GET_U_1(bp + 2 + i));
615 break;
616 case DCCP_OPTION_ACK_VECTOR_NONCE_0:
617 if (optlen > 2) {
618 ND_PRINT(" 0x");
619 for (i = 0; i < optlen - 2; i++)
620 ND_PRINT("%02x",
621 GET_U_1(bp + 2 + i));
622 }
623 break;
624 case DCCP_OPTION_ACK_VECTOR_NONCE_1:
625 if (optlen > 2) {
626 ND_PRINT(" 0x");
627 for (i = 0; i < optlen - 2; i++)
628 ND_PRINT("%02x",
629 GET_U_1(bp + 2 + i));
630 }
631 break;
632 case DCCP_OPTION_DATA_DROPPED:
633 if (optlen > 2) {
634 ND_PRINT(" 0x");
635 for (i = 0; i < optlen - 2; i++)
636 ND_PRINT("%02x",
637 GET_U_1(bp + 2 + i));
638 }
639 break;
640 case DCCP_OPTION_TIMESTAMP:
641 /*
642 * 13.1. Timestamp Option
643 *
644 * +--------+--------+--------+--------+--------+--------+
645 * |00101001|00000110| Timestamp Value |
646 * +--------+--------+--------+--------+--------+--------+
647 * Type=41 Length=6
648 */
649 if (optlen == 6)
650 ND_PRINT(" %u", GET_BE_U_4(bp + 2));
651 else
652 ND_PRINT(" [optlen != 6]");
653 break;
654 case DCCP_OPTION_TIMESTAMP_ECHO:
655 /*
656 * 13.3. Timestamp Echo Option
657 *
658 * +--------+--------+--------+--------+--------+--------+
659 * |00101010|00000110| Timestamp Echo |
660 * +--------+--------+--------+--------+--------+--------+
661 * Type=42 Len=6
662 *
663 * +--------+--------+------- ... -------+--------+--------+
664 * |00101010|00001000| Timestamp Echo | Elapsed Time |
665 * +--------+--------+------- ... -------+--------+--------+
666 * Type=42 Len=8 (4 bytes)
667 *
668 * +--------+--------+------- ... -------+------- ... -------+
669 * |00101010|00001010| Timestamp Echo | Elapsed Time |
670 * +--------+--------+------- ... -------+------- ... -------+
671 * Type=42 Len=10 (4 bytes) (4 bytes)
672 */
673 switch (optlen) {
674 case 6:
675 ND_PRINT(" %u", GET_BE_U_4(bp + 2));
676 break;
677 case 8:
678 ND_PRINT(" %u", GET_BE_U_4(bp + 2));
679 ND_PRINT(" (elapsed time %u)",
680 GET_BE_U_2(bp + 6));
681 break;
682 case 10:
683 ND_PRINT(" %u", GET_BE_U_4(bp + 2));
684 ND_PRINT(" (elapsed time %u)",
685 GET_BE_U_4(bp + 6));
686 break;
687 default:
688 ND_PRINT(" [optlen != 6 or 8 or 10]");
689 break;
690 }
691 break;
692 case DCCP_OPTION_ELAPSED_TIME:
693 if (optlen == 6)
694 ND_PRINT(" %u", GET_BE_U_4(bp + 2));
695 else if (optlen == 4)
696 ND_PRINT(" %u", GET_BE_U_2(bp + 2));
697 else
698 ND_PRINT(" [optlen != 4 or 6]");
699 break;
700 case DCCP_OPTION_DATA_CHECKSUM:
701 if (optlen > 2) {
702 ND_PRINT(" ");
703 for (i = 0; i < optlen - 2; i++)
704 ND_PRINT("%02x",
705 GET_U_1(bp + 2 + i));
706 }
707 break;
708 }
709 }
710
711 return optlen;
712 trunc:
713 nd_print_trunc(ndo);
714 return 0;
715 }