Statistics
| Branch: | Revision:

iof-bird-daemon / proto / ospf / iface.c @ af157fa3

History | View | Annotate | Download (18.6 KB)

1
/*
2
 *        BIRD -- OSPF
3
 *
4
 *        (c) 1999--2005 Ondrej Filip <feela@network.cz>
5
 *
6
 *        Can be freely distributed and used under the terms of the GNU GPL.
7
 */
8

    
9
#include "ospf.h"
10

    
11
char *ospf_is[] = { "down", "loop", "waiting", "point-to-point", "drother",
12
  "backup", "dr"
13
};
14

    
15
char *ospf_ism[] = { "interface up", "wait timer fired", "backup seen",
16
  "neighbor change", "loop indicated", "unloop indicated", "interface down"
17
};
18

    
19
char *ospf_it[] = { "broadcast", "nbma", "point-to-point", "virtual link" };
20

    
21
static void
22
poll_timer_hook(timer * timer)
23
{
24
  ospf_hello_send(timer, 1, NULL);
25
}
26

    
27
static void
28
hello_timer_hook(timer * timer)
29
{
30
  ospf_hello_send(timer, 0, NULL);
31
}
32

    
33
static void
34
wait_timer_hook(timer * timer)
35
{
36
  struct ospf_iface *ifa = (struct ospf_iface *) timer->data;
37
  struct proto *p = &ifa->oa->po->proto;
38

    
39
  OSPF_TRACE(D_EVENTS, "Wait timer fired on interface %s.", ifa->iface->name);
40
  ospf_iface_sm(ifa, ISM_WAITF);
41
}
42

    
43
u32
44
rxbufsize(struct ospf_iface *ifa)
45
{
46
  switch(ifa->rxbuf)
47
  {
48
    case OSPF_RXBUF_NORMAL:
49
      return (ifa->iface->mtu * 2);
50
      break;
51
    case OSPF_RXBUF_LARGE:
52
      return OSPF_MAX_PKT_SIZE;
53
      break;
54
    default:
55
      return ifa->rxbuf;
56
      break;
57
  }
58
}
59

    
60
static int
61
ospf_sk_open(struct ospf_iface *ifa)
62
{
63
  sock *sk;
64
  struct proto *p = &ifa->oa->po->proto;
65

    
66
  sk = sk_new(p->pool);
67
  sk->type = SK_IP;
68
  sk->dport = OSPF_PROTO;
69

    
70
#ifdef OSPFv2
71
  /*
72
   * In Linux IPv4, binding a raw socket to an IP address of an iface causes
73
   * that the socket does not receive multicast packets, as they have
74
   * different (multicast) destination IP address.
75
   */
76
  sk->saddr = IPA_NONE;
77
#else /* OSPFv3 */
78
  sk->saddr = ifa->addr->ip; /* link-local addr */
79
#endif
80

    
81
  sk->tos = IP_PREC_INTERNET_CONTROL;
82
  sk->rx_hook = ospf_rx_hook;
83
  sk->tx_hook = ospf_tx_hook;
84
  sk->err_hook = ospf_err_hook;
85
  sk->iface = ifa->iface;
86
  sk->rbsize = rxbufsize(ifa);
87
  sk->tbsize = ifa->iface->mtu;
88
  sk->data = (void *) ifa;
89
  sk->flags = SKF_LADDR_RX;
90

    
91
  if (sk_open(sk) != 0)
92
    goto err;
93

    
94
#ifdef OSPFv3
95
  /* 12 is an offset of the checksum in an OSPF packet */
96
  if (sk_set_ipv6_checksum(sk, 12) < 0)
97
    goto err;
98
#endif
99

    
100
  sk->saddr = ifa->addr->ip;
101
  if (sk_setup_multicast(sk) < 0)
102
    goto err;
103

    
104
  ifa->sk = sk;
105
  ifa->sk_spf = 0;
106
  ifa->sk_dr = 0;
107
  return 1;
108

    
109
 err:
110
  rfree(sk);
111
  return 0;
112
}
113

    
114
static inline void
115
ospf_sk_join_spf(struct ospf_iface *ifa)
116
{
117
  if (ifa->sk_spf)
118
    return;
119

    
120
  sk_join_group(ifa->sk, AllSPFRouters);
121
  ifa->sk_spf = 1;
122
}
123

    
124
static inline void
125
ospf_sk_join_dr(struct ospf_iface *ifa)
126
{
127
  if (ifa->sk_dr)
128
    return;
129

    
130
  sk_join_group(ifa->sk, AllDRouters);
131
  ifa->sk_dr = 1;
132
}
133

    
134
static inline void
135
ospf_sk_leave_spf(struct ospf_iface *ifa)
136
{
137
  if (!ifa->sk_spf)
138
    return;
139

    
140
  sk_leave_group(ifa->sk, AllSPFRouters);
141
  ifa->sk_spf = 0;
142
}
143

    
144
static inline void
145
ospf_sk_leave_dr(struct ospf_iface *ifa)
146
{
147
  if (!ifa->sk_dr)
148
    return;
149

    
150
  sk_leave_group(ifa->sk, AllDRouters);
151
  ifa->sk_dr = 0;
152
}
153

    
154
static inline void
155
ospf_sk_close(struct ospf_iface *ifa)
156
{
157
  ASSERT(ifa->sk);
158

    
159
  rfree(ifa->sk);
160
  ifa->sk = NULL;
161
}
162

    
163

    
164
/**
165
 * ospf_iface_chstate - handle changes of interface state
166
 * @ifa: OSPF interface
167
 * @state: new state
168
 *
169
 * Many actions must be taken according to interface state changes. New network
170
 * LSAs must be originated, flushed, new multicast sockets to listen for messages for
171
 * %ALLDROUTERS have to be opened, etc.
172
 */
173
void
174
ospf_iface_chstate(struct ospf_iface *ifa, u8 state)
175
{
176
  struct proto_ospf *po = ifa->oa->po;
177
  struct proto *p = &po->proto;
178
  u8 oldstate = ifa->state;
179

    
180
  if (oldstate != state)
181
  {
182
    ifa->state = state;
183

    
184
    if (ifa->type == OSPF_IT_VLINK)
185
    {
186
      OSPF_TRACE(D_EVENTS,
187
                 "Changing state of virtual link %R from \"%s\" into \"%s\".",
188
                 ifa->vid, ospf_is[oldstate], ospf_is[state]);
189
    }
190
    else
191
    {
192
      OSPF_TRACE(D_EVENTS,
193
                 "Changing state of iface: %s from \"%s\" into \"%s\".",
194
                 ifa->iface->name, ospf_is[oldstate], ospf_is[state]);
195
      if (ifa->iface->flags & IF_MULTICAST)
196
      {
197
        if ((ifa->type != OSPF_IT_NBMA) && (ifa->ioprob == OSPF_I_OK) &&
198
            ((state == OSPF_IS_BACKUP) || (state == OSPF_IS_DR)))
199
          ospf_sk_join_dr(ifa);
200
        else
201
          ospf_sk_leave_dr(ifa);
202

    
203
        if ((oldstate == OSPF_IS_DR) && (ifa->net_lsa != NULL))
204
        {
205
          ifa->net_lsa->lsa.age = LSA_MAXAGE;
206
          if (state >= OSPF_IS_WAITING)
207
          {
208
            ospf_lsupd_flush_nlsa(po, ifa->net_lsa);
209
          }
210
          if (can_flush_lsa(po))
211
            flush_lsa(ifa->net_lsa, po);
212
          ifa->net_lsa = NULL;
213
        }
214
      }
215
      // FIXME flushling of link LSA
216
    }
217
  }
218
}
219

    
220
static void
221
ospf_iface_down(struct ospf_iface *ifa)
222
{
223
  struct ospf_neighbor *n, *nx;
224
  struct proto_ospf *po = ifa->oa->po;
225
  struct proto *p = &po->proto;
226
  struct ospf_iface *iff;
227

    
228
  OSPF_TRACE(D_EVENTS, "Removing interface %s", ifa->iface->name);
229

    
230
  /* First of all kill all the related vlinks */
231
  if (ifa->type != OSPF_IT_VLINK)
232
  {
233
    WALK_LIST(iff, po->iface_list)
234
    {
235
      if ((iff->type == OSPF_IT_VLINK) && (iff->vifa == ifa))
236
        ospf_iface_sm(iff, ISM_DOWN);
237
    }
238
  }
239

    
240
  WALK_LIST_DELSAFE(n, nx, ifa->neigh_list)
241
  {
242
    OSPF_TRACE(D_EVENTS, "Removing neighbor %I", n->ip);
243
    ospf_neigh_remove(n);
244
  }
245

    
246
  if (ifa->type == OSPF_IT_VLINK)
247
  {
248
    ifa->vifa = NULL;
249
    ifa->iface = NULL;
250
    ifa->addr = NULL;
251
    ifa->sk = NULL;
252
    ifa->vip = IPA_NONE;
253
    return;
254
  }
255
  else
256
  {
257
    ospf_sk_close(ifa);
258
    rfree(ifa->wait_timer);
259
    rfree(ifa->hello_timer);
260
    rfree(ifa->poll_timer);
261
    rfree(ifa->lock);
262
    rem_node(NODE ifa);
263
    mb_free(ifa);
264
  }
265
}
266

    
267
/**
268
 * ospf_iface_sm - OSPF interface state machine
269
 * @ifa: OSPF interface
270
 * @event: event comming to state machine
271
 *
272
 * This fully respects 9.3 of RFC 2328 except we don't use %LOOP state of
273
 * interface.
274
 */
275
void
276
ospf_iface_sm(struct ospf_iface *ifa, int event)
277
{
278
  struct ospf_area *oa = ifa->oa;
279

    
280
  DBG("SM on %s %s. Event is '%s'\n", (ifa->type == OSPF_IT_VLINK) ? "vlink" : "iface",
281
    ifa->iface ? ifa->iface->name : "(none)" , ospf_ism[event]);
282

    
283
  switch (event)
284
  {
285
  case ISM_UP:
286
    if (ifa->state == OSPF_IS_DOWN)
287
    {
288
      /* Now, nothing should be adjacent */
289
      if ((ifa->type == OSPF_IT_PTP) || (ifa->type == OSPF_IT_VLINK))
290
      {
291
        ospf_iface_chstate(ifa, OSPF_IS_PTP);
292
      }
293
      else
294
      {
295
        if (ifa->priority == 0)
296
          ospf_iface_chstate(ifa, OSPF_IS_DROTHER);
297
        else
298
        {
299
          ospf_iface_chstate(ifa, OSPF_IS_WAITING);
300
          tm_start(ifa->wait_timer, ifa->waitint);
301
        }
302
      }
303

    
304
      tm_start(ifa->hello_timer, ifa->helloint);
305

    
306
      if (ifa->poll_timer)
307
        tm_start(ifa->poll_timer, ifa->pollint);
308

    
309
      hello_timer_hook(ifa->hello_timer);
310
    }
311
    schedule_link_lsa(ifa);
312
    schedule_rt_lsa(ifa->oa);
313
    break;
314
  case ISM_BACKS:
315
  case ISM_WAITF:
316
    if (ifa->state == OSPF_IS_WAITING)
317
    {
318
      bdr_election(ifa);
319
    }
320
    break;
321
  case ISM_NEICH:
322
    if ((ifa->state == OSPF_IS_DROTHER) || (ifa->state == OSPF_IS_DR) ||
323
        (ifa->state == OSPF_IS_BACKUP))
324
    {
325
      bdr_election(ifa);
326
      schedule_rt_lsa(ifa->oa);
327
    }
328
    break;
329
  case ISM_DOWN:
330
    ospf_iface_chstate(ifa, OSPF_IS_DOWN);
331
    ospf_iface_down(ifa);
332
    schedule_rt_lsa(oa);
333
    break;
334
    /*
335
  case ISM_LOOP:
336
    ospf_iface_chstate(ifa, OSPF_IS_LOOP);
337
    break;
338
  case ISM_UNLOOP:
339
    ospf_iface_chstate(ifa, OSPF_IS_DOWN);
340
    break;
341
    */
342
  default:
343
    bug("OSPF_I_SM - Unknown event?");
344
    break;
345
  }
346

    
347
}
348

    
349
u8
350
ospf_iface_clasify(struct iface *ifa, struct ifa *addr)
351
{
352
  if (addr->flags & IA_UNNUMBERED)
353
    return OSPF_IT_PTP;
354

    
355
  if ((ifa->flags & (IF_MULTIACCESS | IF_MULTICAST)) ==
356
      (IF_MULTIACCESS | IF_MULTICAST))
357
    return OSPF_IT_BCAST;
358

    
359
  if ((ifa->flags & (IF_MULTIACCESS | IF_MULTICAST)) == IF_MULTIACCESS)
360
    return OSPF_IT_NBMA;
361

    
362
  return OSPF_IT_PTP;
363
}
364

    
365
struct ospf_iface *
366
ospf_iface_find(struct proto_ospf *p, struct iface *what)
367
{
368
  struct ospf_iface *i;
369

    
370
  WALK_LIST(i, p->iface_list) if ((i->iface == what) && (i->type != OSPF_IT_VLINK))
371
    return i;
372
  return NULL;
373
}
374

    
375
static void
376
ospf_iface_add(struct object_lock *lock)
377
{
378
  struct ospf_iface *ifa = lock->data;
379
  struct proto_ospf *po = ifa->oa->po;
380
  struct proto *p = &po->proto;
381

    
382
  ifa->lock = lock;
383

    
384
  if (ospf_sk_open(ifa))
385
  {
386
    if (ifa->type != OSPF_IT_NBMA)
387
      ospf_sk_join_spf(ifa);
388
  }
389
  else
390
  {
391
    log(L_ERR "%s: Socket open failed on interface %s, declaring as stub", p->name, ifa->iface->name);
392
    ifa->ioprob = OSPF_I_SK;
393
    ifa->stub = 1;
394
  }
395

    
396
  ifa->state = OSPF_IS_DOWN;
397
  ospf_iface_sm(ifa, ISM_UP);
398
}
399

    
400
void
401
ospf_iface_new(struct proto_ospf *po, struct iface *iface, struct ifa *addr,
402
               struct ospf_area_config *ac, struct ospf_iface_patt *ip)
403
{
404
  struct proto *p = &po->proto;
405
  struct ospf_iface *ifa;
406
  struct nbma_node *nbma, *nb;
407
  struct object_lock *lock;
408
  struct ospf_area *oa;
409

    
410
  if (ip->type != OSPF_IT_VLINK)
411
    OSPF_TRACE(D_EVENTS, "Adding interface %s", iface->name);
412

    
413
  ifa = mb_allocz(p->pool, sizeof(struct ospf_iface));
414
  ifa->iface = iface;
415
  ifa->addr = addr;
416

    
417
  ifa->cost = ip->cost;
418
  ifa->rxmtint = ip->rxmtint;
419
  ifa->inftransdelay = ip->inftransdelay;
420
  ifa->priority = ip->priority;
421
  ifa->helloint = ip->helloint;
422
  ifa->pollint = ip->pollint;
423
  ifa->strictnbma = ip->strictnbma;
424
  ifa->waitint = ip->waitint;
425
  ifa->dead = (ip->dead == 0) ? ip->deadc * ifa->helloint : ip->dead;
426
  ifa->stub = ospf_iface_stubby(ip, addr);
427
  ifa->ioprob = OSPF_I_OK;
428
  ifa->rxbuf = ip->rxbuf;
429

    
430
#ifdef OSPFv2
431
  ifa->autype = ip->autype;
432
  ifa->passwords = ip->passwords;
433
#endif
434

    
435
#ifdef OSPFv3
436
  ifa->instance_id = ip->instance_id;
437

    
438
  /*
439
  addr = NULL;
440
  if (ifa->type != OSPF_IT_VLINK)
441
    {
442
      struct ifa *a;
443
      WALK_LIST(a, iface->addrs)
444
        if (a->scope == SCOPE_LINK)
445
          {
446
            addr = a;
447
            break;
448
          }
449

450
      if (!addr)
451
      {
452
        log(L_ERR "%s: Missing link-local address on interface %s, declaring as stub", p->name,  iface->name);
453
        ifa->ioprob = OSPF_I_LL;
454
        ifa->stub = 1;
455
      }
456
    }
457
  */
458
#endif
459

    
460
  if (ip->type == OSPF_IT_UNDEF)
461
    ifa->type = ospf_iface_clasify(iface, addr);
462
  else
463
    ifa->type = ip->type;
464

    
465
#ifdef OSPFv2
466
  if ((ifa->type != OSPF_IT_PTP) && (ifa->type != OSPF_IT_VLINK) &&
467
      (addr->flags & IA_UNNUMBERED))
468
  {
469
    log(L_WARN "%s: Missing proper IP prefix on interface %s, forcing point-to-point mode",
470
        p->name,  iface->name);
471
    ifa->type = OSPF_IT_PTP;
472
  }
473
#endif
474

    
475
  init_list(&ifa->neigh_list);
476
  init_list(&ifa->nbma_list);
477

    
478
  WALK_LIST(nb, ip->nbma_list)
479
  {
480
    nbma = mb_alloc(p->pool, sizeof(struct nbma_node));
481
    nbma->ip = nb->ip;
482
    nbma->eligible = nb->eligible;
483
    add_tail(&ifa->nbma_list, NODE nbma);
484
  }
485

    
486
  /* Add hello timer */
487
  ifa->hello_timer = tm_new(p->pool);
488
  ifa->hello_timer->data = ifa;
489
  ifa->hello_timer->randomize = 0;
490
  ifa->hello_timer->hook = hello_timer_hook;
491
  ifa->hello_timer->recurrent = ifa->helloint;
492
  DBG("%s: Installing hello timer. (%u)\n", p->name, ifa->helloint);
493

    
494
  if (ifa->type == OSPF_IT_NBMA)
495
  {
496
    ifa->poll_timer = tm_new(p->pool);
497
    ifa->poll_timer->data = ifa;
498
    ifa->poll_timer->randomize = 0;
499
    ifa->poll_timer->hook = poll_timer_hook;
500
    ifa->poll_timer->recurrent = ifa->pollint;
501
    DBG("%s: Installing poll timer. (%u)\n", p->name, ifa->pollint);
502
  }
503
  else
504
    ifa->poll_timer = NULL;
505

    
506
  ifa->wait_timer = tm_new(p->pool);
507
  ifa->wait_timer->data = ifa;
508
  ifa->wait_timer->randomize = 0;
509
  ifa->wait_timer->hook = wait_timer_hook;
510
  ifa->wait_timer->recurrent = 0;
511
  DBG("%s: Installing wait timer. (%u)\n", p->name, ifa->waitint);
512
  add_tail(&((struct proto_ospf *) p)->iface_list, NODE ifa);
513
  ifa->state = OSPF_IS_DOWN;
514

    
515
  ifa->oa = NULL;
516
  WALK_LIST(oa, po->area_list)
517
  {
518
    if (oa->areaid == ac->areaid)
519
    {
520
      ifa->oa = oa;
521
      break;
522
    }
523
  }
524

    
525
  if (!ifa->oa)
526
    bug("Cannot add any area to accepted Interface");
527
  else
528

    
529
  if (ifa->type == OSPF_IT_VLINK)
530
  {
531
    ifa->oa = po->backbone;
532
    ifa->voa = oa;
533
    ifa->vid = ip->vid;
534
    return;                        /* Don't lock, don't add sockets */
535
  }
536

    
537
  /*
538
   * In some cases we allow more ospf_ifaces on one physical iface.
539
   * In OSPFv2, if they use different IP address prefix.
540
   * In OSPFv3, if they use different instance_id.
541
   * Therefore, we store such info to lock->addr field.
542
   */
543

    
544
  lock = olock_new(p->pool);
545
#ifdef OSPFv2
546
  lock->addr = ifa->addr->prefix;
547
#else /* OSPFv3 */
548
  lock->addr = _MI(0,0,0,ifa->instance_id);
549
#endif
550
  lock->type = OBJLOCK_IP;
551
  lock->port = OSPF_PROTO;
552
  lock->iface = iface;
553
  lock->data = ifa;
554
  lock->hook = ospf_iface_add;
555

    
556
  olock_acquire(lock);
557
}
558

    
559

    
560
#ifdef OSPFv2
561

    
562
void
563
ospf_ifa_notify(struct proto *p, unsigned flags, struct ifa *a)
564
{
565
  struct proto_ospf *po = (struct proto_ospf *) p;
566
  struct ospf_config *cf = (struct ospf_config *) (p->cf);
567

    
568
  if (a->flags & IA_SECONDARY)
569
    return;
570

    
571
  if (a->scope <= SCOPE_LINK)
572
    return;
573

    
574
  /* In OSPFv2, we create OSPF iface for each address. */
575
  if (flags & IF_CHANGE_UP)
576
  {
577
    int done = 0;
578
    struct ospf_area_config *ac;
579
    WALK_LIST(ac, cf->area_list)
580
    {
581
      struct ospf_iface_patt *ip = (struct ospf_iface_patt *)
582
        iface_patt_find(&ac->patt_list, a->iface, a);
583

    
584
      if (ip)
585
      {
586
        if (!done)
587
          ospf_iface_new(po, a->iface, a, ac, ip);
588
        done++;
589
      }
590
    }
591

    
592
    if (done > 1)
593
      log(L_WARN "%s: Interface %s (IP %I) matches for multiple areas", p->name,  a->iface->name, a->ip);
594
  }
595

    
596
  if (flags & IF_CHANGE_DOWN)
597
  {
598
    struct ospf_iface *ifa, *ifx;
599
    WALK_LIST_DELSAFE(ifa, ifx, po->iface_list)
600
    {
601
      if ((ifa->type != OSPF_IT_VLINK) && (ifa->addr == a))
602
        ospf_iface_sm(ifa, ISM_DOWN);
603
      /* See a note in ospf_iface_notify() */
604
    }
605
  }
606
}
607

    
608
#else /* OSPFv3 */
609

    
610
static inline int iflag_test(u32 *a, u8 i)
611
{
612
  return a[i / 32] & (1u << (i % 32));
613
}
614

    
615
static inline void iflag_set(u32 *a, u8 i)
616
{
617
  a[i / 32] |= (1u << (i % 32));
618
}
619

    
620
void
621
ospf_ifa_notify(struct proto *p, unsigned flags, struct ifa *a)
622
{
623
  struct proto_ospf *po = (struct proto_ospf *) p;
624
  struct ospf_config *cf = (struct ospf_config *) (p->cf);
625

    
626
  if (a->flags & IA_SECONDARY)
627
    return;
628

    
629
  if (a->scope < SCOPE_LINK)
630
    return;
631

    
632
  /* In OSPFv3, we create OSPF iface for link-local address,
633
     other addresses are used for link-LSA. */
634
  if (a->scope == SCOPE_LINK)
635
  {
636
    if (flags & IF_CHANGE_UP)
637
    {
638
      u32 found_all[8] = {};
639
      struct ospf_area_config *ac;
640

    
641
      WALK_LIST(ac, cf->area_list)
642
      {
643
        u32 found_new[8] = {};
644
        struct iface_patt *p;
645

    
646
        WALK_LIST(p, ac->patt_list)
647
        {
648
          if (iface_patt_match(p, i, a))
649
          {
650
            struct ospf_iface_patt *ip = (struct ospf_iface_patt *) p;
651

    
652
            /* If true, we already assigned that IID and we skip
653
               this to implement first-match behavior */
654
            if (iflag_test(found_new, ip->instance_id))
655
              continue;
656

    
657
            /* If true, we already assigned that in a different area,
658
               we log collision */
659
            if (iflag_test(found_all, ip->instance_id))
660
            {
661
              log(L_WARN "%s: Interface %s (IID %d) matches for multiple areas",
662
                  p->name,  a->iface->name, ip->instance_id);
663
              continue;
664
            }
665

    
666
            iflag_set(found_all, ip->instance_id);
667
            iflag_set(found_new, ip->instance_id);
668
            ospf_iface_new(po, a->iface, a, ac, ip);
669
          }
670
        }
671
      }
672
    }
673

    
674
    if (flags & IF_CHANGE_DOWN)
675
    {
676
      struct ospf_iface *ifa, *ifx;
677
      WALK_LIST_DELSAFE(ifa, ifx, po->iface_list)
678
      {
679
        if ((ifa->type != OSPF_IT_VLINK) && (ifa->addr == a))
680
          ospf_iface_sm(ifa, ISM_DOWN);
681
        /* See a note in ospf_iface_notify() */
682
      }
683
    }
684
  }
685
  else
686
  {
687
    struct ospf_iface *ifa;
688
    WALK_LIST(ifa, po->iface_list)
689
    {
690
      if (ifa->iface == a->iface)
691
      {
692
        schedule_rt_lsa(ifa->oa);
693
        /* Event 5 from RFC5340 4.4.3. */
694
        schedule_link_lsa(ifa);
695
        return;
696
      }
697
    }
698
  }
699
}
700

    
701
#endif
702

    
703
void
704
ospf_iface_change_mtu(struct proto_ospf *po, struct ospf_iface *ifa)
705
{
706
  struct proto *p = &po->proto;
707
  struct ospf_packet *op;
708
  struct ospf_neighbor *n;
709
  OSPF_TRACE(D_EVENTS, "Changing MTU on interface %s.", ifa->iface->name);
710

    
711
  if (ifa->sk)
712
  {
713
    ifa->sk->rbsize = rxbufsize(ifa);
714
    ifa->sk->tbsize = ifa->iface->mtu;
715
    sk_reallocate(ifa->sk);
716
  }
717

    
718
  WALK_LIST(n, ifa->neigh_list)
719
  {
720
    op = (struct ospf_packet *) n->ldbdes;
721
    n->ldbdes = mb_allocz(n->pool, ifa->iface->mtu);
722

    
723
    if (ntohs(op->length) <= ifa->iface->mtu)        /* If the packet in old buffer is bigger, let it filled by zeros */
724
      memcpy(n->ldbdes, op, ifa->iface->mtu);        /* If the packet is old is same or smaller, copy it */
725

    
726
    rfree(op);
727
  }
728
}
729

    
730
void
731
ospf_iface_notify(struct proto *p, unsigned flags, struct iface *iface)
732
{
733
  struct proto_ospf *po = (struct proto_ospf *) p;
734
    
735
  DBG("%s: If notify called\n", p->name);
736
  if (iface->flags & IF_IGNORE)
737
    return;
738

    
739
  if (flags & IF_CHANGE_DOWN)
740
  {
741
    struct ospf_iface *ifa, *ifx;
742
    WALK_LIST_DELSAFE(ifa, ifx, po->iface_list)
743
      if ((ifa->type != OSPF_IT_VLINK) && (ifa->iface == iface))
744
        ospf_iface_sm(ifa, ISM_DOWN);
745

    
746
    /* We use here that even shutting down iface also shuts down
747
       the vlinks, but vlinks are not freed and stays in the
748
       iface_list even when down */
749
  }
750

    
751
  if (flags & IF_CHANGE_MTU)
752
  {
753
    struct ospf_iface *ifa;
754
    WALK_LIST(ifa, po->iface_list)
755
      if ((ifa->type != OSPF_IT_VLINK) && (ifa->iface == iface))
756
        ospf_iface_change_mtu(po, ifa);
757
  }
758
}
759

    
760
void
761
ospf_iface_info(struct ospf_iface *ifa)
762
{
763
  char *strict = "(strict)";
764

    
765
  if ((ifa->type != OSPF_IT_NBMA) || (ifa->strictnbma == 0))
766
    strict = "";
767
  if (ifa->type == OSPF_IT_VLINK)
768
  {
769
    cli_msg(-1015, "Virtual link to %R:", ifa->vid);
770
    cli_msg(-1015, "\tPeer IP: %I", ifa->vip);
771
    cli_msg(-1015, "\tTransit area: %R (%u)", ifa->voa->areaid,
772
            ifa->voa->areaid);
773
    cli_msg(-1015, "\tInterface: \"%s\"",
774
            (ifa->iface ? ifa->iface->name : "(none)"));
775
  }
776
  else
777
  {
778
#ifdef OSPFv2
779
    if (ifa->addr->flags & IA_UNNUMBERED)
780
      cli_msg(-1015, "Interface %s (peer %I)", ifa->iface->name, ifa->addr->opposite);
781
    else
782
      cli_msg(-1015, "Interface %s (%I/%d)", ifa->iface->name, ifa->addr->prefix, ifa->addr->pxlen);
783
#else /* OSPFv3 */
784
    cli_msg(-1015, "Interface %s (IID %d)", ifa->iface->name, ifa->instance_id);
785
#endif
786
    cli_msg(-1015, "\tType: %s %s", ospf_it[ifa->type], strict);
787
    cli_msg(-1015, "\tArea: %R (%u)", ifa->oa->areaid, ifa->oa->areaid);
788
  }
789
  cli_msg(-1015, "\tState: %s %s", ospf_is[ifa->state],
790
          ifa->stub ? "(stub)" : "");
791
  cli_msg(-1015, "\tPriority: %u", ifa->priority);
792
  cli_msg(-1015, "\tCost: %u", ifa->cost);
793
  cli_msg(-1015, "\tHello timer: %u", ifa->helloint);
794

    
795
  if (ifa->type == OSPF_IT_NBMA)
796
  {
797
    cli_msg(-1015, "\tPoll timer: %u", ifa->pollint);
798
  }
799
  cli_msg(-1015, "\tWait timer: %u", ifa->waitint);
800
  cli_msg(-1015, "\tDead timer: %u", ifa->dead);
801
  cli_msg(-1015, "\tRetransmit timer: %u", ifa->rxmtint);
802
  if ((ifa->type == OSPF_IT_BCAST) || (ifa->type == OSPF_IT_NBMA))
803
  {
804
    cli_msg(-1015, "\tDesigned router (ID): %R", ifa->drid);
805
    cli_msg(-1015, "\tDesigned router (IP): %I", ifa->drip);
806
    cli_msg(-1015, "\tBackup designed router (ID): %R", ifa->bdrid);
807
    cli_msg(-1015, "\tBackup designed router (IP): %I", ifa->bdrip);
808
  }
809
}
810

    
811
void
812
ospf_iface_shutdown(struct ospf_iface *ifa)
813
{
814
  init_list(&ifa->neigh_list);
815
  hello_timer_hook(ifa->hello_timer);
816
  ospf_sk_close(ifa);
817
}