Annotation of /trunk/glibc/patches/glibc-2.15-revert-netlink-cache.patch
Parent Directory | Revision Log
Revision 1806 -
(hide annotations)
(download)
Tue Jun 12 12:33:27 2012 UTC (12 years, 3 months ago) by niro
File size: 18118 byte(s)
Tue Jun 12 12:33:27 2012 UTC (12 years, 3 months ago) by niro
File size: 18118 byte(s)
-added patches for 2.15-r1
1 | niro | 1806 | diff --git a/include/ifaddrs.h b/include/ifaddrs.h |
2 | index e1c6cac..50e4c48 100644 | ||
3 | --- a/include/ifaddrs.h | ||
4 | +++ b/include/ifaddrs.h | ||
5 | @@ -21,13 +21,8 @@ struct in6addrinfo | ||
6 | extern void __check_pf (bool *seen_ipv4, bool *seen_ipv6, | ||
7 | struct in6addrinfo **in6ai, size_t *in6ailen) | ||
8 | attribute_hidden; | ||
9 | -extern void __free_in6ai (struct in6addrinfo *in6ai) attribute_hidden; | ||
10 | extern void __check_native (uint32_t a1_index, int *a1_native, | ||
11 | uint32_t a2_index, int *a2_native) | ||
12 | attribute_hidden; | ||
13 | |||
14 | -#ifdef IS_IN_nscd | ||
15 | -extern uint32_t __bump_nl_timestamp (void) attribute_hidden; | ||
16 | -#endif | ||
17 | - | ||
18 | #endif /* ifaddrs.h */ | ||
19 | diff --git a/inet/check_pf.c b/inet/check_pf.c | ||
20 | index 0fa34cc..b015432 100644 | ||
21 | --- a/inet/check_pf.c | ||
22 | +++ b/inet/check_pf.c | ||
23 | @@ -1,5 +1,5 @@ | ||
24 | /* Determine protocol families for which interfaces exist. Generic version. | ||
25 | - Copyright (C) 2003, 2006, 2011 Free Software Foundation, Inc. | ||
26 | + Copyright (C) 2003, 2006 Free Software Foundation, Inc. | ||
27 | This file is part of the GNU C Library. | ||
28 | |||
29 | The GNU C Library is free software; you can redistribute it and/or | ||
30 | @@ -54,19 +54,3 @@ __check_pf (bool *seen_ipv4, bool *seen_ipv6, | ||
31 | |||
32 | (void) freeifaddrs (ifa); | ||
33 | } | ||
34 | - | ||
35 | - | ||
36 | -void | ||
37 | -__free_in6ai (struct in6addrinfo *in6ai) | ||
38 | -{ | ||
39 | - /* Nothing to do. */ | ||
40 | -} | ||
41 | - | ||
42 | - | ||
43 | -#ifdef IS_IN_nscd | ||
44 | -uint32_t | ||
45 | -__bump_nl_timestamp (void) | ||
46 | -{ | ||
47 | - return 0; | ||
48 | -} | ||
49 | -#endif | ||
50 | diff --git a/nscd/connections.c b/nscd/connections.c | ||
51 | index c741996..2b5c7ef 100644 | ||
52 | --- a/nscd/connections.c | ||
53 | +++ b/nscd/connections.c | ||
54 | @@ -24,7 +24,6 @@ | ||
55 | #include <errno.h> | ||
56 | #include <fcntl.h> | ||
57 | #include <grp.h> | ||
58 | -#include <ifaddrs.h> | ||
59 | #include <libintl.h> | ||
60 | #include <pthread.h> | ||
61 | #include <pwd.h> | ||
62 | @@ -33,10 +32,6 @@ | ||
63 | #include <stdlib.h> | ||
64 | #include <unistd.h> | ||
65 | #include <arpa/inet.h> | ||
66 | -#ifdef HAVE_NETLINK | ||
67 | -# include <linux/netlink.h> | ||
68 | -# include <linux/rtnetlink.h> | ||
69 | -#endif | ||
70 | #ifdef HAVE_EPOLL | ||
71 | # include <sys/epoll.h> | ||
72 | #endif | ||
73 | @@ -252,11 +247,6 @@ static int sock; | ||
74 | int inotify_fd = -1; | ||
75 | #endif | ||
76 | |||
77 | -#ifdef HAVE_NETLINK | ||
78 | -/* Descriptor for netlink status updates. */ | ||
79 | -static int nl_status_fd = -1; | ||
80 | -#endif | ||
81 | - | ||
82 | #ifndef __ASSUME_SOCK_CLOEXEC | ||
83 | /* Negative if SOCK_CLOEXEC is not supported, positive if it is, zero | ||
84 | before be know the result. */ | ||
85 | @@ -913,65 +903,6 @@ cannot set socket to close on exec: %s; disabling paranoia mode"), | ||
86 | exit (1); | ||
87 | } | ||
88 | |||
89 | -#ifdef HAVE_NETLINK | ||
90 | - if (dbs[hstdb].enabled) | ||
91 | - { | ||
92 | - /* Try to open netlink socket to monitor network setting changes. */ | ||
93 | - nl_status_fd = socket (AF_NETLINK, | ||
94 | - SOCK_RAW | SOCK_CLOEXEC | SOCK_NONBLOCK, | ||
95 | - NETLINK_ROUTE); | ||
96 | - if (nl_status_fd != -1) | ||
97 | - { | ||
98 | - struct sockaddr_nl snl; | ||
99 | - memset (&snl, '\0', sizeof (snl)); | ||
100 | - snl.nl_family = AF_NETLINK; | ||
101 | - /* XXX Is this the best set to use? */ | ||
102 | - snl.nl_groups = (RTMGRP_IPV4_IFADDR | RTMGRP_TC | RTMGRP_IPV4_MROUTE | ||
103 | - | RTMGRP_IPV4_ROUTE | RTMGRP_IPV4_RULE | ||
104 | - | RTMGRP_IPV6_IFADDR | RTMGRP_IPV6_MROUTE | ||
105 | - | RTMGRP_IPV6_ROUTE | RTMGRP_IPV6_IFINFO | ||
106 | - | RTMGRP_IPV6_PREFIX); | ||
107 | - | ||
108 | - if (bind (nl_status_fd, (struct sockaddr *) &snl, sizeof (snl)) != 0) | ||
109 | - { | ||
110 | - close (nl_status_fd); | ||
111 | - nl_status_fd = -1; | ||
112 | - } | ||
113 | - else | ||
114 | - { | ||
115 | - /* Start the timestamp process. */ | ||
116 | - dbs[hstdb].head->extra_data[NSCD_HST_IDX_CONF_TIMESTAMP] | ||
117 | - = __bump_nl_timestamp (); | ||
118 | - | ||
119 | -# ifndef __ASSUME_SOCK_CLOEXEC | ||
120 | - if (have_sock_cloexec < 0) | ||
121 | - { | ||
122 | - /* We don't want to get stuck on accept. */ | ||
123 | - int fl = fcntl (nl_status_fd, F_GETFL); | ||
124 | - if (fl == -1 | ||
125 | - || fcntl (nl_status_fd, F_SETFL, fl | O_NONBLOCK) == -1) | ||
126 | - { | ||
127 | - dbg_log (_("\ | ||
128 | -cannot change socket to nonblocking mode: %s"), | ||
129 | - strerror (errno)); | ||
130 | - exit (1); | ||
131 | - } | ||
132 | - | ||
133 | - /* The descriptor needs to be closed on exec. */ | ||
134 | - if (paranoia | ||
135 | - && fcntl (nl_status_fd, F_SETFD, FD_CLOEXEC) == -1) | ||
136 | - { | ||
137 | - dbg_log (_("cannot set socket to close on exec: %s"), | ||
138 | - strerror (errno)); | ||
139 | - exit (1); | ||
140 | - } | ||
141 | - } | ||
142 | -# endif | ||
143 | - } | ||
144 | - } | ||
145 | - } | ||
146 | -#endif | ||
147 | - | ||
148 | /* Change to unprivileged uid/gid/groups if specified in config file */ | ||
149 | if (server_user != NULL) | ||
150 | finish_drop_privileges (); | ||
151 | @@ -1895,18 +1826,6 @@ main_loop_poll (void) | ||
152 | } | ||
153 | #endif | ||
154 | |||
155 | -#ifdef HAVE_NETLINK | ||
156 | - size_t idx_nl_status_fd = 0; | ||
157 | - if (nl_status_fd != -1) | ||
158 | - { | ||
159 | - idx_nl_status_fd = nused; | ||
160 | - conns[nused].fd = nl_status_fd; | ||
161 | - conns[nused].events = POLLRDNORM; | ||
162 | - ++nused; | ||
163 | - firstfree = nused; | ||
164 | - } | ||
165 | -#endif | ||
166 | - | ||
167 | while (1) | ||
168 | { | ||
169 | /* Wait for any event. We wait at most a couple of seconds so | ||
170 | @@ -2049,20 +1968,6 @@ disabled inotify after read error %d"), | ||
171 | } | ||
172 | #endif | ||
173 | |||
174 | -#ifdef HAVE_NETLINK | ||
175 | - if (idx_nl_status_fd != 0 && conns[idx_nl_status_fd].revents != 0) | ||
176 | - { | ||
177 | - char buf[4096]; | ||
178 | - /* Read all the data. We do not interpret it here. */ | ||
179 | - while (TEMP_FAILURE_RETRY (read (nl_status_fd, buf, | ||
180 | - sizeof (buf))) != -1) | ||
181 | - ; | ||
182 | - | ||
183 | - dbs[hstdb].head->extra_data[NSCD_HST_IDX_CONF_TIMESTAMP] | ||
184 | - = __bump_nl_timestamp (); | ||
185 | - } | ||
186 | -#endif | ||
187 | - | ||
188 | for (size_t cnt = first; cnt < nused && n > 0; ++cnt) | ||
189 | if (conns[cnt].revents != 0) | ||
190 | { | ||
191 | @@ -2141,17 +2046,6 @@ main_loop_epoll (int efd) | ||
192 | } | ||
193 | # endif | ||
194 | |||
195 | -# ifdef HAVE_NETLINK | ||
196 | - if (nl_status_fd != -1) | ||
197 | - { | ||
198 | - ev.events = EPOLLRDNORM; | ||
199 | - ev.data.fd = nl_status_fd; | ||
200 | - if (epoll_ctl (efd, EPOLL_CTL_ADD, nl_status_fd, &ev) == -1) | ||
201 | - /* We cannot use epoll. */ | ||
202 | - return; | ||
203 | - } | ||
204 | -# endif | ||
205 | - | ||
206 | while (1) | ||
207 | { | ||
208 | struct epoll_event revs[100]; | ||
209 | @@ -2268,18 +2162,6 @@ main_loop_epoll (int efd) | ||
210 | } | ||
211 | } | ||
212 | # endif | ||
213 | -# ifdef HAVE_NETLINK | ||
214 | - else if (revs[cnt].data.fd == nl_status_fd) | ||
215 | - { | ||
216 | - char buf[4096]; | ||
217 | - /* Read all the data. We do not interpret it here. */ | ||
218 | - while (TEMP_FAILURE_RETRY (read (nl_status_fd, buf, | ||
219 | - sizeof (buf))) != -1) | ||
220 | - ; | ||
221 | - | ||
222 | - __bump_nl_timestamp (); | ||
223 | - } | ||
224 | -# endif | ||
225 | else | ||
226 | { | ||
227 | /* Remove the descriptor from the epoll descriptor. */ | ||
228 | @@ -2303,7 +2185,6 @@ main_loop_epoll (int efd) | ||
229 | time_t laststart = now - ACCEPT_TIMEOUT; | ||
230 | assert (starttime[sock] == 0); | ||
231 | assert (inotify_fd == -1 || starttime[inotify_fd] == 0); | ||
232 | - assert (nl_status_fd == -1 || starttime[nl_status_fd] == 0); | ||
233 | for (int cnt = highest; cnt > STDERR_FILENO; --cnt) | ||
234 | if (starttime[cnt] != 0 && starttime[cnt] < laststart) | ||
235 | { | ||
236 | diff --git a/nscd/nscd-client.h b/nscd/nscd-client.h | ||
237 | index b5cd2d2..caad26a 100644 | ||
238 | --- a/nscd/nscd-client.h | ||
239 | +++ b/nscd/nscd-client.h | ||
240 | @@ -260,17 +260,12 @@ struct hashentry | ||
241 | |||
242 | |||
243 | /* Current persistent database version. */ | ||
244 | -#define DB_VERSION 2 | ||
245 | +#define DB_VERSION 1 | ||
246 | |||
247 | /* Maximum time allowed between updates of the timestamp. */ | ||
248 | #define MAPPING_TIMEOUT (5 * 60) | ||
249 | |||
250 | |||
251 | -/* Used indices for the EXTRA_DATA element of 'database_pers_head'. | ||
252 | - Each database has its own indices. */ | ||
253 | -#define NSCD_HST_IDX_CONF_TIMESTAMP 0 | ||
254 | - | ||
255 | - | ||
256 | /* Header of persistent database file. */ | ||
257 | struct database_pers_head | ||
258 | { | ||
259 | @@ -279,8 +274,6 @@ struct database_pers_head | ||
260 | volatile int32_t gc_cycle; | ||
261 | volatile int32_t nscd_certainly_running; | ||
262 | volatile nscd_time_t timestamp; | ||
263 | - /* Room for extensions. */ | ||
264 | - volatile uint32_t extra_data[4]; | ||
265 | |||
266 | nscd_ssize_t module; | ||
267 | nscd_ssize_t data_size; | ||
268 | @@ -329,12 +322,6 @@ extern int __nscd_open_socket (const char *key, size_t keylen, | ||
269 | request_type type, void *response, | ||
270 | size_t responselen) attribute_hidden; | ||
271 | |||
272 | -/* Try to get a file descriptor for the shared meory segment | ||
273 | - containing the database. */ | ||
274 | -extern struct mapped_database *__nscd_get_mapping (request_type type, | ||
275 | - const char *key, | ||
276 | - struct mapped_database **mappedp) attribute_hidden; | ||
277 | - | ||
278 | /* Get reference of mapping. */ | ||
279 | extern struct mapped_database *__nscd_get_map_ref (request_type type, | ||
280 | const char *name, | ||
281 | @@ -384,7 +371,4 @@ extern ssize_t writeall (int fd, const void *buf, size_t len) | ||
282 | extern ssize_t sendfileall (int tofd, int fromfd, off_t off, size_t len) | ||
283 | attribute_hidden; | ||
284 | |||
285 | -/* Get netlink timestamp counter from mapped area or zero. */ | ||
286 | -extern uint32_t __nscd_get_nl_timestamp (void); | ||
287 | - | ||
288 | #endif /* nscd.h */ | ||
289 | diff --git a/nscd/nscd_gethst_r.c b/nscd/nscd_gethst_r.c | ||
290 | index 6ee142d..70631fa 100644 | ||
291 | --- a/nscd/nscd_gethst_r.c | ||
292 | +++ b/nscd/nscd_gethst_r.c | ||
293 | @@ -1,4 +1,4 @@ | ||
294 | -/* Copyright (C) 1998-2005, 2006, 2007, 2008, 2009, 2011 | ||
295 | +/* Copyright (C) 1998-2005, 2006, 2007, 2008, 2009 | ||
296 | Free Software Foundation, Inc. | ||
297 | This file is part of the GNU C Library. | ||
298 | Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998. | ||
299 | @@ -98,27 +98,6 @@ libc_freeres_fn (hst_map_free) | ||
300 | } | ||
301 | |||
302 | |||
303 | -uint32_t | ||
304 | -__nscd_get_nl_timestamp (void) | ||
305 | -{ | ||
306 | - if (__nss_not_use_nscd_hosts != 0) | ||
307 | - return 0; | ||
308 | - | ||
309 | - struct mapped_database *map = __hst_map_handle.mapped; | ||
310 | - | ||
311 | - if (map == NULL | ||
312 | - || (map != NO_MAPPING | ||
313 | - && map->head->nscd_certainly_running == 0 | ||
314 | - && map->head->timestamp + MAPPING_TIMEOUT < time (NULL))) | ||
315 | - map = __nscd_get_mapping (GETFDHST, "hosts", &__hst_map_handle.mapped); | ||
316 | - | ||
317 | - if (map == NO_MAPPING) | ||
318 | - return 0; | ||
319 | - | ||
320 | - return map->head->extra_data[NSCD_HST_IDX_CONF_TIMESTAMP]; | ||
321 | -} | ||
322 | - | ||
323 | - | ||
324 | int __nss_have_localdomain attribute_hidden; | ||
325 | |||
326 | static int | ||
327 | diff --git a/nscd/nscd_helper.c b/nscd/nscd_helper.c | ||
328 | index 365b599..fe63f9a 100644 | ||
329 | --- a/nscd/nscd_helper.c | ||
330 | +++ b/nscd/nscd_helper.c | ||
331 | @@ -277,9 +277,9 @@ __nscd_unmap (struct mapped_database *mapped) | ||
332 | |||
333 | /* Try to get a file descriptor for the shared meory segment | ||
334 | containing the database. */ | ||
335 | -struct mapped_database * | ||
336 | -__nscd_get_mapping (request_type type, const char *key, | ||
337 | - struct mapped_database **mappedp) | ||
338 | +static struct mapped_database * | ||
339 | +get_mapping (request_type type, const char *key, | ||
340 | + struct mapped_database **mappedp) | ||
341 | { | ||
342 | struct mapped_database *result = NO_MAPPING; | ||
343 | #ifdef SCM_RIGHTS | ||
344 | @@ -449,8 +449,8 @@ __nscd_get_map_ref (request_type type, const char *name, | ||
345 | || (cur->head->nscd_certainly_running == 0 | ||
346 | && cur->head->timestamp + MAPPING_TIMEOUT < time (NULL)) | ||
347 | || cur->head->data_size > cur->datasize) | ||
348 | - cur = __nscd_get_mapping (type, name, | ||
349 | - (struct mapped_database **) &mapptr->mapped); | ||
350 | + cur = get_mapping (type, name, | ||
351 | + (struct mapped_database **) &mapptr->mapped); | ||
352 | |||
353 | if (__builtin_expect (cur != NO_MAPPING, 1)) | ||
354 | { | ||
355 | diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c | ||
356 | index 1a023f9..4979805 100644 | ||
357 | --- a/sysdeps/posix/getaddrinfo.c | ||
358 | +++ b/sysdeps/posix/getaddrinfo.c | ||
359 | @@ -2386,7 +2386,7 @@ getaddrinfo (const char *name, const char *service, | ||
360 | || (hints->ai_family == PF_INET6 && ! seen_ipv6)) | ||
361 | { | ||
362 | /* We cannot possibly return a valid answer. */ | ||
363 | - __free_in6ai (in6ai); | ||
364 | + free (in6ai); | ||
365 | return EAI_NONAME; | ||
366 | } | ||
367 | } | ||
368 | @@ -2400,7 +2400,7 @@ getaddrinfo (const char *name, const char *service, | ||
369 | { | ||
370 | if (hints->ai_flags & AI_NUMERICSERV) | ||
371 | { | ||
372 | - __free_in6ai (in6ai); | ||
373 | + free (in6ai); | ||
374 | return EAI_NONAME; | ||
375 | } | ||
376 | |||
377 | @@ -2422,7 +2422,7 @@ getaddrinfo (const char *name, const char *service, | ||
378 | if (last_i != 0) | ||
379 | { | ||
380 | freeaddrinfo (p); | ||
381 | - __free_in6ai (in6ai); | ||
382 | + free (in6ai); | ||
383 | |||
384 | return -(last_i & GAIH_EAI); | ||
385 | } | ||
386 | @@ -2434,7 +2434,7 @@ getaddrinfo (const char *name, const char *service, | ||
387 | } | ||
388 | else | ||
389 | { | ||
390 | - __free_in6ai (in6ai); | ||
391 | + free (in6ai); | ||
392 | return EAI_FAMILY; | ||
393 | } | ||
394 | |||
395 | @@ -2622,7 +2622,7 @@ getaddrinfo (const char *name, const char *service, | ||
396 | p->ai_canonname = canonname; | ||
397 | } | ||
398 | |||
399 | - __free_in6ai (in6ai); | ||
400 | + free (in6ai); | ||
401 | |||
402 | if (p) | ||
403 | { | ||
404 | diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile | ||
405 | index e684b16..c907af4 100644 | ||
406 | --- a/sysdeps/unix/sysv/linux/Makefile | ||
407 | +++ b/sysdeps/unix/sysv/linux/Makefile | ||
408 | @@ -173,6 +173,6 @@ CFLAGS-mq_receive.c += -fexceptions | ||
409 | endif | ||
410 | |||
411 | ifeq ($(subdir),nscd) | ||
412 | -sysdep-CFLAGS += -DHAVE_EPOLL -DHAVE_SENDFILE -DHAVE_INOTIFY -DHAVE_NETLINK | ||
413 | +sysdep-CFLAGS += -DHAVE_EPOLL -DHAVE_SENDFILE -DHAVE_INOTIFY | ||
414 | CFLAGS-gai.c += -DNEED_NETLINK | ||
415 | endif | ||
416 | diff --git a/sysdeps/unix/sysv/linux/check_pf.c b/sysdeps/unix/sysv/linux/check_pf.c | ||
417 | index 0738a70..d5ad7ea 100644 | ||
418 | --- a/sysdeps/unix/sysv/linux/check_pf.c | ||
419 | +++ b/sysdeps/unix/sysv/linux/check_pf.c | ||
420 | @@ -1,5 +1,5 @@ | ||
421 | /* Determine protocol families for which interfaces exist. Linux version. | ||
422 | - Copyright (C) 2003, 2006-2008, 2010, 2011 Free Software Foundation, Inc. | ||
423 | + Copyright (C) 2003, 2006, 2007, 2008, 2010, 2011 Free Software Foundation, Inc. | ||
424 | This file is part of the GNU C Library. | ||
425 | |||
426 | The GNU C Library is free software; you can redistribute it and/or | ||
427 | @@ -33,9 +33,6 @@ | ||
428 | |||
429 | #include <not-cancel.h> | ||
430 | #include <kernel-features.h> | ||
431 | -#include <bits/libc-lock.h> | ||
432 | -#include <atomic.h> | ||
433 | -#include <nscd/nscd-client.h> | ||
434 | |||
435 | |||
436 | #ifndef IFA_F_HOMEADDRESS | ||
437 | @@ -46,42 +43,9 @@ | ||
438 | #endif | ||
439 | |||
440 | |||
441 | -struct cached_data | ||
442 | -{ | ||
443 | - uint32_t timestamp; | ||
444 | - uint32_t usecnt; | ||
445 | - bool seen_ipv4; | ||
446 | - bool seen_ipv6; | ||
447 | - size_t in6ailen; | ||
448 | - struct in6addrinfo in6ai[0]; | ||
449 | -}; | ||
450 | - | ||
451 | -static struct cached_data noai6ai_cached = | ||
452 | - { | ||
453 | - .usecnt = 1, /* Make sure we never try to delete this entry. */ | ||
454 | - .in6ailen = 0 | ||
455 | - }; | ||
456 | - | ||
457 | -static struct cached_data *cache; | ||
458 | -__libc_lock_define_initialized (static, lock); | ||
459 | - | ||
460 | - | ||
461 | -#ifdef IS_IN_nscd | ||
462 | -static uint32_t nl_timestamp; | ||
463 | - | ||
464 | -uint32_t | ||
465 | -__bump_nl_timestamp (void) | ||
466 | -{ | ||
467 | - if (atomic_increment_val (&nl_timestamp) == 0) | ||
468 | - atomic_increment (&nl_timestamp); | ||
469 | - | ||
470 | - return nl_timestamp; | ||
471 | -} | ||
472 | -#endif | ||
473 | - | ||
474 | - | ||
475 | -static struct cached_data * | ||
476 | -make_request (int fd, pid_t pid) | ||
477 | +static int | ||
478 | +make_request (int fd, pid_t pid, bool *seen_ipv4, bool *seen_ipv6, | ||
479 | + struct in6addrinfo **in6ai, size_t *in6ailen) | ||
480 | { | ||
481 | struct req | ||
482 | { | ||
483 | @@ -135,6 +99,9 @@ make_request (int fd, pid_t pid) | ||
484 | sizeof (nladdr))) < 0) | ||
485 | goto out_fail; | ||
486 | |||
487 | + *seen_ipv4 = false; | ||
488 | + *seen_ipv6 = false; | ||
489 | + | ||
490 | bool done = false; | ||
491 | struct in6ailist | ||
492 | { | ||
493 | @@ -142,8 +109,6 @@ make_request (int fd, pid_t pid) | ||
494 | struct in6ailist *next; | ||
495 | } *in6ailist = NULL; | ||
496 | size_t in6ailistlen = 0; | ||
497 | - bool seen_ipv4 = false; | ||
498 | - bool seen_ipv6 = false; | ||
499 | |||
500 | do | ||
501 | { | ||
502 | @@ -207,12 +172,12 @@ make_request (int fd, pid_t pid) | ||
503 | { | ||
504 | if (*(const in_addr_t *) address | ||
505 | != htonl (INADDR_LOOPBACK)) | ||
506 | - seen_ipv4 = true; | ||
507 | + *seen_ipv4 = true; | ||
508 | } | ||
509 | else | ||
510 | { | ||
511 | if (!IN6_IS_ADDR_LOOPBACK (address)) | ||
512 | - seen_ipv6 = true; | ||
513 | + *seen_ipv6 = true; | ||
514 | } | ||
515 | } | ||
516 | |||
517 | @@ -246,47 +211,30 @@ make_request (int fd, pid_t pid) | ||
518 | } | ||
519 | while (! done); | ||
520 | |||
521 | - struct cached_data *result; | ||
522 | - if (seen_ipv6 && in6ailist != NULL) | ||
523 | + if (*seen_ipv6 && in6ailist != NULL) | ||
524 | { | ||
525 | - result = malloc (sizeof (*result) | ||
526 | - + in6ailistlen * sizeof (struct in6addrinfo)); | ||
527 | - if (result == NULL) | ||
528 | + *in6ai = malloc (in6ailistlen * sizeof (**in6ai)); | ||
529 | + if (*in6ai == NULL) | ||
530 | goto out_fail; | ||
531 | |||
532 | -#ifdef IS_IN_nscd | ||
533 | - result->timestamp = nl_timestamp; | ||
534 | -#else | ||
535 | - result->timestamp = __nscd_get_nl_timestamp (); | ||
536 | -#endif | ||
537 | - result->usecnt = 2; | ||
538 | - result->seen_ipv4 = seen_ipv4; | ||
539 | - result->seen_ipv6 = true; | ||
540 | - result->in6ailen = in6ailistlen; | ||
541 | + *in6ailen = in6ailistlen; | ||
542 | |||
543 | do | ||
544 | { | ||
545 | - result->in6ai[--in6ailistlen] = in6ailist->info; | ||
546 | + (*in6ai)[--in6ailistlen] = in6ailist->info; | ||
547 | in6ailist = in6ailist->next; | ||
548 | } | ||
549 | while (in6ailist != NULL); | ||
550 | } | ||
551 | - else | ||
552 | - { | ||
553 | - atomic_add (&noai6ai_cached.usecnt, 2); | ||
554 | - noai6ai_cached.seen_ipv4 = seen_ipv4; | ||
555 | - noai6ai_cached.seen_ipv6 = seen_ipv6; | ||
556 | - result = &noai6ai_cached; | ||
557 | - } | ||
558 | |||
559 | if (use_malloc) | ||
560 | free (buf); | ||
561 | - return result; | ||
562 | + return 0; | ||
563 | |||
564 | out_fail: | ||
565 | if (use_malloc) | ||
566 | free (buf); | ||
567 | - return NULL; | ||
568 | + return -1; | ||
569 | } | ||
570 | |||
571 | |||
572 | @@ -310,65 +258,28 @@ __check_pf (bool *seen_ipv4, bool *seen_ipv6, | ||
573 | |||
574 | if (! __no_netlink_support) | ||
575 | { | ||
576 | - struct cached_data *olddata = NULL; | ||
577 | - struct cached_data *data = NULL; | ||
578 | + int fd = __socket (PF_NETLINK, SOCK_RAW, NETLINK_ROUTE); | ||
579 | |||
580 | - __libc_lock_lock (lock); | ||
581 | - | ||
582 | -#ifdef IS_IN_nscd | ||
583 | -# define cache_valid() nl_timestamp != 0 && cache->timestamp == nl_timestamp | ||
584 | -#else | ||
585 | -# define cache_valid() \ | ||
586 | - ({ uint32_t val = __nscd_get_nl_timestamp (); \ | ||
587 | - val != 0 && cache->timestamp == val; }) | ||
588 | -#endif | ||
589 | - if (cache != NULL && cache_valid ()) | ||
590 | - { | ||
591 | - data = cache; | ||
592 | - atomic_increment (&cache->usecnt); | ||
593 | - } | ||
594 | - else | ||
595 | + if (__builtin_expect (fd >= 0, 1)) | ||
596 | { | ||
597 | - int fd = __socket (PF_NETLINK, SOCK_RAW, NETLINK_ROUTE); | ||
598 | + struct sockaddr_nl nladdr; | ||
599 | + memset (&nladdr, '\0', sizeof (nladdr)); | ||
600 | + nladdr.nl_family = AF_NETLINK; | ||
601 | |||
602 | - if (__builtin_expect (fd >= 0, 1)) | ||
603 | - { | ||
604 | - struct sockaddr_nl nladdr; | ||
605 | - memset (&nladdr, '\0', sizeof (nladdr)); | ||
606 | - nladdr.nl_family = AF_NETLINK; | ||
607 | - | ||
608 | - socklen_t addr_len = sizeof (nladdr); | ||
609 | - | ||
610 | - if(__bind (fd, (struct sockaddr *) &nladdr, sizeof (nladdr)) == 0 | ||
611 | - && __getsockname (fd, (struct sockaddr *) &nladdr, | ||
612 | - &addr_len) == 0) | ||
613 | - data = make_request (fd, nladdr.nl_pid); | ||
614 | - | ||
615 | - close_not_cancel_no_status (fd); | ||
616 | - } | ||
617 | - | ||
618 | - if (data != NULL) | ||
619 | - { | ||
620 | - olddata = cache; | ||
621 | - cache = data; | ||
622 | - } | ||
623 | - } | ||
624 | + socklen_t addr_len = sizeof (nladdr); | ||
625 | |||
626 | - __libc_lock_unlock (lock); | ||
627 | + bool success | ||
628 | + = (__bind (fd, (struct sockaddr *) &nladdr, sizeof (nladdr)) == 0 | ||
629 | + && __getsockname (fd, (struct sockaddr *) &nladdr, | ||
630 | + &addr_len) == 0 | ||
631 | + && make_request (fd, nladdr.nl_pid, seen_ipv4, seen_ipv6, | ||
632 | + in6ai, in6ailen) == 0); | ||
633 | |||
634 | - if (data != NULL) | ||
635 | - { | ||
636 | - /* It worked. */ | ||
637 | - *seen_ipv4 = data->seen_ipv4; | ||
638 | - *seen_ipv6 = data->seen_ipv6; | ||
639 | - *in6ailen = data->in6ailen; | ||
640 | - *in6ai = data->in6ai; | ||
641 | - | ||
642 | - if (olddata != NULL && olddata->usecnt > 0 | ||
643 | - && atomic_add_zero (&olddata->usecnt, -1)) | ||
644 | - free (olddata); | ||
645 | + close_not_cancel_no_status (fd); | ||
646 | |||
647 | - return; | ||
648 | + if (success) | ||
649 | + /* It worked. */ | ||
650 | + return; | ||
651 | } | ||
652 | |||
653 | #if __ASSUME_NETLINK_SUPPORT == 0 | ||
654 | @@ -407,26 +318,3 @@ __check_pf (bool *seen_ipv4, bool *seen_ipv6, | ||
655 | (void) freeifaddrs (ifa); | ||
656 | #endif | ||
657 | } | ||
658 | - | ||
659 | - | ||
660 | -void | ||
661 | -__free_in6ai (struct in6addrinfo *ai) | ||
662 | -{ | ||
663 | - if (ai != NULL) | ||
664 | - { | ||
665 | - struct cached_data *data = | ||
666 | - (struct cached_data *) ((char *) ai | ||
667 | - - offsetof (struct cached_data, in6ai)); | ||
668 | - | ||
669 | - if (atomic_add_zero (&data->usecnt, -1)) | ||
670 | - { | ||
671 | - __libc_lock_lock (lock); | ||
672 | - | ||
673 | - if (data->usecnt == 0) | ||
674 | - /* Still unused. */ | ||
675 | - free (data); | ||
676 | - | ||
677 | - __libc_lock_unlock (lock); | ||
678 | - } | ||
679 | - } | ||
680 | -} |