zebra_vty.c 59 KB

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