]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Pull request #3196: vlan: implement vlan encode function
authorTom Peters (thopeter) <thopeter@cisco.com>
Fri, 10 Dec 2021 18:28:17 +0000 (18:28 +0000)
committerTom Peters (thopeter) <thopeter@cisco.com>
Fri, 10 Dec 2021 18:28:17 +0000 (18:28 +0000)
Merge in SNORT/snort3 from ~SBAIGAL/snort3:vlan_encode to master

Squashed commit of the following:

commit 827bea7bfc67403762cec0424767d822f147419b
Author: Steven Baigal (sbaigal) <sbaigal@cisco.com>
Date:   Wed Dec 1 15:32:36 2021 -0500

    vlan: implement vlan encode function

src/codecs/link/cd_vlan.cc

index 1232c08ee24fe81d16737ca59fee3d77e6a8cfa4..6741edd809eeccfd32f643dc00c5901946f65ac7 100644 (file)
@@ -58,6 +58,8 @@ public:
     void get_protocol_ids(std::vector<ProtocolId>& 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;
 };
 
 constexpr unsigned int ETHERNET_MAX_LEN_ENCAP = 1518;    /* 802.3 (+LLC) or ether II ? */
@@ -126,6 +128,20 @@ void VlanCodec::log(TextLog* const text_log, const uint8_t* raw_pkt,
         TextLog_Print(text_log, "  Next:0x%04X", proto);
 }
 
+bool VlanCodec::encode(const uint8_t* const raw_in, const uint16_t raw_len, EncState& enc,
+    Buffer& buf, Flow*)
+{
+    if (!buf.allocate(raw_len))
+        return false;
+
+    memcpy(buf.data(), raw_in, raw_len);
+
+    enc.next_ethertype = ProtocolId::ETHERTYPE_NOT_SET;
+    enc.next_proto = IpProtocol::PROTO_NOT_SET;
+
+    return true;
+}
+
 //-------------------------------------------------------------------------
 // api
 //-------------------------------------------------------------------------