Date: Wed, 9 Aug 2017 22:45:05 +0200 From: raichoo <raichoo@googlemail.com> To: freebsd-hackers@freebsd.org Subject: Re: `ifconfig` patch to resolve IPv6 scope names Message-ID: <CAJaUxezspq%2BYpWH7E3eMcqmCo=uvhbSCe3Q39W3WHn1VyjG5EA@mail.gmail.com> In-Reply-To: <CAJaUxeyRQoQkVdb3jNim_BVbdtBp0hM1pn3AiaR_DPJZAyQapg@mail.gmail.com> References: <CAJaUxeyRQoQkVdb3jNim_BVbdtBp0hM1pn3AiaR_DPJZAyQapg@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Had a little chat with kp on #bsddev and got the advice to use the constants in in6.h instead of the bare scope ids. So here's the revised version. diff --git a/sbin/ifconfig/af_inet6.c b/sbin/ifconfig/af_inet6.c index e93d94355e..4e37656db0 100644 --- a/sbin/ifconfig/af_inet6.c +++ b/sbin/ifconfig/af_inet6.c @@ -268,10 +268,29 @@ 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) + if (((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id) { printf("scopeid 0x%x ", ((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id); + switch (((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id) { + case __IPV6_ADDR_SCOPE_INTFACELOCAL: + printf("interface-local "); + break; + case __IPV6_ADDR_SCOPE_LINKLOCAL: + printf("link-local "); + break; + case __IPV6_ADDR_SCOPE_SITELOCAL: + printf("site-local "); + break; + case __IPV6_ADDR_SCOPE_ORGLOCAL: + printf("organization-local "); + break; + case __IPV6_ADDR_SCOPE_GLOBAL: + printf("global "); + break; + } + } + if (ip6lifetime && (lifetime.ia6t_preferred || lifetime.ia6t_expire)) { printf("pltime "); if (lifetime.ia6t_preferred) { On Wed, Aug 9, 2017 at 10:18 PM, raichoo <raichoo@googlemail.com> wrote: > Hi, > > I've made a trivial patch that resolves IPv6 scope names (according to > rfc4291). > I thought this might be handy, so one does not have to memorize what id > refers > to which scope. And it's a nice opportunity to get my feet wet I guess :) > > This is my first patch and I have no idea what's the best way to > contribute to the > project (probably I didn't look hard enough or in the wrong places). > > Feedback and pointers appreciated. > > Kind regards, > raichoo > > diff --git a/sbin/ifconfig/af_inet6.c b/sbin/ifconfig/af_inet6.c > index e93d94355e..165b2cc90a 100644 > --- a/sbin/ifconfig/af_inet6.c > +++ b/sbin/ifconfig/af_inet6.c > @@ -268,10 +268,32 @@ 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) > + if (((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id) { > printf("scopeid 0x%x ", > ((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_ > scope_id); > > + switch (((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id) > { > + case 0x1: > + printf("interface-local "); > + break; > + case 0x2: > + printf("link-local "); > + break; > + case 0x4: > + printf("admin-local "); > + break; > + case 0x5: > + printf("site-local "); > + break; > + case 0x8: > + printf("organization-local "); > + break; > + case 0xe: > + printf("global "); > + break; > + } > + } > + > if (ip6lifetime && (lifetime.ia6t_preferred || > lifetime.ia6t_expire)) { > printf("pltime "); > if (lifetime.ia6t_preferred) { > >
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAJaUxezspq%2BYpWH7E3eMcqmCo=uvhbSCe3Q39W3WHn1VyjG5EA>