zeek/src/EventHandler.h
Jon Siwek f4101b5265 Improve handling of IPv6 routing type 0 extension headers.
- flow_weird event with name argument value of "routing0_hdr" is raised
  for packets containing an IPv6 routing type 0 header because this
  type of header is now deprecated according to RFC 5095.

- packets with a routing type 0 header and non-zero segments left
  now use the last address in that header in order to associate
  with a connection/flow and for calculating TCP/UDP checksums.

- added a set of IPv4/IPv6 TCP/UDP checksum unit tests
2012-03-27 16:05:45 -05:00

93 lines
2.3 KiB
C++

// Capsulates local and remote event handlers.
#ifndef EVENTHANDLER
#define EVENTHANDLER
#include <assert.h>
#include "List.h"
#include "BroList.h"
class Func;
class FuncType;
class Serializer;
class SerialInfo;
class UnserialInfo;
class EventHandler {
public:
EventHandler(const char* name);
~EventHandler();
const char* Name() { return name; }
Func* LocalHandler() { return local; }
FuncType* FType();
void SetLocalHandler(Func* f);
void AddRemoteHandler(SourceID peer);
void RemoveRemoteHandler(SourceID peer);
void Call(val_list* vl, bool no_remote = false);
// Returns true if there is at least one local or remote handler.
operator bool() const;
void SetUsed() { used = true; }
bool Used() { return used; }
// Handlers marked as error handlers will not be called recursively to
// avoid infinite loops if they trigger a similar error themselves.
void SetErrorHandler() { error_handler = true; }
bool ErrorHandler() { return error_handler; }
const char* Group() { return group; }
void SetGroup(const char* arg_group)
{ group = copy_string(arg_group); }
void SetEnable(bool arg_enable) { enabled = arg_enable; }
// We don't serialize the handler(s) itself here, but
// just the reference to it.
bool Serialize(SerialInfo* info) const;
static EventHandler* Unserialize(UnserialInfo* info);
private:
const char* name;
const char* group;
Func* local;
FuncType* type;
bool used; // this handler is indeed used somewhere
bool enabled;
bool error_handler; // this handler reports error messages.
declare(List, SourceID);
typedef List(SourceID) receiver_list;
receiver_list receivers;
};
// Encapsulates a ptr to an event handler to overload the boolean operator.
class EventHandlerPtr {
public:
EventHandlerPtr(EventHandler* p = 0) { handler = p; }
EventHandlerPtr(const EventHandlerPtr& h) { handler = h.handler; }
const EventHandlerPtr& operator=(EventHandler* p)
{ handler = p; return *this; }
const EventHandlerPtr& operator=(const EventHandlerPtr& h)
{ handler = h.handler; return *this; }
bool operator==(const EventHandlerPtr& h) const
{ return handler == h.handler; }
EventHandler* Ptr() { return handler; }
operator bool() const { return handler && *handler; }
EventHandler* operator->() { return handler; }
const EventHandler* operator->() const { return handler; }
private:
EventHandler* handler;
};
#endif