2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2017 IPFire Network Development Team #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
22 IPSEC_CONNECTION_CONFIG_SETTINGS
="\
40 IPSEC_DEFAULT_AUTH_MODE
="PSK"
41 IPSEC_DEFAULT_DPD_ACTION
="restart"
42 IPSEC_DEFAULT_DPD_DELAY
="30"
43 IPSEC_DEFAULT_DPD_TIMEOUT
="120"
44 IPSEC_DEFAULT_ENABLED
="true"
45 IPSEC_DEFAULT_INACTIVITY_TIMEOUT
="0"
46 IPSEC_DEFAULT_MODE
="tunnel"
47 IPSEC_DEFAULT_SECURITY_POLICY
="system"
48 IPSEC_DEFAULT_START_ACTION
="on-demand"
50 IPSEC_VALID_MODES
="gre-transport tunnel vti"
51 IPSEC_VALID_AUTH_MODES
="PSK"
59 cli_ipsec_connection $@
62 error
"Unrecognized argument: ${action}"
68 cli_ipsec_connection
() {
69 if ipsec_connection_exists
${1}; then
76 authentication|down|disable|dpd|
enable|inactivity_timeout|
local|mode|peer|remote|security_policy|start_action|up
)
77 ipsec_connection_
${key} ${connection} $@
80 cli_ipsec_connection_show
"${connection}"
84 error
"Unrecognized argument: ${key}"
94 ipsec_connection_new $@
97 ipsec_connection_destroy $@
100 if [ -n "${action}" ]; then
101 error
"Unrecognized argument: '${action}'"
109 cli_ipsec_connection_show
() {
110 local connection
="${1}"
112 # Read the config settings
113 local ${IPSEC_CONNECTION_CONFIG_SETTINGS}
114 if ! ipsec_connection_read_config
"${connection}"; then
115 error
"Could not read the connection configuration"
119 cli_headline
0 "IPsec VPN Connection: ${connection}"
124 cli_print_fmt1
1 "Peer" "${PEER}"
128 cli_print_fmt1
1 "Security Policy" "${SECURITY_POLICY-${IPSEC_DEFAULT_SECURITY_POLICY}}"
131 cli_headline
2 "Authentication"
132 case "${AUTH_MODE^^}" in
134 cli_print_fmt1
2 "Mode" "Pre-Shared-Key"
137 cli_print_fmt1
2 "Pre-Shared-Key" "****"
139 cli_print_fmt1
2 "Pre-Shared-Key" "- is not set -"
149 for i
in LOCAL REMOTE
; do
152 cli_headline
2 "Local"
155 cli_headline
2 "Remote"
159 local id_var
="${i}_ID"
160 if [ -n "${!id_var}" ]; then
161 cli_print_fmt1
2 "ID" "${!id_var}"
164 local prefix_var
="${i}_PREFIX"
165 if isset
${prefix_var}; then
166 cli_headline
3 "Prefix(es)"
169 for prefix
in ${!prefix_var}; do
170 cli_print_fmt1
3 "${prefix}"
177 cli_headline
2 "Misc."
181 cli_print_fmt1
2 "Transport Mode" "GRE Transport"
184 cli_print_fmt1
2 "Transport Mode" "Tunnel"
187 cli_print_fmt1
2 "Transport Mode" "Virtual Tunnel Interface"
190 cli_print_fmt1
2 "Transport Mode" "- Unknown -"
195 if isset INACTIVITY_TIMEOUT
&& [ ${INACTIVITY_TIMEOUT} -gt 0 ]; then
196 cli_print_fmt1
2 "Inactivity Timeout" "$(format_time ${INACTIVITY_TIMEOUT})"
203 ipsec_connection_disable
() {
204 local connection
=${1}
206 if ! ipsec_connection_write_config_key
"${connection}" "ENABLED" "false"; then
207 log ERROR
"Could not write configuration settings"
211 ipsec_reload
${connection}
213 # Configure strongswan autostart
214 ipsec_strongswan_autostart
217 ipsec_connection_enable
() {
218 local connection
=${1}
220 if ! ipsec_connection_write_config_key
"${connection}" "ENABLED" "true"; then
221 log ERROR
"Could not write configuration settings"
225 ipsec_reload
"${connection}"
227 # Configure strongswan autostart
228 ipsec_strongswan_autostart
231 # This function writes all values to a via ${connection} specificated VPN IPsec configuration file
232 ipsec_connection_write_config
() {
235 local connection
="${1}"
237 if ! ipsec_connection_exists
"${connection}"; then
238 log ERROR
"No such VPN IPsec connection: ${connection}"
242 local path
="${NETWORK_IPSEC_CONNS_DIR}/${connection}/settings"
244 if ! settings_write
"${path}" ${IPSEC_CONNECTION_CONFIG_SETTINGS}; then
245 log ERROR
"Could not write configuration settings for VPN IPsec connection ${connection}"
249 ipsec_reload
${connection}
252 # This funtion writes the value for one key to a via ${connection} specificated VPN IPsec connection configuration file
253 ipsec_connection_write_config_key
() {
256 local connection
=${1}
262 if ! ipsec_connection_exists
"${connection}"; then
263 log ERROR
"No such VPN ipsec connection: ${connection}"
267 log DEBUG
"Set '${key}' to new value '${value}' in VPN ipsec connection '${connection}'"
269 local ${IPSEC_CONNECTION_CONFIG_SETTINGS}
271 # Read the config settings
272 if ! ipsec_connection_read_config
"${connection}"; then
276 # Set the key to a new value
277 assign
"${key}" "${value}"
279 if ! ipsec_connection_write_config
"${connection}"; then
286 # Reads one or more keys out of a settings file or all if no key is provided.
287 ipsec_connection_read_config
() {
290 local connection
="${1}"
293 if ! ipsec_connection_exists
"${connection}"; then
294 log ERROR
"No such VPN IPsec connection : ${connection}"
300 if [ $# -eq 0 ] && [ -n "${IPSEC_CONNECTION_CONFIG_SETTINGS}" ]; then
301 list_append args
${IPSEC_CONNECTION_CONFIG_SETTINGS}
306 local path
="${NETWORK_IPSEC_CONNS_DIR}/${connection}/settings"
308 if ! settings_read
"${path}" ${args}; then
309 log ERROR
"Could not read settings for VPN IPsec connection ${connection}"
314 # This function checks if a vpn ipsec connection exists
315 # Returns True when yes and false when not
316 ipsec_connection_exists
() {
319 local connection
=${1}
321 local path
="${NETWORK_IPSEC_CONNS_DIR}/${connection}"
323 [ -d "${path}" ] && return ${EXIT_TRUE} || return ${EXIT_FALSE}
326 # Determines if strongswan should be automatically started
327 # when the system boots up.
328 ipsec_strongswan_autostart() {
329 local autostart_needed="false
"
332 for connection in $(ipsec_list_connections); do
335 if ! ipsec_connection_read_config "${connection}" "ENABLED
"; then
336 log WARNING "Could not
read configuation
"
340 if enabled ENABLED; then
341 autostart_needed="true
"
346 # Start strongswan when we need it and when it is not yet enabled
347 if ${autostart_needed}; then
348 if ! service_is_enabled "strongswan
"; then
349 service_enable "strongswan
"
352 if ! service_is_active "strongswan
"; then
353 service_start "strongswan
"
356 # Disable strongswan when we do not need it but it is enabled
357 elif ! ${autostart_needed}; then
358 if service_is_enabled "strongswan
"; then
359 service_disable "strongswan
"
362 if service_is_active "strongswan
"; then
363 service_stop "strongswan
"
368 ipsec_strongswan_load() {
369 if ! cmd swanctl --load-all; then
370 log ERROR "Could not reload strongswan config
"
375 # Reloads the connection after config changes
377 local connection=${1}
381 if ! ipsec_connection_read_config "${connection}" "ENABLED
"; then
382 log ERROR "Could not
read configuration
for IPsec connection
${connection}"
386 if enabled ENABLED; then
387 if ! ipsec_connection_to_strongswan ${connection}; then
388 log ERROR "Could not generate strongswan config
for ${connnection}"
392 unlink "${NETWORK_IPSEC_SWANCTL_CONNECTIONS_DIR}/${connection}.conf
"
395 ipsec_strongswan_load
398 # Handle the cli after authentification
399 ipsec_connection_authentication() {
400 if [ ! $# -gt 1 ]; then
401 log ERROR "Not enough arguments
"
405 local connection=${1}
411 ipsec_connection_authentication_mode "${connection}" $@
414 ipsec_connection_authentication_psk "${connection}" $@
417 log ERROR "Unrecognized argument
: ${cmd}"
423 # Set the authentification mode
424 ipsec_connection_authentication_mode() {
425 if [ ! $# -eq 2 ]; then
426 log ERROR "Not enough arguments
"
429 local connection=${1}
432 if ! isoneof mode ${IPSEC_VALID_AUTH_MODES}; then
433 log ERROR "Auth mode
'${mode}' is invalid
"
437 if ! ipsec_connection_write_config_key "${connection}" "AUTH_MODE
" ${mode^^}; then
438 log ERROR "Could not
write configuration settings
"
444 ipsec_connection_authentication_psk() {
445 if [ ! $# -eq 2 ]; then
446 log ERROR "Not enough arguments
"
450 local connection=${1}
455 if [ ${length} -lt 4 ]; then
456 error "The PSK must be longer than four characters
"
460 if [ ${length} -gt 128 ]; then
461 error "The PSK cannot be longer than
128 characters
"
465 if ! ipsec_connection_write_config_key "${connection}" "PSK
" "${psk}"; then
466 log ERROR "Could not
write configuration settings
"
473 ipsec_connection_up() {
474 local connection="${1}"
476 if ! ipsec_connection_exists "${connection}"; then
477 error "No such VPN IPsec connection
: ${connection}"
481 cmd swanctl --initiate --child "${connection}"
484 ipsec_connection_down() {
485 local connection="${1}"
487 if ! ipsec_connection_exists "${connection}"; then
488 error "No such VPN IPsec connection
: ${connection}"
492 cmd swanctl --terminate --ike "${connection}"
495 # Handle the cli after authentification
496 ipsec_connection_dpd() {
497 if [ ! $# -gt 1 ]; then
498 log ERROR "Not enough arguments
"
502 local connection=${1}
508 ipsec_connection_dpd_action "${connection}" $@
511 ipsec_connection_dpd_delay "${connection}" $@
514 ipsec_connection_dpd_timeout "${connection}" $@
517 log ERROR "Unrecognized argument
: ${cmd}"
523 # Set the default dpd action
524 ipsec_connection_dpd_action() {
525 if [ ! $# -eq 2 ]; then
526 log ERROR "Not enough arguments
"
529 local connection=${1}
532 if ! isoneof action "restart
" "clear"; then
533 log ERROR "dpd action
'${action}' is invalid
"
537 if ! ipsec_connection_write_config_key "${connection}" "DPD_ACTION
" ${action}; then
538 log ERROR "Could not
write configuration settings
"
544 ipsec_connection_dpd_delay() {
545 if [ ! $# -ge 2 ]; then
546 log ERROR "Not enough arguments
"
550 local connection=${1}
554 if ! isinteger value; then
555 value=$(parse_time $@)
556 if [ ! $? -eq 0 ]; then
557 log ERROR "Parsing the passed
time was not sucessful please check the passed values.
"
562 if [ ${value} -lt 0 ]; then
563 log ERROR "The passed
time value must be
in the
sum greater or equal zero seconds.
"
567 if ! ipsec_connection_write_config_key "${connection}" "DPD_DELAY
" ${value}; then
568 log ERROR "Could not
write configuration settings
"
575 # Set the dpd timeout
576 ipsec_connection_dpd_timeout() {
577 if [ ! $# -ge 2 ]; then
578 log ERROR "Not enough arguments
"
582 local connection=${1}
586 if ! isinteger value; then
587 value=$(parse_time $@)
588 if [ ! $? -eq 0 ]; then
589 log ERROR "Parsing the passed
time was not sucessful please check the passed values.
"
594 if [ ${value} -le 0 ]; then
595 log ERROR "The passed
time value must be
in the
sum greater or equal zero seconds.
"
599 if ! ipsec_connection_write_config_key "${connection}" "DPD_TIMEOUT
" ${value}; then
600 log ERROR "Could not
write configuration settings
"
607 # Handle the cli after local
608 ipsec_connection_local() {
609 if [ ! $# -ge 2 ]; then
610 log ERROR "Not enough arguments
"
614 local connection=${1}
620 ipsec_connection_local_address "${connection}" $@
623 ipsec_connection_id "${connection}" "LOCAL
" $@
626 ipsec_connection_prefix "${connection}" "LOCAL
" $@
629 log ERROR "Unrecognized argument
: ${cmd}"
637 # Set the connection mode
638 ipsec_connection_mode() {
639 if [ ! $# -eq 2 ]; then
640 log ERROR "Not enough arguments
"
643 local connection=${1}
646 if ! isoneof mode ${IPSEC_VALID_MODES}; then
647 log ERROR "Mode
'${mode}' is invalid
"
651 if ! ipsec_connection_write_config_key "${connection}" "MODE
" ${mode}; then
652 log ERROR "Could not
write configuration settings
"
659 # Set the local address
660 ipsec_connection_local_address() {
661 if [ ! $# -eq 2 ]; then
662 log ERROR "Not enough arguments
"
665 local connection=${1}
666 local local_address=${2}
668 if ! ipsec_connection_check_peer ${local_address}; then
669 log ERROR "Local address
'${local_address}' is invalid
"
673 if ! ipsec_connection_write_config_key "${connection}" "LOCAL_ADDRESS
" ${local_address}; then
674 log ERROR "Could not
write configuration settings
"
681 # Set the peer to connect to
682 ipsec_connection_peer() {
683 if [ ! $# -eq 2 ]; then
684 log ERROR "Not enough arguments
"
687 local connection=${1}
690 if ! ipsec_connection_check_peer ${peer}; then
691 log ERROR "Peer
'${peer}' is invalid
"
695 if ! ipsec_connection_write_config_key "${connection}" "PEER
" ${peer}; then
696 log ERROR "Could not
write configuration settings
"
703 #Set the local or remote id
704 ipsec_connection_id() {
705 if [ ! $# -eq 3 ]; then
706 log ERROR "Not enough arguments
"
709 local connection=${1}
713 if ! ipsec_connection_check_id ${id}; then
714 log ERROR "Id
'${id}' is invalid
"
718 if ! ipsec_connection_write_config_key "${connection}" "${type}_ID" ${id}; then
719 log ERROR
"Could not write configuration settings"
726 # Set the local or remote prefix
727 ipsec_connection_prefix
() {
728 if [ ! $# -ge 3 ]; then
729 log ERROR
"Not enough arguments"
732 local connection
=${1}
736 local _prefix
="${type}_PREFIX"
738 if ! ipsec_connection_read_config
"${connection}" "${_prefix}"; then
742 # Remove duplicated entries to proceed the list safely
743 assign
"${_prefix}" "$(list_unique ${!_prefix} )"
746 local prefixes_removed
749 while [ $# -gt 0 ]; do
754 list_append prefixes_added
"${arg:1}"
757 list_append prefixes_removed
"${arg:1}"
760 list_append prefixes_set
"${arg}"
763 error
"Invalid argument: ${arg}"
770 # Check if the user is trying a mixed operation
771 if ! list_is_empty prefixes_set
&& (! list_is_empty prefixes_added ||
! list_is_empty prefixes_removed
); then
772 error
"You cannot reset the prefix list and add or remove prefixes at the same time"
776 # Set new prefix list
777 if ! list_is_empty prefixes_set
; then
778 # Check if all prefixes are valid
780 for prefix
in ${prefixes_set}; do
781 if ! ip_net_is_valid
${prefix}; then
782 error
"Unsupported prefix: ${prefix}"
787 assign
"${_prefix}" "${prefixes_set}"
789 # Perform incremental updates
793 # Perform all removals
794 for prefix
in ${prefixes_removed}; do
795 if ! list_remove
"${_prefix}" ${prefix}; then
796 warning
"${prefix} was not on the list and could not be removed"
801 for prefix
in ${prefixes_added}; do
802 if ip_net_is_valid
${prefix}; then
803 if ! list_append_unique
"${_prefix}" ${prefix}; then
804 warning
"${prefix} is already on the prefix list"
807 warning
"${prefix} is not a valid IP network and could not be added"
812 # Check if the list contain at least one valid prefix
813 if list_is_empty
${_prefix}; then
814 error
"Cannot save an empty prefix list"
819 if ! ipsec_connection_write_config_key
"${connection}" "${_prefix}" ${!_prefix}; then
820 log ERROR "Could not
write configuration settings
"
826 # Handle the cli after remote
827 ipsec_connection_remote() {
828 if [ ! $# -ge 2 ]; then
829 log ERROR "Not enough arguments
"
833 local connection=${1}
839 ipsec_connection_id "${connection}" "REMOTE
" $@
843 ipsec_connection_prefix "${connection}" "REMOTE
" $@
846 log ERROR "Unrecognized argument
: ${cmd}"
854 # Set the inactivity timeout
855 ipsec_connection_inactivity_timeout() {
856 if [ ! $# -ge 2 ]; then
857 log ERROR "Not enough arguments
"
861 local connection=${1}
865 if ! isinteger value; then
866 value=$(parse_time $@)
867 if [ ! $? -eq 0 ]; then
868 log ERROR "Parsing the passed
time was not sucessful please check the passed values.
"
873 if [ ${value} -le 0 ]; then
874 log ERROR "The passed
time value must be
in the
sum greater zero seconds.
"
878 if ! ipsec_connection_write_config_key "${connection}" "INACTIVITY_TIMEOUT
" ${value}; then
879 log ERROR "Could not
write configuration settings
"
886 # Set the default start action
887 ipsec_connection_start_action() {
888 if [ ! $# -eq 2 ]; then
889 log ERROR "Not enough arguments
"
892 local connection=${1}
895 if ! isoneof action "on-demand
" "always-on
"; then
896 log ERROR "Start action
'${action}' is invalid
"
900 if ! ipsec_connection_write_config_key "${connection}" "START_ACTION
" ${action}; then
901 log ERROR "Could not
write configuration settings
"
906 # Set the security policy to use
907 ipsec_connection_security_policy() {
908 if [ ! $# -eq 2 ]; then
909 log ERROR "Not enough arguments
"
912 local connection=${1}
913 local security_policy=${2}
915 if ! vpn_security_policy_exists ${security_policy}; then
916 log ERROR "No such vpn security policy
'${security_policy}'"
920 if ! ipsec_connection_write_config_key "${connection}" "SECURITY_POLICY
" ${security_policy}; then
921 log ERROR "Could not
write configuration settings
"
926 # Check if a id is valid
927 ipsec_connection_check_id() {
931 if [[ ${id} =~ ^@[[:alnum:]]+$ ]] || ip_is_valid ${id}; then
938 # Checks if a peer is valid
939 ipsec_connection_check_peer() {
943 # TODO Accept also FQDNs
944 if ip_is_valid ${peer}; then
951 # This function checks if a VPN IPsec connection name is valid
952 # Allowed are only A-Za-z0-9
953 ipsec_connection_check_name() {
956 local connection=${1}
958 [[ "${connection}" =~ [^[:alnum:]$] ]]
961 # Function that creates one VPN IPsec connection
962 ipsec_connection_new() {
963 if [ $# -gt 1 ]; then
964 error "Too many arguments
"
968 local connection="${1}"
969 if ! isset connection; then
970 error "Please provide a connection name
"
974 # Check for duplicates
975 if ipsec_connection_exists "${connection}"; then
976 error "The VPN IPsec connection
${connection} already exists
"
980 # Check if the name of the connection is valid
981 if ipsec_connection_check_name "${connection}"; then
982 error "'${connection}' contains illegal characters
"
986 log DEBUG "Creating VPN IPsec connection
${connection}"
988 if ! mkdir -p "${NETWORK_IPSEC_CONNS_DIR}/${connection}"; then
989 log ERROR "Could not create config directory
for ${connection}"
993 local ${IPSEC_CONNECTION_CONFIG_SETTINGS}
995 AUTH_MODE=${IPSEC_DEFAULT_AUTH_MODE}
996 DPD_ACTION=${IPSEC_DEFAULT_DPD_ACTION}
997 DPD_DELAY=${IPSEC_DEFAULT_DPD_DELAY}
998 DPD_TIMEOUT=${IPSEC_DEFAULT_DPD_TIMEOUT}
999 ENABLED=${IPSEC_DEFAULT_ENABLED}
1000 MODE=${IPSEC_DEFAULT_MODE}
1001 START_ACTION=${IPSEC_DEFAULT_START_ACTION}
1003 INACTIVITY_TIMEOUT=${IPSEC_DEFAULT_INACTIVITY_TIMEOUT}
1004 SECURITY_POLICY=${IPSEC_DEFAULT_SECURITY_POLICY}
1006 if ! ipsec_connection_write_config "${connection}"; then
1007 log ERROR "Could not
write new config
file"
1008 return ${EXIT_ERROR}
1011 # Configure strongswan autostart
1012 ipsec_strongswan_autostart
1015 # Function that deletes based on the passed parameters one ore more vpn security policies
1016 ipsec_connection_destroy() {
1018 for connection in $@; do
1019 if ! ipsec_connection_exists "${connection}"; then
1020 log ERROR "The VPN IPsec connection
${connection} does not exist.
"
1024 log DEBUG "Deleting VPN IPsec connection
${connection}"
1025 if ! rm -rf "${NETWORK_IPSEC_CONNS_DIR}/${connection}"; then
1026 log ERROR "Deleting the VPN IPsec connection
${connection} was not sucessful
"
1027 return ${EXIT_ERROR}
1031 # Configure strongswan autostart
1032 ipsec_strongswan_autostart
1035 # List all ipsec connections
1036 ipsec_list_connections() {
1038 for connection in ${NETWORK_IPSEC_CONNS_DIR}/*; do
1039 [ -d ${connection} ] || continue
1040 basename ${connection}
1044 ipsec_connection_to_strongswan() {
1045 local connection="${1}"
1047 # Read the config settings
1048 local ${IPSEC_CONNECTION_CONFIG_SETTINGS}
1049 if ! ipsec_connection_read_config "${connection}"; then
1050 error "Could not
read the connection
${connection}"
1051 return ${EXIT_ERROR}
1054 local path="${NETWORK_IPSEC_SWANCTL_CONNECTIONS_DIR}/${connection}.conf
"
1057 # Write the connection section
1058 _ipsec_connection_to_strongswan_connection "${connection}"
1060 # Write the secrets section
1061 _ipsec_connection_to_strongswan_secrets "${connection}"
1066 _ipsec_connection_to_strongswan_connection() {
1067 local connection="${1}"
1069 # Read the security policy
1070 local ${VPN_SECURITY_POLICIES_CONFIG_SETTINGS}
1071 if ! vpn_security_policies_read_config "${SECURITY_POLICY}"; then
1072 return ${EXIT_ERROR}
1077 if isset DPD_DELAY && isinteger DPD_DELAY && [ ${DPD_DELAY} -gt 0 ]; then
1081 # Write configuration header
1082 config_header "strongSwan configuration
for ${connection}"
1084 print_indent 0 "connections
{"
1085 print_indent 1 "${connection} {"
1088 print_indent 2 "# IKE Version"
1089 case "${KEY_EXCHANGE^^}" in
1091 print_indent
2 "version = 1"
1094 # Fall back to IKEv2 for any random values
1096 print_indent
2 "version = 2"
1101 # Always only keep one connection open at a time
1102 print_indent
2 "# Unique IDs"
1103 print_indent
2 "unique = replace"
1107 print_indent
2 "# Local Address"
1108 if isset LOCAL_ADDRESS
; then
1109 print_indent
2 "local_addrs = ${LOCAL_ADDRESS}"
1111 print_indent
2 "local_addrs = %any"
1116 print_indent
2 "# Remote Address"
1118 print_indent
2 "remote_addrs = ${PEER}"
1120 print_indent
2 "remote_addrs = %any"
1125 print_indent
2 "# IKE Proposals"
1126 print_indent
2 "proposals = $(vpn_security_policies_make_ike_proposal ${SECURITY_POLICY})"
1130 if enabled dpd
; then
1131 print_indent
2 "# Dead Peer Detection"
1132 print_indent
2 "dpd_delay = ${DPD_DELAY}"
1134 if isset DPD_TIMEOUT
; then
1135 print_indent
2 "dpd_timeout = ${DPD_TIMEOUT}"
1142 print_indent
2 "# Fragmentation"
1143 print_indent
2 "fragmentation = yes"
1147 print_indent
2 "local {"
1150 if isset LOCAL_ID
; then
1151 print_indent
3 "id = ${LOCAL_ID}"
1155 case "${AUTH_MODE}" in
1157 print_indent
3 "auth = psk"
1165 print_indent
2 "remote {"
1168 if isset REMOTE_ID
; then
1169 print_indent
3 "id = ${REMOTE_ID}"
1173 case "${AUTH_MODE}" in
1175 print_indent
3 "auth = psk"
1184 print_indent
2 "children {"
1185 print_indent
3 "${connection} {"
1187 print_indent
4 "# ESP Proposals"
1188 print_indent
4 "esp_proposals = $(vpn_security_policies_make_esp_proposal ${SECURITY_POLICY})"
1195 print_indent
4 "local_ts = dynamic[gre]"
1196 print_indent
4 "remote_ts = dynamic[gre]"
1200 if isset LOCAL_PREFIX
; then
1201 print_indent
4 "local_ts = $(list_join LOCAL_PREFIX ,)"
1203 print_indent
4 "local_ts = dynamic"
1207 if isset REMOTE_PREFIX
; then
1208 print_indent
4 "remote_ts = $(list_join REMOTE_PREFIX ,)"
1210 print_indent
4 "remote_ts = dynamic"
1217 print_indent
4 "# Netfilter Marks"
1218 print_indent
4 "mark_in = %unique"
1219 print_indent
4 "mark_out = %unique"
1222 # Dead Peer Detection
1223 if enabled dpd
; then
1224 print_indent
4 "# Dead Peer Detection"
1225 print_indent
4 "dpd_action = ${DPD_ACTION}"
1230 if isset LIFETIME
; then
1231 print_indent
4 "# Rekey Time"
1232 print_indent
4 "rekey_time = ${LIFETIME}"
1237 print_indent
4 "updown = ${NETWORK_HELPERS_DIR}/ipsec-updown"
1241 print_indent
4 "# Mode"
1244 print_indent
4 "mode = transport"
1247 print_indent
4 "mode = tunnel"
1253 print_indent
4 "# Compression"
1254 if enabled COMPRESSION
; then
1255 print_indent
4 "ipcomp = yes"
1257 print_indent
4 "ipcomp = no"
1261 # Inactivity Timeout
1262 if isset INACTIVITY_TIMEOUT
; then
1263 print_indent
4 "# Inactivity Timeout"
1264 print_indent
4 "inactivity = ${INACTIVITY_TIMEOUT}"
1269 print_indent
4 "# Start Action"
1270 case "${START_ACTION}" in
1272 print_indent
4 "start_action = trap"
1273 print_indent
4 "close_action = trap"
1276 print_indent
4 "start_action = none"
1277 print_indent
4 "close_action = none"
1280 print_indent
4 "start_action = start"
1281 print_indent
4 "close_action = start"
1295 _ipsec_connection_to_strongswan_secrets
() {
1296 local connection
="${1}"
1298 print_indent
0 "secrets {"
1300 case "${AUTH_MODE}" in
1302 print_indent
1 "ike {"
1305 print_indent
2 "secret = ${PSK}"
1308 if isset REMOTE_ID
; then
1309 print_indent
2 "id = ${REMOTE_ID}"