]> git.proxmox.com Git - mirror_frr.git/blob - lib/module.h
Merge pull request #13649 from donaldsharp/unlock_the_node_or_else
[mirror_frr.git] / lib / module.h
1 // SPDX-License-Identifier: ISC
2 /*
3 * Copyright (c) 2015-16 David Lamparter, for NetDEF, Inc.
4 */
5
6 #ifndef _FRR_MODULE_H
7 #define _FRR_MODULE_H
8
9 #include <stdint.h>
10 #include <stdbool.h>
11
12 #include "compiler.h"
13 #include "xref.h"
14
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18
19 struct frrmod_runtime;
20
21 struct frrmod_info {
22 /* single-line few-word title */
23 const char *name;
24 /* human-readable version number, should not contain spaces */
25 const char *version;
26 /* one-paragraph description */
27 const char *description;
28
29 int (*init)(void);
30 };
31
32 /* primary entry point structure to be present in loadable module under
33 * "_frrmod_this_module" dlsym() name
34 *
35 * note space for future extensions is reserved below, so other modules
36 * (e.g. memory management, hooks) can add fields
37 *
38 * const members/info are in frrmod_info.
39 */
40 struct frrmod_runtime {
41 struct frrmod_runtime *next;
42
43 const struct frrmod_info *info;
44 void *dl_handle;
45 bool finished_loading;
46
47 char *load_name;
48 char *load_args;
49 };
50
51 /* space-reserving foo */
52 struct _frrmod_runtime_size {
53 struct frrmod_runtime r;
54 /* this will barf if frrmod_runtime exceeds 1024 bytes ... */
55 uint8_t space[1024 - sizeof(struct frrmod_runtime)];
56 };
57 union _frrmod_runtime_u {
58 struct frrmod_runtime r;
59 struct _frrmod_runtime_size s;
60 };
61
62 extern union _frrmod_runtime_u _frrmod_this_module;
63 #define THIS_MODULE (&_frrmod_this_module.r)
64
65 #define FRR_COREMOD_SETUP(...) \
66 static const struct frrmod_info _frrmod_info = {__VA_ARGS__}; \
67 DSO_LOCAL union _frrmod_runtime_u _frrmod_this_module = {{ \
68 NULL, \
69 &_frrmod_info, \
70 }}; \
71 XREF_SETUP(); \
72 MACRO_REQUIRE_SEMICOLON() /* end */
73
74 #define FRR_MODULE_SETUP(...) \
75 FRR_COREMOD_SETUP(__VA_ARGS__); \
76 DSO_SELF struct frrmod_runtime *frr_module = &_frrmod_this_module.r; \
77 MACRO_REQUIRE_SEMICOLON() /* end */
78
79 extern struct frrmod_runtime *frrmod_list;
80
81 extern void frrmod_init(struct frrmod_runtime *modinfo);
82 extern struct frrmod_runtime *frrmod_load(const char *spec, const char *dir,
83 void (*pFerrlog)(const void *,
84 const char *),
85 const void *pErrlogCookie);
86 #if 0
87 /* not implemented yet */
88 extern void frrmod_unload(struct frrmod_runtime *module);
89 #endif
90
91 #ifdef __cplusplus
92 }
93 #endif
94
95 #endif /* _FRR_MODULE_H */