diff options
author | Tom Gundersen <teg@jklm.no> | 2014-01-28 20:01:37 +0100 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2014-01-30 14:30:39 +0100 |
commit | eb0ea358b688a6f83ff305c6b825c61f12b6dcb8 (patch) | |
tree | 30419235b063de6eda8235fe56636aecec1739c5 /src | |
parent | 801bd9e859d7f3f127617172910786929776472b (diff) |
networkd: address - add support for broadcast
Diffstat (limited to 'src')
-rw-r--r-- | src/network/networkd-address.c | 48 | ||||
-rw-r--r-- | src/network/networkd-gperf.gperf | 1 | ||||
-rw-r--r-- | src/network/networkd-link.c | 2 | ||||
-rw-r--r-- | src/network/networkd.h | 6 |
4 files changed, 49 insertions, 8 deletions
diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c index de5566dfdb..aa7927ff78 100644 --- a/src/network/networkd-address.c +++ b/src/network/networkd-address.c @@ -186,11 +186,7 @@ int address_configure(Address *address, Link *link, } 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)); @@ -253,6 +249,43 @@ int config_parse_dns(const char *unit, 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, @@ -300,7 +333,6 @@ int config_parse_address(const char *unit, } n->prefixlen = (unsigned char) i; - n->netmask.s_addr = htonl(0xfffffffflu >> n->prefixlen); address = strndup(rvalue, e - rvalue); if (!address) @@ -318,6 +350,10 @@ int config_parse_address(const char *unit, 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; diff --git a/src/network/networkd-gperf.gperf b/src/network/networkd-gperf.gperf index de72805625..64dab7cf0c 100644 --- a/src/network/networkd-gperf.gperf +++ b/src/network/networkd-gperf.gperf @@ -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 +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 diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index 9b5ebeda20..dec33e88ee 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -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->netmask = netmask; + addr->broadcast.s_addr = address.s_addr | ~netmask.s_addr; r = route_new_dynamic(&rt); if (r < 0) { diff --git a/src/network/networkd.h b/src/network/networkd.h index f174abbf59..01a8a7f681 100644 --- a/src/network/networkd.h +++ b/src/network/networkd.h @@ -123,7 +123,7 @@ struct Address { unsigned char prefixlen; char *label; - struct in_addr netmask; + struct in_addr broadcast; 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); +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); |