📄 cli.h
字号:
/* There are some command levels which called from command node. */
/*aibin edit for add new node (onu, ngn,v5.....) 20070611*/
enum node_type
{
LOGIN_NODE, /* Input User name */
AUTH_NODE, /* Input Password Authentication mode of vty interface. */
VIEW_NODE, /* View node. Default mode of vty interface. */
AUTH_ENABLE_NODE, /* Authentication mode for change enable. */
SET_PASS_NODE, /* Set password */
CONFIRM_PASS_NODE, /* confirm password */
/* ENABLE_NODE, * Enable node. */
CONFIG_NODE, /* Config node. Default mode of config file. */
DEBUG_NODE, /* Debug node. */
DEBUG_HIDDEN_NODE, /* Debug hidden node */
CL_DEBUG_NODE, /* Cli's little debug node */
AAA_NODE, /* AAA node. */
KEYCHAIN_NODE, /* Key-chain node. */
KEYCHAIN_KEY_NODE, /* Key-chain key node. */
INTERFACE_NODE, /* Interface mode node. */
ZEBRA_NODE, /* zebra connection node. */
TABLE_NODE, /* rtm_table selection node. */
RIP_NODE, /* RIP protocol mode node. */
RIPNG_NODE, /* RIPng protocol mode node. */
BGP_NODE, /* BGP protocol mode which includes BGP4+ */
BGP_VPNV4_NODE, /* BGP MPLS-VPN PE exchange. */
BGP_IPV6_NODE, /* BGP IPv6 address family */
OSPF_NODE, /* OSPF protocol mode */
OSPF6_NODE, /* OSPF protocol for IPv6 mode */
CONFIG_ONU_NODE, /*MASC_NODE, /* MASC for multicast. */
CONFIG_ONU_VOICE_NODE, /*IRDP_NODE, /* ICMP Router Discovery Protocol mode. */
IP_NODE, /* Static ip route node. */
CONFIG_ONU_DATA_NODE, /*ACCESS_NODE, /* Access list node. */
CONFIG_ONU_TDM_NODE, /*PREFIX_NODE, /* Prefix list node. */
CONFIG_V5_NODE, /*ACCESS_IPV6_NODE, /* Access list node. */
CONFIG_NGN_NODE, /*PREFIX_IPV6_NODE, /* Prefix list node. */
AS_LIST_NODE, /* AS list node. */
COMMUNITY_LIST_NODE, /* Community list node. */
RMAP_NODE, /* Route map node. */
SMUX_NODE, /* SNMP configuration node. */
DUMP_NODE, /* Packet dump node. */
HLINK_SUBDEV_NODE, /* H.link Subdevice Node */
CONFIRM_ACTION_NODE, /* Confirm action when erase config or reboot */
VTY_NODE, /* Vty node. */
CC_NODE, /* CC node. by martin On oct.20 2001 */
DOMAIN_NODE, /* DOMAIN node. by martin On oct.22 2001 */
/*liling 2003-03-07 增加目录*/
/*CONFIG_PORT_NODE, liling 2004-03-01 delete port node */
CONFIG_VLAN_NODE,
CONFIG_DEVICE_NODE,
CONFIG_SERVICE_NODE,
/*CONFIG_SNMP_NODE, liling 2004-03-01 delete port node */
CONFIG_IGMP_NODE,
CONFIG_PROFILE_NODE,
CONFIG_STP_NODE,
/* CONFIG_RIB_NODE, liling 2004-03-01 delete port node */
CONFIG_FDB_NODE,
CONFIG_8021X_NODE,
CONFIG_ROUTE_NODE, /*liling 2003-05-15 add route node*/
/*CONFIG_ARP_NODE, liling 2004-03-01 delete port node */
/*end of add*/
CONFIG_QOS_NODE, /* liling 2004-03-11 add qos node*/
#ifdef _xdsl_
/*liling 2003-12-15 add dmt*/
XDV_PROFILE_NODE, /*XDV_PROFILE_NODE,*/
XDV_T_PROFILE_NODE, /* XDV_T_PROFILE_NODE,*/
/*end of add*/
/*liling 2004-02-12 add lan and xa64*/
XT16_T_PROFILE_NODE, /*XT16_T_PROFILE_NODE,*/
XT16_PROFILE_NODE, /*XT16_PROFILE_NODE, */
XA64_T_PROFILE_NODE, /*XA64_T_PROFILE_NODE,*/
XA64_PROFILE_NODE, /*XA64_PROFILE_NODE,*/
/*end of add*/
/*liling 2004-10-18 add xa64+ 、XS32 、XVID node*/
XS32_T_PROFILE_NODE,
XS32_PROFILE_NODE,
XA64PLUS_T_PROFILE_NODE,
XA64PLUS_PROFILE_NODE,
XVID_T_PROFILE_NODE,
XVID_PROFILE_NODE,
/*end of add*/
INTERFACE_FAIL_NODE, /* while interface create fail */
PORT_NODE
#endif
};
/* function pointer . */
struct cmd_node
{
/* Node index. */
enum node_type node;
/* Prompt character at vty interface. */
char *prompt;
/* Is this node's configuration goes to vtysh ? */
int vtysh;
/* Node's configuration write function */
int (*func) (struct vty *);
/* Vector of this node's command list. */
cl_vector cmd_vector;
};
/* Structure of command element. */
struct cmd_element
{
char *string; /* Command specification by string. */
int (*func) (struct cmd_element *, struct vty *, int, char **);
char *doc; /* Documentation of this command. */
int task;
int daemon; /* Daemon to which this command belong. */
cl_vector strvec; /* Pointing out each description vector. */
int cmdsize; /* Command index count. */
char *config; /* Configuration string */
cl_vector subconfig; /* Sub configuration string */
};
/* Return value of the commands. */
#define CMD_SUCCESS 0
#define CMD_WARNING 1
#define CMD_ERR_NO_MATCH 2
#define CMD_ERR_AMBIGUOUS 3
#define CMD_ERR_INCOMPLETE 4
#define CMD_ERR_EXEED_ARGC_MAX 5
#define CMD_ERR_NOTHING_TODO 6
#define CMD_COMPLETE_FULL_MATCH 7
#define CMD_COMPLETE_MATCH 8
#define CMD_COMPLETE_LIST_MATCH 9
#define CMD_SUCCESS_DAEMON 10
#define CMD_MESGTYPE_CMD (NOS_MODULE_CLI<<16+1)
#define DEFUN(funcname, cmdname, cmdstr, helpstr) \
int funcname (struct cmd_element *, struct vty *, int, char **);\
struct cmd_element cmdname = {cmdstr, funcname, helpstr , 0};\
int funcname (struct cmd_element *self, struct vty *vty, int argc, char **argv)
#define MDEFUN(funcname, cmdname, cmdstr, helpstr) \
int funcname (struct cmd_element *, struct vty *, int, char **);\
struct cmd_element cmdname = {cmdstr, funcname, helpstr , MY_CLI_MQADDR};\
int funcname (struct cmd_element *self, struct vty *vty, int argc, char **argv)
/* use MDEFUN and define MY_CLI_MQADDR to your MQ address,
CLI will send command to you by messge */
#define OSPFDEFUN(funcname, cmdname, cmdstr, helpstr) \
int funcname (struct cmd_element *, struct vty *, int, char **);\
struct cmd_element cmdname = {cmdstr, funcname, helpstr, MQ_LOCALADDR(NOS_MODULE_OSPF,0) };\
int funcname (struct cmd_element *self, struct vty *vty, int argc, char **argv)
#define BGPDEFUN(funcname, cmdname, cmdstr, helpstr) \
int funcname (struct cmd_element *, struct vty *, int, char **);\
struct cmd_element cmdname = {cmdstr, funcname, helpstr, MQ_LOCALADDR(NOS_MODULE_BGP,0) };\
int funcname (struct cmd_element *self, struct vty *vty, int argc, char **argv)
#define RIPDEFUN(funcname, cmdname, cmdstr, helpstr) \
int funcname (struct cmd_element *, struct vty *, int, char **);\
struct cmd_element cmdname = {cmdstr, funcname, helpstr, MQ_LOCALADDR(NOS_MODULE_RIP,0) };\
int funcname (struct cmd_element *self, struct vty *vty, int argc, char **argv)
#define ZEBRADEFUN(funcname, cmdname, cmdstr, helpstr) \
int funcname (struct cmd_element *, struct vty *, int, char **);\
struct cmd_element cmdname = {cmdstr, funcname, helpstr, MQ_LOCALADDR(NOS_MODULE_ROUTE,0) };\
int funcname (struct cmd_element *self, struct vty *vty, int argc, char **argv)
/* DEFSH for vtysh. */
#define DEFSH(daemon, cmdname, cmdstr, helpstr) \
struct cmd_element cmdname = { cmdstr, NULL, helpstr, 0, daemon };
/* DEFUN + DEFSH */
#define DEFUNSH(daemon, funcname, cmdname, cmdstr, helpstr) \
int funcname (struct cmd_element *, struct vty *, int, char **);\
struct cmd_element cmdname = { cmdstr, funcname, helpstr, 0, daemon }; \
int funcname (struct cmd_element *self, struct vty *vty, int argc, char **argv)
/* ALIAS macro which define existing command's alias. */
#define ALIAS(funcname, cmdname, cmdstr, helpstr) \
struct cmd_element cmdname = { cmdstr, funcname, helpstr ,0 };
#define MALIAS(funcname, cmdname, cmdstr, helpstr) \
struct cmd_element cmdname = { cmdstr, funcname, helpstr ,MY_CLI_MQADDR };
#define OSPFALIAS(funcname, cmdname, cmdstr, helpstr) \
struct cmd_element cmdname = { cmdstr, funcname, helpstr ,MQ_LOCALADDR(NOS_MODULE_OSPF,0) };
#define RIPALIAS(funcname, cmdname, cmdstr, helpstr) \
struct cmd_element cmdname = { cmdstr, funcname, helpstr ,MQ_LOCALADDR(NOS_MODULE_RIP,0) };
#define ZEBRAALIAS(funcname, cmdname, cmdstr, helpstr) \
struct cmd_element cmdname = { cmdstr, funcname, helpstr ,MQ_LOCALADDR(NOS_MODULE_ROUTE,0) };
/* Some macroes */
/* Common descriptions. */
#define SHOW_STR "Show running system information.\n"
#define CONFIG_STR "Config system's setting.\n"
#define IP_STR "IP information\n"
#define IPV6_STR "IPv6 information\n"
#define NO_STR "Negate a command or set its defaults.\n"
#define CLEAR_STR "Reset functions\n"
#define RIP_STR "RIP information\n"
#define BGP_STR "BGP information\n"
#define OSPF_STR "OSPF information\n"
#define NEIGHBOR_STR "Specify neighbor router\n"
#define DEBUG_STR "Debugging functions\n"
#define ROUTER_STR "Enable a routing process\n"
#define AS_STR "AS number\n"
#define MBGP_STR "MBGP information\n"
#define MATCH_STR "Match values from routing table\n"
#define SET_STR "Set values in destination routing protocol\n"
#define OUT_STR "Filter outgoing routing updates\n"
#define IN_STR "Filter incoming routing updates\n"
#define V4NOTATION_STR "specify by IPv4 address notation(e.g. 0.0.0.0)\n"
#define OSPF6_NUMBER_STR "Specify by number\n"
#define INTERFACE_STR "Interface infomation\n"
#define IFNAME_STR "Interface name(e.g. ep0)\n"
#define IP6_STR "IPv6 Information\n"
#define OSPF6_STR "Open Shortest Path First (OSPF) for IPv6\n"
#define OSPF6_ROUTER_STR "Enable a routing process\n"
#define OSPF6_INSTANCE_STR "<1-65535> Instance ID\n"
#define SECONDS_STR "<1-65535> Seconds\n"
#define ROUTE_STR "Routing Table\n"
#define PREFIX_LIST_STR "Build a prefix list\n"
#define OSPF6_DUMP_TYPE_LIST "(hello|dbdesc|lsreq|lsupdate|lsack|neighbor|interface|area|lsa|zebra|config|dbex|spf|route|lsdb|redistribute)"
/* Prototypes. */
void install_node (struct cmd_node *, int (*)(struct vty *));
void install_default (enum node_type);
void install_element (enum node_type, struct cmd_element *);
void sort_node ();
/* Export typical functions. */
extern struct cmd_element config_end_cmd;
extern struct cmd_element config_exit_cmd;
extern struct cmd_element config_quit_cmd;
extern struct cmd_element config_help_cmd;
extern struct cmd_element config_list_cmd;
int config_exit (struct cmd_element *, struct vty *, int, char **);
int config_help (struct cmd_element *, struct vty *, int, char **);
/*************************************************************
Part III: command user module's struct and function
**************************************************************/
struct cl_cmd_module
{
char *module_name; /* module's name */
int (*init_func) (); /* module's init function , mainly install element; */
/* modules's show run function,
mainly show every module's current running configuration */
int (*showrun_func) (struct vty *);
struct cl_cmd_module *prev; /* previous pointer of module; */
struct cl_cmd_module *next; /* next pointer of module; */
};
#endif /* _CLI_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -