Project

General

Profile

Feature #12522 » patch_openvpn_csc.patch

Patch for pfsense 2.7.2 release - Phil Wardt, 07/19/2024 01:20 PM

View differences:

src/etc/inc/openvpn.inc
757 757

  
758 758
	if ($settings['netbios_enable']) {
759 759

  
760
		if (!empty($settings['dhcp_nbttype']) && ($settings['dhcp_nbttype'] != 0)) {
761
			$conf .= "push \"dhcp-option NBT {$settings['dhcp_nbttype']}\"\n";
760
		if (!empty($settings['netbios_ntype']) && ($settings['netbios_ntype'] != 0)) {
761
			$conf .= "push \"dhcp-option NBT {$settings['netbios_ntype']}\"\n";
762 762
		}
763
		if (!empty($settings['dhcp_nbtscope'])) {
764
			$conf .= "push \"dhcp-option NBS {$settings['dhcp_nbtscope']}\"\n";
763
		if (!empty($settings['netbios_scope'])) {
764
			$conf .= "push \"dhcp-option NBS {$settings['netbios_scope']}\"\n";
765 765
		}
766 766

  
767 767
		if (!empty($settings['wins_server1'])) {
......
774 774
		if (!empty($settings['nbdd_server1'])) {
775 775
			$conf .= "push \"dhcp-option NBDD {$settings['nbdd_server1']}\"\n";
776 776
		}
777
		if (!empty($settings['nbdd_server2'])) {
778
			$conf .= "push \"dhcp-option NBDD {$settings['nbdd_server2']}\"\n";
777 779
		}
780
	}
778 781

  
779 782
	if ($settings['gwredir']) {
780 783
		$conf .= "push \"redirect-gateway def1\"\n";
......
1695 1698
	}
1696 1699
	openvpn_create_dirs();
1697 1700

  
1701
	/* Some options remove the gateway or topology which are required;
1702
	 * in such cases, these can be automatically determined. */
1703
	$auto_config_gateway4 = false;
1704
	$auto_config_gateway6 = false;
1705
	$auto_config_topology = false;
1706

  
1698 1707
	if (empty($settings['server_list'])) {
1699 1708
		$csc_server_list = array();
1700 1709
	} else {
......
1706 1715
		$conf .= "disable\n";
1707 1716
	}
1708 1717

  
1709
	if ($settings['push_reset']) {
1718
	// Reset options
1719
	if (isset($settings['override_options']) && ($settings['override_options'] == 'push_reset')) {
1720
		if (isset($settings['keep_minimal'])) {
1721
			$auto_config_gateway4 = true;
1722
			$auto_config_gateway6 = true;
1723
			$auto_config_topology = true;
1724
		}
1710 1725
		$conf .= "push-reset\n";
1711 1726
	}
1712

  
1713
	if ($settings['remove_route']) {
1714
		$conf .= "push-remove route\n";
1727
	if (!empty($settings['remove_options'])) {
1728
		foreach (explode(',', $settings['remove_options']) as $option) {
1729
			if (isset($settings['keep_minimal']) && ($option == 'remove_route')) {
1730
				$auto_config_gateway4 = true;
1731
				$auto_config_gateway6 = true;
1715 1732
			}
1733
			$options = match ($option) {
1734
				'remove_route' => 'route',
1735
				'remove_iroute' => 'iroute',
1736
				'remove_redirect_gateway' => 'redirect-gateway',
1737
				'remove_inactive' => 'inactive',
1738
				'remove_ping' => 'ping',
1739
				'remove_ping_action' => ['ping-restart', 'ping-exit'],
1740
				'remove_dnsdomain' => '"dhcp-option DOMAIN"',
1741
				'remove_dnsservers' => '"dhcp-option DNS"',
1742
				'remove_ntpservers' => '"dhcp-option NTP"',
1743
				'remove_netbios_ntype' => '"dhcp-option NBT"',
1744
				'remove_netbios_scope' => '"dhcp-option NBS"',
1745
				'remove_wins' => '"dhcp-option WINS"'
1746
			};
1747
			if (is_array($options)) {
1748
				foreach ($options as $option_name) {
1749
					$conf .= "push-remove {$option_name}\n";
1750
				}
1751
			} else {
1752
				$conf .= "push-remove {$options}\n";
1753
			}
1754
		}
1755
	}
1716 1756

  
1757
	// Local network route options
1717 1758
	if ($settings['local_network']) {
1718 1759
		$conf .= openvpn_gen_routes($settings['local_network'], "ipv4", true);
1719 1760
	}
......
1721 1762
		$conf .= openvpn_gen_routes($settings['local_networkv6'], "ipv6", true);
1722 1763
	}
1723 1764

  
1724
	// Add a remote network iroute if set
1765
	// Remote network iroute options
1725 1766
	if (openvpn_validate_cidr($settings['remote_network'], "", true, "ipv4", true) === FALSE) {
1726 1767
		$conf .= openvpn_gen_routes($settings['remote_network'], "ipv4", false, true);
1727 1768
	}
1728
	// Add a remote network iroute if set
1729 1769
	if (openvpn_validate_cidr($settings['remote_networkv6'], "", true, "ipv6", true) === FALSE) {
1730 1770
		$conf .= openvpn_gen_routes($settings['remote_networkv6'], "ipv6", false, true);
1731 1771
	}
1732 1772

  
1773
	// Gatewy override options
1774
	if (!empty($settings['gateway'])) {
1775
		$auto_config_gateway4 = false;
1776
		$conf .= "push \"route-gateway {$settings['gateway']}\"\n";
1777
	}
1778
	if (!empty($settings['gateway6'])) {
1779
		$auto_config_gateway6 = false;
1780
		$conf .= "push \"route-ipv6-gateway {$settings['gateway6']}\"\n";
1781
	}
1782

  
1783
	// Inactivity override options
1784
	if (isset($settings['inactive_seconds'])) {
1785
		$conf .= "push \"inactive {$settings['inactive_seconds']}\"\n";
1786
	}
1787

  
1788
	// Ping override options
1789
	if (isset($settings['ping_seconds'])) {
1790
		$conf .= "push \"ping {$settings['ping_seconds']}\"\n";
1791
	}
1792
	if (isset($settings['ping_action'])) {
1793
		$action = str_replace("_", "-", $settings['ping_action']);
1794
		$conf .= "push \"{$action} {$settings['ping_action_seconds']}\"\n";
1795
	}
1796

  
1797
	// DHCP and gateway redirect options
1733 1798
	openvpn_add_dhcpopts($settings, $conf);
1734 1799

  
1800
	// Custom options
1735 1801
	openvpn_add_custom($settings, $conf);
1802

  
1736 1803
	/* Loop through servers, find which ones can use this CSC */
1737 1804
	foreach (config_get_path('openvpn/openvpn-server', []) as $serversettings) {
1738 1805
		if (isset($serversettings['disable'])) {
......
1742 1809
			if ($serversettings['vpnid'] && (empty($csc_server_list) || in_array($serversettings['vpnid'], $csc_server_list))) {
1743 1810
				$csc_path = "{$g['openvpn_base']}/server{$serversettings['vpnid']}/csc/" . basename($settings['common_name']);
1744 1811
				$csc_conf = $conf;
1812

  
1813
				/* Topology is depends on the server configuration.
1814
				 * TAP mode always uses a subnet topology */
1815
				$topology = ($serversettings['dev_mode'] == 'tap') ? 'subnet' : $serversettings['topology'];
1816
				if ($auto_config_topology) {
1817
					$csc_conf .= "push \"topology {$topology}\"\n";
1818
				}
1819

  
1820
				/* The gateway is the first usable address in the tunnel network.
1821
				 * If the tunnel network is not set, the gateway must be manually
1822
				 * defined. This can happen when using a net30 topology and
1823
				 * resetting options. */
1824
				if ($auto_config_gateway6) {
1825
					// IPv6 always uses a subnet topology
1826
					$tunnel_network = null;
1827
					if (!empty($settings['tunnel_networkv6'])) {
1828
						$tunnel_network = $settings['tunnel_networkv6'];
1829
					} elseif (!empty($serversettings['tunnel_networkv6'])) {
1830
						$tunnel_network = $serversettings['tunnel_networkv6'];
1831
					}
1832
					if (!empty($tunnel_network)) {
1833
						$tunnel_network_parts = openvpn_gen_tunnel_network($tunnel_network);
1834
						$gateway = ip6_after(gen_subnetv6($tunnel_network_parts[0], $tunnel_network_parts[1]));
1835
						$csc_conf .= "push \"route-ipv6-gateway {$gateway}\"\n";
1836
					}
1837
				}
1838
				if ($auto_config_gateway4) {
1839
					$tunnel_network = null;
1840
					if ($topology == "subnet") {
1841
						// The client tunnel network is assumed to be the same as the server's
1842
						$tunnel_network = $serversettings['tunnel_network'];
1843
					} elseif (!empty($settings['tunnel_network'])) {
1844
						$tunnel_network = $settings['tunnel_network'];
1845
					}
1846
					if (!empty($tunnel_network)) {
1847
						$tunnel_network_parts = openvpn_gen_tunnel_network($tunnel_network);
1848
						$gateway = ip_after(gen_subnetv4($tunnel_network_parts[0], $tunnel_network_parts[1]), 1);
1849
						$csc_conf .= "push \"route-gateway {$gateway}\"\n";
1850
					}
1851
				}
1745 1852

  
1746 1853
				if (!empty($serversettings['tunnel_network']) && !empty($settings['tunnel_network'])) {
1747 1854
					list($ip, $mask) = openvpn_gen_tunnel_network($settings['tunnel_network']);
1748
-- a/src/usr/local/www/vpn_openvpn_csc.php
1855
++ b/src/usr/local/www/vpn_openvpn_csc.php
......
34 34
require_once("pfsense-utils.inc");
35 35
require_once("pkg-utils.inc");
36 36

  
37
global $openvpn_tls_server_modes;
37
global $openvpn_tls_server_modes, $openvpn_ping_action;
38 38

  
39 39
init_config_arr(array('openvpn', 'openvpn-csc'));
40 40
$a_csc = &$config['openvpn']['openvpn-csc'];
......
78 78

  
79 79
if (($act == "edit") || ($act == "dup")) {
80 80
	if (isset($id) && $a_csc[$id]) {
81
		$pconfig['keep_minimal'] = $a_csc[$id]['keep_minimal'];
82
		// Handle the "Reset Options" list
83
		if (!empty($a_csc[$id]['remove_options'])) {
84
			$pconfig['override_options'] = 'remove_specified';
85
			$pconfig['remove_options'] = explode(',', $a_csc[$id]['remove_options']);
86
		} elseif (isset($a_csc[$id]['push_reset'])) {
87
			$pconfig['override_options'] = 'push_reset';
88
		}
89

  
81 90
		$pconfig['server_list'] = explode(",", $a_csc[$id]['server_list']);
82 91
		$pconfig['custom_options'] = $a_csc[$id]['custom_options'];
83 92
		$pconfig['disable'] = isset($a_csc[$id]['disable']);
......
89 98
		$pconfig['tunnel_networkv6'] = $a_csc[$id]['tunnel_networkv6'];
90 99
		$pconfig['local_network'] = $a_csc[$id]['local_network'];
91 100
		$pconfig['local_networkv6'] = $a_csc[$id]['local_networkv6'];
101
		$pconfig['gateway'] = $a_csc[$id]['gateway'];
102
		$pconfig['gateway6'] = $a_csc[$id]['gateway6'];
92 103
		$pconfig['remote_network'] = $a_csc[$id]['remote_network'];
93 104
		$pconfig['remote_networkv6'] = $a_csc[$id]['remote_networkv6'];
94 105
		$pconfig['gwredir'] = $a_csc[$id]['gwredir'];
106
		$pconfig['gwredir6'] = $a_csc[$id]['gwredir6'];
95 107

  
96
		$pconfig['push_reset'] = $a_csc[$id]['push_reset'];
97
		$pconfig['remove_route'] = $a_csc[$id]['remove_route'];
108
		$pconfig['inactive_seconds'] = $a_csc[$id]['inactive_seconds'];
109
		$pconfig['ping_seconds'] = $a_csc[$id]['ping_seconds'];
110
		$pconfig['ping_action'] = $a_csc[$id]['ping_action'];
111
		$pconfig['ping_action_seconds'] = $a_csc[$id]['ping_action_seconds'];
98 112

  
99 113
		$pconfig['dns_domain'] = $a_csc[$id]['dns_domain'];
100 114
		if ($pconfig['dns_domain']) {
......
113 127
			$pconfig['dns_server_enable'] = true;
114 128
		}
115 129

  
130
		$pconfig['push_blockoutsidedns'] = $a_csc[$id]['push_blockoutsidedns'];
131
		$pconfig['push_register_dns'] = $a_csc[$id]['push_register_dns'];
132

  
116 133
		$pconfig['ntp_server1'] = $a_csc[$id]['ntp_server1'];
117 134
		$pconfig['ntp_server2'] = $a_csc[$id]['ntp_server2'];
118 135

  
......
134 151
		}
135 152

  
136 153
		$pconfig['nbdd_server1'] = $a_csc[$id]['nbdd_server1'];
137
		if ($pconfig['nbdd_server1']) {
154
		$pconfig['nbdd_server2'] = $a_csc[$id]['nbdd_server2'];
155

  
156
		if ($pconfig['nbdd_server1'] || $pconfig['nbdd_server2']) {
138 157
			$pconfig['nbdd_server_enable'] = true;
139 158
		}
140 159
	}
......
157 176
		$input_errors[] = gettext("This user does not have sufficient privileges to edit Advanced options on this instance.");
158 177
	}
159 178
	if (!$user_can_edit_advanced && !empty($a_csc[$id]['custom_options'])) {
179
		// Restore the "custom options" field
160 180
		$pconfig['custom_options'] = $a_csc[$id]['custom_options'];
161 181
	}
162 182

  
......
180 200
		$input_errors[] = gettext("The field 'IPv6 Tunnel Network' must contain a valid IPv6 prefix or an alias with a single IPv6 prefix.");
181 201
	}
182 202

  
183
	if ($result = openvpn_validate_cidr($pconfig['local_network'], 'IPv4 Local Network', true, "ipv4", true)) {
203
	if (empty($pconfig['gwredir']) && ($result = openvpn_validate_cidr($pconfig['local_network'], 'IPv4 Local Network', true, "ipv4", true))) {
184 204
		$input_errors[] = $result;
185 205
	}
186 206

  
187
	if ($result = openvpn_validate_cidr($pconfig['local_networkv6'], 'IPv6 Local Network', true, "ipv6", true)) {
207
	if (empty($pconfig['gwredir6']) && ($result = openvpn_validate_cidr($pconfig['local_networkv6'], 'IPv6 Local Network', true, "ipv6", true))) {
188 208
		$input_errors[] = $result;
189 209
	}
190 210

  
211
	if (!empty($pconfig['gateway']) && !is_ipaddrv4($pconfig['gateway'])) {
212
		$input_errors[] = gettext("The specified IPv4 gateway address is invalid.");
213
	}
214

  
215
	if (!empty($pconfig['gateway6']) && !is_ipaddrv6($pconfig['gateway6'])) {
216
		$input_errors[] = gettext("The specified IPv6 gateway address is invalid.");
217
	}
218

  
191 219
	if ($result = openvpn_validate_cidr($pconfig['remote_network'], 'IPv4 Remote Network', true, "ipv4", true)) {
192 220
		$input_errors[] = $result;
193 221
	}
......
196 224
		$input_errors[] = $result;
197 225
	}
198 226

  
227
	if (!empty($pconfig['inactive_seconds']) && !is_numericint($pconfig['inactive_seconds'])) {
228
		$input_errors[] = gettext('The supplied "Inactivity Timeout" value is invalid.');
229
	}
230

  
231
	if (!empty($pconfig['ping_seconds']) && !is_numericint($pconfig['ping_seconds'])) {
232
		$input_errors[] = gettext('The supplied "Ping Interval" value is invalid.');
233
	}
234
	if (!empty($pconfig['ping_action']) && ($pconfig['ping_action'] != 'default')) {
235
		if (!isset($openvpn_ping_action[$pconfig['ping_action']])) {
236
			$input_errors[] = gettext('The field "Ping Action" contains an invalid selection.');
237
		}
238
		if (!is_numericint($pconfig['ping_action_seconds'])) {
239
			$input_errors[] = gettext('The supplied "Ping Action" timeout value is invalid.');
240
		}
241
	}
242

  
199 243
	if ($pconfig['dns_server_enable']) {
200 244
		if (!empty($pconfig['dns_server1']) && !is_ipaddr(trim($pconfig['dns_server1']))) {
201 245
			$input_errors[] = gettext("The field 'DNS Server #1' must contain a valid IP address");
......
239 283
			if (!empty($pconfig['nbdd_server1']) && !is_ipaddr(trim($pconfig['nbdd_server1']))) {
240 284
				$input_errors[] = gettext("The field 'NetBIOS Data Distribution Server #1' must contain a valid IP address");
241 285
			}
286
			if (!empty($pconfig['nbdd_server2']) && !is_ipaddr(trim($pconfig['nbdd_server2']))) {
287
				$input_errors[] = gettext("The field 'NetBIOS Data Distribution Server #2' must contain a valid IP address");
242 288
			}
289
		}
243 290

  
244 291
		if (!empty($pconfig['netbios_ntype']) &&
245 292
		    !array_key_exists($pconfig['netbios_ntype'], $netbios_nodetypes)) {
......
255 302
	if (!$input_errors) {
256 303
		$csc = array();
257 304

  
305
		if (isset($pconfig['keep_minimal'])) {
306
			$csc['keep_minimal'] = true;
307
		}
308
		// Handle "Reset Server Options" and "Reset Options"
309
		if (($pconfig['override_options'] == 'remove_specified')) {
310
			// If no options are specified, keep the default behavior.
311
			if (!empty($pconfig['remove_options'])) {
312
				$csc['remove_options'] = implode(',', $pconfig['remove_options']);
313
			}
314
		} elseif ($pconfig['override_options'] == 'push_reset') {
315
			$csc['push_reset'] = true;
316
		}
317

  
258 318
		if (is_array($pconfig['server_list'])) {
259 319
			$csc['server_list'] = implode(",", $pconfig['server_list']);
260 320
		} else {
......
269 329
		$csc['description'] = $pconfig['description'];
270 330
		$csc['tunnel_network'] = $pconfig['tunnel_network'];
271 331
		$csc['tunnel_networkv6'] = $pconfig['tunnel_networkv6'];
332

  
333
		$csc['gateway'] = $pconfig['gateway'];
334
		$csc['gateway6'] = $pconfig['gateway6'];
335
		// Don't push routes if redirecting all traffic.
336
		if (!empty($pconfig['gwredir'])) {
337
			$csc['gwredir'] = $pconfig['gwredir'];
338
		} else {
272 339
			$csc['local_network'] = $pconfig['local_network'];
340
		}
341
		if (!empty($pconfig['gwredir6'])) {
342
			$csc['gwredir6'] = $pconfig['gwredir6'];
343
		} else {
273 344
			$csc['local_networkv6'] = $pconfig['local_networkv6'];
345
		}
346

  
274 347
		$csc['remote_network'] = $pconfig['remote_network'];
275 348
		$csc['remote_networkv6'] = $pconfig['remote_networkv6'];
276
		$csc['gwredir'] = $pconfig['gwredir'];
277
		$csc['push_reset'] = $pconfig['push_reset'];
278
		$csc['remove_route'] = $pconfig['remove_route'];
279 349

  
350
		if (is_numericint($pconfig['inactive_seconds'])) {
351
			$csc['inactive_seconds'] = $pconfig['inactive_seconds'];
352
		}
353
		if (is_numericint($pconfig['ping_seconds'])) {
354
			$csc['ping_seconds'] = $pconfig['ping_seconds'];
355
		}
356
		if (!empty($pconfig['ping_action']) && ($pconfig['ping_action'] != 'default')) {
357
			$csc['ping_action'] = $pconfig['ping_action'];
358
			$csc['ping_action_seconds'] = $pconfig['ping_action_seconds'];
359
		}
360

  
280 361
		if ($pconfig['dns_domain_enable']) {
281 362
			$csc['dns_domain'] = $pconfig['dns_domain'];
282 363
		}
......
288 369
			$csc['dns_server4'] = $pconfig['dns_server4'];
289 370
		}
290 371

  
372
		$csc['push_blockoutsidedns'] = $pconfig['push_blockoutsidedns'];
373
		$csc['push_register_dns'] = $pconfig['push_register_dns'];
374

  
291 375
		if ($pconfig['ntp_server_enable']) {
292 376
			$csc['ntp_server1'] = $pconfig['ntp_server1'];
293 377
			$csc['ntp_server2'] = $pconfig['ntp_server2'];
294 378
		}
295 379

  
296 380
		$csc['netbios_enable'] = $pconfig['netbios_enable'];
381

  
382
		if ($pconfig['netbios_enable']) {
297 383
		$csc['netbios_ntype'] = $pconfig['netbios_ntype'];
298 384
		$csc['netbios_scope'] = $pconfig['netbios_scope'];
299 385

  
300
		if ($pconfig['netbios_enable']) {
301 386
			if ($pconfig['wins_server_enable']) {
302 387
				$csc['wins_server1'] = $pconfig['wins_server1'];
303 388
				$csc['wins_server2'] = $pconfig['wins_server2'];
304 389
			}
305 390

  
306
			if ($pconfig['dns_server_enable']) {
391
			if ($pconfig['nbdd_server_enable']) {
307 392
				$csc['nbdd_server1'] = $pconfig['nbdd_server1'];
393
				$csc['nbdd_server2'] = $pconfig['nbdd_server2'];
308 394
			}
309 395
		}
310 396

  
......
407 493
		true
408 494
		))->setHelp('Select the servers that will utilize this override. When no servers are selected, the override will apply to all servers.');
409 495

  
496

  
497
	$section->addInput(new Form_Select(
498
		'override_options',
499
		'Reset Server Options',
500
		($pconfig['override_options'] ?? 'default'),
501
		[
502
			'default' => 'Keep all server options (default)',
503
			'push_reset' => 'Reset all options',
504
			'remove_specified' => 'Remove specified options'
505
		]
506
	))->setHelp('Prevent this client from receiving server-defined client settings. Other client-specific options on this page will supersede these options.');
507

  
508
	$group = new Form_Group('Remove Options');
509
	$group->addClass('remove_options');
510
	$group->add(new Form_Select(
511
		'remove_options',
512
		null,
513
		$pconfig['remove_options'],
514
		[
515
			'remove_route' => 'Local Routes and Gateways',
516
			'remove_iroute' => 'Remote Routes',
517
			'remove_redirect_gateway' => 'Redirect Gateways',
518
			'remove_inactive' => 'Inactivity Timeout',
519
			'remove_ping' => 'Client Ping',
520
			'remove_ping_action' => 'Ping Action',
521
			'remove_dnsdomain' => 'DNS Domains',
522
			'remove_dnsservers' => 'DNS Servers',
523
			'remove_ntpservers' => 'NTP Options',
524
			'remove_netbios_ntype' => 'NetBIOS Type',
525
			'remove_netbios_scope' => 'NetBIOS Scope',
526
			'remove_wins' => 'WINS Options'
527
		],
528
		true
529
	))->setHelp('A "push-remove" option will be sent to the client for the selected options, removing the respective server-defined option.');
530
	$section->add($group);
531

  
532
	$section->addInput(new Form_Checkbox(
533
		'keep_minimal',
534
		'Keep minimal options',
535
		'Automatically determine the client topology and gateway',
536
		$pconfig['keep_minimal']
537
	))->setHelp('If checked, generate the required client configuration when server options are reset or removed.');
538

  
410 539
	$form->add($section);
411 540

  
412 541
	$section = new Form_Section('Tunnel Settings');
......
431 560
			'<br />');
432 561

  
433 562
	$section->addInput(new Form_Input(
563
		'gateway',
564
		'IPv4 Gateway',
565
		'text',
566
		$pconfig['gateway']
567
	))->setHelp('This is the IPv4 Gateway to push to the client. Normally it is left blank and determined automatically.');
568

  
569
	$section->addInput(new Form_Input(
570
		'gateway6',
571
		'IPv6 Gateway',
572
		'text',
573
		$pconfig['gateway6']
574
	))->setHelp('This is the IPv6 Gateway to push to the client. Normally it is left blank and determined automatically.');
575

  
576
	$section->addInput(new Form_Checkbox(
577
		'gwredir',
578
		'Redirect IPv4 Gateway',
579
		'Force all client generated IPv4 traffic through the tunnel.',
580
		$pconfig['gwredir']
581
	));
582

  
583
	$section->addInput(new Form_Checkbox(
584
		'gwredir6',
585
		'Redirect IPv6 Gateway',
586
		'Force all client-generated IPv6 traffic through the tunnel.',
587
		$pconfig['gwredir6']
588
	));
589

  
590
	$section->addInput(new Form_Input(
434 591
		'local_network',
435 592
		'IPv4 Local Network/s',
436 593
		'text',
......
468 625
		    'NOTE: Remember to add these subnets to the IPv6 Remote Networks list on the corresponding OpenVPN server settings.',
469 626
			'<br />');
470 627

  
471
	$section->addInput(new Form_Checkbox(
472
		'gwredir',
473
		'Redirect Gateway',
474
		'Force all client generated traffic through the tunnel.',
475
		$pconfig['gwredir']
476
	));
477

  
478 628
	$form->add($section);
479 629

  
480
	$section = new Form_Section('Client Settings');
630
	$section = new Form_Section('Other Client Settings');
481 631

  
482
	$section->addInput(new Form_Checkbox(
483
		'push_reset',
484
		'Server Definitions',
485
		'Prevent this client from receiving any server-defined client settings. ',
486
		$pconfig['push_reset']
487
	));
632
	$section->addInput(new Form_Input(
633
		'inactive_seconds',
634
		'Inactivity Timeout',
635
		'number',
636
		$pconfig['inactive_seconds'],
637
		['min' => '0']
638
	))->setHelp('Set connection inactivity timeout')->setWidth(3);
488 639

  
489
	/* as "push-reset" can break subnet topology, 
490
	 * "push-remove route" removes only IPv4/IPv6 routes, see #9702 */
491
	$section->addInput(new Form_Checkbox(
492
		'remove_route',
493
		'Remove Server Routes',
494
		'Prevent this client from receiving any server-defined routes without removing any other options. ',
495
		$pconfig['remove_route']
496
	));
640
	$section->addInput(new Form_Input(
641
		'ping_seconds',
642
		'Ping Interval',
643
		'number',
644
		$pconfig['ping_seconds'],
645
		['min' => '0']
646
	))->setHelp('Set peer ping interval')->setWidth(3);
497 647

  
648
	$group = new Form_Group('Ping Action');
649
	$group->add(new Form_Select(
650
		'ping_action',
651
		null,
652
		$pconfig['ping_action'] ?? 'default',
653
		array_merge([
654
			'default' => 'Don\'t override option (default)'
655
		], $openvpn_ping_action)
656
	))->setHelp('Exit or restart OpenVPN client after server timeout')->setWidth(4);
657
	$group->add(new Form_Input(
658
		'ping_action_seconds',
659
		'timeout seconds',
660
		'number',
661
		$pconfig['ping_action_seconds'],
662
		['min' => '0']
663
	))->setWidth(2)->addClass('ping_action_seconds');
664
	$section->add($group);
665

  
498 666
	$section->addInput(new Form_Checkbox(
499 667
		'dns_domain_enable',
500 668
		'DNS Default Domain',
......
555 723

  
556 724
	$section->add($group);
557 725

  
726
	$section->addInput(new Form_Checkbox(
727
		'push_blockoutsidedns',
728
		'Block Outside DNS',
729
		'Make Windows 10 Clients Block access to DNS servers except across OpenVPN while connected, forcing clients to use only VPN DNS servers.',
730
		$pconfig['push_blockoutsidedns']
731
	))->setHelp('Requires Windows 10 and OpenVPN 2.3.9 or later. Only Windows 10 is prone to DNS leakage in this way, other clients will ignore the option as they are not affected.');
732

  
733
	$section->addInput(new Form_Checkbox(
734
		'push_register_dns',
735
		'Force DNS cache update',
736
		'Run "net stop dnscache", "net start dnscache", "ipconfig /flushdns" and "ipconfig /registerdns" on connection initiation.',
737
		$pconfig['push_register_dns']
738
	))->setHelp('This is known to kick Windows into recognizing pushed DNS servers.');
739

  
558 740
	// NTP servers
559 741
	$section->addInput(new Form_Checkbox(
560 742
		'ntp_server_enable',
......
634 816

  
635 817
	$section->add($group);
636 818

  
819
	$section->addInput(new Form_Checkbox(
820
		'nbdd_server_enable',
821
		'NBDD servers',
822
		'Provide a NetBIOS over TCP/IP Datagram Distribution Servers list to clients',
823
		$pconfig['nbdd_server_enable']
824
	));
825

  
826
	$group = new Form_Group(null);
827

  
828
	$group->add(new Form_Input(
829
		'nbdd_server1',
830
		null,
831
		'text',
832
		$pconfig['nbdd_server1']
833
	))->setHelp('Server 1');
834

  
835
	$group->add(new Form_Input(
836
		'nbdd_server2',
837
		null,
838
		'text',
839
		$pconfig['nbdd_server2']
840
	))->setHelp('Server 2');
841

  
842
	$group->addClass('nbddservers');
843

  
844
	$section->add($group);
845

  
637 846
	$custops = new Form_Textarea(
638 847
		'custom_options',
639 848
		'Advanced',
......
671 880
<script type="text/javascript">
672 881
//<![CDATA[
673 882
events.push(function() {
883
	function gwredir_change() {
884
		hideInput('local_network', ($('#gwredir').prop('checked')));
885
	}
886

  
887
	function gwredir6_change() {
888
		hideInput('local_networkv6', ($('#gwredir6').prop('checked')));
889
	}
890

  
891
	function ping_action_change() {
892
		hideClass('ping_action_seconds', ($('#ping_action').find('option:selected').val() == 'default'));
893
	}
894

  
674 895
	function dnsdomain_change() {
675 896
		if ($('#dns_domain_enable').prop('checked')) {
676 897
			hideClass('dnsdomain', false);
......
702 923
			hideInput('netbios_scope', false);
703 924
			hideCheckbox('wins_server_enable', false);
704 925
			setWins();
926
			hideCheckbox('nbdd_server_enable', false);
927
			setNbdds();
705 928
		} else {
706 929
			hideInput('netbios_ntype', true);
707 930
			hideInput('netbios_scope', true);
708 931
			hideCheckbox('wins_server_enable', true);
709 932
			hideClass('winsservers', true);
933
			hideCheckbox('nbdd_server_enable', true);
934
			hideClass('nbddservers', true);
710 935
		}
711 936
	}
712 937

  
......
714 939
		hideClass('winsservers', ! $('#wins_server_enable').prop('checked'));
715 940
	}
716 941

  
942
	function setNbdds() {
943
		hideClass('nbddservers', ! $('#nbdd_server_enable').prop('checked'));
944
	}
945

  
946
	function remove_options_change() {
947
		hideCheckbox('keep_minimal', ($('#override_options').find('option:selected').val() == 'default'));
948
		hideClass('remove_options', ($('#override_options').find('option:selected').val() != 'remove_specified'));
949
	}
950

  
717 951
	// ---------- Click checkbox handlers ---------------------------------------------------------
718 952

  
953
	 // On clicking Gateway redirect
954
	$('#gwredir').click(function () {
955
		gwredir_change();
956
	});
957

  
958
	 // On clicking Gateway redirect IPv6
959
	$('#gwredir6').click(function () {
960
		gwredir6_change();
961
	});
962

  
963
	 // On clicking Ping Action
964
	$('#ping_action').click(function () {
965
		ping_action_change();
966
	});
967

  
719 968
	 // On clicking DNS Default Domain
720 969
	$('#dns_domain_enable').click(function () {
721 970
		dnsdomain_change();
......
741 990
		setWins();
742 991
	});
743 992

  
993
	// On clicking the nbdd_server_enable checkbox
994
	$('#nbdd_server_enable').click(function () {
995
		setNbdds();
996
	});
997

  
998
	$('#override_options').on('change', function() {
999
		remove_options_change();
1000
	});
744 1001
	// ---------- On initial page load ------------------------------------------------------------
745 1002

  
1003
	remove_options_change();
1004
	gwredir_change();
1005
	gwredir6_change();
1006
	ping_action_change();
746 1007
	setNetbios();
747 1008
	dnsdomain_change();
748 1009
	dnsservers_change();
749
-- a/src/etc/inc/upgrade_config.inc
1010
++ b/src/etc/inc/upgrade_config.inc
......
7026 7026
	}
7027 7027
}
7028 7028

  
7029
/* OpenVPN Client-Specific Override options have changed.
7030
 * https://redmine.pfsense.org/issues/12522 */
7031
 function upgrade_233_to_234() {
7032
	$openvpn_csc_config = config_get_path('openvpn/openvpn-csc', []);
7033
	if (empty($openvpn_csc_config)) {
7034
		return;
7035
	}
7036
	foreach ($openvpn_csc_config as &$settings) {
7037
		if (!is_array($settings)) {
7038
			continue;
7039
		}
7040

  
7041
		// Migrate "remove_route"
7042
		if (isset($settings['remove_route'])) {
7043
			$settings['remove_options'] = 'remove_route';
7044
			unset($settings['remove_route']);
7045
		}
7046
	}
7047
	config_set_path('openvpn/openvpn-csc', $openvpn_csc_config);
7048
}
7049

  
7029 7050
/*
7030 7051
 * Special function that is called independent of current config version. It's
7031 7052
 * a workaround to have config_upgrade running on older versions after next
7032
-- a/src/etc/inc/util.inc
7053
++ b/src/etc/inc/util.inc
......
533 533
	return long2ip32(ip2long($ip) + $offset);
534 534
}
535 535

  
536
/**
537
 * Return the next IPv6 address after the given address
538
 * 
539
 * @param string $ip IPv6 address
540
 * 
541
 * @return string|false IPv6 address; false if it cannot be incremented
542
 */
543
function ip6_after(string $ip): string|false {
544
	/* Convert the IPv6 string to its in_addr representation,
545
	 * increment it by one, then convert it back to a string. */
546
	return inet_ntop(str_pad(gmp_export(
547
		str_increment((string) gmp_import(inet_pton($ip)))
548
	), 16, "\0", STR_PAD_LEFT));
549
}
550

  
536 551
/* Return true if the first IP is 'before' the second */
537 552
function ip_less_than($ip1, $ip2) {
538 553
	// Compare as unsigned long because otherwise it wouldn't work when
(10-10/14)