ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/ipcache.c
(Generate patch)

Comparing ircd-hybrid/trunk/src/ipcache.c (file contents):
Revision 8593 by michael, Sun Oct 21 18:11:04 2018 UTC vs.
Revision 8752 by michael, Tue Jan 1 11:07:01 2019 UTC

# Line 1 | Line 1
1   /*
2   *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (c) 1997-2018 ircd-hybrid development team
4 > *  Copyright (c) 1997-2019 ircd-hybrid development team
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 35 | Line 35
35  
36  
37   static dlink_list ipcache_list;
38 < static patricia_tree_t *ipcache_trie;
38 > static patricia_tree_t *ipcache_trie_v6;
39 > static patricia_tree_t *ipcache_trie_v4;
40  
41  
42 + static void *
43 + ipcache_get_trie(void *addr)
44 + {
45 +  if (((struct sockaddr *)addr)->sa_family == AF_INET6)
46 +    return ipcache_trie_v6;
47 +  else
48 +    return ipcache_trie_v4;
49 + }
50 +
51   /* ipcache_find_or_add_address()
52   *
53   * inputs       - pointer to struct irc_ssaddr
# Line 50 | Line 60 | static patricia_tree_t *ipcache_trie;
60   struct ip_entry *
61   ipcache_record_find_or_add(void *addr)
62   {
63 <  patricia_node_t *pnode = patricia_make_and_lookup_addr(ipcache_trie, addr, 0);
63 >  patricia_tree_t *ptrie = ipcache_get_trie(addr);
64 >  patricia_node_t *pnode = patricia_make_and_lookup_addr(ptrie, addr, 0);
65  
66    if (pnode->data)  /* Deliberate crash if 'pnode' is NULL */
67      return pnode->data;  /* Already added to the trie */
68  
69    struct ip_entry *iptr = xcalloc(sizeof(*iptr));
70 +  iptr->trie_pointer = ptrie;
71    dlinkAdd(pnode, &iptr->node, &ipcache_list);
72  
73    PATRICIA_DATA_SET(pnode, iptr);
# Line 71 | Line 83 | ipcache_record_delete(patricia_node_t *p
83    if (iptr->count_local == 0 && iptr->count_remote == 0 &&
84        (CurrentTime - iptr->last_attempt) >= ConfigGeneral.throttle_time)
85    {
86 +    patricia_remove(iptr->trie_pointer, pnode);
87 +
88      dlinkDelete(&iptr->node, &ipcache_list);
89      xfree(iptr);
76
77    patricia_remove(ipcache_trie, pnode);
90    }
91   }
92  
# Line 90 | Line 102 | ipcache_record_delete(patricia_node_t *p
102   void
103   ipcache_record_remove(void *addr, int local)
104   {
105 <  patricia_node_t *pnode = patricia_try_search_exact_addr(ipcache_trie, addr, 0);
105 >  patricia_node_t *pnode = patricia_try_search_exact_addr(ipcache_get_trie(addr), addr, 0);
106  
107    if (pnode == NULL)
108      return;
# Line 149 | Line 161 | ipcache_init(void)
161      .when = 123
162    };
163  
164 <  ipcache_trie = patricia_new(PATRICIA_MAXBITS);
164 >  ipcache_trie_v6 = patricia_new(128);
165 >  ipcache_trie_v4 = patricia_new( 32);
166  
167    event_add(&event_expire_ipcache, NULL);
168   }

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)