Skip to content

Commit

Permalink
Add VLAN to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DerFetzer committed Feb 4, 2024
1 parent c58c8d2 commit d5f1a2a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
17 changes: 16 additions & 1 deletion src/iface/interface/tests/ipv4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,22 @@ fn test_handle_igmp(#[case] medium: Medium) {
#[cfg(feature = "medium-ethernet")]
Medium::Ethernet => {
let eth_frame = EthernetFrame::new_checked(frame).ok()?;
Ipv4Packet::new_checked(eth_frame.payload()).ok()?
#[cfg(feature = "proto-vlan")]
let ipv4_payload = {
let vlan_packet = VlanPacket::new_checked(eth_frame.payload()).ok()?;
let num_vlan_headers =
if vlan_packet.ethertype() == EthernetProtocol::VlanInner {
2
} else {
1
};
&eth_frame.payload()
[VlanPacket::<&[u8]>::header_len() * num_vlan_headers..]
};
#[cfg(not(feature = "proto-vlan"))]
let ipv4_payload = eth_frame.payload();

Ipv4Packet::new_checked(ipv4_payload).ok()?
}
#[cfg(feature = "medium-ip")]
Medium::Ip => Ipv4Packet::new_checked(&frame[..]).ok()?,
Expand Down
11 changes: 10 additions & 1 deletion src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use crate::wire::*;
pub(crate) fn setup<'a>(medium: Medium) -> (Interface, SocketSet<'a>, TestingDevice) {
let mut device = TestingDevice::new(medium);

let config = Config::new(match medium {
#[allow(unused_mut)]
let mut config = Config::new(match medium {
#[cfg(feature = "medium-ethernet")]
Medium::Ethernet => {
HardwareAddress::Ethernet(EthernetAddress([0x02, 0x02, 0x02, 0x02, 0x02, 0x02]))
Expand All @@ -17,6 +18,14 @@ pub(crate) fn setup<'a>(medium: Medium) -> (Interface, SocketSet<'a>, TestingDev
])),
});

#[cfg(feature = "proto-vlan")]
{
config.vlan_config = Some(VlanConfig {
inner_vlan_id: 100,
outer_vlan_id: Some(200),
});
}

let mut iface = Interface::new(config, &mut device, Instant::ZERO);

#[cfg(feature = "proto-ipv4")]
Expand Down

0 comments on commit d5f1a2a

Please sign in to comment.