base/frameworks/netcontrol/main.bro
-
NetControl
Bro’s NetControl framework.
This plugin-based framework allows to control the traffic that Bro monitors
as well as, if having access to the forwarding path, the traffic the network
forwards. By default, the framework lets everything through, to both Bro
itself as well as on the network. Scripts can then add rules to impose
restrictions on entities, such as specific connections or IP addresses.
This framework has two APIs: a high-level and low-level. The high-level API
provides convenience functions for a set of common operations. The
low-level API provides full flexibility.
Detailed Interface
Types
-
NetControl::Info
-
The record type defining the column fields of the NetControl log.
-
NetControl::InfoCategory
Type: | enum
-
NetControl::MESSAGE
A log entry reflecting a framework message.
-
NetControl::ERROR
A log entry reflecting a framework message.
-
NetControl::RULE
A log entry about a rule.
|
Type of an entry in the NetControl log.
-
NetControl::InfoState
Type: | enum
-
NetControl::REQUESTED
The request to add/remove a rule was sent to the respective backend.
-
NetControl::SUCCEEDED
A rule was successfully added by a backend.
-
NetControl::EXISTS
A backend reported that a rule was already existing.
-
NetControl::FAILED
A rule addition failed.
-
NetControl::REMOVED
A rule was successfully removed by a backend.
-
NetControl::TIMEOUT
A rule timeout was triggered by the NetControl framework or a backend.
|
State of an entry in the NetControl log.
Events
-
NetControl::init
-
Event that is used to initialize plugins. Place all plugin initialization
related functionality in this event.
-
NetControl::init_done
-
Event that is raised once all plugins activated in NetControl::init
have finished their initialization.
-
NetControl::log_netcontrol
-
Event that can be handled to access the NetControl::Info
record as it is sent on to the logging framework.
-
NetControl::rule_added
-
Confirms that a rule was put in place by a plugin.
R: | The rule now in place. |
P: | The state for the plugin that put it into place. |
Msg: | An optional informational message by the plugin. |
-
NetControl::rule_destroyed
-
This event is raised when a rule is deleted from the NetControl framework,
because it is no longer in use. This can be caused by the fact that a rule
was removed by all plugins to which it was added, by the fact that it timed out
or due to rule errors.
To get the cause of a rule remove, catch the rule_removed, rule_timeout and
rule_error events.
-
NetControl::rule_error
-
Reports an error when operating on a rule.
R: | The rule that encountered an error. |
P: | The state for the plugin that reported the error. |
Msg: | An optional informational message by the plugin. |
-
NetControl::rule_exists
-
Signals that a rule that was supposed to be put in place was already
existing at the specified plugin. Rules that already have been existing
continue to be tracked like normal, but no timeout calls will be sent
to the specified plugins. Removal of the rule from the hardware can
still be forced by manually issuing a remove_rule call.
R: | The rule that was already in place. |
P: | The plugin that reported that the rule already was in place. |
Msg: | An optional informational message by the plugin. |
-
NetControl::rule_new
-
This event is raised when a new rule is created by the NetControl framework
due to a call to add_rule. From this moment, until the rule_destroyed event
is raised, the rule is tracked internally by the NetControl framework.
Note that this event does not mean that a rule was successfully added by
any backend; it just means that the rule has been accepted and addition
to the specified backend is queued. To get information when rules are actually
installed by the hardware, use the rule_added, rule_exists, rule_removed, rule_timeout
and rule_error events.
-
NetControl::rule_removed
-
Reports that a plugin reports a rule was removed due to a
remove_rule function call.
R: | The rule now removed. |
P: | The state for the plugin that had the rule in place and now
removed it. |
Msg: | An optional informational message by the plugin. |
-
NetControl::rule_timeout
-
Reports that a rule was removed from a plugin due to a timeout.
R: | The rule now removed. |
I: | Additional flow information, if supported by the protocol. |
P: | The state for the plugin that had the rule in place and now
removed it. |
Msg: | An optional informational message by the plugin. |
Hooks
-
NetControl::rule_policy
-
Hook that allows the modification of rules passed to add_rule before they
are passed on to the plugins. If one of the hooks uses break, the rule is
ignored and not passed on to any plugin.
Functions
-
NetControl::activate
-
Activates a plugin.
P: | The plugin to activate. |
Priority: | The higher the priority, the earlier this plugin will be checked
whether it supports an operation, relative to other plugins. |
-
NetControl::add_rule
-
Installs a rule.
R: | The rule to install. |
Returns: | If successful, returns an ID string unique to the rule that can
later be used to refer to it. If unsuccessful, returns an empty
string. The ID is also assigned to r$id . Note that
“successful” means “a plugin knew how to handle the rule”, it
doesn’t necessarily mean that it was indeed successfully put in
place, because that might happen asynchronously and thus fail
only later. |
-
NetControl::clear
-
Flushes all state by calling NetControl::remove_rule
on all currently active rules.
-
NetControl::delete_rule
-
Deletes a rule without removing it from the backends to which it has been
added before. This means that no messages will be sent to the switches to which
the rule has been added; if it is not removed from them by a separate mechanism,
it will stay installed and not be removed later.
Id: | The rule to delete, specified as the ID returned by NetControl::add_rule . |
Reason: | Optional string argument giving information on why the rule was deleted. |
Returns: | True if removal is successful, or sent to manager.
False if the rule could not be found. |
-
NetControl::find_rules_addr
-
Searches all rules affecting a certain IP address.
This function works on both the manager and workers of a cluster. Note that on
the worker, the internal rule variables (starting with _) will not reflect the
current state.
Ip: | The ip address to search for. |
Returns: | vector of all rules affecting the IP address. |
-
NetControl::find_rules_subnet
-
Searches all rules affecting a certain subnet.
A rule affects a subnet, if it covers the whole subnet. Note especially that
this function will not reveal all rules that are covered by a subnet.
For example, a search for 192.168.17.0/8 will reveal a rule that exists for
192.168.0.0/16, since this rule affects the subnet. However, it will not reveal
a more specific rule for 192.168.17.1/32, which does not directy affect the whole
subnet.
This function works on both the manager and workers of a cluster. Note that on
the worker, the internal rule variables (starting with _) will not reflect the
current state.
Sn: | The subnet to search for. |
Returns: | vector of all rules affecting the subnet. |
-
NetControl::plugin_activated
-
Function called by plugins once they finished their activation. After all
plugins defined in bro_init finished to activate, rules will start to be sent
to the plugins. Rules that scripts try to set before the backends are ready
will be discarded.
-
NetControl::quarantine_host
-
Quarantines a host. This requires a special quarantine server, which runs a HTTP server explaining
the quarantine and a DNS server which resolves all requests to the quarantine server. DNS queries
from the host to the network DNS server will be rewritten and will be sent to the quarantine server
instead. Only http communication infected to quarantinehost is allowed. All other network communication
is blocked.
Infected: | the host to quarantine. |
Dns: | the network dns server. |
Quarantine: | the quarantine server running a dns and a web server. |
T: | how long to leave the quarantine in place. |
Returns: | Vector of inserted rules on success, empty list on failure. |
-
NetControl::redirect_flow
-
Redirects a uni-directional flow to another port.
F: | The flow to redirect. |
Out_port: | Port to redirect the flow to. |
T: | How long to leave the redirect in place, with 0 being indefinitely. |
Location: | An optional string describing where the redirect was triggered. |
Returns: | The id of the inserted rule on success and zero on failure. |
-
NetControl::remove_rule
-
Removes a rule.
Id: | The rule to remove, specified as the ID returned by NetControl::add_rule . |
Reason: | Optional string argument giving information on why the rule was removed. |
Returns: | True if successful, the relevant plugin indicated that it knew
how to handle the removal. Note that again “success” means the
plugin accepted the removal. It might still fail to put it
into effect, as that might happen asynchronously and thus go
wrong at that point. |
-
NetControl::whitelist_address
-
Allows all traffic involving a specific IP address to be forwarded.
A: | The address to be whitelisted. |
T: | How long to whitelist it, with 0 being indefinitely. |
Location: | An optional string describing whitelist was triddered. |
Returns: | The id of the inserted rule on success and zero on failure. |
-
NetControl::whitelist_subnet
-
Allows all traffic involving a specific IP subnet to be forwarded.
S: | The subnet to be whitelisted. |
T: | How long to whitelist it, with 0 being indefinitely. |
Location: | An optional string describing whitelist was triddered. |
Returns: | The id of the inserted rule on success and zero on failure. |