]> git.proxmox.com Git - mirror_frr.git/blame - lib/libfrr.h
Merge pull request #10816 from anlancs/fix-bgdp-local-es-rt
[mirror_frr.git] / lib / libfrr.h
CommitLineData
4f04a76b
DL
1/*
2 * libfrr overall management functions
3 *
4 * Copyright (C) 2016 David Lamparter for NetDEF, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
896014f4
DL
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
4f04a76b
DL
19 */
20
21#ifndef _ZEBRA_FRR_H
22#define _ZEBRA_FRR_H
23
da2fc191 24#include "typesafe.h"
4f04a76b
DL
25#include "sigevent.h"
26#include "privs.h"
27#include "thread.h"
28#include "log.h"
29#include "getopt.h"
30771d65 30#include "module.h"
a5b38c5b 31#include "hook.h"
1c2facd1 32#include "northbound.h"
4f04a76b 33
5e244469
RW
34#ifdef __cplusplus
35extern "C" {
36#endif
37
0a7c7856
DL
38/* The following options disable specific command line options that
39 * are not applicable for a particular daemon.
40 */
4f04a76b
DL
41#define FRR_NO_PRIVSEP (1 << 0)
42#define FRR_NO_TCPVTY (1 << 1)
857b5446 43#define FRR_LIMITED_CLI (1 << 2)
b1dc60f4
DL
44#define FRR_NO_SPLIT_CONFIG (1 << 3)
45#define FRR_NO_PID (1 << 4)
46#define FRR_NO_CFG_PID_DRY (FRR_NO_PID | FRR_NO_SPLIT_CONFIG)
47#define FRR_NO_ZCLIENT (1 << 5)
0a7c7856
DL
48/* If FRR_DETACH_LATER is used, the daemon will keep its parent running
49 * until frr_detach() is called. Normally "somedaemon -d" returns once the
50 * main event loop is reached in the daemon; use this for extra startup bits.
51 *
52 * Does nothing if -d isn't used.
53 */
b1dc60f4 54#define FRR_DETACH_LATER (1 << 6)
4f04a76b 55
da2fc191
DL
56PREDECL_DLIST(log_args);
57struct log_arg {
58 struct log_args_item itm;
59
60 char target[0];
61};
62DECLARE_DLIST(log_args, struct log_arg, itm);
63
1c2facd1
RW
64enum frr_cli_mode {
65 FRR_CLI_CLASSIC = 0,
66 FRR_CLI_TRANSACTIONAL,
67};
68
4f04a76b
DL
69struct frr_daemon_info {
70 unsigned flags;
71
72 const char *progname;
eb05883f 73 const char *name;
bf1013e6 74 const char *logname;
4f04a76b 75 unsigned short instance;
30771d65 76 struct frrmod_runtime *module;
4f04a76b
DL
77
78 char *vty_addr;
79 int vty_port;
80 char *vty_sock_path;
eb05883f
DL
81 bool dryrun;
82 bool daemon_mode;
cff2b211 83 bool terminal;
1c2facd1 84 enum frr_cli_mode cli_mode;
9e224e60
DS
85
86 struct thread *read_in;
eb05883f 87 const char *config_file;
573de11f 88 const char *backup_config_file;
eb05883f 89 const char *pid_file;
1c2facd1
RW
90#ifdef HAVE_SQLITE3
91 const char *db_file;
92#endif
eb05883f 93 const char *vty_path;
80b4df3b 94 const char *module_path;
e4e0229a 95 const char *script_path;
43e587c1 96
d1b4fc1f 97 const char *pathspace;
43e587c1
DS
98 bool zpathspace;
99
da2fc191 100 struct log_args_head early_logging[1];
e9b4e74a 101 const char *early_loglevel;
4f04a76b
DL
102
103 const char *proghelp;
104 void (*printhelp)(FILE *target);
105 const char *copyright;
16077f2f 106 char startinfo[128];
4f04a76b 107
7cc91e67 108 struct frr_signal_t *signals;
4f04a76b
DL
109 size_t n_signals;
110
111 struct zebra_privs_t *privs;
1c2facd1 112
0d8c7a26 113 const struct frr_yang_module_info *const *yang_modules;
1c2facd1 114 size_t n_yang_modules;
2950f5da
DS
115
116 bool log_always;
1a9f340b
MS
117
118 /* Optional upper limit on the number of fds used in select/poll */
119 uint32_t limit_fds;
4f04a76b
DL
120};
121
122/* execname is the daemon's executable (and pidfile and configfile) name,
123 * i.e. "zebra" or "bgpd"
124 * constname is the daemons source-level name, primarily for the logging ID,
125 * i.e. "ZEBRA" or "BGP"
126 *
127 * note that this macro is also a latch-on point for other changes (e.g.
30771d65 128 * upcoming module support) that need to place some per-daemon things. Each
4f04a76b
DL
129 * daemon should have one of these.
130 */
d62a17ae 131#define FRR_DAEMON_INFO(execname, constname, ...) \
132 static struct frr_daemon_info execname##_di = {.name = #execname, \
133 .logname = #constname, \
134 .module = THIS_MODULE, \
135 __VA_ARGS__}; \
136 FRR_COREMOD_SETUP(.name = #execname, \
137 .description = #execname " daemon", \
80413c20
DL
138 .version = FRR_VERSION, ); \
139 MACRO_REQUIRE_SEMICOLON() /* end */
d62a17ae 140
43e587c1 141extern void frr_init_vtydir(void);
d62a17ae 142extern void frr_preinit(struct frr_daemon_info *daemon, int argc, char **argv);
143extern void frr_opt_add(const char *optstr, const struct option *longopts,
144 const char *helpstr);
145extern int frr_getopt(int argc, char *const argv[], int *longindex);
b25b2925
RK
146
147extern __attribute__((__noreturn__)) void frr_help_exit(int status);
4f04a76b
DL
148
149extern struct thread_master *frr_init(void);
1c2facd1
RW
150extern const char *frr_get_progname(void);
151extern enum frr_cli_mode frr_get_cli_mode(void);
6e3253b9
DL
152extern uint32_t frr_get_fd_limit(void);
153extern bool frr_is_startup_fd(int fd);
4f04a76b 154
bf645e31 155/* call order of these hooks is as ordered here */
603c6165 156DECLARE_HOOK(frr_early_init, (struct thread_master * tm), (tm));
8451921b 157DECLARE_HOOK(frr_late_init, (struct thread_master * tm), (tm));
bf645e31
DL
158/* fork() happens between late_init and config_pre */
159DECLARE_HOOK(frr_config_pre, (struct thread_master * tm), (tm));
2bafda27 160DECLARE_HOOK(frr_config_post, (struct thread_master * tm), (tm));
bf645e31 161
eb05883f
DL
162extern void frr_config_fork(void);
163
16077f2f 164extern void frr_run(struct thread_master *master);
0a7c7856 165extern void frr_detach(void);
16077f2f 166
689f5a8c
DL
167extern bool frr_zclient_addr(struct sockaddr_storage *sa, socklen_t *sa_len,
168 const char *path);
169
03951374
DL
170/* these two are before the protocol daemon does its own shutdown
171 * it's named this way being the counterpart to frr_late_init */
8451921b 172DECLARE_KOOH(frr_early_fini, (), ());
03951374
DL
173extern void frr_early_fini(void);
174/* and these two are after the daemon did its own cleanup */
8451921b 175DECLARE_KOOH(frr_fini, (), ());
03951374
DL
176extern void frr_fini(void);
177
ff44f570 178extern char config_default[512];
689f5a8c 179extern char frr_zclientpath[256];
eb05883f 180extern const char frr_sysconfdir[];
43e587c1 181extern char frr_vtydir[256];
80b4df3b 182extern const char frr_moduledir[];
e4e0229a 183extern const char frr_scriptdir[];
4f04a76b 184
b85120bc
DL
185extern char frr_protoname[];
186extern char frr_protonameinst[];
38554d3a
DL
187/* always set in the spot where we *would* fork even if we don't do so */
188extern bool frr_is_after_fork;
b85120bc 189
9eed278b
DL
190extern bool debug_memstats_at_exit;
191
5e244469
RW
192#ifdef __cplusplus
193}
194#endif
195
4f04a76b 196#endif /* _ZEBRA_FRR_H */