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
F82165221: D37435.id115222.diff
Fri, Apr 26, 2:55 AM
F82165209: D37435.id114991.diff
Fri, Apr 26, 2:55 AM
F82165208: D37435.id.diff
Fri, Apr 26, 2:55 AM
F82165195: D37435.id113272.diff
Fri, Apr 26, 2:55 AM
F82137951: D37435.diff
Thu, Apr 25, 8:53 PM
Unknown Object (File)
Mon, Apr 22, 7:00 PM
Unknown Object (File)
Tue, Apr 16, 5:51 PM
Unknown Object (File)
Sun, Apr 7, 12:34 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 Warnings
SeverityLocationCodeMessage
Warningtests/sys/net/if_tun_test.sh:CHMOD1Invalid Executable
Unit
No Test Coverage
Build Status
Buildable 48420
Build 45306: arc lint + arc unit

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
150

Normally we just use CHAR_MAX to make it clear

164

IMO, let's init tundev to NULL here

337

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.

339

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

586

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

864

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.