Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 91700200D43 for ; Tue, 21 Nov 2017 17:43:42 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 90115160BFC; Tue, 21 Nov 2017 16:43:42 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D5CC2160BE3 for ; Tue, 21 Nov 2017 17:43:41 +0100 (CET) Received: (qmail 53725 invoked by uid 500); 21 Nov 2017 16:43:40 -0000 Mailing-List: contact dev-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Id: Delivered-To: mailing list dev@apr.apache.org Received: (qmail 53715 invoked by uid 99); 21 Nov 2017 16:43:40 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 21 Nov 2017 16:43:40 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 198EA1A24D2 for ; Tue, 21 Nov 2017 16:43:40 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.203 X-Spam-Level: X-Spam-Status: No, score=-4.203 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_HI=-5, RP_MATCHES_RCVD=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id QGLddkxSm8Dq for ; Tue, 21 Nov 2017 16:43:37 +0000 (UTC) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id ECF5860E3F for ; Tue, 21 Nov 2017 16:43:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 05A2A8047F for ; Tue, 21 Nov 2017 16:43:30 +0000 (UTC) Received: from latipes.manyfish.co.uk (ovpn-120-79.rdu2.redhat.com [10.10.120.79]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CCF325EE1E for ; Tue, 21 Nov 2017 16:43:29 +0000 (UTC) Received: from jorton by latipes.manyfish.co.uk with local (Exim 4.89) (envelope-from ) id 1eHBdr-0008Ax-FN for dev@apr.apache.org; Tue, 21 Nov 2017 16:43:23 +0000 Date: Tue, 21 Nov 2017 16:43:23 +0000 From: Joe Orton To: dev@apr.apache.org Subject: [RFC] apr_sockaddr_zone_set() Message-ID: <20171121164319.GA31194@redhat.com> Mail-Followup-To: dev@apr.apache.org MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="AhhlLboLdkugWU4S" Content-Disposition: inline User-Agent: Mutt/1.9.1 (2017-09-22) Organization: Registered in England and Wales under Company Registration No. 03798903 Directors: Michael Cunningham (US), Michael O'Neill (Ireland), Paul Argiry (US) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 21 Nov 2017 16:43:30 +0000 (UTC) archived-at: Tue, 21 Nov 2017 16:43:42 -0000 --AhhlLboLdkugWU4S Content-Type: text/plain; charset=utf-8 Content-Disposition: inline This adds support for mapping scope/zone names to interface IDs for IPv6 link-local addresses. Not sure if scope or zone is the better term to use here, any opinions? Could s/_zone_/_scope_/g easily enough. Google suggests Windows supports if_nametoindex too, so the API should be portable, though I don't know about other platforms. Regards, Joe --AhhlLboLdkugWU4S Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename="apr_scope.diff" Index: include/apr_network_io.h =================================================================== --- include/apr_network_io.h (revision 1815933) +++ include/apr_network_io.h (working copy) @@ -441,6 +441,13 @@ const apr_sockaddr_t *src, apr_pool_t *p); +/* Set the zone of an IPv6 link-local address object. + * @param sa Socket address object + * @param zone_id Zone ID (textual "eth0" or numeric "3"). + */ +APR_DECLARE(apr_status_t) apr_sockaddr_zone_set(apr_sockaddr_t *sa, + const char *zone_id); + /** * Look up the host name from an apr_sockaddr_t. * @param hostname The hostname. Index: configure.in =================================================================== --- configure.in (revision 1815933) +++ configure.in (working copy) @@ -1069,7 +1069,9 @@ #endif";; esac -AC_CHECK_HEADERS([sys/types.h sys/mman.h sys/ipc.h sys/mutex.h sys/shm.h sys/file.h kernel/OS.h os2.h windows.h]) +AC_CHECK_HEADERS([sys/types.h sys/mman.h sys/ipc.h sys/mutex.h \ + sys/shm.h sys/file.h kernel/OS.h os2.h windows.h \ + net/if.h]) AC_CHECK_FUNCS([mmap munmap shm_open shm_unlink shmget shmat shmdt shmctl \ create_area mprotect]) @@ -2755,7 +2757,7 @@ AC_SEARCH_LIBS(getaddrinfo, socket inet6) AC_SEARCH_LIBS(gai_strerror, socket inet6) AC_SEARCH_LIBS(getnameinfo, socket inet6) -AC_CHECK_FUNCS(gai_strerror) +AC_CHECK_FUNCS(gai_strerror if_nametoindex) APR_CHECK_WORKING_GETADDRINFO APR_CHECK_NEGATIVE_EAI APR_CHECK_WORKING_GETNAMEINFO Index: network_io/unix/sockaddr.c =================================================================== --- network_io/unix/sockaddr.c (revision 1815933) +++ network_io/unix/sockaddr.c (working copy) @@ -25,6 +25,10 @@ #include #endif +#ifdef HAVE_NET_IF_H +#include +#endif + #define APR_WANT_STRFUNC #include "apr_want.h" @@ -1182,3 +1186,38 @@ #endif /* APR_HAVE_IPV6 */ return 0; /* no match */ } + +APR_DECLARE(apr_status_t) apr_sockaddr_zone_set(apr_sockaddr_t *sa, + const char *zone_id) +{ +#if !APR_HAVE_IPV6 || !defined(HAVE_IF_NAMETOINDEX) + return APR_ENOTIMPL; +#else + unsigned int idx; + + if (sa->family != APR_INET6) { + return APR_EBADIP; + } + + idx = if_nametoindex(zone_id); + if (idx) { + sa->sa.sin6.sin6_scope_id = idx; + return APR_SUCCESS; + } + + if (errno != ENODEV) { + return errno; + } + else { + char *endptr; + apr_int64_t i = apr_strtoi64(zone_id, &endptr, 10); + + if (*endptr != '\0' || errno || i < 1 || i > APR_INT16_MAX) { + return APR_EGENERAL; + } + + sa->sa.sin6.sin6_scope_id = i; + return APR_SUCCESS; + } +#endif +} --AhhlLboLdkugWU4S--