Skip to content

Commit

Permalink
Handle failures to create an interface. Fix #14708
Browse files Browse the repository at this point in the history
The function pfSense_interface_create2() may fail to create the
requested interface, in which case it returns the array:
['error'=>'Could not create interface']
  • Loading branch information
marcos-ng committed Jun 4, 2024
1 parent 70defd0 commit ac39332
Showing 1 changed file with 48 additions and 4 deletions.
52 changes: 48 additions & 4 deletions src/etc/inc/interfaces.inc
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,10 @@ function interface_vlan_configure(&$vlan, $flush = true, $skip_parent_mtu = fals
}

$tmpvlanif = pfSense_interface_create2("vlan");
if (!is_string($tmpvlanif)) {
log_error(sprintf(gettext('Failed to configure interface %1$s: Could not create temporary interface %2$s'), $vlan['vlanif'], 'vlan'));
return(NULL);
}
pfSense_interface_rename($tmpvlanif, $vlanif);
pfSense_ngctl_name("{$tmpvlanif}:", $vlanif);

Expand Down Expand Up @@ -711,12 +715,20 @@ function interface_bridge_configure(&$bridge, $checkmember = 0, $flush = true) {

if (!empty($bridge['bridgeif'])) {
pfSense_interface_destroy($bridge['bridgeif']);
pfSense_interface_create2($bridge['bridgeif']);
$tempifname = pfSense_interface_create2($bridge['bridgeif']);
if (!is_string($tempifname)) {
log_error(sprintf(gettext('Failed to configure interface %1$s: Could not create temporary interface %2$s'), $bridge['bridgeif'], $bridge['bridgeif']));
return;
}
$bridgeif = escapeshellarg($bridge['bridgeif']);
} else {
// if called directly, as interfaces_bridge_edit.php does, and bridgeif isn't set
// normally set by interfaces_bridge_configure, but not upon creation of new bridge
$bridgeif = pfSense_interface_create2("bridge");
if (!is_string($bridgeif)) {
log_error(sprintf(gettext('Failed to configure interface %1$s: Could not create temporary interface %2$s'), $bridge['bridgeif'], 'bridge'));
return;
}
$bridge['bridgeif'] = $bridgeif;
}

Expand Down Expand Up @@ -971,10 +983,18 @@ function interface_lagg_configure($lagg, $flush = true) {

if (is_platform_booting() || !(empty($lagg['laggif']))) {
pfSense_interface_destroy($lagg['laggif']);
pfSense_interface_create2($lagg['laggif']);
$tempifname = pfSense_interface_create2($lagg['laggif']);
if (!is_string($tempifname)) {
log_error(sprintf(gettext('Failed to configure interface %1$s: Could not create temporary interface %2$s'), $lagg['laggif'], $lagg['laggif']));
return -1;
}
$laggif = $lagg['laggif'];
} else {
$laggif = pfSense_interface_create2("lagg");
if (!is_string($laggif)) {
log_error(sprintf(gettext('Failed to configure interface %1$s: Could not create temporary interface %2$s'), $lagg['laggif'], 'lagg'));
return -1;
}
}

/* Check if MTU was defined for this lagg interface */
Expand Down Expand Up @@ -1071,10 +1091,18 @@ function interface_gre_configure(&$gre, $grekey = "", $flush = true) {

if (is_platform_booting() || !(empty($gre['greif']))) {
pfSense_interface_destroy($gre['greif']);
pfSense_interface_create2($gre['greif']);
$tempifname = pfSense_interface_create2($gre['greif']);
if (!is_string($tempifname)) {
log_error(sprintf(gettext('Failed to configure interface %1$s: Could not create temporary interface %2$s'), $gre['if'], $gre['greif']));
return -1;
}
$greif = $gre['greif'];
} else {
$greif = pfSense_interface_create2("gre");
if (!is_string($greif)) {
log_error(sprintf(gettext('Failed to configure interface %1$s: Could not create temporary interface %2$s'), $gre['if'], 'gre'));
return -1;
}
}

$tunnel_type = '';
Expand Down Expand Up @@ -1234,10 +1262,18 @@ function interface_gif_configure(&$gif, $gifkey = "", $flush = true) {

if (is_platform_booting() || !(empty($gif['gifif']))) {
pfSense_interface_destroy($gif['gifif']);
pfSense_interface_create2($gif['gifif']);
$tempifname = pfSense_interface_create2($gif['gifif']);
if (!is_string($tempifname)) {
log_error(sprintf(gettext('Failed to configure interface %1$s: Could not create temporary interface %2$s'), $gif['if'], $gif['gifif']));
return -1;
}
$gifif = $gif['gifif'];
} else {
$gifif = pfSense_interface_create2("gif");
if (!is_string($gifif)) {
log_error(sprintf(gettext('Failed to configure interface %1$s: Could not create temporary interface %2$s'), $gif['if'], 'gif'));
return -1;
}
}

/* Do not change the order here for more see gif(4) NOTES section. */
Expand Down Expand Up @@ -4608,6 +4644,10 @@ function interface_6rd_configure($interface, $wancfg) {
pfSense_interface_destroy($stfiface);
}
$tmpstfiface = pfSense_interface_create2("stf");
if (!is_string($tmpstfiface)) {
log_error(sprintf(gettext('Failed to configure interface %1$s: Could not create temporary interface %2$s'), $wanif, 'stf'));
return false;
}
pfSense_interface_rename($tmpstfiface, $stfiface);
pfSense_interface_flags($stfiface, IFF_LINK2);
mwexec("/sbin/ifconfig {$stfiface} inet6 {$rd6prefix}/{$rd6prefixlen}");
Expand Down Expand Up @@ -4724,6 +4764,10 @@ function interface_6to4_configure($interface, $wancfg) {
pfSense_interface_destroy($stfiface);
}
$tmpstfiface = pfSense_interface_create2("stf");
if (!is_string($tmpstfiface)) {
log_error(sprintf(gettext('Failed to configure interface %1$s: Could not create temporary interface %2$s'), $wanif, 'stf'));
return;
}
pfSense_interface_rename($tmpstfiface, $stfiface);
pfSense_interface_flags($stfiface, IFF_LINK2);
mwexec("/sbin/ifconfig {$stfiface} inet6 {$stflanpr} prefixlen 16");
Expand Down

0 comments on commit ac39332

Please sign in to comment.