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