iface.c revision 81922
1/*-
2 * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/usr.sbin/ppp/iface.c 81922 2001-08-19 22:23:22Z brian $
27 */
28
29#include <sys/param.h>
30#include <sys/socket.h>
31#include <netinet/in.h>
32#include <net/if.h>
33#include <net/if_dl.h>
34#include <net/if_var.h>
35#include <net/route.h>
36#include <arpa/inet.h>
37#include <netinet/in_systm.h>
38#include <netinet/in_var.h>
39#include <netinet/ip.h>
40#ifndef NOINET6
41#include <netinet6/nd6.h>
42#endif
43#include <sys/un.h>
44
45#include <errno.h>
46#include <string.h>
47#include <stdio.h>
48#include <stdlib.h>
49#include <sys/ioctl.h>
50#include <sys/sysctl.h>
51#include <termios.h>
52#include <unistd.h>
53
54#include "layer.h"
55#include "defs.h"
56#include "command.h"
57#include "mbuf.h"
58#include "log.h"
59#include "id.h"
60#include "timer.h"
61#include "fsm.h"
62#include "iplist.h"
63#include "lqr.h"
64#include "hdlc.h"
65#include "throughput.h"
66#include "slcompress.h"
67#include "descriptor.h"
68#include "ncpaddr.h"
69#include "ip.h"
70#include "ipcp.h"
71#include "filter.h"
72#include "lcp.h"
73#include "ccp.h"
74#include "link.h"
75#include "mp.h"
76#ifndef NORADIUS
77#include "radius.h"
78#endif
79#include "ipv6cp.h"
80#include "ncp.h"
81#include "bundle.h"
82#include "prompt.h"
83#include "iface.h"
84
85
86struct iface *
87iface_Create(const char *name)
88{
89  int mib[6], maxtries, err;
90  size_t needed, namelen;
91  char *buf, *ptr, *end;
92  struct if_msghdr *ifm;
93  struct ifa_msghdr *ifam;
94  struct sockaddr_dl *dl;
95  struct sockaddr *sa[RTAX_MAX];
96  struct iface *iface;
97  struct iface_addr *addr;
98
99  mib[0] = CTL_NET;
100  mib[1] = PF_ROUTE;
101  mib[2] = 0;
102  mib[3] = 0;
103  mib[4] = NET_RT_IFLIST;
104  mib[5] = 0;
105
106  maxtries = 20;
107  err = 0;
108  do {
109    if (maxtries-- == 0 || (err && err != ENOMEM)) {
110      fprintf(stderr, "iface_Create: sysctl: %s\n", strerror(err));
111      return NULL;
112    }
113
114    if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0) {
115      fprintf(stderr, "iface_Create: sysctl: estimate: %s\n",
116                strerror(errno));
117      return NULL;
118    }
119
120    if ((buf = (char *)malloc(needed)) == NULL) {
121      fprintf(stderr, "iface_Create: malloc failed: %s\n", strerror(errno));
122      return NULL;
123    }
124
125    if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) {
126      err = errno;
127      free(buf);
128      buf = NULL;
129    }
130  } while (buf == NULL);
131
132  ptr = buf;
133  end = buf + needed;
134  iface = NULL;
135  namelen = strlen(name);
136
137  while (ptr < end && iface == NULL) {
138    ifm = (struct if_msghdr *)ptr;			/* On if_msghdr */
139    if (ifm->ifm_type != RTM_IFINFO)
140      break;
141    dl = (struct sockaddr_dl *)(ifm + 1);		/* Single _dl at end */
142    if (dl->sdl_nlen == namelen && !strncmp(name, dl->sdl_data, namelen)) {
143      iface = (struct iface *)malloc(sizeof *iface);
144      if (iface == NULL) {
145        fprintf(stderr, "iface_Create: malloc: %s\n", strerror(errno));
146        return NULL;
147      }
148      iface->name = strdup(name);
149      iface->index = ifm->ifm_index;
150      iface->flags = ifm->ifm_flags;
151      iface->mtu = 0;
152      iface->addrs = 0;
153      iface->addr = NULL;
154    }
155    ptr += ifm->ifm_msglen;				/* First ifa_msghdr */
156    for (; ptr < end; ptr += ifam->ifam_msglen) {
157      ifam = (struct ifa_msghdr *)ptr;			/* Next if address */
158
159      if (ifam->ifam_type != RTM_NEWADDR)		/* finished this if */
160        break;
161
162      if (iface != NULL && ifam->ifam_addrs & RTA_IFA) {
163        /* Found a configured interface ! */
164        iface_ParseHdr(ifam, sa);
165
166        if (sa[RTAX_IFA] && (sa[RTAX_IFA]->sa_family == AF_INET
167#ifndef NOINET6
168                             || sa[RTAX_IFA]->sa_family == AF_INET6
169#endif
170                             )) {
171          /* Record the address */
172
173          addr = (struct iface_addr *)
174            realloc(iface->addr, (iface->addrs + 1) * sizeof iface->addr[0]);
175          if (addr == NULL)
176            break;
177          iface->addr = addr;
178
179          addr += iface->addrs;
180          iface->addrs++;
181
182          ncprange_setsa(&addr->ifa, sa[RTAX_IFA], sa[RTAX_NETMASK]);
183          if (sa[RTAX_BRD])
184            ncpaddr_setsa(&addr->peer, sa[RTAX_BRD]);
185          else
186            ncpaddr_init(&addr->peer);
187        }
188      }
189    }
190  }
191
192  free(buf);
193
194  return iface;
195}
196
197static int
198iface_addr_Zap(const char *name, struct iface_addr *addr, int s)
199{
200  struct ifaliasreq ifra;
201#ifndef NOINET6
202  struct in6_aliasreq ifra6;
203#endif
204  struct sockaddr_in *me4, *msk4, *peer4;
205  struct sockaddr_storage ssme, sspeer, ssmsk;
206  int res;
207
208  ncprange_getsa(&addr->ifa, &ssme, &ssmsk);
209  ncpaddr_getsa(&addr->peer, &sspeer);
210  res = 0;
211
212  switch (ncprange_family(&addr->ifa)) {
213  case AF_INET:
214    memset(&ifra, '\0', sizeof ifra);
215    strncpy(ifra.ifra_name, name, sizeof ifra.ifra_name - 1);
216
217    me4 = (struct sockaddr_in *)&ifra.ifra_addr;
218    memcpy(me4, &ssme, sizeof *me4);
219
220    msk4 = (struct sockaddr_in *)&ifra.ifra_mask;
221    memcpy(msk4, &ssmsk, sizeof *msk4);
222
223    peer4 = (struct sockaddr_in *)&ifra.ifra_broadaddr;
224    if (ncpaddr_family(&addr->peer) == AF_UNSPEC) {
225      peer4->sin_family = AF_INET;
226      peer4->sin_len = sizeof(*peer4);
227      peer4->sin_addr.s_addr = INADDR_NONE;
228    } else
229      memcpy(peer4, &sspeer, sizeof *peer4);
230
231    res = ID0ioctl(s, SIOCDIFADDR, &ifra);
232    break;
233
234#ifndef NOINET6
235  case AF_INET6:
236    memset(&ifra6, '\0', sizeof ifra6);
237    strncpy(ifra6.ifra_name, name, sizeof ifra6.ifra_name - 1);
238
239    memcpy(&ifra6.ifra_addr, &ssme, sizeof ifra6.ifra_addr);
240    memcpy(&ifra6.ifra_prefixmask, &ssmsk, sizeof ifra6.ifra_prefixmask);
241    ifra6.ifra_prefixmask.sin6_family = AF_UNSPEC;
242    if (ncpaddr_family(&addr->peer) == AF_UNSPEC)
243      ifra6.ifra_dstaddr.sin6_family = AF_UNSPEC;
244    else
245      memcpy(&ifra6.ifra_dstaddr, &sspeer, sizeof ifra6.ifra_dstaddr);
246    ifra6.ifra_lifetime.ia6t_vltime = ND6_INFINITE_LIFETIME;
247    ifra6.ifra_lifetime.ia6t_pltime = ND6_INFINITE_LIFETIME;
248
249    res = ID0ioctl(s, SIOCDIFADDR_IN6, &ifra6);
250    break;
251#endif
252  }
253
254  if (res == -1) {
255    char dst[40];
256    const char *end =
257#ifndef NOINET6
258      ncprange_family(&addr->ifa) == AF_INET6 ? "_IN6" :
259#endif
260      "";
261
262    if (ncpaddr_family(&addr->peer) == AF_UNSPEC)
263      log_Printf(LogWARN, "iface rm: ioctl(SIOCDIFADDR%s, %s): %s\n",
264                 end, ncprange_ntoa(&addr->ifa), strerror(errno));
265    else {
266      snprintf(dst, sizeof dst, "%s", ncpaddr_ntoa(&addr->peer));
267      log_Printf(LogWARN, "iface rm: ioctl(SIOCDIFADDR%s, %s -> %s): %s\n",
268                 end, ncprange_ntoa(&addr->ifa), dst, strerror(errno));
269    }
270  }
271
272  return res != -1;
273}
274
275static void
276iface_addr_Add(const char *name, struct iface_addr *addr, int s)
277{
278  struct ifaliasreq ifra;
279#ifndef NOINET6
280  struct in6_aliasreq ifra6;
281#endif
282  struct sockaddr_in *me4, *msk4, *peer4;
283  struct sockaddr_storage ssme, sspeer, ssmsk;
284  int res;
285
286  ncprange_getsa(&addr->ifa, &ssme, &ssmsk);
287  ncpaddr_getsa(&addr->peer, &sspeer);
288  res = 0;
289
290  switch (ncprange_family(&addr->ifa)) {
291  case AF_INET:
292    memset(&ifra, '\0', sizeof ifra);
293    strncpy(ifra.ifra_name, name, sizeof ifra.ifra_name - 1);
294
295    me4 = (struct sockaddr_in *)&ifra.ifra_addr;
296    memcpy(me4, &ssme, sizeof *me4);
297
298    msk4 = (struct sockaddr_in *)&ifra.ifra_mask;
299    memcpy(msk4, &ssmsk, sizeof *msk4);
300
301    peer4 = (struct sockaddr_in *)&ifra.ifra_broadaddr;
302    if (ncpaddr_family(&addr->peer) == AF_UNSPEC) {
303      peer4->sin_family = AF_INET;
304      peer4->sin_len = sizeof(*peer4);
305      peer4->sin_addr.s_addr = INADDR_NONE;
306    } else
307      memcpy(peer4, &sspeer, sizeof *peer4);
308
309    res = ID0ioctl(s, SIOCAIFADDR, &ifra);
310    break;
311
312#ifndef NOINET6
313  case AF_INET6:
314    memset(&ifra6, '\0', sizeof ifra6);
315    strncpy(ifra6.ifra_name, name, sizeof ifra6.ifra_name - 1);
316
317    memcpy(&ifra6.ifra_addr, &ssme, sizeof ifra6.ifra_addr);
318    memcpy(&ifra6.ifra_prefixmask, &ssmsk, sizeof ifra6.ifra_prefixmask);
319    if (ncpaddr_family(&addr->peer) == AF_UNSPEC)
320      ifra6.ifra_dstaddr.sin6_family = AF_UNSPEC;
321    else
322      memcpy(&ifra6.ifra_dstaddr, &sspeer, sizeof ifra6.ifra_dstaddr);
323    ifra6.ifra_lifetime.ia6t_vltime = ND6_INFINITE_LIFETIME;
324    ifra6.ifra_lifetime.ia6t_pltime = ND6_INFINITE_LIFETIME;
325
326    res = ID0ioctl(s, SIOCAIFADDR_IN6, &ifra6);
327    break;
328#endif
329  }
330
331  if (res == -1) {
332    char dst[40];
333    const char *end =
334#ifndef NOINET6
335      ncprange_family(&addr->ifa) == AF_INET6 ? "_IN6" :
336#endif
337      "";
338
339    if (ncpaddr_family(&addr->peer) == AF_UNSPEC)
340      log_Printf(LogWARN, "iface add: ioctl(SIOCAIFADDR%s, %s): %s\n",
341                 end, ncprange_ntoa(&addr->ifa), strerror(errno));
342    else {
343      snprintf(dst, sizeof dst, "%s", ncpaddr_ntoa(&addr->peer));
344      log_Printf(LogWARN, "iface add: ioctl(SIOCDIFADDR%s, %s -> %s): %s\n",
345                 end, ncprange_ntoa(&addr->ifa), dst, strerror(errno));
346    }
347  }
348}
349
350
351void
352iface_Clear(struct iface *iface, struct ncp *ncp, int family, int how)
353{
354  int addrs, af, inskip, in6skip, n, s4 = -1, s6 = -1, *s;
355
356  if (iface->addrs) {
357    inskip = in6skip = how == IFACE_CLEAR_ALL ? 0 : 1;
358    addrs = 0;
359
360    for (n = 0; n < iface->addrs; n++) {
361      af = ncprange_family(&iface->addr[n].ifa);
362      if (family == 0 || family == af) {
363        if (!iface->addr[n].system && (how & IFACE_SYSTEM))
364          continue;
365        switch (af) {
366        case AF_INET:
367          if (inskip) {
368            inskip = 0;
369            continue;
370          }
371          s = &s4;
372          break;
373
374#ifndef NOINET6
375        case AF_INET6:
376          if (in6skip) {
377            in6skip = 0;
378            continue;
379          }
380          s = &s6;
381          break;
382#endif
383        default:
384          continue;
385        }
386
387        if (*s == -1 && (*s = ID0socket(af, SOCK_DGRAM, 0)) == -1)
388          log_Printf(LogERROR, "iface_Clear: socket(): %s\n", strerror(errno));
389        else if (iface_addr_Zap(iface->name, iface->addr + n, *s)) {
390          ncp_IfaceAddrDeleted(ncp, iface->addr + n);
391          bcopy(iface->addr + n + 1, iface->addr + n,
392                (iface->addrs - n - 1) * sizeof *iface->addr);
393          iface->addrs--;
394          n--;
395        }
396      }
397    }
398
399    /* Don't bother realloc()ing - we have little to gain */
400
401    if (s4)
402      close(s4);
403    if (s6)
404      close(s6);
405  }
406}
407
408int
409iface_Add(struct iface *iface, struct ncp *ncp, const struct ncprange *ifa,
410          const struct ncpaddr *peer, int how)
411{
412  int af, n, s, width;
413  struct ncpaddr ifaddr, ncplocal;
414  struct iface_addr *addr;
415
416  af = ncprange_family(ifa);
417  if ((s = ID0socket(af, SOCK_DGRAM, 0)) == -1) {
418    log_Printf(LogERROR, "iface_Add: socket(): %s\n", strerror(errno));
419    return 0;
420  }
421  ncprange_getaddr(ifa, &ncplocal);
422
423  for (n = 0; n < iface->addrs; n++) {
424    if (ncprange_contains(&iface->addr[n].ifa, &ncplocal)) {
425      if (!(how & IFACE_FORCE_ADD)) {
426        close(s);
427        return 0;	/* errno = EEXIST; */
428      }
429
430      if (ncprange_equal(&iface->addr[n].ifa, ifa) &&
431          ncpaddr_equal(&iface->addr[n].peer, peer)) {
432        close(s);
433        return 1;	/* Already there */
434      }
435
436      width =
437#ifndef NOINET6
438        (af == AF_INET6) ? 128 :
439#endif
440      32;
441      iface_addr_Zap(iface->name, iface->addr + n, s);
442      ncprange_setwidth(&iface->addr[n].ifa, width);
443      ncprange_getaddr(&iface->addr[n].ifa, &ifaddr);
444      if (ncpaddr_equal(&ifaddr, &ncplocal))
445        ncpaddr_copy(&iface->addr[n].peer, peer);
446      else
447        ncpaddr_init(&iface->addr[n].peer);
448      iface_addr_Add(iface->name, iface->addr + n, s);
449      if (ncpaddr_equal(&ifaddr, &ncplocal)) {
450        close(s);
451        ncp_IfaceAddrAdded(ncp, iface->addr + n);
452        return 1;
453      }
454    }
455  }
456
457  addr = (struct iface_addr *)realloc
458    (iface->addr, (iface->addrs + 1) * sizeof iface->addr[0]);
459  if (addr == NULL) {
460    log_Printf(LogERROR, "iface_inAdd: realloc: %s\n", strerror(errno));
461    close(s);
462    return 0;
463  }
464  iface->addr = addr;
465
466  if (how & IFACE_ADD_FIRST) {
467    /* Stuff it at the start of our list */
468    n = 0;
469    bcopy(iface->addr, iface->addr + 1, iface->addrs * sizeof *iface->addr);
470  } else
471    n = iface->addrs;
472
473  iface->addrs++;
474  ncprange_copy(&iface->addr[n].ifa, ifa);
475  ncpaddr_copy(&iface->addr[n].peer, peer);
476  iface->addr[n].system = !!(how & IFACE_SYSTEM);
477  iface_addr_Add(iface->name, iface->addr + n, s);
478
479  close(s);
480  ncp_IfaceAddrAdded(ncp, iface->addr + n);
481
482  return 1;
483}
484
485int
486iface_Delete(struct iface *iface, struct ncp *ncp, const struct ncpaddr *del)
487{
488  struct ncpaddr found;
489  int n, res, s;
490
491  if ((s = ID0socket(ncpaddr_family(del), SOCK_DGRAM, 0)) == -1) {
492    log_Printf(LogERROR, "iface_Delete: socket(): %s\n", strerror(errno));
493    return 0;
494  }
495
496  for (n = res = 0; n < iface->addrs; n++) {
497    ncprange_getaddr(&iface->addr[n].ifa, &found);
498    if (ncpaddr_equal(&found, del)) {
499      iface_addr_Zap(iface->name, iface->addr + n, s);
500      ncp_IfaceAddrDeleted(ncp, iface->addr + n);
501      bcopy(iface->addr + n + 1, iface->addr + n,
502            (iface->addrs - n - 1) * sizeof *iface->addr);
503      iface->addrs--;
504      res = 1;
505      break;
506    }
507  }
508
509  close(s);
510
511  return res;
512}
513
514#define IFACE_ADDFLAGS 1
515#define IFACE_DELFLAGS 2
516
517static int
518iface_ChangeFlags(const char *ifname, int flags, int how)
519{
520  struct ifreq ifrq;
521  int s;
522
523  s = ID0socket(AF_INET, SOCK_DGRAM, 0);
524  if (s < 0) {
525    log_Printf(LogERROR, "iface_ChangeFlags: socket: %s\n", strerror(errno));
526    return 0;
527  }
528
529  memset(&ifrq, '\0', sizeof ifrq);
530  strncpy(ifrq.ifr_name, ifname, sizeof ifrq.ifr_name - 1);
531  ifrq.ifr_name[sizeof ifrq.ifr_name - 1] = '\0';
532  if (ID0ioctl(s, SIOCGIFFLAGS, &ifrq) < 0) {
533    log_Printf(LogERROR, "iface_ChangeFlags: ioctl(SIOCGIFFLAGS): %s\n",
534       strerror(errno));
535    close(s);
536    return 0;
537  }
538
539  if (how == IFACE_ADDFLAGS)
540    ifrq.ifr_flags |= flags;
541  else
542    ifrq.ifr_flags &= ~flags;
543
544  if (ID0ioctl(s, SIOCSIFFLAGS, &ifrq) < 0) {
545    log_Printf(LogERROR, "iface_ChangeFlags: ioctl(SIOCSIFFLAGS): %s\n",
546       strerror(errno));
547    close(s);
548    return 0;
549  }
550  close(s);
551
552  return 1;	/* Success */
553}
554
555int
556iface_SetFlags(const char *ifname, int flags)
557{
558  return iface_ChangeFlags(ifname, flags, IFACE_ADDFLAGS);
559}
560
561int
562iface_ClearFlags(const char *ifname, int flags)
563{
564  return iface_ChangeFlags(ifname, flags, IFACE_DELFLAGS);
565}
566
567void
568iface_Destroy(struct iface *iface)
569{
570  /*
571   * iface_Clear(iface, IFACE_CLEAR_ALL) must be called manually
572   * if that's what the user wants.  It's better to leave the interface
573   * allocated so that existing connections can continue to work.
574   */
575
576  if (iface != NULL) {
577    free(iface->name);
578    free(iface->addr);
579    free(iface);
580  }
581}
582
583#define if_entry(x) { IFF_##x, #x }
584
585struct {
586  int flag;
587  const char *value;
588} if_flags[] = {
589  if_entry(UP),
590  if_entry(BROADCAST),
591  if_entry(DEBUG),
592  if_entry(LOOPBACK),
593  if_entry(POINTOPOINT),
594  if_entry(RUNNING),
595  if_entry(NOARP),
596  if_entry(PROMISC),
597  if_entry(ALLMULTI),
598  if_entry(OACTIVE),
599  if_entry(SIMPLEX),
600  if_entry(LINK0),
601  if_entry(LINK1),
602  if_entry(LINK2),
603  if_entry(MULTICAST),
604  { 0, "???" }
605};
606
607int
608iface_Show(struct cmdargs const *arg)
609{
610  struct ncpaddr ncpaddr;
611  struct iface *iface = arg->bundle->iface, *current;
612  int f, flags;
613#ifndef NOINET6
614  int scopeid, width;
615#endif
616  struct in_addr mask;
617
618  current = iface_Create(iface->name);
619  flags = iface->flags = current->flags;
620  iface_Destroy(current);
621
622  prompt_Printf(arg->prompt, "%s (idx %d) <", iface->name, iface->index);
623  for (f = 0; f < sizeof if_flags / sizeof if_flags[0]; f++)
624    if ((if_flags[f].flag & flags) || (!if_flags[f].flag && flags)) {
625      prompt_Printf(arg->prompt, "%s%s", flags == iface->flags ? "" : ",",
626                    if_flags[f].value);
627      flags &= ~if_flags[f].flag;
628    }
629  prompt_Printf(arg->prompt, "> mtu %d has %d address%s:\n", iface->mtu,
630                iface->addrs, iface->addrs == 1 ? "" : "es");
631
632  for (f = 0; f < iface->addrs; f++) {
633    ncprange_getaddr(&iface->addr[f].ifa, &ncpaddr);
634    switch (ncprange_family(&iface->addr[f].ifa)) {
635    case AF_INET:
636      prompt_Printf(arg->prompt, "  inet %s --> ", ncpaddr_ntoa(&ncpaddr));
637      if (ncpaddr_family(&iface->addr[f].peer) == AF_UNSPEC)
638        prompt_Printf(arg->prompt, "255.255.255.255");
639      else
640        prompt_Printf(arg->prompt, "%s", ncpaddr_ntoa(&iface->addr[f].peer));
641      ncprange_getip4mask(&iface->addr[f].ifa, &mask);
642      prompt_Printf(arg->prompt, " netmask 0x%08lx", (long)ntohl(mask.s_addr));
643      break;
644
645#ifndef NOINET6
646    case AF_INET6:
647      prompt_Printf(arg->prompt, "  inet6 %s", ncpaddr_ntoa(&ncpaddr));
648      if (ncpaddr_family(&iface->addr[f].peer) != AF_UNSPEC)
649        prompt_Printf(arg->prompt, " --> %s",
650                      ncpaddr_ntoa(&iface->addr[f].peer));
651      ncprange_getwidth(&iface->addr[f].ifa, &width);
652      if (ncpaddr_family(&iface->addr[f].peer) == AF_UNSPEC)
653        prompt_Printf(arg->prompt, " prefixlen %d", width);
654      if ((scopeid = ncprange_scopeid(&iface->addr[f].ifa)) != -1)
655        prompt_Printf(arg->prompt, " scopeid 0x%x", (unsigned)scopeid);
656      break;
657#endif
658    }
659    prompt_Printf(arg->prompt, "\n");
660  }
661
662  return 0;
663}
664
665void
666iface_ParseHdr(struct ifa_msghdr *ifam, struct sockaddr *sa[RTAX_MAX])
667{
668  char *wp;
669  int rtax;
670
671  wp = (char *)(ifam + 1);
672
673  for (rtax = 0; rtax < RTAX_MAX; rtax++)
674    if (ifam->ifam_addrs & (1 << rtax)) {
675      sa[rtax] = (struct sockaddr *)wp;
676      wp += ROUNDUP(sa[rtax]->sa_len);
677    } else
678      sa[rtax] = NULL;
679}
680