Steven Luong | c3ed1c9 | 2020-07-27 10:06:58 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 19 | #include <vlib/vlib.h> |
| 20 | |
| 21 | /* ip table add delete callback */ |
| 22 | typedef struct _vnet_ip_table_function_list_elt |
| 23 | { |
| 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; |
| 27 | |
| 28 | typedef enum vnet_ip_table_function_priority_t_ |
| 29 | { |
| 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) |
| 34 | |
| 35 | #ifndef CLIB_MARCH_VARIANT |
| 36 | #define _VNET_IP_TABLE_FUNCTION_DECL_PRIO(f,tag,p) \ |
| 37 | \ |
| 38 | static void __vnet_ip_table_function_init_##tag##_##f (void) \ |
| 39 | __attribute__((__constructor__)) ; \ |
| 40 | \ |
| 41 | static void __vnet_ip_table_function_init_##tag##_##f (void) \ |
| 42 | { \ |
| 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; \ |
| 48 | } \ |
| 49 | static void __vnet_ip_table_function_deinit_##tag##_##f (void) \ |
| 50 | __attribute__((__destructor__)) ; \ |
| 51 | \ |
| 52 | static void __vnet_ip_table_function_deinit_##tag##_##f (void) \ |
| 53 | { \ |
| 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) \ |
| 57 | { \ |
| 58 | vnm->tag##_functions[p] = \ |
| 59 | vnm->tag##_functions[p]->next_ip_table_function; \ |
| 60 | return; \ |
| 61 | } \ |
| 62 | next = vnm->tag##_functions[p]; \ |
| 63 | while (next->next_ip_table_function) \ |
| 64 | { \ |
| 65 | if (next->next_ip_table_function->fp == f) \ |
| 66 | { \ |
| 67 | next->next_ip_table_function = \ |
| 68 | next->next_ip_table_function->next_ip_table_function; \ |
| 69 | return; \ |
| 70 | } \ |
| 71 | next = next->next_ip_table_function; \ |
| 72 | } \ |
| 73 | } |
| 74 | #else |
| 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; |
| 79 | #endif |
| 80 | |
| 81 | #define _VNET_IP_TABLE_FUNCTION_DECL(f,tag) \ |
| 82 | _VNET_IP_TABLE_FUNCTION_DECL_PRIO(f,tag,VNET_ITF_FUNC_PRIORITY_LOW) |
| 83 | |
| 84 | #define VNET_IP_TABLE_ADD_DEL_FUNCTION(f) \ |
| 85 | _VNET_IP_TABLE_FUNCTION_DECL(f,ip_table_add_del) |
| 86 | |
| 87 | #endif /* included_ip_table_h */ |
| 88 | |
| 89 | /* |
| 90 | * fd.io coding-style-patch-verification: ON |
| 91 | * |
| 92 | * Local Variables: |
| 93 | * eval: (c-set-style "gnu") |
| 94 | * End: |
| 95 | */ |