rip_interface.c 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193
  1. /* Interface related function for RIP.
  2. * Copyright (C) 1997, 98 Kunihiro Ishiguro <kunihiro@zebra.org>
  3. *
  4. * This file is part of GNU Zebra.
  5. *
  6. * GNU Zebra is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2, or (at your option) any
  9. * 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 Free
  18. * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  19. * 02111-1307, USA.
  20. */
  21. #include <zebra.h>
  22. #include "command.h"
  23. #include "if.h"
  24. #include "sockunion.h"
  25. #include "prefix.h"
  26. #include "memory.h"
  27. #include "network.h"
  28. #include "table.h"
  29. #include "log.h"
  30. #include "stream.h"
  31. #include "thread.h"
  32. #include "zclient.h"
  33. #include "filter.h"
  34. #include "sockopt.h"
  35. #include "privs.h"
  36. #include "zebra/connected.h"
  37. #include "ripd/ripd.h"
  38. #include "ripd/rip_debug.h"
  39. #include "ripd/rip_interface.h"
  40. /* static prototypes */
  41. static void rip_enable_apply (struct interface *);
  42. static void rip_passive_interface_apply (struct interface *);
  43. static int rip_if_down(struct interface *ifp);
  44. static int rip_enable_if_lookup (const char *ifname);
  45. static int rip_enable_network_lookup2 (struct connected *connected);
  46. static void rip_enable_apply_all (void);
  47. struct message ri_version_msg[] =
  48. {
  49. {RI_RIP_VERSION_1, "1"},
  50. {RI_RIP_VERSION_2, "2"},
  51. {RI_RIP_VERSION_1_AND_2, "1 2"},
  52. {0, NULL}
  53. };
  54. extern struct zebra_privs_t ripd_privs;
  55. /* RIP enabled network vector. */
  56. vector rip_enable_interface;
  57. /* RIP enabled interface table. */
  58. struct route_table *rip_enable_network;
  59. /* Vector to store passive-interface name. */
  60. static int passive_default; /* are we in passive-interface default mode? */
  61. vector Vrip_passive_nondefault;
  62. /* Join to the RIP version 2 multicast group. */
  63. static int
  64. ipv4_multicast_join (int sock,
  65. struct in_addr group,
  66. struct in_addr ifa,
  67. unsigned int ifindex)
  68. {
  69. int ret;
  70. ret = setsockopt_multicast_ipv4 (sock,
  71. IP_ADD_MEMBERSHIP,
  72. ifa,
  73. group.s_addr,
  74. ifindex);
  75. if (ret < 0)
  76. zlog (NULL, LOG_INFO, "can't setsockopt IP_ADD_MEMBERSHIP %s",
  77. safe_strerror (errno));
  78. return ret;
  79. }
  80. /* Leave from the RIP version 2 multicast group. */
  81. static int
  82. ipv4_multicast_leave (int sock,
  83. struct in_addr group,
  84. struct in_addr ifa,
  85. unsigned int ifindex)
  86. {
  87. int ret;
  88. ret = setsockopt_multicast_ipv4 (sock,
  89. IP_DROP_MEMBERSHIP,
  90. ifa,
  91. group.s_addr,
  92. ifindex);
  93. if (ret < 0)
  94. zlog (NULL, LOG_INFO, "can't setsockopt IP_DROP_MEMBERSHIP");
  95. return ret;
  96. }
  97. /* Allocate new RIP's interface configuration. */
  98. static struct rip_interface *
  99. rip_interface_new (void)
  100. {
  101. struct rip_interface *ri;
  102. ri = XMALLOC (MTYPE_RIP_INTERFACE, sizeof (struct rip_interface));
  103. memset (ri, 0, sizeof (struct rip_interface));
  104. /* Default authentication type is simple password for Cisco
  105. compatibility. */
  106. ri->auth_type = RIP_NO_AUTH;
  107. ri->md5_auth_len = RIP_AUTH_MD5_COMPAT_SIZE;
  108. /* Set default split-horizon behavior. If the interface is Frame
  109. Relay or SMDS is enabled, the default value for split-horizon is
  110. off. But currently Zebra does detect Frame Relay or SMDS
  111. interface. So all interface is set to split horizon. */
  112. ri->split_horizon_default = RIP_SPLIT_HORIZON;
  113. ri->split_horizon = ri->split_horizon_default;
  114. return ri;
  115. }
  116. void
  117. rip_interface_multicast_set (int sock, struct connected *connected)
  118. {
  119. struct in_addr addr;
  120. struct prefix_ipv4 *p;
  121. assert (connected != NULL);
  122. if (if_is_pointopoint(connected->ifp) && CONNECTED_DEST_HOST(connected))
  123. p = (struct prefix_ipv4 *) connected->destination;
  124. else
  125. p = (struct prefix_ipv4 *) connected->address;
  126. addr = p->prefix;
  127. if (setsockopt_multicast_ipv4 (sock, IP_MULTICAST_IF, addr, 0,
  128. connected->ifp->ifindex) < 0)
  129. {
  130. zlog_warn ("Can't setsockopt IP_MULTICAST_IF on fd %d to "
  131. "source address %s for interface %s",
  132. sock, inet_ntoa(addr),
  133. connected->ifp->name);
  134. }
  135. return;
  136. }
  137. /* Send RIP request packet to specified interface. */
  138. static void
  139. rip_request_interface_send (struct interface *ifp, u_char version)
  140. {
  141. struct sockaddr_in to;
  142. /* RIPv2 support multicast. */
  143. if (version == RIPv2 && if_is_multicast (ifp))
  144. {
  145. if (IS_RIP_DEBUG_EVENT)
  146. zlog_debug ("multicast request on %s", ifp->name);
  147. rip_request_send (NULL, ifp, version, NULL);
  148. return;
  149. }
  150. /* RIPv1 and non multicast interface. */
  151. if (if_is_pointopoint (ifp) || if_is_broadcast (ifp))
  152. {
  153. struct listnode *cnode, *cnnode;
  154. struct connected *connected;
  155. if (IS_RIP_DEBUG_EVENT)
  156. zlog_debug ("broadcast request to %s", ifp->name);
  157. for (ALL_LIST_ELEMENTS (ifp->connected, cnode, cnnode, connected))
  158. {
  159. if (connected->address->family == AF_INET)
  160. {
  161. memset (&to, 0, sizeof (struct sockaddr_in));
  162. to.sin_port = htons (RIP_PORT_DEFAULT);
  163. if (connected->destination)
  164. /* use specified broadcast or point-to-point destination addr */
  165. to.sin_addr = connected->destination->u.prefix4;
  166. else
  167. /* calculate the appropriate broadcast address */
  168. to.sin_addr.s_addr =
  169. ipv4_broadcast_addr(connected->address->u.prefix4.s_addr,
  170. connected->address->prefixlen);
  171. if (IS_RIP_DEBUG_EVENT)
  172. zlog_debug ("SEND request to %s", inet_ntoa (to.sin_addr));
  173. rip_request_send (&to, ifp, version, connected);
  174. }
  175. }
  176. }
  177. }
  178. /* This will be executed when interface goes up. */
  179. static void
  180. rip_request_interface (struct interface *ifp)
  181. {
  182. struct rip_interface *ri;
  183. /* In default ripd doesn't send RIP_REQUEST to the loopback interface. */
  184. if (if_is_loopback (ifp))
  185. return;
  186. /* If interface is down, don't send RIP packet. */
  187. if (! if_is_operative (ifp))
  188. return;
  189. /* Fetch RIP interface information. */
  190. ri = ifp->info;
  191. /* If there is no version configuration in the interface,
  192. use rip's version setting. */
  193. {
  194. int vsend = ((ri->ri_send == RI_RIP_UNSPEC) ?
  195. rip->version_send : ri->ri_send);
  196. if (vsend & RIPv1)
  197. rip_request_interface_send (ifp, RIPv1);
  198. if (vsend & RIPv2)
  199. rip_request_interface_send (ifp, RIPv2);
  200. }
  201. }
  202. /* Send RIP request to the neighbor. */
  203. static void
  204. rip_request_neighbor (struct in_addr addr)
  205. {
  206. struct sockaddr_in to;
  207. memset (&to, 0, sizeof (struct sockaddr_in));
  208. to.sin_port = htons (RIP_PORT_DEFAULT);
  209. to.sin_addr = addr;
  210. rip_request_send (&to, NULL, rip->version_send, NULL);
  211. }
  212. /* Request routes at all interfaces. */
  213. static void
  214. rip_request_neighbor_all (void)
  215. {
  216. struct route_node *rp;
  217. if (! rip)
  218. return;
  219. if (IS_RIP_DEBUG_EVENT)
  220. zlog_debug ("request to the all neighbor");
  221. /* Send request to all neighbor. */
  222. for (rp = route_top (rip->neighbor); rp; rp = route_next (rp))
  223. if (rp->info)
  224. rip_request_neighbor (rp->p.u.prefix4);
  225. }
  226. /* Multicast packet receive socket. */
  227. static int
  228. rip_multicast_join (struct interface *ifp, int sock)
  229. {
  230. struct listnode *cnode;
  231. struct connected *ifc;
  232. if (if_is_operative (ifp) && if_is_multicast (ifp))
  233. {
  234. if (IS_RIP_DEBUG_EVENT)
  235. zlog_debug ("multicast join at %s", ifp->name);
  236. for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, ifc))
  237. {
  238. struct prefix_ipv4 *p;
  239. struct in_addr group;
  240. p = (struct prefix_ipv4 *) ifc->address;
  241. if (p->family != AF_INET)
  242. continue;
  243. group.s_addr = htonl (INADDR_RIP_GROUP);
  244. if (ipv4_multicast_join (sock, group, p->prefix, ifp->ifindex) < 0)
  245. return -1;
  246. else
  247. return 0;
  248. }
  249. }
  250. return 0;
  251. }
  252. /* Leave from multicast group. */
  253. static void
  254. rip_multicast_leave (struct interface *ifp, int sock)
  255. {
  256. struct listnode *cnode;
  257. struct connected *connected;
  258. if (if_is_up (ifp) && if_is_multicast (ifp))
  259. {
  260. if (IS_RIP_DEBUG_EVENT)
  261. zlog_debug ("multicast leave from %s", ifp->name);
  262. for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected))
  263. {
  264. struct prefix_ipv4 *p;
  265. struct in_addr group;
  266. p = (struct prefix_ipv4 *) connected->address;
  267. if (p->family != AF_INET)
  268. continue;
  269. group.s_addr = htonl (INADDR_RIP_GROUP);
  270. if (ipv4_multicast_leave (sock, group, p->prefix, ifp->ifindex) == 0)
  271. return;
  272. }
  273. }
  274. }
  275. /* Is there and address on interface that I could use ? */
  276. static int
  277. rip_if_ipv4_address_check (struct interface *ifp)
  278. {
  279. struct listnode *nn;
  280. struct connected *connected;
  281. int count = 0;
  282. for (ALL_LIST_ELEMENTS_RO (ifp->connected, nn, connected))
  283. {
  284. struct prefix *p;
  285. p = connected->address;
  286. if (p->family == AF_INET)
  287. count++;
  288. }
  289. return count;
  290. }
  291. /* Does this address belongs to me ? */
  292. int
  293. if_check_address (struct in_addr addr)
  294. {
  295. struct listnode *node;
  296. struct interface *ifp;
  297. for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
  298. {
  299. struct listnode *cnode;
  300. struct connected *connected;
  301. for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected))
  302. {
  303. struct prefix_ipv4 *p;
  304. p = (struct prefix_ipv4 *) connected->address;
  305. if (p->family != AF_INET)
  306. continue;
  307. if (IPV4_ADDR_CMP (&p->prefix, &addr) == 0)
  308. return 1;
  309. }
  310. }
  311. return 0;
  312. }
  313. /* is this address from a valid neighbor? (RFC2453 - Sec. 3.9.2) */
  314. int
  315. if_valid_neighbor (struct in_addr addr)
  316. {
  317. struct listnode *node;
  318. struct connected *connected = NULL;
  319. struct interface *ifp;
  320. struct prefix_ipv4 *p;
  321. struct prefix_ipv4 pa;
  322. pa.family = AF_INET;
  323. pa.prefix = addr;
  324. pa.prefixlen = IPV4_MAX_PREFIXLEN;
  325. for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
  326. {
  327. struct listnode *cnode;
  328. for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected))
  329. {
  330. if (if_is_pointopoint (ifp))
  331. {
  332. p = (struct prefix_ipv4 *) connected->address;
  333. if (p && p->family == AF_INET)
  334. {
  335. if (IPV4_ADDR_SAME (&p->prefix, &addr))
  336. return 1;
  337. p = (struct prefix_ipv4 *) connected->destination;
  338. if (p)
  339. {
  340. if (IPV4_ADDR_SAME (&p->prefix, &addr))
  341. return 1;
  342. }
  343. else
  344. {
  345. if (prefix_match(connected->address,(struct prefix *)&pa))
  346. return 1;
  347. }
  348. }
  349. }
  350. else
  351. {
  352. if ((connected->address->family == AF_INET) &&
  353. prefix_match(connected->address,(struct prefix *)&pa))
  354. return 1;
  355. }
  356. }
  357. }
  358. return 0;
  359. }
  360. /* Inteface link down message processing. */
  361. int
  362. rip_interface_down (int command, struct zclient *zclient, zebra_size_t length)
  363. {
  364. struct interface *ifp;
  365. struct stream *s;
  366. s = zclient->ibuf;
  367. /* zebra_interface_state_read() updates interface structure in
  368. iflist. */
  369. ifp = zebra_interface_state_read(s);
  370. if (ifp == NULL)
  371. return 0;
  372. rip_if_down(ifp);
  373. if (IS_RIP_DEBUG_ZEBRA)
  374. zlog_debug ("interface %s index %d flags %ld metric %d mtu %d is down",
  375. ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu);
  376. return 0;
  377. }
  378. /* Inteface link up message processing */
  379. int
  380. rip_interface_up (int command, struct zclient *zclient, zebra_size_t length)
  381. {
  382. struct interface *ifp;
  383. /* zebra_interface_state_read () updates interface structure in
  384. iflist. */
  385. ifp = zebra_interface_state_read (zclient->ibuf);
  386. if (ifp == NULL)
  387. return 0;
  388. if (IS_RIP_DEBUG_ZEBRA)
  389. zlog_debug ("interface %s index %d flags %ld metric %d mtu %d is up",
  390. ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu);
  391. /* Check if this interface is RIP enabled or not.*/
  392. rip_enable_apply (ifp);
  393. /* Check for a passive interface */
  394. rip_passive_interface_apply (ifp);
  395. /* Apply distribute list to the all interface. */
  396. rip_distribute_update_interface (ifp);
  397. return 0;
  398. }
  399. /* Inteface addition message from zebra. */
  400. int
  401. rip_interface_add (int command, struct zclient *zclient, zebra_size_t length)
  402. {
  403. struct interface *ifp;
  404. ifp = zebra_interface_add_read (zclient->ibuf);
  405. if (IS_RIP_DEBUG_ZEBRA)
  406. zlog_debug ("interface add %s index %d flags %ld metric %d mtu %d",
  407. ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu);
  408. /* Check if this interface is RIP enabled or not.*/
  409. rip_enable_apply (ifp);
  410. /* Check for a passive interface */
  411. rip_passive_interface_apply (ifp);
  412. /* Apply distribute list to the all interface. */
  413. rip_distribute_update_interface (ifp);
  414. /* rip_request_neighbor_all (); */
  415. /* Check interface routemap. */
  416. rip_if_rmap_update_interface (ifp);
  417. return 0;
  418. }
  419. int
  420. rip_interface_delete (int command, struct zclient *zclient,
  421. zebra_size_t length)
  422. {
  423. struct interface *ifp;
  424. struct stream *s;
  425. s = zclient->ibuf;
  426. /* zebra_interface_state_read() updates interface structure in iflist */
  427. ifp = zebra_interface_state_read(s);
  428. if (ifp == NULL)
  429. return 0;
  430. if (if_is_up (ifp)) {
  431. rip_if_down(ifp);
  432. }
  433. zlog_info("interface delete %s index %d flags %ld metric %d mtu %d",
  434. ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu);
  435. /* To support pseudo interface do not free interface structure. */
  436. /* if_delete(ifp); */
  437. ifp->ifindex = IFINDEX_INTERNAL;
  438. return 0;
  439. }
  440. void
  441. rip_interface_clean (void)
  442. {
  443. struct listnode *node;
  444. struct interface *ifp;
  445. struct rip_interface *ri;
  446. for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
  447. {
  448. ri = ifp->info;
  449. ri->enable_network = 0;
  450. ri->enable_interface = 0;
  451. ri->running = 0;
  452. if (ri->t_wakeup)
  453. {
  454. thread_cancel (ri->t_wakeup);
  455. ri->t_wakeup = NULL;
  456. }
  457. }
  458. }
  459. void
  460. rip_interface_reset (void)
  461. {
  462. struct listnode *node;
  463. struct interface *ifp;
  464. struct rip_interface *ri;
  465. for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
  466. {
  467. ri = ifp->info;
  468. ri->enable_network = 0;
  469. ri->enable_interface = 0;
  470. ri->running = 0;
  471. ri->ri_send = RI_RIP_UNSPEC;
  472. ri->ri_receive = RI_RIP_UNSPEC;
  473. ri->auth_type = RIP_NO_AUTH;
  474. if (ri->auth_str)
  475. {
  476. free (ri->auth_str);
  477. ri->auth_str = NULL;
  478. }
  479. if (ri->key_chain)
  480. {
  481. free (ri->key_chain);
  482. ri->key_chain = NULL;
  483. }
  484. ri->split_horizon = RIP_NO_SPLIT_HORIZON;
  485. ri->split_horizon_default = RIP_NO_SPLIT_HORIZON;
  486. ri->list[RIP_FILTER_IN] = NULL;
  487. ri->list[RIP_FILTER_OUT] = NULL;
  488. ri->prefix[RIP_FILTER_IN] = NULL;
  489. ri->prefix[RIP_FILTER_OUT] = NULL;
  490. if (ri->t_wakeup)
  491. {
  492. thread_cancel (ri->t_wakeup);
  493. ri->t_wakeup = NULL;
  494. }
  495. ri->recv_badpackets = 0;
  496. ri->recv_badroutes = 0;
  497. ri->sent_updates = 0;
  498. ri->passive = 0;
  499. }
  500. }
  501. int
  502. rip_if_down(struct interface *ifp)
  503. {
  504. struct route_node *rp;
  505. struct rip_info *rinfo;
  506. struct rip_interface *ri = NULL;
  507. if (rip)
  508. {
  509. for (rp = route_top (rip->table); rp; rp = route_next (rp))
  510. if ((rinfo = rp->info) != NULL)
  511. {
  512. /* Routes got through this interface. */
  513. if (rinfo->ifindex == ifp->ifindex &&
  514. rinfo->type == ZEBRA_ROUTE_RIP &&
  515. rinfo->sub_type == RIP_ROUTE_RTE)
  516. {
  517. rip_zebra_ipv4_delete ((struct prefix_ipv4 *) &rp->p,
  518. &rinfo->nexthop,
  519. rinfo->ifindex);
  520. rip_redistribute_delete (rinfo->type,rinfo->sub_type,
  521. (struct prefix_ipv4 *)&rp->p,
  522. rinfo->ifindex);
  523. }
  524. else
  525. {
  526. /* All redistributed routes but static and system */
  527. if ((rinfo->ifindex == ifp->ifindex) &&
  528. /* (rinfo->type != ZEBRA_ROUTE_STATIC) && */
  529. (rinfo->type != ZEBRA_ROUTE_SYSTEM))
  530. rip_redistribute_delete (rinfo->type,rinfo->sub_type,
  531. (struct prefix_ipv4 *)&rp->p,
  532. rinfo->ifindex);
  533. }
  534. }
  535. }
  536. ri = ifp->info;
  537. if (ri->running)
  538. {
  539. if (IS_RIP_DEBUG_EVENT)
  540. zlog_debug ("turn off %s", ifp->name);
  541. /* Leave from multicast group. */
  542. rip_multicast_leave (ifp, rip->sock);
  543. ri->running = 0;
  544. }
  545. return 0;
  546. }
  547. /* Needed for stop RIP process. */
  548. void
  549. rip_if_down_all ()
  550. {
  551. struct interface *ifp;
  552. struct listnode *node, *nnode;
  553. for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp))
  554. rip_if_down (ifp);
  555. }
  556. static void
  557. rip_apply_address_add (struct connected *ifc)
  558. {
  559. struct prefix_ipv4 address;
  560. struct prefix *p;
  561. if (!rip)
  562. return;
  563. if (! if_is_up(ifc->ifp))
  564. return;
  565. p = ifc->address;
  566. memset (&address, 0, sizeof (address));
  567. address.family = p->family;
  568. address.prefix = p->u.prefix4;
  569. address.prefixlen = p->prefixlen;
  570. apply_mask_ipv4(&address);
  571. /* Check if this interface is RIP enabled or not
  572. or Check if this address's prefix is RIP enabled */
  573. if ((rip_enable_if_lookup(ifc->ifp->name) >= 0) ||
  574. (rip_enable_network_lookup2(ifc) >= 0))
  575. rip_redistribute_add(ZEBRA_ROUTE_CONNECT, RIP_ROUTE_INTERFACE,
  576. &address, ifc->ifp->ifindex, NULL, 0, 0);
  577. }
  578. int
  579. rip_interface_address_add (int command, struct zclient *zclient,
  580. zebra_size_t length)
  581. {
  582. struct connected *ifc;
  583. struct prefix *p;
  584. ifc = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD,
  585. zclient->ibuf);
  586. if (ifc == NULL)
  587. return 0;
  588. p = ifc->address;
  589. if (p->family == AF_INET)
  590. {
  591. if (IS_RIP_DEBUG_ZEBRA)
  592. zlog_debug ("connected address %s/%d is added",
  593. inet_ntoa (p->u.prefix4), p->prefixlen);
  594. rip_enable_apply(ifc->ifp);
  595. /* Check if this prefix needs to be redistributed */
  596. rip_apply_address_add(ifc);
  597. #ifdef HAVE_SNMP
  598. rip_ifaddr_add (ifc->ifp, ifc);
  599. #endif /* HAVE_SNMP */
  600. }
  601. return 0;
  602. }
  603. static void
  604. rip_apply_address_del (struct connected *ifc) {
  605. struct prefix_ipv4 address;
  606. struct prefix *p;
  607. if (!rip)
  608. return;
  609. if (! if_is_up(ifc->ifp))
  610. return;
  611. p = ifc->address;
  612. memset (&address, 0, sizeof (address));
  613. address.family = p->family;
  614. address.prefix = p->u.prefix4;
  615. address.prefixlen = p->prefixlen;
  616. apply_mask_ipv4(&address);
  617. rip_redistribute_delete(ZEBRA_ROUTE_CONNECT, RIP_ROUTE_INTERFACE,
  618. &address, ifc->ifp->ifindex);
  619. }
  620. int
  621. rip_interface_address_delete (int command, struct zclient *zclient,
  622. zebra_size_t length)
  623. {
  624. struct connected *ifc;
  625. struct prefix *p;
  626. ifc = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE,
  627. zclient->ibuf);
  628. if (ifc)
  629. {
  630. p = ifc->address;
  631. if (p->family == AF_INET)
  632. {
  633. if (IS_RIP_DEBUG_ZEBRA)
  634. zlog_debug ("connected address %s/%d is deleted",
  635. inet_ntoa (p->u.prefix4), p->prefixlen);
  636. #ifdef HAVE_SNMP
  637. rip_ifaddr_delete (ifc->ifp, ifc);
  638. #endif /* HAVE_SNMP */
  639. /* Chech wether this prefix needs to be removed */
  640. rip_apply_address_del(ifc);
  641. }
  642. connected_free (ifc);
  643. }
  644. return 0;
  645. }
  646. /* Check interface is enabled by network statement. */
  647. /* Check wether the interface has at least a connected prefix that
  648. * is within the ripng_enable_network table. */
  649. static int
  650. rip_enable_network_lookup_if (struct interface *ifp)
  651. {
  652. struct listnode *node, *nnode;
  653. struct connected *connected;
  654. struct prefix_ipv4 address;
  655. for (ALL_LIST_ELEMENTS (ifp->connected, node, nnode, connected))
  656. {
  657. struct prefix *p;
  658. struct route_node *node;
  659. p = connected->address;
  660. if (p->family == AF_INET)
  661. {
  662. address.family = AF_INET;
  663. address.prefix = p->u.prefix4;
  664. address.prefixlen = IPV4_MAX_BITLEN;
  665. node = route_node_match (rip_enable_network,
  666. (struct prefix *)&address);
  667. if (node)
  668. {
  669. route_unlock_node (node);
  670. return 1;
  671. }
  672. }
  673. }
  674. return -1;
  675. }
  676. /* Check wether connected is within the ripng_enable_network table. */
  677. int
  678. rip_enable_network_lookup2 (struct connected *connected)
  679. {
  680. struct prefix_ipv4 address;
  681. struct prefix *p;
  682. p = connected->address;
  683. if (p->family == AF_INET) {
  684. struct route_node *node;
  685. address.family = p->family;
  686. address.prefix = p->u.prefix4;
  687. address.prefixlen = IPV4_MAX_BITLEN;
  688. /* LPM on p->family, p->u.prefix4/IPV4_MAX_BITLEN within rip_enable_network */
  689. node = route_node_match (rip_enable_network,
  690. (struct prefix *)&address);
  691. if (node) {
  692. route_unlock_node (node);
  693. return 1;
  694. }
  695. }
  696. return -1;
  697. }
  698. /* Add RIP enable network. */
  699. static int
  700. rip_enable_network_add (struct prefix *p)
  701. {
  702. struct route_node *node;
  703. node = route_node_get (rip_enable_network, p);
  704. if (node->info)
  705. {
  706. route_unlock_node (node);
  707. return -1;
  708. }
  709. else
  710. node->info = (char *) "enabled";
  711. /* XXX: One should find a better solution than a generic one */
  712. rip_enable_apply_all();
  713. return 1;
  714. }
  715. /* Delete RIP enable network. */
  716. static int
  717. rip_enable_network_delete (struct prefix *p)
  718. {
  719. struct route_node *node;
  720. node = route_node_lookup (rip_enable_network, p);
  721. if (node)
  722. {
  723. node->info = NULL;
  724. /* Unlock info lock. */
  725. route_unlock_node (node);
  726. /* Unlock lookup lock. */
  727. route_unlock_node (node);
  728. /* XXX: One should find a better solution than a generic one */
  729. rip_enable_apply_all ();
  730. return 1;
  731. }
  732. return -1;
  733. }
  734. /* Check interface is enabled by ifname statement. */
  735. static int
  736. rip_enable_if_lookup (const char *ifname)
  737. {
  738. unsigned int i;
  739. char *str;
  740. for (i = 0; i < vector_active (rip_enable_interface); i++)
  741. if ((str = vector_slot (rip_enable_interface, i)) != NULL)
  742. if (strcmp (str, ifname) == 0)
  743. return i;
  744. return -1;
  745. }
  746. /* Add interface to rip_enable_if. */
  747. static int
  748. rip_enable_if_add (const char *ifname)
  749. {
  750. int ret;
  751. ret = rip_enable_if_lookup (ifname);
  752. if (ret >= 0)
  753. return -1;
  754. vector_set (rip_enable_interface, strdup (ifname));
  755. rip_enable_apply_all(); /* TODOVJ */
  756. return 1;
  757. }
  758. /* Delete interface from rip_enable_if. */
  759. static int
  760. rip_enable_if_delete (const char *ifname)
  761. {
  762. int index;
  763. char *str;
  764. index = rip_enable_if_lookup (ifname);
  765. if (index < 0)
  766. return -1;
  767. str = vector_slot (rip_enable_interface, index);
  768. free (str);
  769. vector_unset (rip_enable_interface, index);
  770. rip_enable_apply_all(); /* TODOVJ */
  771. return 1;
  772. }
  773. /* Join to multicast group and send request to the interface. */
  774. static int
  775. rip_interface_wakeup (struct thread *t)
  776. {
  777. struct interface *ifp;
  778. struct rip_interface *ri;
  779. /* Get interface. */
  780. ifp = THREAD_ARG (t);
  781. ri = ifp->info;
  782. ri->t_wakeup = NULL;
  783. /* Join to multicast group. */
  784. if (rip_multicast_join (ifp, rip->sock) < 0)
  785. {
  786. zlog_err ("multicast join failed, interface %s not running", ifp->name);
  787. return 0;
  788. }
  789. /* Set running flag. */
  790. ri->running = 1;
  791. /* Send RIP request to the interface. */
  792. rip_request_interface (ifp);
  793. return 0;
  794. }
  795. int rip_redistribute_check (int);
  796. static void
  797. rip_connect_set (struct interface *ifp, int set)
  798. {
  799. struct listnode *node, *nnode;
  800. struct connected *connected;
  801. struct prefix_ipv4 address;
  802. for (ALL_LIST_ELEMENTS (ifp->connected, node, nnode, connected))
  803. {
  804. struct prefix *p;
  805. p = connected->address;
  806. if (p->family != AF_INET)
  807. continue;
  808. address.family = AF_INET;
  809. address.prefix = p->u.prefix4;
  810. address.prefixlen = p->prefixlen;
  811. apply_mask_ipv4 (&address);
  812. if (set) {
  813. /* Check once more wether this prefix is within a "network IF_OR_PREF" one */
  814. if ((rip_enable_if_lookup(connected->ifp->name) >= 0) ||
  815. (rip_enable_network_lookup2(connected) >= 0))
  816. rip_redistribute_add (ZEBRA_ROUTE_CONNECT, RIP_ROUTE_INTERFACE,
  817. &address, connected->ifp->ifindex,
  818. NULL, 0, 0);
  819. } else
  820. {
  821. rip_redistribute_delete (ZEBRA_ROUTE_CONNECT, RIP_ROUTE_INTERFACE,
  822. &address, connected->ifp->ifindex);
  823. if (rip_redistribute_check (ZEBRA_ROUTE_CONNECT))
  824. rip_redistribute_add (ZEBRA_ROUTE_CONNECT, RIP_ROUTE_REDISTRIBUTE,
  825. &address, connected->ifp->ifindex,
  826. NULL, 0, 0);
  827. }
  828. }
  829. }
  830. /* Update interface status. */
  831. void
  832. rip_enable_apply (struct interface *ifp)
  833. {
  834. int ret;
  835. struct rip_interface *ri = NULL;
  836. /* Check interface. */
  837. if (! if_is_operative (ifp))
  838. return;
  839. ri = ifp->info;
  840. /* Check network configuration. */
  841. ret = rip_enable_network_lookup_if (ifp);
  842. /* If the interface is matched. */
  843. if (ret > 0)
  844. ri->enable_network = 1;
  845. else
  846. ri->enable_network = 0;
  847. /* Check interface name configuration. */
  848. ret = rip_enable_if_lookup (ifp->name);
  849. if (ret >= 0)
  850. ri->enable_interface = 1;
  851. else
  852. ri->enable_interface = 0;
  853. /* any interface MUST have an IPv4 address */
  854. if ( ! rip_if_ipv4_address_check (ifp) )
  855. {
  856. ri->enable_network = 0;
  857. ri->enable_interface = 0;
  858. }
  859. /* Update running status of the interface. */
  860. if (ri->enable_network || ri->enable_interface)
  861. {
  862. {
  863. if (IS_RIP_DEBUG_EVENT)
  864. zlog_debug ("turn on %s", ifp->name);
  865. /* Add interface wake up thread. */
  866. if (! ri->t_wakeup)
  867. ri->t_wakeup = thread_add_timer (master, rip_interface_wakeup,
  868. ifp, 1);
  869. rip_connect_set (ifp, 1);
  870. }
  871. }
  872. else
  873. {
  874. if (ri->running)
  875. {
  876. /* Might as well clean up the route table as well
  877. * rip_if_down sets to 0 ri->running, and displays "turn off %s"
  878. **/
  879. rip_if_down(ifp);
  880. rip_connect_set (ifp, 0);
  881. }
  882. }
  883. }
  884. /* Apply network configuration to all interface. */
  885. void
  886. rip_enable_apply_all ()
  887. {
  888. struct interface *ifp;
  889. struct listnode *node, *nnode;
  890. /* Check each interface. */
  891. for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp))
  892. rip_enable_apply (ifp);
  893. }
  894. int
  895. rip_neighbor_lookup (struct sockaddr_in *from)
  896. {
  897. struct prefix_ipv4 p;
  898. struct route_node *node;
  899. memset (&p, 0, sizeof (struct prefix_ipv4));
  900. p.family = AF_INET;
  901. p.prefix = from->sin_addr;
  902. p.prefixlen = IPV4_MAX_BITLEN;
  903. node = route_node_lookup (rip->neighbor, (struct prefix *) &p);
  904. if (node)
  905. {
  906. route_unlock_node (node);
  907. return 1;
  908. }
  909. return 0;
  910. }
  911. /* Add new RIP neighbor to the neighbor tree. */
  912. static int
  913. rip_neighbor_add (struct prefix_ipv4 *p)
  914. {
  915. struct route_node *node;
  916. node = route_node_get (rip->neighbor, (struct prefix *) p);
  917. if (node->info)
  918. return -1;
  919. node->info = rip->neighbor;
  920. return 0;
  921. }
  922. /* Delete RIP neighbor from the neighbor tree. */
  923. static int
  924. rip_neighbor_delete (struct prefix_ipv4 *p)
  925. {
  926. struct route_node *node;
  927. /* Lock for look up. */
  928. node = route_node_lookup (rip->neighbor, (struct prefix *) p);
  929. if (! node)
  930. return -1;
  931. node->info = NULL;
  932. /* Unlock lookup lock. */
  933. route_unlock_node (node);
  934. /* Unlock real neighbor information lock. */
  935. route_unlock_node (node);
  936. return 0;
  937. }
  938. /* Clear all network and neighbor configuration. */
  939. void
  940. rip_clean_network ()
  941. {
  942. unsigned int i;
  943. char *str;
  944. struct route_node *rn;
  945. /* rip_enable_network. */
  946. for (rn = route_top (rip_enable_network); rn; rn = route_next (rn))
  947. if (rn->info)
  948. {
  949. rn->info = NULL;
  950. route_unlock_node (rn);
  951. }
  952. /* rip_enable_interface. */
  953. for (i = 0; i < vector_active (rip_enable_interface); i++)
  954. if ((str = vector_slot (rip_enable_interface, i)) != NULL)
  955. {
  956. free (str);
  957. vector_slot (rip_enable_interface, i) = NULL;
  958. }
  959. }
  960. /* Utility function for looking up passive interface settings. */
  961. static int
  962. rip_passive_nondefault_lookup (const char *ifname)
  963. {
  964. unsigned int i;
  965. char *str;
  966. for (i = 0; i < vector_active (Vrip_passive_nondefault); i++)
  967. if ((str = vector_slot (Vrip_passive_nondefault, i)) != NULL)
  968. if (strcmp (str, ifname) == 0)
  969. return i;
  970. return -1;
  971. }
  972. void
  973. rip_passive_interface_apply (struct interface *ifp)
  974. {
  975. struct rip_interface *ri;
  976. ri = ifp->info;
  977. ri->passive = ((rip_passive_nondefault_lookup (ifp->name) < 0) ?
  978. passive_default : !passive_default);
  979. if (IS_RIP_DEBUG_ZEBRA)
  980. zlog_debug ("interface %s: passive = %d",ifp->name,ri->passive);
  981. }
  982. static void
  983. rip_passive_interface_apply_all (void)
  984. {
  985. struct interface *ifp;
  986. struct listnode *node, *nnode;
  987. for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp))
  988. rip_passive_interface_apply (ifp);
  989. }
  990. /* Passive interface. */
  991. static int
  992. rip_passive_nondefault_set (struct vty *vty, const char *ifname)
  993. {
  994. if (rip_passive_nondefault_lookup (ifname) >= 0)
  995. return CMD_WARNING;
  996. vector_set (Vrip_passive_nondefault, strdup (ifname));
  997. rip_passive_interface_apply_all ();
  998. return CMD_SUCCESS;
  999. }
  1000. static int
  1001. rip_passive_nondefault_unset (struct vty *vty, const char *ifname)
  1002. {
  1003. int i;
  1004. char *str;
  1005. i = rip_passive_nondefault_lookup (ifname);
  1006. if (i < 0)
  1007. return CMD_WARNING;
  1008. str = vector_slot (Vrip_passive_nondefault, i);
  1009. free (str);
  1010. vector_unset (Vrip_passive_nondefault, i);
  1011. rip_passive_interface_apply_all ();
  1012. return CMD_SUCCESS;
  1013. }
  1014. /* Free all configured RIP passive-interface settings. */
  1015. void
  1016. rip_passive_nondefault_clean (void)
  1017. {
  1018. unsigned int i;
  1019. char *str;
  1020. for (i = 0; i < vector_active (Vrip_passive_nondefault); i++)
  1021. if ((str = vector_slot (Vrip_passive_nondefault, i)) != NULL)
  1022. {
  1023. free (str);
  1024. vector_slot (Vrip_passive_nondefault, i) = NULL;
  1025. }
  1026. rip_passive_interface_apply_all ();
  1027. }
  1028. /* RIP enable network or interface configuration. */
  1029. DEFUN (rip_network,
  1030. rip_network_cmd,
  1031. "network (A.B.C.D/M|WORD)",
  1032. "Enable routing on an IP network\n"
  1033. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1034. "Interface name\n")
  1035. {
  1036. int ret;
  1037. struct prefix_ipv4 p;
  1038. ret = str2prefix_ipv4 (argv[0], &p);
  1039. if (ret)
  1040. ret = rip_enable_network_add ((struct prefix *) &p);
  1041. else
  1042. ret = rip_enable_if_add (argv[0]);
  1043. if (ret < 0)
  1044. {
  1045. vty_out (vty, "There is a same network configuration %s%s", argv[0],
  1046. VTY_NEWLINE);
  1047. return CMD_WARNING;
  1048. }
  1049. return CMD_SUCCESS;
  1050. }
  1051. /* RIP enable network or interface configuration. */
  1052. DEFUN (no_rip_network,
  1053. no_rip_network_cmd,
  1054. "no network (A.B.C.D/M|WORD)",
  1055. NO_STR
  1056. "Enable routing on an IP network\n"
  1057. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  1058. "Interface name\n")
  1059. {
  1060. int ret;
  1061. struct prefix_ipv4 p;
  1062. ret = str2prefix_ipv4 (argv[0], &p);
  1063. if (ret)
  1064. ret = rip_enable_network_delete ((struct prefix *) &p);
  1065. else
  1066. ret = rip_enable_if_delete (argv[0]);
  1067. if (ret < 0)
  1068. {
  1069. vty_out (vty, "Can't find network configuration %s%s", argv[0],
  1070. VTY_NEWLINE);
  1071. return CMD_WARNING;
  1072. }
  1073. return CMD_SUCCESS;
  1074. }
  1075. /* RIP neighbor configuration set. */
  1076. DEFUN (rip_neighbor,
  1077. rip_neighbor_cmd,
  1078. "neighbor A.B.C.D",
  1079. "Specify a neighbor router\n"
  1080. "Neighbor address\n")
  1081. {
  1082. int ret;
  1083. struct prefix_ipv4 p;
  1084. ret = str2prefix_ipv4 (argv[0], &p);
  1085. if (ret <= 0)
  1086. {
  1087. vty_out (vty, "Please specify address by A.B.C.D%s", VTY_NEWLINE);
  1088. return CMD_WARNING;
  1089. }
  1090. rip_neighbor_add (&p);
  1091. return CMD_SUCCESS;
  1092. }
  1093. /* RIP neighbor configuration unset. */
  1094. DEFUN (no_rip_neighbor,
  1095. no_rip_neighbor_cmd,
  1096. "no neighbor A.B.C.D",
  1097. NO_STR
  1098. "Specify a neighbor router\n"
  1099. "Neighbor address\n")
  1100. {
  1101. int ret;
  1102. struct prefix_ipv4 p;
  1103. ret = str2prefix_ipv4 (argv[0], &p);
  1104. if (ret <= 0)
  1105. {
  1106. vty_out (vty, "Please specify address by A.B.C.D%s", VTY_NEWLINE);
  1107. return CMD_WARNING;
  1108. }
  1109. rip_neighbor_delete (&p);
  1110. return CMD_SUCCESS;
  1111. }
  1112. DEFUN (ip_rip_receive_version,
  1113. ip_rip_receive_version_cmd,
  1114. "ip rip receive version (1|2)",
  1115. IP_STR
  1116. "Routing Information Protocol\n"
  1117. "Advertisement reception\n"
  1118. "Version control\n"
  1119. "RIP version 1\n"
  1120. "RIP version 2\n")
  1121. {
  1122. struct interface *ifp;
  1123. struct rip_interface *ri;
  1124. ifp = (struct interface *)vty->index;
  1125. ri = ifp->info;
  1126. /* Version 1. */
  1127. if (atoi (argv[0]) == 1)
  1128. {
  1129. ri->ri_receive = RI_RIP_VERSION_1;
  1130. return CMD_SUCCESS;
  1131. }
  1132. if (atoi (argv[0]) == 2)
  1133. {
  1134. ri->ri_receive = RI_RIP_VERSION_2;
  1135. return CMD_SUCCESS;
  1136. }
  1137. return CMD_WARNING;
  1138. }
  1139. DEFUN (ip_rip_receive_version_1,
  1140. ip_rip_receive_version_1_cmd,
  1141. "ip rip receive version 1 2",
  1142. IP_STR
  1143. "Routing Information Protocol\n"
  1144. "Advertisement reception\n"
  1145. "Version control\n"
  1146. "RIP version 1\n"
  1147. "RIP version 2\n")
  1148. {
  1149. struct interface *ifp;
  1150. struct rip_interface *ri;
  1151. ifp = (struct interface *)vty->index;
  1152. ri = ifp->info;
  1153. /* Version 1 and 2. */
  1154. ri->ri_receive = RI_RIP_VERSION_1_AND_2;
  1155. return CMD_SUCCESS;
  1156. }
  1157. DEFUN (ip_rip_receive_version_2,
  1158. ip_rip_receive_version_2_cmd,
  1159. "ip rip receive version 2 1",
  1160. IP_STR
  1161. "Routing Information Protocol\n"
  1162. "Advertisement reception\n"
  1163. "Version control\n"
  1164. "RIP version 2\n"
  1165. "RIP version 1\n")
  1166. {
  1167. struct interface *ifp;
  1168. struct rip_interface *ri;
  1169. ifp = (struct interface *)vty->index;
  1170. ri = ifp->info;
  1171. /* Version 1 and 2. */
  1172. ri->ri_receive = RI_RIP_VERSION_1_AND_2;
  1173. return CMD_SUCCESS;
  1174. }
  1175. DEFUN (no_ip_rip_receive_version,
  1176. no_ip_rip_receive_version_cmd,
  1177. "no ip rip receive version",
  1178. NO_STR
  1179. IP_STR
  1180. "Routing Information Protocol\n"
  1181. "Advertisement reception\n"
  1182. "Version control\n")
  1183. {
  1184. struct interface *ifp;
  1185. struct rip_interface *ri;
  1186. ifp = (struct interface *)vty->index;
  1187. ri = ifp->info;
  1188. ri->ri_receive = RI_RIP_UNSPEC;
  1189. return CMD_SUCCESS;
  1190. }
  1191. ALIAS (no_ip_rip_receive_version,
  1192. no_ip_rip_receive_version_num_cmd,
  1193. "no ip rip receive version (1|2)",
  1194. NO_STR
  1195. IP_STR
  1196. "Routing Information Protocol\n"
  1197. "Advertisement reception\n"
  1198. "Version control\n"
  1199. "Version 1\n"
  1200. "Version 2\n")
  1201. DEFUN (ip_rip_send_version,
  1202. ip_rip_send_version_cmd,
  1203. "ip rip send version (1|2)",
  1204. IP_STR
  1205. "Routing Information Protocol\n"
  1206. "Advertisement transmission\n"
  1207. "Version control\n"
  1208. "RIP version 1\n"
  1209. "RIP version 2\n")
  1210. {
  1211. struct interface *ifp;
  1212. struct rip_interface *ri;
  1213. ifp = (struct interface *)vty->index;
  1214. ri = ifp->info;
  1215. /* Version 1. */
  1216. if (atoi (argv[0]) == 1)
  1217. {
  1218. ri->ri_send = RI_RIP_VERSION_1;
  1219. return CMD_SUCCESS;
  1220. }
  1221. if (atoi (argv[0]) == 2)
  1222. {
  1223. ri->ri_send = RI_RIP_VERSION_2;
  1224. return CMD_SUCCESS;
  1225. }
  1226. return CMD_WARNING;
  1227. }
  1228. DEFUN (ip_rip_send_version_1,
  1229. ip_rip_send_version_1_cmd,
  1230. "ip rip send version 1 2",
  1231. IP_STR
  1232. "Routing Information Protocol\n"
  1233. "Advertisement transmission\n"
  1234. "Version control\n"
  1235. "RIP version 1\n"
  1236. "RIP version 2\n")
  1237. {
  1238. struct interface *ifp;
  1239. struct rip_interface *ri;
  1240. ifp = (struct interface *)vty->index;
  1241. ri = ifp->info;
  1242. /* Version 1 and 2. */
  1243. ri->ri_send = RI_RIP_VERSION_1_AND_2;
  1244. return CMD_SUCCESS;
  1245. }
  1246. DEFUN (ip_rip_send_version_2,
  1247. ip_rip_send_version_2_cmd,
  1248. "ip rip send version 2 1",
  1249. IP_STR
  1250. "Routing Information Protocol\n"
  1251. "Advertisement transmission\n"
  1252. "Version control\n"
  1253. "RIP version 2\n"
  1254. "RIP version 1\n")
  1255. {
  1256. struct interface *ifp;
  1257. struct rip_interface *ri;
  1258. ifp = (struct interface *)vty->index;
  1259. ri = ifp->info;
  1260. /* Version 1 and 2. */
  1261. ri->ri_send = RI_RIP_VERSION_1_AND_2;
  1262. return CMD_SUCCESS;
  1263. }
  1264. DEFUN (no_ip_rip_send_version,
  1265. no_ip_rip_send_version_cmd,
  1266. "no ip rip send version",
  1267. NO_STR
  1268. IP_STR
  1269. "Routing Information Protocol\n"
  1270. "Advertisement transmission\n"
  1271. "Version control\n")
  1272. {
  1273. struct interface *ifp;
  1274. struct rip_interface *ri;
  1275. ifp = (struct interface *)vty->index;
  1276. ri = ifp->info;
  1277. ri->ri_send = RI_RIP_UNSPEC;
  1278. return CMD_SUCCESS;
  1279. }
  1280. ALIAS (no_ip_rip_send_version,
  1281. no_ip_rip_send_version_num_cmd,
  1282. "no ip rip send version (1|2)",
  1283. NO_STR
  1284. IP_STR
  1285. "Routing Information Protocol\n"
  1286. "Advertisement transmission\n"
  1287. "Version control\n"
  1288. "Version 1\n"
  1289. "Version 2\n")
  1290. DEFUN (ip_rip_authentication_mode,
  1291. ip_rip_authentication_mode_cmd,
  1292. "ip rip authentication mode (md5|text)",
  1293. IP_STR
  1294. "Routing Information Protocol\n"
  1295. "Authentication control\n"
  1296. "Authentication mode\n"
  1297. "Keyed message digest\n"
  1298. "Clear text authentication\n")
  1299. {
  1300. struct interface *ifp;
  1301. struct rip_interface *ri;
  1302. ifp = (struct interface *)vty->index;
  1303. ri = ifp->info;
  1304. if ( (argc < 1) || (argc > 2) )
  1305. {
  1306. vty_out (vty, "incorrect argument count%s", VTY_NEWLINE);
  1307. return CMD_WARNING;
  1308. }
  1309. if (strncmp ("md5", argv[0], strlen (argv[0])) == 0)
  1310. ri->auth_type = RIP_AUTH_MD5;
  1311. else if (strncmp ("text", argv[0], strlen (argv[0])) == 0)
  1312. ri->auth_type = RIP_AUTH_SIMPLE_PASSWORD;
  1313. else
  1314. {
  1315. vty_out (vty, "mode should be md5 or text%s", VTY_NEWLINE);
  1316. return CMD_WARNING;
  1317. }
  1318. if (argc == 1)
  1319. return CMD_SUCCESS;
  1320. if ( (argc == 2) && (ri->auth_type != RIP_AUTH_MD5) )
  1321. {
  1322. vty_out (vty, "auth length argument only valid for md5%s", VTY_NEWLINE);
  1323. return CMD_WARNING;
  1324. }
  1325. if (strncmp ("r", argv[1], 1) == 0)
  1326. ri->md5_auth_len = RIP_AUTH_MD5_SIZE;
  1327. else if (strncmp ("o", argv[1], 1) == 0)
  1328. ri->md5_auth_len = RIP_AUTH_MD5_COMPAT_SIZE;
  1329. else
  1330. return CMD_WARNING;
  1331. return CMD_SUCCESS;
  1332. }
  1333. ALIAS (ip_rip_authentication_mode,
  1334. ip_rip_authentication_mode_authlen_cmd,
  1335. "ip rip authentication mode (md5|text) auth-length (rfc|old-ripd)",
  1336. IP_STR
  1337. "Routing Information Protocol\n"
  1338. "Authentication control\n"
  1339. "Authentication mode\n"
  1340. "Keyed message digest\n"
  1341. "Clear text authentication\n"
  1342. "MD5 authentication data length\n"
  1343. "RFC compatible\n"
  1344. "Old ripd compatible\n")
  1345. DEFUN (no_ip_rip_authentication_mode,
  1346. no_ip_rip_authentication_mode_cmd,
  1347. "no ip rip authentication mode",
  1348. NO_STR
  1349. IP_STR
  1350. "Routing Information Protocol\n"
  1351. "Authentication control\n"
  1352. "Authentication mode\n")
  1353. {
  1354. struct interface *ifp;
  1355. struct rip_interface *ri;
  1356. ifp = (struct interface *)vty->index;
  1357. ri = ifp->info;
  1358. ri->auth_type = RIP_NO_AUTH;
  1359. ri->md5_auth_len = RIP_AUTH_MD5_COMPAT_SIZE;
  1360. return CMD_SUCCESS;
  1361. }
  1362. ALIAS (no_ip_rip_authentication_mode,
  1363. no_ip_rip_authentication_mode_type_cmd,
  1364. "no ip rip authentication mode (md5|text)",
  1365. NO_STR
  1366. IP_STR
  1367. "Routing Information Protocol\n"
  1368. "Authentication control\n"
  1369. "Authentication mode\n"
  1370. "Keyed message digest\n"
  1371. "Clear text authentication\n")
  1372. ALIAS (no_ip_rip_authentication_mode,
  1373. no_ip_rip_authentication_mode_type_authlen_cmd,
  1374. "no ip rip authentication mode (md5|text) auth-length (rfc|old-ripd)",
  1375. NO_STR
  1376. IP_STR
  1377. "Routing Information Protocol\n"
  1378. "Authentication control\n"
  1379. "Authentication mode\n"
  1380. "Keyed message digest\n"
  1381. "Clear text authentication\n"
  1382. "MD5 authentication data length\n"
  1383. "RFC compatible\n"
  1384. "Old ripd compatible\n")
  1385. DEFUN (ip_rip_authentication_string,
  1386. ip_rip_authentication_string_cmd,
  1387. "ip rip authentication string LINE",
  1388. IP_STR
  1389. "Routing Information Protocol\n"
  1390. "Authentication control\n"
  1391. "Authentication string\n"
  1392. "Authentication string\n")
  1393. {
  1394. struct interface *ifp;
  1395. struct rip_interface *ri;
  1396. ifp = (struct interface *)vty->index;
  1397. ri = ifp->info;
  1398. if (strlen (argv[0]) > 16)
  1399. {
  1400. vty_out (vty, "%% RIPv2 authentication string must be shorter than 16%s",
  1401. VTY_NEWLINE);
  1402. return CMD_WARNING;
  1403. }
  1404. if (ri->key_chain)
  1405. {
  1406. vty_out (vty, "%% key-chain configuration exists%s", VTY_NEWLINE);
  1407. return CMD_WARNING;
  1408. }
  1409. if (ri->auth_str)
  1410. free (ri->auth_str);
  1411. ri->auth_str = strdup (argv[0]);
  1412. return CMD_SUCCESS;
  1413. }
  1414. DEFUN (no_ip_rip_authentication_string,
  1415. no_ip_rip_authentication_string_cmd,
  1416. "no ip rip authentication string",
  1417. NO_STR
  1418. IP_STR
  1419. "Routing Information Protocol\n"
  1420. "Authentication control\n"
  1421. "Authentication string\n")
  1422. {
  1423. struct interface *ifp;
  1424. struct rip_interface *ri;
  1425. ifp = (struct interface *)vty->index;
  1426. ri = ifp->info;
  1427. if (ri->auth_str)
  1428. free (ri->auth_str);
  1429. ri->auth_str = NULL;
  1430. return CMD_SUCCESS;
  1431. }
  1432. ALIAS (no_ip_rip_authentication_string,
  1433. no_ip_rip_authentication_string2_cmd,
  1434. "no ip rip authentication string LINE",
  1435. NO_STR
  1436. IP_STR
  1437. "Routing Information Protocol\n"
  1438. "Authentication control\n"
  1439. "Authentication string\n"
  1440. "Authentication string\n")
  1441. DEFUN (ip_rip_authentication_key_chain,
  1442. ip_rip_authentication_key_chain_cmd,
  1443. "ip rip authentication key-chain LINE",
  1444. IP_STR
  1445. "Routing Information Protocol\n"
  1446. "Authentication control\n"
  1447. "Authentication key-chain\n"
  1448. "name of key-chain\n")
  1449. {
  1450. struct interface *ifp;
  1451. struct rip_interface *ri;
  1452. ifp = (struct interface *) vty->index;
  1453. ri = ifp->info;
  1454. if (ri->auth_str)
  1455. {
  1456. vty_out (vty, "%% authentication string configuration exists%s",
  1457. VTY_NEWLINE);
  1458. return CMD_WARNING;
  1459. }
  1460. if (ri->key_chain)
  1461. free (ri->key_chain);
  1462. ri->key_chain = strdup (argv[0]);
  1463. return CMD_SUCCESS;
  1464. }
  1465. DEFUN (no_ip_rip_authentication_key_chain,
  1466. no_ip_rip_authentication_key_chain_cmd,
  1467. "no ip rip authentication key-chain",
  1468. NO_STR
  1469. IP_STR
  1470. "Routing Information Protocol\n"
  1471. "Authentication control\n"
  1472. "Authentication key-chain\n")
  1473. {
  1474. struct interface *ifp;
  1475. struct rip_interface *ri;
  1476. ifp = (struct interface *) vty->index;
  1477. ri = ifp->info;
  1478. if (ri->key_chain)
  1479. free (ri->key_chain);
  1480. ri->key_chain = NULL;
  1481. return CMD_SUCCESS;
  1482. }
  1483. ALIAS (no_ip_rip_authentication_key_chain,
  1484. no_ip_rip_authentication_key_chain2_cmd,
  1485. "no ip rip authentication key-chain LINE",
  1486. NO_STR
  1487. IP_STR
  1488. "Routing Information Protocol\n"
  1489. "Authentication control\n"
  1490. "Authentication key-chain\n"
  1491. "name of key-chain\n")
  1492. /* CHANGED: ip rip split-horizon
  1493. Cisco and Zebra's command is
  1494. ip split-horizon
  1495. */
  1496. DEFUN (ip_rip_split_horizon,
  1497. ip_rip_split_horizon_cmd,
  1498. "ip rip split-horizon",
  1499. IP_STR
  1500. "Routing Information Protocol\n"
  1501. "Perform split horizon\n")
  1502. {
  1503. struct interface *ifp;
  1504. struct rip_interface *ri;
  1505. ifp = vty->index;
  1506. ri = ifp->info;
  1507. ri->split_horizon = RIP_SPLIT_HORIZON;
  1508. return CMD_SUCCESS;
  1509. }
  1510. DEFUN (ip_rip_split_horizon_poisoned_reverse,
  1511. ip_rip_split_horizon_poisoned_reverse_cmd,
  1512. "ip rip split-horizon poisoned-reverse",
  1513. IP_STR
  1514. "Routing Information Protocol\n"
  1515. "Perform split horizon\n"
  1516. "With poisoned-reverse\n")
  1517. {
  1518. struct interface *ifp;
  1519. struct rip_interface *ri;
  1520. ifp = vty->index;
  1521. ri = ifp->info;
  1522. ri->split_horizon = RIP_SPLIT_HORIZON_POISONED_REVERSE;
  1523. return CMD_SUCCESS;
  1524. }
  1525. /* CHANGED: no ip rip split-horizon
  1526. Cisco and Zebra's command is
  1527. no ip split-horizon
  1528. */
  1529. DEFUN (no_ip_rip_split_horizon,
  1530. no_ip_rip_split_horizon_cmd,
  1531. "no ip rip split-horizon",
  1532. NO_STR
  1533. IP_STR
  1534. "Routing Information Protocol\n"
  1535. "Perform split horizon\n")
  1536. {
  1537. struct interface *ifp;
  1538. struct rip_interface *ri;
  1539. ifp = vty->index;
  1540. ri = ifp->info;
  1541. ri->split_horizon = RIP_NO_SPLIT_HORIZON;
  1542. return CMD_SUCCESS;
  1543. }
  1544. DEFUN (no_ip_rip_split_horizon_poisoned_reverse,
  1545. no_ip_rip_split_horizon_poisoned_reverse_cmd,
  1546. "no ip rip split-horizon poisoned-reverse",
  1547. NO_STR
  1548. IP_STR
  1549. "Routing Information Protocol\n"
  1550. "Perform split horizon\n"
  1551. "With poisoned-reverse\n")
  1552. {
  1553. struct interface *ifp;
  1554. struct rip_interface *ri;
  1555. ifp = vty->index;
  1556. ri = ifp->info;
  1557. switch( ri->split_horizon )
  1558. {
  1559. case RIP_SPLIT_HORIZON_POISONED_REVERSE:
  1560. ri->split_horizon = RIP_SPLIT_HORIZON;
  1561. default:
  1562. break;
  1563. }
  1564. return CMD_SUCCESS;
  1565. }
  1566. DEFUN (rip_passive_interface,
  1567. rip_passive_interface_cmd,
  1568. "passive-interface (IFNAME|default)",
  1569. "Suppress routing updates on an interface\n"
  1570. "Interface name\n"
  1571. "default for all interfaces\n")
  1572. {
  1573. const char *ifname = argv[0];
  1574. if (!strcmp(ifname,"default")) {
  1575. passive_default = 1;
  1576. rip_passive_nondefault_clean();
  1577. return CMD_SUCCESS;
  1578. }
  1579. if (passive_default)
  1580. return rip_passive_nondefault_unset (vty, ifname);
  1581. else
  1582. return rip_passive_nondefault_set (vty, ifname);
  1583. }
  1584. DEFUN (no_rip_passive_interface,
  1585. no_rip_passive_interface_cmd,
  1586. "no passive-interface (IFNAME|default)",
  1587. NO_STR
  1588. "Suppress routing updates on an interface\n"
  1589. "Interface name\n"
  1590. "default for all interfaces\n")
  1591. {
  1592. const char *ifname = argv[0];
  1593. if (!strcmp(ifname,"default")) {
  1594. passive_default = 0;
  1595. rip_passive_nondefault_clean();
  1596. return CMD_SUCCESS;
  1597. }
  1598. if (passive_default)
  1599. return rip_passive_nondefault_set (vty, ifname);
  1600. else
  1601. return rip_passive_nondefault_unset (vty, ifname);
  1602. }
  1603. /* Write rip configuration of each interface. */
  1604. static int
  1605. rip_interface_config_write (struct vty *vty)
  1606. {
  1607. struct listnode *node;
  1608. struct interface *ifp;
  1609. for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
  1610. {
  1611. struct rip_interface *ri;
  1612. ri = ifp->info;
  1613. /* Do not display the interface if there is no
  1614. * configuration about it.
  1615. **/
  1616. if ((!ifp->desc) &&
  1617. (ri->split_horizon == ri->split_horizon_default) &&
  1618. (ri->ri_send == RI_RIP_UNSPEC) &&
  1619. (ri->ri_receive == RI_RIP_UNSPEC) &&
  1620. (ri->auth_type != RIP_AUTH_MD5) &&
  1621. (ri->md5_auth_len != RIP_AUTH_MD5_SIZE) &&
  1622. (!ri->auth_str) &&
  1623. (!ri->key_chain) )
  1624. continue;
  1625. vty_out (vty, "interface %s%s", ifp->name,
  1626. VTY_NEWLINE);
  1627. if (ifp->desc)
  1628. vty_out (vty, " description %s%s", ifp->desc,
  1629. VTY_NEWLINE);
  1630. /* Split horizon. */
  1631. if (ri->split_horizon != ri->split_horizon_default)
  1632. {
  1633. switch (ri->split_horizon) {
  1634. case RIP_SPLIT_HORIZON:
  1635. vty_out (vty, " ip rip split-horizon%s", VTY_NEWLINE);
  1636. break;
  1637. case RIP_SPLIT_HORIZON_POISONED_REVERSE:
  1638. vty_out (vty, " ip rip split-horizon poisoned-reverse%s",
  1639. VTY_NEWLINE);
  1640. break;
  1641. case RIP_NO_SPLIT_HORIZON:
  1642. default:
  1643. vty_out (vty, " no ip rip split-horizon%s", VTY_NEWLINE);
  1644. break;
  1645. }
  1646. }
  1647. /* RIP version setting. */
  1648. if (ri->ri_send != RI_RIP_UNSPEC)
  1649. vty_out (vty, " ip rip send version %s%s",
  1650. lookup (ri_version_msg, ri->ri_send),
  1651. VTY_NEWLINE);
  1652. if (ri->ri_receive != RI_RIP_UNSPEC)
  1653. vty_out (vty, " ip rip receive version %s%s",
  1654. lookup (ri_version_msg, ri->ri_receive),
  1655. VTY_NEWLINE);
  1656. /* RIP authentication. */
  1657. if (ri->auth_type == RIP_AUTH_SIMPLE_PASSWORD)
  1658. vty_out (vty, " ip rip authentication mode text%s", VTY_NEWLINE);
  1659. if (ri->auth_type == RIP_AUTH_MD5)
  1660. {
  1661. vty_out (vty, " ip rip authentication mode md5");
  1662. if (ri->md5_auth_len == RIP_AUTH_MD5_COMPAT_SIZE)
  1663. vty_out (vty, " auth-length old-ripd");
  1664. else
  1665. vty_out (vty, " auth-length rfc");
  1666. vty_out (vty, "%s", VTY_NEWLINE);
  1667. }
  1668. if (ri->auth_str)
  1669. vty_out (vty, " ip rip authentication string %s%s",
  1670. ri->auth_str, VTY_NEWLINE);
  1671. if (ri->key_chain)
  1672. vty_out (vty, " ip rip authentication key-chain %s%s",
  1673. ri->key_chain, VTY_NEWLINE);
  1674. vty_out (vty, "!%s", VTY_NEWLINE);
  1675. }
  1676. return 0;
  1677. }
  1678. int
  1679. config_write_rip_network (struct vty *vty, int config_mode)
  1680. {
  1681. unsigned int i;
  1682. char *ifname;
  1683. struct route_node *node;
  1684. /* Network type RIP enable interface statement. */
  1685. for (node = route_top (rip_enable_network); node; node = route_next (node))
  1686. if (node->info)
  1687. vty_out (vty, "%s%s/%d%s",
  1688. config_mode ? " network " : " ",
  1689. inet_ntoa (node->p.u.prefix4),
  1690. node->p.prefixlen,
  1691. VTY_NEWLINE);
  1692. /* Interface name RIP enable statement. */
  1693. for (i = 0; i < vector_active (rip_enable_interface); i++)
  1694. if ((ifname = vector_slot (rip_enable_interface, i)) != NULL)
  1695. vty_out (vty, "%s%s%s",
  1696. config_mode ? " network " : " ",
  1697. ifname,
  1698. VTY_NEWLINE);
  1699. /* RIP neighbors listing. */
  1700. for (node = route_top (rip->neighbor); node; node = route_next (node))
  1701. if (node->info)
  1702. vty_out (vty, "%s%s%s",
  1703. config_mode ? " neighbor " : " ",
  1704. inet_ntoa (node->p.u.prefix4),
  1705. VTY_NEWLINE);
  1706. /* RIP passive interface listing. */
  1707. if (config_mode) {
  1708. if (passive_default)
  1709. vty_out (vty, " passive-interface default%s", VTY_NEWLINE);
  1710. for (i = 0; i < vector_active (Vrip_passive_nondefault); i++)
  1711. if ((ifname = vector_slot (Vrip_passive_nondefault, i)) != NULL)
  1712. vty_out (vty, " %spassive-interface %s%s",
  1713. (passive_default ? "no " : ""), ifname, VTY_NEWLINE);
  1714. }
  1715. return 0;
  1716. }
  1717. struct cmd_node interface_node =
  1718. {
  1719. INTERFACE_NODE,
  1720. "%s(config-if)# ",
  1721. 1,
  1722. };
  1723. /* Called when interface structure allocated. */
  1724. static int
  1725. rip_interface_new_hook (struct interface *ifp)
  1726. {
  1727. ifp->info = rip_interface_new ();
  1728. return 0;
  1729. }
  1730. /* Called when interface structure deleted. */
  1731. static int
  1732. rip_interface_delete_hook (struct interface *ifp)
  1733. {
  1734. XFREE (MTYPE_RIP_INTERFACE, ifp->info);
  1735. ifp->info = NULL;
  1736. return 0;
  1737. }
  1738. /* Allocate and initialize interface vector. */
  1739. void
  1740. rip_if_init (void)
  1741. {
  1742. /* Default initial size of interface vector. */
  1743. if_init();
  1744. if_add_hook (IF_NEW_HOOK, rip_interface_new_hook);
  1745. if_add_hook (IF_DELETE_HOOK, rip_interface_delete_hook);
  1746. /* RIP network init. */
  1747. rip_enable_interface = vector_init (1);
  1748. rip_enable_network = route_table_init ();
  1749. /* RIP passive interface. */
  1750. Vrip_passive_nondefault = vector_init (1);
  1751. /* Install interface node. */
  1752. install_node (&interface_node, rip_interface_config_write);
  1753. /* Install commands. */
  1754. install_element (CONFIG_NODE, &interface_cmd);
  1755. install_element (CONFIG_NODE, &no_interface_cmd);
  1756. install_default (INTERFACE_NODE);
  1757. install_element (INTERFACE_NODE, &interface_desc_cmd);
  1758. install_element (INTERFACE_NODE, &no_interface_desc_cmd);
  1759. install_element (RIP_NODE, &rip_network_cmd);
  1760. install_element (RIP_NODE, &no_rip_network_cmd);
  1761. install_element (RIP_NODE, &rip_neighbor_cmd);
  1762. install_element (RIP_NODE, &no_rip_neighbor_cmd);
  1763. install_element (RIP_NODE, &rip_passive_interface_cmd);
  1764. install_element (RIP_NODE, &no_rip_passive_interface_cmd);
  1765. install_element (INTERFACE_NODE, &ip_rip_send_version_cmd);
  1766. install_element (INTERFACE_NODE, &ip_rip_send_version_1_cmd);
  1767. install_element (INTERFACE_NODE, &ip_rip_send_version_2_cmd);
  1768. install_element (INTERFACE_NODE, &no_ip_rip_send_version_cmd);
  1769. install_element (INTERFACE_NODE, &no_ip_rip_send_version_num_cmd);
  1770. install_element (INTERFACE_NODE, &ip_rip_receive_version_cmd);
  1771. install_element (INTERFACE_NODE, &ip_rip_receive_version_1_cmd);
  1772. install_element (INTERFACE_NODE, &ip_rip_receive_version_2_cmd);
  1773. install_element (INTERFACE_NODE, &no_ip_rip_receive_version_cmd);
  1774. install_element (INTERFACE_NODE, &no_ip_rip_receive_version_num_cmd);
  1775. install_element (INTERFACE_NODE, &ip_rip_authentication_mode_cmd);
  1776. install_element (INTERFACE_NODE, &ip_rip_authentication_mode_authlen_cmd);
  1777. install_element (INTERFACE_NODE, &no_ip_rip_authentication_mode_cmd);
  1778. install_element (INTERFACE_NODE, &no_ip_rip_authentication_mode_type_cmd);
  1779. install_element (INTERFACE_NODE, &no_ip_rip_authentication_mode_type_authlen_cmd);
  1780. install_element (INTERFACE_NODE, &ip_rip_authentication_key_chain_cmd);
  1781. install_element (INTERFACE_NODE, &no_ip_rip_authentication_key_chain_cmd);
  1782. install_element (INTERFACE_NODE, &no_ip_rip_authentication_key_chain2_cmd);
  1783. install_element (INTERFACE_NODE, &ip_rip_authentication_string_cmd);
  1784. install_element (INTERFACE_NODE, &no_ip_rip_authentication_string_cmd);
  1785. install_element (INTERFACE_NODE, &no_ip_rip_authentication_string2_cmd);
  1786. install_element (INTERFACE_NODE, &ip_rip_split_horizon_cmd);
  1787. install_element (INTERFACE_NODE, &ip_rip_split_horizon_poisoned_reverse_cmd);
  1788. install_element (INTERFACE_NODE, &no_ip_rip_split_horizon_cmd);
  1789. install_element (INTERFACE_NODE, &no_ip_rip_split_horizon_poisoned_reverse_cmd);
  1790. }