]> git.proxmox.com Git - mirror_frr.git/blob - lib/module.h
Merge pull request #10953 from leonshaw/fix/bgp-rm-leak
[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 #include "compiler.h"
24 #include "xref.h"
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 struct frrmod_runtime;
31
32 struct frrmod_info {
33 /* single-line few-word title */
34 const char *name;
35 /* human-readable version number, should not contain spaces */
36 const char *version;
37 /* one-paragraph description */
38 const char *description;
39
40 int (*init)(void);
41 };
42
43 /* primary entry point structure to be present in loadable module under
44 * "_frrmod_this_module" dlsym() name
45 *
46 * note space for future extensions is reserved below, so other modules
47 * (e.g. memory management, hooks) can add fields
48 *
49 * const members/info are in frrmod_info.
50 */
51 struct frrmod_runtime {
52 struct frrmod_runtime *next;
53
54 const struct frrmod_info *info;
55 void *dl_handle;
56 bool finished_loading;
57
58 char *load_name;
59 char *load_args;
60 };
61
62 /* space-reserving foo */
63 struct _frrmod_runtime_size {
64 struct frrmod_runtime r;
65 /* this will barf if frrmod_runtime exceeds 1024 bytes ... */
66 uint8_t space[1024 - sizeof(struct frrmod_runtime)];
67 };
68 union _frrmod_runtime_u {
69 struct frrmod_runtime r;
70 struct _frrmod_runtime_size s;
71 };
72
73 extern union _frrmod_runtime_u _frrmod_this_module;
74 #define THIS_MODULE (&_frrmod_this_module.r)
75
76 #define FRR_COREMOD_SETUP(...) \
77 static const struct frrmod_info _frrmod_info = {__VA_ARGS__}; \
78 DSO_LOCAL union _frrmod_runtime_u _frrmod_this_module = {{ \
79 NULL, \
80 &_frrmod_info, \
81 }}; \
82 XREF_SETUP(); \
83 MACRO_REQUIRE_SEMICOLON() /* end */
84
85 #define FRR_MODULE_SETUP(...) \
86 FRR_COREMOD_SETUP(__VA_ARGS__); \
87 DSO_SELF struct frrmod_runtime *frr_module = &_frrmod_this_module.r; \
88 MACRO_REQUIRE_SEMICOLON() /* end */
89
90 extern struct frrmod_runtime *frrmod_list;
91
92 extern void frrmod_init(struct frrmod_runtime *modinfo);
93 extern struct frrmod_runtime *frrmod_load(const char *spec, const char *dir,
94 void (*pFerrlog)(const void *,
95 const char *),
96 const void *pErrlogCookie);
97 #if 0
98 /* not implemented yet */
99 extern void frrmod_unload(struct frrmod_runtime *module);
100 #endif
101
102 #ifdef __cplusplus
103 }
104 #endif
105
106 #endif /* _FRR_MODULE_H */