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

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

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