~ubuntu-branches/ubuntu/wily/trafficserver/wily

« back to all changes in this revision

Viewing changes to iocore/hostdb/P_HostDBProcessor.h

  • Committer: Package Import Robot
  • Author(s): Adam Conrad
  • Date: 2012-12-17 22:28:16 UTC
  • mfrom: (5.1.8 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20121217222816-7xwjsx5k76zkb63d
Tags: 3.2.0-1ubuntu1
* Revert FreeBSD strerror_r() fixes that give errors with glibc 2.16.
* Apply patch from Konstantinos Margaritis to define barriers on ARM.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
#include "I_HostDBProcessor.h"
32
32
 
33
 
 
34
 
#define HOSTDB_CLIENT_IP_HASH(_client_ip,_ip) (((_client_ip >> 16)^_client_ip^_ip^(_ip>>16))&0xFFFF)
 
33
inline unsigned int HOSTDB_CLIENT_IP_HASH(
 
34
  sockaddr const* lhs,
 
35
  sockaddr const* rhs
 
36
) {
 
37
  unsigned int zret = ~static_cast<unsigned int>(0);
 
38
  if (ats_ip_are_compatible(lhs,rhs)) {
 
39
    if (ats_is_ip4(lhs)) {
 
40
      in_addr_t ip1 = ats_ip4_addr_cast(lhs);
 
41
      in_addr_t ip2 = ats_ip4_addr_cast(rhs);
 
42
      zret = (ip1 >> 16) ^ ip1 ^ ip2 ^ (ip2 >> 16);
 
43
    } else if (ats_is_ip6(lhs)) {
 
44
      uint32_t const* ip1 = ats_ip_addr32_cast(lhs);
 
45
      uint32_t const* ip2 = ats_ip_addr32_cast(rhs);
 
46
      for ( int i = 0 ; i < 4 ; ++i, ++ip1, ++ip2 ) {
 
47
        zret ^= (*ip1 >> 16) ^ *ip1 ^ *ip2 ^ (*ip2 >> 16);
 
48
      }
 
49
    }
 
50
  }
 
51
  return zret & 0xFFFF;
 
52
}
35
53
 
36
54
//
37
55
// Constants
44
62
 
45
63
// Bump this any time hostdb format is changed
46
64
#define HOST_DB_CACHE_MAJOR_VERSION         2
47
 
#define HOST_DB_CACHE_MINOR_VERSION         0
 
65
#define HOST_DB_CACHE_MINOR_VERSION         1
 
66
// 2.1 : IPv6
48
67
 
49
68
#define DEFAULT_HOST_DB_FILENAME             "host.db"
50
69
#define DEFAULT_HOST_DB_SIZE                 (1<<14)
146
165
  HostDBCache();
147
166
};
148
167
 
149
 
inline HostDBInfo *
150
 
HostDBRoundRobin::find_ip(unsigned int ip)
151
 
{
 
168
inline HostDBInfo*
 
169
HostDBRoundRobin::find_ip(sockaddr const* ip) {
152
170
  bool bad = (n <= 0 || n > HOST_DB_MAX_ROUND_ROBIN_INFO || good <= 0 || good > HOST_DB_MAX_ROUND_ROBIN_INFO);
153
171
  if (bad) {
154
172
    ink_assert(!"bad round robin size");
156
174
  }
157
175
 
158
176
  for (int i = 0; i < good; i++) {
159
 
    if (ip == info[i].ip()) {
 
177
    if (ats_ip_addr_eq(ip, info[i].ip())) {
160
178
      return &info[i];
161
179
    }
162
180
  }
165
183
}
166
184
 
167
185
inline HostDBInfo *
168
 
HostDBRoundRobin::select_best(unsigned int client_ip, HostDBInfo * r)
 
186
HostDBRoundRobin::select_best(sockaddr const* client_ip, HostDBInfo * r)
169
187
{
170
188
  (void) r;
171
189
  bool bad = (n <= 0 || n > HOST_DB_MAX_ROUND_ROBIN_INFO || good <= 0 || good > HOST_DB_MAX_ROUND_ROBIN_INFO);
177
195
  if (HostDBProcessor::hostdb_strict_round_robin) {
178
196
    best = current++ % good;
179
197
  } else {
180
 
    unsigned int ip = info[0].ip();
 
198
    sockaddr const* ip = info[0].ip();
181
199
    unsigned int best_hash = HOSTDB_CLIENT_IP_HASH(client_ip, ip);
182
200
    for (int i = 1; i < good; i++) {
183
201
      ip = info[i].ip();
192
210
}
193
211
 
194
212
inline HostDBInfo *
195
 
HostDBRoundRobin::select_best_http(unsigned int client_ip, time_t now, int32_t fail_window)
 
213
HostDBRoundRobin::select_best_http(sockaddr const* client_ip, ink_time_t now, int32_t fail_window)
196
214
{
197
215
  bool bad = (n <= 0 || n > HOST_DB_MAX_ROUND_ROBIN_INFO || good <= 0 || good > HOST_DB_MAX_ROUND_ROBIN_INFO);
 
216
 
198
217
  if (bad) {
199
218
    ink_assert(!"bad round robin size");
200
219
    return NULL;
204
223
  int best_up = -1;
205
224
 
206
225
  if (HostDBProcessor::hostdb_strict_round_robin) {
 
226
    Debug("hostdb", "Using strict round robin");
207
227
    best_up = current++ % good;
 
228
  } else if (HostDBProcessor::hostdb_timed_round_robin > 0) {
 
229
    Debug("hostdb", "Using timed round-robin for HTTP");
 
230
    if ((now - timed_rr_ctime) > HostDBProcessor::hostdb_timed_round_robin) {
 
231
      Debug("hostdb", "Timed interval expired.. rotating");
 
232
      ++current;
 
233
      timed_rr_ctime = now;
 
234
    }
 
235
    best_up = current % good;
 
236
    Debug("hostdb", "Using %d for best_up", best_up);
208
237
  } else {
 
238
    Debug("hostdb", "Using default round robin");
209
239
    unsigned int best_hash_any = 0;
210
240
    unsigned int best_hash_up = 0;
211
 
    unsigned int ip;
 
241
    sockaddr const* ip;
212
242
    for (int i = 0; i < good; i++) {
213
243
      ip = info[i].ip();
214
244
      unsigned int h = HOSTDB_CLIENT_IP_HASH(client_ip, ip);
269
299
struct HostDBContinuation: public Continuation
270
300
{
271
301
  Action action;
272
 
  unsigned int ip;
 
302
  IpEndpoint ip;
273
303
  unsigned int ttl;
274
 
  int port;
275
304
  bool is_srv_lookup;
276
305
  int dns_lookup_timeout;
277
306
  INK_MD5 md5;
309
338
  {
310
339
    return ((*name && is_srv_lookup) ? true : false);
311
340
  }
312
 
  HostDBInfo *lookup_done(int aip, char *aname, bool round_robin, unsigned int attl, SRVHosts * s = NULL);
 
341
  HostDBInfo *lookup_done(sockaddr const* aip, char *aname, bool round_robin, unsigned int attl, SRVHosts * s = NULL);
313
342
  bool do_get_response(Event * e);
314
343
  void do_put_response(ClusterMachine * m, HostDBInfo * r, Continuation * cont);
315
344
  int failed_cluster_request(Event * e);
321
350
 
322
351
  HostDBInfo *insert(unsigned int attl);
323
352
 
324
 
  void init(char *hostname, int len, int aip, int port, INK_MD5 & amd5,
 
353
  void init(const char *hostname, int len, sockaddr const* ip, INK_MD5 & amd5,
325
354
            Continuation * cont, void *pDS = 0, bool is_srv = false, int timeout = 0);
326
355
  int make_get_message(char *buf, int len);
327
356
  int make_put_message(HostDBInfo * r, Continuation * c, char *buf, int len);
328
357
 
329
358
HostDBContinuation():
330
 
  Continuation(NULL), ip(0), ttl(0), port(0),
 
359
  Continuation(NULL), ttl(0),
331
360
    is_srv_lookup(false), dns_lookup_timeout(0),
332
361
    timeout(0), from(0),
333
362
    from_cont(0), probe_depth(0), namelen(0), missing(false), force_dns(false), round_robin(false) {
 
363
    memset(&ip, 0, sizeof ip);
334
364
    memset(name, 0, MAXDNAME);
335
365
    md5.b[0] = 0;
336
366
    md5.b[1] = 0;
378
408
}
379
409
 
380
410
inline bool
381
 
is_dotted_form_hostname(char *c)
 
411
is_dotted_form_hostname(const char *c)
382
412
{
383
413
  return -1 != (int) ink_inet_addr(c);
384
414
}