@@ -153,7 +153,7 @@ struct CoordinatorMessageUpdateType {
153
153
/// This includes adding the guest VF device and switching the data path.
154
154
guest_vf_state : bool ,
155
155
/// Update the receive filter for all channels.
156
- filter_state : bool ,
156
+ filter_state : Option < u32 > ,
157
157
}
158
158
159
159
#[ derive( PartialEq ) ]
@@ -1191,39 +1191,28 @@ impl VmbusDevice for Nic {
1191
1191
open_request : & OpenRequest ,
1192
1192
) -> Result < ( ) , ChannelOpenError > {
1193
1193
// Start the coordinator task if this is the primary channel.
1194
- let ( state, packet_filter ) = if channel_idx == 0 {
1194
+ let state = if channel_idx == 0 {
1195
1195
self . insert_coordinator ( 1 , false ) ;
1196
1196
// No rx traffic on primary channel until guest sets the packet filter.
1197
- ( WorkerState :: Init ( None ) , rndisprot :: NDIS_PACKET_TYPE_NONE )
1197
+ WorkerState :: Init ( None )
1198
1198
} else {
1199
1199
self . coordinator . stop ( ) . await ;
1200
1200
// Get the buffers created when the primary channel was opened.
1201
1201
let buffers = self . coordinator . state ( ) . unwrap ( ) . buffers . clone ( ) . unwrap ( ) ;
1202
1202
// Get the packet filter of the primary channel.
1203
- self . coordinator . state_mut ( ) . unwrap ( ) . workers [ 0 ]
1204
- . stop ( )
1205
- . await ;
1206
- let packet_filter = self . coordinator . state ( ) . unwrap ( ) . workers [ 0 ]
1207
- . state ( )
1208
- . unwrap ( )
1209
- . channel
1210
- . packet_filter ;
1211
- (
1212
- WorkerState :: Ready ( ReadyState {
1213
- state : ActiveState :: new ( None , buffers. recv_buffer . count ) ,
1214
- buffers,
1215
- data : ProcessingData :: new ( ) ,
1216
- } ) ,
1217
- packet_filter,
1218
- )
1203
+ WorkerState :: Ready ( ReadyState {
1204
+ state : ActiveState :: new ( None , buffers. recv_buffer . count ) ,
1205
+ buffers,
1206
+ data : ProcessingData :: new ( ) ,
1207
+ } )
1219
1208
} ;
1220
1209
1221
1210
let num_opened = self
1222
1211
. adapter
1223
1212
. num_sub_channels_opened
1224
1213
. fetch_add ( 1 , Ordering :: SeqCst ) ;
1225
1214
1226
- let r = self . insert_worker ( channel_idx, open_request, state, true , packet_filter ) ;
1215
+ let r = self . insert_worker ( channel_idx, open_request, state, true ) ;
1227
1216
if channel_idx != 0
1228
1217
&& num_opened + 1 == self . coordinator . state_mut ( ) . unwrap ( ) . num_queues as usize
1229
1218
{
@@ -1363,7 +1352,6 @@ impl Nic {
1363
1352
open_request : & OpenRequest ,
1364
1353
state : WorkerState ,
1365
1354
start : bool ,
1366
- packet_filter : u32 ,
1367
1355
) -> Result < ( ) , OpenError > {
1368
1356
let coordinator = self . coordinator . state_mut ( ) . unwrap ( ) ;
1369
1357
@@ -1395,7 +1383,7 @@ impl Nic {
1395
1383
pending_send_size : 0 ,
1396
1384
restart : None ,
1397
1385
can_use_ring_size_opt,
1398
- packet_filter,
1386
+ packet_filter : rndisprot :: NDIS_PACKET_TYPE_NONE ,
1399
1387
} ,
1400
1388
state,
1401
1389
coordinator_send : self . coordinator_send . clone ( ) . unwrap ( ) ,
@@ -1485,7 +1473,6 @@ impl Nic {
1485
1473
mut control : RestoreControl < ' _ > ,
1486
1474
state : saved_state:: SavedState ,
1487
1475
) -> Result < ( ) , NetRestoreError > {
1488
- let mut channel_packet_filter = 0u32 ; // set to primary packet filter
1489
1476
if let Some ( state) = state. open {
1490
1477
let open = match & state. primary {
1491
1478
saved_state:: Primary :: Version => vec ! [ true ] ,
@@ -1635,7 +1622,6 @@ impl Nic {
1635
1622
pending_link_action,
1636
1623
packet_filter,
1637
1624
) ?;
1638
- channel_packet_filter = primary. packet_filter ;
1639
1625
active. primary = Some ( primary) ;
1640
1626
}
1641
1627
@@ -1654,13 +1640,7 @@ impl Nic {
1654
1640
1655
1641
for ( channel_idx, ( state, request) ) in states. into_iter ( ) . zip ( requests) . enumerate ( ) {
1656
1642
if let Some ( state) = state {
1657
- self . insert_worker (
1658
- channel_idx as u16 ,
1659
- & request. unwrap ( ) ,
1660
- state,
1661
- false ,
1662
- channel_packet_filter,
1663
- ) ?;
1643
+ self . insert_worker ( channel_idx as u16 , & request. unwrap ( ) , state, false ) ?;
1664
1644
}
1665
1645
}
1666
1646
} else {
@@ -2835,9 +2815,7 @@ impl<T: RingMem> NetChannel<T> {
2835
2815
if restart_endpoint {
2836
2816
self . restart = Some ( CoordinatorMessage :: Restart ) ;
2837
2817
}
2838
- if packet_filter. is_some ( ) {
2839
- self . send_coordinator_update_filter ( ) ;
2840
- }
2818
+ self . send_coordinator_update_filter ( packet_filter) ;
2841
2819
rndisprot:: STATUS_SUCCESS
2842
2820
}
2843
2821
Err ( err) => {
@@ -3022,7 +3000,7 @@ impl<T: RingMem> NetChannel<T> {
3022
3000
Ok ( ( ) )
3023
3001
}
3024
3002
3025
- fn send_coordinator_update_message ( & mut self , guest_vf : bool , packet_filter : bool ) {
3003
+ fn send_coordinator_update_message ( & mut self , guest_vf : bool , packet_filter : Option < u32 > ) {
3026
3004
if self . restart . is_none ( ) {
3027
3005
self . restart = Some ( CoordinatorMessage :: Update ( CoordinatorMessageUpdateType {
3028
3006
guest_vf_state : guest_vf,
@@ -3035,16 +3013,18 @@ impl<T: RingMem> NetChannel<T> {
3035
3013
} else if let Some ( CoordinatorMessage :: Update ( ref mut update) ) = self . restart {
3036
3014
// Add the new update to the existing message.
3037
3015
update. guest_vf_state |= guest_vf;
3038
- update. filter_state |= packet_filter;
3016
+ if packet_filter. is_some ( ) {
3017
+ update. filter_state = packet_filter;
3018
+ }
3039
3019
}
3040
3020
}
3041
3021
3042
3022
fn send_coordinator_update_vf ( & mut self ) {
3043
- self . send_coordinator_update_message ( true , false ) ;
3023
+ self . send_coordinator_update_message ( true , None ) ;
3044
3024
}
3045
3025
3046
- fn send_coordinator_update_filter ( & mut self ) {
3047
- self . send_coordinator_update_message ( false , true ) ;
3026
+ fn send_coordinator_update_filter ( & mut self , packet_filter : Option < u32 > ) {
3027
+ self . send_coordinator_update_message ( false , packet_filter ) ;
3048
3028
}
3049
3029
}
3050
3030
@@ -3960,15 +3940,18 @@ impl Coordinator {
3960
3940
sleep_duration = None ;
3961
3941
}
3962
3942
Message :: Internal ( CoordinatorMessage :: Update ( update_type) ) => {
3963
- if update_type. filter_state {
3943
+ if let Some ( packet_filter ) = update_type. filter_state {
3964
3944
self . stop_workers ( ) . await ;
3965
- if let Some ( packet_filter) = self . primary_mut ( ) . map ( |p| p. packet_filter ) {
3966
- self . workers . iter_mut ( ) . for_each ( |worker| {
3967
- if let Some ( state) = worker. state_mut ( ) {
3968
- state. channel . packet_filter = packet_filter;
3969
- }
3970
- } ) ;
3971
- }
3945
+ self . workers . iter_mut ( ) . for_each ( |worker| {
3946
+ if let Some ( state) = worker. state_mut ( ) {
3947
+ state. channel . packet_filter = packet_filter;
3948
+ tracing:: debug!(
3949
+ ?packet_filter,
3950
+ channel_idx = state. channel_idx,
3951
+ "update packet filter"
3952
+ ) ;
3953
+ }
3954
+ } ) ;
3972
3955
}
3973
3956
3974
3957
if update_type. guest_vf_state {
0 commit comments