ksherlock / ample

Apple Emulator Frontend for MAME
88 stars 6 forks source link

vmnet helper #23

Open rb6502 opened 1 year ago

rb6502 commented 1 year ago

Hi Kelvin,

I'd like to borrow vmnet_helper (and the MAME-side interface glue) for stock MAME. As you probably noticed, pcap on macOS pretty much only works with wired Ethernet connections and so I've been unable to use or work on any network emulation since I switched daily driving to my MacBook Pro. I can go the QEMU route and just require running MAME as root for networking, but having an external helper running as root is a much cleaner idea.

ksherlock commented 1 year ago

That's fine. The helper code is here and the MAME part is here and here for the lua build part. I didn't think MAME would be interested in it since it's a bit hacky. vmnet has strongly held opinions about the mac address so it has to rewrite ARP and DHCP messages.

rb6502 commented 1 year ago

Ok. I'm trying your plain vmnet where I do run MAME as root before getting into any potential weirdness with vmnet_helper and it's sending packets OK as far as I can see but nothing is ever received. (I'm running an emulated Mac with the Fetch FTP client trying to connect to a server on my LAN). Any ideas on that?

ksherlock commented 1 year ago

Are you using a static IP address? vmnet requires DHCP. Most packets are blocked until DHCP negotiation. I can't recall if I ever tested the plain vmnet so it's also possible there's a bug in there. When vmnet starts up, it creates a bridge100 interface so you can use wireshark or tcpdump to monitor that (inbound packets have checksum errors but that's fine). If that's ok, FTP would probably have to be in passive mode it isn't already.

rb6502 commented 1 year ago

Yeah, I was using static IP. I changed to DHCP and it requests an address and gets a response but it doesn't acknowledge it, it just keeps requesting an address. Maybe Mac OS does care about the checksum? What's an easy way to test on the A2?

ksherlock commented 1 year ago

I haven't tested with MacOS networking. I'll try to set that up and look into it. The IP checksums are fixed at some point after wireshark sees them so they're correct by the time they make it into MAME.

For the Apple II, The ip65 disk will work with -sl3 uthernet

rb6502 commented 1 year ago

Hmm. The Apple II when I try it always forces the interface to -1 even if I fix it in apple2ee.cfg and so nothing works.

On Sun, Sep 17, 2023 at 10:59 AM ksherlock @.***> wrote:

I haven't tested with MacOS networking. I'll try to set that up and look into it. The IP checksums are fixed at some point after wireshark sees them so they're correct by the time they make it into MAME.

For the Apple II, The ip65 disk https://github.com/cc65/ip65/releases/tag/2023-06-11 will work with -sl3 uthernet

— Reply to this email directly, view it on GitHub https://github.com/ksherlock/ample/issues/23#issuecomment-1722495674, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACGU4O4EO5QVRJ76YBPHELTX24F33ANCNFSM6AAAAAA4UEJW3E . You are receiving this because you authored the thread.Message ID: @.***>

rb6502 commented 1 year ago

Never mind, that was user error :-) I got DATE65.SYSTEM to get the time and date correctly.

ksherlock commented 1 year ago

For the macintosh, are you using MacTCP, OpenTransport, or something else?

rb6502 commented 1 year ago

I'm running maciivx -nbe enetnb with 7.6.1 that's been upgraded with Open Transport 1.3.1 (you can get the 1.3 installer and 1.3.1 upgrade from Macintosh Garden).

Related to this, I've added this section: https://wiki.mamedev.org/index.php/Driver:Mac_68K#How_do_I_get_files_into_the_emulation.3F

Would be cool if Ample had a drop box for files to send to the Mac and could run hdiutil for you and set it as the -cdrom, but that's pie-in-the-sky and it's not super hard to do manually.

ksherlock commented 1 year ago

I was able to track down the Open Transport DHCP issues and it was my fault (and checksum related). Here is the updated file.

image
rb6502 commented 1 year ago

Works great! I was able to connect to both the FTP and netatalk servers on my home server and copy files back and forth.

I'll clean this stuff up and submit it sometime after the next release is locked down.

rb6502 commented 1 year ago

Bonus screenshot: https://rbelmont.mameworld.info/wp-content/uploads/2023/09/0000.png

rb6502 commented 1 year ago

So Open Transport works great now, but MacTCP uses BootP instead of DHCP. I assume there's no way to tell it otherwise? I understand a lot of modern routers won't bother with it either so it's very much a problem people with physical machines have too.

ksherlock commented 1 year ago

As far as google would tell me, MacTCP is bootp only. It's not practical, but vmnet might support bootp (I say might because bootp gives it an IP address but I haven't tested an actual connection).

bootp support is disabled by default. There's an /etc/bootpd.plist which vmnet/Mac Internet Sharing create (so it tends to get wiped out). After it's created, the bootp_enabled key needs to be set to true. If /usr/libexec/bootpd is already running, I think a sighup should reload the config.

There's also an /etc/bootptab file which has a list of mac addresses / ip addresses. This would need to be updated with the vmnet mac and the ip address.

man bootpd and man bootptab have more info.

With those files updated, bootp will give the ip address.

rb6502 commented 1 year ago

Oh, interesting. That's cool that vmnet still supports it. Someone at Apple must understand the use cases for vmnet aren't all VMWare types of stuff.

QEMU filed a radar with Apple in 2021 that you shouldn't need root to use vmnet, but I don't expect anything to happen. https://openradar.appspot.com/radar?id=5007417364447232 I believe they were working on some kind of server app similar to vmnet-helper but I don't know where they're at with it.

ksherlock commented 1 year ago

I suspect it's more of accident that bootp still works.

I found one more checksum bug - https://github.com/ksherlock/mame/commit/2152bec136ab10a302b7cd7d771c0ff72df2bde4

rb6502 commented 1 year ago

Thanks! I'm told 'networksetup -setbootp (interface name)' is the more Apple-approved way to enable it, but I haven't tried any methods yet.

rb6502 commented 1 year ago

Fair warning: MAME 0.259 will lock up when reading 3.5" disks. There's a hot fix at https://github.com/mamedev/mame/commit/cf510adc9d34b4ad9a065f3d5bfbcf17115ea06f

ksherlock commented 1 year ago

Thanks for the heads up. I've cherry-picked it into a new build.

I think the networksetup is for controlling the settings as a client (in system settings -> network -> ... configure IPv4 ... On my 10.14 Mac, bootp is still an option but on 13.5 it's gone).

This was pointed out to me the other day which is similar but uses a unix domain socket. Maybe it's better, maybe it's not. I haven't tried but I don't understand how it can work without using the mac address vmnet assigns. It could be that bridged mode (added in 10.15) is more lenient about that.

rb6502 commented 1 year ago

I chased down bootp to /System/Library/LaunchDaemons/bootps.plist where it's disabled and SIP won't allow you to change it even as root. Supposedly you can get launchd to override that by putting your own version in /Library/LaunchDaemons and/or ~/Library/LaunchDaemons but I lack the macOS-foo to get it to work.

rb6502 commented 1 year ago

Any idea if there's anything in vmnet either on the MAME side or the Apple side that would block AppleTalk traffic? I installed the latest netatalk 2.2.10 on my Linux systems and the nbplkup utility shows that they're advertising a server but MAME doesn't see it even when the host Mac is connected with wired Ethernet (WiFi is known to interfere with AppleTalk).

I can connect to the server directly with the newer AppleShare client where you can enter a DNS name or IP address of a server. So AFP over TCP works fine, but just trying to see available servers in the Chooser doesn't show anything (AARP/NBP/the other components of AppleTalk).

ksherlock commented 1 year ago

Bad news... It looks like the Ethertalk packets generated over open transport use a logical link control / subnetwork access protocol (LLC/SNAP) ethernet header that vmnet does not like. (The Use 802.3 checkbox in the TCP/IP control panel enables the SNAP/LLC header for TCP as well and vmnet doesn't like that either). If we remove the SNAP/LLC header the packets still don't make it into vmnet so I think it must be filtering out everything except ARP and IP.

rb6502 commented 1 year ago

That sucks, and arguably most for the IIgs emulation, although System 6 and pre-030 Macs that can't run Open Transport also get hurt. I guess the long-term solution will be to adopt a compatible built-in LocalTalk bridge like Mini vMac and GSPlus/GSPort have. Vas wants to do it differently though: have the 8530 speak the correct bit-serial encoding and then a separate device class similar to the existing bitb for serial does the rest. The Mac guys have done some interesting stuff along those lines recently for real machines ( https://68kmla.org/bb/index.php?threads/releasing-airtalk-wireless-plug-and-play-localtalk-dongle.43838/ for example).

I also might look into if vmnet_common can do bootp/DHCP translation so MacTCP can get online. It seems like it wouldn't be hard, but I need to wrap up the initial integration first.

rb6502 commented 1 year ago

Here's the current status of the cleanup/integration, not including that I want to do something about the network module selection: https://github.com/rb6502/mame/commit/99bfb0d76b0239bac7528898a8c0bc4f135adf63

ksherlock commented 1 year ago

I might be biased but it looks good to me. The vmnet_common stuff should probably be in a namespace.

bootp/dhcp translation shouldn't be that hard and would be handy.

rb6502 commented 11 months ago

Someone on 68KMLA is writing a router that converts between LToUDP (LocalTalk over UDP, which vMac, Basilisk, and GSPort/GSPlus speak) and EtherTalk. They said they're using VMNet in 'bridged' mode instead of 'shared' for their router and it obviously passes EtherTalk packets.

The post about it is here: https://68kmla.org/bb/index.php?threads/developing-a-portable-user-land-appletalk-stack.34622/page-4#post-475509 and I asked them for clarification about the VMNet mode further down the thread.

I tried changing VMNET_SHARED_MODE to VMNET_BRIDGED_MODE and recompiled vmnet_helper and it just hangs when you run it (and makes the parent MAME hang too), so obviously there's something else that needs to change :)

ksherlock commented 11 months ago

Interesting. VMNET_BRIDGED_MODE didn't exist when I originally wrote the helper. I'll try to play with it this weekend.

ksherlock commented 11 months ago

For bridged mode, we need to specify the interface that is bridged, eg:

        xpc_dictionary_set_uint64(dict, vmnet_operation_mode_key, VMNET_BRIDGED_MODE);
        xpc_dictionary_set_string(dict, vmnet_shared_interface_name_key, "en1");

vmnet_start_interface return NULL if there's an error, which it was doing, so that should exit immediately since the status callback will never be executed and it will otherwise hang forever.