From patchwork Tue Sep 5 16:05:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?=C5=81ukasz_Stelmach?= X-Patchwork-Id: 810212 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-84190-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="G3YLe8ww"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xms5k2WWyz9ryk for ; Wed, 6 Sep 2017 02:06:18 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id :mime-version:content-type:content-transfer-encoding; q=dns; s= default; b=LATGUKVp2cacZIjAMtRGaHcLIjhaCjo4Oi4W75RJXALIza5bzhtI4 U2BGwRwhR+QYqg7bQdvG68oH7pTx2m5Xmymc6Ut/kxI/Oo9NdSYkj0ekAz0Dmy7h AFtqoGyf5E/44mbW26AStRFMvHBgei4j9xFdBY0GQ8Xm9ZjQvaGDh8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id :mime-version:content-type:content-transfer-encoding; s=default; bh=rI4yhwzt54HQSWa/GJfldh6YdmU=; b=G3YLe8wwHrxXYfQeWmYvQS4elU3G W6FKZswHzXBRqJtxlQh3xAcmNAGBC8Wvq8BROLsPy6GYQdiTfsAuAgdR/spqLwPV TlQi48ziMvW6S8mAtoLODlhD0r9AyZY2f35YBLMnDpOpixI0qcSgsVb1hMmRnWIB oGI4Z+4AzWrXhhI= Received: (qmail 116978 invoked by alias); 5 Sep 2017 16:06:11 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 116966 invoked by uid 89); 5 Sep 2017 16:06:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-6.9 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, SPF_PASS autolearn=ham version=3.3.2 spammy=nis, H*Ad:D*fm, H*Ad:D*poczta.fm, slight X-HELO: smtpo.poczta.interia.pl X-Interia-R: Interia X-Interia-R-IP: 89.64.33.181 X-Interia-R-Helo: From: =?utf-8?q?=C5=81ukasz_Stelmach?= To: libc-alpha@sourceware.org Cc: =?utf-8?q?=C5=81ukasz_Stelmach?= Subject: [RFC][PATCH 0/4][BZ 17083] Make getaddrinfo(3) return zone id from /etc/hosts for link-local IPv6 addresses Date: Tue, 5 Sep 2017 18:05:26 +0200 Message-Id: <20170905160530.19525-1-stlman@poczta.fm> MIME-Version: 1.0 X-Interia-Antivirus: OK X-IPL-POID: 4 X-IPL-SAS-SPAS: -0.6 X-IPL-SAS-UREP: 0 X-IPL-SAS-UREP-PRIV: 0 X-IPL-Envelope-To: stlman@poczta.fm Hello, The aim of the following patches is to enable retrieving zone (interface) information stored in /etc/hosts along with link-local IPv6 addresses. This requires changes in several places in resolver and NSS. First the parse_line() function needs to detect the scope delimiter, parse what follows and find the network interface index, that later is going to be assigned to sin6_scope_id field of a sockaddr_in6 structure. The easiest way to do this is to use getaddrinfo(3) with AI_NUMERICHOST flag that prevents any DB queries. There is a slight mismatch in naming of variables. The field in the sockaddr_in6 structure is sin6_scope_id while I've decided to use in6_zone_id which better corresponds with the terms used in IPv6 related RFCs. If you think the term "scope" should be used instead of "zone", I am fine with it. When parsed, the zone information needs to be delivered to getaddrinfo(3). It calls NSS functions gethostbyname4_r, gethostbyname3_r and gethostbyname2_r. Only the first of them can return the information because it uses ritcher gaih_addrtupple structure instead of an old hostent. However, gethostname4_r is used only if ai_family hint is set to PF_UNSPEC. Which makes the whole API work weird a bit. With the following entries in /etc/hosts --8<---------------cut here---------------start------------->8--- 192.168.0.1 foo fe80::0203:04ff:fe05:0607%eth0 foo --8<---------------cut here---------------end--------------->8--- querying for AF_INET6 address of host foo won't return any results, which is counterintuitive if not plain wrong. The comment in getaddrinfo.c suggests, that getaddrinfo4_r should not be used unless ai_family is set to PF_UNSPEC, to avoid unnecessary DNS queries. The only way to solve the problem of less capable gethostbyname[23]_r and too verbose gethosbyname4_r is to introduce gethostbynamet5_r which accepts all the arguments of gethostbyname4_r AND an address family (af). So I renamed gethostbyname4_r to gethostbyname5_r and defined gethostbyname4_r as a wrapper for gethostbyname5_r in all four glibc NSS modlues (i.e. files, dns, nis and nisplus). gethostbyname5_r passes the af argument to respective underlying "parsers". Unfotunately I was unable to test NIS/NIS+ modules, so please do it for me. The last bit is to make getaddrinfo(3) call gethostbyname5_r. In theory, with the new function in place, all other code paths are unnecessary. However, as I understand, different non-glibc NSS modules provide different sets of functions so I've left the code paths intact. Ɓukasz Stelmach (4): getaddrinfo: Add comments for #else and #endif directives NSS: Parse zone identifier of IPv6 addresses in /etc/hosts NSS: Introduce gethostbyname5_r function getaddrinfo: Use the new getaddrinfo5_r NSS function nis/Versions | 3 +- nis/nss_nis/nis-hosts.c | 13 ++++++-- nis/nss_nisplus/nisplus-hosts.c | 13 ++++++-- nss/Versions | 1 + nss/nss_files/files-hosts.c | 66 +++++++++++++++++++++++++++++++++++------ resolv/Versions | 2 +- resolv/nss_dns/dns-host.c | 32 ++++++++++++++++++-- sysdeps/posix/getaddrinfo.c | 54 ++++++++++++++++++++------------- 8 files changed, 146 insertions(+), 38 deletions(-)