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