Debian Codegraph @

debian/rfc3442-classless-routes.kfreebsd

raw
1 # set classless routes based on the format specified in RFC3442
2 # e.g.:
3 # new_rfc3442_classless_static_routes='24 192 168 10 192 168 1 1 8 10 10 17 66 41'
4 # specifies the routes:
5 # 192.168.10.0/24 via 192.168.1.1
6 # 10.0.0.0/8 via 10.10.17.66.41
7
8 RUN="yes"
9
10
11 if [ "$RUN" = "yes" ]; then
12 if [ -n "$new_rfc3442_classless_static_routes" ]; then
13 if [ "$reason" = "BOUND" ] || [ "$reason" = "REBOOT" ]; then
14
15 set -- $new_rfc3442_classless_static_routes
16
17 while [ $# -gt 0 ]; do
18 net_length=$1
19 via_arg="-interface ${interface}"
20
21 case $net_length in
22 32|31|30|29|28|27|26|25)
23 if [ $# -lt 9 ]; then
24 return 1
25 fi
26 net_address="${2}.${3}.${4}.${5}"
27 gateway="${6}.${7}.${8}.${9}"
28 shift 9
29 ;;
30 24|23|22|21|20|19|18|17)
31 if [ $# -lt 8 ]; then
32 return 1
33 fi
34 net_address="${2}.${3}.${4}.0"
35 gateway="${5}.${6}.${7}.${8}"
36 shift 8
37 ;;
38 16|15|14|13|12|11|10|9)
39 if [ $# -lt 7 ]; then
40 return 1
41 fi
42 net_address="${2}.${3}.0.0"
43 gateway="${4}.${5}.${6}.${7}"
44 shift 7
45 ;;
46 8|7|6|5|4|3|2|1)
47 if [ $# -lt 6 ]; then
48 return 1
49 fi
50 net_address="${2}.0.0.0"
51 gateway="${3}.${4}.${5}.${6}"
52 shift 6
53 ;;
54 0) # default route
55 if [ $# -lt 5 ]; then
56 return 1
57 fi
58 net_address="0.0.0.0"
59 gateway="${2}.${3}.${4}.${5}"
60 shift 5
61 ;;
62 *) # error
63 return 1
64 ;;
65 esac
66
67 # take care of link-local routes
68 if [ "${gateway}" != '0.0.0.0' ]; then
69 via_arg="gw ${gateway}"
70 fi
71
72 # set route (distinguish between host & net routes)
73 if [ "$net_length" -eq 32 ]; then
74 /sbin/route add -host "${net_address}" "${via_arg}"
75 else
76 /sbin/route add -net "${net_address}/${net_length}" "${via_arg}"
77 fi
78 done
79 fi
80 fi
81 fi