diff --git a/man/networkctl.xml b/man/networkctl.xml
index 7f68f249e47..842702fa332 100644
--- a/man/networkctl.xml
+++ b/man/networkctl.xml
@@ -289,6 +289,14 @@ s - Service VLAN, m - Two-port MAC Relay (TPMR)
Deletes virtual netdevs. Takes interface name or index number.
+
+
+ renew
+
+ Renew dynamic configurations e.g. addresses received from DHCP server.
+ Takes interface name or index number.
+
+
diff --git a/shell-completion/bash/networkctl b/shell-completion/bash/networkctl
index fdfa92d1125..290a62f8116 100644
--- a/shell-completion/bash/networkctl
+++ b/shell-completion/bash/networkctl
@@ -38,7 +38,7 @@ _networkctl() {
local -A VERBS=(
[STANDALONE]='label'
- [LINKS]='status list lldp delete'
+ [LINKS]='status list lldp delete renew'
)
_init_completion || return
diff --git a/src/libsystemd-network/sd-dhcp-client.c b/src/libsystemd-network/sd-dhcp-client.c
index 85238c21d1e..cadacc24d46 100644
--- a/src/libsystemd-network/sd-dhcp-client.c
+++ b/src/libsystemd-network/sd-dhcp-client.c
@@ -995,15 +995,14 @@ static int client_send_request(sd_dhcp_client *client) {
if (r < 0)
return r;
- if (client->state == DHCP_STATE_RENEWING) {
+ if (client->state == DHCP_STATE_RENEWING)
r = dhcp_network_send_udp_socket(client->fd,
client->lease->server_address,
DHCP_PORT_SERVER,
&request->dhcp,
sizeof(DHCPMessage) + optoffset);
- } else {
+ else
r = dhcp_client_send_raw(client, request, sizeof(DHCPPacket) + optoffset);
- }
if (r < 0)
return r;
@@ -1211,7 +1210,7 @@ static int client_initialize_time_events(sd_dhcp_client *client) {
assert(client);
assert(client->event);
- if (client->start_delay) {
+ if (client->start_delay > 0) {
assert_se(sd_event_now(client->event, clock_boottime_or_monotonic(), &usec) >= 0);
usec += client->start_delay;
}
@@ -1882,6 +1881,17 @@ static int client_receive_message_raw(
return client_handle_message(client, &packet->dhcp, len);
}
+int sd_dhcp_client_send_renew(sd_dhcp_client *client) {
+ assert_return(client, -EINVAL);
+ assert_return(client->fd >= 0, -EINVAL);
+
+ client->start_delay = 0;
+ client->attempt = 1;
+ client->state = DHCP_STATE_RENEWING;
+
+ return client_initialize_time_events(client);
+}
+
int sd_dhcp_client_start(sd_dhcp_client *client) {
int r;
diff --git a/src/libsystemd/sd-bus/bus-common-errors.c b/src/libsystemd/sd-bus/bus-common-errors.c
index edd30bf84d8..4e23edd9232 100644
--- a/src/libsystemd/sd-bus/bus-common-errors.c
+++ b/src/libsystemd/sd-bus/bus-common-errors.c
@@ -103,6 +103,7 @@ BUS_ERROR_MAP_ELF_REGISTER const sd_bus_error_map bus_common_errors[] = {
SD_BUS_ERROR_MAP(BUS_ERROR_NO_PRODUCT_UUID, EOPNOTSUPP),
SD_BUS_ERROR_MAP(BUS_ERROR_SPEED_METER_INACTIVE, EOPNOTSUPP),
+ SD_BUS_ERROR_MAP(BUS_ERROR_UNMANAGED_INTERFACE, EOPNOTSUPP),
SD_BUS_ERROR_MAP_END
};
diff --git a/src/libsystemd/sd-bus/bus-common-errors.h b/src/libsystemd/sd-bus/bus-common-errors.h
index 4a29b3bea8e..8da56551f69 100644
--- a/src/libsystemd/sd-bus/bus-common-errors.h
+++ b/src/libsystemd/sd-bus/bus-common-errors.h
@@ -82,5 +82,6 @@
#define BUS_ERROR_NO_PRODUCT_UUID "org.freedesktop.hostname1.NoProductUUID"
#define BUS_ERROR_SPEED_METER_INACTIVE "org.freedesktop.network1.SpeedMeterInactive"
+#define BUS_ERROR_UNMANAGED_INTERFACE "org.freedesktop.network1.UnmanagedInterface"
BUS_ERROR_MAP_ELF_USE(bus_common_errors);
diff --git a/src/network/networkctl.c b/src/network/networkctl.c
index a7cccbc690c..d087e43eb3d 100644
--- a/src/network/networkctl.c
+++ b/src/network/networkctl.c
@@ -1699,6 +1699,48 @@ static int link_delete(int argc, char *argv[], void *userdata) {
return r;
}
+static int link_renew_one(sd_bus *bus, int index, const char *name) {
+ _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
+ int r;
+
+ r = sd_bus_call_method(
+ bus,
+ "org.freedesktop.network1",
+ "/org/freedesktop/network1",
+ "org.freedesktop.network1.Manager",
+ "RenewLink",
+ &error,
+ NULL,
+ "i", index);
+ if (r < 0)
+ return log_error_errno(r, "Failed to renew dynamic configuration of interface %s: %s",
+ name, bus_error_message(&error, r));
+
+ return 0;
+}
+
+static int link_renew(int argc, char *argv[], void *userdata) {
+ _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
+ int index, i, k = 0, r;
+
+ r = sd_bus_open_system(&bus);
+ if (r < 0)
+ return log_error_errno(r, "Failed to connect system bus: %m");
+
+ 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 = link_renew_one(bus, index, argv[i]);
+ if (r < 0 && k >= 0)
+ k = r;
+ }
+
+ return k;
+}
+
+
static int help(void) {
_cleanup_free_ char *link = NULL;
int r;
@@ -1720,7 +1762,8 @@ static int help(void) {
" 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"
+ " delete DEVICES.. Delete virtual netdevs\n"
+ " renew DEVICES.. Renew dynamic configurations\n"
"\nSee the %s for details.\n"
, program_invocation_short_name
, link
@@ -1796,6 +1839,7 @@ static int networkctl_main(int argc, char *argv[]) {
{ "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 },
{}
};
diff --git a/src/network/networkd-link-bus.c b/src/network/networkd-link-bus.c
index 03552725ed3..9ef9146bcd7 100644
--- a/src/network/networkd-link-bus.c
+++ b/src/network/networkd-link-bus.c
@@ -575,6 +575,35 @@ int bus_link_method_revert_dns(sd_bus_message *message, void *userdata, sd_bus_e
return sd_bus_reply_method_return(message, NULL);
}
+int bus_link_method_renew(sd_bus_message *message, void *userdata, sd_bus_error *error) {
+ Link *l = userdata;
+ int r;
+
+ assert(l);
+
+ if (!l->network)
+ return sd_bus_error_setf(error, BUS_ERROR_UNMANAGED_INTERFACE,
+ "Interface %s is not managed by systemd-networkd",
+ l->ifname);
+
+ r = bus_verify_polkit_async(message, CAP_NET_ADMIN,
+ "org.freedesktop.network1.renew",
+ NULL, true, UID_INVALID,
+ &l->manager->polkit_registry, error);
+ if (r < 0)
+ return r;
+ if (r == 0)
+ return 1; /* Polkit will call us back */
+
+ if (l->dhcp_client) {
+ r = sd_dhcp_client_send_renew(l->dhcp_client);
+ if (r < 0)
+ return r;
+ }
+
+ return sd_bus_reply_method_return(message, NULL);
+}
+
const sd_bus_vtable link_vtable[] = {
SD_BUS_VTABLE_START(0),
@@ -595,6 +624,7 @@ const sd_bus_vtable link_vtable[] = {
SD_BUS_METHOD("SetDNSSECNegativeTrustAnchors", "as", NULL, bus_link_method_set_dnssec_negative_trust_anchors, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("RevertNTP", NULL, NULL, bus_link_method_revert_ntp, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("RevertDNS", NULL, NULL, bus_link_method_revert_dns, SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD("Renew", NULL, NULL, bus_link_method_renew, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_VTABLE_END
};
diff --git a/src/network/networkd-link-bus.h b/src/network/networkd-link-bus.h
index 2a653f5058a..1bea0b04536 100644
--- a/src/network/networkd-link-bus.h
+++ b/src/network/networkd-link-bus.h
@@ -30,3 +30,4 @@ int bus_link_method_set_dnssec(sd_bus_message *message, void *userdata, sd_bus_e
int bus_link_method_set_dnssec_negative_trust_anchors(sd_bus_message *message, void *userdata, sd_bus_error *error);
int bus_link_method_revert_ntp(sd_bus_message *message, void *userdata, sd_bus_error *error);
int bus_link_method_revert_dns(sd_bus_message *message, void *userdata, sd_bus_error *error);
+int bus_link_method_renew(sd_bus_message *message, void *userdata, sd_bus_error *error);
diff --git a/src/network/networkd-manager-bus.c b/src/network/networkd-manager-bus.c
index 37b04ce5566..7484fcfa123 100644
--- a/src/network/networkd-manager-bus.c
+++ b/src/network/networkd-manager-bus.c
@@ -183,6 +183,10 @@ static int bus_method_revert_link_dns(sd_bus_message *message, void *userdata, s
return call_link_method(userdata, message, bus_link_method_revert_dns, error);
}
+static int bus_method_renew_link(sd_bus_message *message, void *userdata, sd_bus_error *error) {
+ return call_link_method(userdata, message, bus_link_method_renew, error);
+}
+
const sd_bus_vtable manager_vtable[] = {
SD_BUS_VTABLE_START(0),
@@ -204,6 +208,7 @@ const sd_bus_vtable manager_vtable[] = {
SD_BUS_METHOD("SetLinkDNSSECNegativeTrustAnchors", "ias", NULL, bus_method_set_link_dnssec_negative_trust_anchors, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("RevertLinkNTP", "i", NULL, bus_method_revert_link_ntp, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("RevertLinkDNS", "i", NULL, bus_method_revert_link_dns, SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD("RenewLink", "i", NULL, bus_method_renew_link, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_VTABLE_END
};
diff --git a/src/network/org.freedesktop.network1.policy b/src/network/org.freedesktop.network1.policy
index d6b8dd9a105..4a33f5a8aad 100644
--- a/src/network/org.freedesktop.network1.policy
+++ b/src/network/org.freedesktop.network1.policy
@@ -139,4 +139,15 @@
unix-user:systemd-network
+
+ Renew dynamic addresses
+ Authentication is required to renew dynamic addresses.
+
+ auth_admin
+ auth_admin
+ auth_admin_keep
+
+ unix-user:systemd-network
+
+
diff --git a/src/systemd/sd-dhcp-client.h b/src/systemd/sd-dhcp-client.h
index 46209cda053..d2d74b2b4cf 100644
--- a/src/systemd/sd-dhcp-client.h
+++ b/src/systemd/sd-dhcp-client.h
@@ -178,6 +178,7 @@ int sd_dhcp_client_get_lease(
int sd_dhcp_client_stop(sd_dhcp_client *client);
int sd_dhcp_client_start(sd_dhcp_client *client);
int sd_dhcp_client_send_release(sd_dhcp_client *client);
+int sd_dhcp_client_send_renew(sd_dhcp_client *client);
sd_dhcp_client *sd_dhcp_client_ref(sd_dhcp_client *client);
sd_dhcp_client *sd_dhcp_client_unref(sd_dhcp_client *client);