diff options
author | Vadim Kochan <vadim4j@gmail.com> | 2017-01-30 10:33:24 +0200 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2017-02-09 12:03:15 +0100 |
commit | 4156f1451ac83e0ba1cfa856c86c44af7d30e6f0 (patch) | |
tree | 6b120abfc6c8f86dd6324f0c055db41ffa6052f5 | |
parent | b78eb052d569dd25d4963124bf800429b695616c (diff) |
trafgen: parser: Rename bytes -> mac
Rename <bytes> token member to <mac> as it is used only for MAC
address parsing, for dynamic sized bytes array we have <str>.
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
-rw-r--r-- | trafgen_lexer.l | 2 | ||||
-rw-r--r-- | trafgen_parser.y | 12 |
2 files changed, 7 insertions, 7 deletions
diff --git a/trafgen_lexer.l b/trafgen_lexer.l index 65ec245..cf67c74 100644 --- a/trafgen_lexer.l +++ b/trafgen_lexer.l @@ -300,7 +300,7 @@ ip6_addr ({v680}|{v67}|{v66}|{v65}|{v64}|{v63}|{v62}|{v61}|{v60}) {number_ascii} { yylval.number = (uint8_t) (*yytext); return number; } -{mac} { if (str2mac(yytext, yylval.bytes, 256)) +{mac} { if (str2mac(yytext, yylval.mac, 6)) panic("Failed to parse MAC address %s\n", yytext); return mac; } diff --git a/trafgen_parser.y b/trafgen_parser.y index 60f1f64..5281bf6 100644 --- a/trafgen_parser.y +++ b/trafgen_parser.y @@ -92,7 +92,7 @@ struct proto_field_expr { struct in_addr ip4_addr; struct in6_addr ip6_addr; long long int number; - uint8_t bytes[256]; + uint8_t mac[256]; struct proto_field_func func; } val; }; @@ -433,9 +433,9 @@ static void proto_field_expr_eval(void) else if (field->len == 4) proto_hdr_field_set_be32(hdr, field->id, field_expr.val.number); else - proto_hdr_field_set_bytes(hdr, field->id, field_expr.val.bytes); + panic("Invalid value length %zu, can be 1,2 or 4\n", field->len); } else if (field_expr.type & FIELD_EXPR_MAC) { - proto_hdr_field_set_bytes(hdr, field->id, field_expr.val.bytes); + proto_hdr_field_set_bytes(hdr, field->id, field_expr.val.mac); } else if (field_expr.type & FIELD_EXPR_IP4_ADDR) { proto_hdr_field_set_u32(hdr, field->id, field_expr.val.ip4_addr.s_addr); } else if (field_expr.type & FIELD_EXPR_IP6_ADDR) { @@ -481,7 +481,7 @@ static void field_index_validate(struct proto_field *field, uint16_t index, size struct in_addr ip4_addr; struct in6_addr ip6_addr; long long int number; - uint8_t bytes[256]; + uint8_t mac[6]; char *str; } @@ -516,7 +516,7 @@ static void field_index_validate(struct proto_field *field, uint16_t index, size %type <number> number expression %type <str> string -%type <bytes> mac +%type <mac> mac %type <ip4_addr> ip4_addr %type <ip6_addr> ip6_addr @@ -760,7 +760,7 @@ field_value_expr : number { field_expr.type |= FIELD_EXPR_NUMB; field_expr.val.number = $1; } | mac { field_expr.type |= FIELD_EXPR_MAC; - memcpy(field_expr.val.bytes, $1, sizeof(field_expr.val.bytes)); } + memcpy(field_expr.val.mac, $1, sizeof(field_expr.val.mac)); } | ip4_addr { field_expr.type |= FIELD_EXPR_IP4_ADDR; field_expr.val.ip4_addr = $1; } | ip6_addr { field_expr.type |= FIELD_EXPR_IP6_ADDR; |