bgp_route.c 562 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992
  1. /* BGP routing information
  2. Copyright (C) 1996, 97, 98, 99 Kunihiro Ishiguro
  3. Copyright (C) 2016 Job Snijders <job@instituut.net>
  4. This file is part of GNU Zebra.
  5. GNU Zebra is free software; you can redistribute it and/or modify it
  6. under the terms of the GNU General Public License as published by the
  7. Free Software Foundation; either version 2, or (at your option) any
  8. later version.
  9. GNU Zebra is distributed in the hope that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GNU Zebra; see the file COPYING. If not, write to the Free
  15. Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  16. 02111-1307, USA. */
  17. #include <zebra.h>
  18. #include "prefix.h"
  19. #include "linklist.h"
  20. #include "memory.h"
  21. #include "command.h"
  22. #include "stream.h"
  23. #include "filter.h"
  24. #include "str.h"
  25. #include "log.h"
  26. #include "routemap.h"
  27. #include "buffer.h"
  28. #include "sockunion.h"
  29. #include "plist.h"
  30. #include "thread.h"
  31. #include "workqueue.h"
  32. #include "bgpd/bgpd.h"
  33. #include "bgpd/bgp_table.h"
  34. #include "bgpd/bgp_route.h"
  35. #include "bgpd/bgp_attr.h"
  36. #include "bgpd/bgp_debug.h"
  37. #include "bgpd/bgp_aspath.h"
  38. #include "bgpd/bgp_regex.h"
  39. #include "bgpd/bgp_community.h"
  40. #include "bgpd/bgp_ecommunity.h"
  41. #include "bgpd/bgp_lcommunity.h"
  42. #include "bgpd/bgp_clist.h"
  43. #include "bgpd/bgp_packet.h"
  44. #include "bgpd/bgp_filter.h"
  45. #include "bgpd/bgp_fsm.h"
  46. #include "bgpd/bgp_mplsvpn.h"
  47. #include "bgpd/bgp_nexthop.h"
  48. #include "bgpd/bgp_damp.h"
  49. #include "bgpd/bgp_advertise.h"
  50. #include "bgpd/bgp_zebra.h"
  51. #include "bgpd/bgp_vty.h"
  52. #include "bgpd/bgp_mpath.h"
  53. #include "bgpd/bgp_nht.h"
  54. /* Extern from bgp_dump.c */
  55. extern const char *bgp_origin_str[];
  56. extern const char *bgp_origin_long_str[];
  57. static struct bgp_node *
  58. bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
  59. struct prefix_rd *prd)
  60. {
  61. struct bgp_node *rn;
  62. struct bgp_node *prn = NULL;
  63. assert (table);
  64. if (!table)
  65. return NULL;
  66. if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
  67. {
  68. prn = bgp_node_get (table, (struct prefix *) prd);
  69. if (prn->info == NULL)
  70. prn->info = bgp_table_init (afi, safi);
  71. else
  72. bgp_unlock_node (prn);
  73. table = prn->info;
  74. }
  75. rn = bgp_node_get (table, p);
  76. if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
  77. rn->prn = prn;
  78. return rn;
  79. }
  80. /* Allocate bgp_info_extra */
  81. static struct bgp_info_extra *
  82. bgp_info_extra_new (void)
  83. {
  84. struct bgp_info_extra *new;
  85. new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
  86. return new;
  87. }
  88. static void
  89. bgp_info_extra_free (struct bgp_info_extra **extra)
  90. {
  91. if (extra && *extra)
  92. {
  93. if ((*extra)->damp_info)
  94. bgp_damp_info_free ((*extra)->damp_info, 0);
  95. (*extra)->damp_info = NULL;
  96. XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
  97. *extra = NULL;
  98. }
  99. }
  100. /* Get bgp_info extra information for the given bgp_info, lazy allocated
  101. * if required.
  102. */
  103. struct bgp_info_extra *
  104. bgp_info_extra_get (struct bgp_info *ri)
  105. {
  106. if (!ri->extra)
  107. ri->extra = bgp_info_extra_new();
  108. return ri->extra;
  109. }
  110. /* Free bgp route information. */
  111. static void
  112. bgp_info_free (struct bgp_info *binfo)
  113. {
  114. if (binfo->attr)
  115. bgp_attr_unintern (&binfo->attr);
  116. bgp_unlink_nexthop (binfo);
  117. bgp_info_extra_free (&binfo->extra);
  118. bgp_info_mpath_free (&binfo->mpath);
  119. peer_unlock (binfo->peer); /* bgp_info peer reference */
  120. XFREE (MTYPE_BGP_ROUTE, binfo);
  121. }
  122. struct bgp_info *
  123. bgp_info_lock (struct bgp_info *binfo)
  124. {
  125. binfo->lock++;
  126. return binfo;
  127. }
  128. struct bgp_info *
  129. bgp_info_unlock (struct bgp_info *binfo)
  130. {
  131. assert (binfo && binfo->lock > 0);
  132. binfo->lock--;
  133. if (binfo->lock == 0)
  134. {
  135. #if 0
  136. zlog_debug ("%s: unlocked and freeing", __func__);
  137. zlog_backtrace (LOG_DEBUG);
  138. #endif
  139. bgp_info_free (binfo);
  140. return NULL;
  141. }
  142. #if 0
  143. if (binfo->lock == 1)
  144. {
  145. zlog_debug ("%s: unlocked to 1", __func__);
  146. zlog_backtrace (LOG_DEBUG);
  147. }
  148. #endif
  149. return binfo;
  150. }
  151. void
  152. bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
  153. {
  154. struct bgp_info *top;
  155. top = rn->info;
  156. ri->next = rn->info;
  157. ri->prev = NULL;
  158. if (top)
  159. top->prev = ri;
  160. rn->info = ri;
  161. bgp_info_lock (ri);
  162. bgp_lock_node (rn);
  163. peer_lock (ri->peer); /* bgp_info peer reference */
  164. }
  165. /* Do the actual removal of info from RIB, for use by bgp_process
  166. completion callback *only* */
  167. static void
  168. bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
  169. {
  170. if (ri->next)
  171. ri->next->prev = ri->prev;
  172. if (ri->prev)
  173. ri->prev->next = ri->next;
  174. else
  175. rn->info = ri->next;
  176. bgp_info_mpath_dequeue (ri);
  177. bgp_info_unlock (ri);
  178. bgp_unlock_node (rn);
  179. }
  180. void
  181. bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
  182. {
  183. bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
  184. /* set of previous already took care of pcount */
  185. UNSET_FLAG (ri->flags, BGP_INFO_VALID);
  186. }
  187. /* undo the effects of a previous call to bgp_info_delete; typically
  188. called when a route is deleted and then quickly re-added before the
  189. deletion has been processed */
  190. static void
  191. bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
  192. {
  193. bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
  194. /* unset of previous already took care of pcount */
  195. SET_FLAG (ri->flags, BGP_INFO_VALID);
  196. }
  197. /* Adjust pcount as required */
  198. static void
  199. bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
  200. {
  201. struct bgp_table *table;
  202. assert (rn && bgp_node_table (rn));
  203. assert (ri && ri->peer && ri->peer->bgp);
  204. table = bgp_node_table (rn);
  205. /* Ignore 'pcount' for RS-client tables */
  206. if (table->type != BGP_TABLE_MAIN
  207. || ri->peer == ri->peer->bgp->peer_self)
  208. return;
  209. if (!BGP_INFO_COUNTABLE (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[table->afi][table->safi])
  215. ri->peer->pcount[table->afi][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_COUNTABLE (ri)
  225. && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
  226. {
  227. SET_FLAG (ri->flags, BGP_INFO_COUNTED);
  228. ri->peer->pcount[table->afi][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 countability state */
  239. if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED))
  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 countability state */
  248. if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED))
  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. Return -1 if new is preferred, 1 if exist
  268. * is preferred, or 0 if they are the same (usually will only occur if
  269. * multipath is enabled */
  270. static int
  271. bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
  272. afi_t afi, safi_t safi)
  273. {
  274. struct attr *newattr, *existattr;
  275. struct attr_extra *newattre, *existattre;
  276. bgp_peer_sort_t new_sort;
  277. bgp_peer_sort_t exist_sort;
  278. u_int32_t new_pref;
  279. u_int32_t exist_pref;
  280. u_int32_t new_med;
  281. u_int32_t exist_med;
  282. u_int32_t new_weight;
  283. u_int32_t exist_weight;
  284. uint32_t newm, existm;
  285. struct in_addr new_id;
  286. struct in_addr exist_id;
  287. int new_cluster;
  288. int exist_cluster;
  289. int internal_as_route;
  290. int confed_as_route;
  291. int ret;
  292. /* 0. Null check. */
  293. if (new == NULL)
  294. return 1;
  295. if (exist == NULL)
  296. return -1;
  297. newattr = new->attr;
  298. existattr = exist->attr;
  299. newattre = newattr->extra;
  300. existattre = existattr->extra;
  301. /* 1. Weight check. */
  302. new_weight = exist_weight = 0;
  303. if (newattre)
  304. new_weight = newattre->weight;
  305. if (existattre)
  306. exist_weight = existattre->weight;
  307. if (new_weight > exist_weight)
  308. return -1;
  309. if (new_weight < exist_weight)
  310. return 1;
  311. /* 2. Local preference check. */
  312. new_pref = exist_pref = bgp->default_local_pref;
  313. if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
  314. new_pref = newattr->local_pref;
  315. if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
  316. exist_pref = existattr->local_pref;
  317. if (new_pref > exist_pref)
  318. return -1;
  319. if (new_pref < exist_pref)
  320. return 1;
  321. /* 3. Local route check. We prefer:
  322. * - BGP_ROUTE_STATIC
  323. * - BGP_ROUTE_AGGREGATE
  324. * - BGP_ROUTE_REDISTRIBUTE
  325. */
  326. if (! (new->sub_type == BGP_ROUTE_NORMAL))
  327. return -1;
  328. if (! (exist->sub_type == BGP_ROUTE_NORMAL))
  329. return 1;
  330. /* 4. AS path length check. */
  331. if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
  332. {
  333. int exist_hops = aspath_count_hops (existattr->aspath);
  334. int exist_confeds = aspath_count_confeds (existattr->aspath);
  335. if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
  336. {
  337. int aspath_hops;
  338. aspath_hops = aspath_count_hops (newattr->aspath);
  339. aspath_hops += aspath_count_confeds (newattr->aspath);
  340. if ( aspath_hops < (exist_hops + exist_confeds))
  341. return -1;
  342. if ( aspath_hops > (exist_hops + exist_confeds))
  343. return 1;
  344. }
  345. else
  346. {
  347. int newhops = aspath_count_hops (newattr->aspath);
  348. if (newhops < exist_hops)
  349. return -1;
  350. if (newhops > exist_hops)
  351. return 1;
  352. }
  353. }
  354. /* 5. Origin check. */
  355. if (newattr->origin < existattr->origin)
  356. return -1;
  357. if (newattr->origin > existattr->origin)
  358. return 1;
  359. /* 6. MED check. */
  360. internal_as_route = (aspath_count_hops (newattr->aspath) == 0
  361. && aspath_count_hops (existattr->aspath) == 0);
  362. confed_as_route = (aspath_count_confeds (newattr->aspath) > 0
  363. && aspath_count_confeds (existattr->aspath) > 0
  364. && aspath_count_hops (newattr->aspath) == 0
  365. && aspath_count_hops (existattr->aspath) == 0);
  366. if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
  367. || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
  368. && confed_as_route)
  369. || aspath_cmp_left (newattr->aspath, existattr->aspath)
  370. || aspath_cmp_left_confed (newattr->aspath, existattr->aspath)
  371. || internal_as_route)
  372. {
  373. new_med = bgp_med_value (new->attr, bgp);
  374. exist_med = bgp_med_value (exist->attr, bgp);
  375. if (new_med < exist_med)
  376. return -1;
  377. if (new_med > exist_med)
  378. return 1;
  379. }
  380. /* 7. Peer type check. */
  381. new_sort = new->peer->sort;
  382. exist_sort = exist->peer->sort;
  383. if (new_sort == BGP_PEER_EBGP
  384. && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED))
  385. return -1;
  386. if (exist_sort == BGP_PEER_EBGP
  387. && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED))
  388. return 1;
  389. /* 8. IGP metric check. */
  390. newm = existm = 0;
  391. if (new->extra)
  392. newm = new->extra->igpmetric;
  393. if (exist->extra)
  394. existm = exist->extra->igpmetric;
  395. if (newm < existm)
  396. return -1;
  397. if (newm > existm)
  398. return 1;
  399. /* 9. Maximum path check. */
  400. if (bgp_mpath_is_configured (bgp, afi, safi))
  401. {
  402. if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX))
  403. {
  404. /*
  405. * For the two paths, all comparison steps till IGP metric
  406. * have succeeded - including AS_PATH hop count. Since 'bgp
  407. * bestpath as-path multipath-relax' knob is on, we don't need
  408. * an exact match of AS_PATH. Thus, mark the paths are equal.
  409. * That will trigger both these paths to get into the multipath
  410. * array.
  411. */
  412. return 0;
  413. }
  414. else if (new->peer->sort == BGP_PEER_IBGP)
  415. {
  416. if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
  417. return 0;
  418. }
  419. else if (new->peer->as == exist->peer->as)
  420. return 0;
  421. }
  422. /* 10. If both paths are external, prefer the path that was received
  423. first (the oldest one). This step minimizes route-flap, since a
  424. newer path won't displace an older one, even if it was the
  425. preferred route based on the additional decision criteria below. */
  426. if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
  427. && new_sort == BGP_PEER_EBGP
  428. && exist_sort == BGP_PEER_EBGP)
  429. {
  430. if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
  431. return -1;
  432. if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
  433. return 1;
  434. }
  435. /* 11. Router-ID comparision. */
  436. /* If one of the paths is "stale", the corresponding peer router-id will
  437. * be 0 and would always win over the other path. If originator id is
  438. * used for the comparision, it will decide which path is better.
  439. */
  440. if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
  441. new_id.s_addr = newattre->originator_id.s_addr;
  442. else
  443. new_id.s_addr = new->peer->remote_id.s_addr;
  444. if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
  445. exist_id.s_addr = existattre->originator_id.s_addr;
  446. else
  447. exist_id.s_addr = exist->peer->remote_id.s_addr;
  448. if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
  449. return -1;
  450. if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
  451. return 1;
  452. /* 12. Cluster length comparision. */
  453. new_cluster = exist_cluster = 0;
  454. if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
  455. new_cluster = newattre->cluster->length;
  456. if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
  457. exist_cluster = existattre->cluster->length;
  458. if (new_cluster < exist_cluster)
  459. return -1;
  460. if (new_cluster > exist_cluster)
  461. return 1;
  462. /* 13. Neighbor address comparision. */
  463. /* Do this only if neither path is "stale" as stale paths do not have
  464. * valid peer information (as the connection may or may not be up).
  465. */
  466. if (CHECK_FLAG (exist->flags, BGP_INFO_STALE))
  467. return -1;
  468. if (CHECK_FLAG (new->flags, BGP_INFO_STALE))
  469. return 1;
  470. /* locally configured routes to advertise do not have su_remote */
  471. if (new->peer->su_remote == NULL)
  472. return 1;
  473. if (exist->peer->su_remote == NULL)
  474. return -1;
  475. ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
  476. if (ret == 1)
  477. return 1;
  478. if (ret == -1)
  479. return -1;
  480. return -1;
  481. }
  482. static enum filter_type
  483. bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
  484. afi_t afi, safi_t safi)
  485. {
  486. struct bgp_filter *filter;
  487. filter = &peer->filter[afi][safi];
  488. #define FILTER_EXIST_WARN(F,f,filter) \
  489. if (BGP_DEBUG (update, UPDATE_IN) \
  490. && !(F ## _IN (filter))) \
  491. plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \
  492. peer->host, #f, F ## _IN_NAME(filter));
  493. if (DISTRIBUTE_IN_NAME (filter)) {
  494. FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
  495. if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
  496. return FILTER_DENY;
  497. }
  498. if (PREFIX_LIST_IN_NAME (filter)) {
  499. FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
  500. if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
  501. return FILTER_DENY;
  502. }
  503. if (FILTER_LIST_IN_NAME (filter)) {
  504. FILTER_EXIST_WARN(FILTER_LIST, as, filter);
  505. if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
  506. return FILTER_DENY;
  507. }
  508. return FILTER_PERMIT;
  509. #undef FILTER_EXIST_WARN
  510. }
  511. static enum filter_type
  512. bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
  513. afi_t afi, safi_t safi)
  514. {
  515. struct bgp_filter *filter;
  516. filter = &peer->filter[afi][safi];
  517. #define FILTER_EXIST_WARN(F,f,filter) \
  518. if (BGP_DEBUG (update, UPDATE_OUT) \
  519. && !(F ## _OUT (filter))) \
  520. plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \
  521. peer->host, #f, F ## _OUT_NAME(filter));
  522. if (DISTRIBUTE_OUT_NAME (filter)) {
  523. FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
  524. if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
  525. return FILTER_DENY;
  526. }
  527. if (PREFIX_LIST_OUT_NAME (filter)) {
  528. FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
  529. if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
  530. return FILTER_DENY;
  531. }
  532. if (FILTER_LIST_OUT_NAME (filter)) {
  533. FILTER_EXIST_WARN(FILTER_LIST, as, filter);
  534. if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
  535. return FILTER_DENY;
  536. }
  537. return FILTER_PERMIT;
  538. #undef FILTER_EXIST_WARN
  539. }
  540. /* If community attribute includes no_export then return 1. */
  541. static int
  542. bgp_community_filter (struct peer *peer, struct attr *attr)
  543. {
  544. if (attr->community)
  545. {
  546. /* NO_ADVERTISE check. */
  547. if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
  548. return 1;
  549. /* NO_EXPORT check. */
  550. if (peer->sort == BGP_PEER_EBGP &&
  551. community_include (attr->community, COMMUNITY_NO_EXPORT))
  552. return 1;
  553. /* NO_EXPORT_SUBCONFED check. */
  554. if (peer->sort == BGP_PEER_EBGP
  555. || peer->sort == BGP_PEER_CONFED)
  556. if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
  557. return 1;
  558. }
  559. return 0;
  560. }
  561. /* Route reflection loop check. */
  562. static int
  563. bgp_cluster_filter (struct peer *peer, struct attr *attr)
  564. {
  565. struct in_addr cluster_id;
  566. if (attr->extra && attr->extra->cluster)
  567. {
  568. if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
  569. cluster_id = peer->bgp->cluster_id;
  570. else
  571. cluster_id = peer->bgp->router_id;
  572. if (cluster_loop_check (attr->extra->cluster, cluster_id))
  573. return 1;
  574. }
  575. return 0;
  576. }
  577. static int
  578. bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
  579. afi_t afi, safi_t safi)
  580. {
  581. struct bgp_filter *filter;
  582. struct bgp_info info;
  583. route_map_result_t ret;
  584. filter = &peer->filter[afi][safi];
  585. /* Apply default weight value. */
  586. if (peer->weight)
  587. (bgp_attr_extra_get (attr))->weight = peer->weight;
  588. /* Route map apply. */
  589. if (ROUTE_MAP_IN_NAME (filter))
  590. {
  591. /* Duplicate current value to new strucutre for modification. */
  592. info.peer = peer;
  593. info.attr = attr;
  594. SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
  595. /* Apply BGP route map to the attribute. */
  596. ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
  597. peer->rmap_type = 0;
  598. if (ret == RMAP_DENYMATCH)
  599. /* caller has multiple error paths with bgp_attr_flush() */
  600. return RMAP_DENY;
  601. }
  602. return RMAP_PERMIT;
  603. }
  604. static int
  605. bgp_export_modifier (struct peer *rsclient, struct peer *peer,
  606. struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
  607. {
  608. struct bgp_filter *filter;
  609. struct bgp_info info;
  610. route_map_result_t ret;
  611. filter = &peer->filter[afi][safi];
  612. /* Route map apply. */
  613. if (ROUTE_MAP_EXPORT_NAME (filter))
  614. {
  615. /* Duplicate current value to new strucutre for modification. */
  616. info.peer = rsclient;
  617. info.attr = attr;
  618. SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
  619. /* Apply BGP route map to the attribute. */
  620. ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
  621. rsclient->rmap_type = 0;
  622. if (ret == RMAP_DENYMATCH)
  623. {
  624. /* Free newly generated AS path and community by route-map. */
  625. bgp_attr_flush (attr);
  626. return RMAP_DENY;
  627. }
  628. }
  629. return RMAP_PERMIT;
  630. }
  631. static int
  632. bgp_import_modifier (struct peer *rsclient, struct peer *peer,
  633. struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
  634. {
  635. struct bgp_filter *filter;
  636. struct bgp_info info;
  637. route_map_result_t ret;
  638. filter = &rsclient->filter[afi][safi];
  639. /* Apply default weight value. */
  640. if (peer->weight)
  641. (bgp_attr_extra_get (attr))->weight = peer->weight;
  642. /* Route map apply. */
  643. if (ROUTE_MAP_IMPORT_NAME (filter))
  644. {
  645. /* Duplicate current value to new strucutre for modification. */
  646. info.peer = peer;
  647. info.attr = attr;
  648. SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
  649. /* Apply BGP route map to the attribute. */
  650. ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
  651. peer->rmap_type = 0;
  652. if (ret == RMAP_DENYMATCH)
  653. {
  654. /* Free newly generated AS path and community by route-map. */
  655. bgp_attr_flush (attr);
  656. return RMAP_DENY;
  657. }
  658. }
  659. return RMAP_PERMIT;
  660. }
  661. static int
  662. bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
  663. struct attr *attr, afi_t afi, safi_t safi)
  664. {
  665. int ret;
  666. char buf[SU_ADDRSTRLEN];
  667. struct bgp_filter *filter;
  668. struct peer *from;
  669. struct bgp *bgp;
  670. int transparent;
  671. int reflect;
  672. struct attr *riattr;
  673. from = ri->peer;
  674. filter = &peer->filter[afi][safi];
  675. bgp = peer->bgp;
  676. riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
  677. if (DISABLE_BGP_ANNOUNCE)
  678. return 0;
  679. /* Do not send announces to RS-clients from the 'normal' bgp_table. */
  680. if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
  681. return 0;
  682. /* Do not send back route to sender. */
  683. if (from == peer)
  684. return 0;
  685. /* Aggregate-address suppress check. */
  686. if (ri->extra && ri->extra->suppress)
  687. if (! UNSUPPRESS_MAP_NAME (filter))
  688. return 0;
  689. /* Default route check. */
  690. if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
  691. {
  692. if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
  693. return 0;
  694. else if (p->family == AF_INET6 && p->prefixlen == 0)
  695. return 0;
  696. }
  697. /* Transparency check. */
  698. if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
  699. && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
  700. transparent = 1;
  701. else
  702. transparent = 0;
  703. /* If community is not disabled check the no-export and local. */
  704. if (! transparent && bgp_community_filter (peer, riattr))
  705. return 0;
  706. /* If the attribute has originator-id and it is same as remote
  707. peer's id. */
  708. if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
  709. {
  710. if (IPV4_ADDR_SAME (&peer->remote_id, &riattr->extra->originator_id))
  711. {
  712. if (BGP_DEBUG (filter, FILTER))
  713. zlog (peer->log, LOG_DEBUG,
  714. "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
  715. peer->host,
  716. inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  717. p->prefixlen);
  718. return 0;
  719. }
  720. }
  721. /* ORF prefix-list filter check */
  722. if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
  723. && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
  724. || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
  725. if (peer->orf_plist[afi][safi])
  726. {
  727. if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
  728. return 0;
  729. }
  730. /* Output filter check. */
  731. if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
  732. {
  733. if (BGP_DEBUG (filter, FILTER))
  734. zlog (peer->log, LOG_DEBUG,
  735. "%s [Update:SEND] %s/%d is filtered",
  736. peer->host,
  737. inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  738. p->prefixlen);
  739. return 0;
  740. }
  741. #ifdef BGP_SEND_ASPATH_CHECK
  742. /* AS path loop check. */
  743. if (aspath_loop_check (riattr->aspath, peer->as))
  744. {
  745. if (BGP_DEBUG (filter, FILTER))
  746. zlog (peer->log, LOG_DEBUG,
  747. "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
  748. peer->host, peer->as);
  749. return 0;
  750. }
  751. /* If we're a CONFED we need to loop check the CONFED ID too */
  752. if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
  753. {
  754. if (aspath_loop_check(riattr->aspath, bgp->confed_id))
  755. {
  756. if (BGP_DEBUG (filter, FILTER))
  757. zlog (peer->log, LOG_DEBUG,
  758. "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
  759. peer->host,
  760. bgp->confed_id);
  761. return 0;
  762. }
  763. }
  764. #endif /* BGP_SEND_ASPATH_CHECK */
  765. /* Route-Reflect check. */
  766. if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
  767. reflect = 1;
  768. else
  769. reflect = 0;
  770. /* IBGP reflection check. */
  771. if (reflect)
  772. {
  773. /* A route from a Client peer. */
  774. if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
  775. {
  776. /* Reflect to all the Non-Client peers and also to the
  777. Client peers other than the originator. Originator check
  778. is already done. So there is noting to do. */
  779. /* no bgp client-to-client reflection check. */
  780. if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
  781. if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
  782. return 0;
  783. }
  784. else
  785. {
  786. /* A route from a Non-client peer. Reflect to all other
  787. clients. */
  788. if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
  789. return 0;
  790. }
  791. }
  792. /* For modify attribute, copy it to temporary structure. */
  793. bgp_attr_dup (attr, riattr);
  794. /* If local-preference is not set. */
  795. if ((peer->sort == BGP_PEER_IBGP
  796. || peer->sort == BGP_PEER_CONFED)
  797. && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
  798. {
  799. attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
  800. attr->local_pref = bgp->default_local_pref;
  801. }
  802. /* If originator-id is not set and the route is to be reflected,
  803. set the originator id */
  804. if (peer && from && peer->sort == BGP_PEER_IBGP &&
  805. from->sort == BGP_PEER_IBGP &&
  806. (! (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
  807. {
  808. attr->extra = bgp_attr_extra_get(attr);
  809. IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
  810. SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
  811. }
  812. /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
  813. if (peer->sort == BGP_PEER_EBGP
  814. && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
  815. {
  816. if (ri->peer != bgp->peer_self && ! transparent
  817. && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
  818. attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
  819. }
  820. #define NEXTHOP_IS_V4 (\
  821. (safi != SAFI_ENCAP && p->family == AF_INET) || \
  822. (safi == SAFI_ENCAP && attr->extra->mp_nexthop_len == 4))
  823. #define NEXTHOP_IS_V6 (\
  824. (safi != SAFI_ENCAP && p->family == AF_INET6) || \
  825. (safi == SAFI_ENCAP && attr->extra->mp_nexthop_len == 16))
  826. /* next-hop-set */
  827. if (transparent
  828. || (reflect && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF_ALL))
  829. || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
  830. && ((NEXTHOP_IS_V4 && attr->nexthop.s_addr)
  831. || (NEXTHOP_IS_V6 &&
  832. ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
  833. )))
  834. {
  835. /* NEXT-HOP Unchanged. */
  836. }
  837. else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
  838. || (NEXTHOP_IS_V4 && attr->nexthop.s_addr == 0)
  839. || (NEXTHOP_IS_V6 &&
  840. IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
  841. || (peer->sort == BGP_PEER_EBGP
  842. && (bgp_multiaccess_check_v4 (attr->nexthop, peer) == 0)))
  843. {
  844. /* Set IPv4 nexthop. */
  845. if (NEXTHOP_IS_V4)
  846. {
  847. if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
  848. memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
  849. IPV4_MAX_BYTELEN);
  850. else
  851. memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
  852. }
  853. /* Set IPv6 nexthop. */
  854. if (NEXTHOP_IS_V6)
  855. {
  856. /* IPv6 global nexthop must be included. */
  857. memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
  858. IPV6_MAX_BYTELEN);
  859. attr->extra->mp_nexthop_len = 16;
  860. }
  861. }
  862. if (p->family == AF_INET6 && safi != SAFI_ENCAP)
  863. {
  864. /* Left nexthop_local unchanged if so configured. */
  865. if ( CHECK_FLAG (peer->af_flags[afi][safi],
  866. PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
  867. {
  868. if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
  869. attr->extra->mp_nexthop_len=32;
  870. else
  871. attr->extra->mp_nexthop_len=16;
  872. }
  873. /* Default nexthop_local treatment for non-RS-Clients */
  874. else
  875. {
  876. /* Link-local address should not be transit to different peer. */
  877. attr->extra->mp_nexthop_len = 16;
  878. /* Set link-local address for shared network peer. */
  879. if (peer->shared_network
  880. && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
  881. {
  882. memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
  883. IPV6_MAX_BYTELEN);
  884. attr->extra->mp_nexthop_len = 32;
  885. }
  886. /* If bgpd act as BGP-4+ route-reflector, do not send link-local
  887. address.*/
  888. if (reflect)
  889. attr->extra->mp_nexthop_len = 16;
  890. /* If BGP-4+ link-local nexthop is not link-local nexthop. */
  891. if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
  892. attr->extra->mp_nexthop_len = 16;
  893. }
  894. }
  895. /* If this is EBGP peer and remove-private-AS is set. */
  896. if (peer->sort == BGP_PEER_EBGP
  897. && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
  898. && aspath_private_as_check (attr->aspath))
  899. attr->aspath = aspath_empty_get ();
  900. /* Route map & unsuppress-map apply. */
  901. if (ROUTE_MAP_OUT_NAME (filter)
  902. || (ri->extra && ri->extra->suppress) )
  903. {
  904. struct bgp_info info;
  905. struct attr dummy_attr;
  906. struct attr_extra dummy_extra;
  907. dummy_attr.extra = &dummy_extra;
  908. info.peer = peer;
  909. info.attr = attr;
  910. /* The route reflector is not allowed to modify the attributes
  911. of the reflected IBGP routes, unless configured to allow it */
  912. if ((from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP) &&
  913. !bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
  914. {
  915. bgp_attr_dup (&dummy_attr, attr);
  916. info.attr = &dummy_attr;
  917. }
  918. SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
  919. if (ri->extra && ri->extra->suppress)
  920. ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
  921. else
  922. ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
  923. peer->rmap_type = 0;
  924. if (ret == RMAP_DENYMATCH)
  925. {
  926. bgp_attr_flush (attr);
  927. return 0;
  928. }
  929. }
  930. return 1;
  931. }
  932. static int
  933. bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
  934. struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
  935. {
  936. int ret;
  937. char buf[SU_ADDRSTRLEN];
  938. struct bgp_filter *filter;
  939. struct bgp_info info;
  940. struct peer *from;
  941. struct attr *riattr;
  942. from = ri->peer;
  943. filter = &rsclient->filter[afi][safi];
  944. riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
  945. if (DISABLE_BGP_ANNOUNCE)
  946. return 0;
  947. /* Do not send back route to sender. */
  948. if (from == rsclient)
  949. return 0;
  950. /* Aggregate-address suppress check. */
  951. if (ri->extra && ri->extra->suppress)
  952. if (! UNSUPPRESS_MAP_NAME (filter))
  953. return 0;
  954. /* Default route check. */
  955. if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
  956. PEER_STATUS_DEFAULT_ORIGINATE))
  957. {
  958. if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
  959. return 0;
  960. else if (p->family == AF_INET6 && p->prefixlen == 0)
  961. return 0;
  962. }
  963. /* If the attribute has originator-id and it is same as remote
  964. peer's id. */
  965. if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
  966. {
  967. if (IPV4_ADDR_SAME (&rsclient->remote_id,
  968. &riattr->extra->originator_id))
  969. {
  970. if (BGP_DEBUG (filter, FILTER))
  971. zlog (rsclient->log, LOG_DEBUG,
  972. "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
  973. rsclient->host,
  974. inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  975. p->prefixlen);
  976. return 0;
  977. }
  978. }
  979. /* ORF prefix-list filter check */
  980. if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
  981. && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
  982. || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
  983. if (rsclient->orf_plist[afi][safi])
  984. {
  985. if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
  986. return 0;
  987. }
  988. /* Output filter check. */
  989. if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
  990. {
  991. if (BGP_DEBUG (filter, FILTER))
  992. zlog (rsclient->log, LOG_DEBUG,
  993. "%s [Update:SEND] %s/%d is filtered",
  994. rsclient->host,
  995. inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  996. p->prefixlen);
  997. return 0;
  998. }
  999. #ifdef BGP_SEND_ASPATH_CHECK
  1000. /* AS path loop check. */
  1001. if (aspath_loop_check (riattr->aspath, rsclient->as))
  1002. {
  1003. if (BGP_DEBUG (filter, FILTER))
  1004. zlog (rsclient->log, LOG_DEBUG,
  1005. "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
  1006. rsclient->host, rsclient->as);
  1007. return 0;
  1008. }
  1009. #endif /* BGP_SEND_ASPATH_CHECK */
  1010. /* For modify attribute, copy it to temporary structure. */
  1011. bgp_attr_dup (attr, riattr);
  1012. /* next-hop-set */
  1013. if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
  1014. || (p->family == AF_INET6 &&
  1015. IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
  1016. )
  1017. {
  1018. /* Set IPv4 nexthop. */
  1019. if (p->family == AF_INET)
  1020. {
  1021. if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
  1022. memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
  1023. IPV4_MAX_BYTELEN);
  1024. else
  1025. memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
  1026. }
  1027. /* Set IPv6 nexthop. */
  1028. if (p->family == AF_INET6)
  1029. {
  1030. /* IPv6 global nexthop must be included. */
  1031. memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
  1032. IPV6_MAX_BYTELEN);
  1033. attr->extra->mp_nexthop_len = 16;
  1034. }
  1035. }
  1036. if (p->family == AF_INET6)
  1037. {
  1038. struct attr_extra *attre = attr->extra;
  1039. /* Left nexthop_local unchanged if so configured. */
  1040. if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
  1041. PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
  1042. {
  1043. if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
  1044. attre->mp_nexthop_len=32;
  1045. else
  1046. attre->mp_nexthop_len=16;
  1047. }
  1048. /* Default nexthop_local treatment for RS-Clients */
  1049. else
  1050. {
  1051. /* Announcer and RS-Client are both in the same network */
  1052. if (rsclient->shared_network && from->shared_network &&
  1053. (rsclient->ifindex == from->ifindex))
  1054. {
  1055. if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
  1056. attre->mp_nexthop_len=32;
  1057. else
  1058. attre->mp_nexthop_len=16;
  1059. }
  1060. /* Set link-local address for shared network peer. */
  1061. else if (rsclient->shared_network
  1062. && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
  1063. {
  1064. memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
  1065. IPV6_MAX_BYTELEN);
  1066. attre->mp_nexthop_len = 32;
  1067. }
  1068. else
  1069. attre->mp_nexthop_len = 16;
  1070. }
  1071. }
  1072. /* If this is EBGP peer and remove-private-AS is set. */
  1073. if (rsclient->sort == BGP_PEER_EBGP
  1074. && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
  1075. && aspath_private_as_check (attr->aspath))
  1076. attr->aspath = aspath_empty_get ();
  1077. /* Route map & unsuppress-map apply. */
  1078. if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
  1079. {
  1080. info.peer = rsclient;
  1081. info.attr = attr;
  1082. SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
  1083. if (ri->extra && ri->extra->suppress)
  1084. ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
  1085. else
  1086. ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
  1087. rsclient->rmap_type = 0;
  1088. if (ret == RMAP_DENYMATCH)
  1089. {
  1090. bgp_attr_flush (attr);
  1091. return 0;
  1092. }
  1093. }
  1094. return 1;
  1095. }
  1096. struct bgp_info_pair
  1097. {
  1098. struct bgp_info *old;
  1099. struct bgp_info *new;
  1100. };
  1101. static void
  1102. bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
  1103. struct bgp_info_pair *result,
  1104. afi_t afi, safi_t safi)
  1105. {
  1106. struct bgp_info *new_select;
  1107. struct bgp_info *old_select;
  1108. struct bgp_info *ri;
  1109. struct bgp_info *ri1;
  1110. struct bgp_info *ri2;
  1111. struct bgp_info *nextri = NULL;
  1112. int cmpret, do_mpath;
  1113. struct list mp_list;
  1114. result->old = result->new = NULL;
  1115. if (rn->info == NULL)
  1116. {
  1117. char buf[PREFIX_STRLEN];
  1118. zlog_warn ("%s: Called for route_node %s with no routing entries!",
  1119. __func__,
  1120. prefix2str (&(bgp_node_to_rnode (rn)->p), buf, sizeof(buf)));
  1121. return;
  1122. }
  1123. bgp_mp_list_init (&mp_list);
  1124. do_mpath = bgp_mpath_is_configured (bgp, afi, safi);
  1125. /* bgp deterministic-med */
  1126. new_select = NULL;
  1127. if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
  1128. for (ri1 = rn->info; ri1; ri1 = ri1->next)
  1129. {
  1130. if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
  1131. continue;
  1132. if (BGP_INFO_HOLDDOWN (ri1))
  1133. continue;
  1134. if (ri1->peer && ri1->peer != bgp->peer_self)
  1135. if (ri1->peer->status != Established)
  1136. continue;
  1137. new_select = ri1;
  1138. if (do_mpath)
  1139. bgp_mp_list_add (&mp_list, ri1);
  1140. old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
  1141. if (ri1->next)
  1142. for (ri2 = ri1->next; ri2; ri2 = ri2->next)
  1143. {
  1144. if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
  1145. continue;
  1146. if (BGP_INFO_HOLDDOWN (ri2))
  1147. continue;
  1148. if (ri2->peer &&
  1149. ri2->peer != bgp->peer_self &&
  1150. !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT))
  1151. if (ri2->peer->status != Established)
  1152. continue;
  1153. if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
  1154. || aspath_cmp_left_confed (ri1->attr->aspath,
  1155. ri2->attr->aspath))
  1156. {
  1157. if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
  1158. old_select = ri2;
  1159. if ((cmpret = bgp_info_cmp (bgp, ri2, new_select, afi, safi))
  1160. == -1)
  1161. {
  1162. bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
  1163. new_select = ri2;
  1164. }
  1165. if (do_mpath)
  1166. {
  1167. if (cmpret != 0)
  1168. bgp_mp_list_clear (&mp_list);
  1169. if (cmpret == 0 || cmpret == -1)
  1170. bgp_mp_list_add (&mp_list, ri2);
  1171. }
  1172. bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
  1173. }
  1174. }
  1175. bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
  1176. bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
  1177. bgp_info_mpath_update (rn, new_select, old_select, &mp_list, afi, safi);
  1178. bgp_mp_list_clear (&mp_list);
  1179. }
  1180. /* Check old selected route and new selected route. */
  1181. old_select = NULL;
  1182. new_select = NULL;
  1183. for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
  1184. {
  1185. if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
  1186. old_select = ri;
  1187. if (BGP_INFO_HOLDDOWN (ri))
  1188. {
  1189. /* reap REMOVED routes, if needs be
  1190. * selected route must stay for a while longer though
  1191. */
  1192. if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
  1193. && (ri != old_select))
  1194. bgp_info_reap (rn, ri);
  1195. continue;
  1196. }
  1197. if (ri->peer &&
  1198. ri->peer != bgp->peer_self &&
  1199. !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
  1200. if (ri->peer->status != Established)
  1201. continue;
  1202. if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
  1203. && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
  1204. {
  1205. bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
  1206. continue;
  1207. }
  1208. bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
  1209. bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
  1210. if ((cmpret = bgp_info_cmp (bgp, ri, new_select, afi, safi)) == -1)
  1211. {
  1212. if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
  1213. bgp_mp_dmed_deselect (new_select);
  1214. new_select = ri;
  1215. }
  1216. else if (cmpret == 1 && do_mpath
  1217. && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
  1218. bgp_mp_dmed_deselect (ri);
  1219. if (do_mpath)
  1220. {
  1221. if (cmpret != 0)
  1222. bgp_mp_list_clear (&mp_list);
  1223. if (cmpret == 0 || cmpret == -1)
  1224. bgp_mp_list_add (&mp_list, ri);
  1225. }
  1226. }
  1227. if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
  1228. bgp_info_mpath_update (rn, new_select, old_select, &mp_list, afi, safi);
  1229. bgp_info_mpath_aggregate_update (new_select, old_select);
  1230. bgp_mp_list_clear (&mp_list);
  1231. result->old = old_select;
  1232. result->new = new_select;
  1233. return;
  1234. }
  1235. static int
  1236. bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
  1237. struct bgp_node *rn, afi_t afi, safi_t safi)
  1238. {
  1239. struct prefix *p;
  1240. struct attr attr;
  1241. struct attr_extra extra;
  1242. memset (&attr, 0, sizeof(struct attr));
  1243. memset (&extra, 0, sizeof(struct attr_extra));
  1244. p = &rn->p;
  1245. /* Announce route to Established peer. */
  1246. if (peer->status != Established)
  1247. return 0;
  1248. /* Address family configuration check. */
  1249. if (! peer->afc_nego[afi][safi])
  1250. return 0;
  1251. /* First update is deferred until ORF or ROUTE-REFRESH is received */
  1252. if (CHECK_FLAG (peer->af_sflags[afi][safi],
  1253. PEER_STATUS_ORF_WAIT_REFRESH))
  1254. return 0;
  1255. /* It's initialized in bgp_announce_[check|check_rsclient]() */
  1256. attr.extra = &extra;
  1257. switch (bgp_node_table (rn)->type)
  1258. {
  1259. case BGP_TABLE_MAIN:
  1260. /* Announcement to peer->conf. If the route is filtered,
  1261. withdraw it. */
  1262. if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
  1263. bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
  1264. else
  1265. bgp_adj_out_unset (rn, peer, p, afi, safi);
  1266. break;
  1267. case BGP_TABLE_RSCLIENT:
  1268. /* Announcement to peer->conf. If the route is filtered,
  1269. withdraw it. */
  1270. if (selected &&
  1271. bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
  1272. bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
  1273. else
  1274. bgp_adj_out_unset (rn, peer, p, afi, safi);
  1275. break;
  1276. }
  1277. bgp_attr_flush (&attr);
  1278. return 0;
  1279. }
  1280. struct bgp_process_queue
  1281. {
  1282. struct bgp *bgp;
  1283. struct bgp_node *rn;
  1284. afi_t afi;
  1285. safi_t safi;
  1286. };
  1287. static wq_item_status
  1288. bgp_process_rsclient (struct work_queue *wq, void *data)
  1289. {
  1290. struct bgp_process_queue *pq = data;
  1291. struct bgp *bgp = pq->bgp;
  1292. struct bgp_node *rn = pq->rn;
  1293. afi_t afi = pq->afi;
  1294. safi_t safi = pq->safi;
  1295. struct bgp_info *new_select;
  1296. struct bgp_info *old_select;
  1297. struct bgp_info_pair old_and_new;
  1298. struct listnode *node, *nnode;
  1299. struct peer *rsclient = bgp_node_table (rn)->owner;
  1300. /* Best path selection. */
  1301. bgp_best_selection (bgp, rn, &old_and_new, afi, safi);
  1302. new_select = old_and_new.new;
  1303. old_select = old_and_new.old;
  1304. if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
  1305. {
  1306. if (rsclient->group)
  1307. for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
  1308. {
  1309. /* Nothing to do. */
  1310. if (old_select && old_select == new_select)
  1311. if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
  1312. continue;
  1313. if (old_select)
  1314. bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
  1315. if (new_select)
  1316. {
  1317. bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
  1318. bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
  1319. UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
  1320. }
  1321. bgp_process_announce_selected (rsclient, new_select, rn,
  1322. afi, safi);
  1323. }
  1324. }
  1325. else
  1326. {
  1327. if (old_select)
  1328. bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
  1329. if (new_select)
  1330. {
  1331. bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
  1332. bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
  1333. UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
  1334. }
  1335. bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
  1336. }
  1337. if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
  1338. bgp_info_reap (rn, old_select);
  1339. UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
  1340. return WQ_SUCCESS;
  1341. }
  1342. static wq_item_status
  1343. bgp_process_main (struct work_queue *wq, void *data)
  1344. {
  1345. struct bgp_process_queue *pq = data;
  1346. struct bgp *bgp = pq->bgp;
  1347. struct bgp_node *rn = pq->rn;
  1348. afi_t afi = pq->afi;
  1349. safi_t safi = pq->safi;
  1350. struct prefix *p = &rn->p;
  1351. struct bgp_info *new_select;
  1352. struct bgp_info *old_select;
  1353. struct bgp_info_pair old_and_new;
  1354. struct listnode *node, *nnode;
  1355. struct peer *peer;
  1356. /* Best path selection. */
  1357. bgp_best_selection (bgp, rn, &old_and_new, afi, safi);
  1358. old_select = old_and_new.old;
  1359. new_select = old_and_new.new;
  1360. /* Nothing to do. */
  1361. if (old_select && old_select == new_select
  1362. && !CHECK_FLAG(rn->flags, BGP_NODE_USER_CLEAR))
  1363. {
  1364. if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
  1365. {
  1366. if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
  1367. CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
  1368. bgp_zebra_announce (p, old_select, bgp, safi);
  1369. UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
  1370. UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
  1371. return WQ_SUCCESS;
  1372. }
  1373. }
  1374. /* If the user did "clear ip bgp prefix x.x.x.x" this flag will be set */
  1375. UNSET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
  1376. if (old_select)
  1377. bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
  1378. if (new_select)
  1379. {
  1380. bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
  1381. bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
  1382. UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
  1383. }
  1384. /* Check each BGP peer. */
  1385. for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
  1386. {
  1387. bgp_process_announce_selected (peer, new_select, rn, afi, safi);
  1388. }
  1389. /* FIB update. */
  1390. if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
  1391. ! bgp_option_check (BGP_OPT_NO_FIB)))
  1392. {
  1393. if (new_select
  1394. && new_select->type == ZEBRA_ROUTE_BGP
  1395. && new_select->sub_type == BGP_ROUTE_NORMAL)
  1396. bgp_zebra_announce (p, new_select, bgp, safi);
  1397. else
  1398. {
  1399. /* Withdraw the route from the kernel. */
  1400. if (old_select
  1401. && old_select->type == ZEBRA_ROUTE_BGP
  1402. && old_select->sub_type == BGP_ROUTE_NORMAL)
  1403. bgp_zebra_withdraw (p, old_select, safi);
  1404. }
  1405. }
  1406. /* Reap old select bgp_info, if it has been removed */
  1407. if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
  1408. bgp_info_reap (rn, old_select);
  1409. UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
  1410. return WQ_SUCCESS;
  1411. }
  1412. static void
  1413. bgp_processq_del (struct work_queue *wq, void *data)
  1414. {
  1415. struct bgp_process_queue *pq = data;
  1416. struct bgp_table *table = bgp_node_table (pq->rn);
  1417. bgp_unlock (pq->bgp);
  1418. bgp_unlock_node (pq->rn);
  1419. bgp_table_unlock (table);
  1420. XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
  1421. }
  1422. static void
  1423. bgp_process_queue_init (void)
  1424. {
  1425. bm->process_main_queue
  1426. = work_queue_new (bm->master, "process_main_queue");
  1427. bm->process_rsclient_queue
  1428. = work_queue_new (bm->master, "process_rsclient_queue");
  1429. if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
  1430. {
  1431. zlog_err ("%s: Failed to allocate work queue", __func__);
  1432. exit (1);
  1433. }
  1434. bm->process_main_queue->spec.workfunc = &bgp_process_main;
  1435. bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
  1436. bm->process_main_queue->spec.max_retries = 0;
  1437. bm->process_main_queue->spec.hold = 50;
  1438. bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
  1439. bm->process_rsclient_queue->spec.del_item_data = &bgp_processq_del;
  1440. bm->process_rsclient_queue->spec.max_retries = 0;
  1441. bm->process_rsclient_queue->spec.hold = 50;
  1442. }
  1443. void
  1444. bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
  1445. {
  1446. struct bgp_process_queue *pqnode;
  1447. /* already scheduled for processing? */
  1448. if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
  1449. return;
  1450. if (rn->info == NULL)
  1451. {
  1452. /* XXX: Perhaps remove before next release, after we've flushed out
  1453. * any obvious cases
  1454. */
  1455. assert (rn->info != NULL);
  1456. char buf[PREFIX_STRLEN];
  1457. zlog_warn ("%s: Called for route_node %s with no routing entries!",
  1458. __func__,
  1459. prefix2str (&(bgp_node_to_rnode (rn)->p), buf, sizeof(buf)));
  1460. return;
  1461. }
  1462. if ( (bm->process_main_queue == NULL) ||
  1463. (bm->process_rsclient_queue == NULL) )
  1464. bgp_process_queue_init ();
  1465. pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
  1466. sizeof (struct bgp_process_queue));
  1467. if (!pqnode)
  1468. return;
  1469. /* all unlocked in bgp_processq_del */
  1470. bgp_table_lock (bgp_node_table (rn));
  1471. pqnode->rn = bgp_lock_node (rn);
  1472. pqnode->bgp = bgp;
  1473. bgp_lock (bgp);
  1474. pqnode->afi = afi;
  1475. pqnode->safi = safi;
  1476. switch (bgp_node_table (rn)->type)
  1477. {
  1478. case BGP_TABLE_MAIN:
  1479. work_queue_add (bm->process_main_queue, pqnode);
  1480. break;
  1481. case BGP_TABLE_RSCLIENT:
  1482. work_queue_add (bm->process_rsclient_queue, pqnode);
  1483. break;
  1484. }
  1485. SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
  1486. return;
  1487. }
  1488. static int
  1489. bgp_maximum_prefix_restart_timer (struct thread *thread)
  1490. {
  1491. struct peer *peer;
  1492. peer = THREAD_ARG (thread);
  1493. peer->t_pmax_restart = NULL;
  1494. if (BGP_DEBUG (events, EVENTS))
  1495. zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
  1496. peer->host);
  1497. peer_clear (peer);
  1498. return 0;
  1499. }
  1500. int
  1501. bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
  1502. safi_t safi, int always)
  1503. {
  1504. if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
  1505. return 0;
  1506. if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
  1507. {
  1508. if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
  1509. && ! always)
  1510. return 0;
  1511. zlog (peer->log, LOG_INFO,
  1512. "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
  1513. "limit %ld", afi_safi_print (afi, safi), peer->host,
  1514. peer->pcount[afi][safi], peer->pmax[afi][safi]);
  1515. SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
  1516. if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
  1517. return 0;
  1518. {
  1519. u_int8_t ndata[7];
  1520. if (safi == SAFI_MPLS_VPN)
  1521. safi = SAFI_MPLS_LABELED_VPN;
  1522. ndata[0] = (afi >> 8);
  1523. ndata[1] = afi;
  1524. ndata[2] = safi;
  1525. ndata[3] = (peer->pmax[afi][safi] >> 24);
  1526. ndata[4] = (peer->pmax[afi][safi] >> 16);
  1527. ndata[5] = (peer->pmax[afi][safi] >> 8);
  1528. ndata[6] = (peer->pmax[afi][safi]);
  1529. SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
  1530. bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
  1531. BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
  1532. }
  1533. /* restart timer start */
  1534. if (peer->pmax_restart[afi][safi])
  1535. {
  1536. peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
  1537. if (BGP_DEBUG (events, EVENTS))
  1538. zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
  1539. peer->host, peer->v_pmax_restart);
  1540. BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
  1541. peer->v_pmax_restart);
  1542. }
  1543. return 1;
  1544. }
  1545. else
  1546. UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
  1547. if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
  1548. {
  1549. if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
  1550. && ! always)
  1551. return 0;
  1552. zlog (peer->log, LOG_INFO,
  1553. "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
  1554. afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
  1555. peer->pmax[afi][safi]);
  1556. SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
  1557. }
  1558. else
  1559. UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
  1560. return 0;
  1561. }
  1562. /* Unconditionally remove the route from the RIB, without taking
  1563. * damping into consideration (eg, because the session went down)
  1564. */
  1565. static void
  1566. bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
  1567. afi_t afi, safi_t safi)
  1568. {
  1569. bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
  1570. if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
  1571. bgp_info_delete (rn, ri); /* keep historical info */
  1572. bgp_process (peer->bgp, rn, afi, safi);
  1573. }
  1574. static void
  1575. bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
  1576. afi_t afi, safi_t safi, struct prefix_rd *prd)
  1577. {
  1578. int status = BGP_DAMP_NONE;
  1579. /* apply dampening, if result is suppressed, we'll be retaining
  1580. * the bgp_info in the RIB for historical reference.
  1581. */
  1582. if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
  1583. && peer->sort == BGP_PEER_EBGP)
  1584. if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
  1585. == BGP_DAMP_SUPPRESSED)
  1586. {
  1587. bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
  1588. return;
  1589. }
  1590. bgp_rib_remove (rn, ri, peer, afi, safi);
  1591. }
  1592. static struct bgp_info *
  1593. info_make (int type, int sub_type, struct peer *peer, struct attr *attr,
  1594. struct bgp_node *rn)
  1595. {
  1596. struct bgp_info *new;
  1597. /* Make new BGP info. */
  1598. new = XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
  1599. new->type = type;
  1600. new->sub_type = sub_type;
  1601. new->peer = peer;
  1602. new->attr = attr;
  1603. new->uptime = bgp_clock ();
  1604. new->net = rn;
  1605. return new;
  1606. }
  1607. static void
  1608. bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
  1609. struct attr *attr, struct peer *peer, struct prefix *p, int type,
  1610. int sub_type, struct prefix_rd *prd, u_char *tag)
  1611. {
  1612. struct bgp_node *rn;
  1613. struct bgp *bgp;
  1614. struct attr new_attr;
  1615. struct attr_extra new_extra;
  1616. struct attr *attr_new;
  1617. struct attr *attr_new2;
  1618. struct bgp_info *ri;
  1619. struct bgp_info *new;
  1620. const char *reason;
  1621. char buf[SU_ADDRSTRLEN];
  1622. /* Do not insert announces from a rsclient into its own 'bgp_table'. */
  1623. if (peer == rsclient)
  1624. return;
  1625. bgp = peer->bgp;
  1626. rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
  1627. /* Check previously received route. */
  1628. for (ri = rn->info; ri; ri = ri->next)
  1629. if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
  1630. break;
  1631. /* AS path loop check. */
  1632. if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
  1633. {
  1634. reason = "as-path contains our own AS;";
  1635. goto filtered;
  1636. }
  1637. /* Route reflector originator ID check. */
  1638. if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
  1639. && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
  1640. {
  1641. reason = "originator is us;";
  1642. goto filtered;
  1643. }
  1644. new_attr.extra = &new_extra;
  1645. bgp_attr_dup (&new_attr, attr);
  1646. /* Apply export policy. */
  1647. if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
  1648. bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
  1649. {
  1650. reason = "export-policy;";
  1651. goto filtered;
  1652. }
  1653. attr_new2 = bgp_attr_intern (&new_attr);
  1654. /* Apply import policy. */
  1655. if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
  1656. {
  1657. bgp_attr_unintern (&attr_new2);
  1658. reason = "import-policy;";
  1659. goto filtered;
  1660. }
  1661. attr_new = bgp_attr_intern (&new_attr);
  1662. bgp_attr_unintern (&attr_new2);
  1663. /* IPv4 unicast next hop check. */
  1664. if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
  1665. {
  1666. /* Next hop must not be 0.0.0.0 nor Class D/E address. */
  1667. if (new_attr.nexthop.s_addr == 0
  1668. || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
  1669. {
  1670. bgp_attr_unintern (&attr_new);
  1671. reason = "martian next-hop;";
  1672. goto filtered;
  1673. }
  1674. }
  1675. /* If the update is implicit withdraw. */
  1676. if (ri)
  1677. {
  1678. ri->uptime = bgp_clock ();
  1679. /* Same attribute comes in. */
  1680. if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
  1681. && attrhash_cmp (ri->attr, attr_new))
  1682. {
  1683. if (BGP_DEBUG (update, UPDATE_IN))
  1684. zlog (peer->log, LOG_DEBUG,
  1685. "%s rcvd %s/%d for RS-client %s...duplicate ignored",
  1686. peer->host,
  1687. inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  1688. p->prefixlen, rsclient->host);
  1689. bgp_unlock_node (rn);
  1690. bgp_attr_unintern (&attr_new);
  1691. bgp_attr_flush(&new_attr);
  1692. return;
  1693. }
  1694. /* Withdraw/Announce before we fully processed the withdraw */
  1695. if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
  1696. bgp_info_restore (rn, ri);
  1697. /* Received Logging. */
  1698. if (BGP_DEBUG (update, UPDATE_IN))
  1699. zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
  1700. peer->host,
  1701. inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  1702. p->prefixlen, rsclient->host);
  1703. /* The attribute is changed. */
  1704. bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
  1705. /* Update to new attribute. */
  1706. bgp_attr_unintern (&ri->attr);
  1707. ri->attr = attr_new;
  1708. /* Update MPLS tag. */
  1709. if (safi == SAFI_MPLS_VPN)
  1710. memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
  1711. bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
  1712. /* Process change. */
  1713. bgp_process (bgp, rn, afi, safi);
  1714. bgp_unlock_node (rn);
  1715. return;
  1716. }
  1717. /* Received Logging. */
  1718. if (BGP_DEBUG (update, UPDATE_IN))
  1719. {
  1720. zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
  1721. peer->host,
  1722. inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  1723. p->prefixlen, rsclient->host);
  1724. }
  1725. new = info_make(type, sub_type, peer, attr_new, rn);
  1726. /* Update MPLS tag. */
  1727. if (safi == SAFI_MPLS_VPN)
  1728. memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
  1729. bgp_info_set_flag (rn, new, BGP_INFO_VALID);
  1730. /* Register new BGP information. */
  1731. bgp_info_add (rn, new);
  1732. /* route_node_get lock */
  1733. bgp_unlock_node (rn);
  1734. /* Process change. */
  1735. bgp_process (bgp, rn, afi, safi);
  1736. return;
  1737. filtered:
  1738. /* This BGP update is filtered. Log the reason then update BGP entry. */
  1739. if (BGP_DEBUG (update, UPDATE_IN))
  1740. zlog (peer->log, LOG_DEBUG,
  1741. "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
  1742. peer->host,
  1743. inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  1744. p->prefixlen, rsclient->host, reason);
  1745. if (ri)
  1746. bgp_rib_remove (rn, ri, peer, afi, safi);
  1747. bgp_unlock_node (rn);
  1748. return;
  1749. }
  1750. static void
  1751. bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
  1752. struct peer *peer, struct prefix *p, int type, int sub_type,
  1753. struct prefix_rd *prd, u_char *tag)
  1754. {
  1755. struct bgp_node *rn;
  1756. struct bgp_info *ri;
  1757. char buf[SU_ADDRSTRLEN];
  1758. if (rsclient == peer)
  1759. return;
  1760. rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
  1761. /* Lookup withdrawn route. */
  1762. for (ri = rn->info; ri; ri = ri->next)
  1763. if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
  1764. break;
  1765. /* Withdraw specified route from routing table. */
  1766. if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
  1767. bgp_rib_withdraw (rn, ri, peer, afi, safi, prd);
  1768. else if (BGP_DEBUG (update, UPDATE_IN))
  1769. zlog (peer->log, LOG_DEBUG,
  1770. "%s Can't find the route %s/%d", peer->host,
  1771. inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  1772. p->prefixlen);
  1773. /* Unlock bgp_node_get() lock. */
  1774. bgp_unlock_node (rn);
  1775. }
  1776. static int
  1777. bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
  1778. afi_t afi, safi_t safi, int type, int sub_type,
  1779. struct prefix_rd *prd, u_char *tag, int soft_reconfig)
  1780. {
  1781. int ret;
  1782. int aspath_loop_count = 0;
  1783. struct bgp_node *rn;
  1784. struct bgp *bgp;
  1785. struct attr new_attr;
  1786. struct attr_extra new_extra;
  1787. struct attr *attr_new;
  1788. struct bgp_info *ri;
  1789. struct bgp_info *new;
  1790. const char *reason;
  1791. char buf[SU_ADDRSTRLEN];
  1792. int connected = 0;
  1793. memset (&new_attr, 0, sizeof(struct attr));
  1794. memset (&new_extra, 0, sizeof(struct attr_extra));
  1795. bgp = peer->bgp;
  1796. rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
  1797. /* When peer's soft reconfiguration enabled. Record input packet in
  1798. Adj-RIBs-In. */
  1799. if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
  1800. && peer != bgp->peer_self)
  1801. bgp_adj_in_set (rn, peer, attr);
  1802. /* Check previously received route. */
  1803. for (ri = rn->info; ri; ri = ri->next)
  1804. if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
  1805. break;
  1806. /* AS path local-as loop check. */
  1807. if (peer->change_local_as)
  1808. {
  1809. if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
  1810. aspath_loop_count = 1;
  1811. if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
  1812. {
  1813. reason = "as-path contains our own AS;";
  1814. goto filtered;
  1815. }
  1816. }
  1817. /* AS path loop check. */
  1818. if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
  1819. || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
  1820. && aspath_loop_check(attr->aspath, bgp->confed_id)
  1821. > peer->allowas_in[afi][safi]))
  1822. {
  1823. reason = "as-path contains our own AS;";
  1824. goto filtered;
  1825. }
  1826. /* Route reflector originator ID check. */
  1827. if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
  1828. && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
  1829. {
  1830. reason = "originator is us;";
  1831. goto filtered;
  1832. }
  1833. /* Route reflector cluster ID check. */
  1834. if (bgp_cluster_filter (peer, attr))
  1835. {
  1836. reason = "reflected from the same cluster;";
  1837. goto filtered;
  1838. }
  1839. /* Apply incoming filter. */
  1840. if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
  1841. {
  1842. reason = "filter;";
  1843. goto filtered;
  1844. }
  1845. new_attr.extra = &new_extra;
  1846. bgp_attr_dup (&new_attr, attr);
  1847. /* Apply incoming route-map.
  1848. * NB: new_attr may now contain newly allocated values from route-map "set"
  1849. * commands, so we need bgp_attr_flush in the error paths, until we intern
  1850. * the attr (which takes over the memory references) */
  1851. if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
  1852. {
  1853. reason = "route-map;";
  1854. bgp_attr_flush (&new_attr);
  1855. goto filtered;
  1856. }
  1857. /* IPv4 unicast next hop check. */
  1858. if (afi == AFI_IP && safi == SAFI_UNICAST)
  1859. {
  1860. /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
  1861. must not be my own address. */
  1862. if (new_attr.nexthop.s_addr == 0
  1863. || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
  1864. || bgp_nexthop_self (&new_attr))
  1865. {
  1866. reason = "martian next-hop;";
  1867. bgp_attr_flush (&new_attr);
  1868. goto filtered;
  1869. }
  1870. }
  1871. attr_new = bgp_attr_intern (&new_attr);
  1872. /* If the update is implicit withdraw. */
  1873. if (ri)
  1874. {
  1875. ri->uptime = bgp_clock ();
  1876. /* Same attribute comes in. */
  1877. if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
  1878. && attrhash_cmp (ri->attr, attr_new))
  1879. {
  1880. if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
  1881. && peer->sort == BGP_PEER_EBGP
  1882. && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
  1883. {
  1884. if (BGP_DEBUG (update, UPDATE_IN))
  1885. zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
  1886. peer->host,
  1887. inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  1888. p->prefixlen);
  1889. if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
  1890. {
  1891. bgp_aggregate_increment (bgp, p, ri, afi, safi);
  1892. bgp_process (bgp, rn, afi, safi);
  1893. }
  1894. }
  1895. else /* Duplicate - odd */
  1896. {
  1897. if (BGP_DEBUG (update, UPDATE_IN))
  1898. zlog (peer->log, LOG_DEBUG,
  1899. "%s rcvd %s/%d...duplicate ignored",
  1900. peer->host,
  1901. inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  1902. p->prefixlen);
  1903. /* graceful restart STALE flag unset. */
  1904. if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
  1905. {
  1906. bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
  1907. bgp_process (bgp, rn, afi, safi);
  1908. }
  1909. }
  1910. bgp_unlock_node (rn);
  1911. bgp_attr_unintern (&attr_new);
  1912. bgp_attr_flush (&new_attr);
  1913. return 0;
  1914. }
  1915. /* Withdraw/Announce before we fully processed the withdraw */
  1916. if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
  1917. {
  1918. if (BGP_DEBUG (update, UPDATE_IN))
  1919. zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
  1920. peer->host,
  1921. inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  1922. p->prefixlen);
  1923. bgp_info_restore (rn, ri);
  1924. }
  1925. /* Received Logging. */
  1926. if (BGP_DEBUG (update, UPDATE_IN))
  1927. zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
  1928. peer->host,
  1929. inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  1930. p->prefixlen);
  1931. /* graceful restart STALE flag unset. */
  1932. if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
  1933. bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
  1934. /* The attribute is changed. */
  1935. bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
  1936. /* implicit withdraw, decrement aggregate and pcount here.
  1937. * only if update is accepted, they'll increment below.
  1938. */
  1939. bgp_aggregate_decrement (bgp, p, ri, afi, safi);
  1940. /* Update bgp route dampening information. */
  1941. if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
  1942. && peer->sort == BGP_PEER_EBGP)
  1943. {
  1944. /* This is implicit withdraw so we should update dampening
  1945. information. */
  1946. if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
  1947. bgp_damp_withdraw (ri, rn, afi, safi, 1);
  1948. }
  1949. /* Update to new attribute. */
  1950. bgp_attr_unintern (&ri->attr);
  1951. ri->attr = attr_new;
  1952. /* Update MPLS tag. */
  1953. if (safi == SAFI_MPLS_VPN)
  1954. memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
  1955. bgp_attr_flush (&new_attr);
  1956. /* Update bgp route dampening information. */
  1957. if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
  1958. && peer->sort == BGP_PEER_EBGP)
  1959. {
  1960. /* Now we do normal update dampening. */
  1961. ret = bgp_damp_update (ri, rn, afi, safi);
  1962. if (ret == BGP_DAMP_SUPPRESSED)
  1963. {
  1964. bgp_unlock_node (rn);
  1965. return 0;
  1966. }
  1967. }
  1968. /* Nexthop reachability check. */
  1969. if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
  1970. {
  1971. if (peer->sort == BGP_PEER_EBGP && peer_ttl (peer) == 1 &&
  1972. ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
  1973. connected = 1;
  1974. else
  1975. connected = 0;
  1976. if (bgp_ensure_nexthop (ri, NULL, connected))
  1977. bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
  1978. else
  1979. {
  1980. if (BGP_DEBUG(nht, NHT))
  1981. {
  1982. char buf1[INET6_ADDRSTRLEN];
  1983. inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
  1984. zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
  1985. }
  1986. bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
  1987. }
  1988. }
  1989. else
  1990. bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
  1991. bgp_attr_flush (&new_attr);
  1992. /* Process change. */
  1993. bgp_aggregate_increment (bgp, p, ri, afi, safi);
  1994. bgp_process (bgp, rn, afi, safi);
  1995. bgp_unlock_node (rn);
  1996. return 0;
  1997. }
  1998. /* Received Logging. */
  1999. if (BGP_DEBUG (update, UPDATE_IN))
  2000. {
  2001. zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
  2002. peer->host,
  2003. inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  2004. p->prefixlen);
  2005. }
  2006. /* Make new BGP info. */
  2007. new = info_make(type, sub_type, peer, attr_new, rn);
  2008. /* Update MPLS tag. */
  2009. if (safi == SAFI_MPLS_VPN)
  2010. memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
  2011. /* Nexthop reachability check. */
  2012. if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
  2013. {
  2014. if (peer->sort == BGP_PEER_EBGP && peer_ttl (peer) == 1 &&
  2015. ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
  2016. connected = 1;
  2017. else
  2018. connected = 0;
  2019. if (bgp_ensure_nexthop (new, NULL, connected))
  2020. bgp_info_set_flag (rn, new, BGP_INFO_VALID);
  2021. else
  2022. {
  2023. if (BGP_DEBUG(nht, NHT))
  2024. {
  2025. char buf1[INET6_ADDRSTRLEN];
  2026. inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
  2027. zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
  2028. }
  2029. bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
  2030. }
  2031. }
  2032. else
  2033. bgp_info_set_flag (rn, new, BGP_INFO_VALID);
  2034. /* Increment prefix */
  2035. bgp_aggregate_increment (bgp, p, new, afi, safi);
  2036. /* Register new BGP information. */
  2037. bgp_info_add (rn, new);
  2038. /* route_node_get lock */
  2039. bgp_unlock_node (rn);
  2040. bgp_attr_flush (&new_attr);
  2041. /* If maximum prefix count is configured and current prefix
  2042. count exeed it. */
  2043. if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
  2044. return -1;
  2045. /* Process change. */
  2046. bgp_process (bgp, rn, afi, safi);
  2047. return 0;
  2048. /* This BGP update is filtered. Log the reason then update BGP
  2049. entry. */
  2050. filtered:
  2051. if (BGP_DEBUG (update, UPDATE_IN))
  2052. zlog (peer->log, LOG_DEBUG,
  2053. "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
  2054. peer->host,
  2055. inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  2056. p->prefixlen, reason);
  2057. if (ri)
  2058. bgp_rib_remove (rn, ri, peer, afi, safi);
  2059. bgp_unlock_node (rn);
  2060. bgp_attr_flush (&new_attr);
  2061. return 0;
  2062. }
  2063. int
  2064. bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
  2065. afi_t afi, safi_t safi, int type, int sub_type,
  2066. struct prefix_rd *prd, u_char *tag, int soft_reconfig)
  2067. {
  2068. struct peer *rsclient;
  2069. struct listnode *node, *nnode;
  2070. struct bgp *bgp;
  2071. int ret;
  2072. ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
  2073. soft_reconfig);
  2074. bgp = peer->bgp;
  2075. /* Process the update for each RS-client. */
  2076. for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
  2077. {
  2078. if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
  2079. bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
  2080. sub_type, prd, tag);
  2081. }
  2082. return ret;
  2083. }
  2084. int
  2085. bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
  2086. afi_t afi, safi_t safi, int type, int sub_type,
  2087. struct prefix_rd *prd, u_char *tag)
  2088. {
  2089. struct bgp *bgp;
  2090. char buf[SU_ADDRSTRLEN];
  2091. struct bgp_node *rn;
  2092. struct bgp_info *ri;
  2093. struct peer *rsclient;
  2094. struct listnode *node, *nnode;
  2095. bgp = peer->bgp;
  2096. /* Lookup node. */
  2097. rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
  2098. /* Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all
  2099. * routes that are filtered. This tanks out Quagga RS pretty badly due to
  2100. * the iteration over all RS clients.
  2101. * Since we need to remove the entry from adj_in anyway, do that first and
  2102. * if there was no entry, we don't need to do anything more. */
  2103. if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
  2104. && peer != bgp->peer_self)
  2105. if (!bgp_adj_in_unset (rn, peer))
  2106. {
  2107. if (BGP_DEBUG (update, UPDATE_IN))
  2108. zlog (peer->log, LOG_DEBUG, "%s withdrawing route %s/%d "
  2109. "not in adj-in", peer->host,
  2110. inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  2111. p->prefixlen);
  2112. bgp_unlock_node (rn);
  2113. return 0;
  2114. }
  2115. /* Process the withdraw for each RS-client. */
  2116. for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
  2117. {
  2118. if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
  2119. bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
  2120. }
  2121. /* Logging. */
  2122. if (BGP_DEBUG (update, UPDATE_IN))
  2123. zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
  2124. peer->host,
  2125. inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  2126. p->prefixlen);
  2127. /* Lookup withdrawn route. */
  2128. for (ri = rn->info; ri; ri = ri->next)
  2129. if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
  2130. break;
  2131. /* Withdraw specified route from routing table. */
  2132. if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
  2133. bgp_rib_withdraw (rn, ri, peer, afi, safi, prd);
  2134. else if (BGP_DEBUG (update, UPDATE_IN))
  2135. zlog (peer->log, LOG_DEBUG,
  2136. "%s Can't find the route %s/%d", peer->host,
  2137. inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  2138. p->prefixlen);
  2139. /* Unlock bgp_node_get() lock. */
  2140. bgp_unlock_node (rn);
  2141. return 0;
  2142. }
  2143. void
  2144. bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
  2145. {
  2146. struct bgp *bgp;
  2147. struct attr attr;
  2148. struct aspath *aspath;
  2149. struct prefix p;
  2150. struct peer *from;
  2151. struct bgp_node *rn;
  2152. struct bgp_info *ri;
  2153. int ret = RMAP_DENYMATCH;
  2154. if (!(afi == AFI_IP || afi == AFI_IP6))
  2155. return;
  2156. bgp = peer->bgp;
  2157. from = bgp->peer_self;
  2158. bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
  2159. aspath = attr.aspath;
  2160. attr.local_pref = bgp->default_local_pref;
  2161. memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
  2162. if (afi == AFI_IP)
  2163. str2prefix ("0.0.0.0/0", &p);
  2164. else if (afi == AFI_IP6)
  2165. {
  2166. struct attr_extra *ae = attr.extra;
  2167. str2prefix ("::/0", &p);
  2168. /* IPv6 global nexthop must be included. */
  2169. memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
  2170. IPV6_MAX_BYTELEN);
  2171. ae->mp_nexthop_len = 16;
  2172. /* If the peer is on shared nextwork and we have link-local
  2173. nexthop set it. */
  2174. if (peer->shared_network
  2175. && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
  2176. {
  2177. memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
  2178. IPV6_MAX_BYTELEN);
  2179. ae->mp_nexthop_len = 32;
  2180. }
  2181. }
  2182. if (peer->default_rmap[afi][safi].name)
  2183. {
  2184. SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
  2185. for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
  2186. {
  2187. for (ri = rn->info; ri; ri = ri->next)
  2188. {
  2189. struct attr dummy_attr;
  2190. struct attr_extra dummy_extra;
  2191. struct bgp_info info;
  2192. /* Provide dummy so the route-map can't modify the attributes */
  2193. dummy_attr.extra = &dummy_extra;
  2194. bgp_attr_dup(&dummy_attr, ri->attr);
  2195. info.peer = ri->peer;
  2196. info.attr = &dummy_attr;
  2197. ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
  2198. RMAP_BGP, &info);
  2199. /* The route map might have set attributes. If we don't flush them
  2200. * here, they will be leaked. */
  2201. bgp_attr_flush(&dummy_attr);
  2202. if (ret != RMAP_DENYMATCH)
  2203. break;
  2204. }
  2205. if (ret != RMAP_DENYMATCH)
  2206. break;
  2207. }
  2208. bgp->peer_self->rmap_type = 0;
  2209. if (ret == RMAP_DENYMATCH)
  2210. withdraw = 1;
  2211. }
  2212. if (withdraw)
  2213. {
  2214. if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
  2215. bgp_default_withdraw_send (peer, afi, safi);
  2216. UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
  2217. }
  2218. else
  2219. {
  2220. if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
  2221. {
  2222. SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
  2223. bgp_default_update_send (peer, &attr, afi, safi, from);
  2224. }
  2225. }
  2226. bgp_attr_extra_free (&attr);
  2227. aspath_unintern (&aspath);
  2228. }
  2229. static void
  2230. bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
  2231. struct bgp_table *table, int rsclient)
  2232. {
  2233. struct bgp_node *rn;
  2234. struct bgp_info *ri;
  2235. struct attr attr;
  2236. struct attr_extra extra;
  2237. memset(&extra, 0, sizeof(extra));
  2238. if (! table)
  2239. table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
  2240. if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP)
  2241. && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
  2242. bgp_default_originate (peer, afi, safi, 0);
  2243. /* It's initialized in bgp_announce_[check|check_rsclient]() */
  2244. attr.extra = &extra;
  2245. for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
  2246. for (ri = rn->info; ri; ri = ri->next)
  2247. if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
  2248. {
  2249. if ( (rsclient) ?
  2250. (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
  2251. : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
  2252. bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
  2253. else
  2254. bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
  2255. }
  2256. bgp_attr_flush_encap(&attr);
  2257. }
  2258. void
  2259. bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
  2260. {
  2261. struct bgp_node *rn;
  2262. struct bgp_table *table;
  2263. if (peer->status != Established)
  2264. return;
  2265. if (! peer->afc_nego[afi][safi])
  2266. return;
  2267. /* First update is deferred until ORF or ROUTE-REFRESH is received */
  2268. if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
  2269. return;
  2270. if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
  2271. bgp_announce_table (peer, afi, safi, NULL, 0);
  2272. else
  2273. for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
  2274. rn = bgp_route_next(rn))
  2275. if ((table = (rn->info)) != NULL)
  2276. bgp_announce_table (peer, afi, safi, table, 0);
  2277. if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
  2278. bgp_announce_table (peer, afi, safi, NULL, 1);
  2279. }
  2280. void
  2281. bgp_announce_route_all (struct peer *peer)
  2282. {
  2283. afi_t afi;
  2284. safi_t safi;
  2285. for (afi = AFI_IP; afi < AFI_MAX; afi++)
  2286. for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
  2287. bgp_announce_route (peer, afi, safi);
  2288. }
  2289. static void
  2290. bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
  2291. safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
  2292. {
  2293. struct bgp_node *rn;
  2294. struct bgp_adj_in *ain;
  2295. if (! table)
  2296. table = rsclient->bgp->rib[afi][safi];
  2297. for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
  2298. for (ain = rn->adj_in; ain; ain = ain->next)
  2299. {
  2300. struct bgp_info *ri = rn->info;
  2301. u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
  2302. bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
  2303. &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag);
  2304. }
  2305. }
  2306. void
  2307. bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
  2308. {
  2309. struct bgp_table *table;
  2310. struct bgp_node *rn;
  2311. if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
  2312. bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
  2313. else
  2314. for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
  2315. rn = bgp_route_next (rn))
  2316. if ((table = rn->info) != NULL)
  2317. {
  2318. struct prefix_rd prd;
  2319. prd.family = AF_UNSPEC;
  2320. prd.prefixlen = 64;
  2321. memcpy(&prd.val, rn->p.u.val, 8);
  2322. bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
  2323. }
  2324. }
  2325. static void
  2326. bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
  2327. struct bgp_table *table, struct prefix_rd *prd)
  2328. {
  2329. int ret;
  2330. struct bgp_node *rn;
  2331. struct bgp_adj_in *ain;
  2332. if (! table)
  2333. table = peer->bgp->rib[afi][safi];
  2334. for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
  2335. for (ain = rn->adj_in; ain; ain = ain->next)
  2336. {
  2337. if (ain->peer == peer)
  2338. {
  2339. struct bgp_info *ri = rn->info;
  2340. u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
  2341. ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
  2342. ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
  2343. prd, tag, 1);
  2344. if (ret < 0)
  2345. {
  2346. bgp_unlock_node (rn);
  2347. return;
  2348. }
  2349. continue;
  2350. }
  2351. }
  2352. }
  2353. void
  2354. bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
  2355. {
  2356. struct bgp_node *rn;
  2357. struct bgp_table *table;
  2358. if (peer->status != Established)
  2359. return;
  2360. if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
  2361. bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
  2362. else
  2363. for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
  2364. rn = bgp_route_next (rn))
  2365. if ((table = rn->info) != NULL)
  2366. {
  2367. struct prefix_rd prd;
  2368. prd.family = AF_UNSPEC;
  2369. prd.prefixlen = 64;
  2370. memcpy(&prd.val, rn->p.u.val, 8);
  2371. bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
  2372. }
  2373. }
  2374. struct bgp_clear_node_queue
  2375. {
  2376. struct bgp_node *rn;
  2377. enum bgp_clear_route_type purpose;
  2378. };
  2379. static wq_item_status
  2380. bgp_clear_route_node (struct work_queue *wq, void *data)
  2381. {
  2382. struct bgp_clear_node_queue *cnq = data;
  2383. struct bgp_node *rn = cnq->rn;
  2384. struct peer *peer = wq->spec.data;
  2385. struct bgp_info *ri;
  2386. afi_t afi = bgp_node_table (rn)->afi;
  2387. safi_t safi = bgp_node_table (rn)->safi;
  2388. assert (rn && peer);
  2389. for (ri = rn->info; ri; ri = ri->next)
  2390. if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
  2391. {
  2392. /* graceful restart STALE flag set. */
  2393. if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
  2394. && peer->nsf[afi][safi]
  2395. && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
  2396. && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
  2397. bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
  2398. else
  2399. bgp_rib_remove (rn, ri, peer, afi, safi);
  2400. break;
  2401. }
  2402. return WQ_SUCCESS;
  2403. }
  2404. static void
  2405. bgp_clear_node_queue_del (struct work_queue *wq, void *data)
  2406. {
  2407. struct bgp_clear_node_queue *cnq = data;
  2408. struct bgp_node *rn = cnq->rn;
  2409. struct bgp_table *table = bgp_node_table (rn);
  2410. bgp_unlock_node (rn);
  2411. bgp_table_unlock (table);
  2412. XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
  2413. }
  2414. static void
  2415. bgp_clear_node_complete (struct work_queue *wq)
  2416. {
  2417. struct peer *peer = wq->spec.data;
  2418. /* Tickle FSM to start moving again */
  2419. BGP_EVENT_ADD (peer, Clearing_Completed);
  2420. peer_unlock (peer); /* bgp_clear_route */
  2421. }
  2422. static void
  2423. bgp_clear_node_queue_init (struct peer *peer)
  2424. {
  2425. char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
  2426. snprintf (wname, sizeof(wname), "clear %s", peer->host);
  2427. #undef CLEAR_QUEUE_NAME_LEN
  2428. if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
  2429. {
  2430. zlog_err ("%s: Failed to allocate work queue", __func__);
  2431. exit (1);
  2432. }
  2433. peer->clear_node_queue->spec.hold = 10;
  2434. peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
  2435. peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
  2436. peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
  2437. peer->clear_node_queue->spec.max_retries = 0;
  2438. /* we only 'lock' this peer reference when the queue is actually active */
  2439. peer->clear_node_queue->spec.data = peer;
  2440. }
  2441. static void
  2442. bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
  2443. struct bgp_table *table, struct peer *rsclient,
  2444. enum bgp_clear_route_type purpose)
  2445. {
  2446. struct bgp_node *rn;
  2447. if (! table)
  2448. table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
  2449. /* If still no table => afi/safi isn't configured at all or smth. */
  2450. if (! table)
  2451. return;
  2452. for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
  2453. {
  2454. struct bgp_info *ri;
  2455. struct bgp_adj_in *ain;
  2456. struct bgp_adj_out *aout;
  2457. /* XXX:TODO: This is suboptimal, every non-empty route_node is
  2458. * queued for every clearing peer, regardless of whether it is
  2459. * relevant to the peer at hand.
  2460. *
  2461. * Overview: There are 3 different indices which need to be
  2462. * scrubbed, potentially, when a peer is removed:
  2463. *
  2464. * 1 peer's routes visible via the RIB (ie accepted routes)
  2465. * 2 peer's routes visible by the (optional) peer's adj-in index
  2466. * 3 other routes visible by the peer's adj-out index
  2467. *
  2468. * 3 there is no hurry in scrubbing, once the struct peer is
  2469. * removed from bgp->peer, we could just GC such deleted peer's
  2470. * adj-outs at our leisure.
  2471. *
  2472. * 1 and 2 must be 'scrubbed' in some way, at least made
  2473. * invisible via RIB index before peer session is allowed to be
  2474. * brought back up. So one needs to know when such a 'search' is
  2475. * complete.
  2476. *
  2477. * Ideally:
  2478. *
  2479. * - there'd be a single global queue or a single RIB walker
  2480. * - rather than tracking which route_nodes still need to be
  2481. * examined on a peer basis, we'd track which peers still
  2482. * aren't cleared
  2483. *
  2484. * Given that our per-peer prefix-counts now should be reliable,
  2485. * this may actually be achievable. It doesn't seem to be a huge
  2486. * problem at this time,
  2487. */
  2488. for (ain = rn->adj_in; ain; ain = ain->next)
  2489. if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
  2490. {
  2491. bgp_adj_in_remove (rn, ain);
  2492. bgp_unlock_node (rn);
  2493. break;
  2494. }
  2495. for (aout = rn->adj_out; aout; aout = aout->next)
  2496. if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
  2497. {
  2498. bgp_adj_out_remove (rn, aout, peer, afi, safi);
  2499. bgp_unlock_node (rn);
  2500. break;
  2501. }
  2502. for (ri = rn->info; ri; ri = ri->next)
  2503. if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
  2504. {
  2505. struct bgp_clear_node_queue *cnq;
  2506. /* both unlocked in bgp_clear_node_queue_del */
  2507. bgp_table_lock (bgp_node_table (rn));
  2508. bgp_lock_node (rn);
  2509. cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
  2510. sizeof (struct bgp_clear_node_queue));
  2511. cnq->rn = rn;
  2512. cnq->purpose = purpose;
  2513. work_queue_add (peer->clear_node_queue, cnq);
  2514. break;
  2515. }
  2516. }
  2517. return;
  2518. }
  2519. void
  2520. bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
  2521. enum bgp_clear_route_type purpose)
  2522. {
  2523. struct bgp_node *rn;
  2524. struct bgp_table *table;
  2525. struct peer *rsclient;
  2526. struct listnode *node, *nnode;
  2527. if (peer->clear_node_queue == NULL)
  2528. bgp_clear_node_queue_init (peer);
  2529. /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
  2530. * Idle until it receives a Clearing_Completed event. This protects
  2531. * against peers which flap faster than we can we clear, which could
  2532. * lead to:
  2533. *
  2534. * a) race with routes from the new session being installed before
  2535. * clear_route_node visits the node (to delete the route of that
  2536. * peer)
  2537. * b) resource exhaustion, clear_route_node likely leads to an entry
  2538. * on the process_main queue. Fast-flapping could cause that queue
  2539. * to grow and grow.
  2540. */
  2541. /* lock peer in assumption that clear-node-queue will get nodes; if so,
  2542. * the unlock will happen upon work-queue completion; other wise, the
  2543. * unlock happens at the end of this function.
  2544. */
  2545. if (!peer->clear_node_queue->thread)
  2546. peer_lock (peer); /* bgp_clear_node_complete */
  2547. switch (purpose)
  2548. {
  2549. case BGP_CLEAR_ROUTE_NORMAL:
  2550. if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
  2551. bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
  2552. else
  2553. for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
  2554. rn = bgp_route_next (rn))
  2555. if ((table = rn->info) != NULL)
  2556. bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
  2557. for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
  2558. if (CHECK_FLAG(rsclient->af_flags[afi][safi],
  2559. PEER_FLAG_RSERVER_CLIENT))
  2560. bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
  2561. break;
  2562. case BGP_CLEAR_ROUTE_MY_RSCLIENT:
  2563. /*
  2564. * gpz 091009: TBD why don't we have special handling for
  2565. * SAFI_MPLS_VPN here in the original quagga code?
  2566. * (and, by extension, for SAFI_ENCAP)
  2567. */
  2568. bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
  2569. break;
  2570. default:
  2571. assert (0);
  2572. break;
  2573. }
  2574. /* unlock if no nodes got added to the clear-node-queue. */
  2575. if (!peer->clear_node_queue->thread)
  2576. peer_unlock (peer);
  2577. }
  2578. void
  2579. bgp_clear_route_all (struct peer *peer)
  2580. {
  2581. afi_t afi;
  2582. safi_t safi;
  2583. for (afi = AFI_IP; afi < AFI_MAX; afi++)
  2584. for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
  2585. bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
  2586. }
  2587. /*
  2588. * Finish freeing things when exiting
  2589. */
  2590. static void
  2591. bgp_drain_workqueue_immediate (struct work_queue *wq)
  2592. {
  2593. if (!wq)
  2594. return;
  2595. if (!wq->thread)
  2596. {
  2597. /*
  2598. * no thread implies no queued items
  2599. */
  2600. assert(!wq->items->count);
  2601. return;
  2602. }
  2603. while (wq->items->count)
  2604. {
  2605. if (wq->thread)
  2606. thread_cancel(wq->thread);
  2607. work_queue_run(wq->thread);
  2608. }
  2609. }
  2610. /*
  2611. * Special function to process clear node queue when bgpd is exiting
  2612. * and the thread scheduler is no longer running.
  2613. */
  2614. void
  2615. bgp_peer_clear_node_queue_drain_immediate(struct peer *peer)
  2616. {
  2617. if (!peer)
  2618. return;
  2619. bgp_drain_workqueue_immediate(peer->clear_node_queue);
  2620. }
  2621. /*
  2622. * The work queues are not specific to a BGP instance, but the
  2623. * items in them refer to BGP instances, so this should be called
  2624. * before each BGP instance is deleted.
  2625. */
  2626. void
  2627. bgp_process_queues_drain_immediate(void)
  2628. {
  2629. bgp_drain_workqueue_immediate(bm->process_main_queue);
  2630. bgp_drain_workqueue_immediate(bm->process_rsclient_queue);
  2631. }
  2632. void
  2633. bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
  2634. {
  2635. struct bgp_table *table;
  2636. struct bgp_node *rn;
  2637. struct bgp_adj_in *ain;
  2638. table = peer->bgp->rib[afi][safi];
  2639. for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
  2640. for (ain = rn->adj_in; ain ; ain = ain->next)
  2641. if (ain->peer == peer)
  2642. {
  2643. bgp_adj_in_remove (rn, ain);
  2644. bgp_unlock_node (rn);
  2645. break;
  2646. }
  2647. }
  2648. void
  2649. bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
  2650. {
  2651. struct bgp_node *rn;
  2652. struct bgp_info *ri;
  2653. struct bgp_table *table;
  2654. table = peer->bgp->rib[afi][safi];
  2655. for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
  2656. {
  2657. for (ri = rn->info; ri; ri = ri->next)
  2658. if (ri->peer == peer)
  2659. {
  2660. if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
  2661. bgp_rib_remove (rn, ri, peer, afi, safi);
  2662. break;
  2663. }
  2664. }
  2665. }
  2666. static void
  2667. bgp_cleanup_table(struct bgp_table *table, safi_t safi)
  2668. {
  2669. struct bgp_node *rn;
  2670. struct bgp_info *ri;
  2671. struct bgp_info *next;
  2672. for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
  2673. for (ri = rn->info; ri; ri = next)
  2674. {
  2675. next = ri->next;
  2676. if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
  2677. && ri->type == ZEBRA_ROUTE_BGP
  2678. && ri->sub_type == BGP_ROUTE_NORMAL)
  2679. bgp_zebra_withdraw (&rn->p, ri, safi);
  2680. }
  2681. }
  2682. /* Delete all kernel routes. */
  2683. void
  2684. bgp_cleanup_routes (void)
  2685. {
  2686. struct bgp *bgp;
  2687. struct listnode *node, *nnode;
  2688. afi_t afi;
  2689. for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
  2690. {
  2691. for (afi = AFI_IP; afi < AFI_MAX; ++afi)
  2692. {
  2693. struct bgp_node *rn;
  2694. bgp_cleanup_table(bgp->rib[afi][SAFI_UNICAST], SAFI_UNICAST);
  2695. /*
  2696. * VPN and ENCAP tables are two-level (RD is top level)
  2697. */
  2698. for (rn = bgp_table_top(bgp->rib[afi][SAFI_MPLS_VPN]); rn;
  2699. rn = bgp_route_next (rn))
  2700. {
  2701. if (rn->info)
  2702. {
  2703. bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_MPLS_VPN);
  2704. bgp_table_finish ((struct bgp_table **)&(rn->info));
  2705. rn->info = NULL;
  2706. bgp_unlock_node(rn);
  2707. }
  2708. }
  2709. for (rn = bgp_table_top(bgp->rib[afi][SAFI_ENCAP]); rn;
  2710. rn = bgp_route_next (rn))
  2711. {
  2712. if (rn->info)
  2713. {
  2714. bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_ENCAP);
  2715. bgp_table_finish ((struct bgp_table **)&(rn->info));
  2716. rn->info = NULL;
  2717. bgp_unlock_node(rn);
  2718. }
  2719. }
  2720. }
  2721. }
  2722. }
  2723. void
  2724. bgp_reset (void)
  2725. {
  2726. vty_reset ();
  2727. bgp_zclient_reset ();
  2728. access_list_reset ();
  2729. prefix_list_reset ();
  2730. }
  2731. /* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
  2732. value. */
  2733. int
  2734. bgp_nlri_parse_ip (struct peer *peer, struct attr *attr,
  2735. struct bgp_nlri *packet)
  2736. {
  2737. u_char *pnt;
  2738. u_char *lim;
  2739. struct prefix p;
  2740. int psize;
  2741. int ret;
  2742. /* Check peer status. */
  2743. if (peer->status != Established)
  2744. return 0;
  2745. pnt = packet->nlri;
  2746. lim = pnt + packet->length;
  2747. /* RFC4771 6.3 The NLRI field in the UPDATE message is checked for
  2748. syntactic validity. If the field is syntactically incorrect,
  2749. then the Error Subcode is set to Invalid Network Field. */
  2750. for (; pnt < lim; pnt += psize)
  2751. {
  2752. /* Clear prefix structure. */
  2753. memset (&p, 0, sizeof (struct prefix));
  2754. /* Fetch prefix length. */
  2755. p.prefixlen = *pnt++;
  2756. /* afi/safi validity already verified by caller, bgp_update_receive */
  2757. p.family = afi2family (packet->afi);
  2758. /* Prefix length check. */
  2759. if (p.prefixlen > prefix_blen (&p) * 8)
  2760. {
  2761. plog_err (peer->log,
  2762. "%s [Error] Update packet error"
  2763. " (wrong prefix length %u for afi %u)",
  2764. peer->host, p.prefixlen, packet->afi);
  2765. return -1;
  2766. }
  2767. /* Packet size overflow check. */
  2768. psize = PSIZE (p.prefixlen);
  2769. /* When packet overflow occur return immediately. */
  2770. if (pnt + psize > lim)
  2771. {
  2772. plog_err (peer->log,
  2773. "%s [Error] Update packet error"
  2774. " (prefix length %u overflows packet)",
  2775. peer->host, p.prefixlen);
  2776. return -1;
  2777. }
  2778. /* Defensive coding, double-check the psize fits in a struct prefix */
  2779. if (psize > (ssize_t) sizeof(p.u))
  2780. {
  2781. plog_err (peer->log,
  2782. "%s [Error] Update packet error"
  2783. " (prefix length %u too large for prefix storage %zu!?!!",
  2784. peer->host, p.prefixlen, sizeof(p.u));
  2785. return -1;
  2786. }
  2787. /* Fetch prefix from NLRI packet. */
  2788. memcpy (&p.u.prefix, pnt, psize);
  2789. /* Check address. */
  2790. if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
  2791. {
  2792. if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
  2793. {
  2794. /*
  2795. * From RFC4271 Section 6.3:
  2796. *
  2797. * If a prefix in the NLRI field is semantically incorrect
  2798. * (e.g., an unexpected multicast IP address), an error SHOULD
  2799. * be logged locally, and the prefix SHOULD be ignored.
  2800. */
  2801. zlog (peer->log, LOG_ERR,
  2802. "%s: IPv4 unicast NLRI is multicast address %s, ignoring",
  2803. peer->host, inet_ntoa (p.u.prefix4));
  2804. continue;
  2805. }
  2806. }
  2807. /* Check address. */
  2808. if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
  2809. {
  2810. if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
  2811. {
  2812. char buf[BUFSIZ];
  2813. zlog (peer->log, LOG_ERR,
  2814. "%s: IPv6 unicast NLRI is link-local address %s, ignoring",
  2815. peer->host,
  2816. inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
  2817. continue;
  2818. }
  2819. if (IN6_IS_ADDR_MULTICAST (&p.u.prefix6))
  2820. {
  2821. char buf[BUFSIZ];
  2822. zlog (peer->log, LOG_ERR,
  2823. "%s: IPv6 unicast NLRI is multicast address %s, ignoring",
  2824. peer->host,
  2825. inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
  2826. continue;
  2827. }
  2828. }
  2829. /* Normal process. */
  2830. if (attr)
  2831. ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
  2832. ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
  2833. else
  2834. ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
  2835. ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
  2836. /* Address family configuration mismatch or maximum-prefix count
  2837. overflow. */
  2838. if (ret < 0)
  2839. return -1;
  2840. }
  2841. /* Packet length consistency check. */
  2842. if (pnt != lim)
  2843. {
  2844. plog_err (peer->log,
  2845. "%s [Error] Update packet error"
  2846. " (prefix length mismatch with total length)",
  2847. peer->host);
  2848. return -1;
  2849. }
  2850. return 0;
  2851. }
  2852. static struct bgp_static *
  2853. bgp_static_new (void)
  2854. {
  2855. return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
  2856. }
  2857. static void
  2858. bgp_static_free (struct bgp_static *bgp_static)
  2859. {
  2860. if (bgp_static->rmap.name)
  2861. free (bgp_static->rmap.name);
  2862. XFREE (MTYPE_BGP_STATIC, bgp_static);
  2863. }
  2864. static void
  2865. bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
  2866. struct prefix *p, afi_t afi, safi_t safi)
  2867. {
  2868. struct bgp_node *rn;
  2869. struct bgp_info *ri;
  2870. rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
  2871. /* Check selected route and self inserted route. */
  2872. for (ri = rn->info; ri; ri = ri->next)
  2873. if (ri->peer == bgp->peer_self
  2874. && ri->type == ZEBRA_ROUTE_BGP
  2875. && ri->sub_type == BGP_ROUTE_STATIC)
  2876. break;
  2877. /* Withdraw static BGP route from routing table. */
  2878. if (ri)
  2879. {
  2880. bgp_info_delete (rn, ri);
  2881. bgp_process (bgp, rn, afi, safi);
  2882. }
  2883. /* Unlock bgp_node_lookup. */
  2884. bgp_unlock_node (rn);
  2885. }
  2886. static void
  2887. bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
  2888. struct bgp_static *bgp_static,
  2889. afi_t afi, safi_t safi)
  2890. {
  2891. struct bgp_node *rn;
  2892. struct bgp_info *ri;
  2893. struct bgp_info *new;
  2894. struct bgp_info info;
  2895. struct attr *attr_new;
  2896. struct attr attr;
  2897. struct attr new_attr;
  2898. struct attr_extra new_extra;
  2899. struct bgp *bgp;
  2900. int ret;
  2901. char buf[SU_ADDRSTRLEN];
  2902. bgp = rsclient->bgp;
  2903. assert (bgp_static);
  2904. if (!bgp_static)
  2905. return;
  2906. rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
  2907. bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
  2908. attr.nexthop = bgp_static->igpnexthop;
  2909. attr.med = bgp_static->igpmetric;
  2910. attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
  2911. if (bgp_static->atomic)
  2912. attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
  2913. /* Apply network route-map for export to this rsclient. */
  2914. if (bgp_static->rmap.name)
  2915. {
  2916. struct attr attr_tmp = attr;
  2917. info.peer = rsclient;
  2918. info.attr = &attr_tmp;
  2919. SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
  2920. SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
  2921. ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
  2922. rsclient->rmap_type = 0;
  2923. if (ret == RMAP_DENYMATCH)
  2924. {
  2925. /* Free uninterned attribute. */
  2926. bgp_attr_flush (&attr_tmp);
  2927. /* Unintern original. */
  2928. aspath_unintern (&attr.aspath);
  2929. bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
  2930. bgp_attr_extra_free (&attr);
  2931. return;
  2932. }
  2933. attr_new = bgp_attr_intern (&attr_tmp);
  2934. }
  2935. else
  2936. attr_new = bgp_attr_intern (&attr);
  2937. new_attr.extra = &new_extra;
  2938. bgp_attr_dup(&new_attr, attr_new);
  2939. SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
  2940. if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
  2941. == RMAP_DENY)
  2942. {
  2943. /* This BGP update is filtered. Log the reason then update BGP entry. */
  2944. if (BGP_DEBUG (update, UPDATE_IN))
  2945. zlog (rsclient->log, LOG_DEBUG,
  2946. "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
  2947. inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
  2948. p->prefixlen, rsclient->host);
  2949. bgp->peer_self->rmap_type = 0;
  2950. bgp_attr_unintern (&attr_new);
  2951. aspath_unintern (&attr.aspath);
  2952. bgp_attr_extra_free (&attr);
  2953. bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
  2954. return;
  2955. }
  2956. bgp->peer_self->rmap_type = 0;
  2957. bgp_attr_unintern (&attr_new);
  2958. attr_new = bgp_attr_intern (&new_attr);
  2959. for (ri = rn->info; ri; ri = ri->next)
  2960. if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
  2961. && ri->sub_type == BGP_ROUTE_STATIC)
  2962. break;
  2963. if (ri)
  2964. {
  2965. if (attrhash_cmp (ri->attr, attr_new) &&
  2966. !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
  2967. {
  2968. bgp_unlock_node (rn);
  2969. bgp_attr_unintern (&attr_new);
  2970. aspath_unintern (&attr.aspath);
  2971. bgp_attr_extra_free (&attr);
  2972. return;
  2973. }
  2974. else
  2975. {
  2976. /* The attribute is changed. */
  2977. bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
  2978. /* Rewrite BGP route information. */
  2979. if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
  2980. bgp_info_restore(rn, ri);
  2981. bgp_attr_unintern (&ri->attr);
  2982. ri->attr = attr_new;
  2983. ri->uptime = bgp_clock ();
  2984. /* Nexthop reachability check. */
  2985. if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
  2986. {
  2987. if (bgp_ensure_nexthop (ri, NULL, 0))
  2988. bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
  2989. else
  2990. {
  2991. if (BGP_DEBUG(nht, NHT))
  2992. {
  2993. char buf1[INET6_ADDRSTRLEN];
  2994. inet_ntop(AF_INET, (const void *)&attr_new->nexthop,
  2995. buf1, INET6_ADDRSTRLEN);
  2996. zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
  2997. }
  2998. bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
  2999. }
  3000. }
  3001. /* Process change. */
  3002. bgp_process (bgp, rn, afi, safi);
  3003. bgp_unlock_node (rn);
  3004. aspath_unintern (&attr.aspath);
  3005. bgp_attr_extra_free (&attr);
  3006. return;
  3007. }
  3008. }
  3009. /* Make new BGP info. */
  3010. new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, bgp->peer_self,
  3011. attr_new, rn);
  3012. /* Nexthop reachability check. */
  3013. if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
  3014. {
  3015. if (bgp_ensure_nexthop (new, NULL, 0))
  3016. bgp_info_set_flag (rn, new, BGP_INFO_VALID);
  3017. else
  3018. {
  3019. if (BGP_DEBUG(nht, NHT))
  3020. {
  3021. char buf1[INET6_ADDRSTRLEN];
  3022. inet_ntop(AF_INET, (const void *)&attr_new->nexthop,
  3023. buf1, INET6_ADDRSTRLEN);
  3024. zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
  3025. }
  3026. bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
  3027. }
  3028. }
  3029. else
  3030. bgp_info_set_flag (rn, new, BGP_INFO_VALID);
  3031. /* Register new BGP information. */
  3032. bgp_info_add (rn, new);
  3033. /* route_node_get lock */
  3034. bgp_unlock_node (rn);
  3035. /* Process change. */
  3036. bgp_process (bgp, rn, afi, safi);
  3037. /* Unintern original. */
  3038. aspath_unintern (&attr.aspath);
  3039. bgp_attr_extra_free (&attr);
  3040. }
  3041. static void
  3042. bgp_static_update_main (struct bgp *bgp, struct prefix *p,
  3043. struct bgp_static *bgp_static, afi_t afi, safi_t safi)
  3044. {
  3045. struct bgp_node *rn;
  3046. struct bgp_info *ri;
  3047. struct bgp_info *new;
  3048. struct bgp_info info;
  3049. struct attr attr;
  3050. struct attr *attr_new;
  3051. int ret;
  3052. assert (bgp_static);
  3053. if (!bgp_static)
  3054. return;
  3055. rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
  3056. bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
  3057. attr.nexthop = bgp_static->igpnexthop;
  3058. attr.med = bgp_static->igpmetric;
  3059. attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
  3060. if (bgp_static->atomic)
  3061. attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
  3062. /* Apply route-map. */
  3063. if (bgp_static->rmap.name)
  3064. {
  3065. struct attr attr_tmp = attr;
  3066. info.peer = bgp->peer_self;
  3067. info.attr = &attr_tmp;
  3068. SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
  3069. ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
  3070. bgp->peer_self->rmap_type = 0;
  3071. if (ret == RMAP_DENYMATCH)
  3072. {
  3073. /* Free uninterned attribute. */
  3074. bgp_attr_flush (&attr_tmp);
  3075. /* Unintern original. */
  3076. aspath_unintern (&attr.aspath);
  3077. bgp_attr_extra_free (&attr);
  3078. bgp_static_withdraw (bgp, p, afi, safi);
  3079. return;
  3080. }
  3081. attr_new = bgp_attr_intern (&attr_tmp);
  3082. }
  3083. else
  3084. attr_new = bgp_attr_intern (&attr);
  3085. for (ri = rn->info; ri; ri = ri->next)
  3086. if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
  3087. && ri->sub_type == BGP_ROUTE_STATIC)
  3088. break;
  3089. if (ri)
  3090. {
  3091. if (attrhash_cmp (ri->attr, attr_new) &&
  3092. !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
  3093. {
  3094. bgp_unlock_node (rn);
  3095. bgp_attr_unintern (&attr_new);
  3096. aspath_unintern (&attr.aspath);
  3097. bgp_attr_extra_free (&attr);
  3098. return;
  3099. }
  3100. else
  3101. {
  3102. /* The attribute is changed. */
  3103. bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
  3104. /* Rewrite BGP route information. */
  3105. if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
  3106. bgp_info_restore(rn, ri);
  3107. else
  3108. bgp_aggregate_decrement (bgp, p, ri, afi, safi);
  3109. bgp_attr_unintern (&ri->attr);
  3110. ri->attr = attr_new;
  3111. ri->uptime = bgp_clock ();
  3112. /* Nexthop reachability check. */
  3113. if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
  3114. {
  3115. if (bgp_ensure_nexthop (ri, NULL, 0))
  3116. bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
  3117. else
  3118. {
  3119. if (BGP_DEBUG(nht, NHT))
  3120. {
  3121. char buf1[INET6_ADDRSTRLEN];
  3122. inet_ntop(AF_INET, (const void *)&attr_new->nexthop,
  3123. buf1, INET6_ADDRSTRLEN);
  3124. zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
  3125. }
  3126. bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
  3127. }
  3128. }
  3129. /* Process change. */
  3130. bgp_aggregate_increment (bgp, p, ri, afi, safi);
  3131. bgp_process (bgp, rn, afi, safi);
  3132. bgp_unlock_node (rn);
  3133. aspath_unintern (&attr.aspath);
  3134. bgp_attr_extra_free (&attr);
  3135. return;
  3136. }
  3137. }
  3138. /* Make new BGP info. */
  3139. new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, bgp->peer_self, attr_new,
  3140. rn);
  3141. /* Nexthop reachability check. */
  3142. if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
  3143. {
  3144. if (bgp_ensure_nexthop (new, NULL, 0))
  3145. bgp_info_set_flag (rn, new, BGP_INFO_VALID);
  3146. else
  3147. {
  3148. if (BGP_DEBUG(nht, NHT))
  3149. {
  3150. char buf1[INET6_ADDRSTRLEN];
  3151. inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1,
  3152. INET6_ADDRSTRLEN);
  3153. zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
  3154. }
  3155. bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
  3156. }
  3157. }
  3158. else
  3159. bgp_info_set_flag (rn, new, BGP_INFO_VALID);
  3160. /* Aggregate address increment. */
  3161. bgp_aggregate_increment (bgp, p, new, afi, safi);
  3162. /* Register new BGP information. */
  3163. bgp_info_add (rn, new);
  3164. /* route_node_get lock */
  3165. bgp_unlock_node (rn);
  3166. /* Process change. */
  3167. bgp_process (bgp, rn, afi, safi);
  3168. /* Unintern original. */
  3169. aspath_unintern (&attr.aspath);
  3170. bgp_attr_extra_free (&attr);
  3171. }
  3172. void
  3173. bgp_static_update (struct bgp *bgp, struct prefix *p,
  3174. struct bgp_static *bgp_static, afi_t afi, safi_t safi)
  3175. {
  3176. struct peer *rsclient;
  3177. struct listnode *node, *nnode;
  3178. bgp_static_update_main (bgp, p, bgp_static, afi, safi);
  3179. for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
  3180. {
  3181. if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
  3182. bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
  3183. }
  3184. }
  3185. void
  3186. bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
  3187. safi_t safi)
  3188. {
  3189. struct bgp_node *rn;
  3190. struct bgp_info *ri;
  3191. /* Make new BGP info. */
  3192. rn = bgp_node_get (bgp->rib[afi][safi], p);
  3193. /* Check selected route and self inserted route. */
  3194. for (ri = rn->info; ri; ri = ri->next)
  3195. if (ri->peer == bgp->peer_self
  3196. && ri->type == ZEBRA_ROUTE_BGP
  3197. && ri->sub_type == BGP_ROUTE_STATIC)
  3198. break;
  3199. /* Withdraw static BGP route from routing table. */
  3200. if (ri)
  3201. {
  3202. bgp_aggregate_decrement (bgp, p, ri, afi, safi);
  3203. bgp_unlink_nexthop(ri);
  3204. bgp_info_delete (rn, ri);
  3205. bgp_process (bgp, rn, afi, safi);
  3206. }
  3207. /* Unlock bgp_node_lookup. */
  3208. bgp_unlock_node (rn);
  3209. }
  3210. void
  3211. bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
  3212. {
  3213. struct bgp_static *bgp_static;
  3214. struct bgp *bgp;
  3215. struct bgp_node *rn;
  3216. struct prefix *p;
  3217. bgp = rsclient->bgp;
  3218. for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
  3219. if ((bgp_static = rn->info) != NULL)
  3220. {
  3221. p = &rn->p;
  3222. bgp_static_update_rsclient (rsclient, p, bgp_static,
  3223. afi, safi);
  3224. }
  3225. }
  3226. /*
  3227. * Used for SAFI_MPLS_VPN and SAFI_ENCAP
  3228. */
  3229. static void
  3230. bgp_static_withdraw_safi (struct bgp *bgp, struct prefix *p, afi_t afi,
  3231. safi_t safi, struct prefix_rd *prd, u_char *tag)
  3232. {
  3233. struct bgp_node *rn;
  3234. struct bgp_info *ri;
  3235. rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
  3236. /* Check selected route and self inserted route. */
  3237. for (ri = rn->info; ri; ri = ri->next)
  3238. if (ri->peer == bgp->peer_self
  3239. && ri->type == ZEBRA_ROUTE_BGP
  3240. && ri->sub_type == BGP_ROUTE_STATIC)
  3241. break;
  3242. /* Withdraw static BGP route from routing table. */
  3243. if (ri)
  3244. {
  3245. bgp_aggregate_decrement (bgp, p, ri, afi, safi);
  3246. bgp_info_delete (rn, ri);
  3247. bgp_process (bgp, rn, afi, safi);
  3248. }
  3249. /* Unlock bgp_node_lookup. */
  3250. bgp_unlock_node (rn);
  3251. }
  3252. static void
  3253. bgp_static_update_safi (struct bgp *bgp, struct prefix *p,
  3254. struct bgp_static *bgp_static, afi_t afi, safi_t safi)
  3255. {
  3256. struct bgp_node *rn;
  3257. struct bgp_info *new;
  3258. struct attr *attr_new;
  3259. struct attr attr = { 0 };
  3260. struct bgp_info *ri;
  3261. assert (bgp_static);
  3262. rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, &bgp_static->prd);
  3263. bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
  3264. attr.nexthop = bgp_static->igpnexthop;
  3265. attr.med = bgp_static->igpmetric;
  3266. attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
  3267. /* Apply route-map. */
  3268. if (bgp_static->rmap.name)
  3269. {
  3270. struct attr attr_tmp = attr;
  3271. struct bgp_info info;
  3272. int ret;
  3273. info.peer = bgp->peer_self;
  3274. info.attr = &attr_tmp;
  3275. SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
  3276. ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
  3277. bgp->peer_self->rmap_type = 0;
  3278. if (ret == RMAP_DENYMATCH)
  3279. {
  3280. /* Free uninterned attribute. */
  3281. bgp_attr_flush (&attr_tmp);
  3282. /* Unintern original. */
  3283. aspath_unintern (&attr.aspath);
  3284. bgp_attr_extra_free (&attr);
  3285. bgp_static_withdraw_safi (bgp, p, afi, safi, &bgp_static->prd,
  3286. bgp_static->tag);
  3287. return;
  3288. }
  3289. attr_new = bgp_attr_intern (&attr_tmp);
  3290. }
  3291. else
  3292. {
  3293. attr_new = bgp_attr_intern (&attr);
  3294. }
  3295. for (ri = rn->info; ri; ri = ri->next)
  3296. if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
  3297. && ri->sub_type == BGP_ROUTE_STATIC)
  3298. break;
  3299. if (ri)
  3300. {
  3301. if (attrhash_cmp (ri->attr, attr_new) &&
  3302. !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
  3303. {
  3304. bgp_unlock_node (rn);
  3305. bgp_attr_unintern (&attr_new);
  3306. aspath_unintern (&attr.aspath);
  3307. bgp_attr_extra_free (&attr);
  3308. return;
  3309. }
  3310. else
  3311. {
  3312. /* The attribute is changed. */
  3313. bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
  3314. /* Rewrite BGP route information. */
  3315. if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
  3316. bgp_info_restore(rn, ri);
  3317. else
  3318. bgp_aggregate_decrement (bgp, p, ri, afi, safi);
  3319. bgp_attr_unintern (&ri->attr);
  3320. ri->attr = attr_new;
  3321. ri->uptime = bgp_clock ();
  3322. /* Process change. */
  3323. bgp_aggregate_increment (bgp, p, ri, afi, safi);
  3324. bgp_process (bgp, rn, afi, safi);
  3325. bgp_unlock_node (rn);
  3326. aspath_unintern (&attr.aspath);
  3327. bgp_attr_extra_free (&attr);
  3328. return;
  3329. }
  3330. }
  3331. /* Make new BGP info. */
  3332. new = info_make (ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, bgp->peer_self,
  3333. attr_new, rn);
  3334. SET_FLAG (new->flags, BGP_INFO_VALID);
  3335. new->extra = bgp_info_extra_new();
  3336. memcpy (new->extra->tag, bgp_static->tag, 3);
  3337. /* Aggregate address increment. */
  3338. bgp_aggregate_increment (bgp, p, new, afi, safi);
  3339. /* Register new BGP information. */
  3340. bgp_info_add (rn, new);
  3341. /* route_node_get lock */
  3342. bgp_unlock_node (rn);
  3343. /* Process change. */
  3344. bgp_process (bgp, rn, afi, safi);
  3345. /* Unintern original. */
  3346. aspath_unintern (&attr.aspath);
  3347. bgp_attr_extra_free (&attr);
  3348. }
  3349. /* Configure static BGP network. When user don't run zebra, static
  3350. route should be installed as valid. */
  3351. static int
  3352. bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
  3353. afi_t afi, safi_t safi, const char *rmap, int backdoor)
  3354. {
  3355. int ret;
  3356. struct prefix p;
  3357. struct bgp_static *bgp_static;
  3358. struct bgp_node *rn;
  3359. u_char need_update = 0;
  3360. /* Convert IP prefix string to struct prefix. */
  3361. ret = str2prefix (ip_str, &p);
  3362. if (! ret)
  3363. {
  3364. vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
  3365. return CMD_WARNING;
  3366. }
  3367. if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
  3368. {
  3369. vty_out (vty, "%% Malformed prefix (link-local address)%s",
  3370. VTY_NEWLINE);
  3371. return CMD_WARNING;
  3372. }
  3373. apply_mask (&p);
  3374. /* Set BGP static route configuration. */
  3375. rn = bgp_node_get (bgp->route[afi][safi], &p);
  3376. if (rn->info)
  3377. {
  3378. /* Configuration change. */
  3379. bgp_static = rn->info;
  3380. /* Check previous routes are installed into BGP. */
  3381. if (bgp_static->valid && bgp_static->backdoor != backdoor)
  3382. need_update = 1;
  3383. bgp_static->backdoor = backdoor;
  3384. if (rmap)
  3385. {
  3386. if (bgp_static->rmap.name)
  3387. free (bgp_static->rmap.name);
  3388. bgp_static->rmap.name = strdup (rmap);
  3389. bgp_static->rmap.map = route_map_lookup_by_name (rmap);
  3390. }
  3391. else
  3392. {
  3393. if (bgp_static->rmap.name)
  3394. free (bgp_static->rmap.name);
  3395. bgp_static->rmap.name = NULL;
  3396. bgp_static->rmap.map = NULL;
  3397. bgp_static->valid = 0;
  3398. }
  3399. bgp_unlock_node (rn);
  3400. }
  3401. else
  3402. {
  3403. /* New configuration. */
  3404. bgp_static = bgp_static_new ();
  3405. bgp_static->backdoor = backdoor;
  3406. bgp_static->valid = 0;
  3407. bgp_static->igpmetric = 0;
  3408. bgp_static->igpnexthop.s_addr = 0;
  3409. if (rmap)
  3410. {
  3411. if (bgp_static->rmap.name)
  3412. free (bgp_static->rmap.name);
  3413. bgp_static->rmap.name = strdup (rmap);
  3414. bgp_static->rmap.map = route_map_lookup_by_name (rmap);
  3415. }
  3416. rn->info = bgp_static;
  3417. }
  3418. bgp_static->valid = 1;
  3419. if (need_update)
  3420. bgp_static_withdraw (bgp, &p, afi, safi);
  3421. if (! bgp_static->backdoor)
  3422. bgp_static_update (bgp, &p, bgp_static, afi, safi);
  3423. return CMD_SUCCESS;
  3424. }
  3425. /* Configure static BGP network. */
  3426. static int
  3427. bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
  3428. afi_t afi, safi_t safi)
  3429. {
  3430. int ret;
  3431. struct prefix p;
  3432. struct bgp_static *bgp_static;
  3433. struct bgp_node *rn;
  3434. /* Convert IP prefix string to struct prefix. */
  3435. ret = str2prefix (ip_str, &p);
  3436. if (! ret)
  3437. {
  3438. vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
  3439. return CMD_WARNING;
  3440. }
  3441. if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
  3442. {
  3443. vty_out (vty, "%% Malformed prefix (link-local address)%s",
  3444. VTY_NEWLINE);
  3445. return CMD_WARNING;
  3446. }
  3447. apply_mask (&p);
  3448. rn = bgp_node_lookup (bgp->route[afi][safi], &p);
  3449. if (! rn)
  3450. {
  3451. vty_out (vty, "%% Can't find specified static route configuration.%s",
  3452. VTY_NEWLINE);
  3453. return CMD_WARNING;
  3454. }
  3455. bgp_static = rn->info;
  3456. /* Update BGP RIB. */
  3457. if (! bgp_static->backdoor)
  3458. bgp_static_withdraw (bgp, &p, afi, safi);
  3459. /* Clear configuration. */
  3460. bgp_static_free (bgp_static);
  3461. rn->info = NULL;
  3462. bgp_unlock_node (rn);
  3463. bgp_unlock_node (rn);
  3464. return CMD_SUCCESS;
  3465. }
  3466. /* Called from bgp_delete(). Delete all static routes from the BGP
  3467. instance. */
  3468. void
  3469. bgp_static_delete (struct bgp *bgp)
  3470. {
  3471. afi_t afi;
  3472. safi_t safi;
  3473. struct bgp_node *rn;
  3474. struct bgp_node *rm;
  3475. struct bgp_table *table;
  3476. struct bgp_static *bgp_static;
  3477. for (afi = AFI_IP; afi < AFI_MAX; afi++)
  3478. for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
  3479. for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
  3480. if (rn->info != NULL)
  3481. {
  3482. if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
  3483. {
  3484. table = rn->info;
  3485. for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
  3486. {
  3487. bgp_static = rn->info;
  3488. bgp_static_withdraw_safi (bgp, &rm->p,
  3489. AFI_IP, safi,
  3490. (struct prefix_rd *)&rn->p,
  3491. bgp_static->tag);
  3492. bgp_static_free (bgp_static);
  3493. rn->info = NULL;
  3494. bgp_unlock_node (rn);
  3495. }
  3496. }
  3497. else
  3498. {
  3499. bgp_static = rn->info;
  3500. bgp_static_withdraw (bgp, &rn->p, afi, safi);
  3501. bgp_static_free (bgp_static);
  3502. rn->info = NULL;
  3503. bgp_unlock_node (rn);
  3504. }
  3505. }
  3506. }
  3507. /*
  3508. * gpz 110624
  3509. * Currently this is used to set static routes for VPN and ENCAP.
  3510. * I think it can probably be factored with bgp_static_set.
  3511. */
  3512. int
  3513. bgp_static_set_safi (safi_t safi, struct vty *vty, const char *ip_str,
  3514. const char *rd_str, const char *tag_str,
  3515. const char *rmap_str)
  3516. {
  3517. int ret;
  3518. struct prefix p;
  3519. struct prefix_rd prd;
  3520. struct bgp *bgp;
  3521. struct bgp_node *prn;
  3522. struct bgp_node *rn;
  3523. struct bgp_table *table;
  3524. struct bgp_static *bgp_static;
  3525. u_char tag[3];
  3526. bgp = vty->index;
  3527. ret = str2prefix (ip_str, &p);
  3528. if (! ret)
  3529. {
  3530. vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
  3531. return CMD_WARNING;
  3532. }
  3533. apply_mask (&p);
  3534. ret = str2prefix_rd (rd_str, &prd);
  3535. if (! ret)
  3536. {
  3537. vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
  3538. return CMD_WARNING;
  3539. }
  3540. ret = str2tag (tag_str, tag);
  3541. if (! ret)
  3542. {
  3543. vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
  3544. return CMD_WARNING;
  3545. }
  3546. prn = bgp_node_get (bgp->route[AFI_IP][safi],
  3547. (struct prefix *)&prd);
  3548. if (prn->info == NULL)
  3549. prn->info = bgp_table_init (AFI_IP, safi);
  3550. else
  3551. bgp_unlock_node (prn);
  3552. table = prn->info;
  3553. rn = bgp_node_get (table, &p);
  3554. if (rn->info)
  3555. {
  3556. vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
  3557. bgp_unlock_node (rn);
  3558. }
  3559. else
  3560. {
  3561. /* New configuration. */
  3562. bgp_static = bgp_static_new ();
  3563. bgp_static->backdoor = 0;
  3564. bgp_static->valid = 0;
  3565. bgp_static->igpmetric = 0;
  3566. bgp_static->igpnexthop.s_addr = 0;
  3567. memcpy(bgp_static->tag, tag, 3);
  3568. bgp_static->prd = prd;
  3569. if (rmap_str)
  3570. {
  3571. if (bgp_static->rmap.name)
  3572. free (bgp_static->rmap.name);
  3573. bgp_static->rmap.name = strdup (rmap_str);
  3574. bgp_static->rmap.map = route_map_lookup_by_name (rmap_str);
  3575. }
  3576. rn->info = bgp_static;
  3577. bgp_static->valid = 1;
  3578. bgp_static_update_safi (bgp, &p, bgp_static, AFI_IP, safi);
  3579. }
  3580. return CMD_SUCCESS;
  3581. }
  3582. /* Configure static BGP network. */
  3583. int
  3584. bgp_static_unset_safi(safi_t safi, struct vty *vty, const char *ip_str,
  3585. const char *rd_str, const char *tag_str)
  3586. {
  3587. int ret;
  3588. struct bgp *bgp;
  3589. struct prefix p;
  3590. struct prefix_rd prd;
  3591. struct bgp_node *prn;
  3592. struct bgp_node *rn;
  3593. struct bgp_table *table;
  3594. struct bgp_static *bgp_static;
  3595. u_char tag[3];
  3596. bgp = vty->index;
  3597. /* Convert IP prefix string to struct prefix. */
  3598. ret = str2prefix (ip_str, &p);
  3599. if (! ret)
  3600. {
  3601. vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
  3602. return CMD_WARNING;
  3603. }
  3604. apply_mask (&p);
  3605. ret = str2prefix_rd (rd_str, &prd);
  3606. if (! ret)
  3607. {
  3608. vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
  3609. return CMD_WARNING;
  3610. }
  3611. ret = str2tag (tag_str, tag);
  3612. if (! ret)
  3613. {
  3614. vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
  3615. return CMD_WARNING;
  3616. }
  3617. prn = bgp_node_get (bgp->route[AFI_IP][safi],
  3618. (struct prefix *)&prd);
  3619. if (prn->info == NULL)
  3620. prn->info = bgp_table_init (AFI_IP, safi);
  3621. else
  3622. bgp_unlock_node (prn);
  3623. table = prn->info;
  3624. rn = bgp_node_lookup (table, &p);
  3625. if (rn)
  3626. {
  3627. bgp_static_withdraw_safi (bgp, &p, AFI_IP, safi, &prd, tag);
  3628. bgp_static = rn->info;
  3629. bgp_static_free (bgp_static);
  3630. rn->info = NULL;
  3631. bgp_unlock_node (rn);
  3632. bgp_unlock_node (rn);
  3633. }
  3634. else
  3635. vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
  3636. return CMD_SUCCESS;
  3637. }
  3638. DEFUN (bgp_network,
  3639. bgp_network_cmd,
  3640. "network A.B.C.D/M",
  3641. "Specify a network to announce via BGP\n"
  3642. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
  3643. {
  3644. return bgp_static_set (vty, vty->index, argv[0],
  3645. AFI_IP, bgp_node_safi (vty), NULL, 0);
  3646. }
  3647. DEFUN (bgp_network_route_map,
  3648. bgp_network_route_map_cmd,
  3649. "network A.B.C.D/M route-map WORD",
  3650. "Specify a network to announce via BGP\n"
  3651. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  3652. "Route-map to modify the attributes\n"
  3653. "Name of the route map\n")
  3654. {
  3655. return bgp_static_set (vty, vty->index, argv[0],
  3656. AFI_IP, bgp_node_safi (vty), argv[1], 0);
  3657. }
  3658. DEFUN (bgp_network_backdoor,
  3659. bgp_network_backdoor_cmd,
  3660. "network A.B.C.D/M backdoor",
  3661. "Specify a network to announce via BGP\n"
  3662. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  3663. "Specify a BGP backdoor route\n")
  3664. {
  3665. return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
  3666. NULL, 1);
  3667. }
  3668. DEFUN (bgp_network_mask,
  3669. bgp_network_mask_cmd,
  3670. "network A.B.C.D mask A.B.C.D",
  3671. "Specify a network to announce via BGP\n"
  3672. "Network number\n"
  3673. "Network mask\n"
  3674. "Network mask\n")
  3675. {
  3676. int ret;
  3677. char prefix_str[BUFSIZ];
  3678. ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
  3679. if (! ret)
  3680. {
  3681. vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
  3682. return CMD_WARNING;
  3683. }
  3684. return bgp_static_set (vty, vty->index, prefix_str,
  3685. AFI_IP, bgp_node_safi (vty), NULL, 0);
  3686. }
  3687. DEFUN (bgp_network_mask_route_map,
  3688. bgp_network_mask_route_map_cmd,
  3689. "network A.B.C.D mask A.B.C.D route-map WORD",
  3690. "Specify a network to announce via BGP\n"
  3691. "Network number\n"
  3692. "Network mask\n"
  3693. "Network mask\n"
  3694. "Route-map to modify the attributes\n"
  3695. "Name of the route map\n")
  3696. {
  3697. int ret;
  3698. char prefix_str[BUFSIZ];
  3699. ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
  3700. if (! ret)
  3701. {
  3702. vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
  3703. return CMD_WARNING;
  3704. }
  3705. return bgp_static_set (vty, vty->index, prefix_str,
  3706. AFI_IP, bgp_node_safi (vty), argv[2], 0);
  3707. }
  3708. DEFUN (bgp_network_mask_backdoor,
  3709. bgp_network_mask_backdoor_cmd,
  3710. "network A.B.C.D mask A.B.C.D backdoor",
  3711. "Specify a network to announce via BGP\n"
  3712. "Network number\n"
  3713. "Network mask\n"
  3714. "Network mask\n"
  3715. "Specify a BGP backdoor route\n")
  3716. {
  3717. int ret;
  3718. char prefix_str[BUFSIZ];
  3719. ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
  3720. if (! ret)
  3721. {
  3722. vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
  3723. return CMD_WARNING;
  3724. }
  3725. return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
  3726. NULL, 1);
  3727. }
  3728. DEFUN (bgp_network_mask_natural,
  3729. bgp_network_mask_natural_cmd,
  3730. "network A.B.C.D",
  3731. "Specify a network to announce via BGP\n"
  3732. "Network number\n")
  3733. {
  3734. int ret;
  3735. char prefix_str[BUFSIZ];
  3736. ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
  3737. if (! ret)
  3738. {
  3739. vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
  3740. return CMD_WARNING;
  3741. }
  3742. return bgp_static_set (vty, vty->index, prefix_str,
  3743. AFI_IP, bgp_node_safi (vty), NULL, 0);
  3744. }
  3745. DEFUN (bgp_network_mask_natural_route_map,
  3746. bgp_network_mask_natural_route_map_cmd,
  3747. "network A.B.C.D route-map WORD",
  3748. "Specify a network to announce via BGP\n"
  3749. "Network number\n"
  3750. "Route-map to modify the attributes\n"
  3751. "Name of the route map\n")
  3752. {
  3753. int ret;
  3754. char prefix_str[BUFSIZ];
  3755. ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
  3756. if (! ret)
  3757. {
  3758. vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
  3759. return CMD_WARNING;
  3760. }
  3761. return bgp_static_set (vty, vty->index, prefix_str,
  3762. AFI_IP, bgp_node_safi (vty), argv[1], 0);
  3763. }
  3764. DEFUN (bgp_network_mask_natural_backdoor,
  3765. bgp_network_mask_natural_backdoor_cmd,
  3766. "network A.B.C.D backdoor",
  3767. "Specify a network to announce via BGP\n"
  3768. "Network number\n"
  3769. "Specify a BGP backdoor route\n")
  3770. {
  3771. int ret;
  3772. char prefix_str[BUFSIZ];
  3773. ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
  3774. if (! ret)
  3775. {
  3776. vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
  3777. return CMD_WARNING;
  3778. }
  3779. return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
  3780. NULL, 1);
  3781. }
  3782. DEFUN (no_bgp_network,
  3783. no_bgp_network_cmd,
  3784. "no network A.B.C.D/M",
  3785. NO_STR
  3786. "Specify a network to announce via BGP\n"
  3787. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
  3788. {
  3789. return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
  3790. bgp_node_safi (vty));
  3791. }
  3792. ALIAS (no_bgp_network,
  3793. no_bgp_network_route_map_cmd,
  3794. "no network A.B.C.D/M route-map WORD",
  3795. NO_STR
  3796. "Specify a network to announce via BGP\n"
  3797. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  3798. "Route-map to modify the attributes\n"
  3799. "Name of the route map\n")
  3800. ALIAS (no_bgp_network,
  3801. no_bgp_network_backdoor_cmd,
  3802. "no network A.B.C.D/M backdoor",
  3803. NO_STR
  3804. "Specify a network to announce via BGP\n"
  3805. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  3806. "Specify a BGP backdoor route\n")
  3807. DEFUN (no_bgp_network_mask,
  3808. no_bgp_network_mask_cmd,
  3809. "no network A.B.C.D mask A.B.C.D",
  3810. NO_STR
  3811. "Specify a network to announce via BGP\n"
  3812. "Network number\n"
  3813. "Network mask\n"
  3814. "Network mask\n")
  3815. {
  3816. int ret;
  3817. char prefix_str[BUFSIZ];
  3818. ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
  3819. if (! ret)
  3820. {
  3821. vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
  3822. return CMD_WARNING;
  3823. }
  3824. return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
  3825. bgp_node_safi (vty));
  3826. }
  3827. ALIAS (no_bgp_network_mask,
  3828. no_bgp_network_mask_route_map_cmd,
  3829. "no network A.B.C.D mask A.B.C.D route-map WORD",
  3830. NO_STR
  3831. "Specify a network to announce via BGP\n"
  3832. "Network number\n"
  3833. "Network mask\n"
  3834. "Network mask\n"
  3835. "Route-map to modify the attributes\n"
  3836. "Name of the route map\n")
  3837. ALIAS (no_bgp_network_mask,
  3838. no_bgp_network_mask_backdoor_cmd,
  3839. "no network A.B.C.D mask A.B.C.D backdoor",
  3840. NO_STR
  3841. "Specify a network to announce via BGP\n"
  3842. "Network number\n"
  3843. "Network mask\n"
  3844. "Network mask\n"
  3845. "Specify a BGP backdoor route\n")
  3846. DEFUN (no_bgp_network_mask_natural,
  3847. no_bgp_network_mask_natural_cmd,
  3848. "no network A.B.C.D",
  3849. NO_STR
  3850. "Specify a network to announce via BGP\n"
  3851. "Network number\n")
  3852. {
  3853. int ret;
  3854. char prefix_str[BUFSIZ];
  3855. ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
  3856. if (! ret)
  3857. {
  3858. vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
  3859. return CMD_WARNING;
  3860. }
  3861. return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
  3862. bgp_node_safi (vty));
  3863. }
  3864. ALIAS (no_bgp_network_mask_natural,
  3865. no_bgp_network_mask_natural_route_map_cmd,
  3866. "no network A.B.C.D route-map WORD",
  3867. NO_STR
  3868. "Specify a network to announce via BGP\n"
  3869. "Network number\n"
  3870. "Route-map to modify the attributes\n"
  3871. "Name of the route map\n")
  3872. ALIAS (no_bgp_network_mask_natural,
  3873. no_bgp_network_mask_natural_backdoor_cmd,
  3874. "no network A.B.C.D backdoor",
  3875. NO_STR
  3876. "Specify a network to announce via BGP\n"
  3877. "Network number\n"
  3878. "Specify a BGP backdoor route\n")
  3879. DEFUN (ipv6_bgp_network,
  3880. ipv6_bgp_network_cmd,
  3881. "network X:X::X:X/M",
  3882. "Specify a network to announce via BGP\n"
  3883. "IPv6 prefix <network>/<length>\n")
  3884. {
  3885. return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
  3886. NULL, 0);
  3887. }
  3888. DEFUN (ipv6_bgp_network_route_map,
  3889. ipv6_bgp_network_route_map_cmd,
  3890. "network X:X::X:X/M route-map WORD",
  3891. "Specify a network to announce via BGP\n"
  3892. "IPv6 prefix <network>/<length>\n"
  3893. "Route-map to modify the attributes\n"
  3894. "Name of the route map\n")
  3895. {
  3896. return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
  3897. bgp_node_safi (vty), argv[1], 0);
  3898. }
  3899. DEFUN (no_ipv6_bgp_network,
  3900. no_ipv6_bgp_network_cmd,
  3901. "no network X:X::X:X/M",
  3902. NO_STR
  3903. "Specify a network to announce via BGP\n"
  3904. "IPv6 prefix <network>/<length>\n")
  3905. {
  3906. return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
  3907. }
  3908. ALIAS (no_ipv6_bgp_network,
  3909. no_ipv6_bgp_network_route_map_cmd,
  3910. "no network X:X::X:X/M route-map WORD",
  3911. NO_STR
  3912. "Specify a network to announce via BGP\n"
  3913. "IPv6 prefix <network>/<length>\n"
  3914. "Route-map to modify the attributes\n"
  3915. "Name of the route map\n")
  3916. ALIAS (ipv6_bgp_network,
  3917. old_ipv6_bgp_network_cmd,
  3918. "ipv6 bgp network X:X::X:X/M",
  3919. IPV6_STR
  3920. BGP_STR
  3921. "Specify a network to announce via BGP\n"
  3922. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
  3923. ALIAS (no_ipv6_bgp_network,
  3924. old_no_ipv6_bgp_network_cmd,
  3925. "no ipv6 bgp network X:X::X:X/M",
  3926. NO_STR
  3927. IPV6_STR
  3928. BGP_STR
  3929. "Specify a network to announce via BGP\n"
  3930. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
  3931. /* stubs for removed AS-Pathlimit commands, kept for config compatibility */
  3932. ALIAS_DEPRECATED (bgp_network,
  3933. bgp_network_ttl_cmd,
  3934. "network A.B.C.D/M pathlimit <0-255>",
  3935. "Specify a network to announce via BGP\n"
  3936. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  3937. "AS-Path hopcount limit attribute\n"
  3938. "AS-Pathlimit TTL, in number of AS-Path hops\n")
  3939. ALIAS_DEPRECATED (bgp_network_backdoor,
  3940. bgp_network_backdoor_ttl_cmd,
  3941. "network A.B.C.D/M backdoor pathlimit <0-255>",
  3942. "Specify a network to announce via BGP\n"
  3943. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  3944. "Specify a BGP backdoor route\n"
  3945. "AS-Path hopcount limit attribute\n"
  3946. "AS-Pathlimit TTL, in number of AS-Path hops\n")
  3947. ALIAS_DEPRECATED (bgp_network_mask,
  3948. bgp_network_mask_ttl_cmd,
  3949. "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
  3950. "Specify a network to announce via BGP\n"
  3951. "Network number\n"
  3952. "Network mask\n"
  3953. "Network mask\n"
  3954. "AS-Path hopcount limit attribute\n"
  3955. "AS-Pathlimit TTL, in number of AS-Path hops\n")
  3956. ALIAS_DEPRECATED (bgp_network_mask_backdoor,
  3957. bgp_network_mask_backdoor_ttl_cmd,
  3958. "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
  3959. "Specify a network to announce via BGP\n"
  3960. "Network number\n"
  3961. "Network mask\n"
  3962. "Network mask\n"
  3963. "Specify a BGP backdoor route\n"
  3964. "AS-Path hopcount limit attribute\n"
  3965. "AS-Pathlimit TTL, in number of AS-Path hops\n")
  3966. ALIAS_DEPRECATED (bgp_network_mask_natural,
  3967. bgp_network_mask_natural_ttl_cmd,
  3968. "network A.B.C.D pathlimit <0-255>",
  3969. "Specify a network to announce via BGP\n"
  3970. "Network number\n"
  3971. "AS-Path hopcount limit attribute\n"
  3972. "AS-Pathlimit TTL, in number of AS-Path hops\n")
  3973. ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
  3974. bgp_network_mask_natural_backdoor_ttl_cmd,
  3975. "network A.B.C.D backdoor pathlimit <1-255>",
  3976. "Specify a network to announce via BGP\n"
  3977. "Network number\n"
  3978. "Specify a BGP backdoor route\n"
  3979. "AS-Path hopcount limit attribute\n"
  3980. "AS-Pathlimit TTL, in number of AS-Path hops\n")
  3981. ALIAS_DEPRECATED (no_bgp_network,
  3982. no_bgp_network_ttl_cmd,
  3983. "no network A.B.C.D/M pathlimit <0-255>",
  3984. NO_STR
  3985. "Specify a network to announce via BGP\n"
  3986. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  3987. "AS-Path hopcount limit attribute\n"
  3988. "AS-Pathlimit TTL, in number of AS-Path hops\n")
  3989. ALIAS_DEPRECATED (no_bgp_network,
  3990. no_bgp_network_backdoor_ttl_cmd,
  3991. "no network A.B.C.D/M backdoor pathlimit <0-255>",
  3992. NO_STR
  3993. "Specify a network to announce via BGP\n"
  3994. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  3995. "Specify a BGP backdoor route\n"
  3996. "AS-Path hopcount limit attribute\n"
  3997. "AS-Pathlimit TTL, in number of AS-Path hops\n")
  3998. ALIAS_DEPRECATED (no_bgp_network,
  3999. no_bgp_network_mask_ttl_cmd,
  4000. "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
  4001. NO_STR
  4002. "Specify a network to announce via BGP\n"
  4003. "Network number\n"
  4004. "Network mask\n"
  4005. "Network mask\n"
  4006. "AS-Path hopcount limit attribute\n"
  4007. "AS-Pathlimit TTL, in number of AS-Path hops\n")
  4008. ALIAS_DEPRECATED (no_bgp_network_mask,
  4009. no_bgp_network_mask_backdoor_ttl_cmd,
  4010. "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
  4011. NO_STR
  4012. "Specify a network to announce via BGP\n"
  4013. "Network number\n"
  4014. "Network mask\n"
  4015. "Network mask\n"
  4016. "Specify a BGP backdoor route\n"
  4017. "AS-Path hopcount limit attribute\n"
  4018. "AS-Pathlimit TTL, in number of AS-Path hops\n")
  4019. ALIAS_DEPRECATED (no_bgp_network_mask_natural,
  4020. no_bgp_network_mask_natural_ttl_cmd,
  4021. "no network A.B.C.D pathlimit <0-255>",
  4022. NO_STR
  4023. "Specify a network to announce via BGP\n"
  4024. "Network number\n"
  4025. "AS-Path hopcount limit attribute\n"
  4026. "AS-Pathlimit TTL, in number of AS-Path hops\n")
  4027. ALIAS_DEPRECATED (no_bgp_network_mask_natural,
  4028. no_bgp_network_mask_natural_backdoor_ttl_cmd,
  4029. "no network A.B.C.D backdoor pathlimit <0-255>",
  4030. NO_STR
  4031. "Specify a network to announce via BGP\n"
  4032. "Network number\n"
  4033. "Specify a BGP backdoor route\n"
  4034. "AS-Path hopcount limit attribute\n"
  4035. "AS-Pathlimit TTL, in number of AS-Path hops\n")
  4036. ALIAS_DEPRECATED (ipv6_bgp_network,
  4037. ipv6_bgp_network_ttl_cmd,
  4038. "network X:X::X:X/M pathlimit <0-255>",
  4039. "Specify a network to announce via BGP\n"
  4040. "IPv6 prefix <network>/<length>\n"
  4041. "AS-Path hopcount limit attribute\n"
  4042. "AS-Pathlimit TTL, in number of AS-Path hops\n")
  4043. ALIAS_DEPRECATED (no_ipv6_bgp_network,
  4044. no_ipv6_bgp_network_ttl_cmd,
  4045. "no network X:X::X:X/M pathlimit <0-255>",
  4046. NO_STR
  4047. "Specify a network to announce via BGP\n"
  4048. "IPv6 prefix <network>/<length>\n"
  4049. "AS-Path hopcount limit attribute\n"
  4050. "AS-Pathlimit TTL, in number of AS-Path hops\n")
  4051. /* Aggreagete address:
  4052. advertise-map Set condition to advertise attribute
  4053. as-set Generate AS set path information
  4054. attribute-map Set attributes of aggregate
  4055. route-map Set parameters of aggregate
  4056. summary-only Filter more specific routes from updates
  4057. suppress-map Conditionally filter more specific routes from updates
  4058. <cr>
  4059. */
  4060. struct bgp_aggregate
  4061. {
  4062. /* Summary-only flag. */
  4063. u_char summary_only;
  4064. /* AS set generation. */
  4065. u_char as_set;
  4066. /* Route-map for aggregated route. */
  4067. struct route_map *map;
  4068. /* Suppress-count. */
  4069. unsigned long count;
  4070. /* SAFI configuration. */
  4071. safi_t safi;
  4072. };
  4073. static struct bgp_aggregate *
  4074. bgp_aggregate_new (void)
  4075. {
  4076. return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
  4077. }
  4078. static void
  4079. bgp_aggregate_free (struct bgp_aggregate *aggregate)
  4080. {
  4081. XFREE (MTYPE_BGP_AGGREGATE, aggregate);
  4082. }
  4083. /* Update an aggregate as routes are added/removed from the BGP table */
  4084. static void
  4085. bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
  4086. afi_t afi, safi_t safi, struct bgp_info *del,
  4087. struct bgp_aggregate *aggregate)
  4088. {
  4089. struct bgp_table *table;
  4090. struct bgp_node *top;
  4091. struct bgp_node *rn;
  4092. u_char origin;
  4093. struct aspath *aspath = NULL;
  4094. struct aspath *asmerge = NULL;
  4095. struct community *community = NULL;
  4096. struct community *commerge = NULL;
  4097. struct bgp_info *ri;
  4098. struct bgp_info *new;
  4099. int first = 1;
  4100. unsigned long match = 0;
  4101. u_char atomic_aggregate = 0;
  4102. /* ORIGIN attribute: If at least one route among routes that are
  4103. aggregated has ORIGIN with the value INCOMPLETE, then the
  4104. aggregated route must have the ORIGIN attribute with the value
  4105. INCOMPLETE. Otherwise, if at least one route among routes that
  4106. are aggregated has ORIGIN with the value EGP, then the aggregated
  4107. route must have the origin attribute with the value EGP. In all
  4108. other case the value of the ORIGIN attribute of the aggregated
  4109. route is INTERNAL. */
  4110. origin = BGP_ORIGIN_IGP;
  4111. table = bgp->rib[afi][safi];
  4112. top = bgp_node_get (table, p);
  4113. for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
  4114. if (rn->p.prefixlen > p->prefixlen)
  4115. {
  4116. match = 0;
  4117. for (ri = rn->info; ri; ri = ri->next)
  4118. {
  4119. if (BGP_INFO_HOLDDOWN (ri))
  4120. continue;
  4121. if (del && ri == del)
  4122. continue;
  4123. if (! rinew && first)
  4124. first = 0;
  4125. #ifdef AGGREGATE_NEXTHOP_CHECK
  4126. if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
  4127. || ri->attr->med != med)
  4128. {
  4129. if (aspath)
  4130. aspath_free (aspath);
  4131. if (community)
  4132. community_free (community);
  4133. bgp_unlock_node (rn);
  4134. bgp_unlock_node (top);
  4135. return;
  4136. }
  4137. #endif /* AGGREGATE_NEXTHOP_CHECK */
  4138. if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
  4139. atomic_aggregate = 1;
  4140. if (ri->sub_type != BGP_ROUTE_AGGREGATE)
  4141. {
  4142. if (aggregate->summary_only)
  4143. {
  4144. (bgp_info_extra_get (ri))->suppress++;
  4145. bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
  4146. match++;
  4147. }
  4148. aggregate->count++;
  4149. if (origin < ri->attr->origin)
  4150. origin = ri->attr->origin;
  4151. if (aggregate->as_set)
  4152. {
  4153. if (aspath)
  4154. {
  4155. asmerge = aspath_aggregate (aspath, ri->attr->aspath);
  4156. aspath_free (aspath);
  4157. aspath = asmerge;
  4158. }
  4159. else
  4160. aspath = aspath_dup (ri->attr->aspath);
  4161. if (ri->attr->community)
  4162. {
  4163. if (community)
  4164. {
  4165. commerge = community_merge (community,
  4166. ri->attr->community);
  4167. community = community_uniq_sort (commerge);
  4168. community_free (commerge);
  4169. }
  4170. else
  4171. community = community_dup (ri->attr->community);
  4172. }
  4173. }
  4174. }
  4175. }
  4176. if (match)
  4177. bgp_process (bgp, rn, afi, safi);
  4178. }
  4179. bgp_unlock_node (top);
  4180. if (rinew)
  4181. {
  4182. aggregate->count++;
  4183. if (aggregate->summary_only)
  4184. (bgp_info_extra_get (rinew))->suppress++;
  4185. if (origin < rinew->attr->origin)
  4186. origin = rinew->attr->origin;
  4187. if (aggregate->as_set)
  4188. {
  4189. if (aspath)
  4190. {
  4191. asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
  4192. aspath_free (aspath);
  4193. aspath = asmerge;
  4194. }
  4195. else
  4196. aspath = aspath_dup (rinew->attr->aspath);
  4197. if (rinew->attr->community)
  4198. {
  4199. if (community)
  4200. {
  4201. commerge = community_merge (community,
  4202. rinew->attr->community);
  4203. community = community_uniq_sort (commerge);
  4204. community_free (commerge);
  4205. }
  4206. else
  4207. community = community_dup (rinew->attr->community);
  4208. }
  4209. }
  4210. }
  4211. if (aggregate->count > 0)
  4212. {
  4213. rn = bgp_node_get (table, p);
  4214. new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, bgp->peer_self,
  4215. bgp_attr_aggregate_intern(bgp, origin, aspath, community,
  4216. aggregate->as_set,
  4217. atomic_aggregate), rn);
  4218. SET_FLAG (new->flags, BGP_INFO_VALID);
  4219. bgp_info_add (rn, new);
  4220. bgp_unlock_node (rn);
  4221. bgp_process (bgp, rn, afi, safi);
  4222. }
  4223. else
  4224. {
  4225. if (aspath)
  4226. aspath_free (aspath);
  4227. if (community)
  4228. community_free (community);
  4229. }
  4230. }
  4231. void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
  4232. struct bgp_aggregate *);
  4233. void
  4234. bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
  4235. struct bgp_info *ri, afi_t afi, safi_t safi)
  4236. {
  4237. struct bgp_node *child;
  4238. struct bgp_node *rn;
  4239. struct bgp_aggregate *aggregate;
  4240. struct bgp_table *table;
  4241. /* MPLS-VPN aggregation is not yet supported. */
  4242. if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
  4243. return;
  4244. table = bgp->aggregate[afi][safi];
  4245. /* No aggregates configured. */
  4246. if (bgp_table_top_nolock (table) == NULL)
  4247. return;
  4248. if (p->prefixlen == 0)
  4249. return;
  4250. if (BGP_INFO_HOLDDOWN (ri))
  4251. return;
  4252. child = bgp_node_get (table, p);
  4253. /* Aggregate address configuration check. */
  4254. for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
  4255. if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
  4256. {
  4257. bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
  4258. bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
  4259. }
  4260. bgp_unlock_node (child);
  4261. }
  4262. void
  4263. bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
  4264. struct bgp_info *del, afi_t afi, safi_t safi)
  4265. {
  4266. struct bgp_node *child;
  4267. struct bgp_node *rn;
  4268. struct bgp_aggregate *aggregate;
  4269. struct bgp_table *table;
  4270. /* MPLS-VPN aggregation is not yet supported. */
  4271. if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
  4272. return;
  4273. table = bgp->aggregate[afi][safi];
  4274. /* No aggregates configured. */
  4275. if (bgp_table_top_nolock (table) == NULL)
  4276. return;
  4277. if (p->prefixlen == 0)
  4278. return;
  4279. child = bgp_node_get (table, p);
  4280. /* Aggregate address configuration check. */
  4281. for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
  4282. if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
  4283. {
  4284. bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
  4285. bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
  4286. }
  4287. bgp_unlock_node (child);
  4288. }
  4289. /* Called via bgp_aggregate_set when the user configures aggregate-address */
  4290. static void
  4291. bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
  4292. struct bgp_aggregate *aggregate)
  4293. {
  4294. struct bgp_table *table;
  4295. struct bgp_node *top;
  4296. struct bgp_node *rn;
  4297. struct bgp_info *new;
  4298. struct bgp_info *ri;
  4299. unsigned long match;
  4300. u_char origin = BGP_ORIGIN_IGP;
  4301. struct aspath *aspath = NULL;
  4302. struct aspath *asmerge = NULL;
  4303. struct community *community = NULL;
  4304. struct community *commerge = NULL;
  4305. u_char atomic_aggregate = 0;
  4306. table = bgp->rib[afi][safi];
  4307. /* Sanity check. */
  4308. if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
  4309. return;
  4310. if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
  4311. return;
  4312. /* If routes exists below this node, generate aggregate routes. */
  4313. top = bgp_node_get (table, p);
  4314. for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
  4315. if (rn->p.prefixlen > p->prefixlen)
  4316. {
  4317. match = 0;
  4318. for (ri = rn->info; ri; ri = ri->next)
  4319. {
  4320. if (BGP_INFO_HOLDDOWN (ri))
  4321. continue;
  4322. if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
  4323. atomic_aggregate = 1;
  4324. if (ri->sub_type != BGP_ROUTE_AGGREGATE)
  4325. {
  4326. /* summary-only aggregate route suppress aggregated
  4327. route announcement. */
  4328. if (aggregate->summary_only)
  4329. {
  4330. (bgp_info_extra_get (ri))->suppress++;
  4331. bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
  4332. match++;
  4333. }
  4334. /* If at least one route among routes that are aggregated has
  4335. * ORIGIN with the value INCOMPLETE, then the aggregated route
  4336. * MUST have the ORIGIN attribute with the value INCOMPLETE.
  4337. * Otherwise, if at least one route among routes that are
  4338. * aggregated has ORIGIN with the value EGP, then the aggregated
  4339. * route MUST have the ORIGIN attribute with the value EGP.
  4340. */
  4341. if (origin < ri->attr->origin)
  4342. origin = ri->attr->origin;
  4343. /* as-set aggregate route generate origin, as path,
  4344. community aggregation. */
  4345. if (aggregate->as_set)
  4346. {
  4347. if (aspath)
  4348. {
  4349. asmerge = aspath_aggregate (aspath, ri->attr->aspath);
  4350. aspath_free (aspath);
  4351. aspath = asmerge;
  4352. }
  4353. else
  4354. aspath = aspath_dup (ri->attr->aspath);
  4355. if (ri->attr->community)
  4356. {
  4357. if (community)
  4358. {
  4359. commerge = community_merge (community,
  4360. ri->attr->community);
  4361. community = community_uniq_sort (commerge);
  4362. community_free (commerge);
  4363. }
  4364. else
  4365. community = community_dup (ri->attr->community);
  4366. }
  4367. }
  4368. aggregate->count++;
  4369. }
  4370. }
  4371. /* If this node is suppressed, process the change. */
  4372. if (match)
  4373. bgp_process (bgp, rn, afi, safi);
  4374. }
  4375. bgp_unlock_node (top);
  4376. /* Add aggregate route to BGP table. */
  4377. if (aggregate->count)
  4378. {
  4379. rn = bgp_node_get (table, p);
  4380. new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, bgp->peer_self,
  4381. bgp_attr_aggregate_intern(bgp, origin, aspath, community,
  4382. aggregate->as_set,
  4383. atomic_aggregate), rn);
  4384. SET_FLAG (new->flags, BGP_INFO_VALID);
  4385. bgp_info_add (rn, new);
  4386. bgp_unlock_node (rn);
  4387. /* Process change. */
  4388. bgp_process (bgp, rn, afi, safi);
  4389. }
  4390. else
  4391. {
  4392. if (aspath)
  4393. aspath_free (aspath);
  4394. if (community)
  4395. community_free (community);
  4396. }
  4397. }
  4398. void
  4399. bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
  4400. safi_t safi, struct bgp_aggregate *aggregate)
  4401. {
  4402. struct bgp_table *table;
  4403. struct bgp_node *top;
  4404. struct bgp_node *rn;
  4405. struct bgp_info *ri;
  4406. unsigned long match;
  4407. table = bgp->rib[afi][safi];
  4408. if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
  4409. return;
  4410. if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
  4411. return;
  4412. /* If routes exists below this node, generate aggregate routes. */
  4413. top = bgp_node_get (table, p);
  4414. for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
  4415. if (rn->p.prefixlen > p->prefixlen)
  4416. {
  4417. match = 0;
  4418. for (ri = rn->info; ri; ri = ri->next)
  4419. {
  4420. if (BGP_INFO_HOLDDOWN (ri))
  4421. continue;
  4422. if (ri->sub_type != BGP_ROUTE_AGGREGATE)
  4423. {
  4424. if (aggregate->summary_only && ri->extra)
  4425. {
  4426. ri->extra->suppress--;
  4427. if (ri->extra->suppress == 0)
  4428. {
  4429. bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
  4430. match++;
  4431. }
  4432. }
  4433. aggregate->count--;
  4434. }
  4435. }
  4436. /* If this node was suppressed, process the change. */
  4437. if (match)
  4438. bgp_process (bgp, rn, afi, safi);
  4439. }
  4440. bgp_unlock_node (top);
  4441. /* Delete aggregate route from BGP table. */
  4442. rn = bgp_node_get (table, p);
  4443. for (ri = rn->info; ri; ri = ri->next)
  4444. if (ri->peer == bgp->peer_self
  4445. && ri->type == ZEBRA_ROUTE_BGP
  4446. && ri->sub_type == BGP_ROUTE_AGGREGATE)
  4447. break;
  4448. /* Withdraw static BGP route from routing table. */
  4449. if (ri)
  4450. {
  4451. bgp_info_delete (rn, ri);
  4452. bgp_process (bgp, rn, afi, safi);
  4453. }
  4454. /* Unlock bgp_node_lookup. */
  4455. bgp_unlock_node (rn);
  4456. }
  4457. /* Aggregate route attribute. */
  4458. #define AGGREGATE_SUMMARY_ONLY 1
  4459. #define AGGREGATE_AS_SET 1
  4460. static int
  4461. bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
  4462. afi_t afi, safi_t safi)
  4463. {
  4464. int ret;
  4465. struct prefix p;
  4466. struct bgp_node *rn;
  4467. struct bgp *bgp;
  4468. struct bgp_aggregate *aggregate;
  4469. /* Convert string to prefix structure. */
  4470. ret = str2prefix (prefix_str, &p);
  4471. if (!ret)
  4472. {
  4473. vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
  4474. return CMD_WARNING;
  4475. }
  4476. apply_mask (&p);
  4477. /* Get BGP structure. */
  4478. bgp = vty->index;
  4479. /* Old configuration check. */
  4480. rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
  4481. if (! rn)
  4482. {
  4483. vty_out (vty, "%% There is no aggregate-address configuration.%s",
  4484. VTY_NEWLINE);
  4485. return CMD_WARNING;
  4486. }
  4487. aggregate = rn->info;
  4488. if (aggregate->safi & SAFI_UNICAST)
  4489. bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
  4490. if (aggregate->safi & SAFI_MULTICAST)
  4491. bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
  4492. /* Unlock aggregate address configuration. */
  4493. rn->info = NULL;
  4494. bgp_aggregate_free (aggregate);
  4495. bgp_unlock_node (rn);
  4496. bgp_unlock_node (rn);
  4497. return CMD_SUCCESS;
  4498. }
  4499. static int
  4500. bgp_aggregate_set (struct vty *vty, const char *prefix_str,
  4501. afi_t afi, safi_t safi,
  4502. u_char summary_only, u_char as_set)
  4503. {
  4504. int ret;
  4505. struct prefix p;
  4506. struct bgp_node *rn;
  4507. struct bgp *bgp;
  4508. struct bgp_aggregate *aggregate;
  4509. /* Convert string to prefix structure. */
  4510. ret = str2prefix (prefix_str, &p);
  4511. if (!ret)
  4512. {
  4513. vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
  4514. return CMD_WARNING;
  4515. }
  4516. apply_mask (&p);
  4517. /* Get BGP structure. */
  4518. bgp = vty->index;
  4519. /* Old configuration check. */
  4520. rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
  4521. if (rn->info)
  4522. {
  4523. vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
  4524. /* try to remove the old entry */
  4525. ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
  4526. if (ret)
  4527. {
  4528. vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
  4529. bgp_unlock_node (rn);
  4530. return CMD_WARNING;
  4531. }
  4532. }
  4533. /* Make aggregate address structure. */
  4534. aggregate = bgp_aggregate_new ();
  4535. aggregate->summary_only = summary_only;
  4536. aggregate->as_set = as_set;
  4537. aggregate->safi = safi;
  4538. rn->info = aggregate;
  4539. /* Aggregate address insert into BGP routing table. */
  4540. if (safi & SAFI_UNICAST)
  4541. bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
  4542. if (safi & SAFI_MULTICAST)
  4543. bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
  4544. return CMD_SUCCESS;
  4545. }
  4546. DEFUN (aggregate_address,
  4547. aggregate_address_cmd,
  4548. "aggregate-address A.B.C.D/M",
  4549. "Configure BGP aggregate entries\n"
  4550. "Aggregate prefix\n")
  4551. {
  4552. return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
  4553. }
  4554. DEFUN (aggregate_address_mask,
  4555. aggregate_address_mask_cmd,
  4556. "aggregate-address A.B.C.D A.B.C.D",
  4557. "Configure BGP aggregate entries\n"
  4558. "Aggregate address\n"
  4559. "Aggregate mask\n")
  4560. {
  4561. int ret;
  4562. char prefix_str[BUFSIZ];
  4563. ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
  4564. if (! ret)
  4565. {
  4566. vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
  4567. return CMD_WARNING;
  4568. }
  4569. return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
  4570. 0, 0);
  4571. }
  4572. DEFUN (aggregate_address_summary_only,
  4573. aggregate_address_summary_only_cmd,
  4574. "aggregate-address A.B.C.D/M summary-only",
  4575. "Configure BGP aggregate entries\n"
  4576. "Aggregate prefix\n"
  4577. "Filter more specific routes from updates\n")
  4578. {
  4579. return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
  4580. AGGREGATE_SUMMARY_ONLY, 0);
  4581. }
  4582. DEFUN (aggregate_address_mask_summary_only,
  4583. aggregate_address_mask_summary_only_cmd,
  4584. "aggregate-address A.B.C.D A.B.C.D summary-only",
  4585. "Configure BGP aggregate entries\n"
  4586. "Aggregate address\n"
  4587. "Aggregate mask\n"
  4588. "Filter more specific routes from updates\n")
  4589. {
  4590. int ret;
  4591. char prefix_str[BUFSIZ];
  4592. ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
  4593. if (! ret)
  4594. {
  4595. vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
  4596. return CMD_WARNING;
  4597. }
  4598. return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
  4599. AGGREGATE_SUMMARY_ONLY, 0);
  4600. }
  4601. DEFUN (aggregate_address_as_set,
  4602. aggregate_address_as_set_cmd,
  4603. "aggregate-address A.B.C.D/M as-set",
  4604. "Configure BGP aggregate entries\n"
  4605. "Aggregate prefix\n"
  4606. "Generate AS set path information\n")
  4607. {
  4608. return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
  4609. 0, AGGREGATE_AS_SET);
  4610. }
  4611. DEFUN (aggregate_address_mask_as_set,
  4612. aggregate_address_mask_as_set_cmd,
  4613. "aggregate-address A.B.C.D A.B.C.D as-set",
  4614. "Configure BGP aggregate entries\n"
  4615. "Aggregate address\n"
  4616. "Aggregate mask\n"
  4617. "Generate AS set path information\n")
  4618. {
  4619. int ret;
  4620. char prefix_str[BUFSIZ];
  4621. ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
  4622. if (! ret)
  4623. {
  4624. vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
  4625. return CMD_WARNING;
  4626. }
  4627. return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
  4628. 0, AGGREGATE_AS_SET);
  4629. }
  4630. DEFUN (aggregate_address_as_set_summary,
  4631. aggregate_address_as_set_summary_cmd,
  4632. "aggregate-address A.B.C.D/M as-set summary-only",
  4633. "Configure BGP aggregate entries\n"
  4634. "Aggregate prefix\n"
  4635. "Generate AS set path information\n"
  4636. "Filter more specific routes from updates\n")
  4637. {
  4638. return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
  4639. AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
  4640. }
  4641. ALIAS (aggregate_address_as_set_summary,
  4642. aggregate_address_summary_as_set_cmd,
  4643. "aggregate-address A.B.C.D/M summary-only as-set",
  4644. "Configure BGP aggregate entries\n"
  4645. "Aggregate prefix\n"
  4646. "Filter more specific routes from updates\n"
  4647. "Generate AS set path information\n")
  4648. DEFUN (aggregate_address_mask_as_set_summary,
  4649. aggregate_address_mask_as_set_summary_cmd,
  4650. "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
  4651. "Configure BGP aggregate entries\n"
  4652. "Aggregate address\n"
  4653. "Aggregate mask\n"
  4654. "Generate AS set path information\n"
  4655. "Filter more specific routes from updates\n")
  4656. {
  4657. int ret;
  4658. char prefix_str[BUFSIZ];
  4659. ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
  4660. if (! ret)
  4661. {
  4662. vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
  4663. return CMD_WARNING;
  4664. }
  4665. return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
  4666. AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
  4667. }
  4668. ALIAS (aggregate_address_mask_as_set_summary,
  4669. aggregate_address_mask_summary_as_set_cmd,
  4670. "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
  4671. "Configure BGP aggregate entries\n"
  4672. "Aggregate address\n"
  4673. "Aggregate mask\n"
  4674. "Filter more specific routes from updates\n"
  4675. "Generate AS set path information\n")
  4676. DEFUN (no_aggregate_address,
  4677. no_aggregate_address_cmd,
  4678. "no aggregate-address A.B.C.D/M",
  4679. NO_STR
  4680. "Configure BGP aggregate entries\n"
  4681. "Aggregate prefix\n")
  4682. {
  4683. return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
  4684. }
  4685. ALIAS (no_aggregate_address,
  4686. no_aggregate_address_summary_only_cmd,
  4687. "no aggregate-address A.B.C.D/M summary-only",
  4688. NO_STR
  4689. "Configure BGP aggregate entries\n"
  4690. "Aggregate prefix\n"
  4691. "Filter more specific routes from updates\n")
  4692. ALIAS (no_aggregate_address,
  4693. no_aggregate_address_as_set_cmd,
  4694. "no aggregate-address A.B.C.D/M as-set",
  4695. NO_STR
  4696. "Configure BGP aggregate entries\n"
  4697. "Aggregate prefix\n"
  4698. "Generate AS set path information\n")
  4699. ALIAS (no_aggregate_address,
  4700. no_aggregate_address_as_set_summary_cmd,
  4701. "no aggregate-address A.B.C.D/M as-set summary-only",
  4702. NO_STR
  4703. "Configure BGP aggregate entries\n"
  4704. "Aggregate prefix\n"
  4705. "Generate AS set path information\n"
  4706. "Filter more specific routes from updates\n")
  4707. ALIAS (no_aggregate_address,
  4708. no_aggregate_address_summary_as_set_cmd,
  4709. "no aggregate-address A.B.C.D/M summary-only as-set",
  4710. NO_STR
  4711. "Configure BGP aggregate entries\n"
  4712. "Aggregate prefix\n"
  4713. "Filter more specific routes from updates\n"
  4714. "Generate AS set path information\n")
  4715. DEFUN (no_aggregate_address_mask,
  4716. no_aggregate_address_mask_cmd,
  4717. "no aggregate-address A.B.C.D A.B.C.D",
  4718. NO_STR
  4719. "Configure BGP aggregate entries\n"
  4720. "Aggregate address\n"
  4721. "Aggregate mask\n")
  4722. {
  4723. int ret;
  4724. char prefix_str[BUFSIZ];
  4725. ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
  4726. if (! ret)
  4727. {
  4728. vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
  4729. return CMD_WARNING;
  4730. }
  4731. return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
  4732. }
  4733. ALIAS (no_aggregate_address_mask,
  4734. no_aggregate_address_mask_summary_only_cmd,
  4735. "no aggregate-address A.B.C.D A.B.C.D summary-only",
  4736. NO_STR
  4737. "Configure BGP aggregate entries\n"
  4738. "Aggregate address\n"
  4739. "Aggregate mask\n"
  4740. "Filter more specific routes from updates\n")
  4741. ALIAS (no_aggregate_address_mask,
  4742. no_aggregate_address_mask_as_set_cmd,
  4743. "no aggregate-address A.B.C.D A.B.C.D as-set",
  4744. NO_STR
  4745. "Configure BGP aggregate entries\n"
  4746. "Aggregate address\n"
  4747. "Aggregate mask\n"
  4748. "Generate AS set path information\n")
  4749. ALIAS (no_aggregate_address_mask,
  4750. no_aggregate_address_mask_as_set_summary_cmd,
  4751. "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
  4752. NO_STR
  4753. "Configure BGP aggregate entries\n"
  4754. "Aggregate address\n"
  4755. "Aggregate mask\n"
  4756. "Generate AS set path information\n"
  4757. "Filter more specific routes from updates\n")
  4758. ALIAS (no_aggregate_address_mask,
  4759. no_aggregate_address_mask_summary_as_set_cmd,
  4760. "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
  4761. NO_STR
  4762. "Configure BGP aggregate entries\n"
  4763. "Aggregate address\n"
  4764. "Aggregate mask\n"
  4765. "Filter more specific routes from updates\n"
  4766. "Generate AS set path information\n")
  4767. DEFUN (ipv6_aggregate_address,
  4768. ipv6_aggregate_address_cmd,
  4769. "aggregate-address X:X::X:X/M",
  4770. "Configure BGP aggregate entries\n"
  4771. "Aggregate prefix\n")
  4772. {
  4773. return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
  4774. }
  4775. DEFUN (ipv6_aggregate_address_summary_only,
  4776. ipv6_aggregate_address_summary_only_cmd,
  4777. "aggregate-address X:X::X:X/M summary-only",
  4778. "Configure BGP aggregate entries\n"
  4779. "Aggregate prefix\n"
  4780. "Filter more specific routes from updates\n")
  4781. {
  4782. return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
  4783. AGGREGATE_SUMMARY_ONLY, 0);
  4784. }
  4785. DEFUN (no_ipv6_aggregate_address,
  4786. no_ipv6_aggregate_address_cmd,
  4787. "no aggregate-address X:X::X:X/M",
  4788. NO_STR
  4789. "Configure BGP aggregate entries\n"
  4790. "Aggregate prefix\n")
  4791. {
  4792. return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
  4793. }
  4794. DEFUN (no_ipv6_aggregate_address_summary_only,
  4795. no_ipv6_aggregate_address_summary_only_cmd,
  4796. "no aggregate-address X:X::X:X/M summary-only",
  4797. NO_STR
  4798. "Configure BGP aggregate entries\n"
  4799. "Aggregate prefix\n"
  4800. "Filter more specific routes from updates\n")
  4801. {
  4802. return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
  4803. }
  4804. ALIAS (ipv6_aggregate_address,
  4805. old_ipv6_aggregate_address_cmd,
  4806. "ipv6 bgp aggregate-address X:X::X:X/M",
  4807. IPV6_STR
  4808. BGP_STR
  4809. "Configure BGP aggregate entries\n"
  4810. "Aggregate prefix\n")
  4811. ALIAS (ipv6_aggregate_address_summary_only,
  4812. old_ipv6_aggregate_address_summary_only_cmd,
  4813. "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
  4814. IPV6_STR
  4815. BGP_STR
  4816. "Configure BGP aggregate entries\n"
  4817. "Aggregate prefix\n"
  4818. "Filter more specific routes from updates\n")
  4819. ALIAS (no_ipv6_aggregate_address,
  4820. old_no_ipv6_aggregate_address_cmd,
  4821. "no ipv6 bgp aggregate-address X:X::X:X/M",
  4822. NO_STR
  4823. IPV6_STR
  4824. BGP_STR
  4825. "Configure BGP aggregate entries\n"
  4826. "Aggregate prefix\n")
  4827. ALIAS (no_ipv6_aggregate_address_summary_only,
  4828. old_no_ipv6_aggregate_address_summary_only_cmd,
  4829. "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
  4830. NO_STR
  4831. IPV6_STR
  4832. BGP_STR
  4833. "Configure BGP aggregate entries\n"
  4834. "Aggregate prefix\n"
  4835. "Filter more specific routes from updates\n")
  4836. /* Redistribute route treatment. */
  4837. void
  4838. bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
  4839. const struct in6_addr *nexthop6,
  4840. u_int32_t metric, u_char type, route_tag_t tag)
  4841. {
  4842. struct bgp *bgp;
  4843. struct listnode *node, *nnode;
  4844. struct bgp_info *new;
  4845. struct bgp_info *bi;
  4846. struct bgp_info info;
  4847. struct bgp_node *bn;
  4848. struct attr attr;
  4849. struct attr *new_attr;
  4850. afi_t afi;
  4851. int ret;
  4852. /* Make default attribute. */
  4853. bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
  4854. if (nexthop)
  4855. attr.nexthop = *nexthop;
  4856. if (nexthop6)
  4857. {
  4858. struct attr_extra *extra = bgp_attr_extra_get(&attr);
  4859. extra->mp_nexthop_global = *nexthop6;
  4860. extra->mp_nexthop_len = 16;
  4861. }
  4862. attr.med = metric;
  4863. attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
  4864. attr.extra->tag = tag;
  4865. for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
  4866. {
  4867. afi = family2afi (p->family);
  4868. if (bgp->redist[afi][type])
  4869. {
  4870. struct attr attr_new;
  4871. struct attr_extra extra_new;
  4872. /* Copy attribute for modification. */
  4873. attr_new.extra = &extra_new;
  4874. bgp_attr_dup (&attr_new, &attr);
  4875. if (bgp->redist_metric_flag[afi][type])
  4876. attr_new.med = bgp->redist_metric[afi][type];
  4877. /* Apply route-map. */
  4878. if (bgp->rmap[afi][type].name)
  4879. {
  4880. info.peer = bgp->peer_self;
  4881. info.attr = &attr_new;
  4882. SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
  4883. ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
  4884. &info);
  4885. bgp->peer_self->rmap_type = 0;
  4886. if (ret == RMAP_DENYMATCH)
  4887. {
  4888. /* Free uninterned attribute. */
  4889. bgp_attr_flush (&attr_new);
  4890. /* Unintern original. */
  4891. aspath_unintern (&attr.aspath);
  4892. bgp_attr_extra_free (&attr);
  4893. bgp_redistribute_delete (p, type);
  4894. return;
  4895. }
  4896. }
  4897. bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
  4898. afi, SAFI_UNICAST, p, NULL);
  4899. new_attr = bgp_attr_intern (&attr_new);
  4900. for (bi = bn->info; bi; bi = bi->next)
  4901. if (bi->peer == bgp->peer_self
  4902. && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
  4903. break;
  4904. if (bi)
  4905. {
  4906. if (attrhash_cmp (bi->attr, new_attr) &&
  4907. !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
  4908. {
  4909. bgp_attr_unintern (&new_attr);
  4910. aspath_unintern (&attr.aspath);
  4911. bgp_attr_extra_free (&attr);
  4912. bgp_unlock_node (bn);
  4913. return;
  4914. }
  4915. else
  4916. {
  4917. /* The attribute is changed. */
  4918. bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
  4919. /* Rewrite BGP route information. */
  4920. if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
  4921. bgp_info_restore(bn, bi);
  4922. else
  4923. bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
  4924. bgp_attr_unintern (&bi->attr);
  4925. bi->attr = new_attr;
  4926. bi->uptime = bgp_clock ();
  4927. /* Process change. */
  4928. bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
  4929. bgp_process (bgp, bn, afi, SAFI_UNICAST);
  4930. bgp_unlock_node (bn);
  4931. aspath_unintern (&attr.aspath);
  4932. bgp_attr_extra_free (&attr);
  4933. return;
  4934. }
  4935. }
  4936. new = info_make(type, BGP_ROUTE_REDISTRIBUTE, bgp->peer_self,
  4937. new_attr, bn);
  4938. SET_FLAG (new->flags, BGP_INFO_VALID);
  4939. bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
  4940. bgp_info_add (bn, new);
  4941. bgp_unlock_node (bn);
  4942. bgp_process (bgp, bn, afi, SAFI_UNICAST);
  4943. }
  4944. }
  4945. /* Unintern original. */
  4946. aspath_unintern (&attr.aspath);
  4947. bgp_attr_extra_free (&attr);
  4948. }
  4949. void
  4950. bgp_redistribute_delete (struct prefix *p, u_char type)
  4951. {
  4952. struct bgp *bgp;
  4953. struct listnode *node, *nnode;
  4954. afi_t afi;
  4955. struct bgp_node *rn;
  4956. struct bgp_info *ri;
  4957. for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
  4958. {
  4959. afi = family2afi (p->family);
  4960. if (bgp->redist[afi][type])
  4961. {
  4962. rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
  4963. for (ri = rn->info; ri; ri = ri->next)
  4964. if (ri->peer == bgp->peer_self
  4965. && ri->type == type)
  4966. break;
  4967. if (ri)
  4968. {
  4969. bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
  4970. bgp_info_delete (rn, ri);
  4971. bgp_process (bgp, rn, afi, SAFI_UNICAST);
  4972. }
  4973. bgp_unlock_node (rn);
  4974. }
  4975. }
  4976. }
  4977. /* Withdraw specified route type's route. */
  4978. void
  4979. bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
  4980. {
  4981. struct bgp_node *rn;
  4982. struct bgp_info *ri;
  4983. struct bgp_table *table;
  4984. table = bgp->rib[afi][SAFI_UNICAST];
  4985. for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
  4986. {
  4987. for (ri = rn->info; ri; ri = ri->next)
  4988. if (ri->peer == bgp->peer_self
  4989. && ri->type == type)
  4990. break;
  4991. if (ri)
  4992. {
  4993. bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
  4994. bgp_info_delete (rn, ri);
  4995. bgp_process (bgp, rn, afi, SAFI_UNICAST);
  4996. }
  4997. }
  4998. }
  4999. /* Static function to display route. */
  5000. static void
  5001. route_vty_out_route (struct prefix *p, struct vty *vty)
  5002. {
  5003. int len;
  5004. u_int32_t destination;
  5005. char buf[BUFSIZ];
  5006. if (p->family == AF_INET)
  5007. {
  5008. len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
  5009. destination = ntohl (p->u.prefix4.s_addr);
  5010. if ((IN_CLASSC (destination) && p->prefixlen == 24)
  5011. || (IN_CLASSB (destination) && p->prefixlen == 16)
  5012. || (IN_CLASSA (destination) && p->prefixlen == 8)
  5013. || p->u.prefix4.s_addr == 0)
  5014. {
  5015. /* When mask is natural, mask is not displayed. */
  5016. }
  5017. else
  5018. len += vty_out (vty, "/%d", p->prefixlen);
  5019. }
  5020. else
  5021. len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
  5022. p->prefixlen);
  5023. len = 17 - len;
  5024. if (len < 1)
  5025. vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
  5026. else
  5027. vty_out (vty, "%*s", len, " ");
  5028. }
  5029. enum bgp_display_type
  5030. {
  5031. normal_list,
  5032. };
  5033. /* Print the short form route status for a bgp_info */
  5034. static void
  5035. route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
  5036. {
  5037. /* Route status display. */
  5038. if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
  5039. vty_out (vty, "R");
  5040. else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
  5041. vty_out (vty, "S");
  5042. else if (binfo->extra && binfo->extra->suppress)
  5043. vty_out (vty, "s");
  5044. else if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
  5045. ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
  5046. vty_out (vty, "*");
  5047. else
  5048. vty_out (vty, " ");
  5049. /* Selected */
  5050. if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
  5051. vty_out (vty, "h");
  5052. else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
  5053. vty_out (vty, "d");
  5054. else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
  5055. vty_out (vty, ">");
  5056. else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
  5057. vty_out (vty, "=");
  5058. else
  5059. vty_out (vty, " ");
  5060. /* Internal route. */
  5061. if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
  5062. vty_out (vty, "i");
  5063. else
  5064. vty_out (vty, " ");
  5065. }
  5066. /* called from terminal list command */
  5067. void
  5068. route_vty_out(
  5069. struct vty *vty,
  5070. struct prefix *p,
  5071. struct bgp_info *binfo,
  5072. int display,
  5073. safi_t safi)
  5074. {
  5075. struct attr *attr;
  5076. /* short status lead text */
  5077. route_vty_short_status_out (vty, binfo);
  5078. /* print prefix and mask */
  5079. if (!display)
  5080. route_vty_out_route (p, vty);
  5081. else
  5082. vty_out (vty, "%*s", 17, " ");
  5083. /* Print attribute */
  5084. attr = binfo->attr;
  5085. if (attr)
  5086. {
  5087. /*
  5088. * NEXTHOP start
  5089. */
  5090. /*
  5091. * For ENCAP routes, nexthop address family is not
  5092. * neccessarily the same as the prefix address family.
  5093. * Both SAFI_MPLS_VPN and SAFI_ENCAP use the MP nexthop field
  5094. */
  5095. if ((safi == SAFI_ENCAP) || (safi == SAFI_MPLS_VPN)) {
  5096. if (attr->extra) {
  5097. char buf[BUFSIZ];
  5098. int af = NEXTHOP_FAMILY(attr->extra->mp_nexthop_len);
  5099. switch (af) {
  5100. case AF_INET:
  5101. vty_out (vty, "%s", inet_ntop(af,
  5102. &attr->extra->mp_nexthop_global_in, buf, BUFSIZ));
  5103. break;
  5104. case AF_INET6:
  5105. vty_out (vty, "%s", inet_ntop(af,
  5106. &attr->extra->mp_nexthop_global, buf, BUFSIZ));
  5107. break;
  5108. default:
  5109. vty_out(vty, "?");
  5110. }
  5111. } else {
  5112. vty_out(vty, "?");
  5113. }
  5114. } else {
  5115. if (p->family == AF_INET)
  5116. {
  5117. vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
  5118. }
  5119. else if (p->family == AF_INET6)
  5120. {
  5121. int len;
  5122. char buf[BUFSIZ];
  5123. len = vty_out (vty, "%s",
  5124. inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
  5125. buf, BUFSIZ));
  5126. len = 16 - len;
  5127. if (len < 1)
  5128. vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
  5129. else
  5130. vty_out (vty, "%*s", len, " ");
  5131. }
  5132. else
  5133. {
  5134. vty_out(vty, "?");
  5135. }
  5136. }
  5137. /*
  5138. * NEXTHOP end
  5139. */
  5140. if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
  5141. vty_out (vty, "%10u", attr->med);
  5142. else
  5143. vty_out (vty, " ");
  5144. if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
  5145. vty_out (vty, "%7u", attr->local_pref);
  5146. else
  5147. vty_out (vty, " ");
  5148. vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
  5149. /* Print aspath */
  5150. if (attr->aspath)
  5151. aspath_print_vty (vty, "%s", attr->aspath, " ");
  5152. /* Print origin */
  5153. vty_out (vty, "%s", bgp_origin_str[attr->origin]);
  5154. }
  5155. vty_out (vty, "%s", VTY_NEWLINE);
  5156. }
  5157. /* called from terminal list command */
  5158. void
  5159. route_vty_out_tmp (struct vty *vty, struct prefix *p,
  5160. struct attr *attr, safi_t safi)
  5161. {
  5162. /* Route status display. */
  5163. vty_out (vty, "*");
  5164. vty_out (vty, ">");
  5165. vty_out (vty, " ");
  5166. /* print prefix and mask */
  5167. route_vty_out_route (p, vty);
  5168. /* Print attribute */
  5169. if (attr)
  5170. {
  5171. if (p->family == AF_INET)
  5172. {
  5173. if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
  5174. vty_out (vty, "%-16s",
  5175. inet_ntoa (attr->extra->mp_nexthop_global_in));
  5176. else
  5177. vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
  5178. }
  5179. else if (p->family == AF_INET6)
  5180. {
  5181. int len;
  5182. char buf[BUFSIZ];
  5183. assert (attr->extra);
  5184. len = vty_out (vty, "%s",
  5185. inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
  5186. buf, BUFSIZ));
  5187. len = 16 - len;
  5188. if (len < 1)
  5189. vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
  5190. else
  5191. vty_out (vty, "%*s", len, " ");
  5192. }
  5193. if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
  5194. vty_out (vty, "%10u ", attr->med);
  5195. else
  5196. vty_out (vty, " ");
  5197. if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
  5198. vty_out (vty, "%7u ", attr->local_pref);
  5199. else
  5200. vty_out (vty, " ");
  5201. vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
  5202. /* Print aspath */
  5203. if (attr->aspath)
  5204. aspath_print_vty (vty, "%s", attr->aspath, " ");
  5205. /* Print origin */
  5206. vty_out (vty, "%s", bgp_origin_str[attr->origin]);
  5207. }
  5208. vty_out (vty, "%s", VTY_NEWLINE);
  5209. }
  5210. void
  5211. route_vty_out_tag (struct vty *vty, struct prefix *p,
  5212. struct bgp_info *binfo, int display, safi_t safi)
  5213. {
  5214. struct attr *attr;
  5215. u_int32_t label = 0;
  5216. if (!binfo->extra)
  5217. return;
  5218. /* short status lead text */
  5219. route_vty_short_status_out (vty, binfo);
  5220. /* print prefix and mask */
  5221. if (! display)
  5222. route_vty_out_route (p, vty);
  5223. else
  5224. vty_out (vty, "%*s", 17, " ");
  5225. /* Print attribute */
  5226. attr = binfo->attr;
  5227. if (attr)
  5228. {
  5229. if (p->family == AF_INET)
  5230. {
  5231. if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
  5232. vty_out (vty, "%-16s",
  5233. inet_ntoa (attr->extra->mp_nexthop_global_in));
  5234. else
  5235. vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
  5236. }
  5237. else if (p->family == AF_INET6)
  5238. {
  5239. assert (attr->extra);
  5240. char buf[BUFSIZ];
  5241. char buf1[BUFSIZ];
  5242. if (attr->extra->mp_nexthop_len == 16)
  5243. vty_out (vty, "%s",
  5244. inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
  5245. buf, BUFSIZ));
  5246. else if (attr->extra->mp_nexthop_len == 32)
  5247. vty_out (vty, "%s(%s)",
  5248. inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
  5249. buf, BUFSIZ),
  5250. inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
  5251. buf1, BUFSIZ));
  5252. }
  5253. }
  5254. label = decode_label (binfo->extra->tag);
  5255. vty_out (vty, "notag/%d", label);
  5256. vty_out (vty, "%s", VTY_NEWLINE);
  5257. }
  5258. /* dampening route */
  5259. static void
  5260. damp_route_vty_out (struct vty *vty, struct prefix *p,
  5261. struct bgp_info *binfo, int display, safi_t safi)
  5262. {
  5263. struct attr *attr;
  5264. int len;
  5265. char timebuf[BGP_UPTIME_LEN];
  5266. /* short status lead text */
  5267. route_vty_short_status_out (vty, binfo);
  5268. /* print prefix and mask */
  5269. if (! display)
  5270. route_vty_out_route (p, vty);
  5271. else
  5272. vty_out (vty, "%*s", 17, " ");
  5273. len = vty_out (vty, "%s", binfo->peer->host);
  5274. len = 17 - len;
  5275. if (len < 1)
  5276. vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
  5277. else
  5278. vty_out (vty, "%*s", len, " ");
  5279. vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
  5280. /* Print attribute */
  5281. attr = binfo->attr;
  5282. if (attr)
  5283. {
  5284. /* Print aspath */
  5285. if (attr->aspath)
  5286. aspath_print_vty (vty, "%s", attr->aspath, " ");
  5287. /* Print origin */
  5288. vty_out (vty, "%s", bgp_origin_str[attr->origin]);
  5289. }
  5290. vty_out (vty, "%s", VTY_NEWLINE);
  5291. }
  5292. /* flap route */
  5293. static void
  5294. flap_route_vty_out (struct vty *vty, struct prefix *p,
  5295. struct bgp_info *binfo, int display, safi_t safi)
  5296. {
  5297. struct attr *attr;
  5298. struct bgp_damp_info *bdi;
  5299. char timebuf[BGP_UPTIME_LEN];
  5300. int len;
  5301. if (!binfo->extra)
  5302. return;
  5303. bdi = binfo->extra->damp_info;
  5304. /* short status lead text */
  5305. route_vty_short_status_out (vty, binfo);
  5306. /* print prefix and mask */
  5307. if (! display)
  5308. route_vty_out_route (p, vty);
  5309. else
  5310. vty_out (vty, "%*s", 17, " ");
  5311. len = vty_out (vty, "%s", binfo->peer->host);
  5312. len = 16 - len;
  5313. if (len < 1)
  5314. vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
  5315. else
  5316. vty_out (vty, "%*s", len, " ");
  5317. len = vty_out (vty, "%d", bdi->flap);
  5318. len = 5 - len;
  5319. if (len < 1)
  5320. vty_out (vty, " ");
  5321. else
  5322. vty_out (vty, "%*s ", len, " ");
  5323. vty_out (vty, "%s ", peer_uptime (bdi->start_time,
  5324. timebuf, BGP_UPTIME_LEN));
  5325. if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
  5326. && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
  5327. vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
  5328. else
  5329. vty_out (vty, "%*s ", 8, " ");
  5330. /* Print attribute */
  5331. attr = binfo->attr;
  5332. if (attr)
  5333. {
  5334. /* Print aspath */
  5335. if (attr->aspath)
  5336. aspath_print_vty (vty, "%s", attr->aspath, " ");
  5337. /* Print origin */
  5338. vty_out (vty, "%s", bgp_origin_str[attr->origin]);
  5339. }
  5340. vty_out (vty, "%s", VTY_NEWLINE);
  5341. }
  5342. static void
  5343. route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
  5344. struct bgp_info *binfo, afi_t afi, safi_t safi)
  5345. {
  5346. char buf[INET6_ADDRSTRLEN];
  5347. char buf1[BUFSIZ];
  5348. struct attr *attr;
  5349. int sockunion_vty_out (struct vty *, union sockunion *);
  5350. #ifdef HAVE_CLOCK_MONOTONIC
  5351. time_t tbuf;
  5352. #endif
  5353. attr = binfo->attr;
  5354. if (attr)
  5355. {
  5356. /* Line1 display AS-path, Aggregator */
  5357. if (attr->aspath)
  5358. {
  5359. vty_out (vty, " ");
  5360. if (aspath_count_hops (attr->aspath) == 0)
  5361. vty_out (vty, "Local");
  5362. else
  5363. aspath_print_vty (vty, "%s", attr->aspath, "");
  5364. }
  5365. if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
  5366. vty_out (vty, ", (removed)");
  5367. if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
  5368. vty_out (vty, ", (stale)");
  5369. if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
  5370. vty_out (vty, ", (aggregated by %u %s)",
  5371. attr->extra->aggregator_as,
  5372. inet_ntoa (attr->extra->aggregator_addr));
  5373. if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
  5374. vty_out (vty, ", (Received from a RR-client)");
  5375. if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
  5376. vty_out (vty, ", (Received from a RS-client)");
  5377. if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
  5378. vty_out (vty, ", (history entry)");
  5379. else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
  5380. vty_out (vty, ", (suppressed due to dampening)");
  5381. vty_out (vty, "%s", VTY_NEWLINE);
  5382. /* Line2 display Next-hop, Neighbor, Router-id */
  5383. if (p->family == AF_INET)
  5384. {
  5385. vty_out (vty, " %s", ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)) ?
  5386. inet_ntoa (attr->extra->mp_nexthop_global_in) :
  5387. inet_ntoa (attr->nexthop));
  5388. }
  5389. else
  5390. {
  5391. assert (attr->extra);
  5392. vty_out (vty, " %s",
  5393. inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
  5394. buf, INET6_ADDRSTRLEN));
  5395. }
  5396. if (binfo->peer == bgp->peer_self)
  5397. {
  5398. vty_out (vty, " from %s ",
  5399. p->family == AF_INET ? "0.0.0.0" : "::");
  5400. vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
  5401. }
  5402. else
  5403. {
  5404. if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
  5405. vty_out (vty, " (inaccessible)");
  5406. else if (binfo->extra && binfo->extra->igpmetric)
  5407. vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
  5408. if (!sockunion2str (&binfo->peer->su, buf, sizeof(buf))) {
  5409. buf[0] = '?';
  5410. buf[1] = 0;
  5411. }
  5412. vty_out (vty, " from %s", buf);
  5413. if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
  5414. vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
  5415. else
  5416. vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
  5417. }
  5418. vty_out (vty, "%s", VTY_NEWLINE);
  5419. /* display nexthop local */
  5420. if (attr->extra && attr->extra->mp_nexthop_len == 32)
  5421. {
  5422. vty_out (vty, " (%s)%s",
  5423. inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
  5424. buf, INET6_ADDRSTRLEN),
  5425. VTY_NEWLINE);
  5426. }
  5427. /* Line 3 display Origin, Med, Locpref, Weight, Tag, valid, Int/Ext/Local, Atomic, best */
  5428. vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
  5429. if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
  5430. vty_out (vty, ", metric %u", attr->med);
  5431. if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
  5432. vty_out (vty, ", localpref %u", attr->local_pref);
  5433. else
  5434. vty_out (vty, ", localpref %u", bgp->default_local_pref);
  5435. if (attr->extra && attr->extra->weight != 0)
  5436. vty_out (vty, ", weight %u", attr->extra->weight);
  5437. if (attr->extra && attr->extra->tag != 0)
  5438. vty_out (vty, ", tag %d", attr->extra->tag);
  5439. if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
  5440. vty_out (vty, ", invalid");
  5441. else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
  5442. vty_out (vty, ", valid");
  5443. if (binfo->peer != bgp->peer_self)
  5444. {
  5445. if (binfo->peer->as == binfo->peer->local_as)
  5446. vty_out (vty, ", internal");
  5447. else
  5448. vty_out (vty, ", %s",
  5449. (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
  5450. }
  5451. else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
  5452. vty_out (vty, ", aggregated, local");
  5453. else if (binfo->type != ZEBRA_ROUTE_BGP)
  5454. vty_out (vty, ", sourced");
  5455. else
  5456. vty_out (vty, ", sourced, local");
  5457. if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
  5458. vty_out (vty, ", atomic-aggregate");
  5459. if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
  5460. (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
  5461. bgp_info_mpath_count (binfo)))
  5462. vty_out (vty, ", multipath");
  5463. if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
  5464. vty_out (vty, ", best");
  5465. vty_out (vty, "%s", VTY_NEWLINE);
  5466. /* Line 4 display Community */
  5467. if (attr->community)
  5468. vty_out (vty, " Community: %s%s", attr->community->str,
  5469. VTY_NEWLINE);
  5470. /* Line 5 display Extended-community */
  5471. if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
  5472. vty_out (vty, " Extended Community: %s%s",
  5473. attr->extra->ecommunity->str, VTY_NEWLINE);
  5474. /* Line 6 display Large community */
  5475. if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES))
  5476. vty_out (vty, " Large Community: %s%s",
  5477. attr->extra->lcommunity->str, VTY_NEWLINE);
  5478. /* Line 7 display Originator, Cluster-id */
  5479. if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
  5480. (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
  5481. {
  5482. assert (attr->extra);
  5483. if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
  5484. vty_out (vty, " Originator: %s",
  5485. inet_ntoa (attr->extra->originator_id));
  5486. if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
  5487. {
  5488. int i;
  5489. vty_out (vty, ", Cluster list: ");
  5490. for (i = 0; i < attr->extra->cluster->length / 4; i++)
  5491. vty_out (vty, "%s ",
  5492. inet_ntoa (attr->extra->cluster->list[i]));
  5493. }
  5494. vty_out (vty, "%s", VTY_NEWLINE);
  5495. }
  5496. if (binfo->extra && binfo->extra->damp_info)
  5497. bgp_damp_info_vty (vty, binfo);
  5498. /* Line 8 display Uptime */
  5499. #ifdef HAVE_CLOCK_MONOTONIC
  5500. tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
  5501. vty_out (vty, " Last update: %s", ctime(&tbuf));
  5502. #else
  5503. vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
  5504. #endif /* HAVE_CLOCK_MONOTONIC */
  5505. }
  5506. vty_out (vty, "%s", VTY_NEWLINE);
  5507. }
  5508. #define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
  5509. "h history, * valid, > best, = multipath,%s"\
  5510. " i internal, r RIB-failure, S Stale, R Removed%s"
  5511. #define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
  5512. #define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
  5513. #define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
  5514. #define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
  5515. enum bgp_show_type
  5516. {
  5517. bgp_show_type_normal,
  5518. bgp_show_type_regexp,
  5519. bgp_show_type_prefix_list,
  5520. bgp_show_type_filter_list,
  5521. bgp_show_type_route_map,
  5522. bgp_show_type_neighbor,
  5523. bgp_show_type_cidr_only,
  5524. bgp_show_type_prefix_longer,
  5525. bgp_show_type_community_all,
  5526. bgp_show_type_community,
  5527. bgp_show_type_community_exact,
  5528. bgp_show_type_community_list,
  5529. bgp_show_type_community_list_exact,
  5530. bgp_show_type_lcommunity_all,
  5531. bgp_show_type_lcommunity,
  5532. bgp_show_type_lcommunity_list,
  5533. bgp_show_type_flap_statistics,
  5534. bgp_show_type_flap_address,
  5535. bgp_show_type_flap_prefix,
  5536. bgp_show_type_flap_cidr_only,
  5537. bgp_show_type_flap_regexp,
  5538. bgp_show_type_flap_filter_list,
  5539. bgp_show_type_flap_prefix_list,
  5540. bgp_show_type_flap_prefix_longer,
  5541. bgp_show_type_flap_route_map,
  5542. bgp_show_type_flap_neighbor,
  5543. bgp_show_type_dampend_paths,
  5544. bgp_show_type_damp_neighbor
  5545. };
  5546. static int
  5547. bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
  5548. enum bgp_show_type type, void *output_arg)
  5549. {
  5550. struct bgp_info *ri;
  5551. struct bgp_node *rn;
  5552. int header = 1;
  5553. int display;
  5554. unsigned long output_count;
  5555. unsigned long total_count;
  5556. /* This is first entry point, so reset total line. */
  5557. output_count = 0;
  5558. total_count = 0;
  5559. /* Start processing of routes. */
  5560. for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
  5561. if (rn->info != NULL)
  5562. {
  5563. display = 0;
  5564. for (ri = rn->info; ri; ri = ri->next)
  5565. {
  5566. total_count++;
  5567. if (type == bgp_show_type_flap_statistics
  5568. || type == bgp_show_type_flap_address
  5569. || type == bgp_show_type_flap_prefix
  5570. || type == bgp_show_type_flap_cidr_only
  5571. || type == bgp_show_type_flap_regexp
  5572. || type == bgp_show_type_flap_filter_list
  5573. || type == bgp_show_type_flap_prefix_list
  5574. || type == bgp_show_type_flap_prefix_longer
  5575. || type == bgp_show_type_flap_route_map
  5576. || type == bgp_show_type_flap_neighbor
  5577. || type == bgp_show_type_dampend_paths
  5578. || type == bgp_show_type_damp_neighbor)
  5579. {
  5580. if (!(ri->extra && ri->extra->damp_info))
  5581. continue;
  5582. }
  5583. if (type == bgp_show_type_regexp
  5584. || type == bgp_show_type_flap_regexp)
  5585. {
  5586. regex_t *regex = output_arg;
  5587. if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
  5588. continue;
  5589. }
  5590. if (type == bgp_show_type_prefix_list
  5591. || type == bgp_show_type_flap_prefix_list)
  5592. {
  5593. struct prefix_list *plist = output_arg;
  5594. if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
  5595. continue;
  5596. }
  5597. if (type == bgp_show_type_filter_list
  5598. || type == bgp_show_type_flap_filter_list)
  5599. {
  5600. struct as_list *as_list = output_arg;
  5601. if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
  5602. continue;
  5603. }
  5604. if (type == bgp_show_type_route_map
  5605. || type == bgp_show_type_flap_route_map)
  5606. {
  5607. struct route_map *rmap = output_arg;
  5608. struct bgp_info binfo;
  5609. struct attr dummy_attr;
  5610. struct attr_extra dummy_extra;
  5611. int ret;
  5612. dummy_attr.extra = &dummy_extra;
  5613. bgp_attr_dup (&dummy_attr, ri->attr);
  5614. binfo.peer = ri->peer;
  5615. binfo.attr = &dummy_attr;
  5616. ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
  5617. if (ret == RMAP_DENYMATCH)
  5618. continue;
  5619. }
  5620. if (type == bgp_show_type_neighbor
  5621. || type == bgp_show_type_flap_neighbor
  5622. || type == bgp_show_type_damp_neighbor)
  5623. {
  5624. union sockunion *su = output_arg;
  5625. if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
  5626. continue;
  5627. }
  5628. if (type == bgp_show_type_cidr_only
  5629. || type == bgp_show_type_flap_cidr_only)
  5630. {
  5631. u_int32_t destination;
  5632. destination = ntohl (rn->p.u.prefix4.s_addr);
  5633. if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
  5634. continue;
  5635. if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
  5636. continue;
  5637. if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
  5638. continue;
  5639. }
  5640. if (type == bgp_show_type_prefix_longer
  5641. || type == bgp_show_type_flap_prefix_longer)
  5642. {
  5643. struct prefix *p = output_arg;
  5644. if (! prefix_match (p, &rn->p))
  5645. continue;
  5646. }
  5647. if (type == bgp_show_type_community_all)
  5648. {
  5649. if (! ri->attr->community)
  5650. continue;
  5651. }
  5652. if (type == bgp_show_type_community)
  5653. {
  5654. struct community *com = output_arg;
  5655. if (! ri->attr->community ||
  5656. ! community_match (ri->attr->community, com))
  5657. continue;
  5658. }
  5659. if (type == bgp_show_type_community_exact)
  5660. {
  5661. struct community *com = output_arg;
  5662. if (! ri->attr->community ||
  5663. ! community_cmp (ri->attr->community, com))
  5664. continue;
  5665. }
  5666. if (type == bgp_show_type_community_list)
  5667. {
  5668. struct community_list *list = output_arg;
  5669. if (! community_list_match (ri->attr->community, list))
  5670. continue;
  5671. }
  5672. if (type == bgp_show_type_community_list_exact)
  5673. {
  5674. struct community_list *list = output_arg;
  5675. if (! community_list_exact_match (ri->attr->community, list))
  5676. continue;
  5677. }
  5678. if (type == bgp_show_type_community_all)
  5679. {
  5680. if (! ri->attr->community)
  5681. continue;
  5682. }
  5683. if (type == bgp_show_type_lcommunity)
  5684. {
  5685. struct lcommunity *lcom = output_arg;
  5686. if (! ri->attr->extra || ! ri->attr->extra->lcommunity ||
  5687. ! lcommunity_match (ri->attr->extra->lcommunity, lcom))
  5688. continue;
  5689. }
  5690. if (type == bgp_show_type_lcommunity_list)
  5691. {
  5692. struct community_list *list = output_arg;
  5693. if (! ri->attr->extra ||
  5694. ! lcommunity_list_match (ri->attr->extra->lcommunity, list))
  5695. continue;
  5696. }
  5697. if (type == bgp_show_type_lcommunity_all)
  5698. {
  5699. if (! ri->attr->extra || ! ri->attr->extra->lcommunity)
  5700. continue;
  5701. }
  5702. if (type == bgp_show_type_flap_address
  5703. || type == bgp_show_type_flap_prefix)
  5704. {
  5705. struct prefix *p = output_arg;
  5706. if (! prefix_match (&rn->p, p))
  5707. continue;
  5708. if (type == bgp_show_type_flap_prefix)
  5709. if (p->prefixlen != rn->p.prefixlen)
  5710. continue;
  5711. }
  5712. if (type == bgp_show_type_dampend_paths
  5713. || type == bgp_show_type_damp_neighbor)
  5714. {
  5715. if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
  5716. || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
  5717. continue;
  5718. }
  5719. if (header)
  5720. {
  5721. vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
  5722. vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
  5723. vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
  5724. if (type == bgp_show_type_dampend_paths
  5725. || type == bgp_show_type_damp_neighbor)
  5726. vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
  5727. else if (type == bgp_show_type_flap_statistics
  5728. || type == bgp_show_type_flap_address
  5729. || type == bgp_show_type_flap_prefix
  5730. || type == bgp_show_type_flap_cidr_only
  5731. || type == bgp_show_type_flap_regexp
  5732. || type == bgp_show_type_flap_filter_list
  5733. || type == bgp_show_type_flap_prefix_list
  5734. || type == bgp_show_type_flap_prefix_longer
  5735. || type == bgp_show_type_flap_route_map
  5736. || type == bgp_show_type_flap_neighbor)
  5737. vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
  5738. else
  5739. vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
  5740. header = 0;
  5741. }
  5742. if (type == bgp_show_type_dampend_paths
  5743. || type == bgp_show_type_damp_neighbor)
  5744. damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
  5745. else if (type == bgp_show_type_flap_statistics
  5746. || type == bgp_show_type_flap_address
  5747. || type == bgp_show_type_flap_prefix
  5748. || type == bgp_show_type_flap_cidr_only
  5749. || type == bgp_show_type_flap_regexp
  5750. || type == bgp_show_type_flap_filter_list
  5751. || type == bgp_show_type_flap_prefix_list
  5752. || type == bgp_show_type_flap_prefix_longer
  5753. || type == bgp_show_type_flap_route_map
  5754. || type == bgp_show_type_flap_neighbor)
  5755. flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
  5756. else
  5757. route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
  5758. display++;
  5759. }
  5760. if (display)
  5761. output_count++;
  5762. }
  5763. /* No route is displayed */
  5764. if (output_count == 0)
  5765. {
  5766. if (type == bgp_show_type_normal)
  5767. vty_out (vty, "No BGP prefixes displayed, %ld exist%s", total_count, VTY_NEWLINE);
  5768. }
  5769. else
  5770. vty_out (vty, "%sDisplayed %ld out of %ld total prefixes%s",
  5771. VTY_NEWLINE, output_count, total_count, VTY_NEWLINE);
  5772. return CMD_SUCCESS;
  5773. }
  5774. static int
  5775. bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
  5776. enum bgp_show_type type, void *output_arg)
  5777. {
  5778. struct bgp_table *table;
  5779. if (bgp == NULL) {
  5780. bgp = bgp_get_default ();
  5781. }
  5782. if (bgp == NULL)
  5783. {
  5784. vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
  5785. return CMD_WARNING;
  5786. }
  5787. table = bgp->rib[afi][safi];
  5788. return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
  5789. }
  5790. /* Header of detailed BGP route information */
  5791. static void
  5792. route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
  5793. struct bgp_node *rn,
  5794. struct prefix_rd *prd, afi_t afi, safi_t safi)
  5795. {
  5796. struct bgp_info *ri;
  5797. struct prefix *p;
  5798. struct peer *peer;
  5799. struct listnode *node, *nnode;
  5800. char buf1[INET6_ADDRSTRLEN];
  5801. char buf2[INET6_ADDRSTRLEN];
  5802. int count = 0;
  5803. int best = 0;
  5804. int suppress = 0;
  5805. int no_export = 0;
  5806. int no_advertise = 0;
  5807. int local_as = 0;
  5808. int first = 0;
  5809. int printrd = ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP));
  5810. p = &rn->p;
  5811. vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
  5812. (printrd ? prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
  5813. printrd ? ":" : "",
  5814. inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
  5815. p->prefixlen, VTY_NEWLINE);
  5816. for (ri = rn->info; ri; ri = ri->next)
  5817. {
  5818. count++;
  5819. if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
  5820. {
  5821. best = count;
  5822. if (ri->extra && ri->extra->suppress)
  5823. suppress = 1;
  5824. if (ri->attr->community != NULL)
  5825. {
  5826. if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
  5827. no_advertise = 1;
  5828. if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
  5829. no_export = 1;
  5830. if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
  5831. local_as = 1;
  5832. }
  5833. }
  5834. }
  5835. vty_out (vty, "Paths: (%d available", count);
  5836. if (best)
  5837. {
  5838. vty_out (vty, ", best #%d", best);
  5839. if (safi == SAFI_UNICAST)
  5840. vty_out (vty, ", table Default-IP-Routing-Table");
  5841. }
  5842. else
  5843. vty_out (vty, ", no best path");
  5844. if (no_advertise)
  5845. vty_out (vty, ", not advertised to any peer");
  5846. else if (no_export)
  5847. vty_out (vty, ", not advertised to EBGP peer");
  5848. else if (local_as)
  5849. vty_out (vty, ", not advertised outside local AS");
  5850. if (suppress)
  5851. vty_out (vty, ", Advertisements suppressed by an aggregate.");
  5852. vty_out (vty, ")%s", VTY_NEWLINE);
  5853. /* advertised peer */
  5854. for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
  5855. {
  5856. if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
  5857. {
  5858. if (! first)
  5859. vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
  5860. vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
  5861. first = 1;
  5862. }
  5863. }
  5864. if (! first)
  5865. vty_out (vty, " Not advertised to any peer");
  5866. vty_out (vty, "%s", VTY_NEWLINE);
  5867. }
  5868. /* Display specified route of BGP table. */
  5869. static int
  5870. bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
  5871. struct bgp_table *rib, const char *ip_str,
  5872. afi_t afi, safi_t safi, struct prefix_rd *prd,
  5873. int prefix_check, enum bgp_path_type pathtype)
  5874. {
  5875. int ret;
  5876. int header;
  5877. int display = 0;
  5878. struct prefix match;
  5879. struct bgp_node *rn;
  5880. struct bgp_node *rm;
  5881. struct bgp_info *ri;
  5882. struct bgp_table *table;
  5883. memset (&match, 0, sizeof (struct prefix)); /* keep valgrind happy */
  5884. /* Check IP address argument. */
  5885. ret = str2prefix (ip_str, &match);
  5886. if (! ret)
  5887. {
  5888. vty_out (vty, "address is malformed%s", VTY_NEWLINE);
  5889. return CMD_WARNING;
  5890. }
  5891. match.family = afi2family (afi);
  5892. if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
  5893. {
  5894. for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
  5895. {
  5896. if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
  5897. continue;
  5898. if ((table = rn->info) != NULL)
  5899. {
  5900. header = 1;
  5901. if ((rm = bgp_node_match (table, &match)) != NULL)
  5902. {
  5903. if (prefix_check && rm->p.prefixlen != match.prefixlen)
  5904. {
  5905. bgp_unlock_node (rm);
  5906. continue;
  5907. }
  5908. for (ri = rm->info; ri; ri = ri->next)
  5909. {
  5910. if (header)
  5911. {
  5912. route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
  5913. AFI_IP, safi);
  5914. header = 0;
  5915. }
  5916. display++;
  5917. if (pathtype == BGP_PATH_ALL ||
  5918. (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
  5919. (pathtype == BGP_PATH_MULTIPATH &&
  5920. (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
  5921. route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, safi);
  5922. }
  5923. bgp_unlock_node (rm);
  5924. }
  5925. }
  5926. }
  5927. }
  5928. else
  5929. {
  5930. header = 1;
  5931. if ((rn = bgp_node_match (rib, &match)) != NULL)
  5932. {
  5933. if (! prefix_check || rn->p.prefixlen == match.prefixlen)
  5934. {
  5935. for (ri = rn->info; ri; ri = ri->next)
  5936. {
  5937. if (header)
  5938. {
  5939. route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
  5940. header = 0;
  5941. }
  5942. display++;
  5943. if (pathtype == BGP_PATH_ALL ||
  5944. (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
  5945. (pathtype == BGP_PATH_MULTIPATH &&
  5946. (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
  5947. route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
  5948. }
  5949. }
  5950. bgp_unlock_node (rn);
  5951. }
  5952. }
  5953. if (! display)
  5954. {
  5955. vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
  5956. return CMD_WARNING;
  5957. }
  5958. return CMD_SUCCESS;
  5959. }
  5960. /* Display specified route of Main RIB */
  5961. static int
  5962. bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
  5963. afi_t afi, safi_t safi, struct prefix_rd *prd,
  5964. int prefix_check, enum bgp_path_type pathtype)
  5965. {
  5966. struct bgp *bgp;
  5967. /* BGP structure lookup. */
  5968. if (view_name)
  5969. {
  5970. bgp = bgp_lookup_by_name (view_name);
  5971. if (bgp == NULL)
  5972. {
  5973. vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
  5974. return CMD_WARNING;
  5975. }
  5976. }
  5977. else
  5978. {
  5979. bgp = bgp_get_default ();
  5980. if (bgp == NULL)
  5981. {
  5982. vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
  5983. return CMD_WARNING;
  5984. }
  5985. }
  5986. return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
  5987. afi, safi, prd, prefix_check, pathtype);
  5988. }
  5989. /* BGP route print out function. */
  5990. DEFUN (show_ip_bgp,
  5991. show_ip_bgp_cmd,
  5992. "show ip bgp",
  5993. SHOW_STR
  5994. IP_STR
  5995. BGP_STR)
  5996. {
  5997. return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
  5998. }
  5999. DEFUN (show_ip_bgp_ipv4,
  6000. show_ip_bgp_ipv4_cmd,
  6001. "show ip bgp ipv4 (unicast|multicast)",
  6002. SHOW_STR
  6003. IP_STR
  6004. BGP_STR
  6005. "Address family\n"
  6006. "Address Family modifier\n"
  6007. "Address Family modifier\n")
  6008. {
  6009. if (strncmp (argv[0], "m", 1) == 0)
  6010. return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
  6011. NULL);
  6012. return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
  6013. }
  6014. DEFUN (show_ip_bgp_route,
  6015. show_ip_bgp_route_cmd,
  6016. "show ip bgp A.B.C.D",
  6017. SHOW_STR
  6018. IP_STR
  6019. BGP_STR
  6020. "Network in the BGP routing table to display\n")
  6021. {
  6022. return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
  6023. }
  6024. DEFUN (show_ip_bgp_route_pathtype,
  6025. show_ip_bgp_route_pathtype_cmd,
  6026. "show ip bgp A.B.C.D (bestpath|multipath)",
  6027. SHOW_STR
  6028. IP_STR
  6029. BGP_STR
  6030. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  6031. "Display only the bestpath\n"
  6032. "Display only multipaths\n")
  6033. {
  6034. if (strncmp (argv[1], "b", 1) == 0)
  6035. return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
  6036. else
  6037. return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
  6038. }
  6039. DEFUN (show_bgp_ipv4_safi_route_pathtype,
  6040. show_bgp_ipv4_safi_route_pathtype_cmd,
  6041. "show bgp ipv4 (unicast|multicast) A.B.C.D (bestpath|multipath)",
  6042. SHOW_STR
  6043. BGP_STR
  6044. "Address family\n"
  6045. "Address Family modifier\n"
  6046. "Address Family modifier\n"
  6047. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  6048. "Display only the bestpath\n"
  6049. "Display only multipaths\n")
  6050. {
  6051. if (strncmp (argv[0], "m", 1) == 0)
  6052. if (strncmp (argv[2], "b", 1) == 0)
  6053. return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH);
  6054. else
  6055. return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH);
  6056. else
  6057. if (strncmp (argv[2], "b", 1) == 0)
  6058. return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
  6059. else
  6060. return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
  6061. }
  6062. DEFUN (show_ip_bgp_ipv4_route,
  6063. show_ip_bgp_ipv4_route_cmd,
  6064. "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
  6065. SHOW_STR
  6066. IP_STR
  6067. BGP_STR
  6068. "Address family\n"
  6069. "Address Family modifier\n"
  6070. "Address Family modifier\n"
  6071. "Network in the BGP routing table to display\n")
  6072. {
  6073. if (strncmp (argv[0], "m", 1) == 0)
  6074. return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL);
  6075. return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
  6076. }
  6077. DEFUN (show_ip_bgp_vpnv4_all_route,
  6078. show_ip_bgp_vpnv4_all_route_cmd,
  6079. "show ip bgp vpnv4 all A.B.C.D",
  6080. SHOW_STR
  6081. IP_STR
  6082. BGP_STR
  6083. "Display VPNv4 NLRI specific information\n"
  6084. "Display information about all VPNv4 NLRIs\n"
  6085. "Network in the BGP routing table to display\n")
  6086. {
  6087. return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL);
  6088. }
  6089. DEFUN (show_ip_bgp_vpnv4_rd_route,
  6090. show_ip_bgp_vpnv4_rd_route_cmd,
  6091. "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
  6092. SHOW_STR
  6093. IP_STR
  6094. BGP_STR
  6095. "Display VPNv4 NLRI specific information\n"
  6096. "Display information for a route distinguisher\n"
  6097. "VPN Route Distinguisher\n"
  6098. "Network in the BGP routing table to display\n")
  6099. {
  6100. int ret;
  6101. struct prefix_rd prd;
  6102. ret = str2prefix_rd (argv[0], &prd);
  6103. if (! ret)
  6104. {
  6105. vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
  6106. return CMD_WARNING;
  6107. }
  6108. return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL);
  6109. }
  6110. DEFUN (show_ip_bgp_prefix,
  6111. show_ip_bgp_prefix_cmd,
  6112. "show ip bgp A.B.C.D/M",
  6113. SHOW_STR
  6114. IP_STR
  6115. BGP_STR
  6116. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
  6117. {
  6118. return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
  6119. }
  6120. DEFUN (show_ip_bgp_prefix_pathtype,
  6121. show_ip_bgp_prefix_pathtype_cmd,
  6122. "show ip bgp A.B.C.D/M (bestpath|multipath)",
  6123. SHOW_STR
  6124. IP_STR
  6125. BGP_STR
  6126. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  6127. "Display only the bestpath\n"
  6128. "Display only multipaths\n")
  6129. {
  6130. if (strncmp (argv[1], "b", 1) == 0)
  6131. return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
  6132. else
  6133. return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
  6134. }
  6135. DEFUN (show_ip_bgp_ipv4_prefix,
  6136. show_ip_bgp_ipv4_prefix_cmd,
  6137. "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
  6138. SHOW_STR
  6139. IP_STR
  6140. BGP_STR
  6141. "Address family\n"
  6142. "Address Family modifier\n"
  6143. "Address Family modifier\n"
  6144. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
  6145. {
  6146. if (strncmp (argv[0], "m", 1) == 0)
  6147. return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL);
  6148. return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
  6149. }
  6150. DEFUN (show_ip_bgp_ipv4_prefix_pathtype,
  6151. show_ip_bgp_ipv4_prefix_pathtype_cmd,
  6152. "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath)",
  6153. SHOW_STR
  6154. IP_STR
  6155. BGP_STR
  6156. "Address family\n"
  6157. "Address Family modifier\n"
  6158. "Address Family modifier\n"
  6159. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  6160. "Display only the bestpath\n"
  6161. "Display only multipaths\n")
  6162. {
  6163. if (strncmp (argv[0], "m", 1) == 0)
  6164. if (strncmp (argv[2], "b", 1) == 0)
  6165. return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH);
  6166. else
  6167. return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH);
  6168. else
  6169. if (strncmp (argv[2], "b", 1) == 0)
  6170. return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
  6171. else
  6172. return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
  6173. }
  6174. ALIAS (show_ip_bgp_ipv4_prefix_pathtype,
  6175. show_bgp_ipv4_safi_prefix_pathtype_cmd,
  6176. "show bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath)",
  6177. SHOW_STR
  6178. BGP_STR
  6179. "Address family\n"
  6180. "Address Family modifier\n"
  6181. "Address Family modifier\n"
  6182. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  6183. "Display only the bestpath\n"
  6184. "Display only multipaths\n")
  6185. DEFUN (show_ip_bgp_vpnv4_all_prefix,
  6186. show_ip_bgp_vpnv4_all_prefix_cmd,
  6187. "show ip bgp vpnv4 all A.B.C.D/M",
  6188. SHOW_STR
  6189. IP_STR
  6190. BGP_STR
  6191. "Display VPNv4 NLRI specific information\n"
  6192. "Display information about all VPNv4 NLRIs\n"
  6193. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
  6194. {
  6195. return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1, BGP_PATH_ALL);
  6196. }
  6197. DEFUN (show_ip_bgp_vpnv4_rd_prefix,
  6198. show_ip_bgp_vpnv4_rd_prefix_cmd,
  6199. "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
  6200. SHOW_STR
  6201. IP_STR
  6202. BGP_STR
  6203. "Display VPNv4 NLRI specific information\n"
  6204. "Display information for a route distinguisher\n"
  6205. "VPN Route Distinguisher\n"
  6206. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
  6207. {
  6208. int ret;
  6209. struct prefix_rd prd;
  6210. ret = str2prefix_rd (argv[0], &prd);
  6211. if (! ret)
  6212. {
  6213. vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
  6214. return CMD_WARNING;
  6215. }
  6216. return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1, BGP_PATH_ALL);
  6217. }
  6218. DEFUN (show_ip_bgp_view,
  6219. show_ip_bgp_view_cmd,
  6220. "show ip bgp view WORD",
  6221. SHOW_STR
  6222. IP_STR
  6223. BGP_STR
  6224. "BGP view\n"
  6225. "View name\n")
  6226. {
  6227. struct bgp *bgp;
  6228. /* BGP structure lookup. */
  6229. bgp = bgp_lookup_by_name (argv[0]);
  6230. if (bgp == NULL)
  6231. {
  6232. vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
  6233. return CMD_WARNING;
  6234. }
  6235. return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
  6236. }
  6237. DEFUN (show_ip_bgp_view_route,
  6238. show_ip_bgp_view_route_cmd,
  6239. "show ip bgp view WORD A.B.C.D",
  6240. SHOW_STR
  6241. IP_STR
  6242. BGP_STR
  6243. "BGP view\n"
  6244. "View name\n"
  6245. "Network in the BGP routing table to display\n")
  6246. {
  6247. return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
  6248. }
  6249. DEFUN (show_ip_bgp_view_prefix,
  6250. show_ip_bgp_view_prefix_cmd,
  6251. "show ip bgp view WORD A.B.C.D/M",
  6252. SHOW_STR
  6253. IP_STR
  6254. BGP_STR
  6255. "BGP view\n"
  6256. "View name\n"
  6257. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
  6258. {
  6259. return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
  6260. }
  6261. DEFUN (show_bgp,
  6262. show_bgp_cmd,
  6263. "show bgp",
  6264. SHOW_STR
  6265. BGP_STR)
  6266. {
  6267. return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
  6268. NULL);
  6269. }
  6270. ALIAS (show_bgp,
  6271. show_bgp_ipv6_cmd,
  6272. "show bgp ipv6",
  6273. SHOW_STR
  6274. BGP_STR
  6275. "Address family\n")
  6276. /* old command */
  6277. DEFUN (show_ipv6_bgp,
  6278. show_ipv6_bgp_cmd,
  6279. "show ipv6 bgp",
  6280. SHOW_STR
  6281. IP_STR
  6282. BGP_STR)
  6283. {
  6284. return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
  6285. NULL);
  6286. }
  6287. DEFUN (show_bgp_route,
  6288. show_bgp_route_cmd,
  6289. "show bgp X:X::X:X",
  6290. SHOW_STR
  6291. BGP_STR
  6292. "Network in the BGP routing table to display\n")
  6293. {
  6294. return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
  6295. }
  6296. DEFUN (show_bgp_ipv4_safi,
  6297. show_bgp_ipv4_safi_cmd,
  6298. "show bgp ipv4 (unicast|multicast)",
  6299. SHOW_STR
  6300. BGP_STR
  6301. "Address family\n"
  6302. "Address Family modifier\n"
  6303. "Address Family modifier\n")
  6304. {
  6305. if (strncmp (argv[0], "m", 1) == 0)
  6306. return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
  6307. NULL);
  6308. return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
  6309. }
  6310. DEFUN (show_bgp_ipv4_safi_route,
  6311. show_bgp_ipv4_safi_route_cmd,
  6312. "show bgp ipv4 (unicast|multicast) A.B.C.D",
  6313. SHOW_STR
  6314. BGP_STR
  6315. "Address family\n"
  6316. "Address Family modifier\n"
  6317. "Address Family modifier\n"
  6318. "Network in the BGP routing table to display\n")
  6319. {
  6320. if (strncmp (argv[0], "m", 1) == 0)
  6321. return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL);
  6322. return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
  6323. }
  6324. DEFUN (show_bgp_route_pathtype,
  6325. show_bgp_route_pathtype_cmd,
  6326. "show bgp X:X::X:X (bestpath|multipath)",
  6327. SHOW_STR
  6328. BGP_STR
  6329. "Network in the BGP routing table to display\n"
  6330. "Display only the bestpath\n"
  6331. "Display only multipaths\n")
  6332. {
  6333. if (strncmp (argv[1], "b", 1) == 0)
  6334. return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
  6335. else
  6336. return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
  6337. }
  6338. ALIAS (show_bgp_route_pathtype,
  6339. show_bgp_ipv6_route_pathtype_cmd,
  6340. "show bgp ipv6 X:X::X:X (bestpath|multipath)",
  6341. SHOW_STR
  6342. BGP_STR
  6343. "Address family\n"
  6344. "Network in the BGP routing table to display\n"
  6345. "Display only the bestpath\n"
  6346. "Display only multipaths\n")
  6347. DEFUN (show_bgp_ipv6_safi_route_pathtype,
  6348. show_bgp_ipv6_safi_route_pathtype_cmd,
  6349. "show bgp ipv6 (unicast|multicast) X:X::X:X (bestpath|multipath)",
  6350. SHOW_STR
  6351. BGP_STR
  6352. "Address family\n"
  6353. "Address Family modifier\n"
  6354. "Address Family modifier\n"
  6355. "Network in the BGP routing table to display\n"
  6356. "Display only the bestpath\n"
  6357. "Display only multipaths\n")
  6358. {
  6359. if (strncmp (argv[0], "m", 1) == 0)
  6360. if (strncmp (argv[2], "b", 1) == 0)
  6361. return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH);
  6362. else
  6363. return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH);
  6364. else
  6365. if (strncmp (argv[2], "b", 1) == 0)
  6366. return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
  6367. else
  6368. return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
  6369. }
  6370. DEFUN (show_bgp_ipv4_vpn_route,
  6371. show_bgp_ipv4_vpn_route_cmd,
  6372. "show bgp ipv4 vpn A.B.C.D",
  6373. SHOW_STR
  6374. BGP_STR
  6375. "Address Family\n"
  6376. "Display VPN NLRI specific information\n"
  6377. "Network in the BGP routing table to display\n")
  6378. {
  6379. return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL);
  6380. }
  6381. DEFUN (show_bgp_ipv6_vpn_route,
  6382. show_bgp_ipv6_vpn_route_cmd,
  6383. "show bgp ipv6 vpn X:X::X:X",
  6384. SHOW_STR
  6385. BGP_STR
  6386. "Address Family\n"
  6387. "Display VPN NLRI specific information\n"
  6388. "Network in the BGP routing table to display\n")
  6389. {
  6390. return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL);
  6391. }
  6392. DEFUN (show_bgp_ipv4_vpn_rd_route,
  6393. show_bgp_ipv4_vpn_rd_route_cmd,
  6394. "show bgp ipv4 vpn rd ASN:nn_or_IP-address:nn A.B.C.D",
  6395. SHOW_STR
  6396. BGP_STR
  6397. IP_STR
  6398. "Display VPN NLRI specific information\n"
  6399. "Display information for a route distinguisher\n"
  6400. "VPN Route Distinguisher\n"
  6401. "Network in the BGP routing table to display\n")
  6402. {
  6403. int ret;
  6404. struct prefix_rd prd;
  6405. ret = str2prefix_rd (argv[0], &prd);
  6406. if (! ret)
  6407. {
  6408. vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
  6409. return CMD_WARNING;
  6410. }
  6411. return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL);
  6412. }
  6413. DEFUN (show_bgp_ipv6_vpn_rd_route,
  6414. show_bgp_ipv6_vpn_rd_route_cmd,
  6415. "show bgp ipv6 vpn rd ASN:nn_or_IP-address:nn X:X::X:X",
  6416. SHOW_STR
  6417. BGP_STR
  6418. "Address Family\n"
  6419. "Display VPN NLRI specific information\n"
  6420. "Display information for a route distinguisher\n"
  6421. "VPN Route Distinguisher\n"
  6422. "Network in the BGP routing table to display\n")
  6423. {
  6424. int ret;
  6425. struct prefix_rd prd;
  6426. ret = str2prefix_rd (argv[0], &prd);
  6427. if (! ret)
  6428. {
  6429. vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
  6430. return CMD_WARNING;
  6431. }
  6432. return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL);
  6433. }
  6434. DEFUN (show_bgp_prefix_pathtype,
  6435. show_bgp_prefix_pathtype_cmd,
  6436. "show bgp X:X::X:X/M (bestpath|multipath)",
  6437. SHOW_STR
  6438. BGP_STR
  6439. "IPv6 prefix <network>/<length>\n"
  6440. "Display only the bestpath\n"
  6441. "Display only multipaths\n")
  6442. {
  6443. if (strncmp (argv[1], "b", 1) == 0)
  6444. return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
  6445. else
  6446. return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
  6447. }
  6448. ALIAS (show_bgp_prefix_pathtype,
  6449. show_bgp_ipv6_prefix_pathtype_cmd,
  6450. "show bgp ipv6 X:X::X:X/M (bestpath|multipath)",
  6451. SHOW_STR
  6452. BGP_STR
  6453. "Address family\n"
  6454. "IPv6 prefix <network>/<length>\n"
  6455. "Display only the bestpath\n"
  6456. "Display only multipaths\n")
  6457. DEFUN (show_bgp_ipv6_safi_prefix_pathtype,
  6458. show_bgp_ipv6_safi_prefix_pathtype_cmd,
  6459. "show bgp ipv6 (unicast|multicast) X:X::X:X/M (bestpath|multipath)",
  6460. SHOW_STR
  6461. BGP_STR
  6462. "Address family\n"
  6463. "Address Family modifier\n"
  6464. "Address Family modifier\n"
  6465. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  6466. "Display only the bestpath\n"
  6467. "Display only multipaths\n")
  6468. {
  6469. if (strncmp (argv[0], "m", 1) == 0)
  6470. if (strncmp (argv[2], "b", 1) == 0)
  6471. return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH);
  6472. else
  6473. return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH);
  6474. else
  6475. if (strncmp (argv[2], "b", 1) == 0)
  6476. return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
  6477. else
  6478. return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
  6479. }
  6480. DEFUN (show_bgp_ipv4_encap_route,
  6481. show_bgp_ipv4_encap_route_cmd,
  6482. "show bgp ipv4 encap A.B.C.D",
  6483. SHOW_STR
  6484. BGP_STR
  6485. IP_STR
  6486. "Display ENCAP NLRI specific information\n"
  6487. "Network in the BGP routing table to display\n")
  6488. {
  6489. return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_ENCAP, NULL, 0, BGP_PATH_ALL);
  6490. }
  6491. DEFUN (show_bgp_ipv6_encap_route,
  6492. show_bgp_ipv6_encap_route_cmd,
  6493. "show bgp ipv6 encap X:X::X:X",
  6494. SHOW_STR
  6495. BGP_STR
  6496. IP6_STR
  6497. "Display ENCAP NLRI specific information\n"
  6498. "Network in the BGP routing table to display\n")
  6499. {
  6500. return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_ENCAP, NULL, 0, BGP_PATH_ALL);
  6501. }
  6502. DEFUN (show_bgp_ipv4_safi_rd_route,
  6503. show_bgp_ipv4_safi_rd_route_cmd,
  6504. "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D",
  6505. SHOW_STR
  6506. BGP_STR
  6507. "Address Family\n"
  6508. "Address Family Modifier\n"
  6509. "Address Family Modifier\n"
  6510. "Display information for a route distinguisher\n"
  6511. "ENCAP Route Distinguisher\n"
  6512. "Network in the BGP routing table to display\n")
  6513. {
  6514. int ret;
  6515. struct prefix_rd prd;
  6516. safi_t safi;
  6517. if (bgp_parse_safi(argv[0], &safi)) {
  6518. vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
  6519. return CMD_WARNING;
  6520. }
  6521. ret = str2prefix