]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: do not serialize/deserialize ipv4ll address
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 28 Oct 2020 06:30:25 +0000 (15:30 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 28 Oct 2020 06:46:09 +0000 (15:46 +0900)
The link state file is always removed on stop. So, we cannot deserialize
the address from the file. Moreover, currently the IPv4 link-local address
is always dropped by link_drop_foreign_addresses() on restart. Let's
drop the serialize/deserialize logic for IPv4 LL address.

src/network/networkd-ipv4ll.c
src/network/networkd-ipv4ll.h
src/network/networkd-link.c

index 3be395e1ada6989ef9de339afc85073240660256..e4a20aeae1b5db8e1e3ed606ce87ed4502d15744 100644 (file)
@@ -142,25 +142,6 @@ static void ipv4ll_handler(sd_ipv4ll *ll, int event, void *userdata) {
         }
 }
 
-static int ipv4ll_init(Link *link) {
-        int r;
-
-        assert(link);
-
-        if (link->ipv4ll)
-                return 0;
-
-        r = sd_ipv4ll_new(&link->ipv4ll);
-        if (r < 0)
-                return r;
-
-        r = sd_ipv4ll_attach_event(link->ipv4ll, link->manager->event, 0);
-        if (r < 0)
-                return r;
-
-        return 0;
-}
-
 int ipv4ll_configure(Link *link) {
         uint64_t seed;
         int r;
@@ -170,9 +151,15 @@ int ipv4ll_configure(Link *link) {
         if (!link_ipv4ll_enabled(link, ADDRESS_FAMILY_IPV4 | ADDRESS_FAMILY_FALLBACK_IPV4))
                 return 0;
 
-        r = ipv4ll_init(link);
-        if (r < 0)
-                return r;
+        if (!link->ipv4ll) {
+                r = sd_ipv4ll_new(&link->ipv4ll);
+                if (r < 0)
+                        return r;
+
+                r = sd_ipv4ll_attach_event(link->ipv4ll, link->manager->event, 0);
+                if (r < 0)
+                        return r;
+        }
 
         if (link->sd_device &&
             net_get_unique_predictable_data(link->sd_device, true, &seed) >= 0) {
@@ -224,52 +211,6 @@ int ipv4ll_update_mac(Link *link) {
         return 0;
 }
 
-int link_serialize_ipv4ll(Link *link, FILE *f) {
-        struct in_addr address;
-        int r;
-
-        assert(link);
-
-        if (!link->ipv4ll)
-                return 0;
-
-        r = sd_ipv4ll_get_address(link->ipv4ll, &address);
-        if (r == -ENOENT)
-                return 0;
-        if (r < 0)
-                return r;
-
-        fputs("IPV4LL_ADDRESS=", f);
-        serialize_in_addrs(f, &address, 1, false, NULL);
-        fputc('\n', f);
-
-        return 0;
-}
-
-int link_deserialize_ipv4ll(Link *link, const char *ipv4ll_address) {
-        union in_addr_union address;
-        int r;
-
-        assert(link);
-
-        if (isempty(ipv4ll_address))
-                return 0;
-
-        r = in_addr_from_string(AF_INET, ipv4ll_address, &address);
-        if (r < 0)
-                return log_link_debug_errno(link, r, "Failed to parse IPv4LL address: %s", ipv4ll_address);
-
-        r = ipv4ll_init(link);
-        if (r < 0)
-                return log_link_debug_errno(link, r, "Failed to initialize IPv4LL client: %m");
-
-        r = sd_ipv4ll_set_address(link->ipv4ll, &address.in);
-        if (r < 0)
-                return log_link_debug_errno(link, r, "Failed to set initial IPv4LL address %s: %m", ipv4ll_address);
-
-        return 0;
-}
-
 int config_parse_ipv4ll(
                 const char* unit,
                 const char *filename,
index 4833e304b6c480eafcd48492dbe8f248dd729350..c5df691dcc93ef91c1c97d1447b8545fd9ddbd5f 100644 (file)
@@ -9,7 +9,5 @@ typedef struct Link Link;
 
 int ipv4ll_configure(Link *link);
 int ipv4ll_update_mac(Link *link);
-int link_serialize_ipv4ll(Link *link, FILE *f);
-int link_deserialize_ipv4ll(Link *link, const char *ipv4ll_address);
 
 CONFIG_PARSER_PROTOTYPE(config_parse_ipv4ll);
index 735dee80835e72720de1bb41a07c01c843871758..31f292043d6373d00db698f897bc5a489ba76bc3 100644 (file)
@@ -2414,8 +2414,7 @@ int link_initialized(Link *link, sd_device *device) {
 static int link_load(Link *link) {
         _cleanup_free_ char *network_file = NULL,
                             *addresses = NULL,
-                            *routes = NULL,
-                            *ipv4ll_address = NULL;
+                            *routes = NULL;
         int r;
 
         assert(link);
@@ -2423,8 +2422,7 @@ static int link_load(Link *link) {
         r = parse_env_file(NULL, link->state_file,
                            "NETWORK_FILE", &network_file,
                            "ADDRESSES", &addresses,
-                           "ROUTES", &routes,
-                           "IPV4LL_ADDRESS", &ipv4ll_address);
+                           "ROUTES", &routes);
         if (r < 0 && r != -ENOENT)
                 return log_link_error_errno(link, r, "Failed to read %s: %m", link->state_file);
 
@@ -2461,10 +2459,6 @@ network_file_fail:
         if (r < 0)
                 log_link_warning_errno(link, r, "Failed to load routes from %s, ignoring: %m", link->state_file);
 
-        r = link_deserialize_ipv4ll(link, ipv4ll_address);
-        if (r < 0)
-                log_link_warning_errno(link, r, "Failed to load IPv4LL address from %s, ignoring: %m", link->state_file);
-
         return 0;
 }
 
@@ -3170,10 +3164,6 @@ int link_save(Link *link) {
         } else
                 (void) unlink(link->lease_file);
 
-        r = link_serialize_ipv4ll(link, f);
-        if (r < 0)
-                goto fail;
-
         r = link_serialize_dhcp6_client(link, f);
         if (r < 0)
                 goto fail;