From: Yu Watanabe Date: Sat, 11 Apr 2026 19:50:05 +0000 (+0900) Subject: dhcp: move definition of sd_dhcp_route and related functions to dhcp-route.[ch] X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=08249b359bf697fe09330ea3c506ecdff2e78e6c;p=thirdparty%2Fsystemd.git dhcp: move definition of sd_dhcp_route and related functions to dhcp-route.[ch] This also renames arguments for storing results. No functional change, just refactoring and preparation for later commits. --- diff --git a/src/libsystemd-network/dhcp-lease-internal.h b/src/libsystemd-network/dhcp-lease-internal.h index b436287aeed..bc411a4f36c 100644 --- a/src/libsystemd-network/dhcp-lease-internal.h +++ b/src/libsystemd-network/dhcp-lease-internal.h @@ -12,12 +12,6 @@ #include "sd-forward.h" #include "list.h" -struct sd_dhcp_route { - struct in_addr dst_addr; - struct in_addr gw_addr; - unsigned char dst_prefixlen; -}; - struct sd_dhcp_raw_option { LIST_FIELDS(struct sd_dhcp_raw_option, options); diff --git a/src/libsystemd-network/dhcp-route.c b/src/libsystemd-network/dhcp-route.c new file mode 100644 index 00000000000..33828276ace --- /dev/null +++ b/src/libsystemd-network/dhcp-route.c @@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ + +#include "sd-dhcp-lease.h" + +#include "dhcp-route.h" /* IWYU pragma: keep */ + +int sd_dhcp_route_get_destination(sd_dhcp_route *route, struct in_addr *ret) { + assert_return(route, -EINVAL); + assert_return(ret, -EINVAL); + + *ret = route->dst_addr; + return 0; +} + +int sd_dhcp_route_get_destination_prefix_length(sd_dhcp_route *route, uint8_t *ret) { + assert_return(route, -EINVAL); + assert_return(ret, -EINVAL); + + *ret = route->dst_prefixlen; + return 0; +} + +int sd_dhcp_route_get_gateway(sd_dhcp_route *route, struct in_addr *ret) { + assert_return(route, -EINVAL); + assert_return(ret, -EINVAL); + + *ret = route->gw_addr; + return 0; +} diff --git a/src/libsystemd-network/dhcp-route.h b/src/libsystemd-network/dhcp-route.h new file mode 100644 index 00000000000..e313c08a586 --- /dev/null +++ b/src/libsystemd-network/dhcp-route.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +#pragma once + +#include "sd-forward.h" + +#include "in-addr-util.h" /* IWYU pragma: keep */ + +struct sd_dhcp_route { + struct in_addr dst_addr; + struct in_addr gw_addr; + uint8_t dst_prefixlen; +}; diff --git a/src/libsystemd-network/meson.build b/src/libsystemd-network/meson.build index 500882319e6..74e09fac84c 100644 --- a/src/libsystemd-network/meson.build +++ b/src/libsystemd-network/meson.build @@ -8,6 +8,7 @@ libsystemd_network_sources = files( 'dhcp-option.c', 'dhcp-packet.c', 'dhcp-protocol.c', + 'dhcp-route.c', 'dhcp6-network.c', 'dhcp6-option.c', 'dhcp6-protocol.c', diff --git a/src/libsystemd-network/network-internal.c b/src/libsystemd-network/network-internal.c index c1eaa361afa..cc29d9fd1b1 100644 --- a/src/libsystemd-network/network-internal.c +++ b/src/libsystemd-network/network-internal.c @@ -3,8 +3,10 @@ #include #include +#include "sd-dhcp-lease.h" + #include "alloc-util.h" -#include "dhcp-lease-internal.h" +#include "dhcp-route.h" #include "dns-resolver-internal.h" #include "extract-word.h" #include "hexdecoct.h" diff --git a/src/libsystemd-network/sd-dhcp-lease.c b/src/libsystemd-network/sd-dhcp-lease.c index bfe4874be5a..8003f37fd31 100644 --- a/src/libsystemd-network/sd-dhcp-lease.c +++ b/src/libsystemd-network/sd-dhcp-lease.c @@ -11,6 +11,7 @@ #include "alloc-util.h" #include "dhcp-lease-internal.h" #include "dhcp-option.h" +#include "dhcp-route.h" #include "dns-def.h" #include "dns-domain.h" #include "dns-resolver-internal.h" @@ -1802,27 +1803,3 @@ int sd_dhcp_lease_get_timezone(sd_dhcp_lease *lease, const char **ret) { *ret = lease->timezone; return 0; } - -int sd_dhcp_route_get_destination(sd_dhcp_route *route, struct in_addr *destination) { - assert_return(route, -EINVAL); - assert_return(destination, -EINVAL); - - *destination = route->dst_addr; - return 0; -} - -int sd_dhcp_route_get_destination_prefix_length(sd_dhcp_route *route, uint8_t *length) { - assert_return(route, -EINVAL); - assert_return(length, -EINVAL); - - *length = route->dst_prefixlen; - return 0; -} - -int sd_dhcp_route_get_gateway(sd_dhcp_route *route, struct in_addr *gateway) { - assert_return(route, -EINVAL); - assert_return(gateway, -EINVAL); - - *gateway = route->gw_addr; - return 0; -} diff --git a/src/network/test-network.c b/src/network/test-network.c index ab3a86e10b1..c78c50e3a75 100644 --- a/src/network/test-network.c +++ b/src/network/test-network.c @@ -3,7 +3,7 @@ #include #include "alloc-util.h" -#include "dhcp-lease-internal.h" +#include "dhcp-route.h" #include "hashmap.h" #include "hostname-setup.h" #include "network-internal.h" diff --git a/src/systemd/sd-dhcp-lease.h b/src/systemd/sd-dhcp-lease.h index 3aa67c3fa54..2dbee5450d5 100644 --- a/src/systemd/sd-dhcp-lease.h +++ b/src/systemd/sd-dhcp-lease.h @@ -86,9 +86,9 @@ int sd_dhcp_lease_get_6rd( size_t *ret_n_br_addresses); int sd_dhcp_lease_has_6rd(sd_dhcp_lease *lease); -int sd_dhcp_route_get_destination(sd_dhcp_route *route, struct in_addr *destination); -int sd_dhcp_route_get_destination_prefix_length(sd_dhcp_route *route, uint8_t *length); -int sd_dhcp_route_get_gateway(sd_dhcp_route *route, struct in_addr *gateway); +int sd_dhcp_route_get_destination(sd_dhcp_route *route, struct in_addr *ret); +int sd_dhcp_route_get_destination_prefix_length(sd_dhcp_route *route, uint8_t *ret); +int sd_dhcp_route_get_gateway(sd_dhcp_route *route, struct in_addr *ret); _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_dhcp_lease, sd_dhcp_lease_unref);