bgp_route.c 375 KB

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