Skip to content

Commit dd3b6b4

Browse files
authored
Merge latest devel branch into main (v0.0.6_1) (#29)
* Working on improving interface bootstrap * Testing bootstrapper rewrite * Fix syntax error * Working on bootstrapper * Testing another option * Working on a few things * Fixed syntax problem * Testing * Working on improvements to startup * Removed some code that might not be needed anymore if we change the interface prefix to tun_ * Removed reference to function * Make sure to configure hard during bootup * Working on startup code * Installation update status cosmetic change * Looks like an rcfile might be the best way to get things going at startup * Fix syntax error * Fix glob string * write_rcfile should use config.xml for truth not the conf path * Need to create the pseudoservice definition in wireguard.xml * Fix incorrect variable in wg_write_rcfile * Working on rc startup code * Syntax fix in write_rcfile * This build is likely broken, I'm working on improvements * Yep things are broken, still working * Makefile fix * Another makefile bug * Still testing out different startup mechanisms * More testing * Cosmetic change during install and resync * Remove pseudoservice definition * Candidate for v0.0.6 bump * Remove keep extra secrets setting, no longer required * Comment clarity * More tweaks to startup * Still working on startup code * Remove lingering blurring code * Cleaned up some globals defines that are no longer needed * Cleaning up some obsolete global defines * Implementing proper deinstall handling of configuration data * Syntax error * Syntax error * Not confident in configuration removal code at this point, will reevaluate later. * Need to bump to 0.0.6_1 because I sent an early build to some insiders
1 parent 3171c56 commit dd3b6b4

File tree

9 files changed

+78
-370
lines changed

9 files changed

+78
-370
lines changed

src/Makefile

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# $FreeBSD$
22

33
PORTNAME= pfSense-pkg-WireGuard
4-
PORTVERSION= 0.0.5
4+
PORTVERSION= 0.0.6
55
PORREVISION= 1
66
CATEGORIES= net
77
MASTER_SITES= # empty
@@ -31,11 +31,8 @@ do-extract:
3131
do-install:
3232
${MKDIR} ${STAGEDIR}/etc/inc/priv
3333

34-
${MKDIR} ${STAGEDIR}${PREFIX}/etc
35-
3634
${MKDIR} ${STAGEDIR}${PREFIX}/pkg
3735
${MKDIR} ${STAGEDIR}${PREFIX}/pkg/wireguard
38-
${MKDIR} ${STAGEDIR}${PREFIX}/pkg/wireguard/etc
3936

4037
${MKDIR} ${STAGEDIR}${PREFIX}/www
4138
${MKDIR} ${STAGEDIR}${PREFIX}/www/shortcuts
@@ -46,9 +43,6 @@ do-install:
4643
${INSTALL_DATA} ${FILESDIR}/etc/inc/priv/wireguard.priv.inc \
4744
${STAGEDIR}/etc/inc/priv
4845

49-
${INSTALL_DATA} -m 0755 ${FILESDIR}${PREFIX}/etc/rc.reload_wireguard \
50-
${STAGEDIR}${PREFIX}/etc
51-
5246
${INSTALL_DATA} ${FILESDIR}${PREFIX}/pkg/wireguard.xml \
5347
${STAGEDIR}${PREFIX}/pkg
5448

@@ -65,9 +59,6 @@ do-install:
6559
${INSTALL_DATA} ${FILESDIR}${PREFIX}/pkg/wireguard/wg_validate.inc \
6660
${STAGEDIR}${PREFIX}/pkg/wireguard
6761

68-
${INSTALL_DATA} -m 0755 ${FILESDIR}${PREFIX}/pkg/wireguard/etc/rc.bootstrap_wireguard \
69-
${STAGEDIR}${PREFIX}/pkg/wireguard/etc
70-
7162
${INSTALL_DATA} ${FILESDIR}${PREFIX}/www/shortcuts/pkg_wireguard.inc \
7263
${STAGEDIR}${PREFIX}/www/shortcuts
7364

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

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

src/files/usr/local/pkg/wireguard/etc/rc.bootstrap_wireguard

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

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

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -38,50 +38,13 @@ require_once('wg_install.inc');
3838
require_once('wg_extras.inc');
3939
require_once('wg_validate.inc');
4040

41-
// Setup all WireGuard tunnels
42-
function wg_configure($conf_hard = false, $verbose = false) {
43-
global $config;
44-
45-
$wg_tunnels = $config['installedpackages']['wireguard']['tunnel'];
46-
47-
// Nothing to configure, bail out early
48-
if (!is_array($wg_tunnels)) {
49-
50-
return;
51-
52-
}
53-
54-
// Sync conf files to disk
55-
wg_create_config_files();
56-
57-
$tunnel = [];
58-
59-
foreach ($wg_tunnels as $tunnel) {
60-
61-
if (isset($tunnel['enabled']) && $tunnel['enabled'] == 'yes') {
62-
63-
// Attempt to configure the WireGuard tunnel
64-
wg_configure_if($tunnel, $conf_hard, $verbose);
65-
66-
67-
} else {
68-
69-
// Attempt to destroy the WireGaurd tunnel
70-
wg_destroy_if($tunnel, $verbose);
71-
72-
}
73-
74-
}
75-
76-
}
77-
7841
// Setup WireGuard tunnel
7942
function wg_configure_if($tunnel, $conf_hard = true, $verbose = false) {
8043
global $config, $wgg;
8144

8245
$verbose_pipe = ($verbose ? "" : " > /dev/null 2>&1");
8346

84-
// Should be perform a hard reconfiguration
47+
// Should we perform a hard reconfiguration
8548
if ($conf_hard) {
8649

8750
// Destroy the interface first
@@ -104,6 +67,7 @@ function wg_configure_if($tunnel, $conf_hard = true, $verbose = false) {
10467
// Remove WireGuard tunnel
10568
function wg_destroy_if($tunnel, $verbose = false) {
10669

70+
// Execute the wg-quick(8) way of tearing down an interface
10771
exec_wg_quick_action($tunnel, "down", $verbose);
10872

10973
// Need to transform out of tunnel structure because pfSense_interface_destroy expects an ifname
@@ -113,6 +77,7 @@ function wg_destroy_if($tunnel, $verbose = false) {
11377

11478
}
11579

80+
// Now execute the pfSense way of tearing down an interface
11681
pfSense_interface_destroy($tunnel);
11782

11883
}
@@ -235,29 +200,61 @@ function wg_do_post($post) {
235200
return(array('input_errors' => $input_errors, 'pconfig' => $pconfig));
236201
}
237202

238-
function wg_resync() {
239-
global $config, $wgg;
203+
function wg_resync($verbose = false) {
204+
global $config, $g, $wgg;
205+
206+
// Write out configuration files to disk
207+
wg_create_config_files();
240208

241209
// Attempt to reinstall the interface group to keep things clean
242210
wg_ifgroup_install();
243211

212+
if ($g['wireguard_installing']) {
213+
214+
update_status("\n Configuring WireGuard tunnels...");
215+
216+
}
217+
218+
// Get a list of configured tunnels
244219
$wg_tunnels = $config['installedpackages']['wireguard']['tunnel'];
245220

246221
if (is_array($wg_tunnels)) {
247222

248223
foreach ($wg_tunnels as $tunnel) {
249224

250225
if (isset($tunnel['enabled']) && $tunnel['enabled'] == 'yes') {
251-
$is_assigned = is_wg_tunnel_assigned($tunnel);
252226

253-
wg_configure_if($tunnel, !($is_assigned));
227+
// Determine if we should configure hard or soft
228+
$conf_hard = (!is_wg_tunnel_assigned($tunnel) || !does_interface_exist($tunnel['name']));
229+
230+
wg_configure_if($tunnel, $conf_hard, $verbose);
231+
232+
$if_friendly = convert_real_interface_to_friendly_interface_name($tunnel['name']);
233+
234+
interface_reconfigure($if_friendly);
235+
236+
} else {
237+
238+
// Attempt to destroy the WireGuard tunnel
239+
wg_destroy_if($tunnel, $verbose);
254240

255241
}
256242

243+
244+
257245
}
258246

259247
}
260248

249+
if ($g['wireguard_installing']) {
250+
251+
update_status("done.\n");
252+
253+
// We are no longer installing
254+
unset($g['wireguard_installing']);
255+
256+
}
257+
261258
}
262259

263260
function wg_create_config_files($clean = true) {
@@ -282,7 +279,7 @@ function wg_create_config_files($clean = true) {
282279
// We almost always want to just overwrite the configurations
283280
if ($clean) {
284281

285-
delete_wg_configs();
282+
wg_delete_config_files();
286283

287284
}
288285

@@ -300,6 +297,16 @@ function wg_create_config_files($clean = true) {
300297

301298
}
302299

300+
/*
301+
* Remove all wg config files from the conf directory
302+
*/
303+
function wg_delete_config_files() {
304+
global $wgg;
305+
306+
unlink_if_exists("{$wgg['conf_path']}/*.conf");
307+
308+
}
309+
303310
// Write each file
304311
function make_wg_conf($tunnel) {
305312
global $wgg;
@@ -373,14 +380,6 @@ function make_wg_conf($tunnel) {
373380
chmod($wgg['conf_path'] . "/" . $tunnel['name'] . ".conf", 0600);
374381
}
375382

376-
// Remove all wg config files from the conf directory
377-
function delete_wg_configs() {
378-
global $wgg;
379-
380-
unlink_if_exists($wgg['conf_path'] . "/*.conf");
381-
382-
}
383-
384383
// Return WireGuard tunnel networks for a given address family
385384
function wg_get_tunnel_networks($family = 'both') {
386385
global $config;

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,14 @@ $wgg = array(
3333
'kldstat' => '/sbin/kldstat',
3434
'pkg' => '/usr/sbin/pkg',
3535

36-
'conf_path' => '/etc/wireguard',
36+
'conf_path' => '/usr/local/etc/wireguard',
3737

38-
'if_prefix' => 'wg',
38+
'if_prefix' => 'tun_wg',
3939
'if_group' => 'WireGuard',
4040
'ifgroupentry' => array('ifname' => 'WireGuard', 'descr' => 'Dynamic Group for WireGuard', 'members' => null),
4141
'default_mtu' => 1420,
4242
'default_port' => 51820,
4343

44-
'script_path' => '/usr/local/etc',
45-
'earlyshellcmds' => array('/usr/local/etc/rc.bootstrap_wireguard', '/usr/local/etc/rc.reload_wireguard'),
46-
'pkg_scripts' => array('/usr/local/etc/rc.reload_wireguard'),
47-
'extra_scripts' => array('/usr/local/pkg/wireguard/etc/rc.bootstrap_wireguard'),
48-
4944
'verbose' => false
5045
);
5146

0 commit comments

Comments
 (0)