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