@@ -74,8 +74,8 @@ fn update_ipv4_blocklist(
74
74
// add port to blocklist
75
75
if let Some ( first_zero) = blocked_ports. iter ( ) . enumerate ( ) . find ( |& x| * x. 1 == 0 ) {
76
76
blocked_ports[ first_zero. 0 ] = port;
77
- dbg ! ( "UPSERTING" ) ;
78
- dbg ! ( blocked_ports[ 0 ] , blocked_ports[ 1 ] ) ;
77
+ // dbg!("UPSERTING");
78
+ // dbg!(blocked_ports[0], blocked_ports[1]);
79
79
ipv4_firewall
80
80
. insert ( addr. to_bits ( ) , blocked_ports, 0 )
81
81
. unwrap ( ) ;
@@ -84,10 +84,22 @@ fn update_ipv4_blocklist(
84
84
}
85
85
} else {
86
86
// remove port from blocklist
87
- if let Some ( matching_port) = blocked_ports. iter ( ) . enumerate ( ) . find ( |& x| * x. 1 == port) {
88
- blocked_ports[ matching_port. 0 ] = 0 ;
89
- dbg ! ( "REMOVING" ) ;
90
- dbg ! ( blocked_ports[ 0 ] , blocked_ports[ 1 ] ) ;
87
+ // on veut rebuild une blocklist avec les ports restants non nuls
88
+ // par example là [8888,0,80,0,..]
89
+ // hashmap = key:[0,0,0]
90
+ // => [8888,80,0 ....]
91
+ let non_null_ports = blocked_ports
92
+ . into_iter ( )
93
+ . filter ( |p| ( * p != 0 && * p != port) )
94
+ . collect :: < Vec < u16 > > ( ) ;
95
+ let mut blocked_ports = [ 0 ; 32 ] ;
96
+ for ( idx, p) in non_null_ports. iter ( ) . enumerate ( ) {
97
+ blocked_ports[ idx] = * p;
98
+ }
99
+ if blocked_ports. iter ( ) . sum :: < u16 > ( ) == 0 {
100
+ //now block_list is empty, we need to delete key
101
+ ipv4_firewall. remove ( & addr. to_bits ( ) ) . unwrap ( ) ;
102
+ } else {
91
103
ipv4_firewall
92
104
. insert ( addr. to_bits ( ) , blocked_ports, 0 )
93
105
. unwrap ( ) ;
@@ -96,7 +108,7 @@ fn update_ipv4_blocklist(
96
108
} else {
97
109
// shouldn't be disabling if blocklist is empty
98
110
assert ! ( enabled) ;
99
- //create new blocklist with port as first element
111
+ // create new blocklist with port as first element
100
112
let mut blocked_ports: [ u16 ; 32 ] = [ 0 ; 32 ] ;
101
113
blocked_ports[ 0 ] = port;
102
114
ipv4_firewall
0 commit comments