Skip to content

Commit fc72155

Browse files
committed
network: use structured initializers in wireguard.c
1 parent c195364 commit fc72155

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

src/network/netdev/wireguard.c

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ static WireguardPeer *wireguard_peer_new(Wireguard *w, unsigned section) {
3030
if (w->last_peer_section == section && w->peers)
3131
return w->peers;
3232

33-
peer = new0(WireguardPeer, 1);
33+
peer = new(WireguardPeer, 1);
3434
if (!peer)
3535
return NULL;
36-
peer->flags = WGPEER_F_REPLACE_ALLOWEDIPS;
36+
37+
*peer = (WireguardPeer) {
38+
.flags = WGPEER_F_REPLACE_ALLOWEDIPS,
39+
};
3740

3841
LIST_PREPEND(peers, w->peers, peer);
3942
w->last_peer_section = section;
@@ -576,12 +579,15 @@ int config_parse_wireguard_allowed_ips(const char *unit,
576579
return 0;
577580
}
578581

579-
ipmask = new0(WireguardIPmask, 1);
582+
ipmask = new(WireguardIPmask, 1);
580583
if (!ipmask)
581584
return log_oom();
582-
ipmask->family = family;
583-
ipmask->ip.in6 = addr.in6;
584-
ipmask->cidr = prefixlen;
585+
586+
*ipmask = (WireguardIPmask) {
587+
.family = family,
588+
.ip.in6 = addr.in6,
589+
.cidr = prefixlen,
590+
};
585591

586592
LIST_PREPEND(ipmasks, peer->ipmasks, ipmask);
587593
}
@@ -617,10 +623,6 @@ int config_parse_wireguard_endpoint(const char *unit,
617623
if (!peer)
618624
return log_oom();
619625

620-
endpoint = new0(WireguardEndpoint, 1);
621-
if (!endpoint)
622-
return log_oom();
623-
624626
if (rvalue[0] == '[') {
625627
begin = &rvalue[1];
626628
end = strchr(rvalue, ']');
@@ -654,10 +656,16 @@ int config_parse_wireguard_endpoint(const char *unit,
654656
if (!port)
655657
return log_oom();
656658

657-
endpoint->peer = TAKE_PTR(peer);
658-
endpoint->host = TAKE_PTR(host);
659-
endpoint->port = TAKE_PTR(port);
660-
endpoint->netdev = data;
659+
endpoint = new(WireguardEndpoint, 1);
660+
if (!endpoint)
661+
return log_oom();
662+
663+
*endpoint = (WireguardEndpoint) {
664+
.peer = TAKE_PTR(peer),
665+
.host = TAKE_PTR(host),
666+
.port = TAKE_PTR(port),
667+
.netdev = data,
668+
};
661669
LIST_PREPEND(endpoints, w->unresolved_endpoints, TAKE_PTR(endpoint));
662670

663671
return 0;

0 commit comments

Comments
 (0)