Add 'icmpv4()' function to create ICMPv4 header.
Parameters suported:
type Set type field (default 0: Echo reply)
code Set code field (default 0)
csum Set checksum field (calculated by default)
unused Set 4-byte unused field (default 0)
mtu Set mtu field for destination unreachable (default 0)
seq Set sequence field (default 0)
id Set identifier field (default 0)
addr Set redirect address (default 0)
The following message types are supported:
net-unreach Set 'Destination network is unreachable' message type
host-unreach Set 'Destination host is unreachable' message type
prot-unreach Set 'Destination protocol is unreachable' message type
port-unreach Set 'Destination port is unreachable' message type
net-tos-unreach Set 'Destination network & ToS is unreachable' message
type
host-tos-unreach Set 'Destination host & ToS is unreachable' message type
frag-needed Set 'Fragmentation is needed' message type
route-failed Set 'Source route is failed' message type
net-unknown Set 'Destination network is unknown' message type
host-unknown Set 'Destination host is unknown' message type
host-isolated Set 'Source host isolated' message type
net-forbidden Set 'Network is adimnistratively prohibited' message
type
host-forbidden Set 'Host is administratively prohibited' message type
pkt-filtered Set 'Packet is filtered' message type
net-redirect Set 'Redirect datagram for the network' message type
host-redirect Set 'Redirect datagram for the host' message type
net-tos-redirect Set 'Redirect datagram for the ToS & network' message
type
host-tos-redirect Set 'Redirect datagram for the ToS & host' message type
ttl-timeout Set 'TTL expired in transit' message type
frag-timeout Set 'Fragment reassembly time exceeded' message type
Examples:
a) Send Ping request:
{ icmpv4(echo-request, seq=1, id=1326) }
b) Send ICMPv4 'Host Unreachable' message with IPv4 header as payload:
{
icmpv4(host-unreach),
ipv4()
}
Signed-off-by: Vadim Kochan <[email protected]>
---
trafgen_lexer.l | 29 ++++++++++++++++
trafgen_parser.y | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 131 insertions(+), 1 deletion(-)
diff --git a/trafgen_lexer.l b/trafgen_lexer.l
index 4977f87..c54712a 100644
--- a/trafgen_lexer.l
+++ b/trafgen_lexer.l
@@ -162,6 +162,34 @@ ip6_addr
(({a_hex}?:)?({a_hex}?:)?({a_hex}?:)?({a_hex}?:)?({a_hex}?:)?({a_hex}?:
"nh"|"nexthdr" { return K_NEXT_HDR; }
"hl"|"hoplimit" { return K_HOP_LIMIT; }
+
+ /* ICMPv4 */
+"addr" { return K_ADDR; }
+"mtu" { return K_MTU; }
+
+"net-unreach" { return K_NET_UNREACH; }
+"host-unreach" { return K_HOST_UNREACH; }
+"prot-unreach" { return K_PROT_UNREACH; }
+"port-unreach" { return K_PROT_UNREACH; }
+"net-tos-unreach" { return K_NET_TOS_UNREACH; }
+"host-tos-unreach" { return K_HOST_TOS_UNREACH; }
+"frag-needed" { return K_FRAG_NEEDED; }
+"route-failed" { return K_ROUTE_FAILED; }
+"net-unknown" { return K_NET_UNKNOWN; }
+"host-unknown" { return K_HOST_UNKNOWN; }
+"host-isolated" { return K_HOST_ISOLATED; }
+"net-forbidden" { return K_NET_FORBIDDEN; }
+"host-forbidden" { return K_HOST_FORBIDDEN; }
+"pkt-filtered" { return K_PKT_FILTERED; }
+
+"net-redirect" { return K_NET_REDIRECT; }
+"host-redirect" { return K_HOST_REDIRECT; }
+"net-tos-redirect" { return K_NET_TOS_REDIRECT; }
+"host-tos-redirect" { return K_HOST_TOS_REDIRECT; }
+
+"ttl-timeout" { return K_TIMEOUT_TTL; }
+"frag-timeout" { return K_TIMEOUT_FRAG; }
+
/* ICMPv6 */
"code" { return K_CODE; }
"echo-request" { return K_ECHO_REQUEST; }
@@ -192,6 +220,7 @@ ip6_addr
(({a_hex}?:)?({a_hex}?:)?({a_hex}?:)?({a_hex}?:)?({a_hex}?:)?({a_hex}?:
"arp" { return K_ARP; }
"ip4"|"ipv4" { return K_IP4; }
"ip6"|"ipv6" { return K_IP6; }
+"icmp4"|"icmpv4" { return K_ICMP4; }
"icmp6"|"icmpv6" { return K_ICMP6; }
"udp" { return K_UDP; }
"tcp" { return K_TCP; }
diff --git a/trafgen_parser.y b/trafgen_parser.y
index adb7f5e..b15631b 100644
--- a/trafgen_parser.y
+++ b/trafgen_parser.y
@@ -19,6 +19,7 @@
#include <libgen.h>
#include <net/if_arp.h>
#include <netinet/in.h>
+#include <linux/icmp.h>
#include <linux/if_ether.h>
#include <linux/icmpv6.h>
@@ -362,11 +363,17 @@ static void proto_add(enum proto_id pid)
%token K_TPID K_TCI K_PCP K_DEI K_1Q K_1AD
%token K_LABEL K_TC K_LAST K_EXP
+%token K_ADDR K_MTU
+%token K_NET_UNREACH K_HOST_UNREACH K_PORT_UNREACH K_PROT_UNREACH
K_NET_TOS_UNREACH
+%token K_HOST_TOS_UNREACH K_FRAG_NEEDED K_ROUTE_FAILED K_NET_UNKNOWN
K_HOST_UNKNOWN
+%token K_HOST_ISOLATED K_NET_FORBIDDEN K_HOST_FORBIDDEN K_PKT_FILTERED
K_NET_REDIRECT
+%token K_HOST_REDIRECT K_NET_TOS_REDIRECT K_HOST_TOS_REDIRECT K_TIMEOUT_TTL
K_TIMEOUT_FRAG
+
%token K_ETH
%token K_VLAN K_MPLS
%token K_ARP
%token K_IP4 K_IP6
-%token K_ICMP6
+%token K_ICMP4 K_ICMP6
%token K_UDP K_TCP
%token ',' '{' '}' '(' ')' '[' ']' ':' '-' '+' '*' '/' '%' '&' '|' '<' '>' '^'
@@ -594,6 +601,7 @@ proto
| arp_proto { }
| ip4_proto { }
| ip6_proto { }
+ | icmp4_proto { }
| icmpv6_proto { }
| udp_proto { }
| tcp_proto { }
@@ -817,6 +825,99 @@ ip6
: K_IP6 { proto_add(PROTO_IP6); }
;
+icmp4_proto
+ : icmp4 '(' icmp4_param_list ')' { }
+ ;
+
+icmp4_param_list
+ : { }
+ | icmp4_field { }
+ | icmp4_field delimiter icmp4_param_list { }
+ ;
+
+icmp4_field
+ : K_TYPE skip_white '=' skip_white number
+ { proto_field_set_u8(hdr, ICMPV4_TYPE, $5); }
+ | K_CODE skip_white '=' skip_white number
+ { proto_field_set_u8(hdr, ICMPV4_CODE, $5); }
+ | K_ID skip_white '=' skip_white number
+ { proto_field_set_be16(hdr, ICMPV4_ID, $5); }
+ | K_SEQ skip_white '=' skip_white number
+ { proto_field_set_be16(hdr, ICMPV4_SEQ, $5); }
+ | K_MTU skip_white '=' skip_white number
+ { proto_field_set_be16(hdr, ICMPV4_MTU, $5); }
+ | K_ADDR skip_white '=' skip_white ip4_addr
+ { proto_field_set_u32(hdr, ICMPV4_REDIR_ADDR, $5.s_addr); }
+ | icmp4_unreach
+ { proto_field_set_u8(hdr, ICMPV4_TYPE, ICMP_DEST_UNREACH); }
+ | icmp4_redir
+ { proto_field_set_u8(hdr, ICMPV4_TYPE, ICMP_REDIRECT); }
+ | icmp4_echo
+ { }
+ | icmp4_timeout
+ { proto_field_set_u8(hdr, ICMPV4_TYPE, ICMP_TIME_EXCEEDED); }
+ ;
+
+icmp4_timeout
+ : K_TIMEOUT_TTL
+ { proto_field_set_be16(hdr, ICMPV4_CODE, ICMP_EXC_TTL); }
+ | K_TIMEOUT_FRAG
+ { proto_field_set_be16(hdr, ICMPV4_CODE, ICMP_EXC_FRAGTIME); }
+ ;
+
+icmp4_echo
+ : K_ECHO_REQUEST
+ { proto_field_set_u8(hdr, ICMPV4_TYPE, ICMP_ECHO);
+ proto_field_set_u8(hdr, ICMPV4_CODE, 0); }
+ | K_ECHO_REPLY
+ { proto_field_set_u8(hdr, ICMPV4_TYPE, ICMP_ECHOREPLY);
+ proto_field_set_u8(hdr, ICMPV4_CODE, 0); }
+ ;
+
+icmp4_redir
+ : K_NET_REDIRECT
+ { proto_field_set_u8(hdr, ICMPV4_CODE, ICMP_REDIR_NET); }
+ | K_HOST_REDIRECT
+ { proto_field_set_u8(hdr, ICMPV4_CODE, ICMP_REDIR_HOST); }
+ | K_NET_TOS_REDIRECT
+ { proto_field_set_u8(hdr, ICMPV4_CODE, ICMP_REDIR_NETTOS); }
+ | K_HOST_TOS_REDIRECT
+ { proto_field_set_u8(hdr, ICMPV4_CODE, ICMP_REDIR_HOSTTOS); }
+ ;
+
+icmp4_unreach
+ : K_NET_UNREACH
+ { proto_field_set_u8(hdr, ICMPV4_CODE, ICMP_NET_UNREACH); }
+ | K_HOST_UNREACH
+ { proto_field_set_u8(hdr, ICMPV4_CODE, ICMP_HOST_UNREACH); }
+ | K_PROT_UNREACH
+ { proto_field_set_u8(hdr, ICMPV4_CODE, ICMP_PROT_UNREACH); }
+ | K_PORT_UNREACH
+ { proto_field_set_u8(hdr, ICMPV4_CODE, ICMP_PORT_UNREACH); }
+ | K_NET_TOS_UNREACH
+ { proto_field_set_u8(hdr, ICMPV4_CODE, ICMP_NET_UNR_TOS); }
+ | K_HOST_TOS_UNREACH
+ { proto_field_set_u8(hdr, ICMPV4_CODE, ICMP_HOST_UNR_TOS); }
+ | K_NET_UNKNOWN
+ { proto_field_set_u8(hdr, ICMPV4_CODE, ICMP_NET_UNKNOWN); }
+ | K_HOST_UNKNOWN
+ { proto_field_set_u8(hdr, ICMPV4_CODE, ICMP_HOST_UNKNOWN); }
+ | K_NET_FORBIDDEN
+ { proto_field_set_u8(hdr, ICMPV4_CODE, ICMP_NET_ANO); }
+ | K_HOST_FORBIDDEN
+ { proto_field_set_u8(hdr, ICMPV4_CODE, ICMP_HOST_ANO); }
+ | K_FRAG_NEEDED
+ { proto_field_set_u8(hdr, ICMPV4_CODE, ICMP_FRAG_NEEDED); }
+ | K_ROUTE_FAILED
+ { proto_field_set_u8(hdr, ICMPV4_CODE, ICMP_SR_FAILED); }
+ | K_PKT_FILTERED
+ { proto_field_set_u8(hdr, ICMPV4_CODE, ICMP_PKT_FILTERED); }
+ ;
+
+icmp4
+ : K_ICMP4 { proto_add(PROTO_ICMP4); }
+ ;
+
icmpv6_proto
: icmp6 '(' icmp6_param_list ')' { }
--
2.6.3
--
You received this message because you are subscribed to the Google Groups
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.