From 3967f0a857d776926c1dc6fd217747cf4d099bdc Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Wed, 11 Mar 2020 17:09:11 +0200 Subject: [PATCH] bgpd: Convert type int functions to bool which return 0/1 only This is only for bgp_aspath.[ch] Signed-off-by: Donatas Abraitis --- bgpd/bgp_aspath.c | 58 +++++++++++++++++++++++------------------------ bgpd/bgp_aspath.h | 14 ++++++------ 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/bgpd/bgp_aspath.c b/bgpd/bgp_aspath.c index f73d6e3009..599c9eb8f5 100644 --- a/bgpd/bgp_aspath.c +++ b/bgpd/bgp_aspath.c @@ -477,7 +477,7 @@ as_t aspath_leftmost(struct aspath *aspath) } /* Return 1 if there are any 4-byte ASes in the path */ -unsigned int aspath_has_as4(struct aspath *aspath) +bool aspath_has_as4(struct aspath *aspath) { struct assegment *seg = aspath->segments; unsigned int i; @@ -485,10 +485,10 @@ unsigned int aspath_has_as4(struct aspath *aspath) while (seg) { for (i = 0; i < seg->length; i++) if (seg->as[i] > BGP_AS_MAX) - return 1; + return true; seg = seg->next; } - return 0; + return false; } /* Convert aspath structure to string expression. */ @@ -1114,16 +1114,16 @@ struct aspath *aspath_aggregate(struct aspath *as1, struct aspath *as2) /* When a BGP router receives an UPDATE with an MP_REACH_NLRI attribute, check the leftmost AS number in the AS_PATH attribute is or not the peer's AS number. */ -int aspath_firstas_check(struct aspath *aspath, as_t asno) +bool aspath_firstas_check(struct aspath *aspath, as_t asno) { if ((aspath == NULL) || (aspath->segments == NULL)) - return 0; + return false; if (aspath->segments && (aspath->segments->type == AS_SEQUENCE) && (aspath->segments->as[0] == asno)) - return 1; + return true; - return 0; + return false; } unsigned int aspath_get_first_as(struct aspath *aspath) @@ -1179,12 +1179,12 @@ int aspath_loop_check(struct aspath *aspath, as_t asno) } /* When all of AS path is private AS return 1. */ -int aspath_private_as_check(struct aspath *aspath) +bool aspath_private_as_check(struct aspath *aspath) { struct assegment *seg; if (!(aspath && aspath->segments)) - return 0; + return false; seg = aspath->segments; @@ -1193,20 +1193,20 @@ int aspath_private_as_check(struct aspath *aspath) for (i = 0; i < seg->length; i++) { if (!BGP_AS_IS_PRIVATE(seg->as[i])) - return 0; + return false; } seg = seg->next; } - return 1; + return true; } /* Return True if the entire ASPATH consist of the specified ASN */ -int aspath_single_asn_check(struct aspath *aspath, as_t asn) +bool aspath_single_asn_check(struct aspath *aspath, as_t asn) { struct assegment *seg; if (!(aspath && aspath->segments)) - return 0; + return false; seg = aspath->segments; @@ -1215,11 +1215,11 @@ int aspath_single_asn_check(struct aspath *aspath, as_t asn) for (i = 0; i < seg->length; i++) { if (seg->as[i] != asn) - return 0; + return false; } seg = seg->next; } - return 1; + return true; } /* Replace all instances of the target ASN with our own ASN */ @@ -1338,37 +1338,37 @@ struct aspath *aspath_remove_private_asns(struct aspath *aspath, as_t peer_asn) /* AS path confed check. If aspath contains confed set or sequence then return * 1. */ -int aspath_confed_check(struct aspath *aspath) +bool aspath_confed_check(struct aspath *aspath) { struct assegment *seg; if (!(aspath && aspath->segments)) - return 0; + return false; seg = aspath->segments; while (seg) { if (seg->type == AS_CONFED_SET || seg->type == AS_CONFED_SEQUENCE) - return 1; + return true; seg = seg->next; } - return 0; + return false; } /* Leftmost AS path segment confed check. If leftmost AS segment is of type AS_CONFED_SEQUENCE or AS_CONFED_SET then return 1. */ -int aspath_left_confed_check(struct aspath *aspath) +bool aspath_left_confed_check(struct aspath *aspath) { if (!(aspath && aspath->segments)) - return 0; + return false; if ((aspath->segments->type == AS_CONFED_SEQUENCE) || (aspath->segments->type == AS_CONFED_SET)) - return 1; + return true; - return 0; + return false; } /* Merge as1 to as2. as2 should be uninterned aspath. */ @@ -1605,13 +1605,13 @@ struct aspath *aspath_add_seq(struct aspath *aspath, as_t asno) /* Compare leftmost AS value for MED check. If as1's leftmost AS and as2's leftmost AS is same return 1. */ -int aspath_cmp_left(const struct aspath *aspath1, const struct aspath *aspath2) +bool aspath_cmp_left(const struct aspath *aspath1, const struct aspath *aspath2) { const struct assegment *seg1; const struct assegment *seg2; if (!(aspath1 && aspath2)) - return 0; + return false; seg1 = aspath1->segments; seg2 = aspath2->segments; @@ -1619,7 +1619,7 @@ int aspath_cmp_left(const struct aspath *aspath1, const struct aspath *aspath2) /* If both paths are originated in this AS then we do want to compare * MED */ if (!seg1 && !seg2) - return 1; + return true; /* find first non-confed segments for each */ while (seg1 && ((seg1->type == AS_CONFED_SEQUENCE) @@ -1633,12 +1633,12 @@ int aspath_cmp_left(const struct aspath *aspath1, const struct aspath *aspath2) /* Check as1's */ if (!(seg1 && seg2 && (seg1->type == AS_SEQUENCE) && (seg2->type == AS_SEQUENCE))) - return 0; + return false; if (seg1->as[0] == seg2->as[0]) - return 1; + return true; - return 0; + return false; } /* Truncate an aspath after a number of hops, and put the hops remaining diff --git a/bgpd/bgp_aspath.h b/bgpd/bgp_aspath.h index a4427714ba..f327751f33 100644 --- a/bgpd/bgp_aspath.h +++ b/bgpd/bgp_aspath.h @@ -87,7 +87,7 @@ extern struct aspath *aspath_add_seq_n(struct aspath *, as_t, unsigned); extern struct aspath *aspath_add_seq(struct aspath *, as_t); extern struct aspath *aspath_add_confed_seq(struct aspath *, as_t); extern bool aspath_cmp(const void *as1, const void *as2); -extern int aspath_cmp_left(const struct aspath *, const struct aspath *); +extern bool aspath_cmp_left(const struct aspath *, const struct aspath *); extern bool aspath_cmp_left_confed(const struct aspath *as1, const struct aspath *as2xs); extern struct aspath *aspath_delete_confed_seq(struct aspath *); @@ -106,8 +106,8 @@ extern unsigned int aspath_key_make(const void *); extern unsigned int aspath_get_first_as(struct aspath *); extern unsigned int aspath_get_last_as(struct aspath *); extern int aspath_loop_check(struct aspath *, as_t); -extern int aspath_private_as_check(struct aspath *); -extern int aspath_single_asn_check(struct aspath *, as_t asn); +extern bool aspath_private_as_check(struct aspath *); +extern bool aspath_single_asn_check(struct aspath *, as_t asn); extern struct aspath *aspath_replace_specific_asn(struct aspath *aspath, as_t target_asn, as_t our_asn); @@ -115,9 +115,9 @@ extern struct aspath *aspath_replace_private_asns(struct aspath *aspath, as_t asn, as_t peer_asn); extern struct aspath *aspath_remove_private_asns(struct aspath *aspath, as_t peer_asn); -extern int aspath_firstas_check(struct aspath *, as_t); -extern int aspath_confed_check(struct aspath *); -extern int aspath_left_confed_check(struct aspath *); +extern bool aspath_firstas_check(struct aspath *, as_t); +extern bool aspath_confed_check(struct aspath *); +extern bool aspath_left_confed_check(struct aspath *); extern unsigned long aspath_count(void); extern unsigned int aspath_count_hops(const struct aspath *); extern bool aspath_check_as_sets(struct aspath *aspath); @@ -128,7 +128,7 @@ extern as_t aspath_leftmost(struct aspath *); extern size_t aspath_put(struct stream *, struct aspath *, int); extern struct aspath *aspath_reconcile_as4(struct aspath *, struct aspath *); -extern unsigned int aspath_has_as4(struct aspath *); +extern bool aspath_has_as4(struct aspath *); /* For SNMP BGP4PATHATTRASPATHSEGMENT, might be useful for debug */ extern uint8_t *aspath_snmp_pathseg(struct aspath *, size_t *); -- 2.39.5