Skip to content

Commit

Permalink
vlan: Default reorder-headers: true
Browse files Browse the repository at this point in the history
When `reorder-headers` is not mentioned in desire state, we should
set it to true to be consistent with default behavior of kernel and
NetworkManager.

Integration test cases included.

Resolves: https://issues.redhat.com/browse/RHEL-33362

Signed-off-by: Gris Ge <fge@redhat.com>
  • Loading branch information
cathay4t committed May 22, 2024
1 parent 56d0749 commit 98ceb34
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 2 deletions.
1 change: 1 addition & 0 deletions rust/src/lib/iface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,7 @@ impl MergedInterface {
self.post_inter_ifaces_process_sriov()?;
self.post_inter_ifaces_process_vrf()?;
self.post_inter_ifaces_process_bond()?;
self.post_inter_ifaces_process_vlan();

if let Some(apply_iface) = self.for_apply.as_mut() {
apply_iface.sanitize(true)?;
Expand Down
33 changes: 31 additions & 2 deletions rust/src/lib/ifaces/vlan.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: Apache-2.0

use serde::{Deserialize, Serialize};

use crate::{BaseInterface, InterfaceType};
use crate::{BaseInterface, Interface, InterfaceType, MergedInterface};

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
Expand Down Expand Up @@ -66,7 +68,7 @@ pub struct VlanConfig {
/// Could be `gvrp`, `mvrp` or `none`. Default to none if not defined.
#[serde(skip_serializing_if = "Option::is_none")]
pub registration_protocol: Option<VlanRegistrationProtocol>,
/// reordering of output packet headers
/// reordering of output packet headers. Default to True if not defined.
#[serde(skip_serializing_if = "Option::is_none")]
pub reorder_headers: Option<bool>,
/// loose binding of the interface to its master device's operating state
Expand Down Expand Up @@ -113,3 +115,30 @@ pub enum VlanRegistrationProtocol {
/// No Registration Protocol
None,
}

impl MergedInterface {
// Default reorder_headers to Some(true) unless current interface
// has `reorder_headers` set to `false`
pub(crate) fn post_inter_ifaces_process_vlan(&mut self) {
if let Some(Interface::Vlan(apply_iface)) = self.for_apply.as_mut() {
if let Some(Interface::Vlan(cur_iface)) = self.current.as_ref() {
if cur_iface
.vlan
.as_ref()
.and_then(|v| v.reorder_headers.as_ref())
!= Some(&false)
{
if let Some(vlan_conf) = apply_iface.vlan.as_mut() {
if vlan_conf.reorder_headers.is_none() {
vlan_conf.reorder_headers = Some(true);
}
}
}
} else if let Some(vlan_conf) = apply_iface.vlan.as_mut() {
if vlan_conf.reorder_headers.is_none() {
vlan_conf.reorder_headers = Some(true);
}
}
}
}
}
52 changes: 52 additions & 0 deletions tests/integration/vlan_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,3 +428,55 @@ def test_configure_vlan_with_mvrp(vlan_on_eth1):
] = VLAN.REGISTRATION_PROTOCOL_NONE
libnmstate.apply(flags_state)
assertlib.assert_state_match(flags_state)


def test_new_vlan_default_to_reorder_headers(eth1_up):
with vlan_interface(VLAN_IFNAME, 102, "eth1") as desired_state:
desired_state[Interface.KEY][0][VLAN.CONFIG_SUBTREE][
VLAN.REORDER_HEADERS
] = True
assertlib.assert_state_match(desired_state)
assertlib.assert_absent(VLAN_IFNAME)


@pytest.fixture
def vlan_on_eth1_with_reorder_headers_off(vlan_on_eth1):
desired_state = {
Interface.KEY: [
{
Interface.NAME: VLAN_IFNAME,
Interface.TYPE: InterfaceType.VLAN,
Interface.STATE: InterfaceState.UP,
VLAN.CONFIG_SUBTREE: {
VLAN.ID: 102,
VLAN.BASE_IFACE: "eth1",
VLAN.REORDER_HEADERS: False,
},
}
]
}
libnmstate.apply(desired_state)
yield


def test_vlan_do_not_override_reorder_headers_if_not_mentioned(
vlan_on_eth1_with_reorder_headers_off,
):
desired_state = {
Interface.KEY: [
{
Interface.NAME: VLAN_IFNAME,
Interface.TYPE: InterfaceType.VLAN,
Interface.STATE: InterfaceState.UP,
VLAN.CONFIG_SUBTREE: {
VLAN.ID: 102,
VLAN.BASE_IFACE: "eth1",
},
}
]
}
libnmstate.apply(desired_state)
current_state = statelib.show_only((VLAN_IFNAME,))
assert not current_state[Interface.KEY][0][VLAN.CONFIG_SUBTREE][
VLAN.REORDER_HEADERS
]

0 comments on commit 98ceb34

Please sign in to comment.