From 90810f7a37347206da049e95773613484750187c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 14 May 2020 14:16:43 +0200 Subject: [PATCH] sd-dhcp-server: some function prototype fix-ups Let's use size_t for numbers of entries in memory. Let's use const wherever appropriate. Drop `_server` suffix from function name where we don't have it for similar other cases. --- src/libsystemd-network/dhcp-server-internal.h | 2 +- src/libsystemd-network/sd-dhcp-server.c | 24 ++++++++++++------- src/systemd/sd-dhcp-server.h | 16 ++++++------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/libsystemd-network/dhcp-server-internal.h b/src/libsystemd-network/dhcp-server-internal.h index 94ac6c6e24..fb42f2f80c 100644 --- a/src/libsystemd-network/dhcp-server-internal.h +++ b/src/libsystemd-network/dhcp-server-internal.h @@ -57,7 +57,7 @@ struct sd_dhcp_server { char *timezone; struct in_addr *ntp, *dns, *sip, *pop3_server, *smtp_server, *lpr_server; - unsigned n_ntp, n_dns, n_sip, n_pop3_server, n_smtp_server, n_lpr_server; + size_t n_ntp, n_dns, n_sip, n_pop3_server, n_smtp_server, n_lpr_server; OrderedHashmap *extra_options; OrderedHashmap *vendor_options; diff --git a/src/libsystemd-network/sd-dhcp-server.c b/src/libsystemd-network/sd-dhcp-server.c index 14f2bcb4fb..9db583a7a8 100644 --- a/src/libsystemd-network/sd-dhcp-server.c +++ b/src/libsystemd-network/sd-dhcp-server.c @@ -33,7 +33,13 @@ static DHCPLease *dhcp_lease_free(DHCPLease *lease) { * the whole pool must fit into the subnet, and may not contain the first (any) nor last (broadcast) address * moreover, the server's own address may be in the pool, and is in that case reserved in order not to * accidentally hand it out */ -int sd_dhcp_server_configure_pool(sd_dhcp_server *server, struct in_addr *address, unsigned char prefixlen, uint32_t offset, uint32_t size) { +int sd_dhcp_server_configure_pool( + sd_dhcp_server *server, + const struct in_addr *address, + unsigned char prefixlen, + uint32_t offset, + uint32_t size) { + struct in_addr netmask_addr; be32_t netmask; uint32_t server_off, broadcast_off, size_max; @@ -1135,13 +1141,13 @@ int sd_dhcp_server_set_servers( sd_dhcp_server *server, sd_dhcp_lease_info what, const struct in_addr addresses[], - unsigned n_addresses) { + size_t n_addresses) { assert_return(server, -EINVAL); assert_return(addresses || n_addresses == 0, -EINVAL); struct in_addr **a; - unsigned *n_a; + size_t *n_a; switch (what) { case SD_DHCP_LEASE_DNS_SERVERS: @@ -1197,22 +1203,22 @@ int sd_dhcp_server_set_servers( return 1; } -int sd_dhcp_server_set_dns(sd_dhcp_server *server, const struct in_addr dns[], unsigned n) { +int sd_dhcp_server_set_dns(sd_dhcp_server *server, const struct in_addr dns[], size_t n) { return sd_dhcp_server_set_servers(server, SD_DHCP_LEASE_DNS_SERVERS, dns, n); } -int sd_dhcp_server_set_ntp(sd_dhcp_server *server, const struct in_addr ntp[], unsigned n) { +int sd_dhcp_server_set_ntp(sd_dhcp_server *server, const struct in_addr ntp[], size_t n) { return sd_dhcp_server_set_servers(server, SD_DHCP_LEASE_NTP_SERVERS, ntp, n); } -int sd_dhcp_server_set_sip(sd_dhcp_server *server, const struct in_addr sip[], unsigned n) { +int sd_dhcp_server_set_sip(sd_dhcp_server *server, const struct in_addr sip[], size_t n) { return sd_dhcp_server_set_servers(server, SD_DHCP_LEASE_SIP_SERVERS, sip, n); } -int sd_dhcp_server_set_pop3_server(sd_dhcp_server *server, const struct in_addr pop3[], unsigned n) { +int sd_dhcp_server_set_pop3(sd_dhcp_server *server, const struct in_addr pop3[], size_t n) { return sd_dhcp_server_set_servers(server, SD_DHCP_LEASE_POP3_SERVERS, pop3, n); } -int sd_dhcp_server_set_smtp_server(sd_dhcp_server *server, const struct in_addr smtp[], unsigned n) { +int sd_dhcp_server_set_smtp(sd_dhcp_server *server, const struct in_addr smtp[], size_t n) { return sd_dhcp_server_set_servers(server, SD_DHCP_LEASE_SMTP_SERVERS, smtp, n); } -int sd_dhcp_server_set_lpr(sd_dhcp_server *server, const struct in_addr lpr[], unsigned n) { +int sd_dhcp_server_set_lpr(sd_dhcp_server *server, const struct in_addr lpr[], size_t n) { return sd_dhcp_server_set_servers(server, SD_DHCP_LEASE_LPR_SERVERS, lpr, n); } diff --git a/src/systemd/sd-dhcp-server.h b/src/systemd/sd-dhcp-server.h index 017d2d9cbb..4697f3dd3d 100644 --- a/src/systemd/sd-dhcp-server.h +++ b/src/systemd/sd-dhcp-server.h @@ -45,7 +45,7 @@ int sd_dhcp_server_is_running(sd_dhcp_server *server); int sd_dhcp_server_start(sd_dhcp_server *server); int sd_dhcp_server_stop(sd_dhcp_server *server); -int sd_dhcp_server_configure_pool(sd_dhcp_server *server, struct in_addr *address, unsigned char prefixlen, uint32_t offset, uint32_t size); +int sd_dhcp_server_configure_pool(sd_dhcp_server *server, const struct in_addr *address, unsigned char prefixlen, uint32_t offset, uint32_t size); int sd_dhcp_server_set_timezone(sd_dhcp_server *server, const char *timezone); int sd_dhcp_server_set_emit_router(sd_dhcp_server *server, int enabled); @@ -54,14 +54,14 @@ int sd_dhcp_server_set_servers( sd_dhcp_server *server, sd_dhcp_lease_info what, const struct in_addr addresses[], - unsigned n_addresses); + size_t n_addresses); -int sd_dhcp_server_set_lpr(sd_dhcp_server *server, const struct in_addr lpr[], unsigned n); -int sd_dhcp_server_set_dns(sd_dhcp_server *server, const struct in_addr dns[], unsigned n); -int sd_dhcp_server_set_ntp(sd_dhcp_server *server, const struct in_addr ntp[], unsigned n); -int sd_dhcp_server_set_sip(sd_dhcp_server *server, const struct in_addr sip[], unsigned n); -int sd_dhcp_server_set_pop3_server(sd_dhcp_server *server, const struct in_addr pop3_server[], unsigned n); -int sd_dhcp_server_set_smtp_server(sd_dhcp_server *server, const struct in_addr smtp_server[], unsigned n); +int sd_dhcp_server_set_lpr(sd_dhcp_server *server, const struct in_addr lpr[], size_t n); +int sd_dhcp_server_set_dns(sd_dhcp_server *server, const struct in_addr dns[], size_t n); +int sd_dhcp_server_set_ntp(sd_dhcp_server *server, const struct in_addr ntp[], size_t n); +int sd_dhcp_server_set_sip(sd_dhcp_server *server, const struct in_addr sip[], size_t n); +int sd_dhcp_server_set_pop3(sd_dhcp_server *server, const struct in_addr pop3_server[], size_t n); +int sd_dhcp_server_set_smtp(sd_dhcp_server *server, const struct in_addr smtp_server[], size_t n); int sd_dhcp_server_add_option(sd_dhcp_server *server, sd_dhcp_option *v); int sd_dhcp_server_add_vendor_option(sd_dhcp_server *server, sd_dhcp_option *v);