diff --git a/scapy/contrib/eigrp.py b/scapy/contrib/eigrp.py index 73b4ce022bf60ca2f17010be0bb0869992f8d869..54b8ce8fbe03887ef579dc29d66a348e268b4974 100644 --- a/scapy/contrib/eigrp.py +++ b/scapy/contrib/eigrp.py @@ -168,10 +168,6 @@ class EigrpIP6Field(StrField, IP6Field, EigrpIPField): def getfield(self, pkt, s): return EigrpIPField.getfield(self, pkt, s) -class ThreeBytesField(X3BytesField, ByteField): - def i2repr(self, pkt, x): - return ByteField.i2repr(self, pkt, x) - class EIGRPGeneric(Packet): name = "EIGRP Generic TLV" diff --git a/scapy/contrib/vxlan.py b/scapy/contrib/vxlan.py new file mode 100644 index 0000000000000000000000000000000000000000..d635eefe514c7a3101c07499369b94b801172c4c --- /dev/null +++ b/scapy/contrib/vxlan.py @@ -0,0 +1,26 @@ +# RFC 7348 - Virtual eXtensible Local Area Network (VXLAN): +# A Framework for Overlaying Virtualized Layer 2 Networks over Layer 3 Networks +# http://tools.ietf.org/html/rfc7348 + +# scapy.contrib.description = VXLAN +# scapy.contrib.status = loads + +from scapy.packet import Packet, bind_layers +from scapy.layers.l2 import Ether +from scapy.layers.inet import UDP +from scapy.fields import FlagsField, XByteField, ThreeBytesField + +_VXLAN_FLAGS = ['R' for i in range(0, 24)] + ['R', 'R', 'R', 'I', 'R', 'R', 'R', 'R', 'R'] + + +class VXLAN(Packet): + name = "VXLAN" + fields_desc = [FlagsField("flags", 0x08000000, 32, _VXLAN_FLAGS), + ThreeBytesField("vni", 0), + XByteField("reserved", 0x00)] + + def mysummary(self): + return self.sprintf("VXLAN (vni=%VXLAN.vni%)") + +bind_layers(UDP, VXLAN, dport=4789) +bind_layers(VXLAN, Ether) diff --git a/scapy/contrib/vxlan.uts b/scapy/contrib/vxlan.uts new file mode 100644 index 0000000000000000000000000000000000000000..16c0346f4d297efe672381ad822fcf59edd38f44 --- /dev/null +++ b/scapy/contrib/vxlan.uts @@ -0,0 +1,10 @@ +% VXLAN Tests +* Tests for the Scapy VXLAN layer + ++ Basic Layer Tests + += Build a VXLAN packet with VNI of 42 +str(UDP(sport=1024, dport=4789, len=None, chksum=None)/VXLAN(flags=0x08000000, vni=42)) == "\x04\x00\x12\xb5\x00\x10\x00\x00\x08\x00\x00\x00\x00\x00\x2a\x00" + += Verify VXLAN Ethernet Binding +str(VXLAN(vni=23)/Ether(dst="11:11:11:11:11:11", src="11:11:11:11:11:11", type=0x800)) == "\x08\x00\x00\x00\x00\x00\x17\x00\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x08\x00" diff --git a/scapy/fields.py b/scapy/fields.py index 50eebd0da51063855fa1bea252ff4c405944c543..db0b3ca08534200de5302e597bc227f6c55e18e3 100644 --- a/scapy/fields.py +++ b/scapy/fields.py @@ -275,6 +275,9 @@ class X3BytesField(XByteField): def getfield(self, pkt, s): return s[3:], self.m2i(pkt, struct.unpack(self.fmt, "\x00"+s[:3])[0]) +class ThreeBytesField(X3BytesField, ByteField): + def i2repr(self, pkt, x): + return ByteField.i2repr(self, pkt, x) class ShortField(Field): def __init__(self, name, default):