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
Hide 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)
}
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
"
,
format_prefix
(
xroute
->
prefix
,
xroute
->
plen
),
xroute
->
metric
);
...
...
@@ -1045,6 +1044,7 @@ static void
dump_tables
(
FILE
*
out
)
{
struct
neighbour
*
neigh
;
struct
xroute_stream
*
xroutes
;
struct
route_stream
*
routes
;
fprintf
(
out
,
"
\n
"
);
...
...
@@ -1064,7 +1064,17 @@ dump_tables(FILE *out)
neigh
->
ifp
->
channel
,
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
);
if
(
routes
)
{
while
(
1
)
{
...
...
@@ -1074,6 +1084,7 @@ dump_tables(FILE *out)
}
route_stream_done
(
routes
);
}
fflush
(
out
);
}
...
...
local.c
View file @
0b778cc6
...
...
@@ -253,18 +253,13 @@ local_notify_route(struct babel_route *route, int 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
local_notify_all_1
(
int
s
)
{
int
rc
;
struct
neighbour
*
neigh
;
const
char
*
header
=
"BABEL 0.0
\n
"
;
struct
xroute_stream
*
xroutes
;
struct
route_stream
*
routes
;
rc
=
write_timeout
(
s
,
header
,
strlen
(
header
));
...
...
@@ -275,7 +270,18 @@ local_notify_all_1(int s)
FOR_ALL_NEIGHBOURS
(
neigh
)
{
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
);
if
(
routes
)
{
while
(
1
)
{
...
...
@@ -286,6 +292,7 @@ local_notify_all_1(int s)
}
route_stream_done
(
routes
);
}
rc
=
write_timeout
(
s
,
"done
\n
"
,
5
);
if
(
rc
<
0
)
goto
fail
;
...
...
message.c
View file @
0b778cc6
...
...
@@ -1370,16 +1370,10 @@ update_myseqno()
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
send_self_update
(
struct
interface
*
ifp
)
{
struct
xroute_stream
*
xroutes
;
if
(
ifp
==
NULL
)
{
struct
interface
*
ifp_aux
;
FOR_ALL_INTERFACES
(
ifp_aux
)
{
...
...
@@ -1391,7 +1385,17 @@ send_self_update(struct interface *ifp)
}
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
...
...
xroute.c
View file @
0b778cc6
...
...
@@ -126,13 +126,36 @@ xroutes_estimate()
return
numxroutes
;
}
void
for_all_xroutes
(
void
(
*
f
)(
struct
xroute
*
,
void
*
),
void
*
closure
)
struct
xroute_stream
{
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
++
)
(
*
f
)(
&
xroutes
[
i
],
closure
);
void
xroute_stream_done
(
struct
xroute_stream
*
stream
)
{
free
(
stream
);
}
int
...
...
xroute.h
View file @
0b778cc6
...
...
@@ -28,10 +28,14 @@ struct xroute {
int
proto
;
};
struct
xroute_stream
;
struct
xroute
*
find_xroute
(
const
unsigned
char
*
prefix
,
unsigned
char
plen
);
void
flush_xroute
(
struct
xroute
*
xroute
);
int
add_xroute
(
unsigned
char
prefix
[
16
],
unsigned
char
plen
,
unsigned
short
metric
,
unsigned
int
ifindex
,
int
proto
);
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
);
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