zebra_vty.c 118 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013
  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. if (rib->mtu)
  1186. vty_out (vty, ", mtu %u", rib->mtu);
  1187. vty_out (vty, ", vrf %u", rib->vrf_id);
  1188. if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
  1189. vty_out (vty, ", best");
  1190. if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_FIB_OVERRIDE))
  1191. vty_out (vty, ", fib-override");
  1192. if (CHECK_FLAG (rib->status, RIB_ENTRY_SELECTED_FIB))
  1193. vty_out (vty, ", fib");
  1194. if (rib->refcnt)
  1195. vty_out (vty, ", refcnt %ld", rib->refcnt);
  1196. if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
  1197. vty_out (vty, ", blackhole");
  1198. if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
  1199. vty_out (vty, ", reject");
  1200. vty_out (vty, "%s", VTY_NEWLINE);
  1201. #define ONE_DAY_SECOND 60*60*24
  1202. #define ONE_WEEK_SECOND 60*60*24*7
  1203. if (rib->type == ZEBRA_ROUTE_RIP
  1204. || rib->type == ZEBRA_ROUTE_RIPNG
  1205. || rib->type == ZEBRA_ROUTE_OSPF
  1206. || rib->type == ZEBRA_ROUTE_OSPF6
  1207. || rib->type == ZEBRA_ROUTE_BABEL
  1208. || rib->type == ZEBRA_ROUTE_ISIS
  1209. || rib->type == ZEBRA_ROUTE_BGP)
  1210. {
  1211. time_t uptime;
  1212. struct tm *tm;
  1213. uptime = time (NULL);
  1214. uptime -= rib->uptime;
  1215. tm = gmtime (&uptime);
  1216. vty_out (vty, " Last update ");
  1217. if (uptime < ONE_DAY_SECOND)
  1218. vty_out (vty, "%02d:%02d:%02d",
  1219. tm->tm_hour, tm->tm_min, tm->tm_sec);
  1220. else if (uptime < ONE_WEEK_SECOND)
  1221. vty_out (vty, "%dd%02dh%02dm",
  1222. tm->tm_yday, tm->tm_hour, tm->tm_min);
  1223. else
  1224. vty_out (vty, "%02dw%dd%02dh",
  1225. tm->tm_yday/7,
  1226. tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
  1227. vty_out (vty, " ago%s", VTY_NEWLINE);
  1228. }
  1229. for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing))
  1230. {
  1231. vty_out (vty, " %c%c%s",
  1232. CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE) ? '>' : ' ',
  1233. CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB) ? '*' : ' ',
  1234. recursing ? " " : "");
  1235. switch (nexthop->type)
  1236. {
  1237. case NEXTHOP_TYPE_IPV4:
  1238. case NEXTHOP_TYPE_IPV4_IFINDEX:
  1239. vty_out (vty, " %s", inet_ntoa (nexthop->gate.ipv4));
  1240. if (nexthop->ifindex)
  1241. vty_out (vty, ", via %s",
  1242. ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
  1243. break;
  1244. case NEXTHOP_TYPE_IPV6:
  1245. case NEXTHOP_TYPE_IPV6_IFINDEX:
  1246. case NEXTHOP_TYPE_IPV6_IFNAME:
  1247. vty_out (vty, " %s",
  1248. inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, sizeof(buf)));
  1249. if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME)
  1250. vty_out (vty, ", %s", nexthop->ifname);
  1251. else if (nexthop->ifindex)
  1252. vty_out (vty, ", via %s",
  1253. ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
  1254. break;
  1255. case NEXTHOP_TYPE_IFINDEX:
  1256. vty_out (vty, " directly connected, %s",
  1257. ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
  1258. break;
  1259. case NEXTHOP_TYPE_IFNAME:
  1260. vty_out (vty, " directly connected, %s", nexthop->ifname);
  1261. break;
  1262. case NEXTHOP_TYPE_BLACKHOLE:
  1263. vty_out (vty, " directly connected, Null0");
  1264. break;
  1265. default:
  1266. break;
  1267. }
  1268. if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
  1269. vty_out (vty, " inactive");
  1270. if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ONLINK))
  1271. vty_out (vty, " onlink");
  1272. if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
  1273. vty_out (vty, " (recursive)");
  1274. switch (nexthop->type)
  1275. {
  1276. case NEXTHOP_TYPE_IPV4:
  1277. case NEXTHOP_TYPE_IPV4_IFINDEX:
  1278. case NEXTHOP_TYPE_IPV4_IFNAME:
  1279. if (nexthop->src.ipv4.s_addr)
  1280. {
  1281. if (inet_ntop(AF_INET, &nexthop->src.ipv4, buf, sizeof buf))
  1282. vty_out (vty, ", src %s", buf);
  1283. }
  1284. break;
  1285. #ifdef HAVE_IPV6
  1286. case NEXTHOP_TYPE_IPV6:
  1287. case NEXTHOP_TYPE_IPV6_IFINDEX:
  1288. case NEXTHOP_TYPE_IPV6_IFNAME:
  1289. if (!IPV6_ADDR_SAME(&nexthop->src.ipv6, &in6addr_any))
  1290. {
  1291. if (inet_ntop(AF_INET6, &nexthop->src.ipv6, buf, sizeof buf))
  1292. vty_out (vty, ", src %s", buf);
  1293. }
  1294. break;
  1295. #endif /* HAVE_IPV6 */
  1296. default:
  1297. break;
  1298. }
  1299. vty_out (vty, "%s", VTY_NEWLINE);
  1300. }
  1301. vty_out (vty, "%s", VTY_NEWLINE);
  1302. }
  1303. }
  1304. static void
  1305. vty_show_ip_route (struct vty *vty, struct route_node *rn, struct rib *rib)
  1306. {
  1307. struct nexthop *nexthop, *tnexthop;
  1308. int recursing;
  1309. int len = 0;
  1310. char buf[BUFSIZ];
  1311. /* Nexthop information. */
  1312. for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing))
  1313. {
  1314. if (nexthop == rib->nexthop)
  1315. {
  1316. /* Prefix information. */
  1317. len = vty_out (vty, "%c%c%c %s",
  1318. zebra_route_char (rib->type),
  1319. CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED)
  1320. ? '>' : ' ',
  1321. CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
  1322. ? '*' : ' ',
  1323. prefix2str (&rn->p, buf, sizeof buf));
  1324. /* Distance and metric display. */
  1325. if (rib->type != ZEBRA_ROUTE_CONNECT
  1326. && rib->type != ZEBRA_ROUTE_KERNEL)
  1327. len += vty_out (vty, " [%d/%d]", rib->distance,
  1328. rib->metric);
  1329. if (rib->vrf_id != VRF_DEFAULT)
  1330. len += vty_out (vty, " [vrf %u]", rib->vrf_id);
  1331. }
  1332. else
  1333. vty_out (vty, " %c%*c",
  1334. CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
  1335. ? '*' : ' ',
  1336. len - 3 + (2 * recursing), ' ');
  1337. switch (nexthop->type)
  1338. {
  1339. case NEXTHOP_TYPE_IPV4:
  1340. case NEXTHOP_TYPE_IPV4_IFINDEX:
  1341. vty_out (vty, " via %s", inet_ntoa (nexthop->gate.ipv4));
  1342. if (nexthop->ifindex)
  1343. vty_out (vty, ", %s",
  1344. ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
  1345. break;
  1346. case NEXTHOP_TYPE_IPV6:
  1347. case NEXTHOP_TYPE_IPV6_IFINDEX:
  1348. case NEXTHOP_TYPE_IPV6_IFNAME:
  1349. vty_out (vty, " via %s",
  1350. inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, BUFSIZ));
  1351. if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME)
  1352. vty_out (vty, ", %s", nexthop->ifname);
  1353. else if (nexthop->ifindex)
  1354. vty_out (vty, ", %s",
  1355. ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
  1356. break;
  1357. case NEXTHOP_TYPE_IFINDEX:
  1358. vty_out (vty, " is directly connected, %s",
  1359. ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
  1360. break;
  1361. case NEXTHOP_TYPE_IFNAME:
  1362. vty_out (vty, " is directly connected, %s", nexthop->ifname);
  1363. break;
  1364. case NEXTHOP_TYPE_BLACKHOLE:
  1365. vty_out (vty, " is directly connected, Null0");
  1366. break;
  1367. default:
  1368. break;
  1369. }
  1370. if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
  1371. vty_out (vty, " inactive");
  1372. if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ONLINK))
  1373. vty_out (vty, " onlink");
  1374. if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
  1375. vty_out (vty, " (recursive)");
  1376. switch (nexthop->type)
  1377. {
  1378. case NEXTHOP_TYPE_IPV4:
  1379. case NEXTHOP_TYPE_IPV4_IFINDEX:
  1380. case NEXTHOP_TYPE_IPV4_IFNAME:
  1381. if (nexthop->src.ipv4.s_addr)
  1382. {
  1383. if (inet_ntop(AF_INET, &nexthop->src.ipv4, buf, sizeof buf))
  1384. vty_out (vty, ", src %s", buf);
  1385. }
  1386. break;
  1387. #ifdef HAVE_IPV6
  1388. case NEXTHOP_TYPE_IPV6:
  1389. case NEXTHOP_TYPE_IPV6_IFINDEX:
  1390. case NEXTHOP_TYPE_IPV6_IFNAME:
  1391. if (!IPV6_ADDR_SAME(&nexthop->src.ipv6, &in6addr_any))
  1392. {
  1393. if (inet_ntop(AF_INET6, &nexthop->src.ipv6, buf, sizeof buf))
  1394. vty_out (vty, ", src %s", buf);
  1395. }
  1396. break;
  1397. #endif /* HAVE_IPV6 */
  1398. default:
  1399. break;
  1400. }
  1401. if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
  1402. vty_out (vty, ", bh");
  1403. if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
  1404. vty_out (vty, ", rej");
  1405. if (rib->type == ZEBRA_ROUTE_RIP
  1406. || rib->type == ZEBRA_ROUTE_RIPNG
  1407. || rib->type == ZEBRA_ROUTE_OSPF
  1408. || rib->type == ZEBRA_ROUTE_OSPF6
  1409. || rib->type == ZEBRA_ROUTE_BABEL
  1410. || rib->type == ZEBRA_ROUTE_ISIS
  1411. || rib->type == ZEBRA_ROUTE_BGP)
  1412. {
  1413. time_t uptime;
  1414. struct tm *tm;
  1415. uptime = time (NULL);
  1416. uptime -= rib->uptime;
  1417. tm = gmtime (&uptime);
  1418. #define ONE_DAY_SECOND 60*60*24
  1419. #define ONE_WEEK_SECOND 60*60*24*7
  1420. if (uptime < ONE_DAY_SECOND)
  1421. vty_out (vty, ", %02d:%02d:%02d",
  1422. tm->tm_hour, tm->tm_min, tm->tm_sec);
  1423. else if (uptime < ONE_WEEK_SECOND)
  1424. vty_out (vty, ", %dd%02dh%02dm",
  1425. tm->tm_yday, tm->tm_hour, tm->tm_min);
  1426. else
  1427. vty_out (vty, ", %02dw%dd%02dh",
  1428. tm->tm_yday/7,
  1429. tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
  1430. }
  1431. vty_out (vty, "%s", VTY_NEWLINE);
  1432. }
  1433. }
  1434. DEFUN (show_ip_route,
  1435. show_ip_route_cmd,
  1436. "show ip route",
  1437. SHOW_STR
  1438. IP_STR
  1439. "IP routing table\n")
  1440. {
  1441. vrf_id_t vrf_id = VRF_DEFAULT;
  1442. if (argc > 0)
  1443. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
  1444. return do_show_ip_route(vty, SAFI_UNICAST, vrf_id);
  1445. }
  1446. static int do_show_ip_route(struct vty *vty, safi_t safi, vrf_id_t vrf_id)
  1447. {
  1448. struct route_table *table;
  1449. struct route_node *rn;
  1450. struct rib *rib;
  1451. int first = 1;
  1452. table = zebra_vrf_table (AFI_IP, safi, vrf_id);
  1453. if (! table)
  1454. return CMD_SUCCESS;
  1455. /* Show all IPv4 routes. */
  1456. for (rn = route_top (table); rn; rn = route_next (rn))
  1457. RNODE_FOREACH_RIB (rn, rib)
  1458. {
  1459. if (first)
  1460. {
  1461. vty_out (vty, SHOW_ROUTE_V4_HEADER);
  1462. first = 0;
  1463. }
  1464. vty_show_ip_route (vty, rn, rib);
  1465. }
  1466. return CMD_SUCCESS;
  1467. }
  1468. ALIAS (show_ip_route,
  1469. show_ip_route_vrf_cmd,
  1470. "show ip route " VRF_CMD_STR,
  1471. SHOW_STR
  1472. IP_STR
  1473. "IP routing table\n"
  1474. VRF_CMD_HELP_STR)
  1475. DEFUN (show_ip_route_prefix_longer,
  1476. show_ip_route_prefix_longer_cmd,
  1477. "show ip route A.B.C.D/M longer-prefixes",
  1478. SHOW_STR
  1479. IP_STR
  1480. "IP routing table\n"
  1481. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1482. "Show route matching the specified Network/Mask pair only\n")
  1483. {
  1484. struct route_table *table;
  1485. struct route_node *rn;
  1486. struct rib *rib;
  1487. struct prefix p;
  1488. int ret;
  1489. int first = 1;
  1490. vrf_id_t vrf_id = VRF_DEFAULT;
  1491. ret = str2prefix (argv[0], &p);
  1492. if (! ret)
  1493. {
  1494. vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
  1495. return CMD_WARNING;
  1496. }
  1497. if (argc > 1)
  1498. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
  1499. table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
  1500. if (! table)
  1501. return CMD_SUCCESS;
  1502. /* Show matched type IPv4 routes. */
  1503. for (rn = route_top (table); rn; rn = route_next (rn))
  1504. RNODE_FOREACH_RIB (rn, rib)
  1505. if (prefix_match (&p, &rn->p))
  1506. {
  1507. if (first)
  1508. {
  1509. vty_out (vty, SHOW_ROUTE_V4_HEADER);
  1510. first = 0;
  1511. }
  1512. vty_show_ip_route (vty, rn, rib);
  1513. }
  1514. return CMD_SUCCESS;
  1515. }
  1516. ALIAS (show_ip_route_prefix_longer,
  1517. show_ip_route_prefix_longer_vrf_cmd,
  1518. "show ip route A.B.C.D/M longer-prefixes " VRF_CMD_STR,
  1519. SHOW_STR
  1520. IP_STR
  1521. "IP routing table\n"
  1522. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1523. "Show route matching the specified Network/Mask pair only\n"
  1524. VRF_CMD_HELP_STR)
  1525. DEFUN (show_ip_route_supernets,
  1526. show_ip_route_supernets_cmd,
  1527. "show ip route supernets-only",
  1528. SHOW_STR
  1529. IP_STR
  1530. "IP routing table\n"
  1531. "Show supernet entries only\n")
  1532. {
  1533. struct route_table *table;
  1534. struct route_node *rn;
  1535. struct rib *rib;
  1536. u_int32_t addr;
  1537. int first = 1;
  1538. vrf_id_t vrf_id = VRF_DEFAULT;
  1539. if (argc > 0)
  1540. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
  1541. table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
  1542. if (! table)
  1543. return CMD_SUCCESS;
  1544. /* Show matched type IPv4 routes. */
  1545. for (rn = route_top (table); rn; rn = route_next (rn))
  1546. RNODE_FOREACH_RIB (rn, rib)
  1547. {
  1548. addr = ntohl (rn->p.u.prefix4.s_addr);
  1549. if ((IN_CLASSC (addr) && rn->p.prefixlen < 24)
  1550. || (IN_CLASSB (addr) && rn->p.prefixlen < 16)
  1551. || (IN_CLASSA (addr) && rn->p.prefixlen < 8))
  1552. {
  1553. if (first)
  1554. {
  1555. vty_out (vty, SHOW_ROUTE_V4_HEADER);
  1556. first = 0;
  1557. }
  1558. vty_show_ip_route (vty, rn, rib);
  1559. }
  1560. }
  1561. return CMD_SUCCESS;
  1562. }
  1563. ALIAS (show_ip_route_supernets,
  1564. show_ip_route_supernets_vrf_cmd,
  1565. "show ip route supernets-only " VRF_CMD_STR,
  1566. SHOW_STR
  1567. IP_STR
  1568. "IP routing table\n"
  1569. "Show supernet entries only\n"
  1570. VRF_CMD_HELP_STR)
  1571. DEFUN (show_ip_route_protocol,
  1572. show_ip_route_protocol_cmd,
  1573. "show ip route " QUAGGA_IP_REDIST_STR_ZEBRA,
  1574. SHOW_STR
  1575. IP_STR
  1576. "IP routing table\n"
  1577. QUAGGA_IP_REDIST_HELP_STR_ZEBRA)
  1578. {
  1579. int type;
  1580. struct route_table *table;
  1581. struct route_node *rn;
  1582. struct rib *rib;
  1583. int first = 1;
  1584. vrf_id_t vrf_id = VRF_DEFAULT;
  1585. type = proto_redistnum (AFI_IP, argv[0]);
  1586. if (type < 0)
  1587. {
  1588. vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
  1589. return CMD_WARNING;
  1590. }
  1591. if (argc > 1)
  1592. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
  1593. table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
  1594. if (! table)
  1595. return CMD_SUCCESS;
  1596. /* Show matched type IPv4 routes. */
  1597. for (rn = route_top (table); rn; rn = route_next (rn))
  1598. RNODE_FOREACH_RIB (rn, rib)
  1599. if (rib->type == type)
  1600. {
  1601. if (first)
  1602. {
  1603. vty_out (vty, SHOW_ROUTE_V4_HEADER);
  1604. first = 0;
  1605. }
  1606. vty_show_ip_route (vty, rn, rib);
  1607. }
  1608. return CMD_SUCCESS;
  1609. }
  1610. ALIAS (show_ip_route_protocol,
  1611. show_ip_route_protocol_vrf_cmd,
  1612. "show ip route " QUAGGA_IP_REDIST_STR_ZEBRA " " VRF_CMD_STR,
  1613. SHOW_STR
  1614. IP_STR
  1615. "IP routing table\n"
  1616. QUAGGA_IP_REDIST_HELP_STR_ZEBRA
  1617. VRF_CMD_HELP_STR)
  1618. DEFUN (show_ip_route_addr,
  1619. show_ip_route_addr_cmd,
  1620. "show ip route A.B.C.D",
  1621. SHOW_STR
  1622. IP_STR
  1623. "IP routing table\n"
  1624. "Network in the IP routing table to display\n")
  1625. {
  1626. int ret;
  1627. struct prefix_ipv4 p;
  1628. struct route_table *table;
  1629. struct route_node *rn;
  1630. vrf_id_t vrf_id = VRF_DEFAULT;
  1631. ret = str2prefix_ipv4 (argv[0], &p);
  1632. if (ret <= 0)
  1633. {
  1634. vty_out (vty, "%% Malformed IPv4 address%s", VTY_NEWLINE);
  1635. return CMD_WARNING;
  1636. }
  1637. if (argc > 1)
  1638. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
  1639. table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
  1640. if (! table)
  1641. return CMD_SUCCESS;
  1642. rn = route_node_match (table, (struct prefix *) &p);
  1643. if (! rn)
  1644. {
  1645. vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
  1646. return CMD_WARNING;
  1647. }
  1648. vty_show_ip_route_detail (vty, rn, 0);
  1649. route_unlock_node (rn);
  1650. return CMD_SUCCESS;
  1651. }
  1652. ALIAS (show_ip_route_addr,
  1653. show_ip_route_addr_vrf_cmd,
  1654. "show ip route A.B.C.D " VRF_CMD_STR,
  1655. SHOW_STR
  1656. IP_STR
  1657. "IP routing table\n"
  1658. "Network in the IP routing table to display\n"
  1659. VRF_CMD_HELP_STR)
  1660. DEFUN (show_ip_route_prefix,
  1661. show_ip_route_prefix_cmd,
  1662. "show ip route A.B.C.D/M",
  1663. SHOW_STR
  1664. IP_STR
  1665. "IP routing table\n"
  1666. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
  1667. {
  1668. int ret;
  1669. struct prefix_ipv4 p;
  1670. struct route_table *table;
  1671. struct route_node *rn;
  1672. vrf_id_t vrf_id = VRF_DEFAULT;
  1673. ret = str2prefix_ipv4 (argv[0], &p);
  1674. if (ret <= 0)
  1675. {
  1676. vty_out (vty, "%% Malformed IPv4 address%s", VTY_NEWLINE);
  1677. return CMD_WARNING;
  1678. }
  1679. if (argc > 1)
  1680. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
  1681. table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
  1682. if (! table)
  1683. return CMD_SUCCESS;
  1684. rn = route_node_match (table, (struct prefix *) &p);
  1685. if (! rn || rn->p.prefixlen != p.prefixlen)
  1686. {
  1687. vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
  1688. if (rn)
  1689. route_unlock_node (rn);
  1690. return CMD_WARNING;
  1691. }
  1692. vty_show_ip_route_detail (vty, rn, 0);
  1693. route_unlock_node (rn);
  1694. return CMD_SUCCESS;
  1695. }
  1696. ALIAS (show_ip_route_prefix,
  1697. show_ip_route_prefix_vrf_cmd,
  1698. "show ip route A.B.C.D/M " VRF_CMD_STR,
  1699. SHOW_STR
  1700. IP_STR
  1701. "IP routing table\n"
  1702. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1703. VRF_CMD_HELP_STR)
  1704. static void
  1705. vty_show_ip_route_summary (struct vty *vty, struct route_table *table)
  1706. {
  1707. struct route_node *rn;
  1708. struct rib *rib;
  1709. struct nexthop *nexthop;
  1710. #define ZEBRA_ROUTE_IBGP ZEBRA_ROUTE_MAX
  1711. #define ZEBRA_ROUTE_TOTAL (ZEBRA_ROUTE_IBGP + 1)
  1712. u_int32_t rib_cnt[ZEBRA_ROUTE_TOTAL + 1];
  1713. u_int32_t fib_cnt[ZEBRA_ROUTE_TOTAL + 1];
  1714. u_int32_t i;
  1715. memset (&rib_cnt, 0, sizeof(rib_cnt));
  1716. memset (&fib_cnt, 0, sizeof(fib_cnt));
  1717. for (rn = route_top (table); rn; rn = route_next (rn))
  1718. RNODE_FOREACH_RIB (rn, rib)
  1719. for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
  1720. {
  1721. rib_cnt[ZEBRA_ROUTE_TOTAL]++;
  1722. rib_cnt[rib->type]++;
  1723. if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
  1724. || nexthop_has_fib_child(nexthop))
  1725. {
  1726. fib_cnt[ZEBRA_ROUTE_TOTAL]++;
  1727. fib_cnt[rib->type]++;
  1728. }
  1729. if (rib->type == ZEBRA_ROUTE_BGP &&
  1730. CHECK_FLAG (rib->flags, ZEBRA_FLAG_IBGP))
  1731. {
  1732. rib_cnt[ZEBRA_ROUTE_IBGP]++;
  1733. if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
  1734. || nexthop_has_fib_child(nexthop))
  1735. fib_cnt[ZEBRA_ROUTE_IBGP]++;
  1736. }
  1737. }
  1738. vty_out (vty, "%-20s %-20s %s (vrf %u)%s",
  1739. "Route Source", "Routes", "FIB",
  1740. ((rib_table_info_t *)table->info)->zvrf->vrf_id,
  1741. VTY_NEWLINE);
  1742. for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
  1743. {
  1744. if (rib_cnt[i] > 0)
  1745. {
  1746. if (i == ZEBRA_ROUTE_BGP)
  1747. {
  1748. vty_out (vty, "%-20s %-20d %-20d %s", "ebgp",
  1749. rib_cnt[ZEBRA_ROUTE_BGP] - rib_cnt[ZEBRA_ROUTE_IBGP],
  1750. fib_cnt[ZEBRA_ROUTE_BGP] - fib_cnt[ZEBRA_ROUTE_IBGP],
  1751. VTY_NEWLINE);
  1752. vty_out (vty, "%-20s %-20d %-20d %s", "ibgp",
  1753. rib_cnt[ZEBRA_ROUTE_IBGP], fib_cnt[ZEBRA_ROUTE_IBGP],
  1754. VTY_NEWLINE);
  1755. }
  1756. else
  1757. vty_out (vty, "%-20s %-20d %-20d %s", zebra_route_string(i),
  1758. rib_cnt[i], fib_cnt[i], VTY_NEWLINE);
  1759. }
  1760. }
  1761. vty_out (vty, "------%s", VTY_NEWLINE);
  1762. vty_out (vty, "%-20s %-20d %-20d %s", "Totals", rib_cnt[ZEBRA_ROUTE_TOTAL],
  1763. fib_cnt[ZEBRA_ROUTE_TOTAL], VTY_NEWLINE);
  1764. vty_out (vty, "%s", VTY_NEWLINE);
  1765. }
  1766. /*
  1767. * Implementation of the ip route summary prefix command.
  1768. *
  1769. * This command prints the primary prefixes that have been installed by various
  1770. * protocols on the box.
  1771. *
  1772. */
  1773. static void
  1774. vty_show_ip_route_summary_prefix (struct vty *vty, struct route_table *table)
  1775. {
  1776. struct route_node *rn;
  1777. struct rib *rib;
  1778. struct nexthop *nexthop;
  1779. #define ZEBRA_ROUTE_IBGP ZEBRA_ROUTE_MAX
  1780. #define ZEBRA_ROUTE_TOTAL (ZEBRA_ROUTE_IBGP + 1)
  1781. u_int32_t rib_cnt[ZEBRA_ROUTE_TOTAL + 1];
  1782. u_int32_t fib_cnt[ZEBRA_ROUTE_TOTAL + 1];
  1783. u_int32_t i;
  1784. int cnt;
  1785. memset (&rib_cnt, 0, sizeof(rib_cnt));
  1786. memset (&fib_cnt, 0, sizeof(fib_cnt));
  1787. for (rn = route_top (table); rn; rn = route_next (rn))
  1788. RNODE_FOREACH_RIB (rn, rib)
  1789. {
  1790. /*
  1791. * In case of ECMP, count only once.
  1792. */
  1793. cnt = 0;
  1794. for (nexthop = rib->nexthop; (!cnt && nexthop); nexthop = nexthop->next)
  1795. {
  1796. cnt++;
  1797. rib_cnt[ZEBRA_ROUTE_TOTAL]++;
  1798. rib_cnt[rib->type]++;
  1799. if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB))
  1800. {
  1801. fib_cnt[ZEBRA_ROUTE_TOTAL]++;
  1802. fib_cnt[rib->type]++;
  1803. }
  1804. if (rib->type == ZEBRA_ROUTE_BGP &&
  1805. CHECK_FLAG (rib->flags, ZEBRA_FLAG_IBGP))
  1806. {
  1807. rib_cnt[ZEBRA_ROUTE_IBGP]++;
  1808. if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB))
  1809. fib_cnt[ZEBRA_ROUTE_IBGP]++;
  1810. }
  1811. }
  1812. }
  1813. vty_out (vty, "%-20s %-20s %s (vrf %u)%s",
  1814. "Route Source", "Prefix Routes", "FIB",
  1815. ((rib_table_info_t *)table->info)->zvrf->vrf_id,
  1816. VTY_NEWLINE);
  1817. for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
  1818. {
  1819. if (rib_cnt[i] > 0)
  1820. {
  1821. if (i == ZEBRA_ROUTE_BGP)
  1822. {
  1823. vty_out (vty, "%-20s %-20d %-20d %s", "ebgp",
  1824. rib_cnt[ZEBRA_ROUTE_BGP] - rib_cnt[ZEBRA_ROUTE_IBGP],
  1825. fib_cnt[ZEBRA_ROUTE_BGP] - fib_cnt[ZEBRA_ROUTE_IBGP],
  1826. VTY_NEWLINE);
  1827. vty_out (vty, "%-20s %-20d %-20d %s", "ibgp",
  1828. rib_cnt[ZEBRA_ROUTE_IBGP], fib_cnt[ZEBRA_ROUTE_IBGP],
  1829. VTY_NEWLINE);
  1830. }
  1831. else
  1832. vty_out (vty, "%-20s %-20d %-20d %s", zebra_route_string(i),
  1833. rib_cnt[i], fib_cnt[i], VTY_NEWLINE);
  1834. }
  1835. }
  1836. vty_out (vty, "------%s", VTY_NEWLINE);
  1837. vty_out (vty, "%-20s %-20d %-20d %s", "Totals", rib_cnt[ZEBRA_ROUTE_TOTAL],
  1838. fib_cnt[ZEBRA_ROUTE_TOTAL], VTY_NEWLINE);
  1839. vty_out (vty, "%s", VTY_NEWLINE);
  1840. }
  1841. /* Show route summary. */
  1842. DEFUN (show_ip_route_summary,
  1843. show_ip_route_summary_cmd,
  1844. "show ip route summary",
  1845. SHOW_STR
  1846. IP_STR
  1847. "IP routing table\n"
  1848. "Summary of all routes\n")
  1849. {
  1850. struct route_table *table;
  1851. vrf_id_t vrf_id = VRF_DEFAULT;
  1852. if (argc > 0)
  1853. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
  1854. table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
  1855. if (! table)
  1856. return CMD_SUCCESS;
  1857. vty_show_ip_route_summary (vty, table);
  1858. return CMD_SUCCESS;
  1859. }
  1860. ALIAS (show_ip_route_summary,
  1861. show_ip_route_summary_vrf_cmd,
  1862. "show ip route summary " VRF_CMD_STR,
  1863. SHOW_STR
  1864. IP_STR
  1865. "IP routing table\n"
  1866. "Summary of all routes\n"
  1867. VRF_CMD_HELP_STR)
  1868. /* Show route summary prefix. */
  1869. DEFUN (show_ip_route_summary_prefix,
  1870. show_ip_route_summary_prefix_cmd,
  1871. "show ip route summary prefix",
  1872. SHOW_STR
  1873. IP_STR
  1874. "IP routing table\n"
  1875. "Summary of all routes\n"
  1876. "Prefix routes\n")
  1877. {
  1878. struct route_table *table;
  1879. vrf_id_t vrf_id = VRF_DEFAULT;
  1880. if (argc > 0)
  1881. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
  1882. table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
  1883. if (! table)
  1884. return CMD_SUCCESS;
  1885. vty_show_ip_route_summary_prefix (vty, table);
  1886. return CMD_SUCCESS;
  1887. }
  1888. ALIAS (show_ip_route_summary_prefix,
  1889. show_ip_route_summary_prefix_vrf_cmd,
  1890. "show ip route summary prefix " VRF_CMD_STR,
  1891. SHOW_STR
  1892. IP_STR
  1893. "IP routing table\n"
  1894. "Summary of all routes\n"
  1895. "Prefix routes\n"
  1896. VRF_CMD_HELP_STR)
  1897. DEFUN (show_ip_route_vrf_all,
  1898. show_ip_route_vrf_all_cmd,
  1899. "show ip route " VRF_ALL_CMD_STR,
  1900. SHOW_STR
  1901. IP_STR
  1902. "IP routing table\n"
  1903. VRF_ALL_CMD_HELP_STR)
  1904. {
  1905. struct route_table *table;
  1906. struct route_node *rn;
  1907. struct rib *rib;
  1908. struct zebra_vrf *zvrf;
  1909. vrf_iter_t iter;
  1910. int first = 1;
  1911. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  1912. {
  1913. if ((zvrf = vrf_iter2info (iter)) == NULL ||
  1914. (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL)
  1915. continue;
  1916. /* Show all IPv4 routes. */
  1917. for (rn = route_top (table); rn; rn = route_next (rn))
  1918. RNODE_FOREACH_RIB (rn, rib)
  1919. {
  1920. if (first)
  1921. {
  1922. vty_out (vty, SHOW_ROUTE_V4_HEADER);
  1923. first = 0;
  1924. }
  1925. vty_show_ip_route (vty, rn, rib);
  1926. }
  1927. }
  1928. return CMD_SUCCESS;
  1929. }
  1930. DEFUN (show_ip_route_prefix_longer_vrf_all,
  1931. show_ip_route_prefix_longer_vrf_all_cmd,
  1932. "show ip route A.B.C.D/M longer-prefixes " VRF_ALL_CMD_STR,
  1933. SHOW_STR
  1934. IP_STR
  1935. "IP routing table\n"
  1936. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1937. "Show route matching the specified Network/Mask pair only\n"
  1938. VRF_ALL_CMD_HELP_STR)
  1939. {
  1940. struct route_table *table;
  1941. struct route_node *rn;
  1942. struct rib *rib;
  1943. struct prefix p;
  1944. struct zebra_vrf *zvrf;
  1945. vrf_iter_t iter;
  1946. int ret;
  1947. int first = 1;
  1948. ret = str2prefix (argv[0], &p);
  1949. if (! ret)
  1950. {
  1951. vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
  1952. return CMD_WARNING;
  1953. }
  1954. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  1955. {
  1956. if ((zvrf = vrf_iter2info (iter)) == NULL ||
  1957. (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL)
  1958. continue;
  1959. /* Show matched type IPv4 routes. */
  1960. for (rn = route_top (table); rn; rn = route_next (rn))
  1961. RNODE_FOREACH_RIB (rn, rib)
  1962. if (prefix_match (&p, &rn->p))
  1963. {
  1964. if (first)
  1965. {
  1966. vty_out (vty, SHOW_ROUTE_V4_HEADER);
  1967. first = 0;
  1968. }
  1969. vty_show_ip_route (vty, rn, rib);
  1970. }
  1971. }
  1972. return CMD_SUCCESS;
  1973. }
  1974. DEFUN (show_ip_route_supernets_vrf_all,
  1975. show_ip_route_supernets_vrf_all_cmd,
  1976. "show ip route supernets-only " VRF_ALL_CMD_STR,
  1977. SHOW_STR
  1978. IP_STR
  1979. "IP routing table\n"
  1980. "Show supernet entries only\n"
  1981. VRF_ALL_CMD_HELP_STR)
  1982. {
  1983. struct route_table *table;
  1984. struct route_node *rn;
  1985. struct rib *rib;
  1986. struct zebra_vrf *zvrf;
  1987. vrf_iter_t iter;
  1988. u_int32_t addr;
  1989. int first = 1;
  1990. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  1991. {
  1992. if ((zvrf = vrf_iter2info (iter)) == NULL ||
  1993. (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL)
  1994. continue;
  1995. /* Show matched type IPv4 routes. */
  1996. for (rn = route_top (table); rn; rn = route_next (rn))
  1997. RNODE_FOREACH_RIB (rn, rib)
  1998. {
  1999. addr = ntohl (rn->p.u.prefix4.s_addr);
  2000. if ((IN_CLASSC (addr) && rn->p.prefixlen < 24)
  2001. || (IN_CLASSB (addr) && rn->p.prefixlen < 16)
  2002. || (IN_CLASSA (addr) && rn->p.prefixlen < 8))
  2003. {
  2004. if (first)
  2005. {
  2006. vty_out (vty, SHOW_ROUTE_V4_HEADER);
  2007. first = 0;
  2008. }
  2009. vty_show_ip_route (vty, rn, rib);
  2010. }
  2011. }
  2012. }
  2013. return CMD_SUCCESS;
  2014. }
  2015. DEFUN (show_ip_route_protocol_vrf_all,
  2016. show_ip_route_protocol_vrf_all_cmd,
  2017. "show ip route " QUAGGA_IP_REDIST_STR_ZEBRA " " VRF_ALL_CMD_STR,
  2018. SHOW_STR
  2019. IP_STR
  2020. "IP routing table\n"
  2021. QUAGGA_IP_REDIST_HELP_STR_ZEBRA
  2022. VRF_ALL_CMD_HELP_STR)
  2023. {
  2024. int type;
  2025. struct route_table *table;
  2026. struct route_node *rn;
  2027. struct rib *rib;
  2028. struct zebra_vrf *zvrf;
  2029. vrf_iter_t iter;
  2030. int first = 1;
  2031. type = proto_redistnum (AFI_IP, argv[0]);
  2032. if (type < 0)
  2033. {
  2034. vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
  2035. return CMD_WARNING;
  2036. }
  2037. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  2038. {
  2039. if ((zvrf = vrf_iter2info (iter)) == NULL ||
  2040. (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL)
  2041. continue;
  2042. /* Show matched type IPv4 routes. */
  2043. for (rn = route_top (table); rn; rn = route_next (rn))
  2044. RNODE_FOREACH_RIB (rn, rib)
  2045. if (rib->type == type)
  2046. {
  2047. if (first)
  2048. {
  2049. vty_out (vty, SHOW_ROUTE_V4_HEADER);
  2050. first = 0;
  2051. }
  2052. vty_show_ip_route (vty, rn, rib);
  2053. }
  2054. }
  2055. return CMD_SUCCESS;
  2056. }
  2057. DEFUN (show_ip_route_addr_vrf_all,
  2058. show_ip_route_addr_vrf_all_cmd,
  2059. "show ip route A.B.C.D " VRF_ALL_CMD_STR,
  2060. SHOW_STR
  2061. IP_STR
  2062. "IP routing table\n"
  2063. "Network in the IP routing table to display\n"
  2064. VRF_ALL_CMD_HELP_STR)
  2065. {
  2066. int ret;
  2067. struct prefix_ipv4 p;
  2068. struct route_table *table;
  2069. struct route_node *rn;
  2070. struct zebra_vrf *zvrf;
  2071. vrf_iter_t iter;
  2072. ret = str2prefix_ipv4 (argv[0], &p);
  2073. if (ret <= 0)
  2074. {
  2075. vty_out (vty, "%% Malformed IPv4 address%s", VTY_NEWLINE);
  2076. return CMD_WARNING;
  2077. }
  2078. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  2079. {
  2080. if ((zvrf = vrf_iter2info (iter)) == NULL ||
  2081. (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL)
  2082. continue;
  2083. rn = route_node_match (table, (struct prefix *) &p);
  2084. if (! rn)
  2085. continue;
  2086. vty_show_ip_route_detail (vty, rn, 0);
  2087. route_unlock_node (rn);
  2088. }
  2089. return CMD_SUCCESS;
  2090. }
  2091. DEFUN (show_ip_route_prefix_vrf_all,
  2092. show_ip_route_prefix_vrf_all_cmd,
  2093. "show ip route A.B.C.D/M " VRF_ALL_CMD_STR,
  2094. SHOW_STR
  2095. IP_STR
  2096. "IP routing table\n"
  2097. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  2098. VRF_ALL_CMD_HELP_STR)
  2099. {
  2100. int ret;
  2101. struct prefix_ipv4 p;
  2102. struct route_table *table;
  2103. struct route_node *rn;
  2104. struct zebra_vrf *zvrf;
  2105. vrf_iter_t iter;
  2106. ret = str2prefix_ipv4 (argv[0], &p);
  2107. if (ret <= 0)
  2108. {
  2109. vty_out (vty, "%% Malformed IPv4 address%s", VTY_NEWLINE);
  2110. return CMD_WARNING;
  2111. }
  2112. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  2113. {
  2114. if ((zvrf = vrf_iter2info (iter)) == NULL ||
  2115. (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL)
  2116. continue;
  2117. rn = route_node_match (table, (struct prefix *) &p);
  2118. if (! rn)
  2119. continue;
  2120. if (rn->p.prefixlen != p.prefixlen)
  2121. {
  2122. route_unlock_node (rn);
  2123. continue;
  2124. }
  2125. vty_show_ip_route_detail (vty, rn, 0);
  2126. route_unlock_node (rn);
  2127. }
  2128. return CMD_SUCCESS;
  2129. }
  2130. DEFUN (show_ip_route_summary_vrf_all,
  2131. show_ip_route_summary_vrf_all_cmd,
  2132. "show ip route summary " VRF_ALL_CMD_STR,
  2133. SHOW_STR
  2134. IP_STR
  2135. "IP routing table\n"
  2136. "Summary of all routes\n"
  2137. VRF_ALL_CMD_HELP_STR)
  2138. {
  2139. struct zebra_vrf *zvrf;
  2140. vrf_iter_t iter;
  2141. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  2142. if ((zvrf = vrf_iter2info (iter)) != NULL)
  2143. vty_show_ip_route_summary (vty, zvrf->table[AFI_IP][SAFI_UNICAST]);
  2144. return CMD_SUCCESS;
  2145. }
  2146. DEFUN (show_ip_route_summary_prefix_vrf_all,
  2147. show_ip_route_summary_prefix_vrf_all_cmd,
  2148. "show ip route summary prefix " VRF_ALL_CMD_STR,
  2149. SHOW_STR
  2150. IP_STR
  2151. "IP routing table\n"
  2152. "Summary of all routes\n"
  2153. "Prefix routes\n"
  2154. VRF_ALL_CMD_HELP_STR)
  2155. {
  2156. struct zebra_vrf *zvrf;
  2157. vrf_iter_t iter;
  2158. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  2159. if ((zvrf = vrf_iter2info (iter)) != NULL)
  2160. vty_show_ip_route_summary_prefix (vty, zvrf->table[AFI_IP][SAFI_UNICAST]);
  2161. return CMD_SUCCESS;
  2162. }
  2163. /* Write IPv4 static route configuration. */
  2164. static int
  2165. static_config_ipv4 (struct vty *vty, safi_t safi, const char *cmd)
  2166. {
  2167. struct route_node *rn;
  2168. struct static_route *si;
  2169. struct route_table *stable;
  2170. struct zebra_vrf *zvrf;
  2171. vrf_iter_t iter;
  2172. int write;
  2173. write = 0;
  2174. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  2175. {
  2176. if ((zvrf = vrf_iter2info (iter)) == NULL ||
  2177. (stable = zvrf->stable[AFI_IP][safi]) == NULL)
  2178. continue;
  2179. for (rn = route_top (stable); rn; rn = route_next (rn))
  2180. for (si = rn->info; si; si = si->next)
  2181. {
  2182. vty_out (vty, "%s %s/%d", cmd, inet_ntoa (rn->p.u.prefix4),
  2183. rn->p.prefixlen);
  2184. switch (si->type)
  2185. {
  2186. case STATIC_IPV4_GATEWAY:
  2187. vty_out (vty, " %s", inet_ntoa (si->addr.ipv4));
  2188. break;
  2189. case STATIC_IPV4_IFNAME:
  2190. vty_out (vty, " %s", si->ifname);
  2191. break;
  2192. case STATIC_IPV4_BLACKHOLE:
  2193. vty_out (vty, " Null0");
  2194. break;
  2195. }
  2196. /* flags are incompatible with STATIC_IPV4_BLACKHOLE */
  2197. if (si->type != STATIC_IPV4_BLACKHOLE)
  2198. {
  2199. if (CHECK_FLAG(si->flags, ZEBRA_FLAG_REJECT))
  2200. vty_out (vty, " %s", "reject");
  2201. if (CHECK_FLAG(si->flags, ZEBRA_FLAG_BLACKHOLE))
  2202. vty_out (vty, " %s", "blackhole");
  2203. }
  2204. if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT)
  2205. vty_out (vty, " %d", si->distance);
  2206. if (si->vrf_id != VRF_DEFAULT)
  2207. vty_out (vty, " vrf %u", si->vrf_id);
  2208. vty_out (vty, "%s", VTY_NEWLINE);
  2209. write = 1;
  2210. }
  2211. }
  2212. return write;
  2213. }
  2214. DEFUN (show_ip_protocol,
  2215. show_ip_protocol_cmd,
  2216. "show ip protocol",
  2217. SHOW_STR
  2218. IP_STR
  2219. "IP protocol filtering status\n")
  2220. {
  2221. int i;
  2222. vty_out(vty, "Protocol : route-map %s", VTY_NEWLINE);
  2223. vty_out(vty, "------------------------%s", VTY_NEWLINE);
  2224. for (i=0;i<ZEBRA_ROUTE_MAX;i++)
  2225. {
  2226. if (proto_rm[AFI_IP][i])
  2227. vty_out (vty, "%-10s : %-10s%s", zebra_route_string(i),
  2228. proto_rm[AFI_IP][i],
  2229. VTY_NEWLINE);
  2230. else
  2231. vty_out (vty, "%-10s : none%s", zebra_route_string(i), VTY_NEWLINE);
  2232. }
  2233. if (proto_rm[AFI_IP][i])
  2234. vty_out (vty, "%-10s : %-10s%s", "any", proto_rm[AFI_IP][i],
  2235. VTY_NEWLINE);
  2236. else
  2237. vty_out (vty, "%-10s : none%s", "any", VTY_NEWLINE);
  2238. return CMD_SUCCESS;
  2239. }
  2240. #ifdef HAVE_IPV6
  2241. /* General fucntion for IPv6 static route. */
  2242. static int
  2243. static_ipv6_func (struct vty *vty, int add_cmd, const char *dest_str,
  2244. const char *gate_str, const char *ifname,
  2245. const char *flag_str, const char *distance_str,
  2246. const char *vrf_id_str)
  2247. {
  2248. int ret;
  2249. u_char distance;
  2250. struct prefix p;
  2251. struct in6_addr *gate = NULL;
  2252. struct in6_addr gate_addr;
  2253. u_char type = 0;
  2254. vrf_id_t vrf_id = VRF_DEFAULT;
  2255. u_char flag = 0;
  2256. ret = str2prefix (dest_str, &p);
  2257. if (ret <= 0)
  2258. {
  2259. vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
  2260. return CMD_WARNING;
  2261. }
  2262. /* Apply mask for given prefix. */
  2263. apply_mask (&p);
  2264. /* Route flags */
  2265. if (flag_str) {
  2266. switch(flag_str[0]) {
  2267. case 'r':
  2268. case 'R': /* XXX */
  2269. SET_FLAG (flag, ZEBRA_FLAG_REJECT);
  2270. break;
  2271. case 'b':
  2272. case 'B': /* XXX */
  2273. SET_FLAG (flag, ZEBRA_FLAG_BLACKHOLE);
  2274. break;
  2275. default:
  2276. vty_out (vty, "%% Malformed flag %s %s", flag_str, VTY_NEWLINE);
  2277. return CMD_WARNING;
  2278. }
  2279. }
  2280. /* Administrative distance. */
  2281. if (distance_str)
  2282. distance = atoi (distance_str);
  2283. else
  2284. distance = ZEBRA_STATIC_DISTANCE_DEFAULT;
  2285. /* When gateway is valid IPv6 addrees, then gate is treated as
  2286. nexthop address other case gate is treated as interface name. */
  2287. ret = inet_pton (AF_INET6, gate_str, &gate_addr);
  2288. if (ifname)
  2289. {
  2290. /* When ifname is specified. It must be come with gateway
  2291. address. */
  2292. if (ret != 1)
  2293. {
  2294. vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
  2295. return CMD_WARNING;
  2296. }
  2297. type = STATIC_IPV6_GATEWAY_IFNAME;
  2298. gate = &gate_addr;
  2299. }
  2300. else
  2301. {
  2302. if (ret == 1)
  2303. {
  2304. type = STATIC_IPV6_GATEWAY;
  2305. gate = &gate_addr;
  2306. }
  2307. else
  2308. {
  2309. type = STATIC_IPV6_IFNAME;
  2310. ifname = gate_str;
  2311. }
  2312. }
  2313. /* VRF id */
  2314. if (vrf_id_str)
  2315. VTY_GET_INTEGER ("VRF ID", vrf_id, vrf_id_str);
  2316. if (add_cmd)
  2317. static_add_ipv6 (&p, type, gate, ifname, flag, distance, vrf_id);
  2318. else
  2319. static_delete_ipv6 (&p, type, gate, ifname, distance, vrf_id);
  2320. return CMD_SUCCESS;
  2321. }
  2322. DEFUN (ipv6_route,
  2323. ipv6_route_cmd,
  2324. "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)",
  2325. IP_STR
  2326. "Establish static routes\n"
  2327. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2328. "IPv6 gateway address\n"
  2329. "IPv6 gateway interface name\n")
  2330. {
  2331. return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, NULL, NULL,
  2332. NULL);
  2333. }
  2334. DEFUN (ipv6_route_flags,
  2335. ipv6_route_flags_cmd,
  2336. "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole)",
  2337. IP_STR
  2338. "Establish static routes\n"
  2339. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2340. "IPv6 gateway address\n"
  2341. "IPv6 gateway interface name\n"
  2342. "Emit an ICMP unreachable when matched\n"
  2343. "Silently discard pkts when matched\n")
  2344. {
  2345. return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, argv[2], NULL,
  2346. NULL);
  2347. }
  2348. DEFUN (ipv6_route_ifname,
  2349. ipv6_route_ifname_cmd,
  2350. "ipv6 route X:X::X:X/M X:X::X:X INTERFACE",
  2351. IP_STR
  2352. "Establish static routes\n"
  2353. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2354. "IPv6 gateway address\n"
  2355. "IPv6 gateway interface name\n")
  2356. {
  2357. return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], NULL, NULL,
  2358. NULL);
  2359. }
  2360. DEFUN (ipv6_route_ifname_flags,
  2361. ipv6_route_ifname_flags_cmd,
  2362. "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole)",
  2363. IP_STR
  2364. "Establish static routes\n"
  2365. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2366. "IPv6 gateway address\n"
  2367. "IPv6 gateway interface name\n"
  2368. "Emit an ICMP unreachable when matched\n"
  2369. "Silently discard pkts when matched\n")
  2370. {
  2371. return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], argv[3], NULL,
  2372. NULL);
  2373. }
  2374. DEFUN (ipv6_route_pref,
  2375. ipv6_route_pref_cmd,
  2376. "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
  2377. IP_STR
  2378. "Establish static routes\n"
  2379. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2380. "IPv6 gateway address\n"
  2381. "IPv6 gateway interface name\n"
  2382. "Distance value for this prefix\n")
  2383. {
  2384. return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, NULL, argv[2],
  2385. NULL);
  2386. }
  2387. DEFUN (ipv6_route_flags_pref,
  2388. ipv6_route_flags_pref_cmd,
  2389. "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255>",
  2390. IP_STR
  2391. "Establish static routes\n"
  2392. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2393. "IPv6 gateway address\n"
  2394. "IPv6 gateway interface name\n"
  2395. "Emit an ICMP unreachable when matched\n"
  2396. "Silently discard pkts when matched\n"
  2397. "Distance value for this prefix\n")
  2398. {
  2399. return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, argv[2], argv[3],
  2400. NULL);
  2401. }
  2402. DEFUN (ipv6_route_ifname_pref,
  2403. ipv6_route_ifname_pref_cmd,
  2404. "ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
  2405. IP_STR
  2406. "Establish static routes\n"
  2407. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2408. "IPv6 gateway address\n"
  2409. "IPv6 gateway interface name\n"
  2410. "Distance value for this prefix\n")
  2411. {
  2412. return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], NULL, argv[3],
  2413. NULL);
  2414. }
  2415. DEFUN (ipv6_route_ifname_flags_pref,
  2416. ipv6_route_ifname_flags_pref_cmd,
  2417. "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255>",
  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. "Emit an ICMP unreachable when matched\n"
  2424. "Silently discard pkts when matched\n"
  2425. "Distance value for this prefix\n")
  2426. {
  2427. return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], argv[3], argv[4],
  2428. NULL);
  2429. }
  2430. DEFUN (no_ipv6_route,
  2431. no_ipv6_route_cmd,
  2432. "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)",
  2433. NO_STR
  2434. IP_STR
  2435. "Establish static routes\n"
  2436. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2437. "IPv6 gateway address\n"
  2438. "IPv6 gateway interface name\n")
  2439. {
  2440. return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, NULL, NULL,
  2441. NULL);
  2442. }
  2443. ALIAS (no_ipv6_route,
  2444. no_ipv6_route_flags_cmd,
  2445. "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole)",
  2446. NO_STR
  2447. IP_STR
  2448. "Establish static routes\n"
  2449. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2450. "IPv6 gateway address\n"
  2451. "IPv6 gateway interface name\n"
  2452. "Emit an ICMP unreachable when matched\n"
  2453. "Silently discard pkts when matched\n")
  2454. DEFUN (no_ipv6_route_ifname,
  2455. no_ipv6_route_ifname_cmd,
  2456. "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE",
  2457. NO_STR
  2458. IP_STR
  2459. "Establish static routes\n"
  2460. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2461. "IPv6 gateway address\n"
  2462. "IPv6 gateway interface name\n")
  2463. {
  2464. return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], NULL, NULL,
  2465. NULL);
  2466. }
  2467. ALIAS (no_ipv6_route_ifname,
  2468. no_ipv6_route_ifname_flags_cmd,
  2469. "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole)",
  2470. NO_STR
  2471. IP_STR
  2472. "Establish static routes\n"
  2473. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2474. "IPv6 gateway address\n"
  2475. "IPv6 gateway interface name\n"
  2476. "Emit an ICMP unreachable when matched\n"
  2477. "Silently discard pkts when matched\n")
  2478. DEFUN (no_ipv6_route_pref,
  2479. no_ipv6_route_pref_cmd,
  2480. "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
  2481. NO_STR
  2482. IP_STR
  2483. "Establish static routes\n"
  2484. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2485. "IPv6 gateway address\n"
  2486. "IPv6 gateway interface name\n"
  2487. "Distance value for this prefix\n")
  2488. {
  2489. return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, NULL, argv[2],
  2490. NULL);
  2491. }
  2492. DEFUN (no_ipv6_route_flags_pref,
  2493. no_ipv6_route_flags_pref_cmd,
  2494. "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255>",
  2495. NO_STR
  2496. IP_STR
  2497. "Establish static routes\n"
  2498. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2499. "IPv6 gateway address\n"
  2500. "IPv6 gateway interface name\n"
  2501. "Emit an ICMP unreachable when matched\n"
  2502. "Silently discard pkts when matched\n"
  2503. "Distance value for this prefix\n")
  2504. {
  2505. /* We do not care about argv[2] */
  2506. return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, argv[2], argv[3],
  2507. NULL);
  2508. }
  2509. DEFUN (no_ipv6_route_ifname_pref,
  2510. no_ipv6_route_ifname_pref_cmd,
  2511. "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
  2512. NO_STR
  2513. IP_STR
  2514. "Establish static routes\n"
  2515. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2516. "IPv6 gateway address\n"
  2517. "IPv6 gateway interface name\n"
  2518. "Distance value for this prefix\n")
  2519. {
  2520. return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], NULL, argv[3],
  2521. NULL);
  2522. }
  2523. DEFUN (no_ipv6_route_ifname_flags_pref,
  2524. no_ipv6_route_ifname_flags_pref_cmd,
  2525. "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255>",
  2526. NO_STR
  2527. IP_STR
  2528. "Establish static routes\n"
  2529. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2530. "IPv6 gateway address\n"
  2531. "IPv6 gateway interface name\n"
  2532. "Emit an ICMP unreachable when matched\n"
  2533. "Silently discard pkts when matched\n"
  2534. "Distance value for this prefix\n")
  2535. {
  2536. return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], argv[3], argv[4],
  2537. NULL);
  2538. }
  2539. DEFUN (ipv6_route_vrf,
  2540. ipv6_route_vrf_cmd,
  2541. "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) " VRF_CMD_STR,
  2542. IP_STR
  2543. "Establish static routes\n"
  2544. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2545. "IPv6 gateway address\n"
  2546. "IPv6 gateway interface name\n"
  2547. VRF_CMD_HELP_STR)
  2548. {
  2549. return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, NULL, NULL,
  2550. argv[2]);
  2551. }
  2552. DEFUN (ipv6_route_flags_vrf,
  2553. ipv6_route_flags_vrf_cmd,
  2554. "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) " VRF_CMD_STR,
  2555. IP_STR
  2556. "Establish static routes\n"
  2557. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2558. "IPv6 gateway address\n"
  2559. "IPv6 gateway interface name\n"
  2560. "Emit an ICMP unreachable when matched\n"
  2561. "Silently discard pkts when matched\n"
  2562. VRF_CMD_HELP_STR)
  2563. {
  2564. return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, argv[2], NULL,
  2565. argv[3]);
  2566. }
  2567. DEFUN (ipv6_route_ifname_vrf,
  2568. ipv6_route_ifname_vrf_cmd,
  2569. "ipv6 route X:X::X:X/M X:X::X:X INTERFACE " VRF_CMD_STR,
  2570. IP_STR
  2571. "Establish static routes\n"
  2572. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2573. "IPv6 gateway address\n"
  2574. "IPv6 gateway interface name\n"
  2575. VRF_CMD_HELP_STR)
  2576. {
  2577. return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], NULL, NULL,
  2578. argv[3]);
  2579. }
  2580. DEFUN (ipv6_route_ifname_flags_vrf,
  2581. ipv6_route_ifname_flags_vrf_cmd,
  2582. "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) " VRF_CMD_STR,
  2583. IP_STR
  2584. "Establish static routes\n"
  2585. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2586. "IPv6 gateway address\n"
  2587. "IPv6 gateway interface name\n"
  2588. "Emit an ICMP unreachable when matched\n"
  2589. "Silently discard pkts when matched\n"
  2590. VRF_CMD_HELP_STR)
  2591. {
  2592. return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], argv[3], NULL,
  2593. argv[4]);
  2594. }
  2595. DEFUN (ipv6_route_pref_vrf,
  2596. ipv6_route_pref_vrf_cmd,
  2597. "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255> " VRF_CMD_STR,
  2598. IP_STR
  2599. "Establish static routes\n"
  2600. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2601. "IPv6 gateway address\n"
  2602. "IPv6 gateway interface name\n"
  2603. "Distance value for this prefix\n"
  2604. VRF_CMD_HELP_STR)
  2605. {
  2606. return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, NULL, argv[2],
  2607. argv[3]);
  2608. }
  2609. DEFUN (ipv6_route_flags_pref_vrf,
  2610. ipv6_route_flags_pref_vrf_cmd,
  2611. "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255> " VRF_CMD_STR,
  2612. IP_STR
  2613. "Establish static routes\n"
  2614. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2615. "IPv6 gateway address\n"
  2616. "IPv6 gateway interface name\n"
  2617. "Emit an ICMP unreachable when matched\n"
  2618. "Silently discard pkts when matched\n"
  2619. "Distance value for this prefix\n"
  2620. VRF_CMD_HELP_STR)
  2621. {
  2622. return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, argv[2], argv[3],
  2623. argv[4]);
  2624. }
  2625. DEFUN (ipv6_route_ifname_pref_vrf,
  2626. ipv6_route_ifname_pref_vrf_cmd,
  2627. "ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255> " VRF_CMD_STR,
  2628. IP_STR
  2629. "Establish static routes\n"
  2630. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2631. "IPv6 gateway address\n"
  2632. "IPv6 gateway interface name\n"
  2633. "Distance value for this prefix\n"
  2634. VRF_CMD_HELP_STR)
  2635. {
  2636. return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], NULL, argv[3],
  2637. argv[4]);
  2638. }
  2639. DEFUN (ipv6_route_ifname_flags_pref_vrf,
  2640. ipv6_route_ifname_flags_pref_vrf_cmd,
  2641. "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255> " VRF_CMD_STR,
  2642. IP_STR
  2643. "Establish static routes\n"
  2644. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2645. "IPv6 gateway address\n"
  2646. "IPv6 gateway interface name\n"
  2647. "Emit an ICMP unreachable when matched\n"
  2648. "Silently discard pkts when matched\n"
  2649. "Distance value for this prefix\n"
  2650. VRF_CMD_HELP_STR)
  2651. {
  2652. return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], argv[3], argv[4],
  2653. argv[5]);
  2654. }
  2655. DEFUN (no_ipv6_route_vrf,
  2656. no_ipv6_route_vrf_cmd,
  2657. "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) " VRF_CMD_STR,
  2658. NO_STR
  2659. IP_STR
  2660. "Establish static routes\n"
  2661. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2662. "IPv6 gateway address\n"
  2663. "IPv6 gateway interface name\n"
  2664. VRF_CMD_HELP_STR)
  2665. {
  2666. return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, NULL, NULL,
  2667. (argc > 3) ? argv[3] : argv[2]);
  2668. }
  2669. ALIAS (no_ipv6_route_vrf,
  2670. no_ipv6_route_flags_vrf_cmd,
  2671. "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) " VRF_CMD_STR,
  2672. NO_STR
  2673. IP_STR
  2674. "Establish static routes\n"
  2675. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2676. "IPv6 gateway address\n"
  2677. "IPv6 gateway interface name\n"
  2678. "Emit an ICMP unreachable when matched\n"
  2679. "Silently discard pkts when matched\n"
  2680. VRF_CMD_HELP_STR)
  2681. DEFUN (no_ipv6_route_ifname_vrf,
  2682. no_ipv6_route_ifname_vrf_cmd,
  2683. "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE " VRF_CMD_STR,
  2684. NO_STR
  2685. IP_STR
  2686. "Establish static routes\n"
  2687. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2688. "IPv6 gateway address\n"
  2689. "IPv6 gateway interface name\n"
  2690. VRF_CMD_HELP_STR)
  2691. {
  2692. return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], NULL, NULL,
  2693. (argc > 4) ? argv[4] : argv[3]);
  2694. }
  2695. ALIAS (no_ipv6_route_ifname_vrf,
  2696. no_ipv6_route_ifname_flags_vrf_cmd,
  2697. "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) " VRF_CMD_STR,
  2698. NO_STR
  2699. IP_STR
  2700. "Establish static routes\n"
  2701. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2702. "IPv6 gateway address\n"
  2703. "IPv6 gateway interface name\n"
  2704. "Emit an ICMP unreachable when matched\n"
  2705. "Silently discard pkts when matched\n"
  2706. VRF_CMD_HELP_STR)
  2707. DEFUN (no_ipv6_route_pref_vrf,
  2708. no_ipv6_route_pref_vrf_cmd,
  2709. "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255> " VRF_CMD_STR,
  2710. NO_STR
  2711. IP_STR
  2712. "Establish static routes\n"
  2713. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2714. "IPv6 gateway address\n"
  2715. "IPv6 gateway interface name\n"
  2716. "Distance value for this prefix\n"
  2717. VRF_CMD_HELP_STR)
  2718. {
  2719. return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, NULL, argv[2],
  2720. argv[3]);
  2721. }
  2722. DEFUN (no_ipv6_route_flags_pref_vrf,
  2723. no_ipv6_route_flags_pref_vrf_cmd,
  2724. "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255> " 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. "Emit an ICMP unreachable when matched\n"
  2732. "Silently discard pkts when matched\n"
  2733. "Distance value for this prefix\n"
  2734. VRF_CMD_HELP_STR)
  2735. {
  2736. /* We do not care about argv[2] */
  2737. return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, argv[2], argv[3],
  2738. argv[4]);
  2739. }
  2740. DEFUN (no_ipv6_route_ifname_pref_vrf,
  2741. no_ipv6_route_ifname_pref_vrf_cmd,
  2742. "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255> " VRF_CMD_STR,
  2743. NO_STR
  2744. IP_STR
  2745. "Establish static routes\n"
  2746. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2747. "IPv6 gateway address\n"
  2748. "IPv6 gateway interface name\n"
  2749. "Distance value for this prefix\n"
  2750. VRF_CMD_HELP_STR)
  2751. {
  2752. return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], NULL, argv[3],
  2753. argv[4]);
  2754. }
  2755. DEFUN (no_ipv6_route_ifname_flags_pref_vrf,
  2756. no_ipv6_route_ifname_flags_pref_vrf_cmd,
  2757. "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255> " VRF_CMD_STR,
  2758. NO_STR
  2759. IP_STR
  2760. "Establish static routes\n"
  2761. "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
  2762. "IPv6 gateway address\n"
  2763. "IPv6 gateway interface name\n"
  2764. "Emit an ICMP unreachable when matched\n"
  2765. "Silently discard pkts when matched\n"
  2766. "Distance value for this prefix\n"
  2767. VRF_CMD_HELP_STR)
  2768. {
  2769. return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], argv[3], argv[4],
  2770. argv[5]);
  2771. }
  2772. DEFUN (show_ipv6_route,
  2773. show_ipv6_route_cmd,
  2774. "show ipv6 route",
  2775. SHOW_STR
  2776. IP_STR
  2777. "IPv6 routing table\n")
  2778. {
  2779. struct route_table *table;
  2780. struct route_node *rn;
  2781. struct rib *rib;
  2782. int first = 1;
  2783. vrf_id_t vrf_id = VRF_DEFAULT;
  2784. if (argc > 0)
  2785. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
  2786. table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
  2787. if (! table)
  2788. return CMD_SUCCESS;
  2789. /* Show all IPv6 route. */
  2790. for (rn = route_top (table); rn; rn = route_next (rn))
  2791. RNODE_FOREACH_RIB (rn, rib)
  2792. {
  2793. if (first)
  2794. {
  2795. vty_out (vty, SHOW_ROUTE_V6_HEADER);
  2796. first = 0;
  2797. }
  2798. vty_show_ip_route (vty, rn, rib);
  2799. }
  2800. return CMD_SUCCESS;
  2801. }
  2802. ALIAS (show_ipv6_route,
  2803. show_ipv6_route_vrf_cmd,
  2804. "show ipv6 route " VRF_CMD_STR,
  2805. SHOW_STR
  2806. IP_STR
  2807. "IPv6 routing table\n"
  2808. VRF_CMD_HELP_STR)
  2809. DEFUN (show_ipv6_route_prefix_longer,
  2810. show_ipv6_route_prefix_longer_cmd,
  2811. "show ipv6 route X:X::X:X/M longer-prefixes",
  2812. SHOW_STR
  2813. IP_STR
  2814. "IPv6 routing table\n"
  2815. "IPv6 prefix\n"
  2816. "Show route matching the specified Network/Mask pair only\n")
  2817. {
  2818. struct route_table *table;
  2819. struct route_node *rn;
  2820. struct rib *rib;
  2821. struct prefix p;
  2822. int ret;
  2823. int first = 1;
  2824. vrf_id_t vrf_id = VRF_DEFAULT;
  2825. ret = str2prefix (argv[0], &p);
  2826. if (! ret)
  2827. {
  2828. vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
  2829. return CMD_WARNING;
  2830. }
  2831. if (argc > 1)
  2832. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
  2833. table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
  2834. if (! table)
  2835. return CMD_SUCCESS;
  2836. /* Show matched type IPv6 routes. */
  2837. for (rn = route_top (table); rn; rn = route_next (rn))
  2838. RNODE_FOREACH_RIB (rn, rib)
  2839. if (prefix_match (&p, &rn->p))
  2840. {
  2841. if (first)
  2842. {
  2843. vty_out (vty, SHOW_ROUTE_V6_HEADER);
  2844. first = 0;
  2845. }
  2846. vty_show_ip_route (vty, rn, rib);
  2847. }
  2848. return CMD_SUCCESS;
  2849. }
  2850. ALIAS (show_ipv6_route_prefix_longer,
  2851. show_ipv6_route_prefix_longer_vrf_cmd,
  2852. "show ipv6 route X:X::X:X/M longer-prefixes " VRF_CMD_STR,
  2853. SHOW_STR
  2854. IP_STR
  2855. "IPv6 routing table\n"
  2856. "IPv6 prefix\n"
  2857. "Show route matching the specified Network/Mask pair only\n"
  2858. VRF_CMD_HELP_STR)
  2859. DEFUN (show_ipv6_route_protocol,
  2860. show_ipv6_route_protocol_cmd,
  2861. "show ipv6 route " QUAGGA_IP6_REDIST_STR_ZEBRA,
  2862. SHOW_STR
  2863. IP_STR
  2864. "IP routing table\n"
  2865. QUAGGA_IP6_REDIST_HELP_STR_ZEBRA)
  2866. {
  2867. int type;
  2868. struct route_table *table;
  2869. struct route_node *rn;
  2870. struct rib *rib;
  2871. int first = 1;
  2872. vrf_id_t vrf_id = VRF_DEFAULT;
  2873. type = proto_redistnum (AFI_IP6, argv[0]);
  2874. if (type < 0)
  2875. {
  2876. vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
  2877. return CMD_WARNING;
  2878. }
  2879. if (argc > 1)
  2880. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
  2881. table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
  2882. if (! table)
  2883. return CMD_SUCCESS;
  2884. /* Show matched type IPv6 routes. */
  2885. for (rn = route_top (table); rn; rn = route_next (rn))
  2886. RNODE_FOREACH_RIB (rn, rib)
  2887. if (rib->type == type)
  2888. {
  2889. if (first)
  2890. {
  2891. vty_out (vty, SHOW_ROUTE_V6_HEADER);
  2892. first = 0;
  2893. }
  2894. vty_show_ip_route (vty, rn, rib);
  2895. }
  2896. return CMD_SUCCESS;
  2897. }
  2898. ALIAS (show_ipv6_route_protocol,
  2899. show_ipv6_route_protocol_vrf_cmd,
  2900. "show ipv6 route " QUAGGA_IP6_REDIST_STR_ZEBRA " " VRF_CMD_STR,
  2901. SHOW_STR
  2902. IP_STR
  2903. "IP routing table\n"
  2904. QUAGGA_IP6_REDIST_HELP_STR_ZEBRA
  2905. VRF_CMD_HELP_STR)
  2906. DEFUN (show_ipv6_route_addr,
  2907. show_ipv6_route_addr_cmd,
  2908. "show ipv6 route X:X::X:X",
  2909. SHOW_STR
  2910. IP_STR
  2911. "IPv6 routing table\n"
  2912. "IPv6 Address\n")
  2913. {
  2914. int ret;
  2915. struct prefix_ipv6 p;
  2916. struct route_table *table;
  2917. struct route_node *rn;
  2918. vrf_id_t vrf_id = VRF_DEFAULT;
  2919. ret = str2prefix_ipv6 (argv[0], &p);
  2920. if (ret <= 0)
  2921. {
  2922. vty_out (vty, "Malformed IPv6 address%s", VTY_NEWLINE);
  2923. return CMD_WARNING;
  2924. }
  2925. if (argc > 1)
  2926. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
  2927. table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
  2928. if (! table)
  2929. return CMD_SUCCESS;
  2930. rn = route_node_match (table, (struct prefix *) &p);
  2931. if (! rn)
  2932. {
  2933. vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
  2934. return CMD_WARNING;
  2935. }
  2936. vty_show_ip_route_detail (vty, rn, 0);
  2937. route_unlock_node (rn);
  2938. return CMD_SUCCESS;
  2939. }
  2940. ALIAS (show_ipv6_route_addr,
  2941. show_ipv6_route_addr_vrf_cmd,
  2942. "show ipv6 route X:X::X:X " VRF_CMD_STR,
  2943. SHOW_STR
  2944. IP_STR
  2945. "IPv6 routing table\n"
  2946. "IPv6 Address\n"
  2947. VRF_CMD_HELP_STR)
  2948. DEFUN (show_ipv6_route_prefix,
  2949. show_ipv6_route_prefix_cmd,
  2950. "show ipv6 route X:X::X:X/M",
  2951. SHOW_STR
  2952. IP_STR
  2953. "IPv6 routing table\n"
  2954. "IPv6 prefix\n")
  2955. {
  2956. int ret;
  2957. struct prefix_ipv6 p;
  2958. struct route_table *table;
  2959. struct route_node *rn;
  2960. vrf_id_t vrf_id = VRF_DEFAULT;
  2961. ret = str2prefix_ipv6 (argv[0], &p);
  2962. if (ret <= 0)
  2963. {
  2964. vty_out (vty, "Malformed IPv6 prefix%s", VTY_NEWLINE);
  2965. return CMD_WARNING;
  2966. }
  2967. if (argc > 1)
  2968. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
  2969. table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
  2970. if (! table)
  2971. return CMD_SUCCESS;
  2972. rn = route_node_match (table, (struct prefix *) &p);
  2973. if (! rn || rn->p.prefixlen != p.prefixlen)
  2974. {
  2975. vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
  2976. if (rn)
  2977. route_unlock_node (rn);
  2978. return CMD_WARNING;
  2979. }
  2980. vty_show_ip_route_detail (vty, rn, 0);
  2981. route_unlock_node (rn);
  2982. return CMD_SUCCESS;
  2983. }
  2984. ALIAS (show_ipv6_route_prefix,
  2985. show_ipv6_route_prefix_vrf_cmd,
  2986. "show ipv6 route X:X::X:X/M " VRF_CMD_STR,
  2987. SHOW_STR
  2988. IP_STR
  2989. "IPv6 routing table\n"
  2990. "IPv6 prefix\n"
  2991. VRF_CMD_HELP_STR)
  2992. /* Show route summary. */
  2993. DEFUN (show_ipv6_route_summary,
  2994. show_ipv6_route_summary_cmd,
  2995. "show ipv6 route summary",
  2996. SHOW_STR
  2997. IP_STR
  2998. "IPv6 routing table\n"
  2999. "Summary of all IPv6 routes\n")
  3000. {
  3001. struct route_table *table;
  3002. vrf_id_t vrf_id = VRF_DEFAULT;
  3003. if (argc > 0)
  3004. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
  3005. table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
  3006. if (! table)
  3007. return CMD_SUCCESS;
  3008. vty_show_ip_route_summary (vty, table);
  3009. return CMD_SUCCESS;
  3010. }
  3011. ALIAS (show_ipv6_route_summary,
  3012. show_ipv6_route_summary_vrf_cmd,
  3013. "show ipv6 route summary " VRF_CMD_STR,
  3014. SHOW_STR
  3015. IP_STR
  3016. "IPv6 routing table\n"
  3017. "Summary of all IPv6 routes\n"
  3018. VRF_CMD_HELP_STR)
  3019. /* Show ipv6 route summary prefix. */
  3020. DEFUN (show_ipv6_route_summary_prefix,
  3021. show_ipv6_route_summary_prefix_cmd,
  3022. "show ipv6 route summary prefix",
  3023. SHOW_STR
  3024. IP_STR
  3025. "IPv6 routing table\n"
  3026. "Summary of all IPv6 routes\n"
  3027. "Prefix routes\n")
  3028. {
  3029. struct route_table *table;
  3030. vrf_id_t vrf_id = VRF_DEFAULT;
  3031. if (argc > 0)
  3032. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
  3033. table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
  3034. if (! table)
  3035. return CMD_SUCCESS;
  3036. vty_show_ip_route_summary_prefix (vty, table);
  3037. return CMD_SUCCESS;
  3038. }
  3039. ALIAS (show_ipv6_route_summary_prefix,
  3040. show_ipv6_route_summary_prefix_vrf_cmd,
  3041. "show ipv6 route summary prefix " VRF_CMD_STR,
  3042. SHOW_STR
  3043. IP_STR
  3044. "IPv6 routing table\n"
  3045. "Summary of all IPv6 routes\n"
  3046. "Prefix routes\n"
  3047. VRF_CMD_HELP_STR)
  3048. /*
  3049. * Show IPv6 mroute command.Used to dump
  3050. * the Multicast routing table.
  3051. */
  3052. DEFUN (show_ipv6_mroute,
  3053. show_ipv6_mroute_cmd,
  3054. "show ipv6 mroute",
  3055. SHOW_STR
  3056. IP_STR
  3057. "IPv6 Multicast routing table\n")
  3058. {
  3059. struct route_table *table;
  3060. struct route_node *rn;
  3061. struct rib *rib;
  3062. int first = 1;
  3063. vrf_id_t vrf_id = VRF_DEFAULT;
  3064. if (argc > 0)
  3065. VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
  3066. table = zebra_vrf_table (AFI_IP6, SAFI_MULTICAST, vrf_id);
  3067. if (! table)
  3068. return CMD_SUCCESS;
  3069. /* Show all IPv6 route. */
  3070. for (rn = route_top (table); rn; rn = route_next (rn))
  3071. RNODE_FOREACH_RIB (rn, rib)
  3072. {
  3073. if (first)
  3074. {
  3075. vty_out (vty, SHOW_ROUTE_V6_HEADER);
  3076. first = 0;
  3077. }
  3078. vty_show_ip_route (vty, rn, rib);
  3079. }
  3080. return CMD_SUCCESS;
  3081. }
  3082. ALIAS (show_ipv6_mroute,
  3083. show_ipv6_mroute_vrf_cmd,
  3084. "show ipv6 mroute " VRF_CMD_STR,
  3085. SHOW_STR
  3086. IP_STR
  3087. "IPv6 Multicast routing table\n"
  3088. VRF_CMD_HELP_STR)
  3089. DEFUN (show_ipv6_route_vrf_all,
  3090. show_ipv6_route_vrf_all_cmd,
  3091. "show ipv6 route " VRF_ALL_CMD_STR,
  3092. SHOW_STR
  3093. IP_STR
  3094. "IPv6 routing table\n"
  3095. VRF_ALL_CMD_HELP_STR)
  3096. {
  3097. struct route_table *table;
  3098. struct route_node *rn;
  3099. struct rib *rib;
  3100. struct zebra_vrf *zvrf;
  3101. vrf_iter_t iter;
  3102. int first = 1;
  3103. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  3104. {
  3105. if ((zvrf = vrf_iter2info (iter)) == NULL ||
  3106. (table = zvrf->table[AFI_IP6][SAFI_UNICAST]) == NULL)
  3107. continue;
  3108. /* Show all IPv6 route. */
  3109. for (rn = route_top (table); rn; rn = route_next (rn))
  3110. RNODE_FOREACH_RIB (rn, rib)
  3111. {
  3112. if (first)
  3113. {
  3114. vty_out (vty, SHOW_ROUTE_V6_HEADER);
  3115. first = 0;
  3116. }
  3117. vty_show_ip_route (vty, rn, rib);
  3118. }
  3119. }
  3120. return CMD_SUCCESS;
  3121. }
  3122. DEFUN (show_ipv6_route_prefix_longer_vrf_all,
  3123. show_ipv6_route_prefix_longer_vrf_all_cmd,
  3124. "show ipv6 route X:X::X:X/M longer-prefixes " VRF_ALL_CMD_STR,
  3125. SHOW_STR
  3126. IP_STR
  3127. "IPv6 routing table\n"
  3128. "IPv6 prefix\n"
  3129. "Show route matching the specified Network/Mask pair only\n"
  3130. VRF_ALL_CMD_HELP_STR)
  3131. {
  3132. struct route_table *table;
  3133. struct route_node *rn;
  3134. struct rib *rib;
  3135. struct prefix p;
  3136. struct zebra_vrf *zvrf;
  3137. vrf_iter_t iter;
  3138. int ret;
  3139. int first = 1;
  3140. ret = str2prefix (argv[0], &p);
  3141. if (! ret)
  3142. {
  3143. vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
  3144. return CMD_WARNING;
  3145. }
  3146. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  3147. {
  3148. if ((zvrf = vrf_iter2info (iter)) == NULL ||
  3149. (table = zvrf->table[AFI_IP6][SAFI_UNICAST]) == NULL)
  3150. continue;
  3151. /* Show matched type IPv6 routes. */
  3152. for (rn = route_top (table); rn; rn = route_next (rn))
  3153. RNODE_FOREACH_RIB (rn, rib)
  3154. if (prefix_match (&p, &rn->p))
  3155. {
  3156. if (first)
  3157. {
  3158. vty_out (vty, SHOW_ROUTE_V6_HEADER);
  3159. first = 0;
  3160. }
  3161. vty_show_ip_route (vty, rn, rib);
  3162. }
  3163. }
  3164. return CMD_SUCCESS;
  3165. }
  3166. DEFUN (show_ipv6_route_protocol_vrf_all,
  3167. show_ipv6_route_protocol_vrf_all_cmd,
  3168. "show ipv6 route " QUAGGA_IP6_REDIST_STR_ZEBRA " " VRF_ALL_CMD_STR,
  3169. SHOW_STR
  3170. IP_STR
  3171. "IP routing table\n"
  3172. QUAGGA_IP6_REDIST_HELP_STR_ZEBRA
  3173. VRF_ALL_CMD_HELP_STR)
  3174. {
  3175. int type;
  3176. struct route_table *table;
  3177. struct route_node *rn;
  3178. struct rib *rib;
  3179. struct zebra_vrf *zvrf;
  3180. vrf_iter_t iter;
  3181. int first = 1;
  3182. type = proto_redistnum (AFI_IP6, argv[0]);
  3183. if (type < 0)
  3184. {
  3185. vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
  3186. return CMD_WARNING;
  3187. }
  3188. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  3189. {
  3190. if ((zvrf = vrf_iter2info (iter)) == NULL ||
  3191. (table = zvrf->table[AFI_IP6][SAFI_UNICAST]) == NULL)
  3192. continue;
  3193. /* Show matched type IPv6 routes. */
  3194. for (rn = route_top (table); rn; rn = route_next (rn))
  3195. RNODE_FOREACH_RIB (rn, rib)
  3196. if (rib->type == type)
  3197. {
  3198. if (first)
  3199. {
  3200. vty_out (vty, SHOW_ROUTE_V6_HEADER);
  3201. first = 0;
  3202. }
  3203. vty_show_ip_route (vty, rn, rib);
  3204. }
  3205. }
  3206. return CMD_SUCCESS;
  3207. }
  3208. DEFUN (show_ipv6_route_addr_vrf_all,
  3209. show_ipv6_route_addr_vrf_all_cmd,
  3210. "show ipv6 route X:X::X:X " VRF_ALL_CMD_STR,
  3211. SHOW_STR
  3212. IP_STR
  3213. "IPv6 routing table\n"
  3214. "IPv6 Address\n"
  3215. VRF_ALL_CMD_HELP_STR)
  3216. {
  3217. int ret;
  3218. struct prefix_ipv6 p;
  3219. struct route_table *table;
  3220. struct route_node *rn;
  3221. struct zebra_vrf *zvrf;
  3222. vrf_iter_t iter;
  3223. ret = str2prefix_ipv6 (argv[0], &p);
  3224. if (ret <= 0)
  3225. {
  3226. vty_out (vty, "Malformed IPv6 address%s", VTY_NEWLINE);
  3227. return CMD_WARNING;
  3228. }
  3229. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  3230. {
  3231. if ((zvrf = vrf_iter2info (iter)) == NULL ||
  3232. (table = zvrf->table[AFI_IP6][SAFI_UNICAST]) == NULL)
  3233. continue;
  3234. rn = route_node_match (table, (struct prefix *) &p);
  3235. if (! rn)
  3236. continue;
  3237. vty_show_ip_route_detail (vty, rn, 0);
  3238. route_unlock_node (rn);
  3239. }
  3240. return CMD_SUCCESS;
  3241. }
  3242. DEFUN (show_ipv6_route_prefix_vrf_all,
  3243. show_ipv6_route_prefix_vrf_all_cmd,
  3244. "show ipv6 route X:X::X:X/M " VRF_ALL_CMD_STR,
  3245. SHOW_STR
  3246. IP_STR
  3247. "IPv6 routing table\n"
  3248. "IPv6 prefix\n"
  3249. VRF_ALL_CMD_HELP_STR)
  3250. {
  3251. int ret;
  3252. struct prefix_ipv6 p;
  3253. struct route_table *table;
  3254. struct route_node *rn;
  3255. struct zebra_vrf *zvrf;
  3256. vrf_iter_t iter;
  3257. ret = str2prefix_ipv6 (argv[0], &p);
  3258. if (ret <= 0)
  3259. {
  3260. vty_out (vty, "Malformed IPv6 prefix%s", VTY_NEWLINE);
  3261. return CMD_WARNING;
  3262. }
  3263. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  3264. {
  3265. if ((zvrf = vrf_iter2info (iter)) == NULL ||
  3266. (table = zvrf->table[AFI_IP6][SAFI_UNICAST]) == NULL)
  3267. continue;
  3268. rn = route_node_match (table, (struct prefix *) &p);
  3269. if (! rn)
  3270. continue;
  3271. if (rn->p.prefixlen != p.prefixlen)
  3272. {
  3273. route_unlock_node (rn);
  3274. continue;
  3275. }
  3276. vty_show_ip_route_detail (vty, rn, 0);
  3277. route_unlock_node (rn);
  3278. }
  3279. return CMD_SUCCESS;
  3280. }
  3281. /* Show route summary. */
  3282. DEFUN (show_ipv6_route_summary_vrf_all,
  3283. show_ipv6_route_summary_vrf_all_cmd,
  3284. "show ipv6 route summary " VRF_ALL_CMD_STR,
  3285. SHOW_STR
  3286. IP_STR
  3287. "IPv6 routing table\n"
  3288. "Summary of all IPv6 routes\n"
  3289. VRF_ALL_CMD_HELP_STR)
  3290. {
  3291. struct zebra_vrf *zvrf;
  3292. vrf_iter_t iter;
  3293. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  3294. if ((zvrf = vrf_iter2info (iter)) != NULL)
  3295. vty_show_ip_route_summary (vty, zvrf->table[AFI_IP6][SAFI_UNICAST]);
  3296. return CMD_SUCCESS;
  3297. }
  3298. DEFUN (show_ipv6_mroute_vrf_all,
  3299. show_ipv6_mroute_vrf_all_cmd,
  3300. "show ipv6 mroute " VRF_ALL_CMD_STR,
  3301. SHOW_STR
  3302. IP_STR
  3303. "IPv6 Multicast routing table\n"
  3304. VRF_ALL_CMD_HELP_STR)
  3305. {
  3306. struct route_table *table;
  3307. struct route_node *rn;
  3308. struct rib *rib;
  3309. struct zebra_vrf *zvrf;
  3310. vrf_iter_t iter;
  3311. int first = 1;
  3312. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  3313. {
  3314. if ((zvrf = vrf_iter2info (iter)) == NULL ||
  3315. (table = zvrf->table[AFI_IP6][SAFI_UNICAST]) == NULL)
  3316. continue;
  3317. /* Show all IPv6 route. */
  3318. for (rn = route_top (table); rn; rn = route_next (rn))
  3319. RNODE_FOREACH_RIB (rn, rib)
  3320. {
  3321. if (first)
  3322. {
  3323. vty_out (vty, SHOW_ROUTE_V6_HEADER);
  3324. first = 0;
  3325. }
  3326. vty_show_ip_route (vty, rn, rib);
  3327. }
  3328. }
  3329. return CMD_SUCCESS;
  3330. }
  3331. DEFUN (show_ipv6_route_summary_prefix_vrf_all,
  3332. show_ipv6_route_summary_prefix_vrf_all_cmd,
  3333. "show ipv6 route summary prefix " VRF_ALL_CMD_STR,
  3334. SHOW_STR
  3335. IP_STR
  3336. "IPv6 routing table\n"
  3337. "Summary of all IPv6 routes\n"
  3338. "Prefix routes\n"
  3339. VRF_ALL_CMD_HELP_STR)
  3340. {
  3341. struct zebra_vrf *zvrf;
  3342. vrf_iter_t iter;
  3343. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  3344. if ((zvrf = vrf_iter2info (iter)) != NULL)
  3345. vty_show_ip_route_summary_prefix (vty, zvrf->table[AFI_IP6][SAFI_UNICAST]);
  3346. return CMD_SUCCESS;
  3347. }
  3348. /* Write IPv6 static route configuration. */
  3349. static int
  3350. static_config_ipv6 (struct vty *vty)
  3351. {
  3352. struct route_node *rn;
  3353. struct static_route *si;
  3354. int write;
  3355. char buf[BUFSIZ];
  3356. struct route_table *stable;
  3357. struct zebra_vrf *zvrf;
  3358. vrf_iter_t iter;
  3359. write = 0;
  3360. for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  3361. {
  3362. if ((zvrf = vrf_iter2info (iter)) == NULL ||
  3363. (stable = zvrf->stable[AFI_IP6][SAFI_UNICAST]) == NULL)
  3364. continue;
  3365. for (rn = route_top (stable); rn; rn = route_next (rn))
  3366. for (si = rn->info; si; si = si->next)
  3367. {
  3368. vty_out (vty, "ipv6 route %s", prefix2str (&rn->p, buf, sizeof buf));
  3369. switch (si->type)
  3370. {
  3371. case STATIC_IPV6_GATEWAY:
  3372. vty_out (vty, " %s",
  3373. inet_ntop (AF_INET6, &si->addr.ipv6, buf, BUFSIZ));
  3374. break;
  3375. case STATIC_IPV6_IFNAME:
  3376. vty_out (vty, " %s", si->ifname);
  3377. break;
  3378. case STATIC_IPV6_GATEWAY_IFNAME:
  3379. vty_out (vty, " %s %s",
  3380. inet_ntop (AF_INET6, &si->addr.ipv6, buf, BUFSIZ),
  3381. si->ifname);
  3382. break;
  3383. }
  3384. if (CHECK_FLAG(si->flags, ZEBRA_FLAG_REJECT))
  3385. vty_out (vty, " %s", "reject");
  3386. if (CHECK_FLAG(si->flags, ZEBRA_FLAG_BLACKHOLE))
  3387. vty_out (vty, " %s", "blackhole");
  3388. if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT)
  3389. vty_out (vty, " %d", si->distance);
  3390. if (si->vrf_id != VRF_DEFAULT)
  3391. vty_out (vty, " vrf %u", si->vrf_id);
  3392. vty_out (vty, "%s", VTY_NEWLINE);
  3393. write = 1;
  3394. }
  3395. }
  3396. return write;
  3397. }
  3398. #endif /* HAVE_IPV6 */
  3399. /* Static ip route configuration write function. */
  3400. static int
  3401. zebra_ip_config (struct vty *vty)
  3402. {
  3403. int write = 0;
  3404. write += static_config_ipv4 (vty, SAFI_UNICAST, "ip route");
  3405. write += static_config_ipv4 (vty, SAFI_MULTICAST, "ip mroute");
  3406. #ifdef HAVE_IPV6
  3407. write += static_config_ipv6 (vty);
  3408. #endif /* HAVE_IPV6 */
  3409. return write;
  3410. }
  3411. static int config_write_vty(struct vty *vty)
  3412. {
  3413. int i;
  3414. enum multicast_mode ipv4_multicast_mode = multicast_mode_ipv4_get ();
  3415. if (ipv4_multicast_mode != MCAST_NO_CONFIG)
  3416. vty_out (vty, "ip multicast rpf-lookup-mode %s%s",
  3417. ipv4_multicast_mode == MCAST_URIB_ONLY ? "urib-only" :
  3418. ipv4_multicast_mode == MCAST_MRIB_ONLY ? "mrib-only" :
  3419. ipv4_multicast_mode == MCAST_MIX_MRIB_FIRST ? "mrib-then-urib" :
  3420. ipv4_multicast_mode == MCAST_MIX_DISTANCE ? "lower-distance" :
  3421. "longer-prefix",
  3422. VTY_NEWLINE);
  3423. for (i=0;i<ZEBRA_ROUTE_MAX;i++)
  3424. {
  3425. if (proto_rm[AFI_IP][i])
  3426. vty_out (vty, "ip protocol %s route-map %s%s", zebra_route_string(i),
  3427. proto_rm[AFI_IP][i], VTY_NEWLINE);
  3428. }
  3429. if (proto_rm[AFI_IP][ZEBRA_ROUTE_MAX])
  3430. vty_out (vty, "ip protocol %s route-map %s%s", "any",
  3431. proto_rm[AFI_IP][ZEBRA_ROUTE_MAX], VTY_NEWLINE);
  3432. return 1;
  3433. }
  3434. /* table node for protocol filtering */
  3435. static struct cmd_node protocol_node = { PROTOCOL_NODE, "", 1 };
  3436. /* IP node for static routes. */
  3437. static struct cmd_node ip_node = { IP_NODE, "", 1 };
  3438. /* Route VTY. */
  3439. void
  3440. zebra_vty_init (void)
  3441. {
  3442. install_node (&ip_node, zebra_ip_config);
  3443. install_node (&protocol_node, config_write_vty);
  3444. install_element (CONFIG_NODE, &ip_mroute_cmd);
  3445. install_element (CONFIG_NODE, &ip_mroute_dist_cmd);
  3446. install_element (CONFIG_NODE, &no_ip_mroute_cmd);
  3447. install_element (CONFIG_NODE, &no_ip_mroute_dist_cmd);
  3448. install_element (CONFIG_NODE, &ip_multicast_mode_cmd);
  3449. install_element (CONFIG_NODE, &no_ip_multicast_mode_cmd);
  3450. install_element (CONFIG_NODE, &no_ip_multicast_mode_noarg_cmd);
  3451. install_element (CONFIG_NODE, &ip_protocol_cmd);
  3452. install_element (CONFIG_NODE, &no_ip_protocol_cmd);
  3453. install_element (VIEW_NODE, &show_ip_protocol_cmd);
  3454. install_element (CONFIG_NODE, &ip_route_cmd);
  3455. install_element (CONFIG_NODE, &ip_route_flags_cmd);
  3456. install_element (CONFIG_NODE, &ip_route_flags2_cmd);
  3457. install_element (CONFIG_NODE, &ip_route_mask_cmd);
  3458. install_element (CONFIG_NODE, &ip_route_mask_flags_cmd);
  3459. install_element (CONFIG_NODE, &ip_route_mask_flags2_cmd);
  3460. install_element (CONFIG_NODE, &no_ip_route_cmd);
  3461. install_element (CONFIG_NODE, &no_ip_route_flags_cmd);
  3462. install_element (CONFIG_NODE, &no_ip_route_flags2_cmd);
  3463. install_element (CONFIG_NODE, &no_ip_route_mask_cmd);
  3464. install_element (CONFIG_NODE, &no_ip_route_mask_flags_cmd);
  3465. install_element (CONFIG_NODE, &no_ip_route_mask_flags2_cmd);
  3466. install_element (CONFIG_NODE, &ip_route_distance_cmd);
  3467. install_element (CONFIG_NODE, &ip_route_flags_distance_cmd);
  3468. install_element (CONFIG_NODE, &ip_route_flags_distance2_cmd);
  3469. install_element (CONFIG_NODE, &ip_route_mask_distance_cmd);
  3470. install_element (CONFIG_NODE, &ip_route_mask_flags_distance_cmd);
  3471. install_element (CONFIG_NODE, &ip_route_mask_flags_distance2_cmd);
  3472. install_element (CONFIG_NODE, &no_ip_route_distance_cmd);
  3473. install_element (CONFIG_NODE, &no_ip_route_flags_distance_cmd);
  3474. install_element (CONFIG_NODE, &no_ip_route_flags_distance2_cmd);
  3475. install_element (CONFIG_NODE, &no_ip_route_mask_distance_cmd);
  3476. install_element (CONFIG_NODE, &no_ip_route_mask_flags_distance_cmd);
  3477. install_element (CONFIG_NODE, &no_ip_route_mask_flags_distance2_cmd);
  3478. install_element (VIEW_NODE, &show_ip_route_cmd);
  3479. install_element (VIEW_NODE, &show_ip_route_addr_cmd);
  3480. install_element (VIEW_NODE, &show_ip_route_prefix_cmd);
  3481. install_element (VIEW_NODE, &show_ip_route_prefix_longer_cmd);
  3482. install_element (VIEW_NODE, &show_ip_route_protocol_cmd);
  3483. install_element (VIEW_NODE, &show_ip_route_supernets_cmd);
  3484. install_element (VIEW_NODE, &show_ip_route_summary_cmd);
  3485. install_element (VIEW_NODE, &show_ip_route_summary_prefix_cmd);
  3486. install_element (VIEW_NODE, &show_ip_rpf_cmd);
  3487. install_element (VIEW_NODE, &show_ip_rpf_addr_cmd);
  3488. /* Commands for VRF */
  3489. install_element (CONFIG_NODE, &ip_mroute_vrf_cmd);
  3490. install_element (CONFIG_NODE, &ip_mroute_dist_vrf_cmd);
  3491. install_element (CONFIG_NODE, &no_ip_mroute_vrf_cmd);
  3492. install_element (CONFIG_NODE, &no_ip_mroute_dist_vrf_cmd);
  3493. install_element (CONFIG_NODE, &ip_route_vrf_cmd);
  3494. install_element (CONFIG_NODE, &ip_route_flags_vrf_cmd);
  3495. install_element (CONFIG_NODE, &ip_route_flags2_vrf_cmd);
  3496. install_element (CONFIG_NODE, &ip_route_mask_vrf_cmd);
  3497. install_element (CONFIG_NODE, &ip_route_mask_flags_vrf_cmd);
  3498. install_element (CONFIG_NODE, &ip_route_mask_flags2_vrf_cmd);
  3499. install_element (CONFIG_NODE, &no_ip_route_vrf_cmd);
  3500. install_element (CONFIG_NODE, &no_ip_route_flags_vrf_cmd);
  3501. install_element (CONFIG_NODE, &no_ip_route_flags2_vrf_cmd);
  3502. install_element (CONFIG_NODE, &no_ip_route_mask_vrf_cmd);
  3503. install_element (CONFIG_NODE, &no_ip_route_mask_flags_vrf_cmd);
  3504. install_element (CONFIG_NODE, &no_ip_route_mask_flags2_vrf_cmd);
  3505. install_element (CONFIG_NODE, &ip_route_distance_vrf_cmd);
  3506. install_element (CONFIG_NODE, &ip_route_flags_distance_vrf_cmd);
  3507. install_element (CONFIG_NODE, &ip_route_flags_distance2_vrf_cmd);
  3508. install_element (CONFIG_NODE, &ip_route_mask_distance_vrf_cmd);
  3509. install_element (CONFIG_NODE, &ip_route_mask_flags_distance_vrf_cmd);
  3510. install_element (CONFIG_NODE, &ip_route_mask_flags_distance2_vrf_cmd);
  3511. install_element (CONFIG_NODE, &no_ip_route_distance_vrf_cmd);
  3512. install_element (CONFIG_NODE, &no_ip_route_flags_distance_vrf_cmd);
  3513. install_element (CONFIG_NODE, &no_ip_route_flags_distance2_vrf_cmd);
  3514. install_element (CONFIG_NODE, &no_ip_route_mask_distance_vrf_cmd);
  3515. install_element (CONFIG_NODE, &no_ip_route_mask_flags_distance_vrf_cmd);
  3516. install_element (CONFIG_NODE, &no_ip_route_mask_flags_distance2_vrf_cmd);
  3517. install_element (VIEW_NODE, &show_ip_route_vrf_cmd);
  3518. install_element (VIEW_NODE, &show_ip_route_addr_vrf_cmd);
  3519. install_element (VIEW_NODE, &show_ip_route_prefix_vrf_cmd);
  3520. install_element (VIEW_NODE, &show_ip_route_prefix_longer_vrf_cmd);
  3521. install_element (VIEW_NODE, &show_ip_route_protocol_vrf_cmd);
  3522. install_element (VIEW_NODE, &show_ip_route_supernets_vrf_cmd);
  3523. install_element (VIEW_NODE, &show_ip_route_summary_vrf_cmd);
  3524. install_element (VIEW_NODE, &show_ip_route_summary_prefix_vrf_cmd);
  3525. install_element (VIEW_NODE, &show_ip_route_vrf_all_cmd);
  3526. install_element (VIEW_NODE, &show_ip_route_addr_vrf_all_cmd);
  3527. install_element (VIEW_NODE, &show_ip_route_prefix_vrf_all_cmd);
  3528. install_element (VIEW_NODE, &show_ip_route_prefix_longer_vrf_all_cmd);
  3529. install_element (VIEW_NODE, &show_ip_route_protocol_vrf_all_cmd);
  3530. install_element (VIEW_NODE, &show_ip_route_supernets_vrf_all_cmd);
  3531. install_element (VIEW_NODE, &show_ip_route_summary_vrf_all_cmd);
  3532. install_element (VIEW_NODE, &show_ip_route_summary_prefix_vrf_all_cmd);
  3533. install_element (VIEW_NODE, &show_ip_rpf_vrf_cmd);
  3534. install_element (VIEW_NODE, &show_ip_rpf_vrf_all_cmd);
  3535. install_element (VIEW_NODE, &show_ip_rpf_addr_vrf_cmd);
  3536. install_element (VIEW_NODE, &show_ip_rpf_addr_vrf_all_cmd);
  3537. install_element (CONFIG_NODE, &ipv6_route_cmd);
  3538. install_element (CONFIG_NODE, &ipv6_route_flags_cmd);
  3539. install_element (CONFIG_NODE, &ipv6_route_ifname_cmd);
  3540. install_element (CONFIG_NODE, &ipv6_route_ifname_flags_cmd);
  3541. install_element (CONFIG_NODE, &no_ipv6_route_cmd);
  3542. install_element (CONFIG_NODE, &no_ipv6_route_flags_cmd);
  3543. install_element (CONFIG_NODE, &no_ipv6_route_ifname_cmd);
  3544. install_element (CONFIG_NODE, &no_ipv6_route_ifname_flags_cmd);
  3545. install_element (CONFIG_NODE, &ipv6_route_pref_cmd);
  3546. install_element (CONFIG_NODE, &ipv6_route_flags_pref_cmd);
  3547. install_element (CONFIG_NODE, &ipv6_route_ifname_pref_cmd);
  3548. install_element (CONFIG_NODE, &ipv6_route_ifname_flags_pref_cmd);
  3549. install_element (CONFIG_NODE, &no_ipv6_route_pref_cmd);
  3550. install_element (CONFIG_NODE, &no_ipv6_route_flags_pref_cmd);
  3551. install_element (CONFIG_NODE, &no_ipv6_route_ifname_pref_cmd);
  3552. install_element (CONFIG_NODE, &no_ipv6_route_ifname_flags_pref_cmd);
  3553. install_element (VIEW_NODE, &show_ipv6_route_cmd);
  3554. install_element (VIEW_NODE, &show_ipv6_route_summary_cmd);
  3555. install_element (VIEW_NODE, &show_ipv6_route_summary_prefix_cmd);
  3556. install_element (VIEW_NODE, &show_ipv6_route_protocol_cmd);
  3557. install_element (VIEW_NODE, &show_ipv6_route_addr_cmd);
  3558. install_element (VIEW_NODE, &show_ipv6_route_prefix_cmd);
  3559. install_element (VIEW_NODE, &show_ipv6_route_prefix_longer_cmd);
  3560. install_element (VIEW_NODE, &show_ipv6_mroute_cmd);
  3561. /* Commands for VRF */
  3562. install_element (CONFIG_NODE, &ipv6_route_vrf_cmd);
  3563. install_element (CONFIG_NODE, &ipv6_route_flags_vrf_cmd);
  3564. install_element (CONFIG_NODE, &ipv6_route_ifname_vrf_cmd);
  3565. install_element (CONFIG_NODE, &ipv6_route_ifname_flags_vrf_cmd);
  3566. install_element (CONFIG_NODE, &no_ipv6_route_vrf_cmd);
  3567. install_element (CONFIG_NODE, &no_ipv6_route_flags_vrf_cmd);
  3568. install_element (CONFIG_NODE, &no_ipv6_route_ifname_vrf_cmd);
  3569. install_element (CONFIG_NODE, &no_ipv6_route_ifname_flags_vrf_cmd);
  3570. install_element (CONFIG_NODE, &ipv6_route_pref_vrf_cmd);
  3571. install_element (CONFIG_NODE, &ipv6_route_flags_pref_vrf_cmd);
  3572. install_element (CONFIG_NODE, &ipv6_route_ifname_pref_vrf_cmd);
  3573. install_element (CONFIG_NODE, &ipv6_route_ifname_flags_pref_vrf_cmd);
  3574. install_element (CONFIG_NODE, &no_ipv6_route_pref_vrf_cmd);
  3575. install_element (CONFIG_NODE, &no_ipv6_route_flags_pref_vrf_cmd);
  3576. install_element (CONFIG_NODE, &no_ipv6_route_ifname_pref_vrf_cmd);
  3577. install_element (CONFIG_NODE, &no_ipv6_route_ifname_flags_pref_vrf_cmd);
  3578. install_element (VIEW_NODE, &show_ipv6_route_vrf_cmd);
  3579. install_element (VIEW_NODE, &show_ipv6_route_summary_vrf_cmd);
  3580. install_element (VIEW_NODE, &show_ipv6_route_summary_prefix_vrf_cmd);
  3581. install_element (VIEW_NODE, &show_ipv6_route_protocol_vrf_cmd);
  3582. install_element (VIEW_NODE, &show_ipv6_route_addr_vrf_cmd);
  3583. install_element (VIEW_NODE, &show_ipv6_route_prefix_vrf_cmd);
  3584. install_element (VIEW_NODE, &show_ipv6_route_prefix_longer_vrf_cmd);
  3585. install_element (VIEW_NODE, &show_ipv6_route_vrf_all_cmd);
  3586. install_element (VIEW_NODE, &show_ipv6_route_summary_vrf_all_cmd);
  3587. install_element (VIEW_NODE, &show_ipv6_route_summary_prefix_vrf_all_cmd);
  3588. install_element (VIEW_NODE, &show_ipv6_route_protocol_vrf_all_cmd);
  3589. install_element (VIEW_NODE, &show_ipv6_route_addr_vrf_all_cmd);
  3590. install_element (VIEW_NODE, &show_ipv6_route_prefix_vrf_all_cmd);
  3591. install_element (VIEW_NODE, &show_ipv6_route_prefix_longer_vrf_all_cmd);
  3592. install_element (VIEW_NODE, &show_ipv6_mroute_vrf_cmd);
  3593. install_element (VIEW_NODE, &show_ipv6_mroute_vrf_all_cmd);
  3594. }