Root/package/netifd/files/usr/share/udhcpc/default.script

1#!/bin/sh
2[ -z "$1" ] && echo "Error: should be run by udhcpc" && exit 1
3
4set_classless_routes() {
5    local max=128
6    local type
7    while [ -n "$1" -a -n "$2" -a $max -gt 0 ]; do
8        [ ${1##*/} -eq 32 ] && type=host || type=net
9        echo "udhcpc: adding route for $type $1 via $2"
10        route add -$type "$1" gw "$2" dev "$interface"
11        max=$(($max-1))
12        shift 2
13    done
14}
15
16setup_interface() {
17    echo "udhcpc: ifconfig $interface $ip netmask ${subnet:-255.255.255.0} broadcast ${broadcast:-+}"
18    ifconfig $interface $ip netmask ${subnet:-255.255.255.0} broadcast ${broadcast:-+}
19
20    [ -n "$router" ] && [ "$router" != "0.0.0.0" ] && [ "$router" != "255.255.255.255" ] && {
21        echo "udhcpc: setting default routers: $router"
22
23        local valid_gw=""
24        for i in $router ; do
25            route add default gw $i dev $interface
26            valid_gw="${valid_gw:+$valid_gw|}$i"
27        done
28        
29        eval $(route -n | awk '
30            /^0.0.0.0\W{9}('$valid_gw')\W/ {next}
31            /^0.0.0.0/ {print "route del -net "$1" gw "$2";"}
32        ')
33    }
34
35    # CIDR STATIC ROUTES (rfc3442)
36    [ -n "$staticroutes" ] && set_classless_routes $staticroutes
37    [ -n "$msstaticroutes" ] && set_classless_routes $msstaticroutes
38}
39
40
41applied=
42case "$1" in
43    deconfig)
44        ifconfig "$interface" 0.0.0.0
45    ;;
46    renew)
47        setup_interface update
48    ;;
49    bound)
50        setup_interface ifup
51    ;;
52esac
53
54# user rules
55[ -f /etc/udhcpc.user ] && . /etc/udhcpc.user
56
57exit 0
58

Archive Download this file



interactive