mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-08 21:17:47 +03:00
Merge pull request #11883 from yuwata/network-dhcp-renew
network: dhcp renew
This commit is contained in:
commit
82d1264048
@ -289,6 +289,14 @@ s - Service VLAN, m - Two-port MAC Relay (TPMR)
|
||||
<listitem><para>Deletes virtual netdevs. Takes interface name or index number.</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>
|
||||
<command>renew</command>
|
||||
</term>
|
||||
<listitem><para>Renew dynamic configurations e.g. addresses received from DHCP server.
|
||||
Takes interface name or index number.</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
</variablelist>
|
||||
</refsect1>
|
||||
|
||||
|
@ -38,7 +38,7 @@ _networkctl() {
|
||||
|
||||
local -A VERBS=(
|
||||
[STANDALONE]='label'
|
||||
[LINKS]='status list lldp delete'
|
||||
[LINKS]='status list lldp delete renew'
|
||||
)
|
||||
|
||||
_init_completion || return
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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
|
||||
};
|
||||
|
@ -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);
|
||||
|
@ -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 },
|
||||
{}
|
||||
};
|
||||
|
||||
|
@ -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
|
||||
};
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
};
|
||||
|
@ -139,4 +139,15 @@
|
||||
<annotate key="org.freedesktop.policykit.owner">unix-user:systemd-network</annotate>
|
||||
</action>
|
||||
|
||||
<action id="org.freedesktop.network1.renew">
|
||||
<description gettext-domain="systemd">Renew dynamic addresses</description>
|
||||
<message gettext-domain="systemd">Authentication is required to renew dynamic addresses.</message>
|
||||
<defaults>
|
||||
<allow_any>auth_admin</allow_any>
|
||||
<allow_inactive>auth_admin</allow_inactive>
|
||||
<allow_active>auth_admin_keep</allow_active>
|
||||
</defaults>
|
||||
<annotate key="org.freedesktop.policykit.owner">unix-user:systemd-network</annotate>
|
||||
</action>
|
||||
|
||||
</policyconfig>
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user