summaryrefslogtreecommitdiff
path: root/trafgen_parser.y
diff options
context:
space:
mode:
Diffstat (limited to 'trafgen_parser.y')
-rw-r--r--trafgen_parser.y51
1 files changed, 51 insertions, 0 deletions
diff --git a/trafgen_parser.y b/trafgen_parser.y
index 16f9025..ebc4054 100644
--- a/trafgen_parser.y
+++ b/trafgen_parser.y
@@ -25,6 +25,7 @@
#include "trafgen_conf.h"
#include "trafgen_proto.h"
#include "trafgen_l2.h"
+#include "trafgen_l3.h"
#include "built_in.h"
#include "die.h"
#include "str.h"
@@ -350,9 +351,11 @@ 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_ETH
%token K_ARP
+%token K_IP4
%token ',' '{' '}' '(' ')' '[' ']' ':' '-' '+' '*' '/' '%' '&' '|' '<' '>' '^'
@@ -574,6 +577,7 @@ ddec
proto
: eth_proto { }
| arp_proto { }
+ | ip4_proto { }
;
eth_proto
@@ -637,6 +641,53 @@ arp
: K_ARP { proto_add(PROTO_ARP); }
;
+ip4_proto
+ : ip4 '(' ip4_param_list ')' { }
+ ;
+
+ip4_param_list
+ : { }
+ | ip4_field { }
+ | ip4_field delimiter ip4_param_list { }
+ ;
+
+ip4_field
+ : K_VER skip_white '=' skip_white number
+ { proto_field_set_u8(hdr, IP4_VER, $5); }
+ | K_IHL skip_white '=' skip_white number
+ { proto_field_set_u8(hdr, IP4_IHL, $5); }
+ | K_DADDR skip_white '=' skip_white ip_addr
+ { proto_field_set_u32(hdr, IP4_DADDR, $5.s_addr); }
+ | K_SADDR skip_white '=' skip_white ip_addr
+ { proto_field_set_u32(hdr, IP4_SADDR, $5.s_addr); }
+ | K_PROT skip_white '=' skip_white number
+ { proto_field_set_u8(hdr, IP4_PROTO, $5); }
+ | K_TTL skip_white '=' skip_white number
+ { proto_field_set_u8(hdr, IP4_TTL, $5); }
+ | K_DSCP skip_white '=' skip_white number
+ { proto_field_set_u8(hdr, IP4_DSCP, $5); }
+ | K_ECN skip_white '=' skip_white number
+ { proto_field_set_u8(hdr, IP4_ECN, $5); }
+ | K_TOS skip_white '=' skip_white number
+ { proto_field_set_u8(hdr, IP4_TOS, $5); }
+ | K_LEN skip_white '=' skip_white number
+ { proto_field_set_be16(hdr, IP4_LEN, $5); }
+ | K_ID skip_white '=' skip_white number
+ { proto_field_set_be16(hdr, IP4_ID, $5); }
+ | K_FLAGS skip_white '=' skip_white number
+ { proto_field_set_be16(hdr, IP4_FLAGS, $5); }
+ | K_DF { proto_field_set_be16(hdr, IP4_DF, 1); }
+ | K_MF { proto_field_set_be16(hdr, IP4_MF, 1); }
+ | K_FRAG skip_white '=' skip_white number
+ { proto_field_set_be16(hdr, IP4_FRAG_OFFS, $5); }
+ | K_CSUM skip_white '=' skip_white number
+ { proto_field_set_be16(hdr, IP4_CSUM, $5); }
+ ;
+
+ip4
+ : K_IP4 { proto_add(PROTO_IP4); }
+ ;
+
%%
static void finalize_packet(void)