extern const BaseApi* cd_pgm[];
extern const BaseApi* cd_pppencap[];
extern const BaseApi* cd_pppoepkt[];
+extern const BaseApi* cd_raw[];
extern const BaseApi* cd_routing[];
extern const BaseApi* cd_teredo[];
extern const BaseApi* cd_transbridge[];
PluginManager::load_plugins(cd_pgm);
PluginManager::load_plugins(cd_pppencap);
PluginManager::load_plugins(cd_pppoepkt);
+ PluginManager::load_plugins(cd_raw);
PluginManager::load_plugins(cd_routing);
PluginManager::load_plugins(cd_teredo);
PluginManager::load_plugins(cd_transbridge);
#include "config.h"
#endif
+#include <sfbpf_dlt.h>
+
#include <random>
#include "codecs/codec_module.h"
using namespace snort;
#define CD_IPV4_NAME "ipv4"
-#define CD_IPV4_HELP "support for Internet protocol v4"
+#define CD_IPV4_HELP_STR "support for Internet protocol v4"
+#define CD_IPV4_HELP ADD_DLT(CD_IPV4_HELP_STR, DLT_IPV4)
namespace
{
public:
Ipv4Codec() : Codec(CD_IPV4_NAME) { }
+ void get_data_link_type(std::vector<int>&) override;
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;
};
} // namespace
+void Ipv4Codec::get_data_link_type(std::vector<int>& v)
+{
+ v.push_back(DLT_IPV4);
+}
+
void Ipv4Codec::get_protocol_ids(std::vector<ProtocolId>& v)
{
v.push_back(ProtocolId::ETHERTYPE_IPV4);
#include "config.h"
#endif
+#include <sfbpf_dlt.h>
+
#include "codecs/codec_module.h"
#include "framework/codec.h"
#include "log/text_log.h"
using namespace snort;
#define CD_IPV6_NAME "ipv6"
-#define CD_IPV6_HELP "support for Internet protocol v6"
+#define CD_IPV6_HELP_STR "support for Internet protocol v6"
+#define CD_IPV6_HELP ADD_DLT(CD_IPV6_HELP_STR, DLT_IPV6)
namespace
{
public:
Ipv6Codec() : Codec(CD_IPV6_NAME) { }
+ void get_data_link_type(std::vector<int>&) override;
void get_protocol_ids(std::vector<ProtocolId>& v) override;
bool decode(const RawData&, CodecData&, DecodeData&) override;
bool encode(const uint8_t* const raw_in, const uint16_t raw_len,
************************* CLASS FUNCTIONS ************************
********************************************************************/
+void Ipv6Codec::get_data_link_type(std::vector<int>& v)
+{
+ v.push_back(DLT_IPV6);
+}
+
void Ipv6Codec::get_protocol_ids(std::vector<ProtocolId>& v)
{
v.push_back(ProtocolId::ETHERTYPE_IPV6);
if (STATIC_CODECS)
set (PLUGIN_LIST
cd_eth.cc
+ cd_raw.cc
)
else (STATIC_CODECS)
- add_dynamic_module (cd_eth codecs cd_eth.cc)
+ add_dynamic_module (cd_eth codecs cd_eth.cc cd_raw.cc)
endif (STATIC_CODECS)
--- /dev/null
+//--------------------------------------------------------------------------
+// Copyright (C) 2018-2018 Cisco and/or its affiliates. All rights reserved.
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License Version 2 as published
+// by the Free Software Foundation. You may not use, modify or distribute
+// this program under any other version of the GNU General Public License.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//--------------------------------------------------------------------------
+// cd_raw.cc author Michael Altizer <mialtize@cisco.com>
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sfbpf_dlt.h>
+
+#include "framework/codec.h"
+
+using namespace snort;
+
+#define CD_RAW_NAME "raw"
+#define CD_RAW_HELP_STR "support for raw IP"
+#define CD_RAW_HELP ADD_DLT(CD_RAW_HELP_STR, DLT_RAW)
+
+namespace
+{
+class RawCodec : public Codec
+{
+public:
+ RawCodec() : Codec(CD_RAW_NAME) { }
+
+ bool decode(const RawData&, CodecData&, DecodeData&) override;
+ void get_data_link_type(std::vector<int>&) override;
+};
+} // namespace
+
+bool RawCodec::decode(const RawData& raw, CodecData& data, DecodeData&)
+{
+ uint8_t ipver = (raw.data[0] & 0xf0);
+
+ if (ipver == 0x40)
+ data.next_prot_id = ProtocolId::ETHERTYPE_IPV4;
+ else if (ipver == 0x60)
+ data.next_prot_id = ProtocolId::ETHERTYPE_IPV6;
+ else
+ return false;
+
+ return true;
+}
+
+void RawCodec::get_data_link_type(std::vector<int>& v)
+{
+ v.push_back(DLT_RAW);
+}
+
+//-------------------------------------------------------------------------
+// api
+//-------------------------------------------------------------------------
+
+static Codec* ctor(Module*)
+{ return new RawCodec(); }
+
+static void dtor(Codec* cd)
+{ delete cd; }
+
+static const CodecApi raw_api =
+{
+ {
+ PT_CODEC,
+ sizeof(CodecApi),
+ CDAPI_VERSION,
+ 0,
+ API_RESERVED,
+ API_OPTIONS,
+ CD_RAW_NAME,
+ CD_RAW_HELP,
+ nullptr,
+ nullptr,
+ },
+ nullptr, // pinit
+ nullptr, // pterm
+ nullptr, // tinit
+ nullptr, // tterm
+ ctor, // ctor
+ dtor, // dtor
+};
+
+#ifdef BUILDING_SO
+SO_PUBLIC const BaseApi* snort_plugins[] =
+#else
+const BaseApi* cd_raw[] =
+#endif
+{
+ &raw_api.base,
+ nullptr
+};