#!/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 . # # # ############################################################################### . /lib/network/header-port HOOK_SETTINGS="HOOK ADDRESS PREFIX GATEWAY" function _check() { assert isset ADDRESS assert isinteger PREFIX if [ ${PREFIX} -gt 64 ]; then error "PREFIX is greater than 64." exit ${EXIT_ERROR} fi } function _create() { local zone=${1} shift while [ $# -gt 0 ]; do case "${1}" in --address=*) ADDRESS=${1#--address=} ;; --prefix=*) PREFIX=${1#--prefix=} ;; --gateway=*) GATEWAY=${1#--gateway=} ;; esac shift done # Store IPv6 address in full format ADDRESS=$(ipv6_explode ${ADDRESS}) if [ -n "${GATEWAY}" ]; then GATEWAY=$(ipv6_explode ${GATEWAY}) fi config_write $(zone_dir ${zone})/configs/${HOOK}.$(ipv6_hash ${ADDRESS}).${PREFIX} ${HOOK_SETTINGS} exit ${EXIT_OK} } function _up() { local zone=${1} local config=${2} shift 2 if ! device_exists ${zone}; then error "Zone '${zone}' doesn't exist." exit ${EXIT_ERROR} fi config_read $(zone_dir ${zone})/configs/${config} ip_address_add ${zone} ${ADDRESS}/${PREFIX} if zone_is_nonlocal ${zone} && [ -n "${GATEWAY}" ]; then : # XXX to be done fi exit ${EXIT_OK} } function _down() { local zone=${1} local config=${2} shift 2 if ! device_exists ${zone}; then error "Zone '${zone}' doesn't exist." exit ${EXIT_ERROR} fi config_read $(zone_dir ${zone})/configs/${config} ip_address_del ${zone} ${ADDRESS}/${PREFIX} exit ${EXIT_OK} } function _status() { local zone=${1} local config=${2} shift 2 if ! device_exists ${zone}; then error "Zone '${zone}' doesn't exist." exit ${EXIT_ERROR} fi config_read $(zone_dir ${zone})/configs/${config} printf " %10s - " "${HOOK}" if zone_has_ip ${zone} ${ADDRESS}/${PREFIX}; then echo -ne "${COLOUR_UP} UP ${COLOUR_NORMAL}" else echo -ne "${COLOUR_DOWN}DOWN${COLOUR_NORMAL}" fi echo " - $(ipv6_implode ${ADDRESS})/${PREFIX}" if [ -n "${GATEWAY}" ]; then echo " Gateway: ${GATEWAY}" fi exit ${EXIT_OK} } run $@