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 4367 by michael, Sun Aug 3 10:33:39 2014 UTC vs.
Revision 7924 by michael, Sat Dec 31 13:57:08 2016 UTC

# Line 1 | Line 1
1   /*
2   *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (c) 1997-2014 ircd-hybrid development team
4 > *  Copyright (c) 1997-2017 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 15 | Line 15
15   *
16   *  You should have received a copy of the GNU General Public License
17   *  along with this program; if not, write to the Free Software
18 < *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
18 > *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19   *  USA
20   */
21  
# Line 37 | Line 37 | static dlink_list ip_hash_table[IP_HASH_
37   static mp_pool_t *ip_entry_pool;
38  
39  
40 –
40   /* ipcache_hash_address()
41   *
42   * input        - pointer to an irc_inaddr
# Line 49 | Line 48 | ipcache_hash_address(const struct irc_ss
48   {
49    if (addr->ss.ss_family == AF_INET)
50    {
51 <    const struct sockaddr_in *v4 = (const struct sockaddr_in *)addr;
51 >    const struct sockaddr_in *const v4 = (const struct sockaddr_in *)addr;
52      uint32_t hash = 0, ip = ntohl(v4->sin_addr.s_addr);
53  
54      hash = ((ip >> 12) + ip) & (IP_HASH_SIZE - 1);
55      return hash;
56    }
58 – #ifdef IPV6
57    else
58    {
59 <    const struct sockaddr_in6 *v6 = (const struct sockaddr_in6 *)addr;
60 <    uint32_t hash = 0, *ip = (uint32_t *)&v6->sin6_addr.s6_addr;
59 >    const struct sockaddr_in6 *const v6 = (const struct sockaddr_in6 *)addr;
60 >    uint32_t hash = 0, *const ip = (uint32_t *)&v6->sin6_addr.s6_addr;
61  
62      hash  = ip[0] ^ ip[3];
63      hash ^= hash >> 16;
# Line 67 | Line 65 | ipcache_hash_address(const struct irc_ss
65      hash  = hash & (IP_HASH_SIZE - 1);
66      return hash;
67    }
70 – #else
71 –  return 0;
72 – #endif
68   }
69  
70   /* ipcache_find_or_add_address()
# Line 82 | Line 77 | ipcache_hash_address(const struct irc_ss
77   * count set to 0.
78   */
79   struct ip_entry *
80 < ipcache_find_or_add_address(struct irc_ssaddr *addr)
80 > ipcache_find_or_add_address(const struct irc_ssaddr *addr)
81   {
82 <  dlink_node *ptr = NULL;
82 >  dlink_node *node = NULL;
83    struct ip_entry *iptr = NULL;
84 <  uint32_t hash_index = ipcache_hash_address(addr);
85 <  struct sockaddr_in *v4 = (struct sockaddr_in *)addr, *ptr_v4;
86 < #ifdef IPV6
92 <  struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)addr, *ptr_v6;
93 < #endif
84 >  const uint32_t hash_index = ipcache_hash_address(addr);
85 >  const struct sockaddr_in *v4 = (const struct sockaddr_in *)addr, *ptr_v4;
86 >  const struct sockaddr_in6 *v6 = (const struct sockaddr_in6 *)addr, *ptr_v6;
87  
88 <  DLINK_FOREACH(ptr, ip_hash_table[hash_index].head)
88 >  DLINK_FOREACH(node, ip_hash_table[hash_index].head)
89    {
90 <    iptr = ptr->data;
91 < #ifdef IPV6
90 >    iptr = node->data;
91 >
92      if (iptr->ip.ss.ss_family != addr->ss.ss_family)
93        continue;
94  
95      if (addr->ss.ss_family == AF_INET6)
96      {
97 <      ptr_v6 = (struct sockaddr_in6 *)&iptr->ip;
97 >      ptr_v6 = (const struct sockaddr_in6 *)&iptr->ip;
98        if (!memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr)))
99          return iptr;  /* Found entry already in hash, return it. */
100      }
101      else
109 – #endif
102      {
103 <      ptr_v4 = (struct sockaddr_in *)&iptr->ip;
103 >      ptr_v4 = (const struct sockaddr_in *)&iptr->ip;
104        if (!memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr)))
105          return iptr;  /* Found entry already in hash, return it. */
106      }
# Line 132 | Line 124 | ipcache_find_or_add_address(struct irc_s
124   *                 the struct ip_entry is returned to the ip_entry_heap
125   */
126   void
127 < ipcache_remove_address(struct irc_ssaddr *addr)
127 > ipcache_remove_address(const struct irc_ssaddr *addr)
128   {
129 <  dlink_node *ptr = NULL;
130 <  uint32_t hash_index = ipcache_hash_address(addr);
131 <  struct sockaddr_in *v4 = (struct sockaddr_in *)addr, *ptr_v4;
132 < #ifdef IPV6
141 <  struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)addr, *ptr_v6;
142 < #endif
129 >  dlink_node *node = NULL;
130 >  const uint32_t hash_index = ipcache_hash_address(addr);
131 >  const struct sockaddr_in *v4 = (const struct sockaddr_in *)addr, *ptr_v4;
132 >  const struct sockaddr_in6 *v6 = (const struct sockaddr_in6 *)addr, *ptr_v6;
133  
134 <  DLINK_FOREACH(ptr, ip_hash_table[hash_index].head)
134 >  DLINK_FOREACH(node, ip_hash_table[hash_index].head)
135    {
136 <    struct ip_entry *iptr = ptr->data;
137 < #ifdef IPV6
136 >    struct ip_entry *iptr = node->data;
137 >
138      if (iptr->ip.ss.ss_family != addr->ss.ss_family)
139        continue;
140  
141      if (addr->ss.ss_family == AF_INET6)
142      {
143 <      ptr_v6 = (struct sockaddr_in6 *)&iptr->ip;
143 >      ptr_v6 = (const struct sockaddr_in6 *)&iptr->ip;
144        if (memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr)))
145          continue;
146      }
147      else
158 – #endif
148      {
149 <      ptr_v4 = (struct sockaddr_in *)&iptr->ip;
149 >      ptr_v4 = (const struct sockaddr_in *)&iptr->ip;
150        if (memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr)))
151          continue;
152      }
# Line 183 | Line 172 | ipcache_remove_address(struct irc_ssaddr
172   static void
173   ipcache_remove_expired_entries(void *unused)
174   {
175 <  dlink_node *ptr = NULL, *ptr_next = NULL;
175 >  dlink_node *node = NULL, *node_next = NULL;
176  
177    for (unsigned int i = 0; i < IP_HASH_SIZE; ++i)
178    {
179 <    DLINK_FOREACH_SAFE(ptr, ptr_next, ip_hash_table[i].head)
179 >    DLINK_FOREACH_SAFE(node, node_next, ip_hash_table[i].head)
180      {
181 <      struct ip_entry *iptr = ptr->data;
181 >      struct ip_entry *iptr = node->data;
182  
183        if (iptr->count == 0 &&
184            (CurrentTime - iptr->last_attempt) >= ConfigGeneral.throttle_time)
# Line 212 | Line 201 | ipcache_remove_expired_entries(void *unu
201   * used in the hash.
202   */
203   void
204 < ipcache_get_stats(unsigned int *const number_ips_stored, uint64_t *const mem_ips_stored)
204 > ipcache_get_stats(unsigned int *const number_ips_stored, size_t *const mem_ips_stored)
205   {
206    for (unsigned int i = 0; i < IP_HASH_SIZE; ++i)
207      *number_ips_stored += dlink_list_length(&ip_hash_table[i]);

Comparing ircd-hybrid/trunk/src/ipcache.c (property svn:eol-style):
Revision 4367 by michael, Sun Aug 3 10:33:39 2014 UTC vs.
Revision 7924 by michael, Sat Dec 31 13:57:08 2016 UTC

# Line 0 | Line 1
1 + native

Comparing ircd-hybrid/trunk/src/ipcache.c (property svn:keywords):
Revision 4367 by michael, Sun Aug 3 10:33:39 2014 UTC vs.
Revision 7924 by michael, Sat Dec 31 13:57:08 2016 UTC

# Line 1 | Line 1
1 < Id Revision
1 > Id

Diff Legend

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