diff --git a/bfdd/bfdd_nb_config.c b/bfdd/bfdd_nb_config.c index 50f953115c..48dcce3ddf 100644 --- a/bfdd/bfdd_nb_config.c +++ b/bfdd/bfdd_nb_config.c @@ -383,7 +383,7 @@ int bfdd_bfd_sessions_single_hop_administrative_down_modify( bs = nb_running_get_entry(dnode, NULL, true); - if (shutdown == false) { + if (!shutdown) { if (!BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN)) return NB_OK; @@ -447,7 +447,7 @@ int bfdd_bfd_sessions_single_hop_echo_mode_modify(enum nb_event event, bs = nb_running_get_entry(dnode, NULL, true); - if (echo == false) { + if (!echo) { if (!BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO)) return NB_OK; diff --git a/bfdd/bfdd_vty.c b/bfdd/bfdd_vty.c index 3b795748c0..2a98b0fb02 100644 --- a/bfdd/bfdd_vty.c +++ b/bfdd/bfdd_vty.c @@ -500,7 +500,7 @@ static void _display_peers_brief(struct vty *vty, const char *vrfname, bool use_ bvt.vrfname = vrfname; - if (use_json == false) { + if (!use_json) { bvt.vty = vty; vty_out(vty, "Session count: %lu\n", bfd_get_session_count()); diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 1cd0bbe578..996746bf82 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -299,7 +299,7 @@ static int bgp_node_set_defer_flag(struct bgp_node *rn, bool delete) { struct peer *peer; struct bgp_path_info *old_pi, *nextpi; - bool set_flag = 0; + bool set_flag = false; struct bgp *bgp = NULL; struct bgp_table *table = NULL; afi_t afi = 0; @@ -339,7 +339,7 @@ static int bgp_node_set_defer_flag(struct bgp_node *rn, bool delete) */ if (CHECK_FLAG(old_pi->flags, BGP_PATH_STALE) && (old_pi->sub_type == BGP_ROUTE_NORMAL)) { - set_flag = 1; + set_flag = true; } else { /* If the peer is graceful restart capable and peer is * restarting mode, set the flag BGP_NODE_SELECT_DEFER @@ -349,7 +349,7 @@ static int bgp_node_set_defer_flag(struct bgp_node *rn, bool delete) && BGP_PEER_RESTARTING_MODE(peer) && (old_pi && old_pi->sub_type == BGP_ROUTE_NORMAL)) { - set_flag = 1; + set_flag = true; } } if (set_flag) diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 28e22b685d..29d3b3878a 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -9440,7 +9440,7 @@ static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty, bool use_json, json_object *json) { - bool rbit_status = 0; + bool rbit_status = false; if (!use_json) vty_out(vty, "\n R bit: "); @@ -9450,9 +9450,9 @@ static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty, && (p->status == Established)) { if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV)) - rbit_status = 1; + rbit_status = true; else - rbit_status = 0; + rbit_status = false; } if (rbit_status) { diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index 96b307ee21..f28e557572 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -3148,7 +3148,7 @@ int bgp_handle_socket(struct bgp *bgp, struct vrf *vrf, vrf_id_t old_vrf_id, /* * suppress vrf socket */ - if (create == false) { + if (!create) { bgp_close_vrf_socket(bgp); return 0; } diff --git a/lib/frr_zmq.c b/lib/frr_zmq.c index 7781beae5e..565936a410 100644 --- a/lib/frr_zmq.c +++ b/lib/frr_zmq.c @@ -177,7 +177,7 @@ int funcname_frrzmq_thread_add_read(struct thread_master *master, else { cb = XCALLOC(MTYPE_ZEROMQ_CB, sizeof(struct frrzmq_cb)); - cb->write.cancelled = 1; + cb->write.cancelled = true; *cbp = cb; } @@ -187,7 +187,7 @@ int funcname_frrzmq_thread_add_read(struct thread_master *master, cb->read.cb_msg = msgfunc; cb->read.cb_part = partfunc; cb->read.cb_error = errfunc; - cb->read.cancelled = 0; + cb->read.cancelled = false; if (events & ZMQ_POLLIN) { if (cb->read.thread) { @@ -285,7 +285,7 @@ int funcname_frrzmq_thread_add_write(struct thread_master *master, else { cb = XCALLOC(MTYPE_ZEROMQ_CB, sizeof(struct frrzmq_cb)); - cb->read.cancelled = 1; + cb->read.cancelled = true; *cbp = cb; } @@ -295,7 +295,7 @@ int funcname_frrzmq_thread_add_write(struct thread_master *master, cb->write.cb_msg = msgfunc; cb->write.cb_part = NULL; cb->write.cb_error = errfunc; - cb->write.cancelled = 0; + cb->write.cancelled = false; if (events & ZMQ_POLLOUT) { if (cb->write.thread) { @@ -316,7 +316,7 @@ void frrzmq_thread_cancel(struct frrzmq_cb **cb, struct cb_core *core) { if (!cb || !*cb) return; - core->cancelled = 1; + core->cancelled = true; if (core->thread) { thread_cancel(core->thread); core->thread = NULL; diff --git a/lib/libfrr.c b/lib/libfrr.c index 4fb43edff2..3622890e46 100644 --- a/lib/libfrr.c +++ b/lib/libfrr.c @@ -383,7 +383,7 @@ static int frr_opt(int opt) exit(0); break; case 'd': - di->daemon_mode = 1; + di->daemon_mode = true; break; case 'M': oc = XMALLOC(MTYPE_TMP, sizeof(*oc)); @@ -467,12 +467,12 @@ static int frr_opt(int opt) case 'C': if (di->flags & FRR_NO_CFG_PID_DRY) return 1; - di->dryrun = 1; + di->dryrun = true; break; case 't': if (di->flags & FRR_NO_CFG_PID_DRY) return 1; - di->terminal = 1; + di->terminal = true; break; case 'z': di->zpathspace = true; diff --git a/lib/module.c b/lib/module.c index 098c550684..14d5cfd44f 100644 --- a/lib/module.c +++ b/lib/module.c @@ -58,7 +58,7 @@ static const char *execname = NULL; void frrmod_init(struct frrmod_runtime *modinfo) { - modinfo->finished_loading = 1; + modinfo->finished_loading = true; *frrmod_last = modinfo; frrmod_last = &modinfo->next; @@ -134,7 +134,7 @@ struct frrmod_runtime *frrmod_load(const char *spec, const char *dir, char *err, goto out_fail; } - rtinfo->finished_loading = 1; + rtinfo->finished_loading = true; *frrmod_last = rtinfo; frrmod_last = &rtinfo->next; diff --git a/lib/northbound.c b/lib/northbound.c index 206a88d980..cebedcff09 100644 --- a/lib/northbound.c +++ b/lib/northbound.c @@ -996,7 +996,7 @@ static int nb_transaction_process(enum nb_event event, * Only try to release resources that were allocated * successfully. */ - if (event == NB_EV_ABORT && change->prepare_ok == false) + if (event == NB_EV_ABORT && !change->prepare_ok) break; /* Call the appropriate callback. */ diff --git a/lib/plist.c b/lib/plist.c index e465963f21..40131aebed 100644 --- a/lib/plist.c +++ b/lib/plist.c @@ -2039,7 +2039,7 @@ static void prefix_list_reset_afi(afi_t afi, int orf) assert(master->str.head == NULL); assert(master->str.tail == NULL); - master->seqnum = 1; + master->seqnum = true; master->recent = NULL; } diff --git a/lib/routemap.c b/lib/routemap.c index 64677e8863..f3860924dd 100644 --- a/lib/routemap.c +++ b/lib/routemap.c @@ -2447,7 +2447,7 @@ route_map_result_t route_map_apply(struct route_map *map, } for (; index; index = index->next) { - if (skip_match_clause == false) { + if (!skip_match_clause) { /* Apply this index. */ match_ret = route_map_apply_match(&index->match_list, prefix, type, object); diff --git a/lib/seqlock.c b/lib/seqlock.c index c05ec19db4..588a1175bc 100644 --- a/lib/seqlock.c +++ b/lib/seqlock.c @@ -254,7 +254,7 @@ bool seqlock_check(struct seqlock *sqlo, seqlock_val_t val) cur = atomic_load_explicit(&sqlo->pos, memory_order_relaxed); if (!(cur & SEQLOCK_HELD)) - return 1; + return true; cur = SEQLOCK_VAL(cur) - val - 1; assert(cur < 0x40000000 || cur > 0xc0000000); return cur < 0x80000000; diff --git a/pbrd/pbr_map.c b/pbrd/pbr_map.c index 37b6be6949..fd77a07fb8 100644 --- a/pbrd/pbr_map.c +++ b/pbrd/pbr_map.c @@ -202,7 +202,7 @@ void pbr_map_reason_string(unsigned int reason, char *buf, int size) void pbr_map_final_interface_deletion(struct pbr_map *pbrm, struct pbr_map_interface *pmi) { - if (pmi->delete == true && !pbr_map_interface_is_installed(pbrm, pmi)) { + if (pmi->delete && !pbr_map_interface_is_installed(pbrm, pmi)) { listnode_delete(pbrm->incoming, pmi); pmi->pbrm = NULL; diff --git a/pimd/pim_nht.c b/pimd/pim_nht.c index 518664f7fb..dd94918b69 100644 --- a/pimd/pim_nht.c +++ b/pimd/pim_nht.c @@ -255,7 +255,7 @@ bool pim_nexthop_match(struct pim_instance *pim, struct in_addr addr, int num_ifindex; if (addr.s_addr == INADDR_NONE) - return 0; + return false; memset(nexthop_tab, 0, sizeof(struct pim_zlookup_nexthop) * MULTIPATH_NUM); @@ -268,7 +268,7 @@ bool pim_nexthop_match(struct pim_instance *pim, struct in_addr addr, zlog_warn( "%s %s: could not find nexthop ifindex for address %s", __FILE__, __PRETTY_FUNCTION__, addr_str); - return 0; + return false; } while (i < num_ifindex) { @@ -319,12 +319,12 @@ bool pim_nexthop_match(struct pim_instance *pim, struct in_addr addr, if (nexthop_tab[i].nexthop_addr.u.prefix4.s_addr == ip_src.s_addr) - return 1; + return true; i++; } - return 0; + return false; } /* Given a source address and a neighbor address, check if the neighbor is one @@ -348,7 +348,7 @@ bool pim_nexthop_match_nht_cache(struct pim_instance *pim, struct in_addr addr, pnc = pim_nexthop_cache_find(pim, &rpf); if (!pnc || !pnc->nexthop_num) - return 0; + return false; for (nh_node = pnc->nexthop; nh_node; nh_node = nh_node->next) { first_ifindex = nh_node->ifindex; @@ -398,10 +398,10 @@ bool pim_nexthop_match_nht_cache(struct pim_instance *pim, struct in_addr addr, } if (nh_node->gate.ipv4.s_addr == ip_src.s_addr) - return 1; + return true; } - return 0; + return false; } void pim_rp_nexthop_del(struct rp_info *rp_info) diff --git a/pimd/pim_upstream.c b/pimd/pim_upstream.c index 444ab938f2..940b5a33ce 100644 --- a/pimd/pim_upstream.c +++ b/pimd/pim_upstream.c @@ -1151,7 +1151,7 @@ static inline bool pim_upstream_is_msdp_peer_sa(struct pim_upstream *up) * AND inherited_olist(S,G) != NULL ) ) * } */ -int pim_upstream_evaluate_join_desired(struct pim_instance *pim, +bool pim_upstream_evaluate_join_desired(struct pim_instance *pim, struct pim_upstream *up) { bool empty_imm_oil; diff --git a/pimd/pim_upstream.h b/pimd/pim_upstream.h index c717c467dc..4d693b8b64 100644 --- a/pimd/pim_upstream.h +++ b/pimd/pim_upstream.h @@ -303,8 +303,8 @@ struct pim_upstream *pim_upstream_del(struct pim_instance *pim, struct pim_upstream *up, const char *name); -int pim_upstream_evaluate_join_desired(struct pim_instance *pim, - struct pim_upstream *up); +bool pim_upstream_evaluate_join_desired(struct pim_instance *pim, + struct pim_upstream *up); int pim_upstream_evaluate_join_desired_interface(struct pim_upstream *up, struct pim_ifchannel *ch, struct pim_ifchannel *starch); diff --git a/scripts/coccinelle/bool_assignment.cocci b/scripts/coccinelle/bool_assignment.cocci new file mode 100644 index 0000000000..e6146ea310 --- /dev/null +++ b/scripts/coccinelle/bool_assignment.cocci @@ -0,0 +1,13 @@ +@@ +bool b; +@@ + +( + b = +- 0 ++ false +| + b = +- 1 ++ true +) diff --git a/scripts/coccinelle/bool_expression.cocci b/scripts/coccinelle/bool_expression.cocci new file mode 100644 index 0000000000..c0c329cb59 --- /dev/null +++ b/scripts/coccinelle/bool_expression.cocci @@ -0,0 +1,29 @@ +@@ +bool t; +@@ + +( +- t == true ++ t +| +- true == t ++ t +| +- t != true ++ !t +| +- true != t ++ !t +| +- t == false ++ !t +| +- false == t ++ !t +| +- t != false ++ t +| +- false != t ++ t +) diff --git a/scripts/coccinelle/bool_function.cocci b/scripts/coccinelle/bool_function.cocci new file mode 100644 index 0000000000..0328ecfbbe --- /dev/null +++ b/scripts/coccinelle/bool_function.cocci @@ -0,0 +1,21 @@ +@@ +identifier fn; +typedef bool; +symbol false; +symbol true; +@@ + +bool fn ( ... ) +{ +<... +return +( +- 0 ++ false +| +- 1 ++ true +) + ; +...> +} diff --git a/scripts/coccinelle/bool_function_type.cocci b/scripts/coccinelle/bool_function_type.cocci new file mode 100644 index 0000000000..71bf4f53b8 --- /dev/null +++ b/scripts/coccinelle/bool_function_type.cocci @@ -0,0 +1,19 @@ +@@ +identifier fn; +typedef bool; +symbol false; +symbol true; +@@ + +- int ++ bool +fn (...) +{ +?... +return +( + true +| + false +); +} diff --git a/vrrpd/vrrp.c b/vrrpd/vrrp.c index 03a08dd86b..da6de341e1 100644 --- a/vrrpd/vrrp.c +++ b/vrrpd/vrrp.c @@ -953,7 +953,7 @@ static int vrrp_recv_advertisement(struct vrrp_router *r, struct ipaddr *src, thread_add_timer_msec( master, vrrp_master_down_timer_expire, r, r->skew_time * CS2MS, &r->t_master_down_timer); - } else if (r->vr->preempt_mode == false + } else if (!r->vr->preempt_mode || pkt->hdr.priority >= r->priority) { if (r->vr->version == 3) { r->master_adver_interval = @@ -965,7 +965,7 @@ static int vrrp_recv_advertisement(struct vrrp_router *r, struct ipaddr *src, vrrp_master_down_timer_expire, r, r->master_down_interval * CS2MS, &r->t_master_down_timer); - } else if (r->vr->preempt_mode == true + } else if (r->vr->preempt_mode && pkt->hdr.priority < r->priority) { /* Discard advertisement */ DEBUGD(&vrrp_dbg_proto, @@ -1834,7 +1834,7 @@ static int vrrp_autoconfig_if_add(struct interface *ifp) created = true; } - if (!vr || vr->autoconf == false) + if (!vr || !vr->autoconf) return 0; if (!created) { @@ -2347,11 +2347,11 @@ static bool vrrp_hash_cmp(const void *arg1, const void *arg2) const struct vrrp_vrouter *vr2 = arg2; if (vr1->ifp != vr2->ifp) - return 0; + return false; if (vr1->vrid != vr2->vrid) - return 0; + return false; - return 1; + return true; } void vrrp_init(void) diff --git a/zebra/zebra_mlag.c b/zebra/zebra_mlag.c index fc7804a409..5b721a8eac 100644 --- a/zebra/zebra_mlag.c +++ b/zebra/zebra_mlag.c @@ -605,7 +605,7 @@ int32_t zebra_mlag_test_mlag_internal(const char *none, const char *primary, zsend_capabilities_all_clients(); if (zrouter.mlag_info.role != MLAG_ROLE_NONE) { if (zrouter.mlag_info.clients_interested_cnt == 0 - && test_mlag_in_progress == false) { + && !test_mlag_in_progress) { if (zrouter.mlag_info.zebra_pth_mlag == NULL) zebra_mlag_spawn_pthread(); zrouter.mlag_info.clients_interested_cnt++; @@ -613,7 +613,7 @@ int32_t zebra_mlag_test_mlag_internal(const char *none, const char *primary, hook_call(zebra_mlag_private_open_channel); } } else { - if (test_mlag_in_progress == true) { + if (test_mlag_in_progress) { test_mlag_in_progress = false; zrouter.mlag_info.clients_interested_cnt--; hook_call(zebra_mlag_private_close_channel); @@ -790,7 +790,7 @@ int zebra_mlag_protobuf_encode_client_data(struct stream *s, uint32_t *msg_type) vrf_name_len); } } - if (cleanup == false) { + if (!cleanup) { Bulk_msg.mroute_add = pay_load; len = zebra_mlag_mroute_add_bulk__pack(&Bulk_msg, tmp_buf); @@ -804,7 +804,7 @@ int zebra_mlag_protobuf_encode_client_data(struct stream *s, uint32_t *msg_type) XFREE(MTYPE_MLAG_PBUF, pay_load[i]); } XFREE(MTYPE_MLAG_PBUF, pay_load); - if (cleanup == true) + if (cleanup) return -1; } break; case MLAG_MROUTE_DEL_BULK: {