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