xorp

Configuration Class Reference

Class that contains all configuration and generated code state. More...

#include <configuration.hh>

Inheritance diagram for Configuration:
NONCOPYABLE

List of all members.

Classes

class  ConfError
 Exception thrown on configuration error. More...

Public Types

typedef map< string, Code * > CodeMap
typedef map< string, TagSet * > TagMap

Public Member Functions

 Configuration (ProcessWatchBase &pw)
void delete_term (const string &policy, const string &term)
 Throws an exception on failure.
void update_term_block (const string &policy, const string &term, const uint32_t &block, const ConfigNodeId &order, const string &statement)
 Update the source/dest/action block of a term.
void create_term (const string &policy, const ConfigNodeId &order, const string &term)
 Append a term to a policy.
void create_policy (const string &policy)
 Throws an exception on failure.
void delete_policy (const string &policy)
 Throws an exception on failure.
void create_set (const string &set)
 Throws an exception on failure.
void update_set (const string &type, const string &set, const string &elements)
 Throws an exception on failure.
void delete_set (const string &set)
 Throws an exception on failure.
void add_to_set (const string &type, const string &name, const string &element)
 Add an element to a set.
void delete_from_set (const string &type, const string &name, const string &element)
 Delete an element from a set.
void update_imports (const string &protocol, const POLICIES &imports, const string &mod)
 Throws an exception on failure.
void update_exports (const string &protocol, const POLICIES &exports, const string &mod)
 Throws an exception on failure.
string str ()
void commit (uint32_t msec)
 Commit all configuration changes.
void add_varmap (const string &protocol, const string &name, const string &type, const string &access, const VarRW::Id &id)
 Add a variable to the VarMap, needed for semantic checking.
void set_filter_manager (FilterManagerBase &)
 This method should be called once at initialization to set the FilterManager.
CodeMap & import_filters ()
 A CodeMap is a map relating protocols to code.
CodeMap & sourcematch_filters ()
CodeMap & export_filters ()
SetMapsets ()
TagMap & tagmap ()
string dump_state (uint32_t id)
 Dump internal state.
void clear_imports (const string &protocol)
void clear_exports (const string &protocol)
bool test_policy (const string &policy, const RATTR &attrs, RATTR &mods)
void show (const string &type, const string &name, RESOURCES &res)
void show_sets (const string &type, const string &name, RESOURCES &res)
void show_policies (const string &name, RESOURCES &res)

Private Types

typedef set< string > PolicySet

Private Member Functions

Termfind_term (const string &policy, const string &term)
 Throws an exception if no term is found.
void update_dependencies (PolicyStatement &policy)
 Scans policy and checks which sets it uses.
void compile_policy (const string &name)
 Generate code for a policy.
void compile_policies ()
 Compile all modified and non previously compiled policies.
void link_sourcematch_code (const Code::Target &target)
 Links all source match filter code for a specific target.
void update_tagmap (const string &protocol)
 Update the policytags used by a protocol.
void link_code ()
 Link code for updated targets.
void update_ie (const string &protocol, const POLICIES &policies, IEMap &iemap, PolicyList::PolicyType pt, const string &mod)
void link_code (const Code::Target &target, IEMap &iemap, CodeMap &codemap)
string codemap_str (CodeMap &cm)
void policy_modified (const string &policy)

Private Attributes

PolicyMap _policies
IEMap _imports
IEMap _exports
SetMap _sets
PolicySet _modified_policies
TARGETSET _modified_targets
ElementFactory _ef
CodeMap _import_filters
CodeMap _sourcematch_filters
CodeMap _export_filters
tag_t _currtag
map< string, set< uint32_t > > _protocol_tags
TagMap _tagmap
VarMap _varmap
FilterManagerBase_filter_manager

Detailed Description

Class that contains all configuration and generated code state.

This class contains all user policy configuration. It updates the relevant configuration portions based on user changes. Also, it does some sanity checking by (dis)allowing the user to do certain actions [such as delete sets which are referenced in policies].


Constructor & Destructor Documentation

Configuration::Configuration ( ProcessWatchBase pw)
Parameters:
aprocess watcher used to initialize the VarMap.

Member Function Documentation

void Configuration::add_to_set ( const string &  type,
const string &  name,
const string &  element 
)

Add an element to a set.

Throws an exception on failure. Checks if set exists.

Parameters:
typethe type of the set.
namename of the set.
elementthe element to add.
void Configuration::add_varmap ( const string &  protocol,
const string &  name,
const string &  type,
const string &  access,
const VarRW::Id &  id 
)

Add a variable to the VarMap, needed for semantic checking.

Parameters:
protocolthe protocol this variable is available to.
variablename of the variable.
typethe type of the variable.
accessthe permissions on the variable (r/rw).
idthe id used for VarRW interaction.
void Configuration::commit ( uint32_t  msec)

Commit all configuration changes.

This will compile all needed policies and link them. It will then commit changes to the actual policy filters. Commits are optionally delayed in order to aggregate configuration changes. For example, at boot-up many small changes are done in small time intervals. It would be more efficient to configure the filters only after all changes have been made. Thus delaying a commit will help.

The delay will only be imposed on sending the configuration to the filters -- all semantic checks and compile is done immediately.

Parameters:
msecmilliseconds after which code should be sent to filters.
void Configuration::compile_policies ( ) [private]

Compile all modified and non previously compiled policies.

Throws an exception on failure.

void Configuration::compile_policy ( const string &  name) [private]

Generate code for a policy.

Throws an exception on failure.

Parameters:
namename of policy to be compiled.
void Configuration::create_policy ( const string &  policy)

Throws an exception on failure.

Checks if policy already exists.

Parameters:
policypolicy which should be created.
void Configuration::create_set ( const string &  set)

Throws an exception on failure.

Checks if set already exists.

Parameters:
setname of the set to be created.
void Configuration::create_term ( const string &  policy,
const ConfigNodeId order,
const string &  term 
)

Append a term to a policy.

Throws an exception on failure. Checks if term already exists.

Parameters:
policypolicy in which term should be created.
ordernode ID with position of term.
termterm name which should be created.
void Configuration::delete_from_set ( const string &  type,
const string &  name,
const string &  element 
)

Delete an element from a set.

Throws an exception on failure. Checks if set exists.

Parameters:
typethe type of the set.
namename of the set.
elementthe element to delete.
void Configuration::delete_policy ( const string &  policy)

Throws an exception on failure.

Checks if policy is in use [instantiated by an export/import directive.]

Parameters:
policypolicy which should be deleted.
void Configuration::delete_set ( const string &  set)

Throws an exception on failure.

Checks if set is in use.

Parameters:
setname of set to delete.
void Configuration::delete_term ( const string &  policy,
const string &  term 
)

Throws an exception on failure.

Checks for non-existant policy/term conditions.

Parameters:
policypolicy in which term should be deleted.
termterm to delete.
string Configuration::dump_state ( uint32_t  id)

Dump internal state.

Debugging only.

Parameters:
idspecifies which aspect of state to dump.
Returns:
human readable state information.
CodeMap& Configuration::export_filters ( ) [inline]
Returns:
the CodeMap for export filters.
Term & Configuration::find_term ( const string &  policy,
const string &  term 
) [private]

Throws an exception if no term is found.

Returns:
term being searched for.
Parameters:
policypolicy name term should be found in.
termterm being searched for.
CodeMap& Configuration::import_filters ( ) [inline]

A CodeMap is a map relating protocols to code.

All the code for a protocol will be found in its entry. The code however will normally be for a specific filter.

Returns:
the CodeMap for import filters.
void Configuration::link_sourcematch_code ( const Code::Target target) [private]

Links all source match filter code for a specific target.

Code is internally kept fragmented [so deleting one policy will not involve recompiling the whole policy list for a target, for example].

Parameters:
targettarget for which code should be linked.
void Configuration::set_filter_manager ( FilterManagerBase fm)

This method should be called once at initialization to set the FilterManager.

It should not be deleted by the Configuration class -- it does not own it.

SetMap& Configuration::sets ( ) [inline]
Returns:
the SetMap relating set-name to the actual set.
CodeMap& Configuration::sourcematch_filters ( ) [inline]
Returns:
the CodeMap for source match filters.
string Configuration::str ( )
Returns:
string representation of configuration
TagMap& Configuration::tagmap ( ) [inline]
Returns:
the policy tag map relating policytags to destination protocols.
void Configuration::update_dependencies ( PolicyStatement policy) [private]

Scans policy and checks which sets it uses.

It also binds the policy to those sets, so sets may not be deleted.

Parameters:
policypolicy which should have set dependencies updated.
void Configuration::update_exports ( const string &  protocol,
const POLICIES &  exports,
const string &  mod 
)

Throws an exception on failure.

Checks if policies exist.

Parameters:
protocolname of protocol which should have exports updated.
exportslist of policy-names.
void Configuration::update_imports ( const string &  protocol,
const POLICIES &  imports,
const string &  mod 
)

Throws an exception on failure.

Checks if policies exist.

Parameters:
protocolname of protocol which should have imports updated.
importslist of policy-names.
void Configuration::update_set ( const string &  type,
const string &  set,
const string &  elements 
)

Throws an exception on failure.

Checks if set exists.

Parameters:
typethe type of the set.
setname of the set to be updated.
elementscomma separated elements to be replaced in set.
void Configuration::update_tagmap ( const string &  protocol) [private]

Update the policytags used by a protocol.

Parameters:
protocolprotocol for which to update policytags.
void Configuration::update_term_block ( const string &  policy,
const string &  term,
const uint32_t &  block,
const ConfigNodeId order,
const string &  statement 
)

Update the source/dest/action block of a term.

Throws an exception on failure. Checks for non-existent policy/term conditions. Also tries to parse the configuration. No compilation / semantic check is performed now.

Parameters:
policythe name of the policy.
termthe name of the term.
blockthe block to update (0:source, 1:dest, 2:action).
ordernode ID with position of term.
statementthe statement to insert.

The documentation for this class was generated from the following files:
 All Classes Namespaces Functions Variables Typedefs Enumerations