#!/bin/bash ############################################################################### # # # IPFire.org - A linux based firewall # # Copyright (C) 2010 Michael Tremer & Christian Schmidt # # # # This program is free software: you can redistribute it and/or modify # # it under the terms of the GNU 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 General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program. If not, see . # # # ############################################################################### . /usr/lib/network/header-config HOOK_SETTINGS=( "IPV6" "IPV4" ) DEFAULT_IPV6="on" DEFAULT_IPV4="on" hook_check_config_settings() { assert isbool IPV6 assert isbool IPV4 } hook_parse_cmdline() { local id="${1}" shift while [ $# -gt 0 ]; do case "${1}" in --ipv6=*) IPV6="$(cli_get_bool "${1}")" ;; --ipv4=*) IPV4="$(cli_get_bool "${1}")" ;; *) warning "Ignoring unknown option '${1}'" ;; esac shift done # Check if the user disabled ipv6 and ipv4 if ! enabled IPV6 && ! enabled IPV4; then error "You disabled IPv6 and IPv4. At least one must be enabled" return ${EXIT_ERROR} fi } hook_up() { local zone=${1} local config=${2} shift 2 if ! device_exists ${zone}; then error "Zone '${zone}' doesn't exist." exit ${EXIT_ERROR} fi zone_config_settings_read "${zone}" "${config}" # Start dhclient for IPv6 on this zone if enabled. if enabled IPV6; then dhclient_start ${zone} ipv6 fi # Start dhclient for IPv4 on this zone if enabled. if enabled IPV4; then dhclient_start ${zone} ipv4 fi exit ${EXIT_OK} } hook_down() { local zone=${1} local config=${2} shift 2 if ! device_exists ${zone}; then error "Zone '${zone}' doesn't exist." exit ${EXIT_ERROR} fi # Stop dhclient for IPv6 on this zone. dhclient_stop ${zone} ipv6 # Stop dhclient for IPv4 on this zone. dhclient_stop ${zone} ipv4 exit ${EXIT_OK} } hook_status() { local zone=${1} local config=${2} shift 2 if ! device_exists ${zone}; then error "Zone '${zone}' doesn't exist." exit ${EXIT_ERROR} fi zone_config_settings_read "${zone}" "${config}" local status if dhclient_status ${zone} ipv4 || dhclient_status ${zone} ipv6; then status="${MSG_HOOK_UP}" else status="${MSG_HOOK_DOWN}" fi cli_statusline 3 "${HOOK}" "${status}" cli_space local proto for proto in "IPv6" "IPv4"; do local _proto=${proto,,} cli_print_fmt1 3 "${proto}" if enabled "${proto^^}"; then cli_print_fmt1 4 "Status" "enabled" local address="$(db_get "${zone}/${_proto}/local-ip-address")" if isset address; then cli_print_fmt1 4 "Address" "${address}" fi local gateway="$(db_get "${zone}/${_proto}/remote-ip-address")" if isset gateway; then cli_print_fmt1 4 "Gateway" "${gateway}" fi local dns_servers="$(db_get "${zone}/${_proto}/domain-name-servers")" if isset dns_servers; then cli_print_fmt1 4 "DNS Servers" "${dns_servers}" fi else cli_print_fmt1 4 "Status" "disabled" fi cli_space done exit ${EXIT_OK} }