]> The Tcpdump Group git mirrors - tcpdump/blob - print-dccp.c
On Solaris, for 64-bit builds, use the 64-bit pcap-config.
[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
332 /* checksum calculation */
333 if (ndo->ndo_vflag && ND_TTEST_LEN(bp, len)) {
334 uint16_t sum = 0, dccp_sum;
335
336 dccp_sum = GET_BE_U_2(dh->dccph_checksum);
337 ND_PRINT("cksum 0x%04x ", dccp_sum);
338 if (IP_V(ip) == 4)
339 sum = dccp_cksum(ndo, ip, dh, len);
340 else if (IP_V(ip) == 6)
341 sum = dccp6_cksum(ndo, ip6, dh, len);
342 if (sum != 0)
343 ND_PRINT("(incorrect -> 0x%04x)",in_cksum_shouldbe(dccp_sum, sum));
344 else
345 ND_PRINT("(correct)");
346 }
347
348 if (ndo->ndo_vflag)
349 ND_PRINT(")");
350 ND_PRINT(" ");
351
352 dccph_type = DCCPH_TYPE(dh);
353 switch (dccph_type) {
354 case DCCP_PKT_REQUEST: {
355 const struct dccp_hdr_request *dhr =
356 (const struct dccp_hdr_request *)(bp + fixed_hdrlen);
357 fixed_hdrlen += 4;
358 if (len < fixed_hdrlen) {
359 ND_PRINT("truncated-%s - %u bytes missing!",
360 tok2str(dccp_pkt_type_str, "", dccph_type),
361 fixed_hdrlen - len);
362 return;
363 }
364 ND_TCHECK_SIZE(dhr);
365 ND_PRINT("%s (service=%u) ",
366 tok2str(dccp_pkt_type_str, "", dccph_type),
367 GET_BE_U_4(dhr->dccph_req_service));
368 break;
369 }
370 case DCCP_PKT_RESPONSE: {
371 const struct dccp_hdr_response *dhr =
372 (const struct dccp_hdr_response *)(bp + fixed_hdrlen);
373 fixed_hdrlen += 12;
374 if (len < fixed_hdrlen) {
375 ND_PRINT("truncated-%s - %u bytes missing!",
376 tok2str(dccp_pkt_type_str, "", dccph_type),
377 fixed_hdrlen - len);
378 return;
379 }
380 ND_TCHECK_SIZE(dhr);
381 ND_PRINT("%s (service=%u) ",
382 tok2str(dccp_pkt_type_str, "", dccph_type),
383 GET_BE_U_4(dhr->dccph_resp_service));
384 break;
385 }
386 case DCCP_PKT_DATA:
387 ND_PRINT("%s ", tok2str(dccp_pkt_type_str, "", dccph_type));
388 break;
389 case DCCP_PKT_ACK: {
390 fixed_hdrlen += 8;
391 if (len < fixed_hdrlen) {
392 ND_PRINT("truncated-%s - %u bytes missing!",
393 tok2str(dccp_pkt_type_str, "", dccph_type),
394 fixed_hdrlen - len);
395 return;
396 }
397 ND_PRINT("%s ", tok2str(dccp_pkt_type_str, "", dccph_type));
398 break;
399 }
400 case DCCP_PKT_DATAACK: {
401 fixed_hdrlen += 8;
402 if (len < fixed_hdrlen) {
403 ND_PRINT("truncated-%s - %u bytes missing!",
404 tok2str(dccp_pkt_type_str, "", dccph_type),
405 fixed_hdrlen - len);
406 return;
407 }
408 ND_PRINT("%s ", tok2str(dccp_pkt_type_str, "", dccph_type));
409 break;
410 }
411 case DCCP_PKT_CLOSEREQ:
412 fixed_hdrlen += 8;
413 if (len < fixed_hdrlen) {
414 ND_PRINT("truncated-%s - %u bytes missing!",
415 tok2str(dccp_pkt_type_str, "", dccph_type),
416 fixed_hdrlen - len);
417 return;
418 }
419 ND_PRINT("%s ", tok2str(dccp_pkt_type_str, "", dccph_type));
420 break;
421 case DCCP_PKT_CLOSE:
422 fixed_hdrlen += 8;
423 if (len < fixed_hdrlen) {
424 ND_PRINT("truncated-%s - %u bytes missing!",
425 tok2str(dccp_pkt_type_str, "", dccph_type),
426 fixed_hdrlen - len);
427 return;
428 }
429 ND_PRINT("%s ", tok2str(dccp_pkt_type_str, "", dccph_type));
430 break;
431 case DCCP_PKT_RESET: {
432 const struct dccp_hdr_reset *dhr =
433 (const struct dccp_hdr_reset *)(bp + fixed_hdrlen);
434 fixed_hdrlen += 12;
435 if (len < fixed_hdrlen) {
436 ND_PRINT("truncated-%s - %u bytes missing!",
437 tok2str(dccp_pkt_type_str, "", dccph_type),
438 fixed_hdrlen - len);
439 return;
440 }
441 ND_TCHECK_SIZE(dhr);
442 ND_PRINT("%s (code=%s) ",
443 tok2str(dccp_pkt_type_str, "", dccph_type),
444 tok2str(dccp_reset_code_str, "invalid", GET_U_1(dhr->dccph_reset_code)));
445 break;
446 }
447 case DCCP_PKT_SYNC:
448 fixed_hdrlen += 8;
449 if (len < fixed_hdrlen) {
450 ND_PRINT("truncated-%s - %u bytes missing!",
451 tok2str(dccp_pkt_type_str, "", dccph_type),
452 fixed_hdrlen - len);
453 return;
454 }
455 ND_PRINT("%s ", tok2str(dccp_pkt_type_str, "", dccph_type));
456 break;
457 case DCCP_PKT_SYNCACK:
458 fixed_hdrlen += 8;
459 if (len < fixed_hdrlen) {
460 ND_PRINT("truncated-%s - %u bytes missing!",
461 tok2str(dccp_pkt_type_str, "", dccph_type),
462 fixed_hdrlen - len);
463 return;
464 }
465 ND_PRINT("%s ", tok2str(dccp_pkt_type_str, "", dccph_type));
466 break;
467 default:
468 ND_PRINT("%s ", tok2str(dccp_pkt_type_str, "unknown-type-%u", dccph_type));
469 break;
470 }
471
472 if ((DCCPH_TYPE(dh) != DCCP_PKT_DATA) &&
473 (DCCPH_TYPE(dh) != DCCP_PKT_REQUEST))
474 dccp_print_ack_no(ndo, bp);
475
476 if (ndo->ndo_vflag < 2)
477 return;
478
479 ND_PRINT("seq %" PRIu64, dccp_seqno(ndo, bp));
480
481 /* process options */
482 if (hlen > fixed_hdrlen){
483 u_int optlen;
484 cp = bp + fixed_hdrlen;
485 ND_PRINT(" <");
486
487 hlen -= fixed_hdrlen;
488 while(1){
489 optlen = dccp_print_option(ndo, cp, hlen);
490 if (!optlen)
491 break;
492 if (hlen <= optlen)
493 break;
494 hlen -= optlen;
495 cp += optlen;
496 ND_PRINT(", ");
497 }
498 ND_PRINT(">");
499 }
500 return;
501 trunc:
502 nd_print_trunc(ndo);
503 }
504
505 enum dccp_option_type {
506 DCCP_OPTION_PADDING = 0,
507 DCCP_OPTION_MANDATORY = 1,
508 DCCP_OPTION_SLOW_RECEIVER = 2,
509 DCCP_OPTION_CHANGE_L = 32,
510 DCCP_OPTION_CONFIRM_L = 33,
511 DCCP_OPTION_CHANGE_R = 34,
512 DCCP_OPTION_CONFIRM_R = 35,
513 DCCP_OPTION_INIT_COOKIE = 36,
514 DCCP_OPTION_NDP_COUNT = 37,
515 DCCP_OPTION_ACK_VECTOR_NONCE_0 = 38,
516 DCCP_OPTION_ACK_VECTOR_NONCE_1 = 39,
517 DCCP_OPTION_DATA_DROPPED = 40,
518 DCCP_OPTION_TIMESTAMP = 41,
519 DCCP_OPTION_TIMESTAMP_ECHO = 42,
520 DCCP_OPTION_ELAPSED_TIME = 43,
521 DCCP_OPTION_DATA_CHECKSUM = 44
522 };
523
524 static const struct tok dccp_option_values[] = {
525 { DCCP_OPTION_PADDING, "nop" },
526 { DCCP_OPTION_MANDATORY, "mandatory" },
527 { DCCP_OPTION_SLOW_RECEIVER, "slowreceiver" },
528 { DCCP_OPTION_CHANGE_L, "change_l" },
529 { DCCP_OPTION_CONFIRM_L, "confirm_l" },
530 { DCCP_OPTION_CHANGE_R, "change_r" },
531 { DCCP_OPTION_CONFIRM_R, "confirm_r" },
532 { DCCP_OPTION_INIT_COOKIE, "initcookie" },
533 { DCCP_OPTION_NDP_COUNT, "ndp_count" },
534 { DCCP_OPTION_ACK_VECTOR_NONCE_0, "ack_vector0" },
535 { DCCP_OPTION_ACK_VECTOR_NONCE_1, "ack_vector1" },
536 { DCCP_OPTION_DATA_DROPPED, "data_dropped" },
537 { DCCP_OPTION_TIMESTAMP, "timestamp" },
538 { DCCP_OPTION_TIMESTAMP_ECHO, "timestamp_echo" },
539 { DCCP_OPTION_ELAPSED_TIME, "elapsed_time" },
540 { DCCP_OPTION_DATA_CHECKSUM, "data_checksum" },
541 { 0, NULL }
542 };
543
544 static u_int
545 dccp_print_option(netdissect_options *ndo, const u_char *option, u_int hlen)
546 {
547 uint8_t optlen, i;
548
549 if (GET_U_1(option) >= 32) {
550 optlen = GET_U_1(option + 1);
551 if (optlen < 2) {
552 if (GET_U_1(option) >= 128)
553 ND_PRINT("CCID option %u optlen too short",
554 GET_U_1(option));
555 else
556 ND_PRINT("%s optlen too short",
557 tok2str(dccp_option_values, "Option %u", GET_U_1(option)));
558 return 0;
559 }
560 } else
561 optlen = 1;
562
563 if (hlen < optlen) {
564 if (GET_U_1(option) >= 128)
565 ND_PRINT("CCID option %u optlen goes past header length",
566 GET_U_1(option));
567 else
568 ND_PRINT("%s optlen goes past header length",
569 tok2str(dccp_option_values, "Option %u", GET_U_1(option)));
570 return 0;
571 }
572 ND_TCHECK_LEN(option, optlen);
573
574 if (GET_U_1(option) >= 128) {
575 ND_PRINT("CCID option %u", GET_U_1(option));
576 switch (optlen) {
577 case 4:
578 ND_PRINT(" %u", GET_BE_U_2(option + 2));
579 break;
580 case 6:
581 ND_PRINT(" %u", GET_BE_U_4(option + 2));
582 break;
583 default:
584 break;
585 }
586 } else {
587 ND_PRINT("%s",
588 tok2str(dccp_option_values, "Option %u", GET_U_1(option)));
589 switch (GET_U_1(option)) {
590 case DCCP_OPTION_CHANGE_L:
591 case DCCP_OPTION_CONFIRM_L:
592 case DCCP_OPTION_CHANGE_R:
593 case DCCP_OPTION_CONFIRM_R:
594 if (optlen < 3) {
595 ND_PRINT(" optlen too short");
596 return optlen;
597 }
598 ND_PRINT(" %s", tok2str(dccp_feature_num_str,
599 "invalid (%u)", GET_U_1(option + 2)));
600 for (i = 0; i < optlen - 3; i++)
601 ND_PRINT(" %u", GET_U_1(option + 3 + i));
602 break;
603 case DCCP_OPTION_INIT_COOKIE:
604 if (optlen > 2) {
605 ND_PRINT(" 0x");
606 for (i = 0; i < optlen - 2; i++)
607 ND_PRINT("%02x",
608 GET_U_1(option + 2 + i));
609 }
610 break;
611 case DCCP_OPTION_NDP_COUNT:
612 for (i = 0; i < optlen - 2; i++)
613 ND_PRINT(" %u", GET_U_1(option + 2 + i));
614 break;
615 case DCCP_OPTION_ACK_VECTOR_NONCE_0:
616 if (optlen > 2) {
617 ND_PRINT(" 0x");
618 for (i = 0; i < optlen - 2; i++)
619 ND_PRINT("%02x",
620 GET_U_1(option + 2 + i));
621 }
622 break;
623 case DCCP_OPTION_ACK_VECTOR_NONCE_1:
624 if (optlen > 2) {
625 ND_PRINT(" 0x");
626 for (i = 0; i < optlen - 2; i++)
627 ND_PRINT("%02x",
628 GET_U_1(option + 2 + i));
629 }
630 break;
631 case DCCP_OPTION_DATA_DROPPED:
632 if (optlen > 2) {
633 ND_PRINT(" 0x");
634 for (i = 0; i < optlen - 2; i++)
635 ND_PRINT("%02x",
636 GET_U_1(option + 2 + i));
637 }
638 break;
639 case DCCP_OPTION_TIMESTAMP:
640 /*
641 * 13.1. Timestamp Option
642 *
643 * +--------+--------+--------+--------+--------+--------+
644 * |00101001|00000110| Timestamp Value |
645 * +--------+--------+--------+--------+--------+--------+
646 * Type=41 Length=6
647 */
648 if (optlen == 6)
649 ND_PRINT(" %u", GET_BE_U_4(option + 2));
650 else
651 ND_PRINT(" [optlen != 6]");
652 break;
653 case DCCP_OPTION_TIMESTAMP_ECHO:
654 /*
655 * 13.3. Timestamp Echo Option
656 *
657 * +--------+--------+--------+--------+--------+--------+
658 * |00101010|00000110| Timestamp Echo |
659 * +--------+--------+--------+--------+--------+--------+
660 * Type=42 Len=6
661 *
662 * +--------+--------+------- ... -------+--------+--------+
663 * |00101010|00001000| Timestamp Echo | Elapsed Time |
664 * +--------+--------+------- ... -------+--------+--------+
665 * Type=42 Len=8 (4 bytes)
666 *
667 * +--------+--------+------- ... -------+------- ... -------+
668 * |00101010|00001010| Timestamp Echo | Elapsed Time |
669 * +--------+--------+------- ... -------+------- ... -------+
670 * Type=42 Len=10 (4 bytes) (4 bytes)
671 */
672 switch (optlen) {
673 case 6:
674 ND_PRINT(" %u", GET_BE_U_4(option + 2));
675 break;
676 case 8:
677 ND_PRINT(" %u", GET_BE_U_4(option + 2));
678 ND_PRINT(" (elapsed time %u)",
679 GET_BE_U_2(option + 6));
680 break;
681 case 10:
682 ND_PRINT(" %u", GET_BE_U_4(option + 2));
683 ND_PRINT(" (elapsed time %u)",
684 GET_BE_U_4(option + 6));
685 break;
686 default:
687 ND_PRINT(" [optlen != 6 or 8 or 10]");
688 break;
689 }
690 break;
691 case DCCP_OPTION_ELAPSED_TIME:
692 if (optlen == 6)
693 ND_PRINT(" %u", GET_BE_U_4(option + 2));
694 else if (optlen == 4)
695 ND_PRINT(" %u", GET_BE_U_2(option + 2));
696 else
697 ND_PRINT(" [optlen != 4 or 6]");
698 break;
699 case DCCP_OPTION_DATA_CHECKSUM:
700 if (optlen > 2) {
701 ND_PRINT(" ");
702 for (i = 0; i < optlen - 2; i++)
703 ND_PRINT("%02x",
704 GET_U_1(option + 2 + i));
705 }
706 break;
707 }
708 }
709
710 return optlen;
711 trunc:
712 nd_print_trunc(ndo);
713 return 0;
714 }