network: introduce Reconfigure() bus method

This commit is contained in:
Yu Watanabe 2019-10-23 22:32:27 +09:00
parent f39dbf28f3
commit 99b8517ca7
6 changed files with 46 additions and 5 deletions

View File

@ -604,6 +604,29 @@ int bus_link_method_renew(sd_bus_message *message, void *userdata, sd_bus_error
return sd_bus_reply_method_return(message, NULL);
}
int bus_link_method_reconfigure(sd_bus_message *message, void *userdata, sd_bus_error *error) {
Link *l = userdata;
int r;
assert(message);
assert(l);
r = bus_verify_polkit_async(message, CAP_NET_ADMIN,
"org.freedesktop.network1.reconfigure",
NULL, true, UID_INVALID,
&l->manager->polkit_registry, error);
if (r < 0)
return r;
if (r == 0)
return 1; /* Polkit will call us back */
r = link_reconfigure(l, true);
if (r < 0)
return r;
return sd_bus_reply_method_return(message, NULL);
}
const sd_bus_vtable link_vtable[] = {
SD_BUS_VTABLE_START(0),
@ -625,6 +648,7 @@ const sd_bus_vtable link_vtable[] = {
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_METHOD("Reconfigure", NULL, NULL, bus_link_method_reconfigure, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_VTABLE_END
};

View File

@ -31,3 +31,4 @@ int bus_link_method_set_dnssec_negative_trust_anchors(sd_bus_message *message, v
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);
int bus_link_method_reconfigure(sd_bus_message *message, void *userdata, sd_bus_error *error);

View File

@ -2857,7 +2857,7 @@ static int link_configure_duid(Link *link) {
return 0;
}
int link_reconfigure(Link *link) {
int link_reconfigure(Link *link, bool force) {
Network *network;
int r;
@ -2875,7 +2875,7 @@ int link_reconfigure(Link *link) {
} else if (r < 0)
return r;
if (link->network == network)
if (link->network == network && !force)
return 0;
log_link_info(link, "Re-configuring with %s", network->filename);
@ -3337,7 +3337,7 @@ static int link_carrier_gained(Link *link) {
if (r < 0)
return r;
if (r > 0) {
r = link_reconfigure(link);
r = link_reconfigure(link, false);
if (r < 0)
return r;
}

View File

@ -208,7 +208,7 @@ uint32_t link_get_ipv6_accept_ra_route_table(Link *link);
int link_request_set_routes(Link *link);
int link_request_set_nexthop(Link *link);
int link_reconfigure(Link *link);
int link_reconfigure(Link *link, bool force);
#define ADDRESS_FMT_VAL(address) \
be32toh((address).s_addr) >> 24, \

View File

@ -190,6 +190,10 @@ static int bus_method_renew_link(sd_bus_message *message, void *userdata, sd_bus
return call_link_method(userdata, message, bus_link_method_renew, error);
}
static int bus_method_reconfigure_link(sd_bus_message *message, void *userdata, sd_bus_error *error) {
return call_link_method(userdata, message, bus_link_method_reconfigure, error);
}
static int bus_method_reload(sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *manager = userdata;
Iterator i;
@ -214,7 +218,7 @@ static int bus_method_reload(sd_bus_message *message, void *userdata, sd_bus_err
return r;
HASHMAP_FOREACH(link, manager->links, i) {
r = link_reconfigure(link);
r = link_reconfigure(link, false);
if (r < 0)
return r;
}
@ -244,6 +248,7 @@ const sd_bus_vtable manager_vtable[] = {
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_METHOD("ReconfigureLink", "i", NULL, bus_method_reconfigure_link, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("Reload", NULL, NULL, bus_method_reload, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_VTABLE_END

View File

@ -161,4 +161,15 @@
<annotate key="org.freedesktop.policykit.owner">unix-user:systemd-network</annotate>
</action>
<action id="org.freedesktop.network1.reconfigure">
<description gettext-domain="systemd">Reconfigure network interface</description>
<message gettext-domain="systemd">Authentication is required to reconfigure network interface.</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>