bgp_route.c 402 KB

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