Statistics
| Branch: | Revision:

iof-bird-daemon / proto / ospf / iface.c @ 29239ba2

History | View | Annotate | Download (33.6 KB)

1 4364b47e Ondrej Filip
/*
2
 *        BIRD -- OSPF
3
 *
4 e300066d Ondrej Filip
 *        (c) 1999--2005 Ondrej Filip <feela@network.cz>
5 70945cb6 Ondrej Zajicek
 *        (c) 2009--2014 Ondrej Zajicek <santiago@crfreenet.org>
6
 *        (c) 2009--2014 CZ.NIC z.s.p.o.
7 4364b47e Ondrej Filip
 *
8
 *        Can be freely distributed and used under the terms of the GNU GPL.
9
 */
10
11
#include "ospf.h"
12 29239ba2 Ondrej Zajicek (work)
#include "nest/password.h"
13 4364b47e Ondrej Filip
14 70945cb6 Ondrej Zajicek
15 f8fefde3 Ondrej Zajicek
const char *ospf_is_names[] = {
16
  "Down", "Loopback", "Waiting", "PtP", "DROther", "Backup", "DR"
17 b9ed99f7 Ondrej Filip
};
18 8914e37d Ondrej Filip
19 f8fefde3 Ondrej Zajicek
const char *ospf_ism_names[] = {
20
  "InterfaceUp", "WaitTimer", "BackupSeen", "NeighborChange",
21
  "LoopInd", "UnloopInd", "InterfaceDown"
22 b9ed99f7 Ondrej Filip
};
23 79f036ef Ondrej Filip
24 f8fefde3 Ondrej Zajicek
const char *ospf_it[] = { "broadcast", "nbma", "ptp", "ptmp", "virtual link" };
25 c4f0f014 Ondrej Filip
26 70945cb6 Ondrej Zajicek
27 9831e591 Martin Mares
static void
28 b9ed99f7 Ondrej Filip
poll_timer_hook(timer * timer)
29 39e517d4 Ondrej Filip
{
30 70945cb6 Ondrej Zajicek
  ospf_send_hello(timer->data, OHS_POLL, NULL);
31 39e517d4 Ondrej Filip
}
32
33 9831e591 Martin Mares
static void
34 b9ed99f7 Ondrej Filip
hello_timer_hook(timer * timer)
35 39e517d4 Ondrej Filip
{
36 70945cb6 Ondrej Zajicek
  ospf_send_hello(timer->data, OHS_HELLO, NULL);
37 39e517d4 Ondrej Filip
}
38
39 9831e591 Martin Mares
static void
40 b9ed99f7 Ondrej Filip
wait_timer_hook(timer * timer)
41 39e517d4 Ondrej Filip
{
42 b9ed99f7 Ondrej Filip
  struct ospf_iface *ifa = (struct ospf_iface *) timer->data;
43 70945cb6 Ondrej Zajicek
  struct ospf_proto *p = ifa->oa->po;
44 39e517d4 Ondrej Filip
45 f8fefde3 Ondrej Zajicek
  OSPF_TRACE(D_EVENTS, "Wait timer fired on %s", ifa->ifname);
46 b9ed99f7 Ondrej Filip
  ospf_iface_sm(ifa, ISM_WAITF);
47 39e517d4 Ondrej Filip
}
48
49 48e5f32d Ondrej Zajicek
static inline uint
50
ifa_tx_length(struct ospf_iface *ifa)
51
{
52 742029eb Ondrej Zajicek
  return ifa->cf->tx_length ?: ifa->iface->mtu;
53 48e5f32d Ondrej Zajicek
}
54 8e48831a Ondrej Zajicek
55 48e5f32d Ondrej Zajicek
static inline uint
56 29239ba2 Ondrej Zajicek (work)
ifa_tx_hdrlen(struct ospf_iface *ifa)
57
{
58
  uint hlen = SIZE_OF_IP_HEADER;
59
60
  /* Relevant just for OSPFv2 */
61
  if (ifa->autype == OSPF_AUTH_CRYPT)
62
    hlen += max_mac_length(ifa->passwords);
63
64
  return hlen;
65
}
66
67
static inline uint
68 48e5f32d Ondrej Zajicek
ifa_bufsize(struct ospf_iface *ifa)
69 94c42054 Ondrej Filip
{
70 48e5f32d Ondrej Zajicek
  uint bsize = ifa->cf->rx_buffer ?: ifa->iface->mtu;
71
  return MAX(bsize, ifa->tx_length);
72 94c42054 Ondrej Filip
}
73
74 6f8bbaa1 Ondrej Zajicek
static inline uint
75
ifa_flood_queue_size(struct ospf_iface *ifa)
76
{
77
  return ifa->tx_length / 24;
78
}
79
80 48e5f32d Ondrej Zajicek
int
81
ospf_iface_assure_bufsize(struct ospf_iface *ifa, uint plen)
82
{
83 29239ba2 Ondrej Zajicek (work)
  plen += ifa->tx_hdrlen;
84 48e5f32d Ondrej Zajicek
85
  if (plen <= ifa->sk->tbsize)
86
    return 0;
87
88
  if (ifa->cf->rx_buffer || (plen > 0xffff))
89
    return -1;
90
91
  plen = BIRD_ALIGN(plen, 1024);
92
  plen = MIN(plen, 0xffff);
93
  sk_set_tbsize(ifa->sk, plen);
94
  return 1;
95
}
96
97
98 919f5411 Ondrej Zajicek
struct nbma_node *
99 70945cb6 Ondrej Zajicek
find_nbma_node_(list *nnl, ip_addr ip)
100 919f5411 Ondrej Zajicek
{
101
  struct nbma_node *nn;
102 70945cb6 Ondrej Zajicek
103 919f5411 Ondrej Zajicek
  WALK_LIST(nn, *nnl)
104
    if (ipa_equal(nn->ip, ip))
105
      return nn;
106 70945cb6 Ondrej Zajicek
107 919f5411 Ondrej Zajicek
  return NULL;
108
}
109
110 48e5f32d Ondrej Zajicek
111 353729f5 Ondrej Zajicek
static int
112 7d4e9236 Ondrej Zajicek
ospf_sk_open(struct ospf_iface *ifa)
113 3b16080c Ondrej Filip
{
114 70945cb6 Ondrej Zajicek
  struct ospf_proto *p = ifa->oa->po;
115 05476c4d Ondrej Zajicek
116 d9e7e1b1 Ondrej Zajicek
  sock *sk = sk_new(ifa->pool);
117 353729f5 Ondrej Zajicek
  sk->type = SK_IP;
118
  sk->dport = OSPF_PROTO;
119 48e5f32d Ondrej Zajicek
  sk->saddr = ifa->addr->ip;
120
  sk->iface = ifa->iface;
121 061ab802 Ondrej Zajicek
122 ef4a50be Ondrej Zajicek
  sk->tos = ifa->cf->tx_tos;
123
  sk->priority = ifa->cf->tx_priority;
124 353729f5 Ondrej Zajicek
  sk->rx_hook = ospf_rx_hook;
125 48e5f32d Ondrej Zajicek
  // sk->tx_hook = ospf_tx_hook;
126 353729f5 Ondrej Zajicek
  sk->err_hook = ospf_err_hook;
127 48e5f32d Ondrej Zajicek
  sk->rbsize = sk->tbsize = ifa_bufsize(ifa);
128 353729f5 Ondrej Zajicek
  sk->data = (void *) ifa;
129 70e212f9 Ondrej Zajicek
  sk->flags = SKF_LADDR_RX | (ifa->check_ttl ? SKF_TTL_RX : 0);
130 48e5f32d Ondrej Zajicek
  sk->ttl = ifa->cf->ttl_security ? 255 : 1;
131 353729f5 Ondrej Zajicek
132 48e5f32d Ondrej Zajicek
  if (sk_open(sk) < 0)
133 f9c799a0 Ondrej Zajicek
    goto err;
134
135 70945cb6 Ondrej Zajicek
  /* 12 is an offset of the checksum in an OSPFv3 packet */
136
  if (ospf_is_v3(p))
137
    if (sk_set_ipv6_checksum(sk, 12) < 0)
138
      goto err;
139 4ac7c834 Ondrej Zajicek
140 7d4e9236 Ondrej Zajicek
  if ((ifa->type == OSPF_IT_BCAST) || (ifa->type == OSPF_IT_PTP))
141 919f5411 Ondrej Zajicek
  {
142 95127cbb Ondrej Zajicek
    if (ifa->cf->real_bcast)
143
    {
144
      ifa->all_routers = ifa->addr->brd;
145 70945cb6 Ondrej Zajicek
      ifa->des_routers = IPA_NONE;
146 95127cbb Ondrej Zajicek
147 05476c4d Ondrej Zajicek
      if (sk_setup_broadcast(sk) < 0)
148 742029eb Ondrej Zajicek
        goto err;
149 95127cbb Ondrej Zajicek
    }
150
    else
151
    {
152 70945cb6 Ondrej Zajicek
      ifa->all_routers = ospf_is_v2(p) ? IP4_OSPF_ALL_ROUTERS : IP6_OSPF_ALL_ROUTERS;
153
      ifa->des_routers = ospf_is_v2(p) ? IP4_OSPF_DES_ROUTERS : IP6_OSPF_DES_ROUTERS;
154 2f9955b5 Ondrej Zajicek
155 95127cbb Ondrej Zajicek
      if (sk_setup_multicast(sk) < 0)
156 742029eb Ondrej Zajicek
        goto err;
157 919f5411 Ondrej Zajicek
158 95127cbb Ondrej Zajicek
      if (sk_join_group(sk, ifa->all_routers) < 0)
159 742029eb Ondrej Zajicek
        goto err;
160 95127cbb Ondrej Zajicek
    }
161 919f5411 Ondrej Zajicek
  }
162 f9c799a0 Ondrej Zajicek
163 353729f5 Ondrej Zajicek
  ifa->sk = sk;
164
  ifa->sk_dr = 0;
165
  return 1;
166 f9c799a0 Ondrej Zajicek
167
 err:
168 70945cb6 Ondrej Zajicek
  sk_log_error(sk, p->p.name);
169 353729f5 Ondrej Zajicek
  rfree(sk);
170
  return 0;
171
}
172
173
static inline void
174
ospf_sk_join_dr(struct ospf_iface *ifa)
175
{
176
  if (ifa->sk_dr)
177
    return;
178
179 70945cb6 Ondrej Zajicek
  if (sk_join_group(ifa->sk, ifa->des_routers) < 0)
180
    sk_log_error(ifa->sk, ifa->oa->po->p.name);
181 05476c4d Ondrej Zajicek
182 353729f5 Ondrej Zajicek
  ifa->sk_dr = 1;
183
}
184 7d4e9236 Ondrej Zajicek
185 353729f5 Ondrej Zajicek
static inline void
186
ospf_sk_leave_dr(struct ospf_iface *ifa)
187
{
188
  if (!ifa->sk_dr)
189
    return;
190
191 70945cb6 Ondrej Zajicek
  if (sk_leave_group(ifa->sk, ifa->des_routers) < 0)
192
    sk_log_error(ifa->sk, ifa->oa->po->p.name);
193 05476c4d Ondrej Zajicek
194 353729f5 Ondrej Zajicek
  ifa->sk_dr = 0;
195
}
196
197 48e5f32d Ondrej Zajicek
void
198 70945cb6 Ondrej Zajicek
ospf_open_vlink_sk(struct ospf_proto *p)
199 48e5f32d Ondrej Zajicek
{
200 70945cb6 Ondrej Zajicek
  sock *sk = sk_new(p->p.pool);
201 48e5f32d Ondrej Zajicek
  sk->type = SK_IP;
202
  sk->dport = OSPF_PROTO;
203
204
  /* FIXME: configurable tos/priority ? */
205
  sk->tos = IP_PREC_INTERNET_CONTROL;
206
  sk->priority = sk_priority_control;
207
  sk->err_hook = ospf_verr_hook;
208
209
  sk->rbsize = 0;
210 70945cb6 Ondrej Zajicek
  sk->tbsize = ospf_is_v2(p) ? IP4_MIN_MTU : IP6_MIN_MTU;
211
  sk->data = (void *) p;
212 48e5f32d Ondrej Zajicek
  sk->flags = 0;
213
214
  if (sk_open(sk) < 0)
215
    goto err;
216
217 70945cb6 Ondrej Zajicek
  /* 12 is an offset of the checksum in an OSPFv3 packet */
218
  if (ospf_is_v3(p))
219
    if (sk_set_ipv6_checksum(sk, 12) < 0)
220
      goto err;
221 48e5f32d Ondrej Zajicek
222 70945cb6 Ondrej Zajicek
  p->vlink_sk = sk;
223 48e5f32d Ondrej Zajicek
  return;
224
225
 err:
226 70945cb6 Ondrej Zajicek
  sk_log_error(sk, p->p.name);
227
  log(L_ERR "%s: Cannot open virtual link socket", p->p.name);
228 48e5f32d Ondrej Zajicek
  rfree(sk);
229
}
230
231 b9ed99f7 Ondrej Filip
static void
232
ospf_iface_down(struct ospf_iface *ifa)
233 4364b47e Ondrej Filip
{
234 70945cb6 Ondrej Zajicek
  struct ospf_proto *p = ifa->oa->po;
235 b9ed99f7 Ondrej Filip
  struct ospf_neighbor *n, *nx;
236 98ac6176 Ondrej Filip
  struct ospf_iface *iff;
237 18a0c0bb Ondrej Filip
238 3b16080c Ondrej Filip
  if (ifa->type != OSPF_IT_VLINK)
239
  {
240 70945cb6 Ondrej Zajicek
    if (ospf_is_v3(ifa->oa->po))
241
      OSPF_TRACE(D_EVENTS, "Removing interface %s (IID %d) from area %R",
242
                 ifa->ifname, ifa->instance_id, ifa->oa->areaid);
243
    else if (ifa->addr->flags & IA_PEER)
244
      OSPF_TRACE(D_EVENTS, "Removing interface %s (peer %I) from area %R",
245
                 ifa->ifname, ifa->addr->opposite, ifa->oa->areaid);
246
    else
247
      OSPF_TRACE(D_EVENTS, "Removing interface %s (%I/%d) from area %R",
248
                 ifa->ifname, ifa->addr->prefix, ifa->addr->pxlen, ifa->oa->areaid);
249 6384c7d7 Ondrej Zajicek
250
    /* First of all kill all the related vlinks */
251 70945cb6 Ondrej Zajicek
    WALK_LIST(iff, p->iface_list)
252 3b16080c Ondrej Filip
    {
253 0aad2b92 Ondrej Zajicek
      if ((iff->type == OSPF_IT_VLINK) && (iff->vifa == ifa))
254 353729f5 Ondrej Zajicek
        ospf_iface_sm(iff, ISM_DOWN);
255 3b16080c Ondrej Filip
    }
256
  }
257
258 b9ed99f7 Ondrej Filip
  WALK_LIST_DELSAFE(n, nx, ifa->neigh_list)
259 f8fefde3 Ondrej Zajicek
    ospf_neigh_sm(n, INM_KILLNBR);
260 f9c799a0 Ondrej Zajicek
261 d9e7e1b1 Ondrej Zajicek
  if (ifa->hello_timer)
262
    tm_stop(ifa->hello_timer);
263
264
  if (ifa->poll_timer)
265
    tm_stop(ifa->poll_timer);
266
267
  if (ifa->wait_timer)
268
    tm_stop(ifa->wait_timer);
269
270 70945cb6 Ondrej Zajicek
  ospf_flush2_lsa(p, &ifa->link_lsa);
271
  ospf_flush2_lsa(p, &ifa->net_lsa);
272
  ospf_flush2_lsa(p, &ifa->pxn_lsa);
273
274 3b16080c Ondrej Filip
  if (ifa->type == OSPF_IT_VLINK)
275 98ac6176 Ondrej Filip
  {
276 0aad2b92 Ondrej Zajicek
    ifa->vifa = NULL;
277
    ifa->addr = NULL;
278 3b89a232 Ondrej Zajicek
    ifa->cost = 0;
279 0aad2b92 Ondrej Zajicek
    ifa->vip = IPA_NONE;
280 98ac6176 Ondrej Filip
  }
281 e7b4948c Ondrej Zajicek
282
  ifa->rt_pos_beg = 0;
283
  ifa->rt_pos_end = 0;
284
  ifa->px_pos_beg = 0;
285
  ifa->px_pos_end = 0;
286 d9e7e1b1 Ondrej Zajicek
}
287
288
289 8e48831a Ondrej Zajicek
void
290 d9e7e1b1 Ondrej Zajicek
ospf_iface_remove(struct ospf_iface *ifa)
291
{
292 70945cb6 Ondrej Zajicek
  struct ospf_proto *p = ifa->oa->po;
293 ac9dc669 Ondrej Zajicek
  int i;
294 70945cb6 Ondrej Zajicek
295 8e48831a Ondrej Zajicek
  if (ifa->type == OSPF_IT_VLINK)
296
    OSPF_TRACE(D_EVENTS, "Removing vlink to %R via area %R", ifa->vid, ifa->voa->areaid);
297
298 ac9dc669 Ondrej Zajicek
  /* Release LSAs from flood queue */
299
  if (!ifa->stub)
300
    for (i = 0; i < ifa->flood_queue_used; i++)
301
      ifa->flood_queue[i]->ret_count--;
302
303 d9e7e1b1 Ondrej Zajicek
  ospf_iface_sm(ifa, ISM_DOWN);
304
  rem_node(NODE ifa);
305
  rfree(ifa->pool);
306
}
307
308 8e48831a Ondrej Zajicek
void
309
ospf_iface_shutdown(struct ospf_iface *ifa)
310
{
311
  if (ifa->state > OSPF_IS_DOWN)
312 70945cb6 Ondrej Zajicek
    ospf_send_hello(ifa, OHS_SHUTDOWN, NULL);
313 8e48831a Ondrej Zajicek
}
314
315 d9e7e1b1 Ondrej Zajicek
/**
316
 * ospf_iface_chstate - handle changes of interface state
317
 * @ifa: OSPF interface
318
 * @state: new state
319
 *
320
 * Many actions must be taken according to interface state changes. New network
321
 * LSAs must be originated, flushed, new multicast sockets to listen for messages for
322
 * %ALLDROUTERS have to be opened, etc.
323
 */
324
void
325
ospf_iface_chstate(struct ospf_iface *ifa, u8 state)
326
{
327 70945cb6 Ondrej Zajicek
  struct ospf_proto *p = ifa->oa->po;
328 d9e7e1b1 Ondrej Zajicek
  u8 oldstate = ifa->state;
329
330 70945cb6 Ondrej Zajicek
  if (state == oldstate)
331 d9e7e1b1 Ondrej Zajicek
    return;
332
333 f8fefde3 Ondrej Zajicek
  OSPF_TRACE(D_EVENTS, "Interface %s changed state from %s to %s",
334
             ifa->ifname, ospf_is_names[oldstate], ospf_is_names[state]);
335 d9e7e1b1 Ondrej Zajicek
336 70945cb6 Ondrej Zajicek
  ifa->state = state;
337 d9e7e1b1 Ondrej Zajicek
338 70945cb6 Ondrej Zajicek
  if ((ifa->type == OSPF_IT_BCAST) && ipa_nonzero(ifa->des_routers) && ifa->sk)
339 d9e7e1b1 Ondrej Zajicek
  {
340
    if ((state == OSPF_IS_BACKUP) || (state == OSPF_IS_DR))
341
      ospf_sk_join_dr(ifa);
342
    else
343
      ospf_sk_leave_dr(ifa);
344
  }
345
346
  if ((oldstate > OSPF_IS_LOOP) && (state <= OSPF_IS_LOOP))
347
    ospf_iface_down(ifa);
348
349 70945cb6 Ondrej Zajicek
  /* RFC 2328 12.4 Event 2 - iface state change */
350
  ospf_notify_rt_lsa(ifa->oa);
351
352
  /* RFC 5340 4.4.3 Event 1 - iface state change */
353
  ospf_notify_link_lsa(ifa);
354
355
  /* RFC 2328 12.4 Event 3 - iface enters/leaves DR state */
356
  ospf_notify_net_lsa(ifa);
357 4364b47e Ondrej Filip
}
358
359 d5e4b518 Ondrej Filip
/**
360 b9ed99f7 Ondrej Filip
 * ospf_iface_sm - OSPF interface state machine
361 d5e4b518 Ondrej Filip
 * @ifa: OSPF interface
362
 * @event: event comming to state machine
363
 *
364 d9e7e1b1 Ondrej Zajicek
 * This fully respects 9.3 of RFC 2328 except we have slightly
365
 * different handling of %DOWN and %LOOP state. We remove intefaces
366
 * that are %DOWN. %DOWN state is used when an interface is waiting
367
 * for a lock. %LOOP state is used when an interface does not have a
368
 * link.
369 d5e4b518 Ondrej Filip
 */
370 4364b47e Ondrej Filip
void
371 b9ed99f7 Ondrej Filip
ospf_iface_sm(struct ospf_iface *ifa, int event)
372 4364b47e Ondrej Filip
{
373 f8fefde3 Ondrej Zajicek
  DBG("SM on %s. Event is '%s'\n", ifa->ifname, ospf_ism_names[event]);
374 4364b47e Ondrej Filip
375 b9ed99f7 Ondrej Filip
  switch (event)
376 4364b47e Ondrej Filip
  {
377 b9ed99f7 Ondrej Filip
  case ISM_UP:
378 d9e7e1b1 Ondrej Zajicek
    if (ifa->state <= OSPF_IS_LOOP)
379 b9ed99f7 Ondrej Filip
    {
380
      /* Now, nothing should be adjacent */
381 70945cb6 Ondrej Zajicek
      if ((ifa->type == OSPF_IT_PTP) ||
382
          (ifa->type == OSPF_IT_PTMP) ||
383
          (ifa->type == OSPF_IT_VLINK))
384 3b16080c Ondrej Filip
      {
385 b9ed99f7 Ondrej Filip
        ospf_iface_chstate(ifa, OSPF_IS_PTP);
386 3b16080c Ondrej Filip
      }
387 b9ed99f7 Ondrej Filip
      else
388 4364b47e Ondrej Filip
      {
389 b9ed99f7 Ondrej Filip
        if (ifa->priority == 0)
390
          ospf_iface_chstate(ifa, OSPF_IS_DROTHER);
391
        else
392
        {
393
          ospf_iface_chstate(ifa, OSPF_IS_WAITING);
394 beeda6af Ondrej Zajicek
          if (ifa->wait_timer)
395
            tm_start(ifa->wait_timer, ifa->waitint);
396 b9ed99f7 Ondrej Filip
        }
397 4364b47e Ondrej Filip
      }
398 3b16080c Ondrej Filip
399 beeda6af Ondrej Zajicek
      if (ifa->hello_timer)
400
        tm_start(ifa->hello_timer, ifa->helloint);
401 3b16080c Ondrej Filip
402
      if (ifa->poll_timer)
403
        tm_start(ifa->poll_timer, ifa->pollint);
404
405 70945cb6 Ondrej Zajicek
      ospf_send_hello(ifa, OHS_HELLO, NULL);
406 b9ed99f7 Ondrej Filip
    }
407
    break;
408 d9e7e1b1 Ondrej Zajicek
409 b9ed99f7 Ondrej Filip
  case ISM_BACKS:
410
  case ISM_WAITF:
411
    if (ifa->state == OSPF_IS_WAITING)
412 70945cb6 Ondrej Zajicek
      ospf_dr_election(ifa);
413 b9ed99f7 Ondrej Filip
    break;
414 d9e7e1b1 Ondrej Zajicek
415 b9ed99f7 Ondrej Filip
  case ISM_NEICH:
416 70945cb6 Ondrej Zajicek
    if (ifa->state >= OSPF_IS_DROTHER)
417
      ospf_dr_election(ifa);
418 b9ed99f7 Ondrej Filip
    break;
419 d9e7e1b1 Ondrej Zajicek
420 353729f5 Ondrej Zajicek
  case ISM_LOOP:
421 7d4e9236 Ondrej Zajicek
    if ((ifa->state > OSPF_IS_LOOP) && ifa->check_link)
422 d9e7e1b1 Ondrej Zajicek
      ospf_iface_chstate(ifa, OSPF_IS_LOOP);
423 b9ed99f7 Ondrej Filip
    break;
424 d9e7e1b1 Ondrej Zajicek
425 b9ed99f7 Ondrej Filip
  case ISM_UNLOOP:
426 d9e7e1b1 Ondrej Zajicek
    /* Immediate go UP */
427
    if (ifa->state == OSPF_IS_LOOP)
428
      ospf_iface_sm(ifa, ISM_UP);
429
    break;
430
431
  case ISM_DOWN:
432 b9ed99f7 Ondrej Filip
    ospf_iface_chstate(ifa, OSPF_IS_DOWN);
433
    break;
434 d9e7e1b1 Ondrej Zajicek
435 b9ed99f7 Ondrej Filip
  default:
436
    bug("OSPF_I_SM - Unknown event?");
437
    break;
438 4364b47e Ondrej Filip
  }
439 b9ed99f7 Ondrej Filip
440 4364b47e Ondrej Filip
}
441
442 919f5411 Ondrej Zajicek
static u8
443 70945cb6 Ondrej Zajicek
ospf_iface_classify_(struct iface *ifa, struct ifa *addr)
444 4364b47e Ondrej Filip
{
445 ba321706 Ondrej Zajicek
  if (ipa_nonzero(addr->opposite))
446 919f5411 Ondrej Zajicek
    return (ifa->flags & IF_MULTICAST) ? OSPF_IT_PTP :  OSPF_IT_PTMP;
447 aa80826e Ondrej Zajicek
448 b9ed99f7 Ondrej Filip
  if ((ifa->flags & (IF_MULTIACCESS | IF_MULTICAST)) ==
449
      (IF_MULTIACCESS | IF_MULTICAST))
450
    return OSPF_IT_BCAST;
451
452
  if ((ifa->flags & (IF_MULTIACCESS | IF_MULTICAST)) == IF_MULTIACCESS)
453 4364b47e Ondrej Filip
    return OSPF_IT_NBMA;
454 b9ed99f7 Ondrej Filip
455 4364b47e Ondrej Filip
  return OSPF_IT_PTP;
456
}
457
458 8e48831a Ondrej Zajicek
static inline u8
459
ospf_iface_classify(u8 type, struct ifa *addr)
460
{
461 70945cb6 Ondrej Zajicek
  return (type != OSPF_IT_UNDEF) ? type : ospf_iface_classify_(addr->iface, addr);
462 8e48831a Ondrej Zajicek
}
463
464
465 b9ed99f7 Ondrej Filip
struct ospf_iface *
466 70945cb6 Ondrej Zajicek
ospf_iface_find(struct ospf_proto *p, struct iface *what)
467 4364b47e Ondrej Filip
{
468 70945cb6 Ondrej Zajicek
  struct ospf_iface *ifa;
469
470
  WALK_LIST(ifa, p->iface_list)
471
    if ((ifa->iface == what) && (ifa->type != OSPF_IT_VLINK))
472
      return ifa;
473 4364b47e Ondrej Filip
474
  return NULL;
475
}
476
477 b9ed99f7 Ondrej Filip
static void
478
ospf_iface_add(struct object_lock *lock)
479
{
480
  struct ospf_iface *ifa = lock->data;
481 70945cb6 Ondrej Zajicek
  struct ospf_proto *p = ifa->oa->po;
482 b9ed99f7 Ondrej Filip
483 7d4e9236 Ondrej Zajicek
  /* Open socket if interface is not stub */
484
  if (! ifa->stub && ! ospf_sk_open(ifa))
485 0aad2b92 Ondrej Zajicek
  {
486 70945cb6 Ondrej Zajicek
    log(L_ERR "%s: Cannot open socket for %s, declaring as stub", p->p.name, ifa->ifname);
487 0aad2b92 Ondrej Zajicek
    ifa->ioprob = OSPF_I_SK;
488 b9ed99f7 Ondrej Filip
    ifa->stub = 1;
489
  }
490
491 beeda6af Ondrej Zajicek
  if (! ifa->stub)
492
  {
493
    ifa->hello_timer = tm_new_set(ifa->pool, hello_timer_hook, ifa, 0, ifa->helloint);
494
495
    if (ifa->type == OSPF_IT_NBMA)
496
      ifa->poll_timer = tm_new_set(ifa->pool, poll_timer_hook, ifa, 0, ifa->pollint);
497
498
    if ((ifa->type == OSPF_IT_BCAST) || (ifa->type == OSPF_IT_NBMA))
499
      ifa->wait_timer = tm_new_set(ifa->pool, wait_timer_hook, ifa, 0, 0);
500 6f8bbaa1 Ondrej Zajicek
501
    ifa->flood_queue_size = ifa_flood_queue_size(ifa);
502
    ifa->flood_queue = mb_allocz(ifa->pool, ifa->flood_queue_size * sizeof(void *));
503 beeda6af Ondrej Zajicek
  }
504
505 b5e76398 Ondrej Zajicek
  /* Do iface UP, unless there is no link (then wait in LOOP state) */
506
  if (!ifa->check_link || (ifa->iface->flags & IF_LINK_UP))
507
    ospf_iface_sm(ifa, ISM_UP);
508
  else
509
    ospf_iface_chstate(ifa, OSPF_IS_LOOP);
510 b9ed99f7 Ondrej Filip
}
511
512 8e48831a Ondrej Zajicek
static inline void
513
add_nbma_node(struct ospf_iface *ifa, struct nbma_node *src, int found)
514
{
515
  struct nbma_node *n = mb_alloc(ifa->pool, sizeof(struct nbma_node));
516
  add_tail(&ifa->nbma_list, NODE n);
517
  n->ip = src->ip;
518
  n->eligible = src->eligible;
519
  n->found = found;
520
}
521
522
static int
523
ospf_iface_stubby(struct ospf_iface_patt *ip, struct ifa *addr)
524
{
525 c72aca41 Ondrej Zajicek
  /* a host address */
526 52a43ae3 Ondrej Zajicek
  if (addr->flags & IA_HOST)
527
    return 1;
528
529 c72aca41 Ondrej Zajicek
  /* a loopback iface */
530
  if (addr->iface->flags & IF_LOOPBACK)
531
    return 1;
532
533 8e48831a Ondrej Zajicek
  /*
534 48e5f32d Ondrej Zajicek
   * For compatibility reasons on BSD systems, we force OSPF
535
   * interfaces with non-primary IP prefixes to be stub.
536 8e48831a Ondrej Zajicek
   */
537
#if defined(OSPFv2) && !defined(CONFIG_MC_PROPER_SRC)
538 48e5f32d Ondrej Zajicek
  if (!ip->bsd_secondary && !(addr->flags & IA_PRIMARY))
539 8e48831a Ondrej Zajicek
    return 1;
540
#endif
541
542
  return ip->stub;
543
}
544
545 4364b47e Ondrej Filip
void
546 8e48831a Ondrej Zajicek
ospf_iface_new(struct ospf_area *oa, struct ifa *addr, struct ospf_iface_patt *ip)
547 98ac6176 Ondrej Filip
{
548 70945cb6 Ondrej Zajicek
  struct ospf_proto *p = oa->po;
549 48e5f32d Ondrej Zajicek
  struct iface *iface = addr->iface;
550 98ac6176 Ondrej Filip
  struct ospf_iface *ifa;
551 48e5f32d Ondrej Zajicek
  struct pool *pool;
552 98ac6176 Ondrej Filip
553 70945cb6 Ondrej Zajicek
  if (ospf_is_v3(p))
554
    OSPF_TRACE(D_EVENTS, "Adding interface %s (IID %d) to area %R",
555
               iface->name, ip->instance_id, oa->areaid);
556
  else if (addr->flags & IA_PEER)
557
    OSPF_TRACE(D_EVENTS, "Adding interface %s (peer %I) to area %R",
558
               iface->name, addr->opposite, oa->areaid);
559
  else
560
    OSPF_TRACE(D_EVENTS, "Adding interface %s (%I/%d) to area %R",
561
               iface->name, addr->prefix, addr->pxlen, oa->areaid);
562 353729f5 Ondrej Zajicek
563 70945cb6 Ondrej Zajicek
  pool = rp_new(p->p.pool, "OSPF Interface");
564 d9e7e1b1 Ondrej Zajicek
  ifa = mb_allocz(pool, sizeof(struct ospf_iface));
565 98ac6176 Ondrej Filip
  ifa->iface = iface;
566 0aad2b92 Ondrej Zajicek
  ifa->addr = addr;
567 8e48831a Ondrej Zajicek
  ifa->oa = oa;
568
  ifa->cf = ip;
569 d9e7e1b1 Ondrej Zajicek
  ifa->pool = pool;
570 98ac6176 Ondrej Filip
571 48e5f32d Ondrej Zajicek
  ifa->iface_id = iface->index;
572
  ifa->ifname = iface->name;
573
574 98ac6176 Ondrej Filip
  ifa->cost = ip->cost;
575
  ifa->rxmtint = ip->rxmtint;
576
  ifa->inftransdelay = ip->inftransdelay;
577
  ifa->priority = ip->priority;
578
  ifa->helloint = ip->helloint;
579
  ifa->pollint = ip->pollint;
580
  ifa->strictnbma = ip->strictnbma;
581
  ifa->waitint = ip->waitint;
582 8e48831a Ondrej Zajicek
  ifa->deadint = ip->deadint;
583 af157fa3 Ondrej Zajicek
  ifa->stub = ospf_iface_stubby(ip, addr);
584 0aad2b92 Ondrej Zajicek
  ifa->ioprob = OSPF_I_OK;
585 48e5f32d Ondrej Zajicek
  ifa->tx_length = ifa_tx_length(ifa);
586 29239ba2 Ondrej Zajicek (work)
  ifa->tx_hdrlen = ifa_tx_hdrlen(ifa);
587 391931d4 Ondrej Zajicek
  ifa->check_link = ip->check_link;
588 57c574d8 Ondrej Zajicek
  ifa->ecmp_weight = ip->ecmp_weight;
589 70e212f9 Ondrej Zajicek
  ifa->check_ttl = (ip->ttl_security == 1);
590 1ec52253 Ondrej Zajicek
  ifa->bfd = ip->bfd;
591 98ac6176 Ondrej Filip
  ifa->autype = ip->autype;
592 3e2bd0f1 Ondrej Filip
  ifa->passwords = ip->passwords;
593 70945cb6 Ondrej Zajicek
  ifa->instance_id = ip->instance_id;
594
595 48e5f32d Ondrej Zajicek
  ifa->ptp_netmask = !(addr->flags & IA_PEER);
596 8df02847 Ondrej Zajicek
  if (ip->ptp_netmask < 2)
597
    ifa->ptp_netmask = ip->ptp_netmask;
598 c3226991 Ondrej Zajicek
599 48e5f32d Ondrej Zajicek
600 8e48831a Ondrej Zajicek
  ifa->type = ospf_iface_classify(ip->type, addr);
601 691057f0 Ondrej Zajicek
602 919f5411 Ondrej Zajicek
  /* Check validity of interface type */
603
  int old_type = ifa->type;
604 95127cbb Ondrej Zajicek
  u32 if_multi_flag = ip->real_bcast ? IF_BROADCAST : IF_MULTICAST;
605 919f5411 Ondrej Zajicek
606 70945cb6 Ondrej Zajicek
  if (ospf_is_v2(p) && (ifa->type == OSPF_IT_BCAST) && (addr->flags & IA_PEER))
607 aa80826e Ondrej Zajicek
    ifa->type = OSPF_IT_PTP;
608 919f5411 Ondrej Zajicek
609 70945cb6 Ondrej Zajicek
  if (ospf_is_v2(p) && (ifa->type == OSPF_IT_NBMA) && (addr->flags & IA_PEER))
610 919f5411 Ondrej Zajicek
    ifa->type = OSPF_IT_PTMP;
611 aa80826e Ondrej Zajicek
612 e3f506f9 Ondrej Zajicek (work)
  if ((ifa->type == OSPF_IT_BCAST) && !(iface->flags & if_multi_flag) && !ifa->stub)
613 919f5411 Ondrej Zajicek
    ifa->type = OSPF_IT_NBMA;
614
615 e3f506f9 Ondrej Zajicek (work)
  if ((ifa->type == OSPF_IT_PTP) && !(iface->flags & if_multi_flag) && !ifa->stub)
616 919f5411 Ondrej Zajicek
    ifa->type = OSPF_IT_PTMP;
617
618
  if (ifa->type != old_type)
619
    log(L_WARN "%s: Cannot use interface %s as %s, forcing %s",
620 70945cb6 Ondrej Zajicek
        p->p.name, iface->name, ospf_it[old_type], ospf_it[ifa->type]);
621
622 919f5411 Ondrej Zajicek
623 70945cb6 Ondrej Zajicek
  if ((ifa->type == OSPF_IT_PTP) || (ifa->type == OSPF_IT_PTMP))
624
    ifa->link_lsa_suppression = ip->link_lsa_suppression;
625 919f5411 Ondrej Zajicek
626 48e5f32d Ondrej Zajicek
  ifa->state = OSPF_IS_DOWN;
627 98ac6176 Ondrej Filip
  init_list(&ifa->neigh_list);
628
  init_list(&ifa->nbma_list);
629 3b16080c Ondrej Filip
630 48e5f32d Ondrej Zajicek
  struct nbma_node *nb;
631 98ac6176 Ondrej Filip
  WALK_LIST(nb, ip->nbma_list)
632 9ff52573 Ondrej Zajicek
  {
633
    /* In OSPFv3, addr is link-local while configured neighbors could
634
       have global IP (although RFC 5340 C.5 says link-local addresses
635
       should be used). Because OSPFv3 iface is not subnet-specific,
636
       there is no need for ipa_in_net() check */
637
638 70945cb6 Ondrej Zajicek
    if (ospf_is_v2(p) && !ipa_in_net(nb->ip, addr->prefix, addr->pxlen))
639 9ff52573 Ondrej Zajicek
      continue;
640 70945cb6 Ondrej Zajicek
641
    if (ospf_is_v3(p) && !ipa_is_link_local(nb->ip))
642 f8fefde3 Ondrej Zajicek
      log(L_WARN "%s: Configured neighbor address (%I) should be link-local",
643
          p->p.name, nb->ip);
644 9ff52573 Ondrej Zajicek
645
    add_nbma_node(ifa, nb, 0);
646
  }
647 98ac6176 Ondrej Filip
648 8e48831a Ondrej Zajicek
  add_tail(&oa->po->iface_list, NODE ifa);
649 98ac6176 Ondrej Filip
650 48e5f32d Ondrej Zajicek
  struct object_lock *lock = olock_new(pool);
651 a7a7372a Ondrej Zajicek
  lock->addr = ospf_is_v2(p) ? ifa->addr->prefix : IPA_NONE;
652 98ac6176 Ondrej Filip
  lock->type = OBJLOCK_IP;
653
  lock->port = OSPF_PROTO;
654 a7a7372a Ondrej Zajicek
  lock->inst = ifa->instance_id;
655 98ac6176 Ondrej Filip
  lock->iface = iface;
656
  lock->data = ifa;
657
  lock->hook = ospf_iface_add;
658
659
  olock_acquire(lock);
660
}
661
662 48e5f32d Ondrej Zajicek
void
663 70945cb6 Ondrej Zajicek
ospf_iface_new_vlink(struct ospf_proto *p, struct ospf_iface_patt *ip)
664 48e5f32d Ondrej Zajicek
{
665
  struct ospf_iface *ifa;
666
  struct pool *pool;
667
668 70945cb6 Ondrej Zajicek
  if (!p->vlink_sk)
669 48e5f32d Ondrej Zajicek
    return;
670
671
  OSPF_TRACE(D_EVENTS, "Adding vlink to %R via area %R", ip->vid, ip->voa);
672
673
  /* Vlink ifname is stored just after the ospf_iface structure */
674
675 70945cb6 Ondrej Zajicek
  pool = rp_new(p->p.pool, "OSPF Vlink");
676 48e5f32d Ondrej Zajicek
  ifa = mb_allocz(pool, sizeof(struct ospf_iface) + 16);
677 70945cb6 Ondrej Zajicek
  ifa->oa = p->backbone;
678 48e5f32d Ondrej Zajicek
  ifa->cf = ip;
679
  ifa->pool = pool;
680
681
  /* Assign iface ID, for vlinks, this is ugly hack */
682 70945cb6 Ondrej Zajicek
  u32 vlink_id = p->last_vlink_id++;
683 48e5f32d Ondrej Zajicek
  ifa->iface_id = vlink_id + OSPF_VLINK_ID_OFFSET;
684
  ifa->ifname = (void *) (ifa + 1);
685
  bsprintf(ifa->ifname, "vlink%d", vlink_id);
686
687 70945cb6 Ondrej Zajicek
  ifa->voa = ospf_find_area(p, ip->voa);
688 48e5f32d Ondrej Zajicek
  ifa->vid = ip->vid;
689 70945cb6 Ondrej Zajicek
  ifa->sk = p->vlink_sk;
690 48e5f32d Ondrej Zajicek
691
  ifa->helloint = ip->helloint;
692
  ifa->rxmtint = ip->rxmtint;
693
  ifa->waitint = ip->waitint;
694
  ifa->deadint = ip->deadint;
695
  ifa->inftransdelay = ip->inftransdelay;
696 70945cb6 Ondrej Zajicek
  ifa->tx_length = ospf_is_v2(p) ? IP4_MIN_MTU : IP6_MIN_MTU;
697 29239ba2 Ondrej Zajicek (work)
  ifa->tx_hdrlen = ifa_tx_hdrlen(ifa);
698 48e5f32d Ondrej Zajicek
  ifa->autype = ip->autype;
699
  ifa->passwords = ip->passwords;
700
  ifa->instance_id = ip->instance_id;
701
702
  ifa->type = OSPF_IT_VLINK;
703
704
  ifa->state = OSPF_IS_DOWN;
705
  init_list(&ifa->neigh_list);
706
  init_list(&ifa->nbma_list);
707
708 70945cb6 Ondrej Zajicek
  add_tail(&p->iface_list, NODE ifa);
709 48e5f32d Ondrej Zajicek
710
  ifa->hello_timer = tm_new_set(ifa->pool, hello_timer_hook, ifa, 0, ifa->helloint);
711 6f8bbaa1 Ondrej Zajicek
712
  ifa->flood_queue_size = ifa_flood_queue_size(ifa);
713
  ifa->flood_queue = mb_allocz(ifa->pool, ifa->flood_queue_size * sizeof(void *));
714 48e5f32d Ondrej Zajicek
}
715
716 beeda6af Ondrej Zajicek
static void
717 70945cb6 Ondrej Zajicek
ospf_iface_change_timer(timer *tm, uint val)
718 beeda6af Ondrej Zajicek
{
719
  if (!tm)
720
    return;
721
722
  tm->recurrent = val;
723
724
  if (tm->expires)
725
    tm_start(tm, val);
726
}
727
728 6f8bbaa1 Ondrej Zajicek
static inline void
729
ospf_iface_update_flood_queue_size(struct ospf_iface *ifa)
730
{
731
  uint old_size = ifa->flood_queue_size;
732
  uint new_size = ifa_flood_queue_size(ifa);
733
734
  if (new_size <= old_size)
735
    return;
736
737
  ifa->flood_queue_size = new_size;
738
  ifa->flood_queue = mb_realloc(ifa->flood_queue, new_size * sizeof(void *));
739
  bzero(ifa->flood_queue + old_size, (new_size - old_size) * sizeof(void *));
740
}
741
742 8e48831a Ondrej Zajicek
int
743
ospf_iface_reconfigure(struct ospf_iface *ifa, struct ospf_iface_patt *new)
744
{
745 70945cb6 Ondrej Zajicek
  struct ospf_proto *p = ifa->oa->po;
746 48e5f32d Ondrej Zajicek
  struct ospf_iface_patt *old = ifa->cf;
747
  char *ifname = ifa->ifname;
748 8e48831a Ondrej Zajicek
749
  /* Type could be changed in ospf_iface_new(),
750
     but if config values are same then also results are same */
751 742029eb Ondrej Zajicek
  int old_type = ospf_iface_classify(old->type, ifa->addr);
752 8e48831a Ondrej Zajicek
  int new_type = ospf_iface_classify(new->type, ifa->addr);
753
  if (old_type != new_type)
754
    return 0;
755
756
  int new_stub = ospf_iface_stubby(new, ifa->addr);
757
  if (ifa->stub != new_stub)
758
    return 0;
759
760 ef4a50be Ondrej Zajicek
  /* Change of these options would require to reset the iface socket */
761 48e5f32d Ondrej Zajicek
  if ((new->real_bcast != old->real_bcast) ||
762
      (new->tx_tos != old->tx_tos) ||
763
      (new->tx_priority != old->tx_priority) ||
764
      (new->ttl_security != old->ttl_security))
765 95127cbb Ondrej Zajicek
    return 0;
766
767 8e48831a Ondrej Zajicek
  ifa->cf = new;
768
  ifa->marked = 0;
769
770
771
  /* HELLO TIMER */
772
  if (ifa->helloint != new->helloint)
773
  {
774 f8fefde3 Ondrej Zajicek
    OSPF_TRACE(D_EVENTS, "Changing hello interval of %s from %d to %d",
775 8e48831a Ondrej Zajicek
               ifname, ifa->helloint, new->helloint);
776
777
    ifa->helloint = new->helloint;
778 beeda6af Ondrej Zajicek
    ospf_iface_change_timer(ifa->hello_timer, ifa->helloint);
779 8e48831a Ondrej Zajicek
  }
780
781
  /* RXMT TIMER */
782
  if (ifa->rxmtint != new->rxmtint)
783
  {
784 f8fefde3 Ondrej Zajicek
    OSPF_TRACE(D_EVENTS, "Changing retransmit interval of %s from %d to %d",
785 8e48831a Ondrej Zajicek
               ifname, ifa->rxmtint, new->rxmtint);
786
787
    ifa->rxmtint = new->rxmtint;
788 6f8bbaa1 Ondrej Zajicek
    /* FIXME: Update neighbors' timers */
789 8e48831a Ondrej Zajicek
  }
790
791
  /* POLL TIMER */
792
  if (ifa->pollint != new->pollint)
793
  {
794 f8fefde3 Ondrej Zajicek
    OSPF_TRACE(D_EVENTS, "Changing poll interval of %s from %d to %d",
795 8e48831a Ondrej Zajicek
               ifname, ifa->pollint, new->pollint);
796
797 beeda6af Ondrej Zajicek
    ifa->pollint = new->pollint;
798
    ospf_iface_change_timer(ifa->poll_timer, ifa->pollint);
799 8e48831a Ondrej Zajicek
  }
800
801
  /* WAIT TIMER */
802
  if (ifa->waitint != new->waitint)
803
  {
804 f8fefde3 Ondrej Zajicek
    OSPF_TRACE(D_EVENTS, "Changing wait interval of %s from %d to %d",
805 8e48831a Ondrej Zajicek
               ifname, ifa->waitint, new->waitint);
806
807
    ifa->waitint = new->waitint;
808 beeda6af Ondrej Zajicek
    if (ifa->wait_timer && ifa->wait_timer->expires)
809 8e48831a Ondrej Zajicek
      tm_start(ifa->wait_timer, ifa->waitint);
810
  }
811
812
  /* DEAD TIMER */
813
  if (ifa->deadint != new->deadint)
814
  {
815 f8fefde3 Ondrej Zajicek
    OSPF_TRACE(D_EVENTS, "Changing dead interval of %s from %d to %d",
816 8e48831a Ondrej Zajicek
               ifname, ifa->deadint, new->deadint);
817
    ifa->deadint = new->deadint;
818
  }
819
820
  /* INFTRANS */
821
  if (ifa->inftransdelay != new->inftransdelay)
822
  {
823 f8fefde3 Ondrej Zajicek
    OSPF_TRACE(D_EVENTS, "Changing transmit delay of %s from %d to %d",
824 8e48831a Ondrej Zajicek
                     ifname, ifa->inftransdelay, new->inftransdelay);
825
    ifa->inftransdelay = new->inftransdelay;
826
  }
827
828
  /* AUTHENTICATION */
829
  if (ifa->autype != new->autype)
830
  {
831 f8fefde3 Ondrej Zajicek
    OSPF_TRACE(D_EVENTS, "Changing authentication type of %s", ifname);
832 8e48831a Ondrej Zajicek
    ifa->autype = new->autype;
833
  }
834
835
  /* Update passwords */
836
  ifa->passwords = new->passwords;
837
838 29239ba2 Ondrej Zajicek (work)
  /* Update header length */
839
  ifa->tx_hdrlen = ifa_tx_hdrlen(ifa);
840
841 8e48831a Ondrej Zajicek
  /* Remaining options are just for proper interfaces */
842
  if (ifa->type == OSPF_IT_VLINK)
843
    return 1;
844
845
846
  /* COST */
847
  if (ifa->cost != new->cost)
848
  {
849 f8fefde3 Ondrej Zajicek
    OSPF_TRACE(D_EVENTS, "Changing cost of %s from %d to %d",
850 8e48831a Ondrej Zajicek
               ifname, ifa->cost, new->cost);
851
852
    ifa->cost = new->cost;
853
  }
854
855
  /* PRIORITY */
856
  if (ifa->priority != new->priority)
857
  {
858 f8fefde3 Ondrej Zajicek
    OSPF_TRACE(D_EVENTS, "Changing priority of %s from %d to %d",
859 8e48831a Ondrej Zajicek
               ifname, ifa->priority, new->priority);
860 70945cb6 Ondrej Zajicek
861 8e48831a Ondrej Zajicek
    ifa->priority = new->priority;
862 70945cb6 Ondrej Zajicek
    ospf_notify_link_lsa(ifa);
863 8e48831a Ondrej Zajicek
  }
864
865
  /* STRICT NBMA */
866
  if (ifa->strictnbma != new->strictnbma)
867
  {
868 f8fefde3 Ondrej Zajicek
    OSPF_TRACE(D_EVENTS, "Changing NBMA strictness of %s from %d to %d",
869
               ifname, ifa->strictnbma, new->strictnbma);
870 8e48831a Ondrej Zajicek
    ifa->strictnbma = new->strictnbma;
871
  }
872
873 48e5f32d Ondrej Zajicek
  struct nbma_node *nb, *nbx;
874
875 8e48831a Ondrej Zajicek
  /* NBMA LIST - remove or update old */
876
  WALK_LIST_DELSAFE(nb, nbx, ifa->nbma_list)
877
  {
878 70945cb6 Ondrej Zajicek
    struct nbma_node *nb2 = find_nbma_node_(&new->nbma_list, nb->ip);
879 8e48831a Ondrej Zajicek
    if (nb2)
880
    {
881
      if (nb->eligible != nb2->eligible)
882
      {
883 f8fefde3 Ondrej Zajicek
        OSPF_TRACE(D_EVENTS, "Changing eligibility of NBMA neighbor %I on %s",
884 8e48831a Ondrej Zajicek
                   nb->ip, ifname);
885
        nb->eligible = nb2->eligible;
886
      }
887
    }
888
    else
889
    {
890 f8fefde3 Ondrej Zajicek
      OSPF_TRACE(D_EVENTS, "Removing NBMA neighbor %I on %s",
891 8e48831a Ondrej Zajicek
                       nb->ip, ifname);
892
      rem_node(NODE nb);
893
      mb_free(nb);
894
    }
895
  }
896
897
  /* NBMA LIST - add new */
898
  WALK_LIST(nb, new->nbma_list)
899
  {
900 9ff52573 Ondrej Zajicek
    /* See related note in ospf_iface_new() */
901 70945cb6 Ondrej Zajicek
    if (ospf_is_v2(p) && !ipa_in_net(nb->ip, ifa->addr->prefix, ifa->addr->pxlen))
902 8e48831a Ondrej Zajicek
      continue;
903 70945cb6 Ondrej Zajicek
904
    if (ospf_is_v3(p) && !ipa_is_link_local(nb->ip))
905 f8fefde3 Ondrej Zajicek
      log(L_WARN "%s: Configured neighbor address (%I) should be link-local",
906
          p->p.name, nb->ip);
907 8e48831a Ondrej Zajicek
908
    if (! find_nbma_node(ifa, nb->ip))
909
    {
910 f8fefde3 Ondrej Zajicek
      OSPF_TRACE(D_EVENTS, "Adding NBMA neighbor %I on %s",
911 8e48831a Ondrej Zajicek
                 nb->ip, ifname);
912
      add_nbma_node(ifa, nb, !!find_neigh_by_ip(ifa, nb->ip));
913
    }
914
  }
915
916 48e5f32d Ondrej Zajicek
  int update_buffers = 0;
917
918
  /* TX LENGTH */
919
  if (old->tx_length != new->tx_length)
920
  {
921 f8fefde3 Ondrej Zajicek
    OSPF_TRACE(D_EVENTS, "Changing TX length of %s from %d to %d",
922 48e5f32d Ondrej Zajicek
               ifname, old->tx_length, new->tx_length);
923
924
    /* ifa cannot be vlink */
925
    ifa->tx_length = ifa_tx_length(ifa);
926
    update_buffers = 1;
927 6f8bbaa1 Ondrej Zajicek
928
    if (!ifa->stub)
929
      ospf_iface_update_flood_queue_size(ifa);
930 48e5f32d Ondrej Zajicek
  }
931
932
  /* RX BUFFER */
933
  if (old->rx_buffer != new->rx_buffer)
934
  {
935 f8fefde3 Ondrej Zajicek
    OSPF_TRACE(D_EVENTS, "Changing buffer size of %s from %d to %d",
936 48e5f32d Ondrej Zajicek
               ifname, old->rx_buffer, new->rx_buffer);
937
938
    /* ifa cannot be vlink */
939
    update_buffers = 1;
940
  }
941
942
  /* Buffer size depends on both tx_length and rx_buffer options */
943
  if (update_buffers && ifa->sk)
944 8e48831a Ondrej Zajicek
  {
945 48e5f32d Ondrej Zajicek
    uint bsize = ifa_bufsize(ifa);
946
    sk_set_rbsize(ifa->sk, bsize);
947
    sk_set_tbsize(ifa->sk, bsize);
948 8e48831a Ondrej Zajicek
  }
949
950
  /* LINK */
951
  if (ifa->check_link != new->check_link)
952
  {
953 f8fefde3 Ondrej Zajicek
    OSPF_TRACE(D_EVENTS, "%s link check for %s",
954 8e48831a Ondrej Zajicek
               new->check_link ? "Enabling" : "Disabling", ifname);
955
    ifa->check_link = new->check_link;
956
957 48e5f32d Ondrej Zajicek
    /* ifa cannot be vlink */
958 8e48831a Ondrej Zajicek
    if (!(ifa->iface->flags & IF_LINK_UP))
959
      ospf_iface_sm(ifa, ifa->check_link ? ISM_LOOP : ISM_UNLOOP);
960
  }
961
962
  /* ECMP weight */
963
  if (ifa->ecmp_weight != new->ecmp_weight)
964
  {
965 f8fefde3 Ondrej Zajicek
    OSPF_TRACE(D_EVENTS, "Changing ECMP weight of %s from %d to %d",
966 8e48831a Ondrej Zajicek
               ifname, (int)ifa->ecmp_weight + 1, (int)new->ecmp_weight + 1);
967
    ifa->ecmp_weight = new->ecmp_weight;
968
  }
969
970 70945cb6 Ondrej Zajicek
  /* Link LSA suppression */
971
  if (((ifa->type == OSPF_IT_PTP) || (ifa->type == OSPF_IT_PTMP)) &&
972
      (ifa->link_lsa_suppression != new->link_lsa_suppression))
973
  {
974
    OSPF_TRACE(D_EVENTS, "Changing link LSA suppression of %s from %d to %d",
975
               ifname, ifa->link_lsa_suppression, new->link_lsa_suppression);
976
977
    ifa->link_lsa_suppression = new->link_lsa_suppression;
978
    ospf_notify_link_lsa(ifa);
979
  }
980
981 1ec52253 Ondrej Zajicek
  /* BFD */
982
  if (ifa->bfd != new->bfd)
983
  {
984 f8fefde3 Ondrej Zajicek
    OSPF_TRACE(D_EVENTS, "%s BFD for %s",
985 1ec52253 Ondrej Zajicek
               new->bfd ? "Enabling" : "Disabling", ifname);
986
    ifa->bfd = new->bfd;
987
988
    struct ospf_neighbor *n;
989
    WALK_LIST(n, ifa->neigh_list)
990
      ospf_neigh_update_bfd(n, ifa->bfd);
991
  }
992
993
994 8e48831a Ondrej Zajicek
  /* instance_id is not updated - it is part of key */
995
996
  return 1;
997
}
998
999 0aad2b92 Ondrej Zajicek
1000 70945cb6 Ondrej Zajicek
/*
1001
 * State for matching iface pattterns walk
1002
 *
1003
 * This is significantly different in OSPFv2 and OSPFv3.
1004
 * In OSPFv2, OSPF ifaces are created for each IP prefix (struct ifa)
1005
 * In OSPFv3, OSPF ifaces are created based on real iface (struct iface)
1006
 * We support instance_id for both OSPFv2 (RFC 6549) and OSPFv3.
1007
 *
1008
 * We process one ifa/iface and match it for all configured instance IDs. We
1009
 * maintain bitfields to track whether given instance ID was already matched.
1010
 * We have two bitfields, one global (active) and one per area (ignore), to
1011
 * detect misconfigured cases where one iface with one instance ID matches in
1012
 * multiple areas.
1013
 */
1014 0aad2b92 Ondrej Zajicek
1015 70945cb6 Ondrej Zajicek
struct ospf_mip_walk {
1016
  u32 active[8];                /* Bitfield of active instance IDs */
1017
  u32 ignore[8];                /* Bitfield of instance IDs matched in current area */
1018
  struct ospf_area *oa;                /* Current area */
1019
  struct ospf_iface_patt *ip;        /* Current iface pattern */
1020
  struct iface *iface;                /* Specified iface (input) */
1021
  struct ifa *a;                /* Specified ifa (input) */
1022
  int warn;                        /* Whether iface matched in multiple areas */
1023
};
1024 8e48831a Ondrej Zajicek
1025 70945cb6 Ondrej Zajicek
static int
1026
ospf_walk_matching_iface_patts(struct ospf_proto *p, struct ospf_mip_walk *s)
1027 0aad2b92 Ondrej Zajicek
{
1028 70945cb6 Ondrej Zajicek
  int id;
1029 0aad2b92 Ondrej Zajicek
1030 70945cb6 Ondrej Zajicek
  if (s->ip)
1031
    goto step;
1032 0aad2b92 Ondrej Zajicek
1033 70945cb6 Ondrej Zajicek
  WALK_LIST(s->oa, p->area_list)
1034 0aad2b92 Ondrej Zajicek
  {
1035 cd3b7003 Ondrej Zajicek
    if (s->oa->marked)
1036
      continue;
1037
1038 70945cb6 Ondrej Zajicek
    WALK_LIST(s->ip, s->oa->ac->patt_list)
1039 0aad2b92 Ondrej Zajicek
    {
1040 70945cb6 Ondrej Zajicek
      id = s->ip->instance_id;
1041
      if (BIT32_TEST(s->ignore, id))
1042
        continue;
1043
1044
      if (iface_patt_match(&s->ip->i, s->iface, s->a))
1045 0aad2b92 Ondrej Zajicek
      {
1046 70945cb6 Ondrej Zajicek
        /* Now we matched ifa/iface/instance_id for the first time in current area */
1047
        BIT32_SET(s->ignore, id);
1048 0aad2b92 Ondrej Zajicek
1049 70945cb6 Ondrej Zajicek
        /* If we already found it in previous areas, ignore it and add warning */
1050 a7a7372a Ondrej Zajicek
        if (BIT32_TEST(s->active, id))
1051 70945cb6 Ondrej Zajicek
          { s->warn = 1; continue; }
1052 0aad2b92 Ondrej Zajicek
1053 70945cb6 Ondrej Zajicek
        BIT32_SET(s->active, id);
1054
        return 1;
1055
      step:
1056
        ;
1057
      }
1058 0aad2b92 Ondrej Zajicek
    }
1059 70945cb6 Ondrej Zajicek
    BIT32_ZERO(s->ignore, 256);
1060 0aad2b92 Ondrej Zajicek
  }
1061 70945cb6 Ondrej Zajicek
1062
  if (s->warn)
1063
    log(L_WARN "%s: Interface %s matches for multiple areas", p->p.name, s->iface->name);
1064
1065
  return 0;
1066 0aad2b92 Ondrej Zajicek
}
1067
1068 70945cb6 Ondrej Zajicek
1069 8e48831a Ondrej Zajicek
static struct ospf_iface *
1070 70945cb6 Ondrej Zajicek
ospf_iface_find_by_key(struct ospf_proto *p, struct ifa *a, int instance_id)
1071 8e48831a Ondrej Zajicek
{
1072
  struct ospf_iface *ifa;
1073 70945cb6 Ondrej Zajicek
1074
  WALK_LIST(ifa, p->iface_list)
1075
    if ((ifa->addr == a) && (ifa->instance_id == instance_id) &&
1076
        (ifa->type != OSPF_IT_VLINK))
1077 8e48831a Ondrej Zajicek
      return ifa;
1078
1079
  return NULL;
1080
}
1081 0aad2b92 Ondrej Zajicek
1082 70945cb6 Ondrej Zajicek
1083 8e48831a Ondrej Zajicek
void
1084 70945cb6 Ondrej Zajicek
ospf_ifa_notify2(struct proto *P, uint flags, struct ifa *a)
1085 0aad2b92 Ondrej Zajicek
{
1086 70945cb6 Ondrej Zajicek
  struct ospf_proto *p = (struct ospf_proto *) P;
1087 227af52f Ondrej Zajicek
1088 70945cb6 Ondrej Zajicek
  if (a->flags & IA_SECONDARY)
1089
    return;
1090 8e48831a Ondrej Zajicek
1091 70945cb6 Ondrej Zajicek
  if (a->scope <= SCOPE_LINK)
1092
    return;
1093 8e48831a Ondrej Zajicek
1094 70945cb6 Ondrej Zajicek
  /* In OSPFv2, we create OSPF iface for each address. */
1095
  if (flags & IF_CHANGE_UP)
1096
  {
1097
    struct ospf_mip_walk s = { .iface = a->iface, .a = a };
1098
    while (ospf_walk_matching_iface_patts(p, &s))
1099 a7a7372a Ondrej Zajicek
      ospf_iface_new(s.oa, a, s.ip);
1100 227af52f Ondrej Zajicek
  }
1101 8e48831a Ondrej Zajicek
1102 70945cb6 Ondrej Zajicek
  if (flags & IF_CHANGE_DOWN)
1103
  {
1104
    struct ospf_iface *ifa, *ifx;
1105
    WALK_LIST_DELSAFE(ifa, ifx, p->iface_list)
1106
      if ((ifa->type != OSPF_IT_VLINK) && (ifa->addr == a))
1107
        ospf_iface_remove(ifa);
1108
    /* See a note in ospf_iface_notify() */
1109
  }
1110 0aad2b92 Ondrej Zajicek
}
1111
1112
void
1113 70945cb6 Ondrej Zajicek
ospf_ifa_notify3(struct proto *P, uint flags, struct ifa *a)
1114 0aad2b92 Ondrej Zajicek
{
1115 70945cb6 Ondrej Zajicek
  struct ospf_proto *p = (struct ospf_proto *) P;
1116 0aad2b92 Ondrej Zajicek
1117
  if (a->flags & IA_SECONDARY)
1118
    return;
1119
1120
  if (a->scope < SCOPE_LINK)
1121
    return;
1122
1123
  /* In OSPFv3, we create OSPF iface for link-local address,
1124
     other addresses are used for link-LSA. */
1125
  if (a->scope == SCOPE_LINK)
1126
  {
1127
    if (flags & IF_CHANGE_UP)
1128
    {
1129 70945cb6 Ondrej Zajicek
      struct ospf_mip_walk s = { .iface = a->iface };
1130
      while (ospf_walk_matching_iface_patts(p, &s))
1131 a7a7372a Ondrej Zajicek
        ospf_iface_new(s.oa, a, s.ip);
1132 0aad2b92 Ondrej Zajicek
    }
1133
1134
    if (flags & IF_CHANGE_DOWN)
1135
    {
1136
      struct ospf_iface *ifa, *ifx;
1137 70945cb6 Ondrej Zajicek
      WALK_LIST_DELSAFE(ifa, ifx, p->iface_list)
1138
        if ((ifa->addr == a) && (ifa->type != OSPF_IT_VLINK))
1139 d9e7e1b1 Ondrej Zajicek
          ospf_iface_remove(ifa);
1140 0aad2b92 Ondrej Zajicek
    }
1141
  }
1142
  else
1143
  {
1144
    struct ospf_iface *ifa;
1145 70945cb6 Ondrej Zajicek
    WALK_LIST(ifa, p->iface_list)
1146 0aad2b92 Ondrej Zajicek
      if (ifa->iface == a->iface)
1147
      {
1148 70945cb6 Ondrej Zajicek
        /* RFC 5340 4.4.3 Event 5 - prefix added/deleted */
1149
        ospf_notify_link_lsa(ifa);
1150
        ospf_notify_rt_lsa(ifa->oa);
1151 0aad2b92 Ondrej Zajicek
      }
1152
  }
1153
}
1154
1155 70945cb6 Ondrej Zajicek
1156
static void
1157
ospf_reconfigure_ifaces2(struct ospf_proto *p)
1158 8e48831a Ondrej Zajicek
{
1159 70945cb6 Ondrej Zajicek
  struct iface *iface;
1160
  struct ifa *a;
1161 8e48831a Ondrej Zajicek
1162 70945cb6 Ondrej Zajicek
  WALK_LIST(iface, iface_list)
1163
  {
1164
    if (! (iface->flags & IF_UP))
1165
      continue;
1166
1167
    WALK_LIST(a, iface->addrs)
1168
    {
1169
      if (a->flags & IA_SECONDARY)
1170
        continue;
1171
1172
      if (a->scope <= SCOPE_LINK)
1173
        continue;
1174
1175
      struct ospf_mip_walk s = { .iface = iface, .a = a };
1176
      while (ospf_walk_matching_iface_patts(p, &s))
1177
      {
1178
        /* Main inner loop */
1179
        struct ospf_iface *ifa = ospf_iface_find_by_key(p, a, s.ip->instance_id);
1180
        if (ifa)
1181
        {
1182
          if ((ifa->oa == s.oa) && (ifa->marked < 2) &&
1183
              ospf_iface_reconfigure(ifa, s.ip))
1184
            continue;
1185
1186
          /* Hard restart */
1187
          log(L_INFO "%s: Restarting interface %s (%I/%d) in area %R",
1188
              p->p.name, ifa->ifname, a->prefix, a->pxlen, s.oa->areaid);
1189
          ospf_iface_shutdown(ifa);
1190
          ospf_iface_remove(ifa);
1191
        }
1192 742029eb Ondrej Zajicek
1193 70945cb6 Ondrej Zajicek
        ospf_iface_new(s.oa, a, s.ip);
1194
      }
1195
    }
1196
  }
1197 8e48831a Ondrej Zajicek
}
1198 0aad2b92 Ondrej Zajicek
1199 70945cb6 Ondrej Zajicek
static void
1200
ospf_reconfigure_ifaces3(struct ospf_proto *p)
1201 8e48831a Ondrej Zajicek
{
1202
  struct iface *iface;
1203
  struct ifa *a;
1204
1205
  WALK_LIST(iface, iface_list)
1206 227af52f Ondrej Zajicek
  {
1207
    if (! (iface->flags & IF_UP))
1208
      continue;
1209
1210 8e48831a Ondrej Zajicek
    WALK_LIST(a, iface->addrs)
1211
    {
1212
      if (a->flags & IA_SECONDARY)
1213
        continue;
1214
1215
      if (a->scope != SCOPE_LINK)
1216
        continue;
1217
1218 70945cb6 Ondrej Zajicek
      struct ospf_mip_walk s = { .iface = iface };
1219
      while (ospf_walk_matching_iface_patts(p, &s))
1220 8e48831a Ondrej Zajicek
      {
1221
        /* Main inner loop */
1222 70945cb6 Ondrej Zajicek
        struct ospf_iface *ifa = ospf_iface_find_by_key(p, a, s.ip->instance_id);
1223 8e48831a Ondrej Zajicek
        if (ifa)
1224
        {
1225 70945cb6 Ondrej Zajicek
          if ((ifa->oa == s.oa) && (ifa->marked < 2) &&
1226
              ospf_iface_reconfigure(ifa, s.ip))
1227 8e48831a Ondrej Zajicek
            continue;
1228
1229
          /* Hard restart */
1230 48e5f32d Ondrej Zajicek
          log(L_INFO "%s: Restarting interface %s (IID %d) in area %R",
1231 70945cb6 Ondrej Zajicek
              p->p.name, ifa->ifname, ifa->instance_id, s.oa->areaid);
1232 8e48831a Ondrej Zajicek
          ospf_iface_shutdown(ifa);
1233
          ospf_iface_remove(ifa);
1234
        }
1235
1236 70945cb6 Ondrej Zajicek
        ospf_iface_new(s.oa, a, s.ip);
1237 8e48831a Ondrej Zajicek
      }
1238
    }
1239 227af52f Ondrej Zajicek
  }
1240 8e48831a Ondrej Zajicek
}
1241
1242 70945cb6 Ondrej Zajicek
void
1243
ospf_reconfigure_ifaces(struct ospf_proto *p)
1244
{
1245
  if (ospf_is_v2(p))
1246
    ospf_reconfigure_ifaces2(p);
1247
  else
1248
    ospf_reconfigure_ifaces3(p);
1249
}
1250
1251 8e48831a Ondrej Zajicek
1252
static void
1253 70945cb6 Ondrej Zajicek
ospf_iface_change_mtu(struct ospf_proto *p, struct ospf_iface *ifa)
1254 94c42054 Ondrej Filip
{
1255 48e5f32d Ondrej Zajicek
  /* ifa is not vlink */
1256 94c42054 Ondrej Filip
1257 f8fefde3 Ondrej Zajicek
  OSPF_TRACE(D_EVENTS, "Interface %s changed MTU to %d", ifa->iface->mtu);
1258 94c42054 Ondrej Filip
1259 48e5f32d Ondrej Zajicek
  ifa->tx_length = ifa_tx_length(ifa);
1260 94c42054 Ondrej Filip
1261 48e5f32d Ondrej Zajicek
  if (!ifa->sk)
1262
    return;
1263
1264
  /* We do not shrink dynamic buffers */
1265
  uint bsize = ifa_bufsize(ifa);
1266
  if (bsize > ifa->sk->rbsize)
1267
    sk_set_rbsize(ifa->sk, bsize);
1268
  if (bsize > ifa->sk->tbsize)
1269
    sk_set_tbsize(ifa->sk, bsize);
1270 6f8bbaa1 Ondrej Zajicek
1271
  if (!ifa->stub)
1272
    ospf_iface_update_flood_queue_size(ifa);
1273 94c42054 Ondrej Filip
}
1274
1275 d9e7e1b1 Ondrej Zajicek
static void
1276 70945cb6 Ondrej Zajicek
ospf_iface_notify(struct ospf_proto *p, uint flags, struct ospf_iface *ifa)
1277 d9e7e1b1 Ondrej Zajicek
{
1278 48e5f32d Ondrej Zajicek
  /* ifa is not vlink */
1279
1280 d9e7e1b1 Ondrej Zajicek
  if (flags & IF_CHANGE_DOWN)
1281
  {
1282
    ospf_iface_remove(ifa);
1283
    return;
1284
  }
1285
1286
  if (flags & IF_CHANGE_LINK)
1287
    ospf_iface_sm(ifa, (ifa->iface->flags & IF_LINK_UP) ? ISM_UNLOOP : ISM_LOOP);
1288
1289
  if (flags & IF_CHANGE_MTU)
1290 70945cb6 Ondrej Zajicek
    ospf_iface_change_mtu(p, ifa);
1291 d9e7e1b1 Ondrej Zajicek
}
1292
1293 94c42054 Ondrej Filip
void
1294 70945cb6 Ondrej Zajicek
ospf_if_notify(struct proto *P, uint flags, struct iface *iface)
1295 4364b47e Ondrej Filip
{
1296 70945cb6 Ondrej Zajicek
  struct ospf_proto *p = (struct ospf_proto *) P;
1297 8e48831a Ondrej Zajicek
1298
  /*
1299 4364b47e Ondrej Filip
  if (iface->flags & IF_IGNORE)
1300
    return;
1301 8e48831a Ondrej Zajicek
  */
1302 4364b47e Ondrej Filip
1303 8e48831a Ondrej Zajicek
  /* Going up means that there are no such ifaces yet */
1304 d9e7e1b1 Ondrej Zajicek
  if (flags & IF_CHANGE_UP)
1305
    return;
1306 0aad2b92 Ondrej Zajicek
1307 d9e7e1b1 Ondrej Zajicek
  struct ospf_iface *ifa, *ifx;
1308 70945cb6 Ondrej Zajicek
  WALK_LIST_DELSAFE(ifa, ifx, p->iface_list)
1309 48e5f32d Ondrej Zajicek
    if (ifa->iface == iface)
1310 70945cb6 Ondrej Zajicek
      ospf_iface_notify(p, flags, ifa);
1311 4364b47e Ondrej Filip
1312 d9e7e1b1 Ondrej Zajicek
  /* We use here that even shutting down iface also shuts down
1313
     the vlinks, but vlinks are not freed and stays in the
1314
     iface_list even when down */
1315 4364b47e Ondrej Filip
}
1316
1317 c4f0f014 Ondrej Filip
void
1318
ospf_iface_info(struct ospf_iface *ifa)
1319
{
1320 95127cbb Ondrej Zajicek
  char *more = "";
1321 919f5411 Ondrej Zajicek
1322
  if (ifa->strictnbma &&
1323
      ((ifa->type == OSPF_IT_NBMA) || (ifa->type == OSPF_IT_PTMP)))
1324 95127cbb Ondrej Zajicek
    more = " (strict)";
1325
1326
  if (ifa->cf->real_bcast &&
1327
      ((ifa->type == OSPF_IT_BCAST) || (ifa->type == OSPF_IT_PTP)))
1328
    more = " (real)";
1329 b9ed99f7 Ondrej Filip
1330 3b16080c Ondrej Filip
  if (ifa->type == OSPF_IT_VLINK)
1331
  {
1332 70945cb6 Ondrej Zajicek
    cli_msg(-1015, "Virtual link %s to %R", ifa->ifname, ifa->vid);
1333 6901fd06 Ondrej Filip
    cli_msg(-1015, "\tPeer IP: %I", ifa->vip);
1334 48e5f32d Ondrej Zajicek
    cli_msg(-1015, "\tTransit area: %R (%u)", ifa->voa->areaid, ifa->voa->areaid);
1335 3b16080c Ondrej Filip
  }
1336
  else
1337
  {
1338 70945cb6 Ondrej Zajicek
    if (ospf_is_v3(ifa->oa->po))
1339
      cli_msg(-1015, "Interface %s (IID %d)", ifa->ifname, ifa->instance_id);
1340
    else if (ifa->addr->flags & IA_PEER)
1341 48e5f32d Ondrej Zajicek
      cli_msg(-1015, "Interface %s (peer %I)", ifa->ifname, ifa->addr->opposite);
1342 0aad2b92 Ondrej Zajicek
    else
1343 48e5f32d Ondrej Zajicek
      cli_msg(-1015, "Interface %s (%I/%d)", ifa->ifname, ifa->addr->prefix, ifa->addr->pxlen);
1344 70945cb6 Ondrej Zajicek
1345 95127cbb Ondrej Zajicek
    cli_msg(-1015, "\tType: %s%s", ospf_it[ifa->type], more);
1346 3aab39f5 Ondrej Zajicek
    cli_msg(-1015, "\tArea: %R (%u)", ifa->oa->areaid, ifa->oa->areaid);
1347 3b16080c Ondrej Filip
  }
1348 f8fefde3 Ondrej Zajicek
  cli_msg(-1015, "\tState: %s%s", ospf_is_names[ifa->state], ifa->stub ? " (stub)" : "");
1349 b9ed99f7 Ondrej Filip
  cli_msg(-1015, "\tPriority: %u", ifa->priority);
1350
  cli_msg(-1015, "\tCost: %u", ifa->cost);
1351 57c574d8 Ondrej Zajicek
  if (ifa->oa->po->ecmp)
1352
    cli_msg(-1015, "\tECMP weight: %d", ((int) ifa->ecmp_weight) + 1);
1353 b9ed99f7 Ondrej Filip
  cli_msg(-1015, "\tHello timer: %u", ifa->helloint);
1354 f9bdcad4 Ondrej Zajicek
1355 b9ed99f7 Ondrej Filip
  if (ifa->type == OSPF_IT_NBMA)
1356 f8f1e1f1 Ondrej Filip
  {
1357 b9ed99f7 Ondrej Filip
    cli_msg(-1015, "\tPoll timer: %u", ifa->pollint);
1358 f8f1e1f1 Ondrej Filip
  }
1359 b9ed99f7 Ondrej Filip
  cli_msg(-1015, "\tWait timer: %u", ifa->waitint);
1360 8e48831a Ondrej Zajicek
  cli_msg(-1015, "\tDead timer: %u", ifa->deadint);
1361 b9ed99f7 Ondrej Filip
  cli_msg(-1015, "\tRetransmit timer: %u", ifa->rxmtint);
1362
  if ((ifa->type == OSPF_IT_BCAST) || (ifa->type == OSPF_IT_NBMA))
1363 f8f1e1f1 Ondrej Filip
  {
1364 398f9225 Ondrej Filip
    cli_msg(-1015, "\tDesignated router (ID): %R", ifa->drid);
1365
    cli_msg(-1015, "\tDesignated router (IP): %I", ifa->drip);
1366
    cli_msg(-1015, "\tBackup designated router (ID): %R", ifa->bdrid);
1367
    cli_msg(-1015, "\tBackup designated router (IP): %I", ifa->bdrip);
1368 f8f1e1f1 Ondrej Filip
  }
1369 78e2c6cc Ondrej Filip
}