1 #include <stdint.h>
2 #ifndef WINDOWS
3 #include <sys/socket.h>
4 #else
5 #include <winsock2.h>
6 #endif
7 
8 #define ALG_HASH_VALID 1
9 #define ALG_ROUNDROBIN 2
10 #define ALG_WEIGHT 4
11 #define ALG_PRIO 8
12 #define ALG_HASH 16
13 #define ALG_STUBBORN 32
14 
15 #define EMERGENCY_SERVER (-1)
16 #define ABUSE_SERVER (-2)
17 #define NO_SERVER (-3)
18 
19 #define BLACKLIST_TIME	30	/* how long to shun a server that is down */
20 #define WEIGHT_FACTOR	256	/* to make weight kick in earlier */
21 
22 typedef struct {
23 	int status;		/* last failed connection attempt */
24 	int acl;		/* which clients can use this server */
25 	struct sockaddr_storage addr;
26 	uint8_t hwaddr[6];
27 	int c;			/* connections */
28 	int weight;		/* default 1 */
29 	int prio;
30 	int maxc;		/* max connections, soft limit */
31 	int hard;		/* max connections, hard limit */
32 	uint64_t sx, rx;	/* bytes sent, received */
33 } server;
34 
35 extern int nservers;		/* number of servers */
36 extern server *servers;
37 extern int current;
38 extern int emerg_server;
39 extern int abuse_server;
40 extern int blacklist_time;
41 extern int server_alg;
42 
43 extern char *e_server;
44 extern char *a_server;
45 
46 extern void setaddress(int, char *, int, int);
47 extern void blacklist_server(int);
48 extern int unused_server_slot(int);
49 extern int server_is_blacklisted(int);
50 extern int server_is_unavailable(int);
51 extern int server_by_roundrobin(void);
52 extern int initial_server(int);
53 extern int failover_server(int);
54 extern int try_server(int, int);
55 extern void expand_servertable(int);
56