dde6f2b80ea50e37126e53fc3e012f52ceeb90fa
[openwrt/svn-archive/archive.git] / net / quagga / patches / 999-PW-8083-Intern_communities_in_route_maps.patch
1 From patchwork Sat Jul 24 16:44:07 2010
2 Content-Type: text/plain; charset="utf-8"
3 MIME-Version: 1.0
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>
8 X-Patchwork-Id: 253
9 Message-Id: <201007241836.o6OIa8gR023592@tesla.psc.edu>
10 To: quagga-dev@lists.quagga.net
11
12 * bgp_community.[ch]: (community_lookup) New helper function to look
13 up a community list in the hash table.
14
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.
21
22 ---
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(-)
27
28 --- a/bgpd/bgp_community.c
29 +++ b/bgpd/bgp_community.c
30 @@ -292,6 +292,13 @@ community_com2str (struct community *co
31 return str;
32 }
33
34 +/* Find an 'intern'ed community structure */
35 +struct community *
36 +community_lookup (struct community *com)
37 +{
38 + return (struct community *) hash_lookup (comhash, com);
39 +}
40 +
41 /* Intern communities attribute. */
42 struct community *
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 *);
51
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);
57
58 /* will be interned by caller if required */
59 - attr->community = new;
60 + attr->community = community_intern (new);
61
62 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);
63 }
64 @@ -1403,6 +1403,7 @@ route_set_community_compile (const char
65 {
66 struct rmap_com_set *rcs;
67 struct community *com = NULL;
68 + struct community *comint;
69 char *sp;
70 int additive = 0;
71 int none = 0;
72 @@ -1429,8 +1430,9 @@ route_set_community_compile (const char
73 return NULL;
74 }
75
76 + comint = community_intern (com);
77 rcs = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_com_set));
78 - rcs->com = com;
79 + rcs->com = comint;
80 rcs->additive = additive;
81 rcs->none = none;
82
83 @@ -1493,7 +1495,7 @@ route_set_community_delete (void *rule,
84 }
85 else
86 {
87 - binfo->attr->community = new;
88 + binfo->attr->community = community_intern (new);
89 binfo->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);
90 }
91 }