*/
typedef struct adj_bfd_delegate_t_
{
- /**
- * Base class,linkage to the adjacency
- */
- adj_delegate_t abd_link;
-
/**
* BFD session state
*/
static inline adj_bfd_delegate_t*
adj_bfd_from_base (adj_delegate_t *ad)
{
- if (NULL == ad)
+ if (NULL != ad)
{
- return (NULL);
+ return (pool_elt_at_index(abd_pool, ad->ad_index));
}
- return ((adj_bfd_delegate_t*)((char*)ad -
- STRUCT_OFFSET_OF(adj_bfd_delegate_t,
- abd_link)));
+ return (NULL);
}
static inline const adj_bfd_delegate_t*
adj_bfd_from_const_base (const adj_delegate_t *ad)
{
- if (NULL == ad)
+ if (NULL != ad)
{
- return (NULL);
+ return (pool_elt_at_index(abd_pool, ad->ad_index));
}
- return ((adj_bfd_delegate_t*)((char*)ad -
- STRUCT_OFFSET_OF(adj_bfd_delegate_t,
- abd_link)));
+ return (NULL);
}
static adj_bfd_state_t
abd->abd_state = ADJ_BFD_STATE_UP;
abd->abd_index = session->bs_idx;
- adj_delegate_add(adj_get(ai), ADJ_DELEGATE_BFD, &abd->abd_link);
+ adj_delegate_add(adj_get(ai), ADJ_DELEGATE_BFD, abd - abd_pool);
}
break;
adj_delegate_type_t type,
u32 *index)
{
- adj_delegate_t **delegate;
+ adj_delegate_t *delegate;
int ii;
ii = 0;
vec_foreach(delegate, adj->ia_delegates)
{
- if ((*delegate)->ad_type == type)
+ if (delegate->ad_type == type)
{
if (NULL != index)
*index = ii;
- return (*delegate);
+ return (delegate);
}
else
{
adj_delegate_cmp_for_sort (void * v1,
void * v2)
{
- adj_delegate_t **delegate1 = v1, **delegate2 = v2;
+ adj_delegate_t *aed1 = v1, *aed2 = v2;
- return ((*delegate1)->ad_type - (*delegate2)->ad_type);
+ return (aed1->ad_type - aed2->ad_type);
}
static void
adj_delegate_init (ip_adjacency_t *adj,
adj_delegate_type_t adt,
- adj_delegate_t *aed)
+ index_t adi)
{
- aed->ad_adj_index = adj_get_index(adj);
- aed->ad_type = adt;
+ adj_delegate_t aed = {
+ .ad_adj_index = adj_get_index(adj),
+ .ad_type = adt,
+ .ad_index = adi,
+ };
vec_add1(adj->ia_delegates, aed);
vec_sort_with_function(adj->ia_delegates,
int
adj_delegate_add (ip_adjacency_t *adj,
adj_delegate_type_t adt,
- adj_delegate_t *ad)
+ index_t adi)
{
adj_delegate_t *delegate;
if (NULL == delegate)
{
- adj_delegate_init(adj, adt, ad);
+ adj_delegate_init(adj, adt, adi);
}
else
{
void
adj_delegate_adj_deleted (ip_adjacency_t *adj)
{
- adj_delegate_t **delegate;
+ adj_delegate_t *aed;
- vec_foreach(delegate, adj->ia_delegates)
+ vec_foreach(aed, adj->ia_delegates)
{
- if (ad_vfts[(*delegate)->ad_type].adv_adj_deleted)
+ if (ad_vfts[aed->ad_type].adv_adj_deleted)
{
- ad_vfts[(*delegate)->ad_type].adv_adj_deleted(*delegate);
+ ad_vfts[aed->ad_type].adv_adj_deleted(aed);
}
}
u8*
adj_delegate_format (u8* s, ip_adjacency_t *adj)
{
- adj_delegate_t **aed;
+ adj_delegate_t *aed;
vec_foreach(aed, adj->ia_delegates)
{
- if (ad_vfts[(*aed)->ad_type].adv_format)
+ if (ad_vfts[aed->ad_type].adv_format)
{
s = format(s, "{");
- s = ad_vfts[(*aed)->ad_type].adv_format(*aed, s);
+ s = ad_vfts[aed->ad_type].adv_format(aed, s);
s = format(s, "}");
}
else
} adj_delegate_type_t;
/**
- * Adj delegate. This object should be contained within all type specific
- * delegates. i.e. this is the base class to all type specific derived classes.
- * With this model the delegate provider is free to manage the memory of the
- * delegate in the way it chooses. Specifically it can assign them from its own
- * pools and thus, for example, add the delegates to the FIB node graph.
+ * Adj delegate. This object is attached to the adjacency.
*/
typedef struct adj_delegate_t_
{
* The delagate type
*/
adj_delegate_type_t ad_type;
+
+ /**
+ * The index passed by the provider to identify its delegate instance.
+ * As with all things VPP this is a pool index.
+ */
+ index_t ad_index;
} adj_delegate_t;
/**
*
* @param ai The adjacency to add the delegate to
* @param type The type of delegate being added
- * @param ad The delegate. The provider should allocate memory for this object
- * Typically this is a 'derived' class with the
- * adj_delegate_t struct embedded within.
+ * @param adi The provider's [pool] index of its attached objet
*/
extern int adj_delegate_add(ip_adjacency_t *adj,
adj_delegate_type_t fdt,
- adj_delegate_t *ad);
+ index_t adi);
/**