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
b5290af9
Commit
b5290af9
authored
Jun 12, 2013
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for default parameters to config parser.
parent
61789872
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
61 additions
and
19 deletions
+61
-19
babeld.c
babeld.c
+1
-1
babeld.man
babeld.man
+8
-1
configuration.c
configuration.c
+50
-15
configuration.h
configuration.h
+2
-0
interface.c
interface.c
+0
-2
No files found.
babeld.c
View file @
b5290af9
...
...
@@ -369,7 +369,7 @@ main(int argc, char **argv)
}
for
(
i
=
optind
;
i
<
argc
;
i
++
)
{
vrc
=
add_interface
(
argv
[
i
],
NULL
);
vrc
=
add_interface
(
argv
[
i
],
default_interface_conf
);
if
(
vrc
==
NULL
)
goto
fail
;
}
...
...
babeld.man
View file @
b5290af9
...
...
@@ -152,9 +152,16 @@ An interface is configured by a single line with the following format:
.I name
.RI [ parameter ...]
.PP
.I Name
where
.I name
is the name of the interface (something like
.BR eth0 ).
The default values for all interfaces can be changed by
a line of the form
.IP
.B default
.RI [ parameter ...]
.PP
Each
.I parameter
...
...
configuration.c
View file @
b5290af9
...
...
@@ -40,6 +40,7 @@ THE SOFTWARE.
struct
filter
*
input_filters
=
NULL
;
struct
filter
*
output_filters
=
NULL
;
struct
filter
*
redistribute_filters
=
NULL
;
struct
interface_conf
*
default_interface_conf
=
NULL
;
struct
interface_conf
*
interface_confs
=
NULL
;
/* This file implements a recursive descent parser with one character
...
...
@@ -375,24 +376,17 @@ parse_filter(int c, gnc_t gnc, void *closure)
}
static
struct
interface_conf
*
parse_ifconf
(
int
c
,
gnc_t
gnc
,
void
*
closure
)
parse_anonymous_ifconf
(
int
c
,
gnc_t
gnc
,
void
*
closure
,
struct
interface_conf
*
if_conf
)
{
char
*
token
;
struct
interface_conf
*
if_conf
;
if
(
if_conf
==
NULL
)
{
if_conf
=
calloc
(
1
,
sizeof
(
struct
interface_conf
));
if
(
if_conf
==
NULL
)
goto
error
;
c
=
skip_whitespace
(
c
,
gnc
,
closure
);
if
(
c
<
-
1
||
c
==
'\n'
||
c
==
'#'
)
goto
error
;
c
=
getstring
(
c
,
&
token
,
gnc
,
closure
);
if
(
c
<
-
1
||
token
==
NULL
)
goto
error
;
if_conf
->
ifname
=
token
;
}
while
(
c
>=
0
&&
c
!=
'\n'
)
{
c
=
skip_whitespace
(
c
,
gnc
,
closure
);
...
...
@@ -481,6 +475,33 @@ parse_ifconf(int c, gnc_t gnc, void *closure)
return
NULL
;
}
static
struct
interface_conf
*
parse_ifconf
(
int
c
,
gnc_t
gnc
,
void
*
closure
)
{
char
*
token
;
struct
interface_conf
*
if_conf
;
if_conf
=
calloc
(
1
,
sizeof
(
struct
interface_conf
));
if
(
if_conf
==
NULL
)
goto
error
;
c
=
skip_whitespace
(
c
,
gnc
,
closure
);
if
(
c
<
-
1
||
c
==
'\n'
||
c
==
'#'
)
goto
error
;
c
=
getstring
(
c
,
&
token
,
gnc
,
closure
);
if
(
c
<
-
1
||
token
==
NULL
)
goto
error
;
if_conf
->
ifname
=
token
;
return
parse_anonymous_ifconf
(
c
,
gnc
,
closure
,
if_conf
);
error:
free
(
if_conf
);
return
NULL
;
}
static
void
add_filter
(
struct
filter
*
filter
,
struct
filter
**
filters
)
{
...
...
@@ -591,6 +612,18 @@ parse_config(gnc_t gnc, void *closure)
if
(
if_conf
==
NULL
)
return
-
1
;
add_ifconf
(
if_conf
,
&
interface_confs
);
}
else
if
(
strcmp
(
token
,
"default"
)
==
0
)
{
struct
interface_conf
*
if_conf
;
if_conf
=
parse_anonymous_ifconf
(
c
,
gnc
,
closure
,
NULL
);
if
(
if_conf
==
NULL
)
return
-
1
;
if
(
default_interface_conf
==
NULL
)
default_interface_conf
=
if_conf
;
else
{
merge_ifconf
(
default_interface_conf
,
if_conf
,
default_interface_conf
);
free
(
if_conf
);
}
}
else
{
return
-
1
;
}
...
...
@@ -789,6 +822,8 @@ finalise_config()
if_conf
=
interface_confs
;
interface_confs
=
interface_confs
->
next
;
if_conf
->
next
=
NULL
;
if
(
default_interface_conf
)
merge_ifconf
(
if_conf
,
if_conf
,
default_interface_conf
);
vrc
=
add_interface
(
if_conf
->
ifname
,
if_conf
);
if
(
vrc
==
NULL
)
{
fprintf
(
stderr
,
"Couldn't add interface %s.
\n
"
,
if_conf
->
ifname
);
...
...
configuration.h
View file @
b5290af9
...
...
@@ -34,6 +34,8 @@ struct filter {
struct
filter
*
next
;
};
extern
struct
interface_conf
*
default_interface_conf
;
int
parse_config_from_file
(
const
char
*
filename
,
int
*
line_return
);
int
parse_config_from_string
(
char
*
string
);
void
renumber_filters
(
void
);
...
...
interface.c
View file @
b5290af9
...
...
@@ -62,8 +62,6 @@ add_interface(char *ifname, struct interface_conf *if_conf)
{
struct
interface
*
ifp
;
assert
(
!
if_conf
||
strcmp
(
ifname
,
if_conf
->
ifname
)
==
0
);
FOR_ALL_INTERFACES
(
ifp
)
{
if
(
strcmp
(
ifp
->
name
,
ifname
)
==
0
)
{
assert
(
if_conf
==
NULL
);
...
...
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