bgp_route.c 403 KB

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