From owner-freebsd-hackers@freebsd.org Wed Aug 9 20:45:06 2017 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id EBF59DD5AFE for ; Wed, 9 Aug 2017 20:45:06 +0000 (UTC) (envelope-from raichoo@googlemail.com) Received: from mail-it0-x22f.google.com (mail-it0-x22f.google.com [IPv6:2607:f8b0:4001:c0b::22f]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id BF4A6CCC for ; Wed, 9 Aug 2017 20:45:06 +0000 (UTC) (envelope-from raichoo@googlemail.com) Received: by mail-it0-x22f.google.com with SMTP id 76so3729930ith.0 for ; Wed, 09 Aug 2017 13:45:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=unCpwB/VccVou+W4OaffucM7Z4BeEdeEOZsJo4gGtX4=; b=MDRVFtaAli6JdvGLGe74Notbbsnm9sm3gzDOiKx7dSl3LFvaX/j/9FElNTAjjv1yAs YdyilHjo7d1+NZ2QUJpSkENEdLUFMUR9X8bFGwdxSRUlKjD2jCuFiyGk/s3TYsvoHEjL xKHCCaCGXF3uMUSZM5DhEax6z8evnTlWiRVVzdtftEeq5kiS+FCyMAnw13lYLRELf6Gs sBX2WaVPJ/bsKCOw1ksyuQPhzR7S9qJJdepBB3BDAfecvu2oyeWSc2c8Crco8rfm/glW Ui1Ha4nCeIhl3dMb0Fh96knzeyPLnBIDxHNxYZ8KOngqyTwHU03bA6idLJVMdcTsFjE4 T94g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=unCpwB/VccVou+W4OaffucM7Z4BeEdeEOZsJo4gGtX4=; b=aJToCaUOhbx/HZYbVdm5RqLmzwpF3VkCaRuuZJmz/2xhUEUbb29Wyh7ggPg+yZXciu TWqowG86QX86jsFypaiXiEfz+hlXZ/Q/SpbilDKfBa9kHfki8/N1AJayWfk7BwiHbxbd 8uPhjCkiKoAbIyeKvVWu0vSybHQTNNeoKPtktEhmDIaU2HUm38o1tRw/n0mdZHPl9zZW 1bfojXm2nKujiLFooBneVUW9w+3J9ulvs3QSk6T1NzB73N/s9QXvHmVjcDjiPzW+ANYo 74QvS9biT451mdiEw77zaEz5YW8+HZEoRFmr7gO8KVfdj3HyTinUl1dNKq8c/UeJDc5t EvgA== X-Gm-Message-State: AHYfb5ghZZZhbCYi1vEWn2JSmlqsYHAxciVPYkudKPgUPdQclgaX19PB kqOOnnMhgLEbhzE/FluVKH3lF12bTJ0u X-Received: by 10.36.50.86 with SMTP id j83mr7879261ita.95.1502311505927; Wed, 09 Aug 2017 13:45:05 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.16.69 with HTTP; Wed, 9 Aug 2017 13:45:05 -0700 (PDT) In-Reply-To: References: From: raichoo Date: Wed, 9 Aug 2017 22:45:05 +0200 Message-ID: Subject: Re: `ifconfig` patch to resolve IPv6 scope names To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.23 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Aug 2017 20:45:07 -0000 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 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) { > >