diff options
author | Tom Gundersen <teg@jklm.no> | 2013-11-25 01:33:04 +0100 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2013-11-25 14:53:56 +0100 |
commit | d2df0d0ed3a88e491405b403e6022e6619750130 (patch) | |
tree | d9bccbc34a4c2283403498b9b7ca7ce0d702a6c7 /src/libsystemd-rtnl | |
parent | 517dcac840fe8d5bf30a05c0084eff219af10a4a (diff) |
udev: net_setup_link - don't use Description as Alias
Use Description only internally, and allow Alias to be set
as a separate option. For instance SNMP uses ifalias for
a specific purpose, so let's not write to it by default.
Diffstat (limited to 'src/libsystemd-rtnl')
-rw-r--r-- | src/libsystemd-rtnl/rtnl-message.c | 8 | ||||
-rw-r--r-- | src/libsystemd-rtnl/rtnl-util.c | 18 | ||||
-rw-r--r-- | src/libsystemd-rtnl/rtnl-util.h | 2 |
3 files changed, 21 insertions, 7 deletions
diff --git a/src/libsystemd-rtnl/rtnl-message.c b/src/libsystemd-rtnl/rtnl-message.c index 1ce6862668..26da7f2db8 100644 --- a/src/libsystemd-rtnl/rtnl-message.c +++ b/src/libsystemd-rtnl/rtnl-message.c @@ -129,7 +129,8 @@ int sd_rtnl_message_link_new(uint16_t nlmsg_type, int index, unsigned int type, 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); @@ -258,14 +259,15 @@ int sd_rtnl_message_append(sd_rtnl_message *m, unsigned short type, const void * 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: @@ -352,6 +354,7 @@ int sd_rtnl_message_read(sd_rtnl_message *m, unsigned short *type, void **data) switch (rtm_type) { case RTM_NEWLINK: + case RTM_SETLINK: case RTM_DELLINK: case RTM_GETLINK: if (!m->next_rta) { @@ -512,6 +515,7 @@ int socket_read_message(sd_rtnl *nl, sd_rtnl_message **ret) { 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))) diff --git a/src/libsystemd-rtnl/rtnl-util.c b/src/libsystemd-rtnl/rtnl-util.c index d40858a63b..4e7661bb77 100644 --- a/src/libsystemd-rtnl/rtnl-util.c +++ b/src/libsystemd-rtnl/rtnl-util.c @@ -34,7 +34,7 @@ int rtnl_set_link_name(sd_rtnl *rtnl, int ifindex, const char *name) { 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; @@ -49,7 +49,8 @@ int rtnl_set_link_name(sd_rtnl *rtnl, int ifindex, const char *name) { 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; @@ -57,13 +58,22 @@ int rtnl_set_link_properties(sd_rtnl *rtnl, int ifindex, const struct ether_addr 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) diff --git a/src/libsystemd-rtnl/rtnl-util.h b/src/libsystemd-rtnl/rtnl-util.h index ba0f71f944..013002dd60 100644 --- a/src/libsystemd-rtnl/rtnl-util.h +++ b/src/libsystemd-rtnl/rtnl-util.h @@ -27,7 +27,7 @@ #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); |