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 4329 by michael, Fri Aug 1 18:36:15 2014 UTC vs.
Revision 4415 by michael, Thu Aug 7 14:09:36 2014 UTC

# Line 55 | Line 55 | ipcache_hash_address(const struct irc_ss
55      hash = ((ip >> 12) + ip) & (IP_HASH_SIZE - 1);
56      return hash;
57    }
58 – #ifdef IPV6
58    else
59    {
60      const struct sockaddr_in6 *v6 = (const struct sockaddr_in6 *)addr;
# Line 67 | Line 66 | ipcache_hash_address(const struct irc_ss
66      hash  = hash & (IP_HASH_SIZE - 1);
67      return hash;
68    }
70 – #else
71 –  return 0;
72 – #endif
69   }
70  
71   /* ipcache_find_or_add_address()
# Line 87 | Line 83 | ipcache_find_or_add_address(struct irc_s
83    dlink_node *ptr = NULL;
84    struct ip_entry *iptr = NULL;
85    uint32_t hash_index = ipcache_hash_address(addr);
90 –  int res = 0;
86    struct sockaddr_in *v4 = (struct sockaddr_in *)addr, *ptr_v4;
92 – #ifdef IPV6
87    struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)addr, *ptr_v6;
94 – #endif
88  
89    DLINK_FOREACH(ptr, ip_hash_table[hash_index].head)
90    {
91      iptr = ptr->data;
92 < #ifdef IPV6
92 >
93      if (iptr->ip.ss.ss_family != addr->ss.ss_family)
94        continue;
95  
96      if (addr->ss.ss_family == AF_INET6)
97      {
98        ptr_v6 = (struct sockaddr_in6 *)&iptr->ip;
99 <      res = memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr));
99 >      if (!memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr)))
100 >        return iptr;  /* Found entry already in hash, return it. */
101      }
102      else
109 – #endif
103      {
104        ptr_v4 = (struct sockaddr_in *)&iptr->ip;
105 <      res = memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr));
105 >      if (!memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr)))
106 >        return iptr;  /* Found entry already in hash, return it. */
107      }
114 –
115 –    if (res == 0)
116 –      return iptr;  /* Found entry already in hash, return it. */
108    }
109  
110    iptr = mp_pool_get(ip_entry_pool);
# Line 138 | Line 129 | ipcache_remove_address(struct irc_ssaddr
129   {
130    dlink_node *ptr = NULL;
131    uint32_t hash_index = ipcache_hash_address(addr);
141 –  int res = 0;
132    struct sockaddr_in *v4 = (struct sockaddr_in *)addr, *ptr_v4;
143 – #ifdef IPV6
133    struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)addr, *ptr_v6;
145 – #endif
134  
135    DLINK_FOREACH(ptr, ip_hash_table[hash_index].head)
136    {
137      struct ip_entry *iptr = ptr->data;
138 < #ifdef IPV6
138 >
139      if (iptr->ip.ss.ss_family != addr->ss.ss_family)
140        continue;
141 +
142      if (addr->ss.ss_family == AF_INET6)
143      {
144        ptr_v6 = (struct sockaddr_in6 *)&iptr->ip;
145 <      res = memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr));
145 >      if (memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr)))
146 >        continue;
147      }
148      else
159 – #endif
149      {
150        ptr_v4 = (struct sockaddr_in *)&iptr->ip;
151 <      res = memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr));
151 >      if (memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr)))
152 >        continue;
153      }
154  
165 –    if (res)
166 –      continue;
155      assert(iptr->count > 0);
156  
157      if (--iptr->count == 0 &&
158 <        (CurrentTime - iptr->last_attempt) >= ConfigFileEntry.throttle_time)
158 >        (CurrentTime - iptr->last_attempt) >= ConfigGeneral.throttle_time)
159      {
160        dlinkDelete(&iptr->node, &ip_hash_table[hash_index]);
161        mp_pool_release(iptr);
# Line 194 | Line 182 | ipcache_remove_expired_entries(void *unu
182        struct ip_entry *iptr = ptr->data;
183  
184        if (iptr->count == 0 &&
185 <          (CurrentTime - iptr->last_attempt) >= ConfigFileEntry.throttle_time)
185 >          (CurrentTime - iptr->last_attempt) >= ConfigGeneral.throttle_time)
186        {
187          dlinkDelete(&iptr->node, &ip_hash_table[i]);
188          mp_pool_release(iptr);

Diff Legend

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