From 4d0b09dd07543fbceba9921f1219e310fd53d8ef Mon Sep 17 00:00:00 2001 From: Vadim Kochan Date: Mon, 1 Feb 2016 19:01:40 +0200 Subject: [PATCH] trafgen: parser: Add syntax for VLAN header creating Add 'vlan()' function to generate VLAN header. Fields supported: tpid|proto Set TPID (Tag Protocol Identifier) (default 0x8100) 1ad Set TPID field as 0x88a8 1q Set TPID field as 0x8100 tci Set TCI (Tag Control Information) (default 0) pcp Set PCP (Priority Code Point) (PCP) (default 0) dei|cfi Set DEI (Drop Eligible Indicator) (default 0) id Set VID (VLAN Identifier) (default 0) Examples: { eth(), vlan(id=1), ipv4() } { vlan(id=1, 1ad), vlan(id=100, pcp=3), ipv4() } Signed-off-by: Vadim Kochan Signed-off-by: Tobias Klauser --- trafgen_lexer.l | 9 +++++++++ trafgen_parser.y | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/trafgen_lexer.l b/trafgen_lexer.l index ef7ec2a1..e1d1a3fc 100644 --- a/trafgen_lexer.l +++ b/trafgen_lexer.l @@ -112,6 +112,14 @@ ip4_addr ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+) "saddr"|"sa" { return K_SADDR; } [e]?"type" { return K_ETYPE; } + /* VLAN (802.1Q & 802.1ad) */ +"tpid" { return K_TPID; } +"tci" { return K_TCI; } +"pcp" { return K_PCP; } +"dei"|"cfi" { return K_DEI; } +"1ad" { return K_1AD; } +"1q" { return K_1Q; } + /* ARP */ "sha"|"smac" { return K_SHA; } "spa"|"sip" { return K_SPA; } @@ -158,6 +166,7 @@ ip4_addr ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+) "urgptr" { return K_URG_PTR; } "eth" { return K_ETH; } +"vlan" { return K_VLAN; } "arp" { return K_ARP; } "ip4"|"ipv4" { return K_IP4; } "udp" { return K_UDP; } diff --git a/trafgen_parser.y b/trafgen_parser.y index 1cc541e4..655b0baa 100644 --- a/trafgen_parser.y +++ b/trafgen_parser.y @@ -19,6 +19,7 @@ #include #include #include +#include #include "xmalloc.h" #include "trafgen_parser.tab.h" @@ -354,8 +355,10 @@ static void proto_add(enum proto_id pid) %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_SEQ K_ACK_SEQ K_DOFF K_CWR K_ECE K_URG K_ACK K_PSH K_RST K_SYN K_FIN K_WINDOW K_URG_PTR +%token K_TPID K_TCI K_PCP K_DEI K_1Q K_1AD %token K_ETH +%token K_VLAN %token K_ARP %token K_IP4 %token K_UDP K_TCP @@ -579,6 +582,7 @@ ddec proto : eth_proto { } + | vlan_proto { } | arp_proto { } | ip4_proto { } | udp_proto { } @@ -613,6 +617,42 @@ eth_field { proto_field_set_be16(hdr, ETH_TYPE, $5); } ; +vlan_proto + : vlan '(' vlan_param_list ')' { } + ; + +vlan + : K_VLAN { proto_add(PROTO_VLAN); } + ; + +vlan_param_list + : { } + | vlan_field { } + | vlan_field delimiter vlan_param_list { } + ; + +vlan_type + : K_TPID { } + | K_PROT + ; + +vlan_field + : vlan_type skip_white '=' skip_white number + { proto_field_set_be16(hdr, VLAN_TPID, $5); } + | K_1Q + { proto_field_set_be16(hdr, VLAN_TPID, ETH_P_8021Q); } + | K_1AD + { proto_field_set_be16(hdr, VLAN_TPID, ETH_P_8021AD); } + | K_TCI skip_white '=' skip_white number + { proto_field_set_be16(hdr, VLAN_TCI, $5); } + | K_PCP skip_white '=' skip_white number + { proto_field_set_be16(hdr, VLAN_PCP, $5); } + | K_DEI skip_white '=' skip_white number + { proto_field_set_be16(hdr, VLAN_DEI, $5); } + | K_ID skip_white '=' skip_white number + { proto_field_set_be16(hdr, VLAN_VID, $5); } + ; + arp_proto : arp '(' arp_param_list ')' { } ; -- 2.11.4.GIT