]>
The Tcpdump Group git mirrors - tcpdump/blob - print-forces.c
2 * Redistribution and use in source and binary forms, with or without
3 * modification, are permitted provided that: (1) source code
4 * distributions retain the above copyright notice and this paragraph
5 * in its entirety, and (2) distributions including binary code include
6 * the above copyright notice and this paragraph in its entirety in
7 * the documentation or other materials provided with the distribution.
8 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
9 * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
10 * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
11 * FOR A PARTICULAR PURPOSE.
13 * Copyright (c) 2009 Mojatatu Networks, Inc
21 #include <tcpdump-stdinc.h>
26 #include "interface.h"
34 prestlv_print(register const u_char
* pptr
, register u_int len
,
35 u_int16_t op_msk _U_
, int indent
)
37 struct forces_tlv
*tlv
= (struct forces_tlv
*)pptr
;
38 register const u_char
*tdp
= (u_char
*) TLV_DATA(tlv
);
39 struct res_val
*r
= (struct res_val
*)tdp
;
40 u_int16_t dlen
= len
- TLV_HDRL
;
43 printf("illegal RESULT-TLV: %d bytes! \n", dlen
);
47 if (r
->result
>= 0x18 && r
->result
<= 0xFE) {
48 printf("illegal reserved result code: 0x%x! \n", r
->result
);
53 char *ib
= indent_pr(indent
, 0);
54 printf("%s Result: %s (code 0x%x)\n", ib
,
55 tok2str(ForCES_errs
, NULL
, r
->result
), r
->result
);
61 fdatatlv_print(register const u_char
* pptr
, register u_int len
,
62 u_int16_t op_msk _U_
, int indent
)
64 struct forces_tlv
*tlv
= (struct forces_tlv
*)pptr
;
65 u_int tll
= len
- TLV_HDRL
;
66 register const u_char
*tdp
= (u_char
*) TLV_DATA(tlv
);
67 u_int16_t type
= EXTRACT_16BITS(&tlv
->type
);
68 if (type
!= F_TLV_FULD
) {
69 printf("Error: expecting FULLDATA!\n");
74 char *ib
= indent_pr(indent
+ 2, 1);
75 printf("%s[", &ib
[1]);
76 hex_print_with_offset(ib
, tdp
, tll
, 0);
77 printf("\n%s]\n", &ib
[1]);
83 sdatailv_print(register const u_char
* pptr
, register u_int len
,
84 u_int16_t op_msk _U_
, int indent
)
86 u_int tll
= len
- ILV_HDRL
;
87 struct forces_ilv
*ilv
= (struct forces_ilv
*)pptr
;
92 invilv
= ilv_valid(ilv
, tll
);
94 printf("Error: BAD ILV!\n");
98 register const u_char
*tdp
= (u_char
*) ILV_DATA(ilv
);
99 char *ib
= indent_pr(indent
, 1);
100 printf("\n%s SPARSEDATA: type %x length %d\n", &ib
[1],
101 EXTRACT_32BITS(&ilv
->type
),
102 EXTRACT_32BITS(&ilv
->length
));
103 printf("%s[", &ib
[1]);
104 hex_print_with_offset(ib
, tdp
, tll
, 0);
105 printf("\n%s]\n", &ib
[1]);
108 ilv
= GO_NXT_ILV(ilv
, tll
);
115 sdatatlv_print(register const u_char
* pptr
, register u_int len
,
116 u_int16_t op_msk
, int indent
)
118 struct forces_tlv
*tlv
= (struct forces_tlv
*)pptr
;
119 u_int tll
= len
- TLV_HDRL
;
120 register const u_char
*tdp
= (u_char
*) TLV_DATA(tlv
);
121 u_int16_t type
= EXTRACT_16BITS(&tlv
->type
);
122 if (type
!= F_TLV_SPAD
) {
123 printf("Error: expecting SPARSEDATA!\n");
127 return sdatailv_print(tdp
, tll
, op_msk
, indent
);
131 pkeyitlv_print(register const u_char
* pptr
, register u_int len
,
132 u_int16_t op_msk
, int indent
)
134 struct forces_tlv
*tlv
= (struct forces_tlv
*)pptr
;
135 register const u_char
*tdp
= (u_char
*) TLV_DATA(tlv
);
136 register const u_char
*dp
= tdp
+ 4;
137 struct forces_tlv
*kdtlv
= (struct forces_tlv
*)dp
;
138 u_int32_t id
= EXTRACT_32BITS(tdp
);
139 char *ib
= indent_pr(indent
, 0);
143 printf("%sKeyinfo: Key 0x%x\n", ib
, id
);
144 type
= EXTRACT_16BITS(&kdtlv
->type
);
145 invtlv
= tlv_valid(kdtlv
, len
);
148 printf("%s TLV type 0x%x len %d\n",
149 tok2str(ForCES_TLV_err
, NULL
, invtlv
), type
,
150 EXTRACT_16BITS(&kdtlv
->length
));
153 tll
= EXTRACT_16BITS(&kdtlv
->length
);
154 dp
= (u_char
*) TLV_DATA(kdtlv
);
155 return fdatatlv_print(dp
, tll
, op_msk
, indent
);
159 pdatacnt_print(register const u_char
* pptr
, register u_int len
,
160 u_int32_t IDcnt
, u_int16_t op_msk
, int indent
)
165 char *ib
= indent_pr(indent
, 0);
167 for (i
= 0; i
< IDcnt
; i
++) {
168 id
= EXTRACT_32BITS(pptr
);
170 printf("%s ID#%02u: %d\n", ib
, i
+ 1, id
);
175 struct forces_tlv
*pdtlv
= (struct forces_tlv
*)pptr
;
176 u_int16_t type
= EXTRACT_16BITS(&pdtlv
->type
);
177 u_int16_t tll
= EXTRACT_16BITS(&pdtlv
->length
) - TLV_HDRL
;
179 u_int aln
= F_ALN_LEN(EXTRACT_16BITS(&pdtlv
->length
));
181 int invtlv
= tlv_valid(pdtlv
, len
);
185 ("%s Outstanding bytes %d for TLV type 0x%x TLV len %d\n",
186 tok2str(ForCES_TLV_err
, NULL
, invtlv
), len
, type
,
187 EXTRACT_16BITS(&pdtlv
->length
));
190 if (aln
> EXTRACT_16BITS(&pdtlv
->length
)) {
193 ("Invalid padded pathdata TLV type 0x%x len %d missing %d pad bytes\n",
194 type
, EXTRACT_16BITS(&pdtlv
->length
), aln
- len
);
196 pad
= aln
- EXTRACT_16BITS(&pdtlv
->length
);
199 if (pd_valid(type
)) {
200 struct pdata_ops
*ops
= get_forces_pd(type
);
202 if (vflag
>= 3 && ops
->v
!= F_TLV_PDAT
) {
205 ("%s %s (Length %d DataLen %d pad %d Bytes)\n",
206 ib
, ops
->s
, EXTRACT_16BITS(&pdtlv
->length
),
210 ("%s %s (Length %d DataLen %d Bytes)\n",
211 ib
, ops
->s
, EXTRACT_16BITS(&pdtlv
->length
),
215 chk_op_type(type
, op_msk
, ops
->op_msk
);
217 rc
= ops
->print((const u_char
*)pdtlv
,
218 tll
+ pad
+ TLV_HDRL
, op_msk
,
221 printf("Invalid path data content type 0x%x len %d\n",
222 type
, EXTRACT_16BITS(&pdtlv
->length
));
224 if (EXTRACT_16BITS(&pdtlv
->length
)) {
225 hex_print_with_offset("Bad Data val\n\t [",
237 pdata_print(register const u_char
* pptr
, register u_int len
,
238 u_int16_t op_msk
, int indent
)
240 struct pathdata_h
*pdh
= (struct pathdata_h
*)pptr
;
241 char *ib
= indent_pr(indent
, 0);
244 printf("\n%sPathdata: Flags 0x%x ID count %d\n",
245 ib
, EXTRACT_16BITS(&pdh
->pflags
), EXTRACT_16BITS(&pdh
->pIDcnt
));
248 if (EXTRACT_16BITS(&pdh
->pflags
) & F_SELKEY
) {
251 pptr
+= sizeof(struct pathdata_h
);
252 len
-= sizeof(struct pathdata_h
);
253 minsize
= EXTRACT_16BITS(&pdh
->pIDcnt
) * 4;
255 printf("\t\t\ttruncated IDs expected %uB got %uB\n", minsize
,
257 hex_print_with_offset("\t\t\tID Data[", pptr
, len
, 0);
261 return pdatacnt_print(pptr
, len
, EXTRACT_16BITS(&pdh
->pIDcnt
), op_msk
, indent
);
265 genoptlv_print(register const u_char
* pptr
, register u_int len
,
266 u_int16_t op_msk
, int indent
)
268 struct forces_tlv
*pdtlv
= (struct forces_tlv
*)pptr
;
269 u_int16_t type
= EXTRACT_16BITS(&pdtlv
->type
);
270 int tll
= EXTRACT_16BITS(&pdtlv
->length
) - TLV_HDRL
;
271 int invtlv
= tlv_valid(pdtlv
, len
);
272 char *ib
= indent_pr(indent
, 0);
274 printf("genoptlvprint - %s TLV type 0x%x len %d\n",
275 tok2str(ForCES_TLV
, NULL
, type
), type
, EXTRACT_16BITS(&pdtlv
->length
));
277 register const u_char
*dp
= (u_char
*) TLV_DATA(pdtlv
);
278 if (!ttlv_valid(type
)) {
279 printf("%s TLV type 0x%x len %d\n",
280 tok2str(ForCES_TLV_err
, NULL
, invtlv
), type
,
281 EXTRACT_16BITS(&pdtlv
->length
));
285 printf("%s%s, length %d (data length %d Bytes)",
286 ib
, tok2str(ForCES_TLV
, NULL
, type
),
287 EXTRACT_16BITS(&pdtlv
->length
), tll
);
289 return pdata_print(dp
, tll
, op_msk
, indent
+ 1);
291 printf("\t\t\tInvalid ForCES TLV type=%x", type
);
297 recpdoptlv_print(register const u_char
* pptr
, register u_int len
,
298 u_int16_t op_msk
, int indent
)
300 struct forces_tlv
*pdtlv
= (struct forces_tlv
*)pptr
;
305 register const u_char
*dp
;
309 invtlv
= tlv_valid(pdtlv
, len
);
313 ib
= indent_pr(indent
, 0);
314 type
= EXTRACT_16BITS(&pdtlv
->type
);
315 dp
= (u_char
*) TLV_DATA(pdtlv
);
316 tll
= EXTRACT_16BITS(&pdtlv
->length
) - TLV_HDRL
;
320 ("%s%s, length %d (data encapsulated %d Bytes)",
321 ib
, tok2str(ForCES_TLV
, NULL
, type
),
322 EXTRACT_16BITS(&pdtlv
->length
),
323 EXTRACT_16BITS(&pdtlv
->length
) - TLV_HDRL
);
325 rc
= pdata_print(dp
, tll
, op_msk
, indent
+ 1);
326 pdtlv
= GO_NXT_TLV(pdtlv
, len
);
331 ("\n\t\tMessy PATHDATA TLV header, type (0x%x) \n\t\texcess of %d Bytes ",
332 EXTRACT_16BITS(&pdtlv
->type
), tll
- EXTRACT_16BITS(&pdtlv
->length
));
340 invoptlv_print(register const u_char
* pptr
, register u_int len
,
341 u_int16_t op_msk _U_
, int indent
)
343 char *ib
= indent_pr(indent
, 1);
345 printf("%sData[", &ib
[1]);
346 hex_print_with_offset(ib
, pptr
, len
, 0);
352 int otlv_print(struct forces_tlv
*otlv
, u_int16_t op_msk _U_
, int indent
)
355 register const u_char
*dp
= (u_char
*) TLV_DATA(otlv
);
356 u_int16_t type
= EXTRACT_16BITS(&otlv
->type
);
357 int tll
= EXTRACT_16BITS(&otlv
->length
) - TLV_HDRL
;
358 char *ib
= indent_pr(indent
, 0);
361 ops
= get_forces_optlv_h(type
);
363 printf("%sOper TLV %s(0x%x) length %d\n", ib
, ops
->s
, type
,
364 EXTRACT_16BITS(&otlv
->length
));
366 /* empty TLVs like COMMIT and TRCOMMIT are empty, we stop here .. */
367 if (!ops
->flags
& ZERO_TTLV
) {
368 if (tll
!= 0) /* instead of "if (tll)" - for readability .. */
369 printf("%s: Illegal - MUST be empty\n", ops
->s
);
372 /* rest of ops must at least have 12B {pathinfo} */
373 if (tll
< OP_MIN_SIZ
) {
374 printf("\t\tOper TLV %s(0x%x) length %d\n", ops
->s
, type
,
375 EXTRACT_16BITS(&otlv
->length
));
376 printf("\t\tTruncated data size %d minimum required %d\n", tll
,
378 return invoptlv_print(dp
, tll
, ops
->op_msk
, indent
);
382 rc
= ops
->print(dp
, tll
, ops
->op_msk
, indent
+ 1);
389 asttlv_print(register const u_char
* pptr
, register u_int len
,
390 u_int16_t op_msk _U_
, int indent
)
394 u_int16_t dlen
= len
- TLV_HDRL
;
395 char *ib
= indent_pr(indent
, 0);
396 if (dlen
!= ASTDLN
) {
397 printf("illegal ASTresult-TLV: %d bytes! \n", dlen
);
400 rescode
= EXTRACT_32BITS(pptr
);
401 if (rescode
> ASTMCD
) {
402 printf("illegal ASTresult result code: %d! \n", rescode
);
407 printf("Teardown reason: \n%s", ib
);
410 printf("Normal Teardown");
413 printf("Loss of Heartbeats");
416 printf("Out of bandwidth");
419 printf("Out of Memory");
422 printf("Application Crash");
425 printf("Unknown Teardown reason");
428 printf("(%x) \n%s", rescode
, ib
);
436 asrtlv_print(register const u_char
* pptr
, register u_int len
,
437 u_int16_t op_msk _U_
, int indent
)
441 u_int16_t dlen
= len
- TLV_HDRL
;
442 char *ib
= indent_pr(indent
, 0);
444 if (dlen
!= ASRDLN
) { /* id, instance, oper tlv */
445 printf("illegal ASRresult-TLV: %d bytes! \n", dlen
);
448 rescode
= EXTRACT_32BITS(pptr
);
450 if (rescode
> ASRMCD
) {
451 printf("illegal ASRresult result code: %d! \n", rescode
);
462 printf("FE ID invalid ");
465 printf("permission denied ");
471 printf("(%x) \n%s", rescode
, ib
);
477 gentltlv_print(register const u_char
* pptr _U_
, register u_int len
,
478 u_int16_t op_msk _U_
, int indent _U_
)
480 u_int16_t dlen
= len
- TLV_HDRL
;
481 if (dlen
< 4) { /* at least 32 bits must exist */
482 printf("truncated TLV: %d bytes missing! ", 4 - dlen
);
490 print_metailv(register const u_char
* pptr
, register u_int len
,
491 u_int16_t op_msk _U_
, int indent
)
493 u_int16_t dlen
= len
- ILV_HDRL
;
495 char *ib
= indent_pr(indent
, 0);
496 /* XXX: check header length */
497 struct forces_ilv
*ilv
= (struct forces_ilv
*)pptr
;
498 printf("\n%sMetaID 0x%x length %d\n", ib
, EXTRACT_32BITS(&ilv
->type
),
499 EXTRACT_32BITS(&ilv
->length
));
500 hex_print_with_offset("\n\t\t\t\t[", ILV_DATA(ilv
), tll
, 0);
505 print_metatlv(register const u_char
* pptr
, register u_int len
,
506 u_int16_t op_msk _U_
, int indent
)
508 u_int16_t dlen
= len
- TLV_HDRL
;
509 char *ib
= indent_pr(indent
, 0);
511 struct forces_ilv
*ilv
= (struct forces_ilv
*)pptr
;
514 printf("\n%s METADATA \n", ib
);
516 invilv
= ilv_valid(ilv
, tll
);
519 print_metailv((u_char
*) ilv
, tll
, 0, indent
+ 1);
521 ilv
= GO_NXT_ILV(ilv
, tll
);
530 print_reddata(register const u_char
* pptr
, register u_int len
,
531 u_int16_t op_msk _U_
, int indent _U_
)
533 u_int16_t dlen
= len
- TLV_HDRL
;
536 struct forces_tlv
*tlv
= (struct forces_tlv
*)pptr
;
538 printf("\n\t\t Redirect DATA\n");
539 if (dlen
<= RD_MIN
) {
540 printf("\n\t\ttruncated Redirect data: %d bytes missing! ",
545 invtlv
= tlv_valid(tlv
, tll
);
548 printf("Redir data type 0x%x len %d\n", EXTRACT_16BITS(&tlv
->type
),
549 EXTRACT_16BITS(&tlv
->length
));
554 hex_print_with_offset("\n\t\t\t[", TLV_DATA(tlv
), tll
, 0);
559 redirect_print(register const u_char
* pptr
, register u_int len
,
560 u_int16_t op_msk _U_
, int indent
)
562 struct forces_tlv
*tlv
= (struct forces_tlv
*)pptr
;
563 u_int16_t dlen
= len
- TLV_HDRL
;
567 if (dlen
<= RD_MIN
) {
568 printf("\n\t\ttruncated Redirect TLV: %d bytes missing! ",
575 invtlv
= tlv_valid(tlv
, tll
);
578 if (EXTRACT_16BITS(&tlv
->type
) == F_TLV_METD
) {
579 print_metatlv((u_char
*) TLV_DATA(tlv
), tll
, 0, indent
);
580 } else if ((EXTRACT_16BITS(&tlv
->type
) == F_TLV_REDD
)) {
581 print_reddata((u_char
*) TLV_DATA(tlv
), tll
, 0, indent
);
583 printf("Unknown REDIRECT TLV 0x%x len %d\n",
584 EXTRACT_16BITS(&tlv
->type
), EXTRACT_16BITS(&tlv
->length
));
587 tlv
= GO_NXT_TLV(tlv
, tll
);
592 ("\n\t\tMessy Redirect TLV header, type (0x%x) \n\t\texcess of %d Bytes ",
593 EXTRACT_16BITS(&tlv
->type
), tll
- EXTRACT_16BITS(&tlv
->length
));
604 lfbselect_print(register const u_char
* pptr
, register u_int len
,
605 u_int16_t op_msk
, int indent
)
607 const struct forces_lfbsh
*lfbs
;
608 struct forces_tlv
*otlv
;
609 char *ib
= indent_pr(indent
, 0);
610 u_int16_t dlen
= len
- TLV_HDRL
;
611 u_int tll
= dlen
- OP_OFF
;
614 if (dlen
<= OP_MIN
) { /* id, instance, oper tlv header .. */
615 printf("\n\t\ttruncated lfb selector: %d bytes missing! ",
620 lfbs
= (const struct forces_lfbsh
*)pptr
;
622 printf("\n%s%s(Classid %x) instance %x\n",
623 ib
, tok2str(ForCES_LFBs
, NULL
, EXTRACT_32BITS(&lfbs
->class)),
624 EXTRACT_32BITS(&lfbs
->class),
625 EXTRACT_32BITS(&lfbs
->instance
));
628 otlv
= (struct forces_tlv
*)(lfbs
+ 1);
632 invtlv
= tlv_valid(otlv
, tll
);
635 if (op_valid(EXTRACT_16BITS(&otlv
->type
), op_msk
)) {
636 otlv_print(otlv
, 0, indent
);
641 ("\t\tINValid oper-TLV type 0x%x length %d for this ForCES message\n",
642 EXTRACT_16BITS(&otlv
->type
), EXTRACT_16BITS(&otlv
->length
));
643 invoptlv_print((u_char
*)otlv
, tll
, 0, indent
);
645 otlv
= GO_NXT_TLV(otlv
, tll
);
650 ("\n\t\tMessy oper TLV header, type (0x%x) \n\t\texcess of %d Bytes ",
651 EXTRACT_16BITS(&otlv
->type
), tll
- EXTRACT_16BITS(&otlv
->length
));
659 forces_type_print(register const u_char
* pptr
, const struct forcesh
*fhdr _U_
,
660 register u_int mlen
, struct tom_h
*tops
)
662 struct forces_tlv
*tltlv
;
668 tll
= mlen
- sizeof(struct forcesh
);
671 if (tops
->flags
& ZERO_TTLV
) {
672 printf("<0x%x>Illegal Top level TLV!\n", tops
->flags
);
676 if (tops
->flags
& ZERO_MORE_TTLV
)
678 if (tops
->flags
& ONE_MORE_TTLV
) {
679 printf("\tTop level TLV Data missing!\n");
684 if (tops
->flags
& ZERO_TTLV
) {
688 ttlv
= tops
->flags
>> 4;
689 tltlv
= GET_TOP_TLV(pptr
);
691 /*XXX: 15 top level tlvs will probably be fine
692 You are nuts if you send more ;-> */
694 invtlv
= tlv_valid(tltlv
, tll
);
697 if (!ttlv_valid(EXTRACT_16BITS(&tltlv
->type
))) {
698 printf("\n\tInvalid ForCES Top TLV type=0x%x",
699 EXTRACT_16BITS(&tltlv
->type
));
704 printf("\t%s, length %d (data length %d Bytes)",
705 tok2str(ForCES_TLV
, NULL
, EXTRACT_16BITS(&tltlv
->type
)),
706 EXTRACT_16BITS(&tltlv
->length
), EXTRACT_16BITS(&tltlv
->length
) - 4);
708 rc
= tops
->print((u_char
*) TLV_DATA(tltlv
),
709 EXTRACT_16BITS(&tltlv
->length
), tops
->op_msk
, 9);
713 tltlv
= GO_NXT_TLV(tltlv
, tll
);
719 printf("\tMess TopTLV header: min %lu, total %d advertised %d ",
720 (unsigned long)sizeof(struct forces_tlv
),
721 tll
, EXTRACT_16BITS(&tltlv
->length
));
728 void forces_print(register const u_char
* pptr
, register u_int len
)
730 const struct forcesh
*fhdr
;
736 fhdr
= (const struct forcesh
*)pptr
;
737 if (!tom_valid(fhdr
->fm_tom
)) {
738 printf("Invalid ForCES message type %d\n", fhdr
->fm_tom
);
742 mlen
= ForCES_BLN(fhdr
);
744 tops
= get_forces_tom(fhdr
->fm_tom
);
745 if (tops
->v
== TOM_RSVD
) {
746 printf("\n\tUnknown ForCES message type=0x%x", fhdr
->fm_tom
);
750 printf("\n\tForCES %s ", tops
->s
);
751 if (!ForCES_HLN_VALID(mlen
, len
)) {
753 ("Illegal ForCES pkt len - min %lu, total recvd %d, advertised %d ",
754 (unsigned long)sizeof(struct forcesh
), len
, ForCES_BLN(fhdr
));
758 flg_raw
= EXTRACT_32BITS(pptr
+ 20);
760 printf("\n\tForCES Version %d len %uB flags 0x%08x ",
761 ForCES_V(fhdr
), mlen
, flg_raw
);
762 printf("\n\tSrcID 0x%x(%s) DstID 0x%x(%s) Correlator 0x%"
763 PRIu64
, ForCES_SID(fhdr
), ForCES_node(ForCES_SID(fhdr
)),
764 ForCES_DID(fhdr
), ForCES_node(ForCES_DID(fhdr
)),
765 EXTRACT_64BITS(fhdr
->fm_cor
));
770 ("\n\tForCES flags:\n\t %s(0x%x), prio=%d, %s(0x%x),\n\t %s(0x%x), %s(0x%x)\n",
771 ForCES_ACKp(ForCES_ACK(fhdr
)), ForCES_ACK(fhdr
),
773 ForCES_EMp(ForCES_EM(fhdr
)), ForCES_EM(fhdr
),
774 ForCES_ATp(ForCES_AT(fhdr
)), ForCES_AT(fhdr
),
775 ForCES_TPp(ForCES_TP(fhdr
)), ForCES_TP(fhdr
));
777 ("\t Extra flags: rsv(b5-7) 0x%x rsv(b13-31) 0x%x\n",
778 ForCES_RS1(fhdr
), ForCES_RS2(fhdr
));
780 rc
= forces_type_print(pptr
, fhdr
, mlen
, tops
);
783 hex_print_with_offset("\n\t[", pptr
, len
, 0);
789 printf("\n\t Raw ForCES message \n\t [");
790 hex_print_with_offset("\n\t ", pptr
, len
, 0);