summaryrefslogtreecommitdiff
path: root/trafgen_parser.y
diff options
context:
space:
mode:
authorVadim Kochan <vadim4j@gmail.com>2016-01-29 00:06:27 +0200
committerTobias Klauser <tklauser@distanz.ch>2016-01-29 09:01:14 +0100
commit4f51efe253208cb906a31e75da21a1f718132486 (patch)
tree1a69e5623b175f16bf13969759edf9a9d9836d0e /trafgen_parser.y
parentd275f16591ca44d91ee4e56d65553529a429a62d (diff)
trafgen: parser: Add syntax to build UDP header
Add function 'udp()' to generate UDP header. Fields supported: sp|sport UDP source port (default 0) dp|dport UDP destination port (default 0) len|length Length of UDP header + payload (calculated automatically) csum Checksum field (calculated automatically) Example (Echo request): { udp(dport=7) } Signed-off-by: Vadim Kochan <vadim4j@gmail.com> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'trafgen_parser.y')
-rw-r--r--trafgen_parser.y29
1 files changed, 29 insertions, 0 deletions
diff --git a/trafgen_parser.y b/trafgen_parser.y
index ebc4054..9ec09b1 100644
--- a/trafgen_parser.y
+++ b/trafgen_parser.y
@@ -26,6 +26,7 @@
#include "trafgen_proto.h"
#include "trafgen_l2.h"
#include "trafgen_l3.h"
+#include "trafgen_l4.h"
#include "built_in.h"
#include "die.h"
#include "str.h"
@@ -352,10 +353,12 @@ static void proto_add(enum proto_id pid)
%token K_DADDR K_SADDR K_PROT
%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_SPORT K_DPORT
%token K_ETH
%token K_ARP
%token K_IP4
+%token K_UDP
%token ',' '{' '}' '(' ')' '[' ']' ':' '-' '+' '*' '/' '%' '&' '|' '<' '>' '^'
@@ -578,6 +581,7 @@ proto
: eth_proto { }
| arp_proto { }
| ip4_proto { }
+ | udp_proto { }
;
eth_proto
@@ -688,6 +692,31 @@ ip4
: K_IP4 { proto_add(PROTO_IP4); }
;
+udp_proto
+ : udp '(' udp_param_list ')' { }
+ ;
+
+udp_param_list
+ : { }
+ | udp_field { }
+ | udp_field delimiter udp_param_list { }
+ ;
+
+udp_field
+ : K_SPORT skip_white '=' skip_white number
+ { proto_field_set_be16(hdr, UDP_SPORT, $5); }
+ | K_DPORT skip_white '=' skip_white number
+ { proto_field_set_be16(hdr, UDP_DPORT, $5); }
+ | K_LEN skip_white '=' skip_white number
+ { proto_field_set_be16(hdr, UDP_LEN, $5); }
+ | K_CSUM skip_white '=' skip_white number
+ { proto_field_set_be16(hdr, UDP_CSUM, $5); }
+ ;
+
+udp
+ : K_UDP { proto_add(PROTO_UDP); }
+ ;
+
%%
static void finalize_packet(void)