mirror of
https://github.com/neocturne/fastd.git
synced 2025-05-14 12:25:07 +02:00
Add keypair config
This commit is contained in:
parent
0b61ebf351
commit
6ce20e2bb6
5 changed files with 31 additions and 8 deletions
20
src/config.c
20
src/config.c
|
@ -65,6 +65,7 @@ static void default_config(fastd_config *conf) {
|
||||||
conf->mtu = 1500;
|
conf->mtu = 1500;
|
||||||
conf->mode = MODE_TAP;
|
conf->mode = MODE_TAP;
|
||||||
conf->protocol = &fastd_protocol_null;
|
conf->protocol = &fastd_protocol_null;
|
||||||
|
conf->secret = NULL;
|
||||||
conf->peers = NULL;
|
conf->peers = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,16 +91,22 @@ static bool config_match(const char *opt, ...) {
|
||||||
static void fastd_read_config(fastd_context *ctx, fastd_config *conf, const char *filename) {
|
static void fastd_read_config(fastd_context *ctx, fastd_config *conf, const char *filename) {
|
||||||
yyscan_t scanner;
|
yyscan_t scanner;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
bool use_stdin = !strcmp(filename, "-");
|
||||||
|
|
||||||
|
if (use_stdin)
|
||||||
|
file = stdin;
|
||||||
|
else
|
||||||
|
file = fopen(filename, "r");
|
||||||
|
|
||||||
file = fopen(filename, "r");
|
|
||||||
fastd_config_lex_init(&scanner);
|
fastd_config_lex_init(&scanner);
|
||||||
|
|
||||||
fastd_config_set_in(file, scanner);
|
fastd_config_set_in(file, scanner);
|
||||||
|
|
||||||
fastd_config_parse(ctx, conf, scanner);
|
fastd_config_parse(ctx, conf, scanner);
|
||||||
|
|
||||||
fastd_config_lex_destroy(scanner);
|
fastd_config_lex_destroy(scanner);
|
||||||
fclose(file);
|
|
||||||
|
if (!use_stdin)
|
||||||
|
fclose(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define IF_OPTION(args...) if(config_match(argv[i], args, NULL) && (++i))
|
#define IF_OPTION(args...) if(config_match(argv[i], args, NULL) && (++i))
|
||||||
|
@ -131,7 +138,8 @@ void fastd_configure(fastd_context *ctx, fastd_config *conf, int argc, char *con
|
||||||
}
|
}
|
||||||
|
|
||||||
IF_OPTION_ARG("-i", "--interface") {
|
IF_OPTION_ARG("-i", "--interface") {
|
||||||
conf->ifname = arg;
|
free(conf->ifname);
|
||||||
|
conf->ifname = strdup(arg);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,7 +168,7 @@ void fastd_configure(fastd_context *ctx, fastd_config *conf, int argc, char *con
|
||||||
|
|
||||||
if (charptr) {
|
if (charptr) {
|
||||||
l = strtol(charptr+1, &endptr, 10);
|
l = strtol(charptr+1, &endptr, 10);
|
||||||
if (*endptr || l > 65535)
|
if (*endptr || l < 0 || l > 65535)
|
||||||
exit_error(ctx, "invalid bind port `%s'", charptr+1);
|
exit_error(ctx, "invalid bind port `%s'", charptr+1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -255,7 +263,7 @@ void fastd_configure(fastd_context *ctx, fastd_config *conf, int argc, char *con
|
||||||
|
|
||||||
if (charptr) {
|
if (charptr) {
|
||||||
l = strtol(charptr+1, &endptr, 10);
|
l = strtol(charptr+1, &endptr, 10);
|
||||||
if (*endptr || l > 65535)
|
if (*endptr || l < 0 || l > 65535)
|
||||||
exit_error(ctx, "invalid peer port `%s'", charptr+1);
|
exit_error(ctx, "invalid peer port `%s'", charptr+1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -20,6 +20,8 @@ mode { yylval->str = yytext; return TOK_MODE; }
|
||||||
protocol { yylval->str = yytext; return TOK_PROTOCOL; }
|
protocol { yylval->str = yytext; return TOK_PROTOCOL; }
|
||||||
peer { yylval->str = yytext; return TOK_PEER; }
|
peer { yylval->str = yytext; return TOK_PEER; }
|
||||||
address { yylval->str = yytext; return TOK_ADDRESS; }
|
address { yylval->str = yytext; return TOK_ADDRESS; }
|
||||||
|
secret { yylval->str = yytext; return TOK_SECRET; }
|
||||||
|
key { yylval->str = yytext; return TOK_KEY; }
|
||||||
|
|
||||||
[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3} {
|
[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3} {
|
||||||
if (!inet_pton(AF_INET, yytext, &yylval->addr)) {
|
if (!inet_pton(AF_INET, yytext, &yylval->addr)) {
|
||||||
|
|
13
src/config.y
13
src/config.y
|
@ -29,6 +29,8 @@
|
||||||
%token <str> TOK_PROTOCOL
|
%token <str> TOK_PROTOCOL
|
||||||
%token <str> TOK_PEER
|
%token <str> TOK_PEER
|
||||||
%token <str> TOK_ADDRESS
|
%token <str> TOK_ADDRESS
|
||||||
|
%token <str> TOK_SECRET
|
||||||
|
%token <str> TOK_KEY
|
||||||
|
|
||||||
%token <addr> TOK_ADDR
|
%token <addr> TOK_ADDR
|
||||||
%token <addr6> TOK_ADDR6
|
%token <addr6> TOK_ADDR6
|
||||||
|
@ -73,10 +75,11 @@ statement: TOK_INTERFACE interface ';'
|
||||||
| TOK_MTU mtu ';'
|
| TOK_MTU mtu ';'
|
||||||
| TOK_MODE mode ';'
|
| TOK_MODE mode ';'
|
||||||
| TOK_PROTOCOL protocol ';'
|
| TOK_PROTOCOL protocol ';'
|
||||||
|
| TOK_SECRET secret ';'
|
||||||
| TOK_PEER peer '{' peer_conf '}'
|
| TOK_PEER peer '{' peer_conf '}'
|
||||||
;
|
;
|
||||||
|
|
||||||
interface: TOK_STRING { conf->ifname = strdup($1); }
|
interface: TOK_STRING { free(conf->ifname); conf->ifname = strdup($1); }
|
||||||
;
|
;
|
||||||
|
|
||||||
bind: TOK_ADDR maybe_port {
|
bind: TOK_ADDR maybe_port {
|
||||||
|
@ -116,6 +119,9 @@ protocol: maybe_string {
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
secret: TOK_STRING { free(conf->secret); conf->secret = strdup($1); }
|
||||||
|
;
|
||||||
|
|
||||||
peer: maybe_string {
|
peer: maybe_string {
|
||||||
fastd_peer_config *current_peer = malloc(sizeof(fastd_peer_config));
|
fastd_peer_config *current_peer = malloc(sizeof(fastd_peer_config));
|
||||||
current_peer->next = conf->peers;
|
current_peer->next = conf->peers;
|
||||||
|
@ -132,6 +138,7 @@ peer_conf: peer_conf peer_statement
|
||||||
;
|
;
|
||||||
|
|
||||||
peer_statement: TOK_ADDRESS peer_address ';'
|
peer_statement: TOK_ADDRESS peer_address ';'
|
||||||
|
| TOK_KEY peer_key ';'
|
||||||
;
|
;
|
||||||
|
|
||||||
peer_address: TOK_ADDR maybe_port_default {
|
peer_address: TOK_ADDR maybe_port_default {
|
||||||
|
@ -146,6 +153,10 @@ peer_address: TOK_ADDR maybe_port_default {
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
peer_key: TOK_STRING { free(conf->peers->key); conf->peers->key = strdup($1); }
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
maybe_string: TOK_STRING
|
maybe_string: TOK_STRING
|
||||||
| { $$[0] = '\0'; }
|
| { $$[0] = '\0'; }
|
||||||
;
|
;
|
||||||
|
|
|
@ -81,7 +81,7 @@ struct _fastd_config {
|
||||||
unsigned peer_stale_time_temp;
|
unsigned peer_stale_time_temp;
|
||||||
unsigned eth_addr_stale_time;
|
unsigned eth_addr_stale_time;
|
||||||
|
|
||||||
const char *ifname;
|
char *ifname;
|
||||||
|
|
||||||
struct sockaddr_in bind_addr_in;
|
struct sockaddr_in bind_addr_in;
|
||||||
struct sockaddr_in6 bind_addr_in6;
|
struct sockaddr_in6 bind_addr_in6;
|
||||||
|
@ -90,6 +90,7 @@ struct _fastd_config {
|
||||||
fastd_mode mode;
|
fastd_mode mode;
|
||||||
|
|
||||||
fastd_protocol *protocol;
|
fastd_protocol *protocol;
|
||||||
|
char *secret;
|
||||||
|
|
||||||
fastd_peer_config *peers;
|
fastd_peer_config *peers;
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,7 @@ struct _fastd_peer_config {
|
||||||
fastd_peer_config *next;
|
fastd_peer_config *next;
|
||||||
|
|
||||||
fastd_peer_address address;
|
fastd_peer_address address;
|
||||||
|
char *key;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _fastd_peer_eth_addr {
|
struct _fastd_peer_eth_addr {
|
||||||
|
|
Loading…
Add table
Reference in a new issue