diff options
author | vsevolod <vsevolod@FreeBSD.org> | 2015-02-02 13:03:04 +0000 |
---|---|---|
committer | vsevolod <vsevolod@FreeBSD.org> | 2015-02-02 13:03:04 +0000 |
commit | 6a39979cd265fe809358adb6070c064e4e020600 (patch) | |
tree | e9a4c049f6175a16cc4b9a8bd255cb026d598729 /sbin/ifconfig/af_inet6.c | |
parent | 47e0756aa20f117b6512e683161d62cb894bd3da (diff) | |
download | FreeBSD-src-6a39979cd265fe809358adb6070c064e4e020600.zip FreeBSD-src-6a39979cd265fe809358adb6070c064e4e020600.tar.gz |
Reorganize the list of addresses associated with an interface and group them
based on the address family. This should help to recognize interfaces with
multiple AF (e.g. ipv4 and ipv6) with many aliases or additional addresses. The
order of addresses inside a single group is strictly preserved.
Improve the scope_id output for AF_INET6 families, as the
current approach uses hexadecimal string that is basically the ID of an
interface, whilst this information is already depicted by getnameinfo(3) call.
Therefore, now ifconfig just prints the scope of address as it is defined in
2.4 of RFC 2373.
PR: 197270
Approved by: bapt
MFC after: 2 weeks
Diffstat (limited to 'sbin/ifconfig/af_inet6.c')
-rw-r--r-- | sbin/ifconfig/af_inet6.c | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/sbin/ifconfig/af_inet6.c b/sbin/ifconfig/af_inet6.c index 0f8688a..b1529e23 100644 --- a/sbin/ifconfig/af_inet6.c +++ b/sbin/ifconfig/af_inet6.c @@ -167,6 +167,33 @@ setip6eui64(const char *cmd, int dummy __unused, int s, } static void +in6_print_scope(uint8_t *a) +{ + const char *sname = NULL; + uint16_t val; + + val = (a[0] << 4) + ((a[1] & 0xc0) >> 4); + + if ((val & 0xff0) == 0xff0) + sname = "Multicast"; + else { + switch(val) { + case 0xfe8: + sname = "Link"; + break; + case 0xfec: + sname = "Site"; + break; + default: + sname = "Global"; + break; + } + } + + printf("scope: %s ", sname); +} + +static void in6_status(int s __unused, const struct ifaddrs *ifa) { struct sockaddr_in6 *sin, null_sin; @@ -257,9 +284,7 @@ in6_status(int s __unused, const struct ifaddrs *ifa) if ((flags6 & IN6_IFF_PREFER_SOURCE) != 0) printf("prefer_source "); - if (((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id) - printf("scopeid 0x%x ", - ((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id); + in6_print_scope((uint8_t *)&((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_addr); if (ip6lifetime && (lifetime.ia6t_preferred || lifetime.ia6t_expire)) { printf("pltime "); |