[bgpd] Trim memory usage of BGP routes
2007-05-03 Paul Jakma <paul.jakma@sun.com>
* bgp_route.h: (struct info) Move less frequently used
fields to a lazily allocated struct info_extra.
Export bgp_info_extra_get
* bgp_route.c: (bgp_info_extra_new) allocate extra
(bgp_info_extra_free) Free damp info and the info_extra.
(bgp_info_extra_get) Retrieve the info_extra of a struct
info, allocating as required.
(generally) adjust to use info->extra
* bgp_damp.c: (generally) use bgp_info_extra_get to access
dampinfo
* bgp_attr.h: Move rarely allocated attributes from struct attr
to a struct attr_extra, for a substantial saving in size of
struct attr.
* bgp_attr.c: (bgp_attr_extra_{new,free}), new, self-explanatory.
(bgp_attr_extra_get) Get the attr_extra for a given struct
attr, allocating it if needs be.
(bgp_attr_dup) Shallow copy the struct attr and its attr_extra.
(generally) adjust to know about attr->extra.
* bgp_debug.c: (bgp_dump_attr) ditto
* bgp_vty.c: (show_bgp_memory) print attr and info extra sizes.
* bgp_nexthop.c: (generally) adjust to know about attr->extra
and info->extra.
* bgp_{packet,routemap,snmp,zebra}.c: ditto
* lib/memtypes.c: Add MTYPE_ATTR_EXTRA and MTYPE_BGP_ROUTE_EXTRA
diff --git a/bgpd/bgp_attr.h b/bgpd/bgp_attr.h
index 0734bc2..ac14947 100644
--- a/bgpd/bgp_attr.h
+++ b/bgpd/bgp_attr.h
@@ -45,24 +45,20 @@
/* BGP attribute header must bigger than 2. */
#define BGP_ATTR_MIN_LEN 2 /* Attribute flag and type. */
-
#define BGP_ATTR_DEFAULT_WEIGHT 32768
-/* BGP attribute structure. */
-struct attr
+/* Additional/uncommon BGP attributes.
+ * lazily allocated as and when a struct attr
+ * requires it.
+ */
+struct attr_extra
{
- /* Attributes. */
+ /* Multi-Protocol Nexthop, AFI IPv6 */
#ifdef HAVE_IPV6
struct in6_addr mp_nexthop_global;
struct in6_addr mp_nexthop_local;
#endif /* HAVE_IPV6 */
- /* AS Path structure */
- struct aspath *aspath;
-
- /* Community structure */
- struct community *community;
-
/* Extended Communities attribute. */
struct ecommunity *ecommunity;
@@ -72,6 +68,37 @@
/* Unknown transitive attribute. */
struct transit *transit;
+ struct in_addr mp_nexthop_global_in;
+ struct in_addr mp_nexthop_local_in;
+
+ /* Aggregator Router ID attribute */
+ struct in_addr aggregator_addr;
+
+ /* Route Reflector Originator attribute */
+ struct in_addr originator_id;
+
+ /* Local weight, not actually an attribute */
+ u_int32_t weight;
+
+ /* Aggregator ASN */
+ as_t aggregator_as;
+
+ /* MP Nexthop length */
+ u_char mp_nexthop_len;
+};
+
+/* BGP core attribute structure. */
+struct attr
+{
+ /* AS Path structure */
+ struct aspath *aspath;
+
+ /* Community structure */
+ struct community *community;
+
+ /* Lazily allocated pointer to extra attributes */
+ struct attr_extra *extra;
+
/* Reference count of this attribute. */
unsigned long refcnt;
@@ -82,14 +109,9 @@
struct in_addr nexthop;
u_int32_t med;
u_int32_t local_pref;
- struct in_addr aggregator_addr;
- struct in_addr originator_id;
- struct in_addr mp_nexthop_global_in;
- struct in_addr mp_nexthop_local_in;
- u_int32_t weight;
- as_t aggregator_as;
+
+ /* Path origin attribute */
u_char origin;
- u_char mp_nexthop_len;
};
/* Router Reflector related structure. */
@@ -115,6 +137,9 @@
extern int bgp_attr_parse (struct peer *, struct attr *, bgp_size_t,
struct bgp_nlri *, struct bgp_nlri *);
extern int bgp_attr_check (struct peer *, struct attr *);
+extern struct attr_extra *bgp_attr_extra_get (struct attr *);
+extern void bgp_attr_extra_free (struct attr *);
+extern void bgp_attr_dup (struct attr *, struct attr *);
extern struct attr *bgp_attr_intern (struct attr *attr);
extern void bgp_attr_unintern (struct attr *);
extern void bgp_attr_flush (struct attr *);