The rtc1 patch to klh10-2.0a Patch: klh10-2.0a+rtc1.patch Author: Peter Backes Date: Sun Jan 27 2002 Base: klh10-2.0a This is a set of patches against KLH10, a PDP10 emulator written in C by Ken Harrenstein, to enhance it's networking capabilities under Linux. DESCRIPTION This patch can make networking under Linux with an emulated PDP10 quite comfortable and is probably required with some ethernet device drivers to have a working network support at all. When I first installed klh10 on my Linux machine, networking did not work. After endless investigation, monitoring with tcpdump and studying the source, I finally found out that my device driver changed the ethernet header information supplied by klh10. The fix for the problem was to just pass the data to rewrite the header from to the device driver in a special structure. But I still could not connect to the emulated machine. I had a deeper look into the source and it turned out that the decision on whether to route an ip packet over the configured gateway or whether to send it via ethernet to the target host directly was based on comparing the network address to a mutilated version of the emulating host's ip address. I guess this only worked before if the local network was either class A or if there was a router on the network which was not the emulating host. Connecting from a remote machine to the emulated host worked for the first time after changing the code to use the real destination address for IP packets. It was still not possible to connect from the emulating host itself to the emulator. I had contacted Ken and he told me it was in the nature of the Linux packet filter that it was not possible to send ethernet packets in a way so they were interpreted by the kernel. But after changing the emulator to use a specond raw IP socket instead of the raw ethernet socket for packets addressed to the emulating host, I could ping the emulator from the emulating machine and got a reply. However a telnet connection lost characters and choked quite quickly. Comparing the packet content when it was sent and when it was handled by the kernel showed that there was garbage at the end and that the kernel changed length and checksum in the header, thus effectively appending this garbage to the end of the packet. Soon I found out that this packet skew was caused by the fact that the length of a packet was always aligned to word length. After adding a small routine which removed the padding before sending each packet, connections from the emulating machine worked flawlessly. This patch contains all those changes I made and additionally some smaller, mostly cosmetic fixes. INSTALLATION This is how to apply the patch: tar xzvf /path/to/klh10-2.0a.tgz cd klh10-2.0a patch -p1 < /path/to/klh10-2.0a+rtc1.patch Then compile and install as described in the documentation. TIPS Here are some tips which can make life easier with KLH10 networking. First, if you decide to use an IP address for your emulated machine which is outside of the local network and you don't have a gateway, you need to manually add a route to each computer on the network which you want to reach the emulated machine from. (If there is a gateway on the network it is generally sufficient to add that route only to the gateway. If the gateway is the emulating host and anything is configured properly, you probably don't need to add a route at all, as long as the emulated host is contacted only from machines on the ethernet used by the emulator, but be sure to avoid duplicate packets as described below.) Under Windows, you can use (assumed that 10.134.198.236 is the IP of the emulated host and 192.168.1.10 that of the Windows machine's device which is on the same ethernet as the emulator) route ADD 10.134.198.236 MASK 255.255.255.255 192.168.1.10 Under Linux you have to use the name instead of an IP of the device which is on the same ethernet as the emulator: route add 10.134.198.236/32 eth0 If the machine you run the emulator on is configured for packet forwarding and you don't use a dedicated interface for klh10, then Linux will probably try to handle packets addressed to the emulator, because they're addressed to it's MAC address. It can then happen that the kernel actually tries to forward packets to the emulator, which will cause it to see any packet twice. To fix that, add a simple ipchains rule to the emulating machine (replace 10.134.198.236 with the IP address of the emulated machine and eth0 with the ethernet device your emulator is configured to use): ipchains -I input -s 0.0.0.0/0 -d 10.134.198.236/32 -i eth0 -j DENY It is especially important to specify the ethernet device used by the emulator, because only packets sent to it from there are guaranteed to be seen by it. If the machine is not only configured for packet forwarding but actually is a gateway, the kernel would otherwise refrain from forwarding the packet if it originates from one of the other network devices, giving the emulator no chance to see them. Further you should note that even with die-hard routing enabled, you cannot feed ARP-packets to the kernel. But the kernel needs to have an ARP entry to know to where packets have to be addressed to and therefore will send an ARP request whose reply it cannot see however. So run arp -Ds 10.134.198.236 eth0 (assumed that 10.134.198.236 is the IP of the emulated host and eth0 is the device it uses). PROBLEMS I have noticed that dtelnet it not working in a satisfying way. The clients shipped with Windows and most Linux distributions seem to work fine however. I don't know whether this is related to my patch (I didn't have a chance to try without it ;), but I suspect it to be a problem on the side of dtelnet. CHANGES - Implemented correction of packet skew caused by word boundary at least for IP packets. - Added optional die hard routing: Hack utilizing IPPROTO_RAW to make it possible to connect from the emulating host under Linux. - Enhanced routing for packets. IP target addresses for non-ip packets are calculated using the old method, routing of real IP packets use the header's destination address for the gateway decision instead. - Fixed device driver ethernet address clobbering problem. - Removed bad memcpy from arp_reply(). - Fixed an emulator message missing line break.