Coverage Report

Created: 2026-01-25 06:17

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/frr/ospfd/ospfd.c
Line
Count
Source
1
// SPDX-License-Identifier: GPL-2.0-or-later
2
/* OSPF version 2 daemon program.
3
 * Copyright (C) 1999, 2000 Toshiaki Takada
4
 */
5
6
#include <zebra.h>
7
8
#include "frrevent.h"
9
#include "vty.h"
10
#include "command.h"
11
#include "linklist.h"
12
#include "prefix.h"
13
#include "table.h"
14
#include "if.h"
15
#include "memory.h"
16
#include "stream.h"
17
#include "log.h"
18
#include "sockunion.h" /* for inet_aton () */
19
#include "zclient.h"
20
#include "routemap.h"
21
#include "plist.h"
22
#include "sockopt.h"
23
#include "bfd.h"
24
#include "libfrr.h"
25
#include "defaults.h"
26
#include "lib_errors.h"
27
#include "ldp_sync.h"
28
29
#include "ospfd/ospfd.h"
30
#include "ospfd/ospf_bfd.h"
31
#include "ospfd/ospf_network.h"
32
#include "ospfd/ospf_interface.h"
33
#include "ospfd/ospf_ism.h"
34
#include "ospfd/ospf_asbr.h"
35
#include "ospfd/ospf_lsa.h"
36
#include "ospfd/ospf_lsdb.h"
37
#include "ospfd/ospf_neighbor.h"
38
#include "ospfd/ospf_nsm.h"
39
#include "ospfd/ospf_spf.h"
40
#include "ospfd/ospf_packet.h"
41
#include "ospfd/ospf_dump.h"
42
#include "ospfd/ospf_route.h"
43
#include "ospfd/ospf_zebra.h"
44
#include "ospfd/ospf_abr.h"
45
#include "ospfd/ospf_flood.h"
46
#include "ospfd/ospf_ase.h"
47
#include "ospfd/ospf_ldp_sync.h"
48
#include "ospfd/ospf_gr.h"
49
#include "ospfd/ospf_apiserver.h"
50
51
52
DEFINE_QOBJ_TYPE(ospf);
53
54
/* OSPF process wide configuration. */
55
static struct ospf_master ospf_master;
56
57
/* OSPF process wide configuration pointer to export. */
58
struct ospf_master *om;
59
60
unsigned short ospf_instance;
61
62
extern struct zclient *zclient;
63
64
65
static void ospf_remove_vls_through_area(struct ospf *, struct ospf_area *);
66
static void ospf_network_free(struct ospf *, struct ospf_network *);
67
static void ospf_area_free(struct ospf_area *);
68
static void ospf_network_run(struct prefix *, struct ospf_area *);
69
static void ospf_network_run_interface(struct ospf *, struct interface *,
70
               struct prefix *, struct ospf_area *);
71
static void ospf_network_run_subnet(struct ospf *, struct connected *,
72
            struct prefix *, struct ospf_area *);
73
static int ospf_network_match_iface(const struct connected *,
74
            const struct prefix *);
75
static void ospf_finish_final(struct ospf *);
76
77
/* API to clean refresh queues and LSAs */
78
static void ospf_free_refresh_queue(struct ospf *ospf)
79
0
{
80
0
  for (int i = 0; i < OSPF_LSA_REFRESHER_SLOTS; i++) {
81
0
    struct list *list = ospf->lsa_refresh_queue.qs[i];
82
0
    struct listnode *node, *nnode;
83
0
    struct ospf_lsa *lsa;
84
85
0
    if (list) {
86
0
      for (ALL_LIST_ELEMENTS(list, node, nnode, lsa)) {
87
0
        listnode_delete(list, lsa);
88
0
        lsa->refresh_list = -1;
89
0
        ospf_lsa_unlock(&lsa);
90
0
      }
91
0
      list_delete(&list);
92
0
      ospf->lsa_refresh_queue.qs[i] = NULL;
93
0
    }
94
0
  }
95
0
}
96
#define OSPF_EXTERNAL_LSA_ORIGINATE_DELAY 1
97
98
int p_spaces_compare_func(const struct p_space *a, const struct p_space *b)
99
0
{
100
0
  if (a->protected_resource->type == OSPF_TI_LFA_LINK_PROTECTION
101
0
      && b->protected_resource->type == OSPF_TI_LFA_LINK_PROTECTION)
102
0
    return (a->protected_resource->link->link_id.s_addr
103
0
      - b->protected_resource->link->link_id.s_addr);
104
105
0
  if (a->protected_resource->type == OSPF_TI_LFA_NODE_PROTECTION
106
0
      && b->protected_resource->type == OSPF_TI_LFA_NODE_PROTECTION)
107
0
    return (a->protected_resource->router_id.s_addr
108
0
      - b->protected_resource->router_id.s_addr);
109
110
  /* This should not happen */
111
0
  return 0;
112
0
}
113
114
int q_spaces_compare_func(const struct q_space *a, const struct q_space *b)
115
0
{
116
0
  return (a->root->id.s_addr - b->root->id.s_addr);
117
0
}
118
119
DECLARE_RBTREE_UNIQ(p_spaces, struct p_space, p_spaces_item,
120
        p_spaces_compare_func);
121
122
void ospf_process_refresh_data(struct ospf *ospf, bool reset)
123
1
{
124
1
  struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id);
125
1
  struct in_addr router_id, router_id_old;
126
1
  struct ospf_interface *oi;
127
1
  struct interface *ifp;
128
1
  struct listnode *node, *nnode;
129
1
  struct ospf_area *area;
130
1
  bool rid_change = false;
131
132
1
  if (!ospf->oi_running) {
133
0
    if (IS_DEBUG_OSPF_EVENT)
134
0
      zlog_debug(
135
0
        "Router ospf not configured -- Router-ID update postponed");
136
0
    return;
137
0
  }
138
139
1
  if (IS_DEBUG_OSPF_EVENT)
140
0
    zlog_debug("Router-ID[OLD:%pI4]: Update",
141
1
         &ospf->router_id);
142
143
1
  router_id_old = ospf->router_id;
144
145
  /* Select the router ID based on these priorities:
146
       1. Statically assigned router ID is always the first choice.
147
       2. If there is no statically assigned router ID, then try to stick
148
    with the most recent value, since changing router ID's is very
149
    disruptive.
150
       3. Last choice: just go with whatever the zebra daemon recommends.
151
  */
152
1
  if (ospf->router_id_static.s_addr != INADDR_ANY)
153
0
    router_id = ospf->router_id_static;
154
1
  else if (ospf->router_id.s_addr != INADDR_ANY)
155
0
    router_id = ospf->router_id;
156
1
  else
157
1
    router_id = ospf->router_id_zebra;
158
159
1
  if (IS_DEBUG_OSPF_EVENT)
160
0
    zlog_debug("Router-ID[OLD:%pI4]: Update to %pI4",
161
1
         &ospf->router_id, &router_id);
162
163
1
  rid_change = !(IPV4_ADDR_SAME(&router_id_old, &router_id));
164
1
  if (rid_change || (reset)) {
165
0
    for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
166
      /* Some nbrs are identified by router_id, these needs
167
       * to be rebuilt. Possible optimization would be to do
168
       * oi->nbr_self->router_id = router_id for
169
       * !(virtual | ptop) links
170
       */
171
0
      ospf_nbr_self_reset(oi, router_id);
172
173
      /*
174
       * If the old router id was not set, but now it
175
       * is and the interface is operative and the
176
       * state is ISM_Down we should kick the state
177
       * machine as that we processed the interfaces
178
       * based upon the network statement( or intf config )
179
       * but could not start it at that time.
180
       */
181
0
      if (if_is_operative(oi->ifp) && oi->state == ISM_Down
182
0
          && router_id_old.s_addr == INADDR_ANY)
183
0
        ospf_if_up(oi);
184
0
    }
185
186
    /* Flush (inline) all the self originated LSAs */
187
0
    ospf_flush_self_originated_lsas_now(ospf);
188
189
0
    ospf->router_id = router_id;
190
0
    if (IS_DEBUG_OSPF_EVENT)
191
0
      zlog_debug("Router-ID[NEW:%pI4]: Update",
192
0
           &ospf->router_id);
193
194
    /* Flush (inline) all external LSAs which now match the new
195
       router-id,
196
       need to adjust the OSPF_LSA_SELF flag, so the flush doesn't
197
       hit
198
       asserts in ospf_refresher_unregister_lsa(). This step is
199
       needed
200
       because the current frr code does look-up for
201
       self-originated LSAs
202
       based on the self router-id alone but expects OSPF_LSA_SELF
203
       to be
204
       properly set */
205
0
    if (ospf->lsdb) {
206
0
      struct route_node *rn;
207
0
      struct ospf_lsa *lsa;
208
209
0
      LSDB_LOOP (EXTERNAL_LSDB(ospf), rn, lsa) {
210
        /* AdvRouter and Router ID is the same. */
211
0
        if (IPV4_ADDR_SAME(&lsa->data->adv_router,
212
0
          &ospf->router_id) && rid_change) {
213
0
          SET_FLAG(lsa->flags,
214
0
             OSPF_LSA_SELF_CHECKED);
215
0
          SET_FLAG(lsa->flags, OSPF_LSA_SELF);
216
0
          ospf_lsa_flush_schedule(ospf, lsa);
217
0
        }
218
        /* The above flush will send immediately
219
         * So discard the LSA to originate new
220
         */
221
0
        ospf_discard_from_db(ospf, ospf->lsdb, lsa);
222
0
      }
223
224
0
      LSDB_LOOP (OPAQUE_AS_LSDB(ospf), rn, lsa)
225
0
        ospf_discard_from_db(ospf, ospf->lsdb, lsa);
226
227
0
      ospf_lsdb_delete_all(ospf->lsdb);
228
0
    }
229
230
    /* Since the LSAs are deleted, need reset the aggr flag */
231
0
    ospf_unset_all_aggr_flag(ospf);
232
233
    /* Delete the LSDB */
234
0
    for (ALL_LIST_ELEMENTS(ospf->areas, node, nnode, area))
235
0
      ospf_area_lsdb_discard_delete(area);
236
237
    /* update router-lsa's for each area */
238
0
    ospf_router_lsa_update(ospf);
239
240
    /* update ospf_interface's */
241
0
    FOR_ALL_INTERFACES (vrf, ifp) {
242
0
      if (reset)
243
0
        ospf_if_reset(ifp);
244
0
      else
245
0
        ospf_if_update(ospf, ifp);
246
0
    }
247
248
0
    ospf_external_lsa_rid_change(ospf);
249
250
0
#ifdef SUPPORT_OSPF_API
251
0
    ospf_apiserver_clients_notify_router_id_change(router_id);
252
0
#endif
253
0
  }
254
255
1
  ospf->inst_shutdown = 0;
256
1
}
257
258
void ospf_router_id_update(struct ospf *ospf)
259
1
{
260
1
  ospf_process_refresh_data(ospf, false);
261
1
}
262
263
void ospf_process_reset(struct ospf *ospf)
264
0
{
265
0
  ospf_process_refresh_data(ospf, true);
266
0
}
267
268
void ospf_neighbor_reset(struct ospf *ospf, struct in_addr nbr_id,
269
      const char *nbr_str)
270
0
{
271
0
  struct route_node *rn;
272
0
  struct ospf_neighbor *nbr;
273
0
  struct ospf_interface *oi;
274
0
  struct listnode *node;
275
276
  /* Clear only a particular nbr with nbr router id as nbr_id */
277
0
  if (nbr_str != NULL) {
278
0
    for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
279
0
      nbr = ospf_nbr_lookup_by_routerid(oi->nbrs, &nbr_id);
280
0
      if (nbr)
281
0
        OSPF_NSM_EVENT_EXECUTE(nbr, NSM_KillNbr);
282
0
    }
283
0
    return;
284
0
  }
285
286
  /* send Neighbor event KillNbr to all associated neighbors. */
287
0
  for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
288
0
    for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
289
0
      nbr = rn->info;
290
0
      if (nbr && (nbr != oi->nbr_self))
291
0
        OSPF_NSM_EVENT_EXECUTE(nbr, NSM_KillNbr);
292
0
    }
293
0
  }
294
0
}
295
296
/* For OSPF area sort by area id. */
297
static int ospf_area_id_cmp(struct ospf_area *a1, struct ospf_area *a2)
298
0
{
299
0
  if (ntohl(a1->area_id.s_addr) > ntohl(a2->area_id.s_addr))
300
0
    return 1;
301
0
  if (ntohl(a1->area_id.s_addr) < ntohl(a2->area_id.s_addr))
302
0
    return -1;
303
0
  return 0;
304
0
}
305
306
static void ospf_add(struct ospf *ospf)
307
1
{
308
1
  listnode_add(om->ospf, ospf);
309
1
}
310
311
static void ospf_delete(struct ospf *ospf)
312
0
{
313
0
  listnode_delete(om->ospf, ospf);
314
0
}
315
316
struct ospf *ospf_new_alloc(unsigned short instance, const char *name)
317
1
{
318
1
  int i;
319
1
  struct vrf *vrf = NULL;
320
321
1
  struct ospf *new = XCALLOC(MTYPE_OSPF_TOP, sizeof(struct ospf));
322
323
1
  new->instance = instance;
324
1
  new->router_id.s_addr = htonl(0);
325
1
  new->router_id_static.s_addr = htonl(0);
326
327
1
  vrf = vrf_lookup_by_name(name);
328
1
  if (vrf)
329
1
    new->vrf_id = vrf->vrf_id;
330
0
  else
331
0
    new->vrf_id = VRF_UNKNOWN;
332
333
  /* Freed in ospf_finish_final */
334
1
  new->name = XSTRDUP(MTYPE_OSPF_TOP, name);
335
1
  if (IS_DEBUG_OSPF_EVENT)
336
0
    zlog_debug(
337
1
      "%s: Create new ospf instance with vrf_name %s vrf_id %u",
338
1
      __func__, name, new->vrf_id);
339
340
1
  if (vrf)
341
1
    ospf_vrf_link(new, vrf);
342
343
1
  ospf_zebra_vrf_register(new);
344
345
1
  new->abr_type = OSPF_ABR_DEFAULT;
346
1
  new->oiflist = list_new();
347
1
  new->vlinks = list_new();
348
1
  new->areas = list_new();
349
1
  new->areas->cmp = (int (*)(void *, void *))ospf_area_id_cmp;
350
1
  new->networks = route_table_init();
351
1
  new->nbr_nbma = route_table_init();
352
353
1
  new->lsdb = ospf_lsdb_new();
354
355
1
  new->default_originate = DEFAULT_ORIGINATE_NONE;
356
357
1
  new->passive_interface_default = OSPF_IF_ACTIVE;
358
359
1
  new->new_external_route = route_table_init();
360
1
  new->old_external_route = route_table_init();
361
1
  new->external_lsas = route_table_init();
362
363
1
  new->stub_router_startup_time = OSPF_STUB_ROUTER_UNCONFIGURED;
364
1
  new->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED;
365
1
  new->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET;
366
367
  /* Distribute parameter init. */
368
33
  for (i = 0; i <= ZEBRA_ROUTE_MAX; i++) {
369
32
    new->dtag[i] = 0;
370
32
  }
371
1
  new->default_metric = -1;
372
1
  new->ref_bandwidth = OSPF_DEFAULT_REF_BANDWIDTH;
373
374
  /* LSA timers */
375
1
  new->min_ls_interval = OSPF_MIN_LS_INTERVAL;
376
1
  new->min_ls_arrival = OSPF_MIN_LS_ARRIVAL;
377
378
  /* SPF timer value init. */
379
1
  new->spf_delay = OSPF_SPF_DELAY_DEFAULT;
380
1
  new->spf_holdtime = OSPF_SPF_HOLDTIME_DEFAULT;
381
1
  new->spf_max_holdtime = OSPF_SPF_MAX_HOLDTIME_DEFAULT;
382
1
  new->spf_hold_multiplier = 1;
383
384
  /* MaxAge init. */
385
1
  new->maxage_delay = OSPF_LSA_MAXAGE_REMOVE_DELAY_DEFAULT;
386
1
  new->maxage_lsa = route_table_init();
387
1
  new->t_maxage_walker = NULL;
388
1
  event_add_timer(master, ospf_lsa_maxage_walker, new,
389
1
      OSPF_LSA_MAXAGE_CHECK_INTERVAL, &new->t_maxage_walker);
390
391
  /* Max paths initialization */
392
1
  new->max_multipath = MULTIPATH_NUM;
393
394
  /* Distance table init. */
395
1
  new->distance_table = route_table_init();
396
397
1
  new->lsa_refresh_queue.index = 0;
398
1
  new->lsa_refresh_interval = OSPF_LSA_REFRESH_INTERVAL_DEFAULT;
399
1
  new->lsa_refresh_timer = OSPF_LS_REFRESH_TIME;
400
1
  new->t_lsa_refresher = NULL;
401
1
  event_add_timer(master, ospf_lsa_refresh_walker, new,
402
1
      new->lsa_refresh_interval, &new->t_lsa_refresher);
403
1
  new->lsa_refresher_started = monotime(NULL);
404
405
1
  new->ibuf = stream_new(OSPF_MAX_PACKET_SIZE + 1);
406
407
1
  new->t_read = NULL;
408
1
  new->oi_write_q = list_new();
409
1
  new->write_oi_count = OSPF_WRITE_INTERFACE_COUNT_DEFAULT;
410
411
1
  new->proactive_arp = OSPF_PROACTIVE_ARP_DEFAULT;
412
413
1
  ospf_gr_helper_instance_init(new);
414
415
1
  ospf_asbr_external_aggregator_init(new);
416
417
1
  ospf_opaque_type11_lsa_init(new);
418
419
1
  QOBJ_REG(new, ospf);
420
421
1
  new->fd = -1;
422
1
  new->intf_socket_enabled = true;
423
424
1
  new->recv_sock_bufsize = OSPF_DEFAULT_SOCK_BUFSIZE;
425
1
  new->send_sock_bufsize = OSPF_DEFAULT_SOCK_BUFSIZE;
426
427
1
  return new;
428
1
}
429
430
/* Allocate new ospf structure. */
431
static struct ospf *ospf_new(unsigned short instance, const char *name)
432
1
{
433
1
  struct ospf *new;
434
435
1
  new = ospf_new_alloc(instance, name);
436
1
  ospf_add(new);
437
438
1
  if (new->vrf_id == VRF_UNKNOWN)
439
0
    return new;
440
441
1
  if ((ospf_sock_init(new)) < 0) {
442
0
    flog_err(EC_LIB_SOCKET,
443
0
       "%s: ospf_sock_init is unable to open a socket",
444
0
       __func__);
445
0
    return new;
446
0
  }
447
448
1
  event_add_read(master, ospf_read, new, new->fd, &new->t_read);
449
450
1
  new->oi_running = 1;
451
1
  ospf_router_id_update(new);
452
453
  /*
454
   * Read from non-volatile memory whether this instance is performing a
455
   * graceful restart or not.
456
   */
457
1
  ospf_gr_nvm_read(new);
458
459
1
  new->fr_configured = false;
460
461
1
  return new;
462
1
}
463
464
struct ospf *ospf_lookup_instance(unsigned short instance)
465
0
{
466
0
  struct ospf *ospf;
467
0
  struct listnode *node, *nnode;
468
469
0
  if (listcount(om->ospf) == 0)
470
0
    return NULL;
471
472
0
  for (ALL_LIST_ELEMENTS(om->ospf, node, nnode, ospf))
473
0
    if ((ospf->instance == 0 && instance == 0)
474
0
        || (ospf->instance && instance
475
0
      && ospf->instance == instance))
476
0
      return ospf;
477
478
0
  return NULL;
479
0
}
480
481
static int ospf_is_ready(struct ospf *ospf)
482
0
{
483
  /* OSPF must be on and Router-ID must be configured. */
484
0
  if (!ospf || ospf->router_id.s_addr == INADDR_ANY)
485
0
    return 0;
486
487
0
  return 1;
488
0
}
489
490
struct ospf *ospf_lookup_by_inst_name(unsigned short instance, const char *name)
491
1
{
492
1
  struct ospf *ospf = NULL;
493
1
  struct listnode *node, *nnode;
494
495
1
  for (ALL_LIST_ELEMENTS(om->ospf, node, nnode, ospf)) {
496
0
    if ((ospf->instance == instance)
497
0
        && ((ospf->name == NULL && name == NULL)
498
0
      || (ospf->name && name
499
0
          && strcmp(ospf->name, name) == 0)))
500
0
      return ospf;
501
0
  }
502
1
  return NULL;
503
1
}
504
505
struct ospf *ospf_lookup(unsigned short instance, const char *name)
506
1
{
507
1
  struct ospf *ospf;
508
509
1
  if (ospf_instance) {
510
0
    ospf = ospf_lookup_instance(instance);
511
1
  } else {
512
1
    ospf = ospf_lookup_by_inst_name(instance, name);
513
1
  }
514
515
1
  return ospf;
516
1
}
517
518
struct ospf *ospf_get(unsigned short instance, const char *name, bool *created)
519
1
{
520
1
  struct ospf *ospf;
521
522
1
  ospf = ospf_lookup(instance, name);
523
524
1
  *created = (ospf == NULL);
525
1
  if (ospf == NULL)
526
1
    ospf = ospf_new(instance, name);
527
528
1
  return ospf;
529
1
}
530
531
struct ospf *ospf_lookup_by_vrf_id(vrf_id_t vrf_id)
532
3
{
533
3
  struct vrf *vrf = NULL;
534
535
3
  vrf = vrf_lookup_by_id(vrf_id);
536
3
  if (!vrf)
537
0
    return NULL;
538
3
  return (vrf->info) ? (struct ospf *)vrf->info : NULL;
539
3
}
540
541
uint32_t ospf_count_area_params(struct ospf *ospf)
542
0
{
543
0
  struct vrf *vrf;
544
0
  struct interface *ifp;
545
0
  uint32_t count = 0;
546
547
0
  if (ospf->vrf_id != VRF_UNKNOWN) {
548
0
    vrf = vrf_lookup_by_id(ospf->vrf_id);
549
550
0
    FOR_ALL_INTERFACES (vrf, ifp) {
551
0
      count += ospf_if_count_area_params(ifp);
552
0
    }
553
0
  }
554
555
0
  return count;
556
0
}
557
558
/* It should only be used when processing incoming info update from zebra.
559
 * Other situations, it is not sufficient to lookup the ospf instance by
560
 * vrf_name only without using the instance number.
561
 */
562
static struct ospf *ospf_lookup_by_name(const char *vrf_name)
563
1
{
564
1
  struct ospf *ospf = NULL;
565
1
  struct listnode *node, *nnode;
566
567
1
  for (ALL_LIST_ELEMENTS(om->ospf, node, nnode, ospf))
568
0
    if ((ospf->name == NULL && vrf_name == NULL)
569
0
        || (ospf->name && vrf_name
570
0
      && strcmp(ospf->name, vrf_name) == 0))
571
0
      return ospf;
572
1
  return NULL;
573
1
}
574
575
/* Handle the second half of deferred shutdown. This is called either
576
 * from the deferred-shutdown timer thread, or directly through
577
 * ospf_deferred_shutdown_check.
578
 *
579
 * Function is to cleanup G-R state, if required then call ospf_finish_final
580
 * to complete shutdown of this ospf instance. Possibly exit if the
581
 * whole process is being shutdown and this was the last OSPF instance.
582
 */
583
static void ospf_deferred_shutdown_finish(struct ospf *ospf)
584
0
{
585
0
  ospf->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED;
586
0
  EVENT_OFF(ospf->t_deferred_shutdown);
587
588
0
  ospf_finish_final(ospf);
589
590
  /* *ospf is now invalid */
591
592
  /* ospfd being shut-down? If so, was this the last ospf instance? */
593
0
  if (CHECK_FLAG(om->options, OSPF_MASTER_SHUTDOWN)
594
0
      && (listcount(om->ospf) == 0)) {
595
0
    frr_fini();
596
0
    exit(0);
597
0
  }
598
599
0
  return;
600
0
}
601
602
/* Timer thread for G-R */
603
static void ospf_deferred_shutdown_timer(struct event *t)
604
0
{
605
0
  struct ospf *ospf = EVENT_ARG(t);
606
0
607
0
  ospf_deferred_shutdown_finish(ospf);
608
0
}
609
610
/* Check whether deferred-shutdown must be scheduled, otherwise call
611
 * down directly into second-half of instance shutdown.
612
 */
613
static void ospf_deferred_shutdown_check(struct ospf *ospf)
614
0
{
615
0
  unsigned long timeout;
616
0
  struct listnode *ln;
617
0
  struct ospf_area *area;
618
619
  /* deferred shutdown already running? */
620
0
  if (ospf->t_deferred_shutdown)
621
0
    return;
622
623
  /* Should we try push out max-metric LSAs? */
624
0
  if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED) {
625
0
    for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
626
0
      SET_FLAG(area->stub_router_state,
627
0
         OSPF_AREA_ADMIN_STUB_ROUTED);
628
629
0
      if (!CHECK_FLAG(area->stub_router_state,
630
0
          OSPF_AREA_IS_STUB_ROUTED))
631
0
        ospf_router_lsa_update_area(area);
632
0
    }
633
0
    timeout = ospf->stub_router_shutdown_time;
634
0
  } else {
635
    /* No timer needed */
636
0
    ospf_deferred_shutdown_finish(ospf);
637
0
    return;
638
0
  }
639
640
0
  OSPF_TIMER_ON(ospf->t_deferred_shutdown, ospf_deferred_shutdown_timer,
641
0
          timeout);
642
0
  return;
643
0
}
644
645
/* Shut down the entire process */
646
void ospf_terminate(void)
647
0
{
648
0
  struct ospf *ospf;
649
0
  struct listnode *node, *nnode;
650
651
  /* shutdown already in progress */
652
0
  if (CHECK_FLAG(om->options, OSPF_MASTER_SHUTDOWN))
653
0
    return;
654
655
0
  SET_FLAG(om->options, OSPF_MASTER_SHUTDOWN);
656
657
  /* Skip some steps if OSPF not actually running */
658
0
  if (listcount(om->ospf) == 0)
659
0
    goto done;
660
661
0
  for (ALL_LIST_ELEMENTS(om->ospf, node, nnode, ospf))
662
0
    ospf_finish(ospf);
663
664
  /* Cleanup GR */
665
0
  ospf_gr_helper_stop();
666
667
  /* Cleanup route maps */
668
0
  route_map_finish();
669
670
  /* reverse prefix_list_init */
671
0
  prefix_list_add_hook(NULL);
672
0
  prefix_list_delete_hook(NULL);
673
0
  prefix_list_reset();
674
675
  /* Cleanup vrf info */
676
0
  ospf_vrf_terminate();
677
678
  /* Deliberately go back up, hopefully to thread scheduler, as
679
   * One or more ospf_finish()'s may have deferred shutdown to a timer
680
   * thread
681
   */
682
0
  zclient_stop(zclient);
683
0
  zclient_free(zclient);
684
685
0
done:
686
0
  frr_fini();
687
0
}
688
689
void ospf_finish(struct ospf *ospf)
690
0
{
691
  /* let deferred shutdown decide */
692
0
  ospf_deferred_shutdown_check(ospf);
693
694
  /* if ospf_deferred_shutdown returns, then ospf_finish_final is
695
   * deferred to expiry of G-S timer thread. Return back up, hopefully
696
   * to thread scheduler.
697
   */
698
0
  return;
699
0
}
700
701
/* Final cleanup of ospf instance */
702
static void ospf_finish_final(struct ospf *ospf)
703
0
{
704
0
  struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id);
705
0
  struct route_node *rn;
706
0
  struct ospf_nbr_nbma *nbr_nbma;
707
0
  struct ospf_lsa *lsa;
708
0
  struct ospf_interface *oi;
709
0
  struct ospf_area *area;
710
0
  struct ospf_vl_data *vl_data;
711
0
  struct listnode *node, *nnode;
712
0
  struct ospf_redist *red;
713
0
  int i;
714
715
0
  QOBJ_UNREG(ospf);
716
717
0
  ospf_opaque_type11_lsa_term(ospf);
718
719
0
  ospf_opaque_finish();
720
721
0
  if (!ospf->gr_info.prepare_in_progress)
722
0
    ospf_flush_self_originated_lsas_now(ospf);
723
0
  XFREE(MTYPE_TMP, ospf->gr_info.exit_reason);
724
725
  /* Unregister redistribution */
726
0
  for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
727
0
    struct list *red_list;
728
729
0
    red_list = ospf->redist[i];
730
0
    if (!red_list)
731
0
      continue;
732
733
0
    for (ALL_LIST_ELEMENTS(red_list, node, nnode, red)) {
734
0
      ospf_redistribute_unset(ospf, i, red->instance);
735
0
      ospf_redist_del(ospf, i, red->instance);
736
0
    }
737
0
  }
738
0
  red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0);
739
0
  if (red) {
740
0
    ospf_routemap_unset(red);
741
0
    ospf_redist_del(ospf, DEFAULT_ROUTE, 0);
742
0
    ospf_redistribute_default_set(ospf, DEFAULT_ORIGINATE_NONE, 0, 0);
743
0
  }
744
745
0
  for (ALL_LIST_ELEMENTS(ospf->areas, node, nnode, area))
746
0
    ospf_remove_vls_through_area(ospf, area);
747
748
0
  for (ALL_LIST_ELEMENTS(ospf->vlinks, node, nnode, vl_data))
749
0
    ospf_vl_delete(ospf, vl_data);
750
751
0
  list_delete(&ospf->vlinks);
752
753
  /* shutdown LDP-Sync */
754
0
  if (ospf->vrf_id == VRF_DEFAULT)
755
0
    ospf_ldp_sync_gbl_exit(ospf, true);
756
757
  /* Reset interface. */
758
0
  for (ALL_LIST_ELEMENTS(ospf->oiflist, node, nnode, oi))
759
0
    ospf_if_free(oi);
760
0
  list_delete(&ospf->oiflist);
761
0
  ospf->oi_running = 0;
762
763
  /* De-Register VRF */
764
0
  ospf_zebra_vrf_deregister(ospf);
765
766
  /* Clear static neighbors */
767
0
  for (rn = route_top(ospf->nbr_nbma); rn; rn = route_next(rn))
768
0
    if ((nbr_nbma = rn->info)) {
769
0
      EVENT_OFF(nbr_nbma->t_poll);
770
771
0
      if (nbr_nbma->nbr) {
772
0
        nbr_nbma->nbr->nbr_nbma = NULL;
773
0
        nbr_nbma->nbr = NULL;
774
0
      }
775
776
0
      if (nbr_nbma->oi) {
777
0
        listnode_delete(nbr_nbma->oi->nbr_nbma,
778
0
            nbr_nbma);
779
0
        nbr_nbma->oi = NULL;
780
0
      }
781
782
0
      XFREE(MTYPE_OSPF_NEIGHBOR_STATIC, nbr_nbma);
783
0
    }
784
785
0
  route_table_finish(ospf->nbr_nbma);
786
787
  /* Clear networks and Areas. */
788
0
  for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) {
789
0
    struct ospf_network *network;
790
791
0
    if ((network = rn->info) != NULL) {
792
0
      ospf_network_free(ospf, network);
793
0
      rn->info = NULL;
794
0
      route_unlock_node(rn);
795
0
    }
796
0
  }
797
0
  route_table_finish(ospf->networks);
798
799
0
  for (ALL_LIST_ELEMENTS(ospf->areas, node, nnode, area)) {
800
0
    listnode_delete(ospf->areas, area);
801
0
    ospf_area_free(area);
802
0
  }
803
804
0
  LSDB_LOOP (OPAQUE_AS_LSDB(ospf), rn, lsa)
805
0
    ospf_discard_from_db(ospf, ospf->lsdb, lsa);
806
0
  LSDB_LOOP (EXTERNAL_LSDB(ospf), rn, lsa)
807
0
    ospf_discard_from_db(ospf, ospf->lsdb, lsa);
808
809
0
  ospf_lsdb_delete_all(ospf->lsdb);
810
0
  ospf_lsdb_free(ospf->lsdb);
811
812
0
  for (rn = route_top(ospf->maxage_lsa); rn; rn = route_next(rn)) {
813
0
    if ((lsa = rn->info) != NULL) {
814
0
      ospf_lsa_unlock(&lsa);
815
0
      rn->info = NULL;
816
0
      route_unlock_node(rn);
817
0
    }
818
0
  }
819
0
  route_table_finish(ospf->maxage_lsa);
820
821
0
  if (ospf->old_table)
822
0
    ospf_route_table_free(ospf->old_table);
823
0
  if (ospf->new_table) {
824
0
    if (!ospf->gr_info.prepare_in_progress)
825
0
      ospf_route_delete(ospf, ospf->new_table);
826
0
    ospf_route_table_free(ospf->new_table);
827
0
  }
828
0
  if (ospf->oall_rtrs)
829
0
    ospf_rtrs_free(ospf->oall_rtrs);
830
0
  if (ospf->all_rtrs)
831
0
    ospf_rtrs_free(ospf->all_rtrs);
832
0
  if (ospf->old_rtrs)
833
0
    ospf_rtrs_free(ospf->old_rtrs);
834
0
  if (ospf->new_rtrs)
835
0
    ospf_rtrs_free(ospf->new_rtrs);
836
0
  if (ospf->new_external_route) {
837
0
    if (!ospf->gr_info.prepare_in_progress)
838
0
      ospf_route_delete(ospf, ospf->new_external_route);
839
0
    ospf_route_table_free(ospf->new_external_route);
840
0
  }
841
0
  if (ospf->old_external_route) {
842
0
    if (!ospf->gr_info.prepare_in_progress)
843
0
      ospf_route_delete(ospf, ospf->old_external_route);
844
0
    ospf_route_table_free(ospf->old_external_route);
845
0
  }
846
0
  if (ospf->external_lsas) {
847
0
    ospf_ase_external_lsas_finish(ospf->external_lsas);
848
0
  }
849
850
0
  for (i = ZEBRA_ROUTE_SYSTEM; i <= ZEBRA_ROUTE_MAX; i++) {
851
0
    struct list *ext_list;
852
0
    struct ospf_external *ext;
853
854
0
    ext_list = ospf->external[i];
855
0
    if (!ext_list)
856
0
      continue;
857
858
0
    for (ALL_LIST_ELEMENTS(ext_list, node, nnode, ext)) {
859
0
      if (ext->external_info)
860
0
        for (rn = route_top(ext->external_info); rn;
861
0
             rn = route_next(rn)) {
862
0
          if (rn->info == NULL)
863
0
            continue;
864
865
0
          XFREE(MTYPE_OSPF_EXTERNAL_INFO,
866
0
                rn->info);
867
0
          rn->info = NULL;
868
0
          route_unlock_node(rn);
869
0
        }
870
871
0
      ospf_external_del(ospf, i, ext->instance);
872
0
    }
873
0
  }
874
875
0
  ospf_distance_reset(ospf);
876
0
  route_table_finish(ospf->distance_table);
877
878
  /* Release extrenal Aggregator table */
879
0
  for (rn = route_top(ospf->rt_aggr_tbl); rn; rn = route_next(rn)) {
880
0
    struct ospf_external_aggr_rt *aggr;
881
882
0
    aggr = rn->info;
883
884
0
    if (aggr) {
885
0
      ospf_external_aggregator_free(aggr);
886
0
      rn->info = NULL;
887
0
      route_unlock_node(rn);
888
0
    }
889
0
  }
890
891
  /* Cancel all timers. */
892
0
  EVENT_OFF(ospf->t_read);
893
0
  EVENT_OFF(ospf->t_write);
894
0
  EVENT_OFF(ospf->t_spf_calc);
895
0
  EVENT_OFF(ospf->t_ase_calc);
896
0
  EVENT_OFF(ospf->t_maxage);
897
0
  EVENT_OFF(ospf->t_maxage_walker);
898
0
  EVENT_OFF(ospf->t_abr_task);
899
0
  EVENT_OFF(ospf->t_abr_fr);
900
0
  EVENT_OFF(ospf->t_asbr_check);
901
0
  EVENT_OFF(ospf->t_asbr_nssa_redist_update);
902
0
  EVENT_OFF(ospf->t_distribute_update);
903
0
  EVENT_OFF(ospf->t_lsa_refresher);
904
0
  EVENT_OFF(ospf->t_opaque_lsa_self);
905
0
  EVENT_OFF(ospf->t_sr_update);
906
0
  EVENT_OFF(ospf->t_default_routemap_timer);
907
0
  EVENT_OFF(ospf->t_external_aggr);
908
0
  EVENT_OFF(ospf->gr_info.t_grace_period);
909
910
0
  route_table_finish(ospf->rt_aggr_tbl);
911
912
0
  ospf_free_refresh_queue(ospf);
913
914
0
  list_delete(&ospf->areas);
915
0
  list_delete(&ospf->oi_write_q);
916
917
  /* Reset GR helper data structers */
918
0
  ospf_gr_helper_instance_stop(ospf);
919
920
0
  close(ospf->fd);
921
0
  stream_free(ospf->ibuf);
922
0
  ospf->fd = -1;
923
0
  ospf->max_multipath = MULTIPATH_NUM;
924
0
  ospf_delete(ospf);
925
926
0
  if (vrf)
927
0
    ospf_vrf_unlink(ospf, vrf);
928
929
0
  XFREE(MTYPE_OSPF_TOP, ospf->name);
930
0
  XFREE(MTYPE_OSPF_TOP, ospf);
931
0
}
932
933
934
/* allocate new OSPF Area object */
935
struct ospf_area *ospf_area_new(struct ospf *ospf, struct in_addr area_id)
936
1
{
937
1
  struct ospf_area *new;
938
939
  /* Allocate new config_network. */
940
1
  new = XCALLOC(MTYPE_OSPF_AREA, sizeof(struct ospf_area));
941
942
1
  new->ospf = ospf;
943
944
1
  new->area_id = area_id;
945
1
  new->area_id_fmt = OSPF_AREA_ID_FMT_DOTTEDQUAD;
946
947
1
  new->external_routing = OSPF_AREA_DEFAULT;
948
1
  new->default_cost = 1;
949
1
  new->auth_type = OSPF_AUTH_NULL;
950
951
  /* New LSDB init. */
952
1
  new->lsdb = ospf_lsdb_new();
953
954
  /* Self-originated LSAs initialize. */
955
1
  new->router_lsa_self = NULL;
956
957
  /* Initialize FR field */
958
1
  new->fr_info.enabled = false;
959
1
  new->fr_info.configured = false;
960
1
  new->fr_info.state_changed = false;
961
1
  new->fr_info.router_lsas_recv_dc_bit = 0;
962
1
  new->fr_info.indication_lsa_self = NULL;
963
1
  new->fr_info.area_ind_lsa_recvd = false;
964
1
  new->fr_info.area_dc_clear = false;
965
966
1
  ospf_opaque_type10_lsa_init(new);
967
968
1
  new->oiflist = list_new();
969
1
  new->ranges = route_table_init();
970
1
  new->nssa_ranges = route_table_init();
971
972
1
  if (area_id.s_addr == OSPF_AREA_BACKBONE)
973
1
    ospf->backbone = new;
974
975
1
  return new;
976
1
}
977
978
void ospf_area_lsdb_discard_delete(struct ospf_area *area)
979
0
{
980
0
  struct route_node *rn;
981
0
  struct ospf_lsa *lsa;
982
983
0
  LSDB_LOOP (ROUTER_LSDB(area), rn, lsa)
984
0
    ospf_discard_from_db(area->ospf, area->lsdb, lsa);
985
0
  LSDB_LOOP (NETWORK_LSDB(area), rn, lsa)
986
0
    ospf_discard_from_db(area->ospf, area->lsdb, lsa);
987
0
  LSDB_LOOP (SUMMARY_LSDB(area), rn, lsa)
988
0
    ospf_discard_from_db(area->ospf, area->lsdb, lsa);
989
0
  LSDB_LOOP (ASBR_SUMMARY_LSDB(area), rn, lsa)
990
0
    ospf_discard_from_db(area->ospf, area->lsdb, lsa);
991
992
0
  LSDB_LOOP (NSSA_LSDB(area), rn, lsa)
993
0
    ospf_discard_from_db(area->ospf, area->lsdb, lsa);
994
0
  LSDB_LOOP (OPAQUE_AREA_LSDB(area), rn, lsa)
995
0
    ospf_discard_from_db(area->ospf, area->lsdb, lsa);
996
0
  LSDB_LOOP (OPAQUE_LINK_LSDB(area), rn, lsa)
997
0
    ospf_discard_from_db(area->ospf, area->lsdb, lsa);
998
999
0
  ospf_lsdb_delete_all(area->lsdb);
1000
0
}
1001
1002
static void ospf_area_free(struct ospf_area *area)
1003
0
{
1004
0
  ospf_opaque_type10_lsa_term(area);
1005
1006
  /* Free LSDBs. */
1007
0
  ospf_area_lsdb_discard_delete(area);
1008
1009
0
  ospf_lsdb_free(area->lsdb);
1010
1011
0
  ospf_lsa_unlock(&area->router_lsa_self);
1012
1013
0
  route_table_finish(area->ranges);
1014
0
  route_table_finish(area->nssa_ranges);
1015
0
  list_delete(&area->oiflist);
1016
1017
0
  if (EXPORT_NAME(area))
1018
0
    free(EXPORT_NAME(area));
1019
1020
0
  if (IMPORT_NAME(area))
1021
0
    free(IMPORT_NAME(area));
1022
1023
  /* Cancel timer. */
1024
0
  EVENT_OFF(area->t_stub_router);
1025
0
  EVENT_OFF(area->t_opaque_lsa_self);
1026
1027
0
  if (OSPF_IS_AREA_BACKBONE(area))
1028
0
    area->ospf->backbone = NULL;
1029
1030
0
  XFREE(MTYPE_OSPF_AREA, area);
1031
0
}
1032
1033
void ospf_area_check_free(struct ospf *ospf, struct in_addr area_id)
1034
0
{
1035
0
  struct ospf_area *area;
1036
1037
0
  area = ospf_area_lookup_by_area_id(ospf, area_id);
1038
0
  if (area && listcount(area->oiflist) == 0 &&
1039
0
      area->ranges->top == NULL && area->nssa_ranges->top == NULL &&
1040
0
      !ospf_vl_count(ospf, area) &&
1041
0
      area->shortcut_configured == OSPF_SHORTCUT_DEFAULT &&
1042
0
      area->external_routing == OSPF_AREA_DEFAULT &&
1043
0
      area->no_summary == 0 && area->default_cost == 1 &&
1044
0
      EXPORT_NAME(area) == NULL && IMPORT_NAME(area) == NULL &&
1045
0
      area->auth_type == OSPF_AUTH_NULL) {
1046
0
    listnode_delete(ospf->areas, area);
1047
0
    ospf_area_free(area);
1048
0
  }
1049
0
}
1050
1051
struct ospf_area *ospf_area_get(struct ospf *ospf, struct in_addr area_id)
1052
0
{
1053
0
  struct ospf_area *area;
1054
1055
0
  area = ospf_area_lookup_by_area_id(ospf, area_id);
1056
0
  if (!area) {
1057
0
    area = ospf_area_new(ospf, area_id);
1058
0
    listnode_add_sort(ospf->areas, area);
1059
0
    ospf_check_abr_status(ospf);
1060
0
    if (ospf->stub_router_admin_set
1061
0
        == OSPF_STUB_ROUTER_ADMINISTRATIVE_SET) {
1062
0
      SET_FLAG(area->stub_router_state,
1063
0
         OSPF_AREA_ADMIN_STUB_ROUTED);
1064
0
    }
1065
0
  }
1066
1067
0
  return area;
1068
0
}
1069
1070
struct ospf_area *ospf_area_lookup_by_area_id(struct ospf *ospf,
1071
                struct in_addr area_id)
1072
0
{
1073
0
  struct ospf_area *area;
1074
0
  struct listnode *node;
1075
1076
0
  for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area))
1077
0
    if (IPV4_ADDR_SAME(&area->area_id, &area_id))
1078
0
      return area;
1079
1080
0
  return NULL;
1081
0
}
1082
1083
void ospf_area_add_if(struct ospf_area *area, struct ospf_interface *oi)
1084
1
{
1085
1
  listnode_add(area->oiflist, oi);
1086
1
}
1087
1088
void ospf_area_del_if(struct ospf_area *area, struct ospf_interface *oi)
1089
0
{
1090
0
  listnode_delete(area->oiflist, oi);
1091
0
}
1092
1093
1094
struct ospf_interface *add_ospf_interface(struct connected *co,
1095
            struct ospf_area *area)
1096
1
{
1097
1
  struct ospf_interface *oi;
1098
1099
1
  oi = ospf_if_new(area->ospf, co->ifp, co->address);
1100
1
  oi->connected = co;
1101
1102
1
  oi->area = area;
1103
1104
1
  oi->params = ospf_lookup_if_params(co->ifp, oi->address->u.prefix4);
1105
1
  oi->output_cost = ospf_if_get_output_cost(oi);
1106
1107
  /* Relate ospf interface to ospf instance. */
1108
1
  oi->ospf = area->ospf;
1109
1110
  /* update network type as interface flag */
1111
  /* If network type is specified previously,
1112
     skip network type setting. */
1113
1
  oi->type = IF_DEF_PARAMS(co->ifp)->type;
1114
1
  oi->ptp_dmvpn = IF_DEF_PARAMS(co->ifp)->ptp_dmvpn;
1115
1
  oi->p2mp_delay_reflood = IF_DEF_PARAMS(co->ifp)->p2mp_delay_reflood;
1116
1117
  /* Add pseudo neighbor. */
1118
1
  ospf_nbr_self_reset(oi, oi->ospf->router_id);
1119
1120
1
  ospf_area_add_if(oi->area, oi);
1121
1122
  /* if LDP-IGP Sync is configured globally inherit config */
1123
1
  ospf_ldp_sync_if_init(oi);
1124
1125
  /*
1126
   * if router_id is not configured, don't bring up
1127
   * interfaces.
1128
   * ospf_router_id_update() will call ospf_if_update
1129
   * whenever r-id is configured instead.
1130
   */
1131
1
  if ((area->ospf->router_id.s_addr != INADDR_ANY)
1132
0
      && if_is_operative(co->ifp))
1133
0
    ospf_if_up(oi);
1134
1135
  /*
1136
   * RFC 3623 - Section 5 ("Unplanned Outages"):
1137
   * "The grace-LSAs are encapsulated in Link State Update Packets
1138
   * and sent out to all interfaces, even though the restarted
1139
   * router has no adjacencies and no knowledge of previous
1140
   * adjacencies".
1141
   */
1142
1
  if (oi->ospf->gr_info.restart_in_progress &&
1143
0
      oi->ospf->gr_info.reason == OSPF_GR_UNKNOWN_RESTART)
1144
0
    ospf_gr_unplanned_start_interface(oi);
1145
1146
1
  return oi;
1147
1
}
1148
1149
static void update_redistributed(struct ospf *ospf, int add_to_ospf)
1150
0
{
1151
0
  struct route_node *rn;
1152
0
  struct external_info *ei;
1153
0
  struct ospf_external *ext;
1154
1155
0
  if (ospf_is_type_redistributed(ospf, ZEBRA_ROUTE_CONNECT, 0)) {
1156
0
    ext = ospf_external_lookup(ospf, ZEBRA_ROUTE_CONNECT, 0);
1157
0
    if ((ext) && EXTERNAL_INFO(ext)) {
1158
0
      for (rn = route_top(EXTERNAL_INFO(ext)); rn;
1159
0
           rn = route_next(rn)) {
1160
0
        ei = rn->info;
1161
0
        if (ei == NULL)
1162
0
          continue;
1163
1164
0
        if (add_to_ospf) {
1165
0
          if (ospf_external_info_find_lsa(ospf,
1166
0
                  &ei->p))
1167
0
            if (!ospf_redistribute_check(
1168
0
                  ospf, ei, NULL))
1169
0
              ospf_external_lsa_flush(
1170
0
                ospf, ei->type,
1171
0
                &ei->p,
1172
0
                ei->ifindex /*, ei->nexthop */);
1173
0
        } else {
1174
0
          if (!ospf_external_info_find_lsa(
1175
0
                ospf, &ei->p))
1176
0
            if (ospf_redistribute_check(
1177
0
                  ospf, ei, NULL))
1178
0
              ospf_external_lsa_originate(
1179
0
                ospf, ei);
1180
0
        }
1181
0
      }
1182
0
    }
1183
0
  }
1184
0
}
1185
1186
/* Config network statement related functions. */
1187
static struct ospf_network *ospf_network_new(struct in_addr area_id)
1188
0
{
1189
0
  struct ospf_network *new;
1190
0
  new = XCALLOC(MTYPE_OSPF_NETWORK, sizeof(struct ospf_network));
1191
1192
0
  new->area_id = area_id;
1193
0
  new->area_id_fmt = OSPF_AREA_ID_FMT_DOTTEDQUAD;
1194
1195
0
  return new;
1196
0
}
1197
1198
static void ospf_network_free(struct ospf *ospf, struct ospf_network *network)
1199
0
{
1200
0
  ospf_area_check_free(ospf, network->area_id);
1201
0
  ospf_schedule_abr_task(ospf);
1202
0
  XFREE(MTYPE_OSPF_NETWORK, network);
1203
0
}
1204
1205
int ospf_network_set(struct ospf *ospf, struct prefix_ipv4 *p,
1206
         struct in_addr area_id, int df)
1207
0
{
1208
0
  struct ospf_network *network;
1209
0
  struct ospf_area *area;
1210
0
  struct route_node *rn;
1211
1212
0
  rn = route_node_get(ospf->networks, (struct prefix *)p);
1213
0
  if (rn->info) {
1214
0
    network = rn->info;
1215
0
    route_unlock_node(rn);
1216
1217
0
    if (IPV4_ADDR_SAME(&area_id, &network->area_id)) {
1218
0
      return 1;
1219
0
    } else {
1220
      /* There is already same network statement. */
1221
0
      return 0;
1222
0
    }
1223
0
  }
1224
1225
0
  rn->info = network = ospf_network_new(area_id);
1226
0
  network->area_id_fmt = df;
1227
0
  area = ospf_area_get(ospf, area_id);
1228
0
  ospf_area_display_format_set(ospf, area, df);
1229
1230
  /* Run network config now. */
1231
0
  ospf_network_run((struct prefix *)p, area);
1232
1233
  /* Update connected redistribute. */
1234
0
  update_redistributed(ospf, 1); /* interfaces possibly added */
1235
1236
0
  ospf_area_check_free(ospf, area_id);
1237
1238
0
  return 1;
1239
0
}
1240
1241
int ospf_network_unset(struct ospf *ospf, struct prefix_ipv4 *p,
1242
           struct in_addr area_id)
1243
0
{
1244
0
  struct route_node *rn;
1245
0
  struct ospf_network *network;
1246
0
  struct listnode *node, *nnode;
1247
0
  struct ospf_interface *oi;
1248
1249
0
  rn = route_node_lookup(ospf->networks, (struct prefix *)p);
1250
0
  if (rn == NULL)
1251
0
    return 0;
1252
1253
0
  network = rn->info;
1254
0
  route_unlock_node(rn);
1255
0
  if (!IPV4_ADDR_SAME(&area_id, &network->area_id))
1256
0
    return 0;
1257
1258
0
  ospf_network_free(ospf, rn->info);
1259
0
  rn->info = NULL;
1260
0
  route_unlock_node(rn); /* initial reference */
1261
1262
  /* Find interfaces that are not configured already.  */
1263
0
  for (ALL_LIST_ELEMENTS(ospf->oiflist, node, nnode, oi)) {
1264
1265
0
    if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
1266
0
      continue;
1267
1268
0
    ospf_network_run_subnet(ospf, oi->connected, NULL, NULL);
1269
0
  }
1270
1271
  /* Update connected redistribute. */
1272
0
  update_redistributed(ospf, 0); /* interfaces possibly removed */
1273
0
  ospf_area_check_free(ospf, area_id);
1274
1275
0
  return 1;
1276
0
}
1277
1278
/* Ensure there's an OSPF instance, as "ip ospf area" enabled OSPF means
1279
 * there might not be any 'router ospf' config.
1280
 *
1281
 * Otherwise, doesn't do anything different to ospf_if_update for now
1282
 */
1283
void ospf_interface_area_set(struct ospf *ospf, struct interface *ifp)
1284
0
{
1285
0
  if (!ospf)
1286
0
    return;
1287
1288
0
  ospf_if_update(ospf, ifp);
1289
  /* if_update does a update_redistributed */
1290
1291
0
  return;
1292
0
}
1293
1294
void ospf_interface_area_unset(struct ospf *ospf, struct interface *ifp)
1295
0
{
1296
0
  struct route_node *rn_oi;
1297
1298
0
  if (!ospf)
1299
0
    return; /* Ospf not ready yet */
1300
1301
  /* Find interfaces that may need to be removed. */
1302
0
  for (rn_oi = route_top(IF_OIFS(ifp)); rn_oi;
1303
0
       rn_oi = route_next(rn_oi)) {
1304
0
    struct ospf_interface *oi = NULL;
1305
1306
0
    if ((oi = rn_oi->info) == NULL)
1307
0
      continue;
1308
1309
0
    if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
1310
0
      continue;
1311
1312
0
    ospf_network_run_subnet(ospf, oi->connected, NULL, NULL);
1313
0
  }
1314
1315
  /* Update connected redistribute. */
1316
0
  update_redistributed(ospf, 0); /* interfaces possibly removed */
1317
0
}
1318
1319
/* Check whether interface matches given network
1320
 * returns: 1, true. 0, false
1321
 */
1322
static int ospf_network_match_iface(const struct connected *co,
1323
            const struct prefix *net)
1324
0
{
1325
  /* new approach: more elegant and conceptually clean */
1326
0
  return prefix_match_network_statement(net, CONNECTED_PREFIX(co));
1327
0
}
1328
1329
static void ospf_update_interface_area(struct connected *co,
1330
               struct ospf_area *area)
1331
0
{
1332
0
  struct ospf_interface *oi = ospf_if_table_lookup(co->ifp, co->address);
1333
1334
  /* nothing to be done case */
1335
0
  if (oi && oi->area == area) {
1336
0
    return;
1337
0
  }
1338
1339
0
  if (oi)
1340
0
    ospf_if_free(oi);
1341
1342
0
  add_ospf_interface(co, area);
1343
0
}
1344
1345
/* Run OSPF for the given subnet, taking into account the following
1346
 * possible sources of area configuration, in the given order of preference:
1347
 *
1348
 * - Whether there is interface+address specific area configuration
1349
 * - Whether there is a default area for the interface
1350
 * - Whether there is an area given as a parameter.
1351
 * - If no specific network prefix/area is supplied, whether there's
1352
 *   a matching network configured.
1353
 */
1354
static void ospf_network_run_subnet(struct ospf *ospf, struct connected *co,
1355
            struct prefix *p,
1356
            struct ospf_area *given_area)
1357
0
{
1358
0
  struct ospf_interface *oi;
1359
0
  struct ospf_if_params *params;
1360
0
  struct ospf_area *area = NULL;
1361
0
  struct route_node *rn;
1362
0
  int configed = 0;
1363
1364
0
  if (CHECK_FLAG(co->flags, ZEBRA_IFA_SECONDARY))
1365
0
    return;
1366
1367
0
  if (co->address->family != AF_INET)
1368
0
    return;
1369
1370
  /* Try determine the appropriate area for this interface + address
1371
   * Start by checking interface config
1372
   */
1373
0
  params = ospf_lookup_if_params(co->ifp, co->address->u.prefix4);
1374
0
  if (params && OSPF_IF_PARAM_CONFIGURED(params, if_area))
1375
0
    area = ospf_area_get(ospf, params->if_area);
1376
0
  else {
1377
0
    params = IF_DEF_PARAMS(co->ifp);
1378
0
    if (OSPF_IF_PARAM_CONFIGURED(params, if_area))
1379
0
      area = ospf_area_get(ospf, params->if_area);
1380
0
  }
1381
1382
  /* If we've found an interface and/or addr specific area, then we're
1383
   * done
1384
   */
1385
0
  if (area) {
1386
0
    ospf_update_interface_area(co, area);
1387
0
    return;
1388
0
  }
1389
1390
  /* Otherwise, only remaining possibility is a matching network statement
1391
   */
1392
0
  if (p) {
1393
0
    assert(given_area != NULL);
1394
1395
    /* Which either was supplied as a parameter.. (e.g. cause a new
1396
     * network/area was just added)..
1397
     */
1398
0
    if (p->family == co->address->family
1399
0
        && ospf_network_match_iface(co, p))
1400
0
      ospf_update_interface_area(co, given_area);
1401
1402
0
    return;
1403
0
  }
1404
1405
  /* Else we have to search the existing network/area config to see
1406
   * if any match..
1407
   */
1408
0
  for (rn = route_top(ospf->networks); rn; rn = route_next(rn))
1409
0
    if (rn->info != NULL && ospf_network_match_iface(co, &rn->p)) {
1410
0
      struct ospf_network *network =
1411
0
        (struct ospf_network *)rn->info;
1412
0
      area = ospf_area_get(ospf, network->area_id);
1413
0
      ospf_update_interface_area(co, area);
1414
0
      configed = 1;
1415
0
    }
1416
1417
  /* If the subnet isn't in any area, deconfigure */
1418
0
  if (!configed && (oi = ospf_if_table_lookup(co->ifp, co->address)))
1419
0
    ospf_if_free(oi);
1420
0
}
1421
1422
static void ospf_network_run_interface(struct ospf *ospf, struct interface *ifp,
1423
               struct prefix *p,
1424
               struct ospf_area *given_area)
1425
0
{
1426
0
  struct listnode *cnode;
1427
0
  struct connected *co;
1428
1429
0
  if (memcmp(ifp->name, "VLINK", 5) == 0)
1430
0
    return;
1431
1432
  /* Network prefix without area is nonsensical */
1433
0
  if (p)
1434
0
    assert(given_area != NULL);
1435
1436
  /* if interface prefix is match specified prefix,
1437
     then create socket and join multicast group. */
1438
0
  for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, co))
1439
0
    ospf_network_run_subnet(ospf, co, p, given_area);
1440
0
}
1441
1442
static void ospf_network_run(struct prefix *p, struct ospf_area *area)
1443
0
{
1444
0
  struct vrf *vrf = vrf_lookup_by_id(area->ospf->vrf_id);
1445
0
  struct interface *ifp;
1446
1447
  /* Schedule Router ID Update. */
1448
0
  if (area->ospf->router_id.s_addr == INADDR_ANY)
1449
0
    ospf_router_id_update(area->ospf);
1450
1451
  /* Get target interface. */
1452
0
  FOR_ALL_INTERFACES (vrf, ifp)
1453
0
    ospf_network_run_interface(area->ospf, ifp, p, area);
1454
0
}
1455
1456
void ospf_ls_upd_queue_empty(struct ospf_interface *oi)
1457
0
{
1458
0
  struct route_node *rn;
1459
0
  struct listnode *node, *nnode;
1460
0
  struct list *lst;
1461
0
  struct ospf_lsa *lsa;
1462
1463
  /* empty ls update queue */
1464
0
  for (rn = route_top(oi->ls_upd_queue); rn; rn = route_next(rn))
1465
0
    if ((lst = (struct list *)rn->info)) {
1466
0
      for (ALL_LIST_ELEMENTS(lst, node, nnode, lsa))
1467
0
        ospf_lsa_unlock(&lsa); /* oi->ls_upd_queue */
1468
0
      list_delete(&lst);
1469
0
      rn->info = NULL;
1470
0
    }
1471
1472
  /* remove update event */
1473
0
  EVENT_OFF(oi->t_ls_upd_event);
1474
0
}
1475
1476
void ospf_if_update(struct ospf *ospf, struct interface *ifp)
1477
0
{
1478
1479
0
  if (!ospf)
1480
0
    return;
1481
1482
0
  if (IS_DEBUG_OSPF_EVENT)
1483
0
    zlog_debug(
1484
0
      "%s: interface %s vrf %s(%u) ospf vrf %s vrf_id %u router_id %pI4",
1485
0
      __func__, ifp->name, ifp->vrf->name, ifp->vrf->vrf_id,
1486
0
      ospf_vrf_id_to_name(ospf->vrf_id), ospf->vrf_id,
1487
0
      &ospf->router_id);
1488
1489
  /* OSPF must be ready. */
1490
0
  if (!ospf_is_ready(ospf))
1491
0
    return;
1492
1493
0
  ospf_network_run_interface(ospf, ifp, NULL, NULL);
1494
1495
  /* Update connected redistribute. */
1496
0
  update_redistributed(ospf, 1);
1497
1498
0
}
1499
1500
void ospf_remove_vls_through_area(struct ospf *ospf, struct ospf_area *area)
1501
0
{
1502
0
  struct listnode *node, *nnode;
1503
0
  struct ospf_vl_data *vl_data;
1504
1505
0
  for (ALL_LIST_ELEMENTS(ospf->vlinks, node, nnode, vl_data))
1506
0
    if (IPV4_ADDR_SAME(&vl_data->vl_area_id, &area->area_id))
1507
0
      ospf_vl_delete(ospf, vl_data);
1508
0
}
1509
1510
1511
static const struct message ospf_area_type_msg[] = {
1512
  {OSPF_AREA_DEFAULT, "Default"},
1513
  {OSPF_AREA_STUB, "Stub"},
1514
  {OSPF_AREA_NSSA, "NSSA"},
1515
  {0}};
1516
1517
static void ospf_area_type_set(struct ospf_area *area, int type)
1518
0
{
1519
0
  struct listnode *node;
1520
0
  struct ospf_interface *oi;
1521
1522
0
  if (area->external_routing == type) {
1523
0
    if (IS_DEBUG_OSPF_EVENT)
1524
0
      zlog_debug("Area[%pI4]: Types are the same, ignored.",
1525
0
           &area->area_id);
1526
0
    return;
1527
0
  }
1528
1529
0
  area->external_routing = type;
1530
1531
0
  if (IS_DEBUG_OSPF_EVENT)
1532
0
    zlog_debug("Area[%pI4]: Configured as %s",
1533
0
         &area->area_id,
1534
0
         lookup_msg(ospf_area_type_msg, type, NULL));
1535
1536
0
  switch (area->external_routing) {
1537
0
  case OSPF_AREA_DEFAULT:
1538
0
    for (ALL_LIST_ELEMENTS_RO(area->oiflist, node, oi))
1539
0
      if (oi->nbr_self != NULL) {
1540
0
        UNSET_FLAG(oi->nbr_self->options,
1541
0
             OSPF_OPTION_NP);
1542
0
        SET_FLAG(oi->nbr_self->options, OSPF_OPTION_E);
1543
0
      }
1544
0
    break;
1545
0
  case OSPF_AREA_STUB:
1546
0
    for (ALL_LIST_ELEMENTS_RO(area->oiflist, node, oi))
1547
0
      if (oi->nbr_self != NULL) {
1548
0
        if (IS_DEBUG_OSPF_EVENT)
1549
0
          zlog_debug(
1550
0
            "setting options on %s accordingly",
1551
0
            IF_NAME(oi));
1552
0
        UNSET_FLAG(oi->nbr_self->options,
1553
0
             OSPF_OPTION_NP);
1554
0
        UNSET_FLAG(oi->nbr_self->options,
1555
0
             OSPF_OPTION_E);
1556
0
        if (IS_DEBUG_OSPF_EVENT)
1557
0
          zlog_debug("options set on %s: %x",
1558
0
               IF_NAME(oi), OPTIONS(oi));
1559
0
      }
1560
0
    break;
1561
0
  case OSPF_AREA_NSSA:
1562
0
    for (ALL_LIST_ELEMENTS_RO(area->oiflist, node, oi))
1563
0
      if (oi->nbr_self != NULL) {
1564
0
        zlog_debug(
1565
0
          "setting nssa options on %s accordingly",
1566
0
          IF_NAME(oi));
1567
0
        UNSET_FLAG(oi->nbr_self->options,
1568
0
             OSPF_OPTION_E);
1569
0
        SET_FLAG(oi->nbr_self->options, OSPF_OPTION_NP);
1570
0
        zlog_debug("options set on %s: %x", IF_NAME(oi),
1571
0
             OPTIONS(oi));
1572
0
      }
1573
0
    break;
1574
0
  default:
1575
0
    break;
1576
0
  }
1577
1578
0
  ospf_router_lsa_update_area(area);
1579
0
  ospf_schedule_abr_task(area->ospf);
1580
0
}
1581
1582
int ospf_area_shortcut_set(struct ospf *ospf, struct ospf_area *area, int mode)
1583
0
{
1584
0
  if (area->shortcut_configured == mode)
1585
0
    return 0;
1586
1587
0
  area->shortcut_configured = mode;
1588
0
  ospf_router_lsa_update_area(area);
1589
0
  ospf_schedule_abr_task(ospf);
1590
1591
0
  ospf_area_check_free(ospf, area->area_id);
1592
1593
0
  return 1;
1594
0
}
1595
1596
int ospf_area_shortcut_unset(struct ospf *ospf, struct ospf_area *area)
1597
0
{
1598
0
  area->shortcut_configured = OSPF_SHORTCUT_DEFAULT;
1599
0
  ospf_router_lsa_update_area(area);
1600
0
  ospf_area_check_free(ospf, area->area_id);
1601
0
  ospf_schedule_abr_task(ospf);
1602
1603
0
  return 1;
1604
0
}
1605
1606
static int ospf_area_vlink_count(struct ospf *ospf, struct ospf_area *area)
1607
0
{
1608
0
  struct ospf_vl_data *vl;
1609
0
  struct listnode *node;
1610
0
  int count = 0;
1611
1612
0
  for (ALL_LIST_ELEMENTS_RO(ospf->vlinks, node, vl))
1613
0
    if (IPV4_ADDR_SAME(&vl->vl_area_id, &area->area_id))
1614
0
      count++;
1615
1616
0
  return count;
1617
0
}
1618
1619
int ospf_area_display_format_set(struct ospf *ospf, struct ospf_area *area,
1620
         int df)
1621
0
{
1622
0
  area->area_id_fmt = df;
1623
1624
0
  return 1;
1625
0
}
1626
1627
int ospf_area_stub_set(struct ospf *ospf, struct in_addr area_id)
1628
0
{
1629
0
  struct ospf_area *area;
1630
1631
0
  area = ospf_area_get(ospf, area_id);
1632
0
  if (ospf_area_vlink_count(ospf, area))
1633
0
    return 0;
1634
1635
0
  if (area->external_routing != OSPF_AREA_STUB)
1636
0
    ospf_area_type_set(area, OSPF_AREA_STUB);
1637
1638
0
  return 1;
1639
0
}
1640
1641
int ospf_area_stub_unset(struct ospf *ospf, struct in_addr area_id)
1642
0
{
1643
0
  struct ospf_area *area;
1644
1645
0
  area = ospf_area_lookup_by_area_id(ospf, area_id);
1646
0
  if (area == NULL)
1647
0
    return 1;
1648
1649
0
  if (area->external_routing == OSPF_AREA_STUB)
1650
0
    ospf_area_type_set(area, OSPF_AREA_DEFAULT);
1651
1652
0
  ospf_area_check_free(ospf, area_id);
1653
1654
0
  return 1;
1655
0
}
1656
1657
int ospf_area_no_summary_set(struct ospf *ospf, struct in_addr area_id)
1658
0
{
1659
0
  struct ospf_area *area;
1660
1661
0
  area = ospf_area_get(ospf, area_id);
1662
0
  area->no_summary = 1;
1663
1664
0
  return 1;
1665
0
}
1666
1667
int ospf_area_no_summary_unset(struct ospf *ospf, struct in_addr area_id)
1668
0
{
1669
0
  struct ospf_area *area;
1670
1671
0
  area = ospf_area_lookup_by_area_id(ospf, area_id);
1672
0
  if (area == NULL)
1673
0
    return 0;
1674
1675
0
  area->no_summary = 0;
1676
0
  ospf_area_check_free(ospf, area_id);
1677
1678
0
  return 1;
1679
0
}
1680
1681
int ospf_area_nssa_no_summary_set(struct ospf *ospf, struct in_addr area_id)
1682
0
{
1683
0
  struct ospf_area *area;
1684
1685
0
  area = ospf_area_get(ospf, area_id);
1686
0
  if (ospf_area_vlink_count(ospf, area))
1687
0
    return 0;
1688
1689
0
  if (area->external_routing != OSPF_AREA_NSSA) {
1690
0
    ospf_area_type_set(area, OSPF_AREA_NSSA);
1691
0
    ospf->anyNSSA++;
1692
0
    area->NSSATranslatorRole = OSPF_NSSA_ROLE_CANDIDATE;
1693
0
  }
1694
1695
0
  ospf_area_no_summary_set(ospf, area_id);
1696
1697
0
  return 1;
1698
0
}
1699
1700
int ospf_area_nssa_set(struct ospf *ospf, struct in_addr area_id)
1701
0
{
1702
0
  struct ospf_area *area;
1703
1704
0
  area = ospf_area_get(ospf, area_id);
1705
0
  if (ospf_area_vlink_count(ospf, area))
1706
0
    return 0;
1707
1708
0
  if (area->external_routing != OSPF_AREA_NSSA) {
1709
0
    ospf_area_type_set(area, OSPF_AREA_NSSA);
1710
0
    ospf->anyNSSA++;
1711
1712
    /* set NSSA area defaults */
1713
0
    area->no_summary = 0;
1714
0
    area->suppress_fa = 0;
1715
0
    area->NSSATranslatorRole = OSPF_NSSA_ROLE_CANDIDATE;
1716
0
    area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED;
1717
0
    area->NSSATranslatorStabilityInterval =
1718
0
      OSPF_NSSA_TRANS_STABLE_DEFAULT;
1719
0
  }
1720
0
  return 1;
1721
0
}
1722
1723
int ospf_area_nssa_unset(struct ospf *ospf, struct in_addr area_id)
1724
0
{
1725
0
  struct ospf_area *area;
1726
1727
0
  area = ospf_area_lookup_by_area_id(ospf, area_id);
1728
0
  if (area == NULL)
1729
0
    return 0;
1730
1731
0
  ospf->anyNSSA--;
1732
  /* set NSSA area defaults */
1733
0
  area->no_summary = 0;
1734
0
  area->suppress_fa = 0;
1735
0
  area->NSSATranslatorRole = OSPF_NSSA_ROLE_CANDIDATE;
1736
0
  area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED;
1737
0
  area->NSSATranslatorStabilityInterval = OSPF_NSSA_TRANS_STABLE_DEFAULT;
1738
0
  ospf_area_type_set(area, OSPF_AREA_DEFAULT);
1739
0
  ospf_area_check_free(ospf, area_id);
1740
1741
0
  return 1;
1742
0
}
1743
1744
int ospf_area_nssa_suppress_fa_set(struct ospf *ospf, struct in_addr area_id)
1745
0
{
1746
0
  struct ospf_area *area;
1747
1748
0
  area = ospf_area_lookup_by_area_id(ospf, area_id);
1749
0
  if (area == NULL)
1750
0
    return 0;
1751
1752
0
  area->suppress_fa = 1;
1753
1754
0
  return 1;
1755
0
}
1756
1757
int ospf_area_nssa_suppress_fa_unset(struct ospf *ospf, struct in_addr area_id)
1758
0
{
1759
0
  struct ospf_area *area;
1760
1761
0
  area = ospf_area_lookup_by_area_id(ospf, area_id);
1762
0
  if (area == NULL)
1763
0
    return 0;
1764
1765
0
  area->suppress_fa = 0;
1766
1767
0
  return 1;
1768
0
}
1769
1770
int ospf_area_nssa_translator_role_set(struct ospf *ospf,
1771
               struct in_addr area_id, int role)
1772
0
{
1773
0
  struct ospf_area *area;
1774
1775
0
  area = ospf_area_lookup_by_area_id(ospf, area_id);
1776
0
  if (area == NULL)
1777
0
    return 0;
1778
1779
0
  if (role != area->NSSATranslatorRole) {
1780
0
    if ((area->NSSATranslatorRole == OSPF_NSSA_ROLE_ALWAYS)
1781
0
        || (role == OSPF_NSSA_ROLE_ALWAYS)) {
1782
      /* RFC 3101 3.1
1783
       * if new role is OSPF_NSSA_ROLE_ALWAYS we need to set
1784
       * Nt bit, if the role was OSPF_NSSA_ROLE_ALWAYS we need
1785
       * to clear Nt bit
1786
       */
1787
0
      area->NSSATranslatorRole = role;
1788
0
      ospf_router_lsa_update_area(area);
1789
0
    } else
1790
0
      area->NSSATranslatorRole = role;
1791
0
  }
1792
1793
0
  return 1;
1794
0
}
1795
1796
void ospf_area_nssa_default_originate_set(struct ospf *ospf,
1797
            struct in_addr area_id, int metric,
1798
            int metric_type)
1799
0
{
1800
0
  struct ospf_area *area;
1801
1802
0
  area = ospf_area_lookup_by_area_id(ospf, area_id);
1803
0
  if (area == NULL)
1804
0
    return;
1805
1806
0
  if (!area->nssa_default_originate.enabled) {
1807
0
    area->nssa_default_originate.enabled = true;
1808
0
    if (++ospf->nssa_default_import_check.refcnt == 1) {
1809
0
      ospf->nssa_default_import_check.status = false;
1810
0
      ospf_zebra_import_default_route(ospf, false);
1811
0
    }
1812
0
  }
1813
1814
0
  area->nssa_default_originate.metric_value = metric;
1815
0
  area->nssa_default_originate.metric_type = metric_type;
1816
0
}
1817
1818
void ospf_area_nssa_default_originate_unset(struct ospf *ospf,
1819
              struct in_addr area_id)
1820
0
{
1821
0
  struct ospf_area *area;
1822
1823
0
  area = ospf_area_lookup_by_area_id(ospf, area_id);
1824
0
  if (area == NULL)
1825
0
    return;
1826
1827
0
  if (area->nssa_default_originate.enabled) {
1828
0
    area->nssa_default_originate.enabled = false;
1829
0
    if (--ospf->nssa_default_import_check.refcnt == 0) {
1830
0
      ospf->nssa_default_import_check.status = false;
1831
0
      ospf_zebra_import_default_route(ospf, true);
1832
0
    }
1833
0
    area->nssa_default_originate.metric_value = -1;
1834
0
    area->nssa_default_originate.metric_type = -1;
1835
1836
0
    if (!IS_OSPF_ABR(ospf))
1837
0
      ospf_abr_nssa_type7_defaults(ospf);
1838
0
  }
1839
0
}
1840
1841
int ospf_area_export_list_set(struct ospf *ospf, struct ospf_area *area,
1842
            const char *list_name)
1843
0
{
1844
0
  struct access_list *list;
1845
0
  list = access_list_lookup(AFI_IP, list_name);
1846
1847
0
  EXPORT_LIST(area) = list;
1848
1849
0
  if (EXPORT_NAME(area))
1850
0
    free(EXPORT_NAME(area));
1851
1852
0
  EXPORT_NAME(area) = strdup(list_name);
1853
0
  ospf_schedule_abr_task(ospf);
1854
1855
0
  return 1;
1856
0
}
1857
1858
int ospf_area_export_list_unset(struct ospf *ospf, struct ospf_area *area)
1859
0
{
1860
1861
0
  EXPORT_LIST(area) = 0;
1862
1863
0
  if (EXPORT_NAME(area))
1864
0
    free(EXPORT_NAME(area));
1865
1866
0
  EXPORT_NAME(area) = NULL;
1867
1868
0
  ospf_area_check_free(ospf, area->area_id);
1869
1870
0
  ospf_schedule_abr_task(ospf);
1871
1872
0
  return 1;
1873
0
}
1874
1875
int ospf_area_import_list_set(struct ospf *ospf, struct ospf_area *area,
1876
            const char *name)
1877
0
{
1878
0
  struct access_list *list;
1879
0
  list = access_list_lookup(AFI_IP, name);
1880
1881
0
  IMPORT_LIST(area) = list;
1882
1883
0
  if (IMPORT_NAME(area))
1884
0
    free(IMPORT_NAME(area));
1885
1886
0
  IMPORT_NAME(area) = strdup(name);
1887
0
  ospf_schedule_abr_task(ospf);
1888
1889
0
  return 1;
1890
0
}
1891
1892
int ospf_area_import_list_unset(struct ospf *ospf, struct ospf_area *area)
1893
0
{
1894
0
  IMPORT_LIST(area) = 0;
1895
1896
0
  if (IMPORT_NAME(area))
1897
0
    free(IMPORT_NAME(area));
1898
1899
0
  IMPORT_NAME(area) = NULL;
1900
0
  ospf_area_check_free(ospf, area->area_id);
1901
1902
0
  ospf_schedule_abr_task(ospf);
1903
1904
0
  return 1;
1905
0
}
1906
1907
int ospf_timers_refresh_set(struct ospf *ospf, int interval)
1908
0
{
1909
0
  int time_left;
1910
1911
0
  if (ospf->lsa_refresh_interval == interval)
1912
0
    return 1;
1913
1914
0
  time_left = ospf->lsa_refresh_interval
1915
0
        - (monotime(NULL) - ospf->lsa_refresher_started);
1916
1917
0
  if (time_left > interval) {
1918
0
    EVENT_OFF(ospf->t_lsa_refresher);
1919
0
    event_add_timer(master, ospf_lsa_refresh_walker, ospf, interval,
1920
0
        &ospf->t_lsa_refresher);
1921
0
  }
1922
0
  ospf->lsa_refresh_interval = interval;
1923
1924
0
  return 1;
1925
0
}
1926
1927
int ospf_timers_refresh_unset(struct ospf *ospf)
1928
0
{
1929
0
  int time_left;
1930
1931
0
  time_left = ospf->lsa_refresh_interval
1932
0
        - (monotime(NULL) - ospf->lsa_refresher_started);
1933
1934
0
  if (time_left > OSPF_LSA_REFRESH_INTERVAL_DEFAULT) {
1935
0
    EVENT_OFF(ospf->t_lsa_refresher);
1936
0
    ospf->t_lsa_refresher = NULL;
1937
0
    event_add_timer(master, ospf_lsa_refresh_walker, ospf,
1938
0
        OSPF_LSA_REFRESH_INTERVAL_DEFAULT,
1939
0
        &ospf->t_lsa_refresher);
1940
0
  }
1941
1942
0
  ospf->lsa_refresh_interval = OSPF_LSA_REFRESH_INTERVAL_DEFAULT;
1943
1944
0
  return 1;
1945
0
}
1946
1947
1948
static struct ospf_nbr_nbma *ospf_nbr_nbma_new(void)
1949
0
{
1950
0
  struct ospf_nbr_nbma *nbr_nbma;
1951
1952
0
  nbr_nbma = XCALLOC(MTYPE_OSPF_NEIGHBOR_STATIC,
1953
0
         sizeof(struct ospf_nbr_nbma));
1954
1955
0
  nbr_nbma->priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT;
1956
0
  nbr_nbma->v_poll = OSPF_POLL_INTERVAL_DEFAULT;
1957
1958
0
  return nbr_nbma;
1959
0
}
1960
1961
static void ospf_nbr_nbma_free(struct ospf_nbr_nbma *nbr_nbma)
1962
0
{
1963
0
  XFREE(MTYPE_OSPF_NEIGHBOR_STATIC, nbr_nbma);
1964
0
}
1965
1966
static void ospf_nbr_nbma_delete(struct ospf *ospf,
1967
         struct ospf_nbr_nbma *nbr_nbma)
1968
0
{
1969
0
  struct route_node *rn;
1970
0
  struct prefix_ipv4 p;
1971
1972
0
  p.family = AF_INET;
1973
0
  p.prefix = nbr_nbma->addr;
1974
0
  p.prefixlen = IPV4_MAX_BITLEN;
1975
1976
0
  rn = route_node_lookup(ospf->nbr_nbma, (struct prefix *)&p);
1977
0
  if (rn) {
1978
0
    ospf_nbr_nbma_free(rn->info);
1979
0
    rn->info = NULL;
1980
0
    route_unlock_node(rn);
1981
0
    route_unlock_node(rn);
1982
0
  }
1983
0
}
1984
1985
static void ospf_nbr_nbma_down(struct ospf_nbr_nbma *nbr_nbma)
1986
0
{
1987
0
  EVENT_OFF(nbr_nbma->t_poll);
1988
1989
0
  if (nbr_nbma->nbr) {
1990
0
    nbr_nbma->nbr->nbr_nbma = NULL;
1991
0
    OSPF_NSM_EVENT_EXECUTE(nbr_nbma->nbr, NSM_KillNbr);
1992
0
  }
1993
1994
0
  if (nbr_nbma->oi)
1995
0
    listnode_delete(nbr_nbma->oi->nbr_nbma, nbr_nbma);
1996
0
}
1997
1998
static void ospf_nbr_nbma_add(struct ospf_nbr_nbma *nbr_nbma,
1999
            struct ospf_interface *oi)
2000
0
{
2001
0
  struct ospf_neighbor *nbr;
2002
0
  struct route_node *rn;
2003
0
  struct prefix p;
2004
2005
0
  if (oi->type != OSPF_IFTYPE_NBMA)
2006
0
    return;
2007
2008
0
  if (nbr_nbma->nbr != NULL)
2009
0
    return;
2010
2011
0
  if (IPV4_ADDR_SAME(&oi->nbr_self->address.u.prefix4, &nbr_nbma->addr))
2012
0
    return;
2013
2014
0
  nbr_nbma->oi = oi;
2015
0
  listnode_add(oi->nbr_nbma, nbr_nbma);
2016
2017
  /* Get neighbor information from table. */
2018
0
  p.family = AF_INET;
2019
0
  p.prefixlen = IPV4_MAX_BITLEN;
2020
0
  p.u.prefix4 = nbr_nbma->addr;
2021
2022
0
  rn = route_node_get(oi->nbrs, &p);
2023
0
  if (rn->info) {
2024
0
    nbr = rn->info;
2025
0
    nbr->nbr_nbma = nbr_nbma;
2026
0
    nbr_nbma->nbr = nbr;
2027
2028
0
    route_unlock_node(rn);
2029
0
  } else {
2030
0
    nbr = rn->info = ospf_nbr_new(oi);
2031
0
    nbr->state = NSM_Down;
2032
0
    nbr->src = nbr_nbma->addr;
2033
0
    nbr->nbr_nbma = nbr_nbma;
2034
0
    nbr->priority = nbr_nbma->priority;
2035
0
    nbr->address = p;
2036
2037
0
    nbr_nbma->nbr = nbr;
2038
2039
    /* Configure BFD if interface has it. */
2040
0
    ospf_neighbor_bfd_apply(nbr);
2041
2042
0
    OSPF_NSM_EVENT_EXECUTE(nbr, NSM_Start);
2043
0
  }
2044
0
}
2045
2046
void ospf_nbr_nbma_if_update(struct ospf *ospf, struct ospf_interface *oi)
2047
0
{
2048
0
  struct ospf_nbr_nbma *nbr_nbma;
2049
0
  struct route_node *rn;
2050
0
  struct prefix_ipv4 p;
2051
2052
0
  if (oi->type != OSPF_IFTYPE_NBMA)
2053
0
    return;
2054
2055
0
  for (rn = route_top(ospf->nbr_nbma); rn; rn = route_next(rn))
2056
0
    if ((nbr_nbma = rn->info))
2057
0
      if (nbr_nbma->oi == NULL && nbr_nbma->nbr == NULL) {
2058
0
        p.family = AF_INET;
2059
0
        p.prefix = nbr_nbma->addr;
2060
0
        p.prefixlen = IPV4_MAX_BITLEN;
2061
2062
0
        if (prefix_match(oi->address,
2063
0
             (struct prefix *)&p))
2064
0
          ospf_nbr_nbma_add(nbr_nbma, oi);
2065
0
      }
2066
0
}
2067
2068
struct ospf_nbr_nbma *ospf_nbr_nbma_lookup(struct ospf *ospf,
2069
             struct in_addr nbr_addr)
2070
0
{
2071
0
  struct route_node *rn;
2072
0
  struct prefix_ipv4 p;
2073
2074
0
  p.family = AF_INET;
2075
0
  p.prefix = nbr_addr;
2076
0
  p.prefixlen = IPV4_MAX_BITLEN;
2077
2078
0
  rn = route_node_lookup(ospf->nbr_nbma, (struct prefix *)&p);
2079
0
  if (rn) {
2080
0
    route_unlock_node(rn);
2081
0
    return rn->info;
2082
0
  }
2083
0
  return NULL;
2084
0
}
2085
2086
int ospf_nbr_nbma_set(struct ospf *ospf, struct in_addr nbr_addr)
2087
0
{
2088
0
  struct ospf_nbr_nbma *nbr_nbma;
2089
0
  struct ospf_interface *oi;
2090
0
  struct prefix_ipv4 p;
2091
0
  struct route_node *rn;
2092
0
  struct listnode *node;
2093
2094
0
  nbr_nbma = ospf_nbr_nbma_lookup(ospf, nbr_addr);
2095
0
  if (nbr_nbma)
2096
0
    return 0;
2097
2098
0
  nbr_nbma = ospf_nbr_nbma_new();
2099
0
  nbr_nbma->addr = nbr_addr;
2100
2101
0
  p.family = AF_INET;
2102
0
  p.prefix = nbr_addr;
2103
0
  p.prefixlen = IPV4_MAX_BITLEN;
2104
2105
0
  rn = route_node_get(ospf->nbr_nbma, (struct prefix *)&p);
2106
0
  if (rn->info)
2107
0
    route_unlock_node(rn);
2108
0
  rn->info = nbr_nbma;
2109
2110
0
  for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
2111
0
    if (oi->type == OSPF_IFTYPE_NBMA)
2112
0
      if (prefix_match(oi->address, (struct prefix *)&p)) {
2113
0
        ospf_nbr_nbma_add(nbr_nbma, oi);
2114
0
        break;
2115
0
      }
2116
0
  }
2117
2118
0
  return 1;
2119
0
}
2120
2121
int ospf_nbr_nbma_unset(struct ospf *ospf, struct in_addr nbr_addr)
2122
0
{
2123
0
  struct ospf_nbr_nbma *nbr_nbma;
2124
2125
0
  nbr_nbma = ospf_nbr_nbma_lookup(ospf, nbr_addr);
2126
0
  if (nbr_nbma == NULL)
2127
0
    return 0;
2128
2129
0
  ospf_nbr_nbma_down(nbr_nbma);
2130
0
  ospf_nbr_nbma_delete(ospf, nbr_nbma);
2131
2132
0
  return 1;
2133
0
}
2134
2135
int ospf_nbr_nbma_priority_set(struct ospf *ospf, struct in_addr nbr_addr,
2136
             uint8_t priority)
2137
0
{
2138
0
  struct ospf_nbr_nbma *nbr_nbma;
2139
2140
0
  nbr_nbma = ospf_nbr_nbma_lookup(ospf, nbr_addr);
2141
0
  if (nbr_nbma == NULL)
2142
0
    return 0;
2143
2144
0
  if (nbr_nbma->priority != priority)
2145
0
    nbr_nbma->priority = priority;
2146
2147
0
  return 1;
2148
0
}
2149
2150
int ospf_nbr_nbma_priority_unset(struct ospf *ospf, struct in_addr nbr_addr)
2151
0
{
2152
0
  struct ospf_nbr_nbma *nbr_nbma;
2153
2154
0
  nbr_nbma = ospf_nbr_nbma_lookup(ospf, nbr_addr);
2155
0
  if (nbr_nbma == NULL)
2156
0
    return 0;
2157
2158
0
  if (nbr_nbma != OSPF_NEIGHBOR_PRIORITY_DEFAULT)
2159
0
    nbr_nbma->priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT;
2160
2161
0
  return 1;
2162
0
}
2163
2164
int ospf_nbr_nbma_poll_interval_set(struct ospf *ospf, struct in_addr nbr_addr,
2165
            unsigned int interval)
2166
0
{
2167
0
  struct ospf_nbr_nbma *nbr_nbma;
2168
2169
0
  nbr_nbma = ospf_nbr_nbma_lookup(ospf, nbr_addr);
2170
0
  if (nbr_nbma == NULL)
2171
0
    return 0;
2172
2173
0
  if (nbr_nbma->v_poll != interval) {
2174
0
    nbr_nbma->v_poll = interval;
2175
0
    if (nbr_nbma->oi && ospf_if_is_up(nbr_nbma->oi)) {
2176
0
      EVENT_OFF(nbr_nbma->t_poll);
2177
0
      OSPF_POLL_TIMER_ON(nbr_nbma->t_poll, ospf_poll_timer,
2178
0
             nbr_nbma->v_poll);
2179
0
    }
2180
0
  }
2181
2182
0
  return 1;
2183
0
}
2184
2185
int ospf_nbr_nbma_poll_interval_unset(struct ospf *ospf, struct in_addr addr)
2186
0
{
2187
0
  struct ospf_nbr_nbma *nbr_nbma;
2188
2189
0
  nbr_nbma = ospf_nbr_nbma_lookup(ospf, addr);
2190
0
  if (nbr_nbma == NULL)
2191
0
    return 0;
2192
2193
0
  if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT)
2194
0
    nbr_nbma->v_poll = OSPF_POLL_INTERVAL_DEFAULT;
2195
2196
0
  return 1;
2197
0
}
2198
2199
/*
2200
 * Update socket bufsize(s), usually after config change
2201
 */
2202
void ospf_update_bufsize(struct ospf *ospf, uint32_t recvsize,
2203
       uint32_t sendsize)
2204
0
{
2205
0
  enum ospf_sock_type_e type = OSPF_SOCK_NONE;
2206
2207
  /* Figure out whether there's been a change */
2208
0
  if (recvsize != ospf->recv_sock_bufsize) {
2209
0
    type = OSPF_SOCK_RECV;
2210
0
    ospf->recv_sock_bufsize = recvsize;
2211
2212
0
    if (sendsize != ospf->send_sock_bufsize) {
2213
0
      type = OSPF_SOCK_BOTH;
2214
0
      ospf->send_sock_bufsize = sendsize;
2215
0
    }
2216
0
  } else if (sendsize != ospf->send_sock_bufsize) {
2217
0
    type = OSPF_SOCK_SEND;
2218
0
    ospf->send_sock_bufsize = sendsize;
2219
0
  }
2220
2221
0
  if (type != OSPF_SOCK_NONE)
2222
0
    ospf_sock_bufsize_update(ospf, ospf->fd, type);
2223
0
}
2224
2225
void ospf_master_init(struct event_loop *master)
2226
1
{
2227
1
  memset(&ospf_master, 0, sizeof(ospf_master));
2228
2229
1
  om = &ospf_master;
2230
1
  om->ospf = list_new();
2231
1
  om->master = master;
2232
1
}
2233
2234
/* Link OSPF instance to VRF. */
2235
void ospf_vrf_link(struct ospf *ospf, struct vrf *vrf)
2236
1
{
2237
1
  ospf->vrf_id = vrf->vrf_id;
2238
1
  if (vrf->info != (void *)ospf)
2239
1
    vrf->info = (void *)ospf;
2240
1
}
2241
2242
/* Unlink OSPF instance from VRF. */
2243
void ospf_vrf_unlink(struct ospf *ospf, struct vrf *vrf)
2244
0
{
2245
0
  if (vrf->info == (void *)ospf)
2246
0
    vrf->info = NULL;
2247
0
  ospf->vrf_id = VRF_UNKNOWN;
2248
0
}
2249
2250
/* This is hook function for vrf create called as part of vrf_init */
2251
static int ospf_vrf_new(struct vrf *vrf)
2252
1
{
2253
1
  if (IS_DEBUG_OSPF_EVENT)
2254
0
    zlog_debug("%s: VRF Created: %s(%u)", __func__, vrf->name,
2255
1
         vrf->vrf_id);
2256
2257
1
  return 0;
2258
1
}
2259
2260
/* This is hook function for vrf delete call as part of vrf_init */
2261
static int ospf_vrf_delete(struct vrf *vrf)
2262
0
{
2263
0
  if (IS_DEBUG_OSPF_EVENT)
2264
0
    zlog_debug("%s: VRF Deletion: %s(%u)", __func__, vrf->name,
2265
0
         vrf->vrf_id);
2266
2267
0
  return 0;
2268
0
}
2269
2270
static void ospf_set_redist_vrf_bitmaps(struct ospf *ospf, bool set)
2271
0
{
2272
0
  int type;
2273
0
  struct list *red_list;
2274
2275
0
  for (type = 0; type < ZEBRA_ROUTE_MAX; type++) {
2276
0
    red_list = ospf->redist[type];
2277
0
    if (!red_list)
2278
0
      continue;
2279
0
    if (IS_DEBUG_OSPF_EVENT)
2280
0
      zlog_debug(
2281
0
        "%s: setting redist vrf %d bitmap for type %d",
2282
0
        __func__, ospf->vrf_id, type);
2283
0
    if (set)
2284
0
      vrf_bitmap_set(zclient->redist[AFI_IP][type],
2285
0
               ospf->vrf_id);
2286
0
    else
2287
0
      vrf_bitmap_unset(zclient->redist[AFI_IP][type],
2288
0
           ospf->vrf_id);
2289
0
  }
2290
2291
0
  red_list = ospf->redist[DEFAULT_ROUTE];
2292
0
  if (red_list) {
2293
0
    if (set)
2294
0
      vrf_bitmap_set(zclient->default_information[AFI_IP],
2295
0
               ospf->vrf_id);
2296
0
    else
2297
0
      vrf_bitmap_unset(zclient->default_information[AFI_IP],
2298
0
           ospf->vrf_id);
2299
0
  }
2300
0
}
2301
2302
/* Enable OSPF VRF instance */
2303
static int ospf_vrf_enable(struct vrf *vrf)
2304
1
{
2305
1
  struct ospf *ospf = NULL;
2306
1
  vrf_id_t old_vrf_id;
2307
1
  int ret = 0;
2308
2309
1
  if (IS_DEBUG_OSPF_EVENT)
2310
0
    zlog_debug("%s: VRF %s id %u enabled", __func__, vrf->name,
2311
1
         vrf->vrf_id);
2312
2313
1
  ospf = ospf_lookup_by_name(vrf->name);
2314
1
  if (ospf) {
2315
0
    old_vrf_id = ospf->vrf_id;
2316
    /* We have instance configured, link to VRF and make it "up". */
2317
0
    ospf_vrf_link(ospf, vrf);
2318
0
    if (IS_DEBUG_OSPF_EVENT)
2319
0
      zlog_debug(
2320
0
        "%s: ospf linked to vrf %s vrf_id %u (old id %u)",
2321
0
        __func__, vrf->name, ospf->vrf_id, old_vrf_id);
2322
2323
0
    if (old_vrf_id != ospf->vrf_id) {
2324
0
      ospf_set_redist_vrf_bitmaps(ospf, true);
2325
2326
      /* start zebra redist to us for new vrf */
2327
0
      ospf_zebra_vrf_register(ospf);
2328
2329
0
      ret = ospf_sock_init(ospf);
2330
0
      if (ret < 0 || ospf->fd <= 0)
2331
0
        return 0;
2332
0
      event_add_read(master, ospf_read, ospf, ospf->fd,
2333
0
               &ospf->t_read);
2334
0
      ospf->oi_running = 1;
2335
0
      ospf_router_id_update(ospf);
2336
0
    }
2337
0
  }
2338
2339
1
  return 0;
2340
1
}
2341
2342
/* Disable OSPF VRF instance */
2343
static int ospf_vrf_disable(struct vrf *vrf)
2344
0
{
2345
0
  struct ospf *ospf = NULL;
2346
0
  vrf_id_t old_vrf_id = VRF_UNKNOWN;
2347
2348
0
  if (vrf->vrf_id == VRF_DEFAULT)
2349
0
    return 0;
2350
2351
0
  if (IS_DEBUG_OSPF_EVENT)
2352
0
    zlog_debug("%s: VRF %s id %d disabled.", __func__, vrf->name,
2353
0
         vrf->vrf_id);
2354
2355
0
  ospf = ospf_lookup_by_name(vrf->name);
2356
0
  if (ospf) {
2357
0
    old_vrf_id = ospf->vrf_id;
2358
2359
0
    ospf_zebra_vrf_deregister(ospf);
2360
2361
0
    ospf_set_redist_vrf_bitmaps(ospf, false);
2362
2363
    /* We have instance configured, unlink
2364
     * from VRF and make it "down".
2365
     */
2366
0
    ospf_vrf_unlink(ospf, vrf);
2367
0
    ospf->oi_running = 0;
2368
0
    if (IS_DEBUG_OSPF_EVENT)
2369
0
      zlog_debug("%s: ospf old_vrf_id %d unlinked", __func__,
2370
0
           old_vrf_id);
2371
0
    EVENT_OFF(ospf->t_read);
2372
0
    close(ospf->fd);
2373
0
    ospf->fd = -1;
2374
0
  }
2375
2376
  /* Note: This is a callback, the VRF will be deleted by the caller. */
2377
0
  return 0;
2378
0
}
2379
2380
void ospf_vrf_init(void)
2381
1
{
2382
1
  vrf_init(ospf_vrf_new, ospf_vrf_enable, ospf_vrf_disable,
2383
1
     ospf_vrf_delete);
2384
1
}
2385
2386
void ospf_vrf_terminate(void)
2387
0
{
2388
0
  vrf_terminate();
2389
0
}
2390
2391
const char *ospf_vrf_id_to_name(vrf_id_t vrf_id)
2392
0
{
2393
0
  struct vrf *vrf = vrf_lookup_by_id(vrf_id);
2394
2395
0
  return vrf ? vrf->name : "NIL";
2396
0
}
2397
2398
const char *ospf_get_name(const struct ospf *ospf)
2399
1
{
2400
1
  if (ospf->name)
2401
1
    return ospf->name;
2402
0
  else
2403
0
    return VRF_DEFAULT_NAME;
2404
1
}