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
aaa2c581
Commit
aaa2c581
authored
Apr 11, 2013
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'multiple-local-interfaces'
parents
21fff6b7
f0c4ea01
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
93 additions
and
65 deletions
+93
-65
babeld.c
babeld.c
+31
-21
babeld.h
babeld.h
+0
-1
local.c
local.c
+53
-40
local.h
local.h
+9
-3
No files found.
babeld.c
View file @
aaa2c581
...
...
@@ -88,9 +88,6 @@ struct timeval check_neighbours_timeout, check_interfaces_timeout;
static
volatile
sig_atomic_t
exiting
=
0
,
dumping
=
0
,
reopening
=
0
;
int
local_server_socket
=
-
1
,
local_socket
=
-
1
;
int
local_server_port
=
-
1
;
static
int
kernel_routes_callback
(
int
changed
,
void
*
closure
);
static
void
init_signals
(
void
);
static
void
dump_tables
(
FILE
*
out
);
...
...
@@ -568,13 +565,15 @@ main(int argc, char **argv)
maxfd
=
MAX
(
maxfd
,
kernel_socket
);
}
#ifndef NO_LOCAL_INTERFACE
if
(
local_socket
>=
0
)
{
FD_SET
(
local_socket
,
&
readfds
);
maxfd
=
MAX
(
maxfd
,
local_socket
);
}
else
if
(
local_server_socket
>=
0
)
{
if
(
local_server_socket
>=
0
&&
num_local_sockets
<
MAX_LOCAL_SOCKETS
)
{
FD_SET
(
local_server_socket
,
&
readfds
);
maxfd
=
MAX
(
maxfd
,
local_server_socket
);
}
for
(
i
=
0
;
i
<
num_local_sockets
;
i
++
)
{
FD_SET
(
local_sockets
[
i
],
&
readfds
);
maxfd
=
MAX
(
maxfd
,
local_sockets
[
i
]);
}
#endif
rc
=
select
(
maxfd
+
1
,
&
readfds
,
NULL
,
NULL
,
&
tv
);
if
(
rc
<
0
)
{
...
...
@@ -622,27 +621,38 @@ main(int argc, char **argv)
#ifndef NO_LOCAL_INTERFACE
if
(
local_server_socket
>=
0
&&
FD_ISSET
(
local_server_socket
,
&
readfds
))
{
if
(
local_socket
>=
0
)
{
close
(
local_socket
);
local_socket
=
-
1
;
}
local_socket
=
accept
(
local_server_socket
,
NULL
,
NULL
);
if
(
local_socket
<
0
)
{
int
s
;
s
=
accept
(
local_server_socket
,
NULL
,
NULL
);
if
(
s
<
0
)
{
if
(
errno
!=
EINTR
&&
errno
!=
EAGAIN
)
perror
(
"accept(local_server_socket)"
);
}
else
if
(
num_local_sockets
>=
MAX_LOCAL_SOCKETS
)
{
/* This should never happen, since we don't select for
the server socket in this case. But I'm paranoid. */
fprintf
(
stderr
,
"Internal error: too many local sockets.
\n
"
);
close
(
s
);
}
else
{
local_notify_all
();
local_sockets
[
num_local_sockets
++
]
=
s
;
local_notify_all_1
(
s
);
}
}
if
(
local_socket
>=
0
&&
FD_ISSET
(
local_socket
,
&
readfds
))
{
rc
=
local_read
(
local_socket
);
i
=
0
;
while
(
i
<
num_local_sockets
)
{
if
(
FD_ISSET
(
local_sockets
[
i
],
&
readfds
))
{
rc
=
local_read
(
local_sockets
[
i
]);
if
(
rc
<=
0
)
{
if
(
rc
<
0
)
if
(
rc
<
0
)
{
if
(
errno
==
EINTR
)
continue
;
perror
(
"read(local_socket)"
);
close
(
local_socket
);
local_socket
=
-
1
;
}
close
(
local_sockets
[
i
]);
local_sockets
[
i
]
=
local_sockets
[
--
num_local_sockets
];
continue
;
}
}
i
++
;
}
#endif
...
...
babeld.h
View file @
aaa2c581
...
...
@@ -87,7 +87,6 @@ extern int default_wireless_hello_interval, default_wired_hello_interval;
extern
int
resend_delay
;
extern
int
link_detect
;
extern
int
all_wireless
;
extern
int
local_socket
;
extern
unsigned
char
myid
[
8
];
...
...
local.c
View file @
aaa2c581
...
...
@@ -41,6 +41,10 @@ int dummy;
#else
int
local_server_socket
=
-
1
,
local_sockets
[
MAX_LOCAL_SOCKETS
];
int
num_local_sockets
=
0
;
int
local_server_port
=
-
1
;
int
local_read
(
int
s
)
{
...
...
@@ -88,15 +92,12 @@ write_timeout(int fd, const void *buf, int len)
}
void
local_notify_self
(
)
local_notify_self
_1
(
int
s
)
{
char
buf
[
512
];
char
host
[
64
];
int
rc
;
if
(
local_socket
<
0
)
return
;
rc
=
gethostname
(
host
,
64
);
if
(
rc
<
0
)
...
...
@@ -108,13 +109,13 @@ local_notify_self()
if
(
rc
<
0
||
rc
>=
512
)
goto
fail
;
rc
=
write_timeout
(
local_socket
,
buf
,
rc
);
rc
=
write_timeout
(
s
,
buf
,
rc
);
if
(
rc
<
0
)
goto
fail
;
return
;
fail:
shutdown
(
local_socket
,
1
);
shutdown
(
s
,
1
);
return
;
}
...
...
@@ -129,15 +130,12 @@ local_kind(int kind)
}
}
void
local_notify_neighbour
(
struct
neighbour
*
neigh
,
int
kind
)
static
void
local_notify_neighbour
_1
(
int
s
,
struct
neighbour
*
neigh
,
int
kind
)
{
char
buf
[
512
];
int
rc
;
if
(
local_socket
<
0
)
return
;
rc
=
snprintf
(
buf
,
512
,
"%s neighbour %lx address %s "
"if %s reach %04x rxcost %d txcost %d cost %d
\n
"
,
...
...
@@ -155,25 +153,30 @@ local_notify_neighbour(struct neighbour *neigh, int kind)
if
(
rc
<
0
||
rc
>=
512
)
goto
fail
;
rc
=
write_timeout
(
local_socket
,
buf
,
rc
);
rc
=
write_timeout
(
s
,
buf
,
rc
);
if
(
rc
<
0
)
goto
fail
;
return
;
fail:
shutdown
(
local_socket
,
1
);
shutdown
(
s
,
1
);
return
;
}
void
local_notify_xroute
(
struct
xroute
*
xroute
,
int
kind
)
local_notify_neighbour
(
struct
neighbour
*
neigh
,
int
kind
)
{
int
i
;
for
(
i
=
0
;
i
<
num_local_sockets
;
i
++
)
local_notify_neighbour_1
(
local_sockets
[
i
],
neigh
,
kind
);
}
static
void
local_notify_xroute_1
(
int
s
,
struct
xroute
*
xroute
,
int
kind
)
{
char
buf
[
512
];
int
rc
;
if
(
local_socket
<
0
)
return
;
rc
=
snprintf
(
buf
,
512
,
"%s xroute %s prefix %s metric %d
\n
"
,
local_kind
(
kind
),
format_prefix
(
xroute
->
prefix
,
xroute
->
plen
),
...
...
@@ -183,25 +186,30 @@ local_notify_xroute(struct xroute *xroute, int kind)
if
(
rc
<
0
||
rc
>=
512
)
goto
fail
;
rc
=
write_timeout
(
local_socket
,
buf
,
rc
);
rc
=
write_timeout
(
s
,
buf
,
rc
);
if
(
rc
<
0
)
goto
fail
;
return
;
fail:
shutdown
(
local_socket
,
1
);
shutdown
(
s
,
1
);
return
;
}
void
local_notify_route
(
struct
babel_route
*
route
,
int
kind
)
local_notify_xroute
(
struct
xroute
*
xroute
,
int
kind
)
{
int
i
;
for
(
i
=
0
;
i
<
num_local_sockets
;
i
++
)
local_notify_xroute_1
(
local_sockets
[
i
],
xroute
,
kind
);
}
static
void
local_notify_route_1
(
int
s
,
struct
babel_route
*
route
,
int
kind
)
{
char
buf
[
512
];
int
rc
;
if
(
local_socket
<
0
)
return
;
rc
=
snprintf
(
buf
,
512
,
"%s route %s-%lx prefix %s installed %s "
"id %s metric %d refmetric %d via %s if %s
\n
"
,
...
...
@@ -218,55 +226,60 @@ local_notify_route(struct babel_route *route, int kind)
if
(
rc
<
0
||
rc
>=
512
)
goto
fail
;
rc
=
write_timeout
(
local_socket
,
buf
,
rc
);
rc
=
write_timeout
(
s
,
buf
,
rc
);
if
(
rc
<
0
)
goto
fail
;
return
;
fail:
shutdown
(
local_socket
,
1
);
shutdown
(
s
,
1
);
return
;
}
void
local_notify_route
(
struct
babel_route
*
route
,
int
kind
)
{
int
i
;
for
(
i
=
0
;
i
<
num_local_sockets
;
i
++
)
local_notify_route_1
(
local_sockets
[
i
],
route
,
kind
);
}
static
void
local_notify_xroute_callback
(
struct
xroute
*
xroute
,
void
*
closure
)
{
local_notify_xroute
(
xroute
,
LOCAL_ADD
);
local_notify_xroute
_1
(
*
(
int
*
)
closure
,
xroute
,
LOCAL_ADD
);
}
static
void
local_notify_route_callback
(
struct
babel_route
*
route
,
void
*
closure
)
{
local_notify_route
(
route
,
LOCAL_ADD
);
local_notify_route
_1
(
*
(
int
*
)
closure
,
route
,
LOCAL_ADD
);
}
void
local_notify_all
(
)
local_notify_all
_1
(
int
s
)
{
int
rc
;
struct
neighbour
*
neigh
;
const
char
*
header
=
"BABEL 0.0
\n
"
;
if
(
local_socket
<
0
)
return
;
rc
=
write_timeout
(
local_socket
,
header
,
strlen
(
header
));
rc
=
write_timeout
(
s
,
header
,
strlen
(
header
));
if
(
rc
<
0
)
goto
fail
;
local_notify_self
(
);
local_notify_self
_1
(
s
);
FOR_ALL_NEIGHBOURS
(
neigh
)
{
local_notify_neighbour
(
neigh
,
LOCAL_ADD
);
local_notify_neighbour
_1
(
s
,
neigh
,
LOCAL_ADD
);
}
for_all_xroutes
(
local_notify_xroute_callback
,
NULL
);
for_all_routes
(
local_notify_route_callback
,
NULL
);
rc
=
write_timeout
(
local_socket
,
"done
\n
"
,
5
);
for_all_xroutes
(
local_notify_xroute_callback
,
&
s
);
for_all_routes
(
local_notify_route_callback
,
&
s
);
rc
=
write_timeout
(
s
,
"done
\n
"
,
5
);
if
(
rc
<
0
)
goto
fail
;
return
;
fail:
shutdown
(
local_socket
,
1
);
shutdown
(
s
,
1
);
return
;
}
...
...
local.h
View file @
aaa2c581
...
...
@@ -30,16 +30,22 @@ struct xroute;
#ifndef NO_LOCAL_INTERFACE
#ifndef MAX_LOCAL_SOCKETS
#define MAX_LOCAL_SOCKETS 4
#endif
extern
int
local_server_socket
,
local_sockets
[
MAX_LOCAL_SOCKETS
];
extern
int
num_local_sockets
;
extern
int
local_server_port
;
int
local_read
(
int
s
);
void
local_notify_self
(
void
);
void
local_notify_neighbour
(
struct
neighbour
*
neigh
,
int
kind
);
void
local_notify_xroute
(
struct
xroute
*
xroute
,
int
kind
);
void
local_notify_route
(
struct
babel_route
*
route
,
int
kind
);
void
local_notify_all
(
void
);
void
local_notify_all
_1
(
int
s
);
#else
#define local_notify_self() do {} while(0)
#define local_notify_neighbour(n, k) do {} while(0)
#define local_notify_xroute(x, k) do {} while(0)
#define local_notify_route(r, k) do {} while(0)
...
...
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