blob: dfdd27ab573934705c5e33f76959ee7f1d039ef7 [file] [log] [blame]
Steven Luongc3ed1c92020-07-27 10:06:58 -07001/*
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:
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#ifndef included_ip_table_h
17#define included_ip_table_h
18
Neale Rannse4031132020-10-26 13:00:06 +000019#include <vnet/vnet.h>
Steven Luongc3ed1c92020-07-27 10:06:58 -070020
21typedef enum vnet_ip_table_function_priority_t_
22{
23 VNET_IP_TABLE_FUNC_PRIORITY_LOW,
24 VNET_IP_TABLE_FUNC_PRIORITY_HIGH,
25} vnet_ip_table_function_priority_t;
26#define VNET_IP_TABLE_FUNC_N_PRIO ((vnet_ip_table_function_priority_t)VNET_IP_TABLE_FUNC_PRIORITY_HIGH+1)
27
28#ifndef CLIB_MARCH_VARIANT
29#define _VNET_IP_TABLE_FUNCTION_DECL_PRIO(f,tag,p) \
30 \
31static void __vnet_ip_table_function_init_##tag##_##f (void) \
32 __attribute__((__constructor__)) ; \
33 \
34static void __vnet_ip_table_function_init_##tag##_##f (void) \
35{ \
36 vnet_main_t * vnm = vnet_get_main(); \
37 static _vnet_ip_table_function_list_elt_t init_function; \
38 init_function.next_ip_table_function = vnm->tag##_functions[p]; \
39 vnm->tag##_functions[p] = &init_function; \
40 init_function.fp = (void *) &f; \
41} \
42static void __vnet_ip_table_function_deinit_##tag##_##f (void) \
43 __attribute__((__destructor__)) ; \
44 \
45static void __vnet_ip_table_function_deinit_##tag##_##f (void) \
46{ \
47 vnet_main_t * vnm = vnet_get_main(); \
48 _vnet_ip_table_function_list_elt_t *next; \
49 if (vnm->tag##_functions[p]->fp == f) \
50 { \
51 vnm->tag##_functions[p] = \
52 vnm->tag##_functions[p]->next_ip_table_function; \
53 return; \
54 } \
55 next = vnm->tag##_functions[p]; \
56 while (next->next_ip_table_function) \
57 { \
58 if (next->next_ip_table_function->fp == f) \
59 { \
60 next->next_ip_table_function = \
61 next->next_ip_table_function->next_ip_table_function; \
62 return; \
63 } \
64 next = next->next_ip_table_function; \
65 } \
66}
67#else
68/* create unused pointer to silence compiler warnings and get whole
69 function optimized out */
70#define _VNET_IP_TABLE_FUNCTION_DECL_PRIO(f,tag,p) \
71static __clib_unused void * __clib_unused_##f = f;
72#endif
73
74#define _VNET_IP_TABLE_FUNCTION_DECL(f,tag) \
75 _VNET_IP_TABLE_FUNCTION_DECL_PRIO(f,tag,VNET_ITF_FUNC_PRIORITY_LOW)
76
77#define VNET_IP_TABLE_ADD_DEL_FUNCTION(f) \
78 _VNET_IP_TABLE_FUNCTION_DECL(f,ip_table_add_del)
79
80#endif /* included_ip_table_h */
81
82/*
83 * fd.io coding-style-patch-verification: ON
84 *
85 * Local Variables:
86 * eval: (c-set-style "gnu")
87 * End:
88 */