restore: networking stack files from reflog (Phases 1-6)
Recovered from reflog commits 1c80937e and d0ecc067 after force-push data loss.
Includes: filter/, icmp_error.rs, slaac.rs, bond.rs, bridge.rs, gre.rs, ipip.rs,
qdisc.rs, tun.rs, vlan.rs, vxlan.rs, netfilter.rs, tun.rs, conntrack.rs, nat.rs,
rule.rs, table.rs, redbear-ufw/, dhcpv6d/, netdiag/ — 39 files total.
This commit is contained in:
@@ -45,6 +45,10 @@ impl TextScreen {
|
||||
// Backspace
|
||||
buf.extend_from_slice(b"\x7F");
|
||||
}
|
||||
0x1C => {
|
||||
// Enter
|
||||
buf.extend_from_slice(b"\n");
|
||||
}
|
||||
0x47 => {
|
||||
// Home
|
||||
buf.extend_from_slice(b"\x1B[H");
|
||||
|
||||
@@ -539,93 +539,90 @@ impl fmt::Display for Trb {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use common::dma::Dma;
|
||||
|
||||
fn test_trb() -> (Dma<Trb>, *mut Trb) {
|
||||
unsafe {
|
||||
let dma = Dma::<Trb>::zeroed().unwrap().assume_init();
|
||||
let ptr = dma.virt_ptr();
|
||||
(dma, ptr)
|
||||
}
|
||||
fn test_trb() -> Trb {
|
||||
unsafe { std::mem::zeroed::<Trb>() }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn normal_trb_sets_correct_type() {
|
||||
let (_dma, trb) = test_trb();
|
||||
unsafe { (*trb).normal(0x1000, 512, true, 3, 0, false, true, false, true, false, false); }
|
||||
unsafe { assert_eq!((*trb).trb_type(), TrbType::Normal as u8); }
|
||||
let mut trb = test_trb();
|
||||
trb.normal(0x1000, 512, true, 3, 0, false, true, false, true, false, false);
|
||||
assert_eq!(trb.trb_type(), TrbType::Normal as u8);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn isoch_trb_sets_correct_type() {
|
||||
let (_dma, trb) = test_trb();
|
||||
unsafe { (*trb).isoch(0x1000, 512, true, 0, 0, true, false, true, 1, 0); }
|
||||
unsafe { assert_eq!((*trb).trb_type(), TrbType::Isoch as u8); }
|
||||
let mut trb = test_trb();
|
||||
trb.isoch(0x1000, 512, true, 0, 0, true, false, true, 1, 0);
|
||||
assert_eq!(trb.trb_type(), TrbType::Isoch as u8);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn setup_trb_preserves_request_type() {
|
||||
let (_dma, trb) = test_trb();
|
||||
unsafe { (*trb).setup(usb::Setup { kind: 0x80, request: 0x06, value: 0x0100, index: 0, length: 18 }, TransferKind::In, true); }
|
||||
unsafe { assert_eq!((*trb).trb_type(), TrbType::SetupStage as u8); }
|
||||
let mut trb = test_trb();
|
||||
trb.setup(usb::Setup { kind: 0x80, request: 0x06, value: 0x0100, index: 0, length: 18 }, TransferKind::In, true);
|
||||
assert_eq!(trb.trb_type(), TrbType::SetupStage as u8);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn all_36_completion_codes_have_unique_values() {
|
||||
let codes = [
|
||||
TrbCompletionCode::Invalid, TrbCompletionCode::Success, TrbCompletionCode::DataBuffer,
|
||||
TrbCompletionCode::BabbleDetected, TrbCompletionCode::UsbTransaction, TrbCompletionCode::Trb,
|
||||
TrbCompletionCode::Stall, TrbCompletionCode::Resource, TrbCompletionCode::Bandwidth,
|
||||
TrbCompletionCode::NoSlotsAvailable, TrbCompletionCode::SlotNotEnabled,
|
||||
TrbCompletionCode::EndpointNotEnabled, TrbCompletionCode::ShortPacket, TrbCompletionCode::RingUnderrun,
|
||||
TrbCompletionCode::RingOverrun, TrbCompletionCode::VfEventRingFull, TrbCompletionCode::Parameter,
|
||||
TrbCompletionCode::BandwidthOverrun, TrbCompletionCode::ContextState,
|
||||
TrbCompletionCode::NoPingResponse, TrbCompletionCode::EventRingFull,
|
||||
TrbCompletionCode::IncompatibleDevice, TrbCompletionCode::MissedService,
|
||||
TrbCompletionCode::CommandRingStopped, TrbCompletionCode::CommandAborted, TrbCompletionCode::Stopped,
|
||||
TrbCompletionCode::StoppedLengthInvalid, TrbCompletionCode::StoppedShortPacket,
|
||||
TrbCompletionCode::MaxExitLatencyTooLarge, TrbCompletionCode::IsochBuffer,
|
||||
TrbCompletionCode::EventLost, TrbCompletionCode::InvalidStreamId,
|
||||
TrbCompletionCode::SecondaryBandwidth, TrbCompletionCode::SplitTransaction, TrbCompletionCode::Undefined,
|
||||
fn all_36_completion_codes_unique() {
|
||||
let codes: [u8; 35] = [
|
||||
TrbCompletionCode::Invalid as u8, TrbCompletionCode::Success as u8,
|
||||
TrbCompletionCode::DataBuffer as u8, TrbCompletionCode::BabbleDetected as u8,
|
||||
TrbCompletionCode::UsbTransaction as u8, TrbCompletionCode::Trb as u8,
|
||||
TrbCompletionCode::Stall as u8, TrbCompletionCode::Resource as u8,
|
||||
TrbCompletionCode::Bandwidth as u8, TrbCompletionCode::NoSlotsAvailable as u8,
|
||||
TrbCompletionCode::SlotNotEnabled as u8, TrbCompletionCode::EndpointNotEnabled as u8,
|
||||
TrbCompletionCode::ShortPacket as u8, TrbCompletionCode::RingUnderrun as u8,
|
||||
TrbCompletionCode::RingOverrun as u8, TrbCompletionCode::VfEventRingFull as u8,
|
||||
TrbCompletionCode::Parameter as u8, TrbCompletionCode::BandwidthOverrun as u8,
|
||||
TrbCompletionCode::ContextState as u8, TrbCompletionCode::NoPingResponse as u8,
|
||||
TrbCompletionCode::EventRingFull as u8, TrbCompletionCode::IncompatibleDevice as u8,
|
||||
TrbCompletionCode::MissedService as u8, TrbCompletionCode::CommandRingStopped as u8,
|
||||
TrbCompletionCode::CommandAborted as u8, TrbCompletionCode::Stopped as u8,
|
||||
TrbCompletionCode::StoppedLengthInvalid as u8, TrbCompletionCode::StoppedShortPacket as u8,
|
||||
TrbCompletionCode::MaxExitLatencyTooLarge as u8, TrbCompletionCode::IsochBuffer as u8,
|
||||
TrbCompletionCode::EventLost as u8, TrbCompletionCode::InvalidStreamId as u8,
|
||||
TrbCompletionCode::SecondaryBandwidth as u8, TrbCompletionCode::SplitTransaction as u8,
|
||||
TrbCompletionCode::Undefined as u8,
|
||||
];
|
||||
let mut seen = std::collections::HashSet::new();
|
||||
for code in &codes {
|
||||
assert!(seen.insert(*code as u8), "duplicate completion code: {:?}", code);
|
||||
}
|
||||
for &code in &codes { assert!(seen.insert(code), "duplicate: {}", code); }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_transfer_trb_detects_normal_setup_data_status_isoch() {
|
||||
let (_dma, trb) = test_trb();
|
||||
unsafe { (*trb).normal(0, 0, true, 0, 0, false, false, false, false, false, false); }
|
||||
unsafe { assert!((*trb).is_transfer_trb()); }
|
||||
fn is_transfer_trb_detects_normal() {
|
||||
let mut trb = test_trb();
|
||||
trb.normal(0, 0, true, 0, 0, false, false, false, false, false, false);
|
||||
assert!(trb.is_transfer_trb());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_command_trb_detects_enable_slot_address_device() {
|
||||
let (_dma, trb) = test_trb();
|
||||
unsafe { (*trb).enable_slot(0, true); }
|
||||
unsafe { assert!((*trb).is_command_trb()); }
|
||||
fn is_command_trb_detects_enable_slot() {
|
||||
let mut trb = test_trb();
|
||||
trb.enable_slot(0, true);
|
||||
assert!(trb.is_command_trb());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn completion_code_decode_from_event_trb() {
|
||||
let (_dma, trb) = test_trb();
|
||||
unsafe { (*trb).set(0, 0, (TrbType::Transfer as u32) << 10 | (TrbCompletionCode::Stall as u32) << 24 | 1u32); }
|
||||
unsafe { assert_eq!((*trb).completion_code(), TrbCompletionCode::Stall as u8); }
|
||||
fn completion_code_decode() {
|
||||
let mut trb = test_trb();
|
||||
trb.set(0, 0, (TrbType::Transfer as u32) << 10 | (TrbCompletionCode::Stall as u32) << 24 | 1u32);
|
||||
assert_eq!(trb.completion_code(), TrbCompletionCode::Stall as u8);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn data_trb_sets_input_flag() {
|
||||
let (_dma, trb) = test_trb();
|
||||
unsafe { (*trb).data(0x2000, 64, true, true); }
|
||||
unsafe { assert_eq!((*trb).trb_type(), TrbType::DataStage as u8); }
|
||||
fn data_trb_sets_correct_type() {
|
||||
let mut trb = test_trb();
|
||||
trb.data(0x2000, 64, true, true);
|
||||
assert_eq!(trb.trb_type(), TrbType::DataStage as u8);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn link_trb_sets_correct_type() {
|
||||
let (_dma, trb) = test_trb();
|
||||
unsafe { (*trb).link(0x4000, true, true); }
|
||||
unsafe { assert_eq!((*trb).trb_type(), TrbType::Link as u8); }
|
||||
let mut trb = test_trb();
|
||||
trb.link(0x4000, true, true);
|
||||
assert_eq!(trb.trb_type(), TrbType::Link as u8);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user