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