From: Willy Tarreau Date: Wed, 9 Jul 2025 14:35:27 +0000 (+0200) Subject: CLEANUP: server: simplify server_find_by_id() X-Git-Tag: v3.3-dev4~90 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fda04994d90cc9b731346f73037328881e9bd638;p=thirdparty%2Fhaproxy.git CLEANUP: server: simplify server_find_by_id() At a few places we're seeing some open-coding of the same function, likely because it looks overkill for what it's supposed to do, due to extraneous tests that are not needed (e.g. check of the backend's PR_CAP_BE etc). Let's just remove all these superfluous tests and inline it so that it feels more suitable for use everywhere it's needed. --- diff --git a/include/haproxy/server.h b/include/haproxy/server.h index 50768e79f..b1b1588eb 100644 --- a/include/haproxy/server.h +++ b/include/haproxy/server.h @@ -59,7 +59,6 @@ const char *srv_update_addr_port(struct server *s, const char *addr, const char const char *server_inetaddr_updater_by_to_str(enum server_inetaddr_updater_by by); const char *srv_update_check_addr_port(struct server *s, const char *addr, const char *port); const char *srv_update_agent_addr_port(struct server *s, const char *addr, const char *port); -struct server *server_find_by_id(struct proxy *bk, int id); struct server *server_find_by_id_unique(struct proxy *bk, int id, uint32_t rid); struct server *server_find_by_name(struct proxy *px, const char *name); struct server *server_find(struct proxy *bk, const char *name); @@ -344,6 +343,18 @@ static inline void srv_detach(struct server *srv) } } +/* Returns a pointer to the first server matching id in backend . + * NULL is returned if no match is found. + */ +static inline struct server *server_find_by_id(struct proxy *bk, int id) +{ + struct eb32_node *eb32; + + eb32 = eb32_lookup(&bk->conf.used_server_id, id); + return eb32 ? container_of(eb32, struct server, conf.id) : NULL; +} + + static inline int srv_is_quic(const struct server *srv) { #ifdef USE_QUIC diff --git a/src/server.c b/src/server.c index c0a0bd552..f92787483 100644 --- a/src/server.c +++ b/src/server.c @@ -3958,31 +3958,6 @@ int parse_server(const char *file, int linenum, char **args, return err_code; } -/* Returns a pointer to the first server matching either id . - * NULL is returned if no match is found. - * the lookup is performed in the backend - */ -struct server *server_find_by_id(struct proxy *bk, int id) -{ - struct eb32_node *eb32; - struct server *curserver; - - if (!bk || (id ==0)) - return NULL; - - /* has no backend capabilities, so it can't have a server */ - if (!(bk->cap & PR_CAP_BE)) - return NULL; - - curserver = NULL; - - eb32 = eb32_lookup(&bk->conf.used_server_id, id); - if (eb32) - curserver = container_of(eb32, struct server, conf.id); - - return curserver; -} - /* * This function finds a server with matching " x " within * selected backend .