]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: proxy: bit field for proxy_find_best_match diff status
authorBaptiste Assmann <bedis9@gmail.com>
Fri, 3 Jul 2015 09:03:33 +0000 (11:03 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 21 Jul 2015 21:24:16 +0000 (23:24 +0200)
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
src/proxy.c

index fa640edb525214e6535a19c8e9d08f1e0d34aa2c..0ce3ea9f7a74087f46d15f60880082abb1fa9d4b 100644 (file)
@@ -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 {
index 90d1313564cd23b8e1a45869f93c1cfe3660f684..b690a81febcd6d448f92ca04f43ad90fa44cee0e 100644 (file)
@@ -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 <diff> 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 <diff> 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 */
                }
        }