nBroker C API header file.
More...
#include <net/if.h>
#include "rrc.h"
Go to the source code of this file.
|
#define | NBROKER_AUTO_RULE_ID 0 |
|
#define | NBROKER_FLAGS_FAST (1 << 0) |
|
#define | CMD_QUEUE_ITEMS 1024 /* pow of 2 */ |
|
#define | CMD_QUEUE_ITEMS_MASK (CMD_QUEUE_ITEMS - 1) |
|
|
enum | nbroker_rc_t {
NBROKER_RC_OK = 0,
NBROKER_RC_INTERNAL_ERROR,
NBROKER_RC_SYNTAX_ERROR,
NBROKER_RC_UNSUPPORTED_MODE,
NBROKER_RC_INVALID_DEVICE_PORT,
NBROKER_RC_INVALID_REDIRECTION_PORT,
NBROKER_RC_RULE_NOT_FOUND,
NBROKER_RC_RULE_EXISTS,
NBROKER_RC_DEVICE_COMMAND_ERROR,
NBROKER_RC_BAD_BINARY_VERSION,
NBROKER_RC_CONNECTION_ERROR,
NBROKER_RC_BUSY
} |
|
enum | nbroker_policy_t { NBROKER_POLICY_DROP,
NBROKER_POLICY_PASS
} |
|
enum | nbroker_filter_type_t { NBROKER_TYPE_FILTERING,
NBROKER_TYPE_STEERING
} |
|
enum | cmd_type_t { CMD_SET_RULE = 0
} |
|
|
nbroker_rc_t | nbroker_init (nbroker_t **bkr, u_int32_t flags) |
|
nbroker_rc_t | nbroker_term (nbroker_t *bkr) |
|
nbroker_rc_t | nbroker_set_default_policy (nbroker_t *bkr, const char *port, nbroker_policy_t policy) |
|
nbroker_rc_t | nbroker_apply_pending_rules (nbroker_t *bkr) |
|
nbroker_rc_t | nbroker_set_default_steering (nbroker_t *bkr, const char *port, const char *steer_to) |
|
nbroker_rc_t | nbroker_set_filtering_rule (nbroker_t *bkr, const char *port, u_int32_t *rule_id, const rrc_match_t *match, nbroker_policy_t policy) |
|
nbroker_rc_t | nbroker_set_steering_rule (nbroker_t *bkr, const char *port, u_int32_t *rule_id, const rrc_match_t *match, const char *steer_to) |
|
nbroker_rc_t | nbroker_remove_rule_by_id (nbroker_t *bkr, const char *port, u_int32_t rule_id, nbroker_filter_type_t filter_type) |
|
nbroker_rc_t | nbroker_remove_rule_by_match (nbroker_t *bkr, const char *port, const rrc_match_t *match, nbroker_filter_type_t filter_type) |
|
nbroker_rc_t | nbroker_list_rules (nbroker_t *bkr, const char *port, nbroker_filter_type_t filter_type, u_int32_t *num_rules, nbroker_rule_t **rules) |
|
nbroker_rc_t | nbroker_reset_rules (nbroker_t *bkr, const char *port, nbroker_filter_type_t filter_type) |
|
nbroker_rc_t | nbroker_purge_idle_rules (nbroker_t *bkr, u_int32_t idle_for) |
|
nbroker_rc_t | nbroker_set_auto_purge (nbroker_t *bkr, u_int32_t idle_for) |
|
nbroker_rc_t | nbroker_ifname_to_internal_port (nbroker_t *bkr, const char *ifname, u_int8_t *port) |
|
nbroker_rc_t | nbroker_ifname_to_external_port (nbroker_t *bkr, const char *ifname, u_int8_t *port) |
|
rrc_match_t * | nbroker_parse_rule (const char *rule) |
|
nBroker C API header file.
◆ NBROKER_FLAGS_FAST
#define NBROKER_FLAGS_FAST (1 << 0) |
nbroker_init() flag: use best-effort rules insert for best insert performance (it does not return errors or the rule id)
◆ nbroker_apply_pending_rules()
nbroker_rc_t nbroker_apply_pending_rules |
( |
nbroker_t * |
bkr | ) |
|
Apply pending rules (if any)
- Parameters
-
- Returns
- The error code
◆ nbroker_ifname_to_external_port()
nbroker_rc_t nbroker_ifname_to_external_port |
( |
nbroker_t * |
bkr, |
|
|
const char * |
ifname, |
|
|
u_int8_t * |
port |
|
) |
| |
Converts a linux interface name to the external port index of the device.
- Parameters
-
bkr | The broker handler |
ifname | The interface name |
port | The external port number of the RRC switch bound to the specified interface (out) |
- Returns
- The error code
◆ nbroker_ifname_to_internal_port()
nbroker_rc_t nbroker_ifname_to_internal_port |
( |
nbroker_t * |
bkr, |
|
|
const char * |
ifname, |
|
|
u_int8_t * |
port |
|
) |
| |
Converts a linux interface name to the internal (pci) port index of the device.
- Parameters
-
bkr | The broker handler |
ifname | The interface name |
port | The internal port number of the RRC switch bound to the specified interface (out) |
- Returns
- The error code
◆ nbroker_init()
nbroker_rc_t nbroker_init |
( |
nbroker_t ** |
bkr, |
|
|
u_int32_t |
flags |
|
) |
| |
Init the broker communication.
- Parameters
-
bkr | The broker handler (out) |
flags | Option flags |
- Returns
- The error code
◆ nbroker_list_rules()
nbroker_rc_t nbroker_list_rules |
( |
nbroker_t * |
bkr, |
|
|
const char * |
port, |
|
|
nbroker_filter_type_t |
filter_type, |
|
|
u_int32_t * |
num_rules, |
|
|
nbroker_rule_t ** |
rules |
|
) |
| |
List the active rules of the specified type and port
- Parameters
-
bkr | The broker handler |
port | The target port number or interface name |
filter | type The filter type to filter rules by type |
num_rules | The number of rules (out) |
rules | The rules list (out) |
- Returns
- The error code
◆ nbroker_parse_rule()
rrc_match_t* nbroker_parse_rule |
( |
const char * |
rule | ) |
|
Parses a rule in the broker BPF syntax and produce a rrc_match_t structure. NOTE: a mutex is aquired while performing grammar parsing.
- Parameters
-
- Returns
- NULL on error, the rrc_match_t rule otherwise (it must be freed by the caller)
◆ nbroker_purge_idle_rules()
nbroker_rc_t nbroker_purge_idle_rules |
( |
nbroker_t * |
bkr, |
|
|
u_int32_t |
idle_for |
|
) |
| |
Purge the rules which have been set more than idle_for seconds ago.
- Parameters
-
bkr | The broker handler |
idle_for | The idle time (sec). Pass 0 for automatic purge. |
- Returns
- The error code
◆ nbroker_remove_rule_by_id()
nbroker_rc_t nbroker_remove_rule_by_id |
( |
nbroker_t * |
bkr, |
|
|
const char * |
port, |
|
|
u_int32_t |
rule_id, |
|
|
nbroker_filter_type_t |
filter_type |
|
) |
| |
Remove a rule by its rule id.
- Parameters
-
bkr | The broker handler |
port | The target port number or interface name |
rule_id | The rule id |
filter_type | The filter type |
- Returns
- The error code
◆ nbroker_remove_rule_by_match()
nbroker_rc_t nbroker_remove_rule_by_match |
( |
nbroker_t * |
bkr, |
|
|
const char * |
port, |
|
|
const rrc_match_t * |
match, |
|
|
nbroker_filter_type_t |
filter_type |
|
) |
| |
Remove the first rule matching the specifed match.
- Parameters
-
bkr | The broker handler |
port | The target port number or interface name |
match | The rule to match |
filter_type | The filter type |
- Returns
- The error code
◆ nbroker_reset_rules()
nbroker_rc_t nbroker_reset_rules |
( |
nbroker_t * |
bkr, |
|
|
const char * |
port, |
|
|
nbroker_filter_type_t |
filter_type |
|
) |
| |
Reset all the rules of the specified type on the specified port. Note: the default rules are not affected
- Parameters
-
bkr | The broker handler |
port | The target port number or interface name |
filter_type | The filter type |
- Returns
- The error code
◆ nbroker_set_auto_purge()
nbroker_rc_t nbroker_set_auto_purge |
( |
nbroker_t * |
bkr, |
|
|
u_int32_t |
idle_for |
|
) |
| |
Enable old rules auto-purge. Periodically, rules older than idle_for will be purged.
- Parameters
-
bkr | The broker handler |
idle_for | The idle time (sec). Pass 0 to disable automatic purge. |
- Returns
- The error code
◆ nbroker_set_default_policy()
nbroker_rc_t nbroker_set_default_policy |
( |
nbroker_t * |
bkr, |
|
|
const char * |
port, |
|
|
nbroker_policy_t |
policy |
|
) |
| |
Set the default policy. The port parameter can be either the symbolic linux name or the numeric port id.
- Parameters
-
bkr | The broker handler |
port | The target port number or interface name |
policy | The default policy |
- Returns
- The error code
◆ nbroker_set_default_steering()
nbroker_rc_t nbroker_set_default_steering |
( |
nbroker_t * |
bkr, |
|
|
const char * |
port, |
|
|
const char * |
steer_to |
|
) |
| |
Set the default port redirection. The port parameter can be either the symbolic linux name or the numeric port id.
- Parameters
-
bkr | The broker handler |
port | The target port number or interface name |
steer_to | The default destination port number or interface name |
- Returns
- The error code
◆ nbroker_set_filtering_rule()
nbroker_rc_t nbroker_set_filtering_rule |
( |
nbroker_t * |
bkr, |
|
|
const char * |
port, |
|
|
u_int32_t * |
rule_id, |
|
|
const rrc_match_t * |
match, |
|
|
nbroker_policy_t |
policy |
|
) |
| |
Set a filtering rule for the specified match. On success, the rule_id will contain the newly set rule id.
- Parameters
-
bkr | The broker handler |
port | The target port number or interface name |
rule_id | The rule id. Use NBROKER_AUTO_RULE_ID as rule_id to use the internal rule id management (in/out) |
match | The rule to match |
policy | The policy |
- Returns
- The error code
◆ nbroker_set_steering_rule()
nbroker_rc_t nbroker_set_steering_rule |
( |
nbroker_t * |
bkr, |
|
|
const char * |
port, |
|
|
u_int32_t * |
rule_id, |
|
|
const rrc_match_t * |
match, |
|
|
const char * |
steer_to |
|
) |
| |
Set a port redirection rule for the specified match.
- Parameters
-
bkr | The broker handler |
port | The target port number or interface name |
rule_id | The rule id. Use NBROKER_AUTO_RULE_ID as rule_id to use the internal rule id management. On success, the rule_id will contain the newly set rule id (in/out). |
match | The rule to match |
steer_to | The destination port number or interface name |
- Returns
- The error code
◆ nbroker_term()
Terminates the broker communication. The broker object is freed.
- Parameters
-
- Returns
- The error code