{
struct community_list *cl = data;
- return jhash(cl->name, sizeof(cl->name), 0xdeadbeaf);
+ if (cl->name_hash)
+ return cl->name_hash;
+
+ cl->name_hash = bgp_clist_hash_key(cl->name);
+ return cl->name_hash;
}
static bool bgp_clist_hash_cmp_community_list(const void *a1, const void *a2)
const struct community_list *cl1 = a1;
const struct community_list *cl2 = a2;
+ if (cl1->name_hash != cl2->name_hash)
+ return false;
+
if (strcmp(cl1->name, cl2->name) == 0)
return true;
/* Allocate new community_list and copy given name. */
new = community_list_new();
new->name = XSTRDUP(MTYPE_COMMUNITY_LIST_NAME, name);
+ new->name_hash = bgp_clist_hash_key_community_list(new);
/* Save for later */
hash_get(cm->hash, new, hash_alloc_intern);
}
struct community_list *community_list_lookup(struct community_list_handler *ch,
- const char *name, int master)
+ const char *name,
+ uint32_t name_hash,
+ int master)
{
struct community_list lookup;
struct community_list_master *cm;
return NULL;
lookup.name = (char *)name;
+ lookup.name_hash = name_hash;
return hash_get(cm->hash, &lookup, NULL);
}
{
struct community_list *list;
- list = community_list_lookup(ch, name, master);
+ list = community_list_lookup(ch, name, 0, master);
if (!list)
list = community_list_insert(ch, name, master);
return list;
struct community *com = NULL;
/* Lookup community list. */
- list = community_list_lookup(ch, name, COMMUNITY_LIST_MASTER);
+ list = community_list_lookup(ch, name, 0, COMMUNITY_LIST_MASTER);
if (list == NULL)
return COMMUNITY_LIST_ERR_CANT_FIND_LIST;
regex_t *regex = NULL;
/* Lookup community list. */
- list = community_list_lookup(ch, name, LARGE_COMMUNITY_LIST_MASTER);
+ list = community_list_lookup(ch, name, 0, LARGE_COMMUNITY_LIST_MASTER);
if (list == NULL)
return COMMUNITY_LIST_ERR_CANT_FIND_LIST;
struct ecommunity *ecom = NULL;
/* Lookup extcommunity list. */
- list = community_list_lookup(ch, name, EXTCOMMUNITY_LIST_MASTER);
+ list = community_list_lookup(ch, name, 0, EXTCOMMUNITY_LIST_MASTER);
if (list == NULL)
return COMMUNITY_LIST_ERR_CANT_FIND_LIST;
#ifndef _QUAGGA_BGP_CLIST_H
#define _QUAGGA_BGP_CLIST_H
+#include "jhash.h"
+
/* Master Community-list. */
#define COMMUNITY_LIST_MASTER 0
#define EXTCOMMUNITY_LIST_MASTER 1
/* Name of the community-list. */
char *name;
+ /* Stored hash value of name, to further speed up hash operations */
+ uint32_t name_hash;
+
/* String or number. */
int sort;
community_list_master_lookup(struct community_list_handler *, int);
extern struct community_list *
-community_list_lookup(struct community_list_handler *, const char *, int);
+community_list_lookup(struct community_list_handler *c, const char *name,
+ uint32_t name_hash, int master);
extern int community_list_match(struct community *, struct community_list *);
extern int ecommunity_list_match(struct ecommunity *, struct community_list *);
extern struct lcommunity *
lcommunity_list_match_delete(struct lcommunity *lcom,
struct community_list *list);
+
+static inline uint32_t bgp_clist_hash_key(char *name)
+{
+ return jhash(name, sizeof(name), 0xdeadbeaf);
+}
+
#endif /* _QUAGGA_BGP_CLIST_H */
{
struct community_list *list;
- list = community_list_lookup(bgp_clist, lcom,
+ list = community_list_lookup(bgp_clist, lcom, 0,
LARGE_COMMUNITY_LIST_MASTER);
if (list == NULL) {
vty_out(vty, "%% %s is not a valid large-community-list name\n",
{
struct community_list *list;
- list = community_list_lookup(bgp_clist, com, COMMUNITY_LIST_MASTER);
+ list = community_list_lookup(bgp_clist, com, 0, COMMUNITY_LIST_MASTER);
if (list == NULL) {
vty_out(vty, "%% %s is not a valid community-list name\n", com);
return CMD_WARNING;
/* `match community COMMUNIY' */
struct rmap_community {
char *name;
+ uint32_t name_hash;
int exact;
};
rcom = rule;
list = community_list_lookup(bgp_clist, rcom->name,
+ rcom->name_hash,
COMMUNITY_LIST_MASTER);
if (!list)
return RMAP_NOMATCH;
rcom->name = XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
rcom->exact = 0;
}
+
+ rcom->name_hash = bgp_clist_hash_key(rcom->name);
return rcom;
}
path = object;
list = community_list_lookup(bgp_clist, rcom->name,
+ rcom->name_hash,
LARGE_COMMUNITY_LIST_MASTER);
if (!list)
return RMAP_NOMATCH;
rcom->name = XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
rcom->exact = 0;
}
+
+ rcom->name_hash = bgp_clist_hash_key(rcom->name);
return rcom;
}
path = object;
list = community_list_lookup(bgp_clist, rcom->name,
+ rcom->name_hash,
EXTCOMMUNITY_LIST_MASTER);
if (!list)
return RMAP_NOMATCH;
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);
return rcom;
}
path = object;
list = community_list_lookup(bgp_clist, rcom->name,
+ rcom->name_hash,
LARGE_COMMUNITY_LIST_MASTER);
old = path->attr->lcommunity;
str = NULL;
rcom->name = str;
+ rcom->name_hash = bgp_clist_hash_key(rcom->name);
return rcom;
}
path = object;
list = community_list_lookup(bgp_clist, rcom->name,
+ rcom->name_hash,
COMMUNITY_LIST_MASTER);
old = path->attr->community;
str = NULL;
rcom->name = str;
+ rcom->name_hash = bgp_clist_hash_key(rcom->name);
return rcom;
}
vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
}
- list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
+ list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
COMMUNITY_LIST_MASTER);
if (!list) {
vty_out(vty, "%% Can't find community-list\n");
zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
}
- list = community_list_lookup(bgp_clist, argv[3]->arg,
+ list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
LARGE_COMMUNITY_LIST_MASTER);
if (!list) {
vty_out(vty, "%% Can't find extcommunity-list\n");
vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
}
- list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
+ list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
EXTCOMMUNITY_LIST_MASTER);
if (!list) {
vty_out(vty, "%% Can't find extcommunity-list\n");