COLOUR_UP=${COLOUR_GREEN}
COLOUR_WARN=${COLOUR_YELLOW}
+COLOUR_ENABLED=${COLOUR_GREEN}
+COLOUR_DISABLED=${COLOUR_RED}
+
COLOUR_STP_FORWARDING=${COLOUR_GREEN}
COLOUR_STP_DISCARDING=${COLOUR_RED}
COLOUR_STP_LEARNING=${COLOUR_YELLOW}
local config=${1}
assert isset config
+ assert [ -e "${config}" ]
(
. ${config}
local hook_config=${2}
shift 2
+ assert isset hook_zone
+ assert isset hook_config
+
if ! hook_zone_exists ${hook_zone}; then
error "Hook '${hook_zone}' does not exist."
return ${EXIT_ERROR}
return ${EXIT_ERROR}
fi
+ # If the zone hook has got no ports we exit silently
+ if ! hook_zone_has_ports ${hook}; then
+ return ${EXIT_OK}
+ fi
+
local h
for h in $(hook_dir zone)/${hook}.ports/*; do
h=$(basename ${h})
- ## XXX executeable?
- echo "${h}"
+ if hook_zone_port_exists ${hook} ${h}; then
+ echo "${h}"
+ fi
+ done
+}
+
+function hook_zone_configs_get_all() {
+ local hook=${1}
+
+ if ! hook_exists zone ${hook}; then
+ error "Hook '${hook}' does not exist."
+ return ${EXIT_ERROR}
+ fi
+
+ # If the zone hook has got no configurations we exit silently
+ if ! hook_zone_has_configs ${hook}; then
+ return ${EXIT_OK}
+ fi
+
+ local h
+ for h in $(hook_dir zone)/${hook}.configs/*; do
+ h=$(basename ${h})
+ if hook_zone_config_exists ${hook} ${h}; then
+ echo "${h}"
+ fi
done
+
+ return ${EXIT_OK}
}
mkdir -p $(zone_dir ${zone})
- # Create directory for ports
- mkdir -p $(zone_dir ${zone})/ports
+ # Create directories for configs and ports
+ mkdir -p $(zone_dir ${zone})/{configs,ports}
hook_zone_exec ${hook} create ${zone} $@
local ret=$?
done
}
+# XXX overwritten some lines below
function zone_config() {
local zone=${1}
shift
hook_zone_exec ${hook} config ${zone} $@
}
+function zone_config() {
+ local zone=${1}
+ local action=${2}
+ shift 2
+
+ assert isset zone
+ assert isset action
+ assert zone_exists ${zone}
+
+ # Aliases
+ case "${action}" in
+ del|delete|remove)
+ action="rem"
+ ;;
+ esac
+
+ case "${action}" in
+ create|edit|rem)
+ zone_config_${action} ${zone} $@
+ ;;
+ *)
+ error "Unrecognized argument: ${action}"
+ cli_usage root-zone-config-subcommands
+ exit ${EXIT_ERROR}
+ ;;
+ esac
+}
+
+function zone_config_create() {
+ local zone=${1}
+ shift
+
+ assert isset zone
+
+ local hook=$(zone_get_hook ${zone})
+
+ assert isset hook
+
+ hook_zone_exec ${hook} config_create ${zone} $@
+}
+
function zone_show() {
local zone=${1}
local zone=${1}
local port
- for port in $(zone_dir ${zone})/port.*; do
+ for port in $(zone_dir ${zone})/ports/*; do
[ -e "${port}" ] || continue
echo $(basename ${port})
local zone=${1}
local config
- for config in $(zone_dir ${zone})/config.*; do
+ for config in $(zone_dir ${zone})/configs/*; do
[ -e "${config}" ] || continue
echo $(basename ${config})
local hook_config
local config
for config in $(zone_configs_list ${zone}); do
- hook_config=$(config_get_hook $(zone_dir ${zone})/${config})
+ hook_config=$(config_get_hook $(zone_dir ${zone})/configs/${config})
hook_zone_config_exec ${hook_zone} ${hook_config} ${cmd} ${zone} ${config} $@
done
zone_configs_cmd down $@
}
+function zone_configs_status() {
+ zone_configs_cmd config_status $@
+}
+
function zone_has_ipv4() {
device_has_ipv4 $@
}
! zone_is_up $@
}
-function zone_get_supported_hooks() {
+function zone_get_supported_port_hooks() {
local zone=${1}
local hook=$(zone_get_hook ${zone})
hook_zone_ports_get_all ${hook}
}
+function zone_get_supported_config_hooks() {
+ local zone=${1}
+
+ local hook=$(zone_get_hook ${zone})
+
+ hook_zone_configs_get_all ${hook}
+}
+
function zone_file() {
local zone=${1}
function run() {
case "${action}" in
- add|create|rem|up|down|status)
+ edit|create|rem|up|down|status)
_${action} $@
;;
esac
- error "Device hook '${HOOK}' didn't exit properly."
+ error "Config hook '${HOOK}' didn't exit properly."
exit ${EXIT_ERROR}
}
assert isset hook_zone
assert isset hook_port
- if ! listmatch ${hook_port} $(zone_get_supported_hooks ${zone}); then
+ if ! listmatch ${hook_port} $(zone_get_supported_port_hooks ${zone}); then
error_log "Zone '${zone}' does not support port of type '${hook_port}'."
exit ${EXIT_ERROR}
fi
}
function _config_create() {
- __configcmd create $@
+ local zone=${1}
+ local hook_config=${2}
+ shift 2
+
+ assert isset zone
+ assert isset hook_config
+ assert zone_exists ${zone}
+
+ if ! listmatch ${hook_config} $(zone_get_supported_config_hooks ${zone}); then
+ error_log "Zone '${zone}' does not support configuration of type '${hook_config}'."
+ exit ${EXIT_ERROR}
+ fi
+
+ local hook_zone=$(zone_get_hook ${zone})
+ assert isset hook_zone
+
+ hook_zone_config_exec ${hook_zone} ${hook_config} create ${zone} $@
+
+ exit $?
}
function _config_edit() {
#action=${action//-/_}
case "${action}" in
- create|discover|down|edit|info|rem|status|up|port_add|port_rem|port_up|port_down|port_status)
+ # Main functions
+ create|discover|down|edit|info|rem|status|up)
_${action} $@
;;
- port)
- if ! hook_zone_has_ports ${HOOK}; then
- error "Hook '${HOOK}' does not support ports."
- exit ${EXIT_ERROR}
- fi
-
- _port $@
+ # Port callbacks
+ port_add|port_rem|port_up|port_down|port_status)
+ _${action} $@
;;
- config)
- if ! hook_zone_has_configs ${HOOK}; then
- error "Hook '${HOOK}' does not support configurations."
- exit ${EXIT_ERROR}
- fi
-
- _config $@
+ # Configuration callbacks
+ config_create)
+ _${action} $@
;;
+ # ppp daemon callbacks
ppp-ip-pre-up|ppp-ip-up|ppp-ip-down)
_${action} $@
;;
+ *)
+ error "Unknown action: ${action}"
+ ;;
esac
error "Hook did not exit properly."
# #
###############################################################################
-. /lib/network/header-port
+. /lib/network/header-config
HOOK_SETTINGS="HOOK ADDRESS PREFIX GATEWAY"
PREFIX=$(ipv4_mask_to_cidr ${NETMASK})
fi
- config_write $(zone_dir ${zone})/config.${HOOK}.$(uuid) ${HOOK_SETTINGS}
+ # XXX maybe we can add some hashing to identify a configuration again
+ config_write $(zone_dir ${zone})/configs/${HOOK}.$(uuid) ${HOOK_SETTINGS}
exit ${EXIT_OK}
}
error "Zone '${zone}' doesn't exist."
exit ${EXIT_ERROR}
fi
-
- config_read $(zone_dir ${zone})/${config}
+
+ config_read $(zone_dir ${zone})/configs/${config}
if ! zone_has_ipv4 ${zone} ${ADDRESS}/${PREFIX}; then
ip addr add ${ADDRESS}/${PREFIX} dev ${zone}
exit ${EXIT_ERROR}
fi
- config_read $(zone_dir ${zone})/${config}
+ config_read $(zone_dir ${zone})/configs/${config}
if zone_has_ipv4 ${zone} ${ADDRESS}/${PREFIX}; then
ip addr del ${ADDRESS}/${PREFIX} dev ${zone}
exit ${EXIT_ERROR}
fi
- config_read $(zone_dir ${zone})/${config}
+ config_read $(zone_dir ${zone})/configs/${config}
printf " %10s - " "${HOOK}"
if zone_has_ipv4 ${zone} ${ADDRESS}/${PREFIX}; then
- echo -ne "${COLOUR_OK} OK ${COLOUR_NORMAL}"
+ echo -ne "${COLOUR_ENABLED}ENABLED ${COLOUR_NORMAL}"
else
- echo -ne "${COLOUR_ERROR}ERROR${COLOUR_NORMAL}"
+ echo -ne "${COLOUR_DISABLED}DISABLED${COLOUR_NORMAL}"
fi
echo " - ${ADDRESS}/${PREFIX}"