Skip to content

Commit

Permalink
GRE-in-UDP uses port 4754 (see RFC 8086) (#4057)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
alexforencich committed Feb 5, 2024
1 parent 5b75126 commit d2d76fc
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions scapy/layers/inet.py
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,7 @@ def mysummary(self):
bind_layers(IP, TCP, frag=0, proto=6)
bind_layers(IP, UDP, frag=0, proto=17)
bind_layers(IP, GRE, frag=0, proto=47)
bind_layers(UDP, GRE, dport=4754)

conf.l2types.register(DLT_RAW, IP)
conf.l2types.register_num2layer(DLT_RAW_ALT, IP)
Expand Down
54 changes: 54 additions & 0 deletions test/scapy/layers/inet.uts
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,60 @@ with mock.patch("scapy.layers.l2.getmacbyip", side_effect=_err):
except ValueError:
pass

= GRE binding tests

* Test GRE-in-IP
pkt = Ether(raw(Ether()/IP()/GRE()/IP()/UDP()))
assert isinstance(pkt, Ether)
pkt = pkt.payload
assert isinstance(pkt, IP) and pkt.proto == 47
pkt = pkt.payload
assert isinstance(pkt, GRE) and pkt.proto == 0x0800
pkt = pkt.payload
assert isinstance(pkt, IP)
pkt = pkt.payload
assert isinstance(pkt, UDP)

* Test GRE-in-IPv6
pkt = Ether(raw(Ether()/IPv6()/GRE()/IPv6()/UDP()))
assert isinstance(pkt, Ether)
pkt = pkt.payload
assert isinstance(pkt, IPv6) and pkt.nh == 47
pkt = pkt.payload
assert isinstance(pkt, GRE) and pkt.proto == 0x86dd
pkt = pkt.payload
assert isinstance(pkt, IPv6)
pkt = pkt.payload
assert isinstance(pkt, UDP)

* Test GRE-in-UDP
pkt = Ether(raw(Ether()/IP()/UDP()/GRE()/IP()/UDP()))
assert isinstance(pkt, Ether)
pkt = pkt.payload
assert isinstance(pkt, IP)
pkt = pkt.payload
assert isinstance(pkt, UDP) and pkt.dport == 4754
pkt = pkt.payload
assert isinstance(pkt, GRE) and pkt.proto == 0x0800
pkt = pkt.payload
assert isinstance(pkt, IP)
pkt = pkt.payload
assert isinstance(pkt, UDP)

* Test GRE-in-UDP (IPv6)
pkt = Ether(raw(Ether()/IPv6()/UDP()/GRE()/IPv6()/UDP()))
assert isinstance(pkt, Ether)
pkt = pkt.payload
assert isinstance(pkt, IPv6)
pkt = pkt.payload
assert isinstance(pkt, UDP) and pkt.dport == 4754
pkt = pkt.payload
assert isinstance(pkt, GRE) and pkt.proto == 0x86dd
pkt = pkt.payload
assert isinstance(pkt, IPv6)
pkt = pkt.payload
assert isinstance(pkt, UDP)

############
############
+ inet.py
Expand Down

0 comments on commit d2d76fc

Please sign in to comment.