Page MenuHomeFreeBSD

Allow netcat to be a tun tunnel broker
ClosedPublic

Authored by thj on Nov 18 2022, 4:16 PM.
Tags
None
Referenced Files
F81893469: D37435.diff
Mon, Apr 22, 7:00 PM
Unknown Object (File)
Tue, Apr 16, 5:51 PM
Unknown Object (File)
Sun, Apr 7, 12:34 AM
Unknown Object (File)
Sun, Apr 7, 12:33 AM
Unknown Object (File)
Feb 23 2024, 2:54 AM
Unknown Object (File)
Feb 23 2024, 2:49 AM
Unknown Object (File)
Feb 22 2024, 9:39 AM
Unknown Object (File)
Feb 16 2024, 10:42 AM

Details

Summary

Add tests with this new functionality to test that tun devices can pass packets.

You need to figure both sides with netcat, one side should listen:

  1. ifconfig tun create

tun0

  1. nc -u -l --tun /dev/tun0 192.168.100.12 2600 &
  2. ifconfig tun0 inet 10.4.100.2/24 10.4.100.3 up
  1. ifconfig tun create

tun0

  1. nc -u --tun /dev/tun0 192.168.100.12 2600 &
  2. ifconfig tun0 inet 10.4.100.2/24 10.4.100.2 up

This is very naiive and probably quite fragile, but it is enough to enable tun
tests using just netcat.

Add usage and help strings

Add tun tunnelling test using nc

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

thj requested review of this revision.Nov 18 2022, 4:16 PM
thj retitled this revision from Allow netcat to be a tun tunnel broker Add tests with this new functionality to test that tun devices can pass packets. to Allow netcat to be a tun tunnel broker.Nov 18 2022, 4:35 PM
thj edited the summary of this revision. (Show Details)

Just some minor simplifications, I think we can just use tun_fd being a valid fd as an indicator that we should be tunneling instead of tracking that in separate state.

contrib/netcat/netcat.c
149

Normally we just use CHAR_MAX to make it clear

163

IMO, let's init tundev to NULL here

336

tundev could be a const char * and you can avoid having to make a copy of optarg here, since we don't need to mutate it later.

338

Drop FreeBSD_tun completely, the below conditional can use tundev != NULL

583

tun_fd >= 0, since we initialize it to -1

861

Let's use tun_fd >= 0 for these ones, as well

thj marked 6 inline comments as done.Jan 12 2023, 10:13 AM

Address Kyles review comments

bcr added a subscriber: bcr.

OK for the man page part of the change.

Seems to LGTM; thanks!

This revision is now accepted and ready to land.Jan 17 2023, 2:37 AM
This revision was landed with ongoing or failed builds.Jan 17 2023, 10:07 AM
This revision was automatically updated to reflect the committed changes.