Remove PersistenceSerializer.

This commit is contained in:
Johanna Amann 2019-05-02 13:45:36 -07:00
parent 61c84a0a40
commit ca1b1dd6bb
15 changed files with 5 additions and 830 deletions

View file

@ -14,7 +14,6 @@ const char* attr_name(attr_tag t)
"&rotate_interval", "&rotate_size", "&rotate_interval", "&rotate_size",
"&add_func", "&delete_func", "&expire_func", "&add_func", "&delete_func", "&expire_func",
"&read_expire", "&write_expire", "&create_expire", "&read_expire", "&write_expire", "&create_expire",
"&persistent", "&synchronized",
"&encrypt", "&encrypt",
"&raw_output", "&mergeable", "&priority", "&raw_output", "&mergeable", "&priority",
"&group", "&log", "&error_handler", "&type_column", "&group", "&log", "&error_handler", "&type_column",

View file

@ -287,7 +287,6 @@ set(bro_SRCS
OpaqueVal.cc OpaqueVal.cc
OSFinger.cc OSFinger.cc
PacketFilter.cc PacketFilter.cc
PersistenceSerializer.cc
Pipe.cc Pipe.cc
PolicyFile.cc PolicyFile.cc
PrefixTable.cc PrefixTable.cc

View file

@ -151,7 +151,6 @@ Connection::Connection(NetSessions* s, HashKey* k, double t, const ConnID* id,
is_active = 1; is_active = 1;
skip = 0; skip = 0;
weird = 0; weird = 0;
persistent = 0;
suppress_event = 0; suppress_event = 0;
@ -951,15 +950,11 @@ bool Connection::DoSerialize(SerialInfo* info) const
SERIALIZE_BIT(weird) && SERIALIZE_BIT(weird) &&
SERIALIZE_BIT(finished) && SERIALIZE_BIT(finished) &&
SERIALIZE_BIT(record_packets) && SERIALIZE_BIT(record_packets) &&
SERIALIZE_BIT(record_contents) && SERIALIZE_BIT(record_contents);
SERIALIZE_BIT(persistent);
} }
bool Connection::DoUnserialize(UnserialInfo* info) bool Connection::DoUnserialize(UnserialInfo* info)
{ {
// Make sure this is initialized for the condition in Unserialize().
persistent = 0;
DO_UNSERIALIZE(BroObj); DO_UNSERIALIZE(BroObj);
// Build the hash key first. Some of the recursive *::Unserialize() // Build the hash key first. Some of the recursive *::Unserialize()
@ -1022,7 +1017,6 @@ bool Connection::DoUnserialize(UnserialInfo* info)
UNSERIALIZE_BIT(finished); UNSERIALIZE_BIT(finished);
UNSERIALIZE_BIT(record_packets); UNSERIALIZE_BIT(record_packets);
UNSERIALIZE_BIT(record_contents); UNSERIALIZE_BIT(record_contents);
UNSERIALIZE_BIT(persistent);
// Hmm... Why does each connection store a sessions ptr? // Hmm... Why does each connection store a sessions ptr?
sessions = ::sessions; sessions = ::sessions;

View file

@ -12,7 +12,6 @@
#include "Val.h" #include "Val.h"
#include "Timer.h" #include "Timer.h"
#include "Serializer.h" #include "Serializer.h"
#include "PersistenceSerializer.h"
#include "RuleMatcher.h" #include "RuleMatcher.h"
#include "IPAddr.h" #include "IPAddr.h"
#include "TunnelEncapsulation.h" #include "TunnelEncapsulation.h"
@ -228,14 +227,6 @@ public:
return 1; return 1;
} }
void MakePersistent()
{
persistent = 1;
persistence_serializer->Register(this);
}
bool IsPersistent() { return persistent; }
void Describe(ODesc* d) const override; void Describe(ODesc* d) const override;
void IDString(ODesc* d) const; void IDString(ODesc* d) const;
@ -315,7 +306,7 @@ public:
protected: protected:
Connection() { persistent = 0; } Connection() { }
// Add the given timer to expire at time t. If do_expire // Add the given timer to expire at time t. If do_expire
// is true, then the timer is also evaluated when Bro terminates, // is true, then the timer is also evaluated when Bro terminates,
@ -361,7 +352,6 @@ protected:
unsigned int weird:1; unsigned int weird:1;
unsigned int finished:1; unsigned int finished:1;
unsigned int record_packets:1, record_contents:1; unsigned int record_packets:1, record_contents:1;
unsigned int persistent:1;
unsigned int record_current_packet:1, record_current_content:1; unsigned int record_current_packet:1, record_current_content:1;
unsigned int saw_first_orig_packet:1, saw_first_resp_packet:1; unsigned int saw_first_orig_packet:1, saw_first_resp_packet:1;

View file

@ -11,7 +11,6 @@
#include "File.h" #include "File.h"
#include "Serializer.h" #include "Serializer.h"
#include "RemoteSerializer.h" #include "RemoteSerializer.h"
#include "PersistenceSerializer.h"
#include "Scope.h" #include "Scope.h"
#include "Traverse.h" #include "Traverse.h"
#include "zeexygen/Manager.h" #include "zeexygen/Manager.h"
@ -310,9 +309,6 @@ void ID::CopyFrom(const ID* id)
offset = id->offset ; offset = id->offset ;
infer_return_type = id->infer_return_type; infer_return_type = id->infer_return_type;
if ( FindAttr(ATTR_PERSISTENT) )
persistence_serializer->Unregister(this);
if ( id->type ) if ( id->type )
Ref(id->type); Ref(id->type);
if ( id->val && ! id->weak_ref ) if ( id->val && ! id->weak_ref )
@ -333,10 +329,6 @@ void ID::CopyFrom(const ID* id)
#ifdef DEBUG #ifdef DEBUG
UpdateValID(); UpdateValID();
#endif #endif
if ( FindAttr(ATTR_PERSISTENT) )
persistence_serializer->Unregister(this);
}
#endif #endif
ID* ID::Unserialize(UnserialInfo* info) ID* ID::Unserialize(UnserialInfo* info)
@ -371,7 +363,6 @@ ID* ID::Unserialize(UnserialInfo* info)
{ {
if ( info->id_policy != UnserialInfo::InstantiateNew ) if ( info->id_policy != UnserialInfo::InstantiateNew )
{ {
persistence_serializer->Unregister(current);
remote_serializer->Unregister(current); remote_serializer->Unregister(current);
} }

View file

@ -1,577 +0,0 @@
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <time.h>
#include <dirent.h>
#include <libgen.h>
#include <sys/time.h>
#include <sys/stat.h>
#include "PersistenceSerializer.h"
#include "RemoteSerializer.h"
#include "Conn.h"
#include "Event.h"
#include "Reporter.h"
#include "Net.h"
static void persistence_serializer_delete_func(void* val)
{
time_t* t = reinterpret_cast<time_t*>(val);
free(t);
}
class IncrementalWriteTimer : public Timer {
public:
IncrementalWriteTimer(double t, PersistenceSerializer::SerialStatus* s)
: Timer(t, TIMER_INCREMENTAL_WRITE), status(s) {}
void Dispatch(double t, int is_expire);
PersistenceSerializer::SerialStatus* status;
};
void IncrementalWriteTimer::Dispatch(double t, int is_expire)
{
// Never suspend when we're finishing up.
if ( terminating )
status->info.may_suspend = false;
persistence_serializer->RunSerialization(status);
}
PersistenceSerializer::PersistenceSerializer()
{
dir = 0;
files.SetDeleteFunc(persistence_serializer_delete_func);
}
PersistenceSerializer::~PersistenceSerializer()
{
}
void PersistenceSerializer::Register(ID* id)
{
if ( id->Type()->Tag() == TYPE_FUNC )
{
Error("can't register functions as persistent ID");
return;
}
DBG_LOG(DBG_STATE, "&persistent %s", id->Name());
HashKey key(id->Name());
if ( persistent_ids.Lookup(&key) )
return;
Ref(id);
persistent_ids.Insert(&key, id);
}
void PersistenceSerializer::Unregister(ID* id)
{
HashKey key(id->Name());
Unref((ID*) persistent_ids.Remove(&key));
}
void PersistenceSerializer::Register(Connection* conn)
{
if ( persistent_conns.Lookup(conn->Key()) )
return;
Ref(conn);
HashKey* k = conn->Key();
HashKey* new_key = new HashKey(k->Key(), k->Size(), k->Hash());
persistent_conns.Insert(new_key, conn);
delete new_key;
}
void PersistenceSerializer::Unregister(Connection* conn)
{
Unref(persistent_conns.RemoveEntry(conn->Key()));
}
bool PersistenceSerializer::CheckTimestamp(const char* file)
{
struct stat s;
if ( stat(file, &s) < 0 )
return false;
if ( ! S_ISREG(s.st_mode) )
return false;
bool changed = true;
HashKey* key = new HashKey(file, strlen(file));
time_t* t = files.Lookup(key);
if ( ! t )
{
t = (time_t*) malloc(sizeof(time_t));
if ( ! t )
out_of_memory("saving file timestamp");
files.Insert(key, t);
}
else if ( *t >= s.st_mtime )
changed = false;
*t = s.st_mtime;
delete key;
return changed;
}
bool PersistenceSerializer::CheckForFile(UnserialInfo* info, const char* file,
bool delete_file)
{
bool ret = true;
if ( CheckTimestamp(file) )
{
// Need to copy the filename here, as it may be passed
// in via fmt().
const char* f = copy_string(file);
bool ret = Read(info, f);
if ( delete_file && unlink(f) < 0 )
Error(fmt("can't delete file %s: %s", f, strerror(errno)));
delete [] f;
}
return ret;
}
bool PersistenceSerializer::ReadAll(bool is_init, bool delete_files)
{
#ifdef USE_PERFTOOLS_DEBUG
HeapLeakChecker::Disabler disabler;
#endif
assert(dir);
UnserialInfo config_info(this);
config_info.id_policy = is_init ?
UnserialInfo::Replace : UnserialInfo::CopyCurrentToNew;
if ( ! CheckForFile(&config_info, fmt("%s/config.bst", dir),
delete_files) )
return false;
UnserialInfo state_info(this);
state_info.id_policy = UnserialInfo::CopyNewToCurrent;
if ( ! CheckForFile(&state_info, fmt("%s/state.bst", dir),
delete_files) )
return false;
return true;
}
bool PersistenceSerializer::MoveFileUp(const char* dir, const char* file)
{
char oldname[PATH_MAX];
char newname[PATH_MAX];
safe_snprintf(oldname, PATH_MAX, "%s/.tmp/%s", dir, file );
safe_snprintf(newname, PATH_MAX, "%s/%s", dir, file );
if ( rename(oldname, newname) < 0 )
{
Error(fmt("can't move %s to %s: %s", oldname, newname,
strerror(errno)));
return false;
}
CheckTimestamp(newname);
return true;
}
#if 0
void PersistenceSerializer::RaiseFinishedSendState()
{
val_list* vl = new val_list;
vl->append(new AddrVal(htonl(remote_host)));
vl->append(val_mgr->GetPort(remote_port));
mgr.QueueEvent(finished_send_state, vl);
reporter->Log("Serialization done.");
}
#endif
void PersistenceSerializer::GotEvent(const char* name, double time,
EventHandlerPtr event, val_list* args)
{
mgr.QueueEvent(event, std::move(*args));
delete args;
}
void PersistenceSerializer::GotFunctionCall(const char* name, double time,
Func* func, val_list* args)
{
try
{
func->Call(args);
}
catch ( InterpreterException& e )
{ /* Already reported. */ }
}
void PersistenceSerializer::GotStateAccess(StateAccess* s)
{
s->Replay();
delete s;
}
void PersistenceSerializer::GotTimer(Timer* s)
{
reporter->Error("PersistenceSerializer::GotTimer not implemented");
}
void PersistenceSerializer::GotConnection(Connection* c)
{
Unref(c);
}
void PersistenceSerializer::GotID(ID* id, Val* /* val */)
{
Unref(id);
}
void PersistenceSerializer::GotPacket(Packet* p)
{
reporter->Error("PersistenceSerializer::GotPacket not implemented");
}
bool PersistenceSerializer::LogAccess(const StateAccess& s)
{
if ( ! IsSerializationRunning() )
return true;
loop_over_list(running, i)
{
running[i]->accesses.append(new StateAccess(s));
}
return true;
}
bool PersistenceSerializer::WriteState(bool may_suspend)
{
SerialStatus* status =
new SerialStatus(this, SerialStatus::WritingState);
status->info.may_suspend = may_suspend;
status->ids = &persistent_ids;
status->conns = &persistent_conns;
status->filename = "state.bst";
return RunSerialization(status);
}
bool PersistenceSerializer::WriteConfig(bool may_suspend)
{
if ( mgr.IsDraining() && may_suspend )
// Events which trigger checkpoint are flushed. Ignore; we'll
// checkpoint at termination in any case.
return true;
SerialStatus* status =
new SerialStatus(this, SerialStatus::WritingConfig);
status->info.may_suspend = may_suspend;
status->info.clear_containers = true;
status->ids = global_scope()->GetIDs();
status->filename = "config.bst";
return RunSerialization(status);
}
bool PersistenceSerializer::SendState(SourceID peer, bool may_suspend)
{
SerialStatus* status =
new SerialStatus(remote_serializer, SerialStatus::SendingState);
status->info.may_suspend = may_suspend;
status->ids = &persistent_ids;
status->conns = &persistent_conns;
status->peer = peer;
reporter->Info("Sending state...");
return RunSerialization(status);
}
bool PersistenceSerializer::SendConfig(SourceID peer, bool may_suspend)
{
SerialStatus* status =
new SerialStatus(remote_serializer, SerialStatus::SendingConfig);
status->info.may_suspend = may_suspend;
status->info.clear_containers = true;
status->ids = global_scope()->GetIDs();
status->peer = peer;
reporter->Info("Sending config...");
return RunSerialization(status);
}
bool PersistenceSerializer::RunSerialization(SerialStatus* status)
{
Continuation* cont = &status->info.cont;
if ( cont->NewInstance() )
{
// Serialization is starting. Initialize.
// See if there is already a serialization of this type running.
loop_over_list(running, i)
{
if ( running[i]->type == status->type )
{
reporter->Warning("Serialization of type %d already running.", status->type);
return false;
}
}
running.append(status);
// Initialize.
if ( ! (ensure_dir(dir) && ensure_dir(fmt("%s/.tmp", dir))) )
return false;
if ( ! OpenFile(fmt("%s/.tmp/%s", dir, status->filename), false) )
return false;
if ( ! PrepareForWriting() )
return false;
if ( status->ids )
{
status->id_cookie = status->ids->InitForIteration();
status->ids->MakeRobustCookie(status->id_cookie);
}
if ( status->conns )
{
status->conn_cookie = status->conns->InitForIteration();
status->conns->MakeRobustCookie(status->conn_cookie);
}
}
else if ( cont->ChildSuspended() )
{
// One of our former Serialize() calls suspended itself.
// We have to call it again.
if ( status->id_cookie )
{
if ( ! DoIDSerialization(status, status->current.id) )
return false;
if ( cont->ChildSuspended() )
{
// Oops, it did it again.
timer_mgr->Add(new IncrementalWriteTimer(network_time + state_write_delay, status));
return true;
}
}
else if ( status->conn_cookie )
{
if ( ! DoConnSerialization(status, status->current.conn) )
return false;
if ( cont->ChildSuspended() )
{
// Oops, it did it again.
timer_mgr->Add(new IncrementalWriteTimer(network_time + state_write_delay, status));
return true;
}
}
else
reporter->InternalError("unknown suspend state");
}
else if ( cont->Resuming() )
cont->Resume();
else
reporter->InternalError("unknown continuation state");
if ( status->id_cookie )
{
ID* id;
while ( (id = status->ids->NextEntry(status->id_cookie)) )
{
if ( ! DoIDSerialization(status, id) )
return false;
if ( cont->ChildSuspended() )
{
timer_mgr->Add(new IncrementalWriteTimer(network_time + state_write_delay, status));
return true;
}
if ( status->info.may_suspend )
{
timer_mgr->Add(new IncrementalWriteTimer(network_time + state_write_delay, status));
cont->Suspend();
return true;
}
}
// Cookie has been set to 0 by NextEntry().
}
if ( status->conn_cookie )
{
Connection* conn;
while ( (conn = status->conns->NextEntry(status->conn_cookie)) )
{
if ( ! DoConnSerialization(status, conn) )
return false;
if ( cont->ChildSuspended() )
{
timer_mgr->Add(new IncrementalWriteTimer(network_time + state_write_delay, status));
return true;
}
if ( status->info.may_suspend )
{
timer_mgr->Add(new IncrementalWriteTimer(network_time + state_write_delay, status));
cont->Suspend();
return true;
}
}
// Cookie has been set to 0 by NextEntry().
}
DBG_LOG(DBG_STATE, "finished serialization; %d accesses pending",
status->accesses.length());
if ( status->accesses.length() )
{
// Serialize pending state accesses.
// FIXME: Does this need to suspend?
StateAccess* access;
loop_over_list(status->accesses, i)
{
// Serializing a StateAccess will not suspend.
if ( ! DoAccessSerialization(status, status->accesses[i]) )
return false;
delete status->accesses[i];
}
}
// Finalize.
CloseFile();
bool ret = MoveFileUp(dir, status->filename);
loop_over_list(running, i)
{
if ( running[i]->type == status->type )
{
running.remove_nth(i);
break;
}
}
delete status;
return ret;
}
bool PersistenceSerializer::DoIDSerialization(SerialStatus* status, ID* id)
{
bool success = false;
Continuation* cont = &status->info.cont;
status->current.id = id;
switch ( status->type ) {
case SerialStatus::WritingState:
case SerialStatus::WritingConfig:
cont->SaveContext();
success = Serialize(&status->info, *id);
cont->RestoreContext();
break;
case SerialStatus::SendingState:
case SerialStatus::SendingConfig:
cont->SaveContext();
success = remote_serializer->SendID(&status->info,
status->peer, *id);
cont->RestoreContext();
break;
default:
reporter->InternalError("unknown serialization type");
}
return success;
}
bool PersistenceSerializer::DoConnSerialization(SerialStatus* status,
Connection* conn)
{
bool success = false;
Continuation* cont = &status->info.cont;
status->current.conn = conn;
switch ( status->type ) {
case SerialStatus::WritingState:
case SerialStatus::WritingConfig:
cont->SaveContext();
success = Serialize(&status->info, *conn);
cont->RestoreContext();
break;
case SerialStatus::SendingState:
case SerialStatus::SendingConfig:
cont->SaveContext();
success = remote_serializer->SendConnection(&status->info,
status->peer, *conn);
cont->RestoreContext();
break;
default:
reporter->InternalError("unknown serialization type");
}
return success;
}
bool PersistenceSerializer::DoAccessSerialization(SerialStatus* status,
StateAccess* access)
{
bool success = false;
DisableSuspend suspend(&status->info);
switch ( status->type ) {
case SerialStatus::WritingState:
case SerialStatus::WritingConfig:
success = Serialize(&status->info, *access);
break;
case SerialStatus::SendingState:
case SerialStatus::SendingConfig:
success = remote_serializer->SendAccess(&status->info,
status->peer, *access);
break;
default:
reporter->InternalError("unknown serialization type");
}
return success;
}

View file

@ -1,165 +0,0 @@
// Implements persistance for Bro's data structures.
#ifndef persistence_serializer_h
#define persistence_serializer_h
#include "Serializer.h"
#include "List.h"
class StateAccess;
class PersistenceSerializer : public FileSerializer {
public:
PersistenceSerializer();
~PersistenceSerializer() override;
// Define the directory where to store the data.
void SetDir(const char* arg_dir) { dir = copy_string(arg_dir); }
// Register/unregister the ID/connection to be saved by WriteAll().
void Register(ID* id);
void Unregister(ID* id);
void Register(Connection* conn);
void Unregister(Connection* conn);
// Read all data that has been changed since last scan of directory.
// is_init should be true for the first read upon start-up. All existing
// state will be cleared. If delete_files is true, file which have been
// read are removed (even if the read was unsuccessful!).
bool ReadAll(bool is_init, bool delete_files);
// Each of the following four methods may suspend operation.
// If they do, they install a Timer which resumes after some
// amount of time. If a function is called again before it
// has completely finished its task, it will do nothing and
// return false.
bool WriteState(bool may_suspend);
// Writes Bro's configuration (w/o dynamic state).
bool WriteConfig(bool may_suspend);
// Sends all registered state to remote host
// (by leveraging the remote_serializer).
bool SendState(SourceID peer, bool may_suspend);
// Sends Bro's config to remote host
// (by leveraging the remote_serializer).
bool SendConfig(SourceID peer, bool may_suspend);
// Returns true if a serialization is currently running.
bool IsSerializationRunning() const { return running.length(); }
// Tells the serializer that this access was performed. If a
// serialization is going on, it may store it. (Need only be called if
// IsSerializationRunning() returns true.)
bool LogAccess(const StateAccess& s);
protected:
friend class RemoteSerializer;
friend class IncrementalWriteTimer;
void GotID(ID* id, Val* val) override;
void GotEvent(const char* name, double time,
EventHandlerPtr event, val_list* args) override;
void GotFunctionCall(const char* name, double time,
Func* func, val_list* args) override;
void GotStateAccess(StateAccess* s) override;
void GotTimer(Timer* t) override;
void GotConnection(Connection* c) override;
void GotPacket(Packet* packet) override;
// If file has changed since last check, read it.
bool CheckForFile(UnserialInfo* info, const char* file,
bool delete_file);
// Returns true if it's a regular file and has a more recent timestamp
// than last time we checked it.
bool CheckTimestamp(const char* file);
// Move file from <dir>/tmp/<file> to <dir>/<file>. Afterwards, call
// CheckTimestamp() with <dir>/<file>.
bool MoveFileUp(const char* dir, const char* file);
// Generates an error message, terminates current serialization,
// and returns false.
bool SerialError(const char* msg);
// Start a new serialization.
struct SerialStatus;
bool RunSerialization(SerialStatus* status);
// Helpers for RunSerialization.
bool DoIDSerialization(SerialStatus* status, ID* id);
bool DoConnSerialization(SerialStatus* status, Connection* conn);
bool DoAccessSerialization(SerialStatus* status, StateAccess* access);
typedef PDict(ID) id_map;
declare(PDict, Connection);
typedef PDict(Connection) conn_map;
struct SerialStatus {
enum Type {
WritingState, WritingConfig,
SendingState, SendingConfig,
};
SerialStatus(Serializer* s, Type arg_type) : info(s)
{
type = arg_type;
ids = 0;
id_cookie = 0;
conns = 0;
conn_cookie = 0;
peer = SOURCE_LOCAL;
filename = 0;
}
Type type;
SerialInfo info;
// IDs to serialize.
id_map* ids;
IterCookie* id_cookie;
// Connections to serialize.
conn_map* conns;
IterCookie* conn_cookie;
// Accesses performed while we're serializing.
declare(PList,StateAccess);
typedef PList(StateAccess) state_access_list;
state_access_list accesses;
// The ID/Conn we're currently serializing.
union {
ID* id;
Connection* conn;
} current;
// Only set if type is Writing{State,Config}.
const char* filename;
// Only set if type is Sending{State,Config}.
SourceID peer;
};
const char* dir;
declare(PList, SerialStatus);
PList(SerialStatus) running;
id_map persistent_ids;
conn_map persistent_conns;
// To keep track of files' modification times.
declare(PDict, time_t);
typedef PDict(time_t) file_map;
file_map files;
};
extern PersistenceSerializer* persistence_serializer;
#endif

View file

@ -166,7 +166,6 @@ public:
static void Log(LogLevel level, const char* msg); static void Log(LogLevel level, const char* msg);
protected: protected:
friend class PersistenceSerializer;
friend class IncrementalSendTimer; friend class IncrementalSendTimer;
// Maximum size of serialization caches. // Maximum size of serialization caches.

View file

@ -508,8 +508,6 @@ bool Serializer::UnserializeConnection(UnserialInfo* info)
if ( info->install_conns ) if ( info->install_conns )
{ {
if ( c->IsPersistent() && c->Key() )
persistence_serializer->Register(c);
Ref(c); Ref(c);
sessions->Insert(c); sessions->Insert(c);
} }

View file

@ -1101,9 +1101,6 @@ void NetSessions::Remove(Connection* c)
tcp_stats.StateLeft(to->state, tr->state); tcp_stats.StateLeft(to->state, tr->state);
} }
if ( c->IsPersistent() )
persistence_serializer->Unregister(c);
c->Done(); c->Done();
if ( connection_state_remove ) if ( connection_state_remove )
@ -1194,8 +1191,6 @@ void NetSessions::Insert(Connection* c)
// Some clean-ups similar to those in Remove() (but invisible // Some clean-ups similar to those in Remove() (but invisible
// to the script layer). // to the script layer).
old->CancelTimers(); old->CancelTimers();
if ( old->IsPersistent() )
persistence_serializer->Unregister(old);
delete old->Key(); delete old->Key();
old->ClearKey(); old->ClearKey();
Unref(old); Unref(old);

View file

@ -5,7 +5,6 @@
#include "NetVar.h" #include "NetVar.h"
#include "DebugLogger.h" #include "DebugLogger.h"
#include "RemoteSerializer.h" #include "RemoteSerializer.h"
#include "PersistenceSerializer.h"
int StateAccess::replaying = 0; int StateAccess::replaying = 0;
@ -870,8 +869,6 @@ void StateAccess::Describe(ODesc* d) const
void StateAccess::Log(StateAccess* access) void StateAccess::Log(StateAccess* access)
{ {
bool synchronized = false;
bool persistent = false;
bool tracked = false; bool tracked = false;
if ( access->target_type == TYPE_ID ) if ( access->target_type == TYPE_ID )
@ -885,30 +882,14 @@ void StateAccess::Log(StateAccess* access)
tracked = true; tracked = true;
} }
if ( synchronized )
{
if ( state_serializer )
{
SerialInfo info(state_serializer);
state_serializer->Serialize(&info, *access);
}
SerialInfo info(remote_serializer);
remote_serializer->SendAccess(&info, *access);
}
if ( persistent && persistence_serializer->IsSerializationRunning() )
persistence_serializer->LogAccess(*access);
if ( tracked ) if ( tracked )
notifiers.AccessPerformed(*access); notifiers.AccessPerformed(*access);
#ifdef DEBUG #ifdef DEBUG
ODesc desc; ODesc desc;
access->Describe(&desc); access->Describe(&desc);
DBG_LOG(DBG_STATE, "operation: %s%s [%s%s]", DBG_LOG(DBG_STATE, "operation: %s%s",
desc.Description(), replaying > 0 ? " (replay)" : "", desc.Description(), replaying > 0 ? " (replay)" : "");
persistent ? "P" : "", synchronized ? "S" : "");
#endif #endif
delete access; delete access;

View file

@ -21,7 +21,6 @@ const char* TimerNames[] = {
"FlowWeirdTimer", "FlowWeirdTimer",
"FragTimer", "FragTimer",
"IncrementalSendTimer", "IncrementalSendTimer",
"IncrementalWriteTimer",
"InterconnTimer", "InterconnTimer",
"IPTunnelInactivityTimer", "IPTunnelInactivityTimer",
"NetbiosExpireTimer", "NetbiosExpireTimer",

View file

@ -26,7 +26,6 @@ enum TimerType {
TIMER_FLOW_WEIRD_EXPIRE, TIMER_FLOW_WEIRD_EXPIRE,
TIMER_FRAG, TIMER_FRAG,
TIMER_INCREMENTAL_SEND, TIMER_INCREMENTAL_SEND,
TIMER_INCREMENTAL_WRITE,
TIMER_INTERCONN, TIMER_INTERCONN,
TIMER_IP_TUNNEL_INACTIVITY, TIMER_IP_TUNNEL_INACTIVITY,
TIMER_NB_EXPIRE, TIMER_NB_EXPIRE,

View file

@ -40,7 +40,6 @@ extern "C" {
#include "Anon.h" #include "Anon.h"
#include "Serializer.h" #include "Serializer.h"
#include "RemoteSerializer.h" #include "RemoteSerializer.h"
#include "PersistenceSerializer.h"
#include "EventRegistry.h" #include "EventRegistry.h"
#include "Stats.h" #include "Stats.h"
#include "Brofiler.h" #include "Brofiler.h"
@ -101,7 +100,6 @@ name_list prefixes;
Stmt* stmts; Stmt* stmts;
EventHandlerPtr net_done = 0; EventHandlerPtr net_done = 0;
RuleMatcher* rule_matcher = 0; RuleMatcher* rule_matcher = 0;
PersistenceSerializer* persistence_serializer = 0;
FileSerializer* event_serializer = 0; FileSerializer* event_serializer = 0;
FileSerializer* state_serializer = 0; FileSerializer* state_serializer = 0;
RemoteSerializer* remote_serializer = 0; RemoteSerializer* remote_serializer = 0;
@ -167,7 +165,6 @@ void usage(int code = 1)
fprintf(stderr, " -d|--debug-policy | activate policy file debugging\n"); fprintf(stderr, " -d|--debug-policy | activate policy file debugging\n");
fprintf(stderr, " -e|--exec <bro code> | augment loaded policies by given code\n"); fprintf(stderr, " -e|--exec <bro code> | augment loaded policies by given code\n");
fprintf(stderr, " -f|--filter <filter> | tcpdump filter\n"); fprintf(stderr, " -f|--filter <filter> | tcpdump filter\n");
fprintf(stderr, " -g|--dump-config | dump current config into .state dir\n");
fprintf(stderr, " -h|--help | command line help\n"); fprintf(stderr, " -h|--help | command line help\n");
fprintf(stderr, " -i|--iface <interface> | read from given interface\n"); fprintf(stderr, " -i|--iface <interface> | read from given interface\n");
fprintf(stderr, " -p|--prefix <prefix> | add given prefix to policy file resolution\n"); fprintf(stderr, " -p|--prefix <prefix> | add given prefix to policy file resolution\n");
@ -291,9 +288,6 @@ void done_with_network()
true); true);
} }
// Save state before expiring the remaining events/timers.
persistence_serializer->WriteState(false);
if ( profiling_logger ) if ( profiling_logger )
profiling_logger->Log(); profiling_logger->Log();
@ -371,7 +365,6 @@ void terminate_bro()
delete zeexygen_mgr; delete zeexygen_mgr;
delete timer_mgr; delete timer_mgr;
delete persistence_serializer;
delete event_serializer; delete event_serializer;
delete state_serializer; delete state_serializer;
delete event_registry; delete event_registry;
@ -452,7 +445,6 @@ int main(int argc, char** argv)
char* debug_streams = 0; char* debug_streams = 0;
int parse_only = false; int parse_only = false;
int bare_mode = false; int bare_mode = false;
int dump_cfg = false;
int do_watchdog = 0; int do_watchdog = 0;
int override_ignore_checksums = 0; int override_ignore_checksums = 0;
int rule_debug = 0; int rule_debug = 0;
@ -464,7 +456,6 @@ int main(int argc, char** argv)
{"parse-only", no_argument, 0, 'a'}, {"parse-only", no_argument, 0, 'a'},
{"bare-mode", no_argument, 0, 'b'}, {"bare-mode", no_argument, 0, 'b'},
{"debug-policy", no_argument, 0, 'd'}, {"debug-policy", no_argument, 0, 'd'},
{"dump-config", no_argument, 0, 'g'},
{"exec", required_argument, 0, 'e'}, {"exec", required_argument, 0, 'e'},
{"filter", required_argument, 0, 'f'}, {"filter", required_argument, 0, 'f'},
{"help", no_argument, 0, 'h'}, {"help", no_argument, 0, 'h'},
@ -565,10 +556,6 @@ int main(int argc, char** argv)
user_pcap_filter = optarg; user_pcap_filter = optarg;
break; break;
case 'g':
dump_cfg = true;
break;
case 'h': case 'h':
usage(0); usage(0);
break; break;
@ -795,7 +782,6 @@ int main(int argc, char** argv)
dns_mgr->SetDir(".state"); dns_mgr->SetDir(".state");
iosource_mgr = new iosource::Manager(); iosource_mgr = new iosource::Manager();
persistence_serializer = new PersistenceSerializer();
remote_serializer = new RemoteSerializer(); remote_serializer = new RemoteSerializer();
event_registry = new EventRegistry(); event_registry = new EventRegistry();
analyzer_mgr = new analyzer::Manager(); analyzer_mgr = new analyzer::Manager();
@ -1012,13 +998,9 @@ int main(int argc, char** argv)
exit(0); exit(0);
} }
persistence_serializer->SetDir((const char *)state_dir->AsString()->CheckString());
// Print the ID. // Print the ID.
if ( id_name ) if ( id_name )
{ {
persistence_serializer->ReadAll(true, false);
ID* id = global_scope()->Lookup(id_name); ID* id = global_scope()->Lookup(id_name);
if ( ! id ) if ( ! id )
reporter->FatalError("No such ID: %s\n", id_name); reporter->FatalError("No such ID: %s\n", id_name);
@ -1032,14 +1014,6 @@ int main(int argc, char** argv)
exit(0); exit(0);
} }
persistence_serializer->ReadAll(true, true);
if ( dump_cfg )
{
persistence_serializer->WriteConfig(false);
exit(0);
}
if ( profiling_interval > 0 ) if ( profiling_interval > 0 )
{ {
profiling_logger = new ProfileLogger(profiling_file->AsFile(), profiling_logger = new ProfileLogger(profiling_file->AsFile(),
@ -1205,7 +1179,6 @@ int main(int argc, char** argv)
} }
else else
{ {
persistence_serializer->WriteState(false);
terminate_bro(); terminate_bro();
} }

View file

@ -5,7 +5,7 @@
// Switching parser table type fixes ambiguity problems. // Switching parser table type fixes ambiguity problems.
%define lr.type ielr %define lr.type ielr
%expect 141 %expect 129
%token TOK_ADD TOK_ADD_TO TOK_ADDR TOK_ANY %token TOK_ADD TOK_ADD_TO TOK_ADDR TOK_ANY
%token TOK_ATENDIF TOK_ATELSE TOK_ATIF TOK_ATIFDEF TOK_ATIFNDEF %token TOK_ATENDIF TOK_ATELSE TOK_ATIF TOK_ATIFDEF TOK_ATIFNDEF