impl->pci.flags &= ~DAQ_USR_FLAG_TO_SERVER;
}
+static bool is_ipv4(char const* src)
+{
+ struct in6_addr temp;
+ if ( inet_pton(AF_INET, src, &temp) == 1 )
+ return true;
+ else if ( inet_pton(AF_INET6, src, &temp) == 1 )
+ return false;
+
+ return false;
+}
+
+void IpAddr(uint32_t* addr, char const* ip)
+{
+ if ( is_ipv4(ip) ) {
+ addr[0] = 0;
+ addr[1] = 0;
+ addr[2] = htonl(0xffff);
+ inet_pton(AF_INET, ip, &addr[3]);
+ }
+ else {
+ inet_pton(AF_INET6, ip, addr);
+ }
+}
+
enum Search {
I_ZONE,
E_ZONE,
break;
case SRC_HOST:
- if (inet_pton(AF_INET, s, (uint32_t*)&f->initiatorIp) == 0)
- inet_pton(AF_INET6, s, (uint32_t*)&f->initiatorIp);
- break;
-
- case DST_HOST:
- if (inet_pton(AF_INET, s, (uint32_t*)&f->responderIp) == 0)
- inet_pton(AF_INET6, s, (uint32_t*)&f->responderIp);
+ IpAddr((uint32_t*)&f->initiatorIp, s);
break;
case SRC_PORT:
f->initiatorPort = htons(atoi(s));
break;
+ case DST_HOST:
+ IpAddr((uint32_t*)&f->responderIp, s);
+ break;
+
case DST_PORT:
f->responderPort = htons(atoi(s));
break;
private:
void prune();
- ExpectNode* get_node(FlowKey&, bool&);
+ ExpectNode* get_node(snort::FlowKey&, bool&);
snort::ExpectFlow* get_flow(ExpectNode*, uint32_t, int16_t);
bool set_data(ExpectNode*, snort::ExpectFlow*&, snort::FlowData*);
- ExpectNode* find_node_by_packet(snort::Packet*, FlowKey&);
- bool process_expected(ExpectNode*, FlowKey&, snort::Packet*, snort::Flow*);
+ ExpectNode* find_node_by_packet(snort::Packet*, snort::FlowKey&);
+ bool process_expected(ExpectNode*, snort::FlowKey&, snort::Packet*, snort::Flow*);
private:
class ZHash* hash_table;
class BitOp;
class FlowHAState;
-struct FlowKey;
class Session;
namespace snort
{
+struct FlowKey;
struct Packet;
typedef void (* StreamAppDataFree)(void*);
namespace snort
{
class Flow;
-}
struct FlowKey;
+}
class FlowCache
{
void push(snort::Flow*);
- snort::Flow* find(const FlowKey*);
- snort::Flow* get(const FlowKey*);
+ snort::Flow* find(const snort::FlowKey*);
+ snort::Flow* get(const snort::FlowKey*);
int release(snort::Flow*, PruneReason = PruneReason::NONE, bool do_cleanup = true);
{
class Flow;
class FlowData;
+struct FlowKey;
struct Packet;
struct SfIp;
}
class FlowCache;
-struct FlowKey;
enum class PruneReason : uint8_t;
void process_user(snort::Packet*);
void process_file(snort::Packet*);
- snort::Flow* find_flow(const FlowKey*);
- snort::Flow* new_flow(const FlowKey*);
+ snort::Flow* find_flow(const snort::FlowKey*);
+ snort::Flow* new_flow(const snort::FlowKey*);
void init_ip(const FlowConfig&, snort::InspectSsnFunc);
void init_icmp(const FlowConfig&, snort::InspectSsnFunc);
void init_file(const FlowConfig&, snort::InspectSsnFunc);
void init_exp(uint32_t max);
- void delete_flow(const FlowKey*);
+ void delete_flow(const snort::FlowKey*);
void delete_flow(snort::Flow*, PruneReason);
void purge_flows(PktType);
bool prune_one(PruneReason, bool do_cleanup);
FlowCache* get_cache(PktType);
const FlowCache* get_cache(PktType) const;
- void set_key(FlowKey*, snort::Packet*);
+ void set_key(snort::FlowKey*, snort::Packet*);
unsigned process(snort::Flow*, snort::Packet*);
void preemptive_cleanup();
namespace snort
{
struct SfIp;
-}
PADDING_GUARD_BEGIN
-struct FlowKey
+struct SO_PUBLIC FlowKey
{
uint32_t ip_l[4]; /* Low IP */
uint32_t ip_h[4]; /* High IP */
};
PADDING_GUARD_END
+}
+
#endif
namespace snort
{
class Flow;
-}
struct FlowKey;
+}
// The FlowHAHandle is the dynamically allocated index used uniquely identify
// the client. Used both in the API and HA messages.
{
public:
virtual ~FlowHAClient() = default;
- virtual bool consume(snort::Flow*&, FlowKey*, HAMessage*) { return false; }
+ virtual bool consume(snort::Flow*&, snort::FlowKey*, HAMessage*) { return false; }
virtual bool produce(snort::Flow*, HAMessage*) { return false; }
virtual bool is_update_required(snort::Flow*) { return false; }
virtual bool is_delete_required(snort::Flow*) { return false; }
const Flow_Stats_t* fs = (const Flow_Stats_t*)ev->get_data();
+ SfIp src, dst;
char shost[INET6_ADDRSTRLEN];
char dhost[INET6_ADDRSTRLEN];
- const uint32_t *sip = (const uint32_t*)fs->initiatorIp;
- int fam = AF_INET;
- if ( sip[1] || sip[2] || sip[3] )
- fam = AF_INET6;
+ src.set(fs->initiatorIp);
+ dst.set(fs->responderIp);
- inet_ntop(fam, fs->initiatorIp, shost, INET6_ADDRSTRLEN);
- inet_ntop(fam, fs->responderIp, dhost, INET6_ADDRSTRLEN);
+ src.ntop(shost, sizeof(shost));
+ dst.ntop(dhost, sizeof(dhost));
int vlan_tag = fs->vlan_tag == 0xfff ? 0 : fs->vlan_tag;
struct FTP_DATA_SESSION
{
FTP_TELNET_SESSION ft_ssn;
- FlowKey ftp_key;
+ snort::FlowKey ftp_key;
char* filename;
int data_chan;
int file_xfer_info;
return SFIP_SUCCESS;
}
+SfIpRet SfIp::set(const void* src)
+{
+ assert(src);
+ if ( ((const uint32_t*)src)[0] == 0 &&
+ ((const uint32_t*)src)[1] == 0 &&
+ ((const uint16_t*)src)[4] == 0 &&
+ ((const uint16_t*)src)[5] == 0xffff )
+ return set(&((const uint32_t*)src)[3], AF_INET);
+ return set(src, AF_INET6);
+}
+
/* Obfuscates this IP with an obfuscation CIDR
Makes this: ob | (this & mask) */
void SfIp::obfuscate(SfCidr* ob)
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);
+ /* Sets to a raw source IP, source must be a 128 bit IPv6 (detects IPv4 mapped IPv6)
+ * This is specifically for conversion of Flow_Stats_t ipv4 mapped ipv6 addresses */
+ SfIpRet set(const void* src);
/* Converts string IP format to an array of values. Also checks IP address format. */
SfIpRet pton(const int fam, const char* ip);
{
public:
StreamHAClient() : FlowHAClient(sizeof(SessionHAContent), true) { }
- bool consume(snort::Flow*&, FlowKey*, HAMessage*) override;
+ bool consume(snort::Flow*&, snort::FlowKey*, HAMessage*) override;
bool produce(snort::Flow*, HAMessage*) override;
bool is_update_required(snort::Flow*) override;
bool is_delete_required(snort::Flow*) override;
ProtocolHA(PktType);
virtual ~ProtocolHA();
virtual void delete_session(snort::Flow*) { }
- virtual snort::Flow* create_session(FlowKey*) { return nullptr; }
+ virtual snort::Flow* create_session(snort::FlowKey*) { return nullptr; }
virtual void deactivate_session(snort::Flow*) { }
virtual void process_deletion(snort::Flow*);
{
public:
IcmpHA() : ProtocolHA(PktType::ICMP) { }
- snort::Flow* create_session(FlowKey*) override;
+ snort::Flow* create_session(snort::FlowKey*) override;
private:
};
{
public:
IpHA() : ProtocolHA(PktType::IP) { }
- snort::Flow* create_session(FlowKey*) override;
+ snort::Flow* create_session(snort::FlowKey*) override;
private:
};
{
public:
TcpHA() : ProtocolHA(PktType::TCP) { }
- snort::Flow* create_session(FlowKey*) override;
+ snort::Flow* create_session(snort::FlowKey*) override;
void deactivate_session(snort::Flow*) override;
private:
{
public:
UdpHA() : ProtocolHA(PktType::UDP) { }
- snort::Flow* create_session(FlowKey*) override;
+ snort::Flow* create_session(snort::FlowKey*) override;
private:
};