From e09ebb4383f1775f66289086a88d6ed18c541dac Mon Sep 17 00:00:00 2001
From: Pierre Lorinquer <pierre.lorinquer@ssi.gouv.fr>
Date: Wed, 29 Mar 2017 16:11:57 +0200
Subject: [PATCH] Update following p-l- comments.

The conditions for the tls_data and data fields (in the EAP_TLS and
EAP_FAST classes) were written in a more concise manner.
---
 scapy/layers/l2.py | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/scapy/layers/l2.py b/scapy/layers/l2.py
index d5032ef7..b3c626dd 100644
--- a/scapy/layers/l2.py
+++ b/scapy/layers/l2.py
@@ -539,12 +539,11 @@ class EAP_MD5(EAP):
         ByteEnumField("code", 1, eap_codes),
         ByteField("id", 0),
         FieldLenField("len", None, fmt="H", length_of="optional_name",
-                adjust=lambda p, x: (x + p.value_size + 6) if p.value_size is not None else 6),
+                      adjust=lambda p, x: x + 6 + (p.value_size or 0)),
         ByteEnumField("type", 4, eap_types),
         FieldLenField("value_size", None, fmt="B", length_of="value"),
         XStrLenField("value", '', length_from=lambda p: p.value_size),
-        XStrLenField("optional_name", '',
-                length_from=lambda p: (p.len - p.value_size - 6) if p.len is not None and p.value_size is not None else 0)
+        XStrLenField("optional_name", '', length_from=lambda p: 0 if p.len is None or p.value_size is None else (p.len - p.value_size - 6))
     ]
 
 
@@ -565,8 +564,7 @@ class EAP_TLS(EAP):
         BitField('S', 0, 1),
         BitField('reserved', 0, 5),
         ConditionalField(IntField('tls_message_len', 0), lambda pkt: pkt.L == 1),
-        XStrLenField('tls_data', '',
-                length_from=lambda pkt: pkt.len - 10 if pkt.len is not None and pkt.L == 1 else pkt.len - 6 if pkt.len is not None else 0)
+        XStrLenField('tls_data', '', length_from=lambda pkt: 0 if pkt.len is None else pkt.len - (6 + 4 * pkt.L))
     ]
 
 
@@ -589,8 +587,7 @@ class EAP_FAST(EAP):
         BitField('reserved', 0, 2),
         BitField('version', 0, 3),
         ConditionalField(IntField('message_len', 0), lambda pkt: pkt.L == 1),
-        XStrLenField('data', '', 
-                length_from=lambda pkt: pkt.len - 10 if pkt.len is not None and pkt.L == 1 else pkt.len - 6 if pkt.len is not None else 0)
+        XStrLenField('data', '', length_from=lambda pkt: 0 if pkt.len is None else pkt.len - (6 + 4 * pkt.L))
     ]
 
 
@@ -1110,7 +1107,7 @@ bind_layers( CookedLinux,   EAPOL,         proto=34958)
 bind_layers( GRE,           LLC,           proto=122)
 bind_layers( GRE,           Dot1Q,         proto=33024)
 bind_layers( GRE,           Dot1AD,        type=0x88a8)
-bind_layers( GRE,           Ether,         proto=1)
+bind_layers( GRE,           Ether,         proto=0x6558)
 bind_layers( GRE,           ARP,           proto=2054)
 bind_layers( GRE,           EAPOL,         proto=34958)
 bind_layers( GRE,           GRErouting,    { "routing_present" : 1 } )
-- 
GitLab