return;
}
- idx->key.sip.set(*p->ptrs.ip_api.get_src());
- idx->key.dip.set(*p->ptrs.ip_api.get_dst());
+ idx->key.sip = *p->ptrs.ip_api.get_src();
+ idx->key.dip = *p->ptrs.ip_api.get_dst();
idx->key.sp = p->ptrs.sp;
idx->key.dp = p->ptrs.dp;
idx->metric = tag->tag_metric;
return 0;
}
- idx.key.sip.set(*p->ptrs.ip_api.get_src());
- idx.key.dip.set(*p->ptrs.ip_api.get_dst());
+ idx.key.sip = *p->ptrs.ip_api.get_src();
+ idx.key.dip = *p->ptrs.ip_api.get_dst();
idx.key.sp = p->ptrs.sp;
idx.key.dp = p->ptrs.dp;
if (returned == nullptr)
{
- idx.key.dip.set(*p->ptrs.ip_api.get_src());
- idx.key.sip.set(*p->ptrs.ip_api.get_dst());
+ idx.key.dip = *p->ptrs.ip_api.get_src();
+ idx.key.sip = *p->ptrs.ip_api.get_dst();
idx.key.dp = p->ptrs.sp;
idx.key.sp = p->ptrs.dp;
** Only switch sip, because that's all we check for
** the host tags.
*/
- idx.key.sip.set(*p->ptrs.ip_api.get_src());
+ idx.key.sip = *p->ptrs.ip_api.get_src();
returned = (TagNode*)xhash_find(host_tag_cache_ptr, &idx);
}
int64_t timeout)
{
FileHashKey hashKey;
- hashKey.dip.set(flow->client_ip);
- hashKey.sip.set(flow->server_ip);
+ hashKey.dip = flow->client_ip;
+ hashKey.sip = flow->server_ip;
hashKey.padding = 0;
hashKey.file_id = file_id;
FileContext* file = find(hashKey, timeout);
static void init_roles_ip(const Packet* p, Flow* flow)
{
flow->ssn_state.direction = FROM_CLIENT;
- flow->client_ip.set(*p->ptrs.ip_api.get_src());
- flow->server_ip.set(*p->ptrs.ip_api.get_dst());
+ flow->client_ip = *p->ptrs.ip_api.get_src();
+ flow->server_ip = *p->ptrs.ip_api.get_dst();
}
static void init_roles_tcp(const Packet* p, Flow* flow)
if ( p->ptrs.tcph->is_syn_only() )
{
flow->ssn_state.direction = FROM_CLIENT;
- flow->client_ip.set(*p->ptrs.ip_api.get_src());
+ flow->client_ip = *p->ptrs.ip_api.get_src();
flow->client_port = p->ptrs.sp;
- flow->server_ip.set(*p->ptrs.ip_api.get_dst());
+ flow->server_ip = *p->ptrs.ip_api.get_dst();
flow->server_port = p->ptrs.dp;
}
else if ( p->ptrs.tcph->is_syn_ack() )
{
flow->ssn_state.direction = FROM_SERVER;
- flow->client_ip.set(*p->ptrs.ip_api.get_dst());
+ flow->client_ip = *p->ptrs.ip_api.get_dst();
flow->client_port = p->ptrs.dp;
- flow->server_ip.set(*p->ptrs.ip_api.get_src());
+ flow->server_ip = *p->ptrs.ip_api.get_src();
flow->server_port = p->ptrs.sp;
}
else if (p->ptrs.sp > p->ptrs.dp)
{
flow->ssn_state.direction = FROM_CLIENT;
- flow->client_ip.set(*p->ptrs.ip_api.get_src());
+ flow->client_ip = *p->ptrs.ip_api.get_src();
flow->client_port = p->ptrs.sp;
- flow->server_ip.set(*p->ptrs.ip_api.get_dst());
+ flow->server_ip = *p->ptrs.ip_api.get_dst();
flow->server_port = p->ptrs.dp;
}
else
{
flow->ssn_state.direction = FROM_SERVER;
- flow->client_ip.set(*p->ptrs.ip_api.get_dst());
+ flow->client_ip = *p->ptrs.ip_api.get_dst();
flow->client_port = p->ptrs.dp;
- flow->server_ip.set(*p->ptrs.ip_api.get_src());
+ flow->server_ip = *p->ptrs.ip_api.get_src();
flow->server_port = p->ptrs.sp;
}
}
static void init_roles_udp(const Packet* p, Flow* flow)
{
flow->ssn_state.direction = FROM_CLIENT;
- flow->client_ip.set(*p->ptrs.ip_api.get_src());
+ flow->client_ip = *p->ptrs.ip_api.get_src();
flow->client_port = p->ptrs.sp;
- flow->server_ip.set(*p->ptrs.ip_api.get_dst());
+ flow->server_ip = *p->ptrs.ip_api.get_dst();
flow->server_port = p->ptrs.dp;
}
if ( p->ptrs.decode_flags & DECODE_C2S )
{
flow->ssn_state.direction = FROM_CLIENT;
- flow->client_ip.set(*p->ptrs.ip_api.get_src());
+ flow->client_ip = *p->ptrs.ip_api.get_src();
flow->client_port = p->ptrs.sp;
- flow->server_ip.set(*p->ptrs.ip_api.get_dst());
+ flow->server_ip = *p->ptrs.ip_api.get_dst();
flow->server_port = p->ptrs.dp;
}
else
{
flow->ssn_state.direction = FROM_SERVER;
- flow->client_ip.set(*p->ptrs.ip_api.get_dst());
+ flow->client_ip = *p->ptrs.ip_api.get_dst();
flow->client_port = p->ptrs.dp;
- flow->server_ip.set(*p->ptrs.ip_api.get_src());
+ flow->server_ip = *p->ptrs.ip_api.get_src();
flow->server_port = p->ptrs.sp;
}
}
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//--------------------------------------------------------------------------
-// flow_control_test.cc author Shivakrishna Mulka <smulka@cisco.com>
+// flow_cache_test.cc author davis mcpherson <davmcphe@cisco.com>
#ifdef HAVE_CONFIG_H
#include "config.h"
PacketTracer::PacketTracer() { }
PacketTracer::~PacketTracer() { }
-void PacketTracer::log(const char* format, ...) { }
+void PacketTracer::log(const char*, ...) { }
void PacketTracer::open_file() { }
-void PacketTracer::dump_to_daq(Packet* p) { }
+void PacketTracer::dump_to_daq(Packet*) { }
void PacketTracer::reset() { }
Packet::Packet(bool) { }
Packet::~Packet() { }
DetectionEngine::DetectionEngine() { }
ExpectCache::~ExpectCache() { }
DetectionEngine::~DetectionEngine() { }
-void Flow::init(PktType type) { }
+void Flow::init(PktType) { }
void Flow::term() { }
void Flow::reset(bool) { }
-void set_network_policy(SnortConfig* sc, unsigned i) { }
-void DataBus::publish(const char* key, const uint8_t* buf, unsigned len, Flow* f) { }
-void DataBus::publish(const char* key, Packet* p, Flow* f) { }
+void set_network_policy(SnortConfig*, unsigned) { }
+void DataBus::publish(const char*, const uint8_t*, unsigned, Flow*) { }
+void DataBus::publish(const char*, Packet*, Flow*) { }
SnortConfig* SnortConfig::get_conf() { return nullptr; }
-void Flow::set_direction(Packet* p) { }
-void set_inspection_policy(SnortConfig* sc, unsigned i) { }
-void set_ips_policy(SnortConfig* sc, unsigned i) { }
-void Flow::set_mpls_layer_per_dir(Packet* p) { }
-void DetectionEngine::disable_all(Packet* p) { }
-void Stream::drop_traffic(const Packet* p, char dir) { }
-bool Stream::blocked_flow(Packet* p) { return true; }
-ExpectCache::ExpectCache(uint32_t max) { }
-bool ExpectCache::check(Packet* p, Flow* lws) { return true; }
-bool ExpectCache::is_expected(Packet* p) { return true; }
-Flow* HighAvailabilityManager::import(Packet& p, FlowKey& key) { return nullptr; }
-bool HighAvailabilityManager::in_standby(Flow* flow) { return true; }
-SfIpRet SfIp::set(void const*, int) { return SfIpRet::SFIP_SUCCESS; }
+void Flow::set_direction(Packet*) { }
+void set_inspection_policy(SnortConfig*, unsigned) { }
+void set_ips_policy(SnortConfig*, unsigned) { }
+void Flow::set_mpls_layer_per_dir(Packet*) { }
+void DetectionEngine::disable_all(Packet*) { }
+void Stream::drop_traffic(const Packet*, char) { }
+bool Stream::blocked_flow(Packet*) { return true; }
+ExpectCache::ExpectCache(uint32_t) { }
+bool ExpectCache::check(Packet*, Flow*) { return true; }
+bool ExpectCache::is_expected(Packet*) { return true; }
+Flow* HighAvailabilityManager::import(Packet&, FlowKey&) { return nullptr; }
+bool HighAvailabilityManager::in_standby(Flow*) { return true; }
+SfIpRet SfIp::set(void const*, int) { return SFIP_SUCCESS; }
namespace memory
{
-void MemoryCap::update_allocations(unsigned long m) { }
-void MemoryCap::update_deallocations(unsigned long m) { }
+void MemoryCap::update_allocations(unsigned long) { }
+void MemoryCap::update_deallocations(unsigned long) { }
bool MemoryCap::over_threshold() { return true; }
}
{
namespace layer
{
-const vlan::VlanTagHdr* get_vlan_layer(const Packet* const p) { return nullptr; }
+const vlan::VlanTagHdr* get_vlan_layer(const Packet* const) { return nullptr; }
}
time_t packet_time() { return 0; }
}
}
}
-void Stream::stop_inspection(
- Flow* flow, Packet* p, char dir,
- int32_t /*bytes*/, int /*response*/) { }
+void Stream::stop_inspection(Flow*, Packet*, char, int32_t, int) { }
-int ExpectCache::add_flow(const Packet *ctrlPkt,
- PktType type, IpProtocol ip_proto,
- const SfIp* cliIP, uint16_t cliPort,
- const SfIp* srvIP, uint16_t srvPort,
- char direction, FlowData* fd, SnortProtocolId snort_protocol_id)
+int ExpectCache::add_flow(const Packet*, PktType, IpProtocol, const SfIp*, uint16_t,
+ const SfIp*, uint16_t, char, FlowData*, SnortProtocolId)
{
return 1;
}
fcg.max_flows = 2;
FlowCache *cache = new FlowCache(fcg);
- Flow *list_flows[fcg.max_flows];
int first_port = 1;
int second_port = 2;
flow_key.pkt_type = PktType::TCP;
flow_key.port_l = first_port;
- list_flows[0] = cache->allocate(&flow_key);
+ cache->allocate(&flow_key);
flow_key.port_l = second_port;
- list_flows[1] = cache->allocate(&flow_key);
+ Flow* flow = cache->allocate(&flow_key);
CHECK(cache->get_count() == fcg.max_flows);
// block the second flow
- list_flows[1]->block();
+ flow->block();
// Access the first flow
// This will move it to the MRU
FlowCache *cache = new FlowCache(fcg);
int port = 1;
- Flow *list_flows[fcg.max_flows];
- for ( int i = 0; i < fcg.max_flows; i++ )
+ for ( unsigned i = 0; i < fcg.max_flows; i++ )
{
FlowKey flow_key;
flow_key.port_l = port++;
flow_key.pkt_type = PktType::TCP;
- list_flows[i] = cache->allocate(&flow_key);
+ cache->allocate(&flow_key);
}
CHECK(cache->get_count() == fcg.max_flows);
FlowCache *cache = new FlowCache(fcg);
int port = 1;
- Flow *list_flows[fcg.max_flows];
- for ( int i = 0; i < fcg.max_flows; i++ )
+ for ( unsigned i = 0; i < fcg.max_flows; i++ )
{
FlowKey flow_key;
flow_key.port_l = port++;
flow_key.pkt_type = PktType::TCP;
- list_flows[i] = cache->allocate(&flow_key);
+ cache->allocate(&flow_key);
}
CHECK(cache->get_count() == fcg.max_flows);
FlowCache *cache = new FlowCache(fcg);
int port = 1;
- Flow *list_flows[fcg.max_flows];
- for ( int i = 0; i < fcg.max_flows; i++ )
+ for ( unsigned i = 0; i < fcg.max_flows; i++ )
{
FlowKey flow_key;
flow_key.port_l = port++;
flow_key.pkt_type = PktType::TCP;
- list_flows[i] = cache->allocate(&flow_key);
- list_flows[i]->block();
+ Flow* flow = cache->allocate(&flow_key);
+ flow->block();
}
CHECK(cache->get_count() == fcg.max_flows);
DetectionEngine::~DetectionEngine() = default;
ExpectCache::~ExpectCache() = default;
unsigned FlowCache::purge() { return 1; }
-Flow* FlowCache::find(const FlowKey* key) { return nullptr; }
+Flow* FlowCache::find(const FlowKey*) { return nullptr; }
Flow* FlowCache::allocate(const FlowKey*) { return nullptr; }
-void FlowCache::push(Flow* flow) { }
+void FlowCache::push(Flow*) { }
bool FlowCache::prune_one(PruneReason, bool) { return true; }
unsigned FlowCache::delete_flows(unsigned) { return 0; }
-unsigned FlowCache::timeout(unsigned num_flows, time_t thetime) { return 1; }
-void Flow::init(PktType type) { }
-void set_network_policy(SnortConfig* sc, unsigned i) { }
-void DataBus::publish(const char* key, const uint8_t* buf, unsigned len, Flow* f) { }
-void DataBus::publish(const char* key, Packet* p, Flow* f) { }
+unsigned FlowCache::timeout(unsigned, time_t) { return 1; }
+void Flow::init(PktType) { }
+void set_network_policy(SnortConfig*, unsigned) { }
+void DataBus::publish(const char*, const uint8_t*, unsigned, Flow*) { }
+void DataBus::publish(const char*, Packet*, Flow*) { }
SnortConfig* SnortConfig::get_conf() { return nullptr; }
void FlowCache::unlink_uni(Flow*) { }
void Flow::set_direction(Packet*) { }
#define APP_FORECAST_H
#include <ctime>
+
#include "flow/flow.h"
#include "protocols/packet.h"
+#include "utils/cpp_macros.h"
+
#include "appid_types.h"
#include "application_ids.h"
AppId target;
};
+PADDING_GUARD_BEGIN
class AFActKey
{
public:
uint32_t ip[4];
AppId forecast;
};
+PADDING_GUARD_END
struct AFActVal
{
inline void AppIdDebugSessionConstraints::set(const AppIdDebugSessionConstraints& src)
{
if ((sip_flag = src.sip_flag))
- sip.set(src.sip);
+ sip = src.sip;
if ((dip_flag = src.dip_flag))
- dip.set(src.dip);
+ dip = src.dip;
sport = src.sport;
dport = src.dport;
protocol = src.protocol;
{
HostPortKey hk;
- hk.ip.set(*ip);
+ hk.ip = *ip;
hk.port = port;
hk.proto = protocol;
HostPortKey hk;
HostPortVal hv;
- hk.ip.set(*ip);
+ hk.ip = *ip;
hk.port = port;
hk.proto = proto;
#include "protocols/protocol_ids.h"
#include "sfip/sf_ip.h"
+#include "utils/cpp_macros.h"
+#include "utils/util.h"
#include "service_plugins/service_discovery.h"
-#include "utils/util.h"
class ServiceDetector;
};
+PADDING_GUARD_BEGIN
class AppIdServiceStateKey
{
public:
AppIdServiceStateKey(const snort::SfIp* ip_in,
IpProtocol proto_in, uint16_t port_in, bool decrypted)
{
- ip.set(*ip_in);
+ ip = *ip_in;
port = port_in;
level = decrypted != 0;
proto = proto_in;
uint16_t port;
uint32_t level;
IpProtocol proto;
- char padding[3];
+ uint8_t padding[3];
};
+PADDING_GUARD_END
class MapList
void IpApi::set(const SfIp& sip, const SfIp& dip)
{
type = IAT_DATA;
- src.set(sip);
- dst.set(dip);
+ src = sip;
+ dst = dip;
iph = nullptr;
}
} // namespace ip
TEST(appid_http_session, set_tun_dest)
{
const TunnelDest* tun_dest = nullptr;
- SfIp tun_des, ipv6;
+ SfIp ipv6;
ipv6.set("2001:db8:85a3::8a2e:370:7334");
AppidChangeBits change_bits;
hsession.set_field(REQ_URI_FID, new std::string("[2001:db8:85a3::8a2e:370:7334]:51413"), change_bits);
inline void PTSessionConstraints::set(const PTSessionConstraints& src)
{
if ((sip_flag = src.sip_flag))
- sip.set(src.sip);
+ sip = src.sip;
if ((dip_flag = src.dip_flag))
- dip.set(src.dip);
+ dip = src.dip;
sport = src.sport;
dport = src.dport;
protocol = src.protocol;
if (sip.is_set())
{
- constraints.sip.set(sip);
+ constraints.sip = sip;
constraints.sip_flag = true;
}
if (dip.is_set())
{
- constraints.dip.set(dip);
+ constraints.dip = dip;
constraints.dip_flag = true;
}
if (src_addr->less_than(*dst_addr))
{
- key.ipA.set(*src_addr);
- key.ipB.set(*dst_addr);
+ key.ipA = *src_addr;
+ key.ipB = *dst_addr;
*swapped = 0;
}
else
{
- key.ipA.set(*dst_addr);
- key.ipB.set(*src_addr);
+ key.ipA = *dst_addr;
+ key.ipB = *src_addr;
*swapped = 1;
}
key.scanner.clear();
if (ps_pkt->reverse_pkt)
- key.scanned.set(*p->ptrs.ip_api.get_src());
+ key.scanned = *p->ptrs.ip_api.get_src();
else
- key.scanned.set(*p->ptrs.ip_api.get_dst());
+ key.scanned = *p->ptrs.ip_api.get_dst();
*scanned = ps_tracker_get(&key);
}
key.scanned.clear();
if (ps_pkt->reverse_pkt)
- key.scanner.set(*p->ptrs.ip_api.get_dst());
+ key.scanner = *p->ptrs.ip_api.get_dst();
else
- key.scanner.set(*p->ptrs.ip_api.get_src());
+ key.scanner = *p->ptrs.ip_api.get_src();
*scanner = ps_tracker_get(&key);
}
if (!proto->u_ips.equals(*ip, false))
{
proto->u_ip_count++;
- proto->u_ips.set(*ip);
+ proto->u_ips = *ip;
}
/* we need to do the IP comparisons in host order */
if (proto->low_ip.is_set())
{
if (proto->low_ip.greater_than(*ip))
- proto->low_ip.set(*ip);
+ proto->low_ip = *ip;
}
else
{
- proto->low_ip.set(*ip);
+ proto->low_ip = *ip;
}
if (proto->high_ip.is_set())
{
if (proto->high_ip.less_than(*ip))
- proto->high_ip.set(*ip);
+ proto->high_ip = *ip;
}
else
{
- proto->high_ip.set(*ip);
+ proto->high_ip = *ip;
}
if (proto->u_ports != port)
Packet* p = (Packet*)ps_pkt->pkt;
unsigned win = config->icmp_window;
- SfIp cleared;
- cleared.clear();
-
if (p->ptrs.icmph)
{
switch (p->ptrs.icmph->type)
case ICMP_TIMESTAMP:
case ICMP_ADDRESS:
case ICMP_INFO_REQUEST:
- ps_proto_update(&scanner->proto, 1, 0, win,
- p->ptrs.ip_api.get_dst(), 0, packet_time());
+ if (scanner)
+ {
+ ps_proto_update(&scanner->proto, 1, 0, win,
+ p->ptrs.ip_api.get_dst(), 0, packet_time());
+ }
break;
case ICMP_DEST_UNREACH:
- ps_proto_update(&scanner->proto, 0, 1, win, &cleared, 0, 0);
- scanner->priority_node = 1;
+ if (scanner)
+ {
+ SfIp cleared;
+ cleared.clear();
+
+ ps_proto_update(&scanner->proto, 0, 1, win, &cleared, 0, 0);
+ scanner->priority_node = 1;
+ }
break;
default:
void IpApi::set(const SfIp& sip, const SfIp& dip)
{
type = IAT_DATA;
- src.set(sip);
- dst.set(dip);
+ src = sip;
+ dst = dip;
iph = nullptr;
}
void IpApi::update(const SfIp& sip, const SfIp& dip)
{
- src.set(sip);
- dst.set(dip);
+ src = sip;
+ dst = dip;
}
uint16_t IpApi::tos() const
*/
int SetSiInput(FTPP_SI_INPUT* SiInput, Packet* p)
{
- SiInput->sip.set(*p->ptrs.ip_api.get_src());
- SiInput->dip.set(*p->ptrs.ip_api.get_dst());
+ SiInput->sip = *p->ptrs.ip_api.get_src();
+ SiInput->dip = *p->ptrs.ip_api.get_dst();
SiInput->sport = p->ptrs.sp;
SiInput->dport = p->ptrs.dp;
if (iRet == FTPP_SUCCESS)
{
if (!ipAddr.is_set())
- session->serverIP.set(*p->ptrs.ip_api.get_src());
+ session->serverIP = *p->ptrs.ip_api.get_src();
else
{
session->serverIP = ipAddr;
}
session->serverPort = port;
- session->clientIP.set(*p->ptrs.ip_api.get_dst());
+ session->clientIP = *p->ptrs.ip_api.get_dst();
session->clientPort = 0;
if ((FileService::get_max_file_depth() > 0) ||
/* Server is listening/sending from its own IP,
* FTP Port -1 */
/* Client IP, Port specified via PORT command */
- session->serverIP.set(*p->ptrs.ip_api.get_src());
+ session->serverIP = *p->ptrs.ip_api.get_src();
/* Can't necessarily guarantee this, especially
* in the case of a proxy'd connection where the
struct SO_PUBLIC SfCidr
{
+ /*
+ * Constructors
+ */
+ SfCidr() = default;
+
/*
* Modifiers (incl. convenience ones that delegate to addr)
*/
inline void SfCidr::set(const SfCidr& src)
{
- addr.set(src.addr);
+ addr = src.addr;
bits = src.bits;
}
inline void SfCidr::set(const SfIp& src)
{
- addr.set(src);
+ addr = src;
bits = 128;
}
using SfIpString = char[INET6_ADDRSTRLEN];
struct SfCidr;
+
struct SO_PUBLIC SfIp
{
/*
* Modifiers
*/
void clear();
- void set(const SfIp& src);
SfIpRet set(const char* src, uint16_t* srcBits = nullptr);
/* Sets to a raw source IP (4 or 16 bytes, according to family) */
SfIpRet set(const void* src, int fam);
ip32[0] = ip32[1] = ip32[2] = ip32[3] = 0;
}
-inline void SfIp::set(const SfIp& src)
-{
- /* This is a simple structure, so is this really better than
- *this = src?. */
- family = src.family;
- ip32[0] = src.ip32[0];
- ip32[1] = src.ip32[1];
- ip32[2] = src.ip32[2];
- ip32[3] = src.ip32[3];
-}
-
inline uint16_t SfIp::get_family() const
{
return family;
SfIp ip1, ip2;
ip1.set(f->arg1);
- ip2.set(ip1);
+ ip2 = ip1;
return !memcmp(&ip1, &ip2, sizeof(ip1));
}
}
else
{
- SfIp tmp;
- tmp.set(*ip);
+ SfIp tmp(*ip);
if ( homenet.is_set() )
{
- if ( homenet.contains(&tmp) == SFIP_CONTAINS )
+ if ( homenet.contains(ip) == SFIP_CONTAINS )
tmp.obfuscate(&obfunet);
}
else