1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * libfrr overall management functions
5 * Copyright (C) 2016 David Lamparter for NetDEF, Inc.
19 #include "northbound.h"
25 /* The following options disable specific command line options that
26 * are not applicable for a particular daemon.
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.
39 * Does nothing if -d isn't used.
41 #define FRR_DETACH_LATER (1 << 6)
43 PREDECL_DLIST(log_args
);
45 struct log_args_item itm
;
49 DECLARE_DLIST(log_args
, struct log_arg
, itm
);
53 FRR_CLI_TRANSACTIONAL
,
56 struct frr_daemon_info
{
62 unsigned short instance
;
63 struct frrmod_runtime
*module
;
71 enum frr_cli_mode cli_mode
;
73 struct thread
*read_in
;
74 const char *config_file
;
75 const char *backup_config_file
;
81 const char *module_path
;
82 const char *script_path
;
84 const char *pathspace
;
87 struct log_args_head early_logging
[1];
88 const char *early_loglevel
;
91 void (*printhelp
)(FILE *target
);
92 const char *copyright
;
95 struct frr_signal_t
*signals
;
98 struct zebra_privs_t
*privs
;
100 const struct frr_yang_module_info
*const *yang_modules
;
101 size_t n_yang_modules
;
105 /* Optional upper limit on the number of fds used in select/poll */
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"
114 * note that this macro is also a latch-on point for other changes (e.g.
115 * upcoming module support) that need to place some per-daemon things. Each
116 * daemon should have one of these.
118 #define FRR_DAEMON_INFO(execname, constname, ...) \
119 static struct frr_daemon_info execname##_di = {.name = #execname, \
120 .logname = #constname, \
121 .module = THIS_MODULE, \
123 FRR_COREMOD_SETUP(.name = #execname, \
124 .description = #execname " daemon", \
125 .version = FRR_VERSION, ); \
126 MACRO_REQUIRE_SEMICOLON() /* end */
128 extern void frr_init_vtydir(void);
129 extern void frr_preinit(struct frr_daemon_info
*daemon
, int argc
, char **argv
);
130 extern void frr_opt_add(const char *optstr
, const struct option
*longopts
,
131 const char *helpstr
);
132 extern int frr_getopt(int argc
, char *const argv
[], int *longindex
);
134 extern __attribute__((__noreturn__
)) void frr_help_exit(int status
);
136 extern struct thread_master
*frr_init(void);
137 extern const char *frr_get_progname(void);
138 extern enum frr_cli_mode
frr_get_cli_mode(void);
139 extern uint32_t frr_get_fd_limit(void);
140 extern bool frr_is_startup_fd(int fd
);
142 /* call order of these hooks is as ordered here */
143 DECLARE_HOOK(frr_early_init
, (struct thread_master
* tm
), (tm
));
144 DECLARE_HOOK(frr_late_init
, (struct thread_master
* tm
), (tm
));
145 /* fork() happens between late_init and config_pre */
146 DECLARE_HOOK(frr_config_pre
, (struct thread_master
* tm
), (tm
));
147 DECLARE_HOOK(frr_config_post
, (struct thread_master
* tm
), (tm
));
149 extern void frr_config_fork(void);
151 extern void frr_run(struct thread_master
*master
);
152 extern void frr_detach(void);
154 extern bool frr_zclient_addr(struct sockaddr_storage
*sa
, socklen_t
*sa_len
,
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 */
159 DECLARE_KOOH(frr_early_fini
, (), ());
160 extern void frr_early_fini(void);
161 /* and these two are after the daemon did its own cleanup */
162 DECLARE_KOOH(frr_fini
, (), ());
163 extern void frr_fini(void);
165 extern char config_default
[512];
166 extern char frr_zclientpath
[256];
167 extern const char frr_sysconfdir
[];
168 extern char frr_vtydir
[256];
169 extern const char frr_moduledir
[];
170 extern const char frr_scriptdir
[];
172 extern char frr_protoname
[];
173 extern char frr_protonameinst
[];
174 /* always set in the spot where we *would* fork even if we don't do so */
175 extern bool frr_is_after_fork
;
177 extern bool debug_memstats_at_exit
;
183 #endif /* _ZEBRA_FRR_H */