Skip to content

Commit 18d4c30

Browse files
authored
Fix GTP payload length computation (#3822)
Reducing length of 'length' field along with 'ietype' and 'CR_flag+instance'
1 parent a0d2d9d commit 18d4c30

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

scapy/contrib/gtp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ def post_build(self, p, pay):
451451
tmp_len = len(p)
452452
if isinstance(self.payload, conf.padding_layer):
453453
tmp_len += len(self.payload.load)
454-
p = p[:1] + struct.pack("!H", tmp_len - 2) + p[3:]
454+
p = p[:1] + struct.pack("!H", tmp_len - 4) + p[3:]
455455
return p + pay
456456

457457

test/contrib/gtp_v2.uts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ gtp.dport == 2123 and gtp.seq == 12345 and gtp.gtp_type == 1 and gtp.T == 0
1616
= GTPV2CreateSessionRequest, basic instantiation
1717
gtp = IP() / UDP(dport=2123) / \
1818
GTPHeader(gtp_type="create_session_req", teid=2807, seq=12345) / \
19-
GTPV2CreateSessionRequest()
20-
gtp.dport == 2123 and gtp.teid == 2807 and gtp.seq == 12345
19+
GTPV2CreateSessionRequest(IE_list=[IE_IMSI(IMSI=b'001030000000356'),IE_APN(APN=b'super')])
20+
21+
assert gtp.dport == 2123 and gtp.teid == 2807 and gtp.seq == 12345
22+
ie = gtp.IE_list[1]
23+
assert ie.APN == b"super"
2124

2225
= GTPV2EchoRequest, dissection
2326
h = "333333333333222222222222810080c808004588002937dd0000fd1115490a2a00010a2a0002084b084b00152d0e4001000900000100030001000daa000000003f1f382f"

0 commit comments

Comments
 (0)