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