--valid-lifetime="${new_max_life}" --preferred-lifetime="${new_preferred_life}"
# Save configuration
- routing_db_set "${interface}" "ipv6" "local-ip-address" "${new_ip6_address}/${new_ip6_prefixlen}"
- routing_db_set "${interface}" "ipv6" "active" 1
- #routing_db_set "${interface}" "ipv6" "domain-name" "${new_
+ db_set "${interface}/ipv6/local-ip-address" "${new_ip6_address}/${new_ip6_prefixlen}"
+ db_set "${interface}/ipv6/active" 1
+ #db_set "${interface}/ipv6/domain-name" "${new_
exit 0
# Handle Prefix Delegation
elif isset new_ip6_prefix; then
- routing_db_set "${interface}" "ipv6" "delegated-prefix" "${new_ip6_prefix}"
+ db_set "${interface}/ipv6/delegated-prefix" "${new_ip6_prefix}"
exit 0
fi
if isset new_ip6_address && isset new_ip6_prefixlen; then
# Update nameservers if those have changed
if [[ "${old_dhcp6_name_servers}" != "${new_dhcp6_name_servers}" ]]; then
- routing_db_set "${interface}" "ipv6" "domain-name-servers" "${new_dhcp6_name_servers}"
+ db_set "${interface}/ipv6/domain-name-servers" "${new_dhcp6_name_servers}"
dns_generate_resolvconf
fi
ipv6_address_del "${old_ip6_address}/${old_ip6_prefixlen}" "${interface}"
fi
+ # Update the database
+ db_set "${interface}/ipv6/local-ip-address" \
+ "${new_ip6_address}/${new_ip6_prefixlen}"
+
# Add the new one
ipv6_address_add "${new_ip6_address}/${new_ip6_prefixlen}" "${interface}" \
--valid-lifetime="${new_max_life}" --preferred-lifetime="${new_preferred_life}"
fi
log DEBUG "The delegated prefix has changed from ${old_ip6_prefix} to ${new_ip6_prefix}"
- routing_db_set "${interface}" "ipv6" "delegated-prefix" "${new_ip6_prefix}"
+ db_set "${interface}/ipv6/delegated-prefix" "${new_ip6_prefix}"
exit ${EXIT_OK}
fi
fi
# Save configuration
- routing_db_set ${interface} ipv4 type "ipv4-dhcp"
- routing_db_set ${interface} ipv4 local-ip-address "${new_ip_address}/${new_prefix}"
- routing_db_set ${interface} ipv4 remote-ip-address "${new_routers}"
- routing_db_set ${interface} ipv4 active 1
- routing_db_set ${interface} ipv4 domain-name "${new_domain_name}"
- routing_db_set ${interface} ipv4 domain-name-servers "${new_domain_name_servers}"
- routing_db_set ${interface} ipv4 domain-name-servers-priority "${DNS_SERVER_DYNAMIC_PRIORITY}"
+ db_set "${interface}/ipv4/type" "ipv4-dhcp"
+ db_set "${interface}/ipv4/local-ip-address" \
+ "${new_ip_address}/${new_prefix}"
+ db_set "${interface}/ipv4/remote-ip-address" "${new_routers}"
+ db_set "${interface}/ipv4/active" 1
+ db_set "${interface}/ipv4/domain-name" "${new_domain_name}"
+ db_set "${interface}/ipv4/domain-name-servers" \
+ "${new_domain_name_servers}"
+ db_set "${interface}/ipv4/domain-name-servers-priority" \
+ "${DNS_SERVER_DYNAMIC_PRIORITY}"
# Update the routing tables.
routing_update ${interface} ipv4
ipv4_flush_device ${interface}
fi
- routing_db_remove ${interface} ipv4
+ db_delete "${interface}/ipv4"
routing_default_update
exit 0
# Network directory configuration.
NETWORK_CONFIG_DIR="/etc/network"
+NETWORK_DB_DIR="${RUN_DIR}/db"
NETWORK_ZONE_DIR="${NETWORK_CONFIG_DIR}"
NETWORK_HOOKS_DIR=/usr/lib/network/hooks
# #
###############################################################################
+_db_key2path() {
+ local key="${1}"
+ assert isset key
+
+ print "${NETWORK_DB_DIR}/${key}"
+}
+
+db_exists() {
+ local key="${1}"
+
+ local path="$(_db_key2path "${key}")"
+
+ if [ -e "${path}" ]; then
+ return ${EXIT_TRUE}
+ fi
+
+ return ${EXIT_FALSE}
+}
+
+db_get() {
+ local key="${1}"
+
+ local path="$(_db_key2path "${key}")"
+ fread "${path}"
+}
+
+db_set() {
+ local key="${1}"
+ shift
+
+ local value="$@"
+ local path="$(_db_key2path "${key}")"
+
+ if [ -r "${path}" ]; then
+ log DEBUG "Setting '${key}' = '${value}'"
+ else
+ log DEBUG "Adding '${key}' = '${value}'"
+ fi
+
+ make_parent_dir "${path}"
+ print "${value}" > "${path}"
+}
+
+db_delete() {
+ local key="${1}"
+
+ local path="$(_db_key2path "${key}")"
+
+ log DEBUG "Deleting key = '${key}'"
+
+ if [ -d "${path}" ]; then
+ _db_delete_recursive "${path}"
+ fi
+
+ rm -f - "${path}"
+}
+
+_db_delete_recursive() {
+ local path="${1}"
+
+ local key
+ for key in $(_db_list_path "${path}"); do
+ db_delete "${key}"
+ done
+
+ rmdir "${path}"
+}
+
+db_dump() {
+ _db_dump_recursive "${NETWORK_DB_DIR}"
+}
+
+_db_dump_key() {
+ local key="${1}"
+ local val="$(db_get "${key}")"
+
+ printf "%-38s = %s\n" "${key}" "${val}"
+}
+
+_db_dump_recursive() {
+ local path="${1}"
+
+ local key
+ for key in $(_db_list_path "${path}"); do
+ path="$(_db_key2path "${key}")"
+
+ if [ -d "${path}" ]; then
+ _db_dump_recursive "${path}"
+ else
+ _db_dump_key "${key}"
+ fi
+ done
+}
+
+_db_list_path() {
+ local path="${1}"
+
+ local element
+ for element in ${path}/*; do
+ [ -e "${element}" ] || continue
+
+ print "${element#${NETWORK_DB_DIR}/}"
+ done
+}
+
db_connection_init() {
if [ -e "${DB_CONNECTION_FILE}" ]; then
return ${EXIT_OK}
local zone addr
for zone in $(zones_get_all); do
- addr=$(routing_db_get ${zone} ${proto} local-ip-address)
+ addr="$(db_get "${zone}/${proto}/local-ip-address")"
isset addr || continue
if ipv4_in_subnet ${addr} ${subnet}; then
for zone in $(zones_get_all); do
for proto in ${IP_SUPPORTED_PROTOCOLS}; do
- domain=$(routing_db_get ${zone} ${proto} domain-name)
+ domain="$(db_get "${zone}/${proto}/domain-name")"
isset domain || continue
list_append search_domains "${domainname}"
for zone in $(zones_get_all); do
for proto in ${IP_SUPPORTED_PROTOCOLS}; do
- priority=$(routing_db_get ${zone} ${proto} domain-name-servers-priority)
+ priority="$(db_get "${zone}/${proto}/domain-name-servers-priority")"
isset priority || priority="${DNS_SERVER_DYNAMIC_PRIORITY}"
- servers=$(routing_db_get ${zone} ${proto} domain-name-servers)
+ servers="$(db_get "${zone}/${proto}/domain-name-servers")"
for server in ${servers}; do
print "${priority} ${server}"
done
return ${EXIT_ERROR}
fi
- routing_db_set ${zone} ipv4 active 1
+ db_set "${zone}/ipv4/active" 1
+
routing_update ${zone} ipv4
routing_default_update
# Remove the information about this zone from the routing database
# and update the routing table.
- routing_db_remove ${zone} ipv4
+ db_delete "${zone}/ipv4"
+
routing_update ${zone} ipv4
routing_default_update
# Add information about this zone to the routing database.
routing_db_from_ppp ${zone} ipv6
- routing_db_set ${zone} ipv6 active 1
+ db_set "${zone}/ipv6/active" 1
+
routing_update ${zone} ipv6
routing_default_update
# Remove the information about this zone from the routing database
# and update the routing table.
- routing_db_remove ${zone} ipv6
+ db_delete "${zone}/ipv6"
+
routing_update ${zone} ipv6
routing_default_update
# If the interface does not provide any routing information,
# we can skip this whole stuff.
- if ! routing_db_exists ${zone} ipv6; then
+ if ! db_exists "${zone}/ipv6"; then
return ${EXIT_OK}
fi
# Skip if zone is not active.
- local active=$(routing_db_get ${zone} ipv6 active)
+ local active="$(db_get "${zone}/ipv6/active")"
[ "${active}" = "0" ] && return ${EXIT_OK}
# Skip if there is no prefix or prefix is link-local.
- local addr=$(routing_db_get ${zone} ipv6 local-ip-address)
+ local addr="$(db_get "${zone}/ipv6/local-ip-address")"
if [ -z "${addr}" ] || [ "${addr:0:5}" = "fe80:" ]; then
return ${EXIT_OK}
fi
for zone in ${zones}; do
# Skip if zone is not up
- routing_db_exists ${zone} ${proto} || continue
+ db_exists "${zone}/${proto}" || continue
- if [ "$(routing_db_get ${zone} ${proto} active)" = "1" ]; then
- gateway=$(routing_db_get ${zone} ${proto} remote-ip-address)
+ if [ "$(db_get "${zone}/${proto}/active")" = "1" ]; then
+ gateway="$(db_get "${zone}/${proto}/remote-ip-address")"
# Go on if the device is not there anymore.
device_exists ${zone} || continue
fi
# Apply weight.
- weight=$(routing_db_get ${zone} ${proto} weight)
+ weight="$(db_get "${zone}/${proto}/weight")"
if isinteger ${weight}; then
routes="${routes} weight ${weight}"
fi
route_table_create $@
}
-routing_db_path() {
- local zone=${1}
- local proto=${2}
-
- assert isset zone
- assert isset proto
- assert isoneof proto ${IP_SUPPORTED_PROTOCOLS}
-
- echo "${ROUTING_DB_DIR}/${zone}/${proto}"
-}
-
-routing_db_exists() {
- [ -d "$(routing_db_path $@)" ]
-}
-
-routing_db_create() {
- routing_db_exists $@ && return ${EXIT_OK}
-
- mkdir -p $(routing_db_path $@)
-}
-
-routing_db_remove() {
- rm -rf $(routing_db_path $@)
-}
-
-routing_db_set() {
- local zone=${1}
- local proto=${2}
- local parameter=${3}
- shift 3
-
- local value="$@"
-
- log INFO "Updating database (${zone} - ${proto}): ${parameter} = ${value}"
-
- routing_db_create ${zone} ${proto}
-
- echo "${value}" > $(routing_db_path ${zone} ${proto})/${parameter}
-}
-
-routing_db_get() {
- local zone=${1}
- local proto=${2}
- local parameter=${3}
- shift 3
-
- cat $(routing_db_path ${zone} ${proto})/${parameter} 2>/dev/null
-}
-
routing_db_from_ppp() {
local zone=${1}
local proto=${2}
assert isset proto
# Save ppp configuration
- routing_db_set ${zone} ${proto} type "ppp"
+ db_set "${zone}/${proto}/type" "ppp"
if [ "${proto}" = "ipv6" ]; then
- routing_db_set ${zone} ${proto} local-ip-address ${PPP_LLLOCAL}
- routing_db_set ${zone} ${proto} remote-ip-address ${PPP_LLREMOTE}
+ db_set "${zone}/${proto}/local-ip-address" "${PPP_LLLOCAL}"
+ db_set "${zone}/${proto}/remote-ip-address" "${PPP_LLREMOTE}"
elif [ "${proto}" = "ipv4" ]; then
- routing_db_set ${zone} ${proto} local-ip-address ${PPP_IPLOCAL}
- routing_db_set ${zone} ${proto} remote-ip-address ${PPP_IPREMOTE}
+ db_set "${zone}/${proto}/local-ip-address" "${PPP_IPLOCAL}"
+ db_set "${zone}/${proto}/remote-ip-address" "${PPP_IPREMOTE}"
fi
- routing_db_set ${zone} ${proto} dns ${PPP_DNS1} ${PPP_DNS2}
+ # Save the transmitted DNS servers
+ if isset PPP_DNS1 || isset PPP_DNS2; then
+ db_set "${zone}/${proto}/domain-name-servers" "${PPP_DNS1} ${PPP_DNS2}"
+ else
+ db_set "${zone}/${proto}/domain-name-servers"
+ fi
- routing_db_set ${zone} ${proto} remote-address ${PPP_MACREMOTE,,}
+ # Save the MAC address of the remote DSLAM
+ if isset PPP_MACREMOTE; then
+ db_set "${zone}/${proto}/remote-address" "${PPP_MACREMOTE,,}"
+ fi
}
routing_update() {
cmd ${ip_cmd} route flush table ${table}
# Exit here if there is no routing information.
- if ! routing_db_exists ${zone} ${proto}; then
+ if ! db_exists "${zone}/${proto}"; then
return ${EXIT_OK}
fi
- local local_ip_address=$(routing_db_get ${zone} ${proto} local-ip-address)
- local remote_ip_address=$(routing_db_get ${zone} ${proto} remote-ip-address)
+ local local_ip_address="$(db_get "${zone}/${proto}/local-ip-address")"
+ local remote_ip_address="$(db_get "${zone}/${proto}/remote-ip-address")"
case "${proto}" in
ipv4)
print "%s" "$@" >> ${file} 2>/dev/null
}
+make_parent_dir() {
+ local path="${1}"
+
+ local dirname="$(dirname "${path}")"
+ mkdir -p "${dirname}"
+}
+
enabled() {
local param=${1}
fi
cli_statusline 3 "${HOOK}" "${status}"
- cli_print_fmt1 3 "IPv4 address" "$(routing_db_get ${zone} ipv4 local-ip-address)"
- local gateway=$(routing_db_get ${zone} ipv4 remote-ip-address)
+ cli_print_fmt1 3 "IPv4 address" "$(db_get "${zone}/ipv4/local-ip-address")"
+ local gateway="$(db_get "${zone}/ipv4/remote-ip-address")"
if isset gateway; then
cli_print_fmt1 3 "Gateway" "${gateway}"
fi
ip_address_add ${zone} ${ADDRESS}/${PREFIX}
# Save configuration
- routing_db_set ${zone} ipv4 type "${HOOK}"
- routing_db_set ${zone} ipv4 local-ip-address "${ADDRESS}/${PREFIX}"
- routing_db_set ${zone} ipv4 remote-ip-address "${GATEWAY}"
- routing_db_set ${zone} ipv4 active 1
+ db_set "${zone}/ipv4/type" "${HOOK}"
+ db_set "${zone}/ipv4/local-ip-address" "${ADDRESS}/${PREFIX}"
+ db_set "${zone}/ipv4/remote-ip-address" "${GATEWAY}"
+ db_set "${zone}/ipv4/active" 1
routing_update ${zone} ipv4
routing_default_update
fi
cli_statusline 3 "${HOOK}" "${status}"
- cli_print_fmt1 3 "IPv6 address" "$(routing_db_get "${zone}" "ipv6" "local-ip-address")"
- local gateway=$(routing_db_get ${zone} ipv6 remote-ip-address)
+ cli_print_fmt1 3 "IPv6 address" "$(db_get "${zone}/ipv6/local-ip-address")"
+ local gateway="$(db_get "${zone}/ipv6/remote-ip-address")"
if isset gateway; then
cli_print_fmt1 3 "Gateway" "${gateway}"
fi
ip_address_add ${zone} ${ADDRESS}/${PREFIX}
- routing_db_set ${zone} ipv6 local-ip-address ${ADDRESS}/${PREFIX}
- routing_db_set ${zone} ipv6 remote-ip-address ${GATEWAY}
- routing_db_set ${zone} ipv6 active 1
+ db_set "${zone}/ipv6/local-ip-address" "${ADDRESS}/${PREFIX}"
+ db_set "${zone}/ipv6/remote-ip-address" "${GATEWAY}"
+ db_set "${zone}/ipv6/active" 1
+
routing_default_update
exit ${EXIT_OK}
fi
# Remove routing information from database.
- routing_db_remove ${zone} ipv6
+ db_delete "${zone}/ipv6"
zone_config_settings_read "${zone}" "${config}" ${HOOK_SETTINGS}
device_set_up "${zone}"
# Update routing information.
- routing_db_set "${zone}" ipv6 "type" "${HOOK}"
- routing_db_set "${zone}" ipv6 "local-ip-address" "::${LOCAL_ADDRESS}"
- routing_db_set "${zone}" ipv6 "remote-ip-address" "::${SERVER_ADDRESS}"
- routing_db_set "${zone}" ipv6 "active" 1
+ db_set "${zone}/ipv6/type" "${HOOK}"
+ db_set "${zone}/ipv6/local-ip-address" "::${LOCAL_ADDRESS}"
+ db_set "${zone}/ipv6/remote-ip-address" "::${SERVER_ADDRESS}"
+ db_set "${zone}/ipv6/active" 1
# Update the routing database.
routing_update ${zone} ipv6
assert isset zone
# Remove everything from the routing db.
- routing_db_remove ${zone} ipv6
+ db_delete "${zone}/ipv6"
+
routing_update ${zone} ipv6
routing_default_update
ip_address_add ${zone} ${LOCAL_ADDRESS6}
# Update routing information.
- routing_db_set ${zone} ipv6 type "${HOOK}"
- routing_db_set ${zone} ipv6 local-ip-address "${LOCAL_ADDRESS6}"
- routing_db_set ${zone} ipv6 active 1
+ db_set "${zone}/ipv6/type" "${HOOK}"
+ db_set "${zone}/ipv6/local-ip-address" "${LOCAL_ADDRESS6}"
+ db_set "${zone}/ipv6/active" 1
# Update the routing database.
routing_update ${zone} ipv6
assert isset zone
# Remove everything from the routing db.
- routing_db_remove ${zone} ipv6
+ db_delete "${zone}/ipv6"
+
routing_update ${zone} ipv6
routing_default_update
cli_headline 2 "Point-to-Point-over-Ethernet protocol"
local proto
for proto in ${IP_SUPPORTED_PROTOCOLS}; do
- routing_db_exists ${zone} ${proto} || continue
+ db_exists "${zone}/${proto}" || continue
local headline
case "${proto}" in
esac
cli_headline 3 "${headline}"
- cli_print_fmt1 3 "IP address" "$(routing_db_get ${zone} ${proto} local-ip-address)"
- cli_print_fmt1 3 "Gateway" "$(routing_db_get ${zone} ${proto} remote-ip-address)"
- cli_print_fmt1 3 "DNS servers" "$(routing_db_get ${zone} ${proto} dns)"
+ cli_print_fmt1 3 "IP address" "$(db_get "${zone}/${proto}/local-ip-address")"
+ cli_print_fmt1 3 "Gateway" "$(db_get "${zone}/${proto}/remote-ip-address")"
+ cli_print_fmt1 3 "DNS servers" "$(db_get "${zone}/${proto}/domain-name-servers")"
cli_space
done
cli_headline 2 "Point-to-Point-over-Ethernet protocol"
local proto
for proto in ${IP_SUPPORTED_PROTOCOLS}; do
- routing_db_exists ${zone} ${proto} || continue
+ db_exists "${zone}/${proto}" || continue
local headline
case "${proto}" in
esac
cli_headline 3 "${headline}"
- cli_print_fmt1 3 "IP address" "$(routing_db_get ${zone} ${proto} local-ip-address)"
- cli_print_fmt1 3 "Gateway" "$(routing_db_get ${zone} ${proto} remote-ip-address)"
- cli_print_fmt1 3 "DNS servers" "$(routing_db_get ${zone} ${proto} dns)"
+ cli_print_fmt1 3 "IP address" "$(db_get "${zone}/${proto}/local-ip-address")"
+ cli_print_fmt1 3 "Gateway" "$(db_get "${zone}/${proto}/remote-ip-address")"
+ cli_print_fmt1 3 "DNS servers" "$(db_get "${zone}/${proto}/dns")"
cli_space
- cli_print_fmt1 3 "MAC-Remote" "$(routing_db_get ${zone} ${proto} remote-address)"
+ cli_print_fmt1 3 "MAC-Remote" "$(db_get "${zone}/${proto}/remote-address")"
cli_space
done
shift
case "${cmd}" in
+ db-dump)
+ db_dump
+ ;;
list-devices)
device_list
;;