chiark / gitweb /
dhcp: fix creation of req_opts array
[elogind.git] / src / network / networkd-address.c
index 9cfc0955d31a7d615c7d74fab38d2552b8681b69..63ba33ea24ca9724d881da56e26cacdb1fceda18 100644 (file)
@@ -79,7 +79,12 @@ int address_configure(Address *address, Link *link,
         _cleanup_sd_rtnl_message_unref_ sd_rtnl_message *req = NULL;
         int r;
 
+        assert(address);
+        assert(address->family == AF_INET || address->family == AF_INET6);
+        assert(link);
+        assert(link->ifindex > 0);
         assert(link->manager);
+        assert(link->manager->rtnl);
 
         r = sd_rtnl_message_addr_new(RTM_NEWADDR, link->ifindex,
                         address->family, address->prefixlen,
@@ -90,7 +95,10 @@ int address_configure(Address *address, Link *link,
                 return r;
         }
 
-        r = sd_rtnl_message_append(req, IFA_LOCAL, &address->in_addr);
+        if (address->family == AF_INET)
+                r = sd_rtnl_message_append_in_addr(req, IFA_LOCAL, &address->in_addr.in);
+        else if (address->family == AF_INET6)
+                r = sd_rtnl_message_append_in6_addr(req, IFA_LOCAL, &address->in_addr.in6);
         if (r < 0) {
                 log_error("Could not append IFA_LOCAL attribute: %s",
                           strerror(-r));
@@ -102,7 +110,7 @@ int address_configure(Address *address, Link *link,
 
                 broadcast.s_addr = address->in_addr.in.s_addr | address->netmask.s_addr;
 
-                r = sd_rtnl_message_append(req, IFA_BROADCAST, &broadcast);
+                r = sd_rtnl_message_append_in_addr(req, IFA_BROADCAST, &broadcast);
                 if (r < 0) {
                         log_error("Could not append IFA_BROADCAST attribute: %s",
                                   strerror(-r));
@@ -111,7 +119,7 @@ int address_configure(Address *address, Link *link,
         }
 
         if (address->label) {
-                r = sd_rtnl_message_append(req, IFA_LABEL, address->label);
+                r = sd_rtnl_message_append_string(req, IFA_LABEL, address->label);
                 if (r < 0) {
                         log_error("Could not append IFA_LABEL attribute: %s",
                                   strerror(-r));
@@ -125,8 +133,6 @@ int address_configure(Address *address, Link *link,
                 return r;
         }
 
-        link->rtnl_messages ++;
-
         return 0;
 }
 
@@ -152,6 +158,12 @@ int config_parse_address(const char *unit,
         assert(rvalue);
         assert(data);
 
+        if (streq(section, "Network")) {
+                /* we are not in an Address section, so treat
+                 * this as the special '0' section */
+                section_line = 0;
+        }
+
         r = address_new(network, section_line, &n);
         if (r < 0)
                 return r;