diff options
author | Neale Ranns <neale.ranns@cisco.com> | 2018-02-20 06:25:02 -0800 |
---|---|---|
committer | Neale Ranns <nranns@cisco.com> | 2018-02-21 08:34:12 +0000 |
commit | 76447a740a6989db08dcd0fcbd066b193a875177 (patch) | |
tree | 724e1b2fe1e35202c27a2cdd982bf578cd5c5138 /src/vnet | |
parent | 8a3e575dfca22500744df76c40de600d8aa61e12 (diff) |
Adj Delegates; don't store raw pointers
... you'd think I'd have leanred by now...
Change-Id: I65c54feb2ec016baa07ed96c81ab8f60277c3418
Signed-off-by: Neale Ranns <neale.ranns@cisco.com>
Diffstat (limited to 'src/vnet')
-rw-r--r-- | src/vnet/adj/adj.h | 2 | ||||
-rw-r--r-- | src/vnet/adj/adj_bfd.c | 23 | ||||
-rw-r--r-- | src/vnet/adj/adj_delegate.c | 37 | ||||
-rw-r--r-- | src/vnet/adj/adj_delegate.h | 18 |
4 files changed, 37 insertions, 43 deletions
diff --git a/src/vnet/adj/adj.h b/src/vnet/adj/adj.h index 0434d7c89e5..bcf6c041209 100644 --- a/src/vnet/adj/adj.h +++ b/src/vnet/adj/adj.h @@ -273,7 +273,7 @@ typedef struct ip_adjacency_t_ /** * A sorted vector of delegates */ - struct adj_delegate_t_ **ia_delegates; + struct adj_delegate_t_ *ia_delegates; } ip_adjacency_t; diff --git a/src/vnet/adj/adj_bfd.c b/src/vnet/adj/adj_bfd.c index a4e7e277298..de7abfe4470 100644 --- a/src/vnet/adj/adj_bfd.c +++ b/src/vnet/adj/adj_bfd.c @@ -35,11 +35,6 @@ typedef enum adj_bfd_state_t_ typedef struct adj_bfd_delegate_t_ { /** - * Base class,linkage to the adjacency - */ - adj_delegate_t abd_link; - - /** * BFD session state */ adj_bfd_state_t abd_state; @@ -58,25 +53,21 @@ static adj_bfd_delegate_t *abd_pool; 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 @@ -183,7 +174,7 @@ adj_bfd_notify (bfd_listen_event_e event, 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; diff --git a/src/vnet/adj/adj_delegate.c b/src/vnet/adj/adj_delegate.c index 1cc7c4b94bd..15dcb02afaa 100644 --- a/src/vnet/adj/adj_delegate.c +++ b/src/vnet/adj/adj_delegate.c @@ -32,18 +32,18 @@ adj_delegate_find_i (const ip_adjacency_t *adj, 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 { @@ -81,19 +81,22 @@ static int 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, @@ -103,7 +106,7 @@ adj_delegate_init (ip_adjacency_t *adj, int adj_delegate_add (ip_adjacency_t *adj, adj_delegate_type_t adt, - adj_delegate_t *ad) + index_t adi) { adj_delegate_t *delegate; @@ -111,7 +114,7 @@ adj_delegate_add (ip_adjacency_t *adj, if (NULL == delegate) { - adj_delegate_init(adj, adt, ad); + adj_delegate_init(adj, adt, adi); } else { @@ -124,13 +127,13 @@ adj_delegate_add (ip_adjacency_t *adj, 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); } } @@ -140,14 +143,14 @@ adj_delegate_adj_deleted (ip_adjacency_t *adj) 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 diff --git a/src/vnet/adj/adj_delegate.h b/src/vnet/adj/adj_delegate.h index b57900bf595..c47380012f1 100644 --- a/src/vnet/adj/adj_delegate.h +++ b/src/vnet/adj/adj_delegate.h @@ -39,11 +39,7 @@ typedef enum adj_delegate_type_t_ { } 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_ { @@ -56,6 +52,12 @@ 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; /** @@ -91,13 +93,11 @@ extern void adj_delegate_remove(adj_index_t ai, * * @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); /** |