diff options
author | Vadim Kochan <vadim4j@gmail.com> | 2016-01-29 00:06:25 +0200 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2016-01-29 08:58:54 +0100 |
commit | be21df123309c83cd47a1fa5f2c0ee1cf4657810 (patch) | |
tree | 5330fb556f0f2825a4a5d4a174dc31951ba8fb98 /trafgen_parser.y | |
parent | baf47305fabce02017642b0f43472ab5a4eaa533 (diff) |
trafgen: parser: Add syntax for IPv4 protocol generation
Add 'ip4(), ipv4()' function to build IPv4 header.
Fields supported:
ihl IPv4 header length (default 5 )
ver|version IPv4 version (default 4)
ttl Time To Live (TTL) field (default 0)
dscp DiffServ field (default 0)
ecn ECN bits (default 0)
tos TOS (DSCP + ECN) field (default 0)
len|length IPv4 header + payload length (calculated by default)
id Identifier (default 0)
flags Flags field (default 0)
frag Fragment offset (default 0)
csum IPv4 header checksum (calculated by default)
df Set DF (Dont Fragment) bit to 1 (default is 0)
mf Set MF (More Fragments) bit to 1 (default is 0)
sa|saddr IPv4 source address (default used from output device)
da|daddr IPv4 destination address (default 0.0.0.0)
proto IPv4 protocol id (default 0)
Example:
{ ip4(df, mf, frag=100, prot=0x1, ecn=2, dscp=20) }
{ ip4(da=1.1.1.1), ip4(sa=3.3.3.3, da=3.3.3.4) }
Last example generates IP-in-IP packet.
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.y | 51 |
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) |