diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2016-01-29 14:12:01 +0100 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2016-01-29 14:19:47 +0100 |
commit | 2ba202b8320cbec32520d347ac256c2b4caf0458 (patch) | |
tree | 1e1be887468c3a4d5a769f5d1f838537fff86d0c | |
parent | 56ce71c166cdfeab7cb503d538fd176ec4548e05 (diff) |
trafgen: parser: Support "etype"/"type" keywords for Ethertype
The IEEE 802.3 standard commonly refers to the field specifying the
upper layer protocol as Ethertype, not protocol. Thus, also support the
keywords "etype" and "type" for this field.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
-rw-r--r-- | trafgen.8 | 4 | ||||
-rw-r--r-- | trafgen_l2.c | 4 | ||||
-rw-r--r-- | trafgen_l2.h | 2 | ||||
-rw-r--r-- | trafgen_l3.c | 3 | ||||
-rw-r--r-- | trafgen_lexer.l | 9 | ||||
-rw-r--r-- | trafgen_parser.y | 8 |
6 files changed, 18 insertions, 12 deletions
@@ -294,7 +294,7 @@ Supported protocol headers: .sp .I Ethernet : -.B eth(da=<mac>, sa=<mac>, prot=<number>) +.B eth(da=<mac>, sa=<mac>, type=<number>) .sp .in +4 .B da|daddr @@ -303,7 +303,7 @@ Supported protocol headers: .B sa|saddr - Source MAC address (default: device MAC address) .sp -.B prot|proto +.B etype|type|prot|proto - Ethernet type (default: 0) .in -4 diff --git a/trafgen_l2.c b/trafgen_l2.c index 4bbeea1..e881b06 100644 --- a/trafgen_l2.c +++ b/trafgen_l2.c @@ -13,7 +13,7 @@ struct proto_field eth_fields[] = { { .id = ETH_DST_ADDR, .len = 6, }, { .id = ETH_SRC_ADDR, .len = 6, .offset = 6 }, - { .id = ETH_PROTO_ID, .len = 2, .offset = 12 }, + { .id = ETH_TYPE, .len = 2, .offset = 12 }, }; static void eth_header_init(struct proto_hdr *hdr) @@ -53,7 +53,7 @@ static void arp_header_init(struct proto_hdr *hdr) uint8_t bcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; proto_field_set_default_bytes(lower, ETH_DST_ADDR, bcast); - proto_field_set_default_be16(lower, ETH_PROTO_ID, ETH_P_ARP); + proto_field_set_default_be16(lower, ETH_TYPE, ETH_P_ARP); } proto_header_fields_add(hdr, arp_fields, array_size(arp_fields)); diff --git a/trafgen_l2.h b/trafgen_l2.h index 7643bc3..38727ec 100644 --- a/trafgen_l2.h +++ b/trafgen_l2.h @@ -4,7 +4,7 @@ enum eth_field { ETH_DST_ADDR, ETH_SRC_ADDR, - ETH_PROTO_ID, + ETH_TYPE, }; enum arp_field { diff --git a/trafgen_l3.c b/trafgen_l3.c index dd45395..1771908 100644 --- a/trafgen_l3.c +++ b/trafgen_l3.c @@ -38,9 +38,8 @@ static void ipv4_header_init(struct proto_hdr *hdr) proto_lower_default_add(PROTO_ETH); lower = proto_current_header(); - if (lower->id == PROTO_ETH) - proto_field_set_default_be16(lower, ETH_PROTO_ID, ETH_P_IP); + proto_field_set_default_be16(lower, ETH_TYPE, ETH_P_IP); else if (lower->id == PROTO_IP4) proto_field_set_default_u8(lower, IP4_PROTO, IPPROTO_IPIP); diff --git a/trafgen_lexer.l b/trafgen_lexer.l index 56011a3..a661922 100644 --- a/trafgen_lexer.l +++ b/trafgen_lexer.l @@ -105,10 +105,15 @@ ip_addr ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+) "const32"|"c32" { return K_CONST32; } "const64"|"c64" { return K_CONST64; } + /* IPv4 proto field (must be before more specific rule for K_ETYPE) */ +"prot"[o]? { return K_PROT; } + + /* Ethernet */ "daddr"|"da" { return K_DADDR; } "saddr"|"sa" { return K_SADDR; } -"prot"[o]? { return K_PROT; } +[e]?"type"|"prot"[o]? { return K_ETYPE; } + /* ARP */ "sha"|"smac" { return K_SHA; } "spa"|"sip" { return K_SPA; } "tha"|"tmac" { return K_THA; } @@ -119,6 +124,7 @@ ip_addr ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+) "htype" { return K_HTYPE; } "ptype" { return K_PTYPE; } + /* IPv4 */ "ihl" { return K_IHL; } "ver"|"version" { return K_VER; } "ttl" { return K_TTL; } @@ -133,6 +139,7 @@ ip_addr ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+) "df" { return K_DF; } "mf" { return K_MF; } + /* UDP */ "sp"|"sport" { return K_SPORT; } "dp"|"dport" { return K_DPORT; } diff --git a/trafgen_parser.y b/trafgen_parser.y index 9ec09b1..71f88d8 100644 --- a/trafgen_parser.y +++ b/trafgen_parser.y @@ -350,9 +350,9 @@ static void proto_add(enum proto_id pid) %token K_COMMENT K_FILL K_RND K_SEQINC K_SEQDEC K_DRND K_DINC K_DDEC K_WHITE %token K_CPU K_CSUMIP K_CSUMUDP K_CSUMTCP K_CSUMUDP6 K_CSUMTCP6 K_CONST8 K_CONST16 K_CONST32 K_CONST64 -%token K_DADDR K_SADDR K_PROT +%token K_DADDR K_SADDR K_ETYPE %token K_OPER K_SHA K_SPA K_THA K_TPA K_REQUEST K_REPLY K_PTYPE K_HTYPE -%token K_TTL K_DSCP K_ECN K_TOS K_LEN K_ID K_FLAGS K_FRAG K_IHL K_VER K_CSUM K_DF K_MF +%token K_PROT K_TTL K_DSCP K_ECN K_TOS K_LEN K_ID K_FLAGS K_FRAG K_IHL K_VER K_CSUM K_DF K_MF %token K_SPORT K_DPORT %token K_ETH @@ -603,8 +603,8 @@ eth_field { proto_field_set_bytes(hdr, ETH_DST_ADDR, $5); } | K_SADDR skip_white '=' skip_white mac { proto_field_set_bytes(hdr, ETH_SRC_ADDR, $5); } - | K_PROT skip_white '=' skip_white number - { proto_field_set_be16(hdr, ETH_PROTO_ID, $5); } + | K_ETYPE skip_white '=' skip_white number + { proto_field_set_be16(hdr, ETH_TYPE, $5); } ; arp_proto |