Skip to content

Commit 2b650b9

Browse files
authored
Bump to v0.0.6_2 and prepare for PR with Netgate (#30)
* 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 * Some minor changes to interface handling, working on an edge case * Bump to 0.0.6_2 beause of last commit * Typo fix on include * Removed boilerplate for logging facilities...will address this later. * Testing some improements to the code * Remove references to old include file * fix syntax error * Fix another syntax bug * Another syntax bug * More cleanup and testing * More cleanup * Cosmetic changes to install/deinstall update status * Working on deinstall script * More improvements * Cosmetic * Another cosmetic fix.
1 parent a6b6e63 commit 2b650b9

File tree

13 files changed

+165
-179
lines changed

13 files changed

+165
-179
lines changed

src/Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
PORTNAME= pfSense-pkg-WireGuard
44
PORTVERSION= 0.0.6
5-
PORREVISION= 1
5+
PORREVISION= 2
66
CATEGORIES= net
77
MASTER_SITES= # empty
88
DISTFILES= # empty
@@ -54,8 +54,6 @@ do-install:
5454
${STAGEDIR}${PREFIX}/pkg/wireguard
5555
${INSTALL_DATA} ${FILESDIR}${PREFIX}/pkg/wireguard/wg_install.inc \
5656
${STAGEDIR}${PREFIX}/pkg/wireguard
57-
${INSTALL_DATA} ${FILESDIR}${PREFIX}/pkg/wireguard/wg_extras.inc \
58-
${STAGEDIR}${PREFIX}/pkg/wireguard
5957
${INSTALL_DATA} ${FILESDIR}${PREFIX}/pkg/wireguard/wg_validate.inc \
6058
${STAGEDIR}${PREFIX}/pkg/wireguard
6159

src/files/etc/inc/priv/wireguard.priv.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ $priv_list['page-vpn-wireguard']['match'] = array();
2929

3030
$priv_list['page-vpn-wireguard']['match'][] = "wg/vpn_wg.php";
3131
$priv_list['page-vpn-wireguard']['match'][] = "wg/vpn_wg_edit.php";
32+
$priv_list['page-vpn-wireguard']['match'][] = "wg/vpn_wg_settings.php";
3233

3334
$priv_list['page-status-wireguard'] = array();
3435
$priv_list['page-status-wireguard']['name'] = "WebCfg - Status: WireGuard Status";

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

Lines changed: 59 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,11 @@ require_once('util.inc');
3535
require_once('wg_api.inc');
3636
require_once('wg_globals.inc');
3737
require_once('wg_install.inc');
38-
require_once('wg_extras.inc');
3938
require_once('wg_validate.inc');
4039

4140
// Setup WireGuard tunnel
4241
function wg_configure_if($tunnel, $conf_hard = true, $verbose = false) {
4342
global $config, $wgg;
44-
45-
$verbose_pipe = ($verbose ? "" : " > /dev/null 2>&1");
4643

4744
// Should we perform a hard reconfiguration
4845
if ($conf_hard) {
@@ -59,7 +56,18 @@ function wg_configure_if($tunnel, $conf_hard = true, $verbose = false) {
5956
wg_syncconf($tunnel);
6057

6158
// Add the interface to the interface group (i.e. WireGuard)
62-
exec("{$wgg['ifconfig']} {$tunnel['name']} group {$wgg['ifgroupentry']['ifname']}" . $verbose_pipe);
59+
exec("{$wgg['ifconfig']} {$tunnel['name']} group {$wgg['ifgroupentry']['ifname']}" . verbose_pipe($verbose));
60+
61+
// Get the tunnel interface friendly name if assigned
62+
$if_fname = convert_real_interface_to_friendly_interface_name($tunnel['name']);
63+
64+
if(isset($if_fname)) {
65+
66+
interface_reconfigure($if_fname);
67+
68+
system_routing_configure($if_fname);
69+
70+
}
6371

6472
}
6573

@@ -85,15 +93,17 @@ function wg_destroy_if($tunnel, $verbose = false) {
8593
function wg_delete_tunnel($tunidx) {
8694
global $config, $wgg;
8795

88-
if ($config['installedpackages']['wireguard']['tunnel'][$tunidx]) {
96+
wg_globals();
97+
98+
if ($wgg['tunnels'][$tunidx]) {
8999

90100
unset($ifname);
91101

92102
unset($conf_path);
93103

94-
if (isset($config['installedpackages']['wireguard']['tunnel'][$tunidx]['name'])) {
104+
if (isset($wgg['tunnels'][$tunidx]['name'])) {
95105

96-
$ifname = $config['installedpackages']['wireguard']['tunnel'][$tunidx]['name'];
106+
$ifname = $wgg['tunnels'][$tunidx]['name'];
97107

98108
}
99109

@@ -104,7 +114,7 @@ function wg_delete_tunnel($tunidx) {
104114
}
105115

106116
// Delete the tunnel configuration entry
107-
unset($config['installedpackages']['wireguard']['tunnel'][$tunidx]);
117+
unset($wgg['tunnels'][$tunidx]);
108118

109119
write_config("[WireGuard] tunnel {$index} updated.");
110120

@@ -125,13 +135,13 @@ function wg_delete_tunnel($tunidx) {
125135
function wg_do_post($post) {
126136
global $config, $wgg;
127137

128-
init_config_arr(array('installedpackages', 'wireguard', 'tunnel'));
138+
wg_globals();
129139

130140
$input_errors = array();
131141

132142
$index = $post['index'];
133143

134-
$pconfig = &$config['installedpackages']['wireguard']['tunnel'][$index];
144+
$pconfig = $wgg['tunnels'][$index];
135145

136146
if (empty($pconfig['name'])) {
137147

@@ -193,8 +203,11 @@ function wg_do_post($post) {
193203
$input_errors = wg_validate_post($pconfig);
194204

195205
if (!$input_errors) {
196-
$config['installedpackages']['wireguard']['tunnel'][$index] = $pconfig;
206+
207+
$wgg['tunnels'][$index] = $pconfig;
208+
197209
write_config("[WireGuard] Tunnel {$pconfig['name']} (Index {$index}) updated.");
210+
198211
}
199212

200213
return(array('input_errors' => $input_errors, 'pconfig' => $pconfig));
@@ -203,6 +216,9 @@ function wg_do_post($post) {
203216
function wg_resync($verbose = false) {
204217
global $config, $g, $wgg;
205218

219+
// Read latest settings
220+
wg_globals();
221+
206222
// Write out configuration files to disk
207223
wg_create_config_files();
208224

@@ -215,24 +231,18 @@ function wg_resync($verbose = false) {
215231

216232
}
217233

218-
// Get a list of configured tunnels
219-
$wg_tunnels = $config['installedpackages']['wireguard']['tunnel'];
234+
if (is_array($wgg['tunnels'])) {
220235

221-
if (is_array($wg_tunnels)) {
222-
223-
foreach ($wg_tunnels as $tunnel) {
236+
foreach ($wgg['tunnels'] as $tunnel) {
224237

225238
if (isset($tunnel['enabled']) && $tunnel['enabled'] == 'yes') {
226239

227240
// Determine if we should configure hard or soft
228241
$conf_hard = (!is_wg_tunnel_assigned($tunnel) || !does_interface_exist($tunnel['name']));
229242

243+
// Attempt to create the WireGuard tunnel
230244
wg_configure_if($tunnel, $conf_hard, $verbose);
231245

232-
$if_friendly = convert_real_interface_to_friendly_interface_name($tunnel['name']);
233-
234-
interface_reconfigure($if_friendly);
235-
236246
} else {
237247

238248
// Attempt to destroy the WireGuard tunnel
@@ -248,7 +258,7 @@ function wg_resync($verbose = false) {
248258

249259
if ($g['wireguard_installing']) {
250260

251-
update_status("done.\n");
261+
update_status(" done.\n");
252262

253263
// We are no longer installing
254264
unset($g['wireguard_installing']);
@@ -260,10 +270,10 @@ function wg_resync($verbose = false) {
260270
function wg_create_config_files($clean = true) {
261271
global $config, $wgg;
262272

263-
$wg_tunnels = $config['installedpackages']['wireguard']['tunnel'];
273+
wg_globals();
264274

265275
// We've got some tunnels to configure
266-
if (is_array($wg_tunnels)) {
276+
if (is_array($wgg['tunnels'])) {
267277

268278
// Create configuration path if it is missing
269279
if (!file_exists($wgg['conf_path'])) {
@@ -283,7 +293,7 @@ function wg_create_config_files($clean = true) {
283293

284294
}
285295

286-
foreach ($wg_tunnels as $tunnel) {
296+
foreach ($wgg['tunnels'] as $tunnel) {
287297

288298
if (!empty($tunnel['enabled']) && $tunnel['enabled'] == 'yes') {
289299

@@ -298,12 +308,35 @@ function wg_create_config_files($clean = true) {
298308
}
299309

300310
/*
301-
* Remove all wg config files from the conf directory
311+
* Remove all wg config files from any potential conf directory
302312
*/
303313
function wg_delete_config_files() {
304314
global $wgg;
305315

306-
unlink_if_exists("{$wgg['conf_path']}/*.conf");
316+
// Loop through each potential conf path and delete all .conf files
317+
foreach ($wgg['conf_paths_to_clean'] as $confpath) {
318+
319+
unlink_if_exists("{$confpath}/*.conf");
320+
321+
}
322+
323+
}
324+
325+
/*
326+
* Removes any configuration xml paths as defined by $wgg['xml_conf_tags']
327+
*/
328+
function wg_remove_config_settings() {
329+
global $config, $wgg;
330+
331+
foreach ($wgg['xml_conf_tags'] as $conf_tag) {
332+
333+
if (isset($config['installedpackages'][$conf_tag])) {
334+
335+
unset($config['installedpackages'][$conf_tag]);
336+
337+
}
338+
339+
}
307340

308341
}
309342

@@ -380,63 +413,4 @@ function make_wg_conf($tunnel) {
380413
chmod($wgg['conf_path'] . "/" . $tunnel['name'] . ".conf", 0600);
381414
}
382415

383-
// Return WireGuard tunnel networks for a given address family
384-
function wg_get_tunnel_networks($family = 'both') {
385-
global $config;
386-
$wg_tunnel_networks = array();
387-
init_config_arr(array('installedpackages', 'wireguard', 'tunnel'));
388-
if (is_wg_enabled()) {
389-
foreach ($config['installedpackages']['wireguard']['tunnel'] as $wg) {
390-
if (empty($wg['enabled']) ||
391-
empty($wg['interface']['address'])) {
392-
continue;
393-
}
394-
foreach(explode(',', $wg['interface']['address']) as $wga) {
395-
list($wgnet, $wgmask) = explode('/', trim($wga));
396-
if ((is_ipaddrv6($wgnet) && ($family == 'ipv4')) ||
397-
(is_ipaddrv4($wgnet) && ($family == 'ipv6'))) {
398-
continue;
399-
}
400-
$network = gen_subnet($wgnet, $wgmask);
401-
$wg_tunnel_networks[] = "{$network}/{$wgmask}";
402-
}
403-
}
404-
}
405-
return $wg_tunnel_networks;
406-
}
407-
408-
// Locate a viable remote gateway address for a WireGuard tunnel
409-
// Fall back to using the tunnel address itself.
410-
// https://redmine.pfsense.org/issues/11300
411-
function wg_find_tunnel_gw($tunnel, $addr) {
412-
list($ip, $mask) = explode("/", trim($addr));
413-
// Loop through peers looking for a viable remote gateway address
414-
if (is_array($tunnel['peers']) &&
415-
is_array($tunnel['peers']['wgpeer']) &&
416-
count($tunnel['peers']['wgpeer']) > 0) {
417-
foreach ($tunnel['peers']['wgpeer'] as $peer) {
418-
// If this peer has no configured Peer WireGuard Address, skip it.
419-
if (empty($peer['peerwgaddr'])) {
420-
continue;
421-
}
422-
// Check each Peer WireGuard Address entry
423-
foreach (explode(',', $peer['peerwgaddr']) as $pwga) {
424-
// Ensure the address family of this entry matches the one we're seeking
425-
if (is_v4($ip) !== is_v4($pwga)) {
426-
continue;
427-
}
428-
// If there is a subnet mask, ditch it.
429-
list($pip, $pmask) = explode('/', trim($pwga));
430-
// Check that this address is in the desired subnet
431-
if (ip_in_subnet($pip, trim($addr))) {
432-
// We found a good candidate, return it
433-
return $pip;
434-
}
435-
}
436-
}
437-
}
438-
// If no viable candidate is found, return the tunnel address
439-
return $ip;
440-
}
441-
442416
?>

0 commit comments

Comments
 (0)