diff options
| author | hasso <hasso> | 2005-09-28 18:30:51 +0000 | 
|---|---|---|
| committer | hasso <hasso> | 2005-09-28 18:30:51 +0000 | 
| commit | d3d7474ba98f01e6d9994ff48c0b3a4331a8ef2a (patch) | |
| tree | efa9e1f7f1e7fdb79f5374c78301218f2b68bc95 /isisd/isis_dynhn.c | |
| parent | 9551eea4465e0e3eaab7a133fc06705c8f36afc4 (diff) | |
	* isis_dynh.c, isisd.h: Implement dynamic hostname cache cleanup.
	* isis_lsp.c: Refresh dynamic hostname in the cache while refreshing
	  topology LSP.
Diffstat (limited to 'isisd/isis_dynhn.c')
| -rw-r--r-- | isisd/isis_dynhn.c | 31 | 
1 files changed, 28 insertions, 3 deletions
diff --git a/isisd/isis_dynhn.c b/isisd/isis_dynhn.c index 68257ddce8..13acae71f3 100644 --- a/isisd/isis_dynhn.c +++ b/isisd/isis_dynhn.c @@ -30,6 +30,7 @@  #include "stream.h"  #include "command.h"  #include "if.h" +#include "thread.h"  #include "isisd/dict.h"  #include "isisd/isis_constants.h" @@ -42,18 +43,42 @@  #include "isisd/isis_constants.h"  extern struct isis *isis; +extern struct thread_master *master;  extern struct host host;  struct list *dyn_cache = NULL; +static int dyn_cache_cleanup (struct thread *);  void  dyn_cache_init (void)  {    dyn_cache = list_new (); - +  THREAD_TIMER_ON (master, isis->t_dync_clean, dyn_cache_cleanup, NULL, 120);    return;  } +static int +dyn_cache_cleanup (struct thread *thread) +{ +  struct listnode *node, *nnode; +  struct isis_dynhn *dyn; +  time_t now = time (NULL); + +  isis->t_dync_clean = NULL; + +  for (ALL_LIST_ELEMENTS (dyn_cache, node, nnode, dyn)) +    { +      if ((now - dyn->refresh) < (MAX_AGE + 120)) +	continue; + +      list_delete_node (dyn_cache, node); +      XFREE (MTYPE_ISIS_DYNHN, dyn); +    } + +  THREAD_TIMER_ON (master, isis->t_dync_clean, dyn_cache_cleanup, NULL, 120); +  return ISIS_OK; +} +  struct isis_dynhn *  dynhn_find_by_id (u_char * id)  { @@ -80,13 +105,13 @@ isis_dynhn_insert (u_char * id, struct hostname *hostname, int level)        dyn->refresh = time (NULL);        return;      } -  dyn = XMALLOC (MTYPE_ISIS_DYNHN, sizeof (struct isis_dynhn)); +  dyn = XCALLOC (MTYPE_ISIS_DYNHN, sizeof (struct isis_dynhn));    if (!dyn)      {        zlog_warn ("isis_dynhn_insert(): out of memory!");        return;      } -  memset (dyn, 0, sizeof (struct isis_dynhn)); +    /* we also copy the length */    memcpy (&dyn->name, hostname, hostname->namelen + 1);    memcpy (dyn->id, id, ISIS_SYS_ID_LEN);  | 
