2 * Copyright (c) 2015-16 David Lamparter, for NetDEF, Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
29 #if !defined(__GNUC__)
30 #error module code needs GCC visibility extensions
32 #error module code needs GCC visibility extensions
34 # define DSO_PUBLIC __attribute__ ((visibility ("default")))
35 # define DSO_SELF __attribute__ ((visibility ("protected")))
36 # define DSO_LOCAL __attribute__ ((visibility ("hidden")))
39 struct frrmod_runtime
;
42 /* single-line few-word title */
44 /* human-readable version number, should not contain spaces */
46 /* one-paragraph description */
47 const char *description
;
52 /* primary entry point structure to be present in loadable module under
53 * "_frrmod_this_module" dlsym() name
55 * note space for future extensions is reserved below, so other modules
56 * (e.g. memory management, hooks) can add fields
58 * const members/info are in frrmod_info.
60 struct frrmod_runtime
{
61 struct frrmod_runtime
*next
;
63 const struct frrmod_info
*info
;
65 bool finished_loading
;
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
)];
77 union _frrmod_runtime_u
{
78 struct frrmod_runtime r
;
79 struct _frrmod_runtime_size s
;
82 extern union _frrmod_runtime_u _frrmod_this_module
;
83 #define THIS_MODULE (&_frrmod_this_module.r)
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, \
90 #define FRR_MODULE_SETUP(...) \
91 FRR_COREMOD_SETUP(__VA_ARGS__) \
92 DSO_SELF struct frrmod_runtime *frr_module = &_frrmod_this_module.r;
94 extern struct frrmod_runtime
*frrmod_list
;
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
);
100 /* not implemented yet */
101 extern void frrmod_unload(struct frrmod_runtime
*module
);
104 #endif /* _FRR_MODULE_H */