zebra_vty.c 123 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153
  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 "vrf.h"
  29. #include "zebra/zserv.h"
  30. static int do_show_ip_route(struct vty *vty, safi_t safi, vrf_id_t vrf_id);
  31. static void vty_show_ip_route_detail (struct vty *vty, struct route_node *rn,
  32. int mcast);
  33. static void vty_show_ip_route (struct vty *vty, struct route_node *rn,
  34. struct rib *rib);
  35. /* General function for static route. */
  36. static int
  37. zebra_static_ipv4_safi (struct vty *vty, safi_t safi, int add_cmd,
  38. const char *dest_str, const char *mask_str,
  39. const char *gate_str, const char *flag_str,
  40. const char *distance_str, const char *vrf_id_str)
  41. {
  42. int ret;
  43. u_char distance;
  44. struct prefix p;
  45. struct in_addr gate;
  46. struct in_addr mask;
  47. const char *ifname;
  48. u_char flag = 0;
  49. vrf_id_t vrf_id = VRF_DEFAULT;
  50. ret = str2prefix (dest_str, &p);
  51. if (ret <= 0)
  52. {
  53. vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
  54. return CMD_WARNING;
  55. }
  56. /* Cisco like mask notation. */
  57. if (mask_str)
  58. {
  59. ret = inet_aton (mask_str, &mask);
  60. if (ret == 0)
  61. {
  62. vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
  63. return CMD_WARNING;
  64. }
  65. p.prefixlen = ip_masklen (mask);
  66. }
  67. /* Apply mask for given prefix. */
  68. apply_mask (&p);
  69. /* Administrative distance. */
  70. if (distance_str)
  71. distance = atoi (distance_str);
  72. else
  73. distance = ZEBRA_STATIC_DISTANCE_DEFAULT;
  74. /* VRF id */
  75. if (vrf_id_str)
  76. VTY_GET_INTEGER ("VRF ID", vrf_id, vrf_id_str);
  77. /* Null0 static route. */
  78. if ((gate_str != NULL) && (strncasecmp (gate_str, "Null0", strlen (gate_str)) == 0))
  79. {
  80. if (flag_str)
  81. {
  82. vty_out (vty, "%% can not have flag %s with Null0%s", flag_str, VTY_NEWLINE);
  83. return CMD_WARNING;
  84. }
  85. if (add_cmd)
  86. static_add_ipv4_safi (safi, &p, NULL, NULL, ZEBRA_FLAG_BLACKHOLE, distance, vrf_id);
  87. else
  88. static_delete_ipv4_safi (safi, &p, NULL, NULL, distance, vrf_id);
  89. return CMD_SUCCESS;
  90. }
  91. /* Route flags */
  92. if (flag_str) {
  93. switch(flag_str[0]) {
  94. case 'r':
  95. case 'R': /* XXX */
  96. SET_FLAG (flag, ZEBRA_FLAG_REJECT);
  97. break;
  98. case 'b':
  99. case 'B': /* XXX */
  100. SET_FLAG (flag, ZEBRA_FLAG_BLACKHOLE);
  101. break;
  102. default:
  103. vty_out (vty, "%% Malformed flag %s %s", flag_str, VTY_NEWLINE);
  104. return CMD_WARNING;
  105. }
  106. }
  107. if (gate_str == NULL)
  108. {
  109. if (add_cmd)
  110. static_add_ipv4_safi (safi, &p, NULL, NULL, flag, distance, vrf_id);
  111. else
  112. static_delete_ipv4_safi (safi, &p, NULL, NULL, distance, vrf_id);
  113. return CMD_SUCCESS;
  114. }
  115. /* When gateway is A.B.C.D format, gate is treated as nexthop
  116. address other case gate is treated as interface name. */
  117. ret = inet_aton (gate_str, &gate);
  118. if (ret)
  119. ifname = NULL;
  120. else
  121. ifname = gate_str;
  122. if (add_cmd)
  123. static_add_ipv4_safi (safi, &p, ifname ? NULL : &gate, ifname, flag, distance, vrf_id);
  124. else
  125. static_delete_ipv4_safi (safi, &p, ifname ? NULL : &gate, ifname, distance, vrf_id);
  126. return CMD_SUCCESS;
  127. }
  128. static int
  129. zebra_static_ipv4 (struct vty *vty, int add_cmd, const char *dest_str,
  130. const char *mask_str, const char *gate_str,
  131. const char *flag_str, const char *distance_str,
  132. const char *vrf_id_str)
  133. {
  134. return zebra_static_ipv4_safi (vty, SAFI_UNICAST, add_cmd, dest_str, mask_str,
  135. gate_str, flag_str, distance_str, vrf_id_str);
  136. }
  137. /* Static unicast routes for multicast RPF lookup. */
  138. DEFUN (ip_mroute_dist,
  139. ip_mroute_dist_cmd,
  140. "ip mroute A.B.C.D/M (A.B.C.D|INTERFACE) <1-255>",
  141. IP_STR
  142. "Configure static unicast route into MRIB for multicast RPF lookup\n"
  143. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  144. "Nexthop address\n"
  145. "Nexthop interface name\n"
  146. "Distance\n")
  147. {
  148. VTY_WARN_EXPERIMENTAL();
  149. return zebra_static_ipv4_safi(vty, SAFI_MULTICAST, 1, argv[0], NULL, argv[1],
  150. NULL, argc > 2 ? argv[2] : NULL, NULL);
  151. }
  152. ALIAS (ip_mroute_dist,
  153. ip_mroute_cmd,
  154. "ip mroute A.B.C.D/M (A.B.C.D|INTERFACE)",
  155. IP_STR
  156. "Configure static unicast route into MRIB for multicast RPF lookup\n"
  157. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  158. "Nexthop address\n"
  159. "Nexthop interface name\n")
  160. DEFUN (ip_mroute_dist_vrf,
  161. ip_mroute_dist_vrf_cmd,
  162. "ip mroute A.B.C.D/M (A.B.C.D|INTERFACE) <1-255> " VRF_CMD_STR,
  163. IP_STR
  164. "Configure static unicast route into MRIB for multicast RPF lookup\n"
  165. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  166. "Nexthop address\n"
  167. "Nexthop interface name\n"
  168. "Distance\n"
  169. VRF_CMD_HELP_STR)
  170. {
  171. VTY_WARN_EXPERIMENTAL();
  172. return zebra_static_ipv4_safi(vty, SAFI_MULTICAST, 1, argv[0], NULL, argv[1],
  173. NULL, argc > 3 ? argv[2] : NULL,
  174. argc > 3 ? argv[3] : argv[2]);
  175. }
  176. ALIAS (ip_mroute_dist_vrf,
  177. ip_mroute_vrf_cmd,
  178. "ip mroute A.B.C.D/M (A.B.C.D|INTERFACE) "VRF_CMD_STR,
  179. IP_STR
  180. "Configure static unicast route into MRIB for multicast RPF lookup\n"
  181. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  182. "Nexthop address\n"
  183. "Nexthop interface name\n"
  184. VRF_CMD_HELP_STR)
  185. DEFUN (no_ip_mroute_dist,
  186. no_ip_mroute_dist_cmd,
  187. "no ip mroute A.B.C.D/M (A.B.C.D|INTERFACE) <1-255>",
  188. IP_STR
  189. "Configure static unicast route into MRIB for multicast RPF lookup\n"
  190. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  191. "Nexthop address\n"
  192. "Nexthop interface name\n"
  193. "Distance\n")
  194. {
  195. VTY_WARN_EXPERIMENTAL();
  196. return zebra_static_ipv4_safi(vty, SAFI_MULTICAST, 0, argv[0], NULL, argv[1],
  197. NULL, argc > 2 ? argv[2] : NULL, NULL);
  198. }
  199. ALIAS (no_ip_mroute_dist,
  200. no_ip_mroute_cmd,
  201. "no ip mroute A.B.C.D/M (A.B.C.D|INTERFACE)",
  202. NO_STR
  203. IP_STR
  204. "Configure static unicast route into MRIB for multicast RPF lookup\n"
  205. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  206. "Nexthop address\n"
  207. "Nexthop interface name\n")
  208. DEFUN (no_ip_mroute_dist_vrf,
  209. no_ip_mroute_dist_vrf_cmd,
  210. "no ip mroute A.B.C.D/M (A.B.C.D|INTERFACE) <1-255> " VRF_CMD_STR,
  211. IP_STR
  212. "Configure static unicast route into MRIB for multicast RPF lookup\n"
  213. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  214. "Nexthop address\n"
  215. "Nexthop interface name\n"
  216. "Distance\n"
  217. VRF_CMD_HELP_STR)
  218. {
  219. VTY_WARN_EXPERIMENTAL();
  220. return zebra_static_ipv4_safi(vty, SAFI_MULTICAST, 0, argv[0], NULL, argv[1],
  221. NULL, argc > 3 ? argv[2] : NULL,
  222. argc > 3 ? argv[3] : argv[2]);
  223. }
  224. ALIAS (no_ip_mroute_dist_vrf,
  225. no_ip_mroute_vrf_cmd,
  226. "no ip mroute A.B.C.D/M (A.B.C.D|INTERFACE) " VRF_CMD_STR,
  227. NO_STR
  228. IP_STR
  229. "Configure static unicast route into MRIB for multicast RPF lookup\n"
  230. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  231. "Nexthop address\n"
  232. "Nexthop interface name\n"
  233. VRF_CMD_HELP_STR)
  234. DEFUN (ip_multicast_mode,
  235. ip_multicast_mode_cmd,
  236. "ip multicast rpf-lookup-mode (urib-only|mrib-only|mrib-then-urib|lower-distance|longer-prefix)",
  237. IP_STR
  238. "Multicast options\n"
  239. "RPF lookup behavior\n"
  240. "Lookup in unicast RIB only\n"
  241. "Lookup in multicast RIB only\n"
  242. "Try multicast RIB first, fall back to unicast RIB\n"
  243. "Lookup both, use entry with lower distance\n"
  244. "Lookup both, use entry with longer prefix\n")
  245. {
  246. VTY_WARN_EXPERIMENTAL();
  247. if (!strncmp (argv[0], "u", 1))
  248. multicast_mode_ipv4_set (MCAST_URIB_ONLY);
  249. else if (!strncmp (argv[0], "mrib-o", 6))
  250. multicast_mode_ipv4_set (MCAST_MRIB_ONLY);
  251. else if (!strncmp (argv[0], "mrib-t", 6))
  252. multicast_mode_ipv4_set (MCAST_MIX_MRIB_FIRST);
  253. else if (!strncmp (argv[0], "low", 3))
  254. multicast_mode_ipv4_set (MCAST_MIX_DISTANCE);
  255. else if (!strncmp (argv[0], "lon", 3))
  256. multicast_mode_ipv4_set (MCAST_MIX_PFXLEN);
  257. else
  258. {
  259. vty_out (vty, "Invalid mode specified%s", VTY_NEWLINE);
  260. return CMD_WARNING;
  261. }
  262. return CMD_SUCCESS;
  263. }
  264. DEFUN (no_ip_multicast_mode,
  265. no_ip_multicast_mode_cmd,
  266. "no ip multicast rpf-lookup-mode (urib-only|mrib-only|mrib-then-urib|lower-distance|longer-prefix)",
  267. NO_STR
  268. IP_STR
  269. "Multicast options\n"
  270. "RPF lookup behavior\n"
  271. "Lookup in unicast RIB only\n"
  272. "Lookup in multicast RIB only\n"
  273. "Try multicast RIB first, fall back to unicast RIB\n"
  274. "Lookup both, use entry with lower distance\n"
  275. "Lookup both, use entry with longer prefix\n")
  276. {
  277. multicast_mode_ipv4_set (MCAST_NO_CONFIG);
  278. return CMD_SUCCESS;
  279. }
  280. ALIAS (no_ip_multicast_mode,
  281. no_ip_multicast_mode_noarg_cmd,
  282. "no ip multicast rpf-lookup-mode",
  283. NO_STR
  284. IP_STR
  285. "Multicast options\n"
  286. "RPF lookup behavior\n")
  287. DEFUN (show_ip_rpf,
  288. show_ip_rpf_cmd,
  289. "show ip rpf",
  290. SHOW_STR
  291. IP_STR
  292. "Display RPF information for multicast source\n")
  293. {
  294. vrf_id_t vrf_id = VRF_DEFAULT;
  295. if (argc > 0)
  296. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
  297. VTY_WARN_EXPERIMENTAL();
  298. return do_show_ip_route(vty, SAFI_MULTICAST, vrf_id);
  299. }
  300. ALIAS (show_ip_rpf,
  301. show_ip_rpf_vrf_cmd,
  302. "show ip rpf " VRF_CMD_STR,
  303. SHOW_STR
  304. IP_STR
  305. "Display RPF information for multicast source\n"
  306. VRF_CMD_HELP_STR)
  307. DEFUN (show_ip_rpf_addr,
  308. show_ip_rpf_addr_cmd,
  309. "show ip rpf A.B.C.D",
  310. SHOW_STR
  311. IP_STR
  312. "Display RPF information for multicast source\n"
  313. "IP multicast source address (e.g. 10.0.0.0)\n")
  314. {
  315. struct in_addr addr;
  316. struct route_node *rn;
  317. struct rib *rib;
  318. vrf_id_t vrf_id = VRF_DEFAULT;
  319. int ret;
  320. if (argc > 1)
  321. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
  322. VTY_WARN_EXPERIMENTAL();
  323. ret = inet_aton (argv[0], &addr);
  324. if (ret == 0)
  325. {
  326. vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
  327. return CMD_WARNING;
  328. }
  329. rib = rib_match_ipv4_multicast (addr, &rn, vrf_id);
  330. if (rib)
  331. vty_show_ip_route_detail (vty, rn, 1);
  332. else
  333. vty_out (vty, "%% No match for RPF lookup%s", VTY_NEWLINE);
  334. return CMD_SUCCESS;
  335. }
  336. ALIAS (show_ip_rpf_addr,
  337. show_ip_rpf_addr_vrf_cmd,
  338. "show ip rpf A.B.C.D " VRF_CMD_STR,
  339. SHOW_STR
  340. IP_STR
  341. "Display RPF information for multicast source\n"
  342. "IP multicast source address (e.g. 10.0.0.0)\n"
  343. VRF_CMD_HELP_STR)
  344. DEFUN (show_ip_rpf_vrf_all,
  345. show_ip_rpf_vrf_all_cmd,
  346. "show ip rpf " VRF_ALL_CMD_STR,
  347. SHOW_STR
  348. IP_STR
  349. "Display RPF information for multicast source\n"
  350. VRF_ALL_CMD_HELP_STR)
  351. {
  352. struct zebra_vrf *zvrf;
  353. struct route_table *table;
  354. struct route_node *rn;
  355. struct rib *rib;
  356. vrf_iter_t iter;
  357. int first = 1;
  358. VTY_WARN_EXPERIMENTAL();
  359. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  360. {
  361. if ((zvrf = vrf_iter2info (iter)) == NULL ||
  362. (table = zvrf->table[AFI_IP][SAFI_MULTICAST]) == NULL)
  363. continue;
  364. /* Show all IPv4 routes. */
  365. for (rn = route_top (table); rn; rn = route_next (rn))
  366. RNODE_FOREACH_RIB (rn, rib)
  367. {
  368. if (first)
  369. {
  370. vty_out (vty, SHOW_ROUTE_V4_HEADER);
  371. first = 0;
  372. }
  373. vty_show_ip_route (vty, rn, rib);
  374. }
  375. }
  376. return CMD_SUCCESS;
  377. }
  378. DEFUN (show_ip_rpf_addr_vrf_all,
  379. show_ip_rpf_addr_vrf_all_cmd,
  380. "show ip rpf A.B.C.D " VRF_ALL_CMD_STR,
  381. SHOW_STR
  382. IP_STR
  383. "Display RPF information for multicast source\n"
  384. "IP multicast source address (e.g. 10.0.0.0)\n"
  385. VRF_ALL_CMD_HELP_STR)
  386. {
  387. struct in_addr addr;
  388. struct route_node *rn;
  389. vrf_iter_t iter;
  390. int ret;
  391. VTY_WARN_EXPERIMENTAL();
  392. ret = inet_aton (argv[0], &addr);
  393. if (ret == 0)
  394. {
  395. vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
  396. return CMD_WARNING;
  397. }
  398. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  399. {
  400. if (rib_match_ipv4_multicast (addr, &rn, vrf_iter2id (iter)))
  401. vty_show_ip_route_detail (vty, rn, 1);
  402. }
  403. return CMD_SUCCESS;
  404. }
  405. /* Static route configuration. */
  406. DEFUN (ip_route,
  407. ip_route_cmd,
  408. "ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0)",
  409. IP_STR
  410. "Establish static routes\n"
  411. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  412. "IP gateway address\n"
  413. "IP gateway interface name\n"
  414. "Null interface\n")
  415. {
  416. return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], NULL, NULL,
  417. NULL);
  418. }
  419. DEFUN (ip_route_flags,
  420. ip_route_flags_cmd,
  421. "ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole)",
  422. IP_STR
  423. "Establish static routes\n"
  424. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  425. "IP gateway address\n"
  426. "IP gateway interface name\n"
  427. "Emit an ICMP unreachable when matched\n"
  428. "Silently discard pkts when matched\n")
  429. {
  430. return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], argv[2], NULL,
  431. NULL);
  432. }
  433. DEFUN (ip_route_flags2,
  434. ip_route_flags2_cmd,
  435. "ip route A.B.C.D/M (reject|blackhole)",
  436. IP_STR
  437. "Establish static routes\n"
  438. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  439. "Emit an ICMP unreachable when matched\n"
  440. "Silently discard pkts when matched\n")
  441. {
  442. return zebra_static_ipv4 (vty, 1, argv[0], NULL, NULL, argv[1], NULL,
  443. NULL);
  444. }
  445. /* Mask as A.B.C.D format. */
  446. DEFUN (ip_route_mask,
  447. ip_route_mask_cmd,
  448. "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0)",
  449. IP_STR
  450. "Establish static routes\n"
  451. "IP destination prefix\n"
  452. "IP destination prefix mask\n"
  453. "IP gateway address\n"
  454. "IP gateway interface name\n"
  455. "Null interface\n")
  456. {
  457. return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], NULL, NULL,
  458. NULL);
  459. }
  460. DEFUN (ip_route_mask_flags,
  461. ip_route_mask_flags_cmd,
  462. "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole)",
  463. IP_STR
  464. "Establish static routes\n"
  465. "IP destination prefix\n"
  466. "IP destination prefix mask\n"
  467. "IP gateway address\n"
  468. "IP gateway interface name\n"
  469. "Emit an ICMP unreachable when matched\n"
  470. "Silently discard pkts when matched\n")
  471. {
  472. return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], argv[3], NULL,
  473. NULL);
  474. }
  475. DEFUN (ip_route_mask_flags2,
  476. ip_route_mask_flags2_cmd,
  477. "ip route A.B.C.D A.B.C.D (reject|blackhole)",
  478. IP_STR
  479. "Establish static routes\n"
  480. "IP destination prefix\n"
  481. "IP destination prefix mask\n"
  482. "Emit an ICMP unreachable when matched\n"
  483. "Silently discard pkts when matched\n")
  484. {
  485. return zebra_static_ipv4 (vty, 1, argv[0], argv[1], NULL, argv[2], NULL,
  486. NULL);
  487. }
  488. /* Distance option value. */
  489. DEFUN (ip_route_distance,
  490. ip_route_distance_cmd,
  491. "ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) <1-255>",
  492. IP_STR
  493. "Establish static routes\n"
  494. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  495. "IP gateway address\n"
  496. "IP gateway interface name\n"
  497. "Null interface\n"
  498. "Distance value for this route\n")
  499. {
  500. return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], NULL, argv[2],
  501. NULL);
  502. }
  503. DEFUN (ip_route_flags_distance,
  504. ip_route_flags_distance_cmd,
  505. "ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
  506. IP_STR
  507. "Establish static routes\n"
  508. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  509. "IP gateway address\n"
  510. "IP gateway interface name\n"
  511. "Emit an ICMP unreachable when matched\n"
  512. "Silently discard pkts when matched\n"
  513. "Distance value for this route\n")
  514. {
  515. return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], argv[2], argv[3],
  516. NULL);
  517. }
  518. DEFUN (ip_route_flags_distance2,
  519. ip_route_flags_distance2_cmd,
  520. "ip route A.B.C.D/M (reject|blackhole) <1-255>",
  521. IP_STR
  522. "Establish static routes\n"
  523. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  524. "Emit an ICMP unreachable when matched\n"
  525. "Silently discard pkts when matched\n"
  526. "Distance value for this route\n")
  527. {
  528. return zebra_static_ipv4 (vty, 1, argv[0], NULL, NULL, argv[1], argv[2],
  529. NULL);
  530. }
  531. DEFUN (ip_route_mask_distance,
  532. ip_route_mask_distance_cmd,
  533. "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0) <1-255>",
  534. IP_STR
  535. "Establish static routes\n"
  536. "IP destination prefix\n"
  537. "IP destination prefix mask\n"
  538. "IP gateway address\n"
  539. "IP gateway interface name\n"
  540. "Null interface\n"
  541. "Distance value for this route\n")
  542. {
  543. return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], NULL, argv[3],
  544. NULL);
  545. }
  546. DEFUN (ip_route_mask_flags_distance,
  547. ip_route_mask_flags_distance_cmd,
  548. "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
  549. IP_STR
  550. "Establish static routes\n"
  551. "IP destination prefix\n"
  552. "IP destination prefix mask\n"
  553. "IP gateway address\n"
  554. "IP gateway interface name\n"
  555. "Emit an ICMP unreachable when matched\n"
  556. "Silently discard pkts when matched\n"
  557. "Distance value for this route\n")
  558. {
  559. return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], argv[3], argv[4],
  560. NULL);
  561. }
  562. DEFUN (ip_route_mask_flags_distance2,
  563. ip_route_mask_flags_distance2_cmd,
  564. "ip route A.B.C.D A.B.C.D (reject|blackhole) <1-255>",
  565. IP_STR
  566. "Establish static routes\n"
  567. "IP destination prefix\n"
  568. "IP destination prefix mask\n"
  569. "Emit an ICMP unreachable when matched\n"
  570. "Silently discard pkts when matched\n"
  571. "Distance value for this route\n")
  572. {
  573. return zebra_static_ipv4 (vty, 1, argv[0], argv[1], NULL, argv[2], argv[3],
  574. NULL);
  575. }
  576. DEFUN (no_ip_route,
  577. no_ip_route_cmd,
  578. "no ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0)",
  579. NO_STR
  580. IP_STR
  581. "Establish static routes\n"
  582. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  583. "IP gateway address\n"
  584. "IP gateway interface name\n"
  585. "Null interface\n")
  586. {
  587. return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], NULL, NULL,
  588. NULL);
  589. }
  590. ALIAS (no_ip_route,
  591. no_ip_route_flags_cmd,
  592. "no ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole)",
  593. NO_STR
  594. IP_STR
  595. "Establish static routes\n"
  596. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  597. "IP gateway address\n"
  598. "IP gateway interface name\n"
  599. "Emit an ICMP unreachable when matched\n"
  600. "Silently discard pkts when matched\n")
  601. DEFUN (no_ip_route_flags2,
  602. no_ip_route_flags2_cmd,
  603. "no ip route A.B.C.D/M (reject|blackhole)",
  604. NO_STR
  605. IP_STR
  606. "Establish static routes\n"
  607. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  608. "Emit an ICMP unreachable when matched\n"
  609. "Silently discard pkts when matched\n")
  610. {
  611. return zebra_static_ipv4 (vty, 0, argv[0], NULL, NULL, NULL, NULL,
  612. NULL);
  613. }
  614. DEFUN (no_ip_route_mask,
  615. no_ip_route_mask_cmd,
  616. "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0)",
  617. NO_STR
  618. IP_STR
  619. "Establish static routes\n"
  620. "IP destination prefix\n"
  621. "IP destination prefix mask\n"
  622. "IP gateway address\n"
  623. "IP gateway interface name\n"
  624. "Null interface\n")
  625. {
  626. return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], NULL, NULL,
  627. NULL);
  628. }
  629. ALIAS (no_ip_route_mask,
  630. no_ip_route_mask_flags_cmd,
  631. "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole)",
  632. NO_STR
  633. IP_STR
  634. "Establish static routes\n"
  635. "IP destination prefix\n"
  636. "IP destination prefix mask\n"
  637. "IP gateway address\n"
  638. "IP gateway interface name\n"
  639. "Emit an ICMP unreachable when matched\n"
  640. "Silently discard pkts when matched\n")
  641. DEFUN (no_ip_route_mask_flags2,
  642. no_ip_route_mask_flags2_cmd,
  643. "no ip route A.B.C.D A.B.C.D (reject|blackhole)",
  644. NO_STR
  645. IP_STR
  646. "Establish static routes\n"
  647. "IP destination prefix\n"
  648. "IP destination prefix mask\n"
  649. "Emit an ICMP unreachable when matched\n"
  650. "Silently discard pkts when matched\n")
  651. {
  652. return zebra_static_ipv4 (vty, 0, argv[0], argv[1], NULL, NULL, NULL,
  653. NULL);
  654. }
  655. DEFUN (no_ip_route_distance,
  656. no_ip_route_distance_cmd,
  657. "no ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) <1-255>",
  658. NO_STR
  659. IP_STR
  660. "Establish static routes\n"
  661. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  662. "IP gateway address\n"
  663. "IP gateway interface name\n"
  664. "Null interface\n"
  665. "Distance value for this route\n")
  666. {
  667. return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], NULL, argv[2],
  668. NULL);
  669. }
  670. DEFUN (no_ip_route_flags_distance,
  671. no_ip_route_flags_distance_cmd,
  672. "no ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
  673. NO_STR
  674. IP_STR
  675. "Establish static routes\n"
  676. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  677. "IP gateway address\n"
  678. "IP gateway interface name\n"
  679. "Emit an ICMP unreachable when matched\n"
  680. "Silently discard pkts when matched\n"
  681. "Distance value for this route\n")
  682. {
  683. return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], argv[2], argv[3],
  684. NULL);
  685. }
  686. DEFUN (no_ip_route_flags_distance2,
  687. no_ip_route_flags_distance2_cmd,
  688. "no ip route A.B.C.D/M (reject|blackhole) <1-255>",
  689. NO_STR
  690. IP_STR
  691. "Establish static routes\n"
  692. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  693. "Emit an ICMP unreachable when matched\n"
  694. "Silently discard pkts when matched\n"
  695. "Distance value for this route\n")
  696. {
  697. return zebra_static_ipv4 (vty, 0, argv[0], NULL, NULL, argv[1], argv[2],
  698. NULL);
  699. }
  700. DEFUN (no_ip_route_mask_distance,
  701. no_ip_route_mask_distance_cmd,
  702. "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0) <1-255>",
  703. NO_STR
  704. IP_STR
  705. "Establish static routes\n"
  706. "IP destination prefix\n"
  707. "IP destination prefix mask\n"
  708. "IP gateway address\n"
  709. "IP gateway interface name\n"
  710. "Null interface\n"
  711. "Distance value for this route\n")
  712. {
  713. return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], NULL, argv[3],
  714. NULL);
  715. }
  716. DEFUN (no_ip_route_mask_flags_distance,
  717. no_ip_route_mask_flags_distance_cmd,
  718. "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
  719. NO_STR
  720. IP_STR
  721. "Establish static routes\n"
  722. "IP destination prefix\n"
  723. "IP destination prefix mask\n"
  724. "IP gateway address\n"
  725. "IP gateway interface name\n"
  726. "Emit an ICMP unreachable when matched\n"
  727. "Silently discard pkts when matched\n"
  728. "Distance value for this route\n")
  729. {
  730. return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], argv[3], argv[4],
  731. NULL);
  732. }
  733. DEFUN (no_ip_route_mask_flags_distance2,
  734. no_ip_route_mask_flags_distance2_cmd,
  735. "no ip route A.B.C.D A.B.C.D (reject|blackhole) <1-255>",
  736. NO_STR
  737. IP_STR
  738. "Establish static routes\n"
  739. "IP destination prefix\n"
  740. "IP destination prefix mask\n"
  741. "Emit an ICMP unreachable when matched\n"
  742. "Silently discard pkts when matched\n"
  743. "Distance value for this route\n")
  744. {
  745. return zebra_static_ipv4 (vty, 0, argv[0], argv[1], NULL, argv[2], argv[3],
  746. NULL);
  747. }
  748. DEFUN (ip_route_vrf,
  749. ip_route_vrf_cmd,
  750. "ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) " VRF_CMD_STR,
  751. IP_STR
  752. "Establish static routes\n"
  753. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  754. "IP gateway address\n"
  755. "IP gateway interface name\n"
  756. "Null interface\n"
  757. VRF_CMD_HELP_STR)
  758. {
  759. return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], NULL, NULL,
  760. argv[2]);
  761. }
  762. DEFUN (ip_route_flags_vrf,
  763. ip_route_flags_vrf_cmd,
  764. "ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole) " VRF_CMD_STR,
  765. IP_STR
  766. "Establish static routes\n"
  767. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  768. "IP gateway address\n"
  769. "IP gateway interface name\n"
  770. "Emit an ICMP unreachable when matched\n"
  771. "Silently discard pkts when matched\n"
  772. VRF_CMD_HELP_STR)
  773. {
  774. return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], argv[2], NULL,
  775. argv[3]);
  776. }
  777. DEFUN (ip_route_flags2_vrf,
  778. ip_route_flags2_vrf_cmd,
  779. "ip route A.B.C.D/M (reject|blackhole) " VRF_CMD_STR,
  780. IP_STR
  781. "Establish static routes\n"
  782. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  783. "Emit an ICMP unreachable when matched\n"
  784. "Silently discard pkts when matched\n"
  785. VRF_CMD_HELP_STR)
  786. {
  787. return zebra_static_ipv4 (vty, 1, argv[0], NULL, NULL, argv[1], NULL,
  788. argv[2]);
  789. }
  790. /* Mask as A.B.C.D format. */
  791. DEFUN (ip_route_mask_vrf,
  792. ip_route_mask_vrf_cmd,
  793. "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0) " VRF_CMD_STR,
  794. IP_STR
  795. "Establish static routes\n"
  796. "IP destination prefix\n"
  797. "IP destination prefix mask\n"
  798. "IP gateway address\n"
  799. "IP gateway interface name\n"
  800. "Null interface\n"
  801. VRF_CMD_HELP_STR)
  802. {
  803. return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], NULL, NULL,
  804. argv[3]);
  805. }
  806. DEFUN (ip_route_mask_flags_vrf,
  807. ip_route_mask_flags_vrf_cmd,
  808. "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole) " VRF_CMD_STR,
  809. IP_STR
  810. "Establish static routes\n"
  811. "IP destination prefix\n"
  812. "IP destination prefix mask\n"
  813. "IP gateway address\n"
  814. "IP gateway interface name\n"
  815. "Emit an ICMP unreachable when matched\n"
  816. "Silently discard pkts when matched\n"
  817. VRF_CMD_HELP_STR)
  818. {
  819. return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], argv[3], NULL,
  820. argv[4]);
  821. }
  822. DEFUN (ip_route_mask_flags2_vrf,
  823. ip_route_mask_flags2_vrf_cmd,
  824. "ip route A.B.C.D A.B.C.D (reject|blackhole) " VRF_CMD_STR,
  825. IP_STR
  826. "Establish static routes\n"
  827. "IP destination prefix\n"
  828. "IP destination prefix mask\n"
  829. "Emit an ICMP unreachable when matched\n"
  830. "Silently discard pkts when matched\n"
  831. VRF_CMD_HELP_STR)
  832. {
  833. return zebra_static_ipv4 (vty, 1, argv[0], argv[1], NULL, argv[2], NULL,
  834. argv[3]);
  835. }
  836. /* Distance option value. */
  837. DEFUN (ip_route_distance_vrf,
  838. ip_route_distance_vrf_cmd,
  839. "ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) <1-255> " VRF_CMD_STR,
  840. IP_STR
  841. "Establish static routes\n"
  842. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  843. "IP gateway address\n"
  844. "IP gateway interface name\n"
  845. "Null interface\n"
  846. "Distance value for this route\n"
  847. VRF_CMD_HELP_STR)
  848. {
  849. return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], NULL, argv[2],
  850. argv[3]);
  851. }
  852. DEFUN (ip_route_flags_distance_vrf,
  853. ip_route_flags_distance_vrf_cmd,
  854. "ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole) <1-255> " VRF_CMD_STR,
  855. IP_STR
  856. "Establish static routes\n"
  857. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  858. "IP gateway address\n"
  859. "IP gateway interface name\n"
  860. "Emit an ICMP unreachable when matched\n"
  861. "Silently discard pkts when matched\n"
  862. "Distance value for this route\n"
  863. VRF_CMD_HELP_STR)
  864. {
  865. return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], argv[2], argv[3],
  866. argv[4]);
  867. }
  868. DEFUN (ip_route_flags_distance2_vrf,
  869. ip_route_flags_distance2_vrf_cmd,
  870. "ip route A.B.C.D/M (reject|blackhole) <1-255> " VRF_CMD_STR,
  871. IP_STR
  872. "Establish static routes\n"
  873. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  874. "Emit an ICMP unreachable when matched\n"
  875. "Silently discard pkts when matched\n"
  876. "Distance value for this route\n"
  877. VRF_CMD_HELP_STR)
  878. {
  879. return zebra_static_ipv4 (vty, 1, argv[0], NULL, NULL, argv[1], argv[2],
  880. argv[3]);
  881. }
  882. DEFUN (ip_route_mask_distance_vrf,
  883. ip_route_mask_distance_vrf_cmd,
  884. "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0) <1-255> " VRF_CMD_STR,
  885. IP_STR
  886. "Establish static routes\n"
  887. "IP destination prefix\n"
  888. "IP destination prefix mask\n"
  889. "IP gateway address\n"
  890. "IP gateway interface name\n"
  891. "Null interface\n"
  892. "Distance value for this route\n"
  893. VRF_CMD_HELP_STR)
  894. {
  895. return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], NULL, argv[3],
  896. argv[4]);
  897. }
  898. DEFUN (ip_route_mask_flags_distance_vrf,
  899. ip_route_mask_flags_distance_vrf_cmd,
  900. "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole) <1-255> " VRF_CMD_STR,
  901. IP_STR
  902. "Establish static routes\n"
  903. "IP destination prefix\n"
  904. "IP destination prefix mask\n"
  905. "IP gateway address\n"
  906. "IP gateway interface name\n"
  907. "Emit an ICMP unreachable when matched\n"
  908. "Silently discard pkts when matched\n"
  909. "Distance value for this route\n"
  910. VRF_CMD_HELP_STR)
  911. {
  912. return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], argv[3], argv[4],
  913. argv[5]);
  914. }
  915. DEFUN (ip_route_mask_flags_distance2_vrf,
  916. ip_route_mask_flags_distance2_vrf_cmd,
  917. "ip route A.B.C.D A.B.C.D (reject|blackhole) <1-255> " VRF_CMD_STR,
  918. IP_STR
  919. "Establish static routes\n"
  920. "IP destination prefix\n"
  921. "IP destination prefix mask\n"
  922. "Emit an ICMP unreachable when matched\n"
  923. "Silently discard pkts when matched\n"
  924. "Distance value for this route\n"
  925. VRF_CMD_HELP_STR)
  926. {
  927. return zebra_static_ipv4 (vty, 1, argv[0], argv[1], NULL, argv[2], argv[3],
  928. argv[4]);
  929. }
  930. DEFUN (no_ip_route_vrf,
  931. no_ip_route_vrf_cmd,
  932. "no ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) " VRF_CMD_STR,
  933. NO_STR
  934. IP_STR
  935. "Establish static routes\n"
  936. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  937. "IP gateway address\n"
  938. "IP gateway interface name\n"
  939. "Null interface\n"
  940. VRF_CMD_HELP_STR)
  941. {
  942. return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], NULL, NULL,
  943. (argc > 3) ? argv[3] : argv[2]);
  944. }
  945. ALIAS (no_ip_route_vrf,
  946. no_ip_route_flags_vrf_cmd,
  947. "no ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole) " VRF_CMD_STR,
  948. NO_STR
  949. IP_STR
  950. "Establish static routes\n"
  951. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  952. "IP gateway address\n"
  953. "IP gateway interface name\n"
  954. "Emit an ICMP unreachable when matched\n"
  955. "Silently discard pkts when matched\n"
  956. VRF_CMD_HELP_STR)
  957. DEFUN (no_ip_route_flags2_vrf,
  958. no_ip_route_flags2_vrf_cmd,
  959. "no ip route A.B.C.D/M (reject|blackhole) " VRF_CMD_STR,
  960. NO_STR
  961. IP_STR
  962. "Establish static routes\n"
  963. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  964. "Emit an ICMP unreachable when matched\n"
  965. "Silently discard pkts when matched\n"
  966. VRF_CMD_HELP_STR)
  967. {
  968. return zebra_static_ipv4 (vty, 0, argv[0], NULL, NULL, NULL, NULL,
  969. argv[2]);
  970. }
  971. DEFUN (no_ip_route_mask_vrf,
  972. no_ip_route_mask_vrf_cmd,
  973. "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0) " VRF_CMD_STR,
  974. NO_STR
  975. IP_STR
  976. "Establish static routes\n"
  977. "IP destination prefix\n"
  978. "IP destination prefix mask\n"
  979. "IP gateway address\n"
  980. "IP gateway interface name\n"
  981. "Null interface\n"
  982. VRF_CMD_HELP_STR)
  983. {
  984. return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], NULL, NULL,
  985. (argc > 4) ? argv[4] : argv[3]);
  986. }
  987. ALIAS (no_ip_route_mask_vrf,
  988. no_ip_route_mask_flags_vrf_cmd,
  989. "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole) " VRF_CMD_STR,
  990. NO_STR
  991. IP_STR
  992. "Establish static routes\n"
  993. "IP destination prefix\n"
  994. "IP destination prefix mask\n"
  995. "IP gateway address\n"
  996. "IP gateway interface name\n"
  997. "Emit an ICMP unreachable when matched\n"
  998. "Silently discard pkts when matched\n"
  999. VRF_CMD_HELP_STR)
  1000. DEFUN (no_ip_route_mask_flags2_vrf,
  1001. no_ip_route_mask_flags2_vrf_cmd,
  1002. "no ip route A.B.C.D A.B.C.D (reject|blackhole) " VRF_CMD_STR,
  1003. NO_STR
  1004. IP_STR
  1005. "Establish static routes\n"
  1006. "IP destination prefix\n"
  1007. "IP destination prefix mask\n"
  1008. "Emit an ICMP unreachable when matched\n"
  1009. "Silently discard pkts when matched\n"
  1010. VRF_CMD_HELP_STR)
  1011. {
  1012. return zebra_static_ipv4 (vty, 0, argv[0], argv[1], NULL, NULL, NULL,
  1013. argv[2]);
  1014. }
  1015. DEFUN (no_ip_route_distance_vrf,
  1016. no_ip_route_distance_vrf_cmd,
  1017. "no ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) <1-255> " VRF_CMD_STR,
  1018. NO_STR
  1019. IP_STR
  1020. "Establish static routes\n"
  1021. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  1022. "IP gateway address\n"
  1023. "IP gateway interface name\n"
  1024. "Null interface\n"
  1025. "Distance value for this route\n"
  1026. VRF_CMD_HELP_STR)
  1027. {
  1028. return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], NULL, argv[2],
  1029. argv[3]);
  1030. }
  1031. DEFUN (no_ip_route_flags_distance_vrf,
  1032. no_ip_route_flags_distance_vrf_cmd,
  1033. "no ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole) <1-255> " VRF_CMD_STR,
  1034. NO_STR
  1035. IP_STR
  1036. "Establish static routes\n"
  1037. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  1038. "IP gateway address\n"
  1039. "IP gateway interface name\n"
  1040. "Emit an ICMP unreachable when matched\n"
  1041. "Silently discard pkts when matched\n"
  1042. "Distance value for this route\n"
  1043. VRF_CMD_HELP_STR)
  1044. {
  1045. return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], argv[2], argv[3],
  1046. argv[4]);
  1047. }
  1048. DEFUN (no_ip_route_flags_distance2_vrf,
  1049. no_ip_route_flags_distance2_vrf_cmd,
  1050. "no ip route A.B.C.D/M (reject|blackhole) <1-255> " VRF_CMD_STR,
  1051. NO_STR
  1052. IP_STR
  1053. "Establish static routes\n"
  1054. "IP destination prefix (e.g. 10.0.0.0/8)\n"
  1055. "Emit an ICMP unreachable when matched\n"
  1056. "Silently discard pkts when matched\n"
  1057. "Distance value for this route\n"
  1058. VRF_CMD_HELP_STR)
  1059. {
  1060. return zebra_static_ipv4 (vty, 0, argv[0], NULL, NULL, argv[1], argv[2],
  1061. argv[3]);
  1062. }
  1063. DEFUN (no_ip_route_mask_distance_vrf,
  1064. no_ip_route_mask_distance_vrf_cmd,
  1065. "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0) <1-255> " VRF_CMD_STR,
  1066. NO_STR
  1067. IP_STR
  1068. "Establish static routes\n"
  1069. "IP destination prefix\n"
  1070. "IP destination prefix mask\n"
  1071. "IP gateway address\n"
  1072. "IP gateway interface name\n"
  1073. "Null interface\n"
  1074. "Distance value for this route\n"
  1075. VRF_CMD_HELP_STR)
  1076. {
  1077. return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], NULL, argv[3],
  1078. argv[4]);
  1079. }
  1080. DEFUN (no_ip_route_mask_flags_distance_vrf,
  1081. no_ip_route_mask_flags_distance_vrf_cmd,
  1082. "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole) <1-255> " VRF_CMD_STR,
  1083. NO_STR
  1084. IP_STR
  1085. "Establish static routes\n"
  1086. "IP destination prefix\n"
  1087. "IP destination prefix mask\n"
  1088. "IP gateway address\n"
  1089. "IP gateway interface name\n"
  1090. "Emit an ICMP unreachable when matched\n"
  1091. "Silently discard pkts when matched\n"
  1092. "Distance value for this route\n"
  1093. VRF_CMD_HELP_STR)
  1094. {
  1095. return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], argv[3], argv[4],
  1096. argv[5]);
  1097. }
  1098. DEFUN (no_ip_route_mask_flags_distance2_vrf,
  1099. no_ip_route_mask_flags_distance2_vrf_cmd,
  1100. "no ip route A.B.C.D A.B.C.D (reject|blackhole) <1-255> " VRF_CMD_STR,
  1101. NO_STR
  1102. IP_STR
  1103. "Establish static routes\n"
  1104. "IP destination prefix\n"
  1105. "IP destination prefix mask\n"
  1106. "Emit an ICMP unreachable when matched\n"
  1107. "Silently discard pkts when matched\n"
  1108. "Distance value for this route\n"
  1109. VRF_CMD_HELP_STR)
  1110. {
  1111. return zebra_static_ipv4 (vty, 0, argv[0], argv[1], NULL, argv[2], argv[3],
  1112. argv[4]);
  1113. }
  1114. char *proto_rm[AFI_MAX][ZEBRA_ROUTE_MAX+1]; /* "any" == ZEBRA_ROUTE_MAX */
  1115. DEFUN (ip_protocol,
  1116. ip_protocol_cmd,
  1117. "ip protocol PROTO route-map ROUTE-MAP",
  1118. NO_STR
  1119. "Apply route map to PROTO\n"
  1120. "Protocol name\n"
  1121. "Route map name\n")
  1122. {
  1123. int i;
  1124. if (strcasecmp(argv[0], "any") == 0)
  1125. i = ZEBRA_ROUTE_MAX;
  1126. else
  1127. i = proto_name2num(argv[0]);
  1128. if (i < 0)
  1129. {
  1130. vty_out (vty, "invalid protocol name \"%s\"%s", argv[0] ? argv[0] : "",
  1131. VTY_NEWLINE);
  1132. return CMD_WARNING;
  1133. }
  1134. if (proto_rm[AFI_IP][i])
  1135. XFREE (MTYPE_ROUTE_MAP_NAME, proto_rm[AFI_IP][i]);
  1136. proto_rm[AFI_IP][i] = XSTRDUP (MTYPE_ROUTE_MAP_NAME, argv[1]);
  1137. return CMD_SUCCESS;
  1138. }
  1139. DEFUN (no_ip_protocol,
  1140. no_ip_protocol_cmd,
  1141. "no ip protocol PROTO",
  1142. NO_STR
  1143. "Remove route map from PROTO\n"
  1144. "Protocol name\n")
  1145. {
  1146. int i;
  1147. if (strcasecmp(argv[0], "any") == 0)
  1148. i = ZEBRA_ROUTE_MAX;
  1149. else
  1150. i = proto_name2num(argv[0]);
  1151. if (i < 0)
  1152. {
  1153. vty_out (vty, "invalid protocol name \"%s\"%s", argv[0] ? argv[0] : "",
  1154. VTY_NEWLINE);
  1155. return CMD_WARNING;
  1156. }
  1157. if (proto_rm[AFI_IP][i])
  1158. XFREE (MTYPE_ROUTE_MAP_NAME, proto_rm[AFI_IP][i]);
  1159. proto_rm[AFI_IP][i] = NULL;
  1160. return CMD_SUCCESS;
  1161. }
  1162. /* New RIB. Detailed information for IPv4 route. */
  1163. static void
  1164. vty_show_ip_route_detail (struct vty *vty, struct route_node *rn, int mcast)
  1165. {
  1166. struct rib *rib;
  1167. struct nexthop *nexthop, *tnexthop;
  1168. int recursing;
  1169. char buf[PREFIX_STRLEN];
  1170. RNODE_FOREACH_RIB (rn, rib)
  1171. {
  1172. const char *mcast_info = "";
  1173. if (mcast)
  1174. {
  1175. rib_table_info_t *info = rn->table->info;
  1176. mcast_info = (info->safi == SAFI_MULTICAST)
  1177. ? " using Multicast RIB"
  1178. : " using Unicast RIB";
  1179. }
  1180. vty_out (vty, "Routing entry for %s%s%s",
  1181. prefix2str (&rn->p, buf, sizeof(buf)), mcast_info,
  1182. VTY_NEWLINE);
  1183. vty_out (vty, " Known via \"%s\"", zebra_route_string (rib->type));
  1184. vty_out (vty, ", distance %u, metric %u", rib->distance, rib->metric);
  1185. vty_out (vty, ", vrf %u", rib->vrf_id);
  1186. if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
  1187. vty_out (vty, ", best");
  1188. if (rib->refcnt)
  1189. vty_out (vty, ", refcnt %ld", rib->refcnt);
  1190. if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
  1191. vty_out (vty, ", blackhole");
  1192. if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
  1193. vty_out (vty, ", reject");
  1194. vty_out (vty, "%s", VTY_NEWLINE);
  1195. #define ONE_DAY_SECOND 60*60*24
  1196. #define ONE_WEEK_SECOND 60*60*24*7
  1197. if (rib->type == ZEBRA_ROUTE_RIP
  1198. || rib->type == ZEBRA_ROUTE_RIPNG
  1199. || rib->type == ZEBRA_ROUTE_OSPF
  1200. || rib->type == ZEBRA_ROUTE_OSPF6
  1201. || rib->type == ZEBRA_ROUTE_BABEL
  1202. || rib->type == ZEBRA_ROUTE_ISIS
  1203. || rib->type == ZEBRA_ROUTE_BGP)
  1204. {
  1205. time_t uptime;
  1206. struct tm *tm;
  1207. uptime = time (NULL);
  1208. uptime -= rib->uptime;
  1209. tm = gmtime (&uptime);
  1210. vty_out (vty, " Last update ");
  1211. if (uptime < ONE_DAY_SECOND)
  1212. vty_out (vty, "%02d:%02d:%02d",
  1213. tm->tm_hour, tm->tm_min, tm->tm_sec);
  1214. else if (uptime < ONE_WEEK_SECOND)
  1215. vty_out (vty, "%dd%02dh%02dm",
  1216. tm->tm_yday, tm->tm_hour, tm->tm_min);
  1217. else
  1218. vty_out (vty, "%02dw%dd%02dh",
  1219. tm->tm_yday/7,
  1220. tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
  1221. vty_out (vty, " ago%s", VTY_NEWLINE);
  1222. }
  1223. for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing))
  1224. {
  1225. vty_out (vty, " %c%s",
  1226. CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB) ? '*' : ' ',
  1227. recursing ? " " : "");
  1228. switch (nexthop->type)
  1229. {
  1230. case NEXTHOP_TYPE_IPV4:
  1231. case NEXTHOP_TYPE_IPV4_IFINDEX:
  1232. vty_out (vty, " %s", inet_ntoa (nexthop->gate.ipv4));
  1233. if (nexthop->ifindex)
  1234. vty_out (vty, ", via %s",
  1235. ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
  1236. break;
  1237. case NEXTHOP_TYPE_IPV6:
  1238. case NEXTHOP_TYPE_IPV6_IFINDEX:
  1239. case NEXTHOP_TYPE_IPV6_IFNAME:
  1240. vty_out (vty, " %s",
  1241. inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, sizeof(buf)));
  1242. if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME)
  1243. vty_out (vty, ", %s", nexthop->ifname);
  1244. else if (nexthop->ifindex)
  1245. vty_out (vty, ", via %s",
  1246. ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
  1247. break;
  1248. case NEXTHOP_TYPE_IFINDEX:
  1249. vty_out (vty, " directly connected, %s",
  1250. ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
  1251. break;
  1252. case NEXTHOP_TYPE_IFNAME:
  1253. vty_out (vty, " directly connected, %s", nexthop->ifname);
  1254. break;
  1255. case NEXTHOP_TYPE_BLACKHOLE:
  1256. vty_out (vty, " directly connected, Null0");
  1257. break;
  1258. default:
  1259. break;
  1260. }
  1261. if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
  1262. vty_out (vty, " inactive");
  1263. if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ONLINK))
  1264. vty_out (vty, " onlink");
  1265. if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
  1266. vty_out (vty, " (recursive)");
  1267. switch (nexthop->type)
  1268. {
  1269. case NEXTHOP_TYPE_IPV4:
  1270. case NEXTHOP_TYPE_IPV4_IFINDEX:
  1271. case NEXTHOP_TYPE_IPV4_IFNAME:
  1272. if (nexthop->src.ipv4.s_addr)
  1273. {
  1274. if (inet_ntop(AF_INET, &nexthop->src.ipv4, buf, sizeof buf))
  1275. vty_out (vty, ", src %s", buf);
  1276. }
  1277. break;
  1278. #ifdef HAVE_IPV6
  1279. case NEXTHOP_TYPE_IPV6:
  1280. case NEXTHOP_TYPE_IPV6_IFINDEX:
  1281. case NEXTHOP_TYPE_IPV6_IFNAME:
  1282. if (!IPV6_ADDR_SAME(&nexthop->src.ipv6, &in6addr_any))
  1283. {
  1284. if (inet_ntop(AF_INET6, &nexthop->src.ipv6, buf, sizeof buf))
  1285. vty_out (vty, ", src %s", buf);
  1286. }
  1287. break;
  1288. #endif /* HAVE_IPV6 */
  1289. default:
  1290. break;
  1291. }
  1292. vty_out (vty, "%s", VTY_NEWLINE);
  1293. }
  1294. vty_out (vty, "%s", VTY_NEWLINE);
  1295. }
  1296. }
  1297. static void
  1298. vty_show_ip_route (struct vty *vty, struct route_node *rn, struct rib *rib)
  1299. {
  1300. struct nexthop *nexthop, *tnexthop;
  1301. int recursing;
  1302. int len = 0;
  1303. char buf[BUFSIZ];
  1304. /* Nexthop information. */
  1305. for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing))
  1306. {
  1307. if (nexthop == rib->nexthop)
  1308. {
  1309. /* Prefix information. */
  1310. len = vty_out (vty, "%c%c%c %s",
  1311. zebra_route_char (rib->type),
  1312. CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED)
  1313. ? '>' : ' ',
  1314. CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
  1315. ? '*' : ' ',
  1316. prefix2str (&rn->p, buf, sizeof buf));
  1317. /* Distance and metric display. */
  1318. if (rib->type != ZEBRA_ROUTE_CONNECT
  1319. && rib->type != ZEBRA_ROUTE_KERNEL)
  1320. len += vty_out (vty, " [%d/%d]", rib->distance,
  1321. rib->metric);
  1322. if (rib->vrf_id != VRF_DEFAULT)
  1323. len += vty_out (vty, " [vrf %u]", rib->vrf_id);
  1324. }
  1325. else
  1326. vty_out (vty, " %c%*c",
  1327. CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
  1328. ? '*' : ' ',
  1329. len - 3 + (2 * recursing), ' ');
  1330. switch (nexthop->type)
  1331. {
  1332. case NEXTHOP_TYPE_IPV4:
  1333. case NEXTHOP_TYPE_IPV4_IFINDEX:
  1334. vty_out (vty, " via %s", inet_ntoa (nexthop->gate.ipv4));
  1335. if (nexthop->ifindex)
  1336. vty_out (vty, ", %s",
  1337. ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
  1338. break;
  1339. case NEXTHOP_TYPE_IPV6:
  1340. case NEXTHOP_TYPE_IPV6_IFINDEX:
  1341. case NEXTHOP_TYPE_IPV6_IFNAME:
  1342. vty_out (vty, " via %s",
  1343. inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, BUFSIZ));
  1344. if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME)
  1345. vty_out (vty, ", %s", nexthop->ifname);
  1346. else if (nexthop->ifindex)
  1347. vty_out (vty, ", %s",
  1348. ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
  1349. break;
  1350. case NEXTHOP_TYPE_IFINDEX:
  1351. vty_out (vty, " is directly connected, %s",
  1352. ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
  1353. break;
  1354. case NEXTHOP_TYPE_IFNAME:
  1355. vty_out (vty, " is directly connected, %s", nexthop->ifname);
  1356. break;
  1357. case NEXTHOP_TYPE_BLACKHOLE:
  1358. vty_out (vty, " is directly connected, Null0");
  1359. break;
  1360. default:
  1361. break;
  1362. }
  1363. if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
  1364. vty_out (vty, " inactive");
  1365. if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ONLINK))
  1366. vty_out (vty, " onlink");
  1367. if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
  1368. vty_out (vty, " (recursive)");
  1369. switch (nexthop->type)
  1370. {
  1371. case NEXTHOP_TYPE_IPV4:
  1372. case NEXTHOP_TYPE_IPV4_IFINDEX:
  1373. case NEXTHOP_TYPE_IPV4_IFNAME:
  1374. if (nexthop->src.ipv4.s_addr)
  1375. {
  1376. if (inet_ntop(AF_INET, &nexthop->src.ipv4, buf, sizeof buf))
  1377. vty_out (vty, ", src %s", buf);
  1378. }
  1379. break;
  1380. #ifdef HAVE_IPV6
  1381. case NEXTHOP_TYPE_IPV6:
  1382. case NEXTHOP_TYPE_IPV6_IFINDEX:
  1383. case NEXTHOP_TYPE_IPV6_IFNAME:
  1384. if (!IPV6_ADDR_SAME(&nexthop->src.ipv6, &in6addr_any))
  1385. {
  1386. if (inet_ntop(AF_INET6, &nexthop->src.ipv6, buf, sizeof buf))
  1387. vty_out (vty, ", src %s", buf);
  1388. }
  1389. break;
  1390. #endif /* HAVE_IPV6 */
  1391. default:
  1392. break;
  1393. }
  1394. if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
  1395. vty_out (vty, ", bh");
  1396. if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
  1397. vty_out (vty, ", rej");
  1398. if (rib->type == ZEBRA_ROUTE_RIP
  1399. || rib->type == ZEBRA_ROUTE_RIPNG
  1400. || rib->type == ZEBRA_ROUTE_OSPF
  1401. || rib->type == ZEBRA_ROUTE_OSPF6
  1402. || rib->type == ZEBRA_ROUTE_BABEL
  1403. || rib->type == ZEBRA_ROUTE_ISIS
  1404. || rib->type == ZEBRA_ROUTE_BGP)
  1405. {
  1406. time_t uptime;
  1407. struct tm *tm;
  1408. uptime = time (NULL);
  1409. uptime -= rib->uptime;
  1410. tm = gmtime (&uptime);
  1411. #define ONE_DAY_SECOND 60*60*24
  1412. #define ONE_WEEK_SECOND 60*60*24*7
  1413. if (uptime < ONE_DAY_SECOND)
  1414. vty_out (vty, ", %02d:%02d:%02d",
  1415. tm->tm_hour, tm->tm_min, tm->tm_sec);
  1416. else if (uptime < ONE_WEEK_SECOND)
  1417. vty_out (vty, ", %dd%02dh%02dm",
  1418. tm->tm_yday, tm->tm_hour, tm->tm_min);
  1419. else
  1420. vty_out (vty, ", %02dw%dd%02dh",
  1421. tm->tm_yday/7,
  1422. tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
  1423. }
  1424. vty_out (vty, "%s", VTY_NEWLINE);
  1425. }
  1426. }
  1427. DEFUN (show_ip_route,
  1428. show_ip_route_cmd,
  1429. "show ip route",
  1430. SHOW_STR
  1431. IP_STR
  1432. "IP routing table\n")
  1433. {
  1434. vrf_id_t vrf_id = VRF_DEFAULT;
  1435. if (argc > 0)
  1436. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
  1437. return do_show_ip_route(vty, SAFI_UNICAST, vrf_id);
  1438. }
  1439. static int do_show_ip_route(struct vty *vty, safi_t safi, vrf_id_t vrf_id)
  1440. {
  1441. struct route_table *table;
  1442. struct route_node *rn;
  1443. struct rib *rib;
  1444. int first = 1;
  1445. table = zebra_vrf_table (AFI_IP, safi, vrf_id);
  1446. if (! table)
  1447. return CMD_SUCCESS;
  1448. /* Show all IPv4 routes. */
  1449. for (rn = route_top (table); rn; rn = route_next (rn))
  1450. RNODE_FOREACH_RIB (rn, rib)
  1451. {
  1452. if (first)
  1453. {
  1454. vty_out (vty, SHOW_ROUTE_V4_HEADER);
  1455. first = 0;
  1456. }
  1457. vty_show_ip_route (vty, rn, rib);
  1458. }
  1459. return CMD_SUCCESS;
  1460. }
  1461. ALIAS (show_ip_route,
  1462. show_ip_route_vrf_cmd,
  1463. "show ip route " VRF_CMD_STR,
  1464. SHOW_STR
  1465. IP_STR
  1466. "IP routing table\n"
  1467. VRF_CMD_HELP_STR)
  1468. DEFUN (show_ip_route_prefix_longer,
  1469. show_ip_route_prefix_longer_cmd,
  1470. "show ip route A.B.C.D/M longer-prefixes",
  1471. SHOW_STR
  1472. IP_STR
  1473. "IP routing table\n"
  1474. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1475. "Show route matching the specified Network/Mask pair only\n")
  1476. {
  1477. struct route_table *table;
  1478. struct route_node *rn;
  1479. struct rib *rib;
  1480. struct prefix p;
  1481. int ret;
  1482. int first = 1;
  1483. vrf_id_t vrf_id = VRF_DEFAULT;
  1484. ret = str2prefix (argv[0], &p);
  1485. if (! ret)
  1486. {
  1487. vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
  1488. return CMD_WARNING;
  1489. }
  1490. if (argc > 1)
  1491. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
  1492. table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
  1493. if (! table)
  1494. return CMD_SUCCESS;
  1495. /* Show matched type IPv4 routes. */
  1496. for (rn = route_top (table); rn; rn = route_next (rn))
  1497. RNODE_FOREACH_RIB (rn, rib)
  1498. if (prefix_match (&p, &rn->p))
  1499. {
  1500. if (first)
  1501. {
  1502. vty_out (vty, SHOW_ROUTE_V4_HEADER);
  1503. first = 0;
  1504. }
  1505. vty_show_ip_route (vty, rn, rib);
  1506. }
  1507. return CMD_SUCCESS;
  1508. }
  1509. ALIAS (show_ip_route_prefix_longer,
  1510. show_ip_route_prefix_longer_vrf_cmd,
  1511. "show ip route A.B.C.D/M longer-prefixes " VRF_CMD_STR,
  1512. SHOW_STR
  1513. IP_STR
  1514. "IP routing table\n"
  1515. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1516. "Show route matching the specified Network/Mask pair only\n"
  1517. VRF_CMD_HELP_STR)
  1518. DEFUN (show_ip_route_supernets,
  1519. show_ip_route_supernets_cmd,
  1520. "show ip route supernets-only",
  1521. SHOW_STR
  1522. IP_STR
  1523. "IP routing table\n"
  1524. "Show supernet entries only\n")
  1525. {
  1526. struct route_table *table;
  1527. struct route_node *rn;
  1528. struct rib *rib;
  1529. u_int32_t addr;
  1530. int first = 1;
  1531. vrf_id_t vrf_id = VRF_DEFAULT;
  1532. if (argc > 0)
  1533. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
  1534. table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
  1535. if (! table)
  1536. return CMD_SUCCESS;
  1537. /* Show matched type IPv4 routes. */
  1538. for (rn = route_top (table); rn; rn = route_next (rn))
  1539. RNODE_FOREACH_RIB (rn, rib)
  1540. {
  1541. addr = ntohl (rn->p.u.prefix4.s_addr);
  1542. if ((IN_CLASSC (addr) && rn->p.prefixlen < 24)
  1543. || (IN_CLASSB (addr) && rn->p.prefixlen < 16)
  1544. || (IN_CLASSA (addr) && rn->p.prefixlen < 8))
  1545. {
  1546. if (first)
  1547. {
  1548. vty_out (vty, SHOW_ROUTE_V4_HEADER);
  1549. first = 0;
  1550. }
  1551. vty_show_ip_route (vty, rn, rib);
  1552. }
  1553. }
  1554. return CMD_SUCCESS;
  1555. }
  1556. ALIAS (show_ip_route_supernets,
  1557. show_ip_route_supernets_vrf_cmd,
  1558. "show ip route supernets-only " VRF_CMD_STR,
  1559. SHOW_STR
  1560. IP_STR
  1561. "IP routing table\n"
  1562. "Show supernet entries only\n"
  1563. VRF_CMD_HELP_STR)
  1564. DEFUN (show_ip_route_protocol,
  1565. show_ip_route_protocol_cmd,
  1566. "show ip route " QUAGGA_IP_REDIST_STR_ZEBRA,
  1567. SHOW_STR
  1568. IP_STR
  1569. "IP routing table\n"
  1570. QUAGGA_IP_REDIST_HELP_STR_ZEBRA)
  1571. {
  1572. int type;
  1573. struct route_table *table;
  1574. struct route_node *rn;
  1575. struct rib *rib;
  1576. int first = 1;
  1577. vrf_id_t vrf_id = VRF_DEFAULT;
  1578. type = proto_redistnum (AFI_IP, argv[0]);
  1579. if (type < 0)
  1580. {
  1581. vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
  1582. return CMD_WARNING;
  1583. }
  1584. if (argc > 1)
  1585. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
  1586. table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
  1587. if (! table)
  1588. return CMD_SUCCESS;
  1589. /* Show matched type IPv4 routes. */
  1590. for (rn = route_top (table); rn; rn = route_next (rn))
  1591. RNODE_FOREACH_RIB (rn, rib)
  1592. if (rib->type == type)
  1593. {
  1594. if (first)
  1595. {
  1596. vty_out (vty, SHOW_ROUTE_V4_HEADER);
  1597. first = 0;
  1598. }
  1599. vty_show_ip_route (vty, rn, rib);
  1600. }
  1601. return CMD_SUCCESS;
  1602. }
  1603. ALIAS (show_ip_route_protocol,
  1604. show_ip_route_protocol_vrf_cmd,
  1605. "show ip route " QUAGGA_IP_REDIST_STR_ZEBRA " " VRF_CMD_STR,
  1606. SHOW_STR
  1607. IP_STR
  1608. "IP routing table\n"
  1609. QUAGGA_IP_REDIST_HELP_STR_ZEBRA
  1610. VRF_CMD_HELP_STR)
  1611. DEFUN (show_ip_route_addr,
  1612. show_ip_route_addr_cmd,
  1613. "show ip route A.B.C.D",
  1614. SHOW_STR
  1615. IP_STR
  1616. "IP routing table\n"
  1617. "Network in the IP routing table to display\n")
  1618. {
  1619. int ret;
  1620. struct prefix_ipv4 p;
  1621. struct route_table *table;
  1622. struct route_node *rn;
  1623. vrf_id_t vrf_id = VRF_DEFAULT;
  1624. ret = str2prefix_ipv4 (argv[0], &p);
  1625. if (ret <= 0)
  1626. {
  1627. vty_out (vty, "%% Malformed IPv4 address%s", VTY_NEWLINE);
  1628. return CMD_WARNING;
  1629. }
  1630. if (argc > 1)
  1631. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
  1632. table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
  1633. if (! table)
  1634. return CMD_SUCCESS;
  1635. rn = route_node_match (table, (struct prefix *) &p);
  1636. if (! rn)
  1637. {
  1638. vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
  1639. return CMD_WARNING;
  1640. }
  1641. vty_show_ip_route_detail (vty, rn, 0);
  1642. route_unlock_node (rn);
  1643. return CMD_SUCCESS;
  1644. }
  1645. ALIAS (show_ip_route_addr,
  1646. show_ip_route_addr_vrf_cmd,
  1647. "show ip route A.B.C.D " VRF_CMD_STR,
  1648. SHOW_STR
  1649. IP_STR
  1650. "IP routing table\n"
  1651. "Network in the IP routing table to display\n"
  1652. VRF_CMD_HELP_STR)
  1653. DEFUN (show_ip_route_prefix,
  1654. show_ip_route_prefix_cmd,
  1655. "show ip route A.B.C.D/M",
  1656. SHOW_STR
  1657. IP_STR
  1658. "IP routing table\n"
  1659. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
  1660. {
  1661. int ret;
  1662. struct prefix_ipv4 p;
  1663. struct route_table *table;
  1664. struct route_node *rn;
  1665. vrf_id_t vrf_id = VRF_DEFAULT;
  1666. ret = str2prefix_ipv4 (argv[0], &p);
  1667. if (ret <= 0)
  1668. {
  1669. vty_out (vty, "%% Malformed IPv4 address%s", VTY_NEWLINE);
  1670. return CMD_WARNING;
  1671. }
  1672. if (argc > 1)
  1673. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
  1674. table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
  1675. if (! table)
  1676. return CMD_SUCCESS;
  1677. rn = route_node_match (table, (struct prefix *) &p);
  1678. if (! rn || rn->p.prefixlen != p.prefixlen)
  1679. {
  1680. vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
  1681. if (rn)
  1682. route_unlock_node (rn);
  1683. return CMD_WARNING;
  1684. }
  1685. vty_show_ip_route_detail (vty, rn, 0);
  1686. route_unlock_node (rn);
  1687. return CMD_SUCCESS;
  1688. }
  1689. ALIAS (show_ip_route_prefix,
  1690. show_ip_route_prefix_vrf_cmd,
  1691. "show ip route A.B.C.D/M " VRF_CMD_STR,
  1692. SHOW_STR
  1693. IP_STR
  1694. "IP routing table\n"
  1695. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1696. VRF_CMD_HELP_STR)
  1697. static void
  1698. vty_show_ip_route_summary (struct vty *vty, struct route_table *table)
  1699. {
  1700. struct route_node *rn;
  1701. struct rib *rib;
  1702. struct nexthop *nexthop;
  1703. #define ZEBRA_ROUTE_IBGP ZEBRA_ROUTE_MAX
  1704. #define ZEBRA_ROUTE_TOTAL (ZEBRA_ROUTE_IBGP + 1)
  1705. u_int32_t rib_cnt[ZEBRA_ROUTE_TOTAL + 1];
  1706. u_int32_t fib_cnt[ZEBRA_ROUTE_TOTAL + 1];
  1707. u_int32_t i;
  1708. memset (&rib_cnt, 0, sizeof(rib_cnt));
  1709. memset (&fib_cnt, 0, sizeof(fib_cnt));
  1710. for (rn = route_top (table); rn; rn = route_next (rn))
  1711. RNODE_FOREACH_RIB (rn, rib)
  1712. for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
  1713. {
  1714. rib_cnt[ZEBRA_ROUTE_TOTAL]++;
  1715. rib_cnt[rib->type]++;
  1716. if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
  1717. || nexthop_has_fib_child(nexthop))
  1718. {
  1719. fib_cnt[ZEBRA_ROUTE_TOTAL]++;
  1720. fib_cnt[rib->type]++;
  1721. }
  1722. if (rib->type == ZEBRA_ROUTE_BGP &&
  1723. CHECK_FLAG (rib->flags, ZEBRA_FLAG_IBGP))
  1724. {
  1725. rib_cnt[ZEBRA_ROUTE_IBGP]++;
  1726. if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
  1727. || nexthop_has_fib_child(nexthop))
  1728. fib_cnt[ZEBRA_ROUTE_IBGP]++;
  1729. }
  1730. }
  1731. vty_out (vty, "%-20s %-20s %s (vrf %u)%s",
  1732. "Route Source", "Routes", "FIB",
  1733. ((rib_table_info_t *)table->info)->zvrf->vrf_id,
  1734. VTY_NEWLINE);
  1735. for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
  1736. {
  1737. if (rib_cnt[i] > 0)
  1738. {
  1739. if (i == ZEBRA_ROUTE_BGP)
  1740. {
  1741. vty_out (vty, "%-20s %-20d %-20d %s", "ebgp",
  1742. rib_cnt[ZEBRA_ROUTE_BGP] - rib_cnt[ZEBRA_ROUTE_IBGP],
  1743. fib_cnt[ZEBRA_ROUTE_BGP] - fib_cnt[ZEBRA_ROUTE_IBGP],
  1744. VTY_NEWLINE);
  1745. vty_out (vty, "%-20s %-20d %-20d %s", "ibgp",
  1746. rib_cnt[ZEBRA_ROUTE_IBGP], fib_cnt[ZEBRA_ROUTE_IBGP],
  1747. VTY_NEWLINE);
  1748. }
  1749. else
  1750. vty_out (vty, "%-20s %-20d %-20d %s", zebra_route_string(i),
  1751. rib_cnt[i], fib_cnt[i], VTY_NEWLINE);
  1752. }
  1753. }
  1754. vty_out (vty, "------%s", VTY_NEWLINE);
  1755. vty_out (vty, "%-20s %-20d %-20d %s", "Totals", rib_cnt[ZEBRA_ROUTE_TOTAL],
  1756. fib_cnt[ZEBRA_ROUTE_TOTAL], VTY_NEWLINE);
  1757. vty_out (vty, "%s", VTY_NEWLINE);
  1758. }
  1759. /*
  1760. * Implementation of the ip route summary prefix command.
  1761. *
  1762. * This command prints the primary prefixes that have been installed by various
  1763. * protocols on the box.
  1764. *
  1765. */
  1766. static void
  1767. vty_show_ip_route_summary_prefix (struct vty *vty, struct route_table *table)
  1768. {
  1769. struct route_node *rn;
  1770. struct rib *rib;
  1771. struct nexthop *nexthop;
  1772. #define ZEBRA_ROUTE_IBGP ZEBRA_ROUTE_MAX
  1773. #define ZEBRA_ROUTE_TOTAL (ZEBRA_ROUTE_IBGP + 1)
  1774. u_int32_t rib_cnt[ZEBRA_ROUTE_TOTAL + 1];
  1775. u_int32_t fib_cnt[ZEBRA_ROUTE_TOTAL + 1];
  1776. u_int32_t i;
  1777. int cnt;
  1778. memset (&rib_cnt, 0, sizeof(rib_cnt));
  1779. memset (&fib_cnt, 0, sizeof(fib_cnt));
  1780. for (rn = route_top (table); rn; rn = route_next (rn))
  1781. RNODE_FOREACH_RIB (rn, rib)
  1782. {
  1783. /*
  1784. * In case of ECMP, count only once.
  1785. */
  1786. cnt = 0;
  1787. for (nexthop = rib->nexthop; (!cnt && nexthop); nexthop = nexthop->next)
  1788. {
  1789. cnt++;
  1790. rib_cnt[ZEBRA_ROUTE_TOTAL]++;
  1791. rib_cnt[rib->type]++;
  1792. if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB))
  1793. {
  1794. fib_cnt[ZEBRA_ROUTE_TOTAL]++;
  1795. fib_cnt[rib->type]++;
  1796. }
  1797. if (rib->type == ZEBRA_ROUTE_BGP &&
  1798. CHECK_FLAG (rib->flags, ZEBRA_FLAG_IBGP))
  1799. {
  1800. rib_cnt[ZEBRA_ROUTE_IBGP]++;
  1801. if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB))
  1802. fib_cnt[ZEBRA_ROUTE_IBGP]++;
  1803. }
  1804. }
  1805. }
  1806. vty_out (vty, "%-20s %-20s %s (vrf %u)%s",
  1807. "Route Source", "Prefix Routes", "FIB",
  1808. ((rib_table_info_t *)table->info)->zvrf->vrf_id,
  1809. VTY_NEWLINE);
  1810. for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
  1811. {
  1812. if (rib_cnt[i] > 0)
  1813. {
  1814. if (i == ZEBRA_ROUTE_BGP)
  1815. {
  1816. vty_out (vty, "%-20s %-20d %-20d %s", "ebgp",
  1817. rib_cnt[ZEBRA_ROUTE_BGP] - rib_cnt[ZEBRA_ROUTE_IBGP],
  1818. fib_cnt[ZEBRA_ROUTE_BGP] - fib_cnt[ZEBRA_ROUTE_IBGP],
  1819. VTY_NEWLINE);
  1820. vty_out (vty, "%-20s %-20d %-20d %s", "ibgp",
  1821. rib_cnt[ZEBRA_ROUTE_IBGP], fib_cnt[ZEBRA_ROUTE_IBGP],
  1822. VTY_NEWLINE);
  1823. }
  1824. else
  1825. vty_out (vty, "%-20s %-20d %-20d %s", zebra_route_string(i),
  1826. rib_cnt[i], fib_cnt[i], VTY_NEWLINE);
  1827. }
  1828. }
  1829. vty_out (vty, "------%s", VTY_NEWLINE);
  1830. vty_out (vty, "%-20s %-20d %-20d %s", "Totals", rib_cnt[ZEBRA_ROUTE_TOTAL],
  1831. fib_cnt[ZEBRA_ROUTE_TOTAL], VTY_NEWLINE);
  1832. vty_out (vty, "%s", VTY_NEWLINE);
  1833. }
  1834. /* Show route summary. */
  1835. DEFUN (show_ip_route_summary,
  1836. show_ip_route_summary_cmd,
  1837. "show ip route summary",
  1838. SHOW_STR
  1839. IP_STR
  1840. "IP routing table\n"
  1841. "Summary of all routes\n")
  1842. {
  1843. struct route_table *table;
  1844. vrf_id_t vrf_id = VRF_DEFAULT;
  1845. if (argc > 0)
  1846. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
  1847. table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
  1848. if (! table)
  1849. return CMD_SUCCESS;
  1850. vty_show_ip_route_summary (vty, table);
  1851. return CMD_SUCCESS;
  1852. }
  1853. ALIAS (show_ip_route_summary,
  1854. show_ip_route_summary_vrf_cmd,
  1855. "show ip route summary " VRF_CMD_STR,
  1856. SHOW_STR
  1857. IP_STR
  1858. "IP routing table\n"
  1859. "Summary of all routes\n"
  1860. VRF_CMD_HELP_STR)
  1861. /* Show route summary prefix. */
  1862. DEFUN (show_ip_route_summary_prefix,
  1863. show_ip_route_summary_prefix_cmd,
  1864. "show ip route summary prefix",
  1865. SHOW_STR
  1866. IP_STR
  1867. "IP routing table\n"
  1868. "Summary of all routes\n"
  1869. "Prefix routes\n")
  1870. {
  1871. struct route_table *table;
  1872. vrf_id_t vrf_id = VRF_DEFAULT;
  1873. if (argc > 0)
  1874. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
  1875. table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
  1876. if (! table)
  1877. return CMD_SUCCESS;
  1878. vty_show_ip_route_summary_prefix (vty, table);
  1879. return CMD_SUCCESS;
  1880. }
  1881. ALIAS (show_ip_route_summary_prefix,
  1882. show_ip_route_summary_prefix_vrf_cmd,
  1883. "show ip route summary prefix " VRF_CMD_STR,
  1884. SHOW_STR
  1885. IP_STR
  1886. "IP routing table\n"
  1887. "Summary of all routes\n"
  1888. "Prefix routes\n"
  1889. VRF_CMD_HELP_STR)
  1890. DEFUN (show_ip_route_vrf_all,
  1891. show_ip_route_vrf_all_cmd,
  1892. "show ip route " VRF_ALL_CMD_STR,
  1893. SHOW_STR
  1894. IP_STR
  1895. "IP routing table\n"
  1896. VRF_ALL_CMD_HELP_STR)
  1897. {
  1898. struct route_table *table;
  1899. struct route_node *rn;
  1900. struct rib *rib;
  1901. struct zebra_vrf *zvrf;
  1902. vrf_iter_t iter;
  1903. int first = 1;
  1904. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  1905. {
  1906. if ((zvrf = vrf_iter2info (iter)) == NULL ||
  1907. (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL)
  1908. continue;
  1909. /* Show all IPv4 routes. */
  1910. for (rn = route_top (table); rn; rn = route_next (rn))
  1911. RNODE_FOREACH_RIB (rn, rib)
  1912. {
  1913. if (first)
  1914. {
  1915. vty_out (vty, SHOW_ROUTE_V4_HEADER);
  1916. first = 0;
  1917. }
  1918. vty_show_ip_route (vty, rn, rib);
  1919. }
  1920. }
  1921. return CMD_SUCCESS;
  1922. }
  1923. DEFUN (show_ip_route_prefix_longer_vrf_all,
  1924. show_ip_route_prefix_longer_vrf_all_cmd,
  1925. "show ip route A.B.C.D/M longer-prefixes " VRF_ALL_CMD_STR,
  1926. SHOW_STR
  1927. IP_STR
  1928. "IP routing table\n"
  1929. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1930. "Show route matching the specified Network/Mask pair only\n"
  1931. VRF_ALL_CMD_HELP_STR)
  1932. {
  1933. struct route_table *table;
  1934. struct route_node *rn;
  1935. struct rib *rib;
  1936. struct prefix p;
  1937. struct zebra_vrf *zvrf;
  1938. vrf_iter_t iter;
  1939. int ret;
  1940. int first = 1;
  1941. ret = str2prefix (argv[0], &p);
  1942. if (! ret)
  1943. {
  1944. vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
  1945. return CMD_WARNING;
  1946. }
  1947. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  1948. {
  1949. if ((zvrf = vrf_iter2info (iter)) == NULL ||
  1950. (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL)
  1951. continue;
  1952. /* Show matched type IPv4 routes. */
  1953. for (rn = route_top (table); rn; rn = route_next (rn))
  1954. RNODE_FOREACH_RIB (rn, rib)
  1955. if (prefix_match (&p, &rn->p))
  1956. {
  1957. if (first)
  1958. {
  1959. vty_out (vty, SHOW_ROUTE_V4_HEADER);
  1960. first = 0;
  1961. }
  1962. vty_show_ip_route (vty, rn, rib);
  1963. }
  1964. }
  1965. return CMD_SUCCESS;
  1966. }
  1967. DEFUN (show_ip_route_supernets_vrf_all,
  1968. show_ip_route_supernets_vrf_all_cmd,
  1969. "show ip route supernets-only " VRF_ALL_CMD_STR,
  1970. SHOW_STR
  1971. IP_STR
  1972. "IP routing table\n"
  1973. "Show supernet entries only\n"
  1974. VRF_ALL_CMD_HELP_STR)
  1975. {
  1976. struct route_table *table;
  1977. struct route_node *rn;
  1978. struct rib *rib;
  1979. struct zebra_vrf *zvrf;
  1980. vrf_iter_t iter;
  1981. u_int32_t addr;
  1982. int first = 1;
  1983. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  1984. {
  1985. if ((zvrf = vrf_iter2info (iter)) == NULL ||
  1986. (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL)
  1987. continue;
  1988. /* Show matched type IPv4 routes. */
  1989. for (rn = route_top (table); rn; rn = route_next (rn))
  1990. RNODE_FOREACH_RIB (rn, rib)
  1991. {
  1992. addr = ntohl (rn->p.u.prefix4.s_addr);
  1993. if ((IN_CLASSC (addr) && rn->p.prefixlen < 24)
  1994. || (IN_CLASSB (addr) && rn->p.prefixlen < 16)
  1995. || (IN_CLASSA (addr) && rn->p.prefixlen < 8))
  1996. {
  1997. if (first)
  1998. {
  1999. vty_out (vty, SHOW_ROUTE_V4_HEADER);
  2000. first = 0;
  2001. }
  2002. vty_show_ip_route (vty, rn, rib);
  2003. }
  2004. }
  2005. }
  2006. return CMD_SUCCESS;
  2007. }
  2008. DEFUN (show_ip_route_protocol_vrf_all,
  2009. show_ip_route_protocol_vrf_all_cmd,
  2010. "show ip route " QUAGGA_IP_REDIST_STR_ZEBRA " " VRF_ALL_CMD_STR,
  2011. SHOW_STR
  2012. IP_STR
  2013. "IP routing table\n"
  2014. QUAGGA_IP_REDIST_HELP_STR_ZEBRA
  2015. VRF_ALL_CMD_HELP_STR)
  2016. {
  2017. int type;
  2018. struct route_table *table;
  2019. struct route_node *rn;
  2020. struct rib *rib;
  2021. struct zebra_vrf *zvrf;
  2022. vrf_iter_t iter;
  2023. int first = 1;
  2024. type = proto_redistnum (AFI_IP, argv[0]);
  2025. if (type < 0)
  2026. {
  2027. vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
  2028. return CMD_WARNING;
  2029. }
  2030. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  2031. {
  2032. if ((zvrf = vrf_iter2info (iter)) == NULL ||
  2033. (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL)
  2034. continue;
  2035. /* Show matched type IPv4 routes. */
  2036. for (rn = route_top (table); rn; rn = route_next (rn))
  2037. RNODE_FOREACH_RIB (rn, rib)
  2038. if (rib->type == type)
  2039. {
  2040. if (first)
  2041. {
  2042. vty_out (vty, SHOW_ROUTE_V4_HEADER);
  2043. first = 0;
  2044. }
  2045. vty_show_ip_route (vty, rn, rib);
  2046. }
  2047. }
  2048. return CMD_SUCCESS;
  2049. }
  2050. DEFUN (show_ip_route_addr_vrf_all,
  2051. show_ip_route_addr_vrf_all_cmd,
  2052. "show ip route A.B.C.D " VRF_ALL_CMD_STR,
  2053. SHOW_STR
  2054. IP_STR
  2055. "IP routing table\n"
  2056. "Network in the IP routing table to display\n"
  2057. VRF_ALL_CMD_HELP_STR)
  2058. {
  2059. int ret;
  2060. struct prefix_ipv4 p;
  2061. struct route_table *table;
  2062. struct route_node *rn;
  2063. struct zebra_vrf *zvrf;
  2064. vrf_iter_t iter;
  2065. ret = str2prefix_ipv4 (argv[0], &p);
  2066. if (ret <= 0)
  2067. {
  2068. vty_out (vty, "%% Malformed IPv4 address%s", VTY_NEWLINE);
  2069. return CMD_WARNING;
  2070. }
  2071. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  2072. {
  2073. if ((zvrf = vrf_iter2info (iter)) == NULL ||
  2074. (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL)
  2075. continue;
  2076. rn = route_node_match (table, (struct prefix *) &p);
  2077. if (! rn)
  2078. continue;
  2079. vty_show_ip_route_detail (vty, rn, 0);
  2080. route_unlock_node (rn);
  2081. }
  2082. return CMD_SUCCESS;
  2083. }
  2084. DEFUN (show_ip_route_prefix_vrf_all,
  2085. show_ip_route_prefix_vrf_all_cmd,
  2086. "show ip route A.B.C.D/M " VRF_ALL_CMD_STR,
  2087. SHOW_STR
  2088. IP_STR
  2089. "IP routing table\n"
  2090. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  2091. VRF_ALL_CMD_HELP_STR)
  2092. {
  2093. int ret;
  2094. struct prefix_ipv4 p;
  2095. struct route_table *table;
  2096. struct route_node *rn;
  2097. struct zebra_vrf *zvrf;
  2098. vrf_iter_t iter;
  2099. ret = str2prefix_ipv4 (argv[0], &p);
  2100. if (ret <= 0)
  2101. {
  2102. vty_out (vty, "%% Malformed IPv4 address%s", VTY_NEWLINE);
  2103. return CMD_WARNING;
  2104. }
  2105. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  2106. {
  2107. if ((zvrf = vrf_iter2info (iter)) == NULL ||
  2108. (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL)
  2109. continue;
  2110. rn = route_node_match (table, (struct prefix *) &p);
  2111. if (! rn)
  2112. continue;
  2113. if (rn->p.prefixlen != p.prefixlen)
  2114. {
  2115. route_unlock_node (rn);
  2116. continue;
  2117. }
  2118. vty_show_ip_route_detail (vty, rn, 0);
  2119. route_unlock_node (rn);
  2120. }
  2121. return CMD_SUCCESS;
  2122. }
  2123. DEFUN (show_ip_route_summary_vrf_all,
  2124. show_ip_route_summary_vrf_all_cmd,
  2125. "show ip route summary " VRF_ALL_CMD_STR,
  2126. SHOW_STR
  2127. IP_STR
  2128. "IP routing table\n"
  2129. "Summary of all routes\n"
  2130. VRF_ALL_CMD_HELP_STR)
  2131. {
  2132. struct zebra_vrf *zvrf;
  2133. vrf_iter_t iter;
  2134. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  2135. if ((zvrf = vrf_iter2info (iter)) != NULL)
  2136. vty_show_ip_route_summary (vty, zvrf->table[AFI_IP][SAFI_UNICAST]);
  2137. return CMD_SUCCESS;
  2138. }
  2139. DEFUN (show_ip_route_summary_prefix_vrf_all,
  2140. show_ip_route_summary_prefix_vrf_all_cmd,
  2141. "show ip route summary prefix " VRF_ALL_CMD_STR,
  2142. SHOW_STR
  2143. IP_STR
  2144. "IP routing table\n"
  2145. "Summary of all routes\n"
  2146. "Prefix routes\n"
  2147. VRF_ALL_CMD_HELP_STR)
  2148. {
  2149. struct zebra_vrf *zvrf;
  2150. vrf_iter_t iter;
  2151. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  2152. if ((zvrf = vrf_iter2info (iter)) != NULL)
  2153. vty_show_ip_route_summary_prefix (vty, zvrf->table[AFI_IP][SAFI_UNICAST]);
  2154. return CMD_SUCCESS;
  2155. }
  2156. /* Write IPv4 static route configuration. */
  2157. static int
  2158. static_config_ipv4 (struct vty *vty, safi_t safi, const char *cmd)
  2159. {
  2160. struct route_node *rn;
  2161. struct static_ipv4 *si;
  2162. struct route_table *stable;
  2163. struct zebra_vrf *zvrf;
  2164. vrf_iter_t iter;
  2165. int write;
  2166. write = 0;
  2167. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  2168. {
  2169. if ((zvrf = vrf_iter2info (iter)) == NULL ||
  2170. (stable = zvrf->stable[AFI_IP][safi]) == NULL)
  2171. continue;
  2172. for (rn = route_top (stable); rn; rn = route_next (rn))
  2173. for (si = rn->info; si; si = si->next)
  2174. {
  2175. vty_out (vty, "%s %s/%d", cmd, inet_ntoa (rn->p.u.prefix4),
  2176. rn->p.prefixlen);
  2177. switch (si->type)
  2178. {
  2179. case STATIC_IPV4_GATEWAY:
  2180. vty_out (vty, " %s", inet_ntoa (si->gate.ipv4));
  2181. break;
  2182. case STATIC_IPV4_IFNAME:
  2183. vty_out (vty, " %s", si->gate.ifname);
  2184. break;
  2185. case STATIC_IPV4_BLACKHOLE:
  2186. vty_out (vty, " Null0");
  2187. break;
  2188. }
  2189. /* flags are incompatible with STATIC_IPV4_BLACKHOLE */
  2190. if (si->type != STATIC_IPV4_BLACKHOLE)
  2191. {
  2192. if (CHECK_FLAG(si->flags, ZEBRA_FLAG_REJECT))
  2193. vty_out (vty, " %s", "reject");
  2194. if (CHECK_FLAG(si->flags, ZEBRA_FLAG_BLACKHOLE))
  2195. vty_out (vty, " %s", "blackhole");
  2196. }
  2197. if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT)
  2198. vty_out (vty, " %d", si->distance);
  2199. if (si->vrf_id != VRF_DEFAULT)
  2200. vty_out (vty, " vrf %u", si->vrf_id);
  2201. vty_out (vty, "%s", VTY_NEWLINE);
  2202. write = 1;
  2203. }
  2204. }
  2205. return write;
  2206. }
  2207. DEFUN (show_ip_protocol,
  2208. show_ip_protocol_cmd,
  2209. "show ip protocol",
  2210. SHOW_STR
  2211. IP_STR
  2212. "IP protocol filtering status\n")
  2213. {
  2214. int i;
  2215. vty_out(vty, "Protocol : route-map %s", VTY_NEWLINE);
  2216. vty_out(vty, "------------------------%s", VTY_NEWLINE);
  2217. for (i=0;i<ZEBRA_ROUTE_MAX;i++)
  2218. {
  2219. if (proto_rm[AFI_IP][i])
  2220. vty_out (vty, "%-10s : %-10s%s", zebra_route_string(i),
  2221. proto_rm[AFI_IP][i],
  2222. VTY_NEWLINE);
  2223. else
  2224. vty_out (vty, "%-10s : none%s", zebra_route_string(i), VTY_NEWLINE);
  2225. }
  2226. if (proto_rm[AFI_IP][i])
  2227. vty_out (vty, "%-10s : %-10s%s", "any", proto_rm[AFI_IP][i],
  2228. VTY_NEWLINE);
  2229. else
  2230. vty_out (vty, "%-10s : none%s", "any", VTY_NEWLINE);
  2231. return CMD_SUCCESS;
  2232. }
  2233. /*
  2234. * Show IP mroute command to dump the BGP Multicast
  2235. * routing table
  2236. */
  2237. DEFUN (show_ip_mroute,
  2238. show_ip_mroute_cmd,
  2239. "show ip mroute",
  2240. SHOW_STR
  2241. IP_STR
  2242. "IP Multicast routing table\n")
  2243. {
  2244. struct route_table *table;
  2245. struct route_node *rn;
  2246. struct rib *rib;
  2247. int first = 1;
  2248. vrf_id_t vrf_id = VRF_DEFAULT;
  2249. if (argc > 0)
  2250. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
  2251. table = zebra_vrf_table (AFI_IP, SAFI_MULTICAST, vrf_id);
  2252. if (! table)
  2253. return CMD_SUCCESS;
  2254. /* Show all IPv4 routes. */
  2255. for (rn = route_top (table); rn; rn = route_next (rn))
  2256. RNODE_FOREACH_RIB (rn, rib)
  2257. {
  2258. if (first)
  2259. {
  2260. vty_out (vty, SHOW_ROUTE_V4_HEADER);
  2261. first = 0;
  2262. }
  2263. vty_show_ip_route (vty, rn, rib);
  2264. }
  2265. return CMD_SUCCESS;
  2266. }
  2267. ALIAS (show_ip_mroute,
  2268. show_ip_mroute_vrf_cmd,
  2269. "show ip mroute " VRF_CMD_STR,
  2270. SHOW_STR
  2271. IP_STR
  2272. "IP Multicast routing table\n"
  2273. VRF_CMD_HELP_STR)
  2274. DEFUN (show_ip_mroute_vrf_all,
  2275. show_ip_mroute_vrf_all_cmd,
  2276. "show ip mroute " VRF_ALL_CMD_STR,
  2277. SHOW_STR
  2278. IP_STR
  2279. "IP Multicast routing table\n"
  2280. VRF_ALL_CMD_HELP_STR)
  2281. {
  2282. struct route_table *table;
  2283. struct route_node *rn;
  2284. struct rib *rib;
  2285. struct zebra_vrf *zvrf;
  2286. vrf_iter_t iter;
  2287. int first = 1;
  2288. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  2289. {
  2290. if ((zvrf = vrf_iter2info (iter)) == NULL ||
  2291. (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL)
  2292. continue;
  2293. /* Show all IPv4 routes. */
  2294. for (rn = route_top (table); rn; rn = route_next (rn))
  2295. RNODE_FOREACH_RIB (rn, rib)
  2296. {
  2297. if (first)
  2298. {
  2299. vty_out (vty, SHOW_ROUTE_V4_HEADER);
  2300. first = 0;
  2301. }
  2302. vty_show_ip_route (vty, rn, rib);
  2303. }
  2304. }
  2305. return CMD_SUCCESS;
  2306. }
  2307. #ifdef HAVE_IPV6
  2308. /* General fucntion for IPv6 static route. */
  2309. static int
  2310. static_ipv6_func (struct vty *vty, int add_cmd, const char *dest_str,
  2311. const char *gate_str, const char *ifname,
  2312. const char *flag_str, const char *distance_str,
  2313. const char *vrf_id_str)
  2314. {
  2315. int ret;
  2316. u_char distance;
  2317. struct prefix p;
  2318. struct in6_addr *gate = NULL;
  2319. struct in6_addr gate_addr;
  2320. u_char type = 0;
  2321. vrf_id_t vrf_id = VRF_DEFAULT;
  2322. u_char flag = 0;
  2323. ret = str2prefix (dest_str, &p);
  2324. if (ret <= 0)
  2325. {
  2326. vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
  2327. return CMD_WARNING;
  2328. }
  2329. /* Apply mask for given prefix. */
  2330. apply_mask (&p);
  2331. /* Route flags */
  2332. if (flag_str) {
  2333. switch(flag_str[0]) {
  2334. case 'r':
  2335. case 'R': /* XXX */
  2336. SET_FLAG (flag, ZEBRA_FLAG_REJECT);
  2337. break;
  2338. case 'b':
  2339. case 'B': /* XXX */
  2340. SET_FLAG (flag, ZEBRA_FLAG_BLACKHOLE);
  2341. break;
  2342. default:
  2343. vty_out (vty, "%% Malformed flag %s %s", flag_str, VTY_NEWLINE);
  2344. return CMD_WARNING;
  2345. }
  2346. }
  2347. /* Administrative distance. */
  2348. if (distance_str)
  2349. distance = atoi (distance_str);
  2350. else
  2351. distance = ZEBRA_STATIC_DISTANCE_DEFAULT;
  2352. /* When gateway is valid IPv6 addrees, then gate is treated as
  2353. nexthop address other case gate is treated as interface name. */
  2354. ret = inet_pton (AF_INET6, gate_str, &gate_addr);
  2355. if (ifname)
  2356. {
  2357. /* When ifname is specified. It must be come with gateway
  2358. address. */
  2359. if (ret != 1)
  2360. {
  2361. vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
  2362. return CMD_WARNING;
  2363. }
  2364. type = STATIC_IPV6_GATEWAY_IFNAME;
  2365. gate = &gate_addr;
  2366. }
  2367. else
  2368. {
  2369. if (ret == 1)
  2370. {
  2371. type = STATIC_IPV6_GATEWAY;
  2372. gate = &gate_addr;
  2373. }
  2374. else
  2375. {
  2376. type = STATIC_IPV6_IFNAME;
  2377. ifname = gate_str;
  2378. }
  2379. }
  2380. /* VRF id */
  2381. if (vrf_id_str)
  2382. VTY_GET_INTEGER ("VRF ID", vrf_id, vrf_id_str);
  2383. if (add_cmd)
  2384. static_add_ipv6 (&p, type, gate, ifname, flag, distance, vrf_id);
  2385. else
  2386. static_delete_ipv6 (&p, type, gate, ifname, distance, vrf_id);
  2387. return CMD_SUCCESS;
  2388. }
  2389. DEFUN (ipv6_route,
  2390. ipv6_route_cmd,
  2391. "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)",
  2392. IP_STR
  2393. "Establish static routes\n"
  2394. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2395. "IPv6 gateway address\n"
  2396. "IPv6 gateway interface name\n")
  2397. {
  2398. return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, NULL, NULL,
  2399. NULL);
  2400. }
  2401. DEFUN (ipv6_route_flags,
  2402. ipv6_route_flags_cmd,
  2403. "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole)",
  2404. IP_STR
  2405. "Establish static routes\n"
  2406. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2407. "IPv6 gateway address\n"
  2408. "IPv6 gateway interface name\n"
  2409. "Emit an ICMP unreachable when matched\n"
  2410. "Silently discard pkts when matched\n")
  2411. {
  2412. return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, argv[2], NULL,
  2413. NULL);
  2414. }
  2415. DEFUN (ipv6_route_ifname,
  2416. ipv6_route_ifname_cmd,
  2417. "ipv6 route X:X::X:X/M X:X::X:X INTERFACE",
  2418. IP_STR
  2419. "Establish static routes\n"
  2420. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2421. "IPv6 gateway address\n"
  2422. "IPv6 gateway interface name\n")
  2423. {
  2424. return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], NULL, NULL,
  2425. NULL);
  2426. }
  2427. DEFUN (ipv6_route_ifname_flags,
  2428. ipv6_route_ifname_flags_cmd,
  2429. "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole)",
  2430. IP_STR
  2431. "Establish static routes\n"
  2432. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2433. "IPv6 gateway address\n"
  2434. "IPv6 gateway interface name\n"
  2435. "Emit an ICMP unreachable when matched\n"
  2436. "Silently discard pkts when matched\n")
  2437. {
  2438. return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], argv[3], NULL,
  2439. NULL);
  2440. }
  2441. DEFUN (ipv6_route_pref,
  2442. ipv6_route_pref_cmd,
  2443. "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
  2444. IP_STR
  2445. "Establish static routes\n"
  2446. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2447. "IPv6 gateway address\n"
  2448. "IPv6 gateway interface name\n"
  2449. "Distance value for this prefix\n")
  2450. {
  2451. return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, NULL, argv[2],
  2452. NULL);
  2453. }
  2454. DEFUN (ipv6_route_flags_pref,
  2455. ipv6_route_flags_pref_cmd,
  2456. "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255>",
  2457. IP_STR
  2458. "Establish static routes\n"
  2459. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2460. "IPv6 gateway address\n"
  2461. "IPv6 gateway interface name\n"
  2462. "Emit an ICMP unreachable when matched\n"
  2463. "Silently discard pkts when matched\n"
  2464. "Distance value for this prefix\n")
  2465. {
  2466. return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, argv[2], argv[3],
  2467. NULL);
  2468. }
  2469. DEFUN (ipv6_route_ifname_pref,
  2470. ipv6_route_ifname_pref_cmd,
  2471. "ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
  2472. IP_STR
  2473. "Establish static routes\n"
  2474. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2475. "IPv6 gateway address\n"
  2476. "IPv6 gateway interface name\n"
  2477. "Distance value for this prefix\n")
  2478. {
  2479. return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], NULL, argv[3],
  2480. NULL);
  2481. }
  2482. DEFUN (ipv6_route_ifname_flags_pref,
  2483. ipv6_route_ifname_flags_pref_cmd,
  2484. "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255>",
  2485. IP_STR
  2486. "Establish static routes\n"
  2487. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2488. "IPv6 gateway address\n"
  2489. "IPv6 gateway interface name\n"
  2490. "Emit an ICMP unreachable when matched\n"
  2491. "Silently discard pkts when matched\n"
  2492. "Distance value for this prefix\n")
  2493. {
  2494. return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], argv[3], argv[4],
  2495. NULL);
  2496. }
  2497. DEFUN (no_ipv6_route,
  2498. no_ipv6_route_cmd,
  2499. "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)",
  2500. NO_STR
  2501. IP_STR
  2502. "Establish static routes\n"
  2503. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2504. "IPv6 gateway address\n"
  2505. "IPv6 gateway interface name\n")
  2506. {
  2507. return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, NULL, NULL,
  2508. NULL);
  2509. }
  2510. ALIAS (no_ipv6_route,
  2511. no_ipv6_route_flags_cmd,
  2512. "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole)",
  2513. NO_STR
  2514. IP_STR
  2515. "Establish static routes\n"
  2516. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2517. "IPv6 gateway address\n"
  2518. "IPv6 gateway interface name\n"
  2519. "Emit an ICMP unreachable when matched\n"
  2520. "Silently discard pkts when matched\n")
  2521. DEFUN (no_ipv6_route_ifname,
  2522. no_ipv6_route_ifname_cmd,
  2523. "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE",
  2524. NO_STR
  2525. IP_STR
  2526. "Establish static routes\n"
  2527. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2528. "IPv6 gateway address\n"
  2529. "IPv6 gateway interface name\n")
  2530. {
  2531. return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], NULL, NULL,
  2532. NULL);
  2533. }
  2534. ALIAS (no_ipv6_route_ifname,
  2535. no_ipv6_route_ifname_flags_cmd,
  2536. "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole)",
  2537. NO_STR
  2538. IP_STR
  2539. "Establish static routes\n"
  2540. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2541. "IPv6 gateway address\n"
  2542. "IPv6 gateway interface name\n"
  2543. "Emit an ICMP unreachable when matched\n"
  2544. "Silently discard pkts when matched\n")
  2545. DEFUN (no_ipv6_route_pref,
  2546. no_ipv6_route_pref_cmd,
  2547. "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
  2548. NO_STR
  2549. IP_STR
  2550. "Establish static routes\n"
  2551. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2552. "IPv6 gateway address\n"
  2553. "IPv6 gateway interface name\n"
  2554. "Distance value for this prefix\n")
  2555. {
  2556. return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, NULL, argv[2],
  2557. NULL);
  2558. }
  2559. DEFUN (no_ipv6_route_flags_pref,
  2560. no_ipv6_route_flags_pref_cmd,
  2561. "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255>",
  2562. NO_STR
  2563. IP_STR
  2564. "Establish static routes\n"
  2565. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2566. "IPv6 gateway address\n"
  2567. "IPv6 gateway interface name\n"
  2568. "Emit an ICMP unreachable when matched\n"
  2569. "Silently discard pkts when matched\n"
  2570. "Distance value for this prefix\n")
  2571. {
  2572. /* We do not care about argv[2] */
  2573. return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, argv[2], argv[3],
  2574. NULL);
  2575. }
  2576. DEFUN (no_ipv6_route_ifname_pref,
  2577. no_ipv6_route_ifname_pref_cmd,
  2578. "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
  2579. NO_STR
  2580. IP_STR
  2581. "Establish static routes\n"
  2582. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2583. "IPv6 gateway address\n"
  2584. "IPv6 gateway interface name\n"
  2585. "Distance value for this prefix\n")
  2586. {
  2587. return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], NULL, argv[3],
  2588. NULL);
  2589. }
  2590. DEFUN (no_ipv6_route_ifname_flags_pref,
  2591. no_ipv6_route_ifname_flags_pref_cmd,
  2592. "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255>",
  2593. NO_STR
  2594. IP_STR
  2595. "Establish static routes\n"
  2596. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2597. "IPv6 gateway address\n"
  2598. "IPv6 gateway interface name\n"
  2599. "Emit an ICMP unreachable when matched\n"
  2600. "Silently discard pkts when matched\n"
  2601. "Distance value for this prefix\n")
  2602. {
  2603. return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], argv[3], argv[4],
  2604. NULL);
  2605. }
  2606. DEFUN (ipv6_route_vrf,
  2607. ipv6_route_vrf_cmd,
  2608. "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) " VRF_CMD_STR,
  2609. IP_STR
  2610. "Establish static routes\n"
  2611. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2612. "IPv6 gateway address\n"
  2613. "IPv6 gateway interface name\n"
  2614. VRF_CMD_HELP_STR)
  2615. {
  2616. return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, NULL, NULL,
  2617. argv[2]);
  2618. }
  2619. DEFUN (ipv6_route_flags_vrf,
  2620. ipv6_route_flags_vrf_cmd,
  2621. "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) " VRF_CMD_STR,
  2622. IP_STR
  2623. "Establish static routes\n"
  2624. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2625. "IPv6 gateway address\n"
  2626. "IPv6 gateway interface name\n"
  2627. "Emit an ICMP unreachable when matched\n"
  2628. "Silently discard pkts when matched\n"
  2629. VRF_CMD_HELP_STR)
  2630. {
  2631. return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, argv[2], NULL,
  2632. argv[3]);
  2633. }
  2634. DEFUN (ipv6_route_ifname_vrf,
  2635. ipv6_route_ifname_vrf_cmd,
  2636. "ipv6 route X:X::X:X/M X:X::X:X INTERFACE " VRF_CMD_STR,
  2637. IP_STR
  2638. "Establish static routes\n"
  2639. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2640. "IPv6 gateway address\n"
  2641. "IPv6 gateway interface name\n"
  2642. VRF_CMD_HELP_STR)
  2643. {
  2644. return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], NULL, NULL,
  2645. argv[3]);
  2646. }
  2647. DEFUN (ipv6_route_ifname_flags_vrf,
  2648. ipv6_route_ifname_flags_vrf_cmd,
  2649. "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) " VRF_CMD_STR,
  2650. IP_STR
  2651. "Establish static routes\n"
  2652. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2653. "IPv6 gateway address\n"
  2654. "IPv6 gateway interface name\n"
  2655. "Emit an ICMP unreachable when matched\n"
  2656. "Silently discard pkts when matched\n"
  2657. VRF_CMD_HELP_STR)
  2658. {
  2659. return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], argv[3], NULL,
  2660. argv[4]);
  2661. }
  2662. DEFUN (ipv6_route_pref_vrf,
  2663. ipv6_route_pref_vrf_cmd,
  2664. "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255> " VRF_CMD_STR,
  2665. IP_STR
  2666. "Establish static routes\n"
  2667. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2668. "IPv6 gateway address\n"
  2669. "IPv6 gateway interface name\n"
  2670. "Distance value for this prefix\n"
  2671. VRF_CMD_HELP_STR)
  2672. {
  2673. return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, NULL, argv[2],
  2674. argv[3]);
  2675. }
  2676. DEFUN (ipv6_route_flags_pref_vrf,
  2677. ipv6_route_flags_pref_vrf_cmd,
  2678. "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255> " VRF_CMD_STR,
  2679. IP_STR
  2680. "Establish static routes\n"
  2681. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2682. "IPv6 gateway address\n"
  2683. "IPv6 gateway interface name\n"
  2684. "Emit an ICMP unreachable when matched\n"
  2685. "Silently discard pkts when matched\n"
  2686. "Distance value for this prefix\n"
  2687. VRF_CMD_HELP_STR)
  2688. {
  2689. return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, argv[2], argv[3],
  2690. argv[4]);
  2691. }
  2692. DEFUN (ipv6_route_ifname_pref_vrf,
  2693. ipv6_route_ifname_pref_vrf_cmd,
  2694. "ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255> " VRF_CMD_STR,
  2695. IP_STR
  2696. "Establish static routes\n"
  2697. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2698. "IPv6 gateway address\n"
  2699. "IPv6 gateway interface name\n"
  2700. "Distance value for this prefix\n"
  2701. VRF_CMD_HELP_STR)
  2702. {
  2703. return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], NULL, argv[3],
  2704. argv[4]);
  2705. }
  2706. DEFUN (ipv6_route_ifname_flags_pref_vrf,
  2707. ipv6_route_ifname_flags_pref_vrf_cmd,
  2708. "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255> " VRF_CMD_STR,
  2709. IP_STR
  2710. "Establish static routes\n"
  2711. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2712. "IPv6 gateway address\n"
  2713. "IPv6 gateway interface name\n"
  2714. "Emit an ICMP unreachable when matched\n"
  2715. "Silently discard pkts when matched\n"
  2716. "Distance value for this prefix\n"
  2717. VRF_CMD_HELP_STR)
  2718. {
  2719. return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], argv[3], argv[4],
  2720. argv[5]);
  2721. }
  2722. DEFUN (no_ipv6_route_vrf,
  2723. no_ipv6_route_vrf_cmd,
  2724. "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) " VRF_CMD_STR,
  2725. NO_STR
  2726. IP_STR
  2727. "Establish static routes\n"
  2728. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2729. "IPv6 gateway address\n"
  2730. "IPv6 gateway interface name\n"
  2731. VRF_CMD_HELP_STR)
  2732. {
  2733. return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, NULL, NULL,
  2734. (argc > 3) ? argv[3] : argv[2]);
  2735. }
  2736. ALIAS (no_ipv6_route_vrf,
  2737. no_ipv6_route_flags_vrf_cmd,
  2738. "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) " VRF_CMD_STR,
  2739. NO_STR
  2740. IP_STR
  2741. "Establish static routes\n"
  2742. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2743. "IPv6 gateway address\n"
  2744. "IPv6 gateway interface name\n"
  2745. "Emit an ICMP unreachable when matched\n"
  2746. "Silently discard pkts when matched\n"
  2747. VRF_CMD_HELP_STR)
  2748. DEFUN (no_ipv6_route_ifname_vrf,
  2749. no_ipv6_route_ifname_vrf_cmd,
  2750. "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE " VRF_CMD_STR,
  2751. NO_STR
  2752. IP_STR
  2753. "Establish static routes\n"
  2754. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2755. "IPv6 gateway address\n"
  2756. "IPv6 gateway interface name\n"
  2757. VRF_CMD_HELP_STR)
  2758. {
  2759. return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], NULL, NULL,
  2760. (argc > 4) ? argv[4] : argv[3]);
  2761. }
  2762. ALIAS (no_ipv6_route_ifname_vrf,
  2763. no_ipv6_route_ifname_flags_vrf_cmd,
  2764. "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) " VRF_CMD_STR,
  2765. NO_STR
  2766. IP_STR
  2767. "Establish static routes\n"
  2768. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2769. "IPv6 gateway address\n"
  2770. "IPv6 gateway interface name\n"
  2771. "Emit an ICMP unreachable when matched\n"
  2772. "Silently discard pkts when matched\n"
  2773. VRF_CMD_HELP_STR)
  2774. DEFUN (no_ipv6_route_pref_vrf,
  2775. no_ipv6_route_pref_vrf_cmd,
  2776. "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255> " VRF_CMD_STR,
  2777. NO_STR
  2778. IP_STR
  2779. "Establish static routes\n"
  2780. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2781. "IPv6 gateway address\n"
  2782. "IPv6 gateway interface name\n"
  2783. "Distance value for this prefix\n"
  2784. VRF_CMD_HELP_STR)
  2785. {
  2786. return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, NULL, argv[2],
  2787. argv[3]);
  2788. }
  2789. DEFUN (no_ipv6_route_flags_pref_vrf,
  2790. no_ipv6_route_flags_pref_vrf_cmd,
  2791. "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255> " VRF_CMD_STR,
  2792. NO_STR
  2793. IP_STR
  2794. "Establish static routes\n"
  2795. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2796. "IPv6 gateway address\n"
  2797. "IPv6 gateway interface name\n"
  2798. "Emit an ICMP unreachable when matched\n"
  2799. "Silently discard pkts when matched\n"
  2800. "Distance value for this prefix\n"
  2801. VRF_CMD_HELP_STR)
  2802. {
  2803. /* We do not care about argv[2] */
  2804. return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, argv[2], argv[3],
  2805. argv[4]);
  2806. }
  2807. DEFUN (no_ipv6_route_ifname_pref_vrf,
  2808. no_ipv6_route_ifname_pref_vrf_cmd,
  2809. "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255> " VRF_CMD_STR,
  2810. NO_STR
  2811. IP_STR
  2812. "Establish static routes\n"
  2813. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2814. "IPv6 gateway address\n"
  2815. "IPv6 gateway interface name\n"
  2816. "Distance value for this prefix\n"
  2817. VRF_CMD_HELP_STR)
  2818. {
  2819. return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], NULL, argv[3],
  2820. argv[4]);
  2821. }
  2822. DEFUN (no_ipv6_route_ifname_flags_pref_vrf,
  2823. no_ipv6_route_ifname_flags_pref_vrf_cmd,
  2824. "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255> " VRF_CMD_STR,
  2825. NO_STR
  2826. IP_STR
  2827. "Establish static routes\n"
  2828. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2829. "IPv6 gateway address\n"
  2830. "IPv6 gateway interface name\n"
  2831. "Emit an ICMP unreachable when matched\n"
  2832. "Silently discard pkts when matched\n"
  2833. "Distance value for this prefix\n"
  2834. VRF_CMD_HELP_STR)
  2835. {
  2836. return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], argv[3], argv[4],
  2837. argv[5]);
  2838. }
  2839. DEFUN (show_ipv6_route,
  2840. show_ipv6_route_cmd,
  2841. "show ipv6 route",
  2842. SHOW_STR
  2843. IP_STR
  2844. "IPv6 routing table\n")
  2845. {
  2846. struct route_table *table;
  2847. struct route_node *rn;
  2848. struct rib *rib;
  2849. int first = 1;
  2850. vrf_id_t vrf_id = VRF_DEFAULT;
  2851. if (argc > 0)
  2852. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
  2853. table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
  2854. if (! table)
  2855. return CMD_SUCCESS;
  2856. /* Show all IPv6 route. */
  2857. for (rn = route_top (table); rn; rn = route_next (rn))
  2858. RNODE_FOREACH_RIB (rn, rib)
  2859. {
  2860. if (first)
  2861. {
  2862. vty_out (vty, SHOW_ROUTE_V6_HEADER);
  2863. first = 0;
  2864. }
  2865. vty_show_ip_route (vty, rn, rib);
  2866. }
  2867. return CMD_SUCCESS;
  2868. }
  2869. ALIAS (show_ipv6_route,
  2870. show_ipv6_route_vrf_cmd,
  2871. "show ipv6 route " VRF_CMD_STR,
  2872. SHOW_STR
  2873. IP_STR
  2874. "IPv6 routing table\n"
  2875. VRF_CMD_HELP_STR)
  2876. DEFUN (show_ipv6_route_prefix_longer,
  2877. show_ipv6_route_prefix_longer_cmd,
  2878. "show ipv6 route X:X::X:X/M longer-prefixes",
  2879. SHOW_STR
  2880. IP_STR
  2881. "IPv6 routing table\n"
  2882. "IPv6 prefix\n"
  2883. "Show route matching the specified Network/Mask pair only\n")
  2884. {
  2885. struct route_table *table;
  2886. struct route_node *rn;
  2887. struct rib *rib;
  2888. struct prefix p;
  2889. int ret;
  2890. int first = 1;
  2891. vrf_id_t vrf_id = VRF_DEFAULT;
  2892. ret = str2prefix (argv[0], &p);
  2893. if (! ret)
  2894. {
  2895. vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
  2896. return CMD_WARNING;
  2897. }
  2898. if (argc > 1)
  2899. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
  2900. table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
  2901. if (! table)
  2902. return CMD_SUCCESS;
  2903. /* Show matched type IPv6 routes. */
  2904. for (rn = route_top (table); rn; rn = route_next (rn))
  2905. RNODE_FOREACH_RIB (rn, rib)
  2906. if (prefix_match (&p, &rn->p))
  2907. {
  2908. if (first)
  2909. {
  2910. vty_out (vty, SHOW_ROUTE_V6_HEADER);
  2911. first = 0;
  2912. }
  2913. vty_show_ip_route (vty, rn, rib);
  2914. }
  2915. return CMD_SUCCESS;
  2916. }
  2917. ALIAS (show_ipv6_route_prefix_longer,
  2918. show_ipv6_route_prefix_longer_vrf_cmd,
  2919. "show ipv6 route X:X::X:X/M longer-prefixes " VRF_CMD_STR,
  2920. SHOW_STR
  2921. IP_STR
  2922. "IPv6 routing table\n"
  2923. "IPv6 prefix\n"
  2924. "Show route matching the specified Network/Mask pair only\n"
  2925. VRF_CMD_HELP_STR)
  2926. DEFUN (show_ipv6_route_protocol,
  2927. show_ipv6_route_protocol_cmd,
  2928. "show ipv6 route " QUAGGA_IP6_REDIST_STR_ZEBRA,
  2929. SHOW_STR
  2930. IP_STR
  2931. "IP routing table\n"
  2932. QUAGGA_IP6_REDIST_HELP_STR_ZEBRA)
  2933. {
  2934. int type;
  2935. struct route_table *table;
  2936. struct route_node *rn;
  2937. struct rib *rib;
  2938. int first = 1;
  2939. vrf_id_t vrf_id = VRF_DEFAULT;
  2940. type = proto_redistnum (AFI_IP6, argv[0]);
  2941. if (type < 0)
  2942. {
  2943. vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
  2944. return CMD_WARNING;
  2945. }
  2946. if (argc > 1)
  2947. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
  2948. table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
  2949. if (! table)
  2950. return CMD_SUCCESS;
  2951. /* Show matched type IPv6 routes. */
  2952. for (rn = route_top (table); rn; rn = route_next (rn))
  2953. RNODE_FOREACH_RIB (rn, rib)
  2954. if (rib->type == type)
  2955. {
  2956. if (first)
  2957. {
  2958. vty_out (vty, SHOW_ROUTE_V6_HEADER);
  2959. first = 0;
  2960. }
  2961. vty_show_ip_route (vty, rn, rib);
  2962. }
  2963. return CMD_SUCCESS;
  2964. }
  2965. ALIAS (show_ipv6_route_protocol,
  2966. show_ipv6_route_protocol_vrf_cmd,
  2967. "show ipv6 route " QUAGGA_IP6_REDIST_STR_ZEBRA " " VRF_CMD_STR,
  2968. SHOW_STR
  2969. IP_STR
  2970. "IP routing table\n"
  2971. QUAGGA_IP6_REDIST_HELP_STR_ZEBRA
  2972. VRF_CMD_HELP_STR)
  2973. DEFUN (show_ipv6_route_addr,
  2974. show_ipv6_route_addr_cmd,
  2975. "show ipv6 route X:X::X:X",
  2976. SHOW_STR
  2977. IP_STR
  2978. "IPv6 routing table\n"
  2979. "IPv6 Address\n")
  2980. {
  2981. int ret;
  2982. struct prefix_ipv6 p;
  2983. struct route_table *table;
  2984. struct route_node *rn;
  2985. vrf_id_t vrf_id = VRF_DEFAULT;
  2986. ret = str2prefix_ipv6 (argv[0], &p);
  2987. if (ret <= 0)
  2988. {
  2989. vty_out (vty, "Malformed IPv6 address%s", VTY_NEWLINE);
  2990. return CMD_WARNING;
  2991. }
  2992. if (argc > 1)
  2993. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
  2994. table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
  2995. if (! table)
  2996. return CMD_SUCCESS;
  2997. rn = route_node_match (table, (struct prefix *) &p);
  2998. if (! rn)
  2999. {
  3000. vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
  3001. return CMD_WARNING;
  3002. }
  3003. vty_show_ip_route_detail (vty, rn, 0);
  3004. route_unlock_node (rn);
  3005. return CMD_SUCCESS;
  3006. }
  3007. ALIAS (show_ipv6_route_addr,
  3008. show_ipv6_route_addr_vrf_cmd,
  3009. "show ipv6 route X:X::X:X " VRF_CMD_STR,
  3010. SHOW_STR
  3011. IP_STR
  3012. "IPv6 routing table\n"
  3013. "IPv6 Address\n"
  3014. VRF_CMD_HELP_STR)
  3015. DEFUN (show_ipv6_route_prefix,
  3016. show_ipv6_route_prefix_cmd,
  3017. "show ipv6 route X:X::X:X/M",
  3018. SHOW_STR
  3019. IP_STR
  3020. "IPv6 routing table\n"
  3021. "IPv6 prefix\n")
  3022. {
  3023. int ret;
  3024. struct prefix_ipv6 p;
  3025. struct route_table *table;
  3026. struct route_node *rn;
  3027. vrf_id_t vrf_id = VRF_DEFAULT;
  3028. ret = str2prefix_ipv6 (argv[0], &p);
  3029. if (ret <= 0)
  3030. {
  3031. vty_out (vty, "Malformed IPv6 prefix%s", VTY_NEWLINE);
  3032. return CMD_WARNING;
  3033. }
  3034. if (argc > 1)
  3035. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
  3036. table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
  3037. if (! table)
  3038. return CMD_SUCCESS;
  3039. rn = route_node_match (table, (struct prefix *) &p);
  3040. if (! rn || rn->p.prefixlen != p.prefixlen)
  3041. {
  3042. vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
  3043. if (rn)
  3044. route_unlock_node (rn);
  3045. return CMD_WARNING;
  3046. }
  3047. vty_show_ip_route_detail (vty, rn, 0);
  3048. route_unlock_node (rn);
  3049. return CMD_SUCCESS;
  3050. }
  3051. ALIAS (show_ipv6_route_prefix,
  3052. show_ipv6_route_prefix_vrf_cmd,
  3053. "show ipv6 route X:X::X:X/M " VRF_CMD_STR,
  3054. SHOW_STR
  3055. IP_STR
  3056. "IPv6 routing table\n"
  3057. "IPv6 prefix\n"
  3058. VRF_CMD_HELP_STR)
  3059. /* Show route summary. */
  3060. DEFUN (show_ipv6_route_summary,
  3061. show_ipv6_route_summary_cmd,
  3062. "show ipv6 route summary",
  3063. SHOW_STR
  3064. IP_STR
  3065. "IPv6 routing table\n"
  3066. "Summary of all IPv6 routes\n")
  3067. {
  3068. struct route_table *table;
  3069. vrf_id_t vrf_id = VRF_DEFAULT;
  3070. if (argc > 0)
  3071. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
  3072. table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
  3073. if (! table)
  3074. return CMD_SUCCESS;
  3075. vty_show_ip_route_summary (vty, table);
  3076. return CMD_SUCCESS;
  3077. }
  3078. ALIAS (show_ipv6_route_summary,
  3079. show_ipv6_route_summary_vrf_cmd,
  3080. "show ipv6 route summary " VRF_CMD_STR,
  3081. SHOW_STR
  3082. IP_STR
  3083. "IPv6 routing table\n"
  3084. "Summary of all IPv6 routes\n"
  3085. VRF_CMD_HELP_STR)
  3086. /* Show ipv6 route summary prefix. */
  3087. DEFUN (show_ipv6_route_summary_prefix,
  3088. show_ipv6_route_summary_prefix_cmd,
  3089. "show ipv6 route summary prefix",
  3090. SHOW_STR
  3091. IP_STR
  3092. "IPv6 routing table\n"
  3093. "Summary of all IPv6 routes\n"
  3094. "Prefix routes\n")
  3095. {
  3096. struct route_table *table;
  3097. vrf_id_t vrf_id = VRF_DEFAULT;
  3098. if (argc > 0)
  3099. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
  3100. table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
  3101. if (! table)
  3102. return CMD_SUCCESS;
  3103. vty_show_ip_route_summary_prefix (vty, table);
  3104. return CMD_SUCCESS;
  3105. }
  3106. ALIAS (show_ipv6_route_summary_prefix,
  3107. show_ipv6_route_summary_prefix_vrf_cmd,
  3108. "show ipv6 route summary prefix " VRF_CMD_STR,
  3109. SHOW_STR
  3110. IP_STR
  3111. "IPv6 routing table\n"
  3112. "Summary of all IPv6 routes\n"
  3113. "Prefix routes\n"
  3114. VRF_CMD_HELP_STR)
  3115. /*
  3116. * Show IPv6 mroute command.Used to dump
  3117. * the Multicast routing table.
  3118. */
  3119. DEFUN (show_ipv6_mroute,
  3120. show_ipv6_mroute_cmd,
  3121. "show ipv6 mroute",
  3122. SHOW_STR
  3123. IP_STR
  3124. "IPv6 Multicast routing table\n")
  3125. {
  3126. struct route_table *table;
  3127. struct route_node *rn;
  3128. struct rib *rib;
  3129. int first = 1;
  3130. vrf_id_t vrf_id = VRF_DEFAULT;
  3131. if (argc > 0)
  3132. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
  3133. table = zebra_vrf_table (AFI_IP6, SAFI_MULTICAST, vrf_id);
  3134. if (! table)
  3135. return CMD_SUCCESS;
  3136. /* Show all IPv6 route. */
  3137. for (rn = route_top (table); rn; rn = route_next (rn))
  3138. RNODE_FOREACH_RIB (rn, rib)
  3139. {
  3140. if (first)
  3141. {
  3142. vty_out (vty, SHOW_ROUTE_V6_HEADER);
  3143. first = 0;
  3144. }
  3145. vty_show_ip_route (vty, rn, rib);
  3146. }
  3147. return CMD_SUCCESS;
  3148. }
  3149. ALIAS (show_ipv6_mroute,
  3150. show_ipv6_mroute_vrf_cmd,
  3151. "show ipv6 mroute " VRF_CMD_STR,
  3152. SHOW_STR
  3153. IP_STR
  3154. "IPv6 Multicast routing table\n"
  3155. VRF_CMD_HELP_STR)
  3156. DEFUN (show_ipv6_route_vrf_all,
  3157. show_ipv6_route_vrf_all_cmd,
  3158. "show ipv6 route " VRF_ALL_CMD_STR,
  3159. SHOW_STR
  3160. IP_STR
  3161. "IPv6 routing table\n"
  3162. VRF_ALL_CMD_HELP_STR)
  3163. {
  3164. struct route_table *table;
  3165. struct route_node *rn;
  3166. struct rib *rib;
  3167. struct zebra_vrf *zvrf;
  3168. vrf_iter_t iter;
  3169. int first = 1;
  3170. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  3171. {
  3172. if ((zvrf = vrf_iter2info (iter)) == NULL ||
  3173. (table = zvrf->table[AFI_IP6][SAFI_UNICAST]) == NULL)
  3174. continue;
  3175. /* Show all IPv6 route. */
  3176. for (rn = route_top (table); rn; rn = route_next (rn))
  3177. RNODE_FOREACH_RIB (rn, rib)
  3178. {
  3179. if (first)
  3180. {
  3181. vty_out (vty, SHOW_ROUTE_V6_HEADER);
  3182. first = 0;
  3183. }
  3184. vty_show_ip_route (vty, rn, rib);
  3185. }
  3186. }
  3187. return CMD_SUCCESS;
  3188. }
  3189. DEFUN (show_ipv6_route_prefix_longer_vrf_all,
  3190. show_ipv6_route_prefix_longer_vrf_all_cmd,
  3191. "show ipv6 route X:X::X:X/M longer-prefixes " VRF_ALL_CMD_STR,
  3192. SHOW_STR
  3193. IP_STR
  3194. "IPv6 routing table\n"
  3195. "IPv6 prefix\n"
  3196. "Show route matching the specified Network/Mask pair only\n"
  3197. VRF_ALL_CMD_HELP_STR)
  3198. {
  3199. struct route_table *table;
  3200. struct route_node *rn;
  3201. struct rib *rib;
  3202. struct prefix p;
  3203. struct zebra_vrf *zvrf;
  3204. vrf_iter_t iter;
  3205. int ret;
  3206. int first = 1;
  3207. ret = str2prefix (argv[0], &p);
  3208. if (! ret)
  3209. {
  3210. vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
  3211. return CMD_WARNING;
  3212. }
  3213. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  3214. {
  3215. if ((zvrf = vrf_iter2info (iter)) == NULL ||
  3216. (table = zvrf->table[AFI_IP6][SAFI_UNICAST]) == NULL)
  3217. continue;
  3218. /* Show matched type IPv6 routes. */
  3219. for (rn = route_top (table); rn; rn = route_next (rn))
  3220. RNODE_FOREACH_RIB (rn, rib)
  3221. if (prefix_match (&p, &rn->p))
  3222. {
  3223. if (first)
  3224. {
  3225. vty_out (vty, SHOW_ROUTE_V6_HEADER);
  3226. first = 0;
  3227. }
  3228. vty_show_ip_route (vty, rn, rib);
  3229. }
  3230. }
  3231. return CMD_SUCCESS;
  3232. }
  3233. DEFUN (show_ipv6_route_protocol_vrf_all,
  3234. show_ipv6_route_protocol_vrf_all_cmd,
  3235. "show ipv6 route " QUAGGA_IP6_REDIST_STR_ZEBRA " " VRF_ALL_CMD_STR,
  3236. SHOW_STR
  3237. IP_STR
  3238. "IP routing table\n"
  3239. QUAGGA_IP6_REDIST_HELP_STR_ZEBRA
  3240. VRF_ALL_CMD_HELP_STR)
  3241. {
  3242. int type;
  3243. struct route_table *table;
  3244. struct route_node *rn;
  3245. struct rib *rib;
  3246. struct zebra_vrf *zvrf;
  3247. vrf_iter_t iter;
  3248. int first = 1;
  3249. type = proto_redistnum (AFI_IP6, argv[0]);
  3250. if (type < 0)
  3251. {
  3252. vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
  3253. return CMD_WARNING;
  3254. }
  3255. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  3256. {
  3257. if ((zvrf = vrf_iter2info (iter)) == NULL ||
  3258. (table = zvrf->table[AFI_IP6][SAFI_UNICAST]) == NULL)
  3259. continue;
  3260. /* Show matched type IPv6 routes. */
  3261. for (rn = route_top (table); rn; rn = route_next (rn))
  3262. RNODE_FOREACH_RIB (rn, rib)
  3263. if (rib->type == type)
  3264. {
  3265. if (first)
  3266. {
  3267. vty_out (vty, SHOW_ROUTE_V6_HEADER);
  3268. first = 0;
  3269. }
  3270. vty_show_ip_route (vty, rn, rib);
  3271. }
  3272. }
  3273. return CMD_SUCCESS;
  3274. }
  3275. DEFUN (show_ipv6_route_addr_vrf_all,
  3276. show_ipv6_route_addr_vrf_all_cmd,
  3277. "show ipv6 route X:X::X:X " VRF_ALL_CMD_STR,
  3278. SHOW_STR
  3279. IP_STR
  3280. "IPv6 routing table\n"
  3281. "IPv6 Address\n"
  3282. VRF_ALL_CMD_HELP_STR)
  3283. {
  3284. int ret;
  3285. struct prefix_ipv6 p;
  3286. struct route_table *table;
  3287. struct route_node *rn;
  3288. struct zebra_vrf *zvrf;
  3289. vrf_iter_t iter;
  3290. ret = str2prefix_ipv6 (argv[0], &p);
  3291. if (ret <= 0)
  3292. {
  3293. vty_out (vty, "Malformed IPv6 address%s", VTY_NEWLINE);
  3294. return CMD_WARNING;
  3295. }
  3296. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  3297. {
  3298. if ((zvrf = vrf_iter2info (iter)) == NULL ||
  3299. (table = zvrf->table[AFI_IP6][SAFI_UNICAST]) == NULL)
  3300. continue;
  3301. rn = route_node_match (table, (struct prefix *) &p);
  3302. if (! rn)
  3303. continue;
  3304. vty_show_ip_route_detail (vty, rn, 0);
  3305. route_unlock_node (rn);
  3306. }
  3307. return CMD_SUCCESS;
  3308. }
  3309. DEFUN (show_ipv6_route_prefix_vrf_all,
  3310. show_ipv6_route_prefix_vrf_all_cmd,
  3311. "show ipv6 route X:X::X:X/M " VRF_ALL_CMD_STR,
  3312. SHOW_STR
  3313. IP_STR
  3314. "IPv6 routing table\n"
  3315. "IPv6 prefix\n"
  3316. VRF_ALL_CMD_HELP_STR)
  3317. {
  3318. int ret;
  3319. struct prefix_ipv6 p;
  3320. struct route_table *table;
  3321. struct route_node *rn;
  3322. struct zebra_vrf *zvrf;
  3323. vrf_iter_t iter;
  3324. ret = str2prefix_ipv6 (argv[0], &p);
  3325. if (ret <= 0)
  3326. {
  3327. vty_out (vty, "Malformed IPv6 prefix%s", VTY_NEWLINE);
  3328. return CMD_WARNING;
  3329. }
  3330. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  3331. {
  3332. if ((zvrf = vrf_iter2info (iter)) == NULL ||
  3333. (table = zvrf->table[AFI_IP6][SAFI_UNICAST]) == NULL)
  3334. continue;
  3335. rn = route_node_match (table, (struct prefix *) &p);
  3336. if (! rn)
  3337. continue;
  3338. if (rn->p.prefixlen != p.prefixlen)
  3339. {
  3340. route_unlock_node (rn);
  3341. continue;
  3342. }
  3343. vty_show_ip_route_detail (vty, rn, 0);
  3344. route_unlock_node (rn);
  3345. }
  3346. return CMD_SUCCESS;
  3347. }
  3348. /* Show route summary. */
  3349. DEFUN (show_ipv6_route_summary_vrf_all,
  3350. show_ipv6_route_summary_vrf_all_cmd,
  3351. "show ipv6 route summary " VRF_ALL_CMD_STR,
  3352. SHOW_STR
  3353. IP_STR
  3354. "IPv6 routing table\n"
  3355. "Summary of all IPv6 routes\n"
  3356. VRF_ALL_CMD_HELP_STR)
  3357. {
  3358. struct zebra_vrf *zvrf;
  3359. vrf_iter_t iter;
  3360. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  3361. if ((zvrf = vrf_iter2info (iter)) != NULL)
  3362. vty_show_ip_route_summary (vty, zvrf->table[AFI_IP6][SAFI_UNICAST]);
  3363. return CMD_SUCCESS;
  3364. }
  3365. DEFUN (show_ipv6_mroute_vrf_all,
  3366. show_ipv6_mroute_vrf_all_cmd,
  3367. "show ipv6 mroute " VRF_ALL_CMD_STR,
  3368. SHOW_STR
  3369. IP_STR
  3370. "IPv6 Multicast routing table\n"
  3371. VRF_ALL_CMD_HELP_STR)
  3372. {
  3373. struct route_table *table;
  3374. struct route_node *rn;
  3375. struct rib *rib;
  3376. struct zebra_vrf *zvrf;
  3377. vrf_iter_t iter;
  3378. int first = 1;
  3379. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  3380. {
  3381. if ((zvrf = vrf_iter2info (iter)) == NULL ||
  3382. (table = zvrf->table[AFI_IP6][SAFI_UNICAST]) == NULL)
  3383. continue;
  3384. /* Show all IPv6 route. */
  3385. for (rn = route_top (table); rn; rn = route_next (rn))
  3386. RNODE_FOREACH_RIB (rn, rib)
  3387. {
  3388. if (first)
  3389. {
  3390. vty_out (vty, SHOW_ROUTE_V6_HEADER);
  3391. first = 0;
  3392. }
  3393. vty_show_ip_route (vty, rn, rib);
  3394. }
  3395. }
  3396. return CMD_SUCCESS;
  3397. }
  3398. DEFUN (show_ipv6_route_summary_prefix_vrf_all,
  3399. show_ipv6_route_summary_prefix_vrf_all_cmd,
  3400. "show ipv6 route summary prefix " VRF_ALL_CMD_STR,
  3401. SHOW_STR
  3402. IP_STR
  3403. "IPv6 routing table\n"
  3404. "Summary of all IPv6 routes\n"
  3405. "Prefix routes\n"
  3406. VRF_ALL_CMD_HELP_STR)
  3407. {
  3408. struct zebra_vrf *zvrf;
  3409. vrf_iter_t iter;
  3410. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  3411. if ((zvrf = vrf_iter2info (iter)) != NULL)
  3412. vty_show_ip_route_summary_prefix (vty, zvrf->table[AFI_IP6][SAFI_UNICAST]);
  3413. return CMD_SUCCESS;
  3414. }
  3415. /* Write IPv6 static route configuration. */
  3416. static int
  3417. static_config_ipv6 (struct vty *vty)
  3418. {
  3419. struct route_node *rn;
  3420. struct static_ipv6 *si;
  3421. int write;
  3422. char buf[BUFSIZ];
  3423. struct route_table *stable;
  3424. struct zebra_vrf *zvrf;
  3425. vrf_iter_t iter;
  3426. write = 0;
  3427. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  3428. {
  3429. if ((zvrf = vrf_iter2info (iter)) == NULL ||
  3430. (stable = zvrf->stable[AFI_IP6][SAFI_UNICAST]) == NULL)
  3431. continue;
  3432. for (rn = route_top (stable); rn; rn = route_next (rn))
  3433. for (si = rn->info; si; si = si->next)
  3434. {
  3435. vty_out (vty, "ipv6 route %s", prefix2str (&rn->p, buf, sizeof buf));
  3436. switch (si->type)
  3437. {
  3438. case STATIC_IPV6_GATEWAY:
  3439. vty_out (vty, " %s",
  3440. inet_ntop (AF_INET6, &si->ipv6, buf, BUFSIZ));
  3441. break;
  3442. case STATIC_IPV6_IFNAME:
  3443. vty_out (vty, " %s", si->ifname);
  3444. break;
  3445. case STATIC_IPV6_GATEWAY_IFNAME:
  3446. vty_out (vty, " %s %s",
  3447. inet_ntop (AF_INET6, &si->ipv6, buf, BUFSIZ),
  3448. si->ifname);
  3449. break;
  3450. }
  3451. if (CHECK_FLAG(si->flags, ZEBRA_FLAG_REJECT))
  3452. vty_out (vty, " %s", "reject");
  3453. if (CHECK_FLAG(si->flags, ZEBRA_FLAG_BLACKHOLE))
  3454. vty_out (vty, " %s", "blackhole");
  3455. if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT)
  3456. vty_out (vty, " %d", si->distance);
  3457. if (si->vrf_id != VRF_DEFAULT)
  3458. vty_out (vty, " vrf %u", si->vrf_id);
  3459. vty_out (vty, "%s", VTY_NEWLINE);
  3460. write = 1;
  3461. }
  3462. }
  3463. return write;
  3464. }
  3465. #endif /* HAVE_IPV6 */
  3466. /* Static ip route configuration write function. */
  3467. static int
  3468. zebra_ip_config (struct vty *vty)
  3469. {
  3470. int write = 0;
  3471. write += static_config_ipv4 (vty, SAFI_UNICAST, "ip route");
  3472. write += static_config_ipv4 (vty, SAFI_MULTICAST, "ip mroute");
  3473. #ifdef HAVE_IPV6
  3474. write += static_config_ipv6 (vty);
  3475. #endif /* HAVE_IPV6 */
  3476. return write;
  3477. }
  3478. static int config_write_vty(struct vty *vty)
  3479. {
  3480. int i;
  3481. enum multicast_mode ipv4_multicast_mode = multicast_mode_ipv4_get ();
  3482. if (ipv4_multicast_mode != MCAST_NO_CONFIG)
  3483. vty_out (vty, "ip multicast rpf-lookup-mode %s%s",
  3484. ipv4_multicast_mode == MCAST_URIB_ONLY ? "urib-only" :
  3485. ipv4_multicast_mode == MCAST_MRIB_ONLY ? "mrib-only" :
  3486. ipv4_multicast_mode == MCAST_MIX_MRIB_FIRST ? "mrib-then-urib" :
  3487. ipv4_multicast_mode == MCAST_MIX_DISTANCE ? "lower-distance" :
  3488. "longer-prefix",
  3489. VTY_NEWLINE);
  3490. for (i=0;i<ZEBRA_ROUTE_MAX;i++)
  3491. {
  3492. if (proto_rm[AFI_IP][i])
  3493. vty_out (vty, "ip protocol %s route-map %s%s", zebra_route_string(i),
  3494. proto_rm[AFI_IP][i], VTY_NEWLINE);
  3495. }
  3496. if (proto_rm[AFI_IP][ZEBRA_ROUTE_MAX])
  3497. vty_out (vty, "ip protocol %s route-map %s%s", "any",
  3498. proto_rm[AFI_IP][ZEBRA_ROUTE_MAX], VTY_NEWLINE);
  3499. return 1;
  3500. }
  3501. /* table node for protocol filtering */
  3502. static struct cmd_node protocol_node = { PROTOCOL_NODE, "", 1 };
  3503. /* IP node for static routes. */
  3504. static struct cmd_node ip_node = { IP_NODE, "", 1 };
  3505. /* Route VTY. */
  3506. void
  3507. zebra_vty_init (void)
  3508. {
  3509. install_node (&ip_node, zebra_ip_config);
  3510. install_node (&protocol_node, config_write_vty);
  3511. install_element (CONFIG_NODE, &ip_mroute_cmd);
  3512. install_element (CONFIG_NODE, &ip_mroute_dist_cmd);
  3513. install_element (CONFIG_NODE, &no_ip_mroute_cmd);
  3514. install_element (CONFIG_NODE, &no_ip_mroute_dist_cmd);
  3515. install_element (CONFIG_NODE, &ip_multicast_mode_cmd);
  3516. install_element (CONFIG_NODE, &no_ip_multicast_mode_cmd);
  3517. install_element (CONFIG_NODE, &no_ip_multicast_mode_noarg_cmd);
  3518. install_element (CONFIG_NODE, &ip_protocol_cmd);
  3519. install_element (CONFIG_NODE, &no_ip_protocol_cmd);
  3520. install_element (VIEW_NODE, &show_ip_protocol_cmd);
  3521. install_element (ENABLE_NODE, &show_ip_protocol_cmd);
  3522. install_element (CONFIG_NODE, &ip_route_cmd);
  3523. install_element (CONFIG_NODE, &ip_route_flags_cmd);
  3524. install_element (CONFIG_NODE, &ip_route_flags2_cmd);
  3525. install_element (CONFIG_NODE, &ip_route_mask_cmd);
  3526. install_element (CONFIG_NODE, &ip_route_mask_flags_cmd);
  3527. install_element (CONFIG_NODE, &ip_route_mask_flags2_cmd);
  3528. install_element (CONFIG_NODE, &no_ip_route_cmd);
  3529. install_element (CONFIG_NODE, &no_ip_route_flags_cmd);
  3530. install_element (CONFIG_NODE, &no_ip_route_flags2_cmd);
  3531. install_element (CONFIG_NODE, &no_ip_route_mask_cmd);
  3532. install_element (CONFIG_NODE, &no_ip_route_mask_flags_cmd);
  3533. install_element (CONFIG_NODE, &no_ip_route_mask_flags2_cmd);
  3534. install_element (CONFIG_NODE, &ip_route_distance_cmd);
  3535. install_element (CONFIG_NODE, &ip_route_flags_distance_cmd);
  3536. install_element (CONFIG_NODE, &ip_route_flags_distance2_cmd);
  3537. install_element (CONFIG_NODE, &ip_route_mask_distance_cmd);
  3538. install_element (CONFIG_NODE, &ip_route_mask_flags_distance_cmd);
  3539. install_element (CONFIG_NODE, &ip_route_mask_flags_distance2_cmd);
  3540. install_element (CONFIG_NODE, &no_ip_route_distance_cmd);
  3541. install_element (CONFIG_NODE, &no_ip_route_flags_distance_cmd);
  3542. install_element (CONFIG_NODE, &no_ip_route_flags_distance2_cmd);
  3543. install_element (CONFIG_NODE, &no_ip_route_mask_flags_distance_cmd);
  3544. install_element (CONFIG_NODE, &no_ip_route_mask_flags_distance2_cmd);
  3545. install_element (VIEW_NODE, &show_ip_route_cmd);
  3546. install_element (VIEW_NODE, &show_ip_route_addr_cmd);
  3547. install_element (VIEW_NODE, &show_ip_route_prefix_cmd);
  3548. install_element (VIEW_NODE, &show_ip_route_prefix_longer_cmd);
  3549. install_element (VIEW_NODE, &show_ip_route_protocol_cmd);
  3550. install_element (VIEW_NODE, &show_ip_route_supernets_cmd);
  3551. install_element (VIEW_NODE, &show_ip_route_summary_cmd);
  3552. install_element (VIEW_NODE, &show_ip_route_summary_prefix_cmd);
  3553. install_element (ENABLE_NODE, &show_ip_route_cmd);
  3554. install_element (ENABLE_NODE, &show_ip_route_addr_cmd);
  3555. install_element (ENABLE_NODE, &show_ip_route_prefix_cmd);
  3556. install_element (ENABLE_NODE, &show_ip_route_prefix_longer_cmd);
  3557. install_element (ENABLE_NODE, &show_ip_route_protocol_cmd);
  3558. install_element (ENABLE_NODE, &show_ip_route_supernets_cmd);
  3559. install_element (ENABLE_NODE, &show_ip_route_summary_cmd);
  3560. install_element (ENABLE_NODE, &show_ip_route_summary_prefix_cmd);
  3561. install_element (VIEW_NODE, &show_ip_mroute_cmd);
  3562. install_element (ENABLE_NODE, &show_ip_mroute_cmd);
  3563. install_element (VIEW_NODE, &show_ip_rpf_cmd);
  3564. install_element (ENABLE_NODE, &show_ip_rpf_cmd);
  3565. install_element (VIEW_NODE, &show_ip_rpf_addr_cmd);
  3566. install_element (ENABLE_NODE, &show_ip_rpf_addr_cmd);
  3567. /* Commands for VRF */
  3568. install_element (CONFIG_NODE, &ip_mroute_vrf_cmd);
  3569. install_element (CONFIG_NODE, &ip_mroute_dist_vrf_cmd);
  3570. install_element (CONFIG_NODE, &no_ip_mroute_vrf_cmd);
  3571. install_element (CONFIG_NODE, &no_ip_mroute_dist_vrf_cmd);
  3572. install_element (CONFIG_NODE, &ip_route_vrf_cmd);
  3573. install_element (CONFIG_NODE, &ip_route_flags_vrf_cmd);
  3574. install_element (CONFIG_NODE, &ip_route_flags2_vrf_cmd);
  3575. install_element (CONFIG_NODE, &ip_route_mask_vrf_cmd);
  3576. install_element (CONFIG_NODE, &ip_route_mask_flags_vrf_cmd);
  3577. install_element (CONFIG_NODE, &ip_route_mask_flags2_vrf_cmd);
  3578. install_element (CONFIG_NODE, &no_ip_route_vrf_cmd);
  3579. install_element (CONFIG_NODE, &no_ip_route_flags_vrf_cmd);
  3580. install_element (CONFIG_NODE, &no_ip_route_flags2_vrf_cmd);
  3581. install_element (CONFIG_NODE, &no_ip_route_mask_vrf_cmd);
  3582. install_element (CONFIG_NODE, &no_ip_route_mask_flags_vrf_cmd);
  3583. install_element (CONFIG_NODE, &no_ip_route_mask_flags2_vrf_cmd);
  3584. install_element (CONFIG_NODE, &ip_route_distance_vrf_cmd);
  3585. install_element (CONFIG_NODE, &ip_route_flags_distance_vrf_cmd);
  3586. install_element (CONFIG_NODE, &ip_route_flags_distance2_vrf_cmd);
  3587. install_element (CONFIG_NODE, &ip_route_mask_distance_vrf_cmd);
  3588. install_element (CONFIG_NODE, &ip_route_mask_flags_distance_vrf_cmd);
  3589. install_element (CONFIG_NODE, &ip_route_mask_flags_distance2_vrf_cmd);
  3590. install_element (CONFIG_NODE, &no_ip_route_distance_vrf_cmd);
  3591. install_element (CONFIG_NODE, &no_ip_route_flags_distance_vrf_cmd);
  3592. install_element (CONFIG_NODE, &no_ip_route_flags_distance2_vrf_cmd);
  3593. install_element (CONFIG_NODE, &no_ip_route_mask_flags_distance_vrf_cmd);
  3594. install_element (CONFIG_NODE, &no_ip_route_mask_flags_distance2_vrf_cmd);
  3595. install_element (VIEW_NODE, &show_ip_route_vrf_cmd);
  3596. install_element (VIEW_NODE, &show_ip_route_addr_vrf_cmd);
  3597. install_element (VIEW_NODE, &show_ip_route_prefix_vrf_cmd);
  3598. install_element (VIEW_NODE, &show_ip_route_prefix_longer_vrf_cmd);
  3599. install_element (VIEW_NODE, &show_ip_route_protocol_vrf_cmd);
  3600. install_element (VIEW_NODE, &show_ip_route_supernets_vrf_cmd);
  3601. install_element (VIEW_NODE, &show_ip_route_summary_vrf_cmd);
  3602. install_element (VIEW_NODE, &show_ip_route_summary_prefix_vrf_cmd);
  3603. install_element (ENABLE_NODE, &show_ip_route_vrf_cmd);
  3604. install_element (ENABLE_NODE, &show_ip_route_addr_vrf_cmd);
  3605. install_element (ENABLE_NODE, &show_ip_route_prefix_vrf_cmd);
  3606. install_element (ENABLE_NODE, &show_ip_route_prefix_longer_vrf_cmd);
  3607. install_element (ENABLE_NODE, &show_ip_route_protocol_vrf_cmd);
  3608. install_element (ENABLE_NODE, &show_ip_route_supernets_vrf_cmd);
  3609. install_element (ENABLE_NODE, &show_ip_route_summary_vrf_cmd);
  3610. install_element (ENABLE_NODE, &show_ip_route_summary_prefix_vrf_cmd);
  3611. install_element (VIEW_NODE, &show_ip_route_vrf_all_cmd);
  3612. install_element (VIEW_NODE, &show_ip_route_addr_vrf_all_cmd);
  3613. install_element (VIEW_NODE, &show_ip_route_prefix_vrf_all_cmd);
  3614. install_element (VIEW_NODE, &show_ip_route_prefix_longer_vrf_all_cmd);
  3615. install_element (VIEW_NODE, &show_ip_route_protocol_vrf_all_cmd);
  3616. install_element (VIEW_NODE, &show_ip_route_supernets_vrf_all_cmd);
  3617. install_element (VIEW_NODE, &show_ip_route_summary_vrf_all_cmd);
  3618. install_element (VIEW_NODE, &show_ip_route_summary_prefix_vrf_all_cmd);
  3619. install_element (ENABLE_NODE, &show_ip_route_vrf_all_cmd);
  3620. install_element (ENABLE_NODE, &show_ip_route_addr_vrf_all_cmd);
  3621. install_element (ENABLE_NODE, &show_ip_route_prefix_vrf_all_cmd);
  3622. install_element (ENABLE_NODE, &show_ip_route_prefix_longer_vrf_all_cmd);
  3623. install_element (ENABLE_NODE, &show_ip_route_protocol_vrf_all_cmd);
  3624. install_element (ENABLE_NODE, &show_ip_route_supernets_vrf_all_cmd);
  3625. install_element (ENABLE_NODE, &show_ip_route_summary_vrf_all_cmd);
  3626. install_element (ENABLE_NODE, &show_ip_route_summary_prefix_vrf_all_cmd);
  3627. install_element (VIEW_NODE, &show_ip_mroute_vrf_cmd);
  3628. install_element (ENABLE_NODE, &show_ip_mroute_vrf_cmd);
  3629. install_element (VIEW_NODE, &show_ip_mroute_vrf_all_cmd);
  3630. install_element (ENABLE_NODE, &show_ip_mroute_vrf_all_cmd);
  3631. install_element (VIEW_NODE, &show_ip_rpf_vrf_cmd);
  3632. install_element (VIEW_NODE, &show_ip_rpf_vrf_all_cmd);
  3633. install_element (VIEW_NODE, &show_ip_rpf_addr_vrf_cmd);
  3634. install_element (VIEW_NODE, &show_ip_rpf_addr_vrf_all_cmd);
  3635. install_element (ENABLE_NODE, &show_ip_rpf_vrf_cmd);
  3636. install_element (ENABLE_NODE, &show_ip_rpf_vrf_all_cmd);
  3637. install_element (ENABLE_NODE, &show_ip_rpf_addr_vrf_cmd);
  3638. install_element (ENABLE_NODE, &show_ip_rpf_addr_vrf_all_cmd);
  3639. #ifdef HAVE_IPV6
  3640. install_element (CONFIG_NODE, &ipv6_route_cmd);
  3641. install_element (CONFIG_NODE, &ipv6_route_flags_cmd);
  3642. install_element (CONFIG_NODE, &ipv6_route_ifname_cmd);
  3643. install_element (CONFIG_NODE, &ipv6_route_ifname_flags_cmd);
  3644. install_element (CONFIG_NODE, &no_ipv6_route_cmd);
  3645. install_element (CONFIG_NODE, &no_ipv6_route_flags_cmd);
  3646. install_element (CONFIG_NODE, &no_ipv6_route_ifname_cmd);
  3647. install_element (CONFIG_NODE, &no_ipv6_route_ifname_flags_cmd);
  3648. install_element (CONFIG_NODE, &ipv6_route_pref_cmd);
  3649. install_element (CONFIG_NODE, &ipv6_route_flags_pref_cmd);
  3650. install_element (CONFIG_NODE, &ipv6_route_ifname_pref_cmd);
  3651. install_element (CONFIG_NODE, &ipv6_route_ifname_flags_pref_cmd);
  3652. install_element (CONFIG_NODE, &no_ipv6_route_pref_cmd);
  3653. install_element (CONFIG_NODE, &no_ipv6_route_flags_pref_cmd);
  3654. install_element (CONFIG_NODE, &no_ipv6_route_ifname_pref_cmd);
  3655. install_element (CONFIG_NODE, &no_ipv6_route_ifname_flags_pref_cmd);
  3656. install_element (VIEW_NODE, &show_ipv6_route_cmd);
  3657. install_element (VIEW_NODE, &show_ipv6_route_summary_cmd);
  3658. install_element (VIEW_NODE, &show_ipv6_route_summary_prefix_cmd);
  3659. install_element (VIEW_NODE, &show_ipv6_route_protocol_cmd);
  3660. install_element (VIEW_NODE, &show_ipv6_route_addr_cmd);
  3661. install_element (VIEW_NODE, &show_ipv6_route_prefix_cmd);
  3662. install_element (VIEW_NODE, &show_ipv6_route_prefix_longer_cmd);
  3663. install_element (ENABLE_NODE, &show_ipv6_route_cmd);
  3664. install_element (ENABLE_NODE, &show_ipv6_route_protocol_cmd);
  3665. install_element (ENABLE_NODE, &show_ipv6_route_addr_cmd);
  3666. install_element (ENABLE_NODE, &show_ipv6_route_prefix_cmd);
  3667. install_element (ENABLE_NODE, &show_ipv6_route_prefix_longer_cmd);
  3668. install_element (ENABLE_NODE, &show_ipv6_route_summary_cmd);
  3669. install_element (ENABLE_NODE, &show_ipv6_route_summary_prefix_cmd);
  3670. install_element (VIEW_NODE, &show_ipv6_mroute_cmd);
  3671. install_element (ENABLE_NODE, &show_ipv6_mroute_cmd);
  3672. /* Commands for VRF */
  3673. install_element (CONFIG_NODE, &ipv6_route_vrf_cmd);
  3674. install_element (CONFIG_NODE, &ipv6_route_flags_vrf_cmd);
  3675. install_element (CONFIG_NODE, &ipv6_route_ifname_vrf_cmd);
  3676. install_element (CONFIG_NODE, &ipv6_route_ifname_flags_vrf_cmd);
  3677. install_element (CONFIG_NODE, &no_ipv6_route_vrf_cmd);
  3678. install_element (CONFIG_NODE, &no_ipv6_route_flags_vrf_cmd);
  3679. install_element (CONFIG_NODE, &no_ipv6_route_ifname_vrf_cmd);
  3680. install_element (CONFIG_NODE, &no_ipv6_route_ifname_flags_vrf_cmd);
  3681. install_element (CONFIG_NODE, &ipv6_route_pref_vrf_cmd);
  3682. install_element (CONFIG_NODE, &ipv6_route_flags_pref_vrf_cmd);
  3683. install_element (CONFIG_NODE, &ipv6_route_ifname_pref_vrf_cmd);
  3684. install_element (CONFIG_NODE, &ipv6_route_ifname_flags_pref_vrf_cmd);
  3685. install_element (CONFIG_NODE, &no_ipv6_route_pref_vrf_cmd);
  3686. install_element (CONFIG_NODE, &no_ipv6_route_flags_pref_vrf_cmd);
  3687. install_element (CONFIG_NODE, &no_ipv6_route_ifname_pref_vrf_cmd);
  3688. install_element (CONFIG_NODE, &no_ipv6_route_ifname_flags_pref_vrf_cmd);
  3689. install_element (VIEW_NODE, &show_ipv6_route_vrf_cmd);
  3690. install_element (VIEW_NODE, &show_ipv6_route_summary_vrf_cmd);
  3691. install_element (VIEW_NODE, &show_ipv6_route_summary_prefix_vrf_cmd);
  3692. install_element (VIEW_NODE, &show_ipv6_route_protocol_vrf_cmd);
  3693. install_element (VIEW_NODE, &show_ipv6_route_addr_vrf_cmd);
  3694. install_element (VIEW_NODE, &show_ipv6_route_prefix_vrf_cmd);
  3695. install_element (VIEW_NODE, &show_ipv6_route_prefix_longer_vrf_cmd);
  3696. install_element (ENABLE_NODE, &show_ipv6_route_vrf_cmd);
  3697. install_element (ENABLE_NODE, &show_ipv6_route_protocol_vrf_cmd);
  3698. install_element (ENABLE_NODE, &show_ipv6_route_addr_vrf_cmd);
  3699. install_element (ENABLE_NODE, &show_ipv6_route_prefix_vrf_cmd);
  3700. install_element (ENABLE_NODE, &show_ipv6_route_prefix_longer_vrf_cmd);
  3701. install_element (ENABLE_NODE, &show_ipv6_route_summary_vrf_cmd);
  3702. install_element (ENABLE_NODE, &show_ipv6_route_summary_prefix_vrf_cmd);
  3703. install_element (VIEW_NODE, &show_ipv6_route_vrf_all_cmd);
  3704. install_element (VIEW_NODE, &show_ipv6_route_summary_vrf_all_cmd);
  3705. install_element (VIEW_NODE, &show_ipv6_route_summary_prefix_vrf_all_cmd);
  3706. install_element (VIEW_NODE, &show_ipv6_route_protocol_vrf_all_cmd);
  3707. install_element (VIEW_NODE, &show_ipv6_route_addr_vrf_all_cmd);
  3708. install_element (VIEW_NODE, &show_ipv6_route_prefix_vrf_all_cmd);
  3709. install_element (VIEW_NODE, &show_ipv6_route_prefix_longer_vrf_all_cmd);
  3710. install_element (ENABLE_NODE, &show_ipv6_route_vrf_all_cmd);
  3711. install_element (ENABLE_NODE, &show_ipv6_route_protocol_vrf_all_cmd);
  3712. install_element (ENABLE_NODE, &show_ipv6_route_addr_vrf_all_cmd);
  3713. install_element (ENABLE_NODE, &show_ipv6_route_prefix_vrf_all_cmd);
  3714. install_element (ENABLE_NODE, &show_ipv6_route_prefix_longer_vrf_all_cmd);
  3715. install_element (ENABLE_NODE, &show_ipv6_route_summary_vrf_all_cmd);
  3716. install_element (ENABLE_NODE, &show_ipv6_route_summary_prefix_vrf_all_cmd);
  3717. install_element (VIEW_NODE, &show_ipv6_mroute_vrf_cmd);
  3718. install_element (ENABLE_NODE, &show_ipv6_mroute_vrf_cmd);
  3719. install_element (VIEW_NODE, &show_ipv6_mroute_vrf_all_cmd);
  3720. install_element (ENABLE_NODE, &show_ipv6_mroute_vrf_all_cmd);
  3721. #endif /* HAVE_IPV6 */
  3722. }