#include "daq_user.h"
+#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <stdlib.h>
DAQ_State state;
DAQ_Stats_t stats;
-} FileImpl;
+} HextImpl;
//-------------------------------------------------------------------------
// utility functions
//-------------------------------------------------------------------------
-static void set_c2s(FileImpl* impl, int c2s)
+static void set_c2s(HextImpl* impl, int c2s)
{
if ( c2s )
{
*port = atoi(s);
}
-static void parse_pci(FileImpl* impl, const char* s)
+static void parse_pci(HextImpl* impl, const char* s)
{
parse_host(s, &impl->pci.src_addr, &impl->pci.src_port);
impl->pci.flags &= ~DAQ_USR_FLAG_TO_SERVER;
}
-static unsigned flush(FileImpl* impl)
+static unsigned flush(HextImpl* impl)
{
unsigned n = impl->idx;
impl->idx = 0;
// $packet -> server
// $client <addr> <port>
// $server <addr> <port>
-static void parse_command(FileImpl* impl, char* s)
+static void parse_command(HextImpl* impl, char* s)
{
if ( !strncmp(s, "packet -> client", 16) )
set_c2s(impl, 0);
}
// load quoted string data into buffer up to snaplen
-static void parse_string(FileImpl* impl, char* s)
+static void parse_string(HextImpl* impl, char* s)
{
char t;
}
// load hex data into buffer up to snaplen
-static void parse_hex(FileImpl* impl, char* s)
+static void parse_hex(HextImpl* impl, char* s)
{
char* t = s;
long x = strtol(t, &s, 16);
}
}
-static int parse(FileImpl* impl)
+static int parse(HextImpl* impl)
{
char* s = impl->line;
// file functions
//-------------------------------------------------------------------------
-static int hext_setup(FileImpl* impl)
+static int hext_setup(HextImpl* impl)
{
if ( !strcmp(impl->name, "tty") )
{
return 0;
}
-static void hext_cleanup(FileImpl* impl)
+static void hext_cleanup(HextImpl* impl)
{
if ( impl->fyle != stdin )
fclose(impl->fyle);
impl->fyle = NULL;
}
-static int hext_read(FileImpl* impl)
+static int hext_read(HextImpl* impl)
{
int n = 0;
//-------------------------------------------------------------------------
static int get_vars (
- FileImpl* impl, const DAQ_Config_t* cfg, char* errBuf, size_t errMax
+ HextImpl* impl, const DAQ_Config_t* cfg, char* errBuf, size_t errMax
) {
const char* s = NULL;
DAQ_Dict* entry;
return 1;
}
-static void set_pkt_hdr(FileImpl* impl, DAQ_PktHdr_t* phdr, ssize_t len)
+static void set_pkt_hdr(HextImpl* impl, DAQ_PktHdr_t* phdr, ssize_t len)
{
struct timeval t;
gettimeofday(&t, NULL);
}
static int hext_daq_process(
- FileImpl* impl, DAQ_Analysis_Func_t cb, void* user)
+ HextImpl* impl, DAQ_Analysis_Func_t cb, void* user)
{
DAQ_PktHdr_t hdr;
int n = hext_read(impl);
static void hext_daq_shutdown (void* handle)
{
- FileImpl* impl = (FileImpl*)handle;
+ HextImpl* impl = (HextImpl*)handle;
if ( impl->name )
free(impl->name);
static int hext_daq_initialize (
const DAQ_Config_t* cfg, void** handle, char* errBuf, size_t errMax)
{
- FileImpl* impl = calloc(1, sizeof(*impl));
+ HextImpl* impl = calloc(1, sizeof(*impl));
if ( !impl )
{
static int hext_daq_start (void* handle)
{
- FileImpl* impl = (FileImpl*)handle;
+ HextImpl* impl = (HextImpl*)handle;
if ( hext_setup(impl) )
return DAQ_ERROR;
static int hext_daq_stop (void* handle)
{
- FileImpl* impl = (FileImpl*)handle;
+ HextImpl* impl = (HextImpl*)handle;
hext_cleanup(impl);
impl->state = DAQ_STATE_STOPPED;
return DAQ_SUCCESS;
{
(void)meta;
- FileImpl* impl = (FileImpl*)handle;
+ HextImpl* impl = (HextImpl*)handle;
int hit = 0, miss = 0;
impl->stop = 0;
static int hext_daq_breakloop (void* handle)
{
- FileImpl* impl = (FileImpl*)handle;
+ HextImpl* impl = (HextImpl*)handle;
impl->stop = 1;
return DAQ_SUCCESS;
}
static DAQ_State hext_daq_check_status (void* handle)
{
- FileImpl* impl = (FileImpl*)handle;
+ HextImpl* impl = (HextImpl*)handle;
return impl->state;
}
static int hext_daq_get_stats (void* handle, DAQ_Stats_t* stats)
{
- FileImpl* impl = (FileImpl*)handle;
+ HextImpl* impl = (HextImpl*)handle;
*stats = impl->stats;
return DAQ_SUCCESS;
}
static void hext_daq_reset_stats (void* handle)
{
- FileImpl* impl = (FileImpl*)handle;
+ HextImpl* impl = (HextImpl*)handle;
memset(&impl->stats, 0, sizeof(impl->stats));
}
static int hext_daq_get_snaplen (void* handle)
{
- FileImpl* impl = (FileImpl*)handle;
+ HextImpl* impl = (HextImpl*)handle;
return impl->snaplen;
}
static int hext_daq_get_datalink_type(void *handle)
{
- FileImpl* impl = (FileImpl*)handle;
+ HextImpl* impl = (HextImpl*)handle;
return impl->dlt;
}
static const char* hext_daq_get_errbuf (void* handle)
{
- FileImpl* impl = (FileImpl*)handle;
+ HextImpl* impl = (HextImpl*)handle;
return impl->error;
}
static void hext_daq_set_errbuf (void* handle, const char* s)
{
- FileImpl* impl = (FileImpl*)handle;
+ HextImpl* impl = (HextImpl*)handle;
DPE(impl->error, "%s", s ? s : "");
}
return DAQ_ERROR_NOTSUP;
}
+static int hext_query_flow(void *handle, const DAQ_PktHdr_t *hdr, DAQ_QueryFlow_t *query)
+{
+ HextImpl* impl = (HextImpl*)handle;
+ assert(hdr->priv_ptr == &impl->pci); // sanity check
+
+ if ( query->type == DAQ_USR_QUERY_PCI )
+ {
+ query->value = &impl->pci;
+ query->length = sizeof(impl->pci);
+ return DAQ_SUCCESS;
+ }
+ return DAQ_ERROR_NOTSUP;
+}
+
//-------------------------------------------------------------------------
#ifdef BUILDING_SO
.hup_prep = NULL,
.hup_apply = NULL,
.hup_post = NULL,
- .dp_add_dc = NULL
+ .dp_add_dc = NULL,
+ .query_flow = hext_query_flow
};
public:
SFDAQInstance(const char* intf);
~SFDAQInstance();
+
bool configure(const SnortConfig*);
+ void set_metacallback(DAQ_Meta_Func_t);
+
+ bool start();
+ bool was_started();
+ bool stop();
+ void reload();
void abort();
- const char* get_interface_spec();
+
int get_base_protocol();
+ const char* get_interface_spec();
+ const DAQ_Stats_t* get_stats();
+
bool can_inject();
bool can_inject_raw();
bool can_replace();
bool can_start_unprivileged();
bool can_whitelist();
- bool start();
- bool was_started();
- bool stop();
- void reload();
- void set_metacallback(DAQ_Meta_Func_t);
+
int acquire(int max, DAQ_Analysis_Func_t);
int inject(const DAQ_PktHdr_t*, int rev, const uint8_t* buf, uint32_t len);
bool break_loop(int error);
- const DAQ_Stats_t* get_stats();
+
+ SO_PUBLIC int query_flow(const DAQ_PktHdr_t*, DAQ_QueryFlow_t*);
int modify_flow_opaque(const DAQ_PktHdr_t*, uint32_t opaque);
int add_expected(const Packet* ctrlPkt, const SfIp* cliIP, uint16_t cliPort,
const SfIp* srvIP, uint16_t srvPort, IpProtocol, unsigned timeout_ms,
unsigned /* flags */);
+
private:
bool set_filter(const char*);
std::string interface_spec;
public:
static void load(const SnortConfig*);
static void unload();
+
static void print_types(std::ostream&);
static void init(const SnortConfig*);
static void term();
- static bool forwarding_packet(const DAQ_PktHdr_t*);
+
static const char* get_type();
- SO_PUBLIC static uint32_t get_snap_len();
- static bool unprivileged();
static const char* get_input_spec(const SnortConfig*, unsigned instance_id);
static const char* default_type();
+ static const DAQ_Stats_t* get_stats();
+
+ static bool unprivileged();
+ static bool can_inject();
+ static bool can_inject_raw();
+ static bool can_replace();
+
// FIXIT-M X Temporary thread-local instance helpers to be removed when no longer needed
static void set_local_instance(SFDAQInstance*);
- static SFDAQInstance* get_local_instance();
+
+ SO_PUBLIC static SFDAQInstance* get_local_instance();
SO_PUBLIC static const char* get_interface_spec();
SO_PUBLIC static int get_base_protocol();
- static bool can_inject();
- static bool can_inject_raw();
- static bool can_replace();
+ SO_PUBLIC static uint32_t get_snap_len();
+
static int inject(const DAQ_PktHdr_t*, int rev, const uint8_t* buf, uint32_t len);
+ static bool forwarding_packet(const DAQ_PktHdr_t*);
static bool break_loop(int error);
- static const DAQ_Stats_t* get_stats();
};
#endif