From owner-freebsd-hackers@freebsd.org Thu Aug 10 20:02:17 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 42B9DDDBA0E for ; Thu, 10 Aug 2017 20:02:17 +0000 (UTC) (envelope-from raichoo@googlemail.com) Received: from mail-io0-x22a.google.com (mail-io0-x22a.google.com [IPv6:2607:f8b0:4001:c06::22a]) (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 11B6C6F9BF for ; Thu, 10 Aug 2017 20:02:17 +0000 (UTC) (envelope-from raichoo@googlemail.com) Received: by mail-io0-x22a.google.com with SMTP id o9so13614884iod.1 for ; Thu, 10 Aug 2017 13:02:17 -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 :cc; bh=rj/B/ZCdN9CLTsH8CHbxoGg8KIHKWQfSFtZ9qWe40+0=; b=Iv+3a9XHHQGhCvu6J6xzwhMPFBf0epK7LZyWnfH6g+U6QWdaMIuj1LmAMi7UMmKzuQ r1Tt+nQalHrDKqr1vp4M4mzoYPeHndzuS3RvO8Whn3fELkUPtz9TdpjGEBFG0/45Wtt1 aI/eU50Y7NKkBhiaVKQ98khknVlFKPzX+mGyBdvGAvhSbhFjSESPl28K49hOYmvDzcJw uX3BpA07aW3Va/7Sl+jkpTcU5woHY8+iT6YWN0HVqdhXlUrOrPqHothzD6E8a0okdMtn oy/bTW4LWphdC6zSKgSS+FgmxLdkyYp5Km2BhNQ4xjMPCwqBusVspoSF8+V4dJIKNdnK 6hIw== 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:cc; bh=rj/B/ZCdN9CLTsH8CHbxoGg8KIHKWQfSFtZ9qWe40+0=; b=SGh/N4FTQtCdWiOSFAYwBgABC/jSClmKAlwubr74jeROe0wI+i6nCz2qe3LjUSlo90 xoazydlHhvb8vX6Yko/e16A+ymu1QbQdy7KungIEMbngGQ/5dBTLEdhrytFIJiIV1QEY D4GlmV0BkK8qWKXyNhKMtXpUPRFDpV8YlyvqkP4T38kVsb3WQvUwRfu5ffkxHuZ3GHYR Y14R7+vnmfM/dzDWt6s/oOINCg4jyH40warEalNaMmnwnNrt9G6wP6gHBJ5RN1oyd6mj BBu/w1Kyx2rLbg1xLRxLJuS6LPKLbxVOLw6vYj0qcvjvE0mqZo8Q+1D294hBXghs185f Fwpw== X-Gm-Message-State: AHYfb5iD4VKuAoYnda2MrZ7J6Rjt0hE20elKCEeFfD8DVJmgSR39Aol3 ZH75wAw6jPgXbe2spCzewMaEk8o/Vg== X-Received: by 10.107.35.140 with SMTP id j134mr11530482ioj.94.1502395334250; Thu, 10 Aug 2017 13:02:14 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.19.225 with HTTP; Thu, 10 Aug 2017 13:02:13 -0700 (PDT) In-Reply-To: <8ebce8ed-5b3f-2b59-5b37-f6af7f3d4c2b@yandex.ru> References: <8ebce8ed-5b3f-2b59-5b37-f6af7f3d4c2b@yandex.ru> From: raichoo Date: Thu, 10 Aug 2017 22:02:13 +0200 Message-ID: Subject: Re: `ifconfig` patch to resolve IPv6 scope names To: "Andrey V. Elsukov" Cc: 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: Thu, 10 Aug 2017 20:02:17 -0000 Oh boy, should have read more code before posting that ^^. Thanks a lot for your feedback :) I've modified that patch to make it use the macros defined in in6.h. I'm also quite aware that this patch might be rejected since it might break script depending on `ifconfig` output. But it's a useful little learning experience anyway :) Kind regards, raichoo Here's the new iteration: diff --git a/sbin/ifconfig/af_inet6.c b/sbin/ifconfig/af_inet6.c index e93d94355e..e1d44395c9 100644 --- a/sbin/ifconfig/af_inet6.c +++ b/sbin/ifconfig/af_inet6.c @@ -167,6 +167,35 @@ setip6eui64(const char *cmd, int dummy __unused, int s, } static void +in6_addr_scope(const struct in6_addr *addr) +{ + if (IN6_IS_ADDR_LINKLOCAL(addr)) + printf("link-local "); + else if (IN6_IS_ADDR_SITELOCAL(addr)) + printf("site-local "); + else if (IN6_IS_ADDR_MULTICAST(addr)) { + printf("multicast "); + switch (__IPV6_ADDR_MC_SCOPE(addr)) { + case __IPV6_ADDR_SCOPE_NODELOCAL: + printf("node-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; + } + } +} + +static void in6_status(int s __unused, const struct ifaddrs *ifa) { struct sockaddr_in6 *sin, null_sin; @@ -272,6 +301,8 @@ in6_status(int s __unused, const struct ifaddrs *ifa) printf("scopeid 0x%x ", ((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id); + in6_addr_scope(&((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_addr); + if (ip6lifetime && (lifetime.ia6t_preferred || lifetime.ia6t_expire)) { printf("pltime "); if (lifetime.ia6t_preferred) {