Skip to content

Commit daad60d

Browse files
committed
network: introduce link_deserialize_ipv4ll()
1 parent 571eeba commit daad60d

File tree

3 files changed

+50
-31
lines changed

3 files changed

+50
-31
lines changed

src/network/networkd-ipv4ll.c

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,25 @@ static void ipv4ll_handler(sd_ipv4ll *ll, int event, void *userdata) {
142142
}
143143
}
144144

145+
static int ipv4ll_init(Link *link) {
146+
int r;
147+
148+
assert(link);
149+
150+
if (link->ipv4ll)
151+
return 0;
152+
153+
r = sd_ipv4ll_new(&link->ipv4ll);
154+
if (r < 0)
155+
return r;
156+
157+
r = sd_ipv4ll_attach_event(link->ipv4ll, link->manager->event, 0);
158+
if (r < 0)
159+
return r;
160+
161+
return 0;
162+
}
163+
145164
int ipv4ll_configure(Link *link) {
146165
uint64_t seed;
147166
int r;
@@ -150,15 +169,9 @@ int ipv4ll_configure(Link *link) {
150169
assert(link->network);
151170
assert(link->network->link_local & (ADDRESS_FAMILY_IPV4 | ADDRESS_FAMILY_FALLBACK_IPV4));
152171

153-
if (!link->ipv4ll) {
154-
r = sd_ipv4ll_new(&link->ipv4ll);
155-
if (r < 0)
156-
return r;
157-
158-
r = sd_ipv4ll_attach_event(link->ipv4ll, NULL, 0);
159-
if (r < 0)
160-
return r;
161-
}
172+
r = ipv4ll_init(link);
173+
if (r < 0)
174+
return r;
162175

163176
if (link->sd_device &&
164177
net_get_unique_predictable_data(link->sd_device, true, &seed) >= 0) {
@@ -182,6 +195,30 @@ int ipv4ll_configure(Link *link) {
182195
return 0;
183196
}
184197

198+
int link_deserialize_ipv4ll(Link *link, const char *ipv4ll_address) {
199+
union in_addr_union address;
200+
int r;
201+
202+
assert(link);
203+
204+
if (isempty(ipv4ll_address))
205+
return 0;
206+
207+
r = in_addr_from_string(AF_INET, ipv4ll_address, &address);
208+
if (r < 0)
209+
return log_link_debug_errno(link, r, "Failed to parse IPv4LL address: %s", ipv4ll_address);
210+
211+
r = ipv4ll_init(link);
212+
if (r < 0)
213+
return log_link_debug_errno(link, r, "Failed to initialize IPv4LL client: %m");
214+
215+
r = sd_ipv4ll_set_address(link->ipv4ll, &address.in);
216+
if (r < 0)
217+
return log_link_debug_errno(link, r, "Failed to set initial IPv4LL address %s: %m", ipv4ll_address);
218+
219+
return 0;
220+
}
221+
185222
int config_parse_ipv4ll(
186223
const char* unit,
187224
const char *filename,

src/network/networkd-ipv4ll.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
typedef struct Link Link;
99

1010
int ipv4ll_configure(Link *link);
11+
int link_deserialize_ipv4ll(Link *link, const char *ipv4ll_address);
1112

1213
CONFIG_PARSER_PROTOTYPE(config_parse_ipv4ll);

src/network/networkd-link.c

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2679,7 +2679,6 @@ static int link_load(Link *link) {
26792679
*routes = NULL,
26802680
*dhcp4_address = NULL,
26812681
*ipv4ll_address = NULL;
2682-
union in_addr_union address;
26832682
int r;
26842683

26852684
assert(link);
@@ -2730,27 +2729,9 @@ static int link_load(Link *link) {
27302729
if (r < 0)
27312730
log_link_warning_errno(link, r, "Failed to load DHCPv4 address from %s, ignoring: %m", link->state_file);
27322731

2733-
if (ipv4ll_address) {
2734-
r = in_addr_from_string(AF_INET, ipv4ll_address, &address);
2735-
if (r < 0) {
2736-
log_link_debug_errno(link, r, "Failed to parse IPv4LL address %s: %m", ipv4ll_address);
2737-
goto ipv4ll_address_fail;
2738-
}
2739-
2740-
r = sd_ipv4ll_new(&link->ipv4ll);
2741-
if (r < 0)
2742-
return log_link_error_errno(link, r, "Failed to create IPv4LL client: %m");
2743-
2744-
r = sd_ipv4ll_attach_event(link->ipv4ll, NULL, 0);
2745-
if (r < 0)
2746-
return log_link_error_errno(link, r, "Failed to attach IPv4LL event: %m");
2747-
2748-
r = sd_ipv4ll_set_address(link->ipv4ll, &address.in);
2749-
if (r < 0)
2750-
return log_link_error_errno(link, r, "Failed to set initial IPv4LL address %s: %m", ipv4ll_address);
2751-
}
2752-
2753-
ipv4ll_address_fail:
2732+
r = link_deserialize_ipv4ll(link, ipv4ll_address);
2733+
if (r < 0)
2734+
log_link_warning_errno(link, r, "Failed to load IPv4LL address from %s, ignoring: %m", link->state_file);
27542735

27552736
return 0;
27562737
}

0 commit comments

Comments
 (0)