java.lang.Object
com.aoindustries.firewalld.Service

public class Service extends Object
Represents on specific service as configured in either /usr/lib/firewalld/services/service.xml or /etc/firewalld/services/service.xml.

See man 5 firewalld.service for details.

Author:
AO Industries, Inc.
  • Field Details

    • LOCAL_SERVICES_DIRECTORY

      public static final String LOCAL_SERVICES_DIRECTORY
      The directory containing local service files.
      See Also:
    • SYSTEM_SERVICES_DIRECTORY

      public static final String SYSTEM_SERVICES_DIRECTORY
      The directory containing system service files.
      See Also:
    • EXTENSION

      public static final String EXTENSION
      File extension used on service XML files.
      See Also:
  • Constructor Details

  • Method Details

    • loadService

      public static Service loadService(String name, InputStream in) throws IOException
      Loads a service from an InputStream.
      Throws:
      IOException - when cannot read or parse the service file
    • loadService

      public static Service loadService(String name, File file) throws IOException
      Loads a service from the given File.
      Returns:
      The Service or null if the service file does not exist.
      Throws:
      IOException - when cannot read or parse the service file
    • getLocalServiceFile

      public static File getLocalServiceFile(String name)
      Gets the file to use for local service.
    • loadLocalService

      public static Service loadLocalService(String name) throws IOException
      Loads a local service from LOCAL_SERVICES_DIRECTORY.
      Returns:
      The Service or null if the service file does not exist.
      Throws:
      IOException - when cannot read or parse the service file
    • getSystemServiceFile

      public static File getSystemServiceFile(String name)
      Gets the file to use for system service.
    • loadSystemService

      public static Service loadSystemService(String name) throws IOException
      Loads a system service from SYSTEM_SERVICES_DIRECTORY.
      Returns:
      The Service or null if the service file does not exist.
      Throws:
      IOException - when cannot read or parse the service file
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      Compares two services for equality. All fields must be equal, with ordering not mattering for sets.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getName

      public String getName()
      The name as used by firewalld commands and XML filenames.
    • getVersion

      public String getVersion()
      The optional version.
    • getShortName

      public String getShortName()
      The optional more readable short name.
    • getDescription

      public String getDescription()
      The optional longer description.
    • getPorts

      public Set<IPortRange> getPorts()
      The optional set of ports. When no ports will be an empty set.
      Returns:
      an unmodifiable set of ports
    • getProtocols

      public Set<Protocol> getProtocols()
      The optional set of protocols. When no protocols will be an empty set.
      Returns:
      an unmodifiable set of protocols
    • getSourcePorts

      public Set<IPortRange> getSourcePorts()
      The optional set of source ports. When no source ports will be an empty set.
      Returns:
      an unmodifiable set of source ports
    • getModules

      public Set<String> getModules()
      The optional set of modules. When no modules will be an empty set.
      Returns:
      an unmodifiable set of modules
    • getDestinationIpv4

      public InetAddressPrefix getDestinationIpv4()
      The optional IPv4 destination network.
      Returns:
      the IPv4 address and prefix or null for no IPv4 destination.
      See Also:
    • getDestinationIPv4

      @Deprecated public final InetAddressPrefix getDestinationIPv4()
      Deprecated.
      Please use getDestinationIpv4() instead.
      The optional IPv4 destination network.
      Returns:
      the IPv4 address and prefix or null for no IPv4 destination.
      See Also:
    • getDestinationIpv6

      public InetAddressPrefix getDestinationIpv6()
      The optional IPv6 destination network.
      Returns:
      the IPv6 address and prefix or null for no IPv6 destination.
      See Also:
    • getDestinationIPv6

      @Deprecated public final InetAddressPrefix getDestinationIPv6()
      Deprecated.
      Please use getDestinationIpv6() instead.
      The optional IPv6 destination network.
      Returns:
      the IPv6 address and prefix or null for no IPv6 destination.
      See Also:
    • getDestination

      @Deprecated public InetAddressPrefix getDestination(AddressFamily addressFamily)
      Deprecated.
      Please use getDestination(java.net.ProtocolFamily) as of Java 1.7.
      Gets the destination for the given AddressFamily.
    • getDestination

      public InetAddressPrefix getDestination(ProtocolFamily family)
      Gets the destination for the given ProtocolFamily.
    • getTargets

      public SortedSet<Target> getTargets()
      Gets the set of all targets represented by this service. This may be an empty set when a service is modules-only (like tftp-client).

      This may have overlapping targets if the service was not previously optimized.

      See Also:
    • saveLocalService

      public void saveLocalService() throws IOException
      Write this service to its local service file.
      Throws:
      IOException