Statistics
| Branch: | Revision:

iof-bird / bird-2.0.1 / proto / ospf / iface.c @ 6b3f1a54

History | View | Annotate | Download (33.8 KB)

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

    
11
#include "ospf.h"
12
#include "nest/password.h"
13

    
14

    
15
const char *ospf_is_names[] = {
16
  "Down", "Loopback", "Waiting", "PtP", "DROther", "Backup", "DR"
17
};
18

    
19
const char *ospf_ism_names[] = {
20
  "InterfaceUp", "WaitTimer", "BackupSeen", "NeighborChange",
21
  "LoopInd", "UnloopInd", "InterfaceDown"
22
};
23

    
24
const char *ospf_it[] = { "broadcast", "nbma", "ptp", "ptmp", "virtual link" };
25

    
26

    
27
static void
28
poll_timer_hook(timer * timer)
29
{
30
  ospf_send_hello(timer->data, OHS_POLL, NULL);
31
}
32

    
33
static void
34
hello_timer_hook(timer * timer)
35
{
36
  ospf_send_hello(timer->data, OHS_HELLO, NULL);
37
}
38

    
39
static void
40
wait_timer_hook(timer * timer)
41
{
42
  struct ospf_iface *ifa = (struct ospf_iface *) timer->data;
43
  struct ospf_proto *p = ifa->oa->po;
44

    
45
  OSPF_TRACE(D_EVENTS, "Wait timer fired on %s", ifa->ifname);
46
  ospf_iface_sm(ifa, ISM_WAITF);
47
}
48

    
49
static inline uint
50
ifa_tx_length(struct ospf_iface *ifa)
51
{
52
  return ifa->cf->tx_length ?: ifa->iface->mtu;
53
}
54

    
55
static inline uint
56
ifa_tx_hdrlen(struct ospf_iface *ifa)
57
{
58
  struct ospf_proto *p = ifa->oa->po;
59

    
60
  uint hlen = ospf_is_v2(p) ? IP4_HEADER_LENGTH : IP6_HEADER_LENGTH;
61

    
62
  /* Relevant just for OSPFv2 */
63
  if (ifa->autype == OSPF_AUTH_CRYPT)
64
    hlen += max_mac_length(ifa->passwords);
65

    
66
  return hlen;
67
}
68

    
69
static inline uint
70
ifa_bufsize(struct ospf_iface *ifa)
71
{
72
  uint bsize = ifa->cf->rx_buffer ?: ifa->iface->mtu;
73
  return MAX(bsize, ifa->tx_length);
74
}
75

    
76
static inline uint
77
ifa_flood_queue_size(struct ospf_iface *ifa)
78
{
79
  return ifa->tx_length / 24;
80
}
81

    
82
int
83
ospf_iface_assure_bufsize(struct ospf_iface *ifa, uint plen)
84
{
85
  plen += ifa->tx_hdrlen;
86

    
87
  if (plen <= ifa->sk->tbsize)
88
    return 0;
89

    
90
  if (ifa->cf->rx_buffer || (plen > 0xffff))
91
    return -1;
92

    
93
  plen = BIRD_ALIGN(plen, 1024);
94
  plen = MIN(plen, 0xffff);
95
  sk_set_tbsize(ifa->sk, plen);
96
  return 1;
97
}
98

    
99

    
100
struct nbma_node *
101
find_nbma_node_(list *nnl, ip_addr ip)
102
{
103
  struct nbma_node *nn;
104

    
105
  WALK_LIST(nn, *nnl)
106
    if (ipa_equal(nn->ip, ip))
107
      return nn;
108

    
109
  return NULL;
110
}
111

    
112

    
113
static int
114
ospf_sk_open(struct ospf_iface *ifa)
115
{
116
  struct ospf_proto *p = ifa->oa->po;
117

    
118
  sock *sk = sk_new(ifa->pool);
119
  sk->type = SK_IP;
120
  sk->subtype = ospf_is_v2(p) ? SK_IPV4 : SK_IPV6;
121
  sk->dport = OSPF_PROTO;
122
  sk->saddr = ifa->addr->ip;
123
  sk->iface = ifa->iface;
124
  sk->vrf = p->p.vrf;
125

    
126
  sk->tos = ifa->cf->tx_tos;
127
  sk->priority = ifa->cf->tx_priority;
128
  sk->rx_hook = ospf_rx_hook;
129
  // sk->tx_hook = ospf_tx_hook;
130
  sk->err_hook = ospf_err_hook;
131
  sk->rbsize = sk->tbsize = ifa_bufsize(ifa);
132
  sk->data = (void *) ifa;
133
  sk->flags = SKF_LADDR_RX | (ifa->check_ttl ? SKF_TTL_RX : 0);
134
  sk->ttl = ifa->cf->ttl_security ? 255 : 1;
135

    
136
  if (sk_open(sk) < 0)
137
    goto err;
138

    
139
  /* 12 is an offset of the checksum in an OSPFv3 packet */
140
  if (ospf_is_v3(p))
141
    if (sk_set_ipv6_checksum(sk, 12) < 0)
142
      goto err;
143

    
144
  if ((ifa->type == OSPF_IT_BCAST) || (ifa->type == OSPF_IT_PTP))
145
  {
146
    if (ifa->cf->real_bcast)
147
    {
148
      ifa->all_routers = ifa->addr->brd;
149
      ifa->des_routers = IPA_NONE;
150

    
151
      if (sk_setup_broadcast(sk) < 0)
152
        goto err;
153
    }
154
    else
155
    {
156
      ifa->all_routers = ospf_is_v2(p) ? IP4_OSPF_ALL_ROUTERS : IP6_OSPF_ALL_ROUTERS;
157
      ifa->des_routers = ospf_is_v2(p) ? IP4_OSPF_DES_ROUTERS : IP6_OSPF_DES_ROUTERS;
158

    
159
      if (sk_setup_multicast(sk) < 0)
160
        goto err;
161

    
162
      if (sk_join_group(sk, ifa->all_routers) < 0)
163
        goto err;
164
    }
165
  }
166

    
167
  ifa->sk = sk;
168
  ifa->sk_dr = 0;
169
  return 1;
170

    
171
 err:
172
  sk_log_error(sk, p->p.name);
173
  rfree(sk);
174
  return 0;
175
}
176

    
177
static inline void
178
ospf_sk_join_dr(struct ospf_iface *ifa)
179
{
180
  if (ifa->sk_dr)
181
    return;
182

    
183
  if (sk_join_group(ifa->sk, ifa->des_routers) < 0)
184
    sk_log_error(ifa->sk, ifa->oa->po->p.name);
185

    
186
  ifa->sk_dr = 1;
187
}
188

    
189
static inline void
190
ospf_sk_leave_dr(struct ospf_iface *ifa)
191
{
192
  if (!ifa->sk_dr)
193
    return;
194

    
195
  if (sk_leave_group(ifa->sk, ifa->des_routers) < 0)
196
    sk_log_error(ifa->sk, ifa->oa->po->p.name);
197

    
198
  ifa->sk_dr = 0;
199
}
200

    
201
void
202
ospf_open_vlink_sk(struct ospf_proto *p)
203
{
204
  sock *sk = sk_new(p->p.pool);
205
  sk->type = SK_IP;
206
  sk->subtype = ospf_is_v2(p) ? SK_IPV4 : SK_IPV6;
207
  sk->dport = OSPF_PROTO;
208
  sk->vrf = p->p.vrf;
209

    
210
  /* FIXME: configurable tos/priority ? */
211
  sk->tos = IP_PREC_INTERNET_CONTROL;
212
  sk->priority = sk_priority_control;
213
  sk->err_hook = ospf_verr_hook;
214

    
215
  sk->rbsize = 0;
216
  sk->tbsize = ospf_is_v2(p) ? IP4_MIN_MTU : IP6_MIN_MTU;
217
  sk->data = (void *) p;
218
  sk->flags = 0;
219

    
220
  if (sk_open(sk) < 0)
221
    goto err;
222

    
223
  /* 12 is an offset of the checksum in an OSPFv3 packet */
224
  if (ospf_is_v3(p))
225
    if (sk_set_ipv6_checksum(sk, 12) < 0)
226
      goto err;
227

    
228
  p->vlink_sk = sk;
229
  return;
230

    
231
 err:
232
  sk_log_error(sk, p->p.name);
233
  log(L_ERR "%s: Cannot open virtual link socket", p->p.name);
234
  rfree(sk);
235
}
236

    
237
static void
238
ospf_iface_down(struct ospf_iface *ifa)
239
{
240
  struct ospf_proto *p = ifa->oa->po;
241
  struct ospf_neighbor *n, *nx;
242
  struct ospf_iface *iff;
243

    
244
  if (ifa->type != OSPF_IT_VLINK)
245
  {
246
    if (ospf_is_v3(ifa->oa->po))
247
      OSPF_TRACE(D_EVENTS, "Removing interface %s (IID %d) from area %R",
248
                 ifa->ifname, ifa->instance_id, ifa->oa->areaid);
249
    else if (ifa->addr->flags & IA_PEER)
250
      OSPF_TRACE(D_EVENTS, "Removing interface %s (peer %I) from area %R",
251
                 ifa->ifname, ifa->addr->opposite, ifa->oa->areaid);
252
    else
253
      OSPF_TRACE(D_EVENTS, "Removing interface %s (%N) from area %R",
254
                 ifa->ifname, &ifa->addr->prefix, ifa->oa->areaid);
255

    
256
    /* First of all kill all the related vlinks */
257
    WALK_LIST(iff, p->iface_list)
258
    {
259
      if ((iff->type == OSPF_IT_VLINK) && (iff->vifa == ifa))
260
        ospf_iface_sm(iff, ISM_DOWN);
261
    }
262
  }
263

    
264
  WALK_LIST_DELSAFE(n, nx, ifa->neigh_list)
265
    ospf_neigh_sm(n, INM_KILLNBR);
266

    
267
  if (ifa->hello_timer)
268
    tm_stop(ifa->hello_timer);
269

    
270
  if (ifa->poll_timer)
271
    tm_stop(ifa->poll_timer);
272

    
273
  if (ifa->wait_timer)
274
    tm_stop(ifa->wait_timer);
275

    
276
  ospf_flush2_lsa(p, &ifa->link_lsa);
277
  ospf_flush2_lsa(p, &ifa->net_lsa);
278
  ospf_flush2_lsa(p, &ifa->pxn_lsa);
279

    
280
  if (ifa->type == OSPF_IT_VLINK)
281
  {
282
    ifa->vifa = NULL;
283
    ifa->addr = NULL;
284
    ifa->cost = 0;
285
    ifa->vip = IPA_NONE;
286
  }
287

    
288
  ifa->rt_pos_beg = 0;
289
  ifa->rt_pos_end = 0;
290
  ifa->px_pos_beg = 0;
291
  ifa->px_pos_end = 0;
292
}
293

    
294

    
295
void
296
ospf_iface_remove(struct ospf_iface *ifa)
297
{
298
  struct ospf_proto *p = ifa->oa->po;
299
  int i;
300

    
301
  if (ifa->type == OSPF_IT_VLINK)
302
    OSPF_TRACE(D_EVENTS, "Removing vlink to %R via area %R", ifa->vid, ifa->voa->areaid);
303

    
304
  /* Release LSAs from flood queue */
305
  if (!ifa->stub)
306
    for (i = 0; i < ifa->flood_queue_used; i++)
307
      ifa->flood_queue[i]->ret_count--;
308

    
309
  ospf_iface_sm(ifa, ISM_DOWN);
310
  rem_node(NODE ifa);
311
  rfree(ifa->pool);
312
}
313

    
314
void
315
ospf_iface_shutdown(struct ospf_iface *ifa)
316
{
317
  if (ifa->state > OSPF_IS_DOWN)
318
    ospf_send_hello(ifa, OHS_SHUTDOWN, NULL);
319
}
320

    
321
/**
322
 * ospf_iface_chstate - handle changes of interface state
323
 * @ifa: OSPF interface
324
 * @state: new state
325
 *
326
 * Many actions must be taken according to interface state changes. New network
327
 * LSAs must be originated, flushed, new multicast sockets to listen for messages for
328
 * %ALLDROUTERS have to be opened, etc.
329
 */
330
void
331
ospf_iface_chstate(struct ospf_iface *ifa, u8 state)
332
{
333
  struct ospf_proto *p = ifa->oa->po;
334
  u8 oldstate = ifa->state;
335

    
336
  if (state == oldstate)
337
    return;
338

    
339
  OSPF_TRACE(D_EVENTS, "Interface %s changed state from %s to %s",
340
             ifa->ifname, ospf_is_names[oldstate], ospf_is_names[state]);
341

    
342
  ifa->state = state;
343

    
344
  if ((ifa->type == OSPF_IT_BCAST) && ipa_nonzero(ifa->des_routers) && ifa->sk)
345
  {
346
    if ((state == OSPF_IS_BACKUP) || (state == OSPF_IS_DR))
347
      ospf_sk_join_dr(ifa);
348
    else
349
      ospf_sk_leave_dr(ifa);
350
  }
351

    
352
  if ((oldstate > OSPF_IS_LOOP) && (state <= OSPF_IS_LOOP))
353
    ospf_iface_down(ifa);
354

    
355
  /* RFC 2328 12.4 Event 2 - iface state change */
356
  ospf_notify_rt_lsa(ifa->oa);
357

    
358
  /* RFC 5340 4.4.3 Event 1 - iface state change */
359
  ospf_notify_link_lsa(ifa);
360

    
361
  /* RFC 2328 12.4 Event 3 - iface enters/leaves DR state */
362
  ospf_notify_net_lsa(ifa);
363
}
364

    
365
/**
366
 * ospf_iface_sm - OSPF interface state machine
367
 * @ifa: OSPF interface
368
 * @event: event comming to state machine
369
 *
370
 * This fully respects 9.3 of RFC 2328 except we have slightly
371
 * different handling of %DOWN and %LOOP state. We remove intefaces
372
 * that are %DOWN. %DOWN state is used when an interface is waiting
373
 * for a lock. %LOOP state is used when an interface does not have a
374
 * link.
375
 */
376
void
377
ospf_iface_sm(struct ospf_iface *ifa, int event)
378
{
379
  DBG("SM on %s. Event is '%s'\n", ifa->ifname, ospf_ism_names[event]);
380

    
381
  switch (event)
382
  {
383
  case ISM_UP:
384
    if (ifa->state <= OSPF_IS_LOOP)
385
    {
386
      /* Now, nothing should be adjacent */
387
      if ((ifa->type == OSPF_IT_PTP) ||
388
          (ifa->type == OSPF_IT_PTMP) ||
389
          (ifa->type == OSPF_IT_VLINK))
390
      {
391
        ospf_iface_chstate(ifa, OSPF_IS_PTP);
392
      }
393
      else
394
      {
395
        if (ifa->priority == 0)
396
          ospf_iface_chstate(ifa, OSPF_IS_DROTHER);
397
        else
398
        {
399
          ospf_iface_chstate(ifa, OSPF_IS_WAITING);
400
          if (ifa->wait_timer)
401
            tm_start(ifa->wait_timer, ifa->waitint S);
402
        }
403
      }
404

    
405
      if (ifa->hello_timer)
406
        tm_start(ifa->hello_timer, ifa->helloint S);
407

    
408
      if (ifa->poll_timer)
409
        tm_start(ifa->poll_timer, ifa->pollint S);
410

    
411
      ospf_send_hello(ifa, OHS_HELLO, NULL);
412
    }
413
    break;
414

    
415
  case ISM_BACKS:
416
  case ISM_WAITF:
417
    if (ifa->state == OSPF_IS_WAITING)
418
      ospf_dr_election(ifa);
419
    break;
420

    
421
  case ISM_NEICH:
422
    if (ifa->state >= OSPF_IS_DROTHER)
423
      ospf_dr_election(ifa);
424
    break;
425

    
426
  case ISM_LOOP:
427
    if ((ifa->state > OSPF_IS_LOOP) && ifa->check_link)
428
      ospf_iface_chstate(ifa, OSPF_IS_LOOP);
429
    break;
430

    
431
  case ISM_UNLOOP:
432
    /* Immediate go UP */
433
    if (ifa->state == OSPF_IS_LOOP)
434
      ospf_iface_sm(ifa, ISM_UP);
435
    break;
436

    
437
  case ISM_DOWN:
438
    ospf_iface_chstate(ifa, OSPF_IS_DOWN);
439
    break;
440

    
441
  default:
442
    bug("OSPF_I_SM - Unknown event?");
443
    break;
444
  }
445

    
446
}
447

    
448
static u8
449
ospf_iface_classify_(struct iface *ifa, struct ifa *addr)
450
{
451
  if (ipa_nonzero(addr->opposite))
452
    return (ifa->flags & IF_MULTICAST) ? OSPF_IT_PTP :  OSPF_IT_PTMP;
453

    
454
  if ((ifa->flags & (IF_MULTIACCESS | IF_MULTICAST)) ==
455
      (IF_MULTIACCESS | IF_MULTICAST))
456
    return OSPF_IT_BCAST;
457

    
458
  if ((ifa->flags & (IF_MULTIACCESS | IF_MULTICAST)) == IF_MULTIACCESS)
459
    return OSPF_IT_NBMA;
460

    
461
  return OSPF_IT_PTP;
462
}
463

    
464
static inline u8
465
ospf_iface_classify(u8 type, struct ifa *addr)
466
{
467
  return (type != OSPF_IT_UNDEF) ? type : ospf_iface_classify_(addr->iface, addr);
468
}
469

    
470

    
471
struct ospf_iface *
472
ospf_iface_find(struct ospf_proto *p, struct iface *what)
473
{
474
  struct ospf_iface *ifa;
475

    
476
  WALK_LIST(ifa, p->iface_list)
477
    if ((ifa->iface == what) && (ifa->type != OSPF_IT_VLINK))
478
      return ifa;
479

    
480
  return NULL;
481
}
482

    
483
static void
484
ospf_iface_add(struct object_lock *lock)
485
{
486
  struct ospf_iface *ifa = lock->data;
487
  struct ospf_proto *p = ifa->oa->po;
488

    
489
  /* Open socket if interface is not stub */
490
  if (! ifa->stub && ! ospf_sk_open(ifa))
491
  {
492
    log(L_ERR "%s: Cannot open socket for %s, declaring as stub", p->p.name, ifa->ifname);
493
    ifa->ioprob = OSPF_I_SK;
494
    ifa->stub = 1;
495
  }
496

    
497
  if (! ifa->stub)
498
  {
499
    ifa->hello_timer = tm_new_init(ifa->pool, hello_timer_hook, ifa, ifa->helloint S, 0);
500

    
501
    if (ifa->type == OSPF_IT_NBMA)
502
      ifa->poll_timer = tm_new_init(ifa->pool, poll_timer_hook, ifa, ifa->pollint S, 0);
503

    
504
    if ((ifa->type == OSPF_IT_BCAST) || (ifa->type == OSPF_IT_NBMA))
505
      ifa->wait_timer = tm_new_init(ifa->pool, wait_timer_hook, ifa, 0, 0);
506

    
507
    ifa->flood_queue_size = ifa_flood_queue_size(ifa);
508
    ifa->flood_queue = mb_allocz(ifa->pool, ifa->flood_queue_size * sizeof(void *));
509
  }
510

    
511
  /* Do iface UP, unless there is no link (then wait in LOOP state) */
512
  if (!ifa->check_link || (ifa->iface->flags & IF_LINK_UP))
513
    ospf_iface_sm(ifa, ISM_UP);
514
  else
515
    ospf_iface_chstate(ifa, OSPF_IS_LOOP);
516
}
517

    
518
static inline void
519
add_nbma_node(struct ospf_iface *ifa, struct nbma_node *src, int found)
520
{
521
  struct nbma_node *n = mb_alloc(ifa->pool, sizeof(struct nbma_node));
522
  add_tail(&ifa->nbma_list, NODE n);
523
  n->ip = src->ip;
524
  n->eligible = src->eligible;
525
  n->found = found;
526
}
527

    
528
static int
529
ospf_iface_stubby(struct ospf_iface_patt *ip, struct ifa *addr)
530
{
531
  /* a host address */
532
  if (addr->flags & IA_HOST)
533
    return 1;
534

    
535
  /* a loopback iface */
536
  if (addr->iface->flags & IF_LOOPBACK)
537
    return 1;
538

    
539
  return ip->stub;
540
}
541

    
542
void
543
ospf_iface_new(struct ospf_area *oa, struct ifa *addr, struct ospf_iface_patt *ip)
544
{
545
  struct ospf_proto *p = oa->po;
546
  struct iface *iface = addr->iface;
547
  struct ospf_iface *ifa;
548
  struct pool *pool;
549

    
550
  if (ospf_is_v3(p))
551
    OSPF_TRACE(D_EVENTS, "Adding interface %s (IID %d) to area %R",
552
               iface->name, ip->instance_id, oa->areaid);
553
  else if (addr->flags & IA_PEER)
554
    OSPF_TRACE(D_EVENTS, "Adding interface %s (peer %I) to area %R",
555
               iface->name, addr->opposite, oa->areaid);
556
  else
557
    OSPF_TRACE(D_EVENTS, "Adding interface %s (%N) to area %R",
558
               iface->name, &addr->prefix, oa->areaid);
559

    
560
  pool = rp_new(p->p.pool, "OSPF Interface");
561
  ifa = mb_allocz(pool, sizeof(struct ospf_iface));
562
  ifa->iface = iface;
563
  ifa->addr = addr;
564
  ifa->oa = oa;
565
  ifa->cf = ip;
566
  ifa->pool = pool;
567

    
568
  ifa->iface_id = iface->index;
569
  ifa->ifname = iface->name;
570

    
571
  ifa->cost = ip->cost;
572
  ifa->rxmtint = ip->rxmtint;
573
  ifa->inftransdelay = ip->inftransdelay;
574
  ifa->priority = ip->priority;
575
  ifa->helloint = ip->helloint;
576
  ifa->pollint = ip->pollint;
577
  ifa->strictnbma = ip->strictnbma;
578
  ifa->waitint = ip->waitint;
579
  ifa->deadint = ip->deadint;
580
  ifa->stub = ospf_iface_stubby(ip, addr);
581
  ifa->ioprob = OSPF_I_OK;
582
  ifa->tx_length = ifa_tx_length(ifa);
583
  ifa->tx_hdrlen = ifa_tx_hdrlen(ifa);
584
  ifa->check_link = ip->check_link;
585
  ifa->ecmp_weight = ip->ecmp_weight;
586
  ifa->check_ttl = (ip->ttl_security == 1);
587
  ifa->bfd = ip->bfd;
588
  ifa->autype = ip->autype;
589
  ifa->passwords = ip->passwords;
590
  ifa->instance_id = ip->instance_id;
591

    
592
  ifa->ptp_netmask = !(addr->flags & IA_PEER);
593
  if (ip->ptp_netmask < 2)
594
    ifa->ptp_netmask = ip->ptp_netmask;
595

    
596
  ifa->drip = ifa->bdrip = ospf_is_v2(p) ? IPA_NONE4 : IPA_NONE6;
597

    
598
  ifa->type = ospf_iface_classify(ip->type, addr);
599

    
600
  /* Check validity of interface type */
601
  int old_type = ifa->type;
602
  u32 if_multi_flag = ip->real_bcast ? IF_BROADCAST : IF_MULTICAST;
603

    
604
  if (ospf_is_v2(p) && (ifa->type == OSPF_IT_BCAST) && (addr->flags & IA_PEER))
605
    ifa->type = OSPF_IT_PTP;
606

    
607
  if (ospf_is_v2(p) && (ifa->type == OSPF_IT_NBMA) && (addr->flags & IA_PEER))
608
    ifa->type = OSPF_IT_PTMP;
609

    
610
  if ((ifa->type == OSPF_IT_BCAST) && !(iface->flags & if_multi_flag) && !ifa->stub)
611
    ifa->type = OSPF_IT_NBMA;
612

    
613
  if ((ifa->type == OSPF_IT_PTP) && !(iface->flags & if_multi_flag) && !ifa->stub)
614
    ifa->type = OSPF_IT_PTMP;
615

    
616
  if (ifa->type != old_type)
617
    log(L_WARN "%s: Cannot use interface %s as %s, forcing %s",
618
        p->p.name, iface->name, ospf_it[old_type], ospf_it[ifa->type]);
619

    
620

    
621
  if ((ifa->type == OSPF_IT_PTP) || (ifa->type == OSPF_IT_PTMP))
622
    ifa->link_lsa_suppression = ip->link_lsa_suppression;
623

    
624
  ifa->state = OSPF_IS_DOWN;
625
  init_list(&ifa->neigh_list);
626
  init_list(&ifa->nbma_list);
627

    
628
  struct nbma_node *nb;
629
  WALK_LIST(nb, ip->nbma_list)
630
  {
631
    /* In OSPFv3, addr is link-local while configured neighbors could
632
       have global IP (although RFC 5340 C.5 says link-local addresses
633
       should be used). Because OSPFv3 iface is not subnet-specific,
634
       there is no need for ipa_in_net() check */
635

    
636
    if (ospf_is_v2(p) && !ipa_in_netX(nb->ip, &addr->prefix))
637
      continue;
638

    
639
    if (ospf_is_v3(p) && !ipa_is_link_local(nb->ip))
640
      log(L_WARN "%s: Configured neighbor address (%I) should be link-local",
641
          p->p.name, nb->ip);
642

    
643
    add_nbma_node(ifa, nb, 0);
644
  }
645

    
646
  add_tail(&oa->po->iface_list, NODE ifa);
647

    
648
  struct object_lock *lock = olock_new(pool);
649
  lock->addr = ospf_is_v2(p) ? ipa_from_ip4(net4_prefix(&ifa->addr->prefix)) : IPA_NONE;
650
  lock->type = OBJLOCK_IP;
651
  lock->port = OSPF_PROTO;
652
  lock->inst = ifa->instance_id;
653
  lock->iface = iface;
654
  lock->data = ifa;
655
  lock->hook = ospf_iface_add;
656

    
657
  olock_acquire(lock);
658
}
659

    
660
void
661
ospf_iface_new_vlink(struct ospf_proto *p, struct ospf_iface_patt *ip)
662
{
663
  struct ospf_iface *ifa;
664
  struct pool *pool;
665

    
666
  if (!p->vlink_sk)
667
    return;
668

    
669
  OSPF_TRACE(D_EVENTS, "Adding vlink to %R via area %R", ip->vid, ip->voa);
670

    
671
  /* Vlink ifname is stored just after the ospf_iface structure */
672

    
673
  pool = rp_new(p->p.pool, "OSPF Vlink");
674
  ifa = mb_allocz(pool, sizeof(struct ospf_iface) + 16);
675
  ifa->oa = p->backbone;
676
  ifa->cf = ip;
677
  ifa->pool = pool;
678

    
679
  /* Assign iface ID, for vlinks, this is ugly hack */
680
  u32 vlink_id = p->last_vlink_id++;
681
  ifa->iface_id = vlink_id + OSPF_VLINK_ID_OFFSET;
682
  ifa->ifname = (void *) (ifa + 1);
683
  bsprintf(ifa->ifname, "vlink%d", vlink_id);
684

    
685
  ifa->voa = ospf_find_area(p, ip->voa);
686
  ifa->vid = ip->vid;
687
  ifa->sk = p->vlink_sk;
688

    
689
  ifa->helloint = ip->helloint;
690
  ifa->rxmtint = ip->rxmtint;
691
  ifa->waitint = ip->waitint;
692
  ifa->deadint = ip->deadint;
693
  ifa->inftransdelay = ip->inftransdelay;
694
  ifa->tx_length = ospf_is_v2(p) ? IP4_MIN_MTU : IP6_MIN_MTU;
695
  ifa->tx_hdrlen = ifa_tx_hdrlen(ifa);
696
  ifa->autype = ip->autype;
697
  ifa->passwords = ip->passwords;
698
  ifa->instance_id = ip->instance_id;
699

    
700
  ifa->type = OSPF_IT_VLINK;
701

    
702
  ifa->state = OSPF_IS_DOWN;
703
  init_list(&ifa->neigh_list);
704
  init_list(&ifa->nbma_list);
705

    
706
  add_tail(&p->iface_list, NODE ifa);
707

    
708
  ifa->hello_timer = tm_new_init(ifa->pool, hello_timer_hook, ifa, ifa->helloint S, 0);
709

    
710
  ifa->flood_queue_size = ifa_flood_queue_size(ifa);
711
  ifa->flood_queue = mb_allocz(ifa->pool, ifa->flood_queue_size * sizeof(void *));
712
}
713

    
714
static void
715
ospf_iface_change_timer(timer *tm, uint val)
716
{
717
  if (!tm)
718
    return;
719

    
720
  tm->recurrent = val S;
721

    
722
  if (tm_active(tm))
723
    tm_start(tm, val S);
724
}
725

    
726
static inline void
727
ospf_iface_update_flood_queue_size(struct ospf_iface *ifa)
728
{
729
  uint old_size = ifa->flood_queue_size;
730
  uint new_size = ifa_flood_queue_size(ifa);
731

    
732
  if (new_size <= old_size)
733
    return;
734

    
735
  ifa->flood_queue_size = new_size;
736
  ifa->flood_queue = mb_realloc(ifa->flood_queue, new_size * sizeof(void *));
737
  bzero(ifa->flood_queue + old_size, (new_size - old_size) * sizeof(void *));
738
}
739

    
740
int
741
ospf_iface_reconfigure(struct ospf_iface *ifa, struct ospf_iface_patt *new)
742
{
743
  struct ospf_proto *p = ifa->oa->po;
744
  struct ospf_iface_patt *old = ifa->cf;
745
  char *ifname = ifa->ifname;
746

    
747
  /* Type could be changed in ospf_iface_new(),
748
     but if config values are same then also results are same */
749
  int old_type = ospf_iface_classify(old->type, ifa->addr);
750
  int new_type = ospf_iface_classify(new->type, ifa->addr);
751
  if (old_type != new_type)
752
    return 0;
753

    
754
  int new_stub = ospf_iface_stubby(new, ifa->addr);
755
  if (ifa->stub != new_stub)
756
    return 0;
757

    
758
  /* Change of these options would require to reset the iface socket */
759
  if ((new->real_bcast != old->real_bcast) ||
760
      (new->tx_tos != old->tx_tos) ||
761
      (new->tx_priority != old->tx_priority) ||
762
      (new->ttl_security != old->ttl_security))
763
    return 0;
764

    
765
  ifa->cf = new;
766
  ifa->marked = 0;
767

    
768

    
769
  /* HELLO TIMER */
770
  if (ifa->helloint != new->helloint)
771
  {
772
    OSPF_TRACE(D_EVENTS, "Changing hello interval of %s from %d to %d",
773
               ifname, ifa->helloint, new->helloint);
774

    
775
    ifa->helloint = new->helloint;
776
    ospf_iface_change_timer(ifa->hello_timer, ifa->helloint);
777
  }
778

    
779
  /* RXMT TIMER */
780
  if (ifa->rxmtint != new->rxmtint)
781
  {
782
    OSPF_TRACE(D_EVENTS, "Changing retransmit interval of %s from %d to %d",
783
               ifname, ifa->rxmtint, new->rxmtint);
784

    
785
    ifa->rxmtint = new->rxmtint;
786
    /* FIXME: Update neighbors' timers */
787
  }
788

    
789
  /* POLL TIMER */
790
  if (ifa->pollint != new->pollint)
791
  {
792
    OSPF_TRACE(D_EVENTS, "Changing poll interval of %s from %d to %d",
793
               ifname, ifa->pollint, new->pollint);
794

    
795
    ifa->pollint = new->pollint;
796
    ospf_iface_change_timer(ifa->poll_timer, ifa->pollint);
797
  }
798

    
799
  /* WAIT TIMER */
800
  if (ifa->waitint != new->waitint)
801
  {
802
    OSPF_TRACE(D_EVENTS, "Changing wait interval of %s from %d to %d",
803
               ifname, ifa->waitint, new->waitint);
804

    
805
    ifa->waitint = new->waitint;
806
    if (ifa->wait_timer && tm_active(ifa->wait_timer))
807
      tm_start(ifa->wait_timer, ifa->waitint S);
808
  }
809

    
810
  /* DEAD TIMER */
811
  if (ifa->deadint != new->deadint)
812
  {
813
    OSPF_TRACE(D_EVENTS, "Changing dead interval of %s from %d to %d",
814
               ifname, ifa->deadint, new->deadint);
815
    ifa->deadint = new->deadint;
816
  }
817

    
818
  /* INFTRANS */
819
  if (ifa->inftransdelay != new->inftransdelay)
820
  {
821
    OSPF_TRACE(D_EVENTS, "Changing transmit delay of %s from %d to %d",
822
                     ifname, ifa->inftransdelay, new->inftransdelay);
823
    ifa->inftransdelay = new->inftransdelay;
824
  }
825

    
826
  /* AUTHENTICATION */
827
  if (ifa->autype != new->autype)
828
  {
829
    OSPF_TRACE(D_EVENTS, "Changing authentication type of %s", ifname);
830
    ifa->autype = new->autype;
831
  }
832

    
833
  /* Update passwords */
834
  ifa->passwords = new->passwords;
835

    
836
  /* Update header length */
837
  ifa->tx_hdrlen = ifa_tx_hdrlen(ifa);
838

    
839
  /* Remaining options are just for proper interfaces */
840
  if (ifa->type == OSPF_IT_VLINK)
841
    return 1;
842

    
843

    
844
  /* COST */
845
  if (ifa->cost != new->cost)
846
  {
847
    OSPF_TRACE(D_EVENTS, "Changing cost of %s from %d to %d",
848
               ifname, ifa->cost, new->cost);
849

    
850
    ifa->cost = new->cost;
851
  }
852

    
853
  /* PRIORITY */
854
  if (ifa->priority != new->priority)
855
  {
856
    OSPF_TRACE(D_EVENTS, "Changing priority of %s from %d to %d",
857
               ifname, ifa->priority, new->priority);
858

    
859
    ifa->priority = new->priority;
860
    ospf_notify_link_lsa(ifa);
861
  }
862

    
863
  /* STRICT NBMA */
864
  if (ifa->strictnbma != new->strictnbma)
865
  {
866
    OSPF_TRACE(D_EVENTS, "Changing NBMA strictness of %s from %d to %d",
867
               ifname, ifa->strictnbma, new->strictnbma);
868
    ifa->strictnbma = new->strictnbma;
869
  }
870

    
871
  struct nbma_node *nb, *nbx;
872

    
873
  /* NBMA LIST - remove or update old */
874
  WALK_LIST_DELSAFE(nb, nbx, ifa->nbma_list)
875
  {
876
    struct nbma_node *nb2 = find_nbma_node_(&new->nbma_list, nb->ip);
877
    if (nb2)
878
    {
879
      if (nb->eligible != nb2->eligible)
880
      {
881
        OSPF_TRACE(D_EVENTS, "Changing eligibility of NBMA neighbor %I on %s",
882
                   nb->ip, ifname);
883
        nb->eligible = nb2->eligible;
884
      }
885
    }
886
    else
887
    {
888
      OSPF_TRACE(D_EVENTS, "Removing NBMA neighbor %I on %s",
889
                       nb->ip, ifname);
890
      rem_node(NODE nb);
891
      mb_free(nb);
892
    }
893
  }
894

    
895
  /* NBMA LIST - add new */
896
  WALK_LIST(nb, new->nbma_list)
897
  {
898
    /* See related note in ospf_iface_new() */
899
    if (ospf_is_v2(p) && !ipa_in_netX(nb->ip, &ifa->addr->prefix))
900
      continue;
901

    
902
    if (ospf_is_v3(p) && !ipa_is_link_local(nb->ip))
903
      log(L_WARN "%s: Configured neighbor address (%I) should be link-local",
904
          p->p.name, nb->ip);
905

    
906
    if (! find_nbma_node(ifa, nb->ip))
907
    {
908
      OSPF_TRACE(D_EVENTS, "Adding NBMA neighbor %I on %s",
909
                 nb->ip, ifname);
910
      add_nbma_node(ifa, nb, !!find_neigh_by_ip(ifa, nb->ip));
911
    }
912
  }
913

    
914
  int update_buffers = 0;
915

    
916
  /* TX LENGTH */
917
  if (old->tx_length != new->tx_length)
918
  {
919
    OSPF_TRACE(D_EVENTS, "Changing TX length of %s from %d to %d",
920
               ifname, old->tx_length, new->tx_length);
921

    
922
    /* ifa cannot be vlink */
923
    ifa->tx_length = ifa_tx_length(ifa);
924
    update_buffers = 1;
925

    
926
    if (!ifa->stub)
927
      ospf_iface_update_flood_queue_size(ifa);
928
  }
929

    
930
  /* RX BUFFER */
931
  if (old->rx_buffer != new->rx_buffer)
932
  {
933
    OSPF_TRACE(D_EVENTS, "Changing buffer size of %s from %d to %d",
934
               ifname, old->rx_buffer, new->rx_buffer);
935

    
936
    /* ifa cannot be vlink */
937
    update_buffers = 1;
938
  }
939

    
940
  /* Buffer size depends on both tx_length and rx_buffer options */
941
  if (update_buffers && ifa->sk)
942
  {
943
    uint bsize = ifa_bufsize(ifa);
944
    sk_set_rbsize(ifa->sk, bsize);
945
    sk_set_tbsize(ifa->sk, bsize);
946
  }
947

    
948
  /* LINK */
949
  if (ifa->check_link != new->check_link)
950
  {
951
    OSPF_TRACE(D_EVENTS, "%s link check for %s",
952
               new->check_link ? "Enabling" : "Disabling", ifname);
953
    ifa->check_link = new->check_link;
954

    
955
    /* ifa cannot be vlink */
956
    if (!(ifa->iface->flags & IF_LINK_UP))
957
      ospf_iface_sm(ifa, ifa->check_link ? ISM_LOOP : ISM_UNLOOP);
958
  }
959

    
960
  /* ECMP weight */
961
  if (ifa->ecmp_weight != new->ecmp_weight)
962
  {
963
    OSPF_TRACE(D_EVENTS, "Changing ECMP weight of %s from %d to %d",
964
               ifname, (int)ifa->ecmp_weight + 1, (int)new->ecmp_weight + 1);
965
    ifa->ecmp_weight = new->ecmp_weight;
966
  }
967

    
968
  /* Link LSA suppression */
969
  if (((ifa->type == OSPF_IT_PTP) || (ifa->type == OSPF_IT_PTMP)) &&
970
      (ifa->link_lsa_suppression != new->link_lsa_suppression))
971
  {
972
    OSPF_TRACE(D_EVENTS, "Changing link LSA suppression of %s from %d to %d",
973
               ifname, ifa->link_lsa_suppression, new->link_lsa_suppression);
974

    
975
    ifa->link_lsa_suppression = new->link_lsa_suppression;
976
    ospf_notify_link_lsa(ifa);
977
  }
978

    
979
  /* BFD */
980
  if (ifa->bfd != new->bfd)
981
  {
982
    OSPF_TRACE(D_EVENTS, "%s BFD for %s",
983
               new->bfd ? "Enabling" : "Disabling", ifname);
984
    ifa->bfd = new->bfd;
985

    
986
    struct ospf_neighbor *n;
987
    WALK_LIST(n, ifa->neigh_list)
988
      ospf_neigh_update_bfd(n, ifa->bfd);
989
  }
990

    
991

    
992
  /* instance_id is not updated - it is part of key */
993

    
994
  return 1;
995
}
996

    
997

    
998
/*
999
 * State for matching iface pattterns walk
1000
 *
1001
 * This is significantly different in OSPFv2 and OSPFv3.
1002
 * In OSPFv2, OSPF ifaces are created for each IP prefix (struct ifa)
1003
 * In OSPFv3, OSPF ifaces are created based on real iface (struct iface)
1004
 * We support instance_id for both OSPFv2 (RFC 6549) and OSPFv3.
1005
 *
1006
 * We process one ifa/iface and match it for all configured instance IDs. We
1007
 * maintain bitfields to track whether given instance ID was already matched.
1008
 * We have two bitfields, one global (active) and one per area (ignore), to
1009
 * detect misconfigured cases where one iface with one instance ID matches in
1010
 * multiple areas.
1011
 */
1012

    
1013
struct ospf_mip_walk {
1014
  u32 active[8];                /* Bitfield of active instance IDs */
1015
  u32 ignore[8];                /* Bitfield of instance IDs matched in current area */
1016
  struct ospf_area *oa;                /* Current area */
1017
  struct ospf_iface_patt *ip;        /* Current iface pattern */
1018
  struct iface *iface;                /* Specified iface (input) */
1019
  struct ifa *a;                /* Specified ifa (input) */
1020
  int warn;                        /* Whether iface matched in multiple areas */
1021
};
1022

    
1023
static int
1024
ospf_walk_matching_iface_patts(struct ospf_proto *p, struct ospf_mip_walk *s)
1025
{
1026
  int id;
1027

    
1028
  if (s->ip)
1029
    goto step;
1030

    
1031
  WALK_LIST(s->oa, p->area_list)
1032
  {
1033
    if (s->oa->marked)
1034
      continue;
1035

    
1036
    WALK_LIST(s->ip, s->oa->ac->patt_list)
1037
    {
1038
      id = s->ip->instance_id;
1039
      if (BIT32_TEST(s->ignore, id))
1040
        continue;
1041

    
1042
      if (iface_patt_match(&s->ip->i, s->iface, s->a))
1043
      {
1044
        /* Now we matched ifa/iface/instance_id for the first time in current area */
1045
        BIT32_SET(s->ignore, id);
1046

    
1047
        /* If we already found it in previous areas, ignore it and add warning */
1048
        if (BIT32_TEST(s->active, id))
1049
          { s->warn = 1; continue; }
1050

    
1051
        BIT32_SET(s->active, id);
1052
        return 1;
1053
      step:
1054
        ;
1055
      }
1056
    }
1057
    BIT32_ZERO(s->ignore, 256);
1058
  }
1059

    
1060
  if (s->warn)
1061
    log(L_WARN "%s: Interface %s matches for multiple areas", p->p.name, s->iface->name);
1062

    
1063
  return 0;
1064
}
1065

    
1066

    
1067
static struct ospf_iface *
1068
ospf_iface_find_by_key(struct ospf_proto *p, struct ifa *a, int instance_id)
1069
{
1070
  struct ospf_iface *ifa;
1071

    
1072
  WALK_LIST(ifa, p->iface_list)
1073
    if ((ifa->addr == a) && (ifa->instance_id == instance_id) &&
1074
        (ifa->type != OSPF_IT_VLINK))
1075
      return ifa;
1076

    
1077
  return NULL;
1078
}
1079

    
1080

    
1081
void
1082
ospf_ifa_notify2(struct proto *P, uint flags, struct ifa *a)
1083
{
1084
  struct ospf_proto *p = (struct ospf_proto *) P;
1085

    
1086
  if (a->prefix.type != NET_IP4)
1087
    return;
1088

    
1089
  if (a->flags & IA_SECONDARY)
1090
    return;
1091

    
1092
  if (a->scope <= SCOPE_LINK)
1093
    return;
1094

    
1095
  /* In OSPFv2, we create OSPF iface for each address. */
1096
  if (flags & IF_CHANGE_UP)
1097
  {
1098
    struct ospf_mip_walk s = { .iface = a->iface, .a = a };
1099
    while (ospf_walk_matching_iface_patts(p, &s))
1100
      ospf_iface_new(s.oa, a, s.ip);
1101
  }
1102

    
1103
  if (flags & IF_CHANGE_DOWN)
1104
  {
1105
    struct ospf_iface *ifa, *ifx;
1106
    WALK_LIST_DELSAFE(ifa, ifx, p->iface_list)
1107
      if ((ifa->type != OSPF_IT_VLINK) && (ifa->addr == a))
1108
        ospf_iface_remove(ifa);
1109
    /* See a note in ospf_iface_notify() */
1110
  }
1111
}
1112

    
1113
void
1114
ospf_ifa_notify3(struct proto *P, uint flags, struct ifa *a)
1115
{
1116
  struct ospf_proto *p = (struct ospf_proto *) P;
1117

    
1118
  if (a->flags & IA_SECONDARY)
1119
    return;
1120

    
1121
  if (a->scope < SCOPE_LINK)
1122
    return;
1123

    
1124
  /* In OSPFv3, we create OSPF iface for link-local address,
1125
     other addresses are used for link-LSA. */
1126
  if (a->scope == SCOPE_LINK)
1127
  {
1128
    if (a->prefix.type != NET_IP6)
1129
      return;
1130

    
1131
    if (flags & IF_CHANGE_UP)
1132
    {
1133
      struct ospf_mip_walk s = { .iface = a->iface };
1134
      while (ospf_walk_matching_iface_patts(p, &s))
1135
        ospf_iface_new(s.oa, a, s.ip);
1136
    }
1137

    
1138
    if (flags & IF_CHANGE_DOWN)
1139
    {
1140
      struct ospf_iface *ifa, *ifx;
1141
      WALK_LIST_DELSAFE(ifa, ifx, p->iface_list)
1142
        if ((ifa->addr == a) && (ifa->type != OSPF_IT_VLINK))
1143
          ospf_iface_remove(ifa);
1144
    }
1145
  }
1146
  else
1147
  {
1148
    if (a->prefix.type != ospf_get_af(p))
1149
      return;
1150

    
1151
    struct ospf_iface *ifa;
1152
    WALK_LIST(ifa, p->iface_list)
1153
      if (ifa->iface == a->iface)
1154
      {
1155
        /* RFC 5340 4.4.3 Event 5 - prefix added/deleted */
1156
        ospf_notify_link_lsa(ifa);
1157
        ospf_notify_rt_lsa(ifa->oa);
1158
      }
1159
  }
1160
}
1161

    
1162

    
1163
static void
1164
ospf_reconfigure_ifaces2(struct ospf_proto *p)
1165
{
1166
  struct iface *iface;
1167
  struct ifa *a;
1168

    
1169
  WALK_LIST(iface, iface_list)
1170
  {
1171
    if (! (iface->flags & IF_UP))
1172
      continue;
1173

    
1174
    WALK_LIST(a, iface->addrs)
1175
    {
1176
      if (a->prefix.type != NET_IP4)
1177
        continue;
1178

    
1179
      if (a->flags & IA_SECONDARY)
1180
        continue;
1181

    
1182
      if (a->scope <= SCOPE_LINK)
1183
        continue;
1184

    
1185
      struct ospf_mip_walk s = { .iface = iface, .a = a };
1186
      while (ospf_walk_matching_iface_patts(p, &s))
1187
      {
1188
        /* Main inner loop */
1189
        struct ospf_iface *ifa = ospf_iface_find_by_key(p, a, s.ip->instance_id);
1190
        if (ifa)
1191
        {
1192
          if ((ifa->oa == s.oa) && (ifa->marked < 2) &&
1193
              ospf_iface_reconfigure(ifa, s.ip))
1194
            continue;
1195

    
1196
          /* Hard restart */
1197
          log(L_INFO "%s: Restarting interface %s (%N) in area %R",
1198
              p->p.name, ifa->ifname, &a->prefix, s.oa->areaid);
1199
          ospf_iface_shutdown(ifa);
1200
          ospf_iface_remove(ifa);
1201
        }
1202

    
1203
        ospf_iface_new(s.oa, a, s.ip);
1204
      }
1205
    }
1206
  }
1207
}
1208

    
1209
static void
1210
ospf_reconfigure_ifaces3(struct ospf_proto *p)
1211
{
1212
  struct iface *iface;
1213
  struct ifa *a;
1214

    
1215
  WALK_LIST(iface, iface_list)
1216
  {
1217
    if (! (iface->flags & IF_UP))
1218
      continue;
1219

    
1220
    WALK_LIST(a, iface->addrs)
1221
    {
1222
      if (a->prefix.type != NET_IP6)
1223
        continue;
1224

    
1225
      if (a->flags & IA_SECONDARY)
1226
        continue;
1227

    
1228
      if (a->scope != SCOPE_LINK)
1229
        continue;
1230

    
1231
      struct ospf_mip_walk s = { .iface = iface };
1232
      while (ospf_walk_matching_iface_patts(p, &s))
1233
      {
1234
        /* Main inner loop */
1235
        struct ospf_iface *ifa = ospf_iface_find_by_key(p, a, s.ip->instance_id);
1236
        if (ifa)
1237
        {
1238
          if ((ifa->oa == s.oa) && (ifa->marked < 2) &&
1239
              ospf_iface_reconfigure(ifa, s.ip))
1240
            continue;
1241

    
1242
          /* Hard restart */
1243
          log(L_INFO "%s: Restarting interface %s (IID %d) in area %R",
1244
              p->p.name, ifa->ifname, ifa->instance_id, s.oa->areaid);
1245
          ospf_iface_shutdown(ifa);
1246
          ospf_iface_remove(ifa);
1247
        }
1248

    
1249
        ospf_iface_new(s.oa, a, s.ip);
1250
      }
1251
    }
1252
  }
1253
}
1254

    
1255
void
1256
ospf_reconfigure_ifaces(struct ospf_proto *p)
1257
{
1258
  if (ospf_is_v2(p))
1259
    ospf_reconfigure_ifaces2(p);
1260
  else
1261
    ospf_reconfigure_ifaces3(p);
1262
}
1263

    
1264

    
1265
static void
1266
ospf_iface_change_mtu(struct ospf_proto *p, struct ospf_iface *ifa)
1267
{
1268
  /* ifa is not vlink */
1269

    
1270
  OSPF_TRACE(D_EVENTS, "Interface %s changed MTU to %d", ifa->iface->mtu);
1271

    
1272
  ifa->tx_length = ifa_tx_length(ifa);
1273

    
1274
  if (!ifa->sk)
1275
    return;
1276

    
1277
  /* We do not shrink dynamic buffers */
1278
  uint bsize = ifa_bufsize(ifa);
1279
  if (bsize > ifa->sk->rbsize)
1280
    sk_set_rbsize(ifa->sk, bsize);
1281
  if (bsize > ifa->sk->tbsize)
1282
    sk_set_tbsize(ifa->sk, bsize);
1283

    
1284
  if (!ifa->stub)
1285
    ospf_iface_update_flood_queue_size(ifa);
1286
}
1287

    
1288
static void
1289
ospf_iface_notify(struct ospf_proto *p, uint flags, struct ospf_iface *ifa)
1290
{
1291
  /* ifa is not vlink */
1292

    
1293
  if (flags & IF_CHANGE_DOWN)
1294
  {
1295
    ospf_iface_remove(ifa);
1296
    return;
1297
  }
1298

    
1299
  if (flags & IF_CHANGE_LINK)
1300
    ospf_iface_sm(ifa, (ifa->iface->flags & IF_LINK_UP) ? ISM_UNLOOP : ISM_LOOP);
1301

    
1302
  if (flags & IF_CHANGE_MTU)
1303
    ospf_iface_change_mtu(p, ifa);
1304
}
1305

    
1306
void
1307
ospf_if_notify(struct proto *P, uint flags, struct iface *iface)
1308
{
1309
  struct ospf_proto *p = (struct ospf_proto *) P;
1310

    
1311
  /*
1312
  if (iface->flags & IF_IGNORE)
1313
    return;
1314
  */
1315

    
1316
  /* Going up means that there are no such ifaces yet */
1317
  if (flags & IF_CHANGE_UP)
1318
    return;
1319

    
1320
  struct ospf_iface *ifa, *ifx;
1321
  WALK_LIST_DELSAFE(ifa, ifx, p->iface_list)
1322
    if (ifa->iface == iface)
1323
      ospf_iface_notify(p, flags, ifa);
1324

    
1325
  /* We use here that even shutting down iface also shuts down
1326
     the vlinks, but vlinks are not freed and stays in the
1327
     iface_list even when down */
1328
}
1329

    
1330
void
1331
ospf_iface_info(struct ospf_iface *ifa)
1332
{
1333
  char *more = "";
1334

    
1335
  if (ifa->strictnbma &&
1336
      ((ifa->type == OSPF_IT_NBMA) || (ifa->type == OSPF_IT_PTMP)))
1337
    more = " (strict)";
1338

    
1339
  if (ifa->cf->real_bcast &&
1340
      ((ifa->type == OSPF_IT_BCAST) || (ifa->type == OSPF_IT_PTP)))
1341
    more = " (real)";
1342

    
1343
  if (ifa->type == OSPF_IT_VLINK)
1344
  {
1345
    cli_msg(-1015, "Virtual link %s to %R", ifa->ifname, ifa->vid);
1346
    cli_msg(-1015, "\tPeer IP: %I", ifa->vip);
1347
    cli_msg(-1015, "\tTransit area: %R (%u)", ifa->voa->areaid, ifa->voa->areaid);
1348
  }
1349
  else
1350
  {
1351
    if (ospf_is_v3(ifa->oa->po))
1352
      cli_msg(-1015, "Interface %s (IID %d)", ifa->ifname, ifa->instance_id);
1353
    else if (ifa->addr->flags & IA_PEER)
1354
      cli_msg(-1015, "Interface %s (peer %I)", ifa->ifname, ifa->addr->opposite);
1355
    else
1356
      cli_msg(-1015, "Interface %s (%N)", ifa->ifname, &ifa->addr->prefix);
1357

    
1358
    cli_msg(-1015, "\tType: %s%s", ospf_it[ifa->type], more);
1359
    cli_msg(-1015, "\tArea: %R (%u)", ifa->oa->areaid, ifa->oa->areaid);
1360
  }
1361
  cli_msg(-1015, "\tState: %s%s", ospf_is_names[ifa->state], ifa->stub ? " (stub)" : "");
1362
  cli_msg(-1015, "\tPriority: %u", ifa->priority);
1363
  cli_msg(-1015, "\tCost: %u", ifa->cost);
1364
  if (ifa->oa->po->ecmp)
1365
    cli_msg(-1015, "\tECMP weight: %d", ((int) ifa->ecmp_weight) + 1);
1366
  cli_msg(-1015, "\tHello timer: %u", ifa->helloint);
1367

    
1368
  if (ifa->type == OSPF_IT_NBMA)
1369
  {
1370
    cli_msg(-1015, "\tPoll timer: %u", ifa->pollint);
1371
  }
1372
  cli_msg(-1015, "\tWait timer: %u", ifa->waitint);
1373
  cli_msg(-1015, "\tDead timer: %u", ifa->deadint);
1374
  cli_msg(-1015, "\tRetransmit timer: %u", ifa->rxmtint);
1375
  if ((ifa->type == OSPF_IT_BCAST) || (ifa->type == OSPF_IT_NBMA))
1376
  {
1377
    cli_msg(-1015, "\tDesignated router (ID): %R", ifa->drid);
1378
    cli_msg(-1015, "\tDesignated router (IP): %I", ifa->drip);
1379
    cli_msg(-1015, "\tBackup designated router (ID): %R", ifa->bdrid);
1380
    cli_msg(-1015, "\tBackup designated router (IP): %I", ifa->bdrip);
1381
  }
1382
}