From 9a45125ae7810ff1d3f2927538c510fe70148f63 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 7 Jul 2023 11:30:27 +0900 Subject: [PATCH] network: split-out address_section_adjust_broadcast() No functional change, just refactoring. --- src/network/networkd-address.c | 37 +++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c index 57a9ceb229..d393d3374b 100644 --- a/src/network/networkd-address.c +++ b/src/network/networkd-address.c @@ -2072,6 +2072,32 @@ int config_parse_address_netlabel( return 0; } +static void address_section_adjust_broadcast(Address *address) { + assert(address); + assert(address->section); + + if (!in4_addr_is_set(&address->broadcast)) + return; + + if (address->family == AF_INET6) + log_warning("%s: broadcast address is set for an IPv6 address. " + "Ignoring Broadcast= setting in the [Address] section from line %u.", + address->section->filename, address->section->line); + else if (address->prefixlen > 30) + log_warning("%s: broadcast address is set for an IPv4 address with prefix length larger than 30. " + "Ignoring Broadcast= setting in the [Address] section from line %u.", + address->section->filename, address->section->line); + else if (in4_addr_is_set(&address->in_addr_peer.in)) + log_warning("%s: broadcast address is set for an IPv4 address with peer address. " + "Ignoring Broadcast= setting in the [Address] section from line %u.", + address->section->filename, address->section->line); + else + /* Otherwise, keep the specified broadcast address. */ + return; + + address->broadcast.s_addr = 0; +} + static int address_section_verify(Address *address) { if (section_is_invalid(address->section)) return -EINVAL; @@ -2087,16 +2113,7 @@ static int address_section_verify(Address *address) { assert(IN_SET(address->family, AF_INET, AF_INET6)); - if (in4_addr_is_set(&address->broadcast) && - (address->family == AF_INET6 || address->prefixlen > 30 || - in_addr_is_set(address->family, &address->in_addr_peer))) { - log_warning("%s: broadcast address is set for an IPv6 address, " - "an IPv4 address with peer address, or with prefix length larger than 30. " - "Ignoring Broadcast= setting in the [Address] section from line %u.", - address->section->filename, address->section->line); - - address->broadcast.s_addr = 0; - } + address_section_adjust_broadcast(address); if (address->family == AF_INET6 && address->label) { log_warning("%s: address label is set for IPv6 address in the [Address] section from line %u. " -- 2.25.1