diff --git a/include/haproxy/proxy.h b/include/haproxy/proxy.h index 27a7ae861..039077242 100644 --- a/include/haproxy/proxy.h +++ b/include/haproxy/proxy.h @@ -58,6 +58,8 @@ struct proxy *proxy_find_by_id(int id, int cap, int table); struct proxy *proxy_find_by_name(const char *name, int cap, int table); struct proxy *proxy_find_best_match(int cap, const char *name, int id, int *diff); struct server *findserver(const struct proxy *px, const char *name); +struct server *findserver_unique_id(const struct proxy *px, int puid, uint32_t rid); +struct server *findserver_unique_name(const struct proxy *px, const char *name, uint32_t rid); int proxy_cfg_ensure_no_http(struct proxy *curproxy); void init_new_proxy(struct proxy *p); void proxy_preset_defaults(struct proxy *defproxy); diff --git a/src/proxy.c b/src/proxy.c index 89c9cbe8f..8d4de56e3 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -1285,6 +1285,50 @@ struct server *findserver(const struct proxy *px, const char *name) { return target; } +/* + * This function finds a server with matching " x " within + * selected proxy . + * Using the combination of proxy-uid + revision id ensures that the function + * will either return the server we're expecting or NULL if it has been removed + * from the proxy. + */ +struct server *findserver_unique_id(const struct proxy *px, int puid, uint32_t rid) { + + struct server *cursrv; + + if (!px) + return NULL; + + for (cursrv = px->srv; cursrv; cursrv = cursrv->next) { + if (cursrv->puid == puid && cursrv->rid == rid) + return cursrv; + } + + return NULL; +} + +/* + * This function finds a server with matching " x " within + * selected proxy . + * Using the combination of name + revision id ensures that the function will + * either return the server we're expecting or NULL if it has been removed + * from the proxy. + */ +struct server *findserver_unique_name(const struct proxy *px, const char *name, uint32_t rid) { + + struct server *cursrv; + + if (!px) + return NULL; + + for (cursrv = px->srv; cursrv; cursrv = cursrv->next) { + if (!strcmp(cursrv->id, name) && cursrv->rid == rid) + return cursrv; + } + + return NULL; +} + /* This function checks that the designated proxy has no http directives * enabled. It will output a warning if there are, and will fix some of them. * It returns the number of fatal errors encountered. This should be called