vtysh.c 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024
  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. #include <zebra.h>
  22. #include <sys/un.h>
  23. #include <setjmp.h>
  24. #include <sys/wait.h>
  25. #include <sys/resource.h>
  26. #include <sys/stat.h>
  27. #include <readline/readline.h>
  28. #include <readline/history.h>
  29. #include "command.h"
  30. #include "memory.h"
  31. #include "vtysh/vtysh.h"
  32. /* Struct VTY. */
  33. struct vty *vty;
  34. /* VTY shell pager name. */
  35. char *vtysh_pager_name = NULL;
  36. /* VTY shell client structure. */
  37. struct vtysh_client
  38. {
  39. int fd;
  40. } vtysh_client[VTYSH_INDEX_MAX];
  41. /* When '^Z' is received from vty, move down to the enable mode. */
  42. int
  43. vtysh_end ()
  44. {
  45. switch (vty->node)
  46. {
  47. case VIEW_NODE:
  48. case ENABLE_NODE:
  49. /* Nothing to do. */
  50. break;
  51. default:
  52. vty->node = ENABLE_NODE;
  53. break;
  54. }
  55. return CMD_SUCCESS;
  56. }
  57. DEFUNSH (VTYSH_ALL,
  58. vtysh_end_all,
  59. vtysh_end_all_cmd,
  60. "end",
  61. "End current mode and down to previous mode\n")
  62. {
  63. return vtysh_end (vty);
  64. }
  65. DEFUNSH (VTYSH_ALL,
  66. vtysh_log_stdout,
  67. vtysh_log_stdout_cmd,
  68. "log stdout",
  69. "Logging control\n"
  70. "Logging goes to stdout\n")
  71. {
  72. return CMD_SUCCESS;
  73. }
  74. DEFUNSH (VTYSH_ALL,
  75. no_vtysh_log_stdout,
  76. no_vtysh_log_stdout_cmd,
  77. "no log stdout",
  78. NO_STR
  79. "Logging control\n"
  80. "Logging goes to stdout\n")
  81. {
  82. return CMD_SUCCESS;
  83. }
  84. DEFUNSH (VTYSH_ALL,
  85. vtysh_log_file,
  86. vtysh_log_file_cmd,
  87. "log file FILENAME",
  88. "Logging control\n"
  89. "Logging to file\n"
  90. "Logging filename\n")
  91. {
  92. return CMD_SUCCESS;
  93. }
  94. DEFUNSH (VTYSH_ALL,
  95. no_vtysh_log_file,
  96. no_vtysh_log_file_cmd,
  97. "no log file [FILENAME]",
  98. NO_STR
  99. "Logging control\n"
  100. "Cancel logging to file\n"
  101. "Logging file name\n")
  102. {
  103. return CMD_SUCCESS;
  104. }
  105. DEFUNSH (VTYSH_ALL,
  106. vtysh_log_syslog,
  107. vtysh_log_syslog_cmd,
  108. "log syslog",
  109. "Logging control\n"
  110. "Logging goes to syslog\n")
  111. {
  112. return CMD_SUCCESS;
  113. }
  114. DEFUNSH (VTYSH_ALL,
  115. no_vtysh_log_syslog,
  116. no_vtysh_log_syslog_cmd,
  117. "no log syslog",
  118. NO_STR
  119. "Logging control\n"
  120. "Cancel logging to syslog\n")
  121. {
  122. return CMD_SUCCESS;
  123. }
  124. DEFUNSH (VTYSH_ALL,
  125. vtysh_log_trap,
  126. vtysh_log_trap_cmd,
  127. "log trap (emergencies|alerts|critical|errors|warnings|notifications|informational|debugging)",
  128. "Logging control\n"
  129. "Limit logging to specifed level\n")
  130. {
  131. return CMD_SUCCESS;
  132. }
  133. DEFUNSH (VTYSH_ALL,
  134. no_vtysh_log_trap,
  135. no_vtysh_log_trap_cmd,
  136. "no log trap",
  137. NO_STR
  138. "Logging control\n"
  139. "Permit all logging information\n")
  140. {
  141. return CMD_SUCCESS;
  142. }
  143. DEFUNSH (VTYSH_ALL,
  144. vtysh_log_record_priority,
  145. vtysh_log_record_priority_cmd,
  146. "log record-priority",
  147. "Logging control\n"
  148. "Log the priority of the message within the message\n")
  149. {
  150. return CMD_SUCCESS;
  151. }
  152. DEFUNSH (VTYSH_ALL,
  153. no_vtysh_log_record_priority,
  154. no_vtysh_log_record_priority_cmd,
  155. "no log record-priority",
  156. NO_STR
  157. "Logging control\n"
  158. "Do not log the priority of the message within the message\n")
  159. {
  160. return CMD_SUCCESS;
  161. }
  162. void
  163. vclient_close (struct vtysh_client *vclient)
  164. {
  165. if (vclient->fd > 0)
  166. close (vclient->fd);
  167. vclient->fd = -1;
  168. }
  169. /* Following filled with debug code to trace a problematic condition
  170. under load - it SHOULD handle it.
  171. */
  172. #define ERR_WHERE_STRING "vtysh(): vtysh_client_config(): "
  173. int
  174. vtysh_client_config (struct vtysh_client *vclient, char *line)
  175. {
  176. int ret;
  177. char *buf;
  178. size_t bufsz;
  179. char *pbuf;
  180. size_t left;
  181. char *eoln;
  182. int nbytes;
  183. int i;
  184. int readln;
  185. if (vclient->fd < 0)
  186. return CMD_SUCCESS;
  187. ret = write (vclient->fd, line, strlen (line) + 1);
  188. if (ret <= 0)
  189. {
  190. vclient_close (vclient);
  191. return CMD_SUCCESS;
  192. }
  193. /* Allow enough room for buffer to read more than a few pages from socket
  194. */
  195. bufsz = 5 * getpagesize() + 1;
  196. buf = XMALLOC(MTYPE_TMP, bufsz);
  197. memset(buf, 0, bufsz);
  198. pbuf = buf;
  199. while (1)
  200. {
  201. if (pbuf >= ((buf + bufsz) -1))
  202. {
  203. fprintf (stderr, ERR_WHERE_STRING \
  204. "warning - pbuf beyond buffer end.\n");
  205. return CMD_WARNING;
  206. }
  207. readln = (buf + bufsz) - pbuf - 1;
  208. nbytes = read (vclient->fd, pbuf, readln);
  209. if (nbytes <= 0)
  210. {
  211. if (errno == EINTR)
  212. continue;
  213. fprintf(stderr, ERR_WHERE_STRING "(%u)", errno);
  214. perror("");
  215. if (errno == EAGAIN || errno == EIO)
  216. continue;
  217. vclient_close (vclient);
  218. XFREE(MTYPE_TMP, buf);
  219. return CMD_SUCCESS;
  220. }
  221. pbuf[nbytes] = '\0';
  222. if (nbytes >= 4)
  223. {
  224. i = nbytes - 4;
  225. if (pbuf[i] == '\0' && pbuf[i + 1] == '\0' && pbuf[i + 2] == '\0')
  226. {
  227. ret = pbuf[i + 3];
  228. break;
  229. }
  230. }
  231. pbuf += nbytes;
  232. /* See if a line exists in buffer, if so parse and consume it, and
  233. reset read position */
  234. if ((eoln = strrchr(buf, '\n')) == NULL)
  235. continue;
  236. if (eoln >= ((buf + bufsz) - 1))
  237. {
  238. fprintf (stderr, ERR_WHERE_STRING \
  239. "warning - eoln beyond buffer end.\n");
  240. }
  241. vtysh_config_parse(buf);
  242. eoln++;
  243. left = (size_t)(buf + bufsz - eoln);
  244. memmove(buf, eoln, left);
  245. buf[bufsz-1] = '\0';
  246. pbuf = buf + strlen(buf);
  247. }
  248. /* parse anything left in the buffer */
  249. vtysh_config_parse (buf);
  250. XFREE(MTYPE_TMP, buf);
  251. return ret;
  252. }
  253. int
  254. vtysh_client_execute (struct vtysh_client *vclient, char *line, FILE *fp)
  255. {
  256. int ret;
  257. char buf[1001];
  258. int nbytes;
  259. int i;
  260. if (vclient->fd < 0)
  261. return CMD_SUCCESS;
  262. ret = write (vclient->fd, line, strlen (line) + 1);
  263. if (ret <= 0)
  264. {
  265. vclient_close (vclient);
  266. return CMD_SUCCESS;
  267. }
  268. while (1)
  269. {
  270. nbytes = read (vclient->fd, buf, sizeof(buf)-1);
  271. if (nbytes <= 0 && errno != EINTR)
  272. {
  273. vclient_close (vclient);
  274. return CMD_SUCCESS;
  275. }
  276. if (nbytes > 0)
  277. {
  278. buf[nbytes] = '\0';
  279. fprintf (fp, "%s", buf);
  280. fflush (fp);
  281. if (nbytes >= 4)
  282. {
  283. i = nbytes - 4;
  284. if (buf[i] == '\0' && buf[i + 1] == '\0' && buf[i + 2] == '\0')
  285. {
  286. ret = buf[i + 3];
  287. break;
  288. }
  289. }
  290. }
  291. }
  292. return ret;
  293. }
  294. void
  295. vtysh_exit_ripd_only ()
  296. {
  297. vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIP], "exit", stdout);
  298. }
  299. void
  300. vtysh_pager_init ()
  301. {
  302. vtysh_pager_name = getenv ("VTYSH_PAGER");
  303. if (! vtysh_pager_name)
  304. vtysh_pager_name = "more";
  305. }
  306. /* Command execution over the vty interface. */
  307. void
  308. vtysh_execute_func (char *line, int pager)
  309. {
  310. int ret, cmd_stat;
  311. vector vline;
  312. struct cmd_element *cmd;
  313. FILE *fp = NULL;
  314. int closepager=0;
  315. /* Split readline string up into the vector */
  316. vline = cmd_make_strvec (line);
  317. if (vline == NULL)
  318. return;
  319. ret = cmd_execute_command (vline, vty, &cmd);
  320. cmd_free_strvec (vline);
  321. switch (ret)
  322. {
  323. case CMD_WARNING:
  324. if (vty->type == VTY_FILE)
  325. fprintf (stdout,"Warning...\n");
  326. break;
  327. case CMD_ERR_AMBIGUOUS:
  328. fprintf (stdout,"%% Ambiguous command.\n");
  329. break;
  330. case CMD_ERR_NO_MATCH:
  331. fprintf (stdout,"%% Unknown command.\n");
  332. break;
  333. case CMD_ERR_INCOMPLETE:
  334. fprintf (stdout,"%% Command incomplete.\n");
  335. break;
  336. case CMD_SUCCESS_DAEMON:
  337. {
  338. if (pager && vtysh_pager_name)
  339. {
  340. fp = popen (vtysh_pager_name, "w");
  341. if (fp == NULL)
  342. {
  343. perror ("popen failed for pager");
  344. fp = stdout;
  345. }
  346. else
  347. closepager=1;
  348. }
  349. else
  350. fp = stdout;
  351. if (! strcmp(cmd->string,"configure terminal"))
  352. {
  353. cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ZEBRA],
  354. line, fp);
  355. if (cmd_stat != CMD_WARNING)
  356. cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIP],
  357. line, fp);
  358. if (cmd_stat != CMD_WARNING)
  359. cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIPNG], line, fp);
  360. if (cmd_stat != CMD_WARNING)
  361. cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF],
  362. line, fp);
  363. if (cmd_stat != CMD_WARNING)
  364. cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF6], line, fp);
  365. if (cmd_stat != CMD_WARNING)
  366. cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_BGP],
  367. line, fp);
  368. if (cmd_stat != CMD_WARNING)
  369. cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ISIS], line, fp);
  370. if (cmd_stat)
  371. {
  372. line = "end";
  373. vline = cmd_make_strvec (line);
  374. if (vline == NULL)
  375. {
  376. if (pager && vtysh_pager_name && fp && closepager)
  377. {
  378. if (pclose (fp) == -1)
  379. {
  380. perror ("pclose failed for pager");
  381. }
  382. fp = NULL;
  383. }
  384. return;
  385. }
  386. ret = cmd_execute_command (vline, vty, &cmd);
  387. cmd_free_strvec (vline);
  388. if (ret != CMD_SUCCESS_DAEMON)
  389. break;
  390. }
  391. else
  392. if (cmd->func)
  393. {
  394. (*cmd->func) (cmd, vty, 0, NULL);
  395. break;
  396. }
  397. }
  398. if (cmd->daemon & VTYSH_ZEBRA)
  399. if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ZEBRA], line, fp)
  400. != CMD_SUCCESS)
  401. break;
  402. if (cmd->daemon & VTYSH_RIPD)
  403. if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIP], line, fp)
  404. != CMD_SUCCESS)
  405. break;
  406. if (cmd->daemon & VTYSH_RIPNGD)
  407. if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIPNG], line, fp)
  408. != CMD_SUCCESS)
  409. break;
  410. if (cmd->daemon & VTYSH_OSPFD)
  411. if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF], line, fp)
  412. != CMD_SUCCESS)
  413. break;
  414. if (cmd->daemon & VTYSH_OSPF6D)
  415. if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF6], line, fp)
  416. != CMD_SUCCESS)
  417. break;
  418. if (cmd->daemon & VTYSH_BGPD)
  419. if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_BGP], line, fp)
  420. != CMD_SUCCESS)
  421. break;
  422. if (cmd->daemon & VTYSH_ISISD)
  423. if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ISIS], line, fp)
  424. != CMD_SUCCESS)
  425. break;
  426. if (cmd->func)
  427. (*cmd->func) (cmd, vty, 0, NULL);
  428. }
  429. }
  430. if (pager && vtysh_pager_name && fp && closepager)
  431. {
  432. if (pclose (fp) == -1)
  433. {
  434. perror ("pclose failed for pager");
  435. }
  436. fp = NULL;
  437. }
  438. }
  439. void
  440. vtysh_execute_no_pager (char *line)
  441. {
  442. vtysh_execute_func (line, 0);
  443. }
  444. void
  445. vtysh_execute (char *line)
  446. {
  447. vtysh_execute_func (line, 1);
  448. }
  449. /* Configration make from file. */
  450. int
  451. vtysh_config_from_file (struct vty *vty, FILE *fp)
  452. {
  453. int ret;
  454. vector vline;
  455. struct cmd_element *cmd;
  456. while (fgets (vty->buf, VTY_BUFSIZ, fp))
  457. {
  458. if (vty->buf[0] == '!' || vty->buf[1] == '#')
  459. continue;
  460. vline = cmd_make_strvec (vty->buf);
  461. /* In case of comment line */
  462. if (vline == NULL)
  463. continue;
  464. /* Execute configuration command : this is strict match */
  465. ret = cmd_execute_command_strict (vline, vty, &cmd);
  466. /* Try again with setting node to CONFIG_NODE */
  467. if (ret != CMD_SUCCESS
  468. && ret != CMD_SUCCESS_DAEMON
  469. && ret != CMD_WARNING)
  470. {
  471. if (vty->node == KEYCHAIN_KEY_NODE)
  472. {
  473. vty->node = KEYCHAIN_NODE;
  474. vtysh_exit_ripd_only ();
  475. ret = cmd_execute_command_strict (vline, vty, &cmd);
  476. if (ret != CMD_SUCCESS
  477. && ret != CMD_SUCCESS_DAEMON
  478. && ret != CMD_WARNING)
  479. {
  480. vtysh_exit_ripd_only ();
  481. vty->node = CONFIG_NODE;
  482. ret = cmd_execute_command_strict (vline, vty, &cmd);
  483. }
  484. }
  485. else
  486. {
  487. vtysh_execute ("end");
  488. vtysh_execute ("configure terminal");
  489. vty->node = CONFIG_NODE;
  490. ret = cmd_execute_command_strict (vline, vty, &cmd);
  491. }
  492. }
  493. cmd_free_strvec (vline);
  494. switch (ret)
  495. {
  496. case CMD_WARNING:
  497. if (vty->type == VTY_FILE)
  498. fprintf (stdout,"Warning...\n");
  499. break;
  500. case CMD_ERR_AMBIGUOUS:
  501. fprintf (stdout,"%% Ambiguous command.\n");
  502. break;
  503. case CMD_ERR_NO_MATCH:
  504. fprintf (stdout,"%% Unknown command: %s", vty->buf);
  505. break;
  506. case CMD_ERR_INCOMPLETE:
  507. fprintf (stdout,"%% Command incomplete.\n");
  508. break;
  509. case CMD_SUCCESS_DAEMON:
  510. {
  511. if (cmd->daemon & VTYSH_ZEBRA)
  512. if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ZEBRA],
  513. vty->buf, stdout) != CMD_SUCCESS)
  514. break;
  515. if (cmd->daemon & VTYSH_RIPD)
  516. if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIP],
  517. vty->buf, stdout) != CMD_SUCCESS)
  518. break;
  519. if (cmd->daemon & VTYSH_RIPNGD)
  520. if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIPNG],
  521. vty->buf, stdout) != CMD_SUCCESS)
  522. break;
  523. if (cmd->daemon & VTYSH_OSPFD)
  524. if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF],
  525. vty->buf, stdout) != CMD_SUCCESS)
  526. break;
  527. if (cmd->daemon & VTYSH_OSPF6D)
  528. if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF6],
  529. vty->buf, stdout) != CMD_SUCCESS)
  530. break;
  531. if (cmd->daemon & VTYSH_BGPD)
  532. if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_BGP],
  533. vty->buf, stdout) != CMD_SUCCESS)
  534. break;
  535. if (cmd->daemon & VTYSH_ISISD)
  536. if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ISIS],
  537. vty->buf, stdout) != CMD_SUCCESS)
  538. break;
  539. if (cmd->func)
  540. (*cmd->func) (cmd, vty, 0, NULL);
  541. }
  542. }
  543. }
  544. return CMD_SUCCESS;
  545. }
  546. /* We don't care about the point of the cursor when '?' is typed. */
  547. int
  548. vtysh_rl_describe ()
  549. {
  550. int ret;
  551. int i;
  552. vector vline;
  553. vector describe;
  554. int width;
  555. struct desc *desc;
  556. vline = cmd_make_strvec (rl_line_buffer);
  557. /* In case of '> ?'. */
  558. if (vline == NULL)
  559. {
  560. vline = vector_init (1);
  561. vector_set (vline, '\0');
  562. }
  563. else
  564. if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
  565. vector_set (vline, '\0');
  566. describe = cmd_describe_command (vline, vty, &ret);
  567. fprintf (stdout,"\n");
  568. /* Ambiguous and no match error. */
  569. switch (ret)
  570. {
  571. case CMD_ERR_AMBIGUOUS:
  572. cmd_free_strvec (vline);
  573. fprintf (stdout,"%% Ambiguous command.\n");
  574. rl_on_new_line ();
  575. return 0;
  576. break;
  577. case CMD_ERR_NO_MATCH:
  578. cmd_free_strvec (vline);
  579. fprintf (stdout,"%% There is no matched command.\n");
  580. rl_on_new_line ();
  581. return 0;
  582. break;
  583. }
  584. /* Get width of command string. */
  585. width = 0;
  586. for (i = 0; i < vector_max (describe); i++)
  587. if ((desc = vector_slot (describe, i)) != NULL)
  588. {
  589. int len;
  590. if (desc->cmd[0] == '\0')
  591. continue;
  592. len = strlen (desc->cmd);
  593. if (desc->cmd[0] == '.')
  594. len--;
  595. if (width < len)
  596. width = len;
  597. }
  598. for (i = 0; i < vector_max (describe); i++)
  599. if ((desc = vector_slot (describe, i)) != NULL)
  600. {
  601. if (desc->cmd[0] == '\0')
  602. continue;
  603. if (! desc->str)
  604. fprintf (stdout," %-s\n",
  605. desc->cmd[0] == '.' ? desc->cmd + 1 : desc->cmd);
  606. else
  607. fprintf (stdout," %-*s %s\n",
  608. width,
  609. desc->cmd[0] == '.' ? desc->cmd + 1 : desc->cmd,
  610. desc->str);
  611. }
  612. cmd_free_strvec (vline);
  613. vector_free (describe);
  614. rl_on_new_line();
  615. return 0;
  616. }
  617. /* result of cmd_complete_command() call will be stored here
  618. and used in new_completion() in order to put the space in
  619. correct places only */
  620. int complete_status;
  621. char *
  622. command_generator (const char *text, int state)
  623. {
  624. vector vline;
  625. static char **matched = NULL;
  626. static int index = 0;
  627. /* First call. */
  628. if (! state)
  629. {
  630. index = 0;
  631. if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
  632. return NULL;
  633. vline = cmd_make_strvec (rl_line_buffer);
  634. if (vline == NULL)
  635. return NULL;
  636. if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
  637. vector_set (vline, '\0');
  638. matched = cmd_complete_command (vline, vty, &complete_status);
  639. }
  640. if (matched && matched[index])
  641. return matched[index++];
  642. return NULL;
  643. }
  644. char **
  645. new_completion (char *text, int start, int end)
  646. {
  647. char **matches;
  648. matches = rl_completion_matches (text, command_generator);
  649. if (matches)
  650. {
  651. rl_point = rl_end;
  652. if (complete_status == CMD_COMPLETE_FULL_MATCH)
  653. rl_pending_input = ' ';
  654. }
  655. return matches;
  656. }
  657. char **
  658. vtysh_completion (char *text, int start, int end)
  659. {
  660. int ret;
  661. vector vline;
  662. char **matched = NULL;
  663. if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
  664. return NULL;
  665. vline = cmd_make_strvec (rl_line_buffer);
  666. if (vline == NULL)
  667. return NULL;
  668. /* In case of 'help \t'. */
  669. if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
  670. vector_set (vline, '\0');
  671. matched = cmd_complete_command (vline, vty, &ret);
  672. cmd_free_strvec (vline);
  673. return (char **) matched;
  674. }
  675. /* BGP node structure. */
  676. struct cmd_node bgp_node =
  677. {
  678. BGP_NODE,
  679. "%s(config-router)# ",
  680. };
  681. /* BGP node structure. */
  682. struct cmd_node rip_node =
  683. {
  684. RIP_NODE,
  685. "%s(config-router)# ",
  686. };
  687. /* ISIS node structure. */
  688. struct cmd_node isis_node =
  689. {
  690. ISIS_NODE,
  691. "%s(config-router)# ",
  692. 1
  693. };
  694. struct cmd_node interface_node =
  695. {
  696. INTERFACE_NODE,
  697. "%s(config-if)# ",
  698. };
  699. DEFUNSH (VTYSH_BGPD,
  700. router_bgp,
  701. router_bgp_cmd,
  702. "router bgp <1-65535>",
  703. ROUTER_STR
  704. BGP_STR
  705. AS_STR)
  706. {
  707. vty->node = BGP_NODE;
  708. return CMD_SUCCESS;
  709. }
  710. DEFUNSH (VTYSH_BGPD,
  711. address_family_vpnv4,
  712. address_family_vpnv4_cmd,
  713. "address-family vpnv4",
  714. "Enter Address Family command mode\n"
  715. "Address family\n")
  716. {
  717. vty->node = BGP_VPNV4_NODE;
  718. return CMD_SUCCESS;
  719. }
  720. DEFUNSH (VTYSH_BGPD,
  721. address_family_vpnv4_unicast,
  722. address_family_vpnv4_unicast_cmd,
  723. "address-family vpnv4 unicast",
  724. "Enter Address Family command mode\n"
  725. "Address family\n"
  726. "Address Family Modifier\n")
  727. {
  728. vty->node = BGP_VPNV4_NODE;
  729. return CMD_SUCCESS;
  730. }
  731. DEFUNSH (VTYSH_BGPD,
  732. address_family_ipv4_unicast,
  733. address_family_ipv4_unicast_cmd,
  734. "address-family ipv4 unicast",
  735. "Enter Address Family command mode\n"
  736. "Address family\n"
  737. "Address Family Modifier\n")
  738. {
  739. vty->node = BGP_IPV4_NODE;
  740. return CMD_SUCCESS;
  741. }
  742. DEFUNSH (VTYSH_BGPD,
  743. address_family_ipv4_multicast,
  744. address_family_ipv4_multicast_cmd,
  745. "address-family ipv4 multicast",
  746. "Enter Address Family command mode\n"
  747. "Address family\n"
  748. "Address Family Modifier\n")
  749. {
  750. vty->node = BGP_IPV4M_NODE;
  751. return CMD_SUCCESS;
  752. }
  753. DEFUNSH (VTYSH_BGPD,
  754. address_family_ipv6,
  755. address_family_ipv6_cmd,
  756. "address-family ipv6",
  757. "Enter Address Family command mode\n"
  758. "Address family\n")
  759. {
  760. vty->node = BGP_IPV6_NODE;
  761. return CMD_SUCCESS;
  762. }
  763. DEFUNSH (VTYSH_BGPD,
  764. address_family_ipv6_unicast,
  765. address_family_ipv6_unicast_cmd,
  766. "address-family ipv6 unicast",
  767. "Enter Address Family command mode\n"
  768. "Address family\n"
  769. "Address Family Modifier\n")
  770. {
  771. vty->node = BGP_IPV6_NODE;
  772. return CMD_SUCCESS;
  773. }
  774. DEFUNSH (VTYSH_RIPD,
  775. key_chain,
  776. key_chain_cmd,
  777. "key chain WORD",
  778. "Authentication key management\n"
  779. "Key-chain management\n"
  780. "Key-chain name\n")
  781. {
  782. vty->node = KEYCHAIN_NODE;
  783. return CMD_SUCCESS;
  784. }
  785. DEFUNSH (VTYSH_RIPD,
  786. key,
  787. key_cmd,
  788. "key <0-2147483647>",
  789. "Configure a key\n"
  790. "Key identifier number\n")
  791. {
  792. vty->node = KEYCHAIN_KEY_NODE;
  793. return CMD_SUCCESS;
  794. }
  795. DEFUNSH (VTYSH_RIPD,
  796. router_rip,
  797. router_rip_cmd,
  798. "router rip",
  799. ROUTER_STR
  800. "RIP")
  801. {
  802. vty->node = RIP_NODE;
  803. return CMD_SUCCESS;
  804. }
  805. DEFUNSH (VTYSH_RIPNGD,
  806. router_ripng,
  807. router_ripng_cmd,
  808. "router ripng",
  809. ROUTER_STR
  810. "RIPng")
  811. {
  812. vty->node = RIPNG_NODE;
  813. return CMD_SUCCESS;
  814. }
  815. DEFUNSH (VTYSH_OSPFD,
  816. router_ospf,
  817. router_ospf_cmd,
  818. "router ospf",
  819. "Enable a routing process\n"
  820. "Start OSPF configuration\n")
  821. {
  822. vty->node = OSPF_NODE;
  823. return CMD_SUCCESS;
  824. }
  825. DEFUNSH (VTYSH_OSPF6D,
  826. router_ospf6,
  827. router_ospf6_cmd,
  828. "router ospf6",
  829. OSPF6_ROUTER_STR
  830. OSPF6_STR)
  831. {
  832. vty->node = OSPF6_NODE;
  833. return CMD_SUCCESS;
  834. }
  835. DEFUNSH (VTYSH_ISISD,
  836. router_isis,
  837. router_isis_cmd,
  838. "router isis WORD",
  839. ROUTER_STR
  840. "ISO IS-IS\n"
  841. "ISO Routing area tag")
  842. {
  843. vty->node = ISIS_NODE;
  844. return CMD_SUCCESS;
  845. }
  846. DEFUNSH (VTYSH_RMAP,
  847. route_map,
  848. route_map_cmd,
  849. "route-map WORD (deny|permit) <1-65535>",
  850. "Create route-map or enter route-map command mode\n"
  851. "Route map tag\n"
  852. "Route map denies set operations\n"
  853. "Route map permits set operations\n"
  854. "Sequence to insert to/delete from existing route-map entry\n")
  855. {
  856. vty->node = RMAP_NODE;
  857. return CMD_SUCCESS;
  858. }
  859. /* Enable command */
  860. DEFUNSH (VTYSH_ALL,
  861. vtysh_enable,
  862. vtysh_enable_cmd,
  863. "enable",
  864. "Turn on privileged mode command\n")
  865. {
  866. vty->node = ENABLE_NODE;
  867. return CMD_SUCCESS;
  868. }
  869. /* Disable command */
  870. DEFUNSH (VTYSH_ALL,
  871. vtysh_disable,
  872. vtysh_disable_cmd,
  873. "disable",
  874. "Turn off privileged mode command\n")
  875. {
  876. if (vty->node == ENABLE_NODE)
  877. vty->node = VIEW_NODE;
  878. return CMD_SUCCESS;
  879. }
  880. /* Configration from terminal */
  881. DEFUNSH (VTYSH_ALL,
  882. vtysh_config_terminal,
  883. vtysh_config_terminal_cmd,
  884. "configure terminal",
  885. "Configuration from vty interface\n"
  886. "Configuration terminal\n")
  887. {
  888. vty->node = CONFIG_NODE;
  889. return CMD_SUCCESS;
  890. }
  891. int
  892. vtysh_exit (struct vty *vty)
  893. {
  894. switch (vty->node)
  895. {
  896. case VIEW_NODE:
  897. case ENABLE_NODE:
  898. exit (0);
  899. break;
  900. case CONFIG_NODE:
  901. vty->node = ENABLE_NODE;
  902. break;
  903. case INTERFACE_NODE:
  904. case ZEBRA_NODE:
  905. case BGP_NODE:
  906. case RIP_NODE:
  907. case RIPNG_NODE:
  908. case OSPF_NODE:
  909. case OSPF6_NODE:
  910. case ISIS_NODE:
  911. case MASC_NODE:
  912. case RMAP_NODE:
  913. case VTY_NODE:
  914. case KEYCHAIN_NODE:
  915. vty->node = CONFIG_NODE;
  916. break;
  917. case BGP_VPNV4_NODE:
  918. case BGP_IPV4_NODE:
  919. case BGP_IPV4M_NODE:
  920. case BGP_IPV6_NODE:
  921. vty->node = BGP_NODE;
  922. break;
  923. case KEYCHAIN_KEY_NODE:
  924. vty->node = KEYCHAIN_NODE;
  925. break;
  926. default:
  927. break;
  928. }
  929. return CMD_SUCCESS;
  930. }
  931. DEFUNSH (VTYSH_ALL,
  932. vtysh_exit_all,
  933. vtysh_exit_all_cmd,
  934. "exit",
  935. "Exit current mode and down to previous mode\n")
  936. {
  937. return vtysh_exit (vty);
  938. }
  939. ALIAS (vtysh_exit_all,
  940. vtysh_quit_all_cmd,
  941. "quit",
  942. "Exit current mode and down to previous mode\n")
  943. DEFUNSH (VTYSH_BGPD,
  944. exit_address_family,
  945. exit_address_family_cmd,
  946. "exit-address-family",
  947. "Exit from Address Family configuration mode\n")
  948. {
  949. if (vty->node == BGP_IPV4_NODE
  950. || vty->node == BGP_IPV4M_NODE
  951. || vty->node == BGP_VPNV4_NODE
  952. || vty->node == BGP_IPV6_NODE)
  953. vty->node = BGP_NODE;
  954. return CMD_SUCCESS;
  955. }
  956. DEFUNSH (VTYSH_ZEBRA,
  957. vtysh_exit_zebra,
  958. vtysh_exit_zebra_cmd,
  959. "exit",
  960. "Exit current mode and down to previous mode\n")
  961. {
  962. return vtysh_exit (vty);
  963. }
  964. ALIAS (vtysh_exit_zebra,
  965. vtysh_quit_zebra_cmd,
  966. "quit",
  967. "Exit current mode and down to previous mode\n")
  968. DEFUNSH (VTYSH_RIPD,
  969. vtysh_exit_ripd,
  970. vtysh_exit_ripd_cmd,
  971. "exit",
  972. "Exit current mode and down to previous mode\n")
  973. {
  974. return vtysh_exit (vty);
  975. }
  976. ALIAS (vtysh_exit_ripd,
  977. vtysh_quit_ripd_cmd,
  978. "quit",
  979. "Exit current mode and down to previous mode\n")
  980. DEFUNSH (VTYSH_RIPNGD,
  981. vtysh_exit_ripngd,
  982. vtysh_exit_ripngd_cmd,
  983. "exit",
  984. "Exit current mode and down to previous mode\n")
  985. {
  986. return vtysh_exit (vty);
  987. }
  988. ALIAS (vtysh_exit_ripngd,
  989. vtysh_quit_ripngd_cmd,
  990. "quit",
  991. "Exit current mode and down to previous mode\n")
  992. DEFUNSH (VTYSH_RMAP,
  993. vtysh_exit_rmap,
  994. vtysh_exit_rmap_cmd,
  995. "exit",
  996. "Exit current mode and down to previous mode\n")
  997. {
  998. return vtysh_exit (vty);
  999. }
  1000. ALIAS (vtysh_exit_rmap,
  1001. vtysh_quit_rmap_cmd,
  1002. "quit",
  1003. "Exit current mode and down to previous mode\n")
  1004. DEFUNSH (VTYSH_BGPD,
  1005. vtysh_exit_bgpd,
  1006. vtysh_exit_bgpd_cmd,
  1007. "exit",
  1008. "Exit current mode and down to previous mode\n")
  1009. {
  1010. return vtysh_exit (vty);
  1011. }
  1012. ALIAS (vtysh_exit_bgpd,
  1013. vtysh_quit_bgpd_cmd,
  1014. "quit",
  1015. "Exit current mode and down to previous mode\n")
  1016. DEFUNSH (VTYSH_OSPFD,
  1017. vtysh_exit_ospfd,
  1018. vtysh_exit_ospfd_cmd,
  1019. "exit",
  1020. "Exit current mode and down to previous mode\n")
  1021. {
  1022. return vtysh_exit (vty);
  1023. }
  1024. ALIAS (vtysh_exit_ospfd,
  1025. vtysh_quit_ospfd_cmd,
  1026. "quit",
  1027. "Exit current mode and down to previous mode\n")
  1028. DEFUNSH (VTYSH_OSPF6D,
  1029. vtysh_exit_ospf6d,
  1030. vtysh_exit_ospf6d_cmd,
  1031. "exit",
  1032. "Exit current mode and down to previous mode\n")
  1033. {
  1034. return vtysh_exit (vty);
  1035. }
  1036. ALIAS (vtysh_exit_ospf6d,
  1037. vtysh_quit_ospf6d_cmd,
  1038. "quit",
  1039. "Exit current mode and down to previous mode\n")
  1040. DEFUNSH (VTYSH_ISISD,
  1041. vtysh_exit_isisd,
  1042. vtysh_exit_isisd_cmd,
  1043. "exit",
  1044. "Exit current mode and down to previous mode\n")
  1045. {
  1046. return vtysh_exit (vty);
  1047. }
  1048. ALIAS (vtysh_exit_isisd,
  1049. vtysh_quit_isisd_cmd,
  1050. "quit",
  1051. "Exit current mode and down to previous mode\n")
  1052. DEFUNSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_ISISD,
  1053. vtysh_interface,
  1054. vtysh_interface_cmd,
  1055. "interface IFNAME",
  1056. "Select an interface to configure\n"
  1057. "Interface's name\n")
  1058. {
  1059. vty->node = INTERFACE_NODE;
  1060. return CMD_SUCCESS;
  1061. }
  1062. DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D,
  1063. vtysh_no_interface_cmd,
  1064. "no interface IFNAME",
  1065. NO_STR
  1066. "Delete a pseudo interface's configuration\n"
  1067. "Interface's name\n")
  1068. DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
  1069. interface_desc_cmd,
  1070. "description .LINE",
  1071. "Interface specific description\n"
  1072. "Characters describing this interface\n")
  1073. DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
  1074. no_interface_desc_cmd,
  1075. "no description",
  1076. NO_STR
  1077. "Interface specific description\n")
  1078. DEFUNSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_ISISD,
  1079. vtysh_exit_interface,
  1080. vtysh_exit_interface_cmd,
  1081. "exit",
  1082. "Exit current mode and down to previous mode\n")
  1083. {
  1084. return vtysh_exit (vty);
  1085. }
  1086. ALIAS (vtysh_exit_interface,
  1087. vtysh_quit_interface_cmd,
  1088. "quit",
  1089. "Exit current mode and down to previous mode\n")
  1090. DEFUN (vtysh_write_terminal,
  1091. vtysh_write_terminal_cmd,
  1092. "write terminal",
  1093. "Write running configuration to memory, network, or terminal\n"
  1094. "Write to terminal\n")
  1095. {
  1096. int ret;
  1097. char line[] = "write terminal\n";
  1098. FILE *fp = NULL;
  1099. if (vtysh_pager_name)
  1100. {
  1101. fp = popen (vtysh_pager_name, "w");
  1102. if (fp == NULL)
  1103. {
  1104. perror ("popen");
  1105. exit (1);
  1106. }
  1107. }
  1108. else
  1109. fp = stdout;
  1110. vty_out (vty, "Building configuration...%s", VTY_NEWLINE);
  1111. vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE,
  1112. VTY_NEWLINE);
  1113. vtysh_config_write (fp);
  1114. ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_ZEBRA], line);
  1115. ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_RIP], line);
  1116. ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_RIPNG], line);
  1117. ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_OSPF], line);
  1118. ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_OSPF6], line);
  1119. ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_BGP], line);
  1120. ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_ISIS], line);
  1121. vtysh_config_dump (fp);
  1122. if (vtysh_pager_name && fp)
  1123. {
  1124. fflush (fp);
  1125. if (pclose (fp) == -1)
  1126. {
  1127. perror ("pclose");
  1128. exit (1);
  1129. }
  1130. fp = NULL;
  1131. }
  1132. return CMD_SUCCESS;
  1133. }
  1134. struct vtysh_writeconfig_t {
  1135. int daemon;
  1136. int integrated;
  1137. } vtysh_wc = {-1,0};
  1138. DEFUN (vtysh_write_config,
  1139. vtysh_write_config_cmd,
  1140. "write-config (daemon|integrated)",
  1141. "Specify config files to write to\n"
  1142. "Write per daemon file\n"
  1143. "Write integrated file\n"
  1144. )
  1145. {
  1146. if (!strncmp(argv[0],"d",1)) {
  1147. vtysh_wc.daemon = 1;
  1148. } else if (!strncmp(argv[0],"i",1)) {
  1149. vtysh_wc.integrated = 1;
  1150. }
  1151. return CMD_SUCCESS;
  1152. }
  1153. DEFUN (no_vtysh_write_config,
  1154. no_vtysh_write_config_cmd,
  1155. "no write-config (daemon|integrated)",
  1156. "Negate per daemon and/or integrated config files\n"
  1157. )
  1158. {
  1159. if (!strncmp(argv[0],"d",1)) {
  1160. vtysh_wc.daemon = 0;
  1161. } else if (!strncmp(argv[0],"i",1)) {
  1162. vtysh_wc.integrated = 0;
  1163. }
  1164. return CMD_SUCCESS;
  1165. }
  1166. int write_config_integrated(void)
  1167. {
  1168. int ret;
  1169. char line[] = "write terminal\n";
  1170. FILE *fp;
  1171. char *integrate_sav = NULL;
  1172. integrate_sav = malloc (strlen (integrate_default)
  1173. + strlen (CONF_BACKUP_EXT) + 1);
  1174. strcpy (integrate_sav, integrate_default);
  1175. strcat (integrate_sav, CONF_BACKUP_EXT);
  1176. fprintf (stdout,"Building Configuration...\n");
  1177. /* Move current configuration file to backup config file */
  1178. unlink (integrate_sav);
  1179. rename (integrate_default, integrate_sav);
  1180. free (integrate_sav);
  1181. fp = fopen (integrate_default, "w");
  1182. if (fp == NULL)
  1183. {
  1184. fprintf (stdout,"%% Can't open configuration file %s.\n", integrate_default);
  1185. return CMD_SUCCESS;
  1186. }
  1187. vtysh_config_write (fp);
  1188. ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_ZEBRA], line);
  1189. ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_RIP], line);
  1190. ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_RIPNG], line);
  1191. ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_OSPF], line);
  1192. ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_OSPF6], line);
  1193. ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_BGP], line);
  1194. ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_ISIS], line);
  1195. vtysh_config_dump (fp);
  1196. fclose (fp);
  1197. if (chmod (integrate_default, CONFIGFILE_MASK) != 0)
  1198. {
  1199. fprintf (stdout,"%% Can't chmod configuration file %s: %s (%d)\n",
  1200. integrate_default, strerror(errno), errno);
  1201. return CMD_WARNING;
  1202. }
  1203. fprintf(stdout,"Integrated configuration saved to %s\n",integrate_default);
  1204. fprintf (stdout,"[OK]\n");
  1205. return CMD_SUCCESS;
  1206. }
  1207. DEFUN (vtysh_write_memory,
  1208. vtysh_write_memory_cmd,
  1209. "write memory",
  1210. "Write running configuration to memory, network, or terminal\n"
  1211. "Write configuration to the file (same as write file)\n")
  1212. {
  1213. int ret = CMD_SUCCESS;
  1214. char line[] = "write memory\n";
  1215. /* if integrated Zebra.conf explicitely set */
  1216. if (vtysh_wc.integrated == 1) {
  1217. ret = write_config_integrated();
  1218. }
  1219. if (!vtysh_wc.daemon) {
  1220. return ret;
  1221. }
  1222. fprintf (stdout,"Building Configuration...\n");
  1223. ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ZEBRA], line, stdout);
  1224. ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIP], line, stdout);
  1225. ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIPNG], line, stdout);
  1226. ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF], line, stdout);
  1227. ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF6], line, stdout);
  1228. ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_BGP], line, stdout);
  1229. ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ISIS], line, stdout);
  1230. fprintf (stdout,"[OK]\n");
  1231. return ret;
  1232. }
  1233. ALIAS (vtysh_write_memory,
  1234. vtysh_copy_runningconfig_startupconfig_cmd,
  1235. "copy running-config startup-config",
  1236. "Copy from one file to another\n"
  1237. "Copy from current system configuration\n"
  1238. "Copy to startup configuration\n")
  1239. ALIAS (vtysh_write_memory,
  1240. vtysh_write_file_cmd,
  1241. "write file",
  1242. "Write running configuration to memory, network, or terminal\n"
  1243. "Write configuration to the file (same as write memory)\n")
  1244. ALIAS (vtysh_write_memory,
  1245. vtysh_write_cmd,
  1246. "write",
  1247. "Write running configuration to memory, network, or terminal\n")
  1248. ALIAS (vtysh_write_terminal,
  1249. vtysh_show_running_config_cmd,
  1250. "show running-config",
  1251. SHOW_STR
  1252. "Current operating configuration\n")
  1253. /* Execute command in child process. */
  1254. int
  1255. execute_command (char *command, int argc, char *arg1, char *arg2)
  1256. {
  1257. int ret;
  1258. pid_t pid;
  1259. int status;
  1260. /* Call fork(). */
  1261. pid = fork ();
  1262. if (pid < 0)
  1263. {
  1264. /* Failure of fork(). */
  1265. fprintf (stderr, "Can't fork: %s\n", strerror (errno));
  1266. exit (1);
  1267. }
  1268. else if (pid == 0)
  1269. {
  1270. /* This is child process. */
  1271. switch (argc)
  1272. {
  1273. case 0:
  1274. ret = execlp (command, command, (const char *)NULL);
  1275. break;
  1276. case 1:
  1277. ret = execlp (command, command, arg1, (const char *)NULL);
  1278. break;
  1279. case 2:
  1280. ret = execlp (command, command, arg1, arg2, (const char *)NULL);
  1281. break;
  1282. }
  1283. /* When execlp suceed, this part is not executed. */
  1284. fprintf (stderr, "Can't execute %s: %s\n", command, strerror (errno));
  1285. exit (1);
  1286. }
  1287. else
  1288. {
  1289. /* This is parent. */
  1290. execute_flag = 1;
  1291. ret = wait4 (pid, &status, 0, NULL);
  1292. execute_flag = 0;
  1293. }
  1294. return 0;
  1295. }
  1296. DEFUN (vtysh_ping,
  1297. vtysh_ping_cmd,
  1298. "ping WORD",
  1299. "Send echo messages\n"
  1300. "Ping destination address or hostname\n")
  1301. {
  1302. execute_command ("ping", 1, argv[0], NULL);
  1303. return CMD_SUCCESS;
  1304. }
  1305. ALIAS (vtysh_ping,
  1306. vtysh_ping_ip_cmd,
  1307. "ping ip WORD",
  1308. "Send echo messages\n"
  1309. "IP echo\n"
  1310. "Ping destination address or hostname\n")
  1311. DEFUN (vtysh_traceroute,
  1312. vtysh_traceroute_cmd,
  1313. "traceroute WORD",
  1314. "Trace route to destination\n"
  1315. "Trace route to destination address or hostname\n")
  1316. {
  1317. execute_command ("traceroute", 1, argv[0], NULL);
  1318. return CMD_SUCCESS;
  1319. }
  1320. ALIAS (vtysh_traceroute,
  1321. vtysh_traceroute_ip_cmd,
  1322. "traceroute ip WORD",
  1323. "Trace route to destination\n"
  1324. "IP trace\n"
  1325. "Trace route to destination address or hostname\n")
  1326. #ifdef HAVE_IPV6
  1327. DEFUN (vtysh_ping6,
  1328. vtysh_ping6_cmd,
  1329. "ping ipv6 WORD",
  1330. "Send echo messages\n"
  1331. "IPv6 echo\n"
  1332. "Ping destination address or hostname\n")
  1333. {
  1334. execute_command ("ping6", 1, argv[0], NULL);
  1335. return CMD_SUCCESS;
  1336. }
  1337. DEFUN (vtysh_traceroute6,
  1338. vtysh_traceroute6_cmd,
  1339. "traceroute ipv6 WORD",
  1340. "Trace route to destination\n"
  1341. "IPv6 trace\n"
  1342. "Trace route to destination address or hostname\n")
  1343. {
  1344. execute_command ("traceroute6", 1, argv[0], NULL);
  1345. return CMD_SUCCESS;
  1346. }
  1347. #endif
  1348. DEFUN (vtysh_telnet,
  1349. vtysh_telnet_cmd,
  1350. "telnet WORD",
  1351. "Open a telnet connection\n"
  1352. "IP address or hostname of a remote system\n")
  1353. {
  1354. execute_command ("telnet", 1, argv[0], NULL);
  1355. return CMD_SUCCESS;
  1356. }
  1357. DEFUN (vtysh_telnet_port,
  1358. vtysh_telnet_port_cmd,
  1359. "telnet WORD PORT",
  1360. "Open a telnet connection\n"
  1361. "IP address or hostname of a remote system\n"
  1362. "TCP Port number\n")
  1363. {
  1364. execute_command ("telnet", 2, argv[0], argv[1]);
  1365. return CMD_SUCCESS;
  1366. }
  1367. DEFUN (vtysh_ssh,
  1368. vtysh_ssh_cmd,
  1369. "ssh WORD",
  1370. "Open an ssh connection\n"
  1371. "[user@]host\n")
  1372. {
  1373. execute_command ("ssh", 1, argv[0], NULL);
  1374. return CMD_SUCCESS;
  1375. }
  1376. DEFUN (vtysh_start_shell,
  1377. vtysh_start_shell_cmd,
  1378. "start-shell",
  1379. "Start UNIX shell\n")
  1380. {
  1381. execute_command ("sh", 0, NULL, NULL);
  1382. return CMD_SUCCESS;
  1383. }
  1384. DEFUN (vtysh_start_bash,
  1385. vtysh_start_bash_cmd,
  1386. "start-shell bash",
  1387. "Start UNIX shell\n"
  1388. "Start bash\n")
  1389. {
  1390. execute_command ("bash", 0, NULL, NULL);
  1391. return CMD_SUCCESS;
  1392. }
  1393. DEFUN (vtysh_start_zsh,
  1394. vtysh_start_zsh_cmd,
  1395. "start-shell zsh",
  1396. "Start UNIX shell\n"
  1397. "Start Z shell\n")
  1398. {
  1399. execute_command ("zsh", 0, NULL, NULL);
  1400. return CMD_SUCCESS;
  1401. }
  1402. /* Route map node structure. */
  1403. struct cmd_node rmap_node =
  1404. {
  1405. RMAP_NODE,
  1406. "%s(config-route-map)# "
  1407. };
  1408. /* Zebra node structure. */
  1409. struct cmd_node zebra_node =
  1410. {
  1411. ZEBRA_NODE,
  1412. "%s(config-router)# "
  1413. };
  1414. struct cmd_node bgp_vpnv4_node =
  1415. {
  1416. BGP_VPNV4_NODE,
  1417. "%s(config-router-af)# "
  1418. };
  1419. struct cmd_node bgp_ipv4_node =
  1420. {
  1421. BGP_IPV4_NODE,
  1422. "%s(config-router-af)# "
  1423. };
  1424. struct cmd_node bgp_ipv4m_node =
  1425. {
  1426. BGP_IPV4M_NODE,
  1427. "%s(config-router-af)# "
  1428. };
  1429. struct cmd_node bgp_ipv6_node =
  1430. {
  1431. BGP_IPV6_NODE,
  1432. "%s(config-router-af)# "
  1433. };
  1434. struct cmd_node ospf_node =
  1435. {
  1436. OSPF_NODE,
  1437. "%s(config-router)# "
  1438. };
  1439. /* RIPng node structure. */
  1440. struct cmd_node ripng_node =
  1441. {
  1442. RIPNG_NODE,
  1443. "%s(config-router)# "
  1444. };
  1445. /* OSPF6 node structure. */
  1446. struct cmd_node ospf6_node =
  1447. {
  1448. OSPF6_NODE,
  1449. "%s(config-ospf6)# "
  1450. };
  1451. struct cmd_node keychain_node =
  1452. {
  1453. KEYCHAIN_NODE,
  1454. "%s(config-keychain)# "
  1455. };
  1456. struct cmd_node keychain_key_node =
  1457. {
  1458. KEYCHAIN_KEY_NODE,
  1459. "%s(config-keychain-key)# "
  1460. };
  1461. void
  1462. vtysh_install_default (enum node_type node)
  1463. {
  1464. install_element (node, &config_list_cmd);
  1465. }
  1466. /* Making connection to protocol daemon. */
  1467. int
  1468. vtysh_connect (struct vtysh_client *vclient, char *path)
  1469. {
  1470. int ret;
  1471. int sock, len;
  1472. struct sockaddr_un addr;
  1473. struct stat s_stat;
  1474. uid_t euid;
  1475. gid_t egid;
  1476. memset (vclient, 0, sizeof (struct vtysh_client));
  1477. vclient->fd = -1;
  1478. /* Stat socket to see if we have permission to access it. */
  1479. euid = geteuid();
  1480. egid = getegid();
  1481. ret = stat (path, &s_stat);
  1482. if (ret < 0 && errno != ENOENT)
  1483. {
  1484. fprintf (stderr, "vtysh_connect(%s): stat = %s\n",
  1485. path, strerror(errno));
  1486. exit(1);
  1487. }
  1488. if (ret >= 0)
  1489. {
  1490. if (! S_ISSOCK(s_stat.st_mode))
  1491. {
  1492. fprintf (stderr, "vtysh_connect(%s): Not a socket\n",
  1493. path);
  1494. exit (1);
  1495. }
  1496. }
  1497. sock = socket (AF_UNIX, SOCK_STREAM, 0);
  1498. if (sock < 0)
  1499. {
  1500. #ifdef DEBUG
  1501. fprintf(stderr, "vtysh_connect(%s): socket = %s\n", path, strerror(errno));
  1502. #endif /* DEBUG */
  1503. return -1;
  1504. }
  1505. memset (&addr, 0, sizeof (struct sockaddr_un));
  1506. addr.sun_family = AF_UNIX;
  1507. strncpy (addr.sun_path, path, strlen (path));
  1508. #ifdef HAVE_SUN_LEN
  1509. len = addr.sun_len = SUN_LEN(&addr);
  1510. #else
  1511. len = sizeof (addr.sun_family) + strlen (addr.sun_path);
  1512. #endif /* HAVE_SUN_LEN */
  1513. ret = connect (sock, (struct sockaddr *) &addr, len);
  1514. if (ret < 0)
  1515. {
  1516. #ifdef DEBUG
  1517. fprintf(stderr, "vtysh_connect(%s): connect = %s\n", path, strerror(errno));
  1518. #endif /* DEBUG */
  1519. close (sock);
  1520. return -1;
  1521. }
  1522. vclient->fd = sock;
  1523. return 0;
  1524. }
  1525. void
  1526. vtysh_connect_all()
  1527. {
  1528. /* Clear each daemons client structure. */
  1529. vtysh_connect (&vtysh_client[VTYSH_INDEX_ZEBRA], ZEBRA_VTYSH_PATH);
  1530. vtysh_connect (&vtysh_client[VTYSH_INDEX_RIP], RIP_VTYSH_PATH);
  1531. vtysh_connect (&vtysh_client[VTYSH_INDEX_RIPNG], RIPNG_VTYSH_PATH);
  1532. vtysh_connect (&vtysh_client[VTYSH_INDEX_OSPF], OSPF_VTYSH_PATH);
  1533. vtysh_connect (&vtysh_client[VTYSH_INDEX_OSPF6], OSPF6_VTYSH_PATH);
  1534. vtysh_connect (&vtysh_client[VTYSH_INDEX_BGP], BGP_VTYSH_PATH);
  1535. vtysh_connect (&vtysh_client[VTYSH_INDEX_ISIS], ISIS_VTYSH_PATH);
  1536. }
  1537. /* To disable readline's filename completion */
  1538. char *
  1539. vtysh_completion_entry_function (const char *ignore, int invoking_key)
  1540. {
  1541. return NULL;
  1542. }
  1543. void
  1544. vtysh_readline_init ()
  1545. {
  1546. /* readline related settings. */
  1547. rl_bind_key ('?', vtysh_rl_describe);
  1548. rl_completion_entry_function = vtysh_completion_entry_function;
  1549. rl_attempted_completion_function = (CPPFunction *)new_completion;
  1550. /* do not append space after completion. It will be appended
  1551. in new_completion() function explicitly */
  1552. rl_completion_append_character = '\0';
  1553. }
  1554. char *
  1555. vtysh_prompt ()
  1556. {
  1557. struct utsname names;
  1558. static char buf[100];
  1559. const char*hostname;
  1560. extern struct host host;
  1561. hostname = host.name;
  1562. if (!hostname)
  1563. {
  1564. uname (&names);
  1565. hostname = names.nodename;
  1566. }
  1567. snprintf (buf, sizeof buf, cmd_prompt (vty->node), hostname);
  1568. return buf;
  1569. }
  1570. void
  1571. vtysh_init_vty ()
  1572. {
  1573. /* Make vty structure. */
  1574. vty = vty_new ();
  1575. vty->type = VTY_SHELL;
  1576. vty->node = VIEW_NODE;
  1577. /* Initialize commands. */
  1578. cmd_init (0);
  1579. /* Install nodes. */
  1580. install_node (&bgp_node, NULL);
  1581. install_node (&rip_node, NULL);
  1582. install_node (&interface_node, NULL);
  1583. install_node (&rmap_node, NULL);
  1584. install_node (&zebra_node, NULL);
  1585. install_node (&bgp_vpnv4_node, NULL);
  1586. install_node (&bgp_ipv4_node, NULL);
  1587. install_node (&bgp_ipv4m_node, NULL);
  1588. /* #ifdef HAVE_IPV6 */
  1589. install_node (&bgp_ipv6_node, NULL);
  1590. /* #endif */
  1591. install_node (&ospf_node, NULL);
  1592. /* #ifdef HAVE_IPV6 */
  1593. install_node (&ripng_node, NULL);
  1594. install_node (&ospf6_node, NULL);
  1595. /* #endif */
  1596. install_node (&keychain_node, NULL);
  1597. install_node (&keychain_key_node, NULL);
  1598. install_node (&isis_node, NULL);
  1599. vtysh_install_default (VIEW_NODE);
  1600. vtysh_install_default (ENABLE_NODE);
  1601. vtysh_install_default (CONFIG_NODE);
  1602. vtysh_install_default (BGP_NODE);
  1603. vtysh_install_default (RIP_NODE);
  1604. vtysh_install_default (INTERFACE_NODE);
  1605. vtysh_install_default (RMAP_NODE);
  1606. vtysh_install_default (ZEBRA_NODE);
  1607. vtysh_install_default (BGP_VPNV4_NODE);
  1608. vtysh_install_default (BGP_IPV4_NODE);
  1609. vtysh_install_default (BGP_IPV4M_NODE);
  1610. vtysh_install_default (BGP_IPV6_NODE);
  1611. vtysh_install_default (OSPF_NODE);
  1612. vtysh_install_default (RIPNG_NODE);
  1613. vtysh_install_default (OSPF6_NODE);
  1614. vtysh_install_default (ISIS_NODE);
  1615. vtysh_install_default (KEYCHAIN_NODE);
  1616. vtysh_install_default (KEYCHAIN_KEY_NODE);
  1617. install_element (VIEW_NODE, &vtysh_enable_cmd);
  1618. install_element (ENABLE_NODE, &vtysh_config_terminal_cmd);
  1619. install_element (ENABLE_NODE, &vtysh_disable_cmd);
  1620. /* "exit" command. */
  1621. install_element (VIEW_NODE, &vtysh_exit_all_cmd);
  1622. install_element (VIEW_NODE, &vtysh_quit_all_cmd);
  1623. install_element (CONFIG_NODE, &vtysh_exit_all_cmd);
  1624. /* install_element (CONFIG_NODE, &vtysh_quit_all_cmd); */
  1625. install_element (ENABLE_NODE, &vtysh_exit_all_cmd);
  1626. install_element (ENABLE_NODE, &vtysh_quit_all_cmd);
  1627. install_element (RIP_NODE, &vtysh_exit_ripd_cmd);
  1628. install_element (RIP_NODE, &vtysh_quit_ripd_cmd);
  1629. install_element (RIPNG_NODE, &vtysh_exit_ripngd_cmd);
  1630. install_element (RIPNG_NODE, &vtysh_quit_ripngd_cmd);
  1631. install_element (OSPF_NODE, &vtysh_exit_ospfd_cmd);
  1632. install_element (OSPF_NODE, &vtysh_quit_ospfd_cmd);
  1633. install_element (OSPF6_NODE, &vtysh_exit_ospf6d_cmd);
  1634. install_element (OSPF6_NODE, &vtysh_quit_ospf6d_cmd);
  1635. install_element (BGP_NODE, &vtysh_exit_bgpd_cmd);
  1636. install_element (BGP_NODE, &vtysh_quit_bgpd_cmd);
  1637. install_element (BGP_VPNV4_NODE, &vtysh_exit_bgpd_cmd);
  1638. install_element (BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd);
  1639. install_element (BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd);
  1640. install_element (BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd);
  1641. install_element (BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd);
  1642. install_element (BGP_IPV4M_NODE, &vtysh_quit_bgpd_cmd);
  1643. install_element (BGP_IPV6_NODE, &vtysh_exit_bgpd_cmd);
  1644. install_element (BGP_IPV6_NODE, &vtysh_quit_bgpd_cmd);
  1645. install_element (ISIS_NODE, &vtysh_exit_isisd_cmd);
  1646. install_element (ISIS_NODE, &vtysh_quit_isisd_cmd);
  1647. install_element (KEYCHAIN_NODE, &vtysh_exit_ripd_cmd);
  1648. install_element (KEYCHAIN_NODE, &vtysh_quit_ripd_cmd);
  1649. install_element (KEYCHAIN_KEY_NODE, &vtysh_exit_ripd_cmd);
  1650. install_element (KEYCHAIN_KEY_NODE, &vtysh_quit_ripd_cmd);
  1651. install_element (RMAP_NODE, &vtysh_exit_rmap_cmd);
  1652. install_element (RMAP_NODE, &vtysh_quit_rmap_cmd);
  1653. /* "end" command. */
  1654. install_element (CONFIG_NODE, &vtysh_end_all_cmd);
  1655. install_element (ENABLE_NODE, &vtysh_end_all_cmd);
  1656. install_element (RIP_NODE, &vtysh_end_all_cmd);
  1657. install_element (RIPNG_NODE, &vtysh_end_all_cmd);
  1658. install_element (OSPF_NODE, &vtysh_end_all_cmd);
  1659. install_element (OSPF6_NODE, &vtysh_end_all_cmd);
  1660. install_element (BGP_NODE, &vtysh_end_all_cmd);
  1661. install_element (BGP_IPV4_NODE, &vtysh_end_all_cmd);
  1662. install_element (BGP_IPV4M_NODE, &vtysh_end_all_cmd);
  1663. install_element (BGP_VPNV4_NODE, &vtysh_end_all_cmd);
  1664. install_element (BGP_IPV6_NODE, &vtysh_end_all_cmd);
  1665. install_element (ISIS_NODE, &vtysh_end_all_cmd);
  1666. install_element (KEYCHAIN_NODE, &vtysh_end_all_cmd);
  1667. install_element (KEYCHAIN_KEY_NODE, &vtysh_end_all_cmd);
  1668. install_element (RMAP_NODE, &vtysh_end_all_cmd);
  1669. install_element (INTERFACE_NODE, &interface_desc_cmd);
  1670. install_element (INTERFACE_NODE, &no_interface_desc_cmd);
  1671. install_element (INTERFACE_NODE, &vtysh_end_all_cmd);
  1672. install_element (INTERFACE_NODE, &vtysh_exit_interface_cmd);
  1673. install_element (INTERFACE_NODE, &vtysh_quit_interface_cmd);
  1674. install_element (CONFIG_NODE, &router_rip_cmd);
  1675. #ifdef HAVE_IPV6
  1676. install_element (CONFIG_NODE, &router_ripng_cmd);
  1677. #endif
  1678. install_element (CONFIG_NODE, &router_ospf_cmd);
  1679. #ifdef HAVE_IPV6
  1680. install_element (CONFIG_NODE, &router_ospf6_cmd);
  1681. #endif
  1682. install_element (CONFIG_NODE, &router_isis_cmd);
  1683. install_element (CONFIG_NODE, &router_bgp_cmd);
  1684. install_element (BGP_NODE, &address_family_vpnv4_cmd);
  1685. install_element (BGP_NODE, &address_family_vpnv4_unicast_cmd);
  1686. install_element (BGP_NODE, &address_family_ipv4_unicast_cmd);
  1687. install_element (BGP_NODE, &address_family_ipv4_multicast_cmd);
  1688. #ifdef HAVE_IPV6
  1689. install_element (BGP_NODE, &address_family_ipv6_cmd);
  1690. install_element (BGP_NODE, &address_family_ipv6_unicast_cmd);
  1691. #endif
  1692. install_element (BGP_VPNV4_NODE, &exit_address_family_cmd);
  1693. install_element (BGP_IPV4_NODE, &exit_address_family_cmd);
  1694. install_element (BGP_IPV4M_NODE, &exit_address_family_cmd);
  1695. install_element (BGP_IPV6_NODE, &exit_address_family_cmd);
  1696. install_element (CONFIG_NODE, &key_chain_cmd);
  1697. install_element (CONFIG_NODE, &route_map_cmd);
  1698. install_element (KEYCHAIN_NODE, &key_cmd);
  1699. install_element (KEYCHAIN_NODE, &key_chain_cmd);
  1700. install_element (KEYCHAIN_KEY_NODE, &key_chain_cmd);
  1701. install_element (CONFIG_NODE, &vtysh_interface_cmd);
  1702. install_element (CONFIG_NODE, &vtysh_no_interface_cmd);
  1703. install_element (ENABLE_NODE, &vtysh_show_running_config_cmd);
  1704. install_element (ENABLE_NODE, &vtysh_copy_runningconfig_startupconfig_cmd);
  1705. install_element (ENABLE_NODE, &vtysh_write_file_cmd);
  1706. install_element (ENABLE_NODE, &vtysh_write_cmd);
  1707. /* write terminal command */
  1708. install_element (ENABLE_NODE, &vtysh_write_terminal_cmd);
  1709. install_element (CONFIG_NODE, &vtysh_write_terminal_cmd);
  1710. install_element (BGP_NODE, &vtysh_write_terminal_cmd);
  1711. install_element (BGP_VPNV4_NODE, &vtysh_write_terminal_cmd);
  1712. install_element (BGP_IPV4_NODE, &vtysh_write_terminal_cmd);
  1713. install_element (BGP_IPV4M_NODE, &vtysh_write_terminal_cmd);
  1714. install_element (BGP_IPV6_NODE, &vtysh_write_terminal_cmd);
  1715. install_element (RIP_NODE, &vtysh_write_terminal_cmd);
  1716. install_element (RIPNG_NODE, &vtysh_write_terminal_cmd);
  1717. install_element (OSPF_NODE, &vtysh_write_terminal_cmd);
  1718. install_element (OSPF6_NODE, &vtysh_write_terminal_cmd);
  1719. install_element (ISIS_NODE, &vtysh_write_terminal_cmd);
  1720. install_element (INTERFACE_NODE, &vtysh_write_terminal_cmd);
  1721. install_element (RMAP_NODE, &vtysh_write_terminal_cmd);
  1722. install_element (KEYCHAIN_NODE, &vtysh_write_terminal_cmd);
  1723. install_element (KEYCHAIN_KEY_NODE, &vtysh_write_terminal_cmd);
  1724. /* write memory command */
  1725. install_element (ENABLE_NODE, &vtysh_write_memory_cmd);
  1726. install_element (CONFIG_NODE, &vtysh_write_memory_cmd);
  1727. install_element (BGP_NODE, &vtysh_write_memory_cmd);
  1728. install_element (BGP_VPNV4_NODE, &vtysh_write_memory_cmd);
  1729. install_element (BGP_IPV4_NODE, &vtysh_write_memory_cmd);
  1730. install_element (BGP_IPV4M_NODE, &vtysh_write_memory_cmd);
  1731. install_element (BGP_IPV6_NODE, &vtysh_write_memory_cmd);
  1732. install_element (RIP_NODE, &vtysh_write_memory_cmd);
  1733. install_element (RIPNG_NODE, &vtysh_write_memory_cmd);
  1734. install_element (OSPF_NODE, &vtysh_write_memory_cmd);
  1735. install_element (OSPF6_NODE, &vtysh_write_memory_cmd);
  1736. install_element (ISIS_NODE, &vtysh_write_memory_cmd);
  1737. install_element (INTERFACE_NODE, &vtysh_write_memory_cmd);
  1738. install_element (RMAP_NODE, &vtysh_write_memory_cmd);
  1739. install_element (KEYCHAIN_NODE, &vtysh_write_memory_cmd);
  1740. install_element (KEYCHAIN_KEY_NODE, &vtysh_write_memory_cmd);
  1741. install_element (VIEW_NODE, &vtysh_ping_cmd);
  1742. install_element (VIEW_NODE, &vtysh_ping_ip_cmd);
  1743. install_element (VIEW_NODE, &vtysh_traceroute_cmd);
  1744. install_element (VIEW_NODE, &vtysh_traceroute_ip_cmd);
  1745. #ifdef HAVE_IPV6
  1746. install_element (VIEW_NODE, &vtysh_ping6_cmd);
  1747. install_element (VIEW_NODE, &vtysh_traceroute6_cmd);
  1748. #endif
  1749. install_element (VIEW_NODE, &vtysh_telnet_cmd);
  1750. install_element (VIEW_NODE, &vtysh_telnet_port_cmd);
  1751. install_element (VIEW_NODE, &vtysh_ssh_cmd);
  1752. install_element (ENABLE_NODE, &vtysh_ping_cmd);
  1753. install_element (ENABLE_NODE, &vtysh_ping_ip_cmd);
  1754. install_element (ENABLE_NODE, &vtysh_traceroute_cmd);
  1755. install_element (ENABLE_NODE, &vtysh_traceroute_ip_cmd);
  1756. #ifdef HAVE_IPV6
  1757. install_element (ENABLE_NODE, &vtysh_ping6_cmd);
  1758. install_element (ENABLE_NODE, &vtysh_traceroute6_cmd);
  1759. #endif
  1760. install_element (ENABLE_NODE, &vtysh_telnet_cmd);
  1761. install_element (ENABLE_NODE, &vtysh_telnet_port_cmd);
  1762. install_element (ENABLE_NODE, &vtysh_start_shell_cmd);
  1763. install_element (ENABLE_NODE, &vtysh_start_bash_cmd);
  1764. install_element (ENABLE_NODE, &vtysh_start_zsh_cmd);
  1765. install_element (CONFIG_NODE, &vtysh_log_stdout_cmd);
  1766. install_element (CONFIG_NODE, &no_vtysh_log_stdout_cmd);
  1767. install_element (CONFIG_NODE, &vtysh_log_file_cmd);
  1768. install_element (CONFIG_NODE, &no_vtysh_log_file_cmd);
  1769. install_element (CONFIG_NODE, &vtysh_log_syslog_cmd);
  1770. install_element (CONFIG_NODE, &no_vtysh_log_syslog_cmd);
  1771. install_element (CONFIG_NODE, &vtysh_log_trap_cmd);
  1772. install_element (CONFIG_NODE, &no_vtysh_log_trap_cmd);
  1773. install_element (CONFIG_NODE, &vtysh_log_record_priority_cmd);
  1774. install_element (CONFIG_NODE, &no_vtysh_log_record_priority_cmd);
  1775. install_element (CONFIG_NODE, &vtysh_write_config_cmd);
  1776. install_element (CONFIG_NODE, &no_vtysh_write_config_cmd);
  1777. }