2014-06-16 08:13:40 +00:00
|
|
|
#pragma once
|
2010-05-19 17:02:52 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
2011-08-17 15:13:48 +00:00
|
|
|
/*! \defgroup vty VTY (Virtual TTY) interface
|
|
|
|
* @{
|
2017-06-20 02:35:06 +00:00
|
|
|
* \file vty.h */
|
2011-08-17 15:13:48 +00:00
|
|
|
|
2010-05-19 17:02:52 +00:00
|
|
|
/* GCC have printf type attribute check. */
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#define VTY_PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
|
|
|
|
#else
|
|
|
|
#define VTY_PRINTF_ATTRIBUTE(a,b)
|
|
|
|
#endif /* __GNUC__ */
|
|
|
|
|
|
|
|
/* Does the I/O error indicate that the operation should be retried later? */
|
|
|
|
#define ERRNO_IO_RETRY(EN) \
|
|
|
|
(((EN) == EAGAIN) || ((EN) == EWOULDBLOCK) || ((EN) == EINTR))
|
|
|
|
|
|
|
|
/* Vty read buffer size. */
|
|
|
|
#define VTY_READ_BUFSIZ 512
|
|
|
|
|
|
|
|
#define VTY_BUFSIZ 512
|
|
|
|
#define VTY_MAXHIST 20
|
|
|
|
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! VTY events */
|
2010-05-19 17:02:52 +00:00
|
|
|
enum event {
|
|
|
|
VTY_SERV,
|
|
|
|
VTY_READ,
|
|
|
|
VTY_WRITE,
|
|
|
|
VTY_CLOSED,
|
|
|
|
VTY_TIMEOUT_RESET,
|
|
|
|
#ifdef VTYSH
|
|
|
|
VTYSH_SERV,
|
|
|
|
VTYSH_READ,
|
|
|
|
VTYSH_WRITE
|
|
|
|
#endif /* VTYSH */
|
|
|
|
};
|
|
|
|
|
2012-07-12 07:22:56 +00:00
|
|
|
enum vty_type {
|
|
|
|
VTY_TERM,
|
|
|
|
VTY_FILE,
|
|
|
|
VTY_SHELL,
|
|
|
|
VTY_SHELL_SERV
|
|
|
|
};
|
|
|
|
|
2011-08-17 15:13:48 +00:00
|
|
|
/*! Internal representation of a single VTY */
|
2010-05-19 17:02:52 +00:00
|
|
|
struct vty {
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! underlying file (if any) */
|
2010-05-19 17:02:52 +00:00
|
|
|
FILE *file;
|
|
|
|
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! private data, specified by creator */
|
2010-05-19 17:02:52 +00:00
|
|
|
void *priv;
|
|
|
|
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! File descripter of this vty. */
|
2010-05-19 17:02:52 +00:00
|
|
|
int fd;
|
|
|
|
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! Is this vty connect to file or not */
|
2012-07-12 07:22:56 +00:00
|
|
|
enum vty_type type;
|
2010-05-19 17:02:52 +00:00
|
|
|
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! Node status of this vty */
|
2010-05-19 17:02:52 +00:00
|
|
|
int node;
|
|
|
|
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! Failure count */
|
2010-05-19 17:02:52 +00:00
|
|
|
int fail;
|
|
|
|
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! Output buffer. */
|
2010-05-19 17:02:52 +00:00
|
|
|
struct buffer *obuf;
|
|
|
|
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! Command input buffer */
|
2010-05-19 17:02:52 +00:00
|
|
|
char *buf;
|
|
|
|
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! Command cursor point */
|
2010-05-19 17:02:52 +00:00
|
|
|
int cp;
|
|
|
|
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! Command length */
|
2010-05-19 17:02:52 +00:00
|
|
|
int length;
|
|
|
|
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! Command max length. */
|
2010-05-19 17:02:52 +00:00
|
|
|
int max;
|
|
|
|
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! Histry of command */
|
2010-05-19 17:02:52 +00:00
|
|
|
char *hist[VTY_MAXHIST];
|
|
|
|
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! History lookup current point */
|
2010-05-19 17:02:52 +00:00
|
|
|
int hp;
|
|
|
|
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! History insert end point */
|
2010-05-19 17:02:52 +00:00
|
|
|
int hindex;
|
|
|
|
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! For current referencing point of interface, route-map,
|
2010-05-19 17:02:52 +00:00
|
|
|
access-list etc... */
|
|
|
|
void *index;
|
|
|
|
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! For multiple level index treatment such as key chain and key. */
|
2010-05-19 17:02:52 +00:00
|
|
|
void *index_sub;
|
|
|
|
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! For escape character. */
|
2010-05-19 17:02:52 +00:00
|
|
|
unsigned char escape;
|
|
|
|
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! Current vty status. */
|
2010-05-19 17:02:52 +00:00
|
|
|
enum { VTY_NORMAL, VTY_CLOSE, VTY_MORE, VTY_MORELINE } status;
|
|
|
|
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! IAC handling
|
2011-08-17 15:13:48 +00:00
|
|
|
*
|
|
|
|
* IAC handling: was the last character received the IAC
|
2010-05-19 17:02:52 +00:00
|
|
|
* (interpret-as-command) escape character (and therefore the next
|
|
|
|
* character will be the command code)? Refer to Telnet RFC 854. */
|
|
|
|
unsigned char iac;
|
|
|
|
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! IAC SB (option subnegotiation) handling */
|
2010-05-19 17:02:52 +00:00
|
|
|
unsigned char iac_sb_in_progress;
|
|
|
|
/* At the moment, we care only about the NAWS (window size) negotiation,
|
|
|
|
* and that requires just a 5-character buffer (RFC 1073):
|
|
|
|
* <NAWS char> <16-bit width> <16-bit height> */
|
|
|
|
#define TELNET_NAWS_SB_LEN 5
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! sub-negotiation buffer */
|
2010-05-19 17:02:52 +00:00
|
|
|
unsigned char sb_buf[TELNET_NAWS_SB_LEN];
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! How many subnegotiation characters have we received?
|
2011-08-17 15:13:48 +00:00
|
|
|
*
|
|
|
|
* We just drop those that do not fit in the buffer. */
|
2010-05-19 17:02:52 +00:00
|
|
|
size_t sb_len;
|
|
|
|
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! Window width */
|
2010-05-19 17:02:52 +00:00
|
|
|
int width;
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! Widnow height */
|
2010-05-19 17:02:52 +00:00
|
|
|
int height;
|
|
|
|
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! Configure lines. */
|
2010-05-19 17:02:52 +00:00
|
|
|
int lines;
|
|
|
|
|
|
|
|
int monitor;
|
|
|
|
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! In configure mode. */
|
2010-05-19 17:02:52 +00:00
|
|
|
int config;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Small macro to determine newline is newline only or linefeed needed. */
|
|
|
|
#define VTY_NEWLINE ((vty->type == VTY_TERM) ? "\r\n" : "\n")
|
|
|
|
|
2012-07-12 07:22:56 +00:00
|
|
|
static inline const char *vty_newline(struct vty *vty)
|
2010-05-19 17:02:52 +00:00
|
|
|
{
|
|
|
|
return VTY_NEWLINE;
|
|
|
|
}
|
|
|
|
|
2011-08-17 15:13:48 +00:00
|
|
|
/*! Information an application registers with the VTY */
|
2010-05-25 21:00:45 +00:00
|
|
|
struct vty_app_info {
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! name of the application */
|
2010-06-08 08:12:58 +00:00
|
|
|
const char *name;
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! version string of the application */
|
2010-06-08 08:12:58 +00:00
|
|
|
const char *version;
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! copyright string of the application */
|
2010-06-08 08:12:58 +00:00
|
|
|
const char *copyright;
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! \ref talloc context */
|
2010-05-25 21:00:45 +00:00
|
|
|
void *tall_ctx;
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! call-back for returning to parent n ode */
|
2015-08-02 02:14:07 +00:00
|
|
|
int (*go_parent_cb)(struct vty *vty);
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! call-back to determine if node is config node */
|
2010-08-25 09:34:56 +00:00
|
|
|
int (*is_config_node)(struct vty *vty, int node);
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! Check if the config is consistent before write */
|
2014-11-21 09:40:07 +00:00
|
|
|
int (*config_is_consistent)(struct vty *vty);
|
2010-05-25 21:00:45 +00:00
|
|
|
};
|
|
|
|
|
2010-05-19 17:02:52 +00:00
|
|
|
/* Prototypes. */
|
2010-05-25 21:00:45 +00:00
|
|
|
void vty_init(struct vty_app_info *app_info);
|
2010-05-19 17:02:52 +00:00
|
|
|
int vty_read_config_file(const char *file_name, void *priv);
|
|
|
|
void vty_init_vtysh (void);
|
|
|
|
void vty_reset (void);
|
|
|
|
struct vty *vty_new (void);
|
|
|
|
struct vty *vty_create (int vty_sock, void *priv);
|
|
|
|
int vty_out (struct vty *, const char *, ...) VTY_PRINTF_ATTRIBUTE(2, 3);
|
|
|
|
int vty_out_newline(struct vty *);
|
|
|
|
int vty_read(struct vty *vty);
|
|
|
|
//void vty_time_print (struct vty *, int);
|
|
|
|
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 *);
|
2010-09-13 18:24:03 +00:00
|
|
|
void *vty_current_index(struct vty *);
|
|
|
|
int vty_current_node(struct vty *vty);
|
2015-08-02 02:14:07 +00:00
|
|
|
int vty_go_parent(struct vty *vty);
|
2010-05-19 17:02:52 +00:00
|
|
|
|
2016-02-23 13:01:41 +00:00
|
|
|
/* Return IP address passed to the 'line vty'/'bind' command, or "127.0.0.1" */
|
|
|
|
const char *vty_get_bind_addr(void);
|
|
|
|
|
2010-08-31 09:09:44 +00:00
|
|
|
extern void *tall_vty_ctx;
|
2011-08-17 15:13:48 +00:00
|
|
|
|
2011-09-04 20:56:10 +00:00
|
|
|
extern struct cmd_element cfg_description_cmd;
|
|
|
|
extern struct cmd_element cfg_no_description_cmd;
|
|
|
|
|
2013-10-10 18:21:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* signal handling
|
|
|
|
*/
|
|
|
|
enum signal_vty {
|
|
|
|
S_VTY_EVENT,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct vty_signal_data {
|
|
|
|
enum event event;
|
|
|
|
int sock;
|
|
|
|
struct vty *vty;
|
|
|
|
};
|
|
|
|
|
2012-04-18 19:53:23 +00:00
|
|
|
/*! @} */
|