<varlistentry>
<term><varname>Description</varname></term>
<listitem>
- <para>A description of the device. The <literal>ifalias</literal> is set to this value.</para>
+ <para>A description of the device.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><varname>Alias</varname></term>
+ <listitem>
+ <para>The <literal>ifalias</literal> is set to this value.</para>
</listitem>
</varlistentry>
<varlistentry>
struct ifinfomsg *ifi;
int r;
- assert_return(nlmsg_type == RTM_NEWLINK || nlmsg_type == RTM_DELLINK || nlmsg_type == RTM_GETLINK, -EINVAL);
+ assert_return(nlmsg_type == RTM_NEWLINK || nlmsg_type == RTM_DELLINK ||
+ nlmsg_type == RTM_SETLINK || nlmsg_type == RTM_GETLINK, -EINVAL);
assert_return(index > 0, -EINVAL);
assert_return(ret, -EINVAL);
switch (rtm_type) {
case RTM_NEWLINK:
+ case RTM_SETLINK:
case RTM_DELLINK:
case RTM_GETLINK:
switch (type) {
case IFLA_IFNAME:
+ case IFLA_IFALIAS:
case IFLA_QDISC:
return add_rtattr(m, type, data, strlen(data) + 1);
case IFLA_MTU:
- return add_rtattr(m, type, data, sizeof(uint32_t));
case IFLA_LINK:
return add_rtattr(m, type, data, sizeof(uint32_t));
case IFLA_STATS:
switch (rtm_type) {
case RTM_NEWLINK:
+ case RTM_SETLINK:
case RTM_DELLINK:
case RTM_GETLINK:
if (!m->next_rta) {
k = -EIO;
break;
case RTM_NEWLINK:
+ case RTM_SETLINK:
case RTM_DELLINK:
case RTM_GETLINK:
if (m->hdr->nlmsg_len < NLMSG_LENGTH(sizeof(struct ifinfomsg)))
assert(ifindex > 0);
assert(name);
- r = sd_rtnl_message_link_new(RTM_NEWLINK, ifindex, 0, 0, &message);
+ r = sd_rtnl_message_link_new(RTM_SETLINK, ifindex, 0, 0, &message);
if (r < 0)
return r;
return 0;
}
-int rtnl_set_link_properties(sd_rtnl *rtnl, int ifindex, const struct ether_addr *mac, unsigned mtu) {
+int rtnl_set_link_properties(sd_rtnl *rtnl, int ifindex, const char *alias,
+ const struct ether_addr *mac, unsigned mtu) {
_cleanup_sd_rtnl_message_unref_ sd_rtnl_message *message = NULL;
bool need_update = false;
int r;
assert(rtnl);
assert(ifindex > 0);
- if (!mac && mtu == 0)
+ if (!alias && !mac && mtu == 0)
return 0;
- r = sd_rtnl_message_link_new(RTM_NEWLINK, ifindex, 0, 0, &message);
+ r = sd_rtnl_message_link_new(RTM_SETLINK, ifindex, 0, 0, &message);
if (r < 0)
return r;
+ if (alias) {
+ r = sd_rtnl_message_append(message, IFLA_IFALIAS, alias);
+ if (r < 0)
+ return r;
+
+ need_update = true;
+
+ }
+
if (mac) {
r = sd_rtnl_message_append(message, IFLA_ADDRESS, mac);
if (r < 0)
#include "sd-rtnl.h"
int rtnl_set_link_name(sd_rtnl *rtnl, int ifindex, const char *name);
-int rtnl_set_link_properties(sd_rtnl *rtnl, int ifindex, const struct ether_addr *mac, unsigned mtu);
+int rtnl_set_link_properties(sd_rtnl *rtnl, int ifindex, const char *alias, const struct ether_addr *mac, unsigned mtu);
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_rtnl*, sd_rtnl_unref);
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_rtnl_message*, sd_rtnl_message_unref);
***/
#include <netinet/ether.h>
-#include <net/if.h>
+#include <linux/if.h>
#include <arpa/inet.h>
#include "net-util.h"
return 0;
}
+int config_parse_ifalias(const char *unit,
+ const char *filename,
+ unsigned line,
+ const char *section,
+ const char *lvalue,
+ int ltype,
+ const char *rvalue,
+ void *data,
+ void *userdata) {
+
+ char **s = data;
+ char *n;
+
+ assert(filename);
+ assert(lvalue);
+ assert(rvalue);
+ assert(data);
+
+ n = strdup(rvalue);
+ if (!n)
+ return log_oom();
+
+ if (!ascii_is_valid(n) || strlen(n) >= IFALIASZ) {
+ log_syntax(unit, LOG_ERR, filename, line, EINVAL,
+ "Interface alias is not ASCII clean or is too long, ignoring assignment: %s", rvalue);
+ free(n);
+ return 0;
+ }
+
+ free(*s);
+ if (*n)
+ *s = n;
+ else {
+ free(n);
+ *s = NULL;
+ }
+
+ return 0;
+}
+
int config_parse_hwaddr(const char *unit,
const char *filename,
unsigned line,
const char *section, const char *lvalue, int ltype,
const char *rvalue, void *data, void *userdata);
+int config_parse_ifalias(const char *unit, const char *filename, unsigned line,
+ const char *section, const char *lvalue, int ltype,
+ const char *rvalue, void *data, void *userdata);
+
int net_parse_inaddr(const char *address, unsigned char *family, void *dst);
Link.MACAddress, config_parse_hwaddr, 0, offsetof(link_config, mac)
Link.NamePolicy, config_parse_name_policy, 0, offsetof(link_config, name_policy)
Link.Name, config_parse_ifname, 0, offsetof(link_config, name)
+Link.Alias, config_parse_ifalias, 0, offsetof(link_config, alias)
Link.MTU, config_parse_unsigned, 0, offsetof(link_config, mtu)
Link.SpeedMBytes, config_parse_unsigned, 0, offsetof(link_config, speed)
Link.Duplex, config_parse_duplex, 0, offsetof(link_config, duplex)
free(link->match_driver);
free(link->match_type);
free(link->description);
+ free(link->alias);
free(link);
}
if (!old_name)
return -EINVAL;
- if (config->description) {
- r = udev_device_set_sysattr_value(device, "ifalias",
- config->description);
- if (r < 0)
- log_warning("Could not set description of %s to '%s': %s",
- old_name, config->description, strerror(-r));
- }
-
r = ethtool_set_speed(ctx->ethtool_fd, old_name, config->speed, config->duplex);
if (r < 0)
log_warning("Could not set speed or duplex of %s to %u Mbytes (%s): %s",
mac = config->mac;
}
- r = rtnl_set_link_properties(ctx->rtnl, ifindex, mac, config->mtu);
+ r = rtnl_set_link_properties(ctx->rtnl, ifindex, config->alias, mac, config->mtu);
if (r < 0) {
- log_warning("Could not set MACAddress or MTU on %s: %s", old_name, strerror(-r));
+ log_warning("Could not set Alias, MACAddress or MTU on %s: %s", old_name, strerror(-r));
return r;
}
MACPolicy mac_policy;
NamePolicy *name_policy;
char *name;
+ char *alias;
unsigned int mtu;
unsigned int speed;
Duplex duplex;