[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_damp.c b/bgpd/bgp_damp.c
index 8ba39b6..5a7c9aa 100644
--- a/bgpd/bgp_damp.c
+++ b/bgpd/bgp_damp.c
@@ -178,14 +178,15 @@
 		   afi_t afi, safi_t safi, int attr_change)
 {
   time_t t_now;
-  struct bgp_damp_info *bdi;
+  struct bgp_damp_info *bdi = NULL;
   double last_penalty = 0;
   
   t_now = time (NULL);
 
   /* Processing Unreachable Messages.  */
-  bdi = binfo->damp_info;
-
+  if (binfo->extra)
+    bdi = binfo->extra->damp_info;
+  
   if (bdi == NULL)
     {
       /* If there is no previous stability history. */
@@ -205,7 +206,7 @@
       bdi->index = -1;
       bdi->afi = afi;
       bdi->safi = safi;
-      binfo->damp_info = bdi;
+      (bgp_info_extra_get (binfo))->damp_info = bdi;
       BGP_DAMP_LIST_ADD (damp, bdi);
     }
   else
@@ -264,8 +265,7 @@
   struct bgp_damp_info *bdi;
   int status;
 
-  bdi = binfo->damp_info;
-  if (! bdi)
+  if (!binfo->extra || !((bdi = binfo->extra->damp_info)))
     return BGP_DAMP_USED;
 
   t_now = time (NULL);
@@ -303,9 +303,11 @@
 {
   time_t t_now, t_diff;
   struct bgp_damp_info *bdi;
-
+  
+  assert (binfo->extra && binfo->extra->damp_info);
+  
   t_now = time (NULL);
-  bdi = binfo->damp_info;
+  bdi = binfo->extra->damp_info;
  
   if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
     {
@@ -353,7 +355,7 @@
     return;
 
   binfo = bdi->binfo;
-  binfo->damp_info = NULL;
+  binfo->extra->damp_info = NULL;
 
   if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
     bgp_reuse_list_delete (bdi);
@@ -590,8 +592,11 @@
   char timebuf[BGP_UPTIME_LEN];
   int penalty;
 
+  if (!binfo->extra)
+    return;
+  
   /* BGP dampening information.  */
-  bdi = binfo->damp_info;
+  bdi = binfo->extra->damp_info;
 
   /* If dampening is not enabled or there is no dampening information,
      return immediately.  */
@@ -622,9 +627,12 @@
   time_t t_now, t_diff;
   char timebuf[BGP_UPTIME_LEN];
   int penalty;
-
+  
+  if (!binfo->extra)
+    return NULL;
+  
   /* BGP dampening information.  */
-  bdi = binfo->damp_info;
+  bdi = binfo->extra->damp_info;
 
   /* If dampening is not enabled or there is no dampening information,
      return immediately.  */