summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2019-10-23 22:36:04 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2019-10-24 14:23:12 +0900
commit8dc85c5ef13f5876aa52d35103feb74612db61bb (patch)
tree61d6a1d13961887dd792348cf97b388f31391f97
parente4857ee2f2a4c28a8a3aa6efef2dc9f769a25baf (diff)
downloadsystemd-8dc85c5ef13f5876aa52d35103feb74612db61bb.tar.gz
networkctl: introduce reconfigure method
-rw-r--r--man/networkctl.xml7
-rw-r--r--src/network/networkctl.c87
2 files changed, 74 insertions, 20 deletions
diff --git a/man/networkctl.xml b/man/networkctl.xml
index 436dc12e46..0502ab752c 100644
--- a/man/networkctl.xml
+++ b/man/networkctl.xml
@@ -263,6 +263,13 @@ s - Service VLAN, m - Two-port MAC Relay (TPMR)
<varlistentry>
<term>
+ <command>reconfigure</command>
+ </term>
+ <listitem><para>Reconfigure network interfaces. Takes interface name or index number.</para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
<command>reload</command>
</term>
<listitem><para>Reload <filename>.netdev</filename> and <filename>.network</filename> files.
diff --git a/src/network/networkctl.c b/src/network/networkctl.c
index 09290560f5..d83dc611a5 100644
--- a/src/network/networkctl.c
+++ b/src/network/networkctl.c
@@ -1832,6 +1832,51 @@ static int verb_reload(int argc, char *argv[], void *userdata) {
return 0;
}
+static int verb_reconfigure(int argc, char *argv[], void *userdata) {
+ _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
+ _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
+ _cleanup_set_free_ Set *indexes = NULL;
+ int index, i, r;
+ Iterator j;
+ void *p;
+
+ r = sd_bus_open_system(&bus);
+ if (r < 0)
+ return log_error_errno(r, "Failed to connect system bus: %m");
+
+ indexes = set_new(NULL);
+ if (!indexes)
+ return log_oom();
+
+ for (i = 1; i < argc; i++) {
+ r = parse_ifindex_or_ifname(argv[i], &index);
+ if (r < 0)
+ return log_error_errno(r, "Failed to resolve interface %s", argv[i]);
+
+ r = set_put(indexes, INT_TO_PTR(index));
+ if (r < 0)
+ return log_oom();
+ }
+
+ SET_FOREACH(p, indexes, j) {
+ index = PTR_TO_INT(p);
+ r = sd_bus_call_method(
+ bus,
+ "org.freedesktop.network1",
+ "/org/freedesktop/network1",
+ "org.freedesktop.network1.Manager",
+ "ReconfigureLink",
+ &error, NULL, "i", index);
+ if (r < 0) {
+ char ifname[IF_NAMESIZE + 1];
+
+ return log_error_errno(r, "Failed to reconfigure network interface %s: %m", format_ifname_full(index, ifname, FORMAT_IFNAME_IFINDEX));
+ }
+ }
+
+ return 0;
+}
+
static int help(void) {
_cleanup_free_ char *link = NULL;
int r;
@@ -1843,20 +1888,21 @@ static int help(void) {
printf("%s%s [OPTIONS...]\n\n"
"Query and control the networking subsystem.%s\n"
"\nCommands:\n"
- " list [PATTERN...] List links\n"
- " status [PATTERN...] Show link status\n"
- " lldp [PATTERN...] Show LLDP neighbors\n"
- " label Show current address label entries in the kernel\n"
- " delete DEVICES... Delete virtual netdevs\n"
- " renew DEVICES... Renew dynamic configurations\n"
- " reload Reload .network and .netdev files\n"
+ " list [PATTERN...] List links\n"
+ " status [PATTERN...] Show link status\n"
+ " lldp [PATTERN...] Show LLDP neighbors\n"
+ " label Show current address label entries in the kernel\n"
+ " delete DEVICES... Delete virtual netdevs\n"
+ " renew DEVICES... Renew dynamic configurations\n"
+ " reconfigure DEVICES... Reconfigure interfaces\n"
+ " reload Reload .network and .netdev files\n"
"\nOptions\n"
- " -h --help Show this help\n"
- " --version Show package version\n"
- " --no-pager Do not pipe output into a pager\n"
- " --no-legend Do not show the headers and footers\n"
- " -a --all Show status for all links\n"
- " -s --stats Show detailed link statics\n"
+ " -h --help Show this help\n"
+ " --version Show package version\n"
+ " --no-pager Do not pipe output into a pager\n"
+ " --no-legend Do not show the headers and footers\n"
+ " -a --all Show status for all links\n"
+ " -s --stats Show detailed link statics\n"
"\nSee the %s for details.\n"
, ansi_highlight()
, program_invocation_short_name
@@ -1929,13 +1975,14 @@ static int parse_argv(int argc, char *argv[]) {
static int networkctl_main(int argc, char *argv[]) {
static const Verb verbs[] = {
- { "list", VERB_ANY, VERB_ANY, VERB_DEFAULT, list_links },
- { "status", VERB_ANY, VERB_ANY, 0, link_status },
- { "lldp", VERB_ANY, VERB_ANY, 0, link_lldp_status },
- { "label", VERB_ANY, VERB_ANY, 0, list_address_labels },
- { "delete", 2, VERB_ANY, 0, link_delete },
- { "renew", 2, VERB_ANY, 0, link_renew },
- { "reload", 1, 1, 0, verb_reload },
+ { "list", VERB_ANY, VERB_ANY, VERB_DEFAULT, list_links },
+ { "status", VERB_ANY, VERB_ANY, 0, link_status },
+ { "lldp", VERB_ANY, VERB_ANY, 0, link_lldp_status },
+ { "label", VERB_ANY, VERB_ANY, 0, list_address_labels },
+ { "delete", 2, VERB_ANY, 0, link_delete },
+ { "renew", 2, VERB_ANY, 0, link_renew },
+ { "reconfigure", 2, VERB_ANY, 0, verb_reconfigure },
+ { "reload", 1, 1, 0, verb_reload },
{}
};