2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2018 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 .
/usr
/lib
/network
/header-port
24 SUPPORTED_IP_TUNNEL_MODES
="gretap"
34 hook_check_settings
() {
36 assert isoneof MODE
${SUPPORTED_IP_TUNNEL_MODES}
39 assert mac_is_valid
"${ADDRESS}"
41 # Generate a random mark
43 MARK
="$(( ${RANDOM} & 0xffffffff ))"
47 hook_parse_cmdline
() {
48 while [ $# -gt 0 ]; do
51 ADDRESS
="$(cli_get_val "${1}")"
53 if ! isset ADDRESS ||
! mac_is_valid
"${ADDRESS}"; then
54 error
"Invalid MAC address: ${ADDRESS}"
60 LOCAL_ADDRESS
="$(cli_get_val "${1}")"
64 MODE
="$(cli_get_val "${1}")"
66 # MODE must be on the list of supported protocols
67 if ! isoneof MODE
${SUPPORTED_IP_TUNNEL_MODES}; then
68 error
"Unsupported mode: ${mode}"
74 PEER
="$(cli_get_val "${1}")"
78 error
"Unknown option: ${1}"
85 # Generate a random MAC address if none is set
86 if ! isset ADDRESS
; then
87 ADDRESS
="$(mac_generate)"
90 # If PEER is set, it must be a valid IP address
91 if isset PEER
&& ! ip_is_valid
"${PEER}"; then
92 error
"Peer ${PEER} is not a valid IP address"
96 # If LOCAL_ADDRESS is set, it must be a valid IP address
97 # of the same protocol than PEER is
98 if isset LOCAL_ADDRESS
; then
99 if ! ip_is_valid
"${LOCAL_ADDRESS}"; then
100 error
"Local address ${LOCAL_ADDRESS} is not a valid IP address"
104 if ! ip_protocol_match
"${PEER}" "${LOCAL_ADDRESS}"; then
105 error
"Peer and local address are of different IP protocols"
117 local ${HOOK_SETTINGS[*]}
118 if ! port_settings_read
"${port}" ${HOOK_SETTINGS[*]}; then
119 log ERROR
"Could not read settings for port ${port}"
123 if ! ip_tunnel_add
"${port}" \
125 --address="${ADDRESS}" \
126 --remote-address="${PEER}" \
127 --local-address="${LOCAL_ADDRESS}" \
129 --okey="${MARK}"; then
141 if ! ip_tunnel_del
"${port}"; then
148 hook_hotplug_rename
() {
155 local ${HOOK_SETTINGS[*]}
156 if ! port_settings_read
"${port}" ${HOOK_SETTINGS[*]}; then
157 log ERROR
"Could not read settings for port ${port}"
161 # Get the current MAC address of the device.
162 local address
="$(device_get_address ${device})"
166 if [ "${ADDRESS}" = "${address}" ]; then