diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2017-07-03 10:10:34 +0200 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2017-08-05 08:03:15 +0200 |
commit | d5c2c3f6d7dff4d763d460052671d32f5389c815 (patch) | |
tree | 287f6b229d3af09c3e6254dc826315707fe5bbad | |
parent | f83e56ec6dbe2b03a2ce19767ff992d2637d8de6 (diff) | |
download | NetworkManager-d5c2c3f6d7dff4d763d460052671d32f5389c815.tar.gz |
platform: add nm_platform_link_set_name()
We'll need it to rename the new PPP interface to a given name.
-rw-r--r-- | src/platform/nm-linux-platform.c | 24 | ||||
-rw-r--r-- | src/platform/nm-platform.c | 24 | ||||
-rw-r--r-- | src/platform/nm-platform.h | 2 |
3 files changed, 50 insertions, 0 deletions
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 42a77c5066..85d1591f1c 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -4463,6 +4463,29 @@ nla_put_failure: g_return_val_if_reached (NM_PLATFORM_ERROR_UNSPECIFIED); } +static NMPlatformError +link_set_name (NMPlatform *platform, int ifindex, const char *name) +{ + nm_auto_nlmsg struct nl_msg *nlmsg = NULL; + + _LOGD ("link: change %d: name: %s", ifindex, name); + + nlmsg = _nl_msg_new_link (RTM_NEWLINK, + 0, + ifindex, + NULL, + 0, + 0); + if (!nlmsg) + g_return_val_if_reached (NM_PLATFORM_ERROR_UNSPECIFIED); + + NLA_PUT (nlmsg, IFLA_IFNAME, strlen (name) + 1, name); + + return do_change_link (platform, ifindex, nlmsg) == NM_PLATFORM_ERROR_SUCCESS; +nla_put_failure: + g_return_val_if_reached (FALSE); +} + static gboolean link_get_permanent_address (NMPlatform *platform, int ifindex, @@ -6461,6 +6484,7 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass) platform_class->link_set_address = link_set_address; platform_class->link_get_permanent_address = link_get_permanent_address; platform_class->link_set_mtu = link_set_mtu; + platform_class->link_set_name = link_set_name; platform_class->link_set_sriov_num_vfs = link_set_sriov_num_vfs; platform_class->link_get_physical_port_id = link_get_physical_port_id; diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index 03dc6943b6..e7935d49fb 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -1462,6 +1462,30 @@ nm_platform_link_get_mtu (NMPlatform *self, int ifindex) } /** + * nm_platform_link_set_name: + * @self: platform instance + * @ifindex: Interface index + * @name: The new interface name + * + * Set interface name. + */ +gboolean +nm_platform_link_set_name (NMPlatform *self, int ifindex, const char *name) +{ + _CHECK_SELF (self, klass, FALSE); + + g_return_val_if_fail (ifindex >= 0, FALSE); + g_return_val_if_fail (name, FALSE); + + _LOGD ("link: setting '%s' (%d) name %s", nm_platform_link_get_name (self, ifindex), ifindex, name); + + if (strlen (name) + 1 > IFNAMSIZ) + return FALSE; + + return klass->link_set_name (self, ifindex, name); +} + +/** * nm_platform_link_get_physical_port_id: * @self: platform instance * @ifindex: Interface index diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index a40d33f43d..8e922b95e0 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -682,6 +682,7 @@ typedef struct { size_t *length); NMPlatformError (*link_set_address) (NMPlatform *, int ifindex, gconstpointer address, size_t length); gboolean (*link_set_mtu) (NMPlatform *, int ifindex, guint32 mtu); + gboolean (*link_set_name) (NMPlatform *, int ifindex, const char *name); gboolean (*link_set_sriov_num_vfs) (NMPlatform *, int ifindex, guint num_vfs); char * (*link_get_physical_port_id) (NMPlatform *, int ifindex); @@ -946,6 +947,7 @@ gboolean nm_platform_link_set_ipv6_token (NMPlatform *self, int ifindex, NMUtils gboolean nm_platform_link_get_permanent_address (NMPlatform *self, int ifindex, guint8 *buf, size_t *length); NMPlatformError nm_platform_link_set_address (NMPlatform *self, int ifindex, const void *address, size_t length); gboolean nm_platform_link_set_mtu (NMPlatform *self, int ifindex, guint32 mtu); +gboolean nm_platform_link_set_name (NMPlatform *self, int ifindex, const char *name); gboolean nm_platform_link_set_sriov_num_vfs (NMPlatform *self, int ifindex, guint num_vfs); char *nm_platform_link_get_physical_port_id (NMPlatform *self, int ifindex); |