[RFC,2/2] network: add ipsec

Message ID 1501090354-17617-2-git-send-email-jonatan.schlag@ipfire.org
State New
Headers show

Message

Jonatan Schlag July 26, 2017, 5:32 p.m.
Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
---
 src/network | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)

Comments

Michael Tremer July 27, 2017, 3:46 p.m. | #1
Hi,

On Wed, 2017-07-26 at 19:32 +0200, Jonatan Schlag wrote:
> Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
> ---
>  src/network | 60
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 60 insertions(+)
> 
> diff --git a/src/network b/src/network
> index adc9ac3..893c411 100644
> --- a/src/network
> +++ b/src/network
> @@ -1403,6 +1403,9 @@ cli_vpn() {
>  		security-policies)
>  			cli_vpn_security_policies $@
>  			;;
> +		ipsec)
> +			cli_vpn_ipsec $@
> +			;;
>  		*)
>  			error "Unrecognized argument: ${action}"
>  			exit ${EXIT_ERROR}
> @@ -1410,6 +1413,63 @@ cli_vpn() {
>  	esac
>  }
>  
> +cli_vpn_ipsec() {
> +	local action=${1}
> +	shift 1
> +
> +	case "${action}" in
> +		connection)
> +			cli_vpn_ipsec_connection $@
> +			;;
> +		*)
> +			error "Unrecognized argument: ${action}"
> +			exit ${EXIT_ERROR}
> +			;;
> +	esac
> +}
> +
> +cli_vpn_ipsec_connection() {
> +	if vpn_ipsec_connection_exists ${1}; then
> +		local connection=${1}
> +		local key=${2}
> +		shift 2

You could just replace any - by _ in ${key} which makes this easier:

  key=${key//-/_}

> +
> +		case "${key}" in
> +			authentication|local|mode|peer|remote)
> +				vpn_ipsec_connection_${key}
> ${connection} $@
> +				;;
> +			inactivity-timeout)
> +				vpn_ipsec_connection_inactivity_time
> out ${connection} $@
> +				;;
> +			security-policy)
> +				vpn_ipsec_connection_security_policy
> ${connection} $@
> +				;;
> +			*)
> +				error "Unrecognized argument:
> ${key}"
> +				exit ${EXIT_ERROR}
> +				;;
> +		esac
> +	else
> +		local action=${1}
> +		shift
> +
> +		case "${action}" in
> +			new)
> +				vpn_ipsec_connection_new $@
> +				;;
> +			destroy)
> +				vpn_ipsec_connection_destroy $@
> +				;;
> +			""|*)
> +				if [ -n "${action}" ]; then
> +					error "Unrecognized
> argument: '${action}'"
> +				fi
> +				exit ${EXIT_ERROR}
> +				;;
> +		esac
> +	fi
> +}
> +
>  cli_vpn_security_policies() {
>  
>  	local action