plist.c 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800
  1. /* Prefix list functions.
  2. * Copyright (C) 1999 Kunihiro Ishiguro
  3. *
  4. * This file is part of GNU Zebra.
  5. *
  6. * GNU Zebra is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published
  8. * by the Free Software Foundation; either version 2, or (at your
  9. * option) any later version.
  10. *
  11. * GNU Zebra is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GNU Zebra; see the file COPYING. If not, write to the
  18. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. * Boston, MA 02111-1307, USA.
  20. */
  21. #include <zebra.h>
  22. #include "prefix.h"
  23. #include "command.h"
  24. #include "memory.h"
  25. #include "plist.h"
  26. #include "sockunion.h"
  27. #include "buffer.h"
  28. #include "stream.h"
  29. #include "log.h"
  30. #include "plist_int.h"
  31. /* List of struct prefix_list. */
  32. struct prefix_list_list
  33. {
  34. struct prefix_list *head;
  35. struct prefix_list *tail;
  36. };
  37. /* Master structure of prefix_list. */
  38. struct prefix_master
  39. {
  40. /* List of prefix_list which name is number. */
  41. struct prefix_list_list num;
  42. /* List of prefix_list which name is string. */
  43. struct prefix_list_list str;
  44. /* Whether sequential number is used. */
  45. int seqnum;
  46. /* The latest update. */
  47. struct prefix_list *recent;
  48. /* Hook function which is executed when new prefix_list is added. */
  49. void (*add_hook) (struct prefix_list *);
  50. /* Hook function which is executed when prefix_list is deleted. */
  51. void (*delete_hook) (struct prefix_list *);
  52. };
  53. /* Static structure of IPv4 prefix_list's master. */
  54. static struct prefix_master prefix_master_ipv4 =
  55. {
  56. {NULL, NULL},
  57. {NULL, NULL},
  58. 1,
  59. NULL,
  60. NULL,
  61. };
  62. #ifdef HAVE_IPV6
  63. /* Static structure of IPv6 prefix-list's master. */
  64. static struct prefix_master prefix_master_ipv6 =
  65. {
  66. {NULL, NULL},
  67. {NULL, NULL},
  68. 1,
  69. NULL,
  70. NULL,
  71. };
  72. #endif /* HAVE_IPV6*/
  73. /* Static structure of BGP ORF prefix_list's master. */
  74. static struct prefix_master prefix_master_orf_v4 =
  75. {
  76. {NULL, NULL},
  77. {NULL, NULL},
  78. 1,
  79. NULL,
  80. NULL,
  81. };
  82. /* Static structure of BGP ORF prefix_list's master. */
  83. static struct prefix_master prefix_master_orf_v6 =
  84. {
  85. {NULL, NULL},
  86. {NULL, NULL},
  87. 1,
  88. NULL,
  89. NULL,
  90. };
  91. static struct prefix_master *
  92. prefix_master_get (afi_t afi, int orf)
  93. {
  94. if (afi == AFI_IP)
  95. return orf ? &prefix_master_orf_v4 : &prefix_master_ipv4;
  96. if (afi == AFI_IP6)
  97. return orf ? &prefix_master_orf_v6 : &prefix_master_ipv6;
  98. return NULL;
  99. }
  100. const char *prefix_list_name (struct prefix_list *plist)
  101. {
  102. return plist->name;
  103. }
  104. /* Lookup prefix_list from list of prefix_list by name. */
  105. static struct prefix_list *
  106. prefix_list_lookup_do (afi_t afi, int orf, const char *name)
  107. {
  108. struct prefix_list *plist;
  109. struct prefix_master *master;
  110. if (name == NULL)
  111. return NULL;
  112. master = prefix_master_get (afi, orf);
  113. if (master == NULL)
  114. return NULL;
  115. for (plist = master->num.head; plist; plist = plist->next)
  116. if (strcmp (plist->name, name) == 0)
  117. return plist;
  118. for (plist = master->str.head; plist; plist = plist->next)
  119. if (strcmp (plist->name, name) == 0)
  120. return plist;
  121. return NULL;
  122. }
  123. struct prefix_list *
  124. prefix_list_lookup (afi_t afi, const char *name)
  125. {
  126. return prefix_list_lookup_do (afi, 0, name);
  127. }
  128. struct prefix_list *
  129. prefix_bgp_orf_lookup (afi_t afi, const char *name)
  130. {
  131. return prefix_list_lookup_do (afi, 1, name);
  132. }
  133. static struct prefix_list *
  134. prefix_list_new (void)
  135. {
  136. struct prefix_list *new;
  137. new = XCALLOC (MTYPE_PREFIX_LIST, sizeof (struct prefix_list));
  138. return new;
  139. }
  140. static void
  141. prefix_list_free (struct prefix_list *plist)
  142. {
  143. XFREE (MTYPE_PREFIX_LIST, plist);
  144. }
  145. static struct prefix_list_entry *
  146. prefix_list_entry_new (void)
  147. {
  148. struct prefix_list_entry *new;
  149. new = XCALLOC (MTYPE_PREFIX_LIST_ENTRY, sizeof (struct prefix_list_entry));
  150. return new;
  151. }
  152. static void
  153. prefix_list_entry_free (struct prefix_list_entry *pentry)
  154. {
  155. XFREE (MTYPE_PREFIX_LIST_ENTRY, pentry);
  156. }
  157. /* Insert new prefix list to list of prefix_list. Each prefix_list
  158. is sorted by the name. */
  159. static struct prefix_list *
  160. prefix_list_insert (afi_t afi, int orf, const char *name)
  161. {
  162. unsigned int i;
  163. long number;
  164. struct prefix_list *plist;
  165. struct prefix_list *point;
  166. struct prefix_list_list *list;
  167. struct prefix_master *master;
  168. master = prefix_master_get (afi, orf);
  169. if (master == NULL)
  170. return NULL;
  171. /* Allocate new prefix_list and copy given name. */
  172. plist = prefix_list_new ();
  173. plist->name = XSTRDUP (MTYPE_PREFIX_LIST_STR, name);
  174. plist->master = master;
  175. /* If name is made by all digit character. We treat it as
  176. number. */
  177. for (number = 0, i = 0; i < strlen (name); i++)
  178. {
  179. if (isdigit ((int) name[i]))
  180. number = (number * 10) + (name[i] - '0');
  181. else
  182. break;
  183. }
  184. /* In case of name is all digit character */
  185. if (i == strlen (name))
  186. {
  187. plist->type = PREFIX_TYPE_NUMBER;
  188. /* Set prefix_list to number list. */
  189. list = &master->num;
  190. for (point = list->head; point; point = point->next)
  191. if (atol (point->name) >= number)
  192. break;
  193. }
  194. else
  195. {
  196. plist->type = PREFIX_TYPE_STRING;
  197. /* Set prefix_list to string list. */
  198. list = &master->str;
  199. /* Set point to insertion point. */
  200. for (point = list->head; point; point = point->next)
  201. if (strcmp (point->name, name) >= 0)
  202. break;
  203. }
  204. /* In case of this is the first element of master. */
  205. if (list->head == NULL)
  206. {
  207. list->head = list->tail = plist;
  208. return plist;
  209. }
  210. /* In case of insertion is made at the tail of access_list. */
  211. if (point == NULL)
  212. {
  213. plist->prev = list->tail;
  214. list->tail->next = plist;
  215. list->tail = plist;
  216. return plist;
  217. }
  218. /* In case of insertion is made at the head of access_list. */
  219. if (point == list->head)
  220. {
  221. plist->next = list->head;
  222. list->head->prev = plist;
  223. list->head = plist;
  224. return plist;
  225. }
  226. /* Insertion is made at middle of the access_list. */
  227. plist->next = point;
  228. plist->prev = point->prev;
  229. if (point->prev)
  230. point->prev->next = plist;
  231. point->prev = plist;
  232. return plist;
  233. }
  234. static struct prefix_list *
  235. prefix_list_get (afi_t afi, int orf, const char *name)
  236. {
  237. struct prefix_list *plist;
  238. plist = prefix_list_lookup_do (afi, orf, name);
  239. if (plist == NULL)
  240. plist = prefix_list_insert (afi, orf, name);
  241. return plist;
  242. }
  243. /* Delete prefix-list from prefix_list_master and free it. */
  244. static void
  245. prefix_list_delete (struct prefix_list *plist)
  246. {
  247. struct prefix_list_list *list;
  248. struct prefix_master *master;
  249. struct prefix_list_entry *pentry;
  250. struct prefix_list_entry *next;
  251. /* If prefix-list contain prefix_list_entry free all of it. */
  252. for (pentry = plist->head; pentry; pentry = next)
  253. {
  254. next = pentry->next;
  255. prefix_list_entry_free (pentry);
  256. plist->count--;
  257. }
  258. master = plist->master;
  259. if (plist->type == PREFIX_TYPE_NUMBER)
  260. list = &master->num;
  261. else
  262. list = &master->str;
  263. if (plist->next)
  264. plist->next->prev = plist->prev;
  265. else
  266. list->tail = plist->prev;
  267. if (plist->prev)
  268. plist->prev->next = plist->next;
  269. else
  270. list->head = plist->next;
  271. if (plist->desc)
  272. XFREE (MTYPE_TMP, plist->desc);
  273. /* Make sure master's recent changed prefix-list information is
  274. cleared. */
  275. master->recent = NULL;
  276. if (plist->name)
  277. XFREE (MTYPE_PREFIX_LIST_STR, plist->name);
  278. prefix_list_free (plist);
  279. if (master->delete_hook)
  280. (*master->delete_hook) (NULL);
  281. }
  282. static struct prefix_list_entry *
  283. prefix_list_entry_make (struct prefix *prefix, enum prefix_list_type type,
  284. int seq, int le, int ge, int any)
  285. {
  286. struct prefix_list_entry *pentry;
  287. pentry = prefix_list_entry_new ();
  288. if (any)
  289. pentry->any = 1;
  290. prefix_copy (&pentry->prefix, prefix);
  291. pentry->type = type;
  292. pentry->seq = seq;
  293. pentry->le = le;
  294. pentry->ge = ge;
  295. return pentry;
  296. }
  297. /* Add hook function. */
  298. void
  299. prefix_list_add_hook (void (*func) (struct prefix_list *plist))
  300. {
  301. prefix_master_ipv4.add_hook = func;
  302. #ifdef HAVE_IPV6
  303. prefix_master_ipv6.add_hook = func;
  304. #endif /* HAVE_IPV6 */
  305. }
  306. /* Delete hook function. */
  307. void
  308. prefix_list_delete_hook (void (*func) (struct prefix_list *plist))
  309. {
  310. prefix_master_ipv4.delete_hook = func;
  311. #ifdef HAVE_IPV6
  312. prefix_master_ipv6.delete_hook = func;
  313. #endif /* HAVE_IPVt6 */
  314. }
  315. /* Calculate new sequential number. */
  316. static int
  317. prefix_new_seq_get (struct prefix_list *plist)
  318. {
  319. int maxseq;
  320. int newseq;
  321. struct prefix_list_entry *pentry;
  322. maxseq = newseq = 0;
  323. for (pentry = plist->head; pentry; pentry = pentry->next)
  324. {
  325. if (maxseq < pentry->seq)
  326. maxseq = pentry->seq;
  327. }
  328. newseq = ((maxseq / 5) * 5) + 5;
  329. return newseq;
  330. }
  331. /* Return prefix list entry which has same seq number. */
  332. static struct prefix_list_entry *
  333. prefix_seq_check (struct prefix_list *plist, int seq)
  334. {
  335. struct prefix_list_entry *pentry;
  336. for (pentry = plist->head; pentry; pentry = pentry->next)
  337. if (pentry->seq == seq)
  338. return pentry;
  339. return NULL;
  340. }
  341. static struct prefix_list_entry *
  342. prefix_list_entry_lookup (struct prefix_list *plist, struct prefix *prefix,
  343. enum prefix_list_type type, int seq, int le, int ge)
  344. {
  345. struct prefix_list_entry *pentry;
  346. for (pentry = plist->head; pentry; pentry = pentry->next)
  347. if (prefix_same (&pentry->prefix, prefix) && pentry->type == type)
  348. {
  349. if (seq >= 0 && pentry->seq != seq)
  350. continue;
  351. if (pentry->le != le)
  352. continue;
  353. if (pentry->ge != ge)
  354. continue;
  355. return pentry;
  356. }
  357. return NULL;
  358. }
  359. static void
  360. prefix_list_entry_delete (struct prefix_list *plist,
  361. struct prefix_list_entry *pentry,
  362. int update_list)
  363. {
  364. if (plist == NULL || pentry == NULL)
  365. return;
  366. if (pentry->prev)
  367. pentry->prev->next = pentry->next;
  368. else
  369. plist->head = pentry->next;
  370. if (pentry->next)
  371. pentry->next->prev = pentry->prev;
  372. else
  373. plist->tail = pentry->prev;
  374. prefix_list_entry_free (pentry);
  375. plist->count--;
  376. if (update_list)
  377. {
  378. if (plist->master->delete_hook)
  379. (*plist->master->delete_hook) (plist);
  380. if (plist->head == NULL && plist->tail == NULL && plist->desc == NULL)
  381. prefix_list_delete (plist);
  382. else
  383. plist->master->recent = plist;
  384. }
  385. }
  386. static void
  387. prefix_list_entry_add (struct prefix_list *plist,
  388. struct prefix_list_entry *pentry)
  389. {
  390. struct prefix_list_entry *replace;
  391. struct prefix_list_entry *point;
  392. /* Automatic asignment of seq no. */
  393. if (pentry->seq == -1)
  394. pentry->seq = prefix_new_seq_get (plist);
  395. /* Is there any same seq prefix list entry? */
  396. replace = prefix_seq_check (plist, pentry->seq);
  397. if (replace)
  398. prefix_list_entry_delete (plist, replace, 0);
  399. /* Check insert point. */
  400. for (point = plist->head; point; point = point->next)
  401. if (point->seq >= pentry->seq)
  402. break;
  403. /* In case of this is the first element of the list. */
  404. pentry->next = point;
  405. if (point)
  406. {
  407. if (point->prev)
  408. point->prev->next = pentry;
  409. else
  410. plist->head = pentry;
  411. pentry->prev = point->prev;
  412. point->prev = pentry;
  413. }
  414. else
  415. {
  416. if (plist->tail)
  417. plist->tail->next = pentry;
  418. else
  419. plist->head = pentry;
  420. pentry->prev = plist->tail;
  421. plist->tail = pentry;
  422. }
  423. /* Increment count. */
  424. plist->count++;
  425. /* Run hook function. */
  426. if (plist->master->add_hook)
  427. (*plist->master->add_hook) (plist);
  428. plist->master->recent = plist;
  429. }
  430. /* Return string of prefix_list_type. */
  431. static const char *
  432. prefix_list_type_str (struct prefix_list_entry *pentry)
  433. {
  434. switch (pentry->type)
  435. {
  436. case PREFIX_PERMIT:
  437. return "permit";
  438. case PREFIX_DENY:
  439. return "deny";
  440. default:
  441. return "";
  442. }
  443. }
  444. static int
  445. prefix_list_entry_match (struct prefix_list_entry *pentry, struct prefix *p)
  446. {
  447. int ret;
  448. ret = prefix_match (&pentry->prefix, p);
  449. if (! ret)
  450. return 0;
  451. /* In case of le nor ge is specified, exact match is performed. */
  452. if (! pentry->le && ! pentry->ge)
  453. {
  454. if (pentry->prefix.prefixlen != p->prefixlen)
  455. return 0;
  456. }
  457. else
  458. {
  459. if (pentry->le)
  460. if (p->prefixlen > pentry->le)
  461. return 0;
  462. if (pentry->ge)
  463. if (p->prefixlen < pentry->ge)
  464. return 0;
  465. }
  466. return 1;
  467. }
  468. enum prefix_list_type
  469. prefix_list_apply (struct prefix_list *plist, void *object)
  470. {
  471. struct prefix_list_entry *pentry;
  472. struct prefix *p;
  473. p = (struct prefix *) object;
  474. if (plist == NULL)
  475. return PREFIX_DENY;
  476. if (plist->count == 0)
  477. return PREFIX_PERMIT;
  478. for (pentry = plist->head; pentry; pentry = pentry->next)
  479. {
  480. pentry->refcnt++;
  481. if (prefix_list_entry_match (pentry, p))
  482. {
  483. pentry->hitcnt++;
  484. return pentry->type;
  485. }
  486. }
  487. return PREFIX_DENY;
  488. }
  489. static void __attribute__ ((unused))
  490. prefix_list_print (struct prefix_list *plist)
  491. {
  492. struct prefix_list_entry *pentry;
  493. if (plist == NULL)
  494. return;
  495. printf ("ip prefix-list %s: %d entries\n", plist->name, plist->count);
  496. for (pentry = plist->head; pentry; pentry = pentry->next)
  497. {
  498. if (pentry->any)
  499. printf ("any %s\n", prefix_list_type_str (pentry));
  500. else
  501. {
  502. struct prefix *p;
  503. char buf[BUFSIZ];
  504. p = &pentry->prefix;
  505. printf (" seq %d %s %s/%d",
  506. pentry->seq,
  507. prefix_list_type_str (pentry),
  508. inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
  509. p->prefixlen);
  510. if (pentry->ge)
  511. printf (" ge %d", pentry->ge);
  512. if (pentry->le)
  513. printf (" le %d", pentry->le);
  514. printf ("\n");
  515. }
  516. }
  517. }
  518. /* Retrun 1 when plist already include pentry policy. */
  519. static struct prefix_list_entry *
  520. prefix_entry_dup_check (struct prefix_list *plist,
  521. struct prefix_list_entry *new)
  522. {
  523. struct prefix_list_entry *pentry;
  524. int seq = 0;
  525. if (new->seq == -1)
  526. seq = prefix_new_seq_get (plist);
  527. else
  528. seq = new->seq;
  529. for (pentry = plist->head; pentry; pentry = pentry->next)
  530. {
  531. if (prefix_same (&pentry->prefix, &new->prefix)
  532. && pentry->type == new->type
  533. && pentry->le == new->le
  534. && pentry->ge == new->ge
  535. && pentry->seq != seq)
  536. return pentry;
  537. }
  538. return NULL;
  539. }
  540. static int
  541. vty_invalid_prefix_range (struct vty *vty, const char *prefix)
  542. {
  543. vty_out (vty, "%% Invalid prefix range for %s, make sure: len < ge-value <= le-value%s",
  544. prefix, VTY_NEWLINE);
  545. return CMD_WARNING;
  546. }
  547. static int
  548. vty_prefix_list_install (struct vty *vty, afi_t afi, const char *name,
  549. const char *seq, const char *typestr,
  550. const char *prefix, const char *ge, const char *le)
  551. {
  552. int ret;
  553. enum prefix_list_type type;
  554. struct prefix_list *plist;
  555. struct prefix_list_entry *pentry;
  556. struct prefix_list_entry *dup;
  557. struct prefix p;
  558. int any = 0;
  559. int seqnum = -1;
  560. int lenum = 0;
  561. int genum = 0;
  562. /* Sequential number. */
  563. if (seq)
  564. seqnum = atoi (seq);
  565. /* ge and le number */
  566. if (ge)
  567. genum = atoi (ge);
  568. if (le)
  569. lenum = atoi (le);
  570. /* Check filter type. */
  571. if (strncmp ("permit", typestr, 1) == 0)
  572. type = PREFIX_PERMIT;
  573. else if (strncmp ("deny", typestr, 1) == 0)
  574. type = PREFIX_DENY;
  575. else
  576. {
  577. vty_out (vty, "%% prefix type must be permit or deny%s", VTY_NEWLINE);
  578. return CMD_WARNING;
  579. }
  580. /* "any" is special token for matching any IPv4 addresses. */
  581. if (afi == AFI_IP)
  582. {
  583. if (strncmp ("any", prefix, strlen (prefix)) == 0)
  584. {
  585. ret = str2prefix_ipv4 ("0.0.0.0/0", (struct prefix_ipv4 *) &p);
  586. genum = 0;
  587. lenum = IPV4_MAX_BITLEN;
  588. any = 1;
  589. }
  590. else
  591. ret = str2prefix_ipv4 (prefix, (struct prefix_ipv4 *) &p);
  592. if (ret <= 0)
  593. {
  594. vty_out (vty, "%% Malformed IPv4 prefix%s", VTY_NEWLINE);
  595. return CMD_WARNING;
  596. }
  597. }
  598. #ifdef HAVE_IPV6
  599. else if (afi == AFI_IP6)
  600. {
  601. if (strncmp ("any", prefix, strlen (prefix)) == 0)
  602. {
  603. ret = str2prefix_ipv6 ("::/0", (struct prefix_ipv6 *) &p);
  604. genum = 0;
  605. lenum = IPV6_MAX_BITLEN;
  606. any = 1;
  607. }
  608. else
  609. ret = str2prefix_ipv6 (prefix, (struct prefix_ipv6 *) &p);
  610. if (ret <= 0)
  611. {
  612. vty_out (vty, "%% Malformed IPv6 prefix%s", VTY_NEWLINE);
  613. return CMD_WARNING;
  614. }
  615. }
  616. #endif /* HAVE_IPV6 */
  617. /* ge and le check. */
  618. if (genum && (genum <= p.prefixlen))
  619. return vty_invalid_prefix_range (vty, prefix);
  620. if (lenum && (lenum <= p.prefixlen))
  621. return vty_invalid_prefix_range (vty, prefix);
  622. if (lenum && (genum > lenum))
  623. return vty_invalid_prefix_range (vty, prefix);
  624. if (genum && (lenum == (afi == AFI_IP ? 32 : 128)))
  625. lenum = 0;
  626. /* Get prefix_list with name. */
  627. plist = prefix_list_get (afi, 0, name);
  628. /* Make prefix entry. */
  629. pentry = prefix_list_entry_make (&p, type, seqnum, lenum, genum, any);
  630. /* Check same policy. */
  631. dup = prefix_entry_dup_check (plist, pentry);
  632. if (dup)
  633. {
  634. prefix_list_entry_free (pentry);
  635. vty_out (vty, "%% Insertion failed - prefix-list entry exists:%s",
  636. VTY_NEWLINE);
  637. vty_out (vty, " seq %d %s %s", dup->seq, typestr, prefix);
  638. if (! any && genum)
  639. vty_out (vty, " ge %d", genum);
  640. if (! any && lenum)
  641. vty_out (vty, " le %d", lenum);
  642. vty_out (vty, "%s", VTY_NEWLINE);
  643. return CMD_WARNING;
  644. }
  645. /* Install new filter to the access_list. */
  646. prefix_list_entry_add (plist, pentry);
  647. return CMD_SUCCESS;
  648. }
  649. static int
  650. vty_prefix_list_uninstall (struct vty *vty, afi_t afi, const char *name,
  651. const char *seq, const char *typestr,
  652. const char *prefix, const char *ge, const char *le)
  653. {
  654. int ret;
  655. enum prefix_list_type type;
  656. struct prefix_list *plist;
  657. struct prefix_list_entry *pentry;
  658. struct prefix p;
  659. int seqnum = -1;
  660. int lenum = 0;
  661. int genum = 0;
  662. /* Check prefix list name. */
  663. plist = prefix_list_lookup (afi, name);
  664. if (! plist)
  665. {
  666. vty_out (vty, "%% Can't find specified prefix-list%s", VTY_NEWLINE);
  667. return CMD_WARNING;
  668. }
  669. /* Only prefix-list name specified, delete the entire prefix-list. */
  670. if (seq == NULL && typestr == NULL && prefix == NULL &&
  671. ge == NULL && le == NULL)
  672. {
  673. prefix_list_delete (plist);
  674. return CMD_SUCCESS;
  675. }
  676. /* We must have, at a minimum, both the type and prefix here */
  677. if ((typestr == NULL) || (prefix == NULL))
  678. {
  679. vty_out (vty, "%% Both prefix and type required%s", VTY_NEWLINE);
  680. return CMD_WARNING;
  681. }
  682. /* Check sequence number. */
  683. if (seq)
  684. seqnum = atoi (seq);
  685. /* ge and le number */
  686. if (ge)
  687. genum = atoi (ge);
  688. if (le)
  689. lenum = atoi (le);
  690. /* Check of filter type. */
  691. if (strncmp ("permit", typestr, 1) == 0)
  692. type = PREFIX_PERMIT;
  693. else if (strncmp ("deny", typestr, 1) == 0)
  694. type = PREFIX_DENY;
  695. else
  696. {
  697. vty_out (vty, "%% prefix type must be permit or deny%s", VTY_NEWLINE);
  698. return CMD_WARNING;
  699. }
  700. /* "any" is special token for matching any IPv4 addresses. */
  701. if (afi == AFI_IP)
  702. {
  703. if (strncmp ("any", prefix, strlen (prefix)) == 0)
  704. {
  705. ret = str2prefix_ipv4 ("0.0.0.0/0", (struct prefix_ipv4 *) &p);
  706. genum = 0;
  707. lenum = IPV4_MAX_BITLEN;
  708. }
  709. else
  710. ret = str2prefix_ipv4 (prefix, (struct prefix_ipv4 *) &p);
  711. if (ret <= 0)
  712. {
  713. vty_out (vty, "%% Malformed IPv4 prefix%s", VTY_NEWLINE);
  714. return CMD_WARNING;
  715. }
  716. }
  717. #ifdef HAVE_IPV6
  718. else if (afi == AFI_IP6)
  719. {
  720. if (strncmp ("any", prefix, strlen (prefix)) == 0)
  721. {
  722. ret = str2prefix_ipv6 ("::/0", (struct prefix_ipv6 *) &p);
  723. genum = 0;
  724. lenum = IPV6_MAX_BITLEN;
  725. }
  726. else
  727. ret = str2prefix_ipv6 (prefix, (struct prefix_ipv6 *) &p);
  728. if (ret <= 0)
  729. {
  730. vty_out (vty, "%% Malformed IPv6 prefix%s", VTY_NEWLINE);
  731. return CMD_WARNING;
  732. }
  733. }
  734. #endif /* HAVE_IPV6 */
  735. /* Lookup prefix entry. */
  736. pentry = prefix_list_entry_lookup(plist, &p, type, seqnum, lenum, genum);
  737. if (pentry == NULL)
  738. {
  739. vty_out (vty, "%% Can't find specified prefix-list%s", VTY_NEWLINE);
  740. return CMD_WARNING;
  741. }
  742. /* Install new filter to the access_list. */
  743. prefix_list_entry_delete (plist, pentry, 1);
  744. return CMD_SUCCESS;
  745. }
  746. static int
  747. vty_prefix_list_desc_unset (struct vty *vty, afi_t afi, const char *name)
  748. {
  749. struct prefix_list *plist;
  750. plist = prefix_list_lookup (afi, name);
  751. if (! plist)
  752. {
  753. vty_out (vty, "%% Can't find specified prefix-list%s", VTY_NEWLINE);
  754. return CMD_WARNING;
  755. }
  756. if (plist->desc)
  757. {
  758. XFREE (MTYPE_TMP, plist->desc);
  759. plist->desc = NULL;
  760. }
  761. if (plist->head == NULL && plist->tail == NULL && plist->desc == NULL)
  762. prefix_list_delete (plist);
  763. return CMD_SUCCESS;
  764. }
  765. enum display_type
  766. {
  767. normal_display,
  768. summary_display,
  769. detail_display,
  770. sequential_display,
  771. longer_display,
  772. first_match_display
  773. };
  774. static void
  775. vty_show_prefix_entry (struct vty *vty, afi_t afi, struct prefix_list *plist,
  776. struct prefix_master *master, enum display_type dtype,
  777. int seqnum)
  778. {
  779. struct prefix_list_entry *pentry;
  780. /* Print the name of the protocol */
  781. if (zlog_default)
  782. vty_out (vty, "%s: ", zlog_proto_names[zlog_default->protocol]);
  783. if (dtype == normal_display)
  784. {
  785. vty_out (vty, "ip%s prefix-list %s: %d entries%s",
  786. afi == AFI_IP ? "" : "v6",
  787. plist->name, plist->count, VTY_NEWLINE);
  788. if (plist->desc)
  789. vty_out (vty, " Description: %s%s", plist->desc, VTY_NEWLINE);
  790. }
  791. else if (dtype == summary_display || dtype == detail_display)
  792. {
  793. vty_out (vty, "ip%s prefix-list %s:%s",
  794. afi == AFI_IP ? "" : "v6", plist->name, VTY_NEWLINE);
  795. if (plist->desc)
  796. vty_out (vty, " Description: %s%s", plist->desc, VTY_NEWLINE);
  797. vty_out (vty, " count: %d, range entries: %d, sequences: %d - %d%s",
  798. plist->count, plist->rangecount,
  799. plist->head ? plist->head->seq : 0,
  800. plist->tail ? plist->tail->seq : 0,
  801. VTY_NEWLINE);
  802. }
  803. if (dtype != summary_display)
  804. {
  805. for (pentry = plist->head; pentry; pentry = pentry->next)
  806. {
  807. if (dtype == sequential_display && pentry->seq != seqnum)
  808. continue;
  809. vty_out (vty, " ");
  810. if (master->seqnum)
  811. vty_out (vty, "seq %d ", pentry->seq);
  812. vty_out (vty, "%s ", prefix_list_type_str (pentry));
  813. if (pentry->any)
  814. vty_out (vty, "any");
  815. else
  816. {
  817. struct prefix *p = &pentry->prefix;
  818. char buf[BUFSIZ];
  819. vty_out (vty, "%s/%d",
  820. inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
  821. p->prefixlen);
  822. if (pentry->ge)
  823. vty_out (vty, " ge %d", pentry->ge);
  824. if (pentry->le)
  825. vty_out (vty, " le %d", pentry->le);
  826. }
  827. if (dtype == detail_display || dtype == sequential_display)
  828. vty_out (vty, " (hit count: %ld, refcount: %ld)",
  829. pentry->hitcnt, pentry->refcnt);
  830. vty_out (vty, "%s", VTY_NEWLINE);
  831. }
  832. }
  833. }
  834. static int
  835. vty_show_prefix_list (struct vty *vty, afi_t afi, const char *name,
  836. const char *seq, enum display_type dtype)
  837. {
  838. struct prefix_list *plist;
  839. struct prefix_master *master;
  840. int seqnum = 0;
  841. master = prefix_master_get (afi, 0);
  842. if (master == NULL)
  843. return CMD_WARNING;
  844. if (seq)
  845. seqnum = atoi (seq);
  846. if (name)
  847. {
  848. plist = prefix_list_lookup (afi, name);
  849. if (! plist)
  850. {
  851. vty_out (vty, "%% Can't find specified prefix-list%s", VTY_NEWLINE);
  852. return CMD_WARNING;
  853. }
  854. vty_show_prefix_entry (vty, afi, plist, master, dtype, seqnum);
  855. }
  856. else
  857. {
  858. if (dtype == detail_display || dtype == summary_display)
  859. {
  860. if (master->recent)
  861. vty_out (vty, "Prefix-list with the last deletion/insertion: %s%s",
  862. master->recent->name, VTY_NEWLINE);
  863. }
  864. for (plist = master->num.head; plist; plist = plist->next)
  865. vty_show_prefix_entry (vty, afi, plist, master, dtype, seqnum);
  866. for (plist = master->str.head; plist; plist = plist->next)
  867. vty_show_prefix_entry (vty, afi, plist, master, dtype, seqnum);
  868. }
  869. return CMD_SUCCESS;
  870. }
  871. static int
  872. vty_show_prefix_list_prefix (struct vty *vty, afi_t afi, const char *name,
  873. const char *prefix, enum display_type type)
  874. {
  875. struct prefix_list *plist;
  876. struct prefix_list_entry *pentry;
  877. struct prefix p;
  878. int ret;
  879. int match;
  880. plist = prefix_list_lookup (afi, name);
  881. if (! plist)
  882. {
  883. vty_out (vty, "%% Can't find specified prefix-list%s", VTY_NEWLINE);
  884. return CMD_WARNING;
  885. }
  886. ret = str2prefix (prefix, &p);
  887. if (ret <= 0)
  888. {
  889. vty_out (vty, "%% prefix is malformed%s", VTY_NEWLINE);
  890. return CMD_WARNING;
  891. }
  892. for (pentry = plist->head; pentry; pentry = pentry->next)
  893. {
  894. match = 0;
  895. if (type == normal_display || type == first_match_display)
  896. if (prefix_same (&p, &pentry->prefix))
  897. match = 1;
  898. if (type == longer_display)
  899. if (prefix_match (&p, &pentry->prefix))
  900. match = 1;
  901. if (match)
  902. {
  903. vty_out (vty, " seq %d %s ",
  904. pentry->seq,
  905. prefix_list_type_str (pentry));
  906. if (pentry->any)
  907. vty_out (vty, "any");
  908. else
  909. {
  910. struct prefix *p = &pentry->prefix;
  911. char buf[BUFSIZ];
  912. vty_out (vty, "%s/%d",
  913. inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
  914. p->prefixlen);
  915. if (pentry->ge)
  916. vty_out (vty, " ge %d", pentry->ge);
  917. if (pentry->le)
  918. vty_out (vty, " le %d", pentry->le);
  919. }
  920. if (type == normal_display || type == first_match_display)
  921. vty_out (vty, " (hit count: %ld, refcount: %ld)",
  922. pentry->hitcnt, pentry->refcnt);
  923. vty_out (vty, "%s", VTY_NEWLINE);
  924. if (type == first_match_display)
  925. return CMD_SUCCESS;
  926. }
  927. }
  928. return CMD_SUCCESS;
  929. }
  930. static int
  931. vty_clear_prefix_list (struct vty *vty, afi_t afi, const char *name,
  932. const char *prefix)
  933. {
  934. struct prefix_master *master;
  935. struct prefix_list *plist;
  936. struct prefix_list_entry *pentry;
  937. int ret;
  938. struct prefix p;
  939. master = prefix_master_get (afi, 0);
  940. if (master == NULL)
  941. return CMD_WARNING;
  942. if (name == NULL && prefix == NULL)
  943. {
  944. for (plist = master->num.head; plist; plist = plist->next)
  945. for (pentry = plist->head; pentry; pentry = pentry->next)
  946. pentry->hitcnt = 0;
  947. for (plist = master->str.head; plist; plist = plist->next)
  948. for (pentry = plist->head; pentry; pentry = pentry->next)
  949. pentry->hitcnt = 0;
  950. }
  951. else
  952. {
  953. plist = prefix_list_lookup (afi, name);
  954. if (! plist)
  955. {
  956. vty_out (vty, "%% Can't find specified prefix-list%s", VTY_NEWLINE);
  957. return CMD_WARNING;
  958. }
  959. if (prefix)
  960. {
  961. ret = str2prefix (prefix, &p);
  962. if (ret <= 0)
  963. {
  964. vty_out (vty, "%% prefix is malformed%s", VTY_NEWLINE);
  965. return CMD_WARNING;
  966. }
  967. }
  968. for (pentry = plist->head; pentry; pentry = pentry->next)
  969. {
  970. if (prefix)
  971. {
  972. if (prefix_match (&pentry->prefix, &p))
  973. pentry->hitcnt = 0;
  974. }
  975. else
  976. pentry->hitcnt = 0;
  977. }
  978. }
  979. return CMD_SUCCESS;
  980. }
  981. DEFUN (ip_prefix_list,
  982. ip_prefix_list_cmd,
  983. "ip prefix-list WORD (deny|permit) (A.B.C.D/M|any)",
  984. IP_STR
  985. PREFIX_LIST_STR
  986. "Name of a prefix list\n"
  987. "Specify packets to reject\n"
  988. "Specify packets to forward\n"
  989. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  990. "Any prefix match. Same as \"0.0.0.0/0 le 32\"\n")
  991. {
  992. return vty_prefix_list_install (vty, AFI_IP, argv[0], NULL,
  993. argv[1], argv[2], NULL, NULL);
  994. }
  995. DEFUN (ip_prefix_list_ge,
  996. ip_prefix_list_ge_cmd,
  997. "ip prefix-list WORD (deny|permit) A.B.C.D/M ge <0-32>",
  998. IP_STR
  999. PREFIX_LIST_STR
  1000. "Name of a prefix list\n"
  1001. "Specify packets to reject\n"
  1002. "Specify packets to forward\n"
  1003. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1004. "Minimum prefix length to be matched\n"
  1005. "Minimum prefix length\n")
  1006. {
  1007. return vty_prefix_list_install (vty, AFI_IP, argv[0], NULL, argv[1],
  1008. argv[2], argv[3], NULL);
  1009. }
  1010. DEFUN (ip_prefix_list_ge_le,
  1011. ip_prefix_list_ge_le_cmd,
  1012. "ip prefix-list WORD (deny|permit) A.B.C.D/M ge <0-32> le <0-32>",
  1013. IP_STR
  1014. PREFIX_LIST_STR
  1015. "Name of a prefix list\n"
  1016. "Specify packets to reject\n"
  1017. "Specify packets to forward\n"
  1018. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1019. "Minimum prefix length to be matched\n"
  1020. "Minimum prefix length\n"
  1021. "Maximum prefix length to be matched\n"
  1022. "Maximum prefix length\n")
  1023. {
  1024. return vty_prefix_list_install (vty, AFI_IP, argv[0], NULL, argv[1],
  1025. argv[2], argv[3], argv[4]);
  1026. }
  1027. DEFUN (ip_prefix_list_le,
  1028. ip_prefix_list_le_cmd,
  1029. "ip prefix-list WORD (deny|permit) A.B.C.D/M le <0-32>",
  1030. IP_STR
  1031. PREFIX_LIST_STR
  1032. "Name of a prefix list\n"
  1033. "Specify packets to reject\n"
  1034. "Specify packets to forward\n"
  1035. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1036. "Maximum prefix length to be matched\n"
  1037. "Maximum prefix length\n")
  1038. {
  1039. return vty_prefix_list_install (vty, AFI_IP, argv[0], NULL, argv[1],
  1040. argv[2], NULL, argv[3]);
  1041. }
  1042. DEFUN (ip_prefix_list_le_ge,
  1043. ip_prefix_list_le_ge_cmd,
  1044. "ip prefix-list WORD (deny|permit) A.B.C.D/M le <0-32> ge <0-32>",
  1045. IP_STR
  1046. PREFIX_LIST_STR
  1047. "Name of a prefix list\n"
  1048. "Specify packets to reject\n"
  1049. "Specify packets to forward\n"
  1050. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1051. "Maximum prefix length to be matched\n"
  1052. "Maximum prefix length\n"
  1053. "Minimum prefix length to be matched\n"
  1054. "Minimum prefix length\n")
  1055. {
  1056. return vty_prefix_list_install (vty, AFI_IP, argv[0], NULL, argv[1],
  1057. argv[2], argv[4], argv[3]);
  1058. }
  1059. DEFUN (ip_prefix_list_seq,
  1060. ip_prefix_list_seq_cmd,
  1061. "ip prefix-list WORD seq <1-4294967295> (deny|permit) (A.B.C.D/M|any)",
  1062. IP_STR
  1063. PREFIX_LIST_STR
  1064. "Name of a prefix list\n"
  1065. "sequence number of an entry\n"
  1066. "Sequence number\n"
  1067. "Specify packets to reject\n"
  1068. "Specify packets to forward\n"
  1069. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1070. "Any prefix match. Same as \"0.0.0.0/0 le 32\"\n")
  1071. {
  1072. return vty_prefix_list_install (vty, AFI_IP, argv[0], argv[1], argv[2],
  1073. argv[3], NULL, NULL);
  1074. }
  1075. DEFUN (ip_prefix_list_seq_ge,
  1076. ip_prefix_list_seq_ge_cmd,
  1077. "ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M ge <0-32>",
  1078. IP_STR
  1079. PREFIX_LIST_STR
  1080. "Name of a prefix list\n"
  1081. "sequence number of an entry\n"
  1082. "Sequence number\n"
  1083. "Specify packets to reject\n"
  1084. "Specify packets to forward\n"
  1085. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1086. "Minimum prefix length to be matched\n"
  1087. "Minimum prefix length\n")
  1088. {
  1089. return vty_prefix_list_install (vty, AFI_IP, argv[0], argv[1], argv[2],
  1090. argv[3], argv[4], NULL);
  1091. }
  1092. DEFUN (ip_prefix_list_seq_ge_le,
  1093. ip_prefix_list_seq_ge_le_cmd,
  1094. "ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M ge <0-32> le <0-32>",
  1095. IP_STR
  1096. PREFIX_LIST_STR
  1097. "Name of a prefix list\n"
  1098. "sequence number of an entry\n"
  1099. "Sequence number\n"
  1100. "Specify packets to reject\n"
  1101. "Specify packets to forward\n"
  1102. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1103. "Minimum prefix length to be matched\n"
  1104. "Minimum prefix length\n"
  1105. "Maximum prefix length to be matched\n"
  1106. "Maximum prefix length\n")
  1107. {
  1108. return vty_prefix_list_install (vty, AFI_IP, argv[0], argv[1], argv[2],
  1109. argv[3], argv[4], argv[5]);
  1110. }
  1111. DEFUN (ip_prefix_list_seq_le,
  1112. ip_prefix_list_seq_le_cmd,
  1113. "ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M le <0-32>",
  1114. IP_STR
  1115. PREFIX_LIST_STR
  1116. "Name of a prefix list\n"
  1117. "sequence number of an entry\n"
  1118. "Sequence number\n"
  1119. "Specify packets to reject\n"
  1120. "Specify packets to forward\n"
  1121. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1122. "Maximum prefix length to be matched\n"
  1123. "Maximum prefix length\n")
  1124. {
  1125. return vty_prefix_list_install (vty, AFI_IP, argv[0], argv[1], argv[2],
  1126. argv[3], NULL, argv[4]);
  1127. }
  1128. DEFUN (ip_prefix_list_seq_le_ge,
  1129. ip_prefix_list_seq_le_ge_cmd,
  1130. "ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M le <0-32> ge <0-32>",
  1131. IP_STR
  1132. PREFIX_LIST_STR
  1133. "Name of a prefix list\n"
  1134. "sequence number of an entry\n"
  1135. "Sequence number\n"
  1136. "Specify packets to reject\n"
  1137. "Specify packets to forward\n"
  1138. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1139. "Maximum prefix length to be matched\n"
  1140. "Maximum prefix length\n"
  1141. "Minimum prefix length to be matched\n"
  1142. "Minimum prefix length\n")
  1143. {
  1144. return vty_prefix_list_install (vty, AFI_IP, argv[0], argv[1], argv[2],
  1145. argv[3], argv[5], argv[4]);
  1146. }
  1147. DEFUN (no_ip_prefix_list,
  1148. no_ip_prefix_list_cmd,
  1149. "no ip prefix-list WORD",
  1150. NO_STR
  1151. IP_STR
  1152. PREFIX_LIST_STR
  1153. "Name of a prefix list\n")
  1154. {
  1155. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, NULL,
  1156. NULL, NULL, NULL);
  1157. }
  1158. DEFUN (no_ip_prefix_list_prefix,
  1159. no_ip_prefix_list_prefix_cmd,
  1160. "no ip prefix-list WORD (deny|permit) (A.B.C.D/M|any)",
  1161. NO_STR
  1162. IP_STR
  1163. PREFIX_LIST_STR
  1164. "Name of a prefix list\n"
  1165. "Specify packets to reject\n"
  1166. "Specify packets to forward\n"
  1167. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1168. "Any prefix match. Same as \"0.0.0.0/0 le 32\"\n")
  1169. {
  1170. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, argv[1],
  1171. argv[2], NULL, NULL);
  1172. }
  1173. DEFUN (no_ip_prefix_list_ge,
  1174. no_ip_prefix_list_ge_cmd,
  1175. "no ip prefix-list WORD (deny|permit) A.B.C.D/M ge <0-32>",
  1176. NO_STR
  1177. IP_STR
  1178. PREFIX_LIST_STR
  1179. "Name of a prefix list\n"
  1180. "Specify packets to reject\n"
  1181. "Specify packets to forward\n"
  1182. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1183. "Minimum prefix length to be matched\n"
  1184. "Minimum prefix length\n")
  1185. {
  1186. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, argv[1],
  1187. argv[2], argv[3], NULL);
  1188. }
  1189. DEFUN (no_ip_prefix_list_ge_le,
  1190. no_ip_prefix_list_ge_le_cmd,
  1191. "no ip prefix-list WORD (deny|permit) A.B.C.D/M ge <0-32> le <0-32>",
  1192. NO_STR
  1193. IP_STR
  1194. PREFIX_LIST_STR
  1195. "Name of a prefix list\n"
  1196. "Specify packets to reject\n"
  1197. "Specify packets to forward\n"
  1198. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1199. "Minimum prefix length to be matched\n"
  1200. "Minimum prefix length\n"
  1201. "Maximum prefix length to be matched\n"
  1202. "Maximum prefix length\n")
  1203. {
  1204. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, argv[1],
  1205. argv[2], argv[3], argv[4]);
  1206. }
  1207. DEFUN (no_ip_prefix_list_le,
  1208. no_ip_prefix_list_le_cmd,
  1209. "no ip prefix-list WORD (deny|permit) A.B.C.D/M le <0-32>",
  1210. NO_STR
  1211. IP_STR
  1212. PREFIX_LIST_STR
  1213. "Name of a prefix list\n"
  1214. "Specify packets to reject\n"
  1215. "Specify packets to forward\n"
  1216. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1217. "Maximum prefix length to be matched\n"
  1218. "Maximum prefix length\n")
  1219. {
  1220. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, argv[1],
  1221. argv[2], NULL, argv[3]);
  1222. }
  1223. DEFUN (no_ip_prefix_list_le_ge,
  1224. no_ip_prefix_list_le_ge_cmd,
  1225. "no ip prefix-list WORD (deny|permit) A.B.C.D/M le <0-32> ge <0-32>",
  1226. NO_STR
  1227. IP_STR
  1228. PREFIX_LIST_STR
  1229. "Name of a prefix list\n"
  1230. "Specify packets to reject\n"
  1231. "Specify packets to forward\n"
  1232. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1233. "Maximum prefix length to be matched\n"
  1234. "Maximum prefix length\n"
  1235. "Minimum prefix length to be matched\n"
  1236. "Minimum prefix length\n")
  1237. {
  1238. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, argv[1],
  1239. argv[2], argv[4], argv[3]);
  1240. }
  1241. DEFUN (no_ip_prefix_list_seq,
  1242. no_ip_prefix_list_seq_cmd,
  1243. "no ip prefix-list WORD seq <1-4294967295> (deny|permit) (A.B.C.D/M|any)",
  1244. NO_STR
  1245. IP_STR
  1246. PREFIX_LIST_STR
  1247. "Name of a prefix list\n"
  1248. "sequence number of an entry\n"
  1249. "Sequence number\n"
  1250. "Specify packets to reject\n"
  1251. "Specify packets to forward\n"
  1252. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1253. "Any prefix match. Same as \"0.0.0.0/0 le 32\"\n")
  1254. {
  1255. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], argv[1], argv[2],
  1256. argv[3], NULL, NULL);
  1257. }
  1258. DEFUN (no_ip_prefix_list_seq_ge,
  1259. no_ip_prefix_list_seq_ge_cmd,
  1260. "no ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M ge <0-32>",
  1261. NO_STR
  1262. IP_STR
  1263. PREFIX_LIST_STR
  1264. "Name of a prefix list\n"
  1265. "sequence number of an entry\n"
  1266. "Sequence number\n"
  1267. "Specify packets to reject\n"
  1268. "Specify packets to forward\n"
  1269. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1270. "Minimum prefix length to be matched\n"
  1271. "Minimum prefix length\n")
  1272. {
  1273. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], argv[1], argv[2],
  1274. argv[3], argv[4], NULL);
  1275. }
  1276. DEFUN (no_ip_prefix_list_seq_ge_le,
  1277. no_ip_prefix_list_seq_ge_le_cmd,
  1278. "no ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M ge <0-32> le <0-32>",
  1279. NO_STR
  1280. IP_STR
  1281. PREFIX_LIST_STR
  1282. "Name of a prefix list\n"
  1283. "sequence number of an entry\n"
  1284. "Sequence number\n"
  1285. "Specify packets to reject\n"
  1286. "Specify packets to forward\n"
  1287. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1288. "Minimum prefix length to be matched\n"
  1289. "Minimum prefix length\n"
  1290. "Maximum prefix length to be matched\n"
  1291. "Maximum prefix length\n")
  1292. {
  1293. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], argv[1], argv[2],
  1294. argv[3], argv[4], argv[5]);
  1295. }
  1296. DEFUN (no_ip_prefix_list_seq_le,
  1297. no_ip_prefix_list_seq_le_cmd,
  1298. "no ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M le <0-32>",
  1299. NO_STR
  1300. IP_STR
  1301. PREFIX_LIST_STR
  1302. "Name of a prefix list\n"
  1303. "sequence number of an entry\n"
  1304. "Sequence number\n"
  1305. "Specify packets to reject\n"
  1306. "Specify packets to forward\n"
  1307. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1308. "Maximum prefix length to be matched\n"
  1309. "Maximum prefix length\n")
  1310. {
  1311. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], argv[1], argv[2],
  1312. argv[3], NULL, argv[4]);
  1313. }
  1314. DEFUN (no_ip_prefix_list_seq_le_ge,
  1315. no_ip_prefix_list_seq_le_ge_cmd,
  1316. "no ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M le <0-32> ge <0-32>",
  1317. NO_STR
  1318. IP_STR
  1319. PREFIX_LIST_STR
  1320. "Name of a prefix list\n"
  1321. "sequence number of an entry\n"
  1322. "Sequence number\n"
  1323. "Specify packets to reject\n"
  1324. "Specify packets to forward\n"
  1325. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1326. "Maximum prefix length to be matched\n"
  1327. "Maximum prefix length\n"
  1328. "Minimum prefix length to be matched\n"
  1329. "Minimum prefix length\n")
  1330. {
  1331. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], argv[1], argv[2],
  1332. argv[3], argv[5], argv[4]);
  1333. }
  1334. DEFUN (ip_prefix_list_sequence_number,
  1335. ip_prefix_list_sequence_number_cmd,
  1336. "ip prefix-list sequence-number",
  1337. IP_STR
  1338. PREFIX_LIST_STR
  1339. "Include/exclude sequence numbers in NVGEN\n")
  1340. {
  1341. prefix_master_ipv4.seqnum = 1;
  1342. return CMD_SUCCESS;
  1343. }
  1344. DEFUN (no_ip_prefix_list_sequence_number,
  1345. no_ip_prefix_list_sequence_number_cmd,
  1346. "no ip prefix-list sequence-number",
  1347. NO_STR
  1348. IP_STR
  1349. PREFIX_LIST_STR
  1350. "Include/exclude sequence numbers in NVGEN\n")
  1351. {
  1352. prefix_master_ipv4.seqnum = 0;
  1353. return CMD_SUCCESS;
  1354. }
  1355. DEFUN (ip_prefix_list_description,
  1356. ip_prefix_list_description_cmd,
  1357. "ip prefix-list WORD description .LINE",
  1358. IP_STR
  1359. PREFIX_LIST_STR
  1360. "Name of a prefix list\n"
  1361. "Prefix-list specific description\n"
  1362. "Up to 80 characters describing this prefix-list\n")
  1363. {
  1364. struct prefix_list *plist;
  1365. plist = prefix_list_get (AFI_IP, 0, argv[0]);
  1366. if (plist->desc)
  1367. {
  1368. XFREE (MTYPE_TMP, plist->desc);
  1369. plist->desc = NULL;
  1370. }
  1371. plist->desc = argv_concat(argv, argc, 1);
  1372. return CMD_SUCCESS;
  1373. }
  1374. DEFUN (no_ip_prefix_list_description,
  1375. no_ip_prefix_list_description_cmd,
  1376. "no ip prefix-list WORD description",
  1377. NO_STR
  1378. IP_STR
  1379. PREFIX_LIST_STR
  1380. "Name of a prefix list\n"
  1381. "Prefix-list specific description\n")
  1382. {
  1383. return vty_prefix_list_desc_unset (vty, AFI_IP, argv[0]);
  1384. }
  1385. ALIAS (no_ip_prefix_list_description,
  1386. no_ip_prefix_list_description_arg_cmd,
  1387. "no ip prefix-list WORD description .LINE",
  1388. NO_STR
  1389. IP_STR
  1390. PREFIX_LIST_STR
  1391. "Name of a prefix list\n"
  1392. "Prefix-list specific description\n"
  1393. "Up to 80 characters describing this prefix-list\n")
  1394. DEFUN (show_ip_prefix_list,
  1395. show_ip_prefix_list_cmd,
  1396. "show ip prefix-list",
  1397. SHOW_STR
  1398. IP_STR
  1399. PREFIX_LIST_STR)
  1400. {
  1401. return vty_show_prefix_list (vty, AFI_IP, NULL, NULL, normal_display);
  1402. }
  1403. DEFUN (show_ip_prefix_list_name,
  1404. show_ip_prefix_list_name_cmd,
  1405. "show ip prefix-list WORD",
  1406. SHOW_STR
  1407. IP_STR
  1408. PREFIX_LIST_STR
  1409. "Name of a prefix list\n")
  1410. {
  1411. return vty_show_prefix_list (vty, AFI_IP, argv[0], NULL, normal_display);
  1412. }
  1413. DEFUN (show_ip_prefix_list_name_seq,
  1414. show_ip_prefix_list_name_seq_cmd,
  1415. "show ip prefix-list WORD seq <1-4294967295>",
  1416. SHOW_STR
  1417. IP_STR
  1418. PREFIX_LIST_STR
  1419. "Name of a prefix list\n"
  1420. "sequence number of an entry\n"
  1421. "Sequence number\n")
  1422. {
  1423. return vty_show_prefix_list (vty, AFI_IP, argv[0], argv[1], sequential_display);
  1424. }
  1425. DEFUN (show_ip_prefix_list_prefix,
  1426. show_ip_prefix_list_prefix_cmd,
  1427. "show ip prefix-list WORD A.B.C.D/M",
  1428. SHOW_STR
  1429. IP_STR
  1430. PREFIX_LIST_STR
  1431. "Name of a prefix list\n"
  1432. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
  1433. {
  1434. return vty_show_prefix_list_prefix (vty, AFI_IP, argv[0], argv[1], normal_display);
  1435. }
  1436. DEFUN (show_ip_prefix_list_prefix_longer,
  1437. show_ip_prefix_list_prefix_longer_cmd,
  1438. "show ip prefix-list WORD A.B.C.D/M longer",
  1439. SHOW_STR
  1440. IP_STR
  1441. PREFIX_LIST_STR
  1442. "Name of a prefix list\n"
  1443. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1444. "Lookup longer prefix\n")
  1445. {
  1446. return vty_show_prefix_list_prefix (vty, AFI_IP, argv[0], argv[1], longer_display);
  1447. }
  1448. DEFUN (show_ip_prefix_list_prefix_first_match,
  1449. show_ip_prefix_list_prefix_first_match_cmd,
  1450. "show ip prefix-list WORD A.B.C.D/M first-match",
  1451. SHOW_STR
  1452. IP_STR
  1453. PREFIX_LIST_STR
  1454. "Name of a prefix list\n"
  1455. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1456. "First matched prefix\n")
  1457. {
  1458. return vty_show_prefix_list_prefix (vty, AFI_IP, argv[0], argv[1], first_match_display);
  1459. }
  1460. DEFUN (show_ip_prefix_list_summary,
  1461. show_ip_prefix_list_summary_cmd,
  1462. "show ip prefix-list summary",
  1463. SHOW_STR
  1464. IP_STR
  1465. PREFIX_LIST_STR
  1466. "Summary of prefix lists\n")
  1467. {
  1468. return vty_show_prefix_list (vty, AFI_IP, NULL, NULL, summary_display);
  1469. }
  1470. DEFUN (show_ip_prefix_list_summary_name,
  1471. show_ip_prefix_list_summary_name_cmd,
  1472. "show ip prefix-list summary WORD",
  1473. SHOW_STR
  1474. IP_STR
  1475. PREFIX_LIST_STR
  1476. "Summary of prefix lists\n"
  1477. "Name of a prefix list\n")
  1478. {
  1479. return vty_show_prefix_list (vty, AFI_IP, argv[0], NULL, summary_display);
  1480. }
  1481. DEFUN (show_ip_prefix_list_detail,
  1482. show_ip_prefix_list_detail_cmd,
  1483. "show ip prefix-list detail",
  1484. SHOW_STR
  1485. IP_STR
  1486. PREFIX_LIST_STR
  1487. "Detail of prefix lists\n")
  1488. {
  1489. return vty_show_prefix_list (vty, AFI_IP, NULL, NULL, detail_display);
  1490. }
  1491. DEFUN (show_ip_prefix_list_detail_name,
  1492. show_ip_prefix_list_detail_name_cmd,
  1493. "show ip prefix-list detail WORD",
  1494. SHOW_STR
  1495. IP_STR
  1496. PREFIX_LIST_STR
  1497. "Detail of prefix lists\n"
  1498. "Name of a prefix list\n")
  1499. {
  1500. return vty_show_prefix_list (vty, AFI_IP, argv[0], NULL, detail_display);
  1501. }
  1502. DEFUN (clear_ip_prefix_list,
  1503. clear_ip_prefix_list_cmd,
  1504. "clear ip prefix-list",
  1505. CLEAR_STR
  1506. IP_STR
  1507. PREFIX_LIST_STR)
  1508. {
  1509. return vty_clear_prefix_list (vty, AFI_IP, NULL, NULL);
  1510. }
  1511. DEFUN (clear_ip_prefix_list_name,
  1512. clear_ip_prefix_list_name_cmd,
  1513. "clear ip prefix-list WORD",
  1514. CLEAR_STR
  1515. IP_STR
  1516. PREFIX_LIST_STR
  1517. "Name of a prefix list\n")
  1518. {
  1519. return vty_clear_prefix_list (vty, AFI_IP, argv[0], NULL);
  1520. }
  1521. DEFUN (clear_ip_prefix_list_name_prefix,
  1522. clear_ip_prefix_list_name_prefix_cmd,
  1523. "clear ip prefix-list WORD A.B.C.D/M",
  1524. CLEAR_STR
  1525. IP_STR
  1526. PREFIX_LIST_STR
  1527. "Name of a prefix list\n"
  1528. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
  1529. {
  1530. return vty_clear_prefix_list (vty, AFI_IP, argv[0], argv[1]);
  1531. }
  1532. #ifdef HAVE_IPV6
  1533. DEFUN (ipv6_prefix_list,
  1534. ipv6_prefix_list_cmd,
  1535. "ipv6 prefix-list WORD (deny|permit) (X:X::X:X/M|any)",
  1536. IPV6_STR
  1537. PREFIX_LIST_STR
  1538. "Name of a prefix list\n"
  1539. "Specify packets to reject\n"
  1540. "Specify packets to forward\n"
  1541. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1542. "Any prefix match. Same as \"::0/0 le 128\"\n")
  1543. {
  1544. return vty_prefix_list_install (vty, AFI_IP6, argv[0], NULL,
  1545. argv[1], argv[2], NULL, NULL);
  1546. }
  1547. DEFUN (ipv6_prefix_list_ge,
  1548. ipv6_prefix_list_ge_cmd,
  1549. "ipv6 prefix-list WORD (deny|permit) X:X::X:X/M ge <0-128>",
  1550. IPV6_STR
  1551. PREFIX_LIST_STR
  1552. "Name of a prefix list\n"
  1553. "Specify packets to reject\n"
  1554. "Specify packets to forward\n"
  1555. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1556. "Minimum prefix length to be matched\n"
  1557. "Minimum prefix length\n")
  1558. {
  1559. return vty_prefix_list_install (vty, AFI_IP6, argv[0], NULL, argv[1],
  1560. argv[2], argv[3], NULL);
  1561. }
  1562. DEFUN (ipv6_prefix_list_ge_le,
  1563. ipv6_prefix_list_ge_le_cmd,
  1564. "ipv6 prefix-list WORD (deny|permit) X:X::X:X/M ge <0-128> le <0-128>",
  1565. IPV6_STR
  1566. PREFIX_LIST_STR
  1567. "Name of a prefix list\n"
  1568. "Specify packets to reject\n"
  1569. "Specify packets to forward\n"
  1570. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1571. "Minimum prefix length to be matched\n"
  1572. "Minimum prefix length\n"
  1573. "Maximum prefix length to be matched\n"
  1574. "Maximum prefix length\n")
  1575. {
  1576. return vty_prefix_list_install (vty, AFI_IP6, argv[0], NULL, argv[1],
  1577. argv[2], argv[3], argv[4]);
  1578. }
  1579. DEFUN (ipv6_prefix_list_le,
  1580. ipv6_prefix_list_le_cmd,
  1581. "ipv6 prefix-list WORD (deny|permit) X:X::X:X/M le <0-128>",
  1582. IPV6_STR
  1583. PREFIX_LIST_STR
  1584. "Name of a prefix list\n"
  1585. "Specify packets to reject\n"
  1586. "Specify packets to forward\n"
  1587. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1588. "Maximum prefix length to be matched\n"
  1589. "Maximum prefix length\n")
  1590. {
  1591. return vty_prefix_list_install (vty, AFI_IP6, argv[0], NULL, argv[1],
  1592. argv[2], NULL, argv[3]);
  1593. }
  1594. DEFUN (ipv6_prefix_list_le_ge,
  1595. ipv6_prefix_list_le_ge_cmd,
  1596. "ipv6 prefix-list WORD (deny|permit) X:X::X:X/M le <0-128> ge <0-128>",
  1597. IPV6_STR
  1598. PREFIX_LIST_STR
  1599. "Name of a prefix list\n"
  1600. "Specify packets to reject\n"
  1601. "Specify packets to forward\n"
  1602. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1603. "Maximum prefix length to be matched\n"
  1604. "Maximum prefix length\n"
  1605. "Minimum prefix length to be matched\n"
  1606. "Minimum prefix length\n")
  1607. {
  1608. return vty_prefix_list_install (vty, AFI_IP6, argv[0], NULL, argv[1],
  1609. argv[2], argv[4], argv[3]);
  1610. }
  1611. DEFUN (ipv6_prefix_list_seq,
  1612. ipv6_prefix_list_seq_cmd,
  1613. "ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) (X:X::X:X/M|any)",
  1614. IPV6_STR
  1615. PREFIX_LIST_STR
  1616. "Name of a prefix list\n"
  1617. "sequence number of an entry\n"
  1618. "Sequence number\n"
  1619. "Specify packets to reject\n"
  1620. "Specify packets to forward\n"
  1621. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1622. "Any prefix match. Same as \"::0/0 le 128\"\n")
  1623. {
  1624. return vty_prefix_list_install (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1625. argv[3], NULL, NULL);
  1626. }
  1627. DEFUN (ipv6_prefix_list_seq_ge,
  1628. ipv6_prefix_list_seq_ge_cmd,
  1629. "ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M ge <0-128>",
  1630. IPV6_STR
  1631. PREFIX_LIST_STR
  1632. "Name of a prefix list\n"
  1633. "sequence number of an entry\n"
  1634. "Sequence number\n"
  1635. "Specify packets to reject\n"
  1636. "Specify packets to forward\n"
  1637. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1638. "Minimum prefix length to be matched\n"
  1639. "Minimum prefix length\n")
  1640. {
  1641. return vty_prefix_list_install (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1642. argv[3], argv[4], NULL);
  1643. }
  1644. DEFUN (ipv6_prefix_list_seq_ge_le,
  1645. ipv6_prefix_list_seq_ge_le_cmd,
  1646. "ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M ge <0-128> le <0-128>",
  1647. IPV6_STR
  1648. PREFIX_LIST_STR
  1649. "Name of a prefix list\n"
  1650. "sequence number of an entry\n"
  1651. "Sequence number\n"
  1652. "Specify packets to reject\n"
  1653. "Specify packets to forward\n"
  1654. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1655. "Minimum prefix length to be matched\n"
  1656. "Minimum prefix length\n"
  1657. "Maximum prefix length to be matched\n"
  1658. "Maximum prefix length\n")
  1659. {
  1660. return vty_prefix_list_install (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1661. argv[3], argv[4], argv[5]);
  1662. }
  1663. DEFUN (ipv6_prefix_list_seq_le,
  1664. ipv6_prefix_list_seq_le_cmd,
  1665. "ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M le <0-128>",
  1666. IPV6_STR
  1667. PREFIX_LIST_STR
  1668. "Name of a prefix list\n"
  1669. "sequence number of an entry\n"
  1670. "Sequence number\n"
  1671. "Specify packets to reject\n"
  1672. "Specify packets to forward\n"
  1673. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1674. "Maximum prefix length to be matched\n"
  1675. "Maximum prefix length\n")
  1676. {
  1677. return vty_prefix_list_install (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1678. argv[3], NULL, argv[4]);
  1679. }
  1680. DEFUN (ipv6_prefix_list_seq_le_ge,
  1681. ipv6_prefix_list_seq_le_ge_cmd,
  1682. "ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M le <0-128> ge <0-128>",
  1683. IPV6_STR
  1684. PREFIX_LIST_STR
  1685. "Name of a prefix list\n"
  1686. "sequence number of an entry\n"
  1687. "Sequence number\n"
  1688. "Specify packets to reject\n"
  1689. "Specify packets to forward\n"
  1690. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1691. "Maximum prefix length to be matched\n"
  1692. "Maximum prefix length\n"
  1693. "Minimum prefix length to be matched\n"
  1694. "Minimum prefix length\n")
  1695. {
  1696. return vty_prefix_list_install (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1697. argv[3], argv[5], argv[4]);
  1698. }
  1699. DEFUN (no_ipv6_prefix_list,
  1700. no_ipv6_prefix_list_cmd,
  1701. "no ipv6 prefix-list WORD",
  1702. NO_STR
  1703. IPV6_STR
  1704. PREFIX_LIST_STR
  1705. "Name of a prefix list\n")
  1706. {
  1707. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, NULL,
  1708. NULL, NULL, NULL);
  1709. }
  1710. DEFUN (no_ipv6_prefix_list_prefix,
  1711. no_ipv6_prefix_list_prefix_cmd,
  1712. "no ipv6 prefix-list WORD (deny|permit) (X:X::X:X/M|any)",
  1713. NO_STR
  1714. IPV6_STR
  1715. PREFIX_LIST_STR
  1716. "Name of a prefix list\n"
  1717. "Specify packets to reject\n"
  1718. "Specify packets to forward\n"
  1719. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1720. "Any prefix match. Same as \"::0/0 le 128\"\n")
  1721. {
  1722. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, argv[1],
  1723. argv[2], NULL, NULL);
  1724. }
  1725. DEFUN (no_ipv6_prefix_list_ge,
  1726. no_ipv6_prefix_list_ge_cmd,
  1727. "no ipv6 prefix-list WORD (deny|permit) X:X::X:X/M ge <0-128>",
  1728. NO_STR
  1729. IPV6_STR
  1730. PREFIX_LIST_STR
  1731. "Name of a prefix list\n"
  1732. "Specify packets to reject\n"
  1733. "Specify packets to forward\n"
  1734. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1735. "Minimum prefix length to be matched\n"
  1736. "Minimum prefix length\n")
  1737. {
  1738. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, argv[1],
  1739. argv[2], argv[3], NULL);
  1740. }
  1741. DEFUN (no_ipv6_prefix_list_ge_le,
  1742. no_ipv6_prefix_list_ge_le_cmd,
  1743. "no ipv6 prefix-list WORD (deny|permit) X:X::X:X/M ge <0-128> le <0-128>",
  1744. NO_STR
  1745. IPV6_STR
  1746. PREFIX_LIST_STR
  1747. "Name of a prefix list\n"
  1748. "Specify packets to reject\n"
  1749. "Specify packets to forward\n"
  1750. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1751. "Minimum prefix length to be matched\n"
  1752. "Minimum prefix length\n"
  1753. "Maximum prefix length to be matched\n"
  1754. "Maximum prefix length\n")
  1755. {
  1756. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, argv[1],
  1757. argv[2], argv[3], argv[4]);
  1758. }
  1759. DEFUN (no_ipv6_prefix_list_le,
  1760. no_ipv6_prefix_list_le_cmd,
  1761. "no ipv6 prefix-list WORD (deny|permit) X:X::X:X/M le <0-128>",
  1762. NO_STR
  1763. IPV6_STR
  1764. PREFIX_LIST_STR
  1765. "Name of a prefix list\n"
  1766. "Specify packets to reject\n"
  1767. "Specify packets to forward\n"
  1768. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1769. "Maximum prefix length to be matched\n"
  1770. "Maximum prefix length\n")
  1771. {
  1772. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, argv[1],
  1773. argv[2], NULL, argv[3]);
  1774. }
  1775. DEFUN (no_ipv6_prefix_list_le_ge,
  1776. no_ipv6_prefix_list_le_ge_cmd,
  1777. "no ipv6 prefix-list WORD (deny|permit) X:X::X:X/M le <0-128> ge <0-128>",
  1778. NO_STR
  1779. IPV6_STR
  1780. PREFIX_LIST_STR
  1781. "Name of a prefix list\n"
  1782. "Specify packets to reject\n"
  1783. "Specify packets to forward\n"
  1784. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1785. "Maximum prefix length to be matched\n"
  1786. "Maximum prefix length\n"
  1787. "Minimum prefix length to be matched\n"
  1788. "Minimum prefix length\n")
  1789. {
  1790. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, argv[1],
  1791. argv[2], argv[4], argv[3]);
  1792. }
  1793. DEFUN (no_ipv6_prefix_list_seq,
  1794. no_ipv6_prefix_list_seq_cmd,
  1795. "no ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) (X:X::X:X/M|any)",
  1796. NO_STR
  1797. IPV6_STR
  1798. PREFIX_LIST_STR
  1799. "Name of a prefix list\n"
  1800. "sequence number of an entry\n"
  1801. "Sequence number\n"
  1802. "Specify packets to reject\n"
  1803. "Specify packets to forward\n"
  1804. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1805. "Any prefix match. Same as \"::0/0 le 128\"\n")
  1806. {
  1807. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1808. argv[3], NULL, NULL);
  1809. }
  1810. DEFUN (no_ipv6_prefix_list_seq_ge,
  1811. no_ipv6_prefix_list_seq_ge_cmd,
  1812. "no ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M ge <0-128>",
  1813. NO_STR
  1814. IPV6_STR
  1815. PREFIX_LIST_STR
  1816. "Name of a prefix list\n"
  1817. "sequence number of an entry\n"
  1818. "Sequence number\n"
  1819. "Specify packets to reject\n"
  1820. "Specify packets to forward\n"
  1821. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1822. "Minimum prefix length to be matched\n"
  1823. "Minimum prefix length\n")
  1824. {
  1825. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1826. argv[3], argv[4], NULL);
  1827. }
  1828. DEFUN (no_ipv6_prefix_list_seq_ge_le,
  1829. no_ipv6_prefix_list_seq_ge_le_cmd,
  1830. "no ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M ge <0-128> le <0-128>",
  1831. NO_STR
  1832. IPV6_STR
  1833. PREFIX_LIST_STR
  1834. "Name of a prefix list\n"
  1835. "sequence number of an entry\n"
  1836. "Sequence number\n"
  1837. "Specify packets to reject\n"
  1838. "Specify packets to forward\n"
  1839. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1840. "Minimum prefix length to be matched\n"
  1841. "Minimum prefix length\n"
  1842. "Maximum prefix length to be matched\n"
  1843. "Maximum prefix length\n")
  1844. {
  1845. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1846. argv[3], argv[4], argv[5]);
  1847. }
  1848. DEFUN (no_ipv6_prefix_list_seq_le,
  1849. no_ipv6_prefix_list_seq_le_cmd,
  1850. "no ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M le <0-128>",
  1851. NO_STR
  1852. IPV6_STR
  1853. PREFIX_LIST_STR
  1854. "Name of a prefix list\n"
  1855. "sequence number of an entry\n"
  1856. "Sequence number\n"
  1857. "Specify packets to reject\n"
  1858. "Specify packets to forward\n"
  1859. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1860. "Maximum prefix length to be matched\n"
  1861. "Maximum prefix length\n")
  1862. {
  1863. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1864. argv[3], NULL, argv[4]);
  1865. }
  1866. DEFUN (no_ipv6_prefix_list_seq_le_ge,
  1867. no_ipv6_prefix_list_seq_le_ge_cmd,
  1868. "no ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M le <0-128> ge <0-128>",
  1869. NO_STR
  1870. IPV6_STR
  1871. PREFIX_LIST_STR
  1872. "Name of a prefix list\n"
  1873. "sequence number of an entry\n"
  1874. "Sequence number\n"
  1875. "Specify packets to reject\n"
  1876. "Specify packets to forward\n"
  1877. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1878. "Maximum prefix length to be matched\n"
  1879. "Maximum prefix length\n"
  1880. "Minimum prefix length to be matched\n"
  1881. "Minimum prefix length\n")
  1882. {
  1883. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1884. argv[3], argv[5], argv[4]);
  1885. }
  1886. DEFUN (ipv6_prefix_list_sequence_number,
  1887. ipv6_prefix_list_sequence_number_cmd,
  1888. "ipv6 prefix-list sequence-number",
  1889. IPV6_STR
  1890. PREFIX_LIST_STR
  1891. "Include/exclude sequence numbers in NVGEN\n")
  1892. {
  1893. prefix_master_ipv6.seqnum = 1;
  1894. return CMD_SUCCESS;
  1895. }
  1896. DEFUN (no_ipv6_prefix_list_sequence_number,
  1897. no_ipv6_prefix_list_sequence_number_cmd,
  1898. "no ipv6 prefix-list sequence-number",
  1899. NO_STR
  1900. IPV6_STR
  1901. PREFIX_LIST_STR
  1902. "Include/exclude sequence numbers in NVGEN\n")
  1903. {
  1904. prefix_master_ipv6.seqnum = 0;
  1905. return CMD_SUCCESS;
  1906. }
  1907. DEFUN (ipv6_prefix_list_description,
  1908. ipv6_prefix_list_description_cmd,
  1909. "ipv6 prefix-list WORD description .LINE",
  1910. IPV6_STR
  1911. PREFIX_LIST_STR
  1912. "Name of a prefix list\n"
  1913. "Prefix-list specific description\n"
  1914. "Up to 80 characters describing this prefix-list\n")
  1915. {
  1916. struct prefix_list *plist;
  1917. plist = prefix_list_get (AFI_IP6, 0, argv[0]);
  1918. if (plist->desc)
  1919. {
  1920. XFREE (MTYPE_TMP, plist->desc);
  1921. plist->desc = NULL;
  1922. }
  1923. plist->desc = argv_concat(argv, argc, 1);
  1924. return CMD_SUCCESS;
  1925. }
  1926. DEFUN (no_ipv6_prefix_list_description,
  1927. no_ipv6_prefix_list_description_cmd,
  1928. "no ipv6 prefix-list WORD description",
  1929. NO_STR
  1930. IPV6_STR
  1931. PREFIX_LIST_STR
  1932. "Name of a prefix list\n"
  1933. "Prefix-list specific description\n")
  1934. {
  1935. return vty_prefix_list_desc_unset (vty, AFI_IP6, argv[0]);
  1936. }
  1937. ALIAS (no_ipv6_prefix_list_description,
  1938. no_ipv6_prefix_list_description_arg_cmd,
  1939. "no ipv6 prefix-list WORD description .LINE",
  1940. NO_STR
  1941. IPV6_STR
  1942. PREFIX_LIST_STR
  1943. "Name of a prefix list\n"
  1944. "Prefix-list specific description\n"
  1945. "Up to 80 characters describing this prefix-list\n")
  1946. DEFUN (show_ipv6_prefix_list,
  1947. show_ipv6_prefix_list_cmd,
  1948. "show ipv6 prefix-list",
  1949. SHOW_STR
  1950. IPV6_STR
  1951. PREFIX_LIST_STR)
  1952. {
  1953. return vty_show_prefix_list (vty, AFI_IP6, NULL, NULL, normal_display);
  1954. }
  1955. DEFUN (show_ipv6_prefix_list_name,
  1956. show_ipv6_prefix_list_name_cmd,
  1957. "show ipv6 prefix-list WORD",
  1958. SHOW_STR
  1959. IPV6_STR
  1960. PREFIX_LIST_STR
  1961. "Name of a prefix list\n")
  1962. {
  1963. return vty_show_prefix_list (vty, AFI_IP6, argv[0], NULL, normal_display);
  1964. }
  1965. DEFUN (show_ipv6_prefix_list_name_seq,
  1966. show_ipv6_prefix_list_name_seq_cmd,
  1967. "show ipv6 prefix-list WORD seq <1-4294967295>",
  1968. SHOW_STR
  1969. IPV6_STR
  1970. PREFIX_LIST_STR
  1971. "Name of a prefix list\n"
  1972. "sequence number of an entry\n"
  1973. "Sequence number\n")
  1974. {
  1975. return vty_show_prefix_list (vty, AFI_IP6, argv[0], argv[1], sequential_display);
  1976. }
  1977. DEFUN (show_ipv6_prefix_list_prefix,
  1978. show_ipv6_prefix_list_prefix_cmd,
  1979. "show ipv6 prefix-list WORD X:X::X:X/M",
  1980. SHOW_STR
  1981. IPV6_STR
  1982. PREFIX_LIST_STR
  1983. "Name of a prefix list\n"
  1984. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
  1985. {
  1986. return vty_show_prefix_list_prefix (vty, AFI_IP6, argv[0], argv[1], normal_display);
  1987. }
  1988. DEFUN (show_ipv6_prefix_list_prefix_longer,
  1989. show_ipv6_prefix_list_prefix_longer_cmd,
  1990. "show ipv6 prefix-list WORD X:X::X:X/M longer",
  1991. SHOW_STR
  1992. IPV6_STR
  1993. PREFIX_LIST_STR
  1994. "Name of a prefix list\n"
  1995. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1996. "Lookup longer prefix\n")
  1997. {
  1998. return vty_show_prefix_list_prefix (vty, AFI_IP6, argv[0], argv[1], longer_display);
  1999. }
  2000. DEFUN (show_ipv6_prefix_list_prefix_first_match,
  2001. show_ipv6_prefix_list_prefix_first_match_cmd,
  2002. "show ipv6 prefix-list WORD X:X::X:X/M first-match",
  2003. SHOW_STR
  2004. IPV6_STR
  2005. PREFIX_LIST_STR
  2006. "Name of a prefix list\n"
  2007. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  2008. "First matched prefix\n")
  2009. {
  2010. return vty_show_prefix_list_prefix (vty, AFI_IP6, argv[0], argv[1], first_match_display);
  2011. }
  2012. DEFUN (show_ipv6_prefix_list_summary,
  2013. show_ipv6_prefix_list_summary_cmd,
  2014. "show ipv6 prefix-list summary",
  2015. SHOW_STR
  2016. IPV6_STR
  2017. PREFIX_LIST_STR
  2018. "Summary of prefix lists\n")
  2019. {
  2020. return vty_show_prefix_list (vty, AFI_IP6, NULL, NULL, summary_display);
  2021. }
  2022. DEFUN (show_ipv6_prefix_list_summary_name,
  2023. show_ipv6_prefix_list_summary_name_cmd,
  2024. "show ipv6 prefix-list summary WORD",
  2025. SHOW_STR
  2026. IPV6_STR
  2027. PREFIX_LIST_STR
  2028. "Summary of prefix lists\n"
  2029. "Name of a prefix list\n")
  2030. {
  2031. return vty_show_prefix_list (vty, AFI_IP6, argv[0], NULL, summary_display);
  2032. }
  2033. DEFUN (show_ipv6_prefix_list_detail,
  2034. show_ipv6_prefix_list_detail_cmd,
  2035. "show ipv6 prefix-list detail",
  2036. SHOW_STR
  2037. IPV6_STR
  2038. PREFIX_LIST_STR
  2039. "Detail of prefix lists\n")
  2040. {
  2041. return vty_show_prefix_list (vty, AFI_IP6, NULL, NULL, detail_display);
  2042. }
  2043. DEFUN (show_ipv6_prefix_list_detail_name,
  2044. show_ipv6_prefix_list_detail_name_cmd,
  2045. "show ipv6 prefix-list detail WORD",
  2046. SHOW_STR
  2047. IPV6_STR
  2048. PREFIX_LIST_STR
  2049. "Detail of prefix lists\n"
  2050. "Name of a prefix list\n")
  2051. {
  2052. return vty_show_prefix_list (vty, AFI_IP6, argv[0], NULL, detail_display);
  2053. }
  2054. DEFUN (clear_ipv6_prefix_list,
  2055. clear_ipv6_prefix_list_cmd,
  2056. "clear ipv6 prefix-list",
  2057. CLEAR_STR
  2058. IPV6_STR
  2059. PREFIX_LIST_STR)
  2060. {
  2061. return vty_clear_prefix_list (vty, AFI_IP6, NULL, NULL);
  2062. }
  2063. DEFUN (clear_ipv6_prefix_list_name,
  2064. clear_ipv6_prefix_list_name_cmd,
  2065. "clear ipv6 prefix-list WORD",
  2066. CLEAR_STR
  2067. IPV6_STR
  2068. PREFIX_LIST_STR
  2069. "Name of a prefix list\n")
  2070. {
  2071. return vty_clear_prefix_list (vty, AFI_IP6, argv[0], NULL);
  2072. }
  2073. DEFUN (clear_ipv6_prefix_list_name_prefix,
  2074. clear_ipv6_prefix_list_name_prefix_cmd,
  2075. "clear ipv6 prefix-list WORD X:X::X:X/M",
  2076. CLEAR_STR
  2077. IPV6_STR
  2078. PREFIX_LIST_STR
  2079. "Name of a prefix list\n"
  2080. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
  2081. {
  2082. return vty_clear_prefix_list (vty, AFI_IP6, argv[0], argv[1]);
  2083. }
  2084. #endif /* HAVE_IPV6 */
  2085. /* Configuration write function. */
  2086. static int
  2087. config_write_prefix_afi (afi_t afi, struct vty *vty)
  2088. {
  2089. struct prefix_list *plist;
  2090. struct prefix_list_entry *pentry;
  2091. struct prefix_master *master;
  2092. int write = 0;
  2093. master = prefix_master_get (afi, 0);
  2094. if (master == NULL)
  2095. return 0;
  2096. if (! master->seqnum)
  2097. {
  2098. vty_out (vty, "no ip%s prefix-list sequence-number%s",
  2099. afi == AFI_IP ? "" : "v6", VTY_NEWLINE);
  2100. vty_out (vty, "!%s", VTY_NEWLINE);
  2101. }
  2102. for (plist = master->num.head; plist; plist = plist->next)
  2103. {
  2104. if (plist->desc)
  2105. {
  2106. vty_out (vty, "ip%s prefix-list %s description %s%s",
  2107. afi == AFI_IP ? "" : "v6",
  2108. plist->name, plist->desc, VTY_NEWLINE);
  2109. write++;
  2110. }
  2111. for (pentry = plist->head; pentry; pentry = pentry->next)
  2112. {
  2113. vty_out (vty, "ip%s prefix-list %s ",
  2114. afi == AFI_IP ? "" : "v6",
  2115. plist->name);
  2116. if (master->seqnum)
  2117. vty_out (vty, "seq %d ", pentry->seq);
  2118. vty_out (vty, "%s ", prefix_list_type_str (pentry));
  2119. if (pentry->any)
  2120. vty_out (vty, "any");
  2121. else
  2122. {
  2123. struct prefix *p = &pentry->prefix;
  2124. char buf[BUFSIZ];
  2125. vty_out (vty, "%s/%d",
  2126. inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
  2127. p->prefixlen);
  2128. if (pentry->ge)
  2129. vty_out (vty, " ge %d", pentry->ge);
  2130. if (pentry->le)
  2131. vty_out (vty, " le %d", pentry->le);
  2132. }
  2133. vty_out (vty, "%s", VTY_NEWLINE);
  2134. write++;
  2135. }
  2136. /* vty_out (vty, "!%s", VTY_NEWLINE); */
  2137. }
  2138. for (plist = master->str.head; plist; plist = plist->next)
  2139. {
  2140. if (plist->desc)
  2141. {
  2142. vty_out (vty, "ip%s prefix-list %s description %s%s",
  2143. afi == AFI_IP ? "" : "v6",
  2144. plist->name, plist->desc, VTY_NEWLINE);
  2145. write++;
  2146. }
  2147. for (pentry = plist->head; pentry; pentry = pentry->next)
  2148. {
  2149. vty_out (vty, "ip%s prefix-list %s ",
  2150. afi == AFI_IP ? "" : "v6",
  2151. plist->name);
  2152. if (master->seqnum)
  2153. vty_out (vty, "seq %d ", pentry->seq);
  2154. vty_out (vty, "%s", prefix_list_type_str (pentry));
  2155. if (pentry->any)
  2156. vty_out (vty, " any");
  2157. else
  2158. {
  2159. struct prefix *p = &pentry->prefix;
  2160. char buf[BUFSIZ];
  2161. vty_out (vty, " %s/%d",
  2162. inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
  2163. p->prefixlen);
  2164. if (pentry->ge)
  2165. vty_out (vty, " ge %d", pentry->ge);
  2166. if (pentry->le)
  2167. vty_out (vty, " le %d", pentry->le);
  2168. }
  2169. vty_out (vty, "%s", VTY_NEWLINE);
  2170. write++;
  2171. }
  2172. }
  2173. return write;
  2174. }
  2175. struct stream *
  2176. prefix_bgp_orf_entry (struct stream *s, struct prefix_list *plist,
  2177. u_char init_flag, u_char permit_flag, u_char deny_flag)
  2178. {
  2179. struct prefix_list_entry *pentry;
  2180. if (! plist)
  2181. return s;
  2182. for (pentry = plist->head; pentry; pentry = pentry->next)
  2183. {
  2184. u_char flag = init_flag;
  2185. struct prefix *p = &pentry->prefix;
  2186. flag |= (pentry->type == PREFIX_PERMIT ?
  2187. permit_flag : deny_flag);
  2188. stream_putc (s, flag);
  2189. stream_putl (s, (u_int32_t)pentry->seq);
  2190. stream_putc (s, (u_char)pentry->ge);
  2191. stream_putc (s, (u_char)pentry->le);
  2192. stream_put_prefix (s, p);
  2193. }
  2194. return s;
  2195. }
  2196. int
  2197. prefix_bgp_orf_set (char *name, afi_t afi, struct orf_prefix *orfp,
  2198. int permit, int set)
  2199. {
  2200. struct prefix_list *plist;
  2201. struct prefix_list_entry *pentry;
  2202. /* ge and le value check */
  2203. if (orfp->ge && orfp->ge <= orfp->p.prefixlen)
  2204. return CMD_WARNING;
  2205. if (orfp->le && orfp->le <= orfp->p.prefixlen)
  2206. return CMD_WARNING;
  2207. if (orfp->le && orfp->ge > orfp->le)
  2208. return CMD_WARNING;
  2209. if (orfp->ge && orfp->le == (afi == AFI_IP ? 32 : 128))
  2210. orfp->le = 0;
  2211. plist = prefix_list_get (afi, 1, name);
  2212. if (! plist)
  2213. return CMD_WARNING;
  2214. if (set)
  2215. {
  2216. pentry = prefix_list_entry_make (&orfp->p,
  2217. (permit ? PREFIX_PERMIT : PREFIX_DENY),
  2218. orfp->seq, orfp->le, orfp->ge, 0);
  2219. if (prefix_entry_dup_check (plist, pentry))
  2220. {
  2221. prefix_list_entry_free (pentry);
  2222. return CMD_WARNING;
  2223. }
  2224. prefix_list_entry_add (plist, pentry);
  2225. }
  2226. else
  2227. {
  2228. pentry = prefix_list_entry_lookup (plist, &orfp->p,
  2229. (permit ? PREFIX_PERMIT : PREFIX_DENY),
  2230. orfp->seq, orfp->le, orfp->ge);
  2231. if (! pentry)
  2232. return CMD_WARNING;
  2233. prefix_list_entry_delete (plist, pentry, 1);
  2234. }
  2235. return CMD_SUCCESS;
  2236. }
  2237. void
  2238. prefix_bgp_orf_remove_all (afi_t afi, char *name)
  2239. {
  2240. struct prefix_list *plist;
  2241. plist = prefix_bgp_orf_lookup (afi, name);
  2242. if (plist)
  2243. prefix_list_delete (plist);
  2244. }
  2245. /* return prefix count */
  2246. int
  2247. prefix_bgp_show_prefix_list (struct vty *vty, afi_t afi, char *name)
  2248. {
  2249. struct prefix_list *plist;
  2250. struct prefix_list_entry *pentry;
  2251. plist = prefix_bgp_orf_lookup (afi, name);
  2252. if (! plist)
  2253. return 0;
  2254. if (! vty)
  2255. return plist->count;
  2256. vty_out (vty, "ip%s prefix-list %s: %d entries%s",
  2257. afi == AFI_IP ? "" : "v6",
  2258. plist->name, plist->count, VTY_NEWLINE);
  2259. for (pentry = plist->head; pentry; pentry = pentry->next)
  2260. {
  2261. struct prefix *p = &pentry->prefix;
  2262. char buf[BUFSIZ];
  2263. vty_out (vty, " seq %d %s %s/%d", pentry->seq,
  2264. prefix_list_type_str (pentry),
  2265. inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
  2266. p->prefixlen);
  2267. if (pentry->ge)
  2268. vty_out (vty, " ge %d", pentry->ge);
  2269. if (pentry->le)
  2270. vty_out (vty, " le %d", pentry->le);
  2271. vty_out (vty, "%s", VTY_NEWLINE);
  2272. }
  2273. return plist->count;
  2274. }
  2275. static void
  2276. prefix_list_reset_afi (afi_t afi, int orf)
  2277. {
  2278. struct prefix_list *plist;
  2279. struct prefix_list *next;
  2280. struct prefix_master *master;
  2281. master = prefix_master_get (afi, orf);
  2282. if (master == NULL)
  2283. return;
  2284. for (plist = master->num.head; plist; plist = next)
  2285. {
  2286. next = plist->next;
  2287. prefix_list_delete (plist);
  2288. }
  2289. for (plist = master->str.head; plist; plist = next)
  2290. {
  2291. next = plist->next;
  2292. prefix_list_delete (plist);
  2293. }
  2294. assert (master->num.head == NULL);
  2295. assert (master->num.tail == NULL);
  2296. assert (master->str.head == NULL);
  2297. assert (master->str.tail == NULL);
  2298. master->seqnum = 1;
  2299. master->recent = NULL;
  2300. }
  2301. /* Prefix-list node. */
  2302. static struct cmd_node prefix_node =
  2303. {
  2304. PREFIX_NODE,
  2305. "", /* Prefix list has no interface. */
  2306. 1
  2307. };
  2308. static int
  2309. config_write_prefix_ipv4 (struct vty *vty)
  2310. {
  2311. return config_write_prefix_afi (AFI_IP, vty);
  2312. }
  2313. static void
  2314. prefix_list_init_ipv4 (void)
  2315. {
  2316. install_node (&prefix_node, config_write_prefix_ipv4);
  2317. install_element (CONFIG_NODE, &ip_prefix_list_cmd);
  2318. install_element (CONFIG_NODE, &ip_prefix_list_ge_cmd);
  2319. install_element (CONFIG_NODE, &ip_prefix_list_ge_le_cmd);
  2320. install_element (CONFIG_NODE, &ip_prefix_list_le_cmd);
  2321. install_element (CONFIG_NODE, &ip_prefix_list_le_ge_cmd);
  2322. install_element (CONFIG_NODE, &ip_prefix_list_seq_cmd);
  2323. install_element (CONFIG_NODE, &ip_prefix_list_seq_ge_cmd);
  2324. install_element (CONFIG_NODE, &ip_prefix_list_seq_ge_le_cmd);
  2325. install_element (CONFIG_NODE, &ip_prefix_list_seq_le_cmd);
  2326. install_element (CONFIG_NODE, &ip_prefix_list_seq_le_ge_cmd);
  2327. install_element (CONFIG_NODE, &no_ip_prefix_list_cmd);
  2328. install_element (CONFIG_NODE, &no_ip_prefix_list_prefix_cmd);
  2329. install_element (CONFIG_NODE, &no_ip_prefix_list_ge_cmd);
  2330. install_element (CONFIG_NODE, &no_ip_prefix_list_ge_le_cmd);
  2331. install_element (CONFIG_NODE, &no_ip_prefix_list_le_cmd);
  2332. install_element (CONFIG_NODE, &no_ip_prefix_list_le_ge_cmd);
  2333. install_element (CONFIG_NODE, &no_ip_prefix_list_seq_cmd);
  2334. install_element (CONFIG_NODE, &no_ip_prefix_list_seq_ge_cmd);
  2335. install_element (CONFIG_NODE, &no_ip_prefix_list_seq_ge_le_cmd);
  2336. install_element (CONFIG_NODE, &no_ip_prefix_list_seq_le_cmd);
  2337. install_element (CONFIG_NODE, &no_ip_prefix_list_seq_le_ge_cmd);
  2338. install_element (CONFIG_NODE, &ip_prefix_list_description_cmd);
  2339. install_element (CONFIG_NODE, &no_ip_prefix_list_description_cmd);
  2340. install_element (CONFIG_NODE, &no_ip_prefix_list_description_arg_cmd);
  2341. install_element (CONFIG_NODE, &ip_prefix_list_sequence_number_cmd);
  2342. install_element (CONFIG_NODE, &no_ip_prefix_list_sequence_number_cmd);
  2343. install_element (VIEW_NODE, &show_ip_prefix_list_cmd);
  2344. install_element (VIEW_NODE, &show_ip_prefix_list_name_cmd);
  2345. install_element (VIEW_NODE, &show_ip_prefix_list_name_seq_cmd);
  2346. install_element (VIEW_NODE, &show_ip_prefix_list_prefix_cmd);
  2347. install_element (VIEW_NODE, &show_ip_prefix_list_prefix_longer_cmd);
  2348. install_element (VIEW_NODE, &show_ip_prefix_list_prefix_first_match_cmd);
  2349. install_element (VIEW_NODE, &show_ip_prefix_list_summary_cmd);
  2350. install_element (VIEW_NODE, &show_ip_prefix_list_summary_name_cmd);
  2351. install_element (VIEW_NODE, &show_ip_prefix_list_detail_cmd);
  2352. install_element (VIEW_NODE, &show_ip_prefix_list_detail_name_cmd);
  2353. install_element (ENABLE_NODE, &show_ip_prefix_list_cmd);
  2354. install_element (ENABLE_NODE, &show_ip_prefix_list_name_cmd);
  2355. install_element (ENABLE_NODE, &show_ip_prefix_list_name_seq_cmd);
  2356. install_element (ENABLE_NODE, &show_ip_prefix_list_prefix_cmd);
  2357. install_element (ENABLE_NODE, &show_ip_prefix_list_prefix_longer_cmd);
  2358. install_element (ENABLE_NODE, &show_ip_prefix_list_prefix_first_match_cmd);
  2359. install_element (ENABLE_NODE, &show_ip_prefix_list_summary_cmd);
  2360. install_element (ENABLE_NODE, &show_ip_prefix_list_summary_name_cmd);
  2361. install_element (ENABLE_NODE, &show_ip_prefix_list_detail_cmd);
  2362. install_element (ENABLE_NODE, &show_ip_prefix_list_detail_name_cmd);
  2363. install_element (ENABLE_NODE, &clear_ip_prefix_list_cmd);
  2364. install_element (ENABLE_NODE, &clear_ip_prefix_list_name_cmd);
  2365. install_element (ENABLE_NODE, &clear_ip_prefix_list_name_prefix_cmd);
  2366. }
  2367. #ifdef HAVE_IPV6
  2368. /* Prefix-list node. */
  2369. static struct cmd_node prefix_ipv6_node =
  2370. {
  2371. PREFIX_IPV6_NODE,
  2372. "", /* Prefix list has no interface. */
  2373. 1
  2374. };
  2375. static int
  2376. config_write_prefix_ipv6 (struct vty *vty)
  2377. {
  2378. return config_write_prefix_afi (AFI_IP6, vty);
  2379. }
  2380. static void
  2381. prefix_list_init_ipv6 (void)
  2382. {
  2383. install_node (&prefix_ipv6_node, config_write_prefix_ipv6);
  2384. install_element (CONFIG_NODE, &ipv6_prefix_list_cmd);
  2385. install_element (CONFIG_NODE, &ipv6_prefix_list_ge_cmd);
  2386. install_element (CONFIG_NODE, &ipv6_prefix_list_ge_le_cmd);
  2387. install_element (CONFIG_NODE, &ipv6_prefix_list_le_cmd);
  2388. install_element (CONFIG_NODE, &ipv6_prefix_list_le_ge_cmd);
  2389. install_element (CONFIG_NODE, &ipv6_prefix_list_seq_cmd);
  2390. install_element (CONFIG_NODE, &ipv6_prefix_list_seq_ge_cmd);
  2391. install_element (CONFIG_NODE, &ipv6_prefix_list_seq_ge_le_cmd);
  2392. install_element (CONFIG_NODE, &ipv6_prefix_list_seq_le_cmd);
  2393. install_element (CONFIG_NODE, &ipv6_prefix_list_seq_le_ge_cmd);
  2394. install_element (CONFIG_NODE, &no_ipv6_prefix_list_cmd);
  2395. install_element (CONFIG_NODE, &no_ipv6_prefix_list_prefix_cmd);
  2396. install_element (CONFIG_NODE, &no_ipv6_prefix_list_ge_cmd);
  2397. install_element (CONFIG_NODE, &no_ipv6_prefix_list_ge_le_cmd);
  2398. install_element (CONFIG_NODE, &no_ipv6_prefix_list_le_cmd);
  2399. install_element (CONFIG_NODE, &no_ipv6_prefix_list_le_ge_cmd);
  2400. install_element (CONFIG_NODE, &no_ipv6_prefix_list_seq_cmd);
  2401. install_element (CONFIG_NODE, &no_ipv6_prefix_list_seq_ge_cmd);
  2402. install_element (CONFIG_NODE, &no_ipv6_prefix_list_seq_ge_le_cmd);
  2403. install_element (CONFIG_NODE, &no_ipv6_prefix_list_seq_le_cmd);
  2404. install_element (CONFIG_NODE, &no_ipv6_prefix_list_seq_le_ge_cmd);
  2405. install_element (CONFIG_NODE, &ipv6_prefix_list_description_cmd);
  2406. install_element (CONFIG_NODE, &no_ipv6_prefix_list_description_cmd);
  2407. install_element (CONFIG_NODE, &no_ipv6_prefix_list_description_arg_cmd);
  2408. install_element (CONFIG_NODE, &ipv6_prefix_list_sequence_number_cmd);
  2409. install_element (CONFIG_NODE, &no_ipv6_prefix_list_sequence_number_cmd);
  2410. install_element (VIEW_NODE, &show_ipv6_prefix_list_cmd);
  2411. install_element (VIEW_NODE, &show_ipv6_prefix_list_name_cmd);
  2412. install_element (VIEW_NODE, &show_ipv6_prefix_list_name_seq_cmd);
  2413. install_element (VIEW_NODE, &show_ipv6_prefix_list_prefix_cmd);
  2414. install_element (VIEW_NODE, &show_ipv6_prefix_list_prefix_longer_cmd);
  2415. install_element (VIEW_NODE, &show_ipv6_prefix_list_prefix_first_match_cmd);
  2416. install_element (VIEW_NODE, &show_ipv6_prefix_list_summary_cmd);
  2417. install_element (VIEW_NODE, &show_ipv6_prefix_list_summary_name_cmd);
  2418. install_element (VIEW_NODE, &show_ipv6_prefix_list_detail_cmd);
  2419. install_element (VIEW_NODE, &show_ipv6_prefix_list_detail_name_cmd);
  2420. install_element (ENABLE_NODE, &show_ipv6_prefix_list_cmd);
  2421. install_element (ENABLE_NODE, &show_ipv6_prefix_list_name_cmd);
  2422. install_element (ENABLE_NODE, &show_ipv6_prefix_list_name_seq_cmd);
  2423. install_element (ENABLE_NODE, &show_ipv6_prefix_list_prefix_cmd);
  2424. install_element (ENABLE_NODE, &show_ipv6_prefix_list_prefix_longer_cmd);
  2425. install_element (ENABLE_NODE, &show_ipv6_prefix_list_prefix_first_match_cmd);
  2426. install_element (ENABLE_NODE, &show_ipv6_prefix_list_summary_cmd);
  2427. install_element (ENABLE_NODE, &show_ipv6_prefix_list_summary_name_cmd);
  2428. install_element (ENABLE_NODE, &show_ipv6_prefix_list_detail_cmd);
  2429. install_element (ENABLE_NODE, &show_ipv6_prefix_list_detail_name_cmd);
  2430. install_element (ENABLE_NODE, &clear_ipv6_prefix_list_cmd);
  2431. install_element (ENABLE_NODE, &clear_ipv6_prefix_list_name_cmd);
  2432. install_element (ENABLE_NODE, &clear_ipv6_prefix_list_name_prefix_cmd);
  2433. }
  2434. #endif /* HAVE_IPV6 */
  2435. void
  2436. prefix_list_init ()
  2437. {
  2438. prefix_list_init_ipv4 ();
  2439. #ifdef HAVE_IPV6
  2440. prefix_list_init_ipv6 ();
  2441. #endif /* HAVE_IPV6 */
  2442. }
  2443. void
  2444. prefix_list_reset ()
  2445. {
  2446. prefix_list_reset_afi (AFI_IP, 0);
  2447. prefix_list_reset_afi (AFI_IP6, 0);
  2448. prefix_list_reset_afi (AFI_IP, 1);
  2449. prefix_list_reset_afi (AFI_IP6, 1);
  2450. }