bgp_route.c 368 KB

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