rip_interface.c 52 KB

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