pim_cmd.c 116 KB

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