]> git.proxmox.com Git - mirror_frr.git/blobdiff - watchfrr/watchfrr_vty.c
isisd: implement the 'rejected-adjacency' notification
[mirror_frr.git] / watchfrr / watchfrr_vty.c
index 64af7d7f4a59dac6f7857f665cece9e6567cc5aa..9b844d67f25d0aa427d945c51d4d7a75d52710fb 100644 (file)
@@ -1,21 +1,21 @@
 /*
   watchfrr CLI functions.
-
   Copyright (C) 2016  David Lamparter for NetDEF, Inc.
-
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
-
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
* watchfrr CLI functions.
+ *
* Copyright (C) 2016  David Lamparter for NetDEF, Inc.
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
* with this program; see the file COPYING; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #include <zebra.h>
@@ -40,12 +40,24 @@ DEFUN(config_write_integrated,
        pid_t child;
        sigset_t oldmask, sigmask;
 
+       const char *e_inprog = "Configuration write already in progress.";
+       const char *e_dmn = "Not all daemons are up, cannot write config.";
+
        if (integrated_write_pid != -1) {
-               vty_out(vty, "%% configuration write already in progress.%s",
-                       VTY_NEWLINE);
+               vty_out(vty, "%% %s\n", e_inprog);
                return CMD_WARNING;
        }
 
+       /* check that all daemons are up before clobbering config */
+       if (!check_all_up()) {
+               vty_out(vty, "%% %s\n", e_dmn);
+               /*
+                * vtysh interprets this return value to mean that it should
+                * not try to write the config itself
+                */
+               return CMD_WARNING_CONFIG_FAILED;
+       }
+
        fflush(stdout);
        fflush(stderr);
 
@@ -60,19 +72,23 @@ DEFUN(config_write_integrated,
 
        child = fork();
        if (child == -1) {
-               vty_out(vty, "%% configuration write fork() failed: %s.%s",
-                       safe_strerror(errno), VTY_NEWLINE);
+               vty_out(vty, "%% configuration write fork() failed: %s.\n",
+                       safe_strerror(errno));
                sigprocmask(SIG_SETMASK, &oldmask, NULL);
                return CMD_WARNING;
        }
        if (child != 0) {
-               /* note: the VTY won't write a command return value to vtysh;  the
-                * session temporarily enters an intentional "hang" state.  This is
+               /* note: the VTY won't write a command return value to vtysh;
+                * the
+                * session temporarily enters an intentional "hang" state.  This
+                * is
                 * to make sure latency in vtysh doing the config write (several
-                * seconds is not rare to see) does not interfere with watchfrr's
+                * seconds is not rare to see) does not interfere with
+                * watchfrr's
                 * supervisor job.
                 *
-                * The fd is duplicated here so we don't need to hold a vty pointer
+                * The fd is duplicated here so we don't need to hold a vty
+                * pointer
                 * (which could become invalid in the meantime).
                 */
                integrated_write_pid = child;
@@ -92,15 +108,35 @@ DEFUN(config_write_integrated,
 
        /* unbuffered write; we just messed with stdout... */
        char msg[512];
-       snprintf(msg, sizeof(msg), "error executing %s: %s\n",
-                VTYSH_BIN_PATH, safe_strerror(errno));
+       snprintf(msg, sizeof(msg), "error executing %s: %s\n", VTYSH_BIN_PATH,
+                safe_strerror(errno));
        write(1, msg, strlen(msg));
        exit(1);
 }
 
+DEFUN_NOSH (show_debugging_watchfrr,
+            show_debugging_watchfrr_cmd,
+            "show debugging [watchfrr]",
+            SHOW_STR
+            DEBUG_STR
+            WATCHFRR_STR)
+{
+       return CMD_SUCCESS;
+}
+
+DEFUN (show_watchfrr,
+       show_watchfrr_cmd,
+       "show watchfrr",
+       SHOW_STR
+       WATCHFRR_STR)
+{
+       watchfrr_status(vty);
+       return CMD_SUCCESS;
+}
+
 void integrated_write_sigchld(int status)
 {
-       uint8_t reply[4] = { 0, 0, 0, CMD_WARNING };
+       uint8_t reply[4] = {0, 0, 0, CMD_WARNING};
 
        if (WIFEXITED(status)) {
                zlog_info("configuration write completed with exit code %d",
@@ -131,4 +167,7 @@ void watchfrr_vty_init(void)
 {
        integrated_write_pid = -1;
        install_element(ENABLE_NODE, &config_write_integrated_cmd);
+       install_element(ENABLE_NODE, &show_debugging_watchfrr_cmd);
+       install_element(CONFIG_NODE, &show_debugging_watchfrr_cmd);
+       install_element(VIEW_NODE, &show_watchfrr_cmd);
 }