]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib: vty: add infrastructure for qobj ID "index"
authorDavid Lamparter <equinox@opensourcerouting.org>
Mon, 26 Sep 2016 16:36:49 +0000 (18:36 +0200)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Fri, 7 Oct 2016 13:09:51 +0000 (09:09 -0400)
As mentioned in previous commits, this prepares to replace the vty's
"void *index" context position with a safe qobj pointer.  This will
allow concurrent configuration editing by multiple users, as soon as no
more code (library included) in the daemon uses vty->index anymore.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
lib/vty.h

index 4f1dbe653ec89b967c4b4fe696e151395a3b1ca1..ba68ecb7e133dc1193ab593f21689c8c03b7c2dc 100644 (file)
--- a/lib/vty.h
+++ b/lib/vty.h
@@ -24,10 +24,18 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 #include "thread.h"
 #include "log.h"
 #include "sockunion.h"
+#include "qobj.h"
 
 #define VTY_BUFSIZ 512
 #define VTY_MAXHIST 20
 
+#if defined(VTY_DEPRECATE_INDEX) && defined(__GNUC__) && \
+    (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
+#define INDEX_WARNING __attribute__((deprecated))
+#else
+#define INDEX_WARNING
+#endif
+
 /* VTY struct. */
 struct vty 
 {
@@ -75,7 +83,10 @@ struct vty
 
   /* For current referencing point of interface, route-map,
      access-list etc... */
-  void *index;
+  void *index INDEX_WARNING;
+
+  /* qobj object ID (replacement for "index") */
+  uint64_t qobj_index;
 
   /* For multiple level index treatment such as key chain and key. */
   void *index_sub;
@@ -127,6 +138,46 @@ struct vty
   char address[SU_ADDRSTRLEN];
 };
 
+#undef INDEX_WARNING
+
+static inline void vty_push_context(struct vty *vty,
+                                    int node, uint64_t id, void *idx)
+{
+  vty->node = node;
+  vty->qobj_index = id;
+#if defined(VTY_DEPRECATE_INDEX) && defined(__GNUC__) && \
+    (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+  vty->index = idx;
+#pragma GCC diagnostic pop
+#else
+  vty->index = idx;
+#endif
+}
+
+#define VTY_PUSH_CONTEXT(nodeval, ptr) \
+       vty_push_context(vty, nodeval, QOBJ_ID(ptr), NULL)
+#define VTY_PUSH_CONTEXT_COMPAT(nodeval, ptr) \
+       vty_push_context(vty, nodeval, QOBJ_ID(ptr), ptr)
+
+/* can return NULL if context is invalid! */
+#define VTY_GET_CONTEXT(structname) \
+       QOBJ_GET_TYPESAFE(vty->qobj_index, structname)
+
+/* will return if ptr is NULL. */
+#define VTY_CHECK_CONTEXT(ptr) \
+       if (!ptr) { \
+               vty_out (vty, "Current configuration object was deleted " \
+                               "by another process.%s", VTY_NEWLINE); \
+               return CMD_WARNING; \
+       }
+
+/* struct structname *ptr = <context>;   ptr will never be NULL. */
+#define VTY_DECLVAR_CONTEXT(structname, ptr) \
+       struct structname *ptr = VTY_GET_CONTEXT(structname); \
+       VTY_CHECK_CONTEXT(ptr);
+
 struct vty_arg
 {
   const char *name;