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
F102924125: D37435.id113272.diff
Mon, Nov 18, 7:32 PM
Unknown Object (File)
Sat, Nov 16, 2:22 PM
Unknown Object (File)
Wed, Nov 6, 3:11 PM
Unknown Object (File)
Wed, Nov 6, 3:11 PM
Unknown Object (File)
Tue, Oct 29, 12:57 PM
Unknown Object (File)
Mon, Oct 21, 6:54 PM
Unknown Object (File)
Oct 17 2024, 2:19 AM
Unknown Object (File)
Oct 16 2024, 6:46 PM

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 49072
Build 45961: 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
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.