Skip to content

bind socket using a source port from MOSH_SPORT environment variable - #530

Open
meeuw wants to merge 1 commit into
mobile-shell:masterfrom
meeuw:master
Open

meeuw wants to merge 1 commit into
mobile-shell:masterfrom
meeuw:master

Conversation

@meeuw

@meeuw meeuw commented Jun 3, 2014

Copy link
Copy Markdown

Hi Keith,

Could you please send me some feedback about this crude hack?

It seems to work and I'd like to see it included in mosh.

Thanks in advance!
Dick Marinus

@keithw

keithw commented Jun 3, 2014

Copy link
Copy Markdown
Member

Hello Dick,

Thanks -- can you tell us more? Are you behind a firewall that restricts the client-side port number...?

-Keith

@meeuw

meeuw commented Jun 3, 2014

Copy link
Copy Markdown
Author

Hi Keith, I'd like to use this to connect through a NAT hole punched outside of mosh (by using project purple sendip).

@eminence

Copy link
Copy Markdown
Member

I too would like to see this integration. my use case is the same

@flixr

flixr commented Jul 7, 2015

Copy link
Copy Markdown

I have a very unusual use-case, but would benefit from this as well.
👍 from me

@eminence

Copy link
Copy Markdown
Member

Bumping this issue. I maintain this same functionality with an out-of-tree patch and I'd love to be able to use a stock mosh

@xtaran

xtaran commented Oct 12, 2015

Copy link
Copy Markdown

Please don't name that variable MOSH_SPORT. I really wondered what kind of sport is involved with Mosh. :-)

@flixr

flixr commented Oct 12, 2015

Copy link
Copy Markdown

FYI, I additionally disabled client port hopping if MOSH_SPORT is set: ed0d32d

@eminence

Copy link
Copy Markdown
Member

FWIW, here is my version of this patch: eminence@7e0c3ee

@meeuw

meeuw commented Oct 12, 2015

Copy link
Copy Markdown
Author

@xtaran I've used SPORT from the same parameter as iptables uses (iptables -p tcp --sport)

As @keithw asked, what is YOUR use case for this patch? Mine was only a proof of concept for connecting through a NAT from the Internet, which failed miserably because NAT timed the connection out and the (translated) port changed.

I've never encountered a firewall which allowed only a specific udp sport/dport tuple, what would be the purpose for this?

The only real use case I could think of is (I'm not sure if it would work) that you can kill mosh-client and restart it with the key+sport and be connected again.

@eminence

Copy link
Copy Markdown
Member

My use case is to allow a "reverse connection". The scenario is this:

mosh-server is behind a NAT/Firewall that I cannot change. The server machine does not accept SSH connections from the internet, but I can SSH to it if I am on its LAN. The NAT/Firewall doesn't allow unsolicited incoming UDP packets, but once a "connection" has been established (by sending an outgoing UDP packet), return (incoming) packets are allowed.

mosh-client is on an internet-facing device, with no address translation, and no firewall

Given the following network diagram, here is an example:

  _____________                           _____________
 [ mosh-server ]    [N]                  [ mosh-client ]
 [ 0.0.0.0:SP1 ]====[A]====[internet]====[ 0.0.0.0:CP1 ]
 [_____________]    [T]                  [_____________]

A process on the mosh-server machine binds to local port SP1 and sends a UDP packet to (mosh-client, CP1). A process on the mosh-client machine sees this incoming packet as coming from (nat, SP2), and sends a reply to that address (knowing that the NAT has mapped SP1 to SP2. The mosh-server machine receives this packet.

Now that a set of round-trip packets have been successfully sent/received, the mosh-server process starts up, and binds to local port SP1 (this is easily done via the command line). The MOSH_KEY is read and communicated OOB to the mosh-client. mosh-client starts up, and binds to CP1 (via an environment variable from this patch), plus the (nat, SP2).

Now mosh just does its normal thing -- the client and server can communicate directly.

I have some wrapper scripts that handle this packet sending stuff, and takes care of communicating the key back to the client machine, but I have to have a custom version of mosh-client to make this work.

@meeuw
meeuw force-pushed the master branch 2 times, most recently from b88b278 to ddb13af Compare October 14, 2015 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants