bgp_routemap.c 100 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000
  1. /* Route map function of bgpd.
  2. Copyright (C) 1998, 1999 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 "filter.h"
  19. #include "routemap.h"
  20. #include "command.h"
  21. #include "linklist.h"
  22. #include "plist.h"
  23. #include "memory.h"
  24. #include "log.h"
  25. #ifdef HAVE_LIBPCREPOSIX
  26. # include <pcreposix.h>
  27. #else
  28. # ifdef HAVE_GNU_REGEX
  29. # include <regex.h>
  30. # else
  31. # include "regex-gnu.h"
  32. # endif /* HAVE_GNU_REGEX */
  33. #endif /* HAVE_LIBPCREPOSIX */
  34. #include "buffer.h"
  35. #include "sockunion.h"
  36. #include "bgpd/bgpd.h"
  37. #include "bgpd/bgp_table.h"
  38. #include "bgpd/bgp_attr.h"
  39. #include "bgpd/bgp_aspath.h"
  40. #include "bgpd/bgp_route.h"
  41. #include "bgpd/bgp_regex.h"
  42. #include "bgpd/bgp_community.h"
  43. #include "bgpd/bgp_clist.h"
  44. #include "bgpd/bgp_filter.h"
  45. #include "bgpd/bgp_mplsvpn.h"
  46. #include "bgpd/bgp_ecommunity.h"
  47. #include "bgpd/bgp_vty.h"
  48. /* Memo of route-map commands.
  49. o Cisco route-map
  50. match as-path : Done
  51. community : Done
  52. interface : Not yet
  53. ip address : Done
  54. ip next-hop : Done
  55. ip route-source : Done
  56. ip prefix-list : Done
  57. ipv6 address : Done
  58. ipv6 next-hop : Done
  59. ipv6 route-source: (This will not be implemented by bgpd)
  60. ipv6 prefix-list : Done
  61. length : (This will not be implemented by bgpd)
  62. metric : Done
  63. route-type : (This will not be implemented by bgpd)
  64. tag : (This will not be implemented by bgpd)
  65. set as-path prepend : Done
  66. as-path tag : Not yet
  67. automatic-tag : (This will not be implemented by bgpd)
  68. community : Done
  69. comm-list : Not yet
  70. dampning : Not yet
  71. default : (This will not be implemented by bgpd)
  72. interface : (This will not be implemented by bgpd)
  73. ip default : (This will not be implemented by bgpd)
  74. ip next-hop : Done
  75. ip precedence : (This will not be implemented by bgpd)
  76. ip tos : (This will not be implemented by bgpd)
  77. level : (This will not be implemented by bgpd)
  78. local-preference : Done
  79. metric : Done
  80. metric-type : Not yet
  81. origin : Done
  82. tag : (This will not be implemented by bgpd)
  83. weight : Done
  84. o Local extention
  85. set ipv6 next-hop global: Done
  86. set ipv6 next-hop local : Done
  87. set as-path exclude : Done
  88. */
  89. /* 'match peer (A.B.C.D|X:X::X:X)' */
  90. /* Compares the peer specified in the 'match peer' clause with the peer
  91. received in bgp_info->peer. If it is the same, or if the peer structure
  92. received is a peer_group containing it, returns RMAP_MATCH. */
  93. static route_map_result_t
  94. route_match_peer (void *rule, struct prefix *prefix, route_map_object_t type,
  95. void *object)
  96. {
  97. union sockunion *su;
  98. union sockunion su_def = { .sa.sa_family = AF_INET,
  99. .sin.sin_addr.s_addr = INADDR_ANY };
  100. struct peer_group *group;
  101. struct peer *peer;
  102. struct listnode *node, *nnode;
  103. if (type == RMAP_BGP)
  104. {
  105. su = rule;
  106. peer = ((struct bgp_info *) object)->peer;
  107. if ( ! CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT) &&
  108. ! CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_EXPORT) )
  109. return RMAP_NOMATCH;
  110. /* If su='0.0.0.0' (command 'match peer local'), and it's a NETWORK,
  111. REDISTRIBUTE or DEFAULT_GENERATED route => return RMAP_MATCH */
  112. if (sockunion_same (su, &su_def))
  113. {
  114. int ret;
  115. if ( CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_NETWORK) ||
  116. CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE) ||
  117. CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_DEFAULT))
  118. ret = RMAP_MATCH;
  119. else
  120. ret = RMAP_NOMATCH;
  121. return ret;
  122. }
  123. if (! CHECK_FLAG (peer->sflags, PEER_STATUS_GROUP))
  124. {
  125. if (sockunion_same (su, &peer->su))
  126. return RMAP_MATCH;
  127. return RMAP_NOMATCH;
  128. }
  129. else
  130. {
  131. group = peer->group;
  132. for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer))
  133. {
  134. if (sockunion_same (su, &peer->su))
  135. return RMAP_MATCH;
  136. }
  137. return RMAP_NOMATCH;
  138. }
  139. }
  140. return RMAP_NOMATCH;
  141. }
  142. static void *
  143. route_match_peer_compile (const char *arg)
  144. {
  145. union sockunion *su;
  146. int ret;
  147. su = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (union sockunion));
  148. ret = str2sockunion (strcmp(arg, "local") ? arg : "0.0.0.0", su);
  149. if (ret < 0) {
  150. XFREE (MTYPE_ROUTE_MAP_COMPILED, su);
  151. return NULL;
  152. }
  153. return su;
  154. }
  155. /* Free route map's compiled `ip address' value. */
  156. static void
  157. route_match_peer_free (void *rule)
  158. {
  159. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  160. }
  161. /* Route map commands for ip address matching. */
  162. struct route_map_rule_cmd route_match_peer_cmd =
  163. {
  164. "peer",
  165. route_match_peer,
  166. route_match_peer_compile,
  167. route_match_peer_free
  168. };
  169. /* `match ip address IP_ACCESS_LIST' */
  170. /* Match function should return 1 if match is success else return
  171. zero. */
  172. static route_map_result_t
  173. route_match_ip_address (void *rule, struct prefix *prefix,
  174. route_map_object_t type, void *object)
  175. {
  176. struct access_list *alist;
  177. /* struct prefix_ipv4 match; */
  178. if (type == RMAP_BGP)
  179. {
  180. alist = access_list_lookup (AFI_IP, (char *) rule);
  181. if (alist == NULL)
  182. return RMAP_NOMATCH;
  183. return (access_list_apply (alist, prefix) == FILTER_DENY ?
  184. RMAP_NOMATCH : RMAP_MATCH);
  185. }
  186. return RMAP_NOMATCH;
  187. }
  188. /* Route map `ip address' match statement. `arg' should be
  189. access-list name. */
  190. static void *
  191. route_match_ip_address_compile (const char *arg)
  192. {
  193. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  194. }
  195. /* Free route map's compiled `ip address' value. */
  196. static void
  197. route_match_ip_address_free (void *rule)
  198. {
  199. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  200. }
  201. /* Route map commands for ip address matching. */
  202. struct route_map_rule_cmd route_match_ip_address_cmd =
  203. {
  204. "ip address",
  205. route_match_ip_address,
  206. route_match_ip_address_compile,
  207. route_match_ip_address_free
  208. };
  209. /* `match ip next-hop IP_ADDRESS' */
  210. /* Match function return 1 if match is success else return zero. */
  211. static route_map_result_t
  212. route_match_ip_next_hop (void *rule, struct prefix *prefix,
  213. route_map_object_t type, void *object)
  214. {
  215. struct access_list *alist;
  216. struct bgp_info *bgp_info;
  217. struct prefix_ipv4 p;
  218. if (type == RMAP_BGP)
  219. {
  220. bgp_info = object;
  221. p.family = AF_INET;
  222. p.prefix = bgp_info->attr->nexthop;
  223. p.prefixlen = IPV4_MAX_BITLEN;
  224. alist = access_list_lookup (AFI_IP, (char *) rule);
  225. if (alist == NULL)
  226. return RMAP_NOMATCH;
  227. return (access_list_apply (alist, &p) == FILTER_DENY ?
  228. RMAP_NOMATCH : RMAP_MATCH);
  229. }
  230. return RMAP_NOMATCH;
  231. }
  232. /* Route map `ip next-hop' match statement. `arg' is
  233. access-list name. */
  234. static void *
  235. route_match_ip_next_hop_compile (const char *arg)
  236. {
  237. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  238. }
  239. /* Free route map's compiled `ip address' value. */
  240. static void
  241. route_match_ip_next_hop_free (void *rule)
  242. {
  243. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  244. }
  245. /* Route map commands for ip next-hop matching. */
  246. struct route_map_rule_cmd route_match_ip_next_hop_cmd =
  247. {
  248. "ip next-hop",
  249. route_match_ip_next_hop,
  250. route_match_ip_next_hop_compile,
  251. route_match_ip_next_hop_free
  252. };
  253. /* `match ip route-source ACCESS-LIST' */
  254. /* Match function return 1 if match is success else return zero. */
  255. static route_map_result_t
  256. route_match_ip_route_source (void *rule, struct prefix *prefix,
  257. route_map_object_t type, void *object)
  258. {
  259. struct access_list *alist;
  260. struct bgp_info *bgp_info;
  261. struct peer *peer;
  262. struct prefix_ipv4 p;
  263. if (type == RMAP_BGP)
  264. {
  265. bgp_info = object;
  266. peer = bgp_info->peer;
  267. if (! peer || sockunion_family (&peer->su) != AF_INET)
  268. return RMAP_NOMATCH;
  269. p.family = AF_INET;
  270. p.prefix = peer->su.sin.sin_addr;
  271. p.prefixlen = IPV4_MAX_BITLEN;
  272. alist = access_list_lookup (AFI_IP, (char *) rule);
  273. if (alist == NULL)
  274. return RMAP_NOMATCH;
  275. return (access_list_apply (alist, &p) == FILTER_DENY ?
  276. RMAP_NOMATCH : RMAP_MATCH);
  277. }
  278. return RMAP_NOMATCH;
  279. }
  280. /* Route map `ip route-source' match statement. `arg' is
  281. access-list name. */
  282. static void *
  283. route_match_ip_route_source_compile (const char *arg)
  284. {
  285. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  286. }
  287. /* Free route map's compiled `ip address' value. */
  288. static void
  289. route_match_ip_route_source_free (void *rule)
  290. {
  291. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  292. }
  293. /* Route map commands for ip route-source matching. */
  294. struct route_map_rule_cmd route_match_ip_route_source_cmd =
  295. {
  296. "ip route-source",
  297. route_match_ip_route_source,
  298. route_match_ip_route_source_compile,
  299. route_match_ip_route_source_free
  300. };
  301. /* `match ip address prefix-list PREFIX_LIST' */
  302. static route_map_result_t
  303. route_match_ip_address_prefix_list (void *rule, struct prefix *prefix,
  304. route_map_object_t type, void *object)
  305. {
  306. struct prefix_list *plist;
  307. if (type == RMAP_BGP)
  308. {
  309. plist = prefix_list_lookup (AFI_IP, (char *) rule);
  310. if (plist == NULL)
  311. return RMAP_NOMATCH;
  312. return (prefix_list_apply (plist, prefix) == PREFIX_DENY ?
  313. RMAP_NOMATCH : RMAP_MATCH);
  314. }
  315. return RMAP_NOMATCH;
  316. }
  317. static void *
  318. route_match_ip_address_prefix_list_compile (const char *arg)
  319. {
  320. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  321. }
  322. static void
  323. route_match_ip_address_prefix_list_free (void *rule)
  324. {
  325. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  326. }
  327. struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd =
  328. {
  329. "ip address prefix-list",
  330. route_match_ip_address_prefix_list,
  331. route_match_ip_address_prefix_list_compile,
  332. route_match_ip_address_prefix_list_free
  333. };
  334. /* `match ip next-hop prefix-list PREFIX_LIST' */
  335. static route_map_result_t
  336. route_match_ip_next_hop_prefix_list (void *rule, struct prefix *prefix,
  337. route_map_object_t type, void *object)
  338. {
  339. struct prefix_list *plist;
  340. struct bgp_info *bgp_info;
  341. struct prefix_ipv4 p;
  342. if (type == RMAP_BGP)
  343. {
  344. bgp_info = object;
  345. p.family = AF_INET;
  346. p.prefix = bgp_info->attr->nexthop;
  347. p.prefixlen = IPV4_MAX_BITLEN;
  348. plist = prefix_list_lookup (AFI_IP, (char *) rule);
  349. if (plist == NULL)
  350. return RMAP_NOMATCH;
  351. return (prefix_list_apply (plist, &p) == PREFIX_DENY ?
  352. RMAP_NOMATCH : RMAP_MATCH);
  353. }
  354. return RMAP_NOMATCH;
  355. }
  356. static void *
  357. route_match_ip_next_hop_prefix_list_compile (const char *arg)
  358. {
  359. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  360. }
  361. static void
  362. route_match_ip_next_hop_prefix_list_free (void *rule)
  363. {
  364. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  365. }
  366. struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd =
  367. {
  368. "ip next-hop prefix-list",
  369. route_match_ip_next_hop_prefix_list,
  370. route_match_ip_next_hop_prefix_list_compile,
  371. route_match_ip_next_hop_prefix_list_free
  372. };
  373. /* `match ip route-source prefix-list PREFIX_LIST' */
  374. static route_map_result_t
  375. route_match_ip_route_source_prefix_list (void *rule, struct prefix *prefix,
  376. route_map_object_t type, void *object)
  377. {
  378. struct prefix_list *plist;
  379. struct bgp_info *bgp_info;
  380. struct peer *peer;
  381. struct prefix_ipv4 p;
  382. if (type == RMAP_BGP)
  383. {
  384. bgp_info = object;
  385. peer = bgp_info->peer;
  386. if (! peer || sockunion_family (&peer->su) != AF_INET)
  387. return RMAP_NOMATCH;
  388. p.family = AF_INET;
  389. p.prefix = peer->su.sin.sin_addr;
  390. p.prefixlen = IPV4_MAX_BITLEN;
  391. plist = prefix_list_lookup (AFI_IP, (char *) rule);
  392. if (plist == NULL)
  393. return RMAP_NOMATCH;
  394. return (prefix_list_apply (plist, &p) == PREFIX_DENY ?
  395. RMAP_NOMATCH : RMAP_MATCH);
  396. }
  397. return RMAP_NOMATCH;
  398. }
  399. static void *
  400. route_match_ip_route_source_prefix_list_compile (const char *arg)
  401. {
  402. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  403. }
  404. static void
  405. route_match_ip_route_source_prefix_list_free (void *rule)
  406. {
  407. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  408. }
  409. struct route_map_rule_cmd route_match_ip_route_source_prefix_list_cmd =
  410. {
  411. "ip route-source prefix-list",
  412. route_match_ip_route_source_prefix_list,
  413. route_match_ip_route_source_prefix_list_compile,
  414. route_match_ip_route_source_prefix_list_free
  415. };
  416. /* `match metric METRIC' */
  417. /* Match function return 1 if match is success else return zero. */
  418. static route_map_result_t
  419. route_match_metric (void *rule, struct prefix *prefix,
  420. route_map_object_t type, void *object)
  421. {
  422. u_int32_t *med;
  423. struct bgp_info *bgp_info;
  424. if (type == RMAP_BGP)
  425. {
  426. med = rule;
  427. bgp_info = object;
  428. if (bgp_info->attr->med == *med)
  429. return RMAP_MATCH;
  430. else
  431. return RMAP_NOMATCH;
  432. }
  433. return RMAP_NOMATCH;
  434. }
  435. /* Route map `match metric' match statement. `arg' is MED value */
  436. static void *
  437. route_match_metric_compile (const char *arg)
  438. {
  439. u_int32_t *med;
  440. char *endptr = NULL;
  441. unsigned long tmpval;
  442. /* Metric value shoud be integer. */
  443. if (! all_digit (arg))
  444. return NULL;
  445. errno = 0;
  446. tmpval = strtoul (arg, &endptr, 10);
  447. if (*endptr != '\0' || errno || tmpval > UINT32_MAX)
  448. return NULL;
  449. med = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
  450. if (!med)
  451. return med;
  452. *med = tmpval;
  453. return med;
  454. }
  455. /* Free route map's compiled `match metric' value. */
  456. static void
  457. route_match_metric_free (void *rule)
  458. {
  459. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  460. }
  461. /* Route map commands for metric matching. */
  462. struct route_map_rule_cmd route_match_metric_cmd =
  463. {
  464. "metric",
  465. route_match_metric,
  466. route_match_metric_compile,
  467. route_match_metric_free
  468. };
  469. /* `match as-path ASPATH' */
  470. /* Match function for as-path match. I assume given object is */
  471. static route_map_result_t
  472. route_match_aspath (void *rule, struct prefix *prefix,
  473. route_map_object_t type, void *object)
  474. {
  475. struct as_list *as_list;
  476. struct bgp_info *bgp_info;
  477. if (type == RMAP_BGP)
  478. {
  479. as_list = as_list_lookup ((char *) rule);
  480. if (as_list == NULL)
  481. return RMAP_NOMATCH;
  482. bgp_info = object;
  483. /* Perform match. */
  484. return ((as_list_apply (as_list, bgp_info->attr->aspath) == AS_FILTER_DENY) ? RMAP_NOMATCH : RMAP_MATCH);
  485. }
  486. return RMAP_NOMATCH;
  487. }
  488. /* Compile function for as-path match. */
  489. static void *
  490. route_match_aspath_compile (const char *arg)
  491. {
  492. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  493. }
  494. /* Compile function for as-path match. */
  495. static void
  496. route_match_aspath_free (void *rule)
  497. {
  498. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  499. }
  500. /* Route map commands for aspath matching. */
  501. struct route_map_rule_cmd route_match_aspath_cmd =
  502. {
  503. "as-path",
  504. route_match_aspath,
  505. route_match_aspath_compile,
  506. route_match_aspath_free
  507. };
  508. /* `match community COMMUNIY' */
  509. struct rmap_community
  510. {
  511. char *name;
  512. int exact;
  513. };
  514. /* Match function for community match. */
  515. static route_map_result_t
  516. route_match_community (void *rule, struct prefix *prefix,
  517. route_map_object_t type, void *object)
  518. {
  519. struct community_list *list;
  520. struct bgp_info *bgp_info;
  521. struct rmap_community *rcom;
  522. if (type == RMAP_BGP)
  523. {
  524. bgp_info = object;
  525. rcom = rule;
  526. list = community_list_lookup (bgp_clist, rcom->name, COMMUNITY_LIST_MASTER);
  527. if (! list)
  528. return RMAP_NOMATCH;
  529. if (rcom->exact)
  530. {
  531. if (community_list_exact_match (bgp_info->attr->community, list))
  532. return RMAP_MATCH;
  533. }
  534. else
  535. {
  536. if (community_list_match (bgp_info->attr->community, list))
  537. return RMAP_MATCH;
  538. }
  539. }
  540. return RMAP_NOMATCH;
  541. }
  542. /* Compile function for community match. */
  543. static void *
  544. route_match_community_compile (const char *arg)
  545. {
  546. struct rmap_community *rcom;
  547. int len;
  548. char *p;
  549. rcom = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_community));
  550. p = strchr (arg, ' ');
  551. if (p)
  552. {
  553. len = p - arg;
  554. rcom->name = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, len + 1);
  555. memcpy (rcom->name, arg, len);
  556. rcom->exact = 1;
  557. }
  558. else
  559. {
  560. rcom->name = XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  561. rcom->exact = 0;
  562. }
  563. return rcom;
  564. }
  565. /* Compile function for community match. */
  566. static void
  567. route_match_community_free (void *rule)
  568. {
  569. struct rmap_community *rcom = rule;
  570. XFREE (MTYPE_ROUTE_MAP_COMPILED, rcom->name);
  571. XFREE (MTYPE_ROUTE_MAP_COMPILED, rcom);
  572. }
  573. /* Route map commands for community matching. */
  574. struct route_map_rule_cmd route_match_community_cmd =
  575. {
  576. "community",
  577. route_match_community,
  578. route_match_community_compile,
  579. route_match_community_free
  580. };
  581. /* Match function for extcommunity match. */
  582. static route_map_result_t
  583. route_match_ecommunity (void *rule, struct prefix *prefix,
  584. route_map_object_t type, void *object)
  585. {
  586. struct community_list *list;
  587. struct bgp_info *bgp_info;
  588. if (type == RMAP_BGP)
  589. {
  590. bgp_info = object;
  591. if (!bgp_info->attr->extra)
  592. return RMAP_NOMATCH;
  593. list = community_list_lookup (bgp_clist, (char *) rule,
  594. EXTCOMMUNITY_LIST_MASTER);
  595. if (! list)
  596. return RMAP_NOMATCH;
  597. if (ecommunity_list_match (bgp_info->attr->extra->ecommunity, list))
  598. return RMAP_MATCH;
  599. }
  600. return RMAP_NOMATCH;
  601. }
  602. /* Compile function for extcommunity match. */
  603. static void *
  604. route_match_ecommunity_compile (const char *arg)
  605. {
  606. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  607. }
  608. /* Compile function for extcommunity match. */
  609. static void
  610. route_match_ecommunity_free (void *rule)
  611. {
  612. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  613. }
  614. /* Route map commands for community matching. */
  615. struct route_map_rule_cmd route_match_ecommunity_cmd =
  616. {
  617. "extcommunity",
  618. route_match_ecommunity,
  619. route_match_ecommunity_compile,
  620. route_match_ecommunity_free
  621. };
  622. /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
  623. and `address-family vpnv4'. */
  624. /* `match origin' */
  625. static route_map_result_t
  626. route_match_origin (void *rule, struct prefix *prefix,
  627. route_map_object_t type, void *object)
  628. {
  629. u_char *origin;
  630. struct bgp_info *bgp_info;
  631. if (type == RMAP_BGP)
  632. {
  633. origin = rule;
  634. bgp_info = object;
  635. if (bgp_info->attr->origin == *origin)
  636. return RMAP_MATCH;
  637. }
  638. return RMAP_NOMATCH;
  639. }
  640. static void *
  641. route_match_origin_compile (const char *arg)
  642. {
  643. u_char *origin;
  644. origin = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_char));
  645. if (strcmp (arg, "igp") == 0)
  646. *origin = 0;
  647. else if (strcmp (arg, "egp") == 0)
  648. *origin = 1;
  649. else
  650. *origin = 2;
  651. return origin;
  652. }
  653. /* Free route map's compiled `ip address' value. */
  654. static void
  655. route_match_origin_free (void *rule)
  656. {
  657. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  658. }
  659. /* Route map commands for origin matching. */
  660. struct route_map_rule_cmd route_match_origin_cmd =
  661. {
  662. "origin",
  663. route_match_origin,
  664. route_match_origin_compile,
  665. route_match_origin_free
  666. };
  667. /* match probability { */
  668. static route_map_result_t
  669. route_match_probability (void *rule, struct prefix *prefix,
  670. route_map_object_t type, void *object)
  671. {
  672. long r;
  673. #if _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE >= 500
  674. r = random();
  675. #else
  676. r = (long) rand();
  677. #endif
  678. switch (*(unsigned *) rule)
  679. {
  680. case 0: break;
  681. case RAND_MAX: return RMAP_MATCH;
  682. default:
  683. if (r < *(unsigned *) rule)
  684. {
  685. return RMAP_MATCH;
  686. }
  687. }
  688. return RMAP_NOMATCH;
  689. }
  690. static void *
  691. route_match_probability_compile (const char *arg)
  692. {
  693. unsigned *lobule;
  694. unsigned perc;
  695. #if _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE >= 500
  696. srandom (time (NULL));
  697. #else
  698. srand (time (NULL));
  699. #endif
  700. perc = atoi (arg);
  701. lobule = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (unsigned));
  702. switch (perc)
  703. {
  704. case 0: *lobule = 0; break;
  705. case 100: *lobule = RAND_MAX; break;
  706. default: *lobule = RAND_MAX / 100 * perc;
  707. }
  708. return lobule;
  709. }
  710. static void
  711. route_match_probability_free (void *rule)
  712. {
  713. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  714. }
  715. struct route_map_rule_cmd route_match_probability_cmd =
  716. {
  717. "probability",
  718. route_match_probability,
  719. route_match_probability_compile,
  720. route_match_probability_free
  721. };
  722. /* } */
  723. /* `set ip next-hop IP_ADDRESS' */
  724. /* Set nexthop to object. ojbect must be pointer to struct attr. */
  725. struct rmap_ip_nexthop_set
  726. {
  727. struct in_addr *address;
  728. int peer_address;
  729. };
  730. static route_map_result_t
  731. route_set_ip_nexthop (void *rule, struct prefix *prefix,
  732. route_map_object_t type, void *object)
  733. {
  734. struct rmap_ip_nexthop_set *rins = rule;
  735. struct bgp_info *bgp_info;
  736. struct peer *peer;
  737. if (type == RMAP_BGP)
  738. {
  739. bgp_info = object;
  740. peer = bgp_info->peer;
  741. if (rins->peer_address)
  742. {
  743. if ((CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN) ||
  744. CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT))
  745. && peer->su_remote
  746. && sockunion_family (peer->su_remote) == AF_INET)
  747. {
  748. bgp_info->attr->nexthop.s_addr = sockunion2ip (peer->su_remote);
  749. bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP);
  750. }
  751. else if (CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT)
  752. && peer->su_local
  753. && sockunion_family (peer->su_local) == AF_INET)
  754. {
  755. bgp_info->attr->nexthop.s_addr = sockunion2ip (peer->su_local);
  756. bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP);
  757. }
  758. }
  759. else
  760. {
  761. /* Set next hop value. */
  762. bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP);
  763. bgp_info->attr->nexthop = *rins->address;
  764. }
  765. }
  766. return RMAP_OKAY;
  767. }
  768. /* Route map `ip nexthop' compile function. Given string is converted
  769. to struct in_addr structure. */
  770. static void *
  771. route_set_ip_nexthop_compile (const char *arg)
  772. {
  773. struct rmap_ip_nexthop_set *rins;
  774. struct in_addr *address = NULL;
  775. int peer_address = 0;
  776. int ret;
  777. if (strcmp (arg, "peer-address") == 0)
  778. peer_address = 1;
  779. else
  780. {
  781. address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));
  782. ret = inet_aton (arg, address);
  783. if (ret == 0)
  784. {
  785. XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
  786. return NULL;
  787. }
  788. }
  789. rins = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_ip_nexthop_set));
  790. rins->address = address;
  791. rins->peer_address = peer_address;
  792. return rins;
  793. }
  794. /* Free route map's compiled `ip nexthop' value. */
  795. static void
  796. route_set_ip_nexthop_free (void *rule)
  797. {
  798. struct rmap_ip_nexthop_set *rins = rule;
  799. if (rins->address)
  800. XFREE (MTYPE_ROUTE_MAP_COMPILED, rins->address);
  801. XFREE (MTYPE_ROUTE_MAP_COMPILED, rins);
  802. }
  803. /* Route map commands for ip nexthop set. */
  804. struct route_map_rule_cmd route_set_ip_nexthop_cmd =
  805. {
  806. "ip next-hop",
  807. route_set_ip_nexthop,
  808. route_set_ip_nexthop_compile,
  809. route_set_ip_nexthop_free
  810. };
  811. /* `set local-preference LOCAL_PREF' */
  812. /* Set local preference. */
  813. static route_map_result_t
  814. route_set_local_pref (void *rule, struct prefix *prefix,
  815. route_map_object_t type, void *object)
  816. {
  817. u_int32_t *local_pref;
  818. struct bgp_info *bgp_info;
  819. if (type == RMAP_BGP)
  820. {
  821. /* Fetch routemap's rule information. */
  822. local_pref = rule;
  823. bgp_info = object;
  824. /* Set local preference value. */
  825. bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
  826. bgp_info->attr->local_pref = *local_pref;
  827. }
  828. return RMAP_OKAY;
  829. }
  830. /* set local preference compilation. */
  831. static void *
  832. route_set_local_pref_compile (const char *arg)
  833. {
  834. unsigned long tmp;
  835. u_int32_t *local_pref;
  836. char *endptr = NULL;
  837. /* Local preference value shoud be integer. */
  838. if (! all_digit (arg))
  839. return NULL;
  840. errno = 0;
  841. tmp = strtoul (arg, &endptr, 10);
  842. if (*endptr != '\0' || errno || tmp > UINT32_MAX)
  843. return NULL;
  844. local_pref = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
  845. if (!local_pref)
  846. return local_pref;
  847. *local_pref = tmp;
  848. return local_pref;
  849. }
  850. /* Free route map's local preference value. */
  851. static void
  852. route_set_local_pref_free (void *rule)
  853. {
  854. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  855. }
  856. /* Set local preference rule structure. */
  857. struct route_map_rule_cmd route_set_local_pref_cmd =
  858. {
  859. "local-preference",
  860. route_set_local_pref,
  861. route_set_local_pref_compile,
  862. route_set_local_pref_free,
  863. };
  864. /* `set weight WEIGHT' */
  865. /* Set weight. */
  866. static route_map_result_t
  867. route_set_weight (void *rule, struct prefix *prefix, route_map_object_t type,
  868. void *object)
  869. {
  870. u_int32_t *weight;
  871. struct bgp_info *bgp_info;
  872. if (type == RMAP_BGP)
  873. {
  874. /* Fetch routemap's rule information. */
  875. weight = rule;
  876. bgp_info = object;
  877. /* Set weight value. */
  878. if (*weight)
  879. (bgp_attr_extra_get (bgp_info->attr))->weight = *weight;
  880. else if (bgp_info->attr->extra)
  881. bgp_info->attr->extra->weight = 0;
  882. }
  883. return RMAP_OKAY;
  884. }
  885. /* set local preference compilation. */
  886. static void *
  887. route_set_weight_compile (const char *arg)
  888. {
  889. unsigned long tmp;
  890. u_int32_t *weight;
  891. char *endptr = NULL;
  892. /* Local preference value shoud be integer. */
  893. if (! all_digit (arg))
  894. return NULL;
  895. errno = 0;
  896. tmp = strtoul (arg, &endptr, 10);
  897. if (*endptr != '\0' || errno || tmp > UINT32_MAX)
  898. return NULL;
  899. weight = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
  900. if (weight == NULL)
  901. return weight;
  902. *weight = tmp;
  903. return weight;
  904. }
  905. /* Free route map's local preference value. */
  906. static void
  907. route_set_weight_free (void *rule)
  908. {
  909. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  910. }
  911. /* Set local preference rule structure. */
  912. struct route_map_rule_cmd route_set_weight_cmd =
  913. {
  914. "weight",
  915. route_set_weight,
  916. route_set_weight_compile,
  917. route_set_weight_free,
  918. };
  919. /* `set metric METRIC' */
  920. /* Set metric to attribute. */
  921. static route_map_result_t
  922. route_set_metric (void *rule, struct prefix *prefix,
  923. route_map_object_t type, void *object)
  924. {
  925. char *metric;
  926. u_int32_t metric_val;
  927. struct bgp_info *bgp_info;
  928. if (type == RMAP_BGP)
  929. {
  930. /* Fetch routemap's rule information. */
  931. metric = rule;
  932. bgp_info = object;
  933. if (! (bgp_info->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC)))
  934. bgp_info->attr->med = 0;
  935. bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
  936. if (all_digit (metric))
  937. {
  938. metric_val = strtoul (metric, (char **)NULL, 10);
  939. bgp_info->attr->med = metric_val;
  940. }
  941. else
  942. {
  943. metric_val = strtoul (metric+1, (char **)NULL, 10);
  944. if (strncmp (metric, "+", 1) == 0)
  945. {
  946. if (bgp_info->attr->med/2 + metric_val/2 > BGP_MED_MAX/2)
  947. bgp_info->attr->med = BGP_MED_MAX - 1;
  948. else
  949. bgp_info->attr->med += metric_val;
  950. }
  951. else if (strncmp (metric, "-", 1) == 0)
  952. {
  953. if (bgp_info->attr->med <= metric_val)
  954. bgp_info->attr->med = 0;
  955. else
  956. bgp_info->attr->med -= metric_val;
  957. }
  958. }
  959. }
  960. return RMAP_OKAY;
  961. }
  962. /* set metric compilation. */
  963. static void *
  964. route_set_metric_compile (const char *arg)
  965. {
  966. u_int32_t metric;
  967. unsigned long larg;
  968. char *endptr = NULL;
  969. if (all_digit (arg))
  970. {
  971. /* set metric value check*/
  972. errno = 0;
  973. larg = strtoul (arg, &endptr, 10);
  974. if (*endptr != '\0' || errno || larg > UINT32_MAX)
  975. return NULL;
  976. metric = larg;
  977. }
  978. else
  979. {
  980. /* set metric +/-value check */
  981. if ((strncmp (arg, "+", 1) != 0
  982. && strncmp (arg, "-", 1) != 0)
  983. || (! all_digit (arg+1)))
  984. return NULL;
  985. errno = 0;
  986. larg = strtoul (arg+1, &endptr, 10);
  987. if (*endptr != '\0' || errno || larg > UINT32_MAX)
  988. return NULL;
  989. metric = larg;
  990. }
  991. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  992. }
  993. /* Free route map's compiled `set metric' value. */
  994. static void
  995. route_set_metric_free (void *rule)
  996. {
  997. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  998. }
  999. /* Set metric rule structure. */
  1000. struct route_map_rule_cmd route_set_metric_cmd =
  1001. {
  1002. "metric",
  1003. route_set_metric,
  1004. route_set_metric_compile,
  1005. route_set_metric_free,
  1006. };
  1007. /* `set as-path prepend ASPATH' */
  1008. /* For AS path prepend mechanism. */
  1009. static route_map_result_t
  1010. route_set_aspath_prepend (void *rule, struct prefix *prefix, route_map_object_t type, void *object)
  1011. {
  1012. struct aspath *aspath;
  1013. struct aspath *new;
  1014. struct bgp_info *binfo;
  1015. if (type == RMAP_BGP)
  1016. {
  1017. aspath = rule;
  1018. binfo = object;
  1019. if (binfo->attr->aspath->refcnt)
  1020. new = aspath_dup (binfo->attr->aspath);
  1021. else
  1022. new = binfo->attr->aspath;
  1023. aspath_prepend (aspath, new);
  1024. binfo->attr->aspath = new;
  1025. }
  1026. return RMAP_OKAY;
  1027. }
  1028. /* Compile function for as-path prepend. */
  1029. static void *
  1030. route_set_aspath_prepend_compile (const char *arg)
  1031. {
  1032. struct aspath *aspath;
  1033. aspath = aspath_str2aspath (arg);
  1034. if (! aspath)
  1035. return NULL;
  1036. return aspath;
  1037. }
  1038. /* Compile function for as-path prepend. */
  1039. static void
  1040. route_set_aspath_prepend_free (void *rule)
  1041. {
  1042. struct aspath *aspath = rule;
  1043. aspath_free (aspath);
  1044. }
  1045. /* Set metric rule structure. */
  1046. struct route_map_rule_cmd route_set_aspath_prepend_cmd =
  1047. {
  1048. "as-path prepend",
  1049. route_set_aspath_prepend,
  1050. route_set_aspath_prepend_compile,
  1051. route_set_aspath_prepend_free,
  1052. };
  1053. /* `set as-path exclude ASn' */
  1054. /* For ASN exclude mechanism.
  1055. * Iterate over ASns requested and filter them from the given AS_PATH one by one.
  1056. * Make a deep copy of existing AS_PATH, but for the first ASn only.
  1057. */
  1058. static route_map_result_t
  1059. route_set_aspath_exclude (void *rule, struct prefix *dummy, route_map_object_t type, void *object)
  1060. {
  1061. struct aspath * new_path, * exclude_path;
  1062. struct bgp_info *binfo;
  1063. if (type == RMAP_BGP)
  1064. {
  1065. exclude_path = rule;
  1066. binfo = object;
  1067. if (binfo->attr->aspath->refcnt)
  1068. new_path = aspath_dup (binfo->attr->aspath);
  1069. else
  1070. new_path = binfo->attr->aspath;
  1071. binfo->attr->aspath = aspath_filter_exclude (new_path, exclude_path);
  1072. }
  1073. return RMAP_OKAY;
  1074. }
  1075. /* FIXME: consider using route_set_aspath_prepend_compile() and
  1076. * route_set_aspath_prepend_free(), which two below function are
  1077. * exact clones of.
  1078. */
  1079. /* Compile function for as-path exclude. */
  1080. static void *
  1081. route_set_aspath_exclude_compile (const char *arg)
  1082. {
  1083. struct aspath *aspath;
  1084. aspath = aspath_str2aspath (arg);
  1085. if (! aspath)
  1086. return NULL;
  1087. return aspath;
  1088. }
  1089. static void
  1090. route_set_aspath_exclude_free (void *rule)
  1091. {
  1092. struct aspath *aspath = rule;
  1093. aspath_free (aspath);
  1094. }
  1095. /* Set ASn exlude rule structure. */
  1096. struct route_map_rule_cmd route_set_aspath_exclude_cmd =
  1097. {
  1098. "as-path exclude",
  1099. route_set_aspath_exclude,
  1100. route_set_aspath_exclude_compile,
  1101. route_set_aspath_exclude_free,
  1102. };
  1103. /* `set community COMMUNITY' */
  1104. struct rmap_com_set
  1105. {
  1106. struct community *com;
  1107. int additive;
  1108. int none;
  1109. };
  1110. /* For community set mechanism. */
  1111. static route_map_result_t
  1112. route_set_community (void *rule, struct prefix *prefix,
  1113. route_map_object_t type, void *object)
  1114. {
  1115. struct rmap_com_set *rcs;
  1116. struct bgp_info *binfo;
  1117. struct attr *attr;
  1118. struct community *new = NULL;
  1119. struct community *old;
  1120. struct community *merge;
  1121. if (type == RMAP_BGP)
  1122. {
  1123. rcs = rule;
  1124. binfo = object;
  1125. attr = binfo->attr;
  1126. old = attr->community;
  1127. /* "none" case. */
  1128. if (rcs->none)
  1129. {
  1130. attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES));
  1131. attr->community = NULL;
  1132. /* See the longer comment down below. */
  1133. if (old && old->refcnt == 0)
  1134. community_free(old);
  1135. return RMAP_OKAY;
  1136. }
  1137. /* "additive" case. */
  1138. if (rcs->additive && old)
  1139. {
  1140. merge = community_merge (community_dup (old), rcs->com);
  1141. /* HACK: if the old community is not intern'd,
  1142. * we should free it here, or all reference to it may be lost.
  1143. * Really need to cleanup attribute caching sometime.
  1144. */
  1145. if (old->refcnt == 0)
  1146. community_free (old);
  1147. new = community_uniq_sort (merge);
  1148. community_free (merge);
  1149. }
  1150. else
  1151. new = community_dup (rcs->com);
  1152. /* will be interned by caller if required */
  1153. attr->community = new;
  1154. attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);
  1155. }
  1156. return RMAP_OKAY;
  1157. }
  1158. /* Compile function for set community. */
  1159. static void *
  1160. route_set_community_compile (const char *arg)
  1161. {
  1162. struct rmap_com_set *rcs;
  1163. struct community *com = NULL;
  1164. char *sp;
  1165. int additive = 0;
  1166. int none = 0;
  1167. if (strcmp (arg, "none") == 0)
  1168. none = 1;
  1169. else
  1170. {
  1171. sp = strstr (arg, "additive");
  1172. if (sp && sp > arg)
  1173. {
  1174. /* "additive" keyworkd is included. */
  1175. additive = 1;
  1176. *(sp - 1) = '\0';
  1177. }
  1178. com = community_str2com (arg);
  1179. if (additive)
  1180. *(sp - 1) = ' ';
  1181. if (! com)
  1182. return NULL;
  1183. }
  1184. rcs = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_com_set));
  1185. rcs->com = com;
  1186. rcs->additive = additive;
  1187. rcs->none = none;
  1188. return rcs;
  1189. }
  1190. /* Free function for set community. */
  1191. static void
  1192. route_set_community_free (void *rule)
  1193. {
  1194. struct rmap_com_set *rcs = rule;
  1195. if (rcs->com)
  1196. community_free (rcs->com);
  1197. XFREE (MTYPE_ROUTE_MAP_COMPILED, rcs);
  1198. }
  1199. /* Set community rule structure. */
  1200. struct route_map_rule_cmd route_set_community_cmd =
  1201. {
  1202. "community",
  1203. route_set_community,
  1204. route_set_community_compile,
  1205. route_set_community_free,
  1206. };
  1207. /* `set comm-list (<1-99>|<100-500>|WORD) delete' */
  1208. /* For community set mechanism. */
  1209. static route_map_result_t
  1210. route_set_community_delete (void *rule, struct prefix *prefix,
  1211. route_map_object_t type, void *object)
  1212. {
  1213. struct community_list *list;
  1214. struct community *merge;
  1215. struct community *new;
  1216. struct community *old;
  1217. struct bgp_info *binfo;
  1218. if (type == RMAP_BGP)
  1219. {
  1220. if (! rule)
  1221. return RMAP_OKAY;
  1222. binfo = object;
  1223. list = community_list_lookup (bgp_clist, rule, COMMUNITY_LIST_MASTER);
  1224. old = binfo->attr->community;
  1225. if (list && old)
  1226. {
  1227. merge = community_list_match_delete (community_dup (old), list);
  1228. new = community_uniq_sort (merge);
  1229. community_free (merge);
  1230. /* HACK: if the old community is not intern'd,
  1231. * we should free it here, or all reference to it may be lost.
  1232. * Really need to cleanup attribute caching sometime.
  1233. */
  1234. if (old->refcnt == 0)
  1235. community_free (old);
  1236. if (new->size == 0)
  1237. {
  1238. binfo->attr->community = NULL;
  1239. binfo->attr->flag &= ~ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);
  1240. community_free (new);
  1241. }
  1242. else
  1243. {
  1244. binfo->attr->community = new;
  1245. binfo->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);
  1246. }
  1247. }
  1248. }
  1249. return RMAP_OKAY;
  1250. }
  1251. /* Compile function for set community. */
  1252. static void *
  1253. route_set_community_delete_compile (const char *arg)
  1254. {
  1255. char *p;
  1256. char *str;
  1257. int len;
  1258. p = strchr (arg, ' ');
  1259. if (p)
  1260. {
  1261. len = p - arg;
  1262. str = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, len + 1);
  1263. memcpy (str, arg, len);
  1264. }
  1265. else
  1266. str = NULL;
  1267. return str;
  1268. }
  1269. /* Free function for set community. */
  1270. static void
  1271. route_set_community_delete_free (void *rule)
  1272. {
  1273. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  1274. }
  1275. /* Set community rule structure. */
  1276. struct route_map_rule_cmd route_set_community_delete_cmd =
  1277. {
  1278. "comm-list",
  1279. route_set_community_delete,
  1280. route_set_community_delete_compile,
  1281. route_set_community_delete_free,
  1282. };
  1283. /* `set extcommunity rt COMMUNITY' */
  1284. /* For community set mechanism. */
  1285. static route_map_result_t
  1286. route_set_ecommunity_rt (void *rule, struct prefix *prefix,
  1287. route_map_object_t type, void *object)
  1288. {
  1289. struct ecommunity *ecom;
  1290. struct ecommunity *new_ecom;
  1291. struct ecommunity *old_ecom;
  1292. struct bgp_info *bgp_info;
  1293. if (type == RMAP_BGP)
  1294. {
  1295. ecom = rule;
  1296. bgp_info = object;
  1297. if (! ecom)
  1298. return RMAP_OKAY;
  1299. /* We assume additive for Extended Community. */
  1300. old_ecom = (bgp_attr_extra_get (bgp_info->attr))->ecommunity;
  1301. if (old_ecom)
  1302. new_ecom = ecommunity_merge (ecommunity_dup (old_ecom), ecom);
  1303. else
  1304. new_ecom = ecommunity_dup (ecom);
  1305. bgp_info->attr->extra->ecommunity = ecommunity_intern (new_ecom);
  1306. if (old_ecom)
  1307. ecommunity_unintern (&old_ecom);
  1308. bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES);
  1309. }
  1310. return RMAP_OKAY;
  1311. }
  1312. /* Compile function for set community. */
  1313. static void *
  1314. route_set_ecommunity_rt_compile (const char *arg)
  1315. {
  1316. struct ecommunity *ecom;
  1317. ecom = ecommunity_str2com (arg, ECOMMUNITY_ROUTE_TARGET, 0);
  1318. if (! ecom)
  1319. return NULL;
  1320. return ecommunity_intern (ecom);
  1321. }
  1322. /* Free function for set community. */
  1323. static void
  1324. route_set_ecommunity_rt_free (void *rule)
  1325. {
  1326. struct ecommunity *ecom = rule;
  1327. ecommunity_unintern (&ecom);
  1328. }
  1329. /* Set community rule structure. */
  1330. struct route_map_rule_cmd route_set_ecommunity_rt_cmd =
  1331. {
  1332. "extcommunity rt",
  1333. route_set_ecommunity_rt,
  1334. route_set_ecommunity_rt_compile,
  1335. route_set_ecommunity_rt_free,
  1336. };
  1337. /* `set extcommunity soo COMMUNITY' */
  1338. /* For community set mechanism. */
  1339. static route_map_result_t
  1340. route_set_ecommunity_soo (void *rule, struct prefix *prefix,
  1341. route_map_object_t type, void *object)
  1342. {
  1343. struct ecommunity *ecom, *old_ecom, *new_ecom;
  1344. struct bgp_info *bgp_info;
  1345. if (type == RMAP_BGP)
  1346. {
  1347. ecom = rule;
  1348. bgp_info = object;
  1349. if (! ecom)
  1350. return RMAP_OKAY;
  1351. old_ecom = (bgp_attr_extra_get (bgp_info->attr))->ecommunity;
  1352. if (old_ecom)
  1353. new_ecom = ecommunity_merge (ecommunity_dup (old_ecom), ecom);
  1354. else
  1355. new_ecom = ecommunity_dup (ecom);
  1356. bgp_info->attr->extra->ecommunity = ecommunity_intern (new_ecom);
  1357. if (old_ecom)
  1358. ecommunity_unintern (&old_ecom);
  1359. bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES);
  1360. }
  1361. return RMAP_OKAY;
  1362. }
  1363. /* Compile function for set community. */
  1364. static void *
  1365. route_set_ecommunity_soo_compile (const char *arg)
  1366. {
  1367. struct ecommunity *ecom;
  1368. ecom = ecommunity_str2com (arg, ECOMMUNITY_SITE_ORIGIN, 0);
  1369. if (! ecom)
  1370. return NULL;
  1371. return ecommunity_intern (ecom);
  1372. }
  1373. /* Free function for set community. */
  1374. static void
  1375. route_set_ecommunity_soo_free (void *rule)
  1376. {
  1377. struct ecommunity *ecom = rule;
  1378. ecommunity_unintern (&ecom);
  1379. }
  1380. /* Set community rule structure. */
  1381. struct route_map_rule_cmd route_set_ecommunity_soo_cmd =
  1382. {
  1383. "extcommunity soo",
  1384. route_set_ecommunity_soo,
  1385. route_set_ecommunity_soo_compile,
  1386. route_set_ecommunity_soo_free,
  1387. };
  1388. /* `set origin ORIGIN' */
  1389. /* For origin set. */
  1390. static route_map_result_t
  1391. route_set_origin (void *rule, struct prefix *prefix, route_map_object_t type, void *object)
  1392. {
  1393. u_char *origin;
  1394. struct bgp_info *bgp_info;
  1395. if (type == RMAP_BGP)
  1396. {
  1397. origin = rule;
  1398. bgp_info = object;
  1399. bgp_info->attr->origin = *origin;
  1400. }
  1401. return RMAP_OKAY;
  1402. }
  1403. /* Compile function for origin set. */
  1404. static void *
  1405. route_set_origin_compile (const char *arg)
  1406. {
  1407. u_char *origin;
  1408. origin = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_char));
  1409. if (strcmp (arg, "igp") == 0)
  1410. *origin = 0;
  1411. else if (strcmp (arg, "egp") == 0)
  1412. *origin = 1;
  1413. else
  1414. *origin = 2;
  1415. return origin;
  1416. }
  1417. /* Compile function for origin set. */
  1418. static void
  1419. route_set_origin_free (void *rule)
  1420. {
  1421. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  1422. }
  1423. /* Set metric rule structure. */
  1424. struct route_map_rule_cmd route_set_origin_cmd =
  1425. {
  1426. "origin",
  1427. route_set_origin,
  1428. route_set_origin_compile,
  1429. route_set_origin_free,
  1430. };
  1431. /* `set atomic-aggregate' */
  1432. /* For atomic aggregate set. */
  1433. static route_map_result_t
  1434. route_set_atomic_aggregate (void *rule, struct prefix *prefix,
  1435. route_map_object_t type, void *object)
  1436. {
  1437. struct bgp_info *bgp_info;
  1438. if (type == RMAP_BGP)
  1439. {
  1440. bgp_info = object;
  1441. bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
  1442. }
  1443. return RMAP_OKAY;
  1444. }
  1445. /* Compile function for atomic aggregate. */
  1446. static void *
  1447. route_set_atomic_aggregate_compile (const char *arg)
  1448. {
  1449. return (void *)1;
  1450. }
  1451. /* Compile function for atomic aggregate. */
  1452. static void
  1453. route_set_atomic_aggregate_free (void *rule)
  1454. {
  1455. return;
  1456. }
  1457. /* Set atomic aggregate rule structure. */
  1458. struct route_map_rule_cmd route_set_atomic_aggregate_cmd =
  1459. {
  1460. "atomic-aggregate",
  1461. route_set_atomic_aggregate,
  1462. route_set_atomic_aggregate_compile,
  1463. route_set_atomic_aggregate_free,
  1464. };
  1465. /* `set aggregator as AS A.B.C.D' */
  1466. struct aggregator
  1467. {
  1468. as_t as;
  1469. struct in_addr address;
  1470. };
  1471. static route_map_result_t
  1472. route_set_aggregator_as (void *rule, struct prefix *prefix,
  1473. route_map_object_t type, void *object)
  1474. {
  1475. struct bgp_info *bgp_info;
  1476. struct aggregator *aggregator;
  1477. struct attr_extra *ae;
  1478. if (type == RMAP_BGP)
  1479. {
  1480. bgp_info = object;
  1481. aggregator = rule;
  1482. ae = bgp_attr_extra_get (bgp_info->attr);
  1483. ae->aggregator_as = aggregator->as;
  1484. ae->aggregator_addr = aggregator->address;
  1485. bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR);
  1486. }
  1487. return RMAP_OKAY;
  1488. }
  1489. static void *
  1490. route_set_aggregator_as_compile (const char *arg)
  1491. {
  1492. struct aggregator *aggregator;
  1493. char as[10];
  1494. char address[20];
  1495. aggregator = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct aggregator));
  1496. sscanf (arg, "%s %s", as, address);
  1497. aggregator->as = strtoul (as, NULL, 10);
  1498. inet_aton (address, &aggregator->address);
  1499. return aggregator;
  1500. }
  1501. static void
  1502. route_set_aggregator_as_free (void *rule)
  1503. {
  1504. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  1505. }
  1506. struct route_map_rule_cmd route_set_aggregator_as_cmd =
  1507. {
  1508. "aggregator as",
  1509. route_set_aggregator_as,
  1510. route_set_aggregator_as_compile,
  1511. route_set_aggregator_as_free,
  1512. };
  1513. #ifdef HAVE_IPV6
  1514. /* `match ipv6 address IP_ACCESS_LIST' */
  1515. static route_map_result_t
  1516. route_match_ipv6_address (void *rule, struct prefix *prefix,
  1517. route_map_object_t type, void *object)
  1518. {
  1519. struct access_list *alist;
  1520. if (type == RMAP_BGP)
  1521. {
  1522. alist = access_list_lookup (AFI_IP6, (char *) rule);
  1523. if (alist == NULL)
  1524. return RMAP_NOMATCH;
  1525. return (access_list_apply (alist, prefix) == FILTER_DENY ?
  1526. RMAP_NOMATCH : RMAP_MATCH);
  1527. }
  1528. return RMAP_NOMATCH;
  1529. }
  1530. static void *
  1531. route_match_ipv6_address_compile (const char *arg)
  1532. {
  1533. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  1534. }
  1535. static void
  1536. route_match_ipv6_address_free (void *rule)
  1537. {
  1538. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  1539. }
  1540. /* Route map commands for ip address matching. */
  1541. struct route_map_rule_cmd route_match_ipv6_address_cmd =
  1542. {
  1543. "ipv6 address",
  1544. route_match_ipv6_address,
  1545. route_match_ipv6_address_compile,
  1546. route_match_ipv6_address_free
  1547. };
  1548. /* `match ipv6 next-hop IP_ADDRESS' */
  1549. static route_map_result_t
  1550. route_match_ipv6_next_hop (void *rule, struct prefix *prefix,
  1551. route_map_object_t type, void *object)
  1552. {
  1553. struct in6_addr *addr;
  1554. struct bgp_info *bgp_info;
  1555. if (type == RMAP_BGP)
  1556. {
  1557. addr = rule;
  1558. bgp_info = object;
  1559. if (!bgp_info->attr->extra)
  1560. return RMAP_NOMATCH;
  1561. if (IPV6_ADDR_SAME (&bgp_info->attr->extra->mp_nexthop_global, rule))
  1562. return RMAP_MATCH;
  1563. if (bgp_info->attr->extra->mp_nexthop_len == 32 &&
  1564. IPV6_ADDR_SAME (&bgp_info->attr->extra->mp_nexthop_local, rule))
  1565. return RMAP_MATCH;
  1566. return RMAP_NOMATCH;
  1567. }
  1568. return RMAP_NOMATCH;
  1569. }
  1570. static void *
  1571. route_match_ipv6_next_hop_compile (const char *arg)
  1572. {
  1573. struct in6_addr *address;
  1574. int ret;
  1575. address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr));
  1576. ret = inet_pton (AF_INET6, arg, address);
  1577. if (!ret)
  1578. {
  1579. XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
  1580. return NULL;
  1581. }
  1582. return address;
  1583. }
  1584. static void
  1585. route_match_ipv6_next_hop_free (void *rule)
  1586. {
  1587. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  1588. }
  1589. struct route_map_rule_cmd route_match_ipv6_next_hop_cmd =
  1590. {
  1591. "ipv6 next-hop",
  1592. route_match_ipv6_next_hop,
  1593. route_match_ipv6_next_hop_compile,
  1594. route_match_ipv6_next_hop_free
  1595. };
  1596. /* `match ipv6 address prefix-list PREFIX_LIST' */
  1597. static route_map_result_t
  1598. route_match_ipv6_address_prefix_list (void *rule, struct prefix *prefix,
  1599. route_map_object_t type, void *object)
  1600. {
  1601. struct prefix_list *plist;
  1602. if (type == RMAP_BGP)
  1603. {
  1604. plist = prefix_list_lookup (AFI_IP6, (char *) rule);
  1605. if (plist == NULL)
  1606. return RMAP_NOMATCH;
  1607. return (prefix_list_apply (plist, prefix) == PREFIX_DENY ?
  1608. RMAP_NOMATCH : RMAP_MATCH);
  1609. }
  1610. return RMAP_NOMATCH;
  1611. }
  1612. static void *
  1613. route_match_ipv6_address_prefix_list_compile (const char *arg)
  1614. {
  1615. return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  1616. }
  1617. static void
  1618. route_match_ipv6_address_prefix_list_free (void *rule)
  1619. {
  1620. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  1621. }
  1622. struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd =
  1623. {
  1624. "ipv6 address prefix-list",
  1625. route_match_ipv6_address_prefix_list,
  1626. route_match_ipv6_address_prefix_list_compile,
  1627. route_match_ipv6_address_prefix_list_free
  1628. };
  1629. /* `set ipv6 nexthop global IP_ADDRESS' */
  1630. /* Set nexthop to object. ojbect must be pointer to struct attr. */
  1631. static route_map_result_t
  1632. route_set_ipv6_nexthop_global (void *rule, struct prefix *prefix,
  1633. route_map_object_t type, void *object)
  1634. {
  1635. struct in6_addr *address;
  1636. struct bgp_info *bgp_info;
  1637. if (type == RMAP_BGP)
  1638. {
  1639. /* Fetch routemap's rule information. */
  1640. address = rule;
  1641. bgp_info = object;
  1642. /* Set next hop value. */
  1643. (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_global = *address;
  1644. /* Set nexthop length. */
  1645. if (bgp_info->attr->extra->mp_nexthop_len == 0)
  1646. bgp_info->attr->extra->mp_nexthop_len = 16;
  1647. }
  1648. return RMAP_OKAY;
  1649. }
  1650. /* Route map `ip next-hop' compile function. Given string is converted
  1651. to struct in_addr structure. */
  1652. static void *
  1653. route_set_ipv6_nexthop_global_compile (const char *arg)
  1654. {
  1655. int ret;
  1656. struct in6_addr *address;
  1657. address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr));
  1658. ret = inet_pton (AF_INET6, arg, address);
  1659. if (ret == 0)
  1660. {
  1661. XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
  1662. return NULL;
  1663. }
  1664. return address;
  1665. }
  1666. /* Free route map's compiled `ip next-hop' value. */
  1667. static void
  1668. route_set_ipv6_nexthop_global_free (void *rule)
  1669. {
  1670. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  1671. }
  1672. /* Route map commands for ip nexthop set. */
  1673. struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd =
  1674. {
  1675. "ipv6 next-hop global",
  1676. route_set_ipv6_nexthop_global,
  1677. route_set_ipv6_nexthop_global_compile,
  1678. route_set_ipv6_nexthop_global_free
  1679. };
  1680. /* `set ipv6 nexthop local IP_ADDRESS' */
  1681. /* Set nexthop to object. ojbect must be pointer to struct attr. */
  1682. static route_map_result_t
  1683. route_set_ipv6_nexthop_local (void *rule, struct prefix *prefix,
  1684. route_map_object_t type, void *object)
  1685. {
  1686. struct in6_addr *address;
  1687. struct bgp_info *bgp_info;
  1688. if (type == RMAP_BGP)
  1689. {
  1690. /* Fetch routemap's rule information. */
  1691. address = rule;
  1692. bgp_info = object;
  1693. /* Set next hop value. */
  1694. (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_local = *address;
  1695. /* Set nexthop length. */
  1696. if (bgp_info->attr->extra->mp_nexthop_len != 32)
  1697. bgp_info->attr->extra->mp_nexthop_len = 32;
  1698. }
  1699. return RMAP_OKAY;
  1700. }
  1701. /* Route map `ip nexthop' compile function. Given string is converted
  1702. to struct in_addr structure. */
  1703. static void *
  1704. route_set_ipv6_nexthop_local_compile (const char *arg)
  1705. {
  1706. int ret;
  1707. struct in6_addr *address;
  1708. address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr));
  1709. ret = inet_pton (AF_INET6, arg, address);
  1710. if (ret == 0)
  1711. {
  1712. XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
  1713. return NULL;
  1714. }
  1715. return address;
  1716. }
  1717. /* Free route map's compiled `ip nexthop' value. */
  1718. static void
  1719. route_set_ipv6_nexthop_local_free (void *rule)
  1720. {
  1721. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  1722. }
  1723. /* Route map commands for ip nexthop set. */
  1724. struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd =
  1725. {
  1726. "ipv6 next-hop local",
  1727. route_set_ipv6_nexthop_local,
  1728. route_set_ipv6_nexthop_local_compile,
  1729. route_set_ipv6_nexthop_local_free
  1730. };
  1731. #endif /* HAVE_IPV6 */
  1732. /* `set vpnv4 nexthop A.B.C.D' */
  1733. static route_map_result_t
  1734. route_set_vpnv4_nexthop (void *rule, struct prefix *prefix,
  1735. route_map_object_t type, void *object)
  1736. {
  1737. struct in_addr *address;
  1738. struct bgp_info *bgp_info;
  1739. if (type == RMAP_BGP)
  1740. {
  1741. /* Fetch routemap's rule information. */
  1742. address = rule;
  1743. bgp_info = object;
  1744. /* Set next hop value. */
  1745. (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_global_in = *address;
  1746. }
  1747. return RMAP_OKAY;
  1748. }
  1749. static void *
  1750. route_set_vpnv4_nexthop_compile (const char *arg)
  1751. {
  1752. int ret;
  1753. struct in_addr *address;
  1754. address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));
  1755. ret = inet_aton (arg, address);
  1756. if (ret == 0)
  1757. {
  1758. XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
  1759. return NULL;
  1760. }
  1761. return address;
  1762. }
  1763. static void
  1764. route_set_vpnv4_nexthop_free (void *rule)
  1765. {
  1766. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  1767. }
  1768. /* Route map commands for ip nexthop set. */
  1769. struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd =
  1770. {
  1771. "vpnv4 next-hop",
  1772. route_set_vpnv4_nexthop,
  1773. route_set_vpnv4_nexthop_compile,
  1774. route_set_vpnv4_nexthop_free
  1775. };
  1776. /* `set originator-id' */
  1777. /* For origin set. */
  1778. static route_map_result_t
  1779. route_set_originator_id (void *rule, struct prefix *prefix, route_map_object_t type, void *object)
  1780. {
  1781. struct in_addr *address;
  1782. struct bgp_info *bgp_info;
  1783. if (type == RMAP_BGP)
  1784. {
  1785. address = rule;
  1786. bgp_info = object;
  1787. bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID);
  1788. (bgp_attr_extra_get (bgp_info->attr))->originator_id = *address;
  1789. }
  1790. return RMAP_OKAY;
  1791. }
  1792. /* Compile function for originator-id set. */
  1793. static void *
  1794. route_set_originator_id_compile (const char *arg)
  1795. {
  1796. int ret;
  1797. struct in_addr *address;
  1798. address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));
  1799. ret = inet_aton (arg, address);
  1800. if (ret == 0)
  1801. {
  1802. XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
  1803. return NULL;
  1804. }
  1805. return address;
  1806. }
  1807. /* Compile function for originator_id set. */
  1808. static void
  1809. route_set_originator_id_free (void *rule)
  1810. {
  1811. XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  1812. }
  1813. /* Set metric rule structure. */
  1814. struct route_map_rule_cmd route_set_originator_id_cmd =
  1815. {
  1816. "originator-id",
  1817. route_set_originator_id,
  1818. route_set_originator_id_compile,
  1819. route_set_originator_id_free,
  1820. };
  1821. /* Add bgp route map rule. */
  1822. static int
  1823. bgp_route_match_add (struct vty *vty, struct route_map_index *index,
  1824. const char *command, const char *arg)
  1825. {
  1826. int ret;
  1827. ret = route_map_add_match (index, command, arg);
  1828. if (ret)
  1829. {
  1830. switch (ret)
  1831. {
  1832. case RMAP_RULE_MISSING:
  1833. vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
  1834. return CMD_WARNING;
  1835. case RMAP_COMPILE_ERROR:
  1836. vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
  1837. return CMD_WARNING;
  1838. }
  1839. }
  1840. return CMD_SUCCESS;
  1841. }
  1842. /* Delete bgp route map rule. */
  1843. static int
  1844. bgp_route_match_delete (struct vty *vty, struct route_map_index *index,
  1845. const char *command, const char *arg)
  1846. {
  1847. int ret;
  1848. ret = route_map_delete_match (index, command, arg);
  1849. if (ret)
  1850. {
  1851. switch (ret)
  1852. {
  1853. case RMAP_RULE_MISSING:
  1854. vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
  1855. return CMD_WARNING;
  1856. case RMAP_COMPILE_ERROR:
  1857. vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
  1858. return CMD_WARNING;
  1859. }
  1860. }
  1861. return CMD_SUCCESS;
  1862. }
  1863. /* Add bgp route map rule. */
  1864. static int
  1865. bgp_route_set_add (struct vty *vty, struct route_map_index *index,
  1866. const char *command, const char *arg)
  1867. {
  1868. int ret;
  1869. ret = route_map_add_set (index, command, arg);
  1870. if (ret)
  1871. {
  1872. switch (ret)
  1873. {
  1874. case RMAP_RULE_MISSING:
  1875. vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
  1876. return CMD_WARNING;
  1877. case RMAP_COMPILE_ERROR:
  1878. vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
  1879. return CMD_WARNING;
  1880. }
  1881. }
  1882. return CMD_SUCCESS;
  1883. }
  1884. /* Delete bgp route map rule. */
  1885. static int
  1886. bgp_route_set_delete (struct vty *vty, struct route_map_index *index,
  1887. const char *command, const char *arg)
  1888. {
  1889. int ret;
  1890. ret = route_map_delete_set (index, command, arg);
  1891. if (ret)
  1892. {
  1893. switch (ret)
  1894. {
  1895. case RMAP_RULE_MISSING:
  1896. vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
  1897. return CMD_WARNING;
  1898. case RMAP_COMPILE_ERROR:
  1899. vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
  1900. return CMD_WARNING;
  1901. }
  1902. }
  1903. return CMD_SUCCESS;
  1904. }
  1905. /* Hook function for updating route_map assignment. */
  1906. static void
  1907. bgp_route_map_update (const char *unused)
  1908. {
  1909. int i;
  1910. afi_t afi;
  1911. safi_t safi;
  1912. int direct;
  1913. struct listnode *node, *nnode;
  1914. struct listnode *mnode, *mnnode;
  1915. struct bgp *bgp;
  1916. struct peer *peer;
  1917. struct peer_group *group;
  1918. struct bgp_filter *filter;
  1919. struct bgp_node *bn;
  1920. struct bgp_static *bgp_static;
  1921. /* For neighbor route-map updates. */
  1922. for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
  1923. {
  1924. for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
  1925. {
  1926. for (afi = AFI_IP; afi < AFI_MAX; afi++)
  1927. for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
  1928. {
  1929. filter = &peer->filter[afi][safi];
  1930. for (direct = RMAP_IN; direct < RMAP_MAX; direct++)
  1931. {
  1932. if (filter->map[direct].name)
  1933. filter->map[direct].map =
  1934. route_map_lookup_by_name (filter->map[direct].name);
  1935. else
  1936. filter->map[direct].map = NULL;
  1937. }
  1938. if (filter->usmap.name)
  1939. filter->usmap.map = route_map_lookup_by_name (filter->usmap.name);
  1940. else
  1941. filter->usmap.map = NULL;
  1942. }
  1943. }
  1944. for (ALL_LIST_ELEMENTS (bgp->group, node, nnode, group))
  1945. {
  1946. for (afi = AFI_IP; afi < AFI_MAX; afi++)
  1947. for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
  1948. {
  1949. filter = &group->conf->filter[afi][safi];
  1950. for (direct = RMAP_IN; direct < RMAP_MAX; direct++)
  1951. {
  1952. if (filter->map[direct].name)
  1953. filter->map[direct].map =
  1954. route_map_lookup_by_name (filter->map[direct].name);
  1955. else
  1956. filter->map[direct].map = NULL;
  1957. }
  1958. if (filter->usmap.name)
  1959. filter->usmap.map = route_map_lookup_by_name (filter->usmap.name);
  1960. else
  1961. filter->usmap.map = NULL;
  1962. }
  1963. }
  1964. }
  1965. /* For default-originate route-map updates. */
  1966. for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
  1967. {
  1968. for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
  1969. {
  1970. for (afi = AFI_IP; afi < AFI_MAX; afi++)
  1971. for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
  1972. {
  1973. if (peer->default_rmap[afi][safi].name)
  1974. peer->default_rmap[afi][safi].map =
  1975. route_map_lookup_by_name (peer->default_rmap[afi][safi].name);
  1976. else
  1977. peer->default_rmap[afi][safi].map = NULL;
  1978. }
  1979. }
  1980. }
  1981. /* For network route-map updates. */
  1982. for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
  1983. {
  1984. for (afi = AFI_IP; afi < AFI_MAX; afi++)
  1985. for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
  1986. for (bn = bgp_table_top (bgp->route[afi][safi]); bn;
  1987. bn = bgp_route_next (bn))
  1988. if ((bgp_static = bn->info) != NULL)
  1989. {
  1990. if (bgp_static->rmap.name)
  1991. bgp_static->rmap.map =
  1992. route_map_lookup_by_name (bgp_static->rmap.name);
  1993. else
  1994. bgp_static->rmap.map = NULL;
  1995. }
  1996. }
  1997. /* For redistribute route-map updates. */
  1998. for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
  1999. {
  2000. for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
  2001. {
  2002. if (bgp->rmap[ZEBRA_FAMILY_IPV4][i].name)
  2003. bgp->rmap[ZEBRA_FAMILY_IPV4][i].map =
  2004. route_map_lookup_by_name (bgp->rmap[ZEBRA_FAMILY_IPV4][i].name);
  2005. #ifdef HAVE_IPV6
  2006. if (bgp->rmap[ZEBRA_FAMILY_IPV6][i].name)
  2007. bgp->rmap[ZEBRA_FAMILY_IPV6][i].map =
  2008. route_map_lookup_by_name (bgp->rmap[ZEBRA_FAMILY_IPV6][i].name);
  2009. #endif /* HAVE_IPV6 */
  2010. }
  2011. }
  2012. }
  2013. DEFUN (match_peer,
  2014. match_peer_cmd,
  2015. "match peer (A.B.C.D|X:X::X:X)",
  2016. MATCH_STR
  2017. "Match peer address\n"
  2018. "IPv6 address of peer\n"
  2019. "IP address of peer\n")
  2020. {
  2021. return bgp_route_match_add (vty, vty->index, "peer", argv[0]);
  2022. }
  2023. DEFUN (match_peer_local,
  2024. match_peer_local_cmd,
  2025. "match peer local",
  2026. MATCH_STR
  2027. "Match peer address\n"
  2028. "Static or Redistributed routes\n")
  2029. {
  2030. return bgp_route_match_add (vty, vty->index, "peer", "local");
  2031. }
  2032. DEFUN (no_match_peer,
  2033. no_match_peer_cmd,
  2034. "no match peer",
  2035. NO_STR
  2036. MATCH_STR
  2037. "Match peer address\n")
  2038. {
  2039. if (argc == 0)
  2040. return bgp_route_match_delete (vty, vty->index, "peer", NULL);
  2041. return bgp_route_match_delete (vty, vty->index, "peer", argv[0]);
  2042. }
  2043. ALIAS (no_match_peer,
  2044. no_match_peer_val_cmd,
  2045. "no match peer (A.B.C.D|X:X::X:X)",
  2046. NO_STR
  2047. MATCH_STR
  2048. "Match peer address\n"
  2049. "IPv6 address of peer\n"
  2050. "IP address of peer\n")
  2051. ALIAS (no_match_peer,
  2052. no_match_peer_local_cmd,
  2053. "no match peer local",
  2054. NO_STR
  2055. MATCH_STR
  2056. "Match peer address\n"
  2057. "Static or Redistributed routes\n")
  2058. DEFUN (match_ip_address,
  2059. match_ip_address_cmd,
  2060. "match ip address (<1-199>|<1300-2699>|WORD)",
  2061. MATCH_STR
  2062. IP_STR
  2063. "Match address of route\n"
  2064. "IP access-list number\n"
  2065. "IP access-list number (expanded range)\n"
  2066. "IP Access-list name\n")
  2067. {
  2068. return bgp_route_match_add (vty, vty->index, "ip address", argv[0]);
  2069. }
  2070. DEFUN (no_match_ip_address,
  2071. no_match_ip_address_cmd,
  2072. "no match ip address",
  2073. NO_STR
  2074. MATCH_STR
  2075. IP_STR
  2076. "Match address of route\n")
  2077. {
  2078. if (argc == 0)
  2079. return bgp_route_match_delete (vty, vty->index, "ip address", NULL);
  2080. return bgp_route_match_delete (vty, vty->index, "ip address", argv[0]);
  2081. }
  2082. ALIAS (no_match_ip_address,
  2083. no_match_ip_address_val_cmd,
  2084. "no match ip address (<1-199>|<1300-2699>|WORD)",
  2085. NO_STR
  2086. MATCH_STR
  2087. IP_STR
  2088. "Match address of route\n"
  2089. "IP access-list number\n"
  2090. "IP access-list number (expanded range)\n"
  2091. "IP Access-list name\n")
  2092. DEFUN (match_ip_next_hop,
  2093. match_ip_next_hop_cmd,
  2094. "match ip next-hop (<1-199>|<1300-2699>|WORD)",
  2095. MATCH_STR
  2096. IP_STR
  2097. "Match next-hop address of route\n"
  2098. "IP access-list number\n"
  2099. "IP access-list number (expanded range)\n"
  2100. "IP Access-list name\n")
  2101. {
  2102. return bgp_route_match_add (vty, vty->index, "ip next-hop", argv[0]);
  2103. }
  2104. DEFUN (no_match_ip_next_hop,
  2105. no_match_ip_next_hop_cmd,
  2106. "no match ip next-hop",
  2107. NO_STR
  2108. MATCH_STR
  2109. IP_STR
  2110. "Match next-hop address of route\n")
  2111. {
  2112. if (argc == 0)
  2113. return bgp_route_match_delete (vty, vty->index, "ip next-hop", NULL);
  2114. return bgp_route_match_delete (vty, vty->index, "ip next-hop", argv[0]);
  2115. }
  2116. ALIAS (no_match_ip_next_hop,
  2117. no_match_ip_next_hop_val_cmd,
  2118. "no match ip next-hop (<1-199>|<1300-2699>|WORD)",
  2119. NO_STR
  2120. MATCH_STR
  2121. IP_STR
  2122. "Match next-hop address of route\n"
  2123. "IP access-list number\n"
  2124. "IP access-list number (expanded range)\n"
  2125. "IP Access-list name\n")
  2126. /* match probability { */
  2127. DEFUN (match_probability,
  2128. match_probability_cmd,
  2129. "match probability <0-100>",
  2130. MATCH_STR
  2131. "Match portion of routes defined by percentage value\n"
  2132. "Percentage of routes\n")
  2133. {
  2134. return bgp_route_match_add (vty, vty->index, "probability", argv[0]);
  2135. }
  2136. DEFUN (no_match_probability,
  2137. no_match_probability_cmd,
  2138. "no match probability",
  2139. NO_STR
  2140. MATCH_STR
  2141. "Match portion of routes defined by percentage value\n")
  2142. {
  2143. return bgp_route_match_delete (vty, vty->index, "probability", argc ? argv[0] : NULL);
  2144. }
  2145. ALIAS (no_match_probability,
  2146. no_match_probability_val_cmd,
  2147. "no match probability <1-99>",
  2148. NO_STR
  2149. MATCH_STR
  2150. "Match portion of routes defined by percentage value\n"
  2151. "Percentage of routes\n")
  2152. /* } */
  2153. DEFUN (match_ip_route_source,
  2154. match_ip_route_source_cmd,
  2155. "match ip route-source (<1-199>|<1300-2699>|WORD)",
  2156. MATCH_STR
  2157. IP_STR
  2158. "Match advertising source address of route\n"
  2159. "IP access-list number\n"
  2160. "IP access-list number (expanded range)\n"
  2161. "IP standard access-list name\n")
  2162. {
  2163. return bgp_route_match_add (vty, vty->index, "ip route-source", argv[0]);
  2164. }
  2165. DEFUN (no_match_ip_route_source,
  2166. no_match_ip_route_source_cmd,
  2167. "no match ip route-source",
  2168. NO_STR
  2169. MATCH_STR
  2170. IP_STR
  2171. "Match advertising source address of route\n")
  2172. {
  2173. if (argc == 0)
  2174. return bgp_route_match_delete (vty, vty->index, "ip route-source", NULL);
  2175. return bgp_route_match_delete (vty, vty->index, "ip route-source", argv[0]);
  2176. }
  2177. ALIAS (no_match_ip_route_source,
  2178. no_match_ip_route_source_val_cmd,
  2179. "no match ip route-source (<1-199>|<1300-2699>|WORD)",
  2180. NO_STR
  2181. MATCH_STR
  2182. IP_STR
  2183. "Match advertising source address of route\n"
  2184. "IP access-list number\n"
  2185. "IP access-list number (expanded range)\n"
  2186. "IP standard access-list name\n")
  2187. DEFUN (match_ip_address_prefix_list,
  2188. match_ip_address_prefix_list_cmd,
  2189. "match ip address prefix-list WORD",
  2190. MATCH_STR
  2191. IP_STR
  2192. "Match address of route\n"
  2193. "Match entries of prefix-lists\n"
  2194. "IP prefix-list name\n")
  2195. {
  2196. return bgp_route_match_add (vty, vty->index, "ip address prefix-list", argv[0]);
  2197. }
  2198. DEFUN (no_match_ip_address_prefix_list,
  2199. no_match_ip_address_prefix_list_cmd,
  2200. "no match ip address prefix-list",
  2201. NO_STR
  2202. MATCH_STR
  2203. IP_STR
  2204. "Match address of route\n"
  2205. "Match entries of prefix-lists\n")
  2206. {
  2207. if (argc == 0)
  2208. return bgp_route_match_delete (vty, vty->index, "ip address prefix-list", NULL);
  2209. return bgp_route_match_delete (vty, vty->index, "ip address prefix-list", argv[0]);
  2210. }
  2211. ALIAS (no_match_ip_address_prefix_list,
  2212. no_match_ip_address_prefix_list_val_cmd,
  2213. "no match ip address prefix-list WORD",
  2214. NO_STR
  2215. MATCH_STR
  2216. IP_STR
  2217. "Match address of route\n"
  2218. "Match entries of prefix-lists\n"
  2219. "IP prefix-list name\n")
  2220. DEFUN (match_ip_next_hop_prefix_list,
  2221. match_ip_next_hop_prefix_list_cmd,
  2222. "match ip next-hop prefix-list WORD",
  2223. MATCH_STR
  2224. IP_STR
  2225. "Match next-hop address of route\n"
  2226. "Match entries of prefix-lists\n"
  2227. "IP prefix-list name\n")
  2228. {
  2229. return bgp_route_match_add (vty, vty->index, "ip next-hop prefix-list", argv[0]);
  2230. }
  2231. DEFUN (no_match_ip_next_hop_prefix_list,
  2232. no_match_ip_next_hop_prefix_list_cmd,
  2233. "no match ip next-hop prefix-list",
  2234. NO_STR
  2235. MATCH_STR
  2236. IP_STR
  2237. "Match next-hop address of route\n"
  2238. "Match entries of prefix-lists\n")
  2239. {
  2240. if (argc == 0)
  2241. return bgp_route_match_delete (vty, vty->index, "ip next-hop prefix-list", NULL);
  2242. return bgp_route_match_delete (vty, vty->index, "ip next-hop prefix-list", argv[0]);
  2243. }
  2244. ALIAS (no_match_ip_next_hop_prefix_list,
  2245. no_match_ip_next_hop_prefix_list_val_cmd,
  2246. "no match ip next-hop prefix-list WORD",
  2247. NO_STR
  2248. MATCH_STR
  2249. IP_STR
  2250. "Match next-hop address of route\n"
  2251. "Match entries of prefix-lists\n"
  2252. "IP prefix-list name\n")
  2253. DEFUN (match_ip_route_source_prefix_list,
  2254. match_ip_route_source_prefix_list_cmd,
  2255. "match ip route-source prefix-list WORD",
  2256. MATCH_STR
  2257. IP_STR
  2258. "Match advertising source address of route\n"
  2259. "Match entries of prefix-lists\n"
  2260. "IP prefix-list name\n")
  2261. {
  2262. return bgp_route_match_add (vty, vty->index, "ip route-source prefix-list", argv[0]);
  2263. }
  2264. DEFUN (no_match_ip_route_source_prefix_list,
  2265. no_match_ip_route_source_prefix_list_cmd,
  2266. "no match ip route-source prefix-list",
  2267. NO_STR
  2268. MATCH_STR
  2269. IP_STR
  2270. "Match advertising source address of route\n"
  2271. "Match entries of prefix-lists\n")
  2272. {
  2273. if (argc == 0)
  2274. return bgp_route_match_delete (vty, vty->index, "ip route-source prefix-list", NULL);
  2275. return bgp_route_match_delete (vty, vty->index, "ip route-source prefix-list", argv[0]);
  2276. }
  2277. ALIAS (no_match_ip_route_source_prefix_list,
  2278. no_match_ip_route_source_prefix_list_val_cmd,
  2279. "no match ip route-source prefix-list WORD",
  2280. NO_STR
  2281. MATCH_STR
  2282. IP_STR
  2283. "Match advertising source address of route\n"
  2284. "Match entries of prefix-lists\n"
  2285. "IP prefix-list name\n")
  2286. DEFUN (match_metric,
  2287. match_metric_cmd,
  2288. "match metric <0-4294967295>",
  2289. MATCH_STR
  2290. "Match metric of route\n"
  2291. "Metric value\n")
  2292. {
  2293. return bgp_route_match_add (vty, vty->index, "metric", argv[0]);
  2294. }
  2295. DEFUN (no_match_metric,
  2296. no_match_metric_cmd,
  2297. "no match metric",
  2298. NO_STR
  2299. MATCH_STR
  2300. "Match metric of route\n")
  2301. {
  2302. if (argc == 0)
  2303. return bgp_route_match_delete (vty, vty->index, "metric", NULL);
  2304. return bgp_route_match_delete (vty, vty->index, "metric", argv[0]);
  2305. }
  2306. ALIAS (no_match_metric,
  2307. no_match_metric_val_cmd,
  2308. "no match metric <0-4294967295>",
  2309. NO_STR
  2310. MATCH_STR
  2311. "Match metric of route\n"
  2312. "Metric value\n")
  2313. DEFUN (match_community,
  2314. match_community_cmd,
  2315. "match community (<1-99>|<100-500>|WORD)",
  2316. MATCH_STR
  2317. "Match BGP community list\n"
  2318. "Community-list number (standard)\n"
  2319. "Community-list number (expanded)\n"
  2320. "Community-list name\n")
  2321. {
  2322. return bgp_route_match_add (vty, vty->index, "community", argv[0]);
  2323. }
  2324. DEFUN (match_community_exact,
  2325. match_community_exact_cmd,
  2326. "match community (<1-99>|<100-500>|WORD) exact-match",
  2327. MATCH_STR
  2328. "Match BGP community list\n"
  2329. "Community-list number (standard)\n"
  2330. "Community-list number (expanded)\n"
  2331. "Community-list name\n"
  2332. "Do exact matching of communities\n")
  2333. {
  2334. int ret;
  2335. char *argstr;
  2336. argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
  2337. strlen (argv[0]) + strlen ("exact-match") + 2);
  2338. sprintf (argstr, "%s exact-match", argv[0]);
  2339. ret = bgp_route_match_add (vty, vty->index, "community", argstr);
  2340. XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr);
  2341. return ret;
  2342. }
  2343. DEFUN (no_match_community,
  2344. no_match_community_cmd,
  2345. "no match community",
  2346. NO_STR
  2347. MATCH_STR
  2348. "Match BGP community list\n")
  2349. {
  2350. return bgp_route_match_delete (vty, vty->index, "community", NULL);
  2351. }
  2352. ALIAS (no_match_community,
  2353. no_match_community_val_cmd,
  2354. "no match community (<1-99>|<100-500>|WORD)",
  2355. NO_STR
  2356. MATCH_STR
  2357. "Match BGP community list\n"
  2358. "Community-list number (standard)\n"
  2359. "Community-list number (expanded)\n"
  2360. "Community-list name\n")
  2361. ALIAS (no_match_community,
  2362. no_match_community_exact_cmd,
  2363. "no match community (<1-99>|<100-500>|WORD) exact-match",
  2364. NO_STR
  2365. MATCH_STR
  2366. "Match BGP community list\n"
  2367. "Community-list number (standard)\n"
  2368. "Community-list number (expanded)\n"
  2369. "Community-list name\n"
  2370. "Do exact matching of communities\n")
  2371. DEFUN (match_ecommunity,
  2372. match_ecommunity_cmd,
  2373. "match extcommunity (<1-99>|<100-500>|WORD)",
  2374. MATCH_STR
  2375. "Match BGP/VPN extended community list\n"
  2376. "Extended community-list number (standard)\n"
  2377. "Extended community-list number (expanded)\n"
  2378. "Extended community-list name\n")
  2379. {
  2380. return bgp_route_match_add (vty, vty->index, "extcommunity", argv[0]);
  2381. }
  2382. DEFUN (no_match_ecommunity,
  2383. no_match_ecommunity_cmd,
  2384. "no match extcommunity",
  2385. NO_STR
  2386. MATCH_STR
  2387. "Match BGP/VPN extended community list\n")
  2388. {
  2389. return bgp_route_match_delete (vty, vty->index, "extcommunity", NULL);
  2390. }
  2391. ALIAS (no_match_ecommunity,
  2392. no_match_ecommunity_val_cmd,
  2393. "no match extcommunity (<1-99>|<100-500>|WORD)",
  2394. NO_STR
  2395. MATCH_STR
  2396. "Match BGP/VPN extended community list\n"
  2397. "Extended community-list number (standard)\n"
  2398. "Extended community-list number (expanded)\n"
  2399. "Extended community-list name\n")
  2400. DEFUN (match_aspath,
  2401. match_aspath_cmd,
  2402. "match as-path WORD",
  2403. MATCH_STR
  2404. "Match BGP AS path list\n"
  2405. "AS path access-list name\n")
  2406. {
  2407. return bgp_route_match_add (vty, vty->index, "as-path", argv[0]);
  2408. }
  2409. DEFUN (no_match_aspath,
  2410. no_match_aspath_cmd,
  2411. "no match as-path",
  2412. NO_STR
  2413. MATCH_STR
  2414. "Match BGP AS path list\n")
  2415. {
  2416. return bgp_route_match_delete (vty, vty->index, "as-path", NULL);
  2417. }
  2418. ALIAS (no_match_aspath,
  2419. no_match_aspath_val_cmd,
  2420. "no match as-path WORD",
  2421. NO_STR
  2422. MATCH_STR
  2423. "Match BGP AS path list\n"
  2424. "AS path access-list name\n")
  2425. DEFUN (match_origin,
  2426. match_origin_cmd,
  2427. "match origin (egp|igp|incomplete)",
  2428. MATCH_STR
  2429. "BGP origin code\n"
  2430. "remote EGP\n"
  2431. "local IGP\n"
  2432. "unknown heritage\n")
  2433. {
  2434. if (strncmp (argv[0], "igp", 2) == 0)
  2435. return bgp_route_match_add (vty, vty->index, "origin", "igp");
  2436. if (strncmp (argv[0], "egp", 1) == 0)
  2437. return bgp_route_match_add (vty, vty->index, "origin", "egp");
  2438. if (strncmp (argv[0], "incomplete", 2) == 0)
  2439. return bgp_route_match_add (vty, vty->index, "origin", "incomplete");
  2440. return CMD_WARNING;
  2441. }
  2442. DEFUN (no_match_origin,
  2443. no_match_origin_cmd,
  2444. "no match origin",
  2445. NO_STR
  2446. MATCH_STR
  2447. "BGP origin code\n")
  2448. {
  2449. return bgp_route_match_delete (vty, vty->index, "origin", NULL);
  2450. }
  2451. ALIAS (no_match_origin,
  2452. no_match_origin_val_cmd,
  2453. "no match origin (egp|igp|incomplete)",
  2454. NO_STR
  2455. MATCH_STR
  2456. "BGP origin code\n"
  2457. "remote EGP\n"
  2458. "local IGP\n"
  2459. "unknown heritage\n")
  2460. DEFUN (set_ip_nexthop,
  2461. set_ip_nexthop_cmd,
  2462. "set ip next-hop A.B.C.D",
  2463. SET_STR
  2464. IP_STR
  2465. "Next hop address\n"
  2466. "IP address of next hop\n")
  2467. {
  2468. union sockunion su;
  2469. int ret;
  2470. ret = str2sockunion (argv[0], &su);
  2471. if (ret < 0)
  2472. {
  2473. vty_out (vty, "%% Malformed Next-hop address%s", VTY_NEWLINE);
  2474. return CMD_WARNING;
  2475. }
  2476. return bgp_route_set_add (vty, vty->index, "ip next-hop", argv[0]);
  2477. }
  2478. DEFUN (set_ip_nexthop_peer,
  2479. set_ip_nexthop_peer_cmd,
  2480. "set ip next-hop peer-address",
  2481. SET_STR
  2482. IP_STR
  2483. "Next hop address\n"
  2484. "Use peer address (for BGP only)\n")
  2485. {
  2486. return bgp_route_set_add (vty, vty->index, "ip next-hop", "peer-address");
  2487. }
  2488. DEFUN_DEPRECATED (no_set_ip_nexthop_peer,
  2489. no_set_ip_nexthop_peer_cmd,
  2490. "no set ip next-hop peer-address",
  2491. NO_STR
  2492. SET_STR
  2493. IP_STR
  2494. "Next hop address\n"
  2495. "Use peer address (for BGP only)\n")
  2496. {
  2497. return bgp_route_set_delete (vty, vty->index, "ip next-hop", NULL);
  2498. }
  2499. DEFUN (no_set_ip_nexthop,
  2500. no_set_ip_nexthop_cmd,
  2501. "no set ip next-hop",
  2502. NO_STR
  2503. SET_STR
  2504. "Next hop address\n")
  2505. {
  2506. if (argc == 0)
  2507. return bgp_route_set_delete (vty, vty->index, "ip next-hop", NULL);
  2508. return bgp_route_set_delete (vty, vty->index, "ip next-hop", argv[0]);
  2509. }
  2510. ALIAS (no_set_ip_nexthop,
  2511. no_set_ip_nexthop_val_cmd,
  2512. "no set ip next-hop A.B.C.D",
  2513. NO_STR
  2514. SET_STR
  2515. IP_STR
  2516. "Next hop address\n"
  2517. "IP address of next hop\n")
  2518. DEFUN (set_metric,
  2519. set_metric_cmd,
  2520. "set metric <0-4294967295>",
  2521. SET_STR
  2522. "Metric value for destination routing protocol\n"
  2523. "Metric value\n")
  2524. {
  2525. return bgp_route_set_add (vty, vty->index, "metric", argv[0]);
  2526. }
  2527. ALIAS (set_metric,
  2528. set_metric_addsub_cmd,
  2529. "set metric <+/-metric>",
  2530. SET_STR
  2531. "Metric value for destination routing protocol\n"
  2532. "Add or subtract metric\n")
  2533. DEFUN (no_set_metric,
  2534. no_set_metric_cmd,
  2535. "no set metric",
  2536. NO_STR
  2537. SET_STR
  2538. "Metric value for destination routing protocol\n")
  2539. {
  2540. if (argc == 0)
  2541. return bgp_route_set_delete (vty, vty->index, "metric", NULL);
  2542. return bgp_route_set_delete (vty, vty->index, "metric", argv[0]);
  2543. }
  2544. ALIAS (no_set_metric,
  2545. no_set_metric_val_cmd,
  2546. "no set metric <0-4294967295>",
  2547. NO_STR
  2548. SET_STR
  2549. "Metric value for destination routing protocol\n"
  2550. "Metric value\n")
  2551. DEFUN (set_local_pref,
  2552. set_local_pref_cmd,
  2553. "set local-preference <0-4294967295>",
  2554. SET_STR
  2555. "BGP local preference path attribute\n"
  2556. "Preference value\n")
  2557. {
  2558. return bgp_route_set_add (vty, vty->index, "local-preference", argv[0]);
  2559. }
  2560. DEFUN (no_set_local_pref,
  2561. no_set_local_pref_cmd,
  2562. "no set local-preference",
  2563. NO_STR
  2564. SET_STR
  2565. "BGP local preference path attribute\n")
  2566. {
  2567. if (argc == 0)
  2568. return bgp_route_set_delete (vty, vty->index, "local-preference", NULL);
  2569. return bgp_route_set_delete (vty, vty->index, "local-preference", argv[0]);
  2570. }
  2571. ALIAS (no_set_local_pref,
  2572. no_set_local_pref_val_cmd,
  2573. "no set local-preference <0-4294967295>",
  2574. NO_STR
  2575. SET_STR
  2576. "BGP local preference path attribute\n"
  2577. "Preference value\n")
  2578. DEFUN (set_weight,
  2579. set_weight_cmd,
  2580. "set weight <0-4294967295>",
  2581. SET_STR
  2582. "BGP weight for routing table\n"
  2583. "Weight value\n")
  2584. {
  2585. return bgp_route_set_add (vty, vty->index, "weight", argv[0]);
  2586. }
  2587. DEFUN (no_set_weight,
  2588. no_set_weight_cmd,
  2589. "no set weight",
  2590. NO_STR
  2591. SET_STR
  2592. "BGP weight for routing table\n")
  2593. {
  2594. if (argc == 0)
  2595. return bgp_route_set_delete (vty, vty->index, "weight", NULL);
  2596. return bgp_route_set_delete (vty, vty->index, "weight", argv[0]);
  2597. }
  2598. ALIAS (no_set_weight,
  2599. no_set_weight_val_cmd,
  2600. "no set weight <0-4294967295>",
  2601. NO_STR
  2602. SET_STR
  2603. "BGP weight for routing table\n"
  2604. "Weight value\n")
  2605. DEFUN (set_aspath_prepend,
  2606. set_aspath_prepend_cmd,
  2607. "set as-path prepend ." CMD_AS_RANGE,
  2608. SET_STR
  2609. "Transform BGP AS_PATH attribute\n"
  2610. "Prepend to the as-path\n"
  2611. "AS number\n")
  2612. {
  2613. int ret;
  2614. char *str;
  2615. str = argv_concat (argv, argc, 0);
  2616. ret = bgp_route_set_add (vty, vty->index, "as-path prepend", str);
  2617. XFREE (MTYPE_TMP, str);
  2618. return ret;
  2619. }
  2620. DEFUN (no_set_aspath_prepend,
  2621. no_set_aspath_prepend_cmd,
  2622. "no set as-path prepend",
  2623. NO_STR
  2624. SET_STR
  2625. "Transform BGP AS_PATH attribute\n"
  2626. "Prepend to the as-path\n")
  2627. {
  2628. int ret;
  2629. char *str;
  2630. if (argc == 0)
  2631. return bgp_route_set_delete (vty, vty->index, "as-path prepend", NULL);
  2632. str = argv_concat (argv, argc, 0);
  2633. ret = bgp_route_set_delete (vty, vty->index, "as-path prepend", str);
  2634. XFREE (MTYPE_TMP, str);
  2635. return ret;
  2636. }
  2637. ALIAS (no_set_aspath_prepend,
  2638. no_set_aspath_prepend_val_cmd,
  2639. "no set as-path prepend ." CMD_AS_RANGE,
  2640. NO_STR
  2641. SET_STR
  2642. "Transform BGP AS_PATH attribute\n"
  2643. "Prepend to the as-path\n"
  2644. "AS number\n")
  2645. DEFUN (set_aspath_exclude,
  2646. set_aspath_exclude_cmd,
  2647. "set as-path exclude ." CMD_AS_RANGE,
  2648. SET_STR
  2649. "Transform BGP AS-path attribute\n"
  2650. "Exclude from the as-path\n"
  2651. "AS number\n")
  2652. {
  2653. int ret;
  2654. char *str;
  2655. str = argv_concat (argv, argc, 0);
  2656. ret = bgp_route_set_add (vty, vty->index, "as-path exclude", str);
  2657. XFREE (MTYPE_TMP, str);
  2658. return ret;
  2659. }
  2660. DEFUN (no_set_aspath_exclude,
  2661. no_set_aspath_exclude_cmd,
  2662. "no set as-path exclude",
  2663. NO_STR
  2664. SET_STR
  2665. "Transform BGP AS_PATH attribute\n"
  2666. "Exclude from the as-path\n")
  2667. {
  2668. int ret;
  2669. char *str;
  2670. if (argc == 0)
  2671. return bgp_route_set_delete (vty, vty->index, "as-path exclude", NULL);
  2672. str = argv_concat (argv, argc, 0);
  2673. ret = bgp_route_set_delete (vty, vty->index, "as-path exclude", str);
  2674. XFREE (MTYPE_TMP, str);
  2675. return ret;
  2676. }
  2677. ALIAS (no_set_aspath_exclude,
  2678. no_set_aspath_exclude_val_cmd,
  2679. "no set as-path exclude ." CMD_AS_RANGE,
  2680. NO_STR
  2681. SET_STR
  2682. "Transform BGP AS_PATH attribute\n"
  2683. "Exclude from the as-path\n"
  2684. "AS number\n")
  2685. DEFUN (set_community,
  2686. set_community_cmd,
  2687. "set community .AA:NN",
  2688. SET_STR
  2689. "BGP community attribute\n"
  2690. "Community number in aa:nn format or local-AS|no-advertise|no-export|internet or additive\n")
  2691. {
  2692. int i;
  2693. int first = 0;
  2694. int additive = 0;
  2695. struct buffer *b;
  2696. struct community *com = NULL;
  2697. char *str;
  2698. char *argstr;
  2699. int ret;
  2700. b = buffer_new (1024);
  2701. for (i = 0; i < argc; i++)
  2702. {
  2703. if (strncmp (argv[i], "additive", strlen (argv[i])) == 0)
  2704. {
  2705. additive = 1;
  2706. continue;
  2707. }
  2708. if (first)
  2709. buffer_putc (b, ' ');
  2710. else
  2711. first = 1;
  2712. if (strncmp (argv[i], "internet", strlen (argv[i])) == 0)
  2713. {
  2714. buffer_putstr (b, "internet");
  2715. continue;
  2716. }
  2717. if (strncmp (argv[i], "local-AS", strlen (argv[i])) == 0)
  2718. {
  2719. buffer_putstr (b, "local-AS");
  2720. continue;
  2721. }
  2722. if (strncmp (argv[i], "no-a", strlen ("no-a")) == 0
  2723. && strncmp (argv[i], "no-advertise", strlen (argv[i])) == 0)
  2724. {
  2725. buffer_putstr (b, "no-advertise");
  2726. continue;
  2727. }
  2728. if (strncmp (argv[i], "no-e", strlen ("no-e"))== 0
  2729. && strncmp (argv[i], "no-export", strlen (argv[i])) == 0)
  2730. {
  2731. buffer_putstr (b, "no-export");
  2732. continue;
  2733. }
  2734. buffer_putstr (b, argv[i]);
  2735. }
  2736. buffer_putc (b, '\0');
  2737. /* Fetch result string then compile it to communities attribute. */
  2738. str = buffer_getstr (b);
  2739. buffer_free (b);
  2740. if (str)
  2741. {
  2742. com = community_str2com (str);
  2743. XFREE (MTYPE_TMP, str);
  2744. }
  2745. /* Can't compile user input into communities attribute. */
  2746. if (! com)
  2747. {
  2748. vty_out (vty, "%% Malformed communities attribute%s", VTY_NEWLINE);
  2749. return CMD_WARNING;
  2750. }
  2751. /* Set communites attribute string. */
  2752. str = community_str (com);
  2753. if (additive)
  2754. {
  2755. argstr = XCALLOC (MTYPE_TMP, strlen (str) + strlen (" additive") + 1);
  2756. strcpy (argstr, str);
  2757. strcpy (argstr + strlen (str), " additive");
  2758. ret = bgp_route_set_add (vty, vty->index, "community", argstr);
  2759. XFREE (MTYPE_TMP, argstr);
  2760. }
  2761. else
  2762. ret = bgp_route_set_add (vty, vty->index, "community", str);
  2763. community_free (com);
  2764. return ret;
  2765. }
  2766. DEFUN (set_community_none,
  2767. set_community_none_cmd,
  2768. "set community none",
  2769. SET_STR
  2770. "BGP community attribute\n"
  2771. "No community attribute\n")
  2772. {
  2773. return bgp_route_set_add (vty, vty->index, "community", "none");
  2774. }
  2775. DEFUN (no_set_community,
  2776. no_set_community_cmd,
  2777. "no set community",
  2778. NO_STR
  2779. SET_STR
  2780. "BGP community attribute\n")
  2781. {
  2782. return bgp_route_set_delete (vty, vty->index, "community", NULL);
  2783. }
  2784. ALIAS (no_set_community,
  2785. no_set_community_val_cmd,
  2786. "no set community .AA:NN",
  2787. NO_STR
  2788. SET_STR
  2789. "BGP community attribute\n"
  2790. "Community number in aa:nn format or local-AS|no-advertise|no-export|internet or additive\n")
  2791. ALIAS (no_set_community,
  2792. no_set_community_none_cmd,
  2793. "no set community none",
  2794. NO_STR
  2795. SET_STR
  2796. "BGP community attribute\n"
  2797. "No community attribute\n")
  2798. DEFUN (set_community_delete,
  2799. set_community_delete_cmd,
  2800. "set comm-list (<1-99>|<100-500>|WORD) delete",
  2801. SET_STR
  2802. "set BGP community list (for deletion)\n"
  2803. "Community-list number (standard)\n"
  2804. "Communitly-list number (expanded)\n"
  2805. "Community-list name\n"
  2806. "Delete matching communities\n")
  2807. {
  2808. char *str;
  2809. str = XCALLOC (MTYPE_TMP, strlen (argv[0]) + strlen (" delete") + 1);
  2810. strcpy (str, argv[0]);
  2811. strcpy (str + strlen (argv[0]), " delete");
  2812. bgp_route_set_add (vty, vty->index, "comm-list", str);
  2813. XFREE (MTYPE_TMP, str);
  2814. return CMD_SUCCESS;
  2815. }
  2816. DEFUN (no_set_community_delete,
  2817. no_set_community_delete_cmd,
  2818. "no set comm-list",
  2819. NO_STR
  2820. SET_STR
  2821. "set BGP community list (for deletion)\n")
  2822. {
  2823. return bgp_route_set_delete (vty, vty->index, "comm-list", NULL);
  2824. }
  2825. ALIAS (no_set_community_delete,
  2826. no_set_community_delete_val_cmd,
  2827. "no set comm-list (<1-99>|<100-500>|WORD) delete",
  2828. NO_STR
  2829. SET_STR
  2830. "set BGP community list (for deletion)\n"
  2831. "Community-list number (standard)\n"
  2832. "Communitly-list number (expanded)\n"
  2833. "Community-list name\n"
  2834. "Delete matching communities\n")
  2835. DEFUN (set_ecommunity_rt,
  2836. set_ecommunity_rt_cmd,
  2837. "set extcommunity rt .ASN:nn_or_IP-address:nn",
  2838. SET_STR
  2839. "BGP extended community attribute\n"
  2840. "Route Target extended community\n"
  2841. "VPN extended community\n")
  2842. {
  2843. int ret;
  2844. char *str;
  2845. str = argv_concat (argv, argc, 0);
  2846. ret = bgp_route_set_add (vty, vty->index, "extcommunity rt", str);
  2847. XFREE (MTYPE_TMP, str);
  2848. return ret;
  2849. }
  2850. DEFUN (no_set_ecommunity_rt,
  2851. no_set_ecommunity_rt_cmd,
  2852. "no set extcommunity rt",
  2853. NO_STR
  2854. SET_STR
  2855. "BGP extended community attribute\n"
  2856. "Route Target extended community\n")
  2857. {
  2858. return bgp_route_set_delete (vty, vty->index, "extcommunity rt", NULL);
  2859. }
  2860. ALIAS (no_set_ecommunity_rt,
  2861. no_set_ecommunity_rt_val_cmd,
  2862. "no set extcommunity rt .ASN:nn_or_IP-address:nn",
  2863. NO_STR
  2864. SET_STR
  2865. "BGP extended community attribute\n"
  2866. "Route Target extended community\n"
  2867. "VPN extended community\n")
  2868. DEFUN (set_ecommunity_soo,
  2869. set_ecommunity_soo_cmd,
  2870. "set extcommunity soo .ASN:nn_or_IP-address:nn",
  2871. SET_STR
  2872. "BGP extended community attribute\n"
  2873. "Site-of-Origin extended community\n"
  2874. "VPN extended community\n")
  2875. {
  2876. int ret;
  2877. char *str;
  2878. str = argv_concat (argv, argc, 0);
  2879. ret = bgp_route_set_add (vty, vty->index, "extcommunity soo", str);
  2880. XFREE (MTYPE_TMP, str);
  2881. return ret;
  2882. }
  2883. DEFUN (no_set_ecommunity_soo,
  2884. no_set_ecommunity_soo_cmd,
  2885. "no set extcommunity soo",
  2886. NO_STR
  2887. SET_STR
  2888. "BGP extended community attribute\n"
  2889. "Site-of-Origin extended community\n")
  2890. {
  2891. return bgp_route_set_delete (vty, vty->index, "extcommunity soo", NULL);
  2892. }
  2893. ALIAS (no_set_ecommunity_soo,
  2894. no_set_ecommunity_soo_val_cmd,
  2895. "no set extcommunity soo .ASN:nn_or_IP-address:nn",
  2896. NO_STR
  2897. SET_STR
  2898. "BGP extended community attribute\n"
  2899. "Site-of-Origin extended community\n"
  2900. "VPN extended community\n")
  2901. DEFUN (set_origin,
  2902. set_origin_cmd,
  2903. "set origin (egp|igp|incomplete)",
  2904. SET_STR
  2905. "BGP origin code\n"
  2906. "remote EGP\n"
  2907. "local IGP\n"
  2908. "unknown heritage\n")
  2909. {
  2910. if (strncmp (argv[0], "igp", 2) == 0)
  2911. return bgp_route_set_add (vty, vty->index, "origin", "igp");
  2912. if (strncmp (argv[0], "egp", 1) == 0)
  2913. return bgp_route_set_add (vty, vty->index, "origin", "egp");
  2914. if (strncmp (argv[0], "incomplete", 2) == 0)
  2915. return bgp_route_set_add (vty, vty->index, "origin", "incomplete");
  2916. return CMD_WARNING;
  2917. }
  2918. DEFUN (no_set_origin,
  2919. no_set_origin_cmd,
  2920. "no set origin",
  2921. NO_STR
  2922. SET_STR
  2923. "BGP origin code\n")
  2924. {
  2925. return bgp_route_set_delete (vty, vty->index, "origin", NULL);
  2926. }
  2927. ALIAS (no_set_origin,
  2928. no_set_origin_val_cmd,
  2929. "no set origin (egp|igp|incomplete)",
  2930. NO_STR
  2931. SET_STR
  2932. "BGP origin code\n"
  2933. "remote EGP\n"
  2934. "local IGP\n"
  2935. "unknown heritage\n")
  2936. DEFUN (set_atomic_aggregate,
  2937. set_atomic_aggregate_cmd,
  2938. "set atomic-aggregate",
  2939. SET_STR
  2940. "BGP atomic aggregate attribute\n" )
  2941. {
  2942. return bgp_route_set_add (vty, vty->index, "atomic-aggregate", NULL);
  2943. }
  2944. DEFUN (no_set_atomic_aggregate,
  2945. no_set_atomic_aggregate_cmd,
  2946. "no set atomic-aggregate",
  2947. NO_STR
  2948. SET_STR
  2949. "BGP atomic aggregate attribute\n" )
  2950. {
  2951. return bgp_route_set_delete (vty, vty->index, "atomic-aggregate", NULL);
  2952. }
  2953. DEFUN (set_aggregator_as,
  2954. set_aggregator_as_cmd,
  2955. "set aggregator as " CMD_AS_RANGE " A.B.C.D",
  2956. SET_STR
  2957. "BGP aggregator attribute\n"
  2958. "AS number of aggregator\n"
  2959. "AS number\n"
  2960. "IP address of aggregator\n")
  2961. {
  2962. int ret;
  2963. as_t as;
  2964. struct in_addr address;
  2965. char *argstr;
  2966. VTY_GET_INTEGER_RANGE ("AS", as, argv[0], 1, BGP_AS4_MAX);
  2967. ret = inet_aton (argv[1], &address);
  2968. if (ret == 0)
  2969. {
  2970. vty_out (vty, "Aggregator IP address is invalid%s", VTY_NEWLINE);
  2971. return CMD_WARNING;
  2972. }
  2973. argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
  2974. strlen (argv[0]) + strlen (argv[1]) + 2);
  2975. sprintf (argstr, "%s %s", argv[0], argv[1]);
  2976. ret = bgp_route_set_add (vty, vty->index, "aggregator as", argstr);
  2977. XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr);
  2978. return ret;
  2979. }
  2980. DEFUN (no_set_aggregator_as,
  2981. no_set_aggregator_as_cmd,
  2982. "no set aggregator as",
  2983. NO_STR
  2984. SET_STR
  2985. "BGP aggregator attribute\n"
  2986. "AS number of aggregator\n")
  2987. {
  2988. int ret;
  2989. as_t as;
  2990. struct in_addr address;
  2991. char *argstr;
  2992. if (argv == 0)
  2993. return bgp_route_set_delete (vty, vty->index, "aggregator as", NULL);
  2994. VTY_GET_INTEGER_RANGE ("AS", as, argv[0], 1, BGP_AS4_MAX);
  2995. ret = inet_aton (argv[1], &address);
  2996. if (ret == 0)
  2997. {
  2998. vty_out (vty, "Aggregator IP address is invalid%s", VTY_NEWLINE);
  2999. return CMD_WARNING;
  3000. }
  3001. argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
  3002. strlen (argv[0]) + strlen (argv[1]) + 2);
  3003. sprintf (argstr, "%s %s", argv[0], argv[1]);
  3004. ret = bgp_route_set_delete (vty, vty->index, "aggregator as", argstr);
  3005. XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr);
  3006. return ret;
  3007. }
  3008. ALIAS (no_set_aggregator_as,
  3009. no_set_aggregator_as_val_cmd,
  3010. "no set aggregator as " CMD_AS_RANGE " A.B.C.D",
  3011. NO_STR
  3012. SET_STR
  3013. "BGP aggregator attribute\n"
  3014. "AS number of aggregator\n"
  3015. "AS number\n"
  3016. "IP address of aggregator\n")
  3017. #ifdef HAVE_IPV6
  3018. DEFUN (match_ipv6_address,
  3019. match_ipv6_address_cmd,
  3020. "match ipv6 address WORD",
  3021. MATCH_STR
  3022. IPV6_STR
  3023. "Match IPv6 address of route\n"
  3024. "IPv6 access-list name\n")
  3025. {
  3026. return bgp_route_match_add (vty, vty->index, "ipv6 address", argv[0]);
  3027. }
  3028. DEFUN (no_match_ipv6_address,
  3029. no_match_ipv6_address_cmd,
  3030. "no match ipv6 address WORD",
  3031. NO_STR
  3032. MATCH_STR
  3033. IPV6_STR
  3034. "Match IPv6 address of route\n"
  3035. "IPv6 access-list name\n")
  3036. {
  3037. return bgp_route_match_delete (vty, vty->index, "ipv6 address", argv[0]);
  3038. }
  3039. DEFUN (match_ipv6_next_hop,
  3040. match_ipv6_next_hop_cmd,
  3041. "match ipv6 next-hop X:X::X:X",
  3042. MATCH_STR
  3043. IPV6_STR
  3044. "Match IPv6 next-hop address of route\n"
  3045. "IPv6 address of next hop\n")
  3046. {
  3047. return bgp_route_match_add (vty, vty->index, "ipv6 next-hop", argv[0]);
  3048. }
  3049. DEFUN (no_match_ipv6_next_hop,
  3050. no_match_ipv6_next_hop_cmd,
  3051. "no match ipv6 next-hop X:X::X:X",
  3052. NO_STR
  3053. MATCH_STR
  3054. IPV6_STR
  3055. "Match IPv6 next-hop address of route\n"
  3056. "IPv6 address of next hop\n")
  3057. {
  3058. return bgp_route_match_delete (vty, vty->index, "ipv6 next-hop", argv[0]);
  3059. }
  3060. DEFUN (match_ipv6_address_prefix_list,
  3061. match_ipv6_address_prefix_list_cmd,
  3062. "match ipv6 address prefix-list WORD",
  3063. MATCH_STR
  3064. IPV6_STR
  3065. "Match address of route\n"
  3066. "Match entries of prefix-lists\n"
  3067. "IP prefix-list name\n")
  3068. {
  3069. return bgp_route_match_add (vty, vty->index, "ipv6 address prefix-list", argv[0]);
  3070. }
  3071. DEFUN (no_match_ipv6_address_prefix_list,
  3072. no_match_ipv6_address_prefix_list_cmd,
  3073. "no match ipv6 address prefix-list WORD",
  3074. NO_STR
  3075. MATCH_STR
  3076. IPV6_STR
  3077. "Match address of route\n"
  3078. "Match entries of prefix-lists\n"
  3079. "IP prefix-list name\n")
  3080. {
  3081. return bgp_route_match_delete (vty, vty->index, "ipv6 address prefix-list", argv[0]);
  3082. }
  3083. DEFUN (set_ipv6_nexthop_global,
  3084. set_ipv6_nexthop_global_cmd,
  3085. "set ipv6 next-hop global X:X::X:X",
  3086. SET_STR
  3087. IPV6_STR
  3088. "IPv6 next-hop address\n"
  3089. "IPv6 global address\n"
  3090. "IPv6 address of next hop\n")
  3091. {
  3092. return bgp_route_set_add (vty, vty->index, "ipv6 next-hop global", argv[0]);
  3093. }
  3094. DEFUN (no_set_ipv6_nexthop_global,
  3095. no_set_ipv6_nexthop_global_cmd,
  3096. "no set ipv6 next-hop global",
  3097. NO_STR
  3098. SET_STR
  3099. IPV6_STR
  3100. "IPv6 next-hop address\n"
  3101. "IPv6 global address\n")
  3102. {
  3103. if (argc == 0)
  3104. return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop global", NULL);
  3105. return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop global", argv[0]);
  3106. }
  3107. ALIAS (no_set_ipv6_nexthop_global,
  3108. no_set_ipv6_nexthop_global_val_cmd,
  3109. "no set ipv6 next-hop global X:X::X:X",
  3110. NO_STR
  3111. SET_STR
  3112. IPV6_STR
  3113. "IPv6 next-hop address\n"
  3114. "IPv6 global address\n"
  3115. "IPv6 address of next hop\n")
  3116. DEFUN (set_ipv6_nexthop_local,
  3117. set_ipv6_nexthop_local_cmd,
  3118. "set ipv6 next-hop local X:X::X:X",
  3119. SET_STR
  3120. IPV6_STR
  3121. "IPv6 next-hop address\n"
  3122. "IPv6 local address\n"
  3123. "IPv6 address of next hop\n")
  3124. {
  3125. return bgp_route_set_add (vty, vty->index, "ipv6 next-hop local", argv[0]);
  3126. }
  3127. DEFUN (no_set_ipv6_nexthop_local,
  3128. no_set_ipv6_nexthop_local_cmd,
  3129. "no set ipv6 next-hop local",
  3130. NO_STR
  3131. SET_STR
  3132. IPV6_STR
  3133. "IPv6 next-hop address\n"
  3134. "IPv6 local address\n")
  3135. {
  3136. if (argc == 0)
  3137. return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop local", NULL);
  3138. return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop local", argv[0]);
  3139. }
  3140. ALIAS (no_set_ipv6_nexthop_local,
  3141. no_set_ipv6_nexthop_local_val_cmd,
  3142. "no set ipv6 next-hop local X:X::X:X",
  3143. NO_STR
  3144. SET_STR
  3145. IPV6_STR
  3146. "IPv6 next-hop address\n"
  3147. "IPv6 local address\n"
  3148. "IPv6 address of next hop\n")
  3149. #endif /* HAVE_IPV6 */
  3150. DEFUN (set_vpnv4_nexthop,
  3151. set_vpnv4_nexthop_cmd,
  3152. "set vpnv4 next-hop A.B.C.D",
  3153. SET_STR
  3154. "VPNv4 information\n"
  3155. "VPNv4 next-hop address\n"
  3156. "IP address of next hop\n")
  3157. {
  3158. return bgp_route_set_add (vty, vty->index, "vpnv4 next-hop", argv[0]);
  3159. }
  3160. DEFUN (no_set_vpnv4_nexthop,
  3161. no_set_vpnv4_nexthop_cmd,
  3162. "no set vpnv4 next-hop",
  3163. NO_STR
  3164. SET_STR
  3165. "VPNv4 information\n"
  3166. "VPNv4 next-hop address\n")
  3167. {
  3168. if (argc == 0)
  3169. return bgp_route_set_delete (vty, vty->index, "vpnv4 next-hop", NULL);
  3170. return bgp_route_set_delete (vty, vty->index, "vpnv4 next-hop", argv[0]);
  3171. }
  3172. ALIAS (no_set_vpnv4_nexthop,
  3173. no_set_vpnv4_nexthop_val_cmd,
  3174. "no set vpnv4 next-hop A.B.C.D",
  3175. NO_STR
  3176. SET_STR
  3177. "VPNv4 information\n"
  3178. "VPNv4 next-hop address\n"
  3179. "IP address of next hop\n")
  3180. DEFUN (set_originator_id,
  3181. set_originator_id_cmd,
  3182. "set originator-id A.B.C.D",
  3183. SET_STR
  3184. "BGP originator ID attribute\n"
  3185. "IP address of originator\n")
  3186. {
  3187. return bgp_route_set_add (vty, vty->index, "originator-id", argv[0]);
  3188. }
  3189. DEFUN (no_set_originator_id,
  3190. no_set_originator_id_cmd,
  3191. "no set originator-id",
  3192. NO_STR
  3193. SET_STR
  3194. "BGP originator ID attribute\n")
  3195. {
  3196. if (argc == 0)
  3197. return bgp_route_set_delete (vty, vty->index, "originator-id", NULL);
  3198. return bgp_route_set_delete (vty, vty->index, "originator-id", argv[0]);
  3199. }
  3200. ALIAS (no_set_originator_id,
  3201. no_set_originator_id_val_cmd,
  3202. "no set originator-id A.B.C.D",
  3203. NO_STR
  3204. SET_STR
  3205. "BGP originator ID attribute\n"
  3206. "IP address of originator\n")
  3207. DEFUN_DEPRECATED (set_pathlimit_ttl,
  3208. set_pathlimit_ttl_cmd,
  3209. "set pathlimit ttl <1-255>",
  3210. SET_STR
  3211. "BGP AS-Pathlimit attribute\n"
  3212. "Set AS-Path Hop-count TTL\n")
  3213. {
  3214. return CMD_SUCCESS;
  3215. }
  3216. DEFUN_DEPRECATED (no_set_pathlimit_ttl,
  3217. no_set_pathlimit_ttl_cmd,
  3218. "no set pathlimit ttl",
  3219. NO_STR
  3220. SET_STR
  3221. "BGP AS-Pathlimit attribute\n"
  3222. "Set AS-Path Hop-count TTL\n")
  3223. {
  3224. return CMD_SUCCESS;
  3225. }
  3226. ALIAS (no_set_pathlimit_ttl,
  3227. no_set_pathlimit_ttl_val_cmd,
  3228. "no set pathlimit ttl <1-255>",
  3229. NO_STR
  3230. MATCH_STR
  3231. "BGP AS-Pathlimit attribute\n"
  3232. "Set AS-Path Hop-count TTL\n")
  3233. DEFUN_DEPRECATED (match_pathlimit_as,
  3234. match_pathlimit_as_cmd,
  3235. "match pathlimit as <1-65535>",
  3236. MATCH_STR
  3237. "BGP AS-Pathlimit attribute\n"
  3238. "Match Pathlimit AS number\n")
  3239. {
  3240. return CMD_SUCCESS;
  3241. }
  3242. DEFUN_DEPRECATED (no_match_pathlimit_as,
  3243. no_match_pathlimit_as_cmd,
  3244. "no match pathlimit as",
  3245. NO_STR
  3246. MATCH_STR
  3247. "BGP AS-Pathlimit attribute\n"
  3248. "Match Pathlimit AS number\n")
  3249. {
  3250. return CMD_SUCCESS;
  3251. }
  3252. ALIAS (no_match_pathlimit_as,
  3253. no_match_pathlimit_as_val_cmd,
  3254. "no match pathlimit as <1-65535>",
  3255. NO_STR
  3256. MATCH_STR
  3257. "BGP AS-Pathlimit attribute\n"
  3258. "Match Pathlimit ASN\n")
  3259. /* Initialization of route map. */
  3260. void
  3261. bgp_route_map_init (void)
  3262. {
  3263. route_map_init ();
  3264. route_map_init_vty ();
  3265. route_map_add_hook (bgp_route_map_update);
  3266. route_map_delete_hook (bgp_route_map_update);
  3267. route_map_install_match (&route_match_peer_cmd);
  3268. route_map_install_match (&route_match_ip_address_cmd);
  3269. route_map_install_match (&route_match_ip_next_hop_cmd);
  3270. route_map_install_match (&route_match_ip_route_source_cmd);
  3271. route_map_install_match (&route_match_ip_address_prefix_list_cmd);
  3272. route_map_install_match (&route_match_ip_next_hop_prefix_list_cmd);
  3273. route_map_install_match (&route_match_ip_route_source_prefix_list_cmd);
  3274. route_map_install_match (&route_match_aspath_cmd);
  3275. route_map_install_match (&route_match_community_cmd);
  3276. route_map_install_match (&route_match_ecommunity_cmd);
  3277. route_map_install_match (&route_match_metric_cmd);
  3278. route_map_install_match (&route_match_origin_cmd);
  3279. route_map_install_match (&route_match_probability_cmd);
  3280. route_map_install_set (&route_set_ip_nexthop_cmd);
  3281. route_map_install_set (&route_set_local_pref_cmd);
  3282. route_map_install_set (&route_set_weight_cmd);
  3283. route_map_install_set (&route_set_metric_cmd);
  3284. route_map_install_set (&route_set_aspath_prepend_cmd);
  3285. route_map_install_set (&route_set_aspath_exclude_cmd);
  3286. route_map_install_set (&route_set_origin_cmd);
  3287. route_map_install_set (&route_set_atomic_aggregate_cmd);
  3288. route_map_install_set (&route_set_aggregator_as_cmd);
  3289. route_map_install_set (&route_set_community_cmd);
  3290. route_map_install_set (&route_set_community_delete_cmd);
  3291. route_map_install_set (&route_set_vpnv4_nexthop_cmd);
  3292. route_map_install_set (&route_set_originator_id_cmd);
  3293. route_map_install_set (&route_set_ecommunity_rt_cmd);
  3294. route_map_install_set (&route_set_ecommunity_soo_cmd);
  3295. install_element (RMAP_NODE, &match_peer_cmd);
  3296. install_element (RMAP_NODE, &match_peer_local_cmd);
  3297. install_element (RMAP_NODE, &no_match_peer_cmd);
  3298. install_element (RMAP_NODE, &no_match_peer_val_cmd);
  3299. install_element (RMAP_NODE, &no_match_peer_local_cmd);
  3300. install_element (RMAP_NODE, &match_ip_address_cmd);
  3301. install_element (RMAP_NODE, &no_match_ip_address_cmd);
  3302. install_element (RMAP_NODE, &no_match_ip_address_val_cmd);
  3303. install_element (RMAP_NODE, &match_ip_next_hop_cmd);
  3304. install_element (RMAP_NODE, &no_match_ip_next_hop_cmd);
  3305. install_element (RMAP_NODE, &no_match_ip_next_hop_val_cmd);
  3306. install_element (RMAP_NODE, &match_ip_route_source_cmd);
  3307. install_element (RMAP_NODE, &no_match_ip_route_source_cmd);
  3308. install_element (RMAP_NODE, &no_match_ip_route_source_val_cmd);
  3309. install_element (RMAP_NODE, &match_ip_address_prefix_list_cmd);
  3310. install_element (RMAP_NODE, &no_match_ip_address_prefix_list_cmd);
  3311. install_element (RMAP_NODE, &no_match_ip_address_prefix_list_val_cmd);
  3312. install_element (RMAP_NODE, &match_ip_next_hop_prefix_list_cmd);
  3313. install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_cmd);
  3314. install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_val_cmd);
  3315. install_element (RMAP_NODE, &match_ip_route_source_prefix_list_cmd);
  3316. install_element (RMAP_NODE, &no_match_ip_route_source_prefix_list_cmd);
  3317. install_element (RMAP_NODE, &no_match_ip_route_source_prefix_list_val_cmd);
  3318. install_element (RMAP_NODE, &match_aspath_cmd);
  3319. install_element (RMAP_NODE, &no_match_aspath_cmd);
  3320. install_element (RMAP_NODE, &no_match_aspath_val_cmd);
  3321. install_element (RMAP_NODE, &match_metric_cmd);
  3322. install_element (RMAP_NODE, &no_match_metric_cmd);
  3323. install_element (RMAP_NODE, &no_match_metric_val_cmd);
  3324. install_element (RMAP_NODE, &match_community_cmd);
  3325. install_element (RMAP_NODE, &match_community_exact_cmd);
  3326. install_element (RMAP_NODE, &no_match_community_cmd);
  3327. install_element (RMAP_NODE, &no_match_community_val_cmd);
  3328. install_element (RMAP_NODE, &no_match_community_exact_cmd);
  3329. install_element (RMAP_NODE, &match_ecommunity_cmd);
  3330. install_element (RMAP_NODE, &no_match_ecommunity_cmd);
  3331. install_element (RMAP_NODE, &no_match_ecommunity_val_cmd);
  3332. install_element (RMAP_NODE, &match_origin_cmd);
  3333. install_element (RMAP_NODE, &no_match_origin_cmd);
  3334. install_element (RMAP_NODE, &no_match_origin_val_cmd);
  3335. install_element (RMAP_NODE, &match_probability_cmd);
  3336. install_element (RMAP_NODE, &no_match_probability_cmd);
  3337. install_element (RMAP_NODE, &no_match_probability_val_cmd);
  3338. install_element (RMAP_NODE, &set_ip_nexthop_cmd);
  3339. install_element (RMAP_NODE, &set_ip_nexthop_peer_cmd);
  3340. install_element (RMAP_NODE, &no_set_ip_nexthop_cmd);
  3341. install_element (RMAP_NODE, &no_set_ip_nexthop_val_cmd);
  3342. install_element (RMAP_NODE, &set_local_pref_cmd);
  3343. install_element (RMAP_NODE, &no_set_local_pref_cmd);
  3344. install_element (RMAP_NODE, &no_set_local_pref_val_cmd);
  3345. install_element (RMAP_NODE, &set_weight_cmd);
  3346. install_element (RMAP_NODE, &no_set_weight_cmd);
  3347. install_element (RMAP_NODE, &no_set_weight_val_cmd);
  3348. install_element (RMAP_NODE, &set_metric_cmd);
  3349. install_element (RMAP_NODE, &set_metric_addsub_cmd);
  3350. install_element (RMAP_NODE, &no_set_metric_cmd);
  3351. install_element (RMAP_NODE, &no_set_metric_val_cmd);
  3352. install_element (RMAP_NODE, &set_aspath_prepend_cmd);
  3353. install_element (RMAP_NODE, &set_aspath_exclude_cmd);
  3354. install_element (RMAP_NODE, &no_set_aspath_prepend_cmd);
  3355. install_element (RMAP_NODE, &no_set_aspath_prepend_val_cmd);
  3356. install_element (RMAP_NODE, &no_set_aspath_exclude_cmd);
  3357. install_element (RMAP_NODE, &no_set_aspath_exclude_val_cmd);
  3358. install_element (RMAP_NODE, &set_origin_cmd);
  3359. install_element (RMAP_NODE, &no_set_origin_cmd);
  3360. install_element (RMAP_NODE, &no_set_origin_val_cmd);
  3361. install_element (RMAP_NODE, &set_atomic_aggregate_cmd);
  3362. install_element (RMAP_NODE, &no_set_atomic_aggregate_cmd);
  3363. install_element (RMAP_NODE, &set_aggregator_as_cmd);
  3364. install_element (RMAP_NODE, &no_set_aggregator_as_cmd);
  3365. install_element (RMAP_NODE, &no_set_aggregator_as_val_cmd);
  3366. install_element (RMAP_NODE, &set_community_cmd);
  3367. install_element (RMAP_NODE, &set_community_none_cmd);
  3368. install_element (RMAP_NODE, &no_set_community_cmd);
  3369. install_element (RMAP_NODE, &no_set_community_val_cmd);
  3370. install_element (RMAP_NODE, &no_set_community_none_cmd);
  3371. install_element (RMAP_NODE, &set_community_delete_cmd);
  3372. install_element (RMAP_NODE, &no_set_community_delete_cmd);
  3373. install_element (RMAP_NODE, &no_set_community_delete_val_cmd);
  3374. install_element (RMAP_NODE, &set_ecommunity_rt_cmd);
  3375. install_element (RMAP_NODE, &no_set_ecommunity_rt_cmd);
  3376. install_element (RMAP_NODE, &no_set_ecommunity_rt_val_cmd);
  3377. install_element (RMAP_NODE, &set_ecommunity_soo_cmd);
  3378. install_element (RMAP_NODE, &no_set_ecommunity_soo_cmd);
  3379. install_element (RMAP_NODE, &no_set_ecommunity_soo_val_cmd);
  3380. install_element (RMAP_NODE, &set_vpnv4_nexthop_cmd);
  3381. install_element (RMAP_NODE, &no_set_vpnv4_nexthop_cmd);
  3382. install_element (RMAP_NODE, &no_set_vpnv4_nexthop_val_cmd);
  3383. install_element (RMAP_NODE, &set_originator_id_cmd);
  3384. install_element (RMAP_NODE, &no_set_originator_id_cmd);
  3385. install_element (RMAP_NODE, &no_set_originator_id_val_cmd);
  3386. #ifdef HAVE_IPV6
  3387. route_map_install_match (&route_match_ipv6_address_cmd);
  3388. route_map_install_match (&route_match_ipv6_next_hop_cmd);
  3389. route_map_install_match (&route_match_ipv6_address_prefix_list_cmd);
  3390. route_map_install_set (&route_set_ipv6_nexthop_global_cmd);
  3391. route_map_install_set (&route_set_ipv6_nexthop_local_cmd);
  3392. install_element (RMAP_NODE, &match_ipv6_address_cmd);
  3393. install_element (RMAP_NODE, &no_match_ipv6_address_cmd);
  3394. install_element (RMAP_NODE, &match_ipv6_next_hop_cmd);
  3395. install_element (RMAP_NODE, &no_match_ipv6_next_hop_cmd);
  3396. install_element (RMAP_NODE, &match_ipv6_address_prefix_list_cmd);
  3397. install_element (RMAP_NODE, &no_match_ipv6_address_prefix_list_cmd);
  3398. install_element (RMAP_NODE, &set_ipv6_nexthop_global_cmd);
  3399. install_element (RMAP_NODE, &no_set_ipv6_nexthop_global_cmd);
  3400. install_element (RMAP_NODE, &no_set_ipv6_nexthop_global_val_cmd);
  3401. install_element (RMAP_NODE, &set_ipv6_nexthop_local_cmd);
  3402. install_element (RMAP_NODE, &no_set_ipv6_nexthop_local_cmd);
  3403. install_element (RMAP_NODE, &no_set_ipv6_nexthop_local_val_cmd);
  3404. #endif /* HAVE_IPV6 */
  3405. /* AS-Pathlimit: functionality removed, commands kept for
  3406. * compatibility.
  3407. */
  3408. install_element (RMAP_NODE, &set_pathlimit_ttl_cmd);
  3409. install_element (RMAP_NODE, &no_set_pathlimit_ttl_cmd);
  3410. install_element (RMAP_NODE, &no_set_pathlimit_ttl_val_cmd);
  3411. install_element (RMAP_NODE, &match_pathlimit_as_cmd);
  3412. install_element (RMAP_NODE, &no_match_pathlimit_as_cmd);
  3413. install_element (RMAP_NODE, &no_match_pathlimit_as_val_cmd);
  3414. }