Skip to content

Commit d2d76fc

Browse files
GRE-in-UDP uses port 4754 (see RFC 8086) (#4057)
* GRE-in-UDP uses port 4754 (see RFC 8086) Signed-off-by: Alex Forencich <alex@alexforencich.com> * Add GRE layer binding tests Signed-off-by: Alex Forencich <alex@alexforencich.com> --------- Signed-off-by: Alex Forencich <alex@alexforencich.com>
1 parent 5b75126 commit d2d76fc

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

scapy/layers/inet.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,7 @@ def mysummary(self):
10891089
bind_layers(IP, TCP, frag=0, proto=6)
10901090
bind_layers(IP, UDP, frag=0, proto=17)
10911091
bind_layers(IP, GRE, frag=0, proto=47)
1092+
bind_layers(UDP, GRE, dport=4754)
10921093

10931094
conf.l2types.register(DLT_RAW, IP)
10941095
conf.l2types.register_num2layer(DLT_RAW_ALT, IP)

test/scapy/layers/inet.uts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,60 @@ with mock.patch("scapy.layers.l2.getmacbyip", side_effect=_err):
595595
except ValueError:
596596
pass
597597

598+
= GRE binding tests
599+
600+
* Test GRE-in-IP
601+
pkt = Ether(raw(Ether()/IP()/GRE()/IP()/UDP()))
602+
assert isinstance(pkt, Ether)
603+
pkt = pkt.payload
604+
assert isinstance(pkt, IP) and pkt.proto == 47
605+
pkt = pkt.payload
606+
assert isinstance(pkt, GRE) and pkt.proto == 0x0800
607+
pkt = pkt.payload
608+
assert isinstance(pkt, IP)
609+
pkt = pkt.payload
610+
assert isinstance(pkt, UDP)
611+
612+
* Test GRE-in-IPv6
613+
pkt = Ether(raw(Ether()/IPv6()/GRE()/IPv6()/UDP()))
614+
assert isinstance(pkt, Ether)
615+
pkt = pkt.payload
616+
assert isinstance(pkt, IPv6) and pkt.nh == 47
617+
pkt = pkt.payload
618+
assert isinstance(pkt, GRE) and pkt.proto == 0x86dd
619+
pkt = pkt.payload
620+
assert isinstance(pkt, IPv6)
621+
pkt = pkt.payload
622+
assert isinstance(pkt, UDP)
623+
624+
* Test GRE-in-UDP
625+
pkt = Ether(raw(Ether()/IP()/UDP()/GRE()/IP()/UDP()))
626+
assert isinstance(pkt, Ether)
627+
pkt = pkt.payload
628+
assert isinstance(pkt, IP)
629+
pkt = pkt.payload
630+
assert isinstance(pkt, UDP) and pkt.dport == 4754
631+
pkt = pkt.payload
632+
assert isinstance(pkt, GRE) and pkt.proto == 0x0800
633+
pkt = pkt.payload
634+
assert isinstance(pkt, IP)
635+
pkt = pkt.payload
636+
assert isinstance(pkt, UDP)
637+
638+
* Test GRE-in-UDP (IPv6)
639+
pkt = Ether(raw(Ether()/IPv6()/UDP()/GRE()/IPv6()/UDP()))
640+
assert isinstance(pkt, Ether)
641+
pkt = pkt.payload
642+
assert isinstance(pkt, IPv6)
643+
pkt = pkt.payload
644+
assert isinstance(pkt, UDP) and pkt.dport == 4754
645+
pkt = pkt.payload
646+
assert isinstance(pkt, GRE) and pkt.proto == 0x86dd
647+
pkt = pkt.payload
648+
assert isinstance(pkt, IPv6)
649+
pkt = pkt.payload
650+
assert isinstance(pkt, UDP)
651+
598652
############
599653
############
600654
+ inet.py

0 commit comments

Comments
 (0)