]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/network/networkd-ipv6-proxy-ndp.c
Use consistent spelling of systemd.condition_first_boot argument
[thirdparty/systemd.git] / src / network / networkd-ipv6-proxy-ndp.c
index a332eaefac07fb78b2786876129eb84efe4d61d4..edd369a9e78b6883e984eee0ec357b89a2ab49fb 100644 (file)
@@ -26,13 +26,17 @@ void network_adjust_ipv6_proxy_ndp(Network *network) {
         }
 }
 
-static int ipv6_proxy_ndp_address_configure_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
+static int ipv6_proxy_ndp_address_configure_handler(
+                sd_netlink *rtnl,
+                sd_netlink_message *m,
+                Request *req,
+                Link *link,
+                struct in6_addr *address) {
+
         int r;
 
+        assert(m);
         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)
@@ -48,39 +52,45 @@ static int ipv6_proxy_ndp_address_configure_handler(sd_netlink *rtnl, sd_netlink
 }
 
 /* send a request to the kernel to add an IPv6 Proxy entry to the neighbour table */
-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;
+static int ipv6_proxy_ndp_address_configure(const struct in6_addr *address, Link *link, Request *req) {
+        _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL;
         int r;
 
         assert(address);
         assert(link);
         assert(link->manager);
         assert(link->manager->rtnl);
-        assert(callback);
+        assert(req);
 
         /* create new netlink message */
-        r = sd_rtnl_message_new_neigh(link->manager->rtnl, &req, RTM_NEWNEIGH, link->ifindex, AF_INET6);
+        r = sd_rtnl_message_new_neigh(link->manager->rtnl, &m, RTM_NEWNEIGH, link->ifindex, AF_INET6);
         if (r < 0)
-                return log_link_error_errno(link, r, "Could not create RTM_NEWNEIGH message: %m");
+                return r;
 
-        r = sd_rtnl_message_neigh_set_flags(req, NTF_PROXY);
+        r = sd_rtnl_message_neigh_set_flags(m, NTF_PROXY);
         if (r < 0)
-                return log_link_error_errno(link, r, "Could not set neighbor flags: %m");
+                return r;
 
-        r = sd_netlink_message_append_in6_addr(req, NDA_DST, address);
+        r = sd_netlink_message_append_in6_addr(m, NDA_DST, address);
         if (r < 0)
-                return log_link_error_errno(link, r, "Could not append NDA_DST attribute: %m");
+                return r;
 
-        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");
+        return request_call_netlink_async(link->manager->rtnl, m, req);
+}
+
+static int ipv6_proxy_ndp_address_process_request(Request *req, Link *link, struct in6_addr *address) {
+        int r;
+
+        assert(req);
+        assert(link);
+        assert(address);
+
+        if (!link_is_ready_to_configure(link, false))
+                return 0;
 
-        link_ref(link);
+        r = ipv6_proxy_ndp_address_configure(address, link, req);
+        if (r < 0)
+                return log_link_warning_errno(link, r, "Failed to configure IPv6 proxy NDP address: %m");
 
         return 1;
 }
@@ -95,9 +105,14 @@ int link_request_static_ipv6_proxy_ndp_addresses(Link *link) {
         link->static_ipv6_proxy_ndp_configured = false;
 
         SET_FOREACH(address, link->network->ipv6_proxy_ndp_addresses) {
-                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);
+                r = link_queue_request_safe(link, REQUEST_TYPE_IPV6_PROXY_NDP,
+                                            address, NULL,
+                                            in6_addr_hash_func,
+                                            in6_addr_compare_func,
+                                            ipv6_proxy_ndp_address_process_request,
+                                            &link->static_ipv6_proxy_ndp_messages,
+                                            ipv6_proxy_ndp_address_configure_handler,
+                                            NULL);
                 if (r < 0)
                         return log_link_warning_errno(link, r, "Failed to request IPv6 proxy NDP address: %m");
         }
@@ -113,18 +128,6 @@ int link_request_static_ipv6_proxy_ndp_addresses(Link *link) {
         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,
@@ -138,13 +141,12 @@ int config_parse_ipv6_proxy_ndp_address(
                 void *userdata) {
 
         _cleanup_free_ struct in6_addr *address = NULL;
-        Network *network = userdata;
+        Network *network = ASSERT_PTR(userdata);
         union in_addr_union buffer;
         int r;
 
         assert(filename);
         assert(rvalue);
-        assert(network);
 
         if (isempty(rvalue)) {
                 network->ipv6_proxy_ndp_addresses = set_free_free(network->ipv6_proxy_ndp_addresses);