]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: use structured initializers in wireguard.c
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 3 Nov 2018 12:57:06 +0000 (21:57 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 5 Nov 2018 04:19:02 +0000 (13:19 +0900)
src/network/netdev/wireguard.c

index d773dedc54950a9150a28d3c024c2f47c0cb9d1a..d5a0a19e9f212266b2051ca35e54c06e0d540edd 100644 (file)
@@ -30,10 +30,13 @@ static WireguardPeer *wireguard_peer_new(Wireguard *w, unsigned section) {
         if (w->last_peer_section == section && w->peers)
                 return w->peers;
 
-        peer = new0(WireguardPeer, 1);
+        peer = new(WireguardPeer, 1);
         if (!peer)
                 return NULL;
-        peer->flags = WGPEER_F_REPLACE_ALLOWEDIPS;
+
+        *peer = (WireguardPeer) {
+                .flags = WGPEER_F_REPLACE_ALLOWEDIPS,
+        };
 
         LIST_PREPEND(peers, w->peers, peer);
         w->last_peer_section = section;
@@ -576,12 +579,15 @@ int config_parse_wireguard_allowed_ips(const char *unit,
                         return 0;
                 }
 
-                ipmask = new0(WireguardIPmask, 1);
+                ipmask = new(WireguardIPmask, 1);
                 if (!ipmask)
                         return log_oom();
-                ipmask->family = family;
-                ipmask->ip.in6 = addr.in6;
-                ipmask->cidr = prefixlen;
+
+                *ipmask = (WireguardIPmask) {
+                        .family = family,
+                        .ip.in6 = addr.in6,
+                        .cidr = prefixlen,
+                };
 
                 LIST_PREPEND(ipmasks, peer->ipmasks, ipmask);
         }
@@ -617,10 +623,6 @@ int config_parse_wireguard_endpoint(const char *unit,
         if (!peer)
                 return log_oom();
 
-        endpoint = new0(WireguardEndpoint, 1);
-        if (!endpoint)
-                return log_oom();
-
         if (rvalue[0] == '[') {
                 begin = &rvalue[1];
                 end = strchr(rvalue, ']');
@@ -654,10 +656,16 @@ int config_parse_wireguard_endpoint(const char *unit,
         if (!port)
                 return log_oom();
 
-        endpoint->peer = TAKE_PTR(peer);
-        endpoint->host = TAKE_PTR(host);
-        endpoint->port = TAKE_PTR(port);
-        endpoint->netdev = data;
+        endpoint = new(WireguardEndpoint, 1);
+        if (!endpoint)
+                return log_oom();
+
+        *endpoint = (WireguardEndpoint) {
+                .peer = TAKE_PTR(peer),
+                .host = TAKE_PTR(host),
+                .port = TAKE_PTR(port),
+                .netdev = data,
+        };
         LIST_PREPEND(endpoints, w->unresolved_endpoints, TAKE_PTR(endpoint));
 
         return 0;