예제 #1
0
def wrong_checksum_a(testname):
    hs = TESTS[testname].host_s
    hr = TESTS[testname].host_r
    r_mac = info.get("router_mac", hs)
    target_ip = info.get("host_ip", hr)

    i = IP(dst=target_ip)
    chk = checksum(bytes(i))
    chk = (chk + 1) % (2**16)
    i.chksum = chk

    return Ether(dst=r_mac) / i
def forward_p(testname, packets):
    # The router may or may not (depending on its ARP cache) also send us an
    # ARP request
    hs = TESTS[testname].host_s
    hr = TESTS[testname].host_r

    res, packets = cull_dull_packets(hr, packets)
    icmp_ur, packets = cull_icmp_unreachable(hr, packets)

    if not len(packets):
        error("No packet received")
        return False

    nr_pkts = 2 if testname == "forward_no_arp" else 1
    if not res or len(packets) > nr_pkts:
        error("Excess packets:")
        dump_packets(packets)

        return False

    p = packets[0]
    assert IP in p, "no IP packet from router"
    i = p[IP]
    result = True

    if testname == "ttl":
        crt = i.ttl == 63
        if not crt:
            error("Wrong TTL value")
            error("Expected: ttl=63")
            error("Got: ttl={}".format(i.ttl))

        result = result and crt
    if testname == "checksum":
        router_chk = i.chksum
        i.chksum = 0
        correct_chk = checksum(bytes(i))

        crt = router_chk == correct_chk
        if not crt:
            error("Wrong checksum value")
            error("Expected: checksum=0x{:04x}".format(correct_chk))
            error("Got: checksum=0x{:04x}".format(i.chksum))

        result = result and crt

    crt = i.dst == info.get("host_ip", hr)
    if not crt:
        error("Wrong IP destination value")
        error("Expected: destination={}".format(info.get("host_ip", hr)))
        error("Got: destination={}".format(i.dst))

    result = result and crt

    crt = i.src == info.get("host_ip", hs)
    if not crt:
        error("Wrong IP source value")
        error("Expected: destination={}".format(info.get("host_ip", hs)))
        error("Got: destination={}".format(i.src))

    result = result and crt
    return result