# #
###############################################################################
-function routing_has_default() {
+routing_has_default() {
ip route | grep -q "^default"
}
-function routing_default_update() {
+routing_default_update() {
local routes
local zones=$(zones_get_nonlocal)
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
# Remove too much spaces.
routes=$(echo ${routes})
- # Remove all default routes.
- while ${cmd} | grep -q "^default"; do
- ${cmd} del default
- done
+ # Reload bird configuration
+ [[ "${proto}" = "ipv6" ]] && bird_update
+ # Remove all default routes.
if [ -z "${routes}" ]; then
+ cmd ${cmd} del default
log INFO "Removed default route for ${proto}."
return ${EXIT_OK}
fi
log INFO "Setting default route for ${proto}: ${routes}"
- cmd ${cmd} add default ${routes}
+ cmd ${cmd} replace default ${routes}
assert [ $? -eq 0 ]
- case "${proto}" in
- ipv6)
- # Apply radvd configuration.
- radvd_update
- ;;
- esac
+ triggers_execute_all "online"
done
}
-# XXX deprecated function
-function routing_table_exists() {
- route_table_exists $@
-}
-
-# XXX deprecated function
-function routing_table_create() {
- route_table_create $@
-}
-
-function 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}"
-}
-
-function routing_db_exists() {
- [ -d "$(routing_db_path $@)" ]
-}
-
-function routing_db_create() {
- routing_db_exists $@ && return ${EXIT_OK}
-
- mkdir -p $(routing_db_path $@)
-}
-
-function routing_db_remove() {
- rm -rf $(routing_db_path $@)
-}
-
-function 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}
-}
-
-function routing_db_get() {
- local zone=${1}
- local proto=${2}
- local parameter=${3}
- shift 3
-
- cat $(routing_db_path ${zone} ${proto})/${parameter} 2>/dev/null
-}
-
-function routing_db_from_ppp() {
+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}/remote-address" "${PPP_MACREMOTE,,}"
+ fi
}
-function routing_update() {
+routing_update() {
local zone=${1}
assert isset zone
fi
# Create routing table if not exists
- routing_table_create ${table}
+ route_table_create ${table}
log DEBUG "Flushing routing table ${table}"
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)
- local net_address=$(ipv4_get_netaddress ${local_ip_address})
+ local network=$(ipv4_get_network "${local_ip_address}")
log DEBUG "Adding route for subnet ${local_ip_address} to table ${table}"
- cmd ${ip_cmd} route add table ${table} ${net_address} dev ${zone}
+ cmd ${ip_cmd} route add table "${table}" "${network}" dev "${zone}"
;;
esac