From 8a027ccb3841b3d8eaec0bf4aba8fe3931e1fff8 Mon Sep 17 00:00:00 2001 From: Baptiste Assmann Date: Fri, 3 Jul 2015 11:03:33 +0200 Subject: [PATCH] MINOR: proxy: bit field for proxy_find_best_match diff status function proxy_find_best_match can update the caller by updating an int provided in argument. For now, proxy_find_best_match hardcode bit values 0x01, 0x02 and 0x04, which is not understandable when reading a code exploiting them. This patch defines 3 macros with a more explicit wording, so further reading of a code exploiting the magic bit values will be understandable more easily. --- include/types/proxy.h | 5 +++++ src/proxy.c | 23 +++++++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/include/types/proxy.h b/include/types/proxy.h index fa640edb5..0ce3ea9f7 100644 --- a/include/types/proxy.h +++ b/include/types/proxy.h @@ -186,6 +186,11 @@ enum pr_mode { #define STK_IS_STORE 0x00000002 /* store on request fetch */ #define STK_ON_RSP 0x00000004 /* store on response fetch */ +/* diff bits for proxy_find_best_match */ +#define PR_FBM_MISMATCH_ID 0x01 +#define PR_FBM_MISMATCH_NAME 0x02 +#define PR_FBM_MISMATCH_PROXYTYPE 0x04 + struct stream; struct error_snapshot { diff --git a/src/proxy.c b/src/proxy.c index 90d131356..b690a81fe 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -533,9 +533,12 @@ struct proxy *proxy_find_by_name(const char *name, int cap, int table) * ok ok ok | perfect match * * Upon return if is not NULL, it is zeroed then filled with up to 3 bits : - * - 0x01 : proxy was found but ID differs (and ID was not zero) - * - 0x02 : proxy was found by ID but name differs (and name was not NULL) - * - 0x04 : a proxy of different type was found with the same name and/or id + * - PR_FBM_MISMATCH_ID : proxy was found but ID differs + * (and ID was not zero) + * - PR_FBM_MISMATCH_NAME : proxy was found by ID but name differs + * (and name was not NULL) + * - PR_FBM_MISMATCH_PROXYTYPE : a proxy of different type was found with + * the same name and/or id * * Only a valid proxy is returned. If capabilities do not match, NULL is * returned. The caller can check to report detailed warnings / errors, @@ -574,12 +577,12 @@ struct proxy *proxy_find_best_match(int cap, const char *name, int id, int *diff */ if (byid->options & PR_O_FORCED_ID) { if (diff) - *diff |= 2; + *diff |= PR_FBM_MISMATCH_NAME; return byid; } else { if (diff) - *diff |= 1; + *diff |= PR_FBM_MISMATCH_ID; return byname; } } @@ -589,14 +592,14 @@ struct proxy *proxy_find_best_match(int cap, const char *name, int id, int *diff * - name set but not found */ if (name && diff) - *diff |= 2; + *diff |= PR_FBM_MISMATCH_NAME; return byid; } /* ID not found */ if (byname) { if (diff) - *diff |= 1; + *diff |= PR_FBM_MISMATCH_ID; return byname; } } @@ -615,16 +618,16 @@ struct proxy *proxy_find_best_match(int cap, const char *name, int id, int *diff if (name) { byname = proxy_find_by_name(name, 0, 0); if (byname && (!id || byname->uuid == id)) - *diff |= 4; + *diff |= PR_FBM_MISMATCH_PROXYTYPE; } if (id) { byid = proxy_find_by_id(id, 0, 0); if (byid) { if (!name) - *diff |= 4; /* only type changed */ + *diff |= PR_FBM_MISMATCH_PROXYTYPE; /* only type changed */ else if (byid->options & PR_O_FORCED_ID) - *diff |= 2 | 4; /* name and type changed */ + *diff |= PR_FBM_MISMATCH_NAME | PR_FBM_MISMATCH_PROXYTYPE; /* name and type changed */ /* otherwise it's a different proxy that was returned */ } }