From 7991dc323e9c06b0fa2f70bb2ff2c7694f5b6e93 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Tue, 3 Oct 2017 10:24:45 -0300 Subject: [PATCH 1/4] ldpd: fix wrong indentation in the help menu The -n option was not aligned with the other ones: % ldpd --help [snip] -A, --vty_addr Set vty's bind address -P, --vty_port Set vty's port number --ctl_socket Override ctl socket path -n, --instance Instance id Signed-off-by: Renato Westphal --- ldpd/ldpd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ldpd/ldpd.c b/ldpd/ldpd.c index d31c575920..95cd4ba366 100644 --- a/ldpd/ldpd.c +++ b/ldpd/ldpd.c @@ -206,7 +206,7 @@ main(int argc, char *argv[]) frr_preinit(&ldpd_di, argc, argv); frr_opt_add("LEn:", longopts, " --ctl_socket Override ctl socket path\n" - "-n, --instance Instance id\n"); + " -n, --instance Instance id\n"); while (1) { int opt; From 16cd3d9d4a393f504608445a631c87bef6e83cfa Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Tue, 3 Oct 2017 10:27:05 -0300 Subject: [PATCH 2/4] ldpd: remove the "discovery targeted-hello" commands from the interface node These commands belong only in the global LDP node and in the LDP address-family nodes. Signed-off-by: Renato Westphal --- ldpd/ldp_vty.h | 4 +-- ldpd/ldp_vty_cmds.c | 64 ++++++++++++++++++++++++++++++++------------- ldpd/ldp_vty_conf.c | 19 +++----------- 3 files changed, 51 insertions(+), 36 deletions(-) diff --git a/ldpd/ldp_vty.h b/ldpd/ldp_vty.h index 3d2072f1e5..baf9db51d4 100644 --- a/ldpd/ldp_vty.h +++ b/ldpd/ldp_vty.h @@ -38,8 +38,8 @@ int ldp_l2vpn_config_write(struct vty *); int ldp_debug_config_write(struct vty *); int ldp_vty_mpls_ldp (struct vty *, const char *); int ldp_vty_address_family (struct vty *, const char *, const char *); -int ldp_vty_disc_holdtime(struct vty *, const char *, const char *, long); -int ldp_vty_disc_interval(struct vty *, const char *, const char *, long); +int ldp_vty_disc_holdtime(struct vty *, const char *, enum hello_type, long); +int ldp_vty_disc_interval(struct vty *, const char *, enum hello_type, long); int ldp_vty_targeted_hello_accept(struct vty *, const char *, const char *); int ldp_vty_nbr_session_holdtime(struct vty *, const char *, struct in_addr, long); int ldp_vty_af_session_holdtime(struct vty *, const char *, long); diff --git a/ldpd/ldp_vty_cmds.c b/ldpd/ldp_vty_cmds.c index cd92958d4c..00151a4d99 100644 --- a/ldpd/ldp_vty_cmds.c +++ b/ldpd/ldp_vty_cmds.c @@ -112,30 +112,52 @@ DEFUN_NOSH(ldp_exit_address_family, return CMD_SUCCESS; } -DEFPY (ldp_discovery_holdtime, - ldp_discovery_holdtime_cmd, - "[no] discovery $hello_type holdtime (1-65535)$holdtime", +DEFPY (ldp_discovery_link_holdtime, + ldp_discovery_link_holdtime_cmd, + "[no] discovery hello holdtime (1-65535)$holdtime", NO_STR "Configure discovery parameters\n" "LDP Link Hellos\n" + "Hello holdtime\n" + "Time (seconds) - 65535 implies infinite\n") +{ + return (ldp_vty_disc_holdtime(vty, no, HELLO_LINK, holdtime)); +} + +DEFPY (ldp_discovery_targeted_holdtime, + ldp_discovery_targeted_holdtime_cmd, + "[no] discovery targeted-hello holdtime (1-65535)$holdtime", + NO_STR + "Configure discovery parameters\n" "LDP Targeted Hellos\n" "Hello holdtime\n" "Time (seconds) - 65535 implies infinite\n") { - return (ldp_vty_disc_holdtime(vty, no, hello_type, holdtime)); + return (ldp_vty_disc_holdtime(vty, no, HELLO_TARGETED, holdtime)); } -DEFPY (ldp_discovery_interval, - ldp_discovery_interval_cmd, - "[no] discovery $hello_type interval (1-65535)$interval", +DEFPY (ldp_discovery_link_interval, + ldp_discovery_link_interval_cmd, + "[no] discovery hello interval (1-65535)$interval", NO_STR "Configure discovery parameters\n" "LDP Link Hellos\n" + "Hello interval\n" + "Time (seconds)\n") +{ + return (ldp_vty_disc_interval(vty, no, HELLO_LINK, interval)); +} + +DEFPY (ldp_discovery_targeted_interval, + ldp_discovery_targeted_interval_cmd, + "[no] discovery targeted-hello interval (1-65535)$interval", + NO_STR + "Configure discovery parameters\n" "LDP Targeted Hellos\n" "Hello interval\n" "Time (seconds)\n") { - return (ldp_vty_disc_interval(vty, no, hello_type, interval)); + return (ldp_vty_disc_interval(vty, no, HELLO_TARGETED, interval)); } DEFPY (ldp_dual_stack_transport_connection_prefer_ipv4, @@ -747,8 +769,10 @@ ldp_vty_init (void) install_element(LDP_NODE, &ldp_address_family_cmd); install_element(LDP_NODE, &no_ldp_address_family_cmd); - install_element(LDP_NODE, &ldp_discovery_holdtime_cmd); - install_element(LDP_NODE, &ldp_discovery_interval_cmd); + install_element(LDP_NODE, &ldp_discovery_link_holdtime_cmd); + install_element(LDP_NODE, &ldp_discovery_targeted_holdtime_cmd); + install_element(LDP_NODE, &ldp_discovery_link_interval_cmd); + install_element(LDP_NODE, &ldp_discovery_targeted_interval_cmd); install_element(LDP_NODE, &ldp_dual_stack_transport_connection_prefer_ipv4_cmd); install_element(LDP_NODE, &ldp_dual_stack_cisco_interop_cmd); install_element(LDP_NODE, &ldp_neighbor_password_cmd); @@ -756,8 +780,10 @@ ldp_vty_init (void) install_element(LDP_NODE, &ldp_neighbor_ttl_security_cmd); install_element(LDP_NODE, &ldp_router_id_cmd); - install_element(LDP_IPV4_NODE, &ldp_discovery_holdtime_cmd); - install_element(LDP_IPV4_NODE, &ldp_discovery_interval_cmd); + install_element(LDP_IPV4_NODE, &ldp_discovery_link_holdtime_cmd); + install_element(LDP_IPV4_NODE, &ldp_discovery_targeted_holdtime_cmd); + install_element(LDP_IPV4_NODE, &ldp_discovery_link_interval_cmd); + install_element(LDP_IPV4_NODE, &ldp_discovery_targeted_interval_cmd); install_element(LDP_IPV4_NODE, &ldp_discovery_targeted_hello_accept_cmd); install_element(LDP_IPV4_NODE, &ldp_discovery_transport_address_ipv4_cmd); install_element(LDP_IPV4_NODE, &ldp_label_local_advertise_cmd); @@ -771,8 +797,10 @@ ldp_vty_init (void) install_element(LDP_IPV4_NODE, &ldp_neighbor_ipv4_targeted_cmd); install_element(LDP_IPV4_NODE, &ldp_exit_address_family_cmd); - install_element(LDP_IPV6_NODE, &ldp_discovery_holdtime_cmd); - install_element(LDP_IPV6_NODE, &ldp_discovery_interval_cmd); + install_element(LDP_IPV6_NODE, &ldp_discovery_link_holdtime_cmd); + install_element(LDP_IPV6_NODE, &ldp_discovery_targeted_holdtime_cmd); + install_element(LDP_IPV6_NODE, &ldp_discovery_link_interval_cmd); + install_element(LDP_IPV6_NODE, &ldp_discovery_targeted_interval_cmd); install_element(LDP_IPV6_NODE, &ldp_discovery_targeted_hello_accept_cmd); install_element(LDP_IPV6_NODE, &ldp_discovery_transport_address_ipv6_cmd); install_element(LDP_IPV6_NODE, &ldp_label_local_advertise_cmd); @@ -785,11 +813,11 @@ ldp_vty_init (void) install_element(LDP_IPV6_NODE, &ldp_neighbor_ipv6_targeted_cmd); install_element(LDP_IPV6_NODE, &ldp_exit_address_family_cmd); - install_element(LDP_IPV4_IFACE_NODE, &ldp_discovery_holdtime_cmd); - install_element(LDP_IPV4_IFACE_NODE, &ldp_discovery_interval_cmd); + install_element(LDP_IPV4_IFACE_NODE, &ldp_discovery_link_holdtime_cmd); + install_element(LDP_IPV4_IFACE_NODE, &ldp_discovery_link_interval_cmd); - install_element(LDP_IPV6_IFACE_NODE, &ldp_discovery_holdtime_cmd); - install_element(LDP_IPV6_IFACE_NODE, &ldp_discovery_interval_cmd); + install_element(LDP_IPV6_IFACE_NODE, &ldp_discovery_link_holdtime_cmd); + install_element(LDP_IPV6_IFACE_NODE, &ldp_discovery_link_interval_cmd); install_element(LDP_L2VPN_NODE, &ldp_bridge_cmd); install_element(LDP_L2VPN_NODE, &ldp_mtu_cmd); diff --git a/ldpd/ldp_vty_conf.c b/ldpd/ldp_vty_conf.c index e938582d0d..f43370af2b 100644 --- a/ldpd/ldp_vty_conf.c +++ b/ldpd/ldp_vty_conf.c @@ -459,20 +459,13 @@ ldp_vty_address_family(struct vty *vty, const char *negate, const char *af_str) return (CMD_SUCCESS); } -int -ldp_vty_disc_holdtime(struct vty *vty, const char *negate, - const char *hello_type_str, long secs) +int ldp_vty_disc_holdtime(struct vty *vty, const char *negate, + enum hello_type hello_type, long secs) { struct ldpd_af_conf *af_conf; struct iface *iface; struct iface_af *ia; int af; - enum hello_type hello_type; - - if (hello_type_str[0] == 'h') - hello_type = HELLO_LINK; - else - hello_type = HELLO_TARGETED; switch (vty->node) { case LDP_NODE: @@ -547,18 +540,12 @@ ldp_vty_disc_holdtime(struct vty *vty, const char *negate, int ldp_vty_disc_interval(struct vty *vty, const char *negate, - const char *hello_type_str, long secs) + enum hello_type hello_type, long secs) { struct ldpd_af_conf *af_conf; struct iface *iface; struct iface_af *ia; int af; - enum hello_type hello_type; - - if (hello_type_str[0] == 'h') - hello_type = HELLO_LINK; - else - hello_type = HELLO_TARGETED; switch (vty->node) { case LDP_NODE: From 3b2d98c58e2a5b1db6fbcd7ffb8d9f7972654b82 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Tue, 3 Oct 2017 10:30:44 -0300 Subject: [PATCH 3/4] ldpd: fix issue when displaying the running configuration More than a cosmetic fix, this should prevent issues with frr-reload.py. Before: mpls ldp router-id 1.1.1.1 ! address-family ipv4 discovery transport-address 1.1.1.1 ! interface rt1-eth0 discovery hello holdtime 10 discovery hello interval 3 exit-address-family ! ! After: mpls ldp router-id 1.1.1.1 ! address-family ipv4 discovery transport-address 1.1.1.1 ! interface rt1-eth0 discovery hello holdtime 10 discovery hello interval 3 ! exit-address-family ! ! Signed-off-by: Renato Westphal --- ldpd/ldp_vty_conf.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ldpd/ldp_vty_conf.c b/ldpd/ldp_vty_conf.c index f43370af2b..76c602afbb 100644 --- a/ldpd/ldp_vty_conf.c +++ b/ldpd/ldp_vty_conf.c @@ -233,6 +233,7 @@ ldp_af_config_write(struct vty *vty, int af, struct ldpd_conf *conf, ldp_af_iface_config_write(vty, af); + vty_out(vty, " !\n"); vty_out(vty, " exit-address-family\n"); } From 547322cb0f19b37b1a584e9e6ee867e230c648d7 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Tue, 3 Oct 2017 16:11:07 -0300 Subject: [PATCH 4/4] ldpd: detach stdin/stdout/stderr from the child processes Doing a "ssh user@node 'ldpd -d'" was making the SSH session hang. In the original OpenBSD's ldpd(8) daemon, the daemon function takes care of connecting stdin/stdout/stderr to /dev/null. In the FRR port, this only happens in the frr_run() function, after all children have been forked. Ideally we could try to rearrange libfrr.c and ldpd.c in a way that start_child() is called only after the parent connects the standard I/O streams to /dev/null. But since this issue needs an immediate fix, let's do this workaround for now. Note: even when running on the foreground, all log messages from the child processes are sent to the parent process, which then prints the messages to stdout/stderr and/or to a log file. Reported-by: Martin Winter Signed-off-by: Renato Westphal --- ldpd/ldpd.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ldpd/ldpd.c b/ldpd/ldpd.c index 95cd4ba366..a79e63229f 100644 --- a/ldpd/ldpd.c +++ b/ldpd/ldpd.c @@ -435,7 +435,7 @@ static pid_t start_child(enum ldpd_process p, char *argv0, int fd_async, int fd_sync) { char *argv[3]; - int argc = 0; + int argc = 0, nullfd; pid_t pid; switch (pid = fork()) { @@ -449,6 +449,12 @@ start_child(enum ldpd_process p, char *argv0, int fd_async, int fd_sync) return (pid); } + nullfd = open("/dev/null", O_RDONLY | O_NOCTTY); + dup2(nullfd, 0); + dup2(nullfd, 1); + dup2(nullfd, 2); + close(nullfd); + if (dup2(fd_async, LDPD_FD_ASYNC) == -1) fatal("cannot setup imsg async fd"); if (dup2(fd_sync, LDPD_FD_SYNC) == -1)