Commit a56c7e8e authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Add global options to configuration parser.

This also adds options protocol-port and protocol-group.
parent b5290af9
...@@ -145,8 +145,26 @@ either an interface or a filtering rule. Blank lines are ignored. Comments ...@@ -145,8 +145,26 @@ either an interface or a filtering rule. Blank lines are ignored. Comments
are introduced with an octothorp are introduced with an octothorp
.RB `` # '' .RB `` # ''
and terminate at the end of the line. and terminate at the end of the line.
.SS Global options
Global options are set by a line with the following format:
.IP
.B option
.IR value ...
.PP
where each
.I value
can be one of the following:
.TP
.BI protocol-group " group"
This specifies the link-local multicast address to be used by the
protocol, and is equivalent to the command-line option
.BR \-m .
.TP
.BI protocol-port " port"
This specifies the UDP port number to be used by the protocol, and is equivalent to the command-line option
.BR \-p .
.SS Interface configuration .SS Interface configuration
An interface is configured by a single line with the following format: An interface is configured by a line with the following format:
.IP .IP
.B interface .B interface
.I name .I name
......
...@@ -566,6 +566,45 @@ add_ifconf(struct interface_conf *if_conf, struct interface_conf **if_confs) ...@@ -566,6 +566,45 @@ add_ifconf(struct interface_conf *if_conf, struct interface_conf **if_confs)
} }
} }
static int
parse_option(int c, gnc_t gnc, void *closure)
{
char *token;
while(c >= 0 && c != '\n') {
c = skip_whitespace(c, gnc, closure);
if(c == '\n' || c == '#') {
c = skip_to_eol(c, gnc, closure);
break;
}
c = getword(c, &token, gnc, closure);
if(c < -1)
goto error;
if(strcmp(token, "protocol-port") == 0) {
int p;
c = getint(c, &p, gnc, closure);
if(c < -1 || p <= 0 || p >= 0xFFFF)
goto error;
protocol_port = p;
} else if(strcmp(token, "protocol-group") == 0) {
unsigned char *group = NULL;
c = getip(c, &group, NULL, gnc, closure);
if(c < -1)
goto error;
memcpy(protocol_group, group, 16);
free(group);
} else {
goto error;
}
free(token);
}
return 1;
error:
return -1;
}
static int static int
parse_config(gnc_t gnc, void *closure) parse_config(gnc_t gnc, void *closure)
{ {
...@@ -624,6 +663,11 @@ parse_config(gnc_t gnc, void *closure) ...@@ -624,6 +663,11 @@ parse_config(gnc_t gnc, void *closure)
if_conf, default_interface_conf); if_conf, default_interface_conf);
free(if_conf); free(if_conf);
} }
} else if(strcmp(token, "option") == 0) {
int rc;
rc = parse_option(c, gnc, closure);
if(rc < 0)
return -1;
} else { } else {
return -1; return -1;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment