#include "monitube2-data_main.h"
#include "monitube2-data_config.h"
Go to the source code of this file.
Data Structures | |
struct | list_item_s |
struct | address_s |
struct | rule_s |
struct | prefix_s |
Defines | |
#define | MONITUBE2_MGMT_STRLEN 256 |
Application name length. | |
#define | RLOCK(l) INSIST_ERR(msp_rwlock_rlock(l) == MSP_OK) |
Read lock. | |
#define | WLOCK(l) INSIST_ERR(msp_rwlock_wlock(l) == MSP_OK) |
Write lock. | |
#define | RUNLOCK(l) INSIST_ERR(msp_rwlock_runlock(l) == MSP_OK) |
Read lock. | |
#define | WUNLOCK(l) INSIST_ERR(msp_rwlock_wunlock(l) == MSP_OK) |
Write lock. | |
Typedefs | |
typedef list_item_s | list_item_t |
typedef address_s | address_t |
typedef rule_s | rule_t |
typedef prefix_s | prefix_t |
Functions | |
typedef | TAILQ_HEAD (list_s, list_item_s) |
static void | update_time (evContext ectx UNUSED, void *uap UNUSED, struct timespec due UNUSED, struct timespec inter UNUSED) |
static uint8_t | bit_count (uint32_t n) |
static void | free_policy (evContext ectx UNUSED, void *uap, struct timespec due UNUSED, struct timespec inter UNUSED) |
void | init_config (void) |
time_t | get_current_time (void) |
void | clear_config (void) |
void | update_rule (char *name, uint32_t rate, in_addr_t redirect) |
int | delete_rule (char *name) |
void | add_address (char *name, in_addr_t addr, in_addr_t mask) |
void | delete_address (char *name, in_addr_t addr, in_addr_t mask) |
void | apply_rule (char *name, uint16_t ssid, uint32_t gennum, uint32_t svcid) |
void | remove_rule (char *name, uint16_t ssid, uint32_t gennum, uint32_t svcid) |
void | delete_serviceset (uint16_t ssid, uint32_t gennum, uint32_t svcid) |
int | get_monitored_rule_info (uint16_t ssid, uint32_t svcid, in_addr_t address, uint32_t *rate, uint32_t *redirect_addr) |
Variables | |
int | plugin_id |
evContext * | ctx |
msp_policy_db_handle_t | pdb_handle |
void * | pdb_shm_handle |
ss_info_t | |
static atomic_uint_t | current_time |
static patroot | rules |
These functions will store and provide access to the configuration data which is essentially coming from the mgmt component.
Definition in file monitube2-data_config.c.
The structure we use to bundle the patricia-tree node with the data to store for each destination address/prefix
typedef struct list_item_s list_item_t |
A list item
The structure we use to bundle the radix-tree node with a pointer to the rule we need. Used in the data & ctrl paths with a lock in ss_info_t
The structure we use to bundle the patricia-tree node with the data to store for each rule
Only redirect and rate could be used in the fast path. To change these or delete the rule one should have a write lock. The rest is only touched in the ctrl path (and from one thread). In ctrl side we don't always grab the lock when reading, b/c we don't care about reading while data side is reading. We just want to block ctrl side writing while data side is reading.
void add_address | ( | char * | name, | |
in_addr_t | addr, | |||
in_addr_t | mask | |||
) |
Add an address to the rule
[in] | name | rule name |
[in] | addr | Address |
[in] | mask | Mask to apply to addr |
Definition at line 519 of file monitube2-data_config.c.
References address_s::address, rule_s::addresses, bit_count(), CLOG, list_item_s::data, INSIST_ERR, address_s::mask, address_s::node, pdb_shm_handle, prefix_s::prefix, prefix_s::rnode, prefix_s::rule, rules, ss_info_t, rule_s::ssets, WLOCK, and WUNLOCK.
Referenced by mgmt_client_message().
void apply_rule | ( | char * | name, | |
uint16_t | ssid, | |||
uint32_t | gennum, | |||
uint32_t | svcid | |||
) |
Apply rule on a service set
[in] | name | rule name |
[in] | ssid | service set id |
[in] | gennum | Service set generation number needed for PDB |
[in] | svcid | Service ID needed for PDB |
Definition at line 667 of file monitube2-data_config.c.
References CLOG, list_item_s::data, INSIST_ERR, pdb_handle, pdb_shm_handle, plugin_id, PLUGIN_NAME, rules, ss_info_t, and rule_s::ssets.
Referenced by mgmt_client_message().
static uint8_t bit_count | ( | uint32_t | n | ) | [static] |
Count the number of bits in a uint32_t / in_addr_t
[in] | n | The input (mask) that we want the number of bits for |
Definition at line 195 of file monitube2-data_config.c.
Referenced by add_address(), delete_address(), and delete_rule().
void clear_config | ( | void | ) |
Clear the stored configuration data
Definition at line 288 of file monitube2-data_config.c.
References CLOG, ctx, delete_rule(), free_policy(), rule_s::name, pdb_handle, plugin_id, PLUGIN_NAME, rules, and ss_info_t.
Referenced by mgmt_client_connection(), and mgmt_client_message().
void delete_address | ( | char * | name, | |
in_addr_t | addr, | |||
in_addr_t | mask | |||
) |
Delete an address from the rule
[in] | name | rule name |
[in] | addr | Address |
[in] | mask | Mask to apply to addr |
Definition at line 591 of file monitube2-data_config.c.
References rule_s::addresses, bit_count(), CLOG, list_item_s::data, address_s::node, prefix_s::rule, rules, ss_info_t, rule_s::ssets, WLOCK, and WUNLOCK.
Referenced by mgmt_client_message().
int delete_rule | ( | char * | name | ) |
Delete rule
[in] | name | rule name |
Definition at line 423 of file monitube2-data_config.c.
References address_s::address, rule_s::addresses, bit_count(), CLOG, list_item_s::data, rule_s::lock, address_s::mask, rule_s::node, address_s::node, pdb_shm_handle, prefix_s::rule, rules, ss_info_t, rule_s::ssets, WLOCK, and WUNLOCK.
Referenced by clear_config(), and mgmt_client_message().
void delete_serviceset | ( | uint16_t | ssid, | |
uint32_t | gennum, | |||
uint32_t | svcid | |||
) |
Delete service set
[in] | ssid | service set id |
Definition at line 891 of file monitube2-data_config.c.
References CLOG, ctx, list_item_s::data, free_policy(), pdb_handle, pdb_shm_handle, plugin_id, PLUGIN_NAME, ss_info_t, and rule_s::ssets.
Referenced by mgmt_client_message().
static void free_policy | ( | evContext ectx | UNUSED, | |
void * | uap, | |||
struct timespec due | UNUSED, | |||
struct timespec inter | UNUSED | |||
) | [static] |
Callback to free policy after some delay
[in] | ctx | The event context for this application |
[in] | uap | The user data for this callback |
[in] | due | The absolute time when the event is due (now) |
[in] | inter | The period; when this will next be called |
Definition at line 221 of file monitube2-data_config.c.
References pdb_shm_handle, and ss_info_t.
Referenced by clear_config(), delete_serviceset(), and remove_rule().
time_t get_current_time | ( | void | ) |
Get the currently cached time
Definition at line 278 of file monitube2-data_config.c.
References current_time.
Referenced by process_packet().
int get_monitored_rule_info | ( | uint16_t | ssid, | |
uint32_t | svcid, | |||
in_addr_t | address, | |||
uint32_t * | rate, | |||
uint32_t * | redirect_addr | |||
) |
Find the monitoring rate and redirect address a rule-match happen one exists. This will be run in the fast path.
[in] | ssid | The service set id |
[in] | svcid | The service id |
[in] | address | The destination address |
[out] | rate | If null on input, this is ignored. The monitoring rate; 0 if no rate |
[out] | redirect_addr | If null on input, this is ignored. The mirror addr; 0 if no mirroring |
Definition at line 994 of file monitube2-data_config.c.
References DLOG, rule_s::lock, pdb_handle, plugin_id, PLUGIN_NAME, rule_s::rate, rule_s::redirect, RLOCK, prefix_s::rule, RUNLOCK, and ss_info_t.
Referenced by monitube_data_hdlr().
void init_config | ( | void | ) |
Init the data structures that will store configuration info
Should only be called on startup (one time)
Definition at line 257 of file monitube2-data_config.c.
References CLOG, ctx, current_time, MONITUBE2_MGMT_STRLEN, rules, and update_time().
Referenced by retry_attach_fdb().
void remove_rule | ( | char * | name, | |
uint16_t | ssid, | |||
uint32_t | gennum, | |||
uint32_t | svcid | |||
) |
Remove a rule from a service set
[in] | name | rule name |
[in] | ssid | service set id |
[in] | gennum | Service set generation number needed for PDB |
[in] | svcid | Service ID needed for PDB |
Definition at line 787 of file monitube2-data_config.c.
References CLOG, ctx, list_item_s::data, free_policy(), pdb_handle, pdb_shm_handle, plugin_id, PLUGIN_NAME, rules, ss_info_t, and rule_s::ssets.
Referenced by mgmt_client_message().
typedef TAILQ_HEAD | ( | list_s | , | |
list_item_s | ||||
) |
The structure we use to bundle service-set info
We don't need the prefixes_lock during the delayed delete
< service set id number
< service id
< generation number
< Radix tree for monitor lookups in data path
< Lock while using prefixes or its contents
< list of rules (only used in ctrl path)
Definition at line 70 of file monitube2-data_config.c.
References rules.
void update_rule | ( | char * | name, | |
uint32_t | rate, | |||
in_addr_t | redirect | |||
) |
Update/create a rule
[in] | name | rule name |
[in] | rate | monitoring rate |
[in] | redirect | address for mirroring |
Definition at line 377 of file monitube2-data_config.c.
References rule_s::addresses, CLOG, INSIST_ERR, rule_s::lock, rule_s::name, rule_s::node, pdb_shm_handle, rule_s::rate, rule_s::redirect, rules, rule_s::ssets, WLOCK, and WUNLOCK.
Referenced by mgmt_client_message().
static void update_time | ( | evContext ectx | UNUSED, | |
void *uap | UNUSED, | |||
struct timespec due | UNUSED, | |||
struct timespec inter | UNUSED | |||
) | [static] |
Update cached time
[in] | ctx | The event context for this application |
[in] | uap | The user data for this callback |
[in] | due | The absolute time when the event is due (now) |
[in] | inter | The period; when this will next be called |
Definition at line 177 of file monitube2-data_config.c.
References current_time.
Referenced by init_config().
evContext* ctx |
The main evContext on the ctrl plane side
Definition at line 578 of file monitube2-data_main.c.
Referenced by clear_config(), connect_mgmt(), delete_serviceset(), init_config(), init_connections(), mgmt_client_connection(), monitube_ctrl_hdlr(), process_notifications(), remove_rule(), and retry_attach_fdb().
atomic_uint_t current_time [static] |
The current cached time. Cache it to prevent many system time() calls by the data threads.
Definition at line 136 of file monitube2-data_config.c.
Referenced by get_current_time(), init_config(), and update_time().
msp_policy_db_handle_t pdb_handle |
The policy database handle
Definition at line 583 of file monitube2-data_main.c.
Referenced by apply_rule(), clear_config(), delete_serviceset(), get_monitored_rule_info(), monitube_ctrl_hdlr(), and remove_rule().
void* pdb_shm_handle |
The shared mem handle for the PDB
Definition at line 588 of file monitube2-data_main.c.
Referenced by add_address(), apply_rule(), delete_rule(), delete_serviceset(), free_policy(), monitube_ctrl_hdlr(), remove_rule(), and update_rule().
int plugin_id |
The id assigned by mspmand unique over all plugins
Definition at line 573 of file monitube2-data_main.c.
Referenced by apply_rule(), clear_config(), delete_serviceset(), get_monitored_rule_info(), monitube2_entry(), monitube_ctrl_hdlr(), monitube_data_hdlr(), and remove_rule().
patroot rules [static] |
The PATRICIA tree root for rules configuration. Only used in the ctrl path
Definition at line 142 of file monitube2-data_config.c.
Referenced by add_address(), apply_rule(), clear_config(), delete_address(), delete_rule(), init_config(), remove_rule(), TAILQ_HEAD(), and update_rule().