Skip to content

Commit

Permalink
Wait 20 sec for the if to come up and the default route set
Browse files Browse the repository at this point in the history
urtwn(4) takes longer than 10 sec.
And delete the current default route, so we are sure we load the pf
rules after the new default route is set.
  • Loading branch information
sonertari committed Oct 23, 2021
1 parent f9911a6 commit 88e1544
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/Model/system.php
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,7 @@ function NetStart($if= '')
$intif= trim($intif, '"');
if ($if == '' || $if == $intif) {
if ($this->isWifiIf($intif)) {
// Clear all wifi configuration, ifconfig down or /etc/netstart don't clear them
// Clear all wifi configuration, ifconfig down and /etc/netstart don't clear them
$cmd[]= "/sbin/ifconfig $intif -mediaopt hostap -nwid -wpakey -nwkey 2>&1";
}
$cmd[]= "/sbin/ifconfig $intif down 2>&1";
Expand All @@ -1142,6 +1142,10 @@ function NetStart($if= '')
if ($extif !== FALSE) {
$extif= trim($extif, '"');
if ($if == '' || $if == $extif) {
if ($this->isWifiIf($extif)) {
// Clear all wifi configuration, ifconfig down and /etc/netstart don't clear them
$cmd[]= "/sbin/ifconfig $extif -mediaopt hostap -nwid -wpakey -nwkey 2>&1";
}
$cmd[]= "/sbin/ifconfig $extif down 2>&1";
}
} else {
Expand All @@ -1156,6 +1160,8 @@ function NetStart($if= '')
if ($gateway !== '') {
$cmd[]= "/usr/sbin/arp -nd $gateway 2>&1";
}
// Delete the current default route, so we are sure we load the pf rules after the new default route is set
$cmd[]= "/sbin/route delete default 2>&1";
}

// Pass $if as arg, passing empty string is fine
Expand All @@ -1174,13 +1180,14 @@ function NetStart($if= '')
}
}

$cmdline= implode(' && ', $cmd);
// Implode with ';' not '&&', any of the commands can fail, but we should exec the others
$cmdline= implode(' ; ', $cmd);

exec($cmdline, $output, $retval);
$errout= implode("\n", $output);
Error($errout);

// Refresh pf rules too
// Refresh the pf rules too
$retval&= $this->reloadPfRules();

if ($retval === 0) {
Expand All @@ -1194,7 +1201,7 @@ function reloadPfRules()
{
$cmd= "/sbin/route -n show | grep -q ^default";
$count= 0;
while ($count++ < 10) {
while ($count++ < 20) {
exec($cmd, $output, $retval);
if ($retval === 0) {
break;
Expand Down

0 comments on commit 88e1544

Please sign in to comment.