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