示例#1
0
 def get_policy(self, chain):
     """Returns the policy of *chain* as a string."""
     if isinstance(chain, Chain):
         chain = chain.name
     if not self.builtin_chain(chain):
         return None, None
     cntrs = xt_counters()
     pol = self._iptc.iptc_get_policy(chain, ct.pointer(cntrs), self._handle)
     if not pol:
         raise IPTCError("can't get policy on chain %s: %s" % (chain,
             self.strerror()))
     return Policy(pol), (cntrs.pcnt, cntrs.bcnt)
示例#2
0
 def get_policy(self, chain):
     """Returns the policy of *chain* as a string."""
     if isinstance(chain, Chain):
         chain = chain.name
     if not self.builtin_chain(chain):
         return None, None
     cntrs = xt_counters()
     pol = self._iptc.iptc_get_policy(chain, ct.pointer(cntrs),
                                      self._handle)
     if not pol:
         raise IPTCError("can't get policy on chain %s: %s" %
                         (chain, self.strerror()))
     return Policy(pol), (cntrs.pcnt, cntrs.bcnt)
示例#3
0
 def set_policy(self, chain, policy, counters = None):
     """Set the policy of *chain* to *policy*, and also update chain
     counters if *counters* is specified."""
     if isinstance(chain, Chain):
         chain = chain.name
     if isinstance(policy, Policy):
         policy = policy.name
     if counters:
         cntrs = xt_counters()
         cntrs.pcnt = counters[0]
         cntrs.bcnt = counters[1]
         cntrs = ct.pointer(cntrs)
     else:
         cntrs = None
     rv = self._iptc.iptc_set_policy(chain, policy, cntrs, self._handle)
     if rv != 1:
         raise IPTCError("can't set policy %s on chain %s: %s)" % (policy,
             chain, self.strerror()))
示例#4
0
 def set_policy(self, chain, policy, counters=None):
     """Set the policy of *chain* to *policy*, and also update chain
     counters if *counters* is specified."""
     if isinstance(chain, Chain):
         chain = chain.name
     if isinstance(policy, Policy):
         policy = policy.name
     if counters:
         cntrs = xt_counters()
         cntrs.pcnt = counters[0]
         cntrs.bcnt = counters[1]
         cntrs = ct.pointer(cntrs)
     else:
         cntrs = None
     rv = self._iptc.iptc_set_policy(chain, policy, cntrs, self._handle)
     if rv != 1:
         raise IPTCError("can't set policy %s on chain %s: %s)" %
                         (policy, chain, self.strerror()))