#define _ZEBRA_VTY_H
#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
{
/* File descripter of this vty. */
int fd;
+ /* output FD, to support stdin/stdout combination */
+ int wfd;
+
/* Is this vty connect to file or not */
enum {VTY_TERM, VTY_FILE, VTY_SHELL, VTY_SHELL_SERV} type;
/* Node status of this vty */
int node;
- /* What address is this vty comming from. */
- char *address;
-
/* Failure count */
int fail;
/* Command input buffer */
char *buf;
+ /* Command input error buffer */
+ char *error_buf;
+
/* Command cursor point */
int cp;
/* 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;
/* Timeout seconds and thread. */
unsigned long v_timeout;
struct thread *t_timeout;
+
+ /* What address is this vty comming from. */
+ 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;
+ const char *value;
+ const char **argv;
+ int argc;
};
/* Integrated configuration file. */
#define PRINTF_ATTRIBUTE(a,b)
#endif /* __GNUC__ */
-/* Utility macros to convert VTY argument to unsigned long or integer. */
-#define VTY_GET_LONG(NAME,V,STR) \
-{ \
+/* Utility macros to convert VTY argument to unsigned long */
+#define VTY_GET_ULONG(NAME,V,STR) \
+do { \
char *endptr = NULL; \
+ errno = 0; \
(V) = strtoul ((STR), &endptr, 10); \
- if (*endptr != '\0' || (V) == ULONG_MAX) \
+ if (*(STR) == '-') \
{ \
- vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \
+ vty_out (vty, "%% Invalid %s value (dash)%s", NAME, VTY_NEWLINE); \
return CMD_WARNING; \
} \
-}
-
-#define VTY_GET_INTEGER_RANGE(NAME,V,STR,MIN,MAX) \
-{ \
- unsigned long tmpl; \
- VTY_GET_LONG(NAME, tmpl, STR) \
- if ( tmpl < (MIN) || tmpl > (MAX)) \
+ if (*endptr != '\0') \
{ \
- vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \
+ vty_out (vty, "%% Invalid %s value (%s)%s", NAME, endptr, VTY_NEWLINE); \
return CMD_WARNING; \
} \
- (V) = tmpl; \
-}
+ if (errno) \
+ { \
+ vty_out (vty, "%% Invalid %s value (error %d)%s", NAME, errno, VTY_NEWLINE); \
+ return CMD_WARNING; \
+ } \
+} while (0)
-#define VTY_GET_INTEGER(NAME,V,STR) \
- VTY_GET_INTEGER_RANGE(NAME,V,STR,0U,UINT32_MAX)
+/* Utility macros to convert VTY argument to unsigned long long */
+#define VTY_GET_ULL(NAME,V,STR) \
+do { \
+ char *endptr = NULL; \
+ errno = 0; \
+ (V) = strtoull ((STR), &endptr, 10); \
+ if (*(STR) == '-') \
+ { \
+ vty_out (vty, "%% Invalid %s value (dash)%s", NAME, VTY_NEWLINE); \
+ return CMD_WARNING; \
+ } \
+ if (*endptr != '\0') \
+ { \
+ vty_out (vty, "%% Invalid %s value (%s)%s", NAME, endptr, VTY_NEWLINE); \
+ return CMD_WARNING; \
+ } \
+ if (errno) \
+ { \
+ vty_out (vty, "%% Invalid %s value (error %d)%s", NAME, errno, VTY_NEWLINE); \
+ return CMD_WARNING; \
+ } \
+} while (0)
+
+/*
+ * The logic below ((TMPL) <= ((MIN) && (TMPL) != (MIN)) is
+ * done to circumvent the compiler complaining about
+ * comparing unsigned numbers against zero, if MIN is zero.
+ * NB: The compiler isn't smart enough to supress the warning
+ * if you write (MIN) != 0 && tmpl < (MIN).
+ */
+#define VTY_GET_INTEGER_RANGE_HEART(NAME,TMPL,STR,MIN,MAX) \
+do { \
+ VTY_GET_ULONG(NAME, (TMPL), STR); \
+ if ( ((TMPL) <= (MIN) && (TMPL) != (MIN)) || (TMPL) > (MAX) ) \
+ { \
+ vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE);\
+ return CMD_WARNING; \
+ } \
+} while (0)
+
+#define VTY_GET_INTEGER_RANGE(NAME,V,STR,MIN,MAX) \
+do { \
+ unsigned long long tmpl; \
+ VTY_GET_INTEGER_RANGE_HEART(NAME,tmpl,STR,MIN,MAX); \
+ (V) = tmpl; \
+} while (0)
+
+#define VTY_CHECK_INTEGER_RANGE(NAME,STR,MIN,MAX) \
+do { \
+ unsigned long tmpl; \
+ VTY_GET_INTEGER_RANGE_HEART(NAME,tmpl,STR,MIN,MAX); \
+} while (0)
+
+#define VTY_GET_INTEGER(NAME,V,STR) \
+ VTY_GET_INTEGER_RANGE(NAME,V,STR,0U,UINT32_MAX)
+
+#define VTY_GET_IPV4_ADDRESS(NAME,V,STR) \
+do { \
+ int retv; \
+ retv = inet_aton ((STR), &(V)); \
+ if (!retv) \
+ { \
+ vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \
+ return CMD_WARNING; \
+ } \
+} while (0)
+
+#define VTY_GET_IPV4_PREFIX(NAME,V,STR) \
+do { \
+ int retv; \
+ retv = str2prefix_ipv4 ((STR), &(V)); \
+ if (retv <= 0) \
+ { \
+ vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \
+ return CMD_WARNING; \
+ } \
+} while (0)
+
+#define VTY_WARN_EXPERIMENTAL() \
+do { \
+ vty_out (vty, "%% WARNING: this command is experimental. Both its name and" \
+ " parameters may%s%% change in a future version of Quagga," \
+ " possibly breaking your configuration!%s", \
+ VTY_NEWLINE, VTY_NEWLINE); \
+} while (0)
/* Exported variables */
extern char integrate_default[];
/* Prototypes. */
-void vty_init (struct thread_master *);
-void vty_init_vtysh (void);
-void vty_reset (void);
-void vty_finish (void);
-struct vty *vty_new (void);
-int vty_out (struct vty *, const char *, ...) PRINTF_ATTRIBUTE(2, 3);
-void vty_read_config (char *, char *);
-void vty_time_print (struct vty *, int);
-void vty_serv_sock (const char *, unsigned short, const char *);
-void vty_close (struct vty *);
-char *vty_get_cwd (void);
-void vty_log (const char *level, const char *proto, const char *fmt, va_list);
-int vty_config_lock (struct vty *);
-int vty_config_unlock (struct vty *);
-int vty_shell (struct vty *);
-int vty_shell_serv (struct vty *);
-void vty_hello (struct vty *);
+extern void vty_init (struct thread_master *);
+extern void vty_init_vtysh (void);
+extern void vty_terminate (void);
+extern void vty_reset (void);
+extern struct vty *vty_new (void);
+extern struct vty *vty_stdio (void (*atclose)(void));
+extern int vty_out (struct vty *, const char *, ...) PRINTF_ATTRIBUTE(2, 3);
+extern void vty_read_config (char *, char *);
+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 int vty_shell (struct vty *);
+extern int vty_shell_serv (struct vty *);
+extern void vty_hello (struct vty *);
/* Send a fixed-size message to all vty terminal monitors; this should be
an async-signal-safe function. */
-extern void vty_log_fixed (const char *buf, size_t len);
+extern void vty_log_fixed (char *buf, size_t len);
+
+extern const char *vty_get_arg_value (struct vty_arg **, const char *);
+extern struct vty_arg *vty_get_arg (struct vty_arg **, const char *);
#endif /* _ZEBRA_VTY_H */