From: Yu Watanabe Date: Wed, 23 Oct 2019 13:32:27 +0000 (+0900) Subject: network: introduce Reconfigure() bus method X-Git-Tag: v244~202^2~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=99b8517ca7eb0a9015155cc1e0a9ae66e07240f0;p=platform%2Fupstream%2Fsystemd.git network: introduce Reconfigure() bus method --- diff --git a/src/network/networkd-link-bus.c b/src/network/networkd-link-bus.c index 9ef9146..b0abc0a 100644 --- a/src/network/networkd-link-bus.c +++ b/src/network/networkd-link-bus.c @@ -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 }; diff --git a/src/network/networkd-link-bus.h b/src/network/networkd-link-bus.h index 1bea0b0..09e4ad6 100644 --- a/src/network/networkd-link-bus.h +++ b/src/network/networkd-link-bus.h @@ -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); diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index 5fedd37..179408cb 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -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; } diff --git a/src/network/networkd-link.h b/src/network/networkd-link.h index 8a96da9..b475571 100644 --- a/src/network/networkd-link.h +++ b/src/network/networkd-link.h @@ -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, \ diff --git a/src/network/networkd-manager-bus.c b/src/network/networkd-manager-bus.c index 37253ce..773dcf0 100644 --- a/src/network/networkd-manager-bus.c +++ b/src/network/networkd-manager-bus.c @@ -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 diff --git a/src/network/org.freedesktop.network1.policy b/src/network/org.freedesktop.network1.policy index 79b418b..9b1895e 100644 --- a/src/network/org.freedesktop.network1.policy +++ b/src/network/org.freedesktop.network1.policy @@ -161,4 +161,15 @@ unix-user:systemd-network + + Reconfigure network interface + Authentication is required to reconfigure network interface. + + auth_admin + auth_admin + auth_admin_keep + + unix-user:systemd-network + +