Skip to content

Commit

Permalink
Include port number in the hash server selection algorithm when -r (r…
Browse files Browse the repository at this point in the history
…oundrobin) is specified
  • Loading branch information
ulric committed Oct 12, 2015
1 parent ad993ba commit 2f345d7
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 10 deletions.
4 changes: 0 additions & 4 deletions client.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ int store_client(struct sockaddr_storage *cli)
clients[i].addr = *cli;
clients[i].connects++;

/* don't remember server */
if(server_alg & ALG_HASH_NO_SERVER) {
clients[i].server = NO_SERVER;
}

DEBUG(2, "Client %s has index %d", pen_ntoa(cli), i);

Expand Down
3 changes: 0 additions & 3 deletions pen.c
Original file line number Diff line number Diff line change
Expand Up @@ -2415,9 +2415,6 @@ static int options(int argc, char **argv)
}
break;
#endif /* HAVE_LIBSSL */
case 'N':
server_alg |= ALG_HASH_NO_SERVER;
break;
case '?':
default:
usage();
Expand Down
8 changes: 6 additions & 2 deletions server.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ static int pen_hash(struct sockaddr_storage *a)
switch (a->ss_family) {
case AF_INET:
si = (struct sockaddr_in *)a;
hash = (si->sin_addr.s_addr ^ si->sin_port) % nservers;
if (server_alg & ALG_ROUNDROBIN) {
hash = (si->sin_addr.s_addr ^ si->sin_port) % nservers;
} else {
hash = si->sin_addr.s_addr % nservers;
}

DEBUG(2, "Hash: %d", hash);

Expand Down Expand Up @@ -206,7 +210,7 @@ int initial_server(int conn)
}
if (server_alg & ALG_PRIO) return server_by_prio();
if (server_alg & ALG_WEIGHT) return server_by_weight();
if (server_alg & ALG_HASH || server_alg & ALG_HASH_NO_SERVER) return pen_hash(&clients[conns[conn].client].addr);
if (server_alg & ALG_HASH) return pen_hash(&clients[conns[conn].client].addr);
return server_by_roundrobin();
}

Expand Down
1 change: 0 additions & 1 deletion server.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#define ALG_PRIO 8
#define ALG_HASH 16
#define ALG_STUBBORN 32
#define ALG_HASH_NO_SERVER 64

#define EMERGENCY_SERVER (-1)
#define ABUSE_SERVER (-2)
Expand Down

0 comments on commit 2f345d7

Please sign in to comment.