Statistics
| Branch: | Revision:

iof-bird-daemon / nest / iface.c @ 7e95c05d

History | View | Annotate | Download (16.7 KB)

1
/*
2
 *        BIRD -- Management of Interfaces and Neighbor Cache
3
 *
4
 *        (c) 1998--2000 Martin Mares <mj@ucw.cz>
5
 *
6
 *        Can be freely distributed and used under the terms of the GNU GPL.
7
 */
8

    
9
/**
10
 * DOC: Interfaces
11
 *
12
 * The interface module keeps track of all network interfaces in the
13
 * system and their addresses.
14
 *
15
 * Each interface is represented by an &iface structure which carries
16
 * interface capability flags (%IF_MULTIACCESS, %IF_BROADCAST etc.),
17
 * MTU, interface name and index and finally a linked list of network
18
 * prefixes assigned to the interface, each one represented by
19
 * struct &ifa.
20
 *
21
 * The interface module keeps a `soft-up' state for each &iface which
22
 * is a conjunction of link being up, the interface being of a `sane'
23
 * type and at least one IP address assigned to it.
24
 */
25

    
26
#undef LOCAL_DEBUG
27

    
28
#include "nest/bird.h"
29
#include "nest/iface.h"
30
#include "nest/protocol.h"
31
#include "nest/cli.h"
32
#include "lib/resource.h"
33
#include "lib/string.h"
34
#include "conf/conf.h"
35

    
36
static pool *if_pool;
37

    
38
static void auto_router_id(void);
39

    
40
list iface_list;
41

    
42
/**
43
 * ifa_dump - dump interface address
44
 * @a: interface address descriptor
45
 *
46
 * This function dumps contents of an &ifa to the debug output.
47
 */
48
void
49
ifa_dump(struct ifa *a)
50
{
51
  debug("\t%I, net %I/%-2d bc %I -> %I%s%s%s\n", a->ip, a->prefix, a->pxlen, a->brd, a->opposite,
52
        (a->flags & IF_UP) ? "" : " DOWN",
53
        (a->flags & IA_PRIMARY) ? "" : " SEC",
54
        (a->flags & IA_UNNUMBERED) ? " UNNUM" : "");
55
}
56

    
57
/**
58
 * if_dump - dump interface
59
 * @i: interface to dump
60
 *
61
 * This function dumps all information associated with a given
62
 * network interface to the debug output.
63
 */
64
void
65
if_dump(struct iface *i)
66
{
67
  struct ifa *a;
68

    
69
  debug("IF%d: %s", i->index, i->name);
70
  if (i->flags & IF_SHUTDOWN)
71
    debug(" SHUTDOWN");
72
  if (i->flags & IF_UP)
73
    debug(" UP");
74
  else
75
    debug(" DOWN");
76
  if (i->flags & IF_ADMIN_UP)
77
    debug(" LINK-UP");
78
  if (i->flags & IF_MULTIACCESS)
79
    debug(" MA");
80
  if (i->flags & IF_BROADCAST)
81
    debug(" BC");
82
  if (i->flags & IF_MULTICAST)
83
    debug(" MC");
84
  if (i->flags & IF_LOOPBACK)
85
    debug(" LOOP");
86
  if (i->flags & IF_IGNORE)
87
    debug(" IGN");
88
  if (i->flags & IF_TMP_DOWN)
89
    debug(" TDOWN");
90
  debug(" MTU=%d\n", i->mtu);
91
  WALK_LIST(a, i->addrs)
92
    {
93
      ifa_dump(a);
94
      ASSERT((a != i->addr) == !(a->flags & IA_PRIMARY));
95
    }
96
}
97

    
98
/**
99
 * if_dump_all - dump all interfaces
100
 *
101
 * This function dumps information about all known network
102
 * interfaces to the debug output.
103
 */
104
void
105
if_dump_all(void)
106
{
107
  struct iface *i;
108

    
109
  debug("Known network interfaces:\n");
110
  WALK_LIST(i, iface_list)
111
    if_dump(i);
112
  debug("Router ID: %08x\n", config->router_id);
113
}
114

    
115
static inline unsigned
116
if_what_changed(struct iface *i, struct iface *j)
117
{
118
  unsigned c;
119

    
120
  if (((i->flags ^ j->flags) & ~(IF_UP | IF_SHUTDOWN | IF_UPDATED | IF_ADMIN_UP | IF_LINK_UP | IF_TMP_DOWN | IF_JUST_CREATED))
121
      || i->index != j->index)
122
    return IF_CHANGE_TOO_MUCH;
123
  c = 0;
124
  if ((i->flags ^ j->flags) & IF_UP)
125
    c |= (i->flags & IF_UP) ? IF_CHANGE_DOWN : IF_CHANGE_UP;
126
  if ((i->flags ^ j->flags) & IF_LINK_UP)
127
    c |= IF_CHANGE_LINK;
128
  if (i->mtu != j->mtu)
129
    c |= IF_CHANGE_MTU;
130
  return c;
131
}
132

    
133
static inline void
134
if_copy(struct iface *to, struct iface *from)
135
{
136
  to->flags = from->flags | (to->flags & IF_TMP_DOWN);
137
  to->mtu = from->mtu;
138
}
139

    
140
static inline void
141
ifa_send_notify(struct proto *p, unsigned c, struct ifa *a)
142
{
143
  if (p->ifa_notify)
144
    {
145
      if (p->debug & D_IFACES)
146
        log(L_TRACE "%s < %s address %I/%d on interface %s %s",
147
            p->name, (a->flags & IA_PRIMARY) ? "primary" : "secondary",
148
            a->prefix, a->pxlen, a->iface->name,
149
            (c & IF_CHANGE_UP) ? "added" : "removed");
150
      p->ifa_notify(p, c, a);
151
    }
152
}
153

    
154
static void
155
ifa_notify_change(unsigned c, struct ifa *a)
156
{
157
  struct proto *p;
158

    
159
  DBG("IFA change notification (%x) for %s:%I\n", c, a->iface->name, a->ip);
160
  WALK_LIST(p, active_proto_list)
161
    ifa_send_notify(p, c, a);
162
}
163

    
164
static inline void
165
if_send_notify(struct proto *p, unsigned c, struct iface *i)
166
{
167
  if (p->if_notify)
168
    {
169
      if (p->debug & D_IFACES)
170
        log(L_TRACE "%s < interface %s %s", p->name, i->name,
171
            (c & IF_CHANGE_UP) ? "goes up" :
172
            (c & IF_CHANGE_DOWN) ? "goes down" :
173
            (c & IF_CHANGE_MTU) ? "changes MTU" :
174
            (c & IF_CHANGE_LINK) ? "changes link" :
175
            (c & IF_CHANGE_CREATE) ? "created" :
176
            "sends unknown event");
177
      p->if_notify(p, c, i);
178
    }
179
}
180

    
181
static void
182
if_notify_change(unsigned c, struct iface *i)
183
{
184
  struct proto *p;
185
  struct ifa *a;
186

    
187
  if (i->flags & IF_JUST_CREATED)
188
    {
189
      i->flags &= ~IF_JUST_CREATED;
190
      c |= IF_CHANGE_CREATE | IF_CHANGE_MTU;
191
    }
192

    
193
  DBG("Interface change notification (%x) for %s\n", c, i->name);
194
#ifdef LOCAL_DEBUG
195
  if_dump(i);
196
#endif
197

    
198
  if (c & IF_CHANGE_UP)
199
    neigh_if_up(i);
200
  if (c & IF_CHANGE_DOWN)
201
    WALK_LIST(a, i->addrs)
202
      {
203
        a->flags = (i->flags & ~IA_FLAGS) | (a->flags & IA_FLAGS);
204
        ifa_notify_change(IF_CHANGE_DOWN, a);
205
      }
206

    
207
  WALK_LIST(p, active_proto_list)
208
    if_send_notify(p, c, i);
209

    
210
  if (c & IF_CHANGE_UP)
211
    WALK_LIST(a, i->addrs)
212
      {
213
        a->flags = (i->flags & ~IA_FLAGS) | (a->flags & IA_FLAGS);
214
        ifa_notify_change(IF_CHANGE_UP, a);
215
      }
216

    
217
  if ((c & (IF_CHANGE_UP | IF_CHANGE_DOWN | IF_CHANGE_LINK)) == IF_CHANGE_LINK)
218
    neigh_if_link(i);
219

    
220
  if (c & IF_CHANGE_DOWN)
221
    neigh_if_down(i);
222
}
223

    
224
static unsigned
225
if_recalc_flags(struct iface *i, unsigned flags)
226
{
227
  if ((flags & (IF_SHUTDOWN | IF_TMP_DOWN)) ||
228
      !(flags & IF_ADMIN_UP) ||
229
      !i->addr)
230
    flags &= ~IF_UP;
231
  else
232
    flags |= IF_UP;
233
  return flags;
234
}
235

    
236
static void
237
if_change_flags(struct iface *i, unsigned flags)
238
{
239
  unsigned of = i->flags;
240

    
241
  i->flags = if_recalc_flags(i, flags);
242
  if ((i->flags ^ of) & IF_UP)
243
    if_notify_change((i->flags & IF_UP) ? IF_CHANGE_UP : IF_CHANGE_DOWN, i);
244
}
245

    
246
/**
247
 * if_update - update interface status
248
 * @new: new interface status
249
 *
250
 * if_update() is called by the low-level platform dependent code
251
 * whenever it notices an interface change.
252
 *
253
 * There exist two types of interface updates -- synchronous and asynchronous
254
 * ones. In the synchronous case, the low-level code calls if_start_update(),
255
 * scans all interfaces reported by the OS, uses if_update() and ifa_update()
256
 * to pass them to the core and then it finishes the update sequence by
257
 * calling if_end_update(). When working asynchronously, the sysdep code
258
 * calls if_update() and ifa_update() whenever it notices a change.
259
 *
260
 * if_update() will automatically notify all other modules about the change.
261
 */
262
struct iface *
263
if_update(struct iface *new)
264
{
265
  struct iface *i;
266
  unsigned c;
267

    
268
  WALK_LIST(i, iface_list)
269
    if (!strcmp(new->name, i->name))
270
      {
271
        new->addr = i->addr;
272
        new->flags = if_recalc_flags(new, new->flags);
273
        c = if_what_changed(i, new);
274
        if (c & IF_CHANGE_TOO_MUCH)        /* Changed a lot, convert it to down/up */
275
          {
276
            DBG("Interface %s changed too much -- forcing down/up transition\n", i->name);
277
            if_change_flags(i, i->flags | IF_TMP_DOWN);
278
            rem_node(&i->n);
279
            new->addr = i->addr;
280
            memcpy(&new->addrs, &i->addrs, sizeof(i->addrs));
281
            memcpy(i, new, sizeof(*i));
282
            goto newif;
283
          }
284
        else if (c)
285
          {
286
            if_copy(i, new);
287
            if_notify_change(c, i);
288
          }
289
        i->flags |= IF_UPDATED;
290
        return i;
291
      }
292
  i = mb_alloc(if_pool, sizeof(struct iface));
293
  memcpy(i, new, sizeof(*i));
294
  init_list(&i->addrs);
295
newif:
296
  init_list(&i->neighbors);
297
  i->flags |= IF_UPDATED | IF_TMP_DOWN;                /* Tmp down as we don't have addresses yet */
298
  add_tail(&iface_list, &i->n);
299
  return i;
300
}
301

    
302
void
303
if_start_update(void)
304
{
305
  struct iface *i;
306
  struct ifa *a;
307

    
308
  WALK_LIST(i, iface_list)
309
    {
310
      i->flags &= ~IF_UPDATED;
311
      WALK_LIST(a, i->addrs)
312
        a->flags &= ~IF_UPDATED;
313
    }
314
}
315

    
316
void
317
if_end_partial_update(struct iface *i)
318
{
319
  if (i->flags & IF_TMP_DOWN)
320
    if_change_flags(i, i->flags & ~IF_TMP_DOWN);
321
}
322

    
323
void
324
if_end_update(void)
325
{
326
  struct iface *i;
327
  struct ifa *a, *b;
328

    
329
  if (!config->router_id)
330
    auto_router_id();
331

    
332
  WALK_LIST(i, iface_list)
333
    {
334
      if (!(i->flags & IF_UPDATED))
335
        if_change_flags(i, (i->flags & ~IF_ADMIN_UP) | IF_SHUTDOWN);
336
      else
337
        {
338
          WALK_LIST_DELSAFE(a, b, i->addrs)
339
            if (!(a->flags & IF_UPDATED))
340
              ifa_delete(a);
341
          if_end_partial_update(i);
342
        }
343
    }
344
}
345

    
346
void
347
if_flush_ifaces(struct proto *p)
348
{
349
  if (p->debug & D_EVENTS)
350
    log(L_TRACE "%s: Flushing interfaces", p->name);
351
  if_start_update();
352
  if_end_update();
353
}
354

    
355
/**
356
 * if_feed_baby - advertise interfaces to a new protocol
357
 * @p: protocol to feed
358
 *
359
 * When a new protocol starts, this function sends it a series
360
 * of notifications about all existing interfaces.
361
 */
362
void
363
if_feed_baby(struct proto *p)
364
{
365
  struct iface *i;
366
  struct ifa *a;
367

    
368
  if (!p->if_notify && !p->ifa_notify)        /* shortcut */
369
    return;
370
  DBG("Announcing interfaces to new protocol %s\n", p->name);
371
  WALK_LIST(i, iface_list)
372
    {
373
      if_send_notify(p, IF_CHANGE_CREATE | ((i->flags & IF_UP) ? IF_CHANGE_UP : 0), i);
374
      if (i->flags & IF_UP)
375
        WALK_LIST(a, i->addrs)
376
          ifa_send_notify(p, IF_CHANGE_CREATE | IF_CHANGE_UP, a);
377
    }
378
}
379

    
380
/**
381
 * if_find_by_index - find interface by ifindex
382
 * @idx: ifindex
383
 *
384
 * This function finds an &iface structure corresponding to an interface
385
 * of the given index @idx. Returns a pointer to the structure or %NULL
386
 * if no such structure exists.
387
 */
388
struct iface *
389
if_find_by_index(unsigned idx)
390
{
391
  struct iface *i;
392

    
393
  WALK_LIST(i, iface_list)
394
    if (i->index == idx)
395
      return i;
396
  return NULL;
397
}
398

    
399
/**
400
 * if_find_by_name - find interface by name
401
 * @name: interface name
402
 *
403
 * This function finds an &iface structure corresponding to an interface
404
 * of the given name @name. Returns a pointer to the structure or %NULL
405
 * if no such structure exists.
406
 */
407
struct iface *
408
if_find_by_name(char *name)
409
{
410
  struct iface *i;
411

    
412
  WALK_LIST(i, iface_list)
413
    if (!strcmp(i->name, name))
414
      return i;
415
  return NULL;
416
}
417

    
418
struct ifa *kif_choose_primary(struct iface *i);
419

    
420
static int
421
ifa_recalc_primary(struct iface *i)
422
{
423
  struct ifa *a = kif_choose_primary(i);
424

    
425
  if (a == i->addr)
426
    return 0;
427

    
428
  if (i->addr)
429
    i->addr->flags &= ~IA_PRIMARY;
430

    
431
  if (a)
432
    {
433
      a->flags |= IA_PRIMARY;
434
      rem_node(&a->n);
435
      add_head(&i->addrs, &a->n);
436
    }
437

    
438
  i->addr = a;
439
  return 1;
440
}
441

    
442
void
443
ifa_recalc_all_primary_addresses(void)
444
{
445
  struct iface *i;
446

    
447
  WALK_LIST(i, iface_list)
448
    {
449
      if (ifa_recalc_primary(i))
450
        if_change_flags(i, i->flags | IF_TMP_DOWN);
451
    }
452
}
453

    
454

    
455
/**
456
 * ifa_update - update interface address
457
 * @a: new interface address
458
 *
459
 * This function adds address information to a network
460
 * interface. It's called by the platform dependent code during
461
 * the interface update process described under if_update().
462
 */
463
struct ifa *
464
ifa_update(struct ifa *a)
465
{
466
  struct iface *i = a->iface;
467
  struct ifa *b;
468

    
469
  WALK_LIST(b, i->addrs)
470
    if (ipa_equal(b->ip, a->ip))
471
      {
472
        if (ipa_equal(b->prefix, a->prefix) &&
473
            b->pxlen == a->pxlen &&
474
            ipa_equal(b->brd, a->brd) &&
475
            ipa_equal(b->opposite, a->opposite) &&
476
            b->scope == a->scope &&
477
            !((b->flags ^ a->flags) & IA_UNNUMBERED))
478
          {
479
            b->flags |= IF_UPDATED;
480
            return b;
481
          }
482
        ifa_delete(b);
483
        break;
484
      }
485

    
486
  if (!(i->flags & IF_MULTIACCESS) && a->pxlen < BITS_PER_IP_ADDRESS - 2)
487
    log(L_WARN "Strange prefix length %d for point-to-point interface %s", a->pxlen, i->name);
488
#ifndef IPV6
489
  if ((i->flags & IF_BROADCAST) && !ipa_nonzero(a->brd))
490
    log(L_ERR "Missing broadcast address for interface %s", i->name);
491
#endif
492

    
493
  b = mb_alloc(if_pool, sizeof(struct ifa));
494
  memcpy(b, a, sizeof(struct ifa));
495
  add_tail(&i->addrs, &b->n);
496
  b->flags = (i->flags & ~IA_FLAGS) | (a->flags & IA_FLAGS);
497
  if (ifa_recalc_primary(i))
498
    if_change_flags(i, i->flags | IF_TMP_DOWN);
499
  if (b->flags & IF_UP)
500
    ifa_notify_change(IF_CHANGE_CREATE | IF_CHANGE_UP, b);
501
  return b;
502
}
503

    
504
/**
505
 * ifa_delete - remove interface address
506
 * @a: interface address
507
 *
508
 * This function removes address information from a network
509
 * interface. It's called by the platform dependent code during
510
 * the interface update process described under if_update().
511
 */
512
void
513
ifa_delete(struct ifa *a)
514
{
515
  struct iface *i = a->iface;
516
  struct ifa *b;
517

    
518
  WALK_LIST(b, i->addrs)
519
    if (ipa_equal(b->ip, a->ip))
520
      {
521
        rem_node(&b->n);
522
        if (b->flags & IF_UP)
523
          {
524
            b->flags &= ~IF_UP;
525
            ifa_notify_change(IF_CHANGE_DOWN, b);
526
          }
527
        if (b->flags & IA_PRIMARY)
528
          {
529
            if_change_flags(i, i->flags | IF_TMP_DOWN);
530
            ifa_recalc_primary(i);
531
          }
532
        mb_free(b);
533
        return;
534
      }
535
}
536

    
537
static void
538
auto_router_id(void)
539
{
540
#ifndef IPV6
541
  struct iface *i, *j;
542

    
543
  j = NULL;
544
  WALK_LIST(i, iface_list)
545
    if ((i->flags & IF_ADMIN_UP) &&
546
        !(i->flags & (IF_IGNORE | IF_SHUTDOWN)) &&
547
        i->addr &&
548
        !(i->addr->flags & IA_UNNUMBERED) &&
549
        (!j || ipa_to_u32(i->addr->ip) < ipa_to_u32(j->addr->ip)))
550
      j = i;
551
  if (!j)
552
    die("Cannot determine router ID (no suitable network interface found), please configure it manually");
553
  log(L_INFO "Guessed router ID %I according to interface %s", j->addr->ip, j->name);
554
  config->router_id = ipa_to_u32(j->addr->ip);
555
#endif
556
}
557

    
558
/**
559
 * if_init - initialize interface module
560
 *
561
 * This function is called during BIRD startup to initialize
562
 * all data structures of the interface module.
563
 */
564
void
565
if_init(void)
566
{
567
  if_pool = rp_new(&root_pool, "Interfaces");
568
  init_list(&iface_list);
569
  neigh_init(if_pool);
570
}
571

    
572
/*
573
 *        Interface Pattern Lists
574
 */
575

    
576
int
577
iface_patt_match(struct iface_patt *ifp, struct iface *i, struct ifa *a)
578
{
579
  struct iface_patt_node *p;
580

    
581
  WALK_LIST(p, ifp->ipn_list)
582
    {
583
      char *t = p->pattern;
584
      int pos = p->positive;
585

    
586
      if (t)
587
        {
588
          if (*t == '-')
589
            {
590
              t++;
591
              pos = !pos;
592
            }
593

    
594
          if (!patmatch(t, i->name))
595
            continue;
596
        }
597

    
598
      if (p->pxlen == 0)
599
        return pos;
600

    
601
      if (!a)
602
        continue;
603

    
604
      if (ipa_in_net(a->ip, p->prefix, p->pxlen))
605
        return pos;
606

    
607
      if ((a->flags & IA_UNNUMBERED) &&
608
          ipa_in_net(a->opposite, p->prefix, p->pxlen))
609
        return pos;
610
          
611
      continue;
612
    }
613

    
614
  return 0;
615
}
616

    
617
struct iface_patt *
618
iface_patt_find(list *l, struct iface *i, struct ifa *a)
619
{
620
  struct iface_patt *p;
621

    
622
  WALK_LIST(p, *l)
623
    if (iface_patt_match(p, i, a))
624
      return p;
625

    
626
  return NULL;
627
}
628

    
629
static int
630
iface_plists_equal(struct iface_patt *pa, struct iface_patt *pb)
631
{
632
  struct iface_patt_node *x, *y;
633

    
634
  x = HEAD(pa->ipn_list);
635
  y = HEAD(pb->ipn_list);
636
  while (x->n.next && y->n.next)
637
    {
638
      if ((x->positive != y->positive) ||
639
          (!x->pattern && y->pattern) ||        /* This nasty lines where written by me... :-( Feela */
640
          (!y->pattern && x->pattern) ||
641
          ((x->pattern != y->pattern) && strcmp(x->pattern, y->pattern)) ||
642
          !ipa_equal(x->prefix, y->prefix) ||
643
          (x->pxlen != y->pxlen))
644
        return 0;
645
      x = (void *) x->n.next;
646
      y = (void *) y->n.next;
647
    }
648
  return (!x->n.next && !y->n.next);
649
}
650

    
651
int
652
iface_patts_equal(list *a, list *b, int (*comp)(struct iface_patt *, struct iface_patt *))
653
{
654
  struct iface_patt *x, *y;
655

    
656
  x = HEAD(*a);
657
  y = HEAD(*b);
658
  while (x->n.next && y->n.next)
659
    {
660
      if (!iface_plists_equal(x, y) ||
661
          (comp && !comp(x, y)))
662
        return 0;
663
      x = (void *) x->n.next;
664
      y = (void *) y->n.next;
665
    }
666
  return (!x->n.next && !y->n.next);
667
}
668

    
669
/*
670
 *  CLI commands.
671
 */
672

    
673
static void
674
if_show_addr(struct ifa *a)
675
{
676
  byte broad[STD_ADDRESS_P_LENGTH + 16];
677
  byte opp[STD_ADDRESS_P_LENGTH + 16];
678

    
679
  if (ipa_nonzero(a->brd))
680
    bsprintf(broad, ", broadcast %I", a->brd);
681
  else
682
    broad[0] = 0;
683
  if (ipa_nonzero(a->opposite))
684
    bsprintf(opp, ", opposite %I", a->opposite);
685
  else
686
    opp[0] = 0;
687
  cli_msg(-1003, "\t%I/%d (%s%s%s, scope %s%s)",
688
          a->ip, a->pxlen,
689
          (a->flags & IA_PRIMARY) ? "Primary" : (a->flags & IA_SECONDARY) ? "Secondary" : "Unselected",
690
          broad, opp,
691
          ip_scope_text(a->scope),
692
          (a->flags & IA_UNNUMBERED) ? ", unnumbered" : "");
693
}
694

    
695
void
696
if_show(void)
697
{
698
  struct iface *i;
699
  struct ifa *a;
700
  char *type;
701

    
702
  WALK_LIST(i, iface_list)
703
    {
704
      if (i->flags & IF_SHUTDOWN)
705
        continue;
706

    
707
      cli_msg(-1001, "%s %s (index=%d)", i->name, (i->flags & IF_UP) ? "up" : "DOWN", i->index);
708
      if (!(i->flags & IF_MULTIACCESS))
709
        type = "PtP";
710
      else
711
        type = "MultiAccess";
712
      cli_msg(-1004, "\t%s%s%s Admin%s Link%s%s%s MTU=%d",
713
              type,
714
              (i->flags & IF_BROADCAST) ? " Broadcast" : "",
715
              (i->flags & IF_MULTICAST) ? " Multicast" : "",
716
              (i->flags & IF_ADMIN_UP) ? "Up" : "Down",
717
              (i->flags & IF_LINK_UP) ? "Up" : "Down",
718
              (i->flags & IF_LOOPBACK) ? " Loopback" : "",
719
              (i->flags & IF_IGNORE) ? " Ignored" : "",
720
              i->mtu);
721
      if (i->addr)
722
        if_show_addr(i->addr);
723
      WALK_LIST(a, i->addrs)
724
        if (a != i->addr)
725
          if_show_addr(a);
726
    }
727
  cli_msg(0, "");
728
}
729

    
730
void
731
if_show_summary(void)
732
{
733
  struct iface *i;
734
  byte addr[STD_ADDRESS_P_LENGTH + 16];
735

    
736
  cli_msg(-2005, "interface state address");
737
  WALK_LIST(i, iface_list)
738
    {
739
      if (i->addr)
740
        bsprintf(addr, "%I/%d", i->addr->ip, i->addr->pxlen);
741
      else
742
        addr[0] = 0;
743
      cli_msg(-1005, "%-9s %-5s %s", i->name, (i->flags & IF_UP) ? "up" : "DOWN", addr);
744
    }
745
  cli_msg(0, "");
746
}