]>
Commit | Line | Data |
---|---|---|
b9215da1 MT |
1 | From 6b99458d197ab779ebb6ff632c168e2cbfa4f543 Mon Sep 17 00:00:00 2001 |
2 | From: Florian Weimer <fweimer@redhat.com> | |
3 | Date: Fri, 11 Aug 2023 10:10:16 +0200 | |
a61a21ef | 4 | Subject: [PATCH 03/44] nscd: Do not rebuild getaddrinfo (bug 30709) |
b9215da1 MT |
5 | |
6 | The nscd daemon caches hosts data from NSS modules verbatim, without | |
7 | filtering protocol families or sorting them (otherwise separate caches | |
8 | would be needed for certain ai_flags combinations). The cache | |
9 | implementation is complete separate from the getaddrinfo code. This | |
10 | means that rebuilding getaddrinfo is not needed. The only function | |
11 | actually used is __bump_nl_timestamp from check_pf.c, and this change | |
12 | moves it into nscd/connections.c. | |
13 | ||
14 | Tested on x86_64-linux-gnu with -fexceptions, built with | |
15 | build-many-glibcs.py. I also backported this patch into a distribution | |
16 | that still supports nscd and verified manually that caching still works. | |
17 | ||
18 | Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org> | |
19 | (cherry picked from commit 039ff51ac7e02db1cfc0c23e38ac7bfbb00221d1) | |
20 | --- | |
21 | include/ifaddrs.h | 4 --- | |
22 | inet/check_pf.c | 9 ------ | |
23 | nscd/Makefile | 2 +- | |
24 | nscd/connections.c | 11 +++++++ | |
25 | nscd/gai.c | 50 ------------------------------ | |
26 | sysdeps/unix/sysv/linux/check_pf.c | 17 +--------- | |
27 | 6 files changed, 13 insertions(+), 80 deletions(-) | |
28 | delete mode 100644 nscd/gai.c | |
29 | ||
30 | diff --git a/include/ifaddrs.h b/include/ifaddrs.h | |
31 | index 416118f1b3..19a3afb19f 100644 | |
32 | --- a/include/ifaddrs.h | |
33 | +++ b/include/ifaddrs.h | |
34 | @@ -34,9 +34,5 @@ extern void __check_native (uint32_t a1_index, int *a1_native, | |
35 | uint32_t a2_index, int *a2_native) | |
36 | attribute_hidden; | |
37 | ||
38 | -#if IS_IN (nscd) | |
39 | -extern uint32_t __bump_nl_timestamp (void) attribute_hidden; | |
40 | -#endif | |
41 | - | |
42 | # endif /* !_ISOMAC */ | |
43 | #endif /* ifaddrs.h */ | |
44 | diff --git a/inet/check_pf.c b/inet/check_pf.c | |
45 | index 5310c99121..6d1475920f 100644 | |
46 | --- a/inet/check_pf.c | |
47 | +++ b/inet/check_pf.c | |
48 | @@ -60,12 +60,3 @@ __free_in6ai (struct in6addrinfo *in6ai) | |
49 | { | |
50 | /* Nothing to do. */ | |
51 | } | |
52 | - | |
53 | - | |
54 | -#if IS_IN (nscd) | |
55 | -uint32_t | |
56 | -__bump_nl_timestamp (void) | |
57 | -{ | |
58 | - return 0; | |
59 | -} | |
60 | -#endif | |
61 | diff --git a/nscd/Makefile b/nscd/Makefile | |
62 | index 2a0489f4cf..16b6460ee9 100644 | |
63 | --- a/nscd/Makefile | |
64 | +++ b/nscd/Makefile | |
65 | @@ -35,7 +35,7 @@ nscd-modules := nscd connections pwdcache getpwnam_r getpwuid_r grpcache \ | |
66 | getgrnam_r getgrgid_r hstcache gethstbyad_r gethstbynm3_r \ | |
67 | getsrvbynm_r getsrvbypt_r servicescache \ | |
68 | dbg_log nscd_conf nscd_stat cache mem nscd_setup_thread \ | |
69 | - xmalloc xstrdup aicache initgrcache gai res_hconf \ | |
70 | + xmalloc xstrdup aicache initgrcache res_hconf \ | |
71 | netgroupcache cachedumper | |
72 | ||
73 | ifeq ($(build-nscd)$(have-thread-library),yesyes) | |
74 | diff --git a/nscd/connections.c b/nscd/connections.c | |
75 | index a405a44a9b..15693e5090 100644 | |
76 | --- a/nscd/connections.c | |
77 | +++ b/nscd/connections.c | |
78 | @@ -256,6 +256,17 @@ int inotify_fd = -1; | |
79 | #ifdef HAVE_NETLINK | |
80 | /* Descriptor for netlink status updates. */ | |
81 | static int nl_status_fd = -1; | |
82 | + | |
83 | +static uint32_t | |
84 | +__bump_nl_timestamp (void) | |
85 | +{ | |
86 | + static uint32_t nl_timestamp; | |
87 | + | |
88 | + if (atomic_fetch_add_relaxed (&nl_timestamp, 1) + 1 == 0) | |
89 | + atomic_fetch_add_relaxed (&nl_timestamp, 1); | |
90 | + | |
91 | + return nl_timestamp; | |
92 | +} | |
93 | #endif | |
94 | ||
95 | /* Number of times clients had to wait. */ | |
96 | diff --git a/nscd/gai.c b/nscd/gai.c | |
97 | deleted file mode 100644 | |
98 | index e29f3fe583..0000000000 | |
99 | --- a/nscd/gai.c | |
100 | +++ /dev/null | |
101 | @@ -1,50 +0,0 @@ | |
102 | -/* Copyright (C) 2004-2023 Free Software Foundation, Inc. | |
103 | - This file is part of the GNU C Library. | |
104 | - | |
105 | - This program is free software; you can redistribute it and/or modify | |
106 | - it under the terms of the GNU General Public License as published | |
107 | - by the Free Software Foundation; version 2 of the License, or | |
108 | - (at your option) any later version. | |
109 | - | |
110 | - This program is distributed in the hope that it will be useful, | |
111 | - but WITHOUT ANY WARRANTY; without even the implied warranty of | |
112 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
113 | - GNU General Public License for more details. | |
114 | - | |
115 | - You should have received a copy of the GNU General Public License | |
116 | - along with this program; if not, see <https://www.gnu.org/licenses/>. */ | |
117 | - | |
118 | -#include <alloca.h> | |
119 | -#include <sys/stat.h> | |
120 | - | |
121 | -/* This file uses the getaddrinfo code but it compiles it without NSCD | |
122 | - support. We just need a few symbol renames. */ | |
123 | -#define __ioctl ioctl | |
124 | -#define __getsockname getsockname | |
125 | -#define __socket socket | |
126 | -#define __recvmsg recvmsg | |
127 | -#define __bind bind | |
128 | -#define __sendto sendto | |
129 | -#define __strchrnul strchrnul | |
130 | -#define __getline getline | |
131 | -#define __qsort_r qsort_r | |
132 | -/* nscd uses 1MB or 2MB thread stacks. */ | |
133 | -#define __libc_use_alloca(size) (size <= __MAX_ALLOCA_CUTOFF) | |
134 | -#define __getifaddrs getifaddrs | |
135 | -#define __freeifaddrs freeifaddrs | |
136 | -#undef __fstat64 | |
137 | -#define __fstat64 fstat64 | |
138 | -#undef __stat64 | |
139 | -#define __stat64 stat64 | |
140 | - | |
141 | -/* We are nscd, so we don't want to be talking to ourselves. */ | |
142 | -#undef USE_NSCD | |
143 | - | |
144 | -#include <getaddrinfo.c> | |
145 | - | |
146 | -/* Support code. */ | |
147 | -#include <check_pf.c> | |
148 | -#include <check_native.c> | |
149 | - | |
150 | -/* Some variables normally defined in libc. */ | |
151 | -nss_action_list __nss_hosts_database attribute_hidden; | |
152 | diff --git a/sysdeps/unix/sysv/linux/check_pf.c b/sysdeps/unix/sysv/linux/check_pf.c | |
153 | index 2b0b8b6368..3aa6a00348 100644 | |
154 | --- a/sysdeps/unix/sysv/linux/check_pf.c | |
155 | +++ b/sysdeps/unix/sysv/linux/check_pf.c | |
156 | @@ -66,25 +66,10 @@ static struct cached_data *cache; | |
157 | __libc_lock_define_initialized (static, lock); | |
158 | ||
159 | ||
160 | -#if IS_IN (nscd) | |
161 | -static uint32_t nl_timestamp; | |
162 | - | |
163 | -uint32_t | |
164 | -__bump_nl_timestamp (void) | |
165 | -{ | |
166 | - if (atomic_fetch_add_relaxed (&nl_timestamp, 1) + 1 == 0) | |
167 | - atomic_fetch_add_relaxed (&nl_timestamp, 1); | |
168 | - | |
169 | - return nl_timestamp; | |
170 | -} | |
171 | -#endif | |
172 | - | |
173 | static inline uint32_t | |
174 | get_nl_timestamp (void) | |
175 | { | |
176 | -#if IS_IN (nscd) | |
177 | - return nl_timestamp; | |
178 | -#elif defined USE_NSCD | |
179 | +#if defined USE_NSCD | |
180 | return __nscd_get_nl_timestamp (); | |
181 | #else | |
182 | return 0; | |
183 | -- | |
184 | 2.39.2 | |
185 |