struct server *server_find(struct proxy *bk, const char *name);
struct server *server_find_unique(struct proxy *bk, const char *name, uint32_t rid);
struct server *server_find_best_match(struct proxy *bk, char *name, int id, int *diff);
+uint server_get_next_id(const struct proxy *px, uint from);
void apply_server_state(void);
void srv_compute_all_admin_states(struct proxy *px);
int srv_set_addr_via_libc(struct server *srv, int *err_code);
/* server ID not set, use automatic numbering with first
* spare entry starting with next_svid.
*/
- next_id = get_next_id(&curproxy->conf.used_server_id, next_id);
+ next_id = server_get_next_id(curproxy, next_id);
newsrv->conf.id.key = newsrv->puid = next_id;
eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id);
}
return best_ptr;
}
+/* This function returns the first unused server ID greater than or equal to
+ * <from> in the proxy <px>. Zero is returned if no spare one is found (should
+ * never happen).
+ */
+uint server_get_next_id(const struct proxy *px, uint from)
+{
+ const struct eb32_node *used;
+
+ do {
+ used = eb32_lookup_ge((struct eb_root *)&px->conf.used_server_id, from);
+ if (!used || used->key > from)
+ return from; /* available */
+ from++;
+ } while (from);
+ return from;
+}
+
/* Parse the "backup" server keyword */
static int srv_parse_backup(char **args, int *cur_arg,
struct proxy *curproxy, struct server *newsrv, char **err)
/* generate the server id if not manually specified */
if (!srv->puid) {
- next_id = get_next_id(&be->conf.used_server_id, 1);
+ next_id = server_get_next_id(be, 1);
if (!next_id) {
ha_alert("Cannot attach server : no id left in proxy\n");
goto out;