openvpn: Allow override of interface name
If using a configuration file for OpenVPN, allow overriding name of the interface. The reason is that then people could use configuration file provided by VPN provider directly and override the name of the interface to include it in correct firewall zone without need to alter the configuration file. Signed-off-by: Michal Hrusecky <michal@hrusecky.net> (cherry picked from commit c93667358515ec078ef4ac96393623ac084e5c9e)
This commit is contained in:
		 Michal Hrusecky
					Michal Hrusecky
				
			
				
					committed by
					
						 Jo-Philipp Wich
						Jo-Philipp Wich
					
				
			
			
				
	
			
			
			 Jo-Philipp Wich
						Jo-Philipp Wich
					
				
			
						parent
						
							8483bf3126
						
					
				
				
					commit
					cdb25bcef3
				
			| @@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk | |||||||
| PKG_NAME:=openvpn | PKG_NAME:=openvpn | ||||||
|  |  | ||||||
| PKG_VERSION:=2.4.9 | PKG_VERSION:=2.4.9 | ||||||
| PKG_RELEASE:=2 | PKG_RELEASE:=3 | ||||||
|  |  | ||||||
| PKG_SOURCE_URL:=\ | PKG_SOURCE_URL:=\ | ||||||
| 	https://build.openvpn.net/downloads/releases/ \ | 	https://build.openvpn.net/downloads/releases/ \ | ||||||
|   | |||||||
| @@ -69,6 +69,40 @@ section_enabled() { | |||||||
| 	[ $enable -gt 0 ] || [ $enabled -gt 0 ] | 	[ $enable -gt 0 ] || [ $enabled -gt 0 ] | ||||||
| } | } | ||||||
|  |  | ||||||
|  | openvpn_get_dev() { | ||||||
|  | 	local dev dev_type | ||||||
|  | 	local name="$1" | ||||||
|  | 	local conf="$2" | ||||||
|  |  | ||||||
|  | 	# Do override only for configurations with config_file | ||||||
|  | 	config_get config_file "$name" config | ||||||
|  | 	[ -n "$config_file" ] || return | ||||||
|  |  | ||||||
|  | 	# Check there is someething to override | ||||||
|  | 	config_get dev "$name" dev | ||||||
|  | 	config_get dev_type "$name" dev_type | ||||||
|  | 	[ -n "$dev" ] || return | ||||||
|  |  | ||||||
|  | 	# If there is a no dev_type, try to guess it | ||||||
|  | 	if [ -z "$dev_type" ]; then | ||||||
|  | 		. /lib/functions/openvpn.sh | ||||||
|  |  | ||||||
|  | 		local odev odev_type | ||||||
|  | 		get_openvpn_option "$conf" odev dev | ||||||
|  | 		get_openvpn_option "$conf" odev_type dev-type | ||||||
|  | 		[ -n "$odev_type" ] || odev_type="$odev" | ||||||
|  |  | ||||||
|  | 		case "$odev_type" in | ||||||
|  | 			tun*) dev_type="tun" ;; | ||||||
|  | 			tap*) dev_type="tap" ;; | ||||||
|  | 			*) return;; | ||||||
|  | 		esac | ||||||
|  | 	fi | ||||||
|  |  | ||||||
|  | 	# Return overrides | ||||||
|  | 	echo "--dev-type $dev_type --dev $dev" | ||||||
|  | } | ||||||
|  |  | ||||||
| openvpn_add_instance() { | openvpn_add_instance() { | ||||||
| 	local name="$1" | 	local name="$1" | ||||||
| 	local dir="$2" | 	local dir="$2" | ||||||
| @@ -83,7 +117,8 @@ openvpn_add_instance() { | |||||||
| 		--config "$conf" \ | 		--config "$conf" \ | ||||||
| 		--up "/usr/libexec/openvpn-hotplug up $name" \ | 		--up "/usr/libexec/openvpn-hotplug up $name" \ | ||||||
| 		--down "/usr/libexec/openvpn-hotplug down $name" \ | 		--down "/usr/libexec/openvpn-hotplug down $name" \ | ||||||
| 		--script-security "${security:-2}" | 		--script-security "${security:-2}" \ | ||||||
|  | 		$(openvpn_get_dev "$name" "$conf") | ||||||
| 	procd_set_param file "$dir/$conf" | 	procd_set_param file "$dir/$conf" | ||||||
| 	procd_set_param term_timeout 15 | 	procd_set_param term_timeout 15 | ||||||
| 	procd_set_param respawn | 	procd_set_param respawn | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user