plist.c 75 KB

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