1 From patchwork Sat Jul 24 16:44:07 2010
2 Content-Type: text/plain; charset="utf-8"
4 Content-Transfer-Encoding: 7bit
5 Subject: [quagga-dev,8083,3/3] bgpd: "Intern" communities in route maps
6 Date: Sat, 24 Jul 2010 15:44:07 -0000
7 From: Michael Lambert <lambert@psc.edu>
9 Message-Id: <201007241836.o6OIa8gR023592@tesla.psc.edu>
10 To: quagga-dev@lists.quagga.net
12 * bgp_community.[ch]: (community_lookup) New helper function to look
13 up a community list in the hash table.
15 * bgp_routemap.c: A new community structure was being allocated for
16 every BGP update which matched a route map which set a community.
17 This behavior led to rapid growth in the memory consumed by bgpd.
18 Adding the communities to the hash table addresses the memory
19 growth, but may introduce a problem in modifying or deleting the
20 'set community' statement in the route map.
23 bgpd/bgp_community.c | 7 +++++++
24 bgpd/bgp_community.h | 1 +
25 bgpd/bgp_routemap.c | 8 +++++---
26 3 files changed, 13 insertions(+), 3 deletions(-)
28 --- a/bgpd/bgp_community.c
29 +++ b/bgpd/bgp_community.c
30 @@ -292,6 +292,13 @@ community_com2str (struct community *co
34 +/* Find an 'intern'ed community structure */
36 +community_lookup (struct community *com)
38 + return (struct community *) hash_lookup (comhash, com);
41 /* Intern communities attribute. */
43 community_intern (struct community *com)
44 --- a/bgpd/bgp_community.h
45 +++ b/bgpd/bgp_community.h
46 @@ -70,5 +70,6 @@ extern int community_include (struct com
47 extern void community_del_val (struct community *, u_int32_t *);
48 extern unsigned long community_count (void);
49 extern struct hash *community_hash (void);
50 +extern struct community *community_lookup (struct community *);
52 #endif /* _QUAGGA_BGP_COMMUNITY_H */
53 --- a/bgpd/bgp_routemap.c
54 +++ b/bgpd/bgp_routemap.c
55 @@ -1389,7 +1389,7 @@ route_set_community (void *rule, struct
56 new = community_dup (rcs->com);
58 /* will be interned by caller if required */
59 - attr->community = new;
60 + attr->community = community_intern (new);
62 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);
64 @@ -1403,6 +1403,7 @@ route_set_community_compile (const char
66 struct rmap_com_set *rcs;
67 struct community *com = NULL;
68 + struct community *comint;
72 @@ -1429,8 +1430,9 @@ route_set_community_compile (const char
76 + comint = community_intern (com);
77 rcs = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_com_set));
80 rcs->additive = additive;
83 @@ -1493,7 +1495,7 @@ route_set_community_delete (void *rule,
87 - binfo->attr->community = new;
88 + binfo->attr->community = community_intern (new);
89 binfo->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);