]> git.proxmox.com Git - mirror_frr.git/blob - lib/libfrr.h
Merge pull request #13649 from donaldsharp/unlock_the_node_or_else
[mirror_frr.git] / lib / libfrr.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * libfrr overall management functions
4 *
5 * Copyright (C) 2016 David Lamparter for NetDEF, Inc.
6 */
7
8 #ifndef _ZEBRA_FRR_H
9 #define _ZEBRA_FRR_H
10
11 #include "typesafe.h"
12 #include "sigevent.h"
13 #include "privs.h"
14 #include "frrevent.h"
15 #include "log.h"
16 #include "getopt.h"
17 #include "module.h"
18 #include "hook.h"
19 #include "northbound.h"
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 /* The following options disable specific command line options that
26 * are not applicable for a particular daemon.
27 */
28 #define FRR_NO_PRIVSEP (1 << 0)
29 #define FRR_NO_TCPVTY (1 << 1)
30 #define FRR_LIMITED_CLI (1 << 2)
31 #define FRR_NO_SPLIT_CONFIG (1 << 3)
32 #define FRR_NO_PID (1 << 4)
33 #define FRR_NO_CFG_PID_DRY (FRR_NO_PID | FRR_NO_SPLIT_CONFIG)
34 #define FRR_NO_ZCLIENT (1 << 5)
35 /* If FRR_DETACH_LATER is used, the daemon will keep its parent running
36 * until frr_detach() is called. Normally "somedaemon -d" returns once the
37 * main event loop is reached in the daemon; use this for extra startup bits.
38 *
39 * Does nothing if -d isn't used.
40 */
41 #define FRR_DETACH_LATER (1 << 6)
42 /* If FRR_MANUAL_VTY_START is used, frr_run() will not automatically start
43 * listening on for vty connection (either TCP or Unix socket based). The daemon
44 * is responsible for calling frr_vty_serv() itself.
45 */
46 #define FRR_MANUAL_VTY_START (1 << 7)
47
48 PREDECL_DLIST(log_args);
49 struct log_arg {
50 struct log_args_item itm;
51
52 char target[0];
53 };
54 DECLARE_DLIST(log_args, struct log_arg, itm);
55
56 enum frr_cli_mode {
57 FRR_CLI_CLASSIC = 0,
58 FRR_CLI_TRANSACTIONAL,
59 };
60
61 struct frr_daemon_info {
62 unsigned flags;
63
64 const char *progname;
65 const char *name;
66 const char *logname;
67 unsigned short instance;
68 struct frrmod_runtime *module;
69
70 char *vty_addr;
71 int vty_port;
72 char *vty_sock_path;
73 bool dryrun;
74 bool daemon_mode;
75 bool terminal;
76 enum frr_cli_mode cli_mode;
77
78 struct event *read_in;
79 const char *config_file;
80 const char *backup_config_file;
81 const char *pid_file;
82 #ifdef HAVE_SQLITE3
83 const char *db_file;
84 #endif
85 const char *vty_path;
86 const char *module_path;
87 const char *script_path;
88
89 const char *pathspace;
90 bool zpathspace;
91
92 struct log_args_head early_logging[1];
93 const char *early_loglevel;
94
95 const char *proghelp;
96 void (*printhelp)(FILE *target);
97 const char *copyright;
98 char startinfo[128];
99
100 struct frr_signal_t *signals;
101 size_t n_signals;
102
103 struct zebra_privs_t *privs;
104
105 const struct frr_yang_module_info *const *yang_modules;
106 size_t n_yang_modules;
107
108 bool log_always;
109
110 /* Optional upper limit on the number of fds used in select/poll */
111 uint32_t limit_fds;
112 };
113
114 /* execname is the daemon's executable (and pidfile and configfile) name,
115 * i.e. "zebra" or "bgpd"
116 * constname is the daemons source-level name, primarily for the logging ID,
117 * i.e. "ZEBRA" or "BGP"
118 *
119 * note that this macro is also a latch-on point for other changes (e.g.
120 * upcoming module support) that need to place some per-daemon things. Each
121 * daemon should have one of these.
122 */
123 #define FRR_DAEMON_INFO(execname, constname, ...) \
124 static struct frr_daemon_info execname##_di = {.name = #execname, \
125 .logname = #constname, \
126 .module = THIS_MODULE, \
127 __VA_ARGS__}; \
128 FRR_COREMOD_SETUP(.name = #execname, \
129 .description = #execname " daemon", \
130 .version = FRR_VERSION, ); \
131 MACRO_REQUIRE_SEMICOLON() /* end */
132
133 extern void frr_init_vtydir(void);
134 extern void frr_preinit(struct frr_daemon_info *daemon, int argc, char **argv);
135 extern void frr_opt_add(const char *optstr, const struct option *longopts,
136 const char *helpstr);
137 extern int frr_getopt(int argc, char *const argv[], int *longindex);
138
139 extern __attribute__((__noreturn__)) void frr_help_exit(int status);
140
141 extern struct event_loop *frr_init(void);
142 extern const char *frr_get_progname(void);
143 extern enum frr_cli_mode frr_get_cli_mode(void);
144 extern uint32_t frr_get_fd_limit(void);
145 extern bool frr_is_startup_fd(int fd);
146
147 /* call order of these hooks is as ordered here */
148 DECLARE_HOOK(frr_early_init, (struct event_loop * tm), (tm));
149 DECLARE_HOOK(frr_late_init, (struct event_loop * tm), (tm));
150 /* fork() happens between late_init and config_pre */
151 DECLARE_HOOK(frr_config_pre, (struct event_loop * tm), (tm));
152 DECLARE_HOOK(frr_config_post, (struct event_loop * tm), (tm));
153
154 extern void frr_config_fork(void);
155
156 extern void frr_run(struct event_loop *master);
157 extern void frr_detach(void);
158 extern void frr_vty_serv_start(void);
159 extern void frr_vty_serv_stop(void);
160
161 extern bool frr_zclient_addr(struct sockaddr_storage *sa, socklen_t *sa_len,
162 const char *path);
163
164 /* these two are before the protocol daemon does its own shutdown
165 * it's named this way being the counterpart to frr_late_init */
166 DECLARE_KOOH(frr_early_fini, (), ());
167 extern void frr_early_fini(void);
168 /* and these two are after the daemon did its own cleanup */
169 DECLARE_KOOH(frr_fini, (), ());
170 extern void frr_fini(void);
171
172 extern char config_default[512];
173 extern char frr_zclientpath[256];
174 extern const char frr_sysconfdir[];
175 extern char frr_vtydir[256];
176 extern const char frr_moduledir[];
177 extern const char frr_scriptdir[];
178
179 extern char frr_protoname[];
180 extern char frr_protonameinst[];
181 /* always set in the spot where we *would* fork even if we don't do so */
182 extern bool frr_is_after_fork;
183
184 extern bool debug_memstats_at_exit;
185
186 #ifdef __cplusplus
187 }
188 #endif
189
190 #endif /* _ZEBRA_FRR_H */