summaryrefslogtreecommitdiff
path: root/trafgen_parser.y
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2016-02-01 15:56:10 +0100
committerTobias Klauser <tklauser@distanz.ch>2016-02-01 16:22:24 +0100
commitf26175af848bfb3faaedd98b402949e8bd7ab8bc (patch)
tree3901fb68dd629e08abc02b81349ff4cb6b26f213 /trafgen_parser.y
parent0042946ef9e332e32af00a0fe0c6c7b6eec4b0e1 (diff)
trafgen: parser: Add TCP header generation function
Add a function 'tcp()' to generate TCP headers from the trafgen configuration language. Fields supported: sp|sport TCP source port (default 0) dp|dport TCP destination port (default 0) seq Sequence number (default: 0) aseq|ackseq Acknowledgement number (default 0) doff|hlen Header length/data offset (default: 5) cwr Congestion Window Reduced flag (default: 0) ece|ecn ECN-Echo flag (default: 0) urg Urgent flag (default: 0) ack Acknowledgement flag (default: 0) psh Push flag (default: 0) rst Reset flag (default: 0) syn Synchronize flag (default: 0) fin Finish flag (default: 0) win|window Receive window size (default: 0) csum Checksum field (calculated automatically) urgptr Urgent pointer (default: 0) Example (SYN on port 80/http): { tcp(dport=80, syn, window=5840) } Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'trafgen_parser.y')
-rw-r--r--trafgen_parser.y45
1 files changed, 44 insertions, 1 deletions
diff --git a/trafgen_parser.y b/trafgen_parser.y
index e512aed..7387c14 100644
--- a/trafgen_parser.y
+++ b/trafgen_parser.y
@@ -354,11 +354,12 @@ static void proto_add(enum proto_id pid)
%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_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_ETH
%token K_ARP
%token K_IP4
-%token K_UDP
+%token K_UDP K_TCP
%token ',' '{' '}' '(' ')' '[' ']' ':' '-' '+' '*' '/' '%' '&' '|' '<' '>' '^'
@@ -582,6 +583,7 @@ proto
| arp_proto { }
| ip4_proto { }
| udp_proto { }
+ | tcp_proto { }
;
eth_proto
@@ -717,6 +719,47 @@ udp
: K_UDP { proto_add(PROTO_UDP); }
;
+tcp_proto
+ : tcp '(' tcp_param_list ')' { }
+ ;
+
+tcp_param_list
+ : { }
+ | tcp_field { }
+ | tcp_field delimiter tcp_param_list { }
+ ;
+
+tcp_field
+ : K_SPORT skip_white '=' skip_white number
+ { proto_field_set_be16(hdr, TCP_SPORT, $5); }
+ | K_DPORT skip_white '=' skip_white number
+ { proto_field_set_be16(hdr, TCP_DPORT, $5); }
+ | K_SEQ skip_white '=' skip_white number
+ { proto_field_set_be32(hdr, TCP_SEQ, $5); }
+ | K_ACK_SEQ skip_white '=' skip_white number
+ { proto_field_set_be32(hdr, TCP_ACK_SEQ, $5); }
+ | K_DOFF skip_white '=' skip_white number
+ { proto_field_set_be16(hdr, TCP_DOFF, $5); }
+ | K_CWR { proto_field_set_be16(hdr, TCP_CWR, 1); }
+ | K_ECE { proto_field_set_be16(hdr, TCP_ECE, 1); }
+ | K_URG { proto_field_set_be16(hdr, TCP_URG, 1); }
+ | K_ACK { proto_field_set_be16(hdr, TCP_ACK, 1); }
+ | K_PSH { proto_field_set_be16(hdr, TCP_PSH, 1); }
+ | K_RST { proto_field_set_be16(hdr, TCP_RST, 1); }
+ | K_SYN { proto_field_set_be16(hdr, TCP_SYN, 1); }
+ | K_FIN { proto_field_set_be16(hdr, TCP_FIN, 1); }
+ | K_WINDOW skip_white '=' skip_white number
+ { proto_field_set_be16(hdr, TCP_WINDOW, $5); }
+ | K_CSUM skip_white '=' skip_white number
+ { proto_field_set_be16(hdr, TCP_CSUM, $5); }
+ | K_URG_PTR skip_white '=' skip_white number
+ { proto_field_set_be16(hdr, TCP_URG_PTR, $5); }
+ ;
+
+tcp
+ : K_TCP { proto_add(PROTO_TCP); }
+ ;
+
%%
static void finalize_packet(void)