]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
make names more constent, and use macros
authorAlan T. DeKok <aland@freeradius.org>
Mon, 12 Apr 2021 18:34:42 +0000 (14:34 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 12 Apr 2021 20:46:24 +0000 (16:46 -0400)
23 files changed:
src/include/build.h
src/lib/server/cf_file.c
src/lib/server/cf_util.c
src/lib/server/client.c
src/lib/server/dl_module.c
src/lib/server/map_proc.c
src/lib/server/trigger.c
src/lib/server/virtual_servers.c
src/lib/unlang/xlat_builtin.c
src/lib/unlang/xlat_inst.c
src/lib/util/dict_util.c
src/lib/util/event.c
src/lib/util/inet.c
src/lib/util/misc.h
src/lib/util/sbuff.c
src/modules/proto_ldap_sync/sync.c
src/modules/rlm_cache/drivers/rlm_cache_rbtree/rlm_cache_rbtree.c
src/modules/rlm_detail/rlm_detail.c
src/modules/rlm_icmp/rlm_icmp.c
src/modules/rlm_isc_dhcp/rlm_isc_dhcp.c
src/modules/rlm_redis_ippool/rlm_redis_ippool_tool.c
src/modules/rlm_sigtran/sccp.c
src/protocols/radius/list.c

index 04bce840ed323b34949a120e4b9fd94087764c04..590b09ecfae84a4df7f828def8e7e1821fc301b5 100644 (file)
@@ -87,6 +87,14 @@ extern "C" {
  */
 #define CMP(_a, _b)                    CMP_PREFER_SMALLER(_a, _b)
 
+/*
+ *     Callbacks which make comparisons easier.
+ */
+#define CMP_RETURN(_field) do { \
+               ret = CMP(a->_field, b->_field); \
+               if (ret != 0) return ret; \
+       } while (0)
+
 /** Remove const qualification from a pointer
  *
  * @param[in] _type    The non-const version of the type.
index 96e03352b2354142fca8c68d7922d470b9dd2782..1f1bfe5c690fc7d3a5c861d8a5522953c48c703b 100644 (file)
@@ -500,15 +500,14 @@ static bool cf_template_merge(CONF_SECTION *cs, CONF_SECTION const *template)
 /*
  *     Functions for tracking files by inode
  */
-static int _inode_cmp(void const *a, void const *b)
+static int _inode_cmp(void const *one, void const *two)
 {
-       cf_file_t const *one = a, *two = b;
+       cf_file_t const *a = one, *b = two;
        int ret;
 
-       ret = (one->buf.st_dev < two->buf.st_dev) - (one->buf.st_dev > two->buf.st_dev);
-       if (ret != 0) return ret;
+       CMP_RETURN(buf.st_dev);
 
-       return (one->buf.st_ino < two->buf.st_ino) - (one->buf.st_ino > two->buf.st_ino);
+       return CMP(a->buf.st_ino, b->buf.st_ino);
 }
 
 static int cf_file_open(CONF_SECTION *cs, char const *filename, bool from_dir, FILE **fp_p)
@@ -824,14 +823,12 @@ typedef struct cf_file_heap_t {
 
 static int8_t filename_cmp(void const *one, void const *two)
 {
-       int rcode;
+       int ret;
        cf_file_heap_t const *a = one;
        cf_file_heap_t const *b = two;
 
-       rcode = strcmp(a->filename, b->filename);
-       if (rcode < 0) return -1;
-       if (rcode > 0) return +1;
-       return 0;
+       ret = strcmp(a->filename, b->filename);
+       return CMP(ret, 0);
 }
 
 
index 2860ad752ff740fa69f47c735c33f8ce0f5f4722..f01d44ec857cd6787efd63e2a050c2c0c83c3a88 100644 (file)
@@ -235,50 +235,47 @@ static CONF_ITEM *cf_find_next(CONF_ITEM const *parent, CONF_ITEM const *prev,
  * For CONF_ITEM_SECTION this is 'name1'.
  * For CONF_ITEM_DATA this is 'type'.
  *
- * @param[in] a        First CONF_ITEM to compare.
- * @param[in] b Second CONF_ITEM to compare.
- * @return
- *     - >0 if a > b.
- *     - <0 if a < b.
- *     - 0 if a == b.
+ * @param[in] one      First CONF_ITEM to compare.
+ * @param[in] two      Second CONF_ITEM to compare.
+ * @return CMP(one, two)
  */
-static inline int _cf_ident1_cmp(void const *a, void const *b)
+static inline int _cf_ident1_cmp(void const *one, void const *two)
 {
+       int ret;
+
        CONF_ITEM_TYPE type;
 
        {
-               CONF_ITEM const *one = a;
-               CONF_ITEM const *two = b;
+               CONF_ITEM const *a = one;
+               CONF_ITEM const *b = two;
 
-               if (one->type > two->type) return +1;
-               if (one->type < two->type) return -1;
-
-               type = one->type;
+               CMP_RETURN(type);
+               type = a->type;
        }
 
        switch (type) {
        case CONF_ITEM_PAIR:
        {
-               CONF_PAIR const *one = a;
-               CONF_PAIR const *two = b;
+               CONF_PAIR const *a = one;
+               CONF_PAIR const *b = two;
 
-               return strcmp(one->attr, two->attr);
+               return strcmp(a->attr, b->attr);
        }
 
        case CONF_ITEM_SECTION:
        {
-               CONF_SECTION const *one = a;
-               CONF_SECTION const *two = b;
+               CONF_SECTION const *a = one;
+               CONF_SECTION const *b = two;
 
-               return strcmp(one->name1, two->name1);
+               return strcmp(a->name1, b->name1);
        }
 
        case CONF_ITEM_DATA:
        {
-               CONF_DATA const *one = a;
-               CONF_DATA const *two = b;
+               CONF_DATA const *a = one;
+               CONF_DATA const *b = two;
 
-               return strcmp(one->type, two->type);
+               return strcmp(a->type, b->type);
        }
 
        default:
@@ -292,16 +289,13 @@ static inline int _cf_ident1_cmp(void const *a, void const *b)
  * For CONF_ITEM_SECTION this is 'name2'.
  * For CONF_ITEM_DATA this is 'name'.
  *
- * @param[in] a        First CONF_ITEM to compare.
- * @param[in] b Second CONF_ITEM to compare.
- * @return
- *     - >0 if a > b.
- *     - <0 if a < b.
- *     - 0 if a == b.
+ * @param[in] one      First CONF_ITEM to compare.
+ * @param[in] two      Second CONF_ITEM to compare.
+ * @return CMP(one,two)
  */
-static inline int cf_ident2_cmp(void const *a, void const *b)
+static inline int cf_ident2_cmp(void const *one, void const *two)
 {
-       CONF_ITEM const *ci = a;
+       CONF_ITEM const *ci = one;
 
        switch (ci->type) {
        case CONF_ITEM_PAIR:
@@ -309,26 +303,26 @@ static inline int cf_ident2_cmp(void const *a, void const *b)
 
        case CONF_ITEM_SECTION:
        {
-               CONF_SECTION const *one = a;
-               CONF_SECTION const *two = b;
+               CONF_SECTION const *a = one;
+               CONF_SECTION const *b = two;
 
-               if (!two->name2 && one->name2) return +1;
-               if (two->name2 && !one->name2) return -1;
-               if (!two->name2 && !one->name2) return 0;
+               if (!b->name2 && a->name2) return +1;
+               if (b->name2 && !a->name2) return -1;
+               if (!b->name2 && !a->name2) return 0;
 
-               return strcmp(one->name2, two->name2);
+               return strcmp(a->name2, b->name2);
        }
 
        case CONF_ITEM_DATA:
        {
-               CONF_DATA const *one = a;
-               CONF_DATA const *two = b;
+               CONF_DATA const *a = one;
+               CONF_DATA const *b = two;
 
-               if (!two->name && one->name) return +1;
-               if (two->name && !one->name) return -1;
-               if (!two->name && !one->name) return 0;
+               if (!b->name && a->name) return +1;
+               if (b->name && !a->name) return -1;
+               if (!b->name && !a->name) return 0;
 
-               return strcmp(one->name, two->name);
+               return strcmp(a->name, b->name);
        }
 
        default:
@@ -344,10 +338,7 @@ static inline int cf_ident2_cmp(void const *a, void const *b)
  *
  * @param[in] a        First CONF_ITEM to compare.
  * @param[in] b Second CONF_ITEM to compare.
- * @return
- *     - >0 if a > b.
- *     - <0 if a < b.
- *     - 0 if a == b.
+ * @return CMP(a, b)
  */
 static int _cf_ident2_cmp(void const *a, void const *b)
 {
index 94287f2b5dcf839b7be1834ae5794c01f615d69b..915aa106bef34a2aef1e7f91e623e9216be029b2 100644 (file)
@@ -77,7 +77,7 @@ static int client_cmp(void const *one, void const *two)
         */
        if ((a->proto == IPPROTO_IP) || (b->proto == IPPROTO_IP)) return 0;
 
-       return a->proto - b->proto;
+       return CMP(a->proto, b->proto);
 }
 
 #endif
index f2a3f3b54d2423e3bc2f358979d3ce8c6e75f4e3..e1fd833398c4ab0ebe6631e666dc39e2d66a171c 100644 (file)
@@ -76,7 +76,7 @@ static int dl_module_inst_data_cmp(void const *one, void const *two)
        fr_assert(a->data);
        fr_assert(b->data);
 
-       return (a->data > b->data) - (a->data < b->data);
+       return CMP(a->data, b->data);
 }
 
 static int dl_module_cmp(void const *one, void const *two)
index 34ae45fc717c8376a669d7228f2e82278ed0b11b..a5cb5169036a1b9626ff73ff87615588488855d8 100644 (file)
@@ -41,10 +41,12 @@ static rbtree_t *map_proc_root = NULL;
 static int map_proc_cmp(void const *one, void const *two)
 {
        map_proc_t const *a = one, *b = two;
+       int ret;
 
-       if (a->length != b->length) return a->length - b->length;
+       CMP_RETURN(length);
 
-       return memcmp(a->name, b->name, a->length);
+       ret = memcmp(a->name, b->name, a->length);
+       return CMP(ret, 0);
 }
 
 /** Unregister a map processor
index ea0897a66cd1ef9c6e352d040110d17dd0452b6c..be56568a6b1aa5a805087997cbe04c07d6839127 100644 (file)
@@ -109,18 +109,15 @@ static void _trigger_last_fired_free(void *data)
 
 /** Compares two last fired structures
  *
- * @param a first pointer to compare.
- * @param b second pointer to compare.
- * @return
- *     - -1 if a < b.
- *     - +1 if b > a.
- *     - 0 if both equal.
+ * @param one first pointer to compare.
+ * @param two second pointer to compare.
+ * @return CMP(one, two)
  */
-static int _trigger_last_fired_cmp(void const *a, void const *b)
+static int _trigger_last_fired_cmp(void const *one, void const *two)
 {
-       trigger_last_fired_t const *lf_a = a, *lf_b = b;
+       trigger_last_fired_t const *a = one, *b = two;
 
-       return (lf_a->ci < lf_b->ci) - (lf_a->ci > lf_b->ci);
+       return CMP(a->ci, b->ci);
 }
 
 /** Set the global trigger section trigger_exec will search in, and register xlats
index 6c2bb7e586a8ba9806d7f32867e9ddc68cd2da98..8859540935b4da429408dd42120912c3a11ddc97 100644 (file)
@@ -689,7 +689,7 @@ static int listen_addr_cmp(void const *one, void const *two)
        fr_listen_t const *a = one;
        fr_listen_t const *b = two;
        fr_ipaddr_t aip, bip;
-       int rcode;
+       int ret;
 
        /*
         *      The caller must ensure that the address field is set.
@@ -701,14 +701,12 @@ static int listen_addr_cmp(void const *one, void const *two)
        /*
         *      UDP vs TCP
         */
-       rcode = a->app_io_addr->proto - b->app_io_addr->proto;
-       if (rcode != 0) return rcode;
+       CMP_RETURN(app_io_addr->proto);
 
        /*
         *      Check ports.
         */
-       rcode = a->app_io_addr->inet.src_port - b->app_io_addr->inet.src_port;
-       if (rcode != 0) return rcode;
+       CMP_RETURN(app_io_addr->inet.src_port);
 
        /*
         *      Don't call fr_ipaddr_cmp(), as we need to do our own
@@ -719,19 +717,17 @@ static int listen_addr_cmp(void const *one, void const *two)
        /*
         *      Different address families.
         */
-       rcode = a->app_io_addr->inet.src_ipaddr.af - b->app_io_addr->inet.src_ipaddr.af;
-       if (rcode != 0) return rcode;
+       CMP_RETURN(app_io_addr->inet.src_ipaddr.af);
 
        /*
         *      If both are bound to interfaces, AND the interfaces
         *      are different, then there is no conflict.
         */
        if (a->app_io_addr->inet.src_ipaddr.scope_id && b->app_io_addr->inet.src_ipaddr.scope_id) {
-               rcode = a->app_io_addr->inet.src_ipaddr.scope_id - b->app_io_addr->inet.src_ipaddr.scope_id;
-               if (rcode != 0) return rcode;
+               CMP_RETURN(app_io_addr->inet.src_ipaddr.scope_id);
        }
 
-       rcode = a->app_io_addr->inet.src_ipaddr.prefix - b->app_io_addr->inet.src_ipaddr.prefix;
+       ret = a->app_io_addr->inet.src_ipaddr.prefix - b->app_io_addr->inet.src_ipaddr.prefix;
        aip = a->app_io_addr->inet.src_ipaddr;
        bip = b->app_io_addr->inet.src_ipaddr;
 
@@ -739,10 +735,10 @@ static int listen_addr_cmp(void const *one, void const *two)
         *      Mask out the longer prefix to match the shorter
         *      prefix.
         */
-       if (rcode < 0) {
+       if (ret < 0) {
                fr_ipaddr_mask(&bip, a->app_io_addr->inet.src_ipaddr.prefix);
 
-       } else if (rcode > 0) {
+       } else if (ret > 0) {
                fr_ipaddr_mask(&aip, b->app_io_addr->inet.src_ipaddr.prefix);
 
        }
@@ -1187,12 +1183,14 @@ static void _virtual_namespace_free(void *data)
 /** Compare two virtual namespace callbacks
  *
  */
-static int _virtual_namespace_cmp(void const *a, void const *b)
+static int _virtual_namespace_cmp(void const *one, void const *two)
 {
-       fr_virtual_namespace_t const *ns_a = a;
-       fr_virtual_namespace_t const *ns_b = b;
+       fr_virtual_namespace_t const *a = one;
+       fr_virtual_namespace_t const *b = two;
+       int ret;
 
-       return strcmp(ns_a->namespace, ns_b->namespace);
+       ret = strcmp(a->namespace, b->namespace);
+       return CMP(ret, 0);
 }
 
 /** Add a callback for a specific namespace
@@ -1588,18 +1586,20 @@ int virtual_server_compile_sections(CONF_SECTION *server, virtual_server_compile
 
 static int server_section_name_cmp(void const *one, void const *two)
 {
-       int rcode;
        virtual_server_compile_t const *a = one;
        virtual_server_compile_t const *b = two;
+       int ret;
 
-       rcode = strcmp(a->name, b->name);
-       if (rcode != 0) return rcode;
+       ret = strcmp(a->name, b->name);
+       ret = CMP(ret, 0);
+       if (ret != 0) return ret;
 
        if (a->name2 == b->name2) return 0;
        if ((a->name2 == CF_IDENT_ANY) && (b->name2 != CF_IDENT_ANY)) return -1;
        if ((a->name2 != CF_IDENT_ANY) && (b->name2 == CF_IDENT_ANY)) return +1;
 
-       return strcmp(a->name2, b->name2);
+       ret = strcmp(a->name2, b->name2);
+       return CMP(ret, 0);
 }
 
 /** Register name1 / name2 as allowed processing sections
index 291b7770f0ae05fe80f2a5cb85cc5e65a22e019d..4fef85fdac4eb4bb1b414e867e544bbe32e5d43f 100644 (file)
@@ -102,10 +102,11 @@ static int xlat_cmp(void const *one, void const *two)
        a_len = strlen(a->name);
        b_len = strlen(b->name);
 
-       ret = (a_len > b_len) - (a_len < b_len);
+       ret = CMP(a_len, b_len);
        if (ret != 0) return ret;
 
-       return memcmp(a->name, b->name, a_len);
+       ret = memcmp(a->name, b->name, a_len);
+       return CMP(ret, 0);
 }
 
 
index 7bf9b4925e4c490b3501a7da5df103cc681cbfd7..7e5fe447bf3d5f69c314babd3772e476196a3416 100644 (file)
@@ -42,34 +42,28 @@ static _Thread_local rbtree_t *xlat_thread_inst_tree;
 
 /** Compare two xlat instances based on node pointer
  *
- * @param[in] a                First xlat expansion instance.
- * @param[in] b                Second xlat expansion instance.
- * @return
- *     - +1 if a > b.
- *     - -1 if a < b.
- *     - 0 if a == b.
+ * @param[in] one              First xlat expansion instance.
+ * @param[in] two      Second xlat expansion instance.
+ * @return CMP(one, two)
  */
-static int _xlat_inst_cmp(void const *a, void const *b)
+static int _xlat_inst_cmp(void const *one, void const *two)
 {
-       xlat_inst_t const *my_a = a, *my_b = b;
+       xlat_inst_t const *a = one, *b = two;
 
-       return (my_a->node > my_b->node) - (my_a->node < my_b->node);
+       return CMP(a->node, b->node);
 }
 
 /** Compare two thread instances based on node pointer
  *
- * @param[in] a                First thread specific xlat expansion instance.
- * @param[in] b                Second thread specific xlat expansion instance.
- * @return
- *     - +1 if a > b.
- *     - -1 if a < b.
- *     - 0 if a == b.
+ * @param[in] one      First thread specific xlat expansion instance.
+ * @param[in] two      Second thread specific xlat expansion instance.
+ * @return CMP(one, two)
  */
-static int _xlat_thread_inst_cmp(void const *a, void const *b)
+static int _xlat_thread_inst_cmp(void const *one, void const *two)
 {
-       xlat_thread_inst_t const *my_a = a, *my_b = b;
+       xlat_thread_inst_t const *a = one, *b = two;
 
-       return (my_a->node > my_b->node) - (my_a->node < my_b->node);
+       return CMP(a->node, b->node);
 }
 
 /** Destructor for xlat_thread_inst_t
index 7db5e65108e7ab4b2910bcacaef8fe3f8aa90f41..24f182947592bb3b441886356e626afb45733d3d 100644 (file)
@@ -156,7 +156,7 @@ static int dict_protocol_num_cmp(void const *one, void const *two)
        fr_dict_t const *a = one;
        fr_dict_t const *b = two;
 
-       return a->root->attr - b->root->attr;
+       return CMP(a->root->attr, b->root->attr);
 }
 
 /** Wrap name hash function for fr_dict_attr_t
@@ -225,7 +225,7 @@ static int dict_vendor_pen_cmp(void const *one, void const *two)
        fr_dict_vendor_t const *a = one;
        fr_dict_vendor_t const *b = two;
 
-       return a->pen - b->pen;
+       return CMP(a->pen, b->pen);
 }
 
 /** Hash a enumeration name
index ef1e6daf3d01c3c6483108875e346e7515ba0c61..f07f8efe3b1810be0ab5623267f99a56c7c50940 100644 (file)
@@ -400,30 +400,26 @@ static int8_t fr_event_timer_cmp(void const *a, void const *b)
 
 /** Compare two file descriptor handles
  *
- * @param[in] a the first file descriptor handle.
- * @param[in] b the second file descriptor handle.
- * @return
- *     - +1 if a is more than b.
- *     - -1 if a is less than b.
- *     - 0 if both handles refer to the same file descriptor.
+ * @param[in] one the first file descriptor handle.
+ * @param[in] two the second file descriptor handle.
+ * @return CMP(one, two)
  */
-static int fr_event_fd_cmp(void const *a, void const *b)
+static int fr_event_fd_cmp(void const *one, void const *two)
 {
-       fr_event_fd_t const     *ev_a = a, *ev_b = b;
+       fr_event_fd_t const     *a = one, *b = two;
        int                     ret;
 
-       ret = (ev_a->fd < ev_b->fd) - (ev_a->fd > ev_b->fd);
-       if (ret != 0) return ret;
+       CMP_RETURN(fd);
 
-       return (ev_a->filter > ev_b->filter) - (ev_a->filter < ev_b->filter);
+       return CMP(a->filter, b->filter);
 }
 
 #ifdef LOCAL_PID
-static int8_t fr_event_pid_cmp(void const *a, void const *b)
+static int8_t fr_event_pid_cmp(void const *one, void const *two)
 {
-       fr_event_pid_t const    *ev_a = a, *ev_b = b;
+       fr_event_pid_t const    *a = one, *b = two;
 
-       return CMP(ev_a->pid, ev_b->pid);
+       return CMP(a->pid, b->pid);
 }
 #endif
 
@@ -2377,10 +2373,9 @@ static int event_timer_location_cmp(void const *one, void const *two)
        fr_event_counter_t const        *b = two;
        int                             ret;
 
-       ret = (a->file > b->file) - (a->file < b->file);
-       if (ret != 0) return ret;
+       CMP_RETURN(file);
 
-       return (a->line > b->line) - (a->line < b->line);
+       return CMP(line);
 }
 
 
index 41ebbd4966185b1d592c33da54bdb38d04d93552..65c63ea8081709133967616382606c48929c635f 100644 (file)
@@ -1284,19 +1284,23 @@ int fr_ipaddr_from_ifindex(fr_ipaddr_t *out, int fd, int af, int ifindex)
  */
 int fr_ipaddr_cmp(fr_ipaddr_t const *a, fr_ipaddr_t const *b)
 {
-       if (a->af != b->af) return a->af - b->af;
-       if (a->prefix != b->prefix) return a->prefix - b->prefix;
+       int ret;
+
+       CMP_RETURN(af);
+       CMP_RETURN(prefix);
 
        switch (a->af) {
        case AF_INET:
-               return memcmp(&a->addr.v4,
-                             &b->addr.v4,
-                             sizeof(a->addr.v4));
+               ret = memcmp(&a->addr.v4,
+                            &b->addr.v4,
+                            sizeof(a->addr.v4));
+               return CMP(ret, 0);
 
 #ifdef HAVE_STRUCT_SOCKADDR_IN6
        case AF_INET6:
-               if (a->scope_id != b->scope_id) return a->scope_id - b->scope_id;
-               return memcmp(&a->addr.v6, &b->addr.v6, sizeof(a->addr.v6));
+               CMP_RETURN(scope_id);
+               ret = memcmp(&a->addr.v6, &b->addr.v6, sizeof(a->addr.v6));
+               return CMP(ret, 0);
 #endif
 
        default:
index 967d3c334a39ccf1d751a450fdc48d3733b2e806..d814f7dfc9ee6a2c9fd054055babddb3ba48b8d3 100644 (file)
@@ -40,7 +40,6 @@ typedef               int    (*fr_tmp_cmp_t)(void const *a, void const *b);
 typedef                void (*fr_free_t)(void *);
 typedef                uint32_t (*fr_hash_t)(void const *);
 
-
 /*
  *     Define TALLOC_DEBUG to check overflows with talloc.
  *     we can't use valgrind, because the memory used by
index ad196964bb757378122dccc4aa32cf9ce862b5f8..28332168cd0fcf45f2c8ebd24f3fc8f54113638e 100644 (file)
@@ -512,26 +512,20 @@ static inline bool fr_sbuff_terminal_search(fr_sbuff_t *in, char const *p,
 
 /** Compare two terminal elements for ordering purposes
  *
- * @param[in] a                first terminal to compare.
- * @param[in] b                second terminal to compare.
- * @return
- *     - >0    if a > b.
- *     - 0     if a == b.
- *     - <0    if a < b.
+ * @param[in] one              first terminal to compare.
+ * @param[in] two      second terminal to compare.
+ * @return CMP(one, two)
  */
-static inline int8_t terminal_cmp(void const *a, void const *b)
+static inline int8_t terminal_cmp(void const *one, void const *two)
 {
-       fr_sbuff_term_elem_t const      *our_a = a;
-       fr_sbuff_term_elem_t const      *our_b = b;
-
-       int8_t  ret;
-       int     i_ret;
+       fr_sbuff_term_elem_t const      *a = one;
+       fr_sbuff_term_elem_t const      *b = two;
+       int ret;
 
-       ret = (our_a->len > our_b->len) - (our_a->len < our_b->len);
-       if (ret != 0) return ret;
+       CMP_RETURN(len);
 
-       i_ret = memcmp(our_a->str, our_b->str, our_a->len);
-       return (i_ret > 0) - (i_ret < 0);
+       ret = memcmp(a->str, b->str, a->len);
+       return CMP(ret, 0);
 }
 
 /** Merge two sets of terminal strings
index a7168b334d179c47867b824172305d4c13d87c5b..be6fee0d2409012d1c98763dc6870aaeefc478c6 100644 (file)
@@ -885,13 +885,13 @@ static int _sync_state_free(sync_state_t *sync)
  *
  * @param[in] one first sync to compare.
  * @param[in] two second sync to compare.
- * @return the difference between the msgids.
+ * @return CMP(one, two)
  */
 static int _sync_cmp(void const *one, void const *two)
 {
        sync_state_t const *a = one, *b = two;
 
-       return a->msgid - b->msgid;
+       return CMP(a->msgid, b->msgid);
 }
 
 /** Destroy a sync (does not free config)
index 3cfdb5407e450a72e33b130105b0a7025ec62ea6..f6d3144806abbe6c3cc71dd39aee312e2e761bb5 100644 (file)
@@ -49,10 +49,10 @@ static int cache_entry_cmp(void const *one, void const *two)
        rlm_cache_entry_t const *a = one, *b = two;
        int ret;
 
-       ret = (a->key_len > b->key_len) - (a->key_len < b->key_len);
-       if (ret != 0) return ret;
+       CMP_RETURN(key_len);
 
-       return memcmp(a->key, b->key, a->key_len);
+       ret = memcmp(a->key, b->key, a->key_len);
+       return CMP(ret, 0);
 }
 
 /** Compare two entries by expiry time
@@ -63,7 +63,7 @@ static int8_t cache_heap_cmp(void const *one, void const *two)
 {
        rlm_cache_entry_t const *a = one, *b = two;
 
-       return (a->expires > b->expires) - (a->expires < b->expires);
+       return CMP(a->expires, b->expires);
 }
 
 /** Cleanup a cache_rbtree instance
index 7aac39109a530ab8fadeeeab2d9b712727d20455..1b86463adf0253841b4db62bec111fb15b807525 100644 (file)
@@ -124,7 +124,7 @@ static uint32_t detail_hash(void const *data)
 
 static int detail_cmp(void const *a, void const *b)
 {
-       return (a < b) - (a > b);
+       return CMP(a, b);
 }
 
 /*
index 6bc02bf3fcc3bcbfe0edabe04fd9934c4ce1943d..1892cf3c7ed6798e3093b64cf30c10feb4bf2d28 100644 (file)
@@ -293,7 +293,7 @@ static int echo_cmp(void const *one, void const *two)
        /*
         *      No need to check IP, because "counter" is unique for each packet.
         */
-       return (a->counter < b->counter) - (a->counter > b->counter);
+       return CMP(a->counter, b->counter);
 }
 
 static void mod_icmp_read(UNUSED fr_event_list_t *el, UNUSED int sockfd, UNUSED int flags, void *ctx)
index 90fa0c9609615042827cda4a6a7ecd2f32229f29..d673b3586609a20f37104f6ed93c9786c67f3d23 100644 (file)
@@ -794,9 +794,9 @@ static int host_uid_cmp(void const *one, void const *two)
 {
        isc_host_uid_t const *a = one;
        isc_host_uid_t const *b = two;
-
-       if ( a->client->vb_length < b->client->vb_length) return -1;
-       if ( a->client->vb_length > b->client->vb_length) return +1;
+       int ret;
+       
+       CMP_RETURN(client->vb_length);
 
        return memcmp(a->client->vb_octets, b->client->vb_octets, a->client->vb_length);
 }
index 3179c55d0a14d761e1b0d45bd4e7426c15f95280..8cb9e84c5f3b4ddbbd9502e6217db736d8f81d9d 100644 (file)
@@ -700,11 +700,11 @@ static int8_t pool_cmp(void const *a, void const *b)
        len_a = talloc_array_length((uint8_t const *)a);
        len_b = talloc_array_length((uint8_t const *)b);
 
-       ret = (len_a > len_b) - (len_a < len_b);
+       ret = CMP(len_a, len_b);
        if (ret != 0) return ret;
 
        ret = memcmp(a, b, len_a);
-       return (ret > 0) - (ret < 0);
+       return CMP(ret, 0);
 }
 
 /** Return the pools available across the cluster
index 9cc565e84b8f8a188d84a1c2148f8a2412887a3c..6783e83c190d448cc3fcce305c047bdde929d3b7 100644 (file)
@@ -58,18 +58,15 @@ static uint32_t     txn_tree_inst = 0;
 /** Compare rounds of a transaction
  *
  */
-static int sigtran_txn_cmp(void const *a, void const *b)
+static int sigtran_txn_cmp(void const *one, void const *two)
 {
-       sigtran_transaction_t const *a_tx = a;  /* May be stack allocated */
-       sigtran_transaction_t const *b_tx = b;  /* May be stack allocated */
+       sigtran_transaction_t const *a = one;   /* May be stack allocated */
+       sigtran_transaction_t const *b = two;   /* May be stack allocated */
+       int ret;
 
-       if (a_tx->ctx.otid > b_tx->ctx.otid) return +1;
-       if (a_tx->ctx.otid < b_tx->ctx.otid) return -1;
+       CMP_RETURN(ctx.otid);
 
-       if (a_tx->ctx.invoke_id > b_tx->ctx.invoke_id) return +1;
-       if (a_tx->ctx.invoke_id < b_tx->ctx.invoke_id) return -1;
-
-       return 0;
+       return CMP(a->ctx.invoke_id, b->ctx.invoke_id);
 }
 
 static void sigtran_tcap_timeout(void *data)
index 4f86d3c17c78e09d7bb2b2ac2d30ef1e79d8d398..8f9e22d3c6515b41bfb6dd53109449569de572ee 100644 (file)
@@ -47,19 +47,16 @@ int fr_packet_cmp(void const *a_v, void const *b_v)
        int ret;
 
        /*
-        *      256-way fanout.
+        *      256-way fanout for RADIUS IDs, then by FD.  And then
+        *      since there are sometimes multiple clients for one FD,
+        *      source port.  The comparison on dst_port is largely
+        *      redundant with the comparison on FD, but it's not
+        *      _completely_ redundant.
         */
-       if (a->id < b->id) return -1;
-       if (a->id > b->id) return +1;
-
-       if (a->socket.fd < b->socket.fd) return -1;
-       if (a->socket.fd > b->socket.fd) return +1;
-
-       /*
-        *      Source ports are pretty much random.
-        */
-       ret = (int) a->socket.inet.src_port - (int) b->socket.inet.src_port;
-       if (ret != 0) return ret;
+       CMP_RETURN(id);
+       CMP_RETURN(socket.fd);
+       CMP_RETURN(socket.inet.src_port);
+       CMP_RETURN(socket.inet.dst_port);
 
        /*
         *      Usually many client IPs, and few server IPs
@@ -67,22 +64,7 @@ int fr_packet_cmp(void const *a_v, void const *b_v)
        ret = fr_ipaddr_cmp(&a->socket.inet.src_ipaddr, &b->socket.inet.src_ipaddr);
        if (ret != 0) return ret;
 
-       /*
-        *      One socket can receive packets for multiple
-        *      destination IPs, so we check that before checking the
-        *      file descriptor.
-        */
-       ret = fr_ipaddr_cmp(&a->socket.inet.dst_ipaddr, &b->socket.inet.dst_ipaddr);
-       if (ret != 0) return ret;
-
-       /*
-        *      At this point, the order of comparing socket FDs
-        *      and/or destination ports doesn't matter.  One of those
-        *      fields will make the socket unique, and the other is
-        *      pretty much redundant.
-        */
-       ret = (int) a->socket.inet.dst_port - (int) b->socket.inet.dst_port;
-       return ret;
+       return fr_ipaddr_cmp(&a->socket.inet.dst_ipaddr, &b->socket.inet.dst_ipaddr);
 }
 
 /*