chiark / gitweb /
networkd: address - add support for broadcast
authorTom Gundersen <teg@jklm.no>
Tue, 28 Jan 2014 19:01:37 +0000 (20:01 +0100)
committerTom Gundersen <teg@jklm.no>
Thu, 30 Jan 2014 13:30:39 +0000 (14:30 +0100)
src/network/networkd-address.c
src/network/networkd-gperf.gperf
src/network/networkd-link.c
src/network/networkd.h

index de5566d..aa7927f 100644 (file)
@@ -186,11 +186,7 @@ int address_configure(Address *address, Link *link,
         }
 
         if (address->family == AF_INET) {
         }
 
         if (address->family == AF_INET) {
-                struct in_addr broadcast;
-
-                broadcast.s_addr = address->in_addr.in.s_addr | address->netmask.s_addr;
-
-                r = sd_rtnl_message_append_in_addr(req, IFA_BROADCAST, &broadcast);
+                r = sd_rtnl_message_append_in_addr(req, IFA_BROADCAST, &address->broadcast);
                 if (r < 0) {
                         log_error("Could not append IFA_BROADCAST attribute: %s",
                                   strerror(-r));
                 if (r < 0) {
                         log_error("Could not append IFA_BROADCAST attribute: %s",
                                   strerror(-r));
@@ -253,6 +249,43 @@ int config_parse_dns(const char *unit,
         return 0;
 }
 
         return 0;
 }
 
+int config_parse_broadcast(const char *unit,
+                const char *filename,
+                unsigned line,
+                const char *section,
+                unsigned section_line,
+                const char *lvalue,
+                int ltype,
+                const char *rvalue,
+                void *data,
+                void *userdata) {
+        Network *network = userdata;
+        _cleanup_address_free_ Address *n = NULL;
+        _cleanup_free_ char *address = NULL;
+        int r;
+
+        assert(filename);
+        assert(section);
+        assert(lvalue);
+        assert(rvalue);
+        assert(data);
+
+        r = address_new_static(network, section_line, &n);
+        if (r < 0)
+                return r;
+
+        r = net_parse_inaddr(address, &n->family, &n->broadcast);
+        if (r < 0) {
+                log_syntax(unit, LOG_ERR, filename, line, EINVAL,
+                           "Broadcast is invalid, ignoring assignment: %s", address);
+                return 0;
+        }
+
+        n = NULL;
+
+        return 0;
+}
+
 int config_parse_address(const char *unit,
                 const char *filename,
                 unsigned line,
 int config_parse_address(const char *unit,
                 const char *filename,
                 unsigned line,
@@ -300,7 +333,6 @@ int config_parse_address(const char *unit,
                 }
 
                 n->prefixlen = (unsigned char) i;
                 }
 
                 n->prefixlen = (unsigned char) i;
-                n->netmask.s_addr = htonl(0xfffffffflu >> n->prefixlen);
 
                 address = strndup(rvalue, e - rvalue);
                 if (!address)
 
                 address = strndup(rvalue, e - rvalue);
                 if (!address)
@@ -318,6 +350,10 @@ int config_parse_address(const char *unit,
                 return 0;
         }
 
                 return 0;
         }
 
+        if (n->family == AF_INET && !n->broadcast.s_addr)
+                n->broadcast.s_addr = n->in_addr.in.s_addr |
+                                      htonl(0xfffffffflu >> n->prefixlen);
+
         n = NULL;
 
         return 0;
         n = NULL;
 
         return 0;
index de72805..64dab7c 100644 (file)
@@ -29,6 +29,7 @@ Network.Address,           config_parse_address,          0,       0
 Network.Gateway,           config_parse_gateway,          0,       0
 Network.DNS,               config_parse_dns,              0,       offsetof(Network, dns)
 Address.Address,           config_parse_address,          0,       0
 Network.Gateway,           config_parse_gateway,          0,       0
 Network.DNS,               config_parse_dns,              0,       offsetof(Network, dns)
 Address.Address,           config_parse_address,          0,       0
+Address.Broadcast,         config_parse_broadcast,        0,       0
 Address.Label,             config_parse_label,            0,       0
 Route.Gateway,             config_parse_gateway,          0,       0
 Route.Destination,         config_parse_destination,      0,       0
 Address.Label,             config_parse_label,            0,       0
 Route.Gateway,             config_parse_gateway,          0,       0
 Route.Destination,         config_parse_destination,      0,       0
index 9b5ebed..dec33e8 100644 (file)
@@ -540,7 +540,7 @@ static void dhcp_handler(sd_dhcp_client *client, int event, void *userdata) {
                 addr->family = AF_INET;
                 addr->in_addr.in = address;
                 addr->prefixlen = prefixlen;
                 addr->family = AF_INET;
                 addr->in_addr.in = address;
                 addr->prefixlen = prefixlen;
-                addr->netmask = netmask;
+                addr->broadcast.s_addr = address.s_addr | ~netmask.s_addr;
 
                 r = route_new_dynamic(&rt);
                 if (r < 0) {
 
                 r = route_new_dynamic(&rt);
                 if (r < 0) {
index f174abb..01a8a7f 100644 (file)
@@ -123,7 +123,7 @@ struct Address {
         unsigned char prefixlen;
         char *label;
 
         unsigned char prefixlen;
         char *label;
 
-        struct in_addr netmask;
+        struct in_addr broadcast;
 
         union {
                 struct in_addr in;
 
         union {
                 struct in_addr in;
@@ -305,6 +305,10 @@ int config_parse_address(const char *unit, const char *filename, unsigned line,
                          const char *section, unsigned section_line, const char *lvalue,
                          int ltype, const char *rvalue, void *data, void *userdata);
 
                          const char *section, unsigned section_line, const char *lvalue,
                          int ltype, const char *rvalue, void *data, void *userdata);
 
+int config_parse_broadcast(const char *unit, const char *filename, unsigned line,
+                           const char *section, unsigned section_line, const char *lvalue,
+                           int ltype, const char *rvalue, void *data, void *userdata);
+
 int config_parse_label(const char *unit, const char *filename, unsigned line,
                        const char *section, unsigned section_line, const char *lvalue,
                        int ltype, const char *rvalue, void *data, void *userdata);
 int config_parse_label(const char *unit, const char *filename, unsigned line,
                        const char *section, unsigned section_line, const char *lvalue,
                        int ltype, const char *rvalue, void *data, void *userdata);