-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Bgp ecommlist count #18159
Draft
pguibert6WIND
wants to merge
4
commits into
FRRouting:master
Choose a base branch
from
pguibert6WIND:bgp_ecommlist_count
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Bgp ecommlist count #18159
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6e26683
bgpd: add 'match extcommunity-count' command to restrict comm count
pguibert6WIND ae2b409
yang: enlarge community-limit count from [1-1024] to [0-1024]
pguibert6WIND 8247c77
bgpd: add match ecommunity <exact|any> options
pguibert6WIND 810deaf
topotests: add bgp ecommunity-list match test
pguibert6WIND File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1146,7 +1146,7 @@ bool ecommunity_has_route_target(struct ecommunity *ecom) | |
* Filter is added to display only ECOMMUNITY_ROUTE_TARGET in some cases. | ||
* 0 value displays all. | ||
*/ | ||
char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter) | ||
static char *_ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter, int number) | ||
{ | ||
uint32_t i; | ||
uint8_t *pnt; | ||
|
@@ -1168,8 +1168,10 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter) | |
bool unk_ecom = false; | ||
memset(encbuf, 0x00, sizeof(encbuf)); | ||
|
||
if (number != -1 && (uint32_t)number != i) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does it mean (number)? |
||
continue; | ||
/* Space between each value. */ | ||
if (i > 0) | ||
if (number == -1 && i > 0) | ||
strlcat(str_buf, " ", str_size); | ||
|
||
/* Retrieve value field */ | ||
|
@@ -1496,6 +1498,29 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter) | |
return str_buf; | ||
} | ||
|
||
char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter) | ||
{ | ||
return _ecommunity_ecom2str(ecom, format, filter, -1); | ||
} | ||
|
||
char *ecommunity_ecom2str_one(struct ecommunity *ecom, int format, int number) | ||
{ | ||
return _ecommunity_ecom2str(ecom, format, 0, number); | ||
} | ||
|
||
bool ecommunity_include_one(struct ecommunity *ecom, uint8_t *ptr) | ||
{ | ||
uint32_t i; | ||
uint8_t *ecom_ptr; | ||
|
||
for (i = 0; i < ecom->size; i++) { | ||
ecom_ptr = ecom->val + (i * ECOMMUNITY_SIZE); | ||
if (memcmp(ptr, ecom_ptr, ECOMMUNITY_SIZE) == 0) | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
bool ecommunity_include(struct ecommunity *e1, struct ecommunity *e2) | ||
{ | ||
uint32_t i, j; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1358,6 +1358,61 @@ static const struct route_map_rule_cmd route_match_community_limit_cmd = { | |
route_match_community_limit_compile, route_match_community_limit_free | ||
}; | ||
|
||
/* `match extcommunity-limit' */ | ||
|
||
/* Match function should return : | ||
* - RMAP_MATCH if the bgp update extcommunity list count | ||
* is less or equal to the configured limit. | ||
* - RMAP_NOMATCH if the extcommunity list count is greater than the | ||
* configured limit. | ||
*/ | ||
static enum route_map_cmd_result_t | ||
route_match_extcommunity_limit(void *rule, const struct prefix *prefix, void *object) | ||
{ | ||
struct bgp_path_info *path = NULL; | ||
struct ecommunity *piextcomm = NULL; | ||
uint16_t count = 0; | ||
uint16_t *limit_rule = rule; | ||
|
||
path = (struct bgp_path_info *)object; | ||
|
||
piextcomm = bgp_attr_get_ecommunity(path->attr); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please include also IPv6-address specific extended communities... |
||
if (piextcomm) | ||
count = piextcomm->size; | ||
|
||
if (count <= *limit_rule) | ||
return RMAP_MATCH; | ||
|
||
return RMAP_NOMATCH; | ||
} | ||
|
||
/* Route map `extcommunity-limit' match statement. */ | ||
static void *route_match_extcommunity_limit_compile(const char *arg) | ||
{ | ||
uint16_t *limit = NULL; | ||
char *end = NULL; | ||
|
||
limit = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(uint16_t)); | ||
*limit = strtoul(arg, &end, 10); | ||
if (*end != '\0') { | ||
XFREE(MTYPE_ROUTE_MAP_COMPILED, limit); | ||
return NULL; | ||
} | ||
return limit; | ||
} | ||
|
||
/* Free route map's compiled `community-limit' value. */ | ||
static void route_match_extcommunity_limit_free(void *rule) | ||
{ | ||
XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); | ||
} | ||
|
||
/* Route map commands for community limit matching. */ | ||
static const struct route_map_rule_cmd route_match_extcommunity_limit_cmd = { | ||
"extcommunity-limit", route_match_extcommunity_limit, | ||
route_match_extcommunity_limit_compile, route_match_extcommunity_limit_free | ||
}; | ||
|
||
static enum route_map_cmd_result_t | ||
route_set_evpn_gateway_ip(void *rule, const struct prefix *prefix, void *object) | ||
{ | ||
|
@@ -1853,8 +1908,18 @@ route_match_ecommunity(void *rule, const struct prefix *prefix, void *object) | |
if (!list) | ||
return RMAP_NOMATCH; | ||
|
||
if (ecommunity_list_match(bgp_attr_get_ecommunity(path->attr), list)) | ||
return RMAP_MATCH; | ||
if (rcom->exact) { | ||
if (ecommunity_list_exact_match(bgp_attr_get_ecommunity(path->attr), list)) | ||
return RMAP_MATCH; | ||
} else if (rcom->any) { | ||
if (!bgp_attr_get_ecommunity(path->attr)) | ||
return RMAP_OKAY; | ||
if (ecommunity_list_any_match(bgp_attr_get_ecommunity(path->attr), list)) | ||
return RMAP_MATCH; | ||
} else { | ||
if (ecommunity_list_match(bgp_attr_get_ecommunity(path->attr), list)) | ||
return RMAP_MATCH; | ||
} | ||
|
||
return RMAP_NOMATCH; | ||
} | ||
|
@@ -1863,11 +1928,28 @@ route_match_ecommunity(void *rule, const struct prefix *prefix, void *object) | |
static void *route_match_ecommunity_compile(const char *arg) | ||
{ | ||
struct rmap_community *rcom; | ||
int len; | ||
char *p; | ||
|
||
rcom = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct rmap_community)); | ||
rcom->name = XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); | ||
rcom->name_hash = bgp_clist_hash_key(rcom->name); | ||
|
||
p = strchr(arg, ' '); | ||
if (p) { | ||
len = p - arg; | ||
rcom->name = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, len + 1); | ||
memcpy(rcom->name, arg, len); | ||
p++; | ||
if (*p == 'e') | ||
rcom->exact = true; | ||
else | ||
rcom->any = true; | ||
} else { | ||
rcom->name = XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); | ||
rcom->exact = false; | ||
rcom->any = false; | ||
} | ||
|
||
rcom->name_hash = bgp_clist_hash_key(rcom->name); | ||
return rcom; | ||
} | ||
|
||
|
@@ -5861,16 +5943,19 @@ DEFUN_YANG( | |
|
||
DEFPY_YANG (match_ecommunity, | ||
match_ecommunity_cmd, | ||
"match extcommunity <(1-99)|(100-500)|EXTCOMMUNITY_LIST_NAME>", | ||
"match extcommunity <(1-99)|(100-500)|EXTCOMMUNITY_LIST_NAME> [<exact-match$exact|any$any>]", | ||
MATCH_STR | ||
"Match BGP/VPN extended community list\n" | ||
"Extended community-list number (standard)\n" | ||
"Extended community-list number (expanded)\n" | ||
"Extended community-list name\n") | ||
"Extended community-list name\n" | ||
"Do exact matching of communities\n" | ||
"Do matching of any community\n") | ||
{ | ||
const char *xpath = | ||
"./match-condition[condition='frr-bgp-route-map:match-extcommunity']"; | ||
char xpath_value[XPATH_MAXLEN]; | ||
char xpath_match[XPATH_MAXLEN]; | ||
int idx_comm_list = 2; | ||
|
||
nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); | ||
|
@@ -5881,19 +5966,57 @@ DEFPY_YANG (match_ecommunity, | |
xpath); | ||
nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, argv[idx_comm_list]->arg); | ||
|
||
snprintf(xpath_match, sizeof(xpath_match), | ||
"%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match", | ||
xpath); | ||
if (exact) | ||
nb_cli_enqueue_change(vty, xpath_match, NB_OP_MODIFY, "true"); | ||
else | ||
nb_cli_enqueue_change(vty, xpath_match, NB_OP_MODIFY, "false"); | ||
|
||
snprintf(xpath_match, sizeof(xpath_match), | ||
"%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-any", xpath); | ||
if (any) | ||
nb_cli_enqueue_change(vty, xpath_match, NB_OP_MODIFY, "true"); | ||
else | ||
nb_cli_enqueue_change(vty, xpath_match, NB_OP_MODIFY, "false"); | ||
|
||
return nb_cli_apply_changes(vty, NULL); | ||
} | ||
|
||
|
||
DEFPY_YANG( | ||
match_extcommunity_limit, match_extcommunity_limit_cmd, | ||
"[no$no] match extcommunity-limit ![(0-65535)$limit]", | ||
NO_STR | ||
MATCH_STR | ||
"Match BGP extended community limit\n" | ||
"Extended community limit number\n") | ||
{ | ||
const char *xpath = | ||
"./match-condition[condition='frr-bgp-route-map:match-extcommunity-limit']"; | ||
char xpath_value[XPATH_MAXLEN]; | ||
|
||
nb_cli_enqueue_change(vty, xpath, no ? NB_OP_DESTROY : NB_OP_CREATE, NULL); | ||
snprintf(xpath_value, sizeof(xpath_value), | ||
"%s/rmap-match-condition/frr-bgp-route-map:extcommunity-limit", xpath); | ||
|
||
nb_cli_enqueue_change(vty, xpath_value, no ? NB_OP_DESTROY : NB_OP_MODIFY, limit_str); | ||
return nb_cli_apply_changes(vty, NULL); | ||
} | ||
|
||
|
||
DEFUN_YANG (no_match_ecommunity, | ||
no_match_ecommunity_cmd, | ||
"no match extcommunity [<(1-99)|(100-500)|EXTCOMMUNITY_LIST_NAME>]", | ||
"no match extcommunity [<(1-99)|(100-500)|EXTCOMMUNITY_LIST_NAME> [<exact-match$exact|any$any>]]", | ||
NO_STR | ||
MATCH_STR | ||
"Match BGP/VPN extended community list\n" | ||
"Extended community-list number (standard)\n" | ||
"Extended community-list number (expanded)\n" | ||
"Extended community-list name\n") | ||
"Extended community-list name\n" | ||
"Do exact matching of communities\n" | ||
"Do matching of any community\n") | ||
{ | ||
const char *xpath = | ||
"./match-condition[condition='frr-bgp-route-map:match-extcommunity']"; | ||
|
@@ -7980,6 +8103,7 @@ void bgp_route_map_init(void) | |
route_map_install_match(&route_match_evpn_route_type_cmd); | ||
route_map_install_match(&route_match_evpn_rd_cmd); | ||
route_map_install_match(&route_match_community_limit_cmd); | ||
route_map_install_match(&route_match_extcommunity_limit_cmd); | ||
route_map_install_match(&route_match_evpn_default_route_cmd); | ||
route_map_install_match(&route_match_vrl_source_vrf_cmd); | ||
|
||
|
@@ -8053,6 +8177,7 @@ void bgp_route_map_init(void) | |
install_element(RMAP_NODE, &match_community_cmd); | ||
install_element(RMAP_NODE, &no_match_community_cmd); | ||
install_element(RMAP_NODE, &match_community_limit_cmd); | ||
install_element(RMAP_NODE, &match_extcommunity_limit_cmd); | ||
install_element(RMAP_NODE, &match_lcommunity_cmd); | ||
install_element(RMAP_NODE, &no_match_lcommunity_cmd); | ||
install_element(RMAP_NODE, &match_ecommunity_cmd); | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should handle IPv6-specific extended communities also. Thus ecom->unit_size should be used instead.