platform: link mtu setting

This commit is contained in:
Pavel Šimerda
2013-04-15 21:48:12 +02:00
parent 6c55e5a1c6
commit f63c7f8ee6
7 changed files with 112 additions and 0 deletions

View File

@@ -385,6 +385,27 @@ link_get_address (NMPlatform *platform, int ifindex, size_t *length)
return g_bytes_get_data (device->address, length);
}
static gboolean
link_set_mtu (NMPlatform *platform, int ifindex, guint32 mtu)
{
NMFakePlatformLink *device = link_get (platform, ifindex);
if (device) {
device->link.mtu = mtu;
link_changed (platform, device);
}
return !!device;
}
static guint32
link_get_mtu (NMPlatform *platform, int ifindex)
{
NMFakePlatformLink *device = link_get (platform, ifindex);
return device ? device->link.mtu : 0;
}
static gboolean
link_supports_carrier_detect (NMPlatform *platform, int ifindex)
{
@@ -978,6 +999,8 @@ nm_fake_platform_class_init (NMFakePlatformClass *klass)
platform_class->link_set_address = link_set_address;
platform_class->link_get_address = link_get_address;
platform_class->link_get_mtu = link_get_mtu;
platform_class->link_set_mtu = link_set_mtu;
platform_class->link_supports_carrier_detect = link_supports_carrier_detect;
platform_class->link_supports_vlans = link_supports_vlans;

View File

@@ -335,6 +335,7 @@ link_init (NMPlatformLink *info, struct rtnl_link *rtnllink)
info->connected = !!(rtnl_link_get_flags (rtnllink) & IFF_LOWER_UP);
info->arp = !(rtnl_link_get_flags (rtnllink) & IFF_NOARP);
info->master = rtnl_link_get_master (rtnllink);
info->mtu = rtnl_link_get_mtu (rtnllink);
}
/* Hack: Empty bridges and bonds have IFF_LOWER_UP flag and therefore they break
@@ -1139,6 +1140,26 @@ link_get_address (NMPlatform *platform, int ifindex, size_t *length)
return nladdr ? nl_addr_get_binary_addr (nladdr) : NULL;
}
static gboolean
link_set_mtu (NMPlatform *platform, int ifindex, guint32 mtu)
{
auto_nl_object struct rtnl_link *change;
change = rtnl_link_alloc ();
g_return_val_if_fail (change != NULL, FALSE);
rtnl_link_set_mtu (change, mtu);
return link_change (platform, ifindex, change);
}
static guint32
link_get_mtu (NMPlatform *platform, int ifindex)
{
auto_nl_object struct rtnl_link *rtnllink = link_get (platform, ifindex);
return rtnllink ? rtnl_link_get_mtu (rtnllink) : 0;
}
static int
vlan_add (NMPlatform *platform, const char *name, int parent, int vlan_id, guint32 vlan_flags)
{
@@ -1773,6 +1794,8 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass)
platform_class->link_get_address = link_get_address;
platform_class->link_set_address = link_set_address;
platform_class->link_get_mtu = link_get_mtu;
platform_class->link_set_mtu = link_set_mtu;
platform_class->link_supports_carrier_detect = link_supports_carrier_detect;
platform_class->link_supports_vlans = link_supports_vlans;

View File

@@ -625,6 +625,43 @@ nm_platform_link_set_noarp (int ifindex)
return klass->link_set_noarp (platform, ifindex);
}
/**
* nm_platform_link_set_mtu:
* @ifindex: Interface index
* @mtu: The new MTU value
*
* Set interface MTU.
*/
gboolean
nm_platform_link_set_mtu (int ifindex, guint32 mtu)
{
reset_error ();
g_return_val_if_fail (ifindex >= 0, FALSE);
g_return_val_if_fail (mtu > 0, FALSE);
g_return_val_if_fail (klass->link_set_mtu, FALSE);
debug ("link: setting '%s' (%d) mtu %d", nm_platform_link_get_name (ifindex), ifindex, mtu);
return klass->link_set_mtu (platform, ifindex, mtu);
}
/**
* nm_platform_link_get_mtu:
* @ifindex: Interface index
*
* Returns: MTU value for the interface or 0 on error.
*/
guint32
nm_platform_link_get_mtu (int ifindex)
{
reset_error ();
g_return_val_if_fail (ifindex >= 0, 0);
g_return_val_if_fail (klass->link_get_mtu, 0);
return klass->link_get_mtu (platform, ifindex);
}
/**
* nm_platform_link_enslave:
* @master: Interface index of the master

View File

@@ -67,6 +67,7 @@ typedef struct {
gboolean up;
gboolean connected;
gboolean arp;
guint mtu;
} NMPlatformLink;
typedef struct {
@@ -161,6 +162,8 @@ typedef struct {
gconstpointer (*link_get_address) (NMPlatform *, int ifindex, size_t *length);
gboolean (*link_set_address) (NMPlatform *, int ifindex, gconstpointer address, size_t length);
guint32 (*link_get_mtu) (NMPlatform *, int ifindex);
gboolean (*link_set_mtu) (NMPlatform *, int ifindex, guint32 mtu);
gboolean (*link_supports_carrier_detect) (NMPlatform *, int ifindex);
gboolean (*link_supports_vlans) (NMPlatform *, int ifindex);
@@ -266,6 +269,8 @@ gboolean nm_platform_link_uses_arp (int ifindex);
gconstpointer nm_platform_link_get_address (int ifindex, size_t *length);
gboolean nm_platform_link_set_address (int ifindex, const void *address, size_t length);
guint32 nm_platform_link_get_mtu (int ifindex);
gboolean nm_platform_link_set_mtu (int ifindex, guint32 mtu);
gboolean nm_platform_link_supports_carrier_detect (int ifindex);
gboolean nm_platform_link_supports_vlans (int ifindex);

View File

@@ -36,6 +36,7 @@ dump_interface (NMPlatformLink *link)
printf (" noarp");
if (link->master)
printf (" master %d", link->master);
printf (" mtu %d", link->mtu);
printf ("\n");
nm_platform_vlan_get_info (link->ifindex, &vlan_parent, &vlan_id);
if (vlan_parent)

View File

@@ -230,6 +230,16 @@ do_link_get_address (char **argv)
return TRUE;
}
static gboolean
do_link_set_mtu (char **argv)
{
int ifindex = parse_ifindex (*argv++);
int mtu = strtoul (*argv++, NULL, 10);
return nm_platform_link_set_mtu (ifindex, mtu);
}
LINK_CMD_GET (get_mtu, decimal);
LINK_CMD_GET (supports_carrier_detect, boolean)
LINK_CMD_GET (supports_vlans, boolean)
@@ -594,6 +604,8 @@ static const command_t commands[] = {
{ "link-uses-arp", "check whether interface uses arp", do_link_uses_arp, 1, "<ifname/ifindex>" },
{ "link-get-address", "print link address", do_link_get_address, 1, "<ifname/ifindex>" },
{ "link-set-address", "set link address", do_link_set_address, 2, "<ifname/ifindex> <hex>" },
{ "link-get-mtu", "print link mtu", do_link_get_mtu, 1, "<ifname/ifindex>" },
{ "link-set-mtu", "set link mtu", do_link_set_mtu, 2, "<ifname/ifindex> <mtu>" },
{ "link-supports-carrier-detect", "check whether interface supports carrier detect",
do_link_supports_carrier_detect, 1, "<ifname/ifindex>" },
{ "link-supports-vlans", "check whether interface supports VLANs",

View File

@@ -12,6 +12,7 @@
#define PARENT_NAME "nm-test-parent"
#define VLAN_ID 4077
#define VLAN_FLAGS 0
#define MTU 1357
static void
link_callback (NMPlatform *platform, int ifindex, NMPlatformLink *received, SignalData *data)
@@ -95,6 +96,10 @@ test_bogus(void)
error (NM_PLATFORM_ERROR_NOT_FOUND);
g_assert (!nm_platform_link_get_address (BOGUS_IFINDEX, NULL));
error (NM_PLATFORM_ERROR_NOT_FOUND);
g_assert (!nm_platform_link_set_mtu (BOGUS_IFINDEX, MTU));
error (NM_PLATFORM_ERROR_NOT_FOUND);
g_assert (!nm_platform_link_get_mtu (BOGUS_IFINDEX));
error (NM_PLATFORM_ERROR_NOT_FOUND);
g_assert (!nm_platform_link_supports_carrier_detect (BOGUS_IFINDEX));
error (NM_PLATFORM_ERROR_NOT_FOUND);
@@ -450,6 +455,12 @@ test_internal (void)
g_assert (!memcmp (address, mac, addrlen));
accept_signal (link_changed);
/* Set MTU */
g_assert (nm_platform_link_set_mtu (ifindex, MTU));
no_error ();
g_assert_cmpint (nm_platform_link_get_mtu (ifindex), ==, MTU);
accept_signal (link_changed);
/* Delete device */
g_assert (nm_platform_link_delete (ifindex));
no_error ();