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