Statistics
| Branch: | Revision:

iof-bird-daemon / proto / ospf / ospf.c @ 1a61882d

History | View | Annotate | Download (24.5 KB)

1 c1f8dc91 Ondrej Filip
/*
2
 *        BIRD -- OSPF
3
 *
4 7ab3ff6a Ondrej Filip
 *        (c) 1999 - 2000 Ondrej Filip <feela@network.cz>
5 c1f8dc91 Ondrej Filip
 *
6
 *        Can be freely distributed and used under the terms of the GNU GPL.
7
 */
8
9 89755a86 Ondrej Filip
/**
10
 * DOC: Open Shortest Path First (OSPF)
11
 * 
12 725270cb Martin Mares
 * The OSPF protocol is quite complicated and its complex implemenation is
13 baa5dd6c Ondrej Filip
 * split to many files. In |ospf.c|, you will find mainly the interface
14 725270cb Martin Mares
 * for communication with the core (e.g., reconfiguration hooks, shutdown
15 baa5dd6c Ondrej Filip
 * and initialisation and so on). In |packet.c|, you will find various
16
 * functions for sending and receiving generic OSPF packets. There are
17
 * also routines for authentication and checksumming. File |iface.c| contains
18
 * the interface state machine and functions for allocation and deallocation of OSPF's
19 725270cb Martin Mares
 * interface data structures. Source |neighbor.c| includes the neighbor state
20 baa5dd6c Ondrej Filip
 * machine and functions for election of Designated Router and Backup
21
 * Designated router. In |hello.c|, there are routines for sending
22 725270cb Martin Mares
 * and receiving of hello packets as well as functions for maintaining
23
 * wait times and the inactivity timer. Files |lsreq.c|, |lsack.c|, |dbdes.c|
24
 * contain functions for sending and receiving of link-state requests,
25 baa5dd6c Ondrej Filip
 * link-state acknowledgements and database descriptions respectively.
26 725270cb Martin Mares
 * In |lsupd.c|, there are functions for sending and receiving
27
 * of link-state updates and also the flooding algorithm. Source |topology.c| is
28 baa5dd6c Ondrej Filip
 * a place where routines for searching LSAs in the link-state database,
29 725270cb Martin Mares
 * adding and deleting them reside, there also are functions for originating
30 baa5dd6c Ondrej Filip
 * of various types of LSAs (router LSA, net LSA, external LSA). File |rt.c|
31 725270cb Martin Mares
 * contains routines for calculating the routing table. |lsalib.c| is a set
32 baa5dd6c Ondrej Filip
 * of various functions for working with the LSAs (endianity conversions,
33 725270cb Martin Mares
 * calculation of checksum etc.).
34 89755a86 Ondrej Filip
 *
35 725270cb Martin Mares
 * One instance of the protocol is able to hold LSA databases for
36
 * multiple OSPF areas, to exchange routing information between
37
 * multiple neighbors and to calculate the routing tables. The core
38
 * structure is &proto_ospf to which multiple &ospf_area and
39 baa5dd6c Ondrej Filip
 * &ospf_iface structures are connected. &ospf_area is also connected to
40 725270cb Martin Mares
 * &top_hash_graph which is a dynamic hashing structure that
41
 * describes the link-state database. It allows fast search, addition
42
 * and deletion. Each LSA is kept in two pieces: header and body. Both of them are
43 baa5dd6c Ondrej Filip
 * kept in the endianity of the CPU.
44 37c3e558 Ondrej Filip
 * 
45 725270cb Martin Mares
 * Every area has its own area_disp() which is
46
 * responsible for late originating of router LSA, calculating
47 baa5dd6c Ondrej Filip
 * of the routing table and it also ages and flushes the LSAs. This
48 89755a86 Ondrej Filip
 * function is called in regular intervals.
49 725270cb Martin Mares
 * To every &ospf_iface, we connect one or more
50
 * &ospf_neighbor's -- a structure containing many timers and queues
51
 * for building adjacency and for exchange of routing messages.
52 89755a86 Ondrej Filip
 *
53 725270cb Martin Mares
 * BIRD's OSPF implementation respects RFC2328 in every detail, but
54 baa5dd6c Ondrej Filip
 * some of internal algorithms do differ. The RFC recommends making a snapshot
55
 * of the link-state database when a new adjacency is forming and sending
56
 * the database description packets based on the information in this 
57 725270cb Martin Mares
 * snapshot. The database can be quite large in some networks, so
58 baa5dd6c Ondrej Filip
 * rather we walk through a &slist structure which allows us to
59
 * continue even if the actual LSA we were working with is deleted. New
60
 * LSAs are added at the tail of this &slist.
61 89755a86 Ondrej Filip
 *
62 725270cb Martin Mares
 * We also don't keep a separate OSPF routing table, because the core
63
 * helps us by being able to recognize when a route is updated
64
 * to an identical one and it suppresses the update automatically.
65
 * Due to this, we can flush all the routes we've recalculated and
66 baa5dd6c Ondrej Filip
 * also those we've deleted to the core's routing table and the
67 725270cb Martin Mares
 * core will take care of the rest. This simplifies the process
68
 * and conserves memory.
69 89755a86 Ondrej Filip
 */
70
71 c1f8dc91 Ondrej Filip
#include "ospf.h"
72
73 d83faf8d Martin Mares
static int ospf_rte_better(struct rte *new, struct rte *old);
74
static int ospf_rte_same(struct rte *new, struct rte *old);
75 b8f17cf1 Ondrej Filip
static void area_disp(timer *timer);
76
static void ospf_disp(timer *timer);
77
78 d83faf8d Martin Mares
79 c1f8dc91 Ondrej Filip
static int
80
ospf_start(struct proto *p)
81
{
82 2e10a170 Ondrej Filip
  struct proto_ospf *po = (struct proto_ospf *) p;
83
  struct ospf_config *c = (struct ospf_config *) (p->cf);
84 51cff78b Ondrej Filip
  struct ospf_area_config *ac;
85
  struct ospf_area *oa;
86 2e10a170 Ondrej Filip
  struct area_net *anet, *antmp;
87 f14032ef Ondrej Filip
88 b8f17cf1 Ondrej Filip
  po->rfc1583 = c->rfc1583;
89
  po->ebit = 0;
90
91
  po->tick = c->tick;
92
  po->disp_timer = tm_new(po->proto.pool);
93
  po->disp_timer->data = po;
94
  po->disp_timer->randomize = 0;
95
  po->disp_timer->hook = ospf_disp;
96
  po->disp_timer->recurrent = po->tick;
97
  tm_start(po->disp_timer, 1);
98 5970fcda Ondrej Filip
  init_list(&(po->iface_list));
99
  init_list(&(po->area_list));
100 1a61882d Ondrej Filip
  fib_init(&po->rtf[0], p->pool, sizeof(ort), 16, ospf_rt_initort);
101
  fib_init(&po->rtf[1], p->pool, sizeof(ort), 16, ospf_rt_initort);
102 2e10a170 Ondrej Filip
  po->areano = 0;
103
  if (EMPTY_LIST(c->area_list))
104 51cff78b Ondrej Filip
  {
105 b8f17cf1 Ondrej Filip
    log(L_ERR "Cannot start, no OSPF areas configured!");
106 51cff78b Ondrej Filip
    return PS_DOWN;
107
  }
108 5b1a92e6 Ondrej Filip
109 2e10a170 Ondrej Filip
  WALK_LIST(ac, c->area_list)
110 51cff78b Ondrej Filip
  {
111 2e10a170 Ondrej Filip
    oa = mb_allocz(po->proto.pool, sizeof(struct ospf_area));
112 c926eee7 Ondrej Filip
    add_tail(&po->area_list, NODE oa);
113 51cff78b Ondrej Filip
    po->areano++;
114 2e10a170 Ondrej Filip
    oa->stub = ac->stub;
115
    oa->tick = ac->tick;
116
    oa->areaid = ac->areaid;
117 d5d9693c Ondrej Filip
    oa->gr = ospf_top_new(p->pool);
118 51cff78b Ondrej Filip
    s_init_list(&(oa->lsal));
119 2e10a170 Ondrej Filip
    oa->rt = NULL;
120
    oa->po = po;
121
    oa->disp_timer = tm_new(po->proto.pool);
122
    oa->disp_timer->data = oa;
123
    oa->disp_timer->randomize = 0;
124
    oa->disp_timer->hook = area_disp;
125
    oa->disp_timer->recurrent = oa->tick;
126 b8f17cf1 Ondrej Filip
    tm_start(oa->disp_timer, 2);
127 c926eee7 Ondrej Filip
    init_list(&oa->net_list);
128 2e10a170 Ondrej Filip
    WALK_LIST(anet, ac->net_list)
129 c926eee7 Ondrej Filip
    {
130 2e10a170 Ondrej Filip
      antmp = mb_allocz(po->proto.pool, sizeof(struct area_net));
131
      antmp->px.addr = anet->px.addr;
132
      antmp->px.len = anet->px.len;
133
      antmp->hidden = anet->hidden;
134 c926eee7 Ondrej Filip
      add_tail(&oa->net_list, NODE antmp);
135
    }
136 51cff78b Ondrej Filip
  }
137 c1f8dc91 Ondrej Filip
  return PS_UP;
138
}
139
140
static void
141
ospf_dump(struct proto *p)
142
{
143 b332fcdf Ondrej Filip
  struct ospf_iface *ifa;
144
  struct ospf_neighbor *n;
145 2e10a170 Ondrej Filip
  struct proto_ospf *po = (struct proto_ospf *) p;
146 15087574 Ondrej Filip
  struct ospf_area *oa;
147 c1f8dc91 Ondrej Filip
148 ee4880c8 Ondrej Filip
  OSPF_TRACE(D_EVENTS, "Area number: %d", po->areano);
149 b332fcdf Ondrej Filip
150 163b2073 Ondrej Filip
  WALK_LIST(ifa, po->iface_list)
151 b332fcdf Ondrej Filip
  {
152 f14032ef Ondrej Filip
    OSPF_TRACE(D_EVENTS, "Interface: %s", ifa->iface->name);
153
    OSPF_TRACE(D_EVENTS, "state: %u", ifa->state);
154
    OSPF_TRACE(D_EVENTS, "DR:  %I", ifa->drid);
155
    OSPF_TRACE(D_EVENTS, "BDR: %I", ifa->bdrid);
156 b332fcdf Ondrej Filip
    WALK_LIST(n, ifa->neigh_list)
157
    {
158 ee4880c8 Ondrej Filip
      OSPF_TRACE(D_EVENTS, "  neighbor %I in state %u", n->rid, n->state);
159 b332fcdf Ondrej Filip
    }
160
  }
161 163b2073 Ondrej Filip
162 2e10a170 Ondrej Filip
  WALK_LIST(NODE oa, po->area_list)
163 15087574 Ondrej Filip
  {
164 f14032ef Ondrej Filip
    OSPF_TRACE(D_EVENTS, "LSA graph dump for area \"%I\" start:", oa->areaid);
165 2e10a170 Ondrej Filip
    ospf_top_dump(oa->gr, p);
166
    OSPF_TRACE(D_EVENTS, "LSA graph dump for area \"%I\" finished",
167
               oa->areaid);
168 15087574 Ondrej Filip
  }
169 c6c56264 Ondrej Filip
  neigh_dump_all();
170 c1f8dc91 Ondrej Filip
}
171
172
static struct proto *
173
ospf_init(struct proto_config *c)
174
{
175 4c630a6d Ondrej Filip
  struct proto *p = proto_new(c, sizeof(struct proto_ospf));
176 c1f8dc91 Ondrej Filip
177 2d5b9992 Ondrej Filip
  p->import_control = ospf_import_control;
178 5919c66e Martin Mares
  p->make_tmp_attrs = ospf_make_tmp_attrs;
179
  p->store_tmp_attrs = ospf_store_tmp_attrs;
180 e8085aba Ondrej Filip
  p->rt_notify = ospf_rt_notify;
181 b9ed99f7 Ondrej Filip
  p->if_notify = ospf_iface_notify;
182 5919c66e Martin Mares
  p->rte_better = ospf_rte_better;
183
  p->rte_same = ospf_rte_same;
184 163b2073 Ondrej Filip
185 c1f8dc91 Ondrej Filip
  return p;
186
}
187
188 bbd76b42 Ondrej Filip
/* If new is better return 1 */
189
static int
190
ospf_rte_better(struct rte *new, struct rte *old)
191
{
192 1a61882d Ondrej Filip
  /* FIXME this is wrong */
193 2e10a170 Ondrej Filip
  if (new->u.ospf.metric1 == LSINFINITY)
194
    return 0;
195 bbd76b42 Ondrej Filip
196 d6a7e2fb Ondrej Filip
  /* External paths are always longer that internal */
197 2e10a170 Ondrej Filip
  if (((new->attrs->source == RTS_OSPF)
198
       || (new->attrs->source == RTS_OSPF_IA))
199
      && (old->attrs->source == RTS_OSPF_EXT))
200
    return 1;
201
  if (((old->attrs->source == RTS_OSPF)
202
       || (old->attrs->source == RTS_OSPF_IA))
203
      && (new->attrs->source == RTS_OSPF_EXT))
204
    return 0;
205
206
  if (new->u.ospf.metric2 < old->u.ospf.metric2)
207 bbd76b42 Ondrej Filip
  {
208 2e10a170 Ondrej Filip
    if (old->u.ospf.metric2 == LSINFINITY)
209
      return 0;                        /* Old is E1, new is E2 */
210
    return 1;                        /* Both are E2 */
211 bbd76b42 Ondrej Filip
  }
212 2e10a170 Ondrej Filip
213
  if (new->u.ospf.metric2 > old->u.ospf.metric2)
214 bbd76b42 Ondrej Filip
  {
215 2e10a170 Ondrej Filip
    if (new->u.ospf.metric2 == LSINFINITY)
216
      return 1;                        /* New is E1, old is E2 */
217
    return 0;                        /* Both are E2 */
218 bbd76b42 Ondrej Filip
  }
219 d6a7e2fb Ondrej Filip
220
  /* 
221
   * E2 metrics are the same. It means that:
222
   * 1) Paths are E2 with same metric
223
   * 2) Paths are E1.
224
   */
225
226 2e10a170 Ondrej Filip
  if (new->u.ospf.metric1 < old->u.ospf.metric1)
227
    return 1;
228
  return 0;                        /* Old is shorter or same */
229 bbd76b42 Ondrej Filip
}
230
231 00c1f79a Ondrej Filip
static int
232
ospf_rte_same(struct rte *new, struct rte *old)
233
{
234 5919c66e Martin Mares
  /* new->attrs == old->attrs always */
235
  return
236
    new->u.ospf.metric1 == old->u.ospf.metric1 &&
237
    new->u.ospf.metric2 == old->u.ospf.metric2 &&
238 2e10a170 Ondrej Filip
    new->u.ospf.tag == old->u.ospf.tag;
239 5919c66e Martin Mares
}
240 00c1f79a Ondrej Filip
241 5919c66e Martin Mares
static ea_list *
242 2e10a170 Ondrej Filip
ospf_build_attrs(ea_list * next, struct linpool *pool, u32 m1, u32 m2,
243
                 u32 tag)
244 5919c66e Martin Mares
{
245 2e10a170 Ondrej Filip
  struct ea_list *l =
246
    lp_alloc(pool, sizeof(struct ea_list) + 3 * sizeof(eattr));
247 5919c66e Martin Mares
248
  l->next = next;
249
  l->flags = EALF_SORTED;
250
  l->count = 3;
251
  l->attrs[0].id = EA_OSPF_METRIC1;
252
  l->attrs[0].flags = 0;
253
  l->attrs[0].type = EAF_TYPE_INT | EAF_TEMP;
254
  l->attrs[0].u.data = m1;
255
  l->attrs[1].id = EA_OSPF_METRIC2;
256
  l->attrs[1].flags = 0;
257
  l->attrs[1].type = EAF_TYPE_INT | EAF_TEMP;
258
  l->attrs[1].u.data = m2;
259
  l->attrs[2].id = EA_OSPF_TAG;
260
  l->attrs[2].flags = 0;
261
  l->attrs[2].type = EAF_TYPE_INT | EAF_TEMP;
262
  l->attrs[2].u.data = tag;
263
  return l;
264 00c1f79a Ondrej Filip
}
265
266 70a38319 Ondrej Filip
void
267 b9ed99f7 Ondrej Filip
schedule_net_lsa(struct ospf_iface *ifa)
268
{
269 2e10a170 Ondrej Filip
  ifa->orignet = 1;
270 b9ed99f7 Ondrej Filip
}
271
272
void
273 70a38319 Ondrej Filip
schedule_rt_lsa(struct ospf_area *oa)
274
{
275 b8f17cf1 Ondrej Filip
  struct proto *p = &oa->po->proto;
276 70a38319 Ondrej Filip
277 f14032ef Ondrej Filip
  OSPF_TRACE(D_EVENTS, "Scheduling RT lsa origination for area %I.",
278 2e10a170 Ondrej Filip
             oa->areaid);
279
  oa->origrt = 1;
280 70a38319 Ondrej Filip
}
281
282
void
283 b8f17cf1 Ondrej Filip
schedule_rtcalc(struct proto_ospf *po)
284 70a38319 Ondrej Filip
{
285 2e10a170 Ondrej Filip
  struct proto *p = &po->proto;
286 70a38319 Ondrej Filip
287 b8f17cf1 Ondrej Filip
  if (po->calcrt)
288 2e10a170 Ondrej Filip
    return;
289 3df1e804 Ondrej Filip
290 b8f17cf1 Ondrej Filip
  OSPF_TRACE(D_EVENTS, "Scheduling RT calculation.");
291
  po->calcrt = 1;
292 70a38319 Ondrej Filip
}
293
294 6f58dc64 Ondrej Filip
/**
295 baa5dd6c Ondrej Filip
 * area_disp - invokes link-state database aging, origination of
296 6f58dc64 Ondrej Filip
 * router LSA and routing table calculation
297 6567e6cf Martin Mares
 * @timer: it's called every @ospf_area->tick seconds
298 6f58dc64 Ondrej Filip
 *
299 baa5dd6c Ondrej Filip
 * It invokes aging and when @ospf_area->origrt is set to 1, start
300
 * function for origination of router LSA and network LSAs.
301 6f58dc64 Ondrej Filip
 */
302 70a38319 Ondrej Filip
void
303 2e10a170 Ondrej Filip
area_disp(timer * timer)
304 70a38319 Ondrej Filip
{
305 2e10a170 Ondrej Filip
  struct ospf_area *oa = timer->data;
306
  struct proto_ospf *po = oa->po;
307 78e2c6cc Ondrej Filip
  struct ospf_iface *ifa;
308 70a38319 Ondrej Filip
309
  /* Now try to originage rt_lsa */
310 2e10a170 Ondrej Filip
  if (oa->origrt)
311
    originate_rt_lsa(oa);
312 78e2c6cc Ondrej Filip
313
  /* Now try to originate network LSA's */
314
  WALK_LIST(ifa, po->iface_list)
315
  {
316 2e10a170 Ondrej Filip
    if (ifa->orignet && (ifa->an == oa->areaid))
317
      originate_net_lsa(ifa);
318 78e2c6cc Ondrej Filip
  }
319 70a38319 Ondrej Filip
320 e59e310e Ondrej Filip
  /* Age LSA DB */
321
  ospf_age(oa);
322 b8f17cf1 Ondrej Filip
}
323
324
void
325
ospf_disp(timer * timer)
326
{
327
  struct proto_ospf *po = timer->data;
328 e59e310e Ondrej Filip
329
  /* Calculate routing table */
330 b8f17cf1 Ondrej Filip
  if (po->calcrt)
331
    ospf_rt_spf (po);
332
  po->calcrt = 0;
333 70a38319 Ondrej Filip
}
334
335 b8f17cf1 Ondrej Filip
336
337 6f58dc64 Ondrej Filip
/**
338
 * ospf_import_control - accept or reject new route from nest's routing table
339
 * @p: current instance of protocol
340 6567e6cf Martin Mares
 * @new: the new route
341 baa5dd6c Ondrej Filip
 * @attrs: list of attributes
342
 * @pool: pool for allocation of attributes
343 6f58dc64 Ondrej Filip
 *
344 baa5dd6c Ondrej Filip
 * Its quite simple. It does not accept our own routes and leaves the decision on
345
 * import to the filters.
346 6f58dc64 Ondrej Filip
 */
347
348 2d5b9992 Ondrej Filip
int
349 2e10a170 Ondrej Filip
ospf_import_control(struct proto *p, rte ** new, ea_list ** attrs,
350
                    struct linpool *pool)
351 2d5b9992 Ondrej Filip
{
352 2e10a170 Ondrej Filip
  rte *e = *new;
353 2d5b9992 Ondrej Filip
354 2e10a170 Ondrej Filip
  if (p == e->attrs->proto)
355
    return -1;                        /* Reject our own routes */
356 8441f179 Martin Mares
  *attrs = ospf_build_attrs(*attrs, pool, LSINFINITY, 10000, 0);
357 2e10a170 Ondrej Filip
  return 0;                        /* Leave decision to the filters */
358 5919c66e Martin Mares
}
359 2d5b9992 Ondrej Filip
360 5919c66e Martin Mares
struct ea_list *
361
ospf_make_tmp_attrs(struct rte *rt, struct linpool *pool)
362
{
363 2e10a170 Ondrej Filip
  return ospf_build_attrs(NULL, pool, rt->u.ospf.metric1, rt->u.ospf.metric2,
364
                          rt->u.ospf.tag);
365 5919c66e Martin Mares
}
366
367
void
368
ospf_store_tmp_attrs(struct rte *rt, struct ea_list *attrs)
369
{
370 8441f179 Martin Mares
  rt->u.ospf.metric1 = ea_get_int(attrs, EA_OSPF_METRIC1, LSINFINITY);
371
  rt->u.ospf.metric2 = ea_get_int(attrs, EA_OSPF_METRIC2, 10000);
372 2e10a170 Ondrej Filip
  rt->u.ospf.tag = ea_get_int(attrs, EA_OSPF_TAG, 0);
373 2d5b9992 Ondrej Filip
}
374
375 6f58dc64 Ondrej Filip
/**
376 baa5dd6c Ondrej Filip
 * ospf_shutdown - Finish of OSPF instance
377 6f58dc64 Ondrej Filip
 * @p: current instance of protocol
378
 *
379 baa5dd6c Ondrej Filip
 * RFC does not define any action that should be taken before router
380 6f58dc64 Ondrej Filip
 * shutdown. To make my neighbors react as fast as possible, I send
381
 * them hello packet with empty neighbor list. They should start
382 baa5dd6c Ondrej Filip
 * their neighbor state machine with event %NEIGHBOR_1WAY.
383 6f58dc64 Ondrej Filip
 */
384
385 4bd28fb6 Ondrej Filip
static int
386
ospf_shutdown(struct proto *p)
387
{
388 2e10a170 Ondrej Filip
  struct proto_ospf *po = (struct proto_ospf *) p;
389 4bd28fb6 Ondrej Filip
  struct ospf_iface *ifa;
390 ee4880c8 Ondrej Filip
  OSPF_TRACE(D_EVENTS, "Shutdown requested");
391 4bd28fb6 Ondrej Filip
392
  /* And send to all my neighbors 1WAY */
393 2e10a170 Ondrej Filip
  WALK_LIST(ifa, po->iface_list) ospf_iface_shutdown(ifa);
394
395 4bd28fb6 Ondrej Filip
  return PS_DOWN;
396
}
397
398 e8085aba Ondrej Filip
void
399 2e10a170 Ondrej Filip
ospf_rt_notify(struct proto *p, net * n, rte * new, rte * old UNUSED,
400
               ea_list * attrs)
401 e8085aba Ondrej Filip
{
402 2e10a170 Ondrej Filip
  struct proto_ospf *po = (struct proto_ospf *) p;
403 e8085aba Ondrej Filip
404 baa5dd6c Ondrej Filip
/* Temporarily down write anything
405 ee4880c8 Ondrej Filip
  OSPF_TRACE(D_EVENTS, "Got route %I/%d %s", p->name, n->n.prefix,
406 e8085aba Ondrej Filip
    n->n.pxlen, new ? "up" : "down");
407 52fa3e38 Ondrej Filip
*/
408 e8085aba Ondrej Filip
409 2e10a170 Ondrej Filip
  if (new)                        /* Got some new route */
410 e8085aba Ondrej Filip
  {
411 5919c66e Martin Mares
    originate_ext_lsa(n, new, po, attrs);
412 e8085aba Ondrej Filip
  }
413
  else
414
  {
415 2e10a170 Ondrej Filip
    u32 rtid = po->proto.cf->global->router_id;
416 4bd28fb6 Ondrej Filip
    struct ospf_area *oa;
417
    struct top_hash_entry *en;
418 2e10a170 Ondrej Filip
    u32 pr = ipa_to_u32(n->n.prefix);
419 273fd2c1 Ondrej Filip
    struct ospf_lsa_ext *ext;
420
    int i;
421 2e10a170 Ondrej Filip
    int max = max_ext_lsa(n->n.pxlen);
422 4bd28fb6 Ondrej Filip
423
    /* Flush old external LSA */
424
    WALK_LIST(oa, po->area_list)
425
    {
426 2e10a170 Ondrej Filip
      for (i = 0; i < max; i++, pr++)
427 273fd2c1 Ondrej Filip
      {
428 2e10a170 Ondrej Filip
        if (en = ospf_hash_find(oa->gr, pr, rtid, LSA_T_EXT))
429
        {
430
          ext = en->lsa_body;
431
          if (ipa_compare(ext->netmask, ipa_mkmask(n->n.pxlen)) == 0)
432
          {
433
            ospf_lsupd_flush_nlsa(en, oa);
434
            break;
435
          }
436
        }
437 273fd2c1 Ondrej Filip
      }
438 4bd28fb6 Ondrej Filip
    }
439 e8085aba Ondrej Filip
  }
440
}
441
442 4414d9a5 Ondrej Filip
static void
443 2e10a170 Ondrej Filip
ospf_get_status(struct proto *p, byte * buf)
444 4414d9a5 Ondrej Filip
{
445 2e10a170 Ondrej Filip
  struct proto_ospf *po = (struct proto_ospf *) p;
446 4414d9a5 Ondrej Filip
447 2e10a170 Ondrej Filip
  if (p->proto_state == PS_DOWN)
448
    buf[0] = 0;
449 4414d9a5 Ondrej Filip
  else
450
  {
451
    struct ospf_iface *ifa;
452
    struct ospf_neighbor *n;
453 2e10a170 Ondrej Filip
    int adj = 0;
454 4414d9a5 Ondrej Filip
455 2e10a170 Ondrej Filip
    WALK_LIST(ifa, po->iface_list)
456
      WALK_LIST(n, ifa->neigh_list) if (n->state == NEIGHBOR_FULL)
457
      adj = 1;
458 4414d9a5 Ondrej Filip
459 2e10a170 Ondrej Filip
    if (adj == 0)
460
      strcpy(buf, "Alone");
461
    else
462
      strcpy(buf, "Running");
463 4414d9a5 Ondrej Filip
  }
464
}
465
466 f7c0525e Ondrej Filip
static void
467 2e10a170 Ondrej Filip
ospf_get_route_info(rte * rte, byte * buf, ea_list * attrs UNUSED)
468 f7c0525e Ondrej Filip
{
469 2e10a170 Ondrej Filip
  char met = ' ';
470
  char type = ' ';
471 f7c0525e Ondrej Filip
472 2e10a170 Ondrej Filip
  if (rte->attrs->source == RTS_OSPF_EXT)
473 05dbc97b Ondrej Filip
  {
474 2e10a170 Ondrej Filip
    met = '1';
475
    type = 'E';
476 a7a3a0a3 Ondrej Filip
477 05dbc97b Ondrej Filip
  }
478 2e10a170 Ondrej Filip
  if (rte->u.ospf.metric2 != LSINFINITY)
479
    met = '2';
480
  if (rte->attrs->source == RTS_OSPF_IA)
481
    type = 'A';
482
  if (rte->attrs->source == RTS_OSPF)
483
    type = 'I';
484 73232f6b Ondrej Filip
  buf += bsprintf(buf, " %c", type);
485 2e10a170 Ondrej Filip
  if (met != ' ')
486
    buf += bsprintf(buf, "%c", met);
487 d6a7e2fb Ondrej Filip
  buf += bsprintf(buf, " (%d/%d", rte->pref, rte->u.ospf.metric1);
488 2e10a170 Ondrej Filip
  if (rte->u.ospf.metric2 != LSINFINITY)
489
    buf += bsprintf(buf, "/%d", rte->u.ospf.metric2);
490 d6a7e2fb Ondrej Filip
  buf += bsprintf(buf, ")");
491 2e10a170 Ondrej Filip
  if (rte->attrs->source == RTS_OSPF_EXT && rte->u.ospf.tag)
492 a7a3a0a3 Ondrej Filip
  {
493 23df5e4c Martin Mares
    buf += bsprintf(buf, " [%x]", rte->u.ospf.tag);
494 a7a3a0a3 Ondrej Filip
  }
495 f7c0525e Ondrej Filip
}
496
497 5919c66e Martin Mares
static int
498 2e10a170 Ondrej Filip
ospf_get_attr(eattr * a, byte * buf)
499 5919c66e Martin Mares
{
500
  switch (a->id)
501 2e10a170 Ondrej Filip
  {
502
  case EA_OSPF_METRIC1:
503
    bsprintf(buf, "metric1");
504
    return GA_NAME;
505
  case EA_OSPF_METRIC2:
506
    bsprintf(buf, "metric2");
507
    return GA_NAME;
508
  case EA_OSPF_TAG:
509
    bsprintf(buf, "tag: %08x", a->u.data);
510
    return GA_FULL;
511
  default:
512
    return GA_UNKNOWN;
513
  }
514 5919c66e Martin Mares
}
515 6f58dc64 Ondrej Filip
516 edc34dc9 Ondrej Filip
static int
517
ospf_patt_compare(struct ospf_iface_patt *a, struct ospf_iface_patt *b)
518
{
519 2e10a170 Ondrej Filip
  return ((a->type == b->type) && (a->priority == b->priority));
520 edc34dc9 Ondrej Filip
}
521 5919c66e Martin Mares
522 6f58dc64 Ondrej Filip
/**
523
 * ospf_reconfigure - reconfiguration hook
524
 * @p: current instance of protocol (with old configuration)
525
 * @c: new configuration requested by user
526
 *
527 baa5dd6c Ondrej Filip
 * This hook tries to be a little bit intelligent. Instance of OSPF
528 6f58dc64 Ondrej Filip
 * will survive change of many constants like hello interval,
529 baa5dd6c Ondrej Filip
 * password change, addition or deletion of some neighbor on
530 6f58dc64 Ondrej Filip
 * nonbroadcast network, cost of interface, etc.
531
 */
532 80787d41 Ondrej Filip
static int
533
ospf_reconfigure(struct proto *p, struct proto_config *c)
534
{
535 2e10a170 Ondrej Filip
  struct ospf_config *old = (struct ospf_config *) (p->cf);
536
  struct ospf_config *new = (struct ospf_config *) c;
537
  struct ospf_area_config *ac1, *ac2;
538
  struct proto_ospf *po = (struct proto_ospf *) p;
539
  struct ospf_iface_patt *ip1, *ip2;
540 edc34dc9 Ondrej Filip
  struct ospf_iface *ifa;
541 2e10a170 Ondrej Filip
  struct nbma_node *nb1, *nb2, *nbnx;
542
  struct ospf_area *oa = NULL;
543
  struct area_net *anet, *antmp;
544 edc34dc9 Ondrej Filip
  int found;
545
546 2e10a170 Ondrej Filip
  po->rfc1583 = new->rfc1583;
547 b8f17cf1 Ondrej Filip
  schedule_rtcalc(po);
548 edc34dc9 Ondrej Filip
549 2e10a170 Ondrej Filip
  ac1 = HEAD(old->area_list);
550
  ac2 = HEAD(new->area_list);
551 edc34dc9 Ondrej Filip
552
  /* I should get it in same order */
553 2e10a170 Ondrej Filip
554
  while (((NODE(ac1))->next != NULL) && ((NODE(ac2))->next != NULL))
555 edc34dc9 Ondrej Filip
  {
556 2e10a170 Ondrej Filip
    if (ac1->areaid != ac2->areaid)
557
      return 0;
558
    if (ac1->stub != ac2->stub)
559
      return 0;                        /* FIXME: non zero values can change */
560 c926eee7 Ondrej Filip
561 2e10a170 Ondrej Filip
    WALK_LIST(oa, po->area_list) if (oa->areaid == ac2->areaid)
562
      break;
563 c926eee7 Ondrej Filip
564 2e10a170 Ondrej Filip
    if (!oa)
565
      return 0;
566 c926eee7 Ondrej Filip
567 2e10a170 Ondrej Filip
    if (ac1->tick != ac2->tick)
568 edc34dc9 Ondrej Filip
    {
569 2e10a170 Ondrej Filip
      if (oa->areaid == ac2->areaid)
570 edc34dc9 Ondrej Filip
      {
571 2e10a170 Ondrej Filip
        oa->tick = ac2->tick;
572
        tm_start(oa->disp_timer, oa->tick);
573
        OSPF_TRACE(D_EVENTS,
574
                   "Changing tick interval on area %I from %d to %d",
575
                   oa->areaid, ac1->tick, ac2->tick);
576
        break;
577 edc34dc9 Ondrej Filip
      }
578
    }
579
580 c926eee7 Ondrej Filip
    /* Change net_list */
581
    WALK_LIST_DELSAFE(anet, antmp, oa->net_list)
582
    {
583 2e10a170 Ondrej Filip
      rem_node(NODE anet);
584
      mb_free(anet);
585 c926eee7 Ondrej Filip
    }
586
    WALK_LIST(anet, ac2->net_list)
587
    {
588 2e10a170 Ondrej Filip
      antmp = mb_alloc(p->pool, sizeof(struct area_net));
589
      antmp->px.addr = anet->px.addr;
590
      antmp->px.len = anet->px.len;
591
      antmp->hidden = anet->hidden;
592
      add_tail(&oa->net_list, NODE antmp);
593 c926eee7 Ondrej Filip
    }
594
595 2e10a170 Ondrej Filip
    if (!iface_patts_equal(&ac1->patt_list, &ac2->patt_list,
596
                           (void *) ospf_patt_compare))
597
      return 0;
598 edc34dc9 Ondrej Filip
599
    WALK_LIST(ifa, po->iface_list)
600
    {
601 2e10a170 Ondrej Filip
      if (ip1 = (struct ospf_iface_patt *)
602
          iface_patt_match(&ac1->patt_list, ifa->iface))
603 edc34dc9 Ondrej Filip
      {
604 2e10a170 Ondrej Filip
        /* Now reconfigure interface */
605
        if (!(ip2 = (struct ospf_iface_patt *)
606
              iface_patt_match(&ac2->patt_list, ifa->iface)))
607
          return 0;
608 edc34dc9 Ondrej Filip
609
        /* HELLO TIMER */
610 2e10a170 Ondrej Filip
        if (ip1->helloint != ip2->helloint)
611 edc34dc9 Ondrej Filip
        {
612 2e10a170 Ondrej Filip
          ifa->helloint = ip2->helloint;
613
          ifa->hello_timer->recurrent = ifa->helloint;
614
          tm_start(ifa->hello_timer, ifa->helloint);
615 edc34dc9 Ondrej Filip
          OSPF_TRACE(D_EVENTS,
616 2e10a170 Ondrej Filip
                     "Changing hello interval on interface %s from %d to %d",
617
                     ifa->iface->name, ip1->helloint, ip2->helloint);
618 edc34dc9 Ondrej Filip
        }
619
620 5ddec4e6 Ondrej Filip
        /* POLL TIMER */
621 2e10a170 Ondrej Filip
        if (ip1->pollint != ip2->pollint)
622 5ddec4e6 Ondrej Filip
        {
623 2e10a170 Ondrej Filip
          ifa->pollint = ip2->helloint;
624
          ifa->poll_timer->recurrent = ifa->pollint;
625
          tm_start(ifa->poll_timer, ifa->pollint);
626 5ddec4e6 Ondrej Filip
          OSPF_TRACE(D_EVENTS,
627 2e10a170 Ondrej Filip
                     "Changing poll interval on interface %s from %d to %d",
628
                     ifa->iface->name, ip1->pollint, ip2->pollint);
629 5ddec4e6 Ondrej Filip
        }
630
631 fa6c2405 Ondrej Filip
        /* COST */
632 2e10a170 Ondrej Filip
        if (ip1->cost != ip2->cost)
633 fa6c2405 Ondrej Filip
        {
634 2e10a170 Ondrej Filip
          ifa->cost = ip2->cost;
635 fa6c2405 Ondrej Filip
          OSPF_TRACE(D_EVENTS,
636 2e10a170 Ondrej Filip
                     "Changing cost interface %s from %d to %d",
637
                     ifa->iface->name, ip1->cost, ip2->cost);
638 fa6c2405 Ondrej Filip
          schedule_rt_lsa(ifa->oa);
639
        }
640
641 7cedbf21 Ondrej Filip
        /* strict nbma */
642 2e10a170 Ondrej Filip
        if ((ip1->strictnbma == 0) && (ip2->strictnbma != 0))
643 7cedbf21 Ondrej Filip
        {
644 2e10a170 Ondrej Filip
          ifa->strictnbma = ip2->strictnbma;
645 7cedbf21 Ondrej Filip
          OSPF_TRACE(D_EVENTS,
646 2e10a170 Ondrej Filip
                     "Interface %s is now strict NBMA.", ifa->iface->name);
647 7cedbf21 Ondrej Filip
        }
648 2e10a170 Ondrej Filip
        if ((ip1->strictnbma != 0) && (ip2->strictnbma == 0))
649 7cedbf21 Ondrej Filip
        {
650 2e10a170 Ondrej Filip
          ifa->strictnbma = ip2->strictnbma;
651 7cedbf21 Ondrej Filip
          OSPF_TRACE(D_EVENTS,
652 2e10a170 Ondrej Filip
                     "Interface %s is no longer strict NBMA.",
653
                     ifa->iface->name);
654 e3bc10fd Ondrej Filip
        }
655
656
        /* stub */
657 2e10a170 Ondrej Filip
        if ((ip1->stub == 0) && (ip2->stub != 0))
658 e3bc10fd Ondrej Filip
        {
659 2e10a170 Ondrej Filip
          ifa->stub = ip2->stub;
660
          OSPF_TRACE(D_EVENTS, "Interface %s is now stub.", ifa->iface->name);
661 e3bc10fd Ondrej Filip
        }
662 2e10a170 Ondrej Filip
        if ((ip1->stub != 0) && (ip2->stub == 0) &&
663
            ((ifa->ioprob & OSPF_I_IP) == 0) &&
664
            (((ifa->ioprob & OSPF_I_MC) == 0) || (ifa->type == OSPF_IT_NBMA)))
665 e3bc10fd Ondrej Filip
        {
666 2e10a170 Ondrej Filip
          ifa->stub = ip2->stub;
667 e3bc10fd Ondrej Filip
          OSPF_TRACE(D_EVENTS,
668 2e10a170 Ondrej Filip
                     "Interface %s is no longer stub.", ifa->iface->name);
669 7cedbf21 Ondrej Filip
        }
670
671 baa5dd6c Ondrej Filip
        /* AUTHENTICATION */
672 2e10a170 Ondrej Filip
        if (ip1->autype != ip2->autype)
673 edc34dc9 Ondrej Filip
        {
674 2e10a170 Ondrej Filip
          ifa->autype = ip2->autype;
675 edc34dc9 Ondrej Filip
          OSPF_TRACE(D_EVENTS,
676 2e10a170 Ondrej Filip
                     "Changing authentication type on interface %s",
677
                     ifa->iface->name);
678 edc34dc9 Ondrej Filip
        }
679 2e10a170 Ondrej Filip
        if (strncmp(ip1->password, ip2->password, 8) != 0)
680 edc34dc9 Ondrej Filip
        {
681 2e10a170 Ondrej Filip
          memcpy(ifa->aukey, ip2->password, 8);
682 edc34dc9 Ondrej Filip
          OSPF_TRACE(D_EVENTS,
683 2e10a170 Ondrej Filip
                     "Changing password on interface %s", ifa->iface->name);
684 edc34dc9 Ondrej Filip
        }
685
686
        /* RXMT */
687 2e10a170 Ondrej Filip
        if (ip1->rxmtint != ip2->rxmtint)
688 edc34dc9 Ondrej Filip
        {
689 2e10a170 Ondrej Filip
          ifa->rxmtint = ip2->rxmtint;
690 edc34dc9 Ondrej Filip
          OSPF_TRACE(D_EVENTS,
691 2e10a170 Ondrej Filip
                     "Changing retransmit interval on interface %s from %d to %d",
692
                     ifa->iface->name, ip1->rxmtint, ip2->rxmtint);
693 edc34dc9 Ondrej Filip
        }
694
695
        /* WAIT */
696 2e10a170 Ondrej Filip
        if (ip1->waitint != ip2->waitint)
697 edc34dc9 Ondrej Filip
        {
698 2e10a170 Ondrej Filip
          ifa->waitint = ip2->waitint;
699
          if (ifa->wait_timer->expires != 0)
700
            tm_start(ifa->wait_timer, ifa->waitint);
701 edc34dc9 Ondrej Filip
          OSPF_TRACE(D_EVENTS,
702 2e10a170 Ondrej Filip
                     "Changing wait interval on interface %s from %d to %d",
703
                     ifa->iface->name, ip1->waitint, ip2->waitint);
704 edc34dc9 Ondrej Filip
        }
705
706
        /* INFTRANS */
707 2e10a170 Ondrej Filip
        if (ip1->inftransdelay != ip2->inftransdelay)
708 edc34dc9 Ondrej Filip
        {
709 2e10a170 Ondrej Filip
          ifa->inftransdelay = ip2->inftransdelay;
710 edc34dc9 Ondrej Filip
          OSPF_TRACE(D_EVENTS,
711 2e10a170 Ondrej Filip
                     "Changing transmit delay on interface %s from %d to %d",
712
                     ifa->iface->name, ip1->inftransdelay,
713
                     ip2->inftransdelay);
714 edc34dc9 Ondrej Filip
        }
715
716
        /* DEAD COUNT */
717 2e10a170 Ondrej Filip
        if (ip1->deadc != ip2->deadc)
718 edc34dc9 Ondrej Filip
        {
719 2e10a170 Ondrej Filip
          ifa->deadc = ip2->deadc;
720 edc34dc9 Ondrej Filip
          OSPF_TRACE(D_EVENTS,
721 2e10a170 Ondrej Filip
                     "Changing dead count on interface %s from %d to %d",
722
                     ifa->iface->name, ip1->deadc, ip2->deadc);
723 edc34dc9 Ondrej Filip
        }
724
725
        /* NBMA LIST */
726
        /* First remove old */
727
        WALK_LIST_DELSAFE(nb1, nbnx, ifa->nbma_list)
728
        {
729 2e10a170 Ondrej Filip
          found = 0;
730 edc34dc9 Ondrej Filip
          WALK_LIST(nb2, ip2->nbma_list)
731 2e10a170 Ondrej Filip
            if (ipa_compare(nb1->ip, nb2->ip) == 0)
732
          {
733
            found = 1;
734
            if (nb1->eligible != nb2->eligible)
735
              OSPF_TRACE(D_EVENTS,
736
                         "Changing neighbor eligibility %I on interface %s",
737
                         nb1->ip, ifa->iface->name);
738
            break;
739
          }
740
741
          if (!found)
742 edc34dc9 Ondrej Filip
          {
743
            OSPF_TRACE(D_EVENTS,
744 2e10a170 Ondrej Filip
                       "Removing NBMA neighbor %I on interface %s",
745
                       nb1->ip, ifa->iface->name);
746 edc34dc9 Ondrej Filip
            rem_node(NODE nb1);
747
            mb_free(nb1);
748
          }
749 2e10a170 Ondrej Filip
        }
750 edc34dc9 Ondrej Filip
        /* And then add new */
751
        WALK_LIST(nb2, ip2->nbma_list)
752
        {
753 2e10a170 Ondrej Filip
          found = 0;
754 edc34dc9 Ondrej Filip
          WALK_LIST(nb1, ifa->nbma_list)
755 2e10a170 Ondrej Filip
            if (ipa_compare(nb1->ip, nb2->ip) == 0)
756
          {
757
            found = 1;
758
            break;
759
          }
760
          if (!found)
761 edc34dc9 Ondrej Filip
          {
762 2e10a170 Ondrej Filip
            nb1 = mb_alloc(p->pool, sizeof(struct nbma_node));
763
            nb1->ip = nb2->ip;
764
            nb1->eligible = nb2->eligible;
765 edc34dc9 Ondrej Filip
            add_tail(&ifa->nbma_list, NODE nb1);
766
            OSPF_TRACE(D_EVENTS,
767 2e10a170 Ondrej Filip
                       "Adding NBMA neighbor %I on interface %s",
768
                       nb1->ip, ifa->iface->name);
769 edc34dc9 Ondrej Filip
          }
770 2e10a170 Ondrej Filip
        }
771 edc34dc9 Ondrej Filip
      }
772
    }
773
774 2e10a170 Ondrej Filip
    NODE ac1 = (NODE(ac1))->next;
775
    NODE ac2 = (NODE(ac2))->next;
776 edc34dc9 Ondrej Filip
  }
777
778 2e10a170 Ondrej Filip
  if (((NODE(ac1))->next) != ((NODE(ac2))->next))
779
    return 0;                        /* One is not null */
780 edc34dc9 Ondrej Filip
781 2e10a170 Ondrej Filip
  return 1;                        /* Everything OK :-) */
782 80787d41 Ondrej Filip
}
783 a783e259 Ondrej Filip
784
void
785 c4f0f014 Ondrej Filip
ospf_sh_neigh(struct proto *p, char *iff)
786 a783e259 Ondrej Filip
{
787 2e10a170 Ondrej Filip
  struct ospf_iface *ifa = NULL, *f;
788 a783e259 Ondrej Filip
  struct ospf_neighbor *n;
789 2e10a170 Ondrej Filip
  struct proto_ospf *po = (struct proto_ospf *) p;
790 3488634c Ondrej Filip
791 2e10a170 Ondrej Filip
  if (p->proto_state != PS_UP)
792 3488634c Ondrej Filip
  {
793 2e10a170 Ondrej Filip
    cli_msg(-1013, "%s: is not up", p->name);
794
    cli_msg(0, "");
795 3488634c Ondrej Filip
    return;
796
  }
797 2e10a170 Ondrej Filip
798
  if (iff != NULL)
799 c4f0f014 Ondrej Filip
  {
800
    WALK_LIST(f, po->iface_list)
801
    {
802 2e10a170 Ondrej Filip
      if (strcmp(iff, f->iface->name) == 0)
803 a489f0ce Ondrej Filip
      {
804 2e10a170 Ondrej Filip
        ifa = f;
805
        break;
806 a489f0ce Ondrej Filip
      }
807 c4f0f014 Ondrej Filip
    }
808 2e10a170 Ondrej Filip
    if (ifa == NULL)
809 c4f0f014 Ondrej Filip
    {
810 2e10a170 Ondrej Filip
      cli_msg(0, "");
811 c4f0f014 Ondrej Filip
      return;
812
    }
813 2e10a170 Ondrej Filip
    cli_msg(-1013, "%s:", p->name);
814
    cli_msg(-1013, "%-12s\t%3s\t%-15s\t%-5s\t%-12s\t%-10s", "Router ID",
815
            "Pri", "     State", "DTime", "Router IP", "Interface");
816 a489f0ce Ondrej Filip
    WALK_LIST(n, ifa->neigh_list) ospf_sh_neigh_info(n);
817 2e10a170 Ondrej Filip
    cli_msg(0, "");
818 ece612e1 Ondrej Filip
    return;
819 a489f0ce Ondrej Filip
  }
820
821 2e10a170 Ondrej Filip
  cli_msg(-1013, "%s:", p->name);
822
  cli_msg(-1013, "%-12s\t%3s\t%-15s\t%-5s\t%-12s\t%-10s", "Router ID", "Pri",
823
          "     State", "DTime", "Router IP", "Interface");
824
  WALK_LIST(ifa, po->iface_list)
825
    WALK_LIST(n, ifa->neigh_list) ospf_sh_neigh_info(n);
826
  cli_msg(0, "");
827 a783e259 Ondrej Filip
}
828 4ab4e977 Ondrej Filip
829
void
830
ospf_sh(struct proto *p)
831
{
832
  struct ospf_area *oa;
833 2e10a170 Ondrej Filip
  struct proto_ospf *po = (struct proto_ospf *) p;
834 4ab4e977 Ondrej Filip
  struct ospf_iface *ifa;
835
  struct ospf_neighbor *n;
836
  int ifano;
837
  int nno;
838
  int adjno;
839
840 2e10a170 Ondrej Filip
  if (p->proto_state != PS_UP)
841 3488634c Ondrej Filip
  {
842 2e10a170 Ondrej Filip
    cli_msg(-1014, "%s: is not up", p->name);
843
    cli_msg(0, "");
844 3488634c Ondrej Filip
    return;
845
  }
846
847 2e10a170 Ondrej Filip
  cli_msg(-1014, "%s:", p->name);
848
  cli_msg(-1014, "Number of areas: %u", po->areano);
849
850
  WALK_LIST(oa, po->area_list)
851 4ab4e977 Ondrej Filip
  {
852 2e10a170 Ondrej Filip
    cli_msg(-1014, "\tArea: %I (%u) %s", oa->areaid, oa->areaid,
853
            oa->areaid == 0 ? "[BACKBONE]" : "");
854
    ifano = 0;
855
    nno = 0;
856
    adjno = 0;
857 4ab4e977 Ondrej Filip
    WALK_LIST(ifa, po->iface_list)
858
    {
859 2e10a170 Ondrej Filip
      if (oa == ifa->oa)
860
        ifano++;
861 4ab4e977 Ondrej Filip
      WALK_LIST(n, ifa->neigh_list)
862
      {
863 2e10a170 Ondrej Filip
        nno++;
864
        if (n->state == NEIGHBOR_FULL)
865
          adjno++;
866 4ab4e977 Ondrej Filip
      }
867
    }
868 2e10a170 Ondrej Filip
    cli_msg(-1014, "\t\tStub:\t%s", oa->stub ? "Yes" : "No");
869
    cli_msg(-1014, "\t\tRT scheduler tick:\t%u", oa->tick);
870
    cli_msg(-1014, "\t\tNumber of interfaces:\t%u", ifano);
871
    cli_msg(-1014, "\t\tNumber of LSAs in DB:\t%u", oa->gr->hash_entries);
872
    cli_msg(-1014, "\t\tNumber of neighbors:\t%u", nno);
873
    cli_msg(-1014, "\t\tNumber of adjacent neighbors:\t%u", adjno);
874
    if (!EMPTY_LIST(oa->net_list))
875 c926eee7 Ondrej Filip
    {
876
      struct area_net *anet;
877 2e10a170 Ondrej Filip
      cli_msg(-1014, "\t\tArea networks:");
878 c926eee7 Ondrej Filip
      WALK_LIST(anet, oa->net_list)
879
      {
880 2e10a170 Ondrej Filip
        cli_msg(-1014, "\t\t\t%1I/%u\t%s", anet->px.addr, anet->px.len,
881
                anet->hidden ? "Hidden" : "Advertise");
882 c926eee7 Ondrej Filip
      }
883
    }
884 4ab4e977 Ondrej Filip
  }
885 2e10a170 Ondrej Filip
  cli_msg(0, "");
886 4ab4e977 Ondrej Filip
}
887
888 c4f0f014 Ondrej Filip
void
889
ospf_sh_iface(struct proto *p, char *iff)
890
{
891 2e10a170 Ondrej Filip
  struct proto_ospf *po = (struct proto_ospf *) p;
892
  struct ospf_iface *ifa = NULL, *f;
893 c4f0f014 Ondrej Filip
894 2e10a170 Ondrej Filip
  if (p->proto_state != PS_UP)
895 3488634c Ondrej Filip
  {
896 2e10a170 Ondrej Filip
    cli_msg(-1015, "%s: is not up", p->name);
897
    cli_msg(0, "");
898 3488634c Ondrej Filip
    return;
899
  }
900
901 2e10a170 Ondrej Filip
  if (iff != NULL)
902 c4f0f014 Ondrej Filip
  {
903
    WALK_LIST(f, po->iface_list)
904
    {
905 2e10a170 Ondrej Filip
      if (strcmp(iff, f->iface->name) == 0)
906 a489f0ce Ondrej Filip
      {
907 2e10a170 Ondrej Filip
        ifa = f;
908
        break;
909 a489f0ce Ondrej Filip
      }
910 c4f0f014 Ondrej Filip
    }
911 a489f0ce Ondrej Filip
912 2e10a170 Ondrej Filip
    if (ifa == NULL)
913 c4f0f014 Ondrej Filip
    {
914 2e10a170 Ondrej Filip
      cli_msg(0, "");
915 c4f0f014 Ondrej Filip
      return;
916
    }
917 2e10a170 Ondrej Filip
    cli_msg(-1015, "%s:", p->name);
918 c4f0f014 Ondrej Filip
    ospf_iface_info(ifa);
919 2e10a170 Ondrej Filip
    cli_msg(0, "");
920 c4f0f014 Ondrej Filip
    return;
921
  }
922 2e10a170 Ondrej Filip
  cli_msg(-1015, "%s:", p->name);
923 c4f0f014 Ondrej Filip
  WALK_LIST(ifa, po->iface_list) ospf_iface_info(ifa);
924 2e10a170 Ondrej Filip
  cli_msg(0, "");
925 c4f0f014 Ondrej Filip
}
926
927 80787d41 Ondrej Filip
struct protocol proto_ospf = {
928 2e10a170 Ondrej Filip
  name:"OSPF",
929
  template:"ospf%d",
930
  attr_class:EAP_OSPF,
931
  init:ospf_init,
932
  dump:ospf_dump,
933
  start:ospf_start,
934
  shutdown:ospf_shutdown,
935
  get_route_info:ospf_get_route_info,
936
  get_attr:ospf_get_attr,
937
  get_status:ospf_get_status,
938
  reconfigure:ospf_reconfigure
939 80787d41 Ondrej Filip
};