Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
babeld
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
babeld
Commits
6563584a
Commit
6563584a
authored
May 19, 2008
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use a linked list for neighbours.
parent
e45020f7
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
38 additions
and
52 deletions
+38
-52
babel.c
babel.c
+0
-2
babel.h
babel.h
+0
-1
message.c
message.c
+1
-3
neighbour.c
neighbour.c
+33
-41
neighbour.h
neighbour.h
+4
-5
No files found.
babel.c
View file @
6563584a
...
...
@@ -910,8 +910,6 @@ dump_tables(FILE *out)
fprintf
(
out
,
"My id %s seqno %d
\n
"
,
format_address
(
myid
),
myseqno
);
FOR_ALL_NEIGHBOURS
(
neigh
)
{
if
(
!
neighbour_valid
(
neigh
))
continue
;
fprintf
(
out
,
"Neighbour %s "
,
format_address
(
neigh
->
id
));
fprintf
(
out
,
"at %s dev %s reach %04x rxcost %d txcost %d%s.
\n
"
,
format_address
(
neigh
->
address
),
...
...
babel.h
View file @
6563584a
...
...
@@ -21,7 +21,6 @@ THE SOFTWARE.
*/
#define MAXSRCS 256
#define MAXNEIGHBOURS 64
#define INFINITY ((unsigned short)(~0))
...
...
message.c
View file @
6563584a
...
...
@@ -1022,8 +1022,6 @@ send_ihu(struct neighbour *neigh, struct network *net)
if
(
neigh
==
NULL
)
{
struct
neighbour
*
ngh
;
FOR_ALL_NEIGHBOURS
(
ngh
)
{
if
(
!
neighbour_valid
(
ngh
))
continue
;
if
(
ngh
->
network
==
net
)
send_ihu
(
ngh
,
net
);
}
...
...
@@ -1056,7 +1054,7 @@ send_marginal_ihu(struct network *net)
{
struct
neighbour
*
neigh
;
FOR_ALL_NEIGHBOURS
(
neigh
)
{
if
(
!
neighbour_valid
(
neigh
)
||
(
net
&&
neigh
->
network
!=
net
)
)
if
(
net
&&
neigh
->
network
!=
net
)
continue
;
if
(
neigh
->
txcost
>=
384
||
(
neigh
->
reach
&
0xF000
)
!=
0xF000
)
send_ihu
(
neigh
,
net
);
...
...
neighbour.c
View file @
6563584a
...
...
@@ -34,13 +34,18 @@ THE SOFTWARE.
#include "route.h"
#include "message.h"
struct
neighbour
neighs
[
MAXNEIGHBOURS
];
int
numneighs
=
0
;
struct
neighbour
*
neighs
=
NULL
;
int
neighbour_valid
(
struct
neighbour
*
neigh
)
struct
neighbour
*
find_neighbour
(
const
unsigned
char
*
address
,
struct
network
*
net
)
{
return
neigh
->
hello_seqno
!=
-
2
;
struct
neighbour
*
neigh
;
FOR_ALL_NEIGHBOURS
(
neigh
)
{
if
(
memcmp
(
address
,
neigh
->
address
,
16
)
==
0
&&
neigh
->
network
==
net
)
return
neigh
;
}
return
NULL
;
}
void
...
...
@@ -49,35 +54,23 @@ flush_neighbour(struct neighbour *neigh)
flush_neighbour_routes
(
neigh
);
if
(
unicast_neighbour
==
neigh
)
flush_unicast
(
1
);
memset
(
neigh
,
0
,
sizeof
(
*
neigh
));
VALGRIND_MAKE_MEM_UNDEFINED
(
neigh
,
sizeof
(
*
neigh
));
neigh
->
hello_seqno
=
-
2
;
while
(
numneighs
>
0
&&
!
neighbour_valid
(
&
neighs
[
numneighs
-
1
]))
{
numneighs
--
;
VALGRIND_MAKE_MEM_UNDEFINED
(
&
neighs
[
numneighs
],
sizeof
(
neighs
[
numneighs
]));
}
}
struct
neighbour
*
find_neighbour
(
const
unsigned
char
*
address
,
struct
network
*
net
)
{
struct
neighbour
*
neigh
;
FOR_ALL_NEIGHBOURS
(
neigh
)
{
if
(
!
neighbour_valid
(
neigh
))
continue
;
if
(
memcmp
(
address
,
neigh
->
address
,
16
)
==
0
&&
neigh
->
network
==
net
)
return
neigh
;
if
(
neighs
==
neigh
)
{
neighs
=
neigh
->
next
;
}
else
{
struct
neighbour
*
previous
=
neighs
;
while
(
previous
->
next
!=
neigh
)
previous
=
previous
->
next
;
previous
->
next
=
neigh
->
next
;
}
return
NULL
;
free
(
neigh
)
;
}
struct
neighbour
*
add_neighbour
(
const
unsigned
char
*
id
,
const
unsigned
char
*
address
,
struct
network
*
net
)
{
struct
neighbour
*
neigh
,
*
ngh
;
struct
neighbour
*
neigh
;
const
struct
timeval
zero
=
{
0
,
0
};
neigh
=
find_neighbour
(
address
,
net
);
...
...
@@ -93,17 +86,13 @@ add_neighbour(const unsigned char *id, const unsigned char *address,
}
debugf
(
"Creating neighbour %s (%s).
\n
"
,
format_address
(
id
),
format_address
(
address
));
FOR_ALL_NEIGHBOURS
(
ngh
)
{
if
(
!
neighbour_valid
(
ngh
))
neigh
=
ngh
;
}
if
(
!
neigh
)
{
if
(
numneighs
>=
MAXNEIGHBOURS
)
{
fprintf
(
stderr
,
"Too many neighbours.
\n
"
);
neigh
=
malloc
(
sizeof
(
struct
neighbour
));
if
(
neigh
==
NULL
)
{
perror
(
"malloc(neighbour)"
);
return
NULL
;
}
neigh
=
&
neighs
[
numneighs
++
];
}
neigh
->
hello_seqno
=
-
1
;
memcpy
(
neigh
->
id
,
id
,
16
);
memcpy
(
neigh
->
address
,
address
,
16
);
...
...
@@ -114,6 +103,8 @@ add_neighbour(const unsigned char *id, const unsigned char *address,
neigh
->
hello_interval
=
0
;
neigh
->
ihu_interval
=
0
;
neigh
->
network
=
net
;
neigh
->
next
=
neighs
;
neighs
=
neigh
;
send_hello
(
net
);
return
neigh
;
}
...
...
@@ -240,16 +231,16 @@ check_neighbours()
debugf
(
"Checking neighbours.
\n
"
);
FOR_ALL_NEIGHBOURS
(
neigh
)
{
if
(
!
neighbour_valid
(
neigh
))
continue
;
neigh
=
neighs
;
while
(
neigh
)
{
changed
=
update_neighbour
(
neigh
,
-
1
,
0
);
if
(
neigh
->
reach
==
0
||
neigh
->
hello_time
.
tv_sec
>
now
.
tv_sec
||
/* clock stepped */
timeval_minus_msec
(
&
now
,
&
neigh
->
hello_time
)
>
300000
)
{
flush_neighbour
(
neigh
);
struct
neighbour
*
old
=
neigh
;
neigh
=
neigh
->
next
;
flush_neighbour
(
old
);
continue
;
}
...
...
@@ -264,6 +255,7 @@ check_neighbours()
msecs
=
MIN
(
msecs
,
neigh
->
hello_interval
*
10
);
if
(
neigh
->
ihu_interval
>
0
)
msecs
=
MIN
(
msecs
,
neigh
->
ihu_interval
*
10
);
neigh
=
neigh
->
next
;
}
return
msecs
;
...
...
neighbour.h
View file @
6563584a
...
...
@@ -21,8 +21,8 @@ THE SOFTWARE.
*/
struct
neighbour
{
/* This is -1 when unknown, and -2 for an invalid neighbour,
so don't make it unsigned */
struct
neighbour
*
next
;
/* This is -1 when unknown,
so don't make it unsigned */
int
hello_seqno
;
unsigned
char
id
[
16
];
unsigned
char
address
[
16
];
...
...
@@ -35,11 +35,10 @@ struct neighbour {
struct
network
*
network
;
};
extern
struct
neighbour
neighs
[
MAXNEIGHBOURS
];
extern
int
numneighs
;
extern
struct
neighbour
*
neighs
;
#define FOR_ALL_NEIGHBOURS(_neigh) \
for(_neigh = neighs; _neigh
< neighs + numneighs; _neigh++
)
for(_neigh = neighs; _neigh
; _neigh = _neigh->next
)
int
neighbour_valid
(
struct
neighbour
*
neigh
);
void
flush_neighbour
(
struct
neighbour
*
neigh
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment