@@ -147,19 +147,11 @@ const LINK_DELAY_DURATION: Duration = Duration::from_secs(5);
147
147
#[ cfg( test) ]
148
148
const LINK_DELAY_DURATION : Duration = Duration :: from_millis ( 333 ) ;
149
149
150
- #[ derive( Default , PartialEq ) ]
151
- struct CoordinatorMessageUpdateType {
152
- /// Update guest VF state based on current availability and the guest VF state tracked by the primary channel.
153
- /// This includes adding the guest VF device and switching the data path.
154
- guest_vf_state : bool ,
155
- /// Update the receive filter for all channels.
156
- filter_state : bool ,
157
- }
158
-
159
150
#[ derive( PartialEq ) ]
160
151
enum CoordinatorMessage {
161
- /// Update network state.
162
- Update ( CoordinatorMessageUpdateType ) ,
152
+ /// Update guest VF state based on current availability and the guest VF state tracked by the primary channel.
153
+ /// This includes adding the guest VF device and switching the data path.
154
+ UpdateGuestVfState ,
163
155
/// Restart endpoints and resume processing. This will also attempt to set VF and data path state to match current
164
156
/// expectations.
165
157
Restart ,
@@ -390,7 +382,6 @@ struct NetChannel<T: RingMem> {
390
382
pending_send_size : usize ,
391
383
restart : Option < CoordinatorMessage > ,
392
384
can_use_ring_size_opt : bool ,
393
- packet_filter : u32 ,
394
385
}
395
386
396
387
/// Buffers used during packet processing.
@@ -1373,7 +1364,6 @@ impl Nic {
1373
1364
pending_send_size : 0 ,
1374
1365
restart : None ,
1375
1366
can_use_ring_size_opt,
1376
- packet_filter : rndisprot:: NDIS_PACKET_TYPE_NONE ,
1377
1367
} ,
1378
1368
state,
1379
1369
coordinator_send : self . coordinator_send . clone ( ) . unwrap ( ) ,
@@ -1463,7 +1453,6 @@ impl Nic {
1463
1453
mut control : RestoreControl < ' _ > ,
1464
1454
state : saved_state:: SavedState ,
1465
1455
) -> Result < ( ) , NetRestoreError > {
1466
- let mut saved_packet_filter = 0u32 ;
1467
1456
if let Some ( state) = state. open {
1468
1457
let open = match & state. primary {
1469
1458
saved_state:: Primary :: Version => vec ! [ true ] ,
@@ -1548,12 +1537,8 @@ impl Nic {
1548
1537
tx_spread_sent,
1549
1538
guest_link_down,
1550
1539
pending_link_action,
1551
- packet_filter,
1552
1540
} = ready;
1553
1541
1554
- // If saved state does not have a packet filter set, default to directed, multicast, and broadcast.
1555
- saved_packet_filter = packet_filter. unwrap_or ( rndisprot:: NPROTO_PACKET_FILTER ) ;
1556
-
1557
1542
let version = check_version ( version)
1558
1543
. ok_or ( NetRestoreError :: UnsupportedVersion ( version) ) ?;
1559
1544
@@ -1636,11 +1621,6 @@ impl Nic {
1636
1621
self . insert_worker ( channel_idx as u16 , & request. unwrap ( ) , state, false ) ?;
1637
1622
}
1638
1623
}
1639
- for worker in self . coordinator . state_mut ( ) . unwrap ( ) . workers . iter_mut ( ) {
1640
- if let Some ( worker_state) = worker. state_mut ( ) {
1641
- worker_state. channel . packet_filter = saved_packet_filter;
1642
- }
1643
- }
1644
1624
} else {
1645
1625
control
1646
1626
. restore ( & [ false ] )
@@ -1802,11 +1782,6 @@ impl Nic {
1802
1782
PrimaryChannelGuestVfState :: Restoring ( saved_state) => saved_state,
1803
1783
} ;
1804
1784
1805
- let worker_0_packet_filter = coordinator. workers [ 0 ]
1806
- . state ( )
1807
- . unwrap ( )
1808
- . channel
1809
- . packet_filter ;
1810
1785
saved_state:: Primary :: Ready ( saved_state:: ReadyPrimary {
1811
1786
version : ready. buffers . version as u32 ,
1812
1787
receive_buffer : ready. buffers . recv_buffer . saved_state ( ) ,
@@ -1836,7 +1811,6 @@ impl Nic {
1836
1811
tx_spread_sent : primary. tx_spread_sent ,
1837
1812
guest_link_down : !primary. guest_link_up ,
1838
1813
pending_link_action,
1839
- packet_filter : Some ( worker_0_packet_filter) ,
1840
1814
} )
1841
1815
}
1842
1816
} ;
@@ -2620,12 +2594,7 @@ impl<T: RingMem> NetChannel<T> {
2620
2594
if primary. rndis_state == RndisState :: Operational {
2621
2595
if self . guest_vf_is_available ( Some ( vfid) , buffers. version , buffers. ndis_config ) ? {
2622
2596
primary. guest_vf_state = PrimaryChannelGuestVfState :: AvailableAdvertised ;
2623
- return Ok ( Some ( CoordinatorMessage :: Update (
2624
- CoordinatorMessageUpdateType {
2625
- guest_vf_state : true ,
2626
- ..Default :: default ( )
2627
- } ,
2628
- ) ) ) ;
2597
+ return Ok ( Some ( CoordinatorMessage :: UpdateGuestVfState ) ) ;
2629
2598
} else if let Some ( true ) = primary. is_data_path_switched {
2630
2599
tracing:: error!(
2631
2600
"Data path switched, but current guest negotiation does not support VTL0 VF"
@@ -2765,7 +2734,10 @@ impl<T: RingMem> NetChannel<T> {
2765
2734
// flag on inband packets and won't send a completion
2766
2735
// packet.
2767
2736
primary. guest_vf_state = PrimaryChannelGuestVfState :: AvailableAdvertised ;
2768
- self . send_coordinator_update_vf ( ) ;
2737
+ // restart will also add the VF based on the guest_vf_state
2738
+ if self . restart . is_none ( ) {
2739
+ self . restart = Some ( CoordinatorMessage :: UpdateGuestVfState ) ;
2740
+ }
2769
2741
} else if let Some ( true ) = primary. is_data_path_switched {
2770
2742
tracing:: error!(
2771
2743
"Data path switched, but current guest negotiation does not support VTL0 VF"
@@ -2813,18 +2785,12 @@ impl<T: RingMem> NetChannel<T> {
2813
2785
tracing:: trace!( ?request, "handling control message MESSAGE_TYPE_SET_MSG" ) ;
2814
2786
2815
2787
let status = match self . adapter . handle_oid_set ( primary, request. oid , reader) {
2816
- Ok ( ( restart_endpoint, packet_filter ) ) => {
2788
+ Ok ( restart_endpoint) => {
2817
2789
// Restart the endpoint if the OID changed some critical
2818
2790
// endpoint property.
2819
2791
if restart_endpoint {
2820
2792
self . restart = Some ( CoordinatorMessage :: Restart ) ;
2821
2793
}
2822
- if let Some ( filter) = packet_filter {
2823
- if self . packet_filter != filter {
2824
- self . packet_filter = filter;
2825
- self . send_coordinator_update_filter ( ) ;
2826
- }
2827
- }
2828
2794
rndisprot:: STATUS_SUCCESS
2829
2795
}
2830
2796
Err ( err) => {
@@ -3008,31 +2974,6 @@ impl<T: RingMem> NetChannel<T> {
3008
2974
}
3009
2975
Ok ( ( ) )
3010
2976
}
3011
-
3012
- fn send_coordinator_update_message ( & mut self , guest_vf : bool , packet_filter : bool ) {
3013
- if self . restart . is_none ( ) {
3014
- self . restart = Some ( CoordinatorMessage :: Update ( CoordinatorMessageUpdateType {
3015
- guest_vf_state : guest_vf,
3016
- filter_state : packet_filter,
3017
- } ) ) ;
3018
- } else if let Some ( CoordinatorMessage :: Restart ) = self . restart {
3019
- // If a restart message is pending, do nothing.
3020
- // A restart will try to switch the data path based on primary.guest_vf_state.
3021
- // A restart will apply packet filter changes.
3022
- } else if let Some ( CoordinatorMessage :: Update ( ref mut update) ) = self . restart {
3023
- // Add the new update to the existing message.
3024
- update. guest_vf_state |= guest_vf;
3025
- update. filter_state |= packet_filter;
3026
- }
3027
- }
3028
-
3029
- fn send_coordinator_update_vf ( & mut self ) {
3030
- self . send_coordinator_update_message ( true , false ) ;
3031
- }
3032
-
3033
- fn send_coordinator_update_filter ( & mut self ) {
3034
- self . send_coordinator_update_message ( false , true ) ;
3035
- }
3036
2977
}
3037
2978
3038
2979
/// Writes an RNDIS message to `writer`.
@@ -3350,14 +3291,13 @@ impl Adapter {
3350
3291
primary : & mut PrimaryChannelState ,
3351
3292
oid : rndisprot:: Oid ,
3352
3293
reader : impl MemoryRead + Clone ,
3353
- ) -> Result < ( bool , Option < u32 > ) , OidError > {
3294
+ ) -> Result < bool , OidError > {
3354
3295
tracing:: debug!( ?oid, "oid set" ) ;
3355
3296
3356
3297
let mut restart_endpoint = false ;
3357
- let mut packet_filter = None ;
3358
3298
match oid {
3359
3299
rndisprot:: Oid :: OID_GEN_CURRENT_PACKET_FILTER => {
3360
- packet_filter = self . oid_set_packet_filter ( reader ) ? ;
3300
+ // TODO
3361
3301
}
3362
3302
rndisprot:: Oid :: OID_TCP_OFFLOAD_PARAMETERS => {
3363
3303
self . oid_set_offload_parameters ( reader, primary) ?;
@@ -3384,7 +3324,7 @@ impl Adapter {
3384
3324
return Err ( OidError :: UnknownOid ) ;
3385
3325
}
3386
3326
}
3387
- Ok ( ( restart_endpoint, packet_filter ) )
3327
+ Ok ( restart_endpoint)
3388
3328
}
3389
3329
3390
3330
fn oid_set_rss_parameters (
@@ -3442,15 +3382,6 @@ impl Adapter {
3442
3382
Ok ( ( ) )
3443
3383
}
3444
3384
3445
- fn oid_set_packet_filter (
3446
- & self ,
3447
- reader : impl MemoryRead + Clone ,
3448
- ) -> Result < Option < u32 > , OidError > {
3449
- let filter: rndisprot:: RndisPacketFilterOidValue = reader. clone ( ) . read_plain ( ) ?;
3450
- tracing:: debug!( filter, "set packet filter" ) ;
3451
- Ok ( Some ( filter) )
3452
- }
3453
-
3454
3385
fn oid_set_offload_parameters (
3455
3386
& self ,
3456
3387
reader : impl MemoryRead + Clone ,
@@ -3941,26 +3872,8 @@ impl Coordinator {
3941
3872
}
3942
3873
sleep_duration = None ;
3943
3874
}
3944
- Message :: Internal ( CoordinatorMessage :: Update ( update_type) ) => {
3945
- if update_type. filter_state {
3946
- self . stop_workers ( ) . await ;
3947
- let worker_0_packet_filter =
3948
- self . workers [ 0 ] . state ( ) . unwrap ( ) . channel . packet_filter ;
3949
- self . workers . iter_mut ( ) . skip ( 1 ) . for_each ( |worker| {
3950
- if let Some ( state) = worker. state_mut ( ) {
3951
- state. channel . packet_filter = worker_0_packet_filter;
3952
- tracing:: debug!(
3953
- packet_filter = ?worker_0_packet_filter,
3954
- channel_idx = state. channel_idx,
3955
- "update packet filter"
3956
- ) ;
3957
- }
3958
- } ) ;
3959
- }
3960
-
3961
- if update_type. guest_vf_state {
3962
- self . update_guest_vf_state ( state) . await ;
3963
- }
3875
+ Message :: Internal ( CoordinatorMessage :: UpdateGuestVfState ) => {
3876
+ self . update_guest_vf_state ( state) . await ;
3964
3877
}
3965
3878
Message :: UpdateFromEndpoint ( EndpointAction :: RestartRequired ) => self . restart = true ,
3966
3879
Message :: UpdateFromEndpoint ( EndpointAction :: LinkStatusNotify ( connect) ) => {
@@ -4393,18 +4306,13 @@ impl Coordinator {
4393
4306
self . num_queues = num_queues;
4394
4307
}
4395
4308
4396
- let worker_0_packet_filter = self . workers [ 0 ] . state ( ) . unwrap ( ) . channel . packet_filter ;
4397
4309
// Provide the queue and receive buffer ranges for each worker.
4398
4310
for ( ( worker, queue) , rx_buffer) in self . workers . iter_mut ( ) . zip ( queues) . zip ( rx_buffers) {
4399
4311
worker. task_mut ( ) . queue_state = Some ( QueueState {
4400
4312
queue,
4401
4313
target_vp_set : false ,
4402
4314
rx_buffer_range : rx_buffer,
4403
4315
} ) ;
4404
- // Update the receive packet filter for the subchannel worker.
4405
- if let Some ( worker) = worker. state_mut ( ) {
4406
- worker. channel . packet_filter = worker_0_packet_filter;
4407
- }
4408
4316
}
4409
4317
4410
4318
Ok ( ( ) )
@@ -5012,13 +4920,6 @@ impl<T: 'static + RingMem> NetChannel<T> {
5012
4920
data : & mut ProcessingData ,
5013
4921
epqueue : & mut dyn net_backend:: Queue ,
5014
4922
) -> Result < bool , WorkerError > {
5015
- if self . packet_filter == rndisprot:: NDIS_PACKET_TYPE_NONE {
5016
- tracing:: trace!(
5017
- packet_filter = self . packet_filter,
5018
- "rx packet not processed"
5019
- ) ;
5020
- return Ok ( false ) ;
5021
- }
5022
4923
let n = epqueue
5023
4924
. rx_poll ( & mut data. rx_ready )
5024
4925
. map_err ( WorkerError :: Endpoint ) ?;
@@ -5161,7 +5062,10 @@ impl<T: 'static + RingMem> NetChannel<T> {
5161
5062
_ => ( ) ,
5162
5063
} ;
5163
5064
if queue_switch_operation {
5164
- self . send_coordinator_update_vf ( ) ;
5065
+ // A restart will also try to switch the data path based on primary.guest_vf_state.
5066
+ if self . restart . is_none ( ) {
5067
+ self . restart = Some ( CoordinatorMessage :: UpdateGuestVfState )
5068
+ } ;
5165
5069
} else {
5166
5070
self . send_completion ( transaction_id, & [ ] ) ?;
5167
5071
}
0 commit comments