示例#1
0
文件: nat.py 项目: maximerobin/Ufwi
def formatNetworks(resources, rule, chain, is_source):
    if is_source:
        networks = rule.sources
        filter_interface = (chain != u'POSTROUTING')
    else:
        networks = rule.destinations
        filter_interface = (chain != u'PREROUTING')

    items = []
    for network in flattenNetworkList(networks):
        args = Arguments()
        if filter_interface:
            if is_source:
                args += Arguments("-i", network.interface.name)
            else:
                args += Arguments("-o", network.interface.name)
        if network.hasAddresses():
            addresses = list(network.getAddresses())
            addresses.sort()
            for addr in addresses:
                if addr.version() != 4:
                    continue
                if is_source:
                    network_args = args + Arguments("-s", unicode(addr))
                else:
                    network_args = args + Arguments("-d", unicode(addr))
                items.append((network, network_args))
        else:
            items.append((network, args))
    return items
示例#2
0
文件: acls.py 项目: maximerobin/Ufwi
def formatNetworks(networks, prefix):
    items = []
    for network in flattenNetworkList(networks):
        if isinstance(network, InterfaceResource):
            items.append((None, None))
            continue
        addresses = list(network.getAddresses())
        addresses.sort()
        for address in addresses:
            arguments = Arguments(prefix, address)
            items.append((network, arguments))
    return items
示例#3
0
 def addressList(self, networks, address_type):
     for network in flattenNetworkList(networks):
         # no address: interface network
         if isinstance(network, InterfaceResource):
             if address_type == IPV6_ADDRESS:
                 yield INTERNET_IPV6
             else:
                 yield INTERNET_IPV4
         else:
             assert isinstance(network, (NetworkResource, HostResource, HostnameResource))
             addresses = list(network.getAddresses())
             addresses.sort()
             for address in addresses:
                 yield address