return false;
eth::EtherHdr* ho = reinterpret_cast<eth::EtherHdr*>(buf.data());
- ho->ether_type = enc.ethertype_set() ? htons(to_utype(enc.next_ethertype)) : hi->ether_type;
-
- uint8_t* dst_mac = PacketManager::encode_get_dst_mac();
+ ho->ether_type = enc.ethertype_set() ?
+ htons(to_utype(enc.next_ethertype)) : hi->ether_type;
if ( enc.forward() )
{
memcpy(ho->ether_src, hi->ether_src, sizeof(ho->ether_src));
- /*If user configured remote MAC address, use it*/
- if (nullptr != dst_mac)
- memcpy(ho->ether_dst, dst_mac, sizeof(ho->ether_dst));
+
+ if ( snort_conf->eth_dst )
+ memcpy(ho->ether_dst, snort_conf->eth_dst, sizeof(ho->ether_dst));
else
memcpy(ho->ether_dst, hi->ether_dst, sizeof(ho->ether_dst));
}
else
{
memcpy(ho->ether_src, hi->ether_dst, sizeof(ho->ether_src));
- /*If user configured remote MAC address, use it*/
- if (nullptr != dst_mac)
- memcpy(ho->ether_dst, dst_mac, sizeof(ho->ether_dst));
+
+ if ( snort_conf->eth_dst )
+ memcpy(ho->ether_dst, snort_conf->eth_dst, sizeof(ho->ether_dst));
else
memcpy(ho->ether_dst, hi->ether_src, sizeof(ho->ether_dst));
}
Packet* DetectionEngine::get_packet()
{ return get_current_packet(); }
+void DetectionEngine::set_encode_packet(Packet* p)
+{ Snort::get_switcher()->get_context()->encode_packet = p; }
+
+Packet* DetectionEngine::get_encode_packet()
+{ return Snort::get_switcher()->get_context()->encode_packet; }
+
MpseStash* DetectionEngine::get_stash()
{ return Snort::get_switcher()->get_context()->stash; }
static Packet* set_packet();
static void clear_packet();
+ static void set_encode_packet(Packet*);
+ static Packet* get_encode_packet();
+
static class MpseStash* get_stash();
static uint8_t* get_buffer(unsigned& max);
data(size ? size : IpsContextData::get_max_id() + 1, nullptr)
{
packet = new Packet(false);
+ encode_packet = nullptr;
+
pkth = new DAQ_PktHdr_t;
- buf = new uint8_t[buf_size]; // FIXIT-H use codec max or let pkt do it?
+ buf = new uint8_t[buf_size];
const EventQueueConfig* qc = snort_conf->event_queue_config;
equeue = sfeventq_new(qc->max_events, qc->log_events, sizeof(EventNode));
#include <vector>
#include "main/snort_types.h"
+#include "framework/codec.h"
// required to get a decent decl of pkth
#include "protocols/packet.h"
public:
Packet* packet;
+ Packet* encode_packet;
DAQ_PktHdr_t* pkth;
uint8_t* buf;
struct SF_EVENTQ* equeue;
- static const unsigned buf_size = 65536;
+ static const unsigned buf_size = Codec::PKT_MAX;
private:
std::vector<IpsContextData*> data;
HighAvailabilityManager::process_update(s_packet->flow, pkthdr);
Active::reset();
- PacketManager::encode_reset();
Stream::timeout_flows(pkthdr->ts.tv_sec);
HighAvailabilityManager::process_receive();
s_attempts = 0;
#endif
}
-
- if (NULL != sc->eth_dst)
- PacketManager::encode_set_dst_mac(sc->eth_dst);
}
return true;
}
};
// Encoder Foo
-static THREAD_LOCAL Packet* encode_pkt = nullptr;
static THREAD_LOCAL PegCount total_rebuilt_pkts = 0;
-static THREAD_LOCAL std::array<uint8_t, Codec::PKT_MAX> s_pkt {
- { 0 }
-};
-static THREAD_LOCAL uint8_t* dst_mac = nullptr;
+static THREAD_LOCAL std::array<uint8_t, Codec::PKT_MAX> s_pkt { { 0 } };
//-------------------------------------------------------------------------
// Private helper functions
IpProtocol next_prot,
Buffer& buf)
{
- if ( encode_pkt )
- p = encode_pkt;
+ if ( Packet* pe = DetectionEngine::get_encode_packet() )
+ p = pe;
uint8_t ttl = GetTTL(p, (flags & ENC_FLAG_FWD));
if ( ttl )
// codec support and statistics
//-------------------------------------------------------------------------
-void PacketManager::encode_set_dst_mac(uint8_t* mac)
-{ dst_mac = mac; }
-
-uint8_t* PacketManager::encode_get_dst_mac()
-{ return dst_mac; }
-
uint64_t PacketManager::get_rebuilt_packet_count()
{ return total_rebuilt_pkts; }
-void PacketManager::encode_set_pkt(Packet* p)
-{ encode_pkt = p; }
-
uint16_t PacketManager::encode_get_max_payload(const Packet* p)
{
if ( !p->num_layers )
// decode this packet and set all relevent packet fields.
static void decode(Packet*, const struct _daq_pkthdr*, const uint8_t*, bool cooked = false);
- // when encoding, rather than copy the destination MAC address from the
- // inbound packet, manually set the MAC address.
- static void encode_set_dst_mac(uint8_t*);
-
- // get the MAC address which has been set using encode_set_dst_mac().
- // Useful for root decoders setting the MAC address
- static uint8_t* encode_get_dst_mac();
-
// update the packet's checksums and length variables. Call this function
// after Snort has changed any data in this packet
static void encode_update(Packet*);
// get the number of packets which have been rebuilt by this thread
static PegCount get_rebuilt_packet_count();
- // set the packet to be encoded.
- static void encode_set_pkt(Packet* p);
-
// get the max payload for the current packet
static uint16_t encode_get_max_payload(const Packet*);
- // reset the current 'clone' packet
- static void encode_reset()
- { encode_set_pkt(NULL); }
-
// print codec information. MUST be called after thread_term.
static void dump_stats();
#endif
DetectionEngine de;
- PacketManager::encode_set_pkt(p);
+ de.set_encode_packet(p);
Snort::process_packet(dpkt, dpkt->pkth, dpkt->pkt, true);
+ de.set_encode_packet(nullptr);
- trace_log(stream_ip,
- "Done with rebuilt packet, marking rebuilt...\n");
+ trace_log(stream_ip, "Done with rebuilt packet, marking rebuilt...\n");
- ft->frag_flags = ft->frag_flags | FRAG_REBUILT;
+ ft->frag_flags |= FRAG_REBUILT;
}
/**