pim_cmd.c 104 KB

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