source: trunk/package/base-files/files/etc/hotplug.d/iface/10-routes @ 9337

Last change on this file since 9337 was 9337, checked in by florian, 9 years ago

Add route6 option to setup IPv6 routes (#2528)

  • Property svn:eol-style set to native
File size: 1.7 KB
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        [ -n "$gateway" ] || {
23                echo "Missing gateway in route section $config"
24                return 1
25        }
26
27        netmask="${netmask:-255.255.255.255}"
28        dest="${netmask:+-net "$target" netmask "$netmask"}"
29        dest="${dest:--host "$target"}"
30       
31        /sbin/route add $dest gw "$gateway" ${dev:+dev "$dev"} ${metric:+ metric "$metric"}
32}
33
34add_route6() {
35        local config="$1"
36
37        # is this route intended for the
38        # $INTERFACE of this hotplug event
39        config_get interface "$config" interface
40        [ "$interface" != "$INTERFACE" ] && return 0
41       
42        # get the real interface name from network config
43        config_get dev "$interface" ifname
44
45        config_get target "$config" target
46        config_get gateway "$config" gateway
47        config_get metric "$config" metric
48
49        # make sure there is a gateway and a target
50        [ -n "$target" ] || {
51                echo "Missing target in route section $config"
52                return 1
53        }
54        [ -n "$gateway" ] || {
55                echo "Missing gateway in route section $config"
56                return 1
57        }
58
59        /sbin/route -A inet6 add $target gw "$gateway" ${dev:+dev "$dev"} ${metric:+ metric "$metric"}
60}
61
62case "$ACTION" in
63        ifup)
64                include /lib/network
65                scan_interfaces
66                . /var/state/network
67                config_foreach "add_route" route
68                config_foreach "add_route6" route6
69        ;;
70esac
Note: See TracBrowser for help on using the repository browser.