]> git.proxmox.com Git - mirror_frr.git/blob - lib/libfrr.h
*: require semicolon after FRR_DAEMON_INFO & co.
[mirror_frr.git] / lib / libfrr.h
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 *
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
19 */
20
21 #ifndef _ZEBRA_FRR_H
22 #define _ZEBRA_FRR_H
23
24 #include "sigevent.h"
25 #include "privs.h"
26 #include "thread.h"
27 #include "log.h"
28 #include "getopt.h"
29 #include "module.h"
30 #include "hook.h"
31 #include "northbound.h"
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 /* The following options disable specific command line options that
38 * are not applicable for a particular daemon.
39 */
40 #define FRR_NO_PRIVSEP (1 << 0)
41 #define FRR_NO_TCPVTY (1 << 1)
42 #define FRR_LIMITED_CLI (1 << 2)
43 #define FRR_NO_CFG_PID_DRY (1 << 3)
44 #define FRR_NO_ZCLIENT (1 << 4)
45 /* If FRR_DETACH_LATER is used, the daemon will keep its parent running
46 * until frr_detach() is called. Normally "somedaemon -d" returns once the
47 * main event loop is reached in the daemon; use this for extra startup bits.
48 *
49 * Does nothing if -d isn't used.
50 */
51 #define FRR_DETACH_LATER (1 << 5)
52
53 enum frr_cli_mode {
54 FRR_CLI_CLASSIC = 0,
55 FRR_CLI_TRANSACTIONAL,
56 };
57
58 struct frr_daemon_info {
59 unsigned flags;
60
61 const char *progname;
62 const char *name;
63 const char *logname;
64 unsigned short instance;
65 struct frrmod_runtime *module;
66
67 char *vty_addr;
68 int vty_port;
69 char *vty_sock_path;
70 bool dryrun;
71 bool daemon_mode;
72 bool terminal;
73 enum frr_cli_mode cli_mode;
74
75 struct thread *read_in;
76 const char *config_file;
77 const char *backup_config_file;
78 const char *pid_file;
79 #ifdef HAVE_SQLITE3
80 const char *db_file;
81 #endif
82 const char *vty_path;
83 const char *module_path;
84 const char *script_path;
85
86 const char *pathspace;
87 bool zpathspace;
88
89 const char *early_logging;
90 const char *early_loglevel;
91
92 const char *proghelp;
93 void (*printhelp)(FILE *target);
94 const char *copyright;
95 char startinfo[128];
96
97 struct quagga_signal_t *signals;
98 size_t n_signals;
99
100 struct zebra_privs_t *privs;
101
102 const struct frr_yang_module_info *const *yang_modules;
103 size_t n_yang_modules;
104
105 bool log_always;
106
107 /* Optional upper limit on the number of fds used in select/poll */
108 uint32_t limit_fds;
109 };
110
111 /* execname is the daemon's executable (and pidfile and configfile) name,
112 * i.e. "zebra" or "bgpd"
113 * constname is the daemons source-level name, primarily for the logging ID,
114 * i.e. "ZEBRA" or "BGP"
115 *
116 * note that this macro is also a latch-on point for other changes (e.g.
117 * upcoming module support) that need to place some per-daemon things. Each
118 * daemon should have one of these.
119 */
120 #define FRR_DAEMON_INFO(execname, constname, ...) \
121 static struct frr_daemon_info execname##_di = {.name = #execname, \
122 .logname = #constname, \
123 .module = THIS_MODULE, \
124 __VA_ARGS__}; \
125 FRR_COREMOD_SETUP(.name = #execname, \
126 .description = #execname " daemon", \
127 .version = FRR_VERSION, ); \
128 MACRO_REQUIRE_SEMICOLON() /* end */
129
130 extern void frr_init_vtydir(void);
131 extern void frr_preinit(struct frr_daemon_info *daemon, int argc, char **argv);
132 extern void frr_opt_add(const char *optstr, const struct option *longopts,
133 const char *helpstr);
134 extern int frr_getopt(int argc, char *const argv[], int *longindex);
135
136 extern __attribute__((__noreturn__)) void frr_help_exit(int status);
137
138 extern struct thread_master *frr_init(void);
139 extern const char *frr_get_progname(void);
140 extern enum frr_cli_mode frr_get_cli_mode(void);
141 extern uint32_t frr_get_fd_limit(void);
142 extern bool frr_is_startup_fd(int fd);
143
144 DECLARE_HOOK(frr_late_init, (struct thread_master * tm), (tm));
145 DECLARE_HOOK(frr_very_late_init, (struct thread_master * tm), (tm));
146 extern void frr_config_fork(void);
147
148 extern void frr_run(struct thread_master *master);
149 extern void frr_detach(void);
150
151 extern bool frr_zclient_addr(struct sockaddr_storage *sa, socklen_t *sa_len,
152 const char *path);
153
154 /* these two are before the protocol daemon does its own shutdown
155 * it's named this way being the counterpart to frr_late_init */
156 DECLARE_KOOH(frr_early_fini, (), ());
157 extern void frr_early_fini(void);
158 /* and these two are after the daemon did its own cleanup */
159 DECLARE_KOOH(frr_fini, (), ());
160 extern void frr_fini(void);
161
162 extern char config_default[512];
163 extern char frr_zclientpath[256];
164 extern const char frr_sysconfdir[];
165 extern char frr_vtydir[256];
166 extern const char frr_moduledir[];
167 extern const char frr_scriptdir[];
168
169 extern char frr_protoname[];
170 extern char frr_protonameinst[];
171
172 extern bool debug_memstats_at_exit;
173
174 #ifdef __cplusplus
175 }
176 #endif
177
178 #endif /* _ZEBRA_FRR_H */