
Zc           @   st  d  d l  Z d  d l Z d  d l Z d  d l Z d d l m Z d d l m Z d Z	 d Z
 d Z d Z d	 Z d
 Z d Z d Z d Z d Z d Z d Z dg Z dh Z di Z dj Z dk Z e j e j  Z d Z d   Z d e j f d     YZ  d e j f d     YZ! d e j" f d     YZ# d e j f d     YZ$ d e j f d     YZ% d e j" f d     YZ& d e j f d     YZ' d e j f d     YZ( d  e j f d!     YZ) d" e j f d#     YZ* d$ e j" f d%     YZ+ d& e j" f d'     YZ, d( e j f d)     YZ- d* e j f d+     YZ. d, e j f d-     YZ/ d. e j" f d/     YZ0 d0 e j f d1     YZ1 d2 e j f d3     YZ2 d4 e j f d5     YZ3 e3 Z4 e3 Z5 e3 Z6 d6 e j f d7     YZ7 d8 e j f d9     YZ8 d: e j f d;     YZ9 d< e j f d=     YZ: e: Z; d> e j f d?     YZ< d@ e j" f dA     YZ= dB e j f dC     YZ> e> Z? e> Z@ e> ZA dD e j f dE     YZB dF e j f dG     YZC dH e j f dI     YZD dJ e j f dK     YZE eE ZF dL e j f dM     YZG dN e j" f dO     YZH dP eI f dQ     YZJ e dR  \ ZK ZL e j jM eK dS  ZN e jO jM eK dT  ZP e jQ dU  ZR eR rdV eR f ZS n dW ZS e eS  \ ZT ZR e jQ dX  ZU eU d k rxE dY dZ d[ d\ d] d^ d_ d` g D]" ZW e jX jY eW  reW ZU PqqWn  eU d k r4eJ da   n  e db  \ ZZ ZL eZ j[ Z\ eZ j] Z^ e j_ e^ _` e ja e j_ e jb e jO  e j_ e jb e jc  e ja e jb e ja  g e^ _d eZ je Zf e ja ef _` e ja e ja e ja g ef _d eZ jg Zh e j_ eh _` e ja e jc g eh _d eZ ji Zj e j_ ej _` e ja g ej _d eZ jk Zl e j_ el _` e ja e ja g el _d e j_ jM eZ dc  Zm eZ jn Zo eo   dd   Zp e jq d e j_ e jO  Zr er ep  Zp de   Zs e(   Zt d et _u e jv jw   et _x e jy jw   et _z d et _{ d et _| ep et _} eR d
 k rTe jq e j_ e jO e j~ e j_  Z e eT j  Z e et _ n  i  Z dW e f df     YZ d S(l   iNi   (   t   version(   t   find_libraryi@   i    i   i   i   i
   i   i   i   i   c         C   s   |  t  d t  d @S(   Ni   (   t   _WORDLEN(   t   sz(    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyt   xt_align%   s    t   xt_countersc           B   s,   e  Z d  Z d e j f d e j f g Z RS(   s;   This class is a representation of the C struct xt_counters.t   pcntt   bcnt(   t   __name__t
   __module__t   __doc__t   ctt   c_uint64t   _fields_(    (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyR   )   s   t   xt_entry_target_userc           B   s:   e  Z d  e j f d e j e d f d e j f g Z RS(   t   target_sizet   namei   t   revision(   R   R	   R   t   c_uint16t   c_chart   _XT_FUNCTION_MAXNAMELENt   c_uint8R   (    (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyR   /   s   t   xt_entry_target_uc           B   s#   e  Z d  e f d e j f g Z RS(   t   userR   (   R   R	   R   R   R   R   (    (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyR   5   s   	t   xt_entry_targetc           B   s-   e  Z d  Z d e f d e j d f g Z RS(   s?   This class is a representation of the C struct xt_entry_target.t   ut   datai    (   R   R	   R
   R   R   t   c_ubyteR   (    (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyR   :   s   	t   xt_entry_match_userc           B   s:   e  Z d  e j f d e j e d f d e j f g Z RS(   t
   match_sizeR   i   R   (   R   R	   R   R   R   R   R   R   (    (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyR   @   s   t   xt_entry_match_uc           B   s#   e  Z d  e f d e j f g Z RS(   R   R   (   R   R	   R   R   R   R   (    (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyR   F   s   	t   xt_entry_matchc           B   s-   e  Z d  Z d e f d e j d f g Z RS(   s>   This class is a representation of the C struct xt_entry_match.R   R   i    (   R   R	   R
   R   R   R   R   (    (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyR   K   s   	t   xtables_globalsc           B   s   e  Z d  e j f d e j f d e j f d e j f d e j f d e j d e j e j  f d e j e j e j e j	 e j  f g Z
 RS(   t   option_offsett   program_namet   program_versiont	   orig_optst   optst   exit_errt
   compat_revN(   R   R	   R   t   c_uintt   c_char_pt   c_void_pt	   CFUNCTYPEt   Nonet   c_intR   R   (    (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyR    Q   s   t   optionc           B   sG   e  Z d  e j f d e j f d e j e j  f d e j f g Z RS(   R   t   has_argt   flagt   val(   R   R	   R   R)   R-   t   POINTERR   (    (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyR.   ]   s   t   xt_option_entryc           B   s   e  Z d  e j f d e j f d e j f d e j f d e j f d e j f d e j f d e j f d e j f d	 e j f g
 Z RS(
   R   t   typet   idt   exclt   alsot   flagst   ptrofft   sizet   mint   max(   R   R	   R   R)   R-   R(   t   c_size_tR   (    (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyR3   d   s   t   _U1c           B   sD   e  Z d  e j e j e   f d e j e j e   f g Z RS(   t   matcht   target(   R   R	   R   R2   R   R   R   (    (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyR>   q   s   t   nf_inet_addrc           B   sV   e  Z d  e j d f d e j f d e j d f d e j f d e j d f g Z RS(   t   alli   t   ipt   ip6t   int   in6i   (   R   R	   R   t   c_uint32R   R   (    (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyRA   v   s
   t   _S1c           B   s,   e  Z d  e f d e f d e j f g Z RS(   t   haddrt   hmaskt   hlen(   R   R	   RA   R   R   R   (    (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyRH   ~   s   		t   _S2c           B   s&   e  Z d  e j f d e j f g Z RS(   t	   tos_valuet   tos_mask(   R   R	   R   R   R   (    (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyRL      s   t   _S3c           B   s&   e  Z d  e j f d e j f g Z RS(   t   markt   mask(   R   R	   R   RG   R   (    (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyRO      s   t   _U_valc           B   s   e  Z d Z d e j f d e j d f d e j f d e j f d e j f d	 e j d f d
 e j f d e j d f d e j f d e j d f d e j f d e j d f d e j f d  e	 f d e
 f d e f d e j d f g Z RS(   t   s1t   s2t   s3t   u8t   u8_rangei   t   syslog_levelt   protocolt   u16t	   u16_ranget   portt
   port_ranget   u32t	   u32_ranget   u64t	   u64_ranget   doublet   ethermaci   (   RS   RT   RU   (   R   R	   t   _anonymous_R   R   R   RG   R   t   c_doubleRH   RL   RO   R   (    (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyRR      s$   			t   xt_option_callc           B   s   e  Z d Z d e j f d e j f d e j e  f d e j f d e j f d e j	 f d e j	 f d e
 f d  e f d	 e j f d
 e j f g Z RS(   R   t   argt   ext_namet   entryR   t   xflagst   invertt   nvalsR1   t   xt_entryt   udata(   R   (   R   R	   Rd   R   R)   R2   R3   R*   R(   R   RR   R>   R   (    (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyRf      s   		t   xt_fcheck_callc           B   s>   e  Z d  e j f d e j f d e j f d e j f g Z RS(   Rh   R   Rn   Rj   (   R   R	   R   R)   R*   R(   R   (    (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyRo      s   t   _xtables_match_v1c           B   s  e  Z d  e j f d e j f d e j f d e j f d e j f d e j f d e j f d e j d  f d e j d e j
 e   f d	 e j e j e j e j
 e j  e j e j
 e j  e j e j
 e j
 e    f d
 e j d e j  f d e j d e j e j
 e  e j  f d e j d e j e j
 e   f d e j
 e  f d e j f d e j
 e  f d e j f d e j f g Z d Z d Z d Z RS(   R    t   nextR   R   t   familyR:   t   userspacesizet   helpt   initt   parset   final_checkt   printt   savet
   extra_optsR!   t   mt   mflagst   loadedN(   R   R	   R   R)   R*   R   R   R=   R+   R,   R2   R   R-   R(   R.   R   t   x6_parset	   x6_fcheckt
   x6_options(    (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyRp      s6   t   _xtables_match_v6c           B   s  e  Z d  e j f d e j f d e j f d e j f d e j f d e j f d e j f d e j d  f d e j d e j
 e   f d	 e j e j e j e j
 e j  e j e j
 e j  e j e j
 e j
 e    f d
 e j d e j  f d e j d e j e j
 e  e j  f d e j d e j e j
 e   f d e j
 e  f d e j d e j
 e   f d e j d e j
 e   f d e j
 e  f d e j f d e j
 e  f d e j f d e j f g Z RS(   R    Rq   R   R   Rr   R:   Rs   Rt   Ru   Rv   Rw   Rx   Ry   Rz   R~   R   R   R!   R{   R|   R}   N(   R   R	   R   R)   R*   R   R   R=   R+   R,   R2   R   R-   R(   R.   Rf   Ro   R3   R   (    (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyR      s6   t   _xtables_match_v7c           B   s   e  Z d  e j f d e j f d e j f d e j f d e j f d e j f d e j f d e j d  f d e j d e j
 e   f d	 e j e j e j e j
 e j  e j e j
 e j  e j e j
 e j
 e    f d
 e j d e j  f d e j d e j e j
 e  e j  f d e j d e j e j
 e   f d e j
 e  f d e j d e j
 e   f d e j d e j
 e   f d e j
 e  f d e j f d e j f d e j f d e j
 e  f d e j f d e j f g Z RS(   R    Rq   R   R   Rr   R:   Rs   Rt   Ru   Rv   Rw   Rx   Ry   Rz   R~   R   R   t
   udata_sizeRn   R!   R{   R|   R}   N(   R   R	   R   R)   R*   R   R   R=   R+   R,   R2   R   R-   R(   R.   Rf   Ro   R3   R   (    (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyR     s:   t   _xtables_match_v9c           B   s  e  Z d  e j f d e j f d e j f d e j f d e j f d e j f d e j f d e j f d e j d  f d	 e j d e j
 e   f d
 e j e j e j e j
 e j  e j e j
 e j  e j e j
 e j
 e    f d e j d e j  f d e j d e j e j
 e  e j  f d e j d e j e j
 e   f d e j
 e  f d e j d e j
 e   f d e j d e j
 e   f d e j
 e  f d e j f d e j f d e j f d e j
 e  f d e j f d e j f g Z RS(   R    Rq   R   t	   real_nameR   Rr   R:   Rs   Rt   Ru   Rv   Rw   Rx   Ry   Rz   R~   R   R   R   Rn   R!   R{   R|   R}   N(   R   R	   R   R)   R*   R   R   R=   R+   R,   R2   R   R-   R(   R.   Rf   Ro   R3   R   (    (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyR   ;  s<   t   _xtables_match_v10c           B   s9  e  Z d  e j f d e j f d e j f d e j f d e j f d e j f d e j f d e j f d e j f d	 e j d  f d
 e j d e j
 e   f d e j e j e j e j
 e j  e j e j
 e j  e j e j
 e j
 e    f d e j d e j  f d e j d e j e j
 e  e j  f d e j d e j e j
 e   f d e j e j e j
 e   f d e j
 e  f d e j d e j
 e   f d e j d e j
 e   f d e j
 e  f d e j f d e j f d e j f d e j
 e  f d e j f d e j f g Z RS(   R    Rq   R   R   R   t	   ext_flagsRr   R:   Rs   Rt   Ru   Rv   Rw   Rx   Ry   t   aliasRz   R~   R   R   R   Rn   R!   R{   R|   R}   N(   R   R	   R   R)   R*   R   R   R=   R+   R,   R2   R   R-   R(   R.   Rf   Ro   R3   R   (    (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyR   j  sB   t   _xtables_match_v12c           B   sE  e  Z d  e j f d e j f d e j f d e j f d e j f d e j f d e j f d e j f d e j f d	 e j d  f d
 e j d e j
 e   f d e j e j e j e j
 e j  e j e j
 e j  e j e j
 e j
 e    f d e j d e j  f d e j d e j e j
 e  e j  f d e j d e j e j
 e   f d e j e j e j
 e   f d e j
 e  f d e j d e j
 e   f d e j d e j
 e   f d e j
 e  f d e j f d e j f d e j f d e j f d e j
 e  f d e j f d e j f g Z RS(   R    Rq   R   R   R   R   Rr   R:   Rs   Rt   Ru   Rv   Rw   Rx   Ry   R   Rz   R~   R   R   t   xt_xlateR   Rn   R!   R{   R|   R}   N(   R   R	   R   R)   R*   R   R   R=   R+   R,   R2   R   R-   R(   R.   Rf   Ro   R3   R   (    (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyR     sD   t   xtables_matchc           B   sh   e  Z d  e f d e f d e f d e f d e f d e f d e f d e	 f d e
 f d	 e f g
 Z RS(
   t   v1t   v2t   v4t   v5t   v6t   v7t   v9t   v10t   v11t   v12(   R   R	   Rp   t   _xtables_match_v2t   _xtables_match_v4t   _xtables_match_v5R   R   R   R   t   _xtables_match_v11R   R   (    (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyR     s   									t   _xtables_target_v1c           B   s  e  Z d  e j f d e j f d e j f d e j f d e j f d e j f d e j f d e j d  f d e j d e j
 e   f d	 e j e j e j
 e j  e j e j
 e j  e j e j
 e j
 e    f d
 e j d e j  f d e j d e j e j
 e  e j  f d e j d e j e j
 e   f d e j
 e  f d e j f d e j
 e  f d e j f d e j f d e j f g Z d Z d Z d Z RS(   R    Rq   R   R   Rr   R:   Rs   Rt   Ru   Rv   Rw   Rx   Ry   Rz   R!   t   tt   tflagst   usedR}   N(   R   R	   R   R)   R*   R   R   R=   R+   R,   R2   R   R-   R(   R.   R   R~   R   R   (    (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyR     s8   t   _xtables_target_v6c           B   s  e  Z d  e j f d e j f d e j f d e j f d e j f d e j f d e j f d e j d  f d e j d e j
 e   f d	 e j e j e j
 e j  e j e j
 e j  e j e j
 e j
 e    f d
 e j d e j  f d e j d e j e j
 e  e j  f d e j d e j e j
 e   f d e j
 e  f d e j d e j
 e   f d e j d e j
 e   f d e j
 e  f d e j f d e j
 e  f d e j f d e j f d e j f g Z RS(   R    Rq   R   R   Rr   R:   Rs   Rt   Ru   Rv   Rw   Rx   Ry   Rz   R~   R   R   R!   R   R   R   R}   N(   R   R	   R   R)   R*   R   R   R=   R+   R,   R2   R   R-   R(   R.   Rf   Ro   R3   R   (    (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyR     s8   t   _xtables_target_v7c           B   s  e  Z d  e j f d e j f d e j f d e j f d e j f d e j f d e j f d e j d  f d e j d e j
 e   f d	 e j e j e j
 e j  e j e j
 e j  e j e j
 e j
 e    f d
 e j d e j  f d e j d e j e j
 e  e j  f d e j d e j e j
 e   f d e j
 e  f d e j d e j
 e   f d e j d e j
 e   f d e j
 e  f d e j f d e j f d e j f d e j
 e  f d e j f d e j f d e j f g Z RS(   R    Rq   R   R   Rr   R:   Rs   Rt   Ru   Rv   Rw   Rx   Ry   Rz   R~   R   R   R   Rn   R!   R   R   R   R}   N(   R   R	   R   R)   R*   R   R   R=   R+   R,   R2   R   R-   R(   R.   Rf   Ro   R3   R   (    (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyR   <  s<   t   _xtables_target_v9c           B   s  e  Z d  e j f d e j f d e j f d e j f d e j f d e j f d e j f d e j f d e j d  f d	 e j d e j
 e   f d
 e j e j e j
 e j  e j e j
 e j  e j e j
 e j
 e    f d e j d e j  f d e j d e j e j
 e  e j  f d e j d e j e j
 e   f d e j
 e  f d e j d e j
 e   f d e j d e j
 e   f d e j
 e  f d e j f d e j f d e j f d e j
 e  f d e j f d e j f d e j f g Z RS(   R    Rq   R   R   R   Rr   R:   Rs   Rt   Ru   Rv   Rw   Rx   Ry   Rz   R~   R   R   R   Rn   R!   R   R   R   R}   N(   R   R	   R   R)   R*   R   R   R=   R+   R,   R2   R   R-   R(   R.   Rf   Ro   R3   R   (    (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyR   l  s>   t   _xtables_target_v10c           B   s?  e  Z d  e j f d e j f d e j f d e j f d e j f d e j f d e j f d e j f d e j f d	 e j d  f d
 e j d e j
 e   f d e j e j e j
 e j  e j e j
 e j  e j e j
 e j
 e    f d e j d e j  f d e j d e j e j
 e  e j  f d e j d e j e j
 e   f d e j e j e j
 e   f d e j
 e  f d e j d e j
 e   f d e j d e j
 e   f d e j
 e  f d e j f d e j f d e j f d e j
 e  f d e j f d e j f d e j f g Z RS(   R    Rq   R   R   R   R   Rr   R:   Rs   Rt   Ru   Rv   Rw   Rx   Ry   R   Rz   R~   R   R   R   Rn   R!   R   R   R   R}   N(   R   R	   R   R)   R*   R   R   R=   R+   R,   R2   R   R-   R(   R.   Rf   Ro   R3   R   (    (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyR     sD   t   _xtables_target_v12c           B   sK  e  Z d  e j f d e j f d e j f d e j f d e j f d e j f d e j f d e j f d e j f d	 e j d  f d
 e j d e j
 e   f d e j e j e j
 e j  e j e j
 e j  e j e j
 e j
 e    f d e j d e j  f d e j d e j e j
 e  e j  f d e j d e j e j
 e   f d e j e j e j
 e   f d e j
 e  f d e j d e j
 e   f d e j d e j
 e   f d e j
 e  f d e j f d e j f d e j f d e j f d e j
 e  f d e j f d e j f d e j f g Z RS(   R    Rq   R   R   R   R   Rr   R:   Rs   Rt   Ru   Rv   Rw   Rx   Ry   R   Rz   R~   R   R   R   R   Rn   R!   R   R   R   R}   N(   R   R	   R   R)   R*   R   R   R=   R+   R,   R2   R   R-   R(   R.   Rf   Ro   R3   R   (    (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyR     sF   t   xtables_targetc           B   sh   e  Z d  e f d e f d e f d e f d e f d e f d e f d e	 f d e
 f d	 e f g
 Z RS(
   R   R   R   R   R   R   R   R   R   R   (   R   R	   R   t   _xtables_target_v2t   _xtables_target_v4t   _xtables_target_v5R   R   R   R   t   _xtables_target_v11R   R   (    (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyR     s   									t   XTablesErrorc           B   s   e  Z d  Z RS(   s2   Raised when an xtables call fails for some reason.(   R   R	   R
   (    (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyR     s   t   ct   optindt   optargt   PYTHON_IPTABLES_XTABLES_VERSIONs   libxtables.so.%st   xtablest   XTABLES_LIBDIRs   /lib/xtabless   /lib64/xtabless   /usr/lib/xtabless   /usr/lib/iptabless   /usr/lib64/xtabless   /usr/lib64/iptabless   /usr/local/lib/xtabless!   /usr/lib/x86_64-linux-gnu/xtabless?   can't find directory with extensions; please set XTABLES_LIBDIRt	   xtwrappert   kernel_versionc         G   s   t  |   d  S(   N(   t   _throw(   t   statust   args(    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyt   _xt_exitS  s    c            s     f d   } | S(   Nc             s$   |  d } t  j | j    |    S(   Ni    (   R   t   _xtables_set_nfprotot   proto(   R   t   xtobj(   t   fn(    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyt   newZ  s    
(    (   R   R   (    (   R   s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyt   set_nfprotoY  s    c           B   s  e  Z e j Z e j e _ e j e	  e j
 g e _ e j Z e j e  e _ e j e j e j g e _ e j Z e j e  e _ e j e j g e _ e j Z d! e _ e j
 g e _ e j j e d   Z e j j e d  Z y e j j e d  Z Wn  e k
 r"e j d!  Z n Xe j j e d  Z y e j j e d  Z Wn  e k
 rse j d!  Z n Xi d d 6d d 6Z e j    Z! d	   Z" e# d
  Z$ d   Z% d   Z& d   Z' d   Z( d   Z) d   Z* d   Z+ d   Z, e- d    Z. e- d    Z/ e- d    Z0 d   Z1 d   Z2 e- d    Z3 e- d    Z4 d   Z5 d   Z6 d   Z7 e- d    Z8 d   Z9 d   Z: e- d     Z; RS("   t	   xt_paramst   xtables_matchest   xtables_pending_matchest   xtables_targetst   xtables_pending_targetst	   conntrackt   statet   CTt   NOTRACKc         C   sK   t  j j | d   } | sG t j |   } | t  j | <| j |  n  | S(   N(   R   t   _cachet   getR,   t   objectt   __new__t   _xtinit(   t   clsR   t   obj(    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyR     s    c         C   s   | |  _  | |  _ t j t } d t } d t } y( t | |  |  _ t | |  |  _ Wn t	 d t   n Xt
 j t j t  |  } | r t	 d |   n  d  S(   Ns   _xtables_match_v%ds   _xtables_target_v%ds   unknown xtables version %ds   xtables_init_all() failed: %d(   R   t   no_alias_checkt   syst   modulesR   t   xtables_versiont   getattrt   _match_structt   _target_structR   R   t   _xtables_init_allR   t   pointert   _xt_globals(   t   selfR   R   t
   thismodulet	   matchnamet
   targetnamet   rv(    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyR     s    		

c         C   s   d |  j  S(   Ns   XTables for protocol %d(   R   (   R   (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyt   __repr__  s    c         C   s   | d k r d } n  | S(   Nt    t   ACCEPTt   DROPt   QUEUEt   RETURNt   standard(   R   R   R   R   R   (    (   R   R   (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyt   _check_extname  s    	c         C   s   | t  d |  j | f <d  S(   Ns   %s___%s(   t   _loaded_extsR   (   R   R   t   ext(    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyt   _loaded  s    c         C   s   y t  | d |  } Wn t k
 r |  j   } t  | d | | f d   } | d  k r |  j r | t j k r t j | } |  j | |  } q q n X| S(   Ns   libxt_%s_inits	   %s%s_init(   R   t   AttributeErrort   _get_prefixR,   R   R   t
   _real_namet   _get_initfn_from_lib(   R   R   t   libt   initfnt   prefix(    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyR     s    c         C   s_   yQ t  |  t j k r* t j |  } n  |  j | |  } | rP t |  t SWn n Xt S(   N(   R4   R   t   CDLLR   t   _wrap_voidfnt   Truet   False(   R   R   R   R   (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyt   _try_extinit  s    
c         C   s=   |  j  t k r d S|  j  t k r& d St d |  j    d  S(   Nt   libipt_t   libip6t_s   Unknown protocol %d(   R   t   NFPROTO_IPV4t   NFPROTO_IPV6R   (   R   (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyR     s
    c         C   s   t  | t  r | j   } n  |  j | t  r4 d  S|  j   } t j j t	 d | d  t j j t	 | | d  g } x$ | D] } |  j | |  r d  Sq Wd  S(   Nt   libxt_s   .so(
   t
   isinstancet   bytest   decodeR   t   _lib_xtablesR   t   ost   patht   joint   _xtables_libdir(   R   R   R   t   libsR   (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyt   _try_register  s     c         C   s#   t  j d |  j | f d   } | S(   Ns   %s___%s(   R   R   R   R,   (   R   R   R   (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyt   _get_loaded_ext  s    c         C   s  t  | t  r | j   } n  |  j |  } |  j |  } | d  k	 rL | St j d   j t	 j
 _ t	 j r t j d   j t	 j _ n  t	 j | t d   } | s |  j |  t	 j | t d   } | s | Sn  t j | t j |  j   } |  j | d j |  | S(   Ni    (   R   t   strt   encodeR   R   R,   R   R*   t   valueR   t   _xtables_matchest   _xtables_pending_matchest   _xtables_find_matcht   XTF_TRY_LOADR   t   XTF_DONT_LOADt   castR2   R   R   R   (   R   R   R   R?   R{   (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyt
   find_match  s$    	c         C   s  t  | t  r | j   } n  |  j |  } |  j |  } | d  k	 rL | St j d   j t	 j
 _ t	 j r t j d   j t	 j _ n  t	 j | t  } | s |  j |  t	 j | t  } | s | Sn  t j | t j |  j   } |  j | d j |  | S(   Ni    (   R   R  R  R   R   R,   R   R*   R  R   t   _xtables_targetst   _xtables_pending_targetst   _xtables_find_targetR  R   R  R	  R2   R   R   R   (   R   R   R   R@   R   (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyt   find_target  s$    	c         C   s/   t  | j t j t j |  t j  |  d  S(   N(   t
   _wrap_saveRy   R   R	  R   R*   (   R   t   moduleRC   t   ptr(    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyRy     s    c         C   s5   x. | D]& } | j  s Pn  | j  | k r | Sq Wd  S(   N(   R   R,   (   R   t   entriesR   t   e(    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyt   _option_lookup#  s    	c   	   	   C   s   x| | j  D]q } | j | d k rn t | j | j | | | | |  } | d k rj t d | d   n  d  S| j s
 Pq
 q
 Wt d | d   d  S(   Ni    i   s   invalid value %ss   invalid parameter %s(   Rz   R   t   _wrap_parseRv   R1   t
   ValueErrorR   (	   R   R  t   argvt   invR8   Ri   R  t   optR   (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyt   _parse+  s    	c         C   s  t  |  d k r | d p d  t _ t  |  d t _ y4 | d  k rS | j } n  | d  k rk | j } n  Wn t k
 r n X| r| r|  j | | d  } | s t	 d | j
 | d f   n  t   }	 t j |  |	 _ t |	 _ t j | j  |	 _ | j
 |	 _ t j | j d j t j  |	 _ d |	 _ t j | j  |	 _ t j | t j  |	 _ | j |	 _ t | t j |	   }
 |
 d k rt	 d | j
 |
 | d f   n  | j |	 j O_ d  St j t j d   } |  j | | | | | |  | j | d O_ d  S(   Ni   i    s   %s: no such parameter %ss   %s: parameter error %d (%s)(   t   lenR,   t   _optargR  t   _optindR   R~   R   R  R   R   Rf   R   R   Ri   Rg   R   Rk   Rh   R	  R   R   R*   Rj   R@   Rm   Rn   t
   _wrap_x6fnR   R(   R  (   R   R  Rk   R   t   fwR  R~   R   Ri   t   cbR   R8   (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyt   parse_target9  sB    %		"	c         C   s1  t  |  d k r | d p d  t _ t  |  d t _ y4 | d  k rS | j } n  | d  k rk | j } n  Wn t k
 r n X| r| r|  j | | d  } | s t	 d | j
 | d f   n  t   }	 t j |  |	 _ t |	 _ t j | j  |	 _ | j
 |	 _ t j | j d j t j  |	 _ d |	 _ t j | j  |	 _ t j | t j  |	 _ | j |	 _ t | t j |	   }
 |
 d k rt	 d | j
 t  |  d k r| d pd |
 f   n  | j |	 j O_ d  St j t j d   } |  j | | | | | |  | j | d O_ d  S(   Ni   i    s   %s: no such parameter %ss   %s: parameter '%s' error %dR   (   R  R,   R  R  R  R   R~   R   R  R   R   Rf   R   R   Ri   Rg   R   Rk   Rh   R	  R{   R   R*   Rj   R?   Rm   Rn   R  R|   R(   R  (   R   R  Rk   R{   R  R  R~   R   Ri   R   R   R8   (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyt   parse_matchf  sB    %		"	5c         C   sz   xs | D]k } | j  d  k r  Pn  | j t @r | d | j >@r t d | | j  f   | d | j >@sr q qr q q Wd  S(   Ni   s   %s: --%s must be specified(   R   R,   R8   t
   XTOPT_MANDR5   R   (   R   R   Rj   t   tableRi   (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyt   _options_fcheck  s    	c         C   sB   | j  s d  St | j  | j  } | r> t d | j   n  d  S(   Ns   %s.final_check() has failed(   Rw   t   _wrap_uintfnR   R   R   (   R   R@   R   (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyt   _fcheck_target_old  s    	c         C   s   t    } | j | _ t j | j d j t j  | _ | j | _	 | j
 | _
 t | j t j |   } | r t d | j   n  | j r |  j | j | j | j  n  d  S(   Ni    s   %s.x6_fcheck has failed(   Ro   R   Rh   R   R	  R   R   R*   R   Rj   Rn   R  R   R   R   R   R%  (   R   R@   R   R   (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyt   _fcheck_target_new  s    	"	c         C   sN   d  } y | j } Wn t k
 r& n X| r= |  j |  n |  j |  d  S(   N(   R,   R   R   R(  R'  (   R   R@   R   (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyt   final_check_target  s    c         C   sB   | j  s d  St | j  | j  } | r> t d | j   n  d  S(   Ns   %s.final_check() has failed(   Rw   R&  R|   R   R   (   R   R?   R   (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyt   _fcheck_match_old  s    	c         C   s   t    } | j | _ t j | j d j t j  | _ | j | _	 | j
 | _
 t | j t j |   } | r t d | j   n  | j r |  j | j | j | j  n  d  S(   Ni    s   %s.x6_fcheck has failed(   Ro   R   Rh   R   R	  R{   R   R*   R|   Rj   Rn   R  R   R   R   R   R%  (   R   R?   R   R   (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyt   _fcheck_match_new  s    	"	c         C   sN   d  } y | j } Wn t k
 r& n X| r= |  j |  n |  j |  d  S(   N(   R,   R   R   R+  R*  (   R   R?   R   (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyt   final_check_match  s    N(<   R   R	   R   t   xtables_init_allR   R   R-   t   restypeR2   R    R   t   argtypest   xtables_find_matchR  R   R)   R*   t   xtables_find_targetR  R   t   xtables_set_nfprotoR   R,   t   in_dllt   _xtables_xt_paramsR  R  R  R  R  R   t   weakreft   WeakValueDictionaryR   R   R   R   R   R   R   R   R   R   R   R   R   R
  R  Ry   R  R  R!  R"  R%  R'  R(  R)  R*  R+  R,  (    (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyR   r  sj   							
											--							i   i   i   i   i   (   t   ctypesR   R   R   R5  R   R    t   utilR   t   XT_INV_PROTOt   NFPROTO_UNSPECR   t   NFPROTO_ARPt   NFPROTO_BRIDGER   t   NFPROTO_DECNETt   NFPROTO_NUMPROTOR  t   XTF_DURING_LOADR  t   XTF_LOAD_MUST_SUCCEEDt   XTOPT_INVERTR#  t   XTOPT_MULTIt	   XTOPT_PUTt	   XTOPT_NBOt   sizeoft   c_longR   R   R   t	   StructureR   R   t   UnionR   R   R   R   R   R    R.   R3   R>   RA   RH   RL   RO   RR   Rf   Ro   Rp   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   t	   ExceptionR   t   _libct   _R3  R  R)   R  t   getenvR   t
   _searchlibR   R   R,   t   xtdirR   t   isdirt   _lib_xtwrappert   throw_exceptionR   t
   wrap_parseR  R-   R.  R*   R2   R(   R/  t	   wrap_saveR  t   wrap_uintfnR&  t   wrap_voidfnR   t	   wrap_x6fnR  t   _kernel_versiont   get_kernel_versiont   _get_kernel_versionR   R+   t   _EXIT_FNR   R   R!   t   __pkgname__R  R"   t   __version__R#   R$   R%   R&   R   t   _COMPAT_REV_FNt   xtables_compatible_revisiont   _xt_compat_revR'   R   R   R   (    (    (    s5   /home/vilmos/Projects/python-iptables/iptc/xtables.pyt   <module>   s   	&)./35(+0157														$