print-forces.c 45 KB

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