paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame^] | 1 | /* Virtual terminal [aka TeletYpe] interface routine |
| 2 | Copyright (C) 1997 Kunihiro Ishiguro |
| 3 | |
| 4 | This file is part of GNU Zebra. |
| 5 | |
| 6 | GNU Zebra is free software; you can redistribute it and/or modify it |
| 7 | under the terms of the GNU General Public License as published by the |
| 8 | Free Software Foundation; either version 2, or (at your option) any |
| 9 | later version. |
| 10 | |
| 11 | GNU Zebra is distributed in the hope that it will be useful, but |
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with GNU Zebra; see the file COPYING. If not, write to the Free |
| 18 | Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 19 | 02111-1307, USA. */ |
| 20 | |
| 21 | #ifndef _ZEBRA_VTY_H |
| 22 | #define _ZEBRA_VTY_H |
| 23 | |
| 24 | #define VTY_BUFSIZ 512 |
| 25 | #define VTY_MAXHIST 20 |
| 26 | |
| 27 | /* VTY struct. */ |
| 28 | struct vty |
| 29 | { |
| 30 | /* File descripter of this vty. */ |
| 31 | int fd; |
| 32 | |
| 33 | /* Is this vty connect to file or not */ |
| 34 | enum {VTY_TERM, VTY_FILE, VTY_SHELL, VTY_SHELL_SERV} type; |
| 35 | |
| 36 | /* Node status of this vty */ |
| 37 | int node; |
| 38 | |
| 39 | /* What address is this vty comming from. */ |
| 40 | char *address; |
| 41 | |
| 42 | /* Privilege level of this vty. */ |
| 43 | int privilege; |
| 44 | |
| 45 | /* Failure count */ |
| 46 | int fail; |
| 47 | |
| 48 | /* Output buffer. */ |
| 49 | struct buffer *obuf; |
| 50 | |
| 51 | /* Command input buffer */ |
| 52 | char *buf; |
| 53 | |
| 54 | /* Command cursor point */ |
| 55 | int cp; |
| 56 | |
| 57 | /* Command length */ |
| 58 | int length; |
| 59 | |
| 60 | /* Command max length. */ |
| 61 | int max; |
| 62 | |
| 63 | /* Histry of command */ |
| 64 | char *hist[VTY_MAXHIST]; |
| 65 | |
| 66 | /* History lookup current point */ |
| 67 | int hp; |
| 68 | |
| 69 | /* History insert end point */ |
| 70 | int hindex; |
| 71 | |
| 72 | /* For current referencing point of interface, route-map, |
| 73 | access-list etc... */ |
| 74 | void *index; |
| 75 | |
| 76 | /* For multiple level index treatment such as key chain and key. */ |
| 77 | void *index_sub; |
| 78 | |
| 79 | /* For escape character. */ |
| 80 | unsigned char escape; |
| 81 | |
| 82 | /* Current vty status. */ |
| 83 | enum {VTY_NORMAL, VTY_CLOSE, VTY_MORE, VTY_MORELINE, |
| 84 | VTY_START, VTY_CONTINUE} status; |
| 85 | |
| 86 | /* IAC handling */ |
| 87 | unsigned char iac; |
| 88 | |
| 89 | /* IAC SB handling */ |
| 90 | unsigned char iac_sb_in_progress; |
| 91 | struct buffer *sb_buffer; |
| 92 | |
| 93 | /* Window width/height. */ |
| 94 | int width; |
| 95 | int height; |
| 96 | |
| 97 | int scroll_one; |
| 98 | |
| 99 | /* Configure lines. */ |
| 100 | int lines; |
| 101 | |
| 102 | /* Current executing function pointer. */ |
| 103 | int (*func) (struct vty *, void *arg); |
| 104 | |
| 105 | /* Terminal monitor. */ |
| 106 | int monitor; |
| 107 | |
| 108 | /* In configure mode. */ |
| 109 | int config; |
| 110 | |
| 111 | /* Read and write thread. */ |
| 112 | struct thread *t_read; |
| 113 | struct thread *t_write; |
| 114 | |
| 115 | /* Timeout seconds and thread. */ |
| 116 | unsigned long v_timeout; |
| 117 | struct thread *t_timeout; |
| 118 | |
| 119 | /* Thread output function. */ |
| 120 | struct thread *t_output; |
| 121 | |
| 122 | /* Output data pointer. */ |
| 123 | int (*output_func) (struct vty *, int); |
| 124 | void (*output_clean) (struct vty *); |
| 125 | void *output_rn; |
| 126 | unsigned long output_count; |
| 127 | int output_type; |
| 128 | void *output_arg; |
| 129 | }; |
| 130 | |
| 131 | /* Integrated configuration file. */ |
| 132 | #define INTEGRATE_DEFAULT_CONFIG "Zebra.conf" |
| 133 | |
| 134 | /* Small macro to determine newline is newline only or linefeed needed. */ |
| 135 | #define VTY_NEWLINE ((vty->type == VTY_TERM) ? "\r\n" : "\n") |
| 136 | |
| 137 | /* Default time out value */ |
| 138 | #define VTY_TIMEOUT_DEFAULT 600 |
| 139 | |
| 140 | /* Vty read buffer size. */ |
| 141 | #define VTY_READ_BUFSIZ 512 |
| 142 | |
| 143 | /* Directory separator. */ |
| 144 | #ifndef DIRECTORY_SEP |
| 145 | #define DIRECTORY_SEP '/' |
| 146 | #endif /* DIRECTORY_SEP */ |
| 147 | |
| 148 | #ifndef IS_DIRECTORY_SEP |
| 149 | #define IS_DIRECTORY_SEP(c) ((c) == DIRECTORY_SEP) |
| 150 | #endif |
| 151 | |
| 152 | /* GCC have printf type attribute check. */ |
| 153 | #ifdef __GNUC__ |
| 154 | #define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b))) |
| 155 | #else |
| 156 | #define PRINTF_ATTRIBUTE(a,b) |
| 157 | #endif /* __GNUC__ */ |
| 158 | |
| 159 | /* Utility macro to convert VTY argument to unsigned integer. */ |
| 160 | #define VTY_GET_INTEGER(NAME,V,STR) \ |
| 161 | { \ |
| 162 | char *endptr = NULL; \ |
| 163 | (V) = strtoul ((STR), &endptr, 10); \ |
| 164 | if ((V) == ULONG_MAX || *endptr != '\0') \ |
| 165 | { \ |
| 166 | vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \ |
| 167 | return CMD_WARNING; \ |
| 168 | } \ |
| 169 | } |
| 170 | |
| 171 | #define VTY_GET_INTEGER_RANGE(NAME,V,STR,MIN,MAX) \ |
| 172 | { \ |
| 173 | char *endptr = NULL; \ |
| 174 | (V) = strtoul ((STR), &endptr, 10); \ |
| 175 | if ((V) == ULONG_MAX || *endptr != '\0' \ |
| 176 | || (V) < (MIN) || (V) > (MAX)) \ |
| 177 | { \ |
| 178 | vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \ |
| 179 | return CMD_WARNING; \ |
| 180 | } \ |
| 181 | } |
| 182 | |
| 183 | /* Exported variables */ |
| 184 | extern char integrate_default[]; |
| 185 | |
| 186 | /* Prototypes. */ |
| 187 | void vty_init (void); |
| 188 | void vty_init_vtysh (void); |
| 189 | void vty_reset (void); |
| 190 | void vty_finish (void); |
| 191 | struct vty *vty_new (void); |
| 192 | int vty_out (struct vty *, const char *, ...) PRINTF_ATTRIBUTE(2, 3); |
| 193 | void vty_read_config (char *, char *, char *); |
| 194 | void vty_time_print (struct vty *, int); |
| 195 | void vty_serv_sock (const char *, unsigned short, char *); |
| 196 | void vty_close (struct vty *); |
| 197 | char *vty_get_cwd (void); |
| 198 | void vty_log (const char *, const char *, va_list); |
| 199 | int vty_config_lock (struct vty *); |
| 200 | int vty_config_unlock (struct vty *); |
| 201 | int vty_shell (struct vty *); |
| 202 | int vty_shell_serv (struct vty *); |
| 203 | void vty_hello (struct vty *); |
| 204 | |
| 205 | #endif /* _ZEBRA_VTY_H */ |