2016-05-12 08:39:29 +00:00
|
|
|
/* Host and service name lookups using Name Service Switch modules.
|
2023-01-06 21:08:04 +00:00
|
|
|
Copyright (C) 1996-2023 Free Software Foundation, Inc.
|
2016-05-12 08:39:29 +00:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with the GNU C Library; if not, see
|
Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:
sed -ri '
s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
$(find $(git ls-files) -prune -type f \
! -name '*.po' \
! -name 'ChangeLog*' \
! -path COPYING ! -path COPYING.LIB \
! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
! -path manual/texinfo.tex ! -path scripts/config.guess \
! -path scripts/config.sub ! -path scripts/install-sh \
! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
! -path INSTALL ! -path locale/programs/charmap-kw.h \
! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
! '(' -name configure \
-execdir test -f configure.ac -o -f configure.in ';' ')' \
! '(' -name preconfigure \
-execdir test -f preconfigure.ac ';' ')' \
-print)
and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:
chmod a+x sysdeps/unix/sysv/linux/riscv/configure
# Omit irrelevant whitespace and comment-only changes,
# perhaps from a slightly-different Autoconf version.
git checkout -f \
sysdeps/csky/configure \
sysdeps/hppa/configure \
sysdeps/riscv/configure \
sysdeps/unix/sysv/linux/csky/configure
# Omit changes that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
git checkout -f \
sysdeps/powerpc/powerpc64/ppc-mcount.S \
sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
# Omit change that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 05:40:42 +00:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
2016-05-12 08:39:29 +00:00
|
|
|
|
1996-10-21 01:26:31 +00:00
|
|
|
/* The Inner Net License, Version 2.00
|
|
|
|
|
|
|
|
The author(s) grant permission for redistribution and use in source and
|
|
|
|
binary forms, with or without modification, of the software and documentation
|
|
|
|
provided that the following conditions are met:
|
|
|
|
|
|
|
|
0. If you receive a version of the software that is specifically labelled
|
|
|
|
as not being for redistribution (check the version message and/or README),
|
|
|
|
you are not permitted to redistribute that version of the software in any
|
|
|
|
way or form.
|
|
|
|
1. All terms of the all other applicable copyrights and licenses must be
|
|
|
|
followed.
|
|
|
|
2. Redistributions of source code must retain the authors' copyright
|
|
|
|
notice(s), this list of conditions, and the following disclaimer.
|
|
|
|
3. Redistributions in binary form must reproduce the authors' copyright
|
|
|
|
notice(s), this list of conditions, and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
2002-07-06 06:36:39 +00:00
|
|
|
4. [The copyright holder has authorized the removal of this clause.]
|
1996-10-21 01:26:31 +00:00
|
|
|
5. Neither the name(s) of the author(s) nor the names of its contributors
|
|
|
|
may be used to endorse or promote products derived from this software
|
|
|
|
without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY ITS AUTHORS AND CONTRIBUTORS ``AS IS'' AND ANY
|
|
|
|
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY
|
|
|
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
|
|
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
If these license terms cause you a real problem, contact the author. */
|
|
|
|
|
|
|
|
/* This software is Copyright 1996 by Craig Metz, All Rights Reserved. */
|
|
|
|
|
2000-03-23 21:34:58 +00:00
|
|
|
#include <assert.h>
|
2006-05-04 06:38:07 +00:00
|
|
|
#include <ctype.h>
|
2000-03-23 21:34:58 +00:00
|
|
|
#include <errno.h>
|
2003-04-24 23:45:17 +00:00
|
|
|
#include <ifaddrs.h>
|
2000-03-23 21:34:58 +00:00
|
|
|
#include <netdb.h>
|
2008-05-10 23:27:39 +00:00
|
|
|
#include <nss.h>
|
2016-10-04 09:52:10 +00:00
|
|
|
#include <resolv/resolv-internal.h>
|
2017-06-30 19:10:23 +00:00
|
|
|
#include <resolv/resolv_context.h>
|
2003-04-25 17:54:19 +00:00
|
|
|
#include <stdbool.h>
|
2000-03-23 21:34:58 +00:00
|
|
|
#include <stdio.h>
|
2006-05-04 06:38:07 +00:00
|
|
|
#include <stdio_ext.h>
|
1996-10-21 01:26:31 +00:00
|
|
|
#include <stdlib.h>
|
2000-03-23 21:34:58 +00:00
|
|
|
#include <string.h>
|
2013-05-01 15:46:34 +00:00
|
|
|
#include <stdint.h>
|
2000-03-23 21:34:58 +00:00
|
|
|
#include <arpa/inet.h>
|
2006-05-04 06:38:07 +00:00
|
|
|
#include <net/if.h>
|
2004-12-22 20:10:10 +00:00
|
|
|
#include <netinet/in.h>
|
2006-05-04 06:38:07 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/stat.h>
|
2000-03-23 21:34:58 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/un.h>
|
|
|
|
#include <sys/utsname.h>
|
2006-05-04 06:38:07 +00:00
|
|
|
#include <unistd.h>
|
2002-11-20 19:48:07 +00:00
|
|
|
#include <nsswitch.h>
|
2015-09-08 21:11:03 +00:00
|
|
|
#include <libc-lock.h>
|
2003-11-18 07:04:13 +00:00
|
|
|
#include <not-cancel.h>
|
2004-09-15 08:25:49 +00:00
|
|
|
#include <nscd/nscd-client.h>
|
2004-09-16 22:54:54 +00:00
|
|
|
#include <nscd/nscd_proto.h>
|
2016-05-12 08:39:29 +00:00
|
|
|
#include <scratch_buffer.h>
|
2016-09-15 13:46:30 +00:00
|
|
|
#include <inet/net-internal.h>
|
1997-02-19 04:43:53 +00:00
|
|
|
|
2018-05-23 13:26:19 +00:00
|
|
|
/* Former AI_IDN_ALLOW_UNASSIGNED and AI_IDN_USE_STD3_ASCII_RULES
|
|
|
|
flags, now ignored. */
|
|
|
|
#define DEPRECATED_AI_IDN 0x300
|
2004-03-08 04:10:31 +00:00
|
|
|
|
2018-02-15 20:57:15 +00:00
|
|
|
#if IS_IN (libc)
|
|
|
|
# define feof_unlocked(fp) __feof_unlocked (fp)
|
|
|
|
#endif
|
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
struct gaih_service
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
int num;
|
|
|
|
};
|
1996-10-21 01:26:31 +00:00
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
struct gaih_servtuple
|
|
|
|
{
|
|
|
|
int socktype;
|
|
|
|
int protocol;
|
|
|
|
int port;
|
2022-02-10 07:57:11 +00:00
|
|
|
bool set;
|
1997-08-20 03:53:21 +00:00
|
|
|
};
|
1996-10-21 01:26:31 +00:00
|
|
|
|
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
struct gaih_typeproto
|
|
|
|
{
|
|
|
|
int socktype;
|
|
|
|
int protocol;
|
2008-05-14 17:33:37 +00:00
|
|
|
uint8_t protoflag;
|
|
|
|
bool defaultflag;
|
|
|
|
char name[8];
|
1997-08-20 03:53:21 +00:00
|
|
|
};
|
1996-10-21 01:26:31 +00:00
|
|
|
|
2022-03-07 08:38:51 +00:00
|
|
|
struct gaih_result
|
|
|
|
{
|
|
|
|
struct gaih_addrtuple *at;
|
|
|
|
char *canon;
|
2022-03-04 09:27:12 +00:00
|
|
|
bool free_at;
|
2022-03-07 10:23:45 +00:00
|
|
|
bool got_ipv6;
|
2022-03-07 08:38:51 +00:00
|
|
|
};
|
|
|
|
|
2000-01-05 21:32:20 +00:00
|
|
|
/* Values for `protoflag'. */
|
|
|
|
#define GAI_PROTO_NOSERVICE 1
|
2000-11-10 04:15:55 +00:00
|
|
|
#define GAI_PROTO_PROTOANY 2
|
2000-01-05 21:32:20 +00:00
|
|
|
|
2001-01-21 19:30:28 +00:00
|
|
|
static const struct gaih_typeproto gaih_inet_typeproto[] =
|
1997-08-20 03:53:21 +00:00
|
|
|
{
|
2008-05-14 17:33:37 +00:00
|
|
|
{ 0, 0, 0, false, "" },
|
|
|
|
{ SOCK_STREAM, IPPROTO_TCP, 0, true, "tcp" },
|
|
|
|
{ SOCK_DGRAM, IPPROTO_UDP, 0, true, "udp" },
|
|
|
|
#if defined SOCK_DCCP && defined IPPROTO_DCCP
|
|
|
|
{ SOCK_DCCP, IPPROTO_DCCP, 0, false, "dccp" },
|
|
|
|
#endif
|
|
|
|
#ifdef IPPROTO_UDPLITE
|
|
|
|
{ SOCK_DGRAM, IPPROTO_UDPLITE, 0, false, "udplite" },
|
2008-05-14 17:55:57 +00:00
|
|
|
#endif
|
|
|
|
#ifdef IPPROTO_SCTP
|
|
|
|
{ SOCK_STREAM, IPPROTO_SCTP, 0, false, "sctp" },
|
|
|
|
{ SOCK_SEQPACKET, IPPROTO_SCTP, 0, false, "sctp" },
|
2008-05-14 17:33:37 +00:00
|
|
|
#endif
|
|
|
|
{ SOCK_RAW, 0, GAI_PROTO_PROTOANY|GAI_PROTO_NOSERVICE, true, "raw" },
|
|
|
|
{ 0, 0, 0, false, "" }
|
1996-10-21 01:26:31 +00:00
|
|
|
};
|
|
|
|
|
2001-01-21 19:30:28 +00:00
|
|
|
static const struct addrinfo default_hints =
|
2003-04-24 23:45:17 +00:00
|
|
|
{
|
|
|
|
.ai_flags = AI_DEFAULT,
|
|
|
|
.ai_family = PF_UNSPEC,
|
|
|
|
.ai_socktype = 0,
|
|
|
|
.ai_protocol = 0,
|
|
|
|
.ai_addrlen = 0,
|
|
|
|
.ai_addr = NULL,
|
|
|
|
.ai_canonname = NULL,
|
|
|
|
.ai_next = NULL
|
|
|
|
};
|
1997-08-20 03:53:21 +00:00
|
|
|
|
2022-03-07 10:26:22 +00:00
|
|
|
static void
|
|
|
|
gaih_result_reset (struct gaih_result *res)
|
|
|
|
{
|
|
|
|
if (res->free_at)
|
|
|
|
free (res->at);
|
|
|
|
free (res->canon);
|
|
|
|
memset (res, 0, sizeof (*res));
|
|
|
|
}
|
1997-08-20 03:53:21 +00:00
|
|
|
|
|
|
|
static int
|
2001-01-21 19:30:28 +00:00
|
|
|
gaih_inet_serv (const char *servicename, const struct gaih_typeproto *tp,
|
2016-05-12 08:39:29 +00:00
|
|
|
const struct addrinfo *req, struct gaih_servtuple *st,
|
|
|
|
struct scratch_buffer *tmpbuf)
|
1996-10-21 01:26:31 +00:00
|
|
|
{
|
|
|
|
struct servent *s;
|
1997-03-29 17:32:35 +00:00
|
|
|
struct servent ts;
|
1997-08-20 03:53:21 +00:00
|
|
|
int r;
|
|
|
|
|
|
|
|
do
|
1997-03-29 17:32:35 +00:00
|
|
|
{
|
2016-05-12 08:39:29 +00:00
|
|
|
r = __getservbyname_r (servicename, tp->name, &ts,
|
|
|
|
tmpbuf->data, tmpbuf->length, &s);
|
1999-09-12 19:24:42 +00:00
|
|
|
if (r != 0 || s == NULL)
|
1997-03-29 17:32:35 +00:00
|
|
|
{
|
1999-09-12 19:24:42 +00:00
|
|
|
if (r == ERANGE)
|
2016-05-12 08:39:29 +00:00
|
|
|
{
|
|
|
|
if (!scratch_buffer_grow (tmpbuf))
|
|
|
|
return -EAI_MEMORY;
|
|
|
|
}
|
1997-08-20 03:53:21 +00:00
|
|
|
else
|
2013-12-02 14:53:13 +00:00
|
|
|
return -EAI_SERVICE;
|
1997-03-29 17:32:35 +00:00
|
|
|
}
|
|
|
|
}
|
1997-08-20 03:53:21 +00:00
|
|
|
while (r);
|
1997-03-29 17:32:35 +00:00
|
|
|
|
1999-05-02 21:03:32 +00:00
|
|
|
st->socktype = tp->socktype;
|
2000-11-10 04:15:55 +00:00
|
|
|
st->protocol = ((tp->protoflag & GAI_PROTO_PROTOANY)
|
|
|
|
? req->ai_protocol : tp->protocol);
|
1999-05-02 21:03:32 +00:00
|
|
|
st->port = s->s_port;
|
2022-02-10 07:57:11 +00:00
|
|
|
st->set = true;
|
1996-10-21 01:26:31 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-03-03 17:37:42 +00:00
|
|
|
/* Convert struct hostent to a list of struct gaih_addrtuple objects. h_name
|
|
|
|
is not copied, and the struct hostent object must not be deallocated
|
2022-03-07 10:26:22 +00:00
|
|
|
prematurely. The new addresses are appended to the tuple array in RES. */
|
2016-04-29 08:35:34 +00:00
|
|
|
static bool
|
2022-03-07 10:26:22 +00:00
|
|
|
convert_hostent_to_gaih_addrtuple (const struct addrinfo *req, int family,
|
|
|
|
struct hostent *h, struct gaih_result *res)
|
2016-04-29 08:35:34 +00:00
|
|
|
{
|
|
|
|
/* Count the number of addresses in h->h_addr_list. */
|
|
|
|
size_t count = 0;
|
|
|
|
for (char **p = h->h_addr_list; *p != NULL; ++p)
|
|
|
|
++count;
|
|
|
|
|
|
|
|
/* Report no data if no addresses are available, or if the incoming
|
|
|
|
address size is larger than what we can store. */
|
|
|
|
if (count == 0 || h->h_length > sizeof (((struct gaih_addrtuple) {}).addr))
|
|
|
|
return true;
|
|
|
|
|
2022-03-07 10:26:22 +00:00
|
|
|
struct gaih_addrtuple *array = res->at;
|
2022-03-03 17:37:42 +00:00
|
|
|
size_t old = 0;
|
|
|
|
|
|
|
|
while (array != NULL)
|
|
|
|
{
|
|
|
|
old++;
|
|
|
|
array = array->next;
|
|
|
|
}
|
|
|
|
|
2022-03-07 10:26:22 +00:00
|
|
|
array = realloc (res->at, (old + count) * sizeof (*array));
|
2022-03-03 17:37:42 +00:00
|
|
|
|
2016-04-29 08:35:34 +00:00
|
|
|
if (array == NULL)
|
|
|
|
return false;
|
|
|
|
|
2022-03-07 10:26:22 +00:00
|
|
|
res->got_ipv6 = family == AF_INET6;
|
|
|
|
res->at = array;
|
|
|
|
res->free_at = true;
|
2022-03-03 17:37:42 +00:00
|
|
|
|
|
|
|
/* Update the next pointers on reallocation. */
|
|
|
|
for (size_t i = 0; i < old; i++)
|
|
|
|
array[i].next = array + i + 1;
|
|
|
|
|
|
|
|
array += old;
|
|
|
|
|
|
|
|
memset (array, 0, count * sizeof (*array));
|
|
|
|
|
2016-04-29 08:35:34 +00:00
|
|
|
for (size_t i = 0; i < count; ++i)
|
|
|
|
{
|
|
|
|
if (family == AF_INET && req->ai_family == AF_INET6)
|
|
|
|
{
|
|
|
|
/* Perform address mapping. */
|
|
|
|
array[i].family = AF_INET6;
|
|
|
|
memcpy(array[i].addr + 3, h->h_addr_list[i], sizeof (uint32_t));
|
|
|
|
array[i].addr[2] = htonl (0xffff);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
array[i].family = family;
|
|
|
|
memcpy (array[i].addr, h->h_addr_list[i], h->h_length);
|
|
|
|
}
|
|
|
|
array[i].next = array + i + 1;
|
|
|
|
}
|
|
|
|
array[0].name = h->h_name;
|
|
|
|
array[count - 1].next = NULL;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-03-07 14:18:48 +00:00
|
|
|
static int
|
|
|
|
gethosts (nss_gethostbyname3_r fct, int family, const char *name,
|
|
|
|
const struct addrinfo *req, struct scratch_buffer *tmpbuf,
|
|
|
|
struct gaih_result *res, enum nss_status *statusp, int *no_datap)
|
|
|
|
{
|
|
|
|
struct hostent th;
|
|
|
|
char *localcanon = NULL;
|
|
|
|
enum nss_status status;
|
|
|
|
|
|
|
|
*no_datap = 0;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
*statusp = status = DL_CALL_FCT (fct, (name, family, &th,
|
|
|
|
tmpbuf->data, tmpbuf->length,
|
|
|
|
&errno, &h_errno, NULL,
|
|
|
|
&localcanon));
|
|
|
|
if (status != NSS_STATUS_TRYAGAIN || h_errno != NETDB_INTERNAL
|
|
|
|
|| errno != ERANGE)
|
|
|
|
break;
|
|
|
|
if (!scratch_buffer_grow (tmpbuf))
|
|
|
|
return -EAI_MEMORY;
|
|
|
|
}
|
|
|
|
if (status == NSS_STATUS_NOTFOUND
|
|
|
|
|| status == NSS_STATUS_TRYAGAIN || status == NSS_STATUS_UNAVAIL)
|
|
|
|
{
|
|
|
|
if (h_errno == NETDB_INTERNAL)
|
|
|
|
return -EAI_SYSTEM;
|
|
|
|
if (h_errno == TRY_AGAIN)
|
|
|
|
*no_datap = EAI_AGAIN;
|
|
|
|
else
|
|
|
|
*no_datap = h_errno == NO_DATA;
|
|
|
|
}
|
|
|
|
else if (status == NSS_STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
if (!convert_hostent_to_gaih_addrtuple (req, family, &th, res))
|
2022-03-02 06:15:29 +00:00
|
|
|
return -EAI_MEMORY;
|
2022-03-07 14:18:48 +00:00
|
|
|
|
|
|
|
if (localcanon != NULL && res->canon == NULL)
|
|
|
|
{
|
|
|
|
char *canonbuf = __strdup (localcanon);
|
|
|
|
if (canonbuf == NULL)
|
2022-03-02 06:15:29 +00:00
|
|
|
return -EAI_MEMORY;
|
2022-03-07 14:18:48 +00:00
|
|
|
res->canon = canonbuf;
|
|
|
|
}
|
|
|
|
}
|
2002-11-20 19:48:07 +00:00
|
|
|
|
2022-03-07 14:18:48 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2004-08-15 20:23:40 +00:00
|
|
|
|
2017-06-02 12:54:56 +00:00
|
|
|
/* This function is called if a canonical name is requested, but if
|
|
|
|
the service function did not provide it. It tries to obtain the
|
|
|
|
name using getcanonname_r from the same service NIP. If the name
|
|
|
|
cannot be canonicalized, return a copy of NAME. Return NULL on
|
|
|
|
memory allocation failure. The returned string is allocated on the
|
|
|
|
heap; the caller has to free it. */
|
|
|
|
static char *
|
2020-11-10 03:09:34 +00:00
|
|
|
getcanonname (nss_action_list nip, struct gaih_addrtuple *at, const char *name)
|
2017-06-02 12:54:56 +00:00
|
|
|
{
|
2020-02-12 14:27:37 +00:00
|
|
|
nss_getcanonname_r *cfct = __nss_lookup_function (nip, "getcanonname_r");
|
2017-06-02 12:54:56 +00:00
|
|
|
char *s = (char *) name;
|
|
|
|
if (cfct != NULL)
|
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
if (DL_CALL_FCT (cfct, (at->name ?: name, buf, sizeof (buf),
|
2017-09-01 06:57:07 +00:00
|
|
|
&s, &errno, &h_errno)) != NSS_STATUS_SUCCESS)
|
2017-06-02 12:54:56 +00:00
|
|
|
/* If the canonical name cannot be determined, use the passed
|
|
|
|
string. */
|
|
|
|
s = (char *) name;
|
|
|
|
}
|
2017-06-02 14:35:13 +00:00
|
|
|
return __strdup (name);
|
2017-06-02 12:54:56 +00:00
|
|
|
}
|
2006-04-16 21:34:32 +00:00
|
|
|
|
2022-03-07 16:47:36 +00:00
|
|
|
/* Process looked up canonical name and if necessary, decode to IDNA. Result
|
|
|
|
is a new string written to CANONP and the earlier string is freed. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
process_canonname (const struct addrinfo *req, const char *orig_name,
|
2022-03-07 08:38:51 +00:00
|
|
|
struct gaih_result *res)
|
2022-03-07 16:47:36 +00:00
|
|
|
{
|
2022-03-07 08:38:51 +00:00
|
|
|
char *canon = res->canon;
|
2022-03-07 16:47:36 +00:00
|
|
|
|
|
|
|
if ((req->ai_flags & AI_CANONNAME) != 0)
|
|
|
|
{
|
|
|
|
bool do_idn = req->ai_flags & AI_CANONIDN;
|
|
|
|
if (do_idn)
|
|
|
|
{
|
|
|
|
char *out;
|
|
|
|
int rc = __idna_from_dns_encoding (canon ?: orig_name, &out);
|
|
|
|
if (rc == 0)
|
|
|
|
{
|
|
|
|
free (canon);
|
|
|
|
canon = out;
|
|
|
|
}
|
|
|
|
else if (rc == EAI_IDN_ENCODE)
|
|
|
|
/* Use the punycode name as a fallback. */
|
|
|
|
do_idn = false;
|
|
|
|
else
|
|
|
|
return -rc;
|
|
|
|
}
|
|
|
|
if (!do_idn && canon == NULL && (canon = __strdup (orig_name)) == NULL)
|
|
|
|
return -EAI_MEMORY;
|
|
|
|
}
|
|
|
|
|
2022-03-07 08:38:51 +00:00
|
|
|
res->canon = canon;
|
2022-03-07 16:47:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
static int
|
2022-02-10 07:57:11 +00:00
|
|
|
get_servtuples (const struct gaih_service *service, const struct addrinfo *req,
|
|
|
|
struct gaih_servtuple *st, struct scratch_buffer *tmpbuf)
|
1996-10-21 01:26:31 +00:00
|
|
|
{
|
2022-02-10 07:57:11 +00:00
|
|
|
int i;
|
2001-01-21 19:30:28 +00:00
|
|
|
const struct gaih_typeproto *tp = gaih_inet_typeproto;
|
1996-10-21 01:26:31 +00:00
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
if (req->ai_protocol || req->ai_socktype)
|
|
|
|
{
|
2000-01-05 21:32:20 +00:00
|
|
|
++tp;
|
|
|
|
|
2001-02-02 08:24:56 +00:00
|
|
|
while (tp->name[0]
|
2000-01-18 09:56:22 +00:00
|
|
|
&& ((req->ai_socktype != 0 && req->ai_socktype != tp->socktype)
|
|
|
|
|| (req->ai_protocol != 0
|
2000-11-10 04:15:55 +00:00
|
|
|
&& !(tp->protoflag & GAI_PROTO_PROTOANY)
|
2000-01-18 09:56:22 +00:00
|
|
|
&& req->ai_protocol != tp->protocol)))
|
2000-01-05 21:32:20 +00:00
|
|
|
++tp;
|
|
|
|
|
2001-02-02 08:24:56 +00:00
|
|
|
if (! tp->name[0])
|
1998-09-09 11:53:19 +00:00
|
|
|
{
|
|
|
|
if (req->ai_socktype)
|
2013-12-02 14:53:13 +00:00
|
|
|
return -EAI_SOCKTYPE;
|
1998-09-09 11:53:19 +00:00
|
|
|
else
|
2013-12-02 14:53:13 +00:00
|
|
|
return -EAI_SERVICE;
|
1998-09-09 11:53:19 +00:00
|
|
|
}
|
1997-08-20 03:53:21 +00:00
|
|
|
}
|
|
|
|
|
2022-02-10 07:57:11 +00:00
|
|
|
if (service != NULL && (tp->protoflag & GAI_PROTO_NOSERVICE) != 0)
|
|
|
|
return -EAI_SERVICE;
|
|
|
|
|
|
|
|
if (service == NULL || service->num >= 0)
|
1997-08-20 03:53:21 +00:00
|
|
|
{
|
2022-02-10 07:57:11 +00:00
|
|
|
int port = service != NULL ? htons (service->num) : 0;
|
2000-01-05 21:32:20 +00:00
|
|
|
|
2022-02-10 07:57:11 +00:00
|
|
|
if (req->ai_socktype || req->ai_protocol)
|
1997-08-20 03:53:21 +00:00
|
|
|
{
|
2022-02-10 07:57:11 +00:00
|
|
|
st[0].socktype = tp->socktype;
|
|
|
|
st[0].protocol = ((tp->protoflag & GAI_PROTO_PROTOANY)
|
|
|
|
? req->ai_protocol : tp->protocol);
|
|
|
|
st[0].port = port;
|
|
|
|
st[0].set = true;
|
2000-01-18 09:56:22 +00:00
|
|
|
|
2022-02-10 07:57:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2000-01-18 09:56:22 +00:00
|
|
|
|
2022-02-10 07:57:11 +00:00
|
|
|
/* Neither socket type nor protocol is set. Return all socket types
|
|
|
|
we know about. */
|
|
|
|
for (i = 0, ++tp; tp->name[0]; ++tp)
|
|
|
|
if (tp->defaultflag)
|
|
|
|
{
|
|
|
|
st[i].socktype = tp->socktype;
|
|
|
|
st[i].protocol = tp->protocol;
|
|
|
|
st[i].port = port;
|
|
|
|
st[i++].set = true;
|
|
|
|
}
|
2000-09-29 05:29:24 +00:00
|
|
|
|
2022-02-10 07:57:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1999-05-02 21:03:32 +00:00
|
|
|
|
2022-02-10 07:57:11 +00:00
|
|
|
if (tp->name[0])
|
|
|
|
return gaih_inet_serv (service->name, tp, req, st, tmpbuf);
|
1999-05-02 21:03:32 +00:00
|
|
|
|
2022-02-10 07:57:11 +00:00
|
|
|
for (i = 0, tp++; tp->name[0]; tp++)
|
2000-09-29 05:29:24 +00:00
|
|
|
{
|
2022-02-10 07:57:11 +00:00
|
|
|
if ((tp->protoflag & GAI_PROTO_NOSERVICE) != 0)
|
|
|
|
continue;
|
2005-11-27 22:58:34 +00:00
|
|
|
|
2022-02-10 07:57:11 +00:00
|
|
|
if (req->ai_socktype != 0
|
|
|
|
&& req->ai_socktype != tp->socktype)
|
|
|
|
continue;
|
|
|
|
if (req->ai_protocol != 0
|
|
|
|
&& !(tp->protoflag & GAI_PROTO_PROTOANY)
|
|
|
|
&& req->ai_protocol != tp->protocol)
|
|
|
|
continue;
|
2008-05-14 17:33:37 +00:00
|
|
|
|
2022-02-10 07:57:11 +00:00
|
|
|
if (gaih_inet_serv (service->name,
|
|
|
|
tp, req, &st[i], tmpbuf) != 0)
|
|
|
|
continue;
|
2008-05-14 17:33:37 +00:00
|
|
|
|
2022-02-10 07:57:11 +00:00
|
|
|
i++;
|
2000-09-29 05:29:24 +00:00
|
|
|
}
|
1997-08-20 03:53:21 +00:00
|
|
|
|
2022-02-10 07:57:11 +00:00
|
|
|
if (!st[0].set)
|
|
|
|
return -EAI_SERVICE;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-03-07 10:23:45 +00:00
|
|
|
#ifdef USE_NSCD
|
|
|
|
/* Query addresses from nscd cache, returning a non-zero value on error.
|
|
|
|
RES members have the lookup result; RES->AT is NULL if there were no errors
|
|
|
|
but also no results. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
get_nscd_addresses (const char *name, const struct addrinfo *req,
|
|
|
|
struct gaih_result *res)
|
|
|
|
{
|
|
|
|
if (__nss_not_use_nscd_hosts > 0
|
|
|
|
&& ++__nss_not_use_nscd_hosts > NSS_NSCD_RETRY)
|
|
|
|
__nss_not_use_nscd_hosts = 0;
|
|
|
|
|
|
|
|
res->at = NULL;
|
|
|
|
|
|
|
|
if (__nss_not_use_nscd_hosts || __nss_database_custom[NSS_DBSIDX_hosts])
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Try to use nscd. */
|
|
|
|
struct nscd_ai_result *air = NULL;
|
|
|
|
int err = __nscd_getai (name, &air, &h_errno);
|
|
|
|
|
|
|
|
if (__glibc_unlikely (air == NULL))
|
|
|
|
{
|
|
|
|
/* The database contains a negative entry. */
|
|
|
|
if (err == 0)
|
|
|
|
return -EAI_NONAME;
|
|
|
|
if (__nss_not_use_nscd_hosts == 0)
|
|
|
|
{
|
|
|
|
if (h_errno == NETDB_INTERNAL && errno == ENOMEM)
|
|
|
|
return -EAI_MEMORY;
|
|
|
|
if (h_errno == TRY_AGAIN)
|
|
|
|
return -EAI_AGAIN;
|
|
|
|
return -EAI_SYSTEM;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Transform into gaih_addrtuple list. */
|
|
|
|
int result = 0;
|
|
|
|
char *addrs = air->addrs;
|
|
|
|
|
|
|
|
struct gaih_addrtuple *addrfree = calloc (air->naddrs, sizeof (*addrfree));
|
|
|
|
struct gaih_addrtuple *at = calloc (air->naddrs, sizeof (*at));
|
|
|
|
if (at == NULL)
|
|
|
|
{
|
|
|
|
result = -EAI_MEMORY;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
res->free_at = true;
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
for (int i = 0; i < air->naddrs; ++i)
|
|
|
|
{
|
|
|
|
socklen_t size = (air->family[i] == AF_INET
|
|
|
|
? INADDRSZ : IN6ADDRSZ);
|
|
|
|
|
|
|
|
if (!((air->family[i] == AF_INET
|
|
|
|
&& req->ai_family == AF_INET6
|
|
|
|
&& (req->ai_flags & AI_V4MAPPED) != 0)
|
|
|
|
|| req->ai_family == AF_UNSPEC
|
|
|
|
|| air->family[i] == req->ai_family))
|
|
|
|
{
|
|
|
|
/* Skip over non-matching result. */
|
|
|
|
addrs += size;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (air->family[i] == AF_INET && req->ai_family == AF_INET6
|
|
|
|
&& (req->ai_flags & AI_V4MAPPED))
|
|
|
|
{
|
|
|
|
at[count].family = AF_INET6;
|
|
|
|
at[count].addr[3] = *(uint32_t *) addrs;
|
|
|
|
at[count].addr[2] = htonl (0xffff);
|
|
|
|
}
|
|
|
|
else if (req->ai_family == AF_UNSPEC
|
2022-09-26 17:59:16 +00:00
|
|
|
|| air->family[i] == req->ai_family)
|
2022-03-07 10:23:45 +00:00
|
|
|
{
|
2022-09-26 17:59:16 +00:00
|
|
|
at[count].family = air->family[i];
|
2022-03-07 10:23:45 +00:00
|
|
|
memcpy (at[count].addr, addrs, size);
|
2022-09-26 17:59:16 +00:00
|
|
|
if (air->family[i] == AF_INET6)
|
2022-03-07 10:23:45 +00:00
|
|
|
res->got_ipv6 = true;
|
|
|
|
}
|
|
|
|
at[count].next = at + count + 1;
|
|
|
|
count++;
|
|
|
|
addrs += size;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((req->ai_flags & AI_CANONNAME) && air->canon != NULL)
|
|
|
|
{
|
|
|
|
char *canonbuf = __strdup (air->canon);
|
|
|
|
if (canonbuf == NULL)
|
|
|
|
{
|
|
|
|
result = -EAI_MEMORY;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
res->canon = canonbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count == 0)
|
|
|
|
{
|
|
|
|
result = -EAI_NONAME;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
at[count - 1].next = NULL;
|
|
|
|
|
|
|
|
res->at = at;
|
|
|
|
|
|
|
|
out:
|
|
|
|
free (air);
|
|
|
|
if (result != 0)
|
|
|
|
{
|
|
|
|
free (at);
|
|
|
|
res->free_at = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-03-07 10:26:22 +00:00
|
|
|
static int
|
|
|
|
get_nss_addresses (const char *name, const struct addrinfo *req,
|
|
|
|
struct scratch_buffer *tmpbuf, struct gaih_result *res)
|
|
|
|
{
|
|
|
|
int no_data = 0;
|
|
|
|
int no_inet6_data = 0;
|
|
|
|
nss_action_list nip;
|
|
|
|
enum nss_status inet6_status = NSS_STATUS_UNAVAIL;
|
|
|
|
enum nss_status status = NSS_STATUS_UNAVAIL;
|
|
|
|
int no_more;
|
|
|
|
struct resolv_context *res_ctx = NULL;
|
|
|
|
bool do_merge = false;
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
no_more = !__nss_database_get (nss_database_hosts, &nip);
|
|
|
|
|
|
|
|
/* If we are looking for both IPv4 and IPv6 address we don't
|
|
|
|
want the lookup functions to automatically promote IPv4
|
|
|
|
addresses to IPv6 addresses, so we use the no_inet6
|
|
|
|
function variant. */
|
|
|
|
res_ctx = __resolv_context_get ();
|
|
|
|
if (res_ctx == NULL)
|
|
|
|
no_more = 1;
|
|
|
|
|
|
|
|
while (!no_more)
|
|
|
|
{
|
|
|
|
/* Always start afresh; continue should discard previous results
|
|
|
|
and the hosts database does not support merge. */
|
|
|
|
gaih_result_reset (res);
|
|
|
|
|
|
|
|
if (do_merge)
|
|
|
|
{
|
|
|
|
__set_h_errno (NETDB_INTERNAL);
|
|
|
|
__set_errno (EBUSY);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
no_data = 0;
|
|
|
|
nss_gethostbyname4_r *fct4 = NULL;
|
|
|
|
|
|
|
|
/* gethostbyname4_r sends out parallel A and AAAA queries and
|
|
|
|
is thus only suitable for PF_UNSPEC. */
|
|
|
|
if (req->ai_family == PF_UNSPEC)
|
|
|
|
fct4 = __nss_lookup_function (nip, "gethostbyname4_r");
|
|
|
|
|
|
|
|
if (fct4 != NULL)
|
|
|
|
{
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
status = DL_CALL_FCT (fct4, (name, &res->at,
|
|
|
|
tmpbuf->data, tmpbuf->length,
|
|
|
|
&errno, &h_errno,
|
|
|
|
NULL));
|
|
|
|
if (status == NSS_STATUS_SUCCESS)
|
|
|
|
break;
|
|
|
|
/* gethostbyname4_r may write into AT, so reset it. */
|
|
|
|
res->at = NULL;
|
|
|
|
if (status != NSS_STATUS_TRYAGAIN
|
|
|
|
|| errno != ERANGE || h_errno != NETDB_INTERNAL)
|
|
|
|
{
|
|
|
|
if (h_errno == TRY_AGAIN)
|
|
|
|
no_data = EAI_AGAIN;
|
|
|
|
else
|
|
|
|
no_data = h_errno == NO_DATA;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!scratch_buffer_grow (tmpbuf))
|
|
|
|
{
|
|
|
|
__resolv_context_put (res_ctx);
|
|
|
|
result = -EAI_MEMORY;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status == NSS_STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
assert (!no_data);
|
|
|
|
no_data = 1;
|
|
|
|
|
|
|
|
if ((req->ai_flags & AI_CANONNAME) != 0 && res->canon == NULL)
|
|
|
|
{
|
|
|
|
char *canonbuf = __strdup (res->at->name);
|
|
|
|
if (canonbuf == NULL)
|
|
|
|
{
|
|
|
|
__resolv_context_put (res_ctx);
|
|
|
|
result = -EAI_MEMORY;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
res->canon = canonbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct gaih_addrtuple **pat = &res->at;
|
|
|
|
|
|
|
|
while (*pat != NULL)
|
|
|
|
{
|
|
|
|
if ((*pat)->family == AF_INET
|
|
|
|
&& req->ai_family == AF_INET6
|
|
|
|
&& (req->ai_flags & AI_V4MAPPED) != 0)
|
|
|
|
{
|
|
|
|
uint32_t *pataddr = (*pat)->addr;
|
|
|
|
(*pat)->family = AF_INET6;
|
|
|
|
pataddr[3] = pataddr[0];
|
|
|
|
pataddr[2] = htonl (0xffff);
|
|
|
|
pataddr[1] = 0;
|
|
|
|
pataddr[0] = 0;
|
|
|
|
pat = &((*pat)->next);
|
|
|
|
no_data = 0;
|
|
|
|
}
|
|
|
|
else if (req->ai_family == AF_UNSPEC
|
|
|
|
|| (*pat)->family == req->ai_family)
|
|
|
|
{
|
|
|
|
pat = &((*pat)->next);
|
|
|
|
|
|
|
|
no_data = 0;
|
|
|
|
if (req->ai_family == AF_INET6)
|
|
|
|
res->got_ipv6 = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*pat = ((*pat)->next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
no_inet6_data = no_data;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nss_gethostbyname3_r *fct = NULL;
|
|
|
|
if (req->ai_flags & AI_CANONNAME)
|
|
|
|
/* No need to use this function if we do not look for
|
|
|
|
the canonical name. The function does not exist in
|
|
|
|
all NSS modules and therefore the lookup would
|
|
|
|
often fail. */
|
|
|
|
fct = __nss_lookup_function (nip, "gethostbyname3_r");
|
|
|
|
if (fct == NULL)
|
|
|
|
/* We are cheating here. The gethostbyname2_r
|
|
|
|
function does not have the same interface as
|
|
|
|
gethostbyname3_r but the extra arguments the
|
|
|
|
latter takes are added at the end. So the
|
|
|
|
gethostbyname2_r code will just ignore them. */
|
|
|
|
fct = __nss_lookup_function (nip, "gethostbyname2_r");
|
|
|
|
|
|
|
|
if (fct != NULL)
|
|
|
|
{
|
|
|
|
if (req->ai_family == AF_INET6
|
|
|
|
|| req->ai_family == AF_UNSPEC)
|
|
|
|
{
|
2022-03-07 14:18:48 +00:00
|
|
|
if ((result = gethosts (fct, AF_INET6, name, req, tmpbuf,
|
|
|
|
res, &status, &no_data)) != 0)
|
|
|
|
{
|
|
|
|
__resolv_context_put (res_ctx);
|
|
|
|
goto out;
|
|
|
|
}
|
2022-03-07 10:26:22 +00:00
|
|
|
no_inet6_data = no_data;
|
|
|
|
inet6_status = status;
|
|
|
|
}
|
|
|
|
if (req->ai_family == AF_INET
|
|
|
|
|| req->ai_family == AF_UNSPEC
|
|
|
|
|| (req->ai_family == AF_INET6
|
|
|
|
&& (req->ai_flags & AI_V4MAPPED)
|
|
|
|
/* Avoid generating the mapped addresses if we
|
|
|
|
know we are not going to need them. */
|
|
|
|
&& ((req->ai_flags & AI_ALL) || !res->got_ipv6)))
|
|
|
|
{
|
2022-03-07 14:18:48 +00:00
|
|
|
if ((result = gethosts (fct, AF_INET, name, req, tmpbuf,
|
|
|
|
res, &status, &no_data)) != 0)
|
|
|
|
{
|
|
|
|
__resolv_context_put (res_ctx);
|
|
|
|
goto out;
|
|
|
|
}
|
2022-03-07 10:26:22 +00:00
|
|
|
|
|
|
|
if (req->ai_family == AF_INET)
|
|
|
|
{
|
|
|
|
no_inet6_data = no_data;
|
|
|
|
inet6_status = status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we found one address for AF_INET or AF_INET6,
|
|
|
|
don't continue the search. */
|
|
|
|
if (inet6_status == NSS_STATUS_SUCCESS
|
|
|
|
|| status == NSS_STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
if ((req->ai_flags & AI_CANONNAME) != 0
|
|
|
|
&& res->canon == NULL)
|
|
|
|
{
|
|
|
|
char *canonbuf = getcanonname (nip, res->at, name);
|
|
|
|
if (canonbuf == NULL)
|
|
|
|
{
|
|
|
|
__resolv_context_put (res_ctx);
|
|
|
|
result = -EAI_MEMORY;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
res->canon = canonbuf;
|
|
|
|
}
|
|
|
|
status = NSS_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* We can have different states for AF_INET and
|
|
|
|
AF_INET6. Try to find a useful one for both. */
|
|
|
|
if (inet6_status == NSS_STATUS_TRYAGAIN)
|
|
|
|
status = NSS_STATUS_TRYAGAIN;
|
|
|
|
else if (status == NSS_STATUS_UNAVAIL
|
|
|
|
&& inet6_status != NSS_STATUS_UNAVAIL)
|
|
|
|
status = inet6_status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Could not locate any of the lookup functions.
|
|
|
|
The NSS lookup code does not consistently set
|
|
|
|
errno, so we need to supply our own error
|
|
|
|
code here. The root cause could either be a
|
|
|
|
resource allocation failure, or a missing
|
|
|
|
service function in the DSO (so it should not
|
|
|
|
be listed in /etc/nsswitch.conf). Assume the
|
|
|
|
former, and return EBUSY. */
|
|
|
|
status = NSS_STATUS_UNAVAIL;
|
|
|
|
__set_h_errno (NETDB_INTERNAL);
|
|
|
|
__set_errno (EBUSY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nss_next_action (nip, status) == NSS_ACTION_RETURN)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* The hosts database does not support MERGE. */
|
|
|
|
if (nss_next_action (nip, status) == NSS_ACTION_MERGE)
|
|
|
|
do_merge = true;
|
|
|
|
|
|
|
|
nip++;
|
|
|
|
if (nip->module == NULL)
|
|
|
|
no_more = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
__resolv_context_put (res_ctx);
|
|
|
|
|
|
|
|
/* If we have a failure which sets errno, report it using
|
|
|
|
EAI_SYSTEM. */
|
|
|
|
if ((status == NSS_STATUS_TRYAGAIN || status == NSS_STATUS_UNAVAIL)
|
|
|
|
&& h_errno == NETDB_INTERNAL)
|
|
|
|
{
|
|
|
|
result = -EAI_SYSTEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (no_data != 0 && no_inet6_data != 0)
|
|
|
|
{
|
|
|
|
/* If both requests timed out report this. */
|
|
|
|
if (no_data == EAI_AGAIN && no_inet6_data == EAI_AGAIN)
|
|
|
|
result = -EAI_AGAIN;
|
|
|
|
else
|
|
|
|
/* We made requests but they turned out no data. The name
|
|
|
|
is known, though. */
|
|
|
|
result = -EAI_NODATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (result != 0)
|
|
|
|
gaih_result_reset (res);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-03-07 08:38:51 +00:00
|
|
|
/* Convert numeric addresses to binary into RES. On failure, RES->AT is set to
|
|
|
|
NULL and an error code is returned. If AI_NUMERIC_HOST is not requested and
|
|
|
|
the function cannot determine a result, RES->AT is set to NULL and 0
|
|
|
|
returned. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
text_to_binary_address (const char *name, const struct addrinfo *req,
|
|
|
|
struct gaih_result *res)
|
|
|
|
{
|
|
|
|
struct gaih_addrtuple *at = res->at;
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
assert (at != NULL);
|
|
|
|
|
|
|
|
memset (at->addr, 0, sizeof (at->addr));
|
|
|
|
if (__inet_aton_exact (name, (struct in_addr *) at->addr) != 0)
|
|
|
|
{
|
|
|
|
if (req->ai_family == AF_UNSPEC || req->ai_family == AF_INET)
|
|
|
|
at->family = AF_INET;
|
|
|
|
else if (req->ai_family == AF_INET6 && (req->ai_flags & AI_V4MAPPED))
|
|
|
|
{
|
|
|
|
at->addr[3] = at->addr[0];
|
|
|
|
at->addr[2] = htonl (0xffff);
|
|
|
|
at->addr[1] = 0;
|
|
|
|
at->addr[0] = 0;
|
|
|
|
at->family = AF_INET6;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = -EAI_ADDRFAMILY;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (req->ai_flags & AI_CANONNAME)
|
|
|
|
{
|
|
|
|
char *canonbuf = __strdup (name);
|
|
|
|
if (canonbuf == NULL)
|
|
|
|
{
|
|
|
|
result = -EAI_MEMORY;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
res->canon = canonbuf;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *scope_delim = strchr (name, SCOPE_DELIMITER);
|
|
|
|
int e;
|
|
|
|
|
|
|
|
if (scope_delim == NULL)
|
|
|
|
e = inet_pton (AF_INET6, name, at->addr);
|
|
|
|
else
|
|
|
|
e = __inet_pton_length (AF_INET6, name, scope_delim - name, at->addr);
|
|
|
|
|
|
|
|
if (e > 0)
|
|
|
|
{
|
|
|
|
if (req->ai_family == AF_UNSPEC || req->ai_family == AF_INET6)
|
|
|
|
at->family = AF_INET6;
|
|
|
|
else if (req->ai_family == AF_INET
|
|
|
|
&& IN6_IS_ADDR_V4MAPPED (at->addr))
|
|
|
|
{
|
|
|
|
at->addr[0] = at->addr[3];
|
|
|
|
at->family = AF_INET;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = -EAI_ADDRFAMILY;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scope_delim != NULL
|
|
|
|
&& __inet6_scopeid_pton ((struct in6_addr *) at->addr,
|
|
|
|
scope_delim + 1, &at->scopeid) != 0)
|
|
|
|
{
|
|
|
|
result = -EAI_NONAME;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (req->ai_flags & AI_CANONNAME)
|
|
|
|
{
|
|
|
|
char *canonbuf = __strdup (name);
|
|
|
|
if (canonbuf == NULL)
|
|
|
|
{
|
|
|
|
result = -EAI_MEMORY;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
res->canon = canonbuf;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((req->ai_flags & AI_NUMERICHOST))
|
|
|
|
result = -EAI_NONAME;
|
|
|
|
|
|
|
|
out:
|
|
|
|
res->at = NULL;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-03-04 09:27:12 +00:00
|
|
|
/* If possible, call the simple, old functions, which do not support IPv6 scope
|
|
|
|
ids, nor retrieving the canonical name. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
try_simple_gethostbyname (const char *name, const struct addrinfo *req,
|
|
|
|
struct scratch_buffer *tmpbuf,
|
|
|
|
struct gaih_result *res)
|
|
|
|
{
|
|
|
|
res->at = NULL;
|
|
|
|
|
|
|
|
if (req->ai_family != AF_INET || (req->ai_flags & AI_CANONNAME) != 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
int rc;
|
|
|
|
struct hostent th;
|
|
|
|
struct hostent *h;
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
rc = __gethostbyname2_r (name, AF_INET, &th, tmpbuf->data,
|
|
|
|
tmpbuf->length, &h, &h_errno);
|
|
|
|
if (rc != ERANGE || h_errno != NETDB_INTERNAL)
|
|
|
|
break;
|
|
|
|
if (!scratch_buffer_grow (tmpbuf))
|
|
|
|
return -EAI_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rc == 0)
|
|
|
|
{
|
|
|
|
if (h != NULL)
|
|
|
|
{
|
|
|
|
/* We found data, convert it. RES->AT from the conversion will
|
|
|
|
either be an allocated block or NULL, both of which are safe to
|
|
|
|
pass to free (). */
|
2022-03-07 10:26:22 +00:00
|
|
|
if (!convert_hostent_to_gaih_addrtuple (req, AF_INET, h, res))
|
2022-03-04 09:27:12 +00:00
|
|
|
return -EAI_MEMORY;
|
|
|
|
|
|
|
|
res->free_at = true;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (h_errno == NO_DATA)
|
|
|
|
return -EAI_NODATA;
|
|
|
|
|
|
|
|
return -EAI_NONAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (h_errno == NETDB_INTERNAL)
|
|
|
|
return -EAI_SYSTEM;
|
|
|
|
if (h_errno == TRY_AGAIN)
|
|
|
|
return -EAI_AGAIN;
|
|
|
|
|
|
|
|
/* We made requests but they turned out no data.
|
|
|
|
The name is known, though. */
|
|
|
|
return -EAI_NODATA;
|
|
|
|
}
|
|
|
|
|
2022-03-07 14:54:37 +00:00
|
|
|
/* Add local address information into RES. RES->AT is assumed to have enough
|
|
|
|
space for two tuples and is zeroed out. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
get_local_addresses (const struct addrinfo *req, struct gaih_result *res)
|
|
|
|
{
|
|
|
|
struct gaih_addrtuple *atr = res->at;
|
|
|
|
if (req->ai_family == AF_UNSPEC)
|
|
|
|
res->at->next = res->at + 1;
|
|
|
|
|
|
|
|
if (req->ai_family == AF_UNSPEC || req->ai_family == AF_INET6)
|
|
|
|
{
|
|
|
|
res->at->family = AF_INET6;
|
|
|
|
if ((req->ai_flags & AI_PASSIVE) == 0)
|
|
|
|
memcpy (res->at->addr, &in6addr_loopback, sizeof (struct in6_addr));
|
|
|
|
atr = res->at->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (req->ai_family == AF_UNSPEC || req->ai_family == AF_INET)
|
|
|
|
{
|
|
|
|
atr->family = AF_INET;
|
|
|
|
if ((req->ai_flags & AI_PASSIVE) == 0)
|
|
|
|
atr->addr[0] = htonl (INADDR_LOOPBACK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-07 15:08:31 +00:00
|
|
|
/* Generate results in PAI and its count in NADDRS. Return 0 on success or an
|
|
|
|
error code on failure. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
generate_addrinfo (const struct addrinfo *req, struct gaih_result *res,
|
|
|
|
const struct gaih_servtuple *st, struct addrinfo **pai,
|
|
|
|
unsigned int *naddrs)
|
|
|
|
{
|
|
|
|
size_t socklen;
|
|
|
|
sa_family_t family;
|
|
|
|
|
|
|
|
/* Buffer is the size of an unformatted IPv6 address in printable format. */
|
|
|
|
for (struct gaih_addrtuple *at = res->at; at != NULL; at = at->next)
|
|
|
|
{
|
|
|
|
family = at->family;
|
|
|
|
if (family == AF_INET6)
|
|
|
|
{
|
|
|
|
socklen = sizeof (struct sockaddr_in6);
|
|
|
|
|
|
|
|
/* If we looked up IPv4 mapped address discard them here if
|
|
|
|
the caller isn't interested in all address and we have
|
|
|
|
found at least one IPv6 address. */
|
|
|
|
if (res->got_ipv6
|
|
|
|
&& (req->ai_flags & (AI_V4MAPPED|AI_ALL)) == AI_V4MAPPED
|
|
|
|
&& IN6_IS_ADDR_V4MAPPED (at->addr))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
socklen = sizeof (struct sockaddr_in);
|
|
|
|
|
|
|
|
for (int i = 0; st[i].set; i++)
|
|
|
|
{
|
|
|
|
struct addrinfo *ai;
|
|
|
|
ai = *pai = malloc (sizeof (struct addrinfo) + socklen);
|
|
|
|
if (ai == NULL)
|
|
|
|
return -EAI_MEMORY;
|
|
|
|
|
|
|
|
ai->ai_flags = req->ai_flags;
|
|
|
|
ai->ai_family = family;
|
|
|
|
ai->ai_socktype = st[i].socktype;
|
|
|
|
ai->ai_protocol = st[i].protocol;
|
|
|
|
ai->ai_addrlen = socklen;
|
|
|
|
ai->ai_addr = (void *) (ai + 1);
|
|
|
|
|
|
|
|
/* We only add the canonical name once. */
|
|
|
|
ai->ai_canonname = res->canon;
|
|
|
|
res->canon = NULL;
|
|
|
|
|
|
|
|
#ifdef _HAVE_SA_LEN
|
|
|
|
ai->ai_addr->sa_len = socklen;
|
|
|
|
#endif /* _HAVE_SA_LEN */
|
|
|
|
ai->ai_addr->sa_family = family;
|
|
|
|
|
|
|
|
/* In case of an allocation error the list must be NULL
|
|
|
|
terminated. */
|
|
|
|
ai->ai_next = NULL;
|
|
|
|
|
|
|
|
if (family == AF_INET6)
|
|
|
|
{
|
|
|
|
struct sockaddr_in6 *sin6p = (struct sockaddr_in6 *) ai->ai_addr;
|
|
|
|
sin6p->sin6_port = st[i].port;
|
|
|
|
sin6p->sin6_flowinfo = 0;
|
|
|
|
memcpy (&sin6p->sin6_addr, at->addr, sizeof (struct in6_addr));
|
|
|
|
sin6p->sin6_scope_id = at->scopeid;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct sockaddr_in *sinp = (struct sockaddr_in *) ai->ai_addr;
|
|
|
|
sinp->sin_port = st[i].port;
|
|
|
|
memcpy (&sinp->sin_addr, at->addr, sizeof (struct in_addr));
|
|
|
|
memset (sinp->sin_zero, '\0', sizeof (sinp->sin_zero));
|
|
|
|
}
|
|
|
|
|
|
|
|
pai = &(ai->ai_next);
|
|
|
|
}
|
|
|
|
|
|
|
|
++*naddrs;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-02-10 07:57:11 +00:00
|
|
|
static int
|
|
|
|
gaih_inet (const char *name, const struct gaih_service *service,
|
|
|
|
const struct addrinfo *req, struct addrinfo **pai,
|
|
|
|
unsigned int *naddrs, struct scratch_buffer *tmpbuf)
|
|
|
|
{
|
|
|
|
struct gaih_servtuple st[sizeof (gaih_inet_typeproto)
|
|
|
|
/ sizeof (struct gaih_typeproto)] = {0};
|
|
|
|
|
|
|
|
const char *orig_name = name;
|
|
|
|
|
|
|
|
int rc;
|
|
|
|
if ((rc = get_servtuples (service, req, st, tmpbuf)) != 0)
|
|
|
|
return rc;
|
|
|
|
|
2011-05-21 03:46:03 +00:00
|
|
|
bool malloc_name = false;
|
|
|
|
struct gaih_addrtuple *addrmem = NULL;
|
|
|
|
int result = 0;
|
2016-05-12 08:39:29 +00:00
|
|
|
|
2022-03-07 08:38:51 +00:00
|
|
|
struct gaih_result res = {0};
|
2022-03-07 14:54:37 +00:00
|
|
|
struct gaih_addrtuple local_at[2] = {0};
|
|
|
|
|
|
|
|
res.at = local_at;
|
|
|
|
|
|
|
|
if (__glibc_unlikely (name == NULL))
|
1997-08-20 03:53:21 +00:00
|
|
|
{
|
2022-03-07 14:54:37 +00:00
|
|
|
get_local_addresses (req, &res);
|
|
|
|
goto process_list;
|
|
|
|
}
|
2004-03-08 04:10:31 +00:00
|
|
|
|
2022-03-07 14:54:37 +00:00
|
|
|
if (req->ai_flags & AI_IDN)
|
|
|
|
{
|
|
|
|
char *out;
|
|
|
|
result = __idna_to_dns_encoding (name, &out);
|
|
|
|
if (result != 0)
|
|
|
|
return -result;
|
|
|
|
name = out;
|
|
|
|
malloc_name = true;
|
|
|
|
}
|
2022-03-07 08:38:51 +00:00
|
|
|
|
2022-03-07 14:54:37 +00:00
|
|
|
if ((result = text_to_binary_address (name, req, &res)) != 0)
|
|
|
|
goto free_and_return;
|
|
|
|
else if (res.at != NULL)
|
|
|
|
goto process_list;
|
2022-03-07 08:38:51 +00:00
|
|
|
|
2022-03-07 14:54:37 +00:00
|
|
|
if ((result = try_simple_gethostbyname (name, req, tmpbuf, &res)) != 0)
|
|
|
|
goto free_and_return;
|
|
|
|
else if (res.at != NULL)
|
|
|
|
goto process_list;
|
2022-03-04 09:27:12 +00:00
|
|
|
|
2022-03-07 10:23:45 +00:00
|
|
|
#ifdef USE_NSCD
|
2022-03-07 14:54:37 +00:00
|
|
|
if ((result = get_nscd_addresses (name, req, &res)) != 0)
|
|
|
|
goto free_and_return;
|
|
|
|
else if (res.at != NULL)
|
|
|
|
goto process_list;
|
2022-03-07 10:23:45 +00:00
|
|
|
#endif
|
|
|
|
|
2022-03-07 14:54:37 +00:00
|
|
|
if ((result = get_nss_addresses (name, req, tmpbuf, &res)) != 0)
|
|
|
|
goto free_and_return;
|
|
|
|
else if (res.at != NULL)
|
|
|
|
goto process_list;
|
1997-08-20 03:53:21 +00:00
|
|
|
|
2022-03-07 14:54:37 +00:00
|
|
|
/* None of the lookups worked, so name not found. */
|
|
|
|
result = -EAI_NONAME;
|
|
|
|
goto free_and_return;
|
1997-02-19 04:43:53 +00:00
|
|
|
|
2022-03-07 10:26:22 +00:00
|
|
|
process_list:
|
2022-03-07 15:08:31 +00:00
|
|
|
/* Set up the canonical name if we need it. */
|
|
|
|
if ((result = process_canonname (req, orig_name, &res)) != 0)
|
|
|
|
goto free_and_return;
|
2005-11-27 23:13:21 +00:00
|
|
|
|
2022-03-07 15:08:31 +00:00
|
|
|
result = generate_addrinfo (req, &res, st, pai, naddrs);
|
2011-05-21 03:46:03 +00:00
|
|
|
|
2022-03-07 15:08:31 +00:00
|
|
|
free_and_return:
|
2011-05-21 03:46:03 +00:00
|
|
|
if (malloc_name)
|
|
|
|
free ((char *) name);
|
2017-05-11 08:01:49 +00:00
|
|
|
free (addrmem);
|
2022-03-04 09:27:12 +00:00
|
|
|
if (res.free_at)
|
|
|
|
free (res.at);
|
2022-03-07 08:38:51 +00:00
|
|
|
free (res.canon);
|
2011-05-21 03:46:03 +00:00
|
|
|
|
|
|
|
return result;
|
1996-10-21 01:26:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-18 07:04:13 +00:00
|
|
|
struct sort_result
|
|
|
|
{
|
|
|
|
struct addrinfo *dest_addr;
|
2008-01-10 20:00:52 +00:00
|
|
|
/* Using sockaddr_storage is for now overkill. We only support IPv4
|
|
|
|
and IPv6 so far. If this changes at some point we can adjust the
|
|
|
|
type here. */
|
|
|
|
struct sockaddr_in6 source_addr;
|
2004-09-15 08:25:49 +00:00
|
|
|
uint8_t source_addr_len;
|
2003-11-18 07:04:13 +00:00
|
|
|
bool got_source_addr;
|
2006-04-16 21:34:32 +00:00
|
|
|
uint8_t source_addr_flags;
|
2007-11-12 23:55:58 +00:00
|
|
|
uint8_t prefixlen;
|
2007-11-14 06:58:35 +00:00
|
|
|
uint32_t index;
|
|
|
|
int32_t native;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct sort_result_combo
|
|
|
|
{
|
|
|
|
struct sort_result *results;
|
|
|
|
int nresults;
|
2003-11-18 07:04:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-11-20 00:41:22 +00:00
|
|
|
#if __BYTE_ORDER == __BIG_ENDIAN
|
|
|
|
# define htonl_c(n) n
|
|
|
|
#else
|
|
|
|
# define htonl_c(n) __bswap_constant_32 (n)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static const struct scopeentry
|
|
|
|
{
|
|
|
|
union
|
|
|
|
{
|
|
|
|
char addr[4];
|
|
|
|
uint32_t addr32;
|
|
|
|
};
|
|
|
|
uint32_t netmask;
|
|
|
|
int32_t scope;
|
|
|
|
} default_scopes[] =
|
|
|
|
{
|
|
|
|
/* Link-local addresses: scope 2. */
|
|
|
|
{ { { 169, 254, 0, 0 } }, htonl_c (0xffff0000), 2 },
|
|
|
|
{ { { 127, 0, 0, 0 } }, htonl_c (0xff000000), 2 },
|
|
|
|
/* Default: scope 14. */
|
|
|
|
{ { { 0, 0, 0, 0 } }, htonl_c (0x00000000), 14 }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* The label table. */
|
|
|
|
static const struct scopeentry *scopes;
|
|
|
|
|
|
|
|
|
2003-11-18 07:04:13 +00:00
|
|
|
static int
|
2008-01-10 20:00:52 +00:00
|
|
|
get_scope (const struct sockaddr_in6 *in6)
|
2003-11-18 07:04:13 +00:00
|
|
|
{
|
|
|
|
int scope;
|
2008-01-10 20:00:52 +00:00
|
|
|
if (in6->sin6_family == PF_INET6)
|
2003-11-18 07:04:13 +00:00
|
|
|
{
|
|
|
|
if (! IN6_IS_ADDR_MULTICAST (&in6->sin6_addr))
|
|
|
|
{
|
2008-05-14 22:33:51 +00:00
|
|
|
if (IN6_IS_ADDR_LINKLOCAL (&in6->sin6_addr)
|
|
|
|
/* RFC 4291 2.5.3 says that the loopback address is to be
|
|
|
|
treated like a link-local address. */
|
|
|
|
|| IN6_IS_ADDR_LOOPBACK (&in6->sin6_addr))
|
2003-11-18 07:04:13 +00:00
|
|
|
scope = 2;
|
|
|
|
else if (IN6_IS_ADDR_SITELOCAL (&in6->sin6_addr))
|
|
|
|
scope = 5;
|
|
|
|
else
|
|
|
|
/* XXX Is this the correct default behavior? */
|
|
|
|
scope = 14;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
scope = in6->sin6_addr.s6_addr[1] & 0xf;
|
|
|
|
}
|
2008-01-10 20:00:52 +00:00
|
|
|
else if (in6->sin6_family == PF_INET)
|
2003-11-18 07:04:13 +00:00
|
|
|
{
|
2008-01-10 20:00:52 +00:00
|
|
|
const struct sockaddr_in *in = (const struct sockaddr_in *) in6;
|
2007-11-20 00:41:22 +00:00
|
|
|
|
|
|
|
size_t cnt = 0;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
if ((in->sin_addr.s_addr & scopes[cnt].netmask)
|
|
|
|
== scopes[cnt].addr32)
|
|
|
|
return scopes[cnt].scope;
|
|
|
|
|
|
|
|
++cnt;
|
|
|
|
}
|
|
|
|
/* NOTREACHED */
|
2003-11-18 07:04:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
/* XXX What is a good default? */
|
|
|
|
scope = 15;
|
|
|
|
|
|
|
|
return scope;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-04 06:38:07 +00:00
|
|
|
struct prefixentry
|
2003-11-18 07:04:13 +00:00
|
|
|
{
|
|
|
|
struct in6_addr prefix;
|
|
|
|
unsigned int bits;
|
|
|
|
int val;
|
2006-05-04 06:38:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* The label table. */
|
|
|
|
static const struct prefixentry *labels;
|
|
|
|
|
|
|
|
/* Default labels. */
|
|
|
|
static const struct prefixentry default_labels[] =
|
2003-11-18 07:04:13 +00:00
|
|
|
{
|
|
|
|
/* See RFC 3484 for the details. */
|
2008-01-16 19:47:17 +00:00
|
|
|
{ { .__in6_u
|
|
|
|
= { .__u6_addr8 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } }
|
|
|
|
}, 128, 0 },
|
|
|
|
{ { .__in6_u
|
|
|
|
= { .__u6_addr8 = { 0x20, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }
|
|
|
|
}, 16, 2 },
|
|
|
|
{ { .__in6_u
|
|
|
|
= { .__u6_addr8 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }
|
|
|
|
}, 96, 3 },
|
|
|
|
{ { .__in6_u
|
|
|
|
= { .__u6_addr8 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 } }
|
|
|
|
}, 96, 4 },
|
2006-05-18 16:58:36 +00:00
|
|
|
/* The next two entries differ from RFC 3484. We need to treat
|
|
|
|
IPv6 site-local addresses special because they are never NATed,
|
|
|
|
unlike site-locale IPv4 addresses. If this would not happen, on
|
|
|
|
machines which have only IPv4 and IPv6 site-local addresses, the
|
|
|
|
sorting would prefer the IPv6 site-local addresses, causing
|
|
|
|
unnecessary delays when trying to connect to a global IPv6 address
|
|
|
|
through a site-local IPv6 address. */
|
2008-01-16 19:47:17 +00:00
|
|
|
{ { .__in6_u
|
|
|
|
= { .__u6_addr8 = { 0xfe, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }
|
|
|
|
}, 10, 5 },
|
|
|
|
{ { .__in6_u
|
|
|
|
= { .__u6_addr8 = { 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }
|
|
|
|
}, 7, 6 },
|
2007-11-19 17:31:40 +00:00
|
|
|
/* Additional rule for Teredo tunnels. */
|
2008-01-16 19:47:17 +00:00
|
|
|
{ { .__in6_u
|
|
|
|
= { .__u6_addr8 = { 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }
|
|
|
|
}, 32, 7 },
|
|
|
|
{ { .__in6_u
|
|
|
|
= { .__u6_addr8 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }
|
|
|
|
}, 0, 1 }
|
2003-11-18 07:04:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-05-04 06:38:07 +00:00
|
|
|
/* The precedence table. */
|
|
|
|
static const struct prefixentry *precedence;
|
|
|
|
|
|
|
|
/* The default precedences. */
|
|
|
|
static const struct prefixentry default_precedence[] =
|
2003-11-18 07:04:13 +00:00
|
|
|
{
|
|
|
|
/* See RFC 3484 for the details. */
|
2008-01-16 19:47:17 +00:00
|
|
|
{ { .__in6_u
|
|
|
|
= { .__u6_addr8 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } }
|
|
|
|
}, 128, 50 },
|
|
|
|
{ { .__in6_u
|
|
|
|
= { .__u6_addr8 = { 0x20, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }
|
|
|
|
}, 16, 30 },
|
|
|
|
{ { .__in6_u
|
|
|
|
= { .__u6_addr8 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }
|
|
|
|
}, 96, 20 },
|
|
|
|
{ { .__in6_u
|
|
|
|
= { .__u6_addr8 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 } }
|
|
|
|
}, 96, 10 },
|
|
|
|
{ { .__in6_u
|
|
|
|
= { .__u6_addr8 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }
|
|
|
|
}, 0, 40 }
|
2003-11-18 07:04:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2008-01-10 20:00:52 +00:00
|
|
|
match_prefix (const struct sockaddr_in6 *in6,
|
2006-05-04 06:38:07 +00:00
|
|
|
const struct prefixentry *list, int default_val)
|
2003-11-18 07:04:13 +00:00
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
struct sockaddr_in6 in6_mem;
|
|
|
|
|
2008-01-10 20:00:52 +00:00
|
|
|
if (in6->sin6_family == PF_INET)
|
2003-11-18 07:04:13 +00:00
|
|
|
{
|
2008-01-10 20:00:52 +00:00
|
|
|
const struct sockaddr_in *in = (const struct sockaddr_in *) in6;
|
2003-11-18 07:04:13 +00:00
|
|
|
|
2008-05-14 22:47:15 +00:00
|
|
|
/* Construct a V4-to-6 mapped address. */
|
2003-11-18 07:04:13 +00:00
|
|
|
in6_mem.sin6_family = PF_INET6;
|
|
|
|
in6_mem.sin6_port = in->sin_port;
|
|
|
|
in6_mem.sin6_flowinfo = 0;
|
2008-05-14 22:47:15 +00:00
|
|
|
memset (&in6_mem.sin6_addr, '\0', sizeof (in6_mem.sin6_addr));
|
|
|
|
in6_mem.sin6_addr.s6_addr16[5] = 0xffff;
|
|
|
|
in6_mem.sin6_addr.s6_addr32[3] = in->sin_addr.s_addr;
|
|
|
|
in6_mem.sin6_scope_id = 0;
|
2003-11-18 07:04:13 +00:00
|
|
|
|
|
|
|
in6 = &in6_mem;
|
|
|
|
}
|
2008-01-10 20:00:52 +00:00
|
|
|
else if (in6->sin6_family != PF_INET6)
|
2003-11-18 07:04:13 +00:00
|
|
|
return default_val;
|
|
|
|
|
|
|
|
for (idx = 0; ; ++idx)
|
|
|
|
{
|
|
|
|
unsigned int bits = list[idx].bits;
|
2006-10-02 16:50:55 +00:00
|
|
|
const uint8_t *mask = list[idx].prefix.s6_addr;
|
|
|
|
const uint8_t *val = in6->sin6_addr.s6_addr;
|
2003-11-18 07:04:13 +00:00
|
|
|
|
2005-09-26 16:12:12 +00:00
|
|
|
while (bits >= 8)
|
2003-11-18 07:04:13 +00:00
|
|
|
{
|
|
|
|
if (*mask != *val)
|
|
|
|
break;
|
|
|
|
|
|
|
|
++mask;
|
|
|
|
++val;
|
|
|
|
bits -= 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bits < 8)
|
|
|
|
{
|
2004-02-16 18:48:51 +00:00
|
|
|
if ((*mask & (0xff00 >> bits)) == (*val & (0xff00 >> bits)))
|
2003-11-18 07:04:13 +00:00
|
|
|
/* Match! */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return list[idx].val;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2008-01-10 20:00:52 +00:00
|
|
|
get_label (const struct sockaddr_in6 *in6)
|
2003-11-18 07:04:13 +00:00
|
|
|
{
|
|
|
|
/* XXX What is a good default value? */
|
2008-01-10 20:00:52 +00:00
|
|
|
return match_prefix (in6, labels, INT_MAX);
|
2003-11-18 07:04:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2008-01-10 20:00:52 +00:00
|
|
|
get_precedence (const struct sockaddr_in6 *in6)
|
2003-11-18 07:04:13 +00:00
|
|
|
{
|
|
|
|
/* XXX What is a good default value? */
|
2008-01-10 20:00:52 +00:00
|
|
|
return match_prefix (in6, precedence, 0);
|
2003-11-18 07:04:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-26 21:10:16 +00:00
|
|
|
/* Find last bit set in a word. */
|
|
|
|
static int
|
|
|
|
fls (uint32_t a)
|
|
|
|
{
|
|
|
|
uint32_t mask;
|
2007-11-12 23:55:58 +00:00
|
|
|
int n;
|
2005-09-26 21:10:16 +00:00
|
|
|
for (n = 0, mask = 1 << 31; n < 32; mask >>= 1, ++n)
|
|
|
|
if ((a & mask) != 0)
|
|
|
|
break;
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-18 07:04:13 +00:00
|
|
|
static int
|
2007-11-14 06:58:35 +00:00
|
|
|
rfc3484_sort (const void *p1, const void *p2, void *arg)
|
2003-11-18 07:04:13 +00:00
|
|
|
{
|
2008-01-10 20:00:52 +00:00
|
|
|
const size_t idx1 = *(const size_t *) p1;
|
|
|
|
const size_t idx2 = *(const size_t *) p2;
|
2007-11-14 06:58:35 +00:00
|
|
|
struct sort_result_combo *src = (struct sort_result_combo *) arg;
|
2008-01-10 20:00:52 +00:00
|
|
|
struct sort_result *a1 = &src->results[idx1];
|
|
|
|
struct sort_result *a2 = &src->results[idx2];
|
2003-11-18 07:04:13 +00:00
|
|
|
|
|
|
|
/* Rule 1: Avoid unusable destinations.
|
|
|
|
We have the got_source_addr flag set if the destination is reachable. */
|
|
|
|
if (a1->got_source_addr && ! a2->got_source_addr)
|
|
|
|
return -1;
|
|
|
|
if (! a1->got_source_addr && a2->got_source_addr)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
|
|
/* Rule 2: Prefer matching scope. Only interesting if both
|
|
|
|
destination addresses are IPv6. */
|
|
|
|
int a1_dst_scope
|
2008-01-10 20:00:52 +00:00
|
|
|
= get_scope ((struct sockaddr_in6 *) a1->dest_addr->ai_addr);
|
2003-11-18 07:04:13 +00:00
|
|
|
|
|
|
|
int a2_dst_scope
|
2008-01-10 20:00:52 +00:00
|
|
|
= get_scope ((struct sockaddr_in6 *) a2->dest_addr->ai_addr);
|
2003-11-18 07:04:13 +00:00
|
|
|
|
|
|
|
if (a1->got_source_addr)
|
|
|
|
{
|
|
|
|
int a1_src_scope = get_scope (&a1->source_addr);
|
|
|
|
int a2_src_scope = get_scope (&a2->source_addr);
|
|
|
|
|
|
|
|
if (a1_dst_scope == a1_src_scope && a2_dst_scope != a2_src_scope)
|
|
|
|
return -1;
|
|
|
|
if (a1_dst_scope != a1_src_scope && a2_dst_scope == a2_src_scope)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-16 21:34:32 +00:00
|
|
|
/* Rule 3: Avoid deprecated addresses. */
|
|
|
|
if (a1->got_source_addr)
|
|
|
|
{
|
|
|
|
if (!(a1->source_addr_flags & in6ai_deprecated)
|
|
|
|
&& (a2->source_addr_flags & in6ai_deprecated))
|
|
|
|
return -1;
|
|
|
|
if ((a1->source_addr_flags & in6ai_deprecated)
|
|
|
|
&& !(a2->source_addr_flags & in6ai_deprecated))
|
|
|
|
return 1;
|
|
|
|
}
|
2003-11-18 07:04:13 +00:00
|
|
|
|
2006-09-24 17:14:11 +00:00
|
|
|
/* Rule 4: Prefer home addresses. */
|
|
|
|
if (a1->got_source_addr)
|
|
|
|
{
|
|
|
|
if (!(a1->source_addr_flags & in6ai_homeaddress)
|
|
|
|
&& (a2->source_addr_flags & in6ai_homeaddress))
|
2006-10-16 15:20:20 +00:00
|
|
|
return 1;
|
2006-09-24 17:14:11 +00:00
|
|
|
if ((a1->source_addr_flags & in6ai_homeaddress)
|
|
|
|
&& !(a2->source_addr_flags & in6ai_homeaddress))
|
2006-10-16 15:20:20 +00:00
|
|
|
return -1;
|
2006-09-24 17:14:11 +00:00
|
|
|
}
|
2003-11-18 07:04:13 +00:00
|
|
|
|
|
|
|
/* Rule 5: Prefer matching label. */
|
|
|
|
if (a1->got_source_addr)
|
|
|
|
{
|
|
|
|
int a1_dst_label
|
2008-01-10 20:00:52 +00:00
|
|
|
= get_label ((struct sockaddr_in6 *) a1->dest_addr->ai_addr);
|
2003-11-18 07:04:13 +00:00
|
|
|
int a1_src_label = get_label (&a1->source_addr);
|
|
|
|
|
|
|
|
int a2_dst_label
|
2008-01-10 20:00:52 +00:00
|
|
|
= get_label ((struct sockaddr_in6 *) a2->dest_addr->ai_addr);
|
2003-11-18 07:04:13 +00:00
|
|
|
int a2_src_label = get_label (&a2->source_addr);
|
|
|
|
|
|
|
|
if (a1_dst_label == a1_src_label && a2_dst_label != a2_src_label)
|
|
|
|
return -1;
|
|
|
|
if (a1_dst_label != a1_src_label && a2_dst_label == a2_src_label)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Rule 6: Prefer higher precedence. */
|
|
|
|
int a1_prec
|
2008-01-10 20:00:52 +00:00
|
|
|
= get_precedence ((struct sockaddr_in6 *) a1->dest_addr->ai_addr);
|
2003-11-18 07:04:13 +00:00
|
|
|
int a2_prec
|
2008-01-10 20:00:52 +00:00
|
|
|
= get_precedence ((struct sockaddr_in6 *) a2->dest_addr->ai_addr);
|
2003-11-18 07:04:13 +00:00
|
|
|
|
|
|
|
if (a1_prec > a2_prec)
|
|
|
|
return -1;
|
|
|
|
if (a1_prec < a2_prec)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
2006-04-16 21:34:32 +00:00
|
|
|
/* Rule 7: Prefer native transport. */
|
|
|
|
if (a1->got_source_addr)
|
|
|
|
{
|
2007-11-14 06:58:35 +00:00
|
|
|
/* The same interface index means the same interface which means
|
|
|
|
there is no difference in transport. This should catch many
|
|
|
|
(most?) cases. */
|
|
|
|
if (a1->index != a2->index)
|
|
|
|
{
|
2008-01-10 22:30:58 +00:00
|
|
|
int a1_native = a1->native;
|
|
|
|
int a2_native = a2->native;
|
|
|
|
|
|
|
|
if (a1_native == -1 || a2_native == -1)
|
2007-11-14 06:58:35 +00:00
|
|
|
{
|
2008-01-10 22:30:58 +00:00
|
|
|
uint32_t a1_index;
|
|
|
|
if (a1_native == -1)
|
|
|
|
{
|
|
|
|
/* If we do not have the information use 'native' as
|
|
|
|
the default. */
|
|
|
|
a1_native = 0;
|
|
|
|
a1_index = a1->index;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
a1_index = 0xffffffffu;
|
|
|
|
|
|
|
|
uint32_t a2_index;
|
|
|
|
if (a2_native == -1)
|
|
|
|
{
|
|
|
|
/* If we do not have the information use 'native' as
|
|
|
|
the default. */
|
|
|
|
a2_native = 0;
|
|
|
|
a2_index = a2->index;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
a2_index = 0xffffffffu;
|
|
|
|
|
|
|
|
__check_native (a1_index, &a1_native, a2_index, &a2_native);
|
2007-11-14 06:58:35 +00:00
|
|
|
|
|
|
|
/* Fill in the results in all the records. */
|
|
|
|
for (int i = 0; i < src->nresults; ++i)
|
2013-10-25 04:25:38 +00:00
|
|
|
if (a1_index != -1 && src->results[i].index == a1_index)
|
2008-01-10 22:30:58 +00:00
|
|
|
{
|
|
|
|
assert (src->results[i].native == -1
|
|
|
|
|| src->results[i].native == a1_native);
|
2007-11-14 06:58:35 +00:00
|
|
|
src->results[i].native = a1_native;
|
2008-01-10 22:30:58 +00:00
|
|
|
}
|
2013-10-25 04:25:38 +00:00
|
|
|
else if (a2_index != -1 && src->results[i].index == a2_index)
|
2008-01-10 22:30:58 +00:00
|
|
|
{
|
|
|
|
assert (src->results[i].native == -1
|
|
|
|
|| src->results[i].native == a2_native);
|
2007-11-14 06:58:35 +00:00
|
|
|
src->results[i].native = a2_native;
|
2008-01-10 22:30:58 +00:00
|
|
|
}
|
2007-11-14 06:58:35 +00:00
|
|
|
}
|
2006-04-16 21:34:32 +00:00
|
|
|
|
2008-01-10 22:30:58 +00:00
|
|
|
if (a1_native && !a2_native)
|
2007-11-14 06:58:35 +00:00
|
|
|
return -1;
|
2008-01-10 22:30:58 +00:00
|
|
|
if (!a1_native && a2_native)
|
2007-11-14 06:58:35 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2006-04-16 21:34:32 +00:00
|
|
|
}
|
2003-11-18 07:04:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Rule 8: Prefer smaller scope. */
|
|
|
|
if (a1_dst_scope < a2_dst_scope)
|
|
|
|
return -1;
|
|
|
|
if (a1_dst_scope > a2_dst_scope)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
|
|
/* Rule 9: Use longest matching prefix. */
|
|
|
|
if (a1->got_source_addr
|
|
|
|
&& a1->dest_addr->ai_family == a2->dest_addr->ai_family)
|
|
|
|
{
|
|
|
|
int bit1 = 0;
|
|
|
|
int bit2 = 0;
|
|
|
|
|
|
|
|
if (a1->dest_addr->ai_family == PF_INET)
|
|
|
|
{
|
2008-01-10 20:00:52 +00:00
|
|
|
assert (a1->source_addr.sin6_family == PF_INET);
|
|
|
|
assert (a2->source_addr.sin6_family == PF_INET);
|
2003-11-18 07:04:13 +00:00
|
|
|
|
2007-11-12 23:55:58 +00:00
|
|
|
/* Outside of subnets, as defined by the network masks,
|
|
|
|
common address prefixes for IPv4 addresses make no sense.
|
|
|
|
So, define a non-zero value only if source and
|
|
|
|
destination address are on the same subnet. */
|
|
|
|
struct sockaddr_in *in1_dst
|
|
|
|
= (struct sockaddr_in *) a1->dest_addr->ai_addr;
|
|
|
|
in_addr_t in1_dst_addr = ntohl (in1_dst->sin_addr.s_addr);
|
|
|
|
struct sockaddr_in *in1_src
|
|
|
|
= (struct sockaddr_in *) &a1->source_addr;
|
|
|
|
in_addr_t in1_src_addr = ntohl (in1_src->sin_addr.s_addr);
|
|
|
|
in_addr_t netmask1 = 0xffffffffu << (32 - a1->prefixlen);
|
|
|
|
|
|
|
|
if ((in1_src_addr & netmask1) == (in1_dst_addr & netmask1))
|
|
|
|
bit1 = fls (in1_dst_addr ^ in1_src_addr);
|
|
|
|
|
|
|
|
struct sockaddr_in *in2_dst
|
|
|
|
= (struct sockaddr_in *) a2->dest_addr->ai_addr;
|
|
|
|
in_addr_t in2_dst_addr = ntohl (in2_dst->sin_addr.s_addr);
|
|
|
|
struct sockaddr_in *in2_src
|
|
|
|
= (struct sockaddr_in *) &a2->source_addr;
|
|
|
|
in_addr_t in2_src_addr = ntohl (in2_src->sin_addr.s_addr);
|
|
|
|
in_addr_t netmask2 = 0xffffffffu << (32 - a2->prefixlen);
|
|
|
|
|
|
|
|
if ((in2_src_addr & netmask2) == (in2_dst_addr & netmask2))
|
|
|
|
bit2 = fls (in2_dst_addr ^ in2_src_addr);
|
2003-11-18 07:04:13 +00:00
|
|
|
}
|
|
|
|
else if (a1->dest_addr->ai_family == PF_INET6)
|
|
|
|
{
|
2008-01-10 20:00:52 +00:00
|
|
|
assert (a1->source_addr.sin6_family == PF_INET6);
|
|
|
|
assert (a2->source_addr.sin6_family == PF_INET6);
|
2003-11-18 07:04:13 +00:00
|
|
|
|
|
|
|
struct sockaddr_in6 *in1_dst;
|
|
|
|
struct sockaddr_in6 *in1_src;
|
|
|
|
struct sockaddr_in6 *in2_dst;
|
|
|
|
struct sockaddr_in6 *in2_src;
|
|
|
|
|
|
|
|
in1_dst = (struct sockaddr_in6 *) a1->dest_addr->ai_addr;
|
|
|
|
in1_src = (struct sockaddr_in6 *) &a1->source_addr;
|
|
|
|
in2_dst = (struct sockaddr_in6 *) a2->dest_addr->ai_addr;
|
|
|
|
in2_src = (struct sockaddr_in6 *) &a2->source_addr;
|
|
|
|
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < 4; ++i)
|
|
|
|
if (in1_dst->sin6_addr.s6_addr32[i]
|
|
|
|
!= in1_src->sin6_addr.s6_addr32[i]
|
|
|
|
|| (in2_dst->sin6_addr.s6_addr32[i]
|
|
|
|
!= in2_src->sin6_addr.s6_addr32[i]))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (i < 4)
|
|
|
|
{
|
2005-09-26 21:10:16 +00:00
|
|
|
bit1 = fls (ntohl (in1_dst->sin6_addr.s6_addr32[i]
|
|
|
|
^ in1_src->sin6_addr.s6_addr32[i]));
|
|
|
|
bit2 = fls (ntohl (in2_dst->sin6_addr.s6_addr32[i]
|
|
|
|
^ in2_src->sin6_addr.s6_addr32[i]));
|
2003-11-18 07:04:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bit1 > bit2)
|
|
|
|
return -1;
|
|
|
|
if (bit1 < bit2)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-14 17:58:03 +00:00
|
|
|
/* Rule 10: Otherwise, leave the order unchanged. To ensure this
|
|
|
|
compare with the value indicating the order in which the entries
|
|
|
|
have been received from the services. NB: no two entries can have
|
|
|
|
the same order so the test will never return zero. */
|
2008-01-10 20:00:52 +00:00
|
|
|
return idx1 < idx2 ? -1 : 1;
|
2003-11-18 07:04:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-16 21:34:32 +00:00
|
|
|
static int
|
|
|
|
in6aicmp (const void *p1, const void *p2)
|
|
|
|
{
|
|
|
|
struct in6addrinfo *a1 = (struct in6addrinfo *) p1;
|
|
|
|
struct in6addrinfo *a2 = (struct in6addrinfo *) p2;
|
|
|
|
|
|
|
|
return memcmp (a1->addr, a2->addr, sizeof (a1->addr));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-04 06:38:07 +00:00
|
|
|
/* Name of the config file for RFC 3484 sorting (for now). */
|
|
|
|
#define GAICONF_FNAME "/etc/gai.conf"
|
|
|
|
|
|
|
|
|
2007-10-17 16:05:34 +00:00
|
|
|
/* Non-zero if we are supposed to reload the config file automatically
|
2006-05-04 06:38:07 +00:00
|
|
|
whenever it changed. */
|
|
|
|
static int gaiconf_reload_flag;
|
|
|
|
|
2007-10-17 16:05:34 +00:00
|
|
|
/* Non-zero if gaiconf_reload_flag was ever set to true. */
|
|
|
|
static int gaiconf_reload_flag_ever_set;
|
|
|
|
|
2006-05-04 06:38:07 +00:00
|
|
|
/* Last modification time. */
|
2012-08-17 18:47:06 +00:00
|
|
|
#ifdef _STATBUF_ST_NSEC
|
|
|
|
|
2021-03-02 20:06:02 +00:00
|
|
|
static struct __timespec64 gaiconf_mtime;
|
2006-05-04 06:38:07 +00:00
|
|
|
|
2012-08-17 18:47:06 +00:00
|
|
|
static inline void
|
2021-03-02 20:06:02 +00:00
|
|
|
save_gaiconf_mtime (const struct __stat64_t64 *st)
|
2012-08-17 18:47:06 +00:00
|
|
|
{
|
2021-06-23 17:14:48 +00:00
|
|
|
gaiconf_mtime = (struct __timespec64) { st->st_mtim.tv_sec,
|
|
|
|
st->st_mtim.tv_nsec };
|
2012-08-17 18:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool
|
2021-03-02 20:06:02 +00:00
|
|
|
check_gaiconf_mtime (const struct __stat64_t64 *st)
|
2012-08-17 18:47:06 +00:00
|
|
|
{
|
|
|
|
return (st->st_mtim.tv_sec == gaiconf_mtime.tv_sec
|
|
|
|
&& st->st_mtim.tv_nsec == gaiconf_mtime.tv_nsec);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
static time_t gaiconf_mtime;
|
|
|
|
|
|
|
|
static inline void
|
2021-03-02 20:06:02 +00:00
|
|
|
save_gaiconf_mtime (const struct __stat64_t64 *st)
|
2012-08-17 18:47:06 +00:00
|
|
|
{
|
|
|
|
gaiconf_mtime = st->st_mtime;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool
|
2021-03-02 20:06:02 +00:00
|
|
|
check_gaiconf_mtime (const struct __stat64_t64 *st)
|
2012-08-17 18:47:06 +00:00
|
|
|
{
|
2012-08-17 18:49:00 +00:00
|
|
|
return st->st_mtime == gaiconf_mtime;
|
2012-08-17 18:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2006-05-04 06:38:07 +00:00
|
|
|
|
2022-12-27 21:11:42 +00:00
|
|
|
void
|
|
|
|
__libc_getaddrinfo_freemem (void)
|
2006-05-04 06:38:07 +00:00
|
|
|
{
|
|
|
|
if (labels != default_labels)
|
|
|
|
{
|
|
|
|
const struct prefixentry *old = labels;
|
|
|
|
labels = default_labels;
|
|
|
|
free ((void *) old);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (precedence != default_precedence)
|
|
|
|
{
|
|
|
|
const struct prefixentry *old = precedence;
|
|
|
|
precedence = default_precedence;
|
|
|
|
free ((void *) old);
|
|
|
|
}
|
2007-11-20 00:41:22 +00:00
|
|
|
|
|
|
|
if (scopes != default_scopes)
|
|
|
|
{
|
|
|
|
const struct scopeentry *old = scopes;
|
|
|
|
scopes = default_scopes;
|
|
|
|
free ((void *) old);
|
|
|
|
}
|
2006-05-04 06:38:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct prefixlist
|
|
|
|
{
|
|
|
|
struct prefixentry entry;
|
|
|
|
struct prefixlist *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-11-20 00:41:22 +00:00
|
|
|
struct scopelist
|
|
|
|
{
|
|
|
|
struct scopeentry entry;
|
|
|
|
struct scopelist *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-05-04 06:38:07 +00:00
|
|
|
static void
|
|
|
|
free_prefixlist (struct prefixlist *list)
|
|
|
|
{
|
|
|
|
while (list != NULL)
|
|
|
|
{
|
|
|
|
struct prefixlist *oldp = list;
|
|
|
|
list = list->next;
|
|
|
|
free (oldp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-20 00:41:22 +00:00
|
|
|
static void
|
|
|
|
free_scopelist (struct scopelist *list)
|
|
|
|
{
|
|
|
|
while (list != NULL)
|
|
|
|
{
|
|
|
|
struct scopelist *oldp = list;
|
|
|
|
list = list->next;
|
|
|
|
free (oldp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-04 06:38:07 +00:00
|
|
|
static int
|
|
|
|
prefixcmp (const void *p1, const void *p2)
|
|
|
|
{
|
|
|
|
const struct prefixentry *e1 = (const struct prefixentry *) p1;
|
|
|
|
const struct prefixentry *e2 = (const struct prefixentry *) p2;
|
|
|
|
|
|
|
|
if (e1->bits < e2->bits)
|
|
|
|
return 1;
|
|
|
|
if (e1->bits == e2->bits)
|
|
|
|
return 0;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-20 00:41:22 +00:00
|
|
|
static int
|
|
|
|
scopecmp (const void *p1, const void *p2)
|
|
|
|
{
|
|
|
|
const struct scopeentry *e1 = (const struct scopeentry *) p1;
|
|
|
|
const struct scopeentry *e2 = (const struct scopeentry *) p2;
|
|
|
|
|
|
|
|
if (e1->netmask > e2->netmask)
|
|
|
|
return -1;
|
|
|
|
if (e1->netmask == e2->netmask)
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-07-27 17:19:53 +00:00
|
|
|
static bool
|
|
|
|
add_prefixlist (struct prefixlist **listp, size_t *lenp, bool *nullbitsp,
|
|
|
|
char *val1, char *val2, char **pos)
|
|
|
|
{
|
|
|
|
struct in6_addr prefix;
|
|
|
|
unsigned long int bits;
|
|
|
|
unsigned long int val;
|
|
|
|
char *endp;
|
|
|
|
|
|
|
|
bits = 128;
|
|
|
|
__set_errno (0);
|
|
|
|
char *cp = strchr (val1, '/');
|
|
|
|
if (cp != NULL)
|
|
|
|
*cp++ = '\0';
|
|
|
|
*pos = cp;
|
|
|
|
if (inet_pton (AF_INET6, val1, &prefix)
|
|
|
|
&& (cp == NULL
|
|
|
|
|| (bits = strtoul (cp, &endp, 10)) != ULONG_MAX
|
|
|
|
|| errno != ERANGE)
|
|
|
|
&& *endp == '\0'
|
|
|
|
&& bits <= 128
|
|
|
|
&& ((val = strtoul (val2, &endp, 10)) != ULONG_MAX
|
|
|
|
|| errno != ERANGE)
|
|
|
|
&& *endp == '\0'
|
|
|
|
&& val <= INT_MAX)
|
|
|
|
{
|
|
|
|
struct prefixlist *newp = malloc (sizeof (*newp));
|
|
|
|
if (newp == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
memcpy (&newp->entry.prefix, &prefix, sizeof (prefix));
|
|
|
|
newp->entry.bits = bits;
|
|
|
|
newp->entry.val = val;
|
|
|
|
newp->next = *listp;
|
|
|
|
*listp = newp;
|
|
|
|
++*lenp;
|
|
|
|
*nullbitsp |= bits == 0;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
add_scopelist (struct scopelist **listp, size_t *lenp, bool *nullbitsp,
|
|
|
|
const struct in6_addr *prefixp, unsigned long int bits,
|
|
|
|
unsigned long int val)
|
|
|
|
{
|
|
|
|
struct scopelist *newp = malloc (sizeof (*newp));
|
|
|
|
if (newp == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
newp->entry.netmask = htonl (bits != 96 ? (0xffffffff << (128 - bits)) : 0);
|
|
|
|
newp->entry.addr32 = (prefixp->s6_addr32[3] & newp->entry.netmask);
|
|
|
|
newp->entry.scope = val;
|
|
|
|
newp->next = *listp;
|
|
|
|
*listp = newp;
|
|
|
|
++*lenp;
|
|
|
|
*nullbitsp |= bits == 96;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2007-11-20 00:41:22 +00:00
|
|
|
|
2006-05-04 06:38:07 +00:00
|
|
|
static void
|
|
|
|
gaiconf_init (void)
|
|
|
|
{
|
|
|
|
struct prefixlist *labellist = NULL;
|
|
|
|
size_t nlabellist = 0;
|
|
|
|
bool labellist_nullbits = false;
|
|
|
|
struct prefixlist *precedencelist = NULL;
|
|
|
|
size_t nprecedencelist = 0;
|
|
|
|
bool precedencelist_nullbits = false;
|
2007-11-20 00:41:22 +00:00
|
|
|
struct scopelist *scopelist = NULL;
|
|
|
|
size_t nscopelist = 0;
|
|
|
|
bool scopelist_nullbits = false;
|
2006-05-04 06:38:07 +00:00
|
|
|
|
2011-11-15 09:24:42 +00:00
|
|
|
FILE *fp = fopen (GAICONF_FNAME, "rce");
|
2021-08-03 15:59:23 +00:00
|
|
|
if (fp == NULL)
|
|
|
|
goto no_file;
|
|
|
|
|
|
|
|
struct __stat64_t64 st;
|
|
|
|
if (__fstat64_time64 (fileno (fp), &st) != 0)
|
2006-05-04 06:38:07 +00:00
|
|
|
{
|
2021-08-03 15:59:23 +00:00
|
|
|
fclose (fp);
|
|
|
|
goto no_file;
|
|
|
|
}
|
2006-05-04 06:38:07 +00:00
|
|
|
|
2021-08-03 15:59:23 +00:00
|
|
|
char *line = NULL;
|
|
|
|
size_t linelen = 0;
|
2006-05-04 06:38:07 +00:00
|
|
|
|
2021-08-03 15:59:23 +00:00
|
|
|
__fsetlocking (fp, FSETLOCKING_BYCALLER);
|
2006-05-04 06:38:07 +00:00
|
|
|
|
2021-08-03 15:59:23 +00:00
|
|
|
while (!feof_unlocked (fp))
|
|
|
|
{
|
|
|
|
ssize_t n = __getline (&line, &linelen, fp);
|
|
|
|
if (n <= 0)
|
|
|
|
break;
|
2006-05-04 06:38:07 +00:00
|
|
|
|
2021-08-03 15:59:23 +00:00
|
|
|
/* Handle comments. No escaping possible so this is easy. */
|
|
|
|
char *cp = strchr (line, '#');
|
|
|
|
if (cp != NULL)
|
|
|
|
*cp = '\0';
|
2006-05-04 06:38:07 +00:00
|
|
|
|
2021-08-03 15:59:23 +00:00
|
|
|
cp = line;
|
|
|
|
while (isspace (*cp))
|
|
|
|
++cp;
|
2006-05-04 06:38:07 +00:00
|
|
|
|
2021-08-03 15:59:23 +00:00
|
|
|
char *cmd = cp;
|
|
|
|
while (*cp != '\0' && !isspace (*cp))
|
|
|
|
++cp;
|
|
|
|
size_t cmdlen = cp - cmd;
|
2006-05-04 06:38:07 +00:00
|
|
|
|
2021-08-03 15:59:23 +00:00
|
|
|
if (*cp != '\0')
|
|
|
|
*cp++ = '\0';
|
|
|
|
while (isspace (*cp))
|
|
|
|
++cp;
|
2006-05-04 06:38:07 +00:00
|
|
|
|
2021-08-03 15:59:23 +00:00
|
|
|
char *val1 = cp;
|
|
|
|
while (*cp != '\0' && !isspace (*cp))
|
|
|
|
++cp;
|
|
|
|
size_t val1len = cp - cmd;
|
2006-05-04 06:38:07 +00:00
|
|
|
|
2021-08-03 15:59:23 +00:00
|
|
|
/* We always need at least two values. */
|
|
|
|
if (val1len == 0)
|
|
|
|
continue;
|
2006-05-04 06:38:07 +00:00
|
|
|
|
2021-08-03 15:59:23 +00:00
|
|
|
if (*cp != '\0')
|
|
|
|
*cp++ = '\0';
|
|
|
|
while (isspace (*cp))
|
|
|
|
++cp;
|
2006-05-04 06:38:07 +00:00
|
|
|
|
2021-08-03 15:59:23 +00:00
|
|
|
char *val2 = cp;
|
|
|
|
while (*cp != '\0' && !isspace (*cp))
|
|
|
|
++cp;
|
2006-05-04 06:38:07 +00:00
|
|
|
|
2021-08-03 15:59:23 +00:00
|
|
|
/* Ignore the rest of the line. */
|
|
|
|
*cp = '\0';
|
2006-05-04 06:38:07 +00:00
|
|
|
|
2021-08-03 15:59:23 +00:00
|
|
|
switch (cmdlen)
|
|
|
|
{
|
|
|
|
case 5:
|
|
|
|
if (strcmp (cmd, "label") == 0)
|
2006-05-04 06:38:07 +00:00
|
|
|
{
|
2021-08-03 15:59:23 +00:00
|
|
|
if (!add_prefixlist (&labellist, &nlabellist,
|
|
|
|
&labellist_nullbits, val1, val2, &cp))
|
2006-05-04 06:38:07 +00:00
|
|
|
{
|
2021-08-03 15:59:23 +00:00
|
|
|
free (line);
|
|
|
|
fclose (fp);
|
|
|
|
goto no_file;
|
2006-05-04 06:38:07 +00:00
|
|
|
}
|
2021-08-03 15:59:23 +00:00
|
|
|
}
|
|
|
|
break;
|
2006-05-04 06:38:07 +00:00
|
|
|
|
2021-08-03 15:59:23 +00:00
|
|
|
case 6:
|
|
|
|
if (strcmp (cmd, "reload") == 0)
|
|
|
|
{
|
|
|
|
gaiconf_reload_flag = strcmp (val1, "yes") == 0;
|
|
|
|
if (gaiconf_reload_flag)
|
|
|
|
gaiconf_reload_flag_ever_set = 1;
|
|
|
|
}
|
|
|
|
break;
|
2006-05-04 06:38:07 +00:00
|
|
|
|
2021-08-03 15:59:23 +00:00
|
|
|
case 7:
|
|
|
|
if (strcmp (cmd, "scopev4") == 0)
|
|
|
|
{
|
|
|
|
struct in6_addr prefix;
|
|
|
|
unsigned long int bits;
|
|
|
|
unsigned long int val;
|
|
|
|
char *endp;
|
|
|
|
|
|
|
|
bits = 32;
|
|
|
|
__set_errno (0);
|
|
|
|
cp = strchr (val1, '/');
|
|
|
|
if (cp != NULL)
|
|
|
|
*cp++ = '\0';
|
|
|
|
if (inet_pton (AF_INET6, val1, &prefix))
|
2007-11-20 00:41:22 +00:00
|
|
|
{
|
2021-08-03 15:59:23 +00:00
|
|
|
bits = 128;
|
|
|
|
if (IN6_IS_ADDR_V4MAPPED (&prefix)
|
|
|
|
&& (cp == NULL
|
|
|
|
|| (bits = strtoul (cp, &endp, 10)) != ULONG_MAX
|
|
|
|
|| errno != ERANGE)
|
|
|
|
&& *endp == '\0'
|
|
|
|
&& bits >= 96
|
|
|
|
&& bits <= 128
|
|
|
|
&& ((val = strtoul (val2, &endp, 10)) != ULONG_MAX
|
|
|
|
|| errno != ERANGE)
|
|
|
|
&& *endp == '\0'
|
|
|
|
&& val <= INT_MAX)
|
2007-11-20 00:41:22 +00:00
|
|
|
{
|
2021-07-27 17:19:53 +00:00
|
|
|
if (!add_scopelist (&scopelist, &nscopelist,
|
|
|
|
&scopelist_nullbits, &prefix,
|
2021-08-03 15:59:23 +00:00
|
|
|
bits, val))
|
2021-07-27 17:19:53 +00:00
|
|
|
{
|
|
|
|
free (line);
|
|
|
|
fclose (fp);
|
|
|
|
goto no_file;
|
|
|
|
}
|
2007-11-20 00:41:22 +00:00
|
|
|
}
|
|
|
|
}
|
2021-08-03 15:59:23 +00:00
|
|
|
else if (inet_pton (AF_INET, val1, &prefix.s6_addr32[3])
|
|
|
|
&& (cp == NULL
|
|
|
|
|| (bits = strtoul (cp, &endp, 10)) != ULONG_MAX
|
|
|
|
|| errno != ERANGE)
|
|
|
|
&& *endp == '\0'
|
|
|
|
&& bits <= 32
|
|
|
|
&& ((val = strtoul (val2, &endp, 10)) != ULONG_MAX
|
|
|
|
|| errno != ERANGE)
|
|
|
|
&& *endp == '\0'
|
|
|
|
&& val <= INT_MAX)
|
2006-05-04 06:38:07 +00:00
|
|
|
{
|
2021-08-03 15:59:23 +00:00
|
|
|
if (!add_scopelist (&scopelist, &nscopelist,
|
|
|
|
&scopelist_nullbits, &prefix,
|
|
|
|
bits + 96, val))
|
2021-07-27 17:19:53 +00:00
|
|
|
{
|
|
|
|
free (line);
|
|
|
|
fclose (fp);
|
|
|
|
goto no_file;
|
|
|
|
}
|
2006-05-04 06:38:07 +00:00
|
|
|
}
|
|
|
|
}
|
2021-08-03 15:59:23 +00:00
|
|
|
break;
|
2006-05-04 06:38:07 +00:00
|
|
|
|
2021-08-03 15:59:23 +00:00
|
|
|
case 10:
|
|
|
|
if (strcmp (cmd, "precedence") == 0)
|
2006-05-04 06:38:07 +00:00
|
|
|
{
|
2021-08-03 15:59:23 +00:00
|
|
|
if (!add_prefixlist (&precedencelist, &nprecedencelist,
|
|
|
|
&precedencelist_nullbits, val1, val2,
|
|
|
|
&cp))
|
|
|
|
{
|
|
|
|
free (line);
|
|
|
|
fclose (fp);
|
|
|
|
goto no_file;
|
|
|
|
}
|
2006-05-04 06:38:07 +00:00
|
|
|
}
|
2021-08-03 15:59:23 +00:00
|
|
|
break;
|
2006-05-04 06:38:07 +00:00
|
|
|
}
|
2021-08-03 15:59:23 +00:00
|
|
|
}
|
2006-05-04 06:38:07 +00:00
|
|
|
|
2021-08-03 15:59:23 +00:00
|
|
|
free (line);
|
2006-05-04 06:38:07 +00:00
|
|
|
|
2021-08-03 15:59:23 +00:00
|
|
|
fclose (fp);
|
2006-05-04 06:38:07 +00:00
|
|
|
|
2021-08-03 15:59:23 +00:00
|
|
|
/* Create the array for the labels. */
|
|
|
|
struct prefixentry *new_labels;
|
|
|
|
if (nlabellist > 0)
|
|
|
|
{
|
|
|
|
if (!labellist_nullbits)
|
|
|
|
++nlabellist;
|
|
|
|
new_labels = malloc (nlabellist * sizeof (*new_labels));
|
|
|
|
if (new_labels == NULL)
|
|
|
|
goto no_file;
|
|
|
|
|
|
|
|
int i = nlabellist;
|
|
|
|
if (!labellist_nullbits)
|
|
|
|
{
|
|
|
|
--i;
|
|
|
|
memset (&new_labels[i].prefix, '\0', sizeof (struct in6_addr));
|
|
|
|
new_labels[i].bits = 0;
|
|
|
|
new_labels[i].val = 1;
|
2006-05-04 06:38:07 +00:00
|
|
|
}
|
|
|
|
|
2021-08-03 15:59:23 +00:00
|
|
|
struct prefixlist *l = labellist;
|
|
|
|
while (i-- > 0)
|
2007-11-20 00:41:22 +00:00
|
|
|
{
|
2021-08-03 15:59:23 +00:00
|
|
|
new_labels[i] = l->entry;
|
|
|
|
l = l->next;
|
|
|
|
}
|
|
|
|
free_prefixlist (labellist);
|
|
|
|
labellist = NULL;
|
2007-11-20 00:41:22 +00:00
|
|
|
|
2021-08-03 15:59:23 +00:00
|
|
|
/* Sort the entries so that the most specific ones are at
|
|
|
|
the beginning. */
|
|
|
|
qsort (new_labels, nlabellist, sizeof (*new_labels), prefixcmp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
new_labels = (struct prefixentry *) default_labels;
|
2007-11-20 00:41:22 +00:00
|
|
|
|
2021-08-03 15:59:23 +00:00
|
|
|
struct prefixentry *new_precedence;
|
|
|
|
if (nprecedencelist > 0)
|
|
|
|
{
|
|
|
|
if (!precedencelist_nullbits)
|
|
|
|
++nprecedencelist;
|
|
|
|
new_precedence = malloc (nprecedencelist * sizeof (*new_precedence));
|
|
|
|
if (new_precedence == NULL)
|
|
|
|
{
|
|
|
|
if (new_labels != default_labels)
|
|
|
|
free (new_labels);
|
|
|
|
goto no_file;
|
2007-11-20 00:41:22 +00:00
|
|
|
}
|
2006-05-04 06:38:07 +00:00
|
|
|
|
2021-08-03 15:59:23 +00:00
|
|
|
int i = nprecedencelist;
|
|
|
|
if (!precedencelist_nullbits)
|
|
|
|
{
|
|
|
|
--i;
|
|
|
|
memset (&new_precedence[i].prefix, '\0',
|
|
|
|
sizeof (struct in6_addr));
|
|
|
|
new_precedence[i].bits = 0;
|
|
|
|
new_precedence[i].val = 40;
|
|
|
|
}
|
2006-05-04 06:38:07 +00:00
|
|
|
|
2021-08-03 15:59:23 +00:00
|
|
|
struct prefixlist *l = precedencelist;
|
|
|
|
while (i-- > 0)
|
|
|
|
{
|
|
|
|
new_precedence[i] = l->entry;
|
|
|
|
l = l->next;
|
|
|
|
}
|
|
|
|
free_prefixlist (precedencelist);
|
|
|
|
precedencelist = NULL;
|
2007-11-20 00:41:22 +00:00
|
|
|
|
2021-08-03 15:59:23 +00:00
|
|
|
/* Sort the entries so that the most specific ones are at
|
|
|
|
the beginning. */
|
|
|
|
qsort (new_precedence, nprecedencelist, sizeof (*new_precedence),
|
|
|
|
prefixcmp);
|
2006-05-04 06:38:07 +00:00
|
|
|
}
|
|
|
|
else
|
2021-08-03 15:59:23 +00:00
|
|
|
new_precedence = (struct prefixentry *) default_precedence;
|
|
|
|
|
|
|
|
struct scopeentry *new_scopes;
|
|
|
|
if (nscopelist > 0)
|
2006-05-04 06:38:07 +00:00
|
|
|
{
|
2021-08-03 15:59:23 +00:00
|
|
|
if (!scopelist_nullbits)
|
|
|
|
++nscopelist;
|
|
|
|
new_scopes = malloc (nscopelist * sizeof (*new_scopes));
|
|
|
|
if (new_scopes == NULL)
|
|
|
|
{
|
|
|
|
if (new_labels != default_labels)
|
|
|
|
free (new_labels);
|
|
|
|
if (new_precedence != default_precedence)
|
|
|
|
free (new_precedence);
|
|
|
|
goto no_file;
|
|
|
|
}
|
|
|
|
|
|
|
|
int i = nscopelist;
|
|
|
|
if (!scopelist_nullbits)
|
|
|
|
{
|
|
|
|
--i;
|
|
|
|
new_scopes[i].addr32 = 0;
|
|
|
|
new_scopes[i].netmask = 0;
|
|
|
|
new_scopes[i].scope = 14;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct scopelist *l = scopelist;
|
|
|
|
while (i-- > 0)
|
|
|
|
{
|
|
|
|
new_scopes[i] = l->entry;
|
|
|
|
l = l->next;
|
|
|
|
}
|
2007-11-20 00:41:22 +00:00
|
|
|
free_scopelist (scopelist);
|
2006-05-04 06:38:07 +00:00
|
|
|
|
2021-08-03 15:59:23 +00:00
|
|
|
/* Sort the entries so that the most specific ones are at
|
|
|
|
the beginning. */
|
|
|
|
qsort (new_scopes, nscopelist, sizeof (*new_scopes),
|
|
|
|
scopecmp);
|
2006-05-04 06:38:07 +00:00
|
|
|
}
|
2021-08-03 15:59:23 +00:00
|
|
|
else
|
|
|
|
new_scopes = (struct scopeentry *) default_scopes;
|
|
|
|
|
|
|
|
/* Now we are ready to replace the values. */
|
|
|
|
const struct prefixentry *old = labels;
|
|
|
|
labels = new_labels;
|
|
|
|
if (old != default_labels)
|
|
|
|
free ((void *) old);
|
|
|
|
|
|
|
|
old = precedence;
|
|
|
|
precedence = new_precedence;
|
|
|
|
if (old != default_precedence)
|
|
|
|
free ((void *) old);
|
|
|
|
|
|
|
|
const struct scopeentry *oldscope = scopes;
|
|
|
|
scopes = new_scopes;
|
|
|
|
if (oldscope != default_scopes)
|
|
|
|
free ((void *) oldscope);
|
|
|
|
|
|
|
|
save_gaiconf_mtime (&st);
|
|
|
|
return;
|
|
|
|
|
|
|
|
no_file:
|
|
|
|
free_prefixlist (labellist);
|
|
|
|
free_prefixlist (precedencelist);
|
|
|
|
free_scopelist (scopelist);
|
|
|
|
|
|
|
|
/* If we previously read the file but it is gone now, free the old data and
|
|
|
|
use the builtin one. Leave the reload flag alone. */
|
2022-12-27 21:11:42 +00:00
|
|
|
__libc_getaddrinfo_freemem ();
|
2006-05-04 06:38:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gaiconf_reload (void)
|
|
|
|
{
|
2021-03-02 20:06:02 +00:00
|
|
|
struct __stat64_t64 st;
|
|
|
|
if (__stat64_time64 (GAICONF_FNAME, &st) != 0
|
2012-08-17 18:47:06 +00:00
|
|
|
|| !check_gaiconf_mtime (&st))
|
2006-05-04 06:38:07 +00:00
|
|
|
gaiconf_init ();
|
|
|
|
}
|
|
|
|
|
2022-03-22 17:10:05 +00:00
|
|
|
static bool
|
|
|
|
try_connect (int *fdp, int *afp, struct sockaddr_in6 *source_addrp,
|
|
|
|
const struct sockaddr *addr, socklen_t addrlen, int family)
|
|
|
|
{
|
|
|
|
int fd = *fdp;
|
|
|
|
int af = *afp;
|
|
|
|
socklen_t sl = sizeof (*source_addrp);
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if (fd != -1 && __connect (fd, addr, addrlen) == 0
|
|
|
|
&& __getsockname (fd, (struct sockaddr *) source_addrp, &sl) == 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (errno == EAFNOSUPPORT && af == AF_INET6 && family == AF_INET)
|
|
|
|
{
|
|
|
|
/* This could mean IPv6 sockets are IPv6-only. */
|
|
|
|
if (fd != -1)
|
|
|
|
__close_nocancel_nostatus (fd);
|
|
|
|
*afp = af = AF_INET;
|
|
|
|
*fdp = fd = __socket (AF_INET, SOCK_DGRAM | SOCK_CLOEXEC,
|
|
|
|
IPPROTO_IP);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
__builtin_unreachable ();
|
|
|
|
}
|
2006-05-04 06:38:07 +00:00
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
int
|
|
|
|
getaddrinfo (const char *name, const char *service,
|
|
|
|
const struct addrinfo *hints, struct addrinfo **pai)
|
1996-10-21 01:26:31 +00:00
|
|
|
{
|
2006-04-18 23:35:12 +00:00
|
|
|
int i = 0, last_i = 0;
|
2003-11-18 07:04:13 +00:00
|
|
|
int nresults = 0;
|
2006-04-18 23:35:12 +00:00
|
|
|
struct addrinfo *p = NULL;
|
1996-10-21 01:26:31 +00:00
|
|
|
struct gaih_service gaih_service, *pservice;
|
2003-04-24 23:45:17 +00:00
|
|
|
struct addrinfo local_hints;
|
1996-10-21 01:26:31 +00:00
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
if (name != NULL && name[0] == '*' && name[1] == 0)
|
1997-02-19 04:43:53 +00:00
|
|
|
name = NULL;
|
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
if (service != NULL && service[0] == '*' && service[1] == 0)
|
1997-02-19 04:43:53 +00:00
|
|
|
service = NULL;
|
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
if (name == NULL && service == NULL)
|
1996-10-21 01:26:31 +00:00
|
|
|
return EAI_NONAME;
|
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
if (hints == NULL)
|
|
|
|
hints = &default_hints;
|
1996-10-21 01:26:31 +00:00
|
|
|
|
2003-04-24 23:45:17 +00:00
|
|
|
if (hints->ai_flags
|
|
|
|
& ~(AI_PASSIVE|AI_CANONNAME|AI_NUMERICHOST|AI_ADDRCONFIG|AI_V4MAPPED
|
2018-05-23 13:26:19 +00:00
|
|
|
|AI_IDN|AI_CANONIDN|DEPRECATED_AI_IDN
|
2004-08-05 09:45:35 +00:00
|
|
|
|AI_NUMERICSERV|AI_ALL))
|
1996-10-21 01:26:31 +00:00
|
|
|
return EAI_BADFLAGS;
|
|
|
|
|
2004-02-16 21:00:54 +00:00
|
|
|
if ((hints->ai_flags & AI_CANONNAME) && name == NULL)
|
1996-10-21 01:26:31 +00:00
|
|
|
return EAI_BADFLAGS;
|
|
|
|
|
2019-11-24 21:01:29 +00:00
|
|
|
if (hints->ai_family != AF_UNSPEC && hints->ai_family != AF_INET
|
|
|
|
&& hints->ai_family != AF_INET6)
|
|
|
|
return EAI_FAMILY;
|
|
|
|
|
2006-04-24 17:21:40 +00:00
|
|
|
struct in6addrinfo *in6ai = NULL;
|
2007-04-28 16:09:22 +00:00
|
|
|
size_t in6ailen = 0;
|
2006-04-16 21:34:32 +00:00
|
|
|
bool seen_ipv4 = false;
|
|
|
|
bool seen_ipv6 = false;
|
2011-06-22 19:00:54 +00:00
|
|
|
bool check_pf_called = false;
|
2007-04-28 16:09:22 +00:00
|
|
|
|
2003-04-24 23:45:17 +00:00
|
|
|
if (hints->ai_flags & AI_ADDRCONFIG)
|
|
|
|
{
|
2011-06-22 19:00:54 +00:00
|
|
|
/* We might need information about what interfaces are available.
|
|
|
|
Also determine whether we have IPv4 or IPv6 interfaces or both. We
|
|
|
|
cannot cache the results since new interfaces could be added at
|
|
|
|
any time. */
|
|
|
|
__check_pf (&seen_ipv4, &seen_ipv6, &in6ai, &in6ailen);
|
|
|
|
check_pf_called = true;
|
|
|
|
|
2003-04-24 23:45:17 +00:00
|
|
|
/* Now make a decision on what we return, if anything. */
|
2004-08-05 09:45:35 +00:00
|
|
|
if (hints->ai_family == PF_UNSPEC && (seen_ipv4 || seen_ipv6))
|
2003-04-24 23:45:17 +00:00
|
|
|
{
|
|
|
|
/* If we haven't seen both IPv4 and IPv6 interfaces we can
|
|
|
|
narrow down the search. */
|
2019-11-24 19:35:17 +00:00
|
|
|
if (seen_ipv4 != seen_ipv6)
|
2003-04-24 23:45:17 +00:00
|
|
|
{
|
|
|
|
local_hints = *hints;
|
|
|
|
local_hints.ai_family = seen_ipv4 ? PF_INET : PF_INET6;
|
|
|
|
hints = &local_hints;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((hints->ai_family == PF_INET && ! seen_ipv4)
|
|
|
|
|| (hints->ai_family == PF_INET6 && ! seen_ipv6))
|
2006-04-16 21:34:32 +00:00
|
|
|
{
|
|
|
|
/* We cannot possibly return a valid answer. */
|
2011-10-31 05:51:16 +00:00
|
|
|
__free_in6ai (in6ai);
|
2006-04-16 21:34:32 +00:00
|
|
|
return EAI_NONAME;
|
|
|
|
}
|
2003-04-24 23:45:17 +00:00
|
|
|
}
|
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
if (service && service[0])
|
|
|
|
{
|
|
|
|
char *c;
|
|
|
|
gaih_service.name = service;
|
|
|
|
gaih_service.num = strtoul (gaih_service.name, &c, 10);
|
2004-08-05 09:45:35 +00:00
|
|
|
if (*c != '\0')
|
|
|
|
{
|
|
|
|
if (hints->ai_flags & AI_NUMERICSERV)
|
2006-04-16 21:34:32 +00:00
|
|
|
{
|
2011-10-31 05:51:16 +00:00
|
|
|
__free_in6ai (in6ai);
|
2006-04-16 21:34:32 +00:00
|
|
|
return EAI_NONAME;
|
|
|
|
}
|
2004-08-05 09:45:35 +00:00
|
|
|
|
|
|
|
gaih_service.num = -1;
|
|
|
|
}
|
2004-09-26 08:43:34 +00:00
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
pservice = &gaih_service;
|
|
|
|
}
|
|
|
|
else
|
1996-10-21 01:26:31 +00:00
|
|
|
pservice = NULL;
|
|
|
|
|
2008-06-13 23:35:47 +00:00
|
|
|
struct addrinfo **end = &p;
|
2005-11-27 23:13:21 +00:00
|
|
|
unsigned int naddrs = 0;
|
2019-11-24 21:01:29 +00:00
|
|
|
struct scratch_buffer tmpbuf;
|
2016-05-12 08:39:29 +00:00
|
|
|
|
2019-11-24 21:01:29 +00:00
|
|
|
scratch_buffer_init (&tmpbuf);
|
|
|
|
last_i = gaih_inet (name, pservice, hints, end, &naddrs, &tmpbuf);
|
|
|
|
scratch_buffer_free (&tmpbuf);
|
2006-04-18 23:35:12 +00:00
|
|
|
|
2019-11-24 21:01:29 +00:00
|
|
|
if (last_i != 0)
|
2006-04-18 23:35:12 +00:00
|
|
|
{
|
2019-11-24 21:01:29 +00:00
|
|
|
freeaddrinfo (p);
|
2011-10-31 05:51:16 +00:00
|
|
|
__free_in6ai (in6ai);
|
2019-11-24 21:01:29 +00:00
|
|
|
|
|
|
|
return -last_i;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (*end)
|
|
|
|
{
|
|
|
|
end = &((*end)->ai_next);
|
|
|
|
++nresults;
|
2006-04-18 23:35:12 +00:00
|
|
|
}
|
1996-10-21 01:26:31 +00:00
|
|
|
|
2005-11-27 23:13:21 +00:00
|
|
|
if (naddrs > 1)
|
2003-11-18 07:04:13 +00:00
|
|
|
{
|
2006-05-04 06:38:07 +00:00
|
|
|
/* Read the config file. */
|
|
|
|
__libc_once_define (static, once);
|
|
|
|
__typeof (once) old_once = once;
|
|
|
|
__libc_once (once, gaiconf_init);
|
2003-11-18 07:04:13 +00:00
|
|
|
/* Sort results according to RFC 3484. */
|
2013-03-21 14:50:27 +00:00
|
|
|
struct sort_result *results;
|
|
|
|
size_t *order;
|
2003-11-18 07:04:13 +00:00
|
|
|
struct addrinfo *q;
|
2004-09-15 08:25:49 +00:00
|
|
|
struct addrinfo *last = NULL;
|
2004-08-14 20:13:23 +00:00
|
|
|
char *canonname = NULL;
|
2013-03-21 14:50:27 +00:00
|
|
|
bool malloc_results;
|
2013-04-22 04:54:00 +00:00
|
|
|
size_t alloc_size = nresults * (sizeof (*results) + sizeof (size_t));
|
2013-03-21 14:50:27 +00:00
|
|
|
|
|
|
|
malloc_results
|
2013-04-22 04:54:00 +00:00
|
|
|
= !__libc_use_alloca (alloc_size);
|
2013-03-21 14:50:27 +00:00
|
|
|
if (malloc_results)
|
|
|
|
{
|
2013-04-22 04:54:00 +00:00
|
|
|
results = malloc (alloc_size);
|
2013-03-21 14:50:27 +00:00
|
|
|
if (results == NULL)
|
|
|
|
{
|
|
|
|
__free_in6ai (in6ai);
|
|
|
|
return EAI_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2013-04-22 04:54:00 +00:00
|
|
|
results = alloca (alloc_size);
|
2013-03-21 14:50:27 +00:00
|
|
|
order = (size_t *) (results + nresults);
|
2003-11-18 07:04:13 +00:00
|
|
|
|
2011-06-22 19:00:54 +00:00
|
|
|
/* Now we definitely need the interface information. */
|
|
|
|
if (! check_pf_called)
|
|
|
|
__check_pf (&seen_ipv4, &seen_ipv6, &in6ai, &in6ailen);
|
|
|
|
|
2007-11-14 06:58:35 +00:00
|
|
|
/* If we have information about deprecated and temporary addresses
|
2006-04-16 21:34:32 +00:00
|
|
|
sort the array now. */
|
|
|
|
if (in6ai != NULL)
|
|
|
|
qsort (in6ai, in6ailen, sizeof (*in6ai), in6aicmp);
|
|
|
|
|
2007-09-19 22:12:22 +00:00
|
|
|
int fd = -1;
|
|
|
|
int af = AF_UNSPEC;
|
|
|
|
|
2004-09-15 08:25:49 +00:00
|
|
|
for (i = 0, q = p; q != NULL; ++i, last = q, q = q->ai_next)
|
2003-11-18 07:04:13 +00:00
|
|
|
{
|
|
|
|
results[i].dest_addr = q;
|
2007-11-14 06:58:35 +00:00
|
|
|
results[i].native = -1;
|
2008-01-10 20:00:52 +00:00
|
|
|
order[i] = i;
|
2003-11-18 07:04:13 +00:00
|
|
|
|
2004-09-25 15:06:34 +00:00
|
|
|
/* If we just looked up the address for a different
|
2004-09-15 08:25:49 +00:00
|
|
|
protocol, reuse the result. */
|
|
|
|
if (last != NULL && last->ai_addrlen == q->ai_addrlen
|
|
|
|
&& memcmp (last->ai_addr, q->ai_addr, q->ai_addrlen) == 0)
|
2003-11-18 07:04:13 +00:00
|
|
|
{
|
2004-09-15 08:25:49 +00:00
|
|
|
memcpy (&results[i].source_addr, &results[i - 1].source_addr,
|
|
|
|
results[i - 1].source_addr_len);
|
|
|
|
results[i].source_addr_len = results[i - 1].source_addr_len;
|
|
|
|
results[i].got_source_addr = results[i - 1].got_source_addr;
|
2006-04-16 21:34:32 +00:00
|
|
|
results[i].source_addr_flags = results[i - 1].source_addr_flags;
|
2007-11-12 23:55:58 +00:00
|
|
|
results[i].prefixlen = results[i - 1].prefixlen;
|
2007-11-14 06:58:35 +00:00
|
|
|
results[i].index = results[i - 1].index;
|
2004-09-15 08:25:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-11-12 23:55:58 +00:00
|
|
|
results[i].got_source_addr = false;
|
2006-04-16 21:34:32 +00:00
|
|
|
results[i].source_addr_flags = 0;
|
2007-11-12 23:55:58 +00:00
|
|
|
results[i].prefixlen = 0;
|
2007-11-14 06:58:35 +00:00
|
|
|
results[i].index = 0xffffffffu;
|
2006-04-16 21:34:32 +00:00
|
|
|
|
2004-09-25 15:06:34 +00:00
|
|
|
/* We overwrite the type with SOCK_DGRAM since we do not
|
|
|
|
want connect() to connect to the other side. If we
|
|
|
|
cannot determine the source address remember this
|
|
|
|
fact. */
|
2007-09-19 22:12:22 +00:00
|
|
|
if (fd == -1 || (af == AF_INET && q->ai_family == AF_INET6))
|
|
|
|
{
|
|
|
|
if (fd != -1)
|
2017-07-03 18:22:58 +00:00
|
|
|
__close_nocancel_nostatus (fd);
|
2007-09-19 22:12:22 +00:00
|
|
|
af = q->ai_family;
|
2017-04-19 05:45:04 +00:00
|
|
|
fd = __socket (af, SOCK_DGRAM | SOCK_CLOEXEC, IPPROTO_IP);
|
2007-09-19 22:12:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Reset the connection. */
|
|
|
|
struct sockaddr sa = { .sa_family = AF_UNSPEC };
|
|
|
|
__connect (fd, &sa, sizeof (sa));
|
|
|
|
}
|
|
|
|
|
2022-03-22 17:10:05 +00:00
|
|
|
if (try_connect (&fd, &af, &results[i].source_addr, q->ai_addr,
|
|
|
|
q->ai_addrlen, q->ai_family))
|
2004-09-15 08:25:49 +00:00
|
|
|
{
|
2022-03-22 17:10:05 +00:00
|
|
|
results[i].source_addr_len = sizeof (results[i].source_addr);
|
2004-09-25 15:06:34 +00:00
|
|
|
results[i].got_source_addr = true;
|
2006-04-16 21:34:32 +00:00
|
|
|
|
2007-11-12 23:55:58 +00:00
|
|
|
if (in6ai != NULL)
|
2006-04-16 21:34:32 +00:00
|
|
|
{
|
2007-09-19 22:12:22 +00:00
|
|
|
/* See whether the source address is on the list of
|
[BZ #2510, BZ #2830, BZ #3137, BZ #3313, BZ #3426, BZ #3465, BZ #3480, BZ #3483, BZ #3493, BZ #3514, BZ #3515, BZ #3664, BZ #3673, BZ #3674]
2007-01-11 Jakub Jelinek <jakub@redhat.com>
* sysdeps/i386/soft-fp/sfp-machine.h: Remove.
* sysdeps/x86_64/soft-fp/sfp-machine.h: Likewise.
2007-01-10 Ulrich Drepper <drepper@redhat.com>
* io/fts.c: Make sure fts_cur is always valid after return from
fts_read.
Patch by Miloslav Trmac <mitr@redhat.com>.
2006-10-27 Richard Sandiford <richard@codesourcery.com>
* elf/elf.h (R_MIPS_GLOB_DAT): Define.
(R_MIPS_NUM): Bump by 1.
2007-01-03 Jakub Jelinek <jakub@redhat.com>
* posix/execvp.c: Include alloca.h.
(allocate_scripts_argv): Renamed to...
(scripts_argv): ... this. Don't allocate buffer here nor count
arguments.
(execvp): Use alloca if possible.
* posix/Makefile: Add rules to build and run tst-vfork3 test.
* posix/tst-vfork3.c: New test.
* stdlib/Makefile (tst-strtod3-ENV): Define.
2007-01-02 Ulrich Drepper <drepper@redhat.com>
* posix/getconf.c: Update copyright year.
* nss/getent.c: Likewise.
* iconv/iconvconfig.c: Likewise.
* iconv/iconv_prog.c: Likewise.
* elf/ldconfig.c: Likewise.
* catgets/gencat.c: Likewise.
* csu/version.c: Likewise.
* elf/ldd.bash.in: Likewise.
* elf/sprof.c (print_version): Likewise.
* locale/programs/locale.c: Likewise.
* locale/programs/localedef.c: Likewise.
* nscd/nscd.c (print_version): Likewise.
* debug/xtrace.sh: Likewise.
* malloc/memusage.sh: Likewise.
* malloc/mtrace.pl: Likewise.
* debug/catchsegv.sh: Likewise.
2006-12-24 Ulrich Drepper <drepper@redhat.com>
* malloc/malloc.c (sYSMALLOc): Remove some unnecessary alignment
attempts.
2006-12-23 Ulrich Drepper <drepper@redhat.com>
* posix/wordexp.c: Remove some unnecessary tests.
2006-12-20 SUGIOKA Toshinobu <sugioka@itonet.co.jp>
* sysdeps/unix/sysv/linux/sh/bits/shm.h: New file.
* nss/getXXbyYY_r.c: Include atomic.h.
(INTERNAL (REENTRANT_NAME)): Write startp after start_fct,
add atomic_write_barrier () in between.
2006-11-28 Jakub Jelinek <jakub@redhat.com>
* elf/dl-support.c: Include dl-procinfo.h.
* sysdeps/powerpc/dl-procinfo.h (PPC_PLATFORM_POWER4,
PPC_PLATFORM_PPC970, PPC_PLATFORM_POWER5, PPC_PLATFORM_POWER5_PLUS,
PPC_PLATFORM_POWER6, PPC_PLATFORM_CELL_BE, PPC_PLATFORM_POWER6X):
Define.
(_dl_string_platform): Use PPC_PLATFORM_* macros instead of
hardcoded constants.
* sysdeps/powerpc/dl-procinfo.c (_dl_powerpc_platform): Use
PPC_PLATFORM_* macros for array designators.
2006-11-11 Steven Munroe <sjmunroe@us.ibm.com>
* sysdeps/powerpc/dl-procinfo.c (_dl_powerpc_cap_flags): Add 3 new cap
names to the beginning.
(_dl_powerpc_platforms): Add "power6x".
* sysdeps/powerpc/dl-procinfo.h (_DL_HWCAP_FIRST): Decrease.
(HWCAP_IMPORTANT): Add PPC_FEATURE_HAS_DFP.
(_DL_PLATFORMS_COUNT): Increase.
(_dl_string_platform): Handle power6x case.
* sysdeps/powerpc/sysdep.h (PPC_FEATURE_PA6T, PPC_FEATURE_HAS_DFP,
PPC_FEATURE_POWER6_EXT): Define.
(PPC_FEATURE_POWER5, PPC_FEATURE_POWER5_PLUS): Correct Comment.
[-2^31 .. 2^31) range.
* sysdeps/unix/sysv/linux/bits/statvfs.h: Define ST_RELATIME.
* sysdeps/unix/sysv/linux/internal_statvfs.c (__statvfs_getflags):
Handle relatime mount option.
2006-12-13 Jakub Jelinek <jakub@redhat.com>
* sysdeps/unix/sysv/linux/powerpc/powerpc32/setcontext.S: Include
kernel-features.h.
2006-12-11 Ulrich Drepper <drepper@redhat.com>
* stdlib/strtod_l.c (____STRTOF_INTERNAL): Parse thousand
separators also if no non-zero digits found.
* stdlib/Makefile (tests): Add tst-strtod3.
[BZ #3664]
* stdlib/strtod_l.c (____STRTOF_INTERNAL): Fix test to recognize
empty parsed strings.
* stdlib/Makefile (tests): Add tst-strtod2.
* stdlib/tst-strtod2.c: New file.
[BZ #3673]
* stdlib/strtod_l.c (____STRTOF_INTERNAL): Fix exp_limit
computation.
* stdlib/Makefile (tests): Add tst-atof2.
* stdlib/tst-atof2.c: New file.
[BZ #3674]
* stdlib/strtod_l.c (____STRTOF_INTERNAL): Adjust exponent value
correctly if removing trailing zero of hex-float.
* stdlib/Makefile (tests): Add tst-atof1.
* stdlib/tst-atof1.c: New file.
* misc/mntent_r.c (__hasmntopt): Check p[optlen] even when p == rest.
Start searching for next comma at p rather than rest.
* misc/Makefile (tests): Add tst-mntent2.
* misc/tst-mntent2.c: New test.
2006-12-08 Ulrich Drepper <drepper@redhat.com>
* malloc/memusage.c: Handle realloc with new size of zero and
non-NULL pointer correctly.
(me): Really write first record twice.
(struct entry): Make format bi-arch safe.
(dest): Write out more realloc statistics.
* malloc/memusagestat.c (struct entry): Make format bi-arch safe.
2006-12-05 Jakub Jelinek <jakub@redhat.com>
* nis/nis_subr.c (nis_getnames): Revert last change.
2006-12-03 Kaz Kojima <kkojima@rr.iij4u.or.jp>
* sysdeps/unix/sysv/linux/sh/sys/io.h: Removed.
2006-11-30 H.J. Lu <hongjiu.lu@intel.com>
* sysdeps/i386/i686/memcmp.S: Use jump table as the base of
jump table entries.
2006-11-30 Jan Kratochvil <jan.kratochvil@redhat.com>
* sysdeps/unix/sysv/linux/i386/clone.S: Provide CFI for the outermost
`clone' function to ensure proper unwinding stop of gdb.
* sysdeps/unix/sysv/linux/x86_64/clone.S: Likewise.
2006-12-01 Ulrich Drepper <drepper@redhat.com>
* nscd/nscd.init: Remove obsolete and commented-out -S option
handling.
2006-11-23 Jakub Jelinek <jakub@redhat.com>
[BZ #3514]
* manual/string.texi (strncmp): Fix pastos from wcscmp description.
[BZ #3515]
* manual/string.texi (strtok): Remove duplicate paragraph.
2006-12-01 Jan Kratochvil <jan.kratochvil@redhat.com>
* sysdeps/unix/sysv/linux/x86_64/sigaction.c: Fix compatibility with
libgcc not supporting `rflags' unwinding (register # >= 17).
2006-11-30 Jakub Jelinek <jakub@redhat.com>
* sunrpc/svc_run.c (svc_run): Set my_pollfd to new_pollfd if realloc
succeeded.
2006-11-29 Daniel Jacobowitz <dan@codesourcery.com>
Jakub Jelinek <jakub@redhat.com>
Jan Kratochvil <jan.kratochvil@redhat.com>
* sysdeps/unix/sysv/linux/x86_64/sigaction.c (restore_rt): Add correct
unwind information.
* sysdeps/unix/sysv/linux/x86_64/Makefile: Provide symbols for
'restore_rt' even in the 'signal' directory.
* sysdeps/unix/sysv/linux/x86_64/ucontext_i.sym: Extend the regs list.
malloc crashed. Don't allocate memory unnecessarily in each
loop.
2006-10-21 Jakub Jelinek <jakub@redhat.com>
* resolv/mapv4v6addr.h (map_v4v6_address): Fix last change.
2006-11-20 Ulrich Drepper <drepper@redhat.com>
* resolv/mapv4v6addr.h (map_v4v6_address): Optimize a bit.
2006-11-18 Bruno Haible <bruno@clisp.org>
* sysdeps/unix/sysv/linux/i386/getgroups.c (__getgroups): Invoke
__sysconf only after having tried to call getgroups32.
2006-11-19 Ulrich Drepper <drepper@redhat.com>
* nss/nss_files/files-hosts.c (LINE_PARSER): Support IPv6-style
addresses for IPv4 queries if they can be mapped.
2006-11-16 Jakub Jelinek <jakub@redhat.com>
* sysdeps/x86_64/fpu/s_copysignf.S (__copysignf): Switch to .text.
* sysdeps/x86_64/fpu/s_copysign.S (__copysign): Likewise.
(signmask): Add .size directive.
(othermask): Add .type directive.
2006-11-14 Ulrich Drepper <drepper@redhat.com>
* po/nl.po: Update from translation team.
* timezone/zdump.c: Redo fix for BZ #3137.
2006-11-14 Jakub Jelinek <jakub@redhat.com>
* nss/nss_files/files-alias.c (get_next_alias): Set line back
to first_unused after parsing :include: file.
* timezone/africa: Update from tzdata2006o.
* timezone/antarctica: Likewise.
* timezone/asia: Likewise.
* timezone/australasia: Likewise.
* timezone/backward: Likewise.
* timezone/europe: Likewise.
* timezone/iso3166.tab: Likewise.
* timezone/northamerica: Likewise.
* timezone/southamerica: Likewise.
* timezone/zone.tab: Likewise.
* time/tzfile.c (__tzfile_read): Extend to handle new file format
on machines with 64-bit time_t.
* timezone/checktab.awk: Update from tzcode2006o.
* timezone/ialloc.c: Likewise.
* timezone/private.h: Likewise.
* timezone/scheck.c: Likewise.
* timezone/tzfile.h: Likewise.
* timezone/tzselect.ksh: Likewise.
* timezone/zdump.c: Likewise.
* timezone/zic.c: Likewise.
[BZ #3483]
* elf/ldconfig.c (main): Call setlocale and textdomain.
Patch mostly by Benno Schulenberg <bensberg@justemail.net>.
[BZ #3480]
* manual/argp.texi: Fix typos.
* manual/charset.texi: Likewise.
* manual/errno.texi: Likewise.
* manual/filesys.texi: Likewise.
* manual/lang.texi: Likewise.
* manual/maint.texi: Likewise.
* manual/memory.texi: Likewise.
* manual/message.texi: Likewise.
* manual/resource.texi: Likewise.
* manual/search.texi: Likewise.
* manual/signal.texi: Likewise.
* manual/startup.texi: Likewise.
* manual/stdio.texi: Likewise.
* manual/sysinfo.texi: Likewise.
* manual/syslog.texi: Likewise.
* manual/time.texi: Likewise.
Patch by Ralf Wildenhues <Ralf.Wildenhues@gmx.de>.
[BZ #3465]
* sunrpc/clnt_raw.c: Minimal message improvements.
* sunrpc/pm_getmaps.c: Likewise.
* nis/nss_nisplus/nisplus-publickey.c: Likewise.
* nis/nis_print_group_entry.c: Likewise.
* locale/programs/repertoire.c: Likewise.
* locale/programs/charmap.c: Likewise.
* malloc/memusage.sh: Likewise.
* elf/dl-deps.c: Likewise.
* locale/programs/ld-collate.c: Likewise.
* libio/vswprintf.c: Likewise.
* malloc/memusagestat.c: Likewise.
* sunrpc/auth_unix.c: Likewise.
* sunrpc/rpc_main.c: Likewise.
* nscd/cache.c: Likewise.
* locale/programs/repertoire.c: Unify output messages.
* locale/programs/charmap.c: Likewise.
* locale/programs/ld-ctype.c: Likewise.
* locale/programs/ld-monetary.c: Likewise.
* locale/programs/ld-numeric.c: Likewise.
* locale/programs/ld-time.c: Likewise.
* elf/ldconfig.c: Likewise.
* nscd/selinux.c: Likewise.
* elf/cache.c: Likewise.
Patch mostly by Benno Schulenberg <bensberg@justemail.net>.
2006-11-10 Jakub Jelinek <jakub@redhat.com>
* string/strxfrm_l.c (STRXFRM): Fix trailing \1 optimization
if N is one bigger than return value.
* string/tst-strxfrm2.c (do_test): Also test strxfrm with l1 + 1
and l1 last arguments, if buf is defined, verify the return value
equals to strlen (buf) and verify no byte beyond passed length
is modified.
2006-11-10 Ulrich Drepper <drepper@redhat.com>
* po/sv.po: Update from translation team.
* sysdeps/gnu/siglist.c (__old_sys_siglist, __old_sys_sigabbrev):
Use __new_sys_siglist instead of _sys_siglist_internal as
second macro argument.
(_old_sys_siglist): Use declare_symbol_alias macro instead of
strong_alias.
2006-11-09 Ulrich Drepper <drepper@redhat.com>
[BZ #3493]
* posix/unistd.h (sysconf): Remove const attribute.
* sysdeps/posix/getaddrinfo.c (getaddrinfo): Fix test for
temporary or deprecated addresses.
Patch by Sridhar Samudrala <sri@us.ibm.com>.
* string/Makefile (tests): Add tst-strxfrm2.
* string/tst-strxfrm2.c: New file.
2006-10-09 Jakub Jelinek <jakub@redhat.com>
* elf/dl-debug.c (_dl_debug_initialize): Check r->r_map for 0
rather than r->r_brk.
* string/strxfrm_l.c (STRXFRM): Do the trailing \1 removal
optimization even if needed > n.
2006-11-07 Jakub Jelinek <jakub@redhat.com>
* include/libc-symbols.h (declare_symbol): Rename to...
(declare_symbol_alias): ... this. Add ORIGINAL argument, imply
strong_alias (ORIGINAL, SYMBOL) in asm to make sure it preceedes
.size directive.
* sysdeps/gnu/errlist-compat.awk: Adjust for declare_symbol_alias
changes.
* sysdeps/gnu/siglist.c: Likewise.
2006-11-03 Steven Munroe <sjmunroe@us.ibm.com>
* sysdeps/powerpc/fpu/bits/mathinline.h
[__LIBC_INTERNAL_MATH_INLINES]: Moved to ...
* sysdeps/powerpc/fpu/math_private.h: ...here. New file.
2006-11-05 Ulrich Drepper <drepper@redhat.com>
* sysdeps/unix/sysv/linux/i386/sysconf.c (intel_check_word):
Update handling of cache descriptor 0x49 for new models.
* sysdeps/unix/sysv/linux/x86_64/sysconf.c (intel_check_word):
Likewise.
2006-11-02 Ulrich Drepper <drepper@redhat.com>
* configure.in: Work around ld --help change and avoid -z relro
test completely if the architecture doesn't care about security.
2006-11-01 Ulrich Drepper <drepper@redhat.com>
* po/sv.po: Update from translation team.
2006-10-31 Ulrich Drepper <drepper@redhat.com>
* stdlib/atexit.c (atexit): Don't mark as hidden when used to
generate compatibility version.
2006-10-29 Ulrich Drepper <drepper@redhat.com>
* configure.in: Relax -z relro requirement a bit.
* po/sv.po: Update from translation team.
2006-10-29 Jakub Jelinek <jakub@redhat.com>
* elf/dl-sym.c (do_sym): Use RTLD_SINGLE_THREAD_P.
* elf/dl-runtime.c (_dl_fixup, _dl_profile_fixup): Likewise.
* elf/dl-close.c (_dl_close_worker): Likewise.
* elf/dl-open.c (_dl_open_worker): Likewise.
* sysdeps/generic/sysdep-cancel.h (RTLD_SINGLE_THREAD_P): Define.
* configure.in: Require assembler support for visibility, compiler
support for visibility and aliases, linker support for various -z
options.
* Makeconfig: Remove conditional code which now is unnecessary.
* config.h.in: Likewise.
* config.make.in: Likewise.
* dlfcn/Makefile: Likewise.
* elf/Makefile: Likewise.
* elf/dl-load.c: Likewise.
* elf/rtld.c: Likewise.
* include/libc-symbols.h: Likewise.
* include/stdio.h: Likewise.
* io/Makefile: Likewise.
* io/fstat.c: Likewise.
* io/fstat64.c: Likewise.
* io/fstatat.c: Likewise.
* io/fstatat64.c: Likewise.
* io/lstat.c: Likewise.
* io/lstat64.c: Likewise.
* io/mknod.c: Likewise.
* io/mknodat.c: Likewise.
* io/stat.c: Likewise.
* io/stat64.c: Likewise.
* libio/stdio.c: Likewise.
* nscd/Makefile: Likewise.
* stdlib/Makefile: Likewise.
* stdlib/atexit.c: Likewise.
* sysdeps/generic/ldsodefs.h: Likewise.
* sysdeps/i386/dl-machine.h: Likewise.
* sysdeps/i386/sysdep.h: Likewise.
* sysdeps/i386/i686/memcmp.S: Likewise.
* sysdeps/powerpc/powerpc32/sysdep.h: Likewise.
* sysdeps/unix/sysv/linux/i386/sigaction.c: Likewise.
* sysdeps/unix/sysv/linux/x86_64/sigaction.c: Likewise.
* Makerules: USE_TLS support is now default.
* tls.make.c: Likewise.
* csu/Versions: Likewise.
* csu/libc-start.c: Likewise.
* csu/libc-tls.c: Likewise.
* csu/version.c: Likewise.
* dlfcn/dlinfo.c: Likewise.
* elf/dl-addr.c: Likewise.
* elf/dl-cache.c: Likewise.
* elf/dl-close.c: Likewise.
* elf/dl-iteratephdr.c: Likewise.
* elf/dl-load.c: Likewise.
* elf/dl-lookup.c: Likewise.
* elf/dl-object.c: Likewise.
* elf/dl-open.c: Likewise.
* elf/dl-reloc.c: Likewise.
* elf/dl-support.c: Likewise.
* elf/dl-sym.c: Likewise.
* elf/dl-sysdep.c: Likewise.
* elf/dl-tls.c: Likewise.
* elf/ldconfig.c: Likewise.
* elf/rtld.c: Likewise.
* elf/tst-tls-dlinfo.c: Likewise.
* elf/tst-tls1.c: Likewise.
* elf/tst-tls10.h: Likewise.
* elf/tst-tls14.c: Likewise.
* elf/tst-tls2.c: Likewise.
* elf/tst-tls3.c: Likewise.
* elf/tst-tls4.c: Likewise.
* elf/tst-tls5.c: Likewise.
* elf/tst-tls6.c: Likewise.
* elf/tst-tls7.c: Likewise.
* elf/tst-tls8.c: Likewise.
* elf/tst-tls9.c: Likewise.
* elf/tst-tlsmod1.c: Likewise.
* elf/tst-tlsmod13.c: Likewise.
* elf/tst-tlsmod13a.c: Likewise.
* elf/tst-tlsmod14a.c: Likewise.
* elf/tst-tlsmod2.c: Likewise.
* elf/tst-tlsmod3.c: Likewise.
* elf/tst-tlsmod4.c: Likewise.
* elf/tst-tlsmod5.c: Likewise.
* elf/tst-tlsmod6.c: Likewise.
* include/errno.h: Likewise.
* include/link.h: Likewise.
* include/tls.h: Likewise.
* locale/global-locale.c: Likewise.
* locale/localeinfo.h: Likewise.
* malloc/arena.c: Likewise.
* malloc/hooks.c: Likewise.
* malloc/malloc.c: Likewise.
* resolv/Versions: Likewise.
* sysdeps/alpha/dl-machine.h: Likewise.
* sysdeps/alpha/libc-tls.c: Likewise.
* sysdeps/generic/ldsodefs.h: Likewise.
* sysdeps/generic/tls.h: Likewise.
* sysdeps/i386/dl-machine.h: Likewise.
* sysdeps/ia64/dl-machine.h: Likewise.
* sysdeps/ia64/libc-tls.c: Likewise.
* sysdeps/mach/hurd/fork.c: Likewise.
* sysdeps/mach/hurd/i386/tls.h: Likewise.
* sysdeps/powerpc/powerpc32/dl-machine.c: Likwise.
* sysdeps/powerpc/powerpc32/dl-machine.h: Likewise.
* sysdeps/powerpc/powerpc64/dl-machine.h: Likewise.
* sysdeps/s390/libc-tls.c: Likewise.
* sysdeps/s390/s390-32/dl-machine.h: Likewise.
* sysdeps/s390/s390-64/dl-machine.h: Likewise.
* sysdeps/sh/dl-machine.h: Likewise.
* sysdeps/sparc/sparc32/dl-machine.h: Likewise.
* sysdeps/sparc/sparc64/dl-machine.h: Likewise.
* sysdeps/x86_64/dl-machine.h: Likewise.
[BZ #3426]
* stdlib/stdlib.h: Adjust comment for canonicalize_file_name to
reality.
2006-10-27 Jakub Jelinek <jakub@redhat.com>
* elf/dl-lookup.c (_dl_debug_bindings): Remove unused symbol_scope
argument.
(_dl_lookup_symbol_x): Adjust caller.
* sysdeps/generic/ldsodefs.h (struct link_namespaces): Remove
_ns_global_scope.
* elf/rtld.c (dl_main): Don't initialize _ns_global_scope.
* elf/dl-libc.c: Revert l_scope name changes.
* elf/dl-load.c: Likewise.
* elf/dl-object.c: Likewise.
* elf/rtld.c: Likewise.
* elf/dl-close.c (_dl_close): Likewise.
* elf/dl-open.c (dl_open_worker): Likewise. If not SINGLE_THREAD_P,
always use __rtld_mrlock_{change,done}. Always free old scope list
here if not l_scope_mem.
* elf/dl-runtime.c (_dl_fixup, _dl_profile_fixup): Revert l_scope name
change. Never free scope list here. Just __rtld_mrlock_lock before
the lookup and __rtld_mrlock_unlock it after the lookup.
* elf/dl-sym.c: Likewise.
* include/link.h (struct r_scoperec): Remove.
(struct link_map): Replace l_scoperec with l_scope, l_scoperec_mem
with l_scope_mem and l_scoperec_lock with l_scope_lock.
2006-10-25 Ulrich Drepper <drepper@redhat.com>
* sysdeps/gnu/netinet/tcp.h: Define TCP_CONGESTION.
2006-10-18 Ulrich Drepper <drepper@redhat.com>
* configure.in: Disable building profile libraries by default.
2006-10-18 Ulrich Drepper <drepper@redhat.com>
* elf/dl-lookup.c (_dl_lookup_symbol_x): Add warning to
_dl_lookup_symbol_x code.
2006-10-17 Jakub Jelinek <jakub@redhat.com>
* elf/dl-runtime.c: Include sysdep-cancel.h.
(_dl_fixup, _dl_profile_fixup): Use __rtld_mrlock_* and
scoperec->nusers only if !SINGLE_THREAD_P. Use atomic_*
instead of catomic_* macros.
* elf/dl-sym.c: Include sysdep-cancel.h.
(do_sym): Use __rtld_mrlock_* and scoperec->nusers only
if !SINGLE_THREAD_P. Use atomic_* instead of catomic_* macros.
* elf/dl-close.c: Include sysdep-cancel.h.
(_dl_close): Use __rtld_mrlock_* and scoperec->nusers only
if !SINGLE_THREAD_P. Use atomic_* instead of catomic_* macros.
* elf/dl-open.c: Include sysdep-cancel.h.
(dl_open_worker): Use __rtld_mrlock_* and scoperec->nusers only
if !SINGLE_THREAD_P. Use atomic_* instead of catomic_* macros.
2006-10-17 Jakub Jelinek <jakub@redhat.com>
[BZ #3313]
* malloc/malloc.c (malloc_consolidate): Set maxfb to address of last
fastbin rather than end of fastbin array.
2006-10-18 Ulrich Drepper <drepper@redhat.com>
* sysdeps/i386/i486/bits/atomic.h (catomic_decrement): Use correct
body macro.
* sysdeps/x86_64/bits/atomic.h
(__arch_c_compare_and_exchange_val_64_acq): Add missing casts.
(catomic_decrement): Use correct body macro.
2006-10-17 Jakub Jelinek <jakub@redhat.com>
* include/atomic.h: Add a unique prefix to all local variables
in macros.
* csu/tst-atomic.c (do_test): Test also catomic_* macros.
2006-10-14 Ulrich Drepper <drepper@redhat.com>
* resolv/arpa/nameser.h: Document that ns_t_a6 is deprecated.
[BZ #3313]
* malloc/malloc.c (malloc_consolidate): Don't use get_fast_max to
determine highest fast bin to consolidate, always look into all of
them.
(do_check_malloc_state): Only require for empty bins for large
sizes in main arena.
* libio/stdio.h: Add more __wur attributes.
2006-11-12 Andreas Jaeger <aj@suse.de>
[BZ #2510]
* manual/search.texi (Hash Search Function): Clarify.
(Array Search Function): Clarify.
2006-11-12 Joseph Myers <joseph@codesourcery.com>
[BZ #2830]
* math/atest-exp.c (main): Cast hex value to mp_limb_t before
shifting.
* math/atest-exp2.c (read_mpn_hex): Likewise.
* math/atest-sincos.c (main): Likewise.
* sysdeps/unix/sysv/linux/syscalls.list: Add epoll_pwait.
* sysdeps/unix/sysv/linux/sys/epoll.h: Declare epoll_pwait.
* sysdeps/unix/sysv/linux/Versions (libc): Add epoll_pwait for
version GLIBC_2.6.
* Versions.def: Add GLIBC_2.6 for libc.
* sysdeps/i386/i486/bits/atomic.h: Add catomic_* support.
2006-10-11 Jakub Jelinek <jakub@redhat.com>
* malloc/malloc.c (_int_malloc): Remove unused any_larger variable.
* nis/nis_defaults.c (__nis_default_access): Don't call getenv twice.
* nis/nis_subr.c (nis_getnames): Use __secure_getenv instead of getenv.
* sysdeps/generic/unsecvars.h: Add NIS_PATH.
2006-10-11 Ulrich Drepper <drepper@redhat.com>
* include/atomic.c: Define catomic_* operations.
* sysdeps/x86_64/bits/atomic.h: Likewise. Fix a few minor problems.
* stdlib/cxa_finalize.c: Use catomic_* operations instead of atomic_*.
* malloc/memusage.c: Likewise.
* gmon/mcount.c: Likewise.
* elf/dl-close.c: Likewise.
* elf/dl-open.c: Likewise.
* elf/dl-profile.c: Likewise.
* elf/dl-sym.c: Likewise.
* elf/dl-runtime.c: Likewise.
* elf/dl-fptr.c: Likewise.
* resolv/res_libc.c: Likewise.
2006-10-10 Roland McGrath <roland@frob.com>
* sysdeps/mach/hurd/utimes.c: Use a union to avoid an improper cast.
* sysdeps/mach/hurd/futimes.c: Likewise.
* sysdeps/mach/hurd/lutimes.c: Likewise.
2006-10-09 Ulrich Drepper <drepper@redhat.com>
Jakub Jelinek <jakub@redhat.com>
Implement reference counting of scope records.
* elf/dl-close.c (_dl_close): Remove all scopes from removed objects
from the list in objects which remain. Always allocate new scope
record.
* elf/dl-open.c (dl_open_worker): When growing array for scopes,
don't resize, allocate a new one.
* elf/dl-runtime.c: Update reference counters before using a scope
array.
* elf/dl-sym.c: Likewise.
* elf/dl-libc.c: Adjust for l_scope name change.
* elf/dl-load.c: Likewise.
* elf/dl-object.c: Likewise.
* elf/rtld.c: Likewise.
* include/link.h: Include <rtld-lowlevel.h>. Define struct
r_scoperec. Replace r_scope with pointer to r_scoperec structure.
Add l_scoperec_lock.
* sysdeps/generic/ldsodefs.h: Include <rtld-lowlevel.h>.
* sysdeps/generic/rtld-lowlevel.h: New file.
* include/atomic.h: Rename atomic_and to atomic_and_val and
atomic_or to atomic_or_val. Define new macros atomic_and and
atomic_or which do not return values.
* sysdeps/x86_64/bits/atomic.h: Define atomic_and and atomic_or.
Various cleanups.
* sysdeps/i386/i486/bits/atomic.h: Likewise.
* po/sv.po: Update from translation team.
2006-10-07 Ulrich Drepper <drepper@redhat.com>
* Versions.def: Add GLIBC_2.6 to libpthread.
* include/shlib-compat.h (SHLIB_COMPAT): Expand parameters before use.
(versioned_symbol): Likewise.
(compat_symbol): Likewise.
* po/tr.po: Update from translation team.
* nis/Banner: Removed. It's been integral part forever and the
author info is incomplete anyway.
* libio/Banner: Likewise.
2006-10-06 Ulrich Drepper <drepper@redhat.com>
* version.h (VERSION): Bump to 2.5.90 for new development tree.
2007-01-11 21:51:07 +00:00
|
|
|
deprecated or temporary addresses. */
|
2006-04-16 21:34:32 +00:00
|
|
|
struct in6addrinfo tmp;
|
2007-11-12 23:55:58 +00:00
|
|
|
|
|
|
|
if (q->ai_family == AF_INET && af == AF_INET)
|
|
|
|
{
|
|
|
|
struct sockaddr_in *sinp
|
|
|
|
= (struct sockaddr_in *) &results[i].source_addr;
|
|
|
|
tmp.addr[0] = 0;
|
|
|
|
tmp.addr[1] = 0;
|
|
|
|
tmp.addr[2] = htonl (0xffff);
|
2013-10-25 04:25:38 +00:00
|
|
|
/* Special case for lo interface, the source address
|
|
|
|
being possibly different than the interface
|
|
|
|
address. */
|
|
|
|
if ((ntohl(sinp->sin_addr.s_addr) & 0xff000000)
|
|
|
|
== 0x7f000000)
|
|
|
|
tmp.addr[3] = htonl(0x7f000001);
|
|
|
|
else
|
|
|
|
tmp.addr[3] = sinp->sin_addr.s_addr;
|
2007-11-12 23:55:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct sockaddr_in6 *sin6p
|
|
|
|
= (struct sockaddr_in6 *) &results[i].source_addr;
|
|
|
|
memcpy (tmp.addr, &sin6p->sin6_addr, IN6ADDRSZ);
|
|
|
|
}
|
2006-04-16 21:34:32 +00:00
|
|
|
|
|
|
|
struct in6addrinfo *found
|
|
|
|
= bsearch (&tmp, in6ai, in6ailen, sizeof (*in6ai),
|
|
|
|
in6aicmp);
|
|
|
|
if (found != NULL)
|
2007-11-12 23:55:58 +00:00
|
|
|
{
|
|
|
|
results[i].source_addr_flags = found->flags;
|
|
|
|
results[i].prefixlen = found->prefixlen;
|
2007-11-14 06:58:35 +00:00
|
|
|
results[i].index = found->index;
|
2007-11-12 23:55:58 +00:00
|
|
|
}
|
2006-04-16 21:34:32 +00:00
|
|
|
}
|
2007-11-12 23:55:58 +00:00
|
|
|
|
|
|
|
if (q->ai_family == AF_INET && af == AF_INET6)
|
2007-09-19 22:12:22 +00:00
|
|
|
{
|
|
|
|
/* We have to convert the address. The socket is
|
|
|
|
IPv6 and the request is for IPv4. */
|
|
|
|
struct sockaddr_in6 *sin6
|
|
|
|
= (struct sockaddr_in6 *) &results[i].source_addr;
|
|
|
|
struct sockaddr_in *sin
|
|
|
|
= (struct sockaddr_in *) &results[i].source_addr;
|
|
|
|
assert (IN6_IS_ADDR_V4MAPPED (sin6->sin6_addr.s6_addr32));
|
2007-11-12 23:55:58 +00:00
|
|
|
sin->sin_family = AF_INET;
|
|
|
|
/* We do not have to initialize sin_port since this
|
|
|
|
fields has the same position and size in the IPv6
|
|
|
|
structure. */
|
|
|
|
assert (offsetof (struct sockaddr_in, sin_port)
|
|
|
|
== offsetof (struct sockaddr_in6, sin6_port));
|
|
|
|
assert (sizeof (sin->sin_port)
|
|
|
|
== sizeof (sin6->sin6_port));
|
2007-09-19 22:12:22 +00:00
|
|
|
memcpy (&sin->sin_addr,
|
|
|
|
&sin6->sin6_addr.s6_addr32[3], INADDRSZ);
|
2007-11-12 23:55:58 +00:00
|
|
|
results[i].source_addr_len = sizeof (struct sockaddr_in);
|
2007-09-19 22:12:22 +00:00
|
|
|
}
|
2004-09-15 08:25:49 +00:00
|
|
|
}
|
2004-09-25 15:06:34 +00:00
|
|
|
else
|
|
|
|
/* Just make sure that if we have to process the same
|
|
|
|
address again we do not copy any memory. */
|
|
|
|
results[i].source_addr_len = 0;
|
2003-11-18 07:04:13 +00:00
|
|
|
}
|
2004-08-14 20:13:23 +00:00
|
|
|
|
|
|
|
/* Remember the canonical name. */
|
|
|
|
if (q->ai_canonname != NULL)
|
|
|
|
{
|
|
|
|
assert (canonname == NULL);
|
|
|
|
canonname = q->ai_canonname;
|
|
|
|
q->ai_canonname = NULL;
|
|
|
|
}
|
2003-11-18 07:04:13 +00:00
|
|
|
}
|
|
|
|
|
2007-09-19 22:12:22 +00:00
|
|
|
if (fd != -1)
|
2017-07-03 18:22:58 +00:00
|
|
|
__close_nocancel_nostatus (fd);
|
2007-09-19 22:12:22 +00:00
|
|
|
|
2003-11-18 07:04:13 +00:00
|
|
|
/* We got all the source addresses we can get, now sort using
|
|
|
|
the information. */
|
2007-11-14 06:58:35 +00:00
|
|
|
struct sort_result_combo src
|
|
|
|
= { .results = results, .nresults = nresults };
|
2014-02-10 13:45:42 +00:00
|
|
|
if (__glibc_unlikely (gaiconf_reload_flag_ever_set))
|
2007-10-17 16:05:34 +00:00
|
|
|
{
|
|
|
|
__libc_lock_define_initialized (static, lock);
|
|
|
|
|
|
|
|
__libc_lock_lock (lock);
|
2012-05-10 21:50:14 +00:00
|
|
|
if (__libc_once_get (old_once) && gaiconf_reload_flag)
|
2007-10-17 16:05:34 +00:00
|
|
|
gaiconf_reload ();
|
2014-11-12 22:33:41 +00:00
|
|
|
__qsort_r (order, nresults, sizeof (order[0]), rfc3484_sort, &src);
|
2007-10-17 16:05:34 +00:00
|
|
|
__libc_lock_unlock (lock);
|
|
|
|
}
|
|
|
|
else
|
2014-11-12 22:33:41 +00:00
|
|
|
__qsort_r (order, nresults, sizeof (order[0]), rfc3484_sort, &src);
|
2003-11-18 07:04:13 +00:00
|
|
|
|
|
|
|
/* Queue the results up as they come out of sorting. */
|
2008-01-10 20:00:52 +00:00
|
|
|
q = p = results[order[0]].dest_addr;
|
2003-11-18 07:04:13 +00:00
|
|
|
for (i = 1; i < nresults; ++i)
|
2008-01-10 20:00:52 +00:00
|
|
|
q = q->ai_next = results[order[i]].dest_addr;
|
2003-11-18 07:04:13 +00:00
|
|
|
q->ai_next = NULL;
|
2004-08-14 20:13:23 +00:00
|
|
|
|
|
|
|
/* Fill in the canonical name into the new first entry. */
|
|
|
|
p->ai_canonname = canonname;
|
2013-03-21 14:50:27 +00:00
|
|
|
|
|
|
|
if (malloc_results)
|
|
|
|
free (results);
|
2003-11-18 07:04:13 +00:00
|
|
|
}
|
|
|
|
|
2011-10-31 05:51:16 +00:00
|
|
|
__free_in6ai (in6ai);
|
2006-04-16 21:34:32 +00:00
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
*pai = p;
|
|
|
|
return 0;
|
|
|
|
}
|
1996-10-21 01:26:31 +00:00
|
|
|
|
2013-12-02 14:53:13 +00:00
|
|
|
return last_i ? -last_i : EAI_NONAME;
|
1996-10-21 01:26:31 +00:00
|
|
|
}
|
2002-08-06 06:09:28 +00:00
|
|
|
libc_hidden_def (getaddrinfo)
|
1996-10-21 01:26:31 +00:00
|
|
|
|
2012-10-30 18:14:33 +00:00
|
|
|
nss_interface_function (getaddrinfo)
|
2003-06-16 17:18:06 +00:00
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
void
|
|
|
|
freeaddrinfo (struct addrinfo *ai)
|
1996-10-21 01:26:31 +00:00
|
|
|
{
|
|
|
|
struct addrinfo *p;
|
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
while (ai != NULL)
|
|
|
|
{
|
|
|
|
p = ai;
|
|
|
|
ai = ai->ai_next;
|
2004-08-18 05:10:14 +00:00
|
|
|
free (p->ai_canonname);
|
1997-08-20 03:53:21 +00:00
|
|
|
free (p);
|
|
|
|
}
|
1996-10-21 01:26:31 +00:00
|
|
|
}
|
2002-08-06 06:09:28 +00:00
|
|
|
libc_hidden_def (freeaddrinfo)
|