mirror of
https://github.com/FRRouting/frr.git
synced 2025-04-30 13:37:17 +02:00
mgmtd: lib: read transitioned daemons split config files in mgmtd
When daemons transition to mgmtd they should stop reading their split config files, and let mgmtd do that, otherwise things can get out of sync. Signed-off-by: Christian Hopps <chopps@labn.net>
This commit is contained in:
parent
803829e41e
commit
8033bf3976
|
@ -2400,7 +2400,7 @@ static void vty_timeout(struct event *thread)
|
|||
}
|
||||
|
||||
/* Read up configuration file from file_name. */
|
||||
static void vty_read_file(struct nb_config *config, FILE *confp)
|
||||
void vty_read_file(struct nb_config *config, FILE *confp)
|
||||
{
|
||||
int ret;
|
||||
struct vty *vty;
|
||||
|
|
|
@ -369,6 +369,7 @@ extern void vty_pass_fd(struct vty *vty, int fd);
|
|||
|
||||
extern bool vty_read_config(struct nb_config *config, const char *config_file,
|
||||
char *config_default_dir);
|
||||
extern void vty_read_file(struct nb_config *config, FILE *confp);
|
||||
extern void vty_time_print(struct vty *, int);
|
||||
extern void vty_serv_sock(const char *, unsigned short, const char *);
|
||||
extern void vty_close(struct vty *);
|
||||
|
|
|
@ -62,6 +62,8 @@ struct mgmt_master {
|
|||
};
|
||||
|
||||
extern struct mgmt_master *mm;
|
||||
extern char const *const mgmt_daemons[];
|
||||
extern uint mgmt_daemons_count;
|
||||
|
||||
/* Inline functions */
|
||||
static inline unsigned long timeval_elapsed(struct timeval a, struct timeval b)
|
||||
|
|
|
@ -17,6 +17,13 @@
|
|||
#include "routing_nb.h"
|
||||
|
||||
|
||||
char const *const mgmt_daemons[] = {
|
||||
#ifdef HAVE_STATICD
|
||||
"staticd",
|
||||
#endif
|
||||
};
|
||||
uint mgmt_daemons_count = array_size(mgmt_daemons);
|
||||
|
||||
/* mgmt options, we use GNU getopt library. */
|
||||
static const struct option longopts[] = {
|
||||
{"skip_runas", no_argument, NULL, 'S'},
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
|
||||
#include "command.h"
|
||||
#include "json.h"
|
||||
#include "northbound_cli.h"
|
||||
|
||||
#include "mgmtd/mgmt.h"
|
||||
#include "mgmtd/mgmt_be_server.h"
|
||||
#include "mgmtd/mgmt_be_adapter.h"
|
||||
|
@ -439,6 +441,33 @@ DEFPY(debug_mgmt,
|
|||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
* Analog of `frr_config_read_in()`, instead of our config file though we loop
|
||||
* over all daemons that have transitioned to mgmtd, loading their configs
|
||||
*/
|
||||
static int mgmt_config_pre_hook(struct event_loop *loop)
|
||||
{
|
||||
FILE *confp;
|
||||
char *p;
|
||||
|
||||
for (uint i = 0; i < mgmt_daemons_count; i++) {
|
||||
p = asprintfrr(MTYPE_TMP, "%s/%s.conf", frr_sysconfdir,
|
||||
mgmt_daemons[i]);
|
||||
confp = fopen(p, "r");
|
||||
if (confp == NULL) {
|
||||
if (errno != ENOENT)
|
||||
zlog_err("%s: couldn't read config file %s: %s",
|
||||
__func__, p, safe_strerror(errno));
|
||||
} else {
|
||||
zlog_info("mgmtd: reading daemon config from %s", p);
|
||||
vty_read_file(vty_shared_candidate_config, confp);
|
||||
fclose(confp);
|
||||
}
|
||||
XFREE(MTYPE_TMP, p);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mgmt_vty_init(void)
|
||||
{
|
||||
/*
|
||||
|
@ -452,6 +481,8 @@ void mgmt_vty_init(void)
|
|||
static_vty_init();
|
||||
#endif
|
||||
|
||||
hook_register(frr_config_pre, mgmt_config_pre_hook);
|
||||
|
||||
install_node(&debug_node);
|
||||
|
||||
install_element(VIEW_NODE, &show_mgmt_be_adapter_cmd);
|
||||
|
|
|
@ -161,6 +161,10 @@ static const struct frr_yang_module_info *const staticd_yang_modules[] = {
|
|||
|
||||
#define STATIC_VTY_PORT 2616
|
||||
|
||||
/*
|
||||
* NOTE: .flags == FRR_NO_SPLIT_CONFIG to avoid reading split config, mgmtd will
|
||||
* do this for us now
|
||||
*/
|
||||
FRR_DAEMON_INFO(staticd, STATIC, .vty_port = STATIC_VTY_PORT,
|
||||
|
||||
.proghelp = "Implementation of STATIC.",
|
||||
|
@ -170,7 +174,8 @@ FRR_DAEMON_INFO(staticd, STATIC, .vty_port = STATIC_VTY_PORT,
|
|||
|
||||
.privs = &static_privs, .yang_modules = staticd_yang_modules,
|
||||
.n_yang_modules = array_size(staticd_yang_modules),
|
||||
);
|
||||
|
||||
.flags = FRR_NO_SPLIT_CONFIG);
|
||||
|
||||
int main(int argc, char **argv, char **envp)
|
||||
{
|
||||
|
@ -210,9 +215,12 @@ int main(int argc, char **argv, char **envp)
|
|||
|
||||
routing_control_plane_protocols_register_vrf_dependency();
|
||||
|
||||
snprintf(backup_config_file, sizeof(backup_config_file),
|
||||
"%s/zebra.conf", frr_sysconfdir);
|
||||
staticd_di.backup_config_file = backup_config_file;
|
||||
/*
|
||||
* We set FRR_NO_SPLIT_CONFIG flag to avoid reading our config, but we
|
||||
* still need to write one if vtysh tells us to. Setting the host
|
||||
* config filename does this.
|
||||
*/
|
||||
host_config_set(config_default);
|
||||
|
||||
frr_config_fork();
|
||||
frr_run(master);
|
||||
|
|
Loading…
Reference in a new issue