PF_RING API
API documentation for PF_RING: high-speed packet capture, filtering and analysis framework.
nbroker_api.h File Reference

nBroker C API header file. More...

#include <net/if.h>
#include "rrc.h"

Go to the source code of this file.

Classes

struct  __attribute__
 
struct  nbroker_rule_t
 
struct  cmd_desc_t
 
struct  cmd_queue_t
 
struct  nbroker
 

Macros

#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)
 

Typedefs

typedef struct nbroker nbroker_t
 

Enumerations

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 }
 

Functions

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)
 

Detailed Description

nBroker C API header file.

Macro Definition Documentation

◆ 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)

Function Documentation

◆ nbroker_apply_pending_rules()

nbroker_rc_t nbroker_apply_pending_rules ( nbroker_t bkr)

Apply pending rules (if any)

Parameters
bkrThe broker handler
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
bkrThe broker handler
ifnameThe interface name
portThe 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
bkrThe broker handler
ifnameThe interface name
portThe 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
bkrThe broker handler (out)
flagsOption 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
bkrThe broker handler
portThe target port number or interface name
filtertype The filter type to filter rules by type
num_rulesThe number of rules (out)
rulesThe 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
ruleThe BPF filter
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
bkrThe broker handler
idle_forThe 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
bkrThe broker handler
portThe target port number or interface name
rule_idThe rule id
filter_typeThe 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
bkrThe broker handler
portThe target port number or interface name
matchThe rule to match
filter_typeThe 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
bkrThe broker handler
portThe target port number or interface name
filter_typeThe 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
bkrThe broker handler
idle_forThe 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
bkrThe broker handler
portThe target port number or interface name
policyThe 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
bkrThe broker handler
portThe target port number or interface name
steer_toThe 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
bkrThe broker handler
portThe target port number or interface name
rule_idThe rule id. Use NBROKER_AUTO_RULE_ID as rule_id to use the internal rule id management (in/out)
matchThe rule to match
policyThe 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
bkrThe broker handler
portThe target port number or interface name
rule_idThe 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).
matchThe rule to match
steer_toThe destination port number or interface name
Returns
The error code

◆ nbroker_term()

nbroker_rc_t nbroker_term ( nbroker_t bkr)

Terminates the broker communication. The broker object is freed.

Parameters
bkrThe broker handler
Returns
The error code