diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cli.c | 8 | ||||
-rw-r--r-- | src/erec.c | 1 | ||||
-rw-r--r-- | src/main.c | 3 | ||||
-rw-r--r-- | src/meta.c | 39 | ||||
-rw-r--r-- | src/scanner.l | 6 | ||||
-rw-r--r-- | src/statement.c | 2 |
6 files changed, 46 insertions, 13 deletions
@@ -92,6 +92,8 @@ static void cli_complete(char *line) const HIST_ENTRY *hist; const char *c; LIST_HEAD(msgs); + int len; + char *s; if (line == NULL) { printf("\n"); @@ -119,6 +121,12 @@ static void cli_complete(char *line) if (hist == NULL || strcmp(hist->line, line)) add_history(line); + len = strlen(line); + s = xmalloc(len + 2); + snprintf(s, len + 2, "%s\n", line); + xfree(line); + line = s; + parser_init(state, &msgs); scanner_push_buffer(scanner, &indesc_cli, line); nft_run(scanner, state, &msgs); @@ -92,6 +92,7 @@ void erec_print(FILE *f, const struct error_record *erec) case INDESC_BUFFER: case INDESC_CLI: line = indesc->data; + *strchrnul(line, '\n') = '\0'; break; case INDESC_FILE: memset(buf, 0, sizeof(buf)); @@ -328,12 +328,13 @@ int main(int argc, char * const *argv) for (len = 0, i = optind; i < argc; i++) len += strlen(argv[i]) + strlen(" "); - buf = xzalloc(len + 1); + buf = xzalloc(len + 2); for (i = optind; i < argc; i++) { strcat(buf, argv[i]); if (i + 1 < argc) strcat(buf, " "); } + strcat(buf, "\n"); parser_init(&state, &msgs); scanner = scanner_init(&state); scanner_push_buffer(scanner, &indesc_cmdline, buf); @@ -10,6 +10,7 @@ * Development of this code funded by Astaro AG (http://www.astaro.com/) */ +#include <errno.h> #include <stddef.h> #include <stdlib.h> #include <stdio.h> @@ -89,34 +90,50 @@ static struct error_record *tchandle_type_parse(const struct expr *sym, struct expr **res) { uint32_t handle; + char *str; if (strcmp(sym->identifier, "root") == 0) handle = TC_H_ROOT; else if (strcmp(sym->identifier, "none") == 0) handle = TC_H_UNSPEC; - else if (sym->identifier[0] == ':') { - if (sscanf(sym->identifier, ":%04x", &handle) != 1) + else if (strchr(sym->identifier, ':')) { + uint16_t tmp; + char *colon; + + str = xstrdup(sym->identifier); + + colon = strchr(str, ':'); + if (!colon) goto err; - } else if (sym->identifier[strlen(sym->identifier)-1] == ':') { - if (sscanf(sym->identifier, "%04x:", &handle) != 1) + + *colon = '\0'; + + errno = 0; + tmp = strtoull(str, NULL, 16); + if (errno != 0) goto err; - handle <<= 16; - } else { - uint32_t min, max; + handle = (tmp << 16); + if (str[strlen(str) - 1] == ':') + goto out; - if (sscanf(sym->identifier, "%04x:%04x", &max, &min) != 2) + errno = 0; + tmp = strtoull(colon + 1, NULL, 16); + if (errno != 0) goto err; - handle = max << 16 | min; + handle |= tmp; + } else { + handle = strtoull(sym->identifier, NULL, 0); } +out: *res = constant_expr_alloc(&sym->location, sym->dtype, BYTEORDER_HOST_ENDIAN, sizeof(handle) * BITS_PER_BYTE, &handle); return NULL; err: - return error(&sym->location, "Could not parse %s", - sym->dtype->desc); + xfree(str); + return error(&sym->location, "Could not parse %s", sym->dtype->desc); } static const struct datatype tchandle_type = { diff --git a/src/scanner.l b/src/scanner.l index b1420f35..e9384fd6 100644 --- a/src/scanner.l +++ b/src/scanner.l @@ -170,6 +170,7 @@ ip4addr (([[:digit:]]{1,3}"."){3}([[:digit:]]{1,3})) ip6addr ({v680}|{v67}|{v66}|{v65}|{v64}|{v63}|{v62}|{v61}|{v60}) ip6addr_rfc2732 (\[{ip6addr}\]) +classid ({hexdigit}{1,4}:{hexdigit}{1,4}) addrstring ({macaddr}|{ip4addr}|{ip6addr}) %option prefix="nft_" @@ -506,6 +507,11 @@ addrstring ({macaddr}|{ip4addr}|{ip6addr}) return NUM; } +{classid}/[ \t\n:\-},] { + yylval->string = xstrdup(yytext); + return STRING; + } + {quotedstring} { yytext[yyleng - 1] = '\0'; yylval->string = xstrdup(yytext + 1); diff --git a/src/statement.c b/src/statement.c index fbe74a64..59b133c2 100644 --- a/src/statement.c +++ b/src/statement.c @@ -477,7 +477,7 @@ static void redir_stmt_print(const struct stmt *stmt) printf("redirect"); if (stmt->redir.proto) { - printf(" to "); + printf(" to :"); expr_print(stmt->redir.proto); } |