diff --git a/pbrd/pbr_nht.c b/pbrd/pbr_nht.c index 97a4fcbab621..0dd5a88401a4 100644 --- a/pbrd/pbr_nht.c +++ b/pbrd/pbr_nht.c @@ -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) @@ -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, @@ -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)); } diff --git a/pbrd/pbr_nht.h b/pbrd/pbr_nht.h index 3ca7a04378ee..42d9491529d6 100644 --- a/pbrd/pbr_nht.h +++ b/pbrd/pbr_nht.h @@ -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); diff --git a/pbrd/pbr_vty.c b/pbrd/pbr_vty.c index 366acce1031b..75df410e4270 100644 --- a/pbrd/pbr_vty.c +++ b/pbrd/pbr_vty.c @@ -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; } @@ -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;