@@ -544,35 +544,21 @@ def __init__(self, rule, name=None, target=None, revision=None):
544544
545545 self ._xt = xtables (rule .nfproto )
546546
547- is_standard_target = False
548- module = None
549- for t in rule .tables :
550- if t .is_chain (name ):
551- is_standard_target = True
552- module = self ._xt .find_target ('standard' )
553-
547+ module = (self ._is_standard_target () and
548+ self ._xt .find_target ('standard' ) or
549+ self ._xt .find_target (name ))
554550 if not module :
555- module = self ._xt .find_target (name )
556- if not module :
557- raise XTablesError ("can't find target %s" % (name ))
551+ raise XTablesError ("can't find target %s" % (name ))
558552 self ._module = module [0 ]
559553 self ._module .tflags = 0
560554 if revision is not None :
561555 self ._revision = revision
562556 else :
563557 self ._revision = self ._module .revision
564558
565- self ._target_buf = _malloc (self .size )
566- if self ._target_buf is None :
567- raise Exception ("Can't allocate target buffer" )
568- if target :
569- ct .memmove (self ._target_buf , ct .byref (target ), self .size )
570- self ._update_pointers ()
571- self ._update_parameters ()
572- else :
573- self .reset ()
559+ self ._allocate_buffer (target )
574560
575- if is_standard_target :
561+ if self . _is_standard_target () :
576562 self .standard_target = name
577563
578564 def __del__ (self ):
@@ -600,6 +586,23 @@ def __eq__(self, targ):
600586 def __ne__ (self , rule ):
601587 return not self .__eq__ (rule )
602588
589+ def _allocate_buffer (self , target ):
590+ self ._target_buf = _malloc (self .size )
591+ if self ._target_buf is None :
592+ raise Exception ("Can't allocate target buffer" )
593+ if target :
594+ ct .memmove (self ._target_buf , ct .byref (target ), self .size )
595+ self ._update_pointers ()
596+ self ._update_parameters ()
597+ else :
598+ self .reset ()
599+
600+ def _is_standard_target (self ):
601+ for t in self ._rule .tables :
602+ if t .is_chain (self ._name ):
603+ return True
604+ return False
605+
603606 def _final_check (self ):
604607 self ._xt .final_check_target (self ._module )
605608
0 commit comments