Skip to content

Commit

Permalink
Refactoring on opening services in the installation proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
kobliha committed Aug 16, 2012
1 parent 795af48 commit b51c19e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 35 deletions.
5 changes: 5 additions & 0 deletions library/network/src/SuSEFirewall.ycp
Original file line number Diff line number Diff line change
Expand Up @@ -1440,6 +1440,11 @@
if (IsInterfaceInZone(interface, zone)) interface_zone = add (interface_zone, zone);
});

// Fallback handling for 'any' in the FW_DEV_* configuration
if (interface == special_all_interface_string && size(interface_zone) == 0) {
interface_zone = [special_all_interface_zone];
}

if (IsVerbose() && size(interface_zone) > 1) {
// TRANSLATORS: Error message, %1 = interface name (like eth0)
Report::Error(sformat(_("Interface '%1' is included in multiple firewall zones.
Expand Down
63 changes: 28 additions & 35 deletions library/network/src/SuSEFirewallProposal.ycp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,30 @@
});
}

/**
* Function opens service for network interfaces given as the third parameter.
* Fallback ports are used if the given service is uknown.
*
* @see OpenServiceOnNonDialUpInterfaces for more info.
*
* @param string service, e.g., "service:http-server"
* @param list <string> fallback_ports, e.g., "80"
* @param list <string> interfaces, e.g., "eth3"
*/
define void OpenServiceInInterfaces(string service, list <string> fallback_ports, list <string> interfaces) {
list <string> zones = SuSEFirewall::GetZonesOfInterfaces(interfaces);

if (SuSEFirewallServices::IsKnownService (service)) {
y2milestone("Opening service %1 on interfaces %2 (zones %3)",
service, interfaces, zones);
SuSEFirewall::SetServicesForZones([service], zones, true);
}

if (SuSEFirewallServices::IsKnownService (service) != true || ServiceEnabled (service, interfaces) != true) {
EnableFallbackPorts (fallback_ports, interfaces);
}
}

/**
* Function opens up the service on all non-dial-up network interfaces.
* If there are no network interfaces known and the 'any' feature is supported,
Expand All @@ -224,46 +248,15 @@

// Opening the service for non-dial-up interfaces
if (size(non_dial_up_interfaces)>0) {
list <string> non_dial_up_interfaces_zones = SuSEFirewall::GetZonesOfInterfaces(non_dial_up_interfaces);

if (SuSEFirewallServices::IsKnownService (service)) {
y2milestone("Opening service %1 on interfaces %2 (zones %3)",
service, non_dial_up_interfaces, non_dial_up_interfaces_zones);
SuSEFirewall::SetServicesForZones([service], non_dial_up_interfaces_zones, true);
}

if (SuSEFirewallServices::IsKnownService (service) != true || ServiceEnabled (service, non_dial_up_interfaces_zones) != true) {
EnableFallbackPorts (fallback_ports, non_dial_up_interfaces_zones);
}

OpenServiceInInterfaces(service, fallback_ports, non_dial_up_interfaces);
// Only dial-up network interfaces, there mustn't be any non-dial-up one
} else if (size(dial_up_interfaces) > 0) {
list <string> dial_up_interfaces_zones = SuSEFirewall::GetZonesOfInterfaces(dial_up_interfaces);

if (SuSEFirewallServices::IsKnownService (service)) {
y2warning("Opening service %1 on interfaces %2 (zones %3)",
service, dial_up_interfaces, dial_up_interfaces_zones);
SuSEFirewall::SetServicesForZones([service], dial_up_interfaces_zones, true);
}

if (SuSEFirewallServices::IsKnownService (service) != true || ServiceEnabled (service, dial_up_interfaces) != true) {
EnableFallbackPorts (fallback_ports, dial_up_interfaces);
}

OpenServiceInInterfaces(service, fallback_ports, dial_up_interfaces);
// No network interfaces are known
} else if (size(known_interfaces) == 0) {
if (SuSEFirewall::IsAnyNetworkInterfaceSupported() == true) {
if (SuSEFirewallServices::IsKnownService (service) == true) {
y2warning("WARNING: Opening %1 for the External zone without any known interface!", toupper(service));
SuSEFirewall::SetServicesForZones([service], [SuSEFirewall::special_all_interface_zone], true);
y2milestone("By now, %1 for %2 zone is %3",
service,
SuSEFirewall::special_all_interface_zone,
SuSEFirewall::IsServiceSupportedInZone (service, SuSEFirewall::special_all_interface_zone)
);
} else {
EnableFallbackPorts (fallback_ports, [SuSEFirewall::special_all_interface_zone]);
}
y2warning("WARNING: Opening %1 for the External zone without any known interface!", toupper(service));
OpenServiceInInterfaces(service, fallback_ports, [SuSEFirewall::special_all_interface_string]);
}
}
}
Expand Down

0 comments on commit b51c19e

Please sign in to comment.