[package] base-files: remove redundant netmask handling in 10-routes
[openwrt.git] / package / base-files / files / etc / hotplug.d / iface / 10-routes
1 add_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 config_get gateway "$interface" gateway
24 }
25
26 dest="${netmask:+-net "$target" netmask "$netmask"}"
27 dest="${dest:--host "$target"}"
28
29 /sbin/route add $dest ${gateway:+gw "$gateway"} \
30 ${dev:+dev "$dev"} ${metric:+ metric "$metric"}
31 }
32
33 add_route6() {
34 local config="$1"
35
36 # is this route intended for the
37 # $INTERFACE of this hotplug event
38 config_get interface "$config" interface
39 [ "$interface" != "$INTERFACE" ] && return 0
40
41 # get the real interface name from network config
42 config_get dev "$interface" ifname
43
44 config_get target "$config" target
45 config_get gateway "$config" gateway
46 config_get metric "$config" metric
47
48 # make sure there is a gateway and a target
49 [ -n "$target" ] || {
50 echo "Missing target in route section $config"
51 return 1
52 }
53 [ -n "$gateway" ] || {
54 config_get gateway "$interface" gateway
55 }
56
57 /sbin/route -A inet6 add $target ${gateway:+gw "$gateway"} \
58 ${dev:+dev "$dev"} ${metric:+ metric "$metric"}
59 }
60
61 case "$ACTION" in
62 ifup)
63 include /lib/network
64 scan_interfaces
65 config_foreach "add_route" route
66 config_foreach "add_route6" route6
67 ;;
68 esac
This page took 0.05171 seconds and 5 git commands to generate.