ospf_interface.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261
  1. /*
  2. * OSPF Interface functions.
  3. * Copyright (C) 1999, 2000 Toshiaki Takada
  4. *
  5. * This file is part of GNU Zebra.
  6. *
  7. * GNU Zebra is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published
  9. * by the Free Software Foundation; either version 2, or (at your
  10. * option) any later version.
  11. *
  12. * GNU Zebra is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with GNU Zebra; see the file COPYING. If not, write to the
  19. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  20. * Boston, MA 02111-1307, USA.
  21. */
  22. #include <zebra.h>
  23. #include "thread.h"
  24. #include "linklist.h"
  25. #include "prefix.h"
  26. #include "if.h"
  27. #include "table.h"
  28. #include "memory.h"
  29. #include "command.h"
  30. #include "stream.h"
  31. #include "log.h"
  32. #include "ospfd/ospfd.h"
  33. #include "ospfd/ospf_spf.h"
  34. #include "ospfd/ospf_interface.h"
  35. #include "ospfd/ospf_ism.h"
  36. #include "ospfd/ospf_asbr.h"
  37. #include "ospfd/ospf_lsa.h"
  38. #include "ospfd/ospf_lsdb.h"
  39. #include "ospfd/ospf_neighbor.h"
  40. #include "ospfd/ospf_nsm.h"
  41. #include "ospfd/ospf_packet.h"
  42. #include "ospfd/ospf_abr.h"
  43. #include "ospfd/ospf_network.h"
  44. #include "ospfd/ospf_dump.h"
  45. #ifdef HAVE_SNMP
  46. #include "ospfd/ospf_snmp.h"
  47. #endif /* HAVE_SNMP */
  48. int
  49. ospf_if_get_output_cost (struct ospf_interface *oi)
  50. {
  51. /* If all else fails, use default OSPF cost */
  52. u_int32_t cost;
  53. u_int32_t bw, refbw;
  54. bw = oi->ifp->bandwidth ? oi->ifp->bandwidth : OSPF_DEFAULT_BANDWIDTH;
  55. refbw = oi->ospf->ref_bandwidth;
  56. /* A specifed ip ospf cost overrides a calculated one. */
  57. if (OSPF_IF_PARAM_CONFIGURED (IF_DEF_PARAMS (oi->ifp), output_cost_cmd) ||
  58. OSPF_IF_PARAM_CONFIGURED (oi->params, output_cost_cmd))
  59. cost = OSPF_IF_PARAM (oi, output_cost_cmd);
  60. /* See if a cost can be calculated from the zebra processes
  61. interface bandwidth field. */
  62. else
  63. {
  64. cost = (u_int32_t) ((double)refbw / (double)bw + (double)0.5);
  65. if (cost < 1)
  66. cost = 1;
  67. else if (cost > 65535)
  68. cost = 65535;
  69. }
  70. return cost;
  71. }
  72. void
  73. ospf_if_recalculate_output_cost (struct interface *ifp)
  74. {
  75. u_int32_t newcost;
  76. struct route_node *rn;
  77. for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
  78. {
  79. struct ospf_interface *oi;
  80. if ( (oi = rn->info) == NULL)
  81. continue;
  82. newcost = ospf_if_get_output_cost (oi);
  83. /* Is actual output cost changed? */
  84. if (oi->output_cost != newcost)
  85. {
  86. oi->output_cost = newcost;
  87. ospf_router_lsa_update_area (oi->area);
  88. }
  89. }
  90. }
  91. /* Simulate down/up on the interface. This is needed, for example, when
  92. the MTU changes. */
  93. void
  94. ospf_if_reset(struct interface *ifp)
  95. {
  96. struct route_node *rn;
  97. for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
  98. {
  99. struct ospf_interface *oi;
  100. if ( (oi = rn->info) == NULL)
  101. continue;
  102. ospf_if_down(oi);
  103. ospf_if_up(oi);
  104. }
  105. }
  106. void
  107. ospf_if_reset_variables (struct ospf_interface *oi)
  108. {
  109. /* Set default values. */
  110. /* don't clear this flag. oi->flag = OSPF_IF_DISABLE; */
  111. if (oi->vl_data)
  112. oi->type = OSPF_IFTYPE_VIRTUALLINK;
  113. else
  114. /* preserve network-type */
  115. if (oi->type != OSPF_IFTYPE_NBMA)
  116. oi->type = OSPF_IFTYPE_BROADCAST;
  117. oi->state = ISM_Down;
  118. oi->crypt_seqnum = 0;
  119. /* This must be short, (less than RxmtInterval)
  120. - RFC 2328 Section 13.5 para 3. Set to 1 second to avoid Acks being
  121. held back for too long - MAG */
  122. oi->v_ls_ack = 1;
  123. }
  124. /* lookup oi for specified prefix/ifp */
  125. struct ospf_interface *
  126. ospf_if_table_lookup (struct interface *ifp, struct prefix *prefix)
  127. {
  128. struct prefix p;
  129. struct route_node *rn;
  130. struct ospf_interface *rninfo = NULL;
  131. p = *prefix;
  132. p.prefixlen = IPV4_MAX_PREFIXLEN;
  133. /* route_node_get implicitely locks */
  134. if ((rn = route_node_lookup (IF_OIFS (ifp), &p)))
  135. {
  136. rninfo = (struct ospf_interface *) rn->info;
  137. route_unlock_node (rn);
  138. }
  139. return rninfo;
  140. }
  141. static void
  142. ospf_add_to_if (struct interface *ifp, struct ospf_interface *oi)
  143. {
  144. struct route_node *rn;
  145. struct prefix p;
  146. p = *oi->address;
  147. p.prefixlen = IPV4_MAX_PREFIXLEN;
  148. rn = route_node_get (IF_OIFS (ifp), &p);
  149. /* rn->info should either be NULL or equal to this oi
  150. * as route_node_get may return an existing node
  151. */
  152. assert (!rn->info || rn->info == oi);
  153. rn->info = oi;
  154. }
  155. static void
  156. ospf_delete_from_if (struct interface *ifp, struct ospf_interface *oi)
  157. {
  158. struct route_node *rn;
  159. struct prefix p;
  160. p = *oi->address;
  161. p.prefixlen = IPV4_MAX_PREFIXLEN;
  162. rn = route_node_lookup (IF_OIFS (oi->ifp), &p);
  163. assert (rn);
  164. assert (rn->info);
  165. rn->info = NULL;
  166. route_unlock_node (rn);
  167. route_unlock_node (rn);
  168. }
  169. struct ospf_interface *
  170. ospf_if_new (struct ospf *ospf, struct interface *ifp, struct prefix *p)
  171. {
  172. struct ospf_interface *oi;
  173. if ((oi = ospf_if_table_lookup (ifp, p)) == NULL)
  174. {
  175. oi = XCALLOC (MTYPE_OSPF_IF, sizeof (struct ospf_interface));
  176. memset (oi, 0, sizeof (struct ospf_interface));
  177. }
  178. else
  179. return oi;
  180. /* Set zebra interface pointer. */
  181. oi->ifp = ifp;
  182. oi->address = p;
  183. ospf_add_to_if (ifp, oi);
  184. listnode_add (ospf->oiflist, oi);
  185. /* Initialize neighbor list. */
  186. oi->nbrs = route_table_init ();
  187. /* Initialize static neighbor list. */
  188. oi->nbr_nbma = list_new ();
  189. /* Initialize Link State Acknowledgment list. */
  190. oi->ls_ack = list_new ();
  191. oi->ls_ack_direct.ls_ack = list_new ();
  192. /* Set default values. */
  193. ospf_if_reset_variables (oi);
  194. /* Add pseudo neighbor. */
  195. oi->nbr_self = ospf_nbr_new (oi);
  196. oi->ls_upd_queue = route_table_init ();
  197. oi->t_ls_upd_event = NULL;
  198. oi->t_ls_ack_direct = NULL;
  199. oi->crypt_seqnum = time (NULL);
  200. #ifdef HAVE_OPAQUE_LSA
  201. ospf_opaque_type9_lsa_init (oi);
  202. #endif /* HAVE_OPAQUE_LSA */
  203. oi->ospf = ospf;
  204. return oi;
  205. }
  206. /* Restore an interface to its pre UP state
  207. Used from ism_interface_down only */
  208. void
  209. ospf_if_cleanup (struct ospf_interface *oi)
  210. {
  211. struct route_node *rn;
  212. struct listnode *node, *nnode;
  213. struct ospf_neighbor *nbr;
  214. struct ospf_nbr_nbma *nbr_nbma;
  215. struct ospf_lsa *lsa;
  216. /* oi->nbrs and oi->nbr_nbma should be deleted on InterfaceDown event */
  217. /* delete all static neighbors attached to this interface */
  218. for (ALL_LIST_ELEMENTS (oi->nbr_nbma, node, nnode, nbr_nbma))
  219. {
  220. OSPF_POLL_TIMER_OFF (nbr_nbma->t_poll);
  221. if (nbr_nbma->nbr)
  222. {
  223. nbr_nbma->nbr->nbr_nbma = NULL;
  224. nbr_nbma->nbr = NULL;
  225. }
  226. nbr_nbma->oi = NULL;
  227. listnode_delete (oi->nbr_nbma, nbr_nbma);
  228. }
  229. /* send Neighbor event KillNbr to all associated neighbors. */
  230. for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
  231. if ((nbr = rn->info) != NULL)
  232. if (nbr != oi->nbr_self)
  233. OSPF_NSM_EVENT_EXECUTE (nbr, NSM_KillNbr);
  234. /* Cleanup Link State Acknowlegdment list. */
  235. for (ALL_LIST_ELEMENTS (oi->ls_ack, node, nnode, lsa))
  236. ospf_lsa_unlock (&lsa); /* oi->ls_ack */
  237. list_delete_all_node (oi->ls_ack);
  238. oi->crypt_seqnum = 0;
  239. /* Empty link state update queue */
  240. ospf_ls_upd_queue_empty (oi);
  241. /* Reset pseudo neighbor. */
  242. ospf_nbr_delete (oi->nbr_self);
  243. oi->nbr_self = ospf_nbr_new (oi);
  244. ospf_nbr_add_self (oi);
  245. }
  246. void
  247. ospf_if_free (struct ospf_interface *oi)
  248. {
  249. ospf_if_down (oi);
  250. assert (oi->state == ISM_Down);
  251. #ifdef HAVE_OPAQUE_LSA
  252. ospf_opaque_type9_lsa_term (oi);
  253. #endif /* HAVE_OPAQUE_LSA */
  254. /* Free Pseudo Neighbour */
  255. ospf_nbr_delete (oi->nbr_self);
  256. route_table_finish (oi->nbrs);
  257. route_table_finish (oi->ls_upd_queue);
  258. /* Free any lists that should be freed */
  259. list_free (oi->nbr_nbma);
  260. list_free (oi->ls_ack);
  261. list_free (oi->ls_ack_direct.ls_ack);
  262. ospf_delete_from_if (oi->ifp, oi);
  263. listnode_delete (oi->ospf->oiflist, oi);
  264. listnode_delete (oi->area->oiflist, oi);
  265. thread_cancel_event (master, oi);
  266. memset (oi, 0, sizeof (*oi));
  267. XFREE (MTYPE_OSPF_IF, oi);
  268. }
  269. /*
  270. * check if interface with given address is configured and
  271. * return it if yes. special treatment for PtP networks.
  272. */
  273. struct ospf_interface *
  274. ospf_if_is_configured (struct ospf *ospf, struct in_addr *address)
  275. {
  276. struct listnode *node, *nnode;
  277. struct ospf_interface *oi;
  278. struct prefix_ipv4 addr;
  279. addr.family = AF_INET;
  280. addr.prefix = *address;
  281. addr.prefixlen = IPV4_MAX_PREFIXLEN;
  282. for (ALL_LIST_ELEMENTS (ospf->oiflist, node, nnode, oi))
  283. if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
  284. {
  285. if (oi->type == OSPF_IFTYPE_POINTOPOINT)
  286. {
  287. /* special leniency: match if addr is anywhere on peer subnet */
  288. if (prefix_match(CONNECTED_PREFIX(oi->connected),
  289. (struct prefix *)&addr))
  290. return oi;
  291. }
  292. else
  293. {
  294. if (IPV4_ADDR_SAME (address, &oi->address->u.prefix4))
  295. return oi;
  296. }
  297. }
  298. return NULL;
  299. }
  300. int
  301. ospf_if_is_up (struct ospf_interface *oi)
  302. {
  303. return if_is_up (oi->ifp);
  304. }
  305. struct ospf_interface *
  306. ospf_if_exists (struct ospf_interface *oic)
  307. {
  308. struct listnode *node;
  309. struct ospf *ospf;
  310. struct ospf_interface *oi;
  311. if ((ospf = ospf_lookup ()) == NULL)
  312. return NULL;
  313. for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
  314. if (oi == oic)
  315. return oi;
  316. return NULL;
  317. }
  318. /* Lookup OSPF interface by router LSA posistion */
  319. struct ospf_interface *
  320. ospf_if_lookup_by_lsa_pos (struct ospf_area *area, int lsa_pos)
  321. {
  322. struct listnode *node;
  323. struct ospf_interface *oi;
  324. for (ALL_LIST_ELEMENTS_RO (area->oiflist, node, oi))
  325. {
  326. if (lsa_pos >= oi->lsa_pos_beg && lsa_pos < oi->lsa_pos_end)
  327. return oi;
  328. }
  329. return NULL;
  330. }
  331. struct ospf_interface *
  332. ospf_if_lookup_by_local_addr (struct ospf *ospf,
  333. struct interface *ifp, struct in_addr address)
  334. {
  335. struct listnode *node;
  336. struct ospf_interface *oi;
  337. for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
  338. if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
  339. {
  340. if (ifp && oi->ifp != ifp)
  341. continue;
  342. if (IPV4_ADDR_SAME (&address, &oi->address->u.prefix4))
  343. return oi;
  344. }
  345. return NULL;
  346. }
  347. struct ospf_interface *
  348. ospf_if_lookup_by_prefix (struct ospf *ospf, struct prefix_ipv4 *p)
  349. {
  350. struct listnode *node;
  351. struct ospf_interface *oi;
  352. /* Check each Interface. */
  353. for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
  354. {
  355. if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
  356. {
  357. struct prefix ptmp;
  358. prefix_copy (&ptmp, CONNECTED_PREFIX(oi->connected));
  359. apply_mask (&ptmp);
  360. if (prefix_same (&ptmp, (struct prefix *) p))
  361. return oi;
  362. }
  363. }
  364. return NULL;
  365. }
  366. /* determine receiving interface by ifp and source address */
  367. struct ospf_interface *
  368. ospf_if_lookup_recv_if (struct ospf *ospf, struct in_addr src,
  369. struct interface *ifp)
  370. {
  371. struct route_node *rn;
  372. struct prefix_ipv4 addr;
  373. struct ospf_interface *oi, *match;
  374. addr.family = AF_INET;
  375. addr.prefix = src;
  376. addr.prefixlen = IPV4_MAX_BITLEN;
  377. match = NULL;
  378. for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
  379. {
  380. oi = rn->info;
  381. if (!oi) /* oi can be NULL for PtP aliases */
  382. continue;
  383. if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
  384. continue;
  385. if (if_is_loopback (oi->ifp))
  386. continue;
  387. if (prefix_match (CONNECTED_PREFIX(oi->connected),
  388. (struct prefix *) &addr))
  389. {
  390. if ( (match == NULL) ||
  391. (match->address->prefixlen < oi->address->prefixlen)
  392. )
  393. match = oi;
  394. }
  395. }
  396. return match;
  397. }
  398. void
  399. ospf_if_stream_set (struct ospf_interface *oi)
  400. {
  401. /* set output fifo queue. */
  402. if (oi->obuf == NULL)
  403. oi->obuf = ospf_fifo_new ();
  404. }
  405. void
  406. ospf_if_stream_unset (struct ospf_interface *oi)
  407. {
  408. struct ospf *ospf = oi->ospf;
  409. if (oi->obuf)
  410. {
  411. ospf_fifo_free (oi->obuf);
  412. oi->obuf = NULL;
  413. if (oi->on_write_q)
  414. {
  415. listnode_delete (ospf->oi_write_q, oi);
  416. if (list_isempty(ospf->oi_write_q))
  417. OSPF_TIMER_OFF (ospf->t_write);
  418. oi->on_write_q = 0;
  419. }
  420. }
  421. }
  422. static struct ospf_if_params *
  423. ospf_new_if_params (void)
  424. {
  425. struct ospf_if_params *oip;
  426. oip = XCALLOC (MTYPE_OSPF_IF_PARAMS, sizeof (struct ospf_if_params));
  427. if (!oip)
  428. return NULL;
  429. UNSET_IF_PARAM (oip, output_cost_cmd);
  430. UNSET_IF_PARAM (oip, transmit_delay);
  431. UNSET_IF_PARAM (oip, retransmit_interval);
  432. UNSET_IF_PARAM (oip, passive_interface);
  433. UNSET_IF_PARAM (oip, v_hello);
  434. UNSET_IF_PARAM (oip, fast_hello);
  435. UNSET_IF_PARAM (oip, v_wait);
  436. UNSET_IF_PARAM (oip, priority);
  437. UNSET_IF_PARAM (oip, type);
  438. UNSET_IF_PARAM (oip, auth_simple);
  439. UNSET_IF_PARAM (oip, auth_crypt);
  440. UNSET_IF_PARAM (oip, auth_type);
  441. oip->auth_crypt = list_new ();
  442. oip->network_lsa_seqnum = htonl(OSPF_INITIAL_SEQUENCE_NUMBER);
  443. return oip;
  444. }
  445. void
  446. ospf_del_if_params (struct ospf_if_params *oip)
  447. {
  448. list_delete (oip->auth_crypt);
  449. XFREE (MTYPE_OSPF_IF_PARAMS, oip);
  450. }
  451. void
  452. ospf_free_if_params (struct interface *ifp, struct in_addr addr)
  453. {
  454. struct ospf_if_params *oip;
  455. struct prefix_ipv4 p;
  456. struct route_node *rn;
  457. p.family = AF_INET;
  458. p.prefixlen = IPV4_MAX_PREFIXLEN;
  459. p.prefix = addr;
  460. rn = route_node_lookup (IF_OIFS_PARAMS (ifp), (struct prefix*)&p);
  461. if (!rn || !rn->info)
  462. return;
  463. oip = rn->info;
  464. route_unlock_node (rn);
  465. if (!OSPF_IF_PARAM_CONFIGURED (oip, output_cost_cmd) &&
  466. !OSPF_IF_PARAM_CONFIGURED (oip, transmit_delay) &&
  467. !OSPF_IF_PARAM_CONFIGURED (oip, retransmit_interval) &&
  468. !OSPF_IF_PARAM_CONFIGURED (oip, passive_interface) &&
  469. !OSPF_IF_PARAM_CONFIGURED (oip, v_hello) &&
  470. !OSPF_IF_PARAM_CONFIGURED (oip, fast_hello) &&
  471. !OSPF_IF_PARAM_CONFIGURED (oip, v_wait) &&
  472. !OSPF_IF_PARAM_CONFIGURED (oip, priority) &&
  473. !OSPF_IF_PARAM_CONFIGURED (oip, type) &&
  474. !OSPF_IF_PARAM_CONFIGURED (oip, auth_simple) &&
  475. !OSPF_IF_PARAM_CONFIGURED (oip, auth_type) &&
  476. listcount (oip->auth_crypt) == 0 &&
  477. ntohl (oip->network_lsa_seqnum) != OSPF_INITIAL_SEQUENCE_NUMBER)
  478. {
  479. ospf_del_if_params (oip);
  480. rn->info = NULL;
  481. route_unlock_node (rn);
  482. }
  483. }
  484. struct ospf_if_params *
  485. ospf_lookup_if_params (struct interface *ifp, struct in_addr addr)
  486. {
  487. struct prefix_ipv4 p;
  488. struct route_node *rn;
  489. p.family = AF_INET;
  490. p.prefixlen = IPV4_MAX_PREFIXLEN;
  491. p.prefix = addr;
  492. rn = route_node_lookup (IF_OIFS_PARAMS (ifp), (struct prefix*)&p);
  493. if (rn)
  494. {
  495. route_unlock_node (rn);
  496. return rn->info;
  497. }
  498. return NULL;
  499. }
  500. struct ospf_if_params *
  501. ospf_get_if_params (struct interface *ifp, struct in_addr addr)
  502. {
  503. struct prefix_ipv4 p;
  504. struct route_node *rn;
  505. p.family = AF_INET;
  506. p.prefixlen = IPV4_MAX_PREFIXLEN;
  507. p.prefix = addr;
  508. rn = route_node_get (IF_OIFS_PARAMS (ifp), (struct prefix*)&p);
  509. if (rn->info == NULL)
  510. rn->info = ospf_new_if_params ();
  511. else
  512. route_unlock_node (rn);
  513. return rn->info;
  514. }
  515. void
  516. ospf_if_update_params (struct interface *ifp, struct in_addr addr)
  517. {
  518. struct route_node *rn;
  519. struct ospf_interface *oi;
  520. for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
  521. {
  522. if ((oi = rn->info) == NULL)
  523. continue;
  524. if (IPV4_ADDR_SAME (&oi->address->u.prefix4, &addr))
  525. oi->params = ospf_lookup_if_params (ifp, oi->address->u.prefix4);
  526. }
  527. }
  528. int
  529. ospf_if_new_hook (struct interface *ifp)
  530. {
  531. int rc = 0;
  532. ifp->info = XCALLOC (MTYPE_OSPF_IF_INFO, sizeof (struct ospf_if_info));
  533. IF_OIFS (ifp) = route_table_init ();
  534. IF_OIFS_PARAMS (ifp) = route_table_init ();
  535. IF_DEF_PARAMS (ifp) = ospf_new_if_params ();
  536. SET_IF_PARAM (IF_DEF_PARAMS (ifp), transmit_delay);
  537. IF_DEF_PARAMS (ifp)->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT;
  538. SET_IF_PARAM (IF_DEF_PARAMS (ifp), retransmit_interval);
  539. IF_DEF_PARAMS (ifp)->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT;
  540. SET_IF_PARAM (IF_DEF_PARAMS (ifp), priority);
  541. IF_DEF_PARAMS (ifp)->priority = OSPF_ROUTER_PRIORITY_DEFAULT;
  542. IF_DEF_PARAMS (ifp)->mtu_ignore = OSPF_MTU_IGNORE_DEFAULT;
  543. SET_IF_PARAM (IF_DEF_PARAMS (ifp), v_hello);
  544. IF_DEF_PARAMS (ifp)->v_hello = OSPF_HELLO_INTERVAL_DEFAULT;
  545. SET_IF_PARAM (IF_DEF_PARAMS (ifp), fast_hello);
  546. IF_DEF_PARAMS (ifp)->fast_hello = OSPF_FAST_HELLO_DEFAULT;
  547. SET_IF_PARAM (IF_DEF_PARAMS (ifp), v_wait);
  548. IF_DEF_PARAMS (ifp)->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
  549. SET_IF_PARAM (IF_DEF_PARAMS (ifp), auth_simple);
  550. memset (IF_DEF_PARAMS (ifp)->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE);
  551. SET_IF_PARAM (IF_DEF_PARAMS (ifp), auth_type);
  552. IF_DEF_PARAMS (ifp)->auth_type = OSPF_AUTH_NOTSET;
  553. #ifdef HAVE_OPAQUE_LSA
  554. rc = ospf_opaque_new_if (ifp);
  555. #endif /* HAVE_OPAQUE_LSA */
  556. return rc;
  557. }
  558. static int
  559. ospf_if_delete_hook (struct interface *ifp)
  560. {
  561. int rc = 0;
  562. struct route_node *rn;
  563. #ifdef HAVE_OPAQUE_LSA
  564. rc = ospf_opaque_del_if (ifp);
  565. #endif /* HAVE_OPAQUE_LSA */
  566. route_table_finish (IF_OIFS (ifp));
  567. for (rn = route_top (IF_OIFS_PARAMS (ifp)); rn; rn = route_next (rn))
  568. if (rn->info)
  569. ospf_del_if_params (rn->info);
  570. route_table_finish (IF_OIFS_PARAMS (ifp));
  571. ospf_del_if_params ((struct ospf_if_params *) IF_DEF_PARAMS (ifp));
  572. XFREE (MTYPE_OSPF_IF_INFO, ifp->info);
  573. ifp->info = NULL;
  574. return rc;
  575. }
  576. int
  577. ospf_if_is_enable (struct ospf_interface *oi)
  578. {
  579. if (!if_is_loopback (oi->ifp))
  580. if (if_is_up (oi->ifp))
  581. return 1;
  582. return 0;
  583. }
  584. void
  585. ospf_if_set_multicast(struct ospf_interface *oi)
  586. {
  587. if ((oi->state > ISM_Loopback) &&
  588. (oi->type != OSPF_IFTYPE_LOOPBACK) &&
  589. (oi->type != OSPF_IFTYPE_VIRTUALLINK) &&
  590. (OSPF_IF_PASSIVE_STATUS(oi) == OSPF_IF_ACTIVE))
  591. {
  592. /* The interface should belong to the OSPF-all-routers group. */
  593. if (!OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS) &&
  594. (ospf_if_add_allspfrouters(oi->ospf, oi->address,
  595. oi->ifp->ifindex) >= 0))
  596. /* Set the flag only if the system call to join succeeded. */
  597. OI_MEMBER_JOINED(oi, MEMBER_ALLROUTERS);
  598. }
  599. else
  600. {
  601. /* The interface should NOT belong to the OSPF-all-routers group. */
  602. if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS))
  603. {
  604. /* Only actually drop if this is the last reference */
  605. if (OI_MEMBER_COUNT(oi, MEMBER_ALLROUTERS) == 1)
  606. ospf_if_drop_allspfrouters (oi->ospf, oi->address,
  607. oi->ifp->ifindex);
  608. /* Unset the flag regardless of whether the system call to leave
  609. the group succeeded, since it's much safer to assume that
  610. we are not a member. */
  611. OI_MEMBER_LEFT(oi,MEMBER_ALLROUTERS);
  612. }
  613. }
  614. if (((oi->type == OSPF_IFTYPE_BROADCAST) ||
  615. (oi->type == OSPF_IFTYPE_POINTOPOINT)) &&
  616. ((oi->state == ISM_DR) || (oi->state == ISM_Backup)) &&
  617. (OSPF_IF_PASSIVE_STATUS(oi) == OSPF_IF_ACTIVE))
  618. {
  619. /* The interface should belong to the OSPF-designated-routers group. */
  620. if (!OI_MEMBER_CHECK(oi, MEMBER_DROUTERS) &&
  621. (ospf_if_add_alldrouters(oi->ospf, oi->address,
  622. oi->ifp->ifindex) >= 0))
  623. /* Set the flag only if the system call to join succeeded. */
  624. OI_MEMBER_JOINED(oi, MEMBER_DROUTERS);
  625. }
  626. else
  627. {
  628. /* The interface should NOT belong to the OSPF-designated-routers group */
  629. if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS))
  630. {
  631. /* drop only if last reference */
  632. if (OI_MEMBER_COUNT(oi, MEMBER_DROUTERS) == 1)
  633. ospf_if_drop_alldrouters(oi->ospf, oi->address, oi->ifp->ifindex);
  634. /* Unset the flag regardless of whether the system call to leave
  635. the group succeeded, since it's much safer to assume that
  636. we are not a member. */
  637. OI_MEMBER_LEFT(oi, MEMBER_DROUTERS);
  638. }
  639. }
  640. }
  641. int
  642. ospf_if_up (struct ospf_interface *oi)
  643. {
  644. if (oi == NULL)
  645. return 0;
  646. if (oi->type == OSPF_IFTYPE_LOOPBACK)
  647. OSPF_ISM_EVENT_SCHEDULE (oi, ISM_LoopInd);
  648. else
  649. {
  650. struct ospf *ospf = ospf_lookup ();
  651. if (ospf != NULL)
  652. ospf_adjust_sndbuflen (ospf, oi->ifp->mtu);
  653. else
  654. zlog_warn ("%s: ospf_lookup() returned NULL", __func__);
  655. ospf_if_stream_set (oi);
  656. OSPF_ISM_EVENT_SCHEDULE (oi, ISM_InterfaceUp);
  657. }
  658. return 1;
  659. }
  660. int
  661. ospf_if_down (struct ospf_interface *oi)
  662. {
  663. if (oi == NULL)
  664. return 0;
  665. OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceDown);
  666. /* delete position in router LSA */
  667. oi->lsa_pos_beg = 0;
  668. oi->lsa_pos_end = 0;
  669. /* Shutdown packet reception and sending */
  670. ospf_if_stream_unset (oi);
  671. return 1;
  672. }
  673. /* Virtual Link related functions. */
  674. struct ospf_vl_data *
  675. ospf_vl_data_new (struct ospf_area *area, struct in_addr vl_peer)
  676. {
  677. struct ospf_vl_data *vl_data;
  678. vl_data = XCALLOC (MTYPE_OSPF_VL_DATA, sizeof (struct ospf_vl_data));
  679. vl_data->vl_peer.s_addr = vl_peer.s_addr;
  680. vl_data->vl_area_id = area->area_id;
  681. vl_data->format = area->format;
  682. return vl_data;
  683. }
  684. void
  685. ospf_vl_data_free (struct ospf_vl_data *vl_data)
  686. {
  687. XFREE (MTYPE_OSPF_VL_DATA, vl_data);
  688. }
  689. u_int vlink_count = 0;
  690. struct ospf_interface *
  691. ospf_vl_new (struct ospf *ospf, struct ospf_vl_data *vl_data)
  692. {
  693. struct ospf_interface * voi;
  694. struct interface * vi;
  695. char ifname[INTERFACE_NAMSIZ + 1];
  696. struct ospf_area *area;
  697. struct in_addr area_id;
  698. struct connected *co;
  699. struct prefix_ipv4 *p;
  700. if (IS_DEBUG_OSPF_EVENT)
  701. zlog_debug ("ospf_vl_new(): Start");
  702. if (vlink_count == OSPF_VL_MAX_COUNT)
  703. {
  704. if (IS_DEBUG_OSPF_EVENT)
  705. zlog_debug ("ospf_vl_new(): Alarm: "
  706. "cannot create more than OSPF_MAX_VL_COUNT virtual links");
  707. return NULL;
  708. }
  709. if (IS_DEBUG_OSPF_EVENT)
  710. zlog_debug ("ospf_vl_new(): creating pseudo zebra interface");
  711. snprintf (ifname, sizeof(ifname), "VLINK%d", vlink_count);
  712. vi = if_create (ifname, strnlen(ifname, sizeof(ifname)));
  713. co = connected_new ();
  714. co->ifp = vi;
  715. listnode_add (vi->connected, co);
  716. p = prefix_ipv4_new ();
  717. p->family = AF_INET;
  718. p->prefix.s_addr = 0;
  719. p->prefixlen = 0;
  720. co->address = (struct prefix *)p;
  721. voi = ospf_if_new (ospf, vi, co->address);
  722. if (voi == NULL)
  723. {
  724. if (IS_DEBUG_OSPF_EVENT)
  725. zlog_debug ("ospf_vl_new(): Alarm: OSPF int structure is not created");
  726. return NULL;
  727. }
  728. voi->connected = co;
  729. voi->vl_data = vl_data;
  730. voi->ifp->mtu = OSPF_VL_MTU;
  731. voi->type = OSPF_IFTYPE_VIRTUALLINK;
  732. vlink_count++;
  733. if (IS_DEBUG_OSPF_EVENT)
  734. zlog_debug ("ospf_vl_new(): Created name: %s", ifname);
  735. if (IS_DEBUG_OSPF_EVENT)
  736. zlog_debug ("ospf_vl_new(): set if->name to %s", vi->name);
  737. area_id.s_addr = 0;
  738. area = ospf_area_get (ospf, area_id, OSPF_AREA_ID_FORMAT_ADDRESS);
  739. voi->area = area;
  740. if (IS_DEBUG_OSPF_EVENT)
  741. zlog_debug ("ospf_vl_new(): set associated area to the backbone");
  742. ospf_nbr_add_self (voi);
  743. ospf_area_add_if (voi->area, voi);
  744. ospf_if_stream_set (voi);
  745. if (IS_DEBUG_OSPF_EVENT)
  746. zlog_debug ("ospf_vl_new(): Stop");
  747. return voi;
  748. }
  749. static void
  750. ospf_vl_if_delete (struct ospf_vl_data *vl_data)
  751. {
  752. struct interface *ifp = vl_data->vl_oi->ifp;
  753. vl_data->vl_oi->address->u.prefix4.s_addr = 0;
  754. vl_data->vl_oi->address->prefixlen = 0;
  755. ospf_if_free (vl_data->vl_oi);
  756. if_delete (ifp);
  757. vlink_count--;
  758. }
  759. /* Look up vl_data for given peer, optionally qualified to be in the
  760. * specified area. NULL area returns first found..
  761. */
  762. struct ospf_vl_data *
  763. ospf_vl_lookup (struct ospf *ospf, struct ospf_area *area,
  764. struct in_addr vl_peer)
  765. {
  766. struct ospf_vl_data *vl_data;
  767. struct listnode *node;
  768. if (IS_DEBUG_OSPF_EVENT)
  769. {
  770. zlog_debug ("%s: Looking for %s", __func__, inet_ntoa (vl_peer));
  771. if (area)
  772. zlog_debug ("%s: in area %s", __func__, inet_ntoa (area->area_id));
  773. }
  774. for (ALL_LIST_ELEMENTS_RO (ospf->vlinks, node, vl_data))
  775. {
  776. if (IS_DEBUG_OSPF_EVENT)
  777. zlog_debug ("%s: VL %s, peer %s", __func__,
  778. vl_data->vl_oi->ifp->name,
  779. inet_ntoa (vl_data->vl_peer));
  780. if (area && !IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
  781. continue;
  782. if (IPV4_ADDR_SAME (&vl_data->vl_peer, &vl_peer))
  783. return vl_data;
  784. }
  785. return NULL;
  786. }
  787. static void
  788. ospf_vl_shutdown (struct ospf_vl_data *vl_data)
  789. {
  790. struct ospf_interface *oi;
  791. if ((oi = vl_data->vl_oi) == NULL)
  792. return;
  793. oi->address->u.prefix4.s_addr = 0;
  794. oi->address->prefixlen = 0;
  795. UNSET_FLAG (oi->ifp->flags, IFF_UP);
  796. /* OSPF_ISM_EVENT_SCHEDULE (oi, ISM_InterfaceDown); */
  797. OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceDown);
  798. }
  799. void
  800. ospf_vl_add (struct ospf *ospf, struct ospf_vl_data *vl_data)
  801. {
  802. listnode_add (ospf->vlinks, vl_data);
  803. #ifdef HAVE_SNMP
  804. ospf_snmp_vl_add (vl_data);
  805. #endif /* HAVE_SNMP */
  806. }
  807. void
  808. ospf_vl_delete (struct ospf *ospf, struct ospf_vl_data *vl_data)
  809. {
  810. ospf_vl_shutdown (vl_data);
  811. ospf_vl_if_delete (vl_data);
  812. #ifdef HAVE_SNMP
  813. ospf_snmp_vl_delete (vl_data);
  814. #endif /* HAVE_SNMP */
  815. listnode_delete (ospf->vlinks, vl_data);
  816. ospf_vl_data_free (vl_data);
  817. }
  818. static int
  819. ospf_vl_set_params (struct ospf_vl_data *vl_data, struct vertex *v)
  820. {
  821. int changed = 0;
  822. struct ospf_interface *voi;
  823. struct listnode *node;
  824. struct vertex_parent *vp = NULL;
  825. int i;
  826. struct router_lsa *rl;
  827. voi = vl_data->vl_oi;
  828. if (voi->output_cost != v->distance)
  829. {
  830. voi->output_cost = v->distance;
  831. changed = 1;
  832. }
  833. for (ALL_LIST_ELEMENTS_RO (v->parents, node, vp))
  834. {
  835. vl_data->nexthop.oi = vp->nexthop->oi;
  836. vl_data->nexthop.router = vp->nexthop->router;
  837. if (!IPV4_ADDR_SAME(&voi->address->u.prefix4,
  838. &vl_data->nexthop.oi->address->u.prefix4))
  839. changed = 1;
  840. voi->address->u.prefix4 = vl_data->nexthop.oi->address->u.prefix4;
  841. voi->address->prefixlen = vl_data->nexthop.oi->address->prefixlen;
  842. break; /* We take the first interface. */
  843. }
  844. rl = (struct router_lsa *)v->lsa;
  845. /* use SPF determined backlink index in struct vertex
  846. * for virtual link destination address
  847. */
  848. if (vp && vp->backlink >= 0)
  849. {
  850. if (!IPV4_ADDR_SAME (&vl_data->peer_addr,
  851. &rl->link[vp->backlink].link_data))
  852. changed = 1;
  853. vl_data->peer_addr = rl->link[vp->backlink].link_data;
  854. }
  855. else
  856. {
  857. /* This is highly odd, there is no backlink index
  858. * there should be due to the ospf_spf_has_link() check
  859. * in SPF. Lets warn and try pick a link anyway.
  860. */
  861. zlog_warn ("ospf_vl_set_params: No backlink for %s!",
  862. vl_data->vl_oi->ifp->name);
  863. for (i = 0; i < ntohs (rl->links); i++)
  864. {
  865. switch (rl->link[i].type)
  866. {
  867. case LSA_LINK_TYPE_VIRTUALLINK:
  868. if (IS_DEBUG_OSPF_EVENT)
  869. zlog_debug ("found back link through VL");
  870. case LSA_LINK_TYPE_TRANSIT:
  871. case LSA_LINK_TYPE_POINTOPOINT:
  872. if (!IPV4_ADDR_SAME (&vl_data->peer_addr,
  873. &rl->link[i].link_data))
  874. changed = 1;
  875. vl_data->peer_addr = rl->link[i].link_data;
  876. }
  877. }
  878. }
  879. if (IS_DEBUG_OSPF_EVENT)
  880. zlog_debug ("%s: %s peer address: %s, cost: %d,%schanged", __func__,
  881. vl_data->vl_oi->ifp->name,
  882. inet_ntoa(vl_data->peer_addr),
  883. voi->output_cost,
  884. (changed ? " " : " un"));
  885. return changed;
  886. }
  887. void
  888. ospf_vl_up_check (struct ospf_area *area, struct in_addr rid,
  889. struct vertex *v)
  890. {
  891. struct ospf *ospf = area->ospf;
  892. struct listnode *node;
  893. struct ospf_vl_data *vl_data;
  894. struct ospf_interface *oi;
  895. if (IS_DEBUG_OSPF_EVENT)
  896. {
  897. zlog_debug ("ospf_vl_up_check(): Start");
  898. zlog_debug ("ospf_vl_up_check(): Router ID is %s", inet_ntoa (rid));
  899. zlog_debug ("ospf_vl_up_check(): Area is %s", inet_ntoa (area->area_id));
  900. }
  901. for (ALL_LIST_ELEMENTS_RO (ospf->vlinks, node, vl_data))
  902. {
  903. if (IS_DEBUG_OSPF_EVENT)
  904. {
  905. zlog_debug ("%s: considering VL, %s in area %s", __func__,
  906. vl_data->vl_oi->ifp->name,
  907. inet_ntoa (vl_data->vl_area_id));
  908. zlog_debug ("%s: peer ID: %s", __func__,
  909. inet_ntoa (vl_data->vl_peer));
  910. }
  911. if (IPV4_ADDR_SAME (&vl_data->vl_peer, &rid) &&
  912. IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
  913. {
  914. oi = vl_data->vl_oi;
  915. SET_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED);
  916. if (IS_DEBUG_OSPF_EVENT)
  917. zlog_debug ("ospf_vl_up_check(): this VL matched");
  918. if (oi->state == ISM_Down)
  919. {
  920. if (IS_DEBUG_OSPF_EVENT)
  921. zlog_debug ("ospf_vl_up_check(): VL is down, waking it up");
  922. SET_FLAG (oi->ifp->flags, IFF_UP);
  923. OSPF_ISM_EVENT_EXECUTE(oi,ISM_InterfaceUp);
  924. }
  925. if (ospf_vl_set_params (vl_data, v))
  926. {
  927. if (IS_DEBUG_OSPF (ism, ISM_EVENTS))
  928. zlog_debug ("ospf_vl_up_check: VL cost change,"
  929. " scheduling router lsa refresh");
  930. if (ospf->backbone)
  931. ospf_router_lsa_update_area (ospf->backbone);
  932. else if (IS_DEBUG_OSPF (ism, ISM_EVENTS))
  933. zlog_debug ("ospf_vl_up_check: VL cost change, no backbone!");
  934. }
  935. }
  936. }
  937. }
  938. void
  939. ospf_vl_unapprove (struct ospf *ospf)
  940. {
  941. struct listnode *node;
  942. struct ospf_vl_data *vl_data;
  943. for (ALL_LIST_ELEMENTS_RO (ospf->vlinks, node, vl_data))
  944. UNSET_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED);
  945. }
  946. void
  947. ospf_vl_shut_unapproved (struct ospf *ospf)
  948. {
  949. struct listnode *node, *nnode;
  950. struct ospf_vl_data *vl_data;
  951. for (ALL_LIST_ELEMENTS (ospf->vlinks, node, nnode, vl_data))
  952. if (!CHECK_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED))
  953. ospf_vl_shutdown (vl_data);
  954. }
  955. int
  956. ospf_full_virtual_nbrs (struct ospf_area *area)
  957. {
  958. if (IS_DEBUG_OSPF_EVENT)
  959. {
  960. zlog_debug ("counting fully adjacent virtual neighbors in area %s",
  961. inet_ntoa (area->area_id));
  962. zlog_debug ("there are %d of them", area->full_vls);
  963. }
  964. return area->full_vls;
  965. }
  966. int
  967. ospf_vls_in_area (struct ospf_area *area)
  968. {
  969. struct listnode *node;
  970. struct ospf_vl_data *vl_data;
  971. int c = 0;
  972. for (ALL_LIST_ELEMENTS_RO (area->ospf->vlinks, node, vl_data))
  973. if (IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
  974. c++;
  975. return c;
  976. }
  977. struct crypt_key *
  978. ospf_crypt_key_new ()
  979. {
  980. return XCALLOC (MTYPE_OSPF_CRYPT_KEY, sizeof (struct crypt_key));
  981. }
  982. void
  983. ospf_crypt_key_add (struct list *crypt, struct crypt_key *ck)
  984. {
  985. listnode_add (crypt, ck);
  986. }
  987. struct crypt_key *
  988. ospf_crypt_key_lookup (struct list *auth_crypt, u_char key_id)
  989. {
  990. struct listnode *node;
  991. struct crypt_key *ck;
  992. for (ALL_LIST_ELEMENTS_RO (auth_crypt, node, ck))
  993. if (ck->key_id == key_id)
  994. return ck;
  995. return NULL;
  996. }
  997. int
  998. ospf_crypt_key_delete (struct list *auth_crypt, u_char key_id)
  999. {
  1000. struct listnode *node, *nnode;
  1001. struct crypt_key *ck;
  1002. for (ALL_LIST_ELEMENTS (auth_crypt, node, nnode, ck))
  1003. {
  1004. if (ck->key_id == key_id)
  1005. {
  1006. listnode_delete (auth_crypt, ck);
  1007. XFREE (MTYPE_OSPF_CRYPT_KEY, ck);
  1008. return 1;
  1009. }
  1010. }
  1011. return 0;
  1012. }
  1013. u_char
  1014. ospf_default_iftype(struct interface *ifp)
  1015. {
  1016. if (if_is_pointopoint (ifp))
  1017. return OSPF_IFTYPE_POINTOPOINT;
  1018. else if (if_is_loopback (ifp))
  1019. return OSPF_IFTYPE_LOOPBACK;
  1020. else
  1021. return OSPF_IFTYPE_BROADCAST;
  1022. }
  1023. void
  1024. ospf_if_init ()
  1025. {
  1026. /* Initialize Zebra interface data structure. */
  1027. if_init ();
  1028. om->iflist = iflist;
  1029. if_add_hook (IF_NEW_HOOK, ospf_if_new_hook);
  1030. if_add_hook (IF_DELETE_HOOK, ospf_if_delete_hook);
  1031. }