Skip to content

Commit 94fa5e6

Browse files
committed
save the filter value
1 parent e602370 commit 94fa5e6

File tree

3 files changed

+41
-35
lines changed

3 files changed

+41
-35
lines changed

vm/devices/net/netvsp/src/lib.rs

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ struct NetChannel<T: RingMem> {
382382
pending_send_size: usize,
383383
restart: Option<CoordinatorMessage>,
384384
can_use_ring_size_opt: bool,
385-
stop_rx: bool,
385+
packet_filter: u32,
386386
}
387387

388388
/// Buffers used during packet processing.
@@ -591,7 +591,7 @@ struct PrimaryChannelState {
591591
tx_spread_sent: bool,
592592
guest_link_up: bool,
593593
pending_link_action: PendingLinkAction,
594-
stop_rx: bool,
594+
packet_filter: u32,
595595
}
596596

597597
impl Inspect for PrimaryChannelState {
@@ -783,7 +783,7 @@ impl PrimaryChannelState {
783783
tx_spread_sent: false,
784784
guest_link_up: true,
785785
pending_link_action: PendingLinkAction::Default,
786-
stop_rx: false,
786+
packet_filter: rndisprot::NPROTO_PACKET_FILTER,
787787
}
788788
}
789789

@@ -800,7 +800,7 @@ impl PrimaryChannelState {
800800
tx_spread_sent: bool,
801801
guest_link_down: bool,
802802
pending_link_action: Option<bool>,
803-
stop_rx: bool,
803+
packet_filter: u32,
804804
) -> Result<Self, NetRestoreError> {
805805
// Restore control messages.
806806
let control_messages_len = control_messages.iter().map(|msg| msg.data.len()).sum();
@@ -894,7 +894,7 @@ impl PrimaryChannelState {
894894
tx_spread_sent,
895895
guest_link_up: !guest_link_down,
896896
pending_link_action,
897-
stop_rx,
897+
packet_filter,
898898
})
899899
}
900900
}
@@ -1198,7 +1198,8 @@ impl VmbusDevice for Nic {
11981198
.adapter
11991199
.num_sub_channels_opened
12001200
.fetch_add(1, Ordering::SeqCst);
1201-
let r = self.insert_worker(channel_idx, open_request, state, true, false);
1201+
let packet_filter = rndisprot::NDIS_PACKET_TYPE_NONE; // No traffic until guest sets filter.
1202+
let r = self.insert_worker(channel_idx, open_request, state, true, packet_filter);
12021203
if channel_idx != 0
12031204
&& num_opened + 1 == self.coordinator.state_mut().unwrap().num_queues as usize
12041205
{
@@ -1338,7 +1339,7 @@ impl Nic {
13381339
open_request: &OpenRequest,
13391340
state: WorkerState,
13401341
start: bool,
1341-
stop_rx: bool,
1342+
packet_filter: u32,
13421343
) -> Result<(), OpenError> {
13431344
let coordinator = self.coordinator.state_mut().unwrap();
13441345

@@ -1370,7 +1371,7 @@ impl Nic {
13701371
pending_send_size: 0,
13711372
restart: None,
13721373
can_use_ring_size_opt,
1373-
stop_rx,
1374+
packet_filter,
13741375
},
13751376
state,
13761377
coordinator_send: self.coordinator_send.clone().unwrap(),
@@ -1460,7 +1461,7 @@ impl Nic {
14601461
mut control: RestoreControl<'_>,
14611462
state: saved_state::SavedState,
14621463
) -> Result<(), NetRestoreError> {
1463-
let mut channel_stop_rx = false;
1464+
let mut channel_packet_filter = 0u32; // set to primary packet filter
14641465
if let Some(state) = state.open {
14651466
let open = match &state.primary {
14661467
saved_state::Primary::Version => vec![true],
@@ -1545,7 +1546,7 @@ impl Nic {
15451546
tx_spread_sent,
15461547
guest_link_down,
15471548
pending_link_action,
1548-
stop_rx,
1549+
packet_filter,
15491550
} = ready;
15501551

15511552
let version = check_version(version)
@@ -1608,9 +1609,9 @@ impl Nic {
16081609
tx_spread_sent,
16091610
guest_link_down,
16101611
pending_link_action,
1611-
stop_rx,
1612+
packet_filter,
16121613
)?;
1613-
channel_stop_rx = primary.stop_rx;
1614+
channel_packet_filter = primary.packet_filter;
16141615
active.primary = Some(primary);
16151616
}
16161617

@@ -1634,7 +1635,7 @@ impl Nic {
16341635
&request.unwrap(),
16351636
state,
16361637
false,
1637-
channel_stop_rx,
1638+
channel_packet_filter,
16381639
)?;
16391640
}
16401641
}
@@ -1827,7 +1828,7 @@ impl Nic {
18271828
tx_spread_sent: primary.tx_spread_sent,
18281829
guest_link_down: !primary.guest_link_up,
18291830
pending_link_action,
1830-
stop_rx: primary.stop_rx,
1831+
packet_filter: primary.packet_filter,
18311832
})
18321833
}
18331834
};
@@ -2802,13 +2803,13 @@ impl<T: RingMem> NetChannel<T> {
28022803
tracing::trace!(?request, "handling control message MESSAGE_TYPE_SET_MSG");
28032804

28042805
let status = match self.adapter.handle_oid_set(primary, request.oid, reader) {
2805-
Ok((restart_endpoint, stop_rx)) => {
2806+
Ok((restart_endpoint, packet_filter)) => {
28062807
// Restart the endpoint if the OID changed some critical
28072808
// endpoint property.
28082809
if restart_endpoint {
28092810
self.restart = Some(CoordinatorMessage::Restart);
28102811
}
2811-
self.stop_rx = stop_rx;
2812+
self.packet_filter = packet_filter;
28122813
rndisprot::STATUS_SUCCESS
28132814
}
28142815
Err(err) => {
@@ -3025,16 +3026,12 @@ enum OidError {
30253026
BadVersion,
30263027
#[error("feature {0} not supported")]
30273028
NotSupported(&'static str),
3028-
#[error("packet filter {0} not supported")]
3029-
UnsupportedFilter(u32),
30303029
}
30313030

30323031
impl OidError {
30333032
fn as_status(&self) -> u32 {
30343033
match self {
3035-
OidError::UnknownOid | OidError::NotSupported(_) | OidError::UnsupportedFilter(_) => {
3036-
rndisprot::STATUS_NOT_SUPPORTED
3037-
}
3034+
OidError::UnknownOid | OidError::NotSupported(_) => rndisprot::STATUS_NOT_SUPPORTED,
30383035
OidError::BadVersion => rndisprot::STATUS_BAD_VERSION,
30393036
OidError::InvalidInput(_) => rndisprot::STATUS_INVALID_DATA,
30403037
OidError::Access(_) => rndisprot::STATUS_FAILURE,
@@ -3313,14 +3310,14 @@ impl Adapter {
33133310
primary: &mut PrimaryChannelState,
33143311
oid: rndisprot::Oid,
33153312
reader: impl MemoryRead + Clone,
3316-
) -> Result<(bool, bool), OidError> {
3313+
) -> Result<(bool, u32), OidError> {
33173314
tracing::debug!(?oid, "oid set");
33183315

33193316
let mut restart_endpoint = false;
3320-
let mut stop_rx = false;
3317+
let mut packet_filter = 0u32;
33213318
match oid {
33223319
rndisprot::Oid::OID_GEN_CURRENT_PACKET_FILTER => {
3323-
stop_rx = self.oid_set_packet_filter(reader, primary)?;
3320+
packet_filter = self.oid_set_packet_filter(reader, primary)?;
33243321
}
33253322
rndisprot::Oid::OID_TCP_OFFLOAD_PARAMETERS => {
33263323
self.oid_set_offload_parameters(reader, primary)?;
@@ -3347,7 +3344,7 @@ impl Adapter {
33473344
return Err(OidError::UnknownOid);
33483345
}
33493346
}
3350-
Ok((restart_endpoint, stop_rx))
3347+
Ok((restart_endpoint, packet_filter))
33513348
}
33523349

33533350
fn oid_set_rss_parameters(
@@ -3409,15 +3406,11 @@ impl Adapter {
34093406
&self,
34103407
reader: impl MemoryRead + Clone,
34113408
primary: &mut PrimaryChannelState,
3412-
) -> Result<bool, OidError> {
3409+
) -> Result<u32, OidError> {
34133410
let filter: rndisprot::RndisPacketFilterOidValue = reader.clone().read_plain()?;
3414-
if filter != 0 {
3415-
// TODO:
3416-
// Maybe dont return error since previously we were not?
3417-
return Err(OidError::UnsupportedFilter(filter));
3418-
}
3419-
primary.stop_rx = true;
3420-
Ok(primary.stop_rx)
3411+
primary.packet_filter = filter;
3412+
tracing::debug!(filter, "set packet filter");
3413+
Ok(primary.packet_filter)
34213414
}
34223415

34233416
fn oid_set_offload_parameters(
@@ -4968,7 +4961,11 @@ impl<T: 'static + RingMem> NetChannel<T> {
49684961
data: &mut ProcessingData,
49694962
epqueue: &mut dyn net_backend::Queue,
49704963
) -> Result<bool, WorkerError> {
4971-
if self.stop_rx {
4964+
if self.packet_filter == rndisprot::NDIS_PACKET_TYPE_NONE {
4965+
tracing::debug!(
4966+
packet_filter = self.packet_filter,
4967+
"rx packet not processed"
4968+
);
49724969
return Ok(false);
49734970
}
49744971
let n = epqueue

vm/devices/net/netvsp/src/rndisprot.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,3 +1085,12 @@ open_enum! {
10851085
}
10861086

10871087
pub type RndisPacketFilterOidValue = u32;
1088+
1089+
// Rndis Packet Filter Flags (OID_GEN_CURRENT_PACKET_FILTER)
1090+
pub const NDIS_PACKET_TYPE_NONE: u32 = 0x00000000;
1091+
pub const NDIS_PACKET_TYPE_DIRECTED: u32 = 0x00000001;
1092+
pub const NDIS_PACKET_TYPE_MULTICAST: u32 = 0x00000002;
1093+
pub const NDIS_PACKET_TYPE_ALL_MULTICAST: u32 = 0x00000004;
1094+
pub const NDIS_PACKET_TYPE_BROADCAST: u32 = 0x00000008;
1095+
pub const NPROTO_PACKET_FILTER: u32 =
1096+
NDIS_PACKET_TYPE_DIRECTED | NDIS_PACKET_TYPE_ALL_MULTICAST | NDIS_PACKET_TYPE_BROADCAST;

vm/devices/net/netvsp/src/saved_state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ pub struct ReadyPrimary {
121121
#[mesh(15)]
122122
pub pending_link_action: Option<bool>,
123123
#[mesh(16)]
124-
pub stop_rx: bool,
124+
pub packet_filter: u32,
125125
}
126126

127127
#[derive(Debug, Protobuf)]

0 commit comments

Comments
 (0)