summaryrefslogtreecommitdiff
path: root/usr.sbin/switchctl/parser.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/switchctl/parser.c')
-rw-r--r--usr.sbin/switchctl/parser.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/usr.sbin/switchctl/parser.c b/usr.sbin/switchctl/parser.c
index 39fa77414d0..57ced7b967e 100644
--- a/usr.sbin/switchctl/parser.c
+++ b/usr.sbin/switchctl/parser.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.c,v 1.3 2016/10/12 19:07:42 reyk Exp $ */
+/* $OpenBSD: parser.c,v 1.4 2016/11/15 08:15:07 reyk Exp $ */
/*
* Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
@@ -57,6 +57,7 @@ static const struct token t_reset[];
static const struct token t_log[];
static const struct token t_load[];
static const struct token t_show[];
+static const struct token t_dump[];
static const struct token t_connect[];
static const struct token t_disconnect[];
static const struct token t_forward_to[];
@@ -65,6 +66,7 @@ static const struct token t_uri[];
static const struct token t_main[] = {
{ KEYWORD, "connect", CONNECT, t_connect },
{ KEYWORD, "disconnect", DISCONNECT, t_disconnect },
+ { KEYWORD, "dump", NONE, t_dump },
{ KEYWORD, "load", LOAD, t_load },
{ KEYWORD, "log", NONE, t_log },
{ KEYWORD, "monitor", MONITOR, NULL },
@@ -90,12 +92,21 @@ static const struct token t_load[] = {
{ ENDTOKEN, "", NONE, NULL }
};
+static const struct token t_dump[] = {
+ { KEYWORD, "desc", DUMP_DESC, t_uri },
+ { KEYWORD, "features", DUMP_FEATURES, t_uri },
+ { KEYWORD, "flows", DUMP_FLOWS, t_uri },
+ { KEYWORD, "tables", DUMP_TABLES, t_uri },
+ { ENDTOKEN, "", NONE, NULL }
+};
+
static const struct token t_show[] = {
{ KEYWORD, "summary", SHOW_SUM, NULL },
{ KEYWORD, "switches", SHOW_SWITCHES, NULL },
{ KEYWORD, "macs", SHOW_MACS, NULL },
{ ENDTOKEN, "", NONE, NULL }
};
+
static const struct token t_connect[] = {
{ ADDRESS, "", NONE, t_forward_to },
{ ENDTOKEN, "", NONE, NULL }
@@ -109,6 +120,7 @@ static const struct token t_forward_to[] = {
{ KEYWORD, "forward-to", NONE, t_uri },
{ ENDTOKEN, "", NONE, NULL }
};
+
static const struct token t_uri[] = {
{ URI, "", NONE, NULL },
{ ENDTOKEN, "", NONE, NULL }
@@ -216,6 +228,7 @@ match_token(char *word, const struct token table[])
{
unsigned int i, match = 0;
const struct token *t = NULL;
+ size_t len;
for (i = 0; table[i].type != ENDTOKEN; i++) {
switch (table[i].type) {
@@ -250,7 +263,24 @@ match_token(char *word, const struct token table[])
break;
case URI:
if (!match && word != NULL && strlen(word) > 0) {
- res.uri = strdup(word);
+ len = 4;
+ if (strncmp(word, "tcp:", len) == 0)
+ res.uri.swa_type = SWITCH_CONN_TCP;
+ else if (strncmp(word, "tls:", len) == 0)
+ res.uri.swa_type = SWITCH_CONN_TLS;
+ else {
+ /* set the default */
+ res.uri.swa_type = SWITCH_CONN_TCP;
+ len = 0;
+ }
+ if (parsehostport(word + len,
+ (struct sockaddr *)&res.uri.swa_addr,
+ sizeof(res.uri.swa_addr)) != 0) {
+ fprintf(stderr,
+ "could not parse address: %s\n",
+ word);
+ return (NULL);
+ }
match++;
t = &table[i];
}