summaryrefslogtreecommitdiff
path: root/trafgen_lexer.l
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2016-04-22 16:55:31 +0200
committerTobias Klauser <tklauser@distanz.ch>2016-04-25 17:56:34 +0200
commitc09e06a6efaa94768660636a9c58ce9666e29d05 (patch)
treea41455899d30c7a8de30fdc9eb917702d9769975 /trafgen_lexer.l
parent0cf15c320f9211d59b055157c895537e4b682a07 (diff)
trafgen: proto: Add IPv6 header generation
Support for generating simple IPv6 headers using the 'ip6()/ipv6()' trafgen generation function. Fields supported: ver|version Version (default: 6) tc|tclass Traffic class (default: 0) fl|flow Flow Label (default: 0) len|length Payload length (calculated by default) nh|nexthdr Type of next header (default: 0) hl|hoplimit|ttl Hop Limit, TTL (default: 0) sa|saddr Source IPv6 address (default: device address) da|daddr Destination IPv6 address (default: 0:0:0:0:0:0:0:0) Examples: { eth(), ipv6(daddr=1:2:3:4:5:6:7:8) } { ipv6(tc=2, hl=3, daddr=::1) } { eth(), ipv6(nh=58, sa=2001:db8::, da=::1), 128, 0, 0x52, 0x03, 0, 0, 0, 0 } If not explicitely specified, the lower header is initialized as Ethernet. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'trafgen_lexer.l')
-rw-r--r--trafgen_lexer.l20
1 files changed, 17 insertions, 3 deletions
diff --git a/trafgen_lexer.l b/trafgen_lexer.l
index 3c624f8..a093ac1 100644
--- a/trafgen_lexer.l
+++ b/trafgen_lexer.l
@@ -77,9 +77,13 @@ number_bin ([0]?[b][0-1]+)
number_dec (([0])|([1-9][0-9]*))
number_ascii ([a-zA-Z])
-mac_hex ([a-fA-F0-9]+)
-mac ({mac_hex}:{mac_hex}:{mac_hex}:{mac_hex}:{mac_hex}:{mac_hex})
+a_hex ([a-fA-F0-9]+)
+mac ({a_hex}:{a_hex}:{a_hex}:{a_hex}:{a_hex}:{a_hex})
ip4_addr ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)
+ /* We're very permissive about IPv6 addresses the grammar accepts, as
+ * they can come in various different formats. In any case,
+ * inet_pton(AF_INET6, ...) will reject the invalid ones later on. */
+ip6_addr (({a_hex}?:)?({a_hex}?:)?({a_hex}?:)?({a_hex}?:)?({a_hex}?:)?({a_hex}?:)?({a_hex}?:)?({a_hex})?)
%%
@@ -106,6 +110,7 @@ ip4_addr ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)
"const64"|"c64" { return K_CONST64; }
"prot"[o]? { return K_PROT; }
+"tc"|"tclass" { return K_TC; }
/* Ethernet */
"daddr"|"da" { return K_DADDR; }
@@ -123,7 +128,6 @@ ip4_addr ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)
/* MPLS (Multi Protocol Label Switching) */
"lbl"|"label" { return K_LABEL; }
"last" { return K_LAST; }
-"tc"|"tclass" { return K_TC; }
"exp" { return K_EXP; }
/* ARP */
@@ -152,6 +156,11 @@ ip4_addr ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)
"df" { return K_DF; }
"mf" { return K_MF; }
+ /* IPv6 */
+"fl"|"flow" { return K_FLOW; }
+"nh"|"nexthdr" { return K_NEXT_HDR; }
+"hl"|"hoplimit" { return K_HOP_LIMIT; }
+
/* UDP */
"sp"|"sport" { return K_SPORT; }
"dp"|"dport" { return K_DPORT; }
@@ -176,6 +185,7 @@ ip4_addr ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)
"mpls" { return K_MPLS; }
"arp" { return K_ARP; }
"ip4"|"ipv4" { return K_IP4; }
+"ip6"|"ipv6" { return K_IP6; }
"udp" { return K_UDP; }
"tcp" { return K_TCP; }
@@ -235,6 +245,10 @@ ip4_addr ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)
panic("Failed to parse IPv4 address %s\n", yytext);
return ip4_addr; };
+{ip6_addr} { if (inet_pton(AF_INET6, yytext, &yylval.ip6_addr) != 1)
+ panic("Failed to parse IPv6 address %s\n", yytext);
+ return ip6_addr; };
+
"'\\x"[a-fA-F0-9]{2}"'" { yylval.number = strtol(yytext + 3, NULL, 16);
return number; }