bgp_route.c 372 KB

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