#include "networkd-link.h"
#include "networkd-manager.h"
#include "networkd-network.h"
+#include "networkd-queue.h"
#include "socket-util.h"
#include "string-util.h"
-#include "sysctl-util.h"
-static int set_ipv6_proxy_ndp_address_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
+void network_adjust_ipv6_proxy_ndp(Network *network) {
+ assert(network);
+
+ if (set_isempty(network->ipv6_proxy_ndp_addresses))
+ return;
+
+ if (!socket_ipv6_is_supported()) {
+ log_once(LOG_WARNING,
+ "%s: IPv6 proxy NDP addresses are set, but IPv6 is not supported by kernel, "
+ "Ignoring IPv6 proxy NDP addresses.", network->filename);
+ network->ipv6_proxy_ndp_addresses = set_free_free(network->ipv6_proxy_ndp_addresses);
+ }
+}
+
+static int ipv6_proxy_ndp_address_configure_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
int r;
assert(link);
+ assert(link->static_ipv6_proxy_ndp_messages > 0);
+
+ link->static_ipv6_proxy_ndp_messages--;
r = sd_netlink_message_get_errno(m);
if (r < 0)
log_link_message_warning_errno(link, m, r, "Could not add IPv6 proxy ndp address entry, ignoring");
+ if (link->static_ipv6_proxy_ndp_messages == 0) {
+ log_link_debug(link, "IPv6 proxy NDP addresses set.");
+ link->static_ipv6_proxy_ndp_configured = true;
+ link_check_ready(link);
+ }
+
return 1;
}
/* send a request to the kernel to add a IPv6 Proxy entry to the neighbour table */
-static int ipv6_proxy_ndp_address_configure(Link *link, const struct in6_addr *address) {
+static int ipv6_proxy_ndp_address_configure(
+ const struct in6_addr *address,
+ Link *link,
+ link_netlink_message_handler_t callback) {
+
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
int r;
+ assert(address);
assert(link);
assert(link->manager);
- assert(address);
+ assert(link->manager->rtnl);
+ assert(callback);
/* create new netlink message */
r = sd_rtnl_message_new_neigh(link->manager->rtnl, &req, RTM_NEWNEIGH, link->ifindex, AF_INET6);
if (r < 0)
return log_link_error_errno(link, r, "Could not append NDA_DST attribute: %m");
- r = netlink_call_async(link->manager->rtnl, NULL, req, set_ipv6_proxy_ndp_address_handler,
+ r = netlink_call_async(link->manager->rtnl, NULL, req, callback,
link_netlink_destroy_callback, link);
if (r < 0)
return log_link_error_errno(link, r, "Could not send rtnetlink message: %m");
link_ref(link);
- return 0;
-}
-
-static bool ipv6_proxy_ndp_is_needed(Link *link) {
- assert(link);
-
- if (link->flags & IFF_LOOPBACK)
- return false;
-
- if (!link->network)
- return false;
-
- if (link->network->ipv6_proxy_ndp >= 0)
- return link->network->ipv6_proxy_ndp;
-
- return !set_isempty(link->network->ipv6_proxy_ndp_addresses);
-}
-
-static int ipv6_proxy_ndp_set(Link *link) {
- bool v;
- int r;
-
- assert(link);
-
- if (!socket_ipv6_is_supported())
- return 0;
-
- v = ipv6_proxy_ndp_is_needed(link);
-
- r = sysctl_write_ip_property_boolean(AF_INET6, link->ifname, "proxy_ndp", v);
- if (r < 0)
- return log_link_warning_errno(link, r, "Cannot configure proxy NDP for the interface, ignoring: %m");
-
- return v;
+ return 1;
}
-/* configure all ipv6 proxy ndp addresses */
-int link_set_ipv6_proxy_ndp_addresses(Link *link) {
+int link_request_static_ipv6_proxy_ndp_addresses(Link *link) {
struct in6_addr *address;
int r;
assert(link);
assert(link->network);
- /* enable or disable proxy_ndp itself depending on whether ipv6_proxy_ndp_addresses are set or not */
- r = ipv6_proxy_ndp_set(link);
- if (r <= 0)
- return 0;
+ link->static_ipv6_proxy_ndp_configured = false;
SET_FOREACH(address, link->network->ipv6_proxy_ndp_addresses) {
- r = ipv6_proxy_ndp_address_configure(link, address);
+ r = link_queue_request(link, REQUEST_TYPE_IPV6_PROXY_NDP, address, false,
+ &link->static_ipv6_proxy_ndp_messages,
+ ipv6_proxy_ndp_address_configure_handler, NULL);
if (r < 0)
- return r;
+ return log_link_warning_errno(link, r, "Failed to request IPv6 proxy NDP address: %m");
+ }
+
+ if (link->static_ipv6_proxy_ndp_messages == 0) {
+ link->static_ipv6_proxy_ndp_configured = true;
+ link_check_ready(link);
+ } else {
+ log_link_debug(link, "Setting IPv6 proxy NDP addresses.");
+ link_set_state(link, LINK_STATE_CONFIGURING);
}
return 0;
}
+int request_process_ipv6_proxy_ndp_address(Request *req) {
+ assert(req);
+ assert(req->link);
+ assert(req->ipv6_proxy_ndp);
+ assert(req->type == REQUEST_TYPE_IPV6_PROXY_NDP);
+
+ if (!link_is_ready_to_configure(req->link, false))
+ return 0;
+
+ return ipv6_proxy_ndp_address_configure(req->ipv6_proxy_ndp, req->link, req->netlink_handler);
+}
+
int config_parse_ipv6_proxy_ndp_address(
const char *unit,
const char *filename,