]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/vty.h
zebra, lib: fix the ZEBRA_INTERFACE_VRF_UPDATE zapi message
[mirror_frr.git] / lib / vty.h
index efe91a568b67cbc5102e6ae8924b167ae090dbb3..79b1bd5e9311aee3d44d0e3947d6f1e294e287f5 100644 (file)
--- a/lib/vty.h
+++ b/lib/vty.h
 #include "sockunion.h"
 #include "qobj.h"
 #include "compiler.h"
+#include "northbound.h"
 
 #define VTY_BUFSIZ 4096
 #define VTY_MAXHIST 20
+#define VTY_MAXDEPTH 8
+
+#define VTY_MAXCFGCHANGES 8
 
 struct vty_error {
        char error_buf[VTY_BUFSIZ];
        uint32_t line_num;
 };
 
+struct vty_cfg_change {
+       char xpath[XPATH_MAXLEN];
+       enum nb_operation operation;
+       const char *value;
+};
+
 /* VTY struct. */
 struct vty {
        /* File descripter of this vty. */
@@ -96,6 +106,30 @@ struct vty {
        /* History insert end point */
        int hindex;
 
+       /* Changes enqueued to be applied in the candidate configuration. */
+       size_t num_cfg_changes;
+       struct vty_cfg_change cfg_changes[VTY_MAXCFGCHANGES];
+
+       /* XPath of the current node */
+       int xpath_index;
+       char xpath[VTY_MAXDEPTH][XPATH_MAXLEN];
+
+       /* In configure mode. */
+       bool config;
+
+       /* Private candidate configuration mode. */
+       bool private_config;
+
+       /* Candidate configuration. */
+       struct nb_config *candidate_config;
+
+       /* Base candidate configuration. */
+       struct nb_config *candidate_config_base;
+
+       /* Confirmed-commit timeout and rollback configuration. */
+       struct thread *t_confirmed_commit_timeout;
+       struct nb_config *confirmed_commit_rollback;
+
        /* qobj object ID (replacement for "index") */
        uint64_t qobj_index;
 
@@ -134,9 +168,6 @@ struct vty {
        /* Terminal monitor. */
        int monitor;
 
-       /* In configure mode. */
-       int config;
-
        /* Read and write thread. */
        struct thread *t_read;
        struct thread *t_write;
@@ -201,6 +232,34 @@ static inline void vty_push_context(struct vty *vty, int node, uint64_t id)
        struct structname *ptr = VTY_GET_CONTEXT(structname);                  \
        VTY_CHECK_CONTEXT(ptr);
 
+/* XPath macros. */
+#define VTY_PUSH_XPATH(nodeval, value)                                         \
+       do {                                                                   \
+               if (vty->xpath_index >= VTY_MAXDEPTH) {                        \
+                       vty_out(vty, "%% Reached maximum CLI depth (%u)\n",    \
+                               VTY_MAXDEPTH);                                 \
+                       return CMD_WARNING;                                    \
+               }                                                              \
+               vty->node = nodeval;                                           \
+               strlcpy(vty->xpath[vty->xpath_index], value,                   \
+                       sizeof(vty->xpath[0]));                                \
+               vty->xpath_index++;                                            \
+       } while (0)
+
+#define VTY_CURR_XPATH vty->xpath[vty->xpath_index - 1]
+
+#define VTY_CHECK_XPATH                                                        \
+       do {                                                                   \
+               if (vty->xpath_index > 0                                       \
+                   && !yang_dnode_exists(vty->candidate_config->dnode,        \
+                                         VTY_CURR_XPATH)) {                   \
+                       vty_out(vty,                                           \
+                               "Current configuration object was deleted "    \
+                               "by another process.\n\n");                    \
+                       return CMD_WARNING;                                    \
+               }                                                              \
+       } while (0)
+
 struct vty_arg {
        const char *name;
        const char *value;
@@ -228,6 +287,7 @@ struct vty_arg {
 
 /* Exported variables */
 extern char integrate_default[];
+extern struct vty *vty_exclusive_lock;
 
 /* Prototypes. */
 extern void vty_init(struct thread_master *);
@@ -247,16 +307,19 @@ extern void vty_frame(struct vty *, const char *, ...) PRINTF_ATTRIBUTE(2, 3);
 extern void vty_endframe(struct vty *, const char *);
 bool vty_set_include(struct vty *vty, const char *regexp);
 
-extern bool vty_read_config(const char *, char *);
+extern bool vty_read_config(struct nb_config *config, const char *config_file,
+                           char *config_default_dir);
 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 *);
 extern char *vty_get_cwd(void);
 extern void vty_log(const char *level, const char *proto, const char *fmt,
                    struct timestamp_control *, va_list);
-extern int vty_config_lock(struct vty *);
-extern int vty_config_unlock(struct vty *);
-extern void vty_config_lockless(void);
+extern int vty_config_enter(struct vty *vty, bool private_config,
+                           bool exclusive);
+extern void vty_config_exit(struct vty *);
+extern int vty_config_exclusive_lock(struct vty *vty);
+extern void vty_config_exclusive_unlock(struct vty *vty);
 extern int vty_shell(struct vty *);
 extern int vty_shell_serv(struct vty *);
 extern void vty_hello(struct vty *);