pim_cmd.c 118 KB

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