📄 cli.h
字号:
/***************************************************************************
vty.h - description
-------------------
begin : Sat Jan 6 2001
copyright : (C) 2001 by martinin
email : martinin@dragon.com
***************************************************************************/
#ifndef _CLI_H_
#define _CLI_H_
/*#include <nos_sys.h>
#include <mn_api.h>/*gm add temp*/
/*#include <nos_syslog.h>
/***********************************************************************
part I : vty struct and function
***********************************************************************/
typedef struct _nos_syslog_monitor_conf
{
char return_code;
long ptr_vty;
char monitor_state;
char monitor_level;
char time_stamp;
char log_type_count;
char monitor_type_state[20]; /*aibin*/
} nos_syslog_monitor_conf;
#define VTY_BUFSIZ 512
#define VTY_MAXHIST 20
/* struct for cl_vector */
struct _cl_vector
{
unsigned int max; /* max number of used slot */
unsigned int alloced; /* number of allocated slot */
void **index; /* index to data */
};
typedef struct _cl_vector *cl_vector;
/* VTY struct. */
struct vty
{
/* File descripter of this vty. */
int fd;
/*
int SessionID;
*/
/* 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;
/* Privilege level of this vty. */
int privilege;
/* Failure count */
int fail;
/* Output buffer. */
struct buffer *obuf;
/* Command input buffer */
char *buf;
/* Command cursor point */
int cp;
/* Command length */
int length;
/* Command max length. */
int max;
/* Histry of command */
char *hist[VTY_MAXHIST];
/* History lookup current point */
int hp;
/* History insert end point */
int hindex;
/* For current referencing point of interface, route-map,
access-list etc... */
void *index;
/* For multiple level index treatment such as key chain and key. */
void *index_sub;
/* For escape character. */
unsigned char escape;
/* Current vty status. */
enum
{ VTY_NORMAL, VTY_CLOSE, VTY_MORE, VTY_START, VTY_CONTINUE, VTY_IOREDIRECT }
status;
/* IAC handling */
unsigned char iac;
/* IAC SB handling */
unsigned char iac_sb_in_progress;
struct buffer *sb_buffer;
/* Window width/height. */
int width;
int height;
int scroll_one;
/* Configure lines. */
int lines;
/* Current executing function pointer. */
int (*func) (struct vty *, void *arg);
/* Terminal monitor. */
int monitor;
/* In configure mode. */
int config;
/* Read and write thread. */
struct thread *t_read;
struct thread *t_write;
/* Timeout seconds and thread. */
unsigned long v_timeout;
struct thread *t_timeout;
unsigned short keep_alive_status;
/* when status is 0 then when keep alive timeout ,send a tel option
when status is 1 then when keep alive timeout ,close vty */
unsigned long v_keep_alive_timeout;
struct thread *t_keep_alive_timeout;
/* Thread output function. */
struct thread *t_output;
/* Output data pointer. */
int (*output_func) (struct vty *, int);
void (*output_clean) (struct vty *);
struct route_node *output_rn;
unsigned long output_count;
int output_type;
void *output_arg;
/* vty's connection types , sock, ttys or http */
int conn_type;
/* vty's connection's user name */
char *user_name;
/* enum cli_user_role_type user_role; user role should get it when needed.*/
/* user login failed times ,in authnode , 3 fail disconnect ,
in auth_enable 3 failed back to VIEW_NODE */
int failed_times;
/* Below this is for set pass */
int prev_node; /* preview node before set pass */
char *setpass_username;
char *setpass_first_passwd;
int setpass_type; /* 0 for set login pass , 1 for set enable pass */
/* End of setpass struct */
int ping_taskid;
int v_shell_taskId;
unsigned short cl_vty_in_relay;
int cl_relay_fd;
int cl_telnet_taskid;
int cl_relay_console_bluelight;
int cl_relay_console_have_handshake;
int relay_keep_alive_status;
/* master of the threads. */
struct thread_master *cl_relay_thread_master;
struct thread *t_relay_read;
struct thread *t_relay_keep_alive_timeout;
/* IAC handling */
unsigned char cl_relay_iac;
/* IAC SB handling */
unsigned char cl_relay_iac_sb_in_progress;
struct buffer *cl_relay_sb_buffer;
/* debug monitor 0 no monitor 1 monitor*/
unsigned short debug_monitor;
int monitor_taskid;
unsigned short monitor_type;
int monitor_page_no;
/************************************
frozen vty in and(or) out
used for if a command can't return immediately
then call frozen to freeze vty's in and(or) out
call unfrozen when finished.
1: freezed
0: unfreezed
***********************************/
unsigned short frozen;
int (*action_func) (struct vty *vty);
/* function that called by confirm action */
int hlink_sub_devno;
/*gm add for syslog*/
nos_syslog_monitor_conf monitor_conf;
};
/* Small macro to determine newline is newline only or linefeed needed. */
#define VTY_NEWLINE ((vty->type == VTY_TERM) ? "\r\n" : "\r\n")
/* Prototypes. */
/*int vty_out (struct vty *, const char *, ...);*/
int vty_big_out (struct vty *vty, int maxlen,const char *format, ...);
int vty_direct_out (struct vty *vty , const char *format, ...);
/******************************************************
funcname : cl_vty_monitor_out
description : used for display debug info
input args : just like printf
return values : 1, success
0, failed
*****************************************************/
int cl_vty_monitor_out(const char *format, ...);
/**********************************
funcname: cl_vty_freeze
description: used for freeze vty's in and out
(maybe in or out in future)
make a vty didn't recieve any input
output only with vty_direct_out
used when a command can't return immediately
************************************/
int cl_vty_freeze(void *arg,int frozen_type);
/**********************************
funcname: cl_vty_unfreeze
description: used for unfreeze vty's in and out
(maybe in or out in future)
used when a command finished and return .
************************************/
int cl_vty_unfreeze(void *arg,int unfrozen_to);
/****************************************************************
Part II : Command struct and function
*******************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -