pim_cmd.c 120 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500
  1. /*
  2. PIM for Quagga
  3. Copyright (C) 2008 Everton da Silva Marques
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; see the file COPYING; if not, write to the
  14. Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
  15. MA 02110-1301 USA
  16. $QuaggaId: $Format:%an, %ai, %h$ $
  17. */
  18. #include <sys/ioctl.h>
  19. #include <zebra.h>
  20. #include "command.h"
  21. #include "if.h"
  22. #include "prefix.h"
  23. #include "zclient.h"
  24. #include "pimd.h"
  25. #include "pim_cmd.h"
  26. #include "pim_iface.h"
  27. #include "pim_vty.h"
  28. #include "pim_mroute.h"
  29. #include "pim_str.h"
  30. #include "pim_igmp.h"
  31. #include "pim_igmpv3.h"
  32. #include "pim_sock.h"
  33. #include "pim_time.h"
  34. #include "pim_util.h"
  35. #include "pim_oil.h"
  36. #include "pim_neighbor.h"
  37. #include "pim_pim.h"
  38. #include "pim_ifchannel.h"
  39. #include "pim_hello.h"
  40. #include "pim_msg.h"
  41. #include "pim_upstream.h"
  42. #include "pim_rpf.h"
  43. #include "pim_macro.h"
  44. #include "pim_ssmpingd.h"
  45. #include "pim_zebra.h"
  46. static struct cmd_node pim_global_node = {
  47. PIM_NODE,
  48. "",
  49. 1 /* vtysh ? yes */
  50. };
  51. static struct cmd_node interface_node = {
  52. INTERFACE_NODE,
  53. "%s(config-if)# ",
  54. 1 /* vtysh ? yes */
  55. };
  56. static void pim_if_membership_clear(struct interface *ifp)
  57. {
  58. struct pim_interface *pim_ifp;
  59. pim_ifp = ifp->info;
  60. zassert(pim_ifp);
  61. if (PIM_IF_TEST_PIM(pim_ifp->options) &&
  62. PIM_IF_TEST_IGMP(pim_ifp->options)) {
  63. return;
  64. }
  65. pim_ifchannel_membership_clear(ifp);
  66. }
  67. /*
  68. When PIM is disabled on interface, IGMPv3 local membership
  69. information is not injected into PIM interface state.
  70. The function pim_if_membership_refresh() fetches all IGMPv3 local
  71. membership information into PIM. It is intented to be called
  72. whenever PIM is enabled on the interface in order to collect missed
  73. local membership information.
  74. */
  75. static void pim_if_membership_refresh(struct interface *ifp)
  76. {
  77. struct pim_interface *pim_ifp;
  78. struct listnode *sock_node;
  79. struct igmp_sock *igmp;
  80. pim_ifp = ifp->info;
  81. zassert(pim_ifp);
  82. if (!PIM_IF_TEST_PIM(pim_ifp->options))
  83. return;
  84. if (!PIM_IF_TEST_IGMP(pim_ifp->options))
  85. return;
  86. /*
  87. First clear off membership from all PIM (S,G) entries on the
  88. interface
  89. */
  90. pim_ifchannel_membership_clear(ifp);
  91. /*
  92. Then restore PIM (S,G) membership from all IGMPv3 (S,G) entries on
  93. the interface
  94. */
  95. /* scan igmp sockets */
  96. for (ALL_LIST_ELEMENTS_RO(pim_ifp->igmp_socket_list, sock_node, igmp)) {
  97. struct listnode *grpnode;
  98. struct igmp_group *grp;
  99. /* scan igmp groups */
  100. for (ALL_LIST_ELEMENTS_RO(igmp->igmp_group_list, grpnode, grp)) {
  101. struct listnode *srcnode;
  102. struct igmp_source *src;
  103. /* scan group sources */
  104. for (ALL_LIST_ELEMENTS_RO(grp->group_source_list, srcnode, src)) {
  105. if (IGMP_SOURCE_TEST_FORWARDING(src->source_flags)) {
  106. pim_ifchannel_local_membership_add(ifp,
  107. src->source_addr,
  108. grp->group_addr);
  109. }
  110. } /* scan group sources */
  111. } /* scan igmp groups */
  112. } /* scan igmp sockets */
  113. /*
  114. Finally delete every PIM (S,G) entry lacking all state info
  115. */
  116. pim_ifchannel_delete_on_noinfo(ifp);
  117. }
  118. static void pim_show_assert(struct vty *vty)
  119. {
  120. struct listnode *ifnode;
  121. struct interface *ifp;
  122. time_t now;
  123. now = pim_time_monotonic_sec();
  124. vty_out(vty,
  125. "Interface Address Source Group State Winner Uptime Timer%s",
  126. VTY_NEWLINE);
  127. for (ALL_LIST_ELEMENTS_RO(iflist, ifnode, ifp)) {
  128. struct pim_interface *pim_ifp;
  129. struct in_addr ifaddr;
  130. struct listnode *ch_node;
  131. struct pim_ifchannel *ch;
  132. pim_ifp = ifp->info;
  133. if (!pim_ifp)
  134. continue;
  135. ifaddr = pim_ifp->primary_address;
  136. for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_ifchannel_list, ch_node, ch)) {
  137. char ch_src_str[100];
  138. char ch_grp_str[100];
  139. char winner_str[100];
  140. char uptime[10];
  141. char timer[10];
  142. pim_inet4_dump("<ch_src?>", ch->source_addr,
  143. ch_src_str, sizeof(ch_src_str));
  144. pim_inet4_dump("<ch_grp?>", ch->group_addr,
  145. ch_grp_str, sizeof(ch_grp_str));
  146. pim_inet4_dump("<assrt_win?>", ch->ifassert_winner,
  147. winner_str, sizeof(winner_str));
  148. pim_time_uptime(uptime, sizeof(uptime), now - ch->ifassert_creation);
  149. pim_time_timer_to_mmss(timer, sizeof(timer),
  150. ch->t_ifassert_timer);
  151. vty_out(vty, "%-9s %-15s %-15s %-15s %-6s %-15s %-8s %-5s%s",
  152. ifp->name,
  153. inet_ntoa(ifaddr),
  154. ch_src_str,
  155. ch_grp_str,
  156. pim_ifchannel_ifassert_name(ch->ifassert_state),
  157. winner_str,
  158. uptime,
  159. timer,
  160. VTY_NEWLINE);
  161. } /* scan interface channels */
  162. } /* scan interfaces */
  163. }
  164. static void pim_show_assert_internal(struct vty *vty)
  165. {
  166. struct listnode *ifnode;
  167. struct interface *ifp;
  168. vty_out(vty,
  169. "CA: CouldAssert%s"
  170. "ECA: Evaluate CouldAssert%s"
  171. "ATD: AssertTrackingDesired%s"
  172. "eATD: Evaluate AssertTrackingDesired%s%s",
  173. VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
  174. vty_out(vty,
  175. "Interface Address Source Group CA eCA ATD eATD%s",
  176. VTY_NEWLINE);
  177. for (ALL_LIST_ELEMENTS_RO(iflist, ifnode, ifp)) {
  178. struct pim_interface *pim_ifp;
  179. struct in_addr ifaddr;
  180. struct listnode *ch_node;
  181. struct pim_ifchannel *ch;
  182. pim_ifp = ifp->info;
  183. if (!pim_ifp)
  184. continue;
  185. ifaddr = pim_ifp->primary_address;
  186. for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_ifchannel_list, ch_node, ch)) {
  187. char ch_src_str[100];
  188. char ch_grp_str[100];
  189. pim_inet4_dump("<ch_src?>", ch->source_addr,
  190. ch_src_str, sizeof(ch_src_str));
  191. pim_inet4_dump("<ch_grp?>", ch->group_addr,
  192. ch_grp_str, sizeof(ch_grp_str));
  193. vty_out(vty, "%-9s %-15s %-15s %-15s %-3s %-3s %-3s %-4s%s",
  194. ifp->name,
  195. inet_ntoa(ifaddr),
  196. ch_src_str,
  197. ch_grp_str,
  198. PIM_IF_FLAG_TEST_COULD_ASSERT(ch->flags) ? "yes" : "no",
  199. pim_macro_ch_could_assert_eval(ch) ? "yes" : "no",
  200. PIM_IF_FLAG_TEST_ASSERT_TRACKING_DESIRED(ch->flags) ? "yes" : "no",
  201. pim_macro_assert_tracking_desired_eval(ch) ? "yes" : "no",
  202. VTY_NEWLINE);
  203. } /* scan interface channels */
  204. } /* scan interfaces */
  205. }
  206. static void pim_show_assert_metric(struct vty *vty)
  207. {
  208. struct listnode *ifnode;
  209. struct interface *ifp;
  210. vty_out(vty,
  211. "Interface Address Source Group RPT Pref Metric Address %s",
  212. VTY_NEWLINE);
  213. for (ALL_LIST_ELEMENTS_RO(iflist, ifnode, ifp)) {
  214. struct pim_interface *pim_ifp;
  215. struct in_addr ifaddr;
  216. struct listnode *ch_node;
  217. struct pim_ifchannel *ch;
  218. pim_ifp = ifp->info;
  219. if (!pim_ifp)
  220. continue;
  221. ifaddr = pim_ifp->primary_address;
  222. for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_ifchannel_list, ch_node, ch)) {
  223. char ch_src_str[100];
  224. char ch_grp_str[100];
  225. char addr_str[100];
  226. struct pim_assert_metric am;
  227. am = pim_macro_spt_assert_metric(&ch->upstream->rpf, pim_ifp->primary_address);
  228. pim_inet4_dump("<ch_src?>", ch->source_addr,
  229. ch_src_str, sizeof(ch_src_str));
  230. pim_inet4_dump("<ch_grp?>", ch->group_addr,
  231. ch_grp_str, sizeof(ch_grp_str));
  232. pim_inet4_dump("<addr?>", am.ip_address,
  233. addr_str, sizeof(addr_str));
  234. vty_out(vty, "%-9s %-15s %-15s %-15s %-3s %4u %6u %-15s%s",
  235. ifp->name,
  236. inet_ntoa(ifaddr),
  237. ch_src_str,
  238. ch_grp_str,
  239. am.rpt_bit_flag ? "yes" : "no",
  240. am.metric_preference,
  241. am.route_metric,
  242. addr_str,
  243. VTY_NEWLINE);
  244. } /* scan interface channels */
  245. } /* scan interfaces */
  246. }
  247. static void pim_show_assert_winner_metric(struct vty *vty)
  248. {
  249. struct listnode *ifnode;
  250. struct interface *ifp;
  251. vty_out(vty,
  252. "Interface Address Source Group RPT Pref Metric Address %s",
  253. VTY_NEWLINE);
  254. for (ALL_LIST_ELEMENTS_RO(iflist, ifnode, ifp)) {
  255. struct pim_interface *pim_ifp;
  256. struct in_addr ifaddr;
  257. struct listnode *ch_node;
  258. struct pim_ifchannel *ch;
  259. pim_ifp = ifp->info;
  260. if (!pim_ifp)
  261. continue;
  262. ifaddr = pim_ifp->primary_address;
  263. for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_ifchannel_list, ch_node, ch)) {
  264. char ch_src_str[100];
  265. char ch_grp_str[100];
  266. char addr_str[100];
  267. struct pim_assert_metric *am;
  268. char pref_str[5];
  269. char metr_str[7];
  270. am = &ch->ifassert_winner_metric;
  271. pim_inet4_dump("<ch_src?>", ch->source_addr,
  272. ch_src_str, sizeof(ch_src_str));
  273. pim_inet4_dump("<ch_grp?>", ch->group_addr,
  274. ch_grp_str, sizeof(ch_grp_str));
  275. pim_inet4_dump("<addr?>", am->ip_address,
  276. addr_str, sizeof(addr_str));
  277. if (am->metric_preference == PIM_ASSERT_METRIC_PREFERENCE_MAX)
  278. snprintf(pref_str, sizeof(pref_str), "INFI");
  279. else
  280. snprintf(pref_str, sizeof(pref_str), "%4u", am->metric_preference);
  281. if (am->route_metric == PIM_ASSERT_ROUTE_METRIC_MAX)
  282. snprintf(metr_str, sizeof(metr_str), "INFI");
  283. else
  284. snprintf(metr_str, sizeof(metr_str), "%6u", am->route_metric);
  285. vty_out(vty, "%-9s %-15s %-15s %-15s %-3s %-4s %-6s %-15s%s",
  286. ifp->name,
  287. inet_ntoa(ifaddr),
  288. ch_src_str,
  289. ch_grp_str,
  290. am->rpt_bit_flag ? "yes" : "no",
  291. pref_str,
  292. metr_str,
  293. addr_str,
  294. VTY_NEWLINE);
  295. } /* scan interface channels */
  296. } /* scan interfaces */
  297. }
  298. static void pim_show_membership(struct vty *vty)
  299. {
  300. struct listnode *ifnode;
  301. struct interface *ifp;
  302. vty_out(vty,
  303. "Interface Address Source Group Membership%s",
  304. VTY_NEWLINE);
  305. for (ALL_LIST_ELEMENTS_RO(iflist, ifnode, ifp)) {
  306. struct pim_interface *pim_ifp;
  307. struct in_addr ifaddr;
  308. struct listnode *ch_node;
  309. struct pim_ifchannel *ch;
  310. pim_ifp = ifp->info;
  311. if (!pim_ifp)
  312. continue;
  313. ifaddr = pim_ifp->primary_address;
  314. for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_ifchannel_list, ch_node, ch)) {
  315. char ch_src_str[100];
  316. char ch_grp_str[100];
  317. pim_inet4_dump("<ch_src?>", ch->source_addr,
  318. ch_src_str, sizeof(ch_src_str));
  319. pim_inet4_dump("<ch_grp?>", ch->group_addr,
  320. ch_grp_str, sizeof(ch_grp_str));
  321. vty_out(vty, "%-9s %-15s %-15s %-15s %-10s%s",
  322. ifp->name,
  323. inet_ntoa(ifaddr),
  324. ch_src_str,
  325. ch_grp_str,
  326. ch->local_ifmembership == PIM_IFMEMBERSHIP_NOINFO ?
  327. "NOINFO" : "INCLUDE",
  328. VTY_NEWLINE);
  329. } /* scan interface channels */
  330. } /* scan interfaces */
  331. }
  332. static void igmp_show_interfaces(struct vty *vty)
  333. {
  334. struct listnode *node;
  335. struct interface *ifp;
  336. time_t now;
  337. now = pim_time_monotonic_sec();
  338. vty_out(vty,
  339. "Interface Address ifIndex Socket Uptime Multi Broad MLoop AllMu Prmsc Del%s",
  340. VTY_NEWLINE);
  341. for (ALL_LIST_ELEMENTS_RO(iflist, node, ifp)) {
  342. struct pim_interface *pim_ifp;
  343. struct listnode *sock_node;
  344. struct igmp_sock *igmp;
  345. pim_ifp = ifp->info;
  346. if (!pim_ifp)
  347. continue;
  348. for (ALL_LIST_ELEMENTS_RO(pim_ifp->igmp_socket_list, sock_node, igmp)) {
  349. char uptime[10];
  350. int mloop;
  351. pim_time_uptime(uptime, sizeof(uptime), now - igmp->sock_creation);
  352. mloop = pim_socket_mcastloop_get(igmp->fd);
  353. vty_out(vty, "%-9s %-15s %7d %6d %8s %5s %5s %5s %5s %5s %3s%s",
  354. ifp->name,
  355. inet_ntoa(igmp->ifaddr),
  356. ifp->ifindex,
  357. igmp->fd,
  358. uptime,
  359. if_is_multicast(ifp) ? "yes" : "no",
  360. if_is_broadcast(ifp) ? "yes" : "no",
  361. (mloop < 0) ? "?" : (mloop ? "yes" : "no"),
  362. (ifp->flags & IFF_ALLMULTI) ? "yes" : "no",
  363. (ifp->flags & IFF_PROMISC) ? "yes" : "no",
  364. PIM_IF_IS_DELETED(ifp) ? "yes" : "no",
  365. VTY_NEWLINE);
  366. }
  367. }
  368. }
  369. static void igmp_show_interface_join(struct vty *vty)
  370. {
  371. struct listnode *node;
  372. struct interface *ifp;
  373. time_t now;
  374. now = pim_time_monotonic_sec();
  375. vty_out(vty,
  376. "Interface Address Source Group Socket Uptime %s",
  377. VTY_NEWLINE);
  378. for (ALL_LIST_ELEMENTS_RO(iflist, node, ifp)) {
  379. struct pim_interface *pim_ifp;
  380. struct listnode *join_node;
  381. struct igmp_join *ij;
  382. struct in_addr pri_addr;
  383. char pri_addr_str[100];
  384. pim_ifp = ifp->info;
  385. if (!pim_ifp)
  386. continue;
  387. if (!pim_ifp->igmp_join_list)
  388. continue;
  389. pri_addr = pim_find_primary_addr(ifp);
  390. pim_inet4_dump("<pri?>", pri_addr, pri_addr_str, sizeof(pri_addr_str));
  391. for (ALL_LIST_ELEMENTS_RO(pim_ifp->igmp_join_list, join_node, ij)) {
  392. char group_str[100];
  393. char source_str[100];
  394. char uptime[10];
  395. pim_time_uptime(uptime, sizeof(uptime), now - ij->sock_creation);
  396. pim_inet4_dump("<grp?>", ij->group_addr, group_str, sizeof(group_str));
  397. pim_inet4_dump("<src?>", ij->source_addr, source_str, sizeof(source_str));
  398. vty_out(vty, "%-9s %-15s %-15s %-15s %6d %8s%s",
  399. ifp->name,
  400. pri_addr_str,
  401. source_str,
  402. group_str,
  403. ij->sock_fd,
  404. uptime,
  405. VTY_NEWLINE);
  406. } /* for (pim_ifp->igmp_join_list) */
  407. } /* for (iflist) */
  408. }
  409. static void show_interface_address(struct vty *vty)
  410. {
  411. struct listnode *ifpnode;
  412. struct interface *ifp;
  413. vty_out(vty,
  414. "Interface Primary Secondary %s",
  415. VTY_NEWLINE);
  416. for (ALL_LIST_ELEMENTS_RO(iflist, ifpnode, ifp)) {
  417. struct listnode *ifcnode;
  418. struct connected *ifc;
  419. struct in_addr pri_addr;
  420. char pri_addr_str[100];
  421. pri_addr = pim_find_primary_addr(ifp);
  422. pim_inet4_dump("<pri?>", pri_addr, pri_addr_str, sizeof(pri_addr_str));
  423. for (ALL_LIST_ELEMENTS_RO(ifp->connected, ifcnode, ifc)) {
  424. char sec_addr_str[100];
  425. struct prefix *p = ifc->address;
  426. if (p->family != AF_INET)
  427. continue;
  428. if (p->u.prefix4.s_addr == pri_addr.s_addr) {
  429. sec_addr_str[0] = '\0';
  430. }
  431. else {
  432. pim_inet4_dump("<sec?>", p->u.prefix4, sec_addr_str, sizeof(sec_addr_str));
  433. }
  434. vty_out(vty, "%-9s %-15s %-15s%s",
  435. ifp->name,
  436. pri_addr_str,
  437. sec_addr_str,
  438. VTY_NEWLINE);
  439. }
  440. }
  441. }
  442. static void pim_show_dr(struct vty *vty)
  443. {
  444. struct listnode *node;
  445. struct interface *ifp;
  446. time_t now;
  447. now = pim_time_monotonic_sec();
  448. vty_out(vty,
  449. "NonPri: Number of neighbors missing DR Priority hello option%s%s",
  450. VTY_NEWLINE, VTY_NEWLINE);
  451. vty_out(vty, "Interface Address DR Uptime Elections Changes NonPri%s", VTY_NEWLINE);
  452. for (ALL_LIST_ELEMENTS_RO(iflist, node, ifp)) {
  453. struct pim_interface *pim_ifp;
  454. struct in_addr ifaddr;
  455. char dr_str[100];
  456. char dr_uptime[10];
  457. pim_ifp = ifp->info;
  458. if (!pim_ifp)
  459. continue;
  460. if (pim_ifp->pim_sock_fd < 0)
  461. continue;
  462. ifaddr = pim_ifp->primary_address;
  463. pim_time_uptime_begin(dr_uptime, sizeof(dr_uptime),
  464. now, pim_ifp->pim_dr_election_last);
  465. pim_inet4_dump("<dr?>", pim_ifp->pim_dr_addr,
  466. dr_str, sizeof(dr_str));
  467. vty_out(vty, "%-9s %-15s %-15s %8s %9d %7d %6d%s",
  468. ifp->name,
  469. inet_ntoa(ifaddr),
  470. dr_str,
  471. dr_uptime,
  472. pim_ifp->pim_dr_election_count,
  473. pim_ifp->pim_dr_election_changes,
  474. pim_ifp->pim_dr_num_nondrpri_neighbors,
  475. VTY_NEWLINE);
  476. }
  477. }
  478. static void pim_show_hello(struct vty *vty)
  479. {
  480. struct listnode *node;
  481. struct interface *ifp;
  482. time_t now;
  483. now = pim_time_monotonic_sec();
  484. vty_out(vty, "Interface Address Period Timer StatStart Recv Rfail Send Sfail%s", VTY_NEWLINE);
  485. for (ALL_LIST_ELEMENTS_RO(iflist, node, ifp)) {
  486. struct pim_interface *pim_ifp;
  487. struct in_addr ifaddr;
  488. char hello_period[10];
  489. char hello_timer[10];
  490. char stat_uptime[10];
  491. pim_ifp = ifp->info;
  492. if (!pim_ifp)
  493. continue;
  494. if (pim_ifp->pim_sock_fd < 0)
  495. continue;
  496. ifaddr = pim_ifp->primary_address;
  497. pim_time_timer_to_mmss(hello_timer, sizeof(hello_timer), pim_ifp->t_pim_hello_timer);
  498. pim_time_mmss(hello_period, sizeof(hello_period), pim_ifp->pim_hello_period);
  499. pim_time_uptime(stat_uptime, sizeof(stat_uptime), now - pim_ifp->pim_ifstat_start);
  500. vty_out(vty, "%-9s %-15s %6s %5s %9s %4u %5u %4u %5u%s",
  501. ifp->name,
  502. inet_ntoa(ifaddr),
  503. hello_period,
  504. hello_timer,
  505. stat_uptime,
  506. pim_ifp->pim_ifstat_hello_recv,
  507. pim_ifp->pim_ifstat_hello_recvfail,
  508. pim_ifp->pim_ifstat_hello_sent,
  509. pim_ifp->pim_ifstat_hello_sendfail,
  510. VTY_NEWLINE);
  511. }
  512. }
  513. static void pim_show_interfaces(struct vty *vty)
  514. {
  515. struct listnode *node;
  516. struct interface *ifp;
  517. time_t now;
  518. now = pim_time_monotonic_sec();
  519. vty_out(vty, "Interface Address ifIndex Socket Uptime Multi Broad MLoop AllMu Prmsc Del%s", VTY_NEWLINE);
  520. for (ALL_LIST_ELEMENTS_RO(iflist, node, ifp)) {
  521. struct pim_interface *pim_ifp;
  522. struct in_addr ifaddr;
  523. char uptime[10];
  524. int mloop;
  525. pim_ifp = ifp->info;
  526. if (!pim_ifp)
  527. continue;
  528. if (pim_ifp->pim_sock_fd < 0)
  529. continue;
  530. ifaddr = pim_ifp->primary_address;
  531. pim_time_uptime(uptime, sizeof(uptime), now - pim_ifp->pim_sock_creation);
  532. mloop = pim_socket_mcastloop_get(pim_ifp->pim_sock_fd);
  533. vty_out(vty, "%-9s %-15s %7d %6d %8s %5s %5s %5s %5s %5s %3s%s",
  534. ifp->name,
  535. inet_ntoa(ifaddr),
  536. ifp->ifindex,
  537. pim_ifp->pim_sock_fd,
  538. uptime,
  539. if_is_multicast(ifp) ? "yes" : "no",
  540. if_is_broadcast(ifp) ? "yes" : "no",
  541. (mloop < 0) ? "?" : (mloop ? "yes" : "no"),
  542. (ifp->flags & IFF_ALLMULTI) ? "yes" : "no",
  543. (ifp->flags & IFF_PROMISC) ? "yes" : "no",
  544. PIM_IF_IS_DELETED(ifp) ? "yes" : "no",
  545. VTY_NEWLINE);
  546. }
  547. }
  548. static void pim_show_join(struct vty *vty)
  549. {
  550. struct listnode *ifnode;
  551. struct interface *ifp;
  552. time_t now;
  553. now = pim_time_monotonic_sec();
  554. vty_out(vty,
  555. "Interface Address Source Group State Uptime Expire Prune%s",
  556. VTY_NEWLINE);
  557. for (ALL_LIST_ELEMENTS_RO(iflist, ifnode, ifp)) {
  558. struct pim_interface *pim_ifp;
  559. struct in_addr ifaddr;
  560. struct listnode *ch_node;
  561. struct pim_ifchannel *ch;
  562. pim_ifp = ifp->info;
  563. if (!pim_ifp)
  564. continue;
  565. ifaddr = pim_ifp->primary_address;
  566. for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_ifchannel_list, ch_node, ch)) {
  567. char ch_src_str[100];
  568. char ch_grp_str[100];
  569. char uptime[10];
  570. char expire[10];
  571. char prune[10];
  572. pim_inet4_dump("<ch_src?>", ch->source_addr,
  573. ch_src_str, sizeof(ch_src_str));
  574. pim_inet4_dump("<ch_grp?>", ch->group_addr,
  575. ch_grp_str, sizeof(ch_grp_str));
  576. pim_time_uptime_begin(uptime, sizeof(uptime), now, ch->ifjoin_creation);
  577. pim_time_timer_to_mmss(expire, sizeof(expire),
  578. ch->t_ifjoin_expiry_timer);
  579. pim_time_timer_to_mmss(prune, sizeof(prune),
  580. ch->t_ifjoin_prune_pending_timer);
  581. vty_out(vty, "%-9s %-15s %-15s %-15s %-6s %8s %-6s %5s%s",
  582. ifp->name,
  583. inet_ntoa(ifaddr),
  584. ch_src_str,
  585. ch_grp_str,
  586. pim_ifchannel_ifjoin_name(ch->ifjoin_state),
  587. uptime,
  588. expire,
  589. prune,
  590. VTY_NEWLINE);
  591. } /* scan interface channels */
  592. } /* scan interfaces */
  593. }
  594. static void pim_show_neighbors(struct vty *vty)
  595. {
  596. struct listnode *node;
  597. struct interface *ifp;
  598. time_t now;
  599. now = pim_time_monotonic_sec();
  600. vty_out(vty,
  601. "Recv flags: H=holdtime L=lan_prune_delay P=dr_priority G=generation_id A=address_list%s"
  602. " T=can_disable_join_suppression%s%s",
  603. VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
  604. vty_out(vty, "Interface Address Neighbor Uptime Timer Holdt DrPri GenId Recv %s", VTY_NEWLINE);
  605. for (ALL_LIST_ELEMENTS_RO(iflist, node, ifp)) {
  606. struct pim_interface *pim_ifp;
  607. struct in_addr ifaddr;
  608. struct listnode *neighnode;
  609. struct pim_neighbor *neigh;
  610. pim_ifp = ifp->info;
  611. if (!pim_ifp)
  612. continue;
  613. if (pim_ifp->pim_sock_fd < 0)
  614. continue;
  615. ifaddr = pim_ifp->primary_address;
  616. for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, neighnode, neigh)) {
  617. char uptime[10];
  618. char holdtime[10];
  619. char expire[10];
  620. char neigh_src_str[100];
  621. char recv[7];
  622. pim_inet4_dump("<src?>", neigh->source_addr,
  623. neigh_src_str, sizeof(neigh_src_str));
  624. pim_time_uptime(uptime, sizeof(uptime), now - neigh->creation);
  625. pim_time_mmss(holdtime, sizeof(holdtime), neigh->holdtime);
  626. pim_time_timer_to_mmss(expire, sizeof(expire), neigh->t_expire_timer);
  627. recv[0] = PIM_OPTION_IS_SET(neigh->hello_options, PIM_OPTION_MASK_HOLDTIME) ? 'H' : ' ';
  628. recv[1] = PIM_OPTION_IS_SET(neigh->hello_options, PIM_OPTION_MASK_LAN_PRUNE_DELAY) ? 'L' : ' ';
  629. recv[2] = PIM_OPTION_IS_SET(neigh->hello_options, PIM_OPTION_MASK_DR_PRIORITY) ? 'P' : ' ';
  630. recv[3] = PIM_OPTION_IS_SET(neigh->hello_options, PIM_OPTION_MASK_GENERATION_ID) ? 'G' : ' ';
  631. recv[4] = PIM_OPTION_IS_SET(neigh->hello_options, PIM_OPTION_MASK_ADDRESS_LIST) ? 'A' : ' ';
  632. recv[5] = PIM_OPTION_IS_SET(neigh->hello_options, PIM_OPTION_MASK_CAN_DISABLE_JOIN_SUPPRESSION) ? 'T' : ' ';
  633. recv[6] = '\0';
  634. vty_out(vty, "%-9s %-15s %-15s %8s %5s %5s %5u %08x %6s%s",
  635. ifp->name,
  636. inet_ntoa(ifaddr),
  637. neigh_src_str,
  638. uptime,
  639. expire,
  640. holdtime,
  641. neigh->dr_priority,
  642. neigh->generation_id,
  643. recv,
  644. VTY_NEWLINE);
  645. }
  646. }
  647. }
  648. static void pim_show_lan_prune_delay(struct vty *vty)
  649. {
  650. struct listnode *node;
  651. struct interface *ifp;
  652. vty_out(vty,
  653. "PrDly=propagation_delay (msec) OvInt=override_interval (msec)%s"
  654. "HiDly=highest_propagation_delay (msec) HiInt=highest_override_interval (msec)%s"
  655. "NoDly=number_of_non_lan_delay_neighbors%s"
  656. "T=t_bit LPD=lan_prune_delay_hello_option%s%s",
  657. VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
  658. vty_out(vty, "Interface Address PrDly OvInt NoDly HiDly HiInt T | Neighbor LPD PrDly OvInt T%s", VTY_NEWLINE);
  659. for (ALL_LIST_ELEMENTS_RO(iflist, node, ifp)) {
  660. struct pim_interface *pim_ifp;
  661. struct in_addr ifaddr;
  662. struct listnode *neighnode;
  663. struct pim_neighbor *neigh;
  664. pim_ifp = ifp->info;
  665. if (!pim_ifp)
  666. continue;
  667. if (pim_ifp->pim_sock_fd < 0)
  668. continue;
  669. ifaddr = pim_ifp->primary_address;
  670. for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, neighnode, neigh)) {
  671. char neigh_src_str[100];
  672. pim_inet4_dump("<src?>", neigh->source_addr,
  673. neigh_src_str, sizeof(neigh_src_str));
  674. vty_out(vty, "%-9s %-15s %5u %5u %5u %5u %5u %1u | %-15s %-3s %5u %5u %1u%s",
  675. ifp->name,
  676. inet_ntoa(ifaddr),
  677. pim_ifp->pim_propagation_delay_msec,
  678. pim_ifp->pim_override_interval_msec,
  679. pim_ifp->pim_number_of_nonlandelay_neighbors,
  680. pim_ifp->pim_neighbors_highest_propagation_delay_msec,
  681. pim_ifp->pim_neighbors_highest_override_interval_msec,
  682. PIM_FORCE_BOOLEAN(PIM_IF_TEST_PIM_CAN_DISABLE_JOIN_SUPRESSION(pim_ifp->options)),
  683. neigh_src_str,
  684. PIM_OPTION_IS_SET(neigh->hello_options, PIM_OPTION_MASK_LAN_PRUNE_DELAY) ? "yes" : "no",
  685. neigh->propagation_delay_msec,
  686. neigh->override_interval_msec,
  687. PIM_FORCE_BOOLEAN(PIM_OPTION_IS_SET(neigh->hello_options,
  688. PIM_OPTION_MASK_CAN_DISABLE_JOIN_SUPPRESSION)),
  689. VTY_NEWLINE);
  690. }
  691. }
  692. }
  693. static void pim_show_jp_override_interval(struct vty *vty)
  694. {
  695. struct listnode *node;
  696. struct interface *ifp;
  697. vty_out(vty,
  698. "EffPDelay=effective_propagation_delay (msec)%s"
  699. "EffOvrInt=override_interval (msec)%s"
  700. "JPOvrInt=jp_override_interval (msec)%s%s",
  701. VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
  702. vty_out(vty, "Interface Address LAN_Delay EffPDelay EffOvrInt JPOvrInt%s", VTY_NEWLINE);
  703. for (ALL_LIST_ELEMENTS_RO(iflist, node, ifp)) {
  704. struct pim_interface *pim_ifp;
  705. struct in_addr ifaddr;
  706. pim_ifp = ifp->info;
  707. if (!pim_ifp)
  708. continue;
  709. if (pim_ifp->pim_sock_fd < 0)
  710. continue;
  711. ifaddr = pim_ifp->primary_address;
  712. vty_out(vty, "%-9s %-15s %-9s %9u %9u %8u%s",
  713. ifp->name,
  714. inet_ntoa(ifaddr),
  715. pim_if_lan_delay_enabled(ifp) ? "enabled" : "disabled",
  716. pim_if_effective_propagation_delay_msec(ifp),
  717. pim_if_effective_override_interval_msec(ifp),
  718. pim_if_jp_override_interval_msec(ifp),
  719. VTY_NEWLINE);
  720. }
  721. }
  722. static void pim_show_neighbors_secondary(struct vty *vty)
  723. {
  724. struct listnode *node;
  725. struct interface *ifp;
  726. vty_out(vty, "Interface Address Neighbor Secondary %s", VTY_NEWLINE);
  727. for (ALL_LIST_ELEMENTS_RO(iflist, node, ifp)) {
  728. struct pim_interface *pim_ifp;
  729. struct in_addr ifaddr;
  730. struct listnode *neighnode;
  731. struct pim_neighbor *neigh;
  732. pim_ifp = ifp->info;
  733. if (!pim_ifp)
  734. continue;
  735. if (pim_ifp->pim_sock_fd < 0)
  736. continue;
  737. ifaddr = pim_ifp->primary_address;
  738. for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, neighnode, neigh)) {
  739. char neigh_src_str[100];
  740. struct listnode *prefix_node;
  741. struct prefix *p;
  742. if (!neigh->prefix_list)
  743. continue;
  744. pim_inet4_dump("<src?>", neigh->source_addr,
  745. neigh_src_str, sizeof(neigh_src_str));
  746. for (ALL_LIST_ELEMENTS_RO(neigh->prefix_list, prefix_node, p)) {
  747. char neigh_sec_str[100];
  748. if (p->family != AF_INET)
  749. continue;
  750. pim_inet4_dump("<src?>", p->u.prefix4,
  751. neigh_sec_str, sizeof(neigh_sec_str));
  752. vty_out(vty, "%-9s %-15s %-15s %-15s%s",
  753. ifp->name,
  754. inet_ntoa(ifaddr),
  755. neigh_src_str,
  756. neigh_sec_str,
  757. VTY_NEWLINE);
  758. }
  759. }
  760. }
  761. }
  762. static void pim_show_upstream(struct vty *vty)
  763. {
  764. struct listnode *upnode;
  765. struct pim_upstream *up;
  766. time_t now;
  767. now = pim_time_monotonic_sec();
  768. vty_out(vty, "Source Group State Uptime JoinTimer RefCnt%s", VTY_NEWLINE);
  769. for (ALL_LIST_ELEMENTS_RO(qpim_upstream_list, upnode, up)) {
  770. char src_str[100];
  771. char grp_str[100];
  772. char uptime[10];
  773. char join_timer[10];
  774. pim_inet4_dump("<src?>", up->source_addr, src_str, sizeof(src_str));
  775. pim_inet4_dump("<grp?>", up->group_addr, grp_str, sizeof(grp_str));
  776. pim_time_uptime(uptime, sizeof(uptime), now - up->state_transition);
  777. pim_time_timer_to_hhmmss(join_timer, sizeof(join_timer), up->t_join_timer);
  778. vty_out(vty, "%-15s %-15s %-5s %-8s %-9s %6d%s",
  779. src_str,
  780. grp_str,
  781. up->join_state == PIM_UPSTREAM_JOINED ? "Jnd" : "NtJnd",
  782. uptime,
  783. join_timer,
  784. up->ref_count,
  785. VTY_NEWLINE);
  786. }
  787. }
  788. static void pim_show_join_desired(struct vty *vty)
  789. {
  790. struct listnode *ifnode;
  791. struct listnode *chnode;
  792. struct interface *ifp;
  793. struct pim_interface *pim_ifp;
  794. struct pim_ifchannel *ch;
  795. char src_str[100];
  796. char grp_str[100];
  797. vty_out(vty,
  798. "Interface Source Group LostAssert Joins PimInclude JoinDesired EvalJD%s",
  799. VTY_NEWLINE);
  800. /* scan all interfaces */
  801. for (ALL_LIST_ELEMENTS_RO(iflist, ifnode, ifp)) {
  802. pim_ifp = ifp->info;
  803. if (!pim_ifp)
  804. continue;
  805. /* scan per-interface (S,G) state */
  806. for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_ifchannel_list, chnode, ch)) {
  807. struct pim_upstream *up = ch->upstream;
  808. pim_inet4_dump("<src?>", up->source_addr, src_str, sizeof(src_str));
  809. pim_inet4_dump("<grp?>", up->group_addr, grp_str, sizeof(grp_str));
  810. vty_out(vty, "%-9s %-15s %-15s %-10s %-5s %-10s %-11s %-6s%s",
  811. ifp->name,
  812. src_str,
  813. grp_str,
  814. pim_macro_ch_lost_assert(ch) ? "yes" : "no",
  815. pim_macro_chisin_joins(ch) ? "yes" : "no",
  816. pim_macro_chisin_pim_include(ch) ? "yes" : "no",
  817. PIM_UPSTREAM_FLAG_TEST_DR_JOIN_DESIRED(up->flags) ? "yes" : "no",
  818. pim_upstream_evaluate_join_desired(up) ? "yes" : "no",
  819. VTY_NEWLINE);
  820. }
  821. }
  822. }
  823. static void pim_show_upstream_rpf(struct vty *vty)
  824. {
  825. struct listnode *upnode;
  826. struct pim_upstream *up;
  827. vty_out(vty,
  828. "Source Group RpfIface RibNextHop RpfAddress %s",
  829. VTY_NEWLINE);
  830. for (ALL_LIST_ELEMENTS_RO(qpim_upstream_list, upnode, up)) {
  831. char src_str[100];
  832. char grp_str[100];
  833. char rpf_nexthop_str[100];
  834. char rpf_addr_str[100];
  835. struct pim_rpf *rpf;
  836. const char *rpf_ifname;
  837. rpf = &up->rpf;
  838. pim_inet4_dump("<src?>", up->source_addr, src_str, sizeof(src_str));
  839. pim_inet4_dump("<grp?>", up->group_addr, grp_str, sizeof(grp_str));
  840. pim_inet4_dump("<nexthop?>", rpf->source_nexthop.mrib_nexthop_addr, rpf_nexthop_str, sizeof(rpf_nexthop_str));
  841. pim_inet4_dump("<rpf?>", rpf->rpf_addr, rpf_addr_str, sizeof(rpf_addr_str));
  842. rpf_ifname = rpf->source_nexthop.interface ? rpf->source_nexthop.interface->name : "<ifname?>";
  843. vty_out(vty, "%-15s %-15s %-8s %-15s %-15s%s",
  844. src_str,
  845. grp_str,
  846. rpf_ifname,
  847. rpf_nexthop_str,
  848. rpf_addr_str,
  849. VTY_NEWLINE);
  850. }
  851. }
  852. static void show_rpf_refresh_stats(struct vty *vty, time_t now)
  853. {
  854. char refresh_uptime[10];
  855. pim_time_uptime_begin(refresh_uptime, sizeof(refresh_uptime), now, qpim_rpf_cache_refresh_last);
  856. vty_out(vty,
  857. "RPF Cache Refresh Delay: %ld msecs%s"
  858. "RPF Cache Refresh Timer: %ld msecs%s"
  859. "RPF Cache Refresh Requests: %lld%s"
  860. "RPF Cache Refresh Events: %lld%s"
  861. "RPF Cache Refresh Last: %s%s",
  862. qpim_rpf_cache_refresh_delay_msec, VTY_NEWLINE,
  863. pim_time_timer_remain_msec(qpim_rpf_cache_refresher), VTY_NEWLINE,
  864. (long long)qpim_rpf_cache_refresh_requests, VTY_NEWLINE,
  865. (long long)qpim_rpf_cache_refresh_events, VTY_NEWLINE,
  866. refresh_uptime, VTY_NEWLINE);
  867. }
  868. static void show_scan_oil_stats(struct vty *vty, time_t now)
  869. {
  870. char uptime_scan_oil[10];
  871. char uptime_mroute_add[10];
  872. char uptime_mroute_del[10];
  873. pim_time_uptime_begin(uptime_scan_oil, sizeof(uptime_scan_oil), now, qpim_scan_oil_last);
  874. pim_time_uptime_begin(uptime_mroute_add, sizeof(uptime_mroute_add), now, qpim_mroute_add_last);
  875. pim_time_uptime_begin(uptime_mroute_del, sizeof(uptime_mroute_del), now, qpim_mroute_del_last);
  876. vty_out(vty,
  877. "Scan OIL - Last: %s Events: %lld%s"
  878. "MFC Add - Last: %s Events: %lld%s"
  879. "MFC Del - Last: %s Events: %lld%s",
  880. uptime_scan_oil, (long long) qpim_scan_oil_events, VTY_NEWLINE,
  881. uptime_mroute_add, (long long) qpim_mroute_add_events, VTY_NEWLINE,
  882. uptime_mroute_del, (long long) qpim_mroute_del_events, VTY_NEWLINE);
  883. }
  884. static void pim_show_rpf(struct vty *vty)
  885. {
  886. struct listnode *up_node;
  887. struct pim_upstream *up;
  888. time_t now = pim_time_monotonic_sec();
  889. show_rpf_refresh_stats(vty, now);
  890. vty_out(vty, "%s", VTY_NEWLINE);
  891. vty_out(vty,
  892. "Source Group RpfIface RpfAddress RibNextHop Metric Pref%s",
  893. VTY_NEWLINE);
  894. for (ALL_LIST_ELEMENTS_RO(qpim_upstream_list, up_node, up)) {
  895. char src_str[100];
  896. char grp_str[100];
  897. char rpf_addr_str[100];
  898. char rib_nexthop_str[100];
  899. const char *rpf_ifname;
  900. struct pim_rpf *rpf = &up->rpf;
  901. pim_inet4_dump("<src?>", up->source_addr, src_str, sizeof(src_str));
  902. pim_inet4_dump("<grp?>", up->group_addr, grp_str, sizeof(grp_str));
  903. pim_inet4_dump("<rpf?>", rpf->rpf_addr, rpf_addr_str, sizeof(rpf_addr_str));
  904. pim_inet4_dump("<nexthop?>", rpf->source_nexthop.mrib_nexthop_addr, rib_nexthop_str, sizeof(rib_nexthop_str));
  905. rpf_ifname = rpf->source_nexthop.interface ? rpf->source_nexthop.interface->name : "<ifname?>";
  906. vty_out(vty, "%-15s %-15s %-8s %-15s %-15s %6d %4d%s",
  907. src_str,
  908. grp_str,
  909. rpf_ifname,
  910. rpf_addr_str,
  911. rib_nexthop_str,
  912. rpf->source_nexthop.mrib_route_metric,
  913. rpf->source_nexthop.mrib_metric_preference,
  914. VTY_NEWLINE);
  915. }
  916. }
  917. static void igmp_show_querier(struct vty *vty)
  918. {
  919. struct listnode *node;
  920. struct interface *ifp;
  921. vty_out(vty, "Interface Address Querier StartCount Query-Timer Other-Timer%s", VTY_NEWLINE);
  922. for (ALL_LIST_ELEMENTS_RO(iflist, node, ifp)) {
  923. struct pim_interface *pim_ifp = ifp->info;
  924. struct listnode *sock_node;
  925. struct igmp_sock *igmp;
  926. if (!pim_ifp)
  927. continue;
  928. for (ALL_LIST_ELEMENTS_RO(pim_ifp->igmp_socket_list, sock_node, igmp)) {
  929. char query_hhmmss[10];
  930. char other_hhmmss[10];
  931. pim_time_timer_to_hhmmss(query_hhmmss, sizeof(query_hhmmss), igmp->t_igmp_query_timer);
  932. pim_time_timer_to_hhmmss(other_hhmmss, sizeof(other_hhmmss), igmp->t_other_querier_timer);
  933. vty_out(vty, "%-9s %-15s %-7s %10d %11s %11s%s",
  934. ifp->name,
  935. inet_ntoa(igmp->ifaddr),
  936. igmp->t_igmp_query_timer ? "THIS" : "OTHER",
  937. igmp->startup_query_count,
  938. query_hhmmss,
  939. other_hhmmss,
  940. VTY_NEWLINE);
  941. }
  942. }
  943. }
  944. static void igmp_show_groups(struct vty *vty)
  945. {
  946. struct listnode *ifnode;
  947. struct interface *ifp;
  948. time_t now;
  949. now = pim_time_monotonic_sec();
  950. vty_out(vty, "Interface Address Group Mode Timer Srcs V Uptime %s", VTY_NEWLINE);
  951. /* scan interfaces */
  952. for (ALL_LIST_ELEMENTS_RO(iflist, ifnode, ifp)) {
  953. struct pim_interface *pim_ifp = ifp->info;
  954. struct listnode *sock_node;
  955. struct igmp_sock *igmp;
  956. if (!pim_ifp)
  957. continue;
  958. /* scan igmp sockets */
  959. for (ALL_LIST_ELEMENTS_RO(pim_ifp->igmp_socket_list, sock_node, igmp)) {
  960. char ifaddr_str[100];
  961. struct listnode *grpnode;
  962. struct igmp_group *grp;
  963. pim_inet4_dump("<ifaddr?>", igmp->ifaddr, ifaddr_str, sizeof(ifaddr_str));
  964. /* scan igmp groups */
  965. for (ALL_LIST_ELEMENTS_RO(igmp->igmp_group_list, grpnode, grp)) {
  966. char group_str[100];
  967. char hhmmss[10];
  968. char uptime[10];
  969. pim_inet4_dump("<group?>", grp->group_addr, group_str, sizeof(group_str));
  970. pim_time_timer_to_hhmmss(hhmmss, sizeof(hhmmss), grp->t_group_timer);
  971. pim_time_uptime(uptime, sizeof(uptime), now - grp->group_creation);
  972. vty_out(vty, "%-9s %-15s %-15s %4s %8s %4d %d %8s%s",
  973. ifp->name,
  974. ifaddr_str,
  975. group_str,
  976. grp->group_filtermode_isexcl ? "EXCL" : "INCL",
  977. hhmmss,
  978. grp->group_source_list ? listcount(grp->group_source_list) : 0,
  979. igmp_group_compat_mode(igmp, grp),
  980. uptime,
  981. VTY_NEWLINE);
  982. } /* scan igmp groups */
  983. } /* scan igmp sockets */
  984. } /* scan interfaces */
  985. }
  986. static void igmp_show_group_retransmission(struct vty *vty)
  987. {
  988. struct listnode *ifnode;
  989. struct interface *ifp;
  990. vty_out(vty, "Interface Address Group RetTimer Counter RetSrcs%s", VTY_NEWLINE);
  991. /* scan interfaces */
  992. for (ALL_LIST_ELEMENTS_RO(iflist, ifnode, ifp)) {
  993. struct pim_interface *pim_ifp = ifp->info;
  994. struct listnode *sock_node;
  995. struct igmp_sock *igmp;
  996. if (!pim_ifp)
  997. continue;
  998. /* scan igmp sockets */
  999. for (ALL_LIST_ELEMENTS_RO(pim_ifp->igmp_socket_list, sock_node, igmp)) {
  1000. char ifaddr_str[100];
  1001. struct listnode *grpnode;
  1002. struct igmp_group *grp;
  1003. pim_inet4_dump("<ifaddr?>", igmp->ifaddr, ifaddr_str, sizeof(ifaddr_str));
  1004. /* scan igmp groups */
  1005. for (ALL_LIST_ELEMENTS_RO(igmp->igmp_group_list, grpnode, grp)) {
  1006. char group_str[100];
  1007. char grp_retr_mmss[10];
  1008. struct listnode *src_node;
  1009. struct igmp_source *src;
  1010. int grp_retr_sources = 0;
  1011. pim_inet4_dump("<group?>", grp->group_addr, group_str, sizeof(group_str));
  1012. pim_time_timer_to_mmss(grp_retr_mmss, sizeof(grp_retr_mmss), grp->t_group_query_retransmit_timer);
  1013. /* count group sources with retransmission state */
  1014. for (ALL_LIST_ELEMENTS_RO(grp->group_source_list, src_node, src)) {
  1015. if (src->source_query_retransmit_count > 0) {
  1016. ++grp_retr_sources;
  1017. }
  1018. }
  1019. vty_out(vty, "%-9s %-15s %-15s %-8s %7d %7d%s",
  1020. ifp->name,
  1021. ifaddr_str,
  1022. group_str,
  1023. grp_retr_mmss,
  1024. grp->group_specific_query_retransmit_count,
  1025. grp_retr_sources,
  1026. VTY_NEWLINE);
  1027. } /* scan igmp groups */
  1028. } /* scan igmp sockets */
  1029. } /* scan interfaces */
  1030. }
  1031. static void igmp_show_parameters(struct vty *vty)
  1032. {
  1033. struct listnode *ifnode;
  1034. struct interface *ifp;
  1035. vty_out(vty,
  1036. "QRV: Robustness Variable SQI: Startup Query Interval%s"
  1037. "QQI: Query Interval OQPI: Other Querier Present Interval%s"
  1038. "QRI: Query Response Interval LMQT: Last Member Query Time%s"
  1039. "GMI: Group Membership Interval OHPI: Older Host Present Interval%s%s",
  1040. VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
  1041. vty_out(vty,
  1042. "Interface Address QRV QQI QRI GMI SQI OQPI LMQT OHPI %s",
  1043. VTY_NEWLINE);
  1044. /* scan interfaces */
  1045. for (ALL_LIST_ELEMENTS_RO(iflist, ifnode, ifp)) {
  1046. struct pim_interface *pim_ifp = ifp->info;
  1047. struct listnode *sock_node;
  1048. struct igmp_sock *igmp;
  1049. if (!pim_ifp)
  1050. continue;
  1051. /* scan igmp sockets */
  1052. for (ALL_LIST_ELEMENTS_RO(pim_ifp->igmp_socket_list, sock_node, igmp)) {
  1053. char ifaddr_str[100];
  1054. long gmi_dsec; /* Group Membership Interval */
  1055. long oqpi_dsec; /* Other Querier Present Interval */
  1056. int sqi;
  1057. long lmqt_dsec;
  1058. long ohpi_dsec;
  1059. long qri_dsec;
  1060. pim_inet4_dump("<ifaddr?>", igmp->ifaddr, ifaddr_str, sizeof(ifaddr_str));
  1061. gmi_dsec = PIM_IGMP_GMI_MSEC(igmp->querier_robustness_variable,
  1062. igmp->querier_query_interval,
  1063. pim_ifp->igmp_query_max_response_time_dsec) / 100;
  1064. sqi = PIM_IGMP_SQI(pim_ifp->igmp_default_query_interval);
  1065. oqpi_dsec = PIM_IGMP_OQPI_MSEC(igmp->querier_robustness_variable,
  1066. igmp->querier_query_interval,
  1067. pim_ifp->igmp_query_max_response_time_dsec) / 100;
  1068. lmqt_dsec = PIM_IGMP_LMQT_MSEC(pim_ifp->igmp_query_max_response_time_dsec,
  1069. igmp->querier_robustness_variable) / 100;
  1070. ohpi_dsec = PIM_IGMP_OHPI_DSEC(igmp->querier_robustness_variable,
  1071. igmp->querier_query_interval,
  1072. pim_ifp->igmp_query_max_response_time_dsec);
  1073. qri_dsec = pim_ifp->igmp_query_max_response_time_dsec;
  1074. vty_out(vty,
  1075. "%-9s %-15s %3d %3d %3ld.%ld %3ld.%ld %3d %3ld.%ld %3ld.%ld %3ld.%ld%s",
  1076. ifp->name,
  1077. ifaddr_str,
  1078. igmp->querier_robustness_variable,
  1079. igmp->querier_query_interval,
  1080. qri_dsec / 10, qri_dsec % 10,
  1081. gmi_dsec / 10, gmi_dsec % 10,
  1082. sqi,
  1083. oqpi_dsec / 10, oqpi_dsec % 10,
  1084. lmqt_dsec / 10, lmqt_dsec % 10,
  1085. ohpi_dsec / 10, ohpi_dsec % 10,
  1086. VTY_NEWLINE);
  1087. } /* scan igmp sockets */
  1088. } /* scan interfaces */
  1089. }
  1090. static void igmp_show_sources(struct vty *vty)
  1091. {
  1092. struct listnode *ifnode;
  1093. struct interface *ifp;
  1094. time_t now;
  1095. now = pim_time_monotonic_sec();
  1096. vty_out(vty, "Interface Address Group Source Timer Fwd Uptime %s", VTY_NEWLINE);
  1097. /* scan interfaces */
  1098. for (ALL_LIST_ELEMENTS_RO(iflist, ifnode, ifp)) {
  1099. struct pim_interface *pim_ifp = ifp->info;
  1100. struct listnode *sock_node;
  1101. struct igmp_sock *igmp;
  1102. if (!pim_ifp)
  1103. continue;
  1104. /* scan igmp sockets */
  1105. for (ALL_LIST_ELEMENTS_RO(pim_ifp->igmp_socket_list, sock_node, igmp)) {
  1106. char ifaddr_str[100];
  1107. struct listnode *grpnode;
  1108. struct igmp_group *grp;
  1109. pim_inet4_dump("<ifaddr?>", igmp->ifaddr, ifaddr_str, sizeof(ifaddr_str));
  1110. /* scan igmp groups */
  1111. for (ALL_LIST_ELEMENTS_RO(igmp->igmp_group_list, grpnode, grp)) {
  1112. char group_str[100];
  1113. struct listnode *srcnode;
  1114. struct igmp_source *src;
  1115. pim_inet4_dump("<group?>", grp->group_addr, group_str, sizeof(group_str));
  1116. /* scan group sources */
  1117. for (ALL_LIST_ELEMENTS_RO(grp->group_source_list, srcnode, src)) {
  1118. char source_str[100];
  1119. char mmss[10];
  1120. char uptime[10];
  1121. pim_inet4_dump("<source?>", src->source_addr, source_str, sizeof(source_str));
  1122. pim_time_timer_to_mmss(mmss, sizeof(mmss), src->t_source_timer);
  1123. pim_time_uptime(uptime, sizeof(uptime), now - src->source_creation);
  1124. vty_out(vty, "%-9s %-15s %-15s %-15s %5s %3s %8s%s",
  1125. ifp->name,
  1126. ifaddr_str,
  1127. group_str,
  1128. source_str,
  1129. mmss,
  1130. IGMP_SOURCE_TEST_FORWARDING(src->source_flags) ? "Y" : "N",
  1131. uptime,
  1132. VTY_NEWLINE);
  1133. } /* scan group sources */
  1134. } /* scan igmp groups */
  1135. } /* scan igmp sockets */
  1136. } /* scan interfaces */
  1137. }
  1138. static void igmp_show_source_retransmission(struct vty *vty)
  1139. {
  1140. struct listnode *ifnode;
  1141. struct interface *ifp;
  1142. vty_out(vty, "Interface Address Group Source Counter%s", VTY_NEWLINE);
  1143. /* scan interfaces */
  1144. for (ALL_LIST_ELEMENTS_RO(iflist, ifnode, ifp)) {
  1145. struct pim_interface *pim_ifp = ifp->info;
  1146. struct listnode *sock_node;
  1147. struct igmp_sock *igmp;
  1148. if (!pim_ifp)
  1149. continue;
  1150. /* scan igmp sockets */
  1151. for (ALL_LIST_ELEMENTS_RO(pim_ifp->igmp_socket_list, sock_node, igmp)) {
  1152. char ifaddr_str[100];
  1153. struct listnode *grpnode;
  1154. struct igmp_group *grp;
  1155. pim_inet4_dump("<ifaddr?>", igmp->ifaddr, ifaddr_str, sizeof(ifaddr_str));
  1156. /* scan igmp groups */
  1157. for (ALL_LIST_ELEMENTS_RO(igmp->igmp_group_list, grpnode, grp)) {
  1158. char group_str[100];
  1159. struct listnode *srcnode;
  1160. struct igmp_source *src;
  1161. pim_inet4_dump("<group?>", grp->group_addr, group_str, sizeof(group_str));
  1162. /* scan group sources */
  1163. for (ALL_LIST_ELEMENTS_RO(grp->group_source_list, srcnode, src)) {
  1164. char source_str[100];
  1165. pim_inet4_dump("<source?>", src->source_addr, source_str, sizeof(source_str));
  1166. vty_out(vty, "%-9s %-15s %-15s %-15s %7d%s",
  1167. ifp->name,
  1168. ifaddr_str,
  1169. group_str,
  1170. source_str,
  1171. src->source_query_retransmit_count,
  1172. VTY_NEWLINE);
  1173. } /* scan group sources */
  1174. } /* scan igmp groups */
  1175. } /* scan igmp sockets */
  1176. } /* scan interfaces */
  1177. }
  1178. static void clear_igmp_interfaces()
  1179. {
  1180. struct listnode *ifnode;
  1181. struct listnode *ifnextnode;
  1182. struct interface *ifp;
  1183. for (ALL_LIST_ELEMENTS(iflist, ifnode, ifnextnode, ifp)) {
  1184. pim_if_addr_del_all_igmp(ifp);
  1185. }
  1186. for (ALL_LIST_ELEMENTS(iflist, ifnode, ifnextnode, ifp)) {
  1187. pim_if_addr_add_all(ifp);
  1188. }
  1189. }
  1190. static void clear_pim_interfaces()
  1191. {
  1192. struct listnode *ifnode;
  1193. struct listnode *ifnextnode;
  1194. struct interface *ifp;
  1195. for (ALL_LIST_ELEMENTS(iflist, ifnode, ifnextnode, ifp)) {
  1196. if (ifp->info) {
  1197. pim_neighbor_delete_all(ifp, "interface cleared");
  1198. }
  1199. }
  1200. }
  1201. static void clear_interfaces()
  1202. {
  1203. clear_igmp_interfaces();
  1204. clear_pim_interfaces();
  1205. }
  1206. DEFUN (pim_interface,
  1207. pim_interface_cmd,
  1208. "interface IFNAME",
  1209. "Select an interface to configure\n"
  1210. "Interface's name\n")
  1211. {
  1212. struct interface *ifp;
  1213. const char *ifname = argv[0];
  1214. size_t sl;
  1215. sl = strlen(ifname);
  1216. if (sl > INTERFACE_NAMSIZ) {
  1217. vty_out(vty, "%% Interface name %s is invalid: length exceeds "
  1218. "%d characters%s",
  1219. ifname, INTERFACE_NAMSIZ, VTY_NEWLINE);
  1220. return CMD_WARNING;
  1221. }
  1222. ifp = if_lookup_by_name_len(ifname, sl);
  1223. if (!ifp) {
  1224. vty_out(vty, "%% Interface %s does not exist%s", ifname, VTY_NEWLINE);
  1225. /* Returning here would prevent pimd from booting when there are
  1226. interface commands in pimd.conf, since all interfaces are
  1227. unknown at pimd boot time (the zebra daemon has not been
  1228. contacted for interface discovery). */
  1229. ifp = if_get_by_name_len(ifname, sl);
  1230. if (!ifp) {
  1231. vty_out(vty, "%% Could not create interface %s%s", ifname, VTY_NEWLINE);
  1232. return CMD_WARNING;
  1233. }
  1234. }
  1235. vty->index = ifp;
  1236. vty->node = INTERFACE_NODE;
  1237. return CMD_SUCCESS;
  1238. }
  1239. DEFUN (clear_ip_interfaces,
  1240. clear_ip_interfaces_cmd,
  1241. "clear ip interfaces",
  1242. CLEAR_STR
  1243. IP_STR
  1244. "Reset interfaces\n")
  1245. {
  1246. clear_interfaces();
  1247. return CMD_SUCCESS;
  1248. }
  1249. DEFUN (clear_ip_igmp_interfaces,
  1250. clear_ip_igmp_interfaces_cmd,
  1251. "clear ip igmp interfaces",
  1252. CLEAR_STR
  1253. IP_STR
  1254. CLEAR_IP_IGMP_STR
  1255. "Reset IGMP interfaces\n")
  1256. {
  1257. clear_igmp_interfaces();
  1258. return CMD_SUCCESS;
  1259. }
  1260. static void mroute_add_all()
  1261. {
  1262. struct listnode *node;
  1263. struct channel_oil *c_oil;
  1264. for (ALL_LIST_ELEMENTS_RO(qpim_channel_oil_list, node, c_oil)) {
  1265. if (pim_mroute_add(&c_oil->oil)) {
  1266. /* just log warning */
  1267. char source_str[100];
  1268. char group_str[100];
  1269. pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin, source_str, sizeof(source_str));
  1270. pim_inet4_dump("<group?>", c_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
  1271. zlog_warn("%s %s: (S,G)=(%s,%s) failure writing MFC",
  1272. __FILE__, __PRETTY_FUNCTION__,
  1273. source_str, group_str);
  1274. }
  1275. }
  1276. }
  1277. static void mroute_del_all()
  1278. {
  1279. struct listnode *node;
  1280. struct channel_oil *c_oil;
  1281. for (ALL_LIST_ELEMENTS_RO(qpim_channel_oil_list, node, c_oil)) {
  1282. if (pim_mroute_del(&c_oil->oil)) {
  1283. /* just log warning */
  1284. char source_str[100];
  1285. char group_str[100];
  1286. pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin, source_str, sizeof(source_str));
  1287. pim_inet4_dump("<group?>", c_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
  1288. zlog_warn("%s %s: (S,G)=(%s,%s) failure clearing MFC",
  1289. __FILE__, __PRETTY_FUNCTION__,
  1290. source_str, group_str);
  1291. }
  1292. }
  1293. }
  1294. DEFUN (clear_ip_mroute,
  1295. clear_ip_mroute_cmd,
  1296. "clear ip mroute",
  1297. CLEAR_STR
  1298. IP_STR
  1299. "Reset multicast routes\n")
  1300. {
  1301. mroute_del_all();
  1302. mroute_add_all();
  1303. return CMD_SUCCESS;
  1304. }
  1305. DEFUN (clear_ip_pim_interfaces,
  1306. clear_ip_pim_interfaces_cmd,
  1307. "clear ip pim interfaces",
  1308. CLEAR_STR
  1309. IP_STR
  1310. CLEAR_IP_PIM_STR
  1311. "Reset PIM interfaces\n")
  1312. {
  1313. clear_pim_interfaces();
  1314. return CMD_SUCCESS;
  1315. }
  1316. DEFUN (clear_ip_pim_oil,
  1317. clear_ip_pim_oil_cmd,
  1318. "clear ip pim oil",
  1319. CLEAR_STR
  1320. IP_STR
  1321. CLEAR_IP_PIM_STR
  1322. "Rescan PIM OIL (output interface list)\n")
  1323. {
  1324. pim_scan_oil();
  1325. return CMD_SUCCESS;
  1326. }
  1327. DEFUN (show_ip_igmp_interface,
  1328. show_ip_igmp_interface_cmd,
  1329. "show ip igmp interface",
  1330. SHOW_STR
  1331. IP_STR
  1332. IGMP_STR
  1333. "IGMP interface information\n")
  1334. {
  1335. igmp_show_interfaces(vty);
  1336. return CMD_SUCCESS;
  1337. }
  1338. DEFUN (show_ip_igmp_join,
  1339. show_ip_igmp_join_cmd,
  1340. "show ip igmp join",
  1341. SHOW_STR
  1342. IP_STR
  1343. IGMP_STR
  1344. "IGMP static join information\n")
  1345. {
  1346. igmp_show_interface_join(vty);
  1347. return CMD_SUCCESS;
  1348. }
  1349. DEFUN (show_ip_igmp_groups,
  1350. show_ip_igmp_groups_cmd,
  1351. "show ip igmp groups",
  1352. SHOW_STR
  1353. IP_STR
  1354. IGMP_STR
  1355. IGMP_GROUP_STR)
  1356. {
  1357. igmp_show_groups(vty);
  1358. return CMD_SUCCESS;
  1359. }
  1360. DEFUN (show_ip_igmp_groups_retransmissions,
  1361. show_ip_igmp_groups_retransmissions_cmd,
  1362. "show ip igmp groups retransmissions",
  1363. SHOW_STR
  1364. IP_STR
  1365. IGMP_STR
  1366. IGMP_GROUP_STR
  1367. "IGMP group retransmissions\n")
  1368. {
  1369. igmp_show_group_retransmission(vty);
  1370. return CMD_SUCCESS;
  1371. }
  1372. DEFUN (show_ip_igmp_parameters,
  1373. show_ip_igmp_parameters_cmd,
  1374. "show ip igmp parameters",
  1375. SHOW_STR
  1376. IP_STR
  1377. IGMP_STR
  1378. "IGMP parameters information\n")
  1379. {
  1380. igmp_show_parameters(vty);
  1381. return CMD_SUCCESS;
  1382. }
  1383. DEFUN (show_ip_igmp_sources,
  1384. show_ip_igmp_sources_cmd,
  1385. "show ip igmp sources",
  1386. SHOW_STR
  1387. IP_STR
  1388. IGMP_STR
  1389. IGMP_SOURCE_STR)
  1390. {
  1391. igmp_show_sources(vty);
  1392. return CMD_SUCCESS;
  1393. }
  1394. DEFUN (show_ip_igmp_sources_retransmissions,
  1395. show_ip_igmp_sources_retransmissions_cmd,
  1396. "show ip igmp sources retransmissions",
  1397. SHOW_STR
  1398. IP_STR
  1399. IGMP_STR
  1400. IGMP_SOURCE_STR
  1401. "IGMP source retransmissions\n")
  1402. {
  1403. igmp_show_source_retransmission(vty);
  1404. return CMD_SUCCESS;
  1405. }
  1406. DEFUN (show_ip_igmp_querier,
  1407. show_ip_igmp_querier_cmd,
  1408. "show ip igmp querier",
  1409. SHOW_STR
  1410. IP_STR
  1411. IGMP_STR
  1412. "IGMP querier information\n")
  1413. {
  1414. igmp_show_querier(vty);
  1415. return CMD_SUCCESS;
  1416. }
  1417. DEFUN (show_ip_pim_address,
  1418. show_ip_pim_address_cmd,
  1419. "show ip pim address",
  1420. SHOW_STR
  1421. IP_STR
  1422. PIM_STR
  1423. "PIM interface address\n")
  1424. {
  1425. show_interface_address(vty);
  1426. return CMD_SUCCESS;
  1427. }
  1428. DEFUN (show_ip_pim_assert,
  1429. show_ip_pim_assert_cmd,
  1430. "show ip pim assert",
  1431. SHOW_STR
  1432. IP_STR
  1433. PIM_STR
  1434. "PIM interface assert\n")
  1435. {
  1436. pim_show_assert(vty);
  1437. return CMD_SUCCESS;
  1438. }
  1439. DEFUN (show_ip_pim_assert_internal,
  1440. show_ip_pim_assert_internal_cmd,
  1441. "show ip pim assert-internal",
  1442. SHOW_STR
  1443. IP_STR
  1444. PIM_STR
  1445. "PIM interface internal assert state\n")
  1446. {
  1447. pim_show_assert_internal(vty);
  1448. return CMD_SUCCESS;
  1449. }
  1450. DEFUN (show_ip_pim_assert_metric,
  1451. show_ip_pim_assert_metric_cmd,
  1452. "show ip pim assert-metric",
  1453. SHOW_STR
  1454. IP_STR
  1455. PIM_STR
  1456. "PIM interface assert metric\n")
  1457. {
  1458. pim_show_assert_metric(vty);
  1459. return CMD_SUCCESS;
  1460. }
  1461. DEFUN (show_ip_pim_assert_winner_metric,
  1462. show_ip_pim_assert_winner_metric_cmd,
  1463. "show ip pim assert-winner-metric",
  1464. SHOW_STR
  1465. IP_STR
  1466. PIM_STR
  1467. "PIM interface assert winner metric\n")
  1468. {
  1469. pim_show_assert_winner_metric(vty);
  1470. return CMD_SUCCESS;
  1471. }
  1472. DEFUN (show_ip_pim_dr,
  1473. show_ip_pim_dr_cmd,
  1474. "show ip pim designated-router",
  1475. SHOW_STR
  1476. IP_STR
  1477. PIM_STR
  1478. "PIM interface designated router\n")
  1479. {
  1480. pim_show_dr(vty);
  1481. return CMD_SUCCESS;
  1482. }
  1483. DEFUN (show_ip_pim_hello,
  1484. show_ip_pim_hello_cmd,
  1485. "show ip pim hello",
  1486. SHOW_STR
  1487. IP_STR
  1488. PIM_STR
  1489. "PIM interface hello information\n")
  1490. {
  1491. pim_show_hello(vty);
  1492. return CMD_SUCCESS;
  1493. }
  1494. DEFUN (show_ip_pim_interface,
  1495. show_ip_pim_interface_cmd,
  1496. "show ip pim interface",
  1497. SHOW_STR
  1498. IP_STR
  1499. PIM_STR
  1500. "PIM interface information\n")
  1501. {
  1502. pim_show_interfaces(vty);
  1503. return CMD_SUCCESS;
  1504. }
  1505. DEFUN (show_ip_pim_join,
  1506. show_ip_pim_join_cmd,
  1507. "show ip pim join",
  1508. SHOW_STR
  1509. IP_STR
  1510. PIM_STR
  1511. "PIM interface join information\n")
  1512. {
  1513. pim_show_join(vty);
  1514. return CMD_SUCCESS;
  1515. }
  1516. DEFUN (show_ip_pim_lan_prune_delay,
  1517. show_ip_pim_lan_prune_delay_cmd,
  1518. "show ip pim lan-prune-delay",
  1519. SHOW_STR
  1520. IP_STR
  1521. PIM_STR
  1522. "PIM neighbors LAN prune delay parameters\n")
  1523. {
  1524. pim_show_lan_prune_delay(vty);
  1525. return CMD_SUCCESS;
  1526. }
  1527. DEFUN (show_ip_pim_local_membership,
  1528. show_ip_pim_local_membership_cmd,
  1529. "show ip pim local-membership",
  1530. SHOW_STR
  1531. IP_STR
  1532. PIM_STR
  1533. "PIM interface local-membership\n")
  1534. {
  1535. pim_show_membership(vty);
  1536. return CMD_SUCCESS;
  1537. }
  1538. DEFUN (show_ip_pim_jp_override_interval,
  1539. show_ip_pim_jp_override_interval_cmd,
  1540. "show ip pim jp-override-interval",
  1541. SHOW_STR
  1542. IP_STR
  1543. PIM_STR
  1544. "PIM interface J/P override interval\n")
  1545. {
  1546. pim_show_jp_override_interval(vty);
  1547. return CMD_SUCCESS;
  1548. }
  1549. DEFUN (show_ip_pim_neighbor,
  1550. show_ip_pim_neighbor_cmd,
  1551. "show ip pim neighbor",
  1552. SHOW_STR
  1553. IP_STR
  1554. PIM_STR
  1555. "PIM neighbor information\n")
  1556. {
  1557. pim_show_neighbors(vty);
  1558. return CMD_SUCCESS;
  1559. }
  1560. DEFUN (show_ip_pim_secondary,
  1561. show_ip_pim_secondary_cmd,
  1562. "show ip pim secondary",
  1563. SHOW_STR
  1564. IP_STR
  1565. PIM_STR
  1566. "PIM neighbor addresses\n")
  1567. {
  1568. pim_show_neighbors_secondary(vty);
  1569. return CMD_SUCCESS;
  1570. }
  1571. DEFUN (show_ip_pim_upstream,
  1572. show_ip_pim_upstream_cmd,
  1573. "show ip pim upstream",
  1574. SHOW_STR
  1575. IP_STR
  1576. PIM_STR
  1577. "PIM upstream information\n")
  1578. {
  1579. pim_show_upstream(vty);
  1580. return CMD_SUCCESS;
  1581. }
  1582. DEFUN (show_ip_pim_upstream_join_desired,
  1583. show_ip_pim_upstream_join_desired_cmd,
  1584. "show ip pim upstream-join-desired",
  1585. SHOW_STR
  1586. IP_STR
  1587. PIM_STR
  1588. "PIM upstream join-desired\n")
  1589. {
  1590. pim_show_join_desired(vty);
  1591. return CMD_SUCCESS;
  1592. }
  1593. DEFUN (show_ip_pim_upstream_rpf,
  1594. show_ip_pim_upstream_rpf_cmd,
  1595. "show ip pim upstream-rpf",
  1596. SHOW_STR
  1597. IP_STR
  1598. PIM_STR
  1599. "PIM upstream source rpf\n")
  1600. {
  1601. pim_show_upstream_rpf(vty);
  1602. return CMD_SUCCESS;
  1603. }
  1604. DEFUN (show_ip_pim_rpf,
  1605. show_ip_pim_rpf_cmd,
  1606. "show ip pim rpf",
  1607. SHOW_STR
  1608. IP_STR
  1609. PIM_STR
  1610. "PIM cached source rpf information\n")
  1611. {
  1612. pim_show_rpf(vty);
  1613. return CMD_SUCCESS;
  1614. }
  1615. static void show_multicast_interfaces(struct vty *vty)
  1616. {
  1617. struct listnode *node;
  1618. struct interface *ifp;
  1619. vty_out(vty, "%s", VTY_NEWLINE);
  1620. vty_out(vty, "Interface Address ifi Vif PktsIn PktsOut BytesIn BytesOut%s",
  1621. VTY_NEWLINE);
  1622. for (ALL_LIST_ELEMENTS_RO(iflist, node, ifp)) {
  1623. struct pim_interface *pim_ifp;
  1624. struct in_addr ifaddr;
  1625. struct sioc_vif_req vreq;
  1626. pim_ifp = ifp->info;
  1627. if (!pim_ifp)
  1628. continue;
  1629. memset(&vreq, 0, sizeof(vreq));
  1630. vreq.vifi = pim_ifp->mroute_vif_index;
  1631. if (ioctl(qpim_mroute_socket_fd, SIOCGETVIFCNT, &vreq)) {
  1632. int e = errno;
  1633. vty_out(vty,
  1634. "ioctl(SIOCGETVIFCNT=%d) failure for interface %s vif_index=%d: errno=%d: %s%s",
  1635. SIOCGETVIFCNT,
  1636. ifp->name,
  1637. pim_ifp->mroute_vif_index,
  1638. e,
  1639. safe_strerror(e),
  1640. VTY_NEWLINE);
  1641. continue;
  1642. }
  1643. ifaddr = pim_ifp->primary_address;
  1644. vty_out(vty, "%-9s %-15s %3d %3d %7lu %7lu %10lu %10lu%s",
  1645. ifp->name,
  1646. inet_ntoa(ifaddr),
  1647. ifp->ifindex,
  1648. pim_ifp->mroute_vif_index,
  1649. vreq.icount,
  1650. vreq.ocount,
  1651. vreq.ibytes,
  1652. vreq.obytes,
  1653. VTY_NEWLINE);
  1654. }
  1655. }
  1656. DEFUN (show_ip_multicast,
  1657. show_ip_multicast_cmd,
  1658. "show ip multicast",
  1659. SHOW_STR
  1660. IP_STR
  1661. "Multicast global information\n")
  1662. {
  1663. time_t now = pim_time_monotonic_sec();
  1664. if (PIM_MROUTE_IS_ENABLED) {
  1665. char uptime[10];
  1666. vty_out(vty, "Mroute socket descriptor: %d%s",
  1667. qpim_mroute_socket_fd,
  1668. VTY_NEWLINE);
  1669. pim_time_uptime(uptime, sizeof(uptime), now - qpim_mroute_socket_creation);
  1670. vty_out(vty, "Mroute socket uptime: %s%s",
  1671. uptime,
  1672. VTY_NEWLINE);
  1673. }
  1674. else {
  1675. vty_out(vty, "Multicast disabled%s",
  1676. VTY_NEWLINE);
  1677. }
  1678. vty_out(vty, "%s", VTY_NEWLINE);
  1679. vty_out(vty, "Zclient update socket: ");
  1680. if (qpim_zclient_update) {
  1681. vty_out(vty, "%d failures=%d%s", qpim_zclient_update->sock,
  1682. qpim_zclient_update->fail, VTY_NEWLINE);
  1683. }
  1684. else {
  1685. vty_out(vty, "<null zclient>%s", VTY_NEWLINE);
  1686. }
  1687. vty_out(vty, "Zclient lookup socket: ");
  1688. if (qpim_zclient_lookup) {
  1689. vty_out(vty, "%d failures=%d%s", qpim_zclient_lookup->sock,
  1690. qpim_zclient_lookup->fail, VTY_NEWLINE);
  1691. }
  1692. else {
  1693. vty_out(vty, "<null zclient>%s", VTY_NEWLINE);
  1694. }
  1695. vty_out(vty, "%s", VTY_NEWLINE);
  1696. vty_out(vty, "Current highest VifIndex: %d%s",
  1697. qpim_mroute_oif_highest_vif_index,
  1698. VTY_NEWLINE);
  1699. vty_out(vty, "Maximum highest VifIndex: %d%s",
  1700. MAXVIFS - 1,
  1701. VTY_NEWLINE);
  1702. vty_out(vty, "%s", VTY_NEWLINE);
  1703. vty_out(vty, "Upstream Join Timer: %d secs%s",
  1704. qpim_t_periodic,
  1705. VTY_NEWLINE);
  1706. vty_out(vty, "Join/Prune Holdtime: %d secs%s",
  1707. PIM_JP_HOLDTIME,
  1708. VTY_NEWLINE);
  1709. vty_out(vty, "%s", VTY_NEWLINE);
  1710. show_rpf_refresh_stats(vty, now);
  1711. vty_out(vty, "%s", VTY_NEWLINE);
  1712. show_scan_oil_stats(vty, now);
  1713. show_multicast_interfaces(vty);
  1714. return CMD_SUCCESS;
  1715. }
  1716. static void show_mroute(struct vty *vty)
  1717. {
  1718. struct listnode *node;
  1719. struct channel_oil *c_oil;
  1720. time_t now;
  1721. vty_out(vty, "Proto: I=IGMP P=PIM%s%s", VTY_NEWLINE, VTY_NEWLINE);
  1722. vty_out(vty, "Source Group Proto Input iVifI Output oVifI TTL Uptime %s",
  1723. VTY_NEWLINE);
  1724. now = pim_time_monotonic_sec();
  1725. for (ALL_LIST_ELEMENTS_RO(qpim_channel_oil_list, node, c_oil)) {
  1726. char group_str[100];
  1727. char source_str[100];
  1728. int oif_vif_index;
  1729. pim_inet4_dump("<group?>", c_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
  1730. pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin, source_str, sizeof(source_str));
  1731. for (oif_vif_index = 0; oif_vif_index < MAXVIFS; ++oif_vif_index) {
  1732. struct interface *ifp_in;
  1733. struct interface *ifp_out;
  1734. char oif_uptime[10];
  1735. int ttl;
  1736. char proto[5];
  1737. ttl = c_oil->oil.mfcc_ttls[oif_vif_index];
  1738. if (ttl < 1)
  1739. continue;
  1740. ifp_in = pim_if_find_by_vif_index(c_oil->oil.mfcc_parent);
  1741. ifp_out = pim_if_find_by_vif_index(oif_vif_index);
  1742. pim_time_uptime(oif_uptime, sizeof(oif_uptime), now - c_oil->oif_creation[oif_vif_index]);
  1743. proto[0] = '\0';
  1744. if (c_oil->oif_flags[oif_vif_index] & PIM_OIF_FLAG_PROTO_PIM) {
  1745. strcat(proto, "P");
  1746. }
  1747. if (c_oil->oif_flags[oif_vif_index] & PIM_OIF_FLAG_PROTO_IGMP) {
  1748. strcat(proto, "I");
  1749. }
  1750. vty_out(vty, "%-15s %-15s %-5s %-5s %5d %-6s %5d %3d %8s %s",
  1751. source_str,
  1752. group_str,
  1753. proto,
  1754. ifp_in ? ifp_in->name : "<iif?>",
  1755. c_oil->oil.mfcc_parent,
  1756. ifp_out ? ifp_out->name : "<oif?>",
  1757. oif_vif_index,
  1758. ttl,
  1759. oif_uptime,
  1760. VTY_NEWLINE);
  1761. }
  1762. }
  1763. }
  1764. DEFUN (show_ip_mroute,
  1765. show_ip_mroute_cmd,
  1766. "show ip mroute",
  1767. SHOW_STR
  1768. IP_STR
  1769. MROUTE_STR)
  1770. {
  1771. show_mroute(vty);
  1772. return CMD_SUCCESS;
  1773. }
  1774. static void show_mroute_count(struct vty *vty)
  1775. {
  1776. struct listnode *node;
  1777. struct channel_oil *c_oil;
  1778. vty_out(vty, "%s", VTY_NEWLINE);
  1779. vty_out(vty, "Source Group Packets Bytes WrongIf %s",
  1780. VTY_NEWLINE);
  1781. for (ALL_LIST_ELEMENTS_RO(qpim_channel_oil_list, node, c_oil)) {
  1782. char group_str[100];
  1783. char source_str[100];
  1784. struct sioc_sg_req sgreq;
  1785. memset(&sgreq, 0, sizeof(sgreq));
  1786. sgreq.src = c_oil->oil.mfcc_origin;
  1787. sgreq.grp = c_oil->oil.mfcc_mcastgrp;
  1788. pim_inet4_dump("<group?>", c_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
  1789. pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin, source_str, sizeof(source_str));
  1790. if (ioctl(qpim_mroute_socket_fd, SIOCGETSGCNT, &sgreq)) {
  1791. int e = errno;
  1792. vty_out(vty,
  1793. "ioctl(SIOCGETSGCNT=%d) failure for (S,G)=(%s,%s): errno=%d: %s%s",
  1794. SIOCGETSGCNT,
  1795. source_str,
  1796. group_str,
  1797. e,
  1798. safe_strerror(e),
  1799. VTY_NEWLINE);
  1800. continue;
  1801. }
  1802. vty_out(vty, "%-15s %-15s %7ld %10ld %7ld %s",
  1803. source_str,
  1804. group_str,
  1805. sgreq.pktcnt,
  1806. sgreq.bytecnt,
  1807. sgreq.wrong_if,
  1808. VTY_NEWLINE);
  1809. }
  1810. }
  1811. DEFUN (show_ip_mroute_count,
  1812. show_ip_mroute_count_cmd,
  1813. "show ip mroute count",
  1814. SHOW_STR
  1815. IP_STR
  1816. MROUTE_STR
  1817. "Route and packet count data\n")
  1818. {
  1819. show_mroute_count(vty);
  1820. return CMD_SUCCESS;
  1821. }
  1822. DEFUN (show_ip_rib,
  1823. show_ip_rib_cmd,
  1824. "show ip rib A.B.C.D",
  1825. SHOW_STR
  1826. IP_STR
  1827. RIB_STR
  1828. "Unicast address\n")
  1829. {
  1830. struct in_addr addr;
  1831. const char *addr_str;
  1832. struct pim_nexthop nexthop;
  1833. char nexthop_addr_str[100];
  1834. int result;
  1835. addr_str = argv[0];
  1836. result = inet_pton(AF_INET, addr_str, &addr);
  1837. if (result <= 0) {
  1838. vty_out(vty, "Bad unicast address %s: errno=%d: %s%s",
  1839. addr_str, errno, safe_strerror(errno), VTY_NEWLINE);
  1840. return CMD_WARNING;
  1841. }
  1842. if (pim_nexthop_lookup(&nexthop, addr)) {
  1843. vty_out(vty, "Failure querying RIB nexthop for unicast address %s%s",
  1844. addr_str, VTY_NEWLINE);
  1845. return CMD_WARNING;
  1846. }
  1847. vty_out(vty, "Address NextHop Interface Metric Preference%s",
  1848. VTY_NEWLINE);
  1849. pim_inet4_dump("<nexthop?>", nexthop.mrib_nexthop_addr,
  1850. nexthop_addr_str, sizeof(nexthop_addr_str));
  1851. vty_out(vty, "%-15s %-15s %-9s %6d %10d%s",
  1852. addr_str,
  1853. nexthop_addr_str,
  1854. nexthop.interface ? nexthop.interface->name : "<ifname?>",
  1855. nexthop.mrib_route_metric,
  1856. nexthop.mrib_metric_preference,
  1857. VTY_NEWLINE);
  1858. return CMD_SUCCESS;
  1859. }
  1860. static void show_ssmpingd(struct vty *vty)
  1861. {
  1862. struct listnode *node;
  1863. struct ssmpingd_sock *ss;
  1864. time_t now;
  1865. vty_out(vty, "Source Socket Address Port Uptime Requests%s",
  1866. VTY_NEWLINE);
  1867. if (!qpim_ssmpingd_list)
  1868. return;
  1869. now = pim_time_monotonic_sec();
  1870. for (ALL_LIST_ELEMENTS_RO(qpim_ssmpingd_list, node, ss)) {
  1871. char source_str[100];
  1872. char ss_uptime[10];
  1873. struct sockaddr_in bind_addr;
  1874. socklen_t len = sizeof(bind_addr);
  1875. char bind_addr_str[100];
  1876. pim_inet4_dump("<src?>", ss->source_addr, source_str, sizeof(source_str));
  1877. if (pim_socket_getsockname(ss->sock_fd, (struct sockaddr *) &bind_addr, &len)) {
  1878. vty_out(vty, "%% Failure reading socket name for ssmpingd source %s on fd=%d%s",
  1879. source_str, ss->sock_fd, VTY_NEWLINE);
  1880. }
  1881. pim_inet4_dump("<addr?>", bind_addr.sin_addr, bind_addr_str, sizeof(bind_addr_str));
  1882. pim_time_uptime(ss_uptime, sizeof(ss_uptime), now - ss->creation);
  1883. vty_out(vty, "%-15s %6d %-15s %5d %8s %8lld%s",
  1884. source_str,
  1885. ss->sock_fd,
  1886. bind_addr_str,
  1887. ntohs(bind_addr.sin_port),
  1888. ss_uptime,
  1889. (long long)ss->requests,
  1890. VTY_NEWLINE);
  1891. }
  1892. }
  1893. DEFUN (show_ip_ssmpingd,
  1894. show_ip_ssmpingd_cmd,
  1895. "show ip ssmpingd",
  1896. SHOW_STR
  1897. IP_STR
  1898. SHOW_SSMPINGD_STR)
  1899. {
  1900. show_ssmpingd(vty);
  1901. return CMD_SUCCESS;
  1902. }
  1903. DEFUN (ip_multicast_routing,
  1904. ip_multicast_routing_cmd,
  1905. PIM_CMD_IP_MULTICAST_ROUTING,
  1906. IP_STR
  1907. "Enable IP multicast forwarding\n")
  1908. {
  1909. pim_mroute_socket_enable();
  1910. pim_if_add_vif_all();
  1911. mroute_add_all();
  1912. return CMD_SUCCESS;
  1913. }
  1914. DEFUN (no_ip_multicast_routing,
  1915. no_ip_multicast_routing_cmd,
  1916. PIM_CMD_NO " " PIM_CMD_IP_MULTICAST_ROUTING,
  1917. NO_STR
  1918. IP_STR
  1919. "Global IP configuration subcommands\n"
  1920. "Enable IP multicast forwarding\n")
  1921. {
  1922. mroute_del_all();
  1923. pim_if_del_vif_all();
  1924. pim_mroute_socket_disable();
  1925. return CMD_SUCCESS;
  1926. }
  1927. DEFUN (ip_ssmpingd,
  1928. ip_ssmpingd_cmd,
  1929. "ip ssmpingd [A.B.C.D]",
  1930. IP_STR
  1931. CONF_SSMPINGD_STR
  1932. "Source address\n")
  1933. {
  1934. int result;
  1935. struct in_addr source_addr;
  1936. const char *source_str = (argc > 0) ? argv[0] : "0.0.0.0";
  1937. result = inet_pton(AF_INET, source_str, &source_addr);
  1938. if (result <= 0) {
  1939. vty_out(vty, "%% Bad source address %s: errno=%d: %s%s",
  1940. source_str, errno, safe_strerror(errno), VTY_NEWLINE);
  1941. return CMD_WARNING;
  1942. }
  1943. result = pim_ssmpingd_start(source_addr);
  1944. if (result) {
  1945. vty_out(vty, "%% Failure starting ssmpingd for source %s: %d%s",
  1946. source_str, result, VTY_NEWLINE);
  1947. return CMD_WARNING;
  1948. }
  1949. return CMD_SUCCESS;
  1950. }
  1951. DEFUN (no_ip_ssmpingd,
  1952. no_ip_ssmpingd_cmd,
  1953. "no ip ssmpingd [A.B.C.D]",
  1954. NO_STR
  1955. IP_STR
  1956. CONF_SSMPINGD_STR
  1957. "Source address\n")
  1958. {
  1959. int result;
  1960. struct in_addr source_addr;
  1961. const char *source_str = (argc > 0) ? argv[0] : "0.0.0.0";
  1962. result = inet_pton(AF_INET, source_str, &source_addr);
  1963. if (result <= 0) {
  1964. vty_out(vty, "%% Bad source address %s: errno=%d: %s%s",
  1965. source_str, errno, safe_strerror(errno), VTY_NEWLINE);
  1966. return CMD_WARNING;
  1967. }
  1968. result = pim_ssmpingd_stop(source_addr);
  1969. if (result) {
  1970. vty_out(vty, "%% Failure stopping ssmpingd for source %s: %d%s",
  1971. source_str, result, VTY_NEWLINE);
  1972. return CMD_WARNING;
  1973. }
  1974. return CMD_SUCCESS;
  1975. }
  1976. DEFUN (interface_ip_igmp,
  1977. interface_ip_igmp_cmd,
  1978. "ip igmp",
  1979. IP_STR
  1980. IFACE_IGMP_STR)
  1981. {
  1982. struct interface *ifp;
  1983. struct pim_interface *pim_ifp;
  1984. ifp = vty->index;
  1985. pim_ifp = ifp->info;
  1986. if (!pim_ifp) {
  1987. pim_ifp = pim_if_new(ifp, 1 /* igmp=true */, 0 /* pim=false */);
  1988. if (!pim_ifp) {
  1989. vty_out(vty, "Could not enable IGMP on interface %s%s",
  1990. ifp->name, VTY_NEWLINE);
  1991. return CMD_WARNING;
  1992. }
  1993. }
  1994. else {
  1995. PIM_IF_DO_IGMP(pim_ifp->options);
  1996. }
  1997. pim_if_addr_add_all(ifp);
  1998. pim_if_membership_refresh(ifp);
  1999. return CMD_SUCCESS;
  2000. }
  2001. DEFUN (interface_no_ip_igmp,
  2002. interface_no_ip_igmp_cmd,
  2003. "no ip igmp",
  2004. NO_STR
  2005. IP_STR
  2006. IFACE_IGMP_STR)
  2007. {
  2008. struct interface *ifp;
  2009. struct pim_interface *pim_ifp;
  2010. ifp = vty->index;
  2011. pim_ifp = ifp->info;
  2012. if (!pim_ifp)
  2013. return CMD_SUCCESS;
  2014. PIM_IF_DONT_IGMP(pim_ifp->options);
  2015. pim_if_membership_clear(ifp);
  2016. pim_if_addr_del_all_igmp(ifp);
  2017. if (!PIM_IF_TEST_PIM(pim_ifp->options)) {
  2018. pim_if_delete(ifp);
  2019. }
  2020. return CMD_SUCCESS;
  2021. }
  2022. DEFUN (interface_ip_igmp_join,
  2023. interface_ip_igmp_join_cmd,
  2024. "ip igmp join A.B.C.D A.B.C.D",
  2025. IP_STR
  2026. IFACE_IGMP_STR
  2027. "IGMP join multicast group\n"
  2028. "Multicast group address\n"
  2029. "Source address\n")
  2030. {
  2031. struct interface *ifp;
  2032. const char *group_str;
  2033. const char *source_str;
  2034. struct in_addr group_addr;
  2035. struct in_addr source_addr;
  2036. int result;
  2037. ifp = vty->index;
  2038. /* Group address */
  2039. group_str = argv[0];
  2040. result = inet_pton(AF_INET, group_str, &group_addr);
  2041. if (result <= 0) {
  2042. vty_out(vty, "Bad group address %s: errno=%d: %s%s",
  2043. group_str, errno, safe_strerror(errno), VTY_NEWLINE);
  2044. return CMD_WARNING;
  2045. }
  2046. /* Source address */
  2047. source_str = argv[1];
  2048. result = inet_pton(AF_INET, source_str, &source_addr);
  2049. if (result <= 0) {
  2050. vty_out(vty, "Bad source address %s: errno=%d: %s%s",
  2051. source_str, errno, safe_strerror(errno), VTY_NEWLINE);
  2052. return CMD_WARNING;
  2053. }
  2054. result = pim_if_igmp_join_add(ifp, group_addr, source_addr);
  2055. if (result) {
  2056. vty_out(vty, "%% Failure joining IGMP group %s source %s on interface %s: %d%s",
  2057. group_str, source_str, ifp->name, result, VTY_NEWLINE);
  2058. return CMD_WARNING;
  2059. }
  2060. return CMD_SUCCESS;
  2061. }
  2062. DEFUN (interface_no_ip_igmp_join,
  2063. interface_no_ip_igmp_join_cmd,
  2064. "no ip igmp join A.B.C.D A.B.C.D",
  2065. NO_STR
  2066. IP_STR
  2067. IFACE_IGMP_STR
  2068. "IGMP join multicast group\n"
  2069. "Multicast group address\n"
  2070. "Source address\n")
  2071. {
  2072. struct interface *ifp;
  2073. const char *group_str;
  2074. const char *source_str;
  2075. struct in_addr group_addr;
  2076. struct in_addr source_addr;
  2077. int result;
  2078. ifp = vty->index;
  2079. /* Group address */
  2080. group_str = argv[0];
  2081. result = inet_pton(AF_INET, group_str, &group_addr);
  2082. if (result <= 0) {
  2083. vty_out(vty, "Bad group address %s: errno=%d: %s%s",
  2084. group_str, errno, safe_strerror(errno), VTY_NEWLINE);
  2085. return CMD_WARNING;
  2086. }
  2087. /* Source address */
  2088. source_str = argv[1];
  2089. result = inet_pton(AF_INET, source_str, &source_addr);
  2090. if (result <= 0) {
  2091. vty_out(vty, "Bad source address %s: errno=%d: %s%s",
  2092. source_str, errno, safe_strerror(errno), VTY_NEWLINE);
  2093. return CMD_WARNING;
  2094. }
  2095. result = pim_if_igmp_join_del(ifp, group_addr, source_addr);
  2096. if (result) {
  2097. vty_out(vty, "%% Failure leaving IGMP group %s source %s on interface %s: %d%s",
  2098. group_str, source_str, ifp->name, result, VTY_NEWLINE);
  2099. return CMD_WARNING;
  2100. }
  2101. return CMD_SUCCESS;
  2102. }
  2103. /*
  2104. CLI reconfiguration affects the interface level (struct pim_interface).
  2105. This function propagates the reconfiguration to every active socket
  2106. for that interface.
  2107. */
  2108. static void igmp_sock_query_interval_reconfig(struct igmp_sock *igmp)
  2109. {
  2110. struct interface *ifp;
  2111. struct pim_interface *pim_ifp;
  2112. zassert(igmp);
  2113. /* other querier present? */
  2114. if (igmp->t_other_querier_timer)
  2115. return;
  2116. /* this is the querier */
  2117. zassert(igmp->interface);
  2118. zassert(igmp->interface->info);
  2119. ifp = igmp->interface;
  2120. pim_ifp = ifp->info;
  2121. if (PIM_DEBUG_IGMP_TRACE) {
  2122. char ifaddr_str[100];
  2123. pim_inet4_dump("<ifaddr?>", igmp->ifaddr, ifaddr_str, sizeof(ifaddr_str));
  2124. zlog_debug("%s: Querier %s on %s reconfig query_interval=%d",
  2125. __PRETTY_FUNCTION__,
  2126. ifaddr_str,
  2127. ifp->name,
  2128. pim_ifp->igmp_default_query_interval);
  2129. }
  2130. /*
  2131. igmp_startup_mode_on() will reset QQI:
  2132. igmp->querier_query_interval = pim_ifp->igmp_default_query_interval;
  2133. */
  2134. igmp_startup_mode_on(igmp);
  2135. }
  2136. static void igmp_sock_query_reschedule(struct igmp_sock *igmp)
  2137. {
  2138. if (igmp->t_igmp_query_timer) {
  2139. /* other querier present */
  2140. zassert(igmp->t_igmp_query_timer);
  2141. zassert(!igmp->t_other_querier_timer);
  2142. pim_igmp_general_query_off(igmp);
  2143. pim_igmp_general_query_on(igmp);
  2144. zassert(igmp->t_igmp_query_timer);
  2145. zassert(!igmp->t_other_querier_timer);
  2146. }
  2147. else {
  2148. /* this is the querier */
  2149. zassert(!igmp->t_igmp_query_timer);
  2150. zassert(igmp->t_other_querier_timer);
  2151. pim_igmp_other_querier_timer_off(igmp);
  2152. pim_igmp_other_querier_timer_on(igmp);
  2153. zassert(!igmp->t_igmp_query_timer);
  2154. zassert(igmp->t_other_querier_timer);
  2155. }
  2156. }
  2157. static void change_query_interval(struct pim_interface *pim_ifp,
  2158. int query_interval)
  2159. {
  2160. struct listnode *sock_node;
  2161. struct igmp_sock *igmp;
  2162. pim_ifp->igmp_default_query_interval = query_interval;
  2163. for (ALL_LIST_ELEMENTS_RO(pim_ifp->igmp_socket_list, sock_node, igmp)) {
  2164. igmp_sock_query_interval_reconfig(igmp);
  2165. igmp_sock_query_reschedule(igmp);
  2166. }
  2167. }
  2168. static void change_query_max_response_time(struct pim_interface *pim_ifp,
  2169. int query_max_response_time_dsec)
  2170. {
  2171. struct listnode *sock_node;
  2172. struct igmp_sock *igmp;
  2173. pim_ifp->igmp_query_max_response_time_dsec = query_max_response_time_dsec;
  2174. /*
  2175. Below we modify socket/group/source timers in order to quickly
  2176. reflect the change. Otherwise, those timers would eventually catch
  2177. up.
  2178. */
  2179. /* scan all sockets */
  2180. for (ALL_LIST_ELEMENTS_RO(pim_ifp->igmp_socket_list, sock_node, igmp)) {
  2181. struct listnode *grp_node;
  2182. struct igmp_group *grp;
  2183. /* reschedule socket general query */
  2184. igmp_sock_query_reschedule(igmp);
  2185. /* scan socket groups */
  2186. for (ALL_LIST_ELEMENTS_RO(igmp->igmp_group_list, grp_node, grp)) {
  2187. struct listnode *src_node;
  2188. struct igmp_source *src;
  2189. /* reset group timers for groups in EXCLUDE mode */
  2190. if (grp->group_filtermode_isexcl) {
  2191. igmp_group_reset_gmi(grp);
  2192. }
  2193. /* scan group sources */
  2194. for (ALL_LIST_ELEMENTS_RO(grp->group_source_list, src_node, src)) {
  2195. /* reset source timers for sources with running timers */
  2196. if (src->t_source_timer) {
  2197. igmp_source_reset_gmi(igmp, grp, src);
  2198. }
  2199. }
  2200. }
  2201. }
  2202. }
  2203. #define IGMP_QUERY_INTERVAL_MIN (1)
  2204. #define IGMP_QUERY_INTERVAL_MAX (1800)
  2205. DEFUN (interface_ip_igmp_query_interval,
  2206. interface_ip_igmp_query_interval_cmd,
  2207. PIM_CMD_IP_IGMP_QUERY_INTERVAL " <1-1800>",
  2208. IP_STR
  2209. IFACE_IGMP_STR
  2210. IFACE_IGMP_QUERY_INTERVAL_STR
  2211. "Query interval in seconds\n")
  2212. {
  2213. struct interface *ifp;
  2214. struct pim_interface *pim_ifp;
  2215. int query_interval;
  2216. int query_interval_dsec;
  2217. ifp = vty->index;
  2218. pim_ifp = ifp->info;
  2219. if (!pim_ifp) {
  2220. vty_out(vty,
  2221. "IGMP not enabled on interface %s. Please enable IGMP first.%s",
  2222. ifp->name,
  2223. VTY_NEWLINE);
  2224. return CMD_WARNING;
  2225. }
  2226. query_interval = atoi(argv[0]);
  2227. query_interval_dsec = 10 * query_interval;
  2228. /*
  2229. It seems we don't need to check bounds since command.c does it
  2230. already, but we verify them anyway for extra safety.
  2231. */
  2232. if (query_interval < IGMP_QUERY_INTERVAL_MIN) {
  2233. vty_out(vty, "General query interval %d lower than minimum %d%s",
  2234. query_interval,
  2235. IGMP_QUERY_INTERVAL_MIN,
  2236. VTY_NEWLINE);
  2237. return CMD_WARNING;
  2238. }
  2239. if (query_interval > IGMP_QUERY_INTERVAL_MAX) {
  2240. vty_out(vty, "General query interval %d higher than maximum %d%s",
  2241. query_interval,
  2242. IGMP_QUERY_INTERVAL_MAX,
  2243. VTY_NEWLINE);
  2244. return CMD_WARNING;
  2245. }
  2246. if (query_interval_dsec <= pim_ifp->igmp_query_max_response_time_dsec) {
  2247. vty_out(vty,
  2248. "Can't set general query interval %d dsec <= query max response time %d dsec.%s",
  2249. query_interval_dsec, pim_ifp->igmp_query_max_response_time_dsec,
  2250. VTY_NEWLINE);
  2251. return CMD_WARNING;
  2252. }
  2253. change_query_interval(pim_ifp, query_interval);
  2254. return CMD_SUCCESS;
  2255. }
  2256. DEFUN (interface_no_ip_igmp_query_interval,
  2257. interface_no_ip_igmp_query_interval_cmd,
  2258. PIM_CMD_NO " " PIM_CMD_IP_IGMP_QUERY_INTERVAL,
  2259. NO_STR
  2260. IP_STR
  2261. IFACE_IGMP_STR
  2262. IFACE_IGMP_QUERY_INTERVAL_STR)
  2263. {
  2264. struct interface *ifp;
  2265. struct pim_interface *pim_ifp;
  2266. int default_query_interval_dsec;
  2267. ifp = vty->index;
  2268. pim_ifp = ifp->info;
  2269. if (!pim_ifp)
  2270. return CMD_SUCCESS;
  2271. default_query_interval_dsec = IGMP_GENERAL_QUERY_INTERVAL * 10;
  2272. if (default_query_interval_dsec <= pim_ifp->igmp_query_max_response_time_dsec) {
  2273. vty_out(vty,
  2274. "Can't set default general query interval %d dsec <= query max response time %d dsec.%s",
  2275. default_query_interval_dsec, pim_ifp->igmp_query_max_response_time_dsec,
  2276. VTY_NEWLINE);
  2277. return CMD_WARNING;
  2278. }
  2279. change_query_interval(pim_ifp, IGMP_GENERAL_QUERY_INTERVAL);
  2280. return CMD_SUCCESS;
  2281. }
  2282. #define IGMP_QUERY_MAX_RESPONSE_TIME_MIN (1)
  2283. #define IGMP_QUERY_MAX_RESPONSE_TIME_MAX (25)
  2284. DEFUN (interface_ip_igmp_query_max_response_time,
  2285. interface_ip_igmp_query_max_response_time_cmd,
  2286. PIM_CMD_IP_IGMP_QUERY_MAX_RESPONSE_TIME " <1-25>",
  2287. IP_STR
  2288. IFACE_IGMP_STR
  2289. IFACE_IGMP_QUERY_MAX_RESPONSE_TIME_STR
  2290. "Query response value in seconds\n")
  2291. {
  2292. struct interface *ifp;
  2293. struct pim_interface *pim_ifp;
  2294. int query_max_response_time;
  2295. ifp = vty->index;
  2296. pim_ifp = ifp->info;
  2297. if (!pim_ifp) {
  2298. vty_out(vty,
  2299. "IGMP not enabled on interface %s. Please enable IGMP first.%s",
  2300. ifp->name,
  2301. VTY_NEWLINE);
  2302. return CMD_WARNING;
  2303. }
  2304. query_max_response_time = atoi(argv[0]);
  2305. /*
  2306. It seems we don't need to check bounds since command.c does it
  2307. already, but we verify them anyway for extra safety.
  2308. */
  2309. if (query_max_response_time < IGMP_QUERY_MAX_RESPONSE_TIME_MIN) {
  2310. vty_out(vty, "Query max response time %d sec lower than minimum %d sec%s",
  2311. query_max_response_time,
  2312. IGMP_QUERY_MAX_RESPONSE_TIME_MIN,
  2313. VTY_NEWLINE);
  2314. return CMD_WARNING;
  2315. }
  2316. if (query_max_response_time > IGMP_QUERY_MAX_RESPONSE_TIME_MAX) {
  2317. vty_out(vty, "Query max response time %d sec higher than maximum %d sec%s",
  2318. query_max_response_time,
  2319. IGMP_QUERY_MAX_RESPONSE_TIME_MAX,
  2320. VTY_NEWLINE);
  2321. return CMD_WARNING;
  2322. }
  2323. if (query_max_response_time >= pim_ifp->igmp_default_query_interval) {
  2324. vty_out(vty,
  2325. "Can't set query max response time %d sec >= general query interval %d sec%s",
  2326. query_max_response_time, pim_ifp->igmp_default_query_interval,
  2327. VTY_NEWLINE);
  2328. return CMD_WARNING;
  2329. }
  2330. change_query_max_response_time(pim_ifp, 10 * query_max_response_time);
  2331. return CMD_SUCCESS;
  2332. }
  2333. DEFUN (interface_no_ip_igmp_query_max_response_time,
  2334. interface_no_ip_igmp_query_max_response_time_cmd,
  2335. PIM_CMD_NO " " PIM_CMD_IP_IGMP_QUERY_MAX_RESPONSE_TIME,
  2336. NO_STR
  2337. IP_STR
  2338. IFACE_IGMP_STR
  2339. IFACE_IGMP_QUERY_MAX_RESPONSE_TIME_STR)
  2340. {
  2341. struct interface *ifp;
  2342. struct pim_interface *pim_ifp;
  2343. int default_query_interval_dsec;
  2344. ifp = vty->index;
  2345. pim_ifp = ifp->info;
  2346. if (!pim_ifp)
  2347. return CMD_SUCCESS;
  2348. default_query_interval_dsec = 10 * pim_ifp->igmp_default_query_interval;
  2349. if (IGMP_QUERY_MAX_RESPONSE_TIME_DSEC >= default_query_interval_dsec) {
  2350. vty_out(vty,
  2351. "Can't set default query max response time %d dsec >= general query interval %d dsec.%s",
  2352. IGMP_QUERY_MAX_RESPONSE_TIME_DSEC, default_query_interval_dsec,
  2353. VTY_NEWLINE);
  2354. return CMD_WARNING;
  2355. }
  2356. change_query_max_response_time(pim_ifp, IGMP_QUERY_MAX_RESPONSE_TIME_DSEC);
  2357. return CMD_SUCCESS;
  2358. }
  2359. #define IGMP_QUERY_MAX_RESPONSE_TIME_MIN_DSEC (10)
  2360. #define IGMP_QUERY_MAX_RESPONSE_TIME_MAX_DSEC (250)
  2361. DEFUN (interface_ip_igmp_query_max_response_time_dsec,
  2362. interface_ip_igmp_query_max_response_time_dsec_cmd,
  2363. PIM_CMD_IP_IGMP_QUERY_MAX_RESPONSE_TIME_DSEC " <10-250>",
  2364. IP_STR
  2365. IFACE_IGMP_STR
  2366. IFACE_IGMP_QUERY_MAX_RESPONSE_TIME_DSEC_STR
  2367. "Query response value in deciseconds\n")
  2368. {
  2369. struct interface *ifp;
  2370. struct pim_interface *pim_ifp;
  2371. int query_max_response_time_dsec;
  2372. int default_query_interval_dsec;
  2373. ifp = vty->index;
  2374. pim_ifp = ifp->info;
  2375. if (!pim_ifp) {
  2376. vty_out(vty,
  2377. "IGMP not enabled on interface %s. Please enable IGMP first.%s",
  2378. ifp->name,
  2379. VTY_NEWLINE);
  2380. return CMD_WARNING;
  2381. }
  2382. query_max_response_time_dsec = atoi(argv[0]);
  2383. /*
  2384. It seems we don't need to check bounds since command.c does it
  2385. already, but we verify them anyway for extra safety.
  2386. */
  2387. if (query_max_response_time_dsec < IGMP_QUERY_MAX_RESPONSE_TIME_MIN_DSEC) {
  2388. vty_out(vty, "Query max response time %d dsec lower than minimum %d dsec%s",
  2389. query_max_response_time_dsec,
  2390. IGMP_QUERY_MAX_RESPONSE_TIME_MIN_DSEC,
  2391. VTY_NEWLINE);
  2392. return CMD_WARNING;
  2393. }
  2394. if (query_max_response_time_dsec > IGMP_QUERY_MAX_RESPONSE_TIME_MAX_DSEC) {
  2395. vty_out(vty, "Query max response time %d dsec higher than maximum %d dsec%s",
  2396. query_max_response_time_dsec,
  2397. IGMP_QUERY_MAX_RESPONSE_TIME_MAX_DSEC,
  2398. VTY_NEWLINE);
  2399. return CMD_WARNING;
  2400. }
  2401. default_query_interval_dsec = 10 * pim_ifp->igmp_default_query_interval;
  2402. if (query_max_response_time_dsec >= default_query_interval_dsec) {
  2403. vty_out(vty,
  2404. "Can't set query max response time %d dsec >= general query interval %d dsec%s",
  2405. query_max_response_time_dsec, default_query_interval_dsec,
  2406. VTY_NEWLINE);
  2407. return CMD_WARNING;
  2408. }
  2409. change_query_max_response_time(pim_ifp, query_max_response_time_dsec);
  2410. return CMD_SUCCESS;
  2411. }
  2412. DEFUN (interface_no_ip_igmp_query_max_response_time_dsec,
  2413. interface_no_ip_igmp_query_max_response_time_dsec_cmd,
  2414. PIM_CMD_NO " " PIM_CMD_IP_IGMP_QUERY_MAX_RESPONSE_TIME_DSEC,
  2415. NO_STR
  2416. IP_STR
  2417. IFACE_IGMP_STR
  2418. IFACE_IGMP_QUERY_MAX_RESPONSE_TIME_DSEC_STR)
  2419. {
  2420. struct interface *ifp;
  2421. struct pim_interface *pim_ifp;
  2422. int default_query_interval_dsec;
  2423. ifp = vty->index;
  2424. pim_ifp = ifp->info;
  2425. if (!pim_ifp)
  2426. return CMD_SUCCESS;
  2427. default_query_interval_dsec = 10 * pim_ifp->igmp_default_query_interval;
  2428. if (IGMP_QUERY_MAX_RESPONSE_TIME_DSEC >= default_query_interval_dsec) {
  2429. vty_out(vty,
  2430. "Can't set default query max response time %d dsec >= general query interval %d dsec.%s",
  2431. IGMP_QUERY_MAX_RESPONSE_TIME_DSEC, default_query_interval_dsec,
  2432. VTY_NEWLINE);
  2433. return CMD_WARNING;
  2434. }
  2435. change_query_max_response_time(pim_ifp, IGMP_QUERY_MAX_RESPONSE_TIME_DSEC);
  2436. return CMD_SUCCESS;
  2437. }
  2438. DEFUN (interface_ip_pim_ssm,
  2439. interface_ip_pim_ssm_cmd,
  2440. "ip pim ssm",
  2441. IP_STR
  2442. PIM_STR
  2443. IFACE_PIM_STR)
  2444. {
  2445. struct interface *ifp;
  2446. struct pim_interface *pim_ifp;
  2447. ifp = vty->index;
  2448. pim_ifp = ifp->info;
  2449. if (!pim_ifp) {
  2450. pim_ifp = pim_if_new(ifp, 0 /* igmp=false */, 1 /* pim=true */);
  2451. if (!pim_ifp) {
  2452. vty_out(vty, "Could not enable PIM on interface%s", VTY_NEWLINE);
  2453. return CMD_WARNING;
  2454. }
  2455. }
  2456. else {
  2457. PIM_IF_DO_PIM(pim_ifp->options);
  2458. }
  2459. pim_if_addr_add_all(ifp);
  2460. pim_if_membership_refresh(ifp);
  2461. return CMD_SUCCESS;
  2462. }
  2463. DEFUN (interface_no_ip_pim_ssm,
  2464. interface_no_ip_pim_ssm_cmd,
  2465. "no ip pim ssm",
  2466. NO_STR
  2467. IP_STR
  2468. PIM_STR
  2469. IFACE_PIM_STR)
  2470. {
  2471. struct interface *ifp;
  2472. struct pim_interface *pim_ifp;
  2473. ifp = vty->index;
  2474. pim_ifp = ifp->info;
  2475. if (!pim_ifp)
  2476. return CMD_SUCCESS;
  2477. PIM_IF_DONT_PIM(pim_ifp->options);
  2478. pim_if_membership_clear(ifp);
  2479. /*
  2480. pim_if_addr_del_all() removes all sockets from
  2481. pim_ifp->igmp_socket_list.
  2482. */
  2483. pim_if_addr_del_all(ifp);
  2484. /*
  2485. pim_sock_delete() removes all neighbors from
  2486. pim_ifp->pim_neighbor_list.
  2487. */
  2488. pim_sock_delete(ifp, "pim unconfigured on interface");
  2489. if (!PIM_IF_TEST_IGMP(pim_ifp->options)) {
  2490. pim_if_delete(ifp);
  2491. }
  2492. return CMD_SUCCESS;
  2493. }
  2494. DEFUN (debug_igmp,
  2495. debug_igmp_cmd,
  2496. "debug igmp",
  2497. DEBUG_STR
  2498. DEBUG_IGMP_STR)
  2499. {
  2500. PIM_DO_DEBUG_IGMP_EVENTS;
  2501. PIM_DO_DEBUG_IGMP_PACKETS;
  2502. PIM_DO_DEBUG_IGMP_TRACE;
  2503. return CMD_SUCCESS;
  2504. }
  2505. DEFUN (no_debug_igmp,
  2506. no_debug_igmp_cmd,
  2507. "no debug igmp",
  2508. NO_STR
  2509. DEBUG_STR
  2510. DEBUG_IGMP_STR)
  2511. {
  2512. PIM_DONT_DEBUG_IGMP_EVENTS;
  2513. PIM_DONT_DEBUG_IGMP_PACKETS;
  2514. PIM_DONT_DEBUG_IGMP_TRACE;
  2515. return CMD_SUCCESS;
  2516. }
  2517. ALIAS (no_debug_igmp,
  2518. undebug_igmp_cmd,
  2519. "undebug igmp",
  2520. UNDEBUG_STR
  2521. DEBUG_IGMP_STR)
  2522. DEFUN (debug_igmp_events,
  2523. debug_igmp_events_cmd,
  2524. "debug igmp events",
  2525. DEBUG_STR
  2526. DEBUG_IGMP_STR
  2527. DEBUG_IGMP_EVENTS_STR)
  2528. {
  2529. PIM_DO_DEBUG_IGMP_EVENTS;
  2530. return CMD_SUCCESS;
  2531. }
  2532. DEFUN (no_debug_igmp_events,
  2533. no_debug_igmp_events_cmd,
  2534. "no debug igmp events",
  2535. NO_STR
  2536. DEBUG_STR
  2537. DEBUG_IGMP_STR
  2538. DEBUG_IGMP_EVENTS_STR)
  2539. {
  2540. PIM_DONT_DEBUG_IGMP_EVENTS;
  2541. return CMD_SUCCESS;
  2542. }
  2543. ALIAS (no_debug_igmp_events,
  2544. undebug_igmp_events_cmd,
  2545. "undebug igmp events",
  2546. UNDEBUG_STR
  2547. DEBUG_IGMP_STR
  2548. DEBUG_IGMP_EVENTS_STR)
  2549. DEFUN (debug_igmp_packets,
  2550. debug_igmp_packets_cmd,
  2551. "debug igmp packets",
  2552. DEBUG_STR
  2553. DEBUG_IGMP_STR
  2554. DEBUG_IGMP_PACKETS_STR)
  2555. {
  2556. PIM_DO_DEBUG_IGMP_PACKETS;
  2557. return CMD_SUCCESS;
  2558. }
  2559. DEFUN (no_debug_igmp_packets,
  2560. no_debug_igmp_packets_cmd,
  2561. "no debug igmp packets",
  2562. NO_STR
  2563. DEBUG_STR
  2564. DEBUG_IGMP_STR
  2565. DEBUG_IGMP_PACKETS_STR)
  2566. {
  2567. PIM_DONT_DEBUG_IGMP_PACKETS;
  2568. return CMD_SUCCESS;
  2569. }
  2570. ALIAS (no_debug_igmp_packets,
  2571. undebug_igmp_packets_cmd,
  2572. "undebug igmp packets",
  2573. UNDEBUG_STR
  2574. DEBUG_IGMP_STR
  2575. DEBUG_IGMP_PACKETS_STR)
  2576. DEFUN (debug_igmp_trace,
  2577. debug_igmp_trace_cmd,
  2578. "debug igmp trace",
  2579. DEBUG_STR
  2580. DEBUG_IGMP_STR
  2581. DEBUG_IGMP_TRACE_STR)
  2582. {
  2583. PIM_DO_DEBUG_IGMP_TRACE;
  2584. return CMD_SUCCESS;
  2585. }
  2586. DEFUN (no_debug_igmp_trace,
  2587. no_debug_igmp_trace_cmd,
  2588. "no debug igmp trace",
  2589. NO_STR
  2590. DEBUG_STR
  2591. DEBUG_IGMP_STR
  2592. DEBUG_IGMP_TRACE_STR)
  2593. {
  2594. PIM_DONT_DEBUG_IGMP_TRACE;
  2595. return CMD_SUCCESS;
  2596. }
  2597. ALIAS (no_debug_igmp_trace,
  2598. undebug_igmp_trace_cmd,
  2599. "undebug igmp trace",
  2600. UNDEBUG_STR
  2601. DEBUG_IGMP_STR
  2602. DEBUG_IGMP_TRACE_STR)
  2603. DEFUN (debug_mroute,
  2604. debug_mroute_cmd,
  2605. "debug mroute",
  2606. DEBUG_STR
  2607. DEBUG_MROUTE_STR)
  2608. {
  2609. PIM_DO_DEBUG_MROUTE;
  2610. return CMD_SUCCESS;
  2611. }
  2612. DEFUN (no_debug_mroute,
  2613. no_debug_mroute_cmd,
  2614. "no debug mroute",
  2615. NO_STR
  2616. DEBUG_STR
  2617. DEBUG_MROUTE_STR)
  2618. {
  2619. PIM_DONT_DEBUG_MROUTE;
  2620. return CMD_SUCCESS;
  2621. }
  2622. ALIAS (no_debug_mroute,
  2623. undebug_mroute_cmd,
  2624. "undebug mroute",
  2625. UNDEBUG_STR
  2626. DEBUG_MROUTE_STR)
  2627. DEFUN (debug_pim,
  2628. debug_pim_cmd,
  2629. "debug pim",
  2630. DEBUG_STR
  2631. DEBUG_PIM_STR)
  2632. {
  2633. PIM_DO_DEBUG_PIM_EVENTS;
  2634. PIM_DO_DEBUG_PIM_PACKETS;
  2635. PIM_DO_DEBUG_PIM_TRACE;
  2636. return CMD_SUCCESS;
  2637. }
  2638. DEFUN (no_debug_pim,
  2639. no_debug_pim_cmd,
  2640. "no debug pim",
  2641. NO_STR
  2642. DEBUG_STR
  2643. DEBUG_PIM_STR)
  2644. {
  2645. PIM_DONT_DEBUG_PIM_EVENTS;
  2646. PIM_DONT_DEBUG_PIM_PACKETS;
  2647. PIM_DONT_DEBUG_PIM_TRACE;
  2648. PIM_DONT_DEBUG_PIM_PACKETDUMP_SEND;
  2649. PIM_DONT_DEBUG_PIM_PACKETDUMP_RECV;
  2650. return CMD_SUCCESS;
  2651. }
  2652. ALIAS (no_debug_pim,
  2653. undebug_pim_cmd,
  2654. "undebug pim",
  2655. UNDEBUG_STR
  2656. DEBUG_PIM_STR)
  2657. DEFUN (debug_pim_events,
  2658. debug_pim_events_cmd,
  2659. "debug pim events",
  2660. DEBUG_STR
  2661. DEBUG_PIM_STR
  2662. DEBUG_PIM_EVENTS_STR)
  2663. {
  2664. PIM_DO_DEBUG_PIM_EVENTS;
  2665. return CMD_SUCCESS;
  2666. }
  2667. DEFUN (no_debug_pim_events,
  2668. no_debug_pim_events_cmd,
  2669. "no debug pim events",
  2670. NO_STR
  2671. DEBUG_STR
  2672. DEBUG_PIM_STR
  2673. DEBUG_PIM_EVENTS_STR)
  2674. {
  2675. PIM_DONT_DEBUG_PIM_EVENTS;
  2676. return CMD_SUCCESS;
  2677. }
  2678. ALIAS (no_debug_pim_events,
  2679. undebug_pim_events_cmd,
  2680. "undebug pim events",
  2681. UNDEBUG_STR
  2682. DEBUG_PIM_STR
  2683. DEBUG_PIM_EVENTS_STR)
  2684. DEFUN (debug_pim_packets,
  2685. debug_pim_packets_cmd,
  2686. "debug pim packets",
  2687. DEBUG_STR
  2688. DEBUG_PIM_STR
  2689. DEBUG_PIM_PACKETS_STR)
  2690. {
  2691. PIM_DO_DEBUG_PIM_PACKETS;
  2692. vty_out (vty, "PIM Packet debugging is on %s", VTY_NEWLINE);
  2693. return CMD_SUCCESS;
  2694. }
  2695. DEFUN (debug_pim_packets_filter,
  2696. debug_pim_packets_filter_cmd,
  2697. "debug pim packets (hello|joins)",
  2698. DEBUG_STR
  2699. DEBUG_PIM_STR
  2700. DEBUG_PIM_PACKETS_STR
  2701. DEBUG_PIM_HELLO_PACKETS_STR
  2702. DEBUG_PIM_J_P_PACKETS_STR)
  2703. {
  2704. if (strncmp(argv[0],"h",1) == 0)
  2705. {
  2706. PIM_DO_DEBUG_PIM_HELLO;
  2707. vty_out (vty, "PIM Hello debugging is on %s", VTY_NEWLINE);
  2708. }
  2709. else if (strncmp(argv[0],"j",1) == 0)
  2710. {
  2711. PIM_DO_DEBUG_PIM_J_P;
  2712. vty_out (vty, "PIM Join/Prune debugging is on %s", VTY_NEWLINE);
  2713. }
  2714. return CMD_SUCCESS;
  2715. }
  2716. DEFUN (no_debug_pim_packets,
  2717. no_debug_pim_packets_cmd,
  2718. "no debug pim packets",
  2719. NO_STR
  2720. DEBUG_STR
  2721. DEBUG_PIM_STR
  2722. DEBUG_PIM_PACKETS_STR
  2723. DEBUG_PIM_HELLO_PACKETS_STR
  2724. DEBUG_PIM_J_P_PACKETS_STR)
  2725. {
  2726. PIM_DONT_DEBUG_PIM_PACKETS;
  2727. vty_out (vty, "PIM Packet debugging is off %s", VTY_NEWLINE);
  2728. return CMD_SUCCESS;
  2729. }
  2730. DEFUN (no_debug_pim_packets_filter,
  2731. no_debug_pim_packets_filter_cmd,
  2732. "no debug pim packets (hello|joins)",
  2733. NO_STR
  2734. DEBUG_STR
  2735. DEBUG_PIM_STR
  2736. DEBUG_PIM_PACKETS_STR
  2737. DEBUG_PIM_HELLO_PACKETS_STR
  2738. DEBUG_PIM_J_P_PACKETS_STR)
  2739. {
  2740. if (strncmp(argv[0],"h",1) == 0)
  2741. {
  2742. PIM_DONT_DEBUG_PIM_HELLO;
  2743. vty_out (vty, "PIM Hello debugging is off %s", VTY_NEWLINE);
  2744. }
  2745. else if (strncmp(argv[0],"j",1) == 0)
  2746. {
  2747. PIM_DONT_DEBUG_PIM_J_P;
  2748. vty_out (vty, "PIM Join/Prune debugging is off %s", VTY_NEWLINE);
  2749. }
  2750. return CMD_SUCCESS;
  2751. }
  2752. ALIAS (no_debug_pim_packets,
  2753. undebug_pim_packets_cmd,
  2754. "undebug pim packets",
  2755. UNDEBUG_STR
  2756. DEBUG_PIM_STR
  2757. DEBUG_PIM_PACKETS_STR)
  2758. DEFUN (debug_pim_packetdump_send,
  2759. debug_pim_packetdump_send_cmd,
  2760. "debug pim packet-dump send",
  2761. DEBUG_STR
  2762. DEBUG_PIM_STR
  2763. DEBUG_PIM_PACKETDUMP_STR
  2764. DEBUG_PIM_PACKETDUMP_SEND_STR)
  2765. {
  2766. PIM_DO_DEBUG_PIM_PACKETDUMP_SEND;
  2767. return CMD_SUCCESS;
  2768. }
  2769. DEFUN (no_debug_pim_packetdump_send,
  2770. no_debug_pim_packetdump_send_cmd,
  2771. "no debug pim packet-dump send",
  2772. NO_STR
  2773. DEBUG_STR
  2774. DEBUG_PIM_STR
  2775. DEBUG_PIM_PACKETDUMP_STR
  2776. DEBUG_PIM_PACKETDUMP_SEND_STR)
  2777. {
  2778. PIM_DONT_DEBUG_PIM_PACKETDUMP_SEND;
  2779. return CMD_SUCCESS;
  2780. }
  2781. ALIAS (no_debug_pim_packetdump_send,
  2782. undebug_pim_packetdump_send_cmd,
  2783. "undebug pim packet-dump send",
  2784. UNDEBUG_STR
  2785. DEBUG_PIM_STR
  2786. DEBUG_PIM_PACKETDUMP_STR
  2787. DEBUG_PIM_PACKETDUMP_SEND_STR)
  2788. DEFUN (debug_pim_packetdump_recv,
  2789. debug_pim_packetdump_recv_cmd,
  2790. "debug pim packet-dump receive",
  2791. DEBUG_STR
  2792. DEBUG_PIM_STR
  2793. DEBUG_PIM_PACKETDUMP_STR
  2794. DEBUG_PIM_PACKETDUMP_RECV_STR)
  2795. {
  2796. PIM_DO_DEBUG_PIM_PACKETDUMP_RECV;
  2797. return CMD_SUCCESS;
  2798. }
  2799. DEFUN (no_debug_pim_packetdump_recv,
  2800. no_debug_pim_packetdump_recv_cmd,
  2801. "no debug pim packet-dump receive",
  2802. NO_STR
  2803. DEBUG_STR
  2804. DEBUG_PIM_STR
  2805. DEBUG_PIM_PACKETDUMP_STR
  2806. DEBUG_PIM_PACKETDUMP_RECV_STR)
  2807. {
  2808. PIM_DONT_DEBUG_PIM_PACKETDUMP_RECV;
  2809. return CMD_SUCCESS;
  2810. }
  2811. ALIAS (no_debug_pim_packetdump_recv,
  2812. undebug_pim_packetdump_recv_cmd,
  2813. "undebug pim packet-dump receive",
  2814. UNDEBUG_STR
  2815. DEBUG_PIM_STR
  2816. DEBUG_PIM_PACKETDUMP_STR
  2817. DEBUG_PIM_PACKETDUMP_RECV_STR)
  2818. DEFUN (debug_pim_trace,
  2819. debug_pim_trace_cmd,
  2820. "debug pim trace",
  2821. DEBUG_STR
  2822. DEBUG_PIM_STR
  2823. DEBUG_PIM_TRACE_STR)
  2824. {
  2825. PIM_DO_DEBUG_PIM_TRACE;
  2826. return CMD_SUCCESS;
  2827. }
  2828. DEFUN (no_debug_pim_trace,
  2829. no_debug_pim_trace_cmd,
  2830. "no debug pim trace",
  2831. NO_STR
  2832. DEBUG_STR
  2833. DEBUG_PIM_STR
  2834. DEBUG_PIM_TRACE_STR)
  2835. {
  2836. PIM_DONT_DEBUG_PIM_TRACE;
  2837. return CMD_SUCCESS;
  2838. }
  2839. ALIAS (no_debug_pim_trace,
  2840. undebug_pim_trace_cmd,
  2841. "undebug pim trace",
  2842. UNDEBUG_STR
  2843. DEBUG_PIM_STR
  2844. DEBUG_PIM_TRACE_STR)
  2845. DEFUN (debug_ssmpingd,
  2846. debug_ssmpingd_cmd,
  2847. "debug ssmpingd",
  2848. DEBUG_STR
  2849. DEBUG_PIM_STR
  2850. DEBUG_SSMPINGD_STR)
  2851. {
  2852. PIM_DO_DEBUG_SSMPINGD;
  2853. return CMD_SUCCESS;
  2854. }
  2855. DEFUN (no_debug_ssmpingd,
  2856. no_debug_ssmpingd_cmd,
  2857. "no debug ssmpingd",
  2858. NO_STR
  2859. DEBUG_STR
  2860. DEBUG_PIM_STR
  2861. DEBUG_SSMPINGD_STR)
  2862. {
  2863. PIM_DONT_DEBUG_SSMPINGD;
  2864. return CMD_SUCCESS;
  2865. }
  2866. ALIAS (no_debug_ssmpingd,
  2867. undebug_ssmpingd_cmd,
  2868. "undebug ssmpingd",
  2869. UNDEBUG_STR
  2870. DEBUG_PIM_STR
  2871. DEBUG_SSMPINGD_STR)
  2872. DEFUN (debug_pim_zebra,
  2873. debug_pim_zebra_cmd,
  2874. "debug pim zebra",
  2875. DEBUG_STR
  2876. DEBUG_PIM_STR
  2877. DEBUG_PIM_ZEBRA_STR)
  2878. {
  2879. PIM_DO_DEBUG_ZEBRA;
  2880. return CMD_SUCCESS;
  2881. }
  2882. DEFUN (no_debug_pim_zebra,
  2883. no_debug_pim_zebra_cmd,
  2884. "no debug pim zebra",
  2885. NO_STR
  2886. DEBUG_STR
  2887. DEBUG_PIM_STR
  2888. DEBUG_PIM_ZEBRA_STR)
  2889. {
  2890. PIM_DONT_DEBUG_ZEBRA;
  2891. return CMD_SUCCESS;
  2892. }
  2893. ALIAS (no_debug_pim_zebra,
  2894. undebug_pim_zebra_cmd,
  2895. "undebug pim zebra",
  2896. UNDEBUG_STR
  2897. DEBUG_PIM_STR
  2898. DEBUG_PIM_ZEBRA_STR)
  2899. DEFUN (show_debugging,
  2900. show_debugging_cmd,
  2901. "show debugging",
  2902. SHOW_STR
  2903. "State of each debugging option\n")
  2904. {
  2905. pim_debug_config_write(vty);
  2906. return CMD_SUCCESS;
  2907. }
  2908. static struct igmp_sock *find_igmp_sock_by_fd(int fd)
  2909. {
  2910. struct listnode *ifnode;
  2911. struct interface *ifp;
  2912. /* scan all interfaces */
  2913. for (ALL_LIST_ELEMENTS_RO(iflist, ifnode, ifp)) {
  2914. struct pim_interface *pim_ifp;
  2915. struct igmp_sock *igmp;
  2916. if (!ifp->info)
  2917. continue;
  2918. pim_ifp = ifp->info;
  2919. /* lookup igmp socket under current interface */
  2920. igmp = igmp_sock_lookup_by_fd(pim_ifp->igmp_socket_list, fd);
  2921. if (igmp)
  2922. return igmp;
  2923. }
  2924. return 0;
  2925. }
  2926. DEFUN (test_igmp_receive_report,
  2927. test_igmp_receive_report_cmd,
  2928. "test igmp receive report <0-65535> A.B.C.D <1-6> .LINE",
  2929. "Test\n"
  2930. "Test IGMP protocol\n"
  2931. "Test IGMP message\n"
  2932. "Test IGMP report\n"
  2933. "Socket\n"
  2934. "IGMP group address\n"
  2935. "Record type\n"
  2936. "Sources\n")
  2937. {
  2938. char buf[1000];
  2939. char *igmp_msg;
  2940. struct ip *ip_hdr;
  2941. size_t ip_hlen; /* ip header length in bytes */
  2942. int ip_msg_len;
  2943. int igmp_msg_len;
  2944. const char *socket;
  2945. int socket_fd;
  2946. const char *grp_str;
  2947. struct in_addr grp_addr;
  2948. const char *record_type_str;
  2949. int record_type;
  2950. const char *src_str;
  2951. int result;
  2952. struct igmp_sock *igmp;
  2953. char *group_record;
  2954. int num_sources;
  2955. struct in_addr *sources;
  2956. struct in_addr *src_addr;
  2957. int argi;
  2958. socket = argv[0];
  2959. socket_fd = atoi(socket);
  2960. igmp = find_igmp_sock_by_fd(socket_fd);
  2961. if (!igmp) {
  2962. vty_out(vty, "Could not find IGMP socket %s: fd=%d%s",
  2963. socket, socket_fd, VTY_NEWLINE);
  2964. return CMD_WARNING;
  2965. }
  2966. grp_str = argv[1];
  2967. result = inet_pton(AF_INET, grp_str, &grp_addr);
  2968. if (result <= 0) {
  2969. vty_out(vty, "Bad group address %s: errno=%d: %s%s",
  2970. grp_str, errno, safe_strerror(errno), VTY_NEWLINE);
  2971. return CMD_WARNING;
  2972. }
  2973. record_type_str = argv[2];
  2974. record_type = atoi(record_type_str);
  2975. /*
  2976. Tweak IP header
  2977. */
  2978. ip_hdr = (struct ip *) buf;
  2979. ip_hdr->ip_p = PIM_IP_PROTO_IGMP;
  2980. ip_hlen = PIM_IP_HEADER_MIN_LEN; /* ip header length in bytes */
  2981. ip_hdr->ip_hl = ip_hlen >> 2; /* ip header length in 4-byte words */
  2982. ip_hdr->ip_src = igmp->ifaddr;
  2983. ip_hdr->ip_dst = igmp->ifaddr;
  2984. /*
  2985. Build IGMP v3 report message
  2986. */
  2987. igmp_msg = buf + ip_hlen;
  2988. group_record = igmp_msg + IGMP_V3_REPORT_GROUPPRECORD_OFFSET;
  2989. *igmp_msg = PIM_IGMP_V3_MEMBERSHIP_REPORT; /* type */
  2990. *(uint16_t *) (igmp_msg + IGMP_V3_CHECKSUM_OFFSET) = 0; /* for computing checksum */
  2991. *(uint16_t *) (igmp_msg + IGMP_V3_REPORT_NUMGROUPS_OFFSET) = htons(1); /* one group record */
  2992. *(uint8_t *) (group_record + IGMP_V3_GROUP_RECORD_TYPE_OFFSET) = record_type;
  2993. memcpy(group_record + IGMP_V3_GROUP_RECORD_GROUP_OFFSET, &grp_addr, sizeof(struct in_addr));
  2994. /* Scan LINE sources */
  2995. sources = (struct in_addr *) (group_record + IGMP_V3_GROUP_RECORD_SOURCE_OFFSET);
  2996. src_addr = sources;
  2997. for (argi = 3; argi < argc; ++argi,++src_addr) {
  2998. src_str = argv[argi];
  2999. result = inet_pton(AF_INET, src_str, src_addr);
  3000. if (result <= 0) {
  3001. vty_out(vty, "Bad source address %s: errno=%d: %s%s",
  3002. src_str, errno, safe_strerror(errno), VTY_NEWLINE);
  3003. return CMD_WARNING;
  3004. }
  3005. }
  3006. num_sources = src_addr - sources;
  3007. *(uint16_t *)(group_record + IGMP_V3_GROUP_RECORD_NUMSOURCES_OFFSET) = htons(num_sources);
  3008. igmp_msg_len = IGMP_V3_MSG_MIN_SIZE + (num_sources << 4); /* v3 report for one single group record */
  3009. /* compute checksum */
  3010. *(uint16_t *)(igmp_msg + IGMP_V3_CHECKSUM_OFFSET) = in_cksum(igmp_msg, igmp_msg_len);
  3011. /* "receive" message */
  3012. ip_msg_len = ip_hlen + igmp_msg_len;
  3013. result = pim_igmp_packet(igmp, buf, ip_msg_len);
  3014. if (result) {
  3015. vty_out(vty, "pim_igmp_packet(len=%d) returned: %d%s",
  3016. ip_msg_len, result, VTY_NEWLINE);
  3017. return CMD_WARNING;
  3018. }
  3019. return CMD_SUCCESS;
  3020. }
  3021. static int hexval(uint8_t ch)
  3022. {
  3023. return isdigit(ch) ? (ch - '0') : (10 + tolower(ch) - 'a');
  3024. }
  3025. DEFUN (test_pim_receive_dump,
  3026. test_pim_receive_dump_cmd,
  3027. "test pim receive dump INTERFACE A.B.C.D .LINE",
  3028. "Test\n"
  3029. "Test PIM protocol\n"
  3030. "Test PIM message reception\n"
  3031. "Test PIM packet dump reception from neighbor\n"
  3032. "Interface\n"
  3033. "Neighbor address\n"
  3034. "Packet dump\n")
  3035. {
  3036. uint8_t buf[1000];
  3037. uint8_t *pim_msg;
  3038. struct ip *ip_hdr;
  3039. size_t ip_hlen; /* ip header length in bytes */
  3040. int ip_msg_len;
  3041. int pim_msg_size;
  3042. const char *neigh_str;
  3043. struct in_addr neigh_addr;
  3044. const char *ifname;
  3045. struct interface *ifp;
  3046. int argi;
  3047. int result;
  3048. /* Find interface */
  3049. ifname = argv[0];
  3050. ifp = if_lookup_by_name(ifname);
  3051. if (!ifp) {
  3052. vty_out(vty, "No such interface name %s%s",
  3053. ifname, VTY_NEWLINE);
  3054. return CMD_WARNING;
  3055. }
  3056. /* Neighbor address */
  3057. neigh_str = argv[1];
  3058. result = inet_pton(AF_INET, neigh_str, &neigh_addr);
  3059. if (result <= 0) {
  3060. vty_out(vty, "Bad neighbor address %s: errno=%d: %s%s",
  3061. neigh_str, errno, safe_strerror(errno), VTY_NEWLINE);
  3062. return CMD_WARNING;
  3063. }
  3064. /*
  3065. Tweak IP header
  3066. */
  3067. ip_hdr = (struct ip *) buf;
  3068. ip_hdr->ip_p = PIM_IP_PROTO_PIM;
  3069. ip_hlen = PIM_IP_HEADER_MIN_LEN; /* ip header length in bytes */
  3070. ip_hdr->ip_hl = ip_hlen >> 2; /* ip header length in 4-byte words */
  3071. ip_hdr->ip_src = neigh_addr;
  3072. ip_hdr->ip_dst = qpim_all_pim_routers_addr;
  3073. /*
  3074. Build PIM hello message
  3075. */
  3076. pim_msg = buf + ip_hlen;
  3077. pim_msg_size = 0;
  3078. /* Scan LINE dump into buffer */
  3079. for (argi = 2; argi < argc; ++argi) {
  3080. const char *str = argv[argi];
  3081. int str_len = strlen(str);
  3082. int str_last = str_len - 1;
  3083. int i;
  3084. if (str_len % 2) {
  3085. vty_out(vty, "%% Uneven hex array arg %d=%s%s",
  3086. argi, str, VTY_NEWLINE);
  3087. return CMD_WARNING;
  3088. }
  3089. for (i = 0; i < str_last; i += 2) {
  3090. uint8_t octet;
  3091. int left;
  3092. uint8_t h1 = str[i];
  3093. uint8_t h2 = str[i + 1];
  3094. if (!isxdigit(h1) || !isxdigit(h2)) {
  3095. vty_out(vty, "%% Non-hex octet %c%c at hex array arg %d=%s%s",
  3096. h1, h2, argi, str, VTY_NEWLINE);
  3097. return CMD_WARNING;
  3098. }
  3099. octet = (hexval(h1) << 4) + hexval(h2);
  3100. left = sizeof(buf) - ip_hlen - pim_msg_size;
  3101. if (left < 1) {
  3102. vty_out(vty, "%% Overflow buf_size=%zu buf_left=%d at hex array arg %d=%s octet %02x%s",
  3103. sizeof(buf), left, argi, str, octet, VTY_NEWLINE);
  3104. return CMD_WARNING;
  3105. }
  3106. pim_msg[pim_msg_size++] = octet;
  3107. }
  3108. }
  3109. ip_msg_len = ip_hlen + pim_msg_size;
  3110. vty_out(vty, "Receiving: buf_size=%zu ip_msg_size=%d pim_msg_size=%d%s",
  3111. sizeof(buf), ip_msg_len, pim_msg_size, VTY_NEWLINE);
  3112. /* "receive" message */
  3113. result = pim_pim_packet(ifp, buf, ip_msg_len);
  3114. if (result) {
  3115. vty_out(vty, "%% pim_pim_packet(len=%d) returned failure: %d%s",
  3116. ip_msg_len, result, VTY_NEWLINE);
  3117. return CMD_WARNING;
  3118. }
  3119. return CMD_SUCCESS;
  3120. }
  3121. DEFUN (test_pim_receive_hello,
  3122. test_pim_receive_hello_cmd,
  3123. "test pim receive hello INTERFACE A.B.C.D <0-65535> <0-65535> <0-65535> <0-32767> <0-65535> <0-1>[LINE]",
  3124. "Test\n"
  3125. "Test PIM protocol\n"
  3126. "Test PIM message reception\n"
  3127. "Test PIM hello reception from neighbor\n"
  3128. "Interface\n"
  3129. "Neighbor address\n"
  3130. "Neighbor holdtime\n"
  3131. "Neighbor DR priority\n"
  3132. "Neighbor generation ID\n"
  3133. "Neighbor propagation delay (msec)\n"
  3134. "Neighbor override interval (msec)\n"
  3135. "Neighbor LAN prune delay T-bit\n"
  3136. "Neighbor secondary addresses\n")
  3137. {
  3138. uint8_t buf[1000];
  3139. uint8_t *pim_msg;
  3140. struct ip *ip_hdr;
  3141. size_t ip_hlen; /* ip header length in bytes */
  3142. int ip_msg_len;
  3143. int pim_tlv_size;
  3144. int pim_msg_size;
  3145. const char *neigh_str;
  3146. struct in_addr neigh_addr;
  3147. const char *ifname;
  3148. struct interface *ifp;
  3149. uint16_t neigh_holdtime;
  3150. uint16_t neigh_propagation_delay;
  3151. uint16_t neigh_override_interval;
  3152. int neigh_can_disable_join_suppression;
  3153. uint32_t neigh_dr_priority;
  3154. uint32_t neigh_generation_id;
  3155. int argi;
  3156. int result;
  3157. /* Find interface */
  3158. ifname = argv[0];
  3159. ifp = if_lookup_by_name(ifname);
  3160. if (!ifp) {
  3161. vty_out(vty, "No such interface name %s%s",
  3162. ifname, VTY_NEWLINE);
  3163. return CMD_WARNING;
  3164. }
  3165. /* Neighbor address */
  3166. neigh_str = argv[1];
  3167. result = inet_pton(AF_INET, neigh_str, &neigh_addr);
  3168. if (result <= 0) {
  3169. vty_out(vty, "Bad neighbor address %s: errno=%d: %s%s",
  3170. neigh_str, errno, safe_strerror(errno), VTY_NEWLINE);
  3171. return CMD_WARNING;
  3172. }
  3173. neigh_holdtime = atoi(argv[2]);
  3174. neigh_dr_priority = atoi(argv[3]);
  3175. neigh_generation_id = atoi(argv[4]);
  3176. neigh_propagation_delay = atoi(argv[5]);
  3177. neigh_override_interval = atoi(argv[6]);
  3178. neigh_can_disable_join_suppression = atoi(argv[7]);
  3179. /*
  3180. Tweak IP header
  3181. */
  3182. ip_hdr = (struct ip *) buf;
  3183. ip_hdr->ip_p = PIM_IP_PROTO_PIM;
  3184. ip_hlen = PIM_IP_HEADER_MIN_LEN; /* ip header length in bytes */
  3185. ip_hdr->ip_hl = ip_hlen >> 2; /* ip header length in 4-byte words */
  3186. ip_hdr->ip_src = neigh_addr;
  3187. ip_hdr->ip_dst = qpim_all_pim_routers_addr;
  3188. /*
  3189. Build PIM hello message
  3190. */
  3191. pim_msg = buf + ip_hlen;
  3192. /* Scan LINE addresses */
  3193. for (argi = 8; argi < argc; ++argi) {
  3194. const char *sec_str = argv[argi];
  3195. struct in_addr sec_addr;
  3196. result = inet_pton(AF_INET, sec_str, &sec_addr);
  3197. if (result <= 0) {
  3198. vty_out(vty, "Bad neighbor secondary address %s: errno=%d: %s%s",
  3199. sec_str, errno, safe_strerror(errno), VTY_NEWLINE);
  3200. return CMD_WARNING;
  3201. }
  3202. vty_out(vty,
  3203. "FIXME WRITEME consider neighbor secondary address %s%s",
  3204. sec_str, VTY_NEWLINE);
  3205. }
  3206. pim_tlv_size = pim_hello_build_tlv(ifp->name,
  3207. pim_msg + PIM_PIM_MIN_LEN,
  3208. sizeof(buf) - ip_hlen - PIM_PIM_MIN_LEN,
  3209. neigh_holdtime,
  3210. neigh_dr_priority,
  3211. neigh_generation_id,
  3212. neigh_propagation_delay,
  3213. neigh_override_interval,
  3214. neigh_can_disable_join_suppression,
  3215. 0 /* FIXME secondary address list */);
  3216. if (pim_tlv_size < 0) {
  3217. vty_out(vty, "pim_hello_build_tlv() returned failure: %d%s",
  3218. pim_tlv_size, VTY_NEWLINE);
  3219. return CMD_WARNING;
  3220. }
  3221. pim_msg_size = pim_tlv_size + PIM_PIM_MIN_LEN;
  3222. pim_msg_build_header(pim_msg, pim_msg_size,
  3223. PIM_MSG_TYPE_HELLO);
  3224. /* "receive" message */
  3225. ip_msg_len = ip_hlen + pim_msg_size;
  3226. result = pim_pim_packet(ifp, buf, ip_msg_len);
  3227. if (result) {
  3228. vty_out(vty, "pim_pim_packet(len=%d) returned failure: %d%s",
  3229. ip_msg_len, result, VTY_NEWLINE);
  3230. return CMD_WARNING;
  3231. }
  3232. return CMD_SUCCESS;
  3233. }
  3234. DEFUN (test_pim_receive_assert,
  3235. test_pim_receive_assert_cmd,
  3236. "test pim receive assert INTERFACE A.B.C.D A.B.C.D A.B.C.D <0-65535> <0-65535> <0-1>",
  3237. "Test\n"
  3238. "Test PIM protocol\n"
  3239. "Test PIM message reception\n"
  3240. "Test reception of PIM assert\n"
  3241. "Interface\n"
  3242. "Neighbor address\n"
  3243. "Assert multicast group address\n"
  3244. "Assert unicast source address\n"
  3245. "Assert metric preference\n"
  3246. "Assert route metric\n"
  3247. "Assert RPT bit flag\n")
  3248. {
  3249. uint8_t buf[1000];
  3250. uint8_t *buf_pastend = buf + sizeof(buf);
  3251. uint8_t *pim_msg;
  3252. struct ip *ip_hdr;
  3253. size_t ip_hlen; /* ip header length in bytes */
  3254. int ip_msg_len;
  3255. int pim_msg_size;
  3256. const char *neigh_str;
  3257. struct in_addr neigh_addr;
  3258. const char *group_str;
  3259. struct in_addr group_addr;
  3260. const char *source_str;
  3261. struct in_addr source_addr;
  3262. const char *ifname;
  3263. struct interface *ifp;
  3264. uint32_t assert_metric_preference;
  3265. uint32_t assert_route_metric;
  3266. uint32_t assert_rpt_bit_flag;
  3267. int remain;
  3268. int result;
  3269. /* Find interface */
  3270. ifname = argv[0];
  3271. ifp = if_lookup_by_name(ifname);
  3272. if (!ifp) {
  3273. vty_out(vty, "No such interface name %s%s",
  3274. ifname, VTY_NEWLINE);
  3275. return CMD_WARNING;
  3276. }
  3277. /* Neighbor address */
  3278. neigh_str = argv[1];
  3279. result = inet_pton(AF_INET, neigh_str, &neigh_addr);
  3280. if (result <= 0) {
  3281. vty_out(vty, "Bad neighbor address %s: errno=%d: %s%s",
  3282. neigh_str, errno, safe_strerror(errno), VTY_NEWLINE);
  3283. return CMD_WARNING;
  3284. }
  3285. /* Group address */
  3286. group_str = argv[2];
  3287. result = inet_pton(AF_INET, group_str, &group_addr);
  3288. if (result <= 0) {
  3289. vty_out(vty, "Bad group address %s: errno=%d: %s%s",
  3290. group_str, errno, safe_strerror(errno), VTY_NEWLINE);
  3291. return CMD_WARNING;
  3292. }
  3293. /* Source address */
  3294. source_str = argv[3];
  3295. result = inet_pton(AF_INET, source_str, &source_addr);
  3296. if (result <= 0) {
  3297. vty_out(vty, "Bad source address %s: errno=%d: %s%s",
  3298. source_str, errno, safe_strerror(errno), VTY_NEWLINE);
  3299. return CMD_WARNING;
  3300. }
  3301. assert_metric_preference = atoi(argv[4]);
  3302. assert_route_metric = atoi(argv[5]);
  3303. assert_rpt_bit_flag = atoi(argv[6]);
  3304. remain = buf_pastend - buf;
  3305. if (remain < (int) sizeof(struct ip)) {
  3306. vty_out(vty, "No room for ip header: buf_size=%d < ip_header_size=%zu%s",
  3307. remain, sizeof(struct ip), VTY_NEWLINE);
  3308. return CMD_WARNING;
  3309. }
  3310. /*
  3311. Tweak IP header
  3312. */
  3313. ip_hdr = (struct ip *) buf;
  3314. ip_hdr->ip_p = PIM_IP_PROTO_PIM;
  3315. ip_hlen = PIM_IP_HEADER_MIN_LEN; /* ip header length in bytes */
  3316. ip_hdr->ip_hl = ip_hlen >> 2; /* ip header length in 4-byte words */
  3317. ip_hdr->ip_src = neigh_addr;
  3318. ip_hdr->ip_dst = qpim_all_pim_routers_addr;
  3319. /*
  3320. Build PIM assert message
  3321. */
  3322. pim_msg = buf + ip_hlen; /* skip ip header */
  3323. pim_msg_size = pim_assert_build_msg(pim_msg, buf_pastend - pim_msg, ifp,
  3324. group_addr, source_addr,
  3325. assert_metric_preference,
  3326. assert_route_metric,
  3327. assert_rpt_bit_flag);
  3328. if (pim_msg_size < 0) {
  3329. vty_out(vty, "Failure building PIM assert message: size=%d%s",
  3330. pim_msg_size, VTY_NEWLINE);
  3331. return CMD_WARNING;
  3332. }
  3333. /* "receive" message */
  3334. ip_msg_len = ip_hlen + pim_msg_size;
  3335. result = pim_pim_packet(ifp, buf, ip_msg_len);
  3336. if (result) {
  3337. vty_out(vty, "pim_pim_packet(len=%d) returned failure: %d%s",
  3338. ip_msg_len, result, VTY_NEWLINE);
  3339. return CMD_WARNING;
  3340. }
  3341. return CMD_SUCCESS;
  3342. }
  3343. static int recv_joinprune(struct vty *vty,
  3344. const char *argv[],
  3345. int src_is_join)
  3346. {
  3347. uint8_t buf[1000];
  3348. const uint8_t *buf_pastend = buf + sizeof(buf);
  3349. uint8_t *pim_msg;
  3350. uint8_t *pim_msg_curr;
  3351. int pim_msg_size;
  3352. struct ip *ip_hdr;
  3353. size_t ip_hlen; /* ip header length in bytes */
  3354. int ip_msg_len;
  3355. uint16_t neigh_holdtime;
  3356. const char *neigh_dst_str;
  3357. struct in_addr neigh_dst_addr;
  3358. const char *neigh_src_str;
  3359. struct in_addr neigh_src_addr;
  3360. const char *group_str;
  3361. struct in_addr group_addr;
  3362. const char *source_str;
  3363. struct in_addr source_addr;
  3364. const char *ifname;
  3365. struct interface *ifp;
  3366. int result;
  3367. int remain;
  3368. uint16_t num_joined;
  3369. uint16_t num_pruned;
  3370. /* Find interface */
  3371. ifname = argv[0];
  3372. ifp = if_lookup_by_name(ifname);
  3373. if (!ifp) {
  3374. vty_out(vty, "No such interface name %s%s",
  3375. ifname, VTY_NEWLINE);
  3376. return CMD_WARNING;
  3377. }
  3378. neigh_holdtime = atoi(argv[1]);
  3379. /* Neighbor destination address */
  3380. neigh_dst_str = argv[2];
  3381. result = inet_pton(AF_INET, neigh_dst_str, &neigh_dst_addr);
  3382. if (result <= 0) {
  3383. vty_out(vty, "Bad neighbor destination address %s: errno=%d: %s%s",
  3384. neigh_dst_str, errno, safe_strerror(errno), VTY_NEWLINE);
  3385. return CMD_WARNING;
  3386. }
  3387. /* Neighbor source address */
  3388. neigh_src_str = argv[3];
  3389. result = inet_pton(AF_INET, neigh_src_str, &neigh_src_addr);
  3390. if (result <= 0) {
  3391. vty_out(vty, "Bad neighbor source address %s: errno=%d: %s%s",
  3392. neigh_src_str, errno, safe_strerror(errno), VTY_NEWLINE);
  3393. return CMD_WARNING;
  3394. }
  3395. /* Multicast group address */
  3396. group_str = argv[4];
  3397. result = inet_pton(AF_INET, group_str, &group_addr);
  3398. if (result <= 0) {
  3399. vty_out(vty, "Bad group address %s: errno=%d: %s%s",
  3400. group_str, errno, safe_strerror(errno), VTY_NEWLINE);
  3401. return CMD_WARNING;
  3402. }
  3403. /* Multicast source address */
  3404. source_str = argv[5];
  3405. result = inet_pton(AF_INET, source_str, &source_addr);
  3406. if (result <= 0) {
  3407. vty_out(vty, "Bad source address %s: errno=%d: %s%s",
  3408. source_str, errno, safe_strerror(errno), VTY_NEWLINE);
  3409. return CMD_WARNING;
  3410. }
  3411. /*
  3412. Tweak IP header
  3413. */
  3414. ip_hdr = (struct ip *) buf;
  3415. ip_hdr->ip_p = PIM_IP_PROTO_PIM;
  3416. ip_hlen = PIM_IP_HEADER_MIN_LEN; /* ip header length in bytes */
  3417. ip_hdr->ip_hl = ip_hlen >> 2; /* ip header length in 4-byte words */
  3418. ip_hdr->ip_src = neigh_src_addr;
  3419. ip_hdr->ip_dst = qpim_all_pim_routers_addr;
  3420. /*
  3421. Build PIM message
  3422. */
  3423. pim_msg = buf + ip_hlen;
  3424. /* skip room for pim header */
  3425. pim_msg_curr = pim_msg + PIM_MSG_HEADER_LEN;
  3426. remain = buf_pastend - pim_msg_curr;
  3427. pim_msg_curr = pim_msg_addr_encode_ipv4_ucast(pim_msg_curr,
  3428. remain,
  3429. neigh_dst_addr);
  3430. if (!pim_msg_curr) {
  3431. vty_out(vty, "Failure encoding destination address %s: space left=%d%s",
  3432. neigh_dst_str, remain, VTY_NEWLINE);
  3433. return CMD_WARNING;
  3434. }
  3435. remain = buf_pastend - pim_msg_curr;
  3436. if (remain < 4) {
  3437. vty_out(vty, "Group will not fit: space left=%d%s",
  3438. remain, VTY_NEWLINE);
  3439. return CMD_WARNING;
  3440. }
  3441. *pim_msg_curr = 0; /* reserved */
  3442. ++pim_msg_curr;
  3443. *pim_msg_curr = 1; /* number of groups */
  3444. ++pim_msg_curr;
  3445. *((uint16_t *) pim_msg_curr) = htons(neigh_holdtime);
  3446. ++pim_msg_curr;
  3447. ++pim_msg_curr;
  3448. remain = buf_pastend - pim_msg_curr;
  3449. pim_msg_curr = pim_msg_addr_encode_ipv4_group(pim_msg_curr,
  3450. remain,
  3451. group_addr);
  3452. if (!pim_msg_curr) {
  3453. vty_out(vty, "Failure encoding group address %s: space left=%d%s",
  3454. group_str, remain, VTY_NEWLINE);
  3455. return CMD_WARNING;
  3456. }
  3457. remain = buf_pastend - pim_msg_curr;
  3458. if (remain < 4) {
  3459. vty_out(vty, "Sources will not fit: space left=%d%s",
  3460. remain, VTY_NEWLINE);
  3461. return CMD_WARNING;
  3462. }
  3463. if (src_is_join) {
  3464. num_joined = 1;
  3465. num_pruned = 0;
  3466. }
  3467. else {
  3468. num_joined = 0;
  3469. num_pruned = 1;
  3470. }
  3471. /* number of joined sources */
  3472. *((uint16_t *) pim_msg_curr) = htons(num_joined);
  3473. ++pim_msg_curr;
  3474. ++pim_msg_curr;
  3475. /* number of pruned sources */
  3476. *((uint16_t *) pim_msg_curr) = htons(num_pruned);
  3477. ++pim_msg_curr;
  3478. ++pim_msg_curr;
  3479. remain = buf_pastend - pim_msg_curr;
  3480. pim_msg_curr = pim_msg_addr_encode_ipv4_source(pim_msg_curr,
  3481. remain,
  3482. source_addr);
  3483. if (!pim_msg_curr) {
  3484. vty_out(vty, "Failure encoding source address %s: space left=%d%s",
  3485. source_str, remain, VTY_NEWLINE);
  3486. return CMD_WARNING;
  3487. }
  3488. /* Add PIM header */
  3489. pim_msg_size = pim_msg_curr - pim_msg;
  3490. pim_msg_build_header(pim_msg, pim_msg_size,
  3491. PIM_MSG_TYPE_JOIN_PRUNE);
  3492. /*
  3493. "Receive" message
  3494. */
  3495. ip_msg_len = ip_hlen + pim_msg_size;
  3496. result = pim_pim_packet(ifp, buf, ip_msg_len);
  3497. if (result) {
  3498. vty_out(vty, "pim_pim_packet(len=%d) returned failure: %d%s",
  3499. ip_msg_len, result, VTY_NEWLINE);
  3500. return CMD_WARNING;
  3501. }
  3502. return CMD_SUCCESS;
  3503. }
  3504. DEFUN (test_pim_receive_join,
  3505. test_pim_receive_join_cmd,
  3506. "test pim receive join INTERFACE <0-65535> A.B.C.D A.B.C.D A.B.C.D A.B.C.D",
  3507. "Test\n"
  3508. "Test PIM protocol\n"
  3509. "Test PIM message reception\n"
  3510. "Test PIM join reception from neighbor\n"
  3511. "Interface\n"
  3512. "Neighbor holdtime\n"
  3513. "Upstream neighbor unicast destination address\n"
  3514. "Downstream neighbor unicast source address\n"
  3515. "Multicast group address\n"
  3516. "Unicast source address\n")
  3517. {
  3518. return recv_joinprune(vty, argv, 1 /* src_is_join=true */);
  3519. }
  3520. DEFUN (test_pim_receive_prune,
  3521. test_pim_receive_prune_cmd,
  3522. "test pim receive prune INTERFACE <0-65535> A.B.C.D A.B.C.D A.B.C.D A.B.C.D",
  3523. "Test\n"
  3524. "Test PIM protocol\n"
  3525. "Test PIM message reception\n"
  3526. "Test PIM prune reception from neighbor\n"
  3527. "Interface\n"
  3528. "Neighbor holdtime\n"
  3529. "Upstream neighbor unicast destination address\n"
  3530. "Downstream neighbor unicast source address\n"
  3531. "Multicast group address\n"
  3532. "Unicast source address\n")
  3533. {
  3534. return recv_joinprune(vty, argv, 0 /* src_is_join=false */);
  3535. }
  3536. DEFUN (test_pim_receive_upcall,
  3537. test_pim_receive_upcall_cmd,
  3538. "test pim receive upcall (nocache|wrongvif|wholepkt) <0-65535> A.B.C.D A.B.C.D",
  3539. "Test\n"
  3540. "Test PIM protocol\n"
  3541. "Test PIM message reception\n"
  3542. "Test reception of kernel upcall\n"
  3543. "NOCACHE kernel upcall\n"
  3544. "WRONGVIF kernel upcall\n"
  3545. "WHOLEPKT kernel upcall\n"
  3546. "Input interface vif index\n"
  3547. "Multicast group address\n"
  3548. "Multicast source address\n")
  3549. {
  3550. struct igmpmsg msg;
  3551. const char *upcall_type;
  3552. const char *group_str;
  3553. const char *source_str;
  3554. int result;
  3555. upcall_type = argv[0];
  3556. if (upcall_type[0] == 'n')
  3557. msg.im_msgtype = IGMPMSG_NOCACHE;
  3558. else if (upcall_type[1] == 'r')
  3559. msg.im_msgtype = IGMPMSG_WRONGVIF;
  3560. else if (upcall_type[1] == 'h')
  3561. msg.im_msgtype = IGMPMSG_WHOLEPKT;
  3562. else {
  3563. vty_out(vty, "Unknown kernel upcall type: %s%s",
  3564. upcall_type, VTY_NEWLINE);
  3565. return CMD_WARNING;
  3566. }
  3567. msg.im_vif = atoi(argv[1]);
  3568. /* Group address */
  3569. group_str = argv[2];
  3570. result = inet_pton(AF_INET, group_str, &msg.im_dst);
  3571. if (result <= 0) {
  3572. vty_out(vty, "Bad group address %s: errno=%d: %s%s",
  3573. group_str, errno, safe_strerror(errno), VTY_NEWLINE);
  3574. return CMD_WARNING;
  3575. }
  3576. /* Source address */
  3577. source_str = argv[3];
  3578. result = inet_pton(AF_INET, source_str, &msg.im_src);
  3579. if (result <= 0) {
  3580. vty_out(vty, "Bad source address %s: errno=%d: %s%s",
  3581. source_str, errno, safe_strerror(errno), VTY_NEWLINE);
  3582. return CMD_WARNING;
  3583. }
  3584. msg.im_mbz = 0; /* Must be zero */
  3585. result = pim_mroute_msg(-1, (char *) &msg, sizeof(msg));
  3586. if (result) {
  3587. vty_out(vty, "pim_mroute_msg(len=%zu) returned failure: %d%s",
  3588. sizeof(msg), result, VTY_NEWLINE);
  3589. return CMD_WARNING;
  3590. }
  3591. return CMD_SUCCESS;
  3592. }
  3593. void pim_cmd_init()
  3594. {
  3595. install_node (&pim_global_node, pim_global_config_write); /* PIM_NODE */
  3596. install_node (&interface_node, pim_interface_config_write); /* INTERFACE_NODE */
  3597. install_element (CONFIG_NODE, &ip_multicast_routing_cmd);
  3598. install_element (CONFIG_NODE, &no_ip_multicast_routing_cmd);
  3599. install_element (CONFIG_NODE, &ip_ssmpingd_cmd);
  3600. install_element (CONFIG_NODE, &no_ip_ssmpingd_cmd);
  3601. #if 0
  3602. install_element (CONFIG_NODE, &interface_cmd); /* from if.h */
  3603. #else
  3604. install_element (CONFIG_NODE, &pim_interface_cmd);
  3605. #endif
  3606. install_element (CONFIG_NODE, &no_interface_cmd); /* from if.h */
  3607. install_default (INTERFACE_NODE);
  3608. install_element (INTERFACE_NODE, &interface_ip_igmp_cmd);
  3609. install_element (INTERFACE_NODE, &interface_no_ip_igmp_cmd);
  3610. install_element (INTERFACE_NODE, &interface_ip_igmp_join_cmd);
  3611. install_element (INTERFACE_NODE, &interface_no_ip_igmp_join_cmd);
  3612. install_element (INTERFACE_NODE, &interface_ip_igmp_query_interval_cmd);
  3613. install_element (INTERFACE_NODE, &interface_no_ip_igmp_query_interval_cmd);
  3614. install_element (INTERFACE_NODE, &interface_ip_igmp_query_max_response_time_cmd);
  3615. install_element (INTERFACE_NODE, &interface_no_ip_igmp_query_max_response_time_cmd);
  3616. install_element (INTERFACE_NODE, &interface_ip_igmp_query_max_response_time_dsec_cmd);
  3617. install_element (INTERFACE_NODE, &interface_no_ip_igmp_query_max_response_time_dsec_cmd);
  3618. install_element (INTERFACE_NODE, &interface_ip_pim_ssm_cmd);
  3619. install_element (INTERFACE_NODE, &interface_no_ip_pim_ssm_cmd);
  3620. install_element (VIEW_NODE, &show_ip_igmp_interface_cmd);
  3621. install_element (VIEW_NODE, &show_ip_igmp_join_cmd);
  3622. install_element (VIEW_NODE, &show_ip_igmp_parameters_cmd);
  3623. install_element (VIEW_NODE, &show_ip_igmp_groups_cmd);
  3624. install_element (VIEW_NODE, &show_ip_igmp_groups_retransmissions_cmd);
  3625. install_element (VIEW_NODE, &show_ip_igmp_sources_cmd);
  3626. install_element (VIEW_NODE, &show_ip_igmp_sources_retransmissions_cmd);
  3627. install_element (VIEW_NODE, &show_ip_igmp_querier_cmd);
  3628. install_element (VIEW_NODE, &show_ip_pim_assert_cmd);
  3629. install_element (VIEW_NODE, &show_ip_pim_assert_internal_cmd);
  3630. install_element (VIEW_NODE, &show_ip_pim_assert_metric_cmd);
  3631. install_element (VIEW_NODE, &show_ip_pim_assert_winner_metric_cmd);
  3632. install_element (VIEW_NODE, &show_ip_pim_dr_cmd);
  3633. install_element (VIEW_NODE, &show_ip_pim_hello_cmd);
  3634. install_element (VIEW_NODE, &show_ip_pim_interface_cmd);
  3635. install_element (VIEW_NODE, &show_ip_pim_join_cmd);
  3636. install_element (VIEW_NODE, &show_ip_pim_jp_override_interval_cmd);
  3637. install_element (VIEW_NODE, &show_ip_pim_lan_prune_delay_cmd);
  3638. install_element (VIEW_NODE, &show_ip_pim_local_membership_cmd);
  3639. install_element (VIEW_NODE, &show_ip_pim_neighbor_cmd);
  3640. install_element (VIEW_NODE, &show_ip_pim_rpf_cmd);
  3641. install_element (VIEW_NODE, &show_ip_pim_secondary_cmd);
  3642. install_element (VIEW_NODE, &show_ip_pim_upstream_cmd);
  3643. install_element (VIEW_NODE, &show_ip_pim_upstream_join_desired_cmd);
  3644. install_element (VIEW_NODE, &show_ip_pim_upstream_rpf_cmd);
  3645. install_element (VIEW_NODE, &show_ip_multicast_cmd);
  3646. install_element (VIEW_NODE, &show_ip_mroute_cmd);
  3647. install_element (VIEW_NODE, &show_ip_mroute_count_cmd);
  3648. install_element (VIEW_NODE, &show_ip_rib_cmd);
  3649. install_element (VIEW_NODE, &show_ip_ssmpingd_cmd);
  3650. install_element (VIEW_NODE, &show_debugging_cmd);
  3651. install_element (ENABLE_NODE, &clear_ip_interfaces_cmd);
  3652. install_element (ENABLE_NODE, &clear_ip_igmp_interfaces_cmd);
  3653. install_element (ENABLE_NODE, &clear_ip_mroute_cmd);
  3654. install_element (ENABLE_NODE, &clear_ip_pim_interfaces_cmd);
  3655. install_element (ENABLE_NODE, &clear_ip_pim_oil_cmd);
  3656. install_element (ENABLE_NODE, &show_ip_igmp_interface_cmd);
  3657. install_element (ENABLE_NODE, &show_ip_igmp_join_cmd);
  3658. install_element (ENABLE_NODE, &show_ip_igmp_parameters_cmd);
  3659. install_element (ENABLE_NODE, &show_ip_igmp_groups_cmd);
  3660. install_element (ENABLE_NODE, &show_ip_igmp_groups_retransmissions_cmd);
  3661. install_element (ENABLE_NODE, &show_ip_igmp_sources_cmd);
  3662. install_element (ENABLE_NODE, &show_ip_igmp_sources_retransmissions_cmd);
  3663. install_element (ENABLE_NODE, &show_ip_igmp_querier_cmd);
  3664. install_element (ENABLE_NODE, &show_ip_pim_address_cmd);
  3665. install_element (ENABLE_NODE, &show_ip_pim_assert_cmd);
  3666. install_element (ENABLE_NODE, &show_ip_pim_assert_internal_cmd);
  3667. install_element (ENABLE_NODE, &show_ip_pim_assert_metric_cmd);
  3668. install_element (ENABLE_NODE, &show_ip_pim_assert_winner_metric_cmd);
  3669. install_element (ENABLE_NODE, &show_ip_pim_dr_cmd);
  3670. install_element (ENABLE_NODE, &show_ip_pim_hello_cmd);
  3671. install_element (ENABLE_NODE, &show_ip_pim_interface_cmd);
  3672. install_element (ENABLE_NODE, &show_ip_pim_join_cmd);
  3673. install_element (ENABLE_NODE, &show_ip_pim_jp_override_interval_cmd);
  3674. install_element (ENABLE_NODE, &show_ip_pim_lan_prune_delay_cmd);
  3675. install_element (ENABLE_NODE, &show_ip_pim_local_membership_cmd);
  3676. install_element (ENABLE_NODE, &show_ip_pim_neighbor_cmd);
  3677. install_element (ENABLE_NODE, &show_ip_pim_rpf_cmd);
  3678. install_element (ENABLE_NODE, &show_ip_pim_secondary_cmd);
  3679. install_element (ENABLE_NODE, &show_ip_pim_upstream_cmd);
  3680. install_element (ENABLE_NODE, &show_ip_pim_upstream_join_desired_cmd);
  3681. install_element (ENABLE_NODE, &show_ip_pim_upstream_rpf_cmd);
  3682. install_element (ENABLE_NODE, &show_ip_multicast_cmd);
  3683. install_element (ENABLE_NODE, &show_ip_mroute_cmd);
  3684. install_element (ENABLE_NODE, &show_ip_mroute_count_cmd);
  3685. install_element (ENABLE_NODE, &show_ip_rib_cmd);
  3686. install_element (ENABLE_NODE, &show_ip_ssmpingd_cmd);
  3687. install_element (ENABLE_NODE, &show_debugging_cmd);
  3688. install_element (ENABLE_NODE, &test_igmp_receive_report_cmd);
  3689. install_element (ENABLE_NODE, &test_pim_receive_assert_cmd);
  3690. install_element (ENABLE_NODE, &test_pim_receive_dump_cmd);
  3691. install_element (ENABLE_NODE, &test_pim_receive_hello_cmd);
  3692. install_element (ENABLE_NODE, &test_pim_receive_join_cmd);
  3693. install_element (ENABLE_NODE, &test_pim_receive_prune_cmd);
  3694. install_element (ENABLE_NODE, &test_pim_receive_upcall_cmd);
  3695. install_element (ENABLE_NODE, &debug_igmp_cmd);
  3696. install_element (ENABLE_NODE, &no_debug_igmp_cmd);
  3697. install_element (ENABLE_NODE, &undebug_igmp_cmd);
  3698. install_element (ENABLE_NODE, &debug_igmp_events_cmd);
  3699. install_element (ENABLE_NODE, &no_debug_igmp_events_cmd);
  3700. install_element (ENABLE_NODE, &undebug_igmp_events_cmd);
  3701. install_element (ENABLE_NODE, &debug_igmp_packets_cmd);
  3702. install_element (ENABLE_NODE, &no_debug_igmp_packets_cmd);
  3703. install_element (ENABLE_NODE, &undebug_igmp_packets_cmd);
  3704. install_element (ENABLE_NODE, &debug_igmp_trace_cmd);
  3705. install_element (ENABLE_NODE, &no_debug_igmp_trace_cmd);
  3706. install_element (ENABLE_NODE, &undebug_igmp_trace_cmd);
  3707. install_element (ENABLE_NODE, &debug_mroute_cmd);
  3708. install_element (ENABLE_NODE, &no_debug_mroute_cmd);
  3709. install_element (ENABLE_NODE, &debug_pim_cmd);
  3710. install_element (ENABLE_NODE, &no_debug_pim_cmd);
  3711. install_element (ENABLE_NODE, &undebug_pim_cmd);
  3712. install_element (ENABLE_NODE, &debug_pim_events_cmd);
  3713. install_element (ENABLE_NODE, &no_debug_pim_events_cmd);
  3714. install_element (ENABLE_NODE, &undebug_pim_events_cmd);
  3715. install_element (ENABLE_NODE, &debug_pim_packets_cmd);
  3716. install_element (ENABLE_NODE, &debug_pim_packets_filter_cmd);
  3717. install_element (ENABLE_NODE, &no_debug_pim_packets_cmd);
  3718. install_element (ENABLE_NODE, &no_debug_pim_packets_filter_cmd);
  3719. install_element (ENABLE_NODE, &undebug_pim_packets_cmd);
  3720. install_element (ENABLE_NODE, &debug_pim_packetdump_send_cmd);
  3721. install_element (ENABLE_NODE, &no_debug_pim_packetdump_send_cmd);
  3722. install_element (ENABLE_NODE, &undebug_pim_packetdump_send_cmd);
  3723. install_element (ENABLE_NODE, &debug_pim_packetdump_recv_cmd);
  3724. install_element (ENABLE_NODE, &no_debug_pim_packetdump_recv_cmd);
  3725. install_element (ENABLE_NODE, &undebug_pim_packetdump_recv_cmd);
  3726. install_element (ENABLE_NODE, &debug_pim_trace_cmd);
  3727. install_element (ENABLE_NODE, &no_debug_pim_trace_cmd);
  3728. install_element (ENABLE_NODE, &undebug_pim_trace_cmd);
  3729. install_element (ENABLE_NODE, &debug_ssmpingd_cmd);
  3730. install_element (ENABLE_NODE, &no_debug_ssmpingd_cmd);
  3731. install_element (ENABLE_NODE, &undebug_ssmpingd_cmd);
  3732. install_element (ENABLE_NODE, &debug_pim_zebra_cmd);
  3733. install_element (ENABLE_NODE, &no_debug_pim_zebra_cmd);
  3734. install_element (ENABLE_NODE, &undebug_pim_zebra_cmd);
  3735. install_element (CONFIG_NODE, &debug_igmp_cmd);
  3736. install_element (CONFIG_NODE, &no_debug_igmp_cmd);
  3737. install_element (CONFIG_NODE, &undebug_igmp_cmd);
  3738. install_element (CONFIG_NODE, &debug_igmp_events_cmd);
  3739. install_element (CONFIG_NODE, &no_debug_igmp_events_cmd);
  3740. install_element (CONFIG_NODE, &undebug_igmp_events_cmd);
  3741. install_element (CONFIG_NODE, &debug_igmp_packets_cmd);
  3742. install_element (CONFIG_NODE, &no_debug_igmp_packets_cmd);
  3743. install_element (CONFIG_NODE, &undebug_igmp_packets_cmd);
  3744. install_element (CONFIG_NODE, &debug_igmp_trace_cmd);
  3745. install_element (CONFIG_NODE, &no_debug_igmp_trace_cmd);
  3746. install_element (CONFIG_NODE, &undebug_igmp_trace_cmd);
  3747. install_element (CONFIG_NODE, &debug_mroute_cmd);
  3748. install_element (CONFIG_NODE, &no_debug_mroute_cmd);
  3749. install_element (CONFIG_NODE, &debug_pim_cmd);
  3750. install_element (CONFIG_NODE, &no_debug_pim_cmd);
  3751. install_element (CONFIG_NODE, &undebug_pim_cmd);
  3752. install_element (CONFIG_NODE, &debug_pim_events_cmd);
  3753. install_element (CONFIG_NODE, &no_debug_pim_events_cmd);
  3754. install_element (CONFIG_NODE, &undebug_pim_events_cmd);
  3755. install_element (CONFIG_NODE, &debug_pim_packets_cmd);
  3756. install_element (CONFIG_NODE, &debug_pim_packets_filter_cmd);
  3757. install_element (CONFIG_NODE, &no_debug_pim_packets_cmd);
  3758. install_element (CONFIG_NODE, &no_debug_pim_packets_filter_cmd);
  3759. install_element (CONFIG_NODE, &undebug_pim_packets_cmd);
  3760. install_element (CONFIG_NODE, &debug_pim_trace_cmd);
  3761. install_element (CONFIG_NODE, &no_debug_pim_trace_cmd);
  3762. install_element (CONFIG_NODE, &undebug_pim_trace_cmd);
  3763. install_element (CONFIG_NODE, &debug_ssmpingd_cmd);
  3764. install_element (CONFIG_NODE, &no_debug_ssmpingd_cmd);
  3765. install_element (CONFIG_NODE, &undebug_ssmpingd_cmd);
  3766. install_element (CONFIG_NODE, &debug_pim_zebra_cmd);
  3767. install_element (CONFIG_NODE, &no_debug_pim_zebra_cmd);
  3768. install_element (CONFIG_NODE, &undebug_pim_zebra_cmd);
  3769. }