92e3474bddc7878b1935e4a3cba45d62e85593da
2 [ -z "$1" ] && echo "Error: should be run by udhcpc" && exit 1
6 RESOLV_CONF
="/tmp/resolv.conf.auto"
9 [ -n "$ifc" ] ||
return
10 uci_revert_state
"$1" "$2" "$3" "$4"
11 uci_set_state
"$1" "$2" "$3" "$4"
24 old_ip
="$(uci_get_state network "$ifc" ipaddr)"
25 old_broadcast
="$(uci_get_state network "$ifc" broadcast)"
26 old_subnet
="$(uci_get_state network "$ifc" netmask)"
29 [ "$ip" != "$old_ip" ] \
30 ||
[ "${broadcast:-+}" != "$old_broadcast" ] \
31 ||
[ "${subnet:-255.255.255.0}" != "$old_subnet" ] && {
32 echo "udhcpc: ifconfig $interface $ip netmask ${subnet:-255.255.255.0} broadcast ${broadcast:-+}"
33 ifconfig
$interface $ip netmask
${subnet:-255.255.255.0} broadcast
${broadcast:-+}
35 change_state network
"$ifc" ipaddr
"$ip"
36 change_state network
"$ifc" broadcast
"${broadcast:-+}"
37 change_state network
"$ifc" netmask
"${subnet:-255.255.255.0}"
43 change_state network
"$ifc" lease_gateway
"$router"
44 config_get old_router
"$ifc" gateway
45 user_router
=$
(uci_get
"network.$ifc.gateway")
46 [ -n "$user_router" ] && router
="$user_router"
49 [ -n "$router" ] && [ "$router" != "0.0.0.0" ] && [ "$router" != "255.255.255.255" ] && [ "$router" != "$old_router" ] && {
50 echo "udhcpc: setting default routers: $router"
54 route add default gw
$i dev
$interface
55 valid_gw
="${valid_gw:+$valid_gw|}$i"
58 eval $
(route
-n |
awk '
59 /^0.0.0.0\W{9}('$valid_gw')\W/ {next}
60 /^0.0.0.0/ {print "route del -net "$1" gw "$2";"}
63 change_state network
"$ifc" gateway
"$router"
66 # CIDR STATIC ROUTES (rfc3442)
67 [ -n "$cidrroute" ] && {
68 # This defines how many CIDR Routes can be assigned so that we do not enter
69 # an endless loop on malformed data
71 while [ ${MAXCIDRROUTES} -gt "0" ]; do
74 # $NW == AAA.BBB.CCC.DDD
75 # $GW == EEE.FFF.CCC.DDD
76 # $MASK AAA.[BBB].[CCC].[DDD] EEE.FFF.GGG.HHH
78 MASK
=$
(echo $cidrroute |
awk '{ print $1 }')
79 if [ ${MASK} = "0" ] ; then
80 # $MASK EEE.FFF.GGG.HHH
83 GW
=$
(echo $cidrroute |
awk '{ print $2"."$3"."$4"."$5 }' )
84 elif [ ${MASK} -le "8" ] ; then
85 # $MASK AAA EEE.FFF.GGG.HHH
87 NW
=$
(echo $cidrroute |
awk '{ print $2 }' )
88 GW
=$
(echo $cidrroute |
awk '{ print $3"."$4"."$5"."$6 }' )
89 elif [ ${MASK} -le "16" ] ; then
90 # $MASK AAA.BBB EEE.FFF.GGG.HHH
92 NW
=$
(echo $cidrroute |
awk '{ print $2"."$3 }' )
93 GW
=$
(echo $cidrroute |
awk '{ print $4"."$5"."$6"."$7 }' )
94 elif [ ${MASK} -le "24" ] ; then
95 # $MASK AAA.BBB.CCC EEE.FFF.GGG.HHH
97 NW
=$
(echo $cidrroute |
awk '{ print $2"."$3"."$4 }' )
98 GW
=$
(echo $cidrroute |
awk '{ print $5"."$6"."$7"."$8 }' )
101 # $MASK AAA.BBB.CCC.DDD EEE.FFF.GGG.HHH
103 NW
=$
(echo $cidrroute |
awk '{ print $2"."$3"."$4"."$5 }' )
104 GW
=$
(echo $cidrroute |
awk '{ print $6"."$7"."$8"."$9 }' )
106 echo [$ROUTECOUNTER] Route Network
: $NW/$MASK Gateway
: $GW on
$interface
108 # TODO: Check for malformed data here to eliminate counter workaround
109 # Malformed data is: ... or xxx... or xxx.yyy.. or xxx.yyy.zzz.
111 [ -n "$NW" ] && [ -n "$GW" ] && {
112 route add
$NW gw
$GW dev
$interface
115 # Clear the strings incase they don't get set next time around
116 if [ ${NW} = "0" ]; then
123 # Remove the '.' so that we can delete them from the input with sed
124 TMP
=$
(echo $TMP |
sed "s/\./ /g")
126 # Remove the previous entry from cidrroute
127 cidrroute
=$
(echo $cidrroute |
sed "s/$TMP//g")
130 let ROUTECOUNTER
=$ROUTECOUNTER+1;
131 let MAXCIDRROUTES
=$MAXCIDRROUTES-1;
133 # Leave the loop if cidrroutes is empty (we've parsed everything)
134 [ ! -n "$cidrroute" ] && break
142 old_dns
=$
(uci_get_state network
"$ifc" dns
)
143 old_domain
=$
(uci_get_state network
"$ifc" dnsdomain
)
144 user_dns
=$
(uci_get
"network.$ifc.dns")
145 [ -n "$user_dns" ] && dns
="$user_dns"
147 [ -n "$dns" ] && [ "$dns" != "$old_dns" -o -n "$user_dns" ] && {
148 echo "udhcpc: setting dns servers: $dns"
151 [ -n "$domain" ] && [ "$domain" != "$old_domain" ] && {
152 echo "udhcpc: setting dns domain: $domain"
153 sed -i -e "${old_domain:+/^search $old_domain$/d; }/^search $domain$/d" "${RESOLV_CONF}"
154 echo "search $domain" >> "${RESOLV_CONF}"
155 change_state network
"$ifc" dnsdomain
"$domain"
159 [ -n "$ifc" ] ||
return
162 change_state network
"$ifc" lease_server
"$serverid"
163 change_state network
"$ifc" lease_acquired
"$(date '+%s')"
164 change_state network
"$ifc" lease_lifetime
"$lease"
165 [ -n "$ntpsrv" ] && change_state network
"$ifc" lease_ntpsrv
"$ntpsrv"
166 [ -n "$timesvr" ] && change_state network
"$ifc" lease_timesrv
"$timesvr"
167 [ -n "$hostname" ] && change_state network
"$ifc" lease_hostname
"$hostname"
168 [ -n "$timezone" ] && change_state network
"$ifc" lease_timezone
"$timezone"
172 env
-i ACTION
="$1" INTERFACE
="$ifc" DEVICE
="$ifname" PROTO
=dhcp
/sbin
/hotplug-call iface
178 for ifc
in $interfaces __default
; do
179 if [ "$ifc" = __default
]; then
181 [ -n "$applied" ] && continue
183 config_get ifname
"$ifc" ifname
184 [ "$ifname" = "$interface" ] ||
continue
186 config_get proto
"$ifc" proto
187 [ "$proto" = "dhcp" ] ||
continue
193 ifconfig
"$interface" 0.0.0.0
195 env
-i ACTION
="ifdown" INTERFACE
="$ifc" DEVICE
="$ifname" PROTO
=dhcp
/sbin
/hotplug-call iface
197 config_get device
"$ifc" device
198 config_get ifname
"$ifc" ifname
199 config_get aliases
"$ifc" aliases
200 uci_revert_state network
"$ifc"
201 [ -n "$device" ] && uci_set_state network
"$ifc" device
"$device"
202 [ -n "$ifname" ] && uci_set_state network
"$ifc" ifname
"$ifname"
203 [ -n "$aliases" ] && uci_set_state network
"$ifc" aliases
"$aliases"
207 setup_interface update
216 [ -f /etc
/udhcpc.user
] && .
/etc
/udhcpc.user
This page took 0.070616 seconds and 3 git commands to generate.