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
0b778cc6
Commit
0b778cc6
authored
Jun 18, 2014
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use streams for iterating over xroutes.
parent
ec7519a4
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
73 additions
and
24 deletions
+73
-24
babeld.c
babeld.c
+14
-3
local.c
local.c
+14
-7
message.c
message.c
+12
-8
xroute.c
xroute.c
+28
-5
xroute.h
xroute.h
+5
-1
No files found.
babeld.c
View file @
0b778cc6
...
@@ -1033,9 +1033,8 @@ dump_route(FILE *out, struct babel_route *route)
...
@@ -1033,9 +1033,8 @@ dump_route(FILE *out, struct babel_route *route)
}
}
static
void
static
void
dump_xroute
_callback
(
struct
xroute
*
xroute
,
void
*
closur
e
)
dump_xroute
(
FILE
*
out
,
struct
xroute
*
xrout
e
)
{
{
FILE
*
out
=
(
FILE
*
)
closure
;
fprintf
(
out
,
"%s metric %d (exported)
\n
"
,
fprintf
(
out
,
"%s metric %d (exported)
\n
"
,
format_prefix
(
xroute
->
prefix
,
xroute
->
plen
),
format_prefix
(
xroute
->
prefix
,
xroute
->
plen
),
xroute
->
metric
);
xroute
->
metric
);
...
@@ -1045,6 +1044,7 @@ static void
...
@@ -1045,6 +1044,7 @@ static void
dump_tables
(
FILE
*
out
)
dump_tables
(
FILE
*
out
)
{
{
struct
neighbour
*
neigh
;
struct
neighbour
*
neigh
;
struct
xroute_stream
*
xroutes
;
struct
route_stream
*
routes
;
struct
route_stream
*
routes
;
fprintf
(
out
,
"
\n
"
);
fprintf
(
out
,
"
\n
"
);
...
@@ -1064,7 +1064,17 @@ dump_tables(FILE *out)
...
@@ -1064,7 +1064,17 @@ dump_tables(FILE *out)
neigh
->
ifp
->
channel
,
neigh
->
ifp
->
channel
,
if_up
(
neigh
->
ifp
)
?
""
:
" (down)"
);
if_up
(
neigh
->
ifp
)
?
""
:
" (down)"
);
}
}
for_all_xroutes
(
dump_xroute_callback
,
out
);
xroutes
=
xroute_stream
();
if
(
xroutes
)
{
while
(
1
)
{
struct
xroute
*
xroute
=
xroute_stream_next
(
xroutes
);
if
(
xroute
==
NULL
)
break
;
dump_xroute
(
out
,
xroute
);
}
xroute_stream_done
(
xroutes
);
}
routes
=
route_stream
(
0
);
routes
=
route_stream
(
0
);
if
(
routes
)
{
if
(
routes
)
{
while
(
1
)
{
while
(
1
)
{
...
@@ -1074,6 +1084,7 @@ dump_tables(FILE *out)
...
@@ -1074,6 +1084,7 @@ dump_tables(FILE *out)
}
}
route_stream_done
(
routes
);
route_stream_done
(
routes
);
}
}
fflush
(
out
);
fflush
(
out
);
}
}
...
...
local.c
View file @
0b778cc6
...
@@ -253,18 +253,13 @@ local_notify_route(struct babel_route *route, int kind)
...
@@ -253,18 +253,13 @@ local_notify_route(struct babel_route *route, int kind)
local_notify_route_1
(
local_sockets
[
i
],
route
,
kind
);
local_notify_route_1
(
local_sockets
[
i
],
route
,
kind
);
}
}
static
void
local_notify_xroute_callback
(
struct
xroute
*
xroute
,
void
*
closure
)
{
local_notify_xroute_1
(
*
(
int
*
)
closure
,
xroute
,
LOCAL_ADD
);
}
void
void
local_notify_all_1
(
int
s
)
local_notify_all_1
(
int
s
)
{
{
int
rc
;
int
rc
;
struct
neighbour
*
neigh
;
struct
neighbour
*
neigh
;
const
char
*
header
=
"BABEL 0.0
\n
"
;
const
char
*
header
=
"BABEL 0.0
\n
"
;
struct
xroute_stream
*
xroutes
;
struct
route_stream
*
routes
;
struct
route_stream
*
routes
;
rc
=
write_timeout
(
s
,
header
,
strlen
(
header
));
rc
=
write_timeout
(
s
,
header
,
strlen
(
header
));
...
@@ -275,7 +270,18 @@ local_notify_all_1(int s)
...
@@ -275,7 +270,18 @@ local_notify_all_1(int s)
FOR_ALL_NEIGHBOURS
(
neigh
)
{
FOR_ALL_NEIGHBOURS
(
neigh
)
{
local_notify_neighbour_1
(
s
,
neigh
,
LOCAL_ADD
);
local_notify_neighbour_1
(
s
,
neigh
,
LOCAL_ADD
);
}
}
for_all_xroutes
(
local_notify_xroute_callback
,
&
s
);
xroutes
=
xroute_stream
();
if
(
xroutes
)
{
while
(
1
)
{
struct
xroute
*
xroute
=
xroute_stream_next
(
xroutes
);
if
(
xroute
==
NULL
)
break
;
local_notify_xroute_1
(
s
,
xroute
,
LOCAL_ADD
);
}
xroute_stream_done
(
xroutes
);
}
routes
=
route_stream
(
0
);
routes
=
route_stream
(
0
);
if
(
routes
)
{
if
(
routes
)
{
while
(
1
)
{
while
(
1
)
{
...
@@ -286,6 +292,7 @@ local_notify_all_1(int s)
...
@@ -286,6 +292,7 @@ local_notify_all_1(int s)
}
}
route_stream_done
(
routes
);
route_stream_done
(
routes
);
}
}
rc
=
write_timeout
(
s
,
"done
\n
"
,
5
);
rc
=
write_timeout
(
s
,
"done
\n
"
,
5
);
if
(
rc
<
0
)
if
(
rc
<
0
)
goto
fail
;
goto
fail
;
...
...
message.c
View file @
0b778cc6
...
@@ -1370,16 +1370,10 @@ update_myseqno()
...
@@ -1370,16 +1370,10 @@ update_myseqno()
seqno_time
=
now
;
seqno_time
=
now
;
}
}
static
void
send_xroute_update_callback
(
struct
xroute
*
xroute
,
void
*
closure
)
{
struct
interface
*
ifp
=
(
struct
interface
*
)
closure
;
send_update
(
ifp
,
0
,
xroute
->
prefix
,
xroute
->
plen
);
}
void
void
send_self_update
(
struct
interface
*
ifp
)
send_self_update
(
struct
interface
*
ifp
)
{
{
struct
xroute_stream
*
xroutes
;
if
(
ifp
==
NULL
)
{
if
(
ifp
==
NULL
)
{
struct
interface
*
ifp_aux
;
struct
interface
*
ifp_aux
;
FOR_ALL_INTERFACES
(
ifp_aux
)
{
FOR_ALL_INTERFACES
(
ifp_aux
)
{
...
@@ -1391,7 +1385,17 @@ send_self_update(struct interface *ifp)
...
@@ -1391,7 +1385,17 @@ send_self_update(struct interface *ifp)
}
}
debugf
(
"Sending self update to %s.
\n
"
,
ifp
->
name
);
debugf
(
"Sending self update to %s.
\n
"
,
ifp
->
name
);
for_all_xroutes
(
send_xroute_update_callback
,
ifp
);
xroutes
=
xroute_stream
();
if
(
xroutes
)
{
while
(
1
)
{
struct
xroute
*
xroute
=
xroute_stream_next
(
xroutes
);
if
(
xroute
==
NULL
)
break
;
send_update
(
ifp
,
0
,
xroute
->
prefix
,
xroute
->
plen
);
}
xroute_stream_done
(
xroutes
);
}
else
{
fprintf
(
stderr
,
"Couldn't allocate xroute stream.
\n
"
);
}
}
}
void
void
...
...
xroute.c
View file @
0b778cc6
...
@@ -126,13 +126,36 @@ xroutes_estimate()
...
@@ -126,13 +126,36 @@ xroutes_estimate()
return
numxroutes
;
return
numxroutes
;
}
}
void
struct
xroute_stream
{
for_all_xroutes
(
void
(
*
f
)(
struct
xroute
*
,
void
*
),
void
*
closure
)
int
index
;
};
struct
xroute_stream
*
xroute_stream
()
{
struct
xroute_stream
*
stream
=
malloc
(
sizeof
(
struct
xroute_stream
));
if
(
stream
==
NULL
)
return
NULL
;
stream
->
index
=
0
;
return
stream
;
}
struct
xroute
*
xroute_stream_next
(
struct
xroute_stream
*
stream
)
{
{
int
i
,
n
=
numxroutes
;
if
(
stream
->
index
<
numxroutes
)
return
&
xroutes
[
stream
->
index
++
];
else
return
NULL
;
}
for
(
i
=
0
;
i
<
n
;
i
++
)
void
(
*
f
)(
&
xroutes
[
i
],
closure
);
xroute_stream_done
(
struct
xroute_stream
*
stream
)
{
free
(
stream
);
}
}
int
int
...
...
xroute.h
View file @
0b778cc6
...
@@ -28,10 +28,14 @@ struct xroute {
...
@@ -28,10 +28,14 @@ struct xroute {
int
proto
;
int
proto
;
};
};
struct
xroute_stream
;
struct
xroute
*
find_xroute
(
const
unsigned
char
*
prefix
,
unsigned
char
plen
);
struct
xroute
*
find_xroute
(
const
unsigned
char
*
prefix
,
unsigned
char
plen
);
void
flush_xroute
(
struct
xroute
*
xroute
);
void
flush_xroute
(
struct
xroute
*
xroute
);
int
add_xroute
(
unsigned
char
prefix
[
16
],
unsigned
char
plen
,
int
add_xroute
(
unsigned
char
prefix
[
16
],
unsigned
char
plen
,
unsigned
short
metric
,
unsigned
int
ifindex
,
int
proto
);
unsigned
short
metric
,
unsigned
int
ifindex
,
int
proto
);
int
xroutes_estimate
(
void
);
int
xroutes_estimate
(
void
);
void
for_all_xroutes
(
void
(
*
f
)(
struct
xroute
*
,
void
*
),
void
*
closure
);
struct
xroute_stream
*
xroute_stream
();
struct
xroute
*
xroute_stream_next
(
struct
xroute_stream
*
stream
);
void
xroute_stream_done
(
struct
xroute_stream
*
stream
);
int
check_xroutes
(
int
send_updates
);
int
check_xroutes
(
int
send_updates
);
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