diff options
author | deraadt <> | 2014-04-19 16:38:04 +0000 |
---|---|---|
committer | deraadt <> | 2014-04-19 16:38:04 +0000 |
commit | a21c0bb00d07d5263cf88747b598ac88a87d65ec (patch) | |
tree | 72e7ed0aacd568ad5742f06d5326e6b2e3922d4c | |
parent | 7705026f86844d42c6b1e0ffb1e2e8d7f016ba58 (diff) | |
download | openbsd-a21c0bb00d07d5263cf88747b598ac88a87d65ec.tar.gz openbsd-a21c0bb00d07d5263cf88747b598ac88a87d65ec.tar.bz2 openbsd-a21c0bb00d07d5263cf88747b598ac88a87d65ec.zip |
Remove a gethostbyname() cache layer. The internet works better these
days. Initially fixed this, but Ted asked for it to die.
-rw-r--r-- | src/lib/libssl/src/apps/s_socket.c | 51 |
1 files changed, 1 insertions, 50 deletions
diff --git a/src/lib/libssl/src/apps/s_socket.c b/src/lib/libssl/src/apps/s_socket.c index baf6078a2b..01257a525e 100644 --- a/src/lib/libssl/src/apps/s_socket.c +++ b/src/lib/libssl/src/apps/s_socket.c | |||
@@ -77,7 +77,6 @@ | |||
77 | #ifndef OPENSSL_NO_SOCK | 77 | #ifndef OPENSSL_NO_SOCK |
78 | 78 | ||
79 | 79 | ||
80 | static struct hostent *GetHostByName(char *name); | ||
81 | static int ssl_sock_init(void); | 80 | static int ssl_sock_init(void); |
82 | static int init_server(int *sock, int port, int type); | 81 | static int init_server(int *sock, int port, int type); |
83 | static int init_server_long(int *sock, int port, char *ip, int type); | 82 | static int init_server_long(int *sock, int port, char *ip, int type); |
@@ -296,7 +295,7 @@ redoit: | |||
296 | return (0); | 295 | return (0); |
297 | } | 296 | } |
298 | 297 | ||
299 | h2 = GetHostByName(*host); | 298 | h2 = gethostbyname(*host); |
300 | if (h2 == NULL) { | 299 | if (h2 == NULL) { |
301 | BIO_printf(bio_err, "gethostbyname failure\n"); | 300 | BIO_printf(bio_err, "gethostbyname failure\n"); |
302 | return (0); | 301 | return (0); |
@@ -357,52 +356,4 @@ extract_port(char *str, short *port_ptr) | |||
357 | } | 356 | } |
358 | return (1); | 357 | return (1); |
359 | } | 358 | } |
360 | |||
361 | #define GHBN_NUM 4 | ||
362 | static struct ghbn_cache_st { | ||
363 | char name[128]; | ||
364 | struct hostent ent; | ||
365 | unsigned long order; | ||
366 | } ghbn_cache[GHBN_NUM]; | ||
367 | |||
368 | static unsigned long ghbn_hits = 0L; | ||
369 | static unsigned long ghbn_miss = 0L; | ||
370 | |||
371 | static struct hostent * | ||
372 | GetHostByName(char *name) | ||
373 | { | ||
374 | struct hostent *ret; | ||
375 | int i, lowi = 0; | ||
376 | unsigned long low = (unsigned long) -1; | ||
377 | |||
378 | for (i = 0; i < GHBN_NUM; i++) { | ||
379 | if (low > ghbn_cache[i].order) { | ||
380 | low = ghbn_cache[i].order; | ||
381 | lowi = i; | ||
382 | } | ||
383 | if (ghbn_cache[i].order > 0) { | ||
384 | if (strncmp(name, ghbn_cache[i].name, 128) == 0) | ||
385 | break; | ||
386 | } | ||
387 | } | ||
388 | if (i == GHBN_NUM) { /* no hit */ | ||
389 | ghbn_miss++; | ||
390 | ret = gethostbyname(name); | ||
391 | if (ret == NULL) | ||
392 | return (NULL); | ||
393 | /* else add to cache */ | ||
394 | if (strlen(name) < sizeof ghbn_cache[0].name) { | ||
395 | strlcpy(ghbn_cache[lowi].name, name, sizeof(ghbn_cache[0].name)); | ||
396 | memcpy((char *) &(ghbn_cache[lowi].ent), ret, sizeof(struct hostent)); | ||
397 | ghbn_cache[lowi].order = ghbn_miss + ghbn_hits; | ||
398 | } | ||
399 | return (ret); | ||
400 | } else { | ||
401 | ghbn_hits++; | ||
402 | ret = &(ghbn_cache[i].ent); | ||
403 | ghbn_cache[i].order = ghbn_miss + ghbn_hits; | ||
404 | return (ret); | ||
405 | } | ||
406 | } | ||
407 | |||
408 | #endif | 359 | #endif |