Skip to content

Commit 3a2338a

Browse files
Update main to latest (#77)
* Updated pkg-plist * Makefile fix * Experimenting with wireguard service * Update README.md Co-authored-by: vajonam <152501+vajonam@users.noreply.github.com> Co-authored-by: Manojav Sridhar <manojav@manojav.com>
1 parent f430438 commit 3a2338a

21 files changed

+317
-130
lines changed

README.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
# pfSense-pkg-WireGuard
2-
This is a port of the original WireGuard UI bits as implemented by [Netgate](https://www.netgate.com/) in [pfSense 2.5.0](https://github.com/pfsense/pfsense/tree/RELENG_2_5_0) to a package suitable for sideloading and more frequent updating on future releases of pfSense.
2+
This is a port of the original WireGuard*** UI bits as implemented by [Netgate](https://www.netgate.com/) in [pfSense 2.5.0](https://github.com/pfsense/pfsense/tree/RELENG_2_5_0) to a package suitable for sideloading and more frequent updating on future releases of pfSense.
33

44
This also includes some improvments such as a proper status page (found under Status / WireGuard Status) and improved assigned interface handling.
55

6-
Under the hood, this implementation relies on `wg-quick(8)` for interacting with WireGuard.
7-
86
Because of the present limitations with pfSense internals and what packages can (and cannot) do on the system, this package includes several opinionated design changes that attempt to work around these limitations. The goal of this package is to use nothing more than what pfSense gives us and to leave the core codebase untouched. This will (should) greatly accelerate the review and testing required for consideration in the offical package repository.
97

108
These changes include:
@@ -47,12 +45,6 @@ You can find pre-compiled binaries and packages [here](https://github.com/theone
4745

4846
https://docs.netgate.com/pfsense/en/latest/vpn/wireguard/index.html
4947

50-
## Screenshots (as of v0.0.2_2)
51-
52-
![1](https://github.com/theonemcdonald/pfSense-pkg-WireGuard/blob/main/extra/images/screen1.PNG)
53-
54-
![2](https://github.com/theonemcdonald/pfSense-pkg-WireGuard/blob/main/extra/images/screen2.PNG)
55-
56-
![3](https://github.com/theonemcdonald/pfSense-pkg-WireGuard/blob/main/extra/images/screen3.PNG)
48+
## Recognition
5749

58-
![4](https://github.com/theonemcdonald/pfSense-pkg-WireGuard/blob/main/extra/images/screen4.PNG)
50+
\*** "WireGuard" and the "WireGuard" logo are registered trademarks of Jason A. Donenfeld.

src/Makefile

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PORTNAME= pfSense-pkg-WireGuard
2-
PORTVERSION= 0.0.9
2+
PORTVERSION= 0.0.9.5
33
CATEGORIES= net
44
MASTER_SITES= # empty
55
DISTFILES= # empty
@@ -12,7 +12,7 @@ COMMENT= pfSense package WireGuard
1212
LICENSE= APACHE20
1313

1414
RUN_DEPENDS= wireguard-kmod>0:net/wireguard-kmod \
15-
wireguard-tools-lite>0:net/wireguard-tools-lite
15+
wireguard-tools-lite>0:net/wireguard-tools@lite
1616

1717
NO_BUILD= yes
1818
NO_MTREE= yes
@@ -26,8 +26,6 @@ do-extract:
2626
do-install:
2727
${MKDIR} ${STAGEDIR}/etc/inc/priv
2828

29-
${MKDIR} ${STAGEDIR}${PREFIX}/etc
30-
3129
${MKDIR} ${STAGEDIR}${PREFIX}/pkg/wireguard
3230

3331
${MKDIR} ${STAGEDIR}${PREFIX}/www/shortcuts
@@ -41,9 +39,6 @@ do-install:
4139
${INSTALL_DATA} ${FILESDIR}${PREFIX}/pkg/wireguard.xml \
4240
${STAGEDIR}${PREFIX}/pkg
4341

44-
${INSTALL_DATA} -m 0755 ${FILESDIR}${PREFIX}/etc/rc.* \
45-
${STAGEDIR}${PREFIX}/etc
46-
4742
${INSTALL_DATA} ${FILESDIR}${PREFIX}/pkg/wireguard/*.inc \
4843
${STAGEDIR}${PREFIX}/pkg/wireguard
4944

@@ -63,4 +58,4 @@ do-install:
6358
${STAGEDIR}${DATADIR}/info.xml \
6459
${STAGEDIR}${PREFIX}/pkg/wireguard.xml
6560

66-
.include <bsd.port.mk>
61+
.include <bsd.port.mk>

src/files/usr/local/etc/rc.reload_wireguard

Lines changed: 0 additions & 66 deletions
This file was deleted.

src/files/usr/local/pkg/wireguard.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141
<section>Status</section>
4242
<url>/wg/status_wireguard.php</url>
4343
</menu>
44+
<service>
45+
<name>wireguard</name>
46+
<rcfile>wireguardd</rcfile>
47+
<executable>php_wg</executable>
48+
<description>WireGuard</description>
49+
</service>
4450
<custom_php_install_command>
4551
<![CDATA[
4652
wg_install();

src/files/usr/local/pkg/wireguard/wg.inc

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -384,28 +384,22 @@ function wg_resync_peer($peer) {
384384
function wg_resync_all() {
385385
global $g, $wgg;
386386

387-
wg_create_config_files();
388-
389387
if ($g['wireguard_installing']) {
390388

391-
update_status("done.\n Configuring any existing WireGuard tunnels...");
389+
unset($g['wireguard_installing']);
392390

391+
return;
392+
393393
}
394394

395+
wg_create_config_files();
396+
395397
foreach ($wgg['tunnels'] as $tunnel) {
396-
398+
397399
wg_resync_tunnel($tunnel['name'], true);
398400

399401
}
400402

401-
if ($g['wireguard_installing']) {
402-
403-
update_status("done.\n");
404-
405-
unset($g['wireguard_installing']);
406-
407-
}
408-
409403
}
410404

411405

src/files/usr/local/pkg/wireguard/wg_api.inc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ function wg_interface_update_addresses($wg_ifname) {
268268

269269
}
270270

271+
// Need to let pfSense handle the assigned interfaces
271272
} elseif (is_wg_tunnel_assigned($wg_ifname)) {
272273

273274
if ($pfsense_if_name = wg_get_pfsense_interface_info($wg_ifname)) {
@@ -324,7 +325,7 @@ function wg_interface_syncconf($wg_ifname, $verbose = false) {
324325
}
325326

326327
/*
327-
* This creates a WireGuard interface of a specified name and adds it to the WireGuard interface group
328+
* This creates a WireGuard interface of a specified name
328329
*/
329330
function wg_interface_create($wg_ifname, $verbose = false) {
330331
global $wgg;
@@ -355,7 +356,7 @@ function wg_get_real_ifs() {
355356
}
356357

357358
/*
358-
* This creates a WireGuard interface of a specified name and adds it to the WireGuard interface group
359+
* This adds a WireGuard interface to the WireGuard interface group
359360
*/
360361
function wg_interface_group_add($wg_ifname, $verbose = false) {
361362
global $wgg;
@@ -533,11 +534,11 @@ function wg_get_tunnel_array_index($tunnel_name) {
533534

534535
if (is_array($wgg['tunnels'])) {
535536

536-
foreach ($wgg['tunnels'] as $t_index => $tunnel) {
537+
foreach ($wgg['tunnels'] as $tun_idx => $tunnel) {
537538

538539
if ($tunnel['name'] == $tunnel_name) {
539540

540-
return $t_index;
541+
return $tun_idx;
541542

542543
}
543544

src/files/usr/local/pkg/wireguard/wg_globals.inc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ $wgg = array(
3131
'ifconfig' => '/sbin/ifconfig',
3232
'pkg' => '/usr/sbin/pkg',
3333
'kldunload' => '/sbin/kldunload',
34+
'php' => '/usr/local/bin/php',
35+
'wg_daemon' => '/usr/local/bin/php_wg',
36+
'wg_includes' => '/usr/local/pkg/wireguard',
3437
'kmod' => 'if_wg.ko',
3538
'pkg_names' => array(
3639
'pfSense-pkg-WireGuard',
@@ -53,7 +56,7 @@ $wgg = array(
5356
'members' => null),
5457
'shellcmdentries' => array(
5558
array(
56-
'cmd' => '/usr/local/etc/rc.reload_wireguard',
59+
'cmd' => 'service wireguardd start',
5760
'cmdtype' => 'earlyshellcmd',
5861
'description' => 'WireGuard earlyshellcmd (DO NOT EDIT/DELETE!)')),
5962
'unboundaclentry' => array(

src/files/usr/local/pkg/wireguard/wg_guiconfig.inc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* limitations under the License.
2020
*/
2121

22+
// pfSense includes
23+
require_once('util.inc');
2224

2325
// WireGuard includes
2426
require_once('wireguard/wg_globals.inc');
@@ -186,8 +188,17 @@ function wg_secret_input_type() {
186188

187189
// Gets the appropriate class based on whether or not the target is enabled or disabled
188190
function wg_entrystatus_class($target_device) {
191+
global $wgg;
192+
193+
if (isset($target_device) &&
194+
$target_device['enabled'] == 'yes' &&
195+
is_module_loaded($wgg['kmod'])) {
196+
197+
return 'enabled';
198+
199+
}
189200

190-
return (isset($target_device) && $target_device['enabled'] == 'yes') ? 'enabled' : 'disabled';
201+
return 'disabled';
191202

192203
}
193204

src/files/usr/local/pkg/wireguard/wg_install.inc

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222
// pfSense includes
2323
require_once('config.inc');
2424
require_once('services.inc');
25+
require_once('service-utils.inc');
2526
require_once('util.inc');
2627

2728
// WireGuard includes
28-
require_once('wireguard/wg_globals.inc');
2929
require_once('wireguard/wg_api.inc');
30+
require_once('wireguard/wg_globals.inc');
31+
require_once('wireguard/wg_service.inc');
3032

3133
/*
3234
* This is the main install hook
@@ -53,9 +55,13 @@ function wg_install() {
5355
// Installs the 'WireGuard' interface group
5456
wg_ifgroup_install();
5557

56-
update_status("done.\n");
58+
update_status("done.\n Creating WireGuard service...");
5759

58-
// The first organic resync called by pfSense package manager will finish the installation process
60+
wg_service_install();
61+
62+
wg_service_rcfile();
63+
64+
update_status("done.\n");
5965

6066
}
6167

@@ -243,11 +249,17 @@ function wg_deinstall() {
243249

244250
}
245251

252+
246253
update_status("done.\n Destroying WireGuard tunnels...");
247254

248255
// Teardown any WireGuard tunnel interfaces
249256
wg_destroy_tunnels();
250257

258+
update_status("done.\n Removing WireGuard service...");
259+
260+
// Remove WireGuard watchdog service
261+
wg_service_deinstall();
262+
251263
update_status("done.\n");
252264

253265
}

0 commit comments

Comments
 (0)