Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pbrd: add meat of rule range cli #5

Merged
merged 1 commit into from
Feb 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion pbrd/pbr_nht.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ static struct hash *pbr_nhg_hash;

static uint32_t pbr_nhg_low_table;
static uint32_t pbr_nhg_high_table;
static uint32_t pbr_nhg_low_rule;
static uint32_t pbr_nhg_high_rule;
static bool nhg_tableid[65535];
static bool nhg_rule[65535];
static void *pbr_nh_alloc(void *p);

void pbr_nhgroup_add_cb(const char *name)
Expand Down Expand Up @@ -285,11 +288,45 @@ void pbr_nht_write_table_range(struct vty *vty)
{
if (pbr_nhg_low_table != PBR_NHT_DEFAULT_LOW_TABLEID
|| pbr_nhg_high_table != PBR_NHT_DEFAULT_HIGH_TABLEID) {
vty_out(vty, "pbr table range %u %u", pbr_nhg_low_table,
vty_out(vty, "pbr table range %u %u\n", pbr_nhg_low_table,
pbr_nhg_high_table);
}
}

uint32_t pbr_nht_get_next_rule(void)
{
uint32_t i;
bool found = false;

for (i = pbr_nhg_low_rule; i <= pbr_nhg_high_rule; i++) {
if (nhg_rule[i] == false) {
found = true;
break;
}
}

if (found) {
nhg_rule[i] = true;
return i;
} else
return 0;
}
void pbr_nht_set_rule_range(uint32_t low, uint32_t high)
{
pbr_nhg_low_rule = low;
pbr_nhg_high_rule = high;
}

void pbr_nht_write_rule_range(struct vty *vty)
{
if (pbr_nhg_low_rule != PBR_NHT_DEFAULT_LOW_RULE
|| pbr_nhg_high_rule != PBR_NHT_DEFAULT_HIGH_RULE) {
vty_out(vty, "pbr rule range %u %u\n", pbr_nhg_low_rule,
pbr_nhg_high_rule);
}
}


void pbr_nht_init(void)
{
pbr_nh_hash = hash_create_size(16, pbr_nh_hash_key, pbr_nh_hash_equal,
Expand All @@ -300,5 +337,7 @@ void pbr_nht_init(void)

pbr_nhg_low_table = PBR_NHT_DEFAULT_LOW_TABLEID;
pbr_nhg_high_table = PBR_NHT_DEFAULT_HIGH_TABLEID;
pbr_nhg_low_rule = PBR_NHT_DEFAULT_LOW_RULE;
pbr_nhg_high_rule = PBR_NHT_DEFAULT_HIGH_RULE;
memset(&nhg_tableid, 0, 65535 * sizeof(uint8_t));
}
6 changes: 6 additions & 0 deletions pbrd/pbr_nht.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ extern uint32_t pbr_nht_get_next_tableid(void);
/*
* Get the next rule number to use for installation
*/
extern void pbr_nht_write_rule_range(struct vty *vty);

#define PBR_NHT_DEFAULT_LOW_RULE 5000
#define PBR_NHT_DEFAULT_HIGH_RULE 6000
extern void pbr_nht_set_rule_range(uint32_t low, uint32_t high);

extern uint32_t pbr_nht_get_next_rule(void);

extern void pbr_nhgroup_add_cb(const char *name);
Expand Down
23 changes: 15 additions & 8 deletions pbrd/pbr_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,21 @@ DEFPY (pbr_table_range,
}

DEFPY (pbr_rule_range,
pbr_rule_range_cmd,
"[no] pbr rule range (10-15)$start (16-20)$end",
NO_STR
"Policy based routing\n"
"Policy based routing rule\n"
"Rule range\n"
"Initial value of range\n"
"Final value of range\n")
pbr_rule_range_cmd,
"[no] pbr rule range (5000-65535)$start (6000-65535)$end",
NO_STR
"Policy based routing\n"
"Policy based routing rule\n"
"Rule range\n"
"Initial value of range\n"
"Final value of range\n")
{
if (no)
pbr_nht_set_rule_range(PBR_NHT_DEFAULT_LOW_RULE,
PBR_NHT_DEFAULT_HIGH_RULE);
else
pbr_nht_set_rule_range(start, end);

return CMD_SUCCESS;
}

Expand Down Expand Up @@ -248,6 +254,7 @@ static int pbr_vty_map_config_write(struct vty *vty)
struct pbr_map *pbrm;

pbr_nht_write_table_range(vty);
pbr_nht_write_rule_range(vty);

RB_FOREACH(pbrm, pbr_map_entry_head, &pbr_maps) {
struct pbr_map_sequence *pbrms;
Expand Down