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)
...
@@ -910,8 +910,6 @@ dump_tables(FILE *out)
fprintf
(
out
,
"My id %s seqno %d
\n
"
,
format_address
(
myid
),
myseqno
);
fprintf
(
out
,
"My id %s seqno %d
\n
"
,
format_address
(
myid
),
myseqno
);
FOR_ALL_NEIGHBOURS
(
neigh
)
{
FOR_ALL_NEIGHBOURS
(
neigh
)
{
if
(
!
neighbour_valid
(
neigh
))
continue
;
fprintf
(
out
,
"Neighbour %s "
,
format_address
(
neigh
->
id
));
fprintf
(
out
,
"Neighbour %s "
,
format_address
(
neigh
->
id
));
fprintf
(
out
,
"at %s dev %s reach %04x rxcost %d txcost %d%s.
\n
"
,
fprintf
(
out
,
"at %s dev %s reach %04x rxcost %d txcost %d%s.
\n
"
,
format_address
(
neigh
->
address
),
format_address
(
neigh
->
address
),
...
...
babel.h
View file @
6563584a
...
@@ -21,7 +21,6 @@ THE SOFTWARE.
...
@@ -21,7 +21,6 @@ THE SOFTWARE.
*/
*/
#define MAXSRCS 256
#define MAXSRCS 256
#define MAXNEIGHBOURS 64
#define INFINITY ((unsigned short)(~0))
#define INFINITY ((unsigned short)(~0))
...
...
message.c
View file @
6563584a
...
@@ -1022,8 +1022,6 @@ send_ihu(struct neighbour *neigh, struct network *net)
...
@@ -1022,8 +1022,6 @@ send_ihu(struct neighbour *neigh, struct network *net)
if
(
neigh
==
NULL
)
{
if
(
neigh
==
NULL
)
{
struct
neighbour
*
ngh
;
struct
neighbour
*
ngh
;
FOR_ALL_NEIGHBOURS
(
ngh
)
{
FOR_ALL_NEIGHBOURS
(
ngh
)
{
if
(
!
neighbour_valid
(
ngh
))
continue
;
if
(
ngh
->
network
==
net
)
if
(
ngh
->
network
==
net
)
send_ihu
(
ngh
,
net
);
send_ihu
(
ngh
,
net
);
}
}
...
@@ -1056,7 +1054,7 @@ send_marginal_ihu(struct network *net)
...
@@ -1056,7 +1054,7 @@ send_marginal_ihu(struct network *net)
{
{
struct
neighbour
*
neigh
;
struct
neighbour
*
neigh
;
FOR_ALL_NEIGHBOURS
(
neigh
)
{
FOR_ALL_NEIGHBOURS
(
neigh
)
{
if
(
!
neighbour_valid
(
neigh
)
||
(
net
&&
neigh
->
network
!=
net
)
)
if
(
net
&&
neigh
->
network
!=
net
)
continue
;
continue
;
if
(
neigh
->
txcost
>=
384
||
(
neigh
->
reach
&
0xF000
)
!=
0xF000
)
if
(
neigh
->
txcost
>=
384
||
(
neigh
->
reach
&
0xF000
)
!=
0xF000
)
send_ihu
(
neigh
,
net
);
send_ihu
(
neigh
,
net
);
...
...
neighbour.c
View file @
6563584a
...
@@ -34,13 +34,18 @@ THE SOFTWARE.
...
@@ -34,13 +34,18 @@ THE SOFTWARE.
#include "route.h"
#include "route.h"
#include "message.h"
#include "message.h"
struct
neighbour
neighs
[
MAXNEIGHBOURS
];
struct
neighbour
*
neighs
=
NULL
;
int
numneighs
=
0
;
int
struct
neighbour
*
neighbour_valid
(
struct
neighbour
*
neigh
)
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
void
...
@@ -49,35 +54,23 @@ flush_neighbour(struct neighbour *neigh)
...
@@ -49,35 +54,23 @@ flush_neighbour(struct neighbour *neigh)
flush_neighbour_routes
(
neigh
);
flush_neighbour_routes
(
neigh
);
if
(
unicast_neighbour
==
neigh
)
if
(
unicast_neighbour
==
neigh
)
flush_unicast
(
1
);
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
*
if
(
neighs
==
neigh
)
{
find_neighbour
(
const
unsigned
char
*
address
,
struct
network
*
net
)
neighs
=
neigh
->
next
;
{
}
else
{
struct
neighbour
*
neigh
;
struct
neighbour
*
previous
=
neighs
;
FOR_ALL_NEIGHBOURS
(
neigh
)
{
while
(
previous
->
next
!=
neigh
)
if
(
!
neighbour_valid
(
neigh
))
previous
=
previous
->
next
;
continue
;
previous
->
next
=
neigh
->
next
;
if
(
memcmp
(
address
,
neigh
->
address
,
16
)
==
0
&&
neigh
->
network
==
net
)
return
neigh
;
}
}
return
NULL
;
free
(
neigh
)
;
}
}
struct
neighbour
*
struct
neighbour
*
add_neighbour
(
const
unsigned
char
*
id
,
const
unsigned
char
*
address
,
add_neighbour
(
const
unsigned
char
*
id
,
const
unsigned
char
*
address
,
struct
network
*
net
)
struct
network
*
net
)
{
{
struct
neighbour
*
neigh
,
*
ngh
;
struct
neighbour
*
neigh
;
const
struct
timeval
zero
=
{
0
,
0
};
const
struct
timeval
zero
=
{
0
,
0
};
neigh
=
find_neighbour
(
address
,
net
);
neigh
=
find_neighbour
(
address
,
net
);
...
@@ -93,17 +86,13 @@ add_neighbour(const unsigned char *id, const unsigned char *address,
...
@@ -93,17 +86,13 @@ add_neighbour(const unsigned char *id, const unsigned char *address,
}
}
debugf
(
"Creating neighbour %s (%s).
\n
"
,
debugf
(
"Creating neighbour %s (%s).
\n
"
,
format_address
(
id
),
format_address
(
address
));
format_address
(
id
),
format_address
(
address
));
FOR_ALL_NEIGHBOURS
(
ngh
)
{
if
(
!
neighbour_valid
(
ngh
))
neigh
=
malloc
(
sizeof
(
struct
neighbour
));
neigh
=
ngh
;
if
(
neigh
==
NULL
)
{
}
perror
(
"malloc(neighbour)"
);
if
(
!
neigh
)
{
if
(
numneighs
>=
MAXNEIGHBOURS
)
{
fprintf
(
stderr
,
"Too many neighbours.
\n
"
);
return
NULL
;
return
NULL
;
}
}
neigh
=
&
neighs
[
numneighs
++
];
}
neigh
->
hello_seqno
=
-
1
;
neigh
->
hello_seqno
=
-
1
;
memcpy
(
neigh
->
id
,
id
,
16
);
memcpy
(
neigh
->
id
,
id
,
16
);
memcpy
(
neigh
->
address
,
address
,
16
);
memcpy
(
neigh
->
address
,
address
,
16
);
...
@@ -114,6 +103,8 @@ add_neighbour(const unsigned char *id, const unsigned char *address,
...
@@ -114,6 +103,8 @@ add_neighbour(const unsigned char *id, const unsigned char *address,
neigh
->
hello_interval
=
0
;
neigh
->
hello_interval
=
0
;
neigh
->
ihu_interval
=
0
;
neigh
->
ihu_interval
=
0
;
neigh
->
network
=
net
;
neigh
->
network
=
net
;
neigh
->
next
=
neighs
;
neighs
=
neigh
;
send_hello
(
net
);
send_hello
(
net
);
return
neigh
;
return
neigh
;
}
}
...
@@ -240,16 +231,16 @@ check_neighbours()
...
@@ -240,16 +231,16 @@ check_neighbours()
debugf
(
"Checking neighbours.
\n
"
);
debugf
(
"Checking neighbours.
\n
"
);
FOR_ALL_NEIGHBOURS
(
neigh
)
{
neigh
=
neighs
;
if
(
!
neighbour_valid
(
neigh
))
while
(
neigh
)
{
continue
;
changed
=
update_neighbour
(
neigh
,
-
1
,
0
);
changed
=
update_neighbour
(
neigh
,
-
1
,
0
);
if
(
neigh
->
reach
==
0
||
if
(
neigh
->
reach
==
0
||
neigh
->
hello_time
.
tv_sec
>
now
.
tv_sec
||
/* clock stepped */
neigh
->
hello_time
.
tv_sec
>
now
.
tv_sec
||
/* clock stepped */
timeval_minus_msec
(
&
now
,
&
neigh
->
hello_time
)
>
300000
)
{
timeval_minus_msec
(
&
now
,
&
neigh
->
hello_time
)
>
300000
)
{
flush_neighbour
(
neigh
);
struct
neighbour
*
old
=
neigh
;
neigh
=
neigh
->
next
;
flush_neighbour
(
old
);
continue
;
continue
;
}
}
...
@@ -264,6 +255,7 @@ check_neighbours()
...
@@ -264,6 +255,7 @@ check_neighbours()
msecs
=
MIN
(
msecs
,
neigh
->
hello_interval
*
10
);
msecs
=
MIN
(
msecs
,
neigh
->
hello_interval
*
10
);
if
(
neigh
->
ihu_interval
>
0
)
if
(
neigh
->
ihu_interval
>
0
)
msecs
=
MIN
(
msecs
,
neigh
->
ihu_interval
*
10
);
msecs
=
MIN
(
msecs
,
neigh
->
ihu_interval
*
10
);
neigh
=
neigh
->
next
;
}
}
return
msecs
;
return
msecs
;
...
...
neighbour.h
View file @
6563584a
...
@@ -21,8 +21,8 @@ THE SOFTWARE.
...
@@ -21,8 +21,8 @@ THE SOFTWARE.
*/
*/
struct
neighbour
{
struct
neighbour
{
/* This is -1 when unknown, and -2 for an invalid neighbour,
struct
neighbour
*
next
;
so don't make it unsigned */
/* This is -1 when unknown,
so don't make it unsigned */
int
hello_seqno
;
int
hello_seqno
;
unsigned
char
id
[
16
];
unsigned
char
id
[
16
];
unsigned
char
address
[
16
];
unsigned
char
address
[
16
];
...
@@ -35,11 +35,10 @@ struct neighbour {
...
@@ -35,11 +35,10 @@ struct neighbour {
struct
network
*
network
;
struct
network
*
network
;
};
};
extern
struct
neighbour
neighs
[
MAXNEIGHBOURS
];
extern
struct
neighbour
*
neighs
;
extern
int
numneighs
;
#define FOR_ALL_NEIGHBOURS(_neigh) \
#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
);
int
neighbour_valid
(
struct
neighbour
*
neigh
);
void
flush_neighbour
(
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