bgp_route.c 403 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139
  1. /* BGP routing information
  2. Copyright (C) 1996, 97, 98, 99 Kunihiro Ishiguro
  3. This file is part of GNU Zebra.
  4. GNU Zebra is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by the
  6. Free Software Foundation; either version 2, or (at your option) any
  7. later version.
  8. GNU Zebra 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 GNU Zebra; see the file COPYING. If not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  15. 02111-1307, USA. */
  16. #include <zebra.h>
  17. #include "prefix.h"
  18. #include "linklist.h"
  19. #include "memory.h"
  20. #include "command.h"
  21. #include "stream.h"
  22. #include "filter.h"
  23. #include "str.h"
  24. #include "log.h"
  25. #include "routemap.h"
  26. #include "buffer.h"
  27. #include "sockunion.h"
  28. #include "plist.h"
  29. #include "thread.h"
  30. #include "workqueue.h"
  31. #include "bgpd/bgpd.h"
  32. #include "bgpd/bgp_table.h"
  33. #include "bgpd/bgp_route.h"
  34. #include "bgpd/bgp_attr.h"
  35. #include "bgpd/bgp_debug.h"
  36. #include "bgpd/bgp_aspath.h"
  37. #include "bgpd/bgp_regex.h"
  38. #include "bgpd/bgp_community.h"
  39. #include "bgpd/bgp_ecommunity.h"
  40. #include "bgpd/bgp_clist.h"
  41. #include "bgpd/bgp_packet.h"
  42. #include "bgpd/bgp_filter.h"
  43. #include "bgpd/bgp_fsm.h"
  44. #include "bgpd/bgp_mplsvpn.h"
  45. #include "bgpd/bgp_nexthop.h"
  46. #include "bgpd/bgp_damp.h"
  47. #include "bgpd/bgp_advertise.h"
  48. #include "bgpd/bgp_zebra.h"
  49. #include "bgpd/bgp_vty.h"
  50. #include "bgpd/bgp_mpath.h"
  51. /* Extern from bgp_dump.c */
  52. extern const char *bgp_origin_str[];
  53. extern const char *bgp_origin_long_str[];
  54. static struct bgp_node *
  55. bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
  56. struct prefix_rd *prd)
  57. {
  58. struct bgp_node *rn;
  59. struct bgp_node *prn = NULL;
  60. assert (table);
  61. if (!table)
  62. return NULL;
  63. if (safi == SAFI_MPLS_VPN)
  64. {
  65. prn = bgp_node_get (table, (struct prefix *) prd);
  66. if (prn->info == NULL)
  67. prn->info = bgp_table_init (afi, safi);
  68. else
  69. bgp_unlock_node (prn);
  70. table = prn->info;
  71. }
  72. rn = bgp_node_get (table, p);
  73. if (safi == SAFI_MPLS_VPN)
  74. rn->prn = prn;
  75. return rn;
  76. }
  77. /* Allocate bgp_info_extra */
  78. static struct bgp_info_extra *
  79. bgp_info_extra_new (void)
  80. {
  81. struct bgp_info_extra *new;
  82. new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
  83. return new;
  84. }
  85. static void
  86. bgp_info_extra_free (struct bgp_info_extra **extra)
  87. {
  88. if (extra && *extra)
  89. {
  90. if ((*extra)->damp_info)
  91. bgp_damp_info_free ((*extra)->damp_info, 0);
  92. (*extra)->damp_info = NULL;
  93. XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
  94. *extra = NULL;
  95. }
  96. }
  97. /* Get bgp_info extra information for the given bgp_info, lazy allocated
  98. * if required.
  99. */
  100. struct bgp_info_extra *
  101. bgp_info_extra_get (struct bgp_info *ri)
  102. {
  103. if (!ri->extra)
  104. ri->extra = bgp_info_extra_new();
  105. return ri->extra;
  106. }
  107. /* Allocate new bgp info structure. */
  108. static struct bgp_info *
  109. bgp_info_new (void)
  110. {
  111. return XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
  112. }
  113. /* Free bgp route information. */
  114. static void
  115. bgp_info_free (struct bgp_info *binfo)
  116. {
  117. if (binfo->attr)
  118. bgp_attr_unintern (&binfo->attr);
  119. bgp_info_extra_free (&binfo->extra);
  120. bgp_info_mpath_free (&binfo->mpath);
  121. peer_unlock (binfo->peer); /* bgp_info peer reference */
  122. XFREE (MTYPE_BGP_ROUTE, binfo);
  123. }
  124. struct bgp_info *
  125. bgp_info_lock (struct bgp_info *binfo)
  126. {
  127. binfo->lock++;
  128. return binfo;
  129. }
  130. struct bgp_info *
  131. bgp_info_unlock (struct bgp_info *binfo)
  132. {
  133. assert (binfo && binfo->lock > 0);
  134. binfo->lock--;
  135. if (binfo->lock == 0)
  136. {
  137. #if 0
  138. zlog_debug ("%s: unlocked and freeing", __func__);
  139. zlog_backtrace (LOG_DEBUG);
  140. #endif
  141. bgp_info_free (binfo);
  142. return NULL;
  143. }
  144. #if 0
  145. if (binfo->lock == 1)
  146. {
  147. zlog_debug ("%s: unlocked to 1", __func__);
  148. zlog_backtrace (LOG_DEBUG);
  149. }
  150. #endif
  151. return binfo;
  152. }
  153. void
  154. bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
  155. {
  156. struct bgp_info *top;
  157. top = rn->info;
  158. ri->next = rn->info;
  159. ri->prev = NULL;
  160. if (top)
  161. top->prev = ri;
  162. rn->info = ri;
  163. bgp_info_lock (ri);
  164. bgp_lock_node (rn);
  165. peer_lock (ri->peer); /* bgp_info peer reference */
  166. }
  167. /* Do the actual removal of info from RIB, for use by bgp_process
  168. completion callback *only* */
  169. static void
  170. bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
  171. {
  172. if (ri->next)
  173. ri->next->prev = ri->prev;
  174. if (ri->prev)
  175. ri->prev->next = ri->next;
  176. else
  177. rn->info = ri->next;
  178. bgp_info_mpath_dequeue (ri);
  179. bgp_info_unlock (ri);
  180. bgp_unlock_node (rn);
  181. }
  182. void
  183. bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
  184. {
  185. bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
  186. /* set of previous already took care of pcount */
  187. UNSET_FLAG (ri->flags, BGP_INFO_VALID);
  188. }
  189. /* undo the effects of a previous call to bgp_info_delete; typically
  190. called when a route is deleted and then quickly re-added before the
  191. deletion has been processed */
  192. static void
  193. bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
  194. {
  195. bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
  196. /* unset of previous already took care of pcount */
  197. SET_FLAG (ri->flags, BGP_INFO_VALID);
  198. }
  199. /* Adjust pcount as required */
  200. static void
  201. bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
  202. {
  203. struct bgp_table *table;
  204. assert (rn && bgp_node_table (rn));
  205. assert (ri && ri->peer && ri->peer->bgp);
  206. table = bgp_node_table (rn);
  207. /* Ignore 'pcount' for RS-client tables */
  208. if (table->type != BGP_TABLE_MAIN
  209. || ri->peer == ri->peer->bgp->peer_self)
  210. return;
  211. if (BGP_INFO_HOLDDOWN (ri)
  212. && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
  213. {
  214. UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
  215. /* slight hack, but more robust against errors. */
  216. if (ri->peer->pcount[table->afi][table->safi])
  217. ri->peer->pcount[table->afi][table->safi]--;
  218. else
  219. {
  220. zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
  221. __func__, ri->peer->host);
  222. zlog_backtrace (LOG_WARNING);
  223. zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
  224. }
  225. }
  226. else if (!BGP_INFO_HOLDDOWN (ri)
  227. && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
  228. {
  229. SET_FLAG (ri->flags, BGP_INFO_COUNTED);
  230. ri->peer->pcount[table->afi][table->safi]++;
  231. }
  232. }
  233. /* Set/unset bgp_info flags, adjusting any other state as needed.
  234. * This is here primarily to keep prefix-count in check.
  235. */
  236. void
  237. bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
  238. {
  239. SET_FLAG (ri->flags, flag);
  240. /* early bath if we know it's not a flag that changes useability state */
  241. if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
  242. return;
  243. bgp_pcount_adjust (rn, ri);
  244. }
  245. void
  246. bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
  247. {
  248. UNSET_FLAG (ri->flags, flag);
  249. /* early bath if we know it's not a flag that changes useability state */
  250. if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
  251. return;
  252. bgp_pcount_adjust (rn, ri);
  253. }
  254. /* Get MED value. If MED value is missing and "bgp bestpath
  255. missing-as-worst" is specified, treat it as the worst value. */
  256. static u_int32_t
  257. bgp_med_value (struct attr *attr, struct bgp *bgp)
  258. {
  259. if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
  260. return attr->med;
  261. else
  262. {
  263. if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
  264. return BGP_MED_MAX;
  265. else
  266. return 0;
  267. }
  268. }
  269. /* Compare two bgp route entity. br is preferable then return 1. */
  270. static int
  271. bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
  272. int *paths_eq)
  273. {
  274. struct attr *newattr, *existattr;
  275. struct attr_extra *newattre, *existattre;
  276. bgp_peer_sort_t new_sort;
  277. bgp_peer_sort_t exist_sort;
  278. u_int32_t new_pref;
  279. u_int32_t exist_pref;
  280. u_int32_t new_med;
  281. u_int32_t exist_med;
  282. u_int32_t new_weight;
  283. u_int32_t exist_weight;
  284. uint32_t newm, existm;
  285. struct in_addr new_id;
  286. struct in_addr exist_id;
  287. int new_cluster;
  288. int exist_cluster;
  289. int internal_as_route;
  290. int confed_as_route;
  291. int ret;
  292. *paths_eq = 0;
  293. /* 0. Null check. */
  294. if (new == NULL)
  295. return 0;
  296. if (exist == NULL)
  297. return 1;
  298. newattr = new->attr;
  299. existattr = exist->attr;
  300. newattre = newattr->extra;
  301. existattre = existattr->extra;
  302. /* 1. Weight check. */
  303. new_weight = exist_weight = 0;
  304. if (newattre)
  305. new_weight = newattre->weight;
  306. if (existattre)
  307. exist_weight = existattre->weight;
  308. if (new_weight > exist_weight)
  309. return 1;
  310. if (new_weight < exist_weight)
  311. return 0;
  312. /* 2. Local preference check. */
  313. new_pref = exist_pref = bgp->default_local_pref;
  314. if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
  315. new_pref = newattr->local_pref;
  316. if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
  317. exist_pref = existattr->local_pref;
  318. if (new_pref > exist_pref)
  319. return 1;
  320. if (new_pref < exist_pref)
  321. return 0;
  322. /* 3. Local route check. We prefer:
  323. * - BGP_ROUTE_STATIC
  324. * - BGP_ROUTE_AGGREGATE
  325. * - BGP_ROUTE_REDISTRIBUTE
  326. */
  327. if (! (new->sub_type == BGP_ROUTE_NORMAL))
  328. return 1;
  329. if (! (exist->sub_type == BGP_ROUTE_NORMAL))
  330. return 0;
  331. /* 4. AS path length check. */
  332. if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
  333. {
  334. int exist_hops = aspath_count_hops (existattr->aspath);
  335. int exist_confeds = aspath_count_confeds (existattr->aspath);
  336. if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
  337. {
  338. int aspath_hops;
  339. aspath_hops = aspath_count_hops (newattr->aspath);
  340. aspath_hops += aspath_count_confeds (newattr->aspath);
  341. if ( aspath_hops < (exist_hops + exist_confeds))
  342. return 1;
  343. if ( aspath_hops > (exist_hops + exist_confeds))
  344. return 0;
  345. }
  346. else
  347. {
  348. int newhops = aspath_count_hops (newattr->aspath);
  349. if (newhops < exist_hops)
  350. return 1;
  351. if (newhops > exist_hops)
  352. return 0;
  353. }
  354. }
  355. /* 5. Origin check. */
  356. if (newattr->origin < existattr->origin)
  357. return 1;
  358. if (newattr->origin > existattr->origin)
  359. return 0;
  360. /* 6. MED check. */
  361. internal_as_route = (aspath_count_hops (newattr->aspath) == 0
  362. && aspath_count_hops (existattr->aspath) == 0);
  363. confed_as_route = (aspath_count_confeds (newattr->aspath) > 0
  364. && aspath_count_confeds (existattr->aspath) > 0
  365. && aspath_count_hops (newattr->aspath) == 0
  366. && aspath_count_hops (existattr->aspath) == 0);
  367. if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
  368. || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
  369. && confed_as_route)
  370. || aspath_cmp_left (newattr->aspath, existattr->aspath)
  371. || aspath_cmp_left_confed (newattr->aspath, existattr->aspath)
  372. || internal_as_route)
  373. {
  374. new_med = bgp_med_value (new->attr, bgp);
  375. exist_med = bgp_med_value (exist->attr, bgp);
  376. if (new_med < exist_med)
  377. return 1;
  378. if (new_med > exist_med)
  379. return 0;
  380. }
  381. /* 7. Peer type check. */
  382. new_sort = new->peer->sort;
  383. exist_sort = exist->peer->sort;
  384. if (new_sort == BGP_PEER_EBGP
  385. && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED))
  386. return 1;
  387. if (exist_sort == BGP_PEER_EBGP
  388. && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED))
  389. return 0;
  390. /* 8. IGP metric check. */
  391. newm = existm = 0;
  392. if (new->extra)
  393. newm = new->extra->igpmetric;
  394. if (exist->extra)
  395. existm = exist->extra->igpmetric;
  396. if (newm < existm)
  397. ret = 1;
  398. if (newm > existm)
  399. ret = 0;
  400. /* 9. Maximum path check. */
  401. if (newm == existm)
  402. {
  403. if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX))
  404. {
  405. /*
  406. * For the two paths, all comparison steps till IGP metric
  407. * have succeeded - including AS_PATH hop count. Since 'bgp
  408. * bestpath as-path multipath-relax' knob is on, we don't need
  409. * an exact match of AS_PATH. Thus, mark the paths are equal.
  410. * That will trigger both these paths to get into the multipath
  411. * array.
  412. */
  413. *paths_eq = 1;
  414. }
  415. else if (new->peer->sort == BGP_PEER_IBGP)
  416. {
  417. if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
  418. *paths_eq = 1;
  419. }
  420. else if (new->peer->as == exist->peer->as)
  421. *paths_eq = 1;
  422. }
  423. else
  424. {
  425. /*
  426. * TODO: If unequal cost ibgp multipath is enabled we can
  427. * mark the paths as equal here instead of returning
  428. */
  429. return ret;
  430. }
  431. /* 10. If both paths are external, prefer the path that was received
  432. first (the oldest one). This step minimizes route-flap, since a
  433. newer path won't displace an older one, even if it was the
  434. preferred route based on the additional decision criteria below. */
  435. if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
  436. && new_sort == BGP_PEER_EBGP
  437. && exist_sort == BGP_PEER_EBGP)
  438. {
  439. if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
  440. return 1;
  441. if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
  442. return 0;
  443. }
  444. /* 11. Rourter-ID comparision. */
  445. if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
  446. new_id.s_addr = newattre->originator_id.s_addr;
  447. else
  448. new_id.s_addr = new->peer->remote_id.s_addr;
  449. if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
  450. exist_id.s_addr = existattre->originator_id.s_addr;
  451. else
  452. exist_id.s_addr = exist->peer->remote_id.s_addr;
  453. if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
  454. return 1;
  455. if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
  456. return 0;
  457. /* 12. Cluster length comparision. */
  458. new_cluster = exist_cluster = 0;
  459. if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
  460. new_cluster = newattre->cluster->length;
  461. if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
  462. exist_cluster = existattre->cluster->length;
  463. if (new_cluster < exist_cluster)
  464. return 1;
  465. if (new_cluster > exist_cluster)
  466. return 0;
  467. /* 13. Neighbor address comparision. */
  468. ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
  469. if (ret == 1)
  470. return 0;
  471. if (ret == -1)
  472. return 1;
  473. return 1;
  474. }
  475. static enum filter_type
  476. bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
  477. afi_t afi, safi_t safi)
  478. {
  479. struct bgp_filter *filter;
  480. filter = &peer->filter[afi][safi];
  481. #define FILTER_EXIST_WARN(F,f,filter) \
  482. if (BGP_DEBUG (update, UPDATE_IN) \
  483. && !(F ## _IN (filter))) \
  484. plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \
  485. peer->host, #f, F ## _IN_NAME(filter));
  486. if (DISTRIBUTE_IN_NAME (filter)) {
  487. FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
  488. if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
  489. return FILTER_DENY;
  490. }
  491. if (PREFIX_LIST_IN_NAME (filter)) {
  492. FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
  493. if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
  494. return FILTER_DENY;
  495. }
  496. if (FILTER_LIST_IN_NAME (filter)) {
  497. FILTER_EXIST_WARN(FILTER_LIST, as, filter);
  498. if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
  499. return FILTER_DENY;
  500. }
  501. return FILTER_PERMIT;
  502. #undef FILTER_EXIST_WARN
  503. }
  504. static enum filter_type
  505. bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
  506. afi_t afi, safi_t safi)
  507. {
  508. struct bgp_filter *filter;
  509. filter = &peer->filter[afi][safi];
  510. #define FILTER_EXIST_WARN(F,f,filter) \
  511. if (BGP_DEBUG (update, UPDATE_OUT) \
  512. && !(F ## _OUT (filter))) \
  513. plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \
  514. peer->host, #f, F ## _OUT_NAME(filter));
  515. if (DISTRIBUTE_OUT_NAME (filter)) {
  516. FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
  517. if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
  518. return FILTER_DENY;
  519. }
  520. if (PREFIX_LIST_OUT_NAME (filter)) {
  521. FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
  522. if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
  523. return FILTER_DENY;
  524. }
  525. if (FILTER_LIST_OUT_NAME (filter)) {
  526. FILTER_EXIST_WARN(FILTER_LIST, as, filter);
  527. if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
  528. return FILTER_DENY;
  529. }
  530. return FILTER_PERMIT;
  531. #undef FILTER_EXIST_WARN
  532. }
  533. /* If community attribute includes no_export then return 1. */
  534. static int
  535. bgp_community_filter (struct peer *peer, struct attr *attr)
  536. {
  537. if (attr->community)
  538. {
  539. /* NO_ADVERTISE check. */
  540. if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
  541. return 1;
  542. /* NO_EXPORT check. */
  543. if (peer->sort == BGP_PEER_EBGP &&
  544. community_include (attr->community, COMMUNITY_NO_EXPORT))
  545. return 1;
  546. /* NO_EXPORT_SUBCONFED check. */
  547. if (peer->sort == BGP_PEER_EBGP
  548. || peer->sort == BGP_PEER_CONFED)
  549. if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
  550. return 1;
  551. }
  552. return 0;
  553. }
  554. /* Route reflection loop check. */
  555. static int
  556. bgp_cluster_filter (struct peer *peer, struct attr *attr)
  557. {
  558. struct in_addr cluster_id;
  559. if (attr->extra && attr->extra->cluster)
  560. {
  561. if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
  562. cluster_id = peer->bgp->cluster_id;
  563. else
  564. cluster_id = peer->bgp->router_id;
  565. if (cluster_loop_check (attr->extra->cluster, cluster_id))
  566. return 1;
  567. }
  568. return 0;
  569. }
  570. static int
  571. bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
  572. afi_t afi, safi_t safi)
  573. {
  574. struct bgp_filter *filter;
  575. struct bgp_info info;
  576. route_map_result_t ret;
  577. filter = &peer->filter[afi][safi];
  578. /* Apply default weight value. */
  579. if (peer->weight)
  580. (bgp_attr_extra_get (attr))->weight = peer->weight;
  581. /* Route map apply. */
  582. if (ROUTE_MAP_IN_NAME (filter))
  583. {
  584. /* Duplicate current value to new strucutre for modification. */
  585. info.peer = peer;
  586. info.attr = attr;
  587. SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
  588. /* Apply BGP route map to the attribute. */
  589. ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
  590. peer->rmap_type = 0;
  591. if (ret == RMAP_DENYMATCH)
  592. {
  593. /* Free newly generated AS path and community by route-map. */
  594. bgp_attr_flush (attr);
  595. return RMAP_DENY;
  596. }
  597. }
  598. return RMAP_PERMIT;
  599. }
  600. static int
  601. bgp_export_modifier (struct peer *rsclient, struct peer *peer,
  602. struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
  603. {
  604. struct bgp_filter *filter;
  605. struct bgp_info info;
  606. route_map_result_t ret;
  607. filter = &peer->filter[afi][safi];
  608. /* Route map apply. */
  609. if (ROUTE_MAP_EXPORT_NAME (filter))
  610. {
  611. /* Duplicate current value to new strucutre for modification. */
  612. info.peer = rsclient;
  613. info.attr = attr;
  614. SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
  615. /* Apply BGP route map to the attribute. */
  616. ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
  617. rsclient->rmap_type = 0;
  618. if (ret == RMAP_DENYMATCH)
  619. {
  620. /* Free newly generated AS path and community by route-map. */
  621. bgp_attr_flush (attr);
  622. return RMAP_DENY;
  623. }
  624. }
  625. return RMAP_PERMIT;
  626. }
  627. static int
  628. bgp_import_modifier (struct peer *rsclient, struct peer *peer,
  629. struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
  630. {
  631. struct bgp_filter *filter;
  632. struct bgp_info info;
  633. route_map_result_t ret;
  634. filter = &rsclient->filter[afi][safi];
  635. /* Apply default weight value. */
  636. if (peer->weight)
  637. (bgp_attr_extra_get (attr))->weight = peer->weight;
  638. /* Route map apply. */
  639. if (ROUTE_MAP_IMPORT_NAME (filter))
  640. {
  641. /* Duplicate current value to new strucutre for modification. */
  642. info.peer = peer;
  643. info.attr = attr;
  644. SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
  645. /* Apply BGP route map to the attribute. */
  646. ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
  647. peer->rmap_type = 0;
  648. if (ret == RMAP_DENYMATCH)
  649. {
  650. /* Free newly generated AS path and community by route-map. */
  651. bgp_attr_flush (attr);
  652. return RMAP_DENY;
  653. }
  654. }
  655. return RMAP_PERMIT;
  656. }
  657. static int
  658. bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
  659. struct attr *attr, afi_t afi, safi_t safi)
  660. {
  661. int ret;
  662. char buf[SU_ADDRSTRLEN];
  663. struct bgp_filter *filter;
  664. struct peer *from;
  665. struct bgp *bgp;
  666. int transparent;
  667. int reflect;
  668. struct attr *riattr;
  669. from = ri->peer;
  670. filter = &peer->filter[afi][safi];
  671. bgp = peer->bgp;
  672. riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
  673. if (DISABLE_BGP_ANNOUNCE)
  674. return 0;
  675. /* Do not send announces to RS-clients from the 'normal' bgp_table. */
  676. if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
  677. return 0;
  678. /* Do not send back route to sender. */
  679. if (from == peer)
  680. return 0;
  681. /* Aggregate-address suppress check. */
  682. if (ri->extra && ri->extra->suppress)
  683. if (! UNSUPPRESS_MAP_NAME (filter))
  684. return 0;
  685. /* Default route check. */
  686. if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
  687. {
  688. if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
  689. return 0;
  690. #ifdef HAVE_IPV6
  691. else if (p->family == AF_INET6 && p->prefixlen == 0)
  692. return 0;
  693. #endif /* HAVE_IPV6 */
  694. }
  695. /* Transparency check. */
  696. if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
  697. && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
  698. transparent = 1;
  699. else
  700. transparent = 0;
  701. /* If community is not disabled check the no-export and local. */
  702. if (! transparent && bgp_community_filter (peer, riattr))
  703. return 0;
  704. /* If the attribute has originator-id and it is same as remote
  705. peer's id. */
  706. if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
  707. {
  708. if (IPV4_ADDR_SAME (&peer->remote_id, &riattr->extra->originator_id))
  709. {
  710. if (BGP_DEBUG (filter, FILTER))
  711. zlog (peer->log, LOG_DEBUG,
  712. "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
  713. peer->host,
  714. inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  715. p->prefixlen);
  716. return 0;
  717. }
  718. }
  719. /* ORF prefix-list filter check */
  720. if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
  721. && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
  722. || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
  723. if (peer->orf_plist[afi][safi])
  724. {
  725. if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
  726. return 0;
  727. }
  728. /* Output filter check. */
  729. if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
  730. {
  731. if (BGP_DEBUG (filter, FILTER))
  732. zlog (peer->log, LOG_DEBUG,
  733. "%s [Update:SEND] %s/%d is filtered",
  734. peer->host,
  735. inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  736. p->prefixlen);
  737. return 0;
  738. }
  739. #ifdef BGP_SEND_ASPATH_CHECK
  740. /* AS path loop check. */
  741. if (aspath_loop_check (riattr->aspath, peer->as))
  742. {
  743. if (BGP_DEBUG (filter, FILTER))
  744. zlog (peer->log, LOG_DEBUG,
  745. "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
  746. peer->host, peer->as);
  747. return 0;
  748. }
  749. #endif /* BGP_SEND_ASPATH_CHECK */
  750. /* If we're a CONFED we need to loop check the CONFED ID too */
  751. if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
  752. {
  753. if (aspath_loop_check(riattr->aspath, bgp->confed_id))
  754. {
  755. if (BGP_DEBUG (filter, FILTER))
  756. zlog (peer->log, LOG_DEBUG,
  757. "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
  758. peer->host,
  759. bgp->confed_id);
  760. return 0;
  761. }
  762. }
  763. /* Route-Reflect check. */
  764. if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
  765. reflect = 1;
  766. else
  767. reflect = 0;
  768. /* IBGP reflection check. */
  769. if (reflect)
  770. {
  771. /* A route from a Client peer. */
  772. if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
  773. {
  774. /* Reflect to all the Non-Client peers and also to the
  775. Client peers other than the originator. Originator check
  776. is already done. So there is noting to do. */
  777. /* no bgp client-to-client reflection check. */
  778. if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
  779. if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
  780. return 0;
  781. }
  782. else
  783. {
  784. /* A route from a Non-client peer. Reflect to all other
  785. clients. */
  786. if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
  787. return 0;
  788. }
  789. }
  790. /* For modify attribute, copy it to temporary structure. */
  791. bgp_attr_dup (attr, riattr);
  792. /* If local-preference is not set. */
  793. if ((peer->sort == BGP_PEER_IBGP
  794. || peer->sort == BGP_PEER_CONFED)
  795. && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
  796. {
  797. attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
  798. attr->local_pref = bgp->default_local_pref;
  799. }
  800. /* If originator-id is not set and the route is to be reflected,
  801. set the originator id */
  802. if (peer && from && peer->sort == BGP_PEER_IBGP &&
  803. from->sort == BGP_PEER_IBGP &&
  804. (! (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
  805. {
  806. attr->extra = bgp_attr_extra_get(attr);
  807. IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
  808. SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
  809. }
  810. /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
  811. if (peer->sort == BGP_PEER_EBGP
  812. && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
  813. {
  814. if (ri->peer != bgp->peer_self && ! transparent
  815. && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
  816. attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
  817. }
  818. /* next-hop-set */
  819. if (transparent || reflect
  820. || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
  821. && ((p->family == AF_INET && attr->nexthop.s_addr)
  822. #ifdef HAVE_IPV6
  823. || (p->family == AF_INET6 &&
  824. ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
  825. #endif /* HAVE_IPV6 */
  826. )))
  827. {
  828. /* NEXT-HOP Unchanged. */
  829. }
  830. else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
  831. || (p->family == AF_INET && attr->nexthop.s_addr == 0)
  832. #ifdef HAVE_IPV6
  833. || (p->family == AF_INET6 &&
  834. IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
  835. #endif /* HAVE_IPV6 */
  836. || (peer->sort == BGP_PEER_EBGP
  837. && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
  838. {
  839. /* Set IPv4 nexthop. */
  840. if (p->family == AF_INET)
  841. {
  842. if (safi == SAFI_MPLS_VPN)
  843. memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
  844. IPV4_MAX_BYTELEN);
  845. else
  846. memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
  847. }
  848. #ifdef HAVE_IPV6
  849. /* Set IPv6 nexthop. */
  850. if (p->family == AF_INET6)
  851. {
  852. /* IPv6 global nexthop must be included. */
  853. memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
  854. IPV6_MAX_BYTELEN);
  855. attr->extra->mp_nexthop_len = 16;
  856. }
  857. #endif /* HAVE_IPV6 */
  858. }
  859. #ifdef HAVE_IPV6
  860. if (p->family == AF_INET6)
  861. {
  862. /* Left nexthop_local unchanged if so configured. */
  863. if ( CHECK_FLAG (peer->af_flags[afi][safi],
  864. PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
  865. {
  866. if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
  867. attr->extra->mp_nexthop_len=32;
  868. else
  869. attr->extra->mp_nexthop_len=16;
  870. }
  871. /* Default nexthop_local treatment for non-RS-Clients */
  872. else
  873. {
  874. /* Link-local address should not be transit to different peer. */
  875. attr->extra->mp_nexthop_len = 16;
  876. /* Set link-local address for shared network peer. */
  877. if (peer->shared_network
  878. && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
  879. {
  880. memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
  881. IPV6_MAX_BYTELEN);
  882. attr->extra->mp_nexthop_len = 32;
  883. }
  884. /* If bgpd act as BGP-4+ route-reflector, do not send link-local
  885. address.*/
  886. if (reflect)
  887. attr->extra->mp_nexthop_len = 16;
  888. /* If BGP-4+ link-local nexthop is not link-local nexthop. */
  889. if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
  890. attr->extra->mp_nexthop_len = 16;
  891. }
  892. }
  893. #endif /* HAVE_IPV6 */
  894. /* If this is EBGP peer and remove-private-AS is set. */
  895. if (peer->sort == BGP_PEER_EBGP
  896. && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
  897. && aspath_private_as_check (attr->aspath))
  898. attr->aspath = aspath_empty_get ();
  899. /* Route map & unsuppress-map apply. */
  900. if (ROUTE_MAP_OUT_NAME (filter)
  901. || (ri->extra && ri->extra->suppress) )
  902. {
  903. struct bgp_info info;
  904. struct attr dummy_attr;
  905. struct attr_extra dummy_extra;
  906. dummy_attr.extra = &dummy_extra;
  907. info.peer = peer;
  908. info.attr = attr;
  909. /* The route reflector is not allowed to modify the attributes
  910. of the reflected IBGP routes. */
  911. if (from->sort == BGP_PEER_IBGP
  912. && peer->sort == BGP_PEER_IBGP)
  913. {
  914. bgp_attr_dup (&dummy_attr, attr);
  915. info.attr = &dummy_attr;
  916. }
  917. SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
  918. if (ri->extra && ri->extra->suppress)
  919. ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
  920. else
  921. ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
  922. peer->rmap_type = 0;
  923. if (ret == RMAP_DENYMATCH)
  924. {
  925. bgp_attr_flush (attr);
  926. return 0;
  927. }
  928. }
  929. return 1;
  930. }
  931. static int
  932. bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
  933. struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
  934. {
  935. int ret;
  936. char buf[SU_ADDRSTRLEN];
  937. struct bgp_filter *filter;
  938. struct bgp_info info;
  939. struct peer *from;
  940. struct attr *riattr;
  941. from = ri->peer;
  942. filter = &rsclient->filter[afi][safi];
  943. riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
  944. if (DISABLE_BGP_ANNOUNCE)
  945. return 0;
  946. /* Do not send back route to sender. */
  947. if (from == rsclient)
  948. return 0;
  949. /* Aggregate-address suppress check. */
  950. if (ri->extra && ri->extra->suppress)
  951. if (! UNSUPPRESS_MAP_NAME (filter))
  952. return 0;
  953. /* Default route check. */
  954. if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
  955. PEER_STATUS_DEFAULT_ORIGINATE))
  956. {
  957. if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
  958. return 0;
  959. #ifdef HAVE_IPV6
  960. else if (p->family == AF_INET6 && p->prefixlen == 0)
  961. return 0;
  962. #endif /* HAVE_IPV6 */
  963. }
  964. /* If the attribute has originator-id and it is same as remote
  965. peer's id. */
  966. if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
  967. {
  968. if (IPV4_ADDR_SAME (&rsclient->remote_id,
  969. &riattr->extra->originator_id))
  970. {
  971. if (BGP_DEBUG (filter, FILTER))
  972. zlog (rsclient->log, LOG_DEBUG,
  973. "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
  974. rsclient->host,
  975. inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  976. p->prefixlen);
  977. return 0;
  978. }
  979. }
  980. /* ORF prefix-list filter check */
  981. if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
  982. && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
  983. || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
  984. if (rsclient->orf_plist[afi][safi])
  985. {
  986. if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
  987. return 0;
  988. }
  989. /* Output filter check. */
  990. if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
  991. {
  992. if (BGP_DEBUG (filter, FILTER))
  993. zlog (rsclient->log, LOG_DEBUG,
  994. "%s [Update:SEND] %s/%d is filtered",
  995. rsclient->host,
  996. inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  997. p->prefixlen);
  998. return 0;
  999. }
  1000. #ifdef BGP_SEND_ASPATH_CHECK
  1001. /* AS path loop check. */
  1002. if (aspath_loop_check (riattr->aspath, rsclient->as))
  1003. {
  1004. if (BGP_DEBUG (filter, FILTER))
  1005. zlog (rsclient->log, LOG_DEBUG,
  1006. "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
  1007. rsclient->host, rsclient->as);
  1008. return 0;
  1009. }
  1010. #endif /* BGP_SEND_ASPATH_CHECK */
  1011. /* For modify attribute, copy it to temporary structure. */
  1012. bgp_attr_dup (attr, riattr);
  1013. /* next-hop-set */
  1014. if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
  1015. #ifdef HAVE_IPV6
  1016. || (p->family == AF_INET6 &&
  1017. IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
  1018. #endif /* HAVE_IPV6 */
  1019. )
  1020. {
  1021. /* Set IPv4 nexthop. */
  1022. if (p->family == AF_INET)
  1023. {
  1024. if (safi == SAFI_MPLS_VPN)
  1025. memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
  1026. IPV4_MAX_BYTELEN);
  1027. else
  1028. memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
  1029. }
  1030. #ifdef HAVE_IPV6
  1031. /* Set IPv6 nexthop. */
  1032. if (p->family == AF_INET6)
  1033. {
  1034. /* IPv6 global nexthop must be included. */
  1035. memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
  1036. IPV6_MAX_BYTELEN);
  1037. attr->extra->mp_nexthop_len = 16;
  1038. }
  1039. #endif /* HAVE_IPV6 */
  1040. }
  1041. #ifdef HAVE_IPV6
  1042. if (p->family == AF_INET6)
  1043. {
  1044. struct attr_extra *attre = attr->extra;
  1045. /* Left nexthop_local unchanged if so configured. */
  1046. if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
  1047. PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
  1048. {
  1049. if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
  1050. attre->mp_nexthop_len=32;
  1051. else
  1052. attre->mp_nexthop_len=16;
  1053. }
  1054. /* Default nexthop_local treatment for RS-Clients */
  1055. else
  1056. {
  1057. /* Announcer and RS-Client are both in the same network */
  1058. if (rsclient->shared_network && from->shared_network &&
  1059. (rsclient->ifindex == from->ifindex))
  1060. {
  1061. if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
  1062. attre->mp_nexthop_len=32;
  1063. else
  1064. attre->mp_nexthop_len=16;
  1065. }
  1066. /* Set link-local address for shared network peer. */
  1067. else if (rsclient->shared_network
  1068. && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
  1069. {
  1070. memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
  1071. IPV6_MAX_BYTELEN);
  1072. attre->mp_nexthop_len = 32;
  1073. }
  1074. else
  1075. attre->mp_nexthop_len = 16;
  1076. }
  1077. }
  1078. #endif /* HAVE_IPV6 */
  1079. /* If this is EBGP peer and remove-private-AS is set. */
  1080. if (rsclient->sort == BGP_PEER_EBGP
  1081. && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
  1082. && aspath_private_as_check (attr->aspath))
  1083. attr->aspath = aspath_empty_get ();
  1084. /* Route map & unsuppress-map apply. */
  1085. if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
  1086. {
  1087. info.peer = rsclient;
  1088. info.attr = attr;
  1089. SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
  1090. if (ri->extra && ri->extra->suppress)
  1091. ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
  1092. else
  1093. ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
  1094. rsclient->rmap_type = 0;
  1095. if (ret == RMAP_DENYMATCH)
  1096. {
  1097. bgp_attr_flush (attr);
  1098. return 0;
  1099. }
  1100. }
  1101. return 1;
  1102. }
  1103. struct bgp_info_pair
  1104. {
  1105. struct bgp_info *old;
  1106. struct bgp_info *new;
  1107. };
  1108. static void
  1109. bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
  1110. struct bgp_maxpaths_cfg *mpath_cfg,
  1111. struct bgp_info_pair *result)
  1112. {
  1113. struct bgp_info *new_select;
  1114. struct bgp_info *old_select;
  1115. struct bgp_info *ri;
  1116. struct bgp_info *ri1;
  1117. struct bgp_info *ri2;
  1118. struct bgp_info *nextri = NULL;
  1119. int paths_eq, do_mpath;
  1120. struct list mp_list;
  1121. bgp_mp_list_init (&mp_list);
  1122. do_mpath = (mpath_cfg->maxpaths_ebgp != BGP_DEFAULT_MAXPATHS ||
  1123. mpath_cfg->maxpaths_ibgp != BGP_DEFAULT_MAXPATHS);
  1124. /* bgp deterministic-med */
  1125. new_select = NULL;
  1126. if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
  1127. for (ri1 = rn->info; ri1; ri1 = ri1->next)
  1128. {
  1129. if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
  1130. continue;
  1131. if (BGP_INFO_HOLDDOWN (ri1))
  1132. continue;
  1133. new_select = ri1;
  1134. if (do_mpath)
  1135. bgp_mp_list_add (&mp_list, ri1);
  1136. old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
  1137. if (ri1->next)
  1138. for (ri2 = ri1->next; ri2; ri2 = ri2->next)
  1139. {
  1140. if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
  1141. continue;
  1142. if (BGP_INFO_HOLDDOWN (ri2))
  1143. continue;
  1144. if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
  1145. || aspath_cmp_left_confed (ri1->attr->aspath,
  1146. ri2->attr->aspath))
  1147. {
  1148. if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
  1149. old_select = ri2;
  1150. if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq))
  1151. {
  1152. bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
  1153. new_select = ri2;
  1154. if (do_mpath && !paths_eq)
  1155. {
  1156. bgp_mp_list_clear (&mp_list);
  1157. bgp_mp_list_add (&mp_list, ri2);
  1158. }
  1159. }
  1160. if (do_mpath && paths_eq)
  1161. bgp_mp_list_add (&mp_list, ri2);
  1162. bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
  1163. }
  1164. }
  1165. bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
  1166. bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
  1167. bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
  1168. bgp_mp_list_clear (&mp_list);
  1169. }
  1170. /* Check old selected route and new selected route. */
  1171. old_select = NULL;
  1172. new_select = NULL;
  1173. for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
  1174. {
  1175. if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
  1176. old_select = ri;
  1177. if (BGP_INFO_HOLDDOWN (ri))
  1178. {
  1179. /* reap REMOVED routes, if needs be
  1180. * selected route must stay for a while longer though
  1181. */
  1182. if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
  1183. && (ri != old_select))
  1184. bgp_info_reap (rn, ri);
  1185. continue;
  1186. }
  1187. if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
  1188. && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
  1189. {
  1190. bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
  1191. continue;
  1192. }
  1193. bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
  1194. bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
  1195. if (bgp_info_cmp (bgp, ri, new_select, &paths_eq))
  1196. {
  1197. if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
  1198. bgp_mp_dmed_deselect (new_select);
  1199. new_select = ri;
  1200. if (do_mpath && !paths_eq)
  1201. {
  1202. bgp_mp_list_clear (&mp_list);
  1203. bgp_mp_list_add (&mp_list, ri);
  1204. }
  1205. }
  1206. else if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
  1207. bgp_mp_dmed_deselect (ri);
  1208. if (do_mpath && paths_eq)
  1209. bgp_mp_list_add (&mp_list, ri);
  1210. }
  1211. if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
  1212. bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
  1213. bgp_info_mpath_aggregate_update (new_select, old_select);
  1214. bgp_mp_list_clear (&mp_list);
  1215. result->old = old_select;
  1216. result->new = new_select;
  1217. return;
  1218. }
  1219. static int
  1220. bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
  1221. struct bgp_node *rn, afi_t afi, safi_t safi)
  1222. {
  1223. struct prefix *p;
  1224. struct attr attr;
  1225. struct attr_extra extra;
  1226. p = &rn->p;
  1227. /* Announce route to Established peer. */
  1228. if (peer->status != Established)
  1229. return 0;
  1230. /* Address family configuration check. */
  1231. if (! peer->afc_nego[afi][safi])
  1232. return 0;
  1233. /* First update is deferred until ORF or ROUTE-REFRESH is received */
  1234. if (CHECK_FLAG (peer->af_sflags[afi][safi],
  1235. PEER_STATUS_ORF_WAIT_REFRESH))
  1236. return 0;
  1237. /* It's initialized in bgp_announce_[check|check_rsclient]() */
  1238. attr.extra = &extra;
  1239. switch (bgp_node_table (rn)->type)
  1240. {
  1241. case BGP_TABLE_MAIN:
  1242. /* Announcement to peer->conf. If the route is filtered,
  1243. withdraw it. */
  1244. if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
  1245. bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
  1246. else
  1247. bgp_adj_out_unset (rn, peer, p, afi, safi);
  1248. break;
  1249. case BGP_TABLE_RSCLIENT:
  1250. /* Announcement to peer->conf. If the route is filtered,
  1251. withdraw it. */
  1252. if (selected &&
  1253. bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
  1254. bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
  1255. else
  1256. bgp_adj_out_unset (rn, peer, p, afi, safi);
  1257. break;
  1258. }
  1259. return 0;
  1260. }
  1261. struct bgp_process_queue
  1262. {
  1263. struct bgp *bgp;
  1264. struct bgp_node *rn;
  1265. afi_t afi;
  1266. safi_t safi;
  1267. };
  1268. static wq_item_status
  1269. bgp_process_rsclient (struct work_queue *wq, void *data)
  1270. {
  1271. struct bgp_process_queue *pq = data;
  1272. struct bgp *bgp = pq->bgp;
  1273. struct bgp_node *rn = pq->rn;
  1274. afi_t afi = pq->afi;
  1275. safi_t safi = pq->safi;
  1276. struct bgp_info *new_select;
  1277. struct bgp_info *old_select;
  1278. struct bgp_info_pair old_and_new;
  1279. struct listnode *node, *nnode;
  1280. struct peer *rsclient = bgp_node_table (rn)->owner;
  1281. /* Best path selection. */
  1282. bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
  1283. new_select = old_and_new.new;
  1284. old_select = old_and_new.old;
  1285. if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
  1286. {
  1287. if (rsclient->group)
  1288. for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
  1289. {
  1290. /* Nothing to do. */
  1291. if (old_select && old_select == new_select)
  1292. if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
  1293. continue;
  1294. if (old_select)
  1295. bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
  1296. if (new_select)
  1297. {
  1298. bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
  1299. bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
  1300. UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
  1301. }
  1302. bgp_process_announce_selected (rsclient, new_select, rn,
  1303. afi, safi);
  1304. }
  1305. }
  1306. else
  1307. {
  1308. if (old_select)
  1309. bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
  1310. if (new_select)
  1311. {
  1312. bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
  1313. bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
  1314. UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
  1315. }
  1316. bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
  1317. }
  1318. if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
  1319. bgp_info_reap (rn, old_select);
  1320. UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
  1321. return WQ_SUCCESS;
  1322. }
  1323. static wq_item_status
  1324. bgp_process_main (struct work_queue *wq, void *data)
  1325. {
  1326. struct bgp_process_queue *pq = data;
  1327. struct bgp *bgp = pq->bgp;
  1328. struct bgp_node *rn = pq->rn;
  1329. afi_t afi = pq->afi;
  1330. safi_t safi = pq->safi;
  1331. struct prefix *p = &rn->p;
  1332. struct bgp_info *new_select;
  1333. struct bgp_info *old_select;
  1334. struct bgp_info_pair old_and_new;
  1335. struct listnode *node, *nnode;
  1336. struct peer *peer;
  1337. /* Best path selection. */
  1338. bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
  1339. old_select = old_and_new.old;
  1340. new_select = old_and_new.new;
  1341. /* Nothing to do. */
  1342. if (old_select && old_select == new_select)
  1343. {
  1344. if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
  1345. {
  1346. if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
  1347. CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
  1348. bgp_zebra_announce (p, old_select, bgp, safi);
  1349. UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
  1350. UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
  1351. return WQ_SUCCESS;
  1352. }
  1353. }
  1354. if (old_select)
  1355. bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
  1356. if (new_select)
  1357. {
  1358. bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
  1359. bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
  1360. UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
  1361. }
  1362. /* Check each BGP peer. */
  1363. for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
  1364. {
  1365. bgp_process_announce_selected (peer, new_select, rn, afi, safi);
  1366. }
  1367. /* FIB update. */
  1368. if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
  1369. ! bgp_option_check (BGP_OPT_NO_FIB)))
  1370. {
  1371. if (new_select
  1372. && new_select->type == ZEBRA_ROUTE_BGP
  1373. && new_select->sub_type == BGP_ROUTE_NORMAL)
  1374. bgp_zebra_announce (p, new_select, bgp, safi);
  1375. else
  1376. {
  1377. /* Withdraw the route from the kernel. */
  1378. if (old_select
  1379. && old_select->type == ZEBRA_ROUTE_BGP
  1380. && old_select->sub_type == BGP_ROUTE_NORMAL)
  1381. bgp_zebra_withdraw (p, old_select, safi);
  1382. }
  1383. }
  1384. /* Reap old select bgp_info, it it has been removed */
  1385. if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
  1386. bgp_info_reap (rn, old_select);
  1387. UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
  1388. return WQ_SUCCESS;
  1389. }
  1390. static void
  1391. bgp_processq_del (struct work_queue *wq, void *data)
  1392. {
  1393. struct bgp_process_queue *pq = data;
  1394. struct bgp_table *table = bgp_node_table (pq->rn);
  1395. bgp_unlock (pq->bgp);
  1396. bgp_unlock_node (pq->rn);
  1397. bgp_table_unlock (table);
  1398. XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
  1399. }
  1400. static void
  1401. bgp_process_queue_init (void)
  1402. {
  1403. bm->process_main_queue
  1404. = work_queue_new (bm->master, "process_main_queue");
  1405. bm->process_rsclient_queue
  1406. = work_queue_new (bm->master, "process_rsclient_queue");
  1407. if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
  1408. {
  1409. zlog_err ("%s: Failed to allocate work queue", __func__);
  1410. exit (1);
  1411. }
  1412. bm->process_main_queue->spec.workfunc = &bgp_process_main;
  1413. bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
  1414. bm->process_main_queue->spec.max_retries = 0;
  1415. bm->process_main_queue->spec.hold = 50;
  1416. memcpy (bm->process_rsclient_queue, bm->process_main_queue,
  1417. sizeof (struct work_queue *));
  1418. bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
  1419. }
  1420. void
  1421. bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
  1422. {
  1423. struct bgp_process_queue *pqnode;
  1424. /* already scheduled for processing? */
  1425. if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
  1426. return;
  1427. if ( (bm->process_main_queue == NULL) ||
  1428. (bm->process_rsclient_queue == NULL) )
  1429. bgp_process_queue_init ();
  1430. pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
  1431. sizeof (struct bgp_process_queue));
  1432. if (!pqnode)
  1433. return;
  1434. /* all unlocked in bgp_processq_del */
  1435. bgp_table_lock (bgp_node_table (rn));
  1436. pqnode->rn = bgp_lock_node (rn);
  1437. pqnode->bgp = bgp;
  1438. bgp_lock (bgp);
  1439. pqnode->afi = afi;
  1440. pqnode->safi = safi;
  1441. switch (bgp_node_table (rn)->type)
  1442. {
  1443. case BGP_TABLE_MAIN:
  1444. work_queue_add (bm->process_main_queue, pqnode);
  1445. break;
  1446. case BGP_TABLE_RSCLIENT:
  1447. work_queue_add (bm->process_rsclient_queue, pqnode);
  1448. break;
  1449. }
  1450. SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
  1451. return;
  1452. }
  1453. static int
  1454. bgp_maximum_prefix_restart_timer (struct thread *thread)
  1455. {
  1456. struct peer *peer;
  1457. peer = THREAD_ARG (thread);
  1458. peer->t_pmax_restart = NULL;
  1459. if (BGP_DEBUG (events, EVENTS))
  1460. zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
  1461. peer->host);
  1462. peer_clear (peer);
  1463. return 0;
  1464. }
  1465. int
  1466. bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
  1467. safi_t safi, int always)
  1468. {
  1469. if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
  1470. return 0;
  1471. if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
  1472. {
  1473. if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
  1474. && ! always)
  1475. return 0;
  1476. zlog (peer->log, LOG_INFO,
  1477. "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
  1478. "limit %ld", afi_safi_print (afi, safi), peer->host,
  1479. peer->pcount[afi][safi], peer->pmax[afi][safi]);
  1480. SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
  1481. if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
  1482. return 0;
  1483. {
  1484. u_int8_t ndata[7];
  1485. if (safi == SAFI_MPLS_VPN)
  1486. safi = SAFI_MPLS_LABELED_VPN;
  1487. ndata[0] = (afi >> 8);
  1488. ndata[1] = afi;
  1489. ndata[2] = safi;
  1490. ndata[3] = (peer->pmax[afi][safi] >> 24);
  1491. ndata[4] = (peer->pmax[afi][safi] >> 16);
  1492. ndata[5] = (peer->pmax[afi][safi] >> 8);
  1493. ndata[6] = (peer->pmax[afi][safi]);
  1494. SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
  1495. bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
  1496. BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
  1497. }
  1498. /* restart timer start */
  1499. if (peer->pmax_restart[afi][safi])
  1500. {
  1501. peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
  1502. if (BGP_DEBUG (events, EVENTS))
  1503. zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
  1504. peer->host, peer->v_pmax_restart);
  1505. BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
  1506. peer->v_pmax_restart);
  1507. }
  1508. return 1;
  1509. }
  1510. else
  1511. UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
  1512. if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
  1513. {
  1514. if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
  1515. && ! always)
  1516. return 0;
  1517. zlog (peer->log, LOG_INFO,
  1518. "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
  1519. afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
  1520. peer->pmax[afi][safi]);
  1521. SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
  1522. }
  1523. else
  1524. UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
  1525. return 0;
  1526. }
  1527. /* Unconditionally remove the route from the RIB, without taking
  1528. * damping into consideration (eg, because the session went down)
  1529. */
  1530. static void
  1531. bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
  1532. afi_t afi, safi_t safi)
  1533. {
  1534. bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
  1535. if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
  1536. bgp_info_delete (rn, ri); /* keep historical info */
  1537. bgp_process (peer->bgp, rn, afi, safi);
  1538. }
  1539. static void
  1540. bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
  1541. afi_t afi, safi_t safi)
  1542. {
  1543. int status = BGP_DAMP_NONE;
  1544. /* apply dampening, if result is suppressed, we'll be retaining
  1545. * the bgp_info in the RIB for historical reference.
  1546. */
  1547. if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
  1548. && peer->sort == BGP_PEER_EBGP)
  1549. if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
  1550. == BGP_DAMP_SUPPRESSED)
  1551. {
  1552. bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
  1553. return;
  1554. }
  1555. bgp_rib_remove (rn, ri, peer, afi, safi);
  1556. }
  1557. static void
  1558. bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
  1559. struct attr *attr, struct peer *peer, struct prefix *p, int type,
  1560. int sub_type, struct prefix_rd *prd, u_char *tag)
  1561. {
  1562. struct bgp_node *rn;
  1563. struct bgp *bgp;
  1564. struct attr new_attr;
  1565. struct attr_extra new_extra;
  1566. struct attr *attr_new;
  1567. struct attr *attr_new2;
  1568. struct bgp_info *ri;
  1569. struct bgp_info *new;
  1570. const char *reason;
  1571. char buf[SU_ADDRSTRLEN];
  1572. /* Do not insert announces from a rsclient into its own 'bgp_table'. */
  1573. if (peer == rsclient)
  1574. return;
  1575. bgp = peer->bgp;
  1576. rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
  1577. /* Check previously received route. */
  1578. for (ri = rn->info; ri; ri = ri->next)
  1579. if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
  1580. break;
  1581. /* AS path loop check. */
  1582. if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
  1583. {
  1584. reason = "as-path contains our own AS;";
  1585. goto filtered;
  1586. }
  1587. /* Route reflector originator ID check. */
  1588. if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
  1589. && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
  1590. {
  1591. reason = "originator is us;";
  1592. goto filtered;
  1593. }
  1594. new_attr.extra = &new_extra;
  1595. bgp_attr_dup (&new_attr, attr);
  1596. /* Apply export policy. */
  1597. if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
  1598. bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
  1599. {
  1600. reason = "export-policy;";
  1601. goto filtered;
  1602. }
  1603. attr_new2 = bgp_attr_intern (&new_attr);
  1604. /* Apply import policy. */
  1605. if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
  1606. {
  1607. bgp_attr_unintern (&attr_new2);
  1608. reason = "import-policy;";
  1609. goto filtered;
  1610. }
  1611. attr_new = bgp_attr_intern (&new_attr);
  1612. bgp_attr_unintern (&attr_new2);
  1613. /* IPv4 unicast next hop check. */
  1614. if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
  1615. {
  1616. /* Next hop must not be 0.0.0.0 nor Class D/E address. */
  1617. if (new_attr.nexthop.s_addr == 0
  1618. || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
  1619. {
  1620. bgp_attr_unintern (&attr_new);
  1621. reason = "martian next-hop;";
  1622. goto filtered;
  1623. }
  1624. }
  1625. /* If the update is implicit withdraw. */
  1626. if (ri)
  1627. {
  1628. ri->uptime = bgp_clock ();
  1629. /* Same attribute comes in. */
  1630. if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
  1631. && attrhash_cmp (ri->attr, attr_new))
  1632. {
  1633. bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
  1634. if (BGP_DEBUG (update, UPDATE_IN))
  1635. zlog (peer->log, LOG_DEBUG,
  1636. "%s rcvd %s/%d for RS-client %s...duplicate ignored",
  1637. peer->host,
  1638. inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  1639. p->prefixlen, rsclient->host);
  1640. bgp_unlock_node (rn);
  1641. bgp_attr_unintern (&attr_new);
  1642. return;
  1643. }
  1644. /* Withdraw/Announce before we fully processed the withdraw */
  1645. if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
  1646. bgp_info_restore (rn, ri);
  1647. /* Received Logging. */
  1648. if (BGP_DEBUG (update, UPDATE_IN))
  1649. zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
  1650. peer->host,
  1651. inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  1652. p->prefixlen, rsclient->host);
  1653. /* The attribute is changed. */
  1654. bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
  1655. /* Update to new attribute. */
  1656. bgp_attr_unintern (&ri->attr);
  1657. ri->attr = attr_new;
  1658. /* Update MPLS tag. */
  1659. if (safi == SAFI_MPLS_VPN)
  1660. memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
  1661. bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
  1662. /* Process change. */
  1663. bgp_process (bgp, rn, afi, safi);
  1664. bgp_unlock_node (rn);
  1665. return;
  1666. }
  1667. /* Received Logging. */
  1668. if (BGP_DEBUG (update, UPDATE_IN))
  1669. {
  1670. zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
  1671. peer->host,
  1672. inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  1673. p->prefixlen, rsclient->host);
  1674. }
  1675. /* Make new BGP info. */
  1676. new = bgp_info_new ();
  1677. new->type = type;
  1678. new->sub_type = sub_type;
  1679. new->peer = peer;
  1680. new->attr = attr_new;
  1681. new->uptime = bgp_clock ();
  1682. /* Update MPLS tag. */
  1683. if (safi == SAFI_MPLS_VPN)
  1684. memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
  1685. bgp_info_set_flag (rn, new, BGP_INFO_VALID);
  1686. /* Register new BGP information. */
  1687. bgp_info_add (rn, new);
  1688. /* route_node_get lock */
  1689. bgp_unlock_node (rn);
  1690. /* Process change. */
  1691. bgp_process (bgp, rn, afi, safi);
  1692. return;
  1693. filtered:
  1694. /* This BGP update is filtered. Log the reason then update BGP entry. */
  1695. if (BGP_DEBUG (update, UPDATE_IN))
  1696. zlog (peer->log, LOG_DEBUG,
  1697. "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
  1698. peer->host,
  1699. inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  1700. p->prefixlen, rsclient->host, reason);
  1701. if (ri)
  1702. bgp_rib_remove (rn, ri, peer, afi, safi);
  1703. bgp_unlock_node (rn);
  1704. return;
  1705. }
  1706. static void
  1707. bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
  1708. struct peer *peer, struct prefix *p, int type, int sub_type,
  1709. struct prefix_rd *prd, u_char *tag)
  1710. {
  1711. struct bgp_node *rn;
  1712. struct bgp_info *ri;
  1713. char buf[SU_ADDRSTRLEN];
  1714. if (rsclient == peer)
  1715. return;
  1716. rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
  1717. /* Lookup withdrawn route. */
  1718. for (ri = rn->info; ri; ri = ri->next)
  1719. if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
  1720. break;
  1721. /* Withdraw specified route from routing table. */
  1722. if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
  1723. bgp_rib_withdraw (rn, ri, peer, afi, safi);
  1724. else if (BGP_DEBUG (update, UPDATE_IN))
  1725. zlog (peer->log, LOG_DEBUG,
  1726. "%s Can't find the route %s/%d", peer->host,
  1727. inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  1728. p->prefixlen);
  1729. /* Unlock bgp_node_get() lock. */
  1730. bgp_unlock_node (rn);
  1731. }
  1732. static int
  1733. bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
  1734. afi_t afi, safi_t safi, int type, int sub_type,
  1735. struct prefix_rd *prd, u_char *tag, int soft_reconfig)
  1736. {
  1737. int ret;
  1738. int aspath_loop_count = 0;
  1739. struct bgp_node *rn;
  1740. struct bgp *bgp;
  1741. struct attr new_attr;
  1742. struct attr_extra new_extra;
  1743. struct attr *attr_new;
  1744. struct bgp_info *ri;
  1745. struct bgp_info *new;
  1746. const char *reason;
  1747. char buf[SU_ADDRSTRLEN];
  1748. bgp = peer->bgp;
  1749. rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
  1750. /* When peer's soft reconfiguration enabled. Record input packet in
  1751. Adj-RIBs-In. */
  1752. if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
  1753. && peer != bgp->peer_self)
  1754. bgp_adj_in_set (rn, peer, attr);
  1755. /* Check previously received route. */
  1756. for (ri = rn->info; ri; ri = ri->next)
  1757. if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
  1758. break;
  1759. /* AS path local-as loop check. */
  1760. if (peer->change_local_as)
  1761. {
  1762. if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
  1763. aspath_loop_count = 1;
  1764. if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
  1765. {
  1766. reason = "as-path contains our own AS;";
  1767. goto filtered;
  1768. }
  1769. }
  1770. /* AS path loop check. */
  1771. if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
  1772. || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
  1773. && aspath_loop_check(attr->aspath, bgp->confed_id)
  1774. > peer->allowas_in[afi][safi]))
  1775. {
  1776. reason = "as-path contains our own AS;";
  1777. goto filtered;
  1778. }
  1779. /* Route reflector originator ID check. */
  1780. if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
  1781. && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
  1782. {
  1783. reason = "originator is us;";
  1784. goto filtered;
  1785. }
  1786. /* Route reflector cluster ID check. */
  1787. if (bgp_cluster_filter (peer, attr))
  1788. {
  1789. reason = "reflected from the same cluster;";
  1790. goto filtered;
  1791. }
  1792. /* Apply incoming filter. */
  1793. if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
  1794. {
  1795. reason = "filter;";
  1796. goto filtered;
  1797. }
  1798. new_attr.extra = &new_extra;
  1799. bgp_attr_dup (&new_attr, attr);
  1800. /* Apply incoming route-map. */
  1801. if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
  1802. {
  1803. reason = "route-map;";
  1804. goto filtered;
  1805. }
  1806. /* IPv4 unicast next hop check. */
  1807. if (afi == AFI_IP && safi == SAFI_UNICAST)
  1808. {
  1809. /* If the peer is EBGP and nexthop is not on connected route,
  1810. discard it. */
  1811. if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1
  1812. && ! bgp_nexthop_onlink (afi, &new_attr)
  1813. && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
  1814. {
  1815. reason = "non-connected next-hop;";
  1816. goto filtered;
  1817. }
  1818. /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
  1819. must not be my own address. */
  1820. if (new_attr.nexthop.s_addr == 0
  1821. || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
  1822. || bgp_nexthop_self (&new_attr))
  1823. {
  1824. reason = "martian next-hop;";
  1825. goto filtered;
  1826. }
  1827. }
  1828. attr_new = bgp_attr_intern (&new_attr);
  1829. /* If the update is implicit withdraw. */
  1830. if (ri)
  1831. {
  1832. ri->uptime = bgp_clock ();
  1833. /* Same attribute comes in. */
  1834. if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
  1835. && attrhash_cmp (ri->attr, attr_new))
  1836. {
  1837. bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
  1838. if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
  1839. && peer->sort == BGP_PEER_EBGP
  1840. && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
  1841. {
  1842. if (BGP_DEBUG (update, UPDATE_IN))
  1843. zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
  1844. peer->host,
  1845. inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  1846. p->prefixlen);
  1847. if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
  1848. {
  1849. bgp_aggregate_increment (bgp, p, ri, afi, safi);
  1850. bgp_process (bgp, rn, afi, safi);
  1851. }
  1852. }
  1853. else /* Duplicate - odd */
  1854. {
  1855. if (BGP_DEBUG (update, UPDATE_IN))
  1856. zlog (peer->log, LOG_DEBUG,
  1857. "%s rcvd %s/%d...duplicate ignored",
  1858. peer->host,
  1859. inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  1860. p->prefixlen);
  1861. /* graceful restart STALE flag unset. */
  1862. if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
  1863. {
  1864. bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
  1865. bgp_process (bgp, rn, afi, safi);
  1866. }
  1867. }
  1868. bgp_unlock_node (rn);
  1869. bgp_attr_unintern (&attr_new);
  1870. return 0;
  1871. }
  1872. /* Withdraw/Announce before we fully processed the withdraw */
  1873. if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
  1874. {
  1875. if (BGP_DEBUG (update, UPDATE_IN))
  1876. zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
  1877. peer->host,
  1878. inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  1879. p->prefixlen);
  1880. bgp_info_restore (rn, ri);
  1881. }
  1882. /* Received Logging. */
  1883. if (BGP_DEBUG (update, UPDATE_IN))
  1884. zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
  1885. peer->host,
  1886. inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  1887. p->prefixlen);
  1888. /* graceful restart STALE flag unset. */
  1889. if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
  1890. bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
  1891. /* The attribute is changed. */
  1892. bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
  1893. /* implicit withdraw, decrement aggregate and pcount here.
  1894. * only if update is accepted, they'll increment below.
  1895. */
  1896. bgp_aggregate_decrement (bgp, p, ri, afi, safi);
  1897. /* Update bgp route dampening information. */
  1898. if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
  1899. && peer->sort == BGP_PEER_EBGP)
  1900. {
  1901. /* This is implicit withdraw so we should update dampening
  1902. information. */
  1903. if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
  1904. bgp_damp_withdraw (ri, rn, afi, safi, 1);
  1905. }
  1906. /* Update to new attribute. */
  1907. bgp_attr_unintern (&ri->attr);
  1908. ri->attr = attr_new;
  1909. /* Update MPLS tag. */
  1910. if (safi == SAFI_MPLS_VPN)
  1911. memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
  1912. /* Update bgp route dampening information. */
  1913. if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
  1914. && peer->sort == BGP_PEER_EBGP)
  1915. {
  1916. /* Now we do normal update dampening. */
  1917. ret = bgp_damp_update (ri, rn, afi, safi);
  1918. if (ret == BGP_DAMP_SUPPRESSED)
  1919. {
  1920. bgp_unlock_node (rn);
  1921. return 0;
  1922. }
  1923. }
  1924. /* Nexthop reachability check. */
  1925. if ((afi == AFI_IP || afi == AFI_IP6)
  1926. && safi == SAFI_UNICAST
  1927. && (peer->sort == BGP_PEER_IBGP
  1928. || peer->sort == BGP_PEER_CONFED
  1929. || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
  1930. || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
  1931. {
  1932. if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
  1933. bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
  1934. else
  1935. bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
  1936. }
  1937. else
  1938. bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
  1939. /* Process change. */
  1940. bgp_aggregate_increment (bgp, p, ri, afi, safi);
  1941. bgp_process (bgp, rn, afi, safi);
  1942. bgp_unlock_node (rn);
  1943. return 0;
  1944. }
  1945. /* Received Logging. */
  1946. if (BGP_DEBUG (update, UPDATE_IN))
  1947. {
  1948. zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
  1949. peer->host,
  1950. inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  1951. p->prefixlen);
  1952. }
  1953. /* Make new BGP info. */
  1954. new = bgp_info_new ();
  1955. new->type = type;
  1956. new->sub_type = sub_type;
  1957. new->peer = peer;
  1958. new->attr = attr_new;
  1959. new->uptime = bgp_clock ();
  1960. /* Update MPLS tag. */
  1961. if (safi == SAFI_MPLS_VPN)
  1962. memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
  1963. /* Nexthop reachability check. */
  1964. if ((afi == AFI_IP || afi == AFI_IP6)
  1965. && safi == SAFI_UNICAST
  1966. && (peer->sort == BGP_PEER_IBGP
  1967. || peer->sort == BGP_PEER_CONFED
  1968. || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
  1969. || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
  1970. {
  1971. if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
  1972. bgp_info_set_flag (rn, new, BGP_INFO_VALID);
  1973. else
  1974. bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
  1975. }
  1976. else
  1977. bgp_info_set_flag (rn, new, BGP_INFO_VALID);
  1978. /* Increment prefix */
  1979. bgp_aggregate_increment (bgp, p, new, afi, safi);
  1980. /* Register new BGP information. */
  1981. bgp_info_add (rn, new);
  1982. /* route_node_get lock */
  1983. bgp_unlock_node (rn);
  1984. /* If maximum prefix count is configured and current prefix
  1985. count exeed it. */
  1986. if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
  1987. return -1;
  1988. /* Process change. */
  1989. bgp_process (bgp, rn, afi, safi);
  1990. return 0;
  1991. /* This BGP update is filtered. Log the reason then update BGP
  1992. entry. */
  1993. filtered:
  1994. if (BGP_DEBUG (update, UPDATE_IN))
  1995. zlog (peer->log, LOG_DEBUG,
  1996. "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
  1997. peer->host,
  1998. inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  1999. p->prefixlen, reason);
  2000. if (ri)
  2001. bgp_rib_remove (rn, ri, peer, afi, safi);
  2002. bgp_unlock_node (rn);
  2003. return 0;
  2004. }
  2005. int
  2006. bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
  2007. afi_t afi, safi_t safi, int type, int sub_type,
  2008. struct prefix_rd *prd, u_char *tag, int soft_reconfig)
  2009. {
  2010. struct peer *rsclient;
  2011. struct listnode *node, *nnode;
  2012. struct bgp *bgp;
  2013. int ret;
  2014. ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
  2015. soft_reconfig);
  2016. bgp = peer->bgp;
  2017. /* Process the update for each RS-client. */
  2018. for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
  2019. {
  2020. if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
  2021. bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
  2022. sub_type, prd, tag);
  2023. }
  2024. return ret;
  2025. }
  2026. int
  2027. bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
  2028. afi_t afi, safi_t safi, int type, int sub_type,
  2029. struct prefix_rd *prd, u_char *tag)
  2030. {
  2031. struct bgp *bgp;
  2032. char buf[SU_ADDRSTRLEN];
  2033. struct bgp_node *rn;
  2034. struct bgp_info *ri;
  2035. struct peer *rsclient;
  2036. struct listnode *node, *nnode;
  2037. bgp = peer->bgp;
  2038. /* Process the withdraw for each RS-client. */
  2039. for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
  2040. {
  2041. if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
  2042. bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
  2043. }
  2044. /* Logging. */
  2045. if (BGP_DEBUG (update, UPDATE_IN))
  2046. zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
  2047. peer->host,
  2048. inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  2049. p->prefixlen);
  2050. /* Lookup node. */
  2051. rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
  2052. /* If peer is soft reconfiguration enabled. Record input packet for
  2053. further calculation. */
  2054. if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
  2055. && peer != bgp->peer_self)
  2056. bgp_adj_in_unset (rn, peer);
  2057. /* Lookup withdrawn route. */
  2058. for (ri = rn->info; ri; ri = ri->next)
  2059. if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
  2060. break;
  2061. /* Withdraw specified route from routing table. */
  2062. if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
  2063. bgp_rib_withdraw (rn, ri, peer, afi, safi);
  2064. else if (BGP_DEBUG (update, UPDATE_IN))
  2065. zlog (peer->log, LOG_DEBUG,
  2066. "%s Can't find the route %s/%d", peer->host,
  2067. inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  2068. p->prefixlen);
  2069. /* Unlock bgp_node_get() lock. */
  2070. bgp_unlock_node (rn);
  2071. return 0;
  2072. }
  2073. void
  2074. bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
  2075. {
  2076. struct bgp *bgp;
  2077. struct attr attr;
  2078. struct aspath *aspath;
  2079. struct prefix p;
  2080. struct peer *from;
  2081. struct bgp_node *rn;
  2082. struct bgp_info *ri;
  2083. int ret = RMAP_DENYMATCH;
  2084. if (!(afi == AFI_IP || afi == AFI_IP6))
  2085. return;
  2086. bgp = peer->bgp;
  2087. from = bgp->peer_self;
  2088. bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
  2089. aspath = attr.aspath;
  2090. attr.local_pref = bgp->default_local_pref;
  2091. memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
  2092. if (afi == AFI_IP)
  2093. str2prefix ("0.0.0.0/0", &p);
  2094. #ifdef HAVE_IPV6
  2095. else if (afi == AFI_IP6)
  2096. {
  2097. struct attr_extra *ae = attr.extra;
  2098. str2prefix ("::/0", &p);
  2099. /* IPv6 global nexthop must be included. */
  2100. memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
  2101. IPV6_MAX_BYTELEN);
  2102. ae->mp_nexthop_len = 16;
  2103. /* If the peer is on shared nextwork and we have link-local
  2104. nexthop set it. */
  2105. if (peer->shared_network
  2106. && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
  2107. {
  2108. memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
  2109. IPV6_MAX_BYTELEN);
  2110. ae->mp_nexthop_len = 32;
  2111. }
  2112. }
  2113. #endif /* HAVE_IPV6 */
  2114. if (peer->default_rmap[afi][safi].name)
  2115. {
  2116. SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
  2117. for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
  2118. {
  2119. for (ri = rn->info; ri; ri = ri->next)
  2120. {
  2121. struct attr dummy_attr;
  2122. struct attr_extra dummy_extra;
  2123. struct bgp_info info;
  2124. /* Provide dummy so the route-map can't modify the attributes */
  2125. dummy_attr.extra = &dummy_extra;
  2126. bgp_attr_dup(&dummy_attr, ri->attr);
  2127. info.peer = ri->peer;
  2128. info.attr = &dummy_attr;
  2129. ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
  2130. RMAP_BGP, &info);
  2131. /* The route map might have set attributes. If we don't flush them
  2132. * here, they will be leaked. */
  2133. bgp_attr_flush(&dummy_attr);
  2134. if (ret != RMAP_DENYMATCH)
  2135. break;
  2136. }
  2137. if (ret != RMAP_DENYMATCH)
  2138. break;
  2139. }
  2140. bgp->peer_self->rmap_type = 0;
  2141. if (ret == RMAP_DENYMATCH)
  2142. withdraw = 1;
  2143. }
  2144. if (withdraw)
  2145. {
  2146. if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
  2147. bgp_default_withdraw_send (peer, afi, safi);
  2148. UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
  2149. }
  2150. else
  2151. {
  2152. if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
  2153. {
  2154. SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
  2155. bgp_default_update_send (peer, &attr, afi, safi, from);
  2156. }
  2157. }
  2158. bgp_attr_extra_free (&attr);
  2159. aspath_unintern (&aspath);
  2160. }
  2161. static void
  2162. bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
  2163. struct bgp_table *table, int rsclient)
  2164. {
  2165. struct bgp_node *rn;
  2166. struct bgp_info *ri;
  2167. struct attr attr;
  2168. struct attr_extra extra;
  2169. if (! table)
  2170. table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
  2171. if (safi != SAFI_MPLS_VPN
  2172. && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
  2173. bgp_default_originate (peer, afi, safi, 0);
  2174. /* It's initialized in bgp_announce_[check|check_rsclient]() */
  2175. attr.extra = &extra;
  2176. for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
  2177. for (ri = rn->info; ri; ri = ri->next)
  2178. if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
  2179. {
  2180. if ( (rsclient) ?
  2181. (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
  2182. : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
  2183. bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
  2184. else
  2185. bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
  2186. }
  2187. }
  2188. void
  2189. bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
  2190. {
  2191. struct bgp_node *rn;
  2192. struct bgp_table *table;
  2193. if (peer->status != Established)
  2194. return;
  2195. if (! peer->afc_nego[afi][safi])
  2196. return;
  2197. /* First update is deferred until ORF or ROUTE-REFRESH is received */
  2198. if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
  2199. return;
  2200. if (safi != SAFI_MPLS_VPN)
  2201. bgp_announce_table (peer, afi, safi, NULL, 0);
  2202. else
  2203. for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
  2204. rn = bgp_route_next(rn))
  2205. if ((table = (rn->info)) != NULL)
  2206. bgp_announce_table (peer, afi, safi, table, 0);
  2207. if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
  2208. bgp_announce_table (peer, afi, safi, NULL, 1);
  2209. }
  2210. void
  2211. bgp_announce_route_all (struct peer *peer)
  2212. {
  2213. afi_t afi;
  2214. safi_t safi;
  2215. for (afi = AFI_IP; afi < AFI_MAX; afi++)
  2216. for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
  2217. bgp_announce_route (peer, afi, safi);
  2218. }
  2219. static void
  2220. bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
  2221. safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
  2222. {
  2223. struct bgp_node *rn;
  2224. struct bgp_adj_in *ain;
  2225. if (! table)
  2226. table = rsclient->bgp->rib[afi][safi];
  2227. for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
  2228. for (ain = rn->adj_in; ain; ain = ain->next)
  2229. {
  2230. struct bgp_info *ri = rn->info;
  2231. u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
  2232. bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
  2233. &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag);
  2234. }
  2235. }
  2236. void
  2237. bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
  2238. {
  2239. struct bgp_table *table;
  2240. struct bgp_node *rn;
  2241. if (safi != SAFI_MPLS_VPN)
  2242. bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
  2243. else
  2244. for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
  2245. rn = bgp_route_next (rn))
  2246. if ((table = rn->info) != NULL)
  2247. {
  2248. struct prefix_rd prd;
  2249. prd.family = AF_UNSPEC;
  2250. prd.prefixlen = 64;
  2251. memcpy(&prd.val, rn->p.u.val, 8);
  2252. bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
  2253. }
  2254. }
  2255. static void
  2256. bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
  2257. struct bgp_table *table, struct prefix_rd *prd)
  2258. {
  2259. int ret;
  2260. struct bgp_node *rn;
  2261. struct bgp_adj_in *ain;
  2262. if (! table)
  2263. table = peer->bgp->rib[afi][safi];
  2264. for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
  2265. for (ain = rn->adj_in; ain; ain = ain->next)
  2266. {
  2267. if (ain->peer == peer)
  2268. {
  2269. struct bgp_info *ri = rn->info;
  2270. u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
  2271. ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
  2272. ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
  2273. prd, tag, 1);
  2274. if (ret < 0)
  2275. {
  2276. bgp_unlock_node (rn);
  2277. return;
  2278. }
  2279. continue;
  2280. }
  2281. }
  2282. }
  2283. void
  2284. bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
  2285. {
  2286. struct bgp_node *rn;
  2287. struct bgp_table *table;
  2288. if (peer->status != Established)
  2289. return;
  2290. if (safi != SAFI_MPLS_VPN)
  2291. bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
  2292. else
  2293. for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
  2294. rn = bgp_route_next (rn))
  2295. if ((table = rn->info) != NULL)
  2296. {
  2297. struct prefix_rd prd;
  2298. prd.family = AF_UNSPEC;
  2299. prd.prefixlen = 64;
  2300. memcpy(&prd.val, rn->p.u.val, 8);
  2301. bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
  2302. }
  2303. }
  2304. struct bgp_clear_node_queue
  2305. {
  2306. struct bgp_node *rn;
  2307. enum bgp_clear_route_type purpose;
  2308. };
  2309. static wq_item_status
  2310. bgp_clear_route_node (struct work_queue *wq, void *data)
  2311. {
  2312. struct bgp_clear_node_queue *cnq = data;
  2313. struct bgp_node *rn = cnq->rn;
  2314. struct peer *peer = wq->spec.data;
  2315. struct bgp_info *ri;
  2316. afi_t afi = bgp_node_table (rn)->afi;
  2317. safi_t safi = bgp_node_table (rn)->safi;
  2318. assert (rn && peer);
  2319. for (ri = rn->info; ri; ri = ri->next)
  2320. if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
  2321. {
  2322. /* graceful restart STALE flag set. */
  2323. if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
  2324. && peer->nsf[afi][safi]
  2325. && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
  2326. && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
  2327. bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
  2328. else
  2329. bgp_rib_remove (rn, ri, peer, afi, safi);
  2330. break;
  2331. }
  2332. return WQ_SUCCESS;
  2333. }
  2334. static void
  2335. bgp_clear_node_queue_del (struct work_queue *wq, void *data)
  2336. {
  2337. struct bgp_clear_node_queue *cnq = data;
  2338. struct bgp_node *rn = cnq->rn;
  2339. struct bgp_table *table = bgp_node_table (rn);
  2340. bgp_unlock_node (rn);
  2341. bgp_table_unlock (table);
  2342. XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
  2343. }
  2344. static void
  2345. bgp_clear_node_complete (struct work_queue *wq)
  2346. {
  2347. struct peer *peer = wq->spec.data;
  2348. /* Tickle FSM to start moving again */
  2349. BGP_EVENT_ADD (peer, Clearing_Completed);
  2350. peer_unlock (peer); /* bgp_clear_route */
  2351. }
  2352. static void
  2353. bgp_clear_node_queue_init (struct peer *peer)
  2354. {
  2355. char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
  2356. snprintf (wname, sizeof(wname), "clear %s", peer->host);
  2357. #undef CLEAR_QUEUE_NAME_LEN
  2358. if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
  2359. {
  2360. zlog_err ("%s: Failed to allocate work queue", __func__);
  2361. exit (1);
  2362. }
  2363. peer->clear_node_queue->spec.hold = 10;
  2364. peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
  2365. peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
  2366. peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
  2367. peer->clear_node_queue->spec.max_retries = 0;
  2368. /* we only 'lock' this peer reference when the queue is actually active */
  2369. peer->clear_node_queue->spec.data = peer;
  2370. }
  2371. static void
  2372. bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
  2373. struct bgp_table *table, struct peer *rsclient,
  2374. enum bgp_clear_route_type purpose)
  2375. {
  2376. struct bgp_node *rn;
  2377. if (! table)
  2378. table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
  2379. /* If still no table => afi/safi isn't configured at all or smth. */
  2380. if (! table)
  2381. return;
  2382. for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
  2383. {
  2384. struct bgp_info *ri;
  2385. struct bgp_adj_in *ain;
  2386. struct bgp_adj_out *aout;
  2387. /* XXX:TODO: This is suboptimal, every non-empty route_node is
  2388. * queued for every clearing peer, regardless of whether it is
  2389. * relevant to the peer at hand.
  2390. *
  2391. * Overview: There are 3 different indices which need to be
  2392. * scrubbed, potentially, when a peer is removed:
  2393. *
  2394. * 1 peer's routes visible via the RIB (ie accepted routes)
  2395. * 2 peer's routes visible by the (optional) peer's adj-in index
  2396. * 3 other routes visible by the peer's adj-out index
  2397. *
  2398. * 3 there is no hurry in scrubbing, once the struct peer is
  2399. * removed from bgp->peer, we could just GC such deleted peer's
  2400. * adj-outs at our leisure.
  2401. *
  2402. * 1 and 2 must be 'scrubbed' in some way, at least made
  2403. * invisible via RIB index before peer session is allowed to be
  2404. * brought back up. So one needs to know when such a 'search' is
  2405. * complete.
  2406. *
  2407. * Ideally:
  2408. *
  2409. * - there'd be a single global queue or a single RIB walker
  2410. * - rather than tracking which route_nodes still need to be
  2411. * examined on a peer basis, we'd track which peers still
  2412. * aren't cleared
  2413. *
  2414. * Given that our per-peer prefix-counts now should be reliable,
  2415. * this may actually be achievable. It doesn't seem to be a huge
  2416. * problem at this time,
  2417. */
  2418. for (ain = rn->adj_in; ain; ain = ain->next)
  2419. if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
  2420. {
  2421. bgp_adj_in_remove (rn, ain);
  2422. bgp_unlock_node (rn);
  2423. break;
  2424. }
  2425. for (aout = rn->adj_out; aout; aout = aout->next)
  2426. if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
  2427. {
  2428. bgp_adj_out_remove (rn, aout, peer, afi, safi);
  2429. bgp_unlock_node (rn);
  2430. break;
  2431. }
  2432. for (ri = rn->info; ri; ri = ri->next)
  2433. if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
  2434. {
  2435. struct bgp_clear_node_queue *cnq;
  2436. /* both unlocked in bgp_clear_node_queue_del */
  2437. bgp_table_lock (bgp_node_table (rn));
  2438. bgp_lock_node (rn);
  2439. cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
  2440. sizeof (struct bgp_clear_node_queue));
  2441. cnq->rn = rn;
  2442. cnq->purpose = purpose;
  2443. work_queue_add (peer->clear_node_queue, cnq);
  2444. break;
  2445. }
  2446. }
  2447. return;
  2448. }
  2449. void
  2450. bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
  2451. enum bgp_clear_route_type purpose)
  2452. {
  2453. struct bgp_node *rn;
  2454. struct bgp_table *table;
  2455. struct peer *rsclient;
  2456. struct listnode *node, *nnode;
  2457. if (peer->clear_node_queue == NULL)
  2458. bgp_clear_node_queue_init (peer);
  2459. /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
  2460. * Idle until it receives a Clearing_Completed event. This protects
  2461. * against peers which flap faster than we can we clear, which could
  2462. * lead to:
  2463. *
  2464. * a) race with routes from the new session being installed before
  2465. * clear_route_node visits the node (to delete the route of that
  2466. * peer)
  2467. * b) resource exhaustion, clear_route_node likely leads to an entry
  2468. * on the process_main queue. Fast-flapping could cause that queue
  2469. * to grow and grow.
  2470. */
  2471. if (!peer->clear_node_queue->thread)
  2472. peer_lock (peer); /* bgp_clear_node_complete */
  2473. switch (purpose)
  2474. {
  2475. case BGP_CLEAR_ROUTE_NORMAL:
  2476. if (safi != SAFI_MPLS_VPN)
  2477. bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
  2478. else
  2479. for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
  2480. rn = bgp_route_next (rn))
  2481. if ((table = rn->info) != NULL)
  2482. bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
  2483. for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
  2484. if (CHECK_FLAG(rsclient->af_flags[afi][safi],
  2485. PEER_FLAG_RSERVER_CLIENT))
  2486. bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
  2487. break;
  2488. case BGP_CLEAR_ROUTE_MY_RSCLIENT:
  2489. bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
  2490. break;
  2491. default:
  2492. assert (0);
  2493. break;
  2494. }
  2495. /* If no routes were cleared, nothing was added to workqueue, the
  2496. * completion function won't be run by workqueue code - call it here.
  2497. * XXX: Actually, this assumption doesn't hold, see
  2498. * bgp_clear_route_table(), we queue all non-empty nodes.
  2499. *
  2500. * Additionally, there is a presumption in FSM that clearing is only
  2501. * really needed if peer state is Established - peers in
  2502. * pre-Established states shouldn't have any route-update state
  2503. * associated with them (in or out).
  2504. *
  2505. * We still can get here in pre-Established though, through
  2506. * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
  2507. * check to ensure the assumption above holds.
  2508. *
  2509. * At some future point, this check could be move to the top of the
  2510. * function, and do a quick early-return when state is
  2511. * pre-Established, avoiding above list and table scans. Once we're
  2512. * sure it is safe..
  2513. */
  2514. if (!peer->clear_node_queue->thread)
  2515. bgp_clear_node_complete (peer->clear_node_queue);
  2516. }
  2517. void
  2518. bgp_clear_route_all (struct peer *peer)
  2519. {
  2520. afi_t afi;
  2521. safi_t safi;
  2522. for (afi = AFI_IP; afi < AFI_MAX; afi++)
  2523. for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
  2524. bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
  2525. }
  2526. void
  2527. bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
  2528. {
  2529. struct bgp_table *table;
  2530. struct bgp_node *rn;
  2531. struct bgp_adj_in *ain;
  2532. table = peer->bgp->rib[afi][safi];
  2533. for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
  2534. for (ain = rn->adj_in; ain ; ain = ain->next)
  2535. if (ain->peer == peer)
  2536. {
  2537. bgp_adj_in_remove (rn, ain);
  2538. bgp_unlock_node (rn);
  2539. break;
  2540. }
  2541. }
  2542. void
  2543. bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
  2544. {
  2545. struct bgp_node *rn;
  2546. struct bgp_info *ri;
  2547. struct bgp_table *table;
  2548. table = peer->bgp->rib[afi][safi];
  2549. for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
  2550. {
  2551. for (ri = rn->info; ri; ri = ri->next)
  2552. if (ri->peer == peer)
  2553. {
  2554. if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
  2555. bgp_rib_remove (rn, ri, peer, afi, safi);
  2556. break;
  2557. }
  2558. }
  2559. }
  2560. /* Delete all kernel routes. */
  2561. void
  2562. bgp_cleanup_routes (void)
  2563. {
  2564. struct bgp *bgp;
  2565. struct listnode *node, *nnode;
  2566. struct bgp_node *rn;
  2567. struct bgp_table *table;
  2568. struct bgp_info *ri;
  2569. for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
  2570. {
  2571. table = bgp->rib[AFI_IP][SAFI_UNICAST];
  2572. for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
  2573. for (ri = rn->info; ri; ri = ri->next)
  2574. if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
  2575. && ri->type == ZEBRA_ROUTE_BGP
  2576. && ri->sub_type == BGP_ROUTE_NORMAL)
  2577. bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
  2578. table = bgp->rib[AFI_IP6][SAFI_UNICAST];
  2579. for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
  2580. for (ri = rn->info; ri; ri = ri->next)
  2581. if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
  2582. && ri->type == ZEBRA_ROUTE_BGP
  2583. && ri->sub_type == BGP_ROUTE_NORMAL)
  2584. bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
  2585. }
  2586. }
  2587. void
  2588. bgp_reset (void)
  2589. {
  2590. vty_reset ();
  2591. bgp_zclient_reset ();
  2592. access_list_reset ();
  2593. prefix_list_reset ();
  2594. }
  2595. /* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
  2596. value. */
  2597. int
  2598. bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
  2599. {
  2600. u_char *pnt;
  2601. u_char *lim;
  2602. struct prefix p;
  2603. int psize;
  2604. int ret;
  2605. /* Check peer status. */
  2606. if (peer->status != Established)
  2607. return 0;
  2608. pnt = packet->nlri;
  2609. lim = pnt + packet->length;
  2610. for (; pnt < lim; pnt += psize)
  2611. {
  2612. /* Clear prefix structure. */
  2613. memset (&p, 0, sizeof (struct prefix));
  2614. /* Fetch prefix length. */
  2615. p.prefixlen = *pnt++;
  2616. p.family = afi2family (packet->afi);
  2617. /* Already checked in nlri_sanity_check(). We do double check
  2618. here. */
  2619. if ((packet->afi == AFI_IP && p.prefixlen > 32)
  2620. || (packet->afi == AFI_IP6 && p.prefixlen > 128))
  2621. return -1;
  2622. /* Packet size overflow check. */
  2623. psize = PSIZE (p.prefixlen);
  2624. /* When packet overflow occur return immediately. */
  2625. if (pnt + psize > lim)
  2626. return -1;
  2627. /* Fetch prefix from NLRI packet. */
  2628. memcpy (&p.u.prefix, pnt, psize);
  2629. /* Check address. */
  2630. if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
  2631. {
  2632. if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
  2633. {
  2634. /*
  2635. * From draft-ietf-idr-bgp4-22, Section 6.3:
  2636. * If a BGP router receives an UPDATE message with a
  2637. * semantically incorrect NLRI field, in which a prefix is
  2638. * semantically incorrect (eg. an unexpected multicast IP
  2639. * address), it should ignore the prefix.
  2640. */
  2641. zlog (peer->log, LOG_ERR,
  2642. "IPv4 unicast NLRI is multicast address %s",
  2643. inet_ntoa (p.u.prefix4));
  2644. return -1;
  2645. }
  2646. }
  2647. #ifdef HAVE_IPV6
  2648. /* Check address. */
  2649. if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
  2650. {
  2651. if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
  2652. {
  2653. char buf[BUFSIZ];
  2654. zlog (peer->log, LOG_WARNING,
  2655. "IPv6 link-local NLRI received %s ignore this NLRI",
  2656. inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
  2657. continue;
  2658. }
  2659. }
  2660. #endif /* HAVE_IPV6 */
  2661. /* Normal process. */
  2662. if (attr)
  2663. ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
  2664. ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
  2665. else
  2666. ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
  2667. ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
  2668. /* Address family configuration mismatch or maximum-prefix count
  2669. overflow. */
  2670. if (ret < 0)
  2671. return -1;
  2672. }
  2673. /* Packet length consistency check. */
  2674. if (pnt != lim)
  2675. return -1;
  2676. return 0;
  2677. }
  2678. /* NLRI encode syntax check routine. */
  2679. int
  2680. bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
  2681. bgp_size_t length)
  2682. {
  2683. u_char *end;
  2684. u_char prefixlen;
  2685. int psize;
  2686. end = pnt + length;
  2687. /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
  2688. syntactic validity. If the field is syntactically incorrect,
  2689. then the Error Subcode is set to Invalid Network Field. */
  2690. while (pnt < end)
  2691. {
  2692. prefixlen = *pnt++;
  2693. /* Prefix length check. */
  2694. if ((afi == AFI_IP && prefixlen > 32)
  2695. || (afi == AFI_IP6 && prefixlen > 128))
  2696. {
  2697. plog_err (peer->log,
  2698. "%s [Error] Update packet error (wrong prefix length %d)",
  2699. peer->host, prefixlen);
  2700. bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
  2701. BGP_NOTIFY_UPDATE_INVAL_NETWORK);
  2702. return -1;
  2703. }
  2704. /* Packet size overflow check. */
  2705. psize = PSIZE (prefixlen);
  2706. if (pnt + psize > end)
  2707. {
  2708. plog_err (peer->log,
  2709. "%s [Error] Update packet error"
  2710. " (prefix data overflow prefix size is %d)",
  2711. peer->host, psize);
  2712. bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
  2713. BGP_NOTIFY_UPDATE_INVAL_NETWORK);
  2714. return -1;
  2715. }
  2716. pnt += psize;
  2717. }
  2718. /* Packet length consistency check. */
  2719. if (pnt != end)
  2720. {
  2721. plog_err (peer->log,
  2722. "%s [Error] Update packet error"
  2723. " (prefix length mismatch with total length)",
  2724. peer->host);
  2725. bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
  2726. BGP_NOTIFY_UPDATE_INVAL_NETWORK);
  2727. return -1;
  2728. }
  2729. return 0;
  2730. }
  2731. static struct bgp_static *
  2732. bgp_static_new (void)
  2733. {
  2734. return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
  2735. }
  2736. static void
  2737. bgp_static_free (struct bgp_static *bgp_static)
  2738. {
  2739. if (bgp_static->rmap.name)
  2740. free (bgp_static->rmap.name);
  2741. XFREE (MTYPE_BGP_STATIC, bgp_static);
  2742. }
  2743. static void
  2744. bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
  2745. struct prefix *p, afi_t afi, safi_t safi)
  2746. {
  2747. struct bgp_node *rn;
  2748. struct bgp_info *ri;
  2749. rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
  2750. /* Check selected route and self inserted route. */
  2751. for (ri = rn->info; ri; ri = ri->next)
  2752. if (ri->peer == bgp->peer_self
  2753. && ri->type == ZEBRA_ROUTE_BGP
  2754. && ri->sub_type == BGP_ROUTE_STATIC)
  2755. break;
  2756. /* Withdraw static BGP route from routing table. */
  2757. if (ri)
  2758. {
  2759. bgp_info_delete (rn, ri);
  2760. bgp_process (bgp, rn, afi, safi);
  2761. }
  2762. /* Unlock bgp_node_lookup. */
  2763. bgp_unlock_node (rn);
  2764. }
  2765. static void
  2766. bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
  2767. struct bgp_static *bgp_static,
  2768. afi_t afi, safi_t safi)
  2769. {
  2770. struct bgp_node *rn;
  2771. struct bgp_info *ri;
  2772. struct bgp_info *new;
  2773. struct bgp_info info;
  2774. struct attr *attr_new;
  2775. struct attr attr;
  2776. struct attr new_attr;
  2777. struct attr_extra new_extra;
  2778. struct bgp *bgp;
  2779. int ret;
  2780. char buf[SU_ADDRSTRLEN];
  2781. bgp = rsclient->bgp;
  2782. assert (bgp_static);
  2783. if (!bgp_static)
  2784. return;
  2785. rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
  2786. bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
  2787. attr.nexthop = bgp_static->igpnexthop;
  2788. attr.med = bgp_static->igpmetric;
  2789. attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
  2790. if (bgp_static->atomic)
  2791. attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
  2792. /* Apply network route-map for export to this rsclient. */
  2793. if (bgp_static->rmap.name)
  2794. {
  2795. struct attr attr_tmp = attr;
  2796. info.peer = rsclient;
  2797. info.attr = &attr_tmp;
  2798. SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
  2799. SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
  2800. ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
  2801. rsclient->rmap_type = 0;
  2802. if (ret == RMAP_DENYMATCH)
  2803. {
  2804. /* Free uninterned attribute. */
  2805. bgp_attr_flush (&attr_tmp);
  2806. /* Unintern original. */
  2807. aspath_unintern (&attr.aspath);
  2808. bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
  2809. bgp_attr_extra_free (&attr);
  2810. return;
  2811. }
  2812. attr_new = bgp_attr_intern (&attr_tmp);
  2813. }
  2814. else
  2815. attr_new = bgp_attr_intern (&attr);
  2816. new_attr.extra = &new_extra;
  2817. bgp_attr_dup(&new_attr, attr_new);
  2818. SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
  2819. if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
  2820. == RMAP_DENY)
  2821. {
  2822. /* This BGP update is filtered. Log the reason then update BGP entry. */
  2823. if (BGP_DEBUG (update, UPDATE_IN))
  2824. zlog (rsclient->log, LOG_DEBUG,
  2825. "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
  2826. inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  2827. p->prefixlen, rsclient->host);
  2828. bgp->peer_self->rmap_type = 0;
  2829. bgp_attr_unintern (&attr_new);
  2830. aspath_unintern (&attr.aspath);
  2831. bgp_attr_extra_free (&attr);
  2832. bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
  2833. return;
  2834. }
  2835. bgp->peer_self->rmap_type = 0;
  2836. bgp_attr_unintern (&attr_new);
  2837. attr_new = bgp_attr_intern (&new_attr);
  2838. for (ri = rn->info; ri; ri = ri->next)
  2839. if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
  2840. && ri->sub_type == BGP_ROUTE_STATIC)
  2841. break;
  2842. if (ri)
  2843. {
  2844. if (attrhash_cmp (ri->attr, attr_new) &&
  2845. !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
  2846. {
  2847. bgp_unlock_node (rn);
  2848. bgp_attr_unintern (&attr_new);
  2849. aspath_unintern (&attr.aspath);
  2850. bgp_attr_extra_free (&attr);
  2851. return;
  2852. }
  2853. else
  2854. {
  2855. /* The attribute is changed. */
  2856. bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
  2857. /* Rewrite BGP route information. */
  2858. if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
  2859. bgp_info_restore(rn, ri);
  2860. bgp_attr_unintern (&ri->attr);
  2861. ri->attr = attr_new;
  2862. ri->uptime = bgp_clock ();
  2863. /* Process change. */
  2864. bgp_process (bgp, rn, afi, safi);
  2865. bgp_unlock_node (rn);
  2866. aspath_unintern (&attr.aspath);
  2867. bgp_attr_extra_free (&attr);
  2868. return;
  2869. }
  2870. }
  2871. /* Make new BGP info. */
  2872. new = bgp_info_new ();
  2873. new->type = ZEBRA_ROUTE_BGP;
  2874. new->sub_type = BGP_ROUTE_STATIC;
  2875. new->peer = bgp->peer_self;
  2876. SET_FLAG (new->flags, BGP_INFO_VALID);
  2877. new->attr = attr_new;
  2878. new->uptime = bgp_clock ();
  2879. /* Register new BGP information. */
  2880. bgp_info_add (rn, new);
  2881. /* route_node_get lock */
  2882. bgp_unlock_node (rn);
  2883. /* Process change. */
  2884. bgp_process (bgp, rn, afi, safi);
  2885. /* Unintern original. */
  2886. aspath_unintern (&attr.aspath);
  2887. bgp_attr_extra_free (&attr);
  2888. }
  2889. static void
  2890. bgp_static_update_main (struct bgp *bgp, struct prefix *p,
  2891. struct bgp_static *bgp_static, afi_t afi, safi_t safi)
  2892. {
  2893. struct bgp_node *rn;
  2894. struct bgp_info *ri;
  2895. struct bgp_info *new;
  2896. struct bgp_info info;
  2897. struct attr attr;
  2898. struct attr *attr_new;
  2899. int ret;
  2900. assert (bgp_static);
  2901. if (!bgp_static)
  2902. return;
  2903. rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
  2904. bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
  2905. attr.nexthop = bgp_static->igpnexthop;
  2906. attr.med = bgp_static->igpmetric;
  2907. attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
  2908. if (bgp_static->atomic)
  2909. attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
  2910. /* Apply route-map. */
  2911. if (bgp_static->rmap.name)
  2912. {
  2913. struct attr attr_tmp = attr;
  2914. info.peer = bgp->peer_self;
  2915. info.attr = &attr_tmp;
  2916. SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
  2917. ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
  2918. bgp->peer_self->rmap_type = 0;
  2919. if (ret == RMAP_DENYMATCH)
  2920. {
  2921. /* Free uninterned attribute. */
  2922. bgp_attr_flush (&attr_tmp);
  2923. /* Unintern original. */
  2924. aspath_unintern (&attr.aspath);
  2925. bgp_attr_extra_free (&attr);
  2926. bgp_static_withdraw (bgp, p, afi, safi);
  2927. return;
  2928. }
  2929. attr_new = bgp_attr_intern (&attr_tmp);
  2930. }
  2931. else
  2932. attr_new = bgp_attr_intern (&attr);
  2933. for (ri = rn->info; ri; ri = ri->next)
  2934. if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
  2935. && ri->sub_type == BGP_ROUTE_STATIC)
  2936. break;
  2937. if (ri)
  2938. {
  2939. if (attrhash_cmp (ri->attr, attr_new) &&
  2940. !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
  2941. {
  2942. bgp_unlock_node (rn);
  2943. bgp_attr_unintern (&attr_new);
  2944. aspath_unintern (&attr.aspath);
  2945. bgp_attr_extra_free (&attr);
  2946. return;
  2947. }
  2948. else
  2949. {
  2950. /* The attribute is changed. */
  2951. bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
  2952. /* Rewrite BGP route information. */
  2953. if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
  2954. bgp_info_restore(rn, ri);
  2955. else
  2956. bgp_aggregate_decrement (bgp, p, ri, afi, safi);
  2957. bgp_attr_unintern (&ri->attr);
  2958. ri->attr = attr_new;
  2959. ri->uptime = bgp_clock ();
  2960. /* Process change. */
  2961. bgp_aggregate_increment (bgp, p, ri, afi, safi);
  2962. bgp_process (bgp, rn, afi, safi);
  2963. bgp_unlock_node (rn);
  2964. aspath_unintern (&attr.aspath);
  2965. bgp_attr_extra_free (&attr);
  2966. return;
  2967. }
  2968. }
  2969. /* Make new BGP info. */
  2970. new = bgp_info_new ();
  2971. new->type = ZEBRA_ROUTE_BGP;
  2972. new->sub_type = BGP_ROUTE_STATIC;
  2973. new->peer = bgp->peer_self;
  2974. SET_FLAG (new->flags, BGP_INFO_VALID);
  2975. new->attr = attr_new;
  2976. new->uptime = bgp_clock ();
  2977. /* Aggregate address increment. */
  2978. bgp_aggregate_increment (bgp, p, new, afi, safi);
  2979. /* Register new BGP information. */
  2980. bgp_info_add (rn, new);
  2981. /* route_node_get lock */
  2982. bgp_unlock_node (rn);
  2983. /* Process change. */
  2984. bgp_process (bgp, rn, afi, safi);
  2985. /* Unintern original. */
  2986. aspath_unintern (&attr.aspath);
  2987. bgp_attr_extra_free (&attr);
  2988. }
  2989. void
  2990. bgp_static_update (struct bgp *bgp, struct prefix *p,
  2991. struct bgp_static *bgp_static, afi_t afi, safi_t safi)
  2992. {
  2993. struct peer *rsclient;
  2994. struct listnode *node, *nnode;
  2995. bgp_static_update_main (bgp, p, bgp_static, afi, safi);
  2996. for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
  2997. {
  2998. if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
  2999. bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
  3000. }
  3001. }
  3002. static void
  3003. bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
  3004. safi_t safi, struct prefix_rd *prd, u_char *tag)
  3005. {
  3006. struct bgp_node *rn;
  3007. struct bgp_info *new;
  3008. rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
  3009. /* Make new BGP info. */
  3010. new = bgp_info_new ();
  3011. new->type = ZEBRA_ROUTE_BGP;
  3012. new->sub_type = BGP_ROUTE_STATIC;
  3013. new->peer = bgp->peer_self;
  3014. new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
  3015. SET_FLAG (new->flags, BGP_INFO_VALID);
  3016. new->uptime = bgp_clock ();
  3017. new->extra = bgp_info_extra_new();
  3018. memcpy (new->extra->tag, tag, 3);
  3019. /* Aggregate address increment. */
  3020. bgp_aggregate_increment (bgp, p, new, afi, safi);
  3021. /* Register new BGP information. */
  3022. bgp_info_add (rn, new);
  3023. /* route_node_get lock */
  3024. bgp_unlock_node (rn);
  3025. /* Process change. */
  3026. bgp_process (bgp, rn, afi, safi);
  3027. }
  3028. void
  3029. bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
  3030. safi_t safi)
  3031. {
  3032. struct bgp_node *rn;
  3033. struct bgp_info *ri;
  3034. rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
  3035. /* Check selected route and self inserted route. */
  3036. for (ri = rn->info; ri; ri = ri->next)
  3037. if (ri->peer == bgp->peer_self
  3038. && ri->type == ZEBRA_ROUTE_BGP
  3039. && ri->sub_type == BGP_ROUTE_STATIC)
  3040. break;
  3041. /* Withdraw static BGP route from routing table. */
  3042. if (ri)
  3043. {
  3044. bgp_aggregate_decrement (bgp, p, ri, afi, safi);
  3045. bgp_info_delete (rn, ri);
  3046. bgp_process (bgp, rn, afi, safi);
  3047. }
  3048. /* Unlock bgp_node_lookup. */
  3049. bgp_unlock_node (rn);
  3050. }
  3051. void
  3052. bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
  3053. {
  3054. struct bgp_static *bgp_static;
  3055. struct bgp *bgp;
  3056. struct bgp_node *rn;
  3057. struct prefix *p;
  3058. bgp = rsclient->bgp;
  3059. for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
  3060. if ((bgp_static = rn->info) != NULL)
  3061. {
  3062. p = &rn->p;
  3063. bgp_static_update_rsclient (rsclient, p, bgp_static,
  3064. afi, safi);
  3065. }
  3066. }
  3067. static void
  3068. bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
  3069. safi_t safi, struct prefix_rd *prd, u_char *tag)
  3070. {
  3071. struct bgp_node *rn;
  3072. struct bgp_info *ri;
  3073. rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
  3074. /* Check selected route and self inserted route. */
  3075. for (ri = rn->info; ri; ri = ri->next)
  3076. if (ri->peer == bgp->peer_self
  3077. && ri->type == ZEBRA_ROUTE_BGP
  3078. && ri->sub_type == BGP_ROUTE_STATIC)
  3079. break;
  3080. /* Withdraw static BGP route from routing table. */
  3081. if (ri)
  3082. {
  3083. bgp_aggregate_decrement (bgp, p, ri, afi, safi);
  3084. bgp_info_delete (rn, ri);
  3085. bgp_process (bgp, rn, afi, safi);
  3086. }
  3087. /* Unlock bgp_node_lookup. */
  3088. bgp_unlock_node (rn);
  3089. }
  3090. /* Configure static BGP network. When user don't run zebra, static
  3091. route should be installed as valid. */
  3092. static int
  3093. bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
  3094. afi_t afi, safi_t safi, const char *rmap, int backdoor)
  3095. {
  3096. int ret;
  3097. struct prefix p;
  3098. struct bgp_static *bgp_static;
  3099. struct bgp_node *rn;
  3100. u_char need_update = 0;
  3101. /* Convert IP prefix string to struct prefix. */
  3102. ret = str2prefix (ip_str, &p);
  3103. if (! ret)
  3104. {
  3105. vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
  3106. return CMD_WARNING;
  3107. }
  3108. #ifdef HAVE_IPV6
  3109. if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
  3110. {
  3111. vty_out (vty, "%% Malformed prefix (link-local address)%s",
  3112. VTY_NEWLINE);
  3113. return CMD_WARNING;
  3114. }
  3115. #endif /* HAVE_IPV6 */
  3116. apply_mask (&p);
  3117. /* Set BGP static route configuration. */
  3118. rn = bgp_node_get (bgp->route[afi][safi], &p);
  3119. if (rn->info)
  3120. {
  3121. /* Configuration change. */
  3122. bgp_static = rn->info;
  3123. /* Check previous routes are installed into BGP. */
  3124. if (bgp_static->valid && bgp_static->backdoor != backdoor)
  3125. need_update = 1;
  3126. bgp_static->backdoor = backdoor;
  3127. if (rmap)
  3128. {
  3129. if (bgp_static->rmap.name)
  3130. free (bgp_static->rmap.name);
  3131. bgp_static->rmap.name = strdup (rmap);
  3132. bgp_static->rmap.map = route_map_lookup_by_name (rmap);
  3133. }
  3134. else
  3135. {
  3136. if (bgp_static->rmap.name)
  3137. free (bgp_static->rmap.name);
  3138. bgp_static->rmap.name = NULL;
  3139. bgp_static->rmap.map = NULL;
  3140. bgp_static->valid = 0;
  3141. }
  3142. bgp_unlock_node (rn);
  3143. }
  3144. else
  3145. {
  3146. /* New configuration. */
  3147. bgp_static = bgp_static_new ();
  3148. bgp_static->backdoor = backdoor;
  3149. bgp_static->valid = 0;
  3150. bgp_static->igpmetric = 0;
  3151. bgp_static->igpnexthop.s_addr = 0;
  3152. if (rmap)
  3153. {
  3154. if (bgp_static->rmap.name)
  3155. free (bgp_static->rmap.name);
  3156. bgp_static->rmap.name = strdup (rmap);
  3157. bgp_static->rmap.map = route_map_lookup_by_name (rmap);
  3158. }
  3159. rn->info = bgp_static;
  3160. }
  3161. /* If BGP scan is not enabled, we should install this route here. */
  3162. if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
  3163. {
  3164. bgp_static->valid = 1;
  3165. if (need_update)
  3166. bgp_static_withdraw (bgp, &p, afi, safi);
  3167. if (! bgp_static->backdoor)
  3168. bgp_static_update (bgp, &p, bgp_static, afi, safi);
  3169. }
  3170. return CMD_SUCCESS;
  3171. }
  3172. /* Configure static BGP network. */
  3173. static int
  3174. bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
  3175. afi_t afi, safi_t safi)
  3176. {
  3177. int ret;
  3178. struct prefix p;
  3179. struct bgp_static *bgp_static;
  3180. struct bgp_node *rn;
  3181. /* Convert IP prefix string to struct prefix. */
  3182. ret = str2prefix (ip_str, &p);
  3183. if (! ret)
  3184. {
  3185. vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
  3186. return CMD_WARNING;
  3187. }
  3188. #ifdef HAVE_IPV6
  3189. if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
  3190. {
  3191. vty_out (vty, "%% Malformed prefix (link-local address)%s",
  3192. VTY_NEWLINE);
  3193. return CMD_WARNING;
  3194. }
  3195. #endif /* HAVE_IPV6 */
  3196. apply_mask (&p);
  3197. rn = bgp_node_lookup (bgp->route[afi][safi], &p);
  3198. if (! rn)
  3199. {
  3200. vty_out (vty, "%% Can't find specified static route configuration.%s",
  3201. VTY_NEWLINE);
  3202. return CMD_WARNING;
  3203. }
  3204. bgp_static = rn->info;
  3205. /* Update BGP RIB. */
  3206. if (! bgp_static->backdoor)
  3207. bgp_static_withdraw (bgp, &p, afi, safi);
  3208. /* Clear configuration. */
  3209. bgp_static_free (bgp_static);
  3210. rn->info = NULL;
  3211. bgp_unlock_node (rn);
  3212. bgp_unlock_node (rn);
  3213. return CMD_SUCCESS;
  3214. }
  3215. /* Called from bgp_delete(). Delete all static routes from the BGP
  3216. instance. */
  3217. void
  3218. bgp_static_delete (struct bgp *bgp)
  3219. {
  3220. afi_t afi;
  3221. safi_t safi;
  3222. struct bgp_node *rn;
  3223. struct bgp_node *rm;
  3224. struct bgp_table *table;
  3225. struct bgp_static *bgp_static;
  3226. for (afi = AFI_IP; afi < AFI_MAX; afi++)
  3227. for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
  3228. for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
  3229. if (rn->info != NULL)
  3230. {
  3231. if (safi == SAFI_MPLS_VPN)
  3232. {
  3233. table = rn->info;
  3234. for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
  3235. {
  3236. bgp_static = rn->info;
  3237. bgp_static_withdraw_vpnv4 (bgp, &rm->p,
  3238. AFI_IP, SAFI_MPLS_VPN,
  3239. (struct prefix_rd *)&rn->p,
  3240. bgp_static->tag);
  3241. bgp_static_free (bgp_static);
  3242. rn->info = NULL;
  3243. bgp_unlock_node (rn);
  3244. }
  3245. }
  3246. else
  3247. {
  3248. bgp_static = rn->info;
  3249. bgp_static_withdraw (bgp, &rn->p, afi, safi);
  3250. bgp_static_free (bgp_static);
  3251. rn->info = NULL;
  3252. bgp_unlock_node (rn);
  3253. }
  3254. }
  3255. }
  3256. int
  3257. bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
  3258. const char *tag_str)
  3259. {
  3260. int ret;
  3261. struct prefix p;
  3262. struct prefix_rd prd;
  3263. struct bgp *bgp;
  3264. struct bgp_node *prn;
  3265. struct bgp_node *rn;
  3266. struct bgp_table *table;
  3267. struct bgp_static *bgp_static;
  3268. u_char tag[3];
  3269. bgp = vty->index;
  3270. ret = str2prefix (ip_str, &p);
  3271. if (! ret)
  3272. {
  3273. vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
  3274. return CMD_WARNING;
  3275. }
  3276. apply_mask (&p);
  3277. ret = str2prefix_rd (rd_str, &prd);
  3278. if (! ret)
  3279. {
  3280. vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
  3281. return CMD_WARNING;
  3282. }
  3283. ret = str2tag (tag_str, tag);
  3284. if (! ret)
  3285. {
  3286. vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
  3287. return CMD_WARNING;
  3288. }
  3289. prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
  3290. (struct prefix *)&prd);
  3291. if (prn->info == NULL)
  3292. prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
  3293. else
  3294. bgp_unlock_node (prn);
  3295. table = prn->info;
  3296. rn = bgp_node_get (table, &p);
  3297. if (rn->info)
  3298. {
  3299. vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
  3300. bgp_unlock_node (rn);
  3301. }
  3302. else
  3303. {
  3304. /* New configuration. */
  3305. bgp_static = bgp_static_new ();
  3306. bgp_static->valid = 1;
  3307. memcpy (bgp_static->tag, tag, 3);
  3308. rn->info = bgp_static;
  3309. bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
  3310. }
  3311. return CMD_SUCCESS;
  3312. }
  3313. /* Configure static BGP network. */
  3314. int
  3315. bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
  3316. const char *rd_str, const char *tag_str)
  3317. {
  3318. int ret;
  3319. struct bgp *bgp;
  3320. struct prefix p;
  3321. struct prefix_rd prd;
  3322. struct bgp_node *prn;
  3323. struct bgp_node *rn;
  3324. struct bgp_table *table;
  3325. struct bgp_static *bgp_static;
  3326. u_char tag[3];
  3327. bgp = vty->index;
  3328. /* Convert IP prefix string to struct prefix. */
  3329. ret = str2prefix (ip_str, &p);
  3330. if (! ret)
  3331. {
  3332. vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
  3333. return CMD_WARNING;
  3334. }
  3335. apply_mask (&p);
  3336. ret = str2prefix_rd (rd_str, &prd);
  3337. if (! ret)
  3338. {
  3339. vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
  3340. return CMD_WARNING;
  3341. }
  3342. ret = str2tag (tag_str, tag);
  3343. if (! ret)
  3344. {
  3345. vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
  3346. return CMD_WARNING;
  3347. }
  3348. prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
  3349. (struct prefix *)&prd);
  3350. if (prn->info == NULL)
  3351. prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
  3352. else
  3353. bgp_unlock_node (prn);
  3354. table = prn->info;
  3355. rn = bgp_node_lookup (table, &p);
  3356. if (rn)
  3357. {
  3358. bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
  3359. bgp_static = rn->info;
  3360. bgp_static_free (bgp_static);
  3361. rn->info = NULL;
  3362. bgp_unlock_node (rn);
  3363. bgp_unlock_node (rn);
  3364. }
  3365. else
  3366. vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
  3367. return CMD_SUCCESS;
  3368. }
  3369. DEFUN (bgp_network,
  3370. bgp_network_cmd,
  3371. "network A.B.C.D/M",
  3372. "Specify a network to announce via BGP\n"
  3373. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
  3374. {
  3375. return bgp_static_set (vty, vty->index, argv[0],
  3376. AFI_IP, bgp_node_safi (vty), NULL, 0);
  3377. }
  3378. DEFUN (bgp_network_route_map,
  3379. bgp_network_route_map_cmd,
  3380. "network A.B.C.D/M route-map WORD",
  3381. "Specify a network to announce via BGP\n"
  3382. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  3383. "Route-map to modify the attributes\n"
  3384. "Name of the route map\n")
  3385. {
  3386. return bgp_static_set (vty, vty->index, argv[0],
  3387. AFI_IP, bgp_node_safi (vty), argv[1], 0);
  3388. }
  3389. DEFUN (bgp_network_backdoor,
  3390. bgp_network_backdoor_cmd,
  3391. "network A.B.C.D/M backdoor",
  3392. "Specify a network to announce via BGP\n"
  3393. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  3394. "Specify a BGP backdoor route\n")
  3395. {
  3396. return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
  3397. NULL, 1);
  3398. }
  3399. DEFUN (bgp_network_mask,
  3400. bgp_network_mask_cmd,
  3401. "network A.B.C.D mask A.B.C.D",
  3402. "Specify a network to announce via BGP\n"
  3403. "Network number\n"
  3404. "Network mask\n"
  3405. "Network mask\n")
  3406. {
  3407. int ret;
  3408. char prefix_str[BUFSIZ];
  3409. ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
  3410. if (! ret)
  3411. {
  3412. vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
  3413. return CMD_WARNING;
  3414. }
  3415. return bgp_static_set (vty, vty->index, prefix_str,
  3416. AFI_IP, bgp_node_safi (vty), NULL, 0);
  3417. }
  3418. DEFUN (bgp_network_mask_route_map,
  3419. bgp_network_mask_route_map_cmd,
  3420. "network A.B.C.D mask A.B.C.D route-map WORD",
  3421. "Specify a network to announce via BGP\n"
  3422. "Network number\n"
  3423. "Network mask\n"
  3424. "Network mask\n"
  3425. "Route-map to modify the attributes\n"
  3426. "Name of the route map\n")
  3427. {
  3428. int ret;
  3429. char prefix_str[BUFSIZ];
  3430. ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
  3431. if (! ret)
  3432. {
  3433. vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
  3434. return CMD_WARNING;
  3435. }
  3436. return bgp_static_set (vty, vty->index, prefix_str,
  3437. AFI_IP, bgp_node_safi (vty), argv[2], 0);
  3438. }
  3439. DEFUN (bgp_network_mask_backdoor,
  3440. bgp_network_mask_backdoor_cmd,
  3441. "network A.B.C.D mask A.B.C.D backdoor",
  3442. "Specify a network to announce via BGP\n"
  3443. "Network number\n"
  3444. "Network mask\n"
  3445. "Network mask\n"
  3446. "Specify a BGP backdoor route\n")
  3447. {
  3448. int ret;
  3449. char prefix_str[BUFSIZ];
  3450. ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
  3451. if (! ret)
  3452. {
  3453. vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
  3454. return CMD_WARNING;
  3455. }
  3456. return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
  3457. NULL, 1);
  3458. }
  3459. DEFUN (bgp_network_mask_natural,
  3460. bgp_network_mask_natural_cmd,
  3461. "network A.B.C.D",
  3462. "Specify a network to announce via BGP\n"
  3463. "Network number\n")
  3464. {
  3465. int ret;
  3466. char prefix_str[BUFSIZ];
  3467. ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
  3468. if (! ret)
  3469. {
  3470. vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
  3471. return CMD_WARNING;
  3472. }
  3473. return bgp_static_set (vty, vty->index, prefix_str,
  3474. AFI_IP, bgp_node_safi (vty), NULL, 0);
  3475. }
  3476. DEFUN (bgp_network_mask_natural_route_map,
  3477. bgp_network_mask_natural_route_map_cmd,
  3478. "network A.B.C.D route-map WORD",
  3479. "Specify a network to announce via BGP\n"
  3480. "Network number\n"
  3481. "Route-map to modify the attributes\n"
  3482. "Name of the route map\n")
  3483. {
  3484. int ret;
  3485. char prefix_str[BUFSIZ];
  3486. ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
  3487. if (! ret)
  3488. {
  3489. vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
  3490. return CMD_WARNING;
  3491. }
  3492. return bgp_static_set (vty, vty->index, prefix_str,
  3493. AFI_IP, bgp_node_safi (vty), argv[1], 0);
  3494. }
  3495. DEFUN (bgp_network_mask_natural_backdoor,
  3496. bgp_network_mask_natural_backdoor_cmd,
  3497. "network A.B.C.D backdoor",
  3498. "Specify a network to announce via BGP\n"
  3499. "Network number\n"
  3500. "Specify a BGP backdoor route\n")
  3501. {
  3502. int ret;
  3503. char prefix_str[BUFSIZ];
  3504. ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
  3505. if (! ret)
  3506. {
  3507. vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
  3508. return CMD_WARNING;
  3509. }
  3510. return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
  3511. NULL, 1);
  3512. }
  3513. DEFUN (no_bgp_network,
  3514. no_bgp_network_cmd,
  3515. "no network A.B.C.D/M",
  3516. NO_STR
  3517. "Specify a network to announce via BGP\n"
  3518. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
  3519. {
  3520. return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
  3521. bgp_node_safi (vty));
  3522. }
  3523. ALIAS (no_bgp_network,
  3524. no_bgp_network_route_map_cmd,
  3525. "no network A.B.C.D/M route-map WORD",
  3526. NO_STR
  3527. "Specify a network to announce via BGP\n"
  3528. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  3529. "Route-map to modify the attributes\n"
  3530. "Name of the route map\n")
  3531. ALIAS (no_bgp_network,
  3532. no_bgp_network_backdoor_cmd,
  3533. "no network A.B.C.D/M backdoor",
  3534. NO_STR
  3535. "Specify a network to announce via BGP\n"
  3536. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  3537. "Specify a BGP backdoor route\n")
  3538. DEFUN (no_bgp_network_mask,
  3539. no_bgp_network_mask_cmd,
  3540. "no network A.B.C.D mask A.B.C.D",
  3541. NO_STR
  3542. "Specify a network to announce via BGP\n"
  3543. "Network number\n"
  3544. "Network mask\n"
  3545. "Network mask\n")
  3546. {
  3547. int ret;
  3548. char prefix_str[BUFSIZ];
  3549. ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
  3550. if (! ret)
  3551. {
  3552. vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
  3553. return CMD_WARNING;
  3554. }
  3555. return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
  3556. bgp_node_safi (vty));
  3557. }
  3558. ALIAS (no_bgp_network_mask,
  3559. no_bgp_network_mask_route_map_cmd,
  3560. "no network A.B.C.D mask A.B.C.D route-map WORD",
  3561. NO_STR
  3562. "Specify a network to announce via BGP\n"
  3563. "Network number\n"
  3564. "Network mask\n"
  3565. "Network mask\n"
  3566. "Route-map to modify the attributes\n"
  3567. "Name of the route map\n")
  3568. ALIAS (no_bgp_network_mask,
  3569. no_bgp_network_mask_backdoor_cmd,
  3570. "no network A.B.C.D mask A.B.C.D backdoor",
  3571. NO_STR
  3572. "Specify a network to announce via BGP\n"
  3573. "Network number\n"
  3574. "Network mask\n"
  3575. "Network mask\n"
  3576. "Specify a BGP backdoor route\n")
  3577. DEFUN (no_bgp_network_mask_natural,
  3578. no_bgp_network_mask_natural_cmd,
  3579. "no network A.B.C.D",
  3580. NO_STR
  3581. "Specify a network to announce via BGP\n"
  3582. "Network number\n")
  3583. {
  3584. int ret;
  3585. char prefix_str[BUFSIZ];
  3586. ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
  3587. if (! ret)
  3588. {
  3589. vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
  3590. return CMD_WARNING;
  3591. }
  3592. return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
  3593. bgp_node_safi (vty));
  3594. }
  3595. ALIAS (no_bgp_network_mask_natural,
  3596. no_bgp_network_mask_natural_route_map_cmd,
  3597. "no network A.B.C.D route-map WORD",
  3598. NO_STR
  3599. "Specify a network to announce via BGP\n"
  3600. "Network number\n"
  3601. "Route-map to modify the attributes\n"
  3602. "Name of the route map\n")
  3603. ALIAS (no_bgp_network_mask_natural,
  3604. no_bgp_network_mask_natural_backdoor_cmd,
  3605. "no network A.B.C.D backdoor",
  3606. NO_STR
  3607. "Specify a network to announce via BGP\n"
  3608. "Network number\n"
  3609. "Specify a BGP backdoor route\n")
  3610. #ifdef HAVE_IPV6
  3611. DEFUN (ipv6_bgp_network,
  3612. ipv6_bgp_network_cmd,
  3613. "network X:X::X:X/M",
  3614. "Specify a network to announce via BGP\n"
  3615. "IPv6 prefix <network>/<length>\n")
  3616. {
  3617. return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
  3618. NULL, 0);
  3619. }
  3620. DEFUN (ipv6_bgp_network_route_map,
  3621. ipv6_bgp_network_route_map_cmd,
  3622. "network X:X::X:X/M route-map WORD",
  3623. "Specify a network to announce via BGP\n"
  3624. "IPv6 prefix <network>/<length>\n"
  3625. "Route-map to modify the attributes\n"
  3626. "Name of the route map\n")
  3627. {
  3628. return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
  3629. bgp_node_safi (vty), argv[1], 0);
  3630. }
  3631. DEFUN (no_ipv6_bgp_network,
  3632. no_ipv6_bgp_network_cmd,
  3633. "no network X:X::X:X/M",
  3634. NO_STR
  3635. "Specify a network to announce via BGP\n"
  3636. "IPv6 prefix <network>/<length>\n")
  3637. {
  3638. return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
  3639. }
  3640. ALIAS (no_ipv6_bgp_network,
  3641. no_ipv6_bgp_network_route_map_cmd,
  3642. "no network X:X::X:X/M route-map WORD",
  3643. NO_STR
  3644. "Specify a network to announce via BGP\n"
  3645. "IPv6 prefix <network>/<length>\n"
  3646. "Route-map to modify the attributes\n"
  3647. "Name of the route map\n")
  3648. ALIAS (ipv6_bgp_network,
  3649. old_ipv6_bgp_network_cmd,
  3650. "ipv6 bgp network X:X::X:X/M",
  3651. IPV6_STR
  3652. BGP_STR
  3653. "Specify a network to announce via BGP\n"
  3654. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
  3655. ALIAS (no_ipv6_bgp_network,
  3656. old_no_ipv6_bgp_network_cmd,
  3657. "no ipv6 bgp network X:X::X:X/M",
  3658. NO_STR
  3659. IPV6_STR
  3660. BGP_STR
  3661. "Specify a network to announce via BGP\n"
  3662. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
  3663. #endif /* HAVE_IPV6 */
  3664. /* stubs for removed AS-Pathlimit commands, kept for config compatibility */
  3665. ALIAS_DEPRECATED (bgp_network,
  3666. bgp_network_ttl_cmd,
  3667. "network A.B.C.D/M pathlimit <0-255>",
  3668. "Specify a network to announce via BGP\n"
  3669. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  3670. "AS-Path hopcount limit attribute\n"
  3671. "AS-Pathlimit TTL, in number of AS-Path hops\n")
  3672. ALIAS_DEPRECATED (bgp_network_backdoor,
  3673. bgp_network_backdoor_ttl_cmd,
  3674. "network A.B.C.D/M backdoor pathlimit <0-255>",
  3675. "Specify a network to announce via BGP\n"
  3676. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  3677. "Specify a BGP backdoor route\n"
  3678. "AS-Path hopcount limit attribute\n"
  3679. "AS-Pathlimit TTL, in number of AS-Path hops\n")
  3680. ALIAS_DEPRECATED (bgp_network_mask,
  3681. bgp_network_mask_ttl_cmd,
  3682. "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
  3683. "Specify a network to announce via BGP\n"
  3684. "Network number\n"
  3685. "Network mask\n"
  3686. "Network mask\n"
  3687. "AS-Path hopcount limit attribute\n"
  3688. "AS-Pathlimit TTL, in number of AS-Path hops\n")
  3689. ALIAS_DEPRECATED (bgp_network_mask_backdoor,
  3690. bgp_network_mask_backdoor_ttl_cmd,
  3691. "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
  3692. "Specify a network to announce via BGP\n"
  3693. "Network number\n"
  3694. "Network mask\n"
  3695. "Network mask\n"
  3696. "Specify a BGP backdoor route\n"
  3697. "AS-Path hopcount limit attribute\n"
  3698. "AS-Pathlimit TTL, in number of AS-Path hops\n")
  3699. ALIAS_DEPRECATED (bgp_network_mask_natural,
  3700. bgp_network_mask_natural_ttl_cmd,
  3701. "network A.B.C.D pathlimit <0-255>",
  3702. "Specify a network to announce via BGP\n"
  3703. "Network number\n"
  3704. "AS-Path hopcount limit attribute\n"
  3705. "AS-Pathlimit TTL, in number of AS-Path hops\n")
  3706. ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
  3707. bgp_network_mask_natural_backdoor_ttl_cmd,
  3708. "network A.B.C.D backdoor pathlimit <1-255>",
  3709. "Specify a network to announce via BGP\n"
  3710. "Network number\n"
  3711. "Specify a BGP backdoor route\n"
  3712. "AS-Path hopcount limit attribute\n"
  3713. "AS-Pathlimit TTL, in number of AS-Path hops\n")
  3714. ALIAS_DEPRECATED (no_bgp_network,
  3715. no_bgp_network_ttl_cmd,
  3716. "no network A.B.C.D/M pathlimit <0-255>",
  3717. NO_STR
  3718. "Specify a network to announce via BGP\n"
  3719. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  3720. "AS-Path hopcount limit attribute\n"
  3721. "AS-Pathlimit TTL, in number of AS-Path hops\n")
  3722. ALIAS_DEPRECATED (no_bgp_network,
  3723. no_bgp_network_backdoor_ttl_cmd,
  3724. "no network A.B.C.D/M backdoor pathlimit <0-255>",
  3725. NO_STR
  3726. "Specify a network to announce via BGP\n"
  3727. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  3728. "Specify a BGP backdoor route\n"
  3729. "AS-Path hopcount limit attribute\n"
  3730. "AS-Pathlimit TTL, in number of AS-Path hops\n")
  3731. ALIAS_DEPRECATED (no_bgp_network,
  3732. no_bgp_network_mask_ttl_cmd,
  3733. "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
  3734. NO_STR
  3735. "Specify a network to announce via BGP\n"
  3736. "Network number\n"
  3737. "Network mask\n"
  3738. "Network mask\n"
  3739. "AS-Path hopcount limit attribute\n"
  3740. "AS-Pathlimit TTL, in number of AS-Path hops\n")
  3741. ALIAS_DEPRECATED (no_bgp_network_mask,
  3742. no_bgp_network_mask_backdoor_ttl_cmd,
  3743. "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
  3744. NO_STR
  3745. "Specify a network to announce via BGP\n"
  3746. "Network number\n"
  3747. "Network mask\n"
  3748. "Network mask\n"
  3749. "Specify a BGP backdoor route\n"
  3750. "AS-Path hopcount limit attribute\n"
  3751. "AS-Pathlimit TTL, in number of AS-Path hops\n")
  3752. ALIAS_DEPRECATED (no_bgp_network_mask_natural,
  3753. no_bgp_network_mask_natural_ttl_cmd,
  3754. "no network A.B.C.D pathlimit <0-255>",
  3755. NO_STR
  3756. "Specify a network to announce via BGP\n"
  3757. "Network number\n"
  3758. "AS-Path hopcount limit attribute\n"
  3759. "AS-Pathlimit TTL, in number of AS-Path hops\n")
  3760. ALIAS_DEPRECATED (no_bgp_network_mask_natural,
  3761. no_bgp_network_mask_natural_backdoor_ttl_cmd,
  3762. "no network A.B.C.D backdoor pathlimit <0-255>",
  3763. NO_STR
  3764. "Specify a network to announce via BGP\n"
  3765. "Network number\n"
  3766. "Specify a BGP backdoor route\n"
  3767. "AS-Path hopcount limit attribute\n"
  3768. "AS-Pathlimit TTL, in number of AS-Path hops\n")
  3769. #ifdef HAVE_IPV6
  3770. ALIAS_DEPRECATED (ipv6_bgp_network,
  3771. ipv6_bgp_network_ttl_cmd,
  3772. "network X:X::X:X/M pathlimit <0-255>",
  3773. "Specify a network to announce via BGP\n"
  3774. "IPv6 prefix <network>/<length>\n"
  3775. "AS-Path hopcount limit attribute\n"
  3776. "AS-Pathlimit TTL, in number of AS-Path hops\n")
  3777. ALIAS_DEPRECATED (no_ipv6_bgp_network,
  3778. no_ipv6_bgp_network_ttl_cmd,
  3779. "no network X:X::X:X/M pathlimit <0-255>",
  3780. NO_STR
  3781. "Specify a network to announce via BGP\n"
  3782. "IPv6 prefix <network>/<length>\n"
  3783. "AS-Path hopcount limit attribute\n"
  3784. "AS-Pathlimit TTL, in number of AS-Path hops\n")
  3785. #endif /* HAVE_IPV6 */
  3786. /* Aggreagete address:
  3787. advertise-map Set condition to advertise attribute
  3788. as-set Generate AS set path information
  3789. attribute-map Set attributes of aggregate
  3790. route-map Set parameters of aggregate
  3791. summary-only Filter more specific routes from updates
  3792. suppress-map Conditionally filter more specific routes from updates
  3793. <cr>
  3794. */
  3795. struct bgp_aggregate
  3796. {
  3797. /* Summary-only flag. */
  3798. u_char summary_only;
  3799. /* AS set generation. */
  3800. u_char as_set;
  3801. /* Route-map for aggregated route. */
  3802. struct route_map *map;
  3803. /* Suppress-count. */
  3804. unsigned long count;
  3805. /* SAFI configuration. */
  3806. safi_t safi;
  3807. };
  3808. static struct bgp_aggregate *
  3809. bgp_aggregate_new (void)
  3810. {
  3811. return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
  3812. }
  3813. static void
  3814. bgp_aggregate_free (struct bgp_aggregate *aggregate)
  3815. {
  3816. XFREE (MTYPE_BGP_AGGREGATE, aggregate);
  3817. }
  3818. static void
  3819. bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
  3820. afi_t afi, safi_t safi, struct bgp_info *del,
  3821. struct bgp_aggregate *aggregate)
  3822. {
  3823. struct bgp_table *table;
  3824. struct bgp_node *top;
  3825. struct bgp_node *rn;
  3826. u_char origin;
  3827. struct aspath *aspath = NULL;
  3828. struct aspath *asmerge = NULL;
  3829. struct community *community = NULL;
  3830. struct community *commerge = NULL;
  3831. struct in_addr nexthop;
  3832. u_int32_t med = 0;
  3833. struct bgp_info *ri;
  3834. struct bgp_info *new;
  3835. int first = 1;
  3836. unsigned long match = 0;
  3837. /* Record adding route's nexthop and med. */
  3838. if (rinew)
  3839. {
  3840. nexthop = rinew->attr->nexthop;
  3841. med = rinew->attr->med;
  3842. }
  3843. /* ORIGIN attribute: If at least one route among routes that are
  3844. aggregated has ORIGIN with the value INCOMPLETE, then the
  3845. aggregated route must have the ORIGIN attribute with the value
  3846. INCOMPLETE. Otherwise, if at least one route among routes that
  3847. are aggregated has ORIGIN with the value EGP, then the aggregated
  3848. route must have the origin attribute with the value EGP. In all
  3849. other case the value of the ORIGIN attribute of the aggregated
  3850. route is INTERNAL. */
  3851. origin = BGP_ORIGIN_IGP;
  3852. table = bgp->rib[afi][safi];
  3853. top = bgp_node_get (table, p);
  3854. for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
  3855. if (rn->p.prefixlen > p->prefixlen)
  3856. {
  3857. match = 0;
  3858. for (ri = rn->info; ri; ri = ri->next)
  3859. {
  3860. if (BGP_INFO_HOLDDOWN (ri))
  3861. continue;
  3862. if (del && ri == del)
  3863. continue;
  3864. if (! rinew && first)
  3865. {
  3866. nexthop = ri->attr->nexthop;
  3867. med = ri->attr->med;
  3868. first = 0;
  3869. }
  3870. #ifdef AGGREGATE_NEXTHOP_CHECK
  3871. if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
  3872. || ri->attr->med != med)
  3873. {
  3874. if (aspath)
  3875. aspath_free (aspath);
  3876. if (community)
  3877. community_free (community);
  3878. bgp_unlock_node (rn);
  3879. bgp_unlock_node (top);
  3880. return;
  3881. }
  3882. #endif /* AGGREGATE_NEXTHOP_CHECK */
  3883. if (ri->sub_type != BGP_ROUTE_AGGREGATE)
  3884. {
  3885. if (aggregate->summary_only)
  3886. {
  3887. (bgp_info_extra_get (ri))->suppress++;
  3888. bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
  3889. match++;
  3890. }
  3891. aggregate->count++;
  3892. if (aggregate->as_set)
  3893. {
  3894. if (origin < ri->attr->origin)
  3895. origin = ri->attr->origin;
  3896. if (aspath)
  3897. {
  3898. asmerge = aspath_aggregate (aspath, ri->attr->aspath);
  3899. aspath_free (aspath);
  3900. aspath = asmerge;
  3901. }
  3902. else
  3903. aspath = aspath_dup (ri->attr->aspath);
  3904. if (ri->attr->community)
  3905. {
  3906. if (community)
  3907. {
  3908. commerge = community_merge (community,
  3909. ri->attr->community);
  3910. community = community_uniq_sort (commerge);
  3911. community_free (commerge);
  3912. }
  3913. else
  3914. community = community_dup (ri->attr->community);
  3915. }
  3916. }
  3917. }
  3918. }
  3919. if (match)
  3920. bgp_process (bgp, rn, afi, safi);
  3921. }
  3922. bgp_unlock_node (top);
  3923. if (rinew)
  3924. {
  3925. aggregate->count++;
  3926. if (aggregate->summary_only)
  3927. (bgp_info_extra_get (rinew))->suppress++;
  3928. if (aggregate->as_set)
  3929. {
  3930. if (origin < rinew->attr->origin)
  3931. origin = rinew->attr->origin;
  3932. if (aspath)
  3933. {
  3934. asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
  3935. aspath_free (aspath);
  3936. aspath = asmerge;
  3937. }
  3938. else
  3939. aspath = aspath_dup (rinew->attr->aspath);
  3940. if (rinew->attr->community)
  3941. {
  3942. if (community)
  3943. {
  3944. commerge = community_merge (community,
  3945. rinew->attr->community);
  3946. community = community_uniq_sort (commerge);
  3947. community_free (commerge);
  3948. }
  3949. else
  3950. community = community_dup (rinew->attr->community);
  3951. }
  3952. }
  3953. }
  3954. if (aggregate->count > 0)
  3955. {
  3956. rn = bgp_node_get (table, p);
  3957. new = bgp_info_new ();
  3958. new->type = ZEBRA_ROUTE_BGP;
  3959. new->sub_type = BGP_ROUTE_AGGREGATE;
  3960. new->peer = bgp->peer_self;
  3961. SET_FLAG (new->flags, BGP_INFO_VALID);
  3962. new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
  3963. new->uptime = bgp_clock ();
  3964. bgp_info_add (rn, new);
  3965. bgp_unlock_node (rn);
  3966. bgp_process (bgp, rn, afi, safi);
  3967. }
  3968. else
  3969. {
  3970. if (aspath)
  3971. aspath_free (aspath);
  3972. if (community)
  3973. community_free (community);
  3974. }
  3975. }
  3976. void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
  3977. struct bgp_aggregate *);
  3978. void
  3979. bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
  3980. struct bgp_info *ri, afi_t afi, safi_t safi)
  3981. {
  3982. struct bgp_node *child;
  3983. struct bgp_node *rn;
  3984. struct bgp_aggregate *aggregate;
  3985. struct bgp_table *table;
  3986. /* MPLS-VPN aggregation is not yet supported. */
  3987. if (safi == SAFI_MPLS_VPN)
  3988. return;
  3989. table = bgp->aggregate[afi][safi];
  3990. /* No aggregates configured. */
  3991. if (bgp_table_top_nolock (table) == NULL)
  3992. return;
  3993. if (p->prefixlen == 0)
  3994. return;
  3995. if (BGP_INFO_HOLDDOWN (ri))
  3996. return;
  3997. child = bgp_node_get (table, p);
  3998. /* Aggregate address configuration check. */
  3999. for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
  4000. if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
  4001. {
  4002. bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
  4003. bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
  4004. }
  4005. bgp_unlock_node (child);
  4006. }
  4007. void
  4008. bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
  4009. struct bgp_info *del, afi_t afi, safi_t safi)
  4010. {
  4011. struct bgp_node *child;
  4012. struct bgp_node *rn;
  4013. struct bgp_aggregate *aggregate;
  4014. struct bgp_table *table;
  4015. /* MPLS-VPN aggregation is not yet supported. */
  4016. if (safi == SAFI_MPLS_VPN)
  4017. return;
  4018. table = bgp->aggregate[afi][safi];
  4019. /* No aggregates configured. */
  4020. if (bgp_table_top_nolock (table) == NULL)
  4021. return;
  4022. if (p->prefixlen == 0)
  4023. return;
  4024. child = bgp_node_get (table, p);
  4025. /* Aggregate address configuration check. */
  4026. for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
  4027. if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
  4028. {
  4029. bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
  4030. bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
  4031. }
  4032. bgp_unlock_node (child);
  4033. }
  4034. static void
  4035. bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
  4036. struct bgp_aggregate *aggregate)
  4037. {
  4038. struct bgp_table *table;
  4039. struct bgp_node *top;
  4040. struct bgp_node *rn;
  4041. struct bgp_info *new;
  4042. struct bgp_info *ri;
  4043. unsigned long match;
  4044. u_char origin = BGP_ORIGIN_IGP;
  4045. struct aspath *aspath = NULL;
  4046. struct aspath *asmerge = NULL;
  4047. struct community *community = NULL;
  4048. struct community *commerge = NULL;
  4049. table = bgp->rib[afi][safi];
  4050. /* Sanity check. */
  4051. if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
  4052. return;
  4053. if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
  4054. return;
  4055. /* If routes exists below this node, generate aggregate routes. */
  4056. top = bgp_node_get (table, p);
  4057. for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
  4058. if (rn->p.prefixlen > p->prefixlen)
  4059. {
  4060. match = 0;
  4061. for (ri = rn->info; ri; ri = ri->next)
  4062. {
  4063. if (BGP_INFO_HOLDDOWN (ri))
  4064. continue;
  4065. if (ri->sub_type != BGP_ROUTE_AGGREGATE)
  4066. {
  4067. /* summary-only aggregate route suppress aggregated
  4068. route announcement. */
  4069. if (aggregate->summary_only)
  4070. {
  4071. (bgp_info_extra_get (ri))->suppress++;
  4072. bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
  4073. match++;
  4074. }
  4075. /* as-set aggregate route generate origin, as path,
  4076. community aggregation. */
  4077. if (aggregate->as_set)
  4078. {
  4079. if (origin < ri->attr->origin)
  4080. origin = ri->attr->origin;
  4081. if (aspath)
  4082. {
  4083. asmerge = aspath_aggregate (aspath, ri->attr->aspath);
  4084. aspath_free (aspath);
  4085. aspath = asmerge;
  4086. }
  4087. else
  4088. aspath = aspath_dup (ri->attr->aspath);
  4089. if (ri->attr->community)
  4090. {
  4091. if (community)
  4092. {
  4093. commerge = community_merge (community,
  4094. ri->attr->community);
  4095. community = community_uniq_sort (commerge);
  4096. community_free (commerge);
  4097. }
  4098. else
  4099. community = community_dup (ri->attr->community);
  4100. }
  4101. }
  4102. aggregate->count++;
  4103. }
  4104. }
  4105. /* If this node is suppressed, process the change. */
  4106. if (match)
  4107. bgp_process (bgp, rn, afi, safi);
  4108. }
  4109. bgp_unlock_node (top);
  4110. /* Add aggregate route to BGP table. */
  4111. if (aggregate->count)
  4112. {
  4113. rn = bgp_node_get (table, p);
  4114. new = bgp_info_new ();
  4115. new->type = ZEBRA_ROUTE_BGP;
  4116. new->sub_type = BGP_ROUTE_AGGREGATE;
  4117. new->peer = bgp->peer_self;
  4118. SET_FLAG (new->flags, BGP_INFO_VALID);
  4119. new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
  4120. new->uptime = bgp_clock ();
  4121. bgp_info_add (rn, new);
  4122. bgp_unlock_node (rn);
  4123. /* Process change. */
  4124. bgp_process (bgp, rn, afi, safi);
  4125. }
  4126. }
  4127. void
  4128. bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
  4129. safi_t safi, struct bgp_aggregate *aggregate)
  4130. {
  4131. struct bgp_table *table;
  4132. struct bgp_node *top;
  4133. struct bgp_node *rn;
  4134. struct bgp_info *ri;
  4135. unsigned long match;
  4136. table = bgp->rib[afi][safi];
  4137. if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
  4138. return;
  4139. if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
  4140. return;
  4141. /* If routes exists below this node, generate aggregate routes. */
  4142. top = bgp_node_get (table, p);
  4143. for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
  4144. if (rn->p.prefixlen > p->prefixlen)
  4145. {
  4146. match = 0;
  4147. for (ri = rn->info; ri; ri = ri->next)
  4148. {
  4149. if (BGP_INFO_HOLDDOWN (ri))
  4150. continue;
  4151. if (ri->sub_type != BGP_ROUTE_AGGREGATE)
  4152. {
  4153. if (aggregate->summary_only && ri->extra)
  4154. {
  4155. ri->extra->suppress--;
  4156. if (ri->extra->suppress == 0)
  4157. {
  4158. bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
  4159. match++;
  4160. }
  4161. }
  4162. aggregate->count--;
  4163. }
  4164. }
  4165. /* If this node was suppressed, process the change. */
  4166. if (match)
  4167. bgp_process (bgp, rn, afi, safi);
  4168. }
  4169. bgp_unlock_node (top);
  4170. /* Delete aggregate route from BGP table. */
  4171. rn = bgp_node_get (table, p);
  4172. for (ri = rn->info; ri; ri = ri->next)
  4173. if (ri->peer == bgp->peer_self
  4174. && ri->type == ZEBRA_ROUTE_BGP
  4175. && ri->sub_type == BGP_ROUTE_AGGREGATE)
  4176. break;
  4177. /* Withdraw static BGP route from routing table. */
  4178. if (ri)
  4179. {
  4180. bgp_info_delete (rn, ri);
  4181. bgp_process (bgp, rn, afi, safi);
  4182. }
  4183. /* Unlock bgp_node_lookup. */
  4184. bgp_unlock_node (rn);
  4185. }
  4186. /* Aggregate route attribute. */
  4187. #define AGGREGATE_SUMMARY_ONLY 1
  4188. #define AGGREGATE_AS_SET 1
  4189. static int
  4190. bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
  4191. afi_t afi, safi_t safi)
  4192. {
  4193. int ret;
  4194. struct prefix p;
  4195. struct bgp_node *rn;
  4196. struct bgp *bgp;
  4197. struct bgp_aggregate *aggregate;
  4198. /* Convert string to prefix structure. */
  4199. ret = str2prefix (prefix_str, &p);
  4200. if (!ret)
  4201. {
  4202. vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
  4203. return CMD_WARNING;
  4204. }
  4205. apply_mask (&p);
  4206. /* Get BGP structure. */
  4207. bgp = vty->index;
  4208. /* Old configuration check. */
  4209. rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
  4210. if (! rn)
  4211. {
  4212. vty_out (vty, "%% There is no aggregate-address configuration.%s",
  4213. VTY_NEWLINE);
  4214. return CMD_WARNING;
  4215. }
  4216. aggregate = rn->info;
  4217. if (aggregate->safi & SAFI_UNICAST)
  4218. bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
  4219. if (aggregate->safi & SAFI_MULTICAST)
  4220. bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
  4221. /* Unlock aggregate address configuration. */
  4222. rn->info = NULL;
  4223. bgp_aggregate_free (aggregate);
  4224. bgp_unlock_node (rn);
  4225. bgp_unlock_node (rn);
  4226. return CMD_SUCCESS;
  4227. }
  4228. static int
  4229. bgp_aggregate_set (struct vty *vty, const char *prefix_str,
  4230. afi_t afi, safi_t safi,
  4231. u_char summary_only, u_char as_set)
  4232. {
  4233. int ret;
  4234. struct prefix p;
  4235. struct bgp_node *rn;
  4236. struct bgp *bgp;
  4237. struct bgp_aggregate *aggregate;
  4238. /* Convert string to prefix structure. */
  4239. ret = str2prefix (prefix_str, &p);
  4240. if (!ret)
  4241. {
  4242. vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
  4243. return CMD_WARNING;
  4244. }
  4245. apply_mask (&p);
  4246. /* Get BGP structure. */
  4247. bgp = vty->index;
  4248. /* Old configuration check. */
  4249. rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
  4250. if (rn->info)
  4251. {
  4252. vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
  4253. /* try to remove the old entry */
  4254. ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
  4255. if (ret)
  4256. {
  4257. vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
  4258. bgp_unlock_node (rn);
  4259. return CMD_WARNING;
  4260. }
  4261. }
  4262. /* Make aggregate address structure. */
  4263. aggregate = bgp_aggregate_new ();
  4264. aggregate->summary_only = summary_only;
  4265. aggregate->as_set = as_set;
  4266. aggregate->safi = safi;
  4267. rn->info = aggregate;
  4268. /* Aggregate address insert into BGP routing table. */
  4269. if (safi & SAFI_UNICAST)
  4270. bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
  4271. if (safi & SAFI_MULTICAST)
  4272. bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
  4273. return CMD_SUCCESS;
  4274. }
  4275. DEFUN (aggregate_address,
  4276. aggregate_address_cmd,
  4277. "aggregate-address A.B.C.D/M",
  4278. "Configure BGP aggregate entries\n"
  4279. "Aggregate prefix\n")
  4280. {
  4281. return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
  4282. }
  4283. DEFUN (aggregate_address_mask,
  4284. aggregate_address_mask_cmd,
  4285. "aggregate-address A.B.C.D A.B.C.D",
  4286. "Configure BGP aggregate entries\n"
  4287. "Aggregate address\n"
  4288. "Aggregate mask\n")
  4289. {
  4290. int ret;
  4291. char prefix_str[BUFSIZ];
  4292. ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
  4293. if (! ret)
  4294. {
  4295. vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
  4296. return CMD_WARNING;
  4297. }
  4298. return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
  4299. 0, 0);
  4300. }
  4301. DEFUN (aggregate_address_summary_only,
  4302. aggregate_address_summary_only_cmd,
  4303. "aggregate-address A.B.C.D/M summary-only",
  4304. "Configure BGP aggregate entries\n"
  4305. "Aggregate prefix\n"
  4306. "Filter more specific routes from updates\n")
  4307. {
  4308. return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
  4309. AGGREGATE_SUMMARY_ONLY, 0);
  4310. }
  4311. DEFUN (aggregate_address_mask_summary_only,
  4312. aggregate_address_mask_summary_only_cmd,
  4313. "aggregate-address A.B.C.D A.B.C.D summary-only",
  4314. "Configure BGP aggregate entries\n"
  4315. "Aggregate address\n"
  4316. "Aggregate mask\n"
  4317. "Filter more specific routes from updates\n")
  4318. {
  4319. int ret;
  4320. char prefix_str[BUFSIZ];
  4321. ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
  4322. if (! ret)
  4323. {
  4324. vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
  4325. return CMD_WARNING;
  4326. }
  4327. return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
  4328. AGGREGATE_SUMMARY_ONLY, 0);
  4329. }
  4330. DEFUN (aggregate_address_as_set,
  4331. aggregate_address_as_set_cmd,
  4332. "aggregate-address A.B.C.D/M as-set",
  4333. "Configure BGP aggregate entries\n"
  4334. "Aggregate prefix\n"
  4335. "Generate AS set path information\n")
  4336. {
  4337. return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
  4338. 0, AGGREGATE_AS_SET);
  4339. }
  4340. DEFUN (aggregate_address_mask_as_set,
  4341. aggregate_address_mask_as_set_cmd,
  4342. "aggregate-address A.B.C.D A.B.C.D as-set",
  4343. "Configure BGP aggregate entries\n"
  4344. "Aggregate address\n"
  4345. "Aggregate mask\n"
  4346. "Generate AS set path information\n")
  4347. {
  4348. int ret;
  4349. char prefix_str[BUFSIZ];
  4350. ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
  4351. if (! ret)
  4352. {
  4353. vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
  4354. return CMD_WARNING;
  4355. }
  4356. return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
  4357. 0, AGGREGATE_AS_SET);
  4358. }
  4359. DEFUN (aggregate_address_as_set_summary,
  4360. aggregate_address_as_set_summary_cmd,
  4361. "aggregate-address A.B.C.D/M as-set summary-only",
  4362. "Configure BGP aggregate entries\n"
  4363. "Aggregate prefix\n"
  4364. "Generate AS set path information\n"
  4365. "Filter more specific routes from updates\n")
  4366. {
  4367. return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
  4368. AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
  4369. }
  4370. ALIAS (aggregate_address_as_set_summary,
  4371. aggregate_address_summary_as_set_cmd,
  4372. "aggregate-address A.B.C.D/M summary-only as-set",
  4373. "Configure BGP aggregate entries\n"
  4374. "Aggregate prefix\n"
  4375. "Filter more specific routes from updates\n"
  4376. "Generate AS set path information\n")
  4377. DEFUN (aggregate_address_mask_as_set_summary,
  4378. aggregate_address_mask_as_set_summary_cmd,
  4379. "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
  4380. "Configure BGP aggregate entries\n"
  4381. "Aggregate address\n"
  4382. "Aggregate mask\n"
  4383. "Generate AS set path information\n"
  4384. "Filter more specific routes from updates\n")
  4385. {
  4386. int ret;
  4387. char prefix_str[BUFSIZ];
  4388. ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
  4389. if (! ret)
  4390. {
  4391. vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
  4392. return CMD_WARNING;
  4393. }
  4394. return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
  4395. AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
  4396. }
  4397. ALIAS (aggregate_address_mask_as_set_summary,
  4398. aggregate_address_mask_summary_as_set_cmd,
  4399. "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
  4400. "Configure BGP aggregate entries\n"
  4401. "Aggregate address\n"
  4402. "Aggregate mask\n"
  4403. "Filter more specific routes from updates\n"
  4404. "Generate AS set path information\n")
  4405. DEFUN (no_aggregate_address,
  4406. no_aggregate_address_cmd,
  4407. "no aggregate-address A.B.C.D/M",
  4408. NO_STR
  4409. "Configure BGP aggregate entries\n"
  4410. "Aggregate prefix\n")
  4411. {
  4412. return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
  4413. }
  4414. ALIAS (no_aggregate_address,
  4415. no_aggregate_address_summary_only_cmd,
  4416. "no aggregate-address A.B.C.D/M summary-only",
  4417. NO_STR
  4418. "Configure BGP aggregate entries\n"
  4419. "Aggregate prefix\n"
  4420. "Filter more specific routes from updates\n")
  4421. ALIAS (no_aggregate_address,
  4422. no_aggregate_address_as_set_cmd,
  4423. "no aggregate-address A.B.C.D/M as-set",
  4424. NO_STR
  4425. "Configure BGP aggregate entries\n"
  4426. "Aggregate prefix\n"
  4427. "Generate AS set path information\n")
  4428. ALIAS (no_aggregate_address,
  4429. no_aggregate_address_as_set_summary_cmd,
  4430. "no aggregate-address A.B.C.D/M as-set summary-only",
  4431. NO_STR
  4432. "Configure BGP aggregate entries\n"
  4433. "Aggregate prefix\n"
  4434. "Generate AS set path information\n"
  4435. "Filter more specific routes from updates\n")
  4436. ALIAS (no_aggregate_address,
  4437. no_aggregate_address_summary_as_set_cmd,
  4438. "no aggregate-address A.B.C.D/M summary-only as-set",
  4439. NO_STR
  4440. "Configure BGP aggregate entries\n"
  4441. "Aggregate prefix\n"
  4442. "Filter more specific routes from updates\n"
  4443. "Generate AS set path information\n")
  4444. DEFUN (no_aggregate_address_mask,
  4445. no_aggregate_address_mask_cmd,
  4446. "no aggregate-address A.B.C.D A.B.C.D",
  4447. NO_STR
  4448. "Configure BGP aggregate entries\n"
  4449. "Aggregate address\n"
  4450. "Aggregate mask\n")
  4451. {
  4452. int ret;
  4453. char prefix_str[BUFSIZ];
  4454. ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
  4455. if (! ret)
  4456. {
  4457. vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
  4458. return CMD_WARNING;
  4459. }
  4460. return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
  4461. }
  4462. ALIAS (no_aggregate_address_mask,
  4463. no_aggregate_address_mask_summary_only_cmd,
  4464. "no aggregate-address A.B.C.D A.B.C.D summary-only",
  4465. NO_STR
  4466. "Configure BGP aggregate entries\n"
  4467. "Aggregate address\n"
  4468. "Aggregate mask\n"
  4469. "Filter more specific routes from updates\n")
  4470. ALIAS (no_aggregate_address_mask,
  4471. no_aggregate_address_mask_as_set_cmd,
  4472. "no aggregate-address A.B.C.D A.B.C.D as-set",
  4473. NO_STR
  4474. "Configure BGP aggregate entries\n"
  4475. "Aggregate address\n"
  4476. "Aggregate mask\n"
  4477. "Generate AS set path information\n")
  4478. ALIAS (no_aggregate_address_mask,
  4479. no_aggregate_address_mask_as_set_summary_cmd,
  4480. "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
  4481. NO_STR
  4482. "Configure BGP aggregate entries\n"
  4483. "Aggregate address\n"
  4484. "Aggregate mask\n"
  4485. "Generate AS set path information\n"
  4486. "Filter more specific routes from updates\n")
  4487. ALIAS (no_aggregate_address_mask,
  4488. no_aggregate_address_mask_summary_as_set_cmd,
  4489. "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
  4490. NO_STR
  4491. "Configure BGP aggregate entries\n"
  4492. "Aggregate address\n"
  4493. "Aggregate mask\n"
  4494. "Filter more specific routes from updates\n"
  4495. "Generate AS set path information\n")
  4496. #ifdef HAVE_IPV6
  4497. DEFUN (ipv6_aggregate_address,
  4498. ipv6_aggregate_address_cmd,
  4499. "aggregate-address X:X::X:X/M",
  4500. "Configure BGP aggregate entries\n"
  4501. "Aggregate prefix\n")
  4502. {
  4503. return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
  4504. }
  4505. DEFUN (ipv6_aggregate_address_summary_only,
  4506. ipv6_aggregate_address_summary_only_cmd,
  4507. "aggregate-address X:X::X:X/M summary-only",
  4508. "Configure BGP aggregate entries\n"
  4509. "Aggregate prefix\n"
  4510. "Filter more specific routes from updates\n")
  4511. {
  4512. return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
  4513. AGGREGATE_SUMMARY_ONLY, 0);
  4514. }
  4515. DEFUN (no_ipv6_aggregate_address,
  4516. no_ipv6_aggregate_address_cmd,
  4517. "no aggregate-address X:X::X:X/M",
  4518. NO_STR
  4519. "Configure BGP aggregate entries\n"
  4520. "Aggregate prefix\n")
  4521. {
  4522. return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
  4523. }
  4524. DEFUN (no_ipv6_aggregate_address_summary_only,
  4525. no_ipv6_aggregate_address_summary_only_cmd,
  4526. "no aggregate-address X:X::X:X/M summary-only",
  4527. NO_STR
  4528. "Configure BGP aggregate entries\n"
  4529. "Aggregate prefix\n"
  4530. "Filter more specific routes from updates\n")
  4531. {
  4532. return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
  4533. }
  4534. ALIAS (ipv6_aggregate_address,
  4535. old_ipv6_aggregate_address_cmd,
  4536. "ipv6 bgp aggregate-address X:X::X:X/M",
  4537. IPV6_STR
  4538. BGP_STR
  4539. "Configure BGP aggregate entries\n"
  4540. "Aggregate prefix\n")
  4541. ALIAS (ipv6_aggregate_address_summary_only,
  4542. old_ipv6_aggregate_address_summary_only_cmd,
  4543. "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
  4544. IPV6_STR
  4545. BGP_STR
  4546. "Configure BGP aggregate entries\n"
  4547. "Aggregate prefix\n"
  4548. "Filter more specific routes from updates\n")
  4549. ALIAS (no_ipv6_aggregate_address,
  4550. old_no_ipv6_aggregate_address_cmd,
  4551. "no ipv6 bgp aggregate-address X:X::X:X/M",
  4552. NO_STR
  4553. IPV6_STR
  4554. BGP_STR
  4555. "Configure BGP aggregate entries\n"
  4556. "Aggregate prefix\n")
  4557. ALIAS (no_ipv6_aggregate_address_summary_only,
  4558. old_no_ipv6_aggregate_address_summary_only_cmd,
  4559. "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
  4560. NO_STR
  4561. IPV6_STR
  4562. BGP_STR
  4563. "Configure BGP aggregate entries\n"
  4564. "Aggregate prefix\n"
  4565. "Filter more specific routes from updates\n")
  4566. #endif /* HAVE_IPV6 */
  4567. /* Redistribute route treatment. */
  4568. void
  4569. bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
  4570. const struct in6_addr *nexthop6,
  4571. u_int32_t metric, u_char type)
  4572. {
  4573. struct bgp *bgp;
  4574. struct listnode *node, *nnode;
  4575. struct bgp_info *new;
  4576. struct bgp_info *bi;
  4577. struct bgp_info info;
  4578. struct bgp_node *bn;
  4579. struct attr attr;
  4580. struct attr *new_attr;
  4581. afi_t afi;
  4582. int ret;
  4583. /* Make default attribute. */
  4584. bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
  4585. if (nexthop)
  4586. attr.nexthop = *nexthop;
  4587. #ifdef HAVE_IPV6
  4588. if (nexthop6)
  4589. {
  4590. struct attr_extra *extra = bgp_attr_extra_get(&attr);
  4591. extra->mp_nexthop_global = *nexthop6;
  4592. extra->mp_nexthop_len = 16;
  4593. }
  4594. #endif
  4595. attr.med = metric;
  4596. attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
  4597. for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
  4598. {
  4599. afi = family2afi (p->family);
  4600. if (bgp->redist[afi][type])
  4601. {
  4602. struct attr attr_new;
  4603. struct attr_extra extra_new;
  4604. /* Copy attribute for modification. */
  4605. attr_new.extra = &extra_new;
  4606. bgp_attr_dup (&attr_new, &attr);
  4607. if (bgp->redist_metric_flag[afi][type])
  4608. attr_new.med = bgp->redist_metric[afi][type];
  4609. /* Apply route-map. */
  4610. if (bgp->rmap[afi][type].map)
  4611. {
  4612. info.peer = bgp->peer_self;
  4613. info.attr = &attr_new;
  4614. SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
  4615. ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
  4616. &info);
  4617. bgp->peer_self->rmap_type = 0;
  4618. if (ret == RMAP_DENYMATCH)
  4619. {
  4620. /* Free uninterned attribute. */
  4621. bgp_attr_flush (&attr_new);
  4622. /* Unintern original. */
  4623. aspath_unintern (&attr.aspath);
  4624. bgp_attr_extra_free (&attr);
  4625. bgp_redistribute_delete (p, type);
  4626. return;
  4627. }
  4628. }
  4629. bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
  4630. afi, SAFI_UNICAST, p, NULL);
  4631. new_attr = bgp_attr_intern (&attr_new);
  4632. for (bi = bn->info; bi; bi = bi->next)
  4633. if (bi->peer == bgp->peer_self
  4634. && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
  4635. break;
  4636. if (bi)
  4637. {
  4638. if (attrhash_cmp (bi->attr, new_attr) &&
  4639. !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
  4640. {
  4641. bgp_attr_unintern (&new_attr);
  4642. aspath_unintern (&attr.aspath);
  4643. bgp_attr_extra_free (&attr);
  4644. bgp_unlock_node (bn);
  4645. return;
  4646. }
  4647. else
  4648. {
  4649. /* The attribute is changed. */
  4650. bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
  4651. /* Rewrite BGP route information. */
  4652. if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
  4653. bgp_info_restore(bn, bi);
  4654. else
  4655. bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
  4656. bgp_attr_unintern (&bi->attr);
  4657. bi->attr = new_attr;
  4658. bi->uptime = bgp_clock ();
  4659. /* Process change. */
  4660. bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
  4661. bgp_process (bgp, bn, afi, SAFI_UNICAST);
  4662. bgp_unlock_node (bn);
  4663. aspath_unintern (&attr.aspath);
  4664. bgp_attr_extra_free (&attr);
  4665. return;
  4666. }
  4667. }
  4668. new = bgp_info_new ();
  4669. new->type = type;
  4670. new->sub_type = BGP_ROUTE_REDISTRIBUTE;
  4671. new->peer = bgp->peer_self;
  4672. SET_FLAG (new->flags, BGP_INFO_VALID);
  4673. new->attr = new_attr;
  4674. new->uptime = bgp_clock ();
  4675. bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
  4676. bgp_info_add (bn, new);
  4677. bgp_unlock_node (bn);
  4678. bgp_process (bgp, bn, afi, SAFI_UNICAST);
  4679. }
  4680. }
  4681. /* Unintern original. */
  4682. aspath_unintern (&attr.aspath);
  4683. bgp_attr_extra_free (&attr);
  4684. }
  4685. void
  4686. bgp_redistribute_delete (struct prefix *p, u_char type)
  4687. {
  4688. struct bgp *bgp;
  4689. struct listnode *node, *nnode;
  4690. afi_t afi;
  4691. struct bgp_node *rn;
  4692. struct bgp_info *ri;
  4693. for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
  4694. {
  4695. afi = family2afi (p->family);
  4696. if (bgp->redist[afi][type])
  4697. {
  4698. rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
  4699. for (ri = rn->info; ri; ri = ri->next)
  4700. if (ri->peer == bgp->peer_self
  4701. && ri->type == type)
  4702. break;
  4703. if (ri)
  4704. {
  4705. bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
  4706. bgp_info_delete (rn, ri);
  4707. bgp_process (bgp, rn, afi, SAFI_UNICAST);
  4708. }
  4709. bgp_unlock_node (rn);
  4710. }
  4711. }
  4712. }
  4713. /* Withdraw specified route type's route. */
  4714. void
  4715. bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
  4716. {
  4717. struct bgp_node *rn;
  4718. struct bgp_info *ri;
  4719. struct bgp_table *table;
  4720. table = bgp->rib[afi][SAFI_UNICAST];
  4721. for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
  4722. {
  4723. for (ri = rn->info; ri; ri = ri->next)
  4724. if (ri->peer == bgp->peer_self
  4725. && ri->type == type)
  4726. break;
  4727. if (ri)
  4728. {
  4729. bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
  4730. bgp_info_delete (rn, ri);
  4731. bgp_process (bgp, rn, afi, SAFI_UNICAST);
  4732. }
  4733. }
  4734. }
  4735. /* Static function to display route. */
  4736. static void
  4737. route_vty_out_route (struct prefix *p, struct vty *vty)
  4738. {
  4739. int len;
  4740. u_int32_t destination;
  4741. char buf[BUFSIZ];
  4742. if (p->family == AF_INET)
  4743. {
  4744. len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
  4745. destination = ntohl (p->u.prefix4.s_addr);
  4746. if ((IN_CLASSC (destination) && p->prefixlen == 24)
  4747. || (IN_CLASSB (destination) && p->prefixlen == 16)
  4748. || (IN_CLASSA (destination) && p->prefixlen == 8)
  4749. || p->u.prefix4.s_addr == 0)
  4750. {
  4751. /* When mask is natural, mask is not displayed. */
  4752. }
  4753. else
  4754. len += vty_out (vty, "/%d", p->prefixlen);
  4755. }
  4756. else
  4757. len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
  4758. p->prefixlen);
  4759. len = 17 - len;
  4760. if (len < 1)
  4761. vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
  4762. else
  4763. vty_out (vty, "%*s", len, " ");
  4764. }
  4765. enum bgp_display_type
  4766. {
  4767. normal_list,
  4768. };
  4769. /* Print the short form route status for a bgp_info */
  4770. static void
  4771. route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
  4772. {
  4773. /* Route status display. */
  4774. if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
  4775. vty_out (vty, "R");
  4776. else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
  4777. vty_out (vty, "S");
  4778. else if (binfo->extra && binfo->extra->suppress)
  4779. vty_out (vty, "s");
  4780. else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
  4781. vty_out (vty, "*");
  4782. else
  4783. vty_out (vty, " ");
  4784. /* Selected */
  4785. if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
  4786. vty_out (vty, "h");
  4787. else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
  4788. vty_out (vty, "d");
  4789. else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
  4790. vty_out (vty, ">");
  4791. else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
  4792. vty_out (vty, "=");
  4793. else
  4794. vty_out (vty, " ");
  4795. /* Internal route. */
  4796. if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
  4797. vty_out (vty, "i");
  4798. else
  4799. vty_out (vty, " ");
  4800. }
  4801. /* called from terminal list command */
  4802. void
  4803. route_vty_out (struct vty *vty, struct prefix *p,
  4804. struct bgp_info *binfo, int display, safi_t safi)
  4805. {
  4806. struct attr *attr;
  4807. /* short status lead text */
  4808. route_vty_short_status_out (vty, binfo);
  4809. /* print prefix and mask */
  4810. if (! display)
  4811. route_vty_out_route (p, vty);
  4812. else
  4813. vty_out (vty, "%*s", 17, " ");
  4814. /* Print attribute */
  4815. attr = binfo->attr;
  4816. if (attr)
  4817. {
  4818. if (p->family == AF_INET)
  4819. {
  4820. if (safi == SAFI_MPLS_VPN)
  4821. vty_out (vty, "%-16s",
  4822. inet_ntoa (attr->extra->mp_nexthop_global_in));
  4823. else
  4824. vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
  4825. }
  4826. #ifdef HAVE_IPV6
  4827. else if (p->family == AF_INET6)
  4828. {
  4829. int len;
  4830. char buf[BUFSIZ];
  4831. len = vty_out (vty, "%s",
  4832. inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
  4833. buf, BUFSIZ));
  4834. len = 16 - len;
  4835. if (len < 1)
  4836. vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
  4837. else
  4838. vty_out (vty, "%*s", len, " ");
  4839. }
  4840. #endif /* HAVE_IPV6 */
  4841. if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
  4842. vty_out (vty, "%10u", attr->med);
  4843. else
  4844. vty_out (vty, " ");
  4845. if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
  4846. vty_out (vty, "%7u", attr->local_pref);
  4847. else
  4848. vty_out (vty, " ");
  4849. vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
  4850. /* Print aspath */
  4851. if (attr->aspath)
  4852. aspath_print_vty (vty, "%s", attr->aspath, " ");
  4853. /* Print origin */
  4854. vty_out (vty, "%s", bgp_origin_str[attr->origin]);
  4855. }
  4856. vty_out (vty, "%s", VTY_NEWLINE);
  4857. }
  4858. /* called from terminal list command */
  4859. void
  4860. route_vty_out_tmp (struct vty *vty, struct prefix *p,
  4861. struct attr *attr, safi_t safi)
  4862. {
  4863. /* Route status display. */
  4864. vty_out (vty, "*");
  4865. vty_out (vty, ">");
  4866. vty_out (vty, " ");
  4867. /* print prefix and mask */
  4868. route_vty_out_route (p, vty);
  4869. /* Print attribute */
  4870. if (attr)
  4871. {
  4872. if (p->family == AF_INET)
  4873. {
  4874. if (safi == SAFI_MPLS_VPN)
  4875. vty_out (vty, "%-16s",
  4876. inet_ntoa (attr->extra->mp_nexthop_global_in));
  4877. else
  4878. vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
  4879. }
  4880. #ifdef HAVE_IPV6
  4881. else if (p->family == AF_INET6)
  4882. {
  4883. int len;
  4884. char buf[BUFSIZ];
  4885. assert (attr->extra);
  4886. len = vty_out (vty, "%s",
  4887. inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
  4888. buf, BUFSIZ));
  4889. len = 16 - len;
  4890. if (len < 1)
  4891. vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
  4892. else
  4893. vty_out (vty, "%*s", len, " ");
  4894. }
  4895. #endif /* HAVE_IPV6 */
  4896. if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
  4897. vty_out (vty, "%10u", attr->med);
  4898. else
  4899. vty_out (vty, " ");
  4900. if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
  4901. vty_out (vty, "%7u", attr->local_pref);
  4902. else
  4903. vty_out (vty, " ");
  4904. vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
  4905. /* Print aspath */
  4906. if (attr->aspath)
  4907. aspath_print_vty (vty, "%s", attr->aspath, " ");
  4908. /* Print origin */
  4909. vty_out (vty, "%s", bgp_origin_str[attr->origin]);
  4910. }
  4911. vty_out (vty, "%s", VTY_NEWLINE);
  4912. }
  4913. void
  4914. route_vty_out_tag (struct vty *vty, struct prefix *p,
  4915. struct bgp_info *binfo, int display, safi_t safi)
  4916. {
  4917. struct attr *attr;
  4918. u_int32_t label = 0;
  4919. if (!binfo->extra)
  4920. return;
  4921. /* short status lead text */
  4922. route_vty_short_status_out (vty, binfo);
  4923. /* print prefix and mask */
  4924. if (! display)
  4925. route_vty_out_route (p, vty);
  4926. else
  4927. vty_out (vty, "%*s", 17, " ");
  4928. /* Print attribute */
  4929. attr = binfo->attr;
  4930. if (attr)
  4931. {
  4932. if (p->family == AF_INET)
  4933. {
  4934. if (safi == SAFI_MPLS_VPN)
  4935. vty_out (vty, "%-16s",
  4936. inet_ntoa (attr->extra->mp_nexthop_global_in));
  4937. else
  4938. vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
  4939. }
  4940. #ifdef HAVE_IPV6
  4941. else if (p->family == AF_INET6)
  4942. {
  4943. assert (attr->extra);
  4944. char buf[BUFSIZ];
  4945. char buf1[BUFSIZ];
  4946. if (attr->extra->mp_nexthop_len == 16)
  4947. vty_out (vty, "%s",
  4948. inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
  4949. buf, BUFSIZ));
  4950. else if (attr->extra->mp_nexthop_len == 32)
  4951. vty_out (vty, "%s(%s)",
  4952. inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
  4953. buf, BUFSIZ),
  4954. inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
  4955. buf1, BUFSIZ));
  4956. }
  4957. #endif /* HAVE_IPV6 */
  4958. }
  4959. label = decode_label (binfo->extra->tag);
  4960. vty_out (vty, "notag/%d", label);
  4961. vty_out (vty, "%s", VTY_NEWLINE);
  4962. }
  4963. /* dampening route */
  4964. static void
  4965. damp_route_vty_out (struct vty *vty, struct prefix *p,
  4966. struct bgp_info *binfo, int display, safi_t safi)
  4967. {
  4968. struct attr *attr;
  4969. int len;
  4970. char timebuf[BGP_UPTIME_LEN];
  4971. /* short status lead text */
  4972. route_vty_short_status_out (vty, binfo);
  4973. /* print prefix and mask */
  4974. if (! display)
  4975. route_vty_out_route (p, vty);
  4976. else
  4977. vty_out (vty, "%*s", 17, " ");
  4978. len = vty_out (vty, "%s", binfo->peer->host);
  4979. len = 17 - len;
  4980. if (len < 1)
  4981. vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
  4982. else
  4983. vty_out (vty, "%*s", len, " ");
  4984. vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
  4985. /* Print attribute */
  4986. attr = binfo->attr;
  4987. if (attr)
  4988. {
  4989. /* Print aspath */
  4990. if (attr->aspath)
  4991. aspath_print_vty (vty, "%s", attr->aspath, " ");
  4992. /* Print origin */
  4993. vty_out (vty, "%s", bgp_origin_str[attr->origin]);
  4994. }
  4995. vty_out (vty, "%s", VTY_NEWLINE);
  4996. }
  4997. /* flap route */
  4998. static void
  4999. flap_route_vty_out (struct vty *vty, struct prefix *p,
  5000. struct bgp_info *binfo, int display, safi_t safi)
  5001. {
  5002. struct attr *attr;
  5003. struct bgp_damp_info *bdi;
  5004. char timebuf[BGP_UPTIME_LEN];
  5005. int len;
  5006. if (!binfo->extra)
  5007. return;
  5008. bdi = binfo->extra->damp_info;
  5009. /* short status lead text */
  5010. route_vty_short_status_out (vty, binfo);
  5011. /* print prefix and mask */
  5012. if (! display)
  5013. route_vty_out_route (p, vty);
  5014. else
  5015. vty_out (vty, "%*s", 17, " ");
  5016. len = vty_out (vty, "%s", binfo->peer->host);
  5017. len = 16 - len;
  5018. if (len < 1)
  5019. vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
  5020. else
  5021. vty_out (vty, "%*s", len, " ");
  5022. len = vty_out (vty, "%d", bdi->flap);
  5023. len = 5 - len;
  5024. if (len < 1)
  5025. vty_out (vty, " ");
  5026. else
  5027. vty_out (vty, "%*s ", len, " ");
  5028. vty_out (vty, "%s ", peer_uptime (bdi->start_time,
  5029. timebuf, BGP_UPTIME_LEN));
  5030. if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
  5031. && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
  5032. vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
  5033. else
  5034. vty_out (vty, "%*s ", 8, " ");
  5035. /* Print attribute */
  5036. attr = binfo->attr;
  5037. if (attr)
  5038. {
  5039. /* Print aspath */
  5040. if (attr->aspath)
  5041. aspath_print_vty (vty, "%s", attr->aspath, " ");
  5042. /* Print origin */
  5043. vty_out (vty, "%s", bgp_origin_str[attr->origin]);
  5044. }
  5045. vty_out (vty, "%s", VTY_NEWLINE);
  5046. }
  5047. static void
  5048. route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
  5049. struct bgp_info *binfo, afi_t afi, safi_t safi)
  5050. {
  5051. char buf[INET6_ADDRSTRLEN];
  5052. char buf1[BUFSIZ];
  5053. struct attr *attr;
  5054. int sockunion_vty_out (struct vty *, union sockunion *);
  5055. #ifdef HAVE_CLOCK_MONOTONIC
  5056. time_t tbuf;
  5057. #endif
  5058. attr = binfo->attr;
  5059. if (attr)
  5060. {
  5061. /* Line1 display AS-path, Aggregator */
  5062. if (attr->aspath)
  5063. {
  5064. vty_out (vty, " ");
  5065. if (aspath_count_hops (attr->aspath) == 0)
  5066. vty_out (vty, "Local");
  5067. else
  5068. aspath_print_vty (vty, "%s", attr->aspath, "");
  5069. }
  5070. if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
  5071. vty_out (vty, ", (removed)");
  5072. if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
  5073. vty_out (vty, ", (stale)");
  5074. if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
  5075. vty_out (vty, ", (aggregated by %u %s)",
  5076. attr->extra->aggregator_as,
  5077. inet_ntoa (attr->extra->aggregator_addr));
  5078. if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
  5079. vty_out (vty, ", (Received from a RR-client)");
  5080. if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
  5081. vty_out (vty, ", (Received from a RS-client)");
  5082. if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
  5083. vty_out (vty, ", (history entry)");
  5084. else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
  5085. vty_out (vty, ", (suppressed due to dampening)");
  5086. vty_out (vty, "%s", VTY_NEWLINE);
  5087. /* Line2 display Next-hop, Neighbor, Router-id */
  5088. if (p->family == AF_INET)
  5089. {
  5090. vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
  5091. inet_ntoa (attr->extra->mp_nexthop_global_in) :
  5092. inet_ntoa (attr->nexthop));
  5093. }
  5094. #ifdef HAVE_IPV6
  5095. else
  5096. {
  5097. assert (attr->extra);
  5098. vty_out (vty, " %s",
  5099. inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
  5100. buf, INET6_ADDRSTRLEN));
  5101. }
  5102. #endif /* HAVE_IPV6 */
  5103. if (binfo->peer == bgp->peer_self)
  5104. {
  5105. vty_out (vty, " from %s ",
  5106. p->family == AF_INET ? "0.0.0.0" : "::");
  5107. vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
  5108. }
  5109. else
  5110. {
  5111. if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
  5112. vty_out (vty, " (inaccessible)");
  5113. else if (binfo->extra && binfo->extra->igpmetric)
  5114. vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
  5115. vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
  5116. if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
  5117. vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
  5118. else
  5119. vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
  5120. }
  5121. vty_out (vty, "%s", VTY_NEWLINE);
  5122. #ifdef HAVE_IPV6
  5123. /* display nexthop local */
  5124. if (attr->extra && attr->extra->mp_nexthop_len == 32)
  5125. {
  5126. vty_out (vty, " (%s)%s",
  5127. inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
  5128. buf, INET6_ADDRSTRLEN),
  5129. VTY_NEWLINE);
  5130. }
  5131. #endif /* HAVE_IPV6 */
  5132. /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
  5133. vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
  5134. if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
  5135. vty_out (vty, ", metric %u", attr->med);
  5136. if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
  5137. vty_out (vty, ", localpref %u", attr->local_pref);
  5138. else
  5139. vty_out (vty, ", localpref %u", bgp->default_local_pref);
  5140. if (attr->extra && attr->extra->weight != 0)
  5141. vty_out (vty, ", weight %u", attr->extra->weight);
  5142. if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
  5143. vty_out (vty, ", valid");
  5144. if (binfo->peer != bgp->peer_self)
  5145. {
  5146. if (binfo->peer->as == binfo->peer->local_as)
  5147. vty_out (vty, ", internal");
  5148. else
  5149. vty_out (vty, ", %s",
  5150. (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
  5151. }
  5152. else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
  5153. vty_out (vty, ", aggregated, local");
  5154. else if (binfo->type != ZEBRA_ROUTE_BGP)
  5155. vty_out (vty, ", sourced");
  5156. else
  5157. vty_out (vty, ", sourced, local");
  5158. if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
  5159. vty_out (vty, ", atomic-aggregate");
  5160. if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
  5161. (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
  5162. bgp_info_mpath_count (binfo)))
  5163. vty_out (vty, ", multipath");
  5164. if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
  5165. vty_out (vty, ", best");
  5166. vty_out (vty, "%s", VTY_NEWLINE);
  5167. /* Line 4 display Community */
  5168. if (attr->community)
  5169. vty_out (vty, " Community: %s%s", attr->community->str,
  5170. VTY_NEWLINE);
  5171. /* Line 5 display Extended-community */
  5172. if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
  5173. vty_out (vty, " Extended Community: %s%s",
  5174. attr->extra->ecommunity->str, VTY_NEWLINE);
  5175. /* Line 6 display Originator, Cluster-id */
  5176. if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
  5177. (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
  5178. {
  5179. assert (attr->extra);
  5180. if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
  5181. vty_out (vty, " Originator: %s",
  5182. inet_ntoa (attr->extra->originator_id));
  5183. if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
  5184. {
  5185. int i;
  5186. vty_out (vty, ", Cluster list: ");
  5187. for (i = 0; i < attr->extra->cluster->length / 4; i++)
  5188. vty_out (vty, "%s ",
  5189. inet_ntoa (attr->extra->cluster->list[i]));
  5190. }
  5191. vty_out (vty, "%s", VTY_NEWLINE);
  5192. }
  5193. if (binfo->extra && binfo->extra->damp_info)
  5194. bgp_damp_info_vty (vty, binfo);
  5195. /* Line 7 display Uptime */
  5196. #ifdef HAVE_CLOCK_MONOTONIC
  5197. tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
  5198. vty_out (vty, " Last update: %s", ctime(&tbuf));
  5199. #else
  5200. vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
  5201. #endif /* HAVE_CLOCK_MONOTONIC */
  5202. }
  5203. vty_out (vty, "%s", VTY_NEWLINE);
  5204. }
  5205. #define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
  5206. "h history, * valid, > best, = multipath,%s"\
  5207. " i internal, r RIB-failure, S Stale, R Removed%s"
  5208. #define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
  5209. #define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
  5210. #define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
  5211. #define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
  5212. enum bgp_show_type
  5213. {
  5214. bgp_show_type_normal,
  5215. bgp_show_type_regexp,
  5216. bgp_show_type_prefix_list,
  5217. bgp_show_type_filter_list,
  5218. bgp_show_type_route_map,
  5219. bgp_show_type_neighbor,
  5220. bgp_show_type_cidr_only,
  5221. bgp_show_type_prefix_longer,
  5222. bgp_show_type_community_all,
  5223. bgp_show_type_community,
  5224. bgp_show_type_community_exact,
  5225. bgp_show_type_community_list,
  5226. bgp_show_type_community_list_exact,
  5227. bgp_show_type_flap_statistics,
  5228. bgp_show_type_flap_address,
  5229. bgp_show_type_flap_prefix,
  5230. bgp_show_type_flap_cidr_only,
  5231. bgp_show_type_flap_regexp,
  5232. bgp_show_type_flap_filter_list,
  5233. bgp_show_type_flap_prefix_list,
  5234. bgp_show_type_flap_prefix_longer,
  5235. bgp_show_type_flap_route_map,
  5236. bgp_show_type_flap_neighbor,
  5237. bgp_show_type_dampend_paths,
  5238. bgp_show_type_damp_neighbor
  5239. };
  5240. static int
  5241. bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
  5242. enum bgp_show_type type, void *output_arg)
  5243. {
  5244. struct bgp_info *ri;
  5245. struct bgp_node *rn;
  5246. int header = 1;
  5247. int display;
  5248. unsigned long output_count;
  5249. /* This is first entry point, so reset total line. */
  5250. output_count = 0;
  5251. /* Start processing of routes. */
  5252. for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
  5253. if (rn->info != NULL)
  5254. {
  5255. display = 0;
  5256. for (ri = rn->info; ri; ri = ri->next)
  5257. {
  5258. if (type == bgp_show_type_flap_statistics
  5259. || type == bgp_show_type_flap_address
  5260. || type == bgp_show_type_flap_prefix
  5261. || type == bgp_show_type_flap_cidr_only
  5262. || type == bgp_show_type_flap_regexp
  5263. || type == bgp_show_type_flap_filter_list
  5264. || type == bgp_show_type_flap_prefix_list
  5265. || type == bgp_show_type_flap_prefix_longer
  5266. || type == bgp_show_type_flap_route_map
  5267. || type == bgp_show_type_flap_neighbor
  5268. || type == bgp_show_type_dampend_paths
  5269. || type == bgp_show_type_damp_neighbor)
  5270. {
  5271. if (!(ri->extra && ri->extra->damp_info))
  5272. continue;
  5273. }
  5274. if (type == bgp_show_type_regexp
  5275. || type == bgp_show_type_flap_regexp)
  5276. {
  5277. regex_t *regex = output_arg;
  5278. if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
  5279. continue;
  5280. }
  5281. if (type == bgp_show_type_prefix_list
  5282. || type == bgp_show_type_flap_prefix_list)
  5283. {
  5284. struct prefix_list *plist = output_arg;
  5285. if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
  5286. continue;
  5287. }
  5288. if (type == bgp_show_type_filter_list
  5289. || type == bgp_show_type_flap_filter_list)
  5290. {
  5291. struct as_list *as_list = output_arg;
  5292. if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
  5293. continue;
  5294. }
  5295. if (type == bgp_show_type_route_map
  5296. || type == bgp_show_type_flap_route_map)
  5297. {
  5298. struct route_map *rmap = output_arg;
  5299. struct bgp_info binfo;
  5300. struct attr dummy_attr;
  5301. struct attr_extra dummy_extra;
  5302. int ret;
  5303. dummy_attr.extra = &dummy_extra;
  5304. bgp_attr_dup (&dummy_attr, ri->attr);
  5305. binfo.peer = ri->peer;
  5306. binfo.attr = &dummy_attr;
  5307. ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
  5308. if (ret == RMAP_DENYMATCH)
  5309. continue;
  5310. }
  5311. if (type == bgp_show_type_neighbor
  5312. || type == bgp_show_type_flap_neighbor
  5313. || type == bgp_show_type_damp_neighbor)
  5314. {
  5315. union sockunion *su = output_arg;
  5316. if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
  5317. continue;
  5318. }
  5319. if (type == bgp_show_type_cidr_only
  5320. || type == bgp_show_type_flap_cidr_only)
  5321. {
  5322. u_int32_t destination;
  5323. destination = ntohl (rn->p.u.prefix4.s_addr);
  5324. if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
  5325. continue;
  5326. if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
  5327. continue;
  5328. if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
  5329. continue;
  5330. }
  5331. if (type == bgp_show_type_prefix_longer
  5332. || type == bgp_show_type_flap_prefix_longer)
  5333. {
  5334. struct prefix *p = output_arg;
  5335. if (! prefix_match (p, &rn->p))
  5336. continue;
  5337. }
  5338. if (type == bgp_show_type_community_all)
  5339. {
  5340. if (! ri->attr->community)
  5341. continue;
  5342. }
  5343. if (type == bgp_show_type_community)
  5344. {
  5345. struct community *com = output_arg;
  5346. if (! ri->attr->community ||
  5347. ! community_match (ri->attr->community, com))
  5348. continue;
  5349. }
  5350. if (type == bgp_show_type_community_exact)
  5351. {
  5352. struct community *com = output_arg;
  5353. if (! ri->attr->community ||
  5354. ! community_cmp (ri->attr->community, com))
  5355. continue;
  5356. }
  5357. if (type == bgp_show_type_community_list)
  5358. {
  5359. struct community_list *list = output_arg;
  5360. if (! community_list_match (ri->attr->community, list))
  5361. continue;
  5362. }
  5363. if (type == bgp_show_type_community_list_exact)
  5364. {
  5365. struct community_list *list = output_arg;
  5366. if (! community_list_exact_match (ri->attr->community, list))
  5367. continue;
  5368. }
  5369. if (type == bgp_show_type_flap_address
  5370. || type == bgp_show_type_flap_prefix)
  5371. {
  5372. struct prefix *p = output_arg;
  5373. if (! prefix_match (&rn->p, p))
  5374. continue;
  5375. if (type == bgp_show_type_flap_prefix)
  5376. if (p->prefixlen != rn->p.prefixlen)
  5377. continue;
  5378. }
  5379. if (type == bgp_show_type_dampend_paths
  5380. || type == bgp_show_type_damp_neighbor)
  5381. {
  5382. if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
  5383. || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
  5384. continue;
  5385. }
  5386. if (header)
  5387. {
  5388. vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
  5389. vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
  5390. vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
  5391. if (type == bgp_show_type_dampend_paths
  5392. || type == bgp_show_type_damp_neighbor)
  5393. vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
  5394. else if (type == bgp_show_type_flap_statistics
  5395. || type == bgp_show_type_flap_address
  5396. || type == bgp_show_type_flap_prefix
  5397. || type == bgp_show_type_flap_cidr_only
  5398. || type == bgp_show_type_flap_regexp
  5399. || type == bgp_show_type_flap_filter_list
  5400. || type == bgp_show_type_flap_prefix_list
  5401. || type == bgp_show_type_flap_prefix_longer
  5402. || type == bgp_show_type_flap_route_map
  5403. || type == bgp_show_type_flap_neighbor)
  5404. vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
  5405. else
  5406. vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
  5407. header = 0;
  5408. }
  5409. if (type == bgp_show_type_dampend_paths
  5410. || type == bgp_show_type_damp_neighbor)
  5411. damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
  5412. else if (type == bgp_show_type_flap_statistics
  5413. || type == bgp_show_type_flap_address
  5414. || type == bgp_show_type_flap_prefix
  5415. || type == bgp_show_type_flap_cidr_only
  5416. || type == bgp_show_type_flap_regexp
  5417. || type == bgp_show_type_flap_filter_list
  5418. || type == bgp_show_type_flap_prefix_list
  5419. || type == bgp_show_type_flap_prefix_longer
  5420. || type == bgp_show_type_flap_route_map
  5421. || type == bgp_show_type_flap_neighbor)
  5422. flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
  5423. else
  5424. route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
  5425. display++;
  5426. }
  5427. if (display)
  5428. output_count++;
  5429. }
  5430. /* No route is displayed */
  5431. if (output_count == 0)
  5432. {
  5433. if (type == bgp_show_type_normal)
  5434. vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
  5435. }
  5436. else
  5437. vty_out (vty, "%sTotal number of prefixes %ld%s",
  5438. VTY_NEWLINE, output_count, VTY_NEWLINE);
  5439. return CMD_SUCCESS;
  5440. }
  5441. static int
  5442. bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
  5443. enum bgp_show_type type, void *output_arg)
  5444. {
  5445. struct bgp_table *table;
  5446. if (bgp == NULL) {
  5447. bgp = bgp_get_default ();
  5448. }
  5449. if (bgp == NULL)
  5450. {
  5451. vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
  5452. return CMD_WARNING;
  5453. }
  5454. table = bgp->rib[afi][safi];
  5455. return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
  5456. }
  5457. /* Header of detailed BGP route information */
  5458. static void
  5459. route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
  5460. struct bgp_node *rn,
  5461. struct prefix_rd *prd, afi_t afi, safi_t safi)
  5462. {
  5463. struct bgp_info *ri;
  5464. struct prefix *p;
  5465. struct peer *peer;
  5466. struct listnode *node, *nnode;
  5467. char buf1[INET6_ADDRSTRLEN];
  5468. char buf2[INET6_ADDRSTRLEN];
  5469. int count = 0;
  5470. int best = 0;
  5471. int suppress = 0;
  5472. int no_export = 0;
  5473. int no_advertise = 0;
  5474. int local_as = 0;
  5475. int first = 0;
  5476. p = &rn->p;
  5477. vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
  5478. (safi == SAFI_MPLS_VPN ?
  5479. prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
  5480. safi == SAFI_MPLS_VPN ? ":" : "",
  5481. inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
  5482. p->prefixlen, VTY_NEWLINE);
  5483. for (ri = rn->info; ri; ri = ri->next)
  5484. {
  5485. count++;
  5486. if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
  5487. {
  5488. best = count;
  5489. if (ri->extra && ri->extra->suppress)
  5490. suppress = 1;
  5491. if (ri->attr->community != NULL)
  5492. {
  5493. if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
  5494. no_advertise = 1;
  5495. if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
  5496. no_export = 1;
  5497. if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
  5498. local_as = 1;
  5499. }
  5500. }
  5501. }
  5502. vty_out (vty, "Paths: (%d available", count);
  5503. if (best)
  5504. {
  5505. vty_out (vty, ", best #%d", best);
  5506. if (safi == SAFI_UNICAST)
  5507. vty_out (vty, ", table Default-IP-Routing-Table");
  5508. }
  5509. else
  5510. vty_out (vty, ", no best path");
  5511. if (no_advertise)
  5512. vty_out (vty, ", not advertised to any peer");
  5513. else if (no_export)
  5514. vty_out (vty, ", not advertised to EBGP peer");
  5515. else if (local_as)
  5516. vty_out (vty, ", not advertised outside local AS");
  5517. if (suppress)
  5518. vty_out (vty, ", Advertisements suppressed by an aggregate.");
  5519. vty_out (vty, ")%s", VTY_NEWLINE);
  5520. /* advertised peer */
  5521. for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
  5522. {
  5523. if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
  5524. {
  5525. if (! first)
  5526. vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
  5527. vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
  5528. first = 1;
  5529. }
  5530. }
  5531. if (! first)
  5532. vty_out (vty, " Not advertised to any peer");
  5533. vty_out (vty, "%s", VTY_NEWLINE);
  5534. }
  5535. /* Display specified route of BGP table. */
  5536. static int
  5537. bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
  5538. struct bgp_table *rib, const char *ip_str,
  5539. afi_t afi, safi_t safi, struct prefix_rd *prd,
  5540. int prefix_check)
  5541. {
  5542. int ret;
  5543. int header;
  5544. int display = 0;
  5545. struct prefix match;
  5546. struct bgp_node *rn;
  5547. struct bgp_node *rm;
  5548. struct bgp_info *ri;
  5549. struct bgp_table *table;
  5550. /* Check IP address argument. */
  5551. ret = str2prefix (ip_str, &match);
  5552. if (! ret)
  5553. {
  5554. vty_out (vty, "address is malformed%s", VTY_NEWLINE);
  5555. return CMD_WARNING;
  5556. }
  5557. match.family = afi2family (afi);
  5558. if (safi == SAFI_MPLS_VPN)
  5559. {
  5560. for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
  5561. {
  5562. if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
  5563. continue;
  5564. if ((table = rn->info) != NULL)
  5565. {
  5566. header = 1;
  5567. if ((rm = bgp_node_match (table, &match)) != NULL)
  5568. {
  5569. if (prefix_check && rm->p.prefixlen != match.prefixlen)
  5570. {
  5571. bgp_unlock_node (rm);
  5572. continue;
  5573. }
  5574. for (ri = rm->info; ri; ri = ri->next)
  5575. {
  5576. if (header)
  5577. {
  5578. route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
  5579. AFI_IP, SAFI_MPLS_VPN);
  5580. header = 0;
  5581. }
  5582. display++;
  5583. route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
  5584. }
  5585. bgp_unlock_node (rm);
  5586. }
  5587. }
  5588. }
  5589. }
  5590. else
  5591. {
  5592. header = 1;
  5593. if ((rn = bgp_node_match (rib, &match)) != NULL)
  5594. {
  5595. if (! prefix_check || rn->p.prefixlen == match.prefixlen)
  5596. {
  5597. for (ri = rn->info; ri; ri = ri->next)
  5598. {
  5599. if (header)
  5600. {
  5601. route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
  5602. header = 0;
  5603. }
  5604. display++;
  5605. route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
  5606. }
  5607. }
  5608. bgp_unlock_node (rn);
  5609. }
  5610. }
  5611. if (! display)
  5612. {
  5613. vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
  5614. return CMD_WARNING;
  5615. }
  5616. return CMD_SUCCESS;
  5617. }
  5618. /* Display specified route of Main RIB */
  5619. static int
  5620. bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
  5621. afi_t afi, safi_t safi, struct prefix_rd *prd,
  5622. int prefix_check)
  5623. {
  5624. struct bgp *bgp;
  5625. /* BGP structure lookup. */
  5626. if (view_name)
  5627. {
  5628. bgp = bgp_lookup_by_name (view_name);
  5629. if (bgp == NULL)
  5630. {
  5631. vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
  5632. return CMD_WARNING;
  5633. }
  5634. }
  5635. else
  5636. {
  5637. bgp = bgp_get_default ();
  5638. if (bgp == NULL)
  5639. {
  5640. vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
  5641. return CMD_WARNING;
  5642. }
  5643. }
  5644. return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
  5645. afi, safi, prd, prefix_check);
  5646. }
  5647. /* BGP route print out function. */
  5648. DEFUN (show_ip_bgp,
  5649. show_ip_bgp_cmd,
  5650. "show ip bgp",
  5651. SHOW_STR
  5652. IP_STR
  5653. BGP_STR)
  5654. {
  5655. return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
  5656. }
  5657. DEFUN (show_ip_bgp_ipv4,
  5658. show_ip_bgp_ipv4_cmd,
  5659. "show ip bgp ipv4 (unicast|multicast)",
  5660. SHOW_STR
  5661. IP_STR
  5662. BGP_STR
  5663. "Address family\n"
  5664. "Address Family modifier\n"
  5665. "Address Family modifier\n")
  5666. {
  5667. if (strncmp (argv[0], "m", 1) == 0)
  5668. return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
  5669. NULL);
  5670. return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
  5671. }
  5672. ALIAS (show_ip_bgp_ipv4,
  5673. show_bgp_ipv4_safi_cmd,
  5674. "show bgp ipv4 (unicast|multicast)",
  5675. SHOW_STR
  5676. BGP_STR
  5677. "Address family\n"
  5678. "Address Family modifier\n"
  5679. "Address Family modifier\n")
  5680. DEFUN (show_ip_bgp_route,
  5681. show_ip_bgp_route_cmd,
  5682. "show ip bgp A.B.C.D",
  5683. SHOW_STR
  5684. IP_STR
  5685. BGP_STR
  5686. "Network in the BGP routing table to display\n")
  5687. {
  5688. return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
  5689. }
  5690. DEFUN (show_ip_bgp_ipv4_route,
  5691. show_ip_bgp_ipv4_route_cmd,
  5692. "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
  5693. SHOW_STR
  5694. IP_STR
  5695. BGP_STR
  5696. "Address family\n"
  5697. "Address Family modifier\n"
  5698. "Address Family modifier\n"
  5699. "Network in the BGP routing table to display\n")
  5700. {
  5701. if (strncmp (argv[0], "m", 1) == 0)
  5702. return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
  5703. return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
  5704. }
  5705. ALIAS (show_ip_bgp_ipv4_route,
  5706. show_bgp_ipv4_safi_route_cmd,
  5707. "show bgp ipv4 (unicast|multicast) A.B.C.D",
  5708. SHOW_STR
  5709. BGP_STR
  5710. "Address family\n"
  5711. "Address Family modifier\n"
  5712. "Address Family modifier\n"
  5713. "Network in the BGP routing table to display\n")
  5714. DEFUN (show_ip_bgp_vpnv4_all_route,
  5715. show_ip_bgp_vpnv4_all_route_cmd,
  5716. "show ip bgp vpnv4 all A.B.C.D",
  5717. SHOW_STR
  5718. IP_STR
  5719. BGP_STR
  5720. "Display VPNv4 NLRI specific information\n"
  5721. "Display information about all VPNv4 NLRIs\n"
  5722. "Network in the BGP routing table to display\n")
  5723. {
  5724. return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
  5725. }
  5726. DEFUN (show_ip_bgp_vpnv4_rd_route,
  5727. show_ip_bgp_vpnv4_rd_route_cmd,
  5728. "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
  5729. SHOW_STR
  5730. IP_STR
  5731. BGP_STR
  5732. "Display VPNv4 NLRI specific information\n"
  5733. "Display information for a route distinguisher\n"
  5734. "VPN Route Distinguisher\n"
  5735. "Network in the BGP routing table to display\n")
  5736. {
  5737. int ret;
  5738. struct prefix_rd prd;
  5739. ret = str2prefix_rd (argv[0], &prd);
  5740. if (! ret)
  5741. {
  5742. vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
  5743. return CMD_WARNING;
  5744. }
  5745. return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
  5746. }
  5747. DEFUN (show_ip_bgp_prefix,
  5748. show_ip_bgp_prefix_cmd,
  5749. "show ip bgp A.B.C.D/M",
  5750. SHOW_STR
  5751. IP_STR
  5752. BGP_STR
  5753. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
  5754. {
  5755. return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
  5756. }
  5757. DEFUN (show_ip_bgp_ipv4_prefix,
  5758. show_ip_bgp_ipv4_prefix_cmd,
  5759. "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
  5760. SHOW_STR
  5761. IP_STR
  5762. BGP_STR
  5763. "Address family\n"
  5764. "Address Family modifier\n"
  5765. "Address Family modifier\n"
  5766. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
  5767. {
  5768. if (strncmp (argv[0], "m", 1) == 0)
  5769. return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
  5770. return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
  5771. }
  5772. ALIAS (show_ip_bgp_ipv4_prefix,
  5773. show_bgp_ipv4_safi_prefix_cmd,
  5774. "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
  5775. SHOW_STR
  5776. BGP_STR
  5777. "Address family\n"
  5778. "Address Family modifier\n"
  5779. "Address Family modifier\n"
  5780. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
  5781. DEFUN (show_ip_bgp_vpnv4_all_prefix,
  5782. show_ip_bgp_vpnv4_all_prefix_cmd,
  5783. "show ip bgp vpnv4 all A.B.C.D/M",
  5784. SHOW_STR
  5785. IP_STR
  5786. BGP_STR
  5787. "Display VPNv4 NLRI specific information\n"
  5788. "Display information about all VPNv4 NLRIs\n"
  5789. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
  5790. {
  5791. return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
  5792. }
  5793. DEFUN (show_ip_bgp_vpnv4_rd_prefix,
  5794. show_ip_bgp_vpnv4_rd_prefix_cmd,
  5795. "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
  5796. SHOW_STR
  5797. IP_STR
  5798. BGP_STR
  5799. "Display VPNv4 NLRI specific information\n"
  5800. "Display information for a route distinguisher\n"
  5801. "VPN Route Distinguisher\n"
  5802. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
  5803. {
  5804. int ret;
  5805. struct prefix_rd prd;
  5806. ret = str2prefix_rd (argv[0], &prd);
  5807. if (! ret)
  5808. {
  5809. vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
  5810. return CMD_WARNING;
  5811. }
  5812. return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
  5813. }
  5814. DEFUN (show_ip_bgp_view,
  5815. show_ip_bgp_view_cmd,
  5816. "show ip bgp view WORD",
  5817. SHOW_STR
  5818. IP_STR
  5819. BGP_STR
  5820. "BGP view\n"
  5821. "View name\n")
  5822. {
  5823. struct bgp *bgp;
  5824. /* BGP structure lookup. */
  5825. bgp = bgp_lookup_by_name (argv[0]);
  5826. if (bgp == NULL)
  5827. {
  5828. vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
  5829. return CMD_WARNING;
  5830. }
  5831. return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
  5832. }
  5833. DEFUN (show_ip_bgp_view_route,
  5834. show_ip_bgp_view_route_cmd,
  5835. "show ip bgp view WORD A.B.C.D",
  5836. SHOW_STR
  5837. IP_STR
  5838. BGP_STR
  5839. "BGP view\n"
  5840. "View name\n"
  5841. "Network in the BGP routing table to display\n")
  5842. {
  5843. return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
  5844. }
  5845. DEFUN (show_ip_bgp_view_prefix,
  5846. show_ip_bgp_view_prefix_cmd,
  5847. "show ip bgp view WORD A.B.C.D/M",
  5848. SHOW_STR
  5849. IP_STR
  5850. BGP_STR
  5851. "BGP view\n"
  5852. "View name\n"
  5853. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
  5854. {
  5855. return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
  5856. }
  5857. #ifdef HAVE_IPV6
  5858. DEFUN (show_bgp,
  5859. show_bgp_cmd,
  5860. "show bgp",
  5861. SHOW_STR
  5862. BGP_STR)
  5863. {
  5864. return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
  5865. NULL);
  5866. }
  5867. ALIAS (show_bgp,
  5868. show_bgp_ipv6_cmd,
  5869. "show bgp ipv6",
  5870. SHOW_STR
  5871. BGP_STR
  5872. "Address family\n")
  5873. DEFUN (show_bgp_ipv6_safi,
  5874. show_bgp_ipv6_safi_cmd,
  5875. "show bgp ipv6 (unicast|multicast)",
  5876. SHOW_STR
  5877. BGP_STR
  5878. "Address family\n"
  5879. "Address Family modifier\n"
  5880. "Address Family modifier\n")
  5881. {
  5882. if (strncmp (argv[0], "m", 1) == 0)
  5883. return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
  5884. NULL);
  5885. return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
  5886. }
  5887. /* old command */
  5888. DEFUN (show_ipv6_bgp,
  5889. show_ipv6_bgp_cmd,
  5890. "show ipv6 bgp",
  5891. SHOW_STR
  5892. IP_STR
  5893. BGP_STR)
  5894. {
  5895. return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
  5896. NULL);
  5897. }
  5898. DEFUN (show_bgp_route,
  5899. show_bgp_route_cmd,
  5900. "show bgp X:X::X:X",
  5901. SHOW_STR
  5902. BGP_STR
  5903. "Network in the BGP routing table to display\n")
  5904. {
  5905. return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
  5906. }
  5907. ALIAS (show_bgp_route,
  5908. show_bgp_ipv6_route_cmd,
  5909. "show bgp ipv6 X:X::X:X",
  5910. SHOW_STR
  5911. BGP_STR
  5912. "Address family\n"
  5913. "Network in the BGP routing table to display\n")
  5914. DEFUN (show_bgp_ipv6_safi_route,
  5915. show_bgp_ipv6_safi_route_cmd,
  5916. "show bgp ipv6 (unicast|multicast) X:X::X:X",
  5917. SHOW_STR
  5918. BGP_STR
  5919. "Address family\n"
  5920. "Address Family modifier\n"
  5921. "Address Family modifier\n"
  5922. "Network in the BGP routing table to display\n")
  5923. {
  5924. if (strncmp (argv[0], "m", 1) == 0)
  5925. return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
  5926. return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
  5927. }
  5928. /* old command */
  5929. DEFUN (show_ipv6_bgp_route,
  5930. show_ipv6_bgp_route_cmd,
  5931. "show ipv6 bgp X:X::X:X",
  5932. SHOW_STR
  5933. IP_STR
  5934. BGP_STR
  5935. "Network in the BGP routing table to display\n")
  5936. {
  5937. return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
  5938. }
  5939. DEFUN (show_bgp_prefix,
  5940. show_bgp_prefix_cmd,
  5941. "show bgp X:X::X:X/M",
  5942. SHOW_STR
  5943. BGP_STR
  5944. "IPv6 prefix <network>/<length>\n")
  5945. {
  5946. return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
  5947. }
  5948. ALIAS (show_bgp_prefix,
  5949. show_bgp_ipv6_prefix_cmd,
  5950. "show bgp ipv6 X:X::X:X/M",
  5951. SHOW_STR
  5952. BGP_STR
  5953. "Address family\n"
  5954. "IPv6 prefix <network>/<length>\n")
  5955. DEFUN (show_bgp_ipv6_safi_prefix,
  5956. show_bgp_ipv6_safi_prefix_cmd,
  5957. "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
  5958. SHOW_STR
  5959. BGP_STR
  5960. "Address family\n"
  5961. "Address Family modifier\n"
  5962. "Address Family modifier\n"
  5963. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
  5964. {
  5965. if (strncmp (argv[0], "m", 1) == 0)
  5966. return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
  5967. return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
  5968. }
  5969. /* old command */
  5970. DEFUN (show_ipv6_bgp_prefix,
  5971. show_ipv6_bgp_prefix_cmd,
  5972. "show ipv6 bgp X:X::X:X/M",
  5973. SHOW_STR
  5974. IP_STR
  5975. BGP_STR
  5976. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
  5977. {
  5978. return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
  5979. }
  5980. DEFUN (show_bgp_view,
  5981. show_bgp_view_cmd,
  5982. "show bgp view WORD",
  5983. SHOW_STR
  5984. BGP_STR
  5985. "BGP view\n"
  5986. "View name\n")
  5987. {
  5988. struct bgp *bgp;
  5989. /* BGP structure lookup. */
  5990. bgp = bgp_lookup_by_name (argv[0]);
  5991. if (bgp == NULL)
  5992. {
  5993. vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
  5994. return CMD_WARNING;
  5995. }
  5996. return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
  5997. }
  5998. ALIAS (show_bgp_view,
  5999. show_bgp_view_ipv6_cmd,
  6000. "show bgp view WORD ipv6",
  6001. SHOW_STR
  6002. BGP_STR
  6003. "BGP view\n"
  6004. "View name\n"
  6005. "Address family\n")
  6006. DEFUN (show_bgp_view_route,
  6007. show_bgp_view_route_cmd,
  6008. "show bgp view WORD X:X::X:X",
  6009. SHOW_STR
  6010. BGP_STR
  6011. "BGP view\n"
  6012. "View name\n"
  6013. "Network in the BGP routing table to display\n")
  6014. {
  6015. return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
  6016. }
  6017. ALIAS (show_bgp_view_route,
  6018. show_bgp_view_ipv6_route_cmd,
  6019. "show bgp view WORD ipv6 X:X::X:X",
  6020. SHOW_STR
  6021. BGP_STR
  6022. "BGP view\n"
  6023. "View name\n"
  6024. "Address family\n"
  6025. "Network in the BGP routing table to display\n")
  6026. DEFUN (show_bgp_view_prefix,
  6027. show_bgp_view_prefix_cmd,
  6028. "show bgp view WORD X:X::X:X/M",
  6029. SHOW_STR
  6030. BGP_STR
  6031. "BGP view\n"
  6032. "View name\n"
  6033. "IPv6 prefix <network>/<length>\n")
  6034. {
  6035. return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
  6036. }
  6037. ALIAS (show_bgp_view_prefix,
  6038. show_bgp_view_ipv6_prefix_cmd,
  6039. "show bgp view WORD ipv6 X:X::X:X/M",
  6040. SHOW_STR
  6041. BGP_STR
  6042. "BGP view\n"
  6043. "View name\n"
  6044. "Address family\n"
  6045. "IPv6 prefix <network>/<length>\n")
  6046. /* old command */
  6047. DEFUN (show_ipv6_mbgp,
  6048. show_ipv6_mbgp_cmd,
  6049. "show ipv6 mbgp",
  6050. SHOW_STR
  6051. IP_STR
  6052. MBGP_STR)
  6053. {
  6054. return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
  6055. NULL);
  6056. }
  6057. /* old command */
  6058. DEFUN (show_ipv6_mbgp_route,
  6059. show_ipv6_mbgp_route_cmd,
  6060. "show ipv6 mbgp X:X::X:X",
  6061. SHOW_STR
  6062. IP_STR
  6063. MBGP_STR
  6064. "Network in the MBGP routing table to display\n")
  6065. {
  6066. return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
  6067. }
  6068. /* old command */
  6069. DEFUN (show_ipv6_mbgp_prefix,
  6070. show_ipv6_mbgp_prefix_cmd,
  6071. "show ipv6 mbgp X:X::X:X/M",
  6072. SHOW_STR
  6073. IP_STR
  6074. MBGP_STR
  6075. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
  6076. {
  6077. return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
  6078. }
  6079. #endif
  6080. static int
  6081. bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
  6082. safi_t safi, enum bgp_show_type type)
  6083. {
  6084. int i;
  6085. struct buffer *b;
  6086. char *regstr;
  6087. int first;
  6088. regex_t *regex;
  6089. int rc;
  6090. first = 0;
  6091. b = buffer_new (1024);
  6092. for (i = 0; i < argc; i++)
  6093. {
  6094. if (first)
  6095. buffer_putc (b, ' ');
  6096. else
  6097. {
  6098. if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
  6099. continue;
  6100. first = 1;
  6101. }
  6102. buffer_putstr (b, argv[i]);
  6103. }
  6104. buffer_putc (b, '\0');
  6105. regstr = buffer_getstr (b);
  6106. buffer_free (b);
  6107. regex = bgp_regcomp (regstr);
  6108. XFREE(MTYPE_TMP, regstr);
  6109. if (! regex)
  6110. {
  6111. vty_out (vty, "Can't compile regexp %s%s", argv[0],
  6112. VTY_NEWLINE);
  6113. return CMD_WARNING;
  6114. }
  6115. rc = bgp_show (vty, NULL, afi, safi, type, regex);
  6116. bgp_regex_free (regex);
  6117. return rc;
  6118. }
  6119. DEFUN (show_ip_bgp_regexp,
  6120. show_ip_bgp_regexp_cmd,
  6121. "show ip bgp regexp .LINE",
  6122. SHOW_STR
  6123. IP_STR
  6124. BGP_STR
  6125. "Display routes matching the AS path regular expression\n"
  6126. "A regular-expression to match the BGP AS paths\n")
  6127. {
  6128. return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
  6129. bgp_show_type_regexp);
  6130. }
  6131. DEFUN (show_ip_bgp_flap_regexp,
  6132. show_ip_bgp_flap_regexp_cmd,
  6133. "show ip bgp flap-statistics regexp .LINE",
  6134. SHOW_STR
  6135. IP_STR
  6136. BGP_STR
  6137. "Display flap statistics of routes\n"
  6138. "Display routes matching the AS path regular expression\n"
  6139. "A regular-expression to match the BGP AS paths\n")
  6140. {
  6141. return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
  6142. bgp_show_type_flap_regexp);
  6143. }
  6144. DEFUN (show_ip_bgp_ipv4_regexp,
  6145. show_ip_bgp_ipv4_regexp_cmd,
  6146. "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
  6147. SHOW_STR
  6148. IP_STR
  6149. BGP_STR
  6150. "Address family\n"
  6151. "Address Family modifier\n"
  6152. "Address Family modifier\n"
  6153. "Display routes matching the AS path regular expression\n"
  6154. "A regular-expression to match the BGP AS paths\n")
  6155. {
  6156. if (strncmp (argv[0], "m", 1) == 0)
  6157. return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
  6158. bgp_show_type_regexp);
  6159. return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
  6160. bgp_show_type_regexp);
  6161. }
  6162. #ifdef HAVE_IPV6
  6163. DEFUN (show_bgp_regexp,
  6164. show_bgp_regexp_cmd,
  6165. "show bgp regexp .LINE",
  6166. SHOW_STR
  6167. BGP_STR
  6168. "Display routes matching the AS path regular expression\n"
  6169. "A regular-expression to match the BGP AS paths\n")
  6170. {
  6171. return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
  6172. bgp_show_type_regexp);
  6173. }
  6174. ALIAS (show_bgp_regexp,
  6175. show_bgp_ipv6_regexp_cmd,
  6176. "show bgp ipv6 regexp .LINE",
  6177. SHOW_STR
  6178. BGP_STR
  6179. "Address family\n"
  6180. "Display routes matching the AS path regular expression\n"
  6181. "A regular-expression to match the BGP AS paths\n")
  6182. /* old command */
  6183. DEFUN (show_ipv6_bgp_regexp,
  6184. show_ipv6_bgp_regexp_cmd,
  6185. "show ipv6 bgp regexp .LINE",
  6186. SHOW_STR
  6187. IP_STR
  6188. BGP_STR
  6189. "Display routes matching the AS path regular expression\n"
  6190. "A regular-expression to match the BGP AS paths\n")
  6191. {
  6192. return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
  6193. bgp_show_type_regexp);
  6194. }
  6195. /* old command */
  6196. DEFUN (show_ipv6_mbgp_regexp,
  6197. show_ipv6_mbgp_regexp_cmd,
  6198. "show ipv6 mbgp regexp .LINE",
  6199. SHOW_STR
  6200. IP_STR
  6201. BGP_STR
  6202. "Display routes matching the AS path regular expression\n"
  6203. "A regular-expression to match the MBGP AS paths\n")
  6204. {
  6205. return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
  6206. bgp_show_type_regexp);
  6207. }
  6208. #endif /* HAVE_IPV6 */
  6209. static int
  6210. bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
  6211. safi_t safi, enum bgp_show_type type)
  6212. {
  6213. struct prefix_list *plist;
  6214. plist = prefix_list_lookup (afi, prefix_list_str);
  6215. if (plist == NULL)
  6216. {
  6217. vty_out (vty, "%% %s is not a valid prefix-list name%s",
  6218. prefix_list_str, VTY_NEWLINE);
  6219. return CMD_WARNING;
  6220. }
  6221. return bgp_show (vty, NULL, afi, safi, type, plist);
  6222. }
  6223. DEFUN (show_ip_bgp_prefix_list,
  6224. show_ip_bgp_prefix_list_cmd,
  6225. "show ip bgp prefix-list WORD",
  6226. SHOW_STR
  6227. IP_STR
  6228. BGP_STR
  6229. "Display routes conforming to the prefix-list\n"
  6230. "IP prefix-list name\n")
  6231. {
  6232. return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
  6233. bgp_show_type_prefix_list);
  6234. }
  6235. DEFUN (show_ip_bgp_flap_prefix_list,
  6236. show_ip_bgp_flap_prefix_list_cmd,
  6237. "show ip bgp flap-statistics prefix-list WORD",
  6238. SHOW_STR
  6239. IP_STR
  6240. BGP_STR
  6241. "Display flap statistics of routes\n"
  6242. "Display routes conforming to the prefix-list\n"
  6243. "IP prefix-list name\n")
  6244. {
  6245. return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
  6246. bgp_show_type_flap_prefix_list);
  6247. }
  6248. DEFUN (show_ip_bgp_ipv4_prefix_list,
  6249. show_ip_bgp_ipv4_prefix_list_cmd,
  6250. "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
  6251. SHOW_STR
  6252. IP_STR
  6253. BGP_STR
  6254. "Address family\n"
  6255. "Address Family modifier\n"
  6256. "Address Family modifier\n"
  6257. "Display routes conforming to the prefix-list\n"
  6258. "IP prefix-list name\n")
  6259. {
  6260. if (strncmp (argv[0], "m", 1) == 0)
  6261. return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
  6262. bgp_show_type_prefix_list);
  6263. return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
  6264. bgp_show_type_prefix_list);
  6265. }
  6266. #ifdef HAVE_IPV6
  6267. DEFUN (show_bgp_prefix_list,
  6268. show_bgp_prefix_list_cmd,
  6269. "show bgp prefix-list WORD",
  6270. SHOW_STR
  6271. BGP_STR
  6272. "Display routes conforming to the prefix-list\n"
  6273. "IPv6 prefix-list name\n")
  6274. {
  6275. return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
  6276. bgp_show_type_prefix_list);
  6277. }
  6278. ALIAS (show_bgp_prefix_list,
  6279. show_bgp_ipv6_prefix_list_cmd,
  6280. "show bgp ipv6 prefix-list WORD",
  6281. SHOW_STR
  6282. BGP_STR
  6283. "Address family\n"
  6284. "Display routes conforming to the prefix-list\n"
  6285. "IPv6 prefix-list name\n")
  6286. /* old command */
  6287. DEFUN (show_ipv6_bgp_prefix_list,
  6288. show_ipv6_bgp_prefix_list_cmd,
  6289. "show ipv6 bgp prefix-list WORD",
  6290. SHOW_STR
  6291. IPV6_STR
  6292. BGP_STR
  6293. "Display routes matching the prefix-list\n"
  6294. "IPv6 prefix-list name\n")
  6295. {
  6296. return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
  6297. bgp_show_type_prefix_list);
  6298. }
  6299. /* old command */
  6300. DEFUN (show_ipv6_mbgp_prefix_list,
  6301. show_ipv6_mbgp_prefix_list_cmd,
  6302. "show ipv6 mbgp prefix-list WORD",
  6303. SHOW_STR
  6304. IPV6_STR
  6305. MBGP_STR
  6306. "Display routes matching the prefix-list\n"
  6307. "IPv6 prefix-list name\n")
  6308. {
  6309. return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
  6310. bgp_show_type_prefix_list);
  6311. }
  6312. #endif /* HAVE_IPV6 */
  6313. static int
  6314. bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
  6315. safi_t safi, enum bgp_show_type type)
  6316. {
  6317. struct as_list *as_list;
  6318. as_list = as_list_lookup (filter);
  6319. if (as_list == NULL)
  6320. {
  6321. vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
  6322. return CMD_WARNING;
  6323. }
  6324. return bgp_show (vty, NULL, afi, safi, type, as_list);
  6325. }
  6326. DEFUN (show_ip_bgp_filter_list,
  6327. show_ip_bgp_filter_list_cmd,
  6328. "show ip bgp filter-list WORD",
  6329. SHOW_STR
  6330. IP_STR
  6331. BGP_STR
  6332. "Display routes conforming to the filter-list\n"
  6333. "Regular expression access list name\n")
  6334. {
  6335. return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
  6336. bgp_show_type_filter_list);
  6337. }
  6338. DEFUN (show_ip_bgp_flap_filter_list,
  6339. show_ip_bgp_flap_filter_list_cmd,
  6340. "show ip bgp flap-statistics filter-list WORD",
  6341. SHOW_STR
  6342. IP_STR
  6343. BGP_STR
  6344. "Display flap statistics of routes\n"
  6345. "Display routes conforming to the filter-list\n"
  6346. "Regular expression access list name\n")
  6347. {
  6348. return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
  6349. bgp_show_type_flap_filter_list);
  6350. }
  6351. DEFUN (show_ip_bgp_ipv4_filter_list,
  6352. show_ip_bgp_ipv4_filter_list_cmd,
  6353. "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
  6354. SHOW_STR
  6355. IP_STR
  6356. BGP_STR
  6357. "Address family\n"
  6358. "Address Family modifier\n"
  6359. "Address Family modifier\n"
  6360. "Display routes conforming to the filter-list\n"
  6361. "Regular expression access list name\n")
  6362. {
  6363. if (strncmp (argv[0], "m", 1) == 0)
  6364. return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
  6365. bgp_show_type_filter_list);
  6366. return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
  6367. bgp_show_type_filter_list);
  6368. }
  6369. #ifdef HAVE_IPV6
  6370. DEFUN (show_bgp_filter_list,
  6371. show_bgp_filter_list_cmd,
  6372. "show bgp filter-list WORD",
  6373. SHOW_STR
  6374. BGP_STR
  6375. "Display routes conforming to the filter-list\n"
  6376. "Regular expression access list name\n")
  6377. {
  6378. return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
  6379. bgp_show_type_filter_list);
  6380. }
  6381. ALIAS (show_bgp_filter_list,
  6382. show_bgp_ipv6_filter_list_cmd,
  6383. "show bgp ipv6 filter-list WORD",
  6384. SHOW_STR
  6385. BGP_STR
  6386. "Address family\n"
  6387. "Display routes conforming to the filter-list\n"
  6388. "Regular expression access list name\n")
  6389. /* old command */
  6390. DEFUN (show_ipv6_bgp_filter_list,
  6391. show_ipv6_bgp_filter_list_cmd,
  6392. "show ipv6 bgp filter-list WORD",
  6393. SHOW_STR
  6394. IPV6_STR
  6395. BGP_STR
  6396. "Display routes conforming to the filter-list\n"
  6397. "Regular expression access list name\n")
  6398. {
  6399. return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
  6400. bgp_show_type_filter_list);
  6401. }
  6402. /* old command */
  6403. DEFUN (show_ipv6_mbgp_filter_list,
  6404. show_ipv6_mbgp_filter_list_cmd,
  6405. "show ipv6 mbgp filter-list WORD",
  6406. SHOW_STR
  6407. IPV6_STR
  6408. MBGP_STR
  6409. "Display routes conforming to the filter-list\n"
  6410. "Regular expression access list name\n")
  6411. {
  6412. return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
  6413. bgp_show_type_filter_list);
  6414. }
  6415. #endif /* HAVE_IPV6 */
  6416. static int
  6417. bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
  6418. safi_t safi, enum bgp_show_type type)
  6419. {
  6420. struct route_map *rmap;
  6421. rmap = route_map_lookup_by_name (rmap_str);
  6422. if (! rmap)
  6423. {
  6424. vty_out (vty, "%% %s is not a valid route-map name%s",
  6425. rmap_str, VTY_NEWLINE);
  6426. return CMD_WARNING;
  6427. }
  6428. return bgp_show (vty, NULL, afi, safi, type, rmap);
  6429. }
  6430. DEFUN (show_ip_bgp_route_map,
  6431. show_ip_bgp_route_map_cmd,
  6432. "show ip bgp route-map WORD",
  6433. SHOW_STR
  6434. IP_STR
  6435. BGP_STR
  6436. "Display routes matching the route-map\n"
  6437. "A route-map to match on\n")
  6438. {
  6439. return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
  6440. bgp_show_type_route_map);
  6441. }
  6442. DEFUN (show_ip_bgp_flap_route_map,
  6443. show_ip_bgp_flap_route_map_cmd,
  6444. "show ip bgp flap-statistics route-map WORD",
  6445. SHOW_STR
  6446. IP_STR
  6447. BGP_STR
  6448. "Display flap statistics of routes\n"
  6449. "Display routes matching the route-map\n"
  6450. "A route-map to match on\n")
  6451. {
  6452. return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
  6453. bgp_show_type_flap_route_map);
  6454. }
  6455. DEFUN (show_ip_bgp_ipv4_route_map,
  6456. show_ip_bgp_ipv4_route_map_cmd,
  6457. "show ip bgp ipv4 (unicast|multicast) route-map WORD",
  6458. SHOW_STR
  6459. IP_STR
  6460. BGP_STR
  6461. "Address family\n"
  6462. "Address Family modifier\n"
  6463. "Address Family modifier\n"
  6464. "Display routes matching the route-map\n"
  6465. "A route-map to match on\n")
  6466. {
  6467. if (strncmp (argv[0], "m", 1) == 0)
  6468. return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
  6469. bgp_show_type_route_map);
  6470. return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
  6471. bgp_show_type_route_map);
  6472. }
  6473. DEFUN (show_bgp_route_map,
  6474. show_bgp_route_map_cmd,
  6475. "show bgp route-map WORD",
  6476. SHOW_STR
  6477. BGP_STR
  6478. "Display routes matching the route-map\n"
  6479. "A route-map to match on\n")
  6480. {
  6481. return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
  6482. bgp_show_type_route_map);
  6483. }
  6484. ALIAS (show_bgp_route_map,
  6485. show_bgp_ipv6_route_map_cmd,
  6486. "show bgp ipv6 route-map WORD",
  6487. SHOW_STR
  6488. BGP_STR
  6489. "Address family\n"
  6490. "Display routes matching the route-map\n"
  6491. "A route-map to match on\n")
  6492. DEFUN (show_ip_bgp_cidr_only,
  6493. show_ip_bgp_cidr_only_cmd,
  6494. "show ip bgp cidr-only",
  6495. SHOW_STR
  6496. IP_STR
  6497. BGP_STR
  6498. "Display only routes with non-natural netmasks\n")
  6499. {
  6500. return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
  6501. bgp_show_type_cidr_only, NULL);
  6502. }
  6503. DEFUN (show_ip_bgp_flap_cidr_only,
  6504. show_ip_bgp_flap_cidr_only_cmd,
  6505. "show ip bgp flap-statistics cidr-only",
  6506. SHOW_STR
  6507. IP_STR
  6508. BGP_STR
  6509. "Display flap statistics of routes\n"
  6510. "Display only routes with non-natural netmasks\n")
  6511. {
  6512. return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
  6513. bgp_show_type_flap_cidr_only, NULL);
  6514. }
  6515. DEFUN (show_ip_bgp_ipv4_cidr_only,
  6516. show_ip_bgp_ipv4_cidr_only_cmd,
  6517. "show ip bgp ipv4 (unicast|multicast) cidr-only",
  6518. SHOW_STR
  6519. IP_STR
  6520. BGP_STR
  6521. "Address family\n"
  6522. "Address Family modifier\n"
  6523. "Address Family modifier\n"
  6524. "Display only routes with non-natural netmasks\n")
  6525. {
  6526. if (strncmp (argv[0], "m", 1) == 0)
  6527. return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
  6528. bgp_show_type_cidr_only, NULL);
  6529. return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
  6530. bgp_show_type_cidr_only, NULL);
  6531. }
  6532. DEFUN (show_ip_bgp_community_all,
  6533. show_ip_bgp_community_all_cmd,
  6534. "show ip bgp community",
  6535. SHOW_STR
  6536. IP_STR
  6537. BGP_STR
  6538. "Display routes matching the communities\n")
  6539. {
  6540. return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
  6541. bgp_show_type_community_all, NULL);
  6542. }
  6543. DEFUN (show_ip_bgp_ipv4_community_all,
  6544. show_ip_bgp_ipv4_community_all_cmd,
  6545. "show ip bgp ipv4 (unicast|multicast) community",
  6546. SHOW_STR
  6547. IP_STR
  6548. BGP_STR
  6549. "Address family\n"
  6550. "Address Family modifier\n"
  6551. "Address Family modifier\n"
  6552. "Display routes matching the communities\n")
  6553. {
  6554. if (strncmp (argv[0], "m", 1) == 0)
  6555. return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
  6556. bgp_show_type_community_all, NULL);
  6557. return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
  6558. bgp_show_type_community_all, NULL);
  6559. }
  6560. #ifdef HAVE_IPV6
  6561. DEFUN (show_bgp_community_all,
  6562. show_bgp_community_all_cmd,
  6563. "show bgp community",
  6564. SHOW_STR
  6565. BGP_STR
  6566. "Display routes matching the communities\n")
  6567. {
  6568. return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
  6569. bgp_show_type_community_all, NULL);
  6570. }
  6571. ALIAS (show_bgp_community_all,
  6572. show_bgp_ipv6_community_all_cmd,
  6573. "show bgp ipv6 community",
  6574. SHOW_STR
  6575. BGP_STR
  6576. "Address family\n"
  6577. "Display routes matching the communities\n")
  6578. /* old command */
  6579. DEFUN (show_ipv6_bgp_community_all,
  6580. show_ipv6_bgp_community_all_cmd,
  6581. "show ipv6 bgp community",
  6582. SHOW_STR
  6583. IPV6_STR
  6584. BGP_STR
  6585. "Display routes matching the communities\n")
  6586. {
  6587. return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
  6588. bgp_show_type_community_all, NULL);
  6589. }
  6590. /* old command */
  6591. DEFUN (show_ipv6_mbgp_community_all,
  6592. show_ipv6_mbgp_community_all_cmd,
  6593. "show ipv6 mbgp community",
  6594. SHOW_STR
  6595. IPV6_STR
  6596. MBGP_STR
  6597. "Display routes matching the communities\n")
  6598. {
  6599. return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
  6600. bgp_show_type_community_all, NULL);
  6601. }
  6602. #endif /* HAVE_IPV6 */
  6603. static int
  6604. bgp_show_community (struct vty *vty, const char *view_name, int argc,
  6605. const char **argv, int exact, afi_t afi, safi_t safi)
  6606. {
  6607. struct community *com;
  6608. struct buffer *b;
  6609. struct bgp *bgp;
  6610. int i;
  6611. char *str;
  6612. int first = 0;
  6613. /* BGP structure lookup */
  6614. if (view_name)
  6615. {
  6616. bgp = bgp_lookup_by_name (view_name);
  6617. if (bgp == NULL)
  6618. {
  6619. vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
  6620. return CMD_WARNING;
  6621. }
  6622. }
  6623. else
  6624. {
  6625. bgp = bgp_get_default ();
  6626. if (bgp == NULL)
  6627. {
  6628. vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
  6629. return CMD_WARNING;
  6630. }
  6631. }
  6632. b = buffer_new (1024);
  6633. for (i = 0; i < argc; i++)
  6634. {
  6635. if (first)
  6636. buffer_putc (b, ' ');
  6637. else
  6638. {
  6639. if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
  6640. continue;
  6641. first = 1;
  6642. }
  6643. buffer_putstr (b, argv[i]);
  6644. }
  6645. buffer_putc (b, '\0');
  6646. str = buffer_getstr (b);
  6647. buffer_free (b);
  6648. com = community_str2com (str);
  6649. XFREE (MTYPE_TMP, str);
  6650. if (! com)
  6651. {
  6652. vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
  6653. return CMD_WARNING;
  6654. }
  6655. return bgp_show (vty, bgp, afi, safi,
  6656. (exact ? bgp_show_type_community_exact :
  6657. bgp_show_type_community), com);
  6658. }
  6659. DEFUN (show_ip_bgp_community,
  6660. show_ip_bgp_community_cmd,
  6661. "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
  6662. SHOW_STR
  6663. IP_STR
  6664. BGP_STR
  6665. "Display routes matching the communities\n"
  6666. "community number\n"
  6667. "Do not send outside local AS (well-known community)\n"
  6668. "Do not advertise to any peer (well-known community)\n"
  6669. "Do not export to next AS (well-known community)\n")
  6670. {
  6671. return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
  6672. }
  6673. ALIAS (show_ip_bgp_community,
  6674. show_ip_bgp_community2_cmd,
  6675. "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
  6676. SHOW_STR
  6677. IP_STR
  6678. BGP_STR
  6679. "Display routes matching the communities\n"
  6680. "community number\n"
  6681. "Do not send outside local AS (well-known community)\n"
  6682. "Do not advertise to any peer (well-known community)\n"
  6683. "Do not export to next AS (well-known community)\n"
  6684. "community number\n"
  6685. "Do not send outside local AS (well-known community)\n"
  6686. "Do not advertise to any peer (well-known community)\n"
  6687. "Do not export to next AS (well-known community)\n")
  6688. ALIAS (show_ip_bgp_community,
  6689. show_ip_bgp_community3_cmd,
  6690. "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
  6691. SHOW_STR
  6692. IP_STR
  6693. BGP_STR
  6694. "Display routes matching the communities\n"
  6695. "community number\n"
  6696. "Do not send outside local AS (well-known community)\n"
  6697. "Do not advertise to any peer (well-known community)\n"
  6698. "Do not export to next AS (well-known community)\n"
  6699. "community number\n"
  6700. "Do not send outside local AS (well-known community)\n"
  6701. "Do not advertise to any peer (well-known community)\n"
  6702. "Do not export to next AS (well-known community)\n"
  6703. "community number\n"
  6704. "Do not send outside local AS (well-known community)\n"
  6705. "Do not advertise to any peer (well-known community)\n"
  6706. "Do not export to next AS (well-known community)\n")
  6707. ALIAS (show_ip_bgp_community,
  6708. show_ip_bgp_community4_cmd,
  6709. "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
  6710. SHOW_STR
  6711. IP_STR
  6712. BGP_STR
  6713. "Display routes matching the communities\n"
  6714. "community number\n"
  6715. "Do not send outside local AS (well-known community)\n"
  6716. "Do not advertise to any peer (well-known community)\n"
  6717. "Do not export to next AS (well-known community)\n"
  6718. "community number\n"
  6719. "Do not send outside local AS (well-known community)\n"
  6720. "Do not advertise to any peer (well-known community)\n"
  6721. "Do not export to next AS (well-known community)\n"
  6722. "community number\n"
  6723. "Do not send outside local AS (well-known community)\n"
  6724. "Do not advertise to any peer (well-known community)\n"
  6725. "Do not export to next AS (well-known community)\n"
  6726. "community number\n"
  6727. "Do not send outside local AS (well-known community)\n"
  6728. "Do not advertise to any peer (well-known community)\n"
  6729. "Do not export to next AS (well-known community)\n")
  6730. DEFUN (show_ip_bgp_ipv4_community,
  6731. show_ip_bgp_ipv4_community_cmd,
  6732. "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
  6733. SHOW_STR
  6734. IP_STR
  6735. BGP_STR
  6736. "Address family\n"
  6737. "Address Family modifier\n"
  6738. "Address Family modifier\n"
  6739. "Display routes matching the communities\n"
  6740. "community number\n"
  6741. "Do not send outside local AS (well-known community)\n"
  6742. "Do not advertise to any peer (well-known community)\n"
  6743. "Do not export to next AS (well-known community)\n")
  6744. {
  6745. if (strncmp (argv[0], "m", 1) == 0)
  6746. return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
  6747. return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
  6748. }
  6749. ALIAS (show_ip_bgp_ipv4_community,
  6750. show_ip_bgp_ipv4_community2_cmd,
  6751. "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
  6752. SHOW_STR
  6753. IP_STR
  6754. BGP_STR
  6755. "Address family\n"
  6756. "Address Family modifier\n"
  6757. "Address Family modifier\n"
  6758. "Display routes matching the communities\n"
  6759. "community number\n"
  6760. "Do not send outside local AS (well-known community)\n"
  6761. "Do not advertise to any peer (well-known community)\n"
  6762. "Do not export to next AS (well-known community)\n"
  6763. "community number\n"
  6764. "Do not send outside local AS (well-known community)\n"
  6765. "Do not advertise to any peer (well-known community)\n"
  6766. "Do not export to next AS (well-known community)\n")
  6767. ALIAS (show_ip_bgp_ipv4_community,
  6768. show_ip_bgp_ipv4_community3_cmd,
  6769. "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
  6770. SHOW_STR
  6771. IP_STR
  6772. BGP_STR
  6773. "Address family\n"
  6774. "Address Family modifier\n"
  6775. "Address Family modifier\n"
  6776. "Display routes matching the communities\n"
  6777. "community number\n"
  6778. "Do not send outside local AS (well-known community)\n"
  6779. "Do not advertise to any peer (well-known community)\n"
  6780. "Do not export to next AS (well-known community)\n"
  6781. "community number\n"
  6782. "Do not send outside local AS (well-known community)\n"
  6783. "Do not advertise to any peer (well-known community)\n"
  6784. "Do not export to next AS (well-known community)\n"
  6785. "community number\n"
  6786. "Do not send outside local AS (well-known community)\n"
  6787. "Do not advertise to any peer (well-known community)\n"
  6788. "Do not export to next AS (well-known community)\n")
  6789. ALIAS (show_ip_bgp_ipv4_community,
  6790. show_ip_bgp_ipv4_community4_cmd,
  6791. "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
  6792. SHOW_STR
  6793. IP_STR
  6794. BGP_STR
  6795. "Address family\n"
  6796. "Address Family modifier\n"
  6797. "Address Family modifier\n"
  6798. "Display routes matching the communities\n"
  6799. "community number\n"
  6800. "Do not send outside local AS (well-known community)\n"
  6801. "Do not advertise to any peer (well-known community)\n"
  6802. "Do not export to next AS (well-known community)\n"
  6803. "community number\n"
  6804. "Do not send outside local AS (well-known community)\n"
  6805. "Do not advertise to any peer (well-known community)\n"
  6806. "Do not export to next AS (well-known community)\n"
  6807. "community number\n"
  6808. "Do not send outside local AS (well-known community)\n"
  6809. "Do not advertise to any peer (well-known community)\n"
  6810. "Do not export to next AS (well-known community)\n"
  6811. "community number\n"
  6812. "Do not send outside local AS (well-known community)\n"
  6813. "Do not advertise to any peer (well-known community)\n"
  6814. "Do not export to next AS (well-known community)\n")
  6815. DEFUN (show_bgp_view_afi_safi_community_all,
  6816. show_bgp_view_afi_safi_community_all_cmd,
  6817. #ifdef HAVE_IPV6
  6818. "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
  6819. #else
  6820. "show bgp view WORD ipv4 (unicast|multicast) community",
  6821. #endif
  6822. SHOW_STR
  6823. BGP_STR
  6824. "BGP view\n"
  6825. "View name\n"
  6826. "Address family\n"
  6827. #ifdef HAVE_IPV6
  6828. "Address family\n"
  6829. #endif
  6830. "Address Family modifier\n"
  6831. "Address Family modifier\n"
  6832. "Display routes matching the communities\n")
  6833. {
  6834. int afi;
  6835. int safi;
  6836. struct bgp *bgp;
  6837. /* BGP structure lookup. */
  6838. bgp = bgp_lookup_by_name (argv[0]);
  6839. if (bgp == NULL)
  6840. {
  6841. vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
  6842. return CMD_WARNING;
  6843. }
  6844. #ifdef HAVE_IPV6
  6845. afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
  6846. safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
  6847. #else
  6848. afi = AFI_IP;
  6849. safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
  6850. #endif
  6851. return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
  6852. }
  6853. DEFUN (show_bgp_view_afi_safi_community,
  6854. show_bgp_view_afi_safi_community_cmd,
  6855. #ifdef HAVE_IPV6
  6856. "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
  6857. #else
  6858. "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
  6859. #endif
  6860. SHOW_STR
  6861. BGP_STR
  6862. "BGP view\n"
  6863. "View name\n"
  6864. "Address family\n"
  6865. #ifdef HAVE_IPV6
  6866. "Address family\n"
  6867. #endif
  6868. "Address family modifier\n"
  6869. "Address family modifier\n"
  6870. "Display routes matching the communities\n"
  6871. "community number\n"
  6872. "Do not send outside local AS (well-known community)\n"
  6873. "Do not advertise to any peer (well-known community)\n"
  6874. "Do not export to next AS (well-known community)\n")
  6875. {
  6876. int afi;
  6877. int safi;
  6878. #ifdef HAVE_IPV6
  6879. afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
  6880. safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
  6881. return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
  6882. #else
  6883. afi = AFI_IP;
  6884. safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
  6885. return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
  6886. #endif
  6887. }
  6888. ALIAS (show_bgp_view_afi_safi_community,
  6889. show_bgp_view_afi_safi_community2_cmd,
  6890. #ifdef HAVE_IPV6
  6891. "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
  6892. #else
  6893. "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
  6894. #endif
  6895. SHOW_STR
  6896. BGP_STR
  6897. "BGP view\n"
  6898. "View name\n"
  6899. "Address family\n"
  6900. #ifdef HAVE_IPV6
  6901. "Address family\n"
  6902. #endif
  6903. "Address family modifier\n"
  6904. "Address family modifier\n"
  6905. "Display routes matching the communities\n"
  6906. "community number\n"
  6907. "Do not send outside local AS (well-known community)\n"
  6908. "Do not advertise to any peer (well-known community)\n"
  6909. "Do not export to next AS (well-known community)\n"
  6910. "community number\n"
  6911. "Do not send outside local AS (well-known community)\n"
  6912. "Do not advertise to any peer (well-known community)\n"
  6913. "Do not export to next AS (well-known community)\n")
  6914. ALIAS (show_bgp_view_afi_safi_community,
  6915. show_bgp_view_afi_safi_community3_cmd,
  6916. #ifdef HAVE_IPV6
  6917. "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
  6918. #else
  6919. "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
  6920. #endif
  6921. SHOW_STR
  6922. BGP_STR
  6923. "BGP view\n"
  6924. "View name\n"
  6925. "Address family\n"
  6926. #ifdef HAVE_IPV6
  6927. "Address family\n"
  6928. #endif
  6929. "Address family modifier\n"
  6930. "Address family modifier\n"
  6931. "Display routes matching the communities\n"
  6932. "community number\n"
  6933. "Do not send outside local AS (well-known community)\n"
  6934. "Do not advertise to any peer (well-known community)\n"
  6935. "Do not export to next AS (well-known community)\n"
  6936. "community number\n"
  6937. "Do not send outside local AS (well-known community)\n"
  6938. "Do not advertise to any peer (well-known community)\n"
  6939. "Do not export to next AS (well-known community)\n"
  6940. "community number\n"
  6941. "Do not send outside local AS (well-known community)\n"
  6942. "Do not advertise to any peer (well-known community)\n"
  6943. "Do not export to next AS (well-known community)\n")
  6944. ALIAS (show_bgp_view_afi_safi_community,
  6945. show_bgp_view_afi_safi_community4_cmd,
  6946. #ifdef HAVE_IPV6
  6947. "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
  6948. #else
  6949. "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
  6950. #endif
  6951. SHOW_STR
  6952. BGP_STR
  6953. "BGP view\n"
  6954. "View name\n"
  6955. "Address family\n"
  6956. #ifdef HAVE_IPV6
  6957. "Address family\n"
  6958. #endif
  6959. "Address family modifier\n"
  6960. "Address family modifier\n"
  6961. "Display routes matching the communities\n"
  6962. "community number\n"
  6963. "Do not send outside local AS (well-known community)\n"
  6964. "Do not advertise to any peer (well-known community)\n"
  6965. "Do not export to next AS (well-known community)\n"
  6966. "community number\n"
  6967. "Do not send outside local AS (well-known community)\n"
  6968. "Do not advertise to any peer (well-known community)\n"
  6969. "Do not export to next AS (well-known community)\n"
  6970. "community number\n"
  6971. "Do not send outside local AS (well-known community)\n"
  6972. "Do not advertise to any peer (well-known community)\n"
  6973. "Do not export to next AS (well-known community)\n"
  6974. "community number\n"
  6975. "Do not send outside local AS (well-known community)\n"
  6976. "Do not advertise to any peer (well-known community)\n"
  6977. "Do not export to next AS (well-known community)\n")
  6978. DEFUN (show_ip_bgp_community_exact,
  6979. show_ip_bgp_community_exact_cmd,
  6980. "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
  6981. SHOW_STR
  6982. IP_STR
  6983. BGP_STR
  6984. "Display routes matching the communities\n"
  6985. "community number\n"
  6986. "Do not send outside local AS (well-known community)\n"
  6987. "Do not advertise to any peer (well-known community)\n"
  6988. "Do not export to next AS (well-known community)\n"
  6989. "Exact match of the communities")
  6990. {
  6991. return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
  6992. }
  6993. ALIAS (show_ip_bgp_community_exact,
  6994. show_ip_bgp_community2_exact_cmd,
  6995. "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
  6996. SHOW_STR
  6997. IP_STR
  6998. BGP_STR
  6999. "Display routes matching the communities\n"
  7000. "community number\n"
  7001. "Do not send outside local AS (well-known community)\n"
  7002. "Do not advertise to any peer (well-known community)\n"
  7003. "Do not export to next AS (well-known community)\n"
  7004. "community number\n"
  7005. "Do not send outside local AS (well-known community)\n"
  7006. "Do not advertise to any peer (well-known community)\n"
  7007. "Do not export to next AS (well-known community)\n"
  7008. "Exact match of the communities")
  7009. ALIAS (show_ip_bgp_community_exact,
  7010. show_ip_bgp_community3_exact_cmd,
  7011. "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
  7012. SHOW_STR
  7013. IP_STR
  7014. BGP_STR
  7015. "Display routes matching the communities\n"
  7016. "community number\n"
  7017. "Do not send outside local AS (well-known community)\n"
  7018. "Do not advertise to any peer (well-known community)\n"
  7019. "Do not export to next AS (well-known community)\n"
  7020. "community number\n"
  7021. "Do not send outside local AS (well-known community)\n"
  7022. "Do not advertise to any peer (well-known community)\n"
  7023. "Do not export to next AS (well-known community)\n"
  7024. "community number\n"
  7025. "Do not send outside local AS (well-known community)\n"
  7026. "Do not advertise to any peer (well-known community)\n"
  7027. "Do not export to next AS (well-known community)\n"
  7028. "Exact match of the communities")
  7029. ALIAS (show_ip_bgp_community_exact,
  7030. show_ip_bgp_community4_exact_cmd,
  7031. "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
  7032. SHOW_STR
  7033. IP_STR
  7034. BGP_STR
  7035. "Display routes matching the communities\n"
  7036. "community number\n"
  7037. "Do not send outside local AS (well-known community)\n"
  7038. "Do not advertise to any peer (well-known community)\n"
  7039. "Do not export to next AS (well-known community)\n"
  7040. "community number\n"
  7041. "Do not send outside local AS (well-known community)\n"
  7042. "Do not advertise to any peer (well-known community)\n"
  7043. "Do not export to next AS (well-known community)\n"
  7044. "community number\n"
  7045. "Do not send outside local AS (well-known community)\n"
  7046. "Do not advertise to any peer (well-known community)\n"
  7047. "Do not export to next AS (well-known community)\n"
  7048. "community number\n"
  7049. "Do not send outside local AS (well-known community)\n"
  7050. "Do not advertise to any peer (well-known community)\n"
  7051. "Do not export to next AS (well-known community)\n"
  7052. "Exact match of the communities")
  7053. DEFUN (show_ip_bgp_ipv4_community_exact,
  7054. show_ip_bgp_ipv4_community_exact_cmd,
  7055. "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
  7056. SHOW_STR
  7057. IP_STR
  7058. BGP_STR
  7059. "Address family\n"
  7060. "Address Family modifier\n"
  7061. "Address Family modifier\n"
  7062. "Display routes matching the communities\n"
  7063. "community number\n"
  7064. "Do not send outside local AS (well-known community)\n"
  7065. "Do not advertise to any peer (well-known community)\n"
  7066. "Do not export to next AS (well-known community)\n"
  7067. "Exact match of the communities")
  7068. {
  7069. if (strncmp (argv[0], "m", 1) == 0)
  7070. return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
  7071. return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
  7072. }
  7073. ALIAS (show_ip_bgp_ipv4_community_exact,
  7074. show_ip_bgp_ipv4_community2_exact_cmd,
  7075. "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
  7076. SHOW_STR
  7077. IP_STR
  7078. BGP_STR
  7079. "Address family\n"
  7080. "Address Family modifier\n"
  7081. "Address Family modifier\n"
  7082. "Display routes matching the communities\n"
  7083. "community number\n"
  7084. "Do not send outside local AS (well-known community)\n"
  7085. "Do not advertise to any peer (well-known community)\n"
  7086. "Do not export to next AS (well-known community)\n"
  7087. "community number\n"
  7088. "Do not send outside local AS (well-known community)\n"
  7089. "Do not advertise to any peer (well-known community)\n"
  7090. "Do not export to next AS (well-known community)\n"
  7091. "Exact match of the communities")
  7092. ALIAS (show_ip_bgp_ipv4_community_exact,
  7093. show_ip_bgp_ipv4_community3_exact_cmd,
  7094. "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
  7095. SHOW_STR
  7096. IP_STR
  7097. BGP_STR
  7098. "Address family\n"
  7099. "Address Family modifier\n"
  7100. "Address Family modifier\n"
  7101. "Display routes matching the communities\n"
  7102. "community number\n"
  7103. "Do not send outside local AS (well-known community)\n"
  7104. "Do not advertise to any peer (well-known community)\n"
  7105. "Do not export to next AS (well-known community)\n"
  7106. "community number\n"
  7107. "Do not send outside local AS (well-known community)\n"
  7108. "Do not advertise to any peer (well-known community)\n"
  7109. "Do not export to next AS (well-known community)\n"
  7110. "community number\n"
  7111. "Do not send outside local AS (well-known community)\n"
  7112. "Do not advertise to any peer (well-known community)\n"
  7113. "Do not export to next AS (well-known community)\n"
  7114. "Exact match of the communities")
  7115. ALIAS (show_ip_bgp_ipv4_community_exact,
  7116. show_ip_bgp_ipv4_community4_exact_cmd,
  7117. "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
  7118. SHOW_STR
  7119. IP_STR
  7120. BGP_STR
  7121. "Address family\n"
  7122. "Address Family modifier\n"
  7123. "Address Family modifier\n"
  7124. "Display routes matching the communities\n"
  7125. "community number\n"
  7126. "Do not send outside local AS (well-known community)\n"
  7127. "Do not advertise to any peer (well-known community)\n"
  7128. "Do not export to next AS (well-known community)\n"
  7129. "community number\n"
  7130. "Do not send outside local AS (well-known community)\n"
  7131. "Do not advertise to any peer (well-known community)\n"
  7132. "Do not export to next AS (well-known community)\n"
  7133. "community number\n"
  7134. "Do not send outside local AS (well-known community)\n"
  7135. "Do not advertise to any peer (well-known community)\n"
  7136. "Do not export to next AS (well-known community)\n"
  7137. "community number\n"
  7138. "Do not send outside local AS (well-known community)\n"
  7139. "Do not advertise to any peer (well-known community)\n"
  7140. "Do not export to next AS (well-known community)\n"
  7141. "Exact match of the communities")
  7142. #ifdef HAVE_IPV6
  7143. DEFUN (show_bgp_community,
  7144. show_bgp_community_cmd,
  7145. "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
  7146. SHOW_STR
  7147. BGP_STR
  7148. "Display routes matching the communities\n"
  7149. "community number\n"
  7150. "Do not send outside local AS (well-known community)\n"
  7151. "Do not advertise to any peer (well-known community)\n"
  7152. "Do not export to next AS (well-known community)\n")
  7153. {
  7154. return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
  7155. }
  7156. ALIAS (show_bgp_community,
  7157. show_bgp_ipv6_community_cmd,
  7158. "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
  7159. SHOW_STR
  7160. BGP_STR
  7161. "Address family\n"
  7162. "Display routes matching the communities\n"
  7163. "community number\n"
  7164. "Do not send outside local AS (well-known community)\n"
  7165. "Do not advertise to any peer (well-known community)\n"
  7166. "Do not export to next AS (well-known community)\n")
  7167. ALIAS (show_bgp_community,
  7168. show_bgp_community2_cmd,
  7169. "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
  7170. SHOW_STR
  7171. BGP_STR
  7172. "Display routes matching the communities\n"
  7173. "community number\n"
  7174. "Do not send outside local AS (well-known community)\n"
  7175. "Do not advertise to any peer (well-known community)\n"
  7176. "Do not export to next AS (well-known community)\n"
  7177. "community number\n"
  7178. "Do not send outside local AS (well-known community)\n"
  7179. "Do not advertise to any peer (well-known community)\n"
  7180. "Do not export to next AS (well-known community)\n")
  7181. ALIAS (show_bgp_community,
  7182. show_bgp_ipv6_community2_cmd,
  7183. "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
  7184. SHOW_STR
  7185. BGP_STR
  7186. "Address family\n"
  7187. "Display routes matching the communities\n"
  7188. "community number\n"
  7189. "Do not send outside local AS (well-known community)\n"
  7190. "Do not advertise to any peer (well-known community)\n"
  7191. "Do not export to next AS (well-known community)\n"
  7192. "community number\n"
  7193. "Do not send outside local AS (well-known community)\n"
  7194. "Do not advertise to any peer (well-known community)\n"
  7195. "Do not export to next AS (well-known community)\n")
  7196. ALIAS (show_bgp_community,
  7197. show_bgp_community3_cmd,
  7198. "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
  7199. SHOW_STR
  7200. BGP_STR
  7201. "Display routes matching the communities\n"
  7202. "community number\n"
  7203. "Do not send outside local AS (well-known community)\n"
  7204. "Do not advertise to any peer (well-known community)\n"
  7205. "Do not export to next AS (well-known community)\n"
  7206. "community number\n"
  7207. "Do not send outside local AS (well-known community)\n"
  7208. "Do not advertise to any peer (well-known community)\n"
  7209. "Do not export to next AS (well-known community)\n"
  7210. "community number\n"
  7211. "Do not send outside local AS (well-known community)\n"
  7212. "Do not advertise to any peer (well-known community)\n"
  7213. "Do not export to next AS (well-known community)\n")
  7214. ALIAS (show_bgp_community,
  7215. show_bgp_ipv6_community3_cmd,
  7216. "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
  7217. SHOW_STR
  7218. BGP_STR
  7219. "Address family\n"
  7220. "Display routes matching the communities\n"
  7221. "community number\n"
  7222. "Do not send outside local AS (well-known community)\n"
  7223. "Do not advertise to any peer (well-known community)\n"
  7224. "Do not export to next AS (well-known community)\n"
  7225. "community number\n"
  7226. "Do not send outside local AS (well-known community)\n"
  7227. "Do not advertise to any peer (well-known community)\n"
  7228. "Do not export to next AS (well-known community)\n"
  7229. "community number\n"
  7230. "Do not send outside local AS (well-known community)\n"
  7231. "Do not advertise to any peer (well-known community)\n"
  7232. "Do not export to next AS (well-known community)\n")
  7233. ALIAS (show_bgp_community,
  7234. show_bgp_community4_cmd,
  7235. "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
  7236. SHOW_STR
  7237. BGP_STR
  7238. "Display routes matching the communities\n"
  7239. "community number\n"
  7240. "Do not send outside local AS (well-known community)\n"
  7241. "Do not advertise to any peer (well-known community)\n"
  7242. "Do not export to next AS (well-known community)\n"
  7243. "community number\n"
  7244. "Do not send outside local AS (well-known community)\n"
  7245. "Do not advertise to any peer (well-known community)\n"
  7246. "Do not export to next AS (well-known community)\n"
  7247. "community number\n"
  7248. "Do not send outside local AS (well-known community)\n"
  7249. "Do not advertise to any peer (well-known community)\n"
  7250. "Do not export to next AS (well-known community)\n"
  7251. "community number\n"
  7252. "Do not send outside local AS (well-known community)\n"
  7253. "Do not advertise to any peer (well-known community)\n"
  7254. "Do not export to next AS (well-known community)\n")
  7255. ALIAS (show_bgp_community,
  7256. show_bgp_ipv6_community4_cmd,
  7257. "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
  7258. SHOW_STR
  7259. BGP_STR
  7260. "Address family\n"
  7261. "Display routes matching the communities\n"
  7262. "community number\n"
  7263. "Do not send outside local AS (well-known community)\n"
  7264. "Do not advertise to any peer (well-known community)\n"
  7265. "Do not export to next AS (well-known community)\n"
  7266. "community number\n"
  7267. "Do not send outside local AS (well-known community)\n"
  7268. "Do not advertise to any peer (well-known community)\n"
  7269. "Do not export to next AS (well-known community)\n"
  7270. "community number\n"
  7271. "Do not send outside local AS (well-known community)\n"
  7272. "Do not advertise to any peer (well-known community)\n"
  7273. "Do not export to next AS (well-known community)\n"
  7274. "community number\n"
  7275. "Do not send outside local AS (well-known community)\n"
  7276. "Do not advertise to any peer (well-known community)\n"
  7277. "Do not export to next AS (well-known community)\n")
  7278. /* old command */
  7279. DEFUN (show_ipv6_bgp_community,
  7280. show_ipv6_bgp_community_cmd,
  7281. "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
  7282. SHOW_STR
  7283. IPV6_STR
  7284. BGP_STR
  7285. "Display routes matching the communities\n"
  7286. "community number\n"
  7287. "Do not send outside local AS (well-known community)\n"
  7288. "Do not advertise to any peer (well-known community)\n"
  7289. "Do not export to next AS (well-known community)\n")
  7290. {
  7291. return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
  7292. }
  7293. /* old command */
  7294. ALIAS (show_ipv6_bgp_community,
  7295. show_ipv6_bgp_community2_cmd,
  7296. "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
  7297. SHOW_STR
  7298. IPV6_STR
  7299. BGP_STR
  7300. "Display routes matching the communities\n"
  7301. "community number\n"
  7302. "Do not send outside local AS (well-known community)\n"
  7303. "Do not advertise to any peer (well-known community)\n"
  7304. "Do not export to next AS (well-known community)\n"
  7305. "community number\n"
  7306. "Do not send outside local AS (well-known community)\n"
  7307. "Do not advertise to any peer (well-known community)\n"
  7308. "Do not export to next AS (well-known community)\n")
  7309. /* old command */
  7310. ALIAS (show_ipv6_bgp_community,
  7311. show_ipv6_bgp_community3_cmd,
  7312. "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
  7313. SHOW_STR
  7314. IPV6_STR
  7315. BGP_STR
  7316. "Display routes matching the communities\n"
  7317. "community number\n"
  7318. "Do not send outside local AS (well-known community)\n"
  7319. "Do not advertise to any peer (well-known community)\n"
  7320. "Do not export to next AS (well-known community)\n"
  7321. "community number\n"
  7322. "Do not send outside local AS (well-known community)\n"
  7323. "Do not advertise to any peer (well-known community)\n"
  7324. "Do not export to next AS (well-known community)\n"
  7325. "community number\n"
  7326. "Do not send outside local AS (well-known community)\n"
  7327. "Do not advertise to any peer (well-known community)\n"
  7328. "Do not export to next AS (well-known community)\n")
  7329. /* old command */
  7330. ALIAS (show_ipv6_bgp_community,
  7331. show_ipv6_bgp_community4_cmd,
  7332. "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
  7333. SHOW_STR
  7334. IPV6_STR
  7335. BGP_STR
  7336. "Display routes matching the communities\n"
  7337. "community number\n"
  7338. "Do not send outside local AS (well-known community)\n"
  7339. "Do not advertise to any peer (well-known community)\n"
  7340. "Do not export to next AS (well-known community)\n"
  7341. "community number\n"
  7342. "Do not send outside local AS (well-known community)\n"
  7343. "Do not advertise to any peer (well-known community)\n"
  7344. "Do not export to next AS (well-known community)\n"
  7345. "community number\n"
  7346. "Do not send outside local AS (well-known community)\n"
  7347. "Do not advertise to any peer (well-known community)\n"
  7348. "Do not export to next AS (well-known community)\n"
  7349. "community number\n"
  7350. "Do not send outside local AS (well-known community)\n"
  7351. "Do not advertise to any peer (well-known community)\n"
  7352. "Do not export to next AS (well-known community)\n")
  7353. DEFUN (show_bgp_community_exact,
  7354. show_bgp_community_exact_cmd,
  7355. "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
  7356. SHOW_STR
  7357. BGP_STR
  7358. "Display routes matching the communities\n"
  7359. "community number\n"
  7360. "Do not send outside local AS (well-known community)\n"
  7361. "Do not advertise to any peer (well-known community)\n"
  7362. "Do not export to next AS (well-known community)\n"
  7363. "Exact match of the communities")
  7364. {
  7365. return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
  7366. }
  7367. ALIAS (show_bgp_community_exact,
  7368. show_bgp_ipv6_community_exact_cmd,
  7369. "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
  7370. SHOW_STR
  7371. BGP_STR
  7372. "Address family\n"
  7373. "Display routes matching the communities\n"
  7374. "community number\n"
  7375. "Do not send outside local AS (well-known community)\n"
  7376. "Do not advertise to any peer (well-known community)\n"
  7377. "Do not export to next AS (well-known community)\n"
  7378. "Exact match of the communities")
  7379. ALIAS (show_bgp_community_exact,
  7380. show_bgp_community2_exact_cmd,
  7381. "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
  7382. SHOW_STR
  7383. BGP_STR
  7384. "Display routes matching the communities\n"
  7385. "community number\n"
  7386. "Do not send outside local AS (well-known community)\n"
  7387. "Do not advertise to any peer (well-known community)\n"
  7388. "Do not export to next AS (well-known community)\n"
  7389. "community number\n"
  7390. "Do not send outside local AS (well-known community)\n"
  7391. "Do not advertise to any peer (well-known community)\n"
  7392. "Do not export to next AS (well-known community)\n"
  7393. "Exact match of the communities")
  7394. ALIAS (show_bgp_community_exact,
  7395. show_bgp_ipv6_community2_exact_cmd,
  7396. "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
  7397. SHOW_STR
  7398. BGP_STR
  7399. "Address family\n"
  7400. "Display routes matching the communities\n"
  7401. "community number\n"
  7402. "Do not send outside local AS (well-known community)\n"
  7403. "Do not advertise to any peer (well-known community)\n"
  7404. "Do not export to next AS (well-known community)\n"
  7405. "community number\n"
  7406. "Do not send outside local AS (well-known community)\n"
  7407. "Do not advertise to any peer (well-known community)\n"
  7408. "Do not export to next AS (well-known community)\n"
  7409. "Exact match of the communities")
  7410. ALIAS (show_bgp_community_exact,
  7411. show_bgp_community3_exact_cmd,
  7412. "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
  7413. SHOW_STR
  7414. BGP_STR
  7415. "Display routes matching the communities\n"
  7416. "community number\n"
  7417. "Do not send outside local AS (well-known community)\n"
  7418. "Do not advertise to any peer (well-known community)\n"
  7419. "Do not export to next AS (well-known community)\n"
  7420. "community number\n"
  7421. "Do not send outside local AS (well-known community)\n"
  7422. "Do not advertise to any peer (well-known community)\n"
  7423. "Do not export to next AS (well-known community)\n"
  7424. "community number\n"
  7425. "Do not send outside local AS (well-known community)\n"
  7426. "Do not advertise to any peer (well-known community)\n"
  7427. "Do not export to next AS (well-known community)\n"
  7428. "Exact match of the communities")
  7429. ALIAS (show_bgp_community_exact,
  7430. show_bgp_ipv6_community3_exact_cmd,
  7431. "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
  7432. SHOW_STR
  7433. BGP_STR
  7434. "Address family\n"
  7435. "Display routes matching the communities\n"
  7436. "community number\n"
  7437. "Do not send outside local AS (well-known community)\n"
  7438. "Do not advertise to any peer (well-known community)\n"
  7439. "Do not export to next AS (well-known community)\n"
  7440. "community number\n"
  7441. "Do not send outside local AS (well-known community)\n"
  7442. "Do not advertise to any peer (well-known community)\n"
  7443. "Do not export to next AS (well-known community)\n"
  7444. "community number\n"
  7445. "Do not send outside local AS (well-known community)\n"
  7446. "Do not advertise to any peer (well-known community)\n"
  7447. "Do not export to next AS (well-known community)\n"
  7448. "Exact match of the communities")
  7449. ALIAS (show_bgp_community_exact,
  7450. show_bgp_community4_exact_cmd,
  7451. "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
  7452. SHOW_STR
  7453. BGP_STR
  7454. "Display routes matching the communities\n"
  7455. "community number\n"
  7456. "Do not send outside local AS (well-known community)\n"
  7457. "Do not advertise to any peer (well-known community)\n"
  7458. "Do not export to next AS (well-known community)\n"
  7459. "community number\n"
  7460. "Do not send outside local AS (well-known community)\n"
  7461. "Do not advertise to any peer (well-known community)\n"
  7462. "Do not export to next AS (well-known community)\n"
  7463. "community number\n"
  7464. "Do not send outside local AS (well-known community)\n"
  7465. "Do not advertise to any peer (well-known community)\n"
  7466. "Do not export to next AS (well-known community)\n"
  7467. "community number\n"
  7468. "Do not send outside local AS (well-known community)\n"
  7469. "Do not advertise to any peer (well-known community)\n"
  7470. "Do not export to next AS (well-known community)\n"
  7471. "Exact match of the communities")
  7472. ALIAS (show_bgp_community_exact,
  7473. show_bgp_ipv6_community4_exact_cmd,
  7474. "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
  7475. SHOW_STR
  7476. BGP_STR
  7477. "Address family\n"
  7478. "Display routes matching the communities\n"
  7479. "community number\n"
  7480. "Do not send outside local AS (well-known community)\n"
  7481. "Do not advertise to any peer (well-known community)\n"
  7482. "Do not export to next AS (well-known community)\n"
  7483. "community number\n"
  7484. "Do not send outside local AS (well-known community)\n"
  7485. "Do not advertise to any peer (well-known community)\n"
  7486. "Do not export to next AS (well-known community)\n"
  7487. "community number\n"
  7488. "Do not send outside local AS (well-known community)\n"
  7489. "Do not advertise to any peer (well-known community)\n"
  7490. "Do not export to next AS (well-known community)\n"
  7491. "community number\n"
  7492. "Do not send outside local AS (well-known community)\n"
  7493. "Do not advertise to any peer (well-known community)\n"
  7494. "Do not export to next AS (well-known community)\n"
  7495. "Exact match of the communities")
  7496. /* old command */
  7497. DEFUN (show_ipv6_bgp_community_exact,
  7498. show_ipv6_bgp_community_exact_cmd,
  7499. "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
  7500. SHOW_STR
  7501. IPV6_STR
  7502. BGP_STR
  7503. "Display routes matching the communities\n"
  7504. "community number\n"
  7505. "Do not send outside local AS (well-known community)\n"
  7506. "Do not advertise to any peer (well-known community)\n"
  7507. "Do not export to next AS (well-known community)\n"
  7508. "Exact match of the communities")
  7509. {
  7510. return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
  7511. }
  7512. /* old command */
  7513. ALIAS (show_ipv6_bgp_community_exact,
  7514. show_ipv6_bgp_community2_exact_cmd,
  7515. "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
  7516. SHOW_STR
  7517. IPV6_STR
  7518. BGP_STR
  7519. "Display routes matching the communities\n"
  7520. "community number\n"
  7521. "Do not send outside local AS (well-known community)\n"
  7522. "Do not advertise to any peer (well-known community)\n"
  7523. "Do not export to next AS (well-known community)\n"
  7524. "community number\n"
  7525. "Do not send outside local AS (well-known community)\n"
  7526. "Do not advertise to any peer (well-known community)\n"
  7527. "Do not export to next AS (well-known community)\n"
  7528. "Exact match of the communities")
  7529. /* old command */
  7530. ALIAS (show_ipv6_bgp_community_exact,
  7531. show_ipv6_bgp_community3_exact_cmd,
  7532. "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
  7533. SHOW_STR
  7534. IPV6_STR
  7535. BGP_STR
  7536. "Display routes matching the communities\n"
  7537. "community number\n"
  7538. "Do not send outside local AS (well-known community)\n"
  7539. "Do not advertise to any peer (well-known community)\n"
  7540. "Do not export to next AS (well-known community)\n"
  7541. "community number\n"
  7542. "Do not send outside local AS (well-known community)\n"
  7543. "Do not advertise to any peer (well-known community)\n"
  7544. "Do not export to next AS (well-known community)\n"
  7545. "community number\n"
  7546. "Do not send outside local AS (well-known community)\n"
  7547. "Do not advertise to any peer (well-known community)\n"
  7548. "Do not export to next AS (well-known community)\n"
  7549. "Exact match of the communities")
  7550. /* old command */
  7551. ALIAS (show_ipv6_bgp_community_exact,
  7552. show_ipv6_bgp_community4_exact_cmd,
  7553. "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
  7554. SHOW_STR
  7555. IPV6_STR
  7556. BGP_STR
  7557. "Display routes matching the communities\n"
  7558. "community number\n"
  7559. "Do not send outside local AS (well-known community)\n"
  7560. "Do not advertise to any peer (well-known community)\n"
  7561. "Do not export to next AS (well-known community)\n"
  7562. "community number\n"
  7563. "Do not send outside local AS (well-known community)\n"
  7564. "Do not advertise to any peer (well-known community)\n"
  7565. "Do not export to next AS (well-known community)\n"
  7566. "community number\n"
  7567. "Do not send outside local AS (well-known community)\n"
  7568. "Do not advertise to any peer (well-known community)\n"
  7569. "Do not export to next AS (well-known community)\n"
  7570. "community number\n"
  7571. "Do not send outside local AS (well-known community)\n"
  7572. "Do not advertise to any peer (well-known community)\n"
  7573. "Do not export to next AS (well-known community)\n"
  7574. "Exact match of the communities")
  7575. /* old command */
  7576. DEFUN (show_ipv6_mbgp_community,
  7577. show_ipv6_mbgp_community_cmd,
  7578. "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
  7579. SHOW_STR
  7580. IPV6_STR
  7581. MBGP_STR
  7582. "Display routes matching the communities\n"
  7583. "community number\n"
  7584. "Do not send outside local AS (well-known community)\n"
  7585. "Do not advertise to any peer (well-known community)\n"
  7586. "Do not export to next AS (well-known community)\n")
  7587. {
  7588. return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
  7589. }
  7590. /* old command */
  7591. ALIAS (show_ipv6_mbgp_community,
  7592. show_ipv6_mbgp_community2_cmd,
  7593. "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
  7594. SHOW_STR
  7595. IPV6_STR
  7596. MBGP_STR
  7597. "Display routes matching the communities\n"
  7598. "community number\n"
  7599. "Do not send outside local AS (well-known community)\n"
  7600. "Do not advertise to any peer (well-known community)\n"
  7601. "Do not export to next AS (well-known community)\n"
  7602. "community number\n"
  7603. "Do not send outside local AS (well-known community)\n"
  7604. "Do not advertise to any peer (well-known community)\n"
  7605. "Do not export to next AS (well-known community)\n")
  7606. /* old command */
  7607. ALIAS (show_ipv6_mbgp_community,
  7608. show_ipv6_mbgp_community3_cmd,
  7609. "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
  7610. SHOW_STR
  7611. IPV6_STR
  7612. MBGP_STR
  7613. "Display routes matching the communities\n"
  7614. "community number\n"
  7615. "Do not send outside local AS (well-known community)\n"
  7616. "Do not advertise to any peer (well-known community)\n"
  7617. "Do not export to next AS (well-known community)\n"
  7618. "community number\n"
  7619. "Do not send outside local AS (well-known community)\n"
  7620. "Do not advertise to any peer (well-known community)\n"
  7621. "Do not export to next AS (well-known community)\n"
  7622. "community number\n"
  7623. "Do not send outside local AS (well-known community)\n"
  7624. "Do not advertise to any peer (well-known community)\n"
  7625. "Do not export to next AS (well-known community)\n")
  7626. /* old command */
  7627. ALIAS (show_ipv6_mbgp_community,
  7628. show_ipv6_mbgp_community4_cmd,
  7629. "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
  7630. SHOW_STR
  7631. IPV6_STR
  7632. MBGP_STR
  7633. "Display routes matching the communities\n"
  7634. "community number\n"
  7635. "Do not send outside local AS (well-known community)\n"
  7636. "Do not advertise to any peer (well-known community)\n"
  7637. "Do not export to next AS (well-known community)\n"
  7638. "community number\n"
  7639. "Do not send outside local AS (well-known community)\n"
  7640. "Do not advertise to any peer (well-known community)\n"
  7641. "Do not export to next AS (well-known community)\n"
  7642. "community number\n"
  7643. "Do not send outside local AS (well-known community)\n"
  7644. "Do not advertise to any peer (well-known community)\n"
  7645. "Do not export to next AS (well-known community)\n"
  7646. "community number\n"
  7647. "Do not send outside local AS (well-known community)\n"
  7648. "Do not advertise to any peer (well-known community)\n"
  7649. "Do not export to next AS (well-known community)\n")
  7650. /* old command */
  7651. DEFUN (show_ipv6_mbgp_community_exact,
  7652. show_ipv6_mbgp_community_exact_cmd,
  7653. "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
  7654. SHOW_STR
  7655. IPV6_STR
  7656. MBGP_STR
  7657. "Display routes matching the communities\n"
  7658. "community number\n"
  7659. "Do not send outside local AS (well-known community)\n"
  7660. "Do not advertise to any peer (well-known community)\n"
  7661. "Do not export to next AS (well-known community)\n"
  7662. "Exact match of the communities")
  7663. {
  7664. return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
  7665. }
  7666. /* old command */
  7667. ALIAS (show_ipv6_mbgp_community_exact,
  7668. show_ipv6_mbgp_community2_exact_cmd,
  7669. "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
  7670. SHOW_STR
  7671. IPV6_STR
  7672. MBGP_STR
  7673. "Display routes matching the communities\n"
  7674. "community number\n"
  7675. "Do not send outside local AS (well-known community)\n"
  7676. "Do not advertise to any peer (well-known community)\n"
  7677. "Do not export to next AS (well-known community)\n"
  7678. "community number\n"
  7679. "Do not send outside local AS (well-known community)\n"
  7680. "Do not advertise to any peer (well-known community)\n"
  7681. "Do not export to next AS (well-known community)\n"
  7682. "Exact match of the communities")
  7683. /* old command */
  7684. ALIAS (show_ipv6_mbgp_community_exact,
  7685. show_ipv6_mbgp_community3_exact_cmd,
  7686. "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
  7687. SHOW_STR
  7688. IPV6_STR
  7689. MBGP_STR
  7690. "Display routes matching the communities\n"
  7691. "community number\n"
  7692. "Do not send outside local AS (well-known community)\n"
  7693. "Do not advertise to any peer (well-known community)\n"
  7694. "Do not export to next AS (well-known community)\n"
  7695. "community number\n"
  7696. "Do not send outside local AS (well-known community)\n"
  7697. "Do not advertise to any peer (well-known community)\n"
  7698. "Do not export to next AS (well-known community)\n"
  7699. "community number\n"
  7700. "Do not send outside local AS (well-known community)\n"
  7701. "Do not advertise to any peer (well-known community)\n"
  7702. "Do not export to next AS (well-known community)\n"
  7703. "Exact match of the communities")
  7704. /* old command */
  7705. ALIAS (show_ipv6_mbgp_community_exact,
  7706. show_ipv6_mbgp_community4_exact_cmd,
  7707. "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
  7708. SHOW_STR
  7709. IPV6_STR
  7710. MBGP_STR
  7711. "Display routes matching the communities\n"
  7712. "community number\n"
  7713. "Do not send outside local AS (well-known community)\n"
  7714. "Do not advertise to any peer (well-known community)\n"
  7715. "Do not export to next AS (well-known community)\n"
  7716. "community number\n"
  7717. "Do not send outside local AS (well-known community)\n"
  7718. "Do not advertise to any peer (well-known community)\n"
  7719. "Do not export to next AS (well-known community)\n"
  7720. "community number\n"
  7721. "Do not send outside local AS (well-known community)\n"
  7722. "Do not advertise to any peer (well-known community)\n"
  7723. "Do not export to next AS (well-known community)\n"
  7724. "community number\n"
  7725. "Do not send outside local AS (well-known community)\n"
  7726. "Do not advertise to any peer (well-known community)\n"
  7727. "Do not export to next AS (well-known community)\n"
  7728. "Exact match of the communities")
  7729. #endif /* HAVE_IPV6 */
  7730. static int
  7731. bgp_show_community_list (struct vty *vty, const char *com, int exact,
  7732. afi_t afi, safi_t safi)
  7733. {
  7734. struct community_list *list;
  7735. list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
  7736. if (list == NULL)
  7737. {
  7738. vty_out (vty, "%% %s is not a valid community-list name%s", com,
  7739. VTY_NEWLINE);
  7740. return CMD_WARNING;
  7741. }
  7742. return bgp_show (vty, NULL, afi, safi,
  7743. (exact ? bgp_show_type_community_list_exact :
  7744. bgp_show_type_community_list), list);
  7745. }
  7746. DEFUN (show_ip_bgp_community_list,
  7747. show_ip_bgp_community_list_cmd,
  7748. "show ip bgp community-list (<1-500>|WORD)",
  7749. SHOW_STR
  7750. IP_STR
  7751. BGP_STR
  7752. "Display routes matching the community-list\n"
  7753. "community-list number\n"
  7754. "community-list name\n")
  7755. {
  7756. return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
  7757. }
  7758. DEFUN (show_ip_bgp_ipv4_community_list,
  7759. show_ip_bgp_ipv4_community_list_cmd,
  7760. "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
  7761. SHOW_STR
  7762. IP_STR
  7763. BGP_STR
  7764. "Address family\n"
  7765. "Address Family modifier\n"
  7766. "Address Family modifier\n"
  7767. "Display routes matching the community-list\n"
  7768. "community-list number\n"
  7769. "community-list name\n")
  7770. {
  7771. if (strncmp (argv[0], "m", 1) == 0)
  7772. return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
  7773. return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
  7774. }
  7775. DEFUN (show_ip_bgp_community_list_exact,
  7776. show_ip_bgp_community_list_exact_cmd,
  7777. "show ip bgp community-list (<1-500>|WORD) exact-match",
  7778. SHOW_STR
  7779. IP_STR
  7780. BGP_STR
  7781. "Display routes matching the community-list\n"
  7782. "community-list number\n"
  7783. "community-list name\n"
  7784. "Exact match of the communities\n")
  7785. {
  7786. return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
  7787. }
  7788. DEFUN (show_ip_bgp_ipv4_community_list_exact,
  7789. show_ip_bgp_ipv4_community_list_exact_cmd,
  7790. "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
  7791. SHOW_STR
  7792. IP_STR
  7793. BGP_STR
  7794. "Address family\n"
  7795. "Address Family modifier\n"
  7796. "Address Family modifier\n"
  7797. "Display routes matching the community-list\n"
  7798. "community-list number\n"
  7799. "community-list name\n"
  7800. "Exact match of the communities\n")
  7801. {
  7802. if (strncmp (argv[0], "m", 1) == 0)
  7803. return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
  7804. return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
  7805. }
  7806. #ifdef HAVE_IPV6
  7807. DEFUN (show_bgp_community_list,
  7808. show_bgp_community_list_cmd,
  7809. "show bgp community-list (<1-500>|WORD)",
  7810. SHOW_STR
  7811. BGP_STR
  7812. "Display routes matching the community-list\n"
  7813. "community-list number\n"
  7814. "community-list name\n")
  7815. {
  7816. return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
  7817. }
  7818. ALIAS (show_bgp_community_list,
  7819. show_bgp_ipv6_community_list_cmd,
  7820. "show bgp ipv6 community-list (<1-500>|WORD)",
  7821. SHOW_STR
  7822. BGP_STR
  7823. "Address family\n"
  7824. "Display routes matching the community-list\n"
  7825. "community-list number\n"
  7826. "community-list name\n")
  7827. /* old command */
  7828. DEFUN (show_ipv6_bgp_community_list,
  7829. show_ipv6_bgp_community_list_cmd,
  7830. "show ipv6 bgp community-list WORD",
  7831. SHOW_STR
  7832. IPV6_STR
  7833. BGP_STR
  7834. "Display routes matching the community-list\n"
  7835. "community-list name\n")
  7836. {
  7837. return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
  7838. }
  7839. /* old command */
  7840. DEFUN (show_ipv6_mbgp_community_list,
  7841. show_ipv6_mbgp_community_list_cmd,
  7842. "show ipv6 mbgp community-list WORD",
  7843. SHOW_STR
  7844. IPV6_STR
  7845. MBGP_STR
  7846. "Display routes matching the community-list\n"
  7847. "community-list name\n")
  7848. {
  7849. return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
  7850. }
  7851. DEFUN (show_bgp_community_list_exact,
  7852. show_bgp_community_list_exact_cmd,
  7853. "show bgp community-list (<1-500>|WORD) exact-match",
  7854. SHOW_STR
  7855. BGP_STR
  7856. "Display routes matching the community-list\n"
  7857. "community-list number\n"
  7858. "community-list name\n"
  7859. "Exact match of the communities\n")
  7860. {
  7861. return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
  7862. }
  7863. ALIAS (show_bgp_community_list_exact,
  7864. show_bgp_ipv6_community_list_exact_cmd,
  7865. "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
  7866. SHOW_STR
  7867. BGP_STR
  7868. "Address family\n"
  7869. "Display routes matching the community-list\n"
  7870. "community-list number\n"
  7871. "community-list name\n"
  7872. "Exact match of the communities\n")
  7873. /* old command */
  7874. DEFUN (show_ipv6_bgp_community_list_exact,
  7875. show_ipv6_bgp_community_list_exact_cmd,
  7876. "show ipv6 bgp community-list WORD exact-match",
  7877. SHOW_STR
  7878. IPV6_STR
  7879. BGP_STR
  7880. "Display routes matching the community-list\n"
  7881. "community-list name\n"
  7882. "Exact match of the communities\n")
  7883. {
  7884. return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
  7885. }
  7886. /* old command */
  7887. DEFUN (show_ipv6_mbgp_community_list_exact,
  7888. show_ipv6_mbgp_community_list_exact_cmd,
  7889. "show ipv6 mbgp community-list WORD exact-match",
  7890. SHOW_STR
  7891. IPV6_STR
  7892. MBGP_STR
  7893. "Display routes matching the community-list\n"
  7894. "community-list name\n"
  7895. "Exact match of the communities\n")
  7896. {
  7897. return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
  7898. }
  7899. #endif /* HAVE_IPV6 */
  7900. static int
  7901. bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
  7902. safi_t safi, enum bgp_show_type type)
  7903. {
  7904. int ret;
  7905. struct prefix *p;
  7906. p = prefix_new();
  7907. ret = str2prefix (prefix, p);
  7908. if (! ret)
  7909. {
  7910. vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
  7911. return CMD_WARNING;
  7912. }
  7913. ret = bgp_show (vty, NULL, afi, safi, type, p);
  7914. prefix_free(p);
  7915. return ret;
  7916. }
  7917. DEFUN (show_ip_bgp_prefix_longer,
  7918. show_ip_bgp_prefix_longer_cmd,
  7919. "show ip bgp A.B.C.D/M longer-prefixes",
  7920. SHOW_STR
  7921. IP_STR
  7922. BGP_STR
  7923. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  7924. "Display route and more specific routes\n")
  7925. {
  7926. return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
  7927. bgp_show_type_prefix_longer);
  7928. }
  7929. DEFUN (show_ip_bgp_flap_prefix_longer,
  7930. show_ip_bgp_flap_prefix_longer_cmd,
  7931. "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
  7932. SHOW_STR
  7933. IP_STR
  7934. BGP_STR
  7935. "Display flap statistics of routes\n"
  7936. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  7937. "Display route and more specific routes\n")
  7938. {
  7939. return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
  7940. bgp_show_type_flap_prefix_longer);
  7941. }
  7942. DEFUN (show_ip_bgp_ipv4_prefix_longer,
  7943. show_ip_bgp_ipv4_prefix_longer_cmd,
  7944. "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
  7945. SHOW_STR
  7946. IP_STR
  7947. BGP_STR
  7948. "Address family\n"
  7949. "Address Family modifier\n"
  7950. "Address Family modifier\n"
  7951. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  7952. "Display route and more specific routes\n")
  7953. {
  7954. if (strncmp (argv[0], "m", 1) == 0)
  7955. return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
  7956. bgp_show_type_prefix_longer);
  7957. return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
  7958. bgp_show_type_prefix_longer);
  7959. }
  7960. DEFUN (show_ip_bgp_flap_address,
  7961. show_ip_bgp_flap_address_cmd,
  7962. "show ip bgp flap-statistics A.B.C.D",
  7963. SHOW_STR
  7964. IP_STR
  7965. BGP_STR
  7966. "Display flap statistics of routes\n"
  7967. "Network in the BGP routing table to display\n")
  7968. {
  7969. return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
  7970. bgp_show_type_flap_address);
  7971. }
  7972. DEFUN (show_ip_bgp_flap_prefix,
  7973. show_ip_bgp_flap_prefix_cmd,
  7974. "show ip bgp flap-statistics A.B.C.D/M",
  7975. SHOW_STR
  7976. IP_STR
  7977. BGP_STR
  7978. "Display flap statistics of routes\n"
  7979. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
  7980. {
  7981. return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
  7982. bgp_show_type_flap_prefix);
  7983. }
  7984. #ifdef HAVE_IPV6
  7985. DEFUN (show_bgp_prefix_longer,
  7986. show_bgp_prefix_longer_cmd,
  7987. "show bgp X:X::X:X/M longer-prefixes",
  7988. SHOW_STR
  7989. BGP_STR
  7990. "IPv6 prefix <network>/<length>\n"
  7991. "Display route and more specific routes\n")
  7992. {
  7993. return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
  7994. bgp_show_type_prefix_longer);
  7995. }
  7996. ALIAS (show_bgp_prefix_longer,
  7997. show_bgp_ipv6_prefix_longer_cmd,
  7998. "show bgp ipv6 X:X::X:X/M longer-prefixes",
  7999. SHOW_STR
  8000. BGP_STR
  8001. "Address family\n"
  8002. "IPv6 prefix <network>/<length>\n"
  8003. "Display route and more specific routes\n")
  8004. /* old command */
  8005. DEFUN (show_ipv6_bgp_prefix_longer,
  8006. show_ipv6_bgp_prefix_longer_cmd,
  8007. "show ipv6 bgp X:X::X:X/M longer-prefixes",
  8008. SHOW_STR
  8009. IPV6_STR
  8010. BGP_STR
  8011. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  8012. "Display route and more specific routes\n")
  8013. {
  8014. return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
  8015. bgp_show_type_prefix_longer);
  8016. }
  8017. /* old command */
  8018. DEFUN (show_ipv6_mbgp_prefix_longer,
  8019. show_ipv6_mbgp_prefix_longer_cmd,
  8020. "show ipv6 mbgp X:X::X:X/M longer-prefixes",
  8021. SHOW_STR
  8022. IPV6_STR
  8023. MBGP_STR
  8024. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  8025. "Display route and more specific routes\n")
  8026. {
  8027. return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
  8028. bgp_show_type_prefix_longer);
  8029. }
  8030. #endif /* HAVE_IPV6 */
  8031. static struct peer *
  8032. peer_lookup_in_view (struct vty *vty, const char *view_name,
  8033. const char *ip_str)
  8034. {
  8035. int ret;
  8036. struct bgp *bgp;
  8037. struct peer *peer;
  8038. union sockunion su;
  8039. /* BGP structure lookup. */
  8040. if (view_name)
  8041. {
  8042. bgp = bgp_lookup_by_name (view_name);
  8043. if (! bgp)
  8044. {
  8045. vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
  8046. return NULL;
  8047. }
  8048. }
  8049. else
  8050. {
  8051. bgp = bgp_get_default ();
  8052. if (! bgp)
  8053. {
  8054. vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
  8055. return NULL;
  8056. }
  8057. }
  8058. /* Get peer sockunion. */
  8059. ret = str2sockunion (ip_str, &su);
  8060. if (ret < 0)
  8061. {
  8062. vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
  8063. return NULL;
  8064. }
  8065. /* Peer structure lookup. */
  8066. peer = peer_lookup (bgp, &su);
  8067. if (! peer)
  8068. {
  8069. vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
  8070. return NULL;
  8071. }
  8072. return peer;
  8073. }
  8074. enum bgp_stats
  8075. {
  8076. BGP_STATS_MAXBITLEN = 0,
  8077. BGP_STATS_RIB,
  8078. BGP_STATS_PREFIXES,
  8079. BGP_STATS_TOTPLEN,
  8080. BGP_STATS_UNAGGREGATEABLE,
  8081. BGP_STATS_MAX_AGGREGATEABLE,
  8082. BGP_STATS_AGGREGATES,
  8083. BGP_STATS_SPACE,
  8084. BGP_STATS_ASPATH_COUNT,
  8085. BGP_STATS_ASPATH_MAXHOPS,
  8086. BGP_STATS_ASPATH_TOTHOPS,
  8087. BGP_STATS_ASPATH_MAXSIZE,
  8088. BGP_STATS_ASPATH_TOTSIZE,
  8089. BGP_STATS_ASN_HIGHEST,
  8090. BGP_STATS_MAX,
  8091. };
  8092. static const char *table_stats_strs[] =
  8093. {
  8094. [BGP_STATS_PREFIXES] = "Total Prefixes",
  8095. [BGP_STATS_TOTPLEN] = "Average prefix length",
  8096. [BGP_STATS_RIB] = "Total Advertisements",
  8097. [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
  8098. [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
  8099. [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
  8100. [BGP_STATS_SPACE] = "Address space advertised",
  8101. [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
  8102. [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
  8103. [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
  8104. [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
  8105. [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
  8106. [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
  8107. [BGP_STATS_MAX] = NULL,
  8108. };
  8109. struct bgp_table_stats
  8110. {
  8111. struct bgp_table *table;
  8112. unsigned long long counts[BGP_STATS_MAX];
  8113. };
  8114. #if 0
  8115. #define TALLY_SIGFIG 100000
  8116. static unsigned long
  8117. ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
  8118. {
  8119. unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
  8120. unsigned long res = (newtot * TALLY_SIGFIG) / count;
  8121. unsigned long ret = newtot / count;
  8122. if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
  8123. return ret + 1;
  8124. else
  8125. return ret;
  8126. }
  8127. #endif
  8128. static int
  8129. bgp_table_stats_walker (struct thread *t)
  8130. {
  8131. struct bgp_node *rn;
  8132. struct bgp_node *top;
  8133. struct bgp_table_stats *ts = THREAD_ARG (t);
  8134. unsigned int space = 0;
  8135. if (!(top = bgp_table_top (ts->table)))
  8136. return 0;
  8137. switch (top->p.family)
  8138. {
  8139. case AF_INET:
  8140. space = IPV4_MAX_BITLEN;
  8141. break;
  8142. case AF_INET6:
  8143. space = IPV6_MAX_BITLEN;
  8144. break;
  8145. }
  8146. ts->counts[BGP_STATS_MAXBITLEN] = space;
  8147. for (rn = top; rn; rn = bgp_route_next (rn))
  8148. {
  8149. struct bgp_info *ri;
  8150. struct bgp_node *prn = bgp_node_parent_nolock (rn);
  8151. unsigned int rinum = 0;
  8152. if (rn == top)
  8153. continue;
  8154. if (!rn->info)
  8155. continue;
  8156. ts->counts[BGP_STATS_PREFIXES]++;
  8157. ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
  8158. #if 0
  8159. ts->counts[BGP_STATS_AVGPLEN]
  8160. = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
  8161. ts->counts[BGP_STATS_AVGPLEN],
  8162. rn->p.prefixlen);
  8163. #endif
  8164. /* check if the prefix is included by any other announcements */
  8165. while (prn && !prn->info)
  8166. prn = bgp_node_parent_nolock (prn);
  8167. if (prn == NULL || prn == top)
  8168. {
  8169. ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
  8170. /* announced address space */
  8171. if (space)
  8172. ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
  8173. }
  8174. else if (prn->info)
  8175. ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
  8176. for (ri = rn->info; ri; ri = ri->next)
  8177. {
  8178. rinum++;
  8179. ts->counts[BGP_STATS_RIB]++;
  8180. if (ri->attr &&
  8181. (CHECK_FLAG (ri->attr->flag,
  8182. ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
  8183. ts->counts[BGP_STATS_AGGREGATES]++;
  8184. /* as-path stats */
  8185. if (ri->attr && ri->attr->aspath)
  8186. {
  8187. unsigned int hops = aspath_count_hops (ri->attr->aspath);
  8188. unsigned int size = aspath_size (ri->attr->aspath);
  8189. as_t highest = aspath_highest (ri->attr->aspath);
  8190. ts->counts[BGP_STATS_ASPATH_COUNT]++;
  8191. if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
  8192. ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
  8193. if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
  8194. ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
  8195. ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
  8196. ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
  8197. #if 0
  8198. ts->counts[BGP_STATS_ASPATH_AVGHOPS]
  8199. = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
  8200. ts->counts[BGP_STATS_ASPATH_AVGHOPS],
  8201. hops);
  8202. ts->counts[BGP_STATS_ASPATH_AVGSIZE]
  8203. = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
  8204. ts->counts[BGP_STATS_ASPATH_AVGSIZE],
  8205. size);
  8206. #endif
  8207. if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
  8208. ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
  8209. }
  8210. }
  8211. }
  8212. return 0;
  8213. }
  8214. static int
  8215. bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
  8216. {
  8217. struct bgp_table_stats ts;
  8218. unsigned int i;
  8219. if (!bgp->rib[afi][safi])
  8220. {
  8221. vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
  8222. return CMD_WARNING;
  8223. }
  8224. memset (&ts, 0, sizeof (ts));
  8225. ts.table = bgp->rib[afi][safi];
  8226. thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
  8227. vty_out (vty, "BGP %s RIB statistics%s%s",
  8228. afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
  8229. for (i = 0; i < BGP_STATS_MAX; i++)
  8230. {
  8231. if (!table_stats_strs[i])
  8232. continue;
  8233. switch (i)
  8234. {
  8235. #if 0
  8236. case BGP_STATS_ASPATH_AVGHOPS:
  8237. case BGP_STATS_ASPATH_AVGSIZE:
  8238. case BGP_STATS_AVGPLEN:
  8239. vty_out (vty, "%-30s: ", table_stats_strs[i]);
  8240. vty_out (vty, "%12.2f",
  8241. (float)ts.counts[i] / (float)TALLY_SIGFIG);
  8242. break;
  8243. #endif
  8244. case BGP_STATS_ASPATH_TOTHOPS:
  8245. case BGP_STATS_ASPATH_TOTSIZE:
  8246. vty_out (vty, "%-30s: ", table_stats_strs[i]);
  8247. vty_out (vty, "%12.2f",
  8248. ts.counts[i] ?
  8249. (float)ts.counts[i] /
  8250. (float)ts.counts[BGP_STATS_ASPATH_COUNT]
  8251. : 0);
  8252. break;
  8253. case BGP_STATS_TOTPLEN:
  8254. vty_out (vty, "%-30s: ", table_stats_strs[i]);
  8255. vty_out (vty, "%12.2f",
  8256. ts.counts[i] ?
  8257. (float)ts.counts[i] /
  8258. (float)ts.counts[BGP_STATS_PREFIXES]
  8259. : 0);
  8260. break;
  8261. case BGP_STATS_SPACE:
  8262. vty_out (vty, "%-30s: ", table_stats_strs[i]);
  8263. vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
  8264. if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
  8265. break;
  8266. vty_out (vty, "%30s: ", "%% announced ");
  8267. vty_out (vty, "%12.2f%s",
  8268. 100 * (float)ts.counts[BGP_STATS_SPACE] /
  8269. (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
  8270. VTY_NEWLINE);
  8271. vty_out (vty, "%30s: ", "/8 equivalent ");
  8272. vty_out (vty, "%12.2f%s",
  8273. (float)ts.counts[BGP_STATS_SPACE] /
  8274. (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
  8275. VTY_NEWLINE);
  8276. if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
  8277. break;
  8278. vty_out (vty, "%30s: ", "/24 equivalent ");
  8279. vty_out (vty, "%12.2f",
  8280. (float)ts.counts[BGP_STATS_SPACE] /
  8281. (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
  8282. break;
  8283. default:
  8284. vty_out (vty, "%-30s: ", table_stats_strs[i]);
  8285. vty_out (vty, "%12llu", ts.counts[i]);
  8286. }
  8287. vty_out (vty, "%s", VTY_NEWLINE);
  8288. }
  8289. return CMD_SUCCESS;
  8290. }
  8291. static int
  8292. bgp_table_stats_vty (struct vty *vty, const char *name,
  8293. const char *afi_str, const char *safi_str)
  8294. {
  8295. struct bgp *bgp;
  8296. afi_t afi;
  8297. safi_t safi;
  8298. if (name)
  8299. bgp = bgp_lookup_by_name (name);
  8300. else
  8301. bgp = bgp_get_default ();
  8302. if (!bgp)
  8303. {
  8304. vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
  8305. return CMD_WARNING;
  8306. }
  8307. if (strncmp (afi_str, "ipv", 3) == 0)
  8308. {
  8309. if (strncmp (afi_str, "ipv4", 4) == 0)
  8310. afi = AFI_IP;
  8311. else if (strncmp (afi_str, "ipv6", 4) == 0)
  8312. afi = AFI_IP6;
  8313. else
  8314. {
  8315. vty_out (vty, "%% Invalid address family %s%s",
  8316. afi_str, VTY_NEWLINE);
  8317. return CMD_WARNING;
  8318. }
  8319. if (strncmp (safi_str, "m", 1) == 0)
  8320. safi = SAFI_MULTICAST;
  8321. else if (strncmp (safi_str, "u", 1) == 0)
  8322. safi = SAFI_UNICAST;
  8323. else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
  8324. safi = SAFI_MPLS_LABELED_VPN;
  8325. else
  8326. {
  8327. vty_out (vty, "%% Invalid subsequent address family %s%s",
  8328. safi_str, VTY_NEWLINE);
  8329. return CMD_WARNING;
  8330. }
  8331. }
  8332. else
  8333. {
  8334. vty_out (vty, "%% Invalid address family %s%s",
  8335. afi_str, VTY_NEWLINE);
  8336. return CMD_WARNING;
  8337. }
  8338. return bgp_table_stats (vty, bgp, afi, safi);
  8339. }
  8340. DEFUN (show_bgp_statistics,
  8341. show_bgp_statistics_cmd,
  8342. "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
  8343. SHOW_STR
  8344. BGP_STR
  8345. "Address family\n"
  8346. "Address family\n"
  8347. "Address Family modifier\n"
  8348. "Address Family modifier\n"
  8349. "BGP RIB advertisement statistics\n")
  8350. {
  8351. return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
  8352. }
  8353. ALIAS (show_bgp_statistics,
  8354. show_bgp_statistics_vpnv4_cmd,
  8355. "show bgp (ipv4) (vpnv4) statistics",
  8356. SHOW_STR
  8357. BGP_STR
  8358. "Address family\n"
  8359. "Address Family modifier\n"
  8360. "BGP RIB advertisement statistics\n")
  8361. DEFUN (show_bgp_statistics_view,
  8362. show_bgp_statistics_view_cmd,
  8363. "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
  8364. SHOW_STR
  8365. BGP_STR
  8366. "BGP view\n"
  8367. "Address family\n"
  8368. "Address family\n"
  8369. "Address Family modifier\n"
  8370. "Address Family modifier\n"
  8371. "BGP RIB advertisement statistics\n")
  8372. {
  8373. return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
  8374. }
  8375. ALIAS (show_bgp_statistics_view,
  8376. show_bgp_statistics_view_vpnv4_cmd,
  8377. "show bgp view WORD (ipv4) (vpnv4) statistics",
  8378. SHOW_STR
  8379. BGP_STR
  8380. "BGP view\n"
  8381. "Address family\n"
  8382. "Address Family modifier\n"
  8383. "BGP RIB advertisement statistics\n")
  8384. enum bgp_pcounts
  8385. {
  8386. PCOUNT_ADJ_IN = 0,
  8387. PCOUNT_DAMPED,
  8388. PCOUNT_REMOVED,
  8389. PCOUNT_HISTORY,
  8390. PCOUNT_STALE,
  8391. PCOUNT_VALID,
  8392. PCOUNT_ALL,
  8393. PCOUNT_COUNTED,
  8394. PCOUNT_PFCNT, /* the figure we display to users */
  8395. PCOUNT_MAX,
  8396. };
  8397. static const char *pcount_strs[] =
  8398. {
  8399. [PCOUNT_ADJ_IN] = "Adj-in",
  8400. [PCOUNT_DAMPED] = "Damped",
  8401. [PCOUNT_REMOVED] = "Removed",
  8402. [PCOUNT_HISTORY] = "History",
  8403. [PCOUNT_STALE] = "Stale",
  8404. [PCOUNT_VALID] = "Valid",
  8405. [PCOUNT_ALL] = "All RIB",
  8406. [PCOUNT_COUNTED] = "PfxCt counted",
  8407. [PCOUNT_PFCNT] = "Useable",
  8408. [PCOUNT_MAX] = NULL,
  8409. };
  8410. struct peer_pcounts
  8411. {
  8412. unsigned int count[PCOUNT_MAX];
  8413. const struct peer *peer;
  8414. const struct bgp_table *table;
  8415. };
  8416. static int
  8417. bgp_peer_count_walker (struct thread *t)
  8418. {
  8419. struct bgp_node *rn;
  8420. struct peer_pcounts *pc = THREAD_ARG (t);
  8421. const struct peer *peer = pc->peer;
  8422. for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
  8423. {
  8424. struct bgp_adj_in *ain;
  8425. struct bgp_info *ri;
  8426. for (ain = rn->adj_in; ain; ain = ain->next)
  8427. if (ain->peer == peer)
  8428. pc->count[PCOUNT_ADJ_IN]++;
  8429. for (ri = rn->info; ri; ri = ri->next)
  8430. {
  8431. char buf[SU_ADDRSTRLEN];
  8432. if (ri->peer != peer)
  8433. continue;
  8434. pc->count[PCOUNT_ALL]++;
  8435. if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
  8436. pc->count[PCOUNT_DAMPED]++;
  8437. if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
  8438. pc->count[PCOUNT_HISTORY]++;
  8439. if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
  8440. pc->count[PCOUNT_REMOVED]++;
  8441. if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
  8442. pc->count[PCOUNT_STALE]++;
  8443. if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
  8444. pc->count[PCOUNT_VALID]++;
  8445. if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
  8446. pc->count[PCOUNT_PFCNT]++;
  8447. if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
  8448. {
  8449. pc->count[PCOUNT_COUNTED]++;
  8450. if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
  8451. plog_warn (peer->log,
  8452. "%s [pcount] %s/%d is counted but flags 0x%x",
  8453. peer->host,
  8454. inet_ntop(rn->p.family, &rn->p.u.prefix,
  8455. buf, SU_ADDRSTRLEN),
  8456. rn->p.prefixlen,
  8457. ri->flags);
  8458. }
  8459. else
  8460. {
  8461. if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
  8462. plog_warn (peer->log,
  8463. "%s [pcount] %s/%d not counted but flags 0x%x",
  8464. peer->host,
  8465. inet_ntop(rn->p.family, &rn->p.u.prefix,
  8466. buf, SU_ADDRSTRLEN),
  8467. rn->p.prefixlen,
  8468. ri->flags);
  8469. }
  8470. }
  8471. }
  8472. return 0;
  8473. }
  8474. static int
  8475. bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
  8476. {
  8477. struct peer_pcounts pcounts = { .peer = peer };
  8478. unsigned int i;
  8479. if (!peer || !peer->bgp || !peer->afc[afi][safi]
  8480. || !peer->bgp->rib[afi][safi])
  8481. {
  8482. vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
  8483. return CMD_WARNING;
  8484. }
  8485. memset (&pcounts, 0, sizeof(pcounts));
  8486. pcounts.peer = peer;
  8487. pcounts.table = peer->bgp->rib[afi][safi];
  8488. /* in-place call via thread subsystem so as to record execution time
  8489. * stats for the thread-walk (i.e. ensure this can't be blamed on
  8490. * on just vty_read()).
  8491. */
  8492. thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
  8493. vty_out (vty, "Prefix counts for %s, %s%s",
  8494. peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
  8495. vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
  8496. vty_out (vty, "%sCounts from RIB table walk:%s%s",
  8497. VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
  8498. for (i = 0; i < PCOUNT_MAX; i++)
  8499. vty_out (vty, "%20s: %-10d%s",
  8500. pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
  8501. if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
  8502. {
  8503. vty_out (vty, "%s [pcount] PfxCt drift!%s",
  8504. peer->host, VTY_NEWLINE);
  8505. vty_out (vty, "Please report this bug, with the above command output%s",
  8506. VTY_NEWLINE);
  8507. }
  8508. return CMD_SUCCESS;
  8509. }
  8510. DEFUN (show_ip_bgp_neighbor_prefix_counts,
  8511. show_ip_bgp_neighbor_prefix_counts_cmd,
  8512. "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
  8513. SHOW_STR
  8514. IP_STR
  8515. BGP_STR
  8516. "Detailed information on TCP and BGP neighbor connections\n"
  8517. "Neighbor to display information about\n"
  8518. "Neighbor to display information about\n"
  8519. "Display detailed prefix count information\n")
  8520. {
  8521. struct peer *peer;
  8522. peer = peer_lookup_in_view (vty, NULL, argv[0]);
  8523. if (! peer)
  8524. return CMD_WARNING;
  8525. return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
  8526. }
  8527. DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
  8528. show_bgp_ipv6_neighbor_prefix_counts_cmd,
  8529. "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
  8530. SHOW_STR
  8531. BGP_STR
  8532. "Address family\n"
  8533. "Detailed information on TCP and BGP neighbor connections\n"
  8534. "Neighbor to display information about\n"
  8535. "Neighbor to display information about\n"
  8536. "Display detailed prefix count information\n")
  8537. {
  8538. struct peer *peer;
  8539. peer = peer_lookup_in_view (vty, NULL, argv[0]);
  8540. if (! peer)
  8541. return CMD_WARNING;
  8542. return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
  8543. }
  8544. DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
  8545. show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
  8546. "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
  8547. SHOW_STR
  8548. IP_STR
  8549. BGP_STR
  8550. "Address family\n"
  8551. "Address Family modifier\n"
  8552. "Address Family modifier\n"
  8553. "Detailed information on TCP and BGP neighbor connections\n"
  8554. "Neighbor to display information about\n"
  8555. "Neighbor to display information about\n"
  8556. "Display detailed prefix count information\n")
  8557. {
  8558. struct peer *peer;
  8559. peer = peer_lookup_in_view (vty, NULL, argv[1]);
  8560. if (! peer)
  8561. return CMD_WARNING;
  8562. if (strncmp (argv[0], "m", 1) == 0)
  8563. return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
  8564. return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
  8565. }
  8566. DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
  8567. show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
  8568. "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
  8569. SHOW_STR
  8570. IP_STR
  8571. BGP_STR
  8572. "Address family\n"
  8573. "Address Family modifier\n"
  8574. "Address Family modifier\n"
  8575. "Detailed information on TCP and BGP neighbor connections\n"
  8576. "Neighbor to display information about\n"
  8577. "Neighbor to display information about\n"
  8578. "Display detailed prefix count information\n")
  8579. {
  8580. struct peer *peer;
  8581. peer = peer_lookup_in_view (vty, NULL, argv[0]);
  8582. if (! peer)
  8583. return CMD_WARNING;
  8584. return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
  8585. }
  8586. static void
  8587. show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
  8588. int in)
  8589. {
  8590. struct bgp_table *table;
  8591. struct bgp_adj_in *ain;
  8592. struct bgp_adj_out *adj;
  8593. unsigned long output_count;
  8594. struct bgp_node *rn;
  8595. int header1 = 1;
  8596. struct bgp *bgp;
  8597. int header2 = 1;
  8598. bgp = peer->bgp;
  8599. if (! bgp)
  8600. return;
  8601. table = bgp->rib[afi][safi];
  8602. output_count = 0;
  8603. if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
  8604. PEER_STATUS_DEFAULT_ORIGINATE))
  8605. {
  8606. vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
  8607. vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
  8608. vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
  8609. vty_out (vty, "Originating default network 0.0.0.0%s%s",
  8610. VTY_NEWLINE, VTY_NEWLINE);
  8611. header1 = 0;
  8612. }
  8613. for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
  8614. if (in)
  8615. {
  8616. for (ain = rn->adj_in; ain; ain = ain->next)
  8617. if (ain->peer == peer)
  8618. {
  8619. if (header1)
  8620. {
  8621. vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
  8622. vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
  8623. vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
  8624. header1 = 0;
  8625. }
  8626. if (header2)
  8627. {
  8628. vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
  8629. header2 = 0;
  8630. }
  8631. if (ain->attr)
  8632. {
  8633. route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
  8634. output_count++;
  8635. }
  8636. }
  8637. }
  8638. else
  8639. {
  8640. for (adj = rn->adj_out; adj; adj = adj->next)
  8641. if (adj->peer == peer)
  8642. {
  8643. if (header1)
  8644. {
  8645. vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
  8646. vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
  8647. vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
  8648. header1 = 0;
  8649. }
  8650. if (header2)
  8651. {
  8652. vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
  8653. header2 = 0;
  8654. }
  8655. if (adj->attr)
  8656. {
  8657. route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
  8658. output_count++;
  8659. }
  8660. }
  8661. }
  8662. if (output_count != 0)
  8663. vty_out (vty, "%sTotal number of prefixes %ld%s",
  8664. VTY_NEWLINE, output_count, VTY_NEWLINE);
  8665. }
  8666. static int
  8667. peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
  8668. {
  8669. if (! peer || ! peer->afc[afi][safi])
  8670. {
  8671. vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
  8672. return CMD_WARNING;
  8673. }
  8674. if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
  8675. {
  8676. vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
  8677. VTY_NEWLINE);
  8678. return CMD_WARNING;
  8679. }
  8680. show_adj_route (vty, peer, afi, safi, in);
  8681. return CMD_SUCCESS;
  8682. }
  8683. DEFUN (show_ip_bgp_view_neighbor_advertised_route,
  8684. show_ip_bgp_view_neighbor_advertised_route_cmd,
  8685. "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
  8686. SHOW_STR
  8687. IP_STR
  8688. BGP_STR
  8689. "BGP view\n"
  8690. "View name\n"
  8691. "Detailed information on TCP and BGP neighbor connections\n"
  8692. "Neighbor to display information about\n"
  8693. "Neighbor to display information about\n"
  8694. "Display the routes advertised to a BGP neighbor\n")
  8695. {
  8696. struct peer *peer;
  8697. if (argc == 2)
  8698. peer = peer_lookup_in_view (vty, argv[0], argv[1]);
  8699. else
  8700. peer = peer_lookup_in_view (vty, NULL, argv[0]);
  8701. if (! peer)
  8702. return CMD_WARNING;
  8703. return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
  8704. }
  8705. ALIAS (show_ip_bgp_view_neighbor_advertised_route,
  8706. show_ip_bgp_neighbor_advertised_route_cmd,
  8707. "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
  8708. SHOW_STR
  8709. IP_STR