network: introduce link_deserialize_ipv4ll()
This commit is contained in:
parent
571eeba909
commit
daad60d19e
|
@ -142,6 +142,25 @@ 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;
|
||||
|
@ -150,16 +169,10 @@ int ipv4ll_configure(Link *link) {
|
|||
assert(link->network);
|
||||
assert(link->network->link_local & (ADDRESS_FAMILY_IPV4 | ADDRESS_FAMILY_FALLBACK_IPV4));
|
||||
|
||||
if (!link->ipv4ll) {
|
||||
r = sd_ipv4ll_new(&link->ipv4ll);
|
||||
r = ipv4ll_init(link);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_ipv4ll_attach_event(link->ipv4ll, NULL, 0);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
if (link->sd_device &&
|
||||
net_get_unique_predictable_data(link->sd_device, true, &seed) >= 0) {
|
||||
r = sd_ipv4ll_set_address_seed(link->ipv4ll, seed);
|
||||
|
@ -182,6 +195,30 @@ int ipv4ll_configure(Link *link) {
|
|||
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,
|
||||
|
|
|
@ -8,5 +8,6 @@
|
|||
typedef struct Link Link;
|
||||
|
||||
int ipv4ll_configure(Link *link);
|
||||
int link_deserialize_ipv4ll(Link *link, const char *ipv4ll_address);
|
||||
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_ipv4ll);
|
||||
|
|
|
@ -2679,7 +2679,6 @@ static int link_load(Link *link) {
|
|||
*routes = NULL,
|
||||
*dhcp4_address = NULL,
|
||||
*ipv4ll_address = NULL;
|
||||
union in_addr_union address;
|
||||
int r;
|
||||
|
||||
assert(link);
|
||||
|
@ -2730,27 +2729,9 @@ network_file_fail:
|
|||
if (r < 0)
|
||||
log_link_warning_errno(link, r, "Failed to load DHCPv4 address from %s, ignoring: %m", link->state_file);
|
||||
|
||||
if (ipv4ll_address) {
|
||||
r = in_addr_from_string(AF_INET, ipv4ll_address, &address);
|
||||
if (r < 0) {
|
||||
log_link_debug_errno(link, r, "Failed to parse IPv4LL address %s: %m", ipv4ll_address);
|
||||
goto ipv4ll_address_fail;
|
||||
}
|
||||
|
||||
r = sd_ipv4ll_new(&link->ipv4ll);
|
||||
r = link_deserialize_ipv4ll(link, ipv4ll_address);
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "Failed to create IPv4LL client: %m");
|
||||
|
||||
r = sd_ipv4ll_attach_event(link->ipv4ll, NULL, 0);
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "Failed to attach IPv4LL event: %m");
|
||||
|
||||
r = sd_ipv4ll_set_address(link->ipv4ll, &address.in);
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "Failed to set initial IPv4LL address %s: %m", ipv4ll_address);
|
||||
}
|
||||
|
||||
ipv4ll_address_fail:
|
||||
log_link_warning_errno(link, r, "Failed to load IPv4LL address from %s, ignoring: %m", link->state_file);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue