From f84639988e8acbf6180ba00844f5955dc241b289 Mon Sep 17 00:00:00 2001 From: vishaldhingra Date: Sun, 5 May 2019 23:09:08 -0700 Subject: [PATCH] bgpd : Support for exact-match in match clause for lcommunity FRR has a provision to give exact-match in match clause for standard community, but this option is missing for lcommunity. Part 1 : Added support in clist lib Signed-off-by: vishaldhingra --- bgpd/bgp_clist.c | 26 ++++++++++++++++++++++++++ bgpd/bgp_clist.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/bgpd/bgp_clist.c b/bgpd/bgp_clist.c index b9a5784799..ce617fe6b5 100644 --- a/bgpd/bgp_clist.c +++ b/bgpd/bgp_clist.c @@ -695,6 +695,32 @@ int lcommunity_list_match(struct lcommunity *lcom, struct community_list *list) return 0; } + +/* Perform exact matching. In case of expanded large-community-list, do + * same thing as lcommunity_list_match(). + */ +int lcommunity_list_exact_match(struct lcommunity *lcom, + struct community_list *list) +{ + struct community_entry *entry; + + for (entry = list->head; entry; entry = entry->next) { + if (entry->any) + return entry->direct == COMMUNITY_PERMIT ? 1 : 0; + + if (entry->style == LARGE_COMMUNITY_LIST_STANDARD) { + if (lcommunity_cmp(lcom, entry->u.com)) + return entry->direct == COMMUNITY_PERMIT ? 1 + : 0; + } else if (entry->style == LARGE_COMMUNITY_LIST_EXPANDED) { + if (lcommunity_regexp_match(lcom, entry->reg)) + return entry->direct == COMMUNITY_PERMIT ? 1 + : 0; + } + } + return 0; +} + int ecommunity_list_match(struct ecommunity *ecom, struct community_list *list) { struct community_entry *entry; diff --git a/bgpd/bgp_clist.h b/bgpd/bgp_clist.h index 75a31611ba..87b29ac3be 100644 --- a/bgpd/bgp_clist.h +++ b/bgpd/bgp_clist.h @@ -165,6 +165,8 @@ extern int ecommunity_list_match(struct ecommunity *, struct community_list *); extern int lcommunity_list_match(struct lcommunity *, struct community_list *); extern int community_list_exact_match(struct community *, struct community_list *); +extern int lcommunity_list_exact_match(struct lcommunity *lcom, + struct community_list *list); extern struct community *community_list_match_delete(struct community *, struct community_list *); extern struct lcommunity * -- 2.39.5