mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-04-30 04:42:58 +00:00
ldpd: add ctl_socket cli option to override the compiled-in location for the control socket
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
This commit is contained in:
parent
f38e9e49f5
commit
372b8bd381
@ -51,28 +51,28 @@ control_init(void)
|
|||||||
|
|
||||||
memset(&s_un, 0, sizeof(s_un));
|
memset(&s_un, 0, sizeof(s_un));
|
||||||
s_un.sun_family = AF_UNIX;
|
s_un.sun_family = AF_UNIX;
|
||||||
strlcpy(s_un.sun_path, LDPD_SOCKET, sizeof(s_un.sun_path));
|
strlcpy(s_un.sun_path, ctl_sock_path, sizeof(s_un.sun_path));
|
||||||
|
|
||||||
if (unlink(LDPD_SOCKET) == -1)
|
if (unlink(ctl_sock_path) == -1)
|
||||||
if (errno != ENOENT) {
|
if (errno != ENOENT) {
|
||||||
log_warn("%s: unlink %s", __func__, LDPD_SOCKET);
|
log_warn("%s: unlink %s", __func__, ctl_sock_path);
|
||||||
close(fd);
|
close(fd);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
old_umask = umask(S_IXUSR|S_IXGRP|S_IWOTH|S_IROTH|S_IXOTH);
|
old_umask = umask(S_IXUSR|S_IXGRP|S_IWOTH|S_IROTH|S_IXOTH);
|
||||||
if (bind(fd, (struct sockaddr *)&s_un, sizeof(s_un)) == -1) {
|
if (bind(fd, (struct sockaddr *)&s_un, sizeof(s_un)) == -1) {
|
||||||
log_warn("%s: bind: %s", __func__, LDPD_SOCKET);
|
log_warn("%s: bind: %s", __func__, ctl_sock_path);
|
||||||
close(fd);
|
close(fd);
|
||||||
umask(old_umask);
|
umask(old_umask);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
umask(old_umask);
|
umask(old_umask);
|
||||||
|
|
||||||
if (chmod(LDPD_SOCKET, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) == -1) {
|
if (chmod(ctl_sock_path, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) == -1) {
|
||||||
log_warn("%s: chmod", __func__);
|
log_warn("%s: chmod", __func__);
|
||||||
close(fd);
|
close(fd);
|
||||||
(void)unlink(LDPD_SOCKET);
|
(void)unlink(ctl_sock_path);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ control_cleanup(void)
|
|||||||
{
|
{
|
||||||
accept_del(control_fd);
|
accept_del(control_fd);
|
||||||
close(control_fd);
|
close(control_fd);
|
||||||
unlink(LDPD_SOCKET);
|
unlink(ctl_sock_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ARGSUSED */
|
/* ARGSUSED */
|
||||||
|
@ -405,9 +405,9 @@ ldp_vty_connect(struct imsgbuf *ibuf)
|
|||||||
|
|
||||||
memset(&s_un, 0, sizeof(s_un));
|
memset(&s_un, 0, sizeof(s_un));
|
||||||
s_un.sun_family = AF_UNIX;
|
s_un.sun_family = AF_UNIX;
|
||||||
strlcpy(s_un.sun_path, LDPD_SOCKET, sizeof(s_un.sun_path));
|
strlcpy(s_un.sun_path, ctl_sock_path, sizeof(s_un.sun_path));
|
||||||
if (connect(ctl_sock, (struct sockaddr *)&s_un, sizeof(s_un)) == -1) {
|
if (connect(ctl_sock, (struct sockaddr *)&s_un, sizeof(s_un)) == -1) {
|
||||||
log_warn("%s: connect: %s", __func__, LDPD_SOCKET);
|
log_warn("%s: connect: %s", __func__, ctl_sock_path);
|
||||||
close(ctl_sock);
|
close(ctl_sock);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
43
ldpd/ldpd.c
43
ldpd/ldpd.c
@ -43,7 +43,7 @@
|
|||||||
|
|
||||||
static void ldpd_shutdown(void);
|
static void ldpd_shutdown(void);
|
||||||
static pid_t start_child(enum ldpd_process, char *, int,
|
static pid_t start_child(enum ldpd_process, char *, int,
|
||||||
const char *, const char *);
|
const char *, const char *, const char *);
|
||||||
static int main_dispatch_ldpe(struct thread *);
|
static int main_dispatch_ldpe(struct thread *);
|
||||||
static int main_dispatch_lde(struct thread *);
|
static int main_dispatch_lde(struct thread *);
|
||||||
static int main_imsg_send_ipc_sockets(struct imsgbuf *,
|
static int main_imsg_send_ipc_sockets(struct imsgbuf *,
|
||||||
@ -118,8 +118,12 @@ struct zebra_privs_t ldpd_privs =
|
|||||||
/* VTY Socket prefix */
|
/* VTY Socket prefix */
|
||||||
char vty_sock_path[MAXPATHLEN] = LDP_VTYSH_PATH;
|
char vty_sock_path[MAXPATHLEN] = LDP_VTYSH_PATH;
|
||||||
|
|
||||||
|
/* CTL Socket path */
|
||||||
|
char ctl_sock_path[MAXPATHLEN] = LDPD_SOCKET;
|
||||||
|
|
||||||
/* LDPd options. */
|
/* LDPd options. */
|
||||||
#define OPTION_VTYSOCK 1000
|
#define OPTION_VTYSOCK 1000
|
||||||
|
#define OPTION_CTLSOCK 1001
|
||||||
static struct option longopts[] =
|
static struct option longopts[] =
|
||||||
{
|
{
|
||||||
{ "daemon", no_argument, NULL, 'd'},
|
{ "daemon", no_argument, NULL, 'd'},
|
||||||
@ -131,6 +135,7 @@ static struct option longopts[] =
|
|||||||
{ "vty_addr", required_argument, NULL, 'A'},
|
{ "vty_addr", required_argument, NULL, 'A'},
|
||||||
{ "vty_port", required_argument, NULL, 'P'},
|
{ "vty_port", required_argument, NULL, 'P'},
|
||||||
{ "vty_socket", required_argument, NULL, OPTION_VTYSOCK},
|
{ "vty_socket", required_argument, NULL, OPTION_VTYSOCK},
|
||||||
|
{ "ctl_socket", required_argument, NULL, OPTION_CTLSOCK},
|
||||||
{ "user", required_argument, NULL, 'u'},
|
{ "user", required_argument, NULL, 'u'},
|
||||||
{ "group", required_argument, NULL, 'g'},
|
{ "group", required_argument, NULL, 'g'},
|
||||||
{ "version", no_argument, NULL, 'v'},
|
{ "version", no_argument, NULL, 'v'},
|
||||||
@ -154,6 +159,7 @@ Daemon which manages LDP.\n\n\
|
|||||||
-A, --vty_addr Set vty's bind address\n\
|
-A, --vty_addr Set vty's bind address\n\
|
||||||
-P, --vty_port Set vty's port number\n\
|
-P, --vty_port Set vty's port number\n\
|
||||||
--vty_socket Override vty socket path\n\
|
--vty_socket Override vty socket path\n\
|
||||||
|
--ctl_socket Override ctl socket path\n\
|
||||||
-u, --user User to run as\n\
|
-u, --user User to run as\n\
|
||||||
-g, --group Group to run as\n\
|
-g, --group Group to run as\n\
|
||||||
-v, --version Print program version\n\
|
-v, --version Print program version\n\
|
||||||
@ -219,6 +225,8 @@ main(int argc, char *argv[])
|
|||||||
char *vty_addr = NULL;
|
char *vty_addr = NULL;
|
||||||
int vty_port = LDP_VTY_PORT;
|
int vty_port = LDP_VTY_PORT;
|
||||||
char *vty_sock_name;
|
char *vty_sock_name;
|
||||||
|
char *ctl_sock_custom_path = NULL;
|
||||||
|
char *ctl_sock_name;
|
||||||
int daemon_mode = 0;
|
int daemon_mode = 0;
|
||||||
const char *user = NULL;
|
const char *user = NULL;
|
||||||
const char *group = NULL;
|
const char *group = NULL;
|
||||||
@ -282,6 +290,25 @@ main(int argc, char *argv[])
|
|||||||
case OPTION_VTYSOCK:
|
case OPTION_VTYSOCK:
|
||||||
set_socket_path(vty_sock_path, LDP_VTYSH_PATH, optarg, sizeof (vty_sock_path));
|
set_socket_path(vty_sock_path, LDP_VTYSH_PATH, optarg, sizeof (vty_sock_path));
|
||||||
break;
|
break;
|
||||||
|
case OPTION_CTLSOCK:
|
||||||
|
ctl_sock_name = strrchr(LDPD_SOCKET, '/');
|
||||||
|
if (ctl_sock_name)
|
||||||
|
/* skip '/' */
|
||||||
|
ctl_sock_name++;
|
||||||
|
else
|
||||||
|
/*
|
||||||
|
* LDPD_SOCKET configured as relative path
|
||||||
|
* during config? Should really never happen for
|
||||||
|
* sensible config
|
||||||
|
*/
|
||||||
|
ctl_sock_name = (char *)LDPD_SOCKET;
|
||||||
|
ctl_sock_custom_path = optarg;
|
||||||
|
strlcpy(ctl_sock_path, ctl_sock_custom_path,
|
||||||
|
sizeof(ctl_sock_path));
|
||||||
|
strlcat(ctl_sock_path, "/", sizeof(ctl_sock_path));
|
||||||
|
strlcat(ctl_sock_path, ctl_sock_name,
|
||||||
|
sizeof(ctl_sock_path));
|
||||||
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
user = optarg;
|
user = optarg;
|
||||||
break;
|
break;
|
||||||
@ -328,7 +355,7 @@ main(int argc, char *argv[])
|
|||||||
if (lflag)
|
if (lflag)
|
||||||
lde(user, group);
|
lde(user, group);
|
||||||
else if (eflag)
|
else if (eflag)
|
||||||
ldpe(user, group);
|
ldpe(user, group, ctl_sock_path);
|
||||||
|
|
||||||
master = thread_master_create();
|
master = thread_master_create();
|
||||||
|
|
||||||
@ -370,9 +397,9 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
/* start children */
|
/* start children */
|
||||||
lde_pid = start_child(PROC_LDE_ENGINE, saved_argv0,
|
lde_pid = start_child(PROC_LDE_ENGINE, saved_argv0,
|
||||||
pipe_parent2lde[1], user, group);
|
pipe_parent2lde[1], user, group, ctl_sock_custom_path);
|
||||||
ldpe_pid = start_child(PROC_LDP_ENGINE, saved_argv0,
|
ldpe_pid = start_child(PROC_LDP_ENGINE, saved_argv0,
|
||||||
pipe_parent2ldpe[1], user, group);
|
pipe_parent2ldpe[1], user, group, ctl_sock_custom_path);
|
||||||
|
|
||||||
/* drop privileges */
|
/* drop privileges */
|
||||||
if (user)
|
if (user)
|
||||||
@ -468,9 +495,9 @@ ldpd_shutdown(void)
|
|||||||
|
|
||||||
static pid_t
|
static pid_t
|
||||||
start_child(enum ldpd_process p, char *argv0, int fd, const char *user,
|
start_child(enum ldpd_process p, char *argv0, int fd, const char *user,
|
||||||
const char *group)
|
const char *group, const char *ctl_sock_custom_path)
|
||||||
{
|
{
|
||||||
char *argv[7];
|
char *argv[9];
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
||||||
@ -506,6 +533,10 @@ start_child(enum ldpd_process p, char *argv0, int fd, const char *user,
|
|||||||
argv[argc++] = (char *)"-g";
|
argv[argc++] = (char *)"-g";
|
||||||
argv[argc++] = (char *)group;
|
argv[argc++] = (char *)group;
|
||||||
}
|
}
|
||||||
|
if (ctl_sock_custom_path) {
|
||||||
|
argv[argc++] = (char *)"--ctl_socket";
|
||||||
|
argv[argc++] = (char *)ctl_sock_custom_path;
|
||||||
|
}
|
||||||
argv[argc++] = NULL;
|
argv[argc++] = NULL;
|
||||||
|
|
||||||
execvp(argv0, argv);
|
execvp(argv0, argv);
|
||||||
|
@ -672,6 +672,7 @@ int sock_set_ipv6_mcast_loop(int);
|
|||||||
|
|
||||||
/* quagga */
|
/* quagga */
|
||||||
extern struct thread_master *master;
|
extern struct thread_master *master;
|
||||||
|
extern char ctl_sock_path[MAXPATHLEN];
|
||||||
|
|
||||||
/* ldp_zebra.c */
|
/* ldp_zebra.c */
|
||||||
void ldp_zebra_init(struct thread_master *);
|
void ldp_zebra_init(struct thread_master *);
|
||||||
|
@ -99,7 +99,7 @@ static struct quagga_signal_t ldpe_signals[] =
|
|||||||
|
|
||||||
/* label distribution protocol engine */
|
/* label distribution protocol engine */
|
||||||
void
|
void
|
||||||
ldpe(const char *user, const char *group)
|
ldpe(const char *user, const char *group, const char *ctl_path)
|
||||||
{
|
{
|
||||||
struct thread thread;
|
struct thread thread;
|
||||||
|
|
||||||
@ -128,6 +128,7 @@ ldpe(const char *user, const char *group)
|
|||||||
ldpe_privs.group = group;
|
ldpe_privs.group = group;
|
||||||
zprivs_init(&ldpe_privs);
|
zprivs_init(&ldpe_privs);
|
||||||
|
|
||||||
|
strlcpy(ctl_sock_path, ctl_path, sizeof(ctl_sock_path));
|
||||||
if (control_init() == -1)
|
if (control_init() == -1)
|
||||||
fatalx("control socket setup failed");
|
fatalx("control socket setup failed");
|
||||||
|
|
||||||
|
@ -183,7 +183,7 @@ int tlv_decode_fec_elm(struct nbr *, struct ldp_msg *, char *,
|
|||||||
uint16_t, struct map *);
|
uint16_t, struct map *);
|
||||||
|
|
||||||
/* ldpe.c */
|
/* ldpe.c */
|
||||||
void ldpe(const char *, const char *);
|
void ldpe(const char *, const char *, const char *);
|
||||||
int ldpe_imsg_compose_parent(int, pid_t, void *,
|
int ldpe_imsg_compose_parent(int, pid_t, void *,
|
||||||
uint16_t);
|
uint16_t);
|
||||||
int ldpe_imsg_compose_lde(int, uint32_t, pid_t, void *,
|
int ldpe_imsg_compose_lde(int, uint32_t, pid_t, void *,
|
||||||
|
Loading…
Reference in New Issue
Block a user