9acde829d0b76bfa0cdfd9c9085a4a38524cf6c0
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"
25 old_ip
="$(uci_get_state network "$ifc" ipaddr)"
26 old_broadcast
="$(uci_get_state network "$ifc" broadcast)"
27 old_subnet
="$(uci_get_state network "$ifc" netmask)"
30 [ "$ip" != "$old_ip" ] \
31 ||
[ "${broadcast:-+}" != "$old_broadcast" ] \
32 ||
[ "${subnet:-255.255.255.0}" != "$old_subnet" ] && {
33 echo "udhcpc: ifconfig $interface $ip netmask ${subnet:-255.255.255.0} broadcast ${broadcast:-+}"
34 ifconfig
$interface $ip netmask
${subnet:-255.255.255.0} broadcast
${broadcast:-+}
36 change_state network
"$ifc" ipaddr
"$ip"
37 change_state network
"$ifc" broadcast
"${broadcast:-+}"
38 change_state network
"$ifc" netmask
"${subnet:-255.255.255.0}"
44 change_state network
"$ifc" lease_gateway
"$router"
45 old_router
="$(uci_get_state network "$ifc" gateway)"
46 user_router
="$(uci_get network "$ifc" gateway)"
47 user_metric
="$(uci_get network "$ifc" metric)"
48 [ -n "$user_router" ] && router
="$user_router"
51 [ -n "$router" ] && [ "$router" != "0.0.0.0" ] && [ "$router" != "255.255.255.255" ] && [ "$router" != "$old_router" ] && {
52 echo "udhcpc: setting default routers: $router"
56 route add default gw
$i ${user_metric:+metric $user_metric} dev
$interface
57 valid_gw
="${valid_gw:+$valid_gw|}$i"
60 eval $
(route
-n |
awk '
61 /^0.0.0.0\W{9}('$valid_gw')\W/ {next}
62 /^0.0.0.0/ {print "route del -net "$1" gw "$2";"}
65 change_state network
"$ifc" gateway
"$router"
68 # CIDR STATIC ROUTES (rfc3442)
69 [ -n "$cidrroute" ] && {
70 # This defines how many CIDR Routes can be assigned so that we do not enter
71 # an endless loop on malformed data
73 while [ ${MAXCIDRROUTES} -gt "0" ]; do
76 # $NW == AAA.BBB.CCC.DDD
77 # $GW == EEE.FFF.CCC.DDD
78 # $MASK AAA.[BBB].[CCC].[DDD] EEE.FFF.GGG.HHH
80 MASK
=$
(echo $cidrroute |
awk '{ print $1 }')
81 if [ ${MASK} = "0" ] ; then
82 # $MASK EEE.FFF.GGG.HHH
85 GW
=$
(echo $cidrroute |
awk '{ print $2"."$3"."$4"."$5 }' )
86 elif [ ${MASK} -le "8" ] ; then
87 # $MASK AAA EEE.FFF.GGG.HHH
89 NW
=$
(echo $cidrroute |
awk '{ print $2 }' )
90 GW
=$
(echo $cidrroute |
awk '{ print $3"."$4"."$5"."$6 }' )
91 elif [ ${MASK} -le "16" ] ; then
92 # $MASK AAA.BBB EEE.FFF.GGG.HHH
94 NW
=$
(echo $cidrroute |
awk '{ print $2"."$3 }' )
95 GW
=$
(echo $cidrroute |
awk '{ print $4"."$5"."$6"."$7 }' )
96 elif [ ${MASK} -le "24" ] ; then
97 # $MASK AAA.BBB.CCC EEE.FFF.GGG.HHH
99 NW
=$
(echo $cidrroute |
awk '{ print $2"."$3"."$4 }' )
100 GW
=$
(echo $cidrroute |
awk '{ print $5"."$6"."$7"."$8 }' )
103 # $MASK AAA.BBB.CCC.DDD EEE.FFF.GGG.HHH
105 NW
=$
(echo $cidrroute |
awk '{ print $2"."$3"."$4"."$5 }' )
106 GW
=$
(echo $cidrroute |
awk '{ print $6"."$7"."$8"."$9 }' )
108 echo [$ROUTECOUNTER] Route Network
: $NW/$MASK Gateway
: $GW on
$interface
110 # TODO: Check for malformed data here to eliminate counter workaround
111 # Malformed data is: ... or xxx... or xxx.yyy.. or xxx.yyy.zzz.
113 [ -n "$NW" ] && [ -n "$GW" ] && {
114 route add
$NW gw
$GW dev
$interface
117 # Clear the strings incase they don't get set next time around
118 if [ ${NW} = "0" ]; then
125 # Remove the '.' so that we can delete them from the input with sed
126 TMP
=$
(echo $TMP |
sed "s/\./ /g")
128 # Remove the previous entry from cidrroute
129 cidrroute
=$
(echo $cidrroute |
sed "s/$TMP//g")
132 let ROUTECOUNTER
=$ROUTECOUNTER+1;
133 let MAXCIDRROUTES
=$MAXCIDRROUTES-1;
135 # Leave the loop if cidrroutes is empty (we've parsed everything)
136 [ ! -n "$cidrroute" ] && break
144 old_dns
=$
(uci_get_state network
"$ifc" dns
)
145 old_domain
=$
(uci_get_state network
"$ifc" dnsdomain
)
146 user_dns
=$
(uci_get
"network.$ifc.dns")
147 [ -n "$user_dns" ] && dns
="$user_dns"
149 [ -n "$dns" ] && [ "$dns" != "$old_dns" -o -n "$user_dns" ] && {
150 echo "udhcpc: setting dns servers: $dns"
153 [ -n "$domain" ] && [ "$domain" != "$old_domain" ] && {
154 echo "udhcpc: setting dns domain: $domain"
155 sed -i -e "${old_domain:+/^search $old_domain$/d; }/^search $domain$/d" "${RESOLV_CONF}"
156 echo "search $domain" >> "${RESOLV_CONF}"
157 change_state network
"$ifc" dnsdomain
"$domain"
161 [ -n "$ifc" ] ||
return
164 change_state network
"$ifc" lease_server
"$serverid"
165 change_state network
"$ifc" lease_acquired
"$(date '+%s')"
166 change_state network
"$ifc" lease_lifetime
"$lease"
167 [ -n "$ntpsrv" ] && change_state network
"$ifc" lease_ntpsrv
"$ntpsrv"
168 [ -n "$timesvr" ] && change_state network
"$ifc" lease_timesrv
"$timesvr"
169 [ -n "$hostname" ] && change_state network
"$ifc" lease_hostname
"$hostname"
170 [ -n "$timezone" ] && change_state network
"$ifc" lease_timezone
"$timezone"
174 env
-i ACTION
="$1" INTERFACE
="$ifc" DEVICE
="$ifname" PROTO
=dhcp
/sbin
/hotplug-call iface
180 for ifc
in $interfaces __default
; do
181 if [ "$ifc" = __default
]; then
183 [ -n "$applied" ] && continue
185 config_get ifname
"$ifc" ifname
186 [ "$ifname" = "$interface" ] ||
continue
188 config_get proto
"$ifc" proto
189 [ "$proto" = "dhcp" ] ||
continue
195 ifconfig
"$interface" 0.0.0.0
197 env
-i ACTION
="ifdown" INTERFACE
="$ifc" DEVICE
="$ifname" PROTO
=dhcp
/sbin
/hotplug-call iface
199 config_get device
"$ifc" device
200 config_get ifname
"$ifc" ifname
201 config_get aliases
"$ifc" aliases
202 uci_revert_state network
"$ifc"
203 [ -n "$device" ] && uci_set_state network
"$ifc" device
"$device"
204 [ -n "$ifname" ] && uci_set_state network
"$ifc" ifname
"$ifname"
205 [ -n "$aliases" ] && uci_set_state network
"$ifc" aliases
"$aliases"
209 setup_interface update
218 [ -f /etc
/udhcpc.user
] && .
/etc
/udhcpc.user
This page took 0.056801 seconds and 3 git commands to generate.