summaryrefslogtreecommitdiffstats
path: root/babeld
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-08-05 09:56:24 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-08-05 09:56:24 +0000
commit54de8bbe36d7d968c6367939277942518bd4e11f (patch)
tree924f8c16d9c8831679f355b88c620b9b356c9d5a /babeld
parentAdding debian version 10.0.1-0.1. (diff)
downloadfrr-54de8bbe36d7d968c6367939277942518bd4e11f.tar.xz
frr-54de8bbe36d7d968c6367939277942518bd4e11f.zip
Merging upstream version 10.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'babeld')
-rw-r--r--babeld/message.c136
-rw-r--r--babeld/neighbour.c67
2 files changed, 83 insertions, 120 deletions
diff --git a/babeld/message.c b/babeld/message.c
index f854932..1b83eb9 100644
--- a/babeld/message.c
+++ b/babeld/message.c
@@ -139,7 +139,7 @@ static bool parse_update_subtlv(const unsigned char *a, int alen,
return false;
}
- if (type & SUBTLV_MANDATORY) {
+ if (CHECK_FLAG(type, SUBTLV_MANDATORY)) {
/*
* RFC 8966 - 4.4
* If the mandatory bit is set, then the whole enclosing
@@ -162,8 +162,7 @@ static bool parse_update_subtlv(const unsigned char *a, int alen,
}
if (memchr(a + i + 2, 0, len) != NULL) {
/* 0 is reserved. */
- flog_err(EC_BABEL_PACKET,
- "Channel information contains 0!");
+ flog_err(EC_BABEL_PACKET, "Channel information contains 0!");
return false;
}
memset(channels, 0, DIVERSITY_HOPS);
@@ -203,7 +202,7 @@ parse_hello_subtlv(const unsigned char *a, int alen,
return -1;
}
- if (type & SUBTLV_MANDATORY) {
+ if (CHECK_FLAG(type, SUBTLV_MANDATORY)) {
/*
* RFC 8966 4.4
* If the mandatory bit is set, then the whole enclosing
@@ -417,7 +416,7 @@ parse_packet(const unsigned char *from, struct interface *ifp,
unsigned int hello_send_us = 0, hello_rtt_receive_time = 0;
babel_interface_nfo *babel_ifp = babel_get_if_nfo(ifp);
- if(babel_ifp->flags & BABEL_IF_TIMESTAMPS) {
+ if (CHECK_FLAG(babel_ifp->flags, BABEL_IF_TIMESTAMPS)) {
/* We want to track exactly when we received this packet. */
gettime(&babel_now);
}
@@ -513,8 +512,7 @@ parse_packet(const unsigned char *from, struct interface *ifp,
schedule_neighbours_check(interval * 15, 0);
/* Sub-TLV handling. */
if (len > 8) {
- if (parse_hello_subtlv(message + 8, len - 6,
- &timestamp) > 0) {
+ if (parse_hello_subtlv(message + 8, len - 6, &timestamp) > 0) {
neigh->hello_send_us = timestamp;
neigh->hello_rtt_receive_time = babel_now;
have_hello_rtt = 1;
@@ -554,8 +552,7 @@ parse_packet(const unsigned char *from, struct interface *ifp,
} else if(type == MESSAGE_NH) {
unsigned char nh[16];
int rc;
- rc = network_address(message[2], message + 4, len - 2,
- nh);
+ rc = network_address(message[2], message + 4, len - 2, nh);
if(rc <= 0) {
have_v4_nh = 0;
have_v6_nh = 0;
@@ -577,9 +574,9 @@ parse_packet(const unsigned char *from, struct interface *ifp,
unsigned char channels[DIVERSITY_HOPS];
unsigned short interval, seqno, metric;
int rc, parsed_len;
- bool ignore_update = false;
+ bool ignore_update = false;
- DO_NTOHS(interval, message + 6);
+ DO_NTOHS(interval, message + 6);
DO_NTOHS(seqno, message + 8);
DO_NTOHS(metric, message + 10);
if(message[5] == 0 ||
@@ -651,7 +648,7 @@ parse_packet(const unsigned char *from, struct interface *ifp,
goto done;
}
- if((babel_get_if_nfo(ifp)->flags & BABEL_IF_FARAWAY)) {
+ if(CHECK_FLAG(babel_get_if_nfo(ifp)->flags, BABEL_IF_FARAWAY)) {
channels[0] = 0;
} else {
/* This will be overwritten by parse_update_subtlv below. */
@@ -665,15 +662,14 @@ parse_packet(const unsigned char *from, struct interface *ifp,
}
if(parsed_len < len)
- ignore_update =
- parse_update_subtlv(message + 2 + parsed_len,
- len - parsed_len, channels);
+ ignore_update =
+ parse_update_subtlv(message + 2 + parsed_len,
+ len - parsed_len, channels);
}
if (!ignore_update)
update_route(router_id, prefix, plen, seqno, metric,
- interval, neigh, nh, channels,
- channels_len(channels));
+ interval, neigh, nh, channels, channels_len(channels));
} else if(type == MESSAGE_REQUEST) {
unsigned char prefix[16], src_prefix[16], plen, src_plen;
int rc, is_ss;
@@ -738,8 +734,7 @@ parse_packet(const unsigned char *from, struct interface *ifp,
format_prefix(prefix, plen),
format_address(from), ifp->name,
format_eui64(message + 8), seqno);
- handle_request(neigh, prefix, plen, message[6],
- seqno, message + 8);
+ handle_request(neigh, prefix, plen, message[6], seqno, message + 8);
} else {
debugf(BABEL_DEBUG_COMMON,"Received unknown packet type %d from %s on %s.",
type, format_address(from), ifp->name);
@@ -821,11 +816,10 @@ check_bucket(struct interface *ifp)
}
}
-static int
-fill_rtt_message(struct interface *ifp)
+static int fill_rtt_message(struct interface *ifp)
{
babel_interface_nfo *babel_ifp = babel_get_if_nfo(ifp);
- if((babel_ifp->flags & BABEL_IF_TIMESTAMPS) &&
+ if(CHECK_FLAG(babel_ifp->flags, BABEL_IF_TIMESTAMPS) &&
(babel_ifp->buffered_hello >= 0)) {
if(babel_ifp->sendbuf[babel_ifp->buffered_hello + 8] == SUBTLV_PADN &&
babel_ifp->sendbuf[babel_ifp->buffered_hello + 9] == 4) {
@@ -845,8 +839,7 @@ fill_rtt_message(struct interface *ifp)
return 0;
}
-void
-flushbuf(struct interface *ifp)
+void flushbuf(struct interface *ifp)
{
int rc;
struct sockaddr_in6 sin6;
@@ -888,8 +881,7 @@ flushbuf(struct interface *ifp)
babel_ifp->flush_timeout.tv_usec = 0;
}
-static void
-schedule_flush(struct interface *ifp)
+static void schedule_flush(struct interface *ifp)
{
babel_interface_nfo *babel_ifp = babel_get_if_nfo(ifp);
unsigned msecs = jitter(babel_ifp, 0);
@@ -899,8 +891,7 @@ schedule_flush(struct interface *ifp)
set_timeout(&babel_ifp->flush_timeout, msecs);
}
-static void
-schedule_flush_now(struct interface *ifp)
+static void schedule_flush_now(struct interface *ifp)
{
babel_interface_nfo *babel_ifp = babel_get_if_nfo(ifp);
/* Almost now */
@@ -911,8 +902,7 @@ schedule_flush_now(struct interface *ifp)
set_timeout(&babel_ifp->flush_timeout, msecs);
}
-static void
-schedule_unicast_flush(unsigned msecs)
+static void schedule_unicast_flush(unsigned msecs)
{
if(!unicast_neighbour)
return;
@@ -924,16 +914,14 @@ schedule_unicast_flush(unsigned msecs)
babel_now.tv_sec + (babel_now.tv_usec / 1000 + msecs) / 1000;
}
-static void
-ensure_space(struct interface *ifp, int space)
+static void ensure_space(struct interface *ifp, int space)
{
babel_interface_nfo *babel_ifp = babel_get_if_nfo(ifp);
if(babel_ifp->bufsize - babel_ifp->buffered < space)
flushbuf(ifp);
}
-static void
-start_message(struct interface *ifp, int type, int len)
+static void start_message(struct interface *ifp, int type, int len)
{
babel_interface_nfo *babel_ifp = babel_get_if_nfo(ifp);
if(babel_ifp->bufsize - babel_ifp->buffered < len + 2)
@@ -942,8 +930,7 @@ start_message(struct interface *ifp, int type, int len)
babel_ifp->sendbuf[babel_ifp->buffered++] = len;
}
-static void
-end_message(struct interface *ifp, int type, int bytes)
+static void end_message(struct interface *ifp, int type, int bytes)
{
babel_interface_nfo *babel_ifp = babel_get_if_nfo(ifp);
assert(babel_ifp->buffered >= bytes + 2 &&
@@ -952,23 +939,20 @@ end_message(struct interface *ifp, int type, int bytes)
schedule_flush(ifp);
}
-static void
-accumulate_byte(struct interface *ifp, unsigned char value)
+static void accumulate_byte(struct interface *ifp, unsigned char value)
{
babel_interface_nfo *babel_ifp = babel_get_if_nfo(ifp);
babel_ifp->sendbuf[babel_ifp->buffered++] = value;
}
-static void
-accumulate_short(struct interface *ifp, unsigned short value)
+static void accumulate_short(struct interface *ifp, unsigned short value)
{
babel_interface_nfo *babel_ifp = babel_get_if_nfo(ifp);
DO_HTONS(babel_ifp->sendbuf + babel_ifp->buffered, value);
babel_ifp->buffered += 2;
}
-static void
-accumulate_int(struct interface *ifp, unsigned int value)
+static void accumulate_int(struct interface *ifp, unsigned int value)
{
babel_interface_nfo *babel_ifp = babel_get_if_nfo(ifp);
DO_HTONL(babel_ifp->sendbuf + babel_ifp->buffered, value);
@@ -984,8 +968,7 @@ accumulate_bytes(struct interface *ifp,
babel_ifp->buffered += len;
}
-static int
-start_unicast_message(struct neighbour *neigh, int type, int len)
+static int start_unicast_message(struct neighbour *neigh, int type, int len)
{
if(unicast_neighbour) {
if(neigh != unicast_neighbour ||
@@ -1008,8 +991,7 @@ start_unicast_message(struct neighbour *neigh, int type, int len)
return 1;
}
-static void
-end_unicast_message(struct neighbour *neigh, int type, int bytes)
+static void end_unicast_message(struct neighbour *neigh, int type, int bytes)
{
assert(unicast_neighbour == neigh && unicast_buffered >= bytes + 2 &&
unicast_buffer[unicast_buffered - bytes - 2] == type &&
@@ -1030,8 +1012,7 @@ accumulate_unicast_short(struct neighbour *neigh, unsigned short value)
unicast_buffered += 2;
}
-static void
-accumulate_unicast_int(struct neighbour *neigh, unsigned int value)
+static void accumulate_unicast_int(struct neighbour *neigh, unsigned int value)
{
DO_HTONL(unicast_buffer + unicast_buffered, value);
unicast_buffered += 4;
@@ -1051,15 +1032,16 @@ send_ack(struct neighbour *neigh, unsigned short nonce, unsigned short interval)
int rc;
debugf(BABEL_DEBUG_COMMON,"Sending ack (%04x) to %s on %s.",
nonce, format_address(neigh->address), neigh->ifp->name);
- rc = start_unicast_message(neigh, MESSAGE_ACK, 2); if(rc < 0) return;
+ rc = start_unicast_message(neigh, MESSAGE_ACK, 2);
+ if(rc < 0)
+ return;
accumulate_unicast_short(neigh, nonce);
end_unicast_message(neigh, MESSAGE_ACK, 2);
/* Roughly yields a value no larger than 3/2, so this meets the deadline */
schedule_unicast_flush(roughly(interval * 6));
}
-void
-send_hello_noupdate(struct interface *ifp, unsigned interval)
+void send_hello_noupdate(struct interface *ifp, unsigned interval)
{
babel_interface_nfo *babel_ifp = babel_get_if_nfo(ifp);
/* This avoids sending multiple hellos in a single packet, which breaks
@@ -1082,7 +1064,7 @@ send_hello_noupdate(struct interface *ifp, unsigned interval)
accumulate_short(ifp, 0);
accumulate_short(ifp, babel_ifp->hello_seqno);
accumulate_short(ifp, interval > 0xFFFF ? 0xFFFF : interval);
- if(babel_ifp->flags & BABEL_IF_TIMESTAMPS) {
+ if (CHECK_FLAG(babel_ifp->flags, BABEL_IF_TIMESTAMPS)) {
/* Sub-TLV containing the local time of emission. We use a
Pad4 sub-TLV, which we'll fill just before sending. */
accumulate_byte(ifp, SUBTLV_PADN);
@@ -1090,11 +1072,10 @@ send_hello_noupdate(struct interface *ifp, unsigned interval)
accumulate_int(ifp, 0);
}
end_message(ifp, MESSAGE_HELLO,
- (babel_ifp->flags & BABEL_IF_TIMESTAMPS) ? 12 : 6);
+ CHECK_FLAG(babel_ifp->flags, BABEL_IF_TIMESTAMPS) ? 12 : 6);
}
-void
-send_hello(struct interface *ifp)
+void send_hello(struct interface *ifp)
{
babel_interface_nfo *babel_ifp = babel_get_if_nfo(ifp);
send_hello_noupdate(ifp, (babel_ifp->hello_interval + 9) / 10);
@@ -1105,8 +1086,7 @@ send_hello(struct interface *ifp)
send_marginal_ihu(ifp);
}
-void
-flush_unicast(int dofree)
+void flush_unicast(int dofree)
{
struct sockaddr_in6 sin6;
int rc;
@@ -1183,7 +1163,7 @@ really_send_update(struct interface *ifp,
/* Worst case */
ensure_space(ifp, 20 + 12 + 28);
- v4 = plen >= 96 && v4mapped(prefix);
+ v4 = (plen >= 96) && v4mapped(prefix);
if(v4) {
if(!babel_ifp->ipv4)
@@ -1208,7 +1188,7 @@ really_send_update(struct interface *ifp,
omit++;
}
if(!babel_ifp->have_buffered_prefix || plen >= 48)
- flags |= 0x80;
+ SET_FLAG(flags, 0x80);
real_prefix = prefix;
real_plen = plen;
}
@@ -1216,7 +1196,7 @@ really_send_update(struct interface *ifp,
if(!babel_ifp->have_buffered_id
|| memcmp(id, babel_ifp->buffered_id, 8) != 0) {
if(real_plen == 128 && memcmp(real_prefix + 8, id, 8) == 0) {
- flags |= 0x40;
+ SET_FLAG(flags, 0x40);
} else {
start_message(ifp, MESSAGE_ROUTER_ID, 10);
accumulate_short(ifp, 0);
@@ -1248,14 +1228,13 @@ really_send_update(struct interface *ifp,
end_message(ifp, MESSAGE_UPDATE, 10 + (real_plen + 7) / 8 - omit +
channels_size);
- if(flags & 0x80) {
+ if (CHECK_FLAG(flags, 0x80)) {
memcpy(babel_ifp->buffered_prefix, prefix, 16);
babel_ifp->have_buffered_prefix = 1;
}
}
-static int
-compare_buffered_updates(const void *av, const void *bv)
+static int compare_buffered_updates(const void *av, const void *bv)
{
const struct buffered_update *a = av, *b = bv;
int rc, v4a, v4b, ma, mb;
@@ -1288,8 +1267,7 @@ compare_buffered_updates(const void *av, const void *bv)
return memcmp(a->prefix, b->prefix, 16);
}
-void
-flushupdates(struct interface *ifp)
+void flushupdates(struct interface *ifp)
{
babel_interface_nfo *babel_ifp = NULL;
struct xroute *xroute;
@@ -1299,7 +1277,7 @@ flushupdates(struct interface *ifp)
int i;
if(ifp == NULL) {
- struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
+ struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
struct interface *ifp_aux;
FOR_ALL_INTERFACES(vrf, ifp_aux)
flushupdates(ifp_aux);
@@ -1372,7 +1350,7 @@ flushupdates(struct interface *ifp)
if(metric < INFINITY)
satisfy_request(route->src->prefix, route->src->plen,
seqno, route->src->id, ifp);
- if((babel_ifp->flags & BABEL_IF_SPLIT_HORIZON) &&
+ if(CHECK_FLAG(babel_ifp->flags, BABEL_IF_SPLIT_HORIZON) &&
route->neigh->ifp == ifp)
continue;
@@ -1414,11 +1392,11 @@ flushupdates(struct interface *ifp)
babel_ifp->update_flush_timeout.tv_usec = 0;
}
-static void
-schedule_update_flush(struct interface *ifp, int urgent)
+static void schedule_update_flush(struct interface *ifp, int urgent)
{
babel_interface_nfo *babel_ifp = babel_get_if_nfo(ifp);
unsigned msecs;
+
msecs = update_jitter(babel_ifp, urgent);
if(babel_ifp->update_flush_timeout.tv_sec != 0 &&
timeval_minus_msec(&babel_ifp->update_flush_timeout, &babel_now) < msecs)
@@ -1528,10 +1506,10 @@ send_update_resend(struct interface *ifp,
record_resend(RESEND_UPDATE, prefix, plen, 0, NULL, NULL, resend_delay);
}
-void
-send_wildcard_retraction(struct interface *ifp)
+void send_wildcard_retraction(struct interface *ifp)
{
babel_interface_nfo *babel_ifp = NULL;
+
if(ifp == NULL) {
struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
struct interface *ifp_aux;
@@ -1557,14 +1535,12 @@ send_wildcard_retraction(struct interface *ifp)
babel_ifp->have_buffered_id = 0;
}
-void
-update_myseqno(void)
+void update_myseqno(void)
{
myseqno = seqno_plus(myseqno, 1);
}
-void
-send_self_update(struct interface *ifp)
+void send_self_update(struct interface *ifp)
{
struct xroute_stream *xroutes;
if(ifp == NULL) {
@@ -1592,8 +1568,7 @@ send_self_update(struct interface *ifp)
}
}
-void
-send_ihu(struct neighbour *neigh, struct interface *ifp)
+void send_ihu(struct neighbour *neigh, struct interface *ifp)
{
babel_interface_nfo *babel_ifp = NULL;
int rxcost, interval;
@@ -1645,7 +1620,7 @@ send_ihu(struct neighbour *neigh, struct interface *ifp)
ll = linklocal(neigh->address);
- if((babel_ifp->flags & BABEL_IF_TIMESTAMPS) && neigh->hello_send_us
+ if(CHECK_FLAG(babel_ifp->flags, BABEL_IF_TIMESTAMPS) && neigh->hello_send_us
/* Checks whether the RTT data is not too old to be sent. */
&& timeval_minus_msec(&babel_now,
&neigh->hello_rtt_receive_time) < 1000000) {
@@ -1700,14 +1675,13 @@ send_ihu(struct neighbour *neigh, struct interface *ifp)
}
/* Send IHUs to all marginal neighbours */
-void
-send_marginal_ihu(struct interface *ifp)
+void send_marginal_ihu(struct interface *ifp)
{
struct neighbour *neigh;
FOR_ALL_NEIGHBOURS(neigh) {
if(ifp && neigh->ifp != ifp)
continue;
- if(neigh->txcost >= 384 || (neigh->reach & 0xF000) != 0xF000)
+ if(neigh->txcost >= 384 || CHECK_FLAG(neigh->reach, 0xF000) != 0xF000)
send_ihu(neigh, ifp);
}
}
diff --git a/babeld/neighbour.c b/babeld/neighbour.c
index 51e595a..65e613c 100644
--- a/babeld/neighbour.c
+++ b/babeld/neighbour.c
@@ -34,15 +34,13 @@ find_neighbour_nocreate(const unsigned char *address, struct interface *ifp)
{
struct neighbour *neigh;
FOR_ALL_NEIGHBOURS(neigh) {
- if(memcmp(address, neigh->address, 16) == 0 &&
- neigh->ifp == ifp)
+ if(memcmp(address, neigh->address, 16) == 0 && neigh->ifp == ifp)
return neigh;
}
return NULL;
}
-void
-flush_neighbour(struct neighbour *neigh)
+void flush_neighbour(struct neighbour *neigh)
{
debugf(BABEL_DEBUG_COMMON,"Flushing neighbour %s (reach 0x%04x)",
format_address(neigh->address), neigh->reach);
@@ -102,8 +100,7 @@ find_neighbour(const unsigned char *address, struct interface *ifp)
}
/* Recompute a neighbour's rxcost. Return true if anything changed. */
-int
-update_neighbour(struct neighbour *neigh, int hello, int hello_interval)
+int update_neighbour(struct neighbour *neigh, int hello, int hello_interval)
{
int missed_hellos;
int rc = 0;
@@ -160,26 +157,26 @@ update_neighbour(struct neighbour *neigh, int hello, int hello_interval)
if(hello >= 0) {
neigh->hello_seqno = hello;
neigh->reach >>= 1;
- neigh->reach |= 0x8000;
- if((neigh->reach & 0xFC00) != 0xFC00)
+ SET_FLAG(neigh->reach, 0x8000);
+ if(CHECK_FLAG(neigh->reach, 0xFC00) != 0xFC00)
rc = 1;
}
/* Make sure to give neighbours some feedback early after association */
- if((neigh->reach & 0xBF00) == 0x8000) {
+ if(CHECK_FLAG(neigh->reach, 0xBF00) == 0x8000) {
/* A new neighbour */
send_hello(neigh->ifp);
} else {
/* Don't send hellos, in order to avoid a positive feedback loop. */
- int a = (neigh->reach & 0xC000);
- int b = (neigh->reach & 0x3000);
+ int a = CHECK_FLAG(neigh->reach, 0xC000);
+ int b = CHECK_FLAG(neigh->reach, 0x3000);
if((a == 0xC000 && b == 0) || (a == 0 && b == 0x3000)) {
/* Reachability is either 1100 or 0011 */
send_self_update(neigh->ifp);
}
}
- if((neigh->reach & 0xFC00) == 0xC000) {
+ if(CHECK_FLAG(neigh->reach, 0xFC00) == 0xC000) {
/* This is a newish neighbour, let's request a full route dump.
We ought to avoid this when the network is dense */
send_unicast_request(neigh, NULL, 0);
@@ -188,8 +185,7 @@ update_neighbour(struct neighbour *neigh, int hello, int hello_interval)
return rc;
}
-static int
-reset_txcost(struct neighbour *neigh)
+static int reset_txcost(struct neighbour *neigh)
{
unsigned delay;
@@ -199,9 +195,8 @@ reset_txcost(struct neighbour *neigh)
return 0;
/* If we're losing a lot of packets, we probably lost an IHU too */
- if(delay >= 180000 || (neigh->reach & 0xFFF0) == 0 ||
- (neigh->ihu_interval > 0 &&
- delay >= neigh->ihu_interval * 10U * 10U)) {
+ if (delay >= 180000 || CHECK_FLAG(neigh->reach, 0xFFF0) == 0 ||
+ (neigh->ihu_interval > 0 && delay >= neigh->ihu_interval * 10U * 10U)) {
neigh->txcost = INFINITY;
neigh->ihu_time = babel_now;
return 1;
@@ -210,14 +205,12 @@ reset_txcost(struct neighbour *neigh)
return 0;
}
-unsigned
-neighbour_txcost(struct neighbour *neigh)
+unsigned neighbour_txcost(struct neighbour *neigh)
{
return neigh->txcost;
}
-unsigned
-check_neighbours(void)
+unsigned check_neighbours(void)
{
struct neighbour *neigh;
int changed, rc;
@@ -253,21 +246,20 @@ check_neighbours(void)
return msecs;
}
-unsigned
-neighbour_rxcost(struct neighbour *neigh)
+unsigned neighbour_rxcost(struct neighbour *neigh)
{
unsigned delay;
unsigned short reach = neigh->reach;
delay = timeval_minus_msec(&babel_now, &neigh->hello_time);
- if((reach & 0xFFF0) == 0 || delay >= 180000) {
+ if(CHECK_FLAG(reach, 0xFFF0) == 0 || delay >= 180000) {
return INFINITY;
- } else if(babel_get_if_nfo(neigh->ifp)->flags & BABEL_IF_LQ) {
+ } else if (CHECK_FLAG(babel_get_if_nfo(neigh->ifp)->flags, BABEL_IF_LQ)) {
int sreach =
- ((reach & 0x8000) >> 2) +
- ((reach & 0x4000) >> 1) +
- (reach & 0x3FFF);
+ (CHECK_FLAG(reach, 0x8000) >> 2) +
+ (CHECK_FLAG(reach, 0x4000) >> 1) +
+ CHECK_FLAG(reach, 0x3FFF);
/* 0 <= sreach <= 0x7FFF */
int cost = (0x8000 * babel_get_if_nfo(neigh->ifp)->cost) / (sreach + 1);
/* cost >= interface->cost */
@@ -276,19 +268,18 @@ neighbour_rxcost(struct neighbour *neigh)
return MIN(cost, INFINITY);
} else {
/* To lose one hello is a misfortune, to lose two is carelessness. */
- if((reach & 0xC000) == 0xC000)
+ if (CHECK_FLAG(reach, 0xC000) == 0xC000)
return babel_get_if_nfo(neigh->ifp)->cost;
- else if((reach & 0xC000) == 0)
+ else if (CHECK_FLAG(reach, 0xC000) == 0)
return INFINITY;
- else if((reach & 0x2000))
+ else if (CHECK_FLAG(reach, 0x2000))
return babel_get_if_nfo(neigh->ifp)->cost;
else
return INFINITY;
}
}
-unsigned
-neighbour_rttcost(struct neighbour *neigh)
+unsigned neighbour_rttcost(struct neighbour *neigh)
{
struct interface *ifp = neigh->ifp;
babel_interface_nfo *babel_ifp = babel_get_if_nfo(ifp);
@@ -304,15 +295,14 @@ neighbour_rttcost(struct neighbour *neigh)
(unsigned long long)babel_ifp->max_rtt_penalty *
(neigh->rtt - babel_ifp->rtt_min) /
(babel_ifp->rtt_max - babel_ifp->rtt_min);
- assert((tmp & 0x7FFFFFFF) == tmp);
+ assert(CHECK_FLAG(tmp, 0x7FFFFFFF) == tmp);
return tmp;
} else {
return babel_ifp->max_rtt_penalty;
}
}
-unsigned
-neighbour_cost(struct neighbour *neigh)
+unsigned neighbour_cost(struct neighbour *neigh)
{
unsigned a, b, cost;
@@ -328,7 +318,7 @@ neighbour_cost(struct neighbour *neigh)
if(b >= INFINITY)
return INFINITY;
- if(!(babel_get_if_nfo(neigh->ifp)->flags & BABEL_IF_LQ)
+ if (!CHECK_FLAG(babel_get_if_nfo(neigh->ifp)->flags, BABEL_IF_LQ)
|| (a < 256 && b < 256)) {
cost = a;
} else {
@@ -347,8 +337,7 @@ neighbour_cost(struct neighbour *neigh)
return MIN(cost, INFINITY);
}
-int
-valid_rtt(struct neighbour *neigh)
+int valid_rtt(struct neighbour *neigh)
{
return (timeval_minus_msec(&babel_now, &neigh->rtt_time) < 180000) ? 1 : 0;
}