From 82bd85e185a44faeb102118321997f5fcad8c9b0 Mon Sep 17 00:00:00 2001 From: Andreas Tonnesen Date: Wed, 3 Nov 2004 10:00:11 +0000 Subject: [PATCH] Added usage of olsr_bool for boolean use --- src/build_msg.c | 44 ++++++++++++++++++++++---------------------- src/defs.h | 14 +++++++------- src/linux/tunnel.c | 6 +++--- src/main.c | 28 ++++++++++++++-------------- src/mpr.c | 12 ++++++------ src/neighbor_table.c | 6 +++--- src/neighbor_table.h | 6 +++--- src/packet.c | 33 ++++++++++++++------------------- 8 files changed, 72 insertions(+), 77 deletions(-) diff --git a/src/build_msg.c b/src/build_msg.c index 2be05fcc..68a64a6e 100644 --- a/src/build_msg.c +++ b/src/build_msg.c @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * - * $Id: build_msg.c,v 1.18 2004/11/01 19:27:10 tlopatic Exp $ + * $Id: build_msg.c,v 1.19 2004/11/03 10:00:10 kattemat Exp $ * */ @@ -691,7 +691,7 @@ tc_build4(struct tc_message *message, struct interface *ifp) union olsr_message *m; struct tcmsg *tc; struct neigh_info *mprsaddr; - int found = 0, partial_sent = 0; + olsr_bool found = FALSE, partial_sent = FALSE; if((!message) || (!ifp) || (olsr_cnf->ip_version != AF_INET)) return; @@ -745,15 +745,15 @@ tc_build4(struct tc_message *message, struct interface *ifp) mprsaddr = tc->neigh; curr_size = 12; /* OLSR message header */ curr_size += 4; /* TC header */ - found = 0; - partial_sent = 1; + found = FALSE; + partial_sent = TRUE; } net_output(ifp); remainsize = net_outbuffer_bytes_left(ifp); } - found = 1; + found = TRUE; COPY_IP(&mprsaddr->addr, &mprs->address); @@ -823,7 +823,7 @@ tc_build6(struct tc_message *message, struct interface *ifp) union olsr_message *m; struct tcmsg6 *tc6; struct neigh_info6 *mprsaddr6; - int found = 0, partial_sent = 0; + olsr_bool found = FALSE, partial_sent = FALSE; if ((!message) || (!ifp) || (olsr_cnf->ip_version != AF_INET6)) return; @@ -874,15 +874,15 @@ tc_build6(struct tc_message *message, struct interface *ifp) mprsaddr6 = tc6->neigh; curr_size = 24; /* OLSR message header */ curr_size += 4; /* TC header */ - found = 0; - partial_sent = 1; + found = FALSE; + partial_sent = TRUE; } net_output(ifp); remainsize = net_outbuffer_bytes_left(ifp); } - found = 1; + found = TRUE; //printf("mprsaddr6 is %x\n", (char *)mprsaddr6 - packet); //printf("Adding MPR-selector: %s\n", olsr_ip_to_string(&mprs->address));fflush(stdout); @@ -1274,7 +1274,7 @@ lq_hello_build(struct lq_hello_message *msg, struct interface *outif) struct lq_hello_info_header *info_head; struct lq_hello_neighbor *neigh; unsigned char *buff; - int is_first; + olsr_bool is_first; int i, j; if (msg == NULL || outif == NULL) @@ -1351,7 +1351,7 @@ lq_hello_build(struct lq_hello_message *msg, struct interface *outif) if(j == HIDE_LINK) continue; - is_first = 1; + is_first = TRUE; // loop through neighbors @@ -1368,7 +1368,7 @@ lq_hello_build(struct lq_hello_message *msg, struct interface *outif) // no, we also need space for an info header, as this is the // first neighbor with the current neighor type and link type - if (is_first != 0) + if (is_first) req += sizeof (struct lq_hello_info_header); // we do not have enough space left @@ -1407,12 +1407,12 @@ lq_hello_build(struct lq_hello_message *msg, struct interface *outif) // we need a new info header - is_first = 1; + is_first = TRUE; } // create a new info header - if (is_first != 0) + if (is_first) { info_head = (struct lq_hello_info_header *)(buff + size); size += sizeof (struct lq_hello_info_header); @@ -1441,13 +1441,13 @@ lq_hello_build(struct lq_hello_message *msg, struct interface *outif) buff[size++] = 0; buff[size++] = 0; - is_first = 0; + is_first = FALSE; } // finalize the info header, if there are any neighbors with the // current neighbor type and link type - if (is_first == 0) + if (!is_first) info_head->size = ntohs(buff + size - (unsigned char *)info_head); } } @@ -1483,7 +1483,7 @@ lq_tc_build(struct lq_tc_message *msg, struct interface *outif) struct lq_tc_header *head; struct lq_tc_neighbor *neigh; unsigned char *buff; - int is_empty; + olsr_bool is_empty; if (msg == NULL || outif == NULL) return; @@ -1549,7 +1549,7 @@ lq_tc_build(struct lq_tc_message *msg, struct interface *outif) // initially, we're empty - is_empty = 1; + is_empty = TRUE; // loop through neighbors @@ -1603,7 +1603,7 @@ lq_tc_build(struct lq_tc_message *msg, struct interface *outif) // we're not empty any longer - is_empty = 0; + is_empty = FALSE; } // finalize the OLSR header @@ -1623,15 +1623,15 @@ lq_tc_build(struct lq_tc_message *msg, struct interface *outif) // if we did not advertise any neighbors, we might still want to // send empty LQ_TC messages - if (is_empty != 0 && !TIMED_OUT(&send_empty_tc)) + if (is_empty && !TIMED_OUT(&send_empty_tc)) { olsr_printf(1, "LQ_TC: Sending empty package\n"); - is_empty = 0; + is_empty = FALSE; } // move the message to the output buffer - if (is_empty == 0) + if (!is_empty) net_outbuffer_push(outif, msg_buffer, size + off); // clean-up diff --git a/src/defs.h b/src/defs.h index e5cb037c..07ce1b1e 100644 --- a/src/defs.h +++ b/src/defs.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * - * $Id: defs.h,v 1.20 2004/11/03 09:22:59 kattemat Exp $ + * $Id: defs.h,v 1.21 2004/11/03 10:00:10 kattemat Exp $ * */ @@ -88,15 +88,16 @@ struct tm *nowtm; /* current idea of time (in tm) */ char ipv6_buf[100]; /* buffer for IPv6 inet_htop */ -int disp_pack_in; /* display incoming packet content? */ -int disp_pack_out; /* display outgoing packet content? */ +olsr_bool disp_pack_in; /* display incoming packet content? */ +olsr_bool disp_pack_out; /* display outgoing packet content? */ int llinfo; -int inet_tnl_added; /* If Internet gateway tunnel is added */ -int use_tunnel; /* Use Internet gateway tunneling */ -int gw_tunnel; /* Work as Internet gateway */ +olsr_bool inet_tnl_added; /* If Internet gateway tunnel is added */ +olsr_bool use_tunnel; /* Use Internet gateway tunneling */ +olsr_bool gw_tunnel; /* Work as Internet gateway */ +olsr_bool del_gws; /* * Timer values @@ -131,7 +132,6 @@ extern struct timeval hold_time_fwd; struct sockaddr_in6 null_addr6; /* Address used as Originator Address IPv6 */ -int del_gws; int minsize; diff --git a/src/linux/tunnel.c b/src/linux/tunnel.c index 4e139861..d9a9c475 100644 --- a/src/linux/tunnel.c +++ b/src/linux/tunnel.c @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * - * $Id: tunnel.c,v 1.5 2004/09/21 19:08:58 kattemat Exp $ + * $Id: tunnel.c,v 1.6 2004/11/03 10:00:11 kattemat Exp $ * */ @@ -134,7 +134,7 @@ add_ip_tunnel(struct ip_tunnel_parm *p) /* Store the gateway address */ memcpy(&tnl_addr, &p->iph.daddr, ipsize); - inet_tnl_added = 1; + inet_tnl_added = TRUE; /* Enable tunnel forwarding for gateways */ enable_tunl_forwarding(); @@ -225,7 +225,7 @@ set_up_gw_tunnel(union olsr_ip_addr *adr) printf("Setting up a GW side IP tunnel...\n"); - gw_tunnel = 1; + gw_tunnel = TRUE; memset(&ifr, 0, sizeof(struct ifreq)); diff --git a/src/main.c b/src/main.c index 9d06ab1c..5d990956 100644 --- a/src/main.c +++ b/src/main.c @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * - * $Id: main.c,v 1.24 2004/11/03 09:22:59 kattemat Exp $ + * $Id: main.c,v 1.25 2004/11/03 10:00:10 kattemat Exp $ * */ @@ -371,7 +371,7 @@ main(int argc, char *argv[]) if (strcmp(*argv, "-dispin") == 0) { argv++; argc--; - disp_pack_in = 1; + disp_pack_in = TRUE; continue; } @@ -381,7 +381,7 @@ main(int argc, char *argv[]) if (strcmp(*argv, "-dispout") == 0) { argv++; argc--; - disp_pack_out = 1; + disp_pack_out = TRUE; continue; } @@ -392,7 +392,7 @@ main(int argc, char *argv[]) if (strcmp(*argv, "-ipc") == 0) { argv++; argc--; - olsr_cnf->open_ipc = 1; + olsr_cnf->open_ipc = TRUE; continue; } @@ -403,7 +403,7 @@ main(int argc, char *argv[]) if (strcmp(*argv, "-llinfo") == 0) { argv++; argc--; - llinfo = 1; + llinfo = TRUE; continue; } @@ -413,7 +413,7 @@ main(int argc, char *argv[]) if (strcmp(*argv, "-tnl") == 0) { argv++; argc--; - use_tunnel = 1; + use_tunnel = TRUE; continue; } @@ -444,7 +444,7 @@ main(int argc, char *argv[]) if (strcmp(*argv, "-delgw") == 0) { argv++; argc--; - del_gws = 1; + del_gws = TRUE; continue; } @@ -726,16 +726,16 @@ set_default_values() #endif /* Gateway tunneling */ - use_tunnel = 0; - inet_tnl_added = 0; - gw_tunnel = 0; + use_tunnel = FALSE; + inet_tnl_added = FALSE; + gw_tunnel = FALSE; - llinfo = 0; - del_gws = 0; + llinfo = FALSE; + del_gws = FALSE; /* Display packet content */ - disp_pack_in = 0; - disp_pack_out = 0; + disp_pack_in = FALSE; + disp_pack_out = FALSE; } diff --git a/src/mpr.c b/src/mpr.c index 2542a8dd..2a345cd0 100644 --- a/src/mpr.c +++ b/src/mpr.c @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * - * $Id: mpr.c,v 1.8 2004/11/03 09:22:59 kattemat Exp $ + * $Id: mpr.c,v 1.9 2004/11/03 10:00:11 kattemat Exp $ * */ @@ -156,7 +156,7 @@ olsr_chosen_mpr(struct neighbor_entry *one_hop_neighbor, olsr_u16_t *two_hop_cov //printf("PRE COUNT: %d\n\n", count); - one_hop_neighbor->is_mpr = 1; //NBS_MPR; + one_hop_neighbor->is_mpr = TRUE; //NBS_MPR; for(second_hop_entries = one_hop_neighbor->neighbor_2_list.next; second_hop_entries != &one_hop_neighbor->neighbor_2_list; @@ -273,8 +273,8 @@ olsr_clear_mprs() /* Clear MPR selection */ if(a_neighbor->is_mpr) { - a_neighbor->was_mpr = 1; - a_neighbor->is_mpr = 0; + a_neighbor->was_mpr = TRUE; + a_neighbor->is_mpr = FALSE; } /* Clear two hop neighbors coverage count */ @@ -312,7 +312,7 @@ olsr_check_mpr_changes() { if(a_neighbor->was_mpr) { - a_neighbor->was_mpr = 0; + a_neighbor->was_mpr = FALSE; if(!a_neighbor->is_mpr) retval = 1; } @@ -589,7 +589,7 @@ olsr_optimize_mpr_set() if(remove) { olsr_printf(3, "MPR OPTIMIZE: removiong mpr %s\n\n", olsr_ip_to_string(&a_neighbor->neighbor_main_addr)); - a_neighbor->is_mpr = 0; + a_neighbor->is_mpr = FALSE; } diff --git a/src/neighbor_table.c b/src/neighbor_table.c index bf90279a..b692175d 100644 --- a/src/neighbor_table.c +++ b/src/neighbor_table.c @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * - * $Id: neighbor_table.c,v 1.8 2004/11/03 09:22:59 kattemat Exp $ + * $Id: neighbor_table.c,v 1.9 2004/11/03 10:00:11 kattemat Exp $ * */ @@ -231,8 +231,8 @@ olsr_insert_neighbor_table(union olsr_ip_addr *main_addr) new_neigh->neighbor_2_list.prev = &new_neigh->neighbor_2_list; new_neigh->linkcount = 0; - new_neigh->is_mpr = 0; - new_neigh->was_mpr = 0; + new_neigh->is_mpr = FALSE; + new_neigh->was_mpr = FALSE; /* Queue */ QUEUE_ELEM(neighbortable[hash], new_neigh); diff --git a/src/neighbor_table.h b/src/neighbor_table.h index 57e1152d..80e4e066 100644 --- a/src/neighbor_table.h +++ b/src/neighbor_table.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * - * $Id: neighbor_table.h,v 1.6 2004/10/09 22:32:47 kattemat Exp $ + * $Id: neighbor_table.h,v 1.7 2004/11/03 10:00:11 kattemat Exp $ * */ @@ -46,8 +46,8 @@ struct neighbor_entry union olsr_ip_addr neighbor_main_addr; olsr_u8_t status; olsr_u8_t willingness; - olsr_u8_t is_mpr; - olsr_u8_t was_mpr; /* Used to detect changes in MPR */ + olsr_bool is_mpr; + olsr_bool was_mpr; /* Used to detect changes in MPR */ int neighbor_2_nocov; int linkcount; struct neighbor_2_list_entry neighbor_2_list; diff --git a/src/packet.c b/src/packet.c index a18c6232..bf545c96 100644 --- a/src/packet.c +++ b/src/packet.c @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * - * $Id: packet.c,v 1.9 2004/11/02 22:55:42 tlopatic Exp $ + * $Id: packet.c,v 1.10 2004/11/03 10:00:11 kattemat Exp $ * */ @@ -31,7 +31,7 @@ #include "olsr.h" -static int sending_tc = 0; +static olsr_bool sending_tc = FALSE; /** *Build an internal HELLO package for this @@ -49,7 +49,7 @@ olsr_build_hello_packet(struct hello_message *message, struct interface *outif) struct link_entry *links; struct neighbor_entry *neighbor; olsr_u16_t index; - int found, link; + int link; olsr_printf(3, "\tBuilding HELLO on interface %d\n", outif->if_nr); @@ -188,8 +188,7 @@ olsr_build_hello_packet(struct hello_message *message, struct interface *outif) for(neighbor = neighbortable[index].next; neighbor != &neighbortable[index]; neighbor=neighbor->next) - { - found = 0; + { /* Check that the neighbor is not added yet */ tmp_neigh = message->neighbors; //printf("Checking that the neighbor is not yet added\n"); @@ -198,13 +197,12 @@ olsr_build_hello_packet(struct hello_message *message, struct interface *outif) if(COMP_IP(&tmp_neigh->main_address, &neighbor->neighbor_main_addr)) { //printf("Not adding duplicate neighbor %s\n", olsr_ip_to_string(&neighbor->neighbor_main_addr)); - found = 1; break; } tmp_neigh = tmp_neigh->next; } - if(found) + if(tmp_neigh) continue; message_neighbor = olsr_malloc(sizeof(struct hello_neighbor), "Build HELLO 2"); @@ -292,12 +290,9 @@ olsr_build_tc_packet(struct tc_message *message) struct neighbor_entry *entry; //struct mpr_selector_hash *mprs_hash; //olsr_u16_t index; - int entry_added; + olsr_bool entry_added = FALSE; struct timeval tmp_timer; - - entry_added = 0; - message->multipoint_relay_selector_address=NULL; message->packet_seq_number=0; @@ -330,14 +325,14 @@ olsr_build_tc_packet(struct tc_message *message) COPY_IP(&message_mpr->address, &entry->neighbor_main_addr); message_mpr->next = message->multipoint_relay_selector_address; message->multipoint_relay_selector_address = message_mpr; - entry_added = 1; + entry_added = TRUE; break; } case(1): { /* 1 = Add all MPR selectors and selected MPRs */ - if((entry->is_mpr == 1) || + if((entry->is_mpr) || (olsr_lookup_mprs_set(&entry->neighbor_main_addr) != NULL)) { //printf("\t%s\n", olsr_ip_to_string(&mprs->mpr_selector_addr)); @@ -346,7 +341,7 @@ olsr_build_tc_packet(struct tc_message *message) COPY_IP(&message_mpr->address, &entry->neighbor_main_addr); message_mpr->next = message->multipoint_relay_selector_address; message->multipoint_relay_selector_address = message_mpr; - entry_added = 1; + entry_added = TRUE; } break; } @@ -361,7 +356,7 @@ olsr_build_tc_packet(struct tc_message *message) COPY_IP(&message_mpr->address, &entry->neighbor_main_addr); message_mpr->next = message->multipoint_relay_selector_address; message->multipoint_relay_selector_address = message_mpr; - entry_added = 1; + entry_added = TRUE; } break; } @@ -372,7 +367,7 @@ olsr_build_tc_packet(struct tc_message *message) if(entry_added) { - sending_tc = 1; + sending_tc = TRUE; } else { @@ -383,7 +378,7 @@ olsr_build_tc_packet(struct tc_message *message) olsr_printf(3, "No more MPR selectors - will send empty TCs\n"); timeradd(&now, &tmp_timer, &send_empty_tc); - sending_tc = 0; + sending_tc = FALSE; } } @@ -603,7 +598,7 @@ olsr_build_lq_tc_packet(struct lq_tc_message *msg) } if (msg->neigh != NULL) - sending_tc = 1; + sending_tc = TRUE; else if (sending_tc) { @@ -612,7 +607,7 @@ olsr_build_lq_tc_packet(struct lq_tc_message *msg) olsr_printf(3, "No more MPR selectors - will send empty LQ_TCs\n"); - sending_tc = 0; + sending_tc = FALSE; } return 0; -- 2.20.1