2 * Copyright (c) 2020 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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef included_ip_table_h
17 #define included_ip_table_h
19 #include <vlib/vlib.h>
21 /* ip table add delete callback */
22 typedef struct _vnet_ip_table_function_list_elt
24 struct _vnet_ip_table_function_list_elt *next_ip_table_function;
25 clib_error_t *(*fp) (struct vnet_main_t * vnm, u32 table_id, u32 flags);
26 } _vnet_ip_table_function_list_elt_t;
28 typedef enum vnet_ip_table_function_priority_t_
30 VNET_IP_TABLE_FUNC_PRIORITY_LOW,
31 VNET_IP_TABLE_FUNC_PRIORITY_HIGH,
32 } vnet_ip_table_function_priority_t;
33 #define VNET_IP_TABLE_FUNC_N_PRIO ((vnet_ip_table_function_priority_t)VNET_IP_TABLE_FUNC_PRIORITY_HIGH+1)
35 #ifndef CLIB_MARCH_VARIANT
36 #define _VNET_IP_TABLE_FUNCTION_DECL_PRIO(f,tag,p) \
38 static void __vnet_ip_table_function_init_##tag##_##f (void) \
39 __attribute__((__constructor__)) ; \
41 static void __vnet_ip_table_function_init_##tag##_##f (void) \
43 vnet_main_t * vnm = vnet_get_main(); \
44 static _vnet_ip_table_function_list_elt_t init_function; \
45 init_function.next_ip_table_function = vnm->tag##_functions[p]; \
46 vnm->tag##_functions[p] = &init_function; \
47 init_function.fp = (void *) &f; \
49 static void __vnet_ip_table_function_deinit_##tag##_##f (void) \
50 __attribute__((__destructor__)) ; \
52 static void __vnet_ip_table_function_deinit_##tag##_##f (void) \
54 vnet_main_t * vnm = vnet_get_main(); \
55 _vnet_ip_table_function_list_elt_t *next; \
56 if (vnm->tag##_functions[p]->fp == f) \
58 vnm->tag##_functions[p] = \
59 vnm->tag##_functions[p]->next_ip_table_function; \
62 next = vnm->tag##_functions[p]; \
63 while (next->next_ip_table_function) \
65 if (next->next_ip_table_function->fp == f) \
67 next->next_ip_table_function = \
68 next->next_ip_table_function->next_ip_table_function; \
71 next = next->next_ip_table_function; \
75 /* create unused pointer to silence compiler warnings and get whole
76 function optimized out */
77 #define _VNET_IP_TABLE_FUNCTION_DECL_PRIO(f,tag,p) \
78 static __clib_unused void * __clib_unused_##f = f;
81 #define _VNET_IP_TABLE_FUNCTION_DECL(f,tag) \
82 _VNET_IP_TABLE_FUNCTION_DECL_PRIO(f,tag,VNET_ITF_FUNC_PRIORITY_LOW)
84 #define VNET_IP_TABLE_ADD_DEL_FUNCTION(f) \
85 _VNET_IP_TABLE_FUNCTION_DECL(f,ip_table_add_del)
87 #endif /* included_ip_table_h */
90 * fd.io coding-style-patch-verification: ON
93 * eval: (c-set-style "gnu")