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
1ef8b276
Commit
1ef8b276
authored
Jun 05, 2010
by
dermiste
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixes and cleanup
parent
6e7c6600
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
104 additions
and
99 deletions
+104
-99
babeld.c
babeld.c
+6
-21
babeld.h
babeld.h
+0
-8
kernel.c
kernel.c
+30
-0
kernel.h
kernel.h
+1
-0
kernel_socket.c
kernel_socket.c
+67
-70
No files found.
babeld.c
View file @
1ef8b276
/*
Copyright (c) 2007, 2008 by Juliusz Chroboczek
Copyright (c) 2010 by Vincent Gross
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
...
...
@@ -102,7 +103,7 @@ int
main
(
int
argc
,
char
**
argv
)
{
struct
sockaddr_in6
sin6
;
int
rc
,
fd
,
rfd
,
i
,
opt
;
int
rc
,
fd
,
i
,
opt
;
time_t
expiry_time
,
source_expiry_time
,
kernel_dump_time
;
char
*
config_file
=
NULL
;
void
*
vrc
;
...
...
@@ -111,15 +112,8 @@ main(int argc, char **argv)
gettime
(
&
now
);
rfd
=
open
(
RND_DEV
,
O_RDONLY
);
if
(
rfd
<
0
)
{
perror
(
"open(random)"
);
}
else
{
rc
=
read
(
rfd
,
&
seed
,
sizeof
(
unsigned
int
));
if
(
rc
<
sizeof
(
unsigned
int
))
{
perror
(
"read(random)"
);
}
}
if
(
read_random_bytes
(
&
seed
,
sizeof
(
seed
))
==
-
1
)
perror
(
"read_random_bytes(seed, sizeof(seed))"
);
seed
^=
(
now
.
tv_sec
^
now
.
tv_usec
);
srandom
(
seed
);
...
...
@@ -402,23 +396,14 @@ main(int argc, char **argv)
fprintf
(
stderr
,
"Warning: couldn't find router id -- using random value.
\n
"
);
if
(
rfd
>=
0
)
{
rc
=
read
(
rfd
,
myid
,
8
);
if
(
rc
<
8
)
{
if
(
read_random_bytes
(
myid
,
8
)
==
-
1
)
{
perror
(
"read(random)"
);
goto
fail
;
}
}
else
{
goto
fail
;
}
/* Clear group and global bits */
myid
[
0
]
&=
~
3
;
have_id:
if
(
rfd
>=
0
)
close
(
rfd
);
rfd
=
-
1
;
reboot_time
=
now
.
tv_sec
;
myseqno
=
(
random
()
&
0xFFFF
);
...
...
babeld.h
View file @
1ef8b276
...
...
@@ -80,14 +80,6 @@ THE SOFTWARE.
#endif
#endif
#if defined(__linux)
#define RND_DEV "/dev/urandom"
#elif defined(__OpenBSD__)
#define RND_DEV "/dev/arandom"
#else
#error "don't know which random device to use"
#endif
extern
struct
timeval
now
;
extern
int
debug
;
extern
time_t
reboot_time
;
...
...
kernel.c
View file @
1ef8b276
...
...
@@ -76,3 +76,33 @@ gettime(struct timeval *tv)
previous
=
tv
->
tv_sec
;
return
rc
;
}
#if defined(__linux)
#define RND_DEV "/dev/urandom"
#elif defined (__OpenBSD__)
#define RND_DEV "/dev/arandom"
#endif
int
read_random_bytes
(
void
*
buf
,
size_t
len
)
{
int
rfd
;
int
rc
;
#ifdef RND_DEV
rfd
=
open
(
RND_DEV
,
O_RDONLY
);
if
(
rfd
<
0
)
{
rc
=
-
1
;
}
else
{
rc
=
read
(
rfd
,
buf
,
len
);
if
(
rc
<
len
)
rc
=
-
1
;
close
(
rfd
);
}
#else
rc
=
-
1
;
errno
=
ENOSYS
;
#endif
return
rc
;
}
kernel.h
View file @
1ef8b276
...
...
@@ -63,3 +63,4 @@ int kernel_addresses(char *ifname, int ifindex, int ll,
struct
kernel_route
*
routes
,
int
maxroutes
);
int
if_eui64
(
char
*
ifname
,
int
ifindex
,
unsigned
char
*
eui
);
int
gettime
(
struct
timeval
*
tv
);
int
read_random_bytes
(
void
*
buf
,
size_t
len
);
kernel_socket.c
View file @
1ef8b276
/*
Copyright (c) 2007 by Grégoire Henry
Copyright (c) 2008, 2009 by Juliusz Chroboczek
Copyright (c) 2010 by Vincent Gross
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
...
...
@@ -133,7 +134,7 @@ plen2mask(int n, struct in6_addr *dest)
int
kernel_setup
(
int
setup
)
{
int
rc
;
int
rc
=
0
;
int
forwarding
=
1
;
int
accept_redirects
=
0
;
int
mib
[
4
];
...
...
@@ -149,31 +150,26 @@ kernel_setup(int setup)
if
(
setup
)
rc
=
sysctl
(
mib
,
4
,
&
old_forwarding
,
&
datasize
,
&
forwarding
,
datasize
);
else
if
(
0
<=
old_forwarding
)
else
if
(
old_forwarding
>=
0
)
rc
=
sysctl
(
mib
,
4
,
NULL
,
NULL
,
&
old_forwarding
,
datasize
);
if
(
rc
==
-
1
)
{
if
(
errno
==
ENOMEM
)
perror
(
"Couldn't read forwarding knob."
);
else
perror
(
"Couldn't write forwarding knob."
);
perror
(
"Couldn't tweak forwarding knob."
);
return
-
1
;
}
rc
=
0
;
mib
[
2
]
=
IPPROTO_ICMPV6
;
mib
[
3
]
=
ICMPV6CTL_REDIRACCEPT
;
datasize
=
sizeof
(
old_accept_redirects
);
if
(
setup
)
rc
=
sysctl
(
mib
,
4
,
&
old_accept_redirects
,
&
datasize
,
&
accept_redirects
,
datasize
);
else
if
(
0
<=
old_accept_redirects
)
else
if
(
old_accept_redirects
>=
0
)
rc
=
sysctl
(
mib
,
4
,
NULL
,
NULL
,
&
old_accept_redirects
,
datasize
);
if
(
rc
==
-
1
)
{
if
(
errno
==
ENOMEM
)
perror
(
"Couldn't read accept_redirects knob."
);
else
perror
(
"Couldn't write accept_redirects knob."
);
perror
(
"Couldn't tweak accept_redirects knob."
);
return
-
1
;
}
return
1
;
...
...
@@ -314,11 +310,10 @@ kernel_route(int operation, const unsigned char *dest, unsigned short plen,
const
unsigned
char
*
newgate
,
int
newifindex
,
unsigned
int
newmetric
)
{
unsigned
char
msg
[
512
];
struct
rt_msghdr
*
rtm
;
struct
sockaddr_in6
*
sin6
;
struct
sockaddr_in
*
sin
4
;
struct
sockaddr_in
*
sin
;
int
rc
,
len
,
ipv4
;
char
local6
[
1
][
1
][
16
]
=
IN6ADDR_LOOPBACK_INIT
;
...
...
@@ -375,12 +370,12 @@ kernel_route(int operation, const unsigned char *dest, unsigned short plen,
rtm
->
rtm_index
=
ifindex
;
rtm
->
rtm_flags
=
RTF_UP
|
RTF_PROTO2
;
if
(
plen
==
128
)
rtm
->
rtm_flags
|=
RTF_HOST
;
/* if(memcmp(nexthop->id, dest, 16) == 0) { */
/* rtm -> rtm_flags |= RTF_LLINFO; */
/* rtm -> rtm_flags |= RTF_CLONING; */
/* } else { */
/* if(memcmp(nexthop->id, dest, 16) == 0) { */
/* rtm -> rtm_flags |= RTF_LLINFO; */
/* rtm -> rtm_flags |= RTF_CLONING; */
/* } else { */
rtm
->
rtm_flags
|=
RTF_GATEWAY
;
/* } */
/* } */
if
(
metric
==
KERNEL_INFINITY
)
{
rtm
->
rtm_flags
|=
RTF_BLACKHOLE
;
if
(
ifindex_lo
<
0
)
{
...
...
@@ -412,26 +407,27 @@ kernel_route(int operation, const unsigned char *dest, unsigned short plen,
#define get_sin6_addr(dst,src) \
do { memcpy((dst), (src), 16); } while (0)
/* KAME ipv6 stack does not support IPv4 mapped IPv6, so we have to */
/* KAME ipv6 stack does not support IPv4 mapped IPv6, so we have to
* duplicate the codepath */
if
(
ipv4
)
{
sin4
=
(
struct
sockaddr_in
*
)
msg
;
sin
=
(
struct
sockaddr_in
*
)
msg
;
/* destination */
push_sockaddr_in
(
sin
4
,
sizeof
(
*
rtm
));
get_sin_addr
(
&
(
sin
4
->
sin_addr
),
dest
);
push_sockaddr_in
(
sin
,
sizeof
(
*
rtm
));
get_sin_addr
(
&
(
sin
->
sin_addr
),
dest
);
/* gateway */
push_sockaddr_in
(
sin4
,
ROUNDUP
(
sin4
->
sin_len
));
push_sockaddr_in
(
sin
,
ROUNDUP
(
sin
->
sin_len
));
if
(
metric
==
KERNEL_INFINITY
)
get_sin_addr
(
&
(
sin
4
->
sin_addr
),
**
local4
);
get_sin_addr
(
&
(
sin
->
sin_addr
),
**
local4
);
else
get_sin_addr
(
&
(
sin
4
->
sin_addr
),
gate
);
get_sin_addr
(
&
(
sin
->
sin_addr
),
gate
);
/* netmask */
if
((
rtm
->
rtm_addrs
|
RTA_NETMASK
)
!=
0
)
{
struct
in6_addr
tmp_sin6_addr
;
push_sockaddr_in
(
sin4
,
ROUNDUP
(
sin4
->
sin_len
));
push_sockaddr_in
(
sin
,
ROUNDUP
(
sin
->
sin_len
));
plen2mask
(
plen
,
&
tmp_sin6_addr
);
get_sin_addr
(
&
(
sin4
->
sin_addr
),
(
char
*
)
&
tmp_sin6_addr
);
get_sin_addr
(
&
(
sin
->
sin_addr
),
(
char
*
)
&
tmp_sin6_addr
);
}
len
=
(
char
*
)
sin
4
+
ROUNDUP
(
sin4
->
sin_len
)
-
(
char
*
)
msg
;
len
=
(
char
*
)
sin
+
ROUNDUP
(
sin
->
sin_len
)
-
(
char
*
)
msg
;
}
else
{
sin6
=
(
struct
sockaddr_in6
*
)
msg
;
/* destination */
...
...
@@ -666,9 +662,10 @@ kernel_addresses(char *ifname, int ifindex, int ll,
if
(
!!
ll
!=
!!
IN6_IS_ADDR_LINKLOCAL
(
&
sin6
->
sin6_addr
))
goto
next
;
memcpy
(
routes
[
i
].
prefix
,
&
sin6
->
sin6_addr
,
16
);
if
(
ll
)
/* This a perfect example of counter-productive optimisation :
if
(
ll
)
/* This a perfect example of counter-productive optimisation :
KAME encodes interface index onto bytes 2 and 3, so we have to
reset those bytes to 0 before passing them to babel
. */
reset those bytes to 0 before passing them to babeld
. */
memset
(
routes
[
i
].
prefix
+
2
,
0
,
2
);
routes
[
i
].
plen
=
128
;
routes
[
i
].
metric
=
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