diff options
Diffstat (limited to 'bgpd/bgp_table.h')
| -rw-r--r-- | bgpd/bgp_table.h | 81 | 
1 files changed, 55 insertions, 26 deletions
diff --git a/bgpd/bgp_table.h b/bgpd/bgp_table.h index 9027af5ba3..5b4c3be212 100644 --- a/bgpd/bgp_table.h +++ b/bgpd/bgp_table.h @@ -6,10 +6,6 @@  #ifndef _QUAGGA_BGP_TABLE_H  #define _QUAGGA_BGP_TABLE_H -/* XXX BEGIN TEMPORARY COMPAT */ -#define bgp_dest bgp_node -/* XXX END TEMPORARY COMPAT */ -  #include "mpls.h"  #include "table.h"  #include "queue.h" @@ -67,16 +63,10 @@ enum bgp_path_selection_reason {  	bgp_path_selection_default,  }; -struct bgp_node { -	/* -	 * CAUTION -	 * -	 * These fields must be the very first fields in this structure. -	 * -	 * @see bgp_node_to_rnode -	 * @see bgp_node_from_rnode -	 */ -	ROUTE_NODE_FIELDS +struct bgp_dest { +	struct route_node *rn; + +	void *info;  	struct bgp_adj_out_rb adj_out; @@ -100,6 +90,7 @@ struct bgp_node {  #define BGP_NODE_FIB_INSTALLED          (1 << 6)  #define BGP_NODE_LABEL_REQUESTED        (1 << 7)  #define BGP_NODE_SOFT_RECONFIG (1 << 8) +#define BGP_NODE_PROCESS_CLEAR (1 << 9)  	struct bgp_addpath_node_data tx_addpath; @@ -121,7 +112,7 @@ extern struct bgp_table *bgp_table_init(struct bgp *bgp, afi_t, safi_t);  extern void bgp_table_lock(struct bgp_table *);  extern void bgp_table_unlock(struct bgp_table *);  extern void bgp_table_finish(struct bgp_table **); -extern void bgp_dest_unlock_node(struct bgp_dest *dest); +extern struct bgp_dest *bgp_dest_unlock_node(struct bgp_dest *dest);  extern struct bgp_dest *bgp_dest_lock_node(struct bgp_dest *dest);  extern const char *bgp_dest_get_prefix_str(struct bgp_dest *dest); @@ -133,7 +124,7 @@ extern const char *bgp_dest_get_prefix_str(struct bgp_dest *dest);   */  static inline struct bgp_dest *bgp_dest_from_rnode(struct route_node *rnode)  { -	return (struct bgp_dest *)rnode; +	return (rnode && rnode->info) ? (struct bgp_dest *)rnode->info : NULL;  }  /* @@ -143,7 +134,7 @@ static inline struct bgp_dest *bgp_dest_from_rnode(struct route_node *rnode)   */  static inline struct route_node *bgp_dest_to_rnode(const struct bgp_dest *dest)  { -	return (struct route_node *)dest; +	return dest ? dest->rn : NULL;  }  /* @@ -165,6 +156,9 @@ static inline struct bgp_dest *bgp_dest_parent_nolock(struct bgp_dest *dest)  {  	struct route_node *rn = bgp_dest_to_rnode(dest)->parent; +	while (rn && !rn->info) +		rn = rn->parent; +  	return bgp_dest_from_rnode(rn);  } @@ -178,7 +172,17 @@ static inline struct bgp_dest *bgp_dest_parent_nolock(struct bgp_dest *dest)  static inline struct bgp_dest *  bgp_table_top_nolock(const struct bgp_table *const table)  { -	return bgp_dest_from_rnode(table->route_table->top); +	struct route_node *top; +	struct route_node *rn = top = table->route_table->top; + +	while (rn && !rn->info) { +		if (rn == top) +			route_lock_node(rn); +		rn = route_next(rn); +	} +	if (rn && rn != top) +		route_unlock_node(rn); +	return rn ? rn->info : NULL;  }  /* @@ -187,7 +191,11 @@ bgp_table_top_nolock(const struct bgp_table *const table)  static inline struct bgp_dest *  bgp_table_top(const struct bgp_table *const table)  { -	return bgp_dest_from_rnode(route_top(table->route_table)); +	struct route_node *rn = route_top(table->route_table); + +	while (rn && !rn->info) +		rn = route_next(rn); +	return rn ? rn->info : NULL;  }  /* @@ -195,7 +203,11 @@ bgp_table_top(const struct bgp_table *const table)   */  static inline struct bgp_dest *bgp_route_next(struct bgp_dest *dest)  { -	return bgp_dest_from_rnode(route_next(bgp_dest_to_rnode(dest))); +	struct route_node *rn = route_next(bgp_dest_to_rnode(dest)); + +	while (rn && !rn->info) +		rn = route_next(rn); +	return bgp_dest_from_rnode(rn);  }  /* @@ -209,6 +221,9 @@ static inline struct bgp_dest *bgp_route_next_until(struct bgp_dest *dest,  	rnode = route_next_until(bgp_dest_to_rnode(dest),  			bgp_dest_to_rnode(limit)); +	while (rnode && !rnode->info) +		rnode = route_next_until(rnode, bgp_dest_to_rnode(limit)); +  	return bgp_dest_from_rnode(rnode);  } @@ -218,7 +233,17 @@ static inline struct bgp_dest *bgp_route_next_until(struct bgp_dest *dest,  static inline struct bgp_dest *bgp_node_get(struct bgp_table *const table,  					    const struct prefix *p)  { -	return bgp_dest_from_rnode(route_node_get(table->route_table, p)); +	struct route_node *rn = route_node_get(table->route_table, p); + +	if (!rn->info) { +		struct bgp_dest *dest = XCALLOC(MTYPE_BGP_NODE, +						sizeof(struct bgp_dest)); + +		RB_INIT(bgp_adj_out_rb, &dest->adj_out); +		rn->info = dest; +		dest->rn = rn; +	} +	return rn->info;  }  /* @@ -254,7 +279,11 @@ static inline unsigned long bgp_table_count(const struct bgp_table *const table)  static inline struct bgp_dest *bgp_table_get_next(const struct bgp_table *table,  						  const struct prefix *p)  { -	return bgp_dest_from_rnode(route_table_get_next(table->route_table, p)); +	struct route_node *rn = route_table_get_next(table->route_table, p); + +	while (rn && !rn->info) +		rn = route_next(rn); +	return bgp_dest_from_rnode(rn);  }  /* This would benefit from a real atomic operation... @@ -356,7 +385,7 @@ static inline void bgp_dest_set_bgp_path_info(struct bgp_dest *dest,  static inline struct bgp_table *  bgp_dest_get_bgp_table_info(struct bgp_dest *dest)  { -	return dest->info; +	return dest ? dest->info : NULL;  }  static inline void bgp_dest_set_bgp_table_info(struct bgp_dest *dest, @@ -367,17 +396,17 @@ static inline void bgp_dest_set_bgp_table_info(struct bgp_dest *dest,  static inline bool bgp_dest_has_bgp_path_info_data(struct bgp_dest *dest)  { -	return !!dest->info; +	return dest ? !!dest->info : false;  }  static inline const struct prefix *bgp_dest_get_prefix(const struct bgp_dest *dest)  { -	return &dest->p; +	return dest ? &dest->rn->p : NULL;  }  static inline unsigned int bgp_dest_get_lock_count(const struct bgp_dest *dest)  { -	return dest->lock; +	return dest ? dest->rn->lock : 0;  }  #ifdef _FRR_ATTRIBUTE_PRINTFRR  | 
