network: do not serialize/deserialize ipv4ll address

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.
This commit is contained in:
Yu Watanabe 2020-10-28 15:30:25 +09:00
parent 778c879533
commit ca97e7cda0
3 changed files with 11 additions and 82 deletions

View 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,

View 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);

View 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;