]> git.ipfire.org Git - thirdparty/bird.git/blob - nest/iface.c
Doc: Remove some superfluous slashes
[thirdparty/bird.git] / nest / iface.c
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 list iface_list;
39
40 /**
41 * ifa_dump - dump interface address
42 * @a: interface address descriptor
43 *
44 * This function dumps contents of an &ifa to the debug output.
45 */
46 void
47 ifa_dump(struct ifa *a)
48 {
49 debug("\t%I, net %I/%-2d bc %I -> %I%s%s%s\n", a->ip, a->prefix, a->pxlen, a->brd, a->opposite,
50 (a->flags & IF_UP) ? "" : " DOWN",
51 (a->flags & IA_PRIMARY) ? "" : " SEC",
52 (a->flags & IA_PEER) ? "PEER" : "");
53 }
54
55 /**
56 * if_dump - dump interface
57 * @i: interface to dump
58 *
59 * This function dumps all information associated with a given
60 * network interface to the debug output.
61 */
62 void
63 if_dump(struct iface *i)
64 {
65 struct ifa *a;
66
67 debug("IF%d: %s", i->index, i->name);
68 if (i->flags & IF_SHUTDOWN)
69 debug(" SHUTDOWN");
70 if (i->flags & IF_UP)
71 debug(" UP");
72 else
73 debug(" DOWN");
74 if (i->flags & IF_ADMIN_UP)
75 debug(" LINK-UP");
76 if (i->flags & IF_MULTIACCESS)
77 debug(" MA");
78 if (i->flags & IF_BROADCAST)
79 debug(" BC");
80 if (i->flags & IF_MULTICAST)
81 debug(" MC");
82 if (i->flags & IF_LOOPBACK)
83 debug(" LOOP");
84 if (i->flags & IF_IGNORE)
85 debug(" IGN");
86 if (i->flags & IF_TMP_DOWN)
87 debug(" TDOWN");
88 debug(" MTU=%d\n", i->mtu);
89 WALK_LIST(a, i->addrs)
90 {
91 ifa_dump(a);
92 ASSERT((a != i->addr) == !(a->flags & IA_PRIMARY));
93 }
94 }
95
96 /**
97 * if_dump_all - dump all interfaces
98 *
99 * This function dumps information about all known network
100 * interfaces to the debug output.
101 */
102 void
103 if_dump_all(void)
104 {
105 struct iface *i;
106
107 debug("Known network interfaces:\n");
108 WALK_LIST(i, iface_list)
109 if_dump(i);
110 debug("Router ID: %08x\n", config->router_id);
111 }
112
113 static inline unsigned
114 if_what_changed(struct iface *i, struct iface *j)
115 {
116 unsigned c;
117
118 if (((i->flags ^ j->flags) & ~(IF_UP | IF_SHUTDOWN | IF_UPDATED | IF_ADMIN_UP | IF_LINK_UP | IF_TMP_DOWN | IF_JUST_CREATED))
119 || (i->index != j->index) || (i->master != j->master))
120 return IF_CHANGE_TOO_MUCH;
121 c = 0;
122 if ((i->flags ^ j->flags) & IF_UP)
123 c |= (i->flags & IF_UP) ? IF_CHANGE_DOWN : IF_CHANGE_UP;
124 if ((i->flags ^ j->flags) & IF_LINK_UP)
125 c |= IF_CHANGE_LINK;
126 if (i->mtu != j->mtu)
127 c |= IF_CHANGE_MTU;
128 return c;
129 }
130
131 static inline void
132 if_copy(struct iface *to, struct iface *from)
133 {
134 to->flags = from->flags | (to->flags & IF_TMP_DOWN);
135 to->mtu = from->mtu;
136 to->master_index = from->master_index;
137 to->master = from->master;
138 }
139
140 static inline void
141 ifa_send_notify(struct proto *p, unsigned c, struct ifa *a)
142 {
143 if (p->ifa_notify && (!p->vrf || p->vrf == a->iface->master))
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" : "",
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
161 WALK_LIST(p, active_proto_list)
162 ifa_send_notify(p, c, a);
163 }
164
165 static inline void
166 ifa_notify_change(unsigned c, struct ifa *a)
167 {
168 if (c & IF_CHANGE_DOWN)
169 neigh_ifa_update(a);
170
171 ifa_notify_change_(c, a);
172
173 if (c & IF_CHANGE_UP)
174 neigh_ifa_update(a);
175 }
176
177 static inline void
178 if_send_notify(struct proto *p, unsigned c, struct iface *i)
179 {
180 if (p->if_notify && (!p->vrf || p->vrf == i->master))
181 {
182 if (p->debug & D_IFACES)
183 log(L_TRACE "%s < interface %s %s", p->name, i->name,
184 (c & IF_CHANGE_UP) ? "goes up" :
185 (c & IF_CHANGE_DOWN) ? "goes down" :
186 (c & IF_CHANGE_MTU) ? "changes MTU" :
187 (c & IF_CHANGE_LINK) ? "changes link" :
188 (c & IF_CHANGE_CREATE) ? "created" :
189 "sends unknown event");
190 p->if_notify(p, c, i);
191 }
192 }
193
194 static void
195 if_notify_change(unsigned c, struct iface *i)
196 {
197 struct proto *p;
198 struct ifa *a;
199
200 if (i->flags & IF_JUST_CREATED)
201 {
202 i->flags &= ~IF_JUST_CREATED;
203 c |= IF_CHANGE_CREATE | IF_CHANGE_MTU;
204 }
205
206 DBG("Interface change notification (%x) for %s\n", c, i->name);
207 #ifdef LOCAL_DEBUG
208 if_dump(i);
209 #endif
210
211 if (c & IF_CHANGE_DOWN)
212 neigh_if_down(i);
213
214 if (c & IF_CHANGE_DOWN)
215 WALK_LIST(a, i->addrs)
216 {
217 a->flags = (i->flags & ~IA_FLAGS) | (a->flags & IA_FLAGS);
218 ifa_notify_change_(IF_CHANGE_DOWN, a);
219 }
220
221 WALK_LIST(p, active_proto_list)
222 if_send_notify(p, c, i);
223
224 if (c & IF_CHANGE_UP)
225 WALK_LIST(a, i->addrs)
226 {
227 a->flags = (i->flags & ~IA_FLAGS) | (a->flags & IA_FLAGS);
228 ifa_notify_change_(IF_CHANGE_UP, a);
229 }
230
231 if (c & IF_CHANGE_UP)
232 neigh_if_up(i);
233
234 if ((c & (IF_CHANGE_UP | IF_CHANGE_DOWN | IF_CHANGE_LINK)) == IF_CHANGE_LINK)
235 neigh_if_link(i);
236 }
237
238 static unsigned
239 if_recalc_flags(struct iface *i, unsigned flags)
240 {
241 if ((flags & (IF_SHUTDOWN | IF_TMP_DOWN)) ||
242 !(flags & IF_ADMIN_UP) ||
243 !i->addr ||
244 (i->master_index && !i->master))
245 flags &= ~IF_UP;
246 else
247 flags |= IF_UP;
248 return flags;
249 }
250
251 static void
252 if_change_flags(struct iface *i, unsigned flags)
253 {
254 unsigned of = i->flags;
255
256 i->flags = if_recalc_flags(i, flags);
257 if ((i->flags ^ of) & IF_UP)
258 if_notify_change((i->flags & IF_UP) ? IF_CHANGE_UP : IF_CHANGE_DOWN, i);
259 }
260
261 /**
262 * if_delete - remove interface
263 * @old: interface
264 *
265 * This function is called by the low-level platform dependent code
266 * whenever it notices an interface disappears. It is just a shorthand
267 * for if_update().
268 */
269
270 void
271 if_delete(struct iface *old)
272 {
273 struct iface f = {};
274 strncpy(f.name, old->name, sizeof(f.name)-1);
275 f.flags = IF_SHUTDOWN;
276 if_update(&f);
277 }
278
279 /**
280 * if_update - update interface status
281 * @new: new interface status
282 *
283 * if_update() is called by the low-level platform dependent code
284 * whenever it notices an interface change.
285 *
286 * There exist two types of interface updates -- synchronous and asynchronous
287 * ones. In the synchronous case, the low-level code calls if_start_update(),
288 * scans all interfaces reported by the OS, uses if_update() and ifa_update()
289 * to pass them to the core and then it finishes the update sequence by
290 * calling if_end_update(). When working asynchronously, the sysdep code
291 * calls if_update() and ifa_update() whenever it notices a change.
292 *
293 * if_update() will automatically notify all other modules about the change.
294 */
295 struct iface *
296 if_update(struct iface *new)
297 {
298 struct iface *i;
299 unsigned c;
300
301 WALK_LIST(i, iface_list)
302 if (!strcmp(new->name, i->name))
303 {
304 new->addr = i->addr;
305 new->flags = if_recalc_flags(new, new->flags);
306 c = if_what_changed(i, new);
307 if (c & IF_CHANGE_TOO_MUCH) /* Changed a lot, convert it to down/up */
308 {
309 DBG("Interface %s changed too much -- forcing down/up transition\n", i->name);
310 if_change_flags(i, i->flags | IF_TMP_DOWN);
311 rem_node(&i->n);
312 new->addr = i->addr;
313 memcpy(&new->addrs, &i->addrs, sizeof(i->addrs));
314 memcpy(i, new, sizeof(*i));
315 i->flags &= ~IF_UP; /* IF_TMP_DOWN will be added later */
316 goto newif;
317 }
318
319 if_copy(i, new);
320 if (c)
321 if_notify_change(c, i);
322
323 i->flags |= IF_UPDATED;
324 return i;
325 }
326 i = mb_alloc(if_pool, sizeof(struct iface));
327 memcpy(i, new, sizeof(*i));
328 init_list(&i->addrs);
329 newif:
330 init_list(&i->neighbors);
331 i->flags |= IF_UPDATED | IF_TMP_DOWN; /* Tmp down as we don't have addresses yet */
332 add_tail(&iface_list, &i->n);
333 return i;
334 }
335
336 void
337 if_start_update(void)
338 {
339 struct iface *i;
340 struct ifa *a;
341
342 WALK_LIST(i, iface_list)
343 {
344 i->flags &= ~IF_UPDATED;
345 WALK_LIST(a, i->addrs)
346 a->flags &= ~IF_UPDATED;
347 }
348 }
349
350 void
351 if_end_partial_update(struct iface *i)
352 {
353 if (i->flags & IF_TMP_DOWN)
354 if_change_flags(i, i->flags & ~IF_TMP_DOWN);
355 }
356
357 void
358 if_end_update(void)
359 {
360 struct iface *i;
361 struct ifa *a, *b;
362
363 WALK_LIST(i, iface_list)
364 {
365 if (!(i->flags & IF_UPDATED))
366 if_change_flags(i, (i->flags & ~IF_ADMIN_UP) | IF_SHUTDOWN);
367 else
368 {
369 WALK_LIST_DELSAFE(a, b, i->addrs)
370 if (!(a->flags & IF_UPDATED))
371 ifa_delete(a);
372 if_end_partial_update(i);
373 }
374 }
375 }
376
377 void
378 if_flush_ifaces(struct proto *p)
379 {
380 if (p->debug & D_EVENTS)
381 log(L_TRACE "%s: Flushing interfaces", p->name);
382 if_start_update();
383 if_end_update();
384 }
385
386 /**
387 * if_feed_baby - advertise interfaces to a new protocol
388 * @p: protocol to feed
389 *
390 * When a new protocol starts, this function sends it a series
391 * of notifications about all existing interfaces.
392 */
393 void
394 if_feed_baby(struct proto *p)
395 {
396 struct iface *i;
397 struct ifa *a;
398
399 if (!p->if_notify && !p->ifa_notify) /* shortcut */
400 return;
401 DBG("Announcing interfaces to new protocol %s\n", p->name);
402 WALK_LIST(i, iface_list)
403 {
404 if_send_notify(p, IF_CHANGE_CREATE | ((i->flags & IF_UP) ? IF_CHANGE_UP : 0), i);
405 if (i->flags & IF_UP)
406 WALK_LIST(a, i->addrs)
407 ifa_send_notify(p, IF_CHANGE_CREATE | IF_CHANGE_UP, a);
408 }
409 }
410
411 /**
412 * if_find_by_index - find interface by ifindex
413 * @idx: ifindex
414 *
415 * This function finds an &iface structure corresponding to an interface
416 * of the given index @idx. Returns a pointer to the structure or %NULL
417 * if no such structure exists.
418 */
419 struct iface *
420 if_find_by_index(unsigned idx)
421 {
422 struct iface *i;
423
424 WALK_LIST(i, iface_list)
425 if (i->index == idx && !(i->flags & IF_SHUTDOWN))
426 return i;
427 return NULL;
428 }
429
430 /**
431 * if_find_by_name - find interface by name
432 * @name: interface name
433 *
434 * This function finds an &iface structure corresponding to an interface
435 * of the given name @name. Returns a pointer to the structure or %NULL
436 * if no such structure exists.
437 */
438 struct iface *
439 if_find_by_name(char *name)
440 {
441 struct iface *i;
442
443 WALK_LIST(i, iface_list)
444 if (!strcmp(i->name, name))
445 return i;
446 return NULL;
447 }
448
449 struct iface *
450 if_get_by_name(char *name)
451 {
452 struct iface *i;
453
454 if (i = if_find_by_name(name))
455 return i;
456
457 /* No active iface, create a dummy */
458 i = mb_allocz(if_pool, sizeof(struct iface));
459 strncpy(i->name, name, sizeof(i->name)-1);
460 i->flags = IF_SHUTDOWN;
461 init_list(&i->addrs);
462 init_list(&i->neighbors);
463 add_tail(&iface_list, &i->n);
464 return i;
465 }
466
467 struct ifa *kif_choose_primary(struct iface *i);
468
469 static int
470 ifa_recalc_primary(struct iface *i)
471 {
472 struct ifa *a = kif_choose_primary(i);
473
474 if (a == i->addr)
475 return 0;
476
477 if (i->addr)
478 i->addr->flags &= ~IA_PRIMARY;
479
480 if (a)
481 {
482 a->flags |= IA_PRIMARY;
483 rem_node(&a->n);
484 add_head(&i->addrs, &a->n);
485 }
486
487 i->addr = a;
488 return 1;
489 }
490
491 void
492 ifa_recalc_all_primary_addresses(void)
493 {
494 struct iface *i;
495
496 WALK_LIST(i, iface_list)
497 {
498 if (ifa_recalc_primary(i))
499 if_change_flags(i, i->flags | IF_TMP_DOWN);
500 }
501 }
502
503 static inline int
504 ifa_same(struct ifa *a, struct ifa *b)
505 {
506 return ipa_equal(a->ip, b->ip) && ipa_equal(a->prefix, b->prefix) &&
507 a->pxlen == b->pxlen;
508 }
509
510
511 /**
512 * ifa_update - update interface address
513 * @a: new interface address
514 *
515 * This function adds address information to a network
516 * interface. It's called by the platform dependent code during
517 * the interface update process described under if_update().
518 */
519 struct ifa *
520 ifa_update(struct ifa *a)
521 {
522 struct iface *i = a->iface;
523 struct ifa *b;
524
525 WALK_LIST(b, i->addrs)
526 if (ifa_same(b, a))
527 {
528 if (ipa_equal(b->brd, a->brd) &&
529 ipa_equal(b->opposite, a->opposite) &&
530 b->scope == a->scope &&
531 !((b->flags ^ a->flags) & IA_PEER))
532 {
533 b->flags |= IF_UPDATED;
534 return b;
535 }
536 ifa_delete(b);
537 break;
538 }
539
540 #ifndef IPV6
541 if ((i->flags & IF_BROADCAST) && !ipa_nonzero(a->brd))
542 log(L_ERR "Missing broadcast address for interface %s", i->name);
543 #endif
544
545 b = mb_alloc(if_pool, sizeof(struct ifa));
546 memcpy(b, a, sizeof(struct ifa));
547 add_tail(&i->addrs, &b->n);
548 b->flags = (i->flags & ~IA_FLAGS) | (a->flags & IA_FLAGS);
549 if (ifa_recalc_primary(i))
550 if_change_flags(i, i->flags | IF_TMP_DOWN);
551 if (b->flags & IF_UP)
552 ifa_notify_change(IF_CHANGE_CREATE | IF_CHANGE_UP, b);
553 return b;
554 }
555
556 /**
557 * ifa_delete - remove interface address
558 * @a: interface address
559 *
560 * This function removes address information from a network
561 * interface. It's called by the platform dependent code during
562 * the interface update process described under if_update().
563 */
564 void
565 ifa_delete(struct ifa *a)
566 {
567 struct iface *i = a->iface;
568 struct ifa *b;
569
570 WALK_LIST(b, i->addrs)
571 if (ifa_same(b, a))
572 {
573 rem_node(&b->n);
574 if (b->flags & IF_UP)
575 {
576 b->flags &= ~IF_UP;
577 ifa_notify_change(IF_CHANGE_DOWN, b);
578 }
579 if (b->flags & IA_PRIMARY)
580 {
581 if_change_flags(i, i->flags | IF_TMP_DOWN);
582 ifa_recalc_primary(i);
583 }
584 mb_free(b);
585 return;
586 }
587 }
588
589 u32
590 if_choose_router_id(struct iface_patt *mask UNUSED6, u32 old_id UNUSED6)
591 {
592 #ifndef IPV6
593 struct iface *i;
594 struct ifa *a, *b;
595
596 b = NULL;
597 WALK_LIST(i, iface_list)
598 {
599 if (!(i->flags & IF_ADMIN_UP) ||
600 (i->flags & IF_SHUTDOWN))
601 continue;
602
603 WALK_LIST(a, i->addrs)
604 {
605 if (a->flags & IA_SECONDARY)
606 continue;
607
608 if (a->scope <= SCOPE_LINK)
609 continue;
610
611 /* Check pattern if specified */
612 if (mask && !iface_patt_match(mask, i, a))
613 continue;
614
615 /* No pattern or pattern matched */
616 if (!b || ipa_to_u32(a->ip) < ipa_to_u32(b->ip))
617 b = a;
618 }
619 }
620
621 if (!b)
622 return 0;
623
624 u32 id = ipa_to_u32(b->ip);
625 if (id != old_id)
626 log(L_INFO "Chosen router ID %R according to interface %s", id, b->iface->name);
627
628 return id;
629
630 #else
631 return 0;
632 #endif
633 }
634
635 /**
636 * if_init - initialize interface module
637 *
638 * This function is called during BIRD startup to initialize
639 * all data structures of the interface module.
640 */
641 void
642 if_init(void)
643 {
644 if_pool = rp_new(&root_pool, "Interfaces");
645 init_list(&iface_list);
646 neigh_init(if_pool);
647 }
648
649 /*
650 * Interface Pattern Lists
651 */
652
653 int
654 iface_patt_match(struct iface_patt *ifp, struct iface *i, struct ifa *a)
655 {
656 struct iface_patt_node *p;
657
658 WALK_LIST(p, ifp->ipn_list)
659 {
660 char *t = p->pattern;
661 int pos = p->positive;
662
663 if (t)
664 {
665 if (*t == '-')
666 {
667 t++;
668 pos = !pos;
669 }
670
671 if (!patmatch(t, i->name))
672 continue;
673 }
674
675 if (p->pxlen == 0)
676 return pos;
677
678 if (!a)
679 continue;
680
681 if (ipa_in_net(a->ip, p->prefix, p->pxlen))
682 return pos;
683
684 if ((a->flags & IA_PEER) &&
685 ipa_in_net(a->opposite, p->prefix, p->pxlen))
686 return pos;
687
688 continue;
689 }
690
691 return 0;
692 }
693
694 struct iface_patt *
695 iface_patt_find(list *l, struct iface *i, struct ifa *a)
696 {
697 struct iface_patt *p;
698
699 WALK_LIST(p, *l)
700 if (iface_patt_match(p, i, a))
701 return p;
702
703 return NULL;
704 }
705
706 static int
707 iface_plists_equal(struct iface_patt *pa, struct iface_patt *pb)
708 {
709 struct iface_patt_node *x, *y;
710
711 x = HEAD(pa->ipn_list);
712 y = HEAD(pb->ipn_list);
713 while (x->n.next && y->n.next)
714 {
715 if ((x->positive != y->positive) ||
716 (!x->pattern && y->pattern) || /* This nasty lines where written by me... :-( Feela */
717 (!y->pattern && x->pattern) ||
718 ((x->pattern != y->pattern) && strcmp(x->pattern, y->pattern)) ||
719 !ipa_equal(x->prefix, y->prefix) ||
720 (x->pxlen != y->pxlen))
721 return 0;
722 x = (void *) x->n.next;
723 y = (void *) y->n.next;
724 }
725 return (!x->n.next && !y->n.next);
726 }
727
728 int
729 iface_patts_equal(list *a, list *b, int (*comp)(struct iface_patt *, struct iface_patt *))
730 {
731 struct iface_patt *x, *y;
732
733 x = HEAD(*a);
734 y = HEAD(*b);
735 while (x->n.next && y->n.next)
736 {
737 if (!iface_plists_equal(x, y) ||
738 (comp && !comp(x, y)))
739 return 0;
740 x = (void *) x->n.next;
741 y = (void *) y->n.next;
742 }
743 return (!x->n.next && !y->n.next);
744 }
745
746 /*
747 * CLI commands.
748 */
749
750 static void
751 if_show_addr(struct ifa *a)
752 {
753 byte opp[STD_ADDRESS_P_LENGTH + 16];
754
755 if (ipa_nonzero(a->opposite))
756 bsprintf(opp, ", opposite %I", a->opposite);
757 else
758 opp[0] = 0;
759 cli_msg(-1003, "\t%I/%d (%s%s, scope %s)",
760 a->ip, a->pxlen,
761 (a->flags & IA_PRIMARY) ? "Primary" : (a->flags & IA_SECONDARY) ? "Secondary" : "Unselected",
762 opp, ip_scope_text(a->scope));
763 }
764
765 void
766 if_show(void)
767 {
768 struct iface *i;
769 struct ifa *a;
770 char *type;
771
772 WALK_LIST(i, iface_list)
773 {
774 if (i->flags & IF_SHUTDOWN)
775 continue;
776
777 char mbuf[16 + sizeof(i->name)] = {};
778 if (i->master)
779 bsprintf(mbuf, " master=%s", i->master->name);
780 else if (i->master_index)
781 bsprintf(mbuf, " master=#%u", i->master_index);
782
783 cli_msg(-1001, "%s %s (index=%d%s)", i->name, (i->flags & IF_UP) ? "up" : "DOWN", i->index, mbuf);
784 if (!(i->flags & IF_MULTIACCESS))
785 type = "PtP";
786 else
787 type = "MultiAccess";
788 cli_msg(-1004, "\t%s%s%s Admin%s Link%s%s%s MTU=%d",
789 type,
790 (i->flags & IF_BROADCAST) ? " Broadcast" : "",
791 (i->flags & IF_MULTICAST) ? " Multicast" : "",
792 (i->flags & IF_ADMIN_UP) ? "Up" : "Down",
793 (i->flags & IF_LINK_UP) ? "Up" : "Down",
794 (i->flags & IF_LOOPBACK) ? " Loopback" : "",
795 (i->flags & IF_IGNORE) ? " Ignored" : "",
796 i->mtu);
797 if (i->addr)
798 if_show_addr(i->addr);
799 WALK_LIST(a, i->addrs)
800 if (a != i->addr)
801 if_show_addr(a);
802 }
803 cli_msg(0, "");
804 }
805
806 void
807 if_show_summary(void)
808 {
809 struct iface *i;
810 byte addr[STD_ADDRESS_P_LENGTH + 16];
811
812 cli_msg(-2005, "interface state address");
813 WALK_LIST(i, iface_list)
814 {
815 if (i->addr)
816 bsprintf(addr, "%I/%d", i->addr->ip, i->addr->pxlen);
817 else
818 addr[0] = 0;
819 cli_msg(-1005, "%-9s %-5s %s", i->name, (i->flags & IF_UP) ? "up" : "DOWN", addr);
820 }
821 cli_msg(0, "");
822 }