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