Port forwarding in slirp

About BasiliskII, a 68k Mac emulator for Windows, MacOSX, and Linux that can run System 7.x through MacOS 8.1.

Moderators: Cat_7, Ronald P. Regensburg

Post Reply
CEL
Space Cadet
Posts: 5
Joined: Sun Oct 21, 2007 3:47 am

Port forwarding in slirp

Post by CEL »

I thought it would be nice if Basilisk would allow ports to be exposed outside the virtual network without requiring tun/tap or root privileges, so I decided to investigate the source code. I came across a nice little function, slirp_redir, which wasn't being called anywhere but did exactly what I wanted. So I added some code for accepting "redir" as a preference item, and now it works.

If you are using slirp networking you can forward a port by adding to your prefs file a line such as the following:

Code: Select all

redir tcp:8000:10.0.2.15:80
This will forward TCP port 8000 on the host to port 80 in the virtual machine, assuming its address is 10.0.2.15. You can actually leave out the IP if it is 10.0.2.15, because that is the default.

The code is online here:
https://github.com/clehner/macemu

You can find a Linux binary, built on Fedora 17, here:
https://github.com/clehner/macemu/downloads

I'll try to add a binary for OS X soon.

Here is a screenshot.
Image

Present issues:
  • When a program in the emulator listens on a port, at least with TCP, there is a delay of 16 seconds to start the listening. When connecting from the host there is sometimes another delay of 16 seconds. When connecting from other hosts there does not seem to be this delay.
  • Using 0.0.0.0 as the client address does not work well, so you have to specify the client's address if it is something other than 10.0.2.15 (although in my experience it is always 10.0.2.15).
User avatar
Ronald P. Regensburg
Expert User
Posts: 6711
Joined: Thu Feb 09, 2006 10:24 pm
Location: Amsterdam, Netherlands

Re: Port forwarding in slirp

Post by Ronald P. Regensburg »

Really nice, but why did you fork it from the original cebix/macemu? The BasiliskII/SheepShaver project is best helped forward by joining efforts.
CEL
Space Cadet
Posts: 5
Joined: Sun Oct 21, 2007 3:47 am

Re: Port forwarding in slirp

Post by CEL »

Forking tends to be the way on github for independent developers to contribute to projects. I don't meant to create a separate project. I'll make a pull request now on the cebix repo so the changes can get merged upstream or be commented on.
Gemfinder
Space Cadet
Posts: 4
Joined: Thu Feb 04, 2021 5:10 am

Re: Port forwarding in slirp

Post by Gemfinder »

Did slirp port forwarding ever get merged into SheepShaver?

My urgent goal is to run Civilization II Gold (OS9) over TCP/IP. :-)
User avatar
Cat_7
Expert User
Posts: 5336
Joined: Fri Feb 13, 2004 8:59 am
Location: Sittard, The Netherlands

Re: Port forwarding in slirp

Post by Cat_7 »

Hi,

It seems the code was integrated into at least the kanjitalk755 repository.
However, I couldn't get it to work in my Windows builds. This might be due to my network setup.

To try whether it works at all, first make sure your network prefs are set to slirp.
Then edit your basilisk or sheepshaver prefs manually. Add:

redir tcp:8080:10.0.2.15:80

Don't use the GUI. If you do, the pref will be deleted.
Start Basilisk or SheepShaver directly and start the web sharing service.
In your host try to connect to http://localhost:8080

Best,
Cat_7
User avatar
Ronald P. Regensburg
Expert User
Posts: 6711
Joined: Thu Feb 09, 2006 10:24 pm
Location: Amsterdam, Netherlands

Re: Port forwarding in slirp

Post by Ronald P. Regensburg »

Cat_7 wrote: Thu Feb 04, 2021 7:34 amIt seems the code was integrated into at least the kanjitalk755 repository.
This is new to me. I never saw mention of this before. Where did you see this?
User avatar
Cat_7
Expert User
Posts: 5336
Joined: Fri Feb 13, 2004 8:59 am
Location: Sittard, The Netherlands

Re: Port forwarding in slirp

Post by Cat_7 »

Hi Ronald,

If you clone the repository linked to above, you can search it for slirp_redir.

I see slirp_redir referenced in:
Basilisk/src/slirp/slirp.c
Basilisk/src/slirp/libslirp.h
and
Basilisk/src/Unix/ether_unix.cpp

If you then search the kanjitakk755 source, you can find these same references to slirp_redir.
I see no reference to slirp_redir in ether_windows.cpp, so that might very well explain why it would not work in Windows ;-)

Best,
Cat_7
User avatar
Ronald P. Regensburg
Expert User
Posts: 6711
Joined: Thu Feb 09, 2006 10:24 pm
Location: Amsterdam, Netherlands

Re: Port forwarding in slirp

Post by Ronald P. Regensburg »

I though it was specifically added in kanjitak755 source, Apparently it was merged to cebix/macemu in 2012, before kanjitalk755 forked it. That is why I missed it.
User avatar
Cat_7
Expert User
Posts: 5336
Joined: Fri Feb 13, 2004 8:59 am
Location: Sittard, The Netherlands

Re: Port forwarding in slirp

Post by Cat_7 »

Ah, already merged that long ago!
Did you have a chance to see whether it works in macOS builds?

Best,
Cat_7
kanjitalk755
Mac Mechanic
Posts: 190
Joined: Thu Nov 09, 2017 12:06 pm

Re: Port forwarding in slirp

Post by kanjitalk755 »

In the latest source, both BII and SS support the port forwarding (all platforms).
User avatar
Ronald P. Regensburg
Expert User
Posts: 6711
Joined: Thu Feb 09, 2006 10:24 pm
Location: Amsterdam, Netherlands

Re: Port forwarding in slirp

Post by Ronald P. Regensburg »

kanjitalk755 wrote: Fri Feb 05, 2021 4:13 am In the latest source, both BII and SS support the port forwarding (all platforms).
Existed for macOS and Linux and was now added by kanjkitalk755 for Windows.
Gemfinder
Space Cadet
Posts: 4
Joined: Thu Feb 04, 2021 5:10 am

Re: Port forwarding in slirp

Post by Gemfinder »

Thanks for the advice. So far it doesn't work. I suppose this could be either SS/slirp, or the tcp rules on the host machine (although the MacOS firewall is already turned off, and a mysql service is running OK from localhost:3306).

Added port forwarding to the config file as directed, and assumed the line order doesn't matter:

Image

Turned on web sharing, and verified it works within the emulator.

Image

But no access from the host OS:

Image

And port 8080 is closed:

Image
User avatar
Cat_7
Expert User
Posts: 5336
Joined: Fri Feb 13, 2004 8:59 am
Location: Sittard, The Netherlands

Re: Port forwarding in slirp

Post by Cat_7 »

It seems to work for Basilisk, but not for SheepShaver.

Best,
Cat_7
kanjitalk755
Mac Mechanic
Posts: 190
Joined: Thu Nov 09, 2017 12:06 pm

Re: Port forwarding in slirp

Post by kanjitalk755 »

SheepShaver also supports the port forwarding after commit 8ebc4c9.
User avatar
Cat_7
Expert User
Posts: 5336
Joined: Fri Feb 13, 2004 8:59 am
Location: Sittard, The Netherlands

Re: Port forwarding in slirp

Post by Cat_7 »

Yes, great,

A new SheepShaver build I just created privately works perfectly.
So when a new SheepShaver build comes available, it will support redirection too.

Thanks,
Cat_7
User avatar
Ronald P. Regensburg
Expert User
Posts: 6711
Joined: Thu Feb 09, 2006 10:24 pm
Location: Amsterdam, Netherlands

Re: Port forwarding in slirp

Post by Ronald P. Regensburg »

New macOS builds of both SheepShaver and BasiliskII coming up soon.
User avatar
Ronald P. Regensburg
Expert User
Posts: 6711
Joined: Thu Feb 09, 2006 10:24 pm
Location: Amsterdam, Netherlands

Re: Port forwarding in slirp

Post by Ronald P. Regensburg »

New versions have to wait. After the server upgrade last night, I cannot SFTP anymore to emaculation.com. :cry:
Gemfinder
Space Cadet
Posts: 4
Joined: Thu Feb 04, 2021 5:10 am

Re: Port forwarding in slirp

Post by Gemfinder »

Commit 8ebc4c9 works great. Thanks very much for this.

Ronald, I noticed this was your post number 6502. Looking forward to post number 68000 :lol:
User avatar
Ronald P. Regensburg
Expert User
Posts: 6711
Joined: Thu Feb 09, 2006 10:24 pm
Location: Amsterdam, Netherlands

Re: Port forwarding in slirp

Post by Ronald P. Regensburg »

Now at post 6507.

I can ftp again, but lost a day to figure out what caused the probem.

The promised new builds will come soon, maybe tomorrow.
Gemfinder
Space Cadet
Posts: 4
Joined: Thu Feb 04, 2021 5:10 am

Re: Port forwarding in slirp

Post by Gemfinder »

JK, a bit of CPU numerology. Thanks again for the port forwarding update
Halcyon
Space Cadet
Posts: 4
Joined: Sat Dec 30, 2017 12:34 am

Re: Port forwarding in slirp

Post by Halcyon »

Wow, the port forwarding feature is great! I can finally run a Hotline Server in Sheepshaver and expose the ports.

In case it helps anyone else, you can forward multiple ports (as need by Hotline) by adding additional redir lines:

redir tcp:5500:10.0.2.15:5500
redir tcp:5501:10.0.2.15:5501
Post Reply