#!/bin/bash
#-----------------------------------------------------------------------------------------------------------------------------------
#
# Rx3 OpenVPN Down
#
# Copyright (C) 2025-2026 Arnaud G. GIBERT
# mailto:arnaud@rx3.net
#
# This is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; If not, see
# <https://www.gnu.org/licenses/>.
#
#-----------------------------------------------------------------------------------------------------------------------------------



#-----------------------------------------------------------------------------------------------------------------------------------
# Includes
#-----------------------------------------------------------------------------------------------------------------------------------

: "${RX3_LIB_DIR:=/usr/lib/rx3}"
. "${RX3_LIB_DIR}/network.bash"





#-----------------------------------------------------------------------------------------------------------------------------------
# Global Variables
#-----------------------------------------------------------------------------------------------------------------------------------

declare -g VERSION="1.0.0"
declare -g    NAME="openvpn-down"

declare -g   DEBUG=""
#declare -g   DEBUG="echo"
#declare -g   DEBUG=":"

declare -g     LOG=""
#declare -g     LOG=":"
#declare -g     LOG="echo"





#-----------------------------------------------------------------------------------------------------------------------------------
# Main
#-----------------------------------------------------------------------------------------------------------------------------------

local           dev="$1"
local     local_mtu="$2"
local    remote_mtu="$3"
local local_address="$4"
local local_netmask="$5"
local         phase="$6"


network_init


log_info  "VPN-Down" "[${dev}]: Local_MTU: [${local_mtu}]   Remote_MTU: [${remote_mtu}]   Local_Address: [${local_address}]   Local_Netmask: [${local_netmask}]   Phase: [${phase}]"


network_device_deinit "" "${dev}"

log_trace "VPN-Down" "[${dev}]: Done!"

network_deinit
