@@ -671,16 +671,6 @@ class xtables_target(ct.Union):
671671 ("v10" , _xtables_target_v10 )]
672672
673673
674- class xtables_afinfo (ct .Structure ):
675- _fields_ = [("kmod" , ct .c_char_p ),
676- ("proc_exists" , ct .c_char_p ),
677- ("libprefix" , ct .c_char_p ),
678- ("family" , ct .c_uint8 ),
679- ("ipproto" , ct .c_uint8 ),
680- ("so_rev_match" , ct .c_int ),
681- ("so_rev_target" , ct .c_int )]
682-
683-
684674class XTablesError (Exception ):
685675 """Raised when an xtables call fails for some reason."""
686676
@@ -766,7 +756,10 @@ class xtables(object):
766756 _xtables_find_target .restype = ct .POINTER (xtables_target )
767757 _xtables_find_target .argtypes = [ct .c_char_p , ct .c_int ]
768758
769- _xtables_afinfo = ct .c_void_p .in_dll (_lib_xtables , "afinfo" )
759+ _xtables_set_nfproto = _lib_xtables .xtables_set_nfproto
760+ _xtables_set_nfproto .restype = None
761+ _xtables_set_nfproto .argtypes = [ct .c_uint8 ]
762+
770763 _xtables_xt_params = ct .c_void_p .in_dll (_lib_xtables , "xt_params" )
771764 _xtables_matches = (ct .c_void_p .in_dll (_lib_xtables , "xtables_matches" ))
772765 _xtables_pending_matches = (ct .c_void_p .in_dll (_lib_xtables ,
@@ -808,7 +801,6 @@ def _xtinit(self, proto):
808801 self ._loaded_exts = []
809802
810803 # make sure we're initializing with clean state
811- self ._afinfo = ct .c_void_p (None ).value
812804 self ._xt_params = ct .c_void_p (None ).value
813805 self ._matches = ct .c_void_p (None ).value
814806 self ._pending_matches = ct .c_void_p (None ).value
@@ -827,8 +819,6 @@ def _save_globals(self):
827819 # Save our per-protocol libxtables global variables, and set them to
828820 # NULL so that we don't interfere with other protocols.
829821 null = ct .c_void_p (None )
830- self ._afinfo = xtables ._xtables_afinfo .value
831- xtables ._xtables_afinfo .value = null .value
832822 self ._xt_params = xtables ._xtables_xt_params .value
833823 xtables ._xtables_xt_params .value = null .value
834824 self ._matches = xtables ._xtables_matches .value
@@ -843,7 +833,7 @@ def _save_globals(self):
843833 def _restore_globals (self ):
844834 # Restore per-protocol libxtables global variables saved in
845835 # _save_globals().
846- xtables ._xtables_afinfo . value = self ._afinfo
836+ xtables ._xtables_set_nfproto ( self .proto )
847837 xtables ._xtables_xt_params .value = self ._xt_params
848838 xtables ._xtables_matches .value = self ._matches
849839 xtables ._xtables_pending_matches .value = self ._pending_matches
@@ -868,8 +858,7 @@ def _get_initfn_from_lib(self, name, lib):
868858 try :
869859 initfn = getattr (lib , "libxt_%s_init" % (name ))
870860 except AttributeError :
871- afinfo = ct .cast (self ._afinfo , ct .POINTER (xtables_afinfo ))
872- prefix = afinfo [0 ].libprefix
861+ prefix = self ._get_prefix ()
873862 initfn = getattr (lib , "%s%s_init" % (prefix , name ), None )
874863 return initfn
875864
@@ -885,11 +874,18 @@ def _try_extinit(self, name, lib):
885874 pass
886875 return False
887876
877+ def _get_prefix (self ):
878+ if self .proto == NFPROTO_IPV4 :
879+ return "libipt_"
880+ elif self .proto == NFPROTO_IPV6 :
881+ return "libip6t_"
882+ else :
883+ raise XTablesError ("Unknown protocol %d" % (self .proto ))
884+
888885 def _try_register (self , name ):
889886 if self ._try_extinit (name , _lib_xtables ):
890887 return
891- afinfo = ct .cast (self ._afinfo , ct .POINTER (xtables_afinfo ))
892- prefix = afinfo [0 ].libprefix
888+ prefix = self ._get_prefix ()
893889 libs = [os .path .join (_xtables_libdir , "libxt_" + name + ".so" ),
894890 os .path .join (_xtables_libdir , prefix + name + ".so" )]
895891 for lib in libs :
0 commit comments