vtysh.c 71 KB

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