File tree Expand file tree Collapse file tree 3 files changed +16
-0
lines changed
Expand file tree Collapse file tree 3 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
1313* ** Security** : in case of vulnerabilities.
1414
1515## [ unreleased]
16+ ### Added
17+ - Add function for clearing states related to an interface.
1618
1719## [ 0.4.5] - 2022-12-28
1820- Add support for Timex ICMP rules.
Original file line number Diff line number Diff line change @@ -41,6 +41,8 @@ ioctl!(readwrite pf_add_rule with b'D', 4; pfvar::pfioc_rule);
4141ioctl ! ( readwrite pf_get_rules with b'D' , 6 ; pfvar:: pfioc_rule) ;
4242// DIOCGETRULE
4343ioctl ! ( readwrite pf_get_rule with b'D' , 7 ; pfvar:: pfioc_rule) ;
44+ // DIOCCLRSTATES
45+ ioctl ! ( readwrite pf_clear_states with b'D' , 18 ; pfvar:: pfioc_state_kill) ;
4446// DIOCGETSTATUS
4547ioctl ! ( readwrite pf_get_status with b'D' , 21 ; pfvar:: pf_status) ;
4648// DIOCGETSTATES
Original file line number Diff line number Diff line change @@ -311,6 +311,18 @@ impl PfCtl {
311311 }
312312 }
313313
314+ /// Clear states belonging to a given interface
315+ /// Returns total number of removed states upon success
316+ pub fn clear_interface_states ( & mut self , interface : Interface ) -> Result < u32 > {
317+ let mut pfioc_state_kill = unsafe { mem:: zeroed :: < ffi:: pfvar:: pfioc_state_kill > ( ) } ;
318+ interface
319+ . try_copy_to ( & mut pfioc_state_kill. psk_ifname )
320+ . chain_err ( || ErrorKind :: InvalidArgument ( "Incompatible interface name" ) ) ?;
321+ ioctl_guard ! ( ffi:: pf_clear_states( self . fd( ) , & mut pfioc_state_kill) ) ?;
322+ // psk_af holds the number of killed states
323+ Ok ( pfioc_state_kill. psk_af as u32 )
324+ }
325+
314326 /// Get all states created by stateful rules
315327 fn get_states ( & mut self ) -> Result < Vec < ffi:: pfvar:: pfsync_state > > {
316328 let num_states = self . get_num_states ( ) ?;
You can’t perform that action at this time.
0 commit comments