]> git.proxmox.com Git - mirror_frr.git/blob - lib/module.h
*: reindent
[mirror_frr.git] / lib / module.h
1 /*
2 * Copyright (c) 2015-16 David Lamparter, for NetDEF, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 */
22
23 #ifndef _FRR_MODULE_H
24 #define _FRR_MODULE_H
25
26 #include <stdint.h>
27 #include <stdbool.h>
28
29 #if !defined(__GNUC__)
30 #error module code needs GCC visibility extensions
31 #elif __GNUC__ < 4
32 #error module code needs GCC visibility extensions
33 #else
34 # define DSO_PUBLIC __attribute__ ((visibility ("default")))
35 # define DSO_SELF __attribute__ ((visibility ("protected")))
36 # define DSO_LOCAL __attribute__ ((visibility ("hidden")))
37 #endif
38
39 struct frrmod_runtime;
40
41 struct frrmod_info {
42 /* single-line few-word title */
43 const char *name;
44 /* human-readable version number, should not contain spaces */
45 const char *version;
46 /* one-paragraph description */
47 const char *description;
48
49 int (*init)(void);
50 };
51
52 /* primary entry point structure to be present in loadable module under
53 * "_frrmod_this_module" dlsym() name
54 *
55 * note space for future extensions is reserved below, so other modules
56 * (e.g. memory management, hooks) can add fields
57 *
58 * const members/info are in frrmod_info.
59 */
60 struct frrmod_runtime {
61 struct frrmod_runtime *next;
62
63 const struct frrmod_info *info;
64 void *dl_handle;
65 bool finished_loading;
66
67 char *load_name;
68 char *load_args;
69 };
70
71 /* space-reserving foo */
72 struct _frrmod_runtime_size {
73 struct frrmod_runtime r;
74 /* this will barf if frrmod_runtime exceeds 1024 bytes ... */
75 uint8_t space[1024 - sizeof(struct frrmod_runtime)];
76 };
77 union _frrmod_runtime_u {
78 struct frrmod_runtime r;
79 struct _frrmod_runtime_size s;
80 };
81
82 extern union _frrmod_runtime_u _frrmod_this_module;
83 #define THIS_MODULE (&_frrmod_this_module.r)
84
85 #define FRR_COREMOD_SETUP(...) \
86 static const struct frrmod_info _frrmod_info = {__VA_ARGS__}; \
87 DSO_LOCAL union _frrmod_runtime_u _frrmod_this_module = { \
88 .r.info = &_frrmod_info, \
89 };
90 #define FRR_MODULE_SETUP(...) \
91 FRR_COREMOD_SETUP(__VA_ARGS__) \
92 DSO_SELF struct frrmod_runtime *frr_module = &_frrmod_this_module.r;
93
94 extern struct frrmod_runtime *frrmod_list;
95
96 extern void frrmod_init(struct frrmod_runtime *modinfo);
97 extern struct frrmod_runtime *frrmod_load(const char *spec, const char *dir,
98 char *err, size_t err_len);
99 #if 0
100 /* not implemented yet */
101 extern void frrmod_unload(struct frrmod_runtime *module);
102 #endif
103
104 #endif /* _FRR_MODULE_H */