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