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"
26 HOOK_SETTINGS
="ADDRESS MARK MODE PEER LOCAL_ADDRESS"
28 hook_check_settings
() {
30 assert isoneof MODE
${SUPPORTED_IP_TUNNEL_MODES}
32 # Generate a random mark
34 MARK
="$(( ${RANDOM} & 0xffffffff ))"
38 hook_parse_cmdline
() {
39 while [ $# -gt 0 ]; do
42 LOCAL_ADDRESS
="$(cli_get_val "${1}")"
46 MODE
="$(cli_get_val "${1}")"
48 # MODE must be on the list of supported protocols
49 if ! isoneof MODE
${SUPPORTED_IP_TUNNEL_MODES}; then
50 error
"Unsupported mode: ${mode}"
56 PEER
="$(cli_get_val "${1}")"
60 error
"Unknown option: ${1}"
67 # If PEER is set, it must be a valid IP address
68 if isset PEER
&& ! ip_is_valid
"${PEER}"; then
69 error
"Peer ${PEER} is not a valid IP address"
73 # If LOCAL_ADDRESS is set, it must be a valid IP address
74 # of the same protocol than PEER is
75 if isset LOCAL_ADDRESS
; then
76 if ! ip_is_valid
"${LOCAL_ADDRESS}"; then
77 error
"Local address ${LOCAL_ADDRESS} is not a valid IP address"
81 if ! ip_protocol_match
"${PEER}" "${LOCAL_ADDRESS}"; then
82 error
"Peer and local address are of different IP protocols"
94 local ${HOOK_SETTINGS}
95 if ! port_settings_read
"${port}" ${HOOK_SETTINGS}; then
96 log ERROR
"Could not read settings for port ${port}"
100 if ! ip_tunnel_add
"${port}" \
102 --address="${ADDRESS}" \
103 --remote-address="${PEER}" \
104 --local-address="${LOCAL_ADDRESS}" \
106 --okey="${MARK}"; then
118 if ! ip_tunnel_del
"${port}"; then
125 hook_hotplug_rename
() {
132 local ${HOOK_SETTINGS}
133 if ! port_settings_read
"${port}" ${HOOK_SETTINGS}; then
134 log ERROR
"Could not read settings for port ${port}"
138 # Get the current MAC address of the device.
139 local address
="$(device_get_address ${device})"
143 if [ "${ADDRESS}" = "${address}" ]; then