[bgpd] Handle pcount as flags are changed, fixing pcount issues

2006-09-06 Paul Jakma <paul.jakma@sun.com>

	* (general) Squash any and all prefix-count issues by
	  abstracting route flag changes, and maintaining count as and
	  when flags are modified (rather than relying on explicit
	  modifications of count being sprinkled in just the right
	  places throughout the code).
	* bgp_route.c: (bgp_pcount_{dec,inc}rement) removed.
	  (bgp_pcount_adjust) new, update prefix count as
	  needed for a given route.
	  (bgp_info_{uns,s}et_flag) set/unset a BGP_INFO route status
	  flag, calling previous function when appropriate.
	  (general) Update all set/unsets of flags to use previous.
	  Remove pcount_{dec,inc}rement calls.
	  No need to unset BGP_INFO_VALID in places where
	  bgp_info_delete is called, it does that anyway.
	* bgp_{damp,nexthop}.c: Update to use bgp_info_{un,}set_flag.
	* bgp_route.h: Export bgp_info_{un,}set_flag.
	  Add a 'meta' BGP_INFO flag, BGP_INFO_UNUSEABLE.
	  Move BGP_INFO_HOLDDOWN macro to here from bgpd.h
diff --git a/bgpd/bgp_route.h b/bgpd/bgp_route.h
index e5f3ae5..b0c2fcc 100644
--- a/bgpd/bgp_route.h
+++ b/bgpd/bgp_route.h
@@ -105,6 +105,17 @@
   u_char tag[3];
 };
 
+/* Flags which indicate a route is unuseable in some form */
+#define BGP_INFO_UNUSEABLE \
+  (BGP_INFO_HISTORY|BGP_INFO_DAMPED|BGP_INFO_REMOVED)
+/* Macro to check BGP information is alive or not.  Sadly,
+ * not equivalent to just checking previous, because of the
+ * sense of the additional VALID flag.
+ */
+#define BGP_INFO_HOLDDOWN(BI) \
+  (! CHECK_FLAG ((BI)->flags, BGP_INFO_VALID) \
+   || CHECK_FLAG ((BI)->flags, BGP_INFO_UNUSEABLE))
+
 #define DISTRIBUTE_IN_NAME(F)   ((F)->dlist[FILTER_IN].name)
 #define DISTRIBUTE_IN(F)        ((F)->dlist[FILTER_IN].alist)
 #define DISTRIBUTE_OUT_NAME(F)  ((F)->dlist[FILTER_OUT].name)
@@ -151,6 +162,8 @@
 extern struct bgp_info *bgp_info_unlock (struct bgp_info *);
 extern void bgp_info_add (struct bgp_node *rn, struct bgp_info *ri);
 extern void bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri);
+extern void bgp_info_set_flag (struct bgp_node *, struct bgp_info *, u_int32_t);
+extern void bgp_info_unset_flag (struct bgp_node *, struct bgp_info *, u_int32_t);
 
 extern int bgp_nlri_sanity_check (struct peer *, int, u_char *, bgp_size_t);
 extern int bgp_nlri_parse (struct peer *, struct attr *, struct bgp_nlri *);