1b02c0c18f350f12245a343db1ac41ee4bc0e532
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"
15 [ -n "$ifc" ] ||
return
16 uci
-P /dev
/null get
"$1" 2>/dev
/null
29 config_get old_ip
"$ifc" ipaddr
30 config_get old_broadcast
"$ifc" broadcast
31 config_get old_subnet
"$ifc" netmask
34 [ "$ip" != "$old_ip" ] \
35 ||
[ "${broadcast:-+}" != "$old_broadcast" ] \
36 ||
[ "${subnet:-255.255.255.0}" != "$old_subnet" ] && {
37 echo "udhcpc: ifconfig $interface $ip netmask ${subnet:-255.255.255.0} broadcast ${broadcast:-+}"
38 ifconfig
$interface $ip netmask
${subnet:-255.255.255.0} broadcast
${broadcast:-+}
40 change_state network
"$ifc" ipaddr
"$ip"
41 change_state network
"$ifc" broadcast
"${broadcast:-+}"
42 change_state network
"$ifc" netmask
"${subnet:-255.255.255.0}"
48 change_state network
"$ifc" lease_gateway
"$router"
49 config_get old_router
"$ifc" gateway
50 user_router
=$
(uci_get
"network.$ifc.gateway")
51 [ -n "$user_router" ] && router
="$user_router"
54 [ -n "$router" ] && [ "$router" != "0.0.0.0" ] && [ "$router" != "255.255.255.255" ] && [ "$router" != "$old_router" ] && {
55 echo "udhcpc: setting default routers: $router"
59 route add default gw
$i dev
$interface
60 valid_gw
="${valid_gw:+$valid_gw|}$i"
63 eval $
(route
-n |
awk '
64 /^0.0.0.0\W{9}('$valid_gw')\W/ {next}
65 /^0.0.0.0/ {print "route del -net "$1" gw "$2";"}
68 change_state network
"$ifc" gateway
"$router"
71 # CIDR STATIC ROUTES (rfc3442)
72 [ -n "$cidrroute" ] && {
73 # This defines how many CIDR Routes can be assigned so that we do not enter
74 # an endless loop on malformed data
76 while [ ${MAXCIDRROUTES} -gt "0" ]; do
79 # $NW == AAA.BBB.CCC.DDD
80 # $GW == EEE.FFF.CCC.DDD
81 # $MASK AAA.[BBB].[CCC].[DDD] EEE.FFF.GGG.HHH
83 MASK
=$
(echo $cidrroute |
awk '{ print $1 }')
84 if [ ${MASK} = "0" ] ; then
85 # $MASK EEE.FFF.GGG.HHH
88 GW
=$
(echo $cidrroute |
awk '{ print $2"."$3"."$4"."$5 }' )
89 elif [ ${MASK} -le "8" ] ; then
90 # $MASK AAA EEE.FFF.GGG.HHH
92 NW
=$
(echo $cidrroute |
awk '{ print $2 }' )
93 GW
=$
(echo $cidrroute |
awk '{ print $3"."$4"."$5"."$6 }' )
94 elif [ ${MASK} -le "16" ] ; then
95 # $MASK AAA.BBB EEE.FFF.GGG.HHH
97 NW
=$
(echo $cidrroute |
awk '{ print $2"."$3 }' )
98 GW
=$
(echo $cidrroute |
awk '{ print $4"."$5"."$6"."$7 }' )
99 elif [ ${MASK} -le "24" ] ; then
100 # $MASK AAA.BBB.CCC EEE.FFF.GGG.HHH
102 NW
=$
(echo $cidrroute |
awk '{ print $2"."$3"."$4 }' )
103 GW
=$
(echo $cidrroute |
awk '{ print $5"."$6"."$7"."$8 }' )
106 # $MASK AAA.BBB.CCC.DDD EEE.FFF.GGG.HHH
108 NW
=$
(echo $cidrroute |
awk '{ print $2"."$3"."$4"."$5 }' )
109 GW
=$
(echo $cidrroute |
awk '{ print $6"."$7"."$8"."$9 }' )
111 echo [$ROUTECOUNTER] Route Network
: $NW/$MASK Gateway
: $GW on
$interface
113 # TODO: Check for malformed data here to eliminate counter workaround
114 # Malformed data is: ... or xxx... or xxx.yyy.. or xxx.yyy.zzz.
116 [ -n "$NW" ] && [ -n "$GW" ] && {
117 route add
$NW gw
$GW dev
$interface
120 # Clear the strings incase they don't get set next time around
121 if [ ${NW} = "0" ]; then
128 # Remove the '.' so that we can delete them from the input with sed
129 TMP
=$
(echo $TMP |
sed "s/\./ /g")
131 # Remove the previous entry from cidrroute
132 cidrroute
=$
(echo $cidrroute |
sed "s/$TMP//g")
135 let ROUTECOUNTER
=$ROUTECOUNTER+1;
136 let MAXCIDRROUTES
=$MAXCIDRROUTES-1;
138 # Leave the loop if cidrroutes is empty (we've parsed everything)
139 [ ! -n "$cidrroute" ] && break
147 config_get old_dns
"$ifc" dns
148 user_dns
=$
(uci_get
"network.$ifc.dns")
149 [ -n "$user_dns" ] && dns
="$user_dns"
151 [ -n "$dns" ] && [ ! -s "${RESOLV_CONF}" -o "$dns" != "$old_dns" ] && {
152 echo "udhcpc: setting dns servers: $dns"
153 echo -n > "${RESOLV_CONF}.tmp"
155 echo "nameserver $i" >> "${RESOLV_CONF}.tmp"
157 ${domain:+echo search $domain} >> "${RESOLV_CONF}.tmp"
158 mv "${RESOLV_CONF}.tmp" "$RESOLV_CONF"
160 change_state network
"$ifc" dnsdomain
"$domain"
161 change_state network
"$ifc" dns
"$dns"
164 [ -n "$ifc" ] ||
return
167 change_state network
"$ifc" lease_server
"$serverid"
168 change_state network
"$ifc" lease_acquired
"$(date '+%s')"
169 change_state network
"$ifc" lease_lifetime
"$lease"
170 [ -n "$ntpsrv" ] && change_state network
"$ifc" lease_ntpsrv
"$ntpsrv"
171 [ -n "$timesvr" ] && change_state network
"$ifc" lease_timesrv
"$timesvr"
172 [ -n "$hostname" ] && change_state network
"$ifc" lease_hostname
"$hostname"
173 [ -n "$timezone" ] && change_state network
"$ifc" lease_timezone
"$timezone"
177 env
-i ACTION
="$1" INTERFACE
="$ifc" DEVICE
="$ifname" PROTO
=dhcp
/sbin
/hotplug-call iface
183 for ifc
in $interfaces __default
; do
184 if [ "$ifc" = __default
]; then
186 [ -n "$applied" ] && continue
188 config_get ifname
"$ifc" ifname
189 [ "$ifname" = "$interface" ] ||
continue
191 config_get proto
"$ifc" proto
192 [ "$proto" = "dhcp" ] ||
continue
198 ifconfig
"$interface" 0.0.0.0
200 env
-i ACTION
="ifdown" INTERFACE
="$ifc" DEVICE
="$ifname" PROTO
=dhcp
/sbin
/hotplug-call iface
202 config_get device
"$ifc" device
203 config_get ifname
"$ifc" ifname
204 config_get aliases
"$ifc" aliases
205 uci_revert_state network
"$ifc"
206 [ -n "$device" ] && uci_set_state network
"$ifc" device
"$device"
207 [ -n "$ifname" ] && uci_set_state network
"$ifc" ifname
"$ifname"
208 [ -n "$aliases" ] && uci_set_state network
"$ifc" aliases
"$aliases"
212 setup_interface update
220 [ -f /etc
/udhcpc.user
] && .
/etc
/udhcpc.user
This page took 0.053322 seconds and 3 git commands to generate.