ipsec: IPSec protection for multi-point tunnel interfaces
[vpp.git] / src / vnet / adj / adj_delegate.h
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 /**
16  * A Delagate is a means to implement the Delagation design pattern;
17  * the extension of an object's functionality through the composition of,
18  * and delgation to, other objects.
19  * These 'other' objects are delegates. Delagates are thus attached to
20  * ADJ objects to extend their functionality.
21  */
22
23 #ifndef __ADJ_DELEGATE_T__
24 #define __ADJ_DELEGATE_T__
25
26 #include <vnet/adj/adj.h>
27
28 /**
29  * Built-in delegate types.
30  * When adding new types, if your code is within the vnet subsystem, then add a
31  * new  type here. If not then use the adj_delegate_register_new_type API to
32  * register a new type.
33  */
34 typedef enum adj_delegate_type_t_ {
35     /**
36      * BFD session state
37      */
38     ADJ_DELEGATE_BFD,
39     /**
40      * Stacking of a midchain's nexthop
41      */
42     ADJ_DELEGATE_MIDCHAIN,
43 } adj_delegate_type_t;
44
45 #define ADJ_DELEGATE_LAST (ADJ_DELEGATE_MIDCHAIN)
46
47 /**
48  * Adj delegate. This object is attached to the adjacency.
49  */
50 typedef struct adj_delegate_t_
51 {
52     /**
53      * The ADJ entry object to which the delagate is attached
54      */
55     adj_index_t ad_adj_index;
56
57     /**
58      * The delagate type
59      */
60     adj_delegate_type_t ad_type;
61
62     /**
63      * The index passed by the provider to identify its delegate instance.
64      * As with all things VPP this is a pool index.
65      */
66     index_t ad_index;
67 } adj_delegate_t;
68
69 /**
70  * Indication that the adjacency has been deleted. The delegate provider should free
71  * the delegate.
72  */
73 typedef void (*adj_delegate_adj_deleted_t)(adj_delegate_t *aed);
74
75 /**
76  * Format function for the delegate
77  */
78 typedef u8 * (*adj_delegate_format_t)(const adj_delegate_t *aed, u8 *s);
79
80 /**
81  * Notification that an adjacency has been created
82  */
83 typedef void (*adj_delegate_adj_created_t)(adj_index_t ai);
84
85 /**
86  * An ADJ delegate virtual function table
87  */
88 typedef struct adj_delegate_vft_t_ {
89     adj_delegate_format_t adv_format;
90     adj_delegate_adj_deleted_t adv_adj_deleted;
91     adj_delegate_adj_created_t adv_adj_created;
92 } adj_delegate_vft_t;
93
94 /**
95  * @brief Remove a delegate from an adjacency
96  *
97  * @param ai The adjacency to remove the delegate from
98  * @param type The type of delegate being removed
99  */
100 extern void adj_delegate_remove(adj_index_t ai,
101                                 adj_delegate_type_t type);
102
103 /**
104  * @brief Add a delegate to an adjacency
105  *
106  * @param ai The adjacency to add the delegate to
107  * @param type The type of delegate being added
108  * @param adi The provider's [pool] index of its attached objet
109  */
110 extern int adj_delegate_add(ip_adjacency_t *adj,
111                             adj_delegate_type_t fdt,
112                             index_t adi);
113
114 /**
115  * @brief Get a delegate from an adjacency
116  *
117  * @param ai The adjacency to get the delegate from
118  * @param type The type of delegate being sought
119  */
120 extern adj_delegate_t *adj_delegate_get(const ip_adjacency_t *adj,
121                                         adj_delegate_type_t type);
122
123 /**
124  * @brief Register a VFT for one of the built-in types
125  */
126 extern void adj_delegate_register_type(adj_delegate_type_t type,
127                                        const adj_delegate_vft_t *vft);
128
129 /**
130  * @brief create a new delegate type and register a new VFT
131  */
132 extern adj_delegate_type_t adj_delegate_register_new_type(
133     const adj_delegate_vft_t *vft);
134
135 #endif