Marco Varlese | b598f1d | 2017-09-19 14:25:28 +0200 | [diff] [blame] | 1 | diff --git a/scapy/layers/geneve.py b/scapy/layers/geneve.py |
| 2 | new file mode 100644 |
| 3 | index 0000000..e2ca888 |
| 4 | --- /dev/null |
| 5 | +++ b/scapy/layers/geneve.py |
| 6 | @@ -0,0 +1,50 @@ |
| 7 | +#! /usr/bin/env python |
| 8 | +# (GENEVE): |
| 9 | +# A Framework for Overlaying Virtualized Layer 2 Networks over Layer 3 Networks |
| 10 | + |
| 11 | +from scapy.packet import Packet, bind_layers |
| 12 | +from scapy.layers.l2 import Ether |
| 13 | +from scapy.layers.inet import IP, UDP |
| 14 | +from scapy.layers.inet6 import IPv6 |
| 15 | +from scapy.fields import FlagsField, XByteField, ThreeBytesField, \ |
| 16 | + ConditionalField, ShortField, ByteEnumField, X3BytesField |
| 17 | + |
| 18 | +# |
| 19 | +# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 20 | +# |Ver| Opt Len |O|C| Rsvd. | Protocol Type | |
| 21 | +# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 22 | +# | Virtual Network Identifier (VNI) | Reserved | |
| 23 | +# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 24 | +# | Variable Length Options | |
| 25 | +# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 26 | +# |
| 27 | + |
| 28 | +class GENEVE(Packet): |
| 29 | + name = "GENEVE" |
| 30 | + |
| 31 | + fields_desc = [ |
| 32 | + # INIT = ver + optlen + o + c + rsvd (all zeros) |
| 33 | + ShortField("init", 0x0), |
| 34 | + # PROTOCOL is a 2-bytes field |
| 35 | + ShortField("protocol", 0x6558), |
| 36 | + ThreeBytesField("vni", 0), |
| 37 | + XByteField("reserved2", 0), |
| 38 | + ] |
| 39 | + |
| 40 | + def mysummary(self): |
| 41 | + return self.sprintf("GENEVE (vni=%GENEVE.vni%)") |
| 42 | + |
| 43 | +bind_layers(UDP, GENEVE, dport=6081) # RFC standard port |
| 44 | +bind_layers(UDP, GENEVE, dport=6081) # New IANA assigned port for use with NSH |
| 45 | +bind_layers(UDP, GENEVE, dport=8472) # Linux implementation port |
| 46 | +# By default, set both ports to the RFC standard |
| 47 | +bind_layers(UDP, GENEVE, sport=6081, dport=6081) |
| 48 | + |
| 49 | +bind_layers(GENEVE, Ether) |
| 50 | +bind_layers(GENEVE, IP, NextProtocol=1) |
| 51 | +bind_layers(GENEVE, IPv6, NextProtocol=2) |
| 52 | +bind_layers(GENEVE, Ether, flags=4, NextProtocol=0) |
| 53 | +bind_layers(GENEVE, IP, flags=4, NextProtocol=1) |
| 54 | +bind_layers(GENEVE, IPv6, flags=4, NextProtocol=2) |
| 55 | +bind_layers(GENEVE, Ether, flags=4, NextProtocol=3) |
| 56 | + |