Skip to content

Commit 07854ab

Browse files
gpotter2Ivan StepanenkoElKobano
authored
Fqdn (#4598)
* FQDN coding fix * Update gtp_v2.uts * Fix PEP8 --------- Co-authored-by: Ivan Stepanenko <[email protected]> Co-authored-by: ElKobano <[email protected]>
1 parent 62e335d commit 07854ab

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

scapy/contrib/gtp.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
from scapy.layers.inet import IP, UDP
4646
from scapy.layers.inet6 import IPv6, IP6Field
4747
from scapy.layers.ppp import PPP
48+
from scapy.layers.dns import DNSStrField
4849
from scapy.packet import bind_layers, bind_bottom_up, bind_top_down, \
4950
Packet, Raw
5051
from scapy.volatile import RandInt, RandIP, RandNum, RandString
@@ -208,6 +209,24 @@ def i2m(self, pkt, val):
208209
return ret_string
209210

210211

212+
class FQDNField(DNSStrField):
213+
"""
214+
DNSStrField without ending null.
215+
216+
See ETSI TS 129.244 18.07.00 - 8.66, NOTE 1
217+
"""
218+
219+
def h2i(self, pkt, x):
220+
return bytes_encode(x)
221+
222+
def i2m(self, pkt, x):
223+
return b"".join(chb(len(y)) + y for y in (k[:63] for k in x.split(b".")))
224+
225+
def getfield(self, pkt, s):
226+
remain, s = super().getfield(pkt, s)
227+
return remain, s[:-1]
228+
229+
211230
TBCD_TO_ASCII = b"0123456789*#abc"
212231

213232

scapy/contrib/gtp_v2.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,8 +591,7 @@ class IE_FQDN(gtp.IE_Base):
591591
ShortField("length", None),
592592
BitField("CR_flag", 0, 4),
593593
BitField("instance", 0, 4),
594-
ByteField("fqdn_tr_bit", 0),
595-
StrLenField("fqdn", "", length_from=lambda x: x.length - 1)]
594+
gtp.FQDNField("fqdn", b"", length_from=lambda x: x.length)]
596595

597596

598597
class IE_NotImplementedTLV(gtp.IE_Base):

test/contrib/gtp_v2.uts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,16 @@ ie = IE_MMContext_EPS(ietype=107, length=70, CR_flag=0, instance=0, Sec_Mode=4,
199199
ie.Sec_Mode == 4 and ie.Nhi == 0 and ie.Drxi == 1 and ie.Ksi == 0 and ie.Num_quint == 0 and ie.Num_Quad == 0 and ie.Uambri == 0 and ie.Osci == 0 and ie.Sambri == 1 and ie.Nas_algo == 1 and ie.Nas_cipher == 1 and ie.Nas_dl_count == 2 and ie.Nas_ul_count == 2 and ie.Kasme == 11111111111111111111111111111111111111111111111111111111111111111111111111111
200200

201201
= IE_PDNConnection, IE_FQDN, dissection
202-
h = "d89ef3da40e2fa163e956dce08004500007f0001000040114bbd0a0a0f3d0a0f0b5b084b084b006b5a234883005f0000180f76d163006b0046008800910000020000021890aa80be385102083701a2907066f8bd9f2a28b717671c71c71c71c71c71c70100003d090002625a00028040000812345678900000000000000000006d000900880005000470677731"
202+
h = "d89ef3da40e2fa163e956dce08004500008a0001000040114bbd0a0a0f3d0a0f0b5b084b084b00765a234883006a0000180f76d163006b0046008800910000020000021890aa80be385102083701a2907066f8bd9f2a28b717671c71c71c71c71c71c70100003d090002625a00028040000812345678900000000000000000006d0014008800100004706777310474657374056c6f63616c"
203203
gtp = Ether(hex_bytes(h))
204204
ie = gtp.IE_list[1].IE_list[0]
205-
ie.fqdn_tr_bit == 4 and ie.fqdn == b'pgw1'
205+
ie.fqdn == b'pgw1.test.local'
206+
gtp.build().hex() == h
206207

207208
= IE_PDNConnection, IE_FQDN, basic instantiation
208-
ie = IE_PDNConnection(IE_list=[IE_FQDN(ietype=136, length=5, CR_flag=0, instance=0, fqdn_tr_bit=4, fqdn=b'pgw1')], ietype=109, length=9, CR_flag=0, instance=0)
209+
ie = IE_PDNConnection(IE_list=[IE_FQDN(ietype=136, length=5, CR_flag=0, instance=0, fqdn=b'pgw1.test.local')], ietype=109, length=9, CR_flag=0, instance=0)
209210
ie2 = ie.IE_list[0]
210-
ie2.fqdn_tr_bit == 4 and ie2.fqdn == b'pgw1'
211+
ie2.fqdn == b'pgw1.test.local'
211212

212213
= IE_PAA, dissection
213214
h = "3333333333332222222222228100a384080045b800ed00000000fc1193430a2a00010a2a00027f61084b00d91c47482000cd140339f4d99f66000100080002081132547600004b000800000000000001e24056000d001832f420303932f4200001e2405300030032f4205200010006570009008a000010927f0000025700090187000010927f00000247001a00196161616161616161616161616161616161616161616161616163000100014f000500017f0000034d0004000808000048000800000017000000a4105d002c0049000100e55700090385000010927f00000250001600580700000000000000000000000000000000000000007200020014005311004c"

0 commit comments

Comments
 (0)