[systemd-commits] 4 commits - Makefile.am rules/80-net-setup-link.rules rules/85-net-configure-link.rules src/libsystemd-rtnl src/libudev src/machine src/udev
Tom Gundersen
tomegun at kemper.freedesktop.org
Wed Oct 30 15:32:51 CET 2013
Makefile.am | 2
rules/80-net-setup-link.rules | 13 ++++
rules/85-net-configure-link.rules | 11 ---
src/libsystemd-rtnl/rtnl-util.c | 36 +++++++++---
src/libsystemd-rtnl/rtnl-util.h | 3 -
src/libudev/libudev.c | 2
src/machine/machinectl.c | 1
src/udev/net/link-config.c | 94 ++++++++++++++++++---------------
src/udev/net/link-config.h | 2
src/udev/udev-builtin-net_setup_link.c | 6 +-
src/udev/udev-event.c | 4 -
11 files changed, 106 insertions(+), 68 deletions(-)
New commits:
commit 2004d23a0fcaa6e74631057a2ff75594a038d86e
Author: Tom Gundersen <teg at jklm.no>
Date: Wed Oct 30 15:09:01 2013 +0100
libudev: default log_priority to INFO
This brings it in sync with the default config file.
diff --git a/src/libudev/libudev.c b/src/libudev/libudev.c
index 208039a..bc73a5a 100644
--- a/src/libudev/libudev.c
+++ b/src/libudev/libudev.c
@@ -125,7 +125,7 @@ _public_ struct udev *udev_new(void)
return NULL;
udev->refcount = 1;
udev->log_fn = log_stderr;
- udev->log_priority = LOG_ERR;
+ udev->log_priority = LOG_INFO;
udev_list_init(udev, &udev->properties_list, true);
f = fopen("/etc/udev/udev.conf", "re");
commit f61942250a43a123580d7bbe5d7873dc5118ed97
Author: Tom Gundersen <teg at jklm.no>
Date: Wed Oct 30 14:40:10 2013 +0100
udev: link-config - less verbose logging
Also reinstate print to kmsg when renaming netif.
diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c
index 80f8b16..b268254 100644
--- a/src/udev/net/link-config.c
+++ b/src/udev/net/link-config.c
@@ -44,6 +44,8 @@ struct link_config_ctx {
int ethtool_fd;
+ bool enable_name_policy;
+
sd_rtnl *rtnl;
char **link_dirs;
@@ -67,6 +69,8 @@ int link_config_ctx_new(link_config_ctx **ret) {
ctx->ethtool_fd = -1;
+ ctx->enable_name_policy = true;
+
ctx->link_dirs = strv_new("/etc/systemd/network",
"/run/systemd/network",
"/usr/lib/systemd/network",
@@ -181,12 +185,37 @@ failure:
return r;
}
+static bool enable_name_policy(void) {
+ _cleanup_free_ char *line;
+ char *w, *state;
+ int r;
+ size_t l;
+
+ r = read_one_line_file("/proc/cmdline", &line);
+ if (r < 0) {
+ log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r));
+ return true; /* something is very wrong, let's not make it worse */
+ }
+
+ FOREACH_WORD_QUOTED(w, l, line, state)
+ if (strneq(w, "net.ifnames=0", l))
+ return false;
+
+ return true;
+}
+
int link_config_load(link_config_ctx *ctx) {
int r;
char **files, **f;
link_configs_free(ctx);
+
+ if (!enable_name_policy()) {
+ ctx->enable_name_policy = false;
+ log_info("Network interface NamePolicy= disabled on kernel commandline, ignoring.");
+ }
+
/* update timestamp */
paths_check_timestamp(ctx->link_dirs, &ctx->link_dirs_ts_usec, true);
@@ -255,10 +284,8 @@ int link_config_get(link_config_ctx *ctx, struct udev_device *device, link_confi
link_config *link;
LIST_FOREACH(links, link, ctx->links) {
- if (!match_config(link, device)) {
- log_info("Config file %s does not apply to device %s", link->filename, udev_device_get_sysname(device));
- } else {
- log_info("Config file %s applies to device %s", link->filename, udev_device_get_sysname(device));
+ if (match_config(link, device)) {
+ log_debug("Config file %s applies to device %s", link->filename, udev_device_get_sysname(device));
*ret = link;
return 0;
}
@@ -267,27 +294,6 @@ int link_config_get(link_config_ctx *ctx, struct udev_device *device, link_confi
return -ENOENT;
}
-static bool enable_name_policy(void) {
- _cleanup_free_ char *line;
- char *w, *state;
- int r;
- size_t l;
-
- r = read_one_line_file("/proc/cmdline", &line);
- if (r < 0) {
- log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r));
- return true; /* something is very wrong, let's not make it worse */
- }
-
- FOREACH_WORD_QUOTED(w, l, line, state)
- if (strneq(w, "net.ifnames=0", l)) {
- log_info("Link name policy disabled on kernel commandline, ignoring.");
- return false;
- }
-
- return true;
-}
-
static bool mac_is_random(struct udev_device *device) {
const char *s;
unsigned type;
@@ -387,8 +393,6 @@ int link_config_apply(link_config_ctx *ctx, link_config *config, struct udev_dev
if (!old_name)
return -EINVAL;
- log_info("Configuring %s", old_name);
-
if (config->description) {
r = udev_device_set_sysattr_value(device, "ifalias",
config->description);
@@ -413,7 +417,7 @@ int link_config_apply(link_config_ctx *ctx, link_config *config, struct udev_dev
return -ENODEV;
}
- if (config->name_policy && enable_name_policy()) {
+ if (ctx->enable_name_policy && config->name_policy) {
NamePolicy *policy;
for (policy = config->name_policy; !new_name && *policy != _NAMEPOLICY_INVALID; policy++) {
diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c
index 1242db9..0d1049c 100644
--- a/src/udev/udev-event.c
+++ b/src/udev/udev-event.c
@@ -769,7 +769,7 @@ static int rename_netif(struct udev_event *event)
log_error("error changing net interface name %s to %s: %s",
oldname, name, strerror(-r));
else
- log_info("renamed network interface %s to %s", oldname, name);
+ print_kmsg("renamed network interface %s to %s", oldname, name);
return r;
}
commit 3e137a1b9a0eac2bf43d493d3302c3c959b6ccdb
Author: Tom Gundersen <teg at jklm.no>
Date: Wed Oct 30 04:10:19 2013 +0100
udev: link-config - let udevd set the ifname
diff --git a/Makefile.am b/Makefile.am
index 66bbf20..bd7f577 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2234,7 +2234,7 @@ dist_udevrules_DATA += \
rules/75-net-description.rules \
rules/75-tty-description.rules \
rules/78-sound-card.rules \
- rules/85-net-configure-link.rules \
+ rules/80-net-setup-link.rules \
rules/95-udev-late.rules
dist_udevhwdb_DATA = \
diff --git a/rules/80-net-setup-link.rules b/rules/80-net-setup-link.rules
new file mode 100644
index 0000000..6e411a9
--- /dev/null
+++ b/rules/80-net-setup-link.rules
@@ -0,0 +1,13 @@
+# do not edit this file, it will be overwritten on update
+
+SUBSYSTEM!="net", GOTO="net_setup_link_end"
+
+IMPORT{builtin}="path_id"
+
+ACTION!="add", GOTO="net_setup_link_end"
+
+IMPORT{builtin}="net_setup_link"
+
+NAME=="", ENV{ID_NET_NAME}!="", NAME="$env{ID_NET_NAME}"
+
+LABEL="net_setup_link_end"
diff --git a/rules/85-net-configure-link.rules b/rules/85-net-configure-link.rules
deleted file mode 100644
index d0ecb93..0000000
--- a/rules/85-net-configure-link.rules
+++ /dev/null
@@ -1,11 +0,0 @@
-# do not edit this file, it will be overwritten on update
-
-SUBSYSTEM!="net", GOTO="net_setup_link_end"
-
-IMPORT{builtin}="path_id"
-
-ACTION!="add", GOTO="net_setup_link_end"
-
-RUN{builtin}="net_setup_link"
-
-LABEL="net_setup_link_end"
diff --git a/src/libsystemd-rtnl/rtnl-util.c b/src/libsystemd-rtnl/rtnl-util.c
index bf6bf27..93804bb 100644
--- a/src/libsystemd-rtnl/rtnl-util.c
+++ b/src/libsystemd-rtnl/rtnl-util.c
@@ -25,25 +25,43 @@
#include "rtnl-util.h"
-int rtnl_set_link_properties(sd_rtnl *rtnl, int ifindex, const char *name, const struct ether_addr *mac, unsigned mtu) {
- _cleanup_sd_rtnl_message_unref_ sd_rtnl_message *message;
- bool need_update = false;
+int rtnl_set_link_name(sd_rtnl *rtnl, int ifindex, const char *name) {
+ _cleanup_sd_rtnl_message_unref_ sd_rtnl_message *message = NULL;
int r;
assert(rtnl);
assert(ifindex > 0);
+ assert(name);
r = sd_rtnl_message_link_new(RTM_NEWLINK, ifindex, 0, 0, &message);
if (r < 0)
return r;
- if (name) {
- r = sd_rtnl_message_append(message, IFLA_IFNAME, name);
- if (r < 0)
- return r;
+ r = sd_rtnl_message_append(message, IFLA_IFNAME, name);
+ if (r < 0)
+ return r;
- need_update = true;
- }
+ r = sd_rtnl_send_with_reply_and_block(rtnl, message, 0, NULL);
+ if (r < 0)
+ return r;
+
+ return 0;
+}
+
+int rtnl_set_link_properties(sd_rtnl *rtnl, int ifindex, 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)
+ return 0;
+
+ r = sd_rtnl_message_link_new(RTM_NEWLINK, ifindex, 0, 0, &message);
+ if (r < 0)
+ return r;
if (mac) {
r = sd_rtnl_message_append(message, IFLA_ADDRESS, mac);
diff --git a/src/libsystemd-rtnl/rtnl-util.h b/src/libsystemd-rtnl/rtnl-util.h
index dd8300b..a6ac4b6 100644
--- a/src/libsystemd-rtnl/rtnl-util.h
+++ b/src/libsystemd-rtnl/rtnl-util.h
@@ -23,4 +23,5 @@
#include "sd-rtnl.h"
-int rtnl_set_link_properties(sd_rtnl *rtnl, int ifindex, const char *name, const struct ether_addr *mac, unsigned mtu);
+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);
diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c
index cf966bf..80f8b16 100644
--- a/src/udev/net/link-config.c
+++ b/src/udev/net/link-config.c
@@ -280,8 +280,10 @@ static bool enable_name_policy(void) {
}
FOREACH_WORD_QUOTED(w, l, line, state)
- if (strneq(w, "net.ifnames=0", l))
+ if (strneq(w, "net.ifnames=0", l)) {
+ log_info("Link name policy disabled on kernel commandline, ignoring.");
return false;
+ }
return true;
}
@@ -365,40 +367,45 @@ static int get_mac(struct udev_device *device, bool want_random, struct ether_ad
return 0;
}
-int link_config_apply(link_config_ctx *ctx, link_config *config, struct udev_device *device) {
- const char *name;
+int link_config_apply(link_config_ctx *ctx, link_config *config, struct udev_device *device, const char **name) {
+ const char *old_name;
const char *new_name = NULL;
struct ether_addr generated_mac;
struct ether_addr *mac = NULL;
int r, ifindex;
+ assert(ctx);
+ assert(config);
+ assert(device);
+ assert(name);
+
r = link_config_ctx_connect(ctx);
if (r < 0)
return r;
- name = udev_device_get_sysname(device);
- if (!name)
+ old_name = udev_device_get_sysname(device);
+ if (!old_name)
return -EINVAL;
- log_info("Configuring %s", name);
+ log_info("Configuring %s", old_name);
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",
- name, config->description, strerror(-r));
+ old_name, config->description, strerror(-r));
}
- r = ethtool_set_speed(ctx->ethtool_fd, name, config->speed, config->duplex);
+ 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",
- name, config->speed, duplex_to_string(config->duplex), strerror(-r));
+ old_name, config->speed, duplex_to_string(config->duplex), strerror(-r));
- r = ethtool_set_wol(ctx->ethtool_fd, name, config->wol);
+ r = ethtool_set_wol(ctx->ethtool_fd, old_name, config->wol);
if (r < 0)
log_warning("Could not set WakeOnLan of %s to %s: %s",
- name, wol_to_string(config->wol), strerror(-r));
+ old_name, wol_to_string(config->wol), strerror(-r));
ifindex = udev_device_get_ifindex(device);
if (ifindex <= 0) {
@@ -429,9 +436,12 @@ int link_config_apply(link_config_ctx *ctx, link_config *config, struct udev_dev
}
}
- if (!new_name && config->name) {
- new_name = config->name;
- }
+ if (new_name)
+ *name = new_name; /* a name was set by a policy */
+ else if (config->name)
+ *name = config->name; /* a name was set manually in the config */
+ else
+ *name = NULL;
switch (config->mac_policy) {
case MACPOLICY_PERSISTENT:
@@ -454,9 +464,9 @@ int link_config_apply(link_config_ctx *ctx, link_config *config, struct udev_dev
mac = config->mac;
}
- r = rtnl_set_link_properties(ctx->rtnl, ifindex, new_name, mac, config->mtu);
+ r = rtnl_set_link_properties(ctx->rtnl, ifindex, mac, config->mtu);
if (r < 0) {
- log_warning("Could not set Name, MACAddress or MTU on %s: %s", name, strerror(-r));
+ log_warning("Could not set MACAddress or MTU on %s: %s", old_name, strerror(-r));
return r;
}
diff --git a/src/udev/net/link-config.h b/src/udev/net/link-config.h
index f5dee5a..b3ee81f 100644
--- a/src/udev/net/link-config.h
+++ b/src/udev/net/link-config.h
@@ -74,7 +74,7 @@ int link_config_load(link_config_ctx *ctx);
bool link_config_should_reload(link_config_ctx *ctx);
int link_config_get(link_config_ctx *ctx, struct udev_device *device, struct link_config **ret);
-int link_config_apply(link_config_ctx *ctx, struct link_config *config, struct udev_device *device);
+int link_config_apply(link_config_ctx *ctx, struct link_config *config, struct udev_device *device, const char **name);
const char *name_policy_to_string(NamePolicy p) _const_;
NamePolicy name_policy_from_string(const char *p) _pure_;
diff --git a/src/udev/udev-builtin-net_setup_link.c b/src/udev/udev-builtin-net_setup_link.c
index 6a98b80..e6ffa53 100644
--- a/src/udev/udev-builtin-net_setup_link.c
+++ b/src/udev/udev-builtin-net_setup_link.c
@@ -26,6 +26,7 @@
link_config_ctx *ctx;
static int builtin_net_setup_link(struct udev_device *dev, int argc, char **argv, bool test) {
+ const char *name;
link_config *link;
int r;
@@ -45,12 +46,15 @@ static int builtin_net_setup_link(struct udev_device *dev, int argc, char **argv
}
}
- r = link_config_apply(ctx, link, dev);
+ r = link_config_apply(ctx, link, dev, &name);
if (r < 0) {
log_error("Could not apply link config to %s", udev_device_get_sysname(dev));
return EXIT_FAILURE;
}
+ if (name)
+ udev_builtin_add_property(dev, test, "ID_NET_NAME", name);
+
return EXIT_SUCCESS;
}
diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c
index bdf3a38..1242db9 100644
--- a/src/udev/udev-event.c
+++ b/src/udev/udev-event.c
@@ -764,7 +764,7 @@ static int rename_netif(struct udev_event *event)
if (r < 0)
return r;
- r = rtnl_set_link_properties(rtnl, udev_device_get_ifindex(dev), name, NULL, 0);
+ r = rtnl_set_link_name(rtnl, udev_device_get_ifindex(dev), name);
if (r < 0)
log_error("error changing net interface name %s to %s: %s",
oldname, name, strerror(-r));
commit 415e7f65dbc66089f0d1b9de6785026596df88e7
Author: Marc-Antoine Perennou <Marc-Antoine at Perennou.com>
Date: Wed Oct 30 12:33:11 2013 +0900
machinectl: privileged option is gone
diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c
index 7500d5c..8795565 100644
--- a/src/machine/machinectl.c
+++ b/src/machine/machinectl.c
@@ -572,7 +572,6 @@ static int parse_argv(int argc, char *argv[]) {
{ "kill-who", required_argument, NULL, ARG_KILL_WHO },
{ "signal", required_argument, NULL, 's' },
{ "host", required_argument, NULL, 'H' },
- { "privileged", no_argument, NULL, 'P' },
{ "no-ask-password", no_argument, NULL, ARG_NO_ASK_PASSWORD },
{ NULL, 0, NULL, 0 }
};
More information about the systemd-commits
mailing list