Skip to content
Snippets Groups Projects
Commit 59740885 authored by Pierre Lalet's avatar Pierre Lalet Committed by GitHub
Browse files

Merge pull request #647 from GabrielGanne/nsh-len-default-value-fix

fix nsh len field init
parents bab1b7d9 41b3ed21
No related branches found
No related tags found
No related merge requests found
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
from scapy.all import bind_layers from scapy.all import bind_layers
from scapy.fields import BitField, ByteField, ByteEnumField from scapy.fields import BitField, ByteField, ByteEnumField
from scapy.fields import ShortField, X3BytesField, XIntField from scapy.fields import ShortField, X3BytesField, XIntField
from scapy.fields import ConditionalField, PacketListField from scapy.fields import ConditionalField, PacketListField, BitFieldLenField
from scapy.layers.inet import Ether, IP from scapy.layers.inet import Ether, IP
from scapy.layers.inet6 import IPv6 from scapy.layers.inet6 import IPv6
from scapy.layers.vxlan import VXLAN from scapy.layers.vxlan import VXLAN
...@@ -47,7 +47,9 @@ class NSH(Packet): ...@@ -47,7 +47,9 @@ class NSH(Packet):
BitField('OAM', 0, 1), BitField('OAM', 0, 1),
BitField('Critical', 0, 1), BitField('Critical', 0, 1),
BitField('Reserved', 0, 6), BitField('Reserved', 0, 6),
BitField('Len', 0, 6), BitFieldLenField('Len', None, 6,
count_of='ContextHeaders',
adjust=lambda pkt, x: 6 if pkt.MDType == 1 else x + 2),
ByteEnumField('MDType', 1, {1: 'Fixed Length', ByteEnumField('MDType', 1, {1: 'Fixed Length',
2: 'Variable Length'}), 2: 'Variable Length'}),
ByteEnumField('NextProto', 3, {1: 'IPv4', ByteEnumField('NextProto', 3, {1: 'IPv4',
......
...@@ -8,10 +8,11 @@ from scapy.contrib.nsh import * ...@@ -8,10 +8,11 @@ from scapy.contrib.nsh import *
+ Basic Layer Tests + Basic Layer Tests
= Build a NSH over NSH packet with NSP=42, and NSI=1 = Build a NSH over NSH packet with NSP=42, and NSI=1
str(NSH(Len=2, NSP=42, NSI=1)/NSH()) == b'\x00\x02\x01\x04\x00\x00*\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x03\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' str(NSH(NSP=42, NSI=1)/NSH()) == b'\x00\x06\x01\x04\x00\x00*\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x06\x01\x03\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
= Build a Ethernet over NSH over Ethernet packet (NSH over Ethernet encapsulating the original packet) and verify Ethernet Bindings = Build a Ethernet over NSH over Ethernet packet (NSH over Ethernet encapsulating the original packet) and verify Ethernet Bindings
str(Ether(src="00:00:00:00:00:01", dst="00:00:00:00:00:02")/NSH()/Ether(src="00:00:00:00:00:03", dst="00:00:00:00:00:04")/ARP(psrc="10.0.0.1", hwsrc="00:00:00:00:00:01")) == b'\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x01\x89O\x00\x00\x01\x03\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x03\x08\x06\x00\x01\x08\x00\x06\x04\x00\x01\x00\x00\x00\x00\x00\x01\n\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' str(Ether(src="00:00:00:00:00:01", dst="00:00:00:00:00:02")/NSH()/Ether(src="00:00:00:00:00:03", dst="00:00:00:00:00:04")/ARP(psrc="10.0.0.1", hwsrc="00:00:00:00:00:01")) == b'\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x01\x89O\x00\x06\x01\x03\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x03\x08\x06\x00\x01\x08\x00\x06\x04\x00\x01\x00\x00\x00\x00\x00\x01\n\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
= Build a NSH over GRE packet, and verify GRE Bindings = Build a NSH over GRE packet, and verify GRE Bindings
str(Ether(src="00:00:00:00:00:01", dst="00:00:00:00:00:02")/IP(src="1.1.1.1", dst="2.2.2.2")/GRE()/NSH()/Ether(src="00:00:00:00:00:03", dst="00:00:00:00:00:04")/ARP(psrc="10.0.0.1", hwsrc="00:00:00:00:00:01")) == '\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x01\x08\x00\x45\x00\x00\x5a\x00\x01\x00\x00\x40\x2f\x74\x6f\x01\x01\x01\x01\x02\x02\x02\x02\x00\x00\x89\x4f\x00\x00\x01\x03\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x03\x08\x06\x00\x01\x08\x00\x06\x04\x00\x01\x00\x00\x00\x00\x00\x01\x0a\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' str(Ether(src="00:00:00:00:00:01", dst="00:00:00:00:00:02")/IP(src="1.1.1.1", dst="2.2.2.2")/GRE()/NSH()/Ether(src="00:00:00:00:00:03", dst="00:00:00:00:00:04")/ARP(psrc="10.0.0.1", hwsrc="00:00:00:00:00:01")) == b'\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x01\x08\x00E\x00\x00Z\x00\x01\x00\x00@/to\x01\x01\x01\x01\x02\x02\x02\x02\x00\x00\x89O\x00\x06\x01\x03\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x03\x08\x06\x00\x01\x08\x00\x06\x04\x00\x01\x00\x00\x00\x00\x00\x01\n\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment