openvpn: add support for tls-version-min
[openwrt/openwrt.git] / package / network / services / openvpn / files / openvpn.init
index 08832a086bd47197b49df104ae83dffdefa25008..6dac7b3fa12c1931083c348ca514d2c22788796b 100644 (file)
@@ -13,6 +13,9 @@ PROG=/usr/sbin/openvpn
 LIST_SEP="
 "
 
+UCI_STARTED=
+UCI_DISABLED=
+
 append_param() {
        local s="$1"
        local v="$2"
@@ -29,7 +32,7 @@ append_bools() {
        local p; local v; local s="$1"; shift
        for p in $*; do
                config_get_bool v "$s" "$p"
-               [ "$v" == 1 ] && append_param "$s" "$p" && echo >> "/var/etc/openvpn-$s.conf"
+               [ "$v" = 1 ] && append_param "$s" "$p" && echo >> "/var/etc/openvpn-$s.conf"
        done
 }
 
@@ -59,23 +62,30 @@ openvpn_add_instance() {
        procd_open_instance
        procd_set_param command "$PROG" \
                --syslog "openvpn($name)" \
+               --status "/var/run/openvpn.$name.status" \
                --cd "$dir" \
                --config "$conf"
        procd_set_param file "$dir/$conf"
+       procd_set_param respawn
        procd_close_instance
 }
 
 start_instance() {
        local s="$1"
 
-       section_enabled "$s" || return 1
-
        config_get config "$s" config
+       config="${config:+$(readlink -f "$config")}"
+
+       section_enabled "$s" || {
+               append UCI_DISABLED "$config" "$LIST_SEP"
+               return 1
+       }
 
        [ ! -d "/var/run" ] && mkdir -p "/var/run"
 
        if [ ! -z "$config" ]; then
-               openvpn_add_instance "$s" "$(dirname "$config")" "$(basename "$config")"
+               append UCI_STARTED "$config" "$LIST_SEP"
+               openvpn_add_instance "$s" "${config%/*}" "$config"
                return
        fi
 
@@ -84,7 +94,7 @@ start_instance() {
 
        # append flags
        append_bools "$s" \
-               auth_nocache auth_retry auth_user_pass_optional bind ccd_exclusive client client_cert_not_required \
+               auth_nocache auth_user_pass_optional bind ccd_exclusive client client_cert_not_required \
                client_to_client comp_noadapt disable \
                disable_occ down_pre duplicate_cn fast_io float http_proxy_retry \
                ifconfig_noexec ifconfig_nowarn ifconfig_pool_linear management_forget_disconnect management_hold \
@@ -97,7 +107,7 @@ start_instance() {
 
        # append params
        append_params "$s" \
-               cd askpass auth auth_user_pass auth_user_pass_verify bcast_buffers ca cert \
+               cd askpass auth auth_retry auth_user_pass auth_user_pass_verify bcast_buffers ca cert \
                chroot cipher client_config_dir client_connect client_disconnect comp_lzo connect_freq \
                connect_retry connect_timeout connect_retry_max crl_verify dev dev_node dev_type dh \
                echo engine explicit_exit_notify fragment group hand_window hash_size \
@@ -110,10 +120,12 @@ start_instance() {
                redirect_gateway remap_usr1 remote remote_cert_eku remote_cert_ku remote_cert_tls \
                reneg_bytes reneg_pkts reneg_sec \
                replay_persist replay_window resolv_retry route route_delay route_gateway \
-               route_metric route_up rport script_security secret server server_bridge setenv shaper sndbuf \
-               socks_proxy status status_version syslog tcp_queue_limit tls_auth \
+               route_metric route_pre_down route_up rport script_security secret server server_bridge setenv shaper sndbuf \
+               socks_proxy status status_version syslog tcp_queue_limit tls_auth tls_version_min \
                tls_cipher tls_remote tls_timeout tls_verify tmp_dir topology tran_window \
-               tun_mtu tun_mtu_extra txqueuelen user verb down push up
+               tun_mtu tun_mtu_extra txqueuelen user verb down push up \
+               verify_x509_name x509_username_field \
+               ifconfig_ipv6 route_ipv6 server_ipv6 ifconfig_ipv6_pool ifconfig_ipv6_push iroute_ipv6
 
        openvpn_add_instance "$s" "/var/etc" "openvpn-$s.conf"
 }
@@ -121,4 +133,27 @@ start_instance() {
 start_service() {
        config_load 'openvpn'
        config_foreach start_instance 'openvpn'
+
+       local path name
+       for path in /etc/openvpn/*.conf; do
+               if [ -f "$path" ]; then
+                       name="${path##*/}"; name="${name%.conf}"
+
+                       # don't start configs again that are already started by uci
+                       if echo "$UCI_STARTED" | grep -qxF "$path"; then
+                               continue
+
+                       # don't start configs which are set to disabled in uci
+                       elif echo "$UCI_DISABLED" | grep -qxF "$path"; then
+                               logger -t openvpn "$name.conf is disabled in /etc/config/openvpn"
+                               continue
+                       fi
+
+                       openvpn_add_instance "$name" "${path%/*}" "$path"
+               fi
+       done
+}
+
+service_triggers() {
+       procd_add_reload_trigger openvpn
 }