bgp_route.c 416 KB

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