summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Kochan <vadim4j@gmail.com>2016-02-01 19:01:40 +0200
committerTobias Klauser <tklauser@distanz.ch>2016-02-02 16:54:48 +0100
commit4d0b09dd07543fbceba9921f1219e310fd53d8ef (patch)
treeeb89915df9ad619cf29c9c27619dacd22260c890
parenta4e17af38e2e2545c32292b7b46102d49e738e1e (diff)
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 <vadim4j@gmail.com> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
-rw-r--r--trafgen_lexer.l9
-rw-r--r--trafgen_parser.y40
2 files changed, 49 insertions, 0 deletions
diff --git a/trafgen_lexer.l b/trafgen_lexer.l
index ef7ec2a..e1d1a3f 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 1cc541e..655b0ba 100644
--- a/trafgen_parser.y
+++ b/trafgen_parser.y
@@ -19,6 +19,7 @@
#include <libgen.h>
#include <net/if_arp.h>
#include <netinet/in.h>
+#include <linux/if_ether.h>
#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 ')' { }
;