]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/network/networkd-address-label.c
tree-wide: drop 'This file is part of systemd' blurb
[thirdparty/systemd.git] / src / network / networkd-address-label.c
index 1248719cf349c10f33c300517e848e89dd3c9b81..cb964cbda2845433edc5cb1527c369c8ff4a818c 100644 (file)
@@ -1,20 +1,6 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
 /***
-  This file is part of systemd.
-
   Copyright 2017 Susant Sahani
-
-  systemd is free software; you can redistribute it and/or modify it
-  under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or
-  (at your option) any later version.
-
-  systemd is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
 #include <net/if.h>
 #include "socket-util.h"
 
 int address_label_new(AddressLabel **ret) {
-        _cleanup_address_label_free_ AddressLabel *addrlabel = NULL;
+        _cleanup_(address_label_freep) AddressLabel *addrlabel = NULL;
 
         addrlabel = new0(AddressLabel, 1);
         if (!addrlabel)
                 return -ENOMEM;
 
-        *ret = addrlabel;
-        addrlabel = NULL;
+        *ret = TAKE_PTR(addrlabel);
 
         return 0;
 }
@@ -60,8 +45,8 @@ void address_label_free(AddressLabel *label) {
 }
 
 static int address_label_new_static(Network *network, const char *filename, unsigned section_line, AddressLabel **ret) {
-        _cleanup_network_config_section_free_ NetworkConfigSection *n = NULL;
-        _cleanup_address_label_free_ AddressLabel *label = NULL;
+        _cleanup_(network_config_section_freep) NetworkConfigSection *n = NULL;
+        _cleanup_(address_label_freep) AddressLabel *label = NULL;
         int r;
 
         assert(network);
@@ -74,8 +59,7 @@ static int address_label_new_static(Network *network, const char *filename, unsi
 
         label = hashmap_get(network->address_labels_by_section, n);
         if (label) {
-                *ret = label;
-                label = NULL;
+                *ret = TAKE_PTR(label);
 
                 return 0;
         }
@@ -84,8 +68,7 @@ static int address_label_new_static(Network *network, const char *filename, unsi
         if (r < 0)
                 return r;
 
-        label->section = n;
-        n = NULL;
+        label->section = TAKE_PTR(n);
 
         r = hashmap_put(network->address_labels_by_section, label->section, label);
         if (r < 0)
@@ -95,8 +78,7 @@ static int address_label_new_static(Network *network, const char *filename, unsi
         LIST_APPEND(labels, network->address_labels, label);
         network->n_address_labels++;
 
-        *ret = label;
-        label = NULL;
+        *ret = TAKE_PTR(label);
 
         return 0;
 }
@@ -117,7 +99,7 @@ int address_label_configure(
         assert(link->manager->rtnl);
 
         r = sd_rtnl_message_new_addrlabel(link->manager->rtnl, &req, RTM_NEWADDRLABEL,
-                                          link->ifindex, label->family);
+                                          link->ifindex, AF_INET6);
         if (r < 0)
                 return log_error_errno(r, "Could not allocate RTM_NEWADDR message: %m");
 
@@ -153,11 +135,9 @@ int config_parse_address_label_prefix(const char *unit,
                                       void *data,
                                       void *userdata) {
 
-        _cleanup_address_label_free_ AddressLabel *n = NULL;
+        _cleanup_(address_label_freep) AddressLabel *n = NULL;
         Network *network = userdata;
-        const char *prefix, *e;
-        union in_addr_union buffer;
-        int r, f;
+        int r;
 
         assert(filename);
         assert(section);
@@ -169,44 +149,12 @@ int config_parse_address_label_prefix(const char *unit,
         if (r < 0)
                 return r;
 
-        /* AddressLabel=prefix/prefixlen */
-
-        /* prefixlen */
-        e = strchr(rvalue, '/');
-        if (e) {
-                unsigned i;
-
-                r = safe_atou(e + 1, &i);
-                if (r < 0) {
-                        log_syntax(unit, LOG_ERR, filename, line, r, "Prefix length is invalid, ignoring assignment: %s", e + 1);
-                        return 0;
-                }
-
-                if (i > 128) {
-                        log_syntax(unit, LOG_ERR, filename, line, r, "Prefix length is out of range, ignoring assignment: %s", e + 1);
-                        return 0;
-                }
-
-                n->prefixlen = (unsigned char) i;
-
-                prefix = strndupa(rvalue, e - rvalue);
-        } else
-                prefix = rvalue;
-
-        r = in_addr_from_string_auto(prefix, &f, &buffer);
+        r = in_addr_prefix_from_string(rvalue, AF_INET6, &n->in_addr, &n->prefixlen);
         if (r < 0) {
-                log_syntax(unit, LOG_ERR, filename, line, r, "Address label is invalid, ignoring assignment: %s", prefix);
+                log_syntax(unit, LOG_ERR, filename, line, r, "Address label is invalid, ignoring assignment: %s", rvalue);
                 return 0;
         }
 
-        if (f != AF_INET6) {
-                log_syntax(unit, LOG_ERR, filename, line, 0, "Address label family is not IPv6, ignoring assignment: %s", prefix);
-                return 0;
-        }
-
-        n->family = f;
-        n->in_addr = buffer;
-
         n = NULL;
 
         return 0;
@@ -224,7 +172,7 @@ int config_parse_address_label(
                 void *data,
                 void *userdata) {
 
-        _cleanup_address_label_free_ AddressLabel *n = NULL;
+        _cleanup_(address_label_freep) AddressLabel *n = NULL;
         Network *network = userdata;
         uint32_t k;
         int r;