Skip to content

Commit

Permalink
Finally phase out old tcp client and server code, old network framework
Browse files Browse the repository at this point in the history
New tcp server for ringbufferhandler code
Temporarily disable datasource dev code during thrash
  • Loading branch information
dragorn committed Mar 6, 2017
1 parent 5daf719 commit cd122bd
Show file tree
Hide file tree
Showing 17 changed files with 532 additions and 42 deletions.
8 changes: 4 additions & 4 deletions Makefile.in
Expand Up @@ -12,10 +12,8 @@ PSO = util.o cygwin_utils.o globalregistry.o \
packet.o messagebus.o configfile.o getopt.o \
filtercore.o ifcontrol.o iwcontrol.o madwifing_control.o nl80211_control.o \
psutils.o ipc_remote.o battery.o kismet_json.o \
netframework.o clinetframework.o tcpserver.o tcpclient.o \
tcpclient2.o serialclient2.o pipeclient.o ipc_remote2.o \
tcpserver2.o tcpclient2.o serialclient2.o pipeclient.o ipc_remote2.o \
packetsourcetracker.o $(CAPSOURCES) \
datasourcetracker.o kis_datasource.o \
kis_net_microhttpd.o system_monitor.o kis_httpd_websession.o base64.o \
gps_manager.o kis_gps.o gpsserial2.o gpsgpsd2.o gpsfake.o gpsweb.o \
packetchain.o \
Expand All @@ -34,6 +32,8 @@ PSO = util.o cygwin_utils.o globalregistry.o \
messagebus_restclient.o \
kismet_server.o

#datasourcetracker.o kis_datasource.o \
PS = kismet_server

DRONEO =
Expand All @@ -53,7 +53,7 @@ DRONEO =
CSO = util.o cygwin_utils.o globalregistry.o ringbuf.o \
packet.o messagebus.o configfile.o getopt.o \
filtercore.o ifcontrol.o iwcontrol.o madwifing_control.o nl80211_control.o \
psutils.o ipc_remote.o netframework.o clinetframework.o tcpserver.o tcpclient.o \
psutils.o ipc_remote.o \
timetracker.o kismet_json.o \
packetsourcetracker.o packetchain.o $(CAPSOURCES) \
dumpfile.o dumpfile_tuntap.o \
Expand Down
90 changes: 60 additions & 30 deletions kis_datasource.h
Expand Up @@ -71,7 +71,9 @@ class KisDataSource_QueuedCommand;
// Supported source
class KisDataSource_SupportedSource;

// Forward definition of data sources
class KisDataSource;
typedef shared_ptr<KisDataSource> SharedDataSource;

/* KisDataSourceBuilder
*
Expand All @@ -81,6 +83,9 @@ class KisDataSource;
* It is stored as a tracker_component so that the tracker can directly
* serialize the data for displaying what sources are possible.
*/
class KisDataSourceBuilder;
typedef shared_ptr<KisDataSourceBuilder> SharedDataSourceBuilder;

class KisDataSourceBuilder : public tracker_component {
public:
KisDataSourceBuilder(GlobalRegistry *in_globalreg, int in_id) :
Expand All @@ -89,51 +94,76 @@ class KisDataSourceBuilder : public tracker_component {
reserve_fields(NULL);
}

KisDataSourceBuilder(GlobalRegistry *in_globalreg, int in_id,
SharedTrackerElement e) :
tracker_component(in_globalreg, in_id) {
register_fields();
reserve_fields(e);
}

virtual ~KisDataSourceBuilder();

// Build a source. Sources can be:
// - IPC (locally attached IPC channel using the kismet msgpack IPC
// protocol)
// - Remote (initiated by a remote TCP connection)
// - Lightweight (for low-bandwidth 'whole device record' style capture
// sources, which may implement a REST interface rather than a complete
// IPC channel)
virtual shared_ptr<KisDataSource> create_ipc_source() { return NULL; };
virtual shared_ptr<KisDataSource> create_net_source() { return NULL; };
virtual shared_ptr<KisDataSource> create_lightweight_source() { return NULL; }
virtual SharedTrackerElement clone_type() {
return SharedTrackerElement(new KisDataSourceBuilder(globalreg, get_id()));
}

// Build the actual data source
virtual SharedDataSource build_datasource() { return NULL; }

__Proxy(source_type, string, string, string, source_type);
__Proxy(source_description, string, string, string, source_description);

__Proxy(probe_capable, uint8_t, bool, bool, probe_capable);
__Proxy(list_capable, uint8_t, bool, bool, list_capable);
__Proxy(local_capable, uint8_t, bool, bool, local_capable);
__Proxy(remote_capable, uint8_t, bool, bool, remote_capable);
__Proxy(passive_capable, uint8_t, bool, bool, passive_capable);

protected:
int source_type_id;
virtual void register_fields() {
tracker_component::register_fields();

RegisterField("kismet.datasource.type", TrackerString,
"Datasource type", &source_type);

RegisterField("kismet.datasource.description", TrackerString,
"Datasource description", &source_description);

RegisterField("kismet.datasource.probe_capable", TrackerUInt8,
"Datasource can automatically probe", &probe_capable);

RegisterField("kismet.datasource.list_capable", TrackerUInt8,
"Datasource can list local interfaces", &list_capable);

RegisterField("kismet.datasource.local_capable", TrackerUInt8,
"Datasource can support local interfaces", &local_capable);

RegisterField("kismet.datasource.remote_capable", TrackerUInt8,
"Datasource can support remote interfaces", &remote_capable);

RegisterField("kismet.datasource.passive_capable", TrackerUInt8,
"Datasource can support passive interface-less data", &passive_capable);
}

SharedTrackerElement source_type;
SharedTrackerElement source_description;

SharedTrackerElement probe_capable;
SharedTrackerElement list_capable;
SharedTrackerElement local_capable;
SharedTrackerElement remote_capable;
SharedTrackerElement passive_capable;

};


class KisDataSource : public RingbufferInterface, public tracker_component {
class KisDataSource : public tracker_component {
public:
// Create a builder instance which only knows enough to be able to
// build a complete version of itself
KisDataSource(GlobalRegistry *in_globalreg);
virtual ~KisDataSource();

// Build a new instance of the class, used for opening and probing in IPC
// mode (local sources driven by kismet server)
virtual shared_ptr<KisDataSource> build_ipc_data_source() {
return NULL;
}

// Build a new instance of the class bound to an existing ringbuffer
// handler (used when spawned via the network server)
virtual shared_ptr<KisDataSource>
build_net_data_source(RingbufferHandler *in_handler __attribute__((unused))) {
return NULL;
}

// Error handler callback, called when something goes wrong in the source
// and it has to close.
typedef void (*error_handler)(shared_ptr<KisDataSource>, shared_ptr<void>);
virtual void set_error_handler(error_handler in_cb, shared_ptr<void> in_aux);
virtual void cancel_error_handler();

// Scan for supported devices, since this is async, provide a callback.
// Returns false if unable to launch scan, or true of scan is underway.
Expand Down
1 change: 0 additions & 1 deletion kis_pktproto.h
Expand Up @@ -22,7 +22,6 @@
#include "config.h"

#include "util.h"
#include "netframework.h"
#include "ipc_remote.h"

// Packet control IPC protocol
Expand Down
9 changes: 3 additions & 6 deletions kismet_server.cc
Expand Up @@ -68,15 +68,12 @@
#include "packetsource_airpcap.h"
#include "packetsourcetracker.h"

#include "kis_datasource.h"
#include "datasourcetracker.h"
// #include "kis_datasource.h"
// #include "datasourcetracker.h"

#include "timetracker.h"
#include "alertracker.h"

#include "netframework.h"
#include "tcpserver.h"

#include "kis_net_microhttpd.h"
#include "system_monitor.h"
#include "channeltracker2.h"
Expand Down Expand Up @@ -938,7 +935,7 @@ int main(int argc, char *argv[], char *envp[]) {
Channeltracker_V2::create_channeltracker(globalregistry);

// Add the datasource tracker
Datasourcetracker::create_dst(globalregistry);
// Datasourcetracker::create_dst(globalregistry);

// Create the packetsourcetracker
Packetsourcetracker::create_pst(globalregistry);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions ringbuf_handler.cc
Expand Up @@ -25,6 +25,8 @@
#include "ringbuf_handler.h"

RingbufferHandler::RingbufferHandler(size_t r_buffer_sz, size_t w_buffer_sz) {
closed = false;

if (r_buffer_sz != 0)
read_buffer = new RingbufV2(r_buffer_sz);
else
Expand Down Expand Up @@ -258,6 +260,18 @@ void RingbufferHandler::WriteBufferError(string in_error) {
wbuf_notify->BufferError(in_error);
}

void RingbufferHandler::CloseHandler() {
local_locker lock(&handler_locker);

closed = true;
}

bool RingbufferHandler::FetchClosed() {
local_locker lock(&handler_locker);

return closed;
}

RingbufferInterface::RingbufferInterface() {
handler = NULL;
read_handler = false;
Expand Down
9 changes: 8 additions & 1 deletion ringbuf_handler.h
Expand Up @@ -40,7 +40,7 @@ class RingbufferHandler {
public:
// For one-way buffers, define a buffer as having a size of zero
RingbufferHandler(size_t r_buffer_sz, size_t w_buffer_sz);
~RingbufferHandler();
virtual ~RingbufferHandler();

// Basic size ops
size_t GetReadBufferSize();
Expand Down Expand Up @@ -85,7 +85,14 @@ class RingbufferHandler {
void ReadBufferError(string in_error);
void WriteBufferError(string in_error);

// Close ring buffer (sets closed attribute, can be overridden; provides a
// non-error-oriented closure)
virtual void CloseHandler();
virtual bool FetchClosed();

protected:
bool closed;

RingbufV2 *read_buffer;
RingbufV2 *write_buffer;

Expand Down

0 comments on commit cd122bd

Please sign in to comment.