]> git.puffer.fish Git - mirror/frr.git/commitdiff
*: use compiler.h MIN/MAX macros instead of everyone having one 10033/head
authorDonald Sharp <sharpd@nvidia.com>
Thu, 11 Nov 2021 14:39:52 +0000 (09:39 -0500)
committerDonald Sharp <sharpd@nvidia.com>
Thu, 11 Nov 2021 14:39:52 +0000 (09:39 -0500)
We had various forms of min/max macros across multiple daemons
all of which duplicated what we have in compiler.h.  Convert
everyone to use the `correct` ones

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
12 files changed:
bgpd/bgp_aspath.c
bgpd/bgp_nht.c
bgpd/bgp_updgrp_adv.c
bgpd/bgpd.h
ldpd/hello.c
ldpd/init.c
ldpd/ldpe.h
lib/snmp.c
pathd/path_pcep_controller.c
pimd/pim_msdp_packet.h
pimd/pimd.h
ripngd/ripng_nexthop.c

index 3c67017dc7209856f52a995f63c469e25a60119f..d3424b29578601b8066c05a760fb128a4f4fcaea 100644 (file)
@@ -1002,8 +1002,6 @@ uint8_t *aspath_snmp_pathseg(struct aspath *as, size_t *varlen)
        return stream_pnt(snmp_stream);
 }
 
-#define min(A,B) ((A) < (B) ? (A) : (B))
-
 static struct assegment *aspath_aggregate_as_set_add(struct aspath *aspath,
                                                     struct assegment *asset,
                                                     as_t as)
@@ -1060,7 +1058,7 @@ struct aspath *aspath_aggregate(struct aspath *as1, struct aspath *as2)
                        break;
 
                /* Minimum segment length. */
-               minlen = min(seg1->length, seg2->length);
+               minlen = MIN(seg1->length, seg2->length);
 
                for (match = 0; match < minlen; match++)
                        if (seg1->as[match] != seg2->as[match])
index 28dd19d842c7587b06f7555033f615f03a9ac275..a33e9800e6be0e1ea2a4241c1cb296f6575283bf 100644 (file)
@@ -1298,12 +1298,11 @@ static void bgp_l3nhg_zebra_init(void)
 }
 
 
-#define min(A, B) ((A) < (B) ? (A) : (B))
 void bgp_l3nhg_init(void)
 {
        uint32_t id_max;
 
-       id_max = min(ZEBRA_NHG_PROTO_SPACING - 1, 16 * 1024);
+       id_max = MIN(ZEBRA_NHG_PROTO_SPACING - 1, 16 * 1024);
        bf_init(bgp_nh_id_bitmap, id_max);
        bf_assign_zero_index(bgp_nh_id_bitmap);
 
index 96febcd5df12352ff86c24d43155165f8d07597d..e43ae5c13f9372ba0a1c8a8a27f09ef00d83f44f 100644 (file)
@@ -553,7 +553,7 @@ void bgp_adj_out_set_subgroup(struct bgp_dest *dest,
 
        bgp_adv_fifo_add_tail(&subgrp->sync->update, adv);
 
-       subgrp->version = max(subgrp->version, dest->version);
+       subgrp->version = MAX(subgrp->version, dest->version);
 }
 
 /* The only time 'withdraw' will be false is if we are sending
@@ -609,7 +609,7 @@ void bgp_adj_out_unset_subgroup(struct bgp_dest *dest,
                }
        }
 
-       subgrp->version = max(subgrp->version, dest->version);
+       subgrp->version = MAX(subgrp->version, dest->version);
 }
 
 void bgp_adj_out_remove_subgroup(struct bgp_dest *dest, struct bgp_adj_out *adj,
@@ -721,7 +721,7 @@ void subgroup_announce_table(struct update_subgroup *subgrp,
         * covers the pathological case where all routes in the table have
         * now been deleted.
         */
-       subgrp->version = max(subgrp->version, table->version);
+       subgrp->version = MAX(subgrp->version, table->version);
 
        /*
         * Start a task to merge the subgroup if necessary.
index e60acecfaee5570100f0655a3a464655576c7287..29775bccceffccfe19a57f595e79b68f190a0bfe 100644 (file)
@@ -81,13 +81,6 @@ typedef uint32_t as_t;
 typedef uint16_t as16_t; /* we may still encounter 16 Bit asnums */
 typedef uint16_t bgp_size_t;
 
-#define max(a, b)                                                              \
-       ({                                                                     \
-               __typeof__(a) _a = (a);                                        \
-               __typeof__(b) _b = (b);                                        \
-               _a > _b ? _a : _b;                                             \
-       })
-
 enum bgp_af_index {
        BGP_AF_START,
        BGP_AF_IPV4_UNICAST = BGP_AF_START,
index 5aa14ed067f9b0d1a0e8009e59651767f5265ade..629fe46e70731b5480004995fbe52096d399a780 100644 (file)
@@ -415,13 +415,13 @@ recv_hello(struct in_addr lsr_id, struct ldp_msg *msg, int af,
                if (holdtime == 0)
                        holdtime = LINK_DFLT_HOLDTIME;
 
-               adj->holdtime = min(if_get_hello_holdtime(ia), holdtime);
+               adj->holdtime = MIN(if_get_hello_holdtime(ia), holdtime);
                break;
        case HELLO_TARGETED:
                if (holdtime == 0)
                        holdtime = TARGETED_DFLT_HOLDTIME;
 
-               adj->holdtime = min(tnbr_get_hello_holdtime(tnbr), holdtime);
+               adj->holdtime = MIN(tnbr_get_hello_holdtime(tnbr), holdtime);
        }
        if (adj->holdtime != INFINITE_HOLDTIME)
                adj_start_itimer(adj);
index d394fb08ead83c3f1e49ab4dd5c08e5773299c83..0ee64c16fa745958cfab9a6a1686e4d818de76ae 100644 (file)
@@ -197,7 +197,7 @@ recv_init(struct nbr *nbr, char *buf, uint16_t len)
                len -= tlv_len;
        }
 
-       nbr->keepalive = min(nbr_get_keepalive(nbr->af, nbr->id),
+       nbr->keepalive = MIN(nbr_get_keepalive(nbr->af, nbr->id),
            ntohs(sess.keepalive_time));
 
        max_pdu_len = ntohs(sess.max_pdu_len);
@@ -208,7 +208,7 @@ recv_init(struct nbr *nbr, char *buf, uint16_t len)
         */
        if (max_pdu_len <= 255)
                max_pdu_len = LDP_MAX_LEN;
-       nbr->max_pdu_len = min(max_pdu_len, LDP_MAX_LEN);
+       nbr->max_pdu_len = MIN(max_pdu_len, LDP_MAX_LEN);
 
        nbr_fsm(nbr, NBR_EVT_INIT_RCVD);
 
index 880722424e33d3771f8df25ca4610ffa33b07952..0f650a86d335f330b614b0ff70ec5a18d9a3c287 100644 (file)
@@ -30,9 +30,6 @@
 #include "ldpd.h"
 #include "lib/ldp_sync.h"
 
-#define min(x,y) ((x) <= (y) ? (x) : (y))
-#define max(x,y) ((x) > (y) ? (x) : (y))
-
 /* forward declarations */
 TAILQ_HEAD(mapping_head, mapping_entry);
 
index 23d3f38b31df3c7591c754b85dbd49c0f5a311e9..8d8b3c950c07ca86889ce7186f7c45d837a9b77c 100644 (file)
 
 #include "smux.h"
 
-#define min(A,B) ((A) < (B) ? (A) : (B))
-
 int oid_compare(const oid *o1, int o1_len, const oid *o2, int o2_len)
 {
        int i;
 
-       for (i = 0; i < min(o1_len, o2_len); i++) {
+       for (i = 0; i < MIN(o1_len, o2_len); i++) {
                if (o1[i] < o2[i])
                        return -1;
                else if (o1[i] > o2[i])
index 449c40c16c23fad50f19b5dba189067e2abf3efb..162c53590f9c14dfac207c7ba70e610d435f5bf7 100644 (file)
 
 #define MAX_RECONNECT_DELAY 120
 
-#define min(a, b)                                                              \
-       ({                                                                     \
-               __typeof__(a) _a = (a);                                        \
-               __typeof__(b) _b = (b);                                        \
-               _a <= _b ? _a : _b;                                            \
-       })
-
-
 /* Event handling data structures */
 enum pcep_ctrl_event_type {
        EV_UPDATE_PCC_OPTS = 1,
@@ -1078,7 +1070,7 @@ void remove_pcc_state(struct ctrl_state *ctrl_state,
 
 uint32_t backoff_delay(uint32_t max, uint32_t base, uint32_t retry_count)
 {
-       uint32_t a = min(max, base * (1 << retry_count));
+       uint32_t a = MIN(max, base * (1 << retry_count));
        uint64_t r = frr_weak_random(), m = RAND_MAX;
        uint32_t b = (a / 2) + (r * (a / 2)) / m;
        return b;
index f5af8d11408596d7b394e63304d683e46fd2a9a3..10b7ca4198b32e88ddf868f5a5af2e48a0b3d05d 100644 (file)
@@ -58,7 +58,8 @@
  * fragmentation */
 #define PIM_MSDP_SA_MAX_ENTRY_CNT 120
 
-#define PIM_MSDP_MAX_PACKET_SIZE max(PIM_MSDP_SA_TLV_MAX_SIZE, PIM_MSDP_KA_TLV_MAX_SIZE)
+#define PIM_MSDP_MAX_PACKET_SIZE                                               \
+       MAX(PIM_MSDP_SA_TLV_MAX_SIZE, PIM_MSDP_KA_TLV_MAX_SIZE)
 
 #define PIM_MSDP_PKT_TYPE_STRLEN 16
 
index 4cb860a6b7a95be4d1463a7bca6f4ab0618b4e60..675c0ebc6bec74384eee9c6a6ab745e78b2500d5 100644 (file)
@@ -85,8 +85,6 @@
 #define PIM_INADDR_IS_ANY(addr) (addr).s_addr == PIM_NET_INADDR_ANY
 #define PIM_INADDR_ISNOT_ANY(addr) ((addr).s_addr != PIM_NET_INADDR_ANY) /* struct in_addr addr */
 
-#define max(x,y) ((x) > (y) ? (x) : (y))
-
 #define PIM_MASK_PIM_EVENTS          (1 << 0)
 #define PIM_MASK_PIM_EVENTS_DETAIL   (1 << 1)
 #define PIM_MASK_PIM_PACKETS         (1 << 2)
index 3e9fa90938c917e82543dc322a3b4f25b3f318de..50972feffc9d5157ef69f22053df9a85de8b6a35 100644 (file)
@@ -43,8 +43,6 @@ DEFINE_MTYPE_STATIC(RIPNGD, RIPNG_RTE_DATA, "RIPng rte data");
 
 #define DEBUG 1
 
-#define min(a, b) ((a) < (b) ? (a) : (b))
-
 struct ripng_rte_data {
        struct prefix_ipv6 *p;
        struct ripng_info *rinfo;
@@ -151,7 +149,7 @@ void ripng_rte_send(struct list *ripng_rte_list, struct interface *ifp,
        if (mtu < 0)
                mtu = IFMINMTU;
 
-       rtemax = (min(mtu, RIPNG_MAX_PACKET_SIZE) - IPV6_HDRLEN
+       rtemax = (MIN(mtu, RIPNG_MAX_PACKET_SIZE) - IPV6_HDRLEN
                  - sizeof(struct udphdr) - sizeof(struct ripng_packet)
                  + sizeof(struct rte))
                 / sizeof(struct rte);