Ticket #2987: 10-routes

File 10-routes, 1.4 KB (added by igor.milavec@…, 10 years ago)
Line 
1add_route() {
2        local config="$1"
3
4        # is this route intended for the
5        # $INTERFACE of this hotplug event
6        config_get interface "$config" interface
7        [ "$interface" != "$INTERFACE" ] && return 0
8
9        # get the real interface name from network config
10        config_get dev "$interface" ifname
11
12        config_get target "$config" target
13        config_get netmask "$config" netmask
14        config_get gateway "$config" gateway
15        config_get metric "$config" metric
16
17        # make sure there is a gateway and a target
18        [ -n "$target" ] || {
19                echo "Missing target in route section $config"
20                return 1
21        }
22        [ "$gateway" = "auto" ] && {
23                # Get the gateway from the interface configuration
24                config_get gateway "$interface" gateway
25        }
26        [ -n "$gateway" ] || {
27                echo "Missing gateway in route section $config"
28                return 1
29        }
30
31        netmask="${netmask:-255.255.255.255}"
32        dest="${netmask:+-net "$target" netmask "$netmask"}"
33        dest="${dest:--host "$target"}"
34
35        /sbin/route add $dest gw "$gateway" ${dev:+dev "$dev"} ${metric:+ metric "$metric"}
36}
37
38case "$ACTION" in
39        ifup)
40                include /lib/network
41                scan_interfaces
42                . /var/state/network
43                config_foreach "add_route" route
44        ;;
45esac