Commit 8a7ba132 authored by Ad Schellevis's avatar Ad Schellevis Committed by Franco Fichtner

(legacy) cleanups related to interfaces.inc (remove unused, move single usage, isset issues)

parent eb03dc1a
...@@ -115,40 +115,6 @@ function does_interface_exist($interface, $flush = true) { ...@@ -115,40 +115,6 @@ function does_interface_exist($interface, $flush = true) {
return false; return false;
} }
/*
* does_vip_exist($vip): return true or false if a vip is
* configured.
*/
function does_vip_exist($vip) {
global $config;
if(!$vip)
return false;
switch ($vip['mode']) {
case "carp":
case "ipalias":
/* XXX: Make proper checks? */
$realif = get_real_interface($vip['interface']);
if (!does_interface_exist($realif)) {
return false;
}
break;
case "proxyarp":
/* XXX: Implement this */
default:
return false;
}
$ifacedata = pfSense_getall_interface_addresses($realif);
foreach ($ifacedata as $vipips) {
if ($vipips == "{$vip['subnet']}/{$vip['subnet_bits']}")
return true;
}
return false;
}
function interface_netgraph_needed($interface = "wan") { function interface_netgraph_needed($interface = "wan") {
global $config; global $config;
...@@ -157,10 +123,10 @@ function interface_netgraph_needed($interface = "wan") { ...@@ -157,10 +123,10 @@ function interface_netgraph_needed($interface = "wan") {
if (!empty($config['pptpd']) && if (!empty($config['pptpd']) &&
$config['pptpd']['mode'] == "server") $config['pptpd']['mode'] == "server")
$found = true; $found = true;
if ($found == false && !empty($config['l2tp']) && if (!$found && !empty($config['l2tp']) &&
$config['l2tp']['mode'] == "server") $config['l2tp']['mode'] == "server")
$found = true; $found = true;
if ($found == false && is_array($config['pppoes']['pppoe'])) { if (!$found && isset($config['pppoes']['pppoe']) && is_array($config['pppoes']['pppoe'])) {
foreach ($config['pppoes']['pppoe'] as $pppoe) { foreach ($config['pppoes']['pppoe'] as $pppoe) {
if ($pppoe['mode'] != "server") if ($pppoe['mode'] != "server")
continue; continue;
...@@ -169,7 +135,7 @@ function interface_netgraph_needed($interface = "wan") { ...@@ -169,7 +135,7 @@ function interface_netgraph_needed($interface = "wan") {
break; break;
} }
} }
if ($found == false) { if (!$found) {
if (!empty($config['interfaces'][$interface])) { if (!empty($config['interfaces'][$interface])) {
switch ($config['interfaces'][$interface]['ipaddr']) { switch ($config['interfaces'][$interface]['ipaddr']) {
case "ppp": case "ppp":
...@@ -184,20 +150,10 @@ function interface_netgraph_needed($interface = "wan") { ...@@ -184,20 +150,10 @@ function interface_netgraph_needed($interface = "wan") {
} }
} }
} }
if ($found == false) { if (!$found) {
$realif = get_real_interface($interface); $realif = get_real_interface($interface);
if (isset($config['ppps']['ppp'])) { if (isset($config['ppps']['ppp'])) {
foreach ($config['ppps']['ppp'] as $pppid => $ppp) { foreach ($config['ppps']['ppp'] as $pppid => $ppp) {
/* This if block doesn't do anything. It can be deleted.
PPP interfaces are found above in the previous if ($found == false) block.
This block of code is only entered for OPTx interfaces that are configured for PPPoE modem access, so $realif != $ppp['if']
if ($realif == $ppp['if']) {
$found = true;
break;
}
*/
$ports = explode(',',$ppp['ports']); $ports = explode(',',$ppp['ports']);
foreach($ports as $pid => $port){ foreach($ports as $pid => $port){
$port = get_real_interface($port); $port = get_real_interface($port);
...@@ -218,7 +174,7 @@ This block of code is only entered for OPTx interfaces that are configured for P ...@@ -218,7 +174,7 @@ This block of code is only entered for OPTx interfaces that are configured for P
} }
} }
if ($found == false) { if (!$found) {
$realif = get_real_interface($interface); $realif = get_real_interface($interface);
pfSense_ngctl_detach("{$realif}:", $realif); pfSense_ngctl_detach("{$realif}:", $realif);
} }
...@@ -377,7 +333,7 @@ function interface_qinq_configure(&$vlan, $fd = NULL) { ...@@ -377,7 +333,7 @@ function interface_qinq_configure(&$vlan, $fd = NULL) {
interface_qinq2_configure($qinq, $fd, $macaddr); interface_qinq2_configure($qinq, $fd, $macaddr);
} }
} }
if ($exec == true) { if ($exec) {
fclose($fd); fclose($fd);
mwexec('/usr/sbin/ngctl -f /tmp/netgraphcmd'); mwexec('/usr/sbin/ngctl -f /tmp/netgraphcmd');
} }
...@@ -396,7 +352,7 @@ function interfaces_qinq_configure() { ...@@ -396,7 +352,7 @@ function interfaces_qinq_configure() {
global $config; global $config;
if(file_exists("/var/run/booting")) if(file_exists("/var/run/booting"))
echo gettext("Configuring QinQ interfaces..."); echo gettext("Configuring QinQ interfaces...");
if (is_array($config['qinqs']['qinqentry']) && count($config['qinqs']['qinqentry'])) { if (isset($config['qinqs']['qinqentry']) && is_array($config['qinqs']['qinqentry'])) {
foreach ($config['qinqs']['qinqentry'] as $qinq) { foreach ($config['qinqs']['qinqentry'] as $qinq) {
/* XXX: Maybe we should report any errors?! */ /* XXX: Maybe we should report any errors?! */
interface_qinq_configure($qinq); interface_qinq_configure($qinq);
...@@ -547,7 +503,7 @@ function interface_bridge_configure(&$bridge, $checkmember = 0) { ...@@ -547,7 +503,7 @@ function interface_bridge_configure(&$bridge, $checkmember = 0) {
else if (!empty($mtu) && $mtu < $smallermtu) else if (!empty($mtu) && $mtu < $smallermtu)
$smallermtu = $mtu; $smallermtu = $mtu;
} }
if ($foundgif == false && $checkmember == 2) { if (!$foundgif && $checkmember == 2) {
return; return;
} }
...@@ -745,7 +701,7 @@ function interfaces_lagg_configure($realif = "") { ...@@ -745,7 +701,7 @@ function interfaces_lagg_configure($realif = "") {
if(file_exists("/var/run/booting")) if(file_exists("/var/run/booting"))
echo gettext("Configuring LAGG interfaces..."); echo gettext("Configuring LAGG interfaces...");
$i = 0; $i = 0;
if (is_array($config['laggs']['lagg']) && count($config['laggs']['lagg'])) { if (isset($config['laggs']['lagg']) && is_array($config['laggs']['lagg'])) {
foreach ($config['laggs']['lagg'] as $lagg) { foreach ($config['laggs']['lagg'] as $lagg) {
if(empty($lagg['laggif'])) if(empty($lagg['laggif']))
$lagg['laggif'] = "lagg{$i}"; $lagg['laggif'] = "lagg{$i}";
...@@ -851,7 +807,7 @@ function interface_lagg_configure(&$lagg) ...@@ -851,7 +807,7 @@ function interface_lagg_configure(&$lagg)
function interfaces_gre_configure($checkparent = 0, $realif = "") { function interfaces_gre_configure($checkparent = 0, $realif = "") {
global $config; global $config;
if (is_array($config['gres']['gre']) && count($config['gres']['gre'])) { if (isset($config['gres']['gre']) && is_array($config['gres']['gre'])) {
foreach ($config['gres']['gre'] as $i => $gre) { foreach ($config['gres']['gre'] as $i => $gre) {
if (empty($gre['greif'])) if (empty($gre['greif']))
$gre['greif'] = "gre{$i}"; $gre['greif'] = "gre{$i}";
...@@ -1403,25 +1359,6 @@ function interface_bring_down($interface = "wan", $destroy = false, $ifacecfg = ...@@ -1403,25 +1359,6 @@ function interface_bring_down($interface = "wan", $destroy = false, $ifacecfg =
return; return;
} }
function interfaces_carp_set_maintenancemode($carp_maintenancemode){
global $config;
if (isset($config["virtualip_carp_maintenancemode"]) && $carp_maintenancemode == false) {
unset($config["virtualip_carp_maintenancemode"]);
write_config("Leave CARP maintenance mode");
} else
if (!isset($config["virtualip_carp_maintenancemode"]) && $carp_maintenancemode == true) {
$config["virtualip_carp_maintenancemode"] = true;
write_config("Enter CARP maintenance mode");
}
$viparr = &$config['virtualip']['vip'];
foreach ($viparr as $vip) {
if ($vip['mode'] == "carp") {
interface_carp_configure($vip);
}
}
}
function interfaces_ptpid_used($ptpid) { function interfaces_ptpid_used($ptpid) {
global $config; global $config;
...@@ -1447,7 +1384,7 @@ function getMPDCRONSettings($pppif) ...@@ -1447,7 +1384,7 @@ function getMPDCRONSettings($pppif)
global $config; global $config;
$cron_cmd_file = "/var/etc/pppoe_restart_{$pppif}"; $cron_cmd_file = "/var/etc/pppoe_restart_{$pppif}";
if (is_array($config['cron']['item'])) { if (isset($config['cron']['item']) && is_array($config['cron']['item'])) {
foreach ($config['cron']['item'] as $i => $item) { foreach ($config['cron']['item'] as $i => $item) {
if (stripos($item['command'], $cron_cmd_file) !== false) if (stripos($item['command'], $cron_cmd_file) !== false)
return array("ID" => $i, "ITEM" => $item); return array("ID" => $i, "ITEM" => $item);
...@@ -1463,7 +1400,7 @@ function handle_pppoe_reset($post_array) { ...@@ -1463,7 +1400,7 @@ function handle_pppoe_reset($post_array) {
$pppif = "{$post_array['type']}{$post_array['ptpid']}"; $pppif = "{$post_array['type']}{$post_array['ptpid']}";
$cron_cmd_file = "/var/etc/pppoe_restart_{$pppif}"; $cron_cmd_file = "/var/etc/pppoe_restart_{$pppif}";
if (!is_array($config['cron']['item'])) if (!isset($config['cron']['item']) || !is_array($config['cron']['item']))
$config['cron']['item'] = array(); $config['cron']['item'] = array();
$itemhash = getMPDCRONSettings($pppif); $itemhash = getMPDCRONSettings($pppif);
...@@ -1561,13 +1498,13 @@ function interface_ppps_configure($interface) ...@@ -1561,13 +1498,13 @@ function interface_ppps_configure($interface)
symlink('/usr/local/sbin/mpd.script', '/var/etc/mpd.script'); symlink('/usr/local/sbin/mpd.script', '/var/etc/mpd.script');
} }
if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])) { if (isset($config['ppps']['ppp']) && is_array($config['ppps']['ppp'])) {
foreach ($config['ppps']['ppp'] as $pppid => $ppp) { foreach ($config['ppps']['ppp'] as $pppid => $ppp) {
if ($ifcfg['if'] == $ppp['if']) if ($ifcfg['if'] == $ppp['if'])
break; break;
} }
} }
if (!$ppp || $ifcfg['if'] != $ppp['if']){ if (!isset($ppp) || $ifcfg['if'] != $ppp['if']){
log_error(sprintf(gettext("Can't find PPP config for %s in interface_ppps_configure()."), $ifcfg['if'])); log_error(sprintf(gettext("Can't find PPP config for %s in interface_ppps_configure()."), $ifcfg['if']));
return 0; return 0;
} }
...@@ -2013,7 +1950,7 @@ function interfaces_carp_setup() ...@@ -2013,7 +1950,7 @@ function interfaces_carp_setup()
unset($carp_sync_int); unset($carp_sync_int);
/* setup pfsync interface */ /* setup pfsync interface */
if ($carp_sync_int && isset($pfsyncenabled)) { if (!empty($carp_sync_int) && isset($pfsyncenabled)) {
if (is_ipaddr($pfsyncpeerip)) if (is_ipaddr($pfsyncpeerip))
$syncpeer = "syncpeer {$pfsyncpeerip}"; $syncpeer = "syncpeer {$pfsyncpeerip}";
else else
...@@ -2062,8 +1999,7 @@ function interface_proxyarp_configure($interface = '') ...@@ -2062,8 +1999,7 @@ function interface_proxyarp_configure($interface = '')
} }
$paa = array(); $paa = array();
if (!empty($config['virtualip']) && is_array($config['virtualip']['vip'])) { if (isset($config['virtualip']['vip']) && is_array($config['virtualip']['vip'])) {
/* group by interface */ /* group by interface */
foreach ($config['virtualip']['vip'] as $vipent) { foreach ($config['virtualip']['vip'] as $vipent) {
if ($vipent['mode'] === "proxyarp") { if ($vipent['mode'] === "proxyarp") {
...@@ -2252,7 +2188,7 @@ function interface_wireless_clone($realif, $wlcfg) ...@@ -2252,7 +2188,7 @@ function interface_wireless_clone($realif, $wlcfg)
* If it has not been cloned then go ahead and clone it. * If it has not been cloned then go ahead and clone it.
*/ */
$needs_clone = false; $needs_clone = false;
if(is_array($wlcfg['wireless'])) if(isset($wlcfg['wireless']) && is_array($wlcfg['wireless']))
$wlcfg_mode = $wlcfg['wireless']['mode']; $wlcfg_mode = $wlcfg['wireless']['mode'];
else else
$wlcfg_mode = $wlcfg['mode']; $wlcfg_mode = $wlcfg['mode'];
...@@ -2287,7 +2223,7 @@ function interface_wireless_clone($realif, $wlcfg) ...@@ -2287,7 +2223,7 @@ function interface_wireless_clone($realif, $wlcfg)
$needs_clone = true; $needs_clone = true;
} }
if ($needs_clone == true) { if ($needs_clone) {
/* remove previous instance if it exists */ /* remove previous instance if it exists */
if (does_interface_exist($realif)) { if (does_interface_exist($realif)) {
legacy_interface_destroy($realif); legacy_interface_destroy($realif);
...@@ -2366,7 +2302,7 @@ function interface_sync_wireless_clones(&$ifcfg, $sync_changes = false) ...@@ -2366,7 +2302,7 @@ function interface_sync_wireless_clones(&$ifcfg, $sync_changes = false)
} }
// Sync the mode on the clone creation page with the configured mode on the interface // Sync the mode on the clone creation page with the configured mode on the interface
if (interface_is_wireless_clone($ifcfg['if']) && isset($config['wireless']['clone']) && is_array($config['wireless']['clone'])) { if (stristr($ifcfg['if'], "_wlan") && isset($config['wireless']['clone']) && is_array($config['wireless']['clone'])) {
foreach ($config['wireless']['clone'] as &$clone) { foreach ($config['wireless']['clone'] as &$clone) {
if ($clone['cloneif'] == $ifcfg['if']) { if ($clone['cloneif'] == $ifcfg['if']) {
if ($sync_changes) { if ($sync_changes) {
...@@ -2845,7 +2781,7 @@ function find_dhcp6c_process($interface) ...@@ -2845,7 +2781,7 @@ function find_dhcp6c_process($interface)
function interface_vlan_mtu_configured($realhwif, $mtu) { function interface_vlan_mtu_configured($realhwif, $mtu) {
global $config; global $config;
if (is_array($config['vlans']) && is_array($config['vlans']['vlan'])) { if (isset($config['vlans']['vlan']) && is_array($config['vlans']['vlan'])) {
foreach ($config['vlans']['vlan'] as $vlan) { foreach ($config['vlans']['vlan'] as $vlan) {
if ($vlan['if'] != $realhwif) if ($vlan['if'] != $realhwif)
continue; continue;
...@@ -2990,7 +2926,7 @@ function interface_configure($interface = 'wan', $reloadall = false, $linkupeven ...@@ -2990,7 +2926,7 @@ function interface_configure($interface = 'wan', $reloadall = false, $linkupeven
mwexec("/sbin/ifconfig " . escapeshellarg($realif) . " inet6 -accept_rtadv"); mwexec("/sbin/ifconfig " . escapeshellarg($realif) . " inet6 -accept_rtadv");
/* wireless configuration? */ /* wireless configuration? */
if (is_array($wancfg['wireless'])) if (isset($wancfg['wireless']) && is_array($wancfg['wireless']))
interface_wireless_configure($realif, $wancfg, $wancfg['wireless']); interface_wireless_configure($realif, $wancfg, $wancfg['wireless']);
$mac = get_interface_mac($realhwif); $mac = get_interface_mac($realhwif);
...@@ -3000,7 +2936,7 @@ function interface_configure($interface = 'wan', $reloadall = false, $linkupeven ...@@ -3000,7 +2936,7 @@ function interface_configure($interface = 'wan', $reloadall = false, $linkupeven
* the interface config again, which attempts to spoof the MAC again, * the interface config again, which attempts to spoof the MAC again,
* which cycles the link again... * which cycles the link again...
*/ */
if ($wancfg['spoofmac'] && ($wancfg['spoofmac'] != $mac)) { if (isset($wancfg['spoofmac']) && ($wancfg['spoofmac'] != $mac)) {
mwexec("/sbin/ifconfig " . escapeshellarg($realhwif) . mwexec("/sbin/ifconfig " . escapeshellarg($realhwif) .
" link " . escapeshellarg($wancfg['spoofmac'])); " link " . escapeshellarg($wancfg['spoofmac']));
...@@ -3008,7 +2944,7 @@ function interface_configure($interface = 'wan', $reloadall = false, $linkupeven ...@@ -3008,7 +2944,7 @@ function interface_configure($interface = 'wan', $reloadall = false, $linkupeven
* All vlans need to spoof their parent mac address, too. see * All vlans need to spoof their parent mac address, too. see
* ticket #1514: http://cvstrac.pfsense.com/tktview?tn=1514,33 * ticket #1514: http://cvstrac.pfsense.com/tktview?tn=1514,33
*/ */
if (is_array($config['vlans']['vlan'])) { if (isset($config['vlans']['vlan']) && is_array($config['vlans']['vlan'])) {
foreach ($config['vlans']['vlan'] as $vlan) { foreach ($config['vlans']['vlan'] as $vlan) {
if ($vlan['if'] == $realhwif) if ($vlan['if'] == $realhwif)
mwexec("/sbin/ifconfig " . escapeshellarg($vlan['vlanif']) . mwexec("/sbin/ifconfig " . escapeshellarg($vlan['vlanif']) .
...@@ -3032,12 +2968,14 @@ function interface_configure($interface = 'wan', $reloadall = false, $linkupeven ...@@ -3032,12 +2968,14 @@ function interface_configure($interface = 'wan', $reloadall = false, $linkupeven
} }
/* media */ /* media */
if ($wancfg['media'] || $wancfg['mediaopt']) { if (isset($wancfg['media']) || isset($wancfg['mediaopt'])) {
$cmd = "/sbin/ifconfig " . escapeshellarg($realhwif); $cmd = "/sbin/ifconfig " . escapeshellarg($realhwif);
if ($wancfg['media']) if (isset($wancfg['media'])) {
$cmd .= " media " . escapeshellarg($wancfg['media']); $cmd .= " media " . escapeshellarg($wancfg['media']);
if ($wancfg['mediaopt']) }
if (isset($wancfg['mediaopt'])) {
$cmd .= " mediaopt " . escapeshellarg($wancfg['mediaopt']); $cmd .= " mediaopt " . escapeshellarg($wancfg['mediaopt']);
}
mwexec($cmd); mwexec($cmd);
} }
$options = pfSense_get_interface_addresses($realhwif); $options = pfSense_get_interface_addresses($realhwif);
...@@ -3082,30 +3020,31 @@ function interface_configure($interface = 'wan', $reloadall = false, $linkupeven ...@@ -3082,30 +3020,31 @@ function interface_configure($interface = 'wan', $reloadall = false, $linkupeven
break; break;
} }
switch ($wancfg['ipaddrv6']) { if (isset($wancfg['ipaddrv6'])) {
case 'slaac': switch ($wancfg['ipaddrv6']) {
case 'dhcp6': case 'slaac':
interface_dhcpv6_configure($interface, $wancfg); case 'dhcp6':
break; interface_dhcpv6_configure($interface, $wancfg);
case '6rd': break;
interface_6rd_configure($interface, $wancfg); case '6rd':
break; interface_6rd_configure($interface, $wancfg);
case '6to4': break;
interface_6to4_configure($interface, $wancfg); case '6to4':
break; interface_6to4_configure($interface, $wancfg);
case 'track6': break;
interface_track6_configure($interface, $wancfg, $linkupevent); case 'track6':
break; interface_track6_configure($interface, $wancfg, $linkupevent);
default: break;
/* XXX: Kludge for now related to #3280 */ default:
if (!in_array($tunnelif, array("gif", "gre", "ovp"))) { /* XXX: Kludge for now related to #3280 */
if (is_ipaddrv6($wancfg['ipaddrv6']) && $wancfg['subnetv6'] <> "") { if (!in_array($tunnelif, array("gif", "gre", "ovp"))) {
mwexec("/sbin/ifconfig " . escapeshellarg($realif) . " inet6 {$wancfg['ipaddrv6']} prefixlen " . escapeshellarg($wancfg['subnetv6'])); if (is_ipaddrv6($wancfg['ipaddrv6']) && $wancfg['subnetv6'] <> "") {
mwexec("/sbin/ifconfig " . escapeshellarg($realif) . " inet6 {$wancfg['ipaddrv6']} prefixlen " . escapeshellarg($wancfg['subnetv6']));
}
} }
break;
} }
break;
} }
if (!empty($wancfg['mtu'])) { if (!empty($wancfg['mtu'])) {
if (stristr($realif, "_vlan")) { if (stristr($realif, "_vlan")) {
$assignedparent = convert_real_interface_to_friendly_interface_name($realhwif); $assignedparent = convert_real_interface_to_friendly_interface_name($realhwif);
...@@ -4273,13 +4212,6 @@ function get_parent_interface($interface, $avoidrecurse = false) { ...@@ -4273,13 +4212,6 @@ function get_parent_interface($interface, $avoidrecurse = false) {
return $parents; return $parents;
} }
function interface_is_wireless_clone($wlif) {
if(!stristr($wlif, "_wlan")) {
return false;
} else {
return true;
}
}
function interface_get_wireless_base($wlif) { function interface_get_wireless_base($wlif) {
if(!stristr($wlif, "_wlan")) { if(!stristr($wlif, "_wlan")) {
...@@ -4438,111 +4370,6 @@ function guess_interface_from_ip($ipaddress) { ...@@ -4438,111 +4370,6 @@ function guess_interface_from_ip($ipaddress) {
return $ret; return $ret;
} }
/*
* find_ip_interface($ip): return the interface where an ip is defined
* (or if $bits is specified, where an IP within the subnet is defined)
*/
function find_ip_interface($ip, $bits = null) {
if (!is_ipaddr($ip))
return false;
$isv6ip = is_ipaddrv6($ip);
/* if list */
$ifdescrs = get_configured_interface_list();
foreach ($ifdescrs as $ifdescr => $ifname) {
$ifip = ($isv6ip) ? get_interface_ipv6($ifname) : get_interface_ip($ifname);
if (is_null($ifip))
continue;
if (is_null($bits)) {
if ($ip == $ifip) {
$int = get_real_interface($ifname);
return $int;
}
}
else {
if (ip_in_subnet($ifip, $ip . "/" . $bits)) {
$int = get_real_interface($ifname);
return $int;
}
}
}
return false;
}
/*
* find_virtual_ip_alias($ip): return the virtual IP alias where an IP is found
* (or if $bits is specified, where an IP within the subnet is found)
*/
function find_virtual_ip_alias($ip, $bits = null)
{
global $config;
if (!isset($config['virtualip']['vip'])) {
return false;
}
if (!is_ipaddr($ip)) {
return false;
}
$isv6ip = is_ipaddrv6($ip);
foreach ($config['virtualip']['vip'] as $vip) {
if ($vip['mode'] === "ipalias") {
if (is_ipaddrv6($vip['subnet']) != $isv6ip)
continue;
if (is_null($bits)) {
if (ip_in_subnet($ip, $vip['subnet'] . "/" . $vip['subnet_bits'])) {
return $vip;
}
}
else {
if (($isv6ip && check_subnetsv6_overlap($ip, $bits, $vip['subnet'], $vip['subnet_bits']))
|| (!$isv6ip && check_subnets_overlap($ip, $bits, $vip['subnet'], $vip['subnet_bits']))) {
return $vip;
}
}
}
}
return false;
}
/*
* find_carp_interface($ip): return the carp interface where an ip is defined
*/
function find_carp_interface($ip)
{
global $config;
if (isset($config['virtualip']['vip'])) {
foreach ($config['virtualip']['vip'] as $vip) {
if ($vip['mode'] == "carp") {
if(is_ipaddrv4($ip)) {
$carp_ip = get_interface_ip($vip['interface']);
}
if(is_ipaddrv6($ip)) {
$carp_ip = get_interface_ipv6($vip['interface']);
}
exec("/sbin/ifconfig", $output, $return);
foreach($output as $line) {
$elements = preg_split("/[ ]+/i", $line);
if(strstr($elements[0], "vip"))
$curif = str_replace(":", "", $elements[0]);
if(stristr($line, $ip)) {
$if = $curif;
continue;
}
}
if ($if) {
return $if;
}
}
}
}
}
/****f* interfaces/link_ip_to_carp_interface /****f* interfaces/link_ip_to_carp_interface
...@@ -4721,7 +4548,6 @@ function link_interface_to_gif($interface) ...@@ -4721,7 +4548,6 @@ function link_interface_to_gif($interface)
*/ */
function find_interface_ip($interface, $flush = false) { function find_interface_ip($interface, $flush = false) {
global $interface_ip_arr_cache; global $interface_ip_arr_cache;
global $interface_sn_arr_cache;
$interface = str_replace("\n", "", $interface); $interface = str_replace("\n", "", $interface);
...@@ -4731,8 +4557,9 @@ function find_interface_ip($interface, $flush = false) { ...@@ -4731,8 +4557,9 @@ function find_interface_ip($interface, $flush = false) {
/* Setup IP cache */ /* Setup IP cache */
if (!isset($interface_ip_arr_cache[$interface]) or $flush) { if (!isset($interface_ip_arr_cache[$interface]) or $flush) {
$ifinfo = pfSense_get_interface_addresses($interface); $ifinfo = pfSense_get_interface_addresses($interface);
$interface_ip_arr_cache[$interface] = $ifinfo['ipaddr']; if (isset($ifinfo['ipaddr'])) {
$interface_sn_arr_cache[$interface] = $ifinfo['subnetbits']; $interface_ip_arr_cache[$interface] = $ifinfo['ipaddr'];
}
} }
return $interface_ip_arr_cache[$interface]; return $interface_ip_arr_cache[$interface];
...@@ -4794,16 +4621,14 @@ function find_interface_ipv6_ll($interface, $flush = false) { ...@@ -4794,16 +4621,14 @@ function find_interface_ipv6_ll($interface, $flush = false) {
function find_interface_subnet($interface, $flush = false) { function find_interface_subnet($interface, $flush = false) {
global $interface_sn_arr_cache; global $interface_sn_arr_cache;
global $interface_ip_arr_cache;
$interface = str_replace("\n", "", $interface); $interface = str_replace("\n", "", $interface);
if (does_interface_exist($interface) == false) if (does_interface_exist($interface) == false)
return; return;
if (!isset($interface_sn_arr_cache[$interface]) or $flush) { if (!isset($interface_sn_arr_cache[$interface]) || $flush) {
$ifinfo = pfSense_get_interface_addresses($interface); $ifinfo = pfSense_get_interface_addresses($interface);
if (isset($ifinfo['ipaddr'])) { if (isset($ifinfo['subnetbits'])) {
$interface_ip_arr_cache[$interface] = $ifinfo['ipaddr'];
$interface_sn_arr_cache[$interface] = $ifinfo['subnetbits']; $interface_sn_arr_cache[$interface] = $ifinfo['subnetbits'];
return $interface_sn_arr_cache[$interface]; return $interface_sn_arr_cache[$interface];
} }
...@@ -5047,72 +4872,7 @@ function is_interface_wireless($interface) ...@@ -5047,72 +4872,7 @@ function is_interface_wireless($interface)
return true; return true;
} }
function get_wireless_modes($interface) {
/* return wireless modes and channels */
$wireless_modes = array();
$cloned_interface = get_real_interface($interface);
if($cloned_interface && is_interface_wireless($cloned_interface)) {
$chan_list = "/sbin/ifconfig {$cloned_interface} list chan";
$stack_list = "/usr/bin/awk -F\"Channel \" '{ gsub(/\\*/, \" \"); print \$2 \"\\\n\" \$3 }'";
$format_list = "/usr/bin/awk '{print \$5 \" \" \$6 \",\" \$1}'";
$interface_channels = "";
exec("$chan_list | $stack_list | sort -u | $format_list 2>&1", $interface_channels);
$interface_channel_count = count($interface_channels);
$c = 0;
while ($c < $interface_channel_count) {
$channel_line = explode(",", $interface_channels["$c"]);
$wireless_mode = trim($channel_line[0]);
$wireless_channel = trim($channel_line[1]);
if(trim($wireless_mode) != "") {
/* if we only have 11g also set 11b channels */
if($wireless_mode == "11g") {
if(!isset($wireless_modes["11b"]))
$wireless_modes["11b"] = array();
} else if($wireless_mode == "11g ht") {
if(!isset($wireless_modes["11b"]))
$wireless_modes["11b"] = array();
if(!isset($wireless_modes["11g"]))
$wireless_modes["11g"] = array();
$wireless_mode = "11ng";
} else if($wireless_mode == "11a ht") {
if(!isset($wireless_modes["11a"]))
$wireless_modes["11a"] = array();
$wireless_mode = "11na";
}
$wireless_modes["$wireless_mode"]["$c"] = $wireless_channel;
}
$c++;
}
}
return($wireless_modes);
}
/* return channel numbers, frequency, max txpower, and max regulation txpower */
function get_wireless_channel_info($interface) {
$wireless_channels = array();
$cloned_interface = get_real_interface($interface);
if($cloned_interface && is_interface_wireless($cloned_interface)) {
$chan_list = "/sbin/ifconfig {$cloned_interface} list txpower";
$stack_list = "/usr/bin/awk -F\"Channel \" '{ gsub(/\\*/, \" \"); print \$2 \"\\\n\" \$3 }'";
$format_list = "/usr/bin/awk '{print \$1 \",\" \$3 \" \" \$4 \",\" \$5 \",\" \$7}'";
$interface_channels = "";
exec("$chan_list | $stack_list | sort -u | $format_list 2>&1", $interface_channels);
foreach ($interface_channels as $channel_line) {
$channel_line = explode(",", $channel_line);
if(!isset($wireless_channels[$channel_line[0]]))
$wireless_channels[$channel_line[0]] = $channel_line;
}
}
return($wireless_channels);
}
/****f* interfaces/get_interface_mtu /****f* interfaces/get_interface_mtu
* NAME * NAME
......
...@@ -43,6 +43,42 @@ function xmlrpc_publishable_legacy() ...@@ -43,6 +43,42 @@ function xmlrpc_publishable_legacy()
return $publish; return $publish;
} }
/*
* does_vip_exist($vip): return true or false if a vip is
* configured.
*/
function does_vip_exist($vip) {
global $config;
if(!$vip)
return false;
switch ($vip['mode']) {
case "carp":
case "ipalias":
/* XXX: Make proper checks? */
$realif = get_real_interface($vip['interface']);
if (!does_interface_exist($realif)) {
return false;
}
break;
case "proxyarp":
/* XXX: Implement this */
default:
return false;
}
$ifacedata = pfSense_getall_interface_addresses($realif);
foreach ($ifacedata as $vipips) {
if ($vipips == "{$vip['subnet']}/{$vip['subnet_bits']}")
return true;
}
return false;
}
/** /**
* @param null $category * @param null $category
* @return mixed * @return mixed
......
...@@ -30,6 +30,26 @@ ...@@ -30,6 +30,26 @@
require_once("guiconfig.inc"); require_once("guiconfig.inc");
require_once("globals.inc"); require_once("globals.inc");
function interfaces_carp_set_maintenancemode($carp_maintenancemode){
global $config;
if (isset($config["virtualip_carp_maintenancemode"]) && $carp_maintenancemode == false) {
unset($config["virtualip_carp_maintenancemode"]);
write_config("Leave CARP maintenance mode");
} else
if (!isset($config["virtualip_carp_maintenancemode"]) && $carp_maintenancemode == true) {
$config["virtualip_carp_maintenancemode"] = true;
write_config("Enter CARP maintenance mode");
}
$viparr = &$config['virtualip']['vip'];
foreach ($viparr as $vip) {
if ($vip['mode'] == "carp") {
interface_carp_configure($vip);
}
}
}
unset($interface_arr_cache); unset($interface_arr_cache);
unset($carp_interface_count_cache); unset($carp_interface_count_cache);
unset($interface_ip_arr_cache); unset($interface_ip_arr_cache);
......
...@@ -39,6 +39,74 @@ require_once("rrd.inc"); ...@@ -39,6 +39,74 @@ require_once("rrd.inc");
require_once("vpn.inc"); require_once("vpn.inc");
require_once("xmlparse_attr.inc"); require_once("xmlparse_attr.inc");
function get_wireless_modes($interface) {
/* return wireless modes and channels */
$wireless_modes = array();
$cloned_interface = get_real_interface($interface);
if($cloned_interface && is_interface_wireless($cloned_interface)) {
$chan_list = "/sbin/ifconfig {$cloned_interface} list chan";
$stack_list = "/usr/bin/awk -F\"Channel \" '{ gsub(/\\*/, \" \"); print \$2 \"\\\n\" \$3 }'";
$format_list = "/usr/bin/awk '{print \$5 \" \" \$6 \",\" \$1}'";
$interface_channels = "";
exec("$chan_list | $stack_list | sort -u | $format_list 2>&1", $interface_channels);
$interface_channel_count = count($interface_channels);
$c = 0;
while ($c < $interface_channel_count) {
$channel_line = explode(",", $interface_channels["$c"]);
$wireless_mode = trim($channel_line[0]);
$wireless_channel = trim($channel_line[1]);
if(trim($wireless_mode) != "") {
/* if we only have 11g also set 11b channels */
if($wireless_mode == "11g") {
if(!isset($wireless_modes["11b"]))
$wireless_modes["11b"] = array();
} else if($wireless_mode == "11g ht") {
if(!isset($wireless_modes["11b"]))
$wireless_modes["11b"] = array();
if(!isset($wireless_modes["11g"]))
$wireless_modes["11g"] = array();
$wireless_mode = "11ng";
} else if($wireless_mode == "11a ht") {
if(!isset($wireless_modes["11a"]))
$wireless_modes["11a"] = array();
$wireless_mode = "11na";
}
$wireless_modes["$wireless_mode"]["$c"] = $wireless_channel;
}
$c++;
}
}
return($wireless_modes);
}
/* return channel numbers, frequency, max txpower, and max regulation txpower */
function get_wireless_channel_info($interface) {
$wireless_channels = array();
$cloned_interface = get_real_interface($interface);
if($cloned_interface && is_interface_wireless($cloned_interface)) {
$chan_list = "/sbin/ifconfig {$cloned_interface} list txpower";
$stack_list = "/usr/bin/awk -F\"Channel \" '{ gsub(/\\*/, \" \"); print \$2 \"\\\n\" \$3 }'";
$format_list = "/usr/bin/awk '{print \$1 \",\" \$3 \" \" \$4 \",\" \$5 \",\" \$7}'";
$interface_channels = "";
exec("$chan_list | $stack_list | sort -u | $format_list 2>&1", $interface_channels);
foreach ($interface_channels as $channel_line) {
$channel_line = explode(",", $channel_line);
if(!isset($wireless_channels[$channel_line[0]]))
$wireless_channels[$channel_line[0]] = $channel_line;
}
}
return($wireless_channels);
}
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/interfaces.php'); $referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/interfaces.php');
// Get configured interface list // Get configured interface list
......
...@@ -34,6 +34,41 @@ require_once("functions.inc"); ...@@ -34,6 +34,41 @@ require_once("functions.inc");
require_once("filter.inc"); require_once("filter.inc");
require_once("rrd.inc"); require_once("rrd.inc");
/*
* find_ip_interface($ip): return the interface where an ip is defined
* (or if $bits is specified, where an IP within the subnet is defined)
*/
function find_ip_interface($ip, $bits = null) {
if (!is_ipaddr($ip))
return false;
$isv6ip = is_ipaddrv6($ip);
/* if list */
$ifdescrs = get_configured_interface_list();
foreach ($ifdescrs as $ifdescr => $ifname) {
$ifip = ($isv6ip) ? get_interface_ipv6($ifname) : get_interface_ip($ifname);
if (is_null($ifip))
continue;
if (is_null($bits)) {
if ($ip == $ifip) {
$int = get_real_interface($ifname);
return $int;
}
}
else {
if (ip_in_subnet($ifip, $ip . "/" . $bits)) {
$int = get_real_interface($ifname);
return $int;
}
}
}
return false;
}
global $g; global $g;
$stepid = htmlspecialchars($_GET['stepid']); $stepid = htmlspecialchars($_GET['stepid']);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment