]> The Tcpdump Group git mirrors - tcpdump/blob - print-forces.c
Merge pull request #435 from wolfgangkarall/sigusr1-man
[tcpdump] / print-forces.c
1 /*
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.
12 *
13 * Copyright (c) 2009 Mojatatu Networks, Inc
14 *
15 */
16
17 #define NETDISSECT_REWORKED
18 #ifdef HAVE_CONFIG_H
19 #include "config.h"
20 #endif
21
22 #include <tcpdump-stdinc.h>
23
24 #include "interface.h"
25 #include "extract.h"
26
27 static const char tstr[] = "[|forces]";
28
29 /*
30 * RFC5810: Forwarding and Control Element Separation (ForCES) Protocol
31 */
32 #define ForCES_VERS 1
33 #define ForCES_HDRL 24
34 #define ForCES_ALNL 4U
35 #define TLV_HDRL 4
36 #define ILV_HDRL 8
37
38 #define TOM_RSVD 0x0
39 #define TOM_ASSNSETUP 0x1
40 #define TOM_ASSNTEARD 0x2
41 #define TOM_CONFIG 0x3
42 #define TOM_QUERY 0x4
43 #define TOM_EVENTNOT 0x5
44 #define TOM_PKTREDIR 0x6
45 #define TOM_HEARTBT 0x0F
46 #define TOM_ASSNSETREP 0x11
47 #define TOM_CONFIGREP 0x13
48 #define TOM_QUERYREP 0x14
49
50 /*
51 * tom_h Flags: resv1(8b):maxtlvs(4b):resv2(2b):mintlv(2b)
52 */
53 #define ZERO_TTLV 0x01
54 #define ZERO_MORE_TTLV 0x02
55 #define ONE_MORE_TTLV 0x04
56 #define ZERO_TLV 0x00
57 #define ONE_TLV 0x10
58 #define TWO_TLV 0x20
59 #define MAX_TLV 0xF0
60
61 #define TTLV_T1 (ONE_MORE_TTLV|ONE_TLV)
62 #define TTLV_T2 (ONE_MORE_TTLV|MAX_TLV)
63
64 struct tom_h {
65 uint32_t v;
66 uint16_t flags;
67 uint16_t op_msk;
68 const char *s;
69 int (*print) (netdissect_options *ndo, register const u_char * pptr, register u_int len,
70 uint16_t op_msk, int indent);
71 };
72
73 enum {
74 TOM_RSV_I,
75 TOM_ASS_I,
76 TOM_AST_I,
77 TOM_CFG_I,
78 TOM_QRY_I,
79 TOM_EVN_I,
80 TOM_RED_I,
81 TOM_HBT_I,
82 TOM_ASR_I,
83 TOM_CNR_I,
84 TOM_QRR_I,
85 _TOM_RSV_MAX
86 };
87 #define TOM_MAX_IND (_TOM_RSV_MAX - 1)
88
89 static inline int tom_valid(uint8_t tom)
90 {
91 if (tom > 0) {
92 if (tom >= 0x7 && tom <= 0xe)
93 return 0;
94 if (tom == 0x10)
95 return 0;
96 if (tom > 0x14)
97 return 0;
98 return 1;
99 } else
100 return 0;
101 }
102
103 static inline const char *ForCES_node(uint32_t node)
104 {
105 if (node <= 0x3FFFFFFF)
106 return "FE";
107 if (node >= 0x40000000 && node <= 0x7FFFFFFF)
108 return "CE";
109 if (node >= 0xC0000000 && node <= 0xFFFFFFEF)
110 return "AllMulticast";
111 if (node == 0xFFFFFFFD)
112 return "AllCEsBroadcast";
113 if (node == 0xFFFFFFFE)
114 return "AllFEsBroadcast";
115 if (node == 0xFFFFFFFF)
116 return "AllBroadcast";
117
118 return "ForCESreserved";
119
120 }
121
122 static const struct tok ForCES_ACKs[] = {
123 {0x0, "NoACK"},
124 {0x1, "SuccessACK"},
125 {0x2, "FailureACK"},
126 {0x3, "AlwaysACK"},
127 {0, NULL}
128 };
129
130 static const struct tok ForCES_EMs[] = {
131 {0x0, "EMReserved"},
132 {0x1, "execute-all-or-none"},
133 {0x2, "execute-until-failure"},
134 {0x3, "continue-execute-on-failure"},
135 {0, NULL}
136 };
137
138 static const struct tok ForCES_ATs[] = {
139 {0x0, "Standalone"},
140 {0x1, "2PCtransaction"},
141 {0, NULL}
142 };
143
144 static const struct tok ForCES_TPs[] = {
145 {0x0, "StartofTransaction"},
146 {0x1, "MiddleofTransaction"},
147 {0x2, "EndofTransaction"},
148 {0x3, "abort"},
149 {0, NULL}
150 };
151
152 /*
153 * Structure of forces header, naked of TLVs.
154 */
155 struct forcesh {
156 uint8_t fm_vrsvd; /* version and reserved */
157 #define ForCES_V(forcesh) ((forcesh)->fm_vrsvd >> 4)
158 uint8_t fm_tom; /* type of message */
159 uint16_t fm_len; /* total length * 4 bytes */
160 #define ForCES_BLN(forcesh) ((uint32_t)(EXTRACT_16BITS(&(forcesh)->fm_len) << 2))
161 uint32_t fm_sid; /* Source ID */
162 #define ForCES_SID(forcesh) EXTRACT_32BITS(&(forcesh)->fm_sid)
163 uint32_t fm_did; /* Destination ID */
164 #define ForCES_DID(forcesh) EXTRACT_32BITS(&(forcesh)->fm_did)
165 uint8_t fm_cor[8]; /* correlator */
166 uint32_t fm_flags; /* flags */
167 #define ForCES_ACK(forcesh) ((EXTRACT_32BITS(&(forcesh)->fm_flags)&0xC0000000) >> 30)
168 #define ForCES_PRI(forcesh) ((EXTRACT_32BITS(&(forcesh)->fm_flags)&0x38000000) >> 27)
169 #define ForCES_RS1(forcesh) ((EXTRACT_32BITS(&(forcesh)->fm_flags)&0x07000000) >> 24)
170 #define ForCES_EM(forcesh) ((EXTRACT_32BITS(&(forcesh)->fm_flags)&0x00C00000) >> 22)
171 #define ForCES_AT(forcesh) ((EXTRACT_32BITS(&(forcesh)->fm_flags)&0x00200000) >> 21)
172 #define ForCES_TP(forcesh) ((EXTRACT_32BITS(&(forcesh)->fm_flags)&0x00180000) >> 19)
173 #define ForCES_RS2(forcesh) ((EXTRACT_32BITS(&(forcesh)->fm_flags)&0x0007FFFF) >> 0)
174 };
175
176 #define ForCES_HLN_VALID(fhl,tlen) ((tlen) >= ForCES_HDRL && \
177 (fhl) >= ForCES_HDRL && \
178 (fhl) == (tlen))
179
180 #define F_LFB_RSVD 0x0
181 #define F_LFB_FEO 0x1
182 #define F_LFB_FEPO 0x2
183 static const struct tok ForCES_LFBs[] = {
184 {F_LFB_RSVD, "Invalid TLV"},
185 {F_LFB_FEO, "FEObj LFB"},
186 {F_LFB_FEPO, "FEProtoObj LFB"},
187 {0, NULL}
188 };
189
190 enum {
191 F_OP_RSV,
192 F_OP_SET,
193 F_OP_SETPROP,
194 F_OP_SETRESP,
195 F_OP_SETPRESP,
196 F_OP_DEL,
197 F_OP_DELRESP,
198 F_OP_GET,
199 F_OP_GETPROP,
200 F_OP_GETRESP,
201 F_OP_GETPRESP,
202 F_OP_REPORT,
203 F_OP_COMMIT,
204 F_OP_RCOMMIT,
205 F_OP_RTRCOMP,
206 _F_OP_MAX
207 };
208
209 #define F_OP_MAX (_F_OP_MAX - 1)
210 enum {
211 B_OP_SET = 1 << (F_OP_SET - 1),
212 B_OP_SETPROP = 1 << (F_OP_SETPROP - 1),
213 B_OP_SETRESP = 1 << (F_OP_SETRESP - 1),
214 B_OP_SETPRESP = 1 << (F_OP_SETPRESP - 1),
215 B_OP_DEL = 1 << (F_OP_DEL - 1),
216 B_OP_DELRESP = 1 << (F_OP_DELRESP - 1),
217 B_OP_GET = 1 << (F_OP_GET - 1),
218 B_OP_GETPROP = 1 << (F_OP_GETPROP - 1),
219 B_OP_GETRESP = 1 << (F_OP_GETRESP - 1),
220 B_OP_GETPRESP = 1 << (F_OP_GETPRESP - 1),
221 B_OP_REPORT = 1 << (F_OP_REPORT - 1),
222 B_OP_COMMIT = 1 << (F_OP_COMMIT - 1),
223 B_OP_RCOMMIT = 1 << (F_OP_RCOMMIT - 1),
224 B_OP_RTRCOMP = 1 << (F_OP_RTRCOMP - 1),
225 };
226
227 struct optlv_h {
228 uint16_t flags;
229 uint16_t op_msk;
230 const char *s;
231 int (*print) (netdissect_options *ndo, register const u_char * pptr, register u_int len,
232 uint16_t op_msk, int indent);
233 };
234
235 static int genoptlv_print(netdissect_options *, register const u_char * pptr, register u_int len,
236 uint16_t op_msk, int indent);
237 static int recpdoptlv_print(netdissect_options *, register const u_char * pptr, register u_int len,
238 uint16_t op_msk, int indent);
239 static int invoptlv_print(netdissect_options *, register const u_char * pptr, register u_int len,
240 uint16_t op_msk, int indent);
241
242 #define OP_MIN_SIZ 8
243 struct pathdata_h {
244 uint16_t pflags;
245 uint16_t pIDcnt;
246 };
247
248 #define B_FULLD 0x1
249 #define B_SPARD 0x2
250 #define B_RESTV 0x4
251 #define B_KEYIN 0x8
252 #define B_APPND 0x10
253 #define B_TRNG 0x20
254
255 static const struct optlv_h OPTLV_msg[F_OP_MAX + 1] = {
256 /* F_OP_RSV */ {ZERO_TTLV, 0, "Invalid OPTLV", invoptlv_print},
257 /* F_OP_SET */ {TTLV_T2, B_FULLD | B_SPARD, " Set", recpdoptlv_print},
258 /* F_OP_SETPROP */
259 {TTLV_T2, B_FULLD | B_SPARD, " SetProp", recpdoptlv_print},
260 /* F_OP_SETRESP */ {TTLV_T2, B_RESTV, " SetResp", recpdoptlv_print},
261 /* F_OP_SETPRESP */ {TTLV_T2, B_RESTV, " SetPropResp", recpdoptlv_print},
262 /* F_OP_DEL */ {ZERO_TTLV, 0, " Del", recpdoptlv_print},
263 /* F_OP_DELRESP */ {TTLV_T2, B_RESTV, " DelResp", recpdoptlv_print},
264 /* F_OP_GET */ {ZERO_TTLV, 0, " Get", recpdoptlv_print},
265 /* F_OP_GETPROP */ {ZERO_TTLV, 0, " GetProp", recpdoptlv_print},
266 /* F_OP_GETRESP */
267 {TTLV_T2, B_FULLD | B_SPARD | B_RESTV, " GetResp", recpdoptlv_print},
268 /* F_OP_GETPRESP */
269 {TTLV_T2, B_FULLD | B_RESTV, " GetPropResp", recpdoptlv_print},
270 /* F_OP_REPORT */
271 {TTLV_T2, B_FULLD | B_SPARD, " Report", recpdoptlv_print},
272 /* F_OP_COMMIT */ {ZERO_TTLV, 0, " Commit", NULL},
273 /* F_OP_RCOMMIT */ {TTLV_T1, B_RESTV, " RCommit", genoptlv_print},
274 /* F_OP_RTRCOMP */ {ZERO_TTLV, 0, " RTRCOMP", NULL},
275 };
276
277 static inline const struct optlv_h *get_forces_optlv_h(uint16_t opt)
278 {
279 if (opt > F_OP_MAX || opt <= F_OP_RSV)
280 return &OPTLV_msg[F_OP_RSV];
281
282 return &OPTLV_msg[opt];
283 }
284
285 #define IND_SIZE 256
286 #define IND_CHR ' '
287 #define IND_PREF '\n'
288 #define IND_SUF 0x0
289 char ind_buf[IND_SIZE];
290
291 static inline char *indent_pr(int indent, int nlpref)
292 {
293 int i = 0;
294 char *r = ind_buf;
295
296 if (indent > (IND_SIZE - 1))
297 indent = IND_SIZE - 1;
298
299 if (nlpref) {
300 r[i] = IND_PREF;
301 i++;
302 indent--;
303 }
304
305 while (--indent >= 0)
306 r[i++] = IND_CHR;
307
308 r[i] = IND_SUF;
309 return r;
310 }
311
312 static inline int op_valid(uint16_t op, uint16_t mask)
313 {
314 int opb = 1 << (op - 1);
315
316 if (op == 0)
317 return 0;
318 if (opb & mask)
319 return 1;
320 /* I guess we should allow vendor operations? */
321 if (op >= 0x8000)
322 return 1;
323 return 0;
324 }
325
326 #define F_TLV_RSVD 0x0000
327 #define F_TLV_REDR 0x0001
328 #define F_TLV_ASRS 0x0010
329 #define F_TLV_ASRT 0x0011
330 #define F_TLV_LFBS 0x1000
331 #define F_TLV_PDAT 0x0110
332 #define F_TLV_KEYI 0x0111
333 #define F_TLV_FULD 0x0112
334 #define F_TLV_SPAD 0x0113
335 #define F_TLV_REST 0x0114
336 #define F_TLV_METD 0x0115
337 #define F_TLV_REDD 0x0116
338 #define F_TLV_TRNG 0x0117
339
340
341 #define F_TLV_VNST 0x8000
342
343 static const struct tok ForCES_TLV[] = {
344 {F_TLV_RSVD, "Invalid TLV"},
345 {F_TLV_REDR, "REDIRECT TLV"},
346 {F_TLV_ASRS, "ASResult TLV"},
347 {F_TLV_ASRT, "ASTreason TLV"},
348 {F_TLV_LFBS, "LFBselect TLV"},
349 {F_TLV_PDAT, "PATH-DATA TLV"},
350 {F_TLV_KEYI, "KEYINFO TLV"},
351 {F_TLV_FULD, "FULLDATA TLV"},
352 {F_TLV_SPAD, "SPARSEDATA TLV"},
353 {F_TLV_REST, "RESULT TLV"},
354 {F_TLV_METD, "METADATA TLV"},
355 {F_TLV_REDD, "REDIRECTDATA TLV"},
356 {0, NULL}
357 };
358
359 #define TLV_HLN 4
360 static inline int ttlv_valid(uint16_t ttlv)
361 {
362 if (ttlv > 0) {
363 if (ttlv == 1 || ttlv == 0x1000)
364 return 1;
365 if (ttlv >= 0x10 && ttlv <= 0x11)
366 return 1;
367 if (ttlv >= 0x110 && ttlv <= 0x116)
368 return 1;
369 if (ttlv >= 0x8000)
370 return 0; /* XXX: */
371 }
372
373 return 0;
374 }
375
376 struct forces_ilv {
377 uint32_t type;
378 uint32_t length;
379 };
380
381 struct forces_tlv {
382 uint16_t type;
383 uint16_t length;
384 };
385
386 #define F_ALN_LEN(len) ( ((len)+ForCES_ALNL-1) & ~(ForCES_ALNL-1) )
387 #define GET_TOP_TLV(fhdr) ((struct forces_tlv *)((fhdr) + sizeof (struct forcesh)))
388 #define TLV_SET_LEN(len) (F_ALN_LEN(TLV_HDRL) + (len))
389 #define TLV_ALN_LEN(len) F_ALN_LEN(TLV_SET_LEN(len))
390 #define TLV_RDAT_LEN(tlv) ((int)(EXTRACT_16BITS(&(tlv)->length) - TLV_SET_LEN(0))
391 #define TLV_DATA(tlvp) ((void*)(((char*)(tlvp)) + TLV_SET_LEN(0)))
392 #define GO_NXT_TLV(tlv,rlen) ((rlen) -= F_ALN_LEN(EXTRACT_16BITS(&(tlv)->length)), \
393 (struct forces_tlv*)(((char*)(tlv)) \
394 + F_ALN_LEN(EXTRACT_16BITS(&(tlv)->length))))
395 #define ILV_SET_LEN(len) (F_ALN_LEN(ILV_HDRL) + (len))
396 #define ILV_ALN_LEN(len) F_ALN_LEN(ILV_SET_LEN(len))
397 #define ILV_RDAT_LEN(ilv) ((int)(EXTRACT_32BITS(&(ilv)->length)) - ILV_SET_LEN(0))
398 #define ILV_DATA(ilvp) ((void*)(((char*)(ilvp)) + ILV_SET_LEN(0)))
399 #define GO_NXT_ILV(ilv,rlen) ((rlen) -= F_ALN_LEN(EXTRACT_32BITS(&(ilv)->length)), \
400 (struct forces_ilv *)(((char*)(ilv)) \
401 + F_ALN_LEN(EXTRACT_32BITS(&(ilv)->length))))
402 #define INVALID_RLEN 1
403 #define INVALID_STLN 2
404 #define INVALID_LTLN 3
405 #define INVALID_ALEN 4
406
407 static const struct tok ForCES_TLV_err[] = {
408 {INVALID_RLEN, "Invalid total length"},
409 {INVALID_STLN, "xLV too short"},
410 {INVALID_LTLN, "xLV too long"},
411 {INVALID_ALEN, "data padding missing"},
412 {0, NULL}
413 };
414
415 static inline u_int tlv_valid(const struct forces_tlv *tlv, u_int rlen)
416 {
417 if (rlen < TLV_HDRL)
418 return INVALID_RLEN;
419 if (EXTRACT_16BITS(&tlv->length) < TLV_HDRL)
420 return INVALID_STLN;
421 if (EXTRACT_16BITS(&tlv->length) > rlen)
422 return INVALID_LTLN;
423 if (rlen < F_ALN_LEN(EXTRACT_16BITS(&tlv->length)))
424 return INVALID_ALEN;
425
426 return 0;
427 }
428
429 static inline int ilv_valid(const struct forces_ilv *ilv, u_int rlen)
430 {
431 if (rlen < ILV_HDRL)
432 return INVALID_RLEN;
433 if (EXTRACT_32BITS(&ilv->length) < ILV_HDRL)
434 return INVALID_STLN;
435 if (EXTRACT_32BITS(&ilv->length) > rlen)
436 return INVALID_LTLN;
437 if (rlen < F_ALN_LEN(EXTRACT_32BITS(&ilv->length)))
438 return INVALID_ALEN;
439
440 return 0;
441 }
442
443 static int lfbselect_print(netdissect_options *, register const u_char * pptr, register u_int len,
444 uint16_t op_msk, int indent);
445 static int redirect_print(netdissect_options *, register const u_char * pptr, register u_int len,
446 uint16_t op_msk, int indent);
447 static int asrtlv_print(netdissect_options *, register const u_char * pptr, register u_int len,
448 uint16_t op_msk, int indent);
449 static int asttlv_print(netdissect_options *, register const u_char * pptr, register u_int len,
450 uint16_t op_msk, int indent);
451
452 struct forces_lfbsh {
453 uint32_t class;
454 uint32_t instance;
455 };
456
457 #define ASSNS_OPS (B_OP_REPORT)
458 #define CFG_OPS (B_OP_SET|B_OP_SETPROP|B_OP_DEL|B_OP_COMMIT|B_OP_RTRCOMP)
459 #define CFG_ROPS (B_OP_SETRESP|B_OP_SETPRESP|B_OP_DELRESP|B_OP_RCOMMIT)
460 #define CFG_QY (B_OP_GET|B_OP_GETPROP)
461 #define CFG_QYR (B_OP_GETRESP|B_OP_GETPRESP)
462 #define CFG_EVN (B_OP_REPORT)
463
464 static const struct tom_h ForCES_msg[TOM_MAX_IND + 1] = {
465 /* TOM_RSV_I */ {TOM_RSVD, ZERO_TTLV, 0, "Invalid message", NULL},
466 /* TOM_ASS_I */ {TOM_ASSNSETUP, ZERO_MORE_TTLV | TWO_TLV, ASSNS_OPS,
467 "Association Setup", lfbselect_print},
468 /* TOM_AST_I */
469 {TOM_ASSNTEARD, TTLV_T1, 0, "Association TearDown", asttlv_print},
470 /* TOM_CFG_I */ {TOM_CONFIG, TTLV_T2, CFG_OPS, "Config", lfbselect_print},
471 /* TOM_QRY_I */ {TOM_QUERY, TTLV_T2, CFG_QY, "Query", lfbselect_print},
472 /* TOM_EVN_I */ {TOM_EVENTNOT, TTLV_T1, CFG_EVN, "Event Notification",
473 lfbselect_print},
474 /* TOM_RED_I */
475 {TOM_PKTREDIR, TTLV_T2, 0, "Packet Redirect", redirect_print},
476 /* TOM_HBT_I */ {TOM_HEARTBT, ZERO_TTLV, 0, "HeartBeat", NULL},
477 /* TOM_ASR_I */
478 {TOM_ASSNSETREP, TTLV_T1, 0, "Association Response", asrtlv_print},
479 /* TOM_CNR_I */ {TOM_CONFIGREP, TTLV_T2, CFG_ROPS, "Config Response",
480 lfbselect_print},
481 /* TOM_QRR_I */
482 {TOM_QUERYREP, TTLV_T2, CFG_QYR, "Query Response", lfbselect_print},
483 };
484
485 static inline const struct tom_h *get_forces_tom(uint8_t tom)
486 {
487 int i;
488 for (i = TOM_RSV_I; i <= TOM_MAX_IND; i++) {
489 const struct tom_h *th = &ForCES_msg[i];
490 if (th->v == tom)
491 return th;
492 }
493 return &ForCES_msg[TOM_RSV_I];
494 }
495
496 struct pdata_ops {
497 uint32_t v;
498 uint16_t flags;
499 uint16_t op_msk;
500 const char *s;
501 int (*print) (netdissect_options *, register const u_char * pptr, register u_int len,
502 uint16_t op_msk, int indent);
503 };
504
505 enum {
506 PD_RSV_I,
507 PD_SEL_I,
508 PD_FDT_I,
509 PD_SDT_I,
510 PD_RES_I,
511 PD_PDT_I,
512 _PD_RSV_MAX
513 };
514 #define PD_MAX_IND (_TOM_RSV_MAX - 1)
515
516 static inline int pd_valid(uint16_t pd)
517 {
518 if (pd >= F_TLV_PDAT && pd <= F_TLV_REST)
519 return 1;
520 return 0;
521 }
522
523 static inline void
524 chk_op_type(netdissect_options *ndo,
525 uint16_t type, uint16_t msk, uint16_t omsk)
526 {
527 if (type != F_TLV_PDAT) {
528 if (msk & B_KEYIN) {
529 if (type != F_TLV_KEYI) {
530 ND_PRINT((ndo, "Based on flags expected KEYINFO TLV!\n"));
531 }
532 } else {
533 if (!(msk & omsk)) {
534 ND_PRINT((ndo, "Illegal DATA encoding for type 0x%x programmed %x got %x \n",
535 type, omsk, msk));
536 }
537 }
538 }
539
540 }
541
542 #define F_SELKEY 1
543 #define F_SELTABRANGE 2
544 #define F_TABAPPEND 4
545
546 struct res_val {
547 uint8_t result;
548 uint8_t resv1;
549 uint16_t resv2;
550 };
551
552 static int prestlv_print(netdissect_options *, register const u_char * pptr, register u_int len,
553 uint16_t op_msk, int indent);
554 static int pkeyitlv_print(netdissect_options *, register const u_char * pptr, register u_int len,
555 uint16_t op_msk, int indent);
556 static int fdatatlv_print(netdissect_options *, register const u_char * pptr, register u_int len,
557 uint16_t op_msk, int indent);
558 static int sdatatlv_print(netdissect_options *, register const u_char * pptr, register u_int len,
559 uint16_t op_msk, int indent);
560
561 static const struct pdata_ops ForCES_pdata[PD_MAX_IND + 1] = {
562 /* PD_RSV_I */ {0, 0, 0, "Invalid message", NULL},
563 /* PD_SEL_I */ {F_TLV_KEYI, 0, 0, "KEYINFO TLV", pkeyitlv_print},
564 /* PD_FDT_I */ {F_TLV_FULD, 0, B_FULLD, "FULLDATA TLV", fdatatlv_print},
565 /* PD_SDT_I */ {F_TLV_SPAD, 0, B_SPARD, "SPARSEDATA TLV", sdatatlv_print},
566 /* PD_RES_I */ {F_TLV_REST, 0, B_RESTV, "RESULT TLV", prestlv_print},
567 /* PD_PDT_I */
568 {F_TLV_PDAT, 0, 0, "Inner PATH-DATA TLV", recpdoptlv_print},
569 };
570
571 static inline const struct pdata_ops *get_forces_pd(uint16_t pd)
572 {
573 int i;
574 for (i = PD_RSV_I + 1; i <= PD_MAX_IND; i++) {
575 const struct pdata_ops *pdo = &ForCES_pdata[i];
576 if (pdo->v == pd)
577 return pdo;
578 }
579 return &ForCES_pdata[TOM_RSV_I];
580 }
581
582 enum {
583 E_SUCCESS,
584 E_INVALID_HEADER,
585 E_LENGTH_MISMATCH,
586 E_VERSION_MISMATCH,
587 E_INVALID_DESTINATION_PID,
588 E_LFB_UNKNOWN,
589 E_LFB_NOT_FOUND,
590 E_LFB_INSTANCE_ID_NOT_FOUND,
591 E_INVALID_PATH,
592 E_COMPONENT_DOES_NOT_EXIST,
593 E_EXISTS,
594 E_NOT_FOUND,
595 E_READ_ONLY,
596 E_INVALID_ARRAY_CREATION,
597 E_VALUE_OUT_OF_RANGE,
598 E_CONTENTS_TOO_LONG,
599 E_INVALID_PARAMETERS,
600 E_INVALID_MESSAGE_TYPE,
601 E_INVALID_FLAGS,
602 E_INVALID_TLV,
603 E_EVENT_ERROR,
604 E_NOT_SUPPORTED,
605 E_MEMORY_ERROR,
606 E_INTERNAL_ERROR,
607 /* 0x18-0xFE are reserved .. */
608 E_UNSPECIFIED_ERROR = 0XFF
609 };
610
611 static const struct tok ForCES_errs[] = {
612 {E_SUCCESS, "SUCCESS"},
613 {E_INVALID_HEADER, "INVALID HEADER"},
614 {E_LENGTH_MISMATCH, "LENGTH MISMATCH"},
615 {E_VERSION_MISMATCH, "VERSION MISMATCH"},
616 {E_INVALID_DESTINATION_PID, "INVALID DESTINATION PID"},
617 {E_LFB_UNKNOWN, "LFB UNKNOWN"},
618 {E_LFB_NOT_FOUND, "LFB NOT FOUND"},
619 {E_LFB_INSTANCE_ID_NOT_FOUND, "LFB INSTANCE ID NOT FOUND"},
620 {E_INVALID_PATH, "INVALID PATH"},
621 {E_COMPONENT_DOES_NOT_EXIST, "COMPONENT DOES NOT EXIST"},
622 {E_EXISTS, "EXISTS ALREADY"},
623 {E_NOT_FOUND, "NOT FOUND"},
624 {E_READ_ONLY, "READ ONLY"},
625 {E_INVALID_ARRAY_CREATION, "INVALID ARRAY CREATION"},
626 {E_VALUE_OUT_OF_RANGE, "VALUE OUT OF RANGE"},
627 {E_CONTENTS_TOO_LONG, "CONTENTS TOO LONG"},
628 {E_INVALID_PARAMETERS, "INVALID PARAMETERS"},
629 {E_INVALID_MESSAGE_TYPE, "INVALID MESSAGE TYPE"},
630 {E_INVALID_FLAGS, "INVALID FLAGS"},
631 {E_INVALID_TLV, "INVALID TLV"},
632 {E_EVENT_ERROR, "EVENT ERROR"},
633 {E_NOT_SUPPORTED, "NOT SUPPORTED"},
634 {E_MEMORY_ERROR, "MEMORY ERROR"},
635 {E_INTERNAL_ERROR, "INTERNAL ERROR"},
636 {E_UNSPECIFIED_ERROR, "UNSPECIFIED ERROR"},
637 {0, NULL}
638 };
639
640 #define RESLEN 4
641
642 static int
643 prestlv_print(netdissect_options *ndo,
644 register const u_char * pptr, register u_int len,
645 uint16_t op_msk _U_, int indent)
646 {
647 const struct forces_tlv *tlv = (struct forces_tlv *)pptr;
648 register const u_char *tdp = (u_char *) TLV_DATA(tlv);
649 struct res_val *r = (struct res_val *)tdp;
650 u_int dlen;
651
652 /*
653 * pdatacnt_print() has ensured that len (the TLV length)
654 * >= TLV_HDRL.
655 */
656 dlen = len - TLV_HDRL;
657 if (dlen != RESLEN) {
658 ND_PRINT((ndo, "illegal RESULT-TLV: %d bytes!\n", dlen));
659 return -1;
660 }
661
662 ND_TCHECK(*r);
663 if (r->result >= 0x18 && r->result <= 0xFE) {
664 ND_PRINT((ndo, "illegal reserved result code: 0x%x!\n", r->result));
665 return -1;
666 }
667
668 if (ndo->ndo_vflag >= 3) {
669 char *ib = indent_pr(indent, 0);
670 ND_PRINT((ndo, "%s Result: %s (code 0x%x)\n", ib,
671 tok2str(ForCES_errs, NULL, r->result), r->result));
672 }
673 return 0;
674
675 trunc:
676 ND_PRINT((ndo, "%s", tstr));
677 return -1;
678 }
679
680 static int
681 fdatatlv_print(netdissect_options *ndo,
682 register const u_char * pptr, register u_int len,
683 uint16_t op_msk _U_, int indent)
684 {
685 const struct forces_tlv *tlv = (struct forces_tlv *)pptr;
686 u_int rlen;
687 register const u_char *tdp = (u_char *) TLV_DATA(tlv);
688 uint16_t type;
689
690 /*
691 * pdatacnt_print() or pkeyitlv_print() has ensured that len
692 * (the TLV length) >= TLV_HDRL.
693 */
694 rlen = len - TLV_HDRL;
695 ND_TCHECK(*tlv);
696 type = EXTRACT_16BITS(&tlv->type);
697 if (type != F_TLV_FULD) {
698 ND_PRINT((ndo, "Error: expecting FULLDATA!\n"));
699 return -1;
700 }
701
702 if (ndo->ndo_vflag >= 3) {
703 char *ib = indent_pr(indent + 2, 1);
704 ND_PRINT((ndo, "%s[", &ib[1]));
705 hex_print_with_offset(ndo, ib, tdp, rlen, 0);
706 ND_PRINT((ndo, "\n%s]\n", &ib[1]));
707 }
708 return 0;
709
710 trunc:
711 ND_PRINT((ndo, "%s", tstr));
712 return -1;
713 }
714
715 static int
716 sdatailv_print(netdissect_options *ndo,
717 register const u_char * pptr, register u_int len,
718 uint16_t op_msk _U_, int indent)
719 {
720 u_int rlen;
721 const struct forces_ilv *ilv = (struct forces_ilv *)pptr;
722 int invilv;
723
724 if (len < ILV_HDRL) {
725 ND_PRINT((ndo, "Error: BAD SPARSEDATA-TLV!\n"));
726 return -1;
727 }
728 rlen = len;
729 indent += 1;
730 while (rlen != 0) {
731 #if 0
732 ND_PRINT((ndo, "Jamal - outstanding length <%d>\n", rlen));
733 #endif
734 char *ib = indent_pr(indent, 1);
735 register const u_char *tdp = (u_char *) ILV_DATA(ilv);
736 ND_TCHECK(*ilv);
737 invilv = ilv_valid(ilv, rlen);
738 if (invilv) {
739 ND_PRINT((ndo, "%s[", &ib[1]));
740 hex_print_with_offset(ndo, ib, tdp, rlen, 0);
741 ND_PRINT((ndo, "\n%s]\n", &ib[1]));
742 return -1;
743 }
744 if (ndo->ndo_vflag >= 3) {
745 int ilvl = EXTRACT_32BITS(&ilv->length);
746 ND_PRINT((ndo, "\n%s ILV: type %x length %d\n", &ib[1],
747 EXTRACT_32BITS(&ilv->type), ilvl));
748 hex_print_with_offset(ndo, "\t\t[", tdp, ilvl-ILV_HDRL, 0);
749 }
750
751 ilv = GO_NXT_ILV(ilv, rlen);
752 }
753
754 return 0;
755
756 trunc:
757 ND_PRINT((ndo, "%s", tstr));
758 return -1;
759 }
760
761 static int
762 sdatatlv_print(netdissect_options *ndo,
763 register const u_char * pptr, register u_int len,
764 uint16_t op_msk, int indent)
765 {
766 const struct forces_tlv *tlv = (struct forces_tlv *)pptr;
767 u_int rlen;
768 register const u_char *tdp = (u_char *) TLV_DATA(tlv);
769 uint16_t type;
770
771 /*
772 * pdatacnt_print() has ensured that len (the TLV length)
773 * >= TLV_HDRL.
774 */
775 rlen = len - TLV_HDRL;
776 ND_TCHECK(*tlv);
777 type = EXTRACT_16BITS(&tlv->type);
778 if (type != F_TLV_SPAD) {
779 ND_PRINT((ndo, "Error: expecting SPARSEDATA!\n"));
780 return -1;
781 }
782
783 return sdatailv_print(ndo, tdp, rlen, op_msk, indent);
784
785 trunc:
786 ND_PRINT((ndo, "%s", tstr));
787 return -1;
788 }
789
790 static int
791 pkeyitlv_print(netdissect_options *ndo,
792 register const u_char * pptr, register u_int len,
793 uint16_t op_msk, int indent)
794 {
795 const struct forces_tlv *tlv = (struct forces_tlv *)pptr;
796 register const u_char *tdp = (u_char *) TLV_DATA(tlv);
797 register const u_char *dp = tdp + 4;
798 const struct forces_tlv *kdtlv = (struct forces_tlv *)dp;
799 uint32_t id;
800 char *ib = indent_pr(indent, 0);
801 uint16_t type, tll;
802 u_int invtlv;
803
804 ND_TCHECK(*tdp);
805 id = EXTRACT_32BITS(tdp);
806 ND_PRINT((ndo, "%sKeyinfo: Key 0x%x\n", ib, id));
807 ND_TCHECK(*kdtlv);
808 type = EXTRACT_16BITS(&kdtlv->type);
809 invtlv = tlv_valid(kdtlv, len);
810
811 if (invtlv) {
812 ND_PRINT((ndo, "%s TLV type 0x%x len %d\n",
813 tok2str(ForCES_TLV_err, NULL, invtlv), type,
814 EXTRACT_16BITS(&kdtlv->length)));
815 return -1;
816 }
817 /*
818 * At this point, tlv_valid() has ensured that the TLV
819 * length is large enough but not too large (it doesn't
820 * go past the end of the containing TLV).
821 */
822 tll = EXTRACT_16BITS(&kdtlv->length);
823 dp = (u_char *) TLV_DATA(kdtlv);
824 return fdatatlv_print(ndo, dp, tll, op_msk, indent);
825
826 trunc:
827 ND_PRINT((ndo, "%s", tstr));
828 return -1;
829 }
830
831 #define PTH_DESC_SIZE 12
832
833 static int
834 pdatacnt_print(netdissect_options *ndo,
835 register const u_char * pptr, register u_int len,
836 uint16_t IDcnt, uint16_t op_msk, int indent)
837 {
838 u_int i;
839 uint32_t id;
840 char *ib = indent_pr(indent, 0);
841
842 if ((op_msk & B_APPND) && ndo->ndo_vflag >= 3) {
843 ND_PRINT((ndo, "%sTABLE APPEND\n", ib));
844 }
845 for (i = 0; i < IDcnt; i++) {
846 ND_TCHECK2(*pptr, 4);
847 if (len < 4)
848 goto trunc;
849 id = EXTRACT_32BITS(pptr);
850 if (ndo->ndo_vflag >= 3)
851 ND_PRINT((ndo, "%sID#%02u: %d\n", ib, i + 1, id));
852 len -= 4;
853 pptr += 4;
854 }
855
856 if ((op_msk & B_TRNG) || (op_msk & B_KEYIN)) {
857 if (op_msk & B_TRNG) {
858 uint32_t starti, endi;
859
860 if (len < PTH_DESC_SIZE) {
861 ND_PRINT((ndo, "pathlength %d with key/range too short %d\n",
862 len, PTH_DESC_SIZE));
863 return -1;
864 }
865
866 pptr += sizeof(struct forces_tlv);
867 len -= sizeof(struct forces_tlv);
868
869 starti = EXTRACT_32BITS(pptr);
870 pptr += 4;
871 len -= 4;
872
873 endi = EXTRACT_32BITS(pptr);
874 pptr += 4;
875 len -= 4;
876
877 if (ndo->ndo_vflag >= 3)
878 ND_PRINT((ndo, "%sTable range: [%d,%d]\n", ib, starti, endi));
879 }
880
881 if (op_msk & B_KEYIN) {
882 struct forces_tlv *keytlv;
883 uint16_t tll;
884
885 if (len < PTH_DESC_SIZE) {
886 ND_PRINT((ndo, "pathlength %d with key/range too short %d\n",
887 len, PTH_DESC_SIZE));
888 return -1;
889 }
890
891 /* skip keyid */
892 pptr += 4;
893 len -= 4;
894 keytlv = (struct forces_tlv *)pptr;
895 /* skip header */
896 pptr += sizeof(struct forces_tlv);
897 len -= sizeof(struct forces_tlv);
898 /* skip key content */
899 tll = EXTRACT_16BITS(&keytlv->length);
900 if (tll < TLV_HDRL) {
901 ND_PRINT((ndo, "key content length %u < %u\n",
902 tll, TLV_HDRL));
903 return -1;
904 }
905 tll -= TLV_HDRL;
906 if (len < tll) {
907 ND_PRINT((ndo, "key content too short\n"));
908 return -1;
909 }
910 pptr += tll;
911 len -= tll;
912 }
913
914 }
915
916 if (len) {
917 const struct forces_tlv *pdtlv = (struct forces_tlv *)pptr;
918 uint16_t type;
919 uint16_t tll;
920 int pad = 0;
921 u_int aln;
922 u_int invtlv;
923
924 ND_TCHECK(*pdtlv);
925 type = EXTRACT_16BITS(&pdtlv->type);
926 invtlv = tlv_valid(pdtlv, len);
927 if (invtlv) {
928 ND_PRINT((ndo, "%s Outstanding bytes %d for TLV type 0x%x TLV len %d\n",
929 tok2str(ForCES_TLV_err, NULL, invtlv), len, type,
930 EXTRACT_16BITS(&pdtlv->length)));
931 goto pd_err;
932 }
933 /*
934 * At this point, tlv_valid() has ensured that the TLV
935 * length is large enough but not too large (it doesn't
936 * go past the end of the containing TLV).
937 */
938 tll = EXTRACT_16BITS(&pdtlv->length) - TLV_HDRL;
939 aln = F_ALN_LEN(EXTRACT_16BITS(&pdtlv->length));
940 if (aln > EXTRACT_16BITS(&pdtlv->length)) {
941 if (aln > len) {
942 ND_PRINT((ndo,
943 "Invalid padded pathdata TLV type 0x%x len %d missing %d pad bytes\n",
944 type, EXTRACT_16BITS(&pdtlv->length), aln - len));
945 } else {
946 pad = aln - EXTRACT_16BITS(&pdtlv->length);
947 }
948 }
949 if (pd_valid(type)) {
950 const struct pdata_ops *ops = get_forces_pd(type);
951
952 if (ndo->ndo_vflag >= 3 && ops->v != F_TLV_PDAT) {
953 if (pad)
954 ND_PRINT((ndo, "%s %s (Length %d DataLen %d pad %d Bytes)\n",
955 ib, ops->s, EXTRACT_16BITS(&pdtlv->length), tll, pad));
956 else
957 ND_PRINT((ndo, "%s %s (Length %d DataLen %d Bytes)\n",
958 ib, ops->s, EXTRACT_16BITS(&pdtlv->length), tll));
959 }
960
961 chk_op_type(ndo, type, op_msk, ops->op_msk);
962
963 if (ops->print(ndo, (const u_char *)pdtlv,
964 tll + pad + TLV_HDRL, op_msk,
965 indent + 2) == -1)
966 return -1;
967 len -= (TLV_HDRL + pad + tll);
968 } else {
969 ND_PRINT((ndo, "Invalid path data content type 0x%x len %d\n",
970 type, EXTRACT_16BITS(&pdtlv->length)));
971 pd_err:
972 if (EXTRACT_16BITS(&pdtlv->length)) {
973 hex_print_with_offset(ndo, "Bad Data val\n\t [",
974 pptr, len, 0);
975 ND_PRINT((ndo, "]\n"));
976
977 return -1;
978 }
979 }
980 }
981 return len;
982
983 trunc:
984 ND_PRINT((ndo, "%s", tstr));
985 return -1;
986 }
987
988 static int
989 pdata_print(netdissect_options *ndo,
990 register const u_char * pptr, register u_int len,
991 uint16_t op_msk, int indent)
992 {
993 const struct pathdata_h *pdh = (struct pathdata_h *)pptr;
994 char *ib = indent_pr(indent, 0);
995 u_int minsize = 0;
996 int more_pd = 0;
997 uint16_t idcnt = 0;
998
999 ND_TCHECK(*pdh);
1000 if (len < sizeof(struct pathdata_h))
1001 goto trunc;
1002 if (ndo->ndo_vflag >= 3) {
1003 ND_PRINT((ndo, "\n%sPathdata: Flags 0x%x ID count %d\n",
1004 ib, EXTRACT_16BITS(&pdh->pflags), EXTRACT_16BITS(&pdh->pIDcnt)));
1005 }
1006
1007 if (EXTRACT_16BITS(&pdh->pflags) & F_SELKEY) {
1008 op_msk |= B_KEYIN;
1009 }
1010
1011 /* Table GET Range operation */
1012 if (EXTRACT_16BITS(&pdh->pflags) & F_SELTABRANGE) {
1013 op_msk |= B_TRNG;
1014 }
1015 /* Table SET append operation */
1016 if (EXTRACT_16BITS(&pdh->pflags) & F_TABAPPEND) {
1017 op_msk |= B_APPND;
1018 }
1019
1020 pptr += sizeof(struct pathdata_h);
1021 len -= sizeof(struct pathdata_h);
1022 idcnt = EXTRACT_16BITS(&pdh->pIDcnt);
1023 minsize = idcnt * 4;
1024 if (len < minsize) {
1025 ND_PRINT((ndo, "\t\t\ttruncated IDs expected %uB got %uB\n", minsize,
1026 len));
1027 hex_print_with_offset(ndo, "\t\t\tID Data[", pptr, len, 0);
1028 ND_PRINT((ndo, "]\n"));
1029 return -1;
1030 }
1031
1032 if ((op_msk & B_TRNG) && (op_msk & B_KEYIN)) {
1033 ND_PRINT((ndo, "\t\t\tIllegal to have both Table ranges and keys\n"));
1034 return -1;
1035 }
1036
1037 more_pd = pdatacnt_print(ndo, pptr, len, idcnt, op_msk, indent);
1038 if (more_pd > 0) {
1039 int consumed = len - more_pd;
1040 pptr += consumed;
1041 len = more_pd;
1042 /* XXX: Argh, recurse some more */
1043 return recpdoptlv_print(ndo, pptr, len, op_msk, indent+1);
1044 } else
1045 return 0;
1046
1047 trunc:
1048 ND_PRINT((ndo, "%s", tstr));
1049 return -1;
1050 }
1051
1052 static int
1053 genoptlv_print(netdissect_options *ndo,
1054 register const u_char * pptr, register u_int len,
1055 uint16_t op_msk, int indent)
1056 {
1057 const struct forces_tlv *pdtlv = (struct forces_tlv *)pptr;
1058 uint16_t type;
1059 int tll;
1060 u_int invtlv;
1061 char *ib = indent_pr(indent, 0);
1062
1063 ND_TCHECK(*pdtlv);
1064 type = EXTRACT_16BITS(&pdtlv->type);
1065 tll = EXTRACT_16BITS(&pdtlv->length) - TLV_HDRL;
1066 invtlv = tlv_valid(pdtlv, len);
1067 ND_PRINT((ndo, "genoptlvprint - %s TLV type 0x%x len %d\n",
1068 tok2str(ForCES_TLV, NULL, type), type, EXTRACT_16BITS(&pdtlv->length)));
1069 if (!invtlv) {
1070 /*
1071 * At this point, tlv_valid() has ensured that the TLV
1072 * length is large enough but not too large (it doesn't
1073 * go past the end of the containing TLV).
1074 */
1075 register const u_char *dp = (u_char *) TLV_DATA(pdtlv);
1076 if (!ttlv_valid(type)) {
1077 ND_PRINT((ndo, "%s TLV type 0x%x len %d\n",
1078 tok2str(ForCES_TLV_err, NULL, invtlv), type,
1079 EXTRACT_16BITS(&pdtlv->length)));
1080 return -1;
1081 }
1082 if (ndo->ndo_vflag >= 3)
1083 ND_PRINT((ndo, "%s%s, length %d (data length %d Bytes)",
1084 ib, tok2str(ForCES_TLV, NULL, type),
1085 EXTRACT_16BITS(&pdtlv->length), tll));
1086
1087 return pdata_print(ndo, dp, tll, op_msk, indent + 1);
1088 } else {
1089 ND_PRINT((ndo, "\t\t\tInvalid ForCES TLV type=%x", type));
1090 return -1;
1091 }
1092
1093 trunc:
1094 ND_PRINT((ndo, "%s", tstr));
1095 return -1;
1096 }
1097
1098 static int
1099 recpdoptlv_print(netdissect_options *ndo,
1100 register const u_char * pptr, register u_int len,
1101 uint16_t op_msk, int indent)
1102 {
1103 const struct forces_tlv *pdtlv = (struct forces_tlv *)pptr;
1104 int tll;
1105 u_int invtlv;
1106 uint16_t type;
1107 register const u_char *dp;
1108 char *ib;
1109
1110 while (len != 0) {
1111 ND_TCHECK(*pdtlv);
1112 invtlv = tlv_valid(pdtlv, len);
1113 if (invtlv) {
1114 break;
1115 }
1116
1117 /*
1118 * At this point, tlv_valid() has ensured that the TLV
1119 * length is large enough but not too large (it doesn't
1120 * go past the end of the containing TLV).
1121 */
1122 ib = indent_pr(indent, 0);
1123 type = EXTRACT_16BITS(&pdtlv->type);
1124 dp = (u_char *) TLV_DATA(pdtlv);
1125 tll = EXTRACT_16BITS(&pdtlv->length) - TLV_HDRL;
1126
1127 if (ndo->ndo_vflag >= 3)
1128 ND_PRINT((ndo, "%s%s, length %d (data encapsulated %d Bytes)",
1129 ib, tok2str(ForCES_TLV, NULL, type),
1130 EXTRACT_16BITS(&pdtlv->length),
1131 EXTRACT_16BITS(&pdtlv->length) - TLV_HDRL));
1132
1133 if (pdata_print(ndo, dp, tll, op_msk, indent + 1) == -1)
1134 return -1;
1135 pdtlv = GO_NXT_TLV(pdtlv, len);
1136 }
1137
1138 if (len) {
1139 ND_PRINT((ndo,
1140 "\n\t\tMessy PATHDATA TLV header, type (0x%x)\n\t\texcess of %d Bytes ",
1141 EXTRACT_16BITS(&pdtlv->type), len - EXTRACT_16BITS(&pdtlv->length)));
1142 return -1;
1143 }
1144
1145 return 0;
1146
1147 trunc:
1148 ND_PRINT((ndo, "%s", tstr));
1149 return -1;
1150 }
1151
1152 static int
1153 invoptlv_print(netdissect_options *ndo,
1154 register const u_char * pptr, register u_int len,
1155 uint16_t op_msk _U_, int indent)
1156 {
1157 char *ib = indent_pr(indent, 1);
1158
1159 if (ndo->ndo_vflag >= 3) {
1160 ND_PRINT((ndo, "%sData[", &ib[1]));
1161 hex_print_with_offset(ndo, ib, pptr, len, 0);
1162 ND_PRINT((ndo, "%s]\n", ib));
1163 }
1164 return -1;
1165 }
1166
1167 static int
1168 otlv_print(netdissect_options *ndo,
1169 const struct forces_tlv *otlv, uint16_t op_msk _U_, int indent)
1170 {
1171 int rc = 0;
1172 register const u_char *dp = (u_char *) TLV_DATA(otlv);
1173 uint16_t type;
1174 int tll;
1175 char *ib = indent_pr(indent, 0);
1176 const struct optlv_h *ops;
1177
1178 /*
1179 * lfbselect_print() has ensured that EXTRACT_16BITS(&otlv->length)
1180 * >= TLV_HDRL.
1181 */
1182 ND_TCHECK(*otlv);
1183 type = EXTRACT_16BITS(&otlv->type);
1184 tll = EXTRACT_16BITS(&otlv->length) - TLV_HDRL;
1185 ops = get_forces_optlv_h(type);
1186 if (ndo->ndo_vflag >= 3) {
1187 ND_PRINT((ndo, "%sOper TLV %s(0x%x) length %d\n", ib, ops->s, type,
1188 EXTRACT_16BITS(&otlv->length)));
1189 }
1190 /* rest of ops must at least have 12B {pathinfo} */
1191 if (tll < OP_MIN_SIZ) {
1192 ND_PRINT((ndo, "\t\tOper TLV %s(0x%x) length %d\n", ops->s, type,
1193 EXTRACT_16BITS(&otlv->length)));
1194 ND_PRINT((ndo, "\t\tTruncated data size %d minimum required %d\n", tll,
1195 OP_MIN_SIZ));
1196 return invoptlv_print(ndo, dp, tll, ops->op_msk, indent);
1197
1198 }
1199
1200 /* XXX - do anything with ops->flags? */
1201 rc = ops->print(ndo, dp, tll, ops->op_msk, indent + 1);
1202 return rc;
1203
1204 trunc:
1205 ND_PRINT((ndo, "%s", tstr));
1206 return -1;
1207 }
1208
1209 #define ASTDLN 4
1210 #define ASTMCD 255
1211 static int
1212 asttlv_print(netdissect_options *ndo,
1213 register const u_char * pptr, register u_int len,
1214 uint16_t op_msk _U_, int indent)
1215 {
1216 uint32_t rescode;
1217 u_int dlen;
1218 char *ib = indent_pr(indent, 0);
1219
1220 /*
1221 * forces_type_print() has ensured that len (the TLV length)
1222 * >= TLV_HDRL.
1223 */
1224 dlen = len - TLV_HDRL;
1225 if (dlen != ASTDLN) {
1226 ND_PRINT((ndo, "illegal ASTresult-TLV: %d bytes!\n", dlen));
1227 return -1;
1228 }
1229 ND_TCHECK2(*pptr, 4);
1230 rescode = EXTRACT_32BITS(pptr);
1231 if (rescode > ASTMCD) {
1232 ND_PRINT((ndo, "illegal ASTresult result code: %d!\n", rescode));
1233 return -1;
1234 }
1235
1236 if (ndo->ndo_vflag >= 3) {
1237 ND_PRINT((ndo, "Teardown reason:\n%s", ib));
1238 switch (rescode) {
1239 case 0:
1240 ND_PRINT((ndo, "Normal Teardown"));
1241 break;
1242 case 1:
1243 ND_PRINT((ndo, "Loss of Heartbeats"));
1244 break;
1245 case 2:
1246 ND_PRINT((ndo, "Out of bandwidth"));
1247 break;
1248 case 3:
1249 ND_PRINT((ndo, "Out of Memory"));
1250 break;
1251 case 4:
1252 ND_PRINT((ndo, "Application Crash"));
1253 break;
1254 default:
1255 ND_PRINT((ndo, "Unknown Teardown reason"));
1256 break;
1257 }
1258 ND_PRINT((ndo, "(%x)\n%s", rescode, ib));
1259 }
1260 return 0;
1261
1262 trunc:
1263 ND_PRINT((ndo, "%s", tstr));
1264 return -1;
1265 }
1266
1267 #define ASRDLN 4
1268 #define ASRMCD 3
1269 static int
1270 asrtlv_print(netdissect_options *ndo,
1271 register const u_char * pptr, register u_int len,
1272 uint16_t op_msk _U_, int indent)
1273 {
1274 uint32_t rescode;
1275 u_int dlen;
1276 char *ib = indent_pr(indent, 0);
1277
1278 /*
1279 * forces_type_print() has ensured that len (the TLV length)
1280 * >= TLV_HDRL.
1281 */
1282 dlen = len - TLV_HDRL;
1283 if (dlen != ASRDLN) { /* id, instance, oper tlv */
1284 ND_PRINT((ndo, "illegal ASRresult-TLV: %d bytes!\n", dlen));
1285 return -1;
1286 }
1287 ND_TCHECK2(*pptr, 4);
1288 rescode = EXTRACT_32BITS(pptr);
1289
1290 if (rescode > ASRMCD) {
1291 ND_PRINT((ndo, "illegal ASRresult result code: %d!\n", rescode));
1292 return -1;
1293 }
1294
1295 if (ndo->ndo_vflag >= 3) {
1296 ND_PRINT((ndo, "\n%s", ib));
1297 switch (rescode) {
1298 case 0:
1299 ND_PRINT((ndo, "Success "));
1300 break;
1301 case 1:
1302 ND_PRINT((ndo, "FE ID invalid "));
1303 break;
1304 case 2:
1305 ND_PRINT((ndo, "permission denied "));
1306 break;
1307 default:
1308 ND_PRINT((ndo, "Unknown "));
1309 break;
1310 }
1311 ND_PRINT((ndo, "(%x)\n%s", rescode, ib));
1312 }
1313 return 0;
1314
1315 trunc:
1316 ND_PRINT((ndo, "%s", tstr));
1317 return -1;
1318 }
1319
1320 #if 0
1321 /*
1322 * XXX - not used.
1323 */
1324 static int
1325 gentltlv_print(netdissect_options *ndo,
1326 register const u_char * pptr _U_, register u_int len,
1327 uint16_t op_msk _U_, int indent _U_)
1328 {
1329 u_int dlen = len - TLV_HDRL;
1330
1331 if (dlen < 4) { /* at least 32 bits must exist */
1332 ND_PRINT((ndo, "truncated TLV: %d bytes missing! ", 4 - dlen));
1333 return -1;
1334 }
1335 return 0;
1336 }
1337 #endif
1338
1339 #define RD_MIN 8
1340
1341 static int
1342 print_metailv(netdissect_options *ndo,
1343 register const u_char * pptr, uint16_t op_msk _U_, int indent)
1344 {
1345 u_int rlen;
1346 char *ib = indent_pr(indent, 0);
1347 /* XXX: check header length */
1348 const struct forces_ilv *ilv = (struct forces_ilv *)pptr;
1349
1350 /*
1351 * print_metatlv() has ensured that len (what remains in the
1352 * ILV) >= ILV_HDRL.
1353 */
1354 rlen = EXTRACT_32BITS(&ilv->length) - ILV_HDRL;
1355 ND_TCHECK(*ilv);
1356 ND_PRINT((ndo, "%sMetaID 0x%x length %d\n", ib, EXTRACT_32BITS(&ilv->type),
1357 EXTRACT_32BITS(&ilv->length)));
1358 if (ndo->ndo_vflag >= 3) {
1359 hex_print_with_offset(ndo, "\t\t[", ILV_DATA(ilv), rlen, 0);
1360 ND_PRINT((ndo, " ]\n"));
1361 }
1362 return 0;
1363
1364 trunc:
1365 ND_PRINT((ndo, "%s", tstr));
1366 return -1;
1367 }
1368
1369 static int
1370 print_metatlv(netdissect_options *ndo,
1371 register const u_char * pptr, register u_int len,
1372 uint16_t op_msk _U_, int indent)
1373 {
1374 u_int dlen;
1375 char *ib = indent_pr(indent, 0);
1376 u_int rlen;
1377 const struct forces_ilv *ilv = (struct forces_ilv *)pptr;
1378 int invilv;
1379
1380 /*
1381 * redirect_print() has ensured that len (what remains in the
1382 * TLV) >= TLV_HDRL.
1383 */
1384 dlen = len - TLV_HDRL;
1385 rlen = dlen;
1386 ND_PRINT((ndo, "\n%s METADATA length %d \n", ib, rlen));
1387 while (rlen != 0) {
1388 ND_TCHECK(*ilv);
1389 invilv = ilv_valid(ilv, rlen);
1390 if (invilv) {
1391 break;
1392 }
1393
1394 /*
1395 * At this point, ilv_valid() has ensured that the ILV
1396 * length is large enough but not too large (it doesn't
1397 * go past the end of the containing TLV).
1398 */
1399 print_metailv(ndo, (u_char *) ilv, 0, indent + 1);
1400 ilv = GO_NXT_ILV(ilv, rlen);
1401 }
1402
1403 return 0;
1404
1405 trunc:
1406 ND_PRINT((ndo, "%s", tstr));
1407 return -1;
1408 }
1409
1410
1411 static int
1412 print_reddata(netdissect_options *ndo,
1413 register const u_char * pptr, register u_int len,
1414 uint16_t op_msk _U_, int indent _U_)
1415 {
1416 u_int dlen;
1417 char *ib = indent_pr(indent, 0);
1418 u_int rlen;
1419
1420 dlen = len - TLV_HDRL;
1421 rlen = dlen;
1422 ND_PRINT((ndo, "\n%s Redirect Data length %d \n", ib, rlen));
1423
1424 if (ndo->ndo_vflag >= 3) {
1425 ND_PRINT((ndo, "\t\t["));
1426 hex_print_with_offset(ndo, "\n\t\t", pptr, rlen, 0);
1427 ND_PRINT((ndo, "\n\t\t]"));
1428 }
1429
1430 return 0;
1431 }
1432
1433 static int
1434 redirect_print(netdissect_options *ndo,
1435 register const u_char * pptr, register u_int len,
1436 uint16_t op_msk _U_, int indent)
1437 {
1438 const struct forces_tlv *tlv = (struct forces_tlv *)pptr;
1439 u_int dlen;
1440 u_int rlen;
1441 u_int invtlv;
1442
1443 /*
1444 * forces_type_print() has ensured that len (the TLV length)
1445 * >= TLV_HDRL.
1446 */
1447 dlen = len - TLV_HDRL;
1448 if (dlen <= RD_MIN) {
1449 ND_PRINT((ndo, "\n\t\ttruncated Redirect TLV: %d bytes missing! ",
1450 RD_MIN - dlen));
1451 return -1;
1452 }
1453
1454 rlen = dlen;
1455 indent += 1;
1456 while (rlen != 0) {
1457 ND_TCHECK(*tlv);
1458 invtlv = tlv_valid(tlv, rlen);
1459 if (invtlv) {
1460 ND_PRINT((ndo, "Bad Redirect data\n"));
1461 break;
1462 }
1463
1464 /*
1465 * At this point, tlv_valid() has ensured that the TLV
1466 * length is large enough but not too large (it doesn't
1467 * go past the end of the containing TLV).
1468 */
1469 if (EXTRACT_16BITS(&tlv->type) == F_TLV_METD) {
1470 print_metatlv(ndo, (u_char *) TLV_DATA(tlv),
1471 EXTRACT_16BITS(&tlv->length), 0, indent);
1472 } else if ((EXTRACT_16BITS(&tlv->type) == F_TLV_REDD)) {
1473 print_reddata(ndo, (u_char *) TLV_DATA(tlv),
1474 EXTRACT_16BITS(&tlv->length), 0, indent);
1475 } else {
1476 ND_PRINT((ndo, "Unknown REDIRECT TLV 0x%x len %d\n",
1477 EXTRACT_16BITS(&tlv->type),
1478 EXTRACT_16BITS(&tlv->length)));
1479 }
1480
1481 tlv = GO_NXT_TLV(tlv, rlen);
1482 }
1483
1484 if (rlen) {
1485 ND_PRINT((ndo,
1486 "\n\t\tMessy Redirect TLV header, type (0x%x)\n\t\texcess of %d Bytes ",
1487 EXTRACT_16BITS(&tlv->type),
1488 rlen - EXTRACT_16BITS(&tlv->length)));
1489 return -1;
1490 }
1491
1492 return 0;
1493
1494 trunc:
1495 ND_PRINT((ndo, "%s", tstr));
1496 return -1;
1497 }
1498
1499 #define OP_OFF 8
1500 #define OP_MIN 12
1501
1502 static int
1503 lfbselect_print(netdissect_options *ndo,
1504 register const u_char * pptr, register u_int len,
1505 uint16_t op_msk, int indent)
1506 {
1507 const struct forces_lfbsh *lfbs;
1508 const struct forces_tlv *otlv;
1509 char *ib = indent_pr(indent, 0);
1510 u_int dlen;
1511 u_int rlen;
1512 u_int invtlv;
1513
1514 /*
1515 * forces_type_print() has ensured that len (the TLV length)
1516 * >= TLV_HDRL.
1517 */
1518 dlen = len - TLV_HDRL;
1519 if (dlen <= OP_MIN) { /* id, instance, oper tlv header .. */
1520 ND_PRINT((ndo, "\n\t\ttruncated lfb selector: %d bytes missing! ",
1521 OP_MIN - dlen));
1522 return -1;
1523 }
1524
1525 /*
1526 * At this point, we know that dlen > OP_MIN; OP_OFF < OP_MIN, so
1527 * we also know that it's > OP_OFF.
1528 */
1529 rlen = dlen - OP_OFF;
1530
1531 lfbs = (const struct forces_lfbsh *)pptr;
1532 ND_TCHECK(*lfbs);
1533 if (ndo->ndo_vflag >= 3) {
1534 ND_PRINT((ndo, "\n%s%s(Classid %x) instance %x\n",
1535 ib, tok2str(ForCES_LFBs, NULL, EXTRACT_32BITS(&lfbs->class)),
1536 EXTRACT_32BITS(&lfbs->class),
1537 EXTRACT_32BITS(&lfbs->instance)));
1538 }
1539
1540 otlv = (struct forces_tlv *)(lfbs + 1);
1541
1542 indent += 1;
1543 while (rlen != 0) {
1544 ND_TCHECK(*otlv);
1545 invtlv = tlv_valid(otlv, rlen);
1546 if (invtlv)
1547 break;
1548
1549 /*
1550 * At this point, tlv_valid() has ensured that the TLV
1551 * length is large enough but not too large (it doesn't
1552 * go past the end of the containing TLV).
1553 */
1554 if (op_valid(EXTRACT_16BITS(&otlv->type), op_msk)) {
1555 otlv_print(ndo, otlv, 0, indent);
1556 } else {
1557 if (ndo->ndo_vflag < 3)
1558 ND_PRINT((ndo, "\n"));
1559 ND_PRINT((ndo,
1560 "\t\tINValid oper-TLV type 0x%x length %d for this ForCES message\n",
1561 EXTRACT_16BITS(&otlv->type), EXTRACT_16BITS(&otlv->length)));
1562 invoptlv_print(ndo, (u_char *)otlv, rlen, 0, indent);
1563 }
1564 otlv = GO_NXT_TLV(otlv, rlen);
1565 }
1566
1567 if (rlen) {
1568 ND_PRINT((ndo,
1569 "\n\t\tMessy oper TLV header, type (0x%x)\n\t\texcess of %d Bytes ",
1570 EXTRACT_16BITS(&otlv->type), rlen - EXTRACT_16BITS(&otlv->length)));
1571 return -1;
1572 }
1573
1574 return 0;
1575
1576 trunc:
1577 ND_PRINT((ndo, "%s", tstr));
1578 return -1;
1579 }
1580
1581 static int
1582 forces_type_print(netdissect_options *ndo,
1583 register const u_char * pptr, const struct forcesh *fhdr _U_,
1584 register u_int mlen, const struct tom_h *tops)
1585 {
1586 const struct forces_tlv *tltlv;
1587 u_int rlen;
1588 u_int invtlv;
1589 int rc = 0;
1590 int ttlv = 0;
1591
1592 /*
1593 * forces_print() has already checked that mlen >= ForCES_HDRL
1594 * by calling ForCES_HLN_VALID().
1595 */
1596 rlen = mlen - ForCES_HDRL;
1597
1598 if (rlen > TLV_HLN) {
1599 if (tops->flags & ZERO_TTLV) {
1600 ND_PRINT((ndo, "<0x%x>Illegal Top level TLV!\n", tops->flags));
1601 return -1;
1602 }
1603 } else {
1604 if (tops->flags & ZERO_MORE_TTLV)
1605 return 0;
1606 if (tops->flags & ONE_MORE_TTLV) {
1607 ND_PRINT((ndo, "\tTop level TLV Data missing!\n"));
1608 return -1;
1609 }
1610 }
1611
1612 if (tops->flags & ZERO_TTLV) {
1613 return 0;
1614 }
1615
1616 ttlv = tops->flags >> 4;
1617 tltlv = GET_TOP_TLV(pptr);
1618
1619 /*XXX: 15 top level tlvs will probably be fine
1620 You are nuts if you send more ;-> */
1621 while (rlen != 0) {
1622 ND_TCHECK(*tltlv);
1623 invtlv = tlv_valid(tltlv, rlen);
1624 if (invtlv)
1625 break;
1626
1627 /*
1628 * At this point, tlv_valid() has ensured that the TLV
1629 * length is large enough but not too large (it doesn't
1630 * go past the end of the packet).
1631 */
1632 if (!ttlv_valid(EXTRACT_16BITS(&tltlv->type))) {
1633 ND_PRINT((ndo, "\n\tInvalid ForCES Top TLV type=0x%x",
1634 EXTRACT_16BITS(&tltlv->type)));
1635 return -1;
1636 }
1637
1638 if (ndo->ndo_vflag >= 3)
1639 ND_PRINT((ndo, "\t%s, length %d (data length %d Bytes)",
1640 tok2str(ForCES_TLV, NULL, EXTRACT_16BITS(&tltlv->type)),
1641 EXTRACT_16BITS(&tltlv->length),
1642 EXTRACT_16BITS(&tltlv->length) - TLV_HDRL));
1643
1644 rc = tops->print(ndo, (u_char *) TLV_DATA(tltlv),
1645 EXTRACT_16BITS(&tltlv->length), tops->op_msk, 9);
1646 if (rc < 0) {
1647 return -1;
1648 }
1649 tltlv = GO_NXT_TLV(tltlv, rlen);
1650 ttlv--;
1651 if (ttlv <= 0)
1652 break;
1653 }
1654 /*
1655 * XXX - if ttlv != 0, does that mean that the packet was too
1656 * short, and didn't have *enough* TLVs in it?
1657 */
1658 if (rlen) {
1659 ND_PRINT((ndo, "\tMess TopTLV header: min %u, total %d advertised %d ",
1660 TLV_HDRL, rlen, EXTRACT_16BITS(&tltlv->length)));
1661 return -1;
1662 }
1663
1664 return 0;
1665
1666 trunc:
1667 ND_PRINT((ndo, "%s", tstr));
1668 return -1;
1669 }
1670
1671 void
1672 forces_print(netdissect_options *ndo,
1673 register const u_char * pptr, register u_int len)
1674 {
1675 const struct forcesh *fhdr;
1676 u_int mlen;
1677 uint32_t flg_raw;
1678 const struct tom_h *tops;
1679 int rc = 0;
1680
1681 fhdr = (const struct forcesh *)pptr;
1682 ND_TCHECK(*fhdr);
1683 if (!tom_valid(fhdr->fm_tom)) {
1684 ND_PRINT((ndo, "Invalid ForCES message type %d\n", fhdr->fm_tom));
1685 goto error;
1686 }
1687
1688 mlen = ForCES_BLN(fhdr);
1689
1690 tops = get_forces_tom(fhdr->fm_tom);
1691 if (tops->v == TOM_RSVD) {
1692 ND_PRINT((ndo, "\n\tUnknown ForCES message type=0x%x", fhdr->fm_tom));
1693 goto error;
1694 }
1695
1696 ND_PRINT((ndo, "\n\tForCES %s ", tops->s));
1697 if (!ForCES_HLN_VALID(mlen, len)) {
1698 ND_PRINT((ndo,
1699 "Illegal ForCES pkt len - min %u, total recvd %d, advertised %d ",
1700 ForCES_HDRL, len, ForCES_BLN(fhdr)));
1701 goto error;
1702 }
1703
1704 ND_TCHECK2(*(pptr + 20), 4);
1705 flg_raw = EXTRACT_32BITS(pptr + 20);
1706 if (ndo->ndo_vflag >= 1) {
1707 ND_PRINT((ndo, "\n\tForCES Version %d len %uB flags 0x%08x ",
1708 ForCES_V(fhdr), mlen, flg_raw));
1709 ND_PRINT((ndo,
1710 "\n\tSrcID 0x%x(%s) DstID 0x%x(%s) Correlator 0x%" PRIx64,
1711 ForCES_SID(fhdr), ForCES_node(ForCES_SID(fhdr)),
1712 ForCES_DID(fhdr), ForCES_node(ForCES_DID(fhdr)),
1713 EXTRACT_64BITS(fhdr->fm_cor)));
1714
1715 }
1716 if (ndo->ndo_vflag >= 2) {
1717 ND_PRINT((ndo,
1718 "\n\tForCES flags:\n\t %s(0x%x), prio=%d, %s(0x%x),\n\t %s(0x%x), %s(0x%x)\n",
1719 tok2str(ForCES_ACKs, "ACKUnknown", ForCES_ACK(fhdr)),
1720 ForCES_ACK(fhdr),
1721 ForCES_PRI(fhdr),
1722 tok2str(ForCES_EMs, "EMUnknown", ForCES_EM(fhdr)),
1723 ForCES_EM(fhdr),
1724 tok2str(ForCES_ATs, "ATUnknown", ForCES_AT(fhdr)),
1725 ForCES_AT(fhdr),
1726 tok2str(ForCES_TPs, "TPUnknown", ForCES_TP(fhdr)),
1727 ForCES_TP(fhdr)));
1728 ND_PRINT((ndo,
1729 "\t Extra flags: rsv(b5-7) 0x%x rsv(b13-31) 0x%x\n",
1730 ForCES_RS1(fhdr), ForCES_RS2(fhdr)));
1731 }
1732 rc = forces_type_print(ndo, pptr, fhdr, mlen, tops);
1733 if (rc < 0) {
1734 error:
1735 hex_print_with_offset(ndo, "\n\t[", pptr, len, 0);
1736 ND_PRINT((ndo, "\n\t]"));
1737 return;
1738 }
1739
1740 if (ndo->ndo_vflag >= 4) {
1741 ND_PRINT((ndo, "\n\t Raw ForCES message\n\t ["));
1742 hex_print_with_offset(ndo, "\n\t ", pptr, len, 0);
1743 ND_PRINT((ndo, "\n\t ]"));
1744 }
1745 ND_PRINT((ndo, "\n"));
1746 return;
1747
1748 trunc:
1749 ND_PRINT((ndo, "%s", tstr));
1750 }
1751 /*
1752 * Local Variables:
1753 * c-style: whitesmith
1754 * c-basic-offset: 8
1755 * End:
1756 */