Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wireguard VPN support #86020

Open
wants to merge 34 commits into
base: main
Choose a base branch
from

Conversation

jukkar
Copy link
Member

@jukkar jukkar commented Feb 19, 2025

This is initial Wireguard VPN support. Part of the implementation is ported from wireguard-lwip project.
Some discussion about this can be found in #63722

Some of the commits in this PR might be sent separately to review.

@jukkar jukkar added the In progress For PRs: is work in progress and should not be merged yet. For issues: Is being worked on label Feb 19, 2025
@jukkar jukkar force-pushed the devel/wireguard-support branch from 005e7bb to 01dba8d Compare February 20, 2025 08:30
@jukkar
Copy link
Member Author

jukkar commented Feb 20, 2025

  • Updated to latest main
  • Fixed compilation issues
  • Added VPN support to echo-client and http-server sample applications

@jukkar jukkar force-pushed the devel/wireguard-support branch from 01dba8d to 2fd6262 Compare February 20, 2025 15:07
@jukkar
Copy link
Member Author

jukkar commented Feb 20, 2025

  • Documentation added
  • VPN statistics support added

@jukkar jukkar force-pushed the devel/wireguard-support branch from 2fd6262 to 261c30f Compare February 21, 2025 13:03
@jukkar
Copy link
Member Author

jukkar commented Feb 21, 2025

  • manifest update for net-tools
  • allowed ip address list fixes
  • shell print allowed ips and endpoint
  • more statistics collection

@zephyrbot
Copy link
Collaborator

zephyrbot commented Feb 21, 2025

The following west manifest projects have changed revision in this Pull Request:

Name Old Revision New Revision Diff
net-tools zephyrproject-rtos/net-tools@93acc8b zephyrproject-rtos/net-tools#79 zephyrproject-rtos/net-tools#79/files

DNM label due to: 1 project with PR revision

Note: This message is automatically posted and updated by the Manifest GitHub Action.

@zephyrbot zephyrbot added manifest manifest-net-tools DNM (manifest) This PR should not be merged (controlled by action-manifest) labels Feb 21, 2025
@jukkar jukkar force-pushed the devel/wireguard-support branch from 261c30f to fe241b0 Compare February 21, 2025 16:44
@jukkar
Copy link
Member Author

jukkar commented Feb 21, 2025

  • housekeeping timer works now
  • keepalive timer is working and can be set from application

@jukkar jukkar force-pushed the devel/wireguard-support branch from fe241b0 to 456783b Compare February 23, 2025 14:39
@jukkar
Copy link
Member Author

jukkar commented Feb 23, 2025

  • updated to latest main
  • fixed Zephyr initiated handshake issues
  • CI fixes

@jukkar jukkar force-pushed the devel/wireguard-support branch from 456783b to d7a004e Compare February 24, 2025 09:55
@jukkar jukkar marked this pull request as ready for review February 24, 2025 09:56
@zephyrbot zephyrbot added area: Networking area: Sockets Networking sockets area: HTTP HTTP client/server support area: Samples Samples labels Feb 24, 2025
@jukkar jukkar removed the In progress For PRs: is work in progress and should not be merged yet. For issues: Is being worked on label Feb 24, 2025
If the interface is Wireguard VPN interface, then print
the public key of the interface.

Signed-off-by: Jukka Rissanen <[email protected]>
Sometimes it is useful to view low level network interface information
in the network shell. Enable such prints if network interface debugging
is enabled.

Signed-off-by: Jukka Rissanen <[email protected]>
All connection information was printed only if connection debugging
was enabled which then did not print information about Wireguard or
DHCP handlers. Limiting the printouts like this is not really needed
so print all connection information with "net conn" command.

Signed-off-by: Jukka Rissanen <[email protected]>
Collect Wireguard VPN statistics and allow user to fetch it.

Signed-off-by: Jukka Rissanen <[email protected]>
Show VPN statistics support if enabled.

Signed-off-by: Jukka Rissanen <[email protected]>
The "net wg show 1" will show detailed information of the peer
id 1. This is useful when debugging connectivity issues.

Signed-off-by: Jukka Rissanen <[email protected]>
Send peer add/del network event when the peers is either added
to the system or deleted from the system.
Send VPN connected / disconnected event when a VPN connection
is successfully established or the peer connection is disconnected.

Signed-off-by: Jukka Rissanen <[email protected]>
Add Wireguard VPN events information printouts to event monitor.

Signed-off-by: Jukka Rissanen <[email protected]>
Adding a helper to parse one or more IPv4/6 strings with optional
netmask or prefix length.

Example of the string:

   2001:db8::1/64,192.0.2.1,2001:db8::2,192.0.2.2/24

Signed-off-by: Jukka Rissanen <[email protected]>
Add tests that will verify that IP address with an optional mask
string is properly parsed.

Signed-off-by: Jukka Rissanen <[email protected]>
Add support for getting public address and setting private
key for the virtual interface. This is needed for Wireguard VPN.

Signed-off-by: Jukka Rissanen <[email protected]>
If there are no virtual interfaces attached to this virtual
interface, check if there is a RX handler for this virtual
interface and pass data to it.

Signed-off-by: Jukka Rissanen <[email protected]>
Update dummy interface sent statistics as that was missing.

Signed-off-by: Jukka Rissanen <[email protected]>
Instead of calling various network interface API functions to get
the network interface and related source IP address, have a single
function that can return both data.

Signed-off-by: Jukka Rissanen <[email protected]>
Add Wireguard configuration to echo-server application.

Signed-off-by: Jukka Rissanen <[email protected]>
Add Wireguard configuration to echo-client application.

Signed-off-by: Jukka Rissanen <[email protected]>
CONFIG_NET_MGMT_EVENT_INFO needs to be enabled for this sample so
that we can get detailed information when the event is generated.

Signed-off-by: Jukka Rissanen <[email protected]>
Add Wireguard configuration to http-server application.

Signed-off-by: Jukka Rissanen <[email protected]>
Add a test that enables Wireguard VPN compilation so that
we at least compile test the code.

Signed-off-by: Jukka Rissanen <[email protected]>
Move the common VLAN setup code to samples/net/common directory
so that other network samples can utilize that too.

Signed-off-by: Jukka Rissanen <[email protected]>
Move the common VLAN setup code to samples/net/common directory
so that other network samples can utilize that too.

Signed-off-by: Jukka Rissanen <[email protected]>
Move the common VLAN setup code to samples/net/common directory
so that other network samples can utilize that too.

Signed-off-by: Jukka Rissanen <[email protected]>
Move the common VLAN setup code to samples/net/common directory
so that other network samples can utilize that too.

Signed-off-by: Jukka Rissanen <[email protected]>
Move the common VLAN setup code to samples/net/common directory
so that other network samples can utilize that too.

Signed-off-by: Jukka Rissanen <[email protected]>
Add example and information how to run VPN over a VLAN with
the echo-server sample.

Signed-off-by: Jukka Rissanen <[email protected]>
Update net-tools that has helper scripts for Wireguard VPN
to help testing efforts.

Signed-off-by: Jukka Rissanen <[email protected]>
@jukkar jukkar force-pushed the devel/wireguard-support branch from 8adcfd5 to b672844 Compare February 27, 2025 10:13
@jukkar
Copy link
Member Author

jukkar commented Feb 27, 2025

  • Fixed timer when deciding if the connection init should be done
  • Added support for net wg show <id> command which shows detailed information about the peer connection

Copy link
Collaborator

@pdgendt pdgendt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few fixup commits for the copied BSD-3 and MIT files, should these be squashed instead?

Comment on lines +127 to +134
/* Original network interface */
struct net_if *wg_iface;
/* Pointer to IP header of the encrypted pkt */
union net_ip_header wg_ip_hdr;
/* Pointer to UDP header of the encrypted pkt */
union net_proto_header wg_proto_hdr;
/* Peer id */
int wg_peer_id;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of prefixing all with wg_, put it in a struct?

	struct {
		/* Original network interface */
		struct net_if *iface;
		/* Pointer to IP header of the encrypted pkt */
		union net_ip_header ip_hdr;
		/* Pointer to UDP header of the encrypted pkt */
		union net_proto_header proto_hdr;
		/* Peer id */
		int peer_id;
	} wg;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, we can certainly do that.

@jukkar
Copy link
Member Author

jukkar commented Feb 27, 2025

There are a few fixup commits for the copied BSD-3 and MIT files, should these be squashed instead?

I considered it but then it is difficult to make a diff to the original files to see if there are any changes. We need to modify the source files from wireguard-lwip in order to pass compliance / code formatting check, and the fixup commit is for that. I think the fixup commit is a good compromise here. Readability of the original crypto commits is poor but that is "fixed" in the subsequent commits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: HTTP HTTP client/server support area: Networking area: Samples Samples area: Sockets Networking sockets DNM (manifest) This PR should not be merged (controlled by action-manifest) manifest manifest-net-tools
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants