]> git.proxmox.com Git - mirror_frr.git/blob - lib/module.h
zebra, lib: fix the ZEBRA_INTERFACE_VRF_UPDATE zapi message
[mirror_frr.git] / lib / module.h
1 /*
2 * Copyright (c) 2015-16 David Lamparter, for NetDEF, Inc.
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #ifndef _FRR_MODULE_H
18 #define _FRR_MODULE_H
19
20 #include <stdint.h>
21 #include <stdbool.h>
22
23 #if !defined(__GNUC__)
24 #error module code needs GCC visibility extensions
25 #elif __GNUC__ < 4
26 #error module code needs GCC visibility extensions
27 #else
28 # define DSO_PUBLIC __attribute__ ((visibility ("default")))
29 # define DSO_SELF __attribute__ ((visibility ("protected")))
30 # define DSO_LOCAL __attribute__ ((visibility ("hidden")))
31 #endif
32
33 struct frrmod_runtime;
34
35 struct frrmod_info {
36 /* single-line few-word title */
37 const char *name;
38 /* human-readable version number, should not contain spaces */
39 const char *version;
40 /* one-paragraph description */
41 const char *description;
42
43 int (*init)(void);
44 };
45
46 /* primary entry point structure to be present in loadable module under
47 * "_frrmod_this_module" dlsym() name
48 *
49 * note space for future extensions is reserved below, so other modules
50 * (e.g. memory management, hooks) can add fields
51 *
52 * const members/info are in frrmod_info.
53 */
54 struct frrmod_runtime {
55 struct frrmod_runtime *next;
56
57 const struct frrmod_info *info;
58 void *dl_handle;
59 bool finished_loading;
60
61 char *load_name;
62 char *load_args;
63 };
64
65 /* space-reserving foo */
66 struct _frrmod_runtime_size {
67 struct frrmod_runtime r;
68 /* this will barf if frrmod_runtime exceeds 1024 bytes ... */
69 uint8_t space[1024 - sizeof(struct frrmod_runtime)];
70 };
71 union _frrmod_runtime_u {
72 struct frrmod_runtime r;
73 struct _frrmod_runtime_size s;
74 };
75
76 extern union _frrmod_runtime_u _frrmod_this_module;
77 #define THIS_MODULE (&_frrmod_this_module.r)
78
79 #define FRR_COREMOD_SETUP(...) \
80 static const struct frrmod_info _frrmod_info = {__VA_ARGS__}; \
81 DSO_LOCAL union _frrmod_runtime_u _frrmod_this_module = { \
82 .r.info = &_frrmod_info, \
83 };
84 #define FRR_MODULE_SETUP(...) \
85 FRR_COREMOD_SETUP(__VA_ARGS__) \
86 DSO_SELF struct frrmod_runtime *frr_module = &_frrmod_this_module.r;
87
88 extern struct frrmod_runtime *frrmod_list;
89
90 extern void frrmod_init(struct frrmod_runtime *modinfo);
91 extern struct frrmod_runtime *frrmod_load(const char *spec, const char *dir,
92 char *err, size_t err_len);
93 #if 0
94 /* not implemented yet */
95 extern void frrmod_unload(struct frrmod_runtime *module);
96 #endif
97
98 #endif /* _FRR_MODULE_H */