ospf.c 38.6 KB
Newer Older
Ondřej Filip's avatar
Ondřej Filip committed
1 2 3
/*
 *	BIRD -- OSPF
 *
Ondřej Filip's avatar
Ondřej Filip committed
4
 *	(c) 1999--2004 Ondrej Filip <feela@network.cz>
5 6
 *	(c) 2009--2014 Ondrej Zajicek <santiago@crfreenet.org>
 *	(c) 2009--2014 CZ.NIC z.s.p.o.
Ondřej Filip's avatar
Ondřej Filip committed
7 8 9 10
 *
 *	Can be freely distributed and used under the terms of the GNU GPL.
 */

Ondřej Filip's avatar
Ondřej Filip committed
11 12
/**
 * DOC: Open Shortest Path First (OSPF)
13
 *
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
 * The OSPF protocol is quite complicated and its complex implemenation is split
 * to many files. In |ospf.c|, you will find mainly the interface for
 * communication with the core (e.g., reconfiguration hooks, shutdown and
 * initialisation and so on). File |iface.c| contains the interface state
 * machine and functions for allocation and deallocation of OSPF's interface
 * data structures. Source |neighbor.c| includes the neighbor state machine and
 * functions for election of Designated Router and Backup Designated router. In
 * |packet.c|, you will find various functions for sending and receiving generic
 * OSPF packets. There are also routines for authentication and checksumming.
 * In |hello.c|, there are routines for sending and receiving of hello packets
 * as well as functions for maintaining wait times and the inactivity timer.
 * Files |lsreq.c|, |lsack.c|, |dbdes.c| contain functions for sending and
 * receiving of link-state requests, link-state acknowledgements and database
 * descriptions respectively.  In |lsupd.c|, there are functions for sending and
 * receiving of link-state updates and also the flooding algorithm. Source
 * |topology.c| is a place where routines for searching LSAs in the link-state
 * database, adding and deleting them reside, there also are functions for
 * originating of various types of LSAs (router LSA, net LSA, external LSA).
 * File |rt.c| contains routines for calculating the routing table. |lsalib.c|
 * is a set of various functions for working with the LSAs (endianity
 * conversions, calculation of checksum etc.).
Ondřej Filip's avatar
Ondřej Filip committed
35
 *
36 37 38 39 40 41 42
 * One instance of the protocol is able to hold LSA databases for multiple OSPF
 * areas, to exchange routing information between multiple neighbors and to
 * calculate the routing tables. The core structure is &ospf_proto to which
 * multiple &ospf_area and &ospf_iface structures are connected. &ospf_proto is
 * also connected to &top_hash_graph which is a dynamic hashing structure that
 * describes the link-state database. It allows fast search, addition and
 * deletion. Each LSA is kept in two pieces: header and body. Both of them are
43
 * kept in the endianity of the CPU.
44
 *
45 46 47 48 49 50 51
 * In OSPFv2 specification, it is implied that there is one IP prefix for each
 * physical network/interface (unless it is an ptp link). But in modern systems,
 * there might be more independent IP prefixes associated with an interface.  To
 * handle this situation, we have one &ospf_iface for each active IP prefix
 * (instead for each active iface); This behaves like virtual interface for the
 * purpose of OSPF.  If we receive packet, we associate it with a proper virtual
 * interface mainly according to its source address.
Ondřej Zajíček's avatar
Ondřej Zajíček committed
52
 *
53 54 55 56 57 58 59 60
 * OSPF keeps one socket per &ospf_iface. This allows us (compared to one socket
 * approach) to evade problems with a limit of multicast groups per socket and
 * with sending multicast packets to appropriate interface in a portable way.
 * The socket is associated with underlying physical iface and should not
 * receive packets received on other ifaces (unfortunately, this is not true on
 * BSD). Generally, one packet can be received by more sockets (for example, if
 * there are more &ospf_iface on one physical iface), therefore we explicitly
 * filter received packets according to src/dst IP address and received iface.
Ondřej Zajíček's avatar
Ondřej Zajíček committed
61
 *
62 63 64 65
 * Vlinks are implemented using particularly degenerate form of &ospf_iface,
 * which has several exceptions: it does not have its iface or socket (it copies
 * these from 'parent' &ospf_iface) and it is present in iface list even when
 * down (it is not freed in ospf_iface_down()).
Ondřej Zajíček's avatar
Ondřej Zajíček committed
66
 *
67
 * The heart beat of ospf is ospf_disp(). It is called at regular intervals
68 69 70
 * (&ospf_proto->tick). It is responsible for aging and flushing of LSAs in the
 * database, updating topology information in LSAs and for routing table
 * calculation.
71
 *
72 73 74
 * To every &ospf_iface, we connect one or more &ospf_neighbor's -- a structure
 * containing many timers and queues for building adjacency and for exchange of
 * routing messages.
Ondřej Filip's avatar
Ondřej Filip committed
75
 *
76 77 78 79 80 81 82
 * BIRD's OSPF implementation respects RFC2328 in every detail, but some of
 * internal algorithms do differ. The RFC recommends making a snapshot of the
 * link-state database when a new adjacency is forming and sending the database
 * description packets based on the information in this snapshot. The database
 * can be quite large in some networks, so rather we walk through a &slist
 * structure which allows us to continue even if the actual LSA we were working
 * with is deleted. New LSAs are added at the tail of this &slist.
Ondřej Filip's avatar
Ondřej Filip committed
83
 *
84 85 86 87 88
 * We also do not keep a separate OSPF routing table, because the core helps us
 * by being able to recognize when a route is updated to an identical one and it
 * suppresses the update automatically. Due to this, we can flush all the routes
 * we have recalculated and also those we have deleted to the core's routing
 * table and the core will take care of the rest. This simplifies the process
89
 * and conserves memory.
90 91 92 93 94 95 96
 *
 * Supported standards:
 * - RFC 2328 - main OSPFv2 standard
 * - RFC 5340 - main OSPFv3 standard
 * - RFC 3101 - OSPFv2 NSSA areas
 * - RFC 6549 - OSPFv2 multi-instance extensions
 * - RFC 6987 - OSPF stub router advertisement
Ondřej Filip's avatar
Ondřej Filip committed
97 98
 */

99
#include <stdlib.h>
Ondřej Filip's avatar
Ondřej Filip committed
100 101
#include "ospf.h"

102 103 104
static int ospf_import_control(struct proto *P, rte **new, ea_list **attrs, struct linpool *pool);
static struct ea_list *ospf_make_tmp_attrs(struct rte *rt, struct linpool *pool);
static void ospf_store_tmp_attrs(struct rte *rt, struct ea_list *attrs);
105
static void ospf_reload_routes(struct channel *C);
106 107
static int ospf_rte_better(struct rte *new, struct rte *old);
static int ospf_rte_same(struct rte *new, struct rte *old);
108 109
static void ospf_disp(timer *timer);

Ondřej Filip's avatar
Ondřej Filip committed
110 111 112 113

static void
add_area_nets(struct ospf_area *oa, struct ospf_area_config *ac)
{
114 115 116
  struct ospf_proto *p = oa->po;
  struct area_net_config *anc;
  struct area_net *an;
Ondřej Filip's avatar
Ondřej Filip committed
117

118 119 120 121
  fib_init(&oa->net_fib,  p->p.pool, ospf_is_v2(p) ? NET_IP4 : NET_IP6,
	   sizeof(struct area_net), OFFSETOF(struct area_net, fn), 0, NULL);
  fib_init(&oa->enet_fib, p->p.pool, ospf_is_v2(p) ? NET_IP4 : NET_IP6,
	   sizeof(struct area_net), OFFSETOF(struct area_net, fn), 0, NULL);
Ondřej Filip's avatar
Ondřej Filip committed
122

123 124
  WALK_LIST(anc, ac->net_list)
  {
125
    an = fib_get(&oa->net_fib, &anc->prefix);
126 127
    an->hidden = anc->hidden;
  }
128

129 130
  WALK_LIST(anc, ac->enet_list)
  {
131
    an = fib_get(&oa->enet_fib, &anc->prefix);
132 133 134
    an->hidden = anc->hidden;
    an->tag = anc->tag;
  }
Ondřej Filip's avatar
Ondřej Filip committed
135
}
136

137
static void
138
ospf_area_add(struct ospf_proto *p, struct ospf_area_config *ac)
139 140 141 142 143
{
  struct ospf_area *oa;

  OSPF_TRACE(D_EVENTS, "Adding area %R", ac->areaid);

144 145 146
  oa = mb_allocz(p->p.pool, sizeof(struct ospf_area));
  add_tail(&p->area_list, NODE oa);
  p->areano++;
147 148 149 150

  oa->ac = ac;
  oa->areaid = ac->areaid;
  oa->rt = NULL;
151
  oa->po = p;
152
  fib_init(&oa->rtr, p->p.pool, NET_IP4, sizeof(ort), OFFSETOF(ort, fn), 0, NULL);
153 154 155
  add_area_nets(oa, ac);

  if (oa->areaid == 0)
156
    p->backbone = oa;
157

158 159 160 161
  if (ospf_is_v2(p))
    oa->options = ac->type;
  else
    oa->options = ac->type | OPT_V6 | (p->stub_router ? 0 : OPT_R);
162 163

  ospf_notify_rt_lsa(oa);
164
}
165

166 167 168 169
static void
ospf_flush_area(struct ospf_proto *p, u32 areaid)
{
  struct top_hash_entry *en;
170

171 172 173
  WALK_SLIST(en, p->lsal)
    if ((LSA_SCOPE(en->lsa_type) == LSA_SCOPE_AREA) && (en->domain == areaid))
      ospf_flush_lsa(p, en);
174 175 176 177 178
}

static void
ospf_area_remove(struct ospf_area *oa)
{
179
  struct ospf_proto *p = oa->po;
180 181 182
  OSPF_TRACE(D_EVENTS, "Removing area %R", oa->areaid);

  /* We suppose that interfaces are already removed */
183
  ospf_flush_area(p, oa->areaid);
184

185 186
  fib_free(&oa->rtr);
  fib_free(&oa->net_fib);
187
  fib_free(&oa->enet_fib);
188

189 190 191
  if (oa->translator_timer)
    rfree(oa->translator_timer);

192
  p->areano--;
193 194 195 196 197 198
  rem_node(NODE oa);
  mb_free(oa);
}


struct ospf_area *
199
ospf_find_area(struct ospf_proto *p, u32 aid)
200 201
{
  struct ospf_area *oa;
202
  WALK_LIST(oa, p->area_list)
203 204 205 206 207 208
    if (((struct ospf_area *) oa)->areaid == aid)
      return oa;
  return NULL;
}

static struct ospf_iface *
209
ospf_find_vlink(struct ospf_proto *p, u32 voa, u32 vid)
210 211
{
  struct ospf_iface *ifa;
212
  WALK_LIST(ifa, p->iface_list)
213 214 215 216 217
    if ((ifa->type == OSPF_IT_VLINK) && (ifa->voa->areaid == voa) && (ifa->vid == vid))
      return ifa;
  return NULL;
}

Ondřej Filip's avatar
Ondřej Filip committed
218
static int
219
ospf_start(struct proto *P)
Ondřej Filip's avatar
Ondřej Filip committed
220
{
221 222
  struct ospf_proto *p = (struct ospf_proto *) P;
  struct ospf_config *c = (struct ospf_config *) (P->cf);
223
  struct ospf_area_config *ac;
Ondřej Filip's avatar
Ondřej Filip committed
224

225 226 227 228 229 230 231 232
  p->router_id = proto_get_router_id(P->cf);
  p->ospf2 = c->ospf2;
  p->rfc1583 = c->rfc1583;
  p->stub_router = c->stub_router;
  p->merge_external = c->merge_external;
  p->asbr = c->asbr;
  p->ecmp = c->ecmp;
  p->tick = c->tick;
233
  p->disp_timer = tm_new_set(P->pool, ospf_disp, p, 0, p->tick);
234 235 236 237 238 239 240
  tm_start(p->disp_timer, 1);
  p->lsab_size = 256;
  p->lsab_used = 0;
  p->lsab = mb_alloc(P->pool, p->lsab_size);
  p->nhpool = lp_new(P->pool, 12*sizeof(struct mpnh));
  init_list(&(p->iface_list));
  init_list(&(p->area_list));
241 242
  fib_init(&p->rtf, P->pool, p->ospf2 ? NET_IP4 : NET_IP6,
	   sizeof(ort), OFFSETOF(ort, fn), 0, NULL);
243 244
  if (ospf_is_v3(p))
    idm_init(&p->idm, P->pool, 16);
245
  p->areano = 0;
246
  p->gr = ospf_top_new(p, P->pool);
247
  s_init_list(&(p->lsal));
Ondřej Filip's avatar
Ondřej Filip committed
248

249 250 251 252
  p->flood_event = ev_new(P->pool);
  p->flood_event->hook = ospf_flood_event;
  p->flood_event->data = p;

253 254 255
  p->log_pkt_tbf = (struct tbf){ .rate = 1, .burst = 5 };
  p->log_lsa_tbf = (struct tbf){ .rate = 4, .burst = 20 };

Ondřej Filip's avatar
Ondřej Filip committed
256
  WALK_LIST(ac, c->area_list)
257
    ospf_area_add(p, ac);
258

259
  if (c->abr)
260
    ospf_open_vlink_sk(p);
261

262 263 264
  /* Add all virtual links */
  struct ospf_iface_patt *ic;
  WALK_LIST(ic, c->vlink_list)
265
    ospf_iface_new_vlink(p, ic);
266

Ondřej Filip's avatar
Ondřej Filip committed
267 268 269 270
  return PS_UP;
}

static void
271
ospf_dump(struct proto *P)
Ondřej Filip's avatar
Ondřej Filip committed
272
{
273
  struct ospf_proto *p = (struct ospf_proto *) P;
Ondřej Filip's avatar
Ondřej Filip committed
274 275
  struct ospf_iface *ifa;
  struct ospf_neighbor *n;
Ondřej Filip's avatar
Ondřej Filip committed
276

277
  OSPF_TRACE(D_EVENTS, "Area number: %d", p->areano);
Ondřej Filip's avatar
Ondřej Filip committed
278

279
  WALK_LIST(ifa, p->iface_list)
Ondřej Filip's avatar
Ondřej Filip committed
280
  {
281
    OSPF_TRACE(D_EVENTS, "Interface: %s", ifa->ifname);
Ondřej Filip's avatar
Ondřej Filip committed
282
    OSPF_TRACE(D_EVENTS, "state: %u", ifa->state);
283 284
    OSPF_TRACE(D_EVENTS, "DR:  %R", ifa->drid);
    OSPF_TRACE(D_EVENTS, "BDR: %R", ifa->bdrid);
Ondřej Filip's avatar
Ondřej Filip committed
285 286
    WALK_LIST(n, ifa->neigh_list)
    {
287
      OSPF_TRACE(D_EVENTS, "  neighbor %R in state %u", n->rid, n->state);
Ondřej Filip's avatar
Ondřej Filip committed
288 289
    }
  }
Ondřej Filip's avatar
Ondřej Filip committed
290

291
  /*
292
  OSPF_TRACE(D_EVENTS, "LSA graph dump start:");
293
  ospf_top_dump(p->gr, p);
294
  OSPF_TRACE(D_EVENTS, "LSA graph dump finished");
295
  */
296
  neigh_dump_all();
Ondřej Filip's avatar
Ondřej Filip committed
297 298 299
}

static struct proto *
300
ospf_init(struct proto_config *CF)
Ondřej Filip's avatar
Ondřej Filip committed
301
{
302 303 304 305
  struct ospf_config *cf = (struct ospf_config *) CF;
  struct proto *P = proto_new(CF);

  P->main_channel = proto_add_channel(P, proto_cf_main_channel(CF));
306 307 308

  P->rt_notify = ospf_rt_notify;
  P->if_notify = ospf_if_notify;
309
  P->ifa_notify = cf->ospf2 ? ospf_ifa_notify2 : ospf_ifa_notify3;
310 311 312 313 314 315 316 317
  P->import_control = ospf_import_control;
  P->reload_routes = ospf_reload_routes;
  P->make_tmp_attrs = ospf_make_tmp_attrs;
  P->store_tmp_attrs = ospf_store_tmp_attrs;
  P->rte_better = ospf_rte_better;
  P->rte_same = ospf_rte_same;

  return P;
Ondřej Filip's avatar
Ondřej Filip committed
318 319
}

Ondřej Filip's avatar
Ondřej Filip committed
320 321 322 323
/* If new is better return 1 */
static int
ospf_rte_better(struct rte *new, struct rte *old)
{
Ondřej Filip's avatar
Ondřej Filip committed
324 325
  if (new->u.ospf.metric1 == LSINFINITY)
    return 0;
Ondřej Filip's avatar
Ondřej Filip committed
326

Ondřej Filip's avatar
Ondřej Filip committed
327 328
  if(new->attrs->source < old->attrs->source) return 1;
  if(new->attrs->source > old->attrs->source) return 0;
Ondřej Filip's avatar
Ondřej Filip committed
329

Ondřej Filip's avatar
Ondřej Filip committed
330
  if(new->attrs->source == RTS_OSPF_EXT2)
Ondřej Filip's avatar
Ondřej Filip committed
331
  {
Ondřej Filip's avatar
Ondřej Filip committed
332 333
    if(new->u.ospf.metric2 < old->u.ospf.metric2) return 1;
    if(new->u.ospf.metric2 > old->u.ospf.metric2) return 0;
Ondřej Filip's avatar
Ondřej Filip committed
334
  }
Ondřej Filip's avatar
Ondřej Filip committed
335

Ondřej Filip's avatar
Ondřej Filip committed
336 337
  if (new->u.ospf.metric1 < old->u.ospf.metric1)
    return 1;
Ondřej Filip's avatar
Ondřej Filip committed
338

Ondřej Filip's avatar
Ondřej Filip committed
339
  return 0;			/* Old is shorter or same */
Ondřej Filip's avatar
Ondřej Filip committed
340 341
}

Ondřej Filip's avatar
Ondřej Filip committed
342 343 344
static int
ospf_rte_same(struct rte *new, struct rte *old)
{
345 346 347 348
  /* new->attrs == old->attrs always */
  return
    new->u.ospf.metric1 == old->u.ospf.metric1 &&
    new->u.ospf.metric2 == old->u.ospf.metric2 &&
349 350
    new->u.ospf.tag == old->u.ospf.tag &&
    new->u.ospf.router_id == old->u.ospf.router_id;
351
}
Ondřej Filip's avatar
Ondřej Filip committed
352

353
static ea_list *
Ondřej Filip's avatar
Ondřej Filip committed
354
ospf_build_attrs(ea_list * next, struct linpool *pool, u32 m1, u32 m2,
355
		 u32 tag, u32 rid)
356
{
Ondřej Filip's avatar
Ondřej Filip committed
357
  struct ea_list *l =
358
    lp_alloc(pool, sizeof(struct ea_list) + 4 * sizeof(eattr));
359 360 361

  l->next = next;
  l->flags = EALF_SORTED;
362
  l->count = 4;
363 364 365 366 367 368 369 370 371 372 373 374
  l->attrs[0].id = EA_OSPF_METRIC1;
  l->attrs[0].flags = 0;
  l->attrs[0].type = EAF_TYPE_INT | EAF_TEMP;
  l->attrs[0].u.data = m1;
  l->attrs[1].id = EA_OSPF_METRIC2;
  l->attrs[1].flags = 0;
  l->attrs[1].type = EAF_TYPE_INT | EAF_TEMP;
  l->attrs[1].u.data = m2;
  l->attrs[2].id = EA_OSPF_TAG;
  l->attrs[2].flags = 0;
  l->attrs[2].type = EAF_TYPE_INT | EAF_TEMP;
  l->attrs[2].u.data = tag;
375 376
  l->attrs[3].id = EA_OSPF_ROUTER_ID;
  l->attrs[3].flags = 0;
377
  l->attrs[3].type = EAF_TYPE_ROUTER_ID | EAF_TEMP;
378
  l->attrs[3].u.data = rid;
379
  return l;
Ondřej Filip's avatar
Ondřej Filip committed
380 381
}

382 383

void
384
ospf_schedule_rtcalc(struct ospf_proto *p)
385
{
386
  if (p->calcrt)
Ondřej Filip's avatar
Ondřej Filip committed
387
    return;
388

389
  OSPF_TRACE(D_EVENTS, "Scheduling routing table calculation");
390
  p->calcrt = 1;
391 392
}

393 394
static void
ospf_reload_routes(struct channel *C)
395
{
396
  struct ospf_proto *p = (struct ospf_proto *) C->proto;
397

398 399
  if (p->calcrt == 2)
    return;
400

401
  OSPF_TRACE(D_EVENTS, "Scheduling routing table calculation with route reload");
402
  p->calcrt = 2;
403 404
}

405

406
/**
407
 * ospf_disp - invokes routing table calculation, aging and also area_disp()
408 409
 * @timer: timer usually called every @ospf_proto->tick second, @timer->data
 * point to @ospf_proto
410
 */
411
static void
412 413
ospf_disp(timer * timer)
{
414
  struct ospf_proto *p = timer->data;
415

416 417
  /* Originate or flush local topology LSAs */
  ospf_update_topology(p);
418

419
  /* Process LSA DB */
420
  ospf_update_lsadb(p);
421

422
  /* Calculate routing table */
423 424
  if (p->calcrt)
    ospf_rt_spf(p);
425 426
}

427

Ondřej Filip's avatar
Ondřej Filip committed
428 429
/**
 * ospf_import_control - accept or reject new route from nest's routing table
430
 * @P: OSPF protocol instance
Martin Mareš's avatar
Martin Mareš committed
431
 * @new: the new route
432 433
 * @attrs: list of attributes
 * @pool: pool for allocation of attributes
Ondřej Filip's avatar
Ondřej Filip committed
434
 *
435 436
 * Its quite simple. It does not accept our own routes and leaves the decision on
 * import to the filters.
Ondřej Filip's avatar
Ondřej Filip committed
437
 */
438 439
static int
ospf_import_control(struct proto *P, rte **new, ea_list **attrs, struct linpool *pool)
440
{
441 442
  struct ospf_proto *p = (struct ospf_proto *) P;
  struct ospf_area *oa = ospf_main_area(p);
Ondřej Filip's avatar
Ondřej Filip committed
443
  rte *e = *new;
444

445
  if (e->attrs->src->proto == P)
Ondřej Filip's avatar
Ondřej Filip committed
446
    return -1;			/* Reject our own routes */
447

448 449 450
  if (oa_is_stub(oa))
    return -1;			/* Do not export routes to stub areas */

451 452 453 454 455 456 457 458 459 460 461 462 463
  ea_list *ea = e->attrs->eattrs;
  u32 m0 = ea_get_int(ea, EA_GEN_IGP_METRIC, LSINFINITY);
  u32 m1 = MIN(m0, LSINFINITY);
  u32 m2 = 10000;
  u32 tag = 0;

  /* Hack for setting attributes directly in static protocol */
  if (e->attrs->source == RTS_STATIC)
  {
    m1 = ea_get_int(ea, EA_OSPF_METRIC1, m1);
    m2 = ea_get_int(ea, EA_OSPF_METRIC2, 10000);
    tag = ea_get_int(ea, EA_OSPF_TAG, 0);
  }
464

465
  *attrs = ospf_build_attrs(*attrs, pool, m1, m2, tag, 0);
Ondřej Filip's avatar
Ondřej Filip committed
466
  return 0;			/* Leave decision to the filters */
467
}
468

469
static struct ea_list *
470 471
ospf_make_tmp_attrs(struct rte *rt, struct linpool *pool)
{
Ondřej Filip's avatar
Ondřej Filip committed
472
  return ospf_build_attrs(NULL, pool, rt->u.ospf.metric1, rt->u.ospf.metric2,
473
			  rt->u.ospf.tag, rt->u.ospf.router_id);
474 475
}

476
static void
477 478
ospf_store_tmp_attrs(struct rte *rt, struct ea_list *attrs)
{
479 480
  rt->u.ospf.metric1 = ea_get_int(attrs, EA_OSPF_METRIC1, LSINFINITY);
  rt->u.ospf.metric2 = ea_get_int(attrs, EA_OSPF_METRIC2, 10000);
Ondřej Filip's avatar
Ondřej Filip committed
481
  rt->u.ospf.tag = ea_get_int(attrs, EA_OSPF_TAG, 0);
482
  rt->u.ospf.router_id = ea_get_int(attrs, EA_OSPF_ROUTER_ID, 0);
483 484
}

Ondřej Filip's avatar
Ondřej Filip committed
485
/**
486
 * ospf_shutdown - Finish of OSPF instance
487
 * @P: OSPF protocol instance
Ondřej Filip's avatar
Ondřej Filip committed
488
 *
489
 * RFC does not define any action that should be taken before router
Ondřej Filip's avatar
Ondřej Filip committed
490 491
 * shutdown. To make my neighbors react as fast as possible, I send
 * them hello packet with empty neighbor list. They should start
492
 * their neighbor state machine with event %NEIGHBOR_1WAY.
Ondřej Filip's avatar
Ondřej Filip committed
493
 */
494
static int
495
ospf_shutdown(struct proto *P)
496
{
497
  struct ospf_proto *p = (struct ospf_proto *) P;
498
  struct ospf_iface *ifa;
499

Ondřej Filip's avatar
Ondřej Filip committed
500
  OSPF_TRACE(D_EVENTS, "Shutdown requested");
501 502

  /* And send to all my neighbors 1WAY */
503
  WALK_LIST(ifa, p->iface_list)
504
    ospf_iface_shutdown(ifa);
Ondřej Filip's avatar
Ondřej Filip committed
505

506
  /* Cleanup locked rta entries */
507
  FIB_WALK(&p->rtf, ort, nf)
508
  {
509
    rta_free(nf->old_rta);
510 511 512
  }
  FIB_WALK_END;

513 514 515
  return PS_DOWN;
}

516
static void
517
ospf_get_status(struct proto *P, byte * buf)
518
{
519
  struct ospf_proto *p = (struct ospf_proto *) P;
520

521
  if (p->p.proto_state == PS_DOWN)
Ondřej Filip's avatar
Ondřej Filip committed
522
    buf[0] = 0;
523 524 525 526
  else
  {
    struct ospf_iface *ifa;
    struct ospf_neighbor *n;
Ondřej Filip's avatar
Ondřej Filip committed
527
    int adj = 0;
528

529
    WALK_LIST(ifa, p->iface_list)
Ondřej Filip's avatar
Ondřej Filip committed
530 531
      WALK_LIST(n, ifa->neigh_list) if (n->state == NEIGHBOR_FULL)
      adj = 1;
532

Ondřej Filip's avatar
Ondřej Filip committed
533 534 535 536
    if (adj == 0)
      strcpy(buf, "Alone");
    else
      strcpy(buf, "Running");
537 538 539
  }
}

Ondřej Filip's avatar
Ondřej Filip committed
540
static void
Ondřej Filip's avatar
Ondřej Filip committed
541
ospf_get_route_info(rte * rte, byte * buf, ea_list * attrs UNUSED)
Ondřej Filip's avatar
Ondřej Filip committed
542
{
Ondřej Filip's avatar
Ondřej Filip committed
543
  char *type = "<bug>";
Ondřej Filip's avatar
Ondřej Filip committed
544

545
  switch (rte->attrs->source)
Ondřej Filip's avatar
Ondřej Filip committed
546
  {
547 548 549 550 551 552 553 554 555 556 557 558
  case RTS_OSPF:
    type = "I";
    break;
  case RTS_OSPF_IA:
    type = "IA";
    break;
  case RTS_OSPF_EXT1:
    type = "E1";
    break;
  case RTS_OSPF_EXT2:
    type = "E2";
    break;
Ondřej Filip's avatar
Ondřej Filip committed
559
  }
Ondřej Filip's avatar
Ondřej Filip committed
560 561

  buf += bsprintf(buf, " %s", type);
Ondřej Filip's avatar
Ondřej Filip committed
562
  buf += bsprintf(buf, " (%d/%d", rte->pref, rte->u.ospf.metric1);
Ondřej Filip's avatar
Ondřej Filip committed
563
  if (rte->attrs->source == RTS_OSPF_EXT2)
Ondřej Filip's avatar
Ondřej Filip committed
564
    buf += bsprintf(buf, "/%d", rte->u.ospf.metric2);
Ondřej Filip's avatar
Ondřej Filip committed
565
  buf += bsprintf(buf, ")");
566
  if ((rte->attrs->source == RTS_OSPF_EXT1 || rte->attrs->source == RTS_OSPF_EXT2) && rte->u.ospf.tag)
567
  {
568
    buf += bsprintf(buf, " [%x]", rte->u.ospf.tag);
569
  }
570 571
  if (rte->u.ospf.router_id)
    buf += bsprintf(buf, " [%R]", rte->u.ospf.router_id);
Ondřej Filip's avatar
Ondřej Filip committed
572 573
}

574
static int
575
ospf_get_attr(eattr * a, byte * buf, int buflen UNUSED)
576 577
{
  switch (a->id)
Ondřej Filip's avatar
Ondřej Filip committed
578 579 580 581 582 583 584 585
  {
  case EA_OSPF_METRIC1:
    bsprintf(buf, "metric1");
    return GA_NAME;
  case EA_OSPF_METRIC2:
    bsprintf(buf, "metric2");
    return GA_NAME;
  case EA_OSPF_TAG:
586
    bsprintf(buf, "tag: 0x%08x", a->u.data);
Ondřej Filip's avatar
Ondřej Filip committed
587
    return GA_FULL;
588 589 590
  case EA_OSPF_ROUTER_ID:
    bsprintf(buf, "router_id");
    return GA_NAME;
Ondřej Filip's avatar
Ondřej Filip committed
591 592 593
  default:
    return GA_UNKNOWN;
  }
594
}
Ondřej Filip's avatar
Ondřej Filip committed
595

596 597
static void
ospf_area_reconfigure(struct ospf_area *oa, struct ospf_area_config *nac)
Ondřej Filip's avatar
Ondřej Filip committed
598
{
599 600 601 602
  struct ospf_proto *p = oa->po;
  struct ospf_area_config *oac = oa->ac;
  struct ospf_iface *ifa;

603
  oa->ac = nac;
604

605 606 607 608
  if (ospf_is_v2(p))
    oa->options = nac->type;
  else
    oa->options = nac->type | OPT_V6 | (p->stub_router ? 0 : OPT_R);
609

610 611 612 613 614 615 616
  if (nac->type != oac->type)
  {
    /* Force restart of area interfaces */
    WALK_LIST(ifa, p->iface_list)
      if (ifa->oa == oa)
	ifa->marked = 2;
  }
617 618 619

  /* Handle net_list */
  fib_free(&oa->net_fib);
620
  fib_free(&oa->enet_fib);
621 622 623 624 625
  add_area_nets(oa, nac);

  /* No need to handle stubnet_list */

  oa->marked = 0;
626
  ospf_notify_rt_lsa(oa);
Ondřej Filip's avatar
Ondřej Filip committed
627
}
628

Ondřej Filip's avatar
Ondřej Filip committed
629 630
/**
 * ospf_reconfigure - reconfiguration hook
631
 * @P: current instance of protocol (with old configuration)
Ondřej Filip's avatar
Ondřej Filip committed
632 633
 * @c: new configuration requested by user
 *
634
 * This hook tries to be a little bit intelligent. Instance of OSPF
Ondřej Filip's avatar
Ondřej Filip committed
635
 * will survive change of many constants like hello interval,
636
 * password change, addition or deletion of some neighbor on
Ondřej Filip's avatar
Ondřej Filip committed
637 638
 * nonbroadcast network, cost of interface, etc.
 */
Ondřej Filip's avatar
Ondřej Filip committed
639
static int
640
ospf_reconfigure(struct proto *P, struct proto_config *CF)
Ondřej Filip's avatar
Ondřej Filip committed
641
{
642 643
  struct ospf_proto *p = (struct ospf_proto *) P;
  struct ospf_config *old = (struct ospf_config *) (P->cf);
644
  struct ospf_config *new = (struct ospf_config *) CF;
645 646 647 648 649
  struct ospf_area_config *nac;
  struct ospf_area *oa, *oax;
  struct ospf_iface *ifa, *ifx;
  struct ospf_iface_patt *ip;

650
  if (proto_get_router_id(CF) != p->router_id)
651 652
    return 0;

653 654 655
  if (p->ospf2 != new->ospf2)
    return 0;

656
  if (p->rfc1583 != new->rfc1583)
657 658
    return 0;

659 660
  if (old->abr != new->abr)
    return 0;
Ondřej Filip's avatar
Ondřej Filip committed
661

662 663 664
  if (!proto_configure_channel(P, &P->main_channel, proto_cf_main_channel(CF)))
    return 0;

665 666 667 668 669 670 671
  p->stub_router = new->stub_router;
  p->merge_external = new->merge_external;
  p->asbr = new->asbr;
  p->ecmp = new->ecmp;
  p->tick = new->tick;
  p->disp_timer->recurrent = p->tick;
  tm_start(p->disp_timer, 1);
672

673
  /* Mark all areas and ifaces */
674
  WALK_LIST(oa, p->area_list)
675
    oa->marked = 1;
Ondřej Filip's avatar
Ondřej Filip committed
676

677
  WALK_LIST(ifa, p->iface_list)
678
    ifa->marked = 1;
Ondřej Filip's avatar
Ondřej Filip committed
679

680 681
  /* Add and update areas */
  WALK_LIST(nac, new->area_list)
Ondřej Filip's avatar
Ondřej Filip committed
682
  {
683
    oa = ospf_find_area(p, nac->areaid);
684 685 686
    if (oa)
      ospf_area_reconfigure(oa, nac);
    else
687
      ospf_area_add(p, nac);
688
  }
689

690 691 692
  /* Add and update interfaces */
  ospf_reconfigure_ifaces(p);

693 694 695
  /* Add and update vlinks */
  WALK_LIST(ip, new->vlink_list)
  {
696
    ifa = ospf_find_vlink(p, ip->voa, ip->vid);
697 698 699
    if (ifa)
      ospf_iface_reconfigure(ifa, ip);
    else
700
      ospf_iface_new_vlink(p, ip);
701
  }
Ondřej Filip's avatar
Ondřej Filip committed
702

703
  /* Delete remaining ifaces and areas */
704
  WALK_LIST_DELSAFE(ifa, ifx, p->iface_list)
705
    if (ifa->marked)
Ondřej Filip's avatar
Ondřej Filip committed
706
    {
707 708
      ospf_iface_shutdown(ifa);
      ospf_iface_remove(ifa);
Ondřej Filip's avatar
Ondřej Filip committed
709 710
    }

711
  WALK_LIST_DELSAFE(oa, oax, p->area_list)
712 713
    if (oa->marked)
      ospf_area_remove(oa);
Ondřej Filip's avatar
Ondřej Filip committed
714

715
  ospf_schedule_rtcalc(p);
716

717
  return 1;
Ondřej Filip's avatar
Ondřej Filip committed
718
}
719

720

721
void
722
ospf_sh_neigh(struct proto *P, char *iff)
723
{
724
  struct ospf_proto *p = (struct ospf_proto *) P;
725
  struct ospf_iface *ifa = NULL;
726
  struct ospf_neighbor *n;
727

728
  if (p->p.proto_state != PS_UP)
729
  {
730
    cli_msg(-1013, "%s: is not up", p->p.name);
Ondřej Filip's avatar
Ondřej Filip committed
731
    cli_msg(0, "");
732 733
    return;
  }
Ondřej Filip's avatar
Ondřej Filip committed
734

735
  cli_msg(-1013, "%s:", p->p.name);
736 737
  cli_msg(-1013, "%-12s\t%3s\t%-15s\t%-5s\t%-10s %-12s", "Router ID", "Pri",
	  "     State", "DTime", "Interface", "Router IP");
738
  WALK_LIST(ifa, p->iface_list)
739
    if ((iff == NULL) || patmatch(iff, ifa->ifname))
740 741
      WALK_LIST(n, ifa->neigh_list)
	ospf_sh_neigh_info(n);
Ondřej Filip's avatar
Ondřej Filip committed
742
  cli_msg(0, "");
743
}
Ondřej Filip's avatar
Ondřej Filip committed
744 745

void
746
ospf_sh(struct proto *P)
Ondřej Filip's avatar
Ondřej Filip committed
747
{
748
  struct ospf_proto *p = (struct ospf_proto *) P;
Ondřej Filip's avatar
Ondřej Filip committed
749 750 751
  struct ospf_area *oa;
  struct ospf_iface *ifa;
  struct ospf_neighbor *n;
Ondřej Filip's avatar
Ondřej Filip committed
752
  int ifano, nno, adjno, firstfib;
Ondřej Filip's avatar
Ondřej Filip committed
753

754
  if (p->p.proto_state != PS_UP)
755
  {
756
    cli_msg(-1014, "%s: is not up", p->p.name);
Ondřej Filip's avatar
Ondřej Filip committed
757
    cli_msg(0, "");
758 759 760
    return;
  }

761
  cli_msg(-1014, "%s:", p->p.name);
762
  cli_msg(-1014, "RFC1583 compatibility: %s", (p->rfc1583 ? "enabled" : "disabled"));
763 764 765 766
  cli_msg(-1014, "Stub router: %s", (p->stub_router ? "Yes" : "No"));
  cli_msg(-1014, "RT scheduler tick: %d", p->tick);
  cli_msg(-1014, "Number of areas: %u", p->areano);
  cli_msg(-1014, "Number of LSAs in DB:\t%u", p->gr->hash_entries);
Ondřej Filip's avatar
Ondřej Filip committed
767

768
  WALK_LIST(oa, p->area_list)
Ondřej Filip's avatar
Ondřej Filip committed
769
  {
770
    cli_msg(-1014, "\tArea: %R (%u) %s", oa->areaid, oa->areaid,
Ondřej Filip's avatar
Ondřej Filip committed
771 772 773 774
	    oa->areaid == 0 ? "[BACKBONE]" : "");
    ifano = 0;
    nno = 0;
    adjno = 0;
775
    WALK_LIST(ifa, p->iface_list)
Ondřej Filip's avatar
Ondřej Filip committed
776
    {
Ondřej Filip's avatar
Ondřej Filip committed
777
      if (oa == ifa->oa)
Ondřej Filip's avatar
Ondřej Filip committed
778
      {
779
	ifano++;
780 781
	WALK_LIST(n, ifa->neigh_list)
	{
782 783 784
	  nno++;
	  if (n->state == NEIGHBOR_FULL)
	    adjno++;
785
	}
Ondřej Filip's avatar
Ondřej Filip committed
786 787
      }
    }
788 789 790

    cli_msg(-1014, "\t\tStub:\t%s", oa_is_stub(oa) ? "Yes" : "No");
    cli_msg(-1014, "\t\tNSSA:\t%s", oa_is_nssa(oa) ? "Yes" : "No");
791
    cli_msg(-1014, "\t\tTransit:\t%s", oa->trcap ? "Yes" : "No");
792 793 794 795

    if (oa_is_nssa(oa))
      cli_msg(-1014, "\t\tNSSA translation:\t%s%s", oa->translate ? "Yes" : "No",
	      oa->translate == TRANS_WAIT ? " (run down)" : "");
Ondřej Filip's avatar
Ondřej Filip committed
796 797 798
    cli_msg(-1014, "\t\tNumber of interfaces:\t%u", ifano);
    cli_msg(-1014, "\t\tNumber of neighbors:\t%u", nno);
    cli_msg(-1014, "\t\tNumber of adjacent neighbors:\t%u", adjno);
Ondřej Filip's avatar
Ondřej Filip committed
799 800

    firstfib = 1;
801
    FIB_WALK(&oa->net_fib, struct area_net, anet)
802
    {
Ondřej Filip's avatar
Ondřej Filip committed
803
      if(firstfib)
804
      {
805 806
	cli_msg(-1014, "\t\tArea networks:");
	firstfib = 0;
807
      }
808
      cli_msg(-1014, "\t\t\t%1N\t%s\t%s", anet->fn.addr,
Ondřej Filip's avatar
Ondřej Filip committed
809
		anet->hidden ? "Hidden" : "Advertise", anet->active ? "Active" : "");
810
    }
Ondřej Filip's avatar
Ondřej Filip committed
811
    FIB_WALK_END;
812 813

    firstfib = 1;
814
    FIB_WALK(&oa->enet_fib, struct area_net, anet)
815 816 817
    {
      if(firstfib)
      {
818 819
	cli_msg(-1014, "\t\tArea external networks:");
	firstfib = 0;
820
      }
821
      cli_msg(-1014, "\t\t\t%1N\t%s\t%s", anet->fn.addr,
822 823 824 825
		anet->hidden ? "Hidden" : "Advertise", anet->active ? "Active" : "");
    }
    FIB_WALK_END;

Ondřej Filip's avatar
Ondřej Filip committed
826
  }
Ondřej Filip's avatar
Ondřej Filip committed
827
  cli_msg(0, "");
Ondřej Filip's avatar
Ondřej Filip committed
828 829
}

830
void
831
ospf_sh_iface(struct proto *P, char *iff)
832
{
833
  struct ospf_proto *p = (struct ospf_proto *) P;
834
  struct ospf_iface *ifa = NULL;
835

836
  if (p->p.proto_state != PS_UP)
837
  {
838
    cli_msg(-1015, "%s: is not up", p->p.name);
Ondřej Filip's avatar
Ondřej Filip committed
839
    cli_msg(0, "");
840 841 842
    return;
  }

843 844
  cli_msg(-1015, "%s:", p->p.name);
  WALK_LIST(ifa, p->iface_list)
845
    if ((iff == NULL) || patmatch(iff, ifa->ifname))
846
      ospf_iface_info(ifa);
Ondřej Filip's avatar
Ondřej Filip committed
847
  cli_msg(0, "");
848 849
}

850 851 852
/* lsa_compare_for_state() - Compare function for 'show ospf state'
 *
 * First we want to separate network-LSAs and other LSAs (because network-LSAs
853 854 855 856
 * will be presented as network nodes and other LSAs together as router nodes)
 * Network-LSAs are sorted according to network prefix, other LSAs are sorted
 * according to originating router id (to get all LSA needed to represent one
 * router node together). Then, according to LSA type, ID and age.
857 858 859 860
 *
 * For OSPFv3, we have to handle also Prefix-LSAs. We would like to put each
 * immediately after the referenced LSA. We will make faked LSA based on ref_
 * values
861
 */
862 863 864 865 866 867

static struct ospf_lsa_header *
fake_lsa_from_prefix_lsa(struct ospf_lsa_header *dst, struct ospf_lsa_header *src,
			 struct ospf_lsa_prefix *px)
{
  dst->age = src->age;
868
  dst->type_raw = px->ref_type;
869 870 871 872 873 874 875
  dst->id = px->ref_id;
  dst->rt = px->ref_rt;
  dst->sn = src->sn;

  return dst;
}

876 877

static int lsa_compare_ospf3;
Ondřej Zajíček's avatar
Ondřej Zajíček committed
878

879
static int
880
lsa_compare_for_state(const void *p1, const void *p2)
881
{
882 883
  struct top_hash_entry *he1 = * (struct top_hash_entry **) p1;
  struct top_hash_entry *he2 = * (struct top_hash_entry **) p2;
884 885
  struct ospf_lsa_header *lsa1 = &(he1->lsa);
  struct ospf_lsa_header *lsa2 = &(he2->lsa);
886 887 888
  struct ospf_lsa_header lsatmp1, lsatmp2;
  u16 lsa1_type = he1->lsa_type;
  u16 lsa2_type = he2->lsa_type;
889

890 891 892 893
  if (he1->domain < he2->domain)
    return -1;
  if (he1->domain > he2->domain)
    return 1;
894 895


896 897 898
  /* px1 or px2 assumes OSPFv3 */
  int px1 = (lsa1_type == LSA_T_PREFIX);
  int px2 = (lsa2_type == LSA_T_PREFIX);
899 900

  if (px1)
901
  {
902
    lsa1 = fake_lsa_from_prefix_lsa(&lsatmp1, lsa1, he1->lsa_body);
903 904
    lsa1_type = lsa1->type_raw;	/* FIXME: handle unknown ref_type */
  }
905 906

  if (px2)
907
  {
908
    lsa2 = fake_lsa_from_prefix_lsa(&lsatmp2, lsa2, he2->lsa_body);
909 910 911
    lsa2_type = lsa2->type_raw;
  }

912

913 914
  int nt1 = (lsa1_type == LSA_T_NET);
  int nt2 = (lsa2_type == LSA_T_NET);
915 916 917 918 919 920

  if (nt1 != nt2)
    return nt1 - nt2;

  if (nt1)
  {
921 922 923 924 925 926 927 928
    /* In OSPFv3, networks are named based on ID of DR */
    if (lsa_compare_ospf3)
    {
      if (lsa1->rt < lsa2->rt)
	return -1;
      if (lsa1->rt > lsa2->rt)
	return 1;
    }
929 930 931

    /* For OSPFv2, this is IP of the network,
       for OSPFv3, this is interface ID */
932 933 934 935
    if (lsa1->id < lsa2->id)
      return -1;
    if (lsa1->id > lsa2->id)
      return 1;
936 937 938 939 940

    if (px1 != px2)
      return px1 - px2;

    return lsa1->sn - lsa2->sn;
941
  }
942
  else
943
  {
944 945 946 947
    if (lsa1->rt < lsa2->rt)
      return -1;
    if (lsa1->rt > lsa2->rt)
      return 1;
948

949
    if (lsa1_type < lsa2_type)
950
      return -1;
951
    if (lsa1_type > lsa2_type)
952 953 954 955 956 957
      return 1;

    if (lsa1->id < lsa2->id)
      return -1;
    if (lsa1->id > lsa2->id)
      return 1;
958 959 960

    if (px1 != px2)
      return px1 - px2;
961

962 963
    return lsa1->sn - lsa2->sn;
  }
964
}
965

966 967 968 969 970 971 972 973
static int
ext_compare_for_state(const void *p1, const void *p2)
{
  struct top_hash_entry * he1 = * (struct top_hash_entry **) p1;
  struct top_hash_entry * he2 = * (struct top_hash_entry **) p2;
  struct ospf_lsa_header *lsa1 = &(he1->lsa);
  struct ospf_lsa_header *lsa2 = &(he2->lsa);

974 975 976 977 978 979 980 981 982
  if (lsa1->rt < lsa2->rt)
    return -1;
  if (lsa1->rt > lsa2->rt)
    return 1;

  if (lsa1->id < lsa2->id)
    return -1;
  if (lsa1->id > lsa2->id)
    return 1;
983 984 985 986 987 988 989 990 991 992 993 994 995

  return lsa1->sn - lsa2->sn;
}

static inline void
show_lsa_distance(struct top_hash_entry *he)
{
  if (he->color == INSPF)
    cli_msg(-1016, "\t\tdistance %u", he->dist);
  else
    cli_msg(-1016, "\t\tunreachable");
}

996
static inline void
997
show_lsa_router(struct ospf_proto *p, struct top_hash_entry *he, int verbose)
998
{
999
  struct ospf_lsa_rt_walk rtl;
1000

1001 1002 1003
  cli_msg(-1016, "");
  cli_msg(-1016, "\trouter %R", he->lsa.rt);
  show_lsa_distance(he);
1004

1005 1006 1007 1008
  lsa_walk_rt_init(p, he, &rtl);
  while (lsa_walk_rt(&rtl))
    if (rtl.type == LSART_VLNK)
      cli_msg(-1016, "\t\tvlink %R metric %u", rtl.id, rtl.metric);
1009

1010 1011 1012 1013
  lsa_walk_rt_init(p, he, &rtl);
  while (lsa_walk_rt(&rtl))
    if (rtl.type == LSART_PTP)
      cli_msg(-1016, "\t\trouter %R metric %u", rtl.id, rtl.metric);
1014

1015 1016 1017
  lsa_walk_rt_init(p, he, &rtl);
  while (lsa_walk_rt(&rtl))
    if (rtl.type == LSART_NET)
1018
    {
1019
      if (ospf_is_v2(p))
1020
      {
1021 1022
	/* In OSPFv2, we try to find network-LSA to get prefix/pxlen */
	struct top_hash_entry *net_he = ospf_hash_find_net2(p->gr, he->domain, rtl.id);
1023

1024
	if (net_he && (net_he->lsa.age < LSA_MAXAGE))
1025 1026 1027 1028
	{
	  struct ospf_lsa_header *net_lsa = &(net_he->lsa);
	  struct ospf_lsa_net *net_ln = net_he->lsa_body;

1029
	  cli_msg(-1016, "\t\tnetwork %I/%d metric %u",
1030 1031 1032 1033 1034
		  ipa_from_u32(net_lsa->id & net_ln->optx),
		  u32_masklen(net_ln->optx), rtl.metric);
	}
	else
	  cli_msg(-1016, "\t\tnetwork [%R] metric %u", rtl.id, rtl.metric);
1035 1036
      }
      else
1037
	cli_msg(-1016, "\t\tnetwork [%R-%u] metric %u", rtl.id, rtl.nif, rtl.metric);
1038 1039
    }

1040 1041 1042 1043 1044 1045 1046 1047
  if (ospf_is_v2(p) && verbose)
  {
    lsa_walk_rt_init(p, he, &rtl);
    while (lsa_walk_rt(&rtl))
      if (rtl.type == LSART_STUB)
	cli_msg(-1016, "\t\tstubnet %I/%d metric %u",
		ipa_from_u32(rtl.id), u32_masklen(rtl.data), rtl.metric);
  }
1048 1049 1050
}

static inline void
1051
show_lsa_network(struct top_hash_entry *he, int ospf2)
1052 1053 1054 1055 1056
{
  struct ospf_lsa_header *lsa = &(he->lsa);
  struct ospf_lsa_net *ln = he->lsa_body;
  u32 i;

1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067
  if (ospf2)
  {
    cli_msg(-1016, "");
    cli_msg(-1016, "\tnetwork %I/%d", ipa_from_u32(lsa->id & ln->optx), u32_masklen(ln->optx));
    cli_msg(-1016, "\t\tdr %R", lsa->rt);
  }
  else
  {
    cli_msg(-1016, "");
    cli_msg(-1016, "\tnetwork [%R-%u]", lsa->rt, lsa->id);
  }
1068

1069 1070
  show_lsa_distance(he);

1071
  for (i = 0; i < lsa_net_count(lsa); i++)
1072
    cli_msg(-1016, "\t\trouter %R", ln->routers[i]);
1073 1074 1075
}

static inline void
1076
show_lsa_sum_net(struct top_hash_entry *he, int ospf2)
1077
{
1078
  net_addr net;
1079
  u8 pxopts;
1080
  u32 metric;
1081

1082 1083
  lsa_parse_sum_net(he, ospf2, &net, &pxopts, &metric);
  cli_msg(-1016, "\t\txnetwork %N metric %u", &net, metric);
1084 1085 1086
}

static inline void
1087
show_lsa_sum_rt(struct top_hash_entry *he, int ospf2)
1088
{
1089
  u32 metric;
Ondřej Zajíček's avatar
Ondřej Zajíček committed
1090
  u32 dst_rid;
1091
  u32 options;
1092

1093 1094
  lsa_parse_sum_rt(he, ospf2, &dst_rid, &metric, &options);
  cli_msg(-1016, "\t\txrouter %R metric %u", dst_rid, metric);
1095 1096 1097 1098
}


static inline void
1099
show_lsa_external(struct top_hash_entry *he, int ospf2)
1100
{
1101
  struct ospf_lsa_ext_local rt;
1102
  char str_via[IPA_MAX_TEXT_LENGTH + 8] = "";
1103
  char str_tag[16] = "";
1104

Ondřej Zajíček's avatar