]> git.proxmox.com Git - mirror_frr.git/blame - lib/module.h
Merge pull request #13649 from donaldsharp/unlock_the_node_or_else
[mirror_frr.git] / lib / module.h
CommitLineData
acddc0ed 1// SPDX-License-Identifier: ISC
30771d65
DL
2/*
3 * Copyright (c) 2015-16 David Lamparter, for NetDEF, Inc.
30771d65
DL
4 */
5
6#ifndef _FRR_MODULE_H
7#define _FRR_MODULE_H
8
9#include <stdint.h>
10#include <stdbool.h>
11
8e427c29
DL
12#include "compiler.h"
13#include "xref.h"
14
5e244469
RW
15#ifdef __cplusplus
16extern "C" {
17#endif
18
30771d65
DL
19struct frrmod_runtime;
20
21struct 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 */
40struct 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 */
52struct _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};
57union _frrmod_runtime_u {
58 struct frrmod_runtime r;
59 struct _frrmod_runtime_size s;
60};
61
62extern union _frrmod_runtime_u _frrmod_this_module;
63#define THIS_MODULE (&_frrmod_this_module.r)
64
d62a17ae 65#define FRR_COREMOD_SETUP(...) \
66 static const struct frrmod_info _frrmod_info = {__VA_ARGS__}; \
7f04943d
RW
67 DSO_LOCAL union _frrmod_runtime_u _frrmod_this_module = {{ \
68 NULL, \
69 &_frrmod_info, \
8e427c29 70 }}; \
80413c20
DL
71 XREF_SETUP(); \
72 MACRO_REQUIRE_SEMICOLON() /* end */
8e427c29 73
d62a17ae 74#define FRR_MODULE_SETUP(...) \
80413c20
DL
75 FRR_COREMOD_SETUP(__VA_ARGS__); \
76 DSO_SELF struct frrmod_runtime *frr_module = &_frrmod_this_module.r; \
77 MACRO_REQUIRE_SEMICOLON() /* end */
30771d65
DL
78
79extern struct frrmod_runtime *frrmod_list;
80
81extern void frrmod_init(struct frrmod_runtime *modinfo);
d62a17ae 82extern struct frrmod_runtime *frrmod_load(const char *spec, const char *dir,
52fad8f6
PZ
83 void (*pFerrlog)(const void *,
84 const char *),
85 const void *pErrlogCookie);
30771d65
DL
86#if 0
87/* not implemented yet */
88extern void frrmod_unload(struct frrmod_runtime *module);
89#endif
90
5e244469
RW
91#ifdef __cplusplus
92}
93#endif
94
30771d65 95#endif /* _FRR_MODULE_H */