Skip to content

Commit 5dc31db

Browse files
committed
network: reduce scope of variables, etc.
1 parent a270607 commit 5dc31db

File tree

1 file changed

+11
-23
lines changed

1 file changed

+11
-23
lines changed

src/network/networkd-dhcp-server.c

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,24 @@ static Address* link_find_dhcp_server_address(Link *link) {
2121
assert(link->network);
2222

2323
/* The first statically configured address if there is any */
24-
LIST_FOREACH(addresses, address, link->network->static_addresses) {
25-
26-
if (address->family != AF_INET)
27-
continue;
28-
29-
if (in_addr_is_null(address->family, &address->in_addr))
30-
continue;
31-
32-
return address;
33-
}
24+
LIST_FOREACH(addresses, address, link->network->static_addresses)
25+
if (address->family == AF_INET &&
26+
!in_addr_is_null(address->family, &address->in_addr))
27+
return address;
3428

3529
/* If that didn't work, find a suitable address we got from the pool */
36-
LIST_FOREACH(addresses, address, link->pool_addresses) {
37-
if (address->family != AF_INET)
38-
continue;
39-
40-
return address;
41-
}
30+
LIST_FOREACH(addresses, address, link->pool_addresses)
31+
if (address->family == AF_INET)
32+
return address;
4233

4334
return NULL;
4435
}
4536

4637
static int link_push_uplink_dns_to_dhcp_server(Link *link, sd_dhcp_server *s) {
4738
_cleanup_free_ struct in_addr *addresses = NULL;
4839
size_t n_addresses = 0, n_allocated = 0;
49-
unsigned i;
5040

51-
for (i = 0; i < link->network->n_dns; i++) {
41+
for (unsigned i = 0; i < link->network->n_dns; i++) {
5242
struct in_addr ia;
5343

5444
/* Only look for IPv4 addresses */
@@ -68,16 +58,14 @@ static int link_push_uplink_dns_to_dhcp_server(Link *link, sd_dhcp_server *s) {
6858
}
6959

7060
if (link->network->dhcp_use_dns && link->dhcp_lease) {
71-
const struct in_addr *da = NULL;
72-
int j, n;
61+
const struct in_addr *da;
7362

74-
n = sd_dhcp_lease_get_dns(link->dhcp_lease, &da);
63+
int n = sd_dhcp_lease_get_dns(link->dhcp_lease, &da);
7564
if (n > 0) {
76-
7765
if (!GREEDY_REALLOC(addresses, n_allocated, n_addresses + n))
7866
return log_oom();
7967

80-
for (j = 0; j < n; j++)
68+
for (int j = 0; j < n; j++)
8169
if (in4_addr_is_non_local(&da[j]))
8270
addresses[n_addresses++] = da[j];
8371
}

0 commit comments

Comments
 (0)