# Path: capirca/lib/iptables.py
# class Term(aclgenerator.Term):
# class Iptables(aclgenerator.ACLGenerator):
# class Error(Exception):
# class BadPortsError(Error):
# class UnsupportedFilterError(Error):
# class NoIptablesPolicyError(Error):
# class TcpEstablishedError(Error):
# class EstablishedError(Error):
# class UnsupportedDefaultActionError(Error):
# class UnsupportedTargetOptionError(Error):
# class LimitButNoLogError(Error):
#   _PLATFORM = 'iptables'
#   _POSTJUMP_FORMAT = None
#   _PREJUMP_FORMAT = Template('-A $filter -j $term')
#   _TERM_FORMAT = Template('-N $term')
#   _COMMENT_FORMAT = Template('-A $term -m comment --comment "$comment"')
#   _FILTER_TOP_FORMAT = Template('-A $term')
#   _LOG_FORMAT = Template('-j LOG --log-prefix $term')
#   _PROTO_TABLE = {
#       'icmpv6': '-p ipv6-icmp',
#       'icmp': '-p icmp',
#       'tcp': '-p tcp',
#       'udp': '-p udp',
#       'all': '-p all',
#       'esp': '-p esp',
#       'ah': '-p ah',
#       'gre': '-p gre',
#       }
#   _TCP_FLAGS_TABLE = {
#       'syn': 'SYN',
#       'ack': 'ACK',
#       'fin': 'FIN',
#       'rst': 'RST',
#       'urg': 'URG',
#       'psh': 'PSH',
#       'all': 'ALL',
#       'none': 'NONE',
#       }
#   _KNOWN_OPTIONS_MATCHERS = {
#       # '! -f' also matches non-fragmented packets.
#       'first-fragment': '-m u32 --u32 4&0x3FFF=0x2000',
#       'initial': '--syn',
#       'tcp-initial': '--syn',
#       'sample': '',
#       }
#   _PLATFORM = 'iptables'
#   _DEFAULT_PROTOCOL = 'all'
#   SUFFIX = ''
#   _RENDER_PREFIX = None
#   _RENDER_SUFFIX = None
#   _DEFAULTACTION_FORMAT = '-P %s %s'
#   _DEFAULTACTION_FORMAT_CUSTOM_CHAIN = '-N %s'
#   _DEFAULT_ACTION = 'DROP'
#   _TERM = Term
#   _TERM_MAX_LENGTH = 24
#   _GOOD_FILTERS = ['INPUT', 'OUTPUT', 'FORWARD']
#   _GOOD_OPTIONS = ['nostate', 'abbreviateterms', 'truncateterms', 'noverbose']
#   def __init__(self, term, filter_name, trackstate, filter_action, af='inet',
#                verbose=True):
#   def __str__(self):
#   def _CalculateAddresses(self, term_saddr, exclude_saddr,
#                           term_daddr, exclude_daddr):
#   def _FormatPart(self, protocol, saddr, sport, daddr, dport, options,
#                   tcp_flags, icmp_type, code, track_flags, sint, dint, log_hits,
#                   action):
#   def _GenerateAddressStatement(self, saddr, daddr):
#   def _GeneratePortStatement(self, ports, source=False, dest=False):
#   def _SetDefaultAction(self):
#   def __init__(self, pol, exp_info):
#   def _BuildTokens(self):
#   def _WarnIfCustomTarget(self, target):
#   def _TranslatePolicy(self, pol, exp_info):
#   def SetTarget(self, target, action=None):
#   def __str__(self):
# 
# Path: capirca/lib/nacaddr.py
# def IP(ip, comment='', token='', strict=True):
# def _is_subnet_of(a, b):  # pylint: disable=invalid-name
#   def __init__(self, ip_string, comment='', token='', strict=True):
#   def subnet_of(self, other):
#   def supernet_of(self, other):
#   def __deepcopy__(self, memo):
#   def AddComment(self, comment=''):
#   def supernet(self, prefixlen_diff=1):
#   def __init__(self, ip_string, comment='', token='', strict=True):
#   def subnet_of(self, other):
#   def supernet_of(self, other):
#   def __deepcopy__(self, memo):
#   def supernet(self, prefixlen_diff=1):
#   def AddComment(self, comment=''):
# def _InNetList(adders, ip):
# def IsSuperNet(supernets, subnets):
# def CollapseAddrListPreserveTokens(addresses):
# def _SafeToMerge(address, merge_target, check_addresses):
# def _CollapseAddrListInternal(addresses, complements_by_network):
# def CollapseAddrList(addresses, complement_addresses=None):
# def SortAddrList(addresses):
# def RemoveAddressFromList(superset, exclude):
# def AddressListExclude(superset, excludes, collapse_addrs=True):
# class IPv4(ipaddress.IPv4Network):
# class IPv6(ipaddress.IPv6Network):
# class PrefixlenDiffInvalidError(ipaddress.NetmaskValueError):


import string
from capirca.lib import iptables
from capirca.lib import nacaddr

    """
    src_addr_stmt = ''
    dst_addr_stmt = ''
    if src_addr and dst_addr:
      if src_addr == self._all_ips:
        if 'src' in self.addr_sets:
          src_addr_stmt = ('-m set --match-set %s src' %
                           self.addr_sets['src'][0])
      else:
        src_addr_stmt = '-s %s/%d' % (src_addr.network_address,
                                      src_addr.prefixlen)
      if dst_addr == self._all_ips:
        if 'dst' in self.addr_sets:
          dst_addr_stmt = ('-m set --match-set %s dst' %
                           self.addr_sets['dst'][0])
      else:
        dst_addr_stmt = '-d %s/%d' % (dst_addr.network_address,
                                      dst_addr.prefixlen)
    return (src_addr_stmt, dst_addr_stmt)

  def _GenerateSetName(self, term_name, suffix):
    if self.af == 'inet6':
      suffix += '-v6'
    if len(term_name) + len(suffix) + 1 > self._SET_MAX_LENGTH:
      set_name_max_lenth = self._SET_MAX_LENGTH - len(suffix) - 1
      term_name = term_name[:set_name_max_lenth]
    return '%s-%s' % (term_name, suffix)



# Path: capirca/lib/iptables.py
# class Term(aclgenerator.Term):
# class Iptables(aclgenerator.ACLGenerator):
# class Error(Exception):
# class BadPortsError(Error):
# class UnsupportedFilterError(Error):
# class NoIptablesPolicyError(Error):
# class TcpEstablishedError(Error):
# class EstablishedError(Error):
# class UnsupportedDefaultActionError(Error):
# class UnsupportedTargetOptionError(Error):
# class LimitButNoLogError(Error):
#   _PLATFORM = 'iptables'
#   _POSTJUMP_FORMAT = None
#   _PREJUMP_FORMAT = Template('-A $filter -j $term')
#   _TERM_FORMAT = Template('-N $term')
#   _COMMENT_FORMAT = Template('-A $term -m comment --comment "$comment"')
#   _FILTER_TOP_FORMAT = Template('-A $term')
#   _LOG_FORMAT = Template('-j LOG --log-prefix $term')
#   _PROTO_TABLE = {
#       'icmpv6': '-p ipv6-icmp',
#       'icmp': '-p icmp',
#       'tcp': '-p tcp',
#       'udp': '-p udp',
#       'all': '-p all',
#       'esp': '-p esp',
#       'ah': '-p ah',
#       'gre': '-p gre',
#       }
#   _TCP_FLAGS_TABLE = {
#       'syn': 'SYN',
#       'ack': 'ACK',
#       'fin': 'FIN',
#       'rst': 'RST',
#       'urg': 'URG',
#       'psh': 'PSH',
#       'all': 'ALL',
#       'none': 'NONE',
#       }
#   _KNOWN_OPTIONS_MATCHERS = {
#       # '! -f' also matches non-fragmented packets.
#       'first-fragment': '-m u32 --u32 4&0x3FFF=0x2000',
#       'initial': '--syn',
#       'tcp-initial': '--syn',
#       'sample': '',
#       }
#   _PLATFORM = 'iptables'
#   _DEFAULT_PROTOCOL = 'all'
#   SUFFIX = ''
#   _RENDER_PREFIX = None
#   _RENDER_SUFFIX = None
#   _DEFAULTACTION_FORMAT = '-P %s %s'
#   _DEFAULTACTION_FORMAT_CUSTOM_CHAIN = '-N %s'
#   _DEFAULT_ACTION = 'DROP'
#   _TERM = Term
#   _TERM_MAX_LENGTH = 24
#   _GOOD_FILTERS = ['INPUT', 'OUTPUT', 'FORWARD']
#   _GOOD_OPTIONS = ['nostate', 'abbreviateterms', 'truncateterms', 'noverbose']
#   def __init__(self, term, filter_name, trackstate, filter_action, af='inet',
#                verbose=True):
#   def __str__(self):
#   def _CalculateAddresses(self, term_saddr, exclude_saddr,
#                           term_daddr, exclude_daddr):
#   def _FormatPart(self, protocol, saddr, sport, daddr, dport, options,
#                   tcp_flags, icmp_type, code, track_flags, sint, dint, log_hits,
#                   action):
#   def _GenerateAddressStatement(self, saddr, daddr):
#   def _GeneratePortStatement(self, ports, source=False, dest=False):
#   def _SetDefaultAction(self):
#   def __init__(self, pol, exp_info):
#   def _BuildTokens(self):
#   def _WarnIfCustomTarget(self, target):
#   def _TranslatePolicy(self, pol, exp_info):
#   def SetTarget(self, target, action=None):
#   def __str__(self):
# 
# Path: capirca/lib/nacaddr.py
# def IP(ip, comment='', token='', strict=True):
# def _is_subnet_of(a, b):  # pylint: disable=invalid-name
#   def __init__(self, ip_string, comment='', token='', strict=True):
#   def subnet_of(self, other):
#   def supernet_of(self, other):
#   def __deepcopy__(self, memo):
#   def AddComment(self, comment=''):
#   def supernet(self, prefixlen_diff=1):
#   def __init__(self, ip_string, comment='', token='', strict=True):
#   def subnet_of(self, other):
#   def supernet_of(self, other):
#   def __deepcopy__(self, memo):
#   def supernet(self, prefixlen_diff=1):
#   def AddComment(self, comment=''):
# def _InNetList(adders, ip):
# def IsSuperNet(supernets, subnets):
# def CollapseAddrListPreserveTokens(addresses):
# def _SafeToMerge(address, merge_target, check_addresses):
# def _CollapseAddrListInternal(addresses, complements_by_network):
# def CollapseAddrList(addresses, complement_addresses=None):
# def SortAddrList(addresses):
# def RemoveAddressFromList(superset, exclude):
# def AddressListExclude(superset, excludes, collapse_addrs=True):
# class IPv4(ipaddress.IPv4Network):
# class IPv6(ipaddress.IPv6Network):
# class PrefixlenDiffInvalidError(ipaddress.NetmaskValueError):


# Path: capirca/lib/ipset.py
import string
from capirca.lib import iptables
from capirca.lib import nacaddr


    """
    src_addr_stmt = ''
    dst_addr_stmt = ''
    if src_addr and dst_addr:
      if src_addr == self._all_ips:
        if 'src' in self.addr_sets:
          src_addr_stmt = ('-m set --match-set %s src' %
                           self.addr_sets['src'][0])
      else:
        src_addr_stmt = '-s %s/%d' % (src_addr.network_address,
                                      src_addr.prefixlen)
      if dst_addr == self._all_ips:
        if 'dst' in self.addr_sets:
          dst_addr_stmt = ('-m set --match-set %s dst' %
                           self.addr_sets['dst'][0])
      else:
        dst_addr_stmt = '-d %s/%d' % (dst_addr.network_address,
                                      dst_addr.prefixlen)
    return (src_addr_stmt, dst_addr_stmt)

  def _GenerateSetName(self, term_name, suffix):
    if self.af == 'inet6':
      suffix += '-v6'
    if len(term_name) + len(suffix) + 1 > self._SET_MAX_LENGTH:
      set_name_max_lenth = self._SET_MAX_LENGTH - len(suffix) - 1
      term_name = term_name[:set_name_max_lenth]
    return '%s-%s' % (term_name, suffix)



class Ipset(iptables.Iptables):