Skip to content

Commit c8287d9

Browse files
committed
babeld: changes for code maintainability
these changes are for improving the code maintainability and readability Signed-off-by: sri-mohan1 <[email protected]>
1 parent 21b7f32 commit c8287d9

File tree

1 file changed

+28
-39
lines changed

1 file changed

+28
-39
lines changed

babeld/neighbour.c

+28-39
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,13 @@ find_neighbour_nocreate(const unsigned char *address, struct interface *ifp)
3434
{
3535
struct neighbour *neigh;
3636
FOR_ALL_NEIGHBOURS(neigh) {
37-
if(memcmp(address, neigh->address, 16) == 0 &&
38-
neigh->ifp == ifp)
37+
if(memcmp(address, neigh->address, 16) == 0 && neigh->ifp == ifp)
3938
return neigh;
4039
}
4140
return NULL;
4241
}
4342

44-
void
45-
flush_neighbour(struct neighbour *neigh)
43+
void flush_neighbour(struct neighbour *neigh)
4644
{
4745
debugf(BABEL_DEBUG_COMMON,"Flushing neighbour %s (reach 0x%04x)",
4846
format_address(neigh->address), neigh->reach);
@@ -102,8 +100,7 @@ find_neighbour(const unsigned char *address, struct interface *ifp)
102100
}
103101

104102
/* Recompute a neighbour's rxcost. Return true if anything changed. */
105-
int
106-
update_neighbour(struct neighbour *neigh, int hello, int hello_interval)
103+
int update_neighbour(struct neighbour *neigh, int hello, int hello_interval)
107104
{
108105
int missed_hellos;
109106
int rc = 0;
@@ -160,26 +157,26 @@ update_neighbour(struct neighbour *neigh, int hello, int hello_interval)
160157
if(hello >= 0) {
161158
neigh->hello_seqno = hello;
162159
neigh->reach >>= 1;
163-
neigh->reach |= 0x8000;
164-
if((neigh->reach & 0xFC00) != 0xFC00)
160+
SET_FLAG(neigh->reach, 0x8000);
161+
if(CHECK_FLAG(neigh->reach, 0xFC00) != 0xFC00)
165162
rc = 1;
166163
}
167164

168165
/* Make sure to give neighbours some feedback early after association */
169-
if((neigh->reach & 0xBF00) == 0x8000) {
166+
if(CHECK_FLAG(neigh->reach, 0xBF00) == 0x8000) {
170167
/* A new neighbour */
171168
send_hello(neigh->ifp);
172169
} else {
173170
/* Don't send hellos, in order to avoid a positive feedback loop. */
174-
int a = (neigh->reach & 0xC000);
175-
int b = (neigh->reach & 0x3000);
171+
int a = CHECK_FLAG(neigh->reach, 0xC000);
172+
int b = CHECK_FLAG(neigh->reach, 0x3000);
176173
if((a == 0xC000 && b == 0) || (a == 0 && b == 0x3000)) {
177174
/* Reachability is either 1100 or 0011 */
178175
send_self_update(neigh->ifp);
179176
}
180177
}
181178

182-
if((neigh->reach & 0xFC00) == 0xC000) {
179+
if(CHECK_FLAG(neigh->reach, 0xFC00) == 0xC000) {
183180
/* This is a newish neighbour, let's request a full route dump.
184181
We ought to avoid this when the network is dense */
185182
send_unicast_request(neigh, NULL, 0);
@@ -188,8 +185,7 @@ update_neighbour(struct neighbour *neigh, int hello, int hello_interval)
188185
return rc;
189186
}
190187

191-
static int
192-
reset_txcost(struct neighbour *neigh)
188+
static int reset_txcost(struct neighbour *neigh)
193189
{
194190
unsigned delay;
195191

@@ -199,9 +195,8 @@ reset_txcost(struct neighbour *neigh)
199195
return 0;
200196

201197
/* If we're losing a lot of packets, we probably lost an IHU too */
202-
if(delay >= 180000 || (neigh->reach & 0xFFF0) == 0 ||
203-
(neigh->ihu_interval > 0 &&
204-
delay >= neigh->ihu_interval * 10U * 10U)) {
198+
if (delay >= 180000 || CHECK_FLAG(neigh->reach, 0xFFF0) == 0 ||
199+
(neigh->ihu_interval > 0 && delay >= neigh->ihu_interval * 10U * 10U)) {
205200
neigh->txcost = INFINITY;
206201
neigh->ihu_time = babel_now;
207202
return 1;
@@ -210,14 +205,12 @@ reset_txcost(struct neighbour *neigh)
210205
return 0;
211206
}
212207

213-
unsigned
214-
neighbour_txcost(struct neighbour *neigh)
208+
unsigned neighbour_txcost(struct neighbour *neigh)
215209
{
216210
return neigh->txcost;
217211
}
218212

219-
unsigned
220-
check_neighbours(void)
213+
unsigned check_neighbours(void)
221214
{
222215
struct neighbour *neigh;
223216
int changed, rc;
@@ -253,21 +246,20 @@ check_neighbours(void)
253246
return msecs;
254247
}
255248

256-
unsigned
257-
neighbour_rxcost(struct neighbour *neigh)
249+
unsigned neighbour_rxcost(struct neighbour *neigh)
258250
{
259251
unsigned delay;
260252
unsigned short reach = neigh->reach;
261253

262254
delay = timeval_minus_msec(&babel_now, &neigh->hello_time);
263255

264-
if((reach & 0xFFF0) == 0 || delay >= 180000) {
256+
if(CHECK_FLAG(reach, 0xFFF0) == 0 || delay >= 180000) {
265257
return INFINITY;
266-
} else if(babel_get_if_nfo(neigh->ifp)->flags & BABEL_IF_LQ) {
258+
} else if (CHECK_FLAG(babel_get_if_nfo(neigh->ifp)->flags, BABEL_IF_LQ)) {
267259
int sreach =
268-
((reach & 0x8000) >> 2) +
269-
((reach & 0x4000) >> 1) +
270-
(reach & 0x3FFF);
260+
(CHECK_FLAG(reach, 0x8000) >> 2) +
261+
(CHECK_FLAG(reach, 0x4000) >> 1) +
262+
CHECK_FLAG(reach, 0x3FFF);
271263
/* 0 <= sreach <= 0x7FFF */
272264
int cost = (0x8000 * babel_get_if_nfo(neigh->ifp)->cost) / (sreach + 1);
273265
/* cost >= interface->cost */
@@ -276,19 +268,18 @@ neighbour_rxcost(struct neighbour *neigh)
276268
return MIN(cost, INFINITY);
277269
} else {
278270
/* To lose one hello is a misfortune, to lose two is carelessness. */
279-
if((reach & 0xC000) == 0xC000)
271+
if (CHECK_FLAG(reach, 0xC000) == 0xC000)
280272
return babel_get_if_nfo(neigh->ifp)->cost;
281-
else if((reach & 0xC000) == 0)
273+
else if (CHECK_FLAG(reach, 0xC000) == 0)
282274
return INFINITY;
283-
else if((reach & 0x2000))
275+
else if (CHECK_FLAG(reach, 0x2000))
284276
return babel_get_if_nfo(neigh->ifp)->cost;
285277
else
286278
return INFINITY;
287279
}
288280
}
289281

290-
unsigned
291-
neighbour_rttcost(struct neighbour *neigh)
282+
unsigned neighbour_rttcost(struct neighbour *neigh)
292283
{
293284
struct interface *ifp = neigh->ifp;
294285
babel_interface_nfo *babel_ifp = babel_get_if_nfo(ifp);
@@ -304,15 +295,14 @@ neighbour_rttcost(struct neighbour *neigh)
304295
(unsigned long long)babel_ifp->max_rtt_penalty *
305296
(neigh->rtt - babel_ifp->rtt_min) /
306297
(babel_ifp->rtt_max - babel_ifp->rtt_min);
307-
assert((tmp & 0x7FFFFFFF) == tmp);
298+
assert(CHECK_FLAG(tmp, 0x7FFFFFFF) == tmp);
308299
return tmp;
309300
} else {
310301
return babel_ifp->max_rtt_penalty;
311302
}
312303
}
313304

314-
unsigned
315-
neighbour_cost(struct neighbour *neigh)
305+
unsigned neighbour_cost(struct neighbour *neigh)
316306
{
317307
unsigned a, b, cost;
318308

@@ -328,7 +318,7 @@ neighbour_cost(struct neighbour *neigh)
328318
if(b >= INFINITY)
329319
return INFINITY;
330320

331-
if(!(babel_get_if_nfo(neigh->ifp)->flags & BABEL_IF_LQ)
321+
if (!CHECK_FLAG(babel_get_if_nfo(neigh->ifp)->flags, BABEL_IF_LQ)
332322
|| (a < 256 && b < 256)) {
333323
cost = a;
334324
} else {
@@ -347,8 +337,7 @@ neighbour_cost(struct neighbour *neigh)
347337
return MIN(cost, INFINITY);
348338
}
349339

350-
int
351-
valid_rtt(struct neighbour *neigh)
340+
int valid_rtt(struct neighbour *neigh)
352341
{
353342
return (timeval_minus_msec(&babel_now, &neigh->rtt_time) < 180000) ? 1 : 0;
354343
}

0 commit comments

Comments
 (0)