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.
This commit is contained in:
Lennart Poettering 2020-05-14 14:16:43 +02:00
parent 4b129fba30
commit 90810f7a37
3 changed files with 24 additions and 18 deletions

View File

@ -57,7 +57,7 @@ struct sd_dhcp_server {
char *timezone; char *timezone;
struct in_addr *ntp, *dns, *sip, *pop3_server, *smtp_server, *lpr_server; 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 *extra_options;
OrderedHashmap *vendor_options; OrderedHashmap *vendor_options;

View File

@ -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 * 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 * 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 */ * 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; struct in_addr netmask_addr;
be32_t netmask; be32_t netmask;
uint32_t server_off, broadcast_off, size_max; uint32_t server_off, broadcast_off, size_max;
@ -1135,13 +1141,13 @@ int sd_dhcp_server_set_servers(
sd_dhcp_server *server, sd_dhcp_server *server,
sd_dhcp_lease_info what, sd_dhcp_lease_info what,
const struct in_addr addresses[], const struct in_addr addresses[],
unsigned n_addresses) { size_t n_addresses) {
assert_return(server, -EINVAL); assert_return(server, -EINVAL);
assert_return(addresses || n_addresses == 0, -EINVAL); assert_return(addresses || n_addresses == 0, -EINVAL);
struct in_addr **a; struct in_addr **a;
unsigned *n_a; size_t *n_a;
switch (what) { switch (what) {
case SD_DHCP_LEASE_DNS_SERVERS: case SD_DHCP_LEASE_DNS_SERVERS:
@ -1197,22 +1203,22 @@ int sd_dhcp_server_set_servers(
return 1; 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); 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); 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); 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); 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); 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); return sd_dhcp_server_set_servers(server, SD_DHCP_LEASE_LPR_SERVERS, lpr, n);
} }

View File

@ -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_start(sd_dhcp_server *server);
int sd_dhcp_server_stop(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_timezone(sd_dhcp_server *server, const char *timezone);
int sd_dhcp_server_set_emit_router(sd_dhcp_server *server, int enabled); 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_server *server,
sd_dhcp_lease_info what, sd_dhcp_lease_info what,
const struct in_addr addresses[], 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_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[], unsigned 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[], unsigned 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[], unsigned 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_server(sd_dhcp_server *server, const struct in_addr pop3_server[], unsigned 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_server(sd_dhcp_server *server, const struct in_addr smtp_server[], unsigned 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_option(sd_dhcp_server *server, sd_dhcp_option *v);
int sd_dhcp_server_add_vendor_option(sd_dhcp_server *server, sd_dhcp_option *v); int sd_dhcp_server_add_vendor_option(sd_dhcp_server *server, sd_dhcp_option *v);