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