Add 'mpls()' function for creating MPLS header with parameters:

        lbl|label       MPLS label
        last            Indicates the last label on MPLS stack
        tc|tclass       Traffic Class
        ttl             TTL (Time To Live)

Currently only unicast MPLS is supported, but multicast might be set
via 'eth()' function.

Signed-off-by: Vadim Kochan <vadi...@gmail.com>
---
 trafgen_lexer.l  |  6 ++++++
 trafgen_parser.y | 29 ++++++++++++++++++++++++++++-
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/trafgen_lexer.l b/trafgen_lexer.l
index e1d1a3f..58c96f7 100644
--- a/trafgen_lexer.l
+++ b/trafgen_lexer.l
@@ -120,6 +120,11 @@ ip4_addr   ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)
 "1ad"          { return K_1AD; }
 "1q"           { return K_1Q; }
 
+       /* MPLS (Multi Protocol Label Switching) */
+"lbl"|"label"  { return K_LABEL; }
+"last"         { return K_LAST; }
+"tc"|"tclass"  { return K_TC; }
+
        /* ARP */
 "sha"|"smac"   { return K_SHA; }
 "spa"|"sip"    { return K_SPA; }
@@ -167,6 +172,7 @@ ip4_addr    ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)
 
 "eth"          { return K_ETH; }
 "vlan"         { return K_VLAN; }
+"mpls"         { return K_MPLS; }
 "arp"          { return K_ARP; }
 "ip4"|"ipv4"   { return K_IP4; }
 "udp"          { return K_UDP; }
diff --git a/trafgen_parser.y b/trafgen_parser.y
index 655b0ba..5c11297 100644
--- a/trafgen_parser.y
+++ b/trafgen_parser.y
@@ -356,9 +356,10 @@ static void proto_add(enum proto_id pid)
 %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_TPID K_TCI K_PCP K_DEI K_1Q K_1AD
+%token K_LABEL K_TC K_LAST
 
 %token K_ETH
-%token K_VLAN
+%token K_VLAN K_MPLS
 %token K_ARP
 %token K_IP4
 %token K_UDP K_TCP
@@ -583,6 +584,7 @@ ddec
 proto
        : eth_proto { }
        | vlan_proto { }
+       | mpls_proto { }
        | arp_proto { }
        | ip4_proto { }
        | udp_proto { }
@@ -653,6 +655,31 @@ vlan_field
                { proto_field_set_be16(hdr, VLAN_VID, $5); }
        ;
 
+mpls_proto
+       : mpls '(' mpls_param_list ')' { }
+       ;
+
+mpls
+       : K_MPLS { proto_add(PROTO_MPLS); }
+       ;
+
+mpls_param_list
+       : { }
+       | mpls_field { }
+       | mpls_field delimiter mpls_param_list { }
+       ;
+
+mpls_field
+       : K_LABEL skip_white '=' skip_white number
+               { proto_field_set_be32(hdr, MPLS_LABEL, $5); }
+       | K_TC skip_white '=' skip_white number
+               { proto_field_set_be32(hdr, MPLS_TC, $5); }
+       | K_LAST skip_white '=' skip_white number
+               { proto_field_set_be32(hdr, MPLS_LAST, $5); }
+       | K_TTL skip_white '=' skip_white number
+               { proto_field_set_be32(hdr, MPLS_TTL, $5); }
+       ;
+
 arp_proto
        : arp '(' arp_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 netsniff-ng+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to