`ifconfig` patch to resolve IPv6 scope names
raichoo
raichoo at googlemail.com
Wed Aug 9 20:45:07 UTC 2017
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 at 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) {
>
>
More information about the freebsd-hackers
mailing list