summary refs log tree commit diff
path: root/nscd/nscd_gethst_r.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@gmail.com>2011-10-31 01:51:16 -0400
committerUlrich Drepper <drepper@gmail.com>2011-10-31 01:51:16 -0400
commit3a2c02424d9824f5cdea4ebd32ff929b2b1f49c6 (patch)
treede7827ff96076cb4d181ed781c418601906fa772 /nscd/nscd_gethst_r.c
parent636064eb4c03397c86aa26e489e68f952bd5e53f (diff)
downloadglibc-3a2c02424d9824f5cdea4ebd32ff929b2b1f49c6.tar.gz
glibc-3a2c02424d9824f5cdea4ebd32ff929b2b1f49c6.tar.xz
glibc-3a2c02424d9824f5cdea4ebd32ff929b2b1f49c6.zip
Cache network interface information
Whenever getaddrinfo needed network interface information it used the
netlink interface to read the information every single time.  The
problem is that this information can change at any time.

The patch implements monitoring of the network interfaces through
nscd.  If no change is detected the previously read information can
be reused (which is the norm).  This timestamp information is also
made available to other processes using the shared memory segment
between nscd and those processes.
Diffstat (limited to 'nscd/nscd_gethst_r.c')
-rw-r--r--nscd/nscd_gethst_r.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/nscd/nscd_gethst_r.c b/nscd/nscd_gethst_r.c
index 70631fa961..6ee142d71b 100644
--- a/nscd/nscd_gethst_r.c
+++ b/nscd/nscd_gethst_r.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998-2005, 2006, 2007, 2008, 2009
+/* Copyright (C) 1998-2005, 2006, 2007, 2008, 2009, 2011
    Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
@@ -98,6 +98,27 @@ libc_freeres_fn (hst_map_free)
 }
 
 
+uint32_t
+__nscd_get_nl_timestamp (void)
+{
+  if (__nss_not_use_nscd_hosts != 0)
+    return 0;
+
+  struct mapped_database *map = __hst_map_handle.mapped;
+
+  if (map == NULL
+      || (map != NO_MAPPING
+	  && map->head->nscd_certainly_running == 0
+	  && map->head->timestamp + MAPPING_TIMEOUT < time (NULL)))
+    map = __nscd_get_mapping (GETFDHST, "hosts", &__hst_map_handle.mapped);
+
+  if (map == NO_MAPPING)
+    return 0;
+
+  return map->head->extra_data[NSCD_HST_IDX_CONF_TIMESTAMP];
+}
+
+
 int __nss_have_localdomain attribute_hidden;
 
 static int