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
fded50b1
Commit
fded50b1
authored
Jan 07, 2008
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Split off network-related functions into their own file.
parent
274d95c2
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
198 additions
and
139 deletions
+198
-139
Makefile
Makefile
+2
-2
babel.c
babel.c
+2
-105
babel.h
babel.h
+3
-32
message.c
message.c
+1
-0
neighbour.c
neighbour.c
+1
-0
network.c
network.c
+134
-0
network.h
network.h
+54
-0
route.c
route.c
+1
-0
No files found.
Makefile
View file @
fded50b1
...
...
@@ -6,10 +6,10 @@ DEFINES = $(PLATFORM_DEFINES)
CFLAGS
=
$(CDEBUGFLAGS)
$(DEFINES)
$(EXTRA_DEFINES)
SRCS
=
babel.c net.c kernel.c util.c source.c neighbour.c
\
SRCS
=
babel.c net.c kernel.c util.c
network.c
source.c neighbour.c
\
route.c xroute.c message.c request.c filter.c
OBJS
=
babel.o net.o kernel.o util.o source.o neighbour.o
\
OBJS
=
babel.o net.o kernel.o util.o
network.o
source.o neighbour.o
\
route.o xroute.o message.o request.o filter.o
babel
:
$(OBJS)
...
...
babel.c
View file @
fded50b1
...
...
@@ -42,6 +42,7 @@ THE SOFTWARE.
#include "util.h"
#include "net.h"
#include "kernel.h"
#include "network.h"
#include "source.h"
#include "neighbour.h"
#include "route.h"
...
...
@@ -52,7 +53,7 @@ THE SOFTWARE.
struct
timeval
now
;
unsigned
char
myid
[
16
];
unsigned
char
do_ipv4
=
0
;
int
do_ipv4
=
0
;
int
debug
=
0
;
static
int
maxmtu
;
...
...
@@ -84,8 +85,6 @@ static int kernel_routes_changed = 0;
static
volatile
sig_atomic_t
exiting
=
0
,
dumping
=
0
;
struct
network
*
add_network
(
char
*
ifname
,
int
ifindex
,
int
bufsize
,
int
wired
,
unsigned
int
cost
);
static
int
kernel_routes_callback
(
void
*
closure
);
static
void
init_signals
(
void
);
static
void
dump_tables
(
FILE
*
out
);
...
...
@@ -726,105 +725,3 @@ kernel_routes_callback(void *closure)
kernel_routes_changed
=
1
;
return
1
;
}
struct
network
*
add_network
(
char
*
ifname
,
int
ifindex
,
int
mtu
,
int
wired
,
unsigned
int
cost
)
{
void
*
p
;
char
ipv4
[
4
];
int
rc
;
if
(
numnets
>=
MAXNETS
)
{
fprintf
(
stderr
,
"Too many networks.
\n
"
);
return
NULL
;
}
memset
(
nets
+
numnets
,
0
,
sizeof
(
struct
network
));
nets
[
numnets
].
ifindex
=
ifindex
;
nets
[
numnets
].
ipv4
=
NULL
;
if
(
do_ipv4
)
{
rc
=
kernel_interface_ipv4
(
ifname
,
ifindex
,
ipv4
);
if
(
rc
>=
0
)
{
nets
[
numnets
].
ipv4
=
malloc
(
4
);
if
(
nets
[
numnets
].
ipv4
)
memcpy
(
nets
[
numnets
].
ipv4
,
ipv4
,
4
);
}
}
nets
[
numnets
].
wired
=
wired
;
nets
[
numnets
].
cost
=
cost
;
nets
[
numnets
].
activity_time
=
now
.
tv_sec
;
update_hello_interval
(
&
nets
[
numnets
]);
nets
[
numnets
].
bufsize
=
mtu
-
sizeof
(
packet_header
);
strncpy
(
nets
[
numnets
].
ifname
,
ifname
,
IF_NAMESIZE
);
p
=
malloc
(
nets
[
numnets
].
bufsize
);
if
(
p
==
NULL
)
{
perror
(
"malloc"
);
return
NULL
;
}
nets
[
numnets
].
sendbuf
=
p
;
nets
[
numnets
].
buffered
=
0
;
nets
[
numnets
].
bucket_time
=
now
.
tv_sec
;
nets
[
numnets
].
bucket
=
0
;
nets
[
numnets
].
hello_seqno
=
(
random
()
&
0xFFFF
);
numnets
++
;
return
&
nets
[
numnets
-
1
];
}
int
network_idle
(
struct
network
*
net
)
{
return
(
idle_hello_interval
>
0
&&
net
->
activity_time
<
now
.
tv_sec
-
idle_time
);
}
int
update_hello_interval
(
struct
network
*
net
)
{
int
rc
=
0
;
if
(
network_idle
(
net
))
{
if
(
net
->
hello_interval
!=
idle_hello_interval
)
{
net
->
hello_interval
=
idle_hello_interval
;
rc
=
1
;
}
}
else
if
(
net
->
wired
)
{
if
(
net
->
hello_interval
!=
wired_hello_interval
)
{
net
->
hello_interval
=
wired_hello_interval
;
rc
=
1
;
}
}
else
{
if
(
net
->
hello_interval
!=
wireless_hello_interval
)
{
net
->
hello_interval
=
wireless_hello_interval
;
rc
=
1
;
}
}
if
(
net
->
ihu_interval
!=
3
*
net
->
hello_interval
)
{
net
->
ihu_interval
=
3
*
net
->
hello_interval
;
rc
=
1
;
}
net
->
self_update_interval
=
MAX
(
15
+
net
->
hello_interval
/
2
,
net
->
hello_interval
);
return
rc
;
}
/* This should be no more than half the hello interval, so that hellos
aren't sent late. The result is in milliseconds. */
unsigned
int
jitter
(
struct
network
*
net
)
{
unsigned
interval
=
net
->
hello_interval
*
1000
;
return
(
interval
/
2
+
random
()
%
interval
)
/
4
;
}
unsigned
int
update_jitter
(
struct
network
*
net
,
int
urgent
)
{
unsigned
interval
=
net
->
hello_interval
*
1000
;
if
(
urgent
)
interval
=
MIN
(
interval
,
100
);
return
(
interval
/
2
+
random
()
%
interval
);
}
babel.h
View file @
fded50b1
...
...
@@ -60,38 +60,15 @@ THE SOFTWARE.
#endif
#endif
struct
network
{
unsigned
int
ifindex
;
int
wired
;
unsigned
short
cost
;
int
hello_time
;
int
self_update_time
;
int
update_time
;
int
ihu_time
;
char
ifname
[
IF_NAMESIZE
];
unsigned
char
*
ipv4
;
int
buffered
;
struct
timeval
flush_time
;
int
bufsize
;
unsigned
char
*
sendbuf
;
int
bucket_time
;
unsigned
int
bucket
;
int
activity_time
;
unsigned
short
hello_seqno
;
unsigned
int
hello_interval
;
unsigned
int
self_update_interval
;
unsigned
int
ihu_interval
;
};
extern
struct
timeval
now
;
extern
int
debug
;
extern
int
reboot_time
;
extern
int
do_ipv4
;
extern
int
wireless_hello_interval
,
wired_hello_interval
,
idle_hello_interval
;
extern
int
idle_time
;
extern
unsigned
char
myid
[
16
];
extern
struct
network
nets
[
MAXNETS
];
extern
int
numnets
;
extern
const
unsigned
char
zeroes
[
16
],
ones
[
16
];
extern
int
protocol_port
;
...
...
@@ -99,9 +76,3 @@ extern unsigned char protocol_group[16];
extern
int
protocol_socket
;
extern
int
kernel_socket
;
extern
int
max_request_hopcount
;
int
network_idle
(
struct
network
*
net
);
int
update_hello_interval
(
struct
network
*
net
);
unsigned
int
jitter
(
struct
network
*
net
);
unsigned
int
update_jitter
(
struct
network
*
net
,
int
urgent
);
message.c
View file @
fded50b1
...
...
@@ -30,6 +30,7 @@ THE SOFTWARE.
#include "babel.h"
#include "util.h"
#include "net.h"
#include "network.h"
#include "source.h"
#include "neighbour.h"
#include "route.h"
...
...
neighbour.c
View file @
fded50b1
...
...
@@ -28,6 +28,7 @@ THE SOFTWARE.
#include "babel.h"
#include "util.h"
#include "network.h"
#include "neighbour.h"
#include "source.h"
#include "route.h"
...
...
network.c
0 → 100644
View file @
fded50b1
/*
Copyright (c) 2007, 2008 by Juliusz Chroboczek
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "babel.h"
#include "util.h"
#include "kernel.h"
#include "network.h"
#include "neighbour.h"
#include "message.h"
struct
network
*
add_network
(
char
*
ifname
,
int
ifindex
,
int
mtu
,
int
wired
,
unsigned
int
cost
)
{
void
*
p
;
char
ipv4
[
4
];
int
rc
;
if
(
numnets
>=
MAXNETS
)
{
fprintf
(
stderr
,
"Too many networks.
\n
"
);
return
NULL
;
}
memset
(
nets
+
numnets
,
0
,
sizeof
(
struct
network
));
nets
[
numnets
].
ifindex
=
ifindex
;
nets
[
numnets
].
ipv4
=
NULL
;
if
(
do_ipv4
)
{
rc
=
kernel_interface_ipv4
(
ifname
,
ifindex
,
ipv4
);
if
(
rc
>=
0
)
{
nets
[
numnets
].
ipv4
=
malloc
(
4
);
if
(
nets
[
numnets
].
ipv4
)
memcpy
(
nets
[
numnets
].
ipv4
,
ipv4
,
4
);
}
}
nets
[
numnets
].
wired
=
wired
;
nets
[
numnets
].
cost
=
cost
;
nets
[
numnets
].
activity_time
=
now
.
tv_sec
;
update_hello_interval
(
&
nets
[
numnets
]);
nets
[
numnets
].
bufsize
=
mtu
-
sizeof
(
packet_header
);
strncpy
(
nets
[
numnets
].
ifname
,
ifname
,
IF_NAMESIZE
);
p
=
malloc
(
nets
[
numnets
].
bufsize
);
if
(
p
==
NULL
)
{
perror
(
"malloc"
);
return
NULL
;
}
nets
[
numnets
].
sendbuf
=
p
;
nets
[
numnets
].
buffered
=
0
;
nets
[
numnets
].
bucket_time
=
now
.
tv_sec
;
nets
[
numnets
].
bucket
=
0
;
nets
[
numnets
].
hello_seqno
=
(
random
()
&
0xFFFF
);
numnets
++
;
return
&
nets
[
numnets
-
1
];
}
int
network_idle
(
struct
network
*
net
)
{
return
(
idle_hello_interval
>
0
&&
net
->
activity_time
<
now
.
tv_sec
-
idle_time
);
}
int
update_hello_interval
(
struct
network
*
net
)
{
int
rc
=
0
;
if
(
network_idle
(
net
))
{
if
(
net
->
hello_interval
!=
idle_hello_interval
)
{
net
->
hello_interval
=
idle_hello_interval
;
rc
=
1
;
}
}
else
if
(
net
->
wired
)
{
if
(
net
->
hello_interval
!=
wired_hello_interval
)
{
net
->
hello_interval
=
wired_hello_interval
;
rc
=
1
;
}
}
else
{
if
(
net
->
hello_interval
!=
wireless_hello_interval
)
{
net
->
hello_interval
=
wireless_hello_interval
;
rc
=
1
;
}
}
if
(
net
->
ihu_interval
!=
3
*
net
->
hello_interval
)
{
net
->
ihu_interval
=
3
*
net
->
hello_interval
;
rc
=
1
;
}
net
->
self_update_interval
=
MAX
(
15
+
net
->
hello_interval
/
2
,
net
->
hello_interval
);
return
rc
;
}
/* This should be no more than half the hello interval, so that hellos
aren't sent late. The result is in milliseconds. */
unsigned
int
jitter
(
struct
network
*
net
)
{
unsigned
interval
=
net
->
hello_interval
*
1000
;
return
(
interval
/
2
+
random
()
%
interval
)
/
4
;
}
unsigned
int
update_jitter
(
struct
network
*
net
,
int
urgent
)
{
unsigned
interval
=
net
->
hello_interval
*
1000
;
if
(
urgent
)
interval
=
MIN
(
interval
,
100
);
return
(
interval
/
2
+
random
()
%
interval
);
}
network.h
0 → 100644
View file @
fded50b1
/*
Copyright (c) 2007, 2008 by Juliusz Chroboczek
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
struct
network
{
unsigned
int
ifindex
;
int
wired
;
unsigned
short
cost
;
int
hello_time
;
int
self_update_time
;
int
update_time
;
int
ihu_time
;
char
ifname
[
IF_NAMESIZE
];
unsigned
char
*
ipv4
;
int
buffered
;
struct
timeval
flush_time
;
int
bufsize
;
unsigned
char
*
sendbuf
;
int
bucket_time
;
unsigned
int
bucket
;
int
activity_time
;
unsigned
short
hello_seqno
;
unsigned
int
hello_interval
;
unsigned
int
self_update_interval
;
unsigned
int
ihu_interval
;
};
extern
struct
network
nets
[
MAXNETS
];
extern
int
numnets
;
struct
network
*
add_network
(
char
*
ifname
,
int
ifindex
,
int
mtu
,
int
wired
,
unsigned
int
cost
);
int
network_idle
(
struct
network
*
net
);
int
update_hello_interval
(
struct
network
*
net
);
unsigned
int
jitter
(
struct
network
*
net
);
unsigned
int
update_jitter
(
struct
network
*
net
,
int
urgent
);
route.c
View file @
fded50b1
...
...
@@ -29,6 +29,7 @@ THE SOFTWARE.
#include "babel.h"
#include "util.h"
#include "kernel.h"
#include "network.h"
#include "source.h"
#include "neighbour.h"
#include "route.h"
...
...
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