zebra_vty.c 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956
  1. /* Zebra VTY functions
  2. * Copyright (C) 2002 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
  18. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. * Boston, MA 02111-1307, USA.
  20. */
  21. #include <zebra.h>
  22. #include "if.h"
  23. #include "prefix.h"
  24. #include "command.h"
  25. #include "table.h"
  26. #include "rib.h"
  27. #include "zebra/zserv.h"
  28. /* General fucntion for static route. */
  29. static int
  30. zebra_static_ipv4 (struct vty *vty, int add_cmd, const char *dest_str,
  31. const char *mask_str, const char *gate_str,
  32. const char *flag_str, const char *distance_str)
  33. {
  34. int ret;
  35. u_char distance;
  36. struct prefix p;
  37. struct in_addr gate;
  38. struct in_addr mask;
  39. const char *ifname;
  40. u_char flag = 0;
  41. ret = str2prefix (dest_str, &p);
  42. if (ret <= 0)
  43. {
  44. vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
  45. return CMD_WARNING;
  46. }
  47. /* Cisco like mask notation. */
  48. if (mask_str)
  49. {
  50. ret = inet_aton (mask_str, &mask);
  51. if (ret == 0)
  52. {
  53. vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
  54. return CMD_WARNING;
  55. }
  56. p.prefixlen = ip_masklen (mask);
  57. }
  58. /* Apply mask for given prefix. */
  59. apply_mask (&p);
  60. /* Administrative distance. */
  61. if (distance_str)
  62. distance = atoi (distance_str);
  63. else
  64. distance = ZEBRA_STATIC_DISTANCE_DEFAULT;
  65. /* Null0 static route. */
  66. if ((gate_str != NULL) && (strncasecmp (gate_str, "Null0", strlen (gate_str)) == 0))
  67. {
  68. if (flag_str)
  69. {
  70. vty_out (vty, "%% can not have flag %s with Null0%s", flag_str, VTY_NEWLINE);
  71. return CMD_WARNING;
  72. }
  73. if (add_cmd)
  74. static_add_ipv4 (&p, NULL, NULL, ZEBRA_FLAG_BLACKHOLE, distance, 0);
  75. else
  76. static_delete_ipv4 (&p, NULL, NULL, distance, 0);
  77. return CMD_SUCCESS;
  78. }
  79. /* Route flags */
  80. if (flag_str) {
  81. switch(flag_str[0]) {
  82. case 'r':
  83. case 'R': /* XXX */
  84. SET_FLAG (flag, ZEBRA_FLAG_REJECT);
  85. break;
  86. case 'b':
  87. case 'B': /* XXX */
  88. SET_FLAG (flag, ZEBRA_FLAG_BLACKHOLE);
  89. break;
  90. default:
  91. vty_out (vty, "%% Malformed flag %s %s", flag_str, VTY_NEWLINE);
  92. return CMD_WARNING;
  93. }
  94. }
  95. if (gate_str == NULL)
  96. {
  97. if (add_cmd)
  98. static_add_ipv4 (&p, NULL, NULL, flag, distance, 0);
  99. else
  100. static_delete_ipv4 (&p, NULL, NULL, distance, 0);
  101. return CMD_SUCCESS;
  102. }
  103. /* When gateway is A.B.C.D format, gate is treated as nexthop
  104. address other case gate is treated as interface name. */
  105. ret = inet_aton (gate_str, &gate);
  106. if (ret)
  107. ifname = NULL;
  108. else
  109. ifname = gate_str;
  110. if (add_cmd)
  111. static_add_ipv4 (&p, ifname ? NULL : &gate, ifname, flag, distance, 0);
  112. else
  113. static_delete_ipv4 (&p, ifname ? NULL : &gate, ifname, distance, 0);
  114. return CMD_SUCCESS;
  115. }
  116. /* Static route configuration. */
  117. DEFUN (ip_route,
  118. ip_route_cmd,
  119. "ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0)",
  120. IP_STR
  121. "Establish static routes\n"
  122. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  123. "IP gateway address\n"
  124. "IP gateway interface name\n"
  125. "Null interface\n")
  126. {
  127. return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], NULL, NULL);
  128. }
  129. DEFUN (ip_route_flags,
  130. ip_route_flags_cmd,
  131. "ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole)",
  132. IP_STR
  133. "Establish static routes\n"
  134. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  135. "IP gateway address\n"
  136. "IP gateway interface name\n"
  137. "Emit an ICMP unreachable when matched\n"
  138. "Silently discard pkts when matched\n")
  139. {
  140. return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], argv[2], NULL);
  141. }
  142. DEFUN (ip_route_flags2,
  143. ip_route_flags2_cmd,
  144. "ip route A.B.C.D/M (reject|blackhole)",
  145. IP_STR
  146. "Establish static routes\n"
  147. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  148. "Emit an ICMP unreachable when matched\n"
  149. "Silently discard pkts when matched\n")
  150. {
  151. return zebra_static_ipv4 (vty, 1, argv[0], NULL, NULL, argv[1], NULL);
  152. }
  153. /* Mask as A.B.C.D format. */
  154. DEFUN (ip_route_mask,
  155. ip_route_mask_cmd,
  156. "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0)",
  157. IP_STR
  158. "Establish static routes\n"
  159. "IP destination prefix\n"
  160. "IP destination prefix mask\n"
  161. "IP gateway address\n"
  162. "IP gateway interface name\n"
  163. "Null interface\n")
  164. {
  165. return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], NULL, NULL);
  166. }
  167. DEFUN (ip_route_mask_flags,
  168. ip_route_mask_flags_cmd,
  169. "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole)",
  170. IP_STR
  171. "Establish static routes\n"
  172. "IP destination prefix\n"
  173. "IP destination prefix mask\n"
  174. "IP gateway address\n"
  175. "IP gateway interface name\n"
  176. "Emit an ICMP unreachable when matched\n"
  177. "Silently discard pkts when matched\n")
  178. {
  179. return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], argv[3], NULL);
  180. }
  181. DEFUN (ip_route_mask_flags2,
  182. ip_route_mask_flags2_cmd,
  183. "ip route A.B.C.D A.B.C.D (reject|blackhole)",
  184. IP_STR
  185. "Establish static routes\n"
  186. "IP destination prefix\n"
  187. "IP destination prefix mask\n"
  188. "Emit an ICMP unreachable when matched\n"
  189. "Silently discard pkts when matched\n")
  190. {
  191. return zebra_static_ipv4 (vty, 1, argv[0], argv[1], NULL, argv[2], NULL);
  192. }
  193. /* Distance option value. */
  194. DEFUN (ip_route_distance,
  195. ip_route_distance_cmd,
  196. "ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) <1-255>",
  197. IP_STR
  198. "Establish static routes\n"
  199. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  200. "IP gateway address\n"
  201. "IP gateway interface name\n"
  202. "Null interface\n"
  203. "Distance value for this route\n")
  204. {
  205. return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], NULL, argv[2]);
  206. }
  207. DEFUN (ip_route_flags_distance,
  208. ip_route_flags_distance_cmd,
  209. "ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
  210. IP_STR
  211. "Establish static routes\n"
  212. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  213. "IP gateway address\n"
  214. "IP gateway interface name\n"
  215. "Emit an ICMP unreachable when matched\n"
  216. "Silently discard pkts when matched\n"
  217. "Distance value for this route\n")
  218. {
  219. return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], argv[2], argv[3]);
  220. }
  221. DEFUN (ip_route_flags_distance2,
  222. ip_route_flags_distance2_cmd,
  223. "ip route A.B.C.D/M (reject|blackhole) <1-255>",
  224. IP_STR
  225. "Establish static routes\n"
  226. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  227. "Emit an ICMP unreachable when matched\n"
  228. "Silently discard pkts when matched\n"
  229. "Distance value for this route\n")
  230. {
  231. return zebra_static_ipv4 (vty, 1, argv[0], NULL, NULL, argv[1], argv[2]);
  232. }
  233. DEFUN (ip_route_mask_distance,
  234. ip_route_mask_distance_cmd,
  235. "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0) <1-255>",
  236. IP_STR
  237. "Establish static routes\n"
  238. "IP destination prefix\n"
  239. "IP destination prefix mask\n"
  240. "IP gateway address\n"
  241. "IP gateway interface name\n"
  242. "Null interface\n"
  243. "Distance value for this route\n")
  244. {
  245. return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], NULL, argv[3]);
  246. }
  247. DEFUN (ip_route_mask_flags_distance,
  248. ip_route_mask_flags_distance_cmd,
  249. "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
  250. IP_STR
  251. "Establish static routes\n"
  252. "IP destination prefix\n"
  253. "IP destination prefix mask\n"
  254. "IP gateway address\n"
  255. "IP gateway interface name\n"
  256. "Distance value for this route\n"
  257. "Emit an ICMP unreachable when matched\n"
  258. "Silently discard pkts when matched\n")
  259. {
  260. return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], argv[3], argv[4]);
  261. }
  262. DEFUN (ip_route_mask_flags_distance2,
  263. ip_route_mask_flags_distance2_cmd,
  264. "ip route A.B.C.D A.B.C.D (reject|blackhole) <1-255>",
  265. IP_STR
  266. "Establish static routes\n"
  267. "IP destination prefix\n"
  268. "IP destination prefix mask\n"
  269. "Distance value for this route\n"
  270. "Emit an ICMP unreachable when matched\n"
  271. "Silently discard pkts when matched\n")
  272. {
  273. return zebra_static_ipv4 (vty, 1, argv[0], argv[1], NULL, argv[2], argv[3]);
  274. }
  275. DEFUN (no_ip_route,
  276. no_ip_route_cmd,
  277. "no ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0)",
  278. NO_STR
  279. IP_STR
  280. "Establish static routes\n"
  281. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  282. "IP gateway address\n"
  283. "IP gateway interface name\n"
  284. "Null interface\n")
  285. {
  286. return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], NULL, NULL);
  287. }
  288. ALIAS (no_ip_route,
  289. no_ip_route_flags_cmd,
  290. "no ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole)",
  291. NO_STR
  292. IP_STR
  293. "Establish static routes\n"
  294. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  295. "IP gateway address\n"
  296. "IP gateway interface name\n"
  297. "Emit an ICMP unreachable when matched\n"
  298. "Silently discard pkts when matched\n")
  299. DEFUN (no_ip_route_flags2,
  300. no_ip_route_flags2_cmd,
  301. "no ip route A.B.C.D/M (reject|blackhole)",
  302. NO_STR
  303. IP_STR
  304. "Establish static routes\n"
  305. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  306. "Emit an ICMP unreachable when matched\n"
  307. "Silently discard pkts when matched\n")
  308. {
  309. return zebra_static_ipv4 (vty, 0, argv[0], NULL, NULL, NULL, NULL);
  310. }
  311. DEFUN (no_ip_route_mask,
  312. no_ip_route_mask_cmd,
  313. "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0)",
  314. NO_STR
  315. IP_STR
  316. "Establish static routes\n"
  317. "IP destination prefix\n"
  318. "IP destination prefix mask\n"
  319. "IP gateway address\n"
  320. "IP gateway interface name\n"
  321. "Null interface\n")
  322. {
  323. return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], NULL, NULL);
  324. }
  325. ALIAS (no_ip_route_mask,
  326. no_ip_route_mask_flags_cmd,
  327. "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole)",
  328. NO_STR
  329. IP_STR
  330. "Establish static routes\n"
  331. "IP destination prefix\n"
  332. "IP destination prefix mask\n"
  333. "IP gateway address\n"
  334. "IP gateway interface name\n"
  335. "Emit an ICMP unreachable when matched\n"
  336. "Silently discard pkts when matched\n")
  337. DEFUN (no_ip_route_mask_flags2,
  338. no_ip_route_mask_flags2_cmd,
  339. "no ip route A.B.C.D A.B.C.D (reject|blackhole)",
  340. NO_STR
  341. IP_STR
  342. "Establish static routes\n"
  343. "IP destination prefix\n"
  344. "IP destination prefix mask\n"
  345. "Emit an ICMP unreachable when matched\n"
  346. "Silently discard pkts when matched\n")
  347. {
  348. return zebra_static_ipv4 (vty, 0, argv[0], argv[1], NULL, NULL, NULL);
  349. }
  350. DEFUN (no_ip_route_distance,
  351. no_ip_route_distance_cmd,
  352. "no ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) <1-255>",
  353. NO_STR
  354. IP_STR
  355. "Establish static routes\n"
  356. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  357. "IP gateway address\n"
  358. "IP gateway interface name\n"
  359. "Null interface\n"
  360. "Distance value for this route\n")
  361. {
  362. return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], NULL, argv[2]);
  363. }
  364. DEFUN (no_ip_route_flags_distance,
  365. no_ip_route_flags_distance_cmd,
  366. "no ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
  367. NO_STR
  368. IP_STR
  369. "Establish static routes\n"
  370. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  371. "IP gateway address\n"
  372. "IP gateway interface name\n"
  373. "Emit an ICMP unreachable when matched\n"
  374. "Silently discard pkts when matched\n"
  375. "Distance value for this route\n")
  376. {
  377. return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], argv[2], argv[3]);
  378. }
  379. DEFUN (no_ip_route_flags_distance2,
  380. no_ip_route_flags_distance2_cmd,
  381. "no ip route A.B.C.D/M (reject|blackhole) <1-255>",
  382. NO_STR
  383. IP_STR
  384. "Establish static routes\n"
  385. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  386. "Emit an ICMP unreachable when matched\n"
  387. "Silently discard pkts when matched\n"
  388. "Distance value for this route\n")
  389. {
  390. return zebra_static_ipv4 (vty, 0, argv[0], NULL, NULL, argv[1], argv[2]);
  391. }
  392. DEFUN (no_ip_route_mask_distance,
  393. no_ip_route_mask_distance_cmd,
  394. "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0) <1-255>",
  395. NO_STR
  396. IP_STR
  397. "Establish static routes\n"
  398. "IP destination prefix\n"
  399. "IP destination prefix mask\n"
  400. "IP gateway address\n"
  401. "IP gateway interface name\n"
  402. "Null interface\n"
  403. "Distance value for this route\n")
  404. {
  405. return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], NULL, argv[3]);
  406. }
  407. DEFUN (no_ip_route_mask_flags_distance,
  408. no_ip_route_mask_flags_distance_cmd,
  409. "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
  410. NO_STR
  411. IP_STR
  412. "Establish static routes\n"
  413. "IP destination prefix\n"
  414. "IP destination prefix mask\n"
  415. "IP gateway address\n"
  416. "IP gateway interface name\n"
  417. "Emit an ICMP unreachable when matched\n"
  418. "Silently discard pkts when matched\n"
  419. "Distance value for this route\n")
  420. {
  421. return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], argv[3], argv[4]);
  422. }
  423. DEFUN (no_ip_route_mask_flags_distance2,
  424. no_ip_route_mask_flags_distance2_cmd,
  425. "no ip route A.B.C.D A.B.C.D (reject|blackhole) <1-255>",
  426. NO_STR
  427. IP_STR
  428. "Establish static routes\n"
  429. "IP destination prefix\n"
  430. "IP destination prefix mask\n"
  431. "Emit an ICMP unreachable when matched\n"
  432. "Silently discard pkts when matched\n"
  433. "Distance value for this route\n")
  434. {
  435. return zebra_static_ipv4 (vty, 0, argv[0], argv[1], NULL, argv[2], argv[3]);
  436. }
  437. /* New RIB. Detailed information for IPv4 route. */
  438. static void
  439. vty_show_ip_route_detail (struct vty *vty, struct route_node *rn)
  440. {
  441. struct rib *rib;
  442. struct nexthop *nexthop;
  443. for (rib = rn->info; rib; rib = rib->next)
  444. {
  445. vty_out (vty, "Routing entry for %s/%d%s",
  446. inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
  447. VTY_NEWLINE);
  448. vty_out (vty, " Known via \"%s\"", zebra_route_string (rib->type));
  449. vty_out (vty, ", distance %d, metric %d", rib->distance, rib->metric);
  450. if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
  451. vty_out (vty, ", best");
  452. if (rib->refcnt)
  453. vty_out (vty, ", refcnt %ld", rib->refcnt);
  454. if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
  455. vty_out (vty, ", blackhole");
  456. if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
  457. vty_out (vty, ", reject");
  458. vty_out (vty, "%s", VTY_NEWLINE);
  459. #define ONE_DAY_SECOND 60*60*24
  460. #define ONE_WEEK_SECOND 60*60*24*7
  461. if (rib->type == ZEBRA_ROUTE_RIP
  462. || rib->type == ZEBRA_ROUTE_OSPF
  463. || rib->type == ZEBRA_ROUTE_ISIS
  464. || rib->type == ZEBRA_ROUTE_BGP)
  465. {
  466. time_t uptime;
  467. struct tm *tm;
  468. uptime = time (NULL);
  469. uptime -= rib->uptime;
  470. tm = gmtime (&uptime);
  471. vty_out (vty, " Last update ");
  472. if (uptime < ONE_DAY_SECOND)
  473. vty_out (vty, "%02d:%02d:%02d",
  474. tm->tm_hour, tm->tm_min, tm->tm_sec);
  475. else if (uptime < ONE_WEEK_SECOND)
  476. vty_out (vty, "%dd%02dh%02dm",
  477. tm->tm_yday, tm->tm_hour, tm->tm_min);
  478. else
  479. vty_out (vty, "%02dw%dd%02dh",
  480. tm->tm_yday/7,
  481. tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
  482. vty_out (vty, " ago%s", VTY_NEWLINE);
  483. }
  484. for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
  485. {
  486. vty_out (vty, " %c",
  487. CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB) ? '*' : ' ');
  488. switch (nexthop->type)
  489. {
  490. case NEXTHOP_TYPE_IPV4:
  491. case NEXTHOP_TYPE_IPV4_IFINDEX:
  492. vty_out (vty, " %s", inet_ntoa (nexthop->gate.ipv4));
  493. if (nexthop->ifindex)
  494. vty_out (vty, ", via %s", ifindex2ifname (nexthop->ifindex));
  495. break;
  496. case NEXTHOP_TYPE_IFINDEX:
  497. vty_out (vty, " directly connected, %s",
  498. ifindex2ifname (nexthop->ifindex));
  499. break;
  500. case NEXTHOP_TYPE_IFNAME:
  501. vty_out (vty, " directly connected, %s", nexthop->ifname);
  502. break;
  503. case NEXTHOP_TYPE_BLACKHOLE:
  504. vty_out (vty, " directly connected, Null0");
  505. break;
  506. default:
  507. break;
  508. }
  509. if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
  510. vty_out (vty, " inactive");
  511. if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
  512. {
  513. vty_out (vty, " (recursive");
  514. switch (nexthop->rtype)
  515. {
  516. case NEXTHOP_TYPE_IPV4:
  517. case NEXTHOP_TYPE_IPV4_IFINDEX:
  518. vty_out (vty, " via %s)", inet_ntoa (nexthop->rgate.ipv4));
  519. break;
  520. case NEXTHOP_TYPE_IFINDEX:
  521. case NEXTHOP_TYPE_IFNAME:
  522. vty_out (vty, " is directly connected, %s)",
  523. ifindex2ifname (nexthop->rifindex));
  524. break;
  525. default:
  526. break;
  527. }
  528. }
  529. vty_out (vty, "%s", VTY_NEWLINE);
  530. }
  531. vty_out (vty, "%s", VTY_NEWLINE);
  532. }
  533. }
  534. static void
  535. vty_show_ip_route (struct vty *vty, struct route_node *rn, struct rib *rib)
  536. {
  537. struct nexthop *nexthop;
  538. int len = 0;
  539. char buf[BUFSIZ];
  540. /* Nexthop information. */
  541. for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
  542. {
  543. if (nexthop == rib->nexthop)
  544. {
  545. /* Prefix information. */
  546. len = vty_out (vty, "%c%c%c %s/%d",
  547. zebra_route_char (rib->type),
  548. CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED)
  549. ? '>' : ' ',
  550. CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
  551. ? '*' : ' ',
  552. inet_ntop (AF_INET, &rn->p.u.prefix, buf, BUFSIZ),
  553. rn->p.prefixlen);
  554. /* Distance and metric display. */
  555. if (rib->type != ZEBRA_ROUTE_CONNECT
  556. && rib->type != ZEBRA_ROUTE_KERNEL)
  557. len += vty_out (vty, " [%d/%d]", rib->distance,
  558. rib->metric);
  559. }
  560. else
  561. vty_out (vty, " %c%*c",
  562. CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
  563. ? '*' : ' ',
  564. len - 3, ' ');
  565. switch (nexthop->type)
  566. {
  567. case NEXTHOP_TYPE_IPV4:
  568. case NEXTHOP_TYPE_IPV4_IFINDEX:
  569. vty_out (vty, " via %s", inet_ntoa (nexthop->gate.ipv4));
  570. if (nexthop->ifindex)
  571. vty_out (vty, ", %s", ifindex2ifname (nexthop->ifindex));
  572. break;
  573. case NEXTHOP_TYPE_IFINDEX:
  574. vty_out (vty, " is directly connected, %s",
  575. ifindex2ifname (nexthop->ifindex));
  576. break;
  577. case NEXTHOP_TYPE_IFNAME:
  578. vty_out (vty, " is directly connected, %s", nexthop->ifname);
  579. break;
  580. case NEXTHOP_TYPE_BLACKHOLE:
  581. vty_out (vty, " is directly connected, Null0");
  582. break;
  583. default:
  584. break;
  585. }
  586. if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
  587. vty_out (vty, " inactive");
  588. if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
  589. {
  590. vty_out (vty, " (recursive");
  591. switch (nexthop->rtype)
  592. {
  593. case NEXTHOP_TYPE_IPV4:
  594. case NEXTHOP_TYPE_IPV4_IFINDEX:
  595. vty_out (vty, " via %s)", inet_ntoa (nexthop->rgate.ipv4));
  596. break;
  597. case NEXTHOP_TYPE_IFINDEX:
  598. case NEXTHOP_TYPE_IFNAME:
  599. vty_out (vty, " is directly connected, %s)",
  600. ifindex2ifname (nexthop->rifindex));
  601. break;
  602. default:
  603. break;
  604. }
  605. }
  606. if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
  607. vty_out (vty, ", bh");
  608. if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
  609. vty_out (vty, ", rej");
  610. if (rib->type == ZEBRA_ROUTE_RIP
  611. || rib->type == ZEBRA_ROUTE_OSPF
  612. || rib->type == ZEBRA_ROUTE_ISIS
  613. || rib->type == ZEBRA_ROUTE_BGP)
  614. {
  615. time_t uptime;
  616. struct tm *tm;
  617. uptime = time (NULL);
  618. uptime -= rib->uptime;
  619. tm = gmtime (&uptime);
  620. #define ONE_DAY_SECOND 60*60*24
  621. #define ONE_WEEK_SECOND 60*60*24*7
  622. if (uptime < ONE_DAY_SECOND)
  623. vty_out (vty, ", %02d:%02d:%02d",
  624. tm->tm_hour, tm->tm_min, tm->tm_sec);
  625. else if (uptime < ONE_WEEK_SECOND)
  626. vty_out (vty, ", %dd%02dh%02dm",
  627. tm->tm_yday, tm->tm_hour, tm->tm_min);
  628. else
  629. vty_out (vty, ", %02dw%dd%02dh",
  630. tm->tm_yday/7,
  631. tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
  632. }
  633. vty_out (vty, "%s", VTY_NEWLINE);
  634. }
  635. }
  636. #define SHOW_ROUTE_V4_HEADER "Codes: K - kernel route, C - connected, " \
  637. "S - static, R - RIP, O - OSPF,%s I - ISIS, B - BGP, " \
  638. "> - selected route, * - FIB route%s%s"
  639. DEFUN (show_ip_route,
  640. show_ip_route_cmd,
  641. "show ip route",
  642. SHOW_STR
  643. IP_STR
  644. "IP routing table\n")
  645. {
  646. struct route_table *table;
  647. struct route_node *rn;
  648. struct rib *rib;
  649. int first = 1;
  650. table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
  651. if (! table)
  652. return CMD_SUCCESS;
  653. /* Show all IPv4 routes. */
  654. for (rn = route_top (table); rn; rn = route_next (rn))
  655. for (rib = rn->info; rib; rib = rib->next)
  656. {
  657. if (first)
  658. {
  659. vty_out (vty, SHOW_ROUTE_V4_HEADER, VTY_NEWLINE, VTY_NEWLINE,
  660. VTY_NEWLINE);
  661. first = 0;
  662. }
  663. vty_show_ip_route (vty, rn, rib);
  664. }
  665. return CMD_SUCCESS;
  666. }
  667. DEFUN (show_ip_route_prefix_longer,
  668. show_ip_route_prefix_longer_cmd,
  669. "show ip route A.B.C.D/M longer-prefixes",
  670. SHOW_STR
  671. IP_STR
  672. "IP routing table\n"
  673. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  674. "Show route matching the specified Network/Mask pair only\n")
  675. {
  676. struct route_table *table;
  677. struct route_node *rn;
  678. struct rib *rib;
  679. struct prefix p;
  680. int ret;
  681. int first = 1;
  682. ret = str2prefix (argv[0], &p);
  683. if (! ret)
  684. {
  685. vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
  686. return CMD_WARNING;
  687. }
  688. table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
  689. if (! table)
  690. return CMD_SUCCESS;
  691. /* Show matched type IPv4 routes. */
  692. for (rn = route_top (table); rn; rn = route_next (rn))
  693. for (rib = rn->info; rib; rib = rib->next)
  694. if (prefix_match (&p, &rn->p))
  695. {
  696. if (first)
  697. {
  698. vty_out (vty, SHOW_ROUTE_V4_HEADER, VTY_NEWLINE,
  699. VTY_NEWLINE, VTY_NEWLINE);
  700. first = 0;
  701. }
  702. vty_show_ip_route (vty, rn, rib);
  703. }
  704. return CMD_SUCCESS;
  705. }
  706. DEFUN (show_ip_route_supernets,
  707. show_ip_route_supernets_cmd,
  708. "show ip route supernets-only",
  709. SHOW_STR
  710. IP_STR
  711. "IP routing table\n"
  712. "Show supernet entries only\n")
  713. {
  714. struct route_table *table;
  715. struct route_node *rn;
  716. struct rib *rib;
  717. u_int32_t addr;
  718. int first = 1;
  719. table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
  720. if (! table)
  721. return CMD_SUCCESS;
  722. /* Show matched type IPv4 routes. */
  723. for (rn = route_top (table); rn; rn = route_next (rn))
  724. for (rib = rn->info; rib; rib = rib->next)
  725. {
  726. addr = ntohl (rn->p.u.prefix4.s_addr);
  727. if ((IN_CLASSC (addr) && rn->p.prefixlen < 24)
  728. || (IN_CLASSB (addr) && rn->p.prefixlen < 16)
  729. || (IN_CLASSA (addr) && rn->p.prefixlen < 8))
  730. {
  731. if (first)
  732. {
  733. vty_out (vty, SHOW_ROUTE_V4_HEADER, VTY_NEWLINE,
  734. VTY_NEWLINE, VTY_NEWLINE);
  735. first = 0;
  736. }
  737. vty_show_ip_route (vty, rn, rib);
  738. }
  739. }
  740. return CMD_SUCCESS;
  741. }
  742. DEFUN (show_ip_route_protocol,
  743. show_ip_route_protocol_cmd,
  744. "show ip route (bgp|connected|isis|kernel|ospf|rip|static)",
  745. SHOW_STR
  746. IP_STR
  747. "IP routing table\n"
  748. "Border Gateway Protocol (BGP)\n"
  749. "Connected\n"
  750. "ISO IS-IS (ISIS)\n"
  751. "Kernel\n"
  752. "Open Shortest Path First (OSPF)\n"
  753. "Routing Information Protocol (RIP)\n"
  754. "Static routes\n")
  755. {
  756. int type;
  757. struct route_table *table;
  758. struct route_node *rn;
  759. struct rib *rib;
  760. int first = 1;
  761. if (strncmp (argv[0], "b", 1) == 0)
  762. type = ZEBRA_ROUTE_BGP;
  763. else if (strncmp (argv[0], "c", 1) == 0)
  764. type = ZEBRA_ROUTE_CONNECT;
  765. else if (strncmp (argv[0], "k", 1) ==0)
  766. type = ZEBRA_ROUTE_KERNEL;
  767. else if (strncmp (argv[0], "o", 1) == 0)
  768. type = ZEBRA_ROUTE_OSPF;
  769. else if (strncmp (argv[0], "i", 1) == 0)
  770. type = ZEBRA_ROUTE_ISIS;
  771. else if (strncmp (argv[0], "r", 1) == 0)
  772. type = ZEBRA_ROUTE_RIP;
  773. else if (strncmp (argv[0], "s", 1) == 0)
  774. type = ZEBRA_ROUTE_STATIC;
  775. else
  776. {
  777. vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
  778. return CMD_WARNING;
  779. }
  780. table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
  781. if (! table)
  782. return CMD_SUCCESS;
  783. /* Show matched type IPv4 routes. */
  784. for (rn = route_top (table); rn; rn = route_next (rn))
  785. for (rib = rn->info; rib; rib = rib->next)
  786. if (rib->type == type)
  787. {
  788. if (first)
  789. {
  790. vty_out (vty, SHOW_ROUTE_V4_HEADER,
  791. VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
  792. first = 0;
  793. }
  794. vty_show_ip_route (vty, rn, rib);
  795. }
  796. return CMD_SUCCESS;
  797. }
  798. DEFUN (show_ip_route_addr,
  799. show_ip_route_addr_cmd,
  800. "show ip route A.B.C.D",
  801. SHOW_STR
  802. IP_STR
  803. "IP routing table\n"
  804. "Network in the IP routing table to display\n")
  805. {
  806. int ret;
  807. struct prefix_ipv4 p;
  808. struct route_table *table;
  809. struct route_node *rn;
  810. ret = str2prefix_ipv4 (argv[0], &p);
  811. if (ret <= 0)
  812. {
  813. vty_out (vty, "%% Malformed IPv4 address%s", VTY_NEWLINE);
  814. return CMD_WARNING;
  815. }
  816. table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
  817. if (! table)
  818. return CMD_SUCCESS;
  819. rn = route_node_match (table, (struct prefix *) &p);
  820. if (! rn)
  821. {
  822. vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
  823. return CMD_WARNING;
  824. }
  825. vty_show_ip_route_detail (vty, rn);
  826. route_unlock_node (rn);
  827. return CMD_SUCCESS;
  828. }
  829. DEFUN (show_ip_route_prefix,
  830. show_ip_route_prefix_cmd,
  831. "show ip route A.B.C.D/M",
  832. SHOW_STR
  833. IP_STR
  834. "IP routing table\n"
  835. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
  836. {
  837. int ret;
  838. struct prefix_ipv4 p;
  839. struct route_table *table;
  840. struct route_node *rn;
  841. ret = str2prefix_ipv4 (argv[0], &p);
  842. if (ret <= 0)
  843. {
  844. vty_out (vty, "%% Malformed IPv4 address%s", VTY_NEWLINE);
  845. return CMD_WARNING;
  846. }
  847. table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
  848. if (! table)
  849. return CMD_SUCCESS;
  850. rn = route_node_match (table, (struct prefix *) &p);
  851. if (! rn || rn->p.prefixlen != p.prefixlen)
  852. {
  853. vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
  854. return CMD_WARNING;
  855. }
  856. vty_show_ip_route_detail (vty, rn);
  857. route_unlock_node (rn);
  858. return CMD_SUCCESS;
  859. }
  860. static void
  861. zebra_show_ip_route (struct vty *vty, struct vrf *vrf)
  862. {
  863. vty_out (vty, "IP routing table name is %s(%d)%s",
  864. vrf->name ? vrf->name : "", vrf->id, VTY_NEWLINE);
  865. vty_out (vty, "Route Source Networks%s", VTY_NEWLINE);
  866. vty_out (vty, "connected %d%s", 0, VTY_NEWLINE);
  867. vty_out (vty, "static %d%s", 0, VTY_NEWLINE);
  868. vty_out (vty, "rip %d%s", 0, VTY_NEWLINE);
  869. vty_out (vty, "bgp %d%s", 0, VTY_NEWLINE);
  870. vty_out (vty, " External: %d Internal: %d Local: %d%s",
  871. 0, 0, 0, VTY_NEWLINE);
  872. vty_out (vty, "ospf %d%s", 0, VTY_NEWLINE);
  873. vty_out (vty,
  874. " Intra-area: %d Inter-area: %d External-1: %d External-2: %d%s",
  875. 0, 0, 0, 0, VTY_NEWLINE);
  876. vty_out (vty, " NSSA External-1: %d NSSA External-2: %d%s",
  877. 0, 0, VTY_NEWLINE);
  878. vty_out (vty, "internal %d%s", 0, VTY_NEWLINE);
  879. vty_out (vty, "Total %d%s", 0, VTY_NEWLINE);
  880. }
  881. /* Show route summary. */
  882. DEFUN (show_ip_route_summary,
  883. show_ip_route_summary_cmd,
  884. "show ip route summary",
  885. SHOW_STR
  886. IP_STR
  887. "IP routing table\n"
  888. "Summary of all routes\n")
  889. {
  890. struct vrf *vrf;
  891. /* Default table id is zero. */
  892. vrf = vrf_lookup (0);
  893. if (! vrf)
  894. {
  895. vty_out (vty, "%% No Default-IP-Routing-Table%s", VTY_NEWLINE);
  896. return CMD_WARNING;
  897. }
  898. zebra_show_ip_route (vty, vrf);
  899. return CMD_SUCCESS;
  900. }
  901. /* Write IPv4 static route configuration. */
  902. static int
  903. static_config_ipv4 (struct vty *vty)
  904. {
  905. struct route_node *rn;
  906. struct static_ipv4 *si;
  907. struct route_table *stable;
  908. int write;
  909. write = 0;
  910. /* Lookup table. */
  911. stable = vrf_static_table (AFI_IP, SAFI_UNICAST, 0);
  912. if (! stable)
  913. return -1;
  914. for (rn = route_top (stable); rn; rn = route_next (rn))
  915. for (si = rn->info; si; si = si->next)
  916. {
  917. vty_out (vty, "ip route %s/%d", inet_ntoa (rn->p.u.prefix4),
  918. rn->p.prefixlen);
  919. switch (si->type)
  920. {
  921. case STATIC_IPV4_GATEWAY:
  922. vty_out (vty, " %s", inet_ntoa (si->gate.ipv4));
  923. break;
  924. case STATIC_IPV4_IFNAME:
  925. vty_out (vty, " %s", si->gate.ifname);
  926. break;
  927. case STATIC_IPV4_BLACKHOLE:
  928. vty_out (vty, " Null0");
  929. break;
  930. }
  931. /* flags are incompatible with STATIC_IPV4_BLACKHOLE */
  932. if (si->type != STATIC_IPV4_BLACKHOLE)
  933. {
  934. if (CHECK_FLAG(si->flags, ZEBRA_FLAG_REJECT))
  935. vty_out (vty, " %s", "reject");
  936. if (CHECK_FLAG(si->flags, ZEBRA_FLAG_BLACKHOLE))
  937. vty_out (vty, " %s", "blackhole");
  938. }
  939. if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT)
  940. vty_out (vty, " %d", si->distance);
  941. vty_out (vty, "%s", VTY_NEWLINE);
  942. write = 1;
  943. }
  944. return write;
  945. }
  946. #ifdef HAVE_IPV6
  947. /* General fucntion for IPv6 static route. */
  948. static int
  949. static_ipv6_func (struct vty *vty, int add_cmd, const char *dest_str,
  950. const char *gate_str, const char *ifname,
  951. const char *flag_str, const char *distance_str)
  952. {
  953. int ret;
  954. u_char distance;
  955. struct prefix p;
  956. struct in6_addr *gate = NULL;
  957. struct in6_addr gate_addr;
  958. u_char type = 0;
  959. int table = 0;
  960. u_char flag = 0;
  961. ret = str2prefix (dest_str, &p);
  962. if (ret <= 0)
  963. {
  964. vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
  965. return CMD_WARNING;
  966. }
  967. /* Apply mask for given prefix. */
  968. apply_mask (&p);
  969. /* Route flags */
  970. if (flag_str) {
  971. switch(flag_str[0]) {
  972. case 'r':
  973. case 'R': /* XXX */
  974. SET_FLAG (flag, ZEBRA_FLAG_REJECT);
  975. break;
  976. case 'b':
  977. case 'B': /* XXX */
  978. SET_FLAG (flag, ZEBRA_FLAG_BLACKHOLE);
  979. break;
  980. default:
  981. vty_out (vty, "%% Malformed flag %s %s", flag_str, VTY_NEWLINE);
  982. return CMD_WARNING;
  983. }
  984. }
  985. /* Administrative distance. */
  986. if (distance_str)
  987. distance = atoi (distance_str);
  988. else
  989. distance = ZEBRA_STATIC_DISTANCE_DEFAULT;
  990. /* When gateway is valid IPv6 addrees, then gate is treated as
  991. nexthop address other case gate is treated as interface name. */
  992. ret = inet_pton (AF_INET6, gate_str, &gate_addr);
  993. if (ifname)
  994. {
  995. /* When ifname is specified. It must be come with gateway
  996. address. */
  997. if (ret != 1)
  998. {
  999. vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
  1000. return CMD_WARNING;
  1001. }
  1002. type = STATIC_IPV6_GATEWAY_IFNAME;
  1003. gate = &gate_addr;
  1004. }
  1005. else
  1006. {
  1007. if (ret == 1)
  1008. {
  1009. type = STATIC_IPV6_GATEWAY;
  1010. gate = &gate_addr;
  1011. }
  1012. else
  1013. {
  1014. type = STATIC_IPV6_IFNAME;
  1015. ifname = gate_str;
  1016. }
  1017. }
  1018. if (add_cmd)
  1019. static_add_ipv6 (&p, type, gate, ifname, flag, distance, table);
  1020. else
  1021. static_delete_ipv6 (&p, type, gate, ifname, distance, table);
  1022. return CMD_SUCCESS;
  1023. }
  1024. DEFUN (ipv6_route,
  1025. ipv6_route_cmd,
  1026. "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)",
  1027. IP_STR
  1028. "Establish static routes\n"
  1029. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  1030. "IPv6 gateway address\n"
  1031. "IPv6 gateway interface name\n")
  1032. {
  1033. return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, NULL, NULL);
  1034. }
  1035. DEFUN (ipv6_route_flags,
  1036. ipv6_route_flags_cmd,
  1037. "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole)",
  1038. IP_STR
  1039. "Establish static routes\n"
  1040. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  1041. "IPv6 gateway address\n"
  1042. "IPv6 gateway interface name\n"
  1043. "Emit an ICMP unreachable when matched\n"
  1044. "Silently discard pkts when matched\n")
  1045. {
  1046. return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, argv[2], NULL);
  1047. }
  1048. DEFUN (ipv6_route_ifname,
  1049. ipv6_route_ifname_cmd,
  1050. "ipv6 route X:X::X:X/M X:X::X:X INTERFACE",
  1051. IP_STR
  1052. "Establish static routes\n"
  1053. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  1054. "IPv6 gateway address\n"
  1055. "IPv6 gateway interface name\n")
  1056. {
  1057. return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], NULL, NULL);
  1058. }
  1059. DEFUN (ipv6_route_ifname_flags,
  1060. ipv6_route_ifname_flags_cmd,
  1061. "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole)",
  1062. IP_STR
  1063. "Establish static routes\n"
  1064. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  1065. "IPv6 gateway address\n"
  1066. "IPv6 gateway interface name\n"
  1067. "Emit an ICMP unreachable when matched\n"
  1068. "Silently discard pkts when matched\n")
  1069. {
  1070. return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], argv[3], NULL);
  1071. }
  1072. DEFUN (ipv6_route_pref,
  1073. ipv6_route_pref_cmd,
  1074. "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
  1075. IP_STR
  1076. "Establish static routes\n"
  1077. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  1078. "IPv6 gateway address\n"
  1079. "IPv6 gateway interface name\n"
  1080. "Distance value for this prefix\n")
  1081. {
  1082. return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, NULL, argv[2]);
  1083. }
  1084. DEFUN (ipv6_route_flags_pref,
  1085. ipv6_route_flags_pref_cmd,
  1086. "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255>",
  1087. IP_STR
  1088. "Establish static routes\n"
  1089. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  1090. "IPv6 gateway address\n"
  1091. "IPv6 gateway interface name\n"
  1092. "Emit an ICMP unreachable when matched\n"
  1093. "Silently discard pkts when matched\n"
  1094. "Distance value for this prefix\n")
  1095. {
  1096. return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, argv[2], argv[3]);
  1097. }
  1098. DEFUN (ipv6_route_ifname_pref,
  1099. ipv6_route_ifname_pref_cmd,
  1100. "ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
  1101. IP_STR
  1102. "Establish static routes\n"
  1103. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  1104. "IPv6 gateway address\n"
  1105. "IPv6 gateway interface name\n"
  1106. "Distance value for this prefix\n")
  1107. {
  1108. return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], NULL, argv[3]);
  1109. }
  1110. DEFUN (ipv6_route_ifname_flags_pref,
  1111. ipv6_route_ifname_flags_pref_cmd,
  1112. "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255>",
  1113. IP_STR
  1114. "Establish static routes\n"
  1115. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  1116. "IPv6 gateway address\n"
  1117. "IPv6 gateway interface name\n"
  1118. "Emit an ICMP unreachable when matched\n"
  1119. "Silently discard pkts when matched\n"
  1120. "Distance value for this prefix\n")
  1121. {
  1122. return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], argv[3], argv[4]);
  1123. }
  1124. DEFUN (no_ipv6_route,
  1125. no_ipv6_route_cmd,
  1126. "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)",
  1127. NO_STR
  1128. IP_STR
  1129. "Establish static routes\n"
  1130. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  1131. "IPv6 gateway address\n"
  1132. "IPv6 gateway interface name\n")
  1133. {
  1134. return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, NULL, NULL);
  1135. }
  1136. ALIAS (no_ipv6_route,
  1137. no_ipv6_route_flags_cmd,
  1138. "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole)",
  1139. NO_STR
  1140. IP_STR
  1141. "Establish static routes\n"
  1142. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  1143. "IPv6 gateway address\n"
  1144. "IPv6 gateway interface name\n"
  1145. "Emit an ICMP unreachable when matched\n"
  1146. "Silently discard pkts when matched\n")
  1147. DEFUN (no_ipv6_route_ifname,
  1148. no_ipv6_route_ifname_cmd,
  1149. "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE",
  1150. NO_STR
  1151. IP_STR
  1152. "Establish static routes\n"
  1153. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  1154. "IPv6 gateway address\n"
  1155. "IPv6 gateway interface name\n")
  1156. {
  1157. return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], NULL, NULL);
  1158. }
  1159. ALIAS (no_ipv6_route_ifname,
  1160. no_ipv6_route_ifname_flags_cmd,
  1161. "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole)",
  1162. NO_STR
  1163. IP_STR
  1164. "Establish static routes\n"
  1165. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  1166. "IPv6 gateway address\n"
  1167. "IPv6 gateway interface name\n"
  1168. "Emit an ICMP unreachable when matched\n"
  1169. "Silently discard pkts when matched\n")
  1170. DEFUN (no_ipv6_route_pref,
  1171. no_ipv6_route_pref_cmd,
  1172. "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
  1173. NO_STR
  1174. IP_STR
  1175. "Establish static routes\n"
  1176. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  1177. "IPv6 gateway address\n"
  1178. "IPv6 gateway interface name\n"
  1179. "Distance value for this prefix\n")
  1180. {
  1181. return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, NULL, argv[2]);
  1182. }
  1183. DEFUN (no_ipv6_route_flags_pref,
  1184. no_ipv6_route_flags_pref_cmd,
  1185. "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255>",
  1186. NO_STR
  1187. IP_STR
  1188. "Establish static routes\n"
  1189. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  1190. "IPv6 gateway address\n"
  1191. "IPv6 gateway interface name\n"
  1192. "Emit an ICMP unreachable when matched\n"
  1193. "Silently discard pkts when matched\n"
  1194. "Distance value for this prefix\n")
  1195. {
  1196. /* We do not care about argv[2] */
  1197. return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, argv[2], argv[3]);
  1198. }
  1199. DEFUN (no_ipv6_route_ifname_pref,
  1200. no_ipv6_route_ifname_pref_cmd,
  1201. "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
  1202. NO_STR
  1203. IP_STR
  1204. "Establish static routes\n"
  1205. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  1206. "IPv6 gateway address\n"
  1207. "IPv6 gateway interface name\n"
  1208. "Distance value for this prefix\n")
  1209. {
  1210. return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], NULL, argv[3]);
  1211. }
  1212. DEFUN (no_ipv6_route_ifname_flags_pref,
  1213. no_ipv6_route_ifname_flags_pref_cmd,
  1214. "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255>",
  1215. NO_STR
  1216. IP_STR
  1217. "Establish static routes\n"
  1218. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  1219. "IPv6 gateway address\n"
  1220. "IPv6 gateway interface name\n"
  1221. "Emit an ICMP unreachable when matched\n"
  1222. "Silently discard pkts when matched\n"
  1223. "Distance value for this prefix\n")
  1224. {
  1225. return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], argv[3], argv[4]);
  1226. }
  1227. /* New RIB. Detailed information for IPv6 route. */
  1228. static void
  1229. vty_show_ipv6_route_detail (struct vty *vty, struct route_node *rn)
  1230. {
  1231. struct rib *rib;
  1232. struct nexthop *nexthop;
  1233. char buf[BUFSIZ];
  1234. for (rib = rn->info; rib; rib = rib->next)
  1235. {
  1236. vty_out (vty, "Routing entry for %s/%d%s",
  1237. inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, BUFSIZ),
  1238. rn->p.prefixlen,
  1239. VTY_NEWLINE);
  1240. vty_out (vty, " Known via \"%s\"", zebra_route_string (rib->type));
  1241. vty_out (vty, ", distance %d, metric %d", rib->distance, rib->metric);
  1242. if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
  1243. vty_out (vty, ", best");
  1244. if (rib->refcnt)
  1245. vty_out (vty, ", refcnt %ld", rib->refcnt);
  1246. if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
  1247. vty_out (vty, ", blackhole");
  1248. if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
  1249. vty_out (vty, ", reject");
  1250. vty_out (vty, "%s", VTY_NEWLINE);
  1251. #define ONE_DAY_SECOND 60*60*24
  1252. #define ONE_WEEK_SECOND 60*60*24*7
  1253. if (rib->type == ZEBRA_ROUTE_RIPNG
  1254. || rib->type == ZEBRA_ROUTE_OSPF6
  1255. || rib->type == ZEBRA_ROUTE_ISIS
  1256. || rib->type == ZEBRA_ROUTE_BGP)
  1257. {
  1258. time_t uptime;
  1259. struct tm *tm;
  1260. uptime = time (NULL);
  1261. uptime -= rib->uptime;
  1262. tm = gmtime (&uptime);
  1263. vty_out (vty, " Last update ");
  1264. if (uptime < ONE_DAY_SECOND)
  1265. vty_out (vty, "%02d:%02d:%02d",
  1266. tm->tm_hour, tm->tm_min, tm->tm_sec);
  1267. else if (uptime < ONE_WEEK_SECOND)
  1268. vty_out (vty, "%dd%02dh%02dm",
  1269. tm->tm_yday, tm->tm_hour, tm->tm_min);
  1270. else
  1271. vty_out (vty, "%02dw%dd%02dh",
  1272. tm->tm_yday/7,
  1273. tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
  1274. vty_out (vty, " ago%s", VTY_NEWLINE);
  1275. }
  1276. for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
  1277. {
  1278. vty_out (vty, " %c",
  1279. CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB) ? '*' : ' ');
  1280. switch (nexthop->type)
  1281. {
  1282. case NEXTHOP_TYPE_IPV6:
  1283. case NEXTHOP_TYPE_IPV6_IFINDEX:
  1284. case NEXTHOP_TYPE_IPV6_IFNAME:
  1285. vty_out (vty, " %s",
  1286. inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, BUFSIZ));
  1287. if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME)
  1288. vty_out (vty, ", %s", nexthop->ifname);
  1289. else if (nexthop->ifindex)
  1290. vty_out (vty, ", via %s", ifindex2ifname (nexthop->ifindex));
  1291. break;
  1292. case NEXTHOP_TYPE_IFINDEX:
  1293. vty_out (vty, " directly connected, %s",
  1294. ifindex2ifname (nexthop->ifindex));
  1295. break;
  1296. case NEXTHOP_TYPE_IFNAME:
  1297. vty_out (vty, " directly connected, %s",
  1298. nexthop->ifname);
  1299. break;
  1300. default:
  1301. break;
  1302. }
  1303. if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
  1304. vty_out (vty, " inactive");
  1305. if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
  1306. {
  1307. vty_out (vty, " (recursive");
  1308. switch (nexthop->rtype)
  1309. {
  1310. case NEXTHOP_TYPE_IPV6:
  1311. case NEXTHOP_TYPE_IPV6_IFINDEX:
  1312. case NEXTHOP_TYPE_IPV6_IFNAME:
  1313. vty_out (vty, " via %s)",
  1314. inet_ntop (AF_INET6, &nexthop->rgate.ipv6,
  1315. buf, BUFSIZ));
  1316. if (nexthop->rifindex)
  1317. vty_out (vty, ", %s", ifindex2ifname (nexthop->rifindex));
  1318. break;
  1319. case NEXTHOP_TYPE_IFINDEX:
  1320. case NEXTHOP_TYPE_IFNAME:
  1321. vty_out (vty, " is directly connected, %s)",
  1322. ifindex2ifname (nexthop->rifindex));
  1323. break;
  1324. default:
  1325. break;
  1326. }
  1327. }
  1328. vty_out (vty, "%s", VTY_NEWLINE);
  1329. }
  1330. vty_out (vty, "%s", VTY_NEWLINE);
  1331. }
  1332. }
  1333. static void
  1334. vty_show_ipv6_route (struct vty *vty, struct route_node *rn,
  1335. struct rib *rib)
  1336. {
  1337. struct nexthop *nexthop;
  1338. int len = 0;
  1339. char buf[BUFSIZ];
  1340. /* Nexthop information. */
  1341. for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
  1342. {
  1343. if (nexthop == rib->nexthop)
  1344. {
  1345. /* Prefix information. */
  1346. len = vty_out (vty, "%c%c%c %s/%d",
  1347. zebra_route_char (rib->type),
  1348. CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED)
  1349. ? '>' : ' ',
  1350. CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
  1351. ? '*' : ' ',
  1352. inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, BUFSIZ),
  1353. rn->p.prefixlen);
  1354. /* Distance and metric display. */
  1355. if (rib->type != ZEBRA_ROUTE_CONNECT
  1356. && rib->type != ZEBRA_ROUTE_KERNEL)
  1357. len += vty_out (vty, " [%d/%d]", rib->distance,
  1358. rib->metric);
  1359. }
  1360. else
  1361. vty_out (vty, " %c%*c",
  1362. CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
  1363. ? '*' : ' ',
  1364. len - 3, ' ');
  1365. switch (nexthop->type)
  1366. {
  1367. case NEXTHOP_TYPE_IPV6:
  1368. case NEXTHOP_TYPE_IPV6_IFINDEX:
  1369. case NEXTHOP_TYPE_IPV6_IFNAME:
  1370. vty_out (vty, " via %s",
  1371. inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, BUFSIZ));
  1372. if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME)
  1373. vty_out (vty, ", %s", nexthop->ifname);
  1374. else if (nexthop->ifindex)
  1375. vty_out (vty, ", %s", ifindex2ifname (nexthop->ifindex));
  1376. break;
  1377. case NEXTHOP_TYPE_IFINDEX:
  1378. vty_out (vty, " is directly connected, %s",
  1379. ifindex2ifname (nexthop->ifindex));
  1380. break;
  1381. case NEXTHOP_TYPE_IFNAME:
  1382. vty_out (vty, " is directly connected, %s",
  1383. nexthop->ifname);
  1384. break;
  1385. default:
  1386. break;
  1387. }
  1388. if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
  1389. vty_out (vty, " inactive");
  1390. if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
  1391. {
  1392. vty_out (vty, " (recursive");
  1393. switch (nexthop->rtype)
  1394. {
  1395. case NEXTHOP_TYPE_IPV6:
  1396. case NEXTHOP_TYPE_IPV6_IFINDEX:
  1397. case NEXTHOP_TYPE_IPV6_IFNAME:
  1398. vty_out (vty, " via %s)",
  1399. inet_ntop (AF_INET6, &nexthop->rgate.ipv6,
  1400. buf, BUFSIZ));
  1401. if (nexthop->rifindex)
  1402. vty_out (vty, ", %s", ifindex2ifname (nexthop->rifindex));
  1403. break;
  1404. case NEXTHOP_TYPE_IFINDEX:
  1405. case NEXTHOP_TYPE_IFNAME:
  1406. vty_out (vty, " is directly connected, %s)",
  1407. ifindex2ifname (nexthop->rifindex));
  1408. break;
  1409. default:
  1410. break;
  1411. }
  1412. }
  1413. if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
  1414. vty_out (vty, ", bh");
  1415. if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
  1416. vty_out (vty, ", rej");
  1417. if (rib->type == ZEBRA_ROUTE_RIPNG
  1418. || rib->type == ZEBRA_ROUTE_OSPF6
  1419. || rib->type == ZEBRA_ROUTE_ISIS
  1420. || rib->type == ZEBRA_ROUTE_BGP)
  1421. {
  1422. time_t uptime;
  1423. struct tm *tm;
  1424. uptime = time (NULL);
  1425. uptime -= rib->uptime;
  1426. tm = gmtime (&uptime);
  1427. #define ONE_DAY_SECOND 60*60*24
  1428. #define ONE_WEEK_SECOND 60*60*24*7
  1429. if (uptime < ONE_DAY_SECOND)
  1430. vty_out (vty, ", %02d:%02d:%02d",
  1431. tm->tm_hour, tm->tm_min, tm->tm_sec);
  1432. else if (uptime < ONE_WEEK_SECOND)
  1433. vty_out (vty, ", %dd%02dh%02dm",
  1434. tm->tm_yday, tm->tm_hour, tm->tm_min);
  1435. else
  1436. vty_out (vty, ", %02dw%dd%02dh",
  1437. tm->tm_yday/7,
  1438. tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
  1439. }
  1440. vty_out (vty, "%s", VTY_NEWLINE);
  1441. }
  1442. }
  1443. #define SHOW_ROUTE_V6_HEADER "Codes: K - kernel route, C - connected, S - static, R - RIPng, O - OSPFv3,%s I - ISIS, B - BGP, * - FIB route.%s%s"
  1444. DEFUN (show_ipv6_route,
  1445. show_ipv6_route_cmd,
  1446. "show ipv6 route",
  1447. SHOW_STR
  1448. IP_STR
  1449. "IPv6 routing table\n")
  1450. {
  1451. struct route_table *table;
  1452. struct route_node *rn;
  1453. struct rib *rib;
  1454. int first = 1;
  1455. table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
  1456. if (! table)
  1457. return CMD_SUCCESS;
  1458. /* Show all IPv6 route. */
  1459. for (rn = route_top (table); rn; rn = route_next (rn))
  1460. for (rib = rn->info; rib; rib = rib->next)
  1461. {
  1462. if (first)
  1463. {
  1464. vty_out (vty, SHOW_ROUTE_V6_HEADER, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
  1465. first = 0;
  1466. }
  1467. vty_show_ipv6_route (vty, rn, rib);
  1468. }
  1469. return CMD_SUCCESS;
  1470. }
  1471. DEFUN (show_ipv6_route_prefix_longer,
  1472. show_ipv6_route_prefix_longer_cmd,
  1473. "show ipv6 route X:X::X:X/M longer-prefixes",
  1474. SHOW_STR
  1475. IP_STR
  1476. "IPv6 routing table\n"
  1477. "IPv6 prefix\n"
  1478. "Show route matching the specified Network/Mask pair only\n")
  1479. {
  1480. struct route_table *table;
  1481. struct route_node *rn;
  1482. struct rib *rib;
  1483. struct prefix p;
  1484. int ret;
  1485. int first = 1;
  1486. table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
  1487. if (! table)
  1488. return CMD_SUCCESS;
  1489. ret = str2prefix (argv[0], &p);
  1490. if (! ret)
  1491. {
  1492. vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
  1493. return CMD_WARNING;
  1494. }
  1495. /* Show matched type IPv6 routes. */
  1496. for (rn = route_top (table); rn; rn = route_next (rn))
  1497. for (rib = rn->info; rib; rib = rib->next)
  1498. if (prefix_match (&p, &rn->p))
  1499. {
  1500. if (first)
  1501. {
  1502. vty_out (vty, SHOW_ROUTE_V6_HEADER, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
  1503. first = 0;
  1504. }
  1505. vty_show_ipv6_route (vty, rn, rib);
  1506. }
  1507. return CMD_SUCCESS;
  1508. }
  1509. DEFUN (show_ipv6_route_protocol,
  1510. show_ipv6_route_protocol_cmd,
  1511. "show ipv6 route (bgp|connected|isis|kernel|ospf6|ripng|static)",
  1512. SHOW_STR
  1513. IP_STR
  1514. "IP routing table\n"
  1515. "Border Gateway Protocol (BGP)\n"
  1516. "Connected\n"
  1517. "ISO IS-IS (ISIS)\n"
  1518. "Kernel\n"
  1519. "Open Shortest Path First (OSPFv3)\n"
  1520. "Routing Information Protocol (RIPng)\n"
  1521. "Static routes\n")
  1522. {
  1523. int type;
  1524. struct route_table *table;
  1525. struct route_node *rn;
  1526. struct rib *rib;
  1527. int first = 1;
  1528. if (strncmp (argv[0], "b", 1) == 0)
  1529. type = ZEBRA_ROUTE_BGP;
  1530. else if (strncmp (argv[0], "c", 1) == 0)
  1531. type = ZEBRA_ROUTE_CONNECT;
  1532. else if (strncmp (argv[0], "k", 1) ==0)
  1533. type = ZEBRA_ROUTE_KERNEL;
  1534. else if (strncmp (argv[0], "o", 1) == 0)
  1535. type = ZEBRA_ROUTE_OSPF6;
  1536. else if (strncmp (argv[0], "i", 1) == 0)
  1537. type = ZEBRA_ROUTE_ISIS;
  1538. else if (strncmp (argv[0], "r", 1) == 0)
  1539. type = ZEBRA_ROUTE_RIPNG;
  1540. else if (strncmp (argv[0], "s", 1) == 0)
  1541. type = ZEBRA_ROUTE_STATIC;
  1542. else
  1543. {
  1544. vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
  1545. return CMD_WARNING;
  1546. }
  1547. table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
  1548. if (! table)
  1549. return CMD_SUCCESS;
  1550. /* Show matched type IPv6 routes. */
  1551. for (rn = route_top (table); rn; rn = route_next (rn))
  1552. for (rib = rn->info; rib; rib = rib->next)
  1553. if (rib->type == type)
  1554. {
  1555. if (first)
  1556. {
  1557. vty_out (vty, SHOW_ROUTE_V6_HEADER, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
  1558. first = 0;
  1559. }
  1560. vty_show_ipv6_route (vty, rn, rib);
  1561. }
  1562. return CMD_SUCCESS;
  1563. }
  1564. DEFUN (show_ipv6_route_addr,
  1565. show_ipv6_route_addr_cmd,
  1566. "show ipv6 route X:X::X:X",
  1567. SHOW_STR
  1568. IP_STR
  1569. "IPv6 routing table\n"
  1570. "IPv6 Address\n")
  1571. {
  1572. int ret;
  1573. struct prefix_ipv6 p;
  1574. struct route_table *table;
  1575. struct route_node *rn;
  1576. ret = str2prefix_ipv6 (argv[0], &p);
  1577. if (ret <= 0)
  1578. {
  1579. vty_out (vty, "Malformed IPv6 address%s", VTY_NEWLINE);
  1580. return CMD_WARNING;
  1581. }
  1582. table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
  1583. if (! table)
  1584. return CMD_SUCCESS;
  1585. rn = route_node_match (table, (struct prefix *) &p);
  1586. if (! rn)
  1587. {
  1588. vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
  1589. return CMD_WARNING;
  1590. }
  1591. vty_show_ipv6_route_detail (vty, rn);
  1592. route_unlock_node (rn);
  1593. return CMD_SUCCESS;
  1594. }
  1595. DEFUN (show_ipv6_route_prefix,
  1596. show_ipv6_route_prefix_cmd,
  1597. "show ipv6 route X:X::X:X/M",
  1598. SHOW_STR
  1599. IP_STR
  1600. "IPv6 routing table\n"
  1601. "IPv6 prefix\n")
  1602. {
  1603. int ret;
  1604. struct prefix_ipv6 p;
  1605. struct route_table *table;
  1606. struct route_node *rn;
  1607. ret = str2prefix_ipv6 (argv[0], &p);
  1608. if (ret <= 0)
  1609. {
  1610. vty_out (vty, "Malformed IPv6 prefix%s", VTY_NEWLINE);
  1611. return CMD_WARNING;
  1612. }
  1613. table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
  1614. if (! table)
  1615. return CMD_SUCCESS;
  1616. rn = route_node_match (table, (struct prefix *) &p);
  1617. if (! rn || rn->p.prefixlen != p.prefixlen)
  1618. {
  1619. vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
  1620. return CMD_WARNING;
  1621. }
  1622. vty_show_ipv6_route_detail (vty, rn);
  1623. route_unlock_node (rn);
  1624. return CMD_SUCCESS;
  1625. }
  1626. /* Write IPv6 static route configuration. */
  1627. static int
  1628. static_config_ipv6 (struct vty *vty)
  1629. {
  1630. struct route_node *rn;
  1631. struct static_ipv6 *si;
  1632. int write;
  1633. char buf[BUFSIZ];
  1634. struct route_table *stable;
  1635. write = 0;
  1636. /* Lookup table. */
  1637. stable = vrf_static_table (AFI_IP6, SAFI_UNICAST, 0);
  1638. if (! stable)
  1639. return -1;
  1640. for (rn = route_top (stable); rn; rn = route_next (rn))
  1641. for (si = rn->info; si; si = si->next)
  1642. {
  1643. vty_out (vty, "ipv6 route %s/%d",
  1644. inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, BUFSIZ),
  1645. rn->p.prefixlen);
  1646. switch (si->type)
  1647. {
  1648. case STATIC_IPV6_GATEWAY:
  1649. vty_out (vty, " %s", inet_ntop (AF_INET6, &si->ipv6, buf, BUFSIZ));
  1650. break;
  1651. case STATIC_IPV6_IFNAME:
  1652. vty_out (vty, " %s", si->ifname);
  1653. break;
  1654. case STATIC_IPV6_GATEWAY_IFNAME:
  1655. vty_out (vty, " %s %s",
  1656. inet_ntop (AF_INET6, &si->ipv6, buf, BUFSIZ), si->ifname);
  1657. break;
  1658. }
  1659. if (CHECK_FLAG(si->flags, ZEBRA_FLAG_REJECT))
  1660. vty_out (vty, " %s", "reject");
  1661. if (CHECK_FLAG(si->flags, ZEBRA_FLAG_BLACKHOLE))
  1662. vty_out (vty, " %s", "blackhole");
  1663. if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT)
  1664. vty_out (vty, " %d", si->distance);
  1665. vty_out (vty, "%s", VTY_NEWLINE);
  1666. write = 1;
  1667. }
  1668. return write;
  1669. }
  1670. #endif /* HAVE_IPV6 */
  1671. /* Static ip route configuration write function. */
  1672. static int
  1673. zebra_ip_config (struct vty *vty)
  1674. {
  1675. int write = 0;
  1676. write += static_config_ipv4 (vty);
  1677. #ifdef HAVE_IPV6
  1678. write += static_config_ipv6 (vty);
  1679. #endif /* HAVE_IPV6 */
  1680. return write;
  1681. }
  1682. /* IP node for static routes. */
  1683. struct cmd_node ip_node = { IP_NODE, "", 1 };
  1684. /* Route VTY. */
  1685. void
  1686. zebra_vty_init (void)
  1687. {
  1688. install_node (&ip_node, zebra_ip_config);
  1689. install_element (CONFIG_NODE, &ip_route_cmd);
  1690. install_element (CONFIG_NODE, &ip_route_flags_cmd);
  1691. install_element (CONFIG_NODE, &ip_route_flags2_cmd);
  1692. install_element (CONFIG_NODE, &ip_route_mask_cmd);
  1693. install_element (CONFIG_NODE, &ip_route_mask_flags_cmd);
  1694. install_element (CONFIG_NODE, &ip_route_mask_flags2_cmd);
  1695. install_element (CONFIG_NODE, &no_ip_route_cmd);
  1696. install_element (CONFIG_NODE, &no_ip_route_flags_cmd);
  1697. install_element (CONFIG_NODE, &no_ip_route_flags2_cmd);
  1698. install_element (CONFIG_NODE, &no_ip_route_mask_cmd);
  1699. install_element (CONFIG_NODE, &no_ip_route_mask_flags_cmd);
  1700. install_element (CONFIG_NODE, &no_ip_route_mask_flags2_cmd);
  1701. install_element (CONFIG_NODE, &ip_route_distance_cmd);
  1702. install_element (CONFIG_NODE, &ip_route_flags_distance_cmd);
  1703. install_element (CONFIG_NODE, &ip_route_flags_distance2_cmd);
  1704. install_element (CONFIG_NODE, &ip_route_mask_distance_cmd);
  1705. install_element (CONFIG_NODE, &ip_route_mask_flags_distance_cmd);
  1706. install_element (CONFIG_NODE, &ip_route_mask_flags_distance2_cmd);
  1707. install_element (CONFIG_NODE, &no_ip_route_distance_cmd);
  1708. install_element (CONFIG_NODE, &no_ip_route_flags_distance_cmd);
  1709. install_element (CONFIG_NODE, &no_ip_route_flags_distance2_cmd);
  1710. install_element (CONFIG_NODE, &no_ip_route_mask_flags_distance_cmd);
  1711. install_element (CONFIG_NODE, &no_ip_route_mask_flags_distance2_cmd);
  1712. install_element (VIEW_NODE, &show_ip_route_cmd);
  1713. install_element (VIEW_NODE, &show_ip_route_addr_cmd);
  1714. install_element (VIEW_NODE, &show_ip_route_prefix_cmd);
  1715. install_element (VIEW_NODE, &show_ip_route_prefix_longer_cmd);
  1716. install_element (VIEW_NODE, &show_ip_route_protocol_cmd);
  1717. install_element (VIEW_NODE, &show_ip_route_supernets_cmd);
  1718. install_element (ENABLE_NODE, &show_ip_route_cmd);
  1719. install_element (ENABLE_NODE, &show_ip_route_addr_cmd);
  1720. install_element (ENABLE_NODE, &show_ip_route_prefix_cmd);
  1721. install_element (ENABLE_NODE, &show_ip_route_prefix_longer_cmd);
  1722. install_element (ENABLE_NODE, &show_ip_route_protocol_cmd);
  1723. install_element (ENABLE_NODE, &show_ip_route_supernets_cmd);
  1724. #if 0
  1725. install_element (VIEW_NODE, &show_ip_route_summary_cmd);
  1726. install_element (ENABLE_NODE, &show_ip_route_summary_cmd);
  1727. #endif /* 0 */
  1728. #ifdef HAVE_IPV6
  1729. install_element (CONFIG_NODE, &ipv6_route_cmd);
  1730. install_element (CONFIG_NODE, &ipv6_route_flags_cmd);
  1731. install_element (CONFIG_NODE, &ipv6_route_ifname_cmd);
  1732. install_element (CONFIG_NODE, &ipv6_route_ifname_flags_cmd);
  1733. install_element (CONFIG_NODE, &no_ipv6_route_cmd);
  1734. install_element (CONFIG_NODE, &no_ipv6_route_flags_cmd);
  1735. install_element (CONFIG_NODE, &no_ipv6_route_ifname_cmd);
  1736. install_element (CONFIG_NODE, &no_ipv6_route_ifname_flags_cmd);
  1737. install_element (CONFIG_NODE, &ipv6_route_pref_cmd);
  1738. install_element (CONFIG_NODE, &ipv6_route_flags_pref_cmd);
  1739. install_element (CONFIG_NODE, &ipv6_route_ifname_pref_cmd);
  1740. install_element (CONFIG_NODE, &ipv6_route_ifname_flags_pref_cmd);
  1741. install_element (CONFIG_NODE, &no_ipv6_route_pref_cmd);
  1742. install_element (CONFIG_NODE, &no_ipv6_route_flags_pref_cmd);
  1743. install_element (CONFIG_NODE, &no_ipv6_route_ifname_pref_cmd);
  1744. install_element (CONFIG_NODE, &no_ipv6_route_ifname_flags_pref_cmd);
  1745. install_element (VIEW_NODE, &show_ipv6_route_cmd);
  1746. install_element (VIEW_NODE, &show_ipv6_route_protocol_cmd);
  1747. install_element (VIEW_NODE, &show_ipv6_route_addr_cmd);
  1748. install_element (VIEW_NODE, &show_ipv6_route_prefix_cmd);
  1749. install_element (VIEW_NODE, &show_ipv6_route_prefix_longer_cmd);
  1750. install_element (ENABLE_NODE, &show_ipv6_route_cmd);
  1751. install_element (ENABLE_NODE, &show_ipv6_route_protocol_cmd);
  1752. install_element (ENABLE_NODE, &show_ipv6_route_addr_cmd);
  1753. install_element (ENABLE_NODE, &show_ipv6_route_prefix_cmd);
  1754. install_element (ENABLE_NODE, &show_ipv6_route_prefix_longer_cmd);
  1755. #endif /* HAVE_IPV6 */
  1756. }