plist.c 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780
  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. switch (afi)
  582. {
  583. case AFI_IP:
  584. if (strncmp ("any", prefix, strlen (prefix)) == 0)
  585. {
  586. ret = str2prefix_ipv4 ("0.0.0.0/0", (struct prefix_ipv4 *) &p);
  587. genum = 0;
  588. lenum = IPV4_MAX_BITLEN;
  589. any = 1;
  590. }
  591. else
  592. ret = str2prefix_ipv4 (prefix, (struct prefix_ipv4 *) &p);
  593. if (ret <= 0)
  594. {
  595. vty_out (vty, "%% Malformed IPv4 prefix%s", VTY_NEWLINE);
  596. return CMD_WARNING;
  597. }
  598. break;
  599. case AFI_IP6:
  600. if (strncmp ("any", prefix, strlen (prefix)) == 0)
  601. {
  602. ret = str2prefix_ipv6 ("::/0", (struct prefix_ipv6 *) &p);
  603. genum = 0;
  604. lenum = IPV6_MAX_BITLEN;
  605. any = 1;
  606. }
  607. else
  608. ret = str2prefix_ipv6 (prefix, (struct prefix_ipv6 *) &p);
  609. if (ret <= 0)
  610. {
  611. vty_out (vty, "%% Malformed IPv6 prefix%s", VTY_NEWLINE);
  612. return CMD_WARNING;
  613. }
  614. break;
  615. case AFI_ETHER:
  616. default:
  617. vty_out (vty, "%% Unrecognized AFI (%d)%s", afi, VTY_NEWLINE);
  618. return CMD_WARNING;
  619. break;
  620. }
  621. /* ge and le check. */
  622. if (genum && (genum <= p.prefixlen))
  623. return vty_invalid_prefix_range (vty, prefix);
  624. if (lenum && (lenum <= p.prefixlen))
  625. return vty_invalid_prefix_range (vty, prefix);
  626. if (lenum && (genum > lenum))
  627. return vty_invalid_prefix_range (vty, prefix);
  628. if (genum && (lenum == (afi == AFI_IP ? 32 : 128)))
  629. lenum = 0;
  630. /* Get prefix_list with name. */
  631. plist = prefix_list_get (afi, 0, name);
  632. /* Make prefix entry. */
  633. pentry = prefix_list_entry_make (&p, type, seqnum, lenum, genum, any);
  634. /* Check same policy. */
  635. dup = prefix_entry_dup_check (plist, pentry);
  636. if (dup)
  637. {
  638. prefix_list_entry_free (pentry);
  639. vty_out (vty, "%% Insertion failed - prefix-list entry exists:%s",
  640. VTY_NEWLINE);
  641. vty_out (vty, " seq %d %s %s", dup->seq, typestr, prefix);
  642. if (! any && genum)
  643. vty_out (vty, " ge %d", genum);
  644. if (! any && lenum)
  645. vty_out (vty, " le %d", lenum);
  646. vty_out (vty, "%s", VTY_NEWLINE);
  647. return CMD_WARNING;
  648. }
  649. /* Install new filter to the access_list. */
  650. prefix_list_entry_add (plist, pentry);
  651. return CMD_SUCCESS;
  652. }
  653. static int
  654. vty_prefix_list_uninstall (struct vty *vty, afi_t afi, const char *name,
  655. const char *seq, const char *typestr,
  656. const char *prefix, const char *ge, const char *le)
  657. {
  658. int ret;
  659. enum prefix_list_type type;
  660. struct prefix_list *plist;
  661. struct prefix_list_entry *pentry;
  662. struct prefix p;
  663. int seqnum = -1;
  664. int lenum = 0;
  665. int genum = 0;
  666. /* Check prefix list name. */
  667. plist = prefix_list_lookup (afi, name);
  668. if (! plist)
  669. {
  670. vty_out (vty, "%% Can't find specified prefix-list%s", VTY_NEWLINE);
  671. return CMD_WARNING;
  672. }
  673. /* Only prefix-list name specified, delete the entire prefix-list. */
  674. if (seq == NULL && typestr == NULL && prefix == NULL &&
  675. ge == NULL && le == NULL)
  676. {
  677. prefix_list_delete (plist);
  678. return CMD_SUCCESS;
  679. }
  680. /* We must have, at a minimum, both the type and prefix here */
  681. if ((typestr == NULL) || (prefix == NULL))
  682. {
  683. vty_out (vty, "%% Both prefix and type required%s", VTY_NEWLINE);
  684. return CMD_WARNING;
  685. }
  686. /* Check sequence number. */
  687. if (seq)
  688. seqnum = atoi (seq);
  689. /* ge and le number */
  690. if (ge)
  691. genum = atoi (ge);
  692. if (le)
  693. lenum = atoi (le);
  694. /* Check of filter type. */
  695. if (strncmp ("permit", typestr, 1) == 0)
  696. type = PREFIX_PERMIT;
  697. else if (strncmp ("deny", typestr, 1) == 0)
  698. type = PREFIX_DENY;
  699. else
  700. {
  701. vty_out (vty, "%% prefix type must be permit or deny%s", VTY_NEWLINE);
  702. return CMD_WARNING;
  703. }
  704. /* "any" is special token for matching any IPv4 addresses. */
  705. if (afi == AFI_IP)
  706. {
  707. if (strncmp ("any", prefix, strlen (prefix)) == 0)
  708. {
  709. ret = str2prefix_ipv4 ("0.0.0.0/0", (struct prefix_ipv4 *) &p);
  710. genum = 0;
  711. lenum = IPV4_MAX_BITLEN;
  712. }
  713. else
  714. ret = str2prefix_ipv4 (prefix, (struct prefix_ipv4 *) &p);
  715. if (ret <= 0)
  716. {
  717. vty_out (vty, "%% Malformed IPv4 prefix%s", VTY_NEWLINE);
  718. return CMD_WARNING;
  719. }
  720. }
  721. #ifdef HAVE_IPV6
  722. else if (afi == AFI_IP6)
  723. {
  724. if (strncmp ("any", prefix, strlen (prefix)) == 0)
  725. {
  726. ret = str2prefix_ipv6 ("::/0", (struct prefix_ipv6 *) &p);
  727. genum = 0;
  728. lenum = IPV6_MAX_BITLEN;
  729. }
  730. else
  731. ret = str2prefix_ipv6 (prefix, (struct prefix_ipv6 *) &p);
  732. if (ret <= 0)
  733. {
  734. vty_out (vty, "%% Malformed IPv6 prefix%s", VTY_NEWLINE);
  735. return CMD_WARNING;
  736. }
  737. }
  738. #endif /* HAVE_IPV6 */
  739. /* Lookup prefix entry. */
  740. pentry = prefix_list_entry_lookup(plist, &p, type, seqnum, lenum, genum);
  741. if (pentry == NULL)
  742. {
  743. vty_out (vty, "%% Can't find specified prefix-list%s", VTY_NEWLINE);
  744. return CMD_WARNING;
  745. }
  746. /* Install new filter to the access_list. */
  747. prefix_list_entry_delete (plist, pentry, 1);
  748. return CMD_SUCCESS;
  749. }
  750. static int
  751. vty_prefix_list_desc_unset (struct vty *vty, afi_t afi, const char *name)
  752. {
  753. struct prefix_list *plist;
  754. plist = prefix_list_lookup (afi, name);
  755. if (! plist)
  756. {
  757. vty_out (vty, "%% Can't find specified prefix-list%s", VTY_NEWLINE);
  758. return CMD_WARNING;
  759. }
  760. if (plist->desc)
  761. {
  762. XFREE (MTYPE_TMP, plist->desc);
  763. plist->desc = NULL;
  764. }
  765. if (plist->head == NULL && plist->tail == NULL && plist->desc == NULL)
  766. prefix_list_delete (plist);
  767. return CMD_SUCCESS;
  768. }
  769. enum display_type
  770. {
  771. normal_display,
  772. summary_display,
  773. detail_display,
  774. sequential_display,
  775. longer_display,
  776. first_match_display
  777. };
  778. static void
  779. vty_show_prefix_entry (struct vty *vty, afi_t afi, struct prefix_list *plist,
  780. struct prefix_master *master, enum display_type dtype,
  781. int seqnum)
  782. {
  783. struct prefix_list_entry *pentry;
  784. /* Print the name of the protocol */
  785. if (zlog_default)
  786. vty_out (vty, "%s: ", zlog_proto_names[zlog_default->protocol]);
  787. if (dtype == normal_display)
  788. {
  789. vty_out (vty, "ip%s prefix-list %s: %d entries%s",
  790. afi == AFI_IP ? "" : "v6",
  791. plist->name, plist->count, VTY_NEWLINE);
  792. if (plist->desc)
  793. vty_out (vty, " Description: %s%s", plist->desc, VTY_NEWLINE);
  794. }
  795. else if (dtype == summary_display || dtype == detail_display)
  796. {
  797. vty_out (vty, "ip%s prefix-list %s:%s",
  798. afi == AFI_IP ? "" : "v6", plist->name, VTY_NEWLINE);
  799. if (plist->desc)
  800. vty_out (vty, " Description: %s%s", plist->desc, VTY_NEWLINE);
  801. vty_out (vty, " count: %d, range entries: %d, sequences: %d - %d%s",
  802. plist->count, plist->rangecount,
  803. plist->head ? plist->head->seq : 0,
  804. plist->tail ? plist->tail->seq : 0,
  805. VTY_NEWLINE);
  806. }
  807. if (dtype != summary_display)
  808. {
  809. for (pentry = plist->head; pentry; pentry = pentry->next)
  810. {
  811. if (dtype == sequential_display && pentry->seq != seqnum)
  812. continue;
  813. vty_out (vty, " ");
  814. if (master->seqnum)
  815. vty_out (vty, "seq %d ", pentry->seq);
  816. vty_out (vty, "%s ", prefix_list_type_str (pentry));
  817. if (pentry->any)
  818. vty_out (vty, "any");
  819. else
  820. {
  821. struct prefix *p = &pentry->prefix;
  822. char buf[BUFSIZ];
  823. vty_out (vty, "%s/%d",
  824. inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
  825. p->prefixlen);
  826. if (pentry->ge)
  827. vty_out (vty, " ge %d", pentry->ge);
  828. if (pentry->le)
  829. vty_out (vty, " le %d", pentry->le);
  830. }
  831. if (dtype == detail_display || dtype == sequential_display)
  832. vty_out (vty, " (hit count: %ld, refcount: %ld)",
  833. pentry->hitcnt, pentry->refcnt);
  834. vty_out (vty, "%s", VTY_NEWLINE);
  835. }
  836. }
  837. }
  838. static int
  839. vty_show_prefix_list (struct vty *vty, afi_t afi, const char *name,
  840. const char *seq, enum display_type dtype)
  841. {
  842. struct prefix_list *plist;
  843. struct prefix_master *master;
  844. int seqnum = 0;
  845. master = prefix_master_get (afi, 0);
  846. if (master == NULL)
  847. return CMD_WARNING;
  848. if (seq)
  849. seqnum = atoi (seq);
  850. if (name)
  851. {
  852. plist = prefix_list_lookup (afi, name);
  853. if (! plist)
  854. {
  855. vty_out (vty, "%% Can't find specified prefix-list%s", VTY_NEWLINE);
  856. return CMD_WARNING;
  857. }
  858. vty_show_prefix_entry (vty, afi, plist, master, dtype, seqnum);
  859. }
  860. else
  861. {
  862. if (dtype == detail_display || dtype == summary_display)
  863. {
  864. if (master->recent)
  865. vty_out (vty, "Prefix-list with the last deletion/insertion: %s%s",
  866. master->recent->name, VTY_NEWLINE);
  867. }
  868. for (plist = master->num.head; plist; plist = plist->next)
  869. vty_show_prefix_entry (vty, afi, plist, master, dtype, seqnum);
  870. for (plist = master->str.head; plist; plist = plist->next)
  871. vty_show_prefix_entry (vty, afi, plist, master, dtype, seqnum);
  872. }
  873. return CMD_SUCCESS;
  874. }
  875. static int
  876. vty_show_prefix_list_prefix (struct vty *vty, afi_t afi, const char *name,
  877. const char *prefix, enum display_type type)
  878. {
  879. struct prefix_list *plist;
  880. struct prefix_list_entry *pentry;
  881. struct prefix p;
  882. int ret;
  883. int match;
  884. plist = prefix_list_lookup (afi, name);
  885. if (! plist)
  886. {
  887. vty_out (vty, "%% Can't find specified prefix-list%s", VTY_NEWLINE);
  888. return CMD_WARNING;
  889. }
  890. ret = str2prefix (prefix, &p);
  891. if (ret <= 0)
  892. {
  893. vty_out (vty, "%% prefix is malformed%s", VTY_NEWLINE);
  894. return CMD_WARNING;
  895. }
  896. for (pentry = plist->head; pentry; pentry = pentry->next)
  897. {
  898. match = 0;
  899. if (type == normal_display || type == first_match_display)
  900. if (prefix_same (&p, &pentry->prefix))
  901. match = 1;
  902. if (type == longer_display)
  903. if (prefix_match (&p, &pentry->prefix))
  904. match = 1;
  905. if (match)
  906. {
  907. vty_out (vty, " seq %d %s ",
  908. pentry->seq,
  909. prefix_list_type_str (pentry));
  910. if (pentry->any)
  911. vty_out (vty, "any");
  912. else
  913. {
  914. struct prefix *p = &pentry->prefix;
  915. char buf[BUFSIZ];
  916. vty_out (vty, "%s/%d",
  917. inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
  918. p->prefixlen);
  919. if (pentry->ge)
  920. vty_out (vty, " ge %d", pentry->ge);
  921. if (pentry->le)
  922. vty_out (vty, " le %d", pentry->le);
  923. }
  924. if (type == normal_display || type == first_match_display)
  925. vty_out (vty, " (hit count: %ld, refcount: %ld)",
  926. pentry->hitcnt, pentry->refcnt);
  927. vty_out (vty, "%s", VTY_NEWLINE);
  928. if (type == first_match_display)
  929. return CMD_SUCCESS;
  930. }
  931. }
  932. return CMD_SUCCESS;
  933. }
  934. static int
  935. vty_clear_prefix_list (struct vty *vty, afi_t afi, const char *name,
  936. const char *prefix)
  937. {
  938. struct prefix_master *master;
  939. struct prefix_list *plist;
  940. struct prefix_list_entry *pentry;
  941. int ret;
  942. struct prefix p;
  943. master = prefix_master_get (afi, 0);
  944. if (master == NULL)
  945. return CMD_WARNING;
  946. if (name == NULL && prefix == NULL)
  947. {
  948. for (plist = master->num.head; plist; plist = plist->next)
  949. for (pentry = plist->head; pentry; pentry = pentry->next)
  950. pentry->hitcnt = 0;
  951. for (plist = master->str.head; plist; plist = plist->next)
  952. for (pentry = plist->head; pentry; pentry = pentry->next)
  953. pentry->hitcnt = 0;
  954. }
  955. else
  956. {
  957. plist = prefix_list_lookup (afi, name);
  958. if (! plist)
  959. {
  960. vty_out (vty, "%% Can't find specified prefix-list%s", VTY_NEWLINE);
  961. return CMD_WARNING;
  962. }
  963. if (prefix)
  964. {
  965. ret = str2prefix (prefix, &p);
  966. if (ret <= 0)
  967. {
  968. vty_out (vty, "%% prefix is malformed%s", VTY_NEWLINE);
  969. return CMD_WARNING;
  970. }
  971. }
  972. for (pentry = plist->head; pentry; pentry = pentry->next)
  973. {
  974. if (prefix)
  975. {
  976. if (prefix_match (&pentry->prefix, &p))
  977. pentry->hitcnt = 0;
  978. }
  979. else
  980. pentry->hitcnt = 0;
  981. }
  982. }
  983. return CMD_SUCCESS;
  984. }
  985. DEFUN (ip_prefix_list,
  986. ip_prefix_list_cmd,
  987. "ip prefix-list WORD (deny|permit) (A.B.C.D/M|any)",
  988. IP_STR
  989. PREFIX_LIST_STR
  990. "Name of a prefix list\n"
  991. "Specify packets to reject\n"
  992. "Specify packets to forward\n"
  993. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  994. "Any prefix match. Same as \"0.0.0.0/0 le 32\"\n")
  995. {
  996. return vty_prefix_list_install (vty, AFI_IP, argv[0], NULL,
  997. argv[1], argv[2], NULL, NULL);
  998. }
  999. DEFUN (ip_prefix_list_ge,
  1000. ip_prefix_list_ge_cmd,
  1001. "ip prefix-list WORD (deny|permit) A.B.C.D/M ge <0-32>",
  1002. IP_STR
  1003. PREFIX_LIST_STR
  1004. "Name of a prefix list\n"
  1005. "Specify packets to reject\n"
  1006. "Specify packets to forward\n"
  1007. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1008. "Minimum prefix length to be matched\n"
  1009. "Minimum prefix length\n")
  1010. {
  1011. return vty_prefix_list_install (vty, AFI_IP, argv[0], NULL, argv[1],
  1012. argv[2], argv[3], NULL);
  1013. }
  1014. DEFUN (ip_prefix_list_ge_le,
  1015. ip_prefix_list_ge_le_cmd,
  1016. "ip prefix-list WORD (deny|permit) A.B.C.D/M ge <0-32> le <0-32>",
  1017. IP_STR
  1018. PREFIX_LIST_STR
  1019. "Name of a prefix list\n"
  1020. "Specify packets to reject\n"
  1021. "Specify packets to forward\n"
  1022. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1023. "Minimum prefix length to be matched\n"
  1024. "Minimum prefix length\n"
  1025. "Maximum prefix length to be matched\n"
  1026. "Maximum prefix length\n")
  1027. {
  1028. return vty_prefix_list_install (vty, AFI_IP, argv[0], NULL, argv[1],
  1029. argv[2], argv[3], argv[4]);
  1030. }
  1031. DEFUN (ip_prefix_list_le,
  1032. ip_prefix_list_le_cmd,
  1033. "ip prefix-list WORD (deny|permit) A.B.C.D/M le <0-32>",
  1034. IP_STR
  1035. PREFIX_LIST_STR
  1036. "Name of a prefix list\n"
  1037. "Specify packets to reject\n"
  1038. "Specify packets to forward\n"
  1039. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1040. "Maximum prefix length to be matched\n"
  1041. "Maximum prefix length\n")
  1042. {
  1043. return vty_prefix_list_install (vty, AFI_IP, argv[0], NULL, argv[1],
  1044. argv[2], NULL, argv[3]);
  1045. }
  1046. DEFUN (ip_prefix_list_le_ge,
  1047. ip_prefix_list_le_ge_cmd,
  1048. "ip prefix-list WORD (deny|permit) A.B.C.D/M le <0-32> ge <0-32>",
  1049. IP_STR
  1050. PREFIX_LIST_STR
  1051. "Name of a prefix list\n"
  1052. "Specify packets to reject\n"
  1053. "Specify packets to forward\n"
  1054. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1055. "Maximum prefix length to be matched\n"
  1056. "Maximum prefix length\n"
  1057. "Minimum prefix length to be matched\n"
  1058. "Minimum prefix length\n")
  1059. {
  1060. return vty_prefix_list_install (vty, AFI_IP, argv[0], NULL, argv[1],
  1061. argv[2], argv[4], argv[3]);
  1062. }
  1063. DEFUN (ip_prefix_list_seq,
  1064. ip_prefix_list_seq_cmd,
  1065. "ip prefix-list WORD seq <1-4294967295> (deny|permit) (A.B.C.D/M|any)",
  1066. IP_STR
  1067. PREFIX_LIST_STR
  1068. "Name of a prefix list\n"
  1069. "sequence number of an entry\n"
  1070. "Sequence number\n"
  1071. "Specify packets to reject\n"
  1072. "Specify packets to forward\n"
  1073. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1074. "Any prefix match. Same as \"0.0.0.0/0 le 32\"\n")
  1075. {
  1076. return vty_prefix_list_install (vty, AFI_IP, argv[0], argv[1], argv[2],
  1077. argv[3], NULL, NULL);
  1078. }
  1079. DEFUN (ip_prefix_list_seq_ge,
  1080. ip_prefix_list_seq_ge_cmd,
  1081. "ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M ge <0-32>",
  1082. IP_STR
  1083. PREFIX_LIST_STR
  1084. "Name of a prefix list\n"
  1085. "sequence number of an entry\n"
  1086. "Sequence number\n"
  1087. "Specify packets to reject\n"
  1088. "Specify packets to forward\n"
  1089. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1090. "Minimum prefix length to be matched\n"
  1091. "Minimum prefix length\n")
  1092. {
  1093. return vty_prefix_list_install (vty, AFI_IP, argv[0], argv[1], argv[2],
  1094. argv[3], argv[4], NULL);
  1095. }
  1096. DEFUN (ip_prefix_list_seq_ge_le,
  1097. ip_prefix_list_seq_ge_le_cmd,
  1098. "ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M ge <0-32> le <0-32>",
  1099. IP_STR
  1100. PREFIX_LIST_STR
  1101. "Name of a prefix list\n"
  1102. "sequence number of an entry\n"
  1103. "Sequence number\n"
  1104. "Specify packets to reject\n"
  1105. "Specify packets to forward\n"
  1106. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1107. "Minimum prefix length to be matched\n"
  1108. "Minimum prefix length\n"
  1109. "Maximum prefix length to be matched\n"
  1110. "Maximum prefix length\n")
  1111. {
  1112. return vty_prefix_list_install (vty, AFI_IP, argv[0], argv[1], argv[2],
  1113. argv[3], argv[4], argv[5]);
  1114. }
  1115. DEFUN (ip_prefix_list_seq_le,
  1116. ip_prefix_list_seq_le_cmd,
  1117. "ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M le <0-32>",
  1118. IP_STR
  1119. PREFIX_LIST_STR
  1120. "Name of a prefix list\n"
  1121. "sequence number of an entry\n"
  1122. "Sequence number\n"
  1123. "Specify packets to reject\n"
  1124. "Specify packets to forward\n"
  1125. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1126. "Maximum prefix length to be matched\n"
  1127. "Maximum prefix length\n")
  1128. {
  1129. return vty_prefix_list_install (vty, AFI_IP, argv[0], argv[1], argv[2],
  1130. argv[3], NULL, argv[4]);
  1131. }
  1132. DEFUN (ip_prefix_list_seq_le_ge,
  1133. ip_prefix_list_seq_le_ge_cmd,
  1134. "ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M le <0-32> ge <0-32>",
  1135. IP_STR
  1136. PREFIX_LIST_STR
  1137. "Name of a prefix list\n"
  1138. "sequence number of an entry\n"
  1139. "Sequence number\n"
  1140. "Specify packets to reject\n"
  1141. "Specify packets to forward\n"
  1142. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1143. "Maximum prefix length to be matched\n"
  1144. "Maximum prefix length\n"
  1145. "Minimum prefix length to be matched\n"
  1146. "Minimum prefix length\n")
  1147. {
  1148. return vty_prefix_list_install (vty, AFI_IP, argv[0], argv[1], argv[2],
  1149. argv[3], argv[5], argv[4]);
  1150. }
  1151. DEFUN (no_ip_prefix_list,
  1152. no_ip_prefix_list_cmd,
  1153. "no ip prefix-list WORD",
  1154. NO_STR
  1155. IP_STR
  1156. PREFIX_LIST_STR
  1157. "Name of a prefix list\n")
  1158. {
  1159. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, NULL,
  1160. NULL, NULL, NULL);
  1161. }
  1162. DEFUN (no_ip_prefix_list_prefix,
  1163. no_ip_prefix_list_prefix_cmd,
  1164. "no ip prefix-list WORD (deny|permit) (A.B.C.D/M|any)",
  1165. NO_STR
  1166. IP_STR
  1167. PREFIX_LIST_STR
  1168. "Name of a prefix list\n"
  1169. "Specify packets to reject\n"
  1170. "Specify packets to forward\n"
  1171. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1172. "Any prefix match. Same as \"0.0.0.0/0 le 32\"\n")
  1173. {
  1174. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, argv[1],
  1175. argv[2], NULL, NULL);
  1176. }
  1177. DEFUN (no_ip_prefix_list_ge,
  1178. no_ip_prefix_list_ge_cmd,
  1179. "no ip prefix-list WORD (deny|permit) A.B.C.D/M ge <0-32>",
  1180. NO_STR
  1181. IP_STR
  1182. PREFIX_LIST_STR
  1183. "Name of a prefix list\n"
  1184. "Specify packets to reject\n"
  1185. "Specify packets to forward\n"
  1186. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1187. "Minimum prefix length to be matched\n"
  1188. "Minimum prefix length\n")
  1189. {
  1190. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, argv[1],
  1191. argv[2], argv[3], NULL);
  1192. }
  1193. DEFUN (no_ip_prefix_list_ge_le,
  1194. no_ip_prefix_list_ge_le_cmd,
  1195. "no ip prefix-list WORD (deny|permit) A.B.C.D/M ge <0-32> le <0-32>",
  1196. NO_STR
  1197. IP_STR
  1198. PREFIX_LIST_STR
  1199. "Name of a prefix list\n"
  1200. "Specify packets to reject\n"
  1201. "Specify packets to forward\n"
  1202. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1203. "Minimum prefix length to be matched\n"
  1204. "Minimum prefix length\n"
  1205. "Maximum prefix length to be matched\n"
  1206. "Maximum prefix length\n")
  1207. {
  1208. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, argv[1],
  1209. argv[2], argv[3], argv[4]);
  1210. }
  1211. DEFUN (no_ip_prefix_list_le,
  1212. no_ip_prefix_list_le_cmd,
  1213. "no ip prefix-list WORD (deny|permit) A.B.C.D/M le <0-32>",
  1214. NO_STR
  1215. IP_STR
  1216. PREFIX_LIST_STR
  1217. "Name of a prefix list\n"
  1218. "Specify packets to reject\n"
  1219. "Specify packets to forward\n"
  1220. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1221. "Maximum prefix length to be matched\n"
  1222. "Maximum prefix length\n")
  1223. {
  1224. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, argv[1],
  1225. argv[2], NULL, argv[3]);
  1226. }
  1227. DEFUN (no_ip_prefix_list_le_ge,
  1228. no_ip_prefix_list_le_ge_cmd,
  1229. "no ip prefix-list WORD (deny|permit) A.B.C.D/M le <0-32> ge <0-32>",
  1230. NO_STR
  1231. IP_STR
  1232. PREFIX_LIST_STR
  1233. "Name of a prefix list\n"
  1234. "Specify packets to reject\n"
  1235. "Specify packets to forward\n"
  1236. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1237. "Maximum prefix length to be matched\n"
  1238. "Maximum prefix length\n"
  1239. "Minimum prefix length to be matched\n"
  1240. "Minimum prefix length\n")
  1241. {
  1242. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], NULL, argv[1],
  1243. argv[2], argv[4], argv[3]);
  1244. }
  1245. DEFUN (no_ip_prefix_list_seq,
  1246. no_ip_prefix_list_seq_cmd,
  1247. "no ip prefix-list WORD seq <1-4294967295> (deny|permit) (A.B.C.D/M|any)",
  1248. NO_STR
  1249. IP_STR
  1250. PREFIX_LIST_STR
  1251. "Name of a prefix list\n"
  1252. "sequence number of an entry\n"
  1253. "Sequence number\n"
  1254. "Specify packets to reject\n"
  1255. "Specify packets to forward\n"
  1256. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1257. "Any prefix match. Same as \"0.0.0.0/0 le 32\"\n")
  1258. {
  1259. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], argv[1], argv[2],
  1260. argv[3], NULL, NULL);
  1261. }
  1262. DEFUN (no_ip_prefix_list_seq_ge,
  1263. no_ip_prefix_list_seq_ge_cmd,
  1264. "no ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M ge <0-32>",
  1265. NO_STR
  1266. IP_STR
  1267. PREFIX_LIST_STR
  1268. "Name of a prefix list\n"
  1269. "sequence number of an entry\n"
  1270. "Sequence number\n"
  1271. "Specify packets to reject\n"
  1272. "Specify packets to forward\n"
  1273. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1274. "Minimum prefix length to be matched\n"
  1275. "Minimum prefix length\n")
  1276. {
  1277. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], argv[1], argv[2],
  1278. argv[3], argv[4], NULL);
  1279. }
  1280. DEFUN (no_ip_prefix_list_seq_ge_le,
  1281. no_ip_prefix_list_seq_ge_le_cmd,
  1282. "no ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M ge <0-32> le <0-32>",
  1283. NO_STR
  1284. IP_STR
  1285. PREFIX_LIST_STR
  1286. "Name of a prefix list\n"
  1287. "sequence number of an entry\n"
  1288. "Sequence number\n"
  1289. "Specify packets to reject\n"
  1290. "Specify packets to forward\n"
  1291. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1292. "Minimum prefix length to be matched\n"
  1293. "Minimum prefix length\n"
  1294. "Maximum prefix length to be matched\n"
  1295. "Maximum prefix length\n")
  1296. {
  1297. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], argv[1], argv[2],
  1298. argv[3], argv[4], argv[5]);
  1299. }
  1300. DEFUN (no_ip_prefix_list_seq_le,
  1301. no_ip_prefix_list_seq_le_cmd,
  1302. "no ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M le <0-32>",
  1303. NO_STR
  1304. IP_STR
  1305. PREFIX_LIST_STR
  1306. "Name of a prefix list\n"
  1307. "sequence number of an entry\n"
  1308. "Sequence number\n"
  1309. "Specify packets to reject\n"
  1310. "Specify packets to forward\n"
  1311. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1312. "Maximum prefix length to be matched\n"
  1313. "Maximum prefix length\n")
  1314. {
  1315. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], argv[1], argv[2],
  1316. argv[3], NULL, argv[4]);
  1317. }
  1318. DEFUN (no_ip_prefix_list_seq_le_ge,
  1319. no_ip_prefix_list_seq_le_ge_cmd,
  1320. "no ip prefix-list WORD seq <1-4294967295> (deny|permit) A.B.C.D/M le <0-32> ge <0-32>",
  1321. NO_STR
  1322. IP_STR
  1323. PREFIX_LIST_STR
  1324. "Name of a prefix list\n"
  1325. "sequence number of an entry\n"
  1326. "Sequence number\n"
  1327. "Specify packets to reject\n"
  1328. "Specify packets to forward\n"
  1329. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1330. "Maximum prefix length to be matched\n"
  1331. "Maximum prefix length\n"
  1332. "Minimum prefix length to be matched\n"
  1333. "Minimum prefix length\n")
  1334. {
  1335. return vty_prefix_list_uninstall (vty, AFI_IP, argv[0], argv[1], argv[2],
  1336. argv[3], argv[5], argv[4]);
  1337. }
  1338. DEFUN (ip_prefix_list_sequence_number,
  1339. ip_prefix_list_sequence_number_cmd,
  1340. "ip prefix-list sequence-number",
  1341. IP_STR
  1342. PREFIX_LIST_STR
  1343. "Include/exclude sequence numbers in NVGEN\n")
  1344. {
  1345. prefix_master_ipv4.seqnum = 1;
  1346. return CMD_SUCCESS;
  1347. }
  1348. DEFUN (no_ip_prefix_list_sequence_number,
  1349. no_ip_prefix_list_sequence_number_cmd,
  1350. "no ip prefix-list sequence-number",
  1351. NO_STR
  1352. IP_STR
  1353. PREFIX_LIST_STR
  1354. "Include/exclude sequence numbers in NVGEN\n")
  1355. {
  1356. prefix_master_ipv4.seqnum = 0;
  1357. return CMD_SUCCESS;
  1358. }
  1359. DEFUN (ip_prefix_list_description,
  1360. ip_prefix_list_description_cmd,
  1361. "ip prefix-list WORD description .LINE",
  1362. IP_STR
  1363. PREFIX_LIST_STR
  1364. "Name of a prefix list\n"
  1365. "Prefix-list specific description\n"
  1366. "Up to 80 characters describing this prefix-list\n")
  1367. {
  1368. struct prefix_list *plist;
  1369. plist = prefix_list_get (AFI_IP, 0, argv[0]);
  1370. if (plist->desc)
  1371. {
  1372. XFREE (MTYPE_TMP, plist->desc);
  1373. plist->desc = NULL;
  1374. }
  1375. plist->desc = argv_concat(argv, argc, 1);
  1376. return CMD_SUCCESS;
  1377. }
  1378. DEFUN (no_ip_prefix_list_description,
  1379. no_ip_prefix_list_description_cmd,
  1380. "no ip prefix-list WORD description",
  1381. NO_STR
  1382. IP_STR
  1383. PREFIX_LIST_STR
  1384. "Name of a prefix list\n"
  1385. "Prefix-list specific description\n")
  1386. {
  1387. return vty_prefix_list_desc_unset (vty, AFI_IP, argv[0]);
  1388. }
  1389. ALIAS (no_ip_prefix_list_description,
  1390. no_ip_prefix_list_description_arg_cmd,
  1391. "no ip prefix-list WORD description .LINE",
  1392. NO_STR
  1393. IP_STR
  1394. PREFIX_LIST_STR
  1395. "Name of a prefix list\n"
  1396. "Prefix-list specific description\n"
  1397. "Up to 80 characters describing this prefix-list\n")
  1398. DEFUN (show_ip_prefix_list,
  1399. show_ip_prefix_list_cmd,
  1400. "show ip prefix-list",
  1401. SHOW_STR
  1402. IP_STR
  1403. PREFIX_LIST_STR)
  1404. {
  1405. return vty_show_prefix_list (vty, AFI_IP, NULL, NULL, normal_display);
  1406. }
  1407. DEFUN (show_ip_prefix_list_name,
  1408. show_ip_prefix_list_name_cmd,
  1409. "show ip prefix-list WORD",
  1410. SHOW_STR
  1411. IP_STR
  1412. PREFIX_LIST_STR
  1413. "Name of a prefix list\n")
  1414. {
  1415. return vty_show_prefix_list (vty, AFI_IP, argv[0], NULL, normal_display);
  1416. }
  1417. DEFUN (show_ip_prefix_list_name_seq,
  1418. show_ip_prefix_list_name_seq_cmd,
  1419. "show ip prefix-list WORD seq <1-4294967295>",
  1420. SHOW_STR
  1421. IP_STR
  1422. PREFIX_LIST_STR
  1423. "Name of a prefix list\n"
  1424. "sequence number of an entry\n"
  1425. "Sequence number\n")
  1426. {
  1427. return vty_show_prefix_list (vty, AFI_IP, argv[0], argv[1], sequential_display);
  1428. }
  1429. DEFUN (show_ip_prefix_list_prefix,
  1430. show_ip_prefix_list_prefix_cmd,
  1431. "show ip prefix-list WORD A.B.C.D/M",
  1432. SHOW_STR
  1433. IP_STR
  1434. PREFIX_LIST_STR
  1435. "Name of a prefix list\n"
  1436. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
  1437. {
  1438. return vty_show_prefix_list_prefix (vty, AFI_IP, argv[0], argv[1], normal_display);
  1439. }
  1440. DEFUN (show_ip_prefix_list_prefix_longer,
  1441. show_ip_prefix_list_prefix_longer_cmd,
  1442. "show ip prefix-list WORD A.B.C.D/M longer",
  1443. SHOW_STR
  1444. IP_STR
  1445. PREFIX_LIST_STR
  1446. "Name of a prefix list\n"
  1447. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1448. "Lookup longer prefix\n")
  1449. {
  1450. return vty_show_prefix_list_prefix (vty, AFI_IP, argv[0], argv[1], longer_display);
  1451. }
  1452. DEFUN (show_ip_prefix_list_prefix_first_match,
  1453. show_ip_prefix_list_prefix_first_match_cmd,
  1454. "show ip prefix-list WORD A.B.C.D/M first-match",
  1455. SHOW_STR
  1456. IP_STR
  1457. PREFIX_LIST_STR
  1458. "Name of a prefix list\n"
  1459. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1460. "First matched prefix\n")
  1461. {
  1462. return vty_show_prefix_list_prefix (vty, AFI_IP, argv[0], argv[1], first_match_display);
  1463. }
  1464. DEFUN (show_ip_prefix_list_summary,
  1465. show_ip_prefix_list_summary_cmd,
  1466. "show ip prefix-list summary",
  1467. SHOW_STR
  1468. IP_STR
  1469. PREFIX_LIST_STR
  1470. "Summary of prefix lists\n")
  1471. {
  1472. return vty_show_prefix_list (vty, AFI_IP, NULL, NULL, summary_display);
  1473. }
  1474. DEFUN (show_ip_prefix_list_summary_name,
  1475. show_ip_prefix_list_summary_name_cmd,
  1476. "show ip prefix-list summary WORD",
  1477. SHOW_STR
  1478. IP_STR
  1479. PREFIX_LIST_STR
  1480. "Summary of prefix lists\n"
  1481. "Name of a prefix list\n")
  1482. {
  1483. return vty_show_prefix_list (vty, AFI_IP, argv[0], NULL, summary_display);
  1484. }
  1485. DEFUN (show_ip_prefix_list_detail,
  1486. show_ip_prefix_list_detail_cmd,
  1487. "show ip prefix-list detail",
  1488. SHOW_STR
  1489. IP_STR
  1490. PREFIX_LIST_STR
  1491. "Detail of prefix lists\n")
  1492. {
  1493. return vty_show_prefix_list (vty, AFI_IP, NULL, NULL, detail_display);
  1494. }
  1495. DEFUN (show_ip_prefix_list_detail_name,
  1496. show_ip_prefix_list_detail_name_cmd,
  1497. "show ip prefix-list detail WORD",
  1498. SHOW_STR
  1499. IP_STR
  1500. PREFIX_LIST_STR
  1501. "Detail of prefix lists\n"
  1502. "Name of a prefix list\n")
  1503. {
  1504. return vty_show_prefix_list (vty, AFI_IP, argv[0], NULL, detail_display);
  1505. }
  1506. DEFUN (clear_ip_prefix_list,
  1507. clear_ip_prefix_list_cmd,
  1508. "clear ip prefix-list",
  1509. CLEAR_STR
  1510. IP_STR
  1511. PREFIX_LIST_STR)
  1512. {
  1513. return vty_clear_prefix_list (vty, AFI_IP, NULL, NULL);
  1514. }
  1515. DEFUN (clear_ip_prefix_list_name,
  1516. clear_ip_prefix_list_name_cmd,
  1517. "clear ip prefix-list WORD",
  1518. CLEAR_STR
  1519. IP_STR
  1520. PREFIX_LIST_STR
  1521. "Name of a prefix list\n")
  1522. {
  1523. return vty_clear_prefix_list (vty, AFI_IP, argv[0], NULL);
  1524. }
  1525. DEFUN (clear_ip_prefix_list_name_prefix,
  1526. clear_ip_prefix_list_name_prefix_cmd,
  1527. "clear ip prefix-list WORD A.B.C.D/M",
  1528. CLEAR_STR
  1529. IP_STR
  1530. PREFIX_LIST_STR
  1531. "Name of a prefix list\n"
  1532. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
  1533. {
  1534. return vty_clear_prefix_list (vty, AFI_IP, argv[0], argv[1]);
  1535. }
  1536. #ifdef HAVE_IPV6
  1537. DEFUN (ipv6_prefix_list,
  1538. ipv6_prefix_list_cmd,
  1539. "ipv6 prefix-list WORD (deny|permit) (X:X::X:X/M|any)",
  1540. IPV6_STR
  1541. PREFIX_LIST_STR
  1542. "Name of a prefix list\n"
  1543. "Specify packets to reject\n"
  1544. "Specify packets to forward\n"
  1545. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1546. "Any prefix match. Same as \"::0/0 le 128\"\n")
  1547. {
  1548. return vty_prefix_list_install (vty, AFI_IP6, argv[0], NULL,
  1549. argv[1], argv[2], NULL, NULL);
  1550. }
  1551. DEFUN (ipv6_prefix_list_ge,
  1552. ipv6_prefix_list_ge_cmd,
  1553. "ipv6 prefix-list WORD (deny|permit) X:X::X:X/M ge <0-128>",
  1554. IPV6_STR
  1555. PREFIX_LIST_STR
  1556. "Name of a prefix list\n"
  1557. "Specify packets to reject\n"
  1558. "Specify packets to forward\n"
  1559. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1560. "Minimum prefix length to be matched\n"
  1561. "Minimum prefix length\n")
  1562. {
  1563. return vty_prefix_list_install (vty, AFI_IP6, argv[0], NULL, argv[1],
  1564. argv[2], argv[3], NULL);
  1565. }
  1566. DEFUN (ipv6_prefix_list_ge_le,
  1567. ipv6_prefix_list_ge_le_cmd,
  1568. "ipv6 prefix-list WORD (deny|permit) X:X::X:X/M ge <0-128> le <0-128>",
  1569. IPV6_STR
  1570. PREFIX_LIST_STR
  1571. "Name of a prefix list\n"
  1572. "Specify packets to reject\n"
  1573. "Specify packets to forward\n"
  1574. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1575. "Minimum prefix length to be matched\n"
  1576. "Minimum prefix length\n"
  1577. "Maximum prefix length to be matched\n"
  1578. "Maximum prefix length\n")
  1579. {
  1580. return vty_prefix_list_install (vty, AFI_IP6, argv[0], NULL, argv[1],
  1581. argv[2], argv[3], argv[4]);
  1582. }
  1583. DEFUN (ipv6_prefix_list_le,
  1584. ipv6_prefix_list_le_cmd,
  1585. "ipv6 prefix-list WORD (deny|permit) X:X::X:X/M le <0-128>",
  1586. IPV6_STR
  1587. PREFIX_LIST_STR
  1588. "Name of a prefix list\n"
  1589. "Specify packets to reject\n"
  1590. "Specify packets to forward\n"
  1591. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1592. "Maximum prefix length to be matched\n"
  1593. "Maximum prefix length\n")
  1594. {
  1595. return vty_prefix_list_install (vty, AFI_IP6, argv[0], NULL, argv[1],
  1596. argv[2], NULL, argv[3]);
  1597. }
  1598. DEFUN (ipv6_prefix_list_le_ge,
  1599. ipv6_prefix_list_le_ge_cmd,
  1600. "ipv6 prefix-list WORD (deny|permit) X:X::X:X/M le <0-128> ge <0-128>",
  1601. IPV6_STR
  1602. PREFIX_LIST_STR
  1603. "Name of a prefix list\n"
  1604. "Specify packets to reject\n"
  1605. "Specify packets to forward\n"
  1606. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1607. "Maximum prefix length to be matched\n"
  1608. "Maximum prefix length\n"
  1609. "Minimum prefix length to be matched\n"
  1610. "Minimum prefix length\n")
  1611. {
  1612. return vty_prefix_list_install (vty, AFI_IP6, argv[0], NULL, argv[1],
  1613. argv[2], argv[4], argv[3]);
  1614. }
  1615. DEFUN (ipv6_prefix_list_seq,
  1616. ipv6_prefix_list_seq_cmd,
  1617. "ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) (X:X::X:X/M|any)",
  1618. IPV6_STR
  1619. PREFIX_LIST_STR
  1620. "Name of a prefix list\n"
  1621. "sequence number of an entry\n"
  1622. "Sequence number\n"
  1623. "Specify packets to reject\n"
  1624. "Specify packets to forward\n"
  1625. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1626. "Any prefix match. Same as \"::0/0 le 128\"\n")
  1627. {
  1628. return vty_prefix_list_install (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1629. argv[3], NULL, NULL);
  1630. }
  1631. DEFUN (ipv6_prefix_list_seq_ge,
  1632. ipv6_prefix_list_seq_ge_cmd,
  1633. "ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M ge <0-128>",
  1634. IPV6_STR
  1635. PREFIX_LIST_STR
  1636. "Name of a prefix list\n"
  1637. "sequence number of an entry\n"
  1638. "Sequence number\n"
  1639. "Specify packets to reject\n"
  1640. "Specify packets to forward\n"
  1641. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1642. "Minimum prefix length to be matched\n"
  1643. "Minimum prefix length\n")
  1644. {
  1645. return vty_prefix_list_install (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1646. argv[3], argv[4], NULL);
  1647. }
  1648. DEFUN (ipv6_prefix_list_seq_ge_le,
  1649. ipv6_prefix_list_seq_ge_le_cmd,
  1650. "ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M ge <0-128> le <0-128>",
  1651. IPV6_STR
  1652. PREFIX_LIST_STR
  1653. "Name of a prefix list\n"
  1654. "sequence number of an entry\n"
  1655. "Sequence number\n"
  1656. "Specify packets to reject\n"
  1657. "Specify packets to forward\n"
  1658. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1659. "Minimum prefix length to be matched\n"
  1660. "Minimum prefix length\n"
  1661. "Maximum prefix length to be matched\n"
  1662. "Maximum prefix length\n")
  1663. {
  1664. return vty_prefix_list_install (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1665. argv[3], argv[4], argv[5]);
  1666. }
  1667. DEFUN (ipv6_prefix_list_seq_le,
  1668. ipv6_prefix_list_seq_le_cmd,
  1669. "ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M le <0-128>",
  1670. IPV6_STR
  1671. PREFIX_LIST_STR
  1672. "Name of a prefix list\n"
  1673. "sequence number of an entry\n"
  1674. "Sequence number\n"
  1675. "Specify packets to reject\n"
  1676. "Specify packets to forward\n"
  1677. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1678. "Maximum prefix length to be matched\n"
  1679. "Maximum prefix length\n")
  1680. {
  1681. return vty_prefix_list_install (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1682. argv[3], NULL, argv[4]);
  1683. }
  1684. DEFUN (ipv6_prefix_list_seq_le_ge,
  1685. ipv6_prefix_list_seq_le_ge_cmd,
  1686. "ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M le <0-128> ge <0-128>",
  1687. IPV6_STR
  1688. PREFIX_LIST_STR
  1689. "Name of a prefix list\n"
  1690. "sequence number of an entry\n"
  1691. "Sequence number\n"
  1692. "Specify packets to reject\n"
  1693. "Specify packets to forward\n"
  1694. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1695. "Maximum prefix length to be matched\n"
  1696. "Maximum prefix length\n"
  1697. "Minimum prefix length to be matched\n"
  1698. "Minimum prefix length\n")
  1699. {
  1700. return vty_prefix_list_install (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1701. argv[3], argv[5], argv[4]);
  1702. }
  1703. DEFUN (no_ipv6_prefix_list,
  1704. no_ipv6_prefix_list_cmd,
  1705. "no ipv6 prefix-list WORD",
  1706. NO_STR
  1707. IPV6_STR
  1708. PREFIX_LIST_STR
  1709. "Name of a prefix list\n")
  1710. {
  1711. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, NULL,
  1712. NULL, NULL, NULL);
  1713. }
  1714. DEFUN (no_ipv6_prefix_list_prefix,
  1715. no_ipv6_prefix_list_prefix_cmd,
  1716. "no ipv6 prefix-list WORD (deny|permit) (X:X::X:X/M|any)",
  1717. NO_STR
  1718. IPV6_STR
  1719. PREFIX_LIST_STR
  1720. "Name of a prefix list\n"
  1721. "Specify packets to reject\n"
  1722. "Specify packets to forward\n"
  1723. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1724. "Any prefix match. Same as \"::0/0 le 128\"\n")
  1725. {
  1726. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, argv[1],
  1727. argv[2], NULL, NULL);
  1728. }
  1729. DEFUN (no_ipv6_prefix_list_ge,
  1730. no_ipv6_prefix_list_ge_cmd,
  1731. "no ipv6 prefix-list WORD (deny|permit) X:X::X:X/M ge <0-128>",
  1732. NO_STR
  1733. IPV6_STR
  1734. PREFIX_LIST_STR
  1735. "Name of a prefix list\n"
  1736. "Specify packets to reject\n"
  1737. "Specify packets to forward\n"
  1738. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1739. "Minimum prefix length to be matched\n"
  1740. "Minimum prefix length\n")
  1741. {
  1742. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, argv[1],
  1743. argv[2], argv[3], NULL);
  1744. }
  1745. DEFUN (no_ipv6_prefix_list_ge_le,
  1746. no_ipv6_prefix_list_ge_le_cmd,
  1747. "no ipv6 prefix-list WORD (deny|permit) X:X::X:X/M ge <0-128> le <0-128>",
  1748. NO_STR
  1749. IPV6_STR
  1750. PREFIX_LIST_STR
  1751. "Name of a prefix list\n"
  1752. "Specify packets to reject\n"
  1753. "Specify packets to forward\n"
  1754. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1755. "Minimum prefix length to be matched\n"
  1756. "Minimum prefix length\n"
  1757. "Maximum prefix length to be matched\n"
  1758. "Maximum prefix length\n")
  1759. {
  1760. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, argv[1],
  1761. argv[2], argv[3], argv[4]);
  1762. }
  1763. DEFUN (no_ipv6_prefix_list_le,
  1764. no_ipv6_prefix_list_le_cmd,
  1765. "no ipv6 prefix-list WORD (deny|permit) X:X::X:X/M le <0-128>",
  1766. NO_STR
  1767. IPV6_STR
  1768. PREFIX_LIST_STR
  1769. "Name of a prefix list\n"
  1770. "Specify packets to reject\n"
  1771. "Specify packets to forward\n"
  1772. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1773. "Maximum prefix length to be matched\n"
  1774. "Maximum prefix length\n")
  1775. {
  1776. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, argv[1],
  1777. argv[2], NULL, argv[3]);
  1778. }
  1779. DEFUN (no_ipv6_prefix_list_le_ge,
  1780. no_ipv6_prefix_list_le_ge_cmd,
  1781. "no ipv6 prefix-list WORD (deny|permit) X:X::X:X/M le <0-128> ge <0-128>",
  1782. NO_STR
  1783. IPV6_STR
  1784. PREFIX_LIST_STR
  1785. "Name of a prefix list\n"
  1786. "Specify packets to reject\n"
  1787. "Specify packets to forward\n"
  1788. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1789. "Maximum prefix length to be matched\n"
  1790. "Maximum prefix length\n"
  1791. "Minimum prefix length to be matched\n"
  1792. "Minimum prefix length\n")
  1793. {
  1794. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], NULL, argv[1],
  1795. argv[2], argv[4], argv[3]);
  1796. }
  1797. DEFUN (no_ipv6_prefix_list_seq,
  1798. no_ipv6_prefix_list_seq_cmd,
  1799. "no ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) (X:X::X:X/M|any)",
  1800. NO_STR
  1801. IPV6_STR
  1802. PREFIX_LIST_STR
  1803. "Name of a prefix list\n"
  1804. "sequence number of an entry\n"
  1805. "Sequence number\n"
  1806. "Specify packets to reject\n"
  1807. "Specify packets to forward\n"
  1808. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1809. "Any prefix match. Same as \"::0/0 le 128\"\n")
  1810. {
  1811. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1812. argv[3], NULL, NULL);
  1813. }
  1814. DEFUN (no_ipv6_prefix_list_seq_ge,
  1815. no_ipv6_prefix_list_seq_ge_cmd,
  1816. "no ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M ge <0-128>",
  1817. NO_STR
  1818. IPV6_STR
  1819. PREFIX_LIST_STR
  1820. "Name of a prefix list\n"
  1821. "sequence number of an entry\n"
  1822. "Sequence number\n"
  1823. "Specify packets to reject\n"
  1824. "Specify packets to forward\n"
  1825. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1826. "Minimum prefix length to be matched\n"
  1827. "Minimum prefix length\n")
  1828. {
  1829. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1830. argv[3], argv[4], NULL);
  1831. }
  1832. DEFUN (no_ipv6_prefix_list_seq_ge_le,
  1833. no_ipv6_prefix_list_seq_ge_le_cmd,
  1834. "no ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M ge <0-128> le <0-128>",
  1835. NO_STR
  1836. IPV6_STR
  1837. PREFIX_LIST_STR
  1838. "Name of a prefix list\n"
  1839. "sequence number of an entry\n"
  1840. "Sequence number\n"
  1841. "Specify packets to reject\n"
  1842. "Specify packets to forward\n"
  1843. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1844. "Minimum prefix length to be matched\n"
  1845. "Minimum prefix length\n"
  1846. "Maximum prefix length to be matched\n"
  1847. "Maximum prefix length\n")
  1848. {
  1849. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1850. argv[3], argv[4], argv[5]);
  1851. }
  1852. DEFUN (no_ipv6_prefix_list_seq_le,
  1853. no_ipv6_prefix_list_seq_le_cmd,
  1854. "no ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M le <0-128>",
  1855. NO_STR
  1856. IPV6_STR
  1857. PREFIX_LIST_STR
  1858. "Name of a prefix list\n"
  1859. "sequence number of an entry\n"
  1860. "Sequence number\n"
  1861. "Specify packets to reject\n"
  1862. "Specify packets to forward\n"
  1863. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1864. "Maximum prefix length to be matched\n"
  1865. "Maximum prefix length\n")
  1866. {
  1867. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1868. argv[3], NULL, argv[4]);
  1869. }
  1870. DEFUN (no_ipv6_prefix_list_seq_le_ge,
  1871. no_ipv6_prefix_list_seq_le_ge_cmd,
  1872. "no ipv6 prefix-list WORD seq <1-4294967295> (deny|permit) X:X::X:X/M le <0-128> ge <0-128>",
  1873. NO_STR
  1874. IPV6_STR
  1875. PREFIX_LIST_STR
  1876. "Name of a prefix list\n"
  1877. "sequence number of an entry\n"
  1878. "Sequence number\n"
  1879. "Specify packets to reject\n"
  1880. "Specify packets to forward\n"
  1881. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  1882. "Maximum prefix length to be matched\n"
  1883. "Maximum prefix length\n"
  1884. "Minimum prefix length to be matched\n"
  1885. "Minimum prefix length\n")
  1886. {
  1887. return vty_prefix_list_uninstall (vty, AFI_IP6, argv[0], argv[1], argv[2],
  1888. argv[3], argv[5], argv[4]);
  1889. }
  1890. DEFUN (ipv6_prefix_list_sequence_number,
  1891. ipv6_prefix_list_sequence_number_cmd,
  1892. "ipv6 prefix-list sequence-number",
  1893. IPV6_STR
  1894. PREFIX_LIST_STR
  1895. "Include/exclude sequence numbers in NVGEN\n")
  1896. {
  1897. prefix_master_ipv6.seqnum = 1;
  1898. return CMD_SUCCESS;
  1899. }
  1900. DEFUN (no_ipv6_prefix_list_sequence_number,
  1901. no_ipv6_prefix_list_sequence_number_cmd,
  1902. "no ipv6 prefix-list sequence-number",
  1903. NO_STR
  1904. IPV6_STR
  1905. PREFIX_LIST_STR
  1906. "Include/exclude sequence numbers in NVGEN\n")
  1907. {
  1908. prefix_master_ipv6.seqnum = 0;
  1909. return CMD_SUCCESS;
  1910. }
  1911. DEFUN (ipv6_prefix_list_description,
  1912. ipv6_prefix_list_description_cmd,
  1913. "ipv6 prefix-list WORD description .LINE",
  1914. IPV6_STR
  1915. PREFIX_LIST_STR
  1916. "Name of a prefix list\n"
  1917. "Prefix-list specific description\n"
  1918. "Up to 80 characters describing this prefix-list\n")
  1919. {
  1920. struct prefix_list *plist;
  1921. plist = prefix_list_get (AFI_IP6, 0, argv[0]);
  1922. if (plist->desc)
  1923. {
  1924. XFREE (MTYPE_TMP, plist->desc);
  1925. plist->desc = NULL;
  1926. }
  1927. plist->desc = argv_concat(argv, argc, 1);
  1928. return CMD_SUCCESS;
  1929. }
  1930. DEFUN (no_ipv6_prefix_list_description,
  1931. no_ipv6_prefix_list_description_cmd,
  1932. "no ipv6 prefix-list WORD description",
  1933. NO_STR
  1934. IPV6_STR
  1935. PREFIX_LIST_STR
  1936. "Name of a prefix list\n"
  1937. "Prefix-list specific description\n")
  1938. {
  1939. return vty_prefix_list_desc_unset (vty, AFI_IP6, argv[0]);
  1940. }
  1941. ALIAS (no_ipv6_prefix_list_description,
  1942. no_ipv6_prefix_list_description_arg_cmd,
  1943. "no ipv6 prefix-list WORD description .LINE",
  1944. NO_STR
  1945. IPV6_STR
  1946. PREFIX_LIST_STR
  1947. "Name of a prefix list\n"
  1948. "Prefix-list specific description\n"
  1949. "Up to 80 characters describing this prefix-list\n")
  1950. DEFUN (show_ipv6_prefix_list,
  1951. show_ipv6_prefix_list_cmd,
  1952. "show ipv6 prefix-list",
  1953. SHOW_STR
  1954. IPV6_STR
  1955. PREFIX_LIST_STR)
  1956. {
  1957. return vty_show_prefix_list (vty, AFI_IP6, NULL, NULL, normal_display);
  1958. }
  1959. DEFUN (show_ipv6_prefix_list_name,
  1960. show_ipv6_prefix_list_name_cmd,
  1961. "show ipv6 prefix-list WORD",
  1962. SHOW_STR
  1963. IPV6_STR
  1964. PREFIX_LIST_STR
  1965. "Name of a prefix list\n")
  1966. {
  1967. return vty_show_prefix_list (vty, AFI_IP6, argv[0], NULL, normal_display);
  1968. }
  1969. DEFUN (show_ipv6_prefix_list_name_seq,
  1970. show_ipv6_prefix_list_name_seq_cmd,
  1971. "show ipv6 prefix-list WORD seq <1-4294967295>",
  1972. SHOW_STR
  1973. IPV6_STR
  1974. PREFIX_LIST_STR
  1975. "Name of a prefix list\n"
  1976. "sequence number of an entry\n"
  1977. "Sequence number\n")
  1978. {
  1979. return vty_show_prefix_list (vty, AFI_IP6, argv[0], argv[1], sequential_display);
  1980. }
  1981. DEFUN (show_ipv6_prefix_list_prefix,
  1982. show_ipv6_prefix_list_prefix_cmd,
  1983. "show ipv6 prefix-list WORD X:X::X:X/M",
  1984. SHOW_STR
  1985. IPV6_STR
  1986. PREFIX_LIST_STR
  1987. "Name of a prefix list\n"
  1988. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
  1989. {
  1990. return vty_show_prefix_list_prefix (vty, AFI_IP6, argv[0], argv[1], normal_display);
  1991. }
  1992. DEFUN (show_ipv6_prefix_list_prefix_longer,
  1993. show_ipv6_prefix_list_prefix_longer_cmd,
  1994. "show ipv6 prefix-list WORD X:X::X:X/M longer",
  1995. SHOW_STR
  1996. IPV6_STR
  1997. PREFIX_LIST_STR
  1998. "Name of a prefix list\n"
  1999. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  2000. "Lookup longer prefix\n")
  2001. {
  2002. return vty_show_prefix_list_prefix (vty, AFI_IP6, argv[0], argv[1], longer_display);
  2003. }
  2004. DEFUN (show_ipv6_prefix_list_prefix_first_match,
  2005. show_ipv6_prefix_list_prefix_first_match_cmd,
  2006. "show ipv6 prefix-list WORD X:X::X:X/M first-match",
  2007. SHOW_STR
  2008. IPV6_STR
  2009. PREFIX_LIST_STR
  2010. "Name of a prefix list\n"
  2011. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
  2012. "First matched prefix\n")
  2013. {
  2014. return vty_show_prefix_list_prefix (vty, AFI_IP6, argv[0], argv[1], first_match_display);
  2015. }
  2016. DEFUN (show_ipv6_prefix_list_summary,
  2017. show_ipv6_prefix_list_summary_cmd,
  2018. "show ipv6 prefix-list summary",
  2019. SHOW_STR
  2020. IPV6_STR
  2021. PREFIX_LIST_STR
  2022. "Summary of prefix lists\n")
  2023. {
  2024. return vty_show_prefix_list (vty, AFI_IP6, NULL, NULL, summary_display);
  2025. }
  2026. DEFUN (show_ipv6_prefix_list_summary_name,
  2027. show_ipv6_prefix_list_summary_name_cmd,
  2028. "show ipv6 prefix-list summary WORD",
  2029. SHOW_STR
  2030. IPV6_STR
  2031. PREFIX_LIST_STR
  2032. "Summary of prefix lists\n"
  2033. "Name of a prefix list\n")
  2034. {
  2035. return vty_show_prefix_list (vty, AFI_IP6, argv[0], NULL, summary_display);
  2036. }
  2037. DEFUN (show_ipv6_prefix_list_detail,
  2038. show_ipv6_prefix_list_detail_cmd,
  2039. "show ipv6 prefix-list detail",
  2040. SHOW_STR
  2041. IPV6_STR
  2042. PREFIX_LIST_STR
  2043. "Detail of prefix lists\n")
  2044. {
  2045. return vty_show_prefix_list (vty, AFI_IP6, NULL, NULL, detail_display);
  2046. }
  2047. DEFUN (show_ipv6_prefix_list_detail_name,
  2048. show_ipv6_prefix_list_detail_name_cmd,
  2049. "show ipv6 prefix-list detail WORD",
  2050. SHOW_STR
  2051. IPV6_STR
  2052. PREFIX_LIST_STR
  2053. "Detail of prefix lists\n"
  2054. "Name of a prefix list\n")
  2055. {
  2056. return vty_show_prefix_list (vty, AFI_IP6, argv[0], NULL, detail_display);
  2057. }
  2058. DEFUN (clear_ipv6_prefix_list,
  2059. clear_ipv6_prefix_list_cmd,
  2060. "clear ipv6 prefix-list",
  2061. CLEAR_STR
  2062. IPV6_STR
  2063. PREFIX_LIST_STR)
  2064. {
  2065. return vty_clear_prefix_list (vty, AFI_IP6, NULL, NULL);
  2066. }
  2067. DEFUN (clear_ipv6_prefix_list_name,
  2068. clear_ipv6_prefix_list_name_cmd,
  2069. "clear ipv6 prefix-list WORD",
  2070. CLEAR_STR
  2071. IPV6_STR
  2072. PREFIX_LIST_STR
  2073. "Name of a prefix list\n")
  2074. {
  2075. return vty_clear_prefix_list (vty, AFI_IP6, argv[0], NULL);
  2076. }
  2077. DEFUN (clear_ipv6_prefix_list_name_prefix,
  2078. clear_ipv6_prefix_list_name_prefix_cmd,
  2079. "clear ipv6 prefix-list WORD X:X::X:X/M",
  2080. CLEAR_STR
  2081. IPV6_STR
  2082. PREFIX_LIST_STR
  2083. "Name of a prefix list\n"
  2084. "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
  2085. {
  2086. return vty_clear_prefix_list (vty, AFI_IP6, argv[0], argv[1]);
  2087. }
  2088. #endif /* HAVE_IPV6 */
  2089. /* Configuration write function. */
  2090. static int
  2091. config_write_prefix_afi (afi_t afi, struct vty *vty)
  2092. {
  2093. struct prefix_list *plist;
  2094. struct prefix_list_entry *pentry;
  2095. struct prefix_master *master;
  2096. int write = 0;
  2097. master = prefix_master_get (afi, 0);
  2098. if (master == NULL)
  2099. return 0;
  2100. if (! master->seqnum)
  2101. {
  2102. vty_out (vty, "no ip%s prefix-list sequence-number%s",
  2103. afi == AFI_IP ? "" : "v6", VTY_NEWLINE);
  2104. vty_out (vty, "!%s", VTY_NEWLINE);
  2105. }
  2106. for (plist = master->num.head; plist; plist = plist->next)
  2107. {
  2108. if (plist->desc)
  2109. {
  2110. vty_out (vty, "ip%s prefix-list %s description %s%s",
  2111. afi == AFI_IP ? "" : "v6",
  2112. plist->name, plist->desc, VTY_NEWLINE);
  2113. write++;
  2114. }
  2115. for (pentry = plist->head; pentry; pentry = pentry->next)
  2116. {
  2117. vty_out (vty, "ip%s prefix-list %s ",
  2118. afi == AFI_IP ? "" : "v6",
  2119. plist->name);
  2120. if (master->seqnum)
  2121. vty_out (vty, "seq %d ", pentry->seq);
  2122. vty_out (vty, "%s ", prefix_list_type_str (pentry));
  2123. if (pentry->any)
  2124. vty_out (vty, "any");
  2125. else
  2126. {
  2127. struct prefix *p = &pentry->prefix;
  2128. char buf[BUFSIZ];
  2129. vty_out (vty, "%s/%d",
  2130. inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
  2131. p->prefixlen);
  2132. if (pentry->ge)
  2133. vty_out (vty, " ge %d", pentry->ge);
  2134. if (pentry->le)
  2135. vty_out (vty, " le %d", pentry->le);
  2136. }
  2137. vty_out (vty, "%s", VTY_NEWLINE);
  2138. write++;
  2139. }
  2140. /* vty_out (vty, "!%s", VTY_NEWLINE); */
  2141. }
  2142. for (plist = master->str.head; plist; plist = plist->next)
  2143. {
  2144. if (plist->desc)
  2145. {
  2146. vty_out (vty, "ip%s prefix-list %s description %s%s",
  2147. afi == AFI_IP ? "" : "v6",
  2148. plist->name, plist->desc, VTY_NEWLINE);
  2149. write++;
  2150. }
  2151. for (pentry = plist->head; pentry; pentry = pentry->next)
  2152. {
  2153. vty_out (vty, "ip%s prefix-list %s ",
  2154. afi == AFI_IP ? "" : "v6",
  2155. plist->name);
  2156. if (master->seqnum)
  2157. vty_out (vty, "seq %d ", pentry->seq);
  2158. vty_out (vty, "%s", prefix_list_type_str (pentry));
  2159. if (pentry->any)
  2160. vty_out (vty, " any");
  2161. else
  2162. {
  2163. struct prefix *p = &pentry->prefix;
  2164. char buf[BUFSIZ];
  2165. vty_out (vty, " %s/%d",
  2166. inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
  2167. p->prefixlen);
  2168. if (pentry->ge)
  2169. vty_out (vty, " ge %d", pentry->ge);
  2170. if (pentry->le)
  2171. vty_out (vty, " le %d", pentry->le);
  2172. }
  2173. vty_out (vty, "%s", VTY_NEWLINE);
  2174. write++;
  2175. }
  2176. }
  2177. return write;
  2178. }
  2179. struct stream *
  2180. prefix_bgp_orf_entry (struct stream *s, struct prefix_list *plist,
  2181. u_char init_flag, u_char permit_flag, u_char deny_flag)
  2182. {
  2183. struct prefix_list_entry *pentry;
  2184. if (! plist)
  2185. return s;
  2186. for (pentry = plist->head; pentry; pentry = pentry->next)
  2187. {
  2188. u_char flag = init_flag;
  2189. struct prefix *p = &pentry->prefix;
  2190. flag |= (pentry->type == PREFIX_PERMIT ?
  2191. permit_flag : deny_flag);
  2192. stream_putc (s, flag);
  2193. stream_putl (s, (u_int32_t)pentry->seq);
  2194. stream_putc (s, (u_char)pentry->ge);
  2195. stream_putc (s, (u_char)pentry->le);
  2196. stream_put_prefix (s, p);
  2197. }
  2198. return s;
  2199. }
  2200. int
  2201. prefix_bgp_orf_set (char *name, afi_t afi, struct orf_prefix *orfp,
  2202. int permit, int set)
  2203. {
  2204. struct prefix_list *plist;
  2205. struct prefix_list_entry *pentry;
  2206. /* ge and le value check */
  2207. if (orfp->ge && orfp->ge <= orfp->p.prefixlen)
  2208. return CMD_WARNING;
  2209. if (orfp->le && orfp->le <= orfp->p.prefixlen)
  2210. return CMD_WARNING;
  2211. if (orfp->le && orfp->ge > orfp->le)
  2212. return CMD_WARNING;
  2213. if (orfp->ge && orfp->le == (afi == AFI_IP ? 32 : 128))
  2214. orfp->le = 0;
  2215. plist = prefix_list_get (afi, 1, name);
  2216. if (! plist)
  2217. return CMD_WARNING;
  2218. if (set)
  2219. {
  2220. pentry = prefix_list_entry_make (&orfp->p,
  2221. (permit ? PREFIX_PERMIT : PREFIX_DENY),
  2222. orfp->seq, orfp->le, orfp->ge, 0);
  2223. if (prefix_entry_dup_check (plist, pentry))
  2224. {
  2225. prefix_list_entry_free (pentry);
  2226. return CMD_WARNING;
  2227. }
  2228. prefix_list_entry_add (plist, pentry);
  2229. }
  2230. else
  2231. {
  2232. pentry = prefix_list_entry_lookup (plist, &orfp->p,
  2233. (permit ? PREFIX_PERMIT : PREFIX_DENY),
  2234. orfp->seq, orfp->le, orfp->ge);
  2235. if (! pentry)
  2236. return CMD_WARNING;
  2237. prefix_list_entry_delete (plist, pentry, 1);
  2238. }
  2239. return CMD_SUCCESS;
  2240. }
  2241. void
  2242. prefix_bgp_orf_remove_all (afi_t afi, char *name)
  2243. {
  2244. struct prefix_list *plist;
  2245. plist = prefix_bgp_orf_lookup (afi, name);
  2246. if (plist)
  2247. prefix_list_delete (plist);
  2248. }
  2249. /* return prefix count */
  2250. int
  2251. prefix_bgp_show_prefix_list (struct vty *vty, afi_t afi, char *name)
  2252. {
  2253. struct prefix_list *plist;
  2254. struct prefix_list_entry *pentry;
  2255. plist = prefix_bgp_orf_lookup (afi, name);
  2256. if (! plist)
  2257. return 0;
  2258. if (! vty)
  2259. return plist->count;
  2260. vty_out (vty, "ip%s prefix-list %s: %d entries%s",
  2261. afi == AFI_IP ? "" : "v6",
  2262. plist->name, plist->count, VTY_NEWLINE);
  2263. for (pentry = plist->head; pentry; pentry = pentry->next)
  2264. {
  2265. struct prefix *p = &pentry->prefix;
  2266. char buf[BUFSIZ];
  2267. vty_out (vty, " seq %d %s %s/%d", pentry->seq,
  2268. prefix_list_type_str (pentry),
  2269. inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
  2270. p->prefixlen);
  2271. if (pentry->ge)
  2272. vty_out (vty, " ge %d", pentry->ge);
  2273. if (pentry->le)
  2274. vty_out (vty, " le %d", pentry->le);
  2275. vty_out (vty, "%s", VTY_NEWLINE);
  2276. }
  2277. return plist->count;
  2278. }
  2279. static void
  2280. prefix_list_reset_afi (afi_t afi, int orf)
  2281. {
  2282. struct prefix_list *plist;
  2283. struct prefix_list *next;
  2284. struct prefix_master *master;
  2285. master = prefix_master_get (afi, orf);
  2286. if (master == NULL)
  2287. return;
  2288. for (plist = master->num.head; plist; plist = next)
  2289. {
  2290. next = plist->next;
  2291. prefix_list_delete (plist);
  2292. }
  2293. for (plist = master->str.head; plist; plist = next)
  2294. {
  2295. next = plist->next;
  2296. prefix_list_delete (plist);
  2297. }
  2298. assert (master->num.head == NULL);
  2299. assert (master->num.tail == NULL);
  2300. assert (master->str.head == NULL);
  2301. assert (master->str.tail == NULL);
  2302. master->seqnum = 1;
  2303. master->recent = NULL;
  2304. }
  2305. /* Prefix-list node. */
  2306. static struct cmd_node prefix_node =
  2307. {
  2308. PREFIX_NODE,
  2309. "", /* Prefix list has no interface. */
  2310. 1
  2311. };
  2312. static int
  2313. config_write_prefix_ipv4 (struct vty *vty)
  2314. {
  2315. return config_write_prefix_afi (AFI_IP, vty);
  2316. }
  2317. static void
  2318. prefix_list_init_ipv4 (void)
  2319. {
  2320. install_node (&prefix_node, config_write_prefix_ipv4);
  2321. install_element (CONFIG_NODE, &ip_prefix_list_cmd);
  2322. install_element (CONFIG_NODE, &ip_prefix_list_ge_cmd);
  2323. install_element (CONFIG_NODE, &ip_prefix_list_ge_le_cmd);
  2324. install_element (CONFIG_NODE, &ip_prefix_list_le_cmd);
  2325. install_element (CONFIG_NODE, &ip_prefix_list_le_ge_cmd);
  2326. install_element (CONFIG_NODE, &ip_prefix_list_seq_cmd);
  2327. install_element (CONFIG_NODE, &ip_prefix_list_seq_ge_cmd);
  2328. install_element (CONFIG_NODE, &ip_prefix_list_seq_ge_le_cmd);
  2329. install_element (CONFIG_NODE, &ip_prefix_list_seq_le_cmd);
  2330. install_element (CONFIG_NODE, &ip_prefix_list_seq_le_ge_cmd);
  2331. install_element (CONFIG_NODE, &no_ip_prefix_list_cmd);
  2332. install_element (CONFIG_NODE, &no_ip_prefix_list_prefix_cmd);
  2333. install_element (CONFIG_NODE, &no_ip_prefix_list_ge_cmd);
  2334. install_element (CONFIG_NODE, &no_ip_prefix_list_ge_le_cmd);
  2335. install_element (CONFIG_NODE, &no_ip_prefix_list_le_cmd);
  2336. install_element (CONFIG_NODE, &no_ip_prefix_list_le_ge_cmd);
  2337. install_element (CONFIG_NODE, &no_ip_prefix_list_seq_cmd);
  2338. install_element (CONFIG_NODE, &no_ip_prefix_list_seq_ge_cmd);
  2339. install_element (CONFIG_NODE, &no_ip_prefix_list_seq_ge_le_cmd);
  2340. install_element (CONFIG_NODE, &no_ip_prefix_list_seq_le_cmd);
  2341. install_element (CONFIG_NODE, &no_ip_prefix_list_seq_le_ge_cmd);
  2342. install_element (CONFIG_NODE, &ip_prefix_list_description_cmd);
  2343. install_element (CONFIG_NODE, &no_ip_prefix_list_description_cmd);
  2344. install_element (CONFIG_NODE, &no_ip_prefix_list_description_arg_cmd);
  2345. install_element (CONFIG_NODE, &ip_prefix_list_sequence_number_cmd);
  2346. install_element (CONFIG_NODE, &no_ip_prefix_list_sequence_number_cmd);
  2347. install_element (VIEW_NODE, &show_ip_prefix_list_cmd);
  2348. install_element (VIEW_NODE, &show_ip_prefix_list_name_cmd);
  2349. install_element (VIEW_NODE, &show_ip_prefix_list_name_seq_cmd);
  2350. install_element (VIEW_NODE, &show_ip_prefix_list_prefix_cmd);
  2351. install_element (VIEW_NODE, &show_ip_prefix_list_prefix_longer_cmd);
  2352. install_element (VIEW_NODE, &show_ip_prefix_list_prefix_first_match_cmd);
  2353. install_element (VIEW_NODE, &show_ip_prefix_list_summary_cmd);
  2354. install_element (VIEW_NODE, &show_ip_prefix_list_summary_name_cmd);
  2355. install_element (VIEW_NODE, &show_ip_prefix_list_detail_cmd);
  2356. install_element (VIEW_NODE, &show_ip_prefix_list_detail_name_cmd);
  2357. install_element (ENABLE_NODE, &clear_ip_prefix_list_cmd);
  2358. install_element (ENABLE_NODE, &clear_ip_prefix_list_name_cmd);
  2359. install_element (ENABLE_NODE, &clear_ip_prefix_list_name_prefix_cmd);
  2360. }
  2361. /* Prefix-list node. */
  2362. static struct cmd_node prefix_ipv6_node =
  2363. {
  2364. PREFIX_IPV6_NODE,
  2365. "", /* Prefix list has no interface. */
  2366. 1
  2367. };
  2368. static int
  2369. config_write_prefix_ipv6 (struct vty *vty)
  2370. {
  2371. return config_write_prefix_afi (AFI_IP6, vty);
  2372. }
  2373. static void
  2374. prefix_list_init_ipv6 (void)
  2375. {
  2376. install_node (&prefix_ipv6_node, config_write_prefix_ipv6);
  2377. install_element (CONFIG_NODE, &ipv6_prefix_list_cmd);
  2378. install_element (CONFIG_NODE, &ipv6_prefix_list_ge_cmd);
  2379. install_element (CONFIG_NODE, &ipv6_prefix_list_ge_le_cmd);
  2380. install_element (CONFIG_NODE, &ipv6_prefix_list_le_cmd);
  2381. install_element (CONFIG_NODE, &ipv6_prefix_list_le_ge_cmd);
  2382. install_element (CONFIG_NODE, &ipv6_prefix_list_seq_cmd);
  2383. install_element (CONFIG_NODE, &ipv6_prefix_list_seq_ge_cmd);
  2384. install_element (CONFIG_NODE, &ipv6_prefix_list_seq_ge_le_cmd);
  2385. install_element (CONFIG_NODE, &ipv6_prefix_list_seq_le_cmd);
  2386. install_element (CONFIG_NODE, &ipv6_prefix_list_seq_le_ge_cmd);
  2387. install_element (CONFIG_NODE, &no_ipv6_prefix_list_cmd);
  2388. install_element (CONFIG_NODE, &no_ipv6_prefix_list_prefix_cmd);
  2389. install_element (CONFIG_NODE, &no_ipv6_prefix_list_ge_cmd);
  2390. install_element (CONFIG_NODE, &no_ipv6_prefix_list_ge_le_cmd);
  2391. install_element (CONFIG_NODE, &no_ipv6_prefix_list_le_cmd);
  2392. install_element (CONFIG_NODE, &no_ipv6_prefix_list_le_ge_cmd);
  2393. install_element (CONFIG_NODE, &no_ipv6_prefix_list_seq_cmd);
  2394. install_element (CONFIG_NODE, &no_ipv6_prefix_list_seq_ge_cmd);
  2395. install_element (CONFIG_NODE, &no_ipv6_prefix_list_seq_ge_le_cmd);
  2396. install_element (CONFIG_NODE, &no_ipv6_prefix_list_seq_le_cmd);
  2397. install_element (CONFIG_NODE, &no_ipv6_prefix_list_seq_le_ge_cmd);
  2398. install_element (CONFIG_NODE, &ipv6_prefix_list_description_cmd);
  2399. install_element (CONFIG_NODE, &no_ipv6_prefix_list_description_cmd);
  2400. install_element (CONFIG_NODE, &no_ipv6_prefix_list_description_arg_cmd);
  2401. install_element (CONFIG_NODE, &ipv6_prefix_list_sequence_number_cmd);
  2402. install_element (CONFIG_NODE, &no_ipv6_prefix_list_sequence_number_cmd);
  2403. install_element (VIEW_NODE, &show_ipv6_prefix_list_cmd);
  2404. install_element (VIEW_NODE, &show_ipv6_prefix_list_name_cmd);
  2405. install_element (VIEW_NODE, &show_ipv6_prefix_list_name_seq_cmd);
  2406. install_element (VIEW_NODE, &show_ipv6_prefix_list_prefix_cmd);
  2407. install_element (VIEW_NODE, &show_ipv6_prefix_list_prefix_longer_cmd);
  2408. install_element (VIEW_NODE, &show_ipv6_prefix_list_prefix_first_match_cmd);
  2409. install_element (VIEW_NODE, &show_ipv6_prefix_list_summary_cmd);
  2410. install_element (VIEW_NODE, &show_ipv6_prefix_list_summary_name_cmd);
  2411. install_element (VIEW_NODE, &show_ipv6_prefix_list_detail_cmd);
  2412. install_element (VIEW_NODE, &show_ipv6_prefix_list_detail_name_cmd);
  2413. install_element (ENABLE_NODE, &clear_ipv6_prefix_list_cmd);
  2414. install_element (ENABLE_NODE, &clear_ipv6_prefix_list_name_cmd);
  2415. install_element (ENABLE_NODE, &clear_ipv6_prefix_list_name_prefix_cmd);
  2416. }
  2417. void
  2418. prefix_list_init ()
  2419. {
  2420. prefix_list_init_ipv4 ();
  2421. #ifdef HAVE_IPV6
  2422. prefix_list_init_ipv6 ();
  2423. #endif /* HAVE_IPV6 */
  2424. }
  2425. void
  2426. prefix_list_reset ()
  2427. {
  2428. prefix_list_reset_afi (AFI_IP, 0);
  2429. prefix_list_reset_afi (AFI_IP6, 0);
  2430. prefix_list_reset_afi (AFI_IP, 1);
  2431. prefix_list_reset_afi (AFI_IP6, 1);
  2432. }