mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-09 07:08:02 +02:00
platform: allow setting the MTU at link creation time
Add a parameter to the 'link_add()' virtual function so that the MTU will be configured (via netlink) by the kernel when creating the link. https://bugzilla.redhat.com/show_bug.cgi?id=1778590 Signed-off-by: Antonio Cardace <acardace@redhat.com>
This commit is contained in:
parent
0829dbcd3d
commit
ba2ee46254
4 changed files with 57 additions and 21 deletions
|
|
@ -225,7 +225,8 @@ link_add_pre(NMPlatform *platform,
|
||||||
const char *name,
|
const char *name,
|
||||||
NMLinkType type,
|
NMLinkType type,
|
||||||
const void *address,
|
const void *address,
|
||||||
size_t address_len)
|
size_t address_len,
|
||||||
|
guint32 mtu)
|
||||||
{
|
{
|
||||||
NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE(platform);
|
NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE(platform);
|
||||||
NMFakePlatformLink * device;
|
NMFakePlatformLink * device;
|
||||||
|
|
@ -251,6 +252,7 @@ link_add_pre(NMPlatform *platform,
|
||||||
link->ifindex = name ? ifindex : 0;
|
link->ifindex = name ? ifindex : 0;
|
||||||
link->type = type;
|
link->type = type;
|
||||||
link->kind = g_intern_string(nm_link_type_to_string(type));
|
link->kind = g_intern_string(nm_link_type_to_string(type));
|
||||||
|
link->mtu = mtu;
|
||||||
link->initialized = TRUE;
|
link->initialized = TRUE;
|
||||||
if (name)
|
if (name)
|
||||||
strcpy(link->name, name);
|
strcpy(link->name, name);
|
||||||
|
|
@ -285,6 +287,7 @@ link_add(NMPlatform * platform,
|
||||||
int parent,
|
int parent,
|
||||||
const void * address,
|
const void * address,
|
||||||
size_t address_len,
|
size_t address_len,
|
||||||
|
guint32 mtu,
|
||||||
gconstpointer extra_data,
|
gconstpointer extra_data,
|
||||||
const NMPlatformLink **out_link)
|
const NMPlatformLink **out_link)
|
||||||
{
|
{
|
||||||
|
|
@ -300,7 +303,7 @@ link_add(NMPlatform * platform,
|
||||||
NMPObject * dev_obj;
|
NMPObject * dev_obj;
|
||||||
NMPObject * dev_lnk = NULL;
|
NMPObject * dev_lnk = NULL;
|
||||||
|
|
||||||
device = link_add_pre(platform, name, type, address, address_len);
|
device = link_add_pre(platform, name, type, address, address_len, mtu);
|
||||||
|
|
||||||
g_assert(device);
|
g_assert(device);
|
||||||
|
|
||||||
|
|
@ -326,7 +329,7 @@ link_add(NMPlatform * platform,
|
||||||
case NM_LINK_TYPE_VETH:
|
case NM_LINK_TYPE_VETH:
|
||||||
veth_peer = extra_data;
|
veth_peer = extra_data;
|
||||||
g_assert(veth_peer);
|
g_assert(veth_peer);
|
||||||
device_veth = link_add_pre(platform, veth_peer, type, NULL, 0);
|
device_veth = link_add_pre(platform, veth_peer, type, NULL, 0, 0);
|
||||||
break;
|
break;
|
||||||
case NM_LINK_TYPE_VLAN:
|
case NM_LINK_TYPE_VLAN:
|
||||||
{
|
{
|
||||||
|
|
@ -401,7 +404,7 @@ link_add_one(NMPlatform *platform,
|
||||||
NMPCacheOpsType cache_op;
|
NMPCacheOpsType cache_op;
|
||||||
int ifindex;
|
int ifindex;
|
||||||
|
|
||||||
device = link_add_pre(platform, name, NM_LINK_TYPE_VLAN, NULL, 0);
|
device = link_add_pre(platform, name, NM_LINK_TYPE_VLAN, NULL, 0, 0);
|
||||||
|
|
||||||
ifindex = NMP_OBJECT_CAST_LINK(device->obj)->ifindex;
|
ifindex = NMP_OBJECT_CAST_LINK(device->obj)->ifindex;
|
||||||
|
|
||||||
|
|
@ -1313,10 +1316,10 @@ nm_fake_platform_setup(void)
|
||||||
|
|
||||||
nm_platform_setup(platform);
|
nm_platform_setup(platform);
|
||||||
|
|
||||||
link_add(platform, NM_LINK_TYPE_LOOPBACK, "lo", 0, NULL, 0, NULL, NULL);
|
link_add(platform, NM_LINK_TYPE_LOOPBACK, "lo", 0, NULL, 0, 0, NULL, NULL);
|
||||||
link_add(platform, NM_LINK_TYPE_ETHERNET, "eth0", 0, NULL, 0, NULL, NULL);
|
link_add(platform, NM_LINK_TYPE_ETHERNET, "eth0", 0, NULL, 0, 0, NULL, NULL);
|
||||||
link_add(platform, NM_LINK_TYPE_ETHERNET, "eth1", 0, NULL, 0, NULL, NULL);
|
link_add(platform, NM_LINK_TYPE_ETHERNET, "eth1", 0, NULL, 0, 0, NULL, NULL);
|
||||||
link_add(platform, NM_LINK_TYPE_ETHERNET, "eth2", 0, NULL, 0, NULL, NULL);
|
link_add(platform, NM_LINK_TYPE_ETHERNET, "eth2", 0, NULL, 0, 0, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
||||||
|
|
@ -7341,6 +7341,7 @@ link_add(NMPlatform * platform,
|
||||||
int parent,
|
int parent,
|
||||||
const void * address,
|
const void * address,
|
||||||
size_t address_len,
|
size_t address_len,
|
||||||
|
guint32 mtu,
|
||||||
gconstpointer extra_data,
|
gconstpointer extra_data,
|
||||||
const NMPlatformLink **out_link)
|
const NMPlatformLink **out_link)
|
||||||
{
|
{
|
||||||
|
|
@ -7368,6 +7369,9 @@ link_add(NMPlatform * platform,
|
||||||
if (address && address_len)
|
if (address && address_len)
|
||||||
NLA_PUT(nlmsg, IFLA_ADDRESS, address_len, address);
|
NLA_PUT(nlmsg, IFLA_ADDRESS, address_len, address);
|
||||||
|
|
||||||
|
if (mtu)
|
||||||
|
NLA_PUT_U32(nlmsg, IFLA_MTU, mtu);
|
||||||
|
|
||||||
if (!_nl_msg_new_link_set_linkinfo(nlmsg, type, extra_data))
|
if (!_nl_msg_new_link_set_linkinfo(nlmsg, type, extra_data))
|
||||||
return -NME_UNSPEC;
|
return -NME_UNSPEC;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1230,11 +1230,13 @@ nm_platform_link_add(NMPlatform * self,
|
||||||
int parent,
|
int parent,
|
||||||
const void * address,
|
const void * address,
|
||||||
size_t address_len,
|
size_t address_len,
|
||||||
|
guint32 mtu,
|
||||||
gconstpointer extra_data,
|
gconstpointer extra_data,
|
||||||
const NMPlatformLink **out_link)
|
const NMPlatformLink **out_link)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
char addr_buf[NM_UTILS_HWADDR_LEN_MAX * 3];
|
char addr_buf[NM_UTILS_HWADDR_LEN_MAX * 3];
|
||||||
|
char mtu_buf[16];
|
||||||
char parent_buf[64];
|
char parent_buf[64];
|
||||||
char buf[512];
|
char buf[512];
|
||||||
|
|
||||||
|
|
@ -1254,6 +1256,7 @@ nm_platform_link_add(NMPlatform * self,
|
||||||
"\"%s\"" /* name */
|
"\"%s\"" /* name */
|
||||||
"%s%s" /* parent */
|
"%s%s" /* parent */
|
||||||
"%s%s" /* address */
|
"%s%s" /* address */
|
||||||
|
"%s%s" /* mtu */
|
||||||
"%s" /* extra_data */
|
"%s" /* extra_data */
|
||||||
"",
|
"",
|
||||||
nm_link_type_to_string(type),
|
nm_link_type_to_string(type),
|
||||||
|
|
@ -1263,6 +1266,8 @@ nm_platform_link_add(NMPlatform * self,
|
||||||
address ? ", address: " : "",
|
address ? ", address: " : "",
|
||||||
address ? _nm_utils_hwaddr_ntoa(address, address_len, FALSE, addr_buf, sizeof(addr_buf))
|
address ? _nm_utils_hwaddr_ntoa(address, address_len, FALSE, addr_buf, sizeof(addr_buf))
|
||||||
: "",
|
: "",
|
||||||
|
mtu ? ", mtu: " : "",
|
||||||
|
mtu ? nm_sprintf_buf(mtu_buf, "%u", mtu) : "",
|
||||||
({
|
({
|
||||||
char *buf_p = buf;
|
char *buf_p = buf;
|
||||||
gsize buf_len = sizeof(buf);
|
gsize buf_len = sizeof(buf);
|
||||||
|
|
@ -1345,7 +1350,8 @@ nm_platform_link_add(NMPlatform * self,
|
||||||
buf;
|
buf;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return klass->link_add(self, type, name, parent, address, address_len, extra_data, out_link);
|
return klass
|
||||||
|
->link_add(self, type, name, parent, address, address_len, mtu, extra_data, out_link);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1097,6 +1097,7 @@ typedef struct {
|
||||||
int parent,
|
int parent,
|
||||||
const void * address,
|
const void * address,
|
||||||
size_t address_len,
|
size_t address_len,
|
||||||
|
guint32 mtu,
|
||||||
gconstpointer extra_data,
|
gconstpointer extra_data,
|
||||||
const NMPlatformLink **out_link);
|
const NMPlatformLink **out_link);
|
||||||
gboolean (*link_delete)(NMPlatform *self, int ifindex);
|
gboolean (*link_delete)(NMPlatform *self, int ifindex);
|
||||||
|
|
@ -1544,6 +1545,7 @@ int nm_platform_link_add(NMPlatform * self,
|
||||||
int parent,
|
int parent,
|
||||||
const void * address,
|
const void * address,
|
||||||
size_t address_len,
|
size_t address_len,
|
||||||
|
guint32 mtu,
|
||||||
gconstpointer extra_data,
|
gconstpointer extra_data,
|
||||||
const NMPlatformLink **out_link);
|
const NMPlatformLink **out_link);
|
||||||
|
|
||||||
|
|
@ -1553,13 +1555,13 @@ nm_platform_link_veth_add(NMPlatform * self,
|
||||||
const char * peer,
|
const char * peer,
|
||||||
const NMPlatformLink **out_link)
|
const NMPlatformLink **out_link)
|
||||||
{
|
{
|
||||||
return nm_platform_link_add(self, NM_LINK_TYPE_VETH, name, 0, NULL, 0, peer, out_link);
|
return nm_platform_link_add(self, NM_LINK_TYPE_VETH, name, 0, NULL, 0, 0, peer, out_link);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
nm_platform_link_dummy_add(NMPlatform *self, const char *name, const NMPlatformLink **out_link)
|
nm_platform_link_dummy_add(NMPlatform *self, const char *name, const NMPlatformLink **out_link)
|
||||||
{
|
{
|
||||||
return nm_platform_link_add(self, NM_LINK_TYPE_DUMMY, name, 0, NULL, 0, NULL, out_link);
|
return nm_platform_link_add(self, NM_LINK_TYPE_DUMMY, name, 0, NULL, 0, 0, NULL, out_link);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
|
|
@ -1576,6 +1578,7 @@ nm_platform_link_bridge_add(NMPlatform * self,
|
||||||
0,
|
0,
|
||||||
address,
|
address,
|
||||||
address_len,
|
address_len,
|
||||||
|
0,
|
||||||
props,
|
props,
|
||||||
out_link);
|
out_link);
|
||||||
}
|
}
|
||||||
|
|
@ -1583,19 +1586,19 @@ nm_platform_link_bridge_add(NMPlatform * self,
|
||||||
static inline int
|
static inline int
|
||||||
nm_platform_link_bond_add(NMPlatform *self, const char *name, const NMPlatformLink **out_link)
|
nm_platform_link_bond_add(NMPlatform *self, const char *name, const NMPlatformLink **out_link)
|
||||||
{
|
{
|
||||||
return nm_platform_link_add(self, NM_LINK_TYPE_BOND, name, 0, NULL, 0, NULL, out_link);
|
return nm_platform_link_add(self, NM_LINK_TYPE_BOND, name, 0, NULL, 0, 0, NULL, out_link);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
nm_platform_link_team_add(NMPlatform *self, const char *name, const NMPlatformLink **out_link)
|
nm_platform_link_team_add(NMPlatform *self, const char *name, const NMPlatformLink **out_link)
|
||||||
{
|
{
|
||||||
return nm_platform_link_add(self, NM_LINK_TYPE_TEAM, name, 0, NULL, 0, NULL, out_link);
|
return nm_platform_link_add(self, NM_LINK_TYPE_TEAM, name, 0, NULL, 0, 0, NULL, out_link);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
nm_platform_link_wireguard_add(NMPlatform *self, const char *name, const NMPlatformLink **out_link)
|
nm_platform_link_wireguard_add(NMPlatform *self, const char *name, const NMPlatformLink **out_link)
|
||||||
{
|
{
|
||||||
return nm_platform_link_add(self, NM_LINK_TYPE_WIREGUARD, name, 0, NULL, 0, NULL, out_link);
|
return nm_platform_link_add(self, NM_LINK_TYPE_WIREGUARD, name, 0, NULL, 0, 0, NULL, out_link);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
|
|
@ -1614,6 +1617,7 @@ nm_platform_link_gre_add(NMPlatform * self,
|
||||||
0,
|
0,
|
||||||
address,
|
address,
|
||||||
address_len,
|
address_len,
|
||||||
|
0,
|
||||||
props,
|
props,
|
||||||
out_link);
|
out_link);
|
||||||
}
|
}
|
||||||
|
|
@ -1624,7 +1628,7 @@ nm_platform_link_sit_add(NMPlatform * self,
|
||||||
const NMPlatformLnkSit *props,
|
const NMPlatformLnkSit *props,
|
||||||
const NMPlatformLink ** out_link)
|
const NMPlatformLink ** out_link)
|
||||||
{
|
{
|
||||||
return nm_platform_link_add(self, NM_LINK_TYPE_SIT, name, 0, NULL, 0, props, out_link);
|
return nm_platform_link_add(self, NM_LINK_TYPE_SIT, name, 0, NULL, 0, 0, props, out_link);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
|
|
@ -1644,6 +1648,7 @@ nm_platform_link_vlan_add(NMPlatform * self,
|
||||||
parent,
|
parent,
|
||||||
NULL,
|
NULL,
|
||||||
0,
|
0,
|
||||||
|
0,
|
||||||
&((NMPlatformLnkVlan){
|
&((NMPlatformLnkVlan){
|
||||||
.id = vlanid,
|
.id = vlanid,
|
||||||
.flags = vlanflags,
|
.flags = vlanflags,
|
||||||
|
|
@ -1657,7 +1662,7 @@ nm_platform_link_vrf_add(NMPlatform * self,
|
||||||
const NMPlatformLnkVrf *props,
|
const NMPlatformLnkVrf *props,
|
||||||
const NMPlatformLink ** out_link)
|
const NMPlatformLink ** out_link)
|
||||||
{
|
{
|
||||||
return nm_platform_link_add(self, NM_LINK_TYPE_VRF, name, 0, NULL, 0, props, out_link);
|
return nm_platform_link_add(self, NM_LINK_TYPE_VRF, name, 0, NULL, 0, 0, props, out_link);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
|
|
@ -1666,7 +1671,7 @@ nm_platform_link_vxlan_add(NMPlatform * self,
|
||||||
const NMPlatformLnkVxlan *props,
|
const NMPlatformLnkVxlan *props,
|
||||||
const NMPlatformLink ** out_link)
|
const NMPlatformLink ** out_link)
|
||||||
{
|
{
|
||||||
return nm_platform_link_add(self, NM_LINK_TYPE_VXLAN, name, 0, NULL, 0, props, out_link);
|
return nm_platform_link_add(self, NM_LINK_TYPE_VXLAN, name, 0, NULL, 0, 0, props, out_link);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
|
|
@ -1675,7 +1680,15 @@ nm_platform_link_6lowpan_add(NMPlatform * self,
|
||||||
int parent,
|
int parent,
|
||||||
const NMPlatformLink **out_link)
|
const NMPlatformLink **out_link)
|
||||||
{
|
{
|
||||||
return nm_platform_link_add(self, NM_LINK_TYPE_6LOWPAN, name, parent, NULL, 0, NULL, out_link);
|
return nm_platform_link_add(self,
|
||||||
|
NM_LINK_TYPE_6LOWPAN,
|
||||||
|
name,
|
||||||
|
parent,
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
out_link);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
|
|
@ -1687,7 +1700,7 @@ nm_platform_link_ip6tnl_add(NMPlatform * self,
|
||||||
g_return_val_if_fail(props, -NME_BUG);
|
g_return_val_if_fail(props, -NME_BUG);
|
||||||
g_return_val_if_fail(!props->is_gre, -NME_BUG);
|
g_return_val_if_fail(!props->is_gre, -NME_BUG);
|
||||||
|
|
||||||
return nm_platform_link_add(self, NM_LINK_TYPE_IP6TNL, name, 0, NULL, 0, props, out_link);
|
return nm_platform_link_add(self, NM_LINK_TYPE_IP6TNL, name, 0, NULL, 0, 0, props, out_link);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
|
|
@ -1707,6 +1720,7 @@ nm_platform_link_ip6gre_add(NMPlatform * self,
|
||||||
0,
|
0,
|
||||||
address,
|
address,
|
||||||
address_len,
|
address_len,
|
||||||
|
0,
|
||||||
props,
|
props,
|
||||||
out_link);
|
out_link);
|
||||||
}
|
}
|
||||||
|
|
@ -1719,7 +1733,7 @@ nm_platform_link_ipip_add(NMPlatform * self,
|
||||||
{
|
{
|
||||||
g_return_val_if_fail(props, -NME_BUG);
|
g_return_val_if_fail(props, -NME_BUG);
|
||||||
|
|
||||||
return nm_platform_link_add(self, NM_LINK_TYPE_IPIP, name, 0, NULL, 0, props, out_link);
|
return nm_platform_link_add(self, NM_LINK_TYPE_IPIP, name, 0, NULL, 0, 0, props, out_link);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
|
|
@ -1732,7 +1746,15 @@ nm_platform_link_macsec_add(NMPlatform * self,
|
||||||
g_return_val_if_fail(props, -NME_BUG);
|
g_return_val_if_fail(props, -NME_BUG);
|
||||||
g_return_val_if_fail(parent > 0, -NME_BUG);
|
g_return_val_if_fail(parent > 0, -NME_BUG);
|
||||||
|
|
||||||
return nm_platform_link_add(self, NM_LINK_TYPE_MACSEC, name, parent, NULL, 0, props, out_link);
|
return nm_platform_link_add(self,
|
||||||
|
NM_LINK_TYPE_MACSEC,
|
||||||
|
name,
|
||||||
|
parent,
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
props,
|
||||||
|
out_link);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
|
|
@ -1751,6 +1773,7 @@ nm_platform_link_macvlan_add(NMPlatform * self,
|
||||||
parent,
|
parent,
|
||||||
NULL,
|
NULL,
|
||||||
0,
|
0,
|
||||||
|
0,
|
||||||
props,
|
props,
|
||||||
out_link);
|
out_link);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue