@@ -97,6 +97,26 @@ std::string Wireshark::wiresharkLocalNamespaceName(const WiresharkGenerator& gen
9797 return wiresharkProtocolObjName (generator) + " _local" ;
9898}
9999
100+ std::string Wireshark::wiresharkProtVersionGetFuncName (const WiresharkGenerator& generator)
101+ {
102+ return wiresharkLocalNamespaceName (generator) + " .prot_version_get" ;
103+ }
104+
105+ std::string Wireshark::wiresharkProtVersionSetFuncName (const WiresharkGenerator& generator)
106+ {
107+ return wiresharkLocalNamespaceName (generator) + " .prot_version_set" ;
108+ }
109+
110+ std::string Wireshark::wiresharkPinfoName (const WiresharkGenerator& generator)
111+ {
112+ return wiresharkLocalNamespaceName (generator) + " .last_pinfo" ;
113+ }
114+
115+ std::string Wireshark::wiresharkPacketIdFuncName (const WiresharkGenerator& generator)
116+ {
117+ return wiresharkLocalNamespaceName (generator) + " .packet_id" ;
118+ }
119+
100120bool Wireshark::wiresharkWriteInternal () const
101121{
102122 auto fileName = wiresharkFileName (m_wiresharkGenerator);
@@ -114,6 +134,8 @@ bool Wireshark::wiresharkWriteInternal() const
114134 " #^#GEN_COMMENT#$#\n "
115135 " #^#PROTOCOL#$#\n "
116136 " #^#LOCAL#$#\n "
137+ " #^#PINFO#$#\n "
138+ " #^#PROT_VERSION#$#\n "
117139 " #^#STATUS_CODE#$#\n "
118140 " #^#OPT_MODE#$#\n "
119141 " #^#FIELDS_REG#$#\n "
@@ -141,6 +163,8 @@ bool Wireshark::wiresharkWriteInternal() const
141163 {" EXTRACTORS_DECL" , wiresharkExtractorsDeclInternal ()},
142164 {" EXTRACTORS_REG" , wiresharkExtractorsRegCodeInternal ()},
143165 {" FIELD_VALUE_FUNC" , wiresharkFieldValueFuncInternal ()},
166+ {" PROT_VERSION" , wiresharkProtocolVersionDefInternal ()},
167+ {" PINFO" , wiresharkPinfoDefInternal ()},
144168 };
145169
146170 auto str = commsdsl::gen::util::genProcessTemplate (Templ, repl, true );
@@ -278,6 +302,7 @@ std::string Wireshark::wiresharkDissectFuncBodyInternal() const
278302 " end\n "
279303 " \n "
280304 " pinfo.cols.protocol = #^#NAME#$#.name\n "
305+ " #^#PINFO#$# = pinfo\n "
281306 " \n "
282307 " local result = #^#SUCCESS#$#\n "
283308 " local next_offset = 0\n "
@@ -302,6 +327,7 @@ std::string Wireshark::wiresharkDissectFuncBodyInternal() const
302327 {" FRAMES" , util::genStrListToString (elems, " \n " , " " )},
303328 {" SUCCESS" , wiresharkStatusCodeStr (m_wiresharkGenerator, WiresharkStatusCode::Success)},
304329 {" NOT_ENOUGH_DATA" , wiresharkStatusCodeStr (m_wiresharkGenerator, WiresharkStatusCode::NotEnoughData)},
330+ {" PINFO" , wiresharkPinfoName (m_wiresharkGenerator)},
305331 };
306332
307333 return util::genProcessTemplate (Templ, repl);
@@ -438,6 +464,59 @@ std::string Wireshark::wiresharkFieldValueFuncInternal() const
438464 return util::genProcessTemplate (Templ, repl);
439465}
440466
467+ std::string Wireshark::wiresharkProtocolVersionDefInternal () const
468+ {
469+ const std::string Templ =
470+ " #^#LOCAL#$#.spec_version = #^#SPEC#$#\n "
471+ " #^#LOCAL#$#.prot_version = {}\n "
472+ " \n "
473+ " function #^#GET_NAME#$#()\n "
474+ " local pkt_id = #^#PKT_ID#$#()\n "
475+ " local last_ver = #^#LOCAL#$#.prot_version[pkt_id]\n "
476+ " if last_ver ~= #^#NIL#$# then\n "
477+ " return last_ver\n "
478+ " end\n "
479+ " \n "
480+ " return #^#LOCAL#$#.spec_version\n "
481+ " end\n "
482+ " \n "
483+ " function #^#SET_NAME#$#(value)\n "
484+ " local pkt_id = #^#PKT_ID#$#()\n "
485+ " #^#LOCAL#$#.prot_version[pkt_id] = value\n "
486+ " end\n "
487+ ;
488+
489+ util::GenReplacementMap repl = {
490+ {" LOCAL" , wiresharkLocalNamespaceName (m_wiresharkGenerator)},
491+ {" SPEC" , std::to_string (m_wiresharkGenerator.genProtocolSchema ().genSchemaVersion ())},
492+ {" GET_NAME" , wiresharkProtVersionGetFuncName (m_wiresharkGenerator)},
493+ {" SET_NAME" , wiresharkProtVersionSetFuncName (m_wiresharkGenerator)},
494+ {" PKT_ID" , wiresharkPacketIdFuncName (m_wiresharkGenerator)},
495+ {" NIL" , strings::genNilStr ()},
496+ };
497+
498+ return util::genProcessTemplate (Templ, repl);
499+ }
500+
501+ std::string Wireshark::wiresharkPinfoDefInternal () const
502+ {
503+ const std::string Templ =
504+ " #^#NAME#$# = #^#NIL#$#\n "
505+ " \n "
506+ " function #^#PKT_ID#$#()\n "
507+ " return tostring(#^#NAME#$#.src) .. \" :\" .. tostring(#^#NAME#$#.src_port) .. \" -> \" .. tostring(#^#NAME#$#.dst) .. \" :\" .. tostring(#^#NAME#$#.dst_port)\n "
508+ " end\n "
509+ ;
510+
511+ util::GenReplacementMap repl = {
512+ {" NAME" , wiresharkPinfoName (m_wiresharkGenerator)},
513+ {" NIL" , strings::genNilStr ()},
514+ {" PKT_ID" , wiresharkPacketIdFuncName (m_wiresharkGenerator)},
515+ };
516+
517+ return util::genProcessTemplate (Templ, repl);
518+ }
519+
441520const std::string& Wireshark::wiresharkStatusCodeStrInternal (WiresharkStatusCode code)
442521{
443522 static const std::string Map[] = {
0 commit comments