1*7dc08ffcSJunyu Lai# DNS OPT Resource Record unit tests 2*7dc08ffcSJunyu Lai# 3*7dc08ffcSJunyu Lai# Type the following command to launch start the tests: 4*7dc08ffcSJunyu Lai# $ sudo bash test/run_tests -t test/edns0.uts -F 5*7dc08ffcSJunyu Lai 6*7dc08ffcSJunyu Lai+ Test EDNS0 rdata 7*7dc08ffcSJunyu Lai 8*7dc08ffcSJunyu Lai= EDNS0TLV(), basic instanciation 9*7dc08ffcSJunyu Laitlv = EDNS0TLV() 10*7dc08ffcSJunyu Lairaw(tlv) == b'\x00\x00\x00\x00' 11*7dc08ffcSJunyu Lai 12*7dc08ffcSJunyu Lai= EDNS0TLV(), check parameters 13*7dc08ffcSJunyu Laitlv = EDNS0TLV(optcode=42, optlen=12, optdata="edns0tlv") 14*7dc08ffcSJunyu Lairaw(tlv) == b'\x00*\x00\x0cedns0tlv' 15*7dc08ffcSJunyu Lai 16*7dc08ffcSJunyu Lai= EDNS0TLV(), check computed optlen 17*7dc08ffcSJunyu Laitlv = EDNS0TLV(optdata="edns0tlv") 18*7dc08ffcSJunyu Lairaw(tlv) == b'\x00\x00\x00\x08edns0tlv' 19*7dc08ffcSJunyu Lai 20*7dc08ffcSJunyu Lai= EDNS0TLV(), dissection 21*7dc08ffcSJunyu Laitlv = EDNS0TLV(b'\x00*\x00\x08edns0tlv') 22*7dc08ffcSJunyu Laitlv.optcode == 42 and tlv.optlen == 8 and tlv.optdata == b"edns0tlv" 23*7dc08ffcSJunyu Lai 24*7dc08ffcSJunyu Lai+ Test OPT RR 25*7dc08ffcSJunyu Lai 26*7dc08ffcSJunyu Lai= DNSRROPT(), basic instanciation 27*7dc08ffcSJunyu Laiopt = DNSRROPT() 28*7dc08ffcSJunyu Lairaw(opt) == b'\x00\x00)\x10\x00\x00\x00\x80\x00\x00\x00' 29*7dc08ffcSJunyu Lai 30*7dc08ffcSJunyu Lai= DNSRROPT(), check parameters 31*7dc08ffcSJunyu Laiopt = DNSRROPT(rrname="rropt", type=42, rclass=123, extrcode=1, version=2, z=3, rdlen=4, rdata=[EDNS0TLV()]) 32*7dc08ffcSJunyu Lairaw(opt) == b'\x05rropt\x00\x00*\x00{\x01\x02\x00\x03\x00\x04\x00\x00\x00\x00' 33*7dc08ffcSJunyu Lai 34*7dc08ffcSJunyu Lai= DNSRROPT() & EDN0TLV(), check parameters 35*7dc08ffcSJunyu Laiopt = DNSRROPT(rrname="rropt", type=42, rclass=123, extrcode=1, version=2, z=3, rdlen=4, rdata=[EDNS0TLV(optcode=42, optlen=12, optdata="edns0tlv")]) 36*7dc08ffcSJunyu Lairaw(opt) == b'\x05rropt\x00\x00*\x00{\x01\x02\x00\x03\x00\x04\x00*\x00\x0cedns0tlv' 37*7dc08ffcSJunyu Lai 38*7dc08ffcSJunyu Lai= DNSRROP(), dissection 39*7dc08ffcSJunyu Laiopt = DNSRROPT(b'\x05rropt\x00\x00*\x00{\x01\x02\x00\x03\x00\x0c\x00*\x00\x0cedns0tlv') 40*7dc08ffcSJunyu Laiopt.rrname == b"rropt." and opt.rdlen == 12 and opt.rdata[0].optcode == 42 and opt.rdata[0].optdata == b"edns0tlv" 41*7dc08ffcSJunyu Lai 42*7dc08ffcSJunyu Lai+ Test EDNS-PING 43*7dc08ffcSJunyu Lai 44*7dc08ffcSJunyu Lai= EDNS-PING - basic instanciation 45*7dc08ffcSJunyu Laitlv = EDNS0TLV(optcode=5, optdata=b"\x00\x11\x22\x33") 46*7dc08ffcSJunyu Lairaw(tlv) == b'\x00\x05\x00\x04\x00\x11"3' 47*7dc08ffcSJunyu Lai 48*7dc08ffcSJunyu Lai#= EDNS-PING - Live test 49*7dc08ffcSJunyu Lai#~ netaccess 50*7dc08ffcSJunyu Lai#* NB: 85.17.219.217 and www.edns-ping.org seem down 51*7dc08ffcSJunyu Lai#old_debug_dissector = conf.debug_dissector 52*7dc08ffcSJunyu Lai#conf.debug_dissector = False 53*7dc08ffcSJunyu Lai#r = sr1(IP(dst="85.17.219.217")/UDP()/DNS(qd=[DNSQR(qtype="A", qname="www.edns-ping.org.")], ar=[DNSRROPT(z=0, rdata=[EDNS0TLV(optcode="PING", optdata=b"\x00\x11\x22\x33")])]), timeout=1) 54*7dc08ffcSJunyu Lai#conf.debug_dissector = old_debug_dissector 55*7dc08ffcSJunyu Lai#len(r.ar) and r.ar.rdata[0].optcode == 4 # XXX: should be 5 56*7dc08ffcSJunyu Lai 57*7dc08ffcSJunyu Lai+ Test DNS Name Server Identifier (NSID) Option 58*7dc08ffcSJunyu Lai 59*7dc08ffcSJunyu Lai= NSID- basic instanciation 60*7dc08ffcSJunyu Laitlv = EDNS0TLV(optcode=2, optdata="") 61*7dc08ffcSJunyu Lairaw(tlv) == b'\x00\x02\x00\x00' 62*7dc08ffcSJunyu Lai 63*7dc08ffcSJunyu Lai= NSID - Live test 64*7dc08ffcSJunyu Lai~ netaccess 65*7dc08ffcSJunyu Laiold_debug_dissector = conf.debug_dissector 66*7dc08ffcSJunyu Laiconf.debug_dissector = False 67*7dc08ffcSJunyu Lair = sr1(IP(dst="l.root-servers.net")/UDP()/DNS(qd=[DNSQR(qtype="SOA", qname=".")], ar=[DNSRROPT(z=0, rdata=[EDNS0TLV(optcode="NSID")])]), timeout=1) 68*7dc08ffcSJunyu Laiconf.debug_dissector = old_debug_dissector 69*7dc08ffcSJunyu Lailen(r.ar) and DNSRROPT in r.ar and len(r.ar[DNSRROPT].rdata) and len([x for x in r.ar[DNSRROPT].rdata if x.optcode == 3]) 70