+
    i,  c                   s    R t ^ RIt^ RIt^ RIHt ^ RIHt ^ RIH	t	 ^ RI
Ht ^ RIHtHt ^ RIHt ^ t. ROtRR	R
RRRRR/tRRR
RRR/t ! R R4      tR tR tR tR tR tR# )zThe ipset command wrapperN)errors)FirewallError)runProg)log)tempFilereadfile)COMMANDSfamilyz
inet|inet6hashsizeZvaluemaxelemtimeoutzvalue in secsZinetZ1024Z65536c                   s   a  ] tR t^6t o RtR tR tR tR tRR lt	R t
R	 tR
 tRR ltRR ltR tRR ltRR ltR tR tR tR tRtV tR# )ipsetzipset command wrapper classc                s8    \         R ,          V n        R V n        R# )r   N)r   _commandnameself   &8/usr/lib/python3.14/site-packages/firewall/core/ipset.py__init__Zipset.__init__9   s     )	    c                sV   V Uu. uF  pRV,          NK  	  pp\         P                  ! RV P                  V P                  RP	                  V4      4       \        V P                  V4      w  rEV^ 8w  d1   \        RV P                  : RRP	                  V4      : RV: 24      hV# u upi )zCall ipset with args%sz	%s: %s %s '
' failed: )r   debug2	__class__r   joinr   
ValueError)r   argsZitemZ_argsstatusrets   &&    r   Z__runZipset.__run=   s     *...

;sxxOu5Q;(,sxxL  
 /s   B&c                sp    \        V4      \        8  d"   \        \        P                  RV,          4      hR# )zCheck ipset namezipset name '%s' is not validN)lenIPSET_MAXNAMELENr   r    ZINVALID_NAME)r   r      &&r   
check_nameZipset.check_nameI   s2    t9''##%Cd%J  (r   c                s    \        V4      \        8  g   V\        9  d"   \        \        P
                  RV,          4      hR# )zCheck ipset typez!ipset type name '%s' is not validN)r   r    IPSET_TYPESr   r    ZINVALID_TYPE)r   	type_namer!   r   
check_typeZipset.check_typeP   s:    y>,,	0L##%H9%T  1Mr   Nc                s$   V P                  V4       V P                  V4       RW.p\        V\        4      '       dE   VP	                  4        F0  w  rVVP                  V4       VR8w  g   K  VP                  V4       K2  	  V P                  V4      # )z+Create an ipset with name, type and optionscreate )r"   r%   Z
isinstanceZdictitemsappend_ipset__run)r   set_namer$   optionsr   keyvals   &&&&   r   
set_createZipset.set_createW   ss    !	"(.gt$$#MMOC "9KK$ , zz$r   c                sJ    V P                  V4       V P                  R V.4      # )Zdestroy)r"   r*   )r   r+   r!   r   set_destroyZipset.set_destroyd   s"    !zz9h/00r   c                ,    R W.pV P                  V4      # )Zaddr*   r   r+   entryr      &&& r   set_addZipset.set_addh       x'zz$r   c                r1   )Zdelr2   r3   r5   r   
set_deleteZipset.set_deletel   r7   r   c                s    R W.pV'       d(   VP                  RRP                  V4      ,          4       V P                  V4      # )testr   r   )r)   r   r*   )r   r+   r4   r,   r   s   &&&& r   r9   Z
ipset.testp   s8    (KKsxx001zz$r   c                s    R .pV'       d   VP                  V4       V'       d   VP                  V4       V P                  V4      P                  R4      # )Zlist
)r)   Zextendr*   split)r   r+   r,   r   r5   r   set_listZipset.set_listv   sA    xKK!KK zz$%%d++r   c                s   V P                  R.R7      p/ pR;r4/ pV EFL  p\        V4      ^8  d   K  VP                  R^4       Uu. uF  qwP                  4       NK  	  pp\        V4      ^8w  d   KV  V^ ,          R8X  d   V^,          pKo  V^ ,          R8X  d   V^,          pK  V^ ,          R8X  g   K  V^,          P                  4       p	^ p
V
\        V	4      8  dZ   W,          pVR	9   d@   \        V	4      V
8  d   V
^,          p
W,          W[&   M\        P
                  ! RV4       / u # V
^,          p
Ki  V'       d   V'       d   V\        V4      3W#&   R;r4VP                  4        EKO  	  V# u upi )
z Get active ipsets (only headers)z-terse)r,   NZ:ZNameZTypeZHeaderz&Malformed ipset list -terse output: %s)r   r   r	   r
   Znetmask)r<   r   r;   Zstripr   Zerrorremove_default_create_optionsZclear)r   Zlinesr   Z_nameZ_type_optionslinexZpairZsplitsiopts   &           r   set_get_active_terseZipset.set_get_active_terse~   sF   xj1D4y1}'+zz#q'9:'9!GGI'9D:4yA~aF"QaF"QaH$a#f+o )CUUv;?FA,2IHMII&NPTU#%IFAU"')Fx)P!QCJ $$ 5 6 
1 ;s   E0c                \    R .pV'       d   VP                  V4       V P                  V4      # )saver)   r*   r   r+   r      && r   rE   Z
ipset.save   s'    xKK!zz$r   c                s   V P                  V4       V P                  V4       \        4       pR V9   d
   RV,          pRWR.pV'       dE   VP                  4        F0  w  rVP	                  V4       V	R8w  g   K  VP	                  V	4       K2  	  VP                  RR P                  V4      ,          4       VP                  RV,          4       V Fd  p
R V
9   d
   RV
,          p
V'       d0   VP                  RV: R V
: R R P                  V4      : R24       KJ  VP                  RV: R V
: R24       Kf  	  VP                  4        \        P                  ! VP                  4      p\        P                  ! R	V P                  V P                  R
VP                  VP                  3,          4       R.p\!        V P                  WvP                  R7      w  r\        P"                  ! 4       ^8  d    \%        VP                  4       ^p\%        VP                  4       F\  p\        P&                  ! RW3,          ^^ R7       VP)                  R4      '       g   \        P&                  ! R^R7       V^,          pK^  	  \        P,                  ! VP                  4       V^ 8w  d1   \/        RV P                  : R R P                  V4      : RV: 24      hV#   \*         d     Lfi ; i)r   z'%s'r&   z-existr'   z%s
z	flush %s
zadd r:   z%s: %s restore %sz%s: %dZrestore)Zstdinz%8d: %s)nofmtZnl)rI   r   r   )r"   r%   r   r(   r)   Zwriter   Zcloseosstatr   r   r   r   r   Zst_sizer   ZgetDebugLogLevelr   Zdebug3ZendswithZ	ExceptionZunlinkr   )r   r+   r$   entriesZcreate_optionsZentry_optionsZ	temp_filer   r-   r.   r4   rK   r   r   rA   r?   s   &&&&&&          r   set_restoreZipset.set_restore   s1    	!	"J	(?(H(x8*002C "9KK$ 3 	$/0x/0Ee|(0%-9PQ 5 AB  	wwy~~&

NNMM	55		
 {t>>J!A%
( $Y^^4DJJyA94A!D==..

2Q/FA	 5 			)..!Q;(,sxx~sK  
!  s   2K K%$K%c                rD   )ZflushrF   rG   rH   r   	set_flushZipset.set_flush   s'    yKK!zz$r   c                (    V P                  R W.4      # )renamer2   )r   Zold_set_nameZnew_set_name   &&&r   rP   Zipset.rename   s    zz8\@AAr   c                rO   )swapr2   )r   Z
set_name_1Z
set_name_2rQ   r   rR   Z
ipset.swap   s    zz6::;;r   c                s&    V P                  R .4      # )versionr2   r   r   r   rS   Zipset.version   s    zz9+&&r   )r   r   )N)NN)Z__name__Z
__module__Z__qualname__Z__firstlineno____doc__r   r*   r"   r%   r/   r0   r6   r8   r9   r<   rC   rE   rM   rN   rP   rR   rS   Z__static_attributes__Z__classdictcell__)Z__classdict__s   @r   r   r   6   se     %
 1   ,"H <| B<' 'r   r   c                s2    \        V 4      \        8  d   R# R# )z"Return true if ipset name is validFT)r   r    )r   r   r   check_ipset_namerU      s    
4y##r   c                s    V P                  4       p\         F'  pW!9   g   K  \        V,          W,          8X  g   K%  W K)  	  V# )z&Return only non default create options)ZcopyIPSET_DEFAULT_CREATE_OPTIONS)r,   r>   rB      &  r   r=   r=      s7    ||~H+?;C@HMQ , Or   c           
     s"   . pV P                  R4       FE  p VP                  R4       VP                  \        \        P
                  ! VRR7      4      4       KG  	  RP                  V4      #   \         d    TP                  T4        Ky  i ; i)zNormalize IP addresses in entry,Z/FZstrict)r;   Zindexr)   Zstr	ipaddress
ip_networkr   r   )r4   Z_entryZ_partrW   r   normalize_ipset_entryr\     sw    FS!	!KKMM#i225GHI " 88F  	!MM% 	!s   AA..BBc                s\   \        V P                  R4      4      ^8  d   R#  \        P                  ! V RR7      pT FY  pTP                  \        P                  ! TRR7      4      '       g   K2  \        \        P                  RP                  Y4      4      h	  R#   \         d     R# i ; i)z8Check if entry overlaps any entry in the list of entriesrX   NFrY   z,Entry '{}' overlaps with existing entry '{}')
r   r;   rZ   r[   r   overlapsr   r    INVALID_ENTRYformat)r4   rL   Zentry_networkZitrs   &&  r   check_entry_overlaps_existingr`     s     5;;sq !,,U5A
 !!)"6"6s5"IJJ$$>EEeQ  	  s   B B+*B+c                s    V  Uu. uF  p\         P                  ! VRR7      NK  	  p p\        T 4      ^ 8X  d   R# T P	                  4        T P                  ^ 4      pT  FE  pTP                  T4      '       d*   \        \        P                  RP                  Y#4      4      hTpKG  	  R# u upi   \         d     R# i ; i)z<Check if any entry overlaps any entry in the list of entriesFrY   NzEntry '{}' overlaps entry '{}')rZ   r[   r   r   ZsortZpopr]   r   r    r^   r_   )rL   r@   Zprev_networkZcurrent_networks   &   r   check_for_overlapping_entriesra   '  s    BIJ'Q9''%8'J
 7|qd LLN;;q>L"  11$$077V  ' #u K s!   B. !B)B. )B. .B=<B=)zhash:ipzhash:ip,portzhash:ip,port,ipzhash:ip,port,netzhash:ip,markzhash:netzhash:net,netzhash:net,portzhash:net,port,netzhash:net,ifacezhash:mac)rT   Zos.pathrJ   rZ   Zfirewallr    Zfirewall.errorsr   Zfirewall.core.progr   Zfirewall.core.loggerr   Zfirewall.functionsr   r   Zfirewall.configr   r    r#   ZIPSET_CREATE_OPTIONSrV   r   rU   r=   r\   r`   ra   ) r   r   <module>rb      s         ) & $ 1 $ & lw	  fw  }' }'@
(C'r   