40 #ifndef included_vlib_init_h 41 #define included_vlib_init_h 53 typedef struct _vlib_init_function_list_elt
55 struct _vlib_init_function_list_elt *next_init_function;
57 } _vlib_init_function_list_elt_t;
82 #define VLIB_REMOVE_FROM_LINKED_LIST(first,p,next) \ 89 __typeof__ (p) current = first; \ 90 while (current->next) \ 92 if (current->next == p) \ 94 current->next = current->next->next; \ 97 current = current->next; \ 103 #define _VLIB_INIT_FUNCTION_SYMBOL(x, type) \ 104 _vlib_##type##_function_##x 106 #define VLIB_INIT_FUNCTION_SYMBOL(x) \ 107 _VLIB_INIT_FUNCTION_SYMBOL(x, init) 108 #define VLIB_MAIN_LOOP_ENTER_FUNCTION_SYMBOL(x) \ 109 _VLIB_INIT_FUNCTION_SYMBOL(x, main_loop_enter) 110 #define VLIB_MAIN_LOOP_EXIT_FUNCTION_SYMBOL(x) \ 111 _VLIB_INIT_FUNCTION_SYMBOL(x, main_loop_exit) 112 #define VLIB_CONFIG_FUNCTION_SYMBOL(x) \ 113 _VLIB_INIT_FUNCTION_SYMBOL(x, config) 118 #ifndef CLIB_MARCH_VARIANT 119 #define VLIB_DECLARE_INIT_FUNCTION(x, tag) \ 120 vlib_init_function_t * _VLIB_INIT_FUNCTION_SYMBOL (x, tag) = x; \ 121 static void __vlib_add_##tag##_function_##x (void) \ 122 __attribute__((__constructor__)) ; \ 123 static void __vlib_add_##tag##_function_##x (void) \ 125 vlib_main_t * vm = vlib_get_main(); \ 126 static _vlib_init_function_list_elt_t _vlib_init_function; \ 127 _vlib_init_function.next_init_function \ 128 = vm->tag##_function_registrations; \ 129 vm->tag##_function_registrations = &_vlib_init_function; \ 130 _vlib_init_function.f = &x; \ 132 static void __vlib_rm_##tag##_function_##x (void) \ 133 __attribute__((__destructor__)) ; \ 134 static void __vlib_rm_##tag##_function_##x (void) \ 136 vlib_main_t * vm = vlib_get_main(); \ 137 _vlib_init_function_list_elt_t *next; \ 138 if (vm->tag##_function_registrations->f == &x) \ 140 vm->tag##_function_registrations = \ 141 vm->tag##_function_registrations->next_init_function; \ 144 next = vm->tag##_function_registrations; \ 145 while (next->next_init_function) \ 147 if (next->next_init_function->f == &x) \ 149 next->next_init_function = \ 150 next->next_init_function->next_init_function; \ 153 next = next->next_init_function; \ 159 #define VLIB_DECLARE_INIT_FUNCTION(x, tag) \ 160 static __clib_unused void * __clib_unused_##tag##_##x = x; 163 #define VLIB_INIT_FUNCTION(x) VLIB_DECLARE_INIT_FUNCTION(x,init) 164 #define VLIB_WORKER_INIT_FUNCTION(x) VLIB_DECLARE_INIT_FUNCTION(x,worker_init) 166 #define VLIB_MAIN_LOOP_ENTER_FUNCTION(x) \ 167 VLIB_DECLARE_INIT_FUNCTION(x,main_loop_enter) 168 #define VLIB_MAIN_LOOP_EXIT_FUNCTION(x) \ 169 VLIB_DECLARE_INIT_FUNCTION(x,main_loop_exit) 171 #ifndef CLIB_MARCH_VARIANT 172 #define VLIB_CONFIG_FUNCTION(x,n,...) \ 173 __VA_ARGS__ vlib_config_function_runtime_t \ 174 VLIB_CONFIG_FUNCTION_SYMBOL(x); \ 175 static void __vlib_add_config_function_##x (void) \ 176 __attribute__((__constructor__)) ; \ 177 static void __vlib_add_config_function_##x (void) \ 179 vlib_main_t * vm = vlib_get_main(); \ 180 VLIB_CONFIG_FUNCTION_SYMBOL(x).next_registration \ 181 = vm->config_function_registrations; \ 182 vm->config_function_registrations \ 183 = &VLIB_CONFIG_FUNCTION_SYMBOL(x); \ 185 static void __vlib_rm_config_function_##x (void) \ 186 __attribute__((__destructor__)) ; \ 187 static void __vlib_rm_config_function_##x (void) \ 189 vlib_main_t * vm = vlib_get_main(); \ 190 vlib_config_function_runtime_t *p = \ 191 & VLIB_CONFIG_FUNCTION_SYMBOL (x); \ 192 VLIB_REMOVE_FROM_LINKED_LIST \ 193 (vm->config_function_registrations, p, next_registration);\ 195 vlib_config_function_runtime_t \ 196 VLIB_CONFIG_FUNCTION_SYMBOL (x) \ 205 #define VLIB_CONFIG_FUNCTION(x,n,...) \ 206 static __clib_unused vlib_config_function_runtime_t \ 207 VLIB_CONFIG_FUNCTION_SYMBOL (__clib_unused_##x) \ 215 #ifndef CLIB_MARCH_VARIANT 216 #define VLIB_EARLY_CONFIG_FUNCTION(x,n,...) \ 217 __VA_ARGS__ vlib_config_function_runtime_t \ 218 VLIB_CONFIG_FUNCTION_SYMBOL(x); \ 219 static void __vlib_add_config_function_##x (void) \ 220 __attribute__((__constructor__)) ; \ 221 static void __vlib_add_config_function_##x (void) \ 223 vlib_main_t * vm = vlib_get_main(); \ 224 VLIB_CONFIG_FUNCTION_SYMBOL(x).next_registration \ 225 = vm->config_function_registrations; \ 226 vm->config_function_registrations \ 227 = &VLIB_CONFIG_FUNCTION_SYMBOL(x); \ 229 static void __vlib_rm_config_function_##x (void) \ 230 __attribute__((__destructor__)) ; \ 231 static void __vlib_rm_config_function_##x (void) \ 233 vlib_main_t * vm = vlib_get_main(); \ 234 vlib_config_function_runtime_t *p = \ 235 & VLIB_CONFIG_FUNCTION_SYMBOL (x); \ 236 VLIB_REMOVE_FROM_LINKED_LIST \ 237 (vm->config_function_registrations, p, next_registration);\ 239 vlib_config_function_runtime_t \ 240 VLIB_CONFIG_FUNCTION_SYMBOL (x) \ 249 #define VLIB_EARLY_CONFIG_FUNCTION(x,n,...) \ 250 static __clib_unused vlib_config_function_runtime_t \ 251 VLIB_CONFIG_FUNCTION_SYMBOL (__clib_unused_##x) \ 260 #define vlib_call_init_function(vm, x) \ 262 extern vlib_init_function_t * VLIB_INIT_FUNCTION_SYMBOL (x); \ 263 vlib_init_function_t * _f = VLIB_INIT_FUNCTION_SYMBOL (x); \ 264 clib_error_t * _error = 0; \ 265 if (! hash_get (vm->init_functions_called, _f)) \ 267 hash_set1 (vm->init_functions_called, _f); \ 274 #define vlib_mark_init_function_complete(vm, x) \ 276 extern vlib_init_function_t * VLIB_INIT_FUNCTION_SYMBOL (x); \ 277 vlib_init_function_t * _f = VLIB_INIT_FUNCTION_SYMBOL (x); \ 278 hash_set1 (vm->init_functions_called, _f); \ 281 #define vlib_call_post_graph_init_function(vm, x) \ 283 extern vlib_init_function_t * VLIB_POST_GRAPH_INIT_FUNCTION_SYMBOL (x); \ 284 vlib_init_function_t * _f = VLIB_POST_GRAPH_INIT_FUNCTION_SYMBOL (x); \ 285 clib_error_t * _error = 0; \ 286 if (! hash_get (vm->init_functions_called, _f)) \ 288 hash_set1 (vm->init_functions_called, _f); \ 294 #define vlib_call_config_function(vm, x) \ 296 vlib_config_function_runtime_t * _r; \ 297 clib_error_t * _error = 0; \ 298 extern vlib_config_function_runtime_t \ 299 VLIB_CONFIG_FUNCTION_SYMBOL (x); \ 301 _r = &VLIB_CONFIG_FUNCTION_SYMBOL (x); \ 302 if (! hash_get (vm->init_functions_called, _r->function)) \ 304 hash_set1 (vm->init_functions_called, _r->function); \ 305 _error = _r->function (vm, &_r->input); \ 319 _vlib_init_function_list_elt_t *
320 head,
int call_once);
322 #define foreach_vlib_module_reference \ 327 #define _(x) void vlib_##x##_reference (void); clib_error_t * vlib_call_all_main_loop_exit_functions(struct vlib_main_t *vm)
#define foreach_vlib_module_reference
clib_error_t * vlib_call_all_init_functions(struct vlib_main_t *vm)
clib_error_t * vlib_call_init_exit_functions(struct vlib_main_t *vm, _vlib_init_function_list_elt_t *head, int call_once)
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
struct vlib_config_function_runtime_t vlib_config_function_runtime_t
clib_error_t * vlib_call_all_config_functions(struct vlib_main_t *vm, unformat_input_t *input, int is_early)
clib_error_t * vlib_call_all_main_loop_enter_functions(struct vlib_main_t *vm)
clib_error_t *() vlib_config_function_t(struct vlib_main_t *vm, unformat_input_t *input)
struct vlib_config_function_runtime_t * next_registration