mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-05 03:20:18 +01:00
device: introduce generic function to inherit MTU from parent
Introduce a generic function to set a MTU based on parent's one. Also define a device-specific @mtu_parent_delta value that specifies the difference from parent MTU that should be set by default. For VLAN it is zero but other interface types (for example MACsec) require a positive value due to encapsulation overhead.
This commit is contained in:
parent
6455a4e528
commit
5cf57f4522
4 changed files with 36 additions and 21 deletions
|
|
@ -168,6 +168,9 @@ guint32 nm_device_get_configured_mtu_from_connection (NMDevice *device,
|
|||
|
||||
guint32 nm_device_get_configured_mtu_for_wired (NMDevice *self, NMDeviceMtuSource *out_source);
|
||||
|
||||
guint32 nm_device_get_configured_mtu_wired_parent (NMDevice *self,
|
||||
NMDeviceMtuSource *out_source);
|
||||
|
||||
void nm_device_commit_mtu (NMDevice *self);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
|||
|
|
@ -502,26 +502,6 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *out_failure_reason)
|
|||
return NM_ACT_STAGE_RETURN_SUCCESS;
|
||||
}
|
||||
|
||||
static guint32
|
||||
get_configured_mtu (NMDevice *self, NMDeviceMtuSource *out_source)
|
||||
{
|
||||
guint32 mtu = 0;
|
||||
int ifindex;
|
||||
|
||||
mtu = nm_device_get_configured_mtu_for_wired (self, out_source);
|
||||
if (*out_source != NM_DEVICE_MTU_SOURCE_NONE)
|
||||
return mtu;
|
||||
|
||||
/* Inherit the MTU from parent device, if any */
|
||||
ifindex = nm_device_parent_get_ifindex (self);
|
||||
if (ifindex > 0) {
|
||||
mtu = nm_platform_link_get_mtu (nm_device_get_platform (NM_DEVICE (self)), ifindex);
|
||||
*out_source = NM_DEVICE_MTU_SOURCE_PARENT;
|
||||
}
|
||||
|
||||
return mtu;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
|
|
@ -577,6 +557,7 @@ nm_device_vlan_class_init (NMDeviceVlanClass *klass)
|
|||
device_class->connection_type_supported = NM_SETTING_VLAN_SETTING_NAME;
|
||||
device_class->connection_type_check_compatible = NM_SETTING_VLAN_SETTING_NAME;
|
||||
device_class->link_types = NM_DEVICE_DEFINE_LINK_TYPES (NM_LINK_TYPE_VLAN);
|
||||
device_class->mtu_parent_delta = 0; /* VLANs can have the same MTU of parent */
|
||||
|
||||
device_class->create_and_realize = create_and_realize;
|
||||
device_class->link_changed = link_changed;
|
||||
|
|
@ -584,7 +565,7 @@ nm_device_vlan_class_init (NMDeviceVlanClass *klass)
|
|||
device_class->get_generic_capabilities = get_generic_capabilities;
|
||||
device_class->act_stage1_prepare_set_hwaddr_ethernet = TRUE;
|
||||
device_class->act_stage1_prepare = act_stage1_prepare;
|
||||
device_class->get_configured_mtu = get_configured_mtu;
|
||||
device_class->get_configured_mtu = nm_device_get_configured_mtu_wired_parent;
|
||||
device_class->is_available = is_available;
|
||||
device_class->parent_changed_notify = parent_changed_notify;
|
||||
|
||||
|
|
|
|||
|
|
@ -9324,6 +9324,33 @@ nm_device_get_configured_mtu_for_wired (NMDevice *self, NMDeviceMtuSource *out_s
|
|||
out_source);
|
||||
}
|
||||
|
||||
guint32
|
||||
nm_device_get_configured_mtu_wired_parent (NMDevice *self,
|
||||
NMDeviceMtuSource *out_source)
|
||||
{
|
||||
guint32 mtu = 0;
|
||||
int ifindex;
|
||||
|
||||
mtu = nm_device_get_configured_mtu_for_wired (self, out_source);
|
||||
if (*out_source != NM_DEVICE_MTU_SOURCE_NONE) {
|
||||
nm_assert (mtu > 0);
|
||||
return mtu;
|
||||
}
|
||||
|
||||
/* Inherit the MTU from parent device, if any */
|
||||
ifindex = nm_device_parent_get_ifindex (self);
|
||||
if (ifindex > 0) {
|
||||
mtu = nm_platform_link_get_mtu (nm_device_get_platform (self), ifindex);
|
||||
if (mtu >= NM_DEVICE_GET_CLASS (self)->mtu_parent_delta) {
|
||||
mtu -= NM_DEVICE_GET_CLASS (self)->mtu_parent_delta;
|
||||
*out_source = NM_DEVICE_MTU_SOURCE_PARENT;
|
||||
} else
|
||||
mtu = 0;
|
||||
}
|
||||
|
||||
return mtu;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -225,6 +225,10 @@ typedef struct _NMDeviceClass {
|
|||
|
||||
const NMLinkType *link_types;
|
||||
|
||||
/* if the device MTU is set based on parent's one, this specifies
|
||||
* a delta in the MTU allowed value due the encapsulation overhead */
|
||||
guint16 mtu_parent_delta;
|
||||
|
||||
/* Whether the device type is a master-type. This depends purely on the
|
||||
* type (NMDeviceClass), not the actual device instance. */
|
||||
bool is_master:1;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue