]> The Tcpdump Group git mirrors - tcpdump/blob - print-forces.c
Remove unneeded '&' when getting a pointer to an nd_uintN_t type
[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(const struct forces_tlv *tlv, u_int rlen)
412 {
413 if (rlen < TLV_HDRL)
414 return INVALID_RLEN;
415 if (EXTRACT_BE_U_2(tlv->length) < TLV_HDRL)
416 return INVALID_STLN;
417 if (EXTRACT_BE_U_2(tlv->length) > rlen)
418 return INVALID_LTLN;
419 if (rlen < F_ALN_LEN(EXTRACT_BE_U_2(tlv->length)))
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: %d 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 <%d>\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 int ilvl = EXTRACT_BE_U_4(ilv->length);
744 ND_PRINT("\n%s ILV: type %x length %d\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 invtlv = tlv_valid(kdtlv, len);
808
809 if (invtlv) {
810 ND_PRINT("%s TLV type 0x%x len %d\n",
811 tok2str(ForCES_TLV_err, NULL, invtlv), type,
812 EXTRACT_BE_U_2(kdtlv->length));
813 return -1;
814 }
815 /*
816 * At this point, tlv_valid() has ensured that the TLV
817 * length is large enough but not too large (it doesn't
818 * go past the end of the containing TLV).
819 */
820 tll = EXTRACT_BE_U_2(kdtlv->length);
821 dp = (const u_char *) TLV_DATA(kdtlv);
822 return fdatatlv_print(ndo, dp, tll, op_msk, indent);
823
824 trunc:
825 ND_PRINT("%s", tstr);
826 return -1;
827 }
828
829 #define PTH_DESC_SIZE 12
830
831 static int
832 pdatacnt_print(netdissect_options *ndo,
833 const u_char * pptr, u_int len,
834 uint16_t IDcnt, uint16_t op_msk, int indent)
835 {
836 u_int i;
837 uint32_t id;
838 char *ib = indent_pr(indent, 0);
839
840 if ((op_msk & B_APPND) && ndo->ndo_vflag >= 3) {
841 ND_PRINT("%sTABLE APPEND\n", ib);
842 }
843 for (i = 0; i < IDcnt; i++) {
844 ND_TCHECK_4(pptr);
845 if (len < 4)
846 goto trunc;
847 id = EXTRACT_BE_U_4(pptr);
848 if (ndo->ndo_vflag >= 3)
849 ND_PRINT("%sID#%02u: %d\n", ib, i + 1, id);
850 len -= 4;
851 pptr += 4;
852 }
853
854 if ((op_msk & B_TRNG) || (op_msk & B_KEYIN)) {
855 if (op_msk & B_TRNG) {
856 uint32_t starti, endi;
857
858 if (len < PTH_DESC_SIZE) {
859 ND_PRINT("pathlength %d with key/range too short %d\n",
860 len, PTH_DESC_SIZE);
861 return -1;
862 }
863
864 pptr += sizeof(struct forces_tlv);
865 len -= sizeof(struct forces_tlv);
866
867 starti = EXTRACT_BE_U_4(pptr);
868 pptr += 4;
869 len -= 4;
870
871 endi = EXTRACT_BE_U_4(pptr);
872 pptr += 4;
873 len -= 4;
874
875 if (ndo->ndo_vflag >= 3)
876 ND_PRINT("%sTable range: [%d,%d]\n", ib, starti, endi);
877 }
878
879 if (op_msk & B_KEYIN) {
880 const struct forces_tlv *keytlv;
881 uint16_t tll;
882
883 if (len < PTH_DESC_SIZE) {
884 ND_PRINT("pathlength %d with key/range too short %d\n",
885 len, PTH_DESC_SIZE);
886 return -1;
887 }
888
889 /* skip keyid */
890 pptr += 4;
891 len -= 4;
892 keytlv = (const struct forces_tlv *)pptr;
893 /* skip header */
894 pptr += sizeof(struct forces_tlv);
895 len -= sizeof(struct forces_tlv);
896 /* skip key content */
897 tll = EXTRACT_BE_U_2(keytlv->length);
898 if (tll < TLV_HDRL) {
899 ND_PRINT("key content length %u < %u\n",
900 tll, TLV_HDRL);
901 return -1;
902 }
903 tll -= TLV_HDRL;
904 if (len < tll) {
905 ND_PRINT("key content too short\n");
906 return -1;
907 }
908 pptr += tll;
909 len -= tll;
910 }
911
912 }
913
914 if (len) {
915 const struct forces_tlv *pdtlv = (const struct forces_tlv *)pptr;
916 uint16_t type;
917 uint16_t tll;
918 int pad = 0;
919 u_int aln;
920 u_int invtlv;
921
922 ND_TCHECK_SIZE(pdtlv);
923 type = EXTRACT_BE_U_2(pdtlv->type);
924 invtlv = tlv_valid(pdtlv, len);
925 if (invtlv) {
926 ND_PRINT("%s Outstanding bytes %d for TLV type 0x%x TLV len %d\n",
927 tok2str(ForCES_TLV_err, NULL, invtlv), len, type,
928 EXTRACT_BE_U_2(pdtlv->length));
929 goto pd_err;
930 }
931 /*
932 * At this point, tlv_valid() has ensured that the TLV
933 * length is large enough but not too large (it doesn't
934 * go past the end of the containing TLV).
935 */
936 tll = EXTRACT_BE_U_2(pdtlv->length) - TLV_HDRL;
937 aln = F_ALN_LEN(EXTRACT_BE_U_2(pdtlv->length));
938 if (aln > EXTRACT_BE_U_2(pdtlv->length)) {
939 if (aln > len) {
940 ND_PRINT("Invalid padded pathdata TLV type 0x%x len %d missing %d pad bytes\n",
941 type, EXTRACT_BE_U_2(pdtlv->length),
942 aln - len);
943 } else {
944 pad = aln - EXTRACT_BE_U_2(pdtlv->length);
945 }
946 }
947 if (pd_valid(type)) {
948 const struct pdata_ops *ops = get_forces_pd(type);
949
950 if (ndo->ndo_vflag >= 3 && ops->v != F_TLV_PDAT) {
951 if (pad)
952 ND_PRINT("%s %s (Length %d DataLen %d pad %d Bytes)\n",
953 ib, ops->s,
954 EXTRACT_BE_U_2(pdtlv->length),
955 tll, pad);
956 else
957 ND_PRINT("%s %s (Length %d DataLen %d Bytes)\n",
958 ib, ops->s,
959 EXTRACT_BE_U_2(pdtlv->length),
960 tll);
961 }
962
963 chk_op_type(ndo, type, op_msk, ops->op_msk);
964
965 if (ops->print(ndo, (const u_char *)pdtlv,
966 tll + pad + TLV_HDRL, op_msk,
967 indent + 2) == -1)
968 return -1;
969 len -= (TLV_HDRL + pad + tll);
970 } else {
971 ND_PRINT("Invalid path data content type 0x%x len %d\n",
972 type, EXTRACT_BE_U_2(pdtlv->length));
973 pd_err:
974 if (EXTRACT_BE_U_2(pdtlv->length)) {
975 hex_print_with_offset(ndo, "Bad Data val\n\t [",
976 pptr, len, 0);
977 ND_PRINT("]\n");
978
979 return -1;
980 }
981 }
982 }
983 return len;
984
985 trunc:
986 ND_PRINT("%s", tstr);
987 return -1;
988 }
989
990 static int
991 pdata_print(netdissect_options *ndo,
992 const u_char * pptr, u_int len,
993 uint16_t op_msk, int indent)
994 {
995 const struct pathdata_h *pdh = (const struct pathdata_h *)pptr;
996 char *ib = indent_pr(indent, 0);
997 u_int minsize = 0;
998 int more_pd = 0;
999 uint16_t idcnt = 0;
1000
1001 ND_TCHECK_SIZE(pdh);
1002 if (len < sizeof(struct pathdata_h))
1003 goto trunc;
1004 if (ndo->ndo_vflag >= 3) {
1005 ND_PRINT("\n%sPathdata: Flags 0x%x ID count %d\n",
1006 ib, EXTRACT_BE_U_2(pdh->pflags),
1007 EXTRACT_BE_U_2(pdh->pIDcnt));
1008 }
1009
1010 if (EXTRACT_BE_U_2(pdh->pflags) & F_SELKEY) {
1011 op_msk |= B_KEYIN;
1012 }
1013
1014 /* Table GET Range operation */
1015 if (EXTRACT_BE_U_2(pdh->pflags) & F_SELTABRANGE) {
1016 op_msk |= B_TRNG;
1017 }
1018 /* Table SET append operation */
1019 if (EXTRACT_BE_U_2(pdh->pflags) & F_TABAPPEND) {
1020 op_msk |= B_APPND;
1021 }
1022
1023 pptr += sizeof(struct pathdata_h);
1024 len -= sizeof(struct pathdata_h);
1025 idcnt = EXTRACT_BE_U_2(pdh->pIDcnt);
1026 minsize = idcnt * 4;
1027 if (len < minsize) {
1028 ND_PRINT("\t\t\ttruncated IDs expected %uB got %uB\n", minsize,
1029 len);
1030 hex_print_with_offset(ndo, "\t\t\tID Data[", pptr, len, 0);
1031 ND_PRINT("]\n");
1032 return -1;
1033 }
1034
1035 if ((op_msk & B_TRNG) && (op_msk & B_KEYIN)) {
1036 ND_PRINT("\t\t\tIllegal to have both Table ranges and keys\n");
1037 return -1;
1038 }
1039
1040 more_pd = pdatacnt_print(ndo, pptr, len, idcnt, op_msk, indent);
1041 if (more_pd > 0) {
1042 int consumed = len - more_pd;
1043 pptr += consumed;
1044 len = more_pd;
1045 /* XXX: Argh, recurse some more */
1046 return recpdoptlv_print(ndo, pptr, len, op_msk, indent+1);
1047 } else
1048 return 0;
1049
1050 trunc:
1051 ND_PRINT("%s", tstr);
1052 return -1;
1053 }
1054
1055 static int
1056 genoptlv_print(netdissect_options *ndo,
1057 const u_char * pptr, u_int len,
1058 uint16_t op_msk, int indent)
1059 {
1060 const struct forces_tlv *pdtlv = (const struct forces_tlv *)pptr;
1061 uint16_t type;
1062 int tll;
1063 u_int invtlv;
1064 char *ib = indent_pr(indent, 0);
1065
1066 ND_TCHECK_SIZE(pdtlv);
1067 type = EXTRACT_BE_U_2(pdtlv->type);
1068 tll = EXTRACT_BE_U_2(pdtlv->length) - TLV_HDRL;
1069 invtlv = tlv_valid(pdtlv, len);
1070 ND_PRINT("genoptlvprint - %s TLV type 0x%x len %d\n",
1071 tok2str(ForCES_TLV, NULL, type), type,
1072 EXTRACT_BE_U_2(pdtlv->length));
1073 if (!invtlv) {
1074 /*
1075 * At this point, tlv_valid() has ensured that the TLV
1076 * length is large enough but not too large (it doesn't
1077 * go past the end of the containing TLV).
1078 */
1079 const u_char *dp = (const u_char *) TLV_DATA(pdtlv);
1080 if (!ttlv_valid(type)) {
1081 ND_PRINT("%s TLV type 0x%x len %d\n",
1082 tok2str(ForCES_TLV_err, NULL, invtlv), type,
1083 EXTRACT_BE_U_2(pdtlv->length));
1084 return -1;
1085 }
1086 if (ndo->ndo_vflag >= 3)
1087 ND_PRINT("%s%s, length %d (data length %d Bytes)",
1088 ib, tok2str(ForCES_TLV, NULL, type),
1089 EXTRACT_BE_U_2(pdtlv->length), tll);
1090
1091 return pdata_print(ndo, dp, tll, op_msk, indent + 1);
1092 } else {
1093 ND_PRINT("\t\t\tInvalid ForCES TLV type=%x", type);
1094 return -1;
1095 }
1096
1097 trunc:
1098 ND_PRINT("%s", tstr);
1099 return -1;
1100 }
1101
1102 static int
1103 recpdoptlv_print(netdissect_options *ndo,
1104 const u_char * pptr, u_int len,
1105 uint16_t op_msk, int indent)
1106 {
1107 const struct forces_tlv *pdtlv = (const struct forces_tlv *)pptr;
1108 int tll;
1109 u_int invtlv;
1110 uint16_t type;
1111 const u_char *dp;
1112 char *ib;
1113
1114 while (len != 0) {
1115 ND_TCHECK_SIZE(pdtlv);
1116 invtlv = tlv_valid(pdtlv, len);
1117 if (invtlv) {
1118 break;
1119 }
1120
1121 /*
1122 * At this point, tlv_valid() has ensured that the TLV
1123 * length is large enough but not too large (it doesn't
1124 * go past the end of the containing TLV).
1125 */
1126 ib = indent_pr(indent, 0);
1127 type = EXTRACT_BE_U_2(pdtlv->type);
1128 dp = (const u_char *) TLV_DATA(pdtlv);
1129 tll = EXTRACT_BE_U_2(pdtlv->length) - TLV_HDRL;
1130
1131 if (ndo->ndo_vflag >= 3)
1132 ND_PRINT("%s%s, length %d (data encapsulated %d Bytes)",
1133 ib, tok2str(ForCES_TLV, NULL, type),
1134 EXTRACT_BE_U_2(pdtlv->length),
1135 EXTRACT_BE_U_2(pdtlv->length) - TLV_HDRL);
1136
1137 if (pdata_print(ndo, dp, tll, op_msk, indent + 1) == -1)
1138 return -1;
1139 pdtlv = GO_NXT_TLV(pdtlv, len);
1140 }
1141
1142 if (len) {
1143 ND_PRINT("\n\t\tMessy PATHDATA TLV header, type (0x%x)\n\t\texcess of %d Bytes ",
1144 EXTRACT_BE_U_2(pdtlv->type),
1145 len - EXTRACT_BE_U_2(pdtlv->length));
1146 return -1;
1147 }
1148
1149 return 0;
1150
1151 trunc:
1152 ND_PRINT("%s", tstr);
1153 return -1;
1154 }
1155
1156 static int
1157 invoptlv_print(netdissect_options *ndo,
1158 const u_char * pptr, u_int len,
1159 uint16_t op_msk _U_, int indent)
1160 {
1161 char *ib = indent_pr(indent, 1);
1162
1163 if (ndo->ndo_vflag >= 3) {
1164 ND_PRINT("%sData[", ib + 1);
1165 hex_print_with_offset(ndo, ib, pptr, len, 0);
1166 ND_PRINT("%s]\n", ib);
1167 }
1168 return -1;
1169 }
1170
1171 static int
1172 otlv_print(netdissect_options *ndo,
1173 const struct forces_tlv *otlv, uint16_t op_msk _U_, int indent)
1174 {
1175 int rc = 0;
1176 const u_char *dp = (const u_char *) TLV_DATA(otlv);
1177 uint16_t type;
1178 int tll;
1179 char *ib = indent_pr(indent, 0);
1180 const struct optlv_h *ops;
1181
1182 /*
1183 * lfbselect_print() has ensured that EXTRACT_BE_U_2(otlv->length)
1184 * >= TLV_HDRL.
1185 */
1186 ND_TCHECK_SIZE(otlv);
1187 type = EXTRACT_BE_U_2(otlv->type);
1188 tll = EXTRACT_BE_U_2(otlv->length) - TLV_HDRL;
1189 ops = get_forces_optlv_h(type);
1190 if (ndo->ndo_vflag >= 3) {
1191 ND_PRINT("%sOper TLV %s(0x%x) length %d\n", ib, ops->s, type,
1192 EXTRACT_BE_U_2(otlv->length));
1193 }
1194 /* rest of ops must at least have 12B {pathinfo} */
1195 if (tll < OP_MIN_SIZ) {
1196 ND_PRINT("\t\tOper TLV %s(0x%x) length %d\n", ops->s, type,
1197 EXTRACT_BE_U_2(otlv->length));
1198 ND_PRINT("\t\tTruncated data size %d minimum required %d\n", tll,
1199 OP_MIN_SIZ);
1200 return invoptlv_print(ndo, dp, tll, ops->op_msk, indent);
1201
1202 }
1203
1204 /* XXX - do anything with ops->flags? */
1205 if(ops->print) {
1206 rc = ops->print(ndo, dp, tll, ops->op_msk, indent + 1);
1207 }
1208 return rc;
1209
1210 trunc:
1211 ND_PRINT("%s", tstr);
1212 return -1;
1213 }
1214
1215 #define ASTDLN 4
1216 #define ASTMCD 255
1217 static int
1218 asttlv_print(netdissect_options *ndo,
1219 const u_char * pptr, u_int len,
1220 uint16_t op_msk _U_, int indent)
1221 {
1222 uint32_t rescode;
1223 u_int dlen;
1224 char *ib = indent_pr(indent, 0);
1225
1226 /*
1227 * forces_type_print() has ensured that len (the TLV length)
1228 * >= TLV_HDRL.
1229 */
1230 dlen = len - TLV_HDRL;
1231 if (dlen != ASTDLN) {
1232 ND_PRINT("illegal ASTresult-TLV: %d bytes!\n", dlen);
1233 return -1;
1234 }
1235 ND_TCHECK_4(pptr);
1236 rescode = EXTRACT_BE_U_4(pptr);
1237 if (rescode > ASTMCD) {
1238 ND_PRINT("illegal ASTresult result code: %d!\n", rescode);
1239 return -1;
1240 }
1241
1242 if (ndo->ndo_vflag >= 3) {
1243 ND_PRINT("Teardown reason:\n%s", ib);
1244 switch (rescode) {
1245 case 0:
1246 ND_PRINT("Normal Teardown");
1247 break;
1248 case 1:
1249 ND_PRINT("Loss of Heartbeats");
1250 break;
1251 case 2:
1252 ND_PRINT("Out of bandwidth");
1253 break;
1254 case 3:
1255 ND_PRINT("Out of Memory");
1256 break;
1257 case 4:
1258 ND_PRINT("Application Crash");
1259 break;
1260 default:
1261 ND_PRINT("Unknown Teardown reason");
1262 break;
1263 }
1264 ND_PRINT("(%x)\n%s", rescode, ib);
1265 }
1266 return 0;
1267
1268 trunc:
1269 ND_PRINT("%s", tstr);
1270 return -1;
1271 }
1272
1273 #define ASRDLN 4
1274 #define ASRMCD 3
1275 static int
1276 asrtlv_print(netdissect_options *ndo,
1277 const u_char * pptr, u_int len,
1278 uint16_t op_msk _U_, int indent)
1279 {
1280 uint32_t rescode;
1281 u_int dlen;
1282 char *ib = indent_pr(indent, 0);
1283
1284 /*
1285 * forces_type_print() has ensured that len (the TLV length)
1286 * >= TLV_HDRL.
1287 */
1288 dlen = len - TLV_HDRL;
1289 if (dlen != ASRDLN) { /* id, instance, oper tlv */
1290 ND_PRINT("illegal ASRresult-TLV: %d bytes!\n", dlen);
1291 return -1;
1292 }
1293 ND_TCHECK_4(pptr);
1294 rescode = EXTRACT_BE_U_4(pptr);
1295
1296 if (rescode > ASRMCD) {
1297 ND_PRINT("illegal ASRresult result code: %d!\n", rescode);
1298 return -1;
1299 }
1300
1301 if (ndo->ndo_vflag >= 3) {
1302 ND_PRINT("\n%s", ib);
1303 switch (rescode) {
1304 case 0:
1305 ND_PRINT("Success ");
1306 break;
1307 case 1:
1308 ND_PRINT("FE ID invalid ");
1309 break;
1310 case 2:
1311 ND_PRINT("permission denied ");
1312 break;
1313 default:
1314 ND_PRINT("Unknown ");
1315 break;
1316 }
1317 ND_PRINT("(%x)\n%s", rescode, ib);
1318 }
1319 return 0;
1320
1321 trunc:
1322 ND_PRINT("%s", tstr);
1323 return -1;
1324 }
1325
1326 #if 0
1327 /*
1328 * XXX - not used.
1329 */
1330 static int
1331 gentltlv_print(netdissect_options *ndo,
1332 const u_char * pptr _U_, u_int len,
1333 uint16_t op_msk _U_, int indent _U_)
1334 {
1335 u_int dlen = len - TLV_HDRL;
1336
1337 if (dlen < 4) { /* at least 32 bits must exist */
1338 ND_PRINT("truncated TLV: %d bytes missing! ", 4 - dlen);
1339 return -1;
1340 }
1341 return 0;
1342 }
1343 #endif
1344
1345 #define RD_MIN 8
1346
1347 static int
1348 print_metailv(netdissect_options *ndo,
1349 const u_char * pptr, uint16_t op_msk _U_, int indent)
1350 {
1351 u_int rlen;
1352 char *ib = indent_pr(indent, 0);
1353 /* XXX: check header length */
1354 const struct forces_ilv *ilv = (const struct forces_ilv *)pptr;
1355
1356 /*
1357 * print_metatlv() has ensured that len (what remains in the
1358 * ILV) >= ILV_HDRL.
1359 */
1360 rlen = EXTRACT_BE_U_4(ilv->length) - ILV_HDRL;
1361 ND_TCHECK_SIZE(ilv);
1362 ND_PRINT("%sMetaID 0x%x length %d\n", ib, EXTRACT_BE_U_4(ilv->type),
1363 EXTRACT_BE_U_4(ilv->length));
1364 if (ndo->ndo_vflag >= 3) {
1365 hex_print_with_offset(ndo, "\t\t[", ILV_DATA(ilv), rlen, 0);
1366 ND_PRINT(" ]\n");
1367 }
1368 return 0;
1369
1370 trunc:
1371 ND_PRINT("%s", tstr);
1372 return -1;
1373 }
1374
1375 static int
1376 print_metatlv(netdissect_options *ndo,
1377 const u_char * pptr, u_int len,
1378 uint16_t op_msk _U_, int indent)
1379 {
1380 u_int dlen;
1381 char *ib = indent_pr(indent, 0);
1382 u_int rlen;
1383 const struct forces_ilv *ilv = (const struct forces_ilv *)pptr;
1384 int invilv;
1385
1386 /*
1387 * redirect_print() has ensured that len (what remains in the
1388 * TLV) >= TLV_HDRL.
1389 */
1390 dlen = len - TLV_HDRL;
1391 rlen = dlen;
1392 ND_PRINT("\n%s METADATA length %d \n", ib, rlen);
1393 while (rlen != 0) {
1394 ND_TCHECK_SIZE(ilv);
1395 invilv = ilv_valid(ilv, rlen);
1396 if (invilv) {
1397 break;
1398 }
1399
1400 /*
1401 * At this point, ilv_valid() has ensured that the ILV
1402 * length is large enough but not too large (it doesn't
1403 * go past the end of the containing TLV).
1404 */
1405 print_metailv(ndo, (const u_char *) ilv, 0, indent + 1);
1406 ilv = GO_NXT_ILV(ilv, rlen);
1407 }
1408
1409 return 0;
1410
1411 trunc:
1412 ND_PRINT("%s", tstr);
1413 return -1;
1414 }
1415
1416
1417 static int
1418 print_reddata(netdissect_options *ndo,
1419 const u_char * pptr, u_int len,
1420 uint16_t op_msk _U_, int indent)
1421 {
1422 u_int dlen;
1423 char *ib = indent_pr(indent, 0);
1424 u_int rlen;
1425
1426 dlen = len - TLV_HDRL;
1427 rlen = dlen;
1428 ND_PRINT("\n%s Redirect Data length %d \n", ib, rlen);
1429
1430 if (ndo->ndo_vflag >= 3) {
1431 ND_PRINT("\t\t[");
1432 hex_print_with_offset(ndo, "\n\t\t", pptr, rlen, 0);
1433 ND_PRINT("\n\t\t]");
1434 }
1435
1436 return 0;
1437 }
1438
1439 static int
1440 redirect_print(netdissect_options *ndo,
1441 const u_char * pptr, u_int len,
1442 uint16_t op_msk _U_, int indent)
1443 {
1444 const struct forces_tlv *tlv = (const struct forces_tlv *)pptr;
1445 u_int dlen;
1446 u_int rlen;
1447 u_int invtlv;
1448
1449 /*
1450 * forces_type_print() has ensured that len (the TLV length)
1451 * >= TLV_HDRL.
1452 */
1453 dlen = len - TLV_HDRL;
1454 if (dlen <= RD_MIN) {
1455 ND_PRINT("\n\t\ttruncated Redirect TLV: %d bytes missing! ",
1456 RD_MIN - dlen);
1457 return -1;
1458 }
1459
1460 rlen = dlen;
1461 indent += 1;
1462 while (rlen != 0) {
1463 ND_TCHECK_SIZE(tlv);
1464 invtlv = tlv_valid(tlv, rlen);
1465 if (invtlv) {
1466 ND_PRINT("Bad Redirect data\n");
1467 break;
1468 }
1469
1470 /*
1471 * At this point, tlv_valid() has ensured that the TLV
1472 * length is large enough but not too large (it doesn't
1473 * go past the end of the containing TLV).
1474 */
1475 if (EXTRACT_BE_U_2(tlv->type) == F_TLV_METD) {
1476 print_metatlv(ndo, (const u_char *) TLV_DATA(tlv),
1477 EXTRACT_BE_U_2(tlv->length), 0,
1478 indent);
1479 } else if ((EXTRACT_BE_U_2(tlv->type) == F_TLV_REDD)) {
1480 print_reddata(ndo, (const u_char *) TLV_DATA(tlv),
1481 EXTRACT_BE_U_2(tlv->length), 0,
1482 indent);
1483 } else {
1484 ND_PRINT("Unknown REDIRECT TLV 0x%x len %d\n",
1485 EXTRACT_BE_U_2(tlv->type),
1486 EXTRACT_BE_U_2(tlv->length));
1487 }
1488
1489 tlv = GO_NXT_TLV(tlv, rlen);
1490 }
1491
1492 if (rlen) {
1493 ND_PRINT("\n\t\tMessy Redirect TLV header, type (0x%x)\n\t\texcess of %d Bytes ",
1494 EXTRACT_BE_U_2(tlv->type),
1495 rlen - EXTRACT_BE_U_2(tlv->length));
1496 return -1;
1497 }
1498
1499 return 0;
1500
1501 trunc:
1502 ND_PRINT("%s", tstr);
1503 return -1;
1504 }
1505
1506 #define OP_OFF 8
1507 #define OP_MIN 12
1508
1509 static int
1510 lfbselect_print(netdissect_options *ndo,
1511 const u_char * pptr, u_int len,
1512 uint16_t op_msk, int indent)
1513 {
1514 const struct forces_lfbsh *lfbs;
1515 const struct forces_tlv *otlv;
1516 char *ib = indent_pr(indent, 0);
1517 u_int dlen;
1518 u_int rlen;
1519 u_int invtlv;
1520
1521 /*
1522 * forces_type_print() has ensured that len (the TLV length)
1523 * >= TLV_HDRL.
1524 */
1525 dlen = len - TLV_HDRL;
1526 if (dlen <= OP_MIN) { /* id, instance, oper tlv header .. */
1527 ND_PRINT("\n\t\ttruncated lfb selector: %d bytes missing! ",
1528 OP_MIN - dlen);
1529 return -1;
1530 }
1531
1532 /*
1533 * At this point, we know that dlen > OP_MIN; OP_OFF < OP_MIN, so
1534 * we also know that it's > OP_OFF.
1535 */
1536 rlen = dlen - OP_OFF;
1537
1538 lfbs = (const struct forces_lfbsh *)pptr;
1539 ND_TCHECK_SIZE(lfbs);
1540 if (ndo->ndo_vflag >= 3) {
1541 ND_PRINT("\n%s%s(Classid %x) instance %x\n",
1542 ib,
1543 tok2str(ForCES_LFBs, NULL, EXTRACT_BE_U_4(lfbs->class)),
1544 EXTRACT_BE_U_4(lfbs->class),
1545 EXTRACT_BE_U_4(lfbs->instance));
1546 }
1547
1548 otlv = (const struct forces_tlv *)(lfbs + 1);
1549
1550 indent += 1;
1551 while (rlen != 0) {
1552 ND_TCHECK_SIZE(otlv);
1553 invtlv = tlv_valid(otlv, rlen);
1554 if (invtlv)
1555 break;
1556
1557 /*
1558 * At this point, tlv_valid() has ensured that the TLV
1559 * length is large enough but not too large (it doesn't
1560 * go past the end of the containing TLV).
1561 */
1562 if (op_valid(EXTRACT_BE_U_2(otlv->type), op_msk)) {
1563 otlv_print(ndo, otlv, 0, indent);
1564 } else {
1565 if (ndo->ndo_vflag < 3)
1566 ND_PRINT("\n");
1567 ND_PRINT("\t\tINValid oper-TLV type 0x%x length %d for this ForCES message\n",
1568 EXTRACT_BE_U_2(otlv->type),
1569 EXTRACT_BE_U_2(otlv->length));
1570 invoptlv_print(ndo, (const u_char *)otlv, rlen, 0, indent);
1571 }
1572 otlv = GO_NXT_TLV(otlv, rlen);
1573 }
1574
1575 if (rlen) {
1576 ND_PRINT("\n\t\tMessy oper TLV header, type (0x%x)\n\t\texcess of %d Bytes ",
1577 EXTRACT_BE_U_2(otlv->type),
1578 rlen - EXTRACT_BE_U_2(otlv->length));
1579 return -1;
1580 }
1581
1582 return 0;
1583
1584 trunc:
1585 ND_PRINT("%s", tstr);
1586 return -1;
1587 }
1588
1589 static int
1590 forces_type_print(netdissect_options *ndo,
1591 const u_char * pptr, const struct forcesh *fhdr _U_,
1592 u_int mlen, const struct tom_h *tops)
1593 {
1594 const struct forces_tlv *tltlv;
1595 u_int rlen;
1596 u_int invtlv;
1597 int rc = 0;
1598 int ttlv = 0;
1599
1600 /*
1601 * forces_print() has already checked that mlen >= ForCES_HDRL
1602 * by calling ForCES_HLN_VALID().
1603 */
1604 rlen = mlen - ForCES_HDRL;
1605
1606 if (rlen > TLV_HLN) {
1607 if (tops->flags & ZERO_TTLV) {
1608 ND_PRINT("<0x%x>Illegal Top level TLV!\n", tops->flags);
1609 return -1;
1610 }
1611 } else {
1612 if (tops->flags & ZERO_MORE_TTLV)
1613 return 0;
1614 if (tops->flags & ONE_MORE_TTLV) {
1615 ND_PRINT("\tTop level TLV Data missing!\n");
1616 return -1;
1617 }
1618 }
1619
1620 if (tops->flags & ZERO_TTLV) {
1621 return 0;
1622 }
1623
1624 ttlv = tops->flags >> 4;
1625 tltlv = GET_TOP_TLV(pptr);
1626
1627 /*XXX: 15 top level tlvs will probably be fine
1628 You are nuts if you send more ;-> */
1629 while (rlen != 0) {
1630 ND_TCHECK_SIZE(tltlv);
1631 invtlv = tlv_valid(tltlv, rlen);
1632 if (invtlv)
1633 break;
1634
1635 /*
1636 * At this point, tlv_valid() has ensured that the TLV
1637 * length is large enough but not too large (it doesn't
1638 * go past the end of the packet).
1639 */
1640 if (!ttlv_valid(EXTRACT_BE_U_2(tltlv->type))) {
1641 ND_PRINT("\n\tInvalid ForCES Top TLV type=0x%x",
1642 EXTRACT_BE_U_2(tltlv->type));
1643 return -1;
1644 }
1645
1646 if (ndo->ndo_vflag >= 3)
1647 ND_PRINT("\t%s, length %d (data length %d Bytes)",
1648 tok2str(ForCES_TLV, NULL, EXTRACT_BE_U_2(tltlv->type)),
1649 EXTRACT_BE_U_2(tltlv->length),
1650 EXTRACT_BE_U_2(tltlv->length) - TLV_HDRL);
1651
1652 rc = tops->print(ndo, (const u_char *) TLV_DATA(tltlv),
1653 EXTRACT_BE_U_2(tltlv->length),
1654 tops->op_msk, 9);
1655 if (rc < 0) {
1656 return -1;
1657 }
1658 tltlv = GO_NXT_TLV(tltlv, rlen);
1659 ttlv--;
1660 if (ttlv <= 0)
1661 break;
1662 }
1663 /*
1664 * XXX - if ttlv != 0, does that mean that the packet was too
1665 * short, and didn't have *enough* TLVs in it?
1666 */
1667 if (rlen) {
1668 ND_PRINT("\tMess TopTLV header: min %u, total %d advertised %d ",
1669 TLV_HDRL, rlen, EXTRACT_BE_U_2(tltlv->length));
1670 return -1;
1671 }
1672
1673 return 0;
1674
1675 trunc:
1676 ND_PRINT("%s", tstr);
1677 return -1;
1678 }
1679
1680 void
1681 forces_print(netdissect_options *ndo,
1682 const u_char * pptr, u_int len)
1683 {
1684 const struct forcesh *fhdr;
1685 u_int mlen;
1686 uint32_t flg_raw;
1687 uint8_t tom;
1688 const struct tom_h *tops;
1689 int rc = 0;
1690
1691 fhdr = (const struct forcesh *)pptr;
1692 ND_TCHECK_SIZE(fhdr);
1693 tom = EXTRACT_U_1(fhdr->fm_tom);
1694 if (!tom_valid(tom)) {
1695 ND_PRINT("Invalid ForCES message type %d\n", tom);
1696 goto error;
1697 }
1698
1699 mlen = ForCES_BLN(fhdr);
1700
1701 tops = get_forces_tom(tom);
1702 if (tops->v == TOM_RSVD) {
1703 ND_PRINT("\n\tUnknown ForCES message type=0x%x", tom);
1704 goto error;
1705 }
1706
1707 ND_PRINT("\n\tForCES %s ", tops->s);
1708 if (!ForCES_HLN_VALID(mlen, len)) {
1709 ND_PRINT("Illegal ForCES pkt len - min %u, total recvd %d, advertised %d ",
1710 ForCES_HDRL, len, ForCES_BLN(fhdr));
1711 goto error;
1712 }
1713
1714 ND_TCHECK_4(pptr + 20);
1715 flg_raw = EXTRACT_BE_U_4(pptr + 20);
1716 if (ndo->ndo_vflag >= 1) {
1717 ND_PRINT("\n\tForCES Version %d len %uB flags 0x%08x ",
1718 ForCES_V(fhdr), mlen, flg_raw);
1719 ND_PRINT("\n\tSrcID 0x%x(%s) DstID 0x%x(%s) Correlator 0x%" PRIx64,
1720 ForCES_SID(fhdr), ForCES_node(ForCES_SID(fhdr)),
1721 ForCES_DID(fhdr), ForCES_node(ForCES_DID(fhdr)),
1722 EXTRACT_BE_U_8(fhdr->fm_cor));
1723
1724 }
1725 if (ndo->ndo_vflag >= 2) {
1726 ND_PRINT("\n\tForCES flags:\n\t %s(0x%x), prio=%d, %s(0x%x),\n\t %s(0x%x), %s(0x%x)\n",
1727 tok2str(ForCES_ACKs, "ACKUnknown", ForCES_ACK(fhdr)),
1728 ForCES_ACK(fhdr),
1729 ForCES_PRI(fhdr),
1730 tok2str(ForCES_EMs, "EMUnknown", ForCES_EM(fhdr)),
1731 ForCES_EM(fhdr),
1732 tok2str(ForCES_ATs, "ATUnknown", ForCES_AT(fhdr)),
1733 ForCES_AT(fhdr),
1734 tok2str(ForCES_TPs, "TPUnknown", ForCES_TP(fhdr)),
1735 ForCES_TP(fhdr));
1736 ND_PRINT("\t Extra flags: rsv(b5-7) 0x%x rsv(b13-31) 0x%x\n",
1737 ForCES_RS1(fhdr), ForCES_RS2(fhdr));
1738 }
1739 rc = forces_type_print(ndo, pptr, fhdr, mlen, tops);
1740 if (rc < 0) {
1741 error:
1742 hex_print_with_offset(ndo, "\n\t[", pptr, len, 0);
1743 ND_PRINT("\n\t]");
1744 return;
1745 }
1746
1747 if (ndo->ndo_vflag >= 4) {
1748 ND_PRINT("\n\t Raw ForCES message\n\t [");
1749 hex_print_with_offset(ndo, "\n\t ", pptr, len, 0);
1750 ND_PRINT("\n\t ]");
1751 }
1752 ND_PRINT("\n");
1753 return;
1754
1755 trunc:
1756 ND_PRINT("%s", tstr);
1757 }
1758 /*
1759 * Local Variables:
1760 * c-style: whitesmith
1761 * c-basic-offset: 8
1762 * End:
1763 */