summaryrefslogtreecommitdiff
path: root/trafgen_parser.y
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2016-04-22 16:55:31 +0200
committerTobias Klauser <tklauser@distanz.ch>2016-04-25 17:56:34 +0200
commitc09e06a6efaa94768660636a9c58ce9666e29d05 (patch)
treea41455899d30c7a8de30fdc9eb917702d9769975 /trafgen_parser.y
parent0cf15c320f9211d59b055157c895537e4b682a07 (diff)
trafgen: proto: Add IPv6 header generation
Support for generating simple IPv6 headers using the 'ip6()/ipv6()' trafgen generation function. Fields supported: ver|version Version (default: 6) tc|tclass Traffic class (default: 0) fl|flow Flow Label (default: 0) len|length Payload length (calculated by default) nh|nexthdr Type of next header (default: 0) hl|hoplimit|ttl Hop Limit, TTL (default: 0) sa|saddr Source IPv6 address (default: device address) da|daddr Destination IPv6 address (default: 0:0:0:0:0:0:0:0) Examples: { eth(), ipv6(daddr=1:2:3:4:5:6:7:8) } { ipv6(tc=2, hl=3, daddr=::1) } { eth(), ipv6(nh=58, sa=2001:db8::, da=::1), 128, 0, 0x52, 0x03, 0, 0, 0, 0 } If not explicitely specified, the lower header is initialized as Ethernet. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'trafgen_parser.y')
-rw-r--r--trafgen_parser.y46
1 files changed, 44 insertions, 2 deletions
diff --git a/trafgen_parser.y b/trafgen_parser.y
index 0b1c0fb..d6c9e70 100644
--- a/trafgen_parser.y
+++ b/trafgen_parser.y
@@ -342,6 +342,7 @@ static void proto_add(enum proto_id pid)
%union {
struct in_addr ip4_addr;
+ struct in6_addr ip6_addr;
long long int number;
uint8_t bytes[256];
char *str;
@@ -353,6 +354,7 @@ static void proto_add(enum proto_id pid)
%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_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_FLOW K_NEXT_HDR K_HOP_LIMIT
%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
@@ -361,17 +363,18 @@ static void proto_add(enum proto_id pid)
%token K_ETH
%token K_VLAN K_MPLS
%token K_ARP
-%token K_IP4
+%token K_IP4 K_IP6
%token K_UDP K_TCP
%token ',' '{' '}' '(' ')' '[' ']' ':' '-' '+' '*' '/' '%' '&' '|' '<' '>' '^'
-%token number string mac ip4_addr
+%token number string mac ip4_addr ip6_addr
%type <number> number expression
%type <str> string
%type <bytes> mac
%type <ip4_addr> ip4_addr
+%type <ip6_addr> ip6_addr
%left '-' '+' '*' '/' '%' '&' '|' '<' '>' '^'
@@ -587,6 +590,7 @@ proto
| mpls_proto { }
| arp_proto { }
| ip4_proto { }
+ | ip6_proto { }
| udp_proto { }
| tcp_proto { }
;
@@ -770,6 +774,44 @@ ip4
: K_IP4 { proto_add(PROTO_IP4); }
;
+ip6_proto
+ : ip6 '(' ip6_param_list ')' { }
+ ;
+
+ip6_param_list
+ : { }
+ | ip6_field { }
+ | ip6_field delimiter ip6_param_list { }
+ ;
+
+ip6_hop_limit
+ : K_HOP_LIMIT { }
+ | K_TTL { }
+ ;
+
+ip6_field
+ : K_VER skip_white '=' skip_white number
+ { proto_field_set_be32(hdr, IP6_VER, $5); }
+ | K_TC skip_white '=' skip_white number
+ { proto_field_set_be32(hdr, IP6_CLASS, $5); }
+ | K_FLOW skip_white '=' skip_white number
+ { proto_field_set_be32(hdr, IP6_FLOW_LBL, $5); }
+ | K_LEN skip_white '=' skip_white number
+ { proto_field_set_be16(hdr, IP6_LEN, $5); }
+ | K_NEXT_HDR skip_white '=' skip_white number
+ { proto_field_set_u8(hdr, IP6_NEXT_HDR, $5); }
+ | ip6_hop_limit skip_white '=' skip_white number
+ { proto_field_set_u8(hdr, IP6_HOP_LIMIT, $5); }
+ | K_SADDR skip_white '=' skip_white ip6_addr
+ { proto_field_set_bytes(hdr, IP6_SADDR, (uint8_t *)&($5.s6_addr)); }
+ | K_DADDR skip_white '=' skip_white ip6_addr
+ { proto_field_set_bytes(hdr, IP6_DADDR, (uint8_t *)&($5.s6_addr)); }
+ ;
+
+ip6
+ : K_IP6 { proto_add(PROTO_IP6); }
+ ;
+
udp_proto
: udp '(' udp_param_list ')' { }
;