]>
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
, 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_int32_t allres
= (u_int32_t
) * (u_char
*) TLV_DATA(tlv
);
41 u_int16_t dlen
= len
- TLV_HDRL
;
44 printf("illegal RESULT-TLV: %d bytes! \n", dlen
);
48 if (r
->result
>= 0x18 && r
->result
<= 0xFE) {
49 printf("illegal reserved result code: 0x%x! \n", r
->result
);
54 char *ib
= indent_pr(indent
, 0);
55 printf("%s Result: %s (code 0x%x)\n", ib
,
56 tok2str(ForCES_errs
, NULL
, r
->result
), r
->result
);
62 fdatatlv_print(register const u_char
* pptr
, register u_int len
,
63 u_int16_t op_msk
, int indent
)
65 struct forces_tlv
*tlv
= (struct forces_tlv
*)pptr
;
66 u_int tll
= len
- TLV_HDRL
;
67 register const u_char
*tdp
= (u_char
*) TLV_DATA(tlv
);
68 u_int16_t type
= ntohs(tlv
->type
);
69 if (type
!= F_TLV_FULD
) {
70 printf("Error: expecting FULLDATA!\n");
75 char *ib
= indent_pr(indent
+ 2, 1);
76 printf("%s[", &ib
[1]);
77 hex_print_with_offset(ib
, tdp
, tll
, 0);
78 printf("\n%s]\n", &ib
[1]);
84 sdatailv_print(register const u_char
* pptr
, register u_int len
,
85 u_int16_t op_msk
, int indent
)
87 int tll
= len
- ILV_HDRL
;
88 struct forces_ilv
*ilv
= (struct forces_ilv
*)pptr
;
93 invilv
= ilv_valid(ilv
, tll
);
95 printf("Error: BAD ILV!\n");
99 register const u_char
*tdp
= (u_char
*) ILV_DATA(ilv
);
100 char *ib
= indent_pr(indent
, 1);
101 printf("\n%s SPARSEDATA: type %x length %d\n", &ib
[1],
102 ntohl(ilv
->type
), ntohl(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
= ntohs(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
= ntohs(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 ntohs(kdtlv
->length
));
153 tll
= ntohs(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#%02d: %d\n", ib
, i
+ 1, id
);
175 struct forces_tlv
*pdtlv
= (struct forces_tlv
*)pptr
;
176 u_int16_t type
= ntohs(pdtlv
->type
);
177 u_int16_t tll
= ntohs(pdtlv
->length
) - TLV_HDRL
;
178 register const u_char
*dp
= (u_char
*) TLV_DATA(pdtlv
);
180 int aln
= F_ALN_LEN(ntohs(pdtlv
->length
));
182 int invtlv
= tlv_valid(pdtlv
, len
);
186 ("%s Outstanding bytes %d for TLV type 0x%x TLV len %d\n",
187 tok2str(ForCES_TLV_err
, NULL
, invtlv
), len
, type
,
188 ntohs(pdtlv
->length
));
191 if (aln
> ntohs(pdtlv
->length
)) {
194 ("Invalid padded pathdata TLV type 0x%x len %d missing %d pad bytes\n",
195 type
, ntohs(pdtlv
->length
), aln
- len
);
197 pad
= aln
- ntohs(pdtlv
->length
);
200 if (pd_valid(type
)) {
201 struct pdata_ops
*ops
= get_forces_pd(type
);
203 if (vflag
>= 3 && ops
->v
!= F_TLV_PDAT
) {
206 ("%s %s (Length %d DataLen %d pad %d Bytes)\n",
207 ib
, ops
->s
, ntohs(pdtlv
->length
),
211 ("%s %s (Length %d DataLen %d Bytes)\n",
212 ib
, ops
->s
, ntohs(pdtlv
->length
),
216 chk_op_type(type
, op_msk
, ops
->op_msk
);
218 rc
= ops
->print((const u_char
*)pdtlv
,
219 tll
+ pad
+ TLV_HDRL
, op_msk
,
222 printf("Invalid path data content type 0x%x len %d\n",
223 type
, ntohs(pdtlv
->length
));
225 if (ntohs(pdtlv
->length
)) {
226 hex_print_with_offset("Bad Data val\n\t [",
238 pdata_print(register const u_char
* pptr
, register u_int len
,
239 u_int16_t op_msk
, int indent
)
241 struct pathdata_h
*pdh
= (struct pathdata_h
*)pptr
;
242 char *ib
= indent_pr(indent
, 0);
245 printf("\n%sPathdata: Flags 0x%x ID count %d\n",
246 ib
, ntohs(pdh
->pflags
), ntohs(pdh
->pIDcnt
));
249 if (ntohs(pdh
->pflags
) & F_SELKEY
) {
252 pptr
+= sizeof(struct pathdata_h
);
253 len
-= sizeof(struct pathdata_h
);
254 minsize
= ntohs(pdh
->pIDcnt
) * 4;
256 printf("\t\t\ttruncated IDs expectd %dB got %dB\n", minsize
,
258 hex_print_with_offset("\t\t\tID Data[", pptr
, len
, 0);
262 return pdatacnt_print(pptr
, len
, ntohs(pdh
->pIDcnt
), op_msk
, indent
);
266 genoptlv_print(register const u_char
* pptr
, register u_int len
,
267 u_int16_t op_msk
, int indent
)
269 struct forces_tlv
*pdtlv
= (struct forces_tlv
*)pptr
;
270 u_int16_t type
= ntohs(pdtlv
->type
);
271 int tll
= ntohs(pdtlv
->length
) - TLV_HDRL
;
272 int invtlv
= tlv_valid(pdtlv
, len
);
273 char *ib
= indent_pr(indent
, 0);
277 printf("genoptlvprint - %s TLV type 0x%x len %d\n",
278 tok2str(ForCES_TLV
, NULL
, type
), type
, ntohs(pdtlv
->length
));
280 register const u_char
*dp
= (u_char
*) TLV_DATA(pdtlv
);
281 if (!ttlv_valid(type
)) {
282 printf("%s TLV type 0x%x len %d\n",
283 tok2str(ForCES_TLV_err
, NULL
, invtlv
), type
,
284 ntohs(pdtlv
->length
));
288 printf("%s%s, length %d (data length %d Bytes)",
289 ib
, tok2str(ForCES_TLV
, NULL
, type
),
290 ntohs(pdtlv
->length
), tll
);
292 return pdata_print(dp
, tll
, op_msk
, indent
+ 1);
294 printf("\t\t\tInvalid ForCES TLV type=%x", type
);
300 recpdoptlv_print(register const u_char
* pptr
, register u_int len
,
301 u_int16_t op_msk
, int indent
)
303 struct forces_tlv
*pdtlv
= (struct forces_tlv
*)pptr
;
308 register const u_char
*dp
;
312 invtlv
= tlv_valid(pdtlv
, len
);
316 ib
= indent_pr(indent
, 0);
317 type
= ntohs(pdtlv
->type
);
318 dp
= (u_char
*) TLV_DATA(pdtlv
);
319 tll
= ntohs(pdtlv
->length
) - TLV_HDRL
;
323 ("%s%s, length %d (data encapsulated %d Bytes)",
324 ib
, tok2str(ForCES_TLV
, NULL
, type
),
325 ntohs(pdtlv
->length
),
326 ntohs(pdtlv
->length
) - TLV_HDRL
);
328 rc
= pdata_print(dp
, tll
, op_msk
, indent
+ 1);
329 pdtlv
= GO_NXT_TLV(pdtlv
, len
);
334 ("\n\t\tMessy PATHDATA TLV header, type (0x%x) \n\t\texcess of %d Bytes ",
335 ntohs(pdtlv
->type
), tll
- ntohs(pdtlv
->length
));
343 invoptlv_print(register const u_char
* pptr
, register u_int len
,
344 u_int16_t op_msk
, int indent
)
346 char *ib
= indent_pr(indent
, 1);
348 printf("%sData[", &ib
[1]);
349 hex_print_with_offset(ib
, pptr
, len
, 0);
355 int otlv_print(struct forces_tlv
*otlv
, u_int16_t op_msk
, int indent
)
358 register const u_char
*dp
= (u_char
*) TLV_DATA(otlv
);
359 u_int16_t type
= ntohs(otlv
->type
);
360 int tll
= ntohs(otlv
->length
) - TLV_HDRL
;
361 char *ib
= indent_pr(indent
, 0);
363 struct pathdata_h
*pdh
;
365 ops
= get_forces_optlv_h(type
);
367 printf("%sOper TLV %s(0x%x) length %d\n", ib
, ops
->s
, type
,
368 ntohs(otlv
->length
));
370 //empty TLVs like COMMIT and TRCOMMIT are empty, we stop here ..
371 if (!ops
->flags
& ZERO_TTLV
) {
372 if (tll
!= 0) // instead of "if (tll)" - for readability ..
373 printf("%s: Illegal - MUST be empty\n", ops
->s
);
376 // rest of ops must at least have 12B {pathinfo}
377 if (tll
< OP_MIN_SIZ
) {
378 printf("\t\tOper TLV %s(0x%x) length %d\n", ops
->s
, type
,
379 ntohs(otlv
->length
));
380 printf("\t\tTruncated data size %d minimum required %d\n", tll
,
382 return invoptlv_print(dp
, tll
, ops
->op_msk
, indent
);
386 rc
= ops
->print(dp
, tll
, ops
->op_msk
, indent
+ 1);
393 asttlv_print(register const u_char
* pptr
, register u_int len
,
394 u_int16_t op_msk
, int indent
)
398 u_int16_t dlen
= len
- TLV_HDRL
;
399 char *ib
= indent_pr(indent
, 0);
400 if (dlen
!= ASTDLN
) {
401 printf("illegal ASTresult-TLV: %d bytes! \n", dlen
);
404 rescode
= EXTRACT_32BITS(pptr
);
405 if (rescode
> ASTMCD
) {
406 printf("illegal ASTresult result code: %d! \n", rescode
);
411 printf("Teardown reason: \n%s", ib
);
414 printf("Normal Teardown");
417 printf("Loss of Heartbeats");
420 printf("Out of bandwidth");
423 printf("Out of Memory");
426 printf("Application Crash");
429 printf("Unknown Teardown reason");
432 printf("(%x) \n%s", rescode
, ib
);
440 asrtlv_print(register const u_char
* pptr
, register u_int len
,
441 u_int16_t op_msk
, int indent
)
445 u_int16_t dlen
= len
- TLV_HDRL
;
446 char *ib
= indent_pr(indent
, 0);
448 if (dlen
!= ASRDLN
) { // id, instance, oper tlv
449 printf("illegal ASRresult-TLV: %d bytes! \n", dlen
);
452 rescode
= EXTRACT_32BITS(pptr
);
454 if (rescode
> ASRMCD
) {
455 printf("illegal ASRresult result code: %d! \n", rescode
);
466 printf("FE ID invalid ");
469 printf("permission denied ");
475 printf("(%x) \n%s", rescode
, ib
);
481 gentltlv_print(register const u_char
* pptr
, register u_int len
,
482 u_int16_t op_msk
, int indent
)
484 u_int16_t dlen
= len
- TLV_HDRL
;
485 if (dlen
< 4) { /* at least 32 bits must exist */
486 printf("truncated TLV: %d bytes missing! ", 4 - dlen
);
494 print_metailv(register const u_char
* pptr
, register u_int len
,
495 u_int16_t op_msk
, int indent
)
497 u_int16_t dlen
= len
- ILV_HDRL
;
499 char *ib
= indent_pr(indent
, 0);
500 //XXX: check header length
501 struct forces_ilv
*ilv
= (struct forces_ilv
*)pptr
;
502 printf("\n%sMetaID 0x%x length %d\n", ib
, ntohl(ilv
->type
),
504 hex_print_with_offset("\n\t\t\t\t[", (char *)ILV_DATA(ilv
), tll
, 0);
509 print_metatlv(register const u_char
* pptr
, register u_int len
,
510 u_int16_t op_msk
, int indent
)
512 u_int16_t dlen
= len
- TLV_HDRL
;
513 char *ib
= indent_pr(indent
, 0);
515 struct forces_ilv
*ilv
= (struct forces_ilv
*)pptr
;
518 printf("\n%s METADATA \n", ib
);
520 invilv
= ilv_valid(ilv
, tll
);
523 print_metailv((u_char
*) ilv
, tll
, 0, indent
+ 1);
525 ilv
= GO_NXT_ILV(ilv
, tll
);
534 print_reddata(register const u_char
* pptr
, register u_int len
,
535 u_int16_t op_msk
, int indent
)
537 u_int16_t dlen
= len
- TLV_HDRL
;
540 struct forces_tlv
*tlv
= (struct forces_tlv
*)pptr
;
542 printf("\n\t\t Redirect DATA\n");
543 if (dlen
<= RD_MIN
) {
544 printf("\n\t\ttruncated Redirect data: %d bytes missing! ",
549 invtlv
= tlv_valid(tlv
, tll
);
552 printf("Redir data type 0x%x len %d\n", ntohs(tlv
->type
),
558 hex_print_with_offset("\n\t\t\t[", (char *)TLV_DATA(tlv
), tll
, 0);
563 redirect_print(register const u_char
* pptr
, register u_int len
,
564 u_int16_t op_msk
, int indent
)
566 struct forces_tlv
*tlv
= (struct forces_tlv
*)pptr
;
567 u_int16_t dlen
= len
- TLV_HDRL
;
571 if (dlen
<= RD_MIN
) {
572 printf("\n\t\ttruncated Redirect TLV: %d bytes missing! ",
579 invtlv
= tlv_valid(tlv
, tll
);
582 if (ntohs(tlv
->type
) == F_TLV_METD
) {
583 print_metatlv((u_char
*) TLV_DATA(tlv
), tll
, 0, indent
);
584 } else if ((ntohs(tlv
->type
) == F_TLV_REDD
)) {
585 print_reddata((u_char
*) TLV_DATA(tlv
), tll
, 0, indent
);
587 printf("Unknown REDIRECT TLV 0x%x len %d\n",
588 ntohs(tlv
->type
), ntohs(tlv
->length
));
591 tlv
= GO_NXT_TLV(tlv
, tll
);
596 ("\n\t\tMessy Redirect TLV header, type (0x%x) \n\t\texcess of %d Bytes ",
597 ntohs(tlv
->type
), tll
- ntohs(tlv
->length
));
608 lfbselect_print(register const u_char
* pptr
, register u_int len
,
609 u_int16_t op_msk
, int indent
)
611 const struct forces_lfbsh
*lfbs
;
612 struct forces_tlv
*otlv
;
613 char *ib
= indent_pr(indent
, 0);
614 u_int16_t dlen
= len
- TLV_HDRL
;
615 int tll
= dlen
- OP_OFF
;
618 if (dlen
<= OP_MIN
) { // id, instance, oper tlv header ..
619 printf("\n\t\ttruncated lfb selector: %d bytes missing! ",
624 lfbs
= (const struct forces_lfbsh
*)pptr
;
626 printf("\n%s%s(Classid %x) instance %x\n",
627 ib
, tok2str(ForCES_LFBs
, NULL
, ntohl(lfbs
->class)),
628 ntohl(lfbs
->class), ntohl(lfbs
->instance
));
631 otlv
= (struct forces_tlv
*)(lfbs
+ 1);
635 invtlv
= tlv_valid(otlv
, tll
);
638 if (op_valid(ntohs(otlv
->type
), op_msk
)) {
639 otlv_print(otlv
, 0, indent
);
644 ("\t\tINValid oper-TLV type 0x%x length %d for this ForCES message\n",
645 ntohs(otlv
->type
), ntohs(otlv
->length
));
646 invoptlv_print((char *)otlv
, tll
, 0, indent
);
648 otlv
= GO_NXT_TLV(otlv
, tll
);
653 ("\n\t\tMessy oper TLV header, type (0x%x) \n\t\texcess of %d Bytes ",
654 ntohs(otlv
->type
), tll
- ntohs(otlv
->length
));
662 forces_type_print(register const u_char
* pptr
, const struct forcesh
*fhdr
,
663 register u_int mlen
, struct tom_h
*tops
)
665 struct forces_tlv
*tltlv
;
672 tll
= mlen
- sizeof(struct forcesh
);
675 if (tops
->flags
& ZERO_TTLV
) {
676 printf("<0x%x>Illegal Top level TLV!\n", tops
->flags
);
680 if (tops
->flags
& ZERO_MORE_TTLV
)
682 if (tops
->flags
& ONE_MORE_TTLV
) {
683 printf("\tTop level TLV Data missing!\n");
688 if (tops
->flags
& ZERO_TTLV
) {
692 ttlv
= tops
->flags
>> 4;
693 tltlv
= GET_TOP_TLV(pptr
);
695 /*XXX: 15 top level tlvs will probably be fine
696 You are nuts if you send more ;-> */
698 invtlv
= tlv_valid(tltlv
, tll
);
701 if (!ttlv_valid(ntohs(tltlv
->type
))) {
702 printf("\n\tInvalid ForCES Top TLV type=0x%x",
708 printf("\t%s, length %d (data length %d Bytes)",
709 tok2str(ForCES_TLV
, NULL
, ntohs(tltlv
->type
)),
710 ntohs(tltlv
->length
), ntohs(tltlv
->length
) - 4);
712 rc
= tops
->print((u_char
*) TLV_DATA(tltlv
),
713 ntohs(tltlv
->length
), tops
->op_msk
, 9);
717 tltlv
= GO_NXT_TLV(tltlv
, tll
);
723 printf("\tMess TopTLV header: min %ld, total %d advertised %d ",
724 sizeof(struct forces_tlv
), tll
, ntohs(tltlv
->length
));
731 void forces_print(register const u_char
* pptr
, register u_int len
)
733 const struct forcesh
*fhdr
;
739 fhdr
= (const struct forcesh
*)pptr
;
740 if (!tom_valid(fhdr
->fm_tom
)) {
741 printf("Invalid ForCES message type %d\n", fhdr
->fm_tom
);
745 mlen
= ForCES_BLN(fhdr
);
747 tops
= get_forces_tom(fhdr
->fm_tom
);
748 if (tops
->v
== TOM_RSVD
) {
749 printf("\n\tUnknown ForCES message type=0x%x", fhdr
->fm_tom
);
753 printf("\n\tForCES %s ", tops
->s
);
754 if (!ForCES_HLN_VALID(mlen
, len
)) {
756 ("Illegal ForCES pkt len - min %ld, total recvd %d, advertised %d ",
757 sizeof(struct forcesh
), len
, ForCES_BLN(fhdr
));
761 flg_raw
= EXTRACT_32BITS(pptr
+ 20);
763 printf("\n\tForCES Version %d len %dB flags 0x%08x ",
764 ForCES_V(fhdr
), mlen
, flg_raw
);
765 printf("\n\tSrcID 0x%x(%s) DstID 0x%x(%s) Correlator 0x%"
766 PRIu64
, ForCES_SID(fhdr
), ForCES_node(ForCES_SID(fhdr
)),
767 ForCES_DID(fhdr
), ForCES_node(ForCES_DID(fhdr
)),
768 EXTRACT_64BITS(fhdr
->fm_cor
));
773 ("\n\tForCES flags:\n\t %s(0x%x), prio=%d, %s(0x%x),\n\t %s(0x%x), %s(0x%x)\n",
774 ForCES_ACKp(fhdr
->f_ack
), fhdr
->f_ack
, fhdr
->f_pri
,
775 ForCES_EMp(fhdr
->f_em
), fhdr
->f_em
, ForCES_ATp(fhdr
->f_at
),
776 fhdr
->f_at
, ForCES_TPp(fhdr
->f_tp
), fhdr
->f_tp
);
778 ("\t Extra flags: rsv(b5-7) 0x%x rsv(b13-15) 0x%x rsv(b16-31) 0x%x\n",
779 fhdr
->f_rs1
, fhdr
->f_rs2
, ntohs(fhdr
->f_rs3
));
781 rc
= forces_type_print(pptr
, fhdr
, mlen
, tops
);
784 hex_print_with_offset("\n\t[", pptr
, len
, 0);
790 printf("\n\t Raw ForCES message \n\t [");
791 hex_print_with_offset("\n\t ", pptr
, len
, 0);