diff --git a/server/device.cpp b/server/device.cpp index 5f67c6f..97501ed 100644 --- a/server/device.cpp +++ b/server/device.cpp @@ -382,11 +382,30 @@ quint64 Device::neighborMac(const PacketBuffer *pktBuf) dstIp = qFromBigEndian(pktData + ipHdrLen - 4); mask = ~0 << (32 - ip4PrefixLength_); - qDebug("dst %x self %x mask %x", dstIp, ip4_, mask); + qDebug("dst %x mask %x self %x", dstIp, mask, ip4_); tgtIp = ((dstIp & mask) == (ip4_ & mask)) ? dstIp : ip4Gateway_; return arpTable_.value(tgtIp); } + else if ((ethType == kEthTypeIp6) && hasIp6_) { // IPv6 + UInt128 dstIp, tgtIp, mask; + + if (pktBuf->length() < (kIp6HdrLen+2)) { + qDebug("incomplete IPv6 header: expected %d, actual %d", + kIp6HdrLen, pktBuf->length()-2); + return false; + } + + dstIp = qFromBigEndian(pktData + 24); + mask = ~UInt128(0, 0) << (128 - ip6PrefixLength_); + qDebug("dst %s mask %s self %s", + qPrintable(QHostAddress(dstIp.toArray()).toString()), + qPrintable(QHostAddress(mask.toArray()).toString()), + qPrintable(QHostAddress(ip6_.toArray()).toString())); + tgtIp = ((dstIp & mask) == (ip6_ & mask)) ? dstIp : ip6Gateway_; + + return ndpTable_.value(tgtIp); + } return false; } diff --git a/test/emultest.py b/test/emultest.py index 09a669c..067af69 100644 --- a/test/emultest.py +++ b/test/emultest.py @@ -447,6 +447,7 @@ def test_multiEmulDevNoVlan(drone, ports, dut, dut_ports, dut_ip, s = stream_cfg.stream.add() s.stream_id.id = stream_id.stream_id[i].id s.core.is_enabled = True + s.core.frame_len = 80 # FIXME: change to 128 s.control.packets_per_sec = 100 s.control.num_packets = 10 @@ -703,13 +704,24 @@ def test_multiEmulDevNoVlan(drone, ports, dut, dut_ports, dut_ip, print(cap_pkts) log.info('dumping Rx capture buffer (filtered)') for i in range(num_devs): - cap_pkts = subprocess.check_output([tshark, '-nr', 'capture.pcap', - '-Y', '(ip.src == 10.10.1.' + str(101+i*ip_step) + ') ' - ' && (ip.dst == 10.10.2.' + str(101+i*ip_step) + ')' - ' && (eth.dst == 00:01:02:03:0b:' - + format(1+i*mac_step, '02x')+')']) - print(cap_pkts) - assert cap_pkts.count('\n') == s.control.num_packets/num_devs + if has_ip4: + cap_pkts = subprocess.check_output([tshark, '-nr', 'capture.pcap', + '-Y', '(ip.src == 10.10.1.' + str(101+i*ip_step) + ') ' + ' && (ip.dst == 10.10.2.' + str(101+i*ip_step) + ')' + ' && (eth.dst == 00:01:02:03:0b:' + + format(1+i*mac_step, '02x')+')']) + print(cap_pkts) + assert cap_pkts.count('\n') == s.control.num_packets/num_devs + if has_ip6: + cap_pkts = subprocess.check_output([tshark, '-nr', 'capture.pcap', + '-Y', '(ipv6.src == 1234:1::' + + format(101+i*ip_step, 'x') + ') ' + ' && (ipv6.dst == 1234:2::' + + format(101+i*ip_step, 'x') + ')' + ' && (eth.dst == 00:01:02:03:0b:' + + format(1+i*mac_step, '02x')+')']) + print(cap_pkts) + assert cap_pkts.count('\n') == s.control.num_packets/num_devs os.remove('capture.pcap') drone.stopTransmit(ports.tx)