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