Annotation of embedaddon/quagga/vtysh/vtysh.c, revision 1.1.1.3

1.1       misho       1: /* Virtual terminal interface shell.
                      2:  * Copyright (C) 2000 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: 
                     22: #include <zebra.h>
                     23: 
                     24: #include <sys/un.h>
                     25: #include <setjmp.h>
                     26: #include <sys/wait.h>
                     27: #include <sys/resource.h>
                     28: #include <sys/stat.h>
                     29: 
                     30: #include <readline/readline.h>
                     31: #include <readline/history.h>
                     32: 
                     33: #include "command.h"
                     34: #include "memory.h"
                     35: #include "vtysh/vtysh.h"
                     36: #include "log.h"
                     37: #include "bgpd/bgp_vty.h"
                     38: 
                     39: /* Struct VTY. */
                     40: struct vty *vty;
                     41: 
                     42: /* VTY shell pager name. */
                     43: char *vtysh_pager_name = NULL;
                     44: 
                     45: /* VTY shell client structure. */
                     46: struct vtysh_client
                     47: {
                     48:   int fd;
                     49:   const char *name;
                     50:   int flag;
                     51:   const char *path;
                     52: } vtysh_client[] =
                     53: {
                     54:   { .fd = -1, .name = "zebra", .flag = VTYSH_ZEBRA, .path = ZEBRA_VTYSH_PATH},
                     55:   { .fd = -1, .name = "ripd", .flag = VTYSH_RIPD, .path = RIP_VTYSH_PATH},
                     56:   { .fd = -1, .name = "ripngd", .flag = VTYSH_RIPNGD, .path = RIPNG_VTYSH_PATH},
                     57:   { .fd = -1, .name = "ospfd", .flag = VTYSH_OSPFD, .path = OSPF_VTYSH_PATH},
                     58:   { .fd = -1, .name = "ospf6d", .flag = VTYSH_OSPF6D, .path = OSPF6_VTYSH_PATH},
                     59:   { .fd = -1, .name = "bgpd", .flag = VTYSH_BGPD, .path = BGP_VTYSH_PATH},
                     60:   { .fd = -1, .name = "isisd", .flag = VTYSH_ISISD, .path = ISIS_VTYSH_PATH},
1.1.1.2   misho      61:   { .fd = -1, .name = "babeld", .flag = VTYSH_BABELD, .path = BABEL_VTYSH_PATH},
1.1       misho      62: };
                     63: 
                     64: 
                     65: /* We need direct access to ripd to implement vtysh_exit_ripd_only. */
                     66: static struct vtysh_client *ripd_client = NULL;
                     67:  
                     68: 
                     69: /* Using integrated config from Quagga.conf. Default is no. */
                     70: int vtysh_writeconfig_integrated = 0;
                     71: 
                     72: extern char config_default[];
                     73: 
                     74: static void
                     75: vclient_close (struct vtysh_client *vclient)
                     76: {
                     77:   if (vclient->fd >= 0)
                     78:     {
                     79:       fprintf(stderr,
                     80:              "Warning: closing connection to %s because of an I/O error!\n",
                     81:              vclient->name);
                     82:       close (vclient->fd);
                     83:       vclient->fd = -1;
                     84:     }
                     85: }
                     86: 
                     87: /* Following filled with debug code to trace a problematic condition
                     88:  * under load - it SHOULD handle it. */
                     89: #define ERR_WHERE_STRING "vtysh(): vtysh_client_config(): "
                     90: static int
                     91: vtysh_client_config (struct vtysh_client *vclient, char *line)
                     92: {
                     93:   int ret;
                     94:   char *buf;
                     95:   size_t bufsz;
                     96:   char *pbuf;
                     97:   size_t left;
                     98:   char *eoln;
                     99:   int nbytes;
                    100:   int i;
                    101:   int readln;
                    102: 
                    103:   if (vclient->fd < 0)
                    104:     return CMD_SUCCESS;
                    105: 
                    106:   ret = write (vclient->fd, line, strlen (line) + 1);
                    107:   if (ret <= 0)
                    108:     {
                    109:       vclient_close (vclient);
                    110:       return CMD_SUCCESS;
                    111:     }
                    112:        
                    113:   /* Allow enough room for buffer to read more than a few pages from socket. */
                    114:   bufsz = 5 * getpagesize() + 1;
                    115:   buf = XMALLOC(MTYPE_TMP, bufsz);
                    116:   memset(buf, 0, bufsz);
                    117:   pbuf = buf;
                    118: 
                    119:   while (1)
                    120:     {
                    121:       if (pbuf >= ((buf + bufsz) -1))
                    122:        {
                    123:          fprintf (stderr, ERR_WHERE_STRING \
                    124:                   "warning - pbuf beyond buffer end.\n");
                    125:          return CMD_WARNING;
                    126:        }
                    127: 
                    128:       readln = (buf + bufsz) - pbuf - 1;
                    129:       nbytes = read (vclient->fd, pbuf, readln);
                    130: 
                    131:       if (nbytes <= 0)
                    132:        {
                    133: 
                    134:          if (errno == EINTR)
                    135:            continue;
                    136: 
                    137:          fprintf(stderr, ERR_WHERE_STRING "(%u)", errno);
                    138:          perror("");
                    139: 
                    140:          if (errno == EAGAIN || errno == EIO)
                    141:            continue;
                    142: 
                    143:          vclient_close (vclient);
                    144:          XFREE(MTYPE_TMP, buf);
                    145:          return CMD_SUCCESS;
                    146:        }
                    147: 
                    148:       pbuf[nbytes] = '\0';
                    149: 
                    150:       if (nbytes >= 4)
                    151:        {
                    152:          i = nbytes - 4;
                    153:          if (pbuf[i] == '\0' && pbuf[i + 1] == '\0' && pbuf[i + 2] == '\0')
                    154:            {
                    155:              ret = pbuf[i + 3];
                    156:              break;
                    157:            }
                    158:        }
                    159:       pbuf += nbytes;
                    160: 
                    161:       /* See if a line exists in buffer, if so parse and consume it, and
                    162:        * reset read position. */
                    163:       if ((eoln = strrchr(buf, '\n')) == NULL)
                    164:        continue;
                    165: 
                    166:       if (eoln >= ((buf + bufsz) - 1))
                    167:        {
                    168:          fprintf (stderr, ERR_WHERE_STRING \
                    169:                   "warning - eoln beyond buffer end.\n");
                    170:        }
                    171:       vtysh_config_parse(buf);
                    172: 
                    173:       eoln++;
                    174:       left = (size_t)(buf + bufsz - eoln);
                    175:       memmove(buf, eoln, left);
                    176:       buf[bufsz-1] = '\0';
                    177:       pbuf = buf + strlen(buf);
                    178:     }
                    179: 
                    180:   /* Parse anything left in the buffer. */
                    181: 
                    182:   vtysh_config_parse (buf);
                    183: 
                    184:   XFREE(MTYPE_TMP, buf);
                    185:   return ret;
                    186: }
                    187: 
                    188: static int
                    189: vtysh_client_execute (struct vtysh_client *vclient, const char *line, FILE *fp)
                    190: {
                    191:   int ret;
                    192:   char buf[1001];
                    193:   int nbytes;
                    194:   int i; 
                    195:   int numnulls = 0;
                    196: 
                    197:   if (vclient->fd < 0)
                    198:     return CMD_SUCCESS;
                    199: 
                    200:   ret = write (vclient->fd, line, strlen (line) + 1);
                    201:   if (ret <= 0)
                    202:     {
                    203:       vclient_close (vclient);
                    204:       return CMD_SUCCESS;
                    205:     }
                    206:        
                    207:   while (1)
                    208:     {
                    209:       nbytes = read (vclient->fd, buf, sizeof(buf)-1);
                    210: 
                    211:       if (nbytes <= 0 && errno != EINTR)
                    212:        {
                    213:          vclient_close (vclient);
                    214:          return CMD_SUCCESS;
                    215:        }
                    216: 
                    217:       if (nbytes > 0)
                    218:        {
                    219:          if ((numnulls == 3) && (nbytes == 1))
                    220:            return buf[0];
                    221: 
                    222:          buf[nbytes] = '\0';
                    223:          fputs (buf, fp);
                    224:          fflush (fp);
                    225:          
                    226:          /* check for trailling \0\0\0<ret code>, 
                    227:           * even if split across reads 
                    228:           * (see lib/vty.c::vtysh_read)
                    229:           */
                    230:           if (nbytes >= 4) 
                    231:             {
                    232:               i = nbytes-4;
                    233:               numnulls = 0;
                    234:             }
                    235:           else
                    236:             i = 0;
                    237:           
                    238:           while (i < nbytes && numnulls < 3)
                    239:             {
                    240:               if (buf[i++] == '\0')
                    241:                 numnulls++;
                    242:               else
                    243:                 numnulls = 0;
                    244:             }
                    245: 
                    246:           /* got 3 or more trailing NULs? */
                    247:           if ((numnulls >= 3) && (i < nbytes))
                    248:             return (buf[nbytes-1]);
                    249:        }
                    250:     }
                    251: }
                    252: 
                    253: void
                    254: vtysh_exit_ripd_only (void)
                    255: {
                    256:   if (ripd_client)
                    257:     vtysh_client_execute (ripd_client, "exit", stdout);
                    258: }
                    259: 
                    260: 
                    261: void
                    262: vtysh_pager_init (void)
                    263: {
                    264:   char *pager_defined;
                    265: 
                    266:   pager_defined = getenv ("VTYSH_PAGER");
                    267: 
                    268:   if (pager_defined)
                    269:     vtysh_pager_name = strdup (pager_defined);
                    270:   else
                    271:     vtysh_pager_name = strdup ("more");
                    272: }
                    273: 
                    274: /* Command execution over the vty interface. */
                    275: static int
                    276: vtysh_execute_func (const char *line, int pager)
                    277: {
                    278:   int ret, cmd_stat;
                    279:   u_int i;
                    280:   vector vline;
                    281:   struct cmd_element *cmd;
                    282:   FILE *fp = NULL;
                    283:   int closepager = 0;
                    284:   int tried = 0;
                    285:   int saved_ret, saved_node;
                    286: 
                    287:   /* Split readline string up into the vector. */
                    288:   vline = cmd_make_strvec (line);
                    289: 
                    290:   if (vline == NULL)
                    291:     return CMD_SUCCESS;
                    292: 
                    293:   saved_ret = ret = cmd_execute_command (vline, vty, &cmd, 1);
                    294:   saved_node = vty->node;
                    295: 
                    296:   /* If command doesn't succeeded in current node, try to walk up in node tree.
                    297:    * Changing vty->node is enough to try it just out without actual walkup in
                    298:    * the vtysh. */
                    299:   while (ret != CMD_SUCCESS && ret != CMD_SUCCESS_DAEMON && ret != CMD_WARNING
                    300:         && vty->node > CONFIG_NODE)
                    301:     {
                    302:       vty->node = node_parent(vty->node);
                    303:       ret = cmd_execute_command (vline, vty, &cmd, 1);
                    304:       tried++;
                    305:     }
                    306: 
                    307:   vty->node = saved_node;
                    308: 
                    309:   /* If command succeeded in any other node than current (tried > 0) we have
                    310:    * to move into node in the vtysh where it succeeded. */
                    311:   if (ret == CMD_SUCCESS || ret == CMD_SUCCESS_DAEMON || ret == CMD_WARNING)
                    312:     {
                    313:       if ((saved_node == BGP_VPNV4_NODE || saved_node == BGP_IPV4_NODE
                    314:           || saved_node == BGP_IPV6_NODE || saved_node == BGP_IPV4M_NODE
                    315:           || saved_node == BGP_IPV6M_NODE)
                    316:          && (tried == 1))
                    317:        {
                    318:          vtysh_execute("exit-address-family");
                    319:        }
                    320:       else if ((saved_node == KEYCHAIN_KEY_NODE) && (tried == 1))
                    321:        {
                    322:          vtysh_execute("exit");
                    323:        }
                    324:       else if (tried)
                    325:        {
                    326:          vtysh_execute ("end");
                    327:          vtysh_execute ("configure terminal");
                    328:        }
                    329:     }
                    330:   /* If command didn't succeed in any node, continue with return value from
                    331:    * first try. */
                    332:   else if (tried)
                    333:     {
                    334:       ret = saved_ret;
                    335:     }
                    336: 
                    337:   cmd_free_strvec (vline);
                    338: 
                    339:   cmd_stat = ret;
                    340:   switch (ret)
                    341:     {
                    342:     case CMD_WARNING:
                    343:       if (vty->type == VTY_FILE)
                    344:        fprintf (stdout,"Warning...\n");
                    345:       break;
                    346:     case CMD_ERR_AMBIGUOUS:
                    347:       fprintf (stdout,"%% Ambiguous command.\n");
                    348:       break;
                    349:     case CMD_ERR_NO_MATCH:
                    350:       fprintf (stdout,"%% Unknown command.\n");
                    351:       break;
                    352:     case CMD_ERR_INCOMPLETE:
                    353:       fprintf (stdout,"%% Command incomplete.\n");
                    354:       break;
                    355:     case CMD_SUCCESS_DAEMON:
                    356:       {
                    357:        /* FIXME: Don't open pager for exit commands. popen() causes problems
                    358:         * if exited from vtysh at all. This hack shouldn't cause any problem
                    359:         * but is really ugly. */
                    360:        if (pager && vtysh_pager_name && (strncmp(line, "exit", 4) != 0))
                    361:          {
                    362:            fp = popen (vtysh_pager_name, "w");
                    363:            if (fp == NULL)
                    364:              {
                    365:                perror ("popen failed for pager");
                    366:                fp = stdout;
                    367:              }
                    368:            else
                    369:              closepager=1;
                    370:          }
                    371:        else
                    372:          fp = stdout;
                    373: 
                    374:        if (! strcmp(cmd->string,"configure terminal"))
                    375:          {
1.1.1.3 ! misho     376:            for (i = 0; i < array_size(vtysh_client); i++)
1.1       misho     377:              {
                    378:                cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp);
                    379:                if (cmd_stat == CMD_WARNING)
                    380:                  break;
                    381:              }
                    382: 
                    383:            if (cmd_stat)
                    384:              {
                    385:                line = "end";
                    386:                vline = cmd_make_strvec (line);
                    387: 
                    388:                if (vline == NULL)
                    389:                  {
                    390:                    if (pager && vtysh_pager_name && fp && closepager)
                    391:                      {
                    392:                        if (pclose (fp) == -1)
                    393:                          {
                    394:                            perror ("pclose failed for pager");
                    395:                          }
                    396:                        fp = NULL;
                    397:                      }
                    398:                    return CMD_SUCCESS;
                    399:                  }
                    400: 
                    401:                ret = cmd_execute_command (vline, vty, &cmd, 1);
                    402:                cmd_free_strvec (vline);
                    403:                if (ret != CMD_SUCCESS_DAEMON)
                    404:                  break;
                    405:              }
                    406:            else
                    407:              if (cmd->func)
                    408:                {
                    409:                  (*cmd->func) (cmd, vty, 0, NULL);
                    410:                  break;
                    411:                }
                    412:          }
                    413: 
                    414:        cmd_stat = CMD_SUCCESS;
1.1.1.3 ! misho     415:        for (i = 0; i < array_size(vtysh_client); i++)
1.1       misho     416:          {
                    417:            if (cmd->daemon & vtysh_client[i].flag)
                    418:              {
                    419:                cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp);
                    420:                if (cmd_stat != CMD_SUCCESS)
                    421:                  break;
                    422:              }
                    423:          }
                    424:        if (cmd_stat != CMD_SUCCESS)
                    425:          break;
                    426: 
                    427:        if (cmd->func)
                    428:          (*cmd->func) (cmd, vty, 0, NULL);
                    429:       }
                    430:     }
                    431:   if (pager && vtysh_pager_name && fp && closepager)
                    432:     {
                    433:       if (pclose (fp) == -1)
                    434:        {
                    435:          perror ("pclose failed for pager");
                    436:        }
                    437:       fp = NULL;
                    438:     }
                    439:   return cmd_stat;
                    440: }
                    441: 
                    442: int
                    443: vtysh_execute_no_pager (const char *line)
                    444: {
                    445:   return vtysh_execute_func (line, 0);
                    446: }
                    447: 
                    448: int
                    449: vtysh_execute (const char *line)
                    450: {
                    451:   return vtysh_execute_func (line, 1);
                    452: }
                    453: 
                    454: /* Configration make from file. */
                    455: int
                    456: vtysh_config_from_file (struct vty *vty, FILE *fp)
                    457: {
                    458:   int ret;
                    459:   vector vline;
                    460:   struct cmd_element *cmd;
                    461: 
                    462:   while (fgets (vty->buf, VTY_BUFSIZ, fp))
                    463:     {
                    464:       if (vty->buf[0] == '!' || vty->buf[1] == '#')
                    465:        continue;
                    466: 
                    467:       vline = cmd_make_strvec (vty->buf);
                    468: 
                    469:       /* In case of comment line. */
                    470:       if (vline == NULL)
                    471:        continue;
                    472: 
                    473:       /* Execute configuration command : this is strict match. */
                    474:       ret = cmd_execute_command_strict (vline, vty, &cmd);
                    475: 
                    476:       /* Try again with setting node to CONFIG_NODE. */
                    477:       if (ret != CMD_SUCCESS 
                    478:          && ret != CMD_SUCCESS_DAEMON
                    479:          && ret != CMD_WARNING)
                    480:        {
                    481:          if (vty->node == KEYCHAIN_KEY_NODE)
                    482:            {
                    483:              vty->node = KEYCHAIN_NODE;
                    484:              vtysh_exit_ripd_only ();
                    485:              ret = cmd_execute_command_strict (vline, vty, &cmd);
                    486: 
                    487:              if (ret != CMD_SUCCESS 
                    488:                  && ret != CMD_SUCCESS_DAEMON 
                    489:                  && ret != CMD_WARNING)
                    490:                {
                    491:                  vtysh_exit_ripd_only ();
                    492:                  vty->node = CONFIG_NODE;
                    493:                  ret = cmd_execute_command_strict (vline, vty, &cmd);
                    494:                }
                    495:            }
                    496:          else
                    497:            {
                    498:              vtysh_execute ("end");
                    499:              vtysh_execute ("configure terminal");
                    500:              vty->node = CONFIG_NODE;
                    501:              ret = cmd_execute_command_strict (vline, vty, &cmd);
                    502:            }
                    503:        }         
                    504: 
                    505:       cmd_free_strvec (vline);
                    506: 
                    507:       switch (ret)
                    508:        {
                    509:        case CMD_WARNING:
                    510:          if (vty->type == VTY_FILE)
                    511:            fprintf (stdout,"Warning...\n");
                    512:          break;
                    513:        case CMD_ERR_AMBIGUOUS:
                    514:          fprintf (stdout,"%% Ambiguous command.\n");
                    515:          break;
                    516:        case CMD_ERR_NO_MATCH:
                    517:          fprintf (stdout,"%% Unknown command: %s", vty->buf);
                    518:          break;
                    519:        case CMD_ERR_INCOMPLETE:
                    520:          fprintf (stdout,"%% Command incomplete.\n");
                    521:          break;
                    522:        case CMD_SUCCESS_DAEMON:
                    523:          {
                    524:            u_int i;
                    525:            int cmd_stat = CMD_SUCCESS;
                    526: 
1.1.1.3 ! misho     527:            for (i = 0; i < array_size(vtysh_client); i++)
1.1       misho     528:              {
                    529:                if (cmd->daemon & vtysh_client[i].flag)
                    530:                  {
                    531:                    cmd_stat = vtysh_client_execute (&vtysh_client[i],
                    532:                                                     vty->buf, stdout);
                    533:                    if (cmd_stat != CMD_SUCCESS)
                    534:                      break;
                    535:                  }
                    536:              }
                    537:            if (cmd_stat != CMD_SUCCESS)
                    538:              break;
                    539: 
                    540:            if (cmd->func)
                    541:              (*cmd->func) (cmd, vty, 0, NULL);
                    542:          }
                    543:        }
                    544:     }
                    545:   return CMD_SUCCESS;
                    546: }
                    547: 
                    548: /* We don't care about the point of the cursor when '?' is typed. */
                    549: int
                    550: vtysh_rl_describe (void)
                    551: {
                    552:   int ret;
                    553:   unsigned int i;
                    554:   vector vline;
                    555:   vector describe;
                    556:   int width;
                    557:   struct desc *desc;
                    558: 
                    559:   vline = cmd_make_strvec (rl_line_buffer);
                    560: 
                    561:   /* In case of '> ?'. */
                    562:   if (vline == NULL)
                    563:     {
                    564:       vline = vector_init (1);
                    565:       vector_set (vline, '\0');
                    566:     }
                    567:   else 
                    568:     if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
                    569:       vector_set (vline, '\0');
                    570: 
                    571:   describe = cmd_describe_command (vline, vty, &ret);
                    572: 
                    573:   fprintf (stdout,"\n");
                    574: 
                    575:   /* Ambiguous and no match error. */
                    576:   switch (ret)
                    577:     {
                    578:     case CMD_ERR_AMBIGUOUS:
                    579:       cmd_free_strvec (vline);
                    580:       fprintf (stdout,"%% Ambiguous command.\n");
                    581:       rl_on_new_line ();
                    582:       return 0;
                    583:       break;
                    584:     case CMD_ERR_NO_MATCH:
                    585:       cmd_free_strvec (vline);
                    586:       fprintf (stdout,"%% There is no matched command.\n");
                    587:       rl_on_new_line ();
                    588:       return 0;
                    589:       break;
                    590:     }  
                    591: 
                    592:   /* Get width of command string. */
                    593:   width = 0;
                    594:   for (i = 0; i < vector_active (describe); i++)
                    595:     if ((desc = vector_slot (describe, i)) != NULL)
                    596:       {
                    597:        int len;
                    598: 
                    599:        if (desc->cmd[0] == '\0')
                    600:          continue;
                    601: 
                    602:        len = strlen (desc->cmd);
                    603:        if (desc->cmd[0] == '.')
                    604:          len--;
                    605: 
                    606:        if (width < len)
                    607:          width = len;
                    608:       }
                    609: 
                    610:   for (i = 0; i < vector_active (describe); i++)
                    611:     if ((desc = vector_slot (describe, i)) != NULL)
                    612:       {
                    613:        if (desc->cmd[0] == '\0')
                    614:          continue;
                    615: 
                    616:        if (! desc->str)
                    617:          fprintf (stdout,"  %-s\n",
                    618:                   desc->cmd[0] == '.' ? desc->cmd + 1 : desc->cmd);
                    619:        else
                    620:          fprintf (stdout,"  %-*s  %s\n",
                    621:                   width,
                    622:                   desc->cmd[0] == '.' ? desc->cmd + 1 : desc->cmd,
                    623:                   desc->str);
                    624:       }
                    625: 
                    626:   cmd_free_strvec (vline);
                    627:   vector_free (describe);
                    628: 
                    629:   rl_on_new_line();
                    630: 
                    631:   return 0;
                    632: }
                    633: 
                    634: /* Result of cmd_complete_command() call will be stored here
                    635:  * and used in new_completion() in order to put the space in
                    636:  * correct places only. */
                    637: int complete_status;
                    638: 
                    639: static char *
                    640: command_generator (const char *text, int state)
                    641: {
                    642:   vector vline;
                    643:   static char **matched = NULL;
                    644:   static int index = 0;
                    645: 
                    646:   /* First call. */
                    647:   if (! state)
                    648:     {
                    649:       index = 0;
                    650: 
                    651:       if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
                    652:        return NULL;
                    653: 
                    654:       vline = cmd_make_strvec (rl_line_buffer);
                    655:       if (vline == NULL)
                    656:        return NULL;
                    657: 
                    658:       if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
                    659:        vector_set (vline, '\0');
                    660: 
                    661:       matched = cmd_complete_command (vline, vty, &complete_status);
                    662:     }
                    663: 
                    664:   if (matched && matched[index])
                    665:     return matched[index++];
                    666: 
                    667:   return NULL;
                    668: }
                    669: 
                    670: static char **
                    671: new_completion (char *text, int start, int end)
                    672: {
                    673:   char **matches;
                    674: 
                    675:   matches = rl_completion_matches (text, command_generator);
                    676: 
                    677:   if (matches)
                    678:     {
                    679:       rl_point = rl_end;
                    680:       if (complete_status == CMD_COMPLETE_FULL_MATCH)
                    681:        rl_pending_input = ' ';
                    682:     }
                    683: 
                    684:   return matches;
                    685: }
                    686: 
                    687: #if 0
                    688: /* This function is not actually being used. */
                    689: static char **
                    690: vtysh_completion (char *text, int start, int end)
                    691: {
                    692:   int ret;
                    693:   vector vline;
                    694:   char **matched = NULL;
                    695: 
                    696:   if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
                    697:     return NULL;
                    698: 
                    699:   vline = cmd_make_strvec (rl_line_buffer);
                    700:   if (vline == NULL)
                    701:     return NULL;
                    702: 
                    703:   /* In case of 'help \t'. */
                    704:   if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
                    705:     vector_set (vline, '\0');
                    706: 
                    707:   matched = cmd_complete_command (vline, vty, &ret);
                    708: 
                    709:   cmd_free_strvec (vline);
                    710: 
                    711:   return (char **) matched;
                    712: }
                    713: #endif
                    714: 
                    715: /* Vty node structures. */
                    716: static struct cmd_node bgp_node =
                    717: {
                    718:   BGP_NODE,
                    719:   "%s(config-router)# ",
                    720: };
                    721: 
                    722: static struct cmd_node rip_node =
                    723: {
                    724:   RIP_NODE,
                    725:   "%s(config-router)# ",
                    726: };
                    727: 
                    728: static struct cmd_node isis_node =
                    729: {
                    730:   ISIS_NODE,
                    731:   "%s(config-router)# ",
                    732: };
                    733: 
                    734: static struct cmd_node interface_node =
                    735: {
                    736:   INTERFACE_NODE,
                    737:   "%s(config-if)# ",
                    738: };
                    739: 
                    740: static struct cmd_node rmap_node =
                    741: {
                    742:   RMAP_NODE,
                    743:   "%s(config-route-map)# "
                    744: };
                    745: 
                    746: static struct cmd_node zebra_node =
                    747: {
                    748:   ZEBRA_NODE,
                    749:   "%s(config-router)# "
                    750: };
                    751: 
                    752: static struct cmd_node bgp_vpnv4_node =
                    753: {
                    754:   BGP_VPNV4_NODE,
                    755:   "%s(config-router-af)# "
                    756: };
                    757: 
                    758: static struct cmd_node bgp_ipv4_node =
                    759: {
                    760:   BGP_IPV4_NODE,
                    761:   "%s(config-router-af)# "
                    762: };
                    763: 
                    764: static struct cmd_node bgp_ipv4m_node =
                    765: {
                    766:   BGP_IPV4M_NODE,
                    767:   "%s(config-router-af)# "
                    768: };
                    769: 
                    770: static struct cmd_node bgp_ipv6_node =
                    771: {
                    772:   BGP_IPV6_NODE,
                    773:   "%s(config-router-af)# "
                    774: };
                    775: 
                    776: static struct cmd_node bgp_ipv6m_node =
                    777: {
                    778:   BGP_IPV6M_NODE,
                    779:   "%s(config-router-af)# "
                    780: };
                    781: 
                    782: static struct cmd_node ospf_node =
                    783: {
                    784:   OSPF_NODE,
                    785:   "%s(config-router)# "
                    786: };
                    787: 
                    788: static struct cmd_node ripng_node =
                    789: {
                    790:   RIPNG_NODE,
                    791:   "%s(config-router)# "
                    792: };
                    793: 
                    794: static struct cmd_node ospf6_node =
                    795: {
                    796:   OSPF6_NODE,
                    797:   "%s(config-ospf6)# "
                    798: };
                    799: 
1.1.1.2   misho     800: static struct cmd_node babel_node =
                    801: {
                    802:   BABEL_NODE,
                    803:   "%s(config-babel)# "
                    804: };
                    805: 
1.1       misho     806: static struct cmd_node keychain_node =
                    807: {
                    808:   KEYCHAIN_NODE,
                    809:   "%s(config-keychain)# "
                    810: };
                    811: 
                    812: static struct cmd_node keychain_key_node =
                    813: {
                    814:   KEYCHAIN_KEY_NODE,
                    815:   "%s(config-keychain-key)# "
                    816: };
                    817: 
                    818: /* Defined in lib/vty.c */
                    819: extern struct cmd_node vty_node;
                    820: 
                    821: /* When '^Z' is received from vty, move down to the enable mode. */
                    822: int
                    823: vtysh_end (void)
                    824: {
                    825:   switch (vty->node)
                    826:     {
                    827:     case VIEW_NODE:
                    828:     case ENABLE_NODE:
                    829:       /* Nothing to do. */
                    830:       break;
                    831:     default:
                    832:       vty->node = ENABLE_NODE;
                    833:       break;
                    834:     }
                    835:   return CMD_SUCCESS;
                    836: }
                    837: 
                    838: DEFUNSH (VTYSH_ALL,
                    839:         vtysh_end_all,
                    840:         vtysh_end_all_cmd,
                    841:         "end",
                    842:         "End current mode and change to enable mode\n")
                    843: {
                    844:   return vtysh_end ();
                    845: }
                    846: 
                    847: DEFUNSH (VTYSH_BGPD,
                    848:         router_bgp,
                    849:         router_bgp_cmd,
                    850:         "router bgp " CMD_AS_RANGE,
                    851:         ROUTER_STR
                    852:         BGP_STR
                    853:         AS_STR)
                    854: {
                    855:   vty->node = BGP_NODE;
                    856:   return CMD_SUCCESS;
                    857: }
                    858: 
                    859: ALIAS_SH (VTYSH_BGPD,
                    860:          router_bgp,
                    861:          router_bgp_view_cmd,
                    862:          "router bgp " CMD_AS_RANGE " view WORD",
                    863:          ROUTER_STR
                    864:          BGP_STR
                    865:          AS_STR
                    866:          "BGP view\n"
                    867:          "view name\n")
                    868: 
                    869: DEFUNSH (VTYSH_BGPD,
                    870:         address_family_vpnv4,
                    871:         address_family_vpnv4_cmd,
                    872:         "address-family vpnv4",
                    873:         "Enter Address Family command mode\n"
                    874:         "Address family\n")
                    875: {
                    876:   vty->node = BGP_VPNV4_NODE;
                    877:   return CMD_SUCCESS;
                    878: }
                    879: 
                    880: DEFUNSH (VTYSH_BGPD,
                    881:         address_family_vpnv4_unicast,
                    882:         address_family_vpnv4_unicast_cmd,
                    883:         "address-family vpnv4 unicast",
                    884:         "Enter Address Family command mode\n"
                    885:         "Address family\n"
                    886:         "Address Family Modifier\n")
                    887: {
                    888:   vty->node = BGP_VPNV4_NODE;
                    889:   return CMD_SUCCESS;
                    890: }
                    891: 
                    892: DEFUNSH (VTYSH_BGPD,
                    893:         address_family_ipv4_unicast,
                    894:         address_family_ipv4_unicast_cmd,
                    895:         "address-family ipv4 unicast",
                    896:         "Enter Address Family command mode\n"
                    897:         "Address family\n"
                    898:         "Address Family Modifier\n")
                    899: {
                    900:   vty->node = BGP_IPV4_NODE;
                    901:   return CMD_SUCCESS;
                    902: }
                    903: 
                    904: DEFUNSH (VTYSH_BGPD,
                    905:         address_family_ipv4_multicast,
                    906:         address_family_ipv4_multicast_cmd,
                    907:         "address-family ipv4 multicast",
                    908:         "Enter Address Family command mode\n"
                    909:         "Address family\n"
                    910:         "Address Family Modifier\n")
                    911: {
                    912:   vty->node = BGP_IPV4M_NODE;
                    913:   return CMD_SUCCESS;
                    914: }
                    915: 
                    916: DEFUNSH (VTYSH_BGPD,
                    917:         address_family_ipv6,
                    918:         address_family_ipv6_cmd,
                    919:         "address-family ipv6",
                    920:         "Enter Address Family command mode\n"
                    921:         "Address family\n")
                    922: {
                    923:   vty->node = BGP_IPV6_NODE;
                    924:   return CMD_SUCCESS;
                    925: }
                    926: 
                    927: DEFUNSH (VTYSH_BGPD,
                    928:         address_family_ipv6_unicast,
                    929:         address_family_ipv6_unicast_cmd,
                    930:         "address-family ipv6 unicast",
                    931:         "Enter Address Family command mode\n"
                    932:         "Address family\n"
                    933:         "Address Family Modifier\n")
                    934: {
                    935:   vty->node = BGP_IPV6_NODE;
                    936:   return CMD_SUCCESS;
                    937: }
                    938: 
                    939: DEFUNSH (VTYSH_BGPD,
                    940:         address_family_ipv6_multicast,
                    941:         address_family_ipv6_multicast_cmd,
                    942:         "address-family ipv6 multicast",
                    943:         "Enter Address Family command mode\n"
                    944:         "Address family\n"
                    945:         "Address Family Modifier\n")
                    946: {
                    947:   vty->node = BGP_IPV6M_NODE;
                    948:   return CMD_SUCCESS;
                    949: }
                    950: 
                    951: DEFUNSH (VTYSH_RIPD,
                    952:         key_chain,
                    953:         key_chain_cmd,
                    954:         "key chain WORD",
                    955:         "Authentication key management\n"
                    956:         "Key-chain management\n"
                    957:         "Key-chain name\n")
                    958: {
                    959:   vty->node = KEYCHAIN_NODE;
                    960:   return CMD_SUCCESS;
                    961: }       
                    962: 
                    963: DEFUNSH (VTYSH_RIPD,
                    964:         key,
                    965:         key_cmd,
                    966:         "key <0-2147483647>",
                    967:         "Configure a key\n"
                    968:         "Key identifier number\n")
                    969: {
                    970:   vty->node = KEYCHAIN_KEY_NODE;
                    971:   return CMD_SUCCESS;
                    972: }
                    973: 
                    974: DEFUNSH (VTYSH_RIPD,
                    975:         router_rip,
                    976:         router_rip_cmd,
                    977:         "router rip",
                    978:         ROUTER_STR
                    979:         "RIP")
                    980: {
                    981:   vty->node = RIP_NODE;
                    982:   return CMD_SUCCESS;
                    983: }
                    984: 
                    985: DEFUNSH (VTYSH_RIPNGD,
                    986:         router_ripng,
                    987:         router_ripng_cmd,
                    988:         "router ripng",
                    989:         ROUTER_STR
                    990:         "RIPng")
                    991: {
                    992:   vty->node = RIPNG_NODE;
                    993:   return CMD_SUCCESS;
                    994: }
                    995: 
                    996: DEFUNSH (VTYSH_OSPFD,
                    997:         router_ospf,
                    998:         router_ospf_cmd,
                    999:         "router ospf",
                   1000:         "Enable a routing process\n"
                   1001:         "Start OSPF configuration\n")
                   1002: {
                   1003:   vty->node = OSPF_NODE;
                   1004:   return CMD_SUCCESS;
                   1005: }
                   1006: 
                   1007: DEFUNSH (VTYSH_OSPF6D,
                   1008:         router_ospf6,
                   1009:         router_ospf6_cmd,
                   1010:         "router ospf6",
                   1011:         OSPF6_ROUTER_STR
                   1012:         OSPF6_STR)
                   1013: {
                   1014:   vty->node = OSPF6_NODE;
                   1015:   return CMD_SUCCESS;
                   1016: }
                   1017: 
1.1.1.2   misho    1018: DEFUNSH (VTYSH_BABELD,
                   1019:         router_babel,
                   1020:         router_babel_cmd,
                   1021:         "router babel",
                   1022:         ROUTER_STR
                   1023:         "Babel")
                   1024: {
                   1025:   vty->node = BABEL_NODE;
                   1026:   return CMD_SUCCESS;
                   1027: }
                   1028: 
1.1       misho    1029: DEFUNSH (VTYSH_ISISD,
                   1030:         router_isis,
                   1031:         router_isis_cmd,
                   1032:         "router isis WORD",
                   1033:         ROUTER_STR
                   1034:         "ISO IS-IS\n"
                   1035:         "ISO Routing area tag")
                   1036: {
                   1037:   vty->node = ISIS_NODE;
                   1038:   return CMD_SUCCESS;
                   1039: }
                   1040: 
                   1041: DEFUNSH (VTYSH_RMAP,
                   1042:         route_map,
                   1043:         route_map_cmd,
                   1044:         "route-map WORD (deny|permit) <1-65535>",
                   1045:         "Create route-map or enter route-map command mode\n"
                   1046:         "Route map tag\n"
                   1047:         "Route map denies set operations\n"
                   1048:         "Route map permits set operations\n"
                   1049:         "Sequence to insert to/delete from existing route-map entry\n")
                   1050: {
                   1051:   vty->node = RMAP_NODE;
                   1052:   return CMD_SUCCESS;
                   1053: }
                   1054: 
                   1055: DEFUNSH (VTYSH_ALL,
                   1056:         vtysh_line_vty,
                   1057:         vtysh_line_vty_cmd,
                   1058:         "line vty",
                   1059:         "Configure a terminal line\n"
                   1060:         "Virtual terminal\n")
                   1061: {
                   1062:   vty->node = VTY_NODE;
                   1063:   return CMD_SUCCESS;
                   1064: }
                   1065: 
                   1066: DEFUNSH (VTYSH_ALL,
                   1067:         vtysh_enable, 
                   1068:         vtysh_enable_cmd,
                   1069:         "enable",
                   1070:         "Turn on privileged mode command\n")
                   1071: {
                   1072:   vty->node = ENABLE_NODE;
                   1073:   return CMD_SUCCESS;
                   1074: }
                   1075: 
                   1076: DEFUNSH (VTYSH_ALL,
                   1077:         vtysh_disable, 
                   1078:         vtysh_disable_cmd,
                   1079:         "disable",
                   1080:         "Turn off privileged mode command\n")
                   1081: {
                   1082:   if (vty->node == ENABLE_NODE)
                   1083:     vty->node = VIEW_NODE;
                   1084:   return CMD_SUCCESS;
                   1085: }
                   1086: 
                   1087: DEFUNSH (VTYSH_ALL,
                   1088:         vtysh_config_terminal,
                   1089:         vtysh_config_terminal_cmd,
                   1090:         "configure terminal",
                   1091:         "Configuration from vty interface\n"
                   1092:         "Configuration terminal\n")
                   1093: {
                   1094:   vty->node = CONFIG_NODE;
                   1095:   return CMD_SUCCESS;
                   1096: }
                   1097: 
                   1098: static int
                   1099: vtysh_exit (struct vty *vty)
                   1100: {
                   1101:   switch (vty->node)
                   1102:     {
                   1103:     case VIEW_NODE:
                   1104:     case ENABLE_NODE:
                   1105:       exit (0);
                   1106:       break;
                   1107:     case CONFIG_NODE:
                   1108:       vty->node = ENABLE_NODE;
                   1109:       break;
                   1110:     case INTERFACE_NODE:
                   1111:     case ZEBRA_NODE:
                   1112:     case BGP_NODE:
                   1113:     case RIP_NODE:
                   1114:     case RIPNG_NODE:
                   1115:     case OSPF_NODE:
                   1116:     case OSPF6_NODE:
1.1.1.2   misho    1117:     case BABEL_NODE:
1.1       misho    1118:     case ISIS_NODE:
                   1119:     case MASC_NODE:
                   1120:     case RMAP_NODE:
                   1121:     case VTY_NODE:
                   1122:     case KEYCHAIN_NODE:
                   1123:       vtysh_execute("end");
                   1124:       vtysh_execute("configure terminal");
                   1125:       vty->node = CONFIG_NODE;
                   1126:       break;
                   1127:     case BGP_VPNV4_NODE:
                   1128:     case BGP_IPV4_NODE:
                   1129:     case BGP_IPV4M_NODE:
                   1130:     case BGP_IPV6_NODE:
                   1131:     case BGP_IPV6M_NODE:
                   1132:       vty->node = BGP_NODE;
                   1133:       break;
                   1134:     case KEYCHAIN_KEY_NODE:
                   1135:       vty->node = KEYCHAIN_NODE;
                   1136:       break;
                   1137:     default:
                   1138:       break;
                   1139:     }
                   1140:   return CMD_SUCCESS;
                   1141: }
                   1142: 
                   1143: DEFUNSH (VTYSH_ALL,
                   1144:         vtysh_exit_all,
                   1145:         vtysh_exit_all_cmd,
                   1146:         "exit",
                   1147:         "Exit current mode and down to previous mode\n")
                   1148: {
                   1149:   return vtysh_exit (vty);
                   1150: }
                   1151: 
                   1152: ALIAS (vtysh_exit_all,
                   1153:        vtysh_quit_all_cmd,
                   1154:        "quit",
                   1155:        "Exit current mode and down to previous mode\n")
                   1156: 
                   1157: DEFUNSH (VTYSH_BGPD,
                   1158:         exit_address_family,
                   1159:         exit_address_family_cmd,
                   1160:         "exit-address-family",
                   1161:         "Exit from Address Family configuration mode\n")
                   1162: {
                   1163:   if (vty->node == BGP_IPV4_NODE
                   1164:       || vty->node == BGP_IPV4M_NODE
                   1165:       || vty->node == BGP_VPNV4_NODE
                   1166:       || vty->node == BGP_IPV6_NODE
                   1167:       || vty->node == BGP_IPV6M_NODE)
                   1168:     vty->node = BGP_NODE;
                   1169:   return CMD_SUCCESS;
                   1170: }
                   1171: 
                   1172: DEFUNSH (VTYSH_ZEBRA,
                   1173:         vtysh_exit_zebra,
                   1174:         vtysh_exit_zebra_cmd,
                   1175:         "exit",
                   1176:         "Exit current mode and down to previous mode\n")
                   1177: {
                   1178:   return vtysh_exit (vty);
                   1179: }
                   1180: 
                   1181: ALIAS (vtysh_exit_zebra,
                   1182:        vtysh_quit_zebra_cmd,
                   1183:        "quit",
                   1184:        "Exit current mode and down to previous mode\n")
                   1185: 
                   1186: DEFUNSH (VTYSH_RIPD,
                   1187:         vtysh_exit_ripd,
                   1188:         vtysh_exit_ripd_cmd,
                   1189:         "exit",
                   1190:         "Exit current mode and down to previous mode\n")
                   1191: {
                   1192:   return vtysh_exit (vty);
                   1193: }
                   1194: 
                   1195: ALIAS (vtysh_exit_ripd,
                   1196:        vtysh_quit_ripd_cmd,
                   1197:        "quit",
                   1198:        "Exit current mode and down to previous mode\n")
                   1199: 
                   1200: DEFUNSH (VTYSH_RIPNGD,
                   1201:         vtysh_exit_ripngd,
                   1202:         vtysh_exit_ripngd_cmd,
                   1203:         "exit",
                   1204:         "Exit current mode and down to previous mode\n")
                   1205: {
                   1206:   return vtysh_exit (vty);
                   1207: }
                   1208: 
                   1209: ALIAS (vtysh_exit_ripngd,
                   1210:        vtysh_quit_ripngd_cmd,
                   1211:        "quit",
                   1212:        "Exit current mode and down to previous mode\n")
                   1213: 
                   1214: DEFUNSH (VTYSH_RMAP,
                   1215:         vtysh_exit_rmap,
                   1216:         vtysh_exit_rmap_cmd,
                   1217:         "exit",
                   1218:         "Exit current mode and down to previous mode\n")
                   1219: {
                   1220:   return vtysh_exit (vty);
                   1221: }
                   1222: 
                   1223: ALIAS (vtysh_exit_rmap,
                   1224:        vtysh_quit_rmap_cmd,
                   1225:        "quit",
                   1226:        "Exit current mode and down to previous mode\n")
                   1227: 
                   1228: DEFUNSH (VTYSH_BGPD,
                   1229:         vtysh_exit_bgpd,
                   1230:         vtysh_exit_bgpd_cmd,
                   1231:         "exit",
                   1232:         "Exit current mode and down to previous mode\n")
                   1233: {
                   1234:   return vtysh_exit (vty);
                   1235: }
                   1236: 
                   1237: ALIAS (vtysh_exit_bgpd,
                   1238:        vtysh_quit_bgpd_cmd,
                   1239:        "quit",
                   1240:        "Exit current mode and down to previous mode\n")
                   1241: 
                   1242: DEFUNSH (VTYSH_OSPFD,
                   1243:         vtysh_exit_ospfd,
                   1244:         vtysh_exit_ospfd_cmd,
                   1245:         "exit",
                   1246:         "Exit current mode and down to previous mode\n")
                   1247: {
                   1248:   return vtysh_exit (vty);
                   1249: }
                   1250: 
                   1251: ALIAS (vtysh_exit_ospfd,
                   1252:        vtysh_quit_ospfd_cmd,
                   1253:        "quit",
                   1254:        "Exit current mode and down to previous mode\n")
                   1255: 
                   1256: DEFUNSH (VTYSH_OSPF6D,
                   1257:         vtysh_exit_ospf6d,
                   1258:         vtysh_exit_ospf6d_cmd,
                   1259:         "exit",
                   1260:         "Exit current mode and down to previous mode\n")
                   1261: {
                   1262:   return vtysh_exit (vty);
                   1263: }
                   1264: 
                   1265: ALIAS (vtysh_exit_ospf6d,
                   1266:        vtysh_quit_ospf6d_cmd,
                   1267:        "quit",
                   1268:        "Exit current mode and down to previous mode\n")
                   1269: 
                   1270: DEFUNSH (VTYSH_ISISD,
                   1271:         vtysh_exit_isisd,
                   1272:         vtysh_exit_isisd_cmd,
                   1273:         "exit",
                   1274:         "Exit current mode and down to previous mode\n")
                   1275: {
                   1276:   return vtysh_exit (vty);
                   1277: }
                   1278: 
                   1279: ALIAS (vtysh_exit_isisd,
                   1280:        vtysh_quit_isisd_cmd,
                   1281:        "quit",
                   1282:        "Exit current mode and down to previous mode\n")
                   1283: 
                   1284: DEFUNSH (VTYSH_ALL,
                   1285:          vtysh_exit_line_vty,
                   1286:          vtysh_exit_line_vty_cmd,
                   1287:          "exit",
                   1288:          "Exit current mode and down to previous mode\n")
                   1289: {
                   1290:   return vtysh_exit (vty);
                   1291: }
                   1292: 
                   1293: ALIAS (vtysh_exit_line_vty,
                   1294:        vtysh_quit_line_vty_cmd,
                   1295:        "quit",
                   1296:        "Exit current mode and down to previous mode\n")
                   1297: 
                   1298: DEFUNSH (VTYSH_INTERFACE,
                   1299:         vtysh_interface,
                   1300:         vtysh_interface_cmd,
                   1301:         "interface IFNAME",
                   1302:         "Select an interface to configure\n"
                   1303:         "Interface's name\n")
                   1304: {
                   1305:   vty->node = INTERFACE_NODE;
                   1306:   return CMD_SUCCESS;
                   1307: }
                   1308: 
                   1309: /* TODO Implement "no interface command in isisd. */
                   1310: DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D,
                   1311:        vtysh_no_interface_cmd,
                   1312:        "no interface IFNAME",
                   1313:        NO_STR
                   1314:        "Delete a pseudo interface's configuration\n"
                   1315:        "Interface's name\n")
                   1316: 
                   1317: /* TODO Implement interface description commands in ripngd, ospf6d
                   1318:  * and isisd. */
                   1319: DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
                   1320:        interface_desc_cmd,
                   1321:        "description .LINE",
                   1322:        "Interface specific description\n"
                   1323:        "Characters describing this interface\n")
                   1324:        
                   1325: DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
                   1326:        no_interface_desc_cmd,
                   1327:        "no description",
                   1328:        NO_STR
                   1329:        "Interface specific description\n")
                   1330: 
                   1331: DEFUNSH (VTYSH_INTERFACE,
                   1332:         vtysh_exit_interface,
                   1333:         vtysh_exit_interface_cmd,
                   1334:         "exit",
                   1335:         "Exit current mode and down to previous mode\n")
                   1336: {
                   1337:   return vtysh_exit (vty);
                   1338: }
                   1339: 
                   1340: ALIAS (vtysh_exit_interface,
                   1341:        vtysh_quit_interface_cmd,
                   1342:        "quit",
                   1343:        "Exit current mode and down to previous mode\n")
                   1344: 
                   1345: /* Memory */
                   1346: DEFUN (vtysh_show_memory,
                   1347:        vtysh_show_memory_cmd,
                   1348:        "show memory",
                   1349:        SHOW_STR
                   1350:        "Memory statistics\n")
                   1351: {
                   1352:   unsigned int i;
                   1353:   int ret = CMD_SUCCESS;
                   1354:   char line[] = "show memory\n";
                   1355:   
1.1.1.3 ! misho    1356:   for (i = 0; i < array_size(vtysh_client); i++)
1.1       misho    1357:     if ( vtysh_client[i].fd >= 0 )
                   1358:       {
                   1359:         fprintf (stdout, "Memory statistics for %s:\n", 
                   1360:                  vtysh_client[i].name);
                   1361:         ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
                   1362:         fprintf (stdout,"\n");
                   1363:       }
                   1364:   
                   1365:   return ret;
                   1366: }
                   1367: 
                   1368: /* Logging commands. */
                   1369: DEFUN (vtysh_show_logging,
                   1370:        vtysh_show_logging_cmd,
                   1371:        "show logging",
                   1372:        SHOW_STR
                   1373:        "Show current logging configuration\n")
                   1374: {
                   1375:   unsigned int i;
                   1376:   int ret = CMD_SUCCESS;
                   1377:   char line[] = "show logging\n";
                   1378:   
1.1.1.3 ! misho    1379:   for (i = 0; i < array_size(vtysh_client); i++)
1.1       misho    1380:     if ( vtysh_client[i].fd >= 0 )
                   1381:       {
                   1382:         fprintf (stdout,"Logging configuration for %s:\n", 
                   1383:                  vtysh_client[i].name);
                   1384:         ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
                   1385:         fprintf (stdout,"\n");
                   1386:       }
                   1387:   
                   1388:   return ret;
                   1389: }
                   1390: 
                   1391: DEFUNSH (VTYSH_ALL,
                   1392:         vtysh_log_stdout,
                   1393:         vtysh_log_stdout_cmd,
                   1394:         "log stdout",
                   1395:         "Logging control\n"
                   1396:         "Set stdout logging level\n")
                   1397: {
                   1398:   return CMD_SUCCESS;
                   1399: }
                   1400: 
                   1401: DEFUNSH (VTYSH_ALL,
                   1402:         vtysh_log_stdout_level,
                   1403:         vtysh_log_stdout_level_cmd,
                   1404:         "log stdout "LOG_LEVELS,
                   1405:         "Logging control\n"
                   1406:         "Set stdout logging level\n"
                   1407:         LOG_LEVEL_DESC)
                   1408: {
                   1409:   return CMD_SUCCESS;
                   1410: }
                   1411: 
                   1412: DEFUNSH (VTYSH_ALL,
                   1413:         no_vtysh_log_stdout,
                   1414:         no_vtysh_log_stdout_cmd,
                   1415:         "no log stdout [LEVEL]",
                   1416:         NO_STR
                   1417:         "Logging control\n"
                   1418:         "Cancel logging to stdout\n"
                   1419:         "Logging level\n")
                   1420: {
                   1421:   return CMD_SUCCESS;
                   1422: }
                   1423: 
                   1424: DEFUNSH (VTYSH_ALL,
                   1425:         vtysh_log_file,
                   1426:         vtysh_log_file_cmd,
                   1427:         "log file FILENAME",
                   1428:         "Logging control\n"
                   1429:         "Logging to file\n"
                   1430:         "Logging filename\n")
                   1431: {
                   1432:   return CMD_SUCCESS;
                   1433: }
                   1434: 
                   1435: DEFUNSH (VTYSH_ALL,
                   1436:         vtysh_log_file_level,
                   1437:         vtysh_log_file_level_cmd,
                   1438:         "log file FILENAME "LOG_LEVELS,
                   1439:         "Logging control\n"
                   1440:         "Logging to file\n"
                   1441:         "Logging filename\n"
                   1442:         LOG_LEVEL_DESC)
                   1443: {
                   1444:   return CMD_SUCCESS;
                   1445: }
                   1446: 
                   1447: DEFUNSH (VTYSH_ALL,
                   1448:         no_vtysh_log_file,
                   1449:         no_vtysh_log_file_cmd,
                   1450:         "no log file [FILENAME]",
                   1451:         NO_STR
                   1452:         "Logging control\n"
                   1453:         "Cancel logging to file\n"
                   1454:         "Logging file name\n")
                   1455: {
                   1456:   return CMD_SUCCESS;
                   1457: }
                   1458: 
                   1459: ALIAS_SH (VTYSH_ALL,
                   1460:          no_vtysh_log_file,
                   1461:          no_vtysh_log_file_level_cmd,
                   1462:          "no log file FILENAME LEVEL",
                   1463:          NO_STR
                   1464:          "Logging control\n"
                   1465:          "Cancel logging to file\n"
                   1466:          "Logging file name\n"
                   1467:          "Logging level\n")
                   1468: 
                   1469: DEFUNSH (VTYSH_ALL,
                   1470:         vtysh_log_monitor,
                   1471:         vtysh_log_monitor_cmd,
                   1472:         "log monitor",
                   1473:         "Logging control\n"
                   1474:         "Set terminal line (monitor) logging level\n")
                   1475: {
                   1476:   return CMD_SUCCESS;
                   1477: }
                   1478: 
                   1479: DEFUNSH (VTYSH_ALL,
                   1480:         vtysh_log_monitor_level,
                   1481:         vtysh_log_monitor_level_cmd,
                   1482:         "log monitor "LOG_LEVELS,
                   1483:         "Logging control\n"
                   1484:         "Set terminal line (monitor) logging level\n"
                   1485:         LOG_LEVEL_DESC)
                   1486: {
                   1487:   return CMD_SUCCESS;
                   1488: }
                   1489: 
                   1490: DEFUNSH (VTYSH_ALL,
                   1491:         no_vtysh_log_monitor,
                   1492:         no_vtysh_log_monitor_cmd,
                   1493:         "no log monitor [LEVEL]",
                   1494:         NO_STR
                   1495:         "Logging control\n"
                   1496:         "Disable terminal line (monitor) logging\n"
                   1497:         "Logging level\n")
                   1498: {
                   1499:   return CMD_SUCCESS;
                   1500: }
                   1501: 
                   1502: DEFUNSH (VTYSH_ALL,
                   1503:         vtysh_log_syslog,
                   1504:         vtysh_log_syslog_cmd,
                   1505:         "log syslog",
                   1506:         "Logging control\n"
                   1507:         "Set syslog logging level\n")
                   1508: {
                   1509:   return CMD_SUCCESS;
                   1510: }
                   1511: 
                   1512: DEFUNSH (VTYSH_ALL,
                   1513:         vtysh_log_syslog_level,
                   1514:         vtysh_log_syslog_level_cmd,
                   1515:         "log syslog "LOG_LEVELS,
                   1516:         "Logging control\n"
                   1517:         "Set syslog logging level\n"
                   1518:         LOG_LEVEL_DESC)
                   1519: {
                   1520:   return CMD_SUCCESS;
                   1521: }
                   1522: 
                   1523: DEFUNSH (VTYSH_ALL,
                   1524:         no_vtysh_log_syslog,
                   1525:         no_vtysh_log_syslog_cmd,
                   1526:         "no log syslog [LEVEL]",
                   1527:         NO_STR
                   1528:         "Logging control\n"
                   1529:         "Cancel logging to syslog\n"
                   1530:         "Logging level\n")
                   1531: {
                   1532:   return CMD_SUCCESS;
                   1533: }
                   1534: 
                   1535: DEFUNSH (VTYSH_ALL,
                   1536:         vtysh_log_facility,
                   1537:         vtysh_log_facility_cmd,
                   1538:         "log facility "LOG_FACILITIES,
                   1539:         "Logging control\n"
                   1540:         "Facility parameter for syslog messages\n"
                   1541:         LOG_FACILITY_DESC)
                   1542: 
                   1543: {
                   1544:   return CMD_SUCCESS;
                   1545: }
                   1546: 
                   1547: DEFUNSH (VTYSH_ALL,
                   1548:         no_vtysh_log_facility,
                   1549:         no_vtysh_log_facility_cmd,
                   1550:         "no log facility [FACILITY]",
                   1551:         NO_STR
                   1552:         "Logging control\n"
                   1553:         "Reset syslog facility to default (daemon)\n"
                   1554:         "Syslog facility\n")
                   1555: 
                   1556: {
                   1557:   return CMD_SUCCESS;
                   1558: }
                   1559: 
                   1560: DEFUNSH_DEPRECATED (VTYSH_ALL,
                   1561:                    vtysh_log_trap,
                   1562:                    vtysh_log_trap_cmd,
                   1563:                    "log trap "LOG_LEVELS,
                   1564:                    "Logging control\n"
                   1565:                    "(Deprecated) Set logging level and default for all destinations\n"
                   1566:                    LOG_LEVEL_DESC)
                   1567: 
                   1568: {
                   1569:   return CMD_SUCCESS;
                   1570: }
                   1571: 
                   1572: DEFUNSH_DEPRECATED (VTYSH_ALL,
                   1573:                    no_vtysh_log_trap,
                   1574:                    no_vtysh_log_trap_cmd,
                   1575:                    "no log trap [LEVEL]",
                   1576:                    NO_STR
                   1577:                    "Logging control\n"
                   1578:                    "Permit all logging information\n"
                   1579:                    "Logging level\n")
                   1580: {
                   1581:   return CMD_SUCCESS;
                   1582: }
                   1583: 
                   1584: DEFUNSH (VTYSH_ALL,
                   1585:         vtysh_log_record_priority,
                   1586:         vtysh_log_record_priority_cmd,
                   1587:         "log record-priority",
                   1588:         "Logging control\n"
                   1589:         "Log the priority of the message within the message\n")
                   1590: {
                   1591:   return CMD_SUCCESS;
                   1592: }
                   1593: 
                   1594: DEFUNSH (VTYSH_ALL,
                   1595:         no_vtysh_log_record_priority,
                   1596:         no_vtysh_log_record_priority_cmd,
                   1597:         "no log record-priority",
                   1598:         NO_STR
                   1599:         "Logging control\n"
                   1600:         "Do not log the priority of the message within the message\n")
                   1601: {
                   1602:   return CMD_SUCCESS;
                   1603: }
                   1604: 
                   1605: DEFUNSH (VTYSH_ALL,
                   1606:         vtysh_log_timestamp_precision,
                   1607:         vtysh_log_timestamp_precision_cmd,
                   1608:         "log timestamp precision <0-6>",
                   1609:         "Logging control\n"
                   1610:         "Timestamp configuration\n"
                   1611:         "Set the timestamp precision\n"
                   1612:         "Number of subsecond digits\n")
                   1613: {
                   1614:   return CMD_SUCCESS;
                   1615: }
                   1616: 
                   1617: DEFUNSH (VTYSH_ALL,
                   1618:         no_vtysh_log_timestamp_precision,
                   1619:         no_vtysh_log_timestamp_precision_cmd,
                   1620:         "no log timestamp precision",
                   1621:         NO_STR
                   1622:         "Logging control\n"
                   1623:         "Timestamp configuration\n"
                   1624:         "Reset the timestamp precision to the default value of 0\n")
                   1625: {
                   1626:   return CMD_SUCCESS;
                   1627: }
                   1628: 
                   1629: DEFUNSH (VTYSH_ALL,
                   1630:         vtysh_service_password_encrypt,
                   1631:         vtysh_service_password_encrypt_cmd,
                   1632:         "service password-encryption",
                   1633:         "Set up miscellaneous service\n"
                   1634:         "Enable encrypted passwords\n")
                   1635: {
                   1636:   return CMD_SUCCESS;
                   1637: }
                   1638: 
                   1639: DEFUNSH (VTYSH_ALL,
                   1640:         no_vtysh_service_password_encrypt,
                   1641:         no_vtysh_service_password_encrypt_cmd,
                   1642:         "no service password-encryption",
                   1643:         NO_STR
                   1644:         "Set up miscellaneous service\n"
                   1645:         "Enable encrypted passwords\n")
                   1646: {
                   1647:   return CMD_SUCCESS;
                   1648: }
                   1649: 
                   1650: DEFUNSH (VTYSH_ALL,
                   1651:         vtysh_config_password,
                   1652:         vtysh_password_cmd,
                   1653:         "password (8|) WORD",
                   1654:         "Assign the terminal connection password\n"
                   1655:         "Specifies a HIDDEN password will follow\n"
                   1656:         "dummy string \n"
                   1657:         "The HIDDEN line password string\n")
                   1658: {
                   1659:   return CMD_SUCCESS;
                   1660: }
                   1661: 
                   1662: DEFUNSH (VTYSH_ALL,
                   1663:         vtysh_password_text,
                   1664:         vtysh_password_text_cmd,
                   1665:         "password LINE",
                   1666:         "Assign the terminal connection password\n"
                   1667:         "The UNENCRYPTED (cleartext) line password\n")
                   1668: {
                   1669:   return CMD_SUCCESS;
                   1670: }
                   1671: 
                   1672: DEFUNSH (VTYSH_ALL,
                   1673:         vtysh_config_enable_password,
                   1674:         vtysh_enable_password_cmd,
                   1675:         "enable password (8|) WORD",
                   1676:         "Modify enable password parameters\n"
                   1677:         "Assign the privileged level password\n"
                   1678:         "Specifies a HIDDEN password will follow\n"
                   1679:         "dummy string \n"
                   1680:         "The HIDDEN 'enable' password string\n")
                   1681: {
                   1682:   return CMD_SUCCESS;
                   1683: }
                   1684: 
                   1685: DEFUNSH (VTYSH_ALL,
                   1686:         vtysh_enable_password_text,
                   1687:         vtysh_enable_password_text_cmd,
                   1688:         "enable password LINE",
                   1689:         "Modify enable password parameters\n"
                   1690:         "Assign the privileged level password\n"
                   1691:         "The UNENCRYPTED (cleartext) 'enable' password\n")
                   1692: {
                   1693:   return CMD_SUCCESS;
                   1694: }
                   1695: 
                   1696: DEFUNSH (VTYSH_ALL,
                   1697:         no_vtysh_config_enable_password,
                   1698:         no_vtysh_enable_password_cmd,
                   1699:         "no enable password",
                   1700:         NO_STR
                   1701:         "Modify enable password parameters\n"
                   1702:         "Assign the privileged level password\n")
                   1703: {
                   1704:   return CMD_SUCCESS;
                   1705: }
                   1706: 
                   1707: DEFUN (vtysh_write_terminal,
                   1708:        vtysh_write_terminal_cmd,
                   1709:        "write terminal",
                   1710:        "Write running configuration to memory, network, or terminal\n"
                   1711:        "Write to terminal\n")
                   1712: {
                   1713:   u_int i;
                   1714:   int ret;
                   1715:   char line[] = "write terminal\n";
                   1716:   FILE *fp = NULL;
                   1717: 
                   1718:   if (vtysh_pager_name)
                   1719:     {
                   1720:       fp = popen (vtysh_pager_name, "w");
                   1721:       if (fp == NULL)
                   1722:        {
                   1723:          perror ("popen");
                   1724:          exit (1);
                   1725:        }
                   1726:     }
                   1727:   else
                   1728:     fp = stdout;
                   1729: 
                   1730:   vty_out (vty, "Building configuration...%s", VTY_NEWLINE);
                   1731:   vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE,
                   1732:           VTY_NEWLINE);
                   1733:   vty_out (vty, "!%s", VTY_NEWLINE);
                   1734: 
1.1.1.3 ! misho    1735:   for (i = 0; i < array_size(vtysh_client); i++)
1.1       misho    1736:     ret = vtysh_client_config (&vtysh_client[i], line);
                   1737: 
                   1738:   /* Integrate vtysh specific configuration. */
                   1739:   vtysh_config_write ();
                   1740: 
                   1741:   vtysh_config_dump (fp);
                   1742: 
                   1743:   if (vtysh_pager_name && fp)
                   1744:     {
                   1745:       fflush (fp);
                   1746:       if (pclose (fp) == -1)
                   1747:        {
                   1748:          perror ("pclose");
                   1749:          exit (1);
                   1750:        }
                   1751:       fp = NULL;
                   1752:     }
                   1753: 
                   1754:   vty_out (vty, "end%s", VTY_NEWLINE);
                   1755:   
                   1756:   return CMD_SUCCESS;
                   1757: }
                   1758: 
                   1759: DEFUN (vtysh_integrated_config,
                   1760:        vtysh_integrated_config_cmd,
                   1761:        "service integrated-vtysh-config",
                   1762:        "Set up miscellaneous service\n"
                   1763:        "Write configuration into integrated file\n")
                   1764: {
                   1765:   vtysh_writeconfig_integrated = 1;
                   1766:   return CMD_SUCCESS;
                   1767: }
                   1768: 
                   1769: DEFUN (no_vtysh_integrated_config,
                   1770:        no_vtysh_integrated_config_cmd,
                   1771:        "no service integrated-vtysh-config",
                   1772:        NO_STR
                   1773:        "Set up miscellaneous service\n"
                   1774:        "Write configuration into integrated file\n")
                   1775: {
                   1776:   vtysh_writeconfig_integrated = 0;
                   1777:   return CMD_SUCCESS;
                   1778: }
                   1779: 
                   1780: static int
                   1781: write_config_integrated(void)
                   1782: {
                   1783:   u_int i;
                   1784:   int ret;
                   1785:   char line[] = "write terminal\n";
                   1786:   FILE *fp;
                   1787:   char *integrate_sav = NULL;
                   1788: 
                   1789:   integrate_sav = malloc (strlen (integrate_default) +
                   1790:                          strlen (CONF_BACKUP_EXT) + 1);
                   1791:   strcpy (integrate_sav, integrate_default);
                   1792:   strcat (integrate_sav, CONF_BACKUP_EXT);
                   1793: 
                   1794:   fprintf (stdout,"Building Configuration...\n");
                   1795: 
                   1796:   /* Move current configuration file to backup config file. */
                   1797:   unlink (integrate_sav);
                   1798:   rename (integrate_default, integrate_sav);
                   1799:   free (integrate_sav);
                   1800:  
                   1801:   fp = fopen (integrate_default, "w");
                   1802:   if (fp == NULL)
                   1803:     {
                   1804:       fprintf (stdout,"%% Can't open configuration file %s.\n",
                   1805:               integrate_default);
                   1806:       return CMD_SUCCESS;
                   1807:     }
                   1808: 
1.1.1.3 ! misho    1809:   for (i = 0; i < array_size(vtysh_client); i++)
1.1       misho    1810:     ret = vtysh_client_config (&vtysh_client[i], line);
                   1811: 
                   1812:   vtysh_config_dump (fp);
                   1813: 
                   1814:   fclose (fp);
                   1815: 
                   1816:   if (chmod (integrate_default, CONFIGFILE_MASK) != 0)
                   1817:     {
                   1818:       fprintf (stdout,"%% Can't chmod configuration file %s: %s (%d)\n", 
                   1819:        integrate_default, safe_strerror(errno), errno);
                   1820:       return CMD_WARNING;
                   1821:     }
                   1822: 
                   1823:   fprintf(stdout,"Integrated configuration saved to %s\n",integrate_default);
                   1824: 
                   1825:   fprintf (stdout,"[OK]\n");
                   1826: 
                   1827:   return CMD_SUCCESS;
                   1828: }
                   1829: 
                   1830: DEFUN (vtysh_write_memory,
                   1831:        vtysh_write_memory_cmd,
                   1832:        "write memory",
                   1833:        "Write running configuration to memory, network, or terminal\n"
                   1834:        "Write configuration to the file (same as write file)\n")
                   1835: {
                   1836:   int ret = CMD_SUCCESS;
                   1837:   char line[] = "write memory\n";
                   1838:   u_int i;
                   1839:   
                   1840:   /* If integrated Quagga.conf explicitely set. */
                   1841:   if (vtysh_writeconfig_integrated)
                   1842:     return write_config_integrated();
                   1843: 
                   1844:   fprintf (stdout,"Building Configuration...\n");
                   1845:          
1.1.1.3 ! misho    1846:   for (i = 0; i < array_size(vtysh_client); i++)
1.1       misho    1847:     ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
                   1848:   
                   1849:   fprintf (stdout,"[OK]\n");
                   1850: 
                   1851:   return ret;
                   1852: }
                   1853: 
                   1854: ALIAS (vtysh_write_memory,
                   1855:        vtysh_copy_runningconfig_startupconfig_cmd,
                   1856:        "copy running-config startup-config",  
                   1857:        "Copy from one file to another\n"
                   1858:        "Copy from current system configuration\n"
                   1859:        "Copy to startup configuration\n")
                   1860: 
                   1861: ALIAS (vtysh_write_memory,
                   1862:        vtysh_write_file_cmd,
                   1863:        "write file",
                   1864:        "Write running configuration to memory, network, or terminal\n"
                   1865:        "Write configuration to the file (same as write memory)\n")
                   1866: 
                   1867: ALIAS (vtysh_write_memory,
                   1868:        vtysh_write_cmd,
                   1869:        "write",
                   1870:        "Write running configuration to memory, network, or terminal\n")
                   1871: 
                   1872: ALIAS (vtysh_write_terminal,
                   1873:        vtysh_show_running_config_cmd,
                   1874:        "show running-config",
                   1875:        SHOW_STR
                   1876:        "Current operating configuration\n")
                   1877: 
                   1878: DEFUN (vtysh_terminal_length,
                   1879:        vtysh_terminal_length_cmd,
                   1880:        "terminal length <0-512>",
                   1881:        "Set terminal line parameters\n"
                   1882:        "Set number of lines on a screen\n"
                   1883:        "Number of lines on screen (0 for no pausing)\n")
                   1884: {
                   1885:   int lines;
                   1886:   char *endptr = NULL;
                   1887:   char default_pager[10];
                   1888: 
                   1889:   lines = strtol (argv[0], &endptr, 10);
                   1890:   if (lines < 0 || lines > 512 || *endptr != '\0')
                   1891:     {
                   1892:       vty_out (vty, "length is malformed%s", VTY_NEWLINE);
                   1893:       return CMD_WARNING;
                   1894:     }
                   1895: 
                   1896:   if (vtysh_pager_name)
                   1897:     {
                   1898:       free (vtysh_pager_name);
                   1899:       vtysh_pager_name = NULL;
                   1900:     }
                   1901: 
                   1902:   if (lines != 0)
                   1903:     {
                   1904:       snprintf(default_pager, 10, "more -%i", lines);
                   1905:       vtysh_pager_name = strdup (default_pager);
                   1906:     }
                   1907: 
                   1908:   return CMD_SUCCESS;
                   1909: }
                   1910: 
                   1911: DEFUN (vtysh_terminal_no_length,
                   1912:        vtysh_terminal_no_length_cmd,
                   1913:        "terminal no length",
                   1914:        "Set terminal line parameters\n"
                   1915:        NO_STR
                   1916:        "Set number of lines on a screen\n")
                   1917: {
                   1918:   if (vtysh_pager_name)
                   1919:     {
                   1920:       free (vtysh_pager_name);
                   1921:       vtysh_pager_name = NULL;
                   1922:     }
                   1923: 
                   1924:   vtysh_pager_init();
                   1925:   return CMD_SUCCESS;
                   1926: }
                   1927: 
                   1928: DEFUN (vtysh_show_daemons,
                   1929:        vtysh_show_daemons_cmd,
                   1930:        "show daemons",
                   1931:        SHOW_STR
                   1932:        "Show list of running daemons\n")
                   1933: {
                   1934:   u_int i;
                   1935: 
1.1.1.3 ! misho    1936:   for (i = 0; i < array_size(vtysh_client); i++)
1.1       misho    1937:     if ( vtysh_client[i].fd >= 0 )
                   1938:       vty_out(vty, " %s", vtysh_client[i].name);
                   1939:   vty_out(vty, "%s", VTY_NEWLINE);
                   1940: 
                   1941:   return CMD_SUCCESS;
                   1942: }
                   1943: 
                   1944: /* Execute command in child process. */
                   1945: static int
                   1946: execute_command (const char *command, int argc, const char *arg1,
                   1947:                 const char *arg2)
                   1948: {
                   1949:   int ret;
                   1950:   pid_t pid;
                   1951:   int status;
                   1952: 
                   1953:   /* Call fork(). */
                   1954:   pid = fork ();
                   1955: 
                   1956:   if (pid < 0)
                   1957:     {
                   1958:       /* Failure of fork(). */
                   1959:       fprintf (stderr, "Can't fork: %s\n", safe_strerror (errno));
                   1960:       exit (1);
                   1961:     }
                   1962:   else if (pid == 0)
                   1963:     {
                   1964:       /* This is child process. */
                   1965:       switch (argc)
                   1966:        {
                   1967:        case 0:
                   1968:          ret = execlp (command, command, (const char *)NULL);
                   1969:          break;
                   1970:        case 1:
                   1971:          ret = execlp (command, command, arg1, (const char *)NULL);
                   1972:          break;
                   1973:        case 2:
                   1974:          ret = execlp (command, command, arg1, arg2, (const char *)NULL);
                   1975:          break;
                   1976:        }
                   1977: 
                   1978:       /* When execlp suceed, this part is not executed. */
                   1979:       fprintf (stderr, "Can't execute %s: %s\n", command, safe_strerror (errno));
                   1980:       exit (1);
                   1981:     }
                   1982:   else
                   1983:     {
                   1984:       /* This is parent. */
                   1985:       execute_flag = 1;
                   1986:       ret = wait4 (pid, &status, 0, NULL);
                   1987:       execute_flag = 0;
                   1988:     }
                   1989:   return 0;
                   1990: }
                   1991: 
                   1992: DEFUN (vtysh_ping,
                   1993:        vtysh_ping_cmd,
                   1994:        "ping WORD",
                   1995:        "Send echo messages\n"
                   1996:        "Ping destination address or hostname\n")
                   1997: {
                   1998:   execute_command ("ping", 1, argv[0], NULL);
                   1999:   return CMD_SUCCESS;
                   2000: }
                   2001: 
                   2002: ALIAS (vtysh_ping,
                   2003:        vtysh_ping_ip_cmd,
                   2004:        "ping ip WORD",
                   2005:        "Send echo messages\n"
                   2006:        "IP echo\n"
                   2007:        "Ping destination address or hostname\n")
                   2008: 
                   2009: DEFUN (vtysh_traceroute,
                   2010:        vtysh_traceroute_cmd,
                   2011:        "traceroute WORD",
                   2012:        "Trace route to destination\n"
                   2013:        "Trace route to destination address or hostname\n")
                   2014: {
                   2015:   execute_command ("traceroute", 1, argv[0], NULL);
                   2016:   return CMD_SUCCESS;
                   2017: }
                   2018: 
                   2019: ALIAS (vtysh_traceroute,
                   2020:        vtysh_traceroute_ip_cmd,
                   2021:        "traceroute ip WORD",
                   2022:        "Trace route to destination\n"
                   2023:        "IP trace\n"
                   2024:        "Trace route to destination address or hostname\n")
                   2025: 
                   2026: #ifdef HAVE_IPV6
                   2027: DEFUN (vtysh_ping6,
                   2028:        vtysh_ping6_cmd,
                   2029:        "ping ipv6 WORD",
                   2030:        "Send echo messages\n"
                   2031:        "IPv6 echo\n"
                   2032:        "Ping destination address or hostname\n")
                   2033: {
                   2034:   execute_command ("ping6", 1, argv[0], NULL);
                   2035:   return CMD_SUCCESS;
                   2036: }
                   2037: 
                   2038: DEFUN (vtysh_traceroute6,
                   2039:        vtysh_traceroute6_cmd,
                   2040:        "traceroute ipv6 WORD",
                   2041:        "Trace route to destination\n"
                   2042:        "IPv6 trace\n"
                   2043:        "Trace route to destination address or hostname\n")
                   2044: {
                   2045:   execute_command ("traceroute6", 1, argv[0], NULL);
                   2046:   return CMD_SUCCESS;
                   2047: }
                   2048: #endif
                   2049: 
                   2050: DEFUN (vtysh_telnet,
                   2051:        vtysh_telnet_cmd,
                   2052:        "telnet WORD",
                   2053:        "Open a telnet connection\n"
                   2054:        "IP address or hostname of a remote system\n")
                   2055: {
                   2056:   execute_command ("telnet", 1, argv[0], NULL);
                   2057:   return CMD_SUCCESS;
                   2058: }
                   2059: 
                   2060: DEFUN (vtysh_telnet_port,
                   2061:        vtysh_telnet_port_cmd,
                   2062:        "telnet WORD PORT",
                   2063:        "Open a telnet connection\n"
                   2064:        "IP address or hostname of a remote system\n"
                   2065:        "TCP Port number\n")
                   2066: {
                   2067:   execute_command ("telnet", 2, argv[0], argv[1]);
                   2068:   return CMD_SUCCESS;
                   2069: }
                   2070: 
                   2071: DEFUN (vtysh_ssh,
                   2072:        vtysh_ssh_cmd,
                   2073:        "ssh WORD",
                   2074:        "Open an ssh connection\n"
                   2075:        "[user@]host\n")
                   2076: {
                   2077:   execute_command ("ssh", 1, argv[0], NULL);
                   2078:   return CMD_SUCCESS;
                   2079: }
                   2080: 
                   2081: DEFUN (vtysh_start_shell,
                   2082:        vtysh_start_shell_cmd,
                   2083:        "start-shell",
                   2084:        "Start UNIX shell\n")
                   2085: {
                   2086:   execute_command ("sh", 0, NULL, NULL);
                   2087:   return CMD_SUCCESS;
                   2088: }
                   2089: 
                   2090: DEFUN (vtysh_start_bash,
                   2091:        vtysh_start_bash_cmd,
                   2092:        "start-shell bash",
                   2093:        "Start UNIX shell\n"
                   2094:        "Start bash\n")
                   2095: {
                   2096:   execute_command ("bash", 0, NULL, NULL);
                   2097:   return CMD_SUCCESS;
                   2098: }
                   2099: 
                   2100: DEFUN (vtysh_start_zsh,
                   2101:        vtysh_start_zsh_cmd,
                   2102:        "start-shell zsh",
                   2103:        "Start UNIX shell\n"
                   2104:        "Start Z shell\n")
                   2105: {
                   2106:   execute_command ("zsh", 0, NULL, NULL);
                   2107:   return CMD_SUCCESS;
                   2108: }
                   2109: 
                   2110: static void
                   2111: vtysh_install_default (enum node_type node)
                   2112: {
                   2113:   install_element (node, &config_list_cmd);
                   2114: }
                   2115: 
                   2116: /* Making connection to protocol daemon. */
                   2117: static int
                   2118: vtysh_connect (struct vtysh_client *vclient)
                   2119: {
                   2120:   int ret;
                   2121:   int sock, len;
                   2122:   struct sockaddr_un addr;
                   2123:   struct stat s_stat;
                   2124: 
                   2125:   /* Stat socket to see if we have permission to access it. */
                   2126:   ret = stat (vclient->path, &s_stat);
                   2127:   if (ret < 0 && errno != ENOENT)
                   2128:     {
                   2129:       fprintf  (stderr, "vtysh_connect(%s): stat = %s\n", 
                   2130:                vclient->path, safe_strerror(errno)); 
                   2131:       exit(1);
                   2132:     }
                   2133:   
                   2134:   if (ret >= 0)
                   2135:     {
                   2136:       if (! S_ISSOCK(s_stat.st_mode))
                   2137:        {
                   2138:          fprintf (stderr, "vtysh_connect(%s): Not a socket\n",
                   2139:                   vclient->path);
                   2140:          exit (1);
                   2141:        }
                   2142:       
                   2143:     }
                   2144: 
                   2145:   sock = socket (AF_UNIX, SOCK_STREAM, 0);
                   2146:   if (sock < 0)
                   2147:     {
                   2148: #ifdef DEBUG
                   2149:       fprintf(stderr, "vtysh_connect(%s): socket = %s\n", vclient->path,
                   2150:              safe_strerror(errno));
                   2151: #endif /* DEBUG */
                   2152:       return -1;
                   2153:     }
                   2154: 
                   2155:   memset (&addr, 0, sizeof (struct sockaddr_un));
                   2156:   addr.sun_family = AF_UNIX;
                   2157:   strncpy (addr.sun_path, vclient->path, strlen (vclient->path));
                   2158: #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
                   2159:   len = addr.sun_len = SUN_LEN(&addr);
                   2160: #else
                   2161:   len = sizeof (addr.sun_family) + strlen (addr.sun_path);
                   2162: #endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
                   2163: 
                   2164:   ret = connect (sock, (struct sockaddr *) &addr, len);
                   2165:   if (ret < 0)
                   2166:     {
                   2167: #ifdef DEBUG
                   2168:       fprintf(stderr, "vtysh_connect(%s): connect = %s\n", vclient->path,
                   2169:              safe_strerror(errno));
                   2170: #endif /* DEBUG */
                   2171:       close (sock);
                   2172:       return -1;
                   2173:     }
                   2174:   vclient->fd = sock;
                   2175: 
                   2176:   return 0;
                   2177: }
                   2178: 
                   2179: int
                   2180: vtysh_connect_all(const char *daemon_name)
                   2181: {
                   2182:   u_int i;
                   2183:   int rc = 0;
                   2184:   int matches = 0;
                   2185: 
1.1.1.3 ! misho    2186:   for (i = 0; i < array_size(vtysh_client); i++)
1.1       misho    2187:     {
                   2188:       if (!daemon_name || !strcmp(daemon_name, vtysh_client[i].name))
                   2189:        {
                   2190:          matches++;
                   2191:          if (vtysh_connect(&vtysh_client[i]) == 0)
                   2192:            rc++;
                   2193:          /* We need direct access to ripd in vtysh_exit_ripd_only. */
                   2194:          if (vtysh_client[i].flag == VTYSH_RIPD)
                   2195:            ripd_client = &vtysh_client[i];
                   2196:        }
                   2197:     }
                   2198:   if (!matches)
                   2199:     fprintf(stderr, "Error: no daemons match name %s!\n", daemon_name);
                   2200:   return rc;
                   2201: }
                   2202: 
                   2203: /* To disable readline's filename completion. */
                   2204: static char *
                   2205: vtysh_completion_entry_function (const char *ignore, int invoking_key)
                   2206: {
                   2207:   return NULL;
                   2208: }
                   2209: 
                   2210: void
                   2211: vtysh_readline_init (void)
                   2212: {
                   2213:   /* readline related settings. */
                   2214:   rl_bind_key ('?', (Function *) vtysh_rl_describe);
                   2215:   rl_completion_entry_function = vtysh_completion_entry_function;
                   2216:   rl_attempted_completion_function = (CPPFunction *)new_completion;
                   2217:   /* do not append space after completion. It will be appended
                   2218:    * in new_completion() function explicitly. */
                   2219:   rl_completion_append_character = '\0';
                   2220: }
                   2221: 
                   2222: char *
                   2223: vtysh_prompt (void)
                   2224: {
                   2225:   static struct utsname names;
                   2226:   static char buf[100];
                   2227:   const char*hostname;
                   2228:   extern struct host host;
                   2229: 
                   2230:   hostname = host.name;
                   2231: 
                   2232:   if (!hostname)
                   2233:     {
                   2234:       if (!names.nodename[0])
                   2235:        uname (&names);
                   2236:       hostname = names.nodename;
                   2237:     }
                   2238: 
                   2239:   snprintf (buf, sizeof buf, cmd_prompt (vty->node), hostname);
                   2240: 
                   2241:   return buf;
                   2242: }
                   2243: 
                   2244: void
                   2245: vtysh_init_vty (void)
                   2246: {
                   2247:   /* Make vty structure. */
                   2248:   vty = vty_new ();
                   2249:   vty->type = VTY_SHELL;
                   2250:   vty->node = VIEW_NODE;
                   2251: 
                   2252:   /* Initialize commands. */
                   2253:   cmd_init (0);
                   2254: 
                   2255:   /* Install nodes. */
                   2256:   install_node (&bgp_node, NULL);
                   2257:   install_node (&rip_node, NULL);
                   2258:   install_node (&interface_node, NULL);
                   2259:   install_node (&rmap_node, NULL);
                   2260:   install_node (&zebra_node, NULL);
                   2261:   install_node (&bgp_vpnv4_node, NULL);
                   2262:   install_node (&bgp_ipv4_node, NULL);
                   2263:   install_node (&bgp_ipv4m_node, NULL);
                   2264: /* #ifdef HAVE_IPV6 */
                   2265:   install_node (&bgp_ipv6_node, NULL);
                   2266:   install_node (&bgp_ipv6m_node, NULL);
                   2267: /* #endif */
                   2268:   install_node (&ospf_node, NULL);
                   2269: /* #ifdef HAVE_IPV6 */
                   2270:   install_node (&ripng_node, NULL);
                   2271:   install_node (&ospf6_node, NULL);
                   2272: /* #endif */
1.1.1.2   misho    2273:   install_node (&babel_node, NULL);
1.1       misho    2274:   install_node (&keychain_node, NULL);
                   2275:   install_node (&keychain_key_node, NULL);
                   2276:   install_node (&isis_node, NULL);
                   2277:   install_node (&vty_node, NULL);
                   2278: 
                   2279:   vtysh_install_default (VIEW_NODE);
                   2280:   vtysh_install_default (ENABLE_NODE);
                   2281:   vtysh_install_default (CONFIG_NODE);
                   2282:   vtysh_install_default (BGP_NODE);
                   2283:   vtysh_install_default (RIP_NODE);
                   2284:   vtysh_install_default (INTERFACE_NODE);
                   2285:   vtysh_install_default (RMAP_NODE);
                   2286:   vtysh_install_default (ZEBRA_NODE);
                   2287:   vtysh_install_default (BGP_VPNV4_NODE);
                   2288:   vtysh_install_default (BGP_IPV4_NODE);
                   2289:   vtysh_install_default (BGP_IPV4M_NODE);
                   2290:   vtysh_install_default (BGP_IPV6_NODE);
                   2291:   vtysh_install_default (BGP_IPV6M_NODE);
                   2292:   vtysh_install_default (OSPF_NODE);
                   2293:   vtysh_install_default (RIPNG_NODE);
                   2294:   vtysh_install_default (OSPF6_NODE);
1.1.1.2   misho    2295:   vtysh_install_default (BABEL_NODE);
1.1       misho    2296:   vtysh_install_default (ISIS_NODE);
                   2297:   vtysh_install_default (KEYCHAIN_NODE);
                   2298:   vtysh_install_default (KEYCHAIN_KEY_NODE);
                   2299:   vtysh_install_default (VTY_NODE);
                   2300: 
                   2301:   install_element (VIEW_NODE, &vtysh_enable_cmd);
                   2302:   install_element (ENABLE_NODE, &vtysh_config_terminal_cmd);
                   2303:   install_element (ENABLE_NODE, &vtysh_disable_cmd);
                   2304: 
                   2305:   /* "exit" command. */
                   2306:   install_element (VIEW_NODE, &vtysh_exit_all_cmd);
                   2307:   install_element (VIEW_NODE, &vtysh_quit_all_cmd);
                   2308:   install_element (CONFIG_NODE, &vtysh_exit_all_cmd);
                   2309:   /* install_element (CONFIG_NODE, &vtysh_quit_all_cmd); */
                   2310:   install_element (ENABLE_NODE, &vtysh_exit_all_cmd);
                   2311:   install_element (ENABLE_NODE, &vtysh_quit_all_cmd);
                   2312:   install_element (RIP_NODE, &vtysh_exit_ripd_cmd);
                   2313:   install_element (RIP_NODE, &vtysh_quit_ripd_cmd);
                   2314:   install_element (RIPNG_NODE, &vtysh_exit_ripngd_cmd);
                   2315:   install_element (RIPNG_NODE, &vtysh_quit_ripngd_cmd);
                   2316:   install_element (OSPF_NODE, &vtysh_exit_ospfd_cmd);
                   2317:   install_element (OSPF_NODE, &vtysh_quit_ospfd_cmd);
                   2318:   install_element (OSPF6_NODE, &vtysh_exit_ospf6d_cmd);
                   2319:   install_element (OSPF6_NODE, &vtysh_quit_ospf6d_cmd);
                   2320:   install_element (BGP_NODE, &vtysh_exit_bgpd_cmd);
                   2321:   install_element (BGP_NODE, &vtysh_quit_bgpd_cmd);
                   2322:   install_element (BGP_VPNV4_NODE, &vtysh_exit_bgpd_cmd);
                   2323:   install_element (BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd);
                   2324:   install_element (BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd);
                   2325:   install_element (BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd);
                   2326:   install_element (BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd);
                   2327:   install_element (BGP_IPV4M_NODE, &vtysh_quit_bgpd_cmd);
                   2328:   install_element (BGP_IPV6_NODE, &vtysh_exit_bgpd_cmd);
                   2329:   install_element (BGP_IPV6_NODE, &vtysh_quit_bgpd_cmd);
                   2330:   install_element (BGP_IPV6M_NODE, &vtysh_exit_bgpd_cmd);
                   2331:   install_element (BGP_IPV6M_NODE, &vtysh_quit_bgpd_cmd);
                   2332:   install_element (ISIS_NODE, &vtysh_exit_isisd_cmd);
                   2333:   install_element (ISIS_NODE, &vtysh_quit_isisd_cmd);
                   2334:   install_element (KEYCHAIN_NODE, &vtysh_exit_ripd_cmd);
                   2335:   install_element (KEYCHAIN_NODE, &vtysh_quit_ripd_cmd);
                   2336:   install_element (KEYCHAIN_KEY_NODE, &vtysh_exit_ripd_cmd);
                   2337:   install_element (KEYCHAIN_KEY_NODE, &vtysh_quit_ripd_cmd);
                   2338:   install_element (RMAP_NODE, &vtysh_exit_rmap_cmd);
                   2339:   install_element (RMAP_NODE, &vtysh_quit_rmap_cmd);
                   2340:   install_element (VTY_NODE, &vtysh_exit_line_vty_cmd);
                   2341:   install_element (VTY_NODE, &vtysh_quit_line_vty_cmd);
                   2342: 
                   2343:   /* "end" command. */
                   2344:   install_element (CONFIG_NODE, &vtysh_end_all_cmd);
                   2345:   install_element (ENABLE_NODE, &vtysh_end_all_cmd);
                   2346:   install_element (RIP_NODE, &vtysh_end_all_cmd);
                   2347:   install_element (RIPNG_NODE, &vtysh_end_all_cmd);
                   2348:   install_element (OSPF_NODE, &vtysh_end_all_cmd);
                   2349:   install_element (OSPF6_NODE, &vtysh_end_all_cmd);
1.1.1.2   misho    2350:   install_element (BABEL_NODE, &vtysh_end_all_cmd);
1.1       misho    2351:   install_element (BGP_NODE, &vtysh_end_all_cmd);
                   2352:   install_element (BGP_IPV4_NODE, &vtysh_end_all_cmd);
                   2353:   install_element (BGP_IPV4M_NODE, &vtysh_end_all_cmd);
                   2354:   install_element (BGP_VPNV4_NODE, &vtysh_end_all_cmd);
                   2355:   install_element (BGP_IPV6_NODE, &vtysh_end_all_cmd);
                   2356:   install_element (BGP_IPV6M_NODE, &vtysh_end_all_cmd);
                   2357:   install_element (ISIS_NODE, &vtysh_end_all_cmd);
                   2358:   install_element (KEYCHAIN_NODE, &vtysh_end_all_cmd);
                   2359:   install_element (KEYCHAIN_KEY_NODE, &vtysh_end_all_cmd);
                   2360:   install_element (RMAP_NODE, &vtysh_end_all_cmd);
                   2361:   install_element (VTY_NODE, &vtysh_end_all_cmd);
                   2362: 
                   2363:   install_element (INTERFACE_NODE, &interface_desc_cmd);
                   2364:   install_element (INTERFACE_NODE, &no_interface_desc_cmd);
                   2365:   install_element (INTERFACE_NODE, &vtysh_end_all_cmd);
                   2366:   install_element (INTERFACE_NODE, &vtysh_exit_interface_cmd);
                   2367:   install_element (INTERFACE_NODE, &vtysh_quit_interface_cmd);
                   2368:   install_element (CONFIG_NODE, &router_rip_cmd);
                   2369: #ifdef HAVE_IPV6
                   2370:   install_element (CONFIG_NODE, &router_ripng_cmd);
                   2371: #endif
                   2372:   install_element (CONFIG_NODE, &router_ospf_cmd);
                   2373: #ifdef HAVE_IPV6
                   2374:   install_element (CONFIG_NODE, &router_ospf6_cmd);
                   2375: #endif
1.1.1.2   misho    2376:   install_element (CONFIG_NODE, &router_babel_cmd);
1.1       misho    2377:   install_element (CONFIG_NODE, &router_isis_cmd);
                   2378:   install_element (CONFIG_NODE, &router_bgp_cmd);
                   2379:   install_element (CONFIG_NODE, &router_bgp_view_cmd);
                   2380:   install_element (BGP_NODE, &address_family_vpnv4_cmd);
                   2381:   install_element (BGP_NODE, &address_family_vpnv4_unicast_cmd);
                   2382:   install_element (BGP_NODE, &address_family_ipv4_unicast_cmd);
                   2383:   install_element (BGP_NODE, &address_family_ipv4_multicast_cmd);
                   2384: #ifdef HAVE_IPV6
                   2385:   install_element (BGP_NODE, &address_family_ipv6_cmd);
                   2386:   install_element (BGP_NODE, &address_family_ipv6_unicast_cmd);
                   2387: #endif
                   2388:   install_element (BGP_VPNV4_NODE, &exit_address_family_cmd);
                   2389:   install_element (BGP_IPV4_NODE, &exit_address_family_cmd);
                   2390:   install_element (BGP_IPV4M_NODE, &exit_address_family_cmd);
                   2391:   install_element (BGP_IPV6_NODE, &exit_address_family_cmd);
                   2392:   install_element (BGP_IPV6M_NODE, &exit_address_family_cmd);
                   2393:   install_element (CONFIG_NODE, &key_chain_cmd);
                   2394:   install_element (CONFIG_NODE, &route_map_cmd);
                   2395:   install_element (CONFIG_NODE, &vtysh_line_vty_cmd);
                   2396:   install_element (KEYCHAIN_NODE, &key_cmd);
                   2397:   install_element (KEYCHAIN_NODE, &key_chain_cmd);
                   2398:   install_element (KEYCHAIN_KEY_NODE, &key_chain_cmd);
                   2399:   install_element (CONFIG_NODE, &vtysh_interface_cmd);
                   2400:   install_element (CONFIG_NODE, &vtysh_no_interface_cmd);
                   2401:   install_element (ENABLE_NODE, &vtysh_show_running_config_cmd);
                   2402:   install_element (ENABLE_NODE, &vtysh_copy_runningconfig_startupconfig_cmd);
                   2403:   install_element (ENABLE_NODE, &vtysh_write_file_cmd);
                   2404:   install_element (ENABLE_NODE, &vtysh_write_cmd);
                   2405: 
                   2406:   /* "write terminal" command. */
                   2407:   install_element (ENABLE_NODE, &vtysh_write_terminal_cmd);
                   2408:  
                   2409:   install_element (CONFIG_NODE, &vtysh_integrated_config_cmd);
                   2410:   install_element (CONFIG_NODE, &no_vtysh_integrated_config_cmd);
                   2411: 
                   2412:   /* "write memory" command. */
                   2413:   install_element (ENABLE_NODE, &vtysh_write_memory_cmd);
                   2414: 
                   2415:   install_element (VIEW_NODE, &vtysh_terminal_length_cmd);
                   2416:   install_element (ENABLE_NODE, &vtysh_terminal_length_cmd);
                   2417:   install_element (VIEW_NODE, &vtysh_terminal_no_length_cmd);
                   2418:   install_element (ENABLE_NODE, &vtysh_terminal_no_length_cmd);
                   2419:   install_element (VIEW_NODE, &vtysh_show_daemons_cmd);
                   2420:   install_element (ENABLE_NODE, &vtysh_show_daemons_cmd);
                   2421: 
                   2422:   install_element (VIEW_NODE, &vtysh_ping_cmd);
                   2423:   install_element (VIEW_NODE, &vtysh_ping_ip_cmd);
                   2424:   install_element (VIEW_NODE, &vtysh_traceroute_cmd);
                   2425:   install_element (VIEW_NODE, &vtysh_traceroute_ip_cmd);
                   2426: #ifdef HAVE_IPV6
                   2427:   install_element (VIEW_NODE, &vtysh_ping6_cmd);
                   2428:   install_element (VIEW_NODE, &vtysh_traceroute6_cmd);
                   2429: #endif
                   2430:   install_element (VIEW_NODE, &vtysh_telnet_cmd);
                   2431:   install_element (VIEW_NODE, &vtysh_telnet_port_cmd);
                   2432:   install_element (VIEW_NODE, &vtysh_ssh_cmd);
                   2433:   install_element (ENABLE_NODE, &vtysh_ping_cmd);
                   2434:   install_element (ENABLE_NODE, &vtysh_ping_ip_cmd);
                   2435:   install_element (ENABLE_NODE, &vtysh_traceroute_cmd);
                   2436:   install_element (ENABLE_NODE, &vtysh_traceroute_ip_cmd);
                   2437: #ifdef HAVE_IPV6
                   2438:   install_element (ENABLE_NODE, &vtysh_ping6_cmd);
                   2439:   install_element (ENABLE_NODE, &vtysh_traceroute6_cmd);
                   2440: #endif
                   2441:   install_element (ENABLE_NODE, &vtysh_telnet_cmd);
                   2442:   install_element (ENABLE_NODE, &vtysh_telnet_port_cmd);
                   2443:   install_element (ENABLE_NODE, &vtysh_ssh_cmd);
                   2444:   install_element (ENABLE_NODE, &vtysh_start_shell_cmd);
                   2445:   install_element (ENABLE_NODE, &vtysh_start_bash_cmd);
                   2446:   install_element (ENABLE_NODE, &vtysh_start_zsh_cmd);
                   2447:   
                   2448:   install_element (VIEW_NODE, &vtysh_show_memory_cmd);
                   2449:   install_element (ENABLE_NODE, &vtysh_show_memory_cmd);
                   2450: 
                   2451:   /* Logging */
                   2452:   install_element (ENABLE_NODE, &vtysh_show_logging_cmd);
                   2453:   install_element (VIEW_NODE, &vtysh_show_logging_cmd);
                   2454:   install_element (CONFIG_NODE, &vtysh_log_stdout_cmd);
                   2455:   install_element (CONFIG_NODE, &vtysh_log_stdout_level_cmd);
                   2456:   install_element (CONFIG_NODE, &no_vtysh_log_stdout_cmd);
                   2457:   install_element (CONFIG_NODE, &vtysh_log_file_cmd);
                   2458:   install_element (CONFIG_NODE, &vtysh_log_file_level_cmd);
                   2459:   install_element (CONFIG_NODE, &no_vtysh_log_file_cmd);
                   2460:   install_element (CONFIG_NODE, &no_vtysh_log_file_level_cmd);
                   2461:   install_element (CONFIG_NODE, &vtysh_log_monitor_cmd);
                   2462:   install_element (CONFIG_NODE, &vtysh_log_monitor_level_cmd);
                   2463:   install_element (CONFIG_NODE, &no_vtysh_log_monitor_cmd);
                   2464:   install_element (CONFIG_NODE, &vtysh_log_syslog_cmd);
                   2465:   install_element (CONFIG_NODE, &vtysh_log_syslog_level_cmd);
                   2466:   install_element (CONFIG_NODE, &no_vtysh_log_syslog_cmd);
                   2467:   install_element (CONFIG_NODE, &vtysh_log_trap_cmd);
                   2468:   install_element (CONFIG_NODE, &no_vtysh_log_trap_cmd);
                   2469:   install_element (CONFIG_NODE, &vtysh_log_facility_cmd);
                   2470:   install_element (CONFIG_NODE, &no_vtysh_log_facility_cmd);
                   2471:   install_element (CONFIG_NODE, &vtysh_log_record_priority_cmd);
                   2472:   install_element (CONFIG_NODE, &no_vtysh_log_record_priority_cmd);
                   2473:   install_element (CONFIG_NODE, &vtysh_log_timestamp_precision_cmd);
                   2474:   install_element (CONFIG_NODE, &no_vtysh_log_timestamp_precision_cmd);
                   2475: 
                   2476:   install_element (CONFIG_NODE, &vtysh_service_password_encrypt_cmd);
                   2477:   install_element (CONFIG_NODE, &no_vtysh_service_password_encrypt_cmd);
                   2478: 
                   2479:   install_element (CONFIG_NODE, &vtysh_password_cmd);
                   2480:   install_element (CONFIG_NODE, &vtysh_password_text_cmd);
                   2481:   install_element (CONFIG_NODE, &vtysh_enable_password_cmd);
                   2482:   install_element (CONFIG_NODE, &vtysh_enable_password_text_cmd);
                   2483:   install_element (CONFIG_NODE, &no_vtysh_enable_password_cmd);
                   2484: 
                   2485: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>