mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-04-28 17:42:20 +00:00
lib: mgmtd: add manual vty server start option and use it
Signed-off-by: Christian Hopps <chopps@labn.net>
This commit is contained in:
parent
e13a5c4165
commit
5ba5613077
15
lib/libfrr.c
15
lib/libfrr.c
@ -1036,7 +1036,7 @@ void frr_config_fork(void)
|
||||
zlog_tls_buffer_init();
|
||||
}
|
||||
|
||||
static void frr_vty_serv(void)
|
||||
void frr_vty_serv_start(void)
|
||||
{
|
||||
/* allow explicit override of vty_path in the future
|
||||
* (not currently set anywhere) */
|
||||
@ -1058,7 +1058,15 @@ static void frr_vty_serv(void)
|
||||
di->vty_path = vtypath_default;
|
||||
}
|
||||
|
||||
vty_serv_sock(di->vty_addr, di->vty_port, di->vty_path);
|
||||
vty_serv_start(di->vty_addr, di->vty_port, di->vty_path);
|
||||
}
|
||||
|
||||
void frr_vty_serv_stop(void)
|
||||
{
|
||||
vty_serv_stop();
|
||||
|
||||
if (di->vty_path)
|
||||
unlink(di->vty_path);
|
||||
}
|
||||
|
||||
static void frr_check_detach(void)
|
||||
@ -1155,7 +1163,8 @@ void frr_run(struct event_loop *master)
|
||||
{
|
||||
char instanceinfo[64] = "";
|
||||
|
||||
frr_vty_serv();
|
||||
if (!(di->flags & FRR_MANUAL_VTY_START))
|
||||
frr_vty_serv_start();
|
||||
|
||||
if (di->instance)
|
||||
snprintf(instanceinfo, sizeof(instanceinfo), "instance %u ",
|
||||
|
@ -39,6 +39,11 @@ extern "C" {
|
||||
* Does nothing if -d isn't used.
|
||||
*/
|
||||
#define FRR_DETACH_LATER (1 << 6)
|
||||
/* If FRR_MANUAL_VTY_START is used, frr_run() will not automatically start
|
||||
* listening on for vty connection (either TCP or Unix socket based). The daemon
|
||||
* is responsible for calling frr_vty_serv() itself.
|
||||
*/
|
||||
#define FRR_MANUAL_VTY_START (1 << 7)
|
||||
|
||||
PREDECL_DLIST(log_args);
|
||||
struct log_arg {
|
||||
@ -150,6 +155,8 @@ extern void frr_config_fork(void);
|
||||
|
||||
extern void frr_run(struct event_loop *master);
|
||||
extern void frr_detach(void);
|
||||
extern void frr_vty_serv_start(void);
|
||||
extern void frr_vty_serv_stop(void);
|
||||
|
||||
extern bool frr_zclient_addr(struct sockaddr_storage *sa, socklen_t *sa_len,
|
||||
const char *path);
|
||||
|
33
lib/vty.c
33
lib/vty.c
@ -2374,7 +2374,7 @@ static void vtysh_write(struct event *thread)
|
||||
#endif /* VTYSH */
|
||||
|
||||
/* Determine address family to bind. */
|
||||
void vty_serv_sock(const char *addr, unsigned short port, const char *path)
|
||||
void vty_serv_start(const char *addr, unsigned short port, const char *path)
|
||||
{
|
||||
/* If port is set to 0, do not listen on TCP/IP at all! */
|
||||
if (port)
|
||||
@ -2385,6 +2385,20 @@ void vty_serv_sock(const char *addr, unsigned short port, const char *path)
|
||||
#endif /* VTYSH */
|
||||
}
|
||||
|
||||
void vty_serv_stop(void)
|
||||
{
|
||||
struct vty_serv *vtyserv;
|
||||
|
||||
while ((vtyserv = vtyservs_pop(vty_servs))) {
|
||||
EVENT_OFF(vtyserv->t_accept);
|
||||
close(vtyserv->sock);
|
||||
XFREE(MTYPE_VTY_SERV, vtyserv);
|
||||
}
|
||||
|
||||
vtyservs_fini(vty_servs);
|
||||
vtyservs_init(vty_servs);
|
||||
}
|
||||
|
||||
static void vty_error_delete(void *arg)
|
||||
{
|
||||
struct vty_error *ve = arg;
|
||||
@ -3393,13 +3407,10 @@ static void vty_mgmt_server_connected(uintptr_t lib_hndl, uintptr_t usr_data,
|
||||
mgmt_fe_connected = connected;
|
||||
|
||||
/* Start or stop listening for vty connections */
|
||||
if (connected) {
|
||||
zlog_info("mgmtd: starting vty servers");
|
||||
if (connected)
|
||||
frr_vty_serv_start();
|
||||
} else {
|
||||
zlog_info("mgmtd: stopping vty servers");
|
||||
else
|
||||
frr_vty_serv_stop();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -3849,7 +3860,6 @@ void vty_init(struct event_loop *master_thread, bool do_command_logging)
|
||||
void vty_terminate(void)
|
||||
{
|
||||
struct vty *vty;
|
||||
struct vty_serv *vtyserv;
|
||||
|
||||
if (mgmt_lib_hndl) {
|
||||
mgmt_fe_client_lib_destroy();
|
||||
@ -3875,12 +3885,5 @@ void vty_terminate(void)
|
||||
vtys_fini(vtysh_sessions);
|
||||
vtys_init(vtysh_sessions);
|
||||
|
||||
while ((vtyserv = vtyservs_pop(vty_servs))) {
|
||||
EVENT_OFF(vtyserv->t_accept);
|
||||
close(vtyserv->sock);
|
||||
XFREE(MTYPE_VTY_SERV, vtyserv);
|
||||
}
|
||||
|
||||
vtyservs_fini(vty_servs);
|
||||
vtyservs_init(vty_servs);
|
||||
vty_serv_stop();
|
||||
}
|
||||
|
@ -385,7 +385,8 @@ extern bool vty_read_config(struct nb_config *config, const char *config_file,
|
||||
extern void vty_read_file(struct nb_config *config, FILE *confp);
|
||||
extern void vty_read_file_finish(struct vty *vty, struct nb_config *config);
|
||||
extern void vty_time_print(struct vty *, int);
|
||||
extern void vty_serv_sock(const char *, unsigned short, const char *);
|
||||
extern void vty_serv_start(const char *, unsigned short, const char *);
|
||||
extern void vty_serv_stop(void);
|
||||
extern void vty_close(struct vty *);
|
||||
extern char *vty_get_cwd(void);
|
||||
extern void vty_update_xpath(const char *oldpath, const char *newpath);
|
||||
|
@ -216,7 +216,10 @@ FRR_DAEMON_INFO(mgmtd, MGMTD, .vty_port = MGMTD_VTY_PORT,
|
||||
.signals = mgmt_signals, .n_signals = array_size(mgmt_signals),
|
||||
|
||||
.privs = &mgmt_privs, .yang_modules = mgmt_yang_modules,
|
||||
.n_yang_modules = array_size(mgmt_yang_modules));
|
||||
.n_yang_modules = array_size(mgmt_yang_modules),
|
||||
|
||||
/* avoid libfrr trying to read our config file for us */
|
||||
.flags = FRR_MANUAL_VTY_START);
|
||||
|
||||
#define DEPRECATED_OPTIONS ""
|
||||
|
||||
|
@ -152,7 +152,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
/* Create VTY socket */
|
||||
vty_serv_sock(vty_addr, vty_port, "/tmp/.heavy.sock");
|
||||
vty_serv_start(vty_addr, vty_port, "/tmp/.heavy.sock");
|
||||
|
||||
/* Configuration file read*/
|
||||
if (!config_file)
|
||||
|
Loading…
Reference in New Issue
Block a user