From: George Koikara (gkoikara) Date: Fri, 6 Dec 2019 09:59:33 +0000 (+0000) Subject: Merge pull request #1870 in SNORT/snort3 from ~RJAVALI/snort3:GRE_issu to master X-Git-Tag: 3.0.0-267~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fecd2962cec6f09667343ccf424e7195fd9c4bed;p=thirdparty%2Fsnort3.git Merge pull request #1870 in SNORT/snort3 from ~RJAVALI/snort3:GRE_issu to master Squashed commit of the following: commit c7d297104eceef9da751684b7102899c57fb48ba Author: Raghavendra Javali Date: Mon Nov 18 01:46:47 2019 -0500 codec: Added GRE::encode method --- diff --git a/src/codecs/ip/cd_gre.cc b/src/codecs/ip/cd_gre.cc index 18d713e47..9c6d62aa9 100644 --- a/src/codecs/ip/cd_gre.cc +++ b/src/codecs/ip/cd_gre.cc @@ -27,6 +27,7 @@ #include "log/text_log.h" #include "main/snort_config.h" #include "protocols/gre.h" +#include "log/messages.h" using namespace snort; @@ -63,6 +64,8 @@ public: void get_protocol_ids(std::vector& v) override; bool decode(const RawData&, CodecData&, DecodeData&) override; void log(TextLog* const, const uint8_t* pkt, const uint16_t len) override; + bool encode(const uint8_t* const raw_in, const uint16_t raw_len, + EncState&, Buffer&, Flow*) override; }; static const uint32_t GRE_HEADER_LEN = 4; @@ -93,6 +96,30 @@ void GreCodec::get_protocol_ids(std::vector& v) /* * see RFCs 1701, 2784 and 2637 */ + +bool GreCodec::encode(const uint8_t* const raw_in, const uint16_t raw_len, + EncState& enc, Buffer& buf, Flow*) + +{ + if (raw_len > GRE_HEADER_LEN) + { + ErrorMessage("Invalid GRE header length: %u",raw_len); + return false; + } + + if (!buf.allocate(raw_len)) + return false; + + gre::GREHdr* const greh_out = reinterpret_cast(buf.data()); + memcpy(buf.data(), raw_in, raw_len); + enc.next_proto = IpProtocol::GRE; + enc.next_ethertype = greh_out->proto(); + + GRE_CHKSUM(greh_out); + + return true; +} + bool GreCodec::decode(const RawData& raw, CodecData& codec, DecodeData&) { if (raw.len < GRE_HEADER_LEN)