diff options
author | Michael Lambert <lambert@psc.edu> | 2010-07-24 12:44:07 -0400 |
---|---|---|
committer | Paul Jakma <paul@quagga.net> | 2011-03-21 17:30:52 +0000 |
commit | 2c9fd7e07283b8904ef20030c9dadb032e999b12 (patch) | |
tree | e134706cdc5c91daf0002ef3e2d22d12b09cb758 /bgpd | |
parent | 95cbbd2ace2f88019a7a54e67b4b12aaeda177f7 (diff) |
bgpd: "Intern" communities in route maps
* bgp_community.[ch]: (community_lookup) New helper function to look
up a community list in the hash table.
* bgp_routemap.c: A new community structure was being allocated for
every BGP update which matched a route map which set a community.
This behavior led to rapid growth in the memory consumed by bgpd.
Adding the communities to the hash table addresses the memory
growth, but may introduce a problem in modifying or deleting the
'set community' statement in the route map.
Diffstat (limited to 'bgpd')
-rw-r--r-- | bgpd/bgp_community.c | 7 | ||||
-rw-r--r-- | bgpd/bgp_community.h | 1 | ||||
-rw-r--r-- | bgpd/bgp_routemap.c | 8 |
3 files changed, 13 insertions, 3 deletions
diff --git a/bgpd/bgp_community.c b/bgpd/bgp_community.c index ae1d7a15..68383adf 100644 --- a/bgpd/bgp_community.c +++ b/bgpd/bgp_community.c @@ -292,6 +292,13 @@ community_com2str (struct community *com) return str; } +/* Find an 'intern'ed community structure */ +struct community * +community_lookup (struct community *com) +{ + return (struct community *) hash_lookup (comhash, com); +} + /* Intern communities attribute. */ struct community * community_intern (struct community *com) diff --git a/bgpd/bgp_community.h b/bgpd/bgp_community.h index bc1e56ef..78cbfe2b 100644 --- a/bgpd/bgp_community.h +++ b/bgpd/bgp_community.h @@ -70,5 +70,6 @@ extern int community_include (struct community *, u_int32_t); extern void community_del_val (struct community *, u_int32_t *); extern unsigned long community_count (void); extern struct hash *community_hash (void); +extern struct community *community_lookup (struct community *); #endif /* _QUAGGA_BGP_COMMUNITY_H */ diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c index 81ff48db..2b05e898 100644 --- a/bgpd/bgp_routemap.c +++ b/bgpd/bgp_routemap.c @@ -1297,7 +1297,7 @@ route_set_community (void *rule, struct prefix *prefix, new = community_dup (rcs->com); /* will be interned by caller if required */ - attr->community = new; + attr->community = community_intern (new); attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES); } @@ -1311,6 +1311,7 @@ route_set_community_compile (const char *arg) { struct rmap_com_set *rcs; struct community *com = NULL; + struct community *comint; char *sp; int additive = 0; int none = 0; @@ -1337,8 +1338,9 @@ route_set_community_compile (const char *arg) return NULL; } + comint = community_intern (com); rcs = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_com_set)); - rcs->com = com; + rcs->com = comint; rcs->additive = additive; rcs->none = none; @@ -1401,7 +1403,7 @@ route_set_community_delete (void *rule, struct prefix *prefix, } else { - binfo->attr->community = new; + binfo->attr->community = community_intern (new); binfo->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES); } } |