simwifi: host wlan0 obtains ip and set dns for wlan0 in the defwan wlan0
Signed-off-by: liqinhui <liqinhui@xiaomi.com>
This commit is contained in:
parent
fe03ce5fbe
commit
41762eb187
@ -33,7 +33,7 @@ HOSTAPD_CONF_FILE="$RUN_DIR/hostapd.conf"
|
|||||||
DNSMASQ_PID="$RUN_DIR/dnsmasq.pid"
|
DNSMASQ_PID="$RUN_DIR/dnsmasq.pid"
|
||||||
DNSMASQ_CONF="$RUN_DIR/dnsmasq.conf"
|
DNSMASQ_CONF="$RUN_DIR/dnsmasq.conf"
|
||||||
UDHCPC_PID="$RUN_DIR/udhcpc.pid"
|
UDHCPC_PID="$RUN_DIR/udhcpc.pid"
|
||||||
UDHCPC_SCRIPT="$RUN_DIR/udhcpc.script"
|
UDHCPC_SCRIPT="/var/udhcpc.script"
|
||||||
|
|
||||||
LOG_FILE="$RUN_DIR/simwifi.log"
|
LOG_FILE="$RUN_DIR/simwifi.log"
|
||||||
STATE_FILE="$RUN_DIR/simwifi.state"
|
STATE_FILE="$RUN_DIR/simwifi.state"
|
||||||
@ -151,6 +151,7 @@ init_env()
|
|||||||
|
|
||||||
cp -fr $CUR_DIR/dnsmasq.conf $DNSMASQ_CONF
|
cp -fr $CUR_DIR/dnsmasq.conf $DNSMASQ_CONF
|
||||||
cp -fr $CUR_DIR/udhcpc.script $UDHCPC_SCRIPT
|
cp -fr $CUR_DIR/udhcpc.script $UDHCPC_SCRIPT
|
||||||
|
chmod +x $UDHCPC_SCRIPT
|
||||||
}
|
}
|
||||||
|
|
||||||
# Rename the interface name
|
# Rename the interface name
|
||||||
@ -337,6 +338,8 @@ del_gw_wlan()
|
|||||||
ip route del $router
|
ip route del $router
|
||||||
sw_dbg 1 "del the default router on $wlan_if"
|
sw_dbg 1 "del the default router on $wlan_if"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ifconfig $wlan_if 0.0.0.0
|
||||||
}
|
}
|
||||||
|
|
||||||
stop_sta()
|
stop_sta()
|
||||||
@ -512,7 +515,7 @@ init()
|
|||||||
echo "mode:$2" >> $DEFCONF_FILE
|
echo "mode:$2" >> $DEFCONF_FILE
|
||||||
[ "$2" = "hwsim" ] && modprobe mac80211_hwsim
|
[ "$2" = "hwsim" ] && modprobe mac80211_hwsim
|
||||||
|
|
||||||
set_state SW_INIT
|
set_state SW_INIT "" $NUTTX_BR_IF $1
|
||||||
}
|
}
|
||||||
|
|
||||||
clean()
|
clean()
|
||||||
@ -523,6 +526,7 @@ clean()
|
|||||||
[ "$cur_mode" = "hwsim" ] && modprobe -r mac80211_hwsim
|
[ "$cur_mode" = "hwsim" ] && modprobe -r mac80211_hwsim
|
||||||
|
|
||||||
rm -fr $RUN_DIR
|
rm -fr $RUN_DIR
|
||||||
|
rm -f $UDHCPC_SCRIPT
|
||||||
}
|
}
|
||||||
|
|
||||||
usage()
|
usage()
|
||||||
|
@ -10,6 +10,8 @@ log() {
|
|||||||
logger -t "udhcpc[$PPID]" -p daemon.$1 "$interface: $2"
|
logger -t "udhcpc[$PPID]" -p daemon.$1 "$interface: $2"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SIMWIFILOG_FILE=/var/run/simwifi/simwifi.log
|
||||||
|
DEFCONF_FILE=/var/run/simwifi/simwifi.conf
|
||||||
case $1 in
|
case $1 in
|
||||||
bound|renew)
|
bound|renew)
|
||||||
|
|
||||||
@ -19,6 +21,34 @@ case $1 in
|
|||||||
busybox ifconfig $interface ${mtu:+mtu $mtu} \
|
busybox ifconfig $interface ${mtu:+mtu $mtu} \
|
||||||
$ip netmask $subnet ${broadcast:+broadcast $broadcast}
|
$ip netmask $subnet ${broadcast:+broadcast $broadcast}
|
||||||
|
|
||||||
|
# defwan equals to wlanx, should add router and DEF_NS
|
||||||
|
|
||||||
|
defwan=$(cat $DEFCONF_FILE | grep defwan | awk -F':' '{print $2}')
|
||||||
|
[ ".$defwan" = ".wlan0" ] && {
|
||||||
|
# get current ("old") routes (after setting new IP)
|
||||||
|
crouter=$(busybox ip -4 route show dev $interface |
|
||||||
|
busybox awk '$1 == "default" { print $3; }')
|
||||||
|
router="${router%% *}" # linux kernel supports only one (default) route
|
||||||
|
if [ ".$router" != ".$crouter" ]; then
|
||||||
|
# reset just default routes
|
||||||
|
busybox ip -4 route flush exact 0.0.0.0/0 dev $interface
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$router" ]; then
|
||||||
|
# special case for /32 subnets: use onlink keyword
|
||||||
|
[ ".$subnet" = .255.255.255.255 ] \
|
||||||
|
&& onlink=onlink || onlink=
|
||||||
|
busybox ip -4 route add default via $router dev $interface $onlink
|
||||||
|
log info "udhcpc add router $router on $interfac"
|
||||||
|
fi
|
||||||
|
|
||||||
|
DEF_NS="nameserver 8.8.8.8"
|
||||||
|
RESOLV_CONF_FILE=${RESOLV_CONF:-/etc/resolv.conf}
|
||||||
|
[ -f $RESOLV_CONF_FILE -a -z "$(cat $RESOLV_CONF_FILE | grep 8.8.8.8)" ] && {
|
||||||
|
echo "$DEF_NS" >> "$RESOLV_CONF_FILE"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
log info "$1: IP=$ip/$subnet router=$router domain=\"$domain\" dns=\"$dns\" lease=$lease"
|
log info "$1: IP=$ip/$subnet router=$router domain=\"$domain\" dns=\"$dns\" lease=$lease"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user